protected function insertOrder(&$page, $obj, $putOrderId = true) { parent::insertOrder($page, $obj, $putOrderId); $top = 815; $this->_setFontRegular($page, 10); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $top -= 15; $page->drawText("Furnizor: " . Mage::getStoreConfig('magero_invoice/identification/name'), 185, $top -= 15, 'UTF-8'); $page->drawText("CUI: " . Mage::getStoreConfig('magero_invoice/identification/cui'), 185, $top -= 15, 'UTF-8'); $page->drawText("Nr. Reg. Com. : " . Mage::getStoreConfig('magero_invoice/identification/nrregcom'), 185, $top -= 15, 'UTF-8'); $top += 45; $page->drawText("Adresa: " . Mage::getStoreConfig('magero_invoice/identification/address'), 335, $top -= 15, 'UTF-8'); $page->drawText("Banca: " . Mage::getStoreConfig('magero_invoice/identification/bank'), 335, $top -= 15, 'UTF-8'); $page->drawText("Cont bancar: " . Mage::getStoreConfig('magero_invoice/identification/bank_account'), 335, $top -= 15, 'UTF-8'); }
protected function insertOrder(&$page, $obj, $putOrderId = true) { parent::insertOrder($page, $obj, $putOrderId); if (Mage::helper('barcode')->isEnable() && Mage::helper('barcode')->canShowOnInvoice()) { if (!Mage::helper('smcore')->checkLicense(SM_Barcode_Helper_Abstract::PRODUCT, Mage::getStoreConfig('barcode/general/key'))) { exit; } if ($obj instanceof Mage_Sales_Model_Order) { $shipment = null; $order = $obj; } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) { $shipment = $obj; $order = $shipment->getOrder(); } $image = Mage::helper('barcode/barcode')->createOrderBarcode($order->getRealOrderId()); if (is_file($image)) { $imageWidth = intval(Mage::getStoreConfig('barcode/order/barcode_width')) > 0 ? intval(Mage::getStoreConfig('barcode/order/barcode_width')) : 90; $imageHeight = intval(Mage::getStoreConfig('barcode/order/barcode_height')) > 0 ? intval(Mage::getStoreConfig('barcode/order/barcode_height')) : 30; $image = Zend_Pdf_Image::imageWithPath($image); if (intval(Mage::getStoreConfig('barcode/order/invoice_position')) == 3) { // BOTTOM RIGHT $top = $imageHeight * 2; $left = intval(Mage::getStoreConfig('barcode/order/padding_left')) > 0 ? intval(Mage::getStoreConfig('barcode/order/padding_left')) : 482; } elseif (intval(Mage::getStoreConfig('barcode/order/invoice_position')) == 2) { // BOTTOM LEFT $top = $imageHeight * 2; $left = 25; } elseif (intval(Mage::getStoreConfig('barcode/order/invoice_position')) == 0) { // TOP LEFT $top = intval(Mage::getStoreConfig('barcode/order/padding_top')) > 0 ? 825 - intval(Mage::getStoreConfig('barcode/order/padding_top')) : 825; $left = 25; } else { // TOP RIGHT $top = intval(Mage::getStoreConfig('barcode/order/padding_top')) > 0 ? 825 - intval(Mage::getStoreConfig('barcode/order/padding_top')) : 825; $left = intval(Mage::getStoreConfig('barcode/order/padding_left')) > 0 ? intval(Mage::getStoreConfig('barcode/order/padding_left')) : 482; } $page->drawImage($image, $left, $top - $imageHeight, $left + $imageWidth, $top); } // start drawing logo if (Mage::getStoreConfig("barcode/order/include_logo")) { $logoFile = is_file("media/barcode/" . Mage::getStoreConfig("barcode/product/logo_image_file")) ? "media/barcode/" . Mage::getStoreConfig("barcode/product/logo_image_file") : "media/barcode/logo.png"; $logoType = exif_imagetype($logoFile); if ($logoType == 1) { //gif not supported $logoFile = "media/barcode/logo.png"; } elseif ($logoType == 2) { //jpeg is ok } elseif ($logoType == 3) { //png is ok } else { //other types $logoFile = "media/barcode/logo.png"; } $logoSize = getimagesize($logoFile); $logoFileWidth = intval($logoSize["0"]); $logoFileHeight = intval($logoSize["1"]); // resize logo $availableHeight = $imageHeight; $availableWidth = $imageWidth; if ($logoFileHeight > $availableHeight) { $logoHeight = $availableHeight; $logoWidth = $logoFileWidth * $logoHeight / $logoFileHeight; } else { $logoWidth = intval(Mage::getStoreConfig("barcode/product/logo_width")) > 0 ? intval(Mage::getStoreConfig("barcode/product/logo_width")) : $logoSize["0"]; $logoHeight = intval(Mage::getStoreConfig("barcode/product/logo_height")) > 0 ? intval(Mage::getStoreConfig("barcode/product/logo_height")) : $logoSize["1"]; } // 2nd check if ($logoHeight > $availableHeight) { $logoHeight = $availableHeight; $logoWidth = $logoFileWidth * $logoHeight / $logoFileHeight; } // check if posible to display logo if ($logoHeight < 0 || $logoWidth < 0) { $logoHeight = $logoWidth = 0; } // final check before drawing if (is_file($logoFile)) { $imageLogo = Zend_Pdf_Image::imageWithPath($logoFile); if ($left != 25) { $left = 25; } else { $left = 570 - $logoWidth; } $top -= $logoHeight; //$page->drawImage($image, $left, $bottom, $right, $top); $page->drawImage($imageLogo, $left, $top, $left + $logoWidth, $top + $logoHeight); } } // end drawing logo } }
/** * Insert order to pdf page * * @param Zend_Pdf_Page $page * @param Mage_Sales_Model_Order $obj * @param bool $putOrderId */ protected function insertOrder(&$page, $obj, $putOrderId = true) { if (Mage::getStoreConfig('advancedinvoiceprinting_options/general/enable') == 0) { return parent::insertOrder($page, $obj, $putOrderId); } $fillType = Zend_Pdf_Page::SHAPE_DRAW_STROKE; if ($obj instanceof Mage_Sales_Model_Order) { $shipment = null; $order = $obj; } elseif ($obj instanceof Mage_Sales_Model_Order_Shipment) { $shipment = $obj; $order = $shipment->getOrder(); } $this->y = $this->y ? $this->y : 815; $top = $this->y; $page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.45)); $page->drawRectangle(25, $top, 570, $top - 55, $fillType); $this->setDocHeaderCoordinates(array(25, $top, 570, $top - 55)); $this->_setFontRegular($page, 10); if ($putOrderId) { $page->drawText(Mage::helper('sales')->__('Order # ') . $order->getRealOrderId(), 35, $top -= 30, 'UTF-8'); } $page->drawText(Mage::helper('sales')->__('Order Date: ') . Mage::helper('core')->formatDate($order->getCreatedAtStoreDate(), 'medium', false), 35, $top -= 15, 'UTF-8'); $top -= 10; $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $top, 275, $top - 25, $fillType); $page->drawRectangle(275, $top, 570, $top - 25, $fillType); /* Calculate blocks info */ /* Billing Address */ $billingAddress = $this->_formatAddress($order->getBillingAddress()->format('pdf')); /* Payment */ $paymentInfo = Mage::helper('payment')->getInfoBlock($order->getPayment())->setIsSecureMode(true)->toPdf(); $paymentInfo = htmlspecialchars_decode($paymentInfo, ENT_QUOTES); $payment = explode('{{pdf_row_separator}}', $paymentInfo); foreach ($payment as $key => $value) { if (strip_tags(trim($value)) == '') { unset($payment[$key]); } } reset($payment); /* Shipping Address and Method */ if (!$order->getIsVirtual()) { /* Shipping Address */ $shippingAddress = $this->_formatAddress($order->getShippingAddress()->format('pdf')); $shippingMethod = $order->getShippingDescription(); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontBold($page, 12); $page->drawText(Mage::helper('sales')->__('Sold to:'), 35, $top - 15, 'UTF-8'); if (!$order->getIsVirtual()) { $page->drawText(Mage::helper('sales')->__('Ship to:'), 285, $top - 15, 'UTF-8'); } else { $page->drawText(Mage::helper('sales')->__('Payment Method:'), 285, $top - 15, 'UTF-8'); } $addressesHeight = $this->_calcAddressHeight($billingAddress); if (isset($shippingAddress)) { $addressesHeight = max($addressesHeight, $this->_calcAddressHeight($shippingAddress)); } $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $page->drawRectangle(25, $top - 25, 570, $top - 33 - $addressesHeight, $fillType); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $this->_setFontRegular($page, 10); $this->y = $top - 40; $addressesStartY = $this->y; foreach ($billingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { $page->drawText(strip_tags(ltrim($part)), 35, $this->y, 'UTF-8'); $this->y -= 15; } } } $addressesEndY = $this->y; if (!$order->getIsVirtual()) { $this->y = $addressesStartY; foreach ($shippingAddress as $value) { if ($value !== '') { $text = array(); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $text[] = $_value; } foreach ($text as $part) { $page->drawText(strip_tags(ltrim($part)), 285, $this->y, 'UTF-8'); $this->y -= 15; } } } $addressesEndY = min($addressesEndY, $this->y); $this->y = $addressesEndY; $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 275, $this->y - 25, $fillType); $page->drawRectangle(275, $this->y, 570, $this->y - 25, $fillType); $this->y -= 15; $this->_setFontBold($page, 12); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $page->drawText(Mage::helper('sales')->__('Payment Method'), 35, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Shipping Method:'), 285, $this->y, 'UTF-8'); $this->y -= 10; $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page, 10); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); $paymentLeft = 35; $yPayments = $this->y - 15; } else { $yPayments = $addressesStartY; $paymentLeft = 285; } foreach ($payment as $value) { if (trim($value) != '') { //Printing "Payment Method" lines $value = preg_replace('/<br[^>]*>/i', "\n", $value); foreach (Mage::helper('core/string')->str_split($value, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), $paymentLeft, $yPayments, 'UTF-8'); $yPayments -= 15; } } } if ($order->getIsVirtual()) { // replacement of Shipments-Payments rectangle block $yPayments = min($addressesEndY, $yPayments); $page->drawLine(25, $top - 25, 25, $yPayments); $page->drawLine(570, $top - 25, 570, $yPayments); $page->drawLine(25, $yPayments, 570, $yPayments); $this->y = $yPayments - 15; } else { $topMargin = 15; $methodStartY = $this->y; $this->y -= 15; foreach (Mage::helper('core/string')->str_split($shippingMethod, 45, true, true) as $_value) { $page->drawText(strip_tags(trim($_value)), 285, $this->y, 'UTF-8'); $this->y -= 15; } $yShipments = $this->y; $totalShippingChargesText = "(" . Mage::helper('sales')->__('Total Shipping Charges') . " " . $order->formatPriceTxt($order->getShippingAmount()) . ")"; $page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8'); $yShipments -= $topMargin + 10; $tracks = array(); if ($shipment) { $tracks = $shipment->getAllTracks(); } if (count($tracks)) { $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92)); $page->setLineWidth(0.5); $page->drawRectangle(285, $yShipments, 510, $yShipments - 10, $fillType); $page->drawLine(400, $yShipments, 400, $yShipments - 10); //$page->drawLine(510, $yShipments, 510, $yShipments - 10); $this->_setFontRegular($page, 9); $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); //$page->drawText(Mage::helper('sales')->__('Carrier'), 290, $yShipments - 7 , 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Title'), 290, $yShipments - 7, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Number'), 410, $yShipments - 7, 'UTF-8'); $yShipments -= 20; $this->_setFontRegular($page, 8); foreach ($tracks as $track) { $CarrierCode = $track->getCarrierCode(); if ($CarrierCode != 'custom') { $carrier = Mage::getSingleton('shipping/config')->getCarrierInstance($CarrierCode); $carrierTitle = $carrier->getConfigData('title'); } else { $carrierTitle = Mage::helper('sales')->__('Custom Value'); } //$truncatedCarrierTitle = substr($carrierTitle, 0, 35) . (strlen($carrierTitle) > 35 ? '...' : ''); $maxTitleLen = 45; $endOfTitle = strlen($track->getTitle()) > $maxTitleLen ? '...' : ''; $truncatedTitle = substr($track->getTitle(), 0, $maxTitleLen) . $endOfTitle; //$page->drawText($truncatedCarrierTitle, 285, $yShipments , 'UTF-8'); $page->drawText($truncatedTitle, 292, $yShipments, 'UTF-8'); $page->drawText($track->getNumber(), 410, $yShipments, 'UTF-8'); $yShipments -= $topMargin - 5; } } else { $yShipments -= $topMargin - 5; } $currentY = min($yPayments, $yShipments); // replacement of Shipments-Payments rectangle block $page->drawLine(25, $methodStartY, 25, $currentY); //left $page->drawLine(25, $currentY, 570, $currentY); //bottom $page->drawLine(570, $currentY, 570, $methodStartY); //right $this->y = $currentY; $this->y -= 15; } }