From e6f7c4e9bb2b0854ffdc9e1f6b4b6beb6cefe4e6 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Sun, 5 Apr 2015 18:39:43 +0200 Subject: [PATCH] Fixed items_cart.check_qoh method (returned value, direct call to inventory checking function). --- includes/ui/items_cart.inc | 52 ++++++++++++------------------ manufacturing/work_order_issue.php | 2 +- sales/customer_delivery.php | 2 +- 3 files changed, 22 insertions(+), 34 deletions(-) diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index e2a2ca91..ecec18a2 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -95,13 +95,27 @@ class items_cart function check_qoh($location, $date_, $reverse=false) { - foreach ($this->line_items as $line_no => $line_item) - { - $item_ret = $line_item->check_qoh($location, $date_, $reverse); - if ($item_ret != null) - return $line_no; + 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)) + { + $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_no; + } } - return -1; + return $low_stock; } // ----------- GL item functions @@ -472,32 +486,6 @@ class line_item //$this->price = $price; $this->price = 0; } - - function check_qoh($location, $date_, $reverse) - { - global $SysPrefs; - - if (!$SysPrefs->allow_negative_stock()) - { - if (has_stock_holding($this->mb_flag)) - { - $quantity = $this->quantity; - if ($reverse) - $quantity = -$this->quantity; - - if ($quantity >= 0) - return null; - - $qoh = get_qoh_on_date($this->stock_id, $location, $date_); - if ($quantity + $qoh < 0) - { - return $this; - } - } - } - - return null; - } } //--------------------------------------------------------------------------------------- diff --git a/manufacturing/work_order_issue.php b/manufacturing/work_order_issue.php index a0b747e0..dfe11060 100644 --- a/manufacturing/work_order_issue.php +++ b/manufacturing/work_order_issue.php @@ -100,7 +100,7 @@ function can_process() } $failed_item = $_SESSION['issue_items']->check_qoh($_POST['Location'], $_POST['date_'], !$_POST['IssueType']); - if ($failed_item != -1) + if ($failed_item) { display_error(_("The issue cannot be processed because it would cause negative inventory balance for marked items as of document date or later.")); return false; diff --git a/sales/customer_delivery.php b/sales/customer_delivery.php index 3673b57e..422b93c0 100644 --- a/sales/customer_delivery.php +++ b/sales/customer_delivery.php @@ -203,7 +203,7 @@ function check_data() if (!$SysPrefs->allow_negative_stock() && ($low_stock = $_SESSION['Items']->check_qoh())) { - display_error(_("This document cannot be processed because there is insufficient quantity for: ").implode(',', $low_stock)); + display_error(_("This document cannot be processed because there is insufficient quantity for items marked.")); return false; } -- 2.30.2