<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — The get_balance function needs to adjusted to eliminate voided entries]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8456&amp;type=atom" />
	<updated>2019-10-17T17:41:41Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=8456</id>
		<entry>
			<title type="html"><![CDATA[Re: The get_balance function needs to adjusted to eliminate voided entries]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36281#p36281" />
			<content type="html"><![CDATA[<p>I just wonder if this will calculate faster with this sophisticated statement.<br />The voided amounts are 0 so the results are the same. Just a thought.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2019-10-17T17:41:41Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36281#p36281</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: The get_balance function needs to adjusted to eliminate voided entries]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36274#p36274" />
			<content type="html"><![CDATA[<p>@joe and @itronics, check this with existing core.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-10-17T05:53:51Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36274#p36274</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[The get_balance function needs to adjusted to eliminate voided entries]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36270#p36270" />
			<content type="html"><![CDATA[<p>The get_balance function also includes the voided payment or edited payment. Its better, we have to include the voided table to exclude the entries of voided amount.</p><p>here is my adjusted code.</p><div class="codebox"><pre><code>//----------------------------------------------------------------------------------------------------
function get_balance($account, $dimension, $dimension2, $from, $to, $from_incl=true, $to_incl=true) 
{
    $from_date = date2sql($from);
    $to_date = date2sql($to);

    $sql = &quot;SELECT    SUM(IF(amount &gt;= 0, amount, 0)) as debit, 
                    SUM(IF(amount &lt; 0, -amount, 0)) as credit,
                    SUM(amount) as balance 
        FROM &quot;.TB_PREF.&quot;gl_trans trans  LEFT JOIN &quot;.TB_PREF.&quot;voided AS vd ON trans.type = vd.type AND trans.type_no = vd.id,&quot;
            .TB_PREF.&quot;chart_master coa,&quot;
            .TB_PREF.&quot;chart_types act_type, &quot;
            .TB_PREF.&quot;chart_class act_class
        WHERE trans.account=coa.account_code  AND ISNULL(vd.id)
            AND coa.account_type=act_type.id 
        AND act_type.class_id=act_class.cid&quot;
        .&quot; AND &quot;.($from_incl ? &quot;tran_date &gt;= &#039;$from_date&#039;&quot; : &quot;tran_date &gt; IF(ctype&gt;0 AND ctype&lt;&quot;.CL_INCOME.&quot;, &#039;0000-00-00&#039;, &#039;$from_date&#039;)&quot;)
        .&quot; AND &quot;.($to_incl ? &quot;tran_date &lt;= &#039;$to_date&#039;&quot; : &quot;tran_date &lt; &#039;$to_date&#039;&quot;)
        .($account == null ? &#039;&#039; : &quot; AND account=&quot;.db_escape($account))
        .($dimension == 0 ? &#039;&#039;  : &quot; AND dimension_id = &quot;.($dimension&lt;0 ? 0 : db_escape($dimension)))
        .($dimension2 == 0 ? &#039;&#039; : &quot; AND dimension2_id = &quot;.($dimension2&lt;0 ? 0 : db_escape($dimension2)));

    $result = db_query($sql,&quot;No general ledger accounts were returned&quot;);

    return db_fetch($result);
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-10-16T07:56:20Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36270#p36270</id>
		</entry>
</feed>
