function convert_opening($amount, $dc) { if ($amount == 0) { return "0"; } else { if ($dc == 'D') { return "Dr " . convert_cur($amount); } else { return "Cr " . convert_cur($amount); } } }
function index() { $this->load->model('Ledger_model'); $this->template->set('page_title', 'Chart Of Accounts'); $this->template->set('nav_links', array('group/add' => 'Add Group', 'ledger/add' => 'Add Ledger')); /* Calculating difference in Opening Balance */ $total_op = $this->Ledger_model->get_diff_op_balance(); if ($total_op > 0) { $this->messages->add('Difference in Opening Balance is Dr ' . convert_cur($total_op) . '.', 'error'); } else { if ($total_op < 0) { $this->messages->add('Difference in Opening Balance is Cr ' . convert_cur(-$total_op) . '.', 'error'); } } $this->template->load('template', 'account/index'); return; }
function download($statement, $id = NULL) { /********************** TRIAL BALANCE *************************/ if ($statement == "trialbalance") { $this->load->model('Ledger_model'); $all_ledgers = $this->Ledger_model->get_all_ledgers(); $counter = 0; $trialbalance = array(); $temp_dr_total = 0; $temp_cr_total = 0; $trialbalance[$counter] = array("TRIAL BALANCE", "", "", "", "", "", "", "", ""); $counter++; $trialbalance[$counter] = array("FY " . date_mysql_to_php($this->config->item('account_fy_start')) . " - " . date_mysql_to_php($this->config->item('account_fy_end')), "", "", "", "", "", "", "", ""); $counter++; $trialbalance[$counter][0] = "Ledger"; $trialbalance[$counter][1] = ""; $trialbalance[$counter][2] = "Opening"; $trialbalance[$counter][3] = ""; $trialbalance[$counter][4] = "Closing"; $trialbalance[$counter][5] = ""; $trialbalance[$counter][6] = "Dr Total"; $trialbalance[$counter][7] = ""; $trialbalance[$counter][8] = "Cr Total"; $counter++; foreach ($all_ledgers as $ledger_id => $ledger_name) { if ($ledger_id == 0) { continue; } $trialbalance[$counter][0] = $ledger_name; list($opbal_amount, $opbal_type) = $this->Ledger_model->get_op_balance($ledger_id); if (float_ops($opbal_amount, 0, '==')) { $trialbalance[$counter][1] = ""; $trialbalance[$counter][2] = 0; } else { $trialbalance[$counter][1] = convert_dc($opbal_type); $trialbalance[$counter][2] = $opbal_amount; } $clbal_amount = $this->Ledger_model->get_ledger_balance($ledger_id); if (float_ops($clbal_amount, 0, '==')) { $trialbalance[$counter][3] = ""; $trialbalance[$counter][4] = 0; } else { if (float_ops($clbal_amount, 0, '<')) { $trialbalance[$counter][3] = "Cr"; $trialbalance[$counter][4] = convert_cur(-$clbal_amount); } else { $trialbalance[$counter][3] = "Dr"; $trialbalance[$counter][4] = convert_cur($clbal_amount); } } $dr_total = $this->Ledger_model->get_dr_total($ledger_id); if ($dr_total) { $trialbalance[$counter][5] = "Dr"; $trialbalance[$counter][6] = convert_cur($dr_total); $temp_dr_total = float_ops($temp_dr_total, $dr_total, '+'); } else { $trialbalance[$counter][5] = ""; $trialbalance[$counter][6] = 0; } $cr_total = $this->Ledger_model->get_cr_total($ledger_id); if ($cr_total) { $trialbalance[$counter][7] = "Cr"; $trialbalance[$counter][8] = convert_cur($cr_total); $temp_cr_total = float_ops($temp_cr_total, $cr_total, '+'); } else { $trialbalance[$counter][7] = ""; $trialbalance[$counter][8] = 0; } $counter++; } $trialbalance[$counter][0] = ""; $trialbalance[$counter][1] = ""; $trialbalance[$counter][2] = ""; $trialbalance[$counter][3] = ""; $trialbalance[$counter][4] = ""; $trialbalance[$counter][5] = ""; $trialbalance[$counter][6] = ""; $trialbalance[$counter][7] = ""; $trialbalance[$counter][8] = ""; $counter++; $trialbalance[$counter][0] = "Total"; $trialbalance[$counter][1] = ""; $trialbalance[$counter][2] = ""; $trialbalance[$counter][3] = ""; $trialbalance[$counter][4] = ""; $trialbalance[$counter][5] = "Dr"; $trialbalance[$counter][6] = convert_cur($temp_dr_total); $trialbalance[$counter][7] = "Cr"; $trialbalance[$counter][8] = convert_cur($temp_cr_total); $this->load->helper('csv'); echo array_to_csv($trialbalance, "trialbalance.csv"); return; } /********************** LEDGER STATEMENT **********************/ if ($statement == "ledgerst") { $ledger_id = (int) $this->uri->segment(4); if ($ledger_id < 1) { return; } $this->load->model('Ledger_model'); $cur_balance = 0; $counter = 0; $ledgerst = array(); $ledgerst[$counter] = array("", "", "LEDGER STATEMENT FOR " . strtoupper($this->Ledger_model->get_name($ledger_id)), "", "", "", "", "", "", "", ""); $counter++; $ledgerst[$counter] = array("", "", "FY " . date_mysql_to_php($this->config->item('account_fy_start')) . " - " . date_mysql_to_php($this->config->item('account_fy_end')), "", "", "", "", "", "", "", ""); $counter++; $ledgerst[$counter][0] = "Date"; $ledgerst[$counter][1] = "Number"; $ledgerst[$counter][2] = "Ledger Name"; $ledgerst[$counter][3] = "Narration"; $ledgerst[$counter][4] = "Type"; $ledgerst[$counter][5] = ""; $ledgerst[$counter][6] = "Dr Amount"; $ledgerst[$counter][7] = ""; $ledgerst[$counter][8] = "Cr Amount"; $ledgerst[$counter][9] = ""; $ledgerst[$counter][10] = "Balance"; $counter++; /* Opening Balance */ list($opbalance, $optype) = $this->Ledger_model->get_op_balance($ledger_id); $ledgerst[$counter] = array("Opening Balance", "", "", "", "", "", "", "", "", convert_dc($optype), $opbalance); if ($optype == "D") { $cur_balance = float_ops($cur_balance, $opbalance, '+'); } else { $cur_balance = float_ops($cur_balance, $opbalance, '-'); } $counter++; $this->db->select('entries.id as entries_id, entries.number as entries_number, entries.date as entries_date, entries.narration as entries_narration, entries.entry_type as entries_entry_type, entry_items.amount as entry_items_amount, entry_items.dc as entry_items_dc'); $this->db->from('entries')->join('entry_items', 'entries.id = entry_items.entry_id')->where('entry_items.ledger_id', $ledger_id)->order_by('entries.date', 'asc')->order_by('entries.number', 'asc'); $ledgerst_q = $this->db->get(); foreach ($ledgerst_q->result() as $row) { /* Entry Type */ $current_entry_type = entry_type_info($row->entries_entry_type); $ledgerst[$counter][0] = date_mysql_to_php($row->entries_date); $ledgerst[$counter][1] = full_entry_number($row->entries_entry_type, $row->entries_number); /* Opposite entry name */ $ledgerst[$counter][2] = $this->Ledger_model->get_opp_ledger_name($row->entries_id, $row->entries_entry_type, $row->entry_items_dc, 'text'); $ledgerst[$counter][3] = $row->entries_narration; $ledgerst[$counter][4] = $current_entry_type['name']; if ($row->entry_items_dc == "D") { $cur_balance = float_ops($cur_balance, $row->entry_items_amount, '+'); $ledgerst[$counter][5] = convert_dc($row->entry_items_dc); $ledgerst[$counter][6] = $row->entry_items_amount; $ledgerst[$counter][7] = ""; $ledgerst[$counter][8] = ""; } else { $cur_balance = float_ops($cur_balance, $row->entry_items_amount, '-'); $ledgerst[$counter][5] = ""; $ledgerst[$counter][6] = ""; $ledgerst[$counter][7] = convert_dc($row->entry_items_dc); $ledgerst[$counter][8] = $row->entry_items_amount; } if (float_ops($cur_balance, 0, '==')) { $ledgerst[$counter][9] = ""; $ledgerst[$counter][10] = 0; } else { if (float_ops($cur_balance, 0, '<')) { $ledgerst[$counter][9] = "Cr"; $ledgerst[$counter][10] = convert_cur(-$cur_balance); } else { $ledgerst[$counter][9] = "Dr"; $ledgerst[$counter][10] = convert_cur($cur_balance); } } $counter++; } $ledgerst[$counter][0] = "Closing Balance"; $ledgerst[$counter][1] = ""; $ledgerst[$counter][2] = ""; $ledgerst[$counter][3] = ""; $ledgerst[$counter][4] = ""; $ledgerst[$counter][5] = ""; $ledgerst[$counter][6] = ""; $ledgerst[$counter][7] = ""; $ledgerst[$counter][8] = ""; if (float_ops($cur_balance, 0, '<')) { $ledgerst[$counter][9] = "Cr"; $ledgerst[$counter][10] = convert_cur(-$cur_balance); } else { $ledgerst[$counter][9] = "Dr"; $ledgerst[$counter][10] = convert_cur($cur_balance); } $counter++; $ledgerst[$counter] = array("", "", "", "", "", "", "", "", "", "", ""); $counter++; /* Final Opening and Closing Balance */ $clbalance = $this->Ledger_model->get_ledger_balance($ledger_id); $ledgerst[$counter] = array("Opening Balance", convert_dc($optype), $opbalance, "", "", "", "", "", "", "", ""); $counter++; if (float_ops($clbalance, 0, '==')) { $ledgerst[$counter] = array("Closing Balance", "", 0, "", "", "", "", "", "", "", ""); } else { if (float_ops($clbalance, 0, '<')) { $ledgerst[$counter] = array("Closing Balance", "Cr", convert_cur(-$clbalance), "", "", "", "", "", "", "", ""); } else { $ledgerst[$counter] = array("Closing Balance", "Dr", convert_cur($clbalance), "", "", "", "", "", "", "", ""); } } $this->load->helper('csv'); echo array_to_csv($ledgerst, "ledgerst.csv"); return; } /********************** RECONCILIATION ************************/ if ($statement == "reconciliation") { $ledger_id = (int) $this->uri->segment(4); $reconciliation_type = $this->uri->segment(5); if ($ledger_id < 1) { return; } if (!($reconciliation_type == 'all' or $reconciliation_type == 'pending')) { return; } $this->load->model('Ledger_model'); $cur_balance = 0; $counter = 0; $ledgerst = array(); $ledgerst[$counter] = array("", "", "RECONCILIATION STATEMENT FOR " . strtoupper($this->Ledger_model->get_name($ledger_id)), "", "", "", "", "", "", ""); $counter++; $ledgerst[$counter] = array("", "", "FY " . date_mysql_to_php($this->config->item('account_fy_start')) . " - " . date_mysql_to_php($this->config->item('account_fy_end')), "", "", "", "", "", "", ""); $counter++; $ledgerst[$counter][0] = "Date"; $ledgerst[$counter][1] = "Number"; $ledgerst[$counter][2] = "Ledger Name"; $ledgerst[$counter][3] = "Narration"; $ledgerst[$counter][4] = "Type"; $ledgerst[$counter][5] = ""; $ledgerst[$counter][6] = "Dr Amount"; $ledgerst[$counter][7] = ""; $ledgerst[$counter][8] = "Cr Amount"; $ledgerst[$counter][9] = "Reconciliation Date"; $counter++; /* Opening Balance */ list($opbalance, $optype) = $this->Ledger_model->get_op_balance($ledger_id); $this->db->select('entries.id as entries_id, entries.number as entries_number, entries.date as entries_date, entries.narration as entries_narration, entries.entry_type as entries_entry_type, entry_items.amount as entry_items_amount, entry_items.dc as entry_items_dc, entry_items.reconciliation_date as lreconciliation'); if ($reconciliation_type == 'all') { $this->db->from('entries')->join('entry_items', 'entries.id = entry_items.entry_id')->where('entry_items.ledger_id', $ledger_id)->order_by('entries.date', 'asc')->order_by('entries.number', 'asc'); } else { $this->db->from('entries')->join('entry_items', 'entries.id = entry_items.entry_id')->where('entry_items.ledger_id', $ledger_id)->where('entry_items.reconciliation_date', NULL)->order_by('entries.date', 'asc')->order_by('entries.number', 'asc'); } $ledgerst_q = $this->db->get(); foreach ($ledgerst_q->result() as $row) { /* Entry Type */ $current_entry_type = entry_type_info($row->entries_entry_type); $ledgerst[$counter][0] = date_mysql_to_php($row->entries_date); $ledgerst[$counter][1] = full_entry_number($row->entries_entry_type, $row->entries_number); /* Opposite entry name */ $ledgerst[$counter][2] = $this->Ledger_model->get_opp_ledger_name($row->entries_id, $row->entries_entry_type, $row->entry_items_dc, 'text'); $ledgerst[$counter][3] = $row->entries_narration; $ledgerst[$counter][4] = $current_entry_type['name']; if ($row->entry_items_dc == "D") { $ledgerst[$counter][5] = convert_dc($row->entry_items_dc); $ledgerst[$counter][6] = $row->entry_items_amount; $ledgerst[$counter][7] = ""; $ledgerst[$counter][8] = ""; } else { $ledgerst[$counter][5] = ""; $ledgerst[$counter][6] = ""; $ledgerst[$counter][7] = convert_dc($row->entry_items_dc); $ledgerst[$counter][8] = $row->entry_items_amount; } if ($row->lreconciliation) { $ledgerst[$counter][9] = date_mysql_to_php($row->lreconciliation); } else { $ledgerst[$counter][9] = ""; } $counter++; } $counter++; $ledgerst[$counter] = array("", "", "", "", "", "", "", "", "", ""); $counter++; /* Final Opening and Closing Balance */ $clbalance = $this->Ledger_model->get_ledger_balance($ledger_id); $ledgerst[$counter] = array("Opening Balance", convert_dc($optype), $opbalance, "", "", "", "", "", "", ""); $counter++; if (float_ops($clbalance, 0, '==')) { $ledgerst[$counter] = array("Closing Balance", "", 0, "", "", "", "", "", "", ""); } else { if (float_ops($clbalance, 0, '<')) { $ledgerst[$counter] = array("Closing Balance", "Cr", convert_cur(-$clbalance), "", "", "", "", "", "", ""); } else { $ledgerst[$counter] = array("Closing Balance", "Dr", convert_cur($clbalance), "", "", "", "", "", "", ""); } } /************* Final Reconciliation Balance ***********/ /* Reconciliation Balance - Dr */ $this->db->select_sum('amount', 'drtotal')->from('entry_items')->join('entries', 'entries.id = entry_items.entry_id')->where('entry_items.ledger_id', $ledger_id)->where('entry_items.dc', 'D')->where('entry_items.reconciliation_date IS NOT NULL'); $dr_total_q = $this->db->get(); if ($dr_total = $dr_total_q->row()) { $reconciliation_dr_total = $dr_total->drtotal; } else { $reconciliation_dr_total = 0; } /* Reconciliation Balance - Cr */ $this->db->select_sum('amount', 'crtotal')->from('entry_items')->join('entries', 'entries.id = entry_items.entry_id')->where('entry_items.ledger_id', $ledger_id)->where('entry_items.dc', 'C')->where('entry_items.reconciliation_date IS NOT NULL'); $cr_total_q = $this->db->get(); if ($cr_total = $cr_total_q->row()) { $reconciliation_cr_total = $cr_total->crtotal; } else { $reconciliation_cr_total = 0; } $reconciliation_total = float_ops($reconciliation_dr_total, $reconciliation_cr_total, '-'); $reconciliation_pending = float_ops($clbalance, $reconciliation_total, '-'); $counter++; if (float_ops($reconciliation_pending, 0, '==')) { $ledgerst[$counter] = array("Reconciliation Pending", "", 0, "", "", "", "", "", "", ""); } else { if (float_ops($reconciliation_pending, 0, '<')) { $ledgerst[$counter] = array("Reconciliation Pending", "Cr", convert_cur(-$reconciliation_pending), "", "", "", "", "", "", ""); } else { $ledgerst[$counter] = array("Reconciliation Pending", "Dr", convert_cur($reconciliation_pending), "", "", "", "", "", "", ""); } } $counter++; if (float_ops($reconciliation_total, 0, '==')) { $ledgerst[$counter] = array("Reconciliation Total", "", 0, "", "", "", "", "", "", ""); } else { if (float_ops($reconciliation_total, 0, '<')) { $ledgerst[$counter] = array("Reconciliation Total", "Cr", convert_cur(-$reconciliation_total), "", "", "", "", "", "", ""); } else { $ledgerst[$counter] = array("Reconciliation Total", "Dr", convert_cur($reconciliation_total), "", "", "", "", "", "", ""); } } $this->load->helper('csv'); echo array_to_csv($ledgerst, "reconciliation.csv"); return; } /************************ BALANCE SHEET ***********************/ if ($statement == "balancesheet") { $this->load->library('accountlist'); $this->load->model('Ledger_model'); $liability = new Accountlist(); $liability->init(2); $liability_array = $liability->build_array(); $liability_depth = Accountlist::$max_depth; $liability_total = -$liability->total; Accountlist::reset_max_depth(); $asset = new Accountlist(); $asset->init(1); $asset_array = $asset->build_array(); $asset_depth = Accountlist::$max_depth; $asset_total = $asset->total; $liability->to_csv($liability_array); Accountlist::add_blank_csv(); $asset->to_csv($asset_array); $income = new Accountlist(); $income->init(3); $expense = new Accountlist(); $expense->init(4); $income_total = -$income->total; $expense_total = $expense->total; $pandl = float_ops($income_total, $expense_total, '-'); $diffop = $this->Ledger_model->get_diff_op_balance(); Accountlist::add_blank_csv(); /* Liability side */ $total = $liability_total; Accountlist::add_row_csv(array("Liabilities and Owners Equity Total", convert_cur($liability_total))); /* If Profit then Liability side, If Loss then Asset side */ if (float_ops($pandl, 0, '!=')) { if (float_ops($pandl, 0, '>')) { $total = float_ops($total, $pandl, '+'); Accountlist::add_row_csv(array("Profit & Loss account (Net Profit)", convert_cur($pandl))); } } /* If Op balance Dr then Liability side, If Op balance Cr then Asset side */ if (float_ops($diffop, 0, '!=')) { if (float_ops($diffop, 0, '>')) { $total = float_ops($total, $diffop, '+'); Accountlist::add_row_csv(array("Diff in O/P Balance", "Dr " . convert_cur($diffop))); } } Accountlist::add_row_csv(array("Total - Liabilities and Owners Equity", convert_cur($total))); /* Asset side */ $total = $asset_total; Accountlist::add_row_csv(array("Asset Total", convert_cur($asset_total))); /* If Profit then Liability side, If Loss then Asset side */ if (float_ops($pandl, 0, '!=')) { if (float_ops($pandl, 0, '<')) { $total = float_ops($total, -$pandl, '+'); Accountlist::add_row_csv(array("Profit & Loss account (Net Loss)", convert_cur(-$pandl))); } } /* If Op balance Dr then Liability side, If Op balance Cr then Asset side */ if (float_ops($diffop, 0, '!=')) { if (float_ops($diffop, 0, '<')) { $total = float_ops($total, -$diffop, '+'); Accountlist::add_row_csv(array("Diff in O/P Balance", "Cr " . convert_cur(-$diffop))); } } Accountlist::add_row_csv(array("Total - Assets", convert_cur($total))); $balancesheet = Accountlist::get_csv(); $this->load->helper('csv'); echo array_to_csv($balancesheet, "balancesheet.csv"); return; } /********************** PROFIT AND LOSS ***********************/ if ($statement == "profitandloss") { $this->load->library('accountlist'); $this->load->model('Ledger_model'); /***************** GROSS CALCULATION ******************/ /* Gross P/L : Expenses */ $gross_expense_total = 0; $this->db->from('groups')->where('parent_id', 4)->where('affects_gross', 1); $gross_expense_list_q = $this->db->get(); foreach ($gross_expense_list_q->result() as $row) { $gross_expense = new Accountlist(); $gross_expense->init($row->id); $gross_expense_total = float_ops($gross_expense_total, $gross_expense->total, '+'); $gross_exp_array = $gross_expense->build_array(); $gross_expense->to_csv($gross_exp_array); } Accountlist::add_blank_csv(); /* Gross P/L : Incomes */ $gross_income_total = 0; $this->db->from('groups')->where('parent_id', 3)->where('affects_gross', 1); $gross_income_list_q = $this->db->get(); foreach ($gross_income_list_q->result() as $row) { $gross_income = new Accountlist(); $gross_income->init($row->id); $gross_income_total = float_ops($gross_income_total, $gross_income->total, '+'); $gross_inc_array = $gross_income->build_array(); $gross_income->to_csv($gross_inc_array); } Accountlist::add_blank_csv(); Accountlist::add_blank_csv(); /* Converting to positive value since Cr */ $gross_income_total = -$gross_income_total; /* Calculating Gross P/L */ $grosspl = float_ops($gross_income_total, $gross_expense_total, '-'); /* Showing Gross P/L : Expenses */ $grosstotal = $gross_expense_total; Accountlist::add_row_csv(array("Total Gross Expenses", convert_cur($gross_expense_total))); if (float_ops($grosspl, 0, '>')) { $grosstotal = float_ops($grosstotal, $grosspl, '+'); Accountlist::add_row_csv(array("Gross Profit C/O", convert_cur($grosspl))); } Accountlist::add_row_csv(array("Total Expenses - Gross", convert_cur($grosstotal))); /* Showing Gross P/L : Incomes */ $grosstotal = $gross_income_total; Accountlist::add_row_csv(array("Total Gross Incomes", convert_cur($gross_income_total))); if (float_ops($grosspl, 0, '>')) { } else { if (float_ops($grosspl, 0, '<')) { $grosstotal = float_ops($grosstotal, -$grosspl, '+'); Accountlist::add_row_csv(array("Gross Loss C/O", convert_cur(-$grosspl))); } } Accountlist::add_row_csv(array("Total Incomes - Gross", convert_cur($grosstotal))); /************************* NET CALCULATIONS ***************************/ Accountlist::add_blank_csv(); Accountlist::add_blank_csv(); /* Net P/L : Expenses */ $net_expense_total = 0; $this->db->from('groups')->where('parent_id', 4)->where('affects_gross !=', 1); $net_expense_list_q = $this->db->get(); foreach ($net_expense_list_q->result() as $row) { $net_expense = new Accountlist(); $net_expense->init($row->id); $net_expense_total = float_ops($net_expense_total, $net_expense->total, '+'); $net_exp_array = $net_expense->build_array(); $net_expense->to_csv($net_exp_array); } Accountlist::add_blank_csv(); /* Net P/L : Incomes */ $net_income_total = 0; $this->db->from('groups')->where('parent_id', 3)->where('affects_gross !=', 1); $net_income_list_q = $this->db->get(); foreach ($net_income_list_q->result() as $row) { $net_income = new Accountlist(); $net_income->init($row->id); $net_income_total = float_ops($net_income_total, $net_income->total, '+'); $net_inc_array = $net_income->build_array(); $net_income->to_csv($net_inc_array); } Accountlist::add_blank_csv(); Accountlist::add_blank_csv(); /* Converting to positive value since Cr */ $net_income_total = -$net_income_total; /* Calculating Net P/L */ $netpl = float_ops(float_ops($net_income_total, $net_expense_total, '-'), $grosspl, '+'); /* Showing Net P/L : Expenses */ $nettotal = $net_expense_total; Accountlist::add_row_csv(array("Total Expenses", convert_cur($nettotal))); if (float_ops($grosspl, 0, '>')) { } else { if (float_ops($grosspl, 0, '<')) { $nettotal = float_ops($nettotal, -$grosspl, '+'); Accountlist::add_row_csv(array("Gross Loss B/F", convert_cur(-$grosspl))); } } if (float_ops($netpl, 0, '>')) { $nettotal = float_ops($nettotal, $netpl, '+'); Accountlist::add_row_csv(array("Net Profit", convert_cur($netpl))); } Accountlist::add_row_csv(array("Total - Net Expenses", convert_cur($nettotal))); /* Showing Net P/L : Incomes */ $nettotal = $net_income_total; Accountlist::add_row_csv(array("Total Incomes", convert_cur($nettotal))); if (float_ops($grosspl, 0, '>')) { $nettotal = float_ops($nettotal, $grosspl, '+'); Accountlist::add_row_csv(array("Gross Profit B/F", convert_cur($grosspl))); } if (float_ops($netpl, 0, '>')) { } else { if (float_ops($netpl, 0, '<')) { $nettotal = float_ops($nettotal, -$netpl, '+'); Accountlist::add_row_csv(array("Net Loss", convert_cur(-$netpl))); } } Accountlist::add_row_csv(array("Total - Net Incomes", convert_cur($nettotal))); $balancesheet = Accountlist::get_csv(); $this->load->helper('csv'); echo array_to_csv($balancesheet, "profitandloss.csv"); return; } return; }
echo convert_amount_dc($clbal_amount); echo "</td>"; echo "<td>"; $dr_total = $this->Ledger_model->get_dr_total($ledger_id); if ($dr_total) { echo $dr_total; $temp_dr_total += $dr_total; } else { echo "0"; } echo "</td>"; echo "<td>"; $cr_total = $this->Ledger_model->get_cr_total($ledger_id); if ($cr_total) { echo $cr_total; $temp_cr_total += $cr_total; } else { echo "0"; } echo "</td>"; echo "</tr>"; $odd_even = $odd_even == "odd" ? "even" : "odd"; } echo "<tr class=\"tr-total\"><td colspan=3>TOTAL "; if ($temp_dr_total == $temp_cr_total) { echo "<img src=\"" . asset_url() . "images/icons/match.png\">"; } else { echo "<img src=\"" . asset_url() . "images/icons/nomatch.png\">"; } echo "</td><td>Dr " . convert_cur($temp_dr_total) . "</td><td>Cr " . convert_cur($temp_cr_total) . "</td></tr>"; echo "</table>";
<?php /******************************* Inventory Tree ***************************/ echo "<table border=0 cellpadding=5 class=\"simple-table inventory-summary-table\">"; echo "<thead><tr><th>Name</th><th>Type</th><th>C/L Quantity</th><th>C/L Rate</th><th>C/L Value</tr></thead>"; inventorytree::print_report_tree($inventory_tree); echo "<tr class=\"tr-balance\"><td colspan=\"4\">Total</td><td>" . convert_cur(inventorytree::$total_value) . "</td></tr>"; echo "</table>";
<table border=0 cellpadding=5 class="simple-table entry-view-table"> <thead><tr><th>Inventory Item</th><th>Quantity</th><th>Rate</th><th>Total</th></tr></thead> <?php $inventory_total = 0; foreach ($cur_entry_dest_inventory_items->result() as $row) { echo "<tr>"; echo "<td>" . $this->Inventory_Item_model->get_name($row->inventory_item_id) . "</td>"; echo "<td>" . $row->quantity . "</td>"; echo "<td>" . $row->rate_per_unit . "</td>"; echo "<td>" . $row->total . "</td>"; echo "</tr>"; $inventory_total += $row->total; } ?> <tr class="entry-total"><td colspan=3><strong>Total</strong></td><td id="inventory-total"><?php echo convert_cur($inventory_total); ?> </td></tr> </table> <br /> <p>Narration :<br /> <span class="bold"><?php echo $cur_entry->narration; ?> </span> </p> <p> Tag : <?php
} else { $total += -$pandl; echo "<tr valign=\"top\">"; echo "<td class=\"bold\">Profit & Loss Account (Net Loss)</td>"; echo "<td align=\"right\" class=\"bold\">" . convert_cur(-$pandl) . "</td>"; echo "</tr>"; } } /* If Op balance Dr then Liability side, If Op balance Cr then Asset side */ if ($diffop != 0) { if ($diffop > 0) { echo "<tr>"; echo "<td> </td>"; echo "<td> </td>"; echo "</tr>"; } else { $total += -$diffop; echo "<tr valign=\"top\">"; echo "<td class=\"bold\">Diff in O/P Balance</td>"; echo "<td align=\"right\" class=\"bold\">" . convert_cur(-$diffop) . "</td>"; echo "</tr>"; } } echo "<tr valign=\"top\" class=\"tr-balance\">"; echo "<td class=\"bold\">Total</td>"; echo "<td align=\"right\" class=\"bold\">" . convert_cur($total) . "</td>"; echo "</tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; echo "</table>";
function print_report_tree($inventory_tree) { $CI =& get_instance(); self::$counter++; foreach ($inventory_tree as $row) { if ($row['id'] != 0) { echo "<tr class=\"tr-group\">"; echo "<td>" . self::print_spaces(self::$counter) . $row['name'] . "</td>"; echo "<td>Group</td>"; echo "<td></td>"; echo "<td></td>"; echo "<td></td>"; echo "</tr>"; } if ($row['sub_inventory_items']) { self::$counter++; foreach ($row['sub_inventory_items'] as $row_item) { echo "<tr>"; echo "<td>" . self::print_spaces(self::$counter) . anchor('report/inventory_statement/' . $row_item['id'], $row_item['name'], array('title' => 'View Inventory Item Statement', 'class' => 'anchor-link-a')) . "</td>"; echo "<td>Item</td>"; list($closing_quantity, $closing_rate, $closing_value, $status) = $CI->Inventory_item_model->closing_inventory($row_item['id']); if ($status) { echo "<td>" . $closing_quantity . "</td>"; echo "<td>" . convert_cur($closing_rate) . "</td>"; echo "<td>" . convert_cur($closing_value) . "</td>"; self::$total_value += $closing_value; } else { echo "<td>(-ve bal.)</td>"; echo "<td>(Error)</td>"; echo "<td>(Error)</td>"; } echo "</tr>"; } self::$counter--; } if ($row['sub_inventory_groups']) { foreach ($row['sub_inventory_groups'] as $row_item) { self::print_report_tree($row_item); } } } self::$counter--; }
$cur_value += $row->total; echo "<td>" . $row->quantity . "</td>"; echo "<td>" . convert_cur($row->rate_per_unit) . "</td>"; echo "<td>" . convert_cur($row->total) . "</td>"; echo "<td></td><td></td><td></td>"; } else { if ($row->type == 2) { $cur_quantity -= $row->quantity; $cur_rate -= $row->rate_per_unit; $cur_value -= $row->total; echo "<td></td><td></td><td></td>"; echo "<td>" . $row->quantity . "</td>"; echo "<td>" . convert_cur($row->rate_per_unit) . "</td>"; echo "<td>" . convert_cur($row->total) . "</td>"; } } echo "</tr>"; $odd_even = $odd_even == "odd" ? "even" : "odd"; } /* Current Page Closing Balance */ echo "<tr class=\"tr-balance\"><td colspan=7>Closing Inventory</td><td>" . $cur_quantity . "</td><td>" . convert_cur($cur_rate) . "</td><td>" . convert_cur($cur_value) . "</td>"; echo "</table>"; } if (!$print_preview) { ?> <div id="pagination-container"><?php echo $this->pagination->create_links(); ?> </div> <?php }