Jump to content
chris23

[CONTRIBUTION] PDF Customer Invoice

Recommended Posts

Hi Chris, sorry to bombard you today.

 

I've just found that when the invoice is longer than 1 page, any lines which don't fit on the first page get split 1 line per page until the end. e.g if on my first page the last 3 lines are:

 

Subtotal : £249.63

VAT 17.5%: £37.18

Discount : £-17.65

 

then the Delivery line is on the next page and the Total line is on the page after that.

 

Dave

Share this post


Link to post
Share on other sites

Hello,

I was testing out this contrib and I love it. However I was wondering if anyone can help me. Everything seems to be working except the part where it displays the shipping and total. The shipping cost goes down to a new line, which is actually where the total cost line is, so they overlap. Here's a quick screenshot of what I'm talking about:

 

pdfinvprobyy9.jpg

 

Is there a quick fix for this? Thank you!

Share this post


Link to post
Share on other sites

Hi All,

 

I am looking for contribution which enable me to print Fancy (official looking) Order invoice from admin, and also customer can view and print his order invoice from Account login area.

 

I tried one contribution "Fancier Invoice & Packingslip" this is great contribution but it doesn't work with Paypal Ipn and Google checkout module.

 

I have Paypal Ipn, Express checkout, Google Checkout, and Bank Transfer Payment module installed, please advise if this contribution is useful for me.

 

" PDF Customer Invoice v1.1" : looking on Screen shot it may be same what I am looking for, please advise if this works with all my payment modules.

 

Thanks

 

Regards

Zee

Share this post


Link to post
Share on other sites
Hello,

I was testing out this contrib and I love it. However I was wondering if anyone can help me. Everything seems to be working except the part where it displays the shipping and total. The shipping cost goes down to a new line, which is actually where the total cost line is, so they overlap. Here's a quick screenshot of what I'm talking about:

 

Pepperoni,

That happened to me too, the quick fix is making your shipping method name shorter. The not so quick fix would be to make the text start more on the left, so it will not go to the next line.


MindTwist of Twisted Reality and Twisted Tienda

Share this post


Link to post
Share on other sites
Pepperoni,

That happened to me too, the quick fix is making your shipping method name shorter. The not so quick fix would be to make the text start more on the left, so it will not go to the next line.

 

Pepperoni,

 

Aitor's absolutely correct - I suggest moving to the left. You could also reduce the font size.

 

Regards,

 

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites
" PDF Customer Invoice v1.1" : looking on Screen shot it may be same what I am looking for, please advise if this works with all my payment modules.

 

Hi Zee,

 

I'm not sure what you mean by will this contribution work with a payment module.

If you mean will it display Payment Method: Google Checkout or Payment Method: PayPal IPN, then yes, this will be displayed on the PDF

 

Hope this helps,

 

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites
Hi Chris,

 

I'm to add order comments to the bottom of the invoice below the order totals but not having any luck. No problem adding the text but pulling the comments from the database has me stumped

 

Any ideas?

 

Hi Dave,

There's no easy way to do this.

The information in pdfinvoice.php is taken from the class classes/order.php class and has access to its standard properties.

The comments field is not part of this code, so isn't pulled out.

The class would need modifying to include this information. How desperate are you to have this?

Regards,

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites
Hi Chris, sorry to bombard you today.

 

I've just found that when the invoice is longer than 1 page, any lines which don't fit on the first page get split 1 line per page until the end. e.g if on my first page the last 3 lines are:

 

Subtotal : £249.63

VAT 17.5%: £37.18

Discount : £-17.65

 

then the Delivery line is on the next page and the Total line is on the page after that.

 

Dave

 

Dave,

 

In pdfinvoice.php

 

FIND:

if ((is_long(($item_count / 32) && $i >= 20) || ($i == 20))){
	$pdf->AddPage();
	//Fields Name position
	$Y_Fields_Name_position = 125;
	//Table position, under Fields Name
	$Y_Table_Position = 70;
	output_table_heading($Y_Table_Position-6);
	if ($i == 20) $item_count = 1;
}
}

 

Change the values of $i being 20 to 15:

 

if ((is_long(($item_count / 32) && $i >= 15) || ($i == 15))){
	$pdf->AddPage();
	//Fields Name position
	$Y_Fields_Name_position = 125;
	//Table position, under Fields Name
	$Y_Table_Position = 70;
	output_table_heading($Y_Table_Position-6);
	if ($i == 15) $item_count = 1;
}
}

 

This should force a new page at 15 items, not 20

 

HTH

 

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites

Hi Chris,

 

with regards the pages overflowing, changing the number didn't work. I've attached an invoice from an example order which overflows the page so you can see whats happening and I've also included my code in case you need it. (you remember I used your code to enhance the pdf invoice code that already existed so it may vary from yours :) and we use it as a combined picking/packing slip and invoice to go in with the goods or to form the postage label for post items)

 

Cheers

 

Dave

 

<?php
/*
 $Id: create_pdf,v 1.4 2005/04/07

 osCommerce, Open Source E-Commerce Solutions
 [url="http://www.oscommerce.com"]http://www.oscommerce.com[/url]

 Copyright © 2003 osCommerce

 Released under the GNU General Public License

*/

define('FPDF_FONTPATH','fpdf/font/');
require('fpdf/fpdf.php');

require('includes/application_top.php');
require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_ORDERS_INVOICE);

require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();

include(DIR_WS_CLASSES . 'order.php');

    // function to decode html entities
   function tep_html_entity_decode($text, $quote_style = ENT_QUOTES){
       return html_entity_decode($text, $quote_style);
       }

while (list($key, $oID) = each($_GET)) {
if ($key != "oID")
	break;
	 $orders_query = tep_db_query("select orders_id from " . TABLE_ORDERS . " where orders_id = '" . $oID . "'");
	 $order = new order($oID);

class PDF extends FPDF
{


//Page header
function RoundedRect($x, $y, $w, $h,$r, $style = '')
   {
       $k = $this->k;
       $hp = $this->h;
       if($style=='F')
           $op='f';
       elseif($style=='FD' or $style=='DF')
           $op='B';
       else
           $op='S';
       $MyArc = 4/3 * (sqrt(2) - 1);
       $this->_out(sprintf('%.2f %.2f m',($x+$r)*$k,($hp-$y)*$k ));
       $xc = $x+$w-$r ;
       $yc = $y+$r;
       $this->_out(sprintf('%.2f %.2f l', $xc*$k,($hp-$y)*$k ));

       $this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
       $xc = $x+$w-$r ;
       $yc = $y+$h-$r;
       $this->_out(sprintf('%.2f %.2f l',($x+$w)*$k,($hp-$yc)*$k));
       $this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
       $xc = $x+$r ;
       $yc = $y+$h-$r;
       $this->_out(sprintf('%.2f %.2f l',$xc*$k,($hp-($y+$h))*$k));
       $this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
       $xc = $x+$r ;
       $yc = $y+$r;
       $this->_out(sprintf('%.2f %.2f l',($x)*$k,($hp-$yc)*$k ));
       $this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
       $this->_out($op);
   }

   function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
   {
       $h = $this->h;
       $this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $x1*$this->k, ($h-$y1)*$this->k,
           $x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
   }


function Header()
{
global $oID;
 $date = strftime('%A, %d %B %Y');
//Logo
   //$this->Image('images/logo-sig.jpg',5,10,80);



   // Invoice Number and date
//$this->SetFont('Arial','',20);
//$this->SetTextColor(0);
//$this->SetY(50);
//$this->MultiCell(100,6,"Invoice/Order Number: " . $oID . "\n" . $date ,0,'L');

// Company Address Small Top Right
$this->SetX(0);
$this->SetY(10);
   $this->SetFont('Arial','',6);
$this->SetTextColor(0);
   $this->Ln(0);
   $this->Cell(108);
$this->MultiCell(55, 2, STORE_NAME_ADDRESS,0,'L'); 




//email
//$this->SetX(0);
//$this->SetY(46);
//$this->SetFont('Arial','B',10);
//$this->SetTextColor(0);
//$this->Ln(0);
   //$this->Cell(95);
//$this->MultiCell(100, 6, "E-mail: " . STORE_OWNER_EMAIL_ADDRESS,0,'R');

//website
//$this->SetX(0);
//$this->SetY(51);
//$this->SetFont('Arial','B',10);
//$this->SetTextColor(0);
//$this->Ln(0);
   //$this->Cell(88);
//$this->MultiCell(100, 6, "Web: " . HTTP_SERVER,0,'R');
}

function Footer()
{
   //Position at 1.5 cm from bottom
   $this->SetY(-17);
   //Arial italic 8
   $this->SetFont('Arial','',10);
$this->SetTextColor(158,11,14);
$this->Cell(0,10, PRINT_INVOICE_TEXT, 0,0,'C');
//$this->SetY(-15);
  	//$this->Cell(0,10, PRINT_INVOICE_URL, 0,0,'C');
//Page number
   //$this->Cell(0,10,'Page '.$this->PageNo().'/{nb}',0,0,'C');
}
}
//Instanciation of inherited class
$pdf=new PDF();

// Set the Page Margins
$pdf->SetMargins(6,2,6);

// Add the first page
$pdf->AddPage();

//Add Customer Address Top Left (Small Text)
$pdf->SetFont('Arial','',6);
$pdf->SetTextColor(0);
//$pdf->Text(5,10, ENTRY_SOLD_TO);
$pdf->SetX(0);
$pdf->SetY(10);
   //$pdf->SetFont('Arial','B',8);
//$pdf->SetTextColor(0);
   $pdf->Cell(9);
$pdf->MultiCell(0, 2, tep_address_format(1, $order->customer, '', '', "\n"),0,'L');


//Draw Box for Returns Address
$pdf->SetDrawColor(0);
$pdf->SetLineWidth(0.2);
$pdf->SetFillColor(255);
$pdf->RoundedRect(6, 33, 80, 50, 2, 'DF');
//Draw the returns address text
   $pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0);
$pdf->Text(11,38, ENTRY_SHIP_TO);
$pdf->SetX(0);
$pdf->SetY(42);
   //$pdf->SetFont('Arial','B',8);
//$pdf->SetTextColor(0);
   $pdf->Cell(9);
$pdf->MultiCell(70, 4, STORE_NAME_ADDRESS,0,'L');




//Draw Box for Delivery Address
$pdf->SetDrawColor(0);
$pdf->SetLineWidth(0.2);
$pdf->SetFillColor(255);
$pdf->RoundedRect(108, 33, 85, 50, 2, 'DF');
//Draw the invoice delivery address text
   $pdf->SetFont('Arial','B',12);
