Advertisement
Guest User

Untitled

a guest
Sep 6th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 88.63 KB | None | 0 0
  1. <?php
  2. class SummaryClass
  3. {
  4.     private $con;
  5.     private $dbHost = DB_HOST;
  6.     private $dbUser = DB_USER;
  7.     private $dbPassword = DB_PASS;
  8.     private $dbName = DB_NAME;
  9.  
  10.     public function __construct()
  11.     {
  12.         $this->con = mysqli_connect($this->dbHost, $this->dbUser, $this->dbPassword, $this->dbName)
  13.             or die(mysqli_connect_error());
  14.     }
  15.  
  16.     /*------------------------------------------------------------------
  17.     [Select currency symbol]
  18.     -------------------------------------------------------------------*/
  19.  
  20.     public function toCurrency()
  21.     {
  22.         if (strpos($_SESSION['currency'], "dollar") == true)
  23.             return " dollar";
  24.         else if (strpos($_SESSION['currency'], "euro") == true)
  25.             return " euro";
  26.         else if (strpos($_SESSION['currency'], "lira") == true)
  27.             return " lira";
  28.         else if (strpos($_SESSION['currency'], "pound") == true)
  29.             return " pound";
  30.         else if (strpos($_SESSION['currency'], "ruble") == true)
  31.             return " ruble";
  32.         else if (strpos($_SESSION['currency'], "rupee") == true)
  33.             return " rupee";
  34.         else if (strpos($_SESSION['currency'], "won") == true)
  35.             return " won";
  36.         else
  37.             return " yen";
  38.     }
  39.  
  40.     /*------------------------------------------------------------------
  41.     [Convert number to money format with error check]
  42.     -------------------------------------------------------------------*/
  43.  
  44.     public function toMoney($val, $r = 2)
  45.     {
  46.         $symbol = $_SESSION['currency'];
  47.         $n      = $val;
  48.         $c      = is_float($n) ? 1 : number_format($n, $r);
  49.         $d      = '.';
  50.         $t      = ',';
  51.         $sign   = ($n < 0) ? '-' : '';
  52.         $i      = $n = number_format(abs($n), $r);
  53.         $j      = (($j = $i . length) > 3) ? $j % 3 : 0;
  54.         $Mon    = $sign . ($j ? substr($i, 0, $j) + $t : '') . preg_replace('/(\d{3})(?=\d)/', "$1" + $t, substr($i, $j));
  55.         if ($Mon < 0)
  56.             return "<div class='balance-error'>" . $Mon . " " . $symbol . "</div>";
  57.         else
  58.             return $Mon . " " . $symbol;
  59.     }
  60.  
  61.     /*------------------------------------------------------------------
  62.     [Convert number to words]
  63.     -------------------------------------------------------------------*/
  64.     function indo_number($number) {
  65.     return 'Rp ' . number_format($number, 0, ',', '.');
  66. }
  67.  
  68.    
  69.     public function convert_number_to_words($number)
  70.     {
  71.         $hyphen      = '-';
  72.         $conjunction = ' and ';
  73.         $separator   = ', ';
  74.         $negative    = 'negative ';
  75.         $decimal     = ' point ';
  76.         $dictionary  = array(
  77.             0 => 'zero',
  78.             1 => 'one',
  79.             2 => 'two',
  80.             3 => 'three',
  81.             4 => 'four',
  82.             5 => 'five',
  83.             6 => 'six',
  84.             7 => 'seven',
  85.             8 => 'eight',
  86.             9 => 'nine',
  87.             10 => 'ten',
  88.             11 => 'eleven',
  89.             12 => 'twelve',
  90.             13 => 'thirteen',
  91.             14 => 'fourteen',
  92.             15 => 'fifteen',
  93.             16 => 'sixteen',
  94.             17 => 'seventeen',
  95.             18 => 'eighteen',
  96.             19 => 'nineteen',
  97.             20 => 'twenty',
  98.             30 => 'thirty',
  99.             40 => 'fourty',
  100.             50 => 'fifty',
  101.             60 => 'sixty',
  102.             70 => 'seventy',
  103.             80 => 'eighty',
  104.             90 => 'ninety',
  105.             100 => 'hundred',
  106.             1000 => 'thousand',
  107.             1000000 => 'million',
  108.             1000000000 => 'billion',
  109.             1000000000000 => 'trillion',
  110.             1000000000000000 => 'quadrillion',
  111.             1000000000000000000 => 'quintillion'
  112.         );
  113.         if (!is_numeric($number)) {
  114.             return false;
  115.         }
  116.         if (($number >= 0 && (int) $number < 0) || (int) $number < 0 - PHP_INT_MAX) {
  117.             trigger_error('convert_number_to_words only accepts numbers between -' . PHP_INT_MAX
  118.                 . ' and ' . PHP_INT_MAX, E_USER_WARNING);
  119.             return false;
  120.         }
  121.        
  122.         if ($number < 0) {
  123.             return $negative . $this->convert_number_to_words(abs($number));
  124.         }
  125.        
  126.         $string = $fraction = null;
  127.        
  128.         if (strpos($number, '.') !== false) {
  129.             list($number, $fraction) = explode('.', $number);
  130.         }
  131.        
  132.         switch (true) {
  133.             case $number < 21:
  134.                 $string = $dictionary[$number];
  135.                 break;
  136.             case $number < 100:
  137.                 $tens   = ((int) ($number / 10)) * 10;
  138.                 $units  = $number % 10;
  139.                 $string = $dictionary[$tens];
  140.                 if ($units) {
  141.                     $string .= $hyphen . $dictionary[$units];
  142.                 }
  143.                 break;
  144.             case $number < 1000:
  145.                 $hundreds  = $number / 100;
  146.                 $remainder = $number % 100;
  147.                 $string    = $dictionary[$hundreds] . ' ' . $dictionary[100];
  148.                 if ($remainder) {
  149.                     $string .= $conjunction . $this->convert_number_to_words($remainder);
  150.                 }
  151.                 break;
  152.             default:
  153.                 $baseUnit     = pow(1000, floor(log($number, 1000)));
  154.                 $numBaseUnits = (int) ($number / $baseUnit);
  155.                 $remainder    = $number % $baseUnit;
  156.                 $string       = $this->convert_number_to_words($numBaseUnits) . ' ' . $dictionary[$baseUnit];
  157.                 if ($remainder) {
  158.                     $string .= $remainder < 100 ? $conjunction : $separator;
  159.                     $string .= $this->convert_number_to_words($remainder);
  160.                 }
  161.                 break;
  162.         }
  163.         if (null !== $fraction && is_numeric($fraction)) {
  164.             $string .= $decimal;
  165.             $words = array();
  166.             foreach (str_split((string) $fraction) as $number) {
  167.                 $words[] = $dictionary[$number];
  168.             }
  169.             $string .= implode(' ', $words);
  170.         }
  171.        
  172.         return $string;
  173.     }
  174.  
  175.     /*------------------------------------------------------------------
  176.     [Create Income Statement summary]
  177.     -------------------------------------------------------------------*/
  178.  
  179.     public function createIncomeSummary($GrossRev, $TotalExpenses, $Ebitda, $OtherExpenses, $NetIncome)
  180.     {
  181.         $string = "";
  182.         $string = "Total revenue earned for the period is " . $this->convert_number_to_words($GrossRev)
  183.             . $this->toCurrency() . ".";
  184.         $string .= " Total direct expense was " . $this->convert_number_to_words($TotalExpenses * -1) . $this->toCurrency()
  185.             . ", total indirect expense was " . $this->convert_number_to_words($OtherExpenses * -1) . $this->toCurrency()
  186.             . " resulting in net income of " . $this->convert_number_to_words($NetIncome) . $this->toCurrency();
  187.         $string .= " and EBITDA was " . $this->convert_number_to_words($Ebitda) . $this->toCurrency() . ".";
  188.         return $string;
  189.     }
  190.  
  191.     /*------------------------------------------------------------------
  192.     [Create Owners Equity Summary]
  193.     -------------------------------------------------------------------*/
  194.  
  195.     public function createOwnersEquitySummary($Beginning, $Capital, $Drawing, $Income, $Equity)
  196.     {
  197.         $string = "";
  198.         $string = "Total equity at the beginning of the period is " . $this->convert_number_to_words($Beginning)
  199.             . $this->toCurrency() . ".";
  200.         $string .= " Total capital invested was " . $this->convert_number_to_words($Capital) . $this->toCurrency()
  201.             . ", total drawing was " . $this->convert_number_to_words($Drawing * -1) . $this->toCurrency()
  202.             . ", with net income of " . $this->convert_number_to_words($Income) . $this->toCurrency()
  203.             . " resulting in ending equity of " . $this->convert_number_to_words($Equity) . $this->toCurrency() . ".";
  204.         return $string;
  205.     }
  206.  
  207.     /*------------------------------------------------------------------
  208.     [Create Balance Sheet summary]
  209.     -------------------------------------------------------------------*/
  210.  
  211.     public function createBalanceSheetSummary($Cash, $Asset, $Liability, $Equity)
  212.     {
  213.         $string = "";
  214.         $string = "Total asset at the end of the period is " . $this->convert_number_to_words($Asset) . $this->toCurrency()
  215.             . " including total cash " . $this->convert_number_to_words($Cash) . $this->toCurrency() . ".";
  216.         $string .= " Total liability at the end of the period is " . $this->convert_number_to_words($Liability)
  217.             . $this->toCurrency() . " and total equity " . $this->convert_number_to_words($Equity) . $this->toCurrency() . ".";
  218.         return $string;
  219.     }
  220.  
  221.     /*------------------------------------------------------------------
  222.     [Create Cash Flow summary]
  223.     -------------------------------------------------------------------*/
  224.  
  225.     public function createCashFlowSummary($CashOp, $CashInv, $CashFin, $CashBeginning, $CashEnding)
  226.     {
  227.         $string = "";
  228.         $string = "Total cash at the beginning of the period is " . $this->convert_number_to_words($CashBeginning)
  229.             . $this->toCurrency() . ".";
  230.         $string .= " Cash flow for operating activites is " . $this->convert_number_to_words($CashOp) . $this->toCurrency()
  231.             . ", investing activities is " . $this->convert_number_to_words($CashInv) . $this->toCurrency()
  232.             . ", and financing activities is " . $this->convert_number_to_words($CashFin) . $this->toCurrency() . ".";
  233.         $string .= " Total ending cash is " . $this->convert_number_to_words($CashEnding) . $this->toCurrency() . ".";
  234.         return $string;
  235.     }
  236.  
  237.     /*------------------------------------------------------------------
  238.     [Waterfall graph for Income Statement]
  239.     -------------------------------------------------------------------*/
  240.  
  241.     public function incomeWaterFall($graphGrossRev, $graphTotalExpenses, $graphEbitda, $graphOtherExpenses,
  242.         $graphNetIncome)
  243.     {
  244.         $tooltipEbitda = ($graphEbitda < "0" ? "EBITDA (Loss)" : "EBITDA");
  245.         $tooltipIncome = ($graphNetIncome < "0" ? "Net Loss" : "Net Profit");
  246.        
  247.         if ($graphNetIncome < 0)
  248.             $barHeight = $graphGrossRev + abs($graphNetIncome);
  249.         else
  250.             $barHeight = $graphGrossRev;
  251.         if ($graphNetIncome < 0)
  252.             $revenueBottom = number_format(100 - ($graphGrossRev / $barHeight) * 100) . "%";
  253.         else
  254.             $revenueBottom = "0%";
  255.         $revenueHeight         = number_format(($graphGrossRev / $barHeight) * 100) . "%";
  256.         $directExpenseBottom   = number_format(100 - abs($graphTotalExpenses / $barHeight) * 100) . "%";
  257.         $ebitdaBottom          = min(str_replace("%", "", $revenueBottom), str_replace("%", "", $directExpenseBottom)) . "%";
  258.         $ebitdaHeight          = number_format(abs($graphEbitda / $barHeight) * 100) . "%";
  259.         $indirectExpenseHeight = number_format(abs($graphOtherExpenses / $barHeight) * 100) . "%";
  260.         $indirectExpenseBottom = (str_replace("%", "", $ebitdaBottom) + str_replace("%", "", $ebitdaHeight)
  261.             - str_replace("%", "", $indirectExpenseHeight)) . "%";
  262.         if ($graphEbitda < 0)
  263.             $indirectExpenseBottom = (str_replace("%", "", $indirectExpenseBottom) - str_replace("%", "", $ebitdaHeight)) . "%";
  264.         $incomeHeight = number_format(abs($graphNetIncome / $barHeight) * 100) . "%";
  265.         echo <<<EOT
  266.             <div class="bars income-width blue-last tooltip-bottom" title="Gross Revenue"
  267.                 style="bottom:$revenueBottom;left:12.5%;" data-percent="$revenueHeight"></div>
  268.             <div class="bars income-width red-last tooltip-bottom" title="Direct Expenses"
  269.                 style="bottom:$directExpenseBottom;left:25%;" data-percent="100%"></div>
  270.             <div class="bars income-width purple-last tooltip-bottom" title="$tooltipEbitda"
  271.                 style="bottom:$ebitdaBottom;left:37.5%;" data-percent="$ebitdaHeight"></div>
  272.             <div class="bars income-width orange-last tooltip-bottom" title="Indirect Expenses"
  273.                 style="bottom:$indirectExpenseBottom;left:50%;" data-percent="$indirectExpenseHeight"></div>
  274.             <div class="bars income-width brown-last tooltip-bottom" title="$tooltipIncome"
  275.                 style="bottom:0%;left:62.5%;" data-percent="$incomeHeight"></div>
  276. EOT;
  277.     }
  278.  
  279.     /*------------------------------------------------------------------
  280.     [Waterfall graph for Owners Equity Statement]
  281.     -------------------------------------------------------------------*/
  282.  
  283.     public function equityWaterFall($graphBeginning, $graphCapital, $graphDrawing, $graphIncome, $graphEquity)
  284.     {
  285.         $tooltipIncome = ($graphIncome < "0" ? "Net Loss" : "Net Profit");
  286.         $barHeight       = max($graphBeginning, $graphBeginning + $graphCapital, $graphBeginning + $graphCapital
  287.             + $graphDrawing, $graphBeginning + $graphCapital + $graphDrawing + $graphIncome);
  288.         $beginningHeight = number_format(($graphBeginning / $barHeight) * 100) . "%";
  289.         $capitalBottom   = $beginningHeight;
  290.         $capitalHeight   = number_format(($graphCapital / $barHeight) * 100) . "%";
  291.         $drawingHeight = number_format((abs($graphDrawing) / $barHeight) * 100) . "%";
  292.         $drawingBottom = (str_replace("%", "", $capitalBottom) + str_replace("%", "", $capitalHeight)
  293.             - str_replace("%", "", $drawingHeight)) . "%";
  294.         $incomeHeight = number_format((abs($graphIncome) / $barHeight) * 100) . "%";
  295.         if ($graphIncome < 0)
  296.             $incomeBottom = (str_replace("%", "", $drawingBottom) - str_replace("%", "", $incomeHeight)) . "%";
  297.         else
  298.             $incomeBottom = $drawingBottom;
  299.         $equityHeight = number_format((abs($graphEquity) / $barHeight) * 100) . "%";
  300.         echo <<<EOT
  301.             <div class="bars income-width purple-last tooltip-bottom" title="Beginning Equity"
  302.                 style="bottom:0%;left:12.5%;" data-percent="$beginningHeight"></div>
  303.             <div class="bars income-width blue-last tooltip-bottom" title="Investment"
  304.                 style="bottom:$capitalBottom;left:25%;" data-percent="$capitalHeight"></div>
  305.             <div class="bars income-width red-last tooltip-bottom" title="Drawing"
  306.                 style="bottom:$drawingBottom;left:37.5%;" data-percent="$drawingHeight"></div>
  307.             <div class="bars income-width orange-last tooltip-bottom" title="$tooltipIncome"
  308.                 style="bottom:$incomeBottom;left:50%;" data-percent="$incomeHeight"></div>
  309.             <div class="bars income-width brown-last tooltip-bottom" title="Closing Equity"
  310.                 style="bottom:0;left:62.5%;" data-percent="$equityHeight"></div>
  311. EOT;
  312.     }
  313.  
  314.     /*------------------------------------------------------------------
  315.     [Waterfall graph for Balance Sheet]
  316.     -------------------------------------------------------------------*/
  317.  
  318.     public function balanceWaterFall($graphCurrentAsset, $graphNonCurrentAsset, $graphCurrentLiability,
  319.         $graphNonCurrentLiability, $graphEquity)
  320.     {
  321.         $barHeight = max($graphCurrentAsset + $graphNonCurrentAsset, $graphCurrentLiability
  322.             + $graphNonCurrentLiability + $graphEquity);
  323.         $currentAssetBottom    = "0%";
  324.         $currentAssetHeight    = number_format(($graphCurrentAsset / $barHeight) * 100) . "%";
  325.         $nonCurrentAssetBottom = str_replace("%", "", $currentAssetHeight) . "%";
  326.         $nonCurrentAssetHeight = ($graphNonCurrentAsset != 0 ? "100%" : "0%");
  327.         $currentLiabilityBottom = "0%";
  328.         $currentLiabilityHeight = number_format(($graphCurrentLiability / $barHeight) * 100) . "%";
  329.         $nonCurrentLiabilityBottom = str_replace("%", "", $currentLiabilityHeight) . "%";
  330.         $nonCurrentLiabilityHeight = number_format(($graphNonCurrentLiability / $barHeight) * 100) . "%";
  331.         $equityBottom = (str_replace("%", "", $nonCurrentLiabilityHeight)
  332.             + str_replace("%", "", $currentLiabilityHeight)) . "%";
  333.         $equityHeight = ($graphEquity != 0 ? "100%" : "0%");
  334.         echo <<<EOT
  335.             <div class="bars income-width blue-last tooltip-bottom" title="Current Asset"
  336.                 style="bottom:$currentAssetBottom;left:12.5%;" data-percent="$currentAssetHeight"></div>
  337.             <div class="bars income-width red-last tooltip-bottom" title="Non-current Asset"
  338.                 style="bottom:$nonCurrentAssetBottom;left:25%;" data-percent="$nonCurrentAssetHeight"></div>
  339.             <div class="bars income-width purple-last tooltip-bottom" title="Current Liability"
  340.                 style="bottom:$currentLiabilityBottom;left:37.5%;" data-percent="$currentLiabilityHeight"></div>
  341.             <div class="bars income-width orange-last tooltip-bottom" title="Non-current Liability"
  342.                 style="bottom:$nonCurrentLiabilityBottom;left:50%;" data-percent="$nonCurrentLiabilityHeight"></div>
  343.             <div class="bars income-width brown-last tooltip-bottom" title="Total Equity"
  344.                 style="bottom:$equityBottom;left:62.5%;" data-percent="$equityHeight"></div>
  345. EOT;
  346.     }
  347.  
  348.     /*------------------------------------------------------------------
  349.     [Waterfall graph for Cash Flow Statement]
  350.     -------------------------------------------------------------------*/
  351.  
  352.     public function cashWaterFall($graphCash, $graphCashBeginning, $graphCashEnding)
  353.     {
  354.         $tooltipCash = ($graphCash < "0" ? "Less: Cash Outflow" : "Add: Cash Inflow");
  355.         $barHeight = max($graphCashBeginning, $graphCashBeginning + $graphCash);
  356.         $graphCashBeginningBottom = "0%";
  357.         $graphCashBeginningHeight = number_format(($graphCashBeginning / $barHeight) * 100) . "%";
  358.         $graphCashHeight = number_format(abs($graphCash / $barHeight) * 100) . "%";
  359.         if ($graphCash < 0)
  360.             $graphCashBottom = (str_replace("%", "", $graphCashBeginningHeight)
  361.                 - str_replace("%", "", $graphCashHeight)) . "%";
  362.         else
  363.             $graphCashBottom = $graphCashBeginningHeight;
  364.         $graphCashEndingBottom = "0%";
  365.         $graphCashEndingHeight = number_format(($graphCashEnding / $barHeight) * 100) . "%";
  366.         echo <<<EOT
  367.             <div class="bars income-width blue-last tooltip-bottom" title="Cash: Beginning Period"
  368.                 style="bottom:$graphCashBeginningBottom;left:12.5%;" data-percent="$graphCashBeginningHeight"></div>
  369.             <div class="bars income-width purple-last tooltip-bottom" title="$tooltipCash"
  370.                 style="bottom:$graphCashBottom;left:37.5%;" data-percent="$graphCashHeight"></div>
  371.             <div class="bars income-width brown-last tooltip-bottom" title="Cash: Ending Period"
  372.                 style="bottom:$graphCashEndingBottom;left:62.5%;" data-percent="$graphCashEndingHeight"></div>
  373. EOT;
  374.     }
  375.  
  376.     /*------------------------------------------------------------------
  377.     [Preview balance sheet and create excel export]
  378.     -------------------------------------------------------------------*/
  379.  
  380.     public function previewBalanceSheet($Income, $ClosingEquity, $objExcelBalance)
  381.     {
  382.         $Token = strtotime("now");
  383.         $Month = $_SESSION['month'];
  384.         $Year  = $_SESSION['year'];
  385.         $CheckError = "Correct";
  386.         $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
  387.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  388.         $row           = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  389.         $Cash          = round($row['cash'] + $row['procash'], 2);
  390.         $AccReceivable = $row['accrecser'];
  391.         $PreInsurance  = $row['preins'];
  392.         $PreRent       = $row['preren'];
  393.         $PreSupplies   = $row['presup'];
  394.         $Supplies      = $row['supplies'];
  395.         $Building      = $row['building'];
  396.         $Equipment     = $row['equipment'];
  397.         $DepBuilding   = $row['depbui'];
  398.         $DepEquipment  = $row['depequ'];
  399.         $DepSupplies   = $row['depsup'];
  400.         $Asset         = round($Cash + $AccReceivable + $PreInsurance + $PreRent + $PreSupplies + $Supplies + $Equipment
  401.             + $Building - $DepBuilding - $DepEquipment - $DepSupplies, 2);
  402.        
  403.         $CashReturn  = $Cash;
  404.         $AssetReturn = $Asset;
  405.        
  406.         $graphCurrentAsset    = round($row["cash"] + $row["procash"] + $row["accrecser"] + $row["preins"]
  407.             + $row["preren"] + $row["presup"], 2);
  408.         $graphNonCurrentAsset = round($row["supplies"] + $row["equipment"] + $row["building"] - $row["depbui"]
  409.             - $row["depsup"] - $row["depequ"], 2);
  410.        
  411.         if ($Cash < 0 || $AccReceivable < 0 || $PreInsurance < 0 || $PreRent < 0 || $PreSupplies < 0
  412.             || $Supplies < 0 || $Equipment < 0 || $Building < 0 || $DepBuilding < 0 || $DepEquipment < 0
  413.             || $DepSupplies < 0)
  414.             $CheckError = "Error";
  415.        
  416.         $objExcelBalance->getDefaultStyle()->getFont()->setName('Segoe UI');
  417.         $objExcelBalance->getDefaultStyle()->getFont()->setSize(11);
  418.         $objWriter = PHPExcel_IOFactory::createWriter($objExcelBalance, "Excel2007");
  419.         $objSheet  = $objExcelBalance->getActiveSheet();
  420.         $objSheet->setTitle('Balance Sheet');
  421.         $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  422.         $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
  423.         $objSheet->getColumnDimension('A')->setWidth(50);
  424.         $objSheet->getColumnDimension('B')->setWidth(50);
  425.         $objSheet->getStyle('B2:B34')->getNumberFormat()->setFormatCode('#,##0.00');
  426.         $objSheet->mergeCells('A1:B1');
  427.         $objSheet->getCell('A1')->setValue('Statement of Financial Position');
  428.         $objSheet->mergeCells('A2:B2');
  429.         $objSheet->getCell('A2')->setValue('For the month ending ' . $Month . '\'' . $Year);
  430.         $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
  431.         $objSheet->getCell('A3')->setValue('Account');
  432.         $objSheet->getCell('B3')->setValue('Amount');
  433.         $objSheet->getCell('A4')->setValue('Cash');
  434.         $objSheet->getCell('B4')->setValue($Cash);
  435.         $objSheet->getCell('A5')->setValue('Account Reveivable');
  436.         $objSheet->getCell('B5')->setValue($AccReceivable);
  437.         $objSheet->getCell('A6')->setValue('Prepaid Insurance');
  438.         $objSheet->getCell('B6')->setValue($PreInsurance);
  439.         $objSheet->getCell('A7')->setValue('Prepaid Rent');
  440.         $objSheet->getCell('B7')->setValue($PreRent);
  441.         $objSheet->getCell('A8')->setValue('Prepaid Supplies');
  442.         $objSheet->getCell('B8')->setValue($PreSupplies);
  443.         $objSheet->getCell('A9')->setValue('Supplies');
  444.         $objSheet->getCell('B9')->setValue($Supplies);
  445.         $objSheet->getCell('A10')->setValue('Equipment');
  446.         $objSheet->getCell('B10')->setValue($Equipment);
  447.         $objSheet->getCell('A11')->setValue('Building');
  448.         $objSheet->getCell('B11')->setValue($Building);
  449.         $objSheet->getCell('A12')->setValue('Acc. depriciation building');
  450.         $objSheet->getCell('B12')->setValue($DepBuilding * -1);
  451.         $objSheet->getCell('A13')->setValue('Acc. depriciation equipment');
  452.         $objSheet->getCell('B13')->setValue($DepEquipment * -1);
  453.         $objSheet->getCell('A14')->setValue('Acc. depriciation supplies');
  454.         $objSheet->getCell('B14')->setValue($DepSupplies * -1);
  455.         $objSheet->getCell('A15')->setValue('Total Asset');
  456.         $objSheet->getCell('B15')->setValue('=SUM(B4:B14)');
  457.         $objSheet->getStyle('A15:B15')->getFont()->setBold(true)->setSize(11);
  458.  
  459.         $Cash          = $this->toMoney($Cash);
  460.         $AccReceivable = $this->toMoney($AccReceivable);
  461.         $PreInsurance  = $this->toMoney($PreInsurance);
  462.         $PreRent       = $this->toMoney($PreRent);
  463.         $PreSupplies   = $this->toMoney($PreSupplies);
  464.         $Supplies      = $this->toMoney($Supplies);
  465.         $Equipment     = $this->toMoney($Equipment);
  466.         $Building      = $this->toMoney($Building);
  467.         $DepBuilding   = $this->toMoney($DepBuilding);
  468.         $DepEquipment  = $this->toMoney($DepEquipment);
  469.         $DepSupplies   = $this->toMoney($DepSupplies);
  470.         $Asset         = $this->toMoney($Asset);
  471.  
  472.         echo <<<EOT
  473.             <div class="ui card width-full">
  474.                 <div class="content">
  475.                     <div class="header"><i class="cubes icon"></i>Statement of Financial Position</div>
  476.                     <div class="meta">For the month ending $Month'$Year</div>
  477.                     <table class="ui">
  478.                         <thead>
  479.                             <tr>
  480.                                 <th class="summary-width-left"><i class="book icon"></i>Asset</th>
  481.                                 <th class="summary-width-right">Amount</th>
  482.                             </tr>
  483.                         </thead>
  484.                         <tbody>
  485.                             <tr><td>Cash:</td><td>Rp. $Cash</td></tr>
  486.                             <tr><td>Account Reveivable:</td><td>Rp. $AccReceivable</td></tr>
  487.                             <tr><td>Prepaid Insurance:</td><td>Rp. $PreInsurance</td></tr>
  488.                             <tr><td>Prepaid Rent:</td><td>Rp. $PreRent</td></tr>
  489.                             <tr><td>Prepaid Supplies:</td><td>Rp. $PreSupplies</td></tr>
  490.                             <tr><td>Supplies:</td><td>Rp. $Supplies</td></tr>
  491.                             <tr><td>Equipments:</td><td>Rp. $Equipment</td></tr>
  492.                             <tr><td>Building:</td><td>Rp. $Building</td></tr>
  493.                             <tr><td>Acc. depriciation building:</td><td>Rp. $DepBuilding</td></tr>
  494.                             <tr><td>Acc. depriciation equipment:</td><td>Rp. $DepEquipment</td></tr>
  495.                             <tr><td>Acc. depriciation supplies:</td><td>Rp. $DepSupplies</td></tr>
  496.                         </tbody>
  497.                         <tfoot>
  498.                             <tr>
  499.                                 <th>Total Asset:</th>
  500.                                 <th>$Asset</th>
  501.                             </tr>
  502.                         </tfoot>
  503.                     </table>
  504. EOT;
  505.         $UnuRevenue     = $row['unuser'];
  506.         $CostRevPayable = $row['costrevpay'];
  507.         $EquPayable     = $row['equpay'];
  508.         $SalPayable     = $row['salpay'];
  509.         $WagPayable     = $row['wagpay'];
  510.         $TelPayable     = $row['telpay'];
  511.         $UtiPayable     = $row['utipay'];
  512.         $RenPayable     = $row['renpay'];
  513.         $SupPayable     = $row['suppay'];
  514.         $AdvPayable     = $row['advpay'];
  515.         $VatPayable     = $row['vatpay'];
  516.         $TaxPayable     = $row['taxpay'];
  517.         $LegPayable     = $row['legpay'];
  518.         $MisPayable     = $row['mispay'];
  519.         $NotPayable     = $row['notpay'];
  520.         $IntPayable     = $row['intpay'];
  521.         $Liability      = round($UnuRevenue + $CostRevPayable + $EquPayable + $SalPayable + $WagPayable + $TelPayable
  522.             + $UtiPayable + $RenPayable + $SupPayable + $AdvPayable + $VatPayable + $TaxPayable + $LegPayable
  523.             + $MisPayable + $NotPayable + $IntPayable, 2);
  524.        
  525.         $LiabilityReturn = $Liability;
  526.        
  527.         $graphCurrentLiability    = round($row['unuser'] + $row['costrevpay'] + $row['equpay'] + $row['salpay']
  528.             + $row['wagpay'] + $row['telpay'] + $row['utipay'] + $row['renpay'] + $row['suppay'] + $row['advpay']
  529.             + $row['vatpay'] + $row['taxpay'] + $row['legpay'] + $row['mispay'] + $row['intpay'], 2);
  530.         $graphNonCurrentLiability = $row['notpay'];
  531.        
  532.         if ($UnuRevenue < 0 || $CostRevPayable < 0 || $EquPayable < 0 || $SalPayable < 0 || $WagPayable < 0
  533.             || $TelPayable < 0 || $UtiPayable < 0 || $RenPayable < 0 || $SupPayable < 0 || $AdvPayable < 0 || $VatPayable < 0
  534.             || $TaxPayable < 0 || $LegPayable < 0 || $MisPayable < 0 || $NotPayable < 0 || $IntPayable < 0)
  535.             $CheckError = "Error";
  536.        
  537.         $objSheet->getCell('A16')->setValue('Unearned Revenue');
  538.         $objSheet->getCell('B16')->setValue($UnuRevenue);
  539.         $objSheet->getCell('A17')->setValue('Revenue Cost Payable');
  540.         $objSheet->getCell('B17')->setValue($CostRevPayable);
  541.         $objSheet->getCell('A18')->setValue('Equipments Payable');
  542.         $objSheet->getCell('B18')->setValue($EquPayable);
  543.         $objSheet->getCell('A19')->setValue('Salaries Payable');
  544.         $objSheet->getCell('B19')->setValue($SalPayable);
  545.         $objSheet->getCell('A20')->setValue('Wages Payable');
  546.         $objSheet->getCell('B20')->setValue($WagPayable);
  547.         $objSheet->getCell('A21')->setValue('Tel. Bill Payable');
  548.         $objSheet->getCell('B21')->setValue($TelPayable);
  549.         $objSheet->getCell('A22')->setValue('Utility Bill Payable');
  550.         $objSheet->getCell('B22')->setValue($UtiPayable);
  551.         $objSheet->getCell('A23')->setValue('Rent Payable');
  552.         $objSheet->getCell('B23')->setValue($RenPayable);
  553.         $objSheet->getCell('A24')->setValue('Supplies Payable');
  554.         $objSheet->getCell('B24')->setValue($SupPayable);
  555.         $objSheet->getCell('A25')->setValue('Advertisement Payable');
  556.         $objSheet->getCell('B25')->setValue($AdvPayable);
  557.         $objSheet->getCell('A26')->setValue('VAT Payable');
  558.         $objSheet->getCell('B26')->setValue($VatPayable);
  559.         $objSheet->getCell('A27')->setValue('Tax Payable');
  560.         $objSheet->getCell('B27')->setValue($TaxPayable);
  561.         $objSheet->getCell('A28')->setValue('Legal & Admin Payable');
  562.         $objSheet->getCell('B28')->setValue($LegPayable);
  563.         $objSheet->getCell('A29')->setValue('Miscellaneous Payable');
  564.         $objSheet->getCell('B29')->setValue($MisPayable);
  565.         $objSheet->getCell('A30')->setValue('Notes Payable');
  566.         $objSheet->getCell('B30')->setValue($NotPayable);
  567.         $objSheet->getCell('A31')->setValue('Interest Payable');
  568.         $objSheet->getCell('B31')->setValue($IntPayable);
  569.         $objSheet->getCell('A32')->setValue('Total Liabilities');
  570.         $objSheet->getCell('B32')->setValue('=SUM(B16:B31)');
  571.         $objSheet->getStyle('A32:B32')->getFont()->setBold(true)->setSize(11);
  572.        
  573.         $UnuRevenue     = $this->toMoney($UnuRevenue);
  574.         $CostRevPayable = $this->toMoney($CostRevPayable);
  575.         $EquPayable     = $this->toMoney($EquPayable);
  576.         $SalPayable     = $this->toMoney($SalPayable);
  577.         $WagPayable     = $this->toMoney($WagPayable);
  578.         $TelPayable     = $this->toMoney($TelPayable);
  579.         $UtiPayable     = $this->toMoney($UtiPayable);
  580.         $RenPayable     = $this->toMoney($RenPayable);
  581.         $SupPayable     = $this->toMoney($SupPayable);
  582.         $AdvPayable     = $this->toMoney($AdvPayable);
  583.         $VatPayable     = $this->toMoney($VatPayable);
  584.         $TaxPayable     = $this->toMoney($TaxPayable);
  585.         $LegPayable     = $this->toMoney($LegPayable);
  586.         $MisPayable     = $this->toMoney($MisPayable);
  587.         $NotPayable     = $this->toMoney($NotPayable);
  588.         $IntPayable     = $this->toMoney($IntPayable);
  589.         $Liability      = $this->toMoney($Liability);
  590.         echo <<<EOT
  591.                     <table class="ui">
  592.                         <thead>
  593.                             <tr>
  594.                                 <th class="summary-width-left"><i class="book icon"></i>Liability</th>
  595.                                 <th class="summary-width-right">Amount</th>
  596.                             </tr>
  597.                         </thead>
  598.                         <tbody>
  599.                             <tr><td>Unearned Revenue:</td><td>Rp. $UnuRevenue</td></tr>
  600.                             <tr><td>Revenue Cost Payable:</td><td>Rp. $CostRevPayable</td></tr>
  601.                             <tr><td>Equipments Payable:</td><td>Rp. $EquPayable</td></tr>
  602.                             <tr><td>Salaries Payable:</td><td>Rp. $SalPayable</td></tr>
  603.                             <tr><td>Wages Payable:</td><td>Rp. $WagPayable</td></tr>
  604.                             <tr><td>Tel. Bill Payable:</td><td>Rp. $TelPayable</td></tr>
  605.                             <tr><td>Utility Bill Payable:</td><td>Rp. $UtiPayable</td></tr>
  606.                             <tr><td>Rent Payable:</td><td>Rp. $RenPayable</td></tr>
  607.                             <tr><td>Supplies Payable:</td><td>Rp. $SupPayable</td></tr>
  608.                             <tr><td>Advertisement Payable:</td><td>Rp. $AdvPayable</td></tr>
  609.                             <tr><td>VAT Payable:</td><td>Rp. $VatPayable</td></tr>
  610.                             <tr><td>Tax Payable:</td><td>Rp. $TaxPayable</td></tr>
  611.                             <tr><td>Legal & Admin Payable:</td><td>Rp. $LegPayable</td></tr>
  612.                             <tr><td>Miscellaneous Payable:</td><td>Rp. $MisPayable</td></tr>
  613.                             <tr><td>Notes Payable:</td><td>Rp. $NotPayable</td></tr>
  614.                             <tr><td>Interest Payable:</td><td>Rp. $IntPayable</td></tr>
  615.                         </tbody>
  616.                         <tfoot>
  617.                             <tr>
  618.                                 <th>Total Liabilities:</th>
  619.                                 <th>$Liability</th>
  620.                             </tr>
  621.                         </tfoot>
  622.                     </table>
  623. EOT;
  624.         $Equity       = $ClosingEquity;
  625.         $EquityReturn = $Equity;
  626.        
  627.         $graphEquity = $Equity;
  628.        
  629.         if ($Equity < 0)
  630.             $CheckError = "Error";
  631.        
  632.         $objSheet->getCell('A33')->setValue('Equity');
  633.         $objSheet->getCell('B33')->setValue($Equity);
  634.         $objSheet->getCell('A34')->setValue('Total Owners Equity');
  635.         $objSheet->getCell('B34')->setValue('=B33');
  636.         $objSheet->getStyle('A34:B34')->getFont()->setBold(true)->setSize(11);
  637.         $objWriter->save('statements/BalanceSheet' . '_' . $Token . '.xlsx');
  638.        
  639.         $Equity = $this->toMoney($Equity);
  640.         $BalanceSheetSummary = $this->createBalanceSheetSummary($CashReturn, $AssetReturn, $LiabilityReturn, $EquityReturn);
  641.         echo <<<EOT
  642.                     <table class="ui">
  643.                         <thead>
  644.                             <tr>
  645.                                 <th class="summary-width-left"><i class="book icon"></i>Owner's Equity:</th>
  646.                                 <th class="summary-width-right">Amount</th>
  647.                             </tr>
  648.                         </thead>
  649.                         <tbody>
  650.                             <tr><td>Equity:</td><td>Rp. $Equity</td></tr>
  651.                         </tbody>
  652.                         <tfoot>
  653.                             <tr>
  654.                                 <th>Total Owner's Equity:</th>
  655.                                 <th>$Equity</th>
  656.                             </tr>
  657.                         </tfoot>
  658.                     </table>
  659.                     <div class="summary">
  660.                         <div class="description waterfall right">
  661. EOT;
  662.         $this->balanceWaterFall($graphCurrentAsset, $graphNonCurrentAsset, $graphCurrentLiability,
  663.             $graphNonCurrentLiability, $graphEquity);
  664.         echo <<<EOT
  665.                         </div>
  666.                         <div class="description in-words left">
  667.                             Summary: $BalanceSheetSummary
  668.                         </div>
  669.                     </div>
  670.                 </div>
  671.                 <div class="extra">
  672.                     Download
  673.                     <a href='statements/BalanceSheet_$Token.xlsx'><i class="table icon"></i></a>
  674.                 </div>
  675.             </div>
  676.             <div class="ui horizontal divider"><i class="anchor icon"></i></div>
  677. EOT;
  678.         return array(
  679.             $CashReturn,
  680.             $AssetReturn,
  681.             $LiabilityReturn,
  682.             $EquityReturn,
  683.             $CheckError
  684.         );
  685.     }
  686.  
  687.     /*------------------------------------------------------------------
  688.     [Preview owner's equity statement and create excel export]
  689.     -------------------------------------------------------------------*/
  690.  
  691.     public function previewOwnerEquity($Income, $objExcelEquity)
  692.     {
  693.         $Token = strtotime("now");
  694.         $Month = $_SESSION['month'];
  695.         $Year  = $_SESSION['year'];
  696.        
  697.         $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
  698.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  699.         $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  700.        
  701.         $Beginning = $row['eqbeginning'];
  702.         $Capital   = $row['capital'];
  703.         $Drawing   = $row['drawing'];
  704.         $Equity    = $Beginning + $Capital + $Drawing + $Income;
  705.        
  706.         $graphBeginning = $Beginning;
  707.         $graphCapital   = $Capital;
  708.         $graphDrawing   = $Drawing;
  709.         $graphIncome    = $Income;
  710.         $graphEquity    = $Equity;
  711.        
  712.         $OwnersEquitySummary = $this->createOwnersEquitySummary($Beginning, $Capital, $Drawing, $Income, $Equity);
  713.         $EquityReturn        = $Equity;
  714.         $SignIncome          = ($Income < "0" ? "Less: Net Loss:" : "Add: Net Income:");
  715.        
  716.         $objExcelEquity->getDefaultStyle()->getFont()->setName('Segoe UI');
  717.         $objExcelEquity->getDefaultStyle()->getFont()->setSize(11);
  718.         $objWriter = PHPExcel_IOFactory::createWriter($objExcelEquity, "Excel2007");
  719.         $objSheet  = $objExcelEquity->getActiveSheet();
  720.         $objSheet->setTitle('Owners Equity Statement');
  721.         $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  722.         $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
  723.         $objSheet->getColumnDimension('A')->setWidth(50);
  724.         $objSheet->getColumnDimension('B')->setWidth(50);
  725.         $objSheet->getStyle('B2:B8')->getNumberFormat()->setFormatCode('#,##0.00');
  726.         $objSheet->mergeCells('A1:B1');
  727.         $objSheet->getCell('A1')->setValue('Statement of Owners Equity');
  728.         $objSheet->mergeCells('A2:B2');
  729.         $objSheet->getCell('A2')->setValue('For the month of ' . $Month . '\'' . $Year);
  730.         $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
  731.         $objSheet->getCell('A3')->setValue('Account');
  732.         $objSheet->getCell('B3')->setValue('Amount');
  733.         $objSheet->getCell('A4')->setValue('Equity at Beginning');
  734.         $objSheet->getCell('B4')->setValue($Beginning);
  735.         $objSheet->getCell('A5')->setValue('Investment');
  736.         $objSheet->getCell('B5')->setValue($Capital);
  737.         $objSheet->getCell('A6')->setValue('Less: Drawing');
  738.         $objSheet->getCell('B6')->setValue($Drawing);
  739.         $objSheet->getCell('A7')->setValue($SignIncome);
  740.         $objSheet->getCell('B7')->setValue($Income);
  741.         $objSheet->getCell('A8')->setValue('Total Owners Equity Closing');
  742.         $objSheet->getCell('B8')->setValue('=B4+B5+B6+B7');
  743.         $objSheet->getStyle('A8:B8')->getFont()->setBold(true)->setSize(11);
  744.        
  745.         $objWriter->save('statements/OwnersEquityStatement' . '_' . $Token . '.xlsx');
  746.        
  747.         $Beginning = $this->toMoney($Beginning);
  748.         $Capital   = $this->toMoney($Capital);
  749.         $Drawing   = $this->toMoney($Drawing * -1);
  750.         $Income    = $this->toMoney(abs($Income));
  751.         $Equity    = $this->toMoney($Equity);
  752.        
  753.         echo <<<EOT
  754.             <div class="ui card width-full">
  755.                 <div class="content">
  756.                     <div class="header"><i class="cubes icon"></i>Statement of Owner's Equity</div>
  757.                     <div class="meta">For the month of $Month'$Year</div>
  758.                     <table class="ui">
  759.                         <thead>
  760.                             <tr>
  761.                                 <th class="summary-width-left"><i class="book icon"></i>Equity</th>
  762.                                 <th class="summary-width-right">Amount</th>
  763.                             </tr>
  764.                         </thead>
  765.                         <tbody>
  766.                             <tr><td>Equity at Beginning:</td><td>Rp. $Beginning</td></tr>
  767.                             <tr><td>Investment:</td><td>$Capital</td></tr>
  768.                             <tr><td>Less: Drawing:</td><td>$Drawing</td></tr>
  769.                             <tr><td>$SignIncome</td><td>Rp. $Income</td></tr>
  770.                         </tbody>
  771.                         <tfoot>
  772.                             <tr>
  773.                                 <th>Total Owner's Equity Closing:</th>
  774.                                 <th>$Equity</th>
  775.                             </tr>
  776.                         </tfoot>
  777.                     </table>
  778.                     <div class="summary">
  779.                         <div class="description waterfall left">
  780. EOT;
  781.         $this->equityWaterFall($graphBeginning, $graphCapital, $graphDrawing, $graphIncome, $graphEquity);
  782.         echo <<<EOT
  783.                         </div>
  784.                         <div class="description in-words right">
  785.                             Summary: $OwnersEquitySummary
  786.                         </div>
  787.                     </div>
  788.                 </div>
  789.                 <div class="extra">
  790.                     Download
  791.                     <a href='statements/OwnersEquityStatement_$Token.xlsx'><i class="table icon"></i></a>
  792.                 </div>
  793.             </div>
  794.             <div class="ui horizontal divider"><i class="anchor icon"></i></div>
  795. EOT;
  796.         return array(
  797.             $EquityReturn
  798.         );
  799.     }
  800.  
  801.     /*------------------------------------------------------------------
  802.     [Preview income statement and create excel export]
  803.     -------------------------------------------------------------------*/
  804.  
  805.     public function previewIncomeStatement($objExcelIncome)
  806.     {
  807.         $Token = strtotime("now");
  808.         $Month = $_SESSION['month'];
  809.         $Year  = $_SESSION['year'];
  810.        
  811.         $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
  812.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  813.         $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  814.        
  815.         $ServiceRev       = $row['serrev'];
  816.         $InterestRev      = $row['intrev'];
  817.         $ProGain          = $row['progain'];
  818.         $CostRevExp       = $row['costrevexp'];
  819.         $SalaryExp        = $row['salexp'];
  820.         $WagesExp         = $row['wagexp'];
  821.         $RentExp          = $row['renexp'];
  822.         $InsuranceExp     = $row['insexp'];
  823.         $TelephoneExp     = $row['telexp'];
  824.         $UtilityExp       = $row['utiexp'];
  825.         $AdvertisementExp = $row['advexp'];
  826.         $InterestExp      = $row['intexp'];
  827.         $VatExp           = $row['vatexp'];
  828.         $TaxExp           = $row['taxexp'];
  829.         $LegExp           = $row['legexp'];
  830.         $MisExp           = $row['misexp'];
  831.         $BadExp           = $row['baddebtexp'];
  832.         $DepBuilding      = $row['depbuiexp'];
  833.         $DepEquipment     = $row['depequexp'];
  834.         $DepSupplies      = $row['depsupexp'];
  835.        
  836.         $GrossRev      = round($ServiceRev + $InterestRev + $ProGain, 2);
  837.         $TotalExpenses = round($CostRevExp + $SalaryExp + $WagesExp + $RentExp + $InsuranceExp + $TelephoneExp
  838.             + $UtilityExp + $AdvertisementExp + $MisExp + $LegExp + $BadExp, 2);
  839.         $Ebitda        = round($GrossRev + $TotalExpenses, 2);
  840.         $OtherExpenses = round($InterestExp + $VatExp + $TaxExp + $DepBuilding + $DepEquipment + $DepSupplies, 2);
  841.         $NetIncome     = round($Ebitda + $OtherExpenses, 2);
  842.        
  843.         $graphGrossRev      = $GrossRev;
  844.         $graphTotalExpenses = $TotalExpenses;
  845.         $graphEbitda        = $Ebitda;
  846.         $graphOtherExpenses = $OtherExpenses;
  847.         $graphNetIncome     = $NetIncome;
  848.        
  849.         $IncomeStatementSummary = $this->createIncomeSummary($GrossRev, $TotalExpenses, $Ebitda, $OtherExpenses, $NetIncome);
  850.         $IncomeReturn           = $NetIncome;
  851.        
  852.         $SignEbitda    = ($Ebitda < "0" ? "EBITDA (Loss):" : "EBITDA:");
  853.         $SignNetIncome = ($NetIncome < "0" ? "Net Loss:" : "Net Income:");
  854.        
  855.         $objExcelIncome->getDefaultStyle()->getFont()->setName('Segoe UI');
  856.         $objExcelIncome->getDefaultStyle()->getFont()->setSize(11);
  857.         $objWriter = PHPExcel_IOFactory::createWriter($objExcelIncome, "Excel2007");
  858.         $objSheet  = $objExcelIncome->getActiveSheet();
  859.         $objSheet->setTitle('Income Statement');
  860.         $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  861.         $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
  862.         $objSheet->getColumnDimension('A')->setWidth(50);
  863.         $objSheet->getColumnDimension('B')->setWidth(50);
  864.         $objSheet->getStyle('B2:B50')->getNumberFormat()->setFormatCode('#,##0.00');
  865.         $objSheet->mergeCells('A1:B1');
  866.         $objSheet->getCell('A1')->setValue('Income Statement');
  867.         $objSheet->mergeCells('A2:B2');
  868.         $objSheet->getCell('A2')->setValue('For the month of ' . $Month . '\'' . $Year);
  869.         $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
  870.         $objSheet->getCell('A3')->setValue('Account');
  871.         $objSheet->getCell('B3')->setValue('Amount');
  872.         $objSheet->getCell('A4')->setValue('Service Revenue');
  873.         $objSheet->getCell('B4')->setValue($ServiceRev);
  874.         $objSheet->getCell('A5')->setValue('Interest Revenue');
  875.         $objSheet->getCell('B5')->setValue($InterestRev);
  876.         $objSheet->getCell('A6')->setValue('Gain/loss of sales');
  877.         $objSheet->getCell('B6')->setValue($ProGain);
  878.         $objSheet->getCell('A7')->setValue('Gross Revenue');
  879.         $objSheet->getCell('B7')->setValue('=SUM(B4:B6)');
  880.         $objSheet->getStyle('A7:B7')->getFont()->setBold(true)->setSize(11);
  881.         $objSheet->getCell('A8')->setValue('Cost of Revenue');
  882.         $objSheet->getCell('B8')->setValue($CostRevExp * -1);
  883.         $objSheet->getCell('A9')->setValue('Salaries Expenses');
  884.         $objSheet->getCell('B9')->setValue($SalaryExp * -1);
  885.         $objSheet->getCell('A10')->setValue('Wages Expenses');
  886.         $objSheet->getCell('B10')->setValue($WagesExp * -1);
  887.         $objSheet->getCell('A11')->setValue('Rent Expenses');
  888.         $objSheet->getCell('B11')->setValue($RentExp * -1);
  889.         $objSheet->getCell('A12')->setValue('Insurance Expenses');
  890.         $objSheet->getCell('B12')->setValue($InsuranceExp * -1);
  891.         $objSheet->getCell('A13')->setValue('Telephone Expenses');
  892.         $objSheet->getCell('B13')->setValue($TelephoneExp * -1);
  893.         $objSheet->getCell('A14')->setValue('Utility Expenses');
  894.         $objSheet->getCell('B14')->setValue($UtilityExp * -1);
  895.         $objSheet->getCell('A15')->setValue('Advertisement Expenses');
  896.         $objSheet->getCell('B15')->setValue($AdvertisementExp * -1);
  897.         $objSheet->getCell('A16')->setValue('Legal & Admin Expenses');
  898.         $objSheet->getCell('B16')->setValue($LegExp * -1);
  899.         $objSheet->getCell('A17')->setValue('Miscellaneous Expenses');
  900.         $objSheet->getCell('B17')->setValue($MisExp * -1);
  901.         $objSheet->getCell('A18')->setValue('Bad Debt Expense');
  902.         $objSheet->getCell('B18')->setValue($BadExp * -1);
  903.         $objSheet->getCell('A19')->setValue('Total Direct Expenses');
  904.         $objSheet->getCell('B19')->setValue('=SUM(B8:B18)');
  905.         $objSheet->getStyle('A19:B19')->getFont()->setBold(true)->setSize(11);
  906.         $objSheet->getCell('A20')->setValue($SignEbitda);
  907.         $objSheet->getCell('B20')->setValue('=B7-B19');
  908.         $objSheet->getStyle('A20:B20')->getFont()->setBold(true)->setSize(11);
  909.         $objSheet->getCell('A21')->setValue('Dep. Expense Building');
  910.         $objSheet->getCell('B21')->setValue($DepBuilding * -1);
  911.         $objSheet->getCell('A22')->setValue('Dep. Expense Equipment');
  912.         $objSheet->getCell('B22')->setValue($DepEquipment * -1);
  913.         $objSheet->getCell('A23')->setValue('Dep. Expenses Supplies');
  914.         $objSheet->getCell('B23')->setValue($DepSupplies * -1);
  915.         $objSheet->getCell('A24')->setValue('Interest Expenses');
  916.         $objSheet->getCell('B24')->setValue($InterestExp * -1);
  917.         $objSheet->getCell('A25')->setValue('VAT Expenses');
  918.         $objSheet->getCell('B25')->setValue($VatExp * -1);
  919.         $objSheet->getCell('A26')->setValue('Tax Expenses');
  920.         $objSheet->getCell('B26')->setValue($TaxExp * -1);
  921.         $objSheet->getCell('A27')->setValue('Other Expenses');
  922.         $objSheet->getCell('B27')->setValue('=SUM(B21:B26)');
  923.         $objSheet->getStyle('A27:B27')->getFont()->setBold(true)->setSize(11);
  924.         $objSheet->getCell('A28')->setValue($SignNetIncome);
  925.         $objSheet->getCell('B28')->setValue('=B7-B19-B27');
  926.         $objSheet->getStyle('A28:B28')->getFont()->setBold(true)->setSize(11);
  927.         $objWriter->save('statements/IncomeStatement' . '_' . $Token . '.xlsx');
  928.        
  929.         $ServiceRev       = $this->toMoney($ServiceRev);
  930.         $InterestRev      = $this->toMoney($InterestRev);
  931.         $ProGain          = $this->toMoney($ProGain);
  932.         $CostRevExp       = $this->toMoney($CostRevExp * -1);
  933.         $SalaryExp        = $this->toMoney($SalaryExp * -1);
  934.         $WagesExp         = $this->toMoney($WagesExp * -1);
  935.         $RentExp          = $this->toMoney($RentExp * -1);
  936.         $InsuranceExp     = $this->toMoney($InsuranceExp * -1);
  937.         $TelephoneExp     = $this->toMoney($TelephoneExp * -1);
  938.         $UtilityExp       = $this->toMoney($UtilityExp * -1);
  939.         $AdvertisementExp = $this->toMoney($AdvertisementExp * -1);
  940.         $MisExp           = $this->toMoney($MisExp * -1);
  941.         $InterestExp      = $this->toMoney($InterestExp * -1);
  942.         $VatExp           = $this->toMoney($VatExp * -1);
  943.         $TaxExp           = $this->toMoney($TaxExp * -1);
  944.         $LegExp           = $this->toMoney($LegExp * -1);
  945.         $BadExp           = $this->toMoney($BadExp * -1);
  946.         $DepBuilding      = $this->toMoney($DepBuilding * -1);
  947.         $DepEquipment     = $this->toMoney($DepEquipment * -1);
  948.         $DepSupplies      = $this->toMoney($DepSupplies * -1);
  949.         $GrossRev         = $this->toMoney($GrossRev);
  950.         $TotalExpenses    = $this->toMoney($TotalExpenses * -1);
  951.         $Ebitda           = $this->toMoney(abs($Ebitda));
  952.         $OtherExpenses    = $this->toMoney($OtherExpenses * -1);
  953.         $NetIncome        = $this->toMoney(abs($NetIncome));
  954.         echo <<<EOT
  955.             <div class="ui card width-full">
  956.                 <div class="content">
  957.                     <div class="header"><i class="cubes icon"></i>Income Statement</div>
  958.                     <div class="meta">For the month of $Month'$Year</div>
  959.                     <table class="ui">
  960.                         <thead>
  961.                             <tr>
  962.                                 <th class="summary-width-left"><i class="book icon"></i>Gross Revenue</th>
  963.                                 <th class="summary-width-right"><i class="book icon"></i>Amount</th>
  964.                             </tr>
  965.                         </thead>
  966.                         <tbody>
  967.                             <tr><td>Service Revenue:</td><td>Rp. $ServiceRev</td></tr>
  968.                             <tr><td>Interest Revenue:</td><td>Rp. $InterestRev</td></tr>
  969.                             <tr><td>Gain/Loss on Asset Sales:</td><td>Rp. $ProGain</td></tr>
  970.                         </tbody>
  971.                         <tfoot>
  972.                             <tr>
  973.                                 <th>Gross Revenue:</th>
  974.                                 <th>$GrossRev</th>
  975.                             </tr>
  976.                         </tfoot>
  977.                     </table>
  978. EOT;
  979.         echo <<<EOT
  980.                     <table class="ui">
  981.                         <thead>
  982.                             <tr>
  983.                                 <th class="summary-width-left"><i class="book icon"></i>Direct Expense</th>
  984.                                 <th class="summary-width-right">Amount</th>
  985.                             </tr>
  986.                         </thead>
  987.                         <tbody>
  988.                             <tr><td>Cost of Revenue:</td><td>Rp. $CostRevExp</td></tr>
  989.                             <tr><td>Salaries Expense:</td><td>Rp. $SalaryExp</td></tr>
  990.                             <tr><td>Wages Expense:</td><td>Rp. $WagesExp</td></tr>
  991.                             <tr><td>Rent Expense:</td><td>Rp. $RentExp</td></tr>
  992.                             <tr><td>Insurance Expense:</td><td>Rp. $InsuranceExp</td></tr>
  993.                             <tr><td>Telephone Expense:</td><td>Rp. $TelephoneExp</td></tr>
  994.                             <tr><td>Utility Expense:</td><td>Rp. $UtilityExp</td></tr>
  995.                             <tr><td>Advertisement Expense:</td><td>Rp. $AdvertisementExp</td></tr>
  996.                             <tr><td>Legal & Admin Expense:</td><td>Rp. $LegExp</td></tr>
  997.                             <tr><td>Miscellaneous Expense:</td><td>Rp. $MisExp</td></tr>
  998.                             <tr><td>Bad Det Expense:</td><td>Rp. $BadExp</td></tr>
  999.                         </tbody>
  1000.                         <tfoot>
  1001.                             <tr>
  1002.                                 <th>Total Direct Expense:</th>
  1003.                                 <th>$TotalExpenses</th>
  1004.                             </tr>
  1005.                             <tr>
  1006.                                 <th>$SignEbitda</th>
  1007.                                 <th>$Ebitda</th>
  1008.                             </tr>
  1009.                         </tfoot>
  1010.                     </table>
  1011. EOT;
  1012.         echo <<<EOT
  1013.                     <table class="ui">
  1014.                         <thead>
  1015.                             <tr>
  1016.                                 <th class="summary-width-left"><i class="book icon"></i>Other Expense</th>
  1017.                                 <th class="summary-width-right">Amount</th>
  1018.                             </tr>
  1019.                         </thead>
  1020.                         <tbody>
  1021.                             <tr><td>Dep. Expense Building:</td><td>Rp. $DepBuilding</td></tr>
  1022.                             <tr><td>Dep. Expense Equipment:</td><td>Rp. $DepEquipment</td></tr>
  1023.                             <tr><td>Dep. Expense Supplies:</td><td>Rp. $DepSupplies</td></tr>
  1024.                             <tr><td>Interest Expense:</td><td>Rp. $InterestExp</td></tr>
  1025.                             <tr><td>VAT Expense:</td><td>Rp. $VatExp</td></tr>
  1026.                             <tr><td>Tax Expense:</td><td>Rp. $TaxExp</td></tr>
  1027.                         </tbody>
  1028.                         <tfoot>
  1029.                             <tr>
  1030.                                 <th>Other Expenses:</th>
  1031.                                 <th>$OtherExpenses</th>
  1032.                             </tr>
  1033.                             <tr>
  1034.                                 <th>$SignNetIncome</th>
  1035.                                 <th>$NetIncome</th>
  1036.                             </tr>
  1037.                         </tfoot>
  1038.                     </table>
  1039.                     <div class="summary">
  1040.                         <div class="description waterfall right">
  1041. EOT;
  1042.         $this->incomeWaterFall($graphGrossRev, $graphTotalExpenses, $graphEbitda, $graphOtherExpenses, $graphNetIncome);
  1043.         echo <<<EOT
  1044.                         </div>
  1045.                         <div class="description in-words left">
  1046.                             Summary: $IncomeStatementSummary
  1047.                         </div>
  1048.                     </div>
  1049.                 </div>
  1050.                 <div class="extra">
  1051.                     Download
  1052.                     <a href='statements/IncomeStatement_$Token.xlsx'><i class="table icon"></i></a>
  1053.                 </div>
  1054.             </div>
  1055.             <div class="ui horizontal divider"><i class="anchor icon"></i></div>
  1056. EOT;
  1057.         return array(
  1058.             $IncomeReturn
  1059.         );
  1060.     }
  1061.  
  1062.     /*------------------------------------------------------------------
  1063.     [Preview cash flow statement and create excel export]
  1064.     -------------------------------------------------------------------*/
  1065.  
  1066.     public function previewCashFlowStatement($Income, $objExcelCash)
  1067.     {
  1068.         $Token = strtotime("now");
  1069.         $Month = $_SESSION['month'];
  1070.         $Year  = $_SESSION['year'];
  1071.        
  1072.         $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
  1073.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1074.         $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1075.         $ID  = $_SESSION['id'];
  1076.         if ($ID == '1') {
  1077.             $ProGain        = $row['progain'];
  1078.             $DepBuilding    = $row['depbuiexp'];
  1079.             $DepEquipment   = $row['depequexp'];
  1080.             $DepSupplies    = $row['depsupexp'];
  1081.             $UnuRevenue     = $row['unuser'];
  1082.             $AccReceivable  = $row['accrecser'];
  1083.             $CostRevPayable = $row['costrevpay'];
  1084.             $SalPayable     = $row['salpay'];
  1085.             $WagPayable     = $row['wagpay'];
  1086.             $TelPayable     = $row['telpay'];
  1087.             $UtiPayable     = $row['utipay'];
  1088.             $RenPayable     = $row['renpay'];
  1089.             $AdvPayable     = $row['advpay'];
  1090.             $VatPayable     = $row['vatpay'];
  1091.             $TaxPayable     = $row['taxpay'];
  1092.             $LegPayable     = $row['legpay'];
  1093.             $MisPayable     = $row['mispay'];
  1094.             $ProCash      = $row['procash'];
  1095.             $PreInsurance = $row['preins'];
  1096.             $PreRent      = $row['preren'];
  1097.             $PreSupplies  = $row['presup'];
  1098.             $BuiPurchase  = $row['cashbui'];
  1099.             $EquPurchase  = $row['cashequ'];
  1100.             $SupPurchase  = $row['cashsup'];
  1101.             $NotesPayable = $row['notpay'];
  1102.             $IntPayable   = $row['intpay'];
  1103.             $Capital = $row['capital'];
  1104.             $Drawing = $row['drawing'];
  1105.         }
  1106.         else {
  1107.             $siteQuery = "SELECT * FROM records ORDER BY ID DESC LIMIT 1";
  1108.             $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1109.             $lastBalance = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1110.            
  1111.             $ProGain        = $row['progain'];
  1112.             $DepBuilding    = $row['depbuiexp'];
  1113.             $DepEquipment   = $row['depequexp'];
  1114.             $DepSupplies    = $row['depsupexp'];
  1115.             $UnuRevenue     = round($row['unuser'] - $lastBalance['unuser'], 2);
  1116.             $AccReceivable  = round($row['accrecser'] - $lastBalance['accrecser'], 2);
  1117.             $CostRevPayable = round($row['costrevpay'] - $lastBalance['costrevpay'], 2);
  1118.             $SalPayable     = round($row['salpay'] - $lastBalance['salpay'], 2);
  1119.             $WagPayable     = round($row['wagpay'] - $lastBalance['wagpay'], 2);
  1120.             $TelPayable     = round($row['telpay'] - $lastBalance['telpay'], 2);
  1121.             $UtiPayable     = round($row['utipay'] - $lastBalance['utipay'], 2);
  1122.             $RenPayable     = round($row['renpay'] - $lastBalance['renpay'], 2);
  1123.             $AdvPayable     = round($row['advpay'] - $lastBalance['advpay'], 2);
  1124.             $VatPayable     = round($row['vatpay'] - $lastBalance['vatpay'], 2);
  1125.             $TaxPayable     = round($row['taxpay'] - $lastBalance['taxpay'], 2);
  1126.             $LegPayable     = round($row['legpay'] - $lastBalance['legpay'], 2);
  1127.             $MisPayable     = round($row['mispay'] - $lastBalance['mispay'], 2);
  1128.             $ProCash      = $row['procash'];
  1129.             $PreInsurance = round($row['preins'] - $lastBalance['preins'], 2);
  1130.             $PreRent      = round($row['preren'] - $lastBalance['preren'], 2);
  1131.             $PreSupplies  = round($row['presup'] - $lastBalance['presup'], 2);
  1132.             $BuiPurchase  = $row['cashbui'];
  1133.             $EquPurchase  = $row['cashequ'];
  1134.             $SupPurchase  = $row['cashsup'];
  1135.             $NotesPayable = round($row['notpay'] - $lastBalance['notpay'], 2);
  1136.             $IntPayable   = round($row['intpay'] - $lastBalance['intpay'], 2);
  1137.             $Capital = $row['capital'];
  1138.             $Drawing = $row['drawing'];
  1139.         }
  1140.        
  1141.         $CashOp           = round($Income - $ProGain - $DepBuilding - $DepEquipment - $DepSupplies + $UnuRevenue
  1142.             - $AccReceivable + $CostRevPayable + $SalPayable + $WagPayable + $TelPayable + $UtiPayable + $RenPayable
  1143.             + $AdvPayable + $VatPayable + $TaxPayable + $LegPayable + $MisPayable + $IntPayable, 2);
  1144.         $CashInv          = round($NotesPayable - ($PreInsurance + $PreRent + $PreSupplies + $BuiPurchase + $EquPurchase + $SupPurchase)
  1145.             + $ProCash, 2);
  1146.         $CashFin          = round($Capital + $Drawing, 2);
  1147.         $CashBeginning    = $row['cashbeginning'];
  1148.         $CashEnding       = round($CashBeginning + $CashOp + $CashInv + $CashFin, 2);
  1149.         $CashEndingReturn = $CashEnding;
  1150.        
  1151.         $graphCash          = round($CashOp + $CashInv + $CashFin, 2);
  1152.         $graphCashBeginning = $CashBeginning;
  1153.         $graphCashEnding    = $CashEnding;
  1154.        
  1155.         $CashFlowSummary = $this->createCashFlowSummary($CashOp, $CashInv, $CashFin, $CashBeginning, $CashEnding);
  1156.        
  1157.         $SignIncome         = ($Income < "0" ? "Less: Net Loss:" : "Add: Net Income:");
  1158.         $SignProGain        = ($ProGain < "0" ? "Add: Loss on Asset Sale:" : "Less: Gain on Asset Sale:");
  1159.         $SignAccReceivable  = ($AccReceivable < "0" ? "Add: Decr. in Account Receivable:" : "Less: Incr. in Account Receivable:");
  1160.         $SignUnuRevenue     = ($UnuRevenue < "0" ? "Less: Decr. in Unearned Revenue:" : "Add: Incr. in Unearned Revenue:");
  1161.         $SignCostRevPayable = ($CostRevPayable < "0" ? "Less: Decr. in Revenue Cost Payable:" : "Add: Incr. in Revenue Cost Payable:");
  1162.         $SignSalPayable     = ($SalPayable < "0" ? "Less: Decr. in Salaries Payable:" : "Add: Incr. in Salaries Payable:");
  1163.         $SignWagPayable     = ($WagPayable < "0" ? "Less: Decr. in Wages payable:" : "Add: Incr. in Wages payable:");
  1164.         $SignTelPayable     = ($TelPayable < "0" ? "Less: Decr. in Tel. Bill Payable:" : "Add: Incr. in Tel. Bill Payable:");
  1165.         $SignUtiPayable     = ($UtiPayable < "0" ? "Less: Decr. in Util. Bill Payable:" : "Add: Incr. in Util. Bill Payable:");
  1166.         $SignRenPayable     = ($RenPayable < "0" ? "Less: Decr. in Rent Payable:" : "Add: Incr. in Rent Payable:");
  1167.         $SignAdvPayable     = ($AdvPayable < "0" ? "Less: Decr. in Adv. Payable:" : "Add: Incr. in Adv. Payable:");
  1168.         $SignIntPayable     = ($IntPayable < "0" ? "Less: Decr. in Interest Payable:" : "Add: Incr. in Interest Payable:");
  1169.         $SignVatPayable     = ($VatPayable < "0" ? "Less: Decr. in VAT Payable:" : "Add: Incr. in VAT Payable:");
  1170.         $SignTaxPayable     = ($TaxPayable < "0" ? "Less: Decr. in Tax Payable:" : "Add: Incr. in Tax Payable:");
  1171.         $SignLegPayable     = ($LegPayable < "0" ? "Less: Decr. in Legal & Admin Payable:" : "Add: Incr. in Legal & Admin Payable:");
  1172.         $SignMisPayable     = ($MisPayable < "0" ? "Less: Decr. in Misc. Payable:" : "Add: Incr. in Misc. Payable:");
  1173.         $SignPreInsurance   = ($PreInsurance < "0" ? "Less: Decr. in Prepaid Insurance:" : "Add: Incr. in Prepaid Insurance:");
  1174.         $SignPreRent        = ($PreRent < "0" ? "Less: Decr. in Prepaid Rent:" : "Add: Incr. in Prepaid Rent:");
  1175.         $SignPreSupplies    = ($PreSupplies < "0" ? "Less: Decr. in Prepaid Supplies:" : "Add: Incr. in Prepaid Supplies:");
  1176.         $SignNotesPayable   = ($NotesPayable < "0" ? "Less: Decr. in Notes Payable:" : "Add: Incr. in Notes Payable:");
  1177.         $SignCashOp         = ($CashOp < "0" ? "Less: Cash from Operating Activities:" : "Add: Cash from Operating Activities:");
  1178.         $SignCashInv        = ($CashInv < "0" ? "Less: Cash from Investing Activities:" : "Add: Cash from Investing Activities:");
  1179.         $SignCashFin        = ($CashFin < "0" ? "Less: Cash from Financing Activities:" : "Add: Cash from Financing Activities:");
  1180.        
  1181.         $objExcelCash->getDefaultStyle()->getFont()->setName('Segoe UI');
  1182.         $objExcelCash->getDefaultStyle()->getFont()->setSize(11);
  1183.         $objWriter = PHPExcel_IOFactory::createWriter($objExcelCash, "Excel2007");
  1184.         $objSheet  = $objExcelCash->getActiveSheet();
  1185.         $objSheet->setTitle('Income Statement');
  1186.         $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1187.         $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
  1188.         $objSheet->getColumnDimension('A')->setWidth(50);
  1189.         $objSheet->getColumnDimension('B')->setWidth(50);
  1190.         $objSheet->getStyle('B2:B50')->getNumberFormat()->setFormatCode('#,##0.00');
  1191.         $objSheet->mergeCells('A1:B1');
  1192.         $objSheet->getCell('A1')->setValue('Statement of Cash Flow');
  1193.         $objSheet->mergeCells('A2:B2');
  1194.         $objSheet->getCell('A2')->setValue('For the month of ' . $Month . '\'' . $Year);
  1195.         $objSheet->getCell('A3')->setValue('Account');
  1196.         $objSheet->getCell('B3')->setValue('Amount');
  1197.         $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
  1198.         $objSheet->getCell('A4')->setValue($SignIncome);
  1199.         $objSheet->getCell('B4')->setValue($Income);
  1200.         $objSheet->getCell('A5')->setValue($SignAccReceivable);
  1201.         $objSheet->getCell('B5')->setValue($AccReceivable);
  1202.         $objSheet->getCell('A6')->setValue($SignProGain);
  1203.         $objSheet->getCell('B6')->setValue($ProGain);
  1204.         $objSheet->getCell('A7')->setValue('Add: Dep. Expense Building:');
  1205.         $objSheet->getCell('B7')->setValue($DepBuilding);
  1206.         $objSheet->getCell('A8')->setValue('Add: Dep. Expense Equipment:');
  1207.         $objSheet->getCell('B8')->setValue($DepEquipment);
  1208.         $objSheet->getCell('A9')->setValue('Add: Dep. Expense Supplies:');
  1209.         $objSheet->getCell('B9')->setValue($DepSupplies);
  1210.         $objSheet->getCell('A10')->setValue($SignUnuRevenue);
  1211.         $objSheet->getCell('B10')->setValue($UnuRevenue);
  1212.         $objSheet->getCell('A11')->setValue($SignCostRevPayable);
  1213.         $objSheet->getCell('B11')->setValue($CostRevPayable);
  1214.         $objSheet->getCell('A12')->setValue($SignSalPayable);
  1215.         $objSheet->getCell('B12')->setValue($SalPayable);
  1216.         $objSheet->getCell('A13')->setValue($SignWagPayable);
  1217.         $objSheet->getCell('B13')->setValue($WagPayable);
  1218.         $objSheet->getCell('A14')->setValue($SignTelPayable);
  1219.         $objSheet->getCell('B14')->setValue($TelPayable);
  1220.         $objSheet->getCell('A15')->setValue($SignUtiPayable);
  1221.         $objSheet->getCell('B15')->setValue($UtiPayable);
  1222.         $objSheet->getCell('A16')->setValue($SignRenPayable);
  1223.         $objSheet->getCell('B16')->setValue($RenPayable);
  1224.         $objSheet->getCell('A17')->setValue($SignAdvPayable);
  1225.         $objSheet->getCell('B17')->setValue($AdvPayable);
  1226.         $objSheet->getCell('A18')->setValue($SignIntPayable);
  1227.         $objSheet->getCell('B18')->setValue($IntPayable);
  1228.         $objSheet->getCell('A19')->setValue($SignVatPayable);
  1229.         $objSheet->getCell('B19')->setValue($VatPayable);
  1230.         $objSheet->getCell('A20')->setValue($SignTaxPayable);
  1231.         $objSheet->getCell('B20')->setValue($TaxPayable);
  1232.         $objSheet->getCell('A21')->setValue($SignLegPayable);
  1233.         $objSheet->getCell('B21')->setValue($LegPayable);
  1234.         $objSheet->getCell('A22')->setValue($SignMisPayable);
  1235.         $objSheet->getCell('B22')->setValue($MisPayable);
  1236.         $objSheet->getCell('A23')->setValue($SignCashOp);
  1237.         $objSheet->getCell('B23')->setValue('=B4-B6-B7-B8-B9+B10-B5+B11+B12+B13+B14+B15+B16+B17+B18+B19+B20+B21+B22');
  1238.         $objSheet->getStyle('A23:B23')->getFont()->setBold(true)->setSize(11);
  1239.         $objSheet->getCell('A24')->setValue($SignPreInsurance);
  1240.         $objSheet->getCell('B24')->setValue($PreInsurance);
  1241.         $objSheet->getCell('A25')->setValue($SignPreRent);
  1242.         $objSheet->getCell('B25')->setValue($PreRent);
  1243.         $objSheet->getCell('A26')->setValue($SignPreSupplies);
  1244.         $objSheet->getCell('B26')->setValue($PreSupplies);
  1245.         $objSheet->getCell('A27')->setValue('Building Purchase');
  1246.         $objSheet->getCell('B27')->setValue($BuiPurchase);
  1247.         $objSheet->getCell('A28')->setValue('Equipment Purchase');
  1248.         $objSheet->getCell('B28')->setValue($EquPurchase);
  1249.         $objSheet->getCell('A29')->setValue('Supplies Purchase');
  1250.         $objSheet->getCell('B29')->setValue($SupPurchase);
  1251.         $objSheet->getCell('A30')->setValue($SignNotesPayable);
  1252.         $objSheet->getCell('B30')->setValue($NotesPayable);
  1253.         $objSheet->getCell('A31')->setValue('Add: Proceeds from Asset Sale');
  1254.         $objSheet->getCell('B31')->setValue($ProCash);
  1255.         $objSheet->getCell('A32')->setValue($SignCashInv);
  1256.         $objSheet->getCell('B32')->setValue('=B30+B31-B24-B25-B26-B27-B28-B29');
  1257.         $objSheet->getStyle('A32:B32')->getFont()->setBold(true)->setSize(11);
  1258.         $objSheet->getCell('A33')->setValue('Investment');
  1259.         $objSheet->getCell('B33')->setValue($Capital);
  1260.         $objSheet->getCell('A34')->setValue('Less: Drawing');
  1261.         $objSheet->getCell('B34')->setValue($Drawing);
  1262.         $objSheet->getCell('A35')->setValue($SignCashFin);
  1263.         $objSheet->getCell('B35')->setValue('=B33+B34');
  1264.         $objSheet->getStyle('A35:B35')->getFont()->setBold(true)->setSize(11);
  1265.         $objSheet->getCell('A36')->setValue('Cash: Beginning Month');
  1266.         $objSheet->getCell('B36')->setValue($CashBeginning);
  1267.         $objSheet->getStyle('A36:B36')->getFont()->setBold(true)->setSize(11);
  1268.         $objSheet->getCell('A37')->setValue('Cash: Ending Month');
  1269.         $objSheet->getCell('B37')->setValue('=B23+B32+B35+B36');
  1270.         $objSheet->getStyle('A37:B37')->getFont()->setBold(true)->setSize(11);
  1271.         $objWriter->save('statements/CashFlowStatement' . '_' . $Token . '.xlsx');
  1272.        
  1273.         $ProGain        = $this->toMoney(abs($ProGain));
  1274.         $DepBuilding    = $this->toMoney($DepBuilding * -1);
  1275.         $DepEquipment   = $this->toMoney($DepEquipment * -1);
  1276.         $DepSupplies    = $this->toMoney($DepSupplies * -1);
  1277.         $UnuRevenue     = $this->toMoney(abs($UnuRevenue));
  1278.         $AccReceivable  = $this->toMoney(abs($AccReceivable));
  1279.         $CostRevPayable = $this->toMoney(abs($CostRevPayable));
  1280.         $SalPayable     = $this->toMoney(abs($SalPayable));
  1281.         $WagPayable     = $this->toMoney(abs($WagPayable));
  1282.         $TelPayable     = $this->toMoney(abs($TelPayable));
  1283.         $UtiPayable     = $this->toMoney(abs($UtiPayable));
  1284.         $RenPayable     = $this->toMoney(abs($RenPayable));
  1285.         $AdvPayable     = $this->toMoney(abs($AdvPayable));
  1286.         $IntPayable     = $this->toMoney(abs($IntPayable));
  1287.         $VatPayable     = $this->toMoney(abs($VatPayable));
  1288.         $TaxPayable     = $this->toMoney(abs($TaxPayable));
  1289.         $LegPayable     = $this->toMoney(abs($LegPayable));
  1290.         $MisPayable     = $this->toMoney(abs($MisPayable));
  1291.         $Income         = $this->toMoney(abs($Income));
  1292.         $CashOp         = $this->toMoney(abs($CashOp));
  1293.         $ProCash      = $this->toMoney($ProCash);
  1294.         $PreInsurance = $this->toMoney(abs($PreInsurance));
  1295.         $PreRent      = $this->toMoney(abs($PreRent));
  1296.         $PreSupplies  = $this->toMoney(abs($PreSupplies));
  1297.         $BuiPurchase  = $this->toMoney($BuiPurchase);
  1298.         $EquPurchase  = $this->toMoney($EquPurchase);
  1299.         $SupPurchase  = $this->toMoney($SupPurchase);
  1300.         $NotesPayable = $this->toMoney(abs($NotesPayable));
  1301.         $CashInv      = $this->toMoney(abs($CashInv));
  1302.         $Capital = $this->toMoney($Capital);
  1303.         $Drawing = $this->toMoney($Drawing * -1);
  1304.         $CashFin = $this->toMoney(abs($CashFin));
  1305.         $CashBeginning = $this->toMoney($CashBeginning);
  1306.         $CashEnding    = $this->toMoney($CashEnding);
  1307.         echo <<<EOT
  1308.             <div class="ui card width-full">
  1309.                 <div class="content">
  1310.                     <div class="header"><i class="cubes icon"></i>Statement of Cash Flow</div>
  1311.                     <div class="meta">For the month of $Month'$Year</div>
  1312.                     <table class="ui">
  1313.                         <thead>
  1314.                             <tr>
  1315.                                 <th class="summary-width-left"><i class="book icon"></i>Operating Cash Flow</th>
  1316.                                 <th class="summary-width-right">Amount</th>
  1317.                             </tr>
  1318.                         </thead>
  1319.                         <tbody>
  1320.                             <tr><td>$SignIncome</td><td>Rp. $Income</td></tr>
  1321.                             <tr><td>$SignAccReceivable</td><td>Rp. $AccReceivable</td></tr>
  1322.                             <tr><td>$SignProGain</td><td>Rp. $ProGain</td></tr>
  1323.                             <tr><td>Add: Dep. Expense Building:</td><td>Rp. $DepBuilding</td></tr>
  1324.                             <tr><td>Add: Dep. Expense Equipment:</td><td>Rp. $DepEquipment</td></tr>
  1325.                             <tr><td>Add: Dep. Expense Supplies:</td><td>Rp. $DepSupplies</td></tr>
  1326.                             <tr><td>$SignUnuRevenue</td><td>Rp. $UnuRevenue</td></tr>
  1327.                             <tr><td>$SignCostRevPayable</td><td>Rp. $CostRevPayable</td></tr>
  1328.                             <tr><td>$SignSalPayable</td><td>Rp. $SalPayable</td></tr>
  1329.                             <tr><td>$SignWagPayable</td><td>Rp. $WagPayable</td></tr>
  1330.                             <tr><td>$SignTelPayable</td><td>Rp. $TelPayable</td></tr>
  1331.                             <tr><td>$SignUtiPayable</td><td>Rp. $UtiPayable</td></tr>
  1332.                             <tr><td>$SignRenPayable</td><td>Rp. $RenPayable</td></tr>
  1333.                             <tr><td>$SignAdvPayable</td><td>Rp. $AdvPayable</td></tr>
  1334.                             <tr><td>$SignIntPayable</td><td>Rp. $IntPayable</td></tr>
  1335.                             <tr><td>$SignVatPayable</td><td>Rp. $VatPayable</td></tr>
  1336.                             <tr><td>$SignTaxPayable</td><td>Rp. $TaxPayable</td></tr>
  1337.                             <tr><td>$SignLegPayable</td><td>Rp. $LegPayable</td></tr>
  1338.                             <tr><td>$SignMisPayable</td><td>Rp. $MisPayable</td></tr>
  1339.                         </tbody>
  1340.                         <tfoot>
  1341.                             <tr>
  1342.                                 <th>$SignCashOp</th>
  1343.                                 <th>$CashOp</th>
  1344.                             </tr>
  1345.                         </tfoot>
  1346.                     </table>
  1347. EOT;
  1348.         echo <<<EOT
  1349.                     <table class="ui">
  1350.                         <thead>
  1351.                             <tr>
  1352.                                 <th class="summary-width-left"><i class="book icon"></i>Investing Cash Flow</th>
  1353.                                 <th class="summary-width-right">Amount</th>
  1354.                             </tr>
  1355.                         </thead>
  1356.                         <tbody>
  1357.                             <tr><td>$SignPreInsurance</td><td>Rp. $PreInsurance</td></tr>
  1358.                             <tr><td>$SignPreRent</td><td>Rp. $PreRent</td></tr>
  1359.                             <tr><td>$SignPreSupplies</td><td>Rp. $PreSupplies</td></tr>
  1360.                             <tr><td>Building Purchase:</td><td>Rp. $BuiPurchase</td></tr>
  1361.                             <tr><td>Equipment Purchase:</td><td>Rp. $EquPurchase</td></tr>
  1362.                             <tr><td>Supplies Purchase:</td><td>Rp. $SupPurchase</td></tr>
  1363.                             <tr><td>$SignNotesPayable</td><td>Rp. $NotesPayable</td></tr>
  1364.                             <tr><td>Add: Proceeds from Asset Sale:</td><td>Rp. $ProCash</td></tr>
  1365.                         </tbody>
  1366.                         <tfoot>
  1367.                             <tr>
  1368.                                 <th>$SignCashInv</th>
  1369.                                 <th>$CashInv</th>
  1370.                             </tr>
  1371.                         </tfoot>
  1372.                     </table>
  1373. EOT;
  1374.        
  1375.         echo <<<EOT
  1376.                     <table class="ui">
  1377.                         <thead>
  1378.                             <tr>
  1379.                                 <th class="summary-width-left"><i class="book icon"></i>Financing Cash Flow</th>
  1380.                                 <th class="summary-width-right">Amount</th>
  1381.                             </tr>
  1382.                         </thead>
  1383.                         <tbody>
  1384.                             <tr><td>Investment:</td><td>Rp. $Capital</td></tr>
  1385.                             <tr><td>Less: Drawing:</td><td>Rp. $Drawing</td></tr>
  1386.                         </tbody>
  1387.                         <tfoot>
  1388.                             <tr>
  1389.                                 <th>$SignCashFin</th>
  1390.                                 <th>$CashFin</th>
  1391.                             </tr>
  1392.                             <tr>
  1393.                                 <th>Cash: Beginning Period:</th>
  1394.                                 <th>$CashBeginning</th>
  1395.                             </tr>
  1396.                             <tr>
  1397.                                 <th>Cash: Ending Period:</th>
  1398.                                 <th>$CashEnding</th>
  1399.                             </tr>
  1400.                         </tfoot>
  1401.                     </table>
  1402.                     <div class="summary">
  1403.                         <div class="description waterfall left">
  1404. EOT;
  1405.         $this->cashWaterFall($graphCash, $graphCashBeginning, $graphCashEnding);
  1406.         echo <<<EOT
  1407.                         </div>
  1408.                         <div class="description in-words right">
  1409.                             Summary: $CashFlowSummary
  1410.                         </div>
  1411.                     </div>
  1412.                 </div>
  1413.                 <div class="extra">
  1414.                     Download
  1415.                     <a href='statements/CashFlowStatement_$Token.xlsx'><i class="table icon"></i></a>
  1416.                 </div>
  1417.             </div>
  1418.             <div class="ui horizontal divider"><i class="anchor icon"></i></div>
  1419. EOT;
  1420.         return array(
  1421.             $CashEndingReturn
  1422.         );
  1423.     }
  1424.  
  1425.     /*------------------------------------------------------------------
  1426.     [Preview bank reconciliation and create excel export]
  1427.     -------------------------------------------------------------------*/
  1428.  
  1429.     public function previewBankReconciliation($CashEnding, $objExcelRecon)
  1430.     {
  1431.         $Token = strtotime("now");
  1432.         $Month = $_SESSION['month'];
  1433.         $Year  = $_SESSION['year'];
  1434.        
  1435.         $siteQuery = "SELECT * FROM balance WHERE Status = 'Open'";
  1436.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1437.         $row = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1438.         $DepTransit  = $row['deptransit'];
  1439.         $OutChecks   = $row['outchecks'];
  1440.         $PettyCash   = $row['pettycash'];
  1441.         $BankBalance = round($CashEnding + $DepTransit + $OutChecks + $PettyCash, 2);
  1442.        
  1443.         $objExcelRecon->getDefaultStyle()->getFont()->setName('Segoe UI');
  1444.         $objExcelRecon->getDefaultStyle()->getFont()->setSize(11);
  1445.         $objWriter = PHPExcel_IOFactory::createWriter($objExcelRecon, "Excel2007");
  1446.         $objSheet  = $objExcelRecon->getActiveSheet();
  1447.         $objSheet->setTitle('Bank Reconciliation Statement');
  1448.         $objSheet->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  1449.         $objSheet->getStyle('A1:B1')->getFont()->setBold(true)->setSize(11);
  1450.         $objSheet->getColumnDimension('A')->setWidth(50);
  1451.         $objSheet->getColumnDimension('B')->setWidth(50);
  1452.         $objSheet->getStyle('B2:B8')->getNumberFormat()->setFormatCode('#,##0.00');
  1453.         $objSheet->mergeCells('A1:B1');
  1454.         $objSheet->getCell('A1')->setValue('Statement of Bank Reconciliation');
  1455.         $objSheet->mergeCells('A2:B2');
  1456.         $objSheet->getCell('A2')->setValue('For the month ending ' . $Month . '\'' . $Year);
  1457.         $objSheet->getStyle('A3:B3')->getFont()->setBold(true)->setSize(11);
  1458.         $objSheet->getCell('A3')->setValue('Account');
  1459.         $objSheet->getCell('B3')->setValue('Amount');
  1460.         $objSheet->getCell('A4')->setValue('Cash: Account Statement');
  1461.         $objSheet->getCell('B4')->setValue($CashEnding);
  1462.         $objSheet->getCell('A5')->setValue('Deposit in Transit');
  1463.         $objSheet->getCell('B5')->setValue($DepTransit);
  1464.         $objSheet->getCell('A6')->setValue('Outstanding Checks');
  1465.         $objSheet->getCell('B6')->setValue($OutChecks);
  1466.         $objSheet->getCell('A7')->setValue('Petty Cash');
  1467.         $objSheet->getCell('B7')->setValue($PettyCash);
  1468.         $objSheet->getCell('A8')->setValue('Cash: Bank Statement');
  1469.         $objSheet->getCell('B8')->setValue('=B4+B5+B6+B7');
  1470.         $objSheet->getStyle('A8:B8')->getFont()->setBold(true)->setSize(11);
  1471.         $objWriter->save('statements/ReconciliationStatement' . '_' . $Token . '.xlsx');
  1472.        
  1473.         $CashEnding  = $this->toMoney($CashEnding);
  1474.         $DepTransit  = $this->toMoney($DepTransit * -1);
  1475.         $OutChecks   = $this->toMoney($OutChecks);
  1476.         $PettyCash   = $this->toMoney($PettyCash * -1);
  1477.         $BankBalance = $this->toMoney($BankBalance);
  1478.        
  1479.         echo <<<EOT
  1480.             <div class="ui card width-full">
  1481.                 <div class="content">
  1482.                     <div class="header"><i class="cubes icon"></i>Statement of Bank Reconciliation</div>
  1483.                     <div class="meta">For the month ending $Month'$Year</div>
  1484.                     <table class="ui">
  1485.                         <thead>
  1486.                             <tr>
  1487.                                 <th class="summary-width-left"><i class="book icon"></i>Particulars</th>
  1488.                                 <th class="summary-width-right">Amount</th>
  1489.                             </tr>
  1490.                         </thead>
  1491.                         <tbody>
  1492.                             <tr><td>Cash: Account Statement:</td><td>Rp. $CashEnding</td></tr>
  1493.                             <tr><td>Deposit in Transit:</td><td>Rp. $DepTransit</td></tr>
  1494.                             <tr><td>Outstanding Checks:</td><td>Rp. $OutChecks</td></tr>
  1495.                             <tr><td>Petty Cash:</td><td>Rp. $PettyCash</td></tr>
  1496.                         </tbody>
  1497.                         <tfoot>
  1498.                             <tr>
  1499.                                 <th>Cash: Bank Statement</th>
  1500.                                 <th>$BankBalance</th>
  1501.                             </tr>
  1502.                         </tfoot>
  1503.                     </table>
  1504.                 </div>
  1505.                 <div class="extra">
  1506.                     Download
  1507.                     <a href='statements/ReconciliationStatement_$Token.xlsx'><i class="table icon"></i></a>
  1508.                 </div>
  1509.             </div>
  1510.             <div class="ui horizontal divider"><i class="anchor icon"></i></div>
  1511. EOT;
  1512.     }
  1513.  
  1514.     /*------------------------------------------------------------------
  1515.     [Check correct balance sheet to view closing button]
  1516.     -------------------------------------------------------------------*/
  1517.  
  1518.     public function correctBalance($Asset, $Liability, $Equity, $Cash, $CashEnding, $CheckError)
  1519.     {
  1520.         $Asset = round($Asset, 2);
  1521.         $Equity = round($Liability + $Equity, 2);
  1522.         $Cash = round($Cash, 2);
  1523.         $CashEnding = round($CashEnding, 2);
  1524.         if ($Asset == $Equity && $Cash == $CashEnding && $CheckError == "Correct")
  1525.             return TRUE;
  1526.         else
  1527.             return FALSE;
  1528.     }
  1529.  
  1530.     /*------------------------------------------------------------------
  1531.     [Get next month from current month]
  1532.     -------------------------------------------------------------------*/
  1533.  
  1534.     public function getNextMonth($Month, $Year)
  1535.     {
  1536.         if ($Month == "Jan")
  1537.             $Month = "Feb";
  1538.         elseif ($Month == "Feb")
  1539.             $Month = "Mar";
  1540.         elseif ($Month == "Mar")
  1541.             $Month = "Apr";
  1542.         elseif ($Month == "Apr")
  1543.             $Month = "May";
  1544.         elseif ($Month == "May")
  1545.             $Month = "Jun";
  1546.         elseif ($Month == "Jun")
  1547.             $Month = "Jul";
  1548.         elseif ($Month == "Jul")
  1549.             $Month = "Aug";
  1550.         elseif ($Month == "Aug")
  1551.             $Month = "Sep";
  1552.         elseif ($Month == "Sep")
  1553.             $Month = "Oct";
  1554.         elseif ($Month == "Oct")
  1555.             $Month = "Nov";
  1556.         elseif ($Month == "Nov")
  1557.             $Month = "Dec";
  1558.         elseif ($Month == "Dec") {
  1559.             $Month = "Jan";
  1560.             $Year  = $Year + 1;
  1561.         }
  1562.         return array(
  1563.             $Month,
  1564.             $Year
  1565.         );
  1566.     }
  1567.  
  1568.     /*------------------------------------------------------------------
  1569.     [Backup database on month closing]
  1570.     -------------------------------------------------------------------*/
  1571.  
  1572.     public function backupDatabase($Month, $Year)
  1573.     {
  1574.         $return = "";
  1575.         $tables = array('balance','customer','entry','info','records','recurring','reminders');
  1576.         if($tables == '*')
  1577.         {
  1578.             $result = mysqli_query($this->con, 'SHOW TABLES');
  1579.             while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
  1580.             {
  1581.                 $tables[] = $row[0];
  1582.             }
  1583.         }
  1584.         else
  1585.         {
  1586.             $tables = is_array($tables) ? $tables : explode(',',$tables);
  1587.         }
  1588.         foreach($tables as $table)
  1589.         {
  1590.             $result = mysqli_query($this->con, 'SELECT * FROM '.$table);
  1591.             $num_fields = mysqli_num_fields($result);
  1592.            
  1593.             $return.= 'DROP TABLE '.$table.';';
  1594.             $row2 = mysqli_fetch_row(mysqli_query($this->con, 'SHOW CREATE TABLE '.$table));
  1595.             $return.= "\n\n".$row2[1].";\n\n";
  1596.            
  1597.             for ($i = 0; $i < $num_fields; $i++)
  1598.             {
  1599.                 while($row = mysqli_fetch_row($result))
  1600.                 {
  1601.                     $return.= 'INSERT INTO '.$table.' VALUES(';
  1602.                     for($j=0; $j<$num_fields; $j++)
  1603.                     {
  1604.                         $row[$j] = addslashes($row[$j]);
  1605.                         $row[$j] = ereg_replace("\n","\\n",$row[$j]);
  1606.                         if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; } else { $return.= '""'; }
  1607.                         if ($j<($num_fields-1)) { $return.= ','; }
  1608.                     }
  1609.                     $return.= ");\n";
  1610.                 }
  1611.             }
  1612.             $return.="\n\n\n";
  1613.         }
  1614.         $handle = fopen('../../backup/Monthly-backup-'.$Month.'-'.$Year.'.sql','w+');
  1615.         fwrite($handle,$return);
  1616.         fclose($handle);
  1617.     }
  1618.  
  1619.     /*------------------------------------------------------------------
  1620.     [Insert balance sheet into archive and set info for next month]
  1621.     -------------------------------------------------------------------*/
  1622.  
  1623.     public function insertArchive()
  1624.     {
  1625.         $siteQuery = "SELECT * FROM info WHERE Status = 'Open'";
  1626.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1627.         $siteInfo = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1628.         $ID       = $siteInfo['ID'];
  1629.         $Month    = $siteInfo['month'];
  1630.         $Year     = $siteInfo['year'];
  1631.  
  1632.         $this->backupDatabase($Month, $Year);
  1633.  
  1634.         $siteQuery = "INSERT INTO records
  1635.            (ID, month, year, cash, procash, accrecser, preins, preren, building, cashbui, depbui, equipment,
  1636.                cashequ, depequ, presup, supplies, cashsup, depsup, unuser, costrevpay, notpay, intpay, equpay,
  1637.                salpay, wagpay, telpay, utipay, renpay, suppay, advpay, vatpay, taxpay, legpay, mispay, costrevexp,
  1638.                depbuiexp, depequexp, depsupexp, insexp, renexp, salexp, wagexp, telexp, utiexp, advexp, intexp,
  1639.                vatexp, taxexp, legexp, misexp, baddebtexp, serrev, intrev, capital, drawing, cashbeginning,
  1640.                eqbeginning, progain, deptransit, outchecks, pettycash) select
  1641.            ID, month, year, cash, procash, accrecser, preins, preren, building, cashbui, depbui, equipment,
  1642.                cashequ, depequ, presup, supplies, cashsup, depsup, unuser, costrevpay, notpay, intpay, equpay,
  1643.                salpay, wagpay, telpay, utipay, renpay, suppay, advpay, vatpay, taxpay, legpay, mispay, costrevexp,
  1644.                depbuiexp, depequexp, depsupexp, insexp, renexp, salexp, wagexp, telexp, utiexp, advexp, intexp,
  1645.                vatexp, taxexp, legexp, misexp, baddebtexp, serrev, intrev, capital, drawing, cashbeginning,
  1646.                eqbeginning, progain, deptransit, outchecks, pettycash from balance WHERE Status='Open'";
  1647.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1648.         $siteInfo = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1649.        
  1650.         $siteQuery = "SELECT * FROM info WHERE Status = 'Open'";
  1651.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1652.         $siteInfo = mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1653.  
  1654.         $ID       = $ID + 1;
  1655.         list($Month, $Year) = $this->getNextMonth($Month, $Year);
  1656.         $siteQuery = "UPDATE info SET month='$Month', year='$Year', ID='$ID' WHERE Status = 'Open'";
  1657.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1658.         mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1659.        
  1660.         $siteQuery = "UPDATE entry SET Status='Off' WHERE Status = 'On'";
  1661.         $siteResult = mysqli_query($this->con, $siteQuery) or die('MySql Error' . mysql_error());
  1662.         mysqli_fetch_array($siteResult, MYSQLI_ASSOC);
  1663.     }
  1664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement