Rewritten non-sql list selectors
[fa-stable.git] / includes / ui / items_cart.inc
index da1917df971d657be0caf9333bdf0e5e0ccdd19f..fb2ac021694058ed01d676935ebb70fe15951122 100644 (file)
@@ -5,7 +5,7 @@ include_once($path_to_root . "/inventory/includes/inventory_db.inc");
 
 class items_cart
 {
-
+       var $trans_type;
        var $line_items;
        var $gl_items;
 
@@ -24,21 +24,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 +52,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();
-               }
+                       unset($this->line_items[$line_no]);
        }
 
        function count_items()
@@ -80,11 +77,11 @@ 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;
                }
        }
 
@@ -98,7 +95,6 @@ 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
@@ -120,7 +116,6 @@ class items_cart
                if ($description != null)
                        $this->gl_items[$index]->description = $description;
 
-               $this->clear_editing_flags();
        }
 
        function remove_gl_item($index)
@@ -128,7 +123,6 @@ class items_cart
                if (isset($index))
                {
                        unset($this->gl_items[$index]);
-                       $this->clear_editing_flags();
                }
        }
 
@@ -178,34 +172,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);
-       }
-
 }
 
 //--------------------------------------------------------------------------------------------