Fixed items_cart.check_qoh method (returned value, direct call to inventory checking...
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sun, 5 Apr 2015 16:39:43 +0000 (18:39 +0200)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 6 Apr 2015 15:16:01 +0000 (17:16 +0200)
includes/ui/items_cart.inc
manufacturing/work_order_issue.php
sales/customer_delivery.php

index e2a2ca917b9a2fac75adc4559faa100053dc85d0..ecec18a29f27664f22d40d3d2464d615084f8310 100644 (file)
@@ -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;
-       }
 }
 
 //---------------------------------------------------------------------------------------
index a0b747e0630174587ce12098bccc36c610b66e45..dfe11060557d844b293b7003ffd3a7d1f4075d00 100644 (file)
@@ -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;
index 3673b57eb7f80f42e556c6ea26f52524a55f3fc1..422b93c0edff3a7d4cfeaf337fd253301af29cb8 100644 (file)
@@ -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;
        }