Added update of Units of Measure and converting of deptor_trans records from release...
[fa-stable.git] / gl / includes / ui / gl_deposit_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");
12         echo "<tr><td valign=top width=33%>"; // outer table
13
14         echo "<table>";
15
16     bank_accounts_list_row(_("To:"), 'bank_account', null, true);
17
18     date_row(_("Date:"), 'date_');
19
20         echo "</table>";
21
22         echo "</td><td width=33%>"; // outer table
23
24         echo "<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(_("From:"), 'PayType', $_POST['PayType'], 'person_id');
41
42     switch ($_POST['PayType'])
43     {
44                 case payment_person_types::misc() :
45                 text_row_ex(_("Name:"), '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>";
80
81         echo "</td><td>"; // outer table
82
83         echo "<table>";
84
85         bank_trans_types_list_row(_("Type:"), 'type', null);
86
87     ref_row(_("Reference:"), 'ref', references::get_next(systypes::bank_deposit()));
88
89         echo "</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         display_heading($title);
103
104         $dim = get_company_pref('use_dimension');
105         $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));       
106         
107         start_table("$table_style colspan=7 width=95%");
108         
109         if ($dim == 2)
110                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1", 
111                         _("Dimension")." 2", _("Amount"), _("Memo")); 
112         else if ($dim == 1)
113                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"), 
114                         _("Amount"), _("Memo")); 
115         else
116                 $th = array(_("Account Code"), _("Account Description"), 
117                 _("Amount"), _("Memo")); 
118         table_header($th);
119
120         $k = 0;  //row colour counter
121
122         foreach ($order->gl_items as $item) 
123         {
124                 if (!isset($_GET['Edit']) || $_GET['Edit'] != $item->index)
125                 {
126                 alt_table_row_color($k);
127
128                         label_cells($item->code_id, $item->description);
129                 if ($dim >= 1)
130                         label_cell(get_dimension_string($item->dimension_id, true));
131                 if ($dim > 1)
132                         label_cell(get_dimension_string($item->dimension2_id, true));
133                 amount_cell(abs($item->amount));
134                 label_cell($item->reference);   
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
178                 label_cell($_POST['code_id']);
179                 label_cell($order->gl_items[$Index]->description);
180                 if ($dim >= 1)
181                         dimensions_list_cells(null, 'dimension_id', $_POST['dimension_id'], true, " ", false, 1);
182                 if ($dim > 1)
183                         dimensions_list_cells(null, 'dimension2_id', $_POST['dimension2_id'], true, " ", false, 2);
184         }
185         else
186         {
187                 $_POST['amount'] = 0;
188                 $_POST['dimension_id'] = 0;
189                 $_POST['dimension2_id'] = 0;
190                 $_POST['LineMemo'] = "";
191
192                 if ($_POST['PayType'] == payment_person_types::customer())
193                 {
194                         $acc = get_branch_accounts($_POST['PersonDetailID']);
195                         $_POST['code_id'] = $acc['receivables_account'];
196                 }
197                 elseif ($_POST['PayType'] == payment_person_types::supplier())
198                 {
199                         $acc = get_supplier_accounts($_POST['person_id']);
200                         $_POST['code_id'] = $acc['payable_account'];
201                 }
202                 elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
203                         $_POST['code_id'] = get_company_pref('default_assembly_act');
204                 else    
205                         $_POST['code_id'] = get_company_pref('default_inv_sales_act');
206                 text_cells(null, "CodeID2", $_POST['code_id'], 12, 10, "", "", "onkeyup='recalcAccounts();' onblur='return setAccount(0, false);'");    
207                 gl_all_accounts_list_cells(null, 'code_id', $_POST['code_id'], true, false, "return setAccount(1, false)");
208         if ($dim >= 1)
209                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
210         if ($dim > 1)
211                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
212         }
213         if ($dim < 1)
214                 hidden('dimension_id', 0);
215         if ($dim < 2)
216                 hidden('dimension2_id', 0);
217
218         amount_cells(null, 'amount');
219         text_cells_ex(null, 'LineMemo', 35, 50);
220
221         if (isset($_GET['Edit'])) 
222         {
223         submit_cells('UpdateItem', _("Update"));
224         submit_cells('CancelItemChanges', _("Cancel"));
225         } 
226         else 
227         {
228                 submit_cells('AddItem', _("Add item"), "colspan=2");
229         }
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 ?>