Added Quick Entries in Bank Payments/Deposits (Banking and General Ledger).
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 29 Oct 2008 23:48:27 +0000 (23:48 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Wed, 29 Oct 2008 23:48:27 +0000 (23:48 +0000)
CHANGELOG.txt
applications/generalledger.php
gl/gl_bank.php
gl/includes/db/gl_db_bank_accounts.inc
gl/includes/ui/gl_bank_ui.inc
gl/manage/gl_accounts.php
includes/data_checks.inc
includes/types.inc
includes/ui/ui_lists.inc
sales/manage/customer_branches.php
sql/alter2.1.sql

index 1e20cc962abce04bbec9304eeea030f951bb93f4..fad2f3d0809f00a57e68a535f35207da4aa07882 100644 (file)
@@ -19,6 +19,21 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+30-Oct-2008 Joe Hunt
+! Added Quick Entries in Bank Payments/Deposits (Banking and General Ledger).
+$ /applications/generalledger.php 
+  /includes/data_checks.inc
+  /includes/types.inc
+  /includes/ui/ui_lists.inc
+  /gl/gl_bank.php
+  /gl/includes/db/gl_db_bank_accounts.inc
+  /gl/includes/ui/gl_bank_ui.inc
+  /sales/manage/customer_branches.php
+! New table, 0_quick_entries
+$ /sql/alter2.1.sql
+! Changed GL Accounts form. The tax_code is now Tax Group instead of Tax Type.
+$ /gl/manage/gl_accounts.php
+
 24-Oct-2008 Janusz Dobrowolski
 ! Added hotkeys to final menu options.
 $ /dimensions/dimension_entry.php
index e3b5d6d7db9bb93e04fd8a137886bbb4805a32eb..ecbc6b9128f8ea204a197af09e028190b39a99ba 100644 (file)
@@ -27,6 +27,7 @@
                        $this->add_module(_("Maintenance"));
                        $this->add_lapp_function(2, _("Bank &Accounts"),"gl/manage/bank_accounts.php?");
                        $this->add_lapp_function(2, _("Payment, Deposit and Transfer &Types"),"gl/manage/bank_trans_types.php?");
+                       $this->add_lapp_function(2, _("Quick Entries"),"gl/manage/gl_quick_entries.php?");
                        $this->add_lapp_function(2, "","");
                        $this->add_lapp_function(2, _("&Currencies"),"gl/manage/currencies.php?");
                        $this->add_lapp_function(2, _("&Exchange Rates"),"gl/manage/exchange_rates.php?");
index 522cdd86c9d25213df7a5a09d912c95b486f559a..86a909cfa82e29fc996ef66df326d35376e18b79 100644 (file)
@@ -262,6 +262,50 @@ if (isset($_POST['UpdateItem']))
 if (isset($_POST['CancelItemChanges']))
        line_start_focus();
 
+if (isset($_POST['go']))
+{
+       if (!check_num('totamount', 0))
+       {
+               display_error( _("The amount entered is not a valid number or is less than zero."));
+               set_focus('totamount');
+       }
+       elseif (!get_post('person_id'))
+       {
+               if ($_SESSION['pay_items']->trans_type==systypes::bank_payment())       
+                       display_error( _("No Quick Entries are defined for Payment."));
+               else    
+                       display_error( _("No Quick Entries are defined for Deposit."));
+               set_focus('totamount');
+       }
+       else
+       {
+               $rate = 0;
+               $totamount = input_num('totamount');
+               $qe = get_quick_entry($_POST['person_id']);
+               $account = get_gl_account($qe['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);
+               $totamount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * $totamount;
+               $_SESSION['pay_items']->clear_items();
+               $_SESSION['pay_items']->add_gl_item($qe['account'], 0, 0, $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 = ($_SESSION['pay_items']->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']);
+                       }
+               }
+               line_start_focus();
+       }       
+}      
 
 //-----------------------------------------------------------------------------------------------
 
index 2c405614b9b8b2db9f8a9db18e1894df73bd18fb..506a94c8d56d7764bd57d8fdfb6a33f285e4cb95 100644 (file)
@@ -48,4 +48,60 @@ function get_bank_account($account_code)
 
 //---------------------------------------------------------------------------------------------
 
+function add_quick_entry($description, $account, $deposit)
+{
+       $sql = "INSERT INTO ".TB_PREF."quick_entries (description, account, deposit) VALUES 
+               (".db_escape($description).", ".db_escape($account).", $deposit)";
+
+       db_query($sql, "could not insert quick entry for $description");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function update_quick_entry($selected_id, $description, $account, $deposit)
+{
+       $sql = "UPDATE ".TB_PREF."quick_entries SET description = ".db_escape($description).",
+               account=".db_escape($account).", deposit=$deposit 
+               WHERE id = $selected_id";
+
+       db_query($sql, "could not update quick entry for $selected_id");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function delete_quick_entry($selected_id)
+{
+       $sql = "DELETE FROM ".TB_PREF."quick_entries WHERE id=$selected_id";
+
+       db_query($sql,"could not delete quick entry $selected_id");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_quick_entries($type=false)
+{
+       $sql = "SELECT ".TB_PREF."quick_entries.*, ".TB_PREF."chart_master.account_name 
+               FROM ".TB_PREF."quick_entries, ".TB_PREF."chart_master WHERE
+               ".TB_PREF."quick_entries.account = ".TB_PREF."chart_master.account_code";
+       if ($type == "deposit")
+               $sql .= " AND deposit=1";
+       elseif ($type == "payment")
+               $sql .= " AND deposit=0";
+
+       return db_query($sql, "could not retreive quick entries");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_quick_entry($selected_id)
+{
+       $sql = "SELECT * FROM ".TB_PREF."quick_entries WHERE id=$selected_id";
+
+       $result = db_query($sql, "could not retreive quick entry for $selected_id");
+
+       return db_fetch($result);
+}
+
+//---------------------------------------------------------------------------------------------
+
 ?>
\ No newline at end of file
index 61c5250ab1d2e1d9d62cc55428cc10dcff2062eb..a0a1ed7a77119b5d44f60497b910eff1319c1114 100644 (file)
@@ -67,6 +67,10 @@ function display_bank_header(&$order)
                        hidden('PersonDetailID');
                }
                break;
+               case payment_person_types::QuickEntry() :
+                       quick_entries_list_row(_("Description:"), 'person_id', null, $payment);
+                       amount_row(_("Total Amount"), 'totamount', null, 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);
        //      break;
index 55fd938906ab077b7036f4fa6e2c8ebed9a607e4..2520d355cfd7e43038e023123e378dfa4bc07bcf 100644 (file)
@@ -235,7 +235,7 @@ text_row_ex(_("Account Name:"), 'account_name', 60);
 
 gl_account_types_list_row(_("Account Group:"), 'account_type', null);
 
-tax_types_list_row(_("Tax Type:"), 'tax_code', null, _('No Tax'));
+tax_groups_list_row(_("Tax Group:"), 'tax_code', null, _('No Tax'));
 
 end_table(1);
 
index b79bf3d2357d7c5cc3981331cf06cf82728ccccd..2f33cb531c272485e24e09fc4d728507dbfade61 100644 (file)
@@ -420,6 +420,11 @@ function check_db_has_gl_account_groups($msg)
     }  
 }
 
+function db_has_quick_entries()
+{
+       return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."quick_entries");
+}
+
 function check_empty_result($sql)
 {
        $result = db_query($sql, "could not do check empty query");     
index c8c5f90482dec7bffa1b6c8fe05691f1f958270f..73efbfe1107bfefd8665c95f6985c34cedce5aad 100644 (file)
@@ -144,6 +144,7 @@ $payment_person_types_array = array (
                                                        1=> array ('id' => 1, 'name' => _("Work Order")),
                                                        2=> array ('id' => 2, 'name' => _("Customer")),
                                                        3=> array ('id' => 3, 'name' => _("Supplier")),
+                                                       4=> array ('id' => 4, 'name' => _("Quick Entry"))
                                                        );
 
 class payment_person_types 
@@ -175,12 +176,15 @@ class payment_person_types
        return 3; 
     }
 
-    function dimension()  
+    function QuickEntry()  
     { 
        return 4; 
     }
 
-    //function Project()  { return 4; }
+    function dimension()  
+    { 
+       return 5; 
+    }
 
     function type_name($type)
     {
@@ -194,6 +198,9 @@ class payment_person_types
        {
                case payment_person_types::misc() :
                        return $person_id;
+               case payment_person_types::QuickEntry() :
+                       $qe = get_quick_entry($person_id);
+                       return ($full?payment_person_types::type_name($type) . " ":"") . $qe["description"];
                case payment_person_types::WorkOrder() :
                        $wo = get_work_order($person_id);
                        return ($full?payment_person_types::type_name($type) . " ":"") . $wo["wo_ref"];
@@ -201,8 +208,6 @@ class payment_person_types
                        return ($full?payment_person_types::type_name($type) . " ":"") . get_customer_name($person_id);
                case payment_person_types::supplier() :
                        return ($full?payment_person_types::type_name($type) . " ":"") . get_supplier_name($person_id);
-               //case payment_person_types::Project() :
-               //      return ($full?payment_person_types::type_name($type) . " ":"") . get_dimension_string($person_id);
                default :
                        //DisplayDBerror("Invalid type sent to person_name");
                        //return;
@@ -215,8 +220,8 @@ class payment_person_types
        switch ($type)
        {
                case payment_person_types::misc() :
+               case payment_person_types::QuickEntry() :
                case payment_person_types::WorkOrder() :
-               //case payment_person_types::Project() :
                        return get_company_currency();
 
                case payment_person_types::customer() :
@@ -236,17 +241,17 @@ class payment_person_types
        {
                case payment_person_types::misc() :
                        return true;
-               case payment_person_types::WorkOrder() : // 070305 changed to open workorders ES
+               case payment_person_types::QuickEntry() :
+                       return db_has_quick_entries();
+               case payment_person_types::WorkOrder() : // 070305 changed to open workorders JH
                        return db_has_open_workorders();
                case payment_person_types::customer() :
                        return db_has_customers();
                case payment_person_types::supplier() :
                        return db_has_suppliers();
-               //case payment_person_types::Project() :
-               //      return db_has_dimensions();
                default :
                        display_db_error("Invalid type sent to has_items", "");
-                       return;
+                       return false;
        }
     }
 }
index acfe058cb56a1584d996e446f1003505c61c56e3..e53d0eb23f4499631d182bc5ec30e8e943994a92 100644 (file)
@@ -887,26 +887,26 @@ function tax_groups_list($name, $selected_id=null,
        array(
                'order' => 'id',
                'spec_option' => $none_option,
-               'spec_id' => 0,
+               'spec_id' => reserved_words::get_all_numeric(),
                'select_submit'=> $submit_on_change,
                'async' => false,
        ) );
 }
 
-function tax_groups_list_cells($label, $name, $selected_id=null, $submit_on_change=false)
+function tax_groups_list_cells($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
 {
        if ($label != null)
                echo "<td>$label</td>\n";
        echo "<td>";
-       $str = tax_groups_list($name, $selected_id, false, $submit_on_change);
+       $str = tax_groups_list($name, $selected_id, $none_option, $submit_on_change);
        echo "</td>\n";
        return $str;
 }
 
-function tax_groups_list_row($label, $name, $selected_id=null, $submit_on_change=false)
+function tax_groups_list_row($label, $name, $selected_id=null, $none_option=false, $submit_on_change=false)
 {
        echo "<tr>\n";
-       $str = tax_groups_list_cells($label, $name, $selected_id, false, $submit_on_change);
+       $str = tax_groups_list_cells($label, $name, $selected_id, $none_option, $submit_on_change);
        echo "</tr>\n";
        return $str;
 }
@@ -1506,6 +1506,33 @@ function payment_person_types_list_row($label, $name, $selected_id=null, $relate
        return $str;
 }
 
+//------------------------------------------------------------------------------------------------
+
+function quick_entries_list($name, $selected_id=null, $expense=true, $submit_on_change=false)
+{
+       $sql = "SELECT * FROM ".TB_PREF."quick_entries";
+       if ($expense)
+               $sql .= " WHERE deposit=0";
+       else
+               $sql .= " WHERE deposit=1";
+       combo_input($name, $selected_id, $sql, 'id', 'description',
+               array(
+                       'spec_id' => '',
+                       'order' => 'description',
+                       'select_submit'=> $submit_on_change,
+                       'async' => false
+               ) );
+
+}
+
+function quick_entries_list_row($label, $name, $selected_id=null, $expense=true, $submit_on_change=false)
+{
+       echo "<tr><td>$label</td><td>\n";
+       quick_entries_list($name, $selected_id, $expense, $submit_on_change);
+       echo "</td></tr>\n";
+}
+
+
 //------------------------------------------------------------------------------------------------
 
 function wo_types_list($name, $selected_id=null)
index c4460d69e713b64569191e0a7daf8d67476117d1..69ecd9e4059e9845755d1ab6cc0165f9ccb79337 100644 (file)
@@ -300,7 +300,7 @@ locations_list_row(_("Default Inventory Location:"), 'default_location', null);
 
 shippers_list_row(_("Default Shipping Company:"), 'default_ship_via', null);
 
-tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null, 31, 30);
+tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
 
 yesno_list_row(_("Disable this Branch:"), 'disable_trans', null);
 
index d2d381b471d85d848acd6e04f9f5fbfdb0b681e0..85127db6931d7b108e7162083b6e3b0242e57b30 100644 (file)
@@ -1,3 +1,18 @@
+DROP TABLE IF EXISTS `0_quick_entries`;
+
+CREATE TABLE `0_quick_entries` (
+  `id` smallint(6) NOT NULL auto_increment,
+  `description` varchar(60) NOT NULL,
+  `account` varchar(11) NOT NULL,
+  `deposit` tinyint(1) NOT NULL default '0',
+  PRIMARY KEY  (`id`),
+  UNIQUE KEY `description` (`description`)
+) ENGINE=MyISAM AUTO_INCREMENT=1;
+
+INSERT INTO `0_quick_entries` VALUES ('1', 'Maintenance', '6600', '0');
+INSERT INTO `0_quick_entries` VALUES ('2', 'Phone', '6730', '0');
+INSERT INTO `0_quick_entries` VALUES ('3', 'Cash Sales', '3000', '1');
+
 
 ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) DEFAULT '' AFTER `show_hints` ;
 ALTER TABLE `0_users` ADD `rep_popup` TINYINT(1) DEFAULT '1' AFTER `print_profile` ;