forked from timschofield/webERP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPDFRemittanceAdvice.php
321 lines (262 loc) · 12.1 KB
/
PDFRemittanceAdvice.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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
<?php
include('includes/session.php');
if (isset($_POST['PaymentDate'])){$_POST['PaymentDate'] = ConvertSQLDate($_POST['PaymentDate']);};
If ((isset($_POST['PrintPDF']))
AND isset($_POST['FromCriteria'])
AND mb_strlen($_POST['FromCriteria'])>=1
AND isset($_POST['ToCriteria'])
AND mb_strlen($_POST['ToCriteria'])>=1) {
/*Now figure out the invoice less credits due for the Supplier range under review */
$SQL = "SELECT suppliers.supplierid,
suppliers.suppname,
suppliers.address1,
suppliers.address2,
suppliers.address3,
suppliers.address4,
suppliers.address5,
suppliers.address6,
suppliers.currcode,
supptrans.id,
currencies.decimalplaces AS currdecimalplaces
FROM supptrans INNER JOIN suppliers ON supptrans.supplierno = suppliers.supplierid
INNER JOIN paymentterms ON suppliers.paymentterms = paymentterms.termsindicator
INNER JOIN currencies ON suppliers.currcode=currencies.currabrev
WHERE supptrans.type=22
AND trandate ='" . FormatDateForSQL($_POST['PaymentDate']) . "'
AND supplierno >= '" . $_POST['FromCriteria'] . "'
AND supplierno <= '" . $_POST['ToCriteria'] . "'
AND suppliers.remittance=1
ORDER BY supplierno";
$SuppliersResult = DB_query($SQL);
if (DB_num_rows($SuppliersResult)==0){
//then there aint awt to print
$Title = _('Print Remittance Advices Error');
include('includes/header.php');
prnMsg(_('There were no remittance advices to print out for the supplier range and payment date specified'),'warn');
echo '<br /><a href="'.htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '">' . _('Back') . '</a>';
include('includes/footer.php');
exit;
}
/*then print the report */
include('includes/PDFStarter.php');
$pdf->addInfo('Title',_('Remittance Advice'));
$pdf->addInfo('Subject',_('Remittance Advice') . ' - ' . _('suppliers from') . ' ' . $_POST['FromCriteria'] . ' ' . _('to') . ' ' . $_POST['ToCriteria'] . ' ' . _('and Paid On') . ' ' . $_POST['PaymentDate']);
$LineHeight=12;
$SupplierID ='';
$RemittanceAdviceCounter =0;
while ($SuppliersPaid = DB_fetch_array($SuppliersResult)){
$PageNumber=1;
PageHeader();
$RemittanceAdviceCounter++;
$SupplierID = $SuppliersPaid['supplierid'];
$SupplierName = $SuppliersPaid['suppname'];
$AccumBalance = 0;
/* Now get the transactions and amounts that the payment was allocated to */
$SQL = "SELECT systypes.typename,
supptrans.suppreference,
supptrans.trandate,
supptrans.transno,
suppallocs.amt,
(supptrans.ovamount + supptrans.ovgst ) AS trantotal
FROM supptrans
INNER JOIN systypes ON systypes.typeid = supptrans.type
INNER JOIN suppallocs ON suppallocs.transid_allocto=supptrans.id
WHERE suppallocs.transid_allocfrom='" . $SuppliersPaid['id'] . "'
ORDER BY supptrans.type,
supptrans.transno";
$TransResult = DB_query($SQL,'','',false,false);
if (DB_error_no() !=0) {
$Title = _('Remittance Advice Problem Report');
include('includes/header.php');
prnMsg(_('The details of the payment to the supplier could not be retrieved because') . ' - ' . DB_error_msg(),'error');
echo '<br /><a href="' . $RootPath . '/index.php">' . _('Back to the menu') . '</a>';
if ($Debug==1){
echo '<br />' . _('The SQL that failed was') . ' ' . $SQL;
}
include('includes/footer.php');
exit;
}
while ($DetailTrans = DB_fetch_array($TransResult)){
$DisplayTranDate = ConvertSQLDate($DetailTrans['trandate']);
$LeftOvers = $pdf->addTextWrap($Left_Margin+5, $YPos, 80,$FontSize,$DetailTrans['typename'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+95, $YPos, 80,$FontSize,$DisplayTranDate, 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+175, $YPos, 80,$FontSize,$DetailTrans['suppreference'], 'left');
$LeftOvers = $pdf->addTextWrap($Left_Margin+255, $YPos, 80,$FontSize,locale_number_format($DetailTrans['trantotal'],$SuppliersPaid['currdecimalplaces']), 'right');
$LeftOvers = $pdf->addTextWrap($Left_Margin+355, $YPos,80,$FontSize,locale_number_format($DetailTrans['amt'],$SuppliersPaid['currdecimalplaces']), 'right');
$AccumBalance += $DetailTrans['amt'];
$YPos -=$LineHeight;
if ($YPos < $Bottom_Margin + $LineHeight){
$PageNumber++;
PageHeader();
}
} /*end while there are detail transactions to show */
$YPos -= (0.5*$LineHeight);
$pdf->line($Left_Margin, $YPos+$LineHeight,$Page_Width-$Right_Margin, $YPos+$LineHeight);
$LeftOvers = $pdf->addTextWrap($Left_Margin+280,$YPos,75,$FontSize,_('Total Payment:'), 'right');
$TotalPayments += $AccumBalance;
$LeftOvers = $pdf->addTextWrap($Left_Margin+355,$YPos,80,$FontSize,locale_number_format($AccumBalance,$SuppliersPaid['currdecimalplaces']), 'right');
$YPos -= (1.5*$LineHeight);
$pdf->line($Left_Margin, $YPos+$LineHeight,$Page_Width-$Right_Margin, $YPos+$LineHeight);
} /* end while there are supplier payments to retrieve allocations for */
$FileName=$_SESSION['DatabaseName']. '_' . _('Remittance_Advices') . '_' . date('Y-m-d').'.pdf';
$pdf->OutputD($FileName);
$pdf->__destruct();
} else { /*The option to print PDF was not hit */
$Title=_('Remittance Advices');
$ViewTopic = 'AccountsPayable';
$BookMark = '';
include('includes/header.php');
echo '<p class="page_title_text"><img src="'.$RootPath.'/css/'.$Theme.'/images/printer.png" title="' . $Title . '" alt="" />' . ' '
. $Title . '</p>';
/* show form to allow input */
echo '<form action="' . htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'UTF-8') . '" method="post">';
echo '<input type="hidden" name="FormID" value="' . $_SESSION['FormID'] . '" />';
echo '<fieldset>
<legend>', _('Remittance Advice Criteria'), '</legend>';
if (!isset($_POST['FromCriteria']) or mb_strlen($_POST['FromCriteria'])<1){
$DefaultFromCriteria = '1';
} else {
$DefaultFromCriteria = $_POST['FromCriteria'];
}
if (!isset($_POST['ToCriteria']) or mb_strlen($_POST['ToCriteria'])<1){
$DefaultToCriteria = 'zzzzzzz';
} else {
$DefaultToCriteria = $_POST['ToCriteria'];
}
echo '<field>
<label for="FromCriteria">' . _('From Supplier Code') . ':</label>
<input type="text" maxlength="6" size="7" name="FromCriteria" value="' . $DefaultFromCriteria . '" />
</field>';
echo '<field>
<label for="ToCriteria">' . _('To Supplier Code') . ':</label>
<input type="text" maxlength="6" size="7" name="ToCriteria" value="' . $DefaultToCriteria . '" />
</field>';
if (!isset($_POST['PaymentDate'])){
$DefaultDate = Date($_SESSION['DefaultDateFormat'], Mktime(0,0,0,Date('m')+1,0 ,Date('y')));
} else {
$DefaultDate = $_POST['PaymentDate'];
}
echo '<field>
<label for="PaymentDate">' . _('Date Of Payment') . ':</label>
<input type="date" name="PaymentDate" maxlength="10" size="11" value="' . FormatDateForSQL($DefaultDate) . '" />
</field>';
echo '</fieldset>
<div class="centre">
<input type="submit" name="PrintPDF" value="' . _('Print PDF') . '" />
</div>';
echo '</form>';
include ('includes/footer.php');
} /*end of else not PrintPDF */
function PageHeader(){
global $pdf;
global $PageNumber;
global $YPos;
global $Xpos;
global $LineHeight;
global $Page_Height;
global $Top_Margin;
global $Page_Width;
global $Right_Margin;
global $Left_Margin;
global $Bottom_Margin;
global $FontSize;
global $SupplierName;
global $AccumBalance;
global $RemittanceAdviceCounter;
global $SuppliersPaid;
if ($RemittanceAdviceCounter>0){
$pdf->newPage();
}
$YPos = $Page_Height - $Top_Margin;
$pdf->addJpegFromFile($_SESSION['LogoFile'],$Page_Width/2 -50,$YPos-50,0,30);
// Title
$FontSize =15;
$XPos = $Page_Width/2 - 110;
$pdf->addText($XPos, $YPos,$FontSize, _('Remittance Advice') );
$FontSize = 10;
$pdf->addText($XPos + 150, $YPos,$FontSize, ' '. _('printed:').' ' . Date($_SESSION['DefaultDateFormat']));
$pdf->addText($XPos + 280, $YPos,$FontSize, _('Page').': ' . $PageNumber);
/*Now print out company info at the top left */
$XPos = $Left_Margin;
$YPos = $Page_Height - $Top_Margin - 20;
$FontSize = 10;
$LineHeight = 13;
$LineCount = 0;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $_SESSION['CompanyRecord']['coyname']);
$FontSize = 8;
$LineHeight = 10;
if ($_SESSION['CompanyRecord']['regoffice1'] <> '') {
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice1']);
}
if ($_SESSION['CompanyRecord']['regoffice2'] <> '') {
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice2']);
}
if (($_SESSION['CompanyRecord']['regoffice3'] <> '') OR ($_SESSION['CompanyRecord']['regoffice4'] <> '') OR ($_SESSION['CompanyRecord']['regoffice5'] <> '')) {
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, $_SESSION['CompanyRecord']['regoffice3'] . ' ' . $_SESSION['CompanyRecord']['regoffice4'] . ' ' . $_SESSION['CompanyRecord']['regoffice5']); // country in 6 not printed
}
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Phone') . ':' . $_SESSION['CompanyRecord']['telephone']);
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight,$FontSize, _('Fax') . ': ' . $_SESSION['CompanyRecord']['fax']);
$LineCount += 1;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Email') . ': ' . $_SESSION['CompanyRecord']['email']);
/*Now the supplier details and remittance advice address */
$XPos = $Left_Margin+20;
$YPos = $Page_Height - $Top_Margin - 120;
$LineCount = 0;
$FontSize = 10;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['suppname']);
$LineCount ++;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['address1']);
$LineCount ++;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['address2']);
$LineCount ++;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, $SuppliersPaid['address3'] . ' ' . $SuppliersPaid['address4'] . ' ' . $SuppliersPaid['address5'] . ' ' . $SuppliersPaid['address6']);
$LineCount += 2;
$pdf->addText($XPos, $YPos-$LineCount*$LineHeight, $FontSize, _('Our Code:') . ' ' .$SuppliersPaid['supplierid']);
$YPos = $Page_Height - $Top_Margin - 120;
$FontSize=8;
$XPos = $Page_Width/2 - 60;
$pdf->addText($XPos, $YPos,$FontSize, _('All amounts stated in') . ' - ' . $SuppliersPaid['currcode']);
$YPos -= $LineHeight;
$pdf->addText($XPos, $YPos,$FontSize, $SuppliersPaid['terms']);
$YPos = $Page_Height - $Top_Margin - 180;
//$YPos -= $LineHeight;
$XPos = $Left_Margin;
/*draw a nice curved corner box around the statement details */
/*from the top right */
$pdf->partEllipse($Page_Width-$Right_Margin-10,$YPos-10,0,90,10,10);
/*line to the top left */
$pdf->line($Page_Width-$Right_Margin-10, $YPos,$Left_Margin+10, $YPos);
/*Do top left corner */
$pdf->partEllipse($Left_Margin+10, $YPos-10,90,180,10,10);
/*Do a line to the bottom left corner */
$pdf->line($Left_Margin, $YPos-10,$Left_Margin, $Bottom_Margin+10);
/*Now do the bottom left corner 180 - 270 coming back west*/
$pdf->partEllipse($Left_Margin+10, $Bottom_Margin+10,180,270,10,10);
/*Now a line to the bottom right */
$pdf->line($Left_Margin+10, $Bottom_Margin,$Page_Width-$Right_Margin-10, $Bottom_Margin);
/*Now do the bottom right corner */
$pdf->partEllipse($Page_Width-$Right_Margin-10, $Bottom_Margin+10,270,360,10,10);
/*Finally join up to the top right corner where started */
$pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+10,$Page_Width-$Right_Margin, $YPos-10);
/*Finally join up to the top right corner where started */
$pdf->line($Page_Width-$Right_Margin, $Bottom_Margin+10,$Page_Width-$Right_Margin, $YPos-10);
$YPos -= $LineHeight;
$FontSize =10;
/*Set up headings */
$pdf->addText($Left_Margin+10, $YPos,$FontSize, _('Trans Type') );
$pdf->addText($Left_Margin+100, $YPos,$FontSize, _('Date') );
$pdf->addText($Left_Margin+180, $YPos,$FontSize, _('Reference') );
$pdf->addText($Left_Margin+310, $YPos,$FontSize, _('Total') );
$pdf->addText($Left_Margin+390, $YPos,$FontSize, _('This Payment') );
$YPos -= $LineHeight;
/*draw a line */
$pdf->line($Page_Width-$Right_Margin, $YPos,$XPos, $YPos);
$YPos -= $LineHeight;
$XPos = $Left_Margin;
}
?>