Enhanced Quick Entries to also support Balance Based source amount. Monthly or Yearly...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 10 Dec 2009 09:46:22 +0000 (09:46 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Thu, 10 Dec 2009 09:46:22 +0000 (09:46 +0000)
Only works with type Journal Entry.

CHANGELOG.txt
gl/includes/db/gl_db_bank_accounts.inc
gl/includes/ui/gl_journal_ui.inc
gl/manage/gl_quick_entries.php
includes/ui/ui_view.inc
sql/alter2.3.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index d719aef30babf85045cfd9cdc5cb185ee5b240e9..d01617b57b1386ee2912174a082326c4f5edf54c 100644 (file)
@@ -19,6 +19,16 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+10-Dec-2009 Joe Hunt
++ Enhanced Quick Entries to also support Balance Based source amount. Monthly or Yearly (all)
+  Only works with type Journal Entry.
+$ /gl/manage/gl_quick_entries.php
+  /gl/includes/ui/gl_journal_ui.inc
+  /includes/ui/ui_view.inc
+  /sql/alter2.3.sql
+  /sql/en_US-new.sql
+  /sql/en_US-demo.sql
+  .
 05-Dec-2009 Joe Hunt
 ! Moved all SQL statements from PHP files into relevant *_db.inc files.
   All folders done, except reporting/repXXX.php and reporting/includes/reports_classes.inc
index 7d79858bef83457817bd8aa0bdde9c29629128f5..b0423f55827d6ce9bb6dfe3a9bef9bf36781d558 100644 (file)
@@ -102,22 +102,22 @@ function get_bank_gl_account($id)
 
 //---------------------------------------------------------------------------------------------
 
-function add_quick_entry($description, $type, $base_amount, $base_desc)
+function add_quick_entry($description, $type, $base_amount, $base_desc, $bal_type)
 {
-       $sql = "INSERT INTO ".TB_PREF."quick_entries (description, type, base_amount, base_desc) 
+       $sql = "INSERT INTO ".TB_PREF."quick_entries (description, type, base_amount, base_desc, bal_type
        VALUES (".db_escape($description).", ".db_escape($type).", "
-               .db_escape($base_amount).", ".db_escape($base_desc).")";
+               .db_escape($base_amount).", ".db_escape($base_desc).", ".db_escape($bal_type).")";
 
        db_query($sql, "could not insert quick entry for $description");
 }
 
 //---------------------------------------------------------------------------------------------
 
-function update_quick_entry($selected_id, $description, $type, $base_amount, $base_desc)
+function update_quick_entry($selected_id, $description, $type, $base_amount, $base_desc, $bal_type)
 {
        $sql = "UPDATE ".TB_PREF."quick_entries SET description = ".db_escape($description).",
                type=".db_escape($type).", base_amount=".db_escape($base_amount)
-               .", base_desc=".db_escape($base_desc)."
+               .", base_desc=".db_escape($base_desc).", bal_type=".db_escape($bal_type)."
                WHERE id = ".db_escape($selected_id);
 
        db_query($sql, "could not update quick entry for $selected_id");
index 3d0a97239f8d17048477bce42f83ceada78067ca..7d13dd45442fe128af3354479e9311a3c69b3783 100644 (file)
@@ -21,7 +21,7 @@ function display_order_header(&$Order)
        $qes = has_quick_entries(QE_JOURNAL);
        $new = $Order->order_id==0;
        start_outer_table("$table_style2 width=90%");
-       table_section(1);
+       table_section(1, $qes ? "20%" : "");
 
        start_row();
     date_cells(_("Date:"), 'date_', '', $new);
@@ -41,7 +41,7 @@ function display_order_header(&$Order)
 
        if ($qes !== false)
        {
-               table_section(3, "50%");
+               table_section(3, "40%");
                start_row();
                quick_entries_list_cells(_("Quick Entry").":", 'person_id', null, QE_JOURNAL, true);
                $qid = get_quick_entry(get_post('person_id'));
@@ -49,8 +49,17 @@ function display_order_header(&$Order)
                        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));
+               if ($qid['bal_type'] == 1)
+               {
+                       end_row();
+                       start_row();
+                       $accname = get_gl_account_name($qid['base_desc']);
+                       label_cell(($qid['base_amount'] == 0 ? _("Yearly") : _("Monthly")) . " ". _("balance from account")." ".
+                               $qid['base_desc']." ".$accname."&nbsp;&nbsp;".submit('go', _("Go"), false, false, true), "colspan=2");
+               }
+               else
+                       amount_cells($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
+                               null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));
                end_row();
 
        }
index a9ad9b55db95f14f4910b2cadd6f5bc8a8f1ad07..555c0888a61459f100e5215445fde23e5dc244d2 100644 (file)
@@ -74,7 +74,14 @@ function can_process()
                set_focus('description');
                return false;
        }
-       if (strlen($_POST['base_desc']) == 0) 
+       $bal_type = get_post('bal_type');
+       if ($bal_type == 1 && $_POST['type'] != QE_JOURNAL)
+       {
+               display_error( _("You can only use Balance Based together with Journal Entries."));
+               set_focus('base_desc');
+               return false;
+       }
+       if (!$bal_type && strlen($_POST['base_desc']) == 0) 
        {
                display_error( _("The base amount description cannot be empty."));
                set_focus('base_desc');
@@ -95,13 +102,13 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
                if ($selected_id != -1) 
                {
                        update_quick_entry($selected_id, $_POST['description'], $_POST['type'],
-                                input_num('base_amount'), $_POST['base_desc']);
+                                input_num('base_amount'), $_POST['base_desc'], get_post('bal_type'));
                        display_notification(_('Selected quick entry has been updated'));
                } 
                else 
                {
                        add_quick_entry($_POST['description'], $_POST['type'], 
-                               input_num('base_amount'), $_POST['base_desc']);
+                               input_num('base_amount'), $_POST['base_desc'], get_post('bal_type'));
                        display_notification(_('New quick entry has been added'));
                }
                $Mode = 'RESET';
@@ -155,6 +162,7 @@ if ($Mode == 'RESET')
        $_POST['description'] = $_POST['type'] = '';
        $_POST['base_desc']= _('Base Amount');
        $_POST['base_amount'] = price_format(0);
+       $_POST['bal_type'] = 0;
 }
 if ($Mode2 == 'RESET2')
 {
@@ -186,37 +194,48 @@ end_table(1);
 end_form();
 //-----------------------------------------------------------------------------------
 
+if (list_updated('type') || (isset($_POST['bal_type']) && list_updated('bal_type')))
+{
+       $Ajax->activate('qe');
+}
 start_form();
-
+div_start('qe');
 start_table($table_style2);
 
 if ($selected_id != -1) 
 {
-       //if ($Mode == 'Edit') 
-       //{
-               //editing an existing status code
-               $myrow = get_quick_entry($selected_id);
-
-               $_POST['id']  = $myrow["id"];
-               $_POST['description']  = $myrow["description"];
-               $_POST['type']  = $myrow["type"];
-               $_POST['base_desc']  = $myrow["base_desc"];
-               $_POST['base_amount']  = price_format($myrow["base_amount"]);
-               hidden('selected_id', $selected_id);
-       //}
+       $myrow = get_quick_entry($selected_id);
+
+       $_POST['id']  = $myrow["id"];
+       $_POST['description']  = $myrow["description"];
+       $_POST['type']  = $myrow["type"];
+       $_POST['base_desc']  = $myrow["base_desc"];
+       $_POST['base_amount']  = price_format($myrow["base_amount"]);
+       $_POST['bal_type']  = $myrow["bal_type"];
+       hidden('selected_id', $selected_id);
 } 
 
 text_row_ex(_("Description").':', 'description', 50, 60);
 
-quick_entry_types_list_row(_("Entry Type").':', 'type');
-
-text_row_ex(_("Base Amount Description").':', 'base_desc', 50, 60, '',_('Base Amount'));
-
-amount_row(_("Default Base Amount").':', 'base_amount', price_format(0));
+quick_entry_types_list_row(_("Entry Type").':', 'type', null, $selected_id == -1);
 
+if (get_post('type') == QE_JOURNAL)
+       yesno_list_row(_("Balance Based"), 'bal_type', null, _("Yes"), _("No"), true);
+if (get_post('bal_type') == 1)
+{
+       yesno_list_row(_("Period"), 'base_amount', null, _("Monthly"), _("Yearly"));
+       gl_all_accounts_list_row(_("Account"), 'base_desc', null, true);
+}
+else
+{
+       if ($selected_id == -1)
+               $_POST['base_desc'] = _("Base Amount");
+       text_row_ex(_("Base Amount Description").':', 'base_desc', 50, 60, '',_('Base Amount'));
+       amount_row(_("Default Base Amount").':', 'base_amount', price_format(0));
+}
 end_table(1);
-
 submit_add_or_update_center($selected_id == -1, '', 'both');
+div_end();
 
 end_form();
 
@@ -230,7 +249,7 @@ if ($selected_id != -1)
        $dim = get_company_pref('use_dimension');
        if ($dim == 2)
                $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
-       else if ($dim == 1)     
+       elseif ($dim == 1)      
                $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), "", "");
        else    
                $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), "", "");
