Skip to content

Commit

Permalink
Merge pull request #147 from rafa62/master
Browse files Browse the repository at this point in the history
Clean up and standardise code
  • Loading branch information
rafa62 committed Jan 17, 2019
2 parents 69a8c16 + 7eea667 commit f0c064c
Show file tree
Hide file tree
Showing 2 changed files with 188 additions and 200 deletions.
194 changes: 94 additions & 100 deletions PurchasesReport.php
@@ -1,113 +1,51 @@
<?php
// PurchasesReport.php
// Shows a report of purchases from suppliers for the range of selected dates.
// This program is under the GNU General Public License, last version. 2016-12-18.
// This creative work is under the CC BY-NC-SA, last version. 2016-12-18.
/* PurchasesReport.php
Shows a report of purchases from suppliers for the range of selected dates.
This program is under the GNU General Public License, last version. 2016-12-18.
This creative work is under the CC BY-NC-SA, last version. 2016-12-18.
// Notes:
// Coding Conventions/Style: http://www.weberp.org/CodingConventions.html

/*
This script is "mirror-symmetric" to script SalesReport.php
This script is "mirror-symmetric" to script SalesReport.php.
*/

// BEGIN: Functions division ===================================================
// END: Functions division =====================================================

// BEGIN: Procedure division ===================================================
include('includes/session.php');
$Title = _('Purchases from Suppliers');
$ViewTopic = 'PurchaseOrdering';
$BookMark = 'PurchasesReport';

// BEGIN Functions division ====================================================
// END Functions division ======================================================

// BEGIN Data division =========================================================
// END Data division ===========================================================

// BEGIN Procedure division ====================================================
include('includes/header.php');
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.

