Implemented attachments for Bank Account, and redesign of Bank Accounts to a tabbed...
authorJoe <joe.hunt.consulting@gmail.com>
Tue, 24 Oct 2023 08:11:19 +0000 (10:11 +0200)
committerJoe <joe.hunt.consulting@gmail.com>
Tue, 24 Oct 2023 08:11:19 +0000 (10:11 +0200)
admin/attachments.php
admin/db/attachments_db.inc
admin/db/transactions_db.inc
gl/inquiry/bank_inquiry.php
gl/manage/bank_accounts.php
includes/sysnames.inc
includes/types.inc
includes/ui/attachment.inc

index 90d9da9dcdfd2e7c73d9734311d8a919991e9379..d2895d139d768d58e669aab22e01dcb681693a9c 100644 (file)
@@ -192,8 +192,10 @@ function viewing_controls()
        } elseif(get_post('filterType') == ST_FIXEDASSET){
                stock_items_list_cells(_("Select an Item: "), 'trans_no', null,  false, true,false, false,
                        array('fixed_asset' => 1));
+       } elseif(get_post('filterType') == ST_BANKACCOUNT){
+               bank_accounts_list_cells(_("Select a Bank Account: "), 'trans_no', null,  true);
        }
-
+       
        end_row();
     end_table(1);
 
@@ -202,7 +204,7 @@ function viewing_controls()
 function trans_view($trans)
 {
        if ($trans['type_no']==ST_SUPPLIER || $trans['type_no']==ST_CUSTOMER || $trans['type_no']==ST_ITEM ||
-               $trans['type_no']==ST_FIXEDASSET)
+               $trans['type_no']==ST_FIXEDASSET || $trans['type_no']==ST_BANKACCOUNT)
                return $trans['id'];
        return get_trans_view_str($trans["type_no"], $trans["trans_no"]);
 }
@@ -229,7 +231,7 @@ 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 : 
+       $sql = get_sql_for_attached_documents($type, $type==ST_SUPPLIER || $type==ST_CUSTOMER || $type==ST_BANKACCOUNT ? $trans_no : 
                ($type==ST_ITEM || $type==ST_FIXEDASSET ? get_item_code_id($trans_no) : 0));
        $cols = array(
            _("#") => array('fun'=>'trans_view', 'ord'=>''), 
@@ -276,13 +278,13 @@ 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 && $type != ST_ITEM)
+               if ($type != ST_SUPPLIER && $type != ST_CUSTOMER && $type != ST_ITEM && $type != ST_BANKACCOUNT)
                        label_row(_("Transaction #"), $row['trans_no']);
        }       
        hidden('selected_id', $selected_id);
 }
 else {
-       if ($type != ST_SUPPLIER && $type != ST_CUSTOMER && $type != ST_ITEM && $type != ST_FIXEDASSET)
+       if ($type != ST_SUPPLIER && $type != ST_CUSTOMER && $type != ST_ITEM && $type != ST_FIXEDASSET && $type != ST_BANKACCOUNT)
                text_row_ex(_("Transaction #").':', 'trans_no', 10);
 }
 text_row_ex(_("Doc Title").':', 'description', 40);
index c280688485957f3bcf5746fbb88fa9067acad1cf..5a935fbf5bb7c26bd35ba7198f40afb6541f8eb4 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 || $type == ST_ITEM || $type == ST_FIXEDASSET) && $id_no != null)
+       if(($type == ST_CUSTOMER || $type == ST_SUPPLIER || $type == ST_ITEM || $type == ST_FIXEDASSET || $type == ST_BANKACCOUNT) && $id_no != null)
                $sql .=" AND trans_no = ".db_escape($id_no);
 
        $sql .= " ORDER BY trans_no DESC";
index 6cc5ae31fb2e1f4ce123b1f8ca924ed91b770e7b..d75268e59c635a0f143ee068a8c12716bd5020b5 100644 (file)
@@ -214,6 +214,7 @@ function get_systype_db_info($type)
         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);
         case     ST_FIXEDASSET  : return array(TB_PREF."item_codes", null, "id", "stock_id", null);
+        case     ST_BANKACCOUNT  : return array(TB_PREF."bank_accounts", null, "id", "bank_account_number", null);
        }
 
        display_db_error("invalid type ($type) sent to get_systype_db_info", "", true);
index e273099db7fa6dc721723df38cc0b9b2493050ad..d17716d694fa5db85604a91d1c57c4631289aa0f 100644 (file)
@@ -45,12 +45,13 @@ if (isset($_GET['bank_account']))
 start_form();
 start_table(TABLESTYLE_NOBORDER);
 start_row();
