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