Version typo fixed
[fa-stable.git] / includes / ui / ui_view.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 include_once($path_to_root . "/admin/db/voiding_db.inc");
13 include_once($path_to_root . "/includes/types.inc");
14
15 //--------------------------------------------------------------------------------------
16
17 function get_supplier_trans_view_str($type, $trans_no, $label="", $icon=false)
18 {
19         global $path_to_root;
20
21         $viewer = "";
22         if ($type == systypes::po())
23                 $viewer = "view_po.php";
24         elseif ($type == 20)
25                 $viewer = "view_supp_invoice.php";
26         elseif ($type == 21)
27                 $viewer = "view_supp_credit.php";
28         elseif ($type == 22)
29                 $viewer = "view_supp_payment.php";
30         elseif ($type == 25)
31                 $viewer = "view_grn.php";
32         else
33                 return null;
34
35         if ($label == "")
36                 $label = $trans_no;
37
38         if ($viewer != "")
39         {
40                 $pars = access_string($label);
41                 if (user_graphic_links() && $icon)
42                         $pars[0] = set_icon($icon, $pars[0]);
43                 $preview_str = "<a target='_blank' href='$path_to_root/purchasing/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
44         }
45         else
46                 $preview_str = $label;
47
48         return $preview_str;
49 }
50
51 //--------------------------------------------------------------------------------------
52
53 function get_gl_view_str($type, $trans_no, $label="", $force=false)
54 {
55         global $path_to_root;
56
57         if (!$force && !user_show_gl_info())
58                 return "";
59
60         $icon = false;
61         if ($label == "")
62         {
63                 $label = _("GL");
64                 $icon = ICON_GL;
65         }       
66         $pars = access_string($label);
67         if (user_graphic_links() && $icon)
68                 $pars[0] = set_icon($icon, $pars[0]);
69         $gl_view = "<a target='_blank' href='$path_to_root/gl/view/gl_trans_view.php?type_id=$type&trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
70
71         return $gl_view;
72 }
73
74 //--------------------------------------------------------------------------------------
75
76 function get_gl_view_str_cell($type, $trans_no, $label="")
77 {
78         $str = get_gl_view_str($type, $trans_no, $label);
79         if ($str != "")
80                 return "<td>$str</td>";
81 }
82
83 //--------------------------------------------------------------------------------------
84
85 function get_customer_trans_view_str($type, $trans_no, $label="", $icon=false)
86 {
87         global $path_to_root;
88
89         $viewer = "";
90         if ($type == 10)
91                 $viewer = "view_invoice.php";
92         elseif ($type == 11)
93                 $viewer = "view_credit.php";
94         elseif ($type == 12)
95                 $viewer = "view_receipt.php";
96         elseif ($type == 13)
97                 $viewer = "view_dispatch.php";
98         elseif ($type == 30)
99                 $viewer = "view_sales_order.php";
100         else
101                 return null;
102
103   if(!is_array($trans_no)) $trans_no = array($trans_no);
104
105   $lbl = $label;
106   $preview_str = '';
107
108   foreach($trans_no as $trans) {
109         if ($label == "")
110                 $lbl = $trans;
111         if($preview_str!='') $preview_str .= ',';
112
113         if ($viewer != "")
114         {
115                 $pars = access_string($lbl);
116                 if (user_graphic_links() && $icon)
117                         $pars[0] = set_icon($icon, $pars[0]);
118                 $preview_str .= "<a target='_blank' href='$path_to_root/sales/view/$viewer?trans_no=$trans' onclick=\"javascript:openWindow(this.href,this.target); return false;\" $pars[1]>$pars[0]</a>";
119         }
120         else
121                 $preview_str .= $lbl;
122   }
123
124         return $preview_str;
125 }
126
127 //--------------------------------------------------------------------------------------
128
129 function get_banking_trans_view_str($type, $trans_no, $label="", $icon=false)
130 {
131         global $path_to_root;
132
133         $viewer = "";
134
135         if ($type == 4)
136                 $viewer = "bank_transfer_view.php";
137         elseif ($type == 1)
138                 $viewer = "gl_payment_view.php";
139         elseif ($type == 2)
140                 $viewer = "gl_deposit_view.php";
141         elseif ($type == 0)
142                 $viewer = "";
143         else
144                 return null;
145
146         if ($label == "")
147                 $label = $trans_no;
148
149         if ($viewer != "")
150         {
151                 $pars = access_string($label);
152                 if (user_graphic_links() && $icon)
153                         $pars[0] = set_icon($icon, $pars[0]);
154                 $preview_str = "<a target='_blank' href='$path_to_root/gl/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
155         }
156         else
157                 $preview_str = $label;
158
159         return $preview_str;
160 }
161
162 //--------------------------------------------------------------------------------------
163
164 function get_inventory_trans_view_str($type, $trans_no, $label="", $icon=false)
165 {
166         global $path_to_root;
167
168         $viewer = "";
169
170         if ($type == systypes::inventory_adjustment())
171                 $viewer = "view_adjustment.php";
172         elseif ($type == systypes::location_transfer())
173                 $viewer = "view_transfer.php";
174         else
175                 return null;
176
177         if ($label == "")
178                 $label = $trans_no;
179
180         if ($viewer != "")
181         {
182                 $pars = access_string($label);
183                 if (user_graphic_links() && $icon)
184                         $pars[0] = set_icon($icon, $pars[0]);
185                 $preview_str = "<a target='_blank' href='$path_to_root/inventory/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
186         }
187         else
188                 $preview_str = $label;
189
190         return $preview_str;
191 }
192
193 //--------------------------------------------------------------------------------------
194
195 function get_manufacturing_trans_view_str($type, $trans_no, $label="", $icon=false)
196 {
197         global $path_to_root;
198
199         $viewer = "";
200
201         if ($type == 28)
202                 $viewer = "wo_issue_view.php";
203         elseif ($type == 29)
204                 $viewer = "wo_production_view.php";
205         elseif ($type == systypes::work_order())
206                 $viewer = "work_order_view.php";
207         else
208                 return null;
209
210         if ($label == "")
211                 $label = $trans_no;
212
213         if ($viewer != "")
214         {
215                 $pars = access_string($label);
216                 if (user_graphic_links() && $icon)
217                         $pars[0] = set_icon($icon, $pars[0]);
218                 $preview_str = "<a target='_blank' href='$path_to_root/manufacturing/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
219         }
220         else
221                 $preview_str = $label;
222
223         return $preview_str;
224 }
225
226 //--------------------------------------------------------------------------------------
227
228 function get_dimensions_trans_view_str($type, $trans_no, $label="", $icon=false)
229 {
230         global $path_to_root;
231
232         $viewer = "";
233
234         if ($type == 40)
235                 $viewer = "view_dimension.php";
236         else
237                 return null;
238
239         if ($label == "")
240                 $label = $trans_no;
241
242         if ($viewer != "")
243         {
244                 $pars = access_string($label);
245                 if (user_graphic_links() && $icon)
246                         $pars[0] = set_icon($icon, $pars[0]);
247                 $preview_str = "<a target='_blank' href='$path_to_root/dimensions/view/$viewer?trans_no=$trans_no' onclick=\"javascript:openWindow(this.href,this.target); return false;\"$pars[1]>$pars[0]</a>";
248         }
249         else
250                 $preview_str = $label;
251
252         return $preview_str;
253 }
254
255 //--------------------------------------------------------------------------------------
256
257 function get_trans_view_str($type, $trans_no, $label="", $icon=false)
258 {
259         $view_str = get_customer_trans_view_str($type, $trans_no, $label, $icon);
260         if ($view_str != null)
261                 return $view_str;
262
263         $view_str = get_supplier_trans_view_str($type, $trans_no, $label, $icon);
264         if ($view_str != null)
265                 return $view_str;
266
267         $view_str = get_banking_trans_view_str($type, $trans_no, $label, $icon);
268         if ($view_str != null)
269                 return $view_str;
270
271         $view_str = get_inventory_trans_view_str($type, $trans_no, $label, $icon);
272         if ($view_str != null)
273                 return $view_str;
274
275         $view_str = get_manufacturing_trans_view_str($type, $trans_no, $label, $icon);
276         if ($view_str != null)
277                 return $view_str;
278
279         $view_str = get_dimensions_trans_view_str($type, $trans_no, $label, $icon);
280         if ($view_str != null)
281                 return $view_str;
282
283         return null;
284 }
285
286 //--------------------------------------------------------------------------------------
287 // Displays currency exchange rate for given date.
288 // When there is no exrate for today, 
289 // gets it form ECB and stores in local database.
290 //
291 function exchange_rate_display($from_currency, $to_currency, $date_, $edit_rate=false)
292 {
293     global $Ajax;
294
295         if ($from_currency != $to_currency)
296         {
297                 $comp_currency = get_company_currency();
298                 if ($from_currency == $comp_currency)
299                         $currency = $to_currency;
300                 else
301                         $currency = $from_currency;
302                 $rate = 0;
303                 if ($date_ == Today()) {
304                         $rate = get_date_exchange_rate($currency, $date_);
305                         if (!$rate) {
306                                 $rate = get_ecb_rate($currency);
307                                 if ($rate) 
308                                         add_exchange_rate($currency, $date_, $rate, $rate);
309                         }
310                 }
311                 if (!$rate)
312                         $rate = get_exchange_rate_from_home_currency($currency, $date_);
313                 if ($from_currency != $comp_currency)
314                         $rate = 1 / ($rate / get_exchange_rate_from_home_currency($to_currency, $date_));
315
316                 $rate = number_format2($rate, user_exrate_dec());
317                 if ($edit_rate)
318                         text_row(_("Exchange Rate:"), '_ex_rate', $rate, 8, 8, null, "", " $from_currency = 1 $to_currency"); 
319                 else
320                 label_row(_("Exchange Rate:"),"<span style='vertical-align:top;' id='_ex_rate'>$rate</span> $from_currency = 1 $to_currency" );
321                 $Ajax->addUpdate('_ex_rate','_ex_rate', $rate);
322         }
323 }
324
325 //--------------------------------------------------------------------------------------
326
327 function is_voided_display($type, $id, $label)
328 {
329         global $table_style;
330         $void_entry = get_voided_entry($type, $id);
331
332         if ($void_entry == null)
333                 return false;
334
335         start_table("width=50% $table_style");
336         echo "<tr><td align=center><font color=red>$label</font><br>";
337         echo "<font color=red>" . _("Date Voided:") . " " . sql2date($void_entry["date_"]) . "</font><br>";
338         if (strlen($void_entry["memo_"]) > 0)
339                 echo "<center><font color=red>" . _("Memo:") . " " . $void_entry["memo_"] . "</font></center><br>";
340         echo "</td></tr>";
341         end_table(1);
342
343         return true;
344 }
345
346 //--------------------------------------------------------------------------------------
347
348 function comments_display_row($type, $id)
349 {
350         $comments = get_comments($type, $id);
351         if ($comments and db_num_rows($comments))
352         {
353                 echo "<tr><td colspan=15>";
354         while ($comment = db_fetch($comments))
355         {
356                 echo $comment["memo_"] . "<br>";
357         }
358                 echo "</td></tr>";
359         }
360 }
361
362 //--------------------------------------------------------------------------------------
363
364 function get_comments_string($type, $type_no)
365 {
366         $str_return = "";
367         $result = get_comments($type, $type_no);
368         while ($comment = db_fetch($result))
369         {
370                 if (strlen($str_return))
371                         $str_return = $str_return . " \n";
372                 $str_return = $str_return . $comment["memo_"];
373         }
374         return $str_return;
375 }
376
377 //--------------------------------------------------------------------------------------
378
379 function view_stock_status($stock_id, $description=null, $echo=true)
380 {
381         global $path_to_root;
382         if ($description)
383                 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", (user_show_codes()?$stock_id . " - ":"") . $description, "stock_id=$stock_id");
384                 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >". (user_show_codes()?$stock_id . " - ":"") . $description."</a>";
385         else
386                 //hyperlink_params_separate($path_to_root . "/inventory/inquiry/stock_status.php", $stock_id, "stock_id=$stock_id");
387                 $preview_str = "<a target='_blank' href='$path_to_root/inventory/inquiry/stock_status.php?stock_id=$stock_id' onclick=\"javascript:openWindow(this.href,this.target); return false;\" >$stock_id</a>";
388         if($echo)
389                 echo $preview_str;
390         return $preview_str;
391 }
392
393 function view_stock_status_cell($stock_id, $description=null)
394 {
395         echo "<td>";
396         view_stock_status($stock_id, $description);
397         echo "</td>";
398 }
399
400 //--------------------------------------------------------------------------------------
401
402 function display_debit_or_credit_cells($value)
403 {
404         if ($value >= 0)
405         {
406                 amount_cell($value);
407                 label_cell("");
408         }
409         elseif ($value < 0)
410         {
411                 label_cell("");
412                 amount_cell(abs($value));
413         }
414 }
415
416 //--------------------------------------------------------------------------------------
417
418 function display_customer_trans_tax_details($tax_items, $columns)
419 {
420     while ($tax_item = db_fetch($tax_items))
421     {
422         $tax = number_format2($tax_item['amount'],user_price_dec());
423         if ($tax_item['included_in_price'])
424                 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
425                         _("Amount") . ": $tax", "", "colspan=$columns align=right", "align=right");
426         else
427                 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
428                         $tax, "colspan=$columns align=right", "align=right");
429     }
430 }
431
432 //--------------------------------------------------------------------------------------
433
434 function display_supp_trans_tax_details($tax_items, $columns)
435 {
436     while ($tax_item = db_fetch($tax_items))
437     {
438         $tax = number_format2(abs($tax_item['amount']),user_price_dec());
439         if ($tax_item['included_in_price'])
440                 label_row(_("Included") . " " . $tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%) " .
441                         _("Amount") . ": $tax", "colspan=$columns align=right", "align=right");
442         else
443                 label_row($tax_item['tax_type_name'] . " (" . $tax_item['rate'] . "%)",
444                         $tax, "colspan=$columns align=right", "align=right");
445     }
446 }
447
448 //--------------------------------------------------------------------------------------
449
450 function display_edit_tax_items($taxes, $columns, $tax_included, $leftspan=0)
451 {
452         $total = 0;
453
454     foreach ($taxes as $taxitem)
455     {
456         if ($tax_included)
457         {
458                 label_row(_("Included") . " " . $taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%) " .
459                         _("Amount:") . " " . number_format2($taxitem['Value'],user_price_dec()), "", "colspan=$columns align=right", "align=right",$leftspan);
460         }
461         else
462         {
463                 label_row($taxitem['tax_type_name'] . " (" . $taxitem['rate'] . "%)",
464                         number_format2($taxitem['Value'],user_price_dec()), "colspan=$columns align=right", "align=right",$leftspan);
465                 $total +=  round2($taxitem['Value'], user_price_dec());
466         }
467     }
468
469     return $total;
470 }
471
472 //--------------------------------------------------------------------------------------
473
474 function display_footer_exit()
475 {
476         br(2);
477         end_page();
478         exit;
479 }
480
481 //--------------------------------------------------------------------------------------
482
483 function display_allocations($alloc_result, $total)
484 {
485         global $table_style;
486
487         if (!$alloc_result || db_num_rows($alloc_result) == 0)
488                 return;
489
490     display_heading2(_("Allocations"));
491
492     start_table("$table_style width=80%");
493
494     $th = array( _("Type"), _("Number"), _("Date"), _("Total Amount"),
495         _("Left to Allocate"), _("This Allocation"));
496         table_header($th);
497     $k = $total_allocated = 0;
498
499     while ($alloc_row = db_fetch($alloc_result))
500     {
501
502         alt_table_row_color($k);
503
504         label_cell(systypes::name($alloc_row['type']));
505         label_cell(get_trans_view_str($alloc_row['type'],$alloc_row['trans_no']));
506         label_cell(sql2date($alloc_row['tran_date']));
507         $alloc_row['Total'] = round2($alloc_row['Total'], user_price_dec());
508         $alloc_row['amt'] = round2($alloc_row['amt'], user_price_dec());
509         amount_cell($alloc_row['Total']);
510         //amount_cell($alloc_row['Total'] - $alloc_row['PrevAllocs'] - $alloc_row['amt']);
511         amount_cell($alloc_row['Total'] - $alloc_row['amt']);
512         amount_cell($alloc_row['amt']);
513         end_row();
514
515         $total_allocated += $alloc_row['amt'];
516     }
517     start_row();
518         label_cell(_("Total Allocated:"), "align=right colspan=5");
519         amount_cell($total_allocated);
520         end_row();
521         start_row();
522     label_cell(_("Left to Allocate:"), "align=right colspan=5");
523     $total = round2($total, user_price_dec());
524     amount_cell($total - $total_allocated);
525     end_row();
526
527     end_table(1);
528 }
529
530 //--------------------------------------------------------------------------------------
531
532 function display_allocations_from($person_type, $person_id, $type, $type_no, $total)
533 {
534         switch ($person_type)
535         {
536                 case payment_person_types::customer() :
537                         $alloc_result = get_allocatable_to_cust_transactions($person_id, $type_no, $type);
538                         display_allocations($alloc_result, $total);
539                         return;
540                 case payment_person_types::supplier() :
541                         $alloc_result = get_allocatable_to_supp_transactions($person_id, $type_no, $type);
542                         display_allocations($alloc_result, $total);
543                         return;
544         }
545 }
546
547 //--------------------------------------------------------------------------------------
548 //
549 //      Expands selected quick entry $id into GL posings and adds to cart.
550 //              returns calculated amount posted to bank GL account.
551 //
552 function display_quick_entries(&$cart, $id, $base, $type, $descr='')
553 {
554         $bank_amount = 0;
555         
556         if (!isset($id) || $id == null || $id == "")
557         {
558                 display_error( _("No Quick Entries are defined."));
559                 set_focus('totamount');
560         }
561         else
562         {
563                 if ($type == QE_DEPOSIT)
564                         $base = -$base;
565                 if ($type != QE_SUPPINV)        // only one quick entry on journal/bank transaction
566                         $cart->clear_items();
567                 $qe = get_quick_entry($id);
568                 if ($descr != '') $qe['description'] .= ': '.$descr;
569                 $result = get_quick_entry_lines($id);
570                 $totrate = 0;
571                 while ($row = db_fetch($result))
572                 {
573                         $qe_lines[] = $row;
574
575                         switch (strtolower($row['action'])) {
576                                 case "t": // post taxes calculated on base amount
577                                 case "t+": // ditto & increase base amount
578                                 case "t-": // ditto & reduce base amount
579                                         if (substr($qe_line['action'],0,1) != 'T') 
580                                                 $totrate += get_tax_type_default_rate($row['dest_id']);
581                         }
582                 }
583                 $first = true;
584                 $taxbase = 0;
585                 foreach($qe_lines as $qe_line)
586                 {
587                         switch (strtolower($qe_line['action'])) {
588                                 case "=": // post current base amount to GL account
589                                         $part = $base;
590                                         break;
591                                 case "a": // post amount to GL account and reduce base
592                                         $part = $qe_line['amount'];
593                                         break;
594                                 case "a+": // post amount to GL account and increase base
595                                         $part = $qe_line['amount']; $base += $part;
596                                         break;
597                                 case "a-": // post amount to GL account and reduce base
598                                         $part = $qe_line['amount']; $base -= $part;
599                                         break;
600                                 case "%":       // store acc*amount% to GL account
601                                         $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
602                                         break;
603                                 case "%+":      // ditto & increase base amount
604                                         $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
605                                         $base += $part;
606                                         break;
607                                 case "%-":      // ditto & reduce base amount
608                                         $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
609                                         $base -= $part;
610                                         break;
611                                 case "t": // post taxes calculated on base amount
612                                 case "t+": // ditto & increase base amount
613                                 case "t-": // ditto & reduce base amount
614                                         if ($first)
615                                         {
616                                                 $taxbase = $base/($totrate+100);
617                                                 $first = false;
618                                         }
619
620                                         if (substr($qe_line['action'],0,1) != 'T') 
621                                                 $part = $taxbase;
622                                         else
623                                                 $part = $base;
624                                         $item_tax = get_tax_type($qe_line['dest_id']);
625                                         if ($type == QE_SUPPINV && substr($qe_line['action'],0,1) != 'T')
626                                         {
627                                                 $taxgroup = $cart->tax_group_id;
628                                                 $rates = 0;
629                                                 $res = get_tax_group_items($cart->tax_group_id);
630                                                 while ($row = db_fetch($res))
631                                                         $rates += $row['rate'];
632                                                 if ($rates == 0)
633                                                         continue 2;
634                                         }
635                                         $tax = round2($part * $item_tax['rate'],  user_price_dec());
636                                         if ($tax==0) continue 2;
637                                         $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0)) 
638                                                 ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
639                                         if (!is_tax_gl_unique($gl_code)) {
640                                                 display_error(_("Cannot post to GL account used by more than one tax type."));
641                                                 break 2;
642                                         }
643                                         if ($type != QE_SUPPINV)
644                                                 $cart->add_gl_item($gl_code, 
645                                                         $qe_line['dimension_id'], $qe_line['dimension2_id'], 
646                                                         $tax, $qe['description']);
647                                         else 
648                                         {
649                                                 $acc_name = get_gl_account_name($gl_code);
650                                                 $cart->add_gl_codes_to_trans($gl_code, 
651                                                         $acc_name, $qe_line['dimension_id'], 
652                                                         $qe_line['dimension2_id'], $tax, $qe['description']);
653                                         }
654                                         if (strpos($qe_line['action'], '+'))
655                                                 $base += $tax;
656                                         elseif (strpos($qe_line['action'], '-'))
657                                                 $base -= $tax;
658                                         continue 2;
659                         }
660                         if ($type != QE_SUPPINV)
661                                 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
662                                         $qe_line['dimension2_id'], $part, $qe['description']);
663                         else 
664                         {
665                                 $acc_name = get_gl_account_name($qe_line['dest_id']);
666                                 $cart->add_gl_codes_to_trans($qe_line['dest_id'], 
667                                         $acc_name, $qe_line['dimension_id'], 
668                                         $qe_line['dimension2_id'], $part, $qe['description']);
669                         }
670                 }
671 /*              
672                 while ($qe_line = db_fetch($qe_lines))
673                 {
674                         switch (strtolower($qe_line['action'])) {
675                                 case "=": // post current base amount to GL account
676                                         $part = $base;
677                                         break;
678                                 case "a": // post amount to GL account and reduce base
679                                         $part = $qe_line['amount'];
680                                         break;
681                                 case "a+": // post amount to GL account and increase base
682                                         $part = $qe_line['amount']; $base += $part;
683                                         break;
684                                 case "a-": // post amount to GL account and reduce base
685                                         $part = $qe_line['amount']; $base -= $part;
686                                         break;
687                                 case "%":       // store acc*amount% to GL account
688                                         $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
689                                         break;
690                                 case "%+":      // ditto & increase base amount
691                                         $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
692                                         $base += $part;
693                                         break;
694                                 case "%-":      // ditto & reduce base amount
695                                         $part = round2($base * $qe_line['amount'] / 100, user_price_dec());
696                                         $base -= $part;
697                                         break;
698                                 case "t": // post taxes calculated on base amount
699                                 case "t+": // ditto & increase base amount
700                                 case "t-": // ditto & reduce base amount
701                                         //$taxes = get_taxes_for_item_tax($qe_line['dest_id']);
702                                         if ($type == QE_SUPPINV)
703                                                 $qe_line['dest_id'] = $cart->tax_group_id;
704                                         $taxes = array();
705                                         $res = get_tax_group_items($qe_line['dest_id']);
706                                         while ($row = db_fetch($res))
707                                                 $taxes[] = $row;
708                                         $tax_total = 0;
709                                         $totrate = 0;
710                                         // find total tax 
711                                         if (substr($qe_line['action'],0,1) != 'T') {
712                                                 foreach ($taxes as $index => $item_tax) {
713                                                         $totrate += $item_tax['rate'];
714                                                 }
715                                         }
716                                         $taxbase = $base/($totrate+100);
717                                         foreach ($taxes as $index => $item_tax) {
718                                                 $tax = round2($taxbase * $item_tax['rate'],  user_price_dec());
719                                                 $gl_code = ($type == QE_DEPOSIT || ($type == QE_JOURNAL && $base < 0)) 
720                                                         ? $item_tax['sales_gl_code'] : $item_tax['purchasing_gl_code'];
721                                                 $tax_total += $tax;
722                                                 if ($tax==0) continue;
723                                                 if (!is_tax_gl_unique($gl_code)) {
724                                                         display_error(_("Cannot post to GL account used by more than one tax type."));
725                                                         break 3;
726                                                 }
727                                                 if ($type != QE_SUPPINV)
728                                                         $cart->add_gl_item($gl_code, 
729                                                                 $qe_line['dimension_id'], $qe_line['dimension2_id'], 
730                                                                 $tax, $qe['description']);
731                                                 else 
732                                                 {
733                                                         $acc_name = get_gl_account_name($gl_code);
734                                                         $cart->add_gl_codes_to_trans($gl_code, 
735                                                                 $acc_name, $qe_line['dimension_id'], 
736                                                                 $qe_line['dimension2_id'], $tax, $qe['description']);
737                                                 }
738                                         }
739                                         if (strpos($qe_line['action'], '+'))
740                                                 $base += $tax_total;
741                                         elseif (strpos($qe_line['action'], '-'))
742                                                 $base -= $tax_total;
743                                         continue 2;
744                         }
745                         if ($type != QE_SUPPINV)
746                                 $cart->add_gl_item($qe_line['dest_id'], $qe_line['dimension_id'],
747                                         $qe_line['dimension2_id'], $part, $qe['description']);
748                         else 
749                         {
750                                 $acc_name = get_gl_account_name($qe_line['dest_id']);
751                                 $cart->add_gl_codes_to_trans($qe_line['dest_id'], 
752                                         $acc_name, $qe_line['dimension_id'], 
753                                         $qe_line['dimension2_id'], $part, $qe['description']);
754                         }
755                 }
756 */              
757         }       
758         return $bank_amount;
759 }
760
761
762 function get_js_open_window($width, $height)
763 {
764         $js ="function openWindow(url, title)\n"
765                 . "{\n"
766                 . " var left = (screen.width - $width) / 2;\n"
767                 . " var top = (screen.height - $height) / 2;\n"
768                 . " return window.open(url, title, 'width=$width,height=$height,left='+left+',top='+top+',screenX='+left+',screenY='+top+',status=no,scrollbars=yes');\n"
769                 . "}\n";
770         return $js;
771 }
772
773 /*
774   Setting focus on element $name in $form.
775   If $form<0 $name is element id.
776 */
777 function set_focus($name, $form_no=0) {
778   global $Ajax;
779         $Ajax->addFocus(true, $name);
780     $_POST['_focus'] = $name;
781 }
782 //
783 //      Set default focus on first field $name if not set yet
784 //
785 function default_focus($name, $form_no=0) {
786     if (!isset($_POST['_focus'])) {
787           set_focus($name);
788     }
789 }
790
791 function get_js_png_fix()
792 {
793         $js = "function fixPNG(myImage)\n"
794                 . "{\n"
795                 . " var arVersion = navigator.appVersion.split(\"MSIE\")\n"
796                 . " var version = parseFloat(arVersion[1])\n"
797         . " if ((version >= 5.5) && (version < 7) && (document.body.filters))\n"
798         . " {\n"
799         . "  var imgID = (myImage.id) ? \"id='\" + myImage.id + \"' \" : \"\"\n"
800                 . "  var imgClass = (myImage.className) ? \"class='\" + myImage.className + \"' \" : \"\"\n"
801                 . "  var imgTitle = (myImage.title) ?\n"
802                 . "    \"title='\" + myImage.title  + \"' \" : \"title='\" + myImage.alt + \"' \"\n"
803                 . "  var imgStyle = \"display:inline-block;\" + myImage.style.cssText\n"
804                 . "  var strNewHTML = \"<span \" + imgID + imgClass + imgTitle\n"
805         . "    + \" style=\\\"\" + \"width:\" + myImage.width\n"
806         . "    + \"px; height:\" + myImage.height\n"
807         . "    + \"px;\" + imgStyle + \";\"\n"
808         . "    + \"filter:progid:DXImageTransform.Microsoft.AlphaImageLoader\"\n"
809         . "    + \"(src=\'\" + myImage.src + \"\', sizingMethod='scale');\\\"></span>\"\n"
810                 . "  myImage.outerHTML = strNewHTML\n"
811         . " }\n"
812                 . "}\n";
813         return $js;
814 }
815
816 function get_js_date_picker()
817 {
818     global $comp_path, $go_debug;
819     $fpath = $comp_path.'/'.user_company().'/js_cache/'.'date_picker.js';
820
821     if (!file_exists($fpath) || $go_debug) {
822
823         global $dateseps, $date_system;
824
825         $how = user_date_format();                              // 0 = us/ca, 1 = eu, au, nz, 2 = jp, sw
826         $sep = $dateseps[user_date_sep()];              // date separator
827         $wstart = (($date_system == 1 || $date_system == 2) ? 6 : ($how == 0 ? 0 : 1));                 // weekstart (sun = 0, mon = 1)
828         $months = array(_("January"),_("February"),_("March"),_("April"),_("May"),_("June"),_("July"),_("August"),_("September"),_("October"),_("November"),_("December"));
829         $wdays = array(_("Su"),_("Mo"),_("Tu"),_("We"),_("Th"),_("Fr"),_("Sa"));
830         $wno = _("W"); // week no
831         $back = _("Back");
832         if ($date_system == 1)
833                 list($cyear, $cmon, $cday) = gregorian_to_jalali(date("Y"), date("n"), date("j"));
834         else if ($date_system == 2)
835                 list($cyear, $cmon, $cday) = gregorian_to_islamic(date("Y"), date("n"), date("j"));
836
837
838         $js = "
839 function positionInfo(object) {
840   var p_elm = object;
841   this.getElementLeft = getElementLeft;
842   function getElementLeft() {
843     var x = 0;
844     var elm;
845     if(typeof(p_elm) == 'object'){
846       elm = p_elm;
847     } else {
848       elm = document.getElementById(p_elm);
849     }
850     while (elm != null) {
851       x+= elm.offsetLeft;
852       elm = elm.offsetParent;
853     }
854     return parseInt(x);
855   }
856   this.getElementWidth = getElementWidth;
857   function getElementWidth(){
858     var elm;
859     if(typeof(p_elm) == 'object'){
860       elm = p_elm;
861     } else {
862       elm = document.getElementById(p_elm);
863     }
864     return parseInt(elm.offsetWidth);
865   }
866   this.getElementRight = getElementRight;
867   function getElementRight(){
868     return getElementLeft(p_elm) + getElementWidth(p_elm);
869   }
870   this.getElementTop = getElementTop;
871   function getElementTop() {
872     var y = 0;
873     var elm;
874     if(typeof(p_elm) == 'object'){
875       elm = p_elm;
876     } else {
877       elm = document.getElementById(p_elm);
878     }
879     while (elm != null) {
880       y+= elm.offsetTop;
881       elm = elm.offsetParent;
882     }
883     return parseInt(y);
884   }
885   this.getElementHeight = getElementHeight;
886   function getElementHeight(){
887     var elm;
888     if(typeof(p_elm) == 'object'){
889       elm = p_elm;
890     } else {
891       elm = document.getElementById(p_elm);
892     }
893     return parseInt(elm.offsetHeight);
894   }
895   this.getElementBottom = getElementBottom;
896   function getElementBottom(){
897     return getElementTop(p_elm) + getElementHeight(p_elm);
898   }
899 }
900 function CC() {
901   var calendarId = 'CC';
902   var currentYear = 0;
903   var currentMonth = 0;
904   var currentDay = 0;
905   var selectedYear = 0;
906   var selectedMonth = 0;
907   var selectedDay = 0;
908   var months = ['$months[0]','$months[1]','$months[2]','$months[3]','$months[4]','$months[5]','$months[6]','$months[7]','$months[8]','$months[9]','$months[10]','$months[11]'];
909   var wdays = ['$wdays[0]', '$wdays[1]', '$wdays[2]', '$wdays[3]', '$wdays[4]', '$wdays[5]', '$wdays[6]'];
910   var dateField = null;
911   function getProperty(p_property){
912     var p_elm = calendarId;
913     var elm = null;
914     if(typeof(p_elm) == 'object'){
915       elm = p_elm;
916     } else {
917       elm = document.getElementById(p_elm);
918     }
919     if (elm != null){
920       if(elm.style){
921         elm = elm.style;
922         if(elm[p_property]){
923           return elm[p_property];
924         } else {
925           return null;
926         }
927       } else {
928         return null;
929       }
930     }
931   }
932   function setElementProperty(p_property, p_value, p_elmId){
933     var p_elm = p_elmId;
934     var elm = null;
935     if(typeof(p_elm) == 'object'){
936       elm = p_elm;
937     } else {
938       elm = document.getElementById(p_elm);
939     }
940     if((elm != null) && (elm.style != null)){
941       elm = elm.style;
942       elm[ p_property ] = p_value;
943     }
944   }
945   function setProperty(p_property, p_value) {
946     setElementProperty(p_property, p_value, calendarId);
947   }
948   function getDaysInMonth(year, month) {
949 ";
950         if ($date_system == 1)
951                 $js .= "
952     return [31,31,31,31,31,31,30,30,30,30,30,(((((((year - ((year > 0) ? 474 : 473)) % 2820) + 474) + 38) * 682) % 2816) < 682 ? 30 : 29)][month-1];
953 ";
954         else if ($date_system == 2)
955                 $js .= "
956     return [30,29,30,29,30,29,30,29,30,29,30,(((((11 * year) + 14) % 30) < 11) ? 30 : 29)][month-1];
957 ";
958         else
959                 $js .= "
960     return [31,((!(year % 4 ) && ( (year % 100 ) || !( year % 400 ) ))?29:28),31,30,31,30,31,31,30,31,30,31][month-1];
961 ";
962         $js .= "
963   }
964   function getDayOfWeek(year, month, day) {
965 ";
966         if ($date_system == 1 || $date_system == 2)
967         {
968                 $js .= "
969         function mod(a, b)
970         {
971             return a - (b * Math.floor(a / b));
972         }
973         function jwday(j)
974         {
975             return mod(Math.floor((j + 1.5)), 7);
976         }
977 ";
978         if ($date_system == 1)
979                 $js .= "
980     var epbase, epyear, t;
981     epbase = year - ((year >= 0) ? 474 : 473);
982     epyear = 474 + mod(epbase, 2820);
983     t = day + ((month <= 7) ? ((month - 1) * 31) : (((month - 1) * 30) + 6)) +
984       Math.floor(((epyear * 682) - 110) / 2816) + (epyear - 1) * 365 +
985       Math.floor(epbase / 2820) * 1029983 + (1948320.5 - 1);
986 ";
987         else if ($date_system == 2)
988                 $js .= "
989         var t;
990         t = Math.floor((11 * year + 3) / 30) + 354 * year + 30 * month -
991           Math.floor((month - 1) / 2) + day + 1948440 - 385;
992 ";
993         $js .= "
994     return jwday(t);
995 ";
996         }
997         else
998                 $js .= "
999     var date = new Date(year,month-1,day)
1000     return date.getDay();
1001 ";
1002         $js .= "
1003   }
1004   this.clearDate = clearDate;
1005   function clearDate() {
1006     dateField.value = '';
1007     hide();
1008   }
1009   this.getWeek = getWeek;
1010   function getWeek(year, month, day) {
1011 ";
1012         if ($how == 0)
1013                 $js .= "  day++;";
1014         $js .= "
1015     var date = new Date(year,month-1,day);
1016     var D = date.getDay();
1017     if(D == 0) D = 7;
1018     date.setDate(date.getDate() + (4 - D));
1019     var YN = date.getFullYear();
1020     var ZBDoCY = Math.floor((date.getTime() - new Date(YN, 0, 1, -6)) / 86400000);
1021     var WN = 1 + Math.floor(ZBDoCY / 7);
1022     return WN;
1023   }
1024   this.setDate = setDate;
1025   function setDate(year, month, day) {
1026     if (dateField) {
1027       if (month < 10) {month = '0' + month;}
1028       if (day < 10) {day = '0' + day;}
1029 ";
1030         if ($how == 0)
1031                 $js .= "
1032       var dateString = month+'$sep'+day+'$sep'+year;
1033 ";
1034         else if ($how == 1)
1035                 $js .= "
1036       var dateString = day+'$sep'+month+'$sep'+year;
1037 ";
1038         else
1039                 $js .= "
1040       var dateString = year+'$sep'+month+'$sep'+day;
1041 ";
1042         $js .= "
1043       dateField.value = dateString;
1044           setFocus(dateField.name);
1045           if (dateField.className=='searchbox')
1046                 dateField.onblur();
1047       hide();
1048     }
1049     return;
1050   }
1051   this.changeMonth = changeMonth;
1052   function changeMonth(change) {
1053     currentMonth += change;
1054     currentDay = 0;
1055     if(currentMonth > 12) {
1056       currentMonth = 1;
1057       currentYear++;
1058     } else if(currentMonth < 1) {
1059       currentMonth = 12;
1060       currentYear--;
1061     }
1062     calendar = document.getElementById(calendarId);
1063     calendar.innerHTML = calendarDrawTable();
1064   }
1065   this.changeYear = changeYear;
1066   function changeYear(change) {
1067     currentYear += change;
1068     currentDay = 0;
1069     calendar = document.getElementById(calendarId);
1070     calendar.innerHTML = calendarDrawTable();
1071   }
1072   function getCurrentYear() {
1073     var year = new Date().getYear();
1074     if(year < 1900) year += 1900;
1075     return year;
1076   }
1077   function getCurrentMonth() {
1078     return new Date().getMonth() + 1;
1079   }
1080   function getCurrentDay() {
1081     return new Date().getDate();
1082   }
1083   function calendarDrawTable() {
1084     var dayOfMonth = 1;
1085     var wstart = $wstart;
1086     var wno = '&nbsp;$wno&nbsp;';
1087     var validDay = 0;
1088     var startDayOfWeek = getDayOfWeek(currentYear, currentMonth, dayOfMonth);
1089     var daysInMonth = getDaysInMonth(currentYear, currentMonth);
1090     var css_class = null; //CSS class for each day
1091     var table = \"<table cellspacing='0' cellpadding='0' border='0'>\";
1092     table += \"<tr class='header'>\";
1093     table += \"  <td colspan='2' class='previous'><a href='javascript:changeCCMonth(-1);'>&lt;</a><br><a href='javascript:changeCCYear(-1);'>&laquo;</a></td>\";
1094     table += \"  <td colspan='4' class='title'>\" + months[currentMonth-1] + \"<br>\" + currentYear + \"</td>\";
1095     table += \"  <td colspan='2' class='next'><a href='javascript:changeCCMonth(1);'>&gt;</a><br><a href='javascript:changeCCYear(1);'>&raquo;</a></td>\";
1096     table += \"</tr>\";
1097     table += \"<tr>\";
1098     table += \"<th class='weekno'>\"+wno+\"</th>\";
1099     for (var n=0; n<7; n++)
1100         table += \"<th>\" + wdays[(wstart+n)%7]+\"</th>\";
1101     table += \"</tr>\";
1102     for(var week=0; week < 6; week++) {
1103       table += \"<tr>\";
1104       for(var n=0; n < 7; n++) {
1105         dayOfWeek = (wstart+n)%7;
1106         if(week == 0 && startDayOfWeek == dayOfWeek) {
1107           validDay = 1;
1108         } else if (validDay == 1 && dayOfMonth > daysInMonth) {
1109           validDay = 0;
1110         }
1111         if (n==0)
1112         {
1113                 if (dayOfMonth > daysInMonth)
1114                         table += \"<td class='empty'>&nbsp;</td>\";
1115                 else
1116                         table += \"<td class='weekno'>\"+getWeek(currentYear, currentMonth, dayOfMonth)+\"</td>\";
1117         }
1118         if(validDay) {
1119           if (dayOfMonth == selectedDay && currentYear == selectedYear && currentMonth == selectedMonth) {
1120             css_class = 'current';
1121 ";
1122         if ($date_system == 1 || $date_system == 2)
1123                 $js .= "
1124           } else if (dayOfWeek == 5) {
1125 ";
1126         else
1127                 $js .= "
1128           } else if (dayOfWeek == 0 || dayOfWeek == 6) {
1129 ";
1130                 $js .= "
1131             css_class = 'weekend';
1132           } else {
1133             css_class = 'weekday';
1134           }
1135           table += \"<td><a class='\"+css_class+\"' href=\\\"javascript:setCCDate(\"+currentYear+\",\"+currentMonth+\",\"+dayOfMonth+\")\\\">\"+dayOfMonth+\"</a></td>\";
1136           dayOfMonth++;
1137         } else {
1138           table += \"<td class='empty'>&nbsp;</td>\";
1139         }
1140       }
1141       table += \"</tr>\";
1142     }
1143     table += \"<tr class='header'><th colspan='8' style='padding: 3px;text-align:center;'><a href='javascript:hideCC();'>$back</a></td></tr>\";
1144     table += \"</table>\";
1145     return table;
1146   }
1147   this.show = show;
1148   function show(field) {
1149     can_hide = 0;
1150     if (dateField == field) {
1151       return;
1152     } else {
1153       dateField = field;
1154     }
1155     if(dateField) {
1156       try {
1157         var dateString = new String(dateField.value);
1158         var dateParts = dateString.split('$sep');
1159 ";
1160         if ($how == 0)
1161                 $js .= "
1162         selectedMonth = parseInt(dateParts[0],10);
1163         selectedDay = parseInt(dateParts[1],10);
1164         selectedYear = parseInt(dateParts[2],10);
1165 ";
1166         else if ($how == 1)
1167                 $js .= "
1168         selectedDay = parseInt(dateParts[0],10);
1169         selectedMonth = parseInt(dateParts[1],10);
1170         selectedYear = parseInt(dateParts[2],10);
1171 ";
1172         else
1173                 $js .= "
1174         selectedYear = parseInt(dateParts[0],10);
1175         selectedMonth = parseInt(dateParts[1],10);
1176         selectedDay = parseInt(dateParts[2],10);
1177 ";
1178         $js .= "
1179       } catch(e) {}
1180     }
1181     if (!(selectedYear && selectedMonth && selectedDay)) {
1182 ";
1183         if ($date_system == 1 || $date_system == 2)
1184         {
1185                 $js .= "
1186       selectedMonth = $cmon;
1187       selectedDay = $cday;
1188       selectedYear = $cyear;
1189 ";
1190         }
1191         else
1192         {
1193                 $js .= "
1194       selectedMonth = getCurrentMonth();
1195       selectedDay = getCurrentDay();
1196       selectedYear = getCurrentYear();
1197 ";
1198         }
1199         $js .= "
1200     }
1201     currentMonth = selectedMonth;
1202     currentDay = selectedDay;
1203     currentYear = selectedYear;
1204     if(document.getElementById){
1205       calendar = document.getElementById(calendarId);
1206       calendar.innerHTML = calendarDrawTable(currentYear, currentMonth);
1207       var fieldPos = new positionInfo(dateField);
1208       var calendarPos = new positionInfo(calendarId);
1209       var x = fieldPos.getElementLeft();
1210       var y = fieldPos.getElementBottom();
1211       setProperty('left', x + 'px');
1212       setProperty('top', y + 'px');
1213       setProperty('display', 'block');
1214       if (document.all) {
1215         setElementProperty('left', x + 'px', 'CCIframe');
1216         setElementProperty('top', y + 'px', 'CCIframe');
1217         setElementProperty('width', calendarPos.getElementWidth() + 'px', 'CCIframe');
1218         setElementProperty('height', calendarPos.getElementHeight() + 'px', 'CCIframe');
1219         setElementProperty('display', 'block', 'CCIframe');
1220       }
1221     }
1222   }
1223   this.hide = hide;
1224   function hide() {
1225     if(dateField) {
1226       setProperty('display', 'none');
1227       setElementProperty('display', 'none', 'CCIframe');
1228       dateField = null;
1229     }
1230   }
1231   this.visible = visible;
1232   function visible() {
1233     return dateField
1234   }
1235   this.can_hide = can_hide;
1236   var can_hide = 0;
1237 }
1238 var cC = new CC();
1239 function date_picker(textField) {
1240   cC.show(textField);
1241 }
1242 function hideCC() {
1243   if (cC.visible()) {
1244     cC.hide();
1245   }
1246 }
1247 function setCCDate(year, month, day) {
1248   cC.setDate(year, month, day);
1249 }
1250 function changeCCYear(change) {
1251   cC.changeYear(change);
1252 }
1253 function changeCCMonth(change) {
1254   cC.changeMonth(change);
1255 }
1256 document.write(\"<iframe id='CCIframe' src='javascript:false;' frameBorder='0' scrolling='no'></iframe>\");
1257 document.write(\"<div id='CC'></div>\");";
1258
1259      cache_js_file($fpath, $js);
1260     }
1261     add_js_ufile($fpath);
1262
1263  return '';
1264 }
1265
1266 function alert($msg)
1267 {
1268         echo "\n<script type=\"text/javascript\">\n"
1269                 . "<!--\n"
1270                 . "alert('$msg');\n"
1271                 . "-->\n"
1272                 . "</script>\n";
1273 }
1274
1275 if (!function_exists('_vd'))
1276 {
1277         function _vd($mixed, $title = '', $exit = false)
1278         {
1279         // Only the site admin is able to proceed here.
1280         $str = (!empty($title) ? ($title .':') : '') .'<pre>';
1281         $str .= print_r($mixed, true); //var_dump($mixed);
1282         $str .= "</pre>\n";
1283                 display_error('<table><tr><td>'.$str.'</td></tr></table>');
1284         if ($exit)
1285                 exit;
1286         }
1287 }
1288
1289 function display_backtrace($cond=true, $msg='') {
1290
1291         if ($cond) {
1292                 if ($msg) 
1293                         $str = "<center><span class='headingtext'>$msg</span></center>\n";
1294                 else
1295                         $str = '';
1296                 $str .= '<table border=0>';
1297         $trace = debug_backtrace();
1298                 foreach($trace as $trn => $tr) {
1299                         if (!$trn) continue;
1300                         $str .= '<tr><td>';
1301                         $str .= $tr['file'].':'.$tr['line'].': ';
1302                         $str .= '</td><td>';
1303                         if (isset($tr['type'])) {
1304                                 if($tr['type'] == '::') {
1305                                         $str .= $tr['class'].'::';
1306                                 } else if($tr['type'] == '->') {
1307                                         $str .= '('.$tr['class'].' Object)'.'->';
1308                                 }
1309                         }
1310                         foreach($tr['args'] as $n=>$a) {
1311                                 if (is_object($tr['args'][$n]))
1312                                         $tr['args'][$n] = "(".get_class($tr['args'][$n])." Object)";
1313                                 if (is_array($tr['args'][$n]))
1314                                         $tr['args'][$n] = "(Array[".count($tr['args'][$n])."])";
1315                                 else
1316                                         $tr['args'][$n] = "'".$tr['args'][$n]."'";
1317                         }
1318                         $str .= $tr['function'].'('. implode(',',$tr['args']).')</td>';
1319
1320                         $str .= '</tr>';
1321                 }
1322                 
1323                 $str .= '</table>';
1324         display_error($str);
1325         }
1326 }
1327
1328 ?>