9e8c4936ab76d0bf0395454353f2ac0200569649
[fa-stable.git] / reporting / rep105.php
1 <?php
2
3 $page_security = 2;
4 // ----------------------------------------------------------------
5 // $ Revision:  2.0 $
6 // Creator:     Joe Hunt
7 // date_:       2005-05-19
8 // Title:       Order Status List
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 include_once($path_to_root . "inventory/includes/db/items_category_db.inc");
17
18 //----------------------------------------------------------------------------------------------------
19
20 // trial_inquiry_controls();
21 print_order_status_list();
22
23 //----------------------------------------------------------------------------------------------------
24
25 function GetSalesOrders($from, $to, $category=0, $location=null, $backorder=0)
26 {
27         $fromdate = date2sql($from);
28         $todate = date2sql($to);
29         
30         $sql= "SELECT ".TB_PREF."sales_orders.order_no,
31                                 ".TB_PREF."sales_orders.debtor_no,
32                 ".TB_PREF."sales_orders.branch_code,
33                 ".TB_PREF."sales_orders.customer_ref,
34                 ".TB_PREF."sales_orders.ord_date,
35                 ".TB_PREF."sales_orders.from_stk_loc,
36                 ".TB_PREF."sales_orders.delivery_date,
37                 ".TB_PREF."sales_order_details.stk_code,
38                 ".TB_PREF."stock_master.description,
39                 ".TB_PREF."stock_master.units,
40                 ".TB_PREF."sales_order_details.quantity,
41                 ".TB_PREF."sales_order_details.qty_invoiced
42             FROM ".TB_PREF."sales_orders
43                 INNER JOIN ".TB_PREF."sales_order_details
44                     ON ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
45                 INNER JOIN ".TB_PREF."stock_master
46                     ON ".TB_PREF."sales_order_details.stk_code = ".TB_PREF."stock_master.stock_id
47             WHERE ".TB_PREF."sales_orders.ord_date >='$fromdate'
48                 AND ".TB_PREF."sales_orders.ord_date <='$todate'";
49         if ($category > 0)
50                 $sql .= " AND ".TB_PREF."stock_master.category_id=$category";
51         if ($location != null)
52                 $sql .= " AND ".TB_PREF."sales_orders.from_stk_loc='$location'";
53         if ($backorder)
54                 $sql .= "AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_invoiced > 0";
55         $sql .= " ORDER BY ".TB_PREF."sales_orders.order_no";   
56         
57         return db_query($sql, "Error getting order details");
58 }
59         
60 //----------------------------------------------------------------------------------------------------
61
62 function print_order_status_list()
63 {
64         global $path_to_root;
65         
66         include_once($path_to_root . "reporting/includes/pdf_report.inc");
67         
68         $from = $_POST['PARAM_0'];
69         $to = $_POST['PARAM_1'];
70         $category = $_POST['PARAM_2'];
71         $location = $_POST['PARAM_3'];
72         $backorder = $_POST['PARAM_4'];
73         $comments = $_POST['PARAM_5'];
74
75         $dec = user_qty_dec();
76         
77         if ($category == reserved_words::get_all_numeric())
78                 $category = 0;
79         if ($location == reserved_words::get_all())
80                 $location = null;
81         if ($category == 0)
82                 $cat = _('All');
83         else
84                 $cat = get_category_name($category);
85         if ($location == null)
86                 $loc = _('All');
87         else
88                 $loc = $location;
89         if ($backorder == 0)
90                 $back = _('All Orders');
91         else
92                 $back = _('Back Orders Only');
93                 
94         $cols = array(0, 60, 150, 260, 325,     385, 450, 515);
95         
96         $headers2 = array(_('Order'), _('Customer'), _('Branch'), _('Customer Ref'),
97                 _('Ord Date'),  _('Del Date'),  _('Loc'));
98         
99         $aligns = array('left', 'left', 'right', 'right', 'right', 'right',     'right');
100
101         $headers = array(_('Code'),     _('Description'), _('Ordered'), _('Invoiced'),
102                 _('Outstanding'), _(' '));
103     
104     $params =   array(  0 => $comments,
105                                         1 => array(  'text' => _('Period'), 'from' => $from, 'to' => $to),
106                                         2 => array(  'text' => _('Category'), 'from' => $cat,'to' => ''),
107                                         3 => array(  'text' => _('Location'), 'from' => $loc, 'to' => ''),
108                                         4 => array(  'text' => _('Selection'),'from' => $back,'to' => ''));
109
110         $cols2 = $cols;
111         $aligns2 = $aligns;
112         
113         $rep = new FrontReport(_('Order Status Listing'), "OrderStatusListing.pdf", user_pagesize());
114         $rep->Font();
115         $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
116
117         $rep->Header();
118         $orderno = 0;
119
120         $result = GetSalesOrders($from, $to, $category, $location, $backorder);
121         
122         while ($myrow=db_fetch($result))
123         {
124                 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
125                 {
126                         $orderno = 0;
127                         $rep->Header();
128                 }       
129                 $rep->NewLine(0, 2, false, $orderno);
130                 if ($orderno != $myrow['order_no'])
131                 {
132                         if ($orderno != 0)
133                         {
134                                 $rep->Line($rep->row);
135                                 $rep->NewLine();
136                         }
137                         $rep->TextCol(0, 1,     $myrow['order_no']);
138                         $rep->TextCol(1, 2,     get_customer_name($myrow['debtor_no']));
139                         $rep->TextCol(2, 3,     get_branch_name($myrow['branch_code']));
140                         $rep->TextCol(3, 4,     $myrow['customer_ref']);
141                         $rep->TextCol(4, 5,     sql2date($myrow['ord_date']));
142                         $rep->TextCol(5, 6,     sql2date($myrow['delivery_date']));
143                         $rep->TextCol(6, 7,     $myrow['from_stk_loc']);
144                         $rep->NewLine(2);
145                         $orderno = $myrow['order_no'];                  
146                 }
147                 $rep->TextCol(0, 1,     $myrow['stk_code']);
148                 $rep->TextCol(1, 2,     $myrow['description']);
149                 $rep->TextCol(2, 3,     number_format2($myrow['quantity'], $dec));
150                 $rep->TextCol(3, 4,     number_format2($myrow['qty_invoiced'], $dec));
151                 $rep->TextCol(4, 5,     number_format2($myrow['quantity'] - $myrow['qty_invoiced'], $dec));
152                 if ($myrow['quantity'] - $myrow['qty_invoiced'] > 0)
153                 {
154                         $rep->Font('italic');
155                         $rep->TextCol(5, 6,     _('Outstanding'));
156                         $rep->Font();
157                 }       
158                 $rep->NewLine();
159                 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
160                 {
161                         $orderno = 0;
162                         $rep->Header();
163                 }       
164         }               
165         $rep->Line($rep->row);
166         $rep->End();
167 }
168
169 ?>