diff --git a/action.php b/action.php index 6e375fb..79378fd 100644 --- a/action.php +++ b/action.php @@ -47,6 +47,13 @@ switch ($VARS['action']) { } if (is_empty($VARS['qty'])) { $VARS['qty'] = 1; + } else if (!is_numeric($VARS['qty'])) { + returnToSender('field_nan'); + } + if (is_empty($VARS['want'])) { + $VARS['want'] = 0; + } else if (!is_numeric($VARS['want'])) { + returnToSender('field_nan'); } if (!$database->has('categories', ['catid' => $VARS['cat']])) { returnToSender('invalid_category'); @@ -71,6 +78,7 @@ switch ($VARS['action']) { 'catid' => $VARS['cat'], 'locid' => $VARS['loc'], 'qty' => $VARS['qty'], + 'want' => $VARS['want'], 'userid' => $userid ]; diff --git a/database.mwb b/database.mwb index d435fec..bcb3d74 100644 Binary files a/database.mwb and b/database.mwb differ diff --git a/lang/en_us.php b/lang/en_us.php index 3fadc65..5730f3c 100644 --- a/lang/en_us.php +++ b/lang/en_us.php @@ -77,5 +77,12 @@ define("STRINGS", [ "placeholder location name" => "Over the Hills", "description" => "Description", "notes" => "Notes", - "comments" => "Comments" + "comments" => "Comments", + "minwant" => "Minimum On Hand", + "want" => "Need", + "field not a number" => "You entered something that isn't a number when a number was expected.", + "understocked items" => "Understocked Items", + "view understocked" => "View Understocked", + "only showing understocked" => "Only showing understocked items.", + "show all items" => "Show all items" ]); \ No newline at end of file diff --git a/lang/messages.php b/lang/messages.php index 055b753..52ed211 100644 --- a/lang/messages.php +++ b/lang/messages.php @@ -69,4 +69,8 @@ define("MESSAGES", [ "string" => "location in use", "type" => "danger" ], + "field_nan" => [ + "string" => "field not a number", + "type" => "danger" + ] ]); diff --git a/lib/getitemtable.php b/lib/getitemtable.php index 1f58cb0..c8240e7 100644 --- a/lib/getitemtable.php +++ b/lib/getitemtable.php @@ -8,11 +8,18 @@ require_once __DIR__ . '/userinfo.php'; header("Content-Type: application/json"); +$showwant = ($VARS['show_want'] == 1); + $out = []; $out['draw'] = intval($VARS['draw']); -$out['recordsTotal'] = $database->count('items'); +if ($showwant) { + $out['recordsTotal'] = $database->count('items', ["AND" => ["qty[<]want", "want[>]" => 0]]); +} else { + $out['recordsTotal'] = $database->count('items'); +} + $filter = false; // sort @@ -40,25 +47,33 @@ switch ($VARS['order'][0]['column']) { case 7: $order = ["qty" => $sortby]; break; + case 8: + $order = ["want" => $sortby]; + break; // Note: We're not going to sort by assigned user. It's too hard. Maybe later. } // search if (!is_empty($VARS['search']['value'])) { $filter = true; - $wherenolimit = [ - "OR" => [ - "name[~]" => $VARS['search']['value'], - "catname[~]" => $VARS['search']['value'], - "locname[~]" => $VARS['search']['value'], - "code1[~]" => $VARS['search']['value'], - "code2[~]" => $VARS['search']['value'] - ] + $wherenolimit = []; + if ($showwant) { + $wherenolimit["AND"] = ["qty[<]want", "want[>]" => 0]; + } + $wherenolimit["AND"]["OR"] = [ + "name[~]" => $VARS['search']['value'], + "catname[~]" => $VARS['search']['value'], + "locname[~]" => $VARS['search']['value'], + "code1[~]" => $VARS['search']['value'], + "code2[~]" => $VARS['search']['value'] ]; $where = $wherenolimit; $where["LIMIT"] = [$VARS['start'], $VARS['length']]; } else { $where = ["LIMIT" => [$VARS['start'], $VARS['length']]]; + if ($showwant) { + $where["AND"] = ["qty[<]want", "want[>]" => 0]; + } } if (!is_null($order)) { $where["ORDER"] = $order; @@ -77,6 +92,7 @@ $items = $database->select('items', [ 'code1', 'code2', 'qty', + 'want', 'userid' ], $where); diff --git a/pages/edititem.php b/pages/edititem.php index eeed64f..e092ce3 100644 --- a/pages/edititem.php +++ b/pages/edititem.php @@ -18,6 +18,7 @@ $itemdata = [ 'text2' => '', 'text3' => '', 'qty' => 1, + 'want' => 0, 'userid' => '']; $editing = false; @@ -46,6 +47,7 @@ if (!is_empty($VARS['id'])) { 'locname', 'loccode', 'qty', + 'want', 'userid' ], [ 'itemid' => $VARS['id'] @@ -123,12 +125,18 @@ if (!is_empty($VARS['id'])) {
-
+
+
+
+ + +
+
diff --git a/pages/home.php b/pages/home.php index ab43ffe..90d28bd 100644 --- a/pages/home.php +++ b/pages/home.php @@ -11,29 +11,21 @@ redirectifnotloggedin();

count('items'); ?>

-
-
+ count('items', ["AND" => ["qty[<]want", "want[>]" => 0]]); + ?> +
"> +
-

count('locations'); ?>

+

-
-
-
-
-
-
-

count('categories'); ?>

-
-
diff --git a/pages/items.php b/pages/items.php index 83c9b39..f071c08 100644 --- a/pages/items.php +++ b/pages/items.php @@ -8,6 +8,13 @@ redirectifnotloggedin(); + + +
 
+var filter = null;\n"; +} +?> @@ -19,6 +26,7 @@ redirectifnotloggedin(); + @@ -36,6 +44,7 @@ redirectifnotloggedin(); 'code1', 'code2', 'qty', + 'want', 'userid' ], ["LIMIT" => 100]); $usercache = []; @@ -60,6 +69,7 @@ redirectifnotloggedin(); + + diff --git a/static/js/items.js b/static/js/items.js index 52e8d11..8e8000b 100644 --- a/static/js/items.js +++ b/static/js/items.js @@ -34,6 +34,11 @@ var itemtable = $('#itemtable').DataTable({ serverSide: true, ajax: { url: "lib/getitemtable.php", + data: function (d) { + if (filter == "stock") { + d.show_want = 1; + } + }, dataFilter: function (data) { var json = jQuery.parseJSON(data); json.data = []; @@ -47,6 +52,7 @@ var itemtable = $('#itemtable').DataTable({ row.code1, row.code2, row.qty, + row.want, row.username ]); });