- modules/fotolab updated imagej to current version & some cod fixes to make it work
[care2x.git] / Care2007 / modules / weberp / PrintCustTrans.php
blobc6f4f780ad56837a9eae8e03aab3e9101dfdf55c
1 <?php
3 /* $Revision: 1.26 $ */
5 $PageSecurity = 1;
7 include('includes/session.inc');
9 if (isset($_GET['FromTransNo'])){
10 $FromTransNo = trim($_GET['FromTransNo']);
11 } elseif (isset($_POST['FromTransNo'])){
12 $FromTransNo = trim($_POST['FromTransNo']);
16 if (isset($_GET['InvOrCredit'])){
17 $InvOrCredit = $_GET['InvOrCredit'];
18 } elseif (isset($_POST['InvOrCredit'])){
19 $InvOrCredit = $_POST['InvOrCredit'];
21 if (isset($_GET['PrintPDF'])){
22 $PrintPDF = $_GET['PrintPDF'];
23 } elseif (isset($_POST['PrintPDF'])){
24 $PrintPDF = $_POST['PrintPDF'];
28 If (!isset($_POST['ToTransNo'])
29 OR trim($_POST['ToTransNo'])==''
30 OR $_POST['ToTransNo'] < $FromTransNo){
32 $_POST['ToTransNo'] = $FromTransNo;
35 $FirstTrans = $FromTransNo; /*Need to start a new page only on subsequent transactions */
37 If (isset($PrintPDF)
38 AND $PrintPDF!=''
39 AND isset($FromTransNo)
40 AND isset($InvOrCredit)
41 AND $FromTransNo!=''){
43 include ('includes/class.pdf.php');
46 All this lot unnecessary if session.inc included at the start
47 previously it was not possible to start a session before initiating a class
48 include('config.php');
49 include('includes/ConnectDB.inc');
50 include('includes/GetConfig.php');
51 include('includes/DateFunctions.inc');
52 if (isset($SessionSavePath)){
53 session_save_path($SessionSavePath);
55 ini_set('session.gc_Maxlifetime',$SessionLifeTime);
56 ini_set('max_execution_time',$MaximumExecutionTime);
58 session_start();
61 /*This invoice is hard coded for A4 Landscape invoices or credit notes so can't use PDFStarter.inc*/
62 $Page_Width=842;
63 $Page_Height=595;
64 $Top_Margin=30;
65 $Bottom_Margin=30;
66 $Left_Margin=40;
67 $Right_Margin=30;
69 $PageSize = array(0,0,$Page_Width,$Page_Height);
70 $pdf = & new Cpdf($PageSize);
71 $pdf->selectFont('helvetica');
72 $pdf->addinfo('Author','webERP ' . $Version);
73 $pdf->addinfo('Creator','webERP http://www.weberp.org');
75 $FirstPage = true;
77 if ($InvOrCredit=='Invoice'){
78 $pdf->addinfo('Title',_('Sales Invoice') . ' ' . $FromTransNo . ' to ' . $_POST['ToTransNo']);
79 $pdf->addinfo('Subject',_('Invoices from') . ' ' . $FromTransNo . ' ' . _('to') . ' ' . $_POST['ToTransNo']);
80 } else {
81 $pdf->addinfo('Title',_('Sales Credit Note') );
82 $pdf->addinfo('Subject',_('Credit Notes from') . ' ' . $FromTransNo . ' ' . _('to') . ' ' . $_POST['ToTransNo']);
85 $line_height=16;
87 while ($FromTransNo <= $_POST['ToTransNo']){
89 /*retrieve the invoice details from the database to print
90 notice that salesorder record must be present to print the invoice purging of sales orders will
91 nobble the invoice reprints */
93 if ($InvOrCredit=='Invoice') {
94 $sql = 'SELECT debtortrans.trandate,
95 debtortrans.ovamount,
96 debtortrans.ovdiscount,
97 debtortrans.ovfreight,
98 debtortrans.ovgst,
99 debtortrans.rate,
100 debtortrans.invtext,
101 debtortrans.consignment,
102 debtorsmaster.name,
103 debtorsmaster.address1,
104 debtorsmaster.address2,
105 debtorsmaster.address3,
106 debtorsmaster.address4,
107 debtorsmaster.address5,
108 debtorsmaster.address6,
109 debtorsmaster.currcode,
110 debtorsmaster.invaddrbranch,
111 debtorsmaster.taxref,
112 paymentterms.terms,
113 salesorders.deliverto,
114 salesorders.deladd1,
115 salesorders.deladd2,
116 salesorders.deladd3,
117 salesorders.deladd4,
118 salesorders.deladd5,
119 salesorders.deladd6,
120 salesorders.customerref,
121 salesorders.orderno,
122 salesorders.orddate,
123 locations.locationname,
124 shippers.shippername,
125 custbranch.brname,
126 custbranch.braddress1,
127 custbranch.braddress2,
128 custbranch.braddress3,
129 custbranch.braddress4,
130 custbranch.braddress5,
131 custbranch.braddress6,
132 custbranch.brpostaddr1,
133 custbranch.brpostaddr2,
134 custbranch.brpostaddr3,
135 custbranch.brpostaddr4,
136 custbranch.brpostaddr5,
137 custbranch.brpostaddr6,
138 salesman.salesmanname,
139 debtortrans.debtorno,
140 debtortrans.branchcode
141 FROM debtortrans,
142 debtorsmaster,
143 custbranch,
144 salesorders,
145 shippers,
146 salesman,
147 locations,
148 paymentterms
149 WHERE debtortrans.order_ = salesorders.orderno
150 AND debtortrans.type=10
151 AND debtortrans.transno=' . $FromTransNo . '
152 AND debtortrans.shipvia=shippers.shipper_id
153 AND debtortrans.debtorno=debtorsmaster.debtorno
154 AND debtorsmaster.paymentterms=paymentterms.termsindicator
155 AND debtortrans.debtorno=custbranch.debtorno
156 AND debtortrans.branchcode=custbranch.branchcode
157 AND custbranch.salesman=salesman.salesmancode
158 AND salesorders.fromstkloc=locations.loccode';
160 if ($_POST['PrintEDI']=='No'){
161 $sql = $sql . ' AND debtorsmaster.ediinvoices=0';
163 } else {
165 $sql = 'SELECT debtortrans.trandate,
166 debtortrans.ovamount,
167 debtortrans.ovdiscount,
168 debtortrans.ovfreight,
169 debtortrans.ovgst,
170 debtortrans.rate,
171 debtortrans.invtext,
172 debtorsmaster.invaddrbranch,
173 debtorsmaster.name,
174 debtorsmaster.address1,
175 debtorsmaster.address2,
176 debtorsmaster.address3,
177 debtorsmaster.address4,
178 debtorsmaster.address5,
179 debtorsmaster.address6,
180 debtorsmaster.currcode,
181 debtorsmaster.taxref,
182 custbranch.brname,
183 custbranch.braddress1,
184 custbranch.braddress2,
185 custbranch.braddress3,
186 custbranch.braddress4,
187 custbranch.braddress5,
188 custbranch.braddress6,
189 custbranch.brpostaddr1,
190 custbranch.brpostaddr2,
191 custbranch.brpostaddr3,
192 custbranch.brpostaddr4,
193 custbranch.brpostaddr5,
194 custbranch.brpostaddr6,
195 salesman.salesmanname,
196 debtortrans.debtorno,
197 debtortrans.branchcode,
198 paymentterms.terms
199 FROM debtortrans,
200 debtorsmaster,
201 custbranch,
202 salesman,
203 paymentterms
204 WHERE debtortrans.type=11
205 AND debtorsmaster.paymentterms = paymentterms.termsindicator
206 AND debtortrans.transno=' . $FromTransNo .'
207 AND debtortrans.debtorno=debtorsmaster.debtorno
208 AND debtortrans.debtorno=custbranch.debtorno
209 AND debtortrans.branchcode=custbranch.branchcode
210 AND custbranch.salesman=salesman.salesmancode';
212 if ($_POST['PrintEDI']=='No'){
213 $sql = $sql . ' AND debtorsmaster.ediinvoices=0';
216 $result=DB_query($sql,$db,'','',false,false);
218 if (DB_error_no($db)!=0) {
220 $title = _('Transaction Print Error Report');
221 include ('includes/header.inc');
223 prnMsg( _('There was a problem retrieving the invoice or credit note details for note number') . ' ' . $InvoiceToPrint . ' ' . _('from the database') . '. ' . _('To print an invoice, the sales order record, the customer transaction record and the branch record for the customer must not have been purged') . '. ' . _('To print a credit note only requires the customer, transaction, salesman and branch records be available'),'error');
224 if ($debug==1){
225 prnMsg (_('The SQL used to get this information that failed was') . "<BR>" . $sql,'error');
227 include ('includes/footer.inc');
228 exit;
230 if (DB_num_rows($result)==1){
231 $myrow = DB_fetch_array($result);
233 $ExchRate = $myrow['rate'];
235 if ($InvOrCredit=='Invoice'){
237 $sql = 'SELECT stockmoves.stockid,
238 stockmaster.description,
239 -stockmoves.qty as quantity,
240 stockmoves.discountpercent,
241 ((1 - stockmoves.discountpercent) * stockmoves.price * ' . $ExchRate . '* -stockmoves.qty) AS fxnet,
242 (stockmoves.price * ' . $ExchRate . ') AS fxprice,
243 stockmoves.narrative,
244 stockmaster.units
245 FROM stockmoves,
246 stockmaster
247 WHERE stockmoves.stockid = stockmaster.stockid
248 AND stockmoves.type=10
249 AND stockmoves.transno=' . $FromTransNo . '
250 AND stockmoves.show_on_inv_crds=1';
251 } else {
252 /* only credit notes to be retrieved */
253 $sql = 'SELECT stockmoves.stockid,
254 stockmaster.description,
255 stockmoves.qty as quantity,
256 stockmoves.discountpercent,
257 ((1 - stockmoves.discountpercent) * stockmoves.price * ' . $ExchRate . ' * stockmoves.qty) AS fxnet,
258 (stockmoves.price * ' . $ExchRate . ') AS fxprice,
259 stockmoves.narrative,
260 stockmaster.units
261 FROM stockmoves,
262 stockmaster
263 WHERE stockmoves.stockid = stockmaster.stockid
264 AND stockmoves.type=11
265 AND stockmoves.transno=' . $FromTransNo . '
266 AND stockmoves.show_on_inv_crds=1';
269 $result=DB_query($sql,$db);
270 if (DB_error_no($db)!=0) {
271 $title = _('Transaction Print Error Report');
272 include ('includes/header.inc');
273 echo '<BR>' . _('There was a problem retrieving the invoice or credit note stock movement details for invoice number') . ' ' . $FromTransNo . ' ' . _('from the database');
274 if ($debug==1){
275 echo '<BR>' . _('The SQL used to get this information that failed was') . "<BR>$sql";
277 include('includes/footer.inc');
278 exit;
281 if (DB_num_rows($result)>0){
283 $FontSize = 10;
284 $PageNumber = 1;
286 include('includes/PDFTransPageHeader.inc');
287 $FirstPage = False;
289 while ($myrow2=DB_fetch_array($result)){
291 $DisplayPrice = number_format($myrow2['fxprice'],2);
292 $DisplayQty = number_format($myrow2['quantity'],2);
293 $DisplayNet = number_format($myrow2['fxnet'],2);
295 if ($myrow2['discountpercent']==0){
296 $DisplayDiscount ='';
297 } else {
298 $DisplayDiscount = number_format($myrow2['discountpercent']*100,2) . '%';
301 $LeftOvers = $pdf->addTextWrap($Left_Margin+3,$YPos,95,$FontSize,$myrow2['stockid']);
302 $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,245,$FontSize,$myrow2['description']);
303 $LeftOvers = $pdf->addTextWrap($Left_Margin+353,$YPos,96,$FontSize,$DisplayPrice,'right');
304 $LeftOvers = $pdf->addTextWrap($Left_Margin+453,$YPos,96,$FontSize,$DisplayQty,'right');
305 $LeftOvers = $pdf->addTextWrap($Left_Margin+553,$YPos,35,$FontSize,$myrow2['units'],'centre');
306 $LeftOvers = $pdf->addTextWrap($Left_Margin+590,$YPos,50,$FontSize,$DisplayDiscount,'right');
307 $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos,120,$FontSize,$DisplayNet,'right');
309 $YPos -= ($line_height);
311 $Narrative = $myrow2['narrative'];
312 while (strlen($Narrative)>1){
313 if ($YPos-$line_height <= $Bottom_Margin){
314 /* head up a new invoice/credit note page */
315 /*draw the vertical column lines right to the bottom */
316 PrintLinesToBottom ();
317 include ('includes/PDFTransPageHeader.inc');
318 } //end if need a new page headed up
319 /*increment a line down for the next line item */
320 if (strlen($Narrative)>1){
321 $Narrative = $pdf->addTextWrap($Left_Margin+100,$YPos,245,$FontSize,$Narrative);
323 $YPos -= ($line_height);
325 if ($YPos <= $Bottom_Margin){
327 /* head up a new invoice/credit note page */
328 /*draw the vertical column lines right to the bottom */
329 PrintLinesToBottom ();
330 include ('includes/PDFTransPageHeader.inc');
331 } //end if need a new page headed up
334 } //end while there are line items to print out
335 } /*end if there are stock movements to show on the invoice or credit note*/
337 $YPos -= $line_height;
339 /* check to see enough space left to print the 4 lines for the totals/footer */
340 if (($YPos-$Bottom_Margin)<(2*$line_height)){
342 PrintLinesToBottom ();
343 include ('includes/PDFTransPageHeader.inc');
346 /*Print a column vertical line with enough space for the footer*/
347 /*draw the vertical column lines to 4 lines shy of the bottom
348 to leave space for invoice footer info ie totals etc*/
349 $pdf->line($Left_Margin+97, $TopOfColHeadings+12,$Left_Margin+97,$Bottom_Margin+(4*$line_height));
351 /*Print a column vertical line */
352 $pdf->line($Left_Margin+350, $TopOfColHeadings+12,$Left_Margin+350,$Bottom_Margin+(4*$line_height));
354 /*Print a column vertical line */
355 $pdf->line($Left_Margin+450, $TopOfColHeadings+12,$Left_Margin+450,$Bottom_Margin+(4*$line_height));
357 /*Print a column vertical line */
358 $pdf->line($Left_Margin+550, $TopOfColHeadings+12,$Left_Margin+550,$Bottom_Margin+(4*$line_height));
360 /*Print a column vertical line */
361 $pdf->line($Left_Margin+587, $TopOfColHeadings+12,$Left_Margin+587,$Bottom_Margin+(4*$line_height));
363 $pdf->line($Left_Margin+640, $TopOfColHeadings+12,$Left_Margin+640,$Bottom_Margin+(4*$line_height));
365 /*Rule off at bottom of the vertical lines */
366 $pdf->line($Left_Margin, $Bottom_Margin+(4*$line_height),$Page_Width-$Right_Margin,$Bottom_Margin+(4*$line_height));
368 /*Now print out the footer and totals */
370 if ($InvOrCredit=='Invoice') {
372 $DisplaySubTot = number_format($myrow['ovamount'],2);
373 $DisplayFreight = number_format($myrow['ovfreight'],2);
374 $DisplayTax = number_format($myrow['ovgst'],2);
375 $DisplayTotal = number_format($myrow['ovfreight']+$myrow['ovgst']+$myrow['ovamount'],2);
377 } else {
379 $DisplaySubTot = number_format(-$myrow['ovamount'],2);
380 $DisplayFreight = number_format(-$myrow['ovfreight'],2);
381 $DisplayTax = number_format(-$myrow['ovgst'],2);
382 $DisplayTotal = number_format(-$myrow['ovfreight']-$myrow['ovgst']-$myrow['ovamount'],2);
384 /*Print out the invoice text entered */
385 $YPos = $Bottom_Margin+(3*$line_height);
386 /* Print out the payment terms */
388 $pdf->addTextWrap($Left_Margin+5,$YPos+3,280,$FontSize,_('Payment Terms') . ': ' . $myrow['terms']);
390 $FontSize =8;
391 $LeftOvers = $pdf->addTextWrap($Left_Margin+5,$YPos-12,280,$FontSize,$myrow['invtext']);
392 if (strlen($LeftOvers)>0){
393 $LeftOvers = $pdf->addTextWrap($Left_Margin+5,$YPos-24,280,$FontSize,$LeftOvers);
394 if (strlen($LeftOvers)>0){
395 $LeftOvers = $pdf->addTextWrap($Left_Margin+5,$YPos-36,280,$FontSize,$LeftOvers);
396 /*If there is some of the InvText leftover after 3 lines 200 wide then it is not printed :( */
399 $FontSize = 10;
401 $pdf->addText($Page_Width-$Right_Margin-220, $YPos+5,$FontSize, _('Sub Total'));
402 $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos+5,120,$FontSize,$DisplaySubTot, 'right');
404 $pdf->addText($Page_Width-$Right_Margin-220, $YPos-$line_height+5,$FontSize, _('Freight'));
405 $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos-$line_height+5,120,$FontSize,$DisplayFreight, 'right');
407 $pdf->addText($Page_Width-$Right_Margin-220, $YPos-(2*$line_height)+5,$FontSize, _('Tax'));
408 $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos-(2*$line_height)+5,120, $FontSize,$DisplayTax, 'right');
410 /*rule off for total */
411 $pdf->line($Page_Width-$Right_Margin-222, $YPos-(2*$line_height),$Page_Width-$Right_Margin,$YPos-(2*$line_height));
413 /*vertical to seperate totals from comments and ROMALPA */
414 $pdf->line($Page_Width-$Right_Margin-222, $YPos+$line_height,$Page_Width-$Right_Margin-222,$Bottom_Margin);
416 $YPos+=10;
417 if ($InvOrCredit=='Invoice'){
418 $pdf->addText($Page_Width-$Right_Margin-220, $YPos - ($line_height*3)-6,$FontSize, _('TOTAL INVOICE'));
419 $FontSize=6;
420 $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos-2,245,$FontSize,$_SESSION['RomalpaClause']);
421 while (strlen($LeftOvers)>0 AND $YPos > $Bottom_Margin){
422 $YPos -=7;
423 $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos,245,$FontSize,$LeftOvers);
425 $FontSize=10;
426 } else {
427 $pdf->addText($Page_Width-$Right_Margin-220, $YPos-($line_height*3),$FontSize, _('TOTAL CREDIT'));
429 $LeftOvers = $pdf->addTextWrap($Left_Margin+642,35,120, $FontSize,$DisplayTotal, 'right');
430 } /* end of check to see that there was an invoice record to print */
432 $FromTransNo++;
433 } /* end loop to print invoices */
436 $pdfcode = $pdf->output();
437 $len = strlen($pdfcode);
439 if ($len <1020){
440 include('includes/header.inc');
441 echo '<P>' . _('There were no transactions to print in the range selected');
442 include('includes/footer.inc');
443 exit;
446 if (isset($_GET['Email'])){ //email the invoice to address supplied
448 include ('includes/htmlMimeMail.php');
450 $mail = new htmlMimeMail();
451 $filename = $_SESSION['reports_dir'] . '/' . $InvOrCredit . $_GET['FromTransNo'] . '.pdf';
452 $fp = fopen($filename, 'wb');
453 fwrite ($fp, $pdfcode);
454 fclose ($fp);
456 $attachment = $mail->getFile($filename);
457 $mail->setText(_('Please find attached') . ' ' . $InvOrCredit . ' ' . $_GET['FromTransNo'] );
458 $mail->SetSubject($InvOrCredit . ' ' . $_GET['FromTransNo']);
459 $mail->addAttachment($attachment, $filename, 'application/pdf');
460 $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>');
461 $result = $mail->send(array($_GET['Email']));
463 unlink($filename); //delete the temporary file
465 $title = _('Emailing') . ' ' .$InvOrCredit . ' ' . _('Number') . ' ' . $FromTransNo;
466 include('includes/header.inc');
467 echo "<P>$InvOrCredit " . _('number') . ' ' . $_GET['FromTransNo'] . ' ' . _('has been emailed to') . ' ' . $_GET['Email'];
468 include('includes/footer.inc');
469 exit;
471 } else {
472 header('Content-type: application/pdf');
473 header('Content-Length: ' . $len);
474 header('Content-Disposition: inline; filename=Customer_trans.pdf');
475 header('Expires: 0');
476 header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
477 header('Pragma: public');
479 $pdf->Stream();
482 } else { /*The option to print PDF was not hit */
484 $title=_('Select Invoices/Credit Notes To Print');
485 include('includes/header.inc');
487 if (!isset($FromTransNo) OR $FromTransNo=='') {
490 /*if FromTransNo is not set then show a form to allow input of either a single invoice number or a range of invoices to be printed. Also get the last invoice number created to show the user where the current range is up to */
492 echo "<FORM ACTION='" . $_SERVER['PHP_SELF'] . '?' . SID . "' METHOD='POST'><CENTER><TABLE>";
494 echo '<TR><TD>' . _('Print Invoices or Credit Notes') . '</TD><TD><SELECT name=InvOrCredit>';
495 if ($InvOrCredit=='Invoice' OR !isset($InvOrCredit)){
497 echo "<OPTION SELECTED VALUE='Invoice'>" . _('Invoices');
498 echo "<OPTION VALUE='Credit'>" . _('Credit Notes');
500 } else {
502 echo "<OPTION SELECTED VALUE='Credit'>" . _('Credit Notes');
503 echo "<OPTION VALUE='Invoice'>" . _('Invoices');
507 echo '</SELECT></TD></TR>';
509 echo '<TR><TD>' . _('Print EDI Transactions') . '</TD><TD><SELECT name=PrintEDI>';
510 if ($InvOrCredit=='Invoice' OR !isset($InvOrCredit)){
512 echo "<OPTION SELECTED VALUE='No'>" . _('Do not Print PDF EDI Transactions');
513 echo "<OPTION VALUE='Yes'>" . _('Print PDF EDI Transactions Too');
515 } else {
517 echo "<OPTION VALUE='No'>" . _('Do not Print PDF EDI Transactions');
518 echo "<OPTION SELECTED VALUE='Yes'>" . _('Print PDF EDI Transactions Too');
522 echo '</SELECT></TD></TR>';
523 echo '<TR><TD>' . _('Start invoice/credit note number to print') . '</TD><TD><input Type=text max=6 size=7 name=FromTransNo></TD></TR>';
524 echo '<TR><TD>' . _('End invoice/credit note number to print') . "</TD><TD><input Type=text max=6 size=7 name='ToTransNo'></TD></TR></TABLE></CENTER>";
525 echo "<CENTER><INPUT TYPE=Submit Name='Print' Value='" . _('Print') . "'><P>";
526 echo "<INPUT TYPE=Submit Name='PrintPDF' Value='" . _('Print PDF') . "'></CENTER>";
528 $sql = 'SELECT typeno FROM systypes WHERE typeid=10';
530 $result = DB_query($sql,$db);
531 $myrow = DB_fetch_row($result);
533 echo '<P>' . _('The last invoice created was number') . ' ' . $myrow[0] . '<BR>' . _('If only a single invoice is required') . ', ' . _('enter the invoice number to print in the Start transaction number to print field and leave the End transaction number to print field blank') . '. ' . _('Only use the end invoice to print field if you wish to print a sequential range of invoices');
535 $sql = 'SELECT typeno FROM systypes WHERE typeid=11';
537 $result = DB_query($sql,$db);
538 $myrow = DB_fetch_row($result);
540 echo '<P>' . _('The last credit note created was number') . ' ' . $myrow[0] . '<BR>' . _('A sequential range can be printed using the same method as for invoices above') . '. ' . _('A single credit note can be printed by only entering a start transaction number');
542 } else {
544 while ($FromTransNo <= $_POST['ToTransNo']){
546 /*retrieve the invoice details from the database to print
547 notice that salesorder record must be present to print the invoice purging of sales orders will
548 nobble the invoice reprints */
550 if ($InvOrCredit=='Invoice') {
552 $sql = "SELECT
553 debtortrans.trandate,
554 debtortrans.ovamount,
555 debtortrans.ovdiscount,
556 debtortrans.ovfreight,
557 debtortrans.ovgst,
558 debtortrans.rate,
559 debtortrans.invtext,
560 debtortrans.consignment,
561 debtorsmaster.name,
562 debtorsmaster.address1,
563 debtorsmaster.address2,
564 debtorsmaster.address3,
565 debtorsmaster.address4,
566 debtorsmaster.address5,
567 debtorsmaster.address6,
568 debtorsmaster.currcode,
569 salesorders.deliverto,
570 salesorders.deladd1,
571 salesorders.deladd2,
572 salesorders.deladd3,
573 salesorders.deladd4,
574 salesorders.deladd5,
575 salesorders.deladd6,
576 salesorders.customerref,
577 salesorders.orderno,
578 salesorders.orddate,
579 shippers.shippername,
580 custbranch.brname,
581 custbranch.braddress1,
582 custbranch.braddress2,
583 custbranch.braddress3,
584 custbranch.braddress4,
585 custbranch.braddress5,
586 custbranch.braddress6,
587 salesman.salesmanname,
588 debtortrans.debtorno
589 FROM debtortrans,
590 debtorsmaster,
591 custbranch,
592 salesorders,
593 shippers,
594 salesman
595 WHERE debtortrans.order_ = salesorders.orderno
596 AND debtortrans.type=10
597 AND debtortrans.transno=" . $FromTransNo . "
598 AND debtortrans.shipvia=shippers.shipper_id
599 AND debtortrans.debtorno=debtorsmaster.debtorno
600 AND debtortrans.debtorno=custbranch.debtorno
601 AND debtortrans.branchcode=custbranch.branchcode
602 AND custbranch.salesman=salesman.salesmancode";
603 } else {
605 $sql = 'SELECT debtortrans.trandate,
606 debtortrans.ovamount,
607 debtortrans.ovdiscount,
608 debtortrans.ovfreight,
609 debtortrans.ovgst,
610 debtortrans.rate,
611 debtortrans.invtext,
612 debtorsmaster.name,
613 debtorsmaster.address1,
614 debtorsmaster.address2,
615 debtorsmaster.address3,
616 debtorsmaster.address4,
617 debtorsmaster.address5,
618 debtorsmaster.address6,
619 debtorsmaster.currcode,
620 custbranch.brname,
621 custbranch.braddress1,
622 custbranch.braddress2,
623 custbranch.braddress3,
624 custbranch.braddress4,
625 custbranch.braddress5,
626 custbranch.braddress6,
627 salesman.salesmanname,
628 debtortrans.debtorno
629 FROM debtortrans,
630 debtorsmaster,
631 custbranch,
632 salesman
633 WHERE debtortrans.type=11
634 AND debtortrans.transno=' . $FromTransNo . '
635 AND debtortrans.debtorno=debtorsmaster.debtorno
636 AND debtortrans.debtorno=custbranch.debtorno
637 AND debtortrans.branchcode=custbranch.branchcode
638 AND custbranch.salesman=salesman.salesmancode';
642 $result=DB_query($sql,$db);
643 if (DB_num_rows($result)==0 OR DB_error_no($db)!=0) {
644 echo '<P>' . _('There was a problem retrieving the invoice or credit note details for note number') . ' ' . $InvoiceToPrint . ' ' . _('from the database') . '. ' . _('To print an invoice, the sales order record, the customer transaction record and the branch record for the customer must not have been purged') . '. ' . _('To print a credit note only requires the customer, transaction, salesman and branch records be available');
645 if ($debug==1){
646 echo _('The SQL used to get this information that failed was') . "<BR>$sql";
648 break;
649 include('includes/footer.inc');
650 exit;
651 } elseif (DB_num_rows($result)==1){
653 $myrow = DB_fetch_array($result);
654 /* Then there's an invoice (or credit note) to print. So print out the invoice header and GST Number from the company record */
655 if (count($_SESSION['AllowedPageSecurityTokens'])==1 AND in_array(1, $_SESSION['AllowedPageSecurityTokens']) AND $myrow['debtorno'] != $_SESSION['CustomerID']){
656 echo '<P><FONT COLOR=RED SIZE=4>' . _('This transaction is addressed to another customer and cannot be displayed for privacy reasons') . '. ' . _('Please select only transactions relevant to your company');
657 exit;
660 $ExchRate = $myrow['rate'];
661 $PageNumber = 1;
663 echo "<TABLE WIDTH=100%><TR><TD VALIGN=TOP WIDTH=10%><img src='companies/" . $_SESSION['DatabaseName'] . "/logo.jpg'></TD><TD BGCOLOR='#BBBBBB'><B>";
665 if ($InvOrCredit=='Invoice') {
666 echo '<FONT SIZE=4>' . _('TAX INVOICE') . ' ';
667 } else {
668 echo '<FONT COLOR=RED SIZE=4>' . _('TAX CREDIT NOTE') . ' ';
670 echo '</B>' . _('Number') . ' ' . $FromTransNo . '</FONT><BR><FONT SIZE=1>' . _('Tax Authority Ref') . '. ' . $_SESSION['CompanyRecord']['gstno'] . '</TD></TR></TABLE>';
672 /*Now print out the logo and company name and address */
673 echo "<TABLE WIDTH=100%><TR><TD><FONT SIZE=4 COLOR='#333333'><B>" . $_SESSION['CompanyRecord']['coyname'] . "</B></FONT><BR>";
674 echo $_SESSION['CompanyRecord']['regoffice1'] . '<BR>';
675 echo $_SESSION['CompanyRecord']['regoffice2'] . '<BR>';
676 echo $_SESSION['CompanyRecord']['regoffice3'] . '<BR>';
677 echo $_SESSION['CompanyRecord']['regoffice4'] . '<BR>';
678 echo $_SESSION['CompanyRecord']['regoffice5'] . '<BR>';
679 echo $_SESSION['CompanyRecord']['regoffice6'] . '<BR>';
680 echo _('Telephone') . ': ' . $_SESSION['CompanyRecord']['telephone'] . '<BR>';
681 echo _('Facsimile') . ': ' . $_SESSION['CompanyRecord']['fax'] . '<BR>';
682 echo _('Email') . ': ' . $_SESSION['CompanyRecord']['email'] . '<BR>';
684 echo '</TD><TD WIDTH=50% ALIGN=RIGHT>';
686 /*Now the customer charged to details in a sub table within a cell of the main table*/
688 echo "<TABLE WIDTH=100%><TR><TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Charge To') . ":</B></TD></TR><TR><TD BGCOLOR='#EEEEEE'>";
689 echo $myrow['name'] . '<BR>' . $myrow['address1'] . '<BR>' . $myrow['address2'] . '<BR>' . $myrow['address3'] . '<BR>' . $myrow['address4'] . '<BR>' . $myrow['address5'] . '<BR>' . $myrow['address6'];
690 echo '</TD></TR></TABLE>';
691 /*end of the small table showing charge to account details */
692 echo _('Page') . ': ' . $PageNumber;
693 echo '</TD></TR></TABLE>';
694 /*end of the main table showing the company name and charge to details */
696 if ($InvOrCredit=='Invoice') {
698 echo "<TABLE WIDTH=100%>
699 <TR>
700 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Charge Branch') . ":</B></TD>
701 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Delivered To') . ":</B></TD>
702 </TR>";
703 echo "<TR>
704 <TD BGCOLOR='#EEEEEE'>" .$myrow['brname'] . '<BR>' . $myrow['braddress1'] . '<BR>' . $myrow['braddress2'] . '<BR>' . $myrow['braddress3'] . '<BR>' . $myrow['braddress4'] . '<BR>' . $myrow['braddress5'] . '<BR>' . $myrow['braddress6'] . '</TD>';
706 echo "<TD BGCOLOR='#EEEEEE'>" . $myrow['deliverto'] . '<BR>' . $myrow['deladd1'] . '<BR>' . $myrow['deladd2'] . '<BR>' . $myrow['deladd3'] . '<BR>' . $myrow['deladd4'] . '<BR>' . $myrow['deladd5'] . '<BR>' . $myrow['deladd6'] . '</TD>';
707 echo '</TR>
708 </TABLE><HR>';
710 echo "<TABLE WIDTH=100%>
711 <TR>
712 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Your Order Ref') . "</B></TD>
713 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Our Order No') . "</B></TD>
714 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Order Date') . "</B></TD>
715 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Invoice Date') . "</B></TD>
716 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Sales Person') . "</FONT></B></TD>
717 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Shipper') . "</B></TD>
718 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Consignment Ref') . "</B></TD>
719 </TR>";
720 echo "<TR>
721 <TD BGCOLOR='#EEEEEE'>" . $myrow['customerref'] . "</TD>
722 <TD BGCOLOR='#EEEEEE'>" .$myrow['orderno'] . "</TD>
723 <TD BGCOLOR='#EEEEEE'>" . ConvertSQLDate($myrow['orddate']) . "</TD>
724 <TD BGCOLOR='#EEEEEE'>" . ConvertSQLDate($myrow['trandate']) . "</TD>
725 <TD BGCOLOR='#EEEEEE'>" . $myrow['salesmanname'] . "</TD>
726 <TD BGCOLOR='#EEEEEE'>" . $myrow['shippername'] . "</TD>
727 <TD BGCOLOR='#EEEEEE'>" . $myrow['consignment'] . "</TD>
728 </TR>
729 </TABLE>";
731 $sql ="SELECT stockmoves.stockid,
732 stockmaster.description,
733 -stockmoves.qty as quantity,
734 stockmoves.discountpercent,
735 ((1 - stockmoves.discountpercent) * stockmoves.price * " . $ExchRate . '* -stockmoves.qty) AS fxnet,
736 (stockmoves.price * ' . $ExchRate . ') AS fxprice,
737 stockmoves.narrative,
738 stockmaster.units
739 FROM stockmoves,
740 stockmaster
741 WHERE stockmoves.stockid = stockmaster.stockid
742 AND stockmoves.type=10
743 AND stockmoves.transno=' . $FromTransNo . '
744 AND stockmoves.show_on_inv_crds=1';
746 } else { /* then its a credit note */
748 echo "<TABLE WIDTH=50%><TR>
749 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Branch') . ":</B></TD>
750 </TR>";
751 echo "<TR>
752 <TD BGCOLOR='#EEEEEE'>" .$myrow['brname'] . '<BR>' . $myrow['braddress1'] . '<BR>' . $myrow['braddress2'] . '<BR>' . $myrow['braddress3'] . '<BR>' . $myrow['braddress4'] . '<BR>' . $myrow['braddress5'] . '<BR>' . $myrow['braddress6'] . '</TD>
753 </TR></TABLE>';
754 echo "<HR><TABLE WIDTH=100%><TR>
755 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Date') . "</B></TD>
756 <TD ALIGN=LEFT BGCOLOR='#BBBBBB'><B>" . _('Sales Person') . "</FONT></B></TD>
757 </TR>";
758 echo "<TR>
759 <TD BGCOLOR='#EEEEEE'>" . ConvertSQLDate($myrow['trandate']) . "</TD>
760 <TD BGCOLOR='#EEEEEE'>" . $myrow['salesmanname'] . '</TD>
761 </TR></TABLE>';
763 $sql ='SELECT stockmoves.stockid,
764 stockmaster.description,
765 stockmoves.qty as quantity,
766 stockmoves.discountpercent, ((1 - stockmoves.discountpercent) * stockmoves.price * ' . $ExchRate . ' * stockmoves.qty) AS fxnet,
767 (stockmoves.price * ' . $ExchRate . ') AS fxprice,
768 stockmaster.units
769 FROM stockmoves,
770 stockmaster
771 WHERE stockmoves.stockid = stockmaster.stockid
772 AND stockmoves.type=11
773 AND stockmoves.transno=' . $FromTransNo . '
774 AND stockmoves.show_on_inv_crds=1';
777 echo '<HR>';
778 echo '<CENTER><FONT SIZE=2>' . _('All amounts stated in') . ' ' . $myrow['currcode'] . '</FONT></CENTER>';
780 $result=DB_query($sql,$db);
781 if (DB_error_no($db)!=0) {
782 echo '<BR>' . _('There was a problem retrieving the invoice or credit note stock movement details for invoice number') . ' ' . $FromTransNo . ' ' . _('from the database');
783 if ($debug==1){
784 echo '<BR>' . _('The SQL used to get this information that failed was') . "<BR>$sql";
786 exit;
789 if (DB_num_rows($result)>0){
790 echo "<TABLE WIDTH=100% CELLPADDING=5>
791 <TR><TD class='tableheader'>" . _('Item Code') . "</TD>
792 <TD class='tableheader'>" . _('Item Description') . "</TD>
793 <TD class='tableheader'>" . _('Quantity') . "</TD>
794 <TD class='tableheader'>" . _('Unit') . "</TD>
795 <TD class='tableheader'>" . _('Price') . "</TD>
796 <TD class='tableheader'>" . _('Discount') . "</TD>
797 <TD class='tableheader'>" . _('Net') . '</TD></TR>';
799 $LineCounter =17;
800 $k=0; //row colour counter
802 while ($myrow2=DB_fetch_array($result)){
804 if ($k==1){
805 $RowStarter = "<tr bgcolor='#BBBBBB'>";
806 $k=0;
807 } else {
808 $RowStarter = "<tr bgcolor='#EEEEEE'>";
809 $k=1;
812 echo $RowStarter;
814 $DisplayPrice = number_format($myrow2['fxprice'],2);
815 $DisplayQty = number_format($myrow2['quantity'],2);
816 $DisplayNet = number_format($myrow2['fxnet'],2);
818 if ($myrow2['discountpercent']==0){
819 $DisplayDiscount ='';
820 } else {
821 $DisplayDiscount = number_format($myrow2['discountpercent']*100,2) . '%';
824 printf ('<TD>%s</TD>
825 <TD>%s</TD>
826 <TD ALIGN=RIGHT>%s</TD>
827 <TD ALIGN=RIGHT>%s</TD>
828 <TD ALIGN=RIGHT>%s</TD>
829 <TD ALIGN=RIGHT>%s</TD>
830 <TD ALIGN=RIGHT>%s</TD>
831 </TR>',
832 $myrow2['stockid'],
833 $myrow2['description'],
834 $DisplayQty,
835 $myrow2['units'],
836 $DisplayPrice,
837 $DisplayDiscount,
838 $DisplayNet);
840 if (strlen($myrow2['narrative'])>1){
841 echo $RowStarter . '<TD></TD><TD COLSPAN=6>' . $myrow2['narrative'] . '</TD></TR>';
842 $LineCounter++;
845 $LineCounter++;
847 if ($LineCounter == ($_SESSION['PageLength'] - 2)){
849 /* head up a new invoice/credit note page */
851 $PageNumber++;
852 echo "</TABLE><TABLE WIDTH=100%><TR><TD VALIGN=TOP><img src='companies/" . $_SESSION['DatabaseName'] . "/logo.jpg'></TD><TD BGCOLOR='#BBBBBB'><CENTER><B>";
854 if ($InvOrCredit=='Invoice') {
855 echo '<FONT SIZE=4>' . _('TAX INVOICE') . ' ';
856 } else {
857 echo '<FONT COLOR=RED SIZE=4>' . _('TAX CREDIT NOTE') . ' ';
859 echo '</B>' . _('Number') . ' ' . $FromTransNo . '</FONT><BR><FONT SIZE=1>' . _('GST Number') . ' - ' . $_SESSION['CompanyRecord']['gstno'] . '</TD></TR><TABLE>';
861 /*Now print out company name and address */
862 echo "<TABLE WIDTH=100%><TR>
863 <TD><FONT SIZE=4 COLOR='#333333'><B>" . $_SESSION['CompanyRecord']['coyname'] . '</B></FONT><BR>';
864 echo $_SESSION['CompanyRecord']['regoffice1'] . '<BR>';
865 echo $_SESSION['CompanyRecord']['regoffice2'] . '<BR>';
866 echo $_SESSION['CompanyRecord']['regoffice3'] . '<BR>';
867 echo $_SESSION['CompanyRecord']['regoffice4'] . '<BR>';
868 echo $_SESSION['CompanyRecord']['regoffice5'] . '<BR>';
869 echo $_SESSION['CompanyRecord']['regoffice6'] . '<BR>';
870 echo _('Telephone') . ': ' . $_SESSION['CompanyRecord']['telephone'] . '<BR>';
871 echo _('Facsimile') . ': ' . $_SESSION['CompanyRecord']['fax'] . '<BR>';
872 echo _('Email') . ': ' . $_SESSION['CompanyRecord']['email'] . '<BR>';
873 echo '</TD><TD ALIGN=RIGHT>' . _('Page') . ": $PageNumber</TD></TR></TABLE>";
874 echo "<TABLE WIDTH=100% CELLPADDING=5><TR>
875 <TD class='tableheader'>" . _('Item Code') . "</TD>
876 <TD class='tableheader'>" . _('Item Description') . "</TD>
877 <TD class='tableheader'>" . _('Quantity') . "</TD>
878 <TD class='tableheader'>" . _('Unit') . "</TD>
879 <TD class='tableheader'>" . _('Price') . "</TD>
880 <TD class='tableheader'>" . _('Discount') . "</TD>
881 <TD class='tableheader'>" . _('Net') . "</TD></TR>";
883 $LineCounter = 10;
885 } //end if need a new page headed up
886 } //end while there are line items to print out
887 echo '</TABLE>';
888 } /*end if there are stock movements to show on the invoice or credit note*/
890 /* check to see enough space left to print the totals/footer */
891 $LinesRequiredForText = floor(strlen($myrow['invtext'])/140);
893 if ($LineCounter >= ($_SESSION['PageLength'] - 8 - $LinesRequiredFortext)){
895 /* head up a new invoice/credit note page */
897 $PageNumber++;
898 echo "<TABLE WIDTH=100%><TR><TD VALIGN=TOP><img src='companies/" . $_SESSION['DatabaseName'] . "/logo.jpg'></TD><TD BGCOLOR='#BBBBBB'><CENTER><B>";
900 if ($InvOrCredit=='Invoice') {
901 echo '<FONT SIZE=4>' . _('TAX INVOICE') .' ';
902 } else {
903 echo '<FONT COLOR=RED SIZE=4>' . _('TAX CREDIT NOTE') . ' ';
905 echo '</B>' . _('Number') . ' ' . $FromTransNo . '</FONT><BR><FONT SIZE=1>' . _('GST Number') . ' - ' . $_SESSION['CompanyRecord']['gstno'] . '</TD></TR><TABLE>';
907 /*Print out the logo and company name and address */
908 echo "<TABLE WIDTH=100%><TR><TD><FONT SIZE=4 COLOR='#333333'><B>" . $_SESSION['CompanyRecord']['coyname'] . "</B></FONT><BR>";
909 echo $_SESSION['CompanyRecord']['regoffice1'] . '<BR>';
910 echo $_SESSION['CompanyRecord']['regoffice2'] . '<BR>';
911 echo $_SESSION['CompanyRecord']['regoffice3'] . '<BR>';
912 echo $_SESSION['CompanyRecord']['regoffice4'] . '<BR>';
913 echo $_SESSION['CompanyRecord']['regoffice5'] . '<BR>';
914 echo $_SESSION['CompanyRecord']['regoffice6'] . '<BR>';
915 echo _('Telephone') . ': ' . $_SESSION['CompanyRecord']['telephone'] . '<BR>';
916 echo _('Facsimile') . ': ' . $_SESSION['CompanyRecord']['fax'] . '<BR>';
917 echo _('Email') . ': ' . $_SESSION['CompanyRecord']['email'] . '<BR>';
918 echo '</TD><TD ALIGN=RIGHT>' . _('Page') . ": $PageNumber</TD></TR></TABLE>";
919 echo "<TABLE WIDTH=100% CELLPADDING=5><TR>
920 <TD class='tableheader'>" . _('Item Code') . "</TD>
921 <TD class='tableheader'>" . _('Item Description') . "</TD>
922 <TD class='tableheader'>" . _('Quantity') . "</TD>
923 <TD class='tableheader'>" . _('Unit') . "</TD>
924 <TD class='tableheader'>" . _('Price') . "</TD>
925 <TD class='tableheader'>" . _('Discount') . "</TD>
926 <TD class='tableheader'>" . _('Net') . '</TD></TR>';
928 $LineCounter = 10;
931 /*Space out the footer to the bottom of the page */
933 echo '<BR><BR>' . $myrow['invtext'];
935 $LineCounter=$LineCounter+2+$LinesRequiredForText;
936 while ($LineCounter < ($_SESSION['PageLength'] -6)){
937 echo '<BR>';
938 $LineCounter++;
941 /*Now print out the footer and totals */
943 if ($InvOrCredit=='Invoice') {
945 $DisplaySubTot = number_format($myrow['ovamount'],2);
946 $DisplayFreight = number_format($myrow['ovfreight'],2);
947 $DisplayTax = number_format($myrow['ovgst'],2);
948 $DisplayTotal = number_format($myrow['ovfreight']+$myrow['ovgst']+$myrow['ovamount'],2);
949 } else {
950 $DisplaySubTot = number_format(-$myrow['ovamount'],2);
951 $DisplayFreight = number_format(-$myrow['ovfreight'],2);
952 $DisplayTax = number_format(-$myrow['ovgst'],2);
953 $DisplayTotal = number_format(-$myrow['ovfreight']-$myrow['ovgst']-$myrow['ovamount'],2);
955 /*Print out the invoice text entered */
956 echo '<TABLE WIDTH=100%><TR>
957 <TD ALIGN=RIGHT>' . _('Sub Total') . "</TD>
958 <TD ALIGN=RIGHT BGCOLOR='#EEEEEE' WIDTH=15%>$DisplaySubTot</TD></TR>";
959 echo '<TR><TD ALIGN=RIGHT>' . _('Freight') . "</TD>
960 <TD ALIGN=RIGHT BGCOLOR='#EEEEEE'>$DisplayFreight</TD></TR>";
961 echo '<TR><TD ALIGN=RIGHT>' . _('Tax') . "</TD>
962 <TD ALIGN=RIGHT BGCOLOR='#EEEEEE'>$DisplayTax</TD></TR>";
963 if ($InvOrCredit=='Invoice'){
964 echo '<TR><TD Align=RIGHT><B>' . _('TOTAL INVOICE') . "</B></TD>
965 <TD ALIGN=RIGHT BGCOLOR='#EEEEEE'><U><B>$DisplayTotal</B></U></TD></TR>";
966 } else {
967 echo '<TR><TD Align=RIGHT><FONT COLOR=RED><B>' . _('TOTAL CREDIT') . "</B></FONT></TD>
968 <TD ALIGN=RIGHT BGCOLOR='#EEEEEE'><FONT COLOR=RED><U><B>$DisplayTotal</B></U></FONT></TD></TR>";
970 echo '</TABLE>';
971 } /* end of check to see that there was an invoice record to print */
972 $FromTransNo++;
973 } /* end loop to print invoices */
974 } /*end of if FromTransNo exists */
975 include('includes/footer.inc');
977 } /*end of else not PrintPDF */
981 function PrintLinesToBottom () {
983 global $pdf;
984 global $PageNumber;
985 global $TopOfColHeadings;
986 global $Left_Margin;
987 global $Bottom_Margin;
988 global $line_height;
991 /*draw the vertical column lines right to the bottom */
992 $pdf->line($Left_Margin+97, $TopOfColHeadings+12,$Left_Margin+97,$Bottom_Margin);
994 /*Print a column vertical line */
995 $pdf->line($Left_Margin+350, $TopOfColHeadings+12,$Left_Margin+350,$Bottom_Margin);
997 /*Print a column vertical line */
998 $pdf->line($Left_Margin+450, $TopOfColHeadings+12,$Left_Margin+450,$Bottom_Margin);
1000 /*Print a column vertical line */
1001 $pdf->line($Left_Margin+550, $TopOfColHeadings+12,$Left_Margin+550,$Bottom_Margin);
1003 /*Print a column vertical line */
1004 $pdf->line($Left_Margin+587, $TopOfColHeadings+12,$Left_Margin+587,$Bottom_Margin);
1006 $pdf->line($Left_Margin+640, $TopOfColHeadings+12,$Left_Margin+640,$Bottom_Margin);
1008 $pdf->newPage();
1009 $PageNumber++;