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 = 'SA_SALESBULKREP';
13 // ----------------------------------------------------------------
17 // Title: Order Status List
18 // ----------------------------------------------------------------
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");
27 //----------------------------------------------------------------------------------------------------
29 print_order_status_list();
31 //----------------------------------------------------------------------------------------------------
33 function GetSalesOrders($from, $to, $category=0, $location=null, $backorder=0)
35 $fromdate = date2sql($from);
36 $todate = date2sql($to);
38 $sql= "SELECT sorder.order_no,
51 FROM ".TB_PREF."sales_orders sorder
52 INNER JOIN ".TB_PREF."sales_order_details line
53 ON sorder.order_no = line.order_no
54 AND sorder.trans_type = line.trans_type
55 AND sorder.trans_type = ".ST_SALESORDER."
56 INNER JOIN ".TB_PREF."stock_master item
57 ON line.stk_code = item.stock_id
58 WHERE sorder.ord_date >='$fromdate'
59 AND sorder.ord_date <='$todate'";
61 $sql .= " AND item.category_id=".db_escape($category);
62 if ($location != null)
63 $sql .= " AND sorder.from_stk_loc=".db_escape($location);
65 $sql .= " AND line.quantity - line.qty_sent > 0";
66 $sql .= " ORDER BY sorder.order_no";
68 return db_query($sql, "Error getting order details");
71 //----------------------------------------------------------------------------------------------------
73 function print_order_status_list()
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 $orientation = $_POST['PARAM_6'];
84 $destination = $_POST['PARAM_7'];
86 include_once($path_to_root . "/reporting/includes/excel_report.inc");
88 include_once($path_to_root . "/reporting/includes/pdf_report.inc");
89 $orientation = ($orientation ? 'L' : 'P');
91 if ($category == ALL_NUMERIC)
93 if ($location == ALL_TEXT)
98 $cat = get_category_name($category);
99 if ($location == null)
102 $loc = get_location_name($location);
104 $back = _('All Orders');
106 $back = _('Back Orders Only');
108 $cols = array(0, 60, 150, 260, 325, 385, 450, 515);
110 $headers2 = array(_('Order'), _('Customer'), _('Branch'), _('Customer Ref'),
111 _('Ord Date'), _('Del Date'), _('Loc'));
113 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right');
115 $headers = array(_('Code'), _('Description'), _('Ordered'), _('Delivered'),
116 _('Outstanding'), '', _('Total Amount'));
118 $params = array( 0 => $comments,
119 1 => array( 'text' => _('Period'), 'from' => $from, 'to' => $to),
120 2 => array( 'text' => _('Category'), 'from' => $cat,'to' => ''),
121 3 => array( 'text' => _('Location'), 'from' => $loc, 'to' => ''),
122 4 => array( 'text' => _('Selection'),'from' => $back,'to' => ''));
126 $rep = new FrontReport(_('Order Status Listing'), "OrderStatusListing", user_pagesize(), 9, $orientation);
127 if ($orientation == 'L')
128 recalculate_cols($cols);
131 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
137 $result = GetSalesOrders($from, $to, $category, $location, $backorder);
138 while ($myrow=db_fetch($result))
140 $rep->NewLine(0, 2, false, $orderno);
141 if ($orderno != $myrow['order_no'])
145 $rep->Line($rep->row);
148 $rep->TextCol(0, 1, $myrow['order_no']);
149 $rep->TextCol(1, 2, get_customer_name($myrow['debtor_no']));
150 $rep->TextCol(2, 3, get_branch_name($myrow['branch_code']));
151 $rep->TextCol(3, 4, $myrow['customer_ref']);
152 $rep->DateCol(4, 5, $myrow['ord_date'], true);
153 $rep->DateCol(5, 6, $myrow['delivery_date'], true);
154 $rep->TextCol(6, 7, $myrow['from_stk_loc']);
156 $rep->AmountCol(6, 7, $myrow['total']);
158 $grand_total += $myrow['total'];
159 $orderno = $myrow['order_no'];
161 $rep->TextCol(0, 1, $myrow['stk_code']);
162 $rep->TextCol(1, 2, $myrow['description']);
163 $dec = get_qty_dec($myrow['stk_code']);
164 $rep->AmountCol(2, 3, $myrow['quantity'], $dec);
165 $rep->AmountCol(3, 4, $myrow['qty_sent'], $dec);
166 $rep->AmountCol(4, 5, $myrow['quantity'] - $myrow['qty_sent'], $dec);
167 if ($myrow['quantity'] - $myrow['qty_sent'] > 0)
169 $rep->Font('italic');
170 $rep->TextCol(5, 6, _('Outstanding'));
175 $rep->Line($rep->row);
177 $rep->TextCol(1, 6, _("Grand Total"));
178 $rep->AmountCol(6, 7, $grand_total);
179 $rep->Line($rep->row - 5);