[0000598] Added tax_included field to debtor_trans table.
authorJanusz Dobrowolski <janusz@frontaccouting.eu>
Thu, 16 Feb 2012 12:57:20 +0000 (13:57 +0100)
committerJanusz Dobrowolski <janusz@frontaccouting.eu>
Thu, 16 Feb 2012 12:57:20 +0000 (13:57 +0100)
sales/includes/db/cust_trans_db.inc
sales/includes/db/sales_credit_db.inc
sales/includes/db/sales_delivery_db.inc
sales/includes/db/sales_invoice_db.inc
sql/alter2.4.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index 748fc2a082f6134abe7de6f193cb012d2fe7971f..09b635fc9ea0f02e74ddc8bbfd6621b72d2aac9c 100644 (file)
@@ -56,7 +56,7 @@ function get_customer_trans_version($type, $trans_no) {
 function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
        $date_, $reference, $Total, $discount=0, $Tax=0, $Freight=0, $FreightTax=0,
        $sales_type=0, $order_no=0, $ship_via=0, $due_date="",
-       $AllocAmt=0, $rate=0, $dimension_id=0, $dimension2_id=0, $payment_terms=null)
+       $AllocAmt=0, $rate=0, $dimension_id=0, $dimension2_id=0, $payment_terms=null, $tax_included=0)
 {
        $new = $trans_no==0;
        $curr = get_customer_currency($debtor_no);
@@ -83,7 +83,7 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
                order_, ov_amount, ov_discount,
                ov_gst, ov_freight, ov_freight_tax,
                rate, ship_via, alloc,
-               dimension_id, dimension2_id, payment_terms
+               dimension_id, dimension2_id, payment_terms, tax_included
                ) VALUES (".db_escape($trans_no).", ".db_escape($trans_type).",
                ".db_escape($debtor_no).", ".db_escape($BranchNo).",
                '$SQLDate', '$SQLDueDate', ".db_escape($reference).",
@@ -91,7 +91,8 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
                ".db_escape($Freight).",
                $FreightTax, $rate, ".db_escape($ship_via).", $AllocAmt,
                ".db_escape($dimension_id).", ".db_escape($dimension2_id).", "
-               .db_escape($payment_terms, true).")";
+               .db_escape($payment_terms, true).", "
+               .db_escape($tax_included).")";
        } else {        // may be optional argument should stay unchanged ?
        $sql = "UPDATE ".TB_PREF."debtor_trans SET
                debtor_no=".db_escape($debtor_no)." , branch_code=".db_escape($BranchNo).",
@@ -101,7 +102,8 @@ function write_customer_trans($trans_type, $trans_no, $debtor_no, $BranchNo,
                ov_freight=".db_escape($Freight).", ov_freight_tax=$FreightTax, rate=$rate,
                ship_via=".db_escape($ship_via).", alloc=$AllocAmt,
                dimension_id=".db_escape($dimension_id).", dimension2_id=".db_escape($dimension2_id).",
-               payment_terms=".db_escape($payment_terms)."
+               payment_terms=".db_escape($payment_terms).",
+               tax_included=".db_escape($tax_included)."
                WHERE trans_no=".db_escape($trans_no)." AND type=".db_escape($trans_type);
        }
        db_query($sql, "The debtor transaction record could not be inserted");
index ce1cb17f14ae5fd9097cc7ab5476eaf530a4fa37..869dc538accd3e148b33764763cc5ce5ff607be8 100644 (file)
@@ -17,8 +17,13 @@ function write_credit_note(&$credit_note, $write_off_acc)
 {
        global $Refs;
 
-       $credit_invoice =       is_array($credit_note->src_docs) ?
-                reset(array_keys($credit_note->src_docs)) : $credit_note->src_docs;
+       if (is_array($credit_note->src_docs))
+       {
+               $docs = array_keys($credit_note->src_docs);
+               $credit_invoice = reset($docs);
+       }
+       else
+               $credit_invoice = $credit_note->src_docs;
 
        $credit_date = $credit_note->document_date;
        $tax_group_id = $credit_note->tax_group_id;
@@ -74,7 +79,7 @@ function write_credit_note(&$credit_note, $write_off_acc)
                $credit_note->freight_cost, $freight_added_tax,
                $credit_note->sales_type, $credit_note->order_no, $credit_note->ship_via,
                null, $alloc, 0, $credit_note->dimension_id, $credit_note->dimension2_id,
-               $credit_note->payment); 
+               $credit_note->payment, $credit_note->tax_included); 
                // 2008-06-14 extra $alloc, 2008-11-12 dimension_id Joe Hunt
 
        if ($trans_no==0) {
index 5c269406349b06a7aeadb09e9db755eb2035dc4f..8f1c48718c2e440bde837942e73eea83cbfa4c0b 100644 (file)
@@ -46,7 +46,7 @@ function write_sales_delivery(&$delivery,$bo_policy)
                $delivery->tax_included ? 0 : $freight_tax,
                $delivery->sales_type, $delivery->order_no,
                $delivery->ship_via, $delivery->due_date, 0, 0, $delivery->dimension_id, 
-               $delivery->dimension2_id, $delivery->payment);
+               $delivery->dimension2_id, $delivery->payment, $delivery->tax_included);
 
        if ($trans_no == 0) {
                $delivery->trans_no = array($delivery_no=>0);
index df56eb4d5d5d18ed2a534339f06dfc4cb1914f26..a13109f0e7c91dd37ee8fc13b55d95f49cc53d0c 100644 (file)
@@ -64,7 +64,7 @@ function write_sales_invoice(&$invoice)
                $items_added_tax, $invoice->freight_cost, $freight_added_tax,
                $invoice->sales_type, $sales_order, $invoice->ship_via, 
                $invoice->due_date, 0, 0, $invoice->dimension_id, 
-               $invoice->dimension2_id, $invoice->payment); 
+               $invoice->dimension2_id, $invoice->payment, $invoice->tax_included); 
                // 2008-06-14 extra $alloc, 2008-11-12 added dimension_id Joe Hunt
 
        if ($trans_no == 0) {
index 73bbcef51e2df4f2767267c8980358257808ed30..d99fdc1fc0934ebeff4e285134b3e69f48e9f1be 100644 (file)
@@ -38,3 +38,7 @@ ALTER TABLE `0_sales_order_details` ADD KEY `stkcode` (`stk_code`);
 ALTER TABLE `0_purch_order_details` ADD KEY `itemcode` (`item_code`);
 ALTER TABLE `0_sys_prefs` CHANGE `value` `value` TEXT NOT NULL DEFAULT '';
 ALTER TABLE `0_cust_branch` ADD COLUMN `bank_account` varchar(60) DEFAULT NULL AFTER `notes`;
+
+ALTER TABLE `0_debtor_trans` ADD COLUMN `tax_included` tinyint(1) unsigned NOT NULL default '0' AFTER `payment_terms`;
+UPDATE `0_debtor_trans` tr, `0_trans_tax_details` td SET tr.tax_included=td.included_in_price
+       WHERE tr.`type`=td.trans_type AND tr.trans_no=td.trans_no AND td.included_in_price
\ No newline at end of file
index b8385dc05a42593a79bdb6a7a81e99b5f33df4fc..5fb4f57d9b0f358d182c0da2ec8b6c67623c7680 100644 (file)
@@ -693,6 +693,7 @@ CREATE TABLE IF NOT EXISTS `0_debtor_trans` (
   `dimension_id` int(11) NOT NULL default '0',
   `dimension2_id` int(11) NOT NULL default '0',
   `payment_terms` int(11) default NULL,
+  `tax_included` tinyint(1) unsigned NOT NULL default '0',
   PRIMARY KEY  (`type`,`trans_no`),
   KEY `debtor_no` (`debtor_no`,`branch_code`),
   KEY `tran_date` (`tran_date`)
@@ -702,14 +703,14 @@ CREATE TABLE IF NOT EXISTS `0_debtor_trans` (
 -- Dumping data for table `0_debtor_trans`
 --
 
-INSERT INTO `0_debtor_trans` VALUES(17, 10, 0, 2, 2, '2009-06-21', '2009-06-22', '1', 1, 2, 50, 2.5, 0, 0, 0, 0, 1, 1, 0, 0, 4);
-INSERT INTO `0_debtor_trans` VALUES(18, 10, 1, 3, 3, '2009-06-21', '2009-07-01', '2', 2, 3, 35.89, 1.79, 0, 0, 0, 37.68, 1.3932, 1, 2, 0, 3);
-INSERT INTO `0_debtor_trans` VALUES(19, 10, 0, 2, 2, '2009-06-21', '2009-06-22', '3', 1, 5, 50, 0, 5, 0, 0, 0, 1, 1, 0, 0, 4);
-INSERT INTO `0_debtor_trans` VALUES(3, 11, 0, 3, 3, '2009-06-21', '0000-00-00', '1', 2, 3, 35.89, 1.79, 0, 0, 0, 37.68, 1.3932, 1, 2, 0, 3);
-INSERT INTO `0_debtor_trans` VALUES(2, 13, 0, 1, 1, '2009-06-21', '2009-06-22', '1', 2, 1, 60.8, 0, 10, 0, 0, 0, 1.6445729799917, 1, 0, 0, 3);
-INSERT INTO `0_debtor_trans` VALUES(3, 13, 1, 2, 2, '2009-06-21', '2009-06-22', 'auto', 1, 2, 50, 2.5, 0, 0, 0, 0, 1, 1, 0, 0, 4);
-INSERT INTO `0_debtor_trans` VALUES(4, 13, 1, 3, 3, '2009-06-21', '2009-07-01', 'auto', 2, 3, 35.89, 1.79, 0, 0, 0, 0, 1.3932, 1, 2, 0, 3);
-INSERT INTO `0_debtor_trans` VALUES(5, 13, 1, 2, 2, '2009-06-21', '2009-06-22', 'auto', 1, 5, 50, 0, 5, 0, 0, 0, 1, 1, 0, 0, 4);
+INSERT INTO `0_debtor_trans` VALUES(17, 10, 0, 2, 2, '2009-06-21', '2009-06-22', '1', 1, 2, 50, 2.5, 0, 0, 0, 0, 1, 1, 0, 0, 4, 0);
+INSERT INTO `0_debtor_trans` VALUES(18, 10, 1, 3, 3, '2009-06-21', '2009-07-01', '2', 2, 3, 35.89, 1.79, 0, 0, 0, 37.68, 1.3932, 1, 2, 0, 3, 0);
+INSERT INTO `0_debtor_trans` VALUES(19, 10, 0, 2, 2, '2009-06-21', '2009-06-22', '3', 1, 5, 50, 0, 5, 0, 0, 0, 1, 1, 0, 0, 4, 0);
+INSERT INTO `0_debtor_trans` VALUES(3, 11, 0, 3, 3, '2009-06-21', '0000-00-00', '1', 2, 3, 35.89, 1.79, 0, 0, 0, 37.68, 1.3932, 1, 2, 0, 3, 0);
+INSERT INTO `0_debtor_trans` VALUES(2, 13, 0, 1, 1, '2009-06-21', '2009-06-22', '1', 2, 1, 60.8, 0, 10, 0, 0, 0, 1.6445729799917, 1, 0, 0, 3, 0);
+INSERT INTO `0_debtor_trans` VALUES(3, 13, 1, 2, 2, '2009-06-21', '2009-06-22', 'auto', 1, 2, 50, 2.5, 0, 0, 0, 0, 1, 1, 0, 0, 4, 0);
+INSERT INTO `0_debtor_trans` VALUES(4, 13, 1, 3, 3, '2009-06-21', '2009-07-01', 'auto', 2, 3, 35.89, 1.79, 0, 0, 0, 0, 1.3932, 1, 2, 0, 3, 0);
+INSERT INTO `0_debtor_trans` VALUES(5, 13, 1, 2, 2, '2009-06-21', '2009-06-22', 'auto', 1, 5, 50, 0, 5, 0, 0, 0, 1, 1, 0, 0, 4, 0);
 
 -- --------------------------------------------------------
 
index cd0bc1fc698a112f2b69c2a6453c0a37a87a52e4..baad176f17338d5fa8c852cd12d7a264440e4300 100644 (file)
@@ -652,6 +652,7 @@ CREATE TABLE IF NOT EXISTS `0_debtor_trans` (
   `dimension_id` int(11) NOT NULL default '0',
   `dimension2_id` int(11) NOT NULL default '0',
   `payment_terms` int(11) default NULL,
+  `tax_included` tinyint(1) unsigned NOT NULL default '0',
   PRIMARY KEY  (`type`,`trans_no`),
   KEY `debtor_no` (`debtor_no`,`branch_code`),
   KEY `tran_date` (`tran_date`)