<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Deleting a fiscal year problem]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=8793&amp;type=atom" />
	<updated>2020-09-03T15:43:16Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=8793</id>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=38266#p38266" />
			<content type="html"><![CDATA[<p>Hi all again,<br />Unfortunately i couldn&#039;t solve this problem yet. I modified sql to find invoices, payments and credit notes which allocated in year to delete. </p><div class="codebox"><pre><code>$sql = &quot;SELECT trans_no, type 
            FROM &quot;.TB_PREF.&quot;debtor_trans 
            WHERE tran_date &lt;= &#039;$to&#039; 
            AND (round((ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount), 3) = round((SELECT SUM(amt) FROM &quot;.TB_PREF.&quot;cust_allocations WHERE date_alloc &lt;= &#039;$to&#039; AND trans_no = trans_no_to AND    type = trans_type_to), 3) 
            OR round((ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount), 3) = round((SELECT SUM(amt) FROM &quot;.TB_PREF.&quot;cust_allocations WHERE date_alloc &lt;= &#039;$to&#039; AND trans_no = trans_no_from AND    type = trans_type_from), 3))&quot;;</code></pre></div><br /><p>But it&#039;s not enough to find right transactions to delete. Still I have to separate some invoices and payment. <br />So I have an invoice (1800$) invoiced in 2015 and i have a payment (800$) paid in 2015. This payment is fully allocated to this invoice but remaining balance of this invoice (1000$) paid in 2016. <br />This sql find 800$ payment to delete because this payment is fully allocated in 2015 but invoice is still alive because it&#039;s not fully allocated in 2015.&nbsp; I have to keep this payment to find right balance at the end of 2015. <br />How can i do this? Hope i could explain the problem which i couldn&#039;t solve.</p><p>Thanks in advance.</p>]]></content>
			<author>
				<name><![CDATA[madosk]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44512</uri>
			</author>
			<updated>2020-09-03T15:43:16Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=38266#p38266</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37558#p37558" />
			<content type="html"><![CDATA[<p>This fix only delete allocation. Payment must be deleted too. </p><div class="codebox"><pre><code>$sql = &quot;SELECT trans_no, type FROM &quot;.TB_PREF.&quot;debtor_trans WHERE tran_date &lt;= &#039;$to&#039; AND 
        (ov_amount + ov_gst + ov_freight + ov_freight_tax + ov_discount) = 
        (SELECT SUM(amt) FROM &quot;.TB_PREF.&quot;cust_allocations WHERE date_alloc &lt;= &#039;$to&#039; AND trans_no = trans_no_to AND
        type = trans_type_to)&quot;;</code></pre></div><p>This sql can not find the payment to delete.</p>]]></content>
			<author>
				<name><![CDATA[madosk]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44512</uri>
			</author>
			<updated>2020-05-20T16:27:58Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37558#p37558</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37557#p37557" />
			<content type="html"><![CDATA[<p>Looks like this is a strange issue. I feel the below code is missing the cust allocation. </p><div class="codebox"><pre><code>  while ($row = db_fetch($result))
    {
        if ($row[&#039;type&#039;] == ST_SALESINVOICE)
        {
            $deliveries = get_sales_parent_numbers($row[&#039;type&#039;], $row[&#039;trans_no&#039;]);
            foreach ($deliveries as $delivery)
            {
                $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;debtor_trans_details WHERE debtor_trans_no = $delivery AND debtor_trans_type = &quot;.ST_CUSTDELIVERY;
                db_query($sql, &quot;Could not delete debtor trans details&quot;);
                $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;debtor_trans WHERE trans_no = $delivery AND type = &quot;.ST_CUSTDELIVERY;
                db_query($sql, &quot;Could not delete debtor trans&quot;);
                delete_attachments_and_comments(ST_CUSTDELIVERY, $delivery);
            }        
        }    
        $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;cust_allocations WHERE trans_no_from = {$row[&#039;trans_no&#039;]} AND trans_type_from = {$row[&#039;type&#039;]}&quot;;
        db_query($sql, &quot;Could not delete cust allocations&quot;);
.
.
.
}</code></pre></div><p>And may be it should be like this <br /></p><div class="codebox"><pre><code>while ($row = db_fetch($result))
    {
        if ($row[&#039;type&#039;] == ST_SALESINVOICE)
        {
            $deliveries = get_sales_parent_numbers($row[&#039;type&#039;], $row[&#039;trans_no&#039;]);
            foreach ($deliveries as $delivery)
            {
                $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;debtor_trans_details WHERE debtor_trans_no = $delivery AND debtor_trans_type = &quot;.ST_CUSTDELIVERY;
                db_query($sql, &quot;Could not delete debtor trans details&quot;);
                $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;debtor_trans WHERE trans_no = $delivery AND type = &quot;.ST_CUSTDELIVERY;
                db_query($sql, &quot;Could not delete debtor trans&quot;);
                delete_attachments_and_comments(ST_CUSTDELIVERY, $delivery);
            }        
                      $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;cust_allocations WHERE trans_no_to = {$row[&#039;trans_no&#039;]} AND trans_type_to = {$row[&#039;type&#039;]}&quot;;  // newly added 
        db_query($sql, &quot;Could not delete cust allocations&quot;);  // newly added. 
        }    
        $sql = &quot;DELETE FROM &quot;.TB_PREF.&quot;cust_allocations WHERE trans_no_from = {$row[&#039;trans_no&#039;]} AND trans_type_from = {$row[&#039;type&#039;]}&quot;;
        db_query($sql, &quot;Could not delete cust allocations&quot;);
}</code></pre></div><p>I have added two more lines added newly to collect the respective invoice allocation entires delete. Like the same for supplier allocations.</p><p>If it helps feedback us to fix it in core.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2020-05-20T15:32:29Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37557#p37557</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37556#p37556" />
			<content type="html"><![CDATA[<p>After deletion year 2014 customer has records in debtor_trans table. For example;</p><p><strong>debtor_trans</strong><br />trans_no: <span class="bbu">15496</span><br />type: 12<br />tran_date: 2014-09-29<br />ov_amount: 785<br />alloc: 785</p><p><strong>cust_allocations</strong><br />amt: 335<br />date_alloc: 2014-09-29<br />trans_no_from: <span class="bbu">15496</span><br />trans_type_from: 12<br />trans_no_to: 14931<br />trans_type_to: 10&nbsp; &nbsp; </p><p>amt: 450<br />date_alloc: 2014-09-29<br />trans_no_from: <span class="bbu">15496</span><br />trans_type_from: 12<br />trans_no_to: 15472<br />trans_type_to: 10</p><p>But 15472, 14931 transactions do not exist in debtor_trans. Why this payment didn&#039;t deleted? whereas it payed in 2014 and allocated to invoices in 2014.</p><p>By the way invoices are still alive which are processed in 2014 and allocated in 2015. This part is working correct i think but payments part is not.</p>]]></content>
			<author>
				<name><![CDATA[madosk]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44512</uri>
			</author>
			<updated>2020-05-20T14:47:31Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37556#p37556</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37555#p37555" />
			<content type="html"><![CDATA[<p>I have compatibility problem. I &#039;m using 2.3.26 but commited file compatible with 2.4.x.<br />2.3.26 neither has add_journal method nor 0_journal table. <br />I removed this part of code and tried to delete year but unfortunately customer balance calculated wrong.<br />I&#039;m investigating why balance is wrong. I&#039;ll inform you more if i find something.</p>]]></content>
			<author>
				<name><![CDATA[madosk]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44512</uri>
			</author>
			<updated>2020-05-20T13:56:04Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37555#p37555</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37539#p37539" />
			<content type="html"><![CDATA[<p>Updated <a href="https://frontaccounting.com/fawiki/index.php?n=Help.FiscalYears">Wiki</a>.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-05-17T16:38:51Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37539#p37539</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37524#p37524" />
			<content type="html"><![CDATA[<p>@joe, your solution is good. Instead of rewriting it as journal entry. We keep the invoices alive and it&#039;s allocations alive. So it will be removed if they remove next fiscal year.&nbsp; </p><p>@madosk, This is definitely a time saving way for you to implement it.&nbsp; Hope your problem fixed with this. And post an reply after using this updated program. It would be a solved solution for future referring users.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2020-05-15T11:12:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37524#p37524</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37523#p37523" />
			<content type="html"><![CDATA[<p>@joe: Thanks for solution. I have been working on it for a few days. Your solution is ver simple and i &#039;ll try asap. Will it work for payed before and invoiced next year transactions?</p>]]></content>
			<author>
				<name><![CDATA[madosk]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44512</uri>
			</author>
			<updated>2020-05-15T10:06:11Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37523#p37523</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37522#p37522" />
			<content type="html"><![CDATA[<p>The allocations has been revised and should now work. Committed to stable repo. The fixed file can be downloaded <a href="https://sourceforge.net/p/frontaccounting/git/ci/master/tree/admin/db/fiscalyears_db.inc">here</a>.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2020-05-15T08:44:52Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37522#p37522</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37521#p37521" />
			<content type="html"><![CDATA[<p>Oh yes, I see. The alloc field got stamped in the next year and when the invoice was not allocated by end of last year.<br />I will have to look at the allocation routines instead. Thanks.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2020-05-15T07:36:22Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37521#p37521</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37520#p37520" />
			<content type="html"><![CDATA[<p>How ever there is a problem with payment of next year for previous year invoice. </p><p>Let&#039;s take his example. He issued several invoices&nbsp; at the end of last year and collected the payment in next year.&nbsp; Which means the system needs to make one journal entry for a customer at least to record the invoice balances as opening balance and that should be allocated in the next year.</p>]]></content>
			<author>
				<name><![CDATA[kvvaradha]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=19348</uri>
			</author>
			<updated>2020-05-15T07:17:43Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37520#p37520</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37519#p37519" />
			<content type="html"><![CDATA[<p>Hello again.</p><p>I have now went through the deleting fiscal year procedure. I have found no problems here.<br />Here is a list over what happens when processing deleting of a fiscal year:</p><div class="codebox"><pre><code>Delete Fiscalyear

1. Backup is done
2. All sales orders and details, up to last date, that are fully delivered are removed. Attachments are removed.
3. All purchase orders and details, up to last date, that are fully received are removed. Attachments are removed.
4. All GRN receivals, up to last date, are removed.
5. All debtor trans and details, up to last date, that are fully allocated are removed. Attachments are removed.
6. All cust allocations, up to last date, are removed.
7. All supp trans and details, up to last date, that are fully allocated are removed. Attachments are removed.
8. All supp allocations, up to last date, are removed.
9. All workorders, up to last date, and closed.
   a. All workorder issues are removed. Attachments are removed.
   b. All workorder manufacture are removed. 
   c. All workorder requirements are removed.
   d. Workorders removed. Attachments are removed.
10. All stock moves, up to last date, are removed and converted to a closing stock move.
11. All voided items, up to last date, are removed.
12. All trans tax details, up to last date, are removed.
13. All exchange rater, up to last date, are removed.
14. All cust and supp sub gl transactions are retrieved by account, removed and an end transaction are inserted. 
15. All bank trans, up to last date, are removed and converted to a closing balance trans.
16. All ausit trail, up to last date, are removed.
17. All comments, up to last date, are removed.
18. Finally the fiscalyear is removed.</code></pre></div><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2020-05-15T06:40:49Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37519#p37519</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37507#p37507" />
			<content type="html"><![CDATA[<p>This is a difficult task. I remember writing these routines years back and we really tried to get it all at that time.<br />I will try to look into it asap.</p><p>Joe</p>]]></content>
			<author>
				<name><![CDATA[joe]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=3</uri>
			</author>
			<updated>2020-05-14T10:11:43Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37507#p37507</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37505#p37505" />
			<content type="html"><![CDATA[<p>@joe: Need to refurbish the end of year routines to make sure that the client balances are automatically made along with unpaid and partially paid invoice data for allocation of payments in the subsequent year. This needs to be done for suppliers as well. The appropriate stock moves too need to be taken care of.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2020-05-14T09:28:05Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37505#p37505</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Deleting a fiscal year problem]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=37492#p37492" />
			<content type="html"><![CDATA[<p>Yes you&#039;re right. Thanks for the idea <img src="https://frontaccounting.com/punbb/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />I&#039;ll inform you when finished.</p>]]></content>
			<author>
				<name><![CDATA[madosk]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=44512</uri>
			</author>
			<updated>2020-05-13T11:52:16Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=37492#p37492</id>
		</entry>
</feed>
