Example #1
0
 protected function insertTotals($page, $source)
 {
     parent::insertTotals($page, $source);
     if (Mage::getStoreConfig('magero_invoice/vat_options/tva_incasare')) {
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         $this->_setFontBold($page, 10);
         $page->drawText("TVA la încasare", 435, $this->y - 10, 'UTF-8');
     }
     if (Mage::getStoreConfig('magero_invoice/vat_options/regime') != 'Impozabil TVA') {
         $page->drawText("Regim TVA: " . Mage::getStoreConfig('magero_invoice/vat_options/regime'), 235, $this->y - 50, 'UTF-8');
     }
 }
Example #2
0
 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
     }
 }
Example #3
0
 public function drawLineBlocks(Zend_Pdf_Page $page, array $draw, array $pageSettings = array())
 {
     if (Mage::getStoreConfig('advancedinvoiceprinting_options/general/enable') == 0) {
         return parent::drawLineBlocks($page, $draw, $pageSettings);
     }
     foreach ($draw as $itemsProp) {
         if (!isset($itemsProp['lines']) || !is_array($itemsProp['lines'])) {
             Mage::throwException(Mage::helper('sales')->__('Invalid draw line data. Please define "lines" array.'));
         }
         $lines = $itemsProp['lines'];
         $height = isset($itemsProp['height']) ? $itemsProp['height'] : 10;
         if (empty($itemsProp['shift'])) {
             $shift = 0;
             foreach ($lines as $line) {
                 $maxHeight = 0;
                 foreach ($line as $column) {
                     $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                     if (!is_array($column['text'])) {
                         $column['text'] = array($column['text']);
                     }
                     $top = 0;
                     foreach ($column['text'] as $part) {
                         $top += $lineSpacing;
                     }
                     $maxHeight = $top > $maxHeight ? $top : $maxHeight;
                 }
                 $shift += $maxHeight;
             }
             $itemsProp['shift'] = $shift;
         }
         if ($this->y - $itemsProp['shift'] < $this->calFooterTopArea()) {
             $page = $this->newPage($pageSettings);
         }
         foreach ($lines as $line) {
             $maxHeight = 0;
             foreach ($line as $column) {
                 $fontSize = empty($column['font_size']) ? 10 : $column['font_size'];
                 if (!empty($column['font_file'])) {
                     $font = Zend_Pdf_Font::fontWithPath($column['font_file']);
                     $page->setFont($font, $fontSize);
                 } else {
                     $fontStyle = empty($column['font']) ? 'regular' : $column['font'];
                     switch ($fontStyle) {
                         case 'bold':
                             $font = $this->_setFontBold($page, $fontSize);
                             break;
                         case 'italic':
                             $font = $this->_setFontItalic($page, $fontSize);
                             break;
                         default:
                             $font = $this->_setFontRegular($page, $fontSize);
                             break;
                     }
                 }
                 if (!is_array($column['text'])) {
                     $column['text'] = array($column['text']);
                 }
                 $lineSpacing = !empty($column['height']) ? $column['height'] : $height;
                 $top = 0;
                 foreach ($column['text'] as $part) {
                     if ($this->y - $lineSpacing < $this->calFooterTopArea()) {
                         $page = $this->newPage($pageSettings);
                     }
                     $feed = $column['feed'];
                     $textAlign = empty($column['align']) ? 'left' : $column['align'];
                     $width = empty($column['width']) ? 0 : $column['width'];
                     switch ($textAlign) {
                         case 'right':
                             if ($width) {
                                 $feed = $this->getAlignRight($part, $feed, $width, $font, $fontSize);
                             } else {
                                 $feed = $feed - $this->widthForStringUsingFontSize($part, $font, $fontSize);
                             }
                             break;
                         case 'center':
                             if ($width) {
                                 $feed = $this->getAlignCenter($part, $feed, $width, $font, $fontSize);
                             }
                             break;
                     }
                     $page->drawText($part, $feed, $this->y - $top, 'UTF-8');
                     $top += $lineSpacing;
                 }
                 $maxHeight = $top > $maxHeight ? $top : $maxHeight;
             }
             $this->y -= $maxHeight;
         }
     }
     return $page;
 }
 public function myPdf($invoices = array())
 {
     $debug = false;
     if ($debug) {
         $this->_beforeGetPdf();
         $this->_initRenderer('invoice');
         $pdf = new Zend_Pdf();
         $this->_setPdf($pdf);
         $style = new Zend_Pdf_Style();
         $this->_setFontBold($style, 10);
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         //$page->setFillColor(new Zend_Pdf_Color_RGB(1, 0, 0));
         $this->_setFontRegular($page);
         //$page->drawText('Dies ist ein Test', 35, 780, 'UTF-8');
         $x = 50;
         $y = 800;
     }
     foreach ($invoices as $invoice) {
         $order = $invoice->getOrder();
         $billing = $order->getBillingAddress();
         $payment = $order->getPayment()->getMethodInstance();
         // Immer in der Basisw�hrung des Shops abrechnen
         //$amount		= number_format($this->getOrder()->getBaseGrandTotal(), 2, '.', '');
         //$currency	= $this->getOrder()->getBaseCurrencyCode();
         // in der aktuell ausgew�hlten W�hrung abrechnen
         $amount = number_format($order->getGrandTotal(), 2, '.', '');
         $currency = $order->getOrderCurrencyCode();
         $street = $billing->getStreet();
         $locale = explode('_', Mage::app()->getLocale()->getLocaleCode());
         if (is_array($locale) && !empty($locale)) {
             $language = $locale[0];
         } else {
             $language = $this->getDefaultLocale();
         }
         $userId = $order->getCustomerId();
         $orderId = $payment->getTransactionId();
         $insertId = $orderId;
         $orderId .= '-' . $userId;
         $payCode = 'IV';
         $payMethod = 'FI';
         $userData = array('firstname' => $billing->getFirstname(), 'lastname' => $billing->getLastname(), 'salutation' => 'MR', 'street' => $street[0], 'zip' => $billing->getPostcode(), 'city' => $billing->getCity(), 'country' => $billing->getCountry(), 'email' => $order->getCustomerEmail(), 'ip' => $order->getRemoteIp());
         if (empty($userData['ip'])) {
             $userData['ip'] = $_SERVER['REMOTE_ADDR'];
         }
         // Falls IP Leer, dann aus dem Server holen
         // Payment Request zusammenschrauben
         $data = $payment->prepareData($orderId, $amount, $currency, $payCode, $userData, $language, $payMethod, true);
         $bsParams = $payment->getBillsafeBasket($order);
         $data = array_merge($data, $bsParams);
         $data['IDENTIFICATION.REFERENCEID'] = $order->getPayment()->getLastTransId();
         if ($debug) {
             foreach ($data as $k => $v) {
                 $page->drawText($k . ': ' . $v, $x, $y, 'UTF-8');
                 $y -= 10;
             }
         }
         // Mit Payment kommunizieren
         $res = $payment->doRequest($data);
         //if ($debug) echo '<pre>resp('.print_r($this->response, 1).')</pre>';
         //if ($debug) echo '<pre>'.print_r($res, 1).'</pre>';
         // Payment Antwort auswerten
         $res = $payment->parseResult($res);
         //if ($debug) echo '<pre>'.print_r($res, 1).'</pre>';
         if ($debug) {
             $page->drawText(print_r($res, 1), $x, $y, 'UTF-8');
         }
     }
     if ($debug) {
         $this->_afterGetPdf();
         return $pdf;
     }
     return parent::getPdf($invoices);
 }
