Merged changes from stable branch up to 2.3.12
[fa-stable.git] / sales / includes / cart_class.inc
index fe2130d38a7384cb0834d390144d396805694abb..501ab6a93120346b69ec13acf685719d6b8f9668 100644 (file)
@@ -254,7 +254,13 @@ class cart
        // Makes parent documents for direct delivery/invoice by recurent call.
        // $policy - 0 or 1:  writeoff/return for IV, back order/cancel for DN
        function write($policy=0) {
+
                begin_transaction(); // prevents partial database changes in case of direct delivery/invoice
+               if ($this->reference != 'auto' && $this->trans_no == 0 && !is_new_reference($this->reference, $this->trans_type))
+               {
+                       commit_transaction();
+                       return -1;
+               }
                if (count($this->src_docs) == 0 && ($this->trans_type == ST_SALESINVOICE || $this->trans_type == ST_CUSTDELIVERY) && !$this->is_prepaid()) {
                        // this is direct document - first add parent
                        $ref = $this->reference;