+// Stores journal/bank transaction tax details if applicable
+//
+function add_gl_tax_details($gl_code, $trans_type, $trans_no, $amount, $ex_rate, $date, $memo)
+{
+ $tax_type = is_tax_account($gl_code);
+ if(!$tax_type) return; // $gl_code is not tax account
+
+ $tax = get_tax_type($tax_type);
+ //if ($gl_code == $tax['sales_gl_code'])
+ // $amount = -$amount;
+ // we have to restore net amount as we cannot know the base amount
+ if ($tax['rate'] == 0) {
+// display_warning(_("You should not post gl transactions
+// to tax account with zero tax rate."));
+ $net_amount = 0;
+ } else {
+ // calculate net amount
+ $net_amount = $amount/$tax['rate']*100;
+ }
+
+ add_trans_tax_details($trans_type, $trans_no, $tax['id'], $tax['rate'], 0,
+ $amount, $net_amount, $ex_rate, $date, $memo);
+
+}
+
+//--------------------------------------------------------------------------------
+//
+// Store transaction tax details for fiscal purposes with 'freezed'
+// actual tax type rate.
+//
+function add_trans_tax_details($trans_type, $trans_no, $tax_id, $rate, $included,
+ $amount, $net_amount, $ex_rate, $tran_date, $memo)
+{
+
+ $sql = "INSERT INTO ".TB_PREF."trans_tax_details
+ (trans_type, trans_no, tran_date, tax_type_id, rate, ex_rate,
+ included_in_price, net_amount, amount, memo)
+ VALUES (".db_escape($trans_type)."," . db_escape($trans_no).",'"
+ .date2sql($tran_date)."',".db_escape($tax_id).","
+ .db_escape($rate).",".db_escape($ex_rate).",".($included ? 1:0).","
+ .db_escape($net_amount).","
+ .db_escape($amount).",".db_escape($memo).")";
+
+ db_query($sql, "Cannot save trans tax details");