Removed stock_move.person_id references from stock movements inquiry.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 6 Apr 2015 08:19:42 +0000 (10:19 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 7 Apr 2015 19:35:53 +0000 (21:35 +0200)
inventory/includes/db/movement_types_db.inc
inventory/includes/inventory_db.inc
inventory/inquiry/stock_movements.php

index 48a5d1f94af27fa8e3bf4f95fa869c04dc219197..cb5bff32d178aea0357d8c4c0b196c74f18332f0 100644 (file)
@@ -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)
 {
index 7277dde30c51ad66f59a5cf337806abe8a492031..bc70582b5fea715f6d8da5c44dffd51ebb49a73d 100644 (file)
@@ -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
index e7fb0eed31d893b157e62dd5d99ef286dc6a5140..3efdfb4232d1522a26357f60ac37035d3389d048 100644 (file)
@@ -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("<b>"._("Quantity on hand after") . " " . $_POST['BeforeDate']."</b>", "align=center colspan=$header_span");