+ }
+ // post currency roundings if any
+ if ($check_balance && floatcmp($total_gl, 0))
+ add_gl_trans($this->trans_type, $this->order_id, $this->tran_date,
+ get_company_pref($total_gl>0 ? 'rounding_db_act' : 'rounding_cr_act'), 0, 0, _('Exchange rate roundings'), -$total_gl);
+
+ // update bank ledger if used
+ foreach($bank_trans as $bank_id => $amount)
+ add_bank_trans($this->trans_type, $this->order_id, $bank_id, $this->reference,
+ $this->tran_date, $amount, 0, "", $this->currency,
+ "Cannot insert a destination bank transaction");
+
+ // add AP/AR for journal transaction
+ if ($this->trans_type == ST_JOURNAL)
+ {
+ // update AR
+ foreach($cust_trans as $branch_id => $amount)
+ if (floatcmp($amount, 0))
+ write_cust_journal($this->trans_type, $this->order_id, $branch_id, $this->tran_date,
+ $this->reference, -$amount, $this->rate);
+ // update AP
+ foreach($supp_trans as $supp_id => $amount)
+ if (floatcmp($amount, 0))
+ write_supp_journal($this->trans_type, $this->order_id, $supp_id, $this->tran_date,
+ $this->reference, -$amount, $this->rate, $this->source_ref);
+ }
+
+ // generate tax records for journal transaction
+ if ($this->trans_type == ST_JOURNAL && is_array($this->tax_info))
+ {
+ foreach($this->tax_info['net_amount'] as $tax_id => $net)
+ {
+ if (!$net)
+ continue;
+
+ // in EU VAT system intra-community goods aquisition is posted to both purchasing and sales tax accounts,
+ // but included only in purchase register. To avoid double registering ELSE is used below!
+ if (isset($this->tax_info['tax_in'][$tax_id]))
+ {
+ $tax = $this->tax_info['tax_in'][$tax_id];
+ $reg = TR_INPUT;
+ }
+ elseif (isset($this->tax_info['tax_out'][$tax_id]))
+ {
+ $tax = $this->tax_info['tax_out'][$tax_id];
+ $reg = TR_OUTPUT;
+ }
+ elseif (isset($this->tax_info['tax_reg'])) // e.g. export
+ {
+ $tax = 0;
+ $reg = $this->tax_info['tax_reg'];
+ } else
+ continue;
+
+ $tax_nominal = $this->tax_info['rate'][$tax_id]/100*$net;
+ add_trans_tax_details($this->trans_type, $this->order_id,
+ $tax_id, $this->tax_info['rate'][$tax_id], 0, $tax_nominal, $net, $this->rate,
+ $this->tran_date,
+ $this->source_ref,
+ $this->tax_info['tax_group'],
+ $this->tax_info['tax_date'],
+ $tax, $this->tax_info['tax_category'], 0, $reg);
+ }
+ }
+ }