+ db_query($sql, "Cannot save trans tax details");
+
+}
+//----------------------------------------------------------------------------------------
+
+function get_trans_tax_details($trans_type, $trans_no)
+{
+ $sql = "SELECT ".TB_PREF."trans_tax_details.*, ".TB_PREF."tax_types.name AS tax_type_name
+ FROM ".TB_PREF."trans_tax_details,".TB_PREF."tax_types
+ WHERE trans_type = $trans_type
+ AND trans_no = $trans_no
+ AND (net_amount != 0 OR amount != 0)
+ AND ".TB_PREF."tax_types.id = ".TB_PREF."trans_tax_details.tax_type_id";
+
+ return db_query($sql, "The transaction tax details could not be retrieved");
+}
+
+//----------------------------------------------------------------------------------------
+
+function void_trans_tax_details($type, $type_no)
+{
+ $sql = "UPDATE ".TB_PREF."trans_tax_details SET amount=0, net_amount=0
+ WHERE trans_no=$type_no
+ AND trans_type=$type";
+
+ db_query($sql, "The transaction tax details could not be voided");
+}
+
+function get_tax_summary($from, $to)
+{
+ $fromdate = date2sql($from);
+ $todate = date2sql($to);
+
+ $sql = "SELECT
+ SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, net_amount*ex_rate,0)) net_output,
+ SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, amount*ex_rate,0)) payable,
+ SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 0, net_amount*ex_rate)) net_input,
+ SUM(IF( trans_type=1 || trans_type=11 || trans_type=20,-1,1)*
+ IF(trans_type=0 || trans_type=2 || trans_type=10 || trans_type=11, 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 != 13
+ 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)
+{
+ $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;
+
+ 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)