1 (edited by anoopmb 12/15/2019 11:35:16 am)

Topic: Opening Balance entry for Customers and Suppliers

I have done like this and would like to know will it be a proper solution?

This solution will accept negative values too , which will be a bank deposit by customer or payment to supplier

1. include item cart class in customer and suppliers

   

      include_once($path_to_root . "/includes/ui/items_cart.inc");
    

2. added two input fields to customers and suppliers master (amount and date)
   a. Customer

table_section(2);
    if (!$selected_id) {
        table_section_title(_("Opening Balance"));
        amount_row(_("Amount:"), 'opening_bal');
        if (!isset($_POST['ob_date']))
            $_POST['ob_date'] = add_days(begin_fiscalyear(), -1);
        date_row(_("As of:"), 'ob_date');
    } else {
        hidden('opening_bal', 0);
        hidden('ob_date', Today());
    }

b. Supplier

   if (!$supplier_id) {
        table_section_title(_("Opening Balance"));
        amount_row(_("Amount:"), 'opening_bal');
        if (!isset($_POST['ob_date']))
            $_POST['ob_date'] = add_days(begin_fiscalyear(), -1);
        date_row(_("As of:"), 'ob_date');
    } else {
        hidden('opening_bal', 0);
        hidden('ob_date', Today());
    }

It will appear only in new customer or supplier mode

3. Validation of Opening balance entry date in can_process() method

   for both Customer and supplier
   

    if (input_num('opening_bal') != 0 && !is_date(get_post('ob_date'))) {
        display_error(_("Invalid opening balance entry date."));
        set_focus('ob_date');
        return false;
    }
    

4.  Journal entry in handle_submit method
    a. customer
     

       if (input_num('opening_bal') != 0) {
            $cart = new items_cart(ST_JOURNAL);
            $cart->order_id = 0;
            $cart->tran_date = $cart->doc_date = $cart->event_date = get_post('ob_date');
            $cart->reference = $Refs->get_next(ST_JOURNAL, null, $cart->tran_date);
            $cart->tax_info = false;
            $cart->memo_ = _("Opening Balance Entry");
            $cart->currency = $_POST['curr_code'];
            if ($cart->currency != get_company_pref('curr_default'))
                $cart->rate = get_exchange_rate_to_home_currency($cart->currency,get_post('ob_date'));
            $cart->clear_items();
            if (input_num('opening_bal') > 0) {
                $cart->add_gl_item(get_company_pref('debtors_act'), 0,
                    0, input_num('opening_bal'), _("Opening Balance Entry"), '', $selected_id);
                $cart->add_gl_item(get_company_pref('default_inv_sales_act'), 0,
                    0, input_num('opening_bal') * -1, _("Opening Balance Entry"), '', $selected_id);
            } else {
                $cart->add_gl_item(get_company_pref('debtors_act'), 0,
                    0, input_num('opening_bal'), _("Opening Balance Entry"), '', $selected_id);
                $bank_account= get_bank_account(get_default_customer_bank_account($selected_id));
                $cart->add_gl_item($bank_account['account_code'], 0,
                    0, input_num('opening_bal')*-1 , _("Opening Balance Entry"), '', $selected_id);
            }
            $trans_no = write_journal_entries($cart);

        }
     

    b. Supplier
     

if (input_num('opening_bal') != 0) {
            $cart = new items_cart(ST_JOURNAL);
            $cart->order_id = 0;
            $cart->tran_date = $cart->doc_date = $cart->event_date = get_post('ob_date');
            $cart->reference = $Refs->get_next(ST_JOURNAL, null, $cart->tran_date);
            $cart->tax_info = false;
            $cart->memo_ = _("Opening Balance Entry");
            $cart->currency = $_POST['curr_code'];
            if ($cart->currency != get_company_pref('curr_default'))
                $cart->rate = get_exchange_rate_to_home_currency($cart->currency,get_post('ob_date'));
            $cart->clear_items();
            if (input_num('opening_bal') > 0) {
                $cart->add_gl_item($_POST['payable_account'], 0,
                    0, input_num('opening_bal')* -1, _("Opening Balance Entry"), '', $supplier_id);
                $cart->add_gl_item($_POST['purchase_account']!=''?$_POST['purchase_account']:get_company_pref('grn_clearing_act'), 0,
                    0, input_num('opening_bal') , _("Opening Balance Entry"), '', $supplier_id);
            } else {
                $cart->add_gl_item($_POST['payable_account'], 0,
                    0, input_num('opening_bal')* -1, _("Opening Balance Entry"), '', $supplier_id);
                $bank_account= get_bank_account(get_default_supplier_bank_account($supplier_id));
                $cart->add_gl_item($bank_account['account_code'], 0,
                    0, input_num('opening_bal') , _("Opening Balance Entry"), '', $supplier_id);
            }
            $trans_no = write_journal_entries($cart);

        }
      

NB: patch file is available on request

ANOOP
Experience is the name everyone gives to their mistakes!

Re: Opening Balance entry for Customers and Suppliers

Does the opening balance not come calculated by default in FA? Is it not generally done using a Journal Entry at the start of FA?

3 (edited by anoopmb 12/15/2019 06:21:00 pm)

Re: Opening Balance entry for Customers and Suppliers

This solution can be applied when people shifting to FA

ANOOP
Experience is the name everyone gives to their mistakes!

Re: Opening Balance entry for Customers and Suppliers

In such a case, migrating the entire trial balance is done in two steps involving a temporary Suspense Account as the contra Account.
1. Move all (non allocatable) Non Supplier / Non Customer Balance Sheet / TB entries into FA using Journal Entry
2. Use Credit Note / Debit Note to bring forward allocatable payments for the Customer / Supplier balances

@joe: any better practice?

5 (edited by anoopmb 12/16/2019 03:10:35 pm)

Re: Opening Balance entry for Customers and Suppliers

ok right, if anybody shifting to FA but dont want to import old transactions  but want to start as new in FA , i think they can use this solution for their old customers and suppliers

ANOOP
Experience is the name everyone gives to their mistakes!

Re: Opening Balance entry for Customers and Suppliers

With patch files it will be easy to test.

www.boxygen.pk

Re: Opening Balance entry for Customers and Suppliers

Hi,

you can download patch file from HERE

Post's attachments

2_4_7_Added_opening_balance_entry_for_Customers_and_Suppliers.patch 8.3 kb, 17 downloads since 2019-12-17 

You don't have the permssions to download the attachments of this post.
ANOOP
Experience is the name everyone gives to their mistakes!