Пример #1
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;
 }