*** empty log message ***
[fa-stable.git] / reporting / rep209.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_po();
21
22 //----------------------------------------------------------------------------------------------------
23 function get_po($order_no)
24 {
25         $sql = "SELECT ".TB_PREF."purch_orders.*, ".TB_PREF."suppliers.supp_name, 
26                 ".TB_PREF."suppliers.curr_code, ".TB_PREF."suppliers.payment_terms, ".TB_PREF."locations.location_name 
27                 FROM ".TB_PREF."purch_orders, ".TB_PREF."suppliers, ".TB_PREF."locations 
28                 WHERE ".TB_PREF."purch_orders.supplier_id = ".TB_PREF."suppliers.supplier_id
29                 AND ".TB_PREF."locations.loc_code = into_stock_location 
30                 AND ".TB_PREF."purch_orders.order_no = " . $order_no;
31         $result = db_query($sql, "The order cannot be retrieved");
32     return db_fetch($result);
33 }
34
35 function get_po_details($order_no)
36 {
37         $sql = "SELECT ".TB_PREF."purch_order_details.*, units 
38                 FROM ".TB_PREF."purch_order_details 
39                 LEFT JOIN ".TB_PREF."stock_master 
40                 ON ".TB_PREF."purch_order_details.item_code=".TB_PREF."stock_master.stock_id 
41                 WHERE order_no =$order_no ";
42         $sql .= " ORDER BY po_detail_item";
43         return db_query($sql, "Retreive order Line Items");
44 }
45
46 function print_po()
47 {
48         global $path_to_root;
49         
50         include_once($path_to_root . "reporting/includes/pdf_report.inc");
51         
52         $from = $_POST['PARAM_0'];
53         $to = $_POST['PARAM_1'];
54         $currency = $_POST['PARAM_2'];
55         $bankaccount = $_POST['PARAM_3'];
56         $email = $_POST['PARAM_4'];     
57         $comments = $_POST['PARAM_5'];
58
59         if ($from == null)
60                 $from = 0;
61         if ($to == null)
62                 $to = 0;
63         $dec =user_price_dec();
64         
65         $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
66
67         // $headers in doctext.inc      
68         $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
69         
70         $params = array('comments' => $comments,
71                                         'bankaccount' => $bankaccount);
72         
73         $baccount = get_bank_account($params['bankaccount']);
74         $cur = get_company_Pref('curr_default');
75         
76         if ($email == 0)
77         {
78                 $rep = new FrontReport(_('PURCHASE ORDER'), "PurchaseOrderBulk.pdf", user_pagesize());
79                 $rep->currency = $cur;
80                 $rep->Font();
81                 $rep->Info($params, $cols, null, $aligns);
82         }
83
84         for ($i = $from; $i <= $to; $i++)
85         {
86                 $myrow = get_po($i);
87
88                 if ($email == 1)
89                 {
90                         $rep = new FrontReport("", "", user_pagesize());
91                         $rep->currency = $cur;
92                         $rep->Font();
93                         $rep->title = _('PURCHASE_ORDER');
94                         $rep->filename = "PurchaseOrder" . $i . ".pdf";
95                         $rep->Info($params, $cols, null, $aligns);
96                 }
97                 else
98                         $rep->title = _('PURCHASE ORDER');
99                 $rep->Header2($myrow, null, $myrow, $baccount, 8);
100
101                 $result = get_po_details($i);
102                 $SubTotal = 0;
103                 while ($myrow2=db_fetch($result))
104                 {
105                         $Net = ($myrow2["unit_price"] * $myrow2["quantity_ordered"]);
106                         $SubTotal += $Net;
107                         $DisplayPrice = number_format2($myrow2["unit_price"],$dec);
108                         $DisplayQty = number_format2($myrow2["quantity_ordered"],user_qty_dec());
109                         $DisplayNet = number_format2($Net,$dec);
110                         //$rep->TextCol(0, 1,   $myrow2['item_code'], -2);
111                         $rep->TextCol(0, 2,     $myrow2['description'], -2);
112                         $rep->TextCol(2, 3,     $myrow2['delivery_date'], -2);
113                         $rep->TextCol(3, 4,     $DisplayQty, -2);
114                         $rep->TextCol(4, 5,     $myrow2['units'], -2);
115                         $rep->TextCol(5, 6,     $DisplayPrice, -2);
116                         $rep->TextCol(6, 7,     $DisplayNet, -2);
117                         $rep->NewLine(1);
118                         if ($rep->row < $rep->bottomMargin + (15 * $rep->lineHeight)) 
119                                 $rep->Header2($myrow, $branch, $sales_order, $baccount);
120                 }
121                 if ($myrow['comments'] != "")
122                 {
123                         $rep->NewLine();
124                         $rep->TextColLines(1, 5, $myrow['comments'], -2);
125                 }       
126                 $DisplaySubTot = number_format2($SubTotal,$dec);
127
128                 $rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
129                 $linetype = true;
130                 $doctype = 8;
131                 if ($rep->currency != $myrow['curr_code'])
132                 {
133                         include($path_to_root . "reporting/includes/doctext2.inc");                     
134                 }       
135                 else
136                 {
137                         include($path_to_root . "reporting/includes/doctext.inc");                      
138                 }       
139
140                 $rep->TextCol(3, 6, $doc_Sub_total, -2);
141                 $rep->TextCol(6, 7,     $DisplaySubTot, -2);
142                 $rep->NewLine();
143                 $DisplayTotal = number_format2($SubTotal, $dec);
144                 $rep->Font('bold');     
145                 $rep->TextCol(3, 6, $doc_TOTAL_PO, - 2);
146                 $rep->TextCol(6, 7,     $DisplayTotal, -2);
147                 $rep->Font();   
148                 if ($email == 1)
149                 {
150                         if ($myrow['contact_email'] == '')
151                         {
152                                 $myrow['contact_email'] = $branch['email'];
153                                 $myrow['DebtorName'] = $branch['br_name'];
154                         }
155                         $rep->End($email, $doc_Invoice_no . " " . $myrow['reference'], $myrow);
156                 }       
157         }
158         if ($email == 0)
159                 $rep->End();
160 }
161
162 ?>