Added Quick Entries in GL Journal Entry and changed some needed fixes.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 15 Nov 2008 12:14:09 +0000 (12:14 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 15 Nov 2008 12:14:09 +0000 (12:14 +0000)
CHANGELOG.txt
gl/gl_bank.php
gl/gl_journal.php
gl/includes/db/gl_db_bank_accounts.inc
gl/includes/ui/gl_bank_ui.inc
gl/includes/ui/gl_journal_ui.inc
includes/ui/ui_lists.inc

index b1ac91c32c775727d8d24f81e9fb9eb0c565e63f..d8119744d6c547a42c412c02617de024659e3934 100644 (file)
@@ -19,6 +19,15 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+15-Nov-2008 Joe Hunt
++ Added Quick Entries in GL Journal Entry and changed some needed fixes.
+$ /gl/gl_bank.php
+  /gl/gl_journal.php
+  /gl/includes/db/gl_db_bank_accounts.inc
+  /gl/includes/ui/gl_bank_ui.inc
+  /gl/includes/ui/gl_journal_ui.inc
+  /includes/ui/ui_lists.inc
+  
 15-Nov-2008 Joe Hunt
 + Added Tax Inquiry in Banking and General Ledger tab.
 $ /applications/generalledger.php
index b3f1c1b7766f0f5871371ecf47d4f817346734a7..0df087b2a2baf5e102fe1983d1cfcab1be55aac5 100644 (file)
@@ -246,21 +246,7 @@ function handle_new_item()
        line_start_focus();
 }
 
-//-----------------------------------------------------------------------------------------------
-$id = find_submit('Delete');
-if ($id != -1)
-       handle_delete_item($id);
-
-if (isset($_POST['AddItem']))
-       handle_new_item();
-
-if (isset($_POST['UpdateItem']))
-       handle_update_item();
-
-if (isset($_POST['CancelItemChanges']))
-       line_start_focus();
-
-if (isset($_POST['go']))
+function display_quick_entries(&$cart)
 {
        if (!check_num('totamount', 0))
        {
@@ -269,7 +255,7 @@ if (isset($_POST['go']))
        }
        elseif (!get_post('person_id'))
        {
-               if ($_SESSION['pay_items']->trans_type==systypes::bank_payment())       
+               if ($cart->trans_type==systypes::bank_payment())        
                        display_error( _("No Quick Entries are defined for Payment."));
                else    
                        display_error( _("No Quick Entries are defined for Deposit."));
@@ -279,7 +265,7 @@ if (isset($_POST['go']))
        {
                $rate = 0;
                $totamount = input_num('totamount');
-               $totamount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * $totamount;
+               $totamount = ($cart->trans_type==systypes::bank_payment() ? 1:-1) * $totamount;
                $qe = get_quick_entry($_POST['person_id']);
                $qe_lines = get_quick_entry_lines($_POST['person_id']);
                while ($qe_line = db_fetch($qe_lines))
@@ -293,9 +279,9 @@ if (isset($_POST['go']))
                                        $rate += $item['rate'];
                                if ($rate != 0)
                                        $totamount = $totamount * 100 / ($rate + 100);
-                               $_SESSION['pay_items']->clear_items();
+                               $cart->clear_items();
 
-                               $_SESSION['pay_items']->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
+                               $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
                                        $totamount, $qe['description']);
                                $items = get_tax_group_items($tax_group);
                                while ($item = db_fetch($items))
@@ -303,9 +289,9 @@ if (isset($_POST['go']))
                                        if ($item['rate'] != 0)
                                        {
                                                $amount = $totamount * $item['rate'] / 100;
-                                               $code = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? $item['purchasing_gl_code'] : 
+                                               $code = ($cart->trans_type==systypes::bank_payment() ? $item['purchasing_gl_code'] : 
                                                        $item['sales_gl_code']);
-                                               $_SESSION['pay_items']->add_gl_item($code, 0, 0, $amount, $qe['description']);
+                                               $cart->add_gl_item($code, 0, 0, $amount, $qe['description']);
                                        }
                                }
                        }
