Rolling back to single tax type based QE
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 20 Aug 2009 21:15:29 +0000 (21:15 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 20 Aug 2009 21:15:29 +0000 (21:15 +0000)
CHANGELOG.txt
doc/quick_entries.txt
gl/manage/gl_quick_entries.php
includes/ui/ui_view.inc
update.html

index ed110b3566fa7f71c1f8ee9007dd28181b93fe15..182dff71cfe721224e7a99af58d2dcf4525de3ba 100644 (file)
@@ -24,9 +24,6 @@ $ -> Affected files
 $ /gl/includes/gl_db_accounts.inc
 # If setting the delivered items in PO Receive Items to 0 the value is not updated 
 $ /purchasing/po_receive_items.php
-! Changed so you can choose all the tax types in Quick Entries you want in a single row.
-$ /gl/manage/gl_quick_entries.php
-  /includes/ui/ui_view.inc
 
 19-Aug-2009 Joe Hunt
 ! Change of Quick Entries to use the Tax Types instead, due to complexity using the Tax Groups in EU.
index 64a56d5203fb9bc92d5d2a286310755948c4dd5f..90db1293cce73404548ec88bc2b9946ff78d0694 100644 (file)
@@ -20,8 +20,8 @@ Currently following type of operations are defined:
 
 a) Post constant amount to selected GL account.
 b) Post percent part of base amount to selected GL account
-c) Post taxes for selected tax types, using base amount as net value.
-d) Post taxes for selected tax types, using base amount as value with tax included.
+c) Post taxes for selected tax type, using base amount as net value.
+d) Post taxes for selected tax type, using base amount as value with tax included.
 e) Post remainder from previous calculations to selected GL acount.
 
 After most operations the base amount can be increased, decreased or not changed 
@@ -33,7 +33,8 @@ bill, gazolin or other kind of simple bills. Later on you can create
 more sophisticated entry lines.
 
 If tax should be includes in the base amount you can first select a line
-'Tax included, reduce base and select the correct tax types.
+'Tax included, reduce base and select the correct tax type.
+If more lines with other Tax Types are needed, group them together and use the same action. 
 And a line with 'Remainder' put on the account you want to put the rest on.
 That's it!
 