// Merges gets into posts:
if(isset($_GET['PeriodFrom'])) {// Select period from.
if(isset($_GET['PeriodFrom'])) {
$_POST['PeriodFrom'] = $_GET['PeriodFrom'];
}
if(isset($_GET['PeriodTo'])) {// Select period to.
if(isset($_GET['PeriodTo'])) {
$_POST['PeriodTo'] = $_GET['PeriodTo'];
}
if(isset($_GET['ShowDetails'])) {// Show purchase invoices for the period.
if(isset($_GET['ShowDetails'])) {
$_POST['ShowDetails'] = $_GET['ShowDetails'];
}

// Validates the data submitted in the form:
if(isset($_POST['PeriodFrom']) AND isset($_POST['PeriodTo'])) {
if(Date1GreaterThanDate2($_POST['PeriodFrom'], $_POST['PeriodTo'])) {
// The beginning is after the end.
unset($_POST['PeriodFrom']);
unset($_POST['PeriodTo']);
$_POST['NewReport'] = 'on';
prnMsg(_('The beginning of the period should be before or equal to the end of the period. Please reselect the reporting period.'), 'error');
}
}

// Main code:
if(!isset($_POST['PeriodFrom']) OR !isset($_POST['PeriodTo']) OR $_POST['Action']=='New') {
// If one or more parameters are not set or it is a new report, shows a form to allow input of criteria for the report to generate:
echo
'<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">',
'<input name="FormID" type="hidden" value="', $_SESSION['FormID'], '" />',
// 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="Action" type="submit" value="', _('Submit'), '"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/tick.svg" /> ', _('Submit'), '</button>', // "Submit" button.
'<button onclick="window.location=\'index.php?Application=PO\'" 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">', _('Period from'), '</label></td>';
if(!isset($_POST['PeriodFrom'])) {
$_POST['PeriodFrom'] = date($_SESSION['DefaultDateFormat'], strtotime("-1 year", time()));// One year before current date.
}
echo '<td><input class="date" id="PeriodFrom" maxlength="10" name="PeriodFrom" required="required" size="11" type="text" value="', $_POST['PeriodFrom'], '" />',
fShowFieldHelp(_('Select the beginning of the reporting period')), // Function fShowFieldHelp() in ~/includes/MiscFunctions.php
'</td>
</tr>',
// Select period to:
'<tr>',
'<td><label for="PeriodTo">', _('Period to'), '</label></td>';
if(!isset($_POST['PeriodTo'])) {
$_POST['PeriodTo'] = date($_SESSION['DefaultDateFormat']);
}
echo '<td><input class="date" id="PeriodTo" maxlength="10" name="PeriodTo" required="required" size="11" type="text" value="', $_POST['PeriodTo'], '" />',
fShowFieldHelp(_('Select the end of the reporting period')), // Function fShowFieldHelp() in ~/includes/MiscFunctions.php
'</td>
</tr>',
// Show the budget for the period:
'<tr>',
'<td><label for="ShowDetails">', _('Show details'), '</label></td>',
'<td>',
'<input', (isset($_POST['ShowDetails']) && $_POST['ShowDetails'] ? ' checked="checked"' : ''), ' id="ShowDetails" name="ShowDetails" type="checkbox">', // If $_POST['ShowDetails'] is set AND it is TRUE, shows this input checked.
fShowFieldHelp(_('Check this box to show purchase invoices')), // Function fShowFieldHelp() in ~/includes/MiscFunctions.php
'</td>
</tr>',
'</tbody></table>';
} else {
// If all parameters are set and valid, generates the report:
echo '<p>', _('Period from'), ': ', $_POST['PeriodFrom'],
if(isset($_POST['PeriodFrom']) AND isset($_POST['PeriodTo']) AND !$_POST['NewReport']) {
// If PeriodFrom and PeriodTo are set and it is not a NewReport, generates the report:
echo '<div class="sheet">', // Division to identify the report block.
'<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, '/images/reports.png" title="', // Icon image.
$Title, '" /> ', // Icon title.
$Title, '</p>', // Page title.
'<p>', _('Period from'), ': ', $_POST['PeriodFrom'],
'<br />', _('Period to'), ': ', $_POST['PeriodTo'], '</p>',
'<table class="selection">
<thead>
Expand Down Expand Up @@ -145,7 +83,7 @@
$SupplierOvTax = 0;
$SupplierGlAmount = 0;
$SupplierGlTax = 0;
$Sql = "SELECT
$SQL = "SELECT
supptrans.supplierno,
suppliers.suppname,
suppliers.currcode,
Expand All @@ -161,7 +99,7 @@
AND supptrans.trandate<='" . $PeriodTo . "'
AND supptrans.`type`=20
ORDER BY supptrans.supplierno, supptrans.trandate";
$Result = DB_query($Sql);
$Result = DB_query($SQL);
foreach($Result as $MyRow) {
if($MyRow['supplierno'] != $SupplierId) {// If different, prints supplier totals:
if($SupplierId != '') {// If NOT the first line.
Expand Down Expand Up @@ -226,7 +164,7 @@
'<th>', _('Supplier Name'), '</th>',
'<th>', _('Supplier\'s Currency'), '</th>',
$CommonHead;
$Sql = "SELECT
$SQL = "SELECT
supptrans.supplierno,
suppliers.suppname,
suppliers.currcode,
Expand All @@ -242,7 +180,7 @@
GROUP BY
supptrans.supplierno
ORDER BY supptrans.supplierno, supptrans.trandate";
$Result = DB_query($Sql);
$Result = DB_query($SQL);
foreach($Result as $MyRow) {
echo '<tr class="striped_row">',
'<td class="text">', $MyRow['supplierno'], '</td>',
Expand All @@ -266,21 +204,77 @@
<td class="number">', locale_number_format($TotalGlTax, $_SESSION['CompanyRecord']['decimalplaces']), '</td>
<td class="number">', locale_number_format($TotalGlAmount+$TotalGlTax, $_SESSION['CompanyRecord']['decimalplaces']), '</td>
</tr>',
'</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="ShowDetails" type="hidden" value="', $_POST['ShowDetails'], '" />
<div class="centre noprint">', // Form buttons:
'<button onclick="javascript:window.print()" type="button"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/printer.png" /> ', _('Print'), '</button>', // "Print" button.
'<button name="Action" type="submit" value="New"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/reports.png" /> ', _('New Report'), '</button>', // "New Report" button.
'<button onclick="window.location=\'index.php?Application=PO\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme,
'/images/return.svg" /> ', _('Return'), '</button>', // "Return" button.
'</tbody></table>',
'</div>', // div id="Report".
// Shows a form to select an action after the report was shown:
'<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">',
'<input name="FormID" type="hidden" value="', $_SESSION['FormID'], '" />',
// Resend report parameters:
'<input name="PeriodFrom" type="hidden" value="', $_POST['PeriodFrom'], '" />',
'<input name="PeriodTo" type="hidden" value="', $_POST['PeriodTo'], '" />',
'<input name="ShowDetails" type="hidden" value="', $_POST['ShowDetails'], '" />',
'<div class="centre noprint">', // Form buttons:
'<button onclick="window.print()" type="button"><img alt="" src="', $RootPath, '/css/', $Theme, '/images/printer.png" /> ', _('Print'), '</button>', // "Print" button.
'<button name="NewReport" type="submit" value="on"><img alt="" src="', $RootPath, '/css/', $Theme, '/images/reports.png" /> ', _('New Report'), '</button>', // "New Report" button.
'<button onclick="window.location=\'index.php?Application=PO\'" type="button"><img alt="" src="', $RootPath, '/css/', $Theme, '/images/return.svg" /> ', _('Return'), '</button>', // "Return" button.
'</div>';
} else {
// If PeriodFrom or PeriodTo are NOT set or it is a NewReport, shows a parameters input form:
echo '<p class="page_title_text"><img alt="" src="', $RootPath, '/css/', $Theme, '/images/gl.png" title="', // Icon image.
$Title, '" /> ', // Icon title.
$Title, '</p>';// Page title.
fShowPageHelp(// Shows the page help text if $_SESSION['ShowFieldHelp'] is TRUE or is not set
_('Shows a report of purchases from suppliers for the range of selected dates.'));// Function fShowPageHelp() in ~/includes/MiscFunctions.php
echo // Shows a form to input the report parameters:
'<form action="', htmlspecialchars($_SERVER['PHP_SELF'], ENT_QUOTES, 'UTF-8'), '" method="post">',
'<input name="FormID" type="hidden" value="', $_SESSION['FormID'], '" />',
// 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=PO\'" 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">', _('Period from'), '</label></td>';
if(!isset($_POST['PeriodFrom'])) {
$_POST['PeriodFrom'] = date($_SESSION['DefaultDateFormat'], strtotime("-1 year", time()));// One year before current date.
}
echo '<td><input class="date" id="PeriodFrom" maxlength="10" name="PeriodFrom" required="required" size="11" type="text" value="', $_POST['PeriodFrom'], '" />',
fShowFieldHelp(_('Select the beginning of the reporting period')), // Function fShowFieldHelp() in ~/includes/MiscFunctions.php
'</td>
</tr>',
// Select period to:
'<tr>',
'<td><label for="PeriodTo">', _('Period to'), '</label></td>';
if(!isset($_POST['PeriodTo'])) {
$_POST['PeriodTo'] = date($_SESSION['DefaultDateFormat']);
}
echo '<td><input class="date" id="PeriodTo" maxlength="10" name="PeriodTo" required="required" size="11" type="text" value="', $_POST['PeriodTo'], '" />',
fShowFieldHelp(_('Select the end of the reporting period')), // Function fShowFieldHelp() in ~/includes/MiscFunctions.php
'</td>
</tr>',
// Show the budget for the period:
'<tr>',
'<td><label for="ShowDetails">', _('Show details'), '</label></td>',
'<td>',
'<input', (isset($_POST['ShowDetails']) && $_POST['ShowDetails'] ? ' checked="checked"' : ''), ' id="ShowDetails" name="ShowDetails" type="checkbox">', // If $_POST['ShowDetails'] is set AND it is TRUE, shows this input checked.
fShowFieldHelp(_('Check this box to show purchase invoices')), // Function fShowFieldHelp() in ~/includes/MiscFunctions.php
'</td>
</tr>',
'</tbody></table>';
}
echo '</form>';
include('includes/footer.php');
Expand Down

0 comments on commit f0c064c

Please sign in to comment.