$pdf->SetTextColor(0);
$pdf->Text(113,38,ENTRY_SHIP_TO);
$pdf->SetX(0);
$pdf->SetY(42);
   $pdf->Cell(111);
$pdf->MultiCell(50, 5, tep_address_format(1, $order->delivery, '', '', "\n"),0,'L');

//Draw the top line with invoice text
$pdf->Cell(50);
$pdf->SetY(105);
$pdf->SetDrawColor(153,153,153);
$pdf->Cell(160,.1,'',1,1,'L',1);
//$pdf->SetFont('Arial','BI',15);
//$pdf->SetTextColor(153,153,153);
//$pdf->Text(22,61.5,'Invoice');
$pdf->SetY(105);
$pdf->SetDrawColor(153,153,153);
$pdf->Cell(38);
$pdf->Cell(160,.1,'',1,1,'L',1);


//Draw Box for Sold To Address
$pdf->SetDrawColor(0);
$pdf->SetLineWidth(0.2);
$pdf->SetFillColor(255);
$pdf->RoundedRect(6, 115, 80, 40, 2, 'DF');
//Draw the Delivery address text
   $pdf->SetFont('Arial','B',10);
$pdf->SetTextColor(0);
$pdf->Text(11,120, ENTRY_SOLD_TO);
$pdf->SetX(0);
$pdf->SetY(125);
   //$pdf->SetFont('Arial','B',8);
//$pdf->SetTextColor(0);
   $pdf->Cell(9);
$pdf->MultiCell(70, 4, tep_address_format(1, $order->customer, '', '', "\n"),0,'L');

//Draw the Lower Company address text
   $pdf->SetFont('Arial','B',8);
$pdf->SetTextColor(0);
$pdf->SetX(0);
$pdf->SetY(120);
   $pdf->Cell(150);
$pdf->MultiCell(70, 3, STORE_NAME_ADDRESS,0,'L');

//Print Returns Number
   $pdf->SetFont('Arial','B',6);
$pdf->Text(25, 87, TEXT_RETURNS_LABEL,0,'L');
$pdf->SetFont('Arial','',6);
$pdf->Text(47,87, $temp . tep_db_input($oID));	

//Print Shipping Number
   $pdf->SetFont('Arial','B',6);
$pdf->Text(130, 87, TEXT_SHIPPING_LABEL,0,'L');
$pdf->SetFont('Arial','',6);
$pdf->Text(153,87, $temp . tep_db_input($oID));	


//Print Text Above Line
   $pdf->SetFont('Arial','B',8);
$pdf->Text(10, 103, TEXT_RETURNS,0,'C');

//Draw Box for Order Number, Date & Payment method
//$pdf->SetDrawColor(0);
//$pdf->SetLineWidth(0.2);
//$pdf->SetFillColor(245);
//$pdf->RoundedRect(6, 107, 192, 11, 2, 'DF');

$pdf->SetFont('Arial','B',12);
$pdf->SetTextColor(0);
//Draw Order Number Text
$temp = str_replace(' ', ' ', PRINT_INVOICE_ORDERNR);
$pdf->Text(10,110, $temp . tep_db_input($oID));	
//Draw Date of Order Text
$temp = str_replace(' ', ' ', PRINT_INVOICE_DATE);
$pdf->Text(150,110,$temp . tep_date_short($order->info['date_purchased']));	

//Draw Payment Method Text
   //$pdf->SetFont('Arial','B',8);
//$pdf->SetTextColor(0);
//$pdf->SetX(0);
//$pdf->SetY(150);
   //$pdf->Cell(100);
//$pdf->MultiCell(70, 3,ENTRY_PAYMENT_METHOD . ' ' . $temp, 0, 0, '');
$pdf->SetFont('Arial','B',8);
$pdf->SetTextColor(0);
// Draw customer phone
    $pdf->Text(10,160, tep_html_entity_decode(PDF_INV_CUSTOMER_PHONE) . tep_html_entity_decode($order->customer["telephone"]));
   // Draw customer email
    $pdf->Text(10,165, tep_html_entity_decode(PDF_INV_CUSTOMER_EMAIL) . tep_html_entity_decode($order->customer["email_address"]));
 $temp = substr ($order->info['payment_method'] , 0, 23);
$pdf->Text(10,170, tep_html_entity_decode(ENTRY_PAYMENT_METHOD) . ' ' . tep_html_entity_decode($temp));
// Draw order comments
    $pdf->Text(10,175, tep_html_entity_decode(PDF_INV_CUSTOMER_COMMENTS) . tep_html_entity_decode($orders_status_history->info["comments"]));

//Fields Name position
$Y_Fields_Name_position = 175;
//Table position, under Fields Name
$Y_Table_Position = 181;


