[0000095] Bad behaviour of routine number_format and round in Windows.
[fa-stable.git] / reporting / rep107.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Print Invoices
9 // ----------------------------------------------------------------
10 $path_to_root="../";
11
12 include_once($path_to_root . "includes/session.inc");
13 include_once($path_to_root . "includes/date_functions.inc");
14 include_once($path_to_root . "includes/data_checks.inc");
15 include_once($path_to_root . "sales/includes/sales_db.inc");
16
17 //----------------------------------------------------------------------------------------------------
18
19 // trial_inquiry_controls();
20 print_invoices();
21
22 //----------------------------------------------------------------------------------------------------
23
24 function print_invoices()
25 {
26         global $path_to_root;
27
28         include_once($path_to_root . "reporting/includes/pdf_report.inc");
29
30         $from = $_POST['PARAM_0'];
31         $to = $_POST['PARAM_1'];
32         $currency = $_POST['PARAM_2'];
33         $bankaccount = $_POST['PARAM_3'];
34         $email = $_POST['PARAM_4'];
35         $paylink = $_POST['PARAM_5'];
36         $comments = $_POST['PARAM_6'];
37
38         if ($from == null)
39                 $from = 0;
40         if ($to == null)
41                 $to = 0;
42         $dec = user_price_dec();
43
44         $fno = explode("-", $from);
45         $tno = explode("-", $to);
46
47         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
48
49         // $headers in doctext.inc
50         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
51
52         $params = array('comments' => $comments,
53                                         'bankaccount' => $bankaccount);
54
55         $baccount = get_bank_account($params['bankaccount']);
56         $cur = get_company_Pref('curr_default');
57
58         if ($email == 0)
59         {
60                 $rep = new FrontReport(_('INVOICE'), "InvoiceBulk.pdf", user_pagesize());
61                 $rep->currency = $cur;
62                 $rep->Font();
63                 $rep->Info($params, $cols, null, $aligns);
64         }
65
66         for ($i = $fno[0]; $i <= $tno[0]; $i++)
67         {
68                 for ($j = 10; $j <= 11; $j++)
69                 {
70                         if (isset($_POST['PARAM_7']) && $_POST['PARAM_7'] != $j)
71                                 continue;
72                         if (!exists_customer_trans($j, $i))
73                                 continue;
74                         $sign = $j==10 ? 1 : -1;
75                         $myrow = get_customer_trans($i, $j);
76                         $branch = get_branch($myrow["branch_code"]);
77                         $branch['disable_branch'] = $paylink; // helper
78                         if ($j == 10)
79                                 $sales_order = get_sales_order_header($myrow["order_"]);
80                         else
81                                 $sales_order = null;
82                         if ($email == 1)
83                         {
84                                 $rep = new FrontReport("", "", user_pagesize());
85                                 $rep->currency = $cur;
86                                 $rep->Font();
87                                 if ($j == 10)
88                                 {
89                                         $rep->title = _('INVOICE');
90                                         $rep->filename = "Invoice" . $myrow['reference'] . ".pdf";
91                                 }
92                                 else
93                                 {
94                                         $rep->title = _('CREDIT NOTE');
95                                         $rep->filename = "CreditNote" . $myrow['reference'] . ".pdf";
96                                 }
97                                 $rep->Info($params, $cols, null, $aligns);
98                         }
99                         else
100                                 $rep->title = ($j == 10) ? _('INVOICE') : _('CREDIT NOTE');
101                         $rep->Header2($myrow, $branch, $sales_order, $baccount, $j);
102
103                         $result = get_customer_trans_details($j, $i);
104                         $SubTotal = 0;
105                         while ($myrow2=db_fetch($result))
106                         {
107                                 $Net = round2($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]),
108                                    user_price_dec());
109                                 $SubTotal += $Net;
110                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
111                         $DisplayQty = number_format2($sign*$myrow2["quantity"],get_qty_dec($myrow2['stock_id']));
112                         $DisplayNet = number_format2($Net,$dec);
113                         if ($myrow2["discount_percent"]==0)
114                                         $DisplayDiscount ="";
115                         else
116                                         $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
117                                 $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
118                                 $rep->TextCol(1, 2,     $myrow2['StockDescription'], -2);
119                                 $rep->TextCol(2, 3,     $DisplayQty, -2);
120                                 $rep->TextCol(3, 4,     $myrow2['units'], -2);
121                                 $rep->TextCol(4, 5,     $DisplayPrice, -2);
122                                 $rep->TextCol(5, 6,     $DisplayDiscount, -2);
123                                 $rep->TextCol(6, 7,     $DisplayNet, -2);
124                                 $rep->NewLine(1);
125                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight))
126                                         $rep->Header2($myrow, $branch, $sales_order, $baccount,$j);
127                         }
128
129                         $comments = get_comments($j, $i);
130                         if ($comments && db_num_rows($comments))
131                         {
132                                 $rep->NewLine();
133                         while ($comment=db_fetch($comments))
134                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
135                         }
136
137                         $DisplaySubTot = number_format2($SubTotal,$dec);
138                         $DisplayFreight = number_format2($sign*$myrow["ov_freight"],$dec);
139
140                         $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
141                         $linetype = true;
142                         $doctype = $j;
143                         if ($rep->currency != $myrow['curr_code'])
144                         {
145                                 include($path_to_root . "reporting/includes/doctext2.inc");
146                         }
147                         else
148                         {
149                                 include($path_to_root . "reporting/includes/doctext.inc");
150                         }
151
152                         $rep->TextCol(3, 6, $doc_Sub_total, -2);
153                         $rep->TextCol(6, 7,     $DisplaySubTot, -2);
154                         $rep->NewLine();
155                         $rep->TextCol(3, 6, $doc_Shipping, -2);
156                         $rep->TextCol(6, 7,     $DisplayFreight, -2);
157                         $rep->NewLine();
158                         $tax_items = get_customer_trans_tax_details($j, $i);
159                 while ($tax_item = db_fetch($tax_items))
160                 {
161                         $DisplayTax = number_format2($sign*$tax_item['amount'], $dec);
162
163                         if ($tax_item['included_in_price'])
164                         {
165                                         $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] .
166                                                 " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2);
167                                 }
168                         else
169                         {
170                                         $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" .
171                                                 $tax_item['rate'] . "%)", -2);
172                                         $rep->TextCol(6, 7,     $DisplayTax, -2);
173                                 }
174                                 $rep->NewLine();
175                 }
176                 $rep->NewLine();
177                         $DisplayTotal = number_format2($sign*($myrow["ov_freight"] + $myrow["ov_gst"] +
178                                 $myrow["ov_amount"]+$myrow["ov_freight_tax"]),$dec);
179                         $rep->Font('bold');
180                         $rep->TextCol(3, 6, $doc_TOTAL_INVOICE, - 2);
181                         $rep->TextCol(6, 7, $DisplayTotal, -2);
182                         $rep->Font();
183                         if ($email == 1)
184                         {
185                                 $myrow['dimension_id'] = $paylink; // helper for pmt link
186                                 if ($myrow['email'] == '')
187                                 {
188                                         $myrow['email'] = $branch['email'];
189                                         $myrow['DebtorName'] = $branch['br_name'];
190                                 }
191                                 $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow, $j);
192                         }
193                 }
194         }
195         if ($email == 0)
196                 $rep->End();
197 }
198
199 ?>