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
//$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;
- }
}
//---------------------------------------------------------------------------------------
}
$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;
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;
}