From 781557dd6312e10be5e693ee5a63b7a309dc0591 Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Sat, 14 Jun 2008 08:49:22 +0000 Subject: [PATCH] The Customer Branch Sales Account now overrides the Item Sales Accounts if a Sales Account is here. Can now be set to 'Use Item Sales Accounts', which is the first choice in list and default. If setting the Customer Branch AR Account to a Bank Account (and hereby also Cash Account) the transactions from Direct Invoice and Credit Note will be allocated immediately when placing. --- CHANGELOG.txt | 10 ++++ includes/ui/ui_lists.inc | 12 +++-- sales/includes/db/sales_credit_db.inc | 23 ++++++-- sales/includes/db/sales_invoice_db.inc | 16 +++++- sales/manage/customer_branches.php | 75 ++++++++++++++------------ 5 files changed, 89 insertions(+), 47 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 05037830..24f9db98 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,16 @@ Legend: ! -> Note $ -> Affected files +14-Jun-2008 Joe Hunt +! The Customer Branch Sales Account now overrides the Item Sales Accounts if a Sales Account is here. + Can now be set to 'Use Item Sales Accounts', which is the first choice in list and default. +! If setting the Customer Branch AR Account to a Bank Account (and hereby also Cash Account) the + transactions from Direct Invoice and Credit Note will be allocated immediately when placing. +$ /includes/ui/ui_lists.inc + /sales/includes/db/sales_invoice_db.inc + /sales/includes/db/sales_credit_db.inc + /sales/manage/customer_branches.php + . 12-Jun-2008 Joe Hunt + New inventory sales report. Shows total sales - costs - contribution per category, location, detailed/summary and period. $ /reporting/reports_main.php diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 102227c4..454932cd 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -1231,7 +1231,7 @@ function gl_account_types_list_row($label, $name, $selected_id, $all_option=fals //----------------------------------------------------------------------------------------------- function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false, - $show_group=false, $cells=false) + $show_group=false, $cells=false, $all_option=false) { if ($skip_bank_accounts) $sql = "SELECT chart.account_code, chart.account_name, type.name @@ -1248,6 +1248,8 @@ function gl_all_accounts_list($name, $selected_id, $skip_bank_accounts=false, combo_input($name, $selected_id, $sql, 'chart.account_code', 'chart.account_name', array( 'format' => '_format_account' . ($show_group ? '2' : ''), + 'spec_option' => $all_option===true ? _("Use Item Sales Accounts") : $all_option, + 'spec_id' => '', 'order' => 'account_code', 'search_box' => $cells, 'search_submit' => false, @@ -1269,21 +1271,21 @@ function _format_account2($row) } function gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts=false, - $show_group=false, $cells=false) + $show_group=false, $cells=false, $all_option=false) { if ($label != null) echo "$label\n"; echo ""; - gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells); + gl_all_accounts_list($name, $selected_id, $skip_bank_accounts, $show_group, $cells, $all_option); echo "\n"; } function gl_all_accounts_list_row($label, $name, $selected_id, $skip_bank_accounts=false, - $show_group=false, $cells=false) + $show_group=false, $cells=false, $all_option=false) { echo "\n"; gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts, - $show_group, $cells); + $show_group, $cells, $all_option); echo "\n"; } diff --git a/sales/includes/db/sales_credit_db.inc b/sales/includes/db/sales_credit_db.inc index a7f41e33..bb284f04 100644 --- a/sales/includes/db/sales_credit_db.inc +++ b/sales/includes/db/sales_credit_db.inc @@ -41,6 +41,12 @@ function write_credit_note($credit_note, $write_off_acc) $items_added_tax = 0; $freight_added_tax = 0; } + // 2006-06-14. If the Customer Branch AR Account is set to a Bank Account, + // the transaction will be settled at once. + if (is_bank_account($branch_data['receivables_account'])) + $alloc = $credit_note_total + $items_added_tax + $credit_note->freight_cost + $freight_added_tax; + else + $alloc = 0; // $sales_order=$invoice->order_no; //? // if (is_array($sales_order)) $sales_order = $sales_order[0]; //? @@ -54,9 +60,8 @@ function write_credit_note($credit_note, $write_off_acc) $credit_note_total, 0, $items_added_tax, $credit_note->freight_cost, $freight_added_tax, $credit_note->sales_type, - $credit_note->order_no, $credit_invoice, $credit_note->ship_via - //, $credit_note->due_date - ); + $credit_note->order_no, $credit_invoice, $credit_note->ship_via, + null, $alloc); // 2008-06-14 extra $alloc if ($trans_no==0) { $credit_note->trans_no = array($credit_no=>0); @@ -231,13 +236,21 @@ function add_gl_trans_credit_costs($order, $order_line, $credit_no, $date_, //Post sales transaction to GL credit sales - add_gl_trans_customer(11, $credit_no, $date_, $stock_gl_codes["sales_account"], 0, 0, + // 2008-06-14. If there is a Branch Sales Account, then override with this, + // else take the Item Sales Account + if ($branch_data['sales_account'] != "") + $sales_account = $branch_data['sales_account']; + else + $sales_account = $stock_gl_codes['sales_account']; + add_gl_trans_customer(11, $credit_no, $date_, $sales_account, $stock_gl_codes["dimension_id"], + $stock_gl_codes["dimension2_id"], ($line_taxfree_price * $order_line->qty_dispatched), $order->customer_id, "The credit note GL posting could not be inserted"); if ($order_line->discount_percent != 0) { - add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"], 0, 0, + add_gl_trans_customer(11, $credit_no, $date_, $branch_data["sales_discount_account"], + $stock_gl_codes["dimension_id"], $stock_gl_codes["dimension2_id"], -($line_taxfree_price * $order_line->qty_dispatched * $order_line->discount_percent), $order->customer_id, "The credit note discount GL posting could not be inserted"); diff --git a/sales/includes/db/sales_invoice_db.inc b/sales/includes/db/sales_invoice_db.inc index 3627eb19..8270ea6e 100644 --- a/sales/includes/db/sales_invoice_db.inc +++ b/sales/includes/db/sales_invoice_db.inc @@ -43,6 +43,12 @@ function write_sales_invoice(&$invoice) $items_added_tax = 0; $freight_added_tax = 0; } + // 2006-06-14. If the Customer Branch AR Account is set to a Bank Account, + // the transaction will be settled at once. + if (is_bank_account($branch_data['receivables_account'])) + $alloc = $items_total + $items_added_tax + $invoice->freight_cost + $freight_added_tax; + else + $alloc = 0; /* Insert/update the debtor_trans */ $sales_order = $invoice->order_no; @@ -53,7 +59,7 @@ function write_sales_invoice(&$invoice) $invoice->Branch, $date_, $invoice->reference, $items_total, 0, $items_added_tax, $invoice->freight_cost, $freight_added_tax, $invoice->sales_type, $sales_order, $delivery_no, - $invoice->ship_via, $invoice->due_date); + $invoice->ship_via, $invoice->due_date, $alloc); // 2008-06-14 extra $alloc if ($trans_no == 0) { $invoice->trans_no = array($invoice_no=>0); @@ -87,11 +93,17 @@ function write_sales_invoice(&$invoice) if ($invoice_line->qty_dispatched != 0) { $stock_gl_code = get_stock_gl_code($invoice_line->stock_id); + // 2008-06-14. If there is a Branch Sales Account, then override with this, + // else take the Item Sales Account + if ($branch_data['sales_account'] != "") + $sales_account = $branch_data['sales_account']; + else + $sales_account = $stock_gl_code['sales_account']; if ($invoice_line->line_price() != 0) { //Post sales transaction to GL credit sales - add_gl_trans_customer(10, $invoice_no, $date_, $stock_gl_code["sales_account"], + add_gl_trans_customer(10, $invoice_no, $date_, $sales_account, $stock_gl_code["dimension_id"], $stock_gl_code["dimension2_id"], (-$line_taxfree_price * $invoice_line->qty_dispatched), $invoice->customer_id, "The sales price GL posting could not be inserted"); diff --git a/sales/manage/customer_branches.php b/sales/manage/customer_branches.php index 1ca32ec7..de40042e 100644 --- a/sales/manage/customer_branches.php +++ b/sales/manage/customer_branches.php @@ -22,7 +22,7 @@ check_db_has_tax_groups(_("There are no tax groups defined in the system. At lea //----------------------------------------------------------------------------------------------- -if (isset($_GET['debtor_no'])) +if (isset($_GET['debtor_no'])) { $_POST['customer_id'] = strtoupper($_GET['debtor_no']); $_POST['New'] = "1"; @@ -34,14 +34,14 @@ if (isset($_GET['SelectedBranch'])) unset($_POST['New']); } -if (!isset($_GET['SelectedBranch']) && !isset($_POST['AddUpdate'])) +if (!isset($_GET['SelectedBranch']) && !isset($_POST['AddUpdate'])) { $_POST['New'] = "1"; } //----------------------------------------------------------------------------------------------- -if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) +if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) { //initialise no input errors assumed initially before we test @@ -49,13 +49,13 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) //first off validate inputs sensible - if (strlen($_POST['br_name']) == 0) + if (strlen($_POST['br_name']) == 0) { $input_error = 1; display_error(_("The Branch name cannot be empty.")); } - if ($input_error != 1) + if ($input_error != 1) { //if (!isset($_POST['New'])) @@ -83,7 +83,7 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) WHERE branch_code =".db_escape($_POST['branch_code']) . " AND debtor_no=".db_escape($_POST['customer_id']); - } + } else { /*Selected branch is null cos no item selected on first time round so must be adding a record must be submitting new entries in the new Customer Branches form */ @@ -91,18 +91,18 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) salesman, phone, fax, contact_name, area, email, tax_group_id, sales_account, receivables_account, payment_discount_account, sales_discount_account, default_location, br_post_address, disable_trans, default_ship_via) - VALUES (".db_escape($_POST['customer_id']). ",".db_escape($_POST['br_name']) . ", " - .db_escape($_POST['br_address']) . ", ".db_escape($_POST['salesman']) . ", " + VALUES (".db_escape($_POST['customer_id']). ",".db_escape($_POST['br_name']) . ", " + .db_escape($_POST['br_address']) . ", ".db_escape($_POST['salesman']) . ", " .db_escape($_POST['phone']) . ", ".db_escape($_POST['fax']) . "," - .db_escape($_POST['contact_name']) . ", ".db_escape($_POST['area']) . "," - .db_escape($_POST['email']) . ", ".db_escape($_POST['tax_group_id']) . ", " - .db_escape($_POST['sales_account']) . ", " - .db_escape($_POST['receivables_account']) . ", " - .db_escape($_POST['payment_discount_account']) . ", " - .db_escape($_POST['sales_discount_account']) . ", " - .db_escape($_POST['default_location']) . ", " - .db_escape($_POST['br_post_address']) . "," - .db_escape($_POST['disable_trans']) . ", " + .db_escape($_POST['contact_name']) . ", ".db_escape($_POST['area']) . "," + .db_escape($_POST['email']) . ", ".db_escape($_POST['tax_group_id']) . ", " + .db_escape($_POST['sales_account']) . ", " + .db_escape($_POST['receivables_account']) . ", " + .db_escape($_POST['payment_discount_account']) . ", " + .db_escape($_POST['sales_discount_account']) . ", " + .db_escape($_POST['default_location']) . ", " + .db_escape($_POST['br_post_address']) . "," + .db_escape($_POST['disable_trans']) . ", " .db_escape($_POST['default_ship_via']) . ")"; } @@ -112,8 +112,8 @@ if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) meta_forward($_SERVER['PHP_SELF'], "debtor_no=" . $_POST['customer_id']); } -} -elseif (isset($_GET['delete'])) +} +elseif (isset($_GET['delete'])) { //the link to delete a selected record was clicked instead of the submit button @@ -122,22 +122,22 @@ elseif (isset($_GET['delete'])) $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtor_trans WHERE branch_code='" . $_POST['branch_code']. "' AND debtor_no = '" . $_POST['customer_id']. "'"; $result = db_query($sql,"could not query debtortrans"); $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if ($myrow[0] > 0) { display_error(_("Cannot delete this branch because customer transactions have been created to this branch.")); - } - else + } + else { $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_orders WHERE branch_code='" . $_POST['branch_code']. "' AND debtor_no = '" . $_POST['customer_id']. "'"; $result = db_query($sql,"could not query sales orders"); $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if ($myrow[0] > 0) { display_error(_("Cannot delete this branch because sales orders exist for it. Purge old sales orders first.")); - } - else + } + else { $sql="DELETE FROM ".TB_PREF."cust_branch WHERE branch_code='" . $_POST['branch_code']. "' AND debtor_no='" . $_POST['customer_id']. "'"; db_query($sql,"could not delete branch"); @@ -170,7 +170,7 @@ if ($num_branches) $th = array(_("Name"), _("Contact"), _("Sales Person"), _("Area"), _("Phone No"), _("Fax No"), _("E-mail"), _("Tax Group"), "", ""); - table_header($th); + table_header($th); while ($myrow = db_fetch($result)) { @@ -186,7 +186,7 @@ if ($num_branches) edit_link_cell("debtor_no=" . $_POST['customer_id']. "&SelectedBranch=" . $myrow["branch_code"]); delete_link_cell("debtor_no=" . $_POST['customer_id']. "&SelectedBranch=" . $myrow["branch_code"]. "&delete=yes"); end_row(); - } + } end_table(); //END WHILE LIST LOOP } @@ -194,10 +194,10 @@ else display_note(_("The selected customer does not have any branches. Please create at least one branch.")); //else //{ -//} +//} -if (!isset($_POST['New'])) +if (!isset($_POST['New'])) { hyperlink_params($_SERVER['PHP_SELF'], _("New Customer Branch"), "debtor_no=" . $_POST['customer_id']); } @@ -208,7 +208,7 @@ echo ""; // outer table echo ""; -if (!isset($_POST['New']) && $num_branches) +if (!isset($_POST['New']) && $num_branches) { //editing an existing branch @@ -238,8 +238,8 @@ if (!isset($_POST['New']) && $num_branches) $_POST['receivables_account'] = $myrow['receivables_account']; $_POST['payment_discount_account'] = $myrow['payment_discount_account']; -} -else +} +else { //end of if $SelectedBranch only do the else when a new record is being entered $sql = "SELECT name, address, email @@ -251,11 +251,14 @@ else $_POST['br_address'] = $_POST['br_post_address'] = $myrow["address"]; $_POST['branch_code'] = ""; $_POST['email'] = $myrow['email']; - if (!isset($_POST['sales_account']) || !isset($_POST['sales_discount_account'])) + if (!isset($_POST['sales_account']) || !isset($_POST['sales_discount_account'])) { $company_record = get_company_prefs(); - $_POST['sales_account'] = $company_record["default_sales_act"]; + // $_POST['sales_account'] = $company_record["default_sales_act"]; + // 2008-06-14. Changed so if no account here the Item Sales Account is taken + // Will be set if it should override the item sales account + $_POST['sales_account'] = ''; $_POST['sales_discount_account'] = $company_record['default_sales_discount_act']; $_POST['receivables_account'] = $company_record['debtors_act']; $_POST['payment_discount_account'] = $company_record['default_prompt_payment_act']; @@ -298,7 +301,9 @@ echo"
"; table_section_title(_("GL Accounts")); -gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']); +// 2006-06-14. Changed gl_al_accounts_list to have an optional all_option 'Use Item Sales Accounts' +gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account'], false, + false, false, true); gl_all_accounts_list_row(_("Sales Discount Account:"), 'sales_discount_account', $_POST['sales_discount_account']); -- 2.30.2