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