Example #5
0
 /**
  * Overriden to add call for _drawCheckoutFields method
  *
  * @param  array $invoices
  * @return Zend_Pdf
  */
 public function getPdf($invoices = array())
 {
     if (!Mage::getStoreConfigFlag('checkoutfields/print/pdf_invoice')) {
         return parent::getPdf($invoices);
     }
     $this->_beforeGetPdf();
     $this->_initRenderer('invoice');
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($invoices as $invoice) {
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->emulate($invoice->getStoreId());
             Mage::app()->setCurrentStore($invoice->getStoreId());
         }
         if (method_exists($this, 'insertDocumentNumber')) {
             $page = $this->newPage();
             $order = $invoice->getOrder();
             /* Add image */
             $this->insertLogo($page, $invoice->getStore());
             /* Add address */
             $this->insertAddress($page, $invoice->getStore());
             /* Add head */
             $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
             /* Add document text and number */
             $this->insertDocumentNumber($page, Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId());
             // override start
             $this->_drawCheckoutFields($page, $order);
             // override end
             /* Add table */
             $this->_drawHeader($page);
             /* Add body */
             foreach ($invoice->getAllItems() as $item) {
                 if ($item->getOrderItem()->getParentItem()) {
                     continue;
                 }
                 /* Draw item */
                 $this->_drawItem($item, $page, $order);
                 $page = end($pdf->pages);
             }
             /* Add totals */
             $this->insertTotals($page, $invoice);
             if ($invoice->getStoreId()) {
                 Mage::app()->getLocale()->revert();
             }
         } else {
             $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
             $pdf->pages[] = $page;
             $order = $invoice->getOrder();
             /* Add image */
             $this->insertLogo($page, $invoice->getStore());
             /* Add address */
             $this->insertAddress($page, $invoice->getStore());
             /* Add head */
             $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
             // override start
             $this->_drawCheckoutFields($page, $order);
             // override end
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
             $this->_setFontRegular($page);
             $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
             /* Add table */
             $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, $this->y, 570, $this->y - 15);
             $this->y -= 10;
             /* Add table head */
             $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
             $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
             $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
             $this->y -= 15;
             $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
             /* Add body */
             foreach ($invoice->getAllItems() as $item) {
                 if ($item->getOrderItem()->getParentItem()) {
                     continue;
                 }
                 if ($this->y < 15) {
                     $page = $this->newPage(array('table_header' => true));
                 }
                 /* Draw item */
                 $page = $this->_drawItem($item, $page, $order);
             }
             /* Add totals */
             $page = $this->insertTotals($page, $invoice);
             if ($invoice->getStoreId()) {
                 Mage::app()->getLocale()->revert();
             }
         }
     }
     $this->_afterGetPdf();
     return $pdf;
 }
