1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Sales_Model_Order_Pdf_Shipment_Packaging extends Mage_Sales_Model_Order_Pdf_Abstract
35: {
36: 37: 38: 39: 40: 41:
42: public function getPdf($shipment = null)
43: {
44: $this->_beforeGetPdf();
45: $this->_initRenderer('shipment');
46:
47: $pdf = new Zend_Pdf();
48: $this->_setPdf($pdf);
49: $page = $this->newPage();
50:
51: if ($shipment->getStoreId()) {
52: Mage::app()->getLocale()->emulate($shipment->getStoreId());
53: Mage::app()->setCurrentStore($shipment->getStoreId());
54: }
55:
56: $this->_setFontRegular($page);
57: $this->_drawHeaderBlock($page);
58:
59: $this->y = 740;
60: $this->_drawPackageBlock($page);
61: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
62: $this->_afterGetPdf();
63:
64: if ($shipment->getStoreId()) {
65: Mage::app()->getLocale()->revert();
66: }
67: return $pdf;
68: }
69:
70: 71: 72: 73: 74: 75:
76: protected function (Zend_Pdf_Page $page) {
77: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0.5));
78: $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5));
79: $page->setLineWidth(0.5);
80: $page->drawRectangle(25, 790, 570, 755);
81: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
82: $page->drawText(Mage::helper('sales')->__('Packages'), 35, 770, 'UTF-8');
83: $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
84:
85: return $this;
86: }
87:
88: 89: 90: 91: 92: 93:
94: protected function _drawPackageBlock(Zend_Pdf_Page $page)
95: {
96: if ($this->getPackageShippingBlock()) {
97: $packaging = $this->getPackageShippingBlock();
98: } else {
99: $packaging = Mage::getBlockSingleton('adminhtml/sales_order_shipment_packaging');
100: }
101: $packages = $packaging->getPackages();
102:
103: $packageNum = 1;
104: foreach ($packages as $packageId => $package) {
105: $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
106: $page->drawRectangle(25, $this->y + 15, 190, $this->y - 35);
107: $page->drawRectangle(190, $this->y + 15, 350, $this->y - 35);
108: $page->drawRectangle(350, $this->y + 15, 570, $this->y - 35);
109:
110: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
111: $page->drawRectangle(520, $this->y + 15, 570, $this->y - 5);
112:
113: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
114: $packageText = Mage::helper('sales')->__('Package') . ' ' . $packageNum;
115: $page->drawText($packageText, 525, $this->y , 'UTF-8');
116: $packageNum++;
117:
118: $package = new Varien_Object($package);
119: $params = new Varien_Object($package->getParams());
120: $dimensionUnits = Mage::helper('usa')->getMeasureDimensionName($params->getDimensionUnits());
121:
122: $typeText = Mage::helper('sales')->__('Type') . ' : '
123: . $packaging->getContainerTypeByCode($params->getContainer());
124: $page->drawText($typeText, 35, $this->y , 'UTF-8');
125:
126: if ($params->getLength() != null) {
127: $lengthText = $params->getLength() .' '. $dimensionUnits;
128: } else {
129: $lengthText = '--';
130: }
131: $lengthText = Mage::helper('sales')->__('Length') . ' : ' . $lengthText;
132: $page->drawText($lengthText, 200, $this->y , 'UTF-8');
133:
134: if ($params->getDeliveryConfirmation() != null) {
135: $confirmationText = Mage::helper('sales')->__('Signature Confirmation')
136: . ' : '
137: . $packaging->getDeliveryConfirmationTypeByCode($params->getDeliveryConfirmation());
138: $page->drawText($confirmationText, 355, $this->y , 'UTF-8');
139: }
140:
141: $this->y = $this->y - 10;
142:
143: if ($packaging->displayCustomsValue() != null) {
144: $customsValueText = Mage::helper('sales')->__('Customs Value')
145: . ' : '
146: . $packaging->displayPrice($params->getCustomsValue());
147: $page->drawText($customsValueText, 35, $this->y , 'UTF-8');
148: }
149: if ($params->getWidth() != null) {
150: $widthText = $params->getWidth() .' '. $dimensionUnits;
151: } else {
152: $widthText = '--';
153: }
154: $widthText = Mage::helper('sales')->__('Width') . ' : ' . $widthText;
155: $page->drawText($widthText, 200, $this->y , 'UTF-8');
156:
157: if ($params->getContentType() != null) {
158: if ($params->getContentType() == 'OTHER') {
159: $contentsValue = $params->getContentTypeOther();
160: } else {
161: $contentsValue = $packaging->getContentTypeByCode($params->getContentType());
162: }
163: $contentsText = Mage::helper('sales')->__('Contents')
164: . ' : '
165: . $contentsValue;
166: $page->drawText($contentsText, 355, $this->y , 'UTF-8');
167: }
168:
169: $this->y = $this->y - 10;
170:
171: $weightText = Mage::helper('sales')->__('Total Weight') . ' : ' . $params->getWeight() .' '
172: . Mage::helper('usa')->getMeasureWeightName($params->getWeightUnits());
173: $page->drawText($weightText, 35, $this->y , 'UTF-8');
174:
175: if ($params->getHeight() != null) {
176: $heightText = $params->getHeight() .' '. $dimensionUnits;
177: } else {
178: $heightText = '--';
179: }
180: $heightText = Mage::helper('sales')->__('Height') . ' : ' . $heightText;
181: $page->drawText($heightText, 200, $this->y , 'UTF-8');
182:
183: $this->y = $this->y - 10;
184:
185: if ($params->getSize()) {
186: $sizeText = Mage::helper('sales')->__('Size') . ' : ' . ucfirst(strtolower($params->getSize()));
187: $page->drawText($sizeText, 35, $this->y , 'UTF-8');
188: }
189: if ($params->getGirth() != null) {
190: $dimensionGirthUnits = Mage::helper('usa')->getMeasureDimensionName($params->getGirthDimensionUnits());
191: $girthText = Mage::helper('sales')->__('Girth')
192: . ' : ' . $params->getGirth() . ' ' . $dimensionGirthUnits;
193: $page->drawText($girthText, 200, $this->y , 'UTF-8');
194: }
195:
196: $this->y = $this->y - 5;
197: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
198: $page->drawRectangle(25, $this->y, 570, $this->y - 30 - (count($package->getItems()) * 12));
199:
200: $this->y = $this->y - 10;
201: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
202: $page->drawText(Mage::helper('sales')->__('Items in the Package'), 30, $this->y, 'UTF-8');
203:
204: $txtIndent = 5;
205: $itemCollsNumber = $packaging->displayCustomsValue() ? 5 : 4;
206: $itemCollsX[0] = 30;
207: $itemCollsX[1] = 250;
208: $itemCollsXEnd = 565;
209: $itemCollsXStep = round(($itemCollsXEnd - $itemCollsX[1]) / ($itemCollsNumber - 1));
210:
211: for ($i = 2; $i <= $itemCollsNumber; $i++) {
212: $itemCollsX[$i] = $itemCollsX[$i-1] + $itemCollsXStep;
213: }
214:
215: $i = 0;
216: $page->setFillColor(new Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
217: $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
218: $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
219: $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
220: $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsX[++$i], $this->y - 15);
221: $page->drawRectangle($itemCollsX[$i], $this->y - 5, $itemCollsXEnd, $this->y - 15);
222:
223: $this->y = $this->y - 12;
224: $i = 0;
225:
226: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
227: $page->drawText(Mage::helper('sales')->__('Product'), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8');
228: $page->drawText(Mage::helper('sales')->__('Weight'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
229: if ($packaging->displayCustomsValue()) {
230: $page->drawText(
231: Mage::helper('sales')->__('Customs Value'),
232: $itemCollsX[++$i] + $txtIndent,
233: $this->y,
234: 'UTF-8'
235: );
236: }
237: $page->drawText(
238: Mage::helper('sales')->__('Qty Ordered'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8'
239: );
240: $page->drawText(Mage::helper('sales')->__('Qty'), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
241:
242: $i = 0;
243: foreach ($package->getItems() as $itemId => $item) {
244: $item = new Varien_Object($item);
245: $i = 0;
246:
247: $page->setFillColor(new Zend_Pdf_Color_GrayScale(1));
248: $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
249: $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
250: $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
251: $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsX[++$i], $this->y - 15);
252: $page->drawRectangle($itemCollsX[$i], $this->y - 3, $itemCollsXEnd, $this->y - 15);
253:
254: $this->y = $this->y - 12;
255: $i = 0;
256: $page->setFillColor(new Zend_Pdf_Color_GrayScale(0));
257: $page->drawText($item->getName(), $itemCollsX[$i] + $txtIndent, $this->y, 'UTF-8');
258: $page->drawText($item->getWeight(), $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
259: if ($packaging->displayCustomsValue()) {
260: $page->drawText(
261: $packaging->displayPrice($item->getCustomsValue()),
262: $itemCollsX[++$i] + $txtIndent,
263: $this->y,
264: 'UTF-8'
265: );
266: }
267: $page->drawText(
268: $packaging->getQtyOrderedItem($item->getOrderItemId()),
269: $itemCollsX[++$i] + $txtIndent,
270: $this->y,
271: 'UTF-8'
272: );
273: $page->drawText($item->getQty()*1, $itemCollsX[++$i] + $txtIndent, $this->y, 'UTF-8');
274: }
275: $this->y = $this->y - 30;
276: }
277: return $this;
278: }
279: }
280: