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)
14 global $table_style2, $Ajax, $Refs;
15 $payment = $order->trans_type == ST_BANKPAYMENT;
17 div_start('pmt_header');
19 start_outer_table("width=90% $table_style2"); // outer table
23 bank_accounts_list_row( $payment ? _("From:") : _("To:"), 'bank_account', null, true);
25 date_row(_("Date:"), 'date_', '', true, 0, 0, 0, null, true);
27 table_section(2, "33%");
29 if (!isset($_POST['PayType']))
31 if (isset($_GET['PayType']))
32 $_POST['PayType'] = $_GET['PayType'];
34 $_POST['PayType'] = "";
36 if (!isset($_POST['person_id']))
38 if (isset($_GET['PayPerson']))
39 $_POST['person_id'] = $_GET['PayPerson'];
41 $_POST['person_id'] = "";
43 if (isset($_POST['_PayType_update'])) {
44 $_POST['person_id'] = '';
45 $Ajax->activate('pmt_header');
46 $Ajax->activate('code_id');
47 $Ajax->activate('pagehelp');
48 $Ajax->activate('editors');
50 payment_person_types_list_row( $payment ? _("Pay To:"):_("From:"),
51 'PayType', $_POST['PayType'], true);
52 switch ($_POST['PayType'])
55 text_row_ex($payment ?_("To the Order of:"):_("Name:"),
59 // workorders_list_row(_("Work Order:"), 'person_id', null);
62 supplier_list_row(_("Supplier:"), 'person_id', null, false, true, false, true);
65 customer_list_row(_("Customer:"), 'person_id', null, false, true, false, true);
67 if (db_customer_has_branches($_POST['person_id']))
69 customer_branches_list_row(_("Branch:"), $_POST['person_id'],
70 'PersonDetailID', null, false, true, true, true);
74 $_POST['PersonDetailID'] = ANY_NUMERIC;
75 hidden('PersonDetailID');
80 quick_entries_list_row(_("Type").":", 'person_id', null, ($payment ? QE_PAYMENT : QE_DEPOSIT), true);
81 $qid = get_quick_entry(get_post('person_id'));
82 if (list_updated('person_id')) {
83 unset($_POST['totamount']); // enable default
84 $Ajax->activate('totamount');
86 amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
87 null, " ".submit('go', _("Go"), false, false, true));
89 //case payment_person_types::Project() :
90 // dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true);
94 $person_currency = payment_person_currency($_POST['PayType'], $_POST['person_id']);
95 $bank_currency = get_bank_account_currency($_POST['bank_account']);
97 exchange_rate_display($bank_currency, $person_currency, $_POST['date_']);
99 table_section(3, "33%");
101 if (isset($_GET['NewPayment']))
102 ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_BANKPAYMENT));
104 ref_row(_("Reference:"), 'ref', '', $Refs->get_next(ST_BANKDEPOSIT));
106 end_outer_table(1); // outer table
110 //---------------------------------------------------------------------------------
112 function display_gl_items($title, &$order)
114 global $table_style, $path_to_root;
116 $dim = get_company_pref('use_dimension');
117 $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
118 display_heading($title);
120 div_start('items_table');
121 start_table("$table_style colspan=7 width=95%");
124 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
125 _("Dimension")." 2", _("Amount"), _("Memo"), "");
127 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
128 _("Amount"), _("Memo"), "");
130 $th = array(_("Account Code"), _("Account Description"),
131 _("Amount"), _("Memo"), "");
133 if (count($order->gl_items)) $th[] = '';
136 $k = 0; //row colour counter
138 $id = find_submit('Edit');
139 foreach ($order->gl_items as $line => $item)
143 alt_table_row_color($k);
145 label_cell($item->code_id);
146 label_cell($item->description);
148 label_cell(get_dimension_string($item->dimension_id, true));
150 label_cell(get_dimension_string($item->dimension2_id, true));
151 //amount_cell(abs($item->amount));
152 if ($order->trans_type == ST_BANKDEPOSIT)
153 amount_cell(-$item->amount);
155 amount_cell($item->amount);
156 label_cell($item->reference);
158 edit_button_cell("Edit$line", _("Edit"),
159 _('Edit document line'));
160 delete_button_cell("Delete$line", _("Delete"),
161 _('Remove line from document'));
166 gl_edit_item_controls($order, $dim, $line);
171 gl_edit_item_controls($order, $dim);
173 if ($order->count_gl_items())
174 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right",3);
180 //---------------------------------------------------------------------------------
182 function gl_edit_item_controls(&$order, $dim, $Index=null)
185 $payment = $order->trans_type == ST_BANKPAYMENT;
188 $id = find_submit('Edit');
189 if ($Index != -1 && $Index == $id)
191 $item = $order->gl_items[$Index];
192 $_POST['code_id'] = $item->code_id;
193 $_POST['dimension_id'] = $item->dimension_id;
194 $_POST['dimension2_id'] = $item->dimension2_id;
195 $_POST['amount'] = price_format(abs($item->amount));
196 $_POST['description'] = $item->description;
197 $_POST['LineMemo'] = $item->reference;
199 hidden('Index', $id);
200 echo gl_all_accounts_list('code_id', null, true, true);
202 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
204 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
205 $Ajax->activate('items_table');
209 $_POST['amount'] = price_format(0);
210 $_POST['dimension_id'] = 0;
211 $_POST['dimension2_id'] = 0;
212 $_POST['LineMemo'] = "";
213 if(isset($_POST['_code_id_update'])) {
214 $Ajax->activate('code_id');
217 if ($_POST['PayType'] == PT_CUSTOMER)
219 $acc = get_branch_accounts($_POST['PersonDetailID']);
220 $_POST['code_id'] = $acc['receivables_account'];
222 elseif ($_POST['PayType'] == PT_SUPPLIER)
224 $acc = get_supplier_accounts($_POST['person_id']);
225 $_POST['code_id'] = $acc['payable_account'];
227 //elseif ($_POST['PayType'] == PT_WORKORDER)
228 // $_POST['code_id'] = get_company_pref('default_assembly_act');
231 get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
233 echo gl_all_accounts_list('code_id', null, true, true);
235 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
237 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
240 hidden('dimension_id', 0);
242 hidden('dimension2_id', 0);
244 amount_cells(null, 'amount');
245 text_cells_ex(null, 'LineMemo', 35, 255);
249 button_cell('UpdateItem', _("Update"),
250 _('Confirm changes'), ICON_UPDATE);
251 button_cell('CancelItemChanges', _("Cancel"),
252 _('Cancel changes'), ICON_CANCEL);
257 submit_cells('AddItem', _("Add Item"), "colspan=2",
258 _('Add new item to document'), true);
265 //---------------------------------------------------------------------------------
267 function gl_options_controls()
269 echo "<br><table align='center'>";
271 textarea_row(_("Memo"), 'memo_', null, 50, 3);
277 //---------------------------------------------------------------------------------