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