Improved quick entries.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 22 Jan 2009 16:34:45 +0000 (16:34 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Thu, 22 Jan 2009 16:34:45 +0000 (16:34 +0000)
15 files changed:
gl/gl_bank.php
gl/gl_journal.php
gl/includes/ui/gl_bank_ui.inc
gl/includes/ui/gl_journal_ui.inc
gl/manage/gl_quick_entries.php
includes/types.inc
includes/ui/items_cart.inc
includes/ui/ui_lists.inc
includes/ui/ui_view.inc
purchasing/includes/ui/invoice_ui.inc
purchasing/supplier_credit.php
purchasing/supplier_invoice.php
sql/alter2.1.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index c40def6c8f52f5a6cc3c23c19e3024f236ac9b5d..e5900142851880d566ade96b24114db10afc2480 100644 (file)
@@ -105,7 +105,6 @@ function handle_new_order($type)
 {
        if (isset($_SESSION['pay_items']))
        {
-               $_SESSION['pay_items']->clear_items();
                unset ($_SESSION['pay_items']);
        }
 
@@ -262,7 +261,8 @@ if (isset($_POST['CancelItemChanges']))
 if (isset($_POST['go']))
 {
        display_quick_entries($_SESSION['pay_items'], $_POST['person_id'], input_num('totamount'), 
-               $_SESSION['pay_items']->trans_type==systypes::bank_payment());
+               $_SESSION['pay_items']->trans_type==systypes::bank_payment() ? QE_PAYMENT : QE_DEPOSIT);
+       $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
        line_start_focus();
 }
 //-----------------------------------------------------------------------------------------------
index 44b16f8558780e320270b29f226a460b14029d56..81f6332c1f668b71b200c032265f4467221bc053 100644 (file)
@@ -239,7 +239,8 @@ if (isset($_POST['CancelItemChanges']))
 
 if (isset($_POST['go']))
 {
-       display_quick_entries($_SESSION['journal_items'], $_POST['person_id'], input_num('totamount'));
+       display_quick_entries($_SESSION['journal_items'], $_POST['person_id'], input_num('totamount'), QE_JOURNAL);
+       $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
        line_start_focus();
 }      
 //-----------------------------------------------------------------------------------------------
index 5f95c3dfa63dd10b6de3c74393905d4c17f69b0c..5239dc9a906586c6a2836546fac1a40f793f9a7d 100644 (file)
@@ -72,9 +72,16 @@ function display_bank_header(&$order)
                        hidden('PersonDetailID');
                }
                break;
+
                case payment_person_types::QuickEntry() :
-                       quick_entries_list_row(_("Description:"), 'person_id', null, ($payment ? 0 : 1), 1);
-                       amount_row(_("Total Amount"), 'totamount', null, null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));                       
+                       quick_entries_list_row(_("Type").":", 'person_id', null, ($payment ? QE_PAYMENT : QE_DEPOSIT), true);
+                       $qid = get_quick_entry(get_post('person_id'));
+                       if (list_updated('person_id')) {
+                               unset($_POST['totamount']); // enable default
+                               $Ajax->activate('totamount');
+                       }
+                       amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
+                                null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));
                        break;  
                //case payment_person_types::Project() :
        //      dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true);
index bae82d3b511805b73fc5f6f16cc03f51ed443ffb..1a2a9b4ee06193b26f30bc8e32df18f4bb1632c8 100644 (file)
@@ -18,7 +18,7 @@ function display_order_header(&$Order)
 {
        global $table_style2;
 
-       $qes = has_quick_entries(-1, 0);
+       $qes = has_quick_entries(QE_JOURNAL);
 
        start_outer_table("$table_style2 width=90%");
        table_section(1);
@@ -40,9 +40,16 @@ function display_order_header(&$Order)
        {
                table_section(3, "50%");
                start_row();
-               quick_entries_list_cells(_("Quick Entry:"), 'person_id', null, -1, 0);
-               amount_cells(_("Total Amount"), 'totamount', null, null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));                     
+               quick_entries_list_cells(_("Quick Entry").":", 'person_id', null, QE_JOURNAL, true);
+               $qid = get_quick_entry(get_post('person_id'));
+               if (list_updated('person_id')) {
+                       unset($_POST['totamount']); // enable default
+               $Ajax->activate('totamount');
+               }
+               amount_cells($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
+                null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));
                end_row();
+
        }
                
        end_outer_table(1);
index c042c213aa6aa5cfefe568105f04efd721f3582b..e797cc8cd9c9307c4b3324ca6bddaa54090b43f3 100644 (file)
@@ -74,6 +74,12 @@ function can_process()
                set_focus('description');
                return false;
        }
+       if (strlen($_POST['base_desc']) == 0) 
+       {
+               display_error( _("The base amount description cannot be empty."));
+               set_focus('base_desc');
+               return false;
+       }
 
        return true;
 }