-bank_accounts_list_cells(_("Account:"), 'bank_account', null);
+if (!$page_nested)
+       bank_accounts_list_cells(_("Account:"), 'bank_account', null);
 
 date_cells(_("From:"), 'TransAfterDate', '', null, -user_transaction_days());
 date_cells(_("To:"), 'TransToDate');
 
-submit_cells('Show',_("Show"),'','', 'default');
+submit_cells('Show',_("Show"),'', '', 'default');
 end_row();
 end_table();
 end_form();
@@ -63,8 +64,11 @@ if (!isset($_POST['bank_account']))
 $result = get_bank_trans_for_bank_account($_POST['bank_account'], $_POST['TransAfterDate'], $_POST['TransToDate']);    
 
 div_start('trans_tbl');
-$act = get_bank_account($_POST["bank_account"]);
-display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
+if (!$page_nested)
+{
+       $act = get_bank_account($_POST["bank_account"]);
+       display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
+}
 
 start_table(TABLESTYLE);
 
@@ -108,8 +112,8 @@ while ($myrow = db_fetch($result))
 
        label_cell(get_comments_string($myrow["type"], $myrow["trans_no"]));
        label_cell(get_gl_view_str($myrow["type"], $myrow["trans_no"]));
-
-       label_cell(trans_editor_link($myrow["type"], $myrow["trans_no"]));
+       if (!$page_nested)
+               label_cell(trans_editor_link($myrow["type"], $myrow["trans_no"]));
 
        end_row();
        if ($myrow["amount"] > 0 ) 
index fee5e89daefc58acfec9ff9e4456836d974b7c53..c4098e0c3f14a4257110767e5fc0907ed3273b9d 100644 (file)
 ***********************************************************************/
 $page_security = 'SA_BANKACCOUNT';
 $path_to_root = "../..";
+include($path_to_root . "/includes/db_pager.inc");
 include($path_to_root . "/includes/session.inc");
 
 page(_($help_context = "Bank Accounts"));
 
 include($path_to_root . "/includes/ui.inc");
+include_once($path_to_root . "/includes/ui/attachment.inc");
 
 simple_page_mode();
+
+if (isset($_GET['bank_id'])) 
+{
+       $_POST['bank_id'] = $_GET['bank_id'];
+}
+
+$bank_id = get_post('bank_id', ''); 
+if ($selected_id != -1)
+       $bank_id = $selected_id;
+
 //-----------------------------------------------------------------------------------
 
 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
@@ -41,14 +53,15 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
        }
        if ($input_error != 1)
        {
-       if ($selected_id != -1
+       if ($bank_id
        {
                
-               update_bank_account($selected_id, $_POST['account_code'],
+               update_bank_account($bank_id, $_POST['account_code'],
                                $_POST['account_type'], $_POST['bank_account_name'], 
                                $_POST['bank_name'], $_POST['bank_account_number'], 
                        $_POST['bank_address'], $_POST['BankAccountCurrency'],
                        $_POST['dflt_curr_act'], $_POST['bank_charge_act']);
+                       $Ajax->activate('bank_id'); // in case of status change
                        display_notification(_('Bank account has been updated'));
        } 
        else 
@@ -58,8 +71,10 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                                $_POST['bank_account_name'], $_POST['bank_name'], 
                        $_POST['bank_account_number'], $_POST['bank_address'], 
                                $_POST['BankAccountCurrency'], $_POST['dflt_curr_act'], $_POST['bank_charge_act']);
+                       $bank_id = $_POST['bank_id'] = db_insert_id();
                        display_notification(_('New bank account has been added'));
-       }
+                       $Ajax->activate('_page_body');
+               }
                $Mode = 'RESET';
        }
 } 
@@ -70,20 +85,20 @@ elseif( $Mode == 'Delete')
        $cancel_delete = 0;
        // PREVENT DELETES IF DEPENDENT RECORDS IN 'bank_trans'
 
