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