@@ -88,12 +94,14 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
 
                if ($selected_id != -1) 
                {
-                       update_quick_entry($selected_id, $_POST['description'], $_POST['deposit'], $_POST['bank_only']);
+                       update_quick_entry($selected_id, $_POST['description'], $_POST['type'],
+                                input_num('base_amount'), $_POST['base_desc']);
                        display_notification(_('Selected quick entry has been updated'));
                } 
                else 
                {
-                       add_quick_entry($_POST['description'], $_POST['deposit'], $_POST['bank_only']);
+                       add_quick_entry($_POST['description'], $_POST['type'], 
+                               input_num('base_amount'), $_POST['base_desc']);
                        display_notification(_('New quick entry has been added'));
                }
                $Mode = 'RESET';
@@ -104,13 +112,13 @@ if ($Mode2=='ADD_ITEM2' || $Mode2=='UPDATE_ITEM2')
 {
        if ($selected_id2 != -1) 
        {
-               update_quick_entry_line($selected_id2, $selected_id, $_POST['account'], $_POST['tax_acc'], $_POST['pct'], input_num('amount', 0), 
+               update_quick_entry_line($selected_id2, $selected_id, $_POST['actn'], $_POST['dest_id'], input_num('amount', 0), 
                        $_POST['dimension_id'], $_POST['dimension2_id']);
                display_notification(_('Selected quick entry line has been updated'));
        } 
        else 
        {
-               add_quick_entry_line($selected_id, $_POST['account'], $_POST['tax_acc'], $_POST['pct'], input_num('amount', 0), 
+               add_quick_entry_line($selected_id, $_POST['actn'], $_POST['dest_id'], input_num('amount', 0), 
                        $_POST['dimension_id'], $_POST['dimension2_id']);
                display_notification(_('New quick entry line has been added'));
        }
@@ -144,36 +152,37 @@ if ($Mode2 == 'BDel')
 if ($Mode == 'RESET')
 {
        $selected_id = -1;
-       $_POST['description'] = $_POST['deposit'] = $_POST['bank_only'] = '';
+       $_POST['description'] = $_POST['type'] = '';
+       $_POST['base_desc']= _('Base Amount');
+       $_POST['base_amount'] = price_format(0);
 }
 if ($Mode2 == 'RESET2')
 {
        $selected_id2 = -1;
-       $_POST['account'] = $_POST['tax_acc'] = $_POST['pct'] = $_POST['amount'] = $_POST['dimension_id'] = $_POST['dimension2_id'] = '';
+       $_POST['actn'] = $_POST['dest_id'] = $_POST['amount'] = 
+               $_POST['dimension_id'] = $_POST['dimension2_id'] = '';
 }
 //-----------------------------------------------------------------------------------
 
 $result = get_quick_entries();
 start_form();
 start_table($table_style);
-$th = array(_("Description"), _("Deposit"), _("Bank Only"), "", "");
+$th = array(_("Description"), _("Type"), "", "");
 table_header($th);
 
 $k = 0;
 while ($myrow = db_fetch($result)) 
 {
        alt_table_row_color($k);
-       $deposit_text = ($myrow["deposit"] == 0 ? _("No") : _("Yes"));
-       $bank_text = ($myrow["bank_only"] == 0 ? _("No") : _("Yes"));
+       $type_text = $quick_entry_types[$myrow["type"]];
        label_cell($myrow['description']);
-       label_cell($deposit_text);
-       label_cell($bank_text);
+       label_cell($type_text);
        edit_button_cell("Edit".$myrow["id"], _("Edit"));
        delete_button_cell("Delete".$myrow["id"], _("Delete"));
        end_row();
 }
 
-end_table();
+end_table(1);
 end_form();
 //-----------------------------------------------------------------------------------
 
@@ -190,17 +199,20 @@ if ($selected_id != -1)
 
                $_POST['id']  = $myrow["id"];
                $_POST['description']  = $myrow["description"];
-               $_POST['deposit']  = $myrow["deposit"];
-               $_POST['bank_only']  = $myrow["bank_only"];
+               $_POST['deposit']  = $myrow["type"];
+               $_POST['base_desc']  = $myrow["base_desc"];
+               $_POST['base_amount']  = price_format($myrow["base_amount"]);
                hidden('selected_id', $selected_id);
        //}
 } 
 
-text_row_ex(_("Description:"), 'description', 50, 60);
+text_row_ex(_("Description").':', 'description', 50, 60);
+
+quick_entry_types_list_row(_("Entry Type").':', 'type');
 
-yesno_list_row(_("Deposit:"), 'deposit', null, "", "", false);
+text_row_ex(_("Base Amount Description").':', 'base_desc', 50, 60, '',_('Base Amount'));
 
-yesno_list_row(_("Bank Only:"), 'bank_only', null, "", "", false);
+amount_row(_("Default Base Amount").':', 'base_amount', price_format(0));
 
 end_table(1);
 
@@ -208,6 +220,7 @@ submit_add_or_update_center($selected_id == -1, '', true);
 
 end_form();
 
+
 if ($selected_id != -1)
 {
        display_heading(_("Quick Entry Lines") . " - " . $_POST['description']);
@@ -216,22 +229,34 @@ if ($selected_id != -1)
        start_table($table_style2);
        $dim = get_company_pref('use_dimension');
        if ($dim == 2)
-               $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
+               $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
        else if ($dim == 1)     
-               $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), "", "");
+               $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), "", "");
        else    
