From 3d95c6844745f183ebab970251cd254dd6cbdcec Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 7 Oct 2019 23:40:55 +0200 Subject: [PATCH] Added new attachment types for customer and supplier specific documents. --- admin/attachments.php | 31 ++++++++++++++++++++++++------- admin/db/attachments_db.inc | 25 +++++++++++++++++-------- admin/db/transactions_db.inc | 3 +++ includes/sysnames.inc | 2 ++ includes/types.inc | 2 ++ purchasing/manage/suppliers.php | 13 ++++++++++--- sales/manage/customers.php | 13 ++++++++++--- 7 files changed, 68 insertions(+), 21 deletions(-) diff --git a/admin/attachments.php b/admin/attachments.php index e92276ed..565e4b1e 100644 --- a/admin/attachments.php +++ b/admin/attachments.php @@ -58,7 +58,7 @@ if ($download_id != -1) $type = ($row['filetype']) ? $row['filetype'] : 'application/octet-stream'; header("Content-type: ".$type); header('Content-Length: '.$row['filesize']); - header('Content-Disposition: attachment; filename='.$row['filename']); + header('Content-Disposition: attachment; filename="'.$row['filename'].'"'); echo file_get_contents(company_path()."/attachments/".$row['unique_name']); exit(); } @@ -79,6 +79,13 @@ if (isset($_GET['trans_no'])) if ($Mode == 'ADD_ITEM' || $Mode == 'UPDATE_ITEM') { + + if($_POST['filterType'] == ST_CUSTOMER){ + $_POST['trans_no'] = $_POST['customer_id']; + }elseif($_POST['filterType'] == ST_SUPPLIER){ + $_POST['trans_no'] = $_POST['supplier_id']; + } + if (!transaction_exists($_POST['filterType'], $_POST['trans_no'])) display_error(_("Selected transaction does not exists.")); elseif ($Mode == 'ADD_ITEM' && !isset($_FILES['filename'])) @@ -171,6 +178,12 @@ function viewing_controls() if (list_updated('filterType')) $selected_id = -1; + if(get_post('filterType') == ST_CUSTOMER ){ + customer_list_cells(_("Select a customer: "), 'customer_id', null, _('Select customer'), true, true); + } elseif(get_post('filterType') == ST_SUPPLIER){ + supplier_list_cells(_("Select a supplier: "), 'supplier_id', null, _('Select supplier'), true,true); + } + end_row(); end_table(1); @@ -201,9 +214,9 @@ function delete_link($row) return button('Delete'.$row["id"], _("Delete"), _("Delete"), ICON_DELETE); } -function display_rows($type) +function display_rows($type, $id_no) { - $sql = get_sql_for_attached_documents($type); + $sql = get_sql_for_attached_documents($type, $id_no); $cols = array( _("#") => array('fun'=>'trans_view', 'ord'=>''), _("Description") => array('name'=>'description'), @@ -228,8 +241,8 @@ function display_rows($type) start_form(true); viewing_controls(); - -display_rows($_POST['filterType']); +$id_no = ($_POST['filterType'] == ST_CUSTOMER) ? get_post('customer_id') : get_post('supplier_id'); +display_rows($_POST['filterType'], $id_no); br(2); @@ -248,8 +261,12 @@ if ($selected_id != -1) } hidden('selected_id', $selected_id); } -else - text_row_ex(_("Transaction #").':', 'trans_no', 10); +else { + if( $id_no == 0 ) + text_row_ex(_("Transaction #").':', 'trans_no', 10); + else + hidden('trans_no', $id_no); +} text_row_ex(_("Description").':', 'description', 40); file_row(_("Attached File") . ":", 'filename', 'filename'); diff --git a/admin/db/attachments_db.inc b/admin/db/attachments_db.inc index f3c46dc4..77d8d91e 100644 --- a/admin/db/attachments_db.inc +++ b/admin/db/attachments_db.inc @@ -21,7 +21,7 @@ function add_attachment($filterType, $trans_no, $description, .db_escape($trans_no).",".db_escape($description).", " .db_escape($filename).", ".db_escape($unique_name).", ".db_escape($filesize) .", ".db_escape($filetype).", '$date')"; - db_query($sql, "Attachment could not be inserted"); + db_query($sql, "Attachment could not be inserted"); } //---------------------------------------------------------------------------------------- @@ -41,7 +41,7 @@ function update_attachment($selected_id, $filterType, $trans_no, $description, filetype=".db_escape($filetype).","; } $sql .= "tran_date='$date' WHERE id=".db_escape($selected_id); - db_query($sql, "Attachment could not be updated"); + db_query($sql, "Attachment could not be updated"); } //---------------------------------------------------------------------------------------- @@ -72,10 +72,12 @@ function get_attachment_string($type, $id) //---------------------------------------------------------------------------------------- -function get_attached_documents($type) +function get_attached_documents($type, $trans_no=false) { - $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type) - ." ORDER BY trans_no"; + $sql = "SELECT * FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type); + if ($trans_no) + $sql .= " AND trans_no=".db_escape($trans_no); + $sql .= " ORDER BY trans_no"; return db_query($sql, "Could not retrieve attachments"); } @@ -97,10 +99,17 @@ function has_attachment($type, $id) return $myrow['id']; } -function get_sql_for_attached_documents($type) +function get_sql_for_attached_documents($type, $id_no) { - return "SELECT trans_no, description, filename, filesize, filetype, tran_date, id, type_no FROM ".TB_PREF."attachments WHERE type_no=".db_escape($type) - ." ORDER BY trans_no DESC"; + // $_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) + $sql .=" AND trans_no = ".db_escape($id_no); + + $sql .= " ORDER BY trans_no DESC"; + + return $sql; } function move_trans_attachments($type, $trans_from, $trans_to) diff --git a/admin/db/transactions_db.inc b/admin/db/transactions_db.inc index 466ded81..a948cf3e 100644 --- a/admin/db/transactions_db.inc +++ b/admin/db/transactions_db.inc @@ -209,6 +209,9 @@ function get_systype_db_info($type) case ST_SALESQUOTE : return array(TB_PREF."sales_orders", "trans_type", "order_no", "reference", "ord_date"); case ST_DIMENSION : return array(TB_PREF."dimensions", null, "id", "reference", "date_"); case ST_COSTUPDATE : return array(TB_PREF."journal", "type", "trans_no", "reference", "tran_date"); + + 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); } display_db_error("invalid type ($type) sent to get_systype_db_info", "", true); diff --git a/includes/sysnames.inc b/includes/sysnames.inc index 507bd698..68828bca 100644 --- a/includes/sysnames.inc +++ b/includes/sysnames.inc @@ -41,6 +41,8 @@ $systypes_array = array ( ST_SALESQUOTE => _("Sales Quotation"), ST_COSTUPDATE => _("Cost Update"), ST_DIMENSION => _("Dimension"), + ST_CUSTOMER => _("Customer"), + ST_SUPPLIER => _("Supplier"), ); $fa_systypes_array = array ( diff --git a/includes/types.inc b/includes/types.inc index 959c1cd1..a47e265f 100644 --- a/includes/types.inc +++ b/includes/types.inc @@ -46,6 +46,8 @@ define('ST_SALESORDER', 30); define('ST_SALESQUOTE', 32); define('ST_COSTUPDATE', 35); define('ST_DIMENSION', 40); +define('ST_CUSTOMER', 41); +define('ST_SUPPLIER', 42); // Don't include these defines in the $systypes_array. // They are used for documents only. diff --git a/purchasing/manage/suppliers.php b/purchasing/manage/suppliers.php index 9cab778f..b0c7c35b 100644 --- a/purchasing/manage/suppliers.php +++ b/purchasing/manage/suppliers.php @@ -13,6 +13,7 @@ $page_security = 'SA_SUPPLIER'; $path_to_root = "../.."; include($path_to_root . "/includes/db_pager.inc"); include_once($path_to_root . "/includes/session.inc"); +include_once($path_to_root . "/includes/ui/attachment.inc"); $js = ""; if ($SysPrefs->use_popup_windows) $js .= get_js_open_window(900, 500); @@ -279,19 +280,19 @@ function supplier_settings(&$supplier_id) if ($supplier_id) { submit_center_first('submit', _("Update Supplier"), - _('Update supplier data'), $page_nested ? true : 'default'); + _('Update supplier data'), $page_nested ? true : 'false'); submit_return('select', get_post('supplier_id'), _("Select this supplier and return to document entry.")); submit_center_last('delete', _("Delete Supplier"), _('Delete supplier data if have been never used'), true); } else { - submit_center('submit', _("Add New Supplier Details"), true, '', 'default'); + submit_center('submit', _("Add New Supplier Details"), true, '', 'false'); } div_end(); } -start_form(); +start_form(true); if (db_has_suppliers()) { @@ -320,6 +321,7 @@ tabbed_content_start('tabs', array( 'contacts' => array(_('&Contacts'), $supplier_id), 'transactions' => array(_('&Transactions'), (user_check_access('SA_SUPPTRANSVIEW') ? $supplier_id : null)), 'orders' => array(_('Purchase &Orders'), (user_check_access('SA_SUPPTRANSVIEW') ? $supplier_id : null)), + 'attachments' => array(_('Attachments'), (user_check_access('SA_ATTACHDOCUMENT') ? $supplier_id : null)), )); switch (get_post('_tabs_sel')) { @@ -339,6 +341,11 @@ tabbed_content_start('tabs', array( $_GET['supplier_id'] = $supplier_id; include_once($path_to_root."/purchasing/inquiry/po_search_completed.php"); break; + case 'attachments': + $_GET['trans_no'] = $supplier_id; + $_GET['type_no']= ST_SUPPLIER; + $attachments = new attachments('attachment', $supplier_id, 'suppliers'); + $attachments->show(); }; br(); tabbed_content_end(); diff --git a/sales/manage/customers.php b/sales/manage/customers.php index 3810e2b4..c81f78cb 100644 --- a/sales/manage/customers.php +++ b/sales/manage/customers.php @@ -26,6 +26,7 @@ include_once($path_to_root . "/includes/date_functions.inc"); include_once($path_to_root . "/includes/banking.inc"); include_once($path_to_root . "/includes/ui.inc"); include_once($path_to_root . "/includes/ui/contacts_view.inc"); +include_once($path_to_root . "/includes/ui/attachment.inc"); if (isset($_GET['debtor_no'])) { @@ -304,12 +305,12 @@ function customer_settings($selected_id) if (@$_REQUEST['popup']) hidden('popup', 1); if (!$selected_id) { - submit_center('submit', _("Add New Customer"), true, '', 'default'); + submit_center('submit', _("Add New Customer"), true, '', false); } else { submit_center_first('submit', _("Update Customer"), - _('Update customer data'), $page_nested ? true : 'default'); + _('Update customer data'), $page_nested ? true : false); submit_return('select', $selected_id, _("Select this customer and return to document entry.")); submit_center_last('delete', _("Delete Customer"), _('Delete customer data if have been never used'), true); @@ -321,7 +322,7 @@ function customer_settings($selected_id) check_db_has_sales_types(_("There are no sales types defined. Please define at least one sales type before adding a customer.")); -start_form(); +start_form(true); if (db_has_customers()) { @@ -352,6 +353,7 @@ tabbed_content_start('tabs', array( 'contacts' => array(_('&Contacts'), $selected_id), 'transactions' => array(_('&Transactions'), (user_check_access('SA_SALESTRANSVIEW') ? $selected_id : null)), 'orders' => array(_('Sales &Orders'), (user_check_access('SA_SALESTRANSVIEW') ? $selected_id : null)), + 'attachments' => array(_('Attachments'), (user_check_access('SA_ATTACHDOCUMENT') ? $selected_id : null)), )); switch (get_post('_tabs_sel')) { @@ -371,6 +373,11 @@ tabbed_content_start('tabs', array( $_GET['customer_id'] = $selected_id; include_once($path_to_root."/sales/inquiry/sales_orders_view.php"); break; + case 'attachments': + $_GET['trans_no'] = $selected_id; + $_GET['type_no']= ST_CUSTOMER; + $attachments = new attachments('attachment', $selected_id, 'customers'); + $attachments->show(); }; br(); tabbed_content_end(); -- 2.30.2