knacknuss Posted April 14, 2005 Share Posted April 14, 2005 Hi all I have adapted Neil Westlakes PDF invoice to a PDF packing slip. The only thing missing, are the attributes belonging to the products eg. Nice Shirt - color: red - Size: 12 Can someone please help :) Thanks! <?php /* $Id: create_pdf,v 1.4 2005/04/07 osCommerce, Open Source E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2003 osCommerce Released under the GNU General Public License Written by Neil Westlake ([email protected]) for www.Digiprintuk.com Version History: 1.1 Initial release 1.2 Corrected problem displaying PDF when from a HTTPS URL. 1.3 Modified item display to allow page continuation when more than 20 products are on one invoice. 1.4 Corrected problem with page continuation, now invoices will allow for an unlimited amount of products on one invoice */ 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'); 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/invoice_logo.jpg',3,5,40); // Invoice Number and date $this->SetFont('Arial','B',8); $this->SetTextColor(0,102,153); $this->SetY(37); $this->MultiCell(50,4,"Lieferschein: #" . $oID . "\n" . $date ,0,'L'); // Company Address $this->SetX(0); $this->SetY(10); $this->SetFont('Arial','B',8); $this->SetTextColor(0,102,153); $this->Ln(0); $this->Cell(149); $this->MultiCell(50, 3.5, STORE_NAME_ADDRESS,0,'R'); } function Footer() { //Position at 1.5 cm from bottom $this->SetY(-19); //Arial italic 8 $this->SetFont('Arial','',12); $this->SetTextColor(0,102,153); $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(4,2,4); // Add the first page $pdf->AddPage(); //Draw the top line with invoice text $pdf->Cell(50); $pdf->SetY(62); $pdf->SetDrawColor(153,153,153); $pdf->Cell(15,.1,'',1,1,'L',1); $pdf->SetFont('Arial','BI',15); $pdf->SetTextColor(153,153,153); $pdf->Text(22,63.5,'Lieferschein'); $pdf->SetY(62); $pdf->SetDrawColor(153,153,153); $pdf->Cell(56); $pdf->Cell(142,.1,'',1,1,'L',1); //Draw Box for Invoice Address $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.5); $pdf->SetFillColor(224); $pdf->RoundedRect(3, 67, 90, 35, 2, 'DF'); //Draw the invoice address text $pdf->SetFont('Arial','B',8); $pdf->SetTextColor(0); $pdf->Text(8,74,ENTRY_SOLD_TO); $pdf->SetX(0); $pdf->SetY(78); //$pdf->SetFont('Arial','B',8); //$pdf->SetTextColor(0); $pdf->Cell(5); $pdf->MultiCell(70, 3.3, tep_address_format(1, $order->customer, '', '', "\n"),0,'L'); //Draw Box for Delivery Address $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.5); $pdf->SetFillColor(255); $pdf->RoundedRect(112, 67, 90, 35, 2, 'DF'); //Draw the invoice delivery address text $pdf->SetFont('Arial','B',8); $pdf->SetTextColor(0); $pdf->Text(117,74,ENTRY_SHIP_TO); $pdf->SetX(0); $pdf->SetY(78); $pdf->Cell(115); $pdf->MultiCell(50, 3.3, tep_address_format(1, $order->delivery, '', '', "\n"),0,'L'); //Draw Box for Order Number, Date & Payment method $pdf->SetDrawColor(0); $pdf->SetLineWidth(0.5); $pdf->SetFillColor(224); $pdf->RoundedRect(3, 107, 199, 11, 2, 'DF'); //Draw Order Number Text $temp = str_replace(' ', ' ', PRINT_INVOICE_ORDERNR); $pdf->Text(7,113, $temp . tep_db_input($oID)); //Draw Date of Order Text $temp = str_replace(' ', ' ', PRINT_INVOICE_DATE); $pdf->Text(75,113,$temp . tep_date_short($order->info['date_purchased'])); //Draw Payment Method Text $temp = substr ($order->info['payment_method'] , 0, 23); $pdf->Text(130,113,ENTRY_PAYMENT_METHOD . ' ' . $temp); //$pdf->Cell(198,29,ENTRY_PAYMENT_METHOD . ' ' . $temp, 0, 0, 'R'); //Fields Name position $Y_Fields_Name_position = 125; //Table position, under Fields Name $Y_Table_Position = 131; function output_table_heading($Y_Fields_Name_position){ global $pdf; //First create each Field Name //Gray color filling each Field Name box $pdf->SetFillColor(232,232,232); //Bold Font for Field Name $pdf->SetFont('Arial','B',8); $pdf->SetY($Y_Fields_Name_position); $pdf->SetX(5); $pdf->Cell(10,6,'Anz.',1,0,'C',1); $pdf->SetX(15); $pdf->Cell(25,6,TABLE_HEADING_PRODUCTS_MODEL,1,0,'C',1); $pdf->SetX(40); $pdf->Cell(160,6,TABLE_HEADING_PRODUCTS,1,0,'C',1); //$pdf->SetX(105); $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++) { $pdf->SetFont('Arial','',8); $pdf->SetY($Y_Table_Position); $pdf->SetX(5); $pdf->MultiCell(10,6,$order->products[$i]['qty'],1,'C'); $pdf->SetY($Y_Table_Position); $pdf->SetX(40); if (strlen($order->products[$i]['name'] ) > 40 && strlen($order->products[$i]['name']) < 50){ $pdf->SetFont('Arial','',8); $pdf->MultiCell(160,6,$order->products[$i]['name'],1,'L'); } else if (strlen($order->products[$i]['name']) > 50){ $pdf->SetFont('Arial','',8); $pdf->MultiCell(160,6,substr($order->products[$i]['name'],0,50),1,'L'); } else{ $pdf->MultiCell(160,6,$order->products[$i]['name'],1,'L'); } $pdf->SetFont('Arial','',8); //$pdf->SetY($Y_Table_Position); //$pdf->SetX(95); //$pdf->MultiCell(15,6,tep_display_tax_value($order->products[$i]['tax']) . '%',1,'C'); $pdf->SetY($Y_Table_Position); $pdf->SetX(15); $pdf->SetFont('Arial','',8); $pdf->MultiCell(25,6,$order->products[$i]['model'],1,'C'); $pdf->SetY($Y_Table_Position); $pdf->SetX(120); $pdf->SetFont('Arial','',8); $pdf->SetY($Y_Table_Position); $pdf->SetX(140); $pdf->SetY($Y_Table_Position); $pdf->SetX(160); $pdf->SetY($Y_Table_Position); $pdf->SetX(180); $Y_Table_Position += 6; //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; } } // 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(); ?> Quote Link to comment Share on other sites More sharing options...
Guest Posted August 22, 2005 Share Posted August 22, 2005 Did you get this issue figured out? I have just installed that contribution and done the same thing for my packing slip. Would love to have the attributes added! Quote Link to comment Share on other sites More sharing options...
Guest Posted September 14, 2005 Share Posted September 14, 2005 Any luck here guys!!! Really need a solution to this problem... any help REALLY appreciated! Quote Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 Still haven't found a solution... I think I may go ahead and attempt some changes and see what happens. I'll post here if I figure out anything good. Jenni Quote Link to comment Share on other sites More sharing options...
Guest Posted September 16, 2005 Share Posted September 16, 2005 Still haven't found a solution... I think I may go ahead and attempt some changes and see what happens. I'll post here if I figure out anything good. Jenni <{POST_SNAPBACK}> I wish you luck!!!! i have been trying to igure it out now for about 4 days and have had absolutly no luck! Cheers, Ed Quote Link to comment Share on other sites More sharing options...
yeahyeahyeah Posted October 17, 2005 Share Posted October 17, 2005 I wish you luck!!!! i have been trying to igure it out now for about 4 days and have had absolutly no luck! Cheers, Ed you'll need to take a look at orders.php and how that file display's product attribs. at the top of invoice.php for instance, $order=new order($oID) creates your order, now you have to loop through the product options for ($i=0, $n=sizeof($order->products); $i<$n; $i++) and print them out. Quote Link to comment Share on other sites More sharing options...
Guest Posted November 14, 2007 Share Posted November 14, 2007 you'll need to take a look at orders.php and how that file display's product attribs. at the top of invoice.php for instance, $order=new order($oID) creates your order, now you have to loop through the product options for ($i=0, $n=sizeof($order->products); $i<$n; $i++) and print them out. Hi Guys, Has anyone worked out how to add the attributes into the packingslip and invoice PDF's as it would be a great asset to have Please and thank you in advance Dan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.