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.
! -> 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
//-----------------------------------------------------------------------------------------------
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
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,
}
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 "<td>$label</td>\n";
echo "<td>";
- 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 "</td>\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 "<tr>\n";
gl_all_accounts_list_cells($label, $name, $selected_id, $skip_bank_accounts,
- $show_group, $cells);
+ $show_group, $cells, $all_option);
echo "</tr>\n";
}
$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]; //?
$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);
//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");
$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;
$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);
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");
//-----------------------------------------------------------------------------------------------
-if (isset($_GET['debtor_no']))
+if (isset($_GET['debtor_no']))
{
$_POST['customer_id'] = strtoupper($_GET['debtor_no']);
$_POST['New'] = "1";
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
//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']))
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 */
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']) . ")";
}
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
$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");
$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))
{
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
}
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']);
}
echo "<table>";
-if (!isset($_POST['New']) && $num_branches)
+if (!isset($_POST['New']) && $num_branches)
{
//editing an existing branch
$_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
$_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'];
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']);