Exemplo n.º 1
0
 public function testDivide()
 {
     $one = Money::init(200, 'USD');
     $two = $one->divide(2);
     $this->assertEquals(100, $two->cents);
     $three = Money::init(1000, 'USD');
     $four = $three->divide(0.2);
     $this->assertEquals(5000, $four->cents);
 }
Exemplo n.º 2
0
 /**
  * Divide one Money object and return a new Money object
  *
  * @param int $number
  * @return PhilipBrown\Money\Money
  */
 public function divide($number)
 {
     return Money::init((int) round($this->cents / $number, 0, PHP_ROUND_HALF_EVEN), $this->currency->getIsoCode());
 }
Exemplo n.º 3
0
 /**
  * Set the freebie parameter
  *
  * @param boolean $value
  */
 protected function setFreebieParameter($value)
 {
     if (is_bool($value)) {
         $this->freebie = $value;
         $this->taxable = $this->freebie ? false : $this->taxable;
         $this->tax = $this->freebie ? Money::init(0, $this->currency) : $this->calculateTax();
         $this->discount = $this->freebie ? Money::init(0, $this->currency) : $this->discount;
         return $this->calculateTotal();
     }
     throw new InvalidProductException('The freebie property must be a boolean');
 }
Exemplo n.º 4
0
 /**
  * Reconcile the order if it is dirty
  *
  * @return void
  */
 public function reconcile()
 {
     if ($this->dirty) {
         $total_value = 0;
         $total_discount = 0;
         $total_tax = 0;
         $subtotal = 0;
         foreach ($this->products as $product) {
             $i = $product->quantity;
             while ($i > 0) {
                 $total_value = $total_value + $product->value->cents;
                 $total_discount = $total_discount + $product->discount->cents;
                 $total_tax = $total_tax + $product->tax->cents;
                 $subtotal = $subtotal + $product->total->cents;
                 $i--;
             }
         }
         $this->total_value = Money::init($total_value, $this->region->currency);
         $this->total_discount = Money::init($total_discount, $this->region->currency);
         $this->total_tax = Money::init($total_tax, $this->region->currency);
         $this->subtotal = Money::init($subtotal, $this->region->currency);
         $this->total = Money::init($subtotal - $this->total_discount->cents + $this->total_tax->cents, $this->region->currency);
         $this->dirty = false;
     }
 }