[0000194] Fixed tax records from journal entry (voiding problem)
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 30 Jan 2010 14:25:45 +0000 (14:25 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 30 Jan 2010 14:25:45 +0000 (14:25 +0000)
CHANGELOG.txt
gl/includes/db/gl_db_trans.inc
reporting/rep709.php

index 7cdf1f57cc8f20e61b0f240c45034e7e4fbe4a82..8b4d777b699e0d26ecddb30a1d4c7cbbe3e6504d 100644 (file)
@@ -19,8 +19,13 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+30-Jan-2010 Janusz Dobrowolski
+# [0000194] Fixed tax records from journal entry (voiding problem)
+$ /gl/includes/db/gl_db_trans.inc
+  /reporting/rep709.php
+
 25-Jan-2010 Joe Hunt
-# {0000195] Bug not deleting refs record when deleting Sales Order, Quotation
+# [0000195] Bug not deleting refs record when deleting Sales Order, Quotation
 # A couple of redirecting bugs
 $ /sales/sales_order_entry.php
   /sales/includes/db/sales_order_db.inc
index af06cedf7a4122aaad4554584c79bfb65f635c74..efb8b2f6cc3ab08fa849d89d15390447b48c7ab4 100644 (file)
@@ -279,8 +279,8 @@ function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate,
        if(!$tax_type) return;  // $gl_code is not tax account
        
        $tax = get_tax_type($tax_type);
-       //if ($gl_code == $tax['sales_gl_code']) 
-       //      $amount = -$amount;
+       if ($gl_code == $tax['sales_gl_code']) 
+               $amount = -$amount;
        // we have to restore net amount as we cannot know the base amount
        if ($tax['rate'] == 0) {
 //             display_warning(_("You should not post gl transactions  
@@ -349,14 +349,27 @@ function get_tax_summary($from, $to)
        $todate = date2sql($to);
 
        $sql = "SELECT 
+                               SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE
+                                       ." || trans_type=".ST_JOURNAL.",-1,1)*
+                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE 
+                                       ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
+                                       ." || trans_type=".ST_CUSTCREDIT.", net_amount*ex_rate,0)) net_output,
+
+                               SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE
+                                       ." || trans_type=".ST_JOURNAL.",-1,1)*
+                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
+                                       ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
+                                       ." || trans_type=".ST_CUSTCREDIT.", amount*ex_rate,0)) payable,
+
                                SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
-                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", net_amount*ex_rate,0)) net_output,
-                               SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
-                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", amount*ex_rate,0)) payable,
-                               SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
-                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", 0, net_amount*ex_rate)) net_input,
+                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
+                                       ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
+                                       ." || trans_type=".ST_CUSTCREDIT.", 0, net_amount*ex_rate)) net_input,
+
                                SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
-                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", 0, amount*ex_rate)) collectible,
+                               IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
+                                       ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
+                                       ." || trans_type=".ST_CUSTCREDIT.", 0, amount*ex_rate)) collectible,
                                taxrec.rate,
                                ttype.id,
                                ttype.name
@@ -411,7 +424,7 @@ function write_journal_entries(&$cart, $reverse, $use_transaction=true)
        }
                // store tax details if the gl account is a tax account
                add_gl_tax_details($journal_item->code_id, 
-                       ($journal_item->amount < 0.0 ? ST_BANKDEPOSIT : ST_BANKPAYMENT), $trans_id, -$journal_item->amount, 1, $date_, $memo_);
+                       ST_JOURNAL, $trans_id, $journal_item->amount, 1, $date_, $memo_);
        }
        
        if ($new) {
@@ -448,7 +461,7 @@ function write_journal_entries(&$cart, $reverse, $use_transaction=true)
                }
                        // store tax details if the gl account is a tax account
                        add_gl_tax_details($journal_item->code_id, 
-                               ($journal_item->amount < 0.0 ? ST_BANKDEPOSIT : ST_BANKPAYMENT), $trans_id, $journal_item->amount, 1, $reversingDate, $memo_);
+                               ST_JOURNAL, $trans_id, $journal_item->amount, 1, $reversingDate, $memo_);
        }
 
        add_comments($trans_type, $trans_id_reverse, $reversingDate, $memo_);
index 4baf0105841b9e4e4b91416a7c8446ab4258f03e..3fc4c6375673372cf19974563a047c1fb5625ee0 100644 (file)
@@ -143,7 +143,11 @@ function print_tax_report()
                                $rep->Header();
                        }
                }
-               if (in_array($trans['trans_type'], array(ST_BANKDEPOSIT,ST_SALESINVOICE,ST_CUSTCREDIT))) {
+               if ($trans['trans_type']==ST_JOURNAL && $trans['amount']<0) {
+                       $taxes[$trans['tax_type_id']]['taxout'] -= $trans['amount'];
+                       $taxes[$trans['tax_type_id']]['out'] -= $trans['net_amount'];
+               }
+               elseif (in_array($trans['trans_type'], array(ST_BANKDEPOSIT,ST_SALESINVOICE,ST_CUSTCREDIT))) {
                        $taxes[$trans['tax_type_id']]['taxout'] += $trans['amount'];
                        $taxes[$trans['tax_type_id']]['out'] += $trans['net_amount'];
                } else {