+ $taxes = get_trans_tax_details($type, $trans_no);
+ while ($detail = db_fetch($taxes))
+ {
+ $tax_id = $detail['tax_type_id'];
+ $tax_info['net_amount'][$tax_id] = $detail['net_amount']; // we can two records for the same tax_id, but in this case net_amount is the same
+ $tax_info['tax_date'] = sql2date($detail['tran_date']);
+ //$tax_info['tax_group'] = $detail['tax_group_id'];
+
+ }
+ if (isset($tax_info['net_amount'])) // guess exempt sales/purchase if any tax has been found
+ {
+ $net_sum = 0;
+ foreach($cart->gl_items as $gl)
+ if (!is_tax_account($gl->code_id) && !is_subledger_account($gl->code_id, $gl->person_id))
+ $net_sum += $gl->amount;
+
+ $ex_net = abs($net_sum) - array_sum($tax_info['net_amount']);
+ if ($ex_net > 0)
+ $tax_info['net_amount_ex'] = $ex_net;
+ }
+ $cart->tax_info = $tax_info;
+
+ } else {
+ $cart->tran_date = $cart->doc_date = $cart->event_date = new_doc_date();
+ if (!is_date_in_fiscalyear($cart->tran_date))
+ $cart->tran_date = end_fiscalyear();
+ $cart->reference = $Refs->get_next(ST_JOURNAL, null, $cart->tran_date);
+ }
+
+ $_POST['memo_'] = $cart->memo_;
+ $_POST['ref'] = $cart->reference;
+ $_POST['date_'] = $cart->tran_date;
+ $_POST['event_date'] = $cart->event_date;
+ $_POST['doc_date'] = $cart->doc_date;
+ $_POST['currency'] = $cart->currency;
+ $_POST['_ex_rate'] = exrate_format($cart->rate);
+ $_POST['source_ref'] = $cart->source_ref;
+ if (isset($cart->tax_info['net_amount']) || (!$trans_no && get_company_pref('default_gl_vat')))
+ $_POST['taxable_trans'] = true;
+ $_SESSION['journal_items'] = &$cart;