Moving 2.0 development version to main trunk.
[fa-stable.git] / reporting / includes / reporting.inc
1 <?php
2
3 // Put this on the page only once an outside a form, e.g. print_hidden_script(systypes::sales_order());
4 // If you have both invoices and credit notes on the same page use 10 or 11. Is doesn't matter which.
5
6 function print_hidden_script($type_no)
7 {
8         global $path_to_root;
9         include_once($path_to_root . "/includes/types.inc");
10         $action = "";
11
12         switch ($type_no)
13         {
14                 case systypes::sales_order() :
15                         $action = "$path_to_root/reporting/rep109.php";
16                         $ar = array(
17                                 'PARAM_0' => 0,         // from - these values are updated in print_document_link()
18                                 'PARAM_1' => 0,         // to
19                                 'PARAM_2' => "",        // currency
20                                 'PARAM_3' => get_first_bank_account(),  // bank account
21                                 'PARAM_4' => 0,         // email
22                                 'PARAM_5' => 0,         // quote
23                                 'PARAM_6' => "");       // comments
24                         break;
25                 case systypes::cust_dispatch() :
26                         $action = "$path_to_root/reporting/rep110.php";
27                         $ar = array(
28                                 'PARAM_0' => 0,         // from - these values are updated in print_document_link()
29                                 'PARAM_1' => 0,         // to
30                                 'PARAM_2' => 0,         // email
31                                 'PARAM_3' => "");       // comments
32                         break;
33                 case 10 : // Sales Invoice
34                 case 11 : // Customer Credit Note
35                         $action = "$path_to_root/reporting/rep107.php";
36                         $ar = array(
37                                 'PARAM_0' => 0,         // from - these values are updated in print_document_link()
38                                 'PARAM_1' => 0,         // to
39                                 'PARAM_2' => "",        // currency
40                                 'PARAM_3' => get_first_bank_account(),  // bank account
41                                 'PARAM_4' => 0,         // email
42                                 'PARAM_5' => "",        // paylink
43                                 'PARAM_6' => "",        // comments
44                                 'PARAM_7' => 0);        // IV or CN
45                         break;
46                 case systypes::po() :
47                         $action = "$path_to_root/reporting/rep209.php";
48                         $ar = array(
49                                 'PARAM_0' => 0,         // from - these values are updated in print_document_link()
50                                 'PARAM_1' => 0,         // to
51                                 'PARAM_2' => "",        // currency
52                                 'PARAM_3' => get_first_bank_account(),  // bank account
53                                 'PARAM_4' => 0,         // email
54                                 'PARAM_5' => "");       // comments
55                         break;
56         }
57         $st = "<form method='post' name='pdf_form' action='$action'>";
58         foreach ($ar as $key => $value)
59         {
60                 $st .= "<input type='hidden' name='$key' value='$value' />";
61         }
62         $st .= "</form>\n";
63         $st .= "<script type='text/javascript'>
64 <!--
65 function printDocument(docno, typeno) {
66   document.pdf_form.PARAM_0.value = document.pdf_form.PARAM_1.value = docno;
67   if (typeno == 10 || typeno == 11)
68         document.pdf_form.PARAM_7.value = typeno;
69   window.open('','REP_WINDOW','toolbar=no,scrollbar=no,resizable=yes,menubar=no');
70   document.pdf_form.target='REP_WINDOW';
71   document.pdf_form.submit();
72 }
73 -->
74 </script>\n";
75
76         echo $st;
77 }
78
79 // Ex. label_cell(print_document_link($myrow['order_no'], _("Print")));
80 // or display_note(print_document_link($order_no, _("Print this order")));
81 // or if a button
82 // button("button", _("Print this order"), print_document_link($order_no, "", false))";
83 // or if a button inside a TD
84 // button_cell("button", _("Print this order"), print_document_link($order_no, "", false))";
85 //
86 // You only need full parameter list for invoices/credit notes
87
88 function print_document_link($doc_no, $link_text, $link=true, $type_no=0)
89 {
90         if ($link)
91                 return "<a href=\"javascript:printDocument('$doc_no', '$type_no');\">$link_text</a>";
92         else
93                 return "javascript:printDocument('$doc_no', '$type_no');";
94 }
95
96 function get_first_bank_account()
97 {
98         $sql = "SELECT ".TB_PREF."bank_accounts.account_code FROM ".TB_PREF."bank_accounts, ".TB_PREF."company
99                 WHERE bank_curr_code=curr_default LIMIT 0, 1";
100         $result = db_query($sql);
101         $row = db_fetch_row($result);
102         return $row[0];
103 }
104 ?>