index 8c6bf63bcad55fdbd02f5ae9202cdc112076d8ad..9b51ce3f64c972da290168dd5afa9024b2c5f150 100644 (file)
@@ -523,8 +523,27 @@ function display_quick_entries(&$cart, $id, $base, $type, $descr='')
                if ($type != QE_SUPPINV)        // only one quick entry on journal/bank transaction
                        $cart->clear_items();
                $qe = get_quick_entry($id);
+               if ($qe['bal_type'] == 1)
+               {
+                       if ($qe['base_amount'] == 1.0) // monthly
+                               $begin = begin_month($cart->tran_date);
+                       else
+                       {
+                               if (is_account_balancesheet($qe['base_desc'])) // total
+                                       $begin = "";
+                               else
+                                       $begin = begin_fiscalyear(); // from fiscalyear begin
+                       }               
+                       $base = get_gl_trans_from_to($begin, $cart->tran_date, $qe['base_desc']);
+                               
+               }
                if ($descr != '') $qe['description'] .= ': '.$descr;
                $result = get_quick_entry_lines($id);
+               if (db_num_rows($result) == 0)
+               {
+                       display_error( _("No Quick Entry lines are defined."));
+                       set_focus('totamount');
+               }       
                $totrate = 0;
                while ($row = db_fetch($result))
                {
index 8e9256c53e947a959f77abad8dce246ad20454d9..c1533798285d177f63e23a73216bcb9ddab9cac7 100644 (file)
@@ -1 +1,2 @@
-ALTER TABLE 0_comments ADD KEY type_and_id (`type`, `id`);
\ No newline at end of file
+ALTER TABLE 0_comments ADD KEY type_and_id (`type`, `id`);
+ALTER TABLE 0_quick_entries ADD COLUMN `bal_type` TINYINT(1) NOT NULL default '0'; 
index 5fcaa36689b4642a20e6ea2f6f09d4f229ca1db4..bc0e602af2111c8a78ebfb09aa0fd382cb9f8047 100644 (file)
@@ -1194,6 +1194,7 @@ CREATE TABLE `0_quick_entries` (
   `description` varchar(60) NOT NULL,
   `base_amount` double NOT NULL default '0',
   `base_desc` varchar(60) default NULL,
+  `bal_type` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`id`),
   KEY `description` (`description`)
 ) TYPE=MyISAM AUTO_INCREMENT=4 ;
@@ -1201,9 +1202,9 @@ CREATE TABLE `0_quick_entries` (
 
 ### Data of table `0_quick_entries` ###
 
-INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount');
-INSERT INTO `0_quick_entries` VALUES ('2', '4', 'Phone', '0', 'Amount');
-INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount');
+INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount', '0');
+INSERT INTO `0_quick_entries` VALUES ('2', '4', 'Phone', '0', 'Amount', '0');
+INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount', '0');
 
 
 ### Structure of table `0_quick_entry_lines` ###
index 1be4f088674e419694924e984b260876adc85b04..d8396b07b9972ad1dff90ca329b8fae0bb2641d9 100644 (file)
@@ -1037,6 +1037,7 @@ CREATE TABLE `0_quick_entries` (
   `description` varchar(60) NOT NULL,
   `base_amount` double NOT NULL default '0',
   `base_desc` varchar(60) default NULL,
+  `bal_type` tinyint(1) NOT NULL default '0',
   PRIMARY KEY  (`id`),
   KEY `description` (`description`)
 ) TYPE=MyISAM AUTO_INCREMENT=4 ;
@@ -1044,9 +1045,9 @@ CREATE TABLE `0_quick_entries` (
 
 ### Data of table `0_quick_entries` ###
 
-INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount');
-INSERT INTO `0_quick_entries` VALUES ('2', '4', 'Phone', '0', 'Amount');
-INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount');
+INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount', '0');
+INSERT INTO `0_quick_entries` VALUES ('2', '4', 'Phone', '0', 'Amount'. '0');
+INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount', '0');
 
 
 ### Structure of table `0_quick_entry_lines` ###