From e789a00c4f056bdd5badcbab2931f4ddfe519b79 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Mon, 6 Apr 2015 10:19:42 +0200 Subject: [PATCH] Removed stock_move.person_id references from stock movements inquiry. --- inventory/includes/db/movement_types_db.inc | 22 --------- inventory/includes/inventory_db.inc | 28 ++++++++++++ inventory/inquiry/stock_movements.php | 50 +++++---------------- 3 files changed, 40 insertions(+), 60 deletions(-) diff --git a/inventory/includes/db/movement_types_db.inc b/inventory/includes/db/movement_types_db.inc index 48a5d1f9..cb5bff32 100644 --- a/inventory/includes/db/movement_types_db.inc +++ b/inventory/includes/db/movement_types_db.inc @@ -49,28 +49,6 @@ function delete_movement_type($type_id) db_query($sql, "could not delete item movement type"); } -function get_stock_movements($stock_id, $StockLocation, $BeforeDate, $AfterDate) -{ - $before_date = date2sql($BeforeDate); - $after_date = date2sql($AfterDate); - $sql = "SELECT type, trans_no, tran_date, person_id, qty, reference"; - - if(!$StockLocation) { - $sql .= ", loc_code"; - } - $sql.= " FROM ".TB_PREF."stock_moves - WHERE"; - - if ($StockLocation) { - $sql.= " loc_code=".db_escape($StockLocation)." AND"; - } - - $sql.= " tran_date >= '". $after_date . "' - AND tran_date <= '" . $before_date . "' - AND stock_id = ".db_escape($stock_id) . " ORDER BY tran_date,trans_id"; - - return db_query($sql, "could not query stock moves"); -} function get_stock_movements_before($stock_id, $StockLocation, $AfterDate) { diff --git a/inventory/includes/inventory_db.inc b/inventory/includes/inventory_db.inc index 7277dde3..bc70582b 100644 --- a/inventory/includes/inventory_db.inc +++ b/inventory/includes/inventory_db.inc @@ -31,6 +31,34 @@ function item_img_name($stock_id) return clean_file_name($stock_id); } +function get_stock_movements($stock_id, $StockLocation, $BeforeDate, $AfterDate) +{ + $before_date = date2sql($BeforeDate); + $after_date = date2sql($AfterDate); + $sql = "SELECT move.*, IF(ISNULL(supplier.supplier_id), debtor.name, supplier.supp_name) name"; + + if(!$StockLocation) { + $sql .= ", move.loc_code"; + } + $sql.= " FROM ".TB_PREF."stock_moves move + LEFT JOIN ".TB_PREF."supp_trans credit ON credit.trans_no=move.trans_no AND credit.type=move.type + LEFT JOIN ".TB_PREF."grn_batch grn ON grn.id=move.trans_no AND 25=move.type + LEFT JOIN ".TB_PREF."suppliers supplier ON IFNULL(grn.supplier_id, credit.supplier_id)=supplier.supplier_id + LEFT JOIN ".TB_PREF."debtor_trans cust_trans ON cust_trans.trans_no=move.trans_no AND cust_trans.type=move.type + LEFT JOIN ".TB_PREF."debtors_master debtor ON cust_trans.debtor_no=debtor.debtor_no + WHERE"; + + if ($StockLocation) { + $sql.= " move.loc_code=".db_escape($StockLocation)." AND"; + } + + $sql.= " move.tran_date >= '". $after_date . "' + AND move.tran_date <= '" . $before_date . "' + AND move.stock_id = ".db_escape($stock_id) . " ORDER BY move.tran_date, move.trans_id"; + + return db_query($sql, "could not query stock moves"); +} + function calculate_reorder_level($location, $line, &$st_ids, &$st_names, &$st_num, &$st_reorder) { $sql = "SELECT ".TB_PREF."loc_stock.*, ".TB_PREF."locations.location_name, ".TB_PREF."locations.email diff --git a/inventory/inquiry/stock_movements.php b/inventory/inquiry/stock_movements.php index e7fb0eed..3efdfb42 100644 --- a/inventory/inquiry/stock_movements.php +++ b/inventory/inquiry/stock_movements.php @@ -38,7 +38,8 @@ if (isset($_GET['stock_id'])) $_POST['stock_id'] = $_GET['stock_id']; } -start_form(); +if (!@$_GET['popup']) + start_form(); if (!isset($_POST['stock_id'])) $_POST['stock_id'] = get_global_stock_item(); @@ -76,14 +77,16 @@ $result = get_stock_movements($_POST['stock_id'], $_POST['StockLocation'], div_start('doc_tbl'); start_table(TABLESTYLE); $th = array(_("Type"), _("#"), _("Reference")); -if($display_location) array_push($th, _("Location")); -array_push($th, _("Date"), _("Detail"), _("Quantity In"), _("Quantity Out"), _("Quantity On Hand")); +if ($display_location) + array_push($th, _("Location")); + +array_push($th, _("Date"), _("Detail"), _("Quantity In"), _("Quantity Out"), _("Quantity On Hand")); table_header($th); -$before_qty = get_stock_movements_before($_POST['stock_id'], $_POST['StockLocation'], $_POST['AfterDate']); - +$before_qty = get_qoh_on_date($_POST['stock_id'], $_POST['StockLocation'], add_days($_POST['AfterDate'], -1)); + $after_qty = $before_qty; /* @@ -132,57 +135,28 @@ while ($myrow = db_fetch($result)) label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"])); label_cell(get_trans_view_str($myrow["type"], $myrow["trans_no"], $myrow["reference"])); + if($display_location) { label_cell($myrow['loc_code']); } label_cell($trandate); - $person = $myrow["person_id"]; $gl_posting = ""; - if (($myrow["type"] == ST_CUSTDELIVERY) || ($myrow["type"] == ST_CUSTCREDIT)) - { - $cust_row = get_customer_details_from_trans($myrow["type"], $myrow["trans_no"]); - - if (strlen($cust_row['name']) > 0) - $person = $cust_row['name'] . " (" . $cust_row['br_name'] . ")"; - - } - elseif ($myrow["type"] == ST_SUPPRECEIVE || $myrow['type'] == ST_SUPPCREDIT) - { - // get the supplier name - $supp_name = get_supplier_name($myrow["person_id"]); - - if (strlen($supp_name) > 0) - $person = $supp_name; - } - elseif ($myrow["type"] == ST_LOCTRANSFER || $myrow["type"] == ST_INVADJUST) - { - // get the adjustment type - $movement_type = get_movement_type($myrow["person_id"]); - $person = $movement_type["name"]; - } - elseif ($myrow["type"]==ST_WORKORDER || $myrow["type"] == ST_MANUISSUE || - $myrow["type"] == ST_MANURECEIVE) - { - $person = ""; - } - - label_cell($person); + label_cell($myrow['name']); label_cell((($myrow["qty"] >= 0) ? $quantity_formatted : ""), "nowrap align=right"); label_cell((($myrow["qty"] < 0) ? $quantity_formatted : ""), "nowrap align=right"); qty_cell($after_qty, false, $dec); end_row(); + $j++; - If ($j == 12) + if ($j == 12) { $j = 1; table_header($th); } -//end of page full new headings if } -//end of while loop start_row("class='inquirybg'"); label_cell(""._("Quantity on hand after") . " " . $_POST['BeforeDate']."", "align=center colspan=$header_span"); -- 2.30.2