From deed05a36c33ecad4dd8528b84c13490bbc042de Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Thu, 10 Dec 2009 09:46:22 +0000 Subject: [PATCH] Enhanced Quick Entries to also support Balance Based source amount. Monthly or Yearly (all) Only works with type Journal Entry. --- CHANGELOG.txt | 10 ++++ gl/includes/db/gl_db_bank_accounts.inc | 10 ++-- gl/includes/ui/gl_journal_ui.inc | 17 +++++-- gl/manage/gl_quick_entries.php | 65 +++++++++++++++++--------- includes/ui/ui_view.inc | 19 ++++++++ sql/alter2.3.sql | 3 +- sql/en_US-demo.sql | 7 +-- sql/en_US-new.sql | 7 +-- 8 files changed, 99 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index d719aef3..d01617b5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/gl/includes/db/gl_db_bank_accounts.inc b/gl/includes/db/gl_db_bank_accounts.inc index 7d79858b..b0423f55 100644 --- a/gl/includes/db/gl_db_bank_accounts.inc +++ b/gl/includes/db/gl_db_bank_accounts.inc @@ -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"); diff --git a/gl/includes/ui/gl_journal_ui.inc b/gl/includes/ui/gl_journal_ui.inc index 3d0a9723..7d13dd45 100644 --- a/gl/includes/ui/gl_journal_ui.inc +++ b/gl/includes/ui/gl_journal_ui.inc @@ -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, "  ".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."  ".submit('go', _("Go"), false, false, true), "colspan=2"); + } + else + amount_cells($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']), + null, "  ".submit('go', _("Go"), false, false, true)); end_row(); } diff --git a/gl/manage/gl_quick_entries.php b/gl/manage/gl_quick_entries.php index a9ad9b55..555c0888 100644 --- a/gl/manage/gl_quick_entries.php +++ b/gl/manage/gl_quick_entries.php @@ -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"), "", ""); diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index 8c6bf63b..9b51ce3f 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -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)) { diff --git a/sql/alter2.3.sql b/sql/alter2.3.sql index 8e9256c5..c1533798 100644 --- a/sql/alter2.3.sql +++ b/sql/alter2.3.sql @@ -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'; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index 5fcaa366..bc0e602a 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -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` ### diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 1be4f088..d8396b07 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -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` ### -- 2.30.2