Preparation for Excel Writer continued
[fa-stable.git] / reporting / rep105.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 2;
13 // ----------------------------------------------------------------
14 // $ Revision:  2.0 $
15 // Creator:     Joe Hunt
16 // date_:       2005-05-19
17 // Title:       Order Status List
18 // ----------------------------------------------------------------
19 $path_to_root="..";
20
21 include_once($path_to_root . "/includes/session.inc");
22 include_once($path_to_root . "/includes/date_functions.inc");
23 include_once($path_to_root . "/includes/data_checks.inc");
24 include_once($path_to_root . "/sales/includes/sales_db.inc");
25 include_once($path_to_root . "/inventory/includes/db/items_category_db.inc");
26
27 //----------------------------------------------------------------------------------------------------
28
29 print_order_status_list();
30
31 //----------------------------------------------------------------------------------------------------
32
33 function GetSalesOrders($from, $to, $category=0, $location=null, $backorder=0)
34 {
35         $fromdate = date2sql($from);
36         $todate = date2sql($to);
37
38         $sql= "SELECT ".TB_PREF."sales_orders.order_no,
39                                 ".TB_PREF."sales_orders.debtor_no,
40                 ".TB_PREF."sales_orders.branch_code,
41                 ".TB_PREF."sales_orders.customer_ref,
42                 ".TB_PREF."sales_orders.ord_date,
43                 ".TB_PREF."sales_orders.from_stk_loc,
44                 ".TB_PREF."sales_orders.delivery_date,
45                 ".TB_PREF."sales_order_details.stk_code,
46                 ".TB_PREF."stock_master.description,
47                 ".TB_PREF."stock_master.units,
48                 ".TB_PREF."sales_order_details.quantity,
49                 ".TB_PREF."sales_order_details.qty_sent
50             FROM ".TB_PREF."sales_orders
51                 INNER JOIN ".TB_PREF."sales_order_details
52                     ON ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no
53                 INNER JOIN ".TB_PREF."stock_master
54                     ON ".TB_PREF."sales_order_details.stk_code = ".TB_PREF."stock_master.stock_id
55             WHERE ".TB_PREF."sales_orders.ord_date >='$fromdate'
56                 AND ".TB_PREF."sales_orders.ord_date <='$todate'";
57         if ($category > 0)
58                 $sql .= " AND ".TB_PREF."stock_master.category_id=$category";
59         if ($location != null)
60                 $sql .= " AND ".TB_PREF."sales_orders.from_stk_loc='$location'";
61         if ($backorder)
62                 $sql .= "AND ".TB_PREF."sales_order_details.quantity - ".TB_PREF."sales_order_details.qty_sent > 0";
63         $sql .= " ORDER BY ".TB_PREF."sales_orders.order_no";
64
65         return db_query($sql, "Error getting order details");
66 }
67
68 //----------------------------------------------------------------------------------------------------
69
70 function print_order_status_list()
71 {
72         global $path_to_root;
73
74         $from = $_POST['PARAM_0'];
75         $to = $_POST['PARAM_1'];
76         $category = $_POST['PARAM_2'];
77         $location = $_POST['PARAM_3'];
78         $backorder = $_POST['PARAM_4'];
79         $comments = $_POST['PARAM_5'];
80         $destination = $_POST['PARAM_6'];
81         if ($destination)
82         {
83                 include_once($path_to_root . "/reporting/includes/excel_report.inc");
84                 $filename = "OrderStatusListing.xml";
85         }       
86         else
87         {
88                 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
89                 $filename = "OrderStatusListing.pdf";
90         }
91
92         if ($category == reserved_words::get_all_numeric())
93                 $category = 0;
94         if ($location == reserved_words::get_all())
95                 $location = null;
96         if ($category == 0)
97                 $cat = _('All');
98         else
99                 $cat = get_category_name($category);
100         if ($location == null)
101                 $loc = _('All');
102         else
103                 $loc = $location;
104         if ($backorder == 0)
105                 $back = _('All Orders');
106         else
107                 $back = _('Back Orders Only');
108
109         $cols = array(0, 60, 150, 260, 325,     385, 450, 515);
110
111         $headers2 = array(_('Order'), _('Customer'), _('Branch'), _('Customer Ref'),
112                 _('Ord Date'),  _('Del Date'),  _('Loc'));
113
114         $aligns = array('left', 'left', 'right', 'right', 'right', 'right',     'right');
115
116         $headers = array(_('Code'),     _('Description'), _('Ordered'), _('Invoiced'),
117                 _('Outstanding'), '');
118
119     $params =   array(  0 => $comments,
120                                         1 => array(  'text' => _('Period'), 'from' => $from, 'to' => $to),
121                                         2 => array(  'text' => _('Category'), 'from' => $cat,'to' => ''),
122                                         3 => array(  'text' => _('Location'), 'from' => $loc, 'to' => ''),
123                                         4 => array(  'text' => _('Selection'),'from' => $back,'to' => ''));
124
125         $cols2 = $cols;
126         $aligns2 = $aligns;
127
128         $rep = new FrontReport(_('Order Status Listing'), $filename, user_pagesize());
129         $rep->Font();
130         $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
131
132         $rep->Header();
133         $orderno = 0;
134
135         $result = GetSalesOrders($from, $to, $category, $location, $backorder);
136
137         while ($myrow=db_fetch($result))
138         {
139                 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
140                 {
141                         $orderno = 0;
142                         $rep->Header();
143                 }
144                 $rep->NewLine(0, 2, false, $orderno);
145                 if ($orderno != $myrow['order_no'])
146                 {
147                         if ($orderno != 0)
148                         {
149                                 $rep->Line($rep->row);
150                                 $rep->NewLine();
151                         }
152                         $rep->TextCol(0, 1,     $myrow['order_no']);
153                         $rep->TextCol(1, 2,     get_customer_name($myrow['debtor_no']));
154                         $rep->TextCol(2, 3,     get_branch_name($myrow['branch_code']));
155                         $rep->TextCol(3, 4,     $myrow['customer_ref']);
156                         $rep->DateCol(4, 5,     $myrow['ord_date'], true);
157                         $rep->DateCol(5, 6,     $myrow['delivery_date'], true);
158                         $rep->TextCol(6, 7,     $myrow['from_stk_loc']);
159                         $rep->NewLine(2);
160                         $orderno = $myrow['order_no'];
161                 }
162                 $rep->TextCol(0, 1,     $myrow['stk_code']);
163                 $rep->TextCol(1, 2,     $myrow['description']);
164                 $dec = get_qty_dec($myrow['stk_code']);
165                 $rep->AmountCol(2, 3, $myrow['quantity'], $dec);
166                 $rep->AmountCol(3, 4, $myrow['qty_sent'], $dec);
167                 $rep->AmountCol(4, 5, $myrow['quantity'] - $myrow['qty_sent'], $dec);
168                 if ($myrow['quantity'] - $myrow['qty_sent'] > 0)
169                 {
170                         $rep->Font('italic');
171                         $rep->TextCol(5, 6,     _('Outstanding'));
172                         $rep->Font();
173                 }
174                 $rep->NewLine();
175                 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
176                 {
177                         $orderno = 0;
178                         $rep->Header();
179                 }
180         }
181         $rep->Line($rep->row);
182         $rep->End();
183 }
184
185 ?>