}
function get_sql_for_po_search_completed($from, $to, $supplier_id=ALL_TEXT, $location=ALL_TEXT,
- $order_number = '', $stock_id = '')
+ $order_number = '', $stock_id = '', $also_closed=false)
{
$sql = "SELECT
porder.order_no,
porder.ord_date,
supplier.curr_code,
Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
- porder.into_stock_location
- FROM ".TB_PREF."purch_orders as porder, "
+ porder.into_stock_location,
+ chk.isopen
+ FROM ".TB_PREF."purch_orders as porder
+ LEFT JOIN (
+ SELECT order_no, SUM(quantity_ordered-quantity_received + quantity_ordered-qty_invoiced) isopen
+ FROM ".TB_PREF."purch_order_details
+ GROUP BY order_no
+ ) chk ON chk.order_no=porder.order_no,"
.TB_PREF."purch_order_details as line, "
.TB_PREF."suppliers as supplier, "
.TB_PREF."locations as location
}
+ if (!$also_closed)
+ $sql .= " AND isopen";
$sql .= " GROUP BY porder.order_no";
return $sql;
}
Sum(line.unit_price*line.quantity_ordered) AS OrderValue,
Sum(line.delivery_date < '". date2sql(Today()) ."'
AND (line.quantity_ordered > line.quantity_received)) As OverDue
- FROM "
- .TB_PREF."purch_orders as porder, "
+ FROM ".TB_PREF."purch_orders as porder,"
.TB_PREF."purch_order_details as line, "
.TB_PREF."suppliers as supplier, "
.TB_PREF."locations as location
$js .= get_js_date_picker();
page(_($help_context = "Search Purchase Orders"), false, false, "", $js);
+//---------------------------------------------------------------------------------------------
+function trans_view($trans)
+{
+ return get_trans_view_str(ST_PURCHORDER, $trans["order_no"]);
+}
+
+function edit_link($row)
+{
+ global $page_nested;
+
+ return $page_nested || !$row['isopen'] ? '' :
+ trans_editor_link(ST_PURCHORDER, $row["order_no"]);
+}
+
+function prt_link($row)
+{
+ return print_document_link($row['order_no'], _("Print"), true, 18, ICON_PRINT);
+}
+
if (isset($_GET['order_number']))
{
$_POST['order_number'] = $_GET['order_number'];
if (!$page_nested)
supplier_list_cells(_("Select a supplier: "), 'supplier_id', null, true, true);
+check_cells(_('Also closed:'), 'also_closed', check_value('also_closed'));
+
submit_cells('SearchOrders', _("Search"),'',_('Select documents'), 'default');
end_row();
end_table(1);
-//---------------------------------------------------------------------------------------------
-if (isset($_POST['order_number']))
-{
- $order_number = $_POST['order_number'];
-}
-
-if (isset($_POST['SelectStockFromList']) && ($_POST['SelectStockFromList'] != "") &&
- ($_POST['SelectStockFromList'] != ALL_TEXT))
-{
- $selected_stock_item = $_POST['SelectStockFromList'];
-}
-else
-{
- unset($selected_stock_item);
-}
-//---------------------------------------------------------------------------------------------
-
-function trans_view($trans)
-{
- return get_trans_view_str(ST_PURCHORDER, $trans["order_no"]);
-}
-
-function edit_link($row)
-{
- global $page_nested;
-
- return $page_nested ? '' :
- trans_editor_link(ST_PURCHORDER, $row["order_no"]);
-}
-
-function prt_link($row)
-{
- return print_document_link($row['order_no'], _("Print"), true, 18, ICON_PRINT);
-}
//---------------------------------------------------------------------------------------------
$sql = get_sql_for_po_search_completed(get_post('OrdersAfterDate'), get_post('OrdersToDate'),
- get_post('supplier_id'), get_post('StockLocation'), get_post('order_number'), get_post('SelectStockFromList'));
+ get_post('supplier_id'), get_post('StockLocation'), get_post('order_number'),
+ get_post('SelectStockFromList'), get_post('also_closed'));
$cols = array(
_("#") => array('fun'=>'trans_view', 'ord'=>''),