/** * Get full information about taxes applied to order * * @return array */ public function getFullTaxInfo() { /** @var $source \Magento\Sales\Model\Order */ $source = $this->getOrder(); $taxClassAmount = array(); if ($source instanceof \Magento\Sales\Model\Order) { $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($source); if (empty($taxClassAmount)) { $rates = $this->_taxOrderFactory->create()->getCollection()->loadByOrder($source)->toArray(); $taxClassAmount = $this->_taxCalculation->reproduceProcess($rates['items']); } } return $taxClassAmount; }
/** * Get array of arrays with tax information for display in PDF * array( * $index => array( * 'amount' => $amount, * 'label' => $label, * 'font_size'=> $font_size * ) * ) * * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ public function getFullTaxInfo() { $fontSize = $this->getFontSize() ? $this->getFontSize() : 7; $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($this->getOrder()); if (!empty($taxClassAmount)) { foreach ($taxClassAmount as &$tax) { $percent = $tax['percent'] ? ' (' . $tax['percent'] . '%)' : ''; $tax['amount'] = $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($tax['tax_amount']); $tax['label'] = __($tax['title']) . $percent . ':'; $tax['font_size'] = $fontSize; } } else { /** @var $orders \Magento\Tax\Model\Resource\Sales\Order\Tax\Collection */ $orders = $this->_taxOrdersFactory->create(); $rates = $orders->loadByOrder($this->getOrder())->toArray(); $fullInfo = $this->_taxCalculation->reproduceProcess($rates['items']); $tax_info = []; if ($fullInfo) { foreach ($fullInfo as $info) { if (isset($info['hidden']) && $info['hidden']) { continue; } $_amount = $info['amount']; foreach ($info['rates'] as $rate) { $percent = $rate['percent'] ? ' (' . $rate['percent'] . '%)' : ''; $tax_info[] = ['amount' => $this->getAmountPrefix() . $this->getOrder()->formatPriceTxt($_amount), 'label' => __($rate['title']) . $percent . ':', 'font_size' => $fontSize]; } } } $taxClassAmount = $tax_info; } return $taxClassAmount; }
/** * @dataProvider getCalculatedTaxesForOrderItemsDataProvider */ public function testGetCalculatedTaxesForOrderItems($orderData, $invoiceData, $expectedResults) { $orderId = $orderData['order_id']; $orderShippingTaxAmount = isset($orderData['shipping_tax_amount']) ? $orderData['shipping_tax_amount'] : 0; $orderTaxDetails = $orderData['order_tax_details']; /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Sales\Model\Order $orderMock */ $orderMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock(); $orderMock->expects($this->once())->method('getId')->willReturn($orderId); $orderMock->expects($this->once())->method('getShippingTaxAmount')->willReturn($orderShippingTaxAmount); $orderTaxDetailsMock = $this->mapOrderTaxItemDetail($orderTaxDetails); $this->orderTaxManagementMock->expects($this->any())->method('getOrderTaxDetails')->with($orderId)->will($this->returnValue($orderTaxDetailsMock)); $invoiceShippingTaxAmount = isset($invoiceData['shipping_tax_amount']) ? $invoiceData['shipping_tax_amount'] : 0; $invoiceItems = $invoiceData['invoice_items']; /** @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Sales\Model\Order\Invoice $source */ $source = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Invoice')->disableOriginalConstructor()->getMock(); $source->expects($this->once())->method('getOrder')->willReturn($orderMock); $source->expects($this->once())->method('getShippingTaxAmount')->willReturn($invoiceShippingTaxAmount); $source->expects($this->once())->method('getItems')->willReturn($invoiceItems); $this->priceCurrencyMock->expects($this->any())->method('round')->will($this->returnCallback(function ($arg) { return round($arg, 2); })); $result = $this->helper->getCalculatedTaxes($source); foreach ($result as $index => $appliedTax) { $expectedTax = $expectedResults[$index]; foreach ($appliedTax as $attr => $value) { $this->assertEquals($expectedTax[$attr], $value, "The " . $attr . " of tax does not match"); } } }
/** * Get full information about taxes applied to order * * @return array */ public function getFullTaxInfo() { $source = $this->getSource(); if (!$source instanceof \Magento\Sales\Model\Order\Invoice && !$source instanceof \Magento\Sales\Model\Order\Creditmemo) { $source = $this->getOrder(); } $taxClassAmount = []; if (empty($source)) { return $taxClassAmount; } $taxClassAmount = $this->_taxHelper->getCalculatedTaxes($source); if (empty($taxClassAmount)) { $rates = $this->_taxOrderFactory->create()->getCollection()->loadByOrder($source)->toArray(); $taxClassAmount = $this->_taxCalculation->reproduceProcess($rates['items']); } return $taxClassAmount; }
protected function commonTestGetCalculatedTaxesInvoiceCreditmemo($source, $orderTaxDetails, $expectedResults) { $this->orderTaxService->expects($this->once())->method('getOrderTaxDetails')->with($source->getId())->will($this->returnValue($orderTaxDetails)); $orderTaxDetails = $this->taxHelper->getCalculatedTaxes($source); $this->assertEquals($expectedResults, $orderTaxDetails); }