Rewritten bank deposit/payment related files, added ajax.
[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         //$homeCurrency = get_company_currency();
76         $person_currency = payment_person_types::person_currency($_POST['PayType'], $_POST['person_id']);
77         $bank_currency = get_bank_account_currency($_POST['bank_account']);
78
79         if ($bank_currency != "" && $bank_currency != $person_currency)
80         {
81                 exchange_rate_display($bank_currency, $person_currency, $_POST['date_']);
82         }
83         
84         echo "</table>"; // inner table
85
86         echo "</td><td>";
87
88         echo "<table>"; // inner table
89
90         bank_trans_types_list_row(_("Type:"), 'type', null);
91
92     ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_payment()));
93
94         echo "</table>"; // inner table
95
96         echo "</td></tr>";
97
98         end_table(1); // outer table
99         div_end();
100 }
101 //---------------------------------------------------------------------------------
102
103 function display_gl_items($title, &$order)
104 {
105         global $table_style, $path_to_root;
106
107         $dim = get_company_pref('use_dimension');
108         $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
109         display_heading($title);
110
111     div_start('items_table');
112         start_table("$table_style colspan=7 width=95%");
113
114         if ($dim == 2)
115                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
116                         _("Dimension")." 2", _("Amount"), _("Memo"));
117         else if ($dim == 1)
118                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
119                         _("Amount"), _("Memo"));
120         else
121                 $th = array(_("Account Code"), _("Account Description"),
122                         _("Amount"), _("Memo"));
123
124         if (count($order->gl_items)) $th[] = '';
125
126         table_header($th);
127         $k = 0;  //row colour counter
128
129         $id = find_submit('Edit');
130         foreach ($order->gl_items as $item)
131         {
132                 if ($id != $item->index)
133                 {
134                 alt_table_row_color($k);
135
136                         label_cell($item->code_id);
137                         label_cell($item->description);
138                 if ($dim >= 1)
139                                 label_cell(get_dimension_string($item->dimension_id, true));
140                 if ($dim > 1)
141                                 label_cell(get_dimension_string($item->dimension2_id, true));
142                         amount_cell(abs($item->amount));
143                         label_cell($item->reference);
144
145                         edit_button_cell("Edit$item->index", _("Edit"),
146                                 _('Edit document line'));
147                         edit_button_cell("Delete$item->index", _("Delete"),
148                                 _('Remove line from document'));
149                 end_row();
150                 }
151                 else
152                 {
153                         gl_edit_item_controls($order, $dim, $item->index);
154                 }
155         }
156
157         if ($id == -1)
158                 gl_edit_item_controls($order, $dim);
159
160         if ($order->count_gl_items())
161                 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right");
162
163     end_table();
164         div_end();
165 }
166
167 //---------------------------------------------------------------------------------
168
169 function gl_edit_item_controls(&$order, $dim, $Index=null)
170 {
171         global $Ajax;
172         $payment = $order->trans_type == systypes::bank_payment();
173
174         start_row();
175         $id = find_submit('Edit');
176         if ($Index != -1 && $Index == $id)
177         {
178                 $_POST['code_id'] = $order->gl_items[$Index]->code_id;
179                 $_POST['dimension_id'] = $order->gl_items[$Index]->dimension_id;
180                 $_POST['dimension2_id'] = $order->gl_items[$Index]->dimension2_id;
181                 $_POST['amount'] = 
182                         price_format(($payment ? 1 : -1) * $order->gl_items[$Index]->amount);
183                 $_POST['description'] = $order->gl_items[$Index]->description;
184                 $_POST['LineMemo'] = $order->gl_items[$Index]->reference;
185
186                 hidden('Index', $order->gl_items[$Index]->index);
187                 hidden('code_id', $order->gl_items[$Index]->code_id);
188                 label_cell($_POST['code_id']);
189                 label_cell($order->gl_items[$Index]->description);
190                 if ($dim >= 1)
191                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
192                 if ($dim > 1)
193                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
194             $Ajax->activate('items_table');
195         }
196         else
197         {
198                 $_POST['amount'] = price_format(0);
199                 $_POST['dimension_id'] = 0;
200                 $_POST['dimension2_id'] = 0;
201                 $_POST['LineMemo'] = "";
202                 if(isset($_POST['_code_id_update'])) {
203                             $Ajax->activate('code_id');
204                 }
205
206                 if ($_POST['PayType'] == payment_person_types::customer())
207                 {
208                         $acc = get_branch_accounts($_POST['PersonDetailID']);
209                         $_POST['code_id'] = $acc['receivables_account'];
210                 }
211                 elseif ($_POST['PayType'] == payment_person_types::supplier())
212                 {
213                         $acc = get_supplier_accounts($_POST['person_id']);
214                         $_POST['code_id'] = $acc['payable_account'];
215                 }
216                 elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
217                         $_POST['code_id'] = get_company_pref('default_assembly_act');
218                 else {
219                         $_POST['code_id'] = 
220                                 get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
221                 }
222                 gl_all_accounts_list('code_id', null, true, false, true);
223                 if ($dim >= 1)
224                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
225                 if ($dim > 1)
226                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
227         }
228         if ($dim < 1)
229                 hidden('dimension_id', 0);
230         if ($dim < 2)
231                 hidden('dimension2_id', 0);
232
233         amount_cells(null, 'amount');
234         text_cells_ex(null, 'LineMemo', 35, 50);
235
236         if ($id != -1)
237         {
238                 edit_button_cell('UpdateItem', _("Update"),
239                                 _('Confirm changes'));
240                 edit_button_cell('CancelItemChanges', _("Cancel"),
241                                 _('Cancel changes'));
242                 set_focus('amount');
243         }
244         else
245         {
246                 submit_cells('AddItem', _("Add Item"), "colspan=2",
247                     _('Add new item to document'), true);
248         }
249
250         end_row();
251 }
252
253
254 //---------------------------------------------------------------------------------
255
256 function gl_options_controls()
257 {
258         echo "<br><table align='center'>";
259
260         textarea_row(_("Memo"), 'memo_', null, 50, 3);
261
262         echo "</table>";
263 }
264
265
266 //---------------------------------------------------------------------------------
267
268 ?>