-       if (key_in_foreign_table($selected_id, 'bank_trans', 'bank_act') || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account'))
+       if (key_in_foreign_table($bank_id, 'bank_trans', 'bank_act') || key_in_foreign_table(get_post('account_code'), 'gl_trans', 'account'))
        {
                $cancel_delete = 1;
                display_error(_("Cannot delete this bank account because transactions have been created using this account."));
        }
 
-       if (key_in_foreign_table($selected_id, 'sales_pos', 'pos_account'))
+       if (key_in_foreign_table($bank_id, 'sales_pos', 'pos_account'))
        {
                $cancel_delete = 1;
                display_error(_("Cannot delete this bank account because POS definitions have been created using this account."));
        }
        if (!$cancel_delete) 
        {
-               delete_bank_account($selected_id);
+               delete_bank_account($bank_id);
                display_notification(_('Selected bank account has been deleted'));
        } //end if Delete bank account
        $Mode = 'RESET';
@@ -91,10 +106,11 @@ elseif( $Mode == 'Delete')
 
 if ($Mode == 'RESET')
 {
-       $selected_id = -1;
+       $bank_id = '';
        $_POST['bank_name']  =  $_POST['bank_account_name']  = '';
        $_POST['bank_account_number'] = $_POST['bank_address'] = '';
        $_POST['bank_charge_act'] = get_company_pref('bank_charge_act');
+       $Ajax->activate('_page_body');
 }
 if (!isset($_POST['bank_charge_act']))
        $_POST['bank_charge_act'] = get_company_pref('bank_charge_act');
@@ -103,7 +119,7 @@ if (!isset($_POST['bank_charge_act']))
 
 $result = get_bank_accounts(check_value('show_inactive'));
 
-start_form();
+start_form(true);
 start_table(TABLESTYLE, "width='80%'");
 
 $th = array(_("Account Name"), _("Type"), _("Currency"), _("GL Account"), 
@@ -138,68 +154,113 @@ while ($myrow = db_fetch($result))
 inactive_control_row($th);
 end_table(1);
 
-$is_used = $selected_id != -1 && key_in_foreign_table($selected_id, 'bank_trans', 'bank_act');
 
-start_table(TABLESTYLE2);
-
-if ($selected_id != -1) 
+function bank_account_settings($bank_id)
 {
-  if ($Mode == 'Edit') {       
-       $myrow = get_bank_account($selected_id);
-
-       $_POST['account_code'] = $myrow["account_code"];
-       $_POST['account_type'] = $myrow["account_type"];
-       $_POST['bank_name']  = $myrow["bank_name"];
-       $_POST['bank_account_name']  = $myrow["bank_account_name"];
-       $_POST['bank_account_number'] = $myrow["bank_account_number"];
-       $_POST['bank_address'] = $myrow["bank_address"];
-       $_POST['BankAccountCurrency'] = $myrow["bank_curr_code"];
-       $_POST['dflt_curr_act'] = $myrow["dflt_curr_act"];
-       $_POST['bank_charge_act'] = $myrow["bank_charge_act"];
-  }
-       hidden('selected_id', $selected_id);
-       set_focus('bank_account_name');
-} 
+       global $Mode, $bank_account_types, $page_nested;
 
-text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100);
+       $is_used = $bank_id && key_in_foreign_table($bank_id, 'bank_trans', 'bank_act');
+       
+       start_table(TABLESTYLE2);
 
-if ($is_used) 
-{
-       label_row(_("Account Type:"), $bank_account_types[$_POST['account_type']]);
-       hidden('account_type');
-} 
-else 
-{
-       bank_account_types_list_row(_("Account Type:"), 'account_type', null); 
-}
-if ($is_used) 
-{
-       label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']);
-       hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);
-} 
-else 
-{
-       currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
-}      
+       if ($bank_id) 
+       {
+               if ($Mode == 'Edit') {  
+                       $myrow = get_bank_account($bank_id);
 
-yesno_list_row(_("Default currency account:"), 'dflt_curr_act');
+                       $_POST['account_code'] = $myrow["account_code"];
+                       $_POST['account_type'] = $myrow["account_type"];
+                       $_POST['bank_name']  = $myrow["bank_name"];
+                       $_POST['bank_account_name']  = $myrow["bank_account_name"];
+                       $_POST['bank_account_number'] = $myrow["bank_account_number"];
+                       $_POST['bank_address'] = $myrow["bank_address"];
+                       $_POST['BankAccountCurrency'] = $myrow["bank_curr_code"];
+                       $_POST['dflt_curr_act'] = $myrow["dflt_curr_act"];
+                       $_POST['bank_charge_act'] = $myrow["bank_charge_act"];
+               }
+               hidden('bank_id', $bank_id);
+               set_focus('bank_account_name');
+       } 
 
-if($is_used)
-{
-       label_row(_("Bank Account GL Code:"), $_POST['account_code']);
-       hidden('account_code');
-} else 
-       gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null);
+       text_row(_("Bank Account Name:"), 'bank_account_name', null, 50, 100);
 
-gl_all_accounts_list_row(_("Bank Charges Account:"), 'bank_charge_act', null, true);
-text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
-text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
-textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
+       if ($is_used) 
+       {
+               label_row(_("Account Type:"), $bank_account_types[$_POST['account_type']]);
+               hidden('account_type');
+       } 
+       else 
+       {
+               bank_account_types_list_row(_("Account Type:"), 'account_type', null); 
+       }
+       if ($is_used) 
+       {
+               label_row(_("Bank Account Currency:"), $_POST['BankAccountCurrency']);
+               hidden('BankAccountCurrency', $_POST['BankAccountCurrency']);
+       } 
+       else 
+       {
+               currencies_list_row(_("Bank Account Currency:"), 'BankAccountCurrency', null);
+       }       
 
-end_table(1);
+       yesno_list_row(_("Default currency account:"), 'dflt_curr_act');
+
+       if($is_used)
+       {
+               label_row(_("Bank Account GL Code:"), $_POST['account_code']);
+               hidden('account_code');
+       } else 
+               gl_all_accounts_list_row(_("Bank Account GL Code:"), 'account_code', null);
+
+       gl_all_accounts_list_row(_("Bank Charges Account:"), 'bank_charge_act', null, true);
+       text_row(_("Bank Name:"), 'bank_name', null, 50, 60);
+       text_row(_("Bank Account Number:"), 'bank_account_number', null, 30, 60);
+       textarea_row(_("Bank Address:"), 'bank_address', null, 40, 5);
 
-submit_add_or_update_center($selected_id == -1, '', 'both');
+       end_table(1);
+
+       submit_add_or_update_center(!$bank_id, '', 'both');
+}
+
+if (!$bank_id)
+{
+       unset($_POST['_tabs_sel']); // force settings tab for new customer
+       display_heading("");
+}
+else
+{
+       $act = get_bank_account($bank_id);
+       if ($act)
+               display_heading($act['bank_account_name']." - ".$act['bank_curr_code']);
+}
+if ($bank_id)
+       hidden('bank_id', $bank_id);
+
+tabbed_content_start('tabs', array(
+               'settings' => array(_('&General settings'), $bank_id),
+               'transactions' => array(_('&Transactions'), (user_check_access('SA_BANKTRANSVIEW') ? $bank_id : null)),
+               'attachments' => array(_('Attachments'), (user_check_access('SA_ATTACHDOCUMENT') ? $bank_id : null)),
+       ));
+       
+       switch (get_post('_tabs_sel')) {
+               default:
+               case 'settings':
+                       $Mode = "Edit";
+                       bank_account_settings($bank_id); 
+                       break;
+               case 'transactions':
+                       $_GET['bank_account'] = $bank_id;
+                       include_once($path_to_root."/gl/inquiry/bank_inquiry.php");
+                       break;
+               case 'attachments':
+                       $_GET['trans_no'] = $bank_id;
+                       $_GET['type_no']= ST_BANKACCOUNT;
+                       $attachments = new attachments('attachment', $bank_id, 'bank_accounts');
+                       $attachments->show();
+       };
+br();
+tabbed_content_end();
 
 end_form();
 
-end_page();
+end_page(@$_REQUEST['popup']);
index 0bb259baadd9ad1de5281890ad33c4fa56ededfe..8bc99e345c7788e03b5fcc13c90ff84eea939cd9 100644 (file)
@@ -45,6 +45,7 @@ $systypes_array = array (
        ST_SUPPLIER => _("Supplier"),
        ST_ITEM => _("Item"),
        ST_FIXEDASSET => _("Fixed Asset"),
+       ST_BANKACCOUNT => _("Bank Account"),
        );
 
 $fa_systypes_array = array (
index db5cac152fe707014d04209c1d90ac8704bbf6ab..8996380fe028861ae01cfa67f98f5cf5cdb57cdc 100644 (file)
@@ -50,6 +50,7 @@ define('ST_CUSTOMER', 41);
 define('ST_SUPPLIER', 42);
 define('ST_ITEM', 43);
 define('ST_FIXEDASSET', 44);
+define('ST_BANKACCOUNT', 45);
 
 // Don't include these defines in the $systypes_array.
 // They are used for documents only.
index f6500dafba2ecf01a2cfb8fa2caecf90ac3cc966..06dd5e1cb67a6f5add5b7fd2804550f7221052da 100644 (file)
@@ -135,6 +135,8 @@ class attachments extends simple_crud {
                        $id_word = _("Item ID");
                elseif($type_no==ST_FIXEDASSET) 
                        $id_word = _("Fixed Asset ID");
+               elseif($type_no==ST_BANKACCOUNT) 
+                       $id_word = _("Bank Account ID");
 
                label_row(_($id_word), $_POST['trans_no']);     
                date_row(_("Date"), 'tran_date');
@@ -236,7 +238,6 @@ class attachments extends simple_crud {
                        $max_image_size = 5000;
                $upload_file = "";
                if (isset($_FILES['file_attachment_name']) && $_FILES['file_attachment_name']['name'] != '') {
-                       
                        $result = $_FILES['file_attachment_name']['error'];
                        $upload_file = 'Yes'; 
                        $attr_dir = company_path().'/attachments' ;