-               $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), "", "");
+               $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), "", "");
+
        table_header($th);
        $k = 0;
        while ($myrow = db_fetch($result)) 
        {
                alt_table_row_color($k);
-               label_cell($myrow['account']." ".$myrow['account_name']);
-               $tax_text = ($myrow['tax_acc'] == 0 ? _("No") : _("Yes"));
-               label_cell($tax_text);
-               $pct_text = ($myrow['pct'] == 0 ? _("No") : _("Yes"));
-               label_cell($pct_text);
-               amount_cell($myrow['amount']);
+               
+               label_cell($quick_actions[$myrow['action']]);
+
+               $act_type = strtolower(substr($myrow['action'], 0, 1));
+
+               if ($act_type == 't') {
+                       label_cells($myrow['tax_name'], '');
+               } else {
+                       label_cell($myrow['dest_id'].' '.$myrow['account_name']);
+                       if ($act_type == '=') 
+                               label_cell('');
+                       else
+                       if ($act_type == '%') 
+                               percent_cell($myrow['amount']);
+                       else
+                               amount_cell($myrow['amount']);
+               }               
                if ($dim >= 1)
                        label_cell(get_dimension_string($myrow['dimension_id'], true));
                if ($dim > 1)
@@ -240,15 +265,15 @@ if ($selected_id != -1)
                delete_button_cell("BDel".$myrow["id"], _("Delete"));
                end_row();
        }
-       end_table();
+       end_table(1);
        hidden('selected_id', $selected_id);
        hidden('selected_id2', $selected_id2);
        hidden('description', $_POST['description']);
-       hidden('deposit', $_POST['deposit']);
-       hidden('bank_only', $_POST['bank_only']);
+       hidden('type', $_POST['type']);
        end_form();
        start_form();
 
+       div_start('edit_line');
        start_table($table_style2);
 
        if ($selected_id2 != -1) 
@@ -259,34 +284,47 @@ if ($selected_id != -1)
                        $myrow = get_quick_entry_line($selected_id2);
 
                        $_POST['id']  = $myrow["id"];
-                       $_POST['account']  = $myrow["account"];
-                       $_POST['tax_acc']  = $myrow["tax_acc"];
-                       $_POST['pct']  = $myrow["pct"];
+                       $_POST['dest_id']  = $myrow["dest_id"];
+                       $_POST['actn']  = $myrow["action"];
                        $_POST['amount']  = $myrow["amount"];
                        $_POST['dimension_id']  = $myrow["dimension_id"];
                        $_POST['dimension2_id']  = $myrow["dimension2_id"];
                }
        } 
 
-       gl_all_accounts_list_row(_("Account"), 'account', null);
-       yesno_list_row(_("Use Tax:"), 'tax_acc', null, "", "", false);
-       yesno_list_row(_("Use Percent:"), 'pct', null, "", "", false);
-       amount_row(_("Amount"), 'amount', null);
+       quick_actions_list_row(_("Posted").":",'actn', null, true);
+       if (list_updated('actn'))
+               $Ajax->activate('edit_line');
+
+       $actn = strtolower(substr($_POST['actn'],0,1));
+
+       if ($actn == 't') {
+               item_tax_types_list_row(_("Item Tax Type").":",'dest_id', null);
+       } else {
+               gl_all_accounts_list_row(_("Account").":", 'dest_id', null);
+               if ($actn != '=') {
+                       if ($actn = '%') 
+                               percent_row(_("Part").":", 'amount', percent_format(0));
+                       else
+                               amount_row(_("Amount").":", 'amount', price_format(0));
+               }
+       }
        if ($dim >= 1) 
-               dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 1);
+               dimensions_list_row(_("Dimension").":", 'dimension_id', null, true, " ", false, 1);
        if ($dim > 1) 
-               dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
+               dimensions_list_row(_("Dimension")." 2:", 'dimension2_id', null, true, " ", false, 2);
        
        end_table(1);
        if ($dim < 2)
                hidden('dimension2_id', 0);
        if ($dim < 1)
                hidden('dimension_id', 0);
