From: Joe Hunt Date: Sat, 15 Nov 2008 12:14:09 +0000 (+0000) Subject: Added Quick Entries in GL Journal Entry and changed some needed fixes. X-Git-Tag: v2.4.2~19^2~1748 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=5ddbc6107f4823f6b3629846aba63814bf958d38;p=fa-stable.git Added Quick Entries in GL Journal Entry and changed some needed fixes. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index b1ac91c3..d8119744 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,15 @@ Legend: ! -> Note $ -> Affected files +15-Nov-2008 Joe Hunt ++ Added Quick Entries in GL Journal Entry and changed some needed fixes. +$ /gl/gl_bank.php + /gl/gl_journal.php + /gl/includes/db/gl_db_bank_accounts.inc + /gl/includes/ui/gl_bank_ui.inc + /gl/includes/ui/gl_journal_ui.inc + /includes/ui/ui_lists.inc + 15-Nov-2008 Joe Hunt + Added Tax Inquiry in Banking and General Ledger tab. $ /applications/generalledger.php diff --git a/gl/gl_bank.php b/gl/gl_bank.php index b3f1c1b7..0df087b2 100644 --- a/gl/gl_bank.php +++ b/gl/gl_bank.php @@ -246,21 +246,7 @@ function handle_new_item() line_start_focus(); } -//----------------------------------------------------------------------------------------------- -$id = find_submit('Delete'); -if ($id != -1) - handle_delete_item($id); - -if (isset($_POST['AddItem'])) - handle_new_item(); - -if (isset($_POST['UpdateItem'])) - handle_update_item(); - -if (isset($_POST['CancelItemChanges'])) - line_start_focus(); - -if (isset($_POST['go'])) +function display_quick_entries(&$cart) { if (!check_num('totamount', 0)) { @@ -269,7 +255,7 @@ if (isset($_POST['go'])) } elseif (!get_post('person_id')) { - if ($_SESSION['pay_items']->trans_type==systypes::bank_payment()) + if ($cart->trans_type==systypes::bank_payment()) display_error( _("No Quick Entries are defined for Payment.")); else display_error( _("No Quick Entries are defined for Deposit.")); @@ -279,7 +265,7 @@ if (isset($_POST['go'])) { $rate = 0; $totamount = input_num('totamount'); - $totamount = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? 1:-1) * $totamount; + $totamount = ($cart->trans_type==systypes::bank_payment() ? 1:-1) * $totamount; $qe = get_quick_entry($_POST['person_id']); $qe_lines = get_quick_entry_lines($_POST['person_id']); while ($qe_line = db_fetch($qe_lines)) @@ -293,9 +279,9 @@ if (isset($_POST['go'])) $rate += $item['rate']; if ($rate != 0) $totamount = $totamount * 100 / ($rate + 100); - $_SESSION['pay_items']->clear_items(); + $cart->clear_items(); - $_SESSION['pay_items']->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], + $cart->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)) @@ -303,9 +289,9 @@ if (isset($_POST['go'])) if ($item['rate'] != 0) { $amount = $totamount * $item['rate'] / 100; - $code = ($_SESSION['pay_items']->trans_type==systypes::bank_payment() ? $item['purchasing_gl_code'] : + $code = ($cart->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']); + $cart->add_gl_item($code, 0, 0, $amount, $qe['description']); } } } @@ -315,13 +301,29 @@ if (isset($_POST['go'])) $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'], + $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], $amount, $qe['description']); } } line_start_focus(); } -} +} +//----------------------------------------------------------------------------------------------- +$id = find_submit('Delete'); +if ($id != -1) + handle_delete_item($id); + +if (isset($_POST['AddItem'])) + handle_new_item(); + +if (isset($_POST['UpdateItem'])) + handle_update_item(); + +if (isset($_POST['CancelItemChanges'])) + line_start_focus(); + +if (isset($_POST['go'])) + display_quick_entries($_SESSION['pay_items']); //----------------------------------------------------------------------------------------------- diff --git a/gl/gl_journal.php b/gl/gl_journal.php index 65d61c45..2cef81c8 100644 --- a/gl/gl_journal.php +++ b/gl/gl_journal.php @@ -214,6 +214,61 @@ function handle_new_item() line_start_focus(); } +function display_quick_entries(&$cart) +{ + if (!get_post('person_id')) + { + display_error( _("No Quick Entries are defined.")); + set_focus('totamount'); + } + else + { + $rate = 0; + $totamount = input_num('totamount'); + //$totamount = ($cart->trans_type==systypes::bank_payment() ? 1:-1) * $totamount; + $qe = get_quick_entry($_POST['person_id']); + $qe_lines = get_quick_entry_lines($_POST['person_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 = $totamount * 100 / ($rate + 100); + $cart->clear_items(); + + $cart->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 = ($amount < 0 ? $item['purchasing_gl_code'] : + $item['sales_gl_code']); + $cart->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']; + $cart->add_gl_item($qe_line['account'], $qe_line['dimension_id'], $qe_line['dimension2_id'], + $amount, $qe['description']); + } + } + line_start_focus(); + } +} + //----------------------------------------------------------------------------------------------- $id = find_submit('Delete'); if ($id != -1) @@ -228,6 +283,8 @@ if (isset($_POST['UpdateItem'])) if (isset($_POST['CancelItemChanges'])) line_start_focus(); +if (isset($_POST['go'])) + display_quick_entries($_SESSION['journal_items']); //----------------------------------------------------------------------------------------------- if (isset($_GET['NewJournal']) || !isset($_SESSION['journal_items'])) diff --git a/gl/includes/db/gl_db_bank_accounts.inc b/gl/includes/db/gl_db_bank_accounts.inc index 620b1bc3..2bb39707 100644 --- a/gl/includes/db/gl_db_bank_accounts.inc +++ b/gl/includes/db/gl_db_bank_accounts.inc @@ -119,16 +119,38 @@ function delete_quick_entry_line($selected_id) } //--------------------------------------------------------------------------------------------- -function get_quick_entries($deposit=null, $bank_only=null) + +function has_quick_entries($deposit=-1, $bank_only=-1) +{ + $where = false; + $sql = "SELECT id FROM ".TB_PREF."quick_entries"; + if ($deposit != -1) + { + $sql .= " WHERE deposit=$deposit"; + $where = true; + } + if ($bank_only != -1) + { + if ($where) + $sql .= " AND bank_only=$bank_only"; + else + $sql .= " WHERE bank_only=$bank_only"; + } + + $result = db_query($sql, "could not retreive quick entries"); + return db_num_rows($result) > 0; +} + +function get_quick_entries($deposit=-1, $bank_only=-1) { $where = false; $sql = "SELECT * FROM ".TB_PREF."quick_entries"; - if ($deposit != null) + if ($deposit != -1) { $sql .= " WHERE deposit=$deposit"; $where = true; } - if ($bank_only != null) + if ($bank_only != -1) { if ($where) $sql .= " AND bank_only=$bank_only"; diff --git a/gl/includes/ui/gl_bank_ui.inc b/gl/includes/ui/gl_bank_ui.inc index 303d557c..fa6a500f 100644 --- a/gl/includes/ui/gl_bank_ui.inc +++ b/gl/includes/ui/gl_bank_ui.inc @@ -68,7 +68,7 @@ function display_bank_header(&$order) } break; case payment_person_types::QuickEntry() : - quick_entries_list_row(_("Description:"), 'person_id', null, $payment); + 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)); break; //case payment_person_types::Project() : diff --git a/gl/includes/ui/gl_journal_ui.inc b/gl/includes/ui/gl_journal_ui.inc index a8878fcf..01a22ad3 100644 --- a/gl/includes/ui/gl_journal_ui.inc +++ b/gl/includes/ui/gl_journal_ui.inc @@ -9,8 +9,12 @@ function display_order_header(&$Order) { global $table_style2; + $qes = has_quick_entries(-1, 0); start_table("$table_style2 width=90%"); - echo ""; // outer table + if ($qes) + echo ""; // outer table + else + echo ""; // outer table echo ""; start_row(); @@ -20,13 +24,27 @@ function display_order_header(&$Order) echo "
"; - echo ""; // outer table + if ($qes) + echo ""; // outer table + else + echo ""; // outer table echo ""; - - check_row(_("Reverse Transaction:"), 'Reverse', null); - + start_row(); + check_cells(_("Reverse Transaction:"), 'Reverse', null); + end_row(); echo "
"; + if ($qes !== false) + { + echo ""; // outer table + echo ""; + 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)); + end_row(); + echo "
"; + } + echo ""; // outer table end_table(1); @@ -127,8 +145,16 @@ function gl_edit_item_controls(&$order, $dim, $Index=null) $_POST['code_id'] = $item->code_id; $_POST['dimension_id'] = $item->dimension_id; $_POST['dimension2_id'] = $item->dimension2_id; - $_POST['AmountDebit'] = price_format($item->amount); - $_POST['AmountCredit'] = price_format(abs($item->amount)); + if ($item->amount > 0) + { + $_POST['AmountDebit'] = price_format($item->amount); + $_POST['AmountCredit'] = ""; + } + else + { + $_POST['AmountDebit'] = ""; + $_POST['AmountCredit'] = price_format(abs($item->amount)); + } $_POST['description'] = $item->description; $_POST['LineMemo'] = $item->reference; diff --git a/includes/ui/ui_lists.inc b/includes/ui/ui_lists.inc index 4748136e..9c853473 100644 --- a/includes/ui/ui_lists.inc +++ b/includes/ui/ui_lists.inc @@ -1624,17 +1624,22 @@ function payment_person_types_list_row($label, $name, $selected_id=null, $relate //------------------------------------------------------------------------------------------------ -function quick_entries_list($name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false) +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) - $sql .= " WHERE deposit=0"; - else - $sql .= " WHERE deposit=1"; - if ($bank_only) - $sql .= " AND bank_only=1"; - else - $sql .= " AND bank_only=0"; + 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' => '', @@ -1645,11 +1650,18 @@ function quick_entries_list($name, $selected_id=null, $expense=true, $bank_only= } -function quick_entries_list_row($label, $name, $selected_id=null, $expense=true, $bank_only=true, $submit_on_change=false) +function quick_entries_list_cells($label, $name, $selected_id=null, $expense=-1, $bank_only=-1, $submit_on_change=false) { - echo "$label\n"; + echo "$label\n"; quick_entries_list($name, $selected_id, $expense, $bank_only, $submit_on_change); - echo "\n"; + 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"; }