Record status edition added.
[fa-stable.git] / sales / includes / cart_class.inc
index 628ab43a3ea5e3fd34ea59ed2f03db2b65e769db..f388b54cac18e438ba4c17d63eb5db614642814c 100644 (file)
@@ -1,5 +1,14 @@
 <?php
-
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       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/gpl-3.0.html>.
+***********************************************************************/
 /* Definition of the cart class
 this class can hold all the information for:
 
@@ -17,7 +26,7 @@ class cart
        var $trans_type; // invoice, order, delivery note ...
        var $trans_no = array();// array (num1=>ver1,..) or 0 for new
        var $so_type = 0;               // for sales order: simple=0 template=1
-
+       var $cart_id;           // used to detect multi-tab edition conflits
        var $line_items;  //array of objects of class line_details
 
        var $src_docs = array();        // array of arrays(num1=>ver1,...) or 0 for no src
@@ -77,6 +86,7 @@ class cart
                $this->dimension_id = 0;
                $this->dimension2_id = 0;
                $this->read($type, $trans_no, $view );
+               $this->cart_id = uniqid('');
        }
 
        //-------------------------------------------------------------------------
@@ -141,7 +151,7 @@ class cart
                                  $this->customer_id = get_global_customer();
                                else
                                  $this->customer_id = '';
-                               $this->document_date = Today();
+                               $this->document_date =  new_doc_date();
                                if (!is_date_in_fiscalyear($this->document_date))
                                        $this->document_date = end_fiscalyear();
                                $this->reference = references::get_next($this->trans_type);
@@ -179,7 +189,7 @@ class cart
                                if ($this->cash) {
                                        $this->Location = $pos['pos_location'];
                                        $this->location_name = $pos['location_name'];
-                                       $this->cash_account = $pos['account_code'];
+                                       $this->cash_account = $pos['pos_account'];
                                        $this->account_name = $pos['bank_account_name'];
                                }
                                } else
@@ -212,15 +222,11 @@ class cart
                        $this->trans_no = 0;
                        $this->order_no= $this->trans_type==13 ? key($src->trans_no) : $src->order_no;
                }
-// if we want to save old or derivative document first decode html entities
-// from text fields. For new documents this is not needed.
-               if ($this->trans_no || $this->trans_type != 30) {
-                       $this->reference = @html_entity_decode($this->reference);
-                       $this->Comments = @html_entity_decode($this->Comments);
-                       foreach($this->line_items as $lineno => $line) {
-                               $this->line_items[$lineno]->stock_id = @html_entity_decode($line->stock_id);
-                               $this->line_items[$lineno]->description = @html_entity_decode($line->description);
-                       }
+               $this->reference = @html_entity_decode($this->reference);
+               $this->Comments = @html_entity_decode($this->Comments);
+               foreach($this->line_items as $lineno => $line) {
+                       $this->line_items[$lineno]->stock_id = @html_entity_decode($line->stock_id);
+                       $this->line_items[$lineno]->item_description = @html_entity_decode($line->item_description);
                }
                switch($this->trans_type) {
                        case 10:
@@ -291,8 +297,10 @@ class cart
                return 0;
        }
 
-       function update_cart_item($line_no, $qty, $price, $disc)
+       function update_cart_item($line_no, $qty, $price, $disc, $description="")
        {
+               if ($description != "")
+                       $this->line_items[$line_no]->item_description = $description;
                $this->line_items[$line_no]->quantity = $qty;
                $this->line_items[$line_no]->qty_dispatched = $qty;
                $this->line_items[$line_no]->price = $price;
@@ -306,7 +314,7 @@ class cart
 
        function remove_from_cart($line_no)
        {
-               unset($this->line_items[$line_no]);
+               array_splice($this->line_items, $line_no, 1);
        }
 
        function clear_items()