+       div_end();
+
        hidden('selected_id', $selected_id);
        hidden('selected_id2', $selected_id2);
        hidden('description', $_POST['description']);
-       hidden('deposit', $_POST['deposit']);
-       hidden('bank_only', $_POST['bank_only']);
+       hidden('type', $_POST['type']);
 
        submit_add_or_update_center2($selected_id2 == -1, '', true);
 
index 9003ecebbdaf0e49fa008ee6cf0ff1588a52cc12..4cde8738ba5e99ae30b38f277c3d0d04643232e1 100644 (file)
@@ -300,5 +300,33 @@ class wo_types
        }
 }
 
+$quick_actions = array(
+       '=' => _('Remainder'), // post current base amount to GL account
+       '-' => _('Amount, reduce base'), // post amount to GL account and reduce base
+       '+' => _('Amount, increase base'), // post amount to GL account and increase base
+       '%' => _('% amount of base'),   // store acc*amount% to GL account
+       '%+' => _('% amount of base, increase base'),   // ditto & increase base amount
+       '%-' => _('% amount of base, reduce base'),     // ditto & reduce base amount
+       'T' => _('Taxes added'), // post taxes calculated on base amount
+       'T+' => _('Taxes added, increase base'), // ditto & increase base amount
+       'T-' => _('Taxes added, reduce base'), // ditto & reduce base amount
+       't' => _('Taxes included'), // post taxes calculated on base amount
+       't+' => _('Taxes included, increase base'), // ditto & increase base amount
+       't-' => _('Taxes included, reduce base') // ditto & reduce base amount
+);
+
+define('QE_DEPOSIT', '1');
+define('QE_PAYMENT', '2');
+define('QE_JOURNAL', '3');
+define('QE_SUPPINV', '4');
+
+$quick_entry_types = array(
+               QE_DEPOSIT => _("Bank Deposit"),
+               QE_PAYMENT => _("Bank Payment"),
+               QE_JOURNAL => _("Journal Entry"),
+               QE_SUPPINV => _("Supplier Invoice/Credit")
+);
+
+
 
 ?>
\ No newline at end of file
index a2d3e2d2e9a971494eee82baa76baa6d5de04872..66a17feac93570cd727849ff159a8d175cba3a25 100644 (file)
@@ -101,7 +101,7 @@ class items_cart
                else
                {
                        // shouldn't come here under normal circumstances
-                       display_db_error("unexpected - adding an invalid item or null quantity", "", true);
+                       display_db_error("unexpected - invalid parameters in add_gl_item($code_id, $dimension_id, $dimension2_id, $amount,...)", "", true);
                }
 
                return false;
index 52475c4eb5d4b0b952059f3f425a6fd51851b0ea..46194019b9bf99e37a40eb6bfda67f66b5dc910a 100644 (file)
@@ -1715,49 +1715,6 @@ function payment_person_types_list_row($label, $name, $selected_id=null, $relate
        return $str;
 }
 
-//------------------------------------------------------------------------------------------------
-
-function quick_entries_list($name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false)
-{
-       $where = false;
-       $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
-       if ($expense != -1)
-       {
-               $sql .= " WHERE deposit=$expense";
-               $where = true;
-       }       
-       if ($bank_only != -1)
-       {
-               if ($where)
-                       $sql .= " AND bank_only=$bank_only";
-               else    
-                       $sql .= " WHERE bank_only=$bank_only";
-       }
-       combo_input($name, $selected_id, $sql, 'id', 'description',
-               array(
-                       'spec_id' => '',
-                       'order' => 'description',
-                       'select_submit'=> $submit_on_change,
-                       'async' => false
-               ) );
-
-}
-
-function quick_entries_list_cells($label, $name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false)
-{
-       echo "<td>$label</td><td>\n";
-       quick_entries_list($name, $selected_id, $expense, $bank_only, $submit_on_change);
-       echo "</td>";
-}
-
-function quick_entries_list_row($label, $name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false)
-{
-       echo "<tr>\n";
-       quick_entries_list_cells($label, $name, $selected_id, $expense, $bank_only, $submit_on_change);
-       echo "</tr>\n";
-}
-
-
 //------------------------------------------------------------------------------------------------
 
 function wo_types_list($name, $selected_id=null)
@@ -2040,5 +1997,63 @@ function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_cha
                 ));
 }
 
