Implemented an Items tab for attachments and modified the existing setup attachments.
authorJoe <joe.hunt.consulting@gmail.com>
Sun, 30 Apr 2023 11:38:11 +0000 (13:38 +0200)
committerJoe <joe.hunt.consulting@gmail.com>
Sun, 30 Apr 2023 11:38:11 +0000 (13:38 +0200)
admin/attachments.php
admin/db/attachments_db.inc
admin/db/transactions_db.inc
includes/sysnames.inc
includes/types.inc
includes/ui/attachment.inc
inventory/includes/db/items_db.inc
inventory/manage/items.php

index b3ad754532e165c5dab0a41bb5cb1e276962d871..c000990a7a8f95373e46bfe49a393ed07e9fa867 100644 (file)
@@ -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);
index e563dba3a7bba84dd5e6b9afb2691cba6e2c1b2e..bae91fe179507c00179e923ef42a8efcc22be420 100644 (file)
@@ -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";
index a948cf3e70a1b955547a471a4f5806aa54baf6ff..94b3cebe099625e4dd62a4628ec2b3d4a1972cdf 100644 (file)
@@ -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);
index 68828bca6242f5ff5c45f40dcde5a950245fb36b..b4ac947e71a5399bbeab8045f8bbbd647565de20 100644 (file)
@@ -43,6 +43,7 @@ $systypes_array = array (
        ST_DIMENSION => _("Dimension"),
        ST_CUSTOMER => _("Customer"),
        ST_SUPPLIER => _("Supplier"),
+       ST_ITEM => _("Item")
        );
 
 $fa_systypes_array = array (
index f5e26d13db7dd618bd1be5976298ba740e2aed47..ad151d14fa82f70fa9391a4fca471e64d9d37139 100644 (file)
@@ -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.
index 1ee3df126d4e94848bb1ab895fc81fd858096b6d..a2ed7f0f058611db6b3ecac9739f5eac7c99107a 100644 (file)
@@ -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');
index 02345a67edfad638868a5fb86e06bb6d5b2863f1..b61f4140e2f47b157749bf1bde269b85f9e15c9f 100644 (file)
@@ -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
index 5497838254b515ee22444ab33e8009376406733d..1683ece7cdf4b4d7acc6703215b449bce7b35240 100644 (file)
@@ -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 = "";      
        }
 }
+