X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fcart_class.inc;h=4b01809feba94a838edcec70a395ef0c93241c61;hb=1e4cd218cd0b7e1093b4b63d6636f5360b3c7958;hp=3cf9c5fc811eb8052392fd26d4425832866d63f7;hpb=d963dd95bd75b4b6c7c32bbc2cb36943e5a46a33;p=fa-stable.git diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index 3cf9c5fc..4b01809f 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -104,6 +104,9 @@ class cart $this->trans_type = $type; $this->reference = $Refs->get_next($this->trans_type); + if ($type == ST_CUSTCREDIT) + $this->src_date = $this->document_date; + $this->document_date = new_doc_date(); for($line_no = 0; $line_no < count($this->line_items); $line_no++) { @@ -124,9 +127,6 @@ class cart $this->due_date = get_invoice_duedate($this->payment, $this->document_date); } - if ($type == ST_CUSTCREDIT) - $this->src_date = $this->document_date; - $this->src_docs = $this->trans_no; $this->trans_no = 0; } @@ -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['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; } } @@ -244,10 +243,18 @@ class cart // $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 direct document - first add parent $ref = $this->reference; $date = $this->document_date; + $due_date = $this->due_date; + $dimension_id = $this->dimension_id; + $dimension2_id = $this->dimension2_id; $this->trans_type = get_parent_type($this->trans_type); $this->reference = 'auto'; @@ -257,6 +264,9 @@ class cart $this->read($this->trans_type, $trans_no, true); $this->document_date = $date; $this->reference = $ref; + $this->due_date = $due_date; + $this->dimension_id = $dimension_id; + $this->dimension2_id = $dimension2_id; } $this->reference = @html_entity_decode($this->reference, ENT_QUOTES); $this->Comments = @html_entity_decode($this->Comments, ENT_QUOTES); @@ -486,7 +496,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']; } }