+//------------------------------------------------------------------------------------------------
+
+function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false)
+{
+       $where = false;
+       $sql = "SELECT id, description FROM ".TB_PREF."quick_entries";
+       if ($type != null)
+               $sql .= " WHERE type=$type";
+
+       combo_input($name, $selected_id, $sql, 'id', 'description',
+               array(
+                       'spec_id' => '',
+                       'order' => 'description',
+                       'select_submit'=> $submit_on_change,
+                       'async' => false
+               ) );
+
+}
+
+function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false)
+{
+       echo "<td>$label</td><td>\n";
+       quick_entries_list($name, $selected_id, $type, $submit_on_change);
+       echo "</td>";
+}
+
+function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false)
+{
+       echo "<tr>\n";
+       quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change);
+       echo "</tr>\n";
+}
+
+
+function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+{
+       global $quick_actions;
+       
+       echo "<tr><td>$label</td><td>";
+       array_selector($name, $selected_id, $quick_actions, 
+               array( 
+                       'select_submit'=> $submit_on_change
+               ) );
+       echo "</td></tr>\n";
+}
+
+function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+{
+       global $quick_entry_types;
+               
+       echo "<tr><td>$label</td><td>";
+       array_selector($name, $selected_id, $quick_entry_types, 
+               array( 
+                       'select_submit'=> $submit_on_change
+                       ) );
+       echo "</td></tr>\n";
+}
+
 
 ?>
\ No newline at end of file
index cee877d5c8b64845b961eb49fdac091f5530f471..0de82dfed682fa1788392f0372626c8b31e4fb65 100644 (file)
@@ -548,8 +548,14 @@ function display_allocations_from($person_type, $person_id, $type, $type_no, $to
 }
 
 //--------------------------------------------------------------------------------------
