Skip to content

Commit

Permalink
added rounding before api-call
Browse files Browse the repository at this point in the history
  • Loading branch information
iesus committed Aug 29, 2019
1 parent bd065a2 commit 300a7c1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions app/code/community/Svea/Checkout/Block/Adminhtml/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ protected function _processItem($item, $prefix = '')
'ArticleNumber' => $prefix . $item->getSku(),
'Name' => (string)mb_substr($item->getName(), 0, 40),
'Quantity' => (float)round($item->getQty(), 2),
'UnitPrice' => (float)$item->getPriceInclTax(),
'UnitPrice' => (float)round($item->getPriceInclTax(), 2),
'VatPercent' => (int)round($item->getTaxPercent()),
'DiscountPercent' => (int)0,
'Unit' => (null),
Expand All @@ -293,7 +293,7 @@ protected function _processItem($item, $prefix = '')
'ArticleNumber' => (sprintf('discount-%s', $prefix . $item->getId())),
'Name' => (string)mb_substr($item->getName(), 0, 40),
'Quantity' => 1,
'UnitPrice' => $item->getDiscountAmount() * -1,
'UnitPrice' => round($item->getDiscountAmount() * -1,2),
'VatPercent' => (int)round($item->getTaxPercent()),
'DiscountPercent' => (int)0,
'Unit' => (null),
Expand Down Expand Up @@ -388,7 +388,7 @@ protected function _addShipping($quote)
'ArticleNumber' => '',
'Name' => (string)$shippingTitle,
'Quantity' => 1,
'UnitPrice' => (float)$shipping->getShippingInclTax(),
'UnitPrice' => (float)round($shipping->getShippingInclTax(), 2),
'VatPercent' => $vatPercent,
'DiscountPercent' => '',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ protected function _processItem($item, $prefix = '', $multiply = 1)

$qty = $item->getQty() * $multiply;
$orderRowItem = WebPayItem::orderRow()
->setAmountIncVat((float)$item->getPriceInclTax())
->setAmountIncVat((float)round($item->getPriceInclTax(),2))
->setVatPercent((int)round($item->getTaxPercent()))
->setQuantity((float)round($qty, 2))
->setArticleNumber($prefix . $item->getSku())
Expand All @@ -362,7 +362,7 @@ protected function _processItem($item, $prefix = '', $multiply = 1)
$itemRowDiscount = WebPayItem::fixedDiscount()
->setName(mb_substr(sprintf('discount-%s', $prefix . $item->getId()), 0, 40))
->setVatPercent((int)round($item->getTaxPercent()))
->setAmountIncVat((float)$item->getDiscountAmount());
->setAmountIncVat((float)round($item->getDiscountAmount(),2));

$sveaOrder->addDiscount($itemRowDiscount);
}
Expand Down Expand Up @@ -482,7 +482,7 @@ protected function _addShipping($quote, $sveaOrder, $noSave)
$shippingFee = WebPayItem::shippingFee()
->setName((string)$shippingTitle)
->setVatPercent((int)$vatPercent)
->setAmountIncVat((float)$shippingPrice);
->setAmountIncVat((float)round($shippingPrice,2));

$sveaOrder->addFee($shippingFee);

