public function testProcessRelation()
 {
     $this->invoiceMock->expects($this->once())->method('getId')->willReturn('invoice-id-value');
     $this->invoiceMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->invoiceItemMock]);
     $this->invoiceItemMock->expects($this->once())->method('setParentId')->with('invoice-id-value')->willReturnSelf();
     $this->invoiceItemMock->expects($this->once())->method('getOrderItem')->willReturn($this->orderItemMock);
     $this->invoiceItemMock->expects($this->once())->method('setOrderItem')->with($this->orderItemMock)->willReturnSelf();
     $this->invoiceItemResourceMock->expects($this->once())->method('save')->with($this->invoiceItemMock)->willReturnSelf();
     $this->invoiceMock->expects($this->exactly(2))->method('getComments')->willReturn([$this->invoiceCommentMock]);
     $this->invoiceCommentResourceMock->expects($this->once())->method('save')->with($this->invoiceCommentMock)->willReturnSelf();
     $this->relationProcessor->processRelation($this->invoiceMock);
 }
Example #2
0
 public function testCalcRowTotal()
 {
     $this->item->setData(['order_item_id' => 1, 'qty' => 2]);
     $this->item->setInvoice($this->invoiceMock);
     $this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(0);
     $this->invoiceMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[2, 'regular', false, 2], [2, 'base', false, 2], [2, 'including', false, 2], [2, 'including_base', false, 2]]);
     $this->assertEquals($this->item->calcRowTotal(), $this->item);
 }
Example #3
0
 /**
  * @param \Magento\Sales\Model\Order\Invoice\Item $item
  * @return $this
  */
 public function addItem(\Magento\Sales\Model\Order\Invoice\Item $item)
 {
     $item->setInvoice($this)->setParentId($this->getId())->setStoreId($this->getStoreId());
     if (!$item->getId()) {
         $this->getItemsCollection()->addItem($item);
     }
     return $this;
 }
Example #4
0
 /**
  * Return the total amount minus discount
  *
  * @param OrderItem|InvoiceItem|CreditmemoItem $item
  * @return mixed
  */
 public function getBaseTotalAmount($item)
 {
     $totalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $item->getBaseTaxAmount() + $item->getBaseHiddenTaxAmount();
     return $totalAmount;
 }
Example #5
0
 /**
  * Return the total amount minus discount
  *
  * @param OrderItem|InvoiceItem|CreditmemoItem $item
  * @return mixed
  */
 public function getTotalAmount($item)
 {
     $totalAmount = $item->getRowTotal() + $item->getTaxAmount() + $item->getDiscountTaxCompensationAmount() + $item->getWeeeTaxAppliedRowAmount() - $item->getDiscountAmount();
     return $totalAmount;
 }
Example #6
0
 /**
  * Return the total amount minus discount
  *
  * @param OrderItem|InvoiceItem|CreditMemoItem $item
  * @return mixed
  */
 public function getBaseTotalAmount($item)
 {
     $totalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $item->getBaseTaxAmount() + $item->getBaseHiddenTaxAmount() + $this->weeeHelper->getBaseRowWeeeTaxInclTax($item);
     return $totalAmount;
 }
 /**
  * Calculate base total amount for the item
  *
  * @param QuoteItem|Item|InvoiceItem|CreditmemoItem $item
  * @return mixed
  */
 public function getBaseTotalAmount($item)
 {
     $baseTotalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
     return $baseTotalAmount;
 }
Example #8
0
 /**
  * Return the total amount minus discount
  *
  * @param OrderItem|InvoiceItem|CreditmemoItem $item
  * @return mixed
  */
 public function getBaseTotalAmount($item)
 {
     $totalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $item->getBaseTaxAmount() + $item->getBaseDiscountTaxCompensationAmount();
     return $totalAmount;
 }
Example #9
0
 /**
  * Set quantity to invoice item
  *
  * @param \Magento\Sales\Model\Order\Invoice\Item $item
  * @param float $qty
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function setInvoiceItemQuantity(\Magento\Sales\Model\Order\Invoice\Item $item, $qty)
 {
     $qty = $item->getOrderItem()->getIsQtyDecimal() ? (double) $qty : (int) $qty;
     $qty = $qty > 0 ? $qty : 0;
     /**
      * Check qty availability
      */
     $qtyToInvoice = sprintf("%F", $item->getOrderItem()->getQtyToInvoice());
     $qty = sprintf("%F", $qty);
     if ($qty > $qtyToInvoice && !$item->getOrderItem()->isDummy()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid quantity to invoice item "%1".', $item->getName()));
     }
     $item->setQty($qty);
     return $this;
 }