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_Sales
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: * Sales Order Total PDF model
29: *
30: * @category Mage
31: * @package Mage_Sales
32: * @author Magento Core Team <core@magentocommerce.com>
33: */
34: class Mage_Sales_Model_Order_Pdf_Total_Default extends Varien_Object
35: {
36: /**
37: * Get array of arrays with totals information for display in PDF
38: * array(
39: * $index => array(
40: * 'amount' => $amount,
41: * 'label' => $label,
42: * 'font_size'=> $font_size
43: * )
44: * )
45: * @return array
46: */
47: public function getTotalsForDisplay()
48: {
49: $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
50: if ($this->getAmountPrefix()) {
51: $amount = $this->getAmountPrefix().$amount;
52: }
53: $label = Mage::helper('sales')->__($this->getTitle()) . ':';
54: $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
55: $total = array(
56: 'amount' => $amount,
57: 'label' => $label,
58: 'font_size' => $fontSize
59: );
60: return array($total);
61: }
62:
63: /**
64: * Get array of arrays with tax information for display in PDF
65: * array(
66: * $index => array(
67: * 'amount' => $amount,
68: * 'label' => $label,
69: * 'font_size'=> $font_size
70: * )
71: * )
72: * @return array
73: */
74: public function getFullTaxInfo()
75: {
76: $taxClassAmount = Mage::helper('tax')->getCalculatedTaxes($this->getOrder());
77: $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
78:
79: if (!empty($taxClassAmount)) {
80: $shippingTax = Mage::helper('tax')->getShippingTax($this->getOrder());
81: $taxClassAmount = array_merge($shippingTax, $taxClassAmount);
82:
83: foreach ($taxClassAmount as &$tax) {
84: $percent = $tax['percent'] ? ' (' . $tax['percent']. '%)' : '';
85: $tax['amount'] = $this->getAmountPrefix().$this->getOrder()->formatPriceTxt($tax['tax_amount']);
86: $tax['label'] = Mage::helper('tax')->__($tax['title']) . $percent . ':';
87: $tax['font_size'] = $fontSize;
88: }
89: } else {
90: $rates = Mage::getResourceModel('sales/order_tax_collection')->loadByOrder($this->getOrder())->toArray();
91: $fullInfo = Mage::getSingleton('tax/calculation')->reproduceProcess($rates['items']);
92: $tax_info = array();
93:
94: if ($fullInfo) {
95: foreach ($fullInfo as $info) {
96: if (isset($info['hidden']) && $info['hidden']) {
97: continue;
98: }
99:
100: $_amount = $info['amount'];
101:
102: foreach ($info['rates'] as $rate) {
103: $percent = $rate['percent'] ? ' (' . $rate['percent']. '%)' : '';
104:
105: $tax_info[] = array(
106: 'amount' => $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($_amount),
107: 'label' => Mage::helper('tax')->__($rate['title']) . $percent . ':',
108: 'font_size' => $fontSize
109: );
110: }
111: }
112: }
113: $taxClassAmount = $tax_info;
114: }
115:
116: return $taxClassAmount;
117: }
118:
119: /**
120: * Check if we can display total information in PDF
121: *
122: * @return bool
123: */
124: public function canDisplay()
125: {
126: $amount = $this->getAmount();
127: return $this->getDisplayZero() || ($amount != 0);
128: }
129:
130: /**
131: * Get Total amount from source
132: *
133: * @return float
134: */
135: public function getAmount()
136: {
137: return $this->getSource()->getDataUsingMethod($this->getSourceField());
138: }
139: }
140: