! -> Note
$ -> Affected files
+09-Nov-2008 Joe Hunt
+30-Oct-2008 Joe Hunt
+! changed Quick Entries in Bank Payments/Deposits (Banking and General Ledger) to also work as Automatic Codings.
+$ /includes/ui/ui_lists.inc
+ /includes/ui/ui_input.inc
+ /gl/gl_bank.php
+ /gl/includes/db/gl_db_bank_accounts.inc
+ /gl/includes/ui/gl_bank_ui.inc
+ /gl/manage/gl_quick_entries.php
+! New table, 0:quick_entry_lines, change to 0_quick_entries
+$ /sql/alter2.1.sql
+
+
08-Nov-2008 Janusz Dobrowolski
! Rewritten for paged query results.
$ /purchasing/inquiry/supplier_inquiry.php
function check_item_data()
{
- if (!check_num('amount', 0))
- {
- display_error( _("The amount entered is not a valid number or is less than zero."));
- set_focus('amount');
- return false;
- }
+ //if (!check_num('amount', 0))
+ //{
+ // display_error( _("The amount entered is not a valid number or is less than zero."));
+ // set_focus('amount');
+ // return false;
+ //}
if ($_POST['code_id'] == $_POST['bank_account'])
{
return false;
}
- if (is_bank_account($_POST['code_id']))
- {
- if ($_SESSION['pay_items']->trans_type == systypes::bank_payment())
- display_error( _("You cannot make a payment to a bank account. Please use the transfer funds facility for this."));
- else
- display_error( _("You cannot make a deposit from a bank account. Please use the transfer funds facility for this."));
- set_focus('code_id');
- return false;
- }
+ //if (is_bank_account($_POST['code_id']))
+ //{
+ // if ($_SESSION['pay_items']->trans_type == systypes::bank_payment())
+ // display_error( _("You cannot make a payment to a bank account. Please use the transfer funds facility for this."));
+ // else
+ // display_error( _("You cannot make a deposit from a bank account. Please use the transfer funds facility for this."));
+ // set_focus('code_id');
+ // return false;
+ //}
return true;
}
{
$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))
+ $qe = get_quick_entry($_POST['person_id']);
+ $qe_lines = get_quick_entry_lines($_POST['person_id']);
+ while ($qe_line = db_fetch($qe_lines))
{
- if ($item['rate'] != 0)
+ if ($qe_line['tax_acc'])
{
- $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']);
+ $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);
+ $_SESSION['pay_items']->clear_items();
+
+ $_SESSION['pay_items']->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 = ($_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']);
+ }
+ }
}
+ else
+ {
+ if ($qe_line['pct'])
+ $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'],
+ $amount, $qe['description']);
+ }
}
line_start_focus();
}
//---------------------------------------------------------------------------------------------
-function add_quick_entry($description, $account, $deposit)
+function add_quick_entry($description, $deposit, $bank_only)
{
- $sql = "INSERT INTO ".TB_PREF."quick_entries (description, account, deposit) VALUES
- (".db_escape($description).", ".db_escape($account).", $deposit)";
+ $sql = "INSERT INTO ".TB_PREF."quick_entries (description, deposit, bank_only) VALUES
+ (".db_escape($description).", $deposit, $bank_only)";
db_query($sql, "could not insert quick entry for $description");
}
//---------------------------------------------------------------------------------------------
-function update_quick_entry($selected_id, $description, $account, $deposit)
+function update_quick_entry($selected_id, $description, $deposit, $bank_only)
{
$sql = "UPDATE ".TB_PREF."quick_entries SET description = ".db_escape($description).",
- account=".db_escape($account).", deposit=$deposit
- WHERE id = $selected_id";
+ deposit=$deposit, bank_only=$bank_only WHERE id = $selected_id";
db_query($sql, "could not update quick entry for $selected_id");
}
//---------------------------------------------------------------------------------------------
-function get_quick_entries($type=false)
+function add_quick_entry_line($qid, $account, $tax_acc, $pct, $amount, $dim, $dim2)
{
- $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";
+ $sql = "INSERT INTO ".TB_PREF."quick_entry_lines (qid, account, tax_acc, pct, amount, dimension_id, dimension2_id) VALUES
+ ($qid, ".db_escape($account).", $tax_acc, $pct, $amount, $dim, $dim2)";
- return db_query($sql, "could not retreive quick entries");
+ db_query($sql, "could not insert quick entry line for $qid");
+}
+
+//---------------------------------------------------------------------------------------------
+
+function update_quick_entry_line($selected_id, $qid, $account, $tax_acc, $pct, $amount, $dim, $dim2)
+{
+ $sql = "UPDATE ".TB_PREF."quick_entry_lines SET qid = $qid, account=".db_escape($account).",
+ tax_acc=$tax_acc, pct=$pct, amount=$amount, dimension_id=$dim, dimension2_id=$dim2
+ WHERE id = $selected_id";
+
+ db_query($sql, "could not update quick entry line for $selected_id");
}
//---------------------------------------------------------------------------------------------
+function delete_quick_entry_line($selected_id)
+{
+ $sql = "DELETE FROM ".TB_PREF."quick_entry_lines WHERE id=$selected_id";
+
+ db_query($sql,"could not delete quick entry line $selected_id");
+}
+//---------------------------------------------------------------------------------------------
+
+function get_quick_entries($deposit=null, $bank_only=null)
+{
+ $where = false;
+ $sql = "SELECT * FROM ".TB_PREF."quick_entries";
+ if ($deposit != null)
+ {
+ $sql .= " WHERE deposit=$deposit";
+ $where = true;
+ }
+ if ($bank_only != null)
+ {
+ if ($where)
+ $sql .= " AND bank_only=$bank_only";
+ else
+ $sql .= " WHERE bank_only=$bank_only";
+ }
+ $sql .= " ORDER BY description";
+
+ 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 $selected_id");
+
+ return db_fetch($result);
+}
+
+function get_quick_entry_lines($qid)
+{
+ $sql = "SELECT ".TB_PREF."quick_entry_lines.*, ".TB_PREF."chart_master.account_name
+ FROM ".TB_PREF."quick_entry_lines, ".TB_PREF."chart_master
+ WHERE ".TB_PREF."quick_entry_lines.account = ".TB_PREF."chart_master.account_code
+ AND qid=$qid";
+
+ return db_query($sql, "could not retreive quick entries");
+}
+
+function has_quick_entry_lines($qid)
+{
+ $sql = "SELECT id FROM ".TB_PREF."quick_entry_lines WHERE qid=$qid";
+
+ $result = db_query($sql, "could not retreive quick entries");
+ return db_num_rows($result) > 0;
+}
+
+//---------------------------------------------------------------------------------------------
+
+function get_quick_entry_line($selected_id)
+{
+ $sql = "SELECT * FROM ".TB_PREF."quick_entry_lines WHERE id=$selected_id";
+
$result = db_query($sql, "could not retreive quick entry for $selected_id");
return db_fetch($result);
label_cell(get_dimension_string($item->dimension_id, true));
if ($dim > 1)
label_cell(get_dimension_string($item->dimension2_id, true));
- amount_cell(abs($item->amount));
+ //amount_cell(abs($item->amount));
+ if ($order->trans_type == systypes::bank_deposit())
+ amount_cell(-$item->amount);
+ else
+ amount_cell($item->amount);
label_cell($item->reference);
edit_button_cell("Edit$item->index", _("Edit"),
$_POST['code_id'] =
get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
}
- gl_all_accounts_list('code_id', null, true, false, true);
+ gl_all_accounts_list('code_id', null, false, false, true);
if ($dim >= 1)
dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
if ($dim > 1)
include($path_to_root . "/includes/ui.inc");
simple_page_mode(true);
+simple_page_mode2(true);
+
+function simple_page_mode2($numeric_id = true)
+{
+ global $Ajax, $Mode2, $selected_id2;
+
+ $default = $numeric_id ? -1 : '';
+ $selected_id2 = get_post('selected_id2', $default);
+ foreach (array('ADD_ITEM2', 'UPDATE_ITEM2', 'RESET2') as $m) {
+ if (isset($_POST[$m])) {
+ $Ajax->activate('_page_body');
+ if ($m == 'RESET2')
+ $selected_id2 = $default;
+ $Mode2 = $m; return;
+ }
+ }
+ foreach (array('BEd', 'BDel') as $m) {
+ foreach ($_POST as $p => $pvar) {
+ if (strpos($p, $m) === 0) {
+// $selected_id2 = strtr(substr($p, strlen($m)), array('%2E'=>'.'));
+ unset($_POST['_focus']); // focus on first form entry
+ $selected_id2 = quoted_printable_decode(substr($p, strlen($m)));
+ $Ajax->activate('_page_body');
+ $Mode2 = $m;
+ return;
+ }
+ }
+ }
+ $Mode2 = '';
+}
+
+function submit_add_or_update_center2($add=true, $title=false, $async=false)
+{
+ echo "<center>";
+ if ($add)
+ submit('ADD_ITEM2', _("Add new"), true, $title, $async);
+ else {
+ submit('UPDATE_ITEM2', _("Update"), true, $title, $async);
+ submit('RESET2', _("Cancel"), true, $title, $async);
+ }
+ echo "</center>";
+}
+
//-----------------------------------------------------------------------------------
function can_process()
if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
{
- if (can_process())
- {
+ if (can_process())
+ {
- if ($selected_id != -1)
- {
- update_quick_entry($selected_id, $_POST['description'], $_POST['account'], $_POST['deposit']);
+ if ($selected_id != -1)
+ {
+ update_quick_entry($selected_id, $_POST['description'], $_POST['deposit'], $_POST['bank_only']);
display_notification(_('Selected quick entry has been updated'));
- }
- else
- {
- add_quick_entry($_POST['description'], $_POST['account'], $_POST['deposit']);
- display_notification(_('New account class has been added'));
- }
+ }
+ else
+ {
+ add_quick_entry($_POST['description'], $_POST['deposit'], $_POST['bank_only']);
+ display_notification(_('New quick entry has been added'));
+ }
$Mode = 'RESET';
}
}
+if ($Mode2=='ADD_ITEM2' || $Mode2=='UPDATE_ITEM2')
+{
+ if ($selected_id2 != -1)
+ {
+ update_quick_entry_line($selected_id2, $selected_id, $_POST['account'], $_POST['tax_acc'], $_POST['pct'], input_num('amount', 0),
+ $_POST['dimension_id'], $_POST['dimension2_id']);
+ display_notification(_('Selected quick entry line has been updated'));
+ }
+ else
+ {
+ add_quick_entry_line($selected_id, $_POST['account'], $_POST['tax_acc'], $_POST['pct'], input_num('amount', 0),
+ $_POST['dimension_id'], $_POST['dimension2_id']);
+ display_notification(_('New quick entry line has been added'));
+ }
+ $Mode2 = 'RESET2';
+}
+
//-----------------------------------------------------------------------------------
if ($Mode == 'Delete')
{
-
- delete_quick_entry($selected_id);
- display_notification(_('Selected quick entry has been deleted'));
- $Mode = 'RESET';
+ if (!has_quick_entry_lines($selected_id))
+ {
+ delete_quick_entry($selected_id);
+ display_notification(_('Selected quick entry has been deleted'));
+ $Mode = 'RESET';
+ }
+ else
+ {
+ display_error( _("The Quick Entry has Quick Entry Lines. Cannot be deleted."));
+ set_focus('description');
+ }
}
+if ($Mode2 == 'BDel')
+{
+ delete_quick_entry_line($selected_id2);
+ display_notification(_('Selected quick entry line has been deleted'));
+ $Mode2 = 'RESET2';
+}
//-----------------------------------------------------------------------------------
if ($Mode == 'RESET')
{
$selected_id = -1;
- $_POST['description'] = $_POST['account'] = $_POST['deposit'] = '';
+ $_POST['description'] = $_POST['deposit'] = $_POST['bank_only'] = '';
+}
+if ($Mode2 == 'RESET2')
+{
+ $selected_id2 = -1;
+ $_POST['account'] = $_POST['tax_acc'] = $_POST['pct'] = $_POST['amount'] = $_POST['dimension_id'] = $_POST['dimension2_id'] = '';
}
//-----------------------------------------------------------------------------------
$result = get_quick_entries();
start_form();
start_table($table_style);
-$th = array(_("Description"), _("Account"), _("Deposit"), "", "");
+$th = array(_("Description"), _("Deposit"), _("Bank Only"), "", "");
table_header($th);
$k = 0;
while ($myrow = db_fetch($result))
{
-
alt_table_row_color($k);
-
- if ($myrow["deposit"] == 0)
- {
- $bs_text = _("No");
- }
- else
- {
- $bs_text = _("Yes");
- }
+ $deposit_text = ($myrow["deposit"] == 0 ? _("No") : _("Yes"));
+ $bank_text = ($myrow["bank_only"] == 0 ? _("No") : _("Yes"));
label_cell($myrow['description']);
- label_cell($myrow['account']." ".$myrow['account_name']);
- label_cell($bs_text);
+ label_cell($deposit_text);
+ label_cell($bank_text);
edit_button_cell("Edit".$myrow["id"], _("Edit"));
edit_button_cell("Delete".$myrow["id"], _("Delete"));
end_row();
end_table();
end_form();
-echo '<br>';
//-----------------------------------------------------------------------------------
start_form();
if ($selected_id != -1)
{
- if ($Mode == 'Edit')
- {
+ //if ($Mode == 'Edit')
+ //{
//editing an existing status code
$myrow = get_quick_entry($selected_id);
$_POST['id'] = $myrow["id"];
$_POST['description'] = $myrow["description"];
- $_POST['account'] = $myrow["account"];
$_POST['deposit'] = $myrow["deposit"];
+ $_POST['bank_only'] = $myrow["bank_only"];
hidden('selected_id', $selected_id);
- }
+ //}
}
text_row_ex(_("Description:"), 'description', 50, 60);
-gl_all_accounts_list_row(_("Account"), 'account', null, true);
-
yesno_list_row(_("Deposit:"), 'deposit', null, "", "", false);
+yesno_list_row(_("Bank Only:"), 'bank_only', null, "", "", false);
+
end_table(1);
submit_add_or_update_center($selected_id == -1, '', true);
end_form();
+if ($selected_id != -1)
+{
+ display_heading(_("Quick Entry Lines") . " - " . $_POST['description']);
+ $result = get_quick_entry_lines($selected_id);
+ start_form();
+ start_table($table_style2);
+ $dim = get_company_pref('use_dimension');
+ if ($dim == 2)
+ $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", "");
+ else if ($dim == 1)
+ $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), "", "");
+ else
+ $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), "", "");
+ table_header($th);
+ $k = 0;
+ while ($myrow = db_fetch($result))
+ {
+ alt_table_row_color($k);
+ label_cell($myrow['account']." ".$myrow['account_name']);
+ $tax_text = ($myrow['tax_acc'] == 0 ? _("No") : _("Yes"));
+ label_cell($tax_text);
+ $pct_text = ($myrow['pct'] == 0 ? _("No") : _("Yes"));
+ label_cell($pct_text);
+ amount_cell($myrow['amount']);
+ if ($dim >= 1)
+ label_cell(get_dimension_string($myrow['dimension_id'], true));
+ if ($dim > 1)
+ label_cell(get_dimension_string($myrow['dimension2_id'], true));
+ edit_button_cell("BEd".$myrow["id"], _("Edit"));
+ edit_button_cell("BDel".$myrow["id"], _("Delete"));
+ end_row();
+ }
+ end_table();
+ hidden('selected_id', $selected_id);
+ hidden('selected_id2', $selected_id2);
+ hidden('description', $_POST['description']);
+ hidden('deposit', $_POST['deposit']);
+ hidden('bank_only', $_POST['bank_only']);
+ end_form();
+ start_form();
+
+ start_table($table_style2);
+
+ if ($selected_id2 != -1)
+ {
+ if ($Mode2 == 'BEd')
+ {
+ //editing an existing status code
+ $myrow = get_quick_entry_line($selected_id2);
+
+ $_POST['id'] = $myrow["id"];
+ $_POST['account'] = $myrow["account"];
+ $_POST['tax_acc'] = $myrow["tax_acc"];
+ $_POST['pct'] = $myrow["pct"];
+ $_POST['amount'] = $myrow["amount"];
+ $_POST['dimension_id'] = $myrow["dimension_id"];
+ $_POST['dimension2_id'] = $myrow["dimension2_id"];
+ }
+ }
+
+ gl_all_accounts_list_row(_("Account"), 'account', null, true);
+ yesno_list_row(_("Use Tax:"), 'tax_acc', null, "", "", false);
+ yesno_list_row(_("Use Percent:"), 'pct', null, "", "", false);
+ amount_row(_("Amount"), 'amount', null);
+ if ($dim >= 1)
+ dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 1);
+ if ($dim > 1)
+ dimensions_list_row(_("Dimension")." 2", 'dimension2_id', null, true, " ", false, 2);
+
+ end_table(1);
+ if ($dim < 2)
+ hidden('dimension2_id', 0);
+ if ($dim < 1)
+ hidden('dimension_id', 0);
+ hidden('selected_id', $selected_id);
+ hidden('selected_id2', $selected_id2);
+ hidden('description', $_POST['description']);
+ hidden('deposit', $_POST['deposit']);
+ hidden('bank_only', $_POST['bank_only']);
+
+ submit_add_or_update_center2($selected_id2 == -1, '', true);
+
+ end_form();
+}
//------------------------------------------------------------------------------------
end_page();
//
function input_num($postname=null, $dflt=null)
{
- if (!isset($_POST[$postname]))
+ if (!isset($_POST[$postname]) || $_POST[$postname] == "")
return $dflt;
return user_numeric($_POST[$postname]);
//------------------------------------------------------------------------------------------------
-function quick_entries_list($name, $selected_id=null, $expense=true, $submit_on_change=false)
+function quick_entries_list($name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false)
{
- $sql = "SELECT * FROM ".TB_PREF."quick_entries";
+ $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";
combo_input($name, $selected_id, $sql, 'id', 'description',
array(
'spec_id' => '',
}
-function quick_entries_list_row($label, $name, $selected_id=null, $expense=true, $submit_on_change=false)
+function quick_entries_list_row($label, $name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false)
{
echo "<tr><td>$label</td><td>\n";
- quick_entries_list($name, $selected_id, $expense, $submit_on_change);
+ quick_entries_list($name, $selected_id, $expense, $bank_only, $submit_on_change);
echo "</td></tr>\n";
}
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',
+ `bank_only` tinyint(1) NOT NULL default '0',
+ PRIMARY KEY (`id`),
+ KEY `description` (`description`)
+) ENGINE=MyISAM AUTO_INCREMENT=1;
+
+INSERT INTO `0_quick_entries` VALUES ('1', 'Maintenance', '0', '1');
+INSERT INTO `0_quick_entries` VALUES ('2', 'Phone', '0', '1');
+INSERT INTO `0_quick_entries` VALUES ('3', 'Cash Sales', '1', '1');
+
+DROP TABLE IF EXISTS `0_quick_entry_lines`;
+
+CREATE TABLE `0_quick_entry_lines` (
+ `id` smallint(6) NOT NULL auto_increment,
+ `qid` smallint(6) NOT NULL,
+ `account` varchar(11) NOT NULL,
+ `tax_acc` tinyint(1) NOT NULL default '0',
+ `pct` tinyint(1) NOT NULL default '0',
+ `amount` double default NULL default '0',
+ `dimension_id` int(11) NOT NULL default '0',
+ `dimension2_id` int(11) NOT NULL default '0',
PRIMARY KEY (`id`),
- UNIQUE KEY `description` (`description`)
+ KEY `qid` (`qid`)
) 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');
+INSERT INTO `0_quick_entry_lines` VALUES ('1', '1', '6600', '1', '0', 0, '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('2', '2', '6730', '1', '0', 0, '0', '0');
+INSERT INTO `0_quick_entry_lines` VALUES ('3', '3', '3000', '1', '0', 0, '0', '0');
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` ;