<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8336&amp;type=atom" />
	<updated>2019-08-20T14:53:51Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=8336</id>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35750#p35750" />
			<content type="html"><![CDATA[<p>Sure I will write my part of changes and bug fixes and ideas too.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-08-20T14:53:51Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35750#p35750</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35738#p35738" />
			<content type="html"><![CDATA[<p>Forecasting from how many years it took to come in from FA 2.3 to FA 2.4 and the fact that the devs are much older now, take it to be atleast 5 years from when the <a href="https://github.com/FrontAccountingERP/FA/tree/unstable">initial 2.5 branch</a> began. If it is any sooner, thank the advances in coding technologies and that we are now older and wiser <img src="https://frontaccounting.com/punbb/img/smilies/wink.png" width="15" height="15" alt="wink" /></p><p>@kvvaradha: Whatever changes you have in mind to make a start, do let us know here so that it can atleast get into the codebase for those who wish to benefit from it in the meanwhile and form part of FA 2.5 if and when it appears.</p><p>Aug 17th 2019 - probably last commit to the 2.4(.7) branch.<br />Aug 19th 2019 - first commit to merge stable into unstable for 2.5 branch</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-08-19T17:01:00Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35738#p35738</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35736#p35736" />
			<content type="html"><![CDATA[<p>ok.So when it will be released&nbsp; officially.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-08-19T09:31:52Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35736#p35736</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35724#p35724" />
			<content type="html"><![CDATA[<p>Hello again.</p><p>As I feared, Janusz is about a major rewrite in 2.5 just inside this too. </p><p>He also want to wait until 2.5 implementing this.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2019-08-18T11:06:39Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35724#p35724</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35722#p35722" />
			<content type="html"><![CDATA[<p>You may be right. I will just sync with Janusz regarding this.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2019-08-18T07:23:43Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35722#p35722</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35719#p35719" />
			<content type="html"><![CDATA[<p>Since this does not affect the DB schema, can we not make a start here?</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-08-18T06:13:44Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35719#p35719</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35713#p35713" />
			<content type="html"><![CDATA[<p>You are right guys. However this is quite a change in several files so I would like to do this in release 2.5. I will make a note about this.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2019-08-17T21:50:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35713#p35713</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35706#p35706" />
			<content type="html"><![CDATA[<p>Putting it in a variable and then using it everywhere will make sense.<br />@joe?</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-08-17T13:33:29Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35706#p35706</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35687#p35687" />
			<content type="html"><![CDATA[<p>Even, we can pass the same currency to </p><div class="codebox"><pre><code> get_diff_in_home_currency($supp_trans-&gt;supplier_id, $old_date, $date_, $old_value,     $taxfree_line, $currency); </code></pre></div><p>this will reduce a bit more <br /></p><div class="codebox"><pre><code>function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amount2,$currency=null)
{
    $dec = user_price_dec();
    price_decimal_format($amount2, $dec);
if($currency == null)
    $currency = get_supplier_currency($supplier);
    $ex_rate = get_exchange_rate_to_home_currency($currency, $old_date);
    $amount1 = $amount1 / $ex_rate;
    $ex_rate = get_exchange_rate_to_home_currency($currency, $date);
    $amount2 = $amount2 / $ex_rate;
    $diff = $amount2 - $amount1;
    //return round2($diff, $dec);
    return $diff;
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-08-16T17:08:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35687#p35687</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Some changes in add_supp_invoice to reduce unnecessary query run time]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=35686#p35686" />
			<content type="html"><![CDATA[<p>As i have seen some queries which unnecesaarily runs within loops or its called multiple times to pass it to another data. There is one recent one I am bring here to update the core makes simple. </p><p>/purchasing/includes/db/invoice_db.inc</p><p>From the add_supp_invoice function, there is items line foreach which has a function inside it <br /></p><div class="codebox"><pre><code>$currency = get_supplier_currency($supp_trans-&gt;supplier_id);</code></pre></div><p> This actually no point to run within items loop, just imagine, if the user add 50 items in one invoice and tries to save. this query runs 49 times unnecessarily.&nbsp; and also one more thing with the same function.</p><p>From this function <br /></p><div class="codebox"><pre><code>function add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2,  
    $amount, $supplier_id, $err_msg=&quot;&quot;, $rate=0, $memo=&quot;&quot;)
{
    if ($err_msg == &quot;&quot;)
        $err_msg = &quot;The supplier GL transaction could not be inserted&quot;;    
        
    return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, $memo, 
        $amount, get_supplier_currency($supplier_id), 
        PT_SUPPLIER, $supplier_id, $err_msg, $rate);
}</code></pre></div><p> This is acutally calls more than once for a single item. during the same invoice process. here looks this code.&nbsp; </p><div class="codebox"><pre><code>get_supplier_currency($supplier_id), </code></pre></div><p>it runs more than 100 times as of my above example.&nbsp; So its better take out this and pass one more parameter in the </p><div class="codebox"><pre><code> add_gl_trans_supplier</code></pre></div><p> like this <br /></p><div class="codebox"><pre><code> add_gl_trans_supplier($type, $type_no, $date_, $account, $dimension, $dimension2,  
    $amount, $supplier_id, $err_msg=&quot;&quot;, $rate=0, $memo=&quot;&quot;, $currency=null){
      if ($err_msg == &quot;&quot;)
        $err_msg = &quot;The supplier GL transaction could not be inserted&quot;;    
    if($currency == null )
        $currrency = get_supplier_currency($supplier_id);
    return add_gl_trans($type, $type_no, $date_, $account, $dimension, $dimension2, $memo, 
        $amount, $currency, 
        PT_SUPPLIER, $supplier_id, $err_msg, $rate);
}</code></pre></div><p>. This will simplify more than 150 query load to server when we submit 50 items invoice. </p><p>@Joe,And @Janusz, Hope you guys get the point.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2019-08-16T17:06:23Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=35686#p35686</id>
		</entry>
</feed>
