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 include_once($path_to_root . "/includes/ui.inc");
13 include_once($path_to_root . "/includes/ui/items_cart.inc");
15 //--------------------------------------------------------------------------------
17 function display_order_header(&$Order)
21 $qes = has_quick_entries(QE_JOURNAL);
22 $new = $Order->order_id==0;
23 start_outer_table(TABLESTYLE2, "width='90%'");
26 date_row(_("Journal Date:"), 'date_', '', $new, 0,0,0,null, true);
27 if (input_changed('date_'))
30 $Ajax->activate('ref');
33 currencies_list_row(_('Currency:'), 'currency', null, true);
34 if (list_updated('currency'))
35 unset($_POST['_ex_rate']);
36 exchange_rate_display(get_company_pref('curr_default'), get_post('currency'), get_post('date_'), true);
38 if (list_updated('currency'))
39 $Order->clear_items();
43 date_row(_("Document Date:"), 'doc_date', '', $new);
44 date_row(_("Event Date:"), 'event_date', '', $new);
45 text_row(_("Source ref:"), 'source_ref', null, 30, 60);
51 ref_row(_("Reference:"), 'ref', null, get_post('ref'), false, ST_JOURNAL, get_post('date_'));
52 hidden('ref_original');
57 quick_entries_list_row(_("Quick Entry").":", 'quick', null, QE_JOURNAL, true);
60 $qid = get_quick_entry(get_post('quick'));
61 if (list_updated('quick')) {
62 unset($_POST['totamount']); // enable default
63 $Ajax->activate('totamount');
66 if ($qid['bal_type'] == 1)
68 $accname = get_gl_account_name($qid['base_desc']);
69 label_row(($qid['base_amount'] == 0 ? _("Yearly") : _("Monthly")) . " ". _("balance from account")." ".
70 $qid['base_desc']." ".$accname." ".submit('go', _("Go"), false, false, true),'', "colspan=2");
74 text_row(_('Additional info:'), 'aux_info', null, 35, 255);
75 amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
76 null, " ".submit('go', _("Go"), false, false, true));
81 check_row(_('Include in tax register:'), 'taxable_trans', null, true);
82 // Query the user to retain the reconciled status
83 if (!$new && $Order->reconcile_date) {
84 check_row(_('Reconciled:'), 'reconciled', 1, true);
85 hidden('reconcile_date', $Order->reconcile_date);
90 //---------------------------------------------------------------------------------
92 function display_gl_items($title, &$order)
96 display_heading($title);
98 $dim = get_company_pref('use_dimension');
100 $id = find_submit('Edit');
101 $sub_type = is_subledger_account(get_post('code_id'));
102 $has_subaccounts = $order->has_sub_accounts();
104 div_start('items_table');
105 start_table(TABLESTYLE, "width='95%'");
107 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
108 _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"), "");
110 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
111 _("Debit"), _("Credit"), _("Memo"), "");
113 $th = array(_("Account Code"), _("Account Description"),
114 _("Debit"), _("Credit"), _("Memo"), "");
116 if (count($order->gl_items)) $th[] = '';
117 if ($sub_type || $has_subaccounts)
118 array_insert($th, 2, _("Counterparty"));
125 $id = get_post('Index', -1);
127 foreach ($order->gl_items as $line => $item)
131 alt_table_row_color($k);
133 $acc = $item->code_id . ($item->person_id ? sprintf(' %05d', $item->person_id) : '');
134 label_cells($acc, $item->description);
136 if ($sub_type || $has_subaccounts)
137 label_cell($item->person_name);
140 label_cell(get_dimension_string($item->dimension_id, true));
142 label_cell(get_dimension_string($item->dimension2_id, true));
143 if ($item->amount > 0)
145 amount_cell(abs($item->amount));
151 amount_cell(abs($item->amount));
153 label_cell($item->reference);
155 edit_button_cell("Edit$line", _("Edit"),
156 _('Edit journal line'));
157 delete_button_cell("Delete$line", _("Delete"),
158 _('Remove line from journal'));
163 gl_edit_item_controls($order, $dim, $item->person_id, $line);
168 gl_edit_item_controls($order, $dim, $sub_type);
170 if ($order->count_gl_items())
172 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2")) + ($sub_type || $has_subaccounts ? 1 : 0);
174 label_cell(_("Total"), "align=right colspan=" . $colspan);
175 amount_cell($order->gl_items_total_debit());
176 amount_cell(abs($order->gl_items_total_credit()));
177 label_cell('', "colspan=3");
185 //---------------------------------------------------------------------------------
187 function gl_edit_item_controls(&$order, $dim, $sub_accounts, $Index=null)
192 $id = find_submit('Edit');
194 $continue = $id = get_post('Index', -1);
196 if ($Index != -1 && $Index == $id)
198 // Modifying an existing row
199 $item = $order->gl_items[$Index];
200 if (!isset($continue))
202 $_POST['code_id'] = $item->code_id;
203 $_POST['dimension_id'] = $item->dimension_id;
204 $_POST['dimension2_id'] = $item->dimension2_id;
205 $_POST['person_id'] = $item->person_id;
206 if ($item->amount > 0)
208 $_POST['AmountDebit'] = price_format($item->amount);
209 $_POST['AmountCredit'] = "";
213 $_POST['AmountDebit'] = "";
214 $_POST['AmountCredit'] = price_format(abs($item->amount));
216 $_POST['description'] = $item->description;
217 $_POST['LineMemo'] = $item->reference;
219 hidden('Index', $id);
220 $skip_bank = !$_SESSION["wa_current_user"]->can_access('SA_BANKJOURNAL');
221 echo gl_all_accounts_list('code_id', null, $skip_bank, true, _('[Select account]'), true, false, false);
223 if (is_subledger_account(get_post('code_id')))
224 { // for home currency postings show all customers
225 $sel_cur = get_post('currency', $order->currency);
226 subledger_list_cells(null, 'person_id', get_post('code_id'), null, false, false,
227 get_company_currency() == $sel_cur ? null : $sel_cur);
228 } elseif ($order->has_sub_accounts())
231 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
233 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
234 $Ajax->activate('items_table');
238 $skip_bank = !$_SESSION["wa_current_user"]->can_access('SA_BANKJOURNAL');
239 echo gl_all_accounts_list('code_id', null, $skip_bank, true, _('[Select account]'), true, false, false);
242 // for home currency postings show all customers
243 $sel_cur = get_post('currency', $order->currency);
244 subledger_list_cells(null, 'person_id', get_post('code_id'), null, false, false,
245 get_company_currency() == $sel_cur ? null : $sel_cur);
247 elseif ($order->has_sub_accounts())
251 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
253 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
254 $_POST['LineMemo'] = "";
257 if (get_post('_code_id_update'))
259 $Ajax->activate('code_id');
260 set_focus($sub_accounts ? 'person_id' : 'AmountDebit');
263 hidden('dimension_id', 0);
265 hidden('dimension2_id', 0);
267 small_amount_cells(null, 'AmountDebit');
268 small_amount_cells(null, 'AmountCredit');
269 text_cells_ex(null, 'LineMemo', 35, 255);
273 button_cell('UpdateItem', _("Update"),
274 _('Confirm changes'), ICON_UPDATE);
275 button_cell('CancelItemChanges', _("Cancel"),
276 _('Cancel changes'), ICON_CANCEL);
280 submit_cells('AddItem', _("Add Item"), "colspan=2",
281 _('Add new line to journal'), true);
286 //---------------------------------------------------------------------------------
288 function gl_options_controls()
290 echo "<br><table align='center'>";
292 textarea_row(_("Memo"), 'memo_', null, 50, 3);