+function get_tax_summary($from, $to)
+{
+ $fromdate = date2sql($from);
+ $todate = date2sql($to);
+
+ $sql = "SELECT
+ SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
+ IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", net_amount*ex_rate,0)) net_output,
+ SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
+ IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", amount*ex_rate,0)) payable,
+ SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
+ IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", 0, net_amount*ex_rate)) net_input,
+ SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE.",-1,1)*
+ IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE." || trans_type=".ST_CUSTCREDIT.", 0, amount*ex_rate)) collectible,
+ taxrec.rate,
+ ttype.id,
+ ttype.name
+ FROM ".TB_PREF."tax_types ttype,
+ ".TB_PREF."trans_tax_details taxrec
+ WHERE taxrec.tax_type_id=ttype.id
+ AND taxrec.trans_type != ".ST_CUSTDELIVERY."
+ AND taxrec.tran_date >= '$fromdate'
+ AND taxrec.tran_date <= '$todate'
+ GROUP BY ttype.id";
+//display_error($sql);
+ return db_query($sql,"Cannot retrieve tax summary");
+}
+
+//--------------------------------------------------------------------------------
+// Write/update journal entries.
+//
+function write_journal_entries(&$cart, $reverse, $use_transaction=true)
+{
+ global $Refs;
+
+ $date_ = $cart->tran_date;
+ $ref = $cart->reference;
+ $memo_ = $cart->memo_;
+ $new = $cart->order_id == 0;
+ $trans_type = $cart->trans_type;
+ $trans_id = $new ? get_next_trans_no($trans_type) : $cart->order_id;
+
+ if ($use_transaction)
+ begin_transaction();
+
+ if($new) {
+ $cart->order_id = $trans_id;
+ } else {
+ void_journal_trans($trans_type, $trans_id, true);
+ delete_comments($trans_type, $trans_id);
+ }
+
+ foreach ($cart->gl_items as $journal_item)