Example #6
0
 /**
  * Draw header for item table
  *
  * use _drawHeader for Magento 1.7+
  * maintain compatibility with Magento 1.5
  *
  * @param $page
  */
 protected function _printTableHead($page)
 {
     if (method_exists($this, '_drawHeader')) {
         return parent::_drawHeader($page);
     }
     $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
     $this->_setFontRegular($page);
     /* Add table */
     $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, $this->y, 570, $this->y - 15);
     $this->y -= 10;
     /* Add table head */
     $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
     $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
     $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
     $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
     $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
     $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
     $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
     $this->y -= 15;
 }
Example #7
0
 public function getPdf($invoices = array())
 {
     foreach ($invoices as $invoice) {
         if ($invoice->getOrder()->getPayment()->getMethod() != 'sofortrechnung') {
             return parent::getPdf($invoices);
         }
         break;
     }
     $this->_beforeGetPdf();
     $this->_initRenderer('invoice');
     $pdf = new Zend_Pdf();
     $this->_setPdf($pdf);
     $style = new Zend_Pdf_Style();
     $this->_setFontBold($style, 10);
     foreach ($invoices as $invoice) {
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->emulate($invoice->getStoreId());
             Mage::app()->setCurrentStore($invoice->getStoreId());
         }
         $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4);
         $pdf->pages[] = $page;
         $order = $invoice->getOrder();
         $tid = $order->getPayment()->getPnSuTransactionId();
         if (!empty($tid)) {
             $sObj = new SofortLib_TransactionData(Mage::getStoreConfig('payment/sofort/configkey'));
             $sObj->setTransaction($tid)->sendRequest();
             if ($sObj->isError()) {
                 Mage::throwException(Mage::helper('sales')->__($sObj->getError()));
                 return;
             } else {
                 $url = $sObj->getInvoiceUrl();
                 $pdf = file_get_contents($url);
                 return Zend_Pdf::parse($pdf);
             }
         }
         /* Add image */
         $this->insertLogo($page, $invoice->getStore());
         /* Add address */
         $this->insertAddress($page, $invoice->getStore());
         /* Add head */
         $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId()));
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
         $this->_setFontRegular($page);
         $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8');
         /* Add table */
         $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, $this->y, 570, $this->y - 15);
         $this->y -= 10;
         /* Add table head */
         $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4));
         $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8');
         $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8');
         $this->y -= 15;
         $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
         /* Add body */
         foreach ($invoice->getAllItems() as $item) {
             if ($item->getOrderItem()->getParentItem()) {
                 continue;
             }
             if ($this->y < 15) {
                 $page = $this->newPage(array('table_header' => true));
             }
             /* Draw item */
             $page = $this->_drawItem($item, $page, $order);
         }
         /* Add totals */
         $page = $this->insertTotals($page, $invoice);
         if ($invoice->getStoreId()) {
             Mage::app()->getLocale()->revert();
         }
     }
     $this->_afterGetPdf();
     return $pdf;
 }