Added journal entries edition, removed reverse transaction je option.
[fa-stable.git] / gl / includes / ui / gl_journal_ui.inc
1 <?php
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");
14
15 //--------------------------------------------------------------------------------
16
17 function display_order_header(&$Order)
18 {
19         global $table_style2, $Ajax;
20
21         $qes = has_quick_entries(QE_JOURNAL);
22         $new = $Order->order_id==0;
23         start_outer_table("$table_style2 width=90%");
24         table_section(1);
25
26         start_row();
27     date_cells(_("Date:"), 'date_', '', $new);
28
29         if ($qes)
30                 table_section(2, "20%");
31         else    
32                 table_section(2, "50%");
33
34         if ($new)
35                 ref_cells(_("Reference:"), 'ref', '');
36         else
37                 label_cells(_("Reference:"), $Order->reference);
38         end_row();
39
40         if ($qes !== false)
41         {
42                 table_section(3, "50%");
43                 start_row();
44                 quick_entries_list_cells(_("Quick Entry").":", 'person_id', null, QE_JOURNAL, true);
45                 $qid = get_quick_entry(get_post('person_id'));
46                 if (list_updated('person_id')) {
47                         unset($_POST['totamount']); // enable default
48                 $Ajax->activate('totamount');
49                 }
50                 amount_cells($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
51                  null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));
52                 end_row();
53
54         }
55                 
56         end_outer_table(1);
57 }
58
59 //---------------------------------------------------------------------------------
60
61 function display_gl_items($title, &$order)
62 {
63         global $table_style, $path_to_root;
64
65         display_heading($title);
66
67         $dim = get_company_pref('use_dimension');
68
69     div_start('items_table');
70         start_table("$table_style colspan=7 width=95%");
71         if ($dim == 2)
72                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
73                         _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"), "");
74         else if ($dim == 1)
75                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
76                         _("Debit"), _("Credit"), _("Memo"), "");
77         else
78                 $th = array(_("Account Code"), _("Account Description"),
79                         _("Debit"), _("Credit"), _("Memo"), "");
80
81         if (count($order->gl_items)) $th[] = '';
82
83         table_header($th);      
84
85         $k = 0;
86
87         $id = find_submit('Edit');
88         foreach ($order->gl_items as $line => $item) 
89         {
90                 if ($id != $line)
91                 {
92                 alt_table_row_color($k);
93
94                         label_cells($item->code_id, $item->description);
95                 if ($dim >= 1)
96                                 label_cell(get_dimension_string($item->dimension_id, true));
97                 if ($dim > 1)
98                                 label_cell(get_dimension_string($item->dimension2_id, true));
99                 if ($item->amount > 0)
100                 {
101                         amount_cell(abs($item->amount));
102                         label_cell("");
103                 }       
104                 else
105                 {
106                         label_cell("");
107                         amount_cell(abs($item->amount));
108                 }       
109                         label_cell($item->reference);
110
111                         edit_button_cell("Edit$line", _("Edit"),
112                                 _('Edit journal line'));
113                         delete_button_cell("Delete$line", _("Delete"),
114                                 _('Remove line from journal'));
115                 end_row();
116                 } 
117                 else 
118                 {
119                         gl_edit_item_controls($order, $dim, $line);
120                 }
121         }
122
123         if ($id == -1)
124                 gl_edit_item_controls($order, $dim);
125
126         if ($order->count_gl_items()) 
127         {
128                 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2"));
129                 start_row();
130                 label_cell(_("Total"), "align=right colspan=" . $colspan);
131                 amount_cell($order->gl_items_total_debit());
132                 amount_cell(abs($order->gl_items_total_credit()));
133                 label_cell('', "colspan=3");
134                 end_row();
135         }
136
137     end_table();
138         div_end();
139 }
140
141 //---------------------------------------------------------------------------------
142
143 function gl_edit_item_controls(&$order, $dim, $Index=null)
144 {
145         global $Ajax;
146         start_row();
147
148         $id = find_submit('Edit');
149         if ($Index != -1 && $Index == $id)
150         {
151                 $item = $order->gl_items[$Index];
152                 $_POST['code_id'] = $item->code_id;
153                 $_POST['dimension_id'] = $item->dimension_id;
154                 $_POST['dimension2_id'] = $item->dimension2_id;
155                 if ($item->amount > 0)
156                 {
157                         $_POST['AmountDebit'] = price_format($item->amount);
158                         $_POST['AmountCredit'] = "";
159                 }
160                 else
161                 {
162                         $_POST['AmountDebit'] = "";
163                         $_POST['AmountCredit'] = price_format(abs($item->amount));
164                 }       
165                 $_POST['description'] = $item->description;
166                 $_POST['LineMemo'] = $item->reference;
167
168                 hidden('Index', $id);
169                 hidden('code_id', $item->code_id);
170                 label_cell($_POST['code_id']);
171                 label_cell($item->description);
172                 if ($dim >= 1) 
173                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
174                 if ($dim > 1) 
175                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
176             $Ajax->activate('items_table');
177         }
178         else
179         {
180                 $_POST['AmountDebit'] = '';  //price_format(0);
181                 $_POST['AmountCredit'] = ''; //price_format(0);
182                 $_POST['dimension_id'] = 0;
183                 $_POST['dimension2_id'] = 0;
184                 $_POST['LineMemo'] = "";
185                 $_POST['_code_id_edit'] = "";
186                 $_POST['code_id'] = "";
187                 if(isset($_POST['_code_id_update'])) {
188                             $Ajax->activate('code_id');
189                 }
190                 
191                 $skip_bank = ($_SESSION["wa_current_user"]->access != 2);
192                 gl_all_accounts_list('code_id', null, $skip_bank, true);
193                 if ($dim >= 1)
194                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
195                 if ($dim > 1)
196                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
197         }
198         if ($dim < 1)
199                 hidden('dimension_id', 0);
200         if ($dim < 2)
201                 hidden('dimension2_id', 0);
202
203         small_amount_cells(null, 'AmountDebit');
204         small_amount_cells(null, 'AmountCredit');
205         text_cells_ex(null, 'LineMemo', 35, 50);
206
207         if ($id != -1)
208         {
209                 button_cell('UpdateItem', _("Update"),
210                                 _('Confirm changes'), ICON_UPDATE);
211                 button_cell('CancelItemChanges', _("Cancel"),
212                                 _('Cancel changes'), ICON_CANCEL);
213                 set_focus('amount');
214         } 
215         else 
216                 submit_cells('AddItem', _("Add Item"), "colspan=2",
217                     _('Add new line to journal'), true);
218
219         end_row();
220 }
221
222 //---------------------------------------------------------------------------------
223
224 function gl_options_controls()
225 {
226           echo "<br><table align='center'>";
227
228           textarea_row(_("Memo"), 'memo_', null, 50, 3);
229
230           echo "</table>";
231 }
232
233
234 //---------------------------------------------------------------------------------
235
236 ?>