Esempio n. 1
0
 public function convert(Money $money, $target)
 {
     if (!$target instanceof MoneyCurrency) {
         throw new InvalidArgumentException(sprintf('Second argument must be Currency, %s given.', gettype($target)));
     }
     $rate = $this->swap->quote(new CurrencyPair($money->getCurrency(), $target));
     return new Money($money->multiply((double) $rate->getValue())->getAmount(), $target);
 }
Esempio n. 2
0
 /**
  * @param Quote|Invoice $object
  * @param Money         $total
  *
  * @return mixed
  */
 private function setDiscount($object, Money $total)
 {
     if (null !== $object->getDiscount()) {
         $discount = $total->multiply($object->getDiscount());
         $total = $total->subtract($discount);
         return $total;
     }
     return $total;
 }
Esempio n. 3
0
 function it_converts_money_using_swap(SwapInterface $swap, Money $money, Money $converted, Currency $from, Currency $to)
 {
     $money->getAmount()->willReturn(100);
     $money->getCurrency()->willReturn($from);
     $money->multiply(120.3971)->willReturn($converted);
     $converted->getAmount()->willReturn(12039);
     $converted->getCurrency()->willReturn($to);
     $from->__toString()->willReturn('EUR');
     $to->__toString()->willReturn('RSD');
     $rate = new Rate(120.3971);
     $swap->quote('EUR/RSD')->shouldBeCalled()->willReturn($rate);
     $this->convert($money, $to)->getAmount()->shouldBe(12039);
 }
Esempio n. 4
0
 public function testMultiplication()
 {
     $m = new Money(1, new Currency('EUR'));
     $this->assertEquals(new Money(2, new Currency('EUR')), $m->multiply(1.5));
     $this->assertEquals(new Money(1, new Currency('EUR')), $m->multiply(1.5, Money::ROUND_HALF_DOWN));
     $this->assertNotSame($m, $m->multiply(2));
 }
Esempio n. 5
0
 /**
  * PrePersist listener to update the line total.
  *
  * @ORM\PrePersist
  */
 public function updateTotal()
 {
     $this->total = $this->price->multiply($this->qty);
 }
Esempio n. 6
0
 /**
  * @return Money
  */
 public function negative() : Money
 {
     return new self($this->money->multiply(-1));
 }