More improvements e.g. flags and provision target

This commit is contained in:
2026-08-11 07:48:46 +02:00
parent a3d4825cbd
commit 41556cfe73
22 changed files with 961 additions and 484 deletions
+59 -8
View File
@@ -1,7 +1,7 @@
<?php
/******************************************************************************
* YMS - Yacht Management Software
* Copyright (C) 2024 Thomas Hooge
* Copyright (C) 2024-2026 Thomas Hooge
*
* SPDX-License-Identifier: WTFPL
******************************************************************************/
@@ -27,6 +27,7 @@ switch ($submit = form_get_action()) {
case 'view': $action = ACT_VIEW; break;
case 'edit': $action = ACT_EDIT; break;
case 'del': $action = ACT_DELETE; break;
case 'list': $action = ACT_VIEW_LIST; break;
case 'filter':
$flt = array();
@@ -55,7 +56,8 @@ switch ($submit = form_get_action()) {
$p[':provid'] = $id;
$p[':provname'] = gpc_get_string($_POST, 'provname');
$p[':provcat'] = gpc_get_int($_POST, 'provcat');
$p[':number'] = gpc_get_int($_POST, 'number');
$p[':number'] = gpc_get_uint($_POST, 'number');
$p[':target'] = gpc_get_uint($_POST, 'target');
$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');
@@ -63,6 +65,7 @@ switch ($submit = form_get_action()) {
$p[':shelflife'] = gpc_get_string($_POST, 'shelflife');
$p[':sid'] = gpc_get_int($_POST, 'sid');
if ($p[':sid'] <= 0) $p[':sid'] = NULL;
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('provisions', $p, 'provid');
$action = ACT_VIEW;
break;
@@ -134,7 +137,7 @@ $lastpage = ceil($numrows/$rows_pp);
// 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,"
$sql = "SELECT provid, provname, number, target, unit, storedate, shelflife, sid,"
. " DATEDIFF(shelflife, storedate) AS d0, DATEDIFF (shelflife, CURDATE()) AS d1 "
. "FROM provisions LEFT OUTER JOIN storage USING (sid)";
$sql .= ' WHERE ' . $where;
@@ -195,7 +198,9 @@ foreach ($res as $row) {
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>', $row['number'];
if ($row['target']) echo ' (', $row['target'], ')';
echo "</td>\n";
echo "<td>", $opt_unit[$row['unit']], "</td>\n";
echo "<td>", $row['storedate'], "</td>\n";
echo "<td>", $row['shelflife'], "</td>\n";
@@ -224,6 +229,11 @@ echo $pagination;
form_add_button($g_scriptname);
// Shopping list button
echo '<div class="container-fluid px-0 my-3">', "\n";
echo ' <a href="', $g_scriptname, '?f=list" class="btn btn-secondary">',_('Shopping list'), "</a>\n";
echo "</div>\n";
elseif ($action == ACT_ADD):
// ========== VARIANT: add record =============================================
@@ -258,7 +268,8 @@ echo '<h2>', _('Add provisions'), "</h2>\n";
elseif ($action == ACT_VIEW):
// ========== VARIANT: view single record =====================================
$sql = "SELECT provname, provcat, number, unit, weight, weight_net, storedate, shelflife, sid "
$sql = "SELECT provname, provcat, number, target, unit, weight, weight_net,"
. " storedate, shelflife, sid, remarks "
. "FROM provisions "
. "WHERE provid=?";
$sth = $pdo->prepare($sql);
@@ -269,13 +280,15 @@ 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>", _('Target'), "</th><td>", $prov->target, "</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";
echo '<tr><th>', _('Shelflife'),"</th><td>$prov->shelflife</td></tr>\n";
echo '<tr><th>', _('Shelflife'),"</th><td>", $prov->shelflife, "</td></tr>\n";
echo '<tr><th>', _('Storage'),"</th><td>", ($opt_storage[$prov->sid] ?? ''), "</td></tr>\n";
echo '<tr><th>', _('Remarks'),"</th><td>", nl2br($prov->remarks), "</td></tr>\n";
echo "</table>\n";
form_view_buttons($g_scriptname, $id);
@@ -283,7 +296,8 @@ form_view_buttons($g_scriptname, $id);
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sql = "SELECT provname, provcat, number, weight, weight_net, unit, storedate, shelflife, sid "
$sql = "SELECT provname, provcat, number, target, unit, weight, weight_net,"
. " storedate, shelflife, sid, remarks "
. "FROM provisions "
. "WHERE provid=?";
$sth = $pdo->prepare($sql);
@@ -302,6 +316,10 @@ 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="target"><?=_('Target')?></label>
<input type="number" min="0" max="1000" class="form-control" id="target" name="target" value="<?=$prov->target ?>">
</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); ?>">
@@ -324,7 +342,12 @@ form_create_select('provcat', _('Category'), $g_opt_none + $opt_category, $prov-
</div>
<?php
form_create_select('sid', _('Storage'), $g_opt_none + $opt_storage, $prov->sid);
?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3" maxlength="150"><?=$prov->remarks ?></textarea>
</div>
<?php
form_edit_buttons($g_scriptname, $id);
echo "</form>\n";
@@ -334,6 +357,34 @@ elseif ($action == ACT_DELETE):
echo '<h2>', _('Delete provisions'), "</h2>\n";
?>
<p>Not yet implemented!</p>
<?php
elseif ($action == ACT_VIEW_LIST):
// ========== VARIANT: shopping list ==========================================
echo '<h2>', _('Shopping list'), "</h2>\n";
$sql = "SELECT provid, provname, unit, target - number AS buy "
. "FROM provisions "
. "WHERE target IS NOT NULL AND number < target "
. "ORDER BY provcat, provname";
$sth = $pdo->query($sql);
$res = $sth->fetchAll();
echo "<pre>";
foreach ($res as $row) {
echo $row['provname'];
echo ' ';
echo $row['buy'];
echo ' ';
echo $opt_unit[$row['unit']], "\n";
}
echo "</pre>";
echo '<div class="container-fluid px-0 my-3">', "\n";
echo ' <a href="shopping.php" class="btn btn-primary" target="_blank">',_('Use'), "</a>\n";
echo ' <a href="', $g_scriptname, '" class="btn btn-secondary">',_('Back'), "</a>\n";
echo "</div>\n";
else:
// ========== ERROR UNKNOWN VARIANT ===========================================