Expand Down
16 changes: 8 additions & 8 deletions app/code/community/Svea/Checkout/Model/Payment/Api/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,14 @@ protected function _adjustQty(
$partialActionRow = WebPayItem::numberedOrderRow()
->setRowNumber($key)
->setArticleNumber($referenceNumber . '-' . $item['Name'])
->setAmountIncVat((float)$item['newDiscount']*-1)
->setAmountIncVat((float)round($item['newDiscount']*-1, 2))
->setVatPercent((int)$item['VatPercent'])
->setQuantity($item['Quantity']);

$restOfRowQty = WebPayItem::orderRow()
->setArticleNumber($item['ArticleNumber'])
->setName($item['Name'])
->setAmountIncVat((float)$rest)
->setAmountIncVat((float)round($rest, 2))
->setVatPercent((int)$item['VatPercent'])
->setQuantity((int)$item['Quantity']);

Expand Down Expand Up @@ -215,14 +215,14 @@ protected function _adjustQty(
$partialActionRow = WebPayItem::numberedOrderRow()
->setRowNumber($key)
->setArticleNumber($referenceNumber .'-'. $item['ArticleNumber'])
->setAmountIncVat((float) $item['UnitPrice'])
->setAmountIncVat((float)round($item['UnitPrice'], 2))
->setVatPercent((int) $item['VatPercent'])
->setQuantity($adjustQty);

$restOfRowQty = WebPayItem::orderRow()
->setArticleNumber($item['ArticleNumber'])
->setName($item['Name'])
->setAmountIncVat((float)$item['UnitPrice'])
->setAmountIncVat((float)round($item['UnitPrice'],2))
->setVatPercent((int)$item['VatPercent'])
->setQuantity((int)$rest);

Expand Down Expand Up @@ -299,7 +299,7 @@ public function refund($creditMemo)
WebPayAdmin::creditAmount($sveaConfig)
->setCheckoutOrderId($sveaOrderId)
->setDeliveryId($deliveryKey)
->setAmountIncVat((float)$refundAmount)
->setAmountIncVat((float)round($refundAmount,2))
->creditCheckoutAmount()
->doRequest();
$sveaOrder = $this->_getCheckoutOrder($order);
Expand All @@ -318,7 +318,7 @@ public function refund($creditMemo)
WebPayAdmin::creditAmount($sveaConfig)
->setCheckoutOrderId($sveaOrderId)
->setDeliveryId($deliveryKey)
->setAmountIncVat((float)$refundAmount)
->setAmountIncVat((float)round($refundAmount,2))
->creditCheckoutAmount()
->doRequest();

Expand Down Expand Up @@ -585,15 +585,15 @@ protected function _getActionRows(
$chosenItems[$key] = $row;
$qty = $items[$itemKey]['qty'];
$chosenItems[$key]['action_qty'] = (float)$qty;
$chosenItems[$key]['newDiscount'] = (float)$items[$itemKey]['newDiscount'];
$chosenItems[$key]['newDiscount'] = (float)round($items[$itemKey]['newDiscount'],2);
}
} else {
$itemKey = array_search($row['Name'], array_column($items, 'sku'));
if (in_array($row['Name'], array_column($items, 'sku'))) {
$chosenItems[$key] = $row;
$qty = $items[$itemKey]['qty'];
$chosenItems[$key]['action_qty'] = (float)$qty;
$chosenItems[$key]['newDiscount'] = (float)$items[$itemKey]['newDiscount'];
$chosenItems[$key]['newDiscount'] = (float)round($items[$itemKey]['newDiscount'],2);
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/code/community/Svea/Checkout/Model/Payment/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ protected function _processItem($item, $prefix = '')
}

$orderRowItem = WebPayItem::orderRow()
->setAmountIncVat((float)$item->getPriceInclTax())
->setAmountIncVat((float)round($item->getPriceInclTax()),2)
->setVatPercent((int)round($item->getTaxPercent()))
->setQuantity((float)round($item->getQty(), 2))
->setArticleNumber($prefix . $item->getSku())
Expand All @@ -280,7 +280,7 @@ protected function _processItem($item, $prefix = '')
$itemRowDiscount = WebPayItem::fixedDiscount()
->setName(mb_substr(sprintf('discount-%s', $prefix . $item->getId()), 0, 40))
->setVatPercent((int)round($item->getTaxPercent()))
->setAmountExVat((float)$item->getDiscountAmount());
->setAmountExVat((float)round($item->getDiscountAmount(),2));

$sveaOrder->addDiscount($itemRowDiscount);
}
Expand Down

0 comments on commit 300a7c1

Please sign in to comment.