From: <rc...@us...> - 2016-11-18 00:22:29
|
Revision: 7668 http://sourceforge.net/p/web-erp/reponame/7668 Author: rchacon Date: 2016-11-18 00:22:26 +0000 (Fri, 18 Nov 2016) Log Message: ----------- Add scripts to shows a statement of cash flows for the period using the indirect method. Modified Paths: -------------- trunk/GLAccounts.php trunk/doc/Change.log trunk/doc/Manual/ManualGeneralLedger.html trunk/includes/MainMenuLinksArray.php trunk/sql/mysql/upgrade4.13-4.13.1.sql Added Paths: ----------- trunk/GLCashFlowsIndirect.php trunk/GLCashFlowsSetup.php Modified: trunk/GLAccounts.php =================================================================== --- trunk/GLAccounts.php 2016-11-17 04:17:16 UTC (rev 7667) +++ trunk/GLAccounts.php 2016-11-18 00:22:26 UTC (rev 7668) @@ -2,6 +2,22 @@ /* $Id$*/ /* Defines the general ledger accounts */ +// BEGIN: Functions division --------------------------------------------------- +function CashFlowsActivityName($Activity) { + // Converts the cash flow activity number to an activity text. + switch($Activity) { + case -1: return '<b>' . _('Without setting up') . '</b>'; + case 0: return _('No effect on cash flow'); + case 1: return _('Operating activity'); + case 2: return _('Investing activity'); + case 3: return _('Financing activity'); + case 4: return _('Cash or cash equivalent'); + default: return '<b>' . _('Unknown') . '</b>'; + } +} +// END: Functions division ----------------------------------------------------- + +// BEGIN: Procedure division --------------------------------------------------- include('includes/session.inc'); $Title = _('General Ledger Accounts'); $ViewTopic= 'GeneralLedger'; @@ -13,6 +29,11 @@ $Title, '" /> ', // Icon title. $Title, '</p>';// Page title. +// Merges gets into posts: +if(isset($_GET['CashFlowsActivity'])) {// Select period from. + $_POST['CashFlowsActivity'] = $_GET['CashFlowsActivity']; +} + if(isset($_POST['SelectedAccount'])) { $SelectedAccount = $_POST['SelectedAccount']; } elseif(isset($_GET['SelectedAccount'])) { @@ -36,8 +57,10 @@ if(isset($SelectedAccount) AND $InputError != 1) { - $Sql = "UPDATE chartmaster SET accountname='" . $_POST['AccountName'] . "', - group_='" . $_POST['Group'] . "' + $Sql = "UPDATE + chartmaster SET accountname='" . $_POST['AccountName'] . "', + group_='" . $_POST['Group'] . "', + cashflowsactivity='" . $_POST['CashFlowsActivity'] . "' WHERE accountcode ='" . $SelectedAccount . "'"; $ErrMsg = _('Could not update the account because'); $Result = DB_query($Sql, $ErrMsg); @@ -47,12 +70,16 @@ /*SelectedAccount is null cos no item selected on first time round so must be adding a record must be submitting new entries */ - $Sql = "INSERT INTO chartmaster (accountcode, - accountname, - group_) - VALUES ('" . $_POST['AccountCode'] . "', - '" . $_POST['AccountName'] . "', - '" . $_POST['Group'] . "')"; + $Sql = "INSERT INTO chartmaster ( + accountcode, + accountname, + group_, + cashflowsactivity) + VALUES ('" . + $_POST['AccountCode'] . "', '" . + $_POST['AccountName'] . "', '" . + $_POST['Group'] . "', '" . + $_POST['CashFlowsActivity'] . "')"; $ErrMsg = _('Could not add the new account code'); $Result = DB_query($Sql, $ErrMsg); @@ -62,6 +89,7 @@ unset($_POST['Group']); unset($_POST['AccountCode']); unset($_POST['AccountName']); + unset($_POST['CashFlowsActivity']); unset($SelectedAccount); } elseif(isset($_GET['delete'])) { @@ -196,20 +224,19 @@ if(!isset($_GET['delete'])) { echo '<form method="post" id="GLAccounts" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">'; - echo '<div>'; echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />'; if(isset($SelectedAccount)) { //editing an existing account - $Sql = "SELECT accountcode, accountname, group_ FROM chartmaster WHERE accountcode='" . $SelectedAccount ."'"; - + $Sql = "SELECT accountcode, accountname, group_, cashflowsactivity FROM chartmaster WHERE accountcode='" . $SelectedAccount ."'"; $Result = DB_query($Sql); $MyRow = DB_fetch_array($Result); $_POST['AccountCode'] = $MyRow['accountcode']; $_POST['AccountName'] = $MyRow['accountname']; $_POST['Group'] = $MyRow['group_']; + $_POST['CashFlowsActivity'] = $MyRow['cashflowsactivity']; echo '<input type="hidden" name="SelectedAccount" value="' . $SelectedAccount . '" />'; echo '<input type="hidden" name="AccountCode" value="' . $_POST['AccountCode'] .'" />'; @@ -248,12 +275,27 @@ } echo '</select></td> </tr> - </table> + + <tr> + <td><label for="CashFlowsActivity">', _('Cash Flows Activity'), ':</label></td> + <td><select id="CashFlowsActivity" name="CashFlowsActivity" required="required"> + <option value="0"', ($_POST['CashFlowsActivity'] == 0 ? ' selected="selected"' : ''), '>', _('No effect on cash flow'), '</option> + <option value="1"', ($_POST['CashFlowsActivity'] == 1 ? ' selected="selected"' : ''), '>', _('Operating activity'), '</option> + <option value="2"', ($_POST['CashFlowsActivity'] == 2 ? ' selected="selected"' : ''), '>', _('Investing activity'), '</option> + <option value="3"', ($_POST['CashFlowsActivity'] == 3 ? ' selected="selected"' : ''), '>', _('Financing activity'), '</option> + <option value="4"', ($_POST['CashFlowsActivity'] == 4 ? ' selected="selected"' : ''), '>', _('Cash or cash equivalent'), '</option> + </select> + </td> + </tr> + + + </table>'; + + echo ' <br /> <div class="centre"> <input type="submit" name="submit" value="'. _('Enter Information') . '" /> </div> - </div> </form>'; } //end if record deleted no point displaying form to add record @@ -268,41 +310,45 @@ echo '<br /> <table class="selection"> <tr> - <th class="ascending">' . _('Account Code') . '</th> - <th class="ascending">' . _('Account Name') . '</th> - <th class="ascending">' . _('Account Group') . '</th> - <th class="ascending">' . _('P/L or B/S') . '</th> - <th colspan="2"> </th> + <th class="ascending">', _('Account Code'), '</th> + <th class="ascending">', _('Account Name'), '</th> + <th class="ascending">', _('Account Group'), '</th> + <th class="ascending">', _('P/L or B/S'), '</th> + <th class="ascending">', _('Cash Flows Activity'), '</th> + <th class="noprint" colspan="2"> </th> </tr>'; - $Sql = "SELECT accountcode, - accountname, - group_, - CASE WHEN pandl=0 THEN '" . _('Balance Sheet') . "' ELSE '" . _('Profit/Loss') . "' END AS acttype - FROM chartmaster, - accountgroups - WHERE chartmaster.group_=accountgroups.groupname - ORDER BY chartmaster.accountcode"; + $Sql = "SELECT + accountcode, + accountname, + group_, + CASE WHEN pandl=0 THEN '" . _('Balance Sheet') . "' ELSE '" . _('Profit/Loss') . "' END AS acttype, + cashflowsactivity + FROM chartmaster, accountgroups + WHERE chartmaster.group_=accountgroups.groupname + ORDER BY chartmaster.accountcode"; $ErrMsg = _('The chart accounts could not be retrieved because'); $Result = DB_query($Sql, $ErrMsg); - $k = 0;// Row colour counter. - while($MyRow = DB_fetch_row($Result)) { + $k = 1;// Row colour counter. + foreach($Result as $MyRow) { if($k == 1) { - echo '<tr class="EvenTableRows">'; + echo '<tr class="OddTableRows">'; $k = 0; } else { - echo '<tr class="OddTableRows">'; + echo '<tr class="EvenTableRows">'; $k = 1; } - echo '<td>', $MyRow[0], '</td> - <td>', htmlspecialchars($MyRow[1], ENT_QUOTES, 'UTF-8'), '</td> - <td>', $MyRow[2], '</td> - <td>', $MyRow[3], '</td> - <td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?', '&SelectedAccount=', $MyRow[0], '">', _('Edit'), '</a></td> - <td><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?', '&SelectedAccount=', $MyRow[0], '&delete=1" onclick="return confirm(\'', _('Are you sure you wish to delete this account? Additional checks will be performed in any event to ensure data integrity is not compromised.'), '\');">', _('Delete'), '</a></td> + echo '<td class="text">', $MyRow['accountcode'], '</td> + <td class="text">', htmlspecialchars($MyRow['accountname'], ENT_QUOTES, 'UTF-8'), '</td> + <td class="text">', $MyRow['group_'], '</td> + <td class="text">', $MyRow['acttype'], '</td> + <td class="text">', CashFlowsActivityName($MyRow['cashflowsactivity']), '</td> + <td class="noprint"><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?', '&SelectedAccount=', $MyRow['accountcode'], '">', _('Edit'), '</a></td> + <td class="noprint"><a href="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '?', '&SelectedAccount=', $MyRow['accountcode'], '&delete=1" onclick="return confirm(\'', _('Are you sure you wish to delete this account? Additional checks will be performed in any event to ensure data integrity is not compromised.'), '\');">', _('Delete'), '</a></td> </tr>'; - }// END WHILE LIST LOOP. + }// END foreach($Result as $MyRow). + echo '</table>'; } //END IF selected ACCOUNT Added: trunk/GLCashFlowsIndirect.php =================================================================== --- trunk/GLCashFlowsIndirect.php (rev 0) +++ trunk/GLCashFlowsIndirect.php 2016-11-18 00:22:26 UTC (rev 7668) @@ -0,0 +1,840 @@ +<?php +/* $Id: GLCashFlowsIndirect.php 1 2014-03-12 10:42:50Z rchacon $ */ +/* Shows a statement of cash flows for the period using the indirect method. */ +/* This program is under the GNU General Public License, last version. Rafael E. Chacón, 2016-10-08. */ +/* This creative work is under the CC BY-NC-SA, later version. Rafael E. Chacón, 2016-10-08. */ + +// Notes: +// Coding Conventions/Style: http://www.weberp.org/CodingConventions.html +// Info about a statement of cash flows using the indirect method: IAS 7 - Statement of Cash Flows. + +// BEGIN: Functions division --------------------------------------------------- +function CashFlowsActivityName($Activity) { + // Converts the cash flow activity number to an activity text. + switch($Activity) { + case -1: return _('Without setting up'); + case 0: return _('No effect on cash flow'); + case 1: return _('Operating activities'); + case 2: return _('Investing activities'); + case 3: return _('Financing activities'); + case 4: return _('Cash or cash equivalent'); + default: return _('Unknown'); + } +} +function colDebitCredit($Amount) { + // Function to display in debit or Credit columns in a HTML table. + if($Amount < 0) { + return '<td class="number">' . locale_number_format($Amount, $_SESSION['CompanyRecord']['decimalplaces']) . '</td><td> </td>';// Outflow. + } else { + return '<td> </td><td class="number">' . locale_number_format($Amount, $_SESSION['CompanyRecord']['decimalplaces']) . '</td>';// Inflow. + } +} +// END: Functions division ----------------------------------------------------- + +// BEGIN: Procedure division --------------------------------------------------- +include('includes/session.inc'); +$Title = _('Statement of Cash Flows, Indirect Method'); +$ViewTopic = 'GeneralLedger'; +$BookMark = 'GLCashFlowsIndirect'; +include('includes/header.inc'); + +// Merges gets into posts: +if(isset($_GET['PeriodFrom'])) {// Select period from. + $_POST['PeriodFrom'] = $_GET['PeriodFrom']; +} +if(isset($_GET['PeriodTo'])) {// Select period to. + $_POST['PeriodTo'] = $_GET['PeriodTo']; +} +if(isset($_GET['ShowBudget'])) {// Show the budget for the period. + $_POST['ShowBudget'] = $_GET['ShowBudget']; +} +if(isset($_GET['ShowZeroBalance'])) {// Show accounts with zero balance. + $_POST['ShowZeroBalance'] = $_GET['ShowZeroBalance']; +} +if(isset($_GET['ShowCash'])) {// Show cash and cash equivalents accounts. + $_POST['ShowCash'] = $_GET['ShowCash']; +} + +// Validates the data submitted in the form: +if($_POST['PeriodFrom'] > $_POST['PeriodTo']) { + // The beginning is after the end. + unset($_POST['PeriodFrom']); + unset($_POST['PeriodTo']); + prnMsg(_('The beginning of the period should be before or equal to the end of the period. Please reselect the reporting period.'), 'error'); +} +if($_POST['PeriodTo']-$_POST['PeriodFrom']+1 > 12) { + // The reporting period is greater then 12 months. + unset($_POST['PeriodFrom']); + unset($_POST['PeriodTo']); + prnMsg(_('The period should be 12 months or less in duration. Please select an alternative period range.'), 'error'); +} + +// Main code: +if(isset($_POST['PeriodFrom']) AND isset($_POST['PeriodTo']) AND !isset($_POST['SelectADifferentPeriod'])) {// If all parameters are set and valid, generates the report: + echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/reports.png" title="', // Icon image. + $Title, '" /> ', // Icon title. + $Title, '<br />', // Page title, reporting statement. + stripslashes($_SESSION['CompanyRecord']['coyname']), '<br />'; // Page title, reporting entity. + $PeriodFromName = DB_fetch_array(DB_query('SELECT lastdate_in_period FROM `periods` WHERE `periodno`=' . $_POST['PeriodFrom'])); + $PeriodToName = DB_fetch_array(DB_query('SELECT lastdate_in_period FROM `periods` WHERE `periodno`=' . $_POST['PeriodTo'])); + echo _('From'), ' ', MonthAndYearFromSQLDate($PeriodFromName['lastdate_in_period']), ' ', _('to'), ' ', MonthAndYearFromSQLDate($PeriodToName['lastdate_in_period']), '<br />'; // Page title, reporting period. + include_once('includes/CurrenciesArray.php');// Array to retrieve currency name. + echo _('All amounts stated in'), ': ', _($CurrencyName[$_SESSION['CompanyRecord']['currencydefault']]), '</p>';// Page title, reporting presentation currency and level of rounding used. + echo '<table class="selection">', + // Content of the header and footer of the output table: + '<thead> + <tr> + <th>', _('Account'), '</th> + <th>', _('Account Name'), '</th> + <th colspan="2">', _('Period Actual'), '</th>'; + // Initialise section accumulators: + $ActualSection = 0; + $ActualTotal = 0; + $LastSection = 0; + $LastTotal = 0; + $k = 1;// Lines counter. + // Gets the net profit for the period GL account: + if(!isset($_SESSION['PeriodProfitAccount'])) { + $_SESSION['PeriodProfitAccount'] = ''; + $MyRow = DB_fetch_array(DB_query("SELECT confvalue FROM `config` WHERE confname ='PeriodProfitAccount'")); + if($MyRow) { + $_SESSION['PeriodProfitAccount'] = $MyRow['confvalue']; + } + } + // Gets the retained earnings GL account: + if(!isset($_SESSION['RetainedEarningsAccount'])) { + $_SESSION['RetainedEarningsAccount'] = ''; +/* $MyRow = DB_fetch_array(DB_query("SELECT confvalue FROM `config` WHERE confname ='RetainedEarningsAccount'"));*/ + $MyRow = DB_fetch_array(DB_query("SELECT retainedearnings FROM companies WHERE coycode = 1")); + if($MyRow) { + $_SESSION['RetainedEarningsAccount'] = $MyRow['confvalue']; + } + } + include('includes/GLPostings.inc');// Posts pending GL transactions. + // Outputs the table: + if($_POST['ShowBudget']) {// Parameters: PeriodFrom, PeriodTo, ShowBudget=on, ShowZeroBalance=on/off, ShowCash=on/off. + // BEGIN Outputs the table with budget. + // Code maintenance note: To update 'Outputs the table withOUT budget', copy 'Outputs the table with budget' and remove lines with 'budget'. +//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>> + echo '<th colspan="2">', _('Period Budget'), '</th>', + '<th colspan="2">', _('Last Year'), '</th> + </tr> + </thead><tfoot> + <tr>', + '<td class="text" colspan="8">',// Prints an explanation of signs in actual and relative changes: + '<br /><b>', _('Notes'), ':</b><br />', + _('Cash flows signs: a negative number indicates a cash flow used in activities; a positive number indicates a cash flow provided by activities.'), '<br />'; + if($_POST['ShowCash']) { + echo _('Cash and cash equivalents signs: a negative number indicates a cash outflow; a positive number indicates a cash inflow.'), '<br />'; + } + echo '</td> + </tr> + </tfoot><tbody>'; + // Net profit − dividends = Retained earnings: + echo '<tr> + <td class="text" colspan="8"><br /><h2>', _('Net profit and dividends'), '</h2></td> + </tr> + <tr class="OddTableRows"> + <td> </td> + <td class="text">', _('Net profit for the period'), '</td>'; + // Net profit for the period: + $Sql = "SELECT + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN -chartdetails.actual ELSE 0 END) AS ActualProfit, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN -chartdetails.budget ELSE 0 END) AS BudgetProfit, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN -chartdetails.actual ELSE 0 END) AS LastProfit + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=1"; + $MyRow1 = DB_fetch_array(DB_query($Sql)); + echo colDebitCredit($MyRow1['ActualProfit']), + colDebitCredit($MyRow1['BudgetProfit']), + colDebitCredit($MyRow1['LastProfit']), + '</tr> + <tr class="EvenTableRows"> + <td> </td> + <td class="text">', _('Dividends'), '</td>'; + // Dividends: + $Sql = "SELECT + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN chartdetails.actual ELSE 0 END) AS ActualRetained, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN chartdetails.budget ELSE 0 END) AS BudgetRetained, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN chartdetails.actual ELSE 0 END) AS LastRetained + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 + AND chartdetails.accountcode!='" . $_SESSION['PeriodProfitAccount'] . "' + AND chartdetails.accountcode!='" . $_SESSION['RetainedEarningsAccount'] . "'";// Gets retained earnings by the complement method to include differences. The complement method: Changes(retained earnings) = -Changes(other accounts). + $MyRow2 = DB_fetch_array(DB_query($Sql)); + echo colDebitCredit($MyRow2['ActualRetained'] - $MyRow1['ActualProfit']), + colDebitCredit($MyRow2['BudgetRetained'] - $MyRow1['BudgetProfit']), + colDebitCredit($MyRow2['LastRetained'] - $MyRow1['LastProfit']), + '</tr><tr>', + '<td class="text" colspan="2">', _('Retained earnings'), '</td>', + // Retained earnings changes: + colDebitCredit($MyRow2['ActualRetained']), + colDebitCredit($MyRow2['BudgetRetained']), + colDebitCredit($MyRow2['LastRetained']), + '</tr>'; + $ActualTotal += $MyRow2['ActualRetained']; + $BudgetTotal += $MyRow2['BudgetRetained']; + $LastTotal += $MyRow2['LastRetained']; + // Cash flows sections: + $BudgetSection = 0; + $BudgetTotal = 0; + $Sql = "SELECT + chartmaster.cashflowsactivity, + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN -chartdetails.actual ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN -chartdetails.budget ELSE 0 END) AS BudgetAmount, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN -chartdetails.actual ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity!=4 + GROUP BY + chartdetails.accountcode + ORDER BY + chartmaster.cashflowsactivity, + chartdetails.accountcode"; + $Result = DB_query($Sql); + $IdSection = -1; + // Looks for an account without setting up: + $NeedSetup = FALSE; + foreach($Result as $MyRow) { + if($MyRow['cashflowsactivity'] == -1) { + $NeedSetup = TRUE; + echo '<tr><td colspan="8"> </td></tr>'; + break; + } + } + foreach($Result as $MyRow) { + if($IdSection <> $MyRow['cashflowsactivity']) { + // Prints section total: + echo '<tr> + <td class="text" colspan="2">', CashFlowsActivityName($IdSection), '</td>', + colDebitCredit($ActualSection), + colDebitCredit($BudgetSection), + colDebitCredit($LastSection), + '</tr>'; + // Resets section totals: + $ActualSection = 0; + $BudgetSection = 0; + $LastSection = 0; + $IdSection = $MyRow['cashflowsactivity']; + // Prints next section title: + echo '<tr> + <td class="text" colspan="8"><br /><h2>', CashFlowsActivityName($IdSection), '</h2></td> + </tr>'; + } + if($MyRow['ActualAmount']<>0 + OR $MyRow['BudgetAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?FromPeriod=', $_POST['PeriodFrom'], '&ToPeriod=', $_POST['PeriodTo'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['BudgetAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + $ActualSection += $MyRow['ActualAmount']; + $ActualTotal += $MyRow['ActualAmount']; + $BudgetSection += $MyRow['BudgetAmount']; + $BudgetTotal += $MyRow['BudgetAmount']; + $LastSection += $MyRow['LastAmount']; + $LastTotal += $MyRow['LastAmount']; + } + } + // Prints the last section total: + echo '<tr> + <td class="text" colspan="2">', CashFlowsActivityName($IdSection), '</td>', + colDebitCredit($ActualSection), + colDebitCredit($BudgetSection), + colDebitCredit($LastSection), + '</tr> + <tr><td colspan="8"> </td></tr>', + // Prints Net increase in cash and cash equivalents: + '<tr> + <td class="text" colspan="2"><b>', _('Net increase in cash and cash equivalents'), '</b></td>', + colDebitCredit($ActualTotal), + colDebitCredit($BudgetTotal), + colDebitCredit($LastTotal), + '</tr>'; + // Prints Cash and cash equivalents at beginning of period: + if($_POST['ShowCash']) { + // Prints a detail of Cash and cash equivalents at beginning of period (Parameters: PeriodFrom, PeriodTo, ShowBudget=on, ShowZeroBalance=on/off, ShowCash=ON): + echo '<tr><td colspan="8"> </td></tr>'; + $ActualBeginning = 0; + $BudgetBeginning = 0; + $LastBeginning = 0; + $Sql = "SELECT + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period = '" . $_POST['PeriodFrom'] . "') THEN chartdetails.bfwd ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period = '" . $_POST['PeriodFrom'] . "') THEN chartdetails.bfwdbudget ELSE 0 END) AS BudgetAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodFrom']-12) . "') THEN chartdetails.bfwd ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4 + GROUP BY chartdetails.accountcode + ORDER BY chartdetails.accountcode"; + $Result = DB_query($Sql); + foreach($Result as $MyRow) { + if($MyRow['ActualAmount']<>0 + OR $MyRow['BudgetAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?Period=', $_POST['PeriodFrom'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['BudgetAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + $ActualBeginning += $MyRow['ActualAmount']; + $BudgetBeginning += $MyRow['BudgetAmount']; + $LastBeginning += $MyRow['LastAmount']; + } + } + } else { + // Prints a summary of Cash and cash equivalents at beginning of period (Parameters: PeriodFrom, PeriodTo, ShowBudget=on, ShowZeroBalance=on/off, ShowCash=OFF): + $Sql = "SELECT + Sum(CASE WHEN (chartdetails.period = '" . $_POST['PeriodFrom'] . "') THEN chartdetails.bfwd ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period = '" . $_POST['PeriodFrom'] . "') THEN chartdetails.bfwdbudget ELSE 0 END) AS BudgetAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodFrom']-12) . "') THEN chartdetails.bfwd ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4"; + $Result = DB_query($Sql); + $MyRow = DB_fetch_array($Result); + $ActualBeginning = $MyRow['ActualAmount']; + $BudgetBeginning = $MyRow['BudgetAmount']; + $LastBeginning = $MyRow['LastAmount']; + } + echo '<tr> + <td class="text" colspan="2"><b>', _('Cash and cash equivalents at beginning of period'), '</b></td>', + colDebitCredit($ActualBeginning), + colDebitCredit($BudgetBeginning), + colDebitCredit($LastBeginning), + '</tr>'; + // Prints Cash and cash equivalents at end of period: + if($_POST['ShowCash']) { + // Prints a detail of Cash and cash equivalents at end of period (Parameters: PeriodFrom, PeriodTo, ShowBudget=on, ShowZeroBalance=on/off, ShowCash=ON): + echo '<tr><td colspan="8"> </td></tr>'; + $Sql = "SELECT + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodTo']+1) . "') THEN chartdetails.bfwd ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodTo']+1) . "') THEN chartdetails.bfwdbudget ELSE 0 END) AS BudgetAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodTo']-11) . "') THEN chartdetails.bfwd ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4 + GROUP BY chartdetails.accountcode + ORDER BY chartdetails.accountcode"; + $Result = DB_query($Sql); + foreach($Result as $MyRow) { + if($MyRow['ActualAmount']<>0 + OR $MyRow['BudgetAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?Period=', $_POST['PeriodTo'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['BudgetAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + } + } + } + // Prints Cash and cash equivalents at end of period total: + echo '<tr> + <td class="text" colspan="2"><b>', _('Cash and cash equivalents at end of period'), '</b></td>', + colDebitCredit($ActualTotal+$ActualBeginning), + colDebitCredit($BudgetTotal+$BudgetBeginning), + colDebitCredit($LastTotal+$LastBeginning), + '</tr>'; + // Prints 'Cash or cash equivalent' section if selected (Parameters: PeriodFrom, PeriodTo, ShowBudget=on, ShowZeroBalance=on/off, ShowCash=ON): + if($_POST['ShowCash']) { + // Prints 'Cash or cash equivalent' section title: + echo '<tr><td colspan="8"> </td><tr> + <tr> + <td class="text" colspan="8"><br /><h2>', CashFlowsActivityName(4), '</h2></td> + </tr>'; + // Initialise 'Cash or cash equivalent' section accumulators: + $ActualCash = 0; + $BudgetCash = 0; + $LastCash = 0; + $Sql = "SELECT + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN chartdetails.actual ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN chartdetails.budget ELSE 0 END) AS BudgetAmount, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN chartdetails.actual ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4 + GROUP BY chartdetails.accountcode + ORDER BY + chartdetails.accountcode"; + $Result = DB_query($Sql); + foreach($Result as $MyRow) { + if($MyRow['ActualAmount']<>0 + OR $MyRow['BudgetAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?FromPeriod=', $_POST['PeriodFrom'], '&ToPeriod=', $_POST['PeriodTo'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['BudgetAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + $ActualCash += $MyRow['ActualAmount']; + $BudgetCash += $MyRow['BudgetAmount']; + $LastCash += $MyRow['LastAmount']; + } + } + // Prints 'Cash or cash equivalent' section total: + echo '<tr> + <td class="text" colspan="2">', CashFlowsActivityName(4), '</td>', + colDebitCredit($ActualCash), + colDebitCredit($BudgetCash), + colDebitCredit($LastCash), + '</tr>'; + } +//<<++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + // END Outputs the table with budget. + } else {// Parameters: PeriodFrom, PeriodTo, ShowBudget=OFF, ShowZeroBalance=on/off, ShowCash=on/off. + // BEGIN Outputs the table without budget. + // Code maintenance note: To update 'Outputs the table withOUT budget', copy 'Outputs the table with budget' and remove lines with 'budget'. +//---------------------------------------------------------------------------->> + echo '<th colspan="2">', _('Last Year'), '</th> + </tr> + </thead><tfoot> + <tr>', + '<td class="text" colspan="8">',// Prints an explanation of signs in actual and relative changes: + '<br /><b>', _('Notes'), ':</b><br />', + _('Cash flows signs: a negative number indicates a cash flow used in activities; a positive number indicates a cash flow provided by activities.'), '<br />'; + if($_POST['ShowCash']) { + echo _('Cash and cash equivalents signs: a negative number indicates a cash outflow; a positive number indicates a cash inflow.'), '<br />'; + } + echo '</td> + </tr> + </tfoot><tbody>'; + // Net profit − dividends = Retained earnings: + echo '<tr> + <td class="text" colspan="8"><br /><h2>', _('Net profit and dividends'), '</h2></td> + </tr> + <tr class="OddTableRows"> + <td> </td> + <td class="text">', _('Net profit for the period'), '</td>'; + // Net profit for the period: + $Sql = "SELECT + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN -chartdetails.actual ELSE 0 END) AS ActualProfit, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN -chartdetails.actual ELSE 0 END) AS LastProfit + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=1"; + $MyRow1 = DB_fetch_array(DB_query($Sql)); + echo colDebitCredit($MyRow1['ActualProfit']), + colDebitCredit($MyRow1['LastProfit']), + '</tr> + <tr class="EvenTableRows"> + <td> </td> + <td class="text">', _('Dividends'), '</td>'; + // Dividends: + $Sql = "SELECT + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN chartdetails.actual ELSE 0 END) AS ActualRetained, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN chartdetails.actual ELSE 0 END) AS LastRetained + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 + AND chartdetails.accountcode!='" . $_SESSION['PeriodProfitAccount'] . "' + AND chartdetails.accountcode!='" . $_SESSION['RetainedEarningsAccount'] . "'";// Gets retained earnings by the complement method to include differences. The complement method: Changes(retained earnings) = -Changes(other accounts). + $MyRow2 = DB_fetch_array(DB_query($Sql)); + echo colDebitCredit($MyRow2['ActualRetained'] - $MyRow1['ActualProfit']), + colDebitCredit($MyRow2['LastRetained'] - $MyRow1['LastProfit']), + '</tr><tr>', + '<td class="text" colspan="2">', _('Retained earnings'), '</td>', + // Retained earnings changes: + colDebitCredit($MyRow2['ActualRetained']), + colDebitCredit($MyRow2['LastRetained']), + '</tr>'; + $ActualTotal += $MyRow2['ActualRetained']; + $LastTotal += $MyRow2['LastRetained']; + // Cash flows sections: + $Sql = "SELECT + chartmaster.cashflowsactivity, + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN -chartdetails.actual ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN -chartdetails.actual ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity!=4 + GROUP BY + chartdetails.accountcode + ORDER BY + chartmaster.cashflowsactivity, + chartdetails.accountcode"; + $Result = DB_query($Sql); + $IdSection = -1; + // Looks for an account without setting up: + $NeedSetup = FALSE; + foreach($Result as $MyRow) { + if($MyRow['cashflowsactivity'] == -1) { + $NeedSetup = TRUE; + echo '<tr><td colspan="8"> </td></tr>'; + break; + } + } + foreach($Result as $MyRow) { + if($IdSection <> $MyRow['cashflowsactivity']) { + // Prints section total: + echo '<tr> + <td class="text" colspan="2">', CashFlowsActivityName($IdSection), '</td>', + colDebitCredit($ActualSection), + colDebitCredit($LastSection), + '</tr>'; + // Resets section totals: + $ActualSection = 0; + $LastSection = 0; + $IdSection = $MyRow['cashflowsactivity']; + // Prints next section title: + echo '<tr> + <td class="text" colspan="8"><br /><h2>', CashFlowsActivityName($IdSection), '</h2></td> + </tr>'; + } + if($MyRow['ActualAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?FromPeriod=', $_POST['PeriodFrom'], '&ToPeriod=', $_POST['PeriodTo'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + $ActualSection += $MyRow['ActualAmount']; + $ActualTotal += $MyRow['ActualAmount']; + $LastSection += $MyRow['LastAmount']; + $LastTotal += $MyRow['LastAmount']; + } + } + // Prints the last section total: + echo '<tr> + <td class="text" colspan="2">', CashFlowsActivityName($IdSection), '</td>', + colDebitCredit($ActualSection), + colDebitCredit($LastSection), + '</tr> + <tr><td colspan="8"> </td></tr>', + // Prints Net increase in cash and cash equivalents: + '<tr> + <td class="text" colspan="2"><b>', _('Net increase in cash and cash equivalents'), '</b></td>', + colDebitCredit($ActualTotal), + colDebitCredit($LastTotal), + '</tr>'; + // Prints Cash and cash equivalents at beginning of period: + if($_POST['ShowCash']) { + // Prints a detail of Cash and cash equivalents at beginning of period (Parameters: PeriodFrom, PeriodTo, ShowBudget=OFF, ShowZeroBalance=on/off, ShowCash=ON): + echo '<tr><td colspan="8"> </td></tr>'; + $ActualBeginning = 0; + $LastBeginning = 0; + $Sql = "SELECT + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period = '" . $_POST['PeriodFrom'] . "') THEN chartdetails.bfwd ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodFrom']-12) . "') THEN chartdetails.bfwd ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4 + GROUP BY chartdetails.accountcode + ORDER BY chartdetails.accountcode"; + $Result = DB_query($Sql); + foreach($Result as $MyRow) { + if($MyRow['ActualAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?Period=', $_POST['PeriodFrom'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + $ActualBeginning += $MyRow['ActualAmount']; + $LastBeginning += $MyRow['LastAmount']; + } + } + } else { + // Prints a summary of Cash and cash equivalents at beginning of period (Parameters: PeriodFrom, PeriodTo, ShowBudget=OFF, ShowZeroBalance=on/off, ShowCash=OFF): + $Sql = "SELECT + Sum(CASE WHEN (chartdetails.period = '" . $_POST['PeriodFrom'] . "') THEN chartdetails.bfwd ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodFrom']-12) . "') THEN chartdetails.bfwd ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4"; + $Result = DB_query($Sql); + $MyRow = DB_fetch_array($Result); + $ActualBeginning = $MyRow['ActualAmount']; + $LastBeginning = $MyRow['LastAmount']; + } + echo '<tr> + <td class="text" colspan="2"><b>', _('Cash and cash equivalents at beginning of period'), '</b></td>', + colDebitCredit($ActualBeginning), + colDebitCredit($LastBeginning), + '</tr>'; + // Prints Cash and cash equivalents at end of period: + if($_POST['ShowCash']) { + // Prints a detail of Cash and cash equivalents at end of period (Parameters: PeriodFrom, PeriodTo, ShowBudget=OFF, ShowZeroBalance=on/off, ShowCash=ON): + echo '<tr><td colspan="8"> </td></tr>'; + $Sql = "SELECT + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodTo']+1) . "') THEN chartdetails.bfwd ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period = '" . ($_POST['PeriodTo']-11) . "') THEN chartdetails.bfwd ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4 + GROUP BY chartdetails.accountcode + ORDER BY chartdetails.accountcode"; + $Result = DB_query($Sql); + foreach($Result as $MyRow) { + if($MyRow['ActualAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?Period=', $_POST['PeriodTo'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + } + } + } + // Prints Cash and cash equivalents at end of period total: + echo '<tr> + <td class="text" colspan="2"><b>', _('Cash and cash equivalents at end of period'), '</b></td>', + colDebitCredit($ActualTotal+$ActualBeginning), + colDebitCredit($LastTotal+$LastBeginning), + '</tr>'; + // Prints 'Cash or cash equivalent' section if selected (Parameters: PeriodFrom, PeriodTo, ShowBudget=OFF, ShowZeroBalance=on/off, ShowCash=ON): + if($_POST['ShowCash']) { + // Prints 'Cash or cash equivalent' section title: + echo '<tr><td colspan="8"> </td><tr> + <tr> + <td class="text" colspan="8"><br /><h2>', CashFlowsActivityName(4), '</h2></td> + </tr>'; + // Initialise 'Cash or cash equivalent' section accumulators: + $ActualCash = 0; + $LastCash = 0; + $Sql = "SELECT + chartdetails.accountcode, + chartmaster.accountname, + Sum(CASE WHEN (chartdetails.period >= '" . $_POST['PeriodFrom'] . "' AND chartdetails.period <= '" . $_POST['PeriodTo'] . "') THEN chartdetails.actual ELSE 0 END) AS ActualAmount, + Sum(CASE WHEN (chartdetails.period >= '" . ($_POST['PeriodFrom']-12) . "' AND chartdetails.period <= '" . ($_POST['PeriodTo']-12) . "') THEN chartdetails.actual ELSE 0 END) AS LastAmount + FROM chartmaster + INNER JOIN chartdetails ON chartmaster.accountcode=chartdetails.accountcode + INNER JOIN accountgroups ON chartmaster.group_=accountgroups.groupname + WHERE accountgroups.pandl=0 AND chartmaster.cashflowsactivity=4 + GROUP BY chartdetails.accountcode + ORDER BY + chartdetails.accountcode"; + $Result = DB_query($Sql); + foreach($Result as $MyRow) { + if($MyRow['ActualAmount']<>0 + OR $MyRow['LastAmount']<>0 OR isset($_POST['ShowZeroBalance'])) { + if($k == 1) { + echo '<tr class="OddTableRows">'; + $k = 0; + } else { + echo '<tr class="EvenTableRows">'; + $k = 1; + } + echo '<td class="text"><a href="', $RootPath, '/GLAccountInquiry.php?FromPeriod=', $_POST['PeriodFrom'], '&ToPeriod=', $_POST['PeriodTo'], '&Account=', $MyRow['accountcode'], '">', $MyRow['accountcode'], '</a></td>', + '<td class="text">', $MyRow['accountname'], '</td>', + colDebitCredit($MyRow['ActualAmount']), + colDebitCredit($MyRow['LastAmount']), + '</tr>'; + $ActualCash += $MyRow['ActualAmount']; + $LastCash += $MyRow['LastAmount']; + } + } + // Prints 'Cash or cash equivalent' section total: + echo '<tr> + <td class="text" colspan="2">', CashFlowsActivityName(4), '</td>', + colDebitCredit($ActualCash), + colDebitCredit($LastCash), + '</tr>'; + } +//<<---------------------------------------------------------------------------- + // END Outputs the table without budget. + } + echo '</tbody></table>', + '<br />', + '<form action="', htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8'), '" method="post">', + '<input name="FormID" type="hidden" value="', $_SESSION['FormID'], '" />', + '<input name="PeriodFrom" type="hidden" value="', $_POST['PeriodFrom'], '" />', + '<input name="PeriodTo" type="hidden" value="', $_POST['PeriodTo'], '" />', + '<input name="ShowDetail" type="hidden" value="', $_POST['ShowDetail'], '" />', + '<input name="ShowZeroBalance" type="hidden" value="', $_POST['ShowZeroBalance'], '" />', + '<input name="ShowBudget" type="hidden" value="', $_POST['ShowBudget'], '" />', + '<input name="ShowCash" type="hidden" value="', $_POST['ShowCash'], '" />', // Form buttons: + '<div class="centre noprint">'; + if($NeedSetup) { + echo '<button onclick="javascript:window.location=\'GLCashFlowsSetup.php\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/maintenance.png" /> ', _('Run Setup'), '</button>'; // "Run Setup" button. + } + echo '<button onclick="javascript:window.print()" type="button"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/printer.png" /> ', _('Print This'), '</button>', // "Print This" button. + '<button name="SelectADifferentPeriod" type="submit" value="', _('Select A Different Period'), '"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/gl.png" /> ', _('Select A Different Period'), '</button>', // "Select A Different Period" button. + '<button onclick="javascript:window.location=\'index.php?Application=GL\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/return.svg" /> ', _('Return'), '</button>', // "Return" button. + '</div>'; +} else {// If one or more parameters are NOT set or NOT valid, shows a parameters input form: + echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/reports.png" title="', // Icon image. + $Title, '" /> ', // Icon title. + $Title, '</p>';// Page title. + if(!isset($page_help) OR $page_help) {// If it is not set the $page_help parameter OR it is TRUE, shows the page help text: + echo '<div class="page_help_text">', + _('The statement of cash flows, also known as cash flow statement, reports how changes in balance sheet accounts and income affect cash and cash equivalents, and breaks the analysis down to operating, investing and financing activities.'), '<br />', + _('The purpose of the statement of cash flows is to show whether the company generated and used cash during the period being reported.'), '<br />', + _('The statement of cash flows represents a period of time. This contrasts with the statement of financial position, which represents a single moment in time.'), '<br />', + _('webERP is an "accrual" based system (not a "cash based" system). Accrual systems include items when they are invoiced to the customer, and when expenses are owed based on the supplier invoice date.'), + '</div>'; + } + // Shows a form to allow input of criteria for the report to generate: + echo '<br />', + '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">', + '<input name="FormID" type="hidden" value="', $_SESSION['FormID'], '"/>', // Form's head. + // Input table: + '<table class="selection">', + // Content of the header and footer of the input table: + '<thead> + <tr> + <th colspan="2">',('Report parameters'), '</th> + </tr> + </thead><tfoot> + <tr> + <td colspan="2">', + '<div class="centre">', + '<button name="Submit" type="submit" value="', _('Submit'), '"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/tick.svg" /> ', _('Submit'), '</button>', // "Submit" button. + '<button onclick="window.location=\'index.php?Application=GL\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/return.svg" /> ', _('Return'), '</button>', // "Return" button. + '</div>', + '</td> + </tr> + </tfoot><tbody>', + // Content of the body of the input table: + // Select period from: + '<tr>', + '<td><label for="PeriodFrom">', _('Select period from'), ':</label></td> + <td><select id="PeriodFrom" name="PeriodFrom" required="required">'; + $Periods = DB_query('SELECT periodno, lastdate_in_period FROM periods ORDER BY periodno ASC'); + if(!isset($_POST['PeriodFrom'])) { + $BeginMonth =($_SESSION['YearEnd']==12 ? 1 : $_SESSION['YearEnd']+1);// Sets January as the month that follows December. + if($BeginMonth <= date('n')) {// It is a month in the current year. + $BeginDate = mktime(0, 0, 0, $BeginMonth, 1, date('Y')); + } else {// It is a month in the previous year. + $BeginDate = mktime(0, 0, 0, $BeginMonth, 1, date('Y')-1); + } + $_POST['PeriodFrom'] = GetPeriod(date($_SESSION['DefaultDateFormat'], $BeginDate), $db); + } + foreach($Periods as $MyRow) { + echo '<option',($MyRow['periodno'] == $_POST['PeriodFrom'] ? ' selected="selected"' : '' ), ' value="', $MyRow['periodno'], '">', MonthAndYearFromSQLDate($MyRow['lastdate_in_period']), '</option>'; + } + echo '</select>', + (!isset($field_help) || $field_help ? _('Select the beginning of the reporting period') : ''), // If it is not set the $field_help parameter OR it is TRUE, shows the page help text. + '</td> + </tr>', + // Select period to: + '<tr>', + '<td><label for="PeriodTo">', _('Select period to'), ':</label></td> + <td><select id="PeriodTo" name="PeriodTo" required="required">'; + if(!isset($_POST['PeriodTo'])) { + $_POST['PeriodTo'] = GetPeriod(date($_SESSION['DefaultDateFormat']), $db); + } + foreach($Periods as $MyRow) { + echo '<option',($MyRow['periodno'] == $_POST['PeriodTo'] ? ' selected="selected"' : '' ), ' value="', $MyRow['periodno'], '">', MonthAndYearFromSQLDate($MyRow['lastdate_in_period']), '</option>'; + } + echo '</select>', + (!isset($field_help) || $field_help ? _('Select the end of the reporting period') : ''), // If it is not set the $field_help parameter OR it is TRUE, shows the page help text. + '</td> + </tr>', + // Show the budget for the period: + '<tr>', + '<td><label for="ShowBudget">', _('Show the budget for the period'), ':</label></td> + <td><input',($_POST['ShowBudget'] ? ' checked="checked"' : ''), ' id="ShowBudget" name="ShowBudget" type="checkbox">', // "Checked" if ShowBudget is set AND it is TRUE. + (!isset($field_help) || $field_help ? _('Check this box to show the budget for the period') : ''), // If it is not set the $field_help parameter OR it is TRUE, shows the page help text. + '</td> + </tr>', + // Show accounts with zero balance: + '<tr>', + '<td><label for="ShowZeroBalance">', _('Show accounts with zero balance'), ':</label></td> + <td><input',(isset($_POST['ShowZeroBalance']) && $_POST['ShowZeroBalance'] ? ' checked="checked"' : ''), ' id="ShowZeroBalance" name="ShowZeroBalance" type="checkbox">', // "Checked" if ShowZeroBalance is set AND it is TRUE. + (!isset($field_help) || $field_help ? _('Check this box to show all accounts including those with zero balance') : ''), // If it is not set the $field_help parameter OR it is TRUE, shows the page help text. + '</td> + </tr>', + // Show cash and cash equivalents accounts: + '<tr>', + '<td><label for="ShowCash">', _('Show cash and cash equivalents accounts'), ':</label></td> + <td><input',($_POST['ShowCash'] ? ' checked="checked"' : ''), ' id="ShowCash" name="ShowCash" type="checkbox">', // "Checked" if ShowZeroBalance is set AND it is TRUE. + (!isset($field_help) || $field_help ? _('Check this box to show cash and cash equivalents accounts') : ''), // If it is not set the $field_help parameter OR it is TRUE, shows the page help text. + '</td> + </tr>', + '</tbody></table>'; +} +echo '</form>'; +include('includes/footer.inc'); +?> \ No newline at end of file Added: trunk/GLCashFlowsSetup.php =================================================================== --- trunk/GLCashFlowsSetup.php (rev 0) +++ trunk/GLCashFlowsSetup.php 2016-11-18 00:22:26 UTC (rev 7668) @@ -0,0 +1,239 @@ +<?php +/* $Id: GLCashFlowsSetup.php 7332 2015-08-14 03:27:51Z rchacon $*/ +/* Classifies accounts in any of the three sections of statement of cash flows to assign each account to an activity */ + +// BEGIN: Procedure division --------------------------------------------------- +include('includes/session.inc'); +$Title = _('Cash Flows Activities Maintenance'); +$ViewTopic = 'GeneralLedger'; +$BookMark = 'GLCashFlowsSetup'; +include('includes/header.inc'); + +// Merges gets into posts: +if(isset($_GET['Action'])) { + $_POST['Action'] = $_GET['Action']; +} +if(isset($_GET['PeriodProfitAccount'])) { + $_POST['PeriodProfitAccount'] = $_GET['PeriodProfitAccount']; +} +if(isset($_GET['RetainedEarningsAccount'])) { + $_POST['RetainedEarningsAccount'] = $_GET['RetainedEarningsAccount']; +} +// Do selected action: +switch ($_POST['Action']) { + case 'Update': + // Updates config accounts: + if ($_SESSION['PeriodProfitAccount'] != $_POST['PeriodProfitAccount'] ) { + if(DB_query( + "UPDATE config SET confvalue = '" . $_POST['PeriodProfitAccount'] . "' WHERE confname = 'PeriodProfitAccount'", + _('Can not update chartmaster.cashflowsactivity because') + )) { + $_SESSION['PeriodProfitAccount'] = $_POST['PeriodProfitAccount']; + prnMsg(_('The net profit of the period GL account was updated'), 'success'); + } + } + if ($_SESSION['RetainedEarningsAccount'] != $_POST['RetainedEarningsAccount'] ) { + if(DB_query( +/* "UPDATE config SET confvalue = '" . $_POST['RetainedEarningsAccount'] . "' WHERE confname = 'RetainedEarningsAccount'",*/ + "UPDATE companies SET retainedearnings = '" . $_POST['RetainedEarnings'] . "' WHERE coycode = 1", + _('Can not update chartmaster.cashflowsactivity because') + )) { + $_SESSION['RetainedEarningsAccount'] = $_POST['RetainedEarningsAccount']; + prnMsg(_('The retained earnings GL account was updated'), 'success'); + } + } + break;// END Update. + case 'Reset': + $Sql = "UPDATE `chartmaster` SET `cashflowsactivity`='-1';"; + $ErrMsg = _('Can not update chartmaster.cashflowsactivity because'); + $Result = DB_query($Sql, $ErrMsg); + if($Result) { + prnMsg(_('The cash flow activity was reset in all accounts'), 'success'); + } + break;// END Reset. + case 'Automatic': + // Loads the criteria for assigning the cash flow activity to the account: + // The last criterion overwrites the previous criteria. E.g.: + // In English, use singular to englobe singular and plural (e.g. Loan vs. Loans). + // Leave penultimate: Interests (e.g. Loan interests vs. Loans). + // Leave last: depreciations, amortisations and adjustments (Building depreciation vs. Buildings). + // Comment: MySQL queries are not case-sensitive by default. + + $Criterion = array(); + $i = 0; + + $Criterion[$i]['AccountLike'] = _('Cash'); + $Criterion[$i++]['CashFlowsActivity'] = 4; + + $Criterion[$i]['AccountLike'] = _('Bank'); + $Criterion[$i++]['CashFlowsActivity'] = 4; + + $Criterion[$i]['AccountLike'] = _('Investment'); + $Criterion[$i++]['CashFlowsActivity'] = 4; + + $Criterion[$i]['AccountLike'] = _('Commission'); + $Criterion[$i++]['CashFlowsActivity'] = 3; + + $Criterion[$i]['AccountLike'] = _('Share'); + $Criterion[$i++]['CashFlowsActivity'] = 3; + + $Criterion[$i]['AccountLike'] = _('Dividend'); + $Criterion[$i++]['CashFlowsActivity'] = 3; + + $Criterion[$i]['AccountLike'] = _('Interest'); + $Criterion[$i++]['CashFlowsActivity'] = 3; + + $Criterion[$i]['AccountLike'] = _('Loan'); + $Criterion[$i++]['CashFlowsActivity'] = 3; + + $Criterion[$i]['AccountLike'] = _('Building'); + $Criterion[$i++]['CashFlowsActivity'] = 2; + + $Criterion[$i]['AccountLike'] = _('Equipment'); + $Criterion[$i++]['CashFlowsActivity'] = 2; + + $Criterion[$i]['AccountLike'] = _('Land'); + $Criterion[$i++]['CashFlowsActivity'] = 2; + + $Criterion[$i]['AccountLike'] = _('Vehicle'); + $Criterion[$i++]['CashFlowsActivity'] = 2; + + $Criterion[$i]['AccountLike'] = _('Sale'); + $Criterion[$i++]['CashFlowsActivity'] = 1; + + $Criterion[$i]['AccountLike'] = _('Cost'); + $Criterion[$i++]['CashFlowsActivity'] = 1; + + $Criterion[$i]['AccountLike'] = _('Receivable'); + $Criterion[$i++]['CashFlowsActivity'] = 1; + + $Criterion[$i]['AccountLike'] = _('Inventory'); + $Criterion[$i++]['CashFlowsActivity'] = 1; + + $Criterion[$i]['AccountLike'] = _('Payable'); + $Criterion[$i++]['CashFlowsActivity'] = 1; + + $Criterion[$i]['AccountLike'] = _('Adjustment'); + $Criterion[$i++]['CashFlowsActivity'] = 0; + + $Criterion[$i]['AccountLike'] = _('Amortisation'); + $Criterion[$i++]['CashFlowsActivity'] = 0; + + $Criterion[$i]['AccountLike'] = _('Depreciation'); + $Criterion[$i++]['CashFlowsActivity'] = 0; + + foreach ($Criterion as $Criteria) { + $Sql = "UPDATE `chartmaster` + SET `cashflowsactivity`=". $Criteria['CashFlowsActivity'] . " + WHERE `accountname` LIKE '%". _($Criteria['AccountLike']) . "%' + AND `cashflowsactivity`=-1";// Uses cashflowsactivity=-1 to NOT overwrite. + $ErrMsg = _('Can not update chartmaster.cashflowsactivity. Error code:'); + $Result = DB_query($Sql, $ErrMsg); + // RChacon: Count replacements. + } + if($Result) { + prnMsg(_('The cash flow activity was updated in some accounts'), 'success');// RChacon: Show replacements done. + } + break;// END Automatic. + case 'Manual': + echo "<script>window.location = 'GLAccounts.php';</script>"; + die(); + default: + // No reset , nor Automatic +} + +echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, + '/images/maintenance.png" title="', // Icon image. + $Title, '" /> ', // Icon title. + $Title, '</p>';// Page title. + // BEGIN menu. +if(!isset($page_help) OR $page_help) { + // If it is not set the $page_help parameter OR it is TRUE, shows the page help text: + echo '<div class="page_help_text">', + _('The statement of cash flows, using direct and indirect methods, is partitioned into three sections: operating activities, investing activities and financing activities.'), '<br />', + _('You must classify all accounts in any of those three sections of the cash flow statement, or as no effect on cash flow, or as cash or cash equivalent.'), + '</div>'; +} +// Show a form to allow input of the action for the script to do: +echo '<br />', + '<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">', + '<input name="FormID" type="hidden" value="', $_SESSION['FormID'], '" />', // Form's head. + // Input table: + '<table class="selection">', + // Content of the header and footer of the output table: + '<thead> + <tr> + <th colspan="2">', _('Action to do'), '</th> + </tr> + </thead><tfoot> + <tr> + <td colspan="2">', + '<div class="centre">', + '<button name="Action" type=... [truncated message content] |