Only works with type Journal Entry.
! -> 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
//---------------------------------------------------------------------------------------------
-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");
$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);
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'));
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();
}
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');
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';
$_POST['description'] = $_POST['type'] = '';
$_POST['base_desc']= _('Base Amount');
$_POST['base_amount'] = price_format(0);
+ $_POST['bal_type'] = 0;
}
if ($Mode2 == 'RESET2')
{
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();
$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"), "", "");
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))
{
-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';
`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 ;
### 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` ###
`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 ;
### 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` ###