Webgui: More mobile friendly touch and much more improvements
This commit is contained in:
+95
-25
@@ -54,10 +54,13 @@ switch ($submit = form_get_action()) {
|
||||
$p[':provname'] = gpc_get_string($_POST, 'provname');
|
||||
$p[':provcat'] = gpc_get_int($_POST, 'provcat');
|
||||
$p[':number'] = gpc_get_int($_POST, 'number');
|
||||
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value
|
||||
$p[':weight_net'] = min(gpc_get_float($_POST, 'weight_net'), 999.99);
|
||||
$p[':unit'] = gpc_get_int($_POST, 'unit');
|
||||
$p[':storedate'] = gpc_get_string($_POST, 'storedate');
|
||||
$p[':shelflife'] = gpc_get_string($_POST, 'shelflife');
|
||||
$p[':sid'] = gpc_get_int($_POST, 'sid');
|
||||
if ($p[':sid'] <= 0) $p[':sid'] = NULL;
|
||||
db_exec_update('provisions', $p, 'provid');
|
||||
$action = ACT_VIEW;
|
||||
break;
|
||||
@@ -88,11 +91,19 @@ require 'header.php';
|
||||
if ($action == ACT_DEFAULT):
|
||||
// ========== VARIANT: default behavior =======================================
|
||||
|
||||
page_caption_search($pagetitle);
|
||||
|
||||
// load filter from db
|
||||
$flt = db_get_filter($user->id, 202);
|
||||
|
||||
$w = array('(vid=:vid OR sid IS NULL)');
|
||||
$p = array(':vid' => $user->vid);
|
||||
if ($flt->cat == -1) {
|
||||
$w[] = 'provcat IS NULL';
|
||||
} elseif ($flt->cat > 0) {
|
||||
$w[] = 'provcat=:provcat';
|
||||
$p[':provcat'] = $flt->cat;
|
||||
}
|
||||
if (strlen($flt->txt) > 1) {
|
||||
$w[] = 'provname LIKE :txt';
|
||||
$p[':txt'] = '%'.$flt->txt.'%';
|
||||
@@ -101,67 +112,116 @@ $where = join(' AND ', $w);
|
||||
|
||||
$order = ' ORDER BY provid';
|
||||
|
||||
// get total record count for pagination and limit
|
||||
$sql = "SELECT COUNT(*) FROM provisions LEFT OUTER JOIN storage USING (sid) WHERE " . $where;
|
||||
$sth = $pdo->prepare($sql);
|
||||
try {
|
||||
$sth->execute($p);
|
||||
} catch(PDOException $e) {
|
||||
$g_error->Add($e->getMessage());
|
||||
$g_error->Add($sql);
|
||||
$g_error->Add(print_r($p, true));
|
||||
$g_error->PrintOut();
|
||||
}
|
||||
$numrows = $sth->fetchColumn();
|
||||
$page = gpc_get_int($_REQUEST, 'p', 1);
|
||||
$rows_pp = gpc_get_int($_REQUEST, 'n', $g_rows_pp);
|
||||
$lastpage = ceil($numrows/$rows_pp);
|
||||
|
||||
// provisions can be assigned to a store or be free
|
||||
// d0 is the maximum number of days age
|
||||
// d1 is the current age in days. If negative then it is over limit
|
||||
// TODO display over with warning levels: 50% over, 100% over etc.
|
||||
$sql = "SELECT provid, provname, number, unit, storedate, shelflife, sid,"
|
||||
. " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (CURDATE(), storedate) AS d1 "
|
||||
. " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (shelflife, CURDATE()) AS d1 "
|
||||
. "FROM provisions LEFT OUTER JOIN storage USING (sid)";
|
||||
$sql .= ' WHERE ' . $where;
|
||||
$sql .= $order;
|
||||
|
||||
// if pagination:
|
||||
$sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp;
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute($p);
|
||||
$res = $sth->fetchAll();
|
||||
|
||||
page_caption_search($pagetitle);
|
||||
?>
|
||||
<form method="post" action="<?=$g_scriptname?>">
|
||||
<div id="filter" class="card">
|
||||
<div class="card-header">Filter</div>
|
||||
<div class="card-body">
|
||||
<div class="card-header"><i class="bi bi-funnel me-2"></i>Filter</div>
|
||||
<div class="card-body d-flex flex-wrap gap-3">
|
||||
<?php
|
||||
filter_create_select('flt_cat', _('Category'), $g_opt_all + $g_opt_none + $opt_category, $flt->cat);
|
||||
?>
|
||||
<label for="flt_txt">Text</label>
|
||||
<input type="text" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt?>">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
<button name="submit[freset]" class="btn btn-sm btn-secondary float-end" title="<?=_('Reset filter to defaults')?>"><?=_('Clear')?></button>
|
||||
<div class="d-flex flex-nowrap gap-2">
|
||||
<label for="flt_txt">Text</label>
|
||||
<input type="text" name="flt_txt" size="15" maxlength="30" value="<?=$flt->txt;?>">
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<button name="submit[filter]" class="btn btn-sm btn-primary" title="<?=_('Apply')?>"><?=_('Go')?></button>
|
||||
<button name="submit[freset]" class="btn btn-sm btn-secondary float-end" title="<?=_('Reset filter to defaults')?>"><?=_('Clear')?></button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<?php
|
||||
// Pagination on top
|
||||
$pagination = get_pagination($g_scriptname, '', $page, $lastpage);
|
||||
echo $pagination;
|
||||
|
||||
echo '<table class="table table-striped">', "\n";
|
||||
echo "<thead>\n";
|
||||
echo "<tr>\n";
|
||||
echo '<th>#</th>';
|
||||
echo '<th>', _('Description'), "</th>";
|
||||
echo '<th>', _('Number'), "</th>";
|
||||
echo '<th>', _('Unit'), "</th>";
|
||||
echo '<th>', _('Stored'), "</th>";
|
||||
echo '<th>', _('Best before'), "</th>";
|
||||
echo "<th></th>";
|
||||
echo "<th></th>\n";
|
||||
echo "<th></th>"; // Meter
|
||||
echo "<th></th>\n"; // Buttons
|
||||
echo "</tr>\n";
|
||||
echo "</thead>\n";
|
||||
|
||||
$i = ($page - 1) * $rows_pp;
|
||||
$i0 = $i + 1;
|
||||
foreach ($res as $row) {
|
||||
$i++; // record number
|
||||
echo "<tr>\n";
|
||||
echo "<td>", ! isset($row['sid']) ? '<i class="bi bi-basket"></i> ' : '', $row['provname'], "</td>\n";
|
||||
echo "<td>". $row['number'] ."</td>\n";
|
||||
echo "<td>". $opt_unit[$row['unit']] ."</td>\n";
|
||||
echo "<td>". $row['storedate'] ."</td>\n";
|
||||
echo "<td>". $row['shelflife'] ."</td>\n";
|
||||
echo "<td>";
|
||||
echo '<meter min="0" max="', $row['d0'], '" value="', $row['d1'], '">';
|
||||
// Action buttons
|
||||
form_action_buttons($g_scriptname, $row['provid']);
|
||||
echo "<td>", $i;
|
||||
echo '<a class="text-nowrap" title="', _('View'), '" href="', $g_scriptname, '?f=view&id=', $row['provid'], '"><i class="bi bi-eye ms-2"></i></a>', "\n";
|
||||
echo "</td>\n";
|
||||
echo "<td>", ! isset($row['sid']) ? '<i class="bi bi-cart3"></i> ' : '', $row['provname'], "</td>\n";
|
||||
echo "<td>", $row['number'], "</td>\n";
|
||||
echo "<td>", $opt_unit[$row['unit']], "</td>\n";
|
||||
echo "<td>", $row['storedate'], "</td>\n";
|
||||
echo "<td>", $row['shelflife'], "</td>\n";
|
||||
// TODO shelflife in der Vergangenheit
|
||||
echo "<td>";
|
||||
if ($row['d1'] > 0) {
|
||||
echo '<meter min="0" max="', $row['d0'], '" value="', $row['d1'], '"></meter>';
|
||||
} else {
|
||||
if ($row['d1'] < 0) {
|
||||
echo '<i class="bi bi-exclamation-triangle-fill"></i> ', abs($row['d1']);
|
||||
}
|
||||
}
|
||||
echo "</td>\n";
|
||||
// Edit current record button
|
||||
echo "<td>";
|
||||
echo '<a title="', _('Edit'), '" href="', $g_scriptname, '?f=edit&id=', $row['provid'], '"><i class="bi-pencil"></i></a>';
|
||||
echo "</td>\n";
|
||||
|
||||
echo "</tr>\n";
|
||||
}
|
||||
// Table summary
|
||||
echo "<tfoot>\n";
|
||||
echo '<tr><td colspan="6">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
|
||||
echo '<tr><td colspan="8">', sprintf(_('%d records'), count($res)), '</td></tr>', "\n";
|
||||
echo "</tfoot>\n";
|
||||
echo "</table>\n";
|
||||
|
||||
echo $pagination;
|
||||
|
||||
form_add_button($g_scriptname);
|
||||
|
||||
elseif ($action == ACT_ADD):
|
||||
@@ -187,7 +247,7 @@ echo '<h2>', _('Add provisions'), "</h2>\n";
|
||||
<label for="shelflife"><?=_('Shelflife')?></label>
|
||||
<input type="date" class="form-control" id="shelflife" name="shelflife">
|
||||
</div>
|
||||
<?php form_create_select('sid', _('Storage'), [-1 => '- none -'] + $opt_storage); ?>
|
||||
<?php form_create_select('sid', _('Storage'), $g_opt_none + $opt_storage); ?>
|
||||
<div class="container-fluid px-0 my-3">
|
||||
<button type="submit" name="submit[insert]" class="btn btn-primary"><?=_('Save')?></button>
|
||||
<a href="<?=$g_scriptname?>" class="btn btn-secondary"><?=_('Back')?></a>
|
||||
@@ -198,7 +258,7 @@ echo '<h2>', _('Add provisions'), "</h2>\n";
|
||||
elseif ($action == ACT_VIEW):
|
||||
// ========== VARIANT: view single record =====================================
|
||||
|
||||
$sql = "SELECT provname, provcat, number, unit, storedate, shelflife, sid "
|
||||
$sql = "SELECT provname, provcat, number, unit, weight, weight_net, storedate, shelflife, sid "
|
||||
. "FROM provisions "
|
||||
. "WHERE provid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -209,6 +269,8 @@ echo '<h2>', $prov->provname, "</h2>\n";
|
||||
|
||||
echo '<table class="table">', "\n";
|
||||
echo '<tr><th style="width:20%">', _('Number'),"</th><td>", $prov->number, "</td></tr>\n";
|
||||
echo "<tr><th>", _('Weight'), "</th><td>", format_float($prov->weight, 2, 'kg'), "</td></tr>\n";
|
||||
echo "<tr><th>", _('Weight net'), "</th><td>", format_float($prov->weight_net, 2, 'kg'), "</td></tr>\n";
|
||||
echo '<tr><th>', _('Unit'),"</th><td>", $opt_unit[$prov->unit], "</td></tr>\n";
|
||||
echo '<tr><th>', _('Category'),"</th><td>", $opt_category[$prov->provcat] ?? 'n/a', "</td></tr>\n";
|
||||
echo '<tr><th>', _('Storedate'),"</th><td>", $prov->storedate, "</td></tr>\n";
|
||||
@@ -221,7 +283,7 @@ form_view_buttons($g_scriptname, $id);
|
||||
elseif ($action == ACT_EDIT):
|
||||
// ========== VARIANT: edit single record =====================================
|
||||
|
||||
$sql = "SELECT provname, provcat, number, unit, storedate, shelflife, sid "
|
||||
$sql = "SELECT provname, provcat, number, weight, weight_net, unit, storedate, shelflife, sid "
|
||||
. "FROM provisions "
|
||||
. "WHERE provid=?";
|
||||
$sth = $pdo->prepare($sql);
|
||||
@@ -240,9 +302,17 @@ echo '<h2>', _('Edit provision'), "</h2>\n";
|
||||
<label for="number"><?=_('Number')?></label>
|
||||
<input type="number" min="0" max="1000" class="form-control" id="number" name="number" value="<?=$prov->number ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="weight" class="form-label"><?=_('Weight, kg')?></label>
|
||||
<input type="text" class="form-control" id="weight" name="weight" value="<?=format_float($prov->weight); ?>">
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="weight_net" class="form-label"><?=_('Weight net, kg')?></label>
|
||||
<input type="text" class="form-control" id="weight" name="weight_net" value="<?=format_float($prov->weight_net); ?>">
|
||||
</div>
|
||||
<?php
|
||||
form_create_select('unit', _('Unit'), $opt_unit, $prov->unit);
|
||||
form_create_select('provcat', _('Category'), array_merge($g_opt_none, $opt_category), $prov->provcat);
|
||||
form_create_select('provcat', _('Category'), $g_opt_none + $opt_category, $prov->provcat);
|
||||
?>
|
||||
<div class="mb-3">
|
||||
<label for="storedate"><?=_('Storedate')?></label>
|
||||
@@ -253,7 +323,7 @@ form_create_select('provcat', _('Category'), array_merge($g_opt_none, $opt_categ
|
||||
<input type="date" class="form-control" id="shelflife" name="shelflife" value="<?=$prov->shelflife ?>">
|
||||
</div>
|
||||
<?php
|
||||
form_create_select('sid', _('Storage'), $opt_storage, $prov->sid);
|
||||
form_create_select('sid', _('Storage'), $g_opt_none + $opt_storage, $prov->sid);
|
||||
|
||||
form_edit_buttons($g_scriptname, $id);
|
||||
echo "</form>\n";
|
||||
|
||||
Reference in New Issue
Block a user