Webgui improve series handling and plan date precision

This commit is contained in:
thooge committed 2026-10-22 22:03:04 +02:00
1 parent c2df7e8013
commit b3825cb1b3
6 files changed
+373 -272

No files matched your search

+3 -2
View File
@@ -413,14 +413,15 @@ CREATE TABLE maintenance (
maintid int(10) NOT NULL AUTO_INCREMENT, maintid int(10) NOT NULL AUTO_INCREMENT,
vid smallint(6) NOT NULL DEFAULT 1, vid smallint(6) NOT NULL DEFAULT 1,
eid smallint(6) UNSIGNED DEFAULT NULL, eid smallint(6) UNSIGNED DEFAULT NULL,
series smallint(6) DEFAULT NULL, series smallint(6) UNSIGNED DEFAULT NULL,
activities varchar(40) NOT NULL, activities varchar(40) NOT NULL,
plan_date DATE DEFAULT NULL, plan_date DATE DEFAULT NULL,
plan_precision enum('day','week','month','quarter') NOT NULL DEFAULT 'day',
completion_date DATE DEFAULT NULL, completion_date DATE DEFAULT NULL,
interval_hours smallint(6) DEFAULT NULL, interval_hours smallint(6) DEFAULT NULL,
last_hours int(10) DEFAULT NULL, last_hours int(10) DEFAULT NULL,
remarks varchar(150) DEFAULT NULL, remarks varchar(150) DEFAULT NULL,
maintstate enum('new','plan','ongoing','done') NOT NULL DEFAULT 'new', maintstate enum('new','plan','ongoing','skipped','missed','done') NOT NULL DEFAULT 'new',
PRIMARY KEY (maintid), PRIMARY KEY (maintid),
FOREIGN KEY fk_maintenance_vessel (vid) FOREIGN KEY fk_maintenance_vessel (vid)
REFERENCES vessel(vid) REFERENCES vessel(vid)
+8 -1
View File
@@ -197,6 +197,7 @@ $g_opt_all = array(-2 => _('― all ―'));
$g_opt_none = array(-1 => _('― none ―')); $g_opt_none = array(-1 => _('― none ―'));
$g_opt_empty = array('' => _('― none ―')); $g_opt_empty = array('' => _('― none ―'));
$g_opt_unknown = array(-1 => _('― unknown ―')); $g_opt_unknown = array(-1 => _('― unknown ―'));
$g_opt_new = array(-3 => _('― new ―'));
// Initialize message system // Initialize message system
$g_message = new Message; $g_message = new Message;
@@ -557,6 +558,7 @@ function get_enum($enum) {
'completed' => _('Completed'), 'completed' => _('Completed'),
'closed' => _('Closed'), 'closed' => _('Closed'),
'company' => _('Company'), 'company' => _('Company'),
'day' => _('Day'),
'defect' => _('Defect'), 'defect' => _('Defect'),
'deleted' => _('Deleted'), 'deleted' => _('Deleted'),
'done' => _('Done'), 'done' => _('Done'),
@@ -577,7 +579,9 @@ function get_enum($enum) {
'low' => _('Low'), 'low' => _('Low'),
'manual' => _('Manual'), 'manual' => _('Manual'),
'medium' => _('Medium'), 'medium' => _('Medium'),
'missed' => _('Missed'),
'mono' => _('Monohull'), 'mono' => _('Monohull'),
'month' => _('Month'),
'new' => _('New'), 'new' => _('New'),
'none' => _('None'), 'none' => _('None'),
'normal' => _('Normal'), 'normal' => _('Normal'),
@@ -590,16 +594,19 @@ function get_enum($enum) {
'plan' => _('Planned'), 'plan' => _('Planned'),
'precise' => _('Precise'), 'precise' => _('Precise'),
'project' => _('Project'), 'project' => _('Project'),
'quarter' => _('Quarter'),
'removed' => _('Removed'), 'removed' => _('Removed'),
'repairable' => _('Repairable'), 'repairable' => _('Repairable'),
'rough' => _('Rough'), 'rough' => _('Rough'),
'skipped' => _('Skipped'),
'storage' => _('Storage'), 'storage' => _('Storage'),
'task' => _('Task'), 'task' => _('Task'),
'tri' => _('Trimaran'), 'tri' => _('Trimaran'),
'unknown' => _('Unknown'), 'unknown' => _('Unknown'),
'user' => _('User'), 'user' => _('User'),
'vessel' => _('Vessel'), 'vessel' => _('Vessel'),
'waiting' => _('waiting') 'waiting' => _('Waiting'),
'week' => _('Week'),
); );
return $lookup[$enum] ?? $enum; return $lookup[$enum] ?? $enum;
} }
+293 -250
View File
File diff suppressed because it is too large. Load diff
Binary file not shown.
+67 -18
View File
@@ -16,6 +16,23 @@ $id = gpc_get_int($_REQUEST, 'id', 0);
$opt_equipment = db_get_opt_equip($user->vid); $opt_equipment = db_get_opt_equip($user->vid);
$opt_state = db_load_enum('maintenance', 'maintstate', true, true); $opt_state = db_load_enum('maintenance', 'maintstate', true, true);
$opt_planprec = db_load_enum('maintenance', 'plan_precision', true, true);
// series definition is derived from first maintenance record by plan_date
$opt_series = array();
$sql = "SELECT series, activities "
. "FROM ("
. "SELECT series, activities, "
. "ROW_NUMBER() OVER (PARTITION BY series ORDER BY plan_date ASC) AS n "
. "FROM maintenance "
. "WHERE series>0"
. ") AS ranked "
. "WHERE n=1";
$sth = $pdo->query($sql);
$res = $sth->fetchAll();
foreach ($res as $row) {
$opt_series[$row['series']] = $row['activities'];
}
// ========== ACTIONS START =================================================== // ========== ACTIONS START ===================================================
@@ -31,6 +48,7 @@ switch ($submit = form_get_action()) {
case 'filter': case 'filter':
$flt = array(); $flt = array();
$flt['equip'] = gpc_get_int($_POST, 'flt_equip'); $flt['equip'] = gpc_get_int($_POST, 'flt_equip');
$flt['series'] = gpc_get_int($_POST, 'flt_series');
$flt['txt'] = gpc_get_string($_POST, 'flt_txt'); $flt['txt'] = gpc_get_string($_POST, 'flt_txt');
$allowed = db_load_enum('maintenance', 'maintstate'); $allowed = db_load_enum('maintenance', 'maintstate');
$flt['status'] = gpc_get_set($_POST, 'flt_status', $allowed); $flt['status'] = gpc_get_set($_POST, 'flt_status', $allowed);
@@ -55,11 +73,33 @@ switch ($submit = form_get_action()) {
$p[':maintid'] = $id; $p[':maintid'] = $id;
$p[':eid'] = gpc_get_int($_POST, 'eid'); $p[':eid'] = gpc_get_int($_POST, 'eid');
$p[':activities'] = gpc_get_string($_POST, 'activities', 80); $p[':activities'] = gpc_get_string($_POST, 'activities', 80);
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150); $series = gpc_get_int($_POST, 'series');
$p[':series'] = gpc_get_int($_POST, 'series'); if ($series == -3) {
// new series number by automatic
// TODO generic db function to create a new int val in column
$sql = "SELECT MIN(n.series) AS next_series "
. "FROM ("
. "SELECT 1 AS series "
. "UNION ALL "
. "SELECT DISTINCT series + 1 "
. "FROM maintenance "
. "WHERE series > 0"
. ") AS n "
. "LEFT JOIN maintenance m ON m.series=n.series "
. "WHERE m.series IS NULL";
$p[':series'] = $pdo->query($sql)->fetchColumn();
} else if ($series <= 0) {
$p[':series'] = NULL;
} else {
$p[':series'] = $series;
}
$p[':plan_date'] = gpc_get_date($_POST, 'plan_date'); $p[':plan_date'] = gpc_get_date($_POST, 'plan_date');
$p[':plan_precision'] = gpc_get_enum($_POST, 'plan_precision', array_keys($opt_planprec));
$p[':interval_hours'] = gpc_get_int($_POST, 'interval_hours');
$p[':last_hours'] = gpc_get_int($_POST, 'last_hours');
$p[':completion_date'] = gpc_get_date($_POST, 'completion_date'); $p[':completion_date'] = gpc_get_date($_POST, 'completion_date');
$p[':maintstate'] = gpc_get_string($_POST, 'maintstate'); $p[':maintstate'] = gpc_get_string($_POST, 'maintstate');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('maintenance', $p, 'maintid'); db_exec_update('maintenance', $p, 'maintid');
$action = ACT_VIEW; $action = ACT_VIEW;
break; break;
@@ -84,13 +124,14 @@ if ($action == ACT_DEFAULT):
page_caption_search($pagetitle); page_caption_search($pagetitle);
// load filter from db // load filter from db
$flt = db_get_filter($user->id, 204, ['equip','txt']); $flt = db_get_filter($user->id, 204, ['equip','series','txt']);
// Filter // Filter
$opt_special = array( $opt_special = array(
-2 => _('&horbar; all &horbar;'), -2 => _('&horbar; all &horbar;'),
-1 => _('&horbar; none &horbar;') -1 => _('&horbar; none &horbar;')
); );
?> ?>
<form method="post" action="<?=$g_scriptname?>"> <form method="post" action="<?=$g_scriptname?>">
<div id="filter" class="card"> <div id="filter" class="card">
@@ -110,6 +151,9 @@ foreach ($opt_special + $opt_equipment as $k => $v) {
?> ?>
</select> </select>
</div> </div>
<?php
filter_create_select('flt_series', _('Series'), $g_opt_all + $g_opt_none + $opt_series, $flt->series);
?>
<div class="d-flex flex-nowrap gap-2"> <div class="d-flex flex-nowrap gap-2">
<label for="flt_txt">Text</label> <label for="flt_txt">Text</label>
<input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?? ''?>"> <input type="text" class="form-control" name="flt_txt" maxlength="30" value="<?=$flt->txt ?? ''?>">
@@ -140,13 +184,18 @@ if (isset($flt->equip) and ($flt->equip == -1 or $flt->equip == 0)) {
$w[] = 'm.eid=:eid'; $w[] = 'm.eid=:eid';
$p[':eid'] = $flt->equip; $p[':eid'] = $flt->equip;
} }
if (isset($flt->series) and ($flt->series == -1)) {
$w[] = 'm.series IS NULL';
} elseif($flt->series > 0) {
$w[] = 'm.series=:series';
$p[':series'] = $flt->series;
}
if (strlen($flt->txt) > 1) { if (strlen($flt->txt) > 1) {
$w[] = '(m.activities LIKE :txt OR m.remarks LIKE :txt)'; $w[] = '(m.activities LIKE :txt OR m.remarks LIKE :txt)';
$p[':txt'] = '%'.$flt->txt.'%'; $p[':txt'] = '%'.$flt->txt.'%';
} }
// condition for multiple flags is OR // condition for multiple flags is OR
// $parts = ["maintstate=''", 'maintstate IS NULL']; $parts = ['maintstate IS NULL']; // to get empty result
$parts = [];
foreach ($flt->status as $s) { foreach ($flt->status as $s) {
$parts[] = "maintstate='$s'"; $parts[] = "maintstate='$s'";
} }
@@ -182,7 +231,6 @@ $sql = "SELECT m.maintid, m.activities, m.plan_date, m.interval_hours, m.maintst
$sql .= ' WHERE ' . $where; $sql .= ' WHERE ' . $where;
$sql .= $order; $sql .= $order;
// if pagination: // if pagination:
$sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp; $sql .= ' LIMIT ' . ($page - 1) * $rows_pp . ',' . $rows_pp;
@@ -217,8 +265,8 @@ foreach ($res as $row) {
echo "<td>", h($row['activities']) ,"</td>\n"; echo "<td>", h($row['activities']) ,"</td>\n";
echo "<td>", $row['ename'] ,"</td>\n"; echo "<td>", $row['ename'] ,"</td>\n";
// next plan date or hours // next plan date or hours
echo "<td>", $row['plan_date'], "</td>\n"; echo "<td>", format_date($row['plan_date']), "</td>\n";
echo "<td>", $row['maintstate'], "</td>\n"; echo "<td>", get_enum($row['maintstate']), "</td>\n";
echo "<td>", h($row['remarks']) ,"</td>\n"; echo "<td>", h($row['remarks']) ,"</td>\n";
echo "<td>"; echo "<td>";
// Edit current record button // Edit current record button
@@ -275,7 +323,8 @@ echo '<h2>', _('View Maintenance'), "</h2>\n";
// load maintenance record // load maintenance record
$sql = "SELECT m.activities, m.eid, m.remarks, m.series, m.maintstate, e.ename, " $sql = "SELECT m.activities, m.eid, m.remarks, m.series, m.maintstate, e.ename, "
. "m.plan_date, m.completion_date, m.interval_hours, m.last_hours " . "m.plan_date, m.plan_precision, m.completion_date, m.interval_hours, "
. "m.last_hours "
. "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) " . "FROM maintenance AS m LEFT OUTER JOIN equipment AS e USING (eid) "
. "WHERE m.maintid=?"; . "WHERE m.maintid=?";
$sth = $pdo->prepare($sql); $sth = $pdo->prepare($sql);
@@ -313,6 +362,7 @@ echo '<tr><th>', _('Series'),"</th><td>", $maint->series, "</td></tr>\n";
echo '<tr><th>', _('Interval'),"</th><td>", $maint->interval_hours, " h</td></tr>\n"; echo '<tr><th>', _('Interval'),"</th><td>", $maint->interval_hours, " h</td></tr>\n";
echo '<tr><th>', _('Last'),"</th><td>", $maint->last_hours, "</td></tr>\n"; echo '<tr><th>', _('Last'),"</th><td>", $maint->last_hours, "</td></tr>\n";
echo '<tr><th>', _('Plan date'),"</th><td>", format_date($maint->plan_date), "</td></tr>\n"; echo '<tr><th>', _('Plan date'),"</th><td>", format_date($maint->plan_date), "</td></tr>\n";
echo '<tr><th>', _('Plan date precision'),"</th><td>", get_enum($maint->plan_precision), "</td></tr>\n";
echo '<tr><th>', _('Completion&nbsp;date'),"</th><td>", format_date($maint->completion_date), "</td></tr>\n"; echo '<tr><th>', _('Completion&nbsp;date'),"</th><td>", format_date($maint->completion_date), "</td></tr>\n";
echo '<tr><th scope="row">', _('State'),"</th><td>", get_enum($maint->maintstate), "</td></tr>\n"; echo '<tr><th scope="row">', _('State'),"</th><td>", get_enum($maint->maintstate), "</td></tr>\n";
@@ -397,15 +447,10 @@ echo '<h2>', _('Edit Maintenance'), "</h2>\n";
<label for="activities" class="form-label"><?=_('Activities')?></label> <label for="activities" class="form-label"><?=_('Activities')?></label>
<input type="text" class="form-control" id="activities" name="activities" value="<?=h($maint->activities)?>"> <input type="text" class="form-control" id="activities" name="activities" value="<?=h($maint->activities)?>">
</div> </div>
<?php form_create_select('eid', _('Equipment'), $opt_equipment, $maint->eid); ?> <?php
<div class="mb-3"> form_create_select('eid', _('Equipment'), $opt_equipment, $maint->eid);
<label for="remarks" class="form-label"><?=_('Remarks')?></label> form_create_select('series', _('Series'), $g_opt_none + $g_opt_new + $opt_series, $maint->series);
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=h($maint->remarks)?></textarea> ?>
</div>
<div class="mb-3">
<label for="series" class="form-label"><?=_('Series')?></label>
<input type="text" class="form-control" id="series" name="series" maxlength="4" value="<?=$maint->series ?>">
</div>
<div class="mb-3"> <div class="mb-3">
<label for="interval_hours" class="form-label"><?=_('Interval hours')?></label> <label for="interval_hours" class="form-label"><?=_('Interval hours')?></label>
<input type="number" class="form-control" id="interval_hours" name="interval_hours" inputmode="numeric" maxlength="6" value="<?=$maint->interval_hours ?>"> <input type="number" class="form-control" id="interval_hours" name="interval_hours" inputmode="numeric" maxlength="6" value="<?=$maint->interval_hours ?>">
@@ -418,12 +463,16 @@ echo '<h2>', _('Edit Maintenance'), "</h2>\n";
<label for="plan_date"><?=_('Plan date')?></label> <label for="plan_date"><?=_('Plan date')?></label>
<input type="date" class="form-control" id="plan_date" name="plan_date" value="<?=$maint->plan_date ?>"> <input type="date" class="form-control" id="plan_date" name="plan_date" value="<?=$maint->plan_date ?>">
</div> </div>
<?php
form_create_select('plan_precision', _('Date plan precision'), $opt_planprec, $maint->plan_precision);
?>
<div class="mb-3"> <div class="mb-3">
<label for="completion_date"><?=_('Completion date')?></label> <label for="completion_date"><?=_('Completion date')?></label>
<input type="date" class="form-control" id="completion_date" name="completion_date" value="<?=$maint->completion_date ?>"> <input type="date" class="form-control" id="completion_date" name="completion_date" value="<?=$maint->completion_date ?>">
</div> </div>
<?php <?php
form_create_select('maintstate', _('Status'), $opt_state, $maint->maintstate); form_create_select('maintstate', _('Status'), $opt_state, $maint->maintstate);
form_create_textarea('remarks', _('Remarks'), 3, 150, $maint->remarks);
form_edit_buttons($g_scriptname, $id); form_edit_buttons($g_scriptname, $id);
echo "</form>\n"; echo "</form>\n";
+2 -1
View File
@@ -153,7 +153,8 @@ $lastpage = ceil($numrows/$rows_pp);
// $grandtotal = $pdo->query("SELECT COUNT(*) FROM project WHERE " . $where)->fetchColumn(); // $grandtotal = $pdo->query("SELECT COUNT(*) FROM project WHERE " . $where)->fetchColumn();
$sql = "SELECT projid, projname, startdate, duration, projstate, remarks " $sql = "SELECT projid, projname, startdate, duration, projstate, "
. " IF(CHAR_LENGTH(remarks)>30, CONCAT(LEFT(remarks, 30), '\u{2026}'), remarks) AS remarks "
. "FROM project"; . "FROM project";
$sql .= " WHERE " . $where; $sql .= " WHERE " . $where;
$sql .= $order; $sql .= $order;