Costed Inventory Movement Report: fixed regression after changes in stock_moves.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 6 May 2015 15:24:23 +0000 (17:24 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 6 May 2015 15:24:23 +0000 (17:24 +0200)
reporting/rep308.php

index feb92d78903353caf7b4074fffdea6e4666b32ff..53f8195eecdb1b57db556fc89e809c4fd312efaa 100644 (file)
@@ -126,7 +126,7 @@ function avg_unit_cost($stock_id, $location=null, $to_date)
                        AND move.tran_date < '$to_date' AND standard_cost > 0.001 AND qty <> 0 AND move.type <> ".ST_LOCTRANSFER;
 
        if ($location != '')
-               $sql .= " AND loc_code = ".db_escape($location);
+               $sql .= " AND move.loc_code = ".db_escape($location);
        $sql .= " ORDER BY tran_date";  
 
        $result = db_query($sql, "No standard cost transactions were returned");
@@ -163,12 +163,18 @@ function trans_qty_unit_cost($stock_id, $location=null, $from_date, $to_date, $i
 
        $to_date = date2sql($to_date);
 
-       $sql = "SELECT standard_cost, tran_date, qty FROM ".TB_PREF."stock_moves
+       $sql = "SELECT move.*, IF(ISNULL(supplier.supplier_id), debtor.debtor_no, supplier.supplier_id) person_id
+               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 stock_id=".db_escape($stock_id)."
-               AND tran_date <= '$to_date' AND standard_cost > 0.001 AND qty <> 0 AND type <> ".ST_LOCTRANSFER;
+               AND move.tran_date <= '$to_date' AND standard_cost > 0.001 AND qty <> 0 AND move.type <> ".ST_LOCTRANSFER;
 
        if ($location != '')
-               $sql .= " AND loc_code = ".db_escape($location);
+               $sql .= " AND move.loc_code = ".db_escape($location);
 
        if ($inward)
                $sql .= " AND qty > 0 ";