<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[FrontAccounting forum — Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
	<link rel="self" href="https://frontaccounting.com/punbb/extern.php?action=feed&amp;tid=6474&amp;type=atom" />
	<updated>2019-03-01T16:39:41Z</updated>
	<generator>PunBB</generator>
	<id>https://frontaccounting.com/punbb/viewtopic.php?id=6474</id>
		<entry>
			<title type="html"><![CDATA[Re: Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=34380#p34380" />
			<content type="html"><![CDATA[<p>Read the <a href="https://github.com/apmuthu/FA24extensions/tree/master/Extensions/import_multijournalentries/doc">docs/readme.txt</a> in the module.</p>]]></content>
			<author>
				<name><![CDATA[apmuthu]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=364</uri>
			</author>
			<updated>2019-03-01T16:39:41Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=34380#p34380</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=34377#p34377" />
			<content type="html"><![CDATA[<p>I want to import my opening balances for my customers, suppliers and inventory items during the current fiscal year. Utility named import multiple journal entries currently available in FA 2.4.* doesn&#039;t provide any sample csv format.</p><p>Any idea or suggestion on this.</p><br /><br /><p>Thanks<br />Usman Khan</p>]]></content>
			<author>
				<name><![CDATA[webmekanics]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=17057</uri>
			</author>
			<updated>2019-03-01T12:20:27Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=34377#p34377</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=31570#p31570" />
			<content type="html"><![CDATA[<p>@Braath Waate you are right</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2018-05-05T15:17:48Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=31570#p31570</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=31557#p31557" />
			<content type="html"><![CDATA[<p>I finally realized now what you are doing: importing opening balances from another ERP and dividing the AR/AP account balances into separate balances for each customer/supplier.&nbsp; Thus your mod adding person_id to the import makes sense.&nbsp; Future customer payments then can be applied against the AR established by the journal entry.&nbsp; I tested this just to make sure it works and it does.&nbsp; I am guessing that it works for AP as well.</p><p>Indeed, this approach is more intuitive than the one mentioned in the <a href="https://frontaccounting.com/fawiki/index.php?n=Main.OpeningBalances?setlang=sv">wiki</a> and I recommend that the wiki be updated to mention this approach.&nbsp; </p><p>Ignore my prior post because I was speaking to import <em>transactions</em> from another ERP (i.e. the entire general journal).&nbsp; &nbsp;The problem with that style of import is that FA assigns counterparty to payments/AR but not to sales/AR, resulting in the overpaid issue as described.</p>]]></content>
			<author>
				<name><![CDATA[Braath Waate]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=41493</uri>
			</author>
			<updated>2018-05-02T12:32:58Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=31557#p31557</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=31548#p31548" />
			<content type="html"><![CDATA[<p>To me, importing customer/supplier (person) info into FA is deceptively simple.</p><p>1. To do this import, first one must know the person_id, which requires some kind of lookup by name.<br />2. By adding person_id, I am guessing that FA creates customer/supplier records.&nbsp; If so, you will see these by doing customer/supplier inquiry.<br />3. Imported payments will have no FA invoices, so no allocations against invoices are made.<br />4. Thus, after the import, customer/supplier accounts will appear to have been overpaid, although the AR/AP G/L accounts should be correct.&nbsp; But I would have guessed that this would have been the case even without the person_id, so I am confused at what trial balance account was fixed by adding person_id.</p><p>If this is not the case, and somehow your customer/supplier accounts appear correct after the import, you have discovered something that I do not know.</p><p>Otherwise, the question then becomes how to correct the customer/supplier accounts.&nbsp; I don&#039;t have an easy answer.</p><p>A. Creating dummy customer/supplier invoices in FA may work, but I think that may double the sales and A/R G/L accounts, so may require a GJ entry to fix that.</p><p>B. What I did:</p><p>B.1. zero out the amounts in the customer trans db after the import to get zero balances.&nbsp; </p><p>B.2. Double enter new payments from pre-import invoices into both FA and the old ERP. </p><p>B.3. FA payments were entered using a GJ entry against AR and the appropriate bank account so as not to affect the zero customer balance.</p><p>B.4 New invoices and payments were entered in FA and eventually the customer balances became correct.</p><p>B.5 update the suppler trans database to make all transactions allocated.</p>]]></content>
			<author>
				<name><![CDATA[Braath Waate]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=41493</uri>
			</author>
			<updated>2018-05-01T12:57:55Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=31548#p31548</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=31547#p31547" />
			<content type="html"><![CDATA[<p>I have modified <strong>import_multiplejournalentries.php</strong> to add Journal Entries for Customers and Suppliers</p><div class="codebox"><pre><code>&lt;?php
/**********************************************
Author: Tom Hallman
Name: Import Multiple Journal Entries/Deposits/Payments v2.3
Free software under GNU GPL
***********************************************/
$page_security = &#039;SA_CSVMULTIJOURNALIMPORT&#039;;
$path_to_root=&quot;../..&quot;;

include_once($path_to_root . &quot;/includes/ui/items_cart.inc&quot;);
include_once($path_to_root . &quot;/gl/includes/db/gl_db_trans.inc&quot;);
include_once($path_to_root . &quot;/includes/session.inc&quot;);
add_access_extensions();

// Turn these next two lines on for debugging
//error_reporting(E_ALL);
//ini_set(&quot;display_errors&quot;, &quot;on&quot;);

//--------------------------------------------------------------------------------------------------

function init_entry(&amp;$entry,$type,$date,$reference) // See gl/gl_journal::create_cart() &amp; gl/gl_bank::handle_new_order()
{
    $entry = new items_cart($type);
    $entry-&gt;order_id = 0;
    $entry-&gt;tran_date = $date;
    $entry-&gt;reference = $reference;
    $entry-&gt;memo_ = &#039;Imported via \&#039;Import Multiple Journal Entries\&#039; plugin&#039;;
}

//--------------------------------------------------------------------------------------------------

function import_type_list_row($label, $name, $selected=null, $submit_on_change=false)
{
    $arr = array(
        ST_JOURNAL=&gt; &quot;Journal Entry&quot;,
        ST_BANKDEPOSIT=&gt; &quot;Deposit&quot;,
        ST_BANKPAYMENT=&gt; &quot;Payment&quot;
    );

    echo &quot;&lt;tr&gt;&lt;td class=&#039;label&#039;&gt;$label&lt;/td&gt;&lt;td&gt;&quot;;
    echo array_selector($name, $selected, $arr,
        array(
            &#039;select_submit&#039;=&gt; $submit_on_change,
            &#039;async&#039; =&gt; false,
        ));
    echo &quot;&lt;/td&gt;&lt;/tr&gt;\n&quot;;
}

//--------------------------------------------------------------------------------------------------

function check_journal_entry(&amp;$entry, $entryid)
{
    // Check that this journal entry adds up!
    if (abs($entry-&gt;gl_items_total()) &gt; 0.0001)
    {
        display_error(&quot;Error: journal entry with entryid &#039;$entryid&#039; does not balance (import file: &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
        return true;
    }
}

function write_trans($type, $entry, $curEntryId, $bank_account)
{
    if ($type == ST_JOURNAL)
    {
        if (!check_journal_entry($entry, $curEntryId));
            write_journal_entries($entry, false, false); // FA built-in function
    }
    elseif ($type == ST_BANKDEPOSIT || $type == ST_BANKPAYMENT) {
        add_bank_transaction($entry-&gt;trans_type, $bank_account, $entry, $entry-&gt;tran_date, // FA built-in function
            false, false, false, $entry-&gt;reference, $entry-&gt;memo_, false);
    }

}
//--------------------------------------------------------------------------------------------------

function get_dimension_id_from_reference($ref)
{
    if ($ref == null || trim($ref) == &#039;&#039;)
        return 0;

    $sql = &quot;SELECT id FROM &quot;.TB_PREF.&quot;dimensions WHERE reference LIKE &quot;.db_escape($ref);

    $result = db_query($sql, &quot;could not get dimension from reference&quot;);

    $row = db_fetch_row($result);

    return $row[0];
}

//--------------------------------------------------------------------------------------------------
// Begin the UI
include_once($path_to_root . &quot;/includes/ui.inc&quot;);

page(&quot;Import Multiple Journal Entries / Deposits / Payments&quot;);

// If the import button was selected, we&#039;ll process the form here.  (If not, skip to actual content below.)
if (isset($_POST[&#039;import&#039;]))
{
    if (isset($_FILES[&#039;imp&#039;]) &amp;&amp; $_FILES[&#039;imp&#039;][&#039;name&#039;] != &#039;&#039;)
    {
        $filename = $_FILES[&#039;imp&#039;][&#039;tmp_name&#039;];
        $sep = $_POST[&#039;sep&#039;];
        $type = $_POST[&#039;type&#039;];
        $bank_account = isset($_POST[&#039;bank_account&#039;]) ? $_POST[&#039;bank_account&#039;] : &quot;&quot;;

        // Open the file
        $fp = @fopen($filename, &quot;r&quot;);
        if (!$fp)
        {
            display_error(&quot;Error opening file $filename&quot;);
        } else {

            // Initialize first entryid &amp; date to be null so that a new one is established
            $curEntryId = $curDate = null;

            // Prepare the DB to receive the imported journal entries
            begin_transaction();

            // Process the import file
            $line = 0;
            $entryCount = 0;
            $error = false;
            $errCnt = 0;
            while ($data = fgetcsv($fp, 4096, $sep))
            {
                // Skip the first line, as it&#039;s a header
                if ($line++ == 0) continue;

                // Skip blank lines (which shouldn&#039;t happen in a well-formed CSV, but we&#039;ll be safe)
                if (count($data) == 1) continue;

                // Parse the row of data; Format: entryid,date,reference,accountcode,dimension1,dimension2,amount,memo
                list($entryid, $date, $reference, $code, $dim1_ref, $dim2_ref, $amt, $memo, $person_id) = $data;

                // If the entryid has changed, create the current journal entry (if there was one) and start a new one
                if ($entryid != $curEntryId) {

                    // Check that date is properly-formatted
                    if (!is_date($date)) {
                        display_error(&quot;Error: date &#039;$date&#039; not properly formatted (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                        $error = true;
                    }

                    // Check that the date is in range
                    if (!is_date_in_fiscalyear($date)) {
                        display_error(&quot;Error: date not in fiscal year (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                        $error = true;
                    }

                    // Assign a default reference if it is not specified
                    if ($reference == &#039;&#039;) {
                        // If the entryid has shifted but date is the same, it needs another reference
                        if ($date == $curDate)
                            $refCount++;
                        else // else the entryid and date have shifted, so we can start with a new reference
                            $refCount = 1;
                        list($day, $month, $year) = explode_date_to_dmy($date);
                        $reference = &quot;$month/$day-$refCount&quot;;
                    }

                    // Check that the reference is not in use
                    global $Refs;
                    if (!$Refs-&gt;is_new_reference($reference,$type)) {
                        display_error(&quot;Error: reference &#039;$reference&#039; is already in use (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                        $error = true;
                    }

                    // All good! Initialize a new entry
                    if ($curEntryId != null) {
                        if (!$error)
                        {
                            write_trans($type, $entry, $curEntryId, $bank_account);
                            $entryCount++;
                        }
                    }
                    if ($error)
                        $errCnt++;
                    $error = false;
                    init_entry($entry,$type,$date,$reference);
                    $curEntryId = $entryid;
                    $curDate = $date;
                }

                if ($entryid == &#039;&#039;) {
                    display_error(&quot;Error: entryid not specified (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                    $error = true;
                }
                // Check that the account code exists
                if (get_gl_account($code) == null) {
                    display_error(&quot;Error: Could not find account code &#039;$code&#039; (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                    $error = true;
                }
                // Check that dimension 1 exists
                $dim1 = get_dimension_id_from_reference($dim1_ref);
                if ($dim1_ref != &#039;&#039; &amp;&amp; $dim1 == null) {
                    display_error(&quot;Error: Could not find dimension with reference &#039;$dim1_ref&#039; (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                    $error = true;
                }
                // Check that dimension 2 exists
                $dim2 = get_dimension_id_from_reference($dim2_ref);
                if ($dim2_ref != &#039;&#039; &amp;&amp; $dim2 == null) {
                    display_error(&quot;Error: Could not find dimension with reference &#039;$dim2_ref&#039; (line $line in import file &#039;{$_FILES[&#039;imp&#039;][&#039;name&#039;]}&#039;)&quot;);
                    $error = true;
                }

                if ($type == ST_BANKDEPOSIT)
                    $amt = -$amt;

                // Add to the journal entry / deposit / payment
                if (!$error)
                    $entry-&gt;add_gl_item($code, $dim1, $dim2, $amt, $memo,&#039;&#039;,$person_id);
            }

            // Process final entries in the file
            if (!$error)
            {
                if ($curEntryId != null) {
                    write_trans($type, $entry, $curEntryId, $bank_account);
                    $entryCount++;
                }
            } else
                $errCnt++;

            @fclose($fp);

            // Commit import to database
            if (!$errCnt)
                commit_transaction();

            if ($type == ST_JOURNAL)
                $typeString = &quot;journal entries&quot;;
            elseif ($type == ST_BANKDEPOSIT)
                $typeString = &quot;deposits&quot;;
            elseif ($type == ST_BANKPAYMENT)
                $typeString = &quot;payments&quot;;

            if (!$errCnt) {
                if ($entryCount &gt; 0)
                    display_notification_centered(&quot;$entryCount $typeString have been imported.&quot;);
                else
                    display_error(&quot;Import file contained no $typeString.&quot;);
            }
        }
    }
    else
        display_error(&quot;No import file selected&quot;);
}

start_form(true);

start_table(TABLESTYLE2);

if (!isset($_POST[&#039;type&#039;]))
    $_POST[&#039;type&#039;] = ST_JOURNAL;

if (!isset($_POST[&#039;sep&#039;]))
    $_POST[&#039;sep&#039;] = &quot;,&quot;;

    echo &#039; | &#039;;
    echo &quot;&lt;a href=https://my.pakerp.net/modules/import_multijournalentries/Journal_Entry.cs&gt;Click Here To Download Sample File For Import &lt;/a&gt;&quot;;
    echo &quot;&lt;br&gt; There should be no Comma (,) in any value in any column. Please double check before import&quot;;
    echo &quot;&lt;br&gt; For Customers Opening Balance person_id shall contain debtor_no field value and code shall be Accounts Receivable Code.&quot;;
    echo &quot;&lt;br&gt; For Suppliers Opening Balance person_id shall contain supplier_id field value and code shall be Accounts Payable Code.&quot;;

table_section_title(&quot;Import Settings&quot;);
import_type_list_row(&quot;Import Type:&quot;, &#039;type&#039;, $_POST[&#039;type&#039;], true);
if ($_POST[&#039;type&#039;] != ST_JOURNAL)
    bank_accounts_list_row( $_POST[&#039;type&#039;] == ST_BANKPAYMENT ? _(&quot;From:&quot;) : _(&quot;To:&quot;), &#039;bank_account&#039;, null, false);
text_row(&quot;Field Separator:&quot;, &#039;sep&#039;, $_POST[&#039;sep&#039;], 2, 1);
label_row(&quot;Import File:&quot;, &quot;&lt;input type=&#039;file&#039; id=&#039;imp&#039; name=&#039;imp&#039;&gt;&quot;);

end_table(1);

submit_center(&#039;import&#039;, &quot;Perform Import&quot;);//,true,false,&#039;process&#039;,ICON_SUBMIT);

end_form();

end_page();</code></pre></div><p>This is very helpful to record opening balances of all Trial Balance Accounts when shifting to FA from any other ERP.</p>]]></content>
			<author>
				<name><![CDATA[boxygen]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=20175</uri>
			</author>
			<updated>2018-05-01T06:44:33Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=31547#p31547</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Providing fix for Import Multiple Journal Entries module in v2.4rc1]]></title>
			<link rel="alternate" href="https://frontaccounting.com/punbb/viewtopic.php?pid=26370#p26370" />
			<content type="html"><![CDATA[<p>Hi BB&#039;ers,</p><p>I tried running the <strong>Import Multiple Journal Entries</strong> module on v2.4rc1.<br />It just wouldn&#039;t show anything after importing.<br />By enabling debug mode on the module file, I could see a php error on line 163, the module was using the function <strong>exists</strong> in <strong>/include/references.inc</strong>, which is now deprecated in v2.4rc1.</p><p><span style="color: #FF0000">Error: Call to undefined method references::exists() in /var/www/html/fa24/modules/import_multijournalentries/import_multijournalentries.php on line 163</span></p><p>I have changed the code line to use the new function <strong>is_new_reference</strong>, in the new <strong>/include/references.inc</strong> file.<br />So this is the change to apply in order to get it running:</p><p>On line 163, file <strong>/modules/import_multijournalentries/import_multijournalentries.php</strong>, remove line:<br /></p><div class="codebox"><pre><code>if $Refs-&gt;exists($type, $reference)) {</code></pre></div><p>And insert this line:<br /></p><div class="codebox"><pre><code>if (!($Refs-&gt;is_new_reference($reference,$type))) {</code></pre></div><p>After that, you may import using multiple journal entries module.</p><p>I&#039;ll report this on Mantis to be updated on future versions of FA.</p><p>Rgds.<br />AL.</p><p><a href="https://github.com/apmuthu/FA24extensions/commit/742e01b90090eeca0eb051430a8157337c7ba9ef">Committed</a>.</p>]]></content>
			<author>
				<name><![CDATA[albertolima]]></name>
				<uri>https://frontaccounting.com/punbb/profile.php?id=1640</uri>
			</author>
			<updated>2016-09-14T17:09:28Z</updated>
			<id>https://frontaccounting.com/punbb/viewtopic.php?pid=26370#p26370</id>
		</entry>
</feed>
