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, supp.tax_algorithm,
+ terms.day_in_following_month, supp.tax_included,
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'],
/*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,
- $supp_trans->tax_algorithm);
+ $invoice_items_total, $item_added_tax, $supp_trans->ov_discount, "", 0, $supp_trans->tax_included);
if ($trans_no)
move_trans_attachments($trans_type, $trans_no, $invoice_id);
$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"];
function get_supplier_details_to_order(&$order, $supplier_id)
{
- $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included, supp.tax_algorithm,
+ $sql = "SELECT curr_code, supp_name, tax_group_id, supp.tax_included,
supp.credit_limit - Sum(IFNULL(IF(trans.type=".ST_SUPPCREDIT.", -1, 1)
* (ov_amount + ov_gst + ov_discount),0)) as cur_credit,
terms.terms, terms.days_before_due, terms.day_in_following_month
$_POST['curr_code'] = $myrow["curr_code"];
$order->set_supplier($supplier_id, $myrow["supp_name"], $myrow["curr_code"],
- $myrow["tax_group_id"], $myrow["tax_included"], $myrow["tax_algorithm"]);
+ $myrow["tax_group_id"], $myrow["tax_included"]);
}
//----------------------------------------------------------------------------------------
$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_algorithm"]);
+ $myrow['tax_group_id'], $myrow["tax_included"]);
$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, $tax_algorithm = null)
+ $amount, $amount_tax, $discount, $err_msg="", $rate=0, $included=0)
{
$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, tax_algorithm) ";
+ reference, supp_reference, ov_amount, ov_gst, rate, ov_discount, tax_included) ";
$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($tax_algorithm, true).")";
+ .", ".db_escape($amount_tax).", ".db_escape($rate).", ".db_escape($discount).", ".db_escape($included).")";
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, $tax_algorithm)
+ $notes, $tax_group_id, $tax_included)
{
$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_algorithm)
+ tax_group_id, tax_included)
VALUES (".db_escape($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_algorithm). ")";
+ .db_escape($tax_included). ")";
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, $tax_algorithm)
+ $notes, $tax_group_id, $tax_included)
{
$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_algorithm=".db_escape($tax_algorithm)
+ tax_included=".db_escape($tax_included)
." WHERE supplier_id = ".db_escape($supplier_id);
db_query($sql,"The supplier could not be updated");
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");
-}
-
function get_supplier_currency($supplier_id)
{
$sql = "SELECT curr_code FROM ".TB_PREF."suppliers WHERE supplier_id = ".db_escape($supplier_id);
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 $ex_rate;
var $cash_account;
$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, $tax_algorithm)
+ function set_supplier($supplier_id, $supplier_name, $curr_code, $tax_group_id, $tax_included)
{
$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_algorithm);
+ $this->tax_group_id, $this->tax_included, $this->tax_group_array);
// Adjustment for swiss franken, we always have 5 rappen = 1/20 franken
if ($this->curr_code == 'CHF') {
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_algorithm);
+ $this->tax_included, $this->tax_group_array);
foreach($taxes as $tax)
$total += round($tax['Value'], $dec);
$inv->reference = $ref;
$inv->supp_reference = $cart->supp_ref;
$inv->tax_included = $cart->tax_included;
- $inv->tax_algorithm = $cart->tax_algorithm;
- $inv->stored_algorithm = $cart->stored_algorithm;
$supp = get_supplier($cart->supplier_id);
$inv->tax_group_id = $supp['tax_group_id'];
$inv->ov_amount = $inv->ov_gst = $inv->ov_discount = 0;
}
$inv->tax_overrides = $cart->tax_overrides;
if (!$inv->tax_included) {
- $taxes = $inv->get_taxes($inv->tax_group_id, 0, false, $inv->tax_algorithm);
+ $taxes = $inv->get_taxes($inv->tax_group_id, 0, false);
foreach( $taxes as $taxitem) {
$total += isset($taxitem['Override']) ? $taxitem['Override'] : $taxitem['Value'];
}
$inv_no = add_supp_invoice($inv);
- // presume supplier data need correction
- if ($inv->stored_algorithm != $inv->tax_algorithm)
- update_supp_tax_algorithm($inv->supplier_id, $inv->tax_algorithm);
-
if ($cart->cash_account) {
$pmt_no = write_supp_payment(0, $inv->supplier_id, $cart->cash_account, $inv->tran_date, $Refs->get_next(ST_SUPPAYMENT),
$total, 0, _('Payment for:').$inv->supp_reference .' ('.$type_shortcuts[ST_SUPPINVOICE].$inv_no.')');
var $ov_gst;
var $gl_codes_counter=0;
var $credit = 0;
- var $tax_algorithm;
- var $stored_algorithm;
var $currency;
var $tax_overrides = array(); // array of taxes manually inserted during sales invoice entry
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, null, $this->tax_algorithm);
+ $this->tax_included);
if (isset($this->tax_overrides))
foreach($this->tax_overrides as $id => $value) // add values entered manually
$_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;
$_POST['dimension'] = $supp_trans->dimension;
$_POST['dimension2'] = $supp_trans->dimension2;
$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->dimension = @$_POST['dimension'];
$supp_trans->dimension2 = @$_POST['dimension2'];
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();
$_POST['Comments'] = $cart->Comments;
$_POST['StkLocation'] = $cart->Location;
$_POST['delivery_address'] = $cart->delivery_address;
- $_POST['tax_algorithm'] = $cart->tax_algorithm;
$_POST['prep_amount'] = price_format($cart->prep_amount);
$_POST['_ex_rate'] = $cart->ex_rate;
$_POST['cash_account'] = $cart->cash_account;
$cart->delivery_address = $_POST['delivery_address'];
$cart->dimension = @$_POST['dimension'];
$cart->dimension2 = @$_POST['dimension2'];
- if (isset($_POST['tax_algorithm']))
- $cart->tax_algorithm = $_POST['tax_algorithm'];
$cart->prep_amount = input_num('prep_amount', 0);
$cart->ex_rate = input_num('_ex_rate', null);
get_supplier_details_to_order($order, $_POST['supplier_id']);
get_duedate_from_terms($order);
$_POST['due_date'] = $order->due_date;
- $_POST['tax_algorithm'] = $order->tax_algorithm;
// supplier default price update
foreach ($order->line_items as $line_no=>$item) {
}
$Ajax->activate('items_table');
$Ajax->activate('due_date');
- $Ajax->activate('tax_algorithm');
}
set_global_supplier($_POST['supplier_id']);
start_table(TABLESTYLE2);
-if (list_updated('tax_algorithm')) {
- $trans->tax_algorithm = $_POST['tax_algorithm'];
- $Ajax->activate('items_table');
-}
-
if ($trans->trans_type == ST_SUPPINVOICE) {
- tax_algorithm_list_row(_("Tax algorithm:"), 'tax_algorithm', null, true);
cash_accounts_list_row(_("Payment:"), 'cash_account', null, false, _('Delayed'));
} elseif ($trans->trans_type == ST_PURCHORDER)
amount_row(_("Pre-Payment Required:"), 'prep_amount');
$_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'] = '';
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);
$_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'], get_post('tax_included', 0), get_post('tax_algorithm'));
+ $_POST['notes'], $_POST['tax_group_id'], get_post('tax_included', 0));
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'), get_post('tax_algorithm'));
+ $_POST['payment_discount_account'], $_POST['notes'], $_POST['tax_group_id'], check_value('tax_included'));
$supplier_id = $_POST['supplier_id'] = db_insert_id();
start_table(TABLESTYLE2);
-if (list_updated('tax_algorithm')) {
- $_SESSION['PO']->tax_algorithm = $_POST['tax_algorithm'];
- $Ajax->activate('items_table');
-}
if ($_SESSION['PO']->trans_type == ST_SUPPINVOICE) {
- tax_algorithm_list_row(_("Tax algorithm:"), 'tax_algorithm', null, true);
cash_accounts_list_row(_("Payment:"), 'cash_account', null, false, _('Delayed'));
}
$inv = $_SESSION['supp_trans'];
$invoice_no = add_supp_invoice($inv);
- // 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']);
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.tax_algorithm,".TB_PREF."suppliers.gst_no AS tax_id,
+ .TB_PREF."suppliers.supp_account_no,".TB_PREF."suppliers.tax_included,".TB_PREF."suppliers.gst_no AS tax_id,
".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_algorithm']);
+ $myrow['tax_group_id'], $myrow['tax_included'], null, TCA_LINES);
$first = true;
foreach($tax_items as $tax_item)
{
-ALTER TABLE `0_suppliers` ADD COLUMN `tax_algorithm` tinyint(1) NOT NULL default '1' AFTER `tax_included`;
-ALTER TABLE `0_supp_trans` ADD COLUMN `tax_algorithm` tinyint(1) NULL default '1' AFTER `tax_included`;
INSERT INTO `0_sys_prefs` VALUES('tax_algorithm','glsetup.customer', 'tinyint', 1, '1');
INSERT INTO `0_sys_prefs` VALUES('gl_closing_date','setup.closing_date', 'date', 8, '');
ALTER TABLE `0_audit_trail` CHANGE `fiscal_year` `fiscal_year` int(11) NOT NULL default 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,
-- 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, 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);
+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);
-- --------------------------------------------------------
`rate` double NOT NULL default '1',
`alloc` double NOT NULL default '0',
`tax_included` tinyint(1) NOT NULL default '0',
- `tax_algorithm` 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', '2014-06-21', '2014-07-01', 3300, 0, 165, 1, 3465, 0, 1);
-INSERT INTO `0_supp_trans` VALUES(8, 20, 2, '2', 'cc', '2014-06-21', '2014-07-01', 20, 0, 0, 1, 0, 0, 1);
-INSERT INTO `0_supp_trans` VALUES(4, 22, 2, '1', '', '2014-06-21', '2014-06-21', -3465, 0, 0, 1, 3465, 0, 1);
+INSERT INTO `0_supp_trans` VALUES(7, 20, 2, '1', '5t', '2014-06-21', '2014-07-01', 3300, 0, 165, 1, 3465, 0);
+INSERT INTO `0_supp_trans` VALUES(8, 20, 2, '2', 'cc', '2014-06-21', '2014-07-01', 20, 0, 0, 1, 0, 0);
+INSERT INTO `0_supp_trans` VALUES(4, 22, 2, '1', '', '2014-06-21', '2014-06-21', -3465, 0, 0, 1, 3465, 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_algorithm` tinyint(1) NOT NULL default '1',
PRIMARY KEY (`type`,`trans_no`),
KEY `supplier_id` (`supplier_id`),
KEY `SupplierID_2` (`supplier_id`,`supp_reference`),