Better check for duplicate references in multiuser environments for sales documents.
[fa-stable.git] / sales / includes / cart_class.inc
index f7a41567a4fc45d341e32fe650caa090fc5ca67e..633093675fd722258faec739f32f4d3a0a2f153a 100644 (file)
@@ -145,7 +145,7 @@ class cart
                // that child line_items contains subset of parent lines in _the_same_ order !
                while (($line_no < count($this->line_items)) && ($srcline = db_fetch($srcdetails))) {
                        $line = &$this->line_items[$line_no];
-                       $src_docs[] = $srcline['trans_type']==ST_SALESORDER ?  $srcline['order_no'] : $srcline['debtor_trans_no'];
+                       $src_docs[] = $src_type == ST_SALESORDER ?  $srcline['order_no'] : $srcline['debtor_trans_no'];
                        if ($srcline['id'] == $line->src_id) {
                                if ($this->trans_type == ST_SALESINVOICE)
                                        $line->src_no = $srcline['debtor_trans_no'];
@@ -153,7 +153,6 @@ class cart
                                $line->quantity += $srcline['quantity'] - 
                                        ($src_type==ST_SALESORDER ? $srcline['qty_sent'] : $srcline['qty_done']); // add free qty on src doc
                                $line_no++;
-                               break;
                        }
                }
 
@@ -248,6 +247,7 @@ class cart
                        // this is direct document - first add parent
                        $ref = $this->reference;
                        $date = $this->document_date;
+                       $due_date = $this->due_date;
                        $this->trans_type = get_parent_type($this->trans_type);
 
                        $this->reference = 'auto'; 
@@ -257,8 +257,14 @@ class cart
                        $this->read($this->trans_type, $trans_no, true); 
                        $this->document_date = $date;
                        $this->reference = $ref;
+                       $this->due_date = $due_date;
                }
                $this->reference = @html_entity_decode($this->reference, ENT_QUOTES);
+               if ($this->reference != 'auto' && $this->trans_no == 0 && !is_new_reference($this->reference, $this->trans_type))
+               {
+                       commit_transaction();
+                       return -1;
+               }       
                $this->Comments = @html_entity_decode($this->Comments, ENT_QUOTES);
                foreach($this->line_items as $lineno => $line) {
                        $this->line_items[$lineno]->stock_id = @html_entity_decode($line->stock_id, ENT_QUOTES);
@@ -486,7 +492,7 @@ class cart
                if ($tax_items != null) {
                        foreach ($tax_items as $item_tax) {
                                $index = $item_tax['tax_type_id'];
-                               if (isset($this->tax_group_array[$index])) {
+                               if (isset($this->tax_group_array[$index]['rate'])) {
                                        $tax_rate += $item_tax['rate'];
                                }
                        }