4 // ----------------------------------------------------------------
8 // Title: Order Status List
9 // ----------------------------------------------------------------
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");
18 //----------------------------------------------------------------------------------------------------
20 // trial_inquiry_controls();
21 print_order_status_list();
23 //----------------------------------------------------------------------------------------------------
25 function GetSalesOrders($from, $to, $category=0, $location=null, $backorder=0)
27 $fromdate = date2sql($from);
28 $todate = date2sql($to);
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'";
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'";
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";
57 return db_query($sql, "Error getting order details");
60 //----------------------------------------------------------------------------------------------------
62 function print_order_status_list()
66 include_once($path_to_root . "reporting/includes/pdf_report.inc");
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'];
75 $dec = user_qty_dec();
77 if ($category == reserved_words::get_all_numeric())
79 if ($location == reserved_words::get_all())
84 $cat = get_category_name($category);
85 if ($location == null)
90 $back = _('All Orders');
92 $back = _('Back Orders Only');
94 $cols = array(0, 60, 150, 260, 325, 385, 450, 515);
96 $headers2 = array(_('Order'), _('Customer'), _('Branch'), _('Customer Ref'),
97 _('Ord Date'), _('Del Date'), _('Loc'));
99 $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right');
101 $headers = array(_('Code'), _('Description'), _('Ordered'), _('Invoiced'),
102 _('Outstanding'), '');
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' => ''));
113 $rep = new FrontReport(_('Order Status Listing'), "OrderStatusListing.pdf", user_pagesize());
115 $rep->Info($params, $cols, $headers, $aligns, $cols2, $headers2, $aligns2);
120 $result = GetSalesOrders($from, $to, $category, $location, $backorder);
122 while ($myrow=db_fetch($result))
124 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
129 $rep->NewLine(0, 2, false, $orderno);
130 if ($orderno != $myrow['order_no'])
134 $rep->Line($rep->row);
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']);
145 $orderno = $myrow['order_no'];
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)
154 $rep->Font('italic');
155 $rep->TextCol(5, 6, _('Outstanding'));
159 if ($rep->row < $rep->bottomMargin + (2 * $rep->lineHeight))
165 $rep->Line($rep->row);