<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — New Year reference resetting]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=7922&amp;type=atom" />
	<updated>2019-01-13T12:27:53Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=7922</id>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33938#p33938" />
			<content type="html"><![CDATA[<p>For those who want the Fiscal Year Ending {EE}/{EEEE} format as well, it is available in my <a href="https://github.com/apmuthu/frontac24/commit/1da4ead10164987f2dd992e7974eb4364a4239ba">commit</a>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-13T12:27:53Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33938#p33938</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33923#p33923" />
			<content type="html"><![CDATA[<p>Thanks Janusz and apmuthu</p>]]></content>
			<author>
				<name><![CDATA[anoopmb]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18207</uri>
			</author>
			<updated>2019-01-09T14:30:13Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33923#p33923</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33916#p33916" />
			<content type="html"><![CDATA[<p>Then we can also have the fiscal year end date as {EE} and {EEEE} as well so that we can have ###/2018-19 if we use {NNN}/{FFFF}-{EE}.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-09T08:45:46Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33916#p33916</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33915#p33915" />
			<content type="html"><![CDATA[<p>I have added fix solving this problem to frontaccounting code base.<br />The number templates for short and long form of fiscal year number is {FF} and {FFFF} respectively, which seems to be more intuitive. Thank you for the idea. This will be available with next minor release.<br />Janusz</p>]]></content>
			<author>
				<name><![CDATA[itronics]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=89</uri>
			</author>
			<updated>2019-01-09T08:34:30Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33915#p33915</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33889#p33889" />
			<content type="html"><![CDATA[<p>@joe: This can be included. <a href="https://github.com/anoopmb/FA/commit/34e2e21901742b20ab7ee9433014d2f50f5a3629#diff-a0a0f2644dfd8504e5989eb2191b6f8e">Commit Diff</a>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-08T03:24:17Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33889#p33889</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33882#p33882" />
			<content type="html"><![CDATA[<p>@apmuthu</p><p>you&nbsp; can see my changes on my fork over </p><p><a href="https://github.com/anoopmb/FA/blob/master/includes/references.inc"> here</a></p><p>update is on 2.4.6 /includes/references.inc file</p><p>1. line no 55 updated the placeholder array to</p><div class="codebox"><pre><code>$refline_placeholders = array(
    &#039;MM&#039; =&gt; &#039;date&#039;,
    &#039;Y&#039; =&gt; &#039;date&#039;,
    &#039;YY&#039; =&gt; &#039;date&#039;,
    &#039;YYY&#039; =&gt; &#039;date&#039;,
    &#039;YYYY&#039; =&gt; &#039;date&#039;,
    &#039;UU&#039; =&gt; &#039;user&#039;,
    &#039;P&#039; =&gt; &#039;pos&#039;,
//     FIXME:  for placeholders below all the code should work, but as the ref length is variable,
//       length specification in placeholder format should be implemented.
//    &#039;C&#039; =&gt; &#039;customer&#039;,
//    &#039;B&#039; =&gt; &#039;branch&#039;,
//    &#039;S&#039; =&gt; &#039;supplier&#039;,
//    &#039;L&#039; =&gt; &#039;location&#039;
);</code></pre></div><br /><p>2. added new template in switch case line no 124</p><div class="codebox"><pre><code>                        case &#039;Y&#039;:
                        case &#039;YYY&#039;:
                            list($begin_day, $begin_month, $begin_year) = explode_date_to_dmy(begin_fiscalyear());
                            list($end_day, $end_month, $end_year) = explode_date_to_dmy(end_fiscalyear());
                            $out .= $ph == &#039;Y&#039; ? sprintf(&#039;%04d&#039;, $begin_year) : sprintf(&#039;%04d&#039;, $begin_year) . &quot;-&quot; . sprintf(&#039;%02d&#039;, $end_year % 100);
                            break;</code></pre></div><p>3. updated is_valid function line no 266</p><br /><div class="codebox"><pre><code>function is_valid($reference, $type, $context=null, $line=null)
    {
         if (!isset($line))
             $line = $this-&gt;reflines-&gt;find_refline_id($reference, $type, true);

         if (!isset($line))
             return false;

        $refline = $this-&gt;reflines-&gt;get($line);

        if ($this-&gt;_legacy_line($refline))    //legacy non-templated line
            return strlen(trim($reference)) &gt; 0;

        $regex = preg_quote($refline[&#039;prefix&#039;].$refline[&#039;pattern&#039;]);
        if (!is_array($context))
            $context = array(&#039;date&#039;=&gt;$context);

         $context[&#039;pos&#039;] = $_SESSION[&quot;wa_current_user&quot;]-&gt;pos;

        if (is_date(@$context[&#039;date&#039;]))
        {
            list($year4, $month, $day) = explode(&quot;-&quot;, date2sql($context[&#039;date&#039;]));
            list($begin_year, $begin_month, $begin_day) = explode(&quot;-&quot;, date2sql(begin_fiscalyear()));
            list($end_year, $end_month, $end_day) = explode(&quot;-&quot;, date2sql(end_fiscalyear()));
            $year2 = substr($year4, 2);
            $year3 = $begin_year.&quot;-&quot;.substr($end_year, 2);
        } else
        {
            $month = &#039;\d{2,}&#039;;
            $year2 = &#039;\d{2,}&#039;;
            $year4 = &#039;\d{4,}&#039;;
            $begin_year = &#039;\d{4,}&#039;;
            $year3 = &#039;\d{4,}-\d{2,}&#039;;
        }
        $cust = @$context[&#039;customer&#039;] ? $context[&#039;customer&#039;] : &#039;\d+&#039;;
        $supp = @$context[&#039;supplier&#039;] ? $context[&#039;supplier&#039;] : &#039;\d+&#039;;
        $branch = @$context[&#039;branch&#039;] ? $context[&#039;branch&#039;] : &#039;\d+&#039;;
        $location = @$context[&#039;location&#039;] ? $context[&#039;location&#039;] : &#039;[a-z0-9]+&#039;;
         $pos = @$context[&#039;pos&#039;] ? $context[&#039;pos&#039;] : &#039;\d+&#039;;
        $user = sprintf(&quot;%02d&quot;, $_SESSION[&#039;wa_current_user&#039;]-&gt;user);

        $regex = preg_replace(
            array(
                &#039;/\\\{/&#039;,    // unquote placeholders
                &#039;/\\\}/&#039;,
                &#039;/\{MM\}/&#039;,
                &#039;/\{Y\}/&#039;,
                &#039;/\{YY\}/&#039;,
                &#039;/\{YYY\}/&#039;,
                &#039;/\{YYYY\}/&#039;,
                &#039;/\{C\}/&#039;,
                &#039;/\{B\}/&#039;,
                &#039;/\{S\}/&#039;,
                &#039;/\{L\}/&#039;,
                &#039;/\{UU\}/&#039;,
                 &#039;/\{P\}/&#039;,
                &#039;/\{\d+}/&#039;,
            ),
            array(
                &#039;{&#039;,
                &#039;}&#039;,
                $month,
                $begin_year,
                $year2,
                $year3,
                $year4,
                $cust,
                $branch,
                $supp,
                $location,
                $user,
                 $pos,
                &#039;\d+&#039;,
            ), $regex);

        $regex = &#039;&quot;^&#039;.$regex.&#039;&quot;i&#039;;

        return preg_match($regex, $reference, $match) ? 1 : 0;
    }</code></pre></div>]]></content>
			<author>
				<name><![CDATA[anoopmb]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18207</uri>
			</author>
			<updated>2019-01-07T04:13:38Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33882#p33882</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33881#p33881" />
			<content type="html"><![CDATA[<p>@anoopmb: kindly submit your tested code changes for peer review and inclusion in the core for both {Y} and {YYY}.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-07T02:44:58Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33881#p33881</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33880#p33880" />
			<content type="html"><![CDATA[<p>i have made some changes to my code for now <br />expecting new format will come shortly</p>]]></content>
			<author>
				<name><![CDATA[anoopmb]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18207</uri>
			</author>
			<updated>2019-01-07T02:42:18Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33880#p33880</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33877#p33877" />
			<content type="html"><![CDATA[<p>This <a href="https://frontaccounting.com/fawiki/index.php?n=Help.FormsSetup">Wiki page</a> points to this thread.</p><p>@joe: Along with {Y}, try to include {YYY} to indicate both years if they lie in different calendar years like <strong>/2018-19</strong>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-06T16:16:31Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33877#p33877</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33873#p33873" />
			<content type="html"><![CDATA[<p>By the way the wiki is not updated with these patterns for Transaction References. How to use it?</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2019-01-06T14:46:39Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33873#p33873</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33869#p33869" />
			<content type="html"><![CDATA[<p>I will have Janusz to look at this.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2019-01-05T17:27:11Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33869#p33869</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33866#p33866" />
			<content type="html"><![CDATA[<p>@joe: This will be desirable to include in the core - {Y}.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-05T16:07:26Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33866#p33866</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33857#p33857" />
			<content type="html"><![CDATA[<p>@apmuthu</p><p>Thanks and its very easy to do by calling begin fiscal year method</p>]]></content>
			<author>
				<name><![CDATA[anoopmb]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18207</uri>
			</author>
			<updated>2019-01-05T10:10:51Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33857#p33857</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33851#p33851" />
			<content type="html"><![CDATA[<p>Your <strong>includes/references.inc</strong> line number 99 is for FA 2.3.x.<br />Lines 121, 122 are for FA 2.4.x.</p><p>Just take the Year of the fiscal year beginning only!</p><p>Besides, this will all go wrong if the template is created with all the date elements for when there are too many transactions each day and a template like {DD}{MM}{YYYY} is used! A separate template like {Y} may be used for this kind of resetting of the year each fiscal beginning.</p><p>There is a <strong>function get_fiscalyear_begin_for_date($date)</strong> that obtains the financial year beginning in the file <strong>admin/db/fiscalyears_db.inc</strong>. Also available in it is <strong>get_current_fiscalyear()</strong>. These functions return the MySQL date format whilst taking the user date format as input where needed.</p><p>There is another <strong>function begin_fiscalyear()</strong> that gets the current fiscal year&#039;s begin date in user date format in <strong>includes/date_functions.inc</strong>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-01-05T07:00:53Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33851#p33851</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[New Year reference resetting]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=33843#p33843" />
			<content type="html"><![CDATA[<p>hi,<br />I found one issue that , in India fiscal year end is 31st March of every year, so if I use {YYYY) template on reference, the reference number will reset to start from one on 1st of January.</p><p>for eg. 31st December reference was SO201800080 but on January 1st it became SO201900001 which cant be accepted because current fiscal year is not closed and it should be continuation of last reference (SO201800081)&nbsp; till 31st March.</p><p>My ugly hack to resolve this is</p><p>1. get current fiscal year begin<br />2. check context date is in fiscal year and both year is not same<br />3. if its matching create a new date with previous year and set it as date in reference context</p><div class="codebox"><pre><code>        list($day, $month, $year) = explode_date_to_dmy(begin_fiscalyear());
        list($day1, $month1, $year1) = explode_date_to_dmy($context[&#039;date&#039;]);

    if(is_date_in_fiscalyear($context[&#039;date&#039;])&amp;&amp;$year!=$year1){
            $mdate=sql2date($year.&quot;-&quot;.$month1.&quot;-&quot;.$day1);
            $context[&#039;date&#039;]=$mdate;
        }</code></pre></div><p>added above code in reference.inc line number 99</p><p>Please suggest me if there is better way to resolve this</p>]]></content>
			<author>
				<name><![CDATA[anoopmb]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=18207</uri>
			</author>
			<updated>2019-01-05T01:46:27Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=33843#p33843</id>
		</entry>
</feed>