function output_table_heading($Y_Fields_Name_position){
   global $pdf;
//First create each Field Name
//Gray color filling each Field Name box
$pdf->SetFillColor(145);
//Bold Font for Field Name
$pdf->SetFont('Arial','',8);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(6);
$pdf->Cell(9,6,'Qty',0,0,'C',1);
$pdf->SetX(15);
$pdf->Cell(78,6,TABLE_HEADING_PRODUCTS,0,0,'L',1);
$pdf->SetX(93);
$pdf->Cell(25,6,TABLE_HEADING_PRODUCTS_MODEL,0,0,'C',1);
//$pdf->SetX(105);
//$pdf->Cell(15,6,TABLE_HEADING_TAX,1,0,'C',1);
$pdf->SetX(118);
$pdf->Cell(20,6,TABLE_HEADING_PRICE_EXCLUDING_TAX,0,0,'C',1);
$pdf->SetX(138);
$pdf->Cell(20,6,TABLE_HEADING_PRICE_INCLUDING_TAX,0,0,'C',1);
$pdf->SetX(158);
$pdf->Cell(20,6,TABLE_HEADING_TOTAL_EXCLUDING_TAX,0,0,'C',1);
$pdf->SetX(178);
$pdf->Cell(20,6,TABLE_HEADING_TOTAL_INCLUDING_TAX,0,0,'C',1);
$pdf->Ln();
}
output_table_heading($Y_Fields_Name_position);
//Show the products information line by line
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {

    $prod_attribs='';

    // set cell height

    $cell_height = 5;

    // if product name length is > 45 (arial at font size 10) , we get a line break, so start $attrib_count=1
    // adjust upwards for smaller fonts sizes; trial and error!

    $attrib_count = (strlen($order->products[$i]['name']) > 45 ) ? 1 : 0;

   //get attribs and concat. Use attrib count to increase cell height for row
       if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
       for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
       $prod_attribs .= "\n- " .$order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
       $attrib_count++;
       }
   }
   $attrib_count++;
   $product_name_attrib_contact = $order->products[$i]['name'] . $prod_attribs;
$pdf->SetFillColor(245);
   $pdf->SetFont(Arial,'',8);
 $pdf->SetY($Y_Table_Position);
   $pdf->SetX(6);
   // Pad cell by ($attrib_count * \n) linebreaks to 'force' qty to cell top
   $n_padd="";
   for($n_count=0; $n_count<$attrib_count; $n_count++) {
   $n_padd.="\n";
   }
   $pdf->MultiCell(9,($cell_height), ($order->products[$i]['qty'] . $n_padd) ,0,'C',1);
   // end add padding

   $pdf->SetY($Y_Table_Position);
   $pdf->SetX(15);
   $pdf->SetFont(Arial,'',8);
   $pdf->MultiCell(78,$cell_height,tep_html_entity_decode($product_name_attrib_contact),0,'L',1);

   $pdf->SetFont(Arial,'',8);
   $pdf->SetY($Y_Table_Position);
   $pdf->SetX(93);
$n_padd="";
   for($n_count=0; $n_count<$attrib_count; $n_count++) {
   $n_padd.="\n";
   }
   $pdf->SetFont(Arial,'',8);
   $pdf->MultiCell(25,($cell_height),tep_html_entity_decode($order->products[$i]['model']) . $n_padd,0,'C',1);
   $pdf->SetY($Y_Table_Position);
   $pdf->SetX(118);
$n_padd="";
   for($n_count=0; $n_count<$attrib_count; $n_count++) {
   $n_padd.="\n";
   }
   $pdf->SetFont(Arial,'',8);
   $pdf->MultiCell(20,($cell_height),$currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']) . $n_padd,0,'C',1);
   $pdf->SetY($Y_Table_Position);
   $pdf->SetX(138);
$n_padd="";
   for($n_count=0; $n_count<$attrib_count; $n_count++) {
   $n_padd.="\n";
   }
$pdf->SetFont(Arial,'',8);
   $pdf->MultiCell(20,($cell_height),$currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']) . $n_padd,0,'C',1);
   $pdf->SetY($Y_Table_Position);
   $pdf->SetX(158);
$n_padd="";
   for($n_count=0; $n_count<$attrib_count; $n_count++) {
   $n_padd.="\n";
   }
   $pdf->MultiCell(20,($cell_height),$currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . $n_padd,0,'C',1);
   $pdf->SetY($Y_Table_Position);
   $pdf->SetX(178);
$n_padd="";
   for($n_count=0; $n_count<$attrib_count; $n_count++) {
   $n_padd.="\n";
   }
   $pdf->MultiCell(20,($cell_height),$currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']) . $n_padd,0,'C',1);
   $Y_Table_Position += ($cell_height*$attrib_count);
$pdf->SetFont(Arial,'',10);
   //Check for product line overflow
    $item_count++;
   if ((is_long($item_count / 32) && $i >= 20) || ($i == 20)){
       $pdf->AddPage();
       //Fields Name position
       $Y_Fields_Name_position = 125;
       //Table position, under Fields Name
       $Y_Table_Position = 70;
       output_table_heading($Y_Table_Position-6);
       if ($i == 20) $item_count = 1;
   }
}
for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
$pdf->SetY($Y_Table_Position + 5);
$pdf->SetX(20);
$temp = substr ($order->totals[$i]['text'],0 ,3);
//if ($i == 3) $pdf->Text(10,10,$temp);
if ($temp == '<b>')
	{
	$pdf->SetFont('Arial','B',10);
	$temp2 = substr($order->totals[$i]['text'], 3);
	$order->totals[$i]['text'] = substr($temp2, 0, strlen($temp2)-4);
	}
$pdf->MultiCell(176,6,$order->totals[$i]['title'] . ' ' . $order->totals[$i]['text'],0,'R');
$Y_Table_Position += 5;
}
// Draw the shipping address for label
//Draw the invoice delivery address text
/*
   $pdf->SetFont('Arial','B',11);
$pdf->SetTextColor(0);
//$pdf->Text(117,61,ENTRY_SHIP_TO);
//$pdf->SetX(0);
$pdf->SetY(240);
   $pdf->Cell(20);
$pdf->MultiCell(50, 4, strtoupper(tep_address_format(1, $order->delivery, '', '', "\n")),0,'L');
	*/
	}
