Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class SummaryClass
- {
- private $con;
- private $dbHost = DB_HOST;
- private $dbUser = DB_USER;
- private $dbPassword = DB_PASS;
- private $dbName = DB_NAME;
- public function __construct()
- {
- $this->con = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPassword, $this->dbName)
- or die(mysqli_connect_error());
- }
- /*------------------------------------------------------------------
- [Select currency symbol]
- -------------------------------------------------------------------*/
- public function toCurrency()
- {
- if (strpos($_SESSION['currency'], "dollar") == true)
- return " dollar";
- else if (strpos($_SESSION['currency'], "euro") == true)
- return " euro";
- else if (strpos($_SESSION['currency'], "lira") == true)
- return " lira";
- else if (strpos($_SESSION['currency'], "pound") == true)
- return " pound";
- else if (strpos($_SESSION['currency'], "ruble") == true)
- return " ruble";
- else if (strpos($_SESSION['currency'], "rupee") == true)
- return " rupee";
- else if (strpos($_SESSION['currency'], "won") == true)
- return " won";
- else
- return " yen";
- }
- /*------------------------------------------------------------------
- [Convert number to money format with error check]
- -------------------------------------------------------------------*/
- public function toMoney($val, $r = 2)
- {
- $symbol = $_SESSION['currency'];
- $n = $val;
- $c = is_float($n) ? 1 : number_format($n, $r);
- $d = '.';
- $t = ',';
- $sign = ($n < 0) ? '-' : '';
- $i = $n = number_format(abs($n), $r);
- $j = (($j = $i . length) > 3) ? $j % 3 : 0;
- $Mon = $sign . ($j ? substr($i, 0, $j) + $t : '') . preg_replace('/(\d{3})(?=\d)/', "$1" + $t, substr($i, $j));
- if ($Mon < 0)
- return "<div class='balance-error'>" . $Mon . " " . $symbol . "</div>";
- else
- return $Mon . " " . $symbol;
- }
- /*------------------------------------------------------------------
- [Convert number to words]
- -------------------------------------------------------------------*/
- function indo_number($number) {
- return 'Rp ' . number_format($number, 0, ',', '.');
- }
- public function convert_number_to_words($number)
- {
- $hyphen = '-';
- $conjunction = ' and ';
- $separator = ', ';
- $negative = 'negative ';
- $decimal = ' point ';
- $dictionary = array(
- 0 => 'zero',
- 1 => 'one',
- 2 => 'two',
- 3 => 'three',
- 4 => 'four',
- 5 => 'five',
- 6 => 'six',
- 7 => 'seven',
- 8 => 'eight',
- 9 => 'nine',
- 10 => 'ten',
- 11 => 'eleven',
- 12 => 'twelve',
- 13 => 'thirteen',
- 14 => 'fourteen',
- 15 => 'fifteen',
- 16 => 'sixteen',
- 17 => 'seventeen',
- 18 => 'eighteen',
- 19 => 'nineteen',
- 20 => 'twenty',
- 30 => 'thirty',
- 40 => 'fourty',
- 50 => 'fifty',
- 60 => 'sixty',
- 70 => 'seventy',
- 80 => 'eighty',
- 90 => 'ninety',
- 100 => 'hundred',
- 1000 => 'thousand',
- 1000000 => 'million',
- 1000000000 => 'billion',
- 1000000000000 => 'trillion',
- 1000000000000000 => 'quadrillion',
- 1000000000000000000 => 'quintillion'
- );
- if (!is_numeric($number)) {
- return false;
- }
- if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
- trigger_error('convert_number_to_words only accepts numbers between -' . PHP_INT_MAX
- . ' and ' . PHP_INT_MAX, E_USER_WARNING);
- return false;
- }
- if ($number < 0) {
- return $negative . $this->convert_number_to_words(abs($number));
- }
- $string = $fraction = null;
- if (strpos($number, '.') !== false) {
- list($number, $fraction) = explode('.', $number);
- }
- switch (true) {
- case $number < 21:
- $string = $dictionary[$number];
- break;
- case $number < 100:
- $tens = ((int) ($number / 10)) * 10;
- $units = $number % 10;
- $string = $dictionary[$tens];
- if ($units) {
- $string .= $hyphen . $dictionary[$units];
- }
- break;
- case $number < 1000:
- $hundreds = $number / 100;
- $remainder = $number % 100;
- $string = $dictionary[$hundreds] . ' ' . $dictionary[100];
- if ($remainder) {
- $string .= $conjunction . $this->convert_number_to_words($remainder);
- }
- break;
- default:
- $baseUnit = pow(1000, floor(log($number, 1000)));
- $numBaseUnits = (int) ($number / $baseUnit);
- $remainder = $number % $baseUnit;
- $string = $this->convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
- if ($remainder) {
- $string .= $remainder < 100 ? $conjunction : $separator;
- $string .= $this->convert_number_to_words($remainder);
- }
- break;
- }
- if (null !== $fraction && is_numeric($fraction)) {
- $string .= $decimal;
- $words = array();
- foreach (str_split((string) $fraction) as $number) {
- $words[] = $dictionary[$number];
- }
- $string .= implode(' ', $words);
- }
- return $string;
- }
- /*------------------------------------------------------------------
- [Create Income Statement summary]
- -------------------------------------------------------------------*/
- public function createIncomeSummary($GrossRev, $TotalExpenses, $Ebitda, $OtherExpenses, $NetIncome)
- {
- $string = "";
- $string = "Total revenue earned for the period is " . $this->convert_number_to_words($GrossRev)
- . $this->toCurrency() . ".";
- $string .= " Total direct expense was " . $this->convert_number_to_words($TotalExpenses * -1) . $this->toCurrency()
- . ", total indirect expense was " . $this->convert_number_to_words($OtherExpenses * -1) . $this->toCurrency()
- . " resulting in net income of " . $this->convert_number_to_words($NetIncome) . $this->toCurrency();
- $string .= " and EBITDA was " . $this->convert_number_to_words($Ebitda) . $this->toCurrency() . ".";
- return $string;
- }
- /*------------------------------------------------------------------
- [Create Owners Equity Summary]
- -------------------------------------------------------------------*/
- public function createOwnersEquitySummary($Beginning, $Capital, $Drawing, $Income, $Equity)
- {
- $string = "";
- $string = "Total equity at the beginning of the period is " . $this->convert_number_to_words($Beginning)
- . $this->toCurrency() . ".";
- $string .= " Total capital invested was " . $this->convert_number_to_words($Capital) . $this->toCurrency()
- . ", total drawing was " . $this->convert_number_to_words($Drawing * -1) . $this->toCurrency()
- . ", with net income of " . $this->convert_number_to_words($Income) . $this->toCurrency()
- . " resulting in ending equity of " . $this->convert_number_to_words($Equity) . $this->toCurrency() . ".";
- return $string;
- }
- /*------------------------------------------------------------------
- [Create Balance Sheet summary]
- -------------------------------------------------------------------*/
- public function createBalanceSheetSummary($Cash, $Asset, $Liability, $Equity)
- {
- $string = "";
- $string = "Total asset at the end of the period is " . $this->convert_number_to_words($Asset) . $this->toCurrency()
- . " including total cash " . $this->convert_number_to_words($Cash) . $this->toCurrency() . ".";
- $string .= " Total liability at the end of the period is " . $this->convert_number_to_words($Liability)
- . $this->toCurrency() . " and total equity " . $this->convert_number_to_words($Equity) . $this->toCurrency() . ".";
- return $string;
- }
- /*------------------------------------------------------------------
- [Create Cash Flow summary]
- -------------------------------------------------------------------*/
- public function createCashFlowSummary($CashOp, $CashInv, $CashFin, $CashBeginning, $CashEnding)
- {
- $string = "";
- $string = "Total cash at the beginning of the period is " . $this->convert_number_to_words($CashBeginning)
- . $this->toCurrency() . ".";
- $string .= " Cash flow for operating activites is " . $this->convert_number_to_words($CashOp) . $this->toCurrency()
- . ", investing activities is " . $this->convert_number_to_words($CashInv) . $this->toCurrency()
- . ", and financing activities is " . $this->convert_number_to_words($CashFin) . $this->toCurrency() . ".";
- $string .= " Total ending cash is " . $this->convert_number_to_words($CashEnding) . $this->toCurrency() . ".";
- return $string;
- }
- /*------------------------------------------------------------------
- [Waterfall graph for Income Statement]
- -------------------------------------------------------------------*/
- public function incomeWaterFall($graphGrossRev, $graphTotalExpenses, $graphEbitda, $graphOtherExpenses,
- $graphNetIncome)
- {
- $tooltipEbitda = ($graphEbitda < "0" ? "EBITDA (Loss)" : "EBITDA");
- $tooltipIncome = ($graphNetIncome < "0" ? "Net Loss" : "Net Profit");
- if ($graphNetIncome < 0)
- $barHeight = $graphGrossRev + abs($graphNetIncome);
- else
- $barHeight = $graphGrossRev;
- if ($graphNetIncome < 0)
- $revenueBottom = number_format(100 - ($graphGrossRev / $barHeight) * 100) . "%";
- else
- $revenueBottom = "0%";
- $revenueHeight = number_format(($graphGrossRev / $barHeight) * 100) . "%";
- $directExpenseBottom = number_format(100 - abs($graphTotalExpenses / $barHeight) * 100) . "%";
- $ebitdaBottom = min(str_replace("%", "", $revenueBottom), str_replace("%", "", $directExpenseBottom)) . "%";
- $ebitdaHeight = number_format(abs($graphEbitda / $barHeight) * 100) . "%";
- $indirectExpenseHeight = number_format(abs($graphOtherExpenses / $barHeight) * 100) . "%";
- $indirectExpenseBottom = (str_replace("%", "", $ebitdaBottom) + str_replace("%", "", $ebitdaHeight)
- - str_replace("%", "", $indirectExpenseHeight)) . "%";
- if ($graphEbitda < 0)
- $indirectExpenseBottom = (str_replace("%", "", $indirectExpenseBottom) - str_replace("%", "", $ebitdaHeight)) . "%";
- $incomeHeight = number_format(abs($graphNetIncome / $barHeight) * 100) . "%";
- echo <<<EOT
- <div class="bars income-width blue-last tooltip-bottom" title="Gross Revenue"
- style="bottom:$revenueBottom;left:12.5%;" data-percent="$revenueHeight"></div>
- <div class="bars income-width red-last tooltip-bottom" title="Direct Expenses"
- style="bottom:$directExpenseBottom;left:25%;" data-percent="100%"></div>
- <div class="bars income-width purple-last tooltip-bottom" title="$tooltipEbitda"
- style="bottom:$ebitdaBottom;left:37.5%;" data-percent="$ebitdaHeight"></div>
- <div class="bars income-width orange-last tooltip-bottom" title="Indirect Expenses"
- style="bottom:$indirectExpenseBottom;left:50%;" data-percent="$indirectExpenseHeight"></div>
- <div class="bars income-width brown-last tooltip-bottom" title="$tooltipIncome"
- style="bottom:0%;left:62.5%;" data-percent="$incomeHeight"></div>
- EOT;
- }
- /*------------------------------------------------------------------
- [Waterfall graph for Owners Equity Statement]
- -------------------------------------------------------------------*/
- public function equityWaterFall($graphBeginning, $graphCapital, $graphDrawing, $graphIncome, $graphEquity)
- {
- $tooltipIncome = ($graphIncome < "0" ? "Net Loss" : "Net Profit");
- $barHeight = max($graphBeginning, $graphBeginning + $graphCapital, $graphBeginning + $graphCapital
- + $graphDrawing, $graphBeginning + $graphCapital + $graphDrawing + $graphIncome);
- $beginningHeight = number_format(($graphBeginning / $barHeight) * 100) . "%";
- $capitalBottom = $beginningHeight;
- $capitalHeight = number_format(($graphCapital / $barHeight) * 100) . "%";
- $drawingHeight = number_format((abs($graphDrawing) / $barHeight) * 100) . "%";
- $drawingBottom = (str_replace("%", "", $capitalBottom) + str_replace("%", "", $capitalHeight)
- - str_replace("%", "", $drawingHeight)) . "%";
- $incomeHeight = number_format((abs($graphIncome) / $barHeight) * 100) . "%";
- if ($graphIncome < 0)
- $incomeBottom = (str_replace("%", "", $drawingBottom) - str_replace("%", "", $incomeHeight)) . "%";
- else
- $incomeBottom = $drawingBottom;
- $equityHeight = number_format((abs($graphEquity) / $barHeight) * 100) . "%";
- echo <<<EOT
- <div class="bars income-width purple-last tooltip-bottom" title="Beginning Equity"
- style="bottom:0%;left:12.5%;" data-percent="$beginningHeight"></div>
- <div class="bars income-width blue-last tooltip-bottom" title="Investment"
- style="bottom:$capitalBottom;left:25%;" data-percent="$capitalHeight"></div>
- <div class="bars income-width red-last tooltip-bottom" title="Drawing"
- style="bottom:$drawingBottom;left:37.5%;" data-percent="$drawingHeight"></div>
- <div class="bars income-width orange-last tooltip-bottom" title="$tooltipIncome"
- style="bottom:$incomeBottom;left:50%;" data-percent="$incomeHeight"></div>
- <div class="bars income-width brown-last tooltip-bottom" title="Closing Equity"
- style="bottom:0;left:62.5%;" data-percent="$equityHeight"></div>
- EOT;
- }
- /*------------------------------------------------------------------
- [Waterfall graph for Balance Sheet]
- -------------------------------------------------------------------*/
- public function balanceWaterFall($graphCurrentAsset, $graphNonCurrentAsset, $graphCurrentLiability,
- $graphNonCurrentLiability, $graphEquity)
- {
- $barHeight = max($graphCurrentAsset + $graphNonCurrentAsset, $graphCurrentLiability
- + $graphNonCurrentLiability + $graphEquity);
- $currentAssetBottom = "0%";
- $currentAssetHeight = number_format(($graphCurrentAsset / $barHeight) * 100) . "%";
- $nonCurrentAssetBottom = str_replace("%", "", $currentAssetHeight) . "%";
- $nonCurrentAssetHeight = ($graphNonCurrentAsset != 0 ? "100%" : "0%");
- $currentLiabilityBottom = "0%";
- $currentLiabilityHeight = number_format(($graphCurrentLiability / $barHeight) * 100) . "%";
- $nonCurrentLiabilityBottom = str_replace("%", "", $currentLiabilityHeight) . "%";
- $nonCurrentLiabilityHeight = number_format(($graphNonCurrentLiability / $barHeight) * 100) . "%";
- $equityBottom = (str_replace("%", "", $nonCurrentLiabilityHeight)
- + str_replace("%", "", $currentLiabilityHeight)) . "%";
- $equityHeight = ($graphEquity != 0 ? "100%" : "0%");
- echo <<<EOT
- <div class="bars income-width blue-last tooltip-bottom" title="Current Asset"
- style="bottom:$currentAssetBottom;left:12.5%;" data-percent="$currentAssetHeight"></div>
- <div class="bars income-width red-last tooltip-bottom" title="Non-current Asset"
- style="bottom:$nonCurrentAssetBottom;left:25%;" data-percent="$nonCurrentAssetHeight"></div>
- <div class="bars income-width purple-last tooltip-bottom" title="Current Liability"
- style="bottom:$currentLiabilityBottom;left:37.5%;" data-percent="$currentLiabilityHeight"></div>
- <div class="bars income-width orange-last tooltip-bottom" title="Non-current Liability"
- style="bottom:$nonCurrentLiabilityBottom;left:50%;" data-percent="$nonCurrentLiabilityHeight"></div>
- <div class="bars income-width brown-last tooltip-bottom" title="Total Equity"
- style="bottom:$equityBottom;left:62.5%;" data-percent="$equityHeight"></div>
- EOT;
- }
- /*------------------------------------------------------------------
- [Waterfall graph for Cash Flow Statement]
- -------------------------------------------------------------------*/
- public function cashWaterFall($graphCash, $graphCashBeginning, $graphCashEnding)
- {
- $tooltipCash = ($graphCash < "0" ? "Less: Cash Outflow" : "Add: Cash Inflow");
- $barHeight = max($graphCashBeginning, $graphCashBeginning + $graphCash);
- $graphCashBeginningBottom = "0%";
- $graphCashBeginningHeight = number_format(($graphCashBeginning / $barHeight) * 100) . "%";
- $graphCashHeight = number_format(abs($graphCash / $barHeight) * 100) . "%";
- if ($graphCash < 0)
- $graphCashBottom = (str_replace("%", "", $graphCashBeginningHeight)
- - str_replace("%", "", $graphCashHeight)) . "%";
- else
- $graphCashBottom = $graphCashBeginningHeight;
- $graphCashEndingBottom = "0%";
- $graphCashEndingHeight = number_format(($graphCashEnding / $barHeight) * 100) . "%";
- echo <<<EOT
- <div class="bars income-width blue-last tooltip-bottom" title="Cash: Beginning Period"
- style="bottom:$graphCashBeginningBottom;left:12.5%;" data-percent="$graphCashBeginningHeight"></div>
- <div class="bars income-width purple-last tooltip-bottom" title="$tooltipCash"
- style="bottom:$graphCashBottom;left:37.5%;" data-percent="$graphCashHeight"></div>
- <div class="bars income-width brown-last tooltip-bottom" title="Cash: Ending Period"
- style="bottom:$graphCashEndingBottom;left:62.5%;" data-percent="$graphCashEndingHeight"></div>
- EOT;
- }
- /*------------------------------------------------------------------
- [Preview balance sheet and create excel export]
- -------------------------------------------------------------------*/
- public function previewBalanceSheet($Income, $ClosingEquity, $objExcelBalance)
- {
- $Token = strtotime("now");
- $Month = $_SESSION['month'];
- $Year = $_SESSION['year'];
- $CheckError = "Correct";
- $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $Cash = round($row['cash'] + $row['procash'], 2);
- $AccReceivable = $row['accrecser'];
- $PreInsurance = $row['preins'];
- $PreRent = $row['preren'];
- $PreSupplies = $row['presup'];
- $Supplies = $row['supplies'];
- $Building = $row['building'];
- $Equipment = $row['equipment'];
- $DepBuilding = $row['depbui'];
- $DepEquipment = $row['depequ'];
- $DepSupplies = $row['depsup'];
- $Asset = round($Cash + $AccReceivable + $PreInsurance + $PreRent + $PreSupplies + $Supplies + $Equipment
- + $Building - $DepBuilding - $DepEquipment - $DepSupplies, 2);
- $CashReturn = $Cash;
- $AssetReturn = $Asset;
- $graphCurrentAsset = round($row["cash"] + $row["procash"] + $row["accrecser"] + $row["preins"]
- + $row["preren"] + $row["presup"], 2);
- $graphNonCurrentAsset = round($row["supplies"] + $row["equipment"] + $row["building"] - $row["depbui"]
- - $row["depsup"] - $row["depequ"], 2);
- if ($Cash < 0 || $AccReceivable < 0 || $PreInsurance < 0 || $PreRent < 0 || $PreSupplies < 0
- || $Supplies < 0 || $Equipment < 0 || $Building < 0 || $DepBuilding < 0 || $DepEquipment < 0
- || $DepSupplies < 0)
- $CheckError = "Error";
- $objExcelBalance->getDefaultStyle()->getFont()->setName('Segoe UI');
- $objExcelBalance->getDefaultStyle()->getFont()->setSize(11);
- $objWriter = PHPExcel_IOFactory::createWriter($objExcelBalance, "Excel2007");
- $objSheet = $objExcelBalance->getActiveSheet();
- $objSheet->setTitle('Balance Sheet');
- $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
- $objSheet->getColumnDimension('A')->setWidth(50);
- $objSheet->getColumnDimension('B')->setWidth(50);
- $objSheet->getStyle('B2:B34')->getNumberFormat()->setFormatCode('#,##0.00');
- $objSheet->mergeCells('A1:B1');
- $objSheet->getCell('A1')->setValue('Statement of Financial Position');
- $objSheet->mergeCells('A2:B2');
- $objSheet->getCell('A2')->setValue('For the month ending ' . $Month . '\'' . $Year);
- $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A3')->setValue('Account');
- $objSheet->getCell('B3')->setValue('Amount');
- $objSheet->getCell('A4')->setValue('Cash');
- $objSheet->getCell('B4')->setValue($Cash);
- $objSheet->getCell('A5')->setValue('Account Reveivable');
- $objSheet->getCell('B5')->setValue($AccReceivable);
- $objSheet->getCell('A6')->setValue('Prepaid Insurance');
- $objSheet->getCell('B6')->setValue($PreInsurance);
- $objSheet->getCell('A7')->setValue('Prepaid Rent');
- $objSheet->getCell('B7')->setValue($PreRent);
- $objSheet->getCell('A8')->setValue('Prepaid Supplies');
- $objSheet->getCell('B8')->setValue($PreSupplies);
- $objSheet->getCell('A9')->setValue('Supplies');
- $objSheet->getCell('B9')->setValue($Supplies);
- $objSheet->getCell('A10')->setValue('Equipment');
- $objSheet->getCell('B10')->setValue($Equipment);
- $objSheet->getCell('A11')->setValue('Building');
- $objSheet->getCell('B11')->setValue($Building);
- $objSheet->getCell('A12')->setValue('Acc. depriciation building');
- $objSheet->getCell('B12')->setValue($DepBuilding * -1);
- $objSheet->getCell('A13')->setValue('Acc. depriciation equipment');
- $objSheet->getCell('B13')->setValue($DepEquipment * -1);
- $objSheet->getCell('A14')->setValue('Acc. depriciation supplies');
- $objSheet->getCell('B14')->setValue($DepSupplies * -1);
- $objSheet->getCell('A15')->setValue('Total Asset');
- $objSheet->getCell('B15')->setValue('=SUM(B4:B14)');
- $objSheet->getStyle('A15:B15')->getFont()->setBold(true)->setSize(11);
- $Cash = $this->toMoney($Cash);
- $AccReceivable = $this->toMoney($AccReceivable);
- $PreInsurance = $this->toMoney($PreInsurance);
- $PreRent = $this->toMoney($PreRent);
- $PreSupplies = $this->toMoney($PreSupplies);
- $Supplies = $this->toMoney($Supplies);
- $Equipment = $this->toMoney($Equipment);
- $Building = $this->toMoney($Building);
- $DepBuilding = $this->toMoney($DepBuilding);
- $DepEquipment = $this->toMoney($DepEquipment);
- $DepSupplies = $this->toMoney($DepSupplies);
- $Asset = $this->toMoney($Asset);
- echo <<<EOT
- <div class="ui card width-full">
- <div class="content">
- <div class="header"><i class="cubes icon"></i>Statement of Financial Position</div>
- <div class="meta">For the month ending $Month'$Year</div>
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Asset</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Cash:</td><td>Rp. $Cash</td></tr>
- <tr><td>Account Reveivable:</td><td>Rp. $AccReceivable</td></tr>
- <tr><td>Prepaid Insurance:</td><td>Rp. $PreInsurance</td></tr>
- <tr><td>Prepaid Rent:</td><td>Rp. $PreRent</td></tr>
- <tr><td>Prepaid Supplies:</td><td>Rp. $PreSupplies</td></tr>
- <tr><td>Supplies:</td><td>Rp. $Supplies</td></tr>
- <tr><td>Equipments:</td><td>Rp. $Equipment</td></tr>
- <tr><td>Building:</td><td>Rp. $Building</td></tr>
- <tr><td>Acc. depriciation building:</td><td>Rp. $DepBuilding</td></tr>
- <tr><td>Acc. depriciation equipment:</td><td>Rp. $DepEquipment</td></tr>
- <tr><td>Acc. depriciation supplies:</td><td>Rp. $DepSupplies</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Total Asset:</th>
- <th>$Asset</th>
- </tr>
- </tfoot>
- </table>
- EOT;
- $UnuRevenue = $row['unuser'];
- $CostRevPayable = $row['costrevpay'];
- $EquPayable = $row['equpay'];
- $SalPayable = $row['salpay'];
- $WagPayable = $row['wagpay'];
- $TelPayable = $row['telpay'];
- $UtiPayable = $row['utipay'];
- $RenPayable = $row['renpay'];
- $SupPayable = $row['suppay'];
- $AdvPayable = $row['advpay'];
- $VatPayable = $row['vatpay'];
- $TaxPayable = $row['taxpay'];
- $LegPayable = $row['legpay'];
- $MisPayable = $row['mispay'];
- $NotPayable = $row['notpay'];
- $IntPayable = $row['intpay'];
- $Liability = round($UnuRevenue + $CostRevPayable + $EquPayable + $SalPayable + $WagPayable + $TelPayable
- + $UtiPayable + $RenPayable + $SupPayable + $AdvPayable + $VatPayable + $TaxPayable + $LegPayable
- + $MisPayable + $NotPayable + $IntPayable, 2);
- $LiabilityReturn = $Liability;
- $graphCurrentLiability = round($row['unuser'] + $row['costrevpay'] + $row['equpay'] + $row['salpay']
- + $row['wagpay'] + $row['telpay'] + $row['utipay'] + $row['renpay'] + $row['suppay'] + $row['advpay']
- + $row['vatpay'] + $row['taxpay'] + $row['legpay'] + $row['mispay'] + $row['intpay'], 2);
- $graphNonCurrentLiability = $row['notpay'];
- if ($UnuRevenue < 0 || $CostRevPayable < 0 || $EquPayable < 0 || $SalPayable < 0 || $WagPayable < 0
- || $TelPayable < 0 || $UtiPayable < 0 || $RenPayable < 0 || $SupPayable < 0 || $AdvPayable < 0 || $VatPayable < 0
- || $TaxPayable < 0 || $LegPayable < 0 || $MisPayable < 0 || $NotPayable < 0 || $IntPayable < 0)
- $CheckError = "Error";
- $objSheet->getCell('A16')->setValue('Unearned Revenue');
- $objSheet->getCell('B16')->setValue($UnuRevenue);
- $objSheet->getCell('A17')->setValue('Revenue Cost Payable');
- $objSheet->getCell('B17')->setValue($CostRevPayable);
- $objSheet->getCell('A18')->setValue('Equipments Payable');
- $objSheet->getCell('B18')->setValue($EquPayable);
- $objSheet->getCell('A19')->setValue('Salaries Payable');
- $objSheet->getCell('B19')->setValue($SalPayable);
- $objSheet->getCell('A20')->setValue('Wages Payable');
- $objSheet->getCell('B20')->setValue($WagPayable);
- $objSheet->getCell('A21')->setValue('Tel. Bill Payable');
- $objSheet->getCell('B21')->setValue($TelPayable);
- $objSheet->getCell('A22')->setValue('Utility Bill Payable');
- $objSheet->getCell('B22')->setValue($UtiPayable);
- $objSheet->getCell('A23')->setValue('Rent Payable');
- $objSheet->getCell('B23')->setValue($RenPayable);
- $objSheet->getCell('A24')->setValue('Supplies Payable');
- $objSheet->getCell('B24')->setValue($SupPayable);
- $objSheet->getCell('A25')->setValue('Advertisement Payable');
- $objSheet->getCell('B25')->setValue($AdvPayable);
- $objSheet->getCell('A26')->setValue('VAT Payable');
- $objSheet->getCell('B26')->setValue($VatPayable);
- $objSheet->getCell('A27')->setValue('Tax Payable');
- $objSheet->getCell('B27')->setValue($TaxPayable);
- $objSheet->getCell('A28')->setValue('Legal & Admin Payable');
- $objSheet->getCell('B28')->setValue($LegPayable);
- $objSheet->getCell('A29')->setValue('Miscellaneous Payable');
- $objSheet->getCell('B29')->setValue($MisPayable);
- $objSheet->getCell('A30')->setValue('Notes Payable');
- $objSheet->getCell('B30')->setValue($NotPayable);
- $objSheet->getCell('A31')->setValue('Interest Payable');
- $objSheet->getCell('B31')->setValue($IntPayable);
- $objSheet->getCell('A32')->setValue('Total Liabilities');
- $objSheet->getCell('B32')->setValue('=SUM(B16:B31)');
- $objSheet->getStyle('A32:B32')->getFont()->setBold(true)->setSize(11);
- $UnuRevenue = $this->toMoney($UnuRevenue);
- $CostRevPayable = $this->toMoney($CostRevPayable);
- $EquPayable = $this->toMoney($EquPayable);
- $SalPayable = $this->toMoney($SalPayable);
- $WagPayable = $this->toMoney($WagPayable);
- $TelPayable = $this->toMoney($TelPayable);
- $UtiPayable = $this->toMoney($UtiPayable);
- $RenPayable = $this->toMoney($RenPayable);
- $SupPayable = $this->toMoney($SupPayable);
- $AdvPayable = $this->toMoney($AdvPayable);
- $VatPayable = $this->toMoney($VatPayable);
- $TaxPayable = $this->toMoney($TaxPayable);
- $LegPayable = $this->toMoney($LegPayable);
- $MisPayable = $this->toMoney($MisPayable);
- $NotPayable = $this->toMoney($NotPayable);
- $IntPayable = $this->toMoney($IntPayable);
- $Liability = $this->toMoney($Liability);
- echo <<<EOT
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Liability</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Unearned Revenue:</td><td>Rp. $UnuRevenue</td></tr>
- <tr><td>Revenue Cost Payable:</td><td>Rp. $CostRevPayable</td></tr>
- <tr><td>Equipments Payable:</td><td>Rp. $EquPayable</td></tr>
- <tr><td>Salaries Payable:</td><td>Rp. $SalPayable</td></tr>
- <tr><td>Wages Payable:</td><td>Rp. $WagPayable</td></tr>
- <tr><td>Tel. Bill Payable:</td><td>Rp. $TelPayable</td></tr>
- <tr><td>Utility Bill Payable:</td><td>Rp. $UtiPayable</td></tr>
- <tr><td>Rent Payable:</td><td>Rp. $RenPayable</td></tr>
- <tr><td>Supplies Payable:</td><td>Rp. $SupPayable</td></tr>
- <tr><td>Advertisement Payable:</td><td>Rp. $AdvPayable</td></tr>
- <tr><td>VAT Payable:</td><td>Rp. $VatPayable</td></tr>
- <tr><td>Tax Payable:</td><td>Rp. $TaxPayable</td></tr>
- <tr><td>Legal & Admin Payable:</td><td>Rp. $LegPayable</td></tr>
- <tr><td>Miscellaneous Payable:</td><td>Rp. $MisPayable</td></tr>
- <tr><td>Notes Payable:</td><td>Rp. $NotPayable</td></tr>
- <tr><td>Interest Payable:</td><td>Rp. $IntPayable</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Total Liabilities:</th>
- <th>$Liability</th>
- </tr>
- </tfoot>
- </table>
- EOT;
- $Equity = $ClosingEquity;
- $EquityReturn = $Equity;
- $graphEquity = $Equity;
- if ($Equity < 0)
- $CheckError = "Error";
- $objSheet->getCell('A33')->setValue('Equity');
- $objSheet->getCell('B33')->setValue($Equity);
- $objSheet->getCell('A34')->setValue('Total Owners Equity');
- $objSheet->getCell('B34')->setValue('=B33');
- $objSheet->getStyle('A34:B34')->getFont()->setBold(true)->setSize(11);
- $objWriter->save('statements/BalanceSheet' . '_' . $Token . '.xlsx');
- $Equity = $this->toMoney($Equity);
- $BalanceSheetSummary = $this->createBalanceSheetSummary($CashReturn, $AssetReturn, $LiabilityReturn, $EquityReturn);
- echo <<<EOT
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Owner's Equity:</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Equity:</td><td>Rp. $Equity</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Total Owner's Equity:</th>
- <th>$Equity</th>
- </tr>
- </tfoot>
- </table>
- <div class="summary">
- <div class="description waterfall right">
- EOT;
- $this->balanceWaterFall($graphCurrentAsset, $graphNonCurrentAsset, $graphCurrentLiability,
- $graphNonCurrentLiability, $graphEquity);
- echo <<<EOT
- </div>
- <div class="description in-words left">
- Summary: $BalanceSheetSummary
- </div>
- </div>
- </div>
- <div class="extra">
- Download
- <a href='statements/BalanceSheet_$Token.xlsx'><i class="table icon"></i></a>
- </div>
- </div>
- <div class="ui horizontal divider"><i class="anchor icon"></i></div>
- EOT;
- return array(
- $CashReturn,
- $AssetReturn,
- $LiabilityReturn,
- $EquityReturn,
- $CheckError
- );
- }
- /*------------------------------------------------------------------
- [Preview owner's equity statement and create excel export]
- -------------------------------------------------------------------*/
- public function previewOwnerEquity($Income, $objExcelEquity)
- {
- $Token = strtotime("now");
- $Month = $_SESSION['month'];
- $Year = $_SESSION['year'];
- $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $Beginning = $row['eqbeginning'];
- $Capital = $row['capital'];
- $Drawing = $row['drawing'];
- $Equity = $Beginning + $Capital + $Drawing + $Income;
- $graphBeginning = $Beginning;
- $graphCapital = $Capital;
- $graphDrawing = $Drawing;
- $graphIncome = $Income;
- $graphEquity = $Equity;
- $OwnersEquitySummary = $this->createOwnersEquitySummary($Beginning, $Capital, $Drawing, $Income, $Equity);
- $EquityReturn = $Equity;
- $SignIncome = ($Income < "0" ? "Less: Net Loss:" : "Add: Net Income:");
- $objExcelEquity->getDefaultStyle()->getFont()->setName('Segoe UI');
- $objExcelEquity->getDefaultStyle()->getFont()->setSize(11);
- $objWriter = PHPExcel_IOFactory::createWriter($objExcelEquity, "Excel2007");
- $objSheet = $objExcelEquity->getActiveSheet();
- $objSheet->setTitle('Owners Equity Statement');
- $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
- $objSheet->getColumnDimension('A')->setWidth(50);
- $objSheet->getColumnDimension('B')->setWidth(50);
- $objSheet->getStyle('B2:B8')->getNumberFormat()->setFormatCode('#,##0.00');
- $objSheet->mergeCells('A1:B1');
- $objSheet->getCell('A1')->setValue('Statement of Owners Equity');
- $objSheet->mergeCells('A2:B2');
- $objSheet->getCell('A2')->setValue('For the month of ' . $Month . '\'' . $Year);
- $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A3')->setValue('Account');
- $objSheet->getCell('B3')->setValue('Amount');
- $objSheet->getCell('A4')->setValue('Equity at Beginning');
- $objSheet->getCell('B4')->setValue($Beginning);
- $objSheet->getCell('A5')->setValue('Investment');
- $objSheet->getCell('B5')->setValue($Capital);
- $objSheet->getCell('A6')->setValue('Less: Drawing');
- $objSheet->getCell('B6')->setValue($Drawing);
- $objSheet->getCell('A7')->setValue($SignIncome);
- $objSheet->getCell('B7')->setValue($Income);
- $objSheet->getCell('A8')->setValue('Total Owners Equity Closing');
- $objSheet->getCell('B8')->setValue('=B4+B5+B6+B7');
- $objSheet->getStyle('A8:B8')->getFont()->setBold(true)->setSize(11);
- $objWriter->save('statements/OwnersEquityStatement' . '_' . $Token . '.xlsx');
- $Beginning = $this->toMoney($Beginning);
- $Capital = $this->toMoney($Capital);
- $Drawing = $this->toMoney($Drawing * -1);
- $Income = $this->toMoney(abs($Income));
- $Equity = $this->toMoney($Equity);
- echo <<<EOT
- <div class="ui card width-full">
- <div class="content">
- <div class="header"><i class="cubes icon"></i>Statement of Owner's Equity</div>
- <div class="meta">For the month of $Month'$Year</div>
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Equity</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Equity at Beginning:</td><td>Rp. $Beginning</td></tr>
- <tr><td>Investment:</td><td>$Capital</td></tr>
- <tr><td>Less: Drawing:</td><td>$Drawing</td></tr>
- <tr><td>$SignIncome</td><td>Rp. $Income</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Total Owner's Equity Closing:</th>
- <th>$Equity</th>
- </tr>
- </tfoot>
- </table>
- <div class="summary">
- <div class="description waterfall left">
- EOT;
- $this->equityWaterFall($graphBeginning, $graphCapital, $graphDrawing, $graphIncome, $graphEquity);
- echo <<<EOT
- </div>
- <div class="description in-words right">
- Summary: $OwnersEquitySummary
- </div>
- </div>
- </div>
- <div class="extra">
- Download
- <a href='statements/OwnersEquityStatement_$Token.xlsx'><i class="table icon"></i></a>
- </div>
- </div>
- <div class="ui horizontal divider"><i class="anchor icon"></i></div>
- EOT;
- return array(
- $EquityReturn
- );
- }
- /*------------------------------------------------------------------
- [Preview income statement and create excel export]
- -------------------------------------------------------------------*/
- public function previewIncomeStatement($objExcelIncome)
- {
- $Token = strtotime("now");
- $Month = $_SESSION['month'];
- $Year = $_SESSION['year'];
- $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $ServiceRev = $row['serrev'];
- $InterestRev = $row['intrev'];
- $ProGain = $row['progain'];
- $CostRevExp = $row['costrevexp'];
- $SalaryExp = $row['salexp'];
- $WagesExp = $row['wagexp'];
- $RentExp = $row['renexp'];
- $InsuranceExp = $row['insexp'];
- $TelephoneExp = $row['telexp'];
- $UtilityExp = $row['utiexp'];
- $AdvertisementExp = $row['advexp'];
- $InterestExp = $row['intexp'];
- $VatExp = $row['vatexp'];
- $TaxExp = $row['taxexp'];
- $LegExp = $row['legexp'];
- $MisExp = $row['misexp'];
- $BadExp = $row['baddebtexp'];
- $DepBuilding = $row['depbuiexp'];
- $DepEquipment = $row['depequexp'];
- $DepSupplies = $row['depsupexp'];
- $GrossRev = round($ServiceRev + $InterestRev + $ProGain, 2);
- $TotalExpenses = round($CostRevExp + $SalaryExp + $WagesExp + $RentExp + $InsuranceExp + $TelephoneExp
- + $UtilityExp + $AdvertisementExp + $MisExp + $LegExp + $BadExp, 2);
- $Ebitda = round($GrossRev + $TotalExpenses, 2);
- $OtherExpenses = round($InterestExp + $VatExp + $TaxExp + $DepBuilding + $DepEquipment + $DepSupplies, 2);
- $NetIncome = round($Ebitda + $OtherExpenses, 2);
- $graphGrossRev = $GrossRev;
- $graphTotalExpenses = $TotalExpenses;
- $graphEbitda = $Ebitda;
- $graphOtherExpenses = $OtherExpenses;
- $graphNetIncome = $NetIncome;
- $IncomeStatementSummary = $this->createIncomeSummary($GrossRev, $TotalExpenses, $Ebitda, $OtherExpenses, $NetIncome);
- $IncomeReturn = $NetIncome;
- $SignEbitda = ($Ebitda < "0" ? "EBITDA (Loss):" : "EBITDA:");
- $SignNetIncome = ($NetIncome < "0" ? "Net Loss:" : "Net Income:");
- $objExcelIncome->getDefaultStyle()->getFont()->setName('Segoe UI');
- $objExcelIncome->getDefaultStyle()->getFont()->setSize(11);
- $objWriter = PHPExcel_IOFactory::createWriter($objExcelIncome, "Excel2007");
- $objSheet = $objExcelIncome->getActiveSheet();
- $objSheet->setTitle('Income Statement');
- $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
- $objSheet->getColumnDimension('A')->setWidth(50);
- $objSheet->getColumnDimension('B')->setWidth(50);
- $objSheet->getStyle('B2:B50')->getNumberFormat()->setFormatCode('#,##0.00');
- $objSheet->mergeCells('A1:B1');
- $objSheet->getCell('A1')->setValue('Income Statement');
- $objSheet->mergeCells('A2:B2');
- $objSheet->getCell('A2')->setValue('For the month of ' . $Month . '\'' . $Year);
- $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A3')->setValue('Account');
- $objSheet->getCell('B3')->setValue('Amount');
- $objSheet->getCell('A4')->setValue('Service Revenue');
- $objSheet->getCell('B4')->setValue($ServiceRev);
- $objSheet->getCell('A5')->setValue('Interest Revenue');
- $objSheet->getCell('B5')->setValue($InterestRev);
- $objSheet->getCell('A6')->setValue('Gain/loss of sales');
- $objSheet->getCell('B6')->setValue($ProGain);
- $objSheet->getCell('A7')->setValue('Gross Revenue');
- $objSheet->getCell('B7')->setValue('=SUM(B4:B6)');
- $objSheet->getStyle('A7:B7')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A8')->setValue('Cost of Revenue');
- $objSheet->getCell('B8')->setValue($CostRevExp * -1);
- $objSheet->getCell('A9')->setValue('Salaries Expenses');
- $objSheet->getCell('B9')->setValue($SalaryExp * -1);
- $objSheet->getCell('A10')->setValue('Wages Expenses');
- $objSheet->getCell('B10')->setValue($WagesExp * -1);
- $objSheet->getCell('A11')->setValue('Rent Expenses');
- $objSheet->getCell('B11')->setValue($RentExp * -1);
- $objSheet->getCell('A12')->setValue('Insurance Expenses');
- $objSheet->getCell('B12')->setValue($InsuranceExp * -1);
- $objSheet->getCell('A13')->setValue('Telephone Expenses');
- $objSheet->getCell('B13')->setValue($TelephoneExp * -1);
- $objSheet->getCell('A14')->setValue('Utility Expenses');
- $objSheet->getCell('B14')->setValue($UtilityExp * -1);
- $objSheet->getCell('A15')->setValue('Advertisement Expenses');
- $objSheet->getCell('B15')->setValue($AdvertisementExp * -1);
- $objSheet->getCell('A16')->setValue('Legal & Admin Expenses');
- $objSheet->getCell('B16')->setValue($LegExp * -1);
- $objSheet->getCell('A17')->setValue('Miscellaneous Expenses');
- $objSheet->getCell('B17')->setValue($MisExp * -1);
- $objSheet->getCell('A18')->setValue('Bad Debt Expense');
- $objSheet->getCell('B18')->setValue($BadExp * -1);
- $objSheet->getCell('A19')->setValue('Total Direct Expenses');
- $objSheet->getCell('B19')->setValue('=SUM(B8:B18)');
- $objSheet->getStyle('A19:B19')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A20')->setValue($SignEbitda);
- $objSheet->getCell('B20')->setValue('=B7-B19');
- $objSheet->getStyle('A20:B20')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A21')->setValue('Dep. Expense Building');
- $objSheet->getCell('B21')->setValue($DepBuilding * -1);
- $objSheet->getCell('A22')->setValue('Dep. Expense Equipment');
- $objSheet->getCell('B22')->setValue($DepEquipment * -1);
- $objSheet->getCell('A23')->setValue('Dep. Expenses Supplies');
- $objSheet->getCell('B23')->setValue($DepSupplies * -1);
- $objSheet->getCell('A24')->setValue('Interest Expenses');
- $objSheet->getCell('B24')->setValue($InterestExp * -1);
- $objSheet->getCell('A25')->setValue('VAT Expenses');
- $objSheet->getCell('B25')->setValue($VatExp * -1);
- $objSheet->getCell('A26')->setValue('Tax Expenses');
- $objSheet->getCell('B26')->setValue($TaxExp * -1);
- $objSheet->getCell('A27')->setValue('Other Expenses');
- $objSheet->getCell('B27')->setValue('=SUM(B21:B26)');
- $objSheet->getStyle('A27:B27')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A28')->setValue($SignNetIncome);
- $objSheet->getCell('B28')->setValue('=B7-B19-B27');
- $objSheet->getStyle('A28:B28')->getFont()->setBold(true)->setSize(11);
- $objWriter->save('statements/IncomeStatement' . '_' . $Token . '.xlsx');
- $ServiceRev = $this->toMoney($ServiceRev);
- $InterestRev = $this->toMoney($InterestRev);
- $ProGain = $this->toMoney($ProGain);
- $CostRevExp = $this->toMoney($CostRevExp * -1);
- $SalaryExp = $this->toMoney($SalaryExp * -1);
- $WagesExp = $this->toMoney($WagesExp * -1);
- $RentExp = $this->toMoney($RentExp * -1);
- $InsuranceExp = $this->toMoney($InsuranceExp * -1);
- $TelephoneExp = $this->toMoney($TelephoneExp * -1);
- $UtilityExp = $this->toMoney($UtilityExp * -1);
- $AdvertisementExp = $this->toMoney($AdvertisementExp * -1);
- $MisExp = $this->toMoney($MisExp * -1);
- $InterestExp = $this->toMoney($InterestExp * -1);
- $VatExp = $this->toMoney($VatExp * -1);
- $TaxExp = $this->toMoney($TaxExp * -1);
- $LegExp = $this->toMoney($LegExp * -1);
- $BadExp = $this->toMoney($BadExp * -1);
- $DepBuilding = $this->toMoney($DepBuilding * -1);
- $DepEquipment = $this->toMoney($DepEquipment * -1);
- $DepSupplies = $this->toMoney($DepSupplies * -1);
- $GrossRev = $this->toMoney($GrossRev);
- $TotalExpenses = $this->toMoney($TotalExpenses * -1);
- $Ebitda = $this->toMoney(abs($Ebitda));
- $OtherExpenses = $this->toMoney($OtherExpenses * -1);
- $NetIncome = $this->toMoney(abs($NetIncome));
- echo <<<EOT
- <div class="ui card width-full">
- <div class="content">
- <div class="header"><i class="cubes icon"></i>Income Statement</div>
- <div class="meta">For the month of $Month'$Year</div>
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Gross Revenue</th>
- <th class="summary-width-right"><i class="book icon"></i>Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Service Revenue:</td><td>Rp. $ServiceRev</td></tr>
- <tr><td>Interest Revenue:</td><td>Rp. $InterestRev</td></tr>
- <tr><td>Gain/Loss on Asset Sales:</td><td>Rp. $ProGain</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Gross Revenue:</th>
- <th>$GrossRev</th>
- </tr>
- </tfoot>
- </table>
- EOT;
- echo <<<EOT
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Direct Expense</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Cost of Revenue:</td><td>Rp. $CostRevExp</td></tr>
- <tr><td>Salaries Expense:</td><td>Rp. $SalaryExp</td></tr>
- <tr><td>Wages Expense:</td><td>Rp. $WagesExp</td></tr>
- <tr><td>Rent Expense:</td><td>Rp. $RentExp</td></tr>
- <tr><td>Insurance Expense:</td><td>Rp. $InsuranceExp</td></tr>
- <tr><td>Telephone Expense:</td><td>Rp. $TelephoneExp</td></tr>
- <tr><td>Utility Expense:</td><td>Rp. $UtilityExp</td></tr>
- <tr><td>Advertisement Expense:</td><td>Rp. $AdvertisementExp</td></tr>
- <tr><td>Legal & Admin Expense:</td><td>Rp. $LegExp</td></tr>
- <tr><td>Miscellaneous Expense:</td><td>Rp. $MisExp</td></tr>
- <tr><td>Bad Det Expense:</td><td>Rp. $BadExp</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Total Direct Expense:</th>
- <th>$TotalExpenses</th>
- </tr>
- <tr>
- <th>$SignEbitda</th>
- <th>$Ebitda</th>
- </tr>
- </tfoot>
- </table>
- EOT;
- echo <<<EOT
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Other Expense</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Dep. Expense Building:</td><td>Rp. $DepBuilding</td></tr>
- <tr><td>Dep. Expense Equipment:</td><td>Rp. $DepEquipment</td></tr>
- <tr><td>Dep. Expense Supplies:</td><td>Rp. $DepSupplies</td></tr>
- <tr><td>Interest Expense:</td><td>Rp. $InterestExp</td></tr>
- <tr><td>VAT Expense:</td><td>Rp. $VatExp</td></tr>
- <tr><td>Tax Expense:</td><td>Rp. $TaxExp</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Other Expenses:</th>
- <th>$OtherExpenses</th>
- </tr>
- <tr>
- <th>$SignNetIncome</th>
- <th>$NetIncome</th>
- </tr>
- </tfoot>
- </table>
- <div class="summary">
- <div class="description waterfall right">
- EOT;
- $this->incomeWaterFall($graphGrossRev, $graphTotalExpenses, $graphEbitda, $graphOtherExpenses, $graphNetIncome);
- echo <<<EOT
- </div>
- <div class="description in-words left">
- Summary: $IncomeStatementSummary
- </div>
- </div>
- </div>
- <div class="extra">
- Download
- <a href='statements/IncomeStatement_$Token.xlsx'><i class="table icon"></i></a>
- </div>
- </div>
- <div class="ui horizontal divider"><i class="anchor icon"></i></div>
- EOT;
- return array(
- $IncomeReturn
- );
- }
- /*------------------------------------------------------------------
- [Preview cash flow statement and create excel export]
- -------------------------------------------------------------------*/
- public function previewCashFlowStatement($Income, $objExcelCash)
- {
- $Token = strtotime("now");
- $Month = $_SESSION['month'];
- $Year = $_SESSION['year'];
- $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $ID = $_SESSION['id'];
- if ($ID == '1') {
- $ProGain = $row['progain'];
- $DepBuilding = $row['depbuiexp'];
- $DepEquipment = $row['depequexp'];
- $DepSupplies = $row['depsupexp'];
- $UnuRevenue = $row['unuser'];
- $AccReceivable = $row['accrecser'];
- $CostRevPayable = $row['costrevpay'];
- $SalPayable = $row['salpay'];
- $WagPayable = $row['wagpay'];
- $TelPayable = $row['telpay'];
- $UtiPayable = $row['utipay'];
- $RenPayable = $row['renpay'];
- $AdvPayable = $row['advpay'];
- $VatPayable = $row['vatpay'];
- $TaxPayable = $row['taxpay'];
- $LegPayable = $row['legpay'];
- $MisPayable = $row['mispay'];
- $ProCash = $row['procash'];
- $PreInsurance = $row['preins'];
- $PreRent = $row['preren'];
- $PreSupplies = $row['presup'];
- $BuiPurchase = $row['cashbui'];
- $EquPurchase = $row['cashequ'];
- $SupPurchase = $row['cashsup'];
- $NotesPayable = $row['notpay'];
- $IntPayable = $row['intpay'];
- $Capital = $row['capital'];
- $Drawing = $row['drawing'];
- }
- else {
- $siteQuery = "SELECT * FROM records ORDER BY ID DESC LIMIT 1";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $lastBalance = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $ProGain = $row['progain'];
- $DepBuilding = $row['depbuiexp'];
- $DepEquipment = $row['depequexp'];
- $DepSupplies = $row['depsupexp'];
- $UnuRevenue = round($row['unuser'] - $lastBalance['unuser'], 2);
- $AccReceivable = round($row['accrecser'] - $lastBalance['accrecser'], 2);
- $CostRevPayable = round($row['costrevpay'] - $lastBalance['costrevpay'], 2);
- $SalPayable = round($row['salpay'] - $lastBalance['salpay'], 2);
- $WagPayable = round($row['wagpay'] - $lastBalance['wagpay'], 2);
- $TelPayable = round($row['telpay'] - $lastBalance['telpay'], 2);
- $UtiPayable = round($row['utipay'] - $lastBalance['utipay'], 2);
- $RenPayable = round($row['renpay'] - $lastBalance['renpay'], 2);
- $AdvPayable = round($row['advpay'] - $lastBalance['advpay'], 2);
- $VatPayable = round($row['vatpay'] - $lastBalance['vatpay'], 2);
- $TaxPayable = round($row['taxpay'] - $lastBalance['taxpay'], 2);
- $LegPayable = round($row['legpay'] - $lastBalance['legpay'], 2);
- $MisPayable = round($row['mispay'] - $lastBalance['mispay'], 2);
- $ProCash = $row['procash'];
- $PreInsurance = round($row['preins'] - $lastBalance['preins'], 2);
- $PreRent = round($row['preren'] - $lastBalance['preren'], 2);
- $PreSupplies = round($row['presup'] - $lastBalance['presup'], 2);
- $BuiPurchase = $row['cashbui'];
- $EquPurchase = $row['cashequ'];
- $SupPurchase = $row['cashsup'];
- $NotesPayable = round($row['notpay'] - $lastBalance['notpay'], 2);
- $IntPayable = round($row['intpay'] - $lastBalance['intpay'], 2);
- $Capital = $row['capital'];
- $Drawing = $row['drawing'];
- }
- $CashOp = round($Income - $ProGain - $DepBuilding - $DepEquipment - $DepSupplies + $UnuRevenue
- - $AccReceivable + $CostRevPayable + $SalPayable + $WagPayable + $TelPayable + $UtiPayable + $RenPayable
- + $AdvPayable + $VatPayable + $TaxPayable + $LegPayable + $MisPayable + $IntPayable, 2);
- $CashInv = round($NotesPayable - ($PreInsurance + $PreRent + $PreSupplies + $BuiPurchase + $EquPurchase + $SupPurchase)
- + $ProCash, 2);
- $CashFin = round($Capital + $Drawing, 2);
- $CashBeginning = $row['cashbeginning'];
- $CashEnding = round($CashBeginning + $CashOp + $CashInv + $CashFin, 2);
- $CashEndingReturn = $CashEnding;
- $graphCash = round($CashOp + $CashInv + $CashFin, 2);
- $graphCashBeginning = $CashBeginning;
- $graphCashEnding = $CashEnding;
- $CashFlowSummary = $this->createCashFlowSummary($CashOp, $CashInv, $CashFin, $CashBeginning, $CashEnding);
- $SignIncome = ($Income < "0" ? "Less: Net Loss:" : "Add: Net Income:");
- $SignProGain = ($ProGain < "0" ? "Add: Loss on Asset Sale:" : "Less: Gain on Asset Sale:");
- $SignAccReceivable = ($AccReceivable < "0" ? "Add: Decr. in Account Receivable:" : "Less: Incr. in Account Receivable:");
- $SignUnuRevenue = ($UnuRevenue < "0" ? "Less: Decr. in Unearned Revenue:" : "Add: Incr. in Unearned Revenue:");
- $SignCostRevPayable = ($CostRevPayable < "0" ? "Less: Decr. in Revenue Cost Payable:" : "Add: Incr. in Revenue Cost Payable:");
- $SignSalPayable = ($SalPayable < "0" ? "Less: Decr. in Salaries Payable:" : "Add: Incr. in Salaries Payable:");
- $SignWagPayable = ($WagPayable < "0" ? "Less: Decr. in Wages payable:" : "Add: Incr. in Wages payable:");
- $SignTelPayable = ($TelPayable < "0" ? "Less: Decr. in Tel. Bill Payable:" : "Add: Incr. in Tel. Bill Payable:");
- $SignUtiPayable = ($UtiPayable < "0" ? "Less: Decr. in Util. Bill Payable:" : "Add: Incr. in Util. Bill Payable:");
- $SignRenPayable = ($RenPayable < "0" ? "Less: Decr. in Rent Payable:" : "Add: Incr. in Rent Payable:");
- $SignAdvPayable = ($AdvPayable < "0" ? "Less: Decr. in Adv. Payable:" : "Add: Incr. in Adv. Payable:");
- $SignIntPayable = ($IntPayable < "0" ? "Less: Decr. in Interest Payable:" : "Add: Incr. in Interest Payable:");
- $SignVatPayable = ($VatPayable < "0" ? "Less: Decr. in VAT Payable:" : "Add: Incr. in VAT Payable:");
- $SignTaxPayable = ($TaxPayable < "0" ? "Less: Decr. in Tax Payable:" : "Add: Incr. in Tax Payable:");
- $SignLegPayable = ($LegPayable < "0" ? "Less: Decr. in Legal & Admin Payable:" : "Add: Incr. in Legal & Admin Payable:");
- $SignMisPayable = ($MisPayable < "0" ? "Less: Decr. in Misc. Payable:" : "Add: Incr. in Misc. Payable:");
- $SignPreInsurance = ($PreInsurance < "0" ? "Less: Decr. in Prepaid Insurance:" : "Add: Incr. in Prepaid Insurance:");
- $SignPreRent = ($PreRent < "0" ? "Less: Decr. in Prepaid Rent:" : "Add: Incr. in Prepaid Rent:");
- $SignPreSupplies = ($PreSupplies < "0" ? "Less: Decr. in Prepaid Supplies:" : "Add: Incr. in Prepaid Supplies:");
- $SignNotesPayable = ($NotesPayable < "0" ? "Less: Decr. in Notes Payable:" : "Add: Incr. in Notes Payable:");
- $SignCashOp = ($CashOp < "0" ? "Less: Cash from Operating Activities:" : "Add: Cash from Operating Activities:");
- $SignCashInv = ($CashInv < "0" ? "Less: Cash from Investing Activities:" : "Add: Cash from Investing Activities:");
- $SignCashFin = ($CashFin < "0" ? "Less: Cash from Financing Activities:" : "Add: Cash from Financing Activities:");
- $objExcelCash->getDefaultStyle()->getFont()->setName('Segoe UI');
- $objExcelCash->getDefaultStyle()->getFont()->setSize(11);
- $objWriter = PHPExcel_IOFactory::createWriter($objExcelCash, "Excel2007");
- $objSheet = $objExcelCash->getActiveSheet();
- $objSheet->setTitle('Income Statement');
- $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
- $objSheet->getColumnDimension('A')->setWidth(50);
- $objSheet->getColumnDimension('B')->setWidth(50);
- $objSheet->getStyle('B2:B50')->getNumberFormat()->setFormatCode('#,##0.00');
- $objSheet->mergeCells('A1:B1');
- $objSheet->getCell('A1')->setValue('Statement of Cash Flow');
- $objSheet->mergeCells('A2:B2');
- $objSheet->getCell('A2')->setValue('For the month of ' . $Month . '\'' . $Year);
- $objSheet->getCell('A3')->setValue('Account');
- $objSheet->getCell('B3')->setValue('Amount');
- $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A4')->setValue($SignIncome);
- $objSheet->getCell('B4')->setValue($Income);
- $objSheet->getCell('A5')->setValue($SignAccReceivable);
- $objSheet->getCell('B5')->setValue($AccReceivable);
- $objSheet->getCell('A6')->setValue($SignProGain);
- $objSheet->getCell('B6')->setValue($ProGain);
- $objSheet->getCell('A7')->setValue('Add: Dep. Expense Building:');
- $objSheet->getCell('B7')->setValue($DepBuilding);
- $objSheet->getCell('A8')->setValue('Add: Dep. Expense Equipment:');
- $objSheet->getCell('B8')->setValue($DepEquipment);
- $objSheet->getCell('A9')->setValue('Add: Dep. Expense Supplies:');
- $objSheet->getCell('B9')->setValue($DepSupplies);
- $objSheet->getCell('A10')->setValue($SignUnuRevenue);
- $objSheet->getCell('B10')->setValue($UnuRevenue);
- $objSheet->getCell('A11')->setValue($SignCostRevPayable);
- $objSheet->getCell('B11')->setValue($CostRevPayable);
- $objSheet->getCell('A12')->setValue($SignSalPayable);
- $objSheet->getCell('B12')->setValue($SalPayable);
- $objSheet->getCell('A13')->setValue($SignWagPayable);
- $objSheet->getCell('B13')->setValue($WagPayable);
- $objSheet->getCell('A14')->setValue($SignTelPayable);
- $objSheet->getCell('B14')->setValue($TelPayable);
- $objSheet->getCell('A15')->setValue($SignUtiPayable);
- $objSheet->getCell('B15')->setValue($UtiPayable);
- $objSheet->getCell('A16')->setValue($SignRenPayable);
- $objSheet->getCell('B16')->setValue($RenPayable);
- $objSheet->getCell('A17')->setValue($SignAdvPayable);
- $objSheet->getCell('B17')->setValue($AdvPayable);
- $objSheet->getCell('A18')->setValue($SignIntPayable);
- $objSheet->getCell('B18')->setValue($IntPayable);
- $objSheet->getCell('A19')->setValue($SignVatPayable);
- $objSheet->getCell('B19')->setValue($VatPayable);
- $objSheet->getCell('A20')->setValue($SignTaxPayable);
- $objSheet->getCell('B20')->setValue($TaxPayable);
- $objSheet->getCell('A21')->setValue($SignLegPayable);
- $objSheet->getCell('B21')->setValue($LegPayable);
- $objSheet->getCell('A22')->setValue($SignMisPayable);
- $objSheet->getCell('B22')->setValue($MisPayable);
- $objSheet->getCell('A23')->setValue($SignCashOp);
- $objSheet->getCell('B23')->setValue('=B4-B6-B7-B8-B9+B10-B5+B11+B12+B13+B14+B15+B16+B17+B18+B19+B20+B21+B22');
- $objSheet->getStyle('A23:B23')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A24')->setValue($SignPreInsurance);
- $objSheet->getCell('B24')->setValue($PreInsurance);
- $objSheet->getCell('A25')->setValue($SignPreRent);
- $objSheet->getCell('B25')->setValue($PreRent);
- $objSheet->getCell('A26')->setValue($SignPreSupplies);
- $objSheet->getCell('B26')->setValue($PreSupplies);
- $objSheet->getCell('A27')->setValue('Building Purchase');
- $objSheet->getCell('B27')->setValue($BuiPurchase);
- $objSheet->getCell('A28')->setValue('Equipment Purchase');
- $objSheet->getCell('B28')->setValue($EquPurchase);
- $objSheet->getCell('A29')->setValue('Supplies Purchase');
- $objSheet->getCell('B29')->setValue($SupPurchase);
- $objSheet->getCell('A30')->setValue($SignNotesPayable);
- $objSheet->getCell('B30')->setValue($NotesPayable);
- $objSheet->getCell('A31')->setValue('Add: Proceeds from Asset Sale');
- $objSheet->getCell('B31')->setValue($ProCash);
- $objSheet->getCell('A32')->setValue($SignCashInv);
- $objSheet->getCell('B32')->setValue('=B30+B31-B24-B25-B26-B27-B28-B29');
- $objSheet->getStyle('A32:B32')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A33')->setValue('Investment');
- $objSheet->getCell('B33')->setValue($Capital);
- $objSheet->getCell('A34')->setValue('Less: Drawing');
- $objSheet->getCell('B34')->setValue($Drawing);
- $objSheet->getCell('A35')->setValue($SignCashFin);
- $objSheet->getCell('B35')->setValue('=B33+B34');
- $objSheet->getStyle('A35:B35')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A36')->setValue('Cash: Beginning Month');
- $objSheet->getCell('B36')->setValue($CashBeginning);
- $objSheet->getStyle('A36:B36')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A37')->setValue('Cash: Ending Month');
- $objSheet->getCell('B37')->setValue('=B23+B32+B35+B36');
- $objSheet->getStyle('A37:B37')->getFont()->setBold(true)->setSize(11);
- $objWriter->save('statements/CashFlowStatement' . '_' . $Token . '.xlsx');
- $ProGain = $this->toMoney(abs($ProGain));
- $DepBuilding = $this->toMoney($DepBuilding * -1);
- $DepEquipment = $this->toMoney($DepEquipment * -1);
- $DepSupplies = $this->toMoney($DepSupplies * -1);
- $UnuRevenue = $this->toMoney(abs($UnuRevenue));
- $AccReceivable = $this->toMoney(abs($AccReceivable));
- $CostRevPayable = $this->toMoney(abs($CostRevPayable));
- $SalPayable = $this->toMoney(abs($SalPayable));
- $WagPayable = $this->toMoney(abs($WagPayable));
- $TelPayable = $this->toMoney(abs($TelPayable));
- $UtiPayable = $this->toMoney(abs($UtiPayable));
- $RenPayable = $this->toMoney(abs($RenPayable));
- $AdvPayable = $this->toMoney(abs($AdvPayable));
- $IntPayable = $this->toMoney(abs($IntPayable));
- $VatPayable = $this->toMoney(abs($VatPayable));
- $TaxPayable = $this->toMoney(abs($TaxPayable));
- $LegPayable = $this->toMoney(abs($LegPayable));
- $MisPayable = $this->toMoney(abs($MisPayable));
- $Income = $this->toMoney(abs($Income));
- $CashOp = $this->toMoney(abs($CashOp));
- $ProCash = $this->toMoney($ProCash);
- $PreInsurance = $this->toMoney(abs($PreInsurance));
- $PreRent = $this->toMoney(abs($PreRent));
- $PreSupplies = $this->toMoney(abs($PreSupplies));
- $BuiPurchase = $this->toMoney($BuiPurchase);
- $EquPurchase = $this->toMoney($EquPurchase);
- $SupPurchase = $this->toMoney($SupPurchase);
- $NotesPayable = $this->toMoney(abs($NotesPayable));
- $CashInv = $this->toMoney(abs($CashInv));
- $Capital = $this->toMoney($Capital);
- $Drawing = $this->toMoney($Drawing * -1);
- $CashFin = $this->toMoney(abs($CashFin));
- $CashBeginning = $this->toMoney($CashBeginning);
- $CashEnding = $this->toMoney($CashEnding);
- echo <<<EOT
- <div class="ui card width-full">
- <div class="content">
- <div class="header"><i class="cubes icon"></i>Statement of Cash Flow</div>
- <div class="meta">For the month of $Month'$Year</div>
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Operating Cash Flow</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>$SignIncome</td><td>Rp. $Income</td></tr>
- <tr><td>$SignAccReceivable</td><td>Rp. $AccReceivable</td></tr>
- <tr><td>$SignProGain</td><td>Rp. $ProGain</td></tr>
- <tr><td>Add: Dep. Expense Building:</td><td>Rp. $DepBuilding</td></tr>
- <tr><td>Add: Dep. Expense Equipment:</td><td>Rp. $DepEquipment</td></tr>
- <tr><td>Add: Dep. Expense Supplies:</td><td>Rp. $DepSupplies</td></tr>
- <tr><td>$SignUnuRevenue</td><td>Rp. $UnuRevenue</td></tr>
- <tr><td>$SignCostRevPayable</td><td>Rp. $CostRevPayable</td></tr>
- <tr><td>$SignSalPayable</td><td>Rp. $SalPayable</td></tr>
- <tr><td>$SignWagPayable</td><td>Rp. $WagPayable</td></tr>
- <tr><td>$SignTelPayable</td><td>Rp. $TelPayable</td></tr>
- <tr><td>$SignUtiPayable</td><td>Rp. $UtiPayable</td></tr>
- <tr><td>$SignRenPayable</td><td>Rp. $RenPayable</td></tr>
- <tr><td>$SignAdvPayable</td><td>Rp. $AdvPayable</td></tr>
- <tr><td>$SignIntPayable</td><td>Rp. $IntPayable</td></tr>
- <tr><td>$SignVatPayable</td><td>Rp. $VatPayable</td></tr>
- <tr><td>$SignTaxPayable</td><td>Rp. $TaxPayable</td></tr>
- <tr><td>$SignLegPayable</td><td>Rp. $LegPayable</td></tr>
- <tr><td>$SignMisPayable</td><td>Rp. $MisPayable</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>$SignCashOp</th>
- <th>$CashOp</th>
- </tr>
- </tfoot>
- </table>
- EOT;
- echo <<<EOT
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Investing Cash Flow</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>$SignPreInsurance</td><td>Rp. $PreInsurance</td></tr>
- <tr><td>$SignPreRent</td><td>Rp. $PreRent</td></tr>
- <tr><td>$SignPreSupplies</td><td>Rp. $PreSupplies</td></tr>
- <tr><td>Building Purchase:</td><td>Rp. $BuiPurchase</td></tr>
- <tr><td>Equipment Purchase:</td><td>Rp. $EquPurchase</td></tr>
- <tr><td>Supplies Purchase:</td><td>Rp. $SupPurchase</td></tr>
- <tr><td>$SignNotesPayable</td><td>Rp. $NotesPayable</td></tr>
- <tr><td>Add: Proceeds from Asset Sale:</td><td>Rp. $ProCash</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>$SignCashInv</th>
- <th>$CashInv</th>
- </tr>
- </tfoot>
- </table>
- EOT;
- echo <<<EOT
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Financing Cash Flow</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Investment:</td><td>Rp. $Capital</td></tr>
- <tr><td>Less: Drawing:</td><td>Rp. $Drawing</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>$SignCashFin</th>
- <th>$CashFin</th>
- </tr>
- <tr>
- <th>Cash: Beginning Period:</th>
- <th>$CashBeginning</th>
- </tr>
- <tr>
- <th>Cash: Ending Period:</th>
- <th>$CashEnding</th>
- </tr>
- </tfoot>
- </table>
- <div class="summary">
- <div class="description waterfall left">
- EOT;
- $this->cashWaterFall($graphCash, $graphCashBeginning, $graphCashEnding);
- echo <<<EOT
- </div>
- <div class="description in-words right">
- Summary: $CashFlowSummary
- </div>
- </div>
- </div>
- <div class="extra">
- Download
- <a href='statements/CashFlowStatement_$Token.xlsx'><i class="table icon"></i></a>
- </div>
- </div>
- <div class="ui horizontal divider"><i class="anchor icon"></i></div>
- EOT;
- return array(
- $CashEndingReturn
- );
- }
- /*------------------------------------------------------------------
- [Preview bank reconciliation and create excel export]
- -------------------------------------------------------------------*/
- public function previewBankReconciliation($CashEnding, $objExcelRecon)
- {
- $Token = strtotime("now");
- $Month = $_SESSION['month'];
- $Year = $_SESSION['year'];
- $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $DepTransit = $row['deptransit'];
- $OutChecks = $row['outchecks'];
- $PettyCash = $row['pettycash'];
- $BankBalance = round($CashEnding + $DepTransit + $OutChecks + $PettyCash, 2);
- $objExcelRecon->getDefaultStyle()->getFont()->setName('Segoe UI');
- $objExcelRecon->getDefaultStyle()->getFont()->setSize(11);
- $objWriter = PHPExcel_IOFactory::createWriter($objExcelRecon, "Excel2007");
- $objSheet = $objExcelRecon->getActiveSheet();
- $objSheet->setTitle('Bank Reconciliation Statement');
- $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
- $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
- $objSheet->getColumnDimension('A')->setWidth(50);
- $objSheet->getColumnDimension('B')->setWidth(50);
- $objSheet->getStyle('B2:B8')->getNumberFormat()->setFormatCode('#,##0.00');
- $objSheet->mergeCells('A1:B1');
- $objSheet->getCell('A1')->setValue('Statement of Bank Reconciliation');
- $objSheet->mergeCells('A2:B2');
- $objSheet->getCell('A2')->setValue('For the month ending ' . $Month . '\'' . $Year);
- $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
- $objSheet->getCell('A3')->setValue('Account');
- $objSheet->getCell('B3')->setValue('Amount');
- $objSheet->getCell('A4')->setValue('Cash: Account Statement');
- $objSheet->getCell('B4')->setValue($CashEnding);
- $objSheet->getCell('A5')->setValue('Deposit in Transit');
- $objSheet->getCell('B5')->setValue($DepTransit);
- $objSheet->getCell('A6')->setValue('Outstanding Checks');
- $objSheet->getCell('B6')->setValue($OutChecks);
- $objSheet->getCell('A7')->setValue('Petty Cash');
- $objSheet->getCell('B7')->setValue($PettyCash);
- $objSheet->getCell('A8')->setValue('Cash: Bank Statement');
- $objSheet->getCell('B8')->setValue('=B4+B5+B6+B7');
- $objSheet->getStyle('A8:B8')->getFont()->setBold(true)->setSize(11);
- $objWriter->save('statements/ReconciliationStatement' . '_' . $Token . '.xlsx');
- $CashEnding = $this->toMoney($CashEnding);
- $DepTransit = $this->toMoney($DepTransit * -1);
- $OutChecks = $this->toMoney($OutChecks);
- $PettyCash = $this->toMoney($PettyCash * -1);
- $BankBalance = $this->toMoney($BankBalance);
- echo <<<EOT
- <div class="ui card width-full">
- <div class="content">
- <div class="header"><i class="cubes icon"></i>Statement of Bank Reconciliation</div>
- <div class="meta">For the month ending $Month'$Year</div>
- <table class="ui">
- <thead>
- <tr>
- <th class="summary-width-left"><i class="book icon"></i>Particulars</th>
- <th class="summary-width-right">Amount</th>
- </tr>
- </thead>
- <tbody>
- <tr><td>Cash: Account Statement:</td><td>Rp. $CashEnding</td></tr>
- <tr><td>Deposit in Transit:</td><td>Rp. $DepTransit</td></tr>
- <tr><td>Outstanding Checks:</td><td>Rp. $OutChecks</td></tr>
- <tr><td>Petty Cash:</td><td>Rp. $PettyCash</td></tr>
- </tbody>
- <tfoot>
- <tr>
- <th>Cash: Bank Statement</th>
- <th>$BankBalance</th>
- </tr>
- </tfoot>
- </table>
- </div>
- <div class="extra">
- Download
- <a href='statements/ReconciliationStatement_$Token.xlsx'><i class="table icon"></i></a>
- </div>
- </div>
- <div class="ui horizontal divider"><i class="anchor icon"></i></div>
- EOT;
- }
- /*------------------------------------------------------------------
- [Check correct balance sheet to view closing button]
- -------------------------------------------------------------------*/
- public function correctBalance($Asset, $Liability, $Equity, $Cash, $CashEnding, $CheckError)
- {
- $Asset = round($Asset, 2);
- $Equity = round($Liability + $Equity, 2);
- $Cash = round($Cash, 2);
- $CashEnding = round($CashEnding, 2);
- if ($Asset == $Equity && $Cash == $CashEnding && $CheckError == "Correct")
- return TRUE;
- else
- return FALSE;
- }
- /*------------------------------------------------------------------
- [Get next month from current month]
- -------------------------------------------------------------------*/
- public function getNextMonth($Month, $Year)
- {
- if ($Month == "Jan")
- $Month = "Feb";
- elseif ($Month == "Feb")
- $Month = "Mar";
- elseif ($Month == "Mar")
- $Month = "Apr";
- elseif ($Month == "Apr")
- $Month = "May";
- elseif ($Month == "May")
- $Month = "Jun";
- elseif ($Month == "Jun")
- $Month = "Jul";
- elseif ($Month == "Jul")
- $Month = "Aug";
- elseif ($Month == "Aug")
- $Month = "Sep";
- elseif ($Month == "Sep")
- $Month = "Oct";
- elseif ($Month == "Oct")
- $Month = "Nov";
- elseif ($Month == "Nov")
- $Month = "Dec";
- elseif ($Month == "Dec") {
- $Month = "Jan";
- $Year = $Year + 1;
- }
- return array(
- $Month,
- $Year
- );
- }
- /*------------------------------------------------------------------
- [Backup database on month closing]
- -------------------------------------------------------------------*/
- public function backupDatabase($Month, $Year)
- {
- $return = "";
- $tables = array('balance','customer','entry','info','records','recurring','reminders');
- if($tables == '*')
- {
- $result = mysqli_query($this->con, 'SHOW TABLES');
- while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
- {
- $tables[] = $row[0];
- }
- }
- else
- {
- $tables = is_array($tables) ? $tables : explode(',',$tables);
- }
- foreach($tables as $table)
- {
- $result = mysqli_query($this->con, 'SELECT * FROM '.$table);
- $num_fields = mysqli_num_fields($result);
- $return.= 'DROP TABLE '.$table.';';
- $row2 = mysqli_fetch_row(mysqli_query($this->con, 'SHOW CREATE TABLE '.$table));
- $return.= "\n\n".$row2[1].";\n\n";
- for ($i = 0; $i < $num_fields; $i++)
- {
- while($row = mysqli_fetch_row($result))
- {
- $return.= 'INSERT INTO '.$table.' VALUES(';
- for($j=0; $j<$num_fields; $j++)
- {
- $row[$j] = addslashes($row[$j]);
- $row[$j] = ereg_replace("\n","\\n",$row[$j]);
- if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
- if ($j<($num_fields-1)) { $return.= ','; }
- }
- $return.= ");\n";
- }
- }
- $return.="\n\n\n";
- }
- $handle = fopen('../../backup/Monthly-backup-'.$Month.'-'.$Year.'.sql','w+');
- fwrite($handle,$return);
- fclose($handle);
- }
- /*------------------------------------------------------------------
- [Insert balance sheet into archive and set info for next month]
- -------------------------------------------------------------------*/
- public function insertArchive()
- {
- $siteQuery = "SELECT * FROM info WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $siteInfo = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $ID = $siteInfo['ID'];
- $Month = $siteInfo['month'];
- $Year = $siteInfo['year'];
- $this->backupDatabase($Month, $Year);
- $siteQuery = "INSERT INTO records
- (ID, month, year, cash, procash, accrecser, preins, preren, building, cashbui, depbui, equipment,
- cashequ, depequ, presup, supplies, cashsup, depsup, unuser, costrevpay, notpay, intpay, equpay,
- salpay, wagpay, telpay, utipay, renpay, suppay, advpay, vatpay, taxpay, legpay, mispay, costrevexp,
- depbuiexp, depequexp, depsupexp, insexp, renexp, salexp, wagexp, telexp, utiexp, advexp, intexp,
- vatexp, taxexp, legexp, misexp, baddebtexp, serrev, intrev, capital, drawing, cashbeginning,
- eqbeginning, progain, deptransit, outchecks, pettycash) select
- ID, month, year, cash, procash, accrecser, preins, preren, building, cashbui, depbui, equipment,
- cashequ, depequ, presup, supplies, cashsup, depsup, unuser, costrevpay, notpay, intpay, equpay,
- salpay, wagpay, telpay, utipay, renpay, suppay, advpay, vatpay, taxpay, legpay, mispay, costrevexp,
- depbuiexp, depequexp, depsupexp, insexp, renexp, salexp, wagexp, telexp, utiexp, advexp, intexp,
- vatexp, taxexp, legexp, misexp, baddebtexp, serrev, intrev, capital, drawing, cashbeginning,
- eqbeginning, progain, deptransit, outchecks, pettycash from balance WHERE Status='Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $siteInfo = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $siteQuery = "SELECT * FROM info WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- $siteInfo = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $ID = $ID + 1;
- list($Month, $Year) = $this->getNextMonth($Month, $Year);
- $siteQuery = "UPDATE info SET month='$Month', year='$Year', ID='$ID' WHERE Status = 'Open'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- $siteQuery = "UPDATE entry SET Status='Off' WHERE Status = 'On'";
- $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
- mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement