Code cleanup
[fa-stable.git] / gl / includes / ui / gl_bank_ui.inc
1 <?php
2
3 function display_bank_header(&$order)
4 {
5         global $table_style2, $Ajax;
6         $payment = $order->trans_type == systypes::bank_payment();
7
8         div_start('pmt_header');
9         start_table("width=90% $table_style2"); // outer table
10         echo "<tr><td valign=top width=33%>";
11
12         echo "<table>"; // inner table
13
14     bank_accounts_list_row( $payment ? _("From:") : _("To:"), 'bank_account', null, true);
15
16     date_row(_("Date:"), 'date_');
17
18         echo "</table>"; // inner table
19
20         echo "</td><td width=33%>";
21
22         echo "<table>"; // inner table
23
24         if (!isset($_POST['PayType']))
25         {
26                 if (isset($_GET['PayType']))
27                         $_POST['PayType'] = $_GET['PayType'];
28                 else
29                         $_POST['PayType'] = "";
30         }
31         if (!isset($_POST['person_id']))
32         {
33                 if (isset($_GET['PayPerson']))
34                         $_POST['person_id'] = $_GET['PayPerson'];
35                 else
36                         $_POST['person_id'] = "";
37         }
38         if (isset($_POST['_PayType_update'])) {
39                 $_POST['person_id'] = '';
40                 $Ajax->activate('pmt_header');
41                 $Ajax->activate('code_id');
42         }
43     payment_person_types_list_row( $payment ? _("Pay To:"):_("From:"),
44                  'PayType', $_POST['PayType'], true);
45     switch ($_POST['PayType'])
46     {
47                 case payment_person_types::misc() :
48                 text_row_ex($payment ?_("To the Order of:"):_("Name:"),
49                                  'person_id', 40, 50);
50                 break;
51                 case payment_person_types::WorkOrder() :
52                 workorders_list_row(_("Work Order:"), 'person_id', null);
53                 break;
54                 case payment_person_types::supplier() :
55                 supplier_list_row(_("Supplier:"), 'person_id', null, false, true);
56                 break;
57                 case payment_person_types::customer() :
58                 customer_list_row(_("Customer:"), 'person_id', null, false, true);
59
60                 if (db_customer_has_branches($_POST['person_id']))
61                 {
62                         customer_branches_list_row(_("Branch:"), $_POST['person_id'], 'PersonDetailID', null, false, true, true);
63                 }
64                 else
65                 {
66                                 $_POST['PersonDetailID'] = reserved_words::get_any_numeric();
67                         hidden('PersonDetailID');
68                 }
69                 break;
70                 //case payment_person_types::Project() :
71         //      dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true);
72         //      break;
73     }
74
75         $person_currency = payment_person_types::person_currency($_POST['PayType'], $_POST['person_id']);
76         $bank_currency = get_bank_account_currency($_POST['bank_account']);
77
78         exchange_rate_display($bank_currency, $person_currency, $_POST['date_']);
79
80         echo "</table>"; // inner table
81
82         echo "</td><td>";
83
84         echo "<table>"; // inner table
85
86         bank_trans_types_list_row(_("Type:"), 'type', null);
87
88     ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_payment()));
89
90         echo "</table>"; // inner table
91
92         echo "</td></tr>";
93
94         end_table(1); // outer table
95         div_end();
96 }
97 //---------------------------------------------------------------------------------
98
99 function display_gl_items($title, &$order)
100 {
101         global $table_style, $path_to_root;
102
103         $dim = get_company_pref('use_dimension');
104         $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
105         display_heading($title);
106
107     div_start('items_table');
108         start_table("$table_style colspan=7 width=95%");
109
110         if ($dim == 2)
111                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
112                         _("Dimension")." 2", _("Amount"), _("Memo"));
113         else if ($dim == 1)
114                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
115                         _("Amount"), _("Memo"));
116         else
117                 $th = array(_("Account Code"), _("Account Description"),
118                         _("Amount"), _("Memo"));
119
120         if (count($order->gl_items)) $th[] = '';
121
122         table_header($th);
123         $k = 0;  //row colour counter
124
125         $id = find_submit('Edit');
126         foreach ($order->gl_items as $item)
127         {
128                 if ($id != $item->index)
129                 {
130                 alt_table_row_color($k);
131
132                         label_cell($item->code_id);
133                         label_cell($item->description);
134                 if ($dim >= 1)
135                                 label_cell(get_dimension_string($item->dimension_id, true));
136                 if ($dim > 1)
137                                 label_cell(get_dimension_string($item->dimension2_id, true));
138                         amount_cell(abs($item->amount));
139                         label_cell($item->reference);
140
141                         edit_button_cell("Edit$item->index", _("Edit"),
142                                 _('Edit document line'));
143                         edit_button_cell("Delete$item->index", _("Delete"),
144                                 _('Remove line from document'));
145                 end_row();
146                 }
147                 else
148                 {
149                         gl_edit_item_controls($order, $dim, $item->index);
150                 }
151         }
152
153         if ($id == -1)
154                 gl_edit_item_controls($order, $dim);
155
156         if ($order->count_gl_items())
157                 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right");
158
159     end_table();
160         div_end();
161 }
162
163 //---------------------------------------------------------------------------------
164
165 function gl_edit_item_controls(&$order, $dim, $Index=null)
166 {
167         global $Ajax;
168         $payment = $order->trans_type == systypes::bank_payment();
169
170         start_row();
171         $id = find_submit('Edit');
172         if ($Index != -1 && $Index == $id)
173         {
174                 $item = $order->gl_items[$Index];
175                 $_POST['code_id'] = $item->code_id;
176                 $_POST['dimension_id'] = $item->dimension_id;
177                 $_POST['dimension2_id'] = $item->dimension2_id;
178                 $_POST['amount'] = price_format(abs($item->amount));
179                 $_POST['description'] = $item->description;
180                 $_POST['LineMemo'] = $item->reference;
181
182                 hidden('Index', $item->index);
183                 hidden('code_id', $item->code_id);
184                 label_cell($_POST['code_id']);
185                 label_cell($item->description);
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             $Ajax->activate('items_table');
191         }
192         else
193         {
194                 $_POST['amount'] = price_format(0);
195                 $_POST['dimension_id'] = 0;
196                 $_POST['dimension2_id'] = 0;
197                 $_POST['LineMemo'] = "";
198                 if(isset($_POST['_code_id_update'])) {
199                             $Ajax->activate('code_id');
200                 }
201
202                 if ($_POST['PayType'] == payment_person_types::customer())
203                 {
204                         $acc = get_branch_accounts($_POST['PersonDetailID']);
205                         $_POST['code_id'] = $acc['receivables_account'];
206                 }
207                 elseif ($_POST['PayType'] == payment_person_types::supplier())
208                 {
209                         $acc = get_supplier_accounts($_POST['person_id']);
210                         $_POST['code_id'] = $acc['payable_account'];
211                 }
212                 elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
213                         $_POST['code_id'] = get_company_pref('default_assembly_act');
214                 else {
215                         $_POST['code_id'] = 
216                                 get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
217                 }
218                 gl_all_accounts_list('code_id', null, true, false, true);
219                 if ($dim >= 1)
220                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
221                 if ($dim > 1)
222                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
223         }
224         if ($dim < 1)
225                 hidden('dimension_id', 0);
226         if ($dim < 2)
227                 hidden('dimension2_id', 0);
228
229         amount_cells(null, 'amount');
230         text_cells_ex(null, 'LineMemo', 35, 50);
231
232         if ($id != -1)
233         {
234                 edit_button_cell('UpdateItem', _("Update"),
235                                 _('Confirm changes'));
236                 edit_button_cell('CancelItemChanges', _("Cancel"),
237                                 _('Cancel changes'));
238                 set_focus('amount');
239         }
240         else
241         {
242                 submit_cells('AddItem', _("Add Item"), "colspan=2",
243                     _('Add new item to document'), true);
244         }
245
246         end_row();
247 }
248
249
250 //---------------------------------------------------------------------------------
251
252 function gl_options_controls()
253 {
254         echo "<br><table align='center'>";
255
256         textarea_row(_("Memo"), 'memo_', null, 50, 3);
257
258         echo "</table>";
259 }
260
261
262 //---------------------------------------------------------------------------------
263
264 ?>