forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDFBankingSummary.php
247 lines (210 loc) · 8.2 KB
/
PDFBankingSummary.php
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
include ('includes/session.php');
include('includes/SQL_CommonFunctions.inc');
use Dompdf\Dompdf;
if (isset($_GET['BatchNo'])){
$_POST['BatchNo'] = $_GET['BatchNo'];
}
if (isset($_POST['PrintPDF']) or isset($_POST['View'])) {
$SQL= "SELECT bankaccountname,
bankaccountnumber,
ref,
transdate,
banktranstype,
bankact,
banktrans.exrate,
banktrans.functionalexrate,
banktrans.currcode,
currencies.decimalplaces AS currdecimalplaces
FROM bankaccounts INNER JOIN banktrans
ON bankaccounts.accountcode=banktrans.bankact
INNER JOIN currencies
ON bankaccounts.currcode=currencies.currabrev
WHERE banktrans.transno='" . $_POST['BatchNo'] . "'
AND banktrans.type=12";
$ErrMsg = _('An error occurred getting the header information about the receipt batch number') . ' ' . $_POST['BatchNo'];
$DbgMsg = _('The SQL used to get the receipt header information that failed was');
$Result=DB_query($SQL,$ErrMsg,$DbgMsg);
if (DB_num_rows($Result) == 0){
$Title = _('Create PDF Print-out For A Batch Of Receipts');
include ('includes/header.php');
prnMsg(_('The receipt batch number') . ' ' . $_POST['BatchNo'] . ' ' . _('was not found in the database') . '. ' . _('Please try again selecting a different batch number'), 'warn');
include('includes/footer.php');
exit;
}
/* OK get the row of receipt batch header info from the BankTrans table */
$MyRow = DB_fetch_array($Result);
$ExRate = $MyRow['exrate'];
$FunctionalExRate = $MyRow['functionalexrate'];
$Currency = $MyRow['currcode'];
$BankTransType = $MyRow['banktranstype'];
$BankedDate = $MyRow['transdate'];
$BankActName = $MyRow['bankaccountname'];
$BankActNumber = $MyRow['bankaccountnumber'];
$BankingReference = $MyRow['ref'];
$BankCurrDecimalPlaces = $MyRow['currdecimalplaces'];
$SQL = "SELECT debtorsmaster.name,
ovamount,
invtext,
reference
FROM debtorsmaster INNER JOIN debtortrans
ON debtorsmaster.debtorno=debtortrans.debtorno
WHERE debtortrans.transno='" . $_POST['BatchNo'] . "'
AND debtortrans.type=12";
$CustRecs=DB_query($SQL,'','',false,false);
if (DB_error_no()!=0){
$Title = _('Create PDF Print-out For A Batch Of Receipts');
include ('includes/header.php');
prnMsg(_('An error occurred getting the customer receipts for batch number') . ' ' . $_POST['BatchNo'],'error');
if ($Debug==1){
prnMsg(_('The SQL used to get the customer receipt information that failed was') . '<br />' . $SQL,'error');
}
include('includes/footer.php');
exit;
}
$SQL = "SELECT narrative,
amount
FROM gltrans
WHERE gltrans.typeno='" . $_POST['BatchNo'] . "'
AND gltrans.type=12 and gltrans.amount <0
AND gltrans.account !='" . $MyRow['bankact'] . "'
AND gltrans.account !='" . $_SESSION['CompanyRecord']['debtorsact'] . "'";
$GLRecs=DB_query($SQL,'','',false,false);
if (DB_error_no()!=0){
$Title = _('Create PDF Print-out For A Batch Of Receipts');
include ('includes/header.php');
prnMsg(_('An error occurred getting the GL receipts for batch number') . ' ' . $_POST['BatchNo'],'error');
if ($Debug==1){
prnMsg(_('The SQL used to get the GL receipt information that failed was') . ':<br />' . $SQL,'error');
}
include('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 " . $Version">
<meta name="Creator" content="webERP http://www.weberp.org">
</head>
<body>';
if (isset($_POST['PrintPDF'])) {
$HTML .= '<img class="logo" src=' . $_SESSION['LogoFile'] . ' /><br />';
}
$HTML .= '<div class="centre" id="ReportHeader">
' . $_SESSION['CompanyRecord']['coyname'] . '<br />
' . _('Banking Summary Number') . ' ' . $_POST['BatchNo'] . '<br />
' . _('Date of Banking') .': ' . ConvertSQLDate($MyRow['transdate']) . '<br />
' . _('Banked into') . ': ' . $BankActName . ' - ' . _('Account Number') . ': ' . $BankActNumber . '<br />
' . _('Reference') . ': ' . $BankingReference . '<br />
' . _('Currency') . ': ' . $Currency . '<br />
' . _('Printed') . ': ' . Date($_SESSION['DefaultDateFormat']) . '<br />
</div>
<table>
<thead>
<tr>
<th>' . _('Amount') . '</th>
<th>' . _('Customer') . '</th>
<th>' . _('Bank Details') . '</th>
<th>' . _('Narrative') . '</th>
</tr>
</thead>
<tbody>';
/*PDFStarter.php has all the variables for page size and width set up depending on the users default preferences for paper size */
while ($MyRow=DB_fetch_array($CustRecs)) {
$HTML .= '<tr class="striped_row">
<td>' . locale_number_format(-$MyRow['ovamount'],$BankCurrDecimalPlaces) . '</td>
<td>' . $MyRow['name'] . '</td>
<td>' . $MyRow['invtext'] . '</td>
<td>' . $MyRow['reference'] . '</td>
</tr>';
$TotalBanked -= $MyRow['ovamount'];
} /* end of while there are customer receipts in the batch to print */
/* Right now print out the GL receipt entries in the batch */
while ($MyRow=DB_fetch_array($GLRecs)){
$HTML .= '<tr class="striped_row">
<td>' . locale_number_format((-$MyRow['amount']*$ExRate*$FunctionalExRate),$BankCurrDecimalPlaces) . '</td>
<td></td>
<td></td>
<td>' . $MyRow['narrative'] . '</td>
</tr>';
$TotalBanked += (-$MyRow['amount']*$ExRate);
} /* end of while there are GL receipts in the batch to print */
$HTML .= '<tr class="total_row">
<td>' . locale_number_format($TotalBanked,2) . '</td>
<td>' . _('TOTAL') . ' ' . $Currency . ' ' . _('BANKED') . '</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(['chroot' => __DIR__]);
$dompdf->loadHtml($HTML);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper($_SESSION['PageSize'], 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream($_SESSION['DatabaseName'] . '_BankingSummary_' . date('Y-m-d') . '.pdf', array(
"Attachment" => false
));
} else {
$Title = _('Create PDF Print Out For A Batch Of Receipts');
include ('includes/header.php');
echo '<p class="page_title_text"><img src="' . $RootPath . '/css/' . $Theme . '/images/bank.png" title="' . _('Receipts') . '" alt="" />' . ' ' . _('Create PDF Print Out For A Batch Of Receipts') . '</p>';
echo $HTML;
include ('includes/footer.php');
}
} else { /*The option to print PDF was not hit so display form */
$Title = _('Create PDF Print Out For A Batch Of Receipts');
$ViewTopic = 'ARReports';
$BookMark = 'BankingSummary';
include ('includes/header.php');
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/magnifier.png" title="' .
$Title . '" alt="" />' . ' ' . $Title . '</p>';
$SQL="SELECT DISTINCT
transno,
transdate
FROM banktrans
WHERE type=12
ORDER BY transno DESC";
$Result=DB_query($SQL);
echo '<form method="post" action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" target="_blank">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />
<fieldset>
<legend>', _('Report Criteria'), '</legend>
<field>
<label for="BatchNo">' . _('Select the batch number of receipts to be printed') . ':</label>
<select required="required" autofocus="autofocus" name="BatchNo">';
while ($MyRow=DB_fetch_array($Result)) {
echo '<option value="'.$MyRow['transno'].'">' . _('Batch') .' '. $MyRow['transno'].' - '.ConvertSqlDate($MyRow['transdate']) . '</option>';
}
echo '</select>
</field>
</fieldset>';
echo '<div class="centre">
<input type="submit" name="PrintPDF" title="PDF" value="' . _('Print PDF') . '" />
<input type="submit" name="View" title="View" value="' . _('View') . '" />
</div>
</form>';
include ('includes/footer.php');
exit;
}
?>