prashants / webzash

Easy to use web based double entry accounting software in PHP - MySQL under MIT License
http://webzash.org
Other
208 stars 109 forks source link

Balance Sheet #74

Open kjcpa opened 7 years ago

kjcpa commented 7 years ago

A) Assets: 1) Normal asset account balance is Dr., but normal balance for Accumulated Depreciation under Fixed Assets is Cr. 2) Net Profit or loss is not an asset item.

B) Liabilities: normal liability account balance is Cr., but it may be Dr. if an account is overpaid.

C) Equity: 1)Normal equity account balance is Cr., but Dr. for Owner's Withdrawal account. 2)It may be Cr. or Dr. for Retained Earnings and/or Net-Profit/Loss.

D) Assets = Liabilities + Owners' Equity

kjcpa commented 7 years ago

I made some changes.

kjcpa commented 7 years ago

For InitialData.Mysql.sql

INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (1, NULL, 'Assets', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (2, NULL, 'Liabilities', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (3, NULL, 'Owners Equity', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (4, NULL, 'Incomes', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (5, NULL, 'Expenses', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (6, 1, 'Fixed Assets', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (7, 1, 'Current Assets', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (8, 1, 'Other Assets', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (9, 3, 'Capital Account', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (10, 2, 'Current Liabilities', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (11, 2, 'Long-term Liabilities', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (12, 4, 'Direct Incomes', NULL, 1); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (13, 5, 'Direct Expenses', NULL, 1); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (14, 4, 'Indirect Incomes', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (15, 5, 'Indirect Expenses', NULL, 0); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (16, 4, 'Sales', NULL, 1); INSERT INTO %_PREFIX_%groups (id, parent_id, name, code, affects_gross) VALUES (17, 5, 'Cost of Goods Sold', NULL, 1);

INSERT INTO %_PREFIX_%entrytypes (id, label, name, description, base_type, numbering, prefix, suffix, zero_padding, restriction_bankcash) VALUES (1, 'receipt', 'Receipt', 'Received in Bank account or Cash account', 1, 1, '', '', 0, 2); INSERT INTO %_PREFIX_%entrytypes (id, label, name, description, base_type, numbering, prefix, suffix, zero_padding, restriction_bankcash) VALUES (2, 'payment', 'Payment', 'Payment made from Bank account or Cash account', 1, 1, '', '', 0, 3); INSERT INTO %_PREFIX_%entrytypes (id, label, name, description, base_type, numbering, prefix, suffix, zero_padding, restriction_bankcash) VALUES (3, 'contra', 'Transfer', 'Transfer between Bank account and Cash account', 1, 1, '', '', 0, 4); INSERT INTO %_PREFIX_%entrytypes (id, label, name, description, base_type, numbering, prefix, suffix, zero_padding, restriction_bankcash) VALUES (4, 'journal', 'Journal', 'Transfer between Non Bank account and Cash account', 1, 1, '', '', 0, 5);

kjcpa commented 7 years ago

1)id 1 for asset, 2 for liabilities, 3 for Owners Equity, 4 for income, and 5 for expense.

2)"Purchase" is changed to "Cost of Goods Sold". "Purchase" will be under "Cost of Goods Sold".

3)"Loan (Liabilities)" is changed to 'Long-term Liabilities'.

4)"Investments" is changed to "Other Assets".

kjcpa commented 7 years ago

webzash/app/Plugin/Webzash/View/Accounts/show.ctp: "4" is changed to "5":

/* Print groups */ if ($account->id != 0) { if ($account->id <= 5) { echo ''; } else { echo ''; }

kjcpa commented 7 years ago

Changes to ReportsControler.php:

    /**********************************************************************/
    /*********************** BALANCESHEET CALCULATIONS ********************/
    /**********************************************************************/

    /* Equity */
    $equity = new AccountList();
    $equity->Group = &$this->Group;
    $equity->Ledger = &$this->Ledger;
    $equity->only_opening = $only_opening;
    //$equity->start_date = $startdate;
    $equity->end_date = $enddate;
    $equity->affects_gross = -1;
    $equity->start(3);

    $bsheet['equity'] = $equity;

    $bsheet['equity_total'] = 0;
    if ($equity->cl_total_dc == 'C') {
        $bsheet['equity_total'] = $equity->cl_total;
    } else {
        $bsheet['equity_total'] = calculate($equity->cl_total, 0, 'n');
    }
/* Liabilities */
    $liabilities = new AccountList();
    $liabilities->Group = &$this->Group;
    $liabilities->Ledger = &$this->Ledger;
    $liabilities->only_opening = $only_opening;
    //$liabilities->start_date = $startdate;
    $liabilities->end_date = $enddate;
    $liabilities->affects_gross = -1;
    $liabilities->start(2);

    $bsheet['liabilities'] = $liabilities;

    $bsheet['liabilities_total'] = 0;
    if ($liabilities->cl_total_dc == 'C') {
        $bsheet['liabilities_total'] = $liabilities->cl_total;
    } else {
        $bsheet['liabilities_total'] = calculate($liabilities->cl_total, 0, 'n');
    }
    /* Assets */
    $assets = new AccountList();
    $assets->Group = &$this->Group;
    $assets->Ledger = &$this->Ledger;
    $assets->only_opening = $only_opening;
    //$assets->start_date = $startdate;
    $assets->end_date = $enddate;
    $assets->affects_gross = -1;
    $assets->start(1);

    $bsheet['assets'] = $assets;

    $bsheet['assets_total'] = 0;
    if ($assets->cl_total_dc == 'D') {
        $bsheet['assets_total'] = $assets->cl_total;
    } else {
        $bsheet['assets_total'] = calculate($assets->cl_total, 0, 'n');
    }

    /* Profit and loss calculations */
    $income = new AccountList();
    $income->Group = &$this->Group;
    $income->Ledger = &$this->Ledger;
    $income->only_opening = $only_opening;
    $income->start_date = $startdate;
    $income->end_date = $enddate;
    $income->affects_gross = -1;
    $income->start(4);

    $expense = new AccountList();
    $expense->Group = &$this->Group;
    $expense->Ledger = &$this->Ledger;
    $expense->only_opening = $only_opening;
    $expense->start_date = $startdate;
    $expense->end_date = $enddate;
    $expense->affects_gross = -1;
    $expense->start(5);

    if ($income->cl_total_dc == 'C') {
        $income_total = $income->cl_total;
    } else {
        $income_total = calculate($income->cl_total, 0, 'n');
    }
    if ($expense->cl_total_dc == 'D') {
        $expense_total = $expense->cl_total;
    } else {
        $expense_total = calculate($expense->cl_total, 0, 'n');
    }

    $bsheet['pandl'] = calculate($income_total, $expense_total, '-');

    /* Difference in opening balance */
    $bsheet['opdiff'] = $this->Ledger->getOpeningDiff();
    if (calculate($bsheet['opdiff']['opdiff_balance'], 0, '==')) {
        $bsheet['is_opdiff'] = false;
    } else {
        $bsheet['is_opdiff'] = true;
    }

    /**** Final balancesheet total ****/
    $bsheet['final_liabilities_total'] = $bsheet['liabilities_total'];
            $bsheet['final_equity_total'] = $bsheet['equity_total'];
    $bsheet['final_assets_total'] = $bsheet['assets_total'];

    /* If net profit add to liabilities and equity, if net loss add to assets */
    if (calculate($bsheet['pandl'], 0, '>=')) {
        $bsheet['final_equity_total'] = calculate(
            $bsheet['final_equity_total'],
            $bsheet['pandl'], '+');
    } else {
        $positive_pandl = calculate($bsheet['pandl'], 0, 'n');
        $bsheet['final_equit_total'] = calculate(
            $bsheet['final_equity_total'],
            $positive_pandl, '-');
    }

    /**
     * If difference in opening balance is Dr then subtract from
     * assets else subtract from liabilities
     */
    if ($bsheet['is_opdiff']) {
        if ($bsheet['opdiff']['opdiff_balance_dc'] == 'D') {
            $bsheet['final_assets_total'] = calculate(
                $bsheet['final_assets_total'],
                $bsheet['opdiff']['opdiff_balance'], '+');
        } else {
            $bsheet['final_liabilities_total'] = calculate(
                $bsheet['final_liabilities_total'],
                $bsheet['opdiff']['opdiff_balance'], '+');
        }
    }

    $this->set('bsheet', $bsheet);
kjcpa commented 7 years ago

Changes to balancesheet.ctp:

balancesheet.txt

kjcpa commented 7 years ago

Changes to DashboardController.php:

DashboardController.txt

kjcpa commented 7 years ago

webzash/app/Plugin/Webzash/View/Dashboard/index.ctp:

index.txt