ccb3e33fda00c61c3f721042b7b0c809f7ee0521
[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 $table_style2, $Ajax;
15         $payment = $order->trans_type == systypes::bank_payment();
16
17         div_start('pmt_header');
18
19         start_outer_table("width=90% $table_style2"); // outer table
20
21         table_section(1);
22         
23     bank_accounts_list_row( $payment ? _("From:") : _("To:"), 'bank_account', null, true);
24
25     date_row(_("Date:"), 'date_', '', true, 0, 0, 0, null, true);
26
27         table_section(2, "33%");
28
29         if (!isset($_POST['PayType']))
30         {
31                 if (isset($_GET['PayType']))
32                         $_POST['PayType'] = $_GET['PayType'];
33                 else
34                         $_POST['PayType'] = "";
35         }
36         if (!isset($_POST['person_id']))
37         {
38                 if (isset($_GET['PayPerson']))
39                         $_POST['person_id'] = $_GET['PayPerson'];
40                 else
41                         $_POST['person_id'] = "";
42         }
43         if (isset($_POST['_PayType_update'])) {
44                 $_POST['person_id'] = '';
45                 $Ajax->activate('pmt_header');
46                 $Ajax->activate('code_id');
47         }
48     payment_person_types_list_row( $payment ? _("Pay To:"):_("From:"),
49                  'PayType', $_POST['PayType'], true);
50     switch ($_POST['PayType'])
51     {
52                 case payment_person_types::misc() :
53                 text_row_ex($payment ?_("To the Order of:"):_("Name:"),
54                                  'person_id', 40, 50);
55                 break;
56                 case payment_person_types::WorkOrder() :
57                 workorders_list_row(_("Work Order:"), 'person_id', null);
58                 break;
59                 case payment_person_types::supplier() :
60                 supplier_list_row(_("Supplier:"), 'person_id', null, false, true);
61                 break;
62                 case payment_person_types::customer() :
63                 customer_list_row(_("Customer:"), 'person_id', null, false, true);
64
65                 if (db_customer_has_branches($_POST['person_id']))
66                 {
67                         customer_branches_list_row(_("Branch:"), $_POST['person_id'], 'PersonDetailID', null, false, true, true);
68                 }
69                 else
70                 {
71                                 $_POST['PersonDetailID'] = reserved_words::get_any_numeric();
72                         hidden('PersonDetailID');
73                 }
74                 break;
75
76                 case payment_person_types::QuickEntry() :
77                         quick_entries_list_row(_("Type").":", 'person_id', null, ($payment ? QE_PAYMENT : QE_DEPOSIT), true);
78                         $qid = get_quick_entry(get_post('person_id'));
79                         if (list_updated('person_id')) {
80                                 unset($_POST['totamount']); // enable default
81                                 $Ajax->activate('totamount');
82                         }
83                         amount_row($qid['base_desc'].":", 'totamount', price_format($qid['base_amount']),
84                                  null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));
85                         break;  
86                 //case payment_person_types::Project() :
87         //      dimensions_list_row(_("Dimension:"), 'person_id', $_POST['person_id'], false, null, true);
88         //      break;
89     }
90
91         $person_currency = payment_person_types::person_currency($_POST['PayType'], $_POST['person_id']);
92         $bank_currency = get_bank_account_currency($_POST['bank_account']);
93
94         exchange_rate_display($bank_currency, $person_currency, $_POST['date_']);
95
96         table_section(3, "33%");
97
98         if (isset($_GET['NewPayment']))
99         ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_payment()));
100     else
101         ref_row(_("Reference:"), 'ref', '', references::get_next(systypes::bank_deposit()));
102
103         end_outer_table(1); // outer table
104
105         div_end();
106 }
107 //---------------------------------------------------------------------------------
108
109 function display_gl_items($title, &$order)
110 {
111         global $table_style, $path_to_root;
112
113         $dim = get_company_pref('use_dimension');
114         $colspan = ($dim == 2 ? 4 : ($dim == 1 ? 3 : 2));
115         display_heading($title);
116
117     div_start('items_table');
118         start_table("$table_style colspan=7 width=95%");
119
120         if ($dim == 2)
121                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
122                         _("Dimension")." 2", _("Amount"), _("Memo"), "");
123         else if ($dim == 1)
124                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
125                         _("Amount"), _("Memo"), "");
126         else
127                 $th = array(_("Account Code"), _("Account Description"),
128                         _("Amount"), _("Memo"), "");
129
130         if (count($order->gl_items)) $th[] = '';
131
132         table_header($th);
133         $k = 0;  //row colour counter
134
135         $id = find_submit('Edit');
136         foreach ($order->gl_items as $line => $item)
137         {
138                 if ($id != $line)
139                 {
140                 alt_table_row_color($k);
141
142                         label_cell($item->code_id);
143                         label_cell($item->description);
144                 if ($dim >= 1)
145                                 label_cell(get_dimension_string($item->dimension_id, true));
146                 if ($dim > 1)
147                                 label_cell(get_dimension_string($item->dimension2_id, true));
148                         //amount_cell(abs($item->amount));
149                         if ($order->trans_type == systypes::bank_deposit())
150                                 amount_cell(-$item->amount);
151                         else            
152                                 amount_cell($item->amount);
153                         label_cell($item->reference);
154
155                         edit_button_cell("Edit$line", _("Edit"),
156                                 _('Edit document line'));
157                         delete_button_cell("Delete$line", _("Delete"),
158                                 _('Remove line from document'));
159                 end_row();
160                 }
161                 else
162                 {
163                         gl_edit_item_controls($order, $dim, $line);
164                 }
165         }
166
167         if ($id == -1)
168                 gl_edit_item_controls($order, $dim);
169
170         if ($order->count_gl_items())
171                 label_row(_("Total"), number_format2(abs($order->gl_items_total()), user_price_dec()),"colspan=" . $colspan . " align=right", "align=right",3);
172
173     end_table();
174         div_end();
175 }
176
177 //---------------------------------------------------------------------------------
178
179 function gl_edit_item_controls(&$order, $dim, $Index=null)
180 {
181         global $Ajax;
182         $payment = $order->trans_type == systypes::bank_payment();
183
184         start_row();
185         $id = find_submit('Edit');
186         if ($Index != -1 && $Index == $id)
187         {
188                 $item = $order->gl_items[$Index];
189                 $_POST['code_id'] = $item->code_id;
190                 $_POST['dimension_id'] = $item->dimension_id;
191                 $_POST['dimension2_id'] = $item->dimension2_id;
192                 $_POST['amount'] = price_format(abs($item->amount));
193                 $_POST['description'] = $item->description;
194                 $_POST['LineMemo'] = $item->reference;
195
196                 hidden('Index', $id);
197                 hidden('code_id', $item->code_id);
198                 label_cell($_POST['code_id']);
199                 label_cell($item->description);
200                 if ($dim >= 1)
201                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
202                 if ($dim > 1)
203                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
204             $Ajax->activate('items_table');
205         }
206         else
207         {
208                 $_POST['amount'] = price_format(0);
209                 $_POST['dimension_id'] = 0;
210                 $_POST['dimension2_id'] = 0;
211                 $_POST['LineMemo'] = "";
212                 if(isset($_POST['_code_id_update'])) {
213                             $Ajax->activate('code_id');
214                 }
215
216                 if ($_POST['PayType'] == payment_person_types::customer())
217                 {
218                         $acc = get_branch_accounts($_POST['PersonDetailID']);
219                         $_POST['code_id'] = $acc['receivables_account'];
220                 }
221                 elseif ($_POST['PayType'] == payment_person_types::supplier())
222                 {
223                         $acc = get_supplier_accounts($_POST['person_id']);
224                         $_POST['code_id'] = $acc['payable_account'];
225                 }
226                 elseif ($_POST['PayType'] == payment_person_types::WorkOrder())
227                         $_POST['code_id'] = get_company_pref('default_assembly_act');
228                 else {
229                         $_POST['code_id'] =
230                                 get_company_pref($payment ? 'default_cogs_act':'default_inv_sales_act');
231                 }
232                 gl_all_accounts_list('code_id', null, false, true);
233                 if ($dim >= 1)
234                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
235                 if ($dim > 1)
236                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
237         }
238         if ($dim < 1)
239                 hidden('dimension_id', 0);
240         if ($dim < 2)
241                 hidden('dimension2_id', 0);
242
243         amount_cells(null, 'amount');
244         text_cells_ex(null, 'LineMemo', 35, 50);
245
246         if ($id != -1)
247         {
248                 button_cell('UpdateItem', _("Update"),
249                                 _('Confirm changes'), ICON_UPDATE);
250                 button_cell('CancelItemChanges', _("Cancel"),
251                                 _('Cancel changes'), ICON_CANCEL);
252                 set_focus('amount');
253         }
254         else
255         {
256                 submit_cells('AddItem', _("Add Item"), "colspan=2",
257                     _('Add new item to document'), true);
258         }
259
260         end_row();
261 }
262
263
264 //---------------------------------------------------------------------------------
265
266 function gl_options_controls()
267 {
268         echo "<br><table align='center'>";
269
270         textarea_row(_("Memo"), 'memo_', null, 50, 3);
271
272         echo "</table>";
273 }
274
275
276 //---------------------------------------------------------------------------------
277
278 ?>