// PDF's created now output the file
$pdf->Output();
?>

invoice.pdf

Edited by stubbsy

Share this post


Link to post
Share on other sites
Hi Dave,

There's no easy way to do this.

The information in pdfinvoice.php is taken from the class classes/order.php class and has access to its standard properties.

The comments field is not part of this code, so isn't pulled out.

The class would need modifying to include this information. How desperate are you to have this?

Regards,

Chris

 

Hi Chris,

 

it's not essential but would be nice as we use it to let the customer know why part of their order hasn't been shipped.

 

I don't know if this code is any help, this is the code I was trying to modify to work. Its the code used in the batch print centre to put that information on the pdf invoice

 

//order comments	
$innum = $orders['orders_id'];
$orders_comments_query = tep_db_query("select comments,date_added from " . TABLE_ORDERS_STATUS_HISTORY . " where orders_id = '$innum' order by date_added");
if (tep_db_num_rows($orders_comments_query)) {
while ($orders_comments = tep_db_fetch_array($orders_comments_query)) {
if(tep_not_null($orders_comments['comments'])){
		$pdf->Text(date(TEXT_ORDER_FORMAT, strtotime($orders_comments['date_added'])) ,6);
		$pdf->Text(10, 175, "Comments: " . $orders_comments['comments'],GENERAL_FONT_SIZE);
	}
}
}

Edited by stubbsy

Share this post


Link to post
Share on other sites
with regards the pages overflowing, changing the number didn't work.

 

Hi Dave,

 

You're not kidding about your pdfinvoice.php! It only bears a passing resemblance to my version!

 

I've compared the two versions and after playing with your version, I can get it to behave by dropping the number to 10.

 

This number deterines how many product lines on the page before a new page is added to the pdf. As you are starting your product table further down, you have less room on the first page (you also need to allow for the attribute line, something the orig. contrib didn't cater for). Play with 10, 11, 12 until it fits.

 

In the code block

 

if ((is_long(($item_count / 32) && $i >= 20) || ($i == 20))){
	$pdf->AddPage();
	//Fields Name position
	$Y_Fields_Name_position = 125;
	//Table position, under Fields Name
	$Y_Table_Position = 70;
	output_table_heading($Y_Table_Position-6);
	if ($i == 20) $item_count = 1;
}
}

 

You can get rid of

$Y_Fields_Name_position = 125;
//Table position, under Fields Name

 

This is redundant. Change the $Y_Table_Position = 70; to determine where on the second page the table header and product row continuation go

 

As to your comments query, yes the code you've supplied is the way to go but it ideally needs incorporating into the order.php class as an extra property, not hardcoded into pdfinvoice.php. I'll knock something up and PM it to you.

 

Cheers

 

Chris

Edited by chris23

Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites

Hi Chris,

 

Thanks for your help with my ongoing quest ;)

 

I still couldn't see any difference when I changed the number, so, I've moved my product table up a bit now so that it gives me a bit more space, but still anything that spills over the page is spread over as many pages as there are lines. (as you can see on the example attached)

 

Any ideas?

 

Dave

invoice.pdf

Share this post


Link to post
Share on other sites
Hi Chris,

 

Thanks for your help with my ongoing quest ;)

 

I still couldn't see any difference when I changed the number, so, I've moved my product table up a bit now so that it gives me a bit more space, but still anything that spills over the page is spread over as many pages as there are lines. (as you can see on the example attached)

 

Any ideas?

 

Dave

 

This is really odd Dave. I used the code you sent me and tried it against a sample order in my db of 12 lines - split fine and the payment details stayed together. I can't immediately see why each order->total line is going on a separate page.

 

I'll have another look.

 

C


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites

1st: Very cool contrib... Many Thanks!

 

I added a little dirty hack adding the invoices status at view/print time (checkout below test invoice, lower left corner).

test_invoice.jpg

 

 

If anybody wants to add this....

Add this line to catalog/includes/language/your_lang_folder/pdfinvoice.php

define('PDF_INV_INVOICE_STATUS','Order Status at View/Print: ');

 

Add these two lines to your catalog/pdfinvoice.php (edit the the x,y positions where you would like the actual status to appear)

// Draw order status language
$pdf->Text(7,280.5, tep_html_entity_decode(PDF_INV_INVOICE_STATUS));

 

$pdf->Text(54,281,strip_tags(tep_html_entity_decode($order->info["orders_status"])));

 

I added the above just under....

$pdf->Text(22,61.5,tep_html_entity_decode(PRINT_INVOICE_HEADING));

 

This then takes on the "Invoice" italic and font but you don't have to add it there if you don't like the bold-italic font

 

Cheers!


define('PROJECTS', 'Something that goes on forever!');

Share this post


Link to post
Share on other sites

Hi ALL,

 

Thanks Chris for this great contribution and for your continue support.

 

I just completed installation, just had couple of areas I need some advise.

 

First In "Invoice To" box and "Deliver to" Box PDF invoice displaying all information other then Country Name.

Only showing First letter of Country name like for United Kingdom Only displaying U and for Russian Federation only Showing R.

Please advise how I can fix this Issue.

 

