Merged bugfixes since 2.0.6
[fa-stable.git] / includes / ui / items_cart.inc
index da1917df971d657be0caf9333bdf0e5e0ccdd19f..8afd898103fb39ad8d3bae8c0b1df1974987d6fc 100644 (file)
@@ -1,11 +1,20 @@
 <?php
-
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU Affero General Public License,
+       AGPL, as published by the Free Software Foundation, either version 
+       3 of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/agpl-3.0.html>.
+***********************************************************************/
 include_once($path_to_root . "/includes/prefs/sysprefs.inc");
 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
 
 class items_cart
 {
-
+       var $trans_type;
        var $line_items;
        var $gl_items;
 
@@ -24,21 +33,21 @@ class items_cart
        var $person_id;
        var $branch_id;
 
-       function items_cart()
+       function items_cart($type)
        {
+               $this->trans_type = $type;
                $this->clear_items();
        }
 
        // --------------- line item functions
 
-       function add_to_cart($stock_id, $qty, $standard_cost, $description=null)
+       function add_to_cart($line_no, $stock_id, $qty, $standard_cost, $description=null)
        {
 
                if (isset($stock_id) && $stock_id != "" && isset($qty))
                {
-                       $this->line_items[$stock_id] = new line_item($stock_id, $qty,
+                       $this->line_items[$line_no] = new line_item($stock_id, $qty,
                                $standard_cost, $description);
-                       $this->clear_editing_flags();
                        return true;
                }
                else
@@ -52,25 +61,22 @@ class items_cart
 
        function find_cart_item($stock_id)
        {
-               if (isset($this->line_items[$stock_id]) && $this->line_items[$stock_id] != null)
-                       return $this->line_items[$stock_id];
+               foreach($this->line_items as $line_no=>$line) {
+                       if ($line->stock_id == $stock_id)
+                               return $this->line_items[$line_no];
+               }
                return null;
        }
 
-       function update_cart_item($update_item, $qty, $standard_cost)
+       function update_cart_item($line_no, $qty, $standard_cost)
        {
-               $this->line_items[$update_item]->quantity = $qty;
-               $this->line_items[$update_item]->standard_cost = $standard_cost;
-               $this->clear_editing_flags();
+               $this->line_items[$line_no]->quantity = $qty;
+               $this->line_items[$line_no]->standard_cost = $standard_cost;
        }
 
-       function remove_from_cart(&$stock_id)
+       function remove_from_cart($line_no)
        {
-               if (isset($stock_id))
-               {
-                       unset($this->line_items[$stock_id]);
-                       $this->clear_editing_flags();
-               }
+               array_splice($this->line_items, $line_no, 1);
        }
 
        function count_items()
@@ -80,12 +86,13 @@ class items_cart
 
        function check_qoh($location, $date_, $reverse=false)
        {
-               foreach ($this->line_items as $line_item)
+               foreach ($this->line_items as $line_no => $line_item)
                {
                        $item_ret = $line_item->check_qoh($location, $date_, $reverse);
                        if ($item_ret != null)
-                               return $line_item;
+                               return $line_no;
                }
+               return -1;
        }
 
        // ----------- GL item functions
@@ -98,13 +105,12 @@ class items_cart
                        $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count,
                                $code_id, $dimension_id, $dimension2_id, $amount, $reference, $description);
                        $this->gl_item_count++;
-                       $this->clear_editing_flags();
                        return true;
                }
                else
                {
                        // shouldn't come here under normal circumstances
-                       display_db_error("unexpected - adding an invalid item or null quantity", "", true);
+                       display_db_error("unexpected - invalid parameters in add_gl_item($code_id, $dimension_id, $dimension2_id, $amount,...)", "", true);
                }
 
                return false;
@@ -120,15 +126,13 @@ class items_cart
                if ($description != null)
                        $this->gl_items[$index]->description = $description;
 
-               $this->clear_editing_flags();
        }
 
        function remove_gl_item($index)
        {
                if (isset($index))
                {
-                       unset($this->gl_items[$index]);
-                       $this->clear_editing_flags();
+                       array_splice($this->gl_items, $line_no, 1);
                }
        }
 
@@ -178,34 +182,7 @@ class items_cart
                $this->gl_items = array();
                $this->gl_item_count = 1;
 
-               $this->clear_editing_flags();
-       }
-
-       function clear_editing_flags()
-       {
-               $this->editing_item = $this->deleting_item = 0;
-       }
-
-       function get_editing_item()
-       {
-               return $this->editing_item;
-       }
-
-       function get_deleting_item()
-       {
-               return $this->deleting_item;
        }
-
-       function is_editing_item($index)
-       {
-               return ($this->editing_item > 0) && ($this->editing_item == $index);
-       }
-
-       function is_deleting_item($index)
-       {
-               return ($this->deleting_item > 0) && ($this->deleting_item == $index);
-       }
-
 }
 
 //--------------------------------------------------------------------------------------------