<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Manufacturing Values Off By Small Amounts]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8662&amp;type=atom" />
	<updated>2020-01-30T01:41:22Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=8662</id>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36939#p36939" />
			<content type="html"><![CDATA[<p>I suggest making a fork of the <a href="https://github.com/FrontAccountingERP/FA/tree/master">FA project</a> on github, and adding your changes in, perhaps with help from a 3-way diff tool.&nbsp; Then as new changes are made in FA, you can <a href="https://help.github.com/en/github/collaborating-with-issues-and-pull-requests/syncing-a-fork">sync your fork with the upstream code</a>.&nbsp; Often the new changes are incorporated without any additional effort but sometimes there are conflicts, but then you run git mergetool to help determine how to proceed.</p>]]></content>
			<author>
				<name><![CDATA[Braath Waate]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=41493</uri>
			</author>
			<updated>2020-01-30T01:41:22Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36939#p36939</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36938#p36938" />
			<content type="html"><![CDATA[<p>I have made many changes to FrontAccounting the past 6 months. I have rough notes of these changes. Probably 99% of those changes have been offered from many of you via this forum. </p><p>&nbsp; What is the best way to backup and restore these changes when a new version becomes available? I imagine some of the changes I made to 2.4.7 may already be incorporated in the next version.</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-30T01:24:25Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36938#p36938</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36937#p36937" />
			<content type="html"><![CDATA[<p>Thanks Braathe. I blew right past the main section. After applying your modifications, it DOES address my problem with rounding. Thank you very much.</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-30T01:17:04Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36937#p36937</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36936#p36936" />
			<content type="html"><![CDATA[<p>Just for the record, round2() is mainly needed starting at line 55 to sum up the the boms.&nbsp; Line 65 is just the additional materials.</p>]]></content>
			<author>
				<name><![CDATA[Braath Waate]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=41493</uri>
			</author>
			<updated>2020-01-29T21:45:15Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36936#p36936</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36935#p36935" />
			<content type="html"><![CDATA[<p>The rounding modification didn&#039;t help my issue. I modified manufacturing/includes/db/work_order_produce_items_db.inc by replacing lines starting at line 65 with @Braathe&#039;s suggestion. I still see the differences.</p><p>&nbsp; I have no problem adding a journal entry to clean up. I was more concerned that I was doing something wrong or I setup something wrong and I wanted to correct that. Maybe most people just let this run wild and don&#039;t address it at all. I&#039;m not trying to make more work to do, just wanting to follow best practices with the tools available.</p><p>&nbsp; Thank you very much for the insight and suggestions.</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-29T14:17:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36935#p36935</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36931#p36931" />
			<content type="html"><![CDATA[<p>I don&#039;t know. We have tried to do our best by using the DELTA factor.<br />We can await @Braath Waate&#039;s approach by @paul testing it.</p><p>/Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2020-01-27T22:23:23Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36931#p36931</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36929#p36929" />
			<content type="html"><![CDATA[<p>@joe: How do we handle such rounding errors in a standardised way to avoid adjustment journal entries?</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-01-27T18:16:23Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36929#p36929</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36922#p36922" />
			<content type="html"><![CDATA[<p>This is an FA bug, sort of, and it affects my site as well, but I haven&#039;t gotten around to fixing it yet.&nbsp; And yes, a journal entry is probably the only way to address it without fixing the code.</p><p>When FA closes a work order, it calls work_order_produce() which first creates the Finished Product Requirements.&nbsp; &nbsp;The g/l created by each requirement eventually calls add_gl_trans().&nbsp; Note the rounding in this function:</p><div class="codebox"><pre><code>function add_gl_trans($type, $trans_id, $date_, $account, $dimension, $dimension2, $memo_,
    $amount, $currency=null, $person_type_id=null, $person_id=null, $err_msg=&quot;&quot;, $rate=0)
{
    global $SysPrefs;

    $date = date2sql($date_);
    if ($currency != null)
    {
        if ($rate == 0)
            $amount_in_home_currency = to_home_currency($amount, $currency, $date_);
        else
            $amount_in_home_currency = round2($amount * $rate,  user_price_dec());
    }
    else
        $amount_in_home_currency = round2($amount, user_price_dec());</code></pre></div><p>OK, so each requirement is rounded, and then added up.</p><p>But wait, there is more to do.&nbsp; work_order_produce() then sums up the Finished Product Recieval:</p><div class="codebox"><pre><code>        // 1. calculate sums of material/labour/overhead costs

        // sum collected BOM material &amp; labour costs (no way for separate overhead here for now - needs flag in bom or stock_master)
        $bom = get_wo_requirements($woid);
        $m_cost = $l_cost = 0;
        while ($component = db_fetch($bom))
        {
            if (!is_service($component[&quot;mb_flag&quot;]))
                $m_cost += $component[&#039;unit_cost&#039;]*$component[&#039;units_issued&#039;];
            else
                $l_cost += $component[&#039;unit_cost&#039;]*$component[&#039;units_issued&#039;];
        }

        // add additional material issues
        $issues = get_additional_issues($woid);
        while ($issue = db_fetch($issues))
        {
            if (!is_service($issue[&quot;mb_flag&quot;]))
                $m_cost += $issue[&#039;unit_cost&#039;]*$issue[&#039;qty_issued&#039;];
            else
                $l_cost += $issue[&#039;unit_cost&#039;]*$issue[&#039;qty_issued&#039;];
        }

        // and additional costs
        $o_cost = get_gl_wo_cost($woid, WO_OVERHEAD);
        $l_cost += get_gl_wo_cost($woid, WO_LABOUR);

        $total_cost = $o_cost + $m_cost + $l_cost;

        add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $product[&#039;wip_account&#039;],
            0, 0, $memo, -$total_cost);

        add_gl_trans_std_cost(ST_WORKORDER, $woid, $date_, $product[&#039;inventory_account&#039;],
            0, 0, $memo, $total_cost);</code></pre></div><p>So if all units were able to be manufactured, the calculation should be the same.</p><p>Except for the lack of rounding in this code.</p><p>So if it disturbs you to see these rounding errors, what can you do?&nbsp; Well, you could try rounding m_cost and l_cost like in add_gl_trans.&nbsp; Maybe try:</p><div class="codebox"><pre><code>          if (!is_service($issue[&quot;mb_flag&quot;]))
                $m_cost += round2($issue[&#039;unit_cost&#039;]*$issue[&#039;qty_issued&#039;], user_price_dec());
            else
                $l_cost += round2($issue[&#039;unit_cost&#039;]*$issue[&#039;qty_issued&#039;], user_price_dec());</code></pre></div><p>I haven&#039;t tried this, so it might not work.&nbsp; But this is first thing I would try.</p>]]></content>
			<author>
				<name><![CDATA[Braath Waate]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=41493</uri>
			</author>
			<updated>2020-01-26T23:35:06Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36922#p36922</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36920#p36920" />
			<content type="html"><![CDATA[<p>I just entered four work orders from yesterday. Only one was accurate from inventory through work in progress back into inventory. Two others were off by one penny. One other one was off by 2 pennies. Each one is not much, but with up to 400 work orders a month, it starts to add up.</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-26T17:43:10Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36920#p36920</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36919#p36919" />
			<content type="html"><![CDATA[<p>With the test php file, I get:</p><div class="codebox"><pre><code>1.7 is NOT greater than or equal to 1.7000000000000002
0.30000000000000004</code></pre></div><p>&nbsp; I don&#039;t need super fine precision. I would like consistency. If I&#039;m taking $33.01 out of inventory for manufacturing, I need $33.01 taken from manufacturing back into inventory. Maybe part of my problem is the difference from my vendors unit of 1 equals 1152 units in my inventory. Standard costs are shown at 4 decimal places.</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-26T17:03:44Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36919#p36919</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36918#p36918" />
			<content type="html"><![CDATA[<p>Try this piece of code in a test php file:<br /></p><div class="codebox"><pre><code>&lt;?php
if (1.7 &gt;= 17 * 0.1) {
  echo &#039;1.7 is greater than or equal to &#039; . 17 * 0.1;
} else {
  echo &#039;1.7 is NOT greater than or equal to &#039; . 17 * 0.1;
}

echo &quot;&lt;br&gt;\n&quot; . (0.1 + 0.2);

?&gt;</code></pre></div><p>In XAMPP 1.7.3 (PHP 5.3.1) we get:<br /></p><div class="codebox"><pre><code>1.7 is NOT greater than or equal to 1.7000000000000002
0.30000000000000004</code></pre></div><p>This is because native operator are indeed interpreted in base 2, and most base 10 decimal converts badly in base 2.</p><p>If you need precision, you need to either only manipulate integers (converts perfectly to base 2) or use a dedicated lib such as <a href="https://www.php.net/manual/en/book.bc.php">bcmath</a> (checkout the wrapper to ease bcmath usage <a href="https://github.com/fab2s/Math">Math</a>).</p><p>Ref as of 2 months ago:<br />https://stackoverflow.com/questions/58744298/php-floating-point-multiplication-and-comparison-issue</p><p>Ref as of nearly 11 years ago:<br />https://stackoverflow.com/questions/588004/is-floating-point-math-broken</p><p>Ref in PHP.net:<br />https://bugs.php.net/bug.php?id=74534</p><p><a href="https://floating-point-gui.de/">Floating point arithmetic for programmers</a></p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-01-26T16:33:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36918#p36918</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36913#p36913" />
			<content type="html"><![CDATA[<p>I saw this option, but thought it was for discrepancies while receiving a purchase order if pricing was too far off of the entered amount. But, I did change the value (not knowing it&#039;s potential) with no change to my manufacturing issue. The values I tested with other than the 0.005 were 0.505 and 5.505 - Manufacturing amount inaccuracies are still produced.</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-25T14:36:58Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36913#p36913</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36909#p36909" />
			<content type="html"><![CDATA[<p><strong><em>$config_allocation_settled_allowance</em></strong> value in <strong>config.php</strong>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-01-25T06:31:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36909#p36909</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36907#p36907" />
			<content type="html"><![CDATA[<p>Assuming you are referring to a literal term, I do not find a &quot;delta&quot; value in my FrontAccounting&#039;s config.php</p>]]></content>
			<author>
				<name><![CDATA[paul]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44798</uri>
			</author>
			<updated>2020-01-25T03:40:19Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36907#p36907</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Manufacturing Values Off By Small Amounts]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=36905#p36905" />
			<content type="html"><![CDATA[<p>Then play with the delta value in config.php</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-01-25T03:01:51Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=36905#p36905</id>
		</entry>
</feed>
