public function getTerms($recurring = false, $user_subscription = false, $metaUser = false)
 {
     $plans_comparison = false;
     $plans_comparison_total = false;
     if (is_object($metaUser)) {
         if (is_object($metaUser->focusSubscription)) {
             $comparison = $this->doPlanComparison($metaUser->focusSubscription);
             $plans_comparison = $comparison['comparison'];
             $plans_comparison_total = $comparison['total_comparison'];
         }
     } elseif (is_object($user_subscription)) {
         $comparison = $this->doPlanComparison($user_subscription);
         $plans_comparison = $comparison['comparison'];
         $plans_comparison_total = $comparison['total_comparison'];
     }
     if (!isset($this->params['full_free'])) {
         $this->params['full_free'] = false;
     }
     $allow_trial = $plans_comparison === false && $plans_comparison_total === false;
     $terms = new itemTerms();
     $terms->readParams($this->params, $allow_trial);
     if (!$allow_trial && count($terms->terms) > 1) {
         $terms->incrementPointer();
     }
     return $terms;
 }
Example #2
0
 public function invoice_items_total($request)
 {
     if (isset($request->add->tax)) {
         return true;
     } else {
         $request->add->tax = array();
     }
     $taxtypes = array();
     $taxcollections = array();
     // Collect all the taxes from the individual item costs
     foreach ($request->add->itemlist as $item) {
         foreach ($item['terms']->nextterm->cost as $cost) {
             if ($cost->type == 'tax') {
                 if (in_array($cost->cost['details'], $taxtypes)) {
                     $typeid = array_search($cost->cost['details'], $taxtypes);
                 } else {
                     $taxtypes[] = $cost->cost['details'];
                     $typeid = count($taxtypes) - 1;
                 }
                 if (!isset($taxcollections[$typeid])) {
                     $taxcollections[$typeid] = 0;
                 }
                 $taxcollections[$typeid] += $cost->renderCost() * $item['quantity'];
             }
         }
     }
     if (count($taxcollections) == 0) {
         return null;
     }
     $taxamount = 0;
     // Add tax items to total
     foreach ($taxcollections as $tid => $amount) {
         // Create tax
         $term = new itemTerm();
         if (!empty($taxtypes[$tid])) {
             $term->addCost($amount, array('details' => $taxtypes[$tid], 'tax' => true));
         } else {
             $term->addCost($amount, array('tax' => true));
         }
         $terms = new itemTerms();
         $terms->addTerm($term);
         // Add the "Tax" row
         $request->add->tax[] = array('cost' => $amount, 'terms' => $terms);
         $taxamount += $amount;
     }
     $grand_total = $request->add->total->cost['amount'];
     if (!empty($request->add->discount)) {
         foreach ($request->add->discount as $citems) {
             foreach ($citems as $ccitem) {
                 $citem = $ccitem->renderCost();
                 foreach ($citem as $cost) {
                     if ($cost->type == 'discount') {
                         $grand_total += $cost->cost['amount'];
                     }
                 }
             }
         }
     }
     $grand_total = AECToolbox::correctAmount($grand_total + $taxamount);
     // Modify grand total according to tax
     $request->add->grand_total->set('cost', array('amount' => $grand_total));
     // Formatting for total
     $request->add->total->cost['amount'] = AECToolbox::correctAmount($request->add->total->cost['amount']);
     return true;
 }
Example #3
0
 public function applyToTotal($items, $cart = false, $fullcart = false)
 {
     $itemcount = 0;
     foreach ($items->itemlist as $item) {
         if (is_object($item)) {
             $itemcount += $item->quantitiy;
         } else {
             $itemcount++;
         }
     }
     if (empty($this->fullcartlist)) {
         return $items;
     }
     foreach ($this->fullcartlist as $coupon_code) {
         if (!$this->loadCoupon($coupon_code)) {
             continue;
         }
         if ($this->cph->discount['amount_use']) {
             $this->cph->discount['amount'] = $this->cph->discount['amount'] / $itemcount;
         }
         $cost = null;
         $costarray = array();
         foreach ($items->itemlist as $cid => $citem) {
             if ($citem['obj'] == false) {
                 continue;
             }
             $citem['terms']->nextterm->computeTotal();
             if (empty($cost)) {
                 $cost = clone $citem['terms']->nextterm->getBaseCostObject();
                 $costarray[$cid] = $cost->cost['amount'];
             } else {
                 $ccost = $citem['terms']->nextterm->getBaseCostObject();
                 $cost->cost['amount'] = $cost->cost['amount'] + $ccost->cost['amount'] * $citem['quantity'];
                 $costarray[$cid] = $ccost->cost['amount'];
             }
             $items->itemlist[$cid]['terms'] = $this->cph->applyToTerms($items->itemlist[$cid]['terms'], true);
         }
     }
     $discounttypes = array();
     $discount_col = array();
     foreach ($items->itemlist as $item) {
         foreach ($item['terms']->nextterm->cost as $cost) {
             if ($cost->type != 'discount') {
                 continue;
             }
             $cc = $cost->cost['coupon'] . ' - ' . $cost->cost['details'];
             if (in_array($cc, $discounttypes)) {
                 $typeid = array_search($cc, $discounttypes);
             } else {
                 $discounttypes[] = $cc;
                 $typeid = count($discounttypes) - 1;
             }
             if (!isset($discount_col[$typeid])) {
                 $discount_col[$typeid] = 0;
             }
             $discount_col[$typeid] += $cost->renderCost();
         }
     }
     if (!empty($discount_col)) {
         // Dummy terms
         $terms = new itemTerms();
         $term = new itemTerm();
         foreach ($discount_col as $cid => $discount) {
             $cce = explode(' - ', $discounttypes[$cid], 2);
             $term->addCost($discount, array('amount' => $discount, 'coupon' => $cce[0], 'details' => $cce[1]));
         }
         $terms->addTerm($term);
         if (empty($items->discount)) {
             $items->discount = array();
         }
         $items->discount[] = $terms->terms;
     }
     return $items;
 }