X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=sales%2Fincludes%2Fcart_class.inc;h=64a237f320aa824db88f3377e653e6615cbc7132;hb=84ebe8b3ebc1fc3e6508d75a4f39ce4a868b0b14;hp=f476088e023bf23eaf1087751980fbee3c3d334b;hpb=32549fac62977059b645de22b5ec5cf5cd7c3153;p=fa-stable.git diff --git a/sales/includes/cart_class.inc b/sales/includes/cart_class.inc index f476088e..64a237f3 100644 --- a/sales/includes/cart_class.inc +++ b/sales/includes/cart_class.inc @@ -71,7 +71,8 @@ class cart var $payment; var $payment_terms; // cached payment terms var $credit; - + var $ex_rate; + //------------------------------------------------------------------------- // // $trans_no==0 => open new/direct document @@ -92,7 +93,28 @@ class cart $this->read($type, $trans_no, $prep_child); $this->cart_id = uniqid(''); } - + + /* + Optional sorting items by stock_id. + */ + function _cmp_lines($a, $b) + { + return strcmp($a->stock_id, $b->stock_id); + } + + /* + Returns items array optionally sorted by item code. + */ + function get_items() + { + global $sort_sales_items; + + $items = $this->line_items; + if (@$sort_sales_items) + uasort($items, array($this, '_cmp_lines')); + + return $items; + } // // Prepare cart to new child document entry, just after initial parent doc read. // @@ -104,6 +126,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 +149,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; } @@ -243,10 +265,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'; @@ -256,6 +286,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); @@ -485,7 +518,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']; } }