@@ -315,13 +301,29 @@ if (isset($_POST['go']))
                                        $amount = $totamount * $qe_line['amount'] / 100;
                                else
                                        $amount = $qe_line['amount'];
-                               $_SESSION['pay_items']->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
+                               $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
                                        $amount, $qe['description']);
                        }               
                }
                line_start_focus();
        }       
-}      
+}
+//-----------------------------------------------------------------------------------------------
+$id = find_submit('Delete');
+if ($id != -1)
+       handle_delete_item($id);
+
+if (isset($_POST['AddItem']))
+       handle_new_item();
+
+if (isset($_POST['UpdateItem']))
+       handle_update_item();
+
+if (isset($_POST['CancelItemChanges']))
+       line_start_focus();
+
+if (isset($_POST['go']))
+       display_quick_entries($_SESSION['pay_items']);
 
 //-----------------------------------------------------------------------------------------------
 
index 65d61c453c8b933a1e05a49ba59323ff2a84a332..2cef81c84cfca176a4b1fa377efb30e61ac7a061 100644 (file)
@@ -214,6 +214,61 @@ function handle_new_item()
        line_start_focus();
 }
 
+function display_quick_entries(&$cart)
+{
+       if (!get_post('person_id'))
+       {
+               display_error( _("No Quick Entries are defined."));
+               set_focus('totamount');
+       }
+       else
+       {
+               $rate = 0;
+               $totamount = input_num('totamount');
+               //$totamount = ($cart->trans_type==systypes::bank_payment() ? 1:-1) * $totamount;
+               $qe = get_quick_entry($_POST['person_id']);
+               $qe_lines = get_quick_entry_lines($_POST['person_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 = $totamount * 100 / ($rate + 100);
+                               $cart->clear_items();
+
+                               $cart->add_gl_item($qe_line['account'], $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 = $totamount * $item['rate'] / 100;
+                                               $code = ($amount < 0 ? $item['purchasing_gl_code'] : 
+                                                       $item['sales_gl_code']);
+                                               $cart->add_gl_item($code, 0, 0, $amount, $qe['description']);
+                                       }
+                               }
+                       }
+                       else
+                       {
+                               if ($qe_line['pct'])
+                                       $amount = $totamount * $qe_line['amount'] / 100;
+                               else
+                                       $amount = $qe_line['amount'];
+                               $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], 
+                                       $amount, $qe['description']);
+                       }               
+               }
+               line_start_focus();
+       }       
+}
+
 //-----------------------------------------------------------------------------------------------
 $id = find_submit('Delete');
 if ($id != -1)
@@ -228,6 +283,8 @@ if (isset($_POST['UpdateItem']))
 if (isset($_POST['CancelItemChanges']))
        line_start_focus();
 
+if (isset($_POST['go']))
+       display_quick_entries($_SESSION['journal_items']);
 //-----------------------------------------------------------------------------------------------
 
 if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items']))
index 620b1bc3553cb84c7ed5ffd35337a720b7e1afa2..2bb39707cce6b3de985b47603cacb4d2175fd44a 100644 (file)
@@ -119,16 +119,38 @@ function delete_quick_entry_line($selected_id)
 }
 //---------------------------------------------------------------------------------------------
 
-function get_quick_entries($deposit=null, $bank_only=null)
+
+function has_quick_entries($deposit=-1, $bank_only=-1)
+{
+       $where = false;
+       $sql = "SELECT id FROM ".TB_PREF."quick_entries";
+       if ($deposit != -1)
+       {
+               $sql .= " WHERE deposit=$deposit";
+               $where = true;
+       }               
+       if ($bank_only != -1)
+       {
+               if ($where)
+                       $sql .= " AND bank_only=$bank_only";
+               else    
+                       $sql .= " WHERE bank_only=$bank_only";
+       }               
+
+       $result = db_query($sql, "could not retreive quick entries");
+       return db_num_rows($result) > 0;
+}
+
+function get_quick_entries($deposit=-1, $bank_only=-1)
 {
        $where = false;
        $sql = "SELECT * FROM ".TB_PREF."quick_entries";
-       if ($deposit != null)
+       if ($deposit != -1)
        {
                $sql .= " WHERE deposit=$deposit";
                $where = true;
        }               
-       if ($bank_only != null)
+       if ($bank_only != -1)
        {
                if ($where)
                        $sql .= " AND bank_only=$bank_only";
index 303d557cf1f4debab35406fd941d3fb304f9ad9d..fa6a500f43157bb2445e2eeec3046bcb8f21aa06 100644 (file)
@@ -68,7 +68,7 @@ function display_bank_header(&$order)
                }
                break;
                case payment_person_types::QuickEntry() :
-                       quick_entries_list_row(_("Description:"), 'person_id', null, $payment);
+                       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));                       
                        break;  
                //case payment_person_types::Project() :
