Пример #1
0
 /**
  * Calculates the totals for this line item, including taxes.
  * @return void
  */
 public function calculateTotals()
 {
     $discountAmount = $this->price * $this->discount;
     $this->subtotal = ($this->price - $discountAmount) * $this->quantity;
     if ($this->invoice && !$this->is_tax_exempt) {
         $this->tax = Tax::getTotalTax($this->tax_class_id, $this->subtotal, $this->invoice->getLocationInfo());
     }
     $this->total = $this->subtotal + $this->tax;
 }
Пример #2
0
 /**
  * Calculate totals from invoice items
  * @param  Model $items
  * @return float
  */
 public function calculateTotals($items = null)
 {
     if (!$items) {
         $items = $this->items;
     }
     /*
      * Discount and subtotal
      */
     $discount = 0;
     $subtotal = 0;
     foreach ($items as $item) {
         $subtotal += $item->subtotal;
         $discount += $item->discount;
     }
     /*
      * Calculate tax
      */
     $taxInfo = Tax::calculateTaxes($items, $this->getLocationInfo());
     $this->setSalesTaxes($taxInfo->taxes);
     $tax = $taxInfo->tax_total;
     /*
      * Grand total
      */
     $this->discount = $discount;
     $this->subtotal = $subtotal;
     $this->tax = $tax;
     $this->total = $subtotal - $discount + $tax;
     return $this->total;
 }