Second I want to keep Default font for Payment method and Email(Title) but want to change Actual information(Google Checkout) font to smaller (may be font size 8). How I can change this font size.

 

Thanks for any help in advance.

 

Regards

zee

Share this post


Link to post
Share on other sites

Hi Zee,

 

First In "Invoice To" box and "Deliver to" Box PDF invoice displaying all information other then Country Name.

Only showing First letter of Country name like for United Kingdom Only displaying U and for Russian Federation only Showing R.

Please advise how I can fix this Issue.

 

There's a fix for this in the readme, under the Q and A's. It's an osC issue with an easy fix.

 

Second I want to keep Default font for Payment method and Email(Title) but want to change Actual information(Google Checkout) font to smaller (may be font size 8). How I can change this font size.

 

Edit pdfinvoice.php

 

FIND the block:

 

//Draw Payment Method Text
$temp = substr ($order->info['payment_method'] , 0, 23);
pdf->Text(130,113, tep_html_entity_decode(ENTRY_PAYMENT_METHOD) . ' ' . tep_html_entity_decode($temp));

 

and replace with:

 

//Draw Payment Method Text
$temp = substr ($order->info['payment_method'] , 0, 23);
$pdf->Text(130,113, tep_html_entity_decode(ENTRY_PAYMENT_METHOD));
$pdf->SetFont(PDF_INV_CORE_FONT,'B',8);
$pdf->Text(150,113, tep_html_entity_decode($temp));
$pdf->SetFont(PDF_INV_CORE_FONT,'B',10);

 

What you're doing is splitting the payment title from the payment name, setting the font smaller (8) for the name, then putting it back to 10 for the next entry.

 

You'll have to play with the x value (150) in

 

$pdf->Text(150,113, tep_html_entity_decode($temp));

 

to get the position right

 

HTH

 

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites
I had 'customers_id' instead of 'customer_id'

 

It's fixed now. Thanks!

 

Also, the eps logo support works and looks great! I'm finding that it's best to use legecy eps files, as some of the newer ai and eps files didn't work on my tests, but when saved as legecy files (older versions) they work fine.

 

~Chris

 

PDF Invoice Displaying Customer reference: 0

 

File look like this

"

// Draw customer reference

$pdf->Text(10,117, tep_html_entity_decode(PDF_INV_CUSTOMER_REF) . (int)$customer_id);

 

// Draw customer phone

$pdf->Text(75,117, tep_html_entity_decode(PDF_INV_CUSTOMER_PHONE) . tep_html_entity_decode($order->customer["telephone"]));

// Draw customer email

$pdf->Text(130,117, tep_html_entity_decode(PDF_INV_CUSTOMER_EMAIL) . tep_html_entity_decode($order->customer["email_address"]));@

 

I am sure when I installed this contribution it was displaying Right customer reference, but after some alteration in file like to display Customer telephone and email address in invoice may made some difference in code.

I am not a code man so please advise what need to be fix in this file..

 

Thanks and Regards

 

Zee

Share this post


Link to post
Share on other sites

Hi Chris and all the people.

 

I have the same problem that Stubbsy

 

In this link you can see a invoice with products without attibutes:

pdfinvoice1

In this link you can see a invoice with products with attributes:

pdfinvoice2

 

This is the code:

 

function output_table_heading($Y_Fields_Name_position){
global  $pdf, $cell_color;
//First create each Field Name
// Config color filling each Field Name box
$pdf->SetFillColor($cell_color[0],$cell_color[1],$cell_color[2]);
//Bold Font for Field Name
$pdf->SetFont(PDF_INV_CORE_FONT,'B',10);
$pdf->SetY($Y_Fields_Name_position);
$pdf->SetX(6);
$pdf->Cell(9,6,tep_html_entity_decode(PDF_INV_QTY_CELL),1,0,'C',1);
$pdf->SetX(15);
$pdf->Cell(50,6,tep_html_entity_decode(TABLE_HEADING_PRODUCTS_MODEL),1,0,'C',1);
$pdf->SetX(65);
$pdf->Cell(93,6,tep_html_entity_decode(TABLE_HEADING_PRODUCTS),1,0,'C',1);
//$pdf->SetX(118);
//$pdf->Cell(20,6,tep_html_entity_decode(TABLE_HEADING_PRICE_EXCLUDING_TAX),1,0,'C',1);
//$pdf->SetX(138);
//$pdf->Cell(20,6,tep_html_entity_decode(TABLE_HEADING_PRICE_INCLUDING_TAX),1,0,'C',1);
$pdf->SetX(158);
$pdf->Cell(20,6,tep_html_entity_decode(TABLE_HEADING_PRICE_EXCLUDING_TAX),1,0,'C',1);
$pdf->SetX(178);
$pdf->Cell(20,6,tep_html_entity_decode(TABLE_HEADING_TOTAL_EXCLUDING_TAX),1,0,'C',1);
$pdf->Ln();
}

output_table_heading($Y_Fields_Name_position);
//Show the products information line by line
for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) {

 $prod_attribs='';

 // set cell height

 $cell_height = 5;

 // if product name length is > 45 (arial at font size 10) , we get a line break, so start $attrib_count=1
 // adjust upwards for smaller fonts sizes; trial and error!

 $attrib_count = (strlen($order->products[$i]['name']) > 45 ) ? 1 : 0;

//get attribs and concat. Use attrib count to increase cell height for row
	if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
	for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
	$prod_attribs .= "\n- " .$order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];
	$attrib_count++;
	}
}
$attrib_count++;
$product_name_attrib_contact = $order->products[$i]['name'] . $prod_attribs;

