예제 #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);
 }
예제 #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;
 }
예제 #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);
 }
예제 #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));
 }
예제 #5
0
파일: Item.php 프로젝트: Codixis/CSBill
 /**
  * PrePersist listener to update the line total.
  *
  * @ORM\PrePersist
  */
 public function updateTotal()
 {
     $this->total = $this->price->multiply($this->qty);
 }
예제 #6
0
 /**
  * @return Money
  */
 public function negative() : Money
 {
     return new self($this->money->multiply(-1));
 }