Exemplo n.º 1
0
 }
 echo "</td>";
 echo "<td>";
 echo $current_entry_type['name'];
 echo "</td>";
 if ($row->entry_items_dc == "D") {
     echo "<td>";
     echo convert_dc($row->entry_items_dc);
     echo " ";
     echo $row->entry_items_amount;
     echo "</td>";
     echo "<td></td>";
 } else {
     echo "<td></td>";
     echo "<td>";
     echo convert_dc($row->entry_items_dc);
     echo " ";
     echo $row->entry_items_amount;
     echo "</td>";
 }
 echo "<td>";
 if (!$print_preview) {
     $reconciliation_date = array('name' => 'reconciliation_date[' . $row->entry_items_id . ']', 'id' => 'reconciliation_date', 'maxlength' => '11', 'size' => '11', 'value' => '');
     if ($row->entry_items_reconciliation_date) {
         $reconciliation_date['value'] = date_mysql_to_php($row->entry_items_reconciliation_date);
     }
     echo form_input_date_restrict($reconciliation_date);
 } else {
     if ($row->entry_items_reconciliation_date) {
         echo date_mysql_to_php($row->entry_items_reconciliation_date);
     } else {
Exemplo n.º 2
0
 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;
 }
Exemplo n.º 3
0
?>
</span>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Entry Date : <span class="bold"><?php 
echo date_mysql_to_php_display($cur_entry->date);
?>
</span>
</p>

<table border=0 cellpadding=5 class="simple-table entry-view-table">
<thead><tr><th>Type</th><th>Ledger Account</th><th>Dr Amount</th><th>Cr Amount</th></tr></thead>
<?php 
$odd_even = "odd";
foreach ($cur_entry_ledgers->result() as $row) {
    echo "<tr class=\"tr-" . $odd_even . "\">";
    echo "<td>" . convert_dc($row->dc) . "</td>";
    echo "<td>" . $this->Ledger_model->get_name($row->ledger_id) . "</td>";
    if ($row->dc == "D") {
        echo "<td>Dr " . $row->amount . "</td>";
        echo "<td></td>";
    } else {
        echo "<td></td>";
        echo "<td>Cr " . $row->amount . "</td>";
    }
    echo "</tr>";
    $odd_even = $odd_even == "odd" ? "even" : "odd";
}
?>
<tr class="entry-total"><td colspan=2><strong>Total</strong></td><td id=dr-total>Dr <?php 
echo $cur_entry->dr_total;
?>