<?php

namespace App\Http\Controllers\Audits;

use App\Http\Controllers\Controller;
use App\Models\AccBillsManager;
use App\Models\BillMasterClient;
use App\Models\BillMasterCompanyPayroll;
use App\Models\BillMasterVendor;
use App\Models\CompanyFinancialMainAccount;
use App\Models\EmployeeAdvanceSalary;
use App\Models\EmployeePayrollDeduction;
use App\Models\EmployeePayrollManager;
use App\Models\ExpenseKitchenConsumable;
use App\Models\ExpenseOfficeStationery;
use App\Models\Payment;
use App\Models\Receipt;
use Illuminate\Http\Request;

class CompanyBalanceSheetController extends Controller
{
    /**Display the Balance Sheet Page**/
    public function showCompanyBalanceSheet(){
        return view('audits.company-balance-sheet');
    }

    /**Function to Load Company Balance Sheet**/
    public function loadCompanyBalanceSheet($asOf = null)
    {
        /**Start by Controlling the BS Period**/
        $st = app('CompanySetup')->version_from . '-01-01 00:00:00';
        $ed = date('Y-m-d') . " 23:59:59";
        if ($asOf != null) {
            $ed = $asOf . " 23:59:59";
        }

        $mainLedgers = CompanyFinancialMainAccount::all();
        /**A Balance Sheet checks as of a particular Date**/

        $table = '<table style="width: 100%; border-collapse: collapse">';
        /**Start your Table Now**/
        $table .= '<tr style="background-color: #4ee8e8; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%">Category</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%">Ledger Number</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%">Ledger Name</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%">Dr</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%">Cr</th>';
        $table .= '</tr>';

        /**Group the BS**/
        $table .= '<tr style="background-color: #e1daa6; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: center" class="error">ASSET LISTING</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        /**Non-Current/ Fixed Asset Listing**/
        $table .= '<tr style="background-color: #9ce18b; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%">Non Current/Fixed Assets</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        /**We will Prepare to Display all Non-Current Assets**/
        $n_cr_ass = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'non_c_asset'){
                /**We will be looping to get the Non-Current Assets Ledgers**/
            }
        }
        /**Display a Summation of the Amounts for Non_current Assets**/
        $table .= '<tr style="border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: right">Totals:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; text-align: right"><u>'.number_format($n_cr_ass,2).'</u></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';


        /**Current Asset Listing**/
        $table .= '<tr style="background-color: #9ce18b; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%">Current Assets</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        /**We will Prepare to Display all Non-Current Assets**/
        $cr_ass = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'c_asset'){
                /**We will be looping to get the Current Assets Ledgers**/
                $current_assets = $mainLedger->ledgerAccounts;
                foreach ($current_assets as $current_asset){
                    /**This affects a DR Ledger only**/
                    $dr_amount = 0;
                    if($mainLedger->category_type == 'CB'){
                        /**Here we are handling Bank Accounts and Cash Accounts**/
                        $paidIn = Receipt::where('acc_id', $current_asset->id)->whereBetween('rct_date',[$st, $ed])->sum('amount');
                        $paidOut = Payment::where('acc_id', $current_asset->id)->whereBetween('pv_date',[$st, $ed])->sum('amount');

                        /**Current Balance is Equal to the Difference between the Two**/
                        $dr_amount = $paidIn - $paidOut;
                    }elseif ($mainLedger->category_type == 'PC'){
                        /**Here we are handling Petty Cash Accounts**/
                        $paidIn = Payment::where('ledger_id', $current_asset->id)->whereBetween('pv_date',[$st, $ed])->sum('amount');
                        $paidOut = Payment::where('acc_id', $current_asset->id)->whereBetween('pv_date',[$st, $ed])->sum('amount');

                        /**Current Balance is Equal to the Difference between the Two**/
                        $dr_amount = $paidIn - $paidOut;
                    }else{
                        /**We are handling Normal Current Asset Accounts, Some of them are mappable**/
                        if($current_asset->mapped == 1){
                            /**Here we are handling mapped Ledgers:- Some Ledgers that are mapped are always DR Current Assets**/
                            //1. TDebtors
                            if($current_asset->mapped_id == 'Tdebtors'){
                                /**Here we just pull the Data from Bill Master - Clients Table**/
                                $dr_amount = BillMasterClient::whereBetween('date',[$st, $ed])->sum('amount');
                            }elseif ($current_asset->mapped_id == 'staffAccount'){
                                /**Here we just pull the Data from Staff Current Accounts**/
                                /**All Employee Advances form part of the Staff Current Accounts**/
                                $givenAdvances = EmployeeAdvanceSalary::whereBetween('date_disbursed',[$st, $ed])->sum('amount');
                                $repaidAdvances = EmployeeAdvanceSalary::whereBetween('date_disbursed',[$st, $ed])->sum('paid_amount');
                                $dr_amount = $givenAdvances - $repaidAdvances;
                            }
                        }
                    }
                    /**Only Display Ledgers that are not having 0 amounts**/
                    if($dr_amount != 0){
                        /**Sum Up the Current Asset Amounts**/
                        $cr_ass += $dr_amount;
                        $tbFunction = $current_asset->id.",".strtotime($st).",".strtotime($ed);
                        $table .= '<tr style="border: 1px solid #7c7b7b">';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: center"></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b">'.strtoupper($current_asset->acc_no).'</th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"><b class="error" style="cursor: pointer" onclick="viewLedgerReport('.$tbFunction.')">'.strtoupper($current_asset->acc_name).'</b></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: right">'.number_format($dr_amount,2).'</th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"></th>';
                        $table .= '</tr>';
                    }
                }

            }
        }
        /**Display a Summation of the Amounts for Current Assets**/
        $table .= '<tr style="border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: right">Totals:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; text-align: right"><u>'.number_format($cr_ass,2).'</u></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        /**We now Sum up the Asset Amounts**/
        $table .= '<tr style="background-color: #fffd64; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: right; font-size: 16px">Total Assets Amount:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; text-align: center; font-size: 14px"><u>'.number_format($cr_ass + $n_cr_ass,2).'</u></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';


        /**We Prepare to Display All Liabilities and Capital Ledgers**/
        /**Group the BS**/
        $table .= '<tr style="background-color: #e1daa6; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: center" class="error">CAPITAL AND LIABILITIES</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        /**Display the Non-Current Liabilities**/
        $table .= '<tr style="background-color: #9ce18b; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%">Non Current Liabilities</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        $n_cr_lb = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'non_c_liability'){
                /**We will be looping to get the Non-Current Liability Ledgers**/
            }
        }
        /**Display a Summation of the Amounts for Non-current Liabilities**/
        $table .= '<tr style="border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: right">Totals:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; text-align: right"><u>'.number_format($n_cr_lb,2).'</u></th>';
        $table .= '</tr>';

        /**Display the Current Liabilities**/
        $table .= '<tr style="background-color: #9ce18b; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%">Current Liabilities</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '</tr>';

        $cr_lb = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'c_liability'){
                /**We will be looping to get the Current Liability Ledgers**/
                /**In most cases, Non Current Liability accounts are always mapped**/
                //1. Trade Creditors Ledger
                $current_liabilities = $mainLedger->ledgerAccounts;
                foreach ($current_liabilities as $current_liability){
                    $cr_amount = 0;
                    if($current_liability->mapped == 1){
                        if ($current_liability->mapped_id == 'SundryCreditors'){
                            //2. SundryCreditors
                            /**Here we pull all unpaid Bills that are connected to the Sundry Creditors Main Ledger Account: Bill Master - Vendors**/
                            $cr_amount = BillMasterVendor::whereBetween('date',[$st, $ed])->sum('amount');
                        }elseif ($current_liability->mapped_id == 'SalaryControl'){
                            //3. Salary Control Liability
                            /**Here we pull all unpaid Salaries that are connected to the Salary Control Main Ledger Account: Bill Master - Company Payroll**/
                            $cr_amount = BillMasterCompanyPayroll::whereBetween('date',[$st, $ed])->sum('amount');
                            //dd($cr_amount);
                        }
                    }else{
                        /**We will Display Non Mapped Current Liability Accounts**/

                    }
                    /**Only Display Ledgers that are not having 0 amounts**/
                    if($cr_amount != 0){
                        /**We sum up the Current Liabilities to get the total Liability Amount**/
                        $cr_lb += $cr_amount;

                        $tbFunction = $current_liability->id.",".strtotime($st).",".strtotime($ed);
                        $table .= '<tr style="border: 1px solid #7c7b7b">';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: center"></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b">'.strtoupper($current_liability->acc_no).'</th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"><b class="error" style="cursor: pointer" onclick="viewLedgerReport('.$tbFunction.')">'.strtoupper($current_liability->acc_name).'</b></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: right"></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: right">'.number_format($cr_amount,2).'</th>';
                        $table .= '</tr>';
                    }
                }
            }
        }
        /**Display a Summation of the Amounts for Current Liabilities**/
        $table .= '<tr style="border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: right">Totals:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; text-align: right"><u>'.number_format($cr_lb,2).'</u></th>';
        $table .= '</tr>';


        /**Get a List of All your Expenses Ledgers**/
        $exp = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'expense'){
                /**We will be looping to get the Expenses Ledgers**/
                $expenses = $mainLedger->ledgerAccounts;
                foreach ($expenses as $expense){
                    $exp_amount = 0;
                    if($expense->mapped == 1){
                        /**Some Expense Ledgers are Mapped**/
                        //1. P.A.Y.E
                        if($expense->mapped_id == 'PAYE'){
                            /**We Just Sum PAYE amounts from the EmployeePayrollManager Table**/
                            $exp_amount = EmployeePayrollManager::where('approved', 1)->whereBetween('approved_at',[$st, $ed])->sum('paye');
                        }elseif ($expense->mapped_id == 'SalaryExpense'){
                            /**We Just Sum net_salary amounts from the EmployeePayrollManager Table**/
                            $exp_amount = EmployeePayrollManager::where('approved', 1)->whereBetween('approved_at',[$st, $ed])->sum('net_salary');
                        }elseif ($expense->mapped_id == 'AgentCommExpense'){
                            /**This is mapped to Paid Agent's Commissions**/
                            //$exp_amount = 0;
                        }elseif ($expense->mapped_id == 'OfficeStationary'){
                            /**This is mapped to Office Stationery**/
                            $exp_amount = ExpenseOfficeStationery::where('status', 'paid')->whereBetween('created_at',[$st, $ed])->sum('total_price');
                        }elseif ($expense->mapped_id == 'OfficeConsumables'){
                            /**This is mapped to Office Consumables**/
                            $exp_amount = ExpenseKitchenConsumable::where('status', 'paid')->whereBetween('created_at',[$st, $ed])->sum('total_price');
                        }
                    }else{
                        /**We look into Bill-Manager Ledger for all Bills Created on that Ledger**/
                        $exp_on_bills = AccBillsManager::where('ledger_id', $expense->id)->whereBetween('date',[$st, $ed])->sum('amount');
                        /**Some Ledgers are Expenditure Ledgers and are controlled by Salary Accounts**/
                        $exp_on_employee_deduction = 0;

                        if($expense->deductionType != null){
                            /**We assume that the Deduction Ledger/Type Exists and is mapped on to this Ledger**/
                            $exp_on_employee_deduction = EmployeePayrollDeduction::where('deduction_id', $expense->deductionType->id)->whereBetween('created_at',[$st, $ed])->sum('deduction_amount');
                        }

                        $exp_amount = $exp_on_bills + $exp_on_employee_deduction;
                    }
                    /**Only Display Ledgers that are not having 0 amounts**/
                    if($exp_amount != 0){
                        /**We get Total Expenditure Figure**/
                        $exp += $exp_amount;
                    }
                }
            }
        }

        /**Get a List of All your Income Ledgers**/
        $cr_income = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'income'){
                /**We will be looping to get the Expenses Ledgers**/
                $incomes = $mainLedger->ledgerAccounts;
                foreach ($incomes as $income){
                    $income_amount = 0;
                    if($income->mapped == 1){

                    }else{
                        /**Here we will Display unmapped Income Ledgers**/
                    }
                    /**Only Display Ledgers that are not having 0 amounts**/
                    if($income_amount != 0){
                        /**We get Total Income Figure**/
                        $cr_income += $income_amount;
                    }
                }
            }
        }
        $retained_earnings = $cr_income - $exp;

        /**Get a List of All your Equity Ledgers**/
        $table .= '<tr style="background-color: #9ce18b; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b">Equity</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"></th>';
        $table .= '</tr>';
        $cr_equty = 0;
        foreach ($mainLedgers as $mainLedger){
            if($mainLedger->category == 'equity'){
                /**We will be looping to get the Equity Ledgers**/
                $equities = $mainLedger->ledgerAccounts;
                foreach ($equities as $equity){
                    $equity_amount = 0;
                    if($equity->mapped == 1){
                        /**Here we will be checking for any Mapped Equity Ledgers**/
                        /**A Good Example is the Retained Earnings**/
                        if($equity->mapped_id == 'retainedEarnings'){
                            $equity_amount = $retained_earnings;
                        }
                    }else{
                        /**Here we will Display unmapped Equity Ledgers**/
                    }
                    /**Only Display Ledgers that are not having 0 amounts**/
                    if($equity_amount != 0){
                        /**Sum up all Equity Amounts**/
                        $cr_equty += $equity_amount;

                        $tbFunction = $equity->id.",".strtotime($st).",".strtotime($ed);
                        $table .= '<tr style="border: 1px solid #7c7b7b">';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: center"></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b">'.strtoupper($equity->acc_no).'</th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b"><b class="error" style="cursor: pointer" onclick="viewLedgerReport('.$tbFunction.')">'.strtoupper($equity->acc_name).'</b></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: right"></th>';
                        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; text-align: right">'.number_format($equity_amount,2).'</th>';
                        $table .= '</tr>';
                    }
                }
            }
        }

        /**We now Sum up the Asset Amounts**/
        $table .= '<tr style="background-color: #fffd64; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%; text-align: right; font-size: 16px">Total Capital and Liabilities Amount:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; text-align: center; font-size: 14px"><u>'.number_format($cr_lb + $n_cr_lb + $cr_equty,2).'</u></th>';
        $table .= '</tr>';


        /**End your Table Now**/
        $ttl_dr =  $n_cr_ass + $cr_ass;
        $ttl_cr = $cr_lb + $n_cr_lb + $cr_equty;
        $table .= '<tr style="background-color: #c7d0d0; border: 1px solid #7c7b7b">';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 20%; font-size: 16px">Balance Sheet Figures:</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 15%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 45%"></th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; font-size: 14px; text-align: center" class="error">'.number_format($ttl_dr,2).'</th>';
        $table .= '<th style="padding: 5px; border-right: 1px solid #7c7b7b; width: 10%; font-size: 14px; text-align: center" class="error">'.number_format($ttl_cr,2).'</th>';
        $table .= '</tr>';

        $table .= '</table>';

        return $table;
    }
}