$pdf->SetFont(PDF_INV_CORE_FONT,'',10);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(6);
// Pad cell by ($attrib_count * \n) linebreaks to 'force' qty to cell top
$n_padd="";
for($n_count=0; $n_count<$attrib_count; $n_count++) {
$n_padd.="\n";
}
$pdf->MultiCell(9,($cell_height), ($order->products[$i]['qty'] . $n_padd) ,1,'C');
// end add padding



$pdf->SetY($Y_Table_Position);
$pdf->SetX(65);
	$pdf->SetFont(PDF_INV_CORE_FONT,'',6);
$pdf->MultiCell(93,$cell_height,tep_html_entity_decode($product_name_attrib_contact),1,'L');


//$pdf->SetFont(PDF_INV_CORE_FONT,'',10);
//$pdf->SetY($Y_Table_Position);
//$pdf->SetX(15);
//$pdf->SetFont(PDF_INV_CORE_FONT,'',8);
//$pdf->MultiCell(25,($cell_height*$attrib_count),tep_html_entity_decode($order->products[$i]['model']),1,'C');
//
$pdf->SetFont(PDF_INV_CORE_FONT,'',6);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(15);
// Pad cell by ($attrib_count * \n) linebreaks to 'force' qty to cell top

$pdf->MultiCell(50,($cell_height), ($order->products[$i]['model'] . $n_padd) ,1,'C');
//
$pdf->SetY($Y_Table_Position);
$pdf->SetX(118);
$pdf->SetFont(PDF_INV_CORE_FONT,'',10);
//$pdf->MultiCell(20,($cell_height*$attrib_count),$currencies->format($order->products[$i]['final_price'], true, $order->info['currency'], $order->info['currency_value']),1,'C');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(138);
//$pdf->MultiCell(20,($cell_height*$attrib_count),$currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']), true, $order->info['currency'], $order->info['currency_value']),1,'C');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(158);
$n_padd="";
for($n_count=0; $n_count<$attrib_count; $n_count++) {
$n_padd.="\n";
}
$pdf->MultiCell(20,($cell_height*$attrib_count),$currencies->format($order->products[$i]['final_price'] * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']. $n_padd),1,'C');
$pdf->SetY($Y_Table_Position);
$pdf->SetX(178);
$n_padd="";
for($n_count=0; $n_count<$attrib_count; $n_count++) {
$n_padd.="\n";
}
$pdf->MultiCell(20,($cell_height*$attrib_count),$currencies->format(tep_add_tax($order->products[$i]['final_price'], $order->products[$i]['tax']) * $order->products[$i]['qty'], true, $order->info['currency'], $order->info['currency_value']. $n_padd),1,'C');
//$pdf->SetY($Y_Table_Position);
$Y_Table_Position += ($cell_height*$attrib_count);

//Check for product line overflow
 $item_count++;
if ((is_long($item_count / 32) && $i >= 20) || ($i == 20)){
	$pdf->AddPage();
	//Fields Name position
  //  $Y_Fields_Name_position = 125;
	//Table position, under Fields Name
	$Y_Table_Position = 70;
	output_table_heading($Y_Table_Position-6);
	if ($i == 20) $item_count = 1;
}
}

for ($i = 0, $n = sizeof($order->totals); $i < $n; $i++) {
$pdf->SetY($Y_Table_Position + 5);
$pdf->SetX(102);
$temp = substr ($order->totals[$i]['text'],0 ,3);
if ($temp == '<b>')
	{
	$pdf->SetFont(PDF_INV_CORE_FONT,'B',10);
	$temp2 = substr($order->totals[$i]['text'], 3);
	$order->totals[$i]['text'] = substr($temp2, 0, strlen($temp2)-4);
	}
$pdf->MultiCell(94,6,$order->totals[$i]['title'] . ' ' . $order->totals[$i]['text'],0,'R');
$Y_Table_Position += 5;
}

 

Please tell me the solution for this problem.

 

Regards.

Share this post


Link to post
Share on other sites

First of all, thanks for a great contribution. I have some problems I don't know how to fix. Here they go:

 

  1. I want to change the outlook of PDF, so it first shows VAT-number, next Web and at last e-mail
  2. I want to expand the Ordernumber field, at the moment it is only showing 5 characters, while I want it to show at least 18 characters. How can I expand this field. I can't find where its size is determined.

Please advise how I can fix this. And once again thanks for a great contribution.

Share this post


Link to post
Share on other sites
First of all, thanks for a great contribution. I have some problems I don't know how to fix. Here they go:
  1. I want to change the outlook of PDF, so it first shows VAT-number, next Web and at last e-mail
  2. I want to expand the Ordernumber field, at the moment it is only showing 5 characters, while I want it to show at least 18 characters. How can I expand this field. I can't find where its size is determined.

Please advise how I can fix this. And once again thanks for a great contribution.

 

Hi Zahoor,

 

If you want to move elements around, you need to adjust the x and y coordinates of each element

 

EDIT pdfinvoice.php

 

FIND:

 

//Email
$this->SetX(0);
$this->SetY(43);
$this->SetFont(PDF_INV_CORE_FONT,'B',10);
$this->SetTextColor($highlight_color[0],$highlight_color[1],$highlight_color[2]);
$this->Ln(0);
$this->Cell(88);
$this->MultiCell(100, 6, tep_html_entity_decode(PDF_INV_EMAIL) . STORE_OWNER_EMAIL_ADDRESS,0,'R');

//Website
$this->SetX(0);
$this->SetY(48);
$this->SetFont(PDF_INV_CORE_FONT,'B',10);
$this->SetTextColor($highlight_color[0],$highlight_color[1],$highlight_color[2]);
$this->Ln(0);
$this->Cell(88);
$this->MultiCell(100, 6, tep_html_entity_decode(PDF_INV_WEB) . HTTP_SERVER,0,'R');

// VAT / Tax number (if enabled)
if (DISPLAY_PDF_TAX_NUMBER == 'true'){
$this->SetX(0);
$this->SetY(53);
$this->SetFont(PDF_INV_CORE_FONT,'B',10);
$this->SetTextColor($highlight_color[0],$highlight_color[1],$highlight_color[2]);
$this->Ln(0);
$this->Cell(88);
$this->MultiCell(100, 6, tep_html_entity_decode(PDF_TAX_NAME) . " " . PDF_TAX_NUMBER,0,'R');
  }

 

Adjust the SetX and Set Y to move the Web, Email and VAT/Tax number elements

 

To change the order number, find

 

//Draw Order Number Text
$pdf->Text(10,113, tep_html_entity_decode(PRINT_INVOICE_ORDERNR) . (int)$HTTP_GET_VARS['order_id']);	
//Draw Date of Order Text
$pdf->Text(75,113, tep_html_entity_decode(PRINT_INVOICE_DATE) . tep_date_short($order->info['date_purchased']));	
//Draw Payment Method Text

 

Adjust the 10 & 75 to move the x coordinates. You may need to reduct the font size of the order reference. See post 166 above for instructions for changing font size for individual elements.

 

HTH

 

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites
Hi Chris and all the people.

 

I have the same problem that Stubbsy

 

Please tell me the solution for this problem.

 

Regards.

 

Hi Jose,

 

Did you try the fix I posted for Dave? (stubbsy) - Post #161 above.

I'm still trying to fix Dave's, though he has a fully customised pdfinvoice.php that uses parts of my code.

The fix in #161 works for me with 12 lines.

Please give it a go and let me know what happens - it would help me either way

Regards,

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites

Hi Chris

I've improvised a solution.

Last code shows all the attributes.

With this new code we show only the selectec attributes. And we have more space in the page for new products.

 

   $attrib_count = (strlen($order->products[$i]['name']) > 45 ) ? 1 : 0;
  $attrib_visible = 0;   
//get attribs and concat. Use attrib count to increase cell height for row
	if ( (isset($order->products[$i]['attributes'])) && (sizeof($order->products[$i]['attributes']) > 0) ) {
	for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
	if ($order->products[$i]['attributes'][$j]['value'] != '---'){

	$prod_attribs .= "\n- " .$order->products[$i]['attributes'][$j]['option'] . ': ' . $order->products[$i]['attributes'][$j]['value'];


	$attrib_visible++;}
//$order->products[$i]['attributes'][$j]['value']; 

	$attrib_count++;

	}

}
$attrib_visible++;
$attrib_count++;