-function display_quick_entries(&$cart, $id, $totamount, $payment=true, $supp_trans=false)
+//
+//     Expands selected quick entry $id into GL posings and adds to cart.
+//             returns calculated amount posted to bank GL account.
+//
+function display_quick_entries(&$cart, $id, $base, $type, $descr='')
 {
+       $bank_amount = 0;
+       
        if (!isset($id) || $id == null || $id == "")
        {
                display_error( _("No Quick Entries are defined."));
@@ -557,71 +563,80 @@ function display_quick_entries(&$cart, $id, $totamount, $payment=true, $supp_tra
        }
        else
        {
-               $rate = 0;
-               if (!$payment)
-                       $totamount = -$totamount;
-               if (!$supp_trans)       
+               if ($type == QE_DEPOSIT)
+                       $base = -$base;
+               if ($type != QE_SUPPINV)        // only one quick entry on journal/bank transaction
                        $cart->clear_items();
                $qe = get_quick_entry($id);
+               if ($descr != '') $qe['description'] .= ': '.$descr;
                $qe_lines = get_quick_entry_lines($id);
                while ($qe_line = db_fetch($qe_lines))
                {
-                       if ($qe_line['tax_acc'])
-                       {
-                               $account = get_gl_account($qe_line['account']);
-                               $tax_group = $account['tax_code'];
-                               $items = get_tax_group_items($tax_group);
-                               while ($item = db_fetch($items))
-                                       $rate += $item['rate'];
-                               if ($rate != 0)
-                                       $totamount = round2($totamount * 100 / ($rate + 100), user_price_dec());
-                               //$cart->clear_items();
-                               if (!$supp_trans)
-                                       $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
-                                               $totamount, $qe['description']);
-                               else
-                               {
-                                       $acc_name = get_gl_account_name($qe_line['account']);
-                                       $cart->add_gl_codes_to_trans($qe_line['account'], $acc_name, $qe_line['dimension_id'], 
-                                               $qe_line['dimension2_id'], $totamount, $qe['description']);
-                               }               
-                               $items = get_tax_group_items($tax_group);
-                               while ($item = db_fetch($items))
-                               {
-                                       if ($item['rate'] != 0)
-                                       {
-                                               $amount = round2($totamount * $item['rate'] / 100, user_price_dec());
-                                               $code = (($amount < 0 || $payment || $supp_trans) ? $item['purchasing_gl_code'] : 
-                                                       $item['sales_gl_code']);
-                                               if (!$supp_trans)       
-                                                       $cart->add_gl_item($code, 0, 0, $amount, $qe['description']);
+                       switch (strtolower($qe_line['action'])) {
+                               case "=": // post current base amount to GL account
+                                       $part = $base;
+                                       break;
+                               case "-": // post amount to GL account and reduce base
+                                       $part = $qe_line['amount']; $base -= $part;
+                                       break;
+                               case "+": // post amount to GL account and increase 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']);
+                                       $tax_total = 0;
+                                       foreach ($taxes as $index => $item_tax) {
+                                               if(substr($qe_line['action'],0,1) != 'T')
+                                                       $tax = round($base * $item_tax['rate'] 
+                                                               / ($item_tax['rate'] + 100),  user_price_dec());
                                                else
-                                               {
-                                                       $acc_name = get_gl_account_name($code);
-                                                       $cart->add_gl_codes_to_trans($code, $acc_name, 0, 0, $amount, $qe['description']);
+                                                       $tax = round($base * $item_tax['rate'] / 100,  user_price_dec());
+
+                                               $gl_code = $type != QE_DEPOSIT 
+                                                       ? $item_tax['purchasing_gl_code'] : $item_tax['sales_gl_code'];
+                                               $tax_total += $tax;
+                                               if ($type != QE_SUPPINV)
+                                                       $cart->add_gl_item($gl_code, 
+                                                               $qe_line['dimension_id'], $qe_line['dimension2_id'], 
+                                                               $tax, $qe['description']);
+                                               else {
+                                                       $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_total;
+                                       elseif (strpos($qe_line['action'], '-'))
+                                               $base -= $tax_total;
+                                       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']);
                        }
-                       else
-                       {
-                               if ($qe_line['pct'])
-                                       $amount = round2($totamount * $qe_line['amount'] / 100, user_price_dec());
-                               else
-                                       $amount = $qe_line['amount'];
-                               if (!$supp_trans)       
-                                       $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
-                                               $amount, $qe['description']);
-                               else
-                               {
-                                       $acc_name = get_gl_account_name($qe_line['account']);
-                                       $cart->add_gl_codes_to_trans($qe_line['account'], $acc_name, $qe_line['dimension_id'], 
-                                               $qe_line['dimension2_id'], $amount, $qe['description']);
-                               }
-                       }               
                }
-               //line_start_focus();
        }       
+       return $bank_amount;
 }
 
 
index 116dee3c4df33a092ba6a97b64a48227fc339a4d..2e2d17cc6d5d48fca0b3cd3ad769c00de8d80920 100644 (file)
@@ -195,7 +195,7 @@ function display_gl_controls(&$supp_trans, $k)
 
 function display_gl_items(&$supp_trans, $mode=0)
 {
-       global $table_style, $path_to_root;
+       global $table_style, $path_to_root, $Ajax;
 
     // if displaying in form, and no items, exit
     if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0)
@@ -212,18 +212,25 @@ function display_gl_items(&$supp_trans, $mode=0)
 
        if ($mode == 1)
        {
-               $qes = has_quick_entries(-1, 0);
+               $qes = has_quick_entries(QE_SUPPINV);
                if ($qes !== false)
                {
                        echo "<div style='float:right;'>";
                        echo _("Quick Entry:")."&nbsp;"; 
-                       quick_entries_list('qid', null, 0, 1);
-                       echo "&nbsp;"._("Amount")."&nbsp;";
-                       $amount = input_num('totamount');
+                       quick_entries_list('qid', null, QE_SUPPINV, true);
+                       $qid = get_quick_entry(get_post('qid'));
+                       if (list_updated('qid')) {
+                               unset($_POST['totamount']); // enable default
+                               $Ajax->activate('totamount');
+                       }
+                       echo "&nbsp;".$qid['base_desc'].":"."&nbsp;";
+
+                       $amount = input_num('totamount', $qid['base_amount']);
                        $dec = user_price_dec();
                        echo "<input class='amount' type='text' name='totamount' size='7' maxlength='12' dec='$dec' value='$amount'>&nbsp;";
                        submit('go', _("Go"), true, false, true);
                        echo "</div>";
+
                }       
        }
        display_heading($heading);
index 00a8cd5eaac2e321083c103440dea82a72de4021..45f7a6caedaa10c3f51a7a07d1d28b6e77b3d245 100644 (file)
@@ -311,7 +311,8 @@ if (isset($_POST['RefreshInquiry']))
 if (isset($_POST['go']))
 {
        $Ajax->activate('gl_items');
-       display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), true, true);
+       display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), QE_SUPPINV);
+       $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
        $Ajax->activate('inv_tot');
 }
 
index 6dcd5cbaae1ba6f0f23758b5c8132b733269ea0b..52ce2f7b03e9c557adf0c48adb587a13c87a2c8b 100644 (file)
@@ -379,7 +379,8 @@ if ($_SESSION["wa_current_user"]->access == 2)
 if (isset($_POST['go']))
 {
        $Ajax->activate('gl_items');
-       display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), true, true);
+       display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), QE_SUPPINV);
+       $_POST['totamount'] = price_format(0); $Ajax->activate('totamount');
        $Ajax->activate('inv_tot');
 }
 
index fcb785c35a39289316cc385e733b2320438796fc..8e5b45f1fb03a181f2ce09b6f5e8ed267a543cee 100644 (file)
@@ -104,35 +104,35 @@ DROP TABLE IF EXISTS `0_quick_entries`;
 
 CREATE TABLE `0_quick_entries` (
   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
+  `type` tinyint(1) NOT NULL default '0',
   `description` varchar(60) NOT NULL,
-  `deposit` tinyint(1) NOT NULL default '0',
-  `bank_only` tinyint(1) NOT NULL default '0',
+  `base_amount` double NOT NULL default '0',
+  `base_desc` varchar(60) NULL,
   PRIMARY KEY  (`id`),
   KEY `description` (`description`)
 ) TYPE=MyISAM AUTO_INCREMENT=1;
 
