}
}
add_trans_tax_details($trans_type, $trans_no, $tax['id'], $tax['rate'], $included,
- $amount, $net_amount, $ex_rate, $date, $memo);
+ $amount, $net_amount, $ex_rate, $date, $memo, null);
}
// 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)
+ $amount, $net_amount, $ex_rate, $tran_date, $memo, $reg_type=null)
{
+ // guess tax register if not set
+ if (!isset($reg_type))
+ $reg_type = in_array($trans_type, array(ST_SUPPINVOICE, ST_SUPPCREDIT)) ? TR_OUTPUT
+ : in_array($trans_type, array(ST_SALESINVOICE, ST_CUSTCREDIT)) ? TR_INPUT : null;
$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)
+ included_in_price, net_amount, amount, memo, reg_type)
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_escape($amount).",".db_escape($memo).",".db_escape($reg_type, true).")";
db_query($sql, "Cannot save trans tax details");
db_query($sql, "The transaction tax details could not be cleared");
}
-function get_tax_summary($from, $to)
+function get_tax_summary($from, $to, $also_zero_purchases=false)
{
$fromdate = date2sql($from);
$todate = date2sql($to);
$sql = "SELECT
- SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE
- ." || trans_type=".ST_JOURNAL.",-1,1)*
- IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
- ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
- ." || trans_type=".ST_CUSTCREDIT.", net_amount*ex_rate,0)) net_output,
-
- SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE
- ." || trans_type=".ST_JOURNAL.",-1,1)*
- IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
- ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
- ." || trans_type=".ST_CUSTCREDIT.", amount*ex_rate,0)) payable,
-
- SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE." || trans_type=".ST_JOURNAL.",-1,1)*
- IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
- ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
- ." || trans_type=".ST_CUSTCREDIT.", 0, net_amount*ex_rate)) net_input,
-
- SUM(IF(trans_type=".ST_CUSTCREDIT." || trans_type=".ST_SUPPINVOICE." || trans_type=".ST_JOURNAL.",-1,1)*
- IF(trans_type=".ST_BANKDEPOSIT." || trans_type=".ST_SALESINVOICE
- ." || (trans_type=".ST_JOURNAL ." AND amount<0)"
- ." || trans_type=".ST_CUSTCREDIT.", 0, amount*ex_rate)) collectible,
+ SUM(IF(trans_type=".ST_SUPPCREDIT.",-1,1)*IF(taxrec.amount, taxrec.effective_amount/taxrec.amount, 1)*
+ IF((reg_type=".TR_OUTPUT.")"
+ ." || ((trans_type IN(".ST_SUPPINVOICE.",".ST_SUPPCREDIT.") OR (trans_type=".ST_JOURNAL." AND reg_type=".TR_INPUT."))
+ ), net_amount*ex_rate,0)
+ ) net_output,
+
+ SUM(IF(trans_type=".ST_SUPPCREDIT.",-1,1)*
+ IF((reg_type=".TR_OUTPUT.")"
+ ." || ((trans_type IN(".ST_SUPPINVOICE.",".ST_SUPPCREDIT.") OR (trans_type=".ST_JOURNAL." AND reg_type=".TR_INPUT."))
+ ), amount*ex_rate,0)) payable,
+
+ SUM(IF(trans_type IN(".ST_SUPPCREDIT."),-1,1)*
+ IF(reg_type=".TR_INPUT
+ . ($also_zero_purchases ? '': " AND tax_type_id AND taxrec.rate")
+ .", net_amount*ex_rate, 0)) net_input,
+
+ SUM(IF(trans_type IN(".ST_SUPPCREDIT."),-1,1)*
+ IF(reg_type=".TR_INPUT
+ . ($also_zero_purchases ? '': " AND tax_type_id AND taxrec.rate ")
+ .", amount*ex_rate, 0)) 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."
+ FROM ".TB_PREF."trans_tax_details taxrec LEFT JOIN ".TB_PREF."tax_types ttype ON taxrec.tax_type_id=ttype.id
+ LEFT JOIN ".TB_PREF."tax_groups tgroup ON taxrec.tax_group_id=tgroup.id
+ WHERE taxrec.trans_type IN (".implode(',',
+ array(ST_SALESINVOICE, ST_CUSTCREDIT, ST_SUPPINVOICE, ST_SUPPCREDIT, ST_JOURNAL)).")
AND taxrec.tran_date >= '$fromdate'
AND taxrec.tran_date <= '$todate'
GROUP BY ttype.id";
-//display_error($sql);
+
+ // display_error($sql);
return db_query($sql,"Cannot retrieve tax summary");
}
-
//--------------------------------------------------------------------------------------------------
function exists_gl_trans($type, $trans_id)
gl.tran_date,
gl.type as trans_type,
gl.type_no as trans_no,
- IFNULL(max(supp.supp_name), max(cust.name)) as name,
+ IFNULL(MAX(supp.supp_name), MAX(cust.name)) as name,
IF(ISNULL(st.supp_reference), '', st.supp_reference) AS supp_reference,
refs.reference,"
.($dimension ? " -SUM(IF(dim.dimension in(gl.dimension_id,gl.dimension2_id), gl.amount, 0)) as amount,":" SUM(IF(gl.amount>0, gl.amount,0)) as amount,")
if ($myrow['alloc'] != 0 || get_voided_entry(ST_SALESINVOICE, $row["trans_no"]) !== false)
$ok = false;
}
- return $ok ? trans_editor_link($row["trans_type"], $row["trans_type"]) : '';
+ return $ok ? trans_editor_link( $row["trans_type"], $row["trans_no"]) : '';
+}
+
+function invoice_supp_reference($row)
+{
+ return $row['supp_reference'];
}
$sql = get_sql_for_journal_inquiry(get_post('filterType', -1), get_post('FromDate'),
_("Type") => array('fun'=>'systype_name'),
_("Trans #") => array('fun'=>'view_link'),
_("Counterparty") => array('ord' => ''),
+ _("Supplier's Reference") => 'skip',
_("Reference"),
_("Amount") => array('type'=>'amount'),
_("Memo"),
$cols[_("#")] = 'skip';
}
+if($_POST['filterType'] == ST_SUPPINVOICE) //add the payment column if shown supplier invoices only
+{
+ $cols[_("Supplier's Reference")] = array('fun'=>'invoice_supp_reference', 'align'=>'center');
+}
+
$table =& new_db_pager('journal_tbl', $sql, $cols);
$table->width = "80%";
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);
+ $this->source_ref, $reg);
}
}
}
}
add_trans_tax_details($trans_type, $invoice_id,
$taxitem['tax_type_id'], $taxitem['rate'], $supp_trans->tax_included, $taxitem['Value'],
- $taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference);
+ $taxitem['Net'], $ex_rate, $date_, $supp_trans->supp_reference, TR_INPUT);
if (isset($taxitem['purchasing_gl_code']))
{
LEFT JOIN ".TB_PREF."debtors_master as debt ON dtrans.debtor_no=debt.debtor_no
LEFT JOIN ".TB_PREF."cust_branch as branch ON dtrans.branch_code=branch.branch_code
WHERE (taxrec.amount <> 0 OR taxrec.net_amount <> 0)
- AND taxrec.trans_type <> ".ST_CUSTDELIVERY."
+ AND !ISNULL(taxrec.reg_type)
AND taxrec.tran_date >= '$fromdate'
AND taxrec.tran_date <= '$todate'
ORDER BY taxrec.trans_type, taxrec.tran_date, taxrec.trans_no, taxrec.ex_rate";
$rep->NewPage();
}
}
- if ($trans['trans_type']==ST_JOURNAL && $trans['amount']<0) {
+ if ($trans['trans_type']==ST_JOURNAL && $trans['reg_type']==TR_INPUT) {
$taxes[$trans['tax_type_id']]['taxin'] += $trans['amount'];
$taxes[$trans['tax_type_id']]['in'] += $trans['net_amount'];
}
- elseif ($trans['trans_type']==ST_JOURNAL && $trans['amount']>=0) {
+ elseif ($trans['trans_type']==ST_JOURNAL && $trans['reg_type']==TR_OUTPUT) {
$taxes[$trans['tax_type_id']]['taxout'] += $trans['amount'];
$taxes[$trans['tax_type_id']]['out'] += $trans['net_amount'];
}
elseif (in_array($trans['trans_type'], array(ST_BANKDEPOSIT,ST_SALESINVOICE,ST_CUSTCREDIT))) {
$taxes[$trans['tax_type_id']]['taxout'] += $trans['amount'];
$taxes[$trans['tax_type_id']]['out'] += $trans['net_amount'];
- } else {
+ } elseif ($trans['reg_type'] !== NULL) {
$taxes[$trans['tax_type_id']]['taxin'] += $trans['amount'];
$taxes[$trans['tax_type_id']]['in'] += $trans['net_amount'];
}
add_trans_tax_details(ST_CUSTCREDIT, $credit_no, $taxitem['tax_type_id'],
$taxitem['rate'], $credit_note->tax_included, $taxitem['Value'],
$taxitem['Net'], $ex_rate,
- $credit_note->document_date, $credit_note->reference);
+ $credit_note->document_date, $credit_note->reference, TR_OUTPUT);
$total += add_gl_trans_customer(ST_CUSTCREDIT, $credit_no, $credit_date, $taxitem['sales_gl_code'], 0, 0,
$taxitem['Value'], $credit_note->customer_id,
$ex_rate = get_exchange_rate_from_home_currency(get_customer_currency($delivery->customer_id), $delivery->document_date);
add_trans_tax_details(ST_CUSTDELIVERY, $delivery_no, $taxitem['tax_type_id'],
$taxitem['rate'], $delivery->tax_included, $taxitem['Value'],
- $taxitem['Net'], $ex_rate, $delivery->document_date, $delivery->reference );
+ $taxitem['Net'], $ex_rate, $delivery->document_date, $delivery->reference, null);
}
}
if ($taxitem['Net'] != 0) {
$ex_rate = get_exchange_rate_from_home_currency(get_customer_currency($invoice->customer_id), $date_);
add_trans_tax_details(ST_SALESINVOICE, $invoice_no, $taxitem['tax_type_id'],
- $taxitem['rate'], $invoice->tax_included, $taxitem['Value'],
- $taxitem['Net'], $ex_rate, $date_, $invoice->reference, $date_, $prepaid_factor*$taxitem['Value']);
+ $taxitem['rate'], $invoice->tax_included, $prepaid_factor*$taxitem['Value'],
+ $taxitem['Net'], $ex_rate, $date_, $invoice->reference, TR_OUTPUT);
if (isset($taxitem['sales_gl_code']))
$total += add_gl_trans_customer(ST_SALESINVOICE, $invoice_no, $date_, $taxitem['sales_gl_code'], 0, 0,
(-$taxitem['Value'])*$prepaid_factor, $invoice->customer_id,
ALTER TABLE `0_supp_trans` DROP PRIMARY KEY;
ALTER TABLE `0_supp_trans` ADD PRIMARY KEY (`type`,`trans_no`, `supplier_id`);
+ALTER TABLE `0_trans_tax_details` ADD COLUMN `reg_type` tinyint(1) DEFAULT NULL AFTER `memo`;
+
+UPDATE `0_trans_tax_details` reg
+ SET reg.reg_type=1
+ WHERE reg.trans_type IN(20, 21);
+
+UPDATE `0_trans_tax_details` reg
+ SET reg.reg_type=0
+ WHERE reg.trans_type IN(10, 11);
+
`net_amount` double NOT NULL default '0',
`amount` double NOT NULL default '0',
`memo` tinytext,
+ `reg_type` tinyint(1) default NULL,
PRIMARY KEY (`id`),
KEY `Type_and_Number` (`trans_type`,`trans_no`),
KEY `tran_date` (`tran_date`)
-- Dumping data for table `0_trans_tax_details`
--
-INSERT INTO `0_trans_tax_details` VALUES(1, 20, 7, '2014-06-21', 1, 5, 1, 0, 3300, 165, '5t');
-INSERT INTO `0_trans_tax_details` VALUES(2, 13, 3, '2014-06-21', 1, 5, 1, 0, 50, 2.5, 'auto');
-INSERT INTO `0_trans_tax_details` VALUES(3, 10, 17, '2014-06-21', 1, 5, 1, 0, 50, 2.5, '1');
-INSERT INTO `0_trans_tax_details` VALUES(4, 13, 4, '2014-06-21', 1, 5, 1.3932, 0, 35.89, 1.7945, 'auto');
-INSERT INTO `0_trans_tax_details` VALUES(5, 10, 18, '2014-06-21', 1, 5, 1.3932, 0, 35.89, 1.7945, '2');
-INSERT INTO `0_trans_tax_details` VALUES(6, 2, 5, '2014-06-21', 1, 5, 1, 0, 95.2, 4.76, '');
-INSERT INTO `0_trans_tax_details` VALUES(7, 1, 8, '2014-06-21', 1, 5, 1, 0, -47.6, -2.38, '');
-INSERT INTO `0_trans_tax_details` VALUES(8, 20, 8, '2014-06-21', 1, 5, 1, 0, -19, -0.95, 'cc');
-INSERT INTO `0_trans_tax_details` VALUES(9, 13, 5, '2014-06-21', 1, 5, 1, 1, 47.619047619048, 2.3809523809524, 'auto');
-INSERT INTO `0_trans_tax_details` VALUES(10, 10, 19, '2014-06-21', 1, 5, 1, 1, 47.619047619048, 2.3809523809524, '3');
-INSERT INTO `0_trans_tax_details` VALUES(11, 11, 3, '2014-06-21', 1, 5, 1.3932, 0, 35.89, 1.7945, '1');
+INSERT INTO `0_trans_tax_details` VALUES(1, 20, 7, '2014-06-21', 1, 5, 1, 0, 3300, 165, '5t', 1);
+INSERT INTO `0_trans_tax_details` VALUES(2, 13, 3, '2014-06-21', 1, 5, 1, 0, 50, 2.5, 'auto', NULL);
+INSERT INTO `0_trans_tax_details` VALUES(3, 10, 17, '2014-06-21', 1, 5, 1, 0, 50, 2.5, '1', 0);
+INSERT INTO `0_trans_tax_details` VALUES(4, 13, 4, '2014-06-21', 1, 5, 1.3932, 0, 35.89, 1.7945, 'auto', NULL);
+INSERT INTO `0_trans_tax_details` VALUES(5, 10, 18, '2014-06-21', 1, 5, 1.3932, 0, 35.89, 1.7945, '2', 0);
+INSERT INTO `0_trans_tax_details` VALUES(6, 2, 5, '2014-06-21', 1, 5, 1, 0, 95.2, 4.76, '', NULL);
+INSERT INTO `0_trans_tax_details` VALUES(7, 1, 8, '2014-06-21', 1, 5, 1, 0, -47.6, -2.38, '', NULL);
+INSERT INTO `0_trans_tax_details` VALUES(8, 20, 8, '2014-06-21', 1, 5, 1, 0, -19, -0.95, 'cc', 1);
+INSERT INTO `0_trans_tax_details` VALUES(9, 13, 5, '2014-06-21', 1, 5, 1, 1, 47.619047619048, 2.3809523809524, 'auto', NULL);
+INSERT INTO `0_trans_tax_details` VALUES(10, 10, 19, '2014-06-21', 1, 5, 1, 1, 47.619047619048, 2.3809523809524, '3', 0);
+INSERT INTO `0_trans_tax_details` VALUES(11, 11, 3, '2014-06-21', 1, 5, 1.3932, 0, 35.89, 1.7945, '1', 0);
-- --------------------------------------------------------
`net_amount` double NOT NULL default '0',
`amount` double NOT NULL default '0',
`memo` tinytext,
+ `reg_type` tinyint(1) default NULL,
PRIMARY KEY (`id`),
KEY `Type_and_Number` (`trans_type`,`trans_no`),
KEY `tran_date` (`tran_date`)