*** empty log message ***
[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         $comments = $_POST['PARAM_5'];
36
37         if ($from == null)
38                 $from = 0;
39         if ($to == null)
40                 $to = 0;
41         $dec =user_price_dec();
42         
43         $fno = explode("-", $from);
44         $tno = explode("-", $to);
45
46         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
47
48         // $headers in doctext.inc      
49         $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
50         
51         $params = array('comments' => $comments,
52                                         'bankaccount' => $bankaccount);
53         
54         $baccount = get_bank_account($params['bankaccount']);
55         $cur = get_company_Pref('curr_default');
56         
57         if ($email == 0)
58         {
59                 $rep = new FrontReport(_('INVOICE'), "InvoiceBulk.pdf", user_pagesize());
60                 $rep->currency = $cur;
61                 $rep->Font();
62                 $rep->Info($params, $cols, null, $aligns);
63         }
64
65         for ($i = $fno[0]; $i <= $tno[0]; $i++)
66         {
67                 for ($j = 10; $j <= 11; $j++)
68                 {
69                         if (!exists_customer_trans($j, $i))
70                                 continue;
71                         $myrow = get_customer_trans($i, $j);
72                         $branch = get_branch($myrow["branch_code"]);
73                         if ($j == 10)
74                                 $sales_order = get_sales_order($myrow["order_"]);
75                         else
76                                 $sales_order = null;
77                         if ($email == 1)
78                         {
79                                 $rep = new FrontReport("", "", user_pagesize());
80                                 $rep->currency = $cur;
81                                 $rep->Font();
82                                 if ($j == 10)
83                                 {
84                                         $rep->title = _('INVOICE');
85                                         $rep->filename = "Invoice" . $myrow['reference'] . ".pdf";
86                                 }
87                                 else    
88                                 {
89                                         $rep->title = _('CREDIT NOTE');
90                                         $rep->filename = "CreditNote" . $myrow['reference'] . ".pdf";
91                                 }       
92                                 $rep->Info($params, $cols, null, $aligns);
93                         }
94                         else
95                                 $rep->title = ($j == 10) ? _('INVOICE') : _('CREDIT NOTE');
96                         $rep->Header2($myrow, $branch, $sales_order, $baccount, $j);
97                         
98                         $result = get_customer_trans_details($j, $i);
99                         $SubTotal = 0;
100                         while ($myrow2=db_fetch($result))
101                         {
102                                 $Net = ((1 - $myrow2["discount_percent"]) * $myrow2["FullUnitPrice"] * -$myrow2["quantity"]);
103                                 $SubTotal += $Net;
104                         $DisplayPrice = number_format2($myrow2["FullUnitPrice"],$dec);
105                         $DisplayQty = number_format2(-$myrow2["quantity"],user_qty_dec());
106                         $DisplayNet = number_format2($Net,$dec);
107                         if ($myrow2["discount_percent"]==0)
108                                         $DisplayDiscount ="";
109                         else 
110                                         $DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";
111                                 $rep->TextCol(0, 1,     $myrow2['stock_id'], -2);
112                                 $rep->TextCol(1, 2,     $myrow2['StockDescription'], -2);
113                                 $rep->TextCol(2, 3,     $DisplayQty, -2);
114                                 $rep->TextCol(3, 4,     $myrow2['units'], -2);
115                                 $rep->TextCol(4, 5,     $DisplayPrice, -2);
116                                 $rep->TextCol(5, 6,     $DisplayDiscount, -2);
117                                 $rep->TextCol(6, 7,     $DisplayNet, -2);
118                                 $rep->NewLine(1);
119                                 if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight)) 
120                                         $rep->Header2($myrow, $branch, $sales_order, $baccount);
121                         }
122                         
123                         $comments = get_comments($j, $i);
124                         if ($comments && db_num_rows($comments))
125                         {       
126                                 $rep->NewLine();
127                         while ($comment=db_fetch($comments)) 
128                                 $rep->TextColLines(0, 6, $comment['memo_'], -2);
129                         }       
130                                 
131                         $DisplaySubTot = number_format2($SubTotal,$dec);
132                         $DisplayFreight = number_format2($myrow["ov_freight"],$dec);
133
134                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
135                         $linetype = true;
136                         $doctype = $j;
137                         if ($rep->currency != $myrow['curr_code'])
138                         {
139                                 include($path_to_root . "reporting/includes/doctext2.inc");                     
140                         }       
141                         else
142                         {
143                                 include($path_to_root . "reporting/includes/doctext.inc");                      
144                         }       
145                 
146                         $rep->TextCol(3, 6, $doc_Sub_total, -2);
147                         $rep->TextCol(6, 7,     $DisplaySubTot, -2);
148                         $rep->NewLine();
149                         $rep->TextCol(3, 6, $doc_Shipping, -2);
150                         $rep->TextCol(6, 7,     $DisplayFreight, -2);
151                         $rep->NewLine();
152                         $tax_items = get_customer_trans_tax_details($j, $i);
153                 while ($tax_item = db_fetch($tax_items)) 
154                 {
155                         $DisplayTax = number_format2($tax_item['amount'], $dec);
156                         if ($tax_item['included_in_price'])
157                         {
158                                         $rep->TextCol(3, 7, $doc_Included . " " . $tax_item['tax_type_name'] . 
159                                                 " (" . $tax_item['rate'] . "%) " . $doc_Amount . ":" . $DisplayTax, -2);
160                                 }               
161                         else
162                         {
163                                         $rep->TextCol(3, 6, $tax_item['tax_type_name'] . " (" . 
164                                                 $tax_item['rate'] . "%)", -2);
165                                         $rep->TextCol(6, 7,     $DisplayTax, -2);
166                                 }                       
167                                 $rep->NewLine();
168                 }
169                 $rep->NewLine();
170                         $DisplayTotal = number_format2($myrow["ov_freight"] + $myrow["ov_gst"] +
171                                 $myrow["ov_amount"],$dec);
172                         $rep->Font('bold');     
173                         $rep->TextCol(3, 6, $doc_TOTAL_INVOICE, - 2);
174                         $rep->TextCol(6, 7,     $DisplayTotal, -2);
175                         $rep->Font();   
176                         if ($email == 1)
177                         {
178                                 if ($myrow['email'] == '')
179                                 {
180                                         $myrow['email'] = $branch['email'];
181                                         $myrow['DebtorName'] = $branch['br_name'];
182                                 }
183                                 $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow, $j);
184                         }       
185                 }
186         }
187         if ($email == 0)
188                 $rep->End();
189 }
190
191 ?>