1 (edited by kvvaradha 01/23/2019 09:45:54 am)

Topic: items_cart class has a logical bug, should be fixed.

The items_cart.inc looks like this function

function check_qoh($location, $date_, $reverse=false)
    {
        global $SysPrefs;

        $low_stock = array();

        if (!$SysPrefs->allow_negative_stock() || is_fixed_asset($line_items->mb_flag))
        {
            foreach ($this->line_items as $line_no => $line_item)
                if (has_stock_holding($line_item->mb_flag) || is_fixed_asset($line_item->mb_flag))
                {
                    $quantity = $line_item->quantity;
                    if ($reverse)
                        $quantity = -$line_item->quantity;

                    if ($quantity >= 0)
                        continue;

                    if (check_negative_stock($line_item->stock_id, $quantity, $location, $date_))
                        $low_stock[] = $line_item->stock_id;
                }
        }
        return $low_stock;
    }

But here  is the bug,

if (!$SysPrefs->allow_negative_stock() || is_fixed_asset($line_items->mb_flag))

Probably the is_fixed_asset($line_items->mb_flag) is invalid to put it here. we already checking that inside for loop.  Also the object $line_items->mb_flag is not available.  so change the function like this.

function check_qoh($location, $date_, $reverse=false)
    {
        global $SysPrefs;

        $low_stock = array();
        if (!$SysPrefs->allow_negative_stock())
        {
            foreach ($this->line_items as $line_no => $line_item)
                if (has_stock_holding($line_item->mb_flag) || is_fixed_asset($line_item->mb_flag))
                {
                    $quantity = $line_item->quantity;
                    if ($reverse)
                        $quantity = -$line_item->quantity;

                    if ($quantity >= 0)
                        continue;

                    if (check_negative_stock($line_item->stock_id, $quantity, $location, $date_))
                        $low_stock[] = $line_item->stock_id;
                }
        }
        return $low_stock;
    }

Hope that fixes the undefined noin-object error

Subscription service based on FA
HRM CRM POS batch Themes

Re: items_cart class has a logical bug, should be fixed.

This has been fixed and committed to repo. Thanks @kvvaradha for detecting this.

A new file for replacement can be downloaded here.

Joe