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