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: class Mage_Tax_Block_Sales_Order_Tax extends Mage_Core_Block_Template
31: {
32: 33: 34: 35: 36:
37: protected $_config;
38: protected $_order;
39: protected $_source;
40:
41: 42: 43:
44: protected function _construct()
45: {
46: $this->_config = Mage::getSingleton('tax/config');
47: }
48:
49: 50: 51: 52: 53:
54: public function displayFullSummary()
55: {
56: return $this->_config->displaySalesFullSummary($this->getOrder()->getStore());
57: }
58:
59: 60: 61: 62: 63:
64: public function getSource()
65: {
66: return $this->_source;
67: }
68:
69: 70: 71: 72: 73:
74: public function initTotals()
75: {
76:
77: $parent = $this->getParentBlock();
78: $this->_order = $parent->getOrder();
79: $this->_source = $parent->getSource();
80:
81: $store = $this->getStore();
82: $allowTax = ($this->_source->getTaxAmount() > 0) || ($this->_config->displaySalesZeroTax($store));
83: $grandTotal = (float) $this->_source->getGrandTotal();
84: if (!$grandTotal || ($allowTax && !$this->_config->displaySalesTaxWithGrandTotal($store))) {
85: $this->_addTax();
86: }
87:
88: $this->_initSubtotal();
89: $this->_initShipping();
90: $this->_initDiscount();
91: $this->_initGrandTotal();
92: return $this;
93: }
94:
95: 96: 97: 98: 99: 100:
101: protected function _addTax($after='discount')
102: {
103: $taxTotal = new Varien_Object(array(
104: 'code' => 'tax',
105: 'block_name'=> $this->getNameInLayout()
106: ));
107: $this->getParentBlock()->addTotal($taxTotal, $after);
108: return $this;
109: }
110:
111: 112: 113: 114: 115:
116: public function getStore()
117: {
118: return $this->_order->getStore();
119: }
120:
121: protected function _initSubtotal()
122: {
123: $store = $this->getStore();
124: $parent = $this->getParentBlock();
125: $subtotal = $parent->getTotal('subtotal');
126: if (!$subtotal) {
127: return $this;
128: }
129: if ($this->_config->displaySalesSubtotalBoth($store)) {
130: $subtotal = (float) $this->_source->getSubtotal();
131: $baseSubtotal = (float) $this->_source->getBaseSubtotal();
132: $subtotalIncl = (float) $this->_source->getSubtotalInclTax();
133: $baseSubtotalIncl= (float) $this->_source->getBaseSubtotalInclTax();
134:
135: if (!$subtotalIncl) {
136: $subtotalIncl = $subtotal+ $this->_source->getTaxAmount()
137: - $this->_source->getShippingTaxAmount();
138: }
139: if (!$baseSubtotalIncl) {
140: $baseSubtotalIncl = $baseSubtotal + $this->_source->getBaseTaxAmount()
141: - $this->_source->getBaseShippingTaxAmount();
142: }
143: $subtotalIncl = max(0, $subtotalIncl);
144: $baseSubtotalIncl = max(0, $baseSubtotalIncl);
145: $totalExcl = new Varien_Object(array(
146: 'code' => 'subtotal_excl',
147: 'value' => $subtotal,
148: 'base_value'=> $baseSubtotal,
149: 'label' => $this->__('Subtotal (Excl.Tax)')
150: ));
151: $totalIncl = new Varien_Object(array(
152: 'code' => 'subtotal_incl',
153: 'value' => $subtotalIncl,
154: 'base_value'=> $baseSubtotalIncl,
155: 'label' => $this->__('Subtotal (Incl.Tax)')
156: ));
157: $parent->addTotal($totalExcl, 'subtotal');
158: $parent->addTotal($totalIncl, 'subtotal_excl');
159: $parent->removeTotal('subtotal');
160: } elseif ($this->_config->displaySalesSubtotalInclTax($store)) {
161: $subtotalIncl = (float) $this->_source->getSubtotalInclTax();
162: $baseSubtotalIncl= (float) $this->_source->getBaseSubtotalInclTax();
163:
164: if (!$subtotalIncl) {
165: $subtotalIncl = $this->_source->getSubtotal()
166: + $this->_source->getTaxAmount()
167: - $this->_source->getShippingTaxAmount();
168: }
169: if (!$baseSubtotalIncl) {
170: $baseSubtotalIncl = $this->_source->getBaseSubtotal()
171: + $this->_source->getBaseTaxAmount()
172: - $this->_source->getBaseShippingTaxAmount();
173: }
174:
175: $total = $parent->getTotal('subtotal');
176: if ($total) {
177: $total->setValue(max(0, $subtotalIncl));
178: $total->setBaseValue(max(0, $baseSubtotalIncl));
179: }
180: }
181: return $this;
182: }
183:
184: protected function _initShipping()
185: {
186: $store = $this->getStore();
187: $parent = $this->getParentBlock();
188: $shipping = $parent->getTotal('shipping');
189: if (!$shipping) {
190: return $this;
191: }
192:
193: if ($this->_config->displaySalesShippingBoth($store)) {
194: $shipping = (float) $this->_source->getShippingAmount();
195: $baseShipping = (float) $this->_source->getBaseShippingAmount();
196: $shippingIncl = (float) $this->_source->getShippingInclTax();
197: if (!$shippingIncl) {
198: $shippingIncl = $shipping + (float) $this->_source->getShippingTaxAmount();
199: }
200: $baseShippingIncl = (float) $this->_source->getBaseShippingInclTax();
201: if (!$baseShippingIncl) {
202: $baseShippingIncl = $baseShipping + (float) $this->_source->getBaseShippingTaxAmount();
203: }
204:
205: $totalExcl = new Varien_Object(array(
206: 'code' => 'shipping',
207: 'value' => $shipping,
208: 'base_value'=> $baseShipping,
209: 'label' => $this->__('Shipping & Handling (Excl.Tax)')
210: ));
211: $totalIncl = new Varien_Object(array(
212: 'code' => 'shipping_incl',
213: 'value' => $shippingIncl,
214: 'base_value'=> $baseShippingIncl,
215: 'label' => $this->__('Shipping & Handling (Incl.Tax)')
216: ));
217: $parent->addTotal($totalExcl, 'shipping');
218: $parent->addTotal($totalIncl, 'shipping');
219: } elseif ($this->_config->displaySalesShippingInclTax($store)) {
220: $shippingIncl = $this->_source->getShippingInclTax();
221: if (!$shippingIncl) {
222: $shippingIncl = $this->_source->getShippingAmount()
223: + $this->_source->getShippingTaxAmount();
224: }
225: $baseShippingIncl = $this->_source->getBaseShippingInclTax();
226: if (!$baseShippingIncl) {
227: $baseShippingIncl = $this->_source->getBaseShippingAmount()
228: + $this->_source->getBaseShippingTaxAmount();
229: }
230: $total = $parent->getTotal('shipping');
231: if ($total) {
232: $total->setValue($shippingIncl);
233: $total->setBaseValue($baseShippingIncl);
234: }
235: }
236: return $this;
237: }
238:
239: protected function _initDiscount()
240: {
241:
242:
243:
244:
245:
246:
247:
248: }
249:
250: protected function _initGrandTotal()
251: {
252: $store = $this->getStore();
253: $parent = $this->getParentBlock();
254: $grandototal = $parent->getTotal('grand_total');
255: if (!$grandototal || !(float)$this->_source->getGrandTotal()) {
256: return $this;
257: }
258:
259: if ($this->_config->displaySalesTaxWithGrandTotal($store)) {
260: $grandtotal = $this->_source->getGrandTotal();
261: $baseGrandtotal = $this->_source->getBaseGrandTotal();
262: $grandtotalExcl = $grandtotal - $this->_source->getTaxAmount();
263: $baseGrandtotalExcl = $baseGrandtotal - $this->_source->getBaseTaxAmount();
264: $grandtotalExcl = max($grandtotalExcl, 0);
265: $baseGrandtotalExcl = max($baseGrandtotalExcl, 0);
266: $totalExcl = new Varien_Object(array(
267: 'code' => 'grand_total',
268: 'strong' => true,
269: 'value' => $grandtotalExcl,
270: 'base_value'=> $baseGrandtotalExcl,
271: 'label' => $this->__('Grand Total (Excl.Tax)')
272: ));
273: $totalIncl = new Varien_Object(array(
274: 'code' => 'grand_total_incl',
275: 'strong' => true,
276: 'value' => $grandtotal,
277: 'base_value'=> $baseGrandtotal,
278: 'label' => $this->__('Grand Total (Incl.Tax)')
279: ));
280: $parent->addTotal($totalExcl, 'grand_total');
281: $this->_addTax('grand_total');
282: $parent->addTotal($totalIncl, 'tax');
283: }
284: return $this;
285: }
286:
287: public function getOrder()
288: {
289: return $this->_order;
290: }
291:
292: public function getLabelProperties()
293: {
294: return $this->getParentBlock()->getLabelProperties();
295: }
296:
297: public function getValueProperties()
298: {
299: return $this->getParentBlock()->getValueProperties();
300: }
301: }
302: