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