Added default storage to vessel and some other fixes

This commit is contained in:
2026-07-20 13:05:15 +02:00
parent a01329fdab
commit 562aa587ad
10 changed files with 205 additions and 25 deletions
+1
View File
@@ -74,6 +74,7 @@ CREATE TABLE vessel (
beltpos_aft float(4,2) UNSIGNED DEFAULT NULL,
beltpos_bow float(4,2) UNSIGNED DEFAULT NULL,
shapefile varchar(40) DEFAULT NULL,
sid_default smallint(6) UNSIGNED DEFAULT NULL, -- default storage
remarks varchar(150) DEFAULT NULL,
PRIMARY KEY (vid)
) ENGINE=InnoDB;
+1 -1
View File
@@ -70,7 +70,7 @@ INSERT INTO dropdown (ddid, ddval, ddtext) VALUES
INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES
(2, 1, 'Supplier', 'fixed'),
(2, 2, 'Manufacturer', 'fixed'),
(2, 3, 'Shipyard', fixed),
(2, 3, 'Shipyard', 'fixed'),
(2, 9, 'Generic', 'fixed');
INSERT INTO dropdown (ddid, ddval, ddtext, flags) VALUES
+5 -2
View File
@@ -20,6 +20,7 @@ $pagetitle = _('Boxes');
$id = gpc_get_int($_REQUEST, 'id', 0);
// TODO use global function
// Storage options
$sql = "SELECT sid, sname FROM storage WHERE vid=? ORDER BY sname";
$sth = $pdo->prepare($sql);
@@ -44,7 +45,7 @@ switch ($submit = form_get_action()) {
case 'insert':
$p[':label'] = gpc_get_string($_POST, 'label');
$p[':sid'] = gpc_get_int($_POST, 'sid');
$p[':sid'] = gpc_get_uint($_POST, 'sid');
$p[':content'] = gpc_get_string($_POST, 'content');
$p[':remarks'] = gpc_get_string($_POST, 'remarks');
$id = db_exec_insert('box', $p);
@@ -59,6 +60,7 @@ switch ($submit = form_get_action()) {
$p[':content'] = gpc_get_string($_POST, 'content');
$p[':color'] = gpc_get_color($_POST, 'color');
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 99.99);
$p[':sid'] = gpc_get_uint($_POST, 'sid');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('box', $p, 'boxid');
$action = ACT_VIEW;
@@ -231,7 +233,7 @@ if ($res) {
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
$sql = "SELECT boxtype, label, content, color, weight, remarks "
$sql = "SELECT boxtype, label, content, color, weight, sid, remarks "
. "FROM box "
. "WHERE boxid=?";
$sth = $pdo->prepare($sql);
@@ -261,6 +263,7 @@ echo '<h2>', _('Edit Box'), "</h2>\n";
<label for="weight" class="form-label"><?=_('Weight, kg')?></label>
<input type="text" class="form-control" id="weight" name="weight" value="<?=format_float($box->weight); ?>">
</div>
<?php form_create_select('sid', _('Storage'), $opt_storage, $box->sid); ?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$box->remarks ?></textarea>
+36 -1
View File
@@ -128,6 +128,7 @@ $g_doc_mimetypes = ['image/png', 'image/jpeg', 'image/svg+xml', 'application/pdf
// form option lists
$g_opt_all = array(-2 => _('&horbar; all &horbar;'));
$g_opt_none = array(-1 => _('&horbar; none &horbar;'));
$g_opt_empty = array('' => _('&horbar; none &horbar;'));
$g_opt_unknown = array(-1 => _('&horbar; unknown &horbar;'));
// Initialize message system
@@ -392,6 +393,7 @@ function db_exec_insert($table, $params) {
$g_error->Add('SQL-Error: '. $e->getMessage());
$g_error->Add($sql);
$g_error->Add(print_r($params, true));
return false;
}
return $pdo->LastInsertId();
}
@@ -772,7 +774,6 @@ function db_get_opt_vessel() {
return $list;
}
function db_get_opt_storage($vid) {
global $pdo;
global $g_error;
@@ -927,6 +928,40 @@ function db_get_filter($user, $sno, $fields = []) {
return $flt;
}
function db_get_default_storage($vesselid, $fallback=true) {
global $pdo;
global $g_error, $g_warning;
$sql = "SELECT sid_default FROM vessel WHERE vid=?";
$sth = $pdo->prepare($sql);
try {
$sth->execute([$vesselid]);
} catch(PDOException $e) {
$g_error->Add($e->getMessage());
return false;
}
$sid = $sth->fetchColumn();
if ($sid == NULL && $fallback) {
// try to get another storage as last fallback
$g_warning->Add(_('No default storage defined for current vessel'));
$sql = "SELECT MIN(sid), sname FROM storage WHERE vid=?";
$sth = $pdo->prepare($sql);
try {
$sth->execute([$vesselid]);
} catch(PDOException $e) {
$g_error->Add($e->getMessage());
return false;
}
$row = $sth->fetch(PDO::FETCH_NUM);
if ($row[0] == NULL) {
$g_error->Add('Error: No storage defined for current vessel');
return false;
}
$sid = $row[0];
$g_warning->Add(sprintf(_("Selected fallback storage '%s'"), $row[1]));
}
return $sid;
}
function date_to_sql($var) {
if (!isset($var) || $var == '') {
return NULL;
+33 -6
View File
@@ -79,6 +79,7 @@ switch ($submit = form_get_action()) {
$p[':shapefile'] = NULL;
}
$p[':shipyard'] = gpc_get_int($_POST, 'shipyard');
$p[':sid_default'] = gpc_get_uint($_POST, 'sid');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('vessel', $p, 'vid');
$action = ACT_DEFAULT;
@@ -448,13 +449,37 @@ echo '<h2>', _('Add additional yacht'), "</h2>\n";
elseif ($action == ACT_EDIT):
// ========== VARIANT: edit single record =====================================
// get list of shapefiles
//$opt_shapefiles = array('' => _('--- none ---'));
$opt_shapefiles = $g_opt_none;
// check if there is a shapefile-index
$shapeindexfile = $g_doc_basepath . '/shapeindex.json';
$shapeindex = [];
if (!file_exists($shapeindexfile)) {
// try to read metadata from top of svg file
foreach (glob($g_shapedir.'/*.svg') as $f) {
$f = basename($f);
$opt_shapefiles[$f] = $f;
$fh = fopen($f, 'r');
$fname = basename($f);
$header = fread($fh, 1024);
if (preg_match('/<title[^>]*>(.*?)<\/title>/is', $header, $match)) {
$title = trim($match[1]);
} else {
$title = $fname;
}
$shapeindex[$fname] = $title;
fclose($fh);
}
$json = json_encode($shapeindex, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
file_put_contents($shapeindexfile, $json);
} else {
// read svg metadata from existing file
$json = file_get_contents($shapeindexfile);
$shapeindex = json_decode($json, true);
if (json_last_error() !== JSON_ERROR_NONE) {
// TODO some kind of error and fallback
// perhaps regenerate index file?
}
}
$opt_shapefiles = $g_opt_none + $shapeindex;
$opt_storage = db_get_opt_storage($user->vid);
$opt_shipyard = $g_opt_none + [-3 => _('&horbar; Custom-built &horbar;')];
$sql = "SELECT compid, compname FROM company WHERE comptype=3 ORDER BY compname";
@@ -465,7 +490,7 @@ foreach ($sth->fetchAll(PDO::FETCH_NUM) as $row) {
$sql = "SELECT vesselname, vtype, model, loa, lwl, beam, draught, draught_min,"
. " displacement, ballast, beltpos_aft, beltpos_bow, shapefile,"
. " shipyard, remarks "
. " shipyard, sid_default, remarks "
. "FROM vessel "
. "WHERE vid=?";
$sth = $pdo->prepare($sql);
@@ -526,6 +551,8 @@ $vessel = $sth->fetch(PDO::FETCH_OBJ);
</div> */
form_create_select('shapefile', _('Shape file'), $opt_shapefiles, $vessel->shapefile);
form_create_select('shipyard', _('Shipyard'), $opt_shipyard, $vessel->shipyard);
form_create_select('sid', _('Default Storage'), $g_opt_none + $opt_storage, $vessel->sid_default);
?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
+26 -6
View File
@@ -48,9 +48,18 @@ switch ($submit = form_get_action()) {
$p[':invname'] = gpc_get_string($_POST, 'invname');
$p[':number'] = gpc_get_int($_POST, 'number');
$p[':conttype'] = gpc_get_string($_POST, 'conttype');
$p[':sid'] = gpc_get_int($_POST, 'sid');
$p[':boxid'] = gpc_get_int($_POST, 'boxid');
$p[':invcond'] = 'good';
$p[':sid'] = gpc_get_uint($_POST, 'sid', 0);
$p[':boxid'] = gpc_get_uint($_POST, 'boxid', 0);
if ($p[':sid'] == NULL && $p[':boxid'] == NULL) {
$p[':conttype'] = 'storage';
$sid = db_get_default_storage($user->vid);
if ($sid === false) {
$action = ACT_ADD;
break;
}
$p[':sid'] = $sid;
}
$p[':invcond'] = 'unknown';
$id = db_exec_insert('inventory', $p);
$action = ACT_VIEW;
break;
@@ -60,8 +69,17 @@ switch ($submit = form_get_action()) {
$p[':invname'] = gpc_get_string($_POST, 'invname');
$p[':number'] = gpc_get_int($_POST, 'number');
$p[':conttype'] = gpc_get_string($_POST, 'conttype');
$p[':sid'] = gpc_get_int($_POST, 'sid');
$p[':boxid'] = gpc_get_int($_POST, 'boxid');
$p[':sid'] = gpc_get_uint($_POST, 'sid', 0);
$p[':boxid'] = gpc_get_uint($_POST, 'boxid', 0);
if ($p[':sid'] == NULL && $p[':boxid'] == NULL) {
$p[':conttype'] = 'storage';
$sid = db_get_default_storage($user->vid);
if ($sid === false) {
$action = ACT_VIEW;
break;
}
$p[':sid'] = $sid;
}
$p[':weight'] = min(gpc_get_float($_POST, 'weight'), 999.99); // limit max value
$p[':price'] = gpc_get_currency($_POST, 'price');
$p[':purchdate'] = gpc_get_date($_POST, 'purchdate');
@@ -351,7 +369,9 @@ echo '<table class="table">', "\n";
echo '<tr><th style="width:20%">', _('Box type'),"</th><td>", $inventory->conttype, "</td></tr>\n";
// Container with link
echo "<tr><th>", _('Container'),"</th><td>", sprintf(_('%s in %s'), $box['label'], $storagename);
echo '<tr><th>', $inventory->conttype == 'storage' ? _('Storage') : _('Container');
echo '</th><td>', sprintf(_('%s in %s'), $box['label'], $storagename);
// TODO insert link
echo "</td></tr>\n";
echo "<tr><th>", _('Location ID'), "</th><td>", $inventory->locationid, "</td></tr>\n";
+11
View File
@@ -30,6 +30,17 @@ function gpc_get_int(&$GPC, $varname, $default = NULL) {
return (int)$GPC[$varname];
}
function gpc_get_uint(&$GPC, $varname, $default = NULL) {
if (!isset($GPC[$varname])) {
return $default;
}
$val = (int)$GPC[$varname];
if ($val < 0) {
$val = $default;
}
return $val;
}
function gpc_get_float(&$GPC, $varname, $default = NULL) {
global $g_lconv;
if (!isset($GPC[$varname]) or (strlen(trim($GPC[$varname])) == 0)) {
+8 -2
View File
@@ -330,15 +330,21 @@ if (empty($res)) {
<tr>
<th>#</th>
<th><?=_('Task')?></th>
<th></th>
</tr>
</thead>
<?php
$i = 1;
foreach ($res as $row) {
echo "<tr>";
echo "<td>", $i++, "</td>";
echo "<td>", $i++;
echo '<a class="text-nowrap" title="', _('View'), '" href="task.php?f=view&id=', $row['taskid'], '"><i class="bi bi-eye ms-2"></i></a>', "\n";
echo "</td>";
echo "<td>", $row['taskname'], "</td>";
form_action_buttons('task.php', $row['taskid']);
// Edit current record button
echo "<td>";
echo '<a title="', _('Edit'), '" href="task.php?f=edit&id=', $row['taskid'], '"><i class="bi-pencil"></i></a>', "\n";
echo "</td>\n";
echo "</tr>\n";
} // endforeach;
echo "</table>\n";
+63
View File
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="1023.9999"
height="412"
viewBox="0 0 270.93331 109.00834"
version="1.1"
id="svg5"
xml:space="preserve"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"><title
id="title1472">Etap 23</title><defs
id="defs2" /><metadata
id="metadata307"><rdf:RDF><cc:Work
rdf:about=""><dc:title>Etap 23</dc:title></cc:Work></rdf:RDF></metadata><g
id="layer3"><path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="m 0.86350443,56.194479 c 0,0 0.69516577,-14.052372 2.35183327,-20.194909 1.6566675,-6.142538 7.2458203,-17.836033 7.2458203,-17.836033 0,0 26.514024,-8.2805452 34.450621,-9.6979403 12.412423,-2.2167318 31.13408,-6.4342996 53.931466,-6.3070386 19.314615,0.1078193 53.094175,5.573439 76.283115,12.8907639 16.69715,5.268824 40.14414,13.436259 63.79504,23.921131 14.71032,6.521353 26.48827,13.146633 30.48785,15.138539 1.11012,0.552872 0.96357,2.01622 0.96357,2.01622"
id="path245" /><use
x="0"
y="0"
xlink:href="#path245"
id="use461"
transform="matrix(1,0,0,-1,-0.01141454,112.22431)" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529169;stroke-linecap:butt;stroke-linejoin:round;stroke-dasharray:2.11667, 1.05833, 0.529169, 1.05833;stroke-dashoffset:0;stroke-opacity:1"
d="M 8.579525e-7,56.091669 270.48373,56.091668"
id="path271" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529168;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 243.01026,40.79159 V 71.25056"
id="path1051-5-20-3-5" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529168;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 143.32867,7.3151282 V 53.180623"
id="path1051-5-20-3-5-3" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529168;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 143.01507,70.407464 V 105.23012"
id="path1051-5-20-3-5-3-1" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529168;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 117.33745,3.3521262 V 12.178617"
id="path1051-5-20-3-5-3-5" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529169;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 92.185244,2.3233771 V 12.236508"
id="path1051-5-20-3-5-3-5-3" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 66.584543,4.8189868 V 107.726"
id="path1051-5-20-3-5-3-6" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 143.50598,12.19599 H 66.434472"
id="path1051-5-20-3-5-3-6-7" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 66.45163,38.498153 H 9.4379737"
id="path1051-5-20-3-5-3-6-7-5" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 66.508118,69.931578 H 9.494461"
id="path1051-5-20-3-5-3-6-7-5-6" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 142.7458,70.803411 H 67.016281"
id="path1051-5-20-3-5-3-6-7-5-6-2" /><path
style="display:inline;fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.529167;stroke-linecap:butt;stroke-linejoin:miter;stroke-dasharray:none;stroke-opacity:1"
d="M 142.96058,38.598891 H 67.231062"
id="path1051-5-20-3-5-3-6-7-5-6-2-9" /></g></svg>

After

Width:  |  Height:  |  Size: 4.6 KiB

+16 -2
View File
@@ -14,6 +14,7 @@ $pagetitle = _('Storage');
$id = gpc_get_int($_REQUEST, 'id', 0);
$opt_stype = db_get_options(3);
$opt_capaunit = $g_opt_empty + db_load_enum('storage', 'capaunit', true, true);
// ========== ACTIONS START ===================================================
@@ -44,6 +45,10 @@ switch ($submit = form_get_action()) {
$p[':wx'] = gpc_get_int($_POST, 'wx');
$p[':wy'] = gpc_get_int($_POST, 'wy');
$p[':wz'] = gpc_get_int($_POST, 'wz');
$p[':angle'] = gpc_get_int($_POST, 'angle');
$p[':capacity'] = gpc_get_int($_POST, 'capacity');
if ($p[':capacity'] == 0) $p[':capacity'] = NULL;
$p[':capaunit'] = gpc_get_string($_POST, 'capaunit');
$p[':remarks'] = gpc_get_string($_POST, 'remarks', 150);
db_exec_update('storage', $p, 'sid');
$action = ACT_VIEW;
@@ -180,7 +185,7 @@ foreach ($res as $row) {
}
// Table summary
$numrows = count($res);
table_rec_summary($i, $numrows, $numrows, 4);
table_rec_summary($i, $numrows, $numrows, 5);
echo "</table>\n";
form_add_button('box.php');
@@ -277,7 +282,7 @@ elseif ($action == ACT_EDIT):
echo '<h2>', _('Edit Storage'), "</h2>\n";
$sql = "SELECT sid, sname, stype, x, y, z, wx, wy, wz, remarks "
$sql = "SELECT sid, sname, stype, x, y, z, wx, wy, wz, angle, capacity, capaunit, remarks "
. "FROM storage "
. "WHERE sid=?";
$sth = $pdo->prepare($sql);
@@ -322,6 +327,15 @@ form_create_select('stype', _('Type'), $opt_stype, $storage->stype);
</div>
</div>
</div>
<div class="mb-3">
<label for="angle" class="form-label"><?=_('Angle, deg.')?></label>
<input type="number" class="form-control" id="angle" name="angle" value="<?=$storage->angle ?>">
</div>
<div class="mb-3">
<label for="capacity" class="form-label"><?=_('Capacity')?></label>
<input type="number" class="form-control" id="capacity" name="capacity" value="<?=$storage->capacity ?>">
</div>
<?php form_create_select('capaunit', _('Capacity Unit'), $opt_capaunit, $storage->capaunit); ?>
<div class="mb-3">
<label for="remarks" class="form-label"><?=_('Remarks')?></label>
<textarea class="form-control" id="remarks" name="remarks" rows="3"><?=$storage->remarks ?></textarea>