From: <tim...@us...> - 2010-02-08 14:18:48
|
Revision: 3339 http://web-erp.svn.sourceforge.net/web-erp/?rev=3339&view=rev Author: tim_schofield Date: 2010-02-08 14:18:40 +0000 (Mon, 08 Feb 2010) Log Message: ----------- Add the lanscape sales invoice Note to the Form Designer Modified Paths: -------------- trunk/FormDesigner.php trunk/PrintCustTrans.php trunk/doc/Change.log.html trunk/includes/PDFTransPageHeader.inc Added Paths: ----------- trunk/companies/weberpdemo/FormDesigns/SalesInvoice.xml Modified: trunk/FormDesigner.php =================================================================== --- trunk/FormDesigner.php 2010-02-05 16:30:42 UTC (rev 3338) +++ trunk/FormDesigner.php 2010-02-08 14:18:40 UTC (rev 3339) @@ -5,7 +5,7 @@ $title = _('Form Designer'); include('includes/header.inc'); function FontSizes() { - return array(6, 8, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24); //Possible font sizes + return array(6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 22, 24); //Possible font sizes } function SimpleTextLine($key) { /* Displays a table row containing the attributes for a @@ -108,6 +108,9 @@ case 'GoodsReceived.xml': echo '<meta http-equiv="Refresh" content="0; url=' . $rootpath . '/PDFGrn.php?' . SID .'GRNNo=Preview&PONo=1">'; break; + case 'SalesInvoice.xml': + echo '<meta http-equiv="Refresh" content="0; url=' . $rootpath . '/PrintCustTrans.php?' . SID .'FromTransNo=Preview&InvOrCredit=Invoice&PrintPDF=True">'; + break; } } else { /* otherwise check that the web server has write premissions on the companies @@ -154,7 +157,7 @@ $Papers=array('A4_Landscape', 'A4_Portrait', 'A3_Landscape', 'A3_Portrait', 'letter_Portrait', 'letter_Landscape', 'legal_Portrait', 'legal_Landscape'); // Possible paper sizes/orientations echo '<form method="post" id="Form" action="' . $_SERVER['PHP_SELF'] . '?' . SID . '">'; echo '<input name=FormName type=hidden value="'.$_POST['FormName'].'">'; -echo '<table width=85% border=1>'; //Start of outer table +echo '<table width=95% border=1>'; //Start of outer table echo '<tr><th width=33%>'._('Form Name').'<input type="text" name="formname" value="'.$FormDesign['name'].'"></th>'; /* Select the paper size/orientation */ echo '<th width=33%>'._('Paper Size').'<select name="PaperSize">'; @@ -186,19 +189,19 @@ $counter=$counter+1; break; case 'SimpleText': - echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=6>'.$key['name'].'</th></tr>'; + echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=6>'.$key['name'].'</th></tr>'."\n"; SimpleTextLine($key); echo '</table></td>'; $counter=$counter+1; break; case 'MultiLineText': - echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=4>'.$key['name'].'</th></tr>'; + echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=4>'.$key['name'].'</th></tr>'."\n"; MultiTextLine($key); echo '</table></td>'; $counter=$counter+1; break; case 'ElementArray': - echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=7>'.$key['name'].'</th></tr>'; + echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=7>'.$key['name'].'</th></tr>'."\n"; foreach ($key as $subkey) { if ($subkey['type']=='SimpleText') { echo '<tr>'; @@ -238,6 +241,15 @@ echo '</table></td>'; $counter=$counter+1; break; + case 'Line': + echo '<td colspan=1 valign=top><table width=100% border=1><tr><th colspan=6>'.$key['name'].'</th></tr>'; + echo '<td class=number>'._('Start x co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'startx" size=4 maxlength=4 value="'.$key->startx.'"></td>'; + echo '<td class=number>'._('Start y co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'starty" size=4 maxlength=4 value="'.$key->starty.'"></td></tr><tr>'; + echo '<td class=number>'._('End x co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'endx" size=4 maxlength=4 value="'.$key->endx.'"></td>'; + echo '<td class=number>'._('End y co-ordinate').' = '.'</td><td><input type="text" class="number" name="'.$key['id'].'endy" size=4 maxlength=4 value="'.$key->endy.'"></td>'; + echo '</table></td>'; + $counter=$counter+1; + break; } if ($counter==4) { // If the row is full start a new one $counter=1; Modified: trunk/PrintCustTrans.php =================================================================== --- trunk/PrintCustTrans.php 2010-02-05 16:30:42 UTC (rev 3338) +++ trunk/PrintCustTrans.php 2010-02-08 14:18:40 UTC (rev 3339) @@ -1,89 +1,55 @@ <?php - /* $Id$ */ - $PageSecurity = 1; - -include('includes/session.inc'); - +include ('includes/session.inc'); if (isset($_GET['FromTransNo'])) { $FromTransNo = trim($_GET['FromTransNo']); } elseif (isset($_POST['FromTransNo'])) { $FromTransNo = trim($_POST['FromTransNo']); } - if (isset($_GET['InvOrCredit'])) { $InvOrCredit = $_GET['InvOrCredit']; } elseif (isset($_POST['InvOrCredit'])) { $InvOrCredit = $_POST['InvOrCredit']; } - if (isset($_GET['PrintPDF'])) { $PrintPDF = $_GET['PrintPDF']; } elseif (isset($_POST['PrintPDF'])) { $PrintPDF = $_POST['PrintPDF']; } - -if (!isset($_POST['ToTransNo']) - or trim($_POST['ToTransNo'])=='' - or $_POST['ToTransNo'] < $FromTransNo) { - +if (!isset($_POST['ToTransNo']) or trim($_POST['ToTransNo']) == '' or $_POST['ToTransNo'] < $FromTransNo) { $_POST['ToTransNo'] = $FromTransNo; } - $FirstTrans = $FromTransNo; /* Need to start a new page only on subsequent transactions */ - -if (isset($PrintPDF) or isset($_GET['PrintPDF']) - and $PrintPDF!='' - and isset($FromTransNo) - and isset($InvOrCredit) - and $FromTransNo!=''){ - - include ('includes/class.pdf.php'); - require('fpdi/fpdi.php'); - - /* This invoice is hard coded for A4 Landscape invoices or credit notes so can't use PDFStarter.inc */ - - $Page_Width=842; - $Page_Height=595; - $Top_Margin=30; - $Bottom_Margin=30; - $Left_Margin=40; - $Right_Margin=30; - -// Javier: now I use the native constructor, better to not use references - $pdf = new Cpdf('L', 'pt', 'A4'); - $pdf->addInfo('Creator', 'webERP http://www.weberp.org'); - $pdf->addInfo('Author', 'webERP ' . $Version); - - if ($InvOrCredit=='Invoice') { - $pdf->addInfo('Title',_('Sales Invoice') . ' ' . $FromTransNo . ' to ' . $_POST['ToTransNo']); - $pdf->addInfo('Subject',_('Invoices from') . ' ' . $FromTransNo . ' ' . _('to') . ' ' . $_POST['ToTransNo']); +if ($FromTransNo=='Preview') { + $FormDesign = simplexml_load_file(sys_get_temp_dir().'/SalesInvoice.xml'); +} else { + $FormDesign = simplexml_load_file($PathPrefix.'companies/'.$_SESSION['DatabaseName'].'/FormDesigns/SalesInvoice.xml'); +} +if (isset($PrintPDF) or isset($_GET['PrintPDF']) and $PrintPDF != '' and isset($FromTransNo) and isset($InvOrCredit) and $FromTransNo != '') { + $PaperSize = $FormDesign->PaperSize; + include ('includes/PDFStarter.php'); + require ('fpdi/fpdi.php'); + // Javier: now I use the native constructor, better to not use references + if ($InvOrCredit == 'Invoice') { + $pdf->addInfo('Title', _('Sales Invoice') . ' ' . $FromTransNo . ' to ' . $_POST['ToTransNo']); + $pdf->addInfo('Subject', _('Invoices from') . ' ' . $FromTransNo . ' ' . _('to') . ' ' . $_POST['ToTransNo']); } else { - $pdf->addInfo('Title',_('Sales Credit Note') ); - $pdf->addInfo('Subject',_('Credit Notes from') . ' ' . $FromTransNo . ' ' . _('to') . ' ' . $_POST['ToTransNo']); + $pdf->addInfo('Title', _('Sales Credit Note')); + $pdf->addInfo('Subject', _('Credit Notes from') . ' ' . $FromTransNo . ' ' . _('to') . ' ' . $_POST['ToTransNo']); } - -/* Javier: I have brought this piece from the pdf class constructor to get it closer to the admin/user, + /* Javier: I have brought this piece from the pdf class constructor to get it closer to the admin/user, I corrected it to match TCPDF, but it still needs some check, after which, I think it should be moved to each report to provide flexible Document Header and Margins in a per-report basis. */ - $pdf->setAutoPageBreak(0); // Javier: needs check. - $pdf->setPrintHeader(false); // Javier: I added this must be called before Add Page - $pdf->AddPage(); - $pdf->cMargin = 0; // Javier: needs check. -/* END Brought from class.pdf.php constructor */ - -// $pdf->selectFont('helvetica'); + /* END Brought from class.pdf.php constructor */ + // $pdf->selectFont('helvetica'); $FirstPage = true; - $line_height=16; - - while ($FromTransNo <= $_POST['ToTransNo']){ - - /* retrieve the invoice details from the database to print - notice that salesorder record must be present to print the invoice purging of sales orders will - nobble the invoice reprints */ - - if ($InvOrCredit=='Invoice') { + $line_height = $FormDesign->LineHeight; + while ($FromTransNo <= $_POST['ToTransNo']) { + /* retrieve the invoice details from the database to print + notice that salesorder record must be present to print the invoice purging of sales orders will + nobble the invoice reprints */ + if ($InvOrCredit == 'Invoice') { $sql = 'SELECT debtortrans.trandate, debtortrans.ovamount, debtortrans.ovdiscount, @@ -149,8 +115,7 @@ AND debtortrans.branchcode=custbranch.branchcode AND custbranch.salesman=salesman.salesmancode AND salesorders.fromstkloc=locations.loccode'; - - if (isset($_POST['PrintEDI']) and $_POST['PrintEDI']=='No') { + if (isset($_POST['PrintEDI']) and $_POST['PrintEDI'] == 'No') { $sql = $sql . ' AND debtorsmaster.ediinvoices=0'; } } else { @@ -195,34 +160,36 @@ paymentterms WHERE debtortrans.type=11 AND debtorsmaster.paymentterms = paymentterms.termsindicator - AND debtortrans.transno=' . $FromTransNo .' + AND debtortrans.transno=' . $FromTransNo . ' AND debtortrans.debtorno=debtorsmaster.debtorno AND debtortrans.debtorno=custbranch.debtorno AND debtortrans.branchcode=custbranch.branchcode AND custbranch.salesman=salesman.salesmancode'; - - if ($_POST['PrintEDI']=='No') { + if ($_POST['PrintEDI'] == 'No') { $sql = $sql . ' AND debtorsmaster.ediinvoices=0'; } } // end else - - $result=DB_query($sql, $db, '', '',false, false); - - if (DB_error_no($db)!=0) { - $title = _('Transaction Print Error Report'); - include ('includes/header.inc'); - 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'); - if ($debug==1) { - prnMsg (_('The SQL used to get this information that failed was') . "<br />" . $sql,'error'); + if ($FromTransNo!='Preview') { + $result = DB_query($sql, $db, '', '', false, false); + if (DB_error_no($db) != 0) { + $title = _('Transaction Print Error Report'); + include ('includes/header.inc'); + 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'); + if ($debug == 1) { + prnMsg(_('The SQL used to get this information that failed was') . "<br />" . $sql, 'error'); + } + include ('includes/footer.inc'); + exit; } - include ('includes/footer.inc'); - exit; } - if (DB_num_rows($result)==1) { - $myrow = DB_fetch_array($result); - $ExchRate = $myrow['rate']; - if ($InvOrCredit=='Invoice') { - + if ($FromTransNo=='Preview' or DB_num_rows($result) == 1) { + if ($FromTransNo!='Preview') { + $myrow = DB_fetch_array($result); + $ExchRate = $myrow['rate']; + } else { + $ExchRate = 'X'; + } + if ($InvOrCredit == 'Invoice') { $sql = 'SELECT stockmoves.stockid, stockmaster.description, -stockmoves.qty as quantity, @@ -238,7 +205,7 @@ AND stockmoves.transno=' . $FromTransNo . ' AND stockmoves.show_on_inv_crds=1'; } else { - /* only credit notes to be retrieved */ + /* only credit notes to be retrieved */ $sql = 'SELECT stockmoves.stockid, stockmaster.description, stockmoves.qty as quantity, @@ -254,341 +221,269 @@ AND stockmoves.transno=' . $FromTransNo . ' AND stockmoves.show_on_inv_crds=1'; } // end else - - $result=DB_query($sql,$db); - if (DB_error_no($db)!=0) { + if ($FromTransNo!='Preview') { + $result = DB_query($sql, $db); + } + if (DB_error_no($db) != 0) { $title = _('Transaction Print Error Report'); include ('includes/header.inc'); echo '<br>' . _('There was a problem retrieving the invoice or credit note stock movement details for invoice number') . ' ' . $FromTransNo . ' ' . _('from the database'); - if ($debug==1) { + if ($debug == 1) { echo '<br>' . _('The SQL used to get this information that failed was') . "<br>$sql"; } - include('includes/footer.inc'); + include ('includes/footer.inc'); exit; } - - if (DB_num_rows($result)>0) { - - $FontSize = 10; + if ($FromTransNo=='Preview' or DB_num_rows($result) > 0) { $PageNumber = 1; - - include('includes/PDFTransPageHeader.inc'); + include ('includes/PDFTransPageHeader.inc'); $FirstPage = False; - while ($myrow2=DB_fetch_array($result)) { - - if ($myrow2['discountpercent']==0) { - $DisplayDiscount =''; + $YPos = $Page_Height - $FormDesign->Data->y; + $Line=1; + while (($FromTransNo=='Preview' and $Line==1) or (isset($result) and $myrow2 = DB_fetch_array($result))) { + if ($myrow2['discountpercent'] == 0) { + $DisplayDiscount = ''; } else { - $DisplayDiscount = number_format($myrow2['discountpercent']*100,2) . '%'; - $DiscountPrice=$myrow2['fxprice']*(1-$myrow2['discountpercent']); + $DisplayDiscount = number_format($myrow2['discountpercent'] * 100, 2) . '%'; + $DiscountPrice = $myrow2['fxprice'] * (1 - $myrow2['discountpercent']); } - $DisplayNet=number_format($myrow2['fxnet'],2); - $DisplayPrice=$myrow2['fxprice']; - $DisplayQty=$myrow2['quantity']; - - $LeftOvers = $pdf->addTextWrap($Left_Margin+3,$YPos,95,$FontSize,$myrow2['stockid']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+100,$YPos,245,$FontSize,$myrow2['description']); - $LeftOvers = $pdf->addTextWrap($Left_Margin+353,$YPos,96,$FontSize,$DisplayPrice,'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+453,$YPos,96,$FontSize,$DisplayQty,'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+553,$YPos,35,$FontSize,$myrow2['units'],'centre'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+590,$YPos,50,$FontSize,$DisplayDiscount,'right'); - $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos,120,$FontSize,$DisplayNet,'right'); - - $YPos -= ($line_height); - - $lines=explode('\r\n',$myrow2['narrative']); - for ($i=0;$i<sizeOf($lines);$i++) { - while (strlen($lines[$i])>1) { - if ($YPos-$line_height <= $Bottom_Margin) { + $DisplayNet = number_format($myrow2['fxnet'], 2); + $DisplayPrice = $myrow2['fxprice']; + $DisplayQty = $myrow2['quantity']; + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column1->x, $YPos,$FormDesign->Data->Column1->Length, $FormDesign->Data->Column1->FontSize, $myrow2['stockid']); + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column2->x, $YPos,$FormDesign->Data->Column2->Length, $FormDesign->Data->Column2->FontSize, $myrow2['description']); + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column3->x, $YPos,$FormDesign->Data->Column3->Length, $FormDesign->Data->Column3->FontSize, $DisplayPrice, 'right'); + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column4->x, $YPos,$FormDesign->Data->Column4->Length, $FormDesign->Data->Column4->FontSize, $DisplayQty, 'right'); + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column5->x, $YPos,$FormDesign->Data->Column5->Length, $FormDesign->Data->Column5->FontSize, $myrow2['units'], 'centre'); + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column6->x, $YPos,$FormDesign->Data->Column6->Length, $FormDesign->Data->Column6->FontSize, $DisplayDiscount, 'right'); + $LeftOvers = $pdf->addTextWrap($FormDesign->Data->Column7->x, $YPos,$FormDesign->Data->Column7->Length, $FormDesign->Data->Column7->FontSize, $DisplayNet, 'right'); + $YPos-= ($line_height); + $lines = explode('\r\n', $myrow2['narrative']); + for ($i = 0;$i < sizeOf($lines);$i++) { + while (strlen($lines[$i]) > 1) { + if ($YPos - $line_height <= $Bottom_Margin) { /* head up a new invoice/credit note page */ /* draw the vertical column lines right to the bottom */ - PrintLinesToBottom (); - include ('includes/PDFTransPageHeaderPortrait.inc'); - } //end if need a new page headed up - - /* increment a line down for the next line item */ - if (strlen($lines[$i])>1){ - $lines[$i] = $pdf->addTextWrap($Left_Margin+100,$YPos,245,$FontSize,stripslashes($lines[$i])); + PrintLinesToBottom($pdf, $Page_Height, $PageNumber, $FormDesign); + include ('includes/PDFTransPageHeaderPortrait.inc'); + } //end if need a new page headed up + /* increment a line down for the next line item */ + if (strlen($lines[$i]) > 1) { + $lines[$i] = $pdf->addTextWrap($Left_Margin + 100, $YPos, 245, $FontSize, stripslashes($lines[$i])); } - $YPos -= ($line_height); + $YPos-= ($line_height); } } if ($YPos <= $Bottom_Margin) { - /* head up a new invoice/credit note page */ /*draw the vertical column lines right to the bottom */ - PrintLinesToBottom (); + PrintLinesToBottom($pdf, $Page_Height, $PageNumber, $FormDesign); include ('includes/PDFTransPageHeader.inc'); } //end if need a new page headed up + $Line++; } //end while there are line items to print out - } /*end if there are stock movements to show on the invoice or credit note*/ - $YPos -= $line_height; - + } /*end if there are stock movements to show on the invoice or credit note*/ + $YPos-= $line_height; /* check to see enough space left to print the 4 lines for the totals/footer */ - if (($YPos-$Bottom_Margin)<(2*$line_height)) { - - PrintLinesToBottom (); + if (($YPos - $Bottom_Margin) < (2 * $line_height)) { + PrintLinesToBottom($pdf, $Page_Height, $PageNumber, $FormDesign); include ('includes/PDFTransPageHeader.inc'); - } /* Print a column vertical line with enough space for the footer */ /* draw the vertical column lines to 4 lines shy of the bottom to leave space for invoice footer info ie totals etc */ - $pdf->line($Left_Margin+97, $TopOfColHeadings+12,$Left_Margin+97,$Bottom_Margin+(4*$line_height)); - + $pdf->line($FormDesign->DataLines->Line1->startx, $Page_Height - $FormDesign->DataLines->Line1->starty, $FormDesign->DataLines->Line1->endx, $Page_Height - $FormDesign->DataLines->Line1->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+350, $TopOfColHeadings+12,$Left_Margin+350,$Bottom_Margin+(4*$line_height)); - + $pdf->line($FormDesign->DataLines->Line2->startx, $Page_Height - $FormDesign->DataLines->Line2->starty, $FormDesign->DataLines->Line2->endx, $Page_Height - $FormDesign->DataLines->Line2->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+450, $TopOfColHeadings+12,$Left_Margin+450,$Bottom_Margin+(4*$line_height)); - + $pdf->line($FormDesign->DataLines->Line3->startx, $Page_Height - $FormDesign->DataLines->Line3->starty, $FormDesign->DataLines->Line3->endx, $Page_Height - $FormDesign->DataLines->Line3->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+550, $TopOfColHeadings+12,$Left_Margin+550,$Bottom_Margin+(4*$line_height)); - + $pdf->line($FormDesign->DataLines->Line4->startx, $Page_Height - $FormDesign->DataLines->Line4->starty, $FormDesign->DataLines->Line4->endx, $Page_Height - $FormDesign->DataLines->Line4->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+587, $TopOfColHeadings+12,$Left_Margin+587,$Bottom_Margin+(4*$line_height)); - - $pdf->line($Left_Margin+640, $TopOfColHeadings+12,$Left_Margin+640,$Bottom_Margin+(4*$line_height)); - + $pdf->line($FormDesign->DataLines->Line5->startx, $Page_Height - $FormDesign->DataLines->Line5->starty, $FormDesign->DataLines->Line5->endx, $Page_Height - $FormDesign->DataLines->Line5->endy); + $pdf->line($FormDesign->DataLines->Line6->startx, $Page_Height - $FormDesign->DataLines->Line6->starty, $FormDesign->DataLines->Line6->endx, $Page_Height - $FormDesign->DataLines->Line6->endy); /* Rule off at bottom of the vertical lines */ - $pdf->line($Left_Margin, $Bottom_Margin+(4*$line_height),$Page_Width-$Right_Margin,$Bottom_Margin+(4*$line_height)); - + $pdf->line($FormDesign->LineAboveFooter->startx, $Page_Height - $FormDesign->LineAboveFooter->starty, $FormDesign->LineAboveFooter->endx, $Page_Height - $FormDesign->LineAboveFooter->endy); /* Now print out the footer and totals */ - - if ($InvOrCredit=='Invoice') { - - $DisplaySubTot = number_format($myrow['ovamount'],2); - $DisplayFreight = number_format($myrow['ovfreight'],2); - $DisplayTax = number_format($myrow['ovgst'],2); - $DisplayTotal = number_format($myrow['ovfreight']+$myrow['ovgst']+$myrow['ovamount'],2); - + if ($InvOrCredit == 'Invoice') { + $DisplaySubTot = number_format($myrow['ovamount'], 2); + $DisplayFreight = number_format($myrow['ovfreight'], 2); + $DisplayTax = number_format($myrow['ovgst'], 2); + $DisplayTotal = number_format($myrow['ovfreight'] + $myrow['ovgst'] + $myrow['ovamount'], 2); } else { - - $DisplaySubTot = number_format(-$myrow['ovamount'],2); - $DisplayFreight = number_format(-$myrow['ovfreight'],2); - $DisplayTax = number_format(-$myrow['ovgst'],2); - $DisplayTotal = number_format(-$myrow['ovfreight']-$myrow['ovgst']-$myrow['ovamount'],2); + $DisplaySubTot = number_format(-$myrow['ovamount'], 2); + $DisplayFreight = number_format(-$myrow['ovfreight'], 2); + $DisplayTax = number_format(-$myrow['ovgst'], 2); + $DisplayTotal = number_format(-$myrow['ovfreight'] - $myrow['ovgst'] - $myrow['ovamount'], 2); } - /* Print out the invoice text entered */ - $YPos = $Bottom_Margin+(3*$line_height); - /* Print out the payment terms */ - $pdf->addTextWrap($Left_Margin+5,$YPos+3,280,$FontSize,_('Payment Terms') . ': ' . $myrow['terms']); - // $pdf->addText($Page_Width-$Right_Margin-392, $YPos - ($line_height*3)+22,$FontSize, _('Bank Code:***** Bank Account:*****')); - // $FontSize=10; - - $FontSize =8; - $LeftOvers = $pdf->addTextWrap($Left_Margin+5,$YPos-12,280,$FontSize,$myrow['invtext']); - if (strlen($LeftOvers)>0) { - $LeftOvers = $pdf->addTextWrap($Left_Margin+5,$YPos-24,280,$FontSize,$LeftOvers); - if (strlen($LeftOvers)>0) { - $LeftOvers = $pdf->addTextWrap($Left_Margin+5,$YPos-36,280,$FontSize,$LeftOvers); + $pdf->addTextWrap($FormDesign->PaymentTerms->x, $Page_Height - $FormDesign->PaymentTerms->y, $FormDesign->PaymentTerms->Length, $FormDesign->PaymentTerms->FontSize, _('Payment Terms') . ': ' . $myrow['terms']); + // $pdf->addText($Page_Width-$Right_Margin-392, $YPos - ($line_height*3)+22,$FontSize, _('Bank Code:***** Bank Account:*****')); + // $FontSize=10; + $LeftOvers = $pdf->addTextWrap($FormDesign->InvoiceText->x, $Page_Height - $FormDesign->InvoiceText->y, $FormDesign->InvoiceText->Length, $FormDesign->InvoiceText->FontSize, $myrow['invtext']); + if (strlen($LeftOvers) > 0) { + $LeftOvers = $pdf->addTextWrap($FormDesign->InvoiceText->x, $Page_Height - $FormDesign->InvoiceText->y-10, $FormDesign->InvoiceText->Length, $FormDesign->InvoiceText->FontSize, $LeftOvers); + if (strlen($LeftOvers) > 0) { + $LeftOvers = $pdf->addTextWrap($FormDesign->InvoiceText->x, $Page_Height - $FormDesign->InvoiceText->y-20, $FormDesign->InvoiceText->Length, $FormDesign->InvoiceText->FontSize, $LeftOvers); /*If there is some of the InvText leftover after 3 lines 200 wide then it is not printed :( */ } } - $FontSize = 10; - - $pdf->addText($Page_Width-$Right_Margin-220, $YPos+5,$FontSize, _('Sub Total')); - $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos+5,120,$FontSize,$DisplaySubTot, 'right'); - - $pdf->addText($Page_Width-$Right_Margin-220, $YPos-$line_height+5,$FontSize, _('Freight')); - $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos-$line_height+5,120,$FontSize,$DisplayFreight, 'right'); - - $pdf->addText($Page_Width-$Right_Margin-220, $YPos-(2*$line_height)+5,$FontSize, _('Tax')); - $LeftOvers = $pdf->addTextWrap($Left_Margin+642,$YPos-(2*$line_height)+5,120, $FontSize,$DisplayTax, 'right'); - + $pdf->addText($FormDesign->SubTotalCaption->x, $Page_Height - $FormDesign->SubTotalCaption->y, $FormDesign->SubTotalCaption->FontSize, _('Sub Total')); + $LeftOvers = $pdf->addTextWrap($FormDesign->SubTotal->x, $Page_Height - $FormDesign->SubTotal->y, $FormDesign->SubTotal->Length, $FormDesign->SubTotal->FontSize, $DisplaySubTot, 'right'); + $pdf->addText($FormDesign->FreightCaption->x, $Page_Height - $FormDesign->FreightCaption->y, $FormDesign->FreightCaption->FontSize, _('Freight')); + $LeftOvers = $pdf->addTextWrap($FormDesign->Freight->x, $Page_Height - $FormDesign->Freight->y, $FormDesign->Freight->Length, $FormDesign->Freight->FontSize, $DisplayFreight, 'right'); + $pdf->addText($FormDesign->TaxCaption->x, $Page_Height - $FormDesign->TaxCaption->y, $FormDesign->TaxCaption->FontSize, _('Tax')); + $LeftOvers = $pdf->addTextWrap($FormDesign->Tax->x, $Page_Height - $FormDesign->Tax->y, $FormDesign->Tax->Length, $FormDesign->Tax->FontSize, $DisplayTax, 'right'); /*rule off for total */ - $pdf->line($Page_Width-$Right_Margin-222, $YPos-(2*$line_height),$Page_Width-$Right_Margin,$YPos-(2*$line_height)); - + $pdf->line($FormDesign->TotalLine->startx, $Page_Height - $FormDesign->TotalLine->starty, $FormDesign->TotalLine->endx, $Page_Height - $FormDesign->TotalLine->endy); /*vertical to separate totals from comments and ROMALPA */ - $pdf->line($Page_Width-$Right_Margin-222, $YPos+$line_height,$Page_Width-$Right_Margin-222,$Bottom_Margin); - - $YPos+=10; - if ($InvOrCredit=='Invoice') { - $pdf->addText($Page_Width-$Right_Margin-220, $YPos - ($line_height*3)-6,$FontSize, _('TOTAL INVOICE')); - $FontSize=9; - $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos-4,245,$FontSize,$_SESSION['RomalpaClause']); - while (strlen($LeftOvers)>0 AND $YPos > $Bottom_Margin) { - $YPos-=14; - $LeftOvers = $pdf->addTextWrap($Left_Margin+300,$YPos,245,$FontSize,$LeftOvers); + $pdf->line($FormDesign->RomalpaLine->startx, $Page_Height - $FormDesign->RomalpaLine->starty, $FormDesign->RomalpaLine->endx, $Page_Height - $FormDesign->RomalpaLine->endy); + if ($InvOrCredit == 'Invoice') { + $pdf->addText($FormDesign->TotalCaption->x, $Page_Height - $FormDesign->TotalCaption->y, $FormDesign->TotalCaption->FontSize, _('TOTAL INVOICE')); + $YPos=$FormDesign->Romalpa->y; + $LeftOvers = $pdf->addTextWrap($FormDesign->Romalpa->x, $Page_Height - $YPos, $FormDesign->Romalpa->Length, $FormDesign->Romalpa->FontSize, $_SESSION['RomalpaClause']); + while (strlen($LeftOvers) > 0 AND ($Page_Height - $YPos) > $Bottom_Margin) { + $YPos+= $FormDesign->Romalpa->FontSize+1; + $LeftOvers = $pdf->addTextWrap($FormDesign->Romalpa->x, $Page_Height - $YPos, $FormDesign->Romalpa->Length, $FormDesign->Romalpa->FontSize, $LeftOvers); } /* Add Images for Visa / Mastercard / Paypal */ if (file_exists('companies/' . $_SESSION['DatabaseName'] . '/payment.jpg')) { - $pdf->addJpegFromFile('companies/' . $_SESSION['DatabaseName'] . '/payment.jpg',$Page_Width/2 -280,$YPos-20,0,40); + $pdf->addJpegFromFile('companies/' . $_SESSION['DatabaseName'] . '/payment.jpg', $FormDesign->CreditCardLogo->x,$Page_Height -$FormDesign->CreditCardLogo->y,$FormDesign->CreditCardLogo->width,$FormDesign->CreditCardLogo->height); } - $pdf->addText($Page_Width-$Right_Margin-472, $YPos - ($line_height*3)+32,$FontSize, ''); - $FontSize=10; +// $pdf->addText($Page_Width - $Right_Margin - 472, $YPos - ($line_height * 3) + 32, $FontSize, ''); } else { - $pdf->addText($Page_Width-$Right_Margin-220, $YPos-($line_height*3),$FontSize, _('TOTAL CREDIT')); - } - $LeftOvers = $pdf->addTextWrap($Left_Margin+642,35,120, $FontSize,$DisplayTotal, 'right'); + $pdf->addText($FormDesign->TotalCaption->x, $Page_Height - $FormDesign->TotalCaption->y, $FormDesign->TotalCaption->FontSize, _('TOTAL CREDIT')); + } + $LeftOvers = $pdf->addTextWrap($FormDesign->Total->x, $Page_Height - $FormDesign->Total->y, $FormDesign->Total->Length, $FormDesign->Total->FontSize, $DisplayTotal, 'right'); } /* end of check to see that there was an invoice record to print */ - $FromTransNo++; - } /* end loop to print invoices */ - - // Start FPDI concatination to append PDF files conditionally to the invoice - // This part taken from FPDI example page -not used yet since change to TCPDF Dec 2009 - class concat_pdf extends FPDI { - - var $files = array(); - - function setFiles($files) { - $this->files = $files; - } - - function concat() { - foreach($this->files as $file) { - if ($file != 'pdf_append/none') { - $pagecount = $this->setSourceFile($file); - for ($i = 1; $i <= $pagecount; $i++) { - $tplidx = $this->ImportPage($i); - $s = $this->getTemplatesize($tplidx); - $this->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); - $this->useTemplate($tplidx); - } + } +} /* end loop to print invoices */ +// Start FPDI concatination to append PDF files conditionally to the invoice +// This part taken from FPDI example page -not used yet since change to TCPDF Dec 2009 +class concat_pdf extends FPDI { + var $files = array(); + function setFiles($files) { + $this->files = $files; + } + function concat() { + foreach($this->files as $file) { + if ($file != 'pdf_append/none') { + $pagecount = $this->setSourceFile($file); + for ($i = 1;$i <= $pagecount;$i++) { + $tplidx = $this->ImportPage($i); + $s = $this->getTemplatesize($tplidx); + $this->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $this->useTemplate($tplidx); } } } } - - // $pdf =& new concat_pdf(); - - // Have to get the TransNo again, GET[FromTransNo] is updated on each pass of loop - if (isset($_GET['FromTransNo'])) { - $FromTransNo = trim($_GET['FromTransNo']); - } elseif (isset($_POST['FromTransNo'])) { - $FromTransNo = trim($_POST['FromTransNo']); - } - - if ($InvOrCredit=='Invoice') { - $sql = 'SELECT stockmoves.stockid, stockmaster.appendfile +} +// $pdf =& new concat_pdf(); +// Have to get the TransNo again, GET[FromTransNo] is updated on each pass of loop +if (isset($_GET['FromTransNo'])) { + $FromTransNo = trim($_GET['FromTransNo']); +} elseif (isset($_POST['FromTransNo'])) { + $FromTransNo = trim($_POST['FromTransNo']); +} +if ($InvOrCredit == 'Invoice') { + $sql = 'SELECT stockmoves.stockid, stockmaster.appendfile FROM stockmoves, stockmaster WHERE stockmoves.stockid = stockmaster.stockid AND stockmoves.type=10 AND stockmoves.transno=' . $FromTransNo . ' AND stockmoves.show_on_inv_crds=1'; -// }; - - $result=DB_query($sql,$db); - // Loop the result set and add appendfile if the field is not 0 or none - while ($row=DB_fetch_array($result)) { - if ($row['appendfile'] !='0' AND $row['appendfile'] !=='none') { - $pdf->setFiles(array($_SESSION['reports_dir'] . '/Invoice.pdf','companies/' . $_SESSION['DatabaseName'] . '/pdf_append/' . $row['appendfile'])); + // }; + if ($FromTransNo!='Preview') { + $result = DB_query($sql, $db); + } + // Loop the result set and add appendfile if the field is not 0 or none + while (isset($result) and $row = DB_fetch_array($result)) { + if ($row['appendfile'] != '0' AND $row['appendfile'] !== 'none') { + $pdf->setFiles(array($_SESSION['reports_dir'] . '/Invoice.pdf', 'companies/' . $_SESSION['DatabaseName'] . '/pdf_append/' . $row['appendfile'])); $pdf->concat(); - $pdf->Output($_SESSION['CompanyRecord']['coyname'] . '_Invoice.pdf','I'); + $pdf->Output($_SESSION['CompanyRecord']['coyname'] . '_Invoice.pdf', 'I'); exit; // If EMAIL is selected, send the invoice via email, this is not appending pages yet though + } elseif (isset($_GET['Email'])) { - $pdf->Output($_SESSION['reports_dir'] . '/Invoice.pdf','F'); + $pdf->Output($_SESSION['reports_dir'] . '/Invoice.pdf', 'F'); } else { // If the appendfile field is empty and EMAIL is not selected, just print the invoice without any appended pages - $pdf->Output($_SESSION['CompanyRecord']['coyname'] . '_Invoice.pdf','I'); + $pdf->Output($_SESSION['CompanyRecord']['coyname'] . '_Invoice.pdf', 'I'); exit; } } //End FPDI Concat - - - if (isset($_GET['Email'])){ //email the invoice to address supplied - include('includes/header.inc'); - + if (isset($_GET['Email'])) { //email the invoice to address supplied + include ('includes/header.inc'); include ('includes/htmlMimeMail.php'); - $mail = new htmlMimeMail(); $filename = $_SESSION['reports_dir'] . '/Invoice.pdf'; - $fp = fopen( $_SESSION['reports_dir'] . '/Invoice.pdf','wb'); - fwrite ($fp, $pdfcode); - fclose ($fp); - + $fp = fopen($_SESSION['reports_dir'] . '/Invoice.pdf', 'wb'); + fwrite($fp, $pdfcode); + fclose($fp); $attachment = $mail->getFile($filename); - $mail->setText(_('Please find attached') . ' ' . $InvOrCredit . ' ' . $_GET['FromTransNo'] ); + $mail->setText(_('Please find attached') . ' ' . $InvOrCredit . ' ' . $_GET['FromTransNo']); $mail->SetSubject($InvOrCredit . ' ' . $_GET['FromTransNo']); $mail->addAttachment($attachment, $filename, 'application/pdf'); $mail->setFrom($_SESSION['CompanyRecord']['coyname'] . ' <' . $_SESSION['CompanyRecord']['email'] . '>'); $result = $mail->send(array($_GET['Email'])); - unlink($filename); //delete the temporary file - - $title = _('Emailing') . ' ' .$InvOrCredit . ' ' . _('Number') . ' ' . $FromTransNo; - include('includes/header.inc'); + $title = _('Emailing') . ' ' . $InvOrCredit . ' ' . _('Number') . ' ' . $FromTransNo; + include ('includes/header.inc'); echo "<p>$InvOrCredit " . _('number') . ' ' . $_GET['FromTransNo'] . ' ' . _('has been emailed to') . ' ' . $_GET['Email']; - include('includes/footer.inc'); + include ('includes/footer.inc'); exit; - } else { - $pdf->OutputD('PrintCustTrans.pdf'); - $pdf-> __destruct(); + $pdf->__destruct(); } - } else { /*The option to print PDF was not hit */ - - $title=_('Select Invoices/Credit Notes To Print'); - include('includes/header.inc'); - - if (!isset($FromTransNo) OR $FromTransNo=='') { - + $title = _('Select Invoices/Credit Notes To Print'); + include ('includes/header.inc'); + if (!isset($FromTransNo) OR $FromTransNo == '') { /* 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 */ echo "<form action='" . $_SERVER['PHP_SELF'] . '?' . SID . "' method='POST'><table class='table1'>"; - echo '<div class="centre"><p class="page_title_text"><img src="'.$rootpath.'/css/'.$theme.'/images/printer.png" title="' . _('Print') . '" alt="">' . ' ' . _('Print Invoices or Credit Notes (Landscape Mode)') . '</div>'; + echo '<div class="centre"><p class="page_title_text"><img src="' . $rootpath . '/css/' . $theme . '/images/printer.png" title="' . _('Print') . '" alt="">' . ' ' . _('Print Invoices or Credit Notes (Landscape Mode)') . '</div>'; echo '<tr><td>' . _('Print Invoices or Credit Notes') . '</td><td><select name=InvOrCredit>'; - if ($InvOrCredit=='Invoice' OR !isset($InvOrCredit)) { - + if ($InvOrCredit == 'Invoice' OR !isset($InvOrCredit)) { echo "<option selected VALUE='Invoice'>" . _('Invoices'); echo "<option VALUE='Credit'>" . _('Credit Notes'); - } else { - echo "<option selected VALUE='Credit'>" . _('Credit Notes'); echo "<option VALUE='Invoice'>" . _('Invoices'); } - echo '</select></td></tr>'; echo '<tr><td>' . _('Print EDI Transactions') . '</td><td><select name=PrintEDI>'; - - if ($InvOrCredit=='Invoice' OR !isset($InvOrCredit)) { - + if ($InvOrCredit == 'Invoice' OR !isset($InvOrCredit)) { echo "<option selected VALUE='No'>" . _('Do not Print PDF EDI Transactions'); echo "<option VALUE='Yes'>" . _('Print PDF EDI Transactions Too'); - } else { - echo "<option VALUE='No'>" . _('Do not Print PDF EDI Transactions'); echo "<option selected VALUE='Yes'>" . _('Print PDF EDI Transactions Too'); } - echo '</select></td></tr>'; echo '<tr><td>' . _('Start invoice/credit note number to print') . '</td><td><input Type=text class=number max=6 size=7 name=FromTransNo></td></tr>'; echo '<tr><td>' . _('End invoice/credit note number to print') . "</td><td><input Type=text class=number max=6 size=7 name='ToTransNo'></td></tr></table>"; echo "<div class='centre'><input type=Submit Name='Print' Value='" . _('Print') . "'><p>"; echo "<input type=Submit Name='PrintPDF' Value='" . _('Print PDF') . "'></div>"; - $sql = 'SELECT typeno FROM systypes WHERE typeid=10'; - - $result = DB_query($sql,$db); + $result = DB_query($sql, $db); $myrow = DB_fetch_row($result); - echo '<div class="page_help_text"><b>' . _('The last invoice created was number') . ' ' . $myrow[0] . '</b><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') . ''; - $sql = 'SELECT typeno FROM systypes WHERE typeid=11'; - - $result = DB_query($sql,$db); + $result = DB_query($sql, $db); $myrow = DB_fetch_row($result); - echo '<br /><b>' . _('The last credit note created was number') . ' ' . $myrow[0] . '</b><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') . '</DIV'; - } else { - while ($FromTransNo <= $_POST['ToTransNo']) { - /*retrieve the invoice details from the database to print notice that salesorder record must be present to print the invoice purging of sales orders will nobble the invoice reprints */ - - if ($InvOrCredit=='Invoice') { - + if ($InvOrCredit == 'Invoice') { $sql = "SELECT debtortrans.trandate, debtortrans.ovamount, @@ -641,7 +536,6 @@ AND debtortrans.branchcode=custbranch.branchcode AND custbranch.salesman=salesman.salesmancode"; } else { - $sql = 'SELECT debtortrans.trandate, debtortrans.ovamount, debtortrans.ovdiscount, @@ -677,37 +571,31 @@ AND debtortrans.branchcode=custbranch.branchcode AND custbranch.salesman=salesman.salesmancode'; } - - $result=DB_query($sql,$db); - if (DB_num_rows($result)==0 OR DB_error_no($db)!=0) { + $result = DB_query($sql, $db); + if (DB_num_rows($result) == 0 OR DB_error_no($db) != 0) { 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'); - if ($debug==1) { + if ($debug == 1) { echo _('The SQL used to get this information that failed was') . "<br>$sql"; } break; - include('includes/footer.inc'); + include ('includes/footer.inc'); exit; - } elseif (DB_num_rows($result)==1) { - + } elseif (DB_num_rows($result) == 1) { $myrow = DB_fetch_array($result); /* Then there's an invoice (or credit note) to print. So print out the invoice header and GST Number from the company record */ - if (count($_SESSION['AllowedPageSecurityTokens'])==1 AND in_array(1, $_SESSION['AllowedPageSecurityTokens']) AND $myrow['debtorno'] != $_SESSION['CustomerID']){ + if (count($_SESSION['AllowedPageSecurityTokens']) == 1 AND in_array(1, $_SESSION['AllowedPageSecurityTokens']) AND $myrow['debtorno'] != $_SESSION['CustomerID']) { 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'); exit; } - $ExchRate = $myrow['rate']; $PageNumber = 1; - echo "<table class='table1'><tr><td VALIGN=TOP WIDTH=10%><img src='" . $_SESSION['LogoFile'] . "'></td><td bgcolor='#BBBBBB'><b>"; - - if ($InvOrCredit=='Invoice') { - echo '<font size=4>' . _('TAX INVOICE') . ' '; + if ($InvOrCredit == 'Invoice') { + echo '<font size=4>' . _('TAX INVOICE') . ' '; } else { - echo '<font color=RED size=4>' . _('TAX CREDIT NOTE') . ' '; + echo '<font color=RED size=4>' . _('TAX CREDIT NOTE') . ' '; } echo '</b>' . _('Number') . ' ' . $FromTransNo . '</font><br><font size=1>' . _('Tax Authority Ref') . '. ' . $_SESSION['CompanyRecord']['gstno'] . '</td></tr></table>'; - /* Now print out the logo and company name and address */ echo "<table class='table1'><tr><td><font size=4 color='#333333'><b>" . $_SESSION['CompanyRecord']['coyname'] . "</b></font><br>"; echo $_SESSION['CompanyRecord']['regoffice1'] . '<br>'; @@ -719,11 +607,8 @@ echo _('Telephone') . ': ' . $_SESSION['CompanyRecord']['telephone'] . '<br>'; echo _('Facsimile') . ': ' . $_SESSION['CompanyRecord']['fax'] . '<br>'; echo _('Email') . ': ' . $_SESSION['CompanyRecord']['email'] . '<br>'; - echo '</td><td WIDTH=50% class=number>'; - /* Now the customer charged to details in a sub table within a cell of the main table*/ - echo "<table class='table1'><tr><td align=left bgcolor='#BBBBBB'><b>" . _('Charge To') . ":</b></td></tr><tr><td bgcolor='#EEEEEE'>"; echo $myrow['name'] . '<br>' . $myrow['address1'] . '<br>' . $myrow['address2'] . '<br>' . $myrow['address3'] . '<br>' . $myrow['address4'] . '<br>' . $myrow['address5'] . '<br>' . $myrow['address6']; echo '</td></tr></table>'; @@ -731,22 +616,18 @@ echo _('Page') . ': ' . $PageNumber; echo '</td></tr></table>'; /*end of the main table showing the company name and charge to details */ - - if ($InvOrCredit=='Invoice') { - - echo "<table class='table1'> + if ($InvOrCredit == 'Invoice') { + echo "<table class='table1'> <tr> <td align=left bgcolor='#BBBBBB'><b>" . _('Charge Branch') . ":</b></td> <td align=left bgcolor='#BBBBBB'><b>" . _('Delivered To') . ":</b></td> </tr>"; - echo "<tr> - <td bgcolor='#EEEEEE'>" .$myrow['brname'] . '<br>' . $myrow['braddress1'] . '<br>' . $myrow['braddress2'] . '<br>' . $myrow['braddress3'] . '<br>' . $myrow['braddress4'] . '<br>' . $myrow['braddress5'] . '<br>' . $myrow['braddress6'] . '</td>'; - - 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>'; - echo '</tr> + echo "<tr> + <td bgcolor='#EEEEEE'>" . $myrow['brname'] . '<br>' . $myrow['braddress1'] . '<br>' . $myrow['braddress2'] . '<br>' . $myrow['braddress3'] . '<br>' . $myrow['braddress4'] . '<br>' . $myrow['braddress5'] . '<br>' . $myrow['braddress6'] . '</td>'; + 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>'; + echo '</tr> </table><hr>'; - - echo "<table class='table1'> + echo "<table class='table1'> <tr> <td align=left bgcolor='#BBBBBB'><b>" . _('Your Order Ref') . "</b></td> <td align=left bgcolor='#BBBBBB'><b>" . _('Our Order No') . "</b></td> @@ -756,9 +637,9 @@ <td align=left bgcolor='#BBBBBB'><b>" . _('Shipper') . "</b></td> <td align=left bgcolor='#BBBBBB'><b>" . _('Consignment Ref') . "</b></td> </tr>"; - echo "<tr> + echo "<tr> <td bgcolor='#EEEEEE'>" . $myrow['customerref'] . "</td> - <td bgcolor='#EEEEEE'>" .$myrow['orderno'] . "</td> + <td bgcolor='#EEEEEE'>" . $myrow['orderno'] . "</td> <td bgcolor='#EEEEEE'>" . ConvertSQLDate($myrow['orddate']) . "</td> <td bgcolor='#EEEEEE'>" . ConvertSQLDate($myrow['trandate']) . "</td> <td bgcolor='#EEEEEE'>" . $myrow['salesmanname'] . "</td> @@ -766,8 +647,7 @@ <td bgcolor='#EEEEEE'>" . $myrow['consignment'] . "</td> </tr> </table>"; - - $sql ="SELECT stockmoves.stockid, + $sql = "SELECT stockmoves.stockid, stockmaster.description, -stockmoves.qty as quantity, stockmoves.discountpercent, @@ -781,25 +661,22 @@ AND stockmoves.type=10 AND stockmoves.transno=' . $FromTransNo . ' AND stockmoves.show_on_inv_crds=1'; - } else { /* then its a credit note */ - - echo "<table WIDTH=50%><tr> + echo "<table WIDTH=50%><tr> <td align=left bgcolor='#BBBBBB'><b>" . _('Branch') . ":</b></td> </tr>"; - echo "<tr> - <td bgcolor='#EEEEEE'>" .$myrow['brname'] . '<br>' . $myrow['braddress1'] . '<br>' . $myrow['braddress2'] . '<br>' . $myrow['braddress3'] . '<br>' . $myrow['braddress4'] . '<br>' . $myrow['braddress5'] . '<br>' . $myrow['braddress6'] . '</td> + echo "<tr> + <td bgcolor='#EEEEEE'>" . $myrow['brname'] . '<br>' . $myrow['braddress1'] . '<br>' . $myrow['braddress2'] . '<br>' . $myrow['braddress3'] . '<br>' . $myrow['braddress4'] . '<br>' . $myrow['braddress5'] . '<br>' . $myrow['braddress6'] . '</td> </tr></table>'; - echo "<hr><table class='table1'><tr> + echo "<hr><table class='table1'><tr> <td align=left bgcolor='#BBBBBB'><b>" . _('Date') . "</b></td> <td align=left bgcolor='#BBBBBB'><b>" . _('Sales Person') . "</font></b></td> </tr>"; - echo "<tr> + echo "<tr> <td bgcolor='#EEEEEE'>" . ConvertSQLDate($myrow['trandate']) . "</td> <td bgcolor='#EEEEEE'>" . $myrow['salesmanname'] . '</td> </tr></table>'; - - $sql ='SELECT stockmoves.stockid, + $sql = 'SELECT stockmoves.stockid, stockmaster.description, stockmoves.qty as quantity, stockmoves.discountpercent, ((1 - stockmoves.discountpercent) * stockmoves.price * ' . $ExchRate . ' * stockmoves.qty) AS fxnet, @@ -812,20 +689,17 @@ AND stockmoves.transno=' . $FromTransNo . ' AND stockmoves.show_on_inv_crds=1'; } - echo '<hr>'; echo '<div class="centre"><font size=2>' . _('All amounts stated in') . ' ' . $myrow['currcode'] . '</font></div>'; - - $result=DB_query($sql,$db); - if (DB_error_no($db)!=0) { + $result = DB_query($sql, $db); + if (DB_error_no($db) != 0) { echo '<br>' . _('There was a problem retrieving the invoice or credit note stock movement details for invoice number') . ' ' . $FromTransNo . ' ' . _('from the database'); - if ($debug==1){ - echo '<br>' . _('The SQL used to get this information that failed was') . "<br>$sql"; + if ($debug == 1) { + echo '<br>' . _('The SQL used to get this information that failed was') . "<br>$sql"; } exit; } - - if (DB_num_rows($result)>0){ + if (DB_num_rows($result) > 0) { echo "<table class='table1'> <tr><th>" . _('Item Code') . "</th> <th>" . _('Item Description') . "</th> @@ -834,83 +708,62 @@ <th>" . _('Price') . "</th> <th>" . _('Discount') . "</th> <th>" . _('Net') . '</th></tr>'; - - $LineCounter =17; - $k=0; //row colour counter - - while ($myrow2=DB_fetch_array($result)){ - - if ($k==1){ - $RowStarter = '<tr class="EvenTableRows">'; - $k=0; - } else { - $RowStarter = '<tr class="OddTableRows">'; - $k=1; - } - - echo $RowStarter; - - $DisplayPrice = number_format($myrow2['fxprice'],2); - $DisplayQty = number_format($myrow2['quantity'],2); - $DisplayNet = number_format($myrow2['fxnet'],2); - - if ($myrow2['discountpercent']==0){ - $DisplayDiscount =''; - } else { - $DisplayDiscount = number_format($myrow2['discountpercent']*100,2) . '%'; - } - - printf ('<td>%s</td> + $LineCounter = 17; + $k = 0; //row colour counter + while ($myrow2 = DB_fetch_array($result)) { + if ($k == 1) { + $RowStarter = '<tr class="EvenTableRows">'; + $k = 0; + } else { + $RowStarter = '<tr class="OddTableRows">'; + $k = 1; + } + echo $RowStarter; + $DisplayPrice = number_format($myrow2['fxprice'], 2); + $DisplayQty = number_format($myrow2['quantity'], 2); + $DisplayNet = number_format($myrow2['fxnet'], 2); + if ($myrow2['discountpercent'] == 0) { + $DisplayDiscount = ''; + } else { + $DisplayDiscount = number_format($myrow2['discountpercent'] * 100, 2) . '%'; + } + printf('<td>%s</td> <td>%s</td> <td class=number>%s</td> <td class=number>%s</td> <td class=number>%s</td> <td class=number>%s</td> <td class=number>%s</td> - </tr>', - $myrow2['stockid'], - $myrow2['description'], - $DisplayQty, - $myrow2['units'], - $DisplayPrice, - $DisplayDiscount, - $DisplayNet); - - if (strlen($myrow2['narrative'])>1){ - echo $RowStarter . '<td></td><td colspan=6>' . $myrow2['narrative'] . '</td></tr>'; + </tr>', $myrow2['stockid'], $myrow2['description'], $DisplayQty, $myrow2['units'], $DisplayPrice, $DisplayDiscount, $DisplayNet); + if (strlen($myrow2['narrative']) > 1) { + echo $RowStarter . '<td></td><td colspan=6>' . $myrow2['narrative'] . '</td></tr>'; $LineCounter++; - } - - $LineCounter++; - - if ($LineCounter == ($_SESSION['PageLength'] - 2)){ - - /* head up a new invoice/credit note page */ - - $PageNumber++; - echo "</table><table class='table1'><tr><td VALIGN=TOp><img src='" . $_SESSION['LogoFile'] . "'></td><td bgcolor='#BBBBBB'><b>"; - - if ($InvOrCredit=='Invoice') { - echo '<font size=4>' . _('TAX INVOICE') . ' '; - } else { - echo '<font color=RED size=4>' . _('TAX CREDIT NOTE') . ' '; - } - echo '</b>' . _('Number') . ' ' . $FromTransNo . '</font><br /><font size=1>' . _('GST Number') . ' - ' . $_SESSION['CompanyRecord']['gstno'] . '</td></tr></table>'; - - /*Now print out company name and address */ - echo "<table class='table1'><tr> + } + $LineCounter++; + if ($LineCounter == ($_SESSION['PageLength'] - 2)) { + /* head up a new invoice/credit note page */ + $PageNumber++; + echo "</table><table class='table1'><tr><td VALIGN=TOp><img src='" . $_SESSION['LogoFile'] . "'></td><td bgcolor='#BBBBBB'><b>"; + if ($InvOrCredit == 'Invoice') { + echo '<font size=4>' . _('TAX INVOICE') . ' '; + } else { + echo '<font color=RED size=4>' . _('TAX CREDIT NOTE') . ' '; + } + echo '</b>' . _('Number') . ' ' . $FromTransNo . '</font><br /><font size=1>' . _('GST Number') . ' - ' . $_SESSION['CompanyRecord']['gstno'] . '</td></tr></table>'; + /*Now print out company name and address */ + echo "<table class='table1'><tr> <td><font size=4 color='#333333'><b>" . $_SESSION['CompanyRecord']['coyname'] . '</b></font><br>'; - echo $_SESSION['CompanyRecord']['regoffice1'] . '<br>'; - echo $_SESSION['CompanyRecord']['regoffice2'] . '<br>'; - echo $_SESSION['CompanyRecord']['regoffice3'] . '<br>'; - echo $_SESSION['CompanyRecord']['regoffice4'] . '<br>'; - echo $_SESSION['CompanyRecord']['regoffice5'] . '<br>'; - echo $_SESSION['CompanyRecord']['regoffice6'] . '<br>'; - echo _('Telephone') . ': ' . $_SESSION['CompanyRecord']['telephone'] . '<br>'; - echo _('Facsimile') . ': ' . $_SESSION['CompanyRecord']['fax'] . '<br>'; - echo _('Email') . ': ' . $_SESSION['CompanyRecord']['email'] . '<br>'; - echo '</td><td class=number>' . _('Page') . ": $PageNumber</td></tr></table>"; - echo "<table class='table1'><tr> + echo $_SESSION['CompanyRecord']['regoffice1'] . '<br>'; + echo $_SESSION['CompanyRecord']['regoffice2'] . '<br>'; + echo $_SESSION['CompanyRecord']['regoffice3'] . '<br>'; + echo $_SESSION['CompanyRecord']['regoffice4'] . '<br>'; + echo $_SESSION['CompanyRecord']['regoffice5'] . '<br>'; + echo $_SESSION['CompanyRecord']['regoffice6'] . '<br>'; + echo _('Telephone') . ': ' . $_SESSION['CompanyRecord']['telephone'] . '<br>'; + echo _('Facsimile') . ': ' . $_SESSION['CompanyRecord']['fax'] . '<br>'; + echo _('Email') . ': ' . $_SESSION['CompanyRecord']['email'] . '<br>'; + echo '</td><td class=number>' . _('Page') . ": $PageNumber</td></tr></table>"; + echo "<table class='table1'><tr> <th>" . _('Item Code') . "</th> <th>" . _('Item Description') . "</th> <th>" . _('Quantity') . "</th> @@ -918,30 +771,24 @@ <th>" . _('Price') . "</th> <th>" . _('Discount') . "</th> <th>" . _('Net') . "</th></tr>"; + $LineCounter = 10; + } //end if need a new page headed up - $LineCounter = 10; - - } //end if need a new page headed up } //end while there are line items to print out echo '</table>'; } /*end if there are stock movements to show on the invoice or credit note*/ - /* check to see enough space left to print the totals/footer */ - $LinesRequiredForText = floor(strlen($myrow['invtext'])/140); - - if ($LineCounter >= ($_SESSION['PageLength'] - 8 - $LinesRequiredForText)){ - + $LinesRequiredForText = floor(strlen($myrow['invtext']) / 140); + if ($LineCounter >= ($_SESSION['PageLength'] - 8 - $LinesRequiredForText)) { /* head up a new invoice/credit note page */ $PageNumber++; echo "<table class='table1'><tr><td VALIGN=TOp><img src='" . $_SESSION['LogoFile'] . "'></td><td bgcolor='#BBBBBB'><b>"; - - if ($InvOrCredit=='Invoice') { - echo '<font size=4>' . _('TAX INVOICE') .' '; + if ($InvOrCredit == 'Invoice') { + echo '<font size=4>' . _('TAX INVOICE') . ' '; } else { - echo '<font color=RED size=4>' . _('TAX CREDIT NOTE') . ' '; + echo '<font color=RED size=4>' . _('TAX CREDIT NOTE') . ' '; } echo '</b>' . _('Number') . ' ' . $FromTransNo . '</font><br><font size=1>' . _('GST Number') . ' - ' . $_SESSION['CompanyRecord']['gstno'] . '</td></tr><table>'; - /* Print out the logo and company name and address */ echo "<table class='table1'><tr><td><font size=4 color='#333333'><b>" . $_SESSION['CompanyRecord']['coyname'] . "</b></font><br>"; echo $_SESSION['CompanyRecord']['regoffice1'] . '<br>'; @@ -962,35 +809,27 @@ <th>" . _('Price') . "</th> <th>" . _('Discount') . "</th> <th>" . _('Net') . '</th></tr>'; - $LineCounter = 10; } - /* Space out the footer to the bottom of the page */ - echo '<br><br>' . $myrow['invtext']; - - $LineCounter=$LineCounter+2+$LinesRequiredForText; - while ($LineCounter < ($_SESSION['PageLength'] -6)){ + $LineCounter = $LineCounter + 2 + $LinesRequiredForText; + while ($LineCounter < ($_SESSION['PageLength'] - 6)) { echo '<br>'; $LineCounter++; } - /* Now print out the footer and totals */ - - if ($InvOrCredit=='Invoice') { - - $DisplaySubTot = number_format($myrow['ovamount'],2); - $DisplayFreight = number_format($myrow['ovfreight'],2); - $DisplayTax = number_format($myrow['ovgst'],2); - $DisplayTotal = number_format($myrow['ovfreight']+$myrow['ovgst']+$myrow['ovamount'],2); + if ($InvOrCredit == 'Invoice') { + $DisplaySubTot = number_format($myrow['ovamount'], 2); + $DisplayFreight = number_format($myrow['ovfreight'], 2); + $DisplayTax = number_format($myrow['ovgst'], 2); + $DisplayTotal = number_format($myrow['ovfreight'] + $myrow['ovgst'] + $myrow['ovamount'], 2); } else { - $DisplaySubTot = number_format(-$myrow['ovamount'],2); - $DisplayFreight = number_format(-$myrow['ovfreight'],2); - $DisplayTax = number_format(-$myrow['ovgst'],2); - $DisplayTotal = number_format(-$myrow['ovfreight']-$myrow['ovgst']-$myrow['ovamount'],2); + $DisplaySubTot = number_format(-$myrow['ovamount'], 2); + $DisplayFreight = number_format(-$myrow['ovfreight'], 2); + $DisplayTax = number_format(-$myrow['ovgst'], 2); + $DisplayTotal = number_format(-$myrow['ovfreight'] - $myrow['ovgst'] - $myrow['ovamount'], 2); } - /*Print out the invoice text entered */ echo '<table class=table1><tr> <td class=number>' . _('Sub Total') . "</td> @@ -999,11 +838,11 @@ <td class=number bgcolor='#EEEEEE'>$DisplayFreight</td></tr>"; echo '<tr><td class=number>' . _('Tax') . "</td> <td class=number bgcolor='#EEEEEE'>$DisplayTax</td></tr>"; - if ($InvOrCredit=='Invoice'){ - echo '<tr><td class=number><b>' . _('TOTAL INVOICE') . "</b></td> + if ($InvOrCredit == 'Invoice') { + echo '<tr><td class=number><b>' . _('TOTAL INVOICE') . "</b></td> <td class=number bgcolor='#EEEEEE'><U><b>$DisplayTotal</b></U></td></tr>"; } else { - echo '<tr><td class=number><font color=RED><b>' . _('TOTAL CREDIT') . "</b></font></td> + echo '<tr><td class=number><font color=RED><b>' . _('TOTAL CREDIT') . "</b></font></td> <td class=number bgcolor='#EEEEEE'><font color=RED><U><b>$DisplayTotal</b></U></font></td></tr>"; } echo '</table>'; @@ -1011,39 +850,21 @@ $FromTransNo++; } /* end loop to print invoices */ } /*end of if FromTransNo exists */ - include('includes/footer.inc'); + include ('includes/footer.inc'); } /*end of else not PrintPDF */ - - -function PrintLinesToBottom () { - - global $pdf; - global $PageNumber; - global $TopOfColHeadings; - global $Left_Margin; - global $Bottom_Margin; - global $line_height; - +function PrintLinesToBottom($pdf, $Page_Height, $PageNumber, $FormDesign) { /* draw the vertical column lines right to the bottom */ - $pdf->line($Left_Margin+97, $TopOfColHeadings+12,$Left_Margin+97,$Bottom_Margin); - + $pdf->line($FormDesign->DataLines->Line1->startx, $Page_Height - $FormDesign->DataLines->Line1->starty, $FormDesign->DataLines->Line1->endx, $Page_Height - $FormDesign->DataLines->Line1->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+350, $TopOfColHeadings+12,$Left_Margin+350,$Bottom_Margin); - + $pdf->line($FormDesign->DataLines->Line2->startx, $Page_Height - $FormDesign->DataLines->Line2->starty, $FormDesign->DataLines->Line2->endx, $Page_Height - $FormDesign->DataLines->Line2->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+450, $TopOfColHeadings+12,$Left_Margin+450,$Bottom_Margin); - + $pdf->line($FormDesign->DataLines->Line3->startx, $Page_Height - $FormDesign->DataLines->Line3->starty, $FormDesign->DataLines->Line3->endx, $Page_Height - $FormDesign->DataLines->Line3->endy); /* Print a column vertical line */ - $pdf->line($Left_Margin+550, $TopOfColHeadings+12,$Left_Margin+550... [truncated message content] |