-
- $branch_data = get_branch_accounts($invoice->Branch);
-
- $invoice_items_total = $invoice->get_items_total_dispatch($tax_group_id);
-
- $tax_total = 0;
- $taxes = $invoice->get_taxes($tax_group_id, $charge_shipping);
- foreach ($taxes as $taxitem)
- $tax_total += $taxitem['Value'];
-
- /*Now insert the debtor_trans */
-
- $invoice_no = add_customer_trans(10, $invoice->customer_id, $invoice->Branch, $date_,
- $reference, $invoice_items_total, 0, $tax_total, $charge_shipping,
- $sales_type, $sales_order, $ship_via, $due_date);
-
- // If balance of the order cancelled update sales order details quantity.
- foreach ($invoice->line_items as $order_line)
+
+ $branch_data = get_branch_accounts($invoice->Branch);
+
+ $customer = get_customer($invoice->customer_id);
+
+ add_new_exchange_rate($customer['curr_code'], $date_, $invoice->ex_rate);
+
+ // offer price values without freight costs
+ $items_total = $invoice->get_items_total_dispatch();
+ $freight_tax = $invoice->get_shipping_tax();
+
+ if (!$invoice->is_prepaid())
+ update_customer_trans_version(get_parent_type(ST_SALESINVOICE), $invoice->src_docs);
+
+ $ov_gst = 0;
+ $taxes = $invoice->get_taxes(); // all taxes with freight_tax
+ $dec = user_price_dec();
+ foreach ($taxes as $taxitem) {
+ $taxitem['Value'] = round2($taxitem['Value'], $dec);
+ $ov_gst += $taxitem['Value'];
+ }
+
+ 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;
+ }
+
+ /* 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
+
+ if ($trans_no) {
+ $allocs = get_payments_for($trans_no, ST_SALESINVOICE);
+ delete_comments(ST_SALESINVOICE, $trans_no);
+ void_gl_trans(ST_SALESINVOICE, $trans_no, true);
+ void_trans_tax_details(ST_SALESINVOICE, $trans_no);
+ } else
+ $allocs = get_payments_for($invoice->order_no, ST_SALESORDER);
+
+ if ($invoice->is_prepaid()) // selected prepayment is already in cart