'default_prompt_payment_act', 'default_inventory_act', 'default_cogs_act',
'default_adj_act', 'default_inv_sales_act', 'default_assembly_act', 'legal_text',
'past_due_days', 'default_workorder_required', 'default_dim_required',
- 'default_delivery_required', 'grn_clearing_act',
+ 'default_delivery_required', 'grn_clearing_act', 'tax_algorithm',
'allow_negative_stock'=> 0, 'accumulate_shipping'=> 0,
'po_over_receive' => 0.0, 'po_over_charge' => 0.0, 'default_credit_limit'=>0.0
)));
$_POST['exchange_diff_act'] = $myrow["exchange_diff_act"];
$_POST['bank_charge_act'] = $myrow["bank_charge_act"];
+$_POST['tax_algorithm'] = $myrow["tax_algorithm"];
$_POST['default_sales_act'] = $myrow["default_sales_act"];
$_POST['default_sales_discount_act'] = $myrow["default_sales_discount_act"];
$_POST['default_prompt_payment_act'] = $myrow["default_prompt_payment_act"];
gl_all_accounts_list_row(_("Bank Charges Account:"), 'bank_charge_act', $_POST['bank_charge_act']);
+tax_algorithm_list_row(_("Tax Algorithm:"), 'tax_algorithm', $_POST['tax_algorithm']);
+
//---------------
table_section_title(_("Customers and Sales"));
PTT_DAYS => _("After No. of Days"),
PTT_FOLLOWING => _("Day In Following Month")
);
+//----------------------------------------------------------------------------------
+$tax_algorithms = array(
+ TCA_LINES => _("Sum per line taxes"),
+ TCA_TOTALS => _("Taxes from totals")
+);
?>
\ No newline at end of file
define('PTT_DAYS', 3);
define('PTT_FOLLOWING', 4);
+//----------------------------------------------------------------------------------
+// Tax calculation algorithms used in als and purchase (depends on supplier's invoicing software)
+
+define('TCA_TOTALS', 1); // taxes are calculated from respective net totals for all lines
+define('TCA_LINES', 2); // taxes calculated for every line, then summed
+
include_once($path_to_root . '/includes/sysnames.inc');
?>
\ No newline at end of file
}
//-----------------------------------------------------------------------------------------------
-function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+function cash_accounts_list_row($label, $name, $selected_id=null, $submit_on_change=false, $all_option=false)
{
+ global $all_items;
+
$sql = "SELECT ".TB_PREF."bank_accounts.id, bank_account_name, bank_curr_code, inactive
FROM ".TB_PREF."bank_accounts
WHERE ".TB_PREF."bank_accounts.account_type=".BT_CASH;
echo "<td>";
echo combo_input($name, $selected_id, $sql, 'id', 'bank_account_name',
array(
+ 'spec_option' => $all_option,
+ 'spec_id' => $all_items,
'format' => '_format_add_curr',
'select_submit'=> $submit_on_change,
'async' => true
echo array_selector( $name, $value, $coas );
echo "</td></tr>\n";
}
+
+function tax_algorithm_list($name, $value=null, $submit_on_change = false)
+{
+ global $tax_algorithms;
+
+ return array_selector($name, $value, $tax_algorithms,
+ array(
+ 'select_submit'=> $submit_on_change,
+ 'async' => true,
+ )
+ );
+}
+
+function tax_algorithm_list_cells($label, $name, $value=null, $submit_on_change=false)
+{
+ if ($label != null)
+ echo "<td>$label</td>\n";
+ echo "<td>";
+ echo tax_algorithm_list($name, $value, $submit_on_change);
+ echo "</td>\n";
+}
+
+function tax_algorithm_list_row($label, $name, $value=null, $submit_on_change=false)
+{
+ echo "<tr><td class='label'>$label</td>";
+ tax_algorithm_list_cells(null, $name, $value, $submit_on_change);
+ echo "</tr>\n";
+}
?>
\ No newline at end of file
function read_supplier_details_to_trans(&$supp_trans, $supplier_id)
{
$sql = "SELECT supp.supp_name, terms.terms, terms.days_before_due,
- terms.day_in_following_month, supp.tax_included,
+ terms.day_in_following_month, supp.tax_included, supp.tax_algorithm,
supp.tax_group_id, tax_group.name AS tax_group_name,
supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
* (ov_amount + ov_gst + ov_discount),0)) as cur_credit
$supp_trans->supplier_id = $supplier_id;
$supp_trans->tax_included = $myrow['tax_included'];
+ $supp_trans->tax_algorithm = $supp_trans->stored_algorithm = $myrow['tax_algorithm'];
$supp_trans->supplier_name = $myrow['supp_name'];
$supp_trans->terms = array(
'description' => $myrow['terms'],
$tax_total += $taxes[$n]['Value'];
}
- $invoice_items_total = $supp_trans->get_items_total();
+ $invoice_items_total = $supp_trans->get_items_total(); // get total with/without tax dep. on tax_included
// $invoice_items_total = $supp_trans->get_total_taxfree($supp_trans->tax_group_id);
if($supp_trans->tax_included==0) {
/*First insert the invoice into the supp_trans table*/
$invoice_id = write_supp_trans($trans_type, 0, $supp_trans->supplier_id, $date_, $supp_trans->due_date,
$supp_trans->reference, $supp_trans->supp_reference,
- $invoice_items_total, $item_added_tax, $supp_trans->ov_discount, "", 0, $supp_trans->tax_included);
+ $invoice_items_total, $item_added_tax, $supp_trans->ov_discount, "", 0, $supp_trans->tax_included,
+ $supp_trans->tax_algorithm);
$total = 0;
/* Now the control account */
$supp_trans->ov_discount = $trans_row["ov_discount"];
$supp_trans->ov_gst = $trans_row["ov_gst"];
$supp_trans->tax_included = $trans_row["tax_included"];
+ $supp_trans->stored_algorithm = $supp_trans->tax_algorithm = $trans_row["tax_algorithm"];
$id = $trans_row["trans_no"];
$order->order_no = $order_no;
$order->set_supplier($myrow["supplier_id"], $myrow["supp_name"], $myrow["curr_code"],
- $myrow['tax_group_id'], $myrow["tax_included"]);
+ $myrow['tax_group_id'], $myrow["tax_included"], $myrow["tax_algorithm"]);
$order->credit = get_current_supp_credit($order->supplier_id);
// FIXME - this should be revised for transaction update case.
//
function write_supp_trans($type, $trans_no, $supplier_id, $date_, $due_date, $reference, $supp_reference,
- $amount, $amount_tax, $discount, $err_msg="", $rate=0, $included=0)
+ $amount, $amount_tax, $discount, $err_msg="", $rate=0, $included=0, $tax_algorithm = null)
{
$new = $trans_no==0;
$date = date2sql($date_);
$sql = "INSERT INTO ".TB_PREF."supp_trans (trans_no, type, supplier_id, tran_date, due_date,
- reference, supp_reference, ov_amount, ov_gst, rate, ov_discount, tax_included) ";
+ reference, supp_reference, ov_amount, ov_gst, rate, ov_discount, tax_included, tax_algorithm) ";
$sql .= "VALUES (".db_escape($trans_no).", ".db_escape($type)
.", ".db_escape($supplier_id).", '$date', '$due_date',
".db_escape($reference).", ".db_escape($supp_reference).", ".db_escape($amount)
- .", ".db_escape($amount_tax).", ".db_escape($rate).", ".db_escape($discount).", ".db_escape($included).")";
+ .", ".db_escape($amount_tax).", ".db_escape($rate).", ".db_escape($discount).", ".db_escape($included).
+ ", ".db_escape($tax_algorithm, true).")";
if ($err_msg == "")
$err_msg = "Cannot insert a supplier transaction record";
function add_supplier($supp_name, $supp_ref, $address, $supp_address, $gst_no,
$website, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id,
$curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
- $notes, $tax_group_id, $tax_included)
+ $notes, $tax_group_id, $tax_included, $tax_algorithm)
{
$sql = "INSERT INTO ".TB_PREF."suppliers (supp_name, supp_ref, address, supp_address, gst_no, website,
supp_account_no, bank_account, credit_limit, dimension_id, dimension2_id, curr_code,
payment_terms, payable_account, purchase_account, payment_discount_account, notes,
- tax_group_id, tax_included)
+ tax_group_id, tax_included, tax_algorithm)
VALUES (".db_escape($_POST['supp_name']). ", "
.db_escape($supp_ref). ", "
.db_escape($address) . ", "
.db_escape($payment_discount_account). ", "
.db_escape($notes). ", "
.db_escape($tax_group_id). ", "
- .db_escape($tax_included). ")";
+ .db_escape($tax_included). ", "
+ .db_escape($tax_algorithm). ")";
db_query($sql,"The supplier could not be added");
}
function update_supplier($supplier_id, $supp_name, $supp_ref, $address, $supp_address, $gst_no,
$website, $supp_account_no, $bank_account, $credit_limit, $dimension_id, $dimension2_id,
$curr_code, $payment_terms, $payable_account, $purchase_account, $payment_discount_account,
- $notes, $tax_group_id, $tax_included)
+ $notes, $tax_group_id, $tax_included, $tax_algorithm)
{
$sql = "UPDATE ".TB_PREF."suppliers SET supp_name=".db_escape($supp_name) . ",
supp_ref=".db_escape($supp_ref) . ",
payment_discount_account=".db_escape($payment_discount_account) . ",
notes=".db_escape($notes) . ",
tax_group_id=".db_escape($tax_group_id). ",
- tax_included=".db_escape($tax_included)
+ tax_included=".db_escape($tax_included).",
+ tax_algorithm=".db_escape($tax_algorithm)
." WHERE supplier_id = ".db_escape($supplier_id);
db_query($sql,"The supplier could not be updated");
".TB_PREF."payment_terms.days_before_due,
".TB_PREF."payment_terms.day_in_following_month";
- $result = db_query($sql,"The customer details could not be retrieved");
+ $result = db_query($sql,"The supplier details could not be retrieved");
$supp = db_fetch($result);
return $supp;
return !key_in_foreign_table($id, $tables, 'supplier_id');
}
+
+function update_supp_tax_algorithm($supplier_id, $tax_algorithm)
+{
+ $sql = "UPDATE ".TB_PREF."suppliers SET tax_algorithm=".db_escape($tax_algorithm)
+ . " WHERE supplier_id=".db_escape($supplier_id);
+ return db_query($sql, "cannot update supplier's tax calculation algorithm");
+}
+
?>
\ No newline at end of file
var $tax_group_id;
var $tax_group_array = null; // saves db queries
var $tax_included; // type of prices
+ var $tax_algorithm;
+ var $stored_algorithm; // copy to find the change after invoice in processed
var $terms;
var $reference;
$this->lines_on_order = $this->order_no = $this->supplier_id = 0;
}
- function set_supplier($supplier_id, $supplier_name, $curr_code, $tax_group_id, $tax_included)
+ function set_supplier($supplier_id, $supplier_name, $curr_code, $tax_group_id, $tax_included, $tax_algorithm)
{
$this->supplier_id = $supplier_id;
$this->supplier_name = $supplier_name;
$this->curr_code = $curr_code;
$this->tax_group_id = $tax_group_id;
$this->tax_included = $tax_included;
+ $this->stored_algorithm = $this->tax_algorithm = $tax_algorithm;
$this->tax_group_array = get_tax_group_items_as_array($tax_group_id);
}
$prices[] = round($ln_itm->price * ($receival ? $ln_itm->receive_qty : $ln_itm->quantity), user_price_dec());
}
$taxes = get_tax_for_items($items, $prices, $shipping_cost,
- $this->tax_group_id, $this->tax_included, $this->tax_group_array);
-
+ $this->tax_group_id, $this->tax_included, $this->tax_group_array, $this->tax_algorithm);
// Adjustment for swiss franken, we always have 5 rappen = 1/20 franken
if ($this->curr_code == 'CHF') {
$val = $taxes['1']['Value'];
- $val1 = (floatval((intval(round(($val*20),0)))/20));
- $taxes['1']['Value'] = $val1;
+ $taxes['1']['Value'] = (floatval((intval(round(($val*20),0)))/20));
}
return $taxes;
}
if (!$this->tax_included ) {
$taxes = get_tax_for_items($items, $prices, 0, $this->tax_group_id,
- $this->tax_included, $this->tax_group_array);
+ $this->tax_included, $this->tax_group_array, $this->tax_algorithm);
foreach($taxes as $tax)
$total += round($tax['Value'], $dec);
var $ov_gst;
var $gl_codes_counter=0;
var $credit = 0;
+ var $tax_algorithm;
+ var $stored_algorithm;
function supp_trans($trans_type)
{
if ($tax_group_id == null)
$tax_group_id = $this->tax_group_id;
$taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id,
- $this->tax_included);
+ $this->tax_included, null, $this->tax_algorithm);
///////////////// Joe Hunt 2009.08.18
}
return $total;
}
-
+ //
+ // Returns transaction total
+ //
function get_items_total()
{
$total = 0;
$_POST['supp_reference'] = $supp_trans->supp_reference;
$_POST['reference'] = $supp_trans->reference;
$_POST['supplier_id'] = $supp_trans->supplier_id;
+ $_POST['tax_algorithm'] = $supp_trans->tax_algorithm;
}
//--------------------------------------------------------------------------------------------------
$supp_trans->due_date = $_POST['due_date'];
$supp_trans->supp_reference = $_POST['supp_reference'];
$supp_trans->reference = $_POST['reference'];
+ if (isset($_POST['tax_algorithm']))
+ $supp_trans->tax_algorithm = $_POST['tax_algorithm'];
$supp_trans->ov_amount = 0; /* for starters */
if (count($supp_trans->grn_items) > 0)
function invoice_totals(&$supp_trans)
{
+ global $Ajax;
+
copy_to_trans($supp_trans);
$dim = get_company_pref('use_dimension');
$colspan = ($dim == 2 ? 7 : ($dim == 1 ? 6 : 5));
+ div_start('tax_table');
start_table(TABLESTYLE, "width=95%");
label_row(_("Sub-total:"), price_format( $supp_trans->ov_amount), "colspan=$colspan align=right", "align=right");
end_table(1);
start_table(TABLESTYLE2);
+ tax_algorithm_list_row(_("Tax algorithm:"), 'tax_algorithm', null, true);
+ if (list_updated('tax_algorithm')) {
+ $supp_trans->tax_algorithm = $_POST['tax_algorithm'];
+ $Ajax->activate('tax_table');
+ }
textarea_row(_("Memo:"), "Comments", null, 50, 3);
end_table(1);
+ div_end();
}
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------
function supplier_settings(&$supplier_id)
{
-
+
start_outer_table(TABLESTYLE2);
table_section(1);
$_POST['credit_limit'] = price_format($myrow["credit_limit"]);
$_POST['tax_group_id'] = $myrow["tax_group_id"];
$_POST['tax_included'] = $myrow["tax_included"];
+ $_POST['tax_algorithm'] = $myrow["tax_algorithm"];
$_POST['payable_account'] = $myrow["payable_account"];
$_POST['purchase_account'] = $myrow["purchase_account"];
$_POST['payment_discount_account'] = $myrow["payment_discount_account"];
$_POST['dimension_id'] = 0;
$_POST['dimension2_id'] = 0;
$_POST['tax_included'] = 0;
+ $_POST['tax_algorithm'] = 1;
$_POST['sales_type'] = -1;
$_POST['gst_no'] = $_POST['bank_account'] = '';
$_POST['payment_terms'] = '';
payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
//
// tax_included option from supplier record is used directly in update_average_cost() function,
- // therefore we can't edit the option after any transaction waas done for the supplier.
+ // therefore we can't edit the option after any transaction was done for the supplier.
//
if (is_new_supplier($supplier_id))
check_row(_("Prices contain tax included:"), 'tax_included');
hidden('tax_included');
label_row(_("Prices contain tax included:"), $_POST['tax_included'] ? _('Yes') : _('No'));
}
+ tax_algorithm_list_row(_("Tax Calculation Algorithm:"), 'tax_algorithm', null);
+
+ if (!$supplier_id) table_section(2);
+
table_section_title(_("Accounts"));
gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account'],
false, false, _("Use Item Inventory/COGS Account"));
gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
- table_section(2);
+ if ($supplier_id) table_section(2);
$dim = get_company_pref('use_dimension');
if ($dim >= 1)
{
$_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'],
input_num('credit_limit', 0), $_POST['dimension_id'], $_POST['dimension2_id'], $_POST['curr_code'],
$_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'], $_POST['payment_discount_account'],
- $_POST['notes'], $_POST['tax_group_id'], @$_POST['tax_included']);
+ $_POST['notes'], $_POST['tax_group_id'], @$_POST['tax_included'], get_post('tax_algorithm'));
update_record_status($_POST['supplier_id'], $_POST['inactive'],
'suppliers', 'supplier_id');
$_POST['gst_no'], $_POST['website'], $_POST['supp_account_no'], $_POST['bank_account'],
input_num('credit_limit',0), $_POST['dimension_id'], $_POST['dimension2_id'],
$_POST['curr_code'], $_POST['payment_terms'], $_POST['payable_account'], $_POST['purchase_account'],
- $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
+ $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'), get_post('tax_algorithm'));
$supplier_id = $_POST['supplier_id'] = db_insert_id();
if (!check_data())
return;
+ $inv = $_SESSION['supp_trans'];
+ $invoice_no = add_supp_invoice($inv);
- $invoice_no = add_supp_invoice($_SESSION['supp_trans']);
+ // presume supplier data need correction
+ if ($inv->stored_algorithm != $inv->tax_algorithm)
+ update_supp_tax_algorithm($inv->supplier_id, $inv->tax_algorithm);
$_SESSION['supp_trans']->clear_items();
unset($_SESSION['supp_trans']);
{
global $check_price_charged_vs_order_price,
$check_qty_charged_vs_del_qty, $SysPrefs;
+
if (!check_num('this_quantity_inv'.$n, 0) || input_num('this_quantity_inv'.$n)==0)
{
display_error( _("The quantity to invoice must be numeric and greater than zero."));
function get_po($order_no)
{
$sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, "
- .TB_PREF."suppliers.supp_account_no,".TB_PREF."suppliers.tax_included,
+ .TB_PREF."suppliers.supp_account_no,".TB_PREF."suppliers.tax_included,".TB_PREF."suppliers.tax_algorithm,
".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.payment_terms, ".TB_PREF."locations.location_name,
".TB_PREF."suppliers.address, ".TB_PREF."suppliers.contact, ".TB_PREF."suppliers.tax_group_id
FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations
$rep->NewLine();
$tax_items = get_tax_for_items($items, $prices, 0,
- $myrow['tax_group_id'], $myrow['tax_included'], null);
+ $myrow['tax_group_id'], $myrow['tax_included'], null, $myrow['tax_algorithm']);
$first = true;
foreach($tax_items as $tax_item)
{
`curr_code` char(3) default NULL,
`payment_terms` int(11) default NULL,
`tax_included` tinyint(1) NOT NULL default '0',
+ `tax_algorithm` tinyint(1) NOT NULL default '1',
`dimension_id` int(11) default '0',
`dimension2_id` int(11) default '0',
`tax_group_id` int(11) default NULL,
-- Dumping data for table `0_suppliers`
--
-INSERT INTO `0_suppliers` VALUES(1, 'Junk Beer ApS', 'Junk Beer', 'Mailing 1\nMailing 2\nMailing 3', 'Address 1\nAddress 2\nAddress 3', '123456', 'Contact', '111', '', '', 'DKK', 3, 0, 1, 0, 2, 1000, '', '2100', '5060', 'A supplier with junk beers.', 0);
-INSERT INTO `0_suppliers` VALUES(2, 'Lucky Luke Inc.', 'Lucky Luke', 'Mailing 1\nMailing 2\nMailing 3', 'Address 1\nAddress 2\nAddress 3', '654321', 'Luke', '333', '', '', 'USD', 3, 0, 0, 0, 1, 500, '', '2100', '5060', '', 0);
-INSERT INTO `0_suppliers` VALUES(3, 'Money Makers Ltd.', 'Money Makers', 'Mailing 1\nMailing 2\nMailing 3', 'Address 1\nAddress 2\nAddress 3', '987654', 'Makers', '222', '', '', 'GBP', 3, 0, 0, 0, 2, 300, '', '2100', '5060', '', 0);
+INSERT INTO `0_suppliers` VALUES(1, 'Junk Beer ApS', 'Junk Beer', 'Mailing 1\nMailing 2\nMailing 3', 'Address 1\nAddress 2\nAddress 3', '123456', 'Contact', '111', '', '', 'DKK', 3, 0, 1, 1, 0, 2, 1000, '', '2100', '5060', 'A supplier with junk beers.', 0);
+INSERT INTO `0_suppliers` VALUES(2, 'Lucky Luke Inc.', 'Lucky Luke', 'Mailing 1\nMailing 2\nMailing 3', 'Address 1\nAddress 2\nAddress 3', '654321', 'Luke', '333', '', '', 'USD', 3, 0, 1, 0, 0, 1, 500, '', '2100', '5060', '', 0);
+INSERT INTO `0_suppliers` VALUES(3, 'Money Makers Ltd.', 'Money Makers', 'Mailing 1\nMailing 2\nMailing 3', 'Address 1\nAddress 2\nAddress 3', '987654', 'Makers', '222', '', '', 'GBP', 3, 0, 1, 0, 0, 2, 300, '', '2100', '5060', '', 0);
-- --------------------------------------------------------
`rate` double NOT NULL default '1',
`alloc` double NOT NULL default '0',
`tax_included` tinyint(1) NOT NULL default '0',
+ `tax_algorihm` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`type`,`trans_no`),
KEY `supplier_id` (`supplier_id`),
KEY `SupplierID_2` (`supplier_id`,`supp_reference`),
-- Dumping data for table `0_supp_trans`
--
-INSERT INTO `0_supp_trans` VALUES(7, 20, 2, '1', '5t', '2009-06-21', '2009-07-01', 3300, 0, 165, 1, 3465, 0);
-INSERT INTO `0_supp_trans` VALUES(8, 20, 2, '2', 'cc', '2009-06-21', '2009-07-01', 20, 0, 0, 1, 0, 0);
-INSERT INTO `0_supp_trans` VALUES(4, 22, 2, '1', '', '2009-06-21', '2009-06-21', -3465, 0, 0, 1, 3465, 0);
+INSERT INTO `0_supp_trans` VALUES(7, 20, 2, '1', '5t', '2009-06-21', '2009-07-01', 3300, 0, 165, 1, 3465, 0, 1);
+INSERT INTO `0_supp_trans` VALUES(8, 20, 2, '2', 'cc', '2009-06-21', '2009-07-01', 20, 0, 0, 1, 0, 0, 1);
+INSERT INTO `0_supp_trans` VALUES(4, 22, 2, '1', '', '2009-06-21', '2009-06-21', -3465, 0, 0, 1, 3465, 0, 1);
-- --------------------------------------------------------
INSERT INTO `0_sys_prefs` VALUES('retained_earnings_act', 'glsetup.general', 'varchar', 15, '3590');
INSERT INTO `0_sys_prefs` VALUES('bank_charge_act', 'glsetup.general', 'varchar', 15, '5690');
INSERT INTO `0_sys_prefs` VALUES('exchange_diff_act', 'glsetup.general', 'varchar', 15, '4450');
+INSERT INTO `0_sys_prefs` VALUES('tax_algorithm', 'glsetup.general', 'tinyint', 1, '1');
INSERT INTO `0_sys_prefs` VALUES('default_credit_limit', 'glsetup.customer', 'int', 11, '1000');
INSERT INTO `0_sys_prefs` VALUES('accumulate_shipping', 'glsetup.customer', 'tinyint', 1, '0');
INSERT INTO `0_sys_prefs` VALUES('legal_text', 'glsetup.customer', 'tinytext', 0, '');
`curr_code` char(3) default NULL,
`payment_terms` int(11) default NULL,
`tax_included` tinyint(1) NOT NULL default '0',
+ `tax_algorithm` tinyint(1) NOT NULL default '1',
`dimension_id` int(11) default '0',
`dimension2_id` int(11) default '0',
`tax_group_id` int(11) default NULL,
`rate` double NOT NULL default '1',
`alloc` double NOT NULL default '0',
`tax_included` tinyint(1) NOT NULL default '0',
+ `tax_algorihm` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`type`,`trans_no`),
KEY `supplier_id` (`supplier_id`),
KEY `SupplierID_2` (`supplier_id`,`supp_reference`),
INSERT INTO `0_sys_prefs` VALUES('retained_earnings_act', 'glsetup.general', 'varchar', 15, '3590');
INSERT INTO `0_sys_prefs` VALUES('bank_charge_act', 'glsetup.general', 'varchar', 15, '5690');
INSERT INTO `0_sys_prefs` VALUES('exchange_diff_act', 'glsetup.general', 'varchar', 15, '4450');
+INSERT INTO `0_sys_prefs` VALUES('tax_algorithm', 'glsetup.general', 'tinyint', 1, '1');
INSERT INTO `0_sys_prefs` VALUES('default_credit_limit', 'glsetup.customer', 'int', 11, '1000');
INSERT INTO `0_sys_prefs` VALUES('accumulate_shipping', 'glsetup.customer', 'tinyint', 1, '0');
INSERT INTO `0_sys_prefs` VALUES('legal_text', 'glsetup.customer', 'tinytext', 0, '');
//-----------------------------------------------------------------------------------
// return an array of (tax_type_id, tax_type_name, sales_gl_code, purchasing_gl_code, rate, included_in_price, Value)
-function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_included=null, $tax_items_array=null)
+function get_tax_for_items($items, $prices, $shipping_cost, $tax_group, $tax_included=null, $tax_items_array=null, $tax_algorithm = null)
{
+ if (!$tax_algorithm)
+ $tax_algorithm = get_company_pref('tax_algorithm');
// first create and set an array with all the tax types of the tax group
if($tax_items_array!=null)
$ret_tax_array = $tax_items_array;
else
$ret_tax_array = get_tax_group_items_as_array($tax_group);
+ $dec = user_price_dec();
foreach($ret_tax_array as $k=>$t)
$ret_tax_array[$k]['Net'] = 0;
$index = $item_tax['tax_type_id'];
if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings
$nprice = get_tax_free_price_for_item($items[$i], $prices[$i], $tax_group, $tax_included);
- $ret_tax_array[$index]['Value'] += ($nprice * $item_tax['rate'] / 100);
+ $ret_tax_array[$index]['Value'] += round2($nprice * $item_tax['rate'] / 100, $dec);
$ret_tax_array[$index]['Net'] += $nprice;
} else {
- $ret_tax_array[$index]['Value'] += ($prices[$i] * $item_tax['rate'] / 100);
+ $ret_tax_array[$index]['Value'] += round2($prices[$i] * $item_tax['rate'] / 100, $dec);
$ret_tax_array[$index]['Net'] += $prices[$i];
}
}
$tax_rate += $item_tax['rate'];
}
}
- $shipping_net = round2($shipping_cost / (1 + ($tax_rate / 100)), user_price_dec());
+ $shipping_net = round2($shipping_cost / (1 + ($tax_rate / 100)), $dec);
}
foreach ($item_taxes as $item_tax)
{
$index = $item_tax['tax_type_id'];
if(isset($ret_tax_array[$index])) {
if($tax_included==1) {// 2008-11-26 Joe Hunt Taxes are stored without roundings
- $ret_tax_array[$index]['Value'] += ($shipping_net * $item_tax['rate'] / 100);
+ $ret_tax_array[$index]['Value'] += round2($shipping_net * $item_tax['rate'] / 100, $dec);
$ret_tax_array[$index]['Net'] += $shipping_net;
} else {
- $ret_tax_array[$index]['Value'] += ($shipping_cost * $item_tax['rate'] / 100);
+ $ret_tax_array[$index]['Value'] += round2($shipping_cost * $item_tax['rate'] / 100, $dec);
$ret_tax_array[$index]['Net'] += $shipping_cost;
- }
+ }
}
}
}
}
- //print_r($ret_tax_array);
+ if ($tax_algorithm == TCA_TOTALS ) {
+ // update taxes with
+ foreach($ret_tax_array as $index => $item_tax) {
+ $ret_tax_array[$index]['Value'] = round2($item_tax['Net'] * $item_tax['rate'] / 100, $dec);
+ }
+ }
return $ret_tax_array;
}