index a8878fcf06343dbbce9ddae8d991050f7211c1c4..01a22ad330ff8c1c7fa9ec6fc87d0de0d1273222 100644 (file)
@@ -9,8 +9,12 @@ function display_order_header(&$Order)
 {
        global $table_style2;
 
+       $qes = has_quick_entries(-1, 0);
        start_table("$table_style2 width=90%");
-       echo "<tr><td valign=top width=50%>"; // outer table
+       if ($qes)
+               echo "<tr><td valign=top width=30%>"; // outer table
+       else    
+               echo "<tr><td valign=top width=50%>"; // outer table
 
        echo "<table>";
        start_row();
@@ -20,13 +24,27 @@ function display_order_header(&$Order)
 
        echo "</table>";
 
-       echo "</td><td width=50%>"; // outer table
+       if ($qes)
+               echo "</td><td width=20%>"; // outer table
+       else    
+               echo "</td><td width=50%>"; // outer table
 
        echo "<table>";
-
-       check_row(_("Reverse Transaction:"), 'Reverse', null);
-
+       start_row();
+       check_cells(_("Reverse Transaction:"), 'Reverse', null);
+       end_row();
        echo "</table>";
+       if ($qes !== false)
+       {
+               echo "</td><td width=50%>"; // outer table
+               echo "<table>";
+               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));                     
+               end_row();
+               echo "</table>";
+       }
+               
 
        echo "</td></tr>"; // outer table
        end_table(1);
@@ -127,8 +145,16 @@ function gl_edit_item_controls(&$order, $dim, $Index=null)
                $_POST['code_id'] = $item->code_id;
                $_POST['dimension_id'] = $item->dimension_id;
                $_POST['dimension2_id'] = $item->dimension2_id;
-               $_POST['AmountDebit'] = price_format($item->amount);
-               $_POST['AmountCredit'] = price_format(abs($item->amount));
+               if ($item->amount > 0)
+               {
+                       $_POST['AmountDebit'] = price_format($item->amount);
+                       $_POST['AmountCredit'] = "";
+               }
+               else
+               {
+                       $_POST['AmountDebit'] = "";
+                       $_POST['AmountCredit'] = price_format(abs($item->amount));
+               }       
                $_POST['description'] = $item->description;
                $_POST['LineMemo'] = $item->reference;
 
index 4748136ee9579b17c4851bb855da35ec9639a50f..9c8534731fe768ba09780afb8fa404bb7ddf966a 100644 (file)
@@ -1624,17 +1624,22 @@ function payment_person_types_list_row($label, $name, $selected_id=null, $relate
 
 //------------------------------------------------------------------------------------------------
 
-function quick_entries_list($name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false)
+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)
-               $sql .= " WHERE deposit=0";
-       else
-               $sql .= " WHERE deposit=1";
-       if ($bank_only)
-               $sql .= " AND bank_only=1";
-       else
-               $sql .= " AND bank_only=0";
+       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' => '',
@@ -1645,11 +1650,18 @@ function quick_entries_list($name, $selected_id=null, $expense=true, $bank_only=
 
 }
 
-function quick_entries_list_row($label, $name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false)
+function quick_entries_list_cells($label, $name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false)
 {
-       echo "<tr><td>$label</td><td>\n";
+       echo "<td>$label</td><td>\n";
        quick_entries_list($name, $selected_id, $expense, $bank_only, $submit_on_change);
-       echo "</td></tr>\n";
+       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";
 }