-INSERT INTO `0_quick_entries` VALUES ('1', 'Maintenance', '0', '1');
-INSERT INTO `0_quick_entries` VALUES ('2', 'Phone', '0', '1');
-INSERT INTO `0_quick_entries` VALUES ('3', 'Cash Sales', '1', '1');
+INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount');
+INSERT INTO `0_quick_entries` VALUES ('2', '1', 'Phone', '0', 'Amount');
+INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount');
 
 DROP TABLE IF EXISTS `0_quick_entry_lines`;
 
 CREATE TABLE `0_quick_entry_lines` (
   `id` smallint(6) UNSIGNED NOT NULL auto_increment,
   `qid` smallint(6) UNSIGNED NOT NULL,
-  `account` varchar(11) NOT NULL,
-  `tax_acc` tinyint(1) NOT NULL default '0',
-  `pct` tinyint(1) NOT NULL default '0',
   `amount` double default NULL default '0',
+  `action` varchar(2) NOT NULL,
+  `dest_id` varchar(11) NOT NULL,
   `dimension_id` smallint(6) UNSIGNED NULL default NULL,
   `dimension2_id` smallint(6) UNSIGNED NULL default NULL,
   PRIMARY KEY  (`id`),
   KEY `qid` (`qid`)
 ) TYPE=MyISAM AUTO_INCREMENT=1;
 
-INSERT INTO `0_quick_entry_lines` VALUES ('1', '1', '6600', '1', '0', 0, '0', '0');
-INSERT INTO `0_quick_entry_lines` VALUES ('2', '2', '6730', '1', '0', 0, '0', '0');
-INSERT INTO `0_quick_entry_lines` VALUES ('3', '3', '3000', '1', '0', 0, '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('1', '1','0','=', '6600', '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('2', '2','0','=', '6730', '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('3', '3','0','=', '3000', '0', '0');
 
 ALTER TABLE `0_users` DROP COLUMN `print_profile`;
 ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) NOT NULL DEFAULT '1';
index f2f89ab8b32efff1bdc6e3830dd3a8035e66d26e..b13b4d136817768dbe6da3d762359293c08b3ec7 100644 (file)
@@ -1472,51 +1472,47 @@ INSERT INTO `0_purch_orders` VALUES ('12', '0', '4', '', '2008-03-25', '13', '',
 INSERT INTO `0_purch_orders` VALUES ('13', '0', '4', '', '2008-03-25', '14', '', 'DEF', 'N/A');
 INSERT INTO `0_purch_orders` VALUES ('14', '0', '1', '', '2009-01-10', '15', '', 'CWA', 'address');
 
-
 ### Structure of table `0_quick_entries` ###
 
 DROP TABLE IF EXISTS `0_quick_entries`;
 
 CREATE TABLE `0_quick_entries` (
-  `id` smallint(6) unsigned NOT NULL auto_increment,
+  `id` smallint(6) UNSIGNED NOT NULL auto_increment,
+  `type` tinyint(1) NOT NULL default '0',
   `description` varchar(60) NOT NULL,
-  `deposit` tinyint(1) NOT NULL default '0',
-  `bank_only` tinyint(1) NOT NULL default '0',
+  `base_amount` double NOT NULL default '0',
+  `base_desc` varchar(60) NULL,
   PRIMARY KEY  (`id`),
   KEY `description` (`description`)
-) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
-
+) TYPE=MyISAM AUTO_INCREMENT=1;
 
 ### Data of table `0_quick_entries` ###
 
-INSERT INTO `0_quick_entries` VALUES ('1', 'Maintenance', '0', '1');
-INSERT INTO `0_quick_entries` VALUES ('2', 'Phone', '0', '1');
-INSERT INTO `0_quick_entries` VALUES ('3', 'Cash Sales', '1', '1');
-
+INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount');
+INSERT INTO `0_quick_entries` VALUES ('2', '1', 'Phone', '0', 'Amount');
+INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount');
 
 ### Structure of table `0_quick_entry_lines` ###
 
 DROP TABLE IF EXISTS `0_quick_entry_lines`;
 
 CREATE TABLE `0_quick_entry_lines` (
-  `id` smallint(6) unsigned NOT NULL auto_increment,
-  `qid` smallint(6) unsigned NOT NULL,
-  `account` varchar(11) NOT NULL,
-  `tax_acc` tinyint(1) NOT NULL default '0',
-  `pct` tinyint(1) NOT NULL default '0',
-  `amount` double default '0',
-  `dimension_id` smallint(6) unsigned default NULL,
-  `dimension2_id` smallint(6) unsigned default NULL,
+  `id` smallint(6) UNSIGNED NOT NULL auto_increment,
+  `qid` smallint(6) UNSIGNED NOT NULL,
+  `amount` double default NULL default '0',
+  `action` varchar(2) NOT NULL,
+  `dest_id` varchar(11) NOT NULL,
+  `dimension_id` smallint(6) UNSIGNED NULL default NULL,
+  `dimension2_id` smallint(6) UNSIGNED NULL default NULL,
   PRIMARY KEY  (`id`),
   KEY `qid` (`qid`)
-) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
-
+) TYPE=MyISAM AUTO_INCREMENT=1;
 
 ### Data of table `0_quick_entry_lines` ###
 
