2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function display_bank_header(&$order)
15 $payment = $order->trans_type == ST_BANKPAYMENT;
17 $customer_error = false;
18 div_start('pmt_header');
20 start_outer_table(TABLESTYLE2, "width=90%"); // outer table
24 date_row(_("Date:"), 'date_', '', true, 0, 0, 0, null, true);
26 ref_row(_("Reference:"), 'ref', '');
28 table_section(2, "33%");
30 if (!isset($_POST['PayType']))
32 if (isset($_GET['PayType']))
33 $_POST['PayType'] = $_GET['PayType'];
35 $_POST['PayType'] = "";
37 if (!isset($_POST['person_id']))
39 if (isset($_GET['PayPerson']))
40 $_POST['person_id'] = $_GET['PayPerson'];
42 $_POST['person_id'] = "";
44 if (isset($_POST['_PayType_update'])) {
45 $_POST['person_id'] = '';
46 $Ajax->activate('pmt_header');
47 $Ajax->activate('code_id');
48 $Ajax->activate('pagehelp');
49 $Ajax->activate('editors');
50 $Ajax->activate('footer');
52 payment_person_types_list_row( $payment ? _("Pay To:"):_("From:"),
53 'PayType', $_POST['PayType'], true);
54 switch ($_POST['PayType'])
57 text_row_ex($payment ?_("To the Order of:"):_("Name:"),
61 // workorders_list_row(_("Work Order:"), 'person_id', null);
64 supplier_list_row(_("Supplier:"), 'person_id', null, false, true, false, true);
67 customer_list_row(_("Customer:"), 'person_id', null, false, true, false, true);
69 if (db_customer_has_branches($_POST['person_id']))
71 customer_branches_list_row(_("Branch:"), $_POST['person_id'],
72 'PersonDetailID', null, false, true, true, true);
76 $_POST['PersonDetailID'] = ANY_NUMERIC;
77 hidden('PersonDetailID');
79 $trans = get_customer_habit($_POST['person_id']); // take care of customers on hold
80 if ($trans['dissallow_invoices'] != 0)
84 $customer_error = true;
85 display_error(_("This customer account is on hold."));
88 display_warning(_("This customer account is on hold."));
93 quick_entries_list_row(_("Type").":", 'person_id', null, ($payment ? QE_PAYMENT : QE_DEPOSIT), true);
94 $qid = get_quick_entry(get_post('person_id'));
95 if (list_updated('person_id')) {
96 unset($_POST['totamount']); // enable default
97 $Ajax->activate('footer');
98 $Ajax->activate('totamount');
100 amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
101 null, " ".submit('go', _("Go"), false, false, true));
103 //case payment_person_types::Project() :
104 // dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true);
108 table_section(3, "33%");
110 if (!$order->order_id && !get_post('bank_account'))
112 if ($_POST['PayType'] == PT_CUSTOMER)
113 $_POST['bank_account'] = get_default_customer_bank_account($_POST['person_id']);
114 elseif ($_POST['PayType'] == PT_SUPPLIER)
115 $_POST['bank_account'] = get_default_supplier_bank_account($_POST['person_id']);
117 unset($_POST['bank_account']);
120 bank_accounts_list_row( $payment ? _("From:") : _("Into:"), 'bank_account', null, true);
122 bank_balance_row($_POST['bank_account']);
124 $bank_currency = get_bank_account_currency($_POST['bank_account']);
126 exchange_rate_display(get_company_currency(), $bank_currency, $_POST['date_']);
128 end_outer_table(1); // outer table
138 //---------------------------------------------------------------------------------
140 function display_gl_items($title, &$order)
142 global $path_to_root;
144 $dim = get_company_pref('use_dimension');
145 $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
146 display_heading($title);
148 div_start('items_table');
149 start_table(TABLESTYLE, "colspan=7 width=95%");
152 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
153 _("Dimension")." 2", _("Amount"), _("Memo"), "");
155 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
156 _("Amount"), _("Memo"), "");
158 $th = array(_("Account Code"), _("Account Description"),
159 _("Amount"), _("Memo"), "");
161 if (count($order->gl_items)) $th[] = '';
164 $k = 0; //row colour counter
166 $id = find_submit('Edit');
167 foreach ($order->gl_items as $line => $item)
171 alt_table_row_color($k);
173 label_cell($item->code_id);
174 label_cell($item->description);
176 label_cell(get_dimension_string($item->dimension_id, true));
178 label_cell(get_dimension_string($item->dimension2_id, true));
179 //amount_cell(abs($item->amount));
180 if ($order->trans_type == ST_BANKDEPOSIT)
181 amount_cell(-$item->amount);
183 amount_cell($item->amount);
184 label_cell($item->reference);
186 edit_button_cell("Edit$line", _("Edit"),
187 _('Edit document line'));
188 delete_button_cell("Delete$line", _("Delete"),
189 _('Remove line from document'));
194 gl_edit_item_controls($order, $dim, $line);
199 gl_edit_item_controls($order, $dim);
201 if ($order->count_gl_items())
202 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right",3);
208 //---------------------------------------------------------------------------------
210 function gl_edit_item_controls(&$order, $dim, $Index=null)
213 $payment = $order->trans_type == ST_BANKPAYMENT;
216 $id = find_submit('Edit');
217 if ($Index != -1 && $Index == $id)
219 $item = $order->gl_items[$Index];
220 $_POST['code_id'] = $item->code_id;
221 $_POST['dimension_id'] = $item->dimension_id;
222 $_POST['dimension2_id'] = $item->dimension2_id;
223 $_POST['amount'] = price_format(abs($item->amount));
224 $_POST['description'] = $item->description;
225 $_POST['LineMemo'] = $item->reference;
227 hidden('Index', $id);
228 echo gl_all_accounts_list('code_id', null, true, true);
230 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
232 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
233 $Ajax->activate('items_table');
237 $_POST['amount'] = price_format(0);
238 $_POST['dimension_id'] = 0;
239 $_POST['dimension2_id'] = 0;
240 //$_POST['LineMemo'] = ""; // let memo go to next line Joe Hunt 2010-05-30
241 if(isset($_POST['_code_id_update'])) {
242 $Ajax->activate('code_id');
245 if ($_POST['PayType'] == PT_CUSTOMER)
247 $acc = get_branch_accounts($_POST['PersonDetailID']);
248 $_POST['code_id'] = $acc['receivables_account'];
250 elseif ($_POST['PayType'] == PT_SUPPLIER)
252 $acc = get_supplier_accounts($_POST['person_id']);
253 $_POST['code_id'] = $acc['payable_account'];
255 //elseif ($_POST['PayType'] == PT_WORKORDER)
256 // $_POST['code_id'] = get_company_pref('default_assembly_act');
259 get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
261 echo gl_all_accounts_list('code_id', null, true, true);
263 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
265 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
268 hidden('dimension_id', 0);
270 hidden('dimension2_id', 0);
272 amount_cells(null, 'amount');
273 text_cells_ex(null, 'LineMemo', 35, 255);
277 button_cell('UpdateItem', _("Update"),
278 _('Confirm changes'), ICON_UPDATE);
279 button_cell('CancelItemChanges', _("Cancel"),
280 _('Cancel changes'), ICON_CANCEL);
285 submit_cells('AddItem', _("Add Item"), "colspan=2",
286 _('Add new item to document'), true);
293 //---------------------------------------------------------------------------------
295 function gl_options_controls($order)
298 echo "<br><table align='center'>";
300 $type = get_post('PayType');
301 $bank_curr = get_bank_account_currency(get_post('bank_account'));
302 $person_curr = $type == PT_CUSTOMER ? get_customer_currency(get_post('person_id'))
303 : ($type == PT_SUPPLIER ? get_supplier_currency(get_post('person_id')) : $bank_curr);
305 if ($person_curr != $bank_curr)
307 $_POST['settled_amount'] =
308 price_format($order->gl_items_total() / get_exchange_rate_from_to($bank_curr, $person_curr, get_post('date_')));
309 amount_row($type == PT_CUSTOMER ? _("Settled AR Amount:") : _("Settled AP Amount:"),
310 'settled_amount', null, null, $person_curr, user_price_dec());
312 textarea_row(_("Memo"), 'memo_', null, 50, 3);
319 //---------------------------------------------------------------------------------