<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[FrontAccounting forum — Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
		<link>https://frontaccounting.com/punbb/viewtopic.php?id=8184</link>
		<atom:link href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8184&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Anomaly created by Cost Update in Inventory Sales Report (rep304).]]></description>
		<lastBuildDate>Sun, 23 Jun 2019 12:41:17 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35296#p35296</link>
			<description><![CDATA[<p>@itronics,&nbsp; yes database consistency requires some update queries to run. </p><p>I agree with you. I will check in detail later</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Sun, 23 Jun 2019 12:41:17 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35296#p35296</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35295#p35295</link>
			<description><![CDATA[<p>@boxygen<br />I have to reopen this thread for a moment.</p><p>Finally to maintain database consistency on existing installations I have reverted the changes in add_stock_adjustment_item() and related fixes in reports rep301, rep308.&nbsp; We will address all this in forthgoing 2.5 release. We plan to change stock_moves table structure to better upport inventory cost tracking. All comments regarding this feature are welcome&nbsp; <a href="https://frontaccounting.com/punbb/viewtopic.php?pid=35294">in this thread</a>. </p><p>As far as I understand, after revertion all should still work as expected, as suggested changes where mostly technical. If I&#039;m wrong, please do not hesitate to reopen the thread and explain the lasting problems (if any) once again.<br />J.</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Sun, 23 Jun 2019 11:28:04 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35295#p35295</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35256#p35256</link>
			<description><![CDATA[<p>It would be nice to preserve the whitespace in the commits so that effective changes can be discerned. The whitespace cleanup can be in a separate commit.</p><p>The recent changes on 2019-06-17 (<a href="https://github.com/FrontAccountingERP/FA/commit/c2b751f91d79c69bb802b1bff13a3c4bdecb87b0">1</a>, <a href="https://github.com/FrontAccountingERP/FA/commit/8e6c8cda775a4435fcc3670a004968c4c5710d98">2</a>) have been assimilated in my repo separating the <a href="https://github.com/apmuthu/frontac24/commit/03fe22842cd52beb735b62e326901e0b8ed38da0">actual changes</a> and the <a href="https://github.com/apmuthu/frontac24/commit/81ec6d1f01b7adbfd4203ffbaf12d8eb24b77c52">whitespace synch</a>.</p>]]></description>
			<author><![CDATA[null@example.com (apmuthu)]]></author>
			<pubDate>Wed, 19 Jun 2019 02:18:54 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35256#p35256</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35236#p35236</link>
			<description><![CDATA[<p>@boxygen</p><p>Please try again. For some reason you were not upgraded internally as Senior Member. Even if it was shown.</p><p>Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Mon, 17 Jun 2019 09:22:38 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35236#p35236</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35235#p35235</link>
			<description><![CDATA[<p>@joe, not for this topic now. But I have few suggestions for 2.5. This post https://frontaccounting.com/punbb/viewtopic.php?id=8137 doesn&#039;t allow us to post. Where can we post for suggestions for 2.5.</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Mon, 17 Jun 2019 08:07:13 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35235#p35235</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35234#p35234</link>
			<description><![CDATA[<p>@boxygen.</p><p>Slightly update of add_stock_adjustment_item by @itronics. Committed to stable repo. Only keeping the parameter names.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Mon, 17 Jun 2019 08:00:15 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35234#p35234</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35227#p35227</link>
			<description><![CDATA[<p>@boxygen.</p><p>I have tested your changes in /inventory/includes/db/items_adjust_db.inc, /reporting/rep301.php and /reporting/rep308.php.<br />And the test passed ok.<br />These changes has been committed to stable repo.<br />Do you have more files to change, @boxygen, because we plan to ship a minor release 2.4.7 next week?<br />Major changes will wait to the upcoming release 2.5 unstable that also are about to ship.</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Mon, 17 Jun 2019 06:32:03 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35227#p35227</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35222#p35222</link>
			<description><![CDATA[<p>@boxygen.</p><p>I think I can follow you now. I will just test this tomorrow to ensure that it is right. If the reports take the domestic price from the underlying ex_rate values in the grn and sub credit transaction lines.</p><p>Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Sun, 16 Jun 2019 21:59:32 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35222#p35222</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35221#p35221</link>
			<description><![CDATA[<p>@joe,<br /></p><div class="quotebox"><blockquote><p>Should we change back to the former functions, get_domestic_price, in rep301 and rep308, but wich these changed rows?</p></blockquote></div><p>You can do either, or but I think better keep the one in post # 11. I have tested it. It has changed conditions as well as some removal of logical bugs and</p><div class="quotebox"><blockquote><p>And post #8 should be changed? and the wrongly calculated domestic price?</p></blockquote></div><p>Post #8 should be committed otherwise domestic_price will not calculate correctly.</p><p>With my finally suggested codes in post#8 and post#11 domestic_price is calculating correctly the average cost.</p><p>Regards.</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Sun, 16 Jun 2019 21:49:25 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35221#p35221</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35219#p35219</link>
			<description><![CDATA[<p>@boxygen</p><p>Should we change back to the former functions, get_domestic_price, in rep301 and rep308, but wich these changed rows?<br />And post #8 should be changed? and the wrongly calculated domestic price?</p><p>/Joe</p>]]></description>
			<author><![CDATA[null@example.com (joe)]]></author>
			<pubDate>Sun, 16 Jun 2019 21:34:33 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35219#p35219</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35218#p35218</link>
			<description><![CDATA[<p>@joe,</p><p>function <strong>get_domestic_price</strong> needs some more adjustments. But it requires changes in post#8 to be committed first.</p><div class="codebox"><pre><code>function get_domestic_price($myrow, $stock_id)
{
    if ($myrow[&#039;type&#039;] == ST_SUPPRECEIVE || $myrow[&#039;type&#039;] == ST_SUPPCREDIT || $myrow[&#039;type&#039;] == ST_INVADJUST)
     {
        $price = $myrow[&#039;price&#039;];
        if ($myrow[&#039;person_id&#039;] &gt; 0)
        {
            // Do we have foreign currency?
            $supp = get_supplier($myrow[&#039;person_id&#039;]);
            $currency = $supp[&#039;curr_code&#039;];
            $ex_rate = $myrow[&#039;ex_rate&#039;];
            $price *= $ex_rate;
        }
    }
    else
        $price = $myrow[&#039;standard_cost&#039;]; //pick standard_cost for sales deliveries

    return $price;
}</code></pre></div><p><strong>Explanation:</strong> </p><p>1. We need <strong>price</strong> Value only for ST_SUPPRECEIVE, ST_SUPPCREDIT AND ST_INVADUST. For Sales Deliveries we need the <strong>standard_cost</strong> for Average cost calculation in rep301, rep308.</p><p>2. $price *= $ex_rate is currently $price /= $ex_rate which is a logical mistake.</p><p>3. We can pick Exchange Rate directly from Supplier Transaction for GRN and Supplier Credit Note. For this we need some more changes in rep301 and rep308</p><p>Following partial code in the SQL Query shall be replaced with</p><div class="codebox"><pre><code>IF(ISNULL(supplier.supplier_id), debtor.debtor_no, supplier.supplier_id) person_id</code></pre></div><p>This code</p><div class="codebox"><pre><code>supplier.supplier_id person_id, IF(ISNULL(grn.rate), credit.rate, grn.rate) ex_rate</code></pre></div><p><strong>Explanation</strong><br />1. We need person_id only for suppliers to get exchange rate of the transaction in <strong>get_domestic_price</strong> function<br />2. ex_rate is directly picked from either GRN or Supplier Credit</p><br /><p>I have tested all this after creating a fresh item and executing all type of transactions on it as in <a href="https://snag.gy/1HATof.jpg">this image</a></p><p>There is one understanding that ST_CUSTCREDIT transactions will always pick the prevailing unit_cost.</p><p>Regards.</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Sun, 16 Jun 2019 20:37:36 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35218#p35218</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35216#p35216</link>
			<description><![CDATA[<p>Thanks for your endorsement. I agree with your plan</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Sun, 16 Jun 2019 16:11:41 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35216#p35216</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35215#p35215</link>
			<description><![CDATA[<p>@boxygen,<br />Yes, this is how I plan to implement cost update logging.</p><p>Regarding database update for inventory adjustment, we will have to add this in upgrade procedure to release 2.5. We do not have updating procedure for minor releases, so implementing this in 2.4.* would require run the query outside user&#039;s awareness. Skilled user suffered with this problem can run the query manually anyway.</p><p>J.</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Sun, 16 Jun 2019 13:20:52 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35215#p35215</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35214#p35214</link>
			<description><![CDATA[<p>@joe,<br /><a href="https://github.com/FrontAccountingERP/FA/commit/936e862fe67af1b6113aee0d727eb86e7f021cc1">This</a> commit needs one more commit in the function <strong>add_stock_adjustment_item</strong> on <strong>/inventory/includes/db/items_adjust_db.inc</strong> as follows</p><div class="codebox"><pre><code>function add_stock_adjustment_item($adj_id, $stock_id, $location, $date_, $reference,
    $quantity, $price, $memo_)
{
    $mb_flag = get_mb_flag($stock_id);
    if (is_service($mb_flag))
    {
        display_db_error(&quot;Cannot do inventory adjustment for Service item : $stock_id&quot;, &quot;&quot;);
    }
    update_average_material_cost(null, $stock_id, $price, $quantity, $date_);
    if (is_fixed_asset($mb_flag)) {
        $sql = &quot;UPDATE &quot;.TB_PREF.&quot;stock_master SET inactive=1
            WHERE stock_id=&quot;.db_escape($stock_id);
        db_query($sql,&quot;The inactive flag for the fixed asset could not be updated&quot;);
    }
  $standard_cost = get_unit_cost($stock_id); //added by faisal
    add_stock_move(ST_INVADJUST, $stock_id, $adj_id, $location,
        $date_, $reference, $quantity, $standard_cost, $price);
    $inv_value = $price * $quantity;
    $adj_value = $price * -($quantity);
    if (is_fixed_asset($mb_flag)) {
        // get the initial value of the fixed assset.
        $row = get_fixed_asset_move($stock_id, ST_SUPPRECEIVE);
        $inv_value = $row[&#039;price&#039;] * $quantity;
        $adj_value = (-($row[&#039;price&#039;]) + $price) * $quantity;
    }
    if ($price &gt; 0 || is_fixed_asset($mb_flag))
    {
        $stock_gl_codes = get_stock_gl_code($stock_id);
        add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_,
            $stock_gl_codes[&#039;adjustment_account&#039;], $stock_gl_codes[&#039;dimension_id&#039;], $stock_gl_codes[&#039;dimension2_id&#039;], $memo_, $adj_value  );
        add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, $stock_gl_codes[&#039;inventory_account&#039;], 0, 0, $memo_, $inv_value);
    }
    if (is_fixed_asset($mb_flag)) {
        // Additional gl entry for fixed asset.
        $grn_act = get_company_pref(&#039;default_loss_on_asset_disposal_act&#039;);
        add_gl_trans_std_cost(ST_INVADJUST, $adj_id, $date_, $grn_act, 0, 0, $memo_, ($price * -($quantity)));
    }
}</code></pre></div><p><strong>FOR LEGACY DATA ACCURACY</strong></p><p>In order to keep rep301 and rep308 workable with older data than this commit one update query needs to be executed to bring standard_cost values in the price field for all transactions through inventory_adjustment.</p><div class="codebox"><pre><code>UPDATE stock_moves SET price=standard_cost WHERE type=17</code></pre></div><p><strong> WORKAROUND FOR COST UPDATE </strong></p><br /><p>@itronics for logging Cost Update tracking in stock_moves I have a workaround solution. May be you endorse it. Just sharing the idea. If approved I can work on code.</p><p>We can execute 2 Inventory Adjustments per location for that particular item when cost update is executed.</p><p>#1. This will bring the QOH to ZERO even for -ve inventory on the prevailing cost price in the system.<br />#2. This will bring the QOH on the same position either +ve or -ve at the New Cost give through Cost Update.</p><p>With this workaround we will be able to bring correct results in rep301 and rep308 as well.</p><p><strong> EXCHANGE RATE AFFECT</strong></p><p>In this function <strong>get_domestic_price</strong> the exchange rate factor is applied when person_id &gt; 0. But for Inventory Adjustments person_id is always 0</p><p>However you are right that there shall be a column to record Exchange Rate of that transaction so that any change in exchange_rates shall not affect the transaction.</p>]]></description>
			<author><![CDATA[null@example.com (boxygen)]]></author>
			<pubDate>Sun, 16 Jun 2019 10:19:23 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35214#p35214</guid>
		</item>
		<item>
			<title><![CDATA[Re: Anomaly created by Cost Update in Inventory Sales Report (rep304)]]></title>
			<link>https://frontaccounting.com/punbb/viewtopic.php?pid=35213#p35213</link>
			<description><![CDATA[<p>There are at lest two fixes still needed:<br />. changing item cost in Cost Update has no track in stock_moves;<br />. the price is in transaction currency, but there is lack&nbsp; of currency exchange rate recorded in stock_stock_moves, so logging in stock_moves is unreliable (you can at any time change currency exchange rate in exchange_rates table);</p><p>We will refine the logging feature of stock_moves in the next days, however the changes will go probably to unstable branch. for next 2.5 release. </p><p>J.</p>]]></description>
			<author><![CDATA[null@example.com (itronics)]]></author>
			<pubDate>Sun, 16 Jun 2019 08:06:02 +0000</pubDate>
			<guid>https://frontaccounting.com/punbb/viewtopic.php?pid=35213#p35213</guid>
		</item>
	</channel>
</rss>