index 048bb76746fe8710d7175b3a9b984ff0ea90dc7e..ed19b7fe2f5b21e185a339c75a3a76146dd46160 100644 (file)
@@ -110,23 +110,6 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 
 if ($Mode2=='ADD_ITEM2' || $Mode2=='UPDATE_ITEM2') 
 {
-       if ($_POST['tax'] == 't')
-       {
-               $res = get_all_tax_types_simple();
-               $j = 1;
-               $i = 0;
-               while ($tt = db_fetch($res))
-               {
-                       if (check_value('dest_id'.$tt['id']))
-                       {
-                               $i |= $j;
-                               unset($_POST['dest_id'.$tt['id']]);
-                       }       
-                       $j <<= 1;
-               }
-               $_POST['dest_id'] = $i;
-               unset($_POST['tax']);
-       }
        if ($selected_id2 != -1) 
        {
                update_quick_entry_line($selected_id2, $selected_id, $_POST['actn'], $_POST['dest_id'], input_num('amount', 0), 
@@ -264,23 +247,7 @@ if ($selected_id != -1)
 
                if ($act_type == 't') 
                {
-                       //label_cells($myrow['tax_name'], '');
-                       $res = get_all_tax_types_simple();
-                       $i = 1;
-                       $str = "";
-                       $first = true;
-                       while ($tt = db_fetch($res))
-                       {
-                               if ($myrow['dest_id'] & $i)
-                               {
-                                       if (!$first)
-                                               $str .= ", ";
-                                       $str .= $tt['name'] . " " . $tt['rate'] . "%";
-                                       $first = false;
-                               }       
-                               $i <<= 1;
-                       }
-                       label_cells($str, '');
+                       label_cells($myrow['tax_name'], '');
                } 
                else 
                {
@@ -329,31 +296,14 @@ if ($selected_id != -1)
 
        quick_actions_list_row(_("Posted").":",'actn', null, true);
        if (list_updated('actn'))
-       {
                $Ajax->activate('edit_line');
-               if (strtolower(substr($_POST['actn'],0,1)) == 't')
-                       $_POST['dest_id'] = "";
-       }       
 
        $actn = strtolower(substr($_POST['actn'],0,1));
 
        if ($actn == 't') 
        {
-               $res = get_all_tax_types_simple();
-               $i = 1;
-               if ($_POST['dest_id'] == '')
-                       $_POST['dest_id'] = 1;
-               label_row(" ", "<b>" . _("Tax Types")."</b>");
-               while ($tt = db_fetch($res))
-               {
-                       $str = $tt['name'] . " " . $tt['rate'] . "% ";
-                       if ($_POST['dest_id'] & $i)
-                               $_POST['dest_id'.$tt['id']] = 1;
-                       check_row($str, 'dest_id'.$tt['id'], null);
-                       $i <<= 1;
-               }
-               //label_cell($str);
-               
+               //item_tax_types_list_row(_("Item Tax Type").":",'dest_id', null);
+               tax_types_list_row(_("Tax Type").":", 'dest_id', null);
        } 
        else 
        {
@@ -376,7 +326,6 @@ if ($selected_id != -1)
                hidden('dimension2_id', 0);
        if ($dim < 1)
                hidden('dimension_id', 0);
-       hidden('tax', $actn);
        div_end();
 
        hidden('selected_id', $selected_id);
index 2765c6c4a106ad4904439645dbe296ecaf97050d..4e50bbf6d79d944f4073832166c02240834d4ef0 100644 (file)
@@ -567,8 +567,22 @@ function display_quick_entries(&$cart, $id, $base, $type, $descr='')
                $qe = get_quick_entry($id);
                if ($descr != '') $qe['description'] .= ': '.$descr;
                $result = get_quick_entry_lines($id);
+               $totrate = 0;
+               while ($row = db_fetch($result))
+               {
+                       $qe_lines[] = $row;
 
-               while ($qe_line = db_fetch($result))
+                       switch (strtolower($row['action'])) {
+                               case "t": // post taxes calculated on base amount
+                               case "t+": // ditto & increase base amount
+                               case "t-": // ditto & reduce base amount
+                                       if (substr($qe_line['action'],0,1) != 'T') 
+                                               $totrate += get_tax_type_default_rate($row['dest_id']);
+                       }
+               }
+               $first = true;
+               $taxbase = 0;
+               foreach($qe_lines as $qe_line)
                {
                        switch (strtolower($qe_line['action'])) {
                                case "=": // post current base amount to GL account
@@ -597,30 +611,100 @@ function display_quick_entries(&$cart, $id, $base, $type, $descr='')
                                case "t": // post taxes calculated on base amount
                                case "t+": // ditto & increase base amount
                                case "t-": // ditto & reduce base amount
-                                       //$taxes = get_taxes_for_item_tax($qe_line['dest_id']);
-                                       $taxes = array();
-                                       if ($type == QE_SUPPINV)
+                                       if ($first)
+                                       {
+                                               $taxbase = $base/($totrate+100);
+                                               $first = false;
+                                       }
+
+                                       if (substr($qe_line['action'],0,1) != 'T') 
+                                               $part = $taxbase;
+                                       else
+                                               $part = $base;
+                                       $item_tax = get_tax_type($qe_line['dest_id']);
+                                       if ($type == QE_SUPPINV && substr($qe_line['action'],0,1) != 'T')
                                        {
+                                               $taxgroup = $cart->tax_group_id;
+                                               $rates = 0;
                                                $res = get_tax_group_items($cart->tax_group_id);
                                                while ($row = db_fetch($res))
-                                                       $taxes[] = array('rate'=>$row['rate'], 'sales_gl_code'=>$row['sales_gl_code'], 
-                                                               'purchasing_gl_code'=>$row['purchasing_gl_code']);
+                                                       $rates += $row['rate'];
+                                               if ($rates == 0)
+                                                       continue 2;
                                        }
-                                       else
+                                       $tax = round2($part * $item_tax['rate'],  user_price_dec());
+                                       if ($tax==0) continue 2;
+                                       $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0)) 
+                                               ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
+                                       if (!is_tax_gl_unique($gl_code)) {
+                                               display_error(_("Cannot post to GL account used by more than one tax type."));
+                                               break 2;
+                                       }
+                                       if ($type != QE_SUPPINV)
+                                               $cart->add_gl_item($gl_code, 
+                                                       $qe_line['dimension_id'], $qe_line['dimension2_id'], 
+                                                       $tax, $qe['description']);
+                                       else 
                                        {
-                                               $res = get_all_tax_types_simple();
-                                               $i = 1;
-                                               while ($tt = db_fetch($res))
-                                               {
-                                                       if ($qe_line['dest_id'] & $i)
-                                                       {
-                                                               $row2 = get_tax_type($tt['id']);
-                                                               $taxes[] = array('rate'=>$row2['rate'], 'sales_gl_code'=>$row2['sales_gl_code'], 
-                                                                       'purchasing_gl_code'=>$row2['purchasing_gl_code']);
-                                                       }       
-                                                       $i <<= 1;
-                                               }
-                                       }                                                               
+                                               $acc_name = get_gl_account_name($gl_code);
+                                               $cart->add_gl_codes_to_trans($gl_code, 
+                                                       $acc_name, $qe_line['dimension_id'], 
+                                                       $qe_line['dimension2_id'], $tax, $qe['description']);
+                                       }
+                                       if (strpos($qe_line['action'], '+'))
+                                               $base += $tax;
+                                       elseif (strpos($qe_line['action'], '-'))
+                                               $base -= $tax;
+                                       continue 2;
+                       }
+                       if ($type != QE_SUPPINV)
+                               $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
+                                       $qe_line['dimension2_id'], $part, $qe['description']);
+                       else 
+                       {
+                               $acc_name = get_gl_account_name($qe_line['dest_id']);
+                               $cart->add_gl_codes_to_trans($qe_line['dest_id'], 
+                                       $acc_name, $qe_line['dimension_id'], 
+                                       $qe_line['dimension2_id'], $part, $qe['description']);
+                       }
+               }
+/*             
+               while ($qe_line = db_fetch($qe_lines))
+               {
+                       switch (strtolower($qe_line['action'])) {
+                               case "=": // post current base amount to GL account
+                                       $part = $base;
+                                       break;
+                               case "a": // post amount to GL account and reduce base
+                                       $part = $qe_line['amount'];
+                                       break;
+                               case "a+": // post amount to GL account and increase base
+                                       $part = $qe_line['amount']; $base += $part;
+                                       break;
+                               case "a-": // post amount to GL account and reduce base
+                                       $part = $qe_line['amount']; $base -= $part;
+                                       break;
+                               case "%":       // store acc*amount% to GL account
+                                       $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
+                                       break;
+                               case "%+":      // ditto & increase base amount
+                                       $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
+                                       $base += $part;
+                                       break;
+                               case "%-":      // ditto & reduce base amount
+                                       $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
+                                       $base -= $part;
+                                       break;
+                               case "t": // post taxes calculated on base amount
+                               case "t+": // ditto & increase base amount
+                               case "t-": // ditto & reduce base amount
+                                       //$taxes = get_taxes_for_item_tax($qe_line['dest_id']);
+                                       if ($type == QE_SUPPINV)
+                                               $qe_line['dest_id'] = $cart->tax_group_id;
+                                       $taxes = array();
+                                       $res = get_tax_group_items($qe_line['dest_id']);
+                                       while ($row = db_fetch($res))
+                                               $taxes[] = $row;
                                        $tax_total = 0;
                                        $totrate = 0;
                                        // find total tax 
@@ -669,6 +753,7 @@ function display_quick_entries(&$cart, $id, $base, $type, $descr='')
                                        $qe_line['dimension2_id'], $part, $qe['description']);
                        }
                }
+*/             
        }       
        return $bank_amount;
 }
index 608dfe8f87d3dbe5c3f56180e00e4a892093ecd0..2d822faec7946e61d60798ce942fab3cd2b234ad 100644 (file)
@@ -57,7 +57,8 @@ upgrade ALL your companies.</strong></li><li style="font-weight: bold;">If somet
 updating from release 2.1.2 to 2.1.3, please go into Bank and General
 Ledger tab. Enter Account Classes. Change the Class Types to a proper
 value for all classes.</li><li style="font-weight: bold;">When updating from release 2.1.4 to 2.1.5, please go into Bank and General Ledger tab. Enter Quick Entries. <br />The&nbsp;Tax now uses Tax Types instead of Item Tax Types. The reason for changing this is for the complex rules inside the EU.<br />Change
-to correct Tax Types.&nbsp;.</li>
+to correct Tax Type. If you need more Tax Type lines in the same Quick
+Entry, please group them together and use the same action type.</li>
 </ul>
 
 <p style="font-weight: bold;">&nbsp;</p>