/app/code/core/Mage/Bundle/Model/Sales/Order/Pdf/Items/Creditmemo.php

https://bitbucket.org/kdms/sh-magento · PHP · 224 lines · 154 code · 25 blank · 45 comment · 13 complexity · 57011e679b42a1b5e61a072005eb426d MD5 · raw file

  1. <?php
  2. /**
  3. * Magento Enterprise Edition
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Magento Enterprise Edition License
  8. * that is bundled with this package in the file LICENSE_EE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.magentocommerce.com/license/enterprise-edition
  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_Bundle
  23. * @copyright Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://www.magentocommerce.com/license/enterprise-edition
  25. */
  26. /**
  27. * Sales Order Creditmemo Pdf default items renderer
  28. *
  29. * @category Mage
  30. * @package Mage_Sales
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Bundle_Model_Sales_Order_Pdf_Items_Creditmemo extends Mage_Bundle_Model_Sales_Order_Pdf_Items_Abstract
  34. {
  35. /**
  36. * Draw item line
  37. *
  38. */
  39. public function draw()
  40. {
  41. $order = $this->getOrder();
  42. $item = $this->getItem();
  43. $pdf = $this->getPdf();
  44. $page = $this->getPage();
  45. $items = $this->getChilds($item);
  46. $_prevOptionId = '';
  47. $drawItems = array();
  48. $leftBound = 35;
  49. $rightBound = 565;
  50. foreach ($items as $_item) {
  51. $x = $leftBound;
  52. $line = array();
  53. $attributes = $this->getSelectionAttributes($_item);
  54. if (is_array($attributes)) {
  55. $optionId = $attributes['option_id'];
  56. }
  57. else {
  58. $optionId = 0;
  59. }
  60. if (!isset($drawItems[$optionId])) {
  61. $drawItems[$optionId] = array(
  62. 'lines' => array(),
  63. 'height' => 15
  64. );
  65. }
  66. // draw selection attributes
  67. if ($_item->getOrderItem()->getParentItem()) {
  68. if ($_prevOptionId != $attributes['option_id']) {
  69. $line[0] = array(
  70. 'font' => 'italic',
  71. 'text' => Mage::helper('core/string')->str_split($attributes['option_label'], 38, true, true),
  72. 'feed' => $x
  73. );
  74. $drawItems[$optionId] = array(
  75. 'lines' => array($line),
  76. 'height' => 15
  77. );
  78. $line = array();
  79. $_prevOptionId = $attributes['option_id'];
  80. }
  81. }
  82. // draw product titles
  83. if ($_item->getOrderItem()->getParentItem()) {
  84. $feed = $x + 5;
  85. $name = $this->getValueHtml($_item);
  86. } else {
  87. $feed = $x;
  88. $name = $_item->getName();
  89. }
  90. $line[] = array(
  91. 'text' => Mage::helper('core/string')->str_split($name, 35, true, true),
  92. 'feed' => $feed
  93. );
  94. $x += 220;
  95. // draw SKUs
  96. if (!$_item->getOrderItem()->getParentItem()) {
  97. $text = array();
  98. foreach (Mage::helper('core/string')->str_split($item->getSku(), 17) as $part) {
  99. $text[] = $part;
  100. }
  101. $line[] = array(
  102. 'text' => $text,
  103. 'feed' => $x
  104. );
  105. }
  106. $x += 100;
  107. // draw prices
  108. if ($this->canShowPriceInfo($_item)) {
  109. // draw Total(ex)
  110. $text = $order->formatPriceTxt($_item->getRowTotal());
  111. $line[] = array(
  112. 'text' => $text,
  113. 'feed' => $x,
  114. 'font' => 'bold',
  115. 'align' => 'right',
  116. 'width' => 50
  117. );
  118. $x += 50;
  119. // draw Discount
  120. $text = $order->formatPriceTxt(-$_item->getDiscountAmount());
  121. $line[] = array(
  122. 'text' => $text,
  123. 'feed' => $x,
  124. 'font' => 'bold',
  125. 'align' => 'right',
  126. 'width' => 50
  127. );
  128. $x += 50;
  129. // draw QTY
  130. $text = $_item->getQty() * 1;
  131. $line[] = array(
  132. 'text' => $_item->getQty()*1,
  133. 'feed' => $x,
  134. 'font' => 'bold',
  135. 'align' => 'center',
  136. 'width' => 30
  137. );
  138. $x += 30;
  139. // draw Tax
  140. $text = $order->formatPriceTxt($_item->getTaxAmount());
  141. $line[] = array(
  142. 'text' => $text,
  143. 'feed' => $x,
  144. 'font' => 'bold',
  145. 'align' => 'right',
  146. 'width' => 45
  147. );
  148. $x += 45;
  149. // draw Total(inc)
  150. $text = $order->formatPriceTxt(
  151. $_item->getRowTotal() + $_item->getTaxAmount() - $_item->getDiscountAmount()
  152. );
  153. $line[] = array(
  154. 'text' => $text,
  155. 'feed' => $rightBound,
  156. 'font' => 'bold',
  157. 'align' => 'right',
  158. );
  159. }
  160. $drawItems[$optionId]['lines'][] = $line;
  161. }
  162. // custom options
  163. $options = $item->getOrderItem()->getProductOptions();
  164. if ($options) {
  165. if (isset($options['options'])) {
  166. foreach ($options['options'] as $option) {
  167. $lines = array();
  168. $lines[][] = array(
  169. 'text' => Mage::helper('core/string')->str_split(strip_tags($option['label']), 40, true, true),
  170. 'font' => 'italic',
  171. 'feed' => $leftBound
  172. );
  173. if ($option['value']) {
  174. $text = array();
  175. $_printValue = isset($option['print_value'])
  176. ? $option['print_value']
  177. : strip_tags($option['value']);
  178. $values = explode(', ', $_printValue);
  179. foreach ($values as $value) {
  180. foreach (Mage::helper('core/string')->str_split($value, 30, true, true) as $_value) {
  181. $text[] = $_value;
  182. }
  183. }
  184. $lines[][] = array(
  185. 'text' => $text,
  186. 'feed' => $leftBound + 5
  187. );
  188. }
  189. $drawItems[] = array(
  190. 'lines' => $lines,
  191. 'height' => 15
  192. );
  193. }
  194. }
  195. }
  196. $page = $pdf->drawLineBlocks($page, $drawItems, array('table_header' => true));
  197. $this->setPage($page);
  198. }
  199. }