From d1de4b72e5fa6b5952c75b7c79479935bdd0d9d8 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 30 Apr 2023 13:38:11 +0200 Subject: [PATCH] Implemented an Items tab for attachments and modified the existing setup attachments. --- admin/attachments.php | 22 +++++++++++++++------- admin/db/attachments_db.inc | 2 +- admin/db/transactions_db.inc | 1 + includes/sysnames.inc | 1 + includes/types.inc | 1 + includes/ui/attachment.inc | 2 ++ inventory/includes/db/items_db.inc | 12 ++++++++++++ inventory/manage/items.php | 9 +++++++++ 8 files changed, 42 insertions(+), 8 deletions(-) diff --git a/admin/attachments.php b/admin/attachments.php index b3ad7545..c000990a 100644 --- a/admin/attachments.php +++ b/admin/attachments.php @@ -20,6 +20,7 @@ include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/data_checks.inc"); include_once($path_to_root . "/admin/db/attachments_db.inc"); include_once($path_to_root . "/admin/db/transactions_db.inc"); +include_once($path_to_root . "/inventory/includes/db/items_db.inc"); if (isset($_GET['vw'])) $view_id = $_GET['vw']; @@ -81,6 +82,8 @@ if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM') { $filename = basename($_FILES['filename']['name']); + if ($_POST['filterType'] == ST_ITEM && $Mode == 'ADD_ITEM') + $_POST['trans_no'] = get_item_code_id($_POST['trans_no']); if (!transaction_exists($_POST['filterType'], $_POST['trans_no'])) display_error(_("Selected transaction does not exists.")); elseif ($Mode == 'ADD_ITEM' && !in_array(strtoupper(substr($filename, strlen($filename) - 3)), array('JPG','PNG','GIF', 'PDF', 'DOC', 'ODT'))) @@ -184,6 +187,8 @@ function viewing_controls() customer_list_cells(_("Select a customer: "), 'trans_no', null, false, true, true); } elseif(get_post('filterType') == ST_SUPPLIER){ supplier_list_cells(_("Select a supplier: "), 'trans_no', null, false, true,true); + } elseif(get_post('filterType') == ST_ITEM){ + stock_items_list_cells(_("Select an Item: "), 'trans_no', null, false, true,true); } end_row(); @@ -193,6 +198,8 @@ function viewing_controls() function trans_view($trans) { + if ($type==ST_SUPPLIER || $type==ST_CUSTOMER || $type==ST_ITEM) + return $trans['id']; return get_trans_view_str($trans["type_no"], $trans["trans_no"]); } @@ -218,14 +225,15 @@ function delete_link($row) function display_rows($type, $trans_no) { - $sql = get_sql_for_attached_documents($type, $type==ST_SUPPLIER || $type==ST_CUSTOMER ? $trans_no : 0); + $sql = get_sql_for_attached_documents($type, $type==ST_SUPPLIER || $type==ST_CUSTOMER ? $trans_no : + ($type==ST_ITEM ? get_item_code_id($trans_no) : 0)); $cols = array( - _("#") => $type == ST_SUPPLIER || $type == ST_CUSTOMER? 'skip' : array('fun'=>'trans_view', 'ord'=>''), - _("Description") => array('name'=>'description'), + _("#") => array('fun'=>'trans_view', 'ord'=>''), + _("Doc Title") => array('name'=>'description'), _("Filename") => array('name'=>'filename'), _("Size") => array('name'=>'filesize'), _("Filetype") => array('name'=>'filetype'), - _("Date Uploaded") => array('name'=>'tran_date', 'type'=>'date'), + _("Doc Date") => array('name'=>'tran_date', 'type'=>'date', 'ord'=>''), array('insert'=>true, 'fun'=>'edit_link'), array('insert'=>true, 'fun'=>'view_link'), array('insert'=>true, 'fun'=>'download_link'), @@ -264,16 +272,16 @@ if ($selected_id != -1) $_POST['description'] = $row["description"]; hidden('trans_no', $row['trans_no']); hidden('unique_name', $row['unique_name']); - if ($type != ST_SUPPLIER && $type != ST_CUSTOMER) + if ($type != ST_SUPPLIER && $type != ST_CUSTOMER && $type != ST_ITEM) label_row(_("Transaction #"), $row['trans_no']); } hidden('selected_id', $selected_id); } else { - if ($type != ST_SUPPLIER && $type != ST_CUSTOMER) + if ($type != ST_SUPPLIER && $type != ST_CUSTOMER && $type != ST_ITEM) text_row_ex(_("Transaction #").':', 'trans_no', 10); } -text_row_ex(_("Description").':', 'description', 40); +text_row_ex(_("Doc Title").':', 'description', 40); file_row(_("Attached File") . ":", 'filename', 'filename'); end_table(1); diff --git a/admin/db/attachments_db.inc b/admin/db/attachments_db.inc index e563dba3..bae91fe1 100644 --- a/admin/db/attachments_db.inc +++ b/admin/db/attachments_db.inc @@ -104,7 +104,7 @@ function get_sql_for_attached_documents($type, $id_no) // $_POST['trans_no'] will be used to store the customer_id or supplier_id for them $sql = "SELECT trans_no, description, filename, filesize, filetype, tran_date, id, type_no FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type); - if(($type == ST_CUSTOMER || $type == ST_SUPPLIER) && $id_no != null) + if(($type == ST_CUSTOMER || $type == ST_SUPPLIER || $type == ST_ITEM) && $id_no != null) $sql .=" AND trans_no = ".db_escape($id_no); $sql .= " ORDER BY trans_no DESC"; diff --git a/admin/db/transactions_db.inc b/admin/db/transactions_db.inc index a948cf3e..94b3cebe 100644 --- a/admin/db/transactions_db.inc +++ b/admin/db/transactions_db.inc @@ -212,6 +212,7 @@ function get_systype_db_info($type) case ST_CUSTOMER : return array(TB_PREF."debtors_master", null, "debtor_no", "debtor_ref", null); case ST_SUPPLIER : return array(TB_PREF."suppliers", null, "supplier_id", "supp_ref", null); + case ST_ITEM : return array(TB_PREF."item_codes", null, "id", "stock_id", null); } display_db_error("invalid type ($type) sent to get_systype_db_info", "", true); diff --git a/includes/sysnames.inc b/includes/sysnames.inc index 68828bca..b4ac947e 100644 --- a/includes/sysnames.inc +++ b/includes/sysnames.inc @@ -43,6 +43,7 @@ $systypes_array = array ( ST_DIMENSION => _("Dimension"), ST_CUSTOMER => _("Customer"), ST_SUPPLIER => _("Supplier"), + ST_ITEM => _("Item") ); $fa_systypes_array = array ( diff --git a/includes/types.inc b/includes/types.inc index f5e26d13..ad151d14 100644 --- a/includes/types.inc +++ b/includes/types.inc @@ -48,6 +48,7 @@ define('ST_COSTUPDATE', 35); define('ST_DIMENSION', 40); define('ST_CUSTOMER', 41); define('ST_SUPPLIER', 42); +define('ST_ITEM', 43); // Don't include these defines in the $systypes_array. // They are used for documents only. diff --git a/includes/ui/attachment.inc b/includes/ui/attachment.inc index 1ee3df12..a2ed7f0f 100644 --- a/includes/ui/attachment.inc +++ b/includes/ui/attachment.inc @@ -131,6 +131,8 @@ class attachments extends simple_crud { $id_word = _("Customer ID"); elseif($type_no==ST_SUPPLIER) // 6 $id_word = _("Supplier ID"); + elseif($type_no==ST_ITEM) // 7 + $id_word = _("Item ID"); label_row(_($id_word), $_POST['trans_no']); date_row(_("Date"), 'tran_date'); diff --git a/inventory/includes/db/items_db.inc b/inventory/includes/db/items_db.inc index 02345a67..b61f4140 100644 --- a/inventory/includes/db/items_db.inc +++ b/inventory/includes/db/items_db.inc @@ -228,3 +228,15 @@ function get_items_search($description, $type) return db_query($sql, "Failed in retreiving item list."); } +function get_item_code_id($stock_id) +{ + $sql = "SELECT ic.id + FROM ".TB_PREF."item_codes ic, ".TB_PREF."stock_master sm + WHERE ic.item_code = ".db_escape($stock_id)." AND ic.item_code = ic.stock_id AND + ic.stock_id = sm.stock_id"; + + $result = db_query($sql, "could not get item id"); + $row = db_fetch_row($result); + + return is_array($row) ? $row[0] : false; +} \ No newline at end of file diff --git a/inventory/manage/items.php b/inventory/manage/items.php index 54978382..1683ece7 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -38,6 +38,7 @@ page($_SESSION['page_title'], @$_REQUEST['popup'], false, "", $js); include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/data_checks.inc"); +include_once($path_to_root . "/includes/ui/attachment.inc"); include_once($path_to_root . "/inventory/includes/inventory_db.inc"); include_once($path_to_root . "/fixed_assets/includes/fixed_assets_db.inc"); @@ -596,6 +597,7 @@ $tabs = (get_post('fixed_asset')) 'movement' => array(_('&Transactions'), (user_check_access('SA_ITEMSTRANSVIEW') && is_inventory_item($stock_id) ? $stock_id : null)), 'status' => array(_('&Status'), (user_check_access('SA_ITEMSSTATVIEW') ? $stock_id : null)), + 'attachments' => array(_('Attachments'), (user_check_access('SA_ATTACHDOCUMENT') ? get_item_code_id($stock_id) : null)), ); tabbed_content_start('tabs', $tabs); @@ -637,6 +639,12 @@ tabbed_content_start('tabs', $tabs); $_GET['stock_id'] = $stock_id; include_once($path_to_root."/inventory/inquiry/stock_status.php"); break; + case 'attachments': + $id = get_item_code_id($stock_id); + $_GET['trans_no'] = $id; + $_GET['type_no']= ST_ITEM; + $attachments = new attachments('attachment', $id, 'items'); + $attachments->show(); }; br(); @@ -692,3 +700,4 @@ function generateBarcode() { $tmpBarcodeID = ""; } } + -- 2.30.2