$product_name_attrib_contact = $order->products[$i]['name'] . $prod_attribs;




$pdf->SetFont(PDF_INV_CORE_FONT,'',10);
$pdf->SetY($Y_Table_Position);
$pdf->SetX(6);
// Pad cell by ($attrib_count * \n) linebreaks to 'force' qty to cell top
//$n_padd="";
//for($n_count=0; $n_count<$prod_attribs; $n_count++) {
//$n_padd.="\n";
//}
$pdf->MultiCell(9,($cell_height*$attrib_visible), ($order->products[$i]['qty']) ,1,'C');
// end add padding

 

Now i have a question for you. Is possible a watermark with a image instead of a text?

 

Regards.

Share this post


Link to post
Share on other sites
Hi Chris

I've improvised a solution.

Last code shows all the attributes.

With this new code we show only the selectec attributes. And we have more space in the page for new products.

 

Thanks Jose,

 

I'm a bit confused however. Have you set up your attributes to have "non chosen" options (set as "---" as the value)?

 

As to an image watermark, to be honest, I'd never given it any thought .... Probablemente mañana :D

 

Hasta luego

 

Chris


Please use forum for support rather than PM - PMs unrelated to my contributions will be ignored.

Google Site Search is your friend

My contributions: Tracking Module | PDF Customer Invoice | Subcategory textboxes

Share this post


Link to post
Share on other sites
Thanks Jose,

 

I'm a bit confused however. Have you set up your attributes to have "non chosen" options (set as "---" as the value)?

 

As to an image watermark, to be honest, I'd never given it any thought .... Probablemente mañana :D

 

Hasta luego

 

Chris

 

Hola.

Al poner sólo los atributos que están activos, gano espacio para nuevos productos y no hay descuadre en las páginas posteriores. El valor "---" es el que pongo como atributo sin valor. Obviamente, se puede elegir cualquiera, yo elegí este. Se que es una solución un tanto rara, porque no solucionamos el problema del overflow, ya que si el cliente elige todos los atributos, volveremos a tener overflow y descuadre. He intentado implementar un salto de página cuando el número de atributos es determinado, pero no funciona correctamente y sigo teniendo descuadre.

 

Saludos.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×