+ if($invoice->tax_included==0) {
+ $items_added_tax = $ov_gst-$freight_tax;
+ $freight_added_tax = $freight_tax;
+ } else {
+ $items_added_tax = 0;
+ $freight_added_tax = 0;
+ }
+ // 2006-06-14. If the Customer Branch AR Account is set to a Bank Account,
+ // the transaction will be settled at once.
+ if (is_bank_account($branch_data['receivables_account']))
+ $alloc = $items_total + $items_added_tax + $invoice->freight_cost + $freight_added_tax;
+ else
+ $alloc = 0;
+
+ /* Insert/update the debtor_trans */
+ $sales_order = $invoice->order_no;
+ if (is_array($sales_order))
+ $sales_order = $sales_order[0]; // assume all crucial SO data are same for every delivery
+
+ $invoice_no = write_customer_trans(10, $trans_no, $invoice->customer_id,
+ $invoice->Branch, $date_, $invoice->reference, $items_total, 0,
+ $items_added_tax, $invoice->freight_cost, $freight_added_tax,
+ $invoice->sales_type, $sales_order, $delivery_no,
+ $invoice->ship_via, $invoice->due_date, $alloc, 0, $invoice->dimension_id, $invoice->dimension2_id);
+ // 2008-06-14 extra $alloc, 2008-11-12 added dimension_id Joe Hunt
+
+ if ($trans_no == 0) {
+ $invoice->trans_no = array($invoice_no=>0);
+ set_document_parent($invoice);
+ } else {
+ delete_comments(10, $invoice_no);
+ void_gl_trans(10, $invoice_no, true);
+ void_cust_allocations(10, $invoice_no); // ?
+ void_customer_trans_tax_details(10, $invoice_no);
+ }
+ $total = 0;
+ foreach ($invoice->line_items as $invoice_line) {