Inventory Item Status



Purpose

Current and Future Item Status.

Procedure

Tips and Tricks


Demand is calculated bu the following two functions : 

<?php
$demand_qty = get_demand_qty($_POST['stock_id'], $myrow["loc_code"]);
$demand_qty += get_demand_asm_qty($_POST['stock_id'], $myrow["loc_code"]);
?>

<?php
public static function get_demand_qty($stock_id, $location)
    {
        $sql = "SELECT SUM(".TB_PREF."sales_order_details.quantity - "
        .TB_PREF."sales_order_details.qty_sent) AS QtyDemand
            FROM ".TB_PREF."sales_order_details,
                    ".TB_PREF."sales_orders
                WHERE ".TB_PREF."sales_order_details.order_no="
                .TB_PREF."sales_orders.order_no AND ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." AND
                ".TB_PREF."sales_orders.trans_type=".TB_PREF."sales_order_details.trans_type AND ";
                if ($location != "")
                $sql .= TB_PREF."sales_orders.from_stk_loc =".db_escape($location)." AND ";
                $sql .= TB_PREF."sales_order_details.stk_code = ".db_escape($stock_id);

                $result = db_query($sql,"No transactions were returned");
                $row = db_fetch($result);
                if ($row === false)
                return 0;
                return $row['QtyDemand'];
    }
?>
<?php
// recursion fixed by Tom Moulton
    function get_demand_asm_qty($stock_id, $location)
    {
        $demand_qty = 0.0;
        $sql = "SELECT ".TB_PREF."sales_order_details.stk_code, SUM(".TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent)
                   AS Demmand
                   FROM ".TB_PREF."sales_order_details,
                        ".TB_PREF."sales_orders,
                        ".TB_PREF."stock_master
                   WHERE ".TB_PREF."sales_orders.order_no = ".TB_PREF."sales_order_details.order_no AND 
                       ".TB_PREF."sales_orders.trans_type=".ST_SALESORDER." AND 
                    ".TB_PREF."sales_orders.trans_type=".TB_PREF."sales_order_details.trans_type AND ";
        if ($location != "")
        $sql .= TB_PREF."sales_orders.from_stk_loc =".db_escape($location)." AND ";
        $sql .= TB_PREF."sales_order_details.quantity-".TB_PREF."sales_order_details.qty_sent > 0 AND
                   ".TB_PREF."stock_master.stock_id=".TB_PREF."sales_order_details.stk_code AND
                   (".TB_PREF."stock_master.mb_flag='M' OR ".TB_PREF."stock_master.mb_flag='A')
                   GROUP BY ".TB_PREF."sales_order_details.stk_code";
        $result = db_query($sql, "No transactions were returned");
        while ($row = db_fetch_row($result)) {
            $demand_qty += stock_demand_manufacture($row[0], $row[1], $stock_id, $location);
        }
        return $demand_qty;
    }
?>


Database Schema


 Source Code


functions used : 

include :

Comments