-INSERT INTO `0_quick_entry_lines` VALUES ('1', '1', '6600', '1', '0', '0', '0', '0');
-INSERT INTO `0_quick_entry_lines` VALUES ('2', '2', '6730', '1', '0', '0', '0', '0');
-INSERT INTO `0_quick_entry_lines` VALUES ('3', '3', '3000', '1', '0', '0', '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('1', '1','0','=', '6600', '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('2', '2','0','=', '6730', '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('3', '3','0','=', '3000', '0', '0');
 
 
 ### Structure of table `0_recurrent_invoices` ###
index 91905a1e2dd0e8de1f6e74e12eb0d931b71dffb2..68facba4d3ec7fa2e82654b6a0ec0412759901d6 100644 (file)
@@ -973,54 +973,40 @@ CREATE TABLE `0_purch_orders` (
 
 ### Data of table `0_purch_orders` ###
 
-
-
 ### Structure of table `0_quick_entries` ###
 
 DROP TABLE IF EXISTS `0_quick_entries`;
 
 CREATE TABLE `0_quick_entries` (
-  `id` smallint(6) unsigned NOT NULL auto_increment,
+  `id` smallint(6) UNSIGNED NOT NULL auto_increment,
+  `type` tinyint(1) NOT NULL default '0',
   `description` varchar(60) NOT NULL,
-  `deposit` tinyint(1) NOT NULL default '0',
-  `bank_only` tinyint(1) NOT NULL default '0',
+  `base_amount` double NOT NULL default '0',
+  `base_desc` varchar(60) NULL,
   PRIMARY KEY  (`id`),
   KEY `description` (`description`)
-) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
-
+) TYPE=MyISAM AUTO_INCREMENT=1;
 
 ### Data of table `0_quick_entries` ###
 
-INSERT INTO `0_quick_entries` VALUES ('1', 'Maintenance', '0', '1');
-INSERT INTO `0_quick_entries` VALUES ('2', 'Phone', '0', '1');
-INSERT INTO `0_quick_entries` VALUES ('3', 'Cash Sales', '1', '1');
-
-
 ### Structure of table `0_quick_entry_lines` ###
 
 DROP TABLE IF EXISTS `0_quick_entry_lines`;
 
 CREATE TABLE `0_quick_entry_lines` (
-  `id` smallint(6) unsigned NOT NULL auto_increment,
-  `qid` smallint(6) unsigned NOT NULL,
-  `account` varchar(11) NOT NULL,
-  `tax_acc` tinyint(1) NOT NULL default '0',
-  `pct` tinyint(1) NOT NULL default '0',
-  `amount` double default '0',
-  `dimension_id` smallint(6) unsigned default NULL,
-  `dimension2_id` smallint(6) unsigned default NULL,
+  `id` smallint(6) UNSIGNED NOT NULL auto_increment,
+  `qid` smallint(6) UNSIGNED NOT NULL,
+  `amount` double default NULL default '0',
+  `action` varchar(2) NOT NULL,
+  `dest_id` varchar(11) NOT NULL,
+  `dimension_id` smallint(6) UNSIGNED NULL default NULL,
+  `dimension2_id` smallint(6) UNSIGNED NULL default NULL,
   PRIMARY KEY  (`id`),
   KEY `qid` (`qid`)
-) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
-
+) TYPE=MyISAM AUTO_INCREMENT=1;
 
 ### Data of table `0_quick_entry_lines` ###
 
-INSERT INTO `0_quick_entry_lines` VALUES ('1', '1', '6600', '1', '0', '0', '0', '0');
-INSERT INTO `0_quick_entry_lines` VALUES ('2', '2', '6730', '1', '0', '0', '0', '0');
-INSERT INTO `0_quick_entry_lines` VALUES ('3', '3', '3000', '1', '0', '0', '0', '0');
-
-
 ### Structure of table `0_recurrent_invoices` ###
 
 DROP TABLE IF EXISTS `0_recurrent_invoices`;