13fc5c6b701e52b9c2c6d9fca02eb206699e079f
[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         table_header($th);
118         $k = 0;  //row colour counter
119
120         foreach ($order->gl_items as $item)
121         {
122                 if (!isset($_GET['Edit']) || $_GET['Edit'] != $item->index)
123                 {
124                 alt_table_row_color($k);
125
126                         label_cell($item->code_id);
127                         label_cell($item->description);
128                 if ($dim >= 1)
129                                 label_cell(get_dimension_string($item->dimension_id, true));
130                 if ($dim > 1)
131                                 label_cell(get_dimension_string($item->dimension2_id, true));
132                         amount_cell($item->amount);
133                         label_cell($item->reference);
134
135                         edit_link_cell("Edit=$item->index");
136                         delete_link_cell("Delete=$item->index");
137                 end_row();
138                 }
139                 else
140                 {
141                         gl_edit_item_controls($order, $dim, $item->index);
142                 }
143         }
144
145         if (!isset($_GET['Edit']))
146                 gl_edit_item_controls($order, $dim);
147
148         if ($order->count_gl_items())
149                 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right");
150
151     end_table();
152 }
153
154 //---------------------------------------------------------------------------------
155
156 function gl_edit_item_controls(&$order, $dim, $Index=null)
157 {
158         start_row();
159
160         if (isset($_GET['Edit']) && $Index != null)
161         {
162                 if (!isset($_POST['code_id']))
163                         $_POST['code_id'] = $order->gl_items[$Index]->code_id;
164                 if (!isset($_POST['dimension_id']))
165                         $_POST['dimension_id'] = $order->gl_items[$Index]->dimension_id;
166                 if (!isset($_POST['dimension2_id']))
167                         $_POST['dimension2_id'] = $order->gl_items[$Index]->dimension2_id;
168                 if (!isset($_POST['amount']) || ($_POST['amount'] == ""))
169                         $_POST['amount'] = $order->gl_items[$Index]->amount;
170                 if (!isset($_POST['description']) || ($_POST['description'] == ""))
171                         $_POST['description'] = $order->gl_items[$Index]->description;
172                 if (!isset($_POST['LineMemo']) || ($_POST['LineMemo'] == ""))
173                         $_POST['LineMemo'] = $order->gl_items[$Index]->reference;
174
175                 hidden('Index', $order->gl_items[$Index]->index);
176                 hidden('code_id', $order->gl_items[$Index]->code_id);
177                 label_cell($_POST['code_id']);
178                 label_cell($order->gl_items[$Index]->description);
179                 if ($dim >= 1)
180                         dimensions_list_cells(null, 'dimension_id', $_POST['dimension_id'], true, " ", false, 1);
181                 if ($dim > 1)
182                         dimensions_list_cells(null, 'dimension2_id', $_POST['dimension2_id'], true, " ", false, 2);
183         }
184         else
185         {
186                 $_POST['amount'] = 0;
187                 $_POST['dimension_id'] = 0;
188                 $_POST['dimension2_id'] = 0;
189                 $_POST['LineMemo'] = "";
190
191                 if ($_POST['PayType'] == payment_person_types::customer())
192                 {
193                         $acc = get_branch_accounts($_POST['PersonDetailID']);
194                         $_POST['code_id'] = $acc['receivables_account'];
195                 }
196                 elseif ($_POST['PayType'] == payment_person_types::supplier())
197                 {
198                         $acc = get_supplier_accounts($_POST['person_id']);
199                         $_POST['code_id'] = $acc['payable_account'];
200                 }
201                 elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
202                         $_POST['code_id'] = get_company_pref('default_assembly_act');
203                 else
204                         $_POST['code_id'] = get_company_pref('default_cogs_act');
205                 text_cells(null, "CodeID2", $_POST['code_id'], 12, 10, "", "", "onkeyup='recalcAccounts()' onblur='return setAccount(0, false)'");
206                 gl_all_accounts_list_cells(null, 'code_id', $_POST['code_id'], true, false, "return setAccount(1, false)");
207                 if ($dim >= 1)
208                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
209                 if ($dim > 1)
210                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
211         }
212         if ($dim < 1)
213                 hidden('dimension_id', 0);
214         if ($dim < 2)
215                 hidden('dimension2_id', 0);
216
217         amount_cells(null, 'amount');
218         text_cells_ex(null, 'LineMemo', 35, 50);
219
220         if (isset($_GET['Edit']))
221         {
222         submit_cells('UpdateItem', _("Update"));
223         submit_cells('CancelItemChanges', _("Cancel"));
224         }
225         else
226                 submit_cells('AddItem', _("Add Item"), "colspan=2");
227
228         end_row();
229 }
230
231
232 //---------------------------------------------------------------------------------
233
234 function gl_options_controls()
235 {
236         echo "<br><table align='center'>";
237
238         textarea_row(_("Memo"), 'memo_', null, 50, 3);
239
240         echo "</table>";
241 }
242
243
244 //---------------------------------------------------------------------------------
245
246 ?>