-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathDebtorsAtPeriodEnd.php
More file actions
207 lines (168 loc) · 7.93 KB
/
DebtorsAtPeriodEnd.php
File metadata and controls
207 lines (168 loc) · 7.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<?php
require(__DIR__ . '/includes/session.php');
use Dompdf\Dompdf;
include(__DIR__ . '/includes/SetDomPDFOptions.php');
include(__DIR__ . '/includes/SQL_CommonFunctions.php');
if (isset($_POST['PrintPDF']) or isset($_POST['View'])) {
/*Get the date of the last day in the period selected */
$PeriodEndDate = ConvertSQLDate(EndDateSQLFromPeriodNo($_POST['PeriodEnd']));
/*Now figure out the aged analysis for the customer range under review */
$SQL = "SELECT debtorsmaster.debtorno,
debtorsmaster.name,
currencies.currency,
currencies.decimalplaces,
SUM((debtortrans.balance)/debtortrans.rate) AS balance,
SUM(debtortrans.balance) AS fxbalance,
SUM(CASE WHEN debtortrans.prd > '" . $_POST['PeriodEnd'] . "' THEN
(debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount)/debtortrans.rate ELSE 0 END) AS afterdatetrans,
SUM(CASE WHEN debtortrans.prd > '" . $_POST['PeriodEnd'] . "'
AND (debtortrans.type=11 OR debtortrans.type=12) THEN
debtortrans.diffonexch ELSE 0 END) AS afterdatediffonexch,
SUM(CASE WHEN debtortrans.prd > '" . $_POST['PeriodEnd'] . "' THEN
debtortrans.ovamount + debtortrans.ovgst + debtortrans.ovfreight + debtortrans.ovdiscount ELSE 0 END
) AS fxafterdatetrans
FROM debtorsmaster INNER JOIN currencies
ON debtorsmaster.currcode = currencies.currabrev
INNER JOIN debtortrans
ON debtorsmaster.debtorno = debtortrans.debtorno
WHERE debtorsmaster.debtorno >= '" . $_POST['FromCriteria'] . "'
AND debtorsmaster.debtorno <= '" . $_POST['ToCriteria'] . "'
GROUP BY debtorsmaster.debtorno,
debtorsmaster.name,
currencies.currency,
currencies.decimalplaces";
$ErrMsg = ('The customer details could not be retrieved');
$CustomerResult = DB_query($SQL, $ErrMsg);
if (DB_num_rows($CustomerResult) == 0) {
$Title = __('Customer Balances') . ' - ' . __('Problem Report');
include(__DIR__ . '/includes/header.php');
prnMsg(__('The customer details listing has no clients to report on'),'warn');
echo '<br /><a href="' . $RootPath . '/index.php">' . __('Back to the menu') . '</a>';
include(__DIR__ . '/includes/footer.php');
exit();
}
$HTML = '';
if (isset($_POST['PrintPDF'])) {
$HTML .= '<html>
<head>';
$HTML .= '<link href="css/reports.css" rel="stylesheet" type="text/css" />';
}
$HTML .= '<meta name="author" content="WebERP">
<meta name="Creator" content="webERP https://www.weberp.org">
</head>
<body>
<div class="centre" id="ReportHeader">
' . $_SESSION['CompanyRecord']['coyname'] . '<br />
' . __('Customer Balances For Customers between') . ' ' . $_POST['FromCriteria'] . ' ' . __('and') . ' ' . $_POST['ToCriteria'] . ' ' . __('as at') . ' ' . $PeriodEndDate . '<br />
' . __('Printed') . ': ' . date($_SESSION['DefaultDateFormat']) . '<br />
</div>
<table>
<thead>
<tr>
<th>' . __('Customer') . '</th>
<th>' . __('Balance') . '</th>
<th>' . __('FX') . '</th>
<th>' . __('Currency') . '</th>
</tr>
</thead>
<tbody>';
$TotBal=0;
while ($DebtorBalances = DB_fetch_array($CustomerResult)){
$Balance = $DebtorBalances['balance'] - $DebtorBalances['afterdatetrans'] + $DebtorBalances['afterdatediffonexch'] ;
$FXBalance = $DebtorBalances['fxbalance'] - $DebtorBalances['fxafterdatetrans'];
if (ABS($Balance) > CurrencyTolerance($_SESSION['CompanyRecord']['currencydefault'])
OR ABS($FXBalance) > CurrencyTolerance($DebtorBalances['currency'])) {
$DisplayBalance = locale_number_format($DebtorBalances['balance'] - $DebtorBalances['afterdatetrans'],$DebtorBalances['decimalplaces']);
$DisplayFXBalance = locale_number_format($DebtorBalances['fxbalance'] - $DebtorBalances['fxafterdatetrans'],$DebtorBalances['decimalplaces']);
$TotBal += $Balance;
$HTML .= '<tr class="striped_row">
<td>' . $DebtorBalances['debtorno'] . ' - ' . html_entity_decode($DebtorBalances['name'],ENT_QUOTES,'UTF-8') . '</td>
<td class="number">' . $DisplayBalance . '</td>
<td class="number">' . $DisplayFXBalance . '</td>
<td class="number">' . $DebtorBalances['currency'] . '</td>
</tr>';
}
} /*end customer aged analysis while loop */
$DisplayTotBalance = locale_number_format($TotBal,$_SESSION['CompanyRecord']['decimalplaces']);
$HTML .= '<tr class="total_row">
<td>' . __('Total balances') . '</td>
<td class="number">' . $DisplayTotBalance . '</td>
<td colspan="2"></td>
</tr>';
if (isset($_POST['PrintPDF'])) {
$HTML .= '</tbody>
<div class="footer fixed-section">
<div class="right">
<span class="page-number">Page </span>
</div>
</div>
</table>';
} else {
$HTML .= '</tbody>
</table>
<div class="centre">
<form><input type="submit" name="close" value="' . __('Close') . '" onclick="window.close()" /></form>
</div>';
}
$HTML .= '</body>
</html>';
if (isset($_POST['PrintPDF'])) {
$DomPDF = new Dompdf($DomPDFOptions); // Pass the options object defined in SetDomPDFOptions.php containing common options
$DomPDF->loadHtml($HTML);
// (Optional) Setup the paper size and orientation
$DomPDF->setPaper($_SESSION['PageSize'], 'landscape');
// Render the HTML as PDF
$DomPDF->render();
// Output the generated PDF to Browser
$DomPDF->stream($_SESSION['DatabaseName'] . '_DebtorBals_' . date('Y-m-d') . '.pdf', array(
"Attachment" => false
));
} else {
$Title = __('Debtor Balances');
include(__DIR__ . '/includes/header.php');
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/maintenance.png" title="' . $Title . '" alt="" />' . ' ' . $Title . '</p>';
echo $HTML;
include(__DIR__ . '/includes/footer.php');
}
} else { /*The option to print PDF was not hit */
$Title=__('Debtor Balances');
$ViewTopic = 'ARReports';
$BookMark = 'PriorMonthDebtors';
include(__DIR__ . '/includes/header.php');
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/customer.png" title="' . __('Search') .
'" alt="" />' . ' ' . $Title . '</p>';
if (!isset($_POST['FromCriteria']) OR !isset($_POST['ToCriteria'])) {
/*if $FromCriteria is not set then show a form to allow input */
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post" target="_blank">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<fieldset>
<legend>', __('Report Criteria'), '</legend>';
echo '<field>
<label for="FromCriteria">' . __('From Customer Code') .':</label>
<input tabindex="1" type="text" maxlength="10" size="8" name="FromCriteria" required="required" data-type="no-illegal-chars" title="" value="1" />
<fieldhelp>' . __('Enter a portion of the code of first customer to report') . '</fieldhelp>
</field>
<field>
<label for="ToCriteria">' . __('To Customer Code') . ':</label>
<input tabindex="2" type="text" maxlength="10" size="8" name="ToCriteria" required="required" data-type="no-illegal-chars" title="" value="zzzzzz" />
<fieldhelp>' . __('Enter a portion of the code of last customer to report') . '</fieldhelp>
</field>
<field>
<label for="PeriodEnd">' . __('Balances As At') . ':</label>
<select tabindex="3" name="PeriodEnd">';
$SQL = "SELECT periodno, lastdate_in_period FROM periods ORDER BY periodno DESC";
$Periods = DB_query($SQL,__('Could not retrieve period data because'),__('The SQL that failed to get the period data was'));
while ($MyRow = DB_fetch_array($Periods)){
echo '<option value="' . $MyRow['periodno'] . '">' . MonthAndYearFromSQLDate($MyRow['lastdate_in_period']) . '</option>';
}
}
echo '</select>
</field>
</fieldset>
<div class="centre">
<input type="submit" name="PrintPDF" title="Produce PDF Report" value="' . __('Print PDF') . '" />
<input type="submit" name="View" title="View Report" value="' . __('View') . '" />
</div>
</form>';
include(__DIR__ . '/includes/footer.php');
} /*end of else not PrintPDF */