Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Usa_Block_Adminhtml_Dhl_Unitofmeasure
  • Mage_Usa_Helper_Data
  • Mage_Usa_Model_Shipping_Carrier_Abstract
  • Mage_Usa_Model_Shipping_Carrier_Abstract_Source_Mode
  • Mage_Usa_Model_Shipping_Carrier_Abstract_Source_Requesttype
  • Mage_Usa_Model_Shipping_Carrier_Dhl
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Contenttype
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Abstract
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Doc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Freedoc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Freenondoc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Nondoc
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Size
  • Mage_Usa_Model_Shipping_Carrier_Dhl_International_Source_Method_Unitofmeasure
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Dutypaymenttype
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Protection_Rounding
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Protection_Value
  • Mage_Usa_Model_Shipping_Carrier_Dhl_Source_Shipmenttype
  • Mage_Usa_Model_Shipping_Carrier_Fedex
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Dropoff
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Fedex_Source_Packaging
  • Mage_Usa_Model_Shipping_Carrier_Ups
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Container
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_DestType
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_OriginShipment
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Pickup
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Type
  • Mage_Usa_Model_Shipping_Carrier_Ups_Source_Unitofmeasure
  • Mage_Usa_Model_Shipping_Carrier_Usps
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Container
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Freemethod
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Machinable
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Method
  • Mage_Usa_Model_Shipping_Carrier_Usps_Source_Size
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Usa
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * DHL International (API v1.4) Label Creation
 29:  *
 30:  * @category Mage
 31:  * @package  Mage_Usa
 32:  * @author   Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
 35: {
 36:     /**
 37:      * X coordinate of a block
 38:      */
 39:     const X_INDENT = 60;
 40: 
 41:     /**
 42:      * Y coordinate of a block
 43:      */
 44:     const Y_INDENT = 15;
 45: 
 46:     /**
 47:      * Pdf Page Instance
 48:      *
 49:      * @var Zend_Pdf_Page
 50:      */
 51:     protected $_page;
 52: 
 53:     /**
 54:      * Create font instances
 55:      */
 56:     public function __construct()
 57:     {
 58:         $this->_fontNormal = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
 59:         $this->_fontBold = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD);
 60:     }
 61: 
 62:     /**
 63:      * Get Page
 64:      *
 65:      * @return Zend_Pdf_Page
 66:      */
 67:     public function getPage()
 68:     {
 69:         return $this->_page;
 70:     }
 71: 
 72:     /**
 73:      * Set Page
 74:      *
 75:      * @param Zend_Pdf_Page $page
 76:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
 77:      */
 78:     public function setPage(Zend_Pdf_Page $page)
 79:     {
 80:         $this->_page = $page;
 81:         return $this;
 82:     }
 83: 
 84:     /**
 85:      * Calculate x coordinate with identation
 86:      *
 87:      * @param int $pt
 88:      * @return int
 89:      */
 90:     protected function _x($pt)
 91:     {
 92:         return $pt + self::X_INDENT;
 93:     }
 94: 
 95:     /**
 96:      * Calculate y coordinate with identation
 97:      *
 98:      * @param int $pt
 99:      * @return int
100:      */
101:     protected function _y($pt)
102:     {
103:         return 595 - self::Y_INDENT - $pt;
104:     }
105: 
106:     /**
107:      * Add Border
108:      *
109:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
110:      * @throws Zend_Pdf_Exception
111:      */
112:     public function addBorder()
113:     {
114:         $x = $this->_x(0);
115:         $y = $this->_y(0);
116: 
117:         $image = new Zend_Pdf_Resource_Image_Jpeg(Mage::getBaseDir('media')  . DS .  'dhl' . DS . 'logo.jpg');
118:         $this->_page->drawImage($image, $x + 191, $this->_y(27), $x + 287, $this->_y(1));
119: 
120:         /* Vertical borders */
121:         $this->_page->drawLine($x, $y, $x, $this->_y(568));
122:         $this->_page->drawLine($x + 287.5, $y, $x + 287.5, $this->_y(568));
123:         $this->_page->drawLine($x + 139.5, $y, $x + 139.5, $this->_y(28));
124:         $this->_page->drawLine($x + 190.5, $y, $x + 190.5, $this->_y(28));
125: 
126:         /* Horisontal borders */
127:         $this->_page->drawLine($x, $y, $x + 288, $y);
128:         $this->_page->drawLine($x, $this->_y(28), $x + 288, $this->_y(28));
129:         $this->_page->drawLine($x, $this->_y(80.5), $x + 288, $this->_y(80.5));
130:         $this->_page->drawLine($x, $this->_y(164), $x + 288, $this->_y(164));
131:         $this->_page->drawLine($x, $this->_y(194), $x + 288, $this->_y(194));
132:         $this->_page->drawLine($x, $this->_y(217.5), $x + 288, $this->_y(217.5));
133:         $this->_page->drawLine($x, $this->_y(245.5), $x + 288, $this->_y(245.5));
134:         $this->_page->drawLine($x, $this->_y(568.5), $x + 288, $this->_y(568.5));
135: 
136:         $this->_page->setLineWidth(0.3);
137:         $x = $this->_x(3);
138:         $y = $this->_y(83);
139:         $this->_page->drawLine($x, $y, $x + 10, $y);
140:         $this->_page->drawLine($x, $y, $x, $y - 10);
141: 
142:         $x = $this->_x(3);
143:         $y = $this->_y(161);
144:         $this->_page->drawLine($x, $y, $x + 10, $y);
145:         $this->_page->drawLine($x, $y, $x, $y + 10);
146: 
147:         $x = $this->_x(285);
148:         $y = $this->_y(83);
149:         $this->_page->drawLine($x, $y, $x - 10, $y);
150:         $this->_page->drawLine($x, $y, $x, $y - 10);
151: 
152:         $x = $this->_x(285);
153:         $y = $this->_y(161);
154:         $this->_page->drawLine($x, $y, $x - 10, $y);
155:         $this->_page->drawLine($x, $y, $x, $y + 10);
156: 
157:         return $this;
158:     }
159: 
160:     /**
161:      * Add Product Name
162:      *
163:      * @param string $name
164:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
165:      * @throws InvalidArgumentException
166:      * @throws Zend_Pdf_Exception
167:      */
168:     public function addProductName($name)
169:     {
170:         $this->_page->saveGS();
171:         $this->_page->setFont($this->_fontBold, 9);
172:         if (!strlen($name)) {
173:             throw new InvalidArgumentException(Mage::helper('usa')->__('Product name is missing'));
174:         }
175:         $this->_page->drawText($name, $this->_x(8), $this->_y(12));
176:         $this->_page->restoreGS();
177:         return $this;
178:     }
179: 
180:     /**
181:      * Add Product Content Code
182:      *
183:      * @param string $code
184:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
185:      * @throws Zend_Pdf_Exception
186:      * @throws InvalidArgumentException
187:      */
188:     public function addProductContentCode($code)
189:     {
190:         $this->_page->saveGS();
191:         $codes = array(
192:             'TDK' => 0, 'TDE' => 1, 'TDL' => 0, 'TDM' => 1, 'TDT' => 0,
193:             'TDY' => 1, 'XPD' => 0, 'DOX' => 0, 'WPX' => 1, 'ECX' => 0,
194:             'DOM' => 0
195:         );
196:         if (!key_exists($code, $codes)) {
197:             throw new InvalidArgumentException(Mage::helper('usa')->__('Product content code is invalid'));
198:         }
199:         $font = null;
200:         if ($codes[$code]) {
201:             $this->_page->drawRectangle(
202:                 $this->_x(140),
203:                 $this->_y(0),
204:                 $this->_x(190),
205:                 $this->_y(28),
206:                 Zend_Pdf_Page::SHAPE_DRAW_FILL
207:             );
208:             $this->_page->setFillColor(new Zend_Pdf_Color_Html("#ffffff"));
209:             $font = $this->_fontBold;
210:         } else {
211:             $font = $this->_fontNormal;
212:         }
213:         $this->_page->setFont($font, 17);
214:         $this->_page->drawText($code, $this->_x(146), $this->_y(21));
215:         $this->_page->restoreGS();
216:         return $this;
217:     }
218: 
219:     /**
220:      * Add Unit Id
221:      *
222:      * @param int $id
223:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
224:      * @throws Zend_Pdf_Exception
225:      */
226:     public function addUnitId($id)
227:     {
228:         $this->_page->saveGS();
229:         $this->_page->setFont($this->_fontNormal, 6);
230: 
231:         $this->_page->drawText('Unit ID', $this->_x(8), $this->_y(20));
232:         $this->_page->restoreGS();
233:         return $this;
234:     }
235: 
236:     /**
237:      * Add Reference Data
238:      *
239:      * @param $data
240:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
241:      * @throws Zend_Pdf_Exception
242:      */
243:     public function addReferenceData($data)
244:     {
245:         $this->_page->saveGS();
246:         $this->_page->setFont($this->_fontNormal, 6);
247:         $this->_page->drawText('GREF', $this->_x(80), $this->_y(20));
248:         //TODO: Add reference data rendering
249:         $this->_page->restoreGS();
250:         return $this;
251:     }
252: 
253:     /**
254:      * Add Sender Info
255:      *
256:      * @param SimpleXMLElement $sender
257:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
258:      * @throws InvalidArgumentException
259:      * @throws Zend_Pdf_Exception
260:      */
261:     public function addSenderInfo(SimpleXMLElement $sender)
262:     {
263:         $this->_page->saveGS();
264:         $this->_page->setFont($this->_fontNormal, 6);
265:         $this->_page->drawText('From:', $this->_x(8), $this->_y(36));
266:         $contactName = implode(' ', array_filter(array((string)$sender->CompanyName,
267:             (string)$sender->Contact->PersonName))
268:         );
269:         if (!$contactName) {
270:             throw new InvalidArgumentException(Mage::helper('usa')->__('Sender contact name is missing'));
271:         }
272:         $this->_page->drawText($contactName, $this->_x(25), $this->_y(36));
273: 
274:         $phoneNumber = implode(' ', array_filter(array((string)$sender->Contact->PhoneNumber,
275:             (string)$sender->Contact->PhoneExtension))
276:         );
277:         $phoneNumber = $phoneNumber ? "Phone: " . $phoneNumber : null;
278:         $pageY = $this->_drawSenderAddress($sender->AddressLine, $phoneNumber);
279: 
280:         $divisionCode = (string)(strlen($sender->DivisionCode) ? $sender->DivisionCode . ' ' : null);
281:         $cityInfo = implode(' ', array_filter(array($sender->City, $divisionCode, $sender->PostalCode)));
282:         if (!strlen($cityInfo)) {
283:             throw new InvalidArgumentException(Mage::helper('usa')->__('Sender city info is missing'));
284:         }
285:         $this->_page->drawText($cityInfo, $this->_x(25), $pageY);
286: 
287:         $this->_page->setFont($this->_fontBold, 6);
288:         $countryInfo = (string)(($sender->CountryName) ? $sender->CountryName : $sender->CountryCode);
289:         if (!strlen($countryInfo)) {
290:             throw new InvalidArgumentException(Mage::helper('usa')->__('Sender country info is missing'));
291:         }
292:         $this->_page->drawText($countryInfo, $this->_x(25), $pageY - $this->_page->getFontSize());
293: 
294:         $this->_page->restoreGS();
295:         return $this;
296:     }
297: 
298:     /**
299:      * Draw Sender Address
300:      *
301:      * @param SimpleXMLElement $addressLines
302:      * @param string $phoneNumber
303:      * @return float
304:      * @throws Zend_Pdf_Exception
305:      */
306:     protected function _drawSenderAddress(SimpleXMLElement $addressLines, $phoneNumber)
307:     {
308:         $lines = array();
309:         foreach ($addressLines as $line) {
310:             $lines [] = $line;
311:         }
312: 
313:         $pageY = 0;
314:         if (strlen($lines[0]) > 28) {
315:             $firstLine = array_shift($lines);
316:             $pageY = $this->_page->drawLines(array($firstLine), $this->_x(25), $this->_y(42), 28);
317:             $this->_page->drawText($phoneNumber, $this->_x(103), $this->_y(42));
318:         } else {
319:             $pageY = $this->_y(42);
320:             $lineLength = $this->_page->getTextWidth(
321:                 $lines[0] . ' ', $this->_page->getFont(), $this->_page->getFontSize()
322:             );
323:             $this->_page->drawText($phoneNumber, $this->_x(25 + $lineLength), $this->_y(42));
324:         }
325: 
326:         return $this->_page->drawLines($lines, $this->_x(25), $pageY, 49);
327:     }
328: 
329:     /**
330:      * Add Origin Info
331:      *
332:      * @param string $serviceAreaCode
333:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
334:      * @throws InvalidArgumentException
335:      * @throws Zend_Pdf_Exception
336:      */
337:     public function addOriginInfo($serviceAreaCode)
338:     {
339:         if (strlen(!$serviceAreaCode)) {
340:             throw new InvalidArgumentException(Mage::helper('usa')->__('Origin serviceAreaCode is missing'));
341:         }
342:         $this->_page->saveGS();
343:         $this->_page->setFont($this->_fontNormal, 6);
344:         $this->_page->drawText("Origin:", $this->_x(260), $this->_y(36));
345:         $this->_page->setFont($this->_fontBold, 9);
346:         $this->_page->drawText($serviceAreaCode, $this->_x(260), $this->_y(45));
347: 
348:         $this->_page->restoreGS();
349:         return $this;
350:     }
351: 
352:     /**
353:      * Add Receive Info
354:      *
355:      * @param SimpleXMLElement $consignee
356:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
357:      * @throws Zend_Pdf_Exception
358:      */
359:     public function addReceiveInfo(SimpleXMLElement $consignee)
360:     {
361:         $this->_page->saveGS();
362: 
363:         $this->_page->setFont($this->_fontNormal, 9);
364:         $this->_page->drawText("To:", $this->_x(5), $this->_y(92));
365:         $this->_page->drawText($consignee->CompanyName, $this->_x(20), $this->_y(90));
366:         $y = $this->_page->drawLines($consignee->AddressLine, $this->_x(19), $this->_y(100), 50);
367: 
368:         $this->_page->setFont($this->_fontBold, 11);
369:         $cityInfo = implode(' ', array_filter(array($consignee->PostalCode, $consignee->City,
370:             $consignee->DivisionCode))
371:         );
372:         $y = min($y - 3, 460);
373:         $this->_page->drawLines(array($cityInfo, $consignee->CountryName), $this->_x(20), $y, 44);
374: 
375:         $this->_page->setFont($this->_fontNormal, 6);
376:         $this->_page->drawText('Contact:', $this->_x(260), $this->_y(90));
377: 
378:         $y = $this->_page->drawLines(array($consignee->Contact->PersonName), $this->_x(283), $this->_y(98), 25,
379:             Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page::ALIGN_RIGHT
380:         );
381:         $phoneNumber = implode(' ', array_filter(array($consignee->Contact->PhoneNumber,
382:             $consignee->Contact->PhoneExtension))
383:         );
384:         $this->_page->drawText($phoneNumber, $this->_x(283), $y, null,
385:             Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page::ALIGN_RIGHT
386:         );
387: 
388:         $this->_page->restoreGS();
389:         return $this;
390:     }
391: 
392:     /**
393:      * Add Destination Facility Code
394:      *
395:      * @param string $countryCode
396:      * @param string $serviceAreaCode
397:      * @param string $facilityCode
398:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
399:      * @throws InvalidArgumentException
400:      * @throws Zend_Pdf_Exception
401:      */
402:     public function addDestinationFacilityCode($countryCode, $serviceAreaCode, $facilityCode)
403:     {
404:         $this->_page->saveGS();
405:         $this->_page->setFont($this->_fontNormal, 20);
406:         $code = implode('-', array_filter(array($countryCode, $serviceAreaCode, $facilityCode)));
407: 
408:         if (!strlen($code)) {
409:             throw new InvalidArgumentException(Mage::helper('usa')->__('Destination facility code is empty'));
410:         }
411:         $this->_page->drawText($code, $this->_x(144), $this->_y(186), null,
412:             Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page::ALIGN_CENTER
413:         );
414: 
415:         $this->_page->restoreGS();
416:         return $this;
417:     }
418: 
419:     /**
420:      * Add Service Features Codes
421:      *
422:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
423:      * @throws Zend_Pdf_Exception
424:      */
425:     public function addServiceFeaturesCodes()
426:     {
427:         $this->_page->saveGS();
428:         $this->_page->drawRectangle($this->_x(0), $this->_y(195), $this->_x(218), $this->_y(217),
429:             Zend_Pdf_Page::SHAPE_DRAW_FILL
430:         );
431:         $this->_page->restoreGS();
432:         return $this;
433:     }
434: 
435:     /**
436:      * Add Delivery Date Code
437:      *
438:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
439:      * @throws Zend_Pdf_Exception
440:      */
441:     public function addDeliveryDateCode()
442:     {
443:         $this->_page->saveGS();
444: 
445:         $this->_page->setFont($this->_fontNormal, 6);
446:         $this->_page->drawText('Day:', $this->_x(220), $this->_y(201));
447:         $this->_page->drawText('Time:', $this->_x(250), $this->_y(201));
448: 
449:         $this->_page->setFont($this->_fontNormal, 20);
450: 
451:         $this->_page->restoreGS();
452:         return $this;
453:     }
454: 
455:     /**
456:      * Add Shipment Information
457:      *
458:      * @param Mage_Sales_Model_Order_Shipment $data
459:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page
460:      * @throws Exception
461:      */
462:     public function addShipmentInformation($data)
463:     {
464:         $this->_page->saveGS();
465:         $this->_page->setFont($this->_fontNormal, 6);
466: 
467:         $refCode = $data->getOrder()->getIncrementId();
468:         if (!$refCode) {
469:             throw new InvalidArgumentException(Mage::helper('usa')->__('Reference code is missing'));
470:         }
471:         $this->_page->drawText('Ref Code: ' . Mage::helper('usa')->__('Order #%s', $refCode), $this->_x(8),
472:             $this->_y(224)
473:         );
474:         $this->_page->restoreGS();
475:         return $this;
476:     }
477: 
478:     /**
479:      * Add Date Info
480:      * @param string $date
481:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
482:      * @throws Zend_Pdf_Exception
483:      */
484:     public function addDateInfo($date)
485:     {
486:         $this->_page->saveGS();
487: 
488:         $this->_page->setFont($this->_fontNormal, 6);
489:         $this->_page->drawText('Date:', $this->_x(160), $this->_y(224));
490:         $this->_page->drawText($date, $this->_x(150), $this->_y(231));
491: 
492:         $this->_page->restoreGS();
493:         return $this;
494:     }
495: 
496:     /**
497:      * Add Weight Info
498:      *
499:      * @param string $weight
500:      * @param string $unit
501:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
502:      * @throws InvalidArgumentException
503:      * @throws Zend_Pdf_Exception
504:      */
505:     public function addWeightInfo($weight, $unit)
506:     {
507:         $this->_page->saveGS();
508: 
509:         $units = array("K" => 'kg', "L" => 'lb');
510:         if (!isset($units[$unit])) {
511:             throw new InvalidArgumentException(Mage::helper('usa')->__('Weight unit is invalid'));
512:         }
513:         $unit = $units[$unit];
514: 
515:         $this->_page->setFont($this->_fontNormal, 6);
516:         $this->_page->drawText('Shpt Weight:', $this->_x(196), $this->_y(224));
517:         $this->_page->setFont($this->_fontBold, 11);
518:         $this->_page->drawText($weight . ' ' . $unit, $this->_x(195), $this->_y(234));
519: 
520:         $this->_page->restoreGS();
521:         return $this;
522:     }
523: 
524:     /**
525:      * Add Content: Shipment Description
526:      *
527:      * @param array $package
528:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
529:      * @throws Exception
530:      */
531:     public function addContentInfo($package)
532:     {
533:         $this->_page->saveGS();
534:         $this->_page->setFont($this->_fontNormal, 6);
535:         if (empty($package)) {
536:             throw new InvalidArgumentException(Mage::helper('usa')->__('Package content is missing'));
537:         }
538: 
539:         $x = 225;
540:         $y = 300;
541:         $this->_page->drawText('Content: ', $this->_x($x), $this->_y($y));
542:         $i = 0;
543:         foreach ($package['items'] as $item) {
544:             $i++;
545:             $this->_page->drawText(substr($item['name'], 0, 20), $this->_x($x), $this->_y($y += 6));
546:             if ($i == 12) {
547:                 break;
548:             }
549:         }
550:         $this->_page->restoreGS();
551:         return $this;
552:     }
553: 
554:     /**
555:      * Add Waybill Barcode
556:      *
557:      * @param string $number
558:      * @param string $barCode
559:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
560:      * @throws InvalidArgumentException
561:      * @throws Zend_Pdf_Exception
562:      */
563:     public function addWaybillBarcode($number, $barCode)
564:     {
565:         $this->_page->saveGS();
566: 
567:         if(!strlen($number) || !strlen($barCode)) {
568:             throw new InvalidArgumentException(Mage::helper('usa')->__('Waybill barcode information is missing'));
569:         }
570:         $image = new Zend_Pdf_Resource_Image_Png("data://image/png;base64," . $barCode);
571:         $this->_page->drawImage($image, $this->_x(0), $this->_y(296), $this->_x(232), $this->_y(375));
572: 
573:         $this->_page->setFont($this->_fontNormal, 9);
574:         $number = substr($number, 0, 2) . ' ' . substr($number, 2, 4) . ' ' . substr($number, 6, 4);
575:         $this->_page->drawText("WAYBILL " . $number, $this->_x(13.5), $this->_y(382));
576: 
577:         $this->_page->restoreGS();
578:         return $this;
579:     }
580: 
581:     /**
582:      * Add Routing Barcode
583:      *
584:      * @param string $routingCode
585:      * @param string $id
586:      * @param string $barCode
587:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
588:      * @throws InvalidArgumentException
589:      * @throws Zend_Pdf_Exception
590:      */
591:     public function addRoutingBarcode($routingCode, $id, $barCode)
592:     {
593:         $this->_page->saveGS();
594: 
595:         if(!$barCode) {
596:             throw new InvalidArgumentException(Mage::helper('usa')->__('Routing barcode is missing'));
597:         }
598: 
599:         $image = new Zend_Pdf_Resource_Image_Png("data://image/png;base64," . $barCode);
600:         $this->_page->drawImage($image, $this->_x(0), $this->_y(386), $this->_x(232), $this->_y(465));
601: 
602:         $this->_page->setFont($this->_fontNormal, 9);
603:         $routingText = '(' . $id . ')' . $routingCode;
604:         $this->_page->drawText($routingText, $this->_x(12), $this->_y(472));
605: 
606:         $this->_page->restoreGS();
607:         return $this;
608:     }
609: 
610:     /**
611:      * Add Piece Id Barcode
612:      *
613:      * @param string $dataIdentifier
614:      * @param string $licensePlate
615:      * @param string $barCode
616:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
617:      * @throws InvalidArgumentException
618:      * @throws Zend_Pdf_Exception
619:      */
620:     public function addPieceIdBarcode($dataIdentifier, $licensePlate, $barCode)
621:     {
622:         $this->_page->saveGS();
623: 
624:         if (!strlen($barCode)) {
625:             throw new InvalidArgumentException(Mage::helper('usa')->__('Piece Id barcode is missing'));
626:         }
627: 
628:         $image = new Zend_Pdf_Resource_Image_Png('data://image/png;base64,' . $barCode);
629:         $this->_page->drawImage($image, $this->_x(29), $this->_y(476), $this->_x(261), $this->_y(555));
630: 
631:         $this->_page->setFont($this->_fontNormal, 9);
632:         $routingText = '(' . $dataIdentifier . ')' . $licensePlate;
633:         $this->_page->drawText($routingText, $this->_x(144), $this->_y(563), '',
634:             Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_Page::ALIGN_CENTER
635:         );
636: 
637:         $this->_page->restoreGS();
638:         return $this;
639:     }
640: 
641:     /**
642:      * Add Piece Number
643:      *
644:      * @param int $pieceNumber
645:      * @param int $piecesTotal
646:      * @return Mage_Usa_Model_Shipping_Carrier_Dhl_Label_Pdf_PageBuilder
647:      * @throws InvalidArgumentException
648:      * @throws Zend_Pdf_Exception
649:      */
650:     public function addPieceNumber($pieceNumber, $piecesTotal)
651:     {
652:         $this->_page->saveGS();
653: 
654:         if (!$pieceNumber || !$piecesTotal) {
655:             throw new InvalidArgumentException(Mage::helper('usa')->__('Piece number information is missing'));
656:         }
657: 
658:         $this->_page->setFont($this->_fontNormal, 6);
659:         $this->_page->drawText('Piece:', $this->_x(256), $this->_y(224));
660:         $this->_page->setFont($this->_fontBold, 11);
661:         $this->_page->drawText($pieceNumber . '/' . $piecesTotal, $this->_x(256), $this->_y(234));
662: 
663:         $this->_page->restoreGS();
664:         return $this;
665:     }
666: }
667: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0