27027f83638619a035aaf7b2e2015497d478c5fa
[fa-stable.git] / gl / includes / ui / gl_bank_ui.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 function display_bank_header(&$order)
13 {
14         global $Ajax, $Refs;
15         $payment = $order->trans_type == ST_BANKPAYMENT;
16
17         div_start('pmt_header');
18
19         start_outer_table(TABLESTYLE2, "width=90%"); // outer table
20
21         table_section(1);
22         
23         if (list_updated('PayType') || list_updated('person_id'))
24         {
25                 if ($_POST['PayType'] == PT_CUSTOMER || $_POST['PayType'] == PT_SUPPLIER)
26                 {
27                         $Ajax->activate('person_id');
28                         if ($_POST['PayType'] == PT_CUSTOMER)
29                         $_POST['bank_account'] = get_default_customer_bank_account($_POST['person_id']);
30                 else    
31                         $_POST['bank_account'] = get_default_supplier_bank_account($_POST['person_id']);
32                 }
33         }       
34     bank_accounts_list_row( $payment ? _("From:") : _("To:"), 'bank_account', null, true);
35     if ($payment)
36                 bank_balance_row($_POST['bank_account']);
37         
38     date_row(_("Date:"), 'date_', '', true, 0, 0, 0, null, true);
39
40         table_section(2, "33%");
41
42         if (!isset($_POST['PayType']))
43         {
44                 if (isset($_GET['PayType']))
45                         $_POST['PayType'] = $_GET['PayType'];
46                 else
47                         $_POST['PayType'] = "";
48         }
49         if (!isset($_POST['person_id']))
50         {
51                 if (isset($_GET['PayPerson']))
52                         $_POST['person_id'] = $_GET['PayPerson'];
53                 else
54                         $_POST['person_id'] = "";
55         }
56         if (isset($_POST['_PayType_update'])) {
57                 $_POST['person_id'] = '';
58                 $Ajax->activate('pmt_header');
59                 $Ajax->activate('code_id');
60                 $Ajax->activate('pagehelp');
61                 $Ajax->activate('editors');
62         }
63     payment_person_types_list_row( $payment ? _("Pay To:"):_("From:"),
64                  'PayType', $_POST['PayType'], true);
65     switch ($_POST['PayType'])
66     {
67                 case PT_MISC :
68                 text_row_ex($payment ?_("To the Order of:"):_("Name:"),
69                                  'person_id', 40, 50);
70                 break;
71                 //case PT_WORKORDER :
72         //      workorders_list_row(_("Work Order:"), 'person_id', null);
73         //      break;
74                 case PT_SUPPLIER :
75                 supplier_list_row(_("Supplier:"), 'person_id', null, false, true, false, true);
76                 break;
77                 case PT_CUSTOMER :
78                 customer_list_row(_("Customer:"), 'person_id', null, false, true, false, true);
79
80                 if (db_customer_has_branches($_POST['person_id']))
81                 {
82                         customer_branches_list_row(_("Branch:"), $_POST['person_id'], 
83                                         'PersonDetailID', null, false, true, true, true);
84                 }
85                 else
86                 {
87                                 $_POST['PersonDetailID'] = ANY_NUMERIC;
88                         hidden('PersonDetailID');
89                 }
90                 break;
91
92                 case PT_QUICKENTRY :
93                         quick_entries_list_row(_("Type").":", 'person_id', null, ($payment ? QE_PAYMENT : QE_DEPOSIT), true);
94                         $qid = get_quick_entry(get_post('person_id'));
95                         if (list_updated('person_id')) {
96                                 unset($_POST['totamount']); // enable default
97                                 $Ajax->activate('totamount');
98                         }
99                         amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
100                                  null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));
101                         break;  
102                 //case payment_person_types::Project() :
103         //      dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true);
104         //      break;
105     }
106
107         $person_currency = payment_person_currency($_POST['PayType'], $_POST['person_id']);
108         $bank_currency = get_bank_account_currency($_POST['bank_account']);
109
110         exchange_rate_display($bank_currency, $person_currency, $_POST['date_']);
111
112         table_section(3, "33%");
113
114         ref_row(_("Reference:"), 'ref', '');
115
116         end_outer_table(1); // outer table
117
118         div_end();
119 }
120 //---------------------------------------------------------------------------------
121
122 function display_gl_items($title, &$order)
123 {
124         global $path_to_root;
125
126         $dim = get_company_pref('use_dimension');
127         $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
128         display_heading($title);
129
130     div_start('items_table');
131         start_table(TABLESTYLE, "colspan=7 width=95%");
132
133         if ($dim == 2)
134                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
135                         _("Dimension")." 2", _("Amount"), _("Memo"), "");
136         else if ($dim == 1)
137                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
138                         _("Amount"), _("Memo"), "");
139         else
140                 $th = array(_("Account Code"), _("Account Description"),
141                         _("Amount"), _("Memo"), "");
142
143         if (count($order->gl_items)) $th[] = '';
144
145         table_header($th);
146         $k = 0;  //row colour counter
147
148         $id = find_submit('Edit');
149         foreach ($order->gl_items as $line => $item)
150         {
151                 if ($id != $line)
152                 {
153                 alt_table_row_color($k);
154
155                         label_cell($item->code_id);
156                         label_cell($item->description);
157                 if ($dim >= 1)
158                                 label_cell(get_dimension_string($item->dimension_id, true));
159                 if ($dim > 1)
160                                 label_cell(get_dimension_string($item->dimension2_id, true));
161                         //amount_cell(abs($item->amount));
162                         if ($order->trans_type == ST_BANKDEPOSIT)
163                                 amount_cell(-$item->amount);
164                         else            
165                                 amount_cell($item->amount);
166                         label_cell($item->reference);
167
168                         edit_button_cell("Edit$line", _("Edit"),
169                                 _('Edit document line'));
170                         delete_button_cell("Delete$line", _("Delete"),
171                                 _('Remove line from document'));
172                 end_row();
173                 }
174                 else
175                 {
176                         gl_edit_item_controls($order, $dim, $line);
177                 }
178         }
179
180         if ($id == -1)
181                 gl_edit_item_controls($order, $dim);
182
183         if ($order->count_gl_items())
184                 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right",3);
185
186     end_table();
187         div_end();
188 }
189
190 //---------------------------------------------------------------------------------
191
192 function gl_edit_item_controls(&$order, $dim, $Index=null)
193 {
194         global $Ajax;
195         $payment = $order->trans_type == ST_BANKPAYMENT;
196
197         start_row();
198         $id = find_submit('Edit');
199         if ($Index != -1 && $Index == $id)
200         {
201                 $item = $order->gl_items[$Index];
202                 $_POST['code_id'] = $item->code_id;
203                 $_POST['dimension_id'] = $item->dimension_id;
204                 $_POST['dimension2_id'] = $item->dimension2_id;
205                 $_POST['amount'] = price_format(abs($item->amount));
206                 $_POST['description'] = $item->description;
207                 $_POST['LineMemo'] = $item->reference;
208
209                 hidden('Index', $id);
210                 echo gl_all_accounts_list('code_id', null, true, true);
211                 if ($dim >= 1)
212                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
213                 if ($dim > 1)
214                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
215             $Ajax->activate('items_table');
216         }
217         else
218         {
219                 $_POST['amount'] = price_format(0);
220                 $_POST['dimension_id'] = 0;
221                 $_POST['dimension2_id'] = 0;
222                 //$_POST['LineMemo'] = ""; // let memo go to next line Joe Hunt 2010-05-30
223                 if(isset($_POST['_code_id_update'])) {
224                             $Ajax->activate('code_id');
225                 }
226
227                 if ($_POST['PayType'] == PT_CUSTOMER)
228                 {
229                         $acc = get_branch_accounts($_POST['PersonDetailID']);
230                         $_POST['code_id'] = $acc['receivables_account'];
231                 }
232                 elseif ($_POST['PayType'] == PT_SUPPLIER)
233                 {
234                         $acc = get_supplier_accounts($_POST['person_id']);
235                         $_POST['code_id'] = $acc['payable_account'];
236                 }
237                 //elseif ($_POST['PayType'] == PT_WORKORDER)
238                 //      $_POST['code_id'] = get_company_pref('default_assembly_act');
239                 else {
240                         $_POST['code_id'] =
241                                 get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
242                 }
243                 echo gl_all_accounts_list('code_id', null, true, true);
244                 if ($dim >= 1)
245                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
246                 if ($dim > 1)
247                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
248         }
249         if ($dim < 1)
250                 hidden('dimension_id', 0);
251         if ($dim < 2)
252                 hidden('dimension2_id', 0);
253
254         amount_cells(null, 'amount');
255         text_cells_ex(null, 'LineMemo', 35, 255);
256
257         if ($id != -1)
258         {
259                 button_cell('UpdateItem', _("Update"),
260                                 _('Confirm changes'), ICON_UPDATE);
261                 button_cell('CancelItemChanges', _("Cancel"),
262                                 _('Cancel changes'), ICON_CANCEL);
263                 set_focus('amount');
264         }
265         else
266         {
267                 submit_cells('AddItem', _("Add Item"), "colspan=2",
268                     _('Add new item to document'), true);
269         }
270
271         end_row();
272 }
273
274
275 //---------------------------------------------------------------------------------
276
277 function gl_options_controls()
278 {
279         echo "<br><table align='center'>";
280
281         textarea_row(_("Memo"), 'memo_', null, 50, 3);
282
283         echo "</table>";
284 }
285
286
287 //---------------------------------------------------------------------------------
288
289 ?>