Moving 2.0 development version to main trunk.
[fa-stable.git] / includes / ui / items_cart.inc
index 2c77babf3b4b76ad1eaf9ab01db699026418fe07..a2d3e2d2e9a971494eee82baa76baa6d5de04872 100644 (file)
@@ -1,10 +1,11 @@
 <?php
 
+include_once($path_to_root . "/includes/prefs/sysprefs.inc");
 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
 
-class items_cart 
+class items_cart
 {
-
+       var $trans_type;
        var $line_items;
        var $gl_items;
 
@@ -13,7 +14,7 @@ class items_cart
        var     $order_id;
 
        var $editing_item, $deleting_item;
-       
+
        var $from_loc;
        var $to_loc;
        var $tran_date;
@@ -23,24 +24,24 @@ 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 
+               }
+               else
                {
                        // shouldn't come here under normal circumstances
                        display_db_error("unexpected - adding an invalid item or null quantity", "", true);
@@ -51,56 +52,53 @@ 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() 
+       function count_items()
        {
                return count($this->line_items);
        }
 
        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
 
        function add_gl_item($code_id, $dimension_id, $dimension2_id, $amount, $reference, $description=null)
        {
-               if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id)  && 
+               if (isset($code_id) && $code_id != "" && isset($amount) && isset($dimension_id)  &&
                        isset($dimension2_id))
                {
-                       $this->gl_items[$this->gl_item_count] = new gl_item($this->gl_item_count, 
+                       $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 
+               }
+               else
                {
                        // shouldn't come here under normal circumstances
                        display_db_error("unexpected - adding an invalid item or null quantity", "", true);
@@ -119,7 +117,6 @@ class items_cart
                if ($description != null)
                        $this->gl_items[$index]->description = $description;
 
-               $this->clear_editing_flags();
        }
 
        function remove_gl_item($index)
@@ -127,16 +124,15 @@ class items_cart
                if (isset($index))
                {
                        unset($this->gl_items[$index]);
-                       $this->clear_editing_flags();
                }
        }
 
-       function count_gl_items() 
+       function count_gl_items()
        {
                return count($this->gl_items);
        }
 
-       function gl_items_total() 
+       function gl_items_total()
        {
                $total = 0;
                foreach ($this->gl_items as $gl_item)
@@ -144,10 +140,10 @@ class items_cart
                return $total;
        }
 
-       function gl_items_total_debit() 
+       function gl_items_total_debit()
        {
                $total = 0;
-               foreach ($this->gl_items as $gl_item) 
+               foreach ($this->gl_items as $gl_item)
                {
                        if ($gl_item->amount > 0)
                                $total += $gl_item->amount;
@@ -155,10 +151,10 @@ class items_cart
                return $total;
        }
 
-       function gl_items_total_credit() 
+       function gl_items_total_credit()
        {
                $total = 0;
-               foreach ($this->gl_items as $gl_item) 
+               foreach ($this->gl_items as $gl_item)
                {
                        if ($gl_item->amount < 0)
                                $total += $gl_item->amount;
@@ -168,7 +164,7 @@ class items_cart
 
        // ------------ common functions
 
-       function clear_items() 
+       function clear_items()
        {
        unset($this->line_items);
                $this->line_items = array();
@@ -177,39 +173,12 @@ 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);
-       }
-
 }
 
 //--------------------------------------------------------------------------------------------
 
-class line_item 
+class line_item
 {
        var $stock_id;
        var $item_description;
@@ -260,7 +229,7 @@ class line_item
                                        return null;
 
                                $qoh = get_qoh_on_date($this->stock_id, $location, $date_);
-                       if ($quantity + $qoh < 0) 
+                       if ($quantity + $qoh < 0)
                        {
                                return $this;
                        }
@@ -273,7 +242,7 @@ class line_item
 
 //---------------------------------------------------------------------------------------
 
-class gl_item 
+class gl_item
 {
 
        var $index;
@@ -284,7 +253,7 @@ class gl_item
        var $reference;
        var $description;
 
-       function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference, 
+       function gl_item($index, $code_id, $dimension_id, $dimension2_id, $amount, $reference,
                $description=null)
        {
                //echo "adding $index, $code_id, $dimension_id, $amount, $reference<br>";