From 33ba3d43d75c04080dd0d49067bafd2188fd04b1 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Thu, 22 Jan 2009 16:34:45 +0000 Subject: [PATCH] Improved quick entries. --- gl/gl_bank.php | 4 +- gl/gl_journal.php | 3 +- gl/includes/ui/gl_bank_ui.inc | 11 ++- gl/includes/ui/gl_journal_ui.inc | 13 ++- gl/manage/gl_quick_entries.php | 118 +++++++++++++++--------- includes/types.inc | 28 ++++++ includes/ui/items_cart.inc | 2 +- includes/ui/ui_lists.inc | 101 ++++++++++++--------- includes/ui/ui_view.inc | 125 ++++++++++++++------------ purchasing/includes/ui/invoice_ui.inc | 17 ++-- purchasing/supplier_credit.php | 3 +- purchasing/supplier_invoice.php | 3 +- sql/alter2.1.sql | 22 ++--- sql/en_US-demo.sql | 42 ++++----- sql/en_US-new.sql | 40 +++------ 15 files changed, 317 insertions(+), 215 deletions(-) diff --git a/gl/gl_bank.php b/gl/gl_bank.php index c40def6c..e5900142 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -105,7 +105,6 @@ function handle_new_order($type) { if (isset($_SESSION['pay_items'])) { - $_SESSION['pay_items']->clear_items(); unset ($_SESSION['pay_items']); } @@ -262,7 +261,8 @@ if (isset($_POST['CancelItemChanges'])) if (isset($_POST['go'])) { display_quick_entries($_SESSION['pay_items'], $_POST['person_id'], input_num('totamount'), - $_SESSION['pay_items']->trans_type==systypes::bank_payment()); + $_SESSION['pay_items']->trans_type==systypes::bank_payment() ? QE_PAYMENT : QE_DEPOSIT); + $_POST['totamount'] = price_format(0); $Ajax->activate('totamount'); line_start_focus(); } //----------------------------------------------------------------------------------------------- diff --git a/gl/gl_journal.php b/gl/gl_journal.php index 44b16f85..81f6332c 100644 --- a/gl/gl_journal.php +++ b/gl/gl_journal.php @@ -239,7 +239,8 @@ if (isset($_POST['CancelItemChanges'])) if (isset($_POST['go'])) { - display_quick_entries($_SESSION['journal_items'], $_POST['person_id'], input_num('totamount')); + display_quick_entries($_SESSION['journal_items'], $_POST['person_id'], input_num('totamount'), QE_JOURNAL); + $_POST['totamount'] = price_format(0); $Ajax->activate('totamount'); line_start_focus(); } //----------------------------------------------------------------------------------------------- diff --git a/gl/includes/ui/gl_bank_ui.inc b/gl/includes/ui/gl_bank_ui.inc index 5f95c3df..5239dc9a 100644 --- a/gl/includes/ui/gl_bank_ui.inc +++ b/gl/includes/ui/gl_bank_ui.inc @@ -72,9 +72,16 @@ function display_bank_header(&$order) hidden('PersonDetailID'); } break; + case payment_person_types::QuickEntry() : - quick_entries_list_row(_("Description:"), 'person_id', null, ($payment ? 0 : 1), 1); - amount_row(_("Total Amount"), 'totamount', null, null, "  ".submit('go', _("Go"), false, false, true)); + quick_entries_list_row(_("Type").":", 'person_id', null, ($payment ? QE_PAYMENT : QE_DEPOSIT), true); + $qid = get_quick_entry(get_post('person_id')); + if (list_updated('person_id')) { + unset($_POST['totamount']); // enable default + $Ajax->activate('totamount'); + } + amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']), + null, "  ".submit('go', _("Go"), false, false, true)); break; //case payment_person_types::Project() : // dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true); diff --git a/gl/includes/ui/gl_journal_ui.inc b/gl/includes/ui/gl_journal_ui.inc index bae82d3b..1a2a9b4e 100644 --- a/gl/includes/ui/gl_journal_ui.inc +++ b/gl/includes/ui/gl_journal_ui.inc @@ -18,7 +18,7 @@ function display_order_header(&$Order) { global $table_style2; - $qes = has_quick_entries(-1, 0); + $qes = has_quick_entries(QE_JOURNAL); start_outer_table("$table_style2 width=90%"); table_section(1); @@ -40,9 +40,16 @@ function display_order_header(&$Order) { table_section(3, "50%"); start_row(); - quick_entries_list_cells(_("Quick Entry:"), 'person_id', null, -1, 0); - amount_cells(_("Total Amount"), 'totamount', null, null, "  ".submit('go', _("Go"), false, false, true)); + quick_entries_list_cells(_("Quick Entry").":", 'person_id', null, QE_JOURNAL, true); + $qid = get_quick_entry(get_post('person_id')); + if (list_updated('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)); end_row(); + } end_outer_table(1); diff --git a/gl/manage/gl_quick_entries.php b/gl/manage/gl_quick_entries.php index c042c213..e797cc8c 100644 --- a/gl/manage/gl_quick_entries.php +++ b/gl/manage/gl_quick_entries.php @@ -74,6 +74,12 @@ function can_process() set_focus('description'); return false; } + if (strlen($_POST['base_desc']) == 0) + { + display_error( _("The base amount description cannot be empty.")); + set_focus('base_desc'); + return false; + } return true; } @@ -88,12 +94,14 @@ if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') if ($selected_id != -1) { - update_quick_entry($selected_id, $_POST['description'], $_POST['deposit'], $_POST['bank_only']); + update_quick_entry($selected_id, $_POST['description'], $_POST['type'], + input_num('base_amount'), $_POST['base_desc']); display_notification(_('Selected quick entry has been updated')); } else { - add_quick_entry($_POST['description'], $_POST['deposit'], $_POST['bank_only']); + add_quick_entry($_POST['description'], $_POST['type'], + input_num('base_amount'), $_POST['base_desc']); display_notification(_('New quick entry has been added')); } $Mode = 'RESET'; @@ -104,13 +112,13 @@ 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), + update_quick_entry_line($selected_id2, $selected_id, $_POST['actn'], $_POST['dest_id'], 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), + add_quick_entry_line($selected_id, $_POST['actn'], $_POST['dest_id'], input_num('amount', 0), $_POST['dimension_id'], $_POST['dimension2_id']); display_notification(_('New quick entry line has been added')); } @@ -144,36 +152,37 @@ if ($Mode2 == 'BDel') if ($Mode == 'RESET') { $selected_id = -1; - $_POST['description'] = $_POST['deposit'] = $_POST['bank_only'] = ''; + $_POST['description'] = $_POST['type'] = ''; + $_POST['base_desc']= _('Base Amount'); + $_POST['base_amount'] = price_format(0); } if ($Mode2 == 'RESET2') { $selected_id2 = -1; - $_POST['account'] = $_POST['tax_acc'] = $_POST['pct'] = $_POST['amount'] = $_POST['dimension_id'] = $_POST['dimension2_id'] = ''; + $_POST['actn'] = $_POST['dest_id'] = $_POST['amount'] = + $_POST['dimension_id'] = $_POST['dimension2_id'] = ''; } //----------------------------------------------------------------------------------- $result = get_quick_entries(); start_form(); start_table($table_style); -$th = array(_("Description"), _("Deposit"), _("Bank Only"), "", ""); +$th = array(_("Description"), _("Type"), "", ""); table_header($th); $k = 0; while ($myrow = db_fetch($result)) { alt_table_row_color($k); - $deposit_text = ($myrow["deposit"] == 0 ? _("No") : _("Yes")); - $bank_text = ($myrow["bank_only"] == 0 ? _("No") : _("Yes")); + $type_text = $quick_entry_types[$myrow["type"]]; label_cell($myrow['description']); - label_cell($deposit_text); - label_cell($bank_text); + label_cell($type_text); edit_button_cell("Edit".$myrow["id"], _("Edit")); delete_button_cell("Delete".$myrow["id"], _("Delete")); end_row(); } -end_table(); +end_table(1); end_form(); //----------------------------------------------------------------------------------- @@ -190,17 +199,20 @@ if ($selected_id != -1) $_POST['id'] = $myrow["id"]; $_POST['description'] = $myrow["description"]; - $_POST['deposit'] = $myrow["deposit"]; - $_POST['bank_only'] = $myrow["bank_only"]; + $_POST['deposit'] = $myrow["type"]; + $_POST['base_desc'] = $myrow["base_desc"]; + $_POST['base_amount'] = price_format($myrow["base_amount"]); hidden('selected_id', $selected_id); //} } -text_row_ex(_("Description:"), 'description', 50, 60); +text_row_ex(_("Description").':', 'description', 50, 60); + +quick_entry_types_list_row(_("Entry Type").':', 'type'); -yesno_list_row(_("Deposit:"), 'deposit', null, "", "", false); +text_row_ex(_("Base Amount Description").':', 'base_desc', 50, 60, '',_('Base Amount')); -yesno_list_row(_("Bank Only:"), 'bank_only', null, "", "", false); +amount_row(_("Default Base Amount").':', 'base_amount', price_format(0)); end_table(1); @@ -208,6 +220,7 @@ submit_add_or_update_center($selected_id == -1, '', true); end_form(); + if ($selected_id != -1) { display_heading(_("Quick Entry Lines") . " - " . $_POST['description']); @@ -216,22 +229,34 @@ if ($selected_id != -1) start_table($table_style2); $dim = get_company_pref('use_dimension'); if ($dim == 2) - $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", ""); + $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), _("Dimension")." 2", "", ""); else if ($dim == 1) - $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), _("Dimension"), "", ""); + $th = array(_("Post"), _("Account/Tax Type"), _("Amount"), _("Dimension"), "", ""); else - $th = array(_("Account"), _("Use Tax"), _("Percent"), _("Amount"), "", ""); + $th = array(_("Post"), _("Account/Tax Type"), _("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']); + + label_cell($quick_actions[$myrow['action']]); + + $act_type = strtolower(substr($myrow['action'], 0, 1)); + + if ($act_type == 't') { + label_cells($myrow['tax_name'], ''); + } else { + label_cell($myrow['dest_id'].' '.$myrow['account_name']); + if ($act_type == '=') + label_cell(''); + else + if ($act_type == '%') + percent_cell($myrow['amount']); + else + amount_cell($myrow['amount']); + } if ($dim >= 1) label_cell(get_dimension_string($myrow['dimension_id'], true)); if ($dim > 1) @@ -240,15 +265,15 @@ if ($selected_id != -1) delete_button_cell("BDel".$myrow["id"], _("Delete")); end_row(); } - end_table(); + end_table(1); hidden('selected_id', $selected_id); hidden('selected_id2', $selected_id2); hidden('description', $_POST['description']); - hidden('deposit', $_POST['deposit']); - hidden('bank_only', $_POST['bank_only']); + hidden('type', $_POST['type']); end_form(); start_form(); + div_start('edit_line'); start_table($table_style2); if ($selected_id2 != -1) @@ -259,34 +284,47 @@ if ($selected_id != -1) $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['dest_id'] = $myrow["dest_id"]; + $_POST['actn'] = $myrow["action"]; $_POST['amount'] = $myrow["amount"]; $_POST['dimension_id'] = $myrow["dimension_id"]; $_POST['dimension2_id'] = $myrow["dimension2_id"]; } } - gl_all_accounts_list_row(_("Account"), 'account', null); - yesno_list_row(_("Use Tax:"), 'tax_acc', null, "", "", false); - yesno_list_row(_("Use Percent:"), 'pct', null, "", "", false); - amount_row(_("Amount"), 'amount', null); + quick_actions_list_row(_("Posted").":",'actn', null, true); + if (list_updated('actn')) + $Ajax->activate('edit_line'); + + $actn = strtolower(substr($_POST['actn'],0,1)); + + if ($actn == 't') { + item_tax_types_list_row(_("Item Tax Type").":",'dest_id', null); + } else { + gl_all_accounts_list_row(_("Account").":", 'dest_id', null); + if ($actn != '=') { + if ($actn = '%') + percent_row(_("Part").":", 'amount', percent_format(0)); + else + amount_row(_("Amount").":", 'amount', price_format(0)); + } + } if ($dim >= 1) - dimensions_list_row(_("Dimension"), 'dimension_id', null, true, " ", false, 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); + 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); + div_end(); + hidden('selected_id', $selected_id); hidden('selected_id2', $selected_id2); hidden('description', $_POST['description']); - hidden('deposit', $_POST['deposit']); - hidden('bank_only', $_POST['bank_only']); + hidden('type', $_POST['type']); submit_add_or_update_center2($selected_id2 == -1, '', true); diff --git a/includes/types.inc b/includes/types.inc index 9003eceb..4cde8738 100644 --- a/includes/types.inc +++ b/includes/types.inc @@ -300,5 +300,33 @@ class wo_types } } +$quick_actions = array( + '=' => _('Remainder'), // post current base amount to GL account + '-' => _('Amount, reduce base'), // post amount to GL account and reduce base + '+' => _('Amount, increase base'), // post amount to GL account and increase base + '%' => _('% amount of base'), // store acc*amount% to GL account + '%+' => _('% amount of base, increase base'), // ditto & increase base amount + '%-' => _('% amount of base, reduce base'), // ditto & reduce base amount + 'T' => _('Taxes added'), // post taxes calculated on base amount + 'T+' => _('Taxes added, increase base'), // ditto & increase base amount + 'T-' => _('Taxes added, reduce base'), // ditto & reduce base amount + 't' => _('Taxes included'), // post taxes calculated on base amount + 't+' => _('Taxes included, increase base'), // ditto & increase base amount + 't-' => _('Taxes included, reduce base') // ditto & reduce base amount +); + +define('QE_DEPOSIT', '1'); +define('QE_PAYMENT', '2'); +define('QE_JOURNAL', '3'); +define('QE_SUPPINV', '4'); + +$quick_entry_types = array( + QE_DEPOSIT => _("Bank Deposit"), + QE_PAYMENT => _("Bank Payment"), + QE_JOURNAL => _("Journal Entry"), + QE_SUPPINV => _("Supplier Invoice/Credit") +); + + ?> \ No newline at end of file diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index a2d3e2d2..66a17fea 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -101,7 +101,7 @@ class items_cart else { // shouldn't come here under normal circumstances - display_db_error("unexpected - adding an invalid item or null quantity", "", true); + display_db_error("unexpected - invalid parameters in add_gl_item($code_id, $dimension_id, $dimension2_id, $amount,...)", "", true); } return false; diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 52475c4e..46194019 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -1715,49 +1715,6 @@ function payment_person_types_list_row($label, $name, $selected_id=null, $relate return $str; } -//------------------------------------------------------------------------------------------------ - -function quick_entries_list($name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false) -{ - $where = false; - $sql = "SELECT id, description FROM ".TB_PREF."quick_entries"; - if ($expense != -1) - { - $sql .= " WHERE deposit=$expense"; - $where = true; - } - if ($bank_only != -1) - { - if ($where) - $sql .= " AND bank_only=$bank_only"; - else - $sql .= " WHERE bank_only=$bank_only"; - } - combo_input($name, $selected_id, $sql, 'id', 'description', - array( - 'spec_id' => '', - 'order' => 'description', - 'select_submit'=> $submit_on_change, - 'async' => false - ) ); - -} - -function quick_entries_list_cells($label, $name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false) -{ - echo "$label\n"; - quick_entries_list($name, $selected_id, $expense, $bank_only, $submit_on_change); - echo ""; -} - -function quick_entries_list_row($label, $name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false) -{ - echo "\n"; - quick_entries_list_cells($label, $name, $selected_id, $expense, $bank_only, $submit_on_change); - echo "\n"; -} - - //------------------------------------------------------------------------------------------------ function wo_types_list($name, $selected_id=null) @@ -2040,5 +1997,63 @@ function printers_list($name, $selected_id=null, $spec_opt=false, $submit_on_cha )); } +//------------------------------------------------------------------------------------------------ + +function quick_entries_list($name, $selected_id=null, $type=null, $submit_on_change=false) +{ + $where = false; + $sql = "SELECT id, description FROM ".TB_PREF."quick_entries"; + if ($type != null) + $sql .= " WHERE type=$type"; + + combo_input($name, $selected_id, $sql, 'id', 'description', + array( + 'spec_id' => '', + 'order' => 'description', + 'select_submit'=> $submit_on_change, + 'async' => false + ) ); + +} + +function quick_entries_list_cells($label, $name, $selected_id=null, $type, $submit_on_change=false) +{ + echo "$label\n"; + quick_entries_list($name, $selected_id, $type, $submit_on_change); + echo ""; +} + +function quick_entries_list_row($label, $name, $selected_id=null, $type, $submit_on_change=false) +{ + echo "\n"; + quick_entries_list_cells($label, $name, $selected_id, $type, $submit_on_change); + echo "\n"; +} + + +function quick_actions_list_row($label, $name, $selected_id=null, $submit_on_change=false) +{ + global $quick_actions; + + echo "$label"; + array_selector($name, $selected_id, $quick_actions, + array( + 'select_submit'=> $submit_on_change + ) ); + echo "\n"; +} + +function quick_entry_types_list_row($label, $name, $selected_id=null, $submit_on_change=false) +{ + global $quick_entry_types; + + echo "$label"; + array_selector($name, $selected_id, $quick_entry_types, + array( + 'select_submit'=> $submit_on_change + ) ); + echo "\n"; +} + ?> \ No newline at end of file diff --git a/includes/ui/ui_view.inc b/includes/ui/ui_view.inc index cee877d5..0de82dfe 100644 --- a/includes/ui/ui_view.inc +++ b/includes/ui/ui_view.inc @@ -548,8 +548,14 @@ function display_allocations_from($person_type, $person_id, $type, $type_no, $to } //-------------------------------------------------------------------------------------- -function display_quick_entries(&$cart, $id, $totamount, $payment=true, $supp_trans=false) +// +// Expands selected quick entry $id into GL posings and adds to cart. +// returns calculated amount posted to bank GL account. +// +function display_quick_entries(&$cart, $id, $base, $type, $descr='') { + $bank_amount = 0; + if (!isset($id) || $id == null || $id == "") { display_error( _("No Quick Entries are defined.")); @@ -557,71 +563,80 @@ function display_quick_entries(&$cart, $id, $totamount, $payment=true, $supp_tra } else { - $rate = 0; - if (!$payment) - $totamount = -$totamount; - if (!$supp_trans) + if ($type == QE_DEPOSIT) + $base = -$base; + if ($type != QE_SUPPINV) // only one quick entry on journal/bank transaction $cart->clear_items(); $qe = get_quick_entry($id); + if ($descr != '') $qe['description'] .= ': '.$descr; $qe_lines = get_quick_entry_lines($id); while ($qe_line = db_fetch($qe_lines)) { - if ($qe_line['tax_acc']) - { - $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 = round2($totamount * 100 / ($rate + 100), user_price_dec()); - //$cart->clear_items(); - if (!$supp_trans) - $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], - $totamount, $qe['description']); - else - { - $acc_name = get_gl_account_name($qe_line['account']); - $cart->add_gl_codes_to_trans($qe_line['account'], $acc_name, $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 = round2($totamount * $item['rate'] / 100, user_price_dec()); - $code = (($amount < 0 || $payment || $supp_trans) ? $item['purchasing_gl_code'] : - $item['sales_gl_code']); - if (!$supp_trans) - $cart->add_gl_item($code, 0, 0, $amount, $qe['description']); + switch (strtolower($qe_line['action'])) { + case "=": // post current base amount to GL account + $part = $base; + break; + case "-": // post amount to GL account and reduce base + $part = $qe_line['amount']; $base -= $part; + break; + case "+": // post amount to GL account and increase base + $part = $qe_line['amount']; $base += $part; + break; + case "%": // store acc*amount% to GL account + $part = round2($base * $qe_line['amount'] / 100, user_price_dec()); + break; + case "%+": // ditto & increase base amount + $part = round2($base * $qe_line['amount'] / 100, user_price_dec()); + $base += $part; + break; + case "%-": // ditto & reduce base amount + $part = round2($base * $qe_line['amount'] / 100, user_price_dec()); + $base -= $part; + break; + case "t": // post taxes calculated on base amount + case "t+": // ditto & increase base amount + case "t-": // ditto & reduce base amount + $taxes = get_taxes_for_item_tax($qe_line['dest_id']); + $tax_total = 0; + foreach ($taxes as $index => $item_tax) { + if(substr($qe_line['action'],0,1) != 'T') + $tax = round($base * $item_tax['rate'] + / ($item_tax['rate'] + 100), user_price_dec()); else - { - $acc_name = get_gl_account_name($code); - $cart->add_gl_codes_to_trans($code, $acc_name, 0, 0, $amount, $qe['description']); + $tax = round($base * $item_tax['rate'] / 100, user_price_dec()); + + $gl_code = $type != QE_DEPOSIT + ? $item_tax['purchasing_gl_code'] : $item_tax['sales_gl_code']; + $tax_total += $tax; + if ($type != QE_SUPPINV) + $cart->add_gl_item($gl_code, + $qe_line['dimension_id'], $qe_line['dimension2_id'], + $tax, $qe['description']); + else { + $acc_name = get_gl_account_name($gl_code); + $cart->add_gl_codes_to_trans($gl_code, + $acc_name, $qe_line['dimension_id'], + $qe_line['dimension2_id'], $tax, $qe['description']); } } - } + if (strpos($qe_line['action'], '+')) + $base += $tax_total; + elseif (strpos($qe_line['action'], '-')) + $base -= $tax_total; + continue 2; + } + if ($type != QE_SUPPINV) + $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'], + $qe_line['dimension2_id'], $part, $qe['description']); + else { + $acc_name = get_gl_account_name($qe_line['dest_id']); + $cart->add_gl_codes_to_trans($qe_line['dest_id'], + $acc_name, $qe_line['dimension_id'], + $qe_line['dimension2_id'], $part, $qe['description']); } - else - { - if ($qe_line['pct']) - $amount = round2($totamount * $qe_line['amount'] / 100, user_price_dec()); - else - $amount = $qe_line['amount']; - if (!$supp_trans) - $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], - $amount, $qe['description']); - else - { - $acc_name = get_gl_account_name($qe_line['account']); - $cart->add_gl_codes_to_trans($qe_line['account'], $acc_name, $qe_line['dimension_id'], - $qe_line['dimension2_id'], $amount, $qe['description']); - } - } } - //line_start_focus(); } + return $bank_amount; } diff --git a/purchasing/includes/ui/invoice_ui.inc b/purchasing/includes/ui/invoice_ui.inc index 116dee3c..2e2d17cc 100644 --- a/purchasing/includes/ui/invoice_ui.inc +++ b/purchasing/includes/ui/invoice_ui.inc @@ -195,7 +195,7 @@ function display_gl_controls(&$supp_trans, $k) function display_gl_items(&$supp_trans, $mode=0) { - global $table_style, $path_to_root; + global $table_style, $path_to_root, $Ajax; // if displaying in form, and no items, exit if (($mode == 2 || $mode == 3) && count($supp_trans->gl_codes) == 0) @@ -212,18 +212,25 @@ function display_gl_items(&$supp_trans, $mode=0) if ($mode == 1) { - $qes = has_quick_entries(-1, 0); + $qes = has_quick_entries(QE_SUPPINV); if ($qes !== false) { echo "
"; echo _("Quick Entry:")." "; - quick_entries_list('qid', null, 0, 1); - echo " "._("Amount")." "; - $amount = input_num('totamount'); + quick_entries_list('qid', null, QE_SUPPINV, true); + $qid = get_quick_entry(get_post('qid')); + if (list_updated('qid')) { + unset($_POST['totamount']); // enable default + $Ajax->activate('totamount'); + } + echo " ".$qid['base_desc'].":"." "; + + $amount = input_num('totamount', $qid['base_amount']); $dec = user_price_dec(); echo " "; submit('go', _("Go"), true, false, true); echo "
"; + } } display_heading($heading); diff --git a/purchasing/supplier_credit.php b/purchasing/supplier_credit.php index 00a8cd5e..45f7a6ca 100644 --- a/purchasing/supplier_credit.php +++ b/purchasing/supplier_credit.php @@ -311,7 +311,8 @@ if (isset($_POST['RefreshInquiry'])) if (isset($_POST['go'])) { $Ajax->activate('gl_items'); - display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), true, true); + display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), QE_SUPPINV); + $_POST['totamount'] = price_format(0); $Ajax->activate('totamount'); $Ajax->activate('inv_tot'); } diff --git a/purchasing/supplier_invoice.php b/purchasing/supplier_invoice.php index 6dcd5cba..52ce2f7b 100644 --- a/purchasing/supplier_invoice.php +++ b/purchasing/supplier_invoice.php @@ -379,7 +379,8 @@ if ($_SESSION["wa_current_user"]->access == 2) if (isset($_POST['go'])) { $Ajax->activate('gl_items'); - display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), true, true); + display_quick_entries($_SESSION['supp_trans'], $_POST['qid'], input_num('totamount'), QE_SUPPINV); + $_POST['totamount'] = price_format(0); $Ajax->activate('totamount'); $Ajax->activate('inv_tot'); } diff --git a/sql/alter2.1.sql b/sql/alter2.1.sql index fcb785c3..8e5b45f1 100644 --- a/sql/alter2.1.sql +++ b/sql/alter2.1.sql @@ -104,35 +104,35 @@ DROP TABLE IF EXISTS `0_quick_entries`; CREATE TABLE `0_quick_entries` ( `id` smallint(6) UNSIGNED NOT NULL auto_increment, + `type` tinyint(1) NOT NULL default '0', `description` varchar(60) NOT NULL, - `deposit` tinyint(1) NOT NULL default '0', - `bank_only` tinyint(1) NOT NULL default '0', + `base_amount` double NOT NULL default '0', + `base_desc` varchar(60) NULL, PRIMARY KEY (`id`), KEY `description` (`description`) ) TYPE=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'); +INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount'); +INSERT INTO `0_quick_entries` VALUES ('2', '1', 'Phone', '0', 'Amount'); +INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount'); DROP TABLE IF EXISTS `0_quick_entry_lines`; CREATE TABLE `0_quick_entry_lines` ( `id` smallint(6) UNSIGNED NOT NULL auto_increment, `qid` smallint(6) UNSIGNED 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', + `action` varchar(2) NOT NULL, + `dest_id` varchar(11) NOT NULL, `dimension_id` smallint(6) UNSIGNED NULL default NULL, `dimension2_id` smallint(6) UNSIGNED NULL default NULL, PRIMARY KEY (`id`), KEY `qid` (`qid`) ) TYPE=MyISAM AUTO_INCREMENT=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'); +INSERT INTO `0_quick_entry_lines` VALUES ('1', '1','0','=', '6600', '0', '0'); +INSERT INTO `0_quick_entry_lines` VALUES ('2', '2','0','=', '6730', '0', '0'); +INSERT INTO `0_quick_entry_lines` VALUES ('3', '3','0','=', '3000', '0', '0'); ALTER TABLE `0_users` DROP COLUMN `print_profile`; ALTER TABLE `0_users` ADD `print_profile` VARCHAR(30) NOT NULL DEFAULT '1'; diff --git a/sql/en_US-demo.sql b/sql/en_US-demo.sql index f2f89ab8..b13b4d13 100644 --- a/sql/en_US-demo.sql +++ b/sql/en_US-demo.sql @@ -1472,51 +1472,47 @@ INSERT INTO `0_purch_orders` VALUES ('12', '0', '4', '', '2008-03-25', '13', '', INSERT INTO `0_purch_orders` VALUES ('13', '0', '4', '', '2008-03-25', '14', '', 'DEF', 'N/A'); INSERT INTO `0_purch_orders` VALUES ('14', '0', '1', '', '2009-01-10', '15', '', 'CWA', 'address'); - ### Structure of table `0_quick_entries` ### DROP TABLE IF EXISTS `0_quick_entries`; CREATE TABLE `0_quick_entries` ( - `id` smallint(6) unsigned NOT NULL auto_increment, + `id` smallint(6) UNSIGNED NOT NULL auto_increment, + `type` tinyint(1) NOT NULL default '0', `description` varchar(60) NOT NULL, - `deposit` tinyint(1) NOT NULL default '0', - `bank_only` tinyint(1) NOT NULL default '0', + `base_amount` double NOT NULL default '0', + `base_desc` varchar(60) NULL, PRIMARY KEY (`id`), KEY `description` (`description`) -) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; - +) TYPE=MyISAM AUTO_INCREMENT=1; ### Data of table `0_quick_entries` ### -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'); - +INSERT INTO `0_quick_entries` VALUES ('1', '1', 'Maintenance', '0', 'Amount'); +INSERT INTO `0_quick_entries` VALUES ('2', '1', 'Phone', '0', 'Amount'); +INSERT INTO `0_quick_entries` VALUES ('3', '2', 'Cash Sales', '0', 'Amount'); ### Structure of table `0_quick_entry_lines` ### DROP TABLE IF EXISTS `0_quick_entry_lines`; CREATE TABLE `0_quick_entry_lines` ( - `id` smallint(6) unsigned NOT NULL auto_increment, - `qid` smallint(6) unsigned 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 '0', - `dimension_id` smallint(6) unsigned default NULL, - `dimension2_id` smallint(6) unsigned default NULL, + `id` smallint(6) UNSIGNED NOT NULL auto_increment, + `qid` smallint(6) UNSIGNED NOT NULL, + `amount` double default NULL default '0', + `action` varchar(2) NOT NULL, + `dest_id` varchar(11) NOT NULL, + `dimension_id` smallint(6) UNSIGNED NULL default NULL, + `dimension2_id` smallint(6) UNSIGNED NULL default NULL, PRIMARY KEY (`id`), KEY `qid` (`qid`) -) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; - +) TYPE=MyISAM AUTO_INCREMENT=1; ### Data of table `0_quick_entry_lines` ### -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'); +INSERT INTO `0_quick_entry_lines` VALUES ('1', '1','0','=', '6600', '0', '0'); +INSERT INTO `0_quick_entry_lines` VALUES ('2', '2','0','=', '6730', '0', '0'); +INSERT INTO `0_quick_entry_lines` VALUES ('3', '3','0','=', '3000', '0', '0'); ### Structure of table `0_recurrent_invoices` ### diff --git a/sql/en_US-new.sql b/sql/en_US-new.sql index 91905a1e..68facba4 100644 --- a/sql/en_US-new.sql +++ b/sql/en_US-new.sql @@ -973,54 +973,40 @@ CREATE TABLE `0_purch_orders` ( ### Data of table `0_purch_orders` ### - - ### Structure of table `0_quick_entries` ### DROP TABLE IF EXISTS `0_quick_entries`; CREATE TABLE `0_quick_entries` ( - `id` smallint(6) unsigned NOT NULL auto_increment, + `id` smallint(6) UNSIGNED NOT NULL auto_increment, + `type` tinyint(1) NOT NULL default '0', `description` varchar(60) NOT NULL, - `deposit` tinyint(1) NOT NULL default '0', - `bank_only` tinyint(1) NOT NULL default '0', + `base_amount` double NOT NULL default '0', + `base_desc` varchar(60) NULL, PRIMARY KEY (`id`), KEY `description` (`description`) -) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; - +) TYPE=MyISAM AUTO_INCREMENT=1; ### Data of table `0_quick_entries` ### -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'); - - ### Structure of table `0_quick_entry_lines` ### DROP TABLE IF EXISTS `0_quick_entry_lines`; CREATE TABLE `0_quick_entry_lines` ( - `id` smallint(6) unsigned NOT NULL auto_increment, - `qid` smallint(6) unsigned 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 '0', - `dimension_id` smallint(6) unsigned default NULL, - `dimension2_id` smallint(6) unsigned default NULL, + `id` smallint(6) UNSIGNED NOT NULL auto_increment, + `qid` smallint(6) UNSIGNED NOT NULL, + `amount` double default NULL default '0', + `action` varchar(2) NOT NULL, + `dest_id` varchar(11) NOT NULL, + `dimension_id` smallint(6) UNSIGNED NULL default NULL, + `dimension2_id` smallint(6) UNSIGNED NULL default NULL, PRIMARY KEY (`id`), KEY `qid` (`qid`) -) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; - +) TYPE=MyISAM AUTO_INCREMENT=1; ### Data of table `0_quick_entry_lines` ### -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'); - - ### Structure of table `0_recurrent_invoices` ### DROP TABLE IF EXISTS `0_recurrent_invoices`; -- 2.30.2