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%");
24 table_section(1, $qes ? "20%" : "");
27 date_cells(_("Date:"), 'date_', '', $new);
29 table_section(2, $qes ? "20%" : "50%");
30 ref_cells(_("Reference:"), 'ref', '');
31 hidden('ref_original');
36 table_section(3, "20%");
38 check_cells(_("Reverse Transaction:"), 'Reverse', null);
44 table_section(3, "40%");
46 quick_entries_list_cells(_("Quick Entry").":", 'person_id', null, QE_JOURNAL, true);
47 $qid = get_quick_entry(get_post('person_id'));
48 if (list_updated('person_id')) {
49 unset($_POST['totamount']); // enable default
50 $Ajax->activate('totamount');
52 if ($qid['bal_type'] == 1)
56 $accname = get_gl_account_name($qid['base_desc']);
57 label_cell(($qid['base_amount'] == 0 ? _("Yearly") : _("Monthly")) . " ". _("balance from account")." ".
58 $qid['base_desc']." ".$accname." ".submit('go', _("Go"), false, false, true), "colspan=2");
61 amount_cells($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
62 null, " ".submit('go', _("Go"), false, false, true));
70 //---------------------------------------------------------------------------------
72 function display_gl_items($title, &$order)
76 display_heading($title);
78 $dim = get_company_pref('use_dimension');
80 div_start('items_table');
81 start_table(TABLESTYLE, "colspan=7 width=95%");
83 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
84 _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"), "");
86 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
87 _("Debit"), _("Credit"), _("Memo"), "");
89 $th = array(_("Account Code"), _("Account Description"),
90 _("Debit"), _("Credit"), _("Memo"), "");
92 if (count($order->gl_items)) $th[] = '';
98 $id = find_submit('Edit');
99 foreach ($order->gl_items as $line => $item)
103 alt_table_row_color($k);
105 label_cells($item->code_id, $item->description);
107 label_cell(get_dimension_string($item->dimension_id, true));
109 label_cell(get_dimension_string($item->dimension2_id, true));
110 if ($item->amount > 0)
112 amount_cell(abs($item->amount));
118 amount_cell(abs($item->amount));
120 label_cell($item->reference);
122 edit_button_cell("Edit$line", _("Edit"),
123 _('Edit journal line'));
124 delete_button_cell("Delete$line", _("Delete"),
125 _('Remove line from journal'));
130 gl_edit_item_controls($order, $dim, $line);
135 gl_edit_item_controls($order, $dim);
137 if ($order->count_gl_items())
139 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2"));
141 label_cell(_("Total"), "align=right colspan=" . $colspan);
142 amount_cell($order->gl_items_total_debit());
143 amount_cell(abs($order->gl_items_total_credit()));
144 label_cell('', "colspan=3");
152 //---------------------------------------------------------------------------------
154 function gl_edit_item_controls(&$order, $dim, $Index=null)
159 $id = find_submit('Edit');
160 if ($Index != -1 && $Index == $id)
162 // Modifying an existing row
163 $item = $order->gl_items[$Index];
164 $_POST['code_id'] = $item->code_id;
165 $_POST['dimension_id'] = $item->dimension_id;
166 $_POST['dimension2_id'] = $item->dimension2_id;
167 if ($item->amount > 0)
169 $_POST['AmountDebit'] = price_format($item->amount);
170 $_POST['AmountCredit'] = "";
174 $_POST['AmountDebit'] = "";
175 $_POST['AmountCredit'] = price_format(abs($item->amount));
177 $_POST['description'] = $item->description;
178 $_POST['LineMemo'] = $item->reference;
180 hidden('Index', $id);
181 $skip_bank = !$_SESSION["wa_current_user"]->can_access('SA_BANKJOURNAL');
182 echo gl_all_accounts_list('code_id', null, $skip_bank, true);
184 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
186 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
187 $Ajax->activate('items_table');
192 $_POST['AmountDebit'] = ''; //price_format(0);
193 $_POST['AmountCredit'] = ''; //price_format(0);
194 $_POST['dimension_id'] = 0;
195 $_POST['dimension2_id'] = 0;
196 //$_POST['LineMemo'] = ""; // let memo go to next line Joe Hunt 2010-05-30
197 $_POST['_code_id_edit'] = "";
198 $_POST['code_id'] = "";
199 if(isset($_POST['_code_id_update'])) {
200 $Ajax->activate('code_id');
203 $skip_bank = !$_SESSION["wa_current_user"]->can_access('SA_BANKJOURNAL');
204 echo gl_all_accounts_list('code_id', null, $skip_bank, true);
206 dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
208 dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
211 hidden('dimension_id', 0);
213 hidden('dimension2_id', 0);
215 small_amount_cells(null, 'AmountDebit');
216 small_amount_cells(null, 'AmountCredit');
217 text_cells_ex(null, 'LineMemo', 35, 255);
221 button_cell('UpdateItem', _("Update"),
222 _('Confirm changes'), ICON_UPDATE);
223 button_cell('CancelItemChanges', _("Cancel"),
224 _('Cancel changes'), ICON_CANCEL);
228 submit_cells('AddItem', _("Add Item"), "colspan=2",
229 _('Add new line to journal'), true);
234 //---------------------------------------------------------------------------------
236 function gl_options_controls()
238 echo "<br><table align='center'>";
240 textarea_row(_("Memo"), 'memo_', null, 50, 3);
246 //---------------------------------------------------------------------------------