function match(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentDate = 'now')
 {
     switch ($this->type) {
         case self::TYPE_GLOBAL_1:
             return $tier == 0;
         case self::TYPE_GLOBAL_2:
             return $tier == 1;
     }
     if ($tier != 0) {
         return false;
     }
     // no custom rules for 2-tier
     // check conditions
     foreach ($this->getConditions() as $conditionType => $vars) {
         switch ($conditionType) {
             case self::COND_AFF_SALES_COUNT:
             case self::COND_AFF_SALES_AMOUNT:
                 if (empty($vars['count']) || empty($vars['days'])) {
                     return false;
                 }
                 $e = sqlDate($paymentDate);
                 $b = sqlDate($e . '-' . $vars['days'] . ' days');
                 $stats = $this->getDi()->affCommissionTable->getAffStats($aff->pk(), $b, $e);
                 $key = $conditionType == self::COND_AFF_SALES_AMOUNT ? 'amount' : 'count';
                 if ($stats[$key] < $vars['count']) {
                     return false;
                 }
                 break;
             case self::COND_AFF_GROUP_ID:
                 if (!array_intersect($aff->getGroups(), (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_ID:
                 if ($item->item_type != 'product' || !in_array($item->item_id, (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_CATEGORY_ID:
                 if ($item->item_type != 'product') {
                     return false;
                 }
                 $pr = $item->tryLoadProduct();
                 if (!$pr) {
                     return false;
                 }
                 if (!array_intersect($pr->getCategories(), (array) $vars)) {
                     return false;
                 }
                 break;
             default:
                 return false;
         }
     }
     return true;
 }
예제 #2
0
파일: Invoice.php 프로젝트: grlf/eyedock
 /**
  * Return true if subscription can be changed
  * @param Invoice $invoice
  * @param BillingPlan $from
  * @param BillingPlan $to
  * @return boolean
  */
 public function canUpgrade(InvoiceItem $item, ProductUpgrade $upgrade)
 {
     if ($item->billing_plan_id != $upgrade->from_billing_plan_id) {
         return false;
     }
     // check for other recurring items
     foreach ($this->getItems() as $it) {
         if ($item->invoice_item_id != $it->invoice_item_id) {
             if ((double) $it->second_total) {
                 return false;
             }
         }
         // there is another recurring item, upgrade impossible
     }
     $to = $upgrade->getToPlan();
     if (!$to) {
         return false;
     }
     // check if $to is compatible to billing terms
     $newItem = $this->createItem($to->getProduct());
     $error = $this->isItemCompatible($newItem, array($item));
     if (null != $error) {
         return false;
     }
     /* check if paysystem can do upgrade */
     $pr = $item->tryLoadProduct();
     if (!$pr instanceof Product) {
         return false;
     }
     $ps = $this->getPaysystem();
     if (!$ps) {
         return false;
     }
     return $ps->canUpgrade($this, $item, $upgrade);
 }
예제 #3
0
 function match(Invoice $invoice, InvoiceItem $item, User $aff, $paymentNumber = 0, $tier = 0, $paymentDate = 'now')
 {
     if ($this->type == self::TYPE_GLOBAL) {
         return $tier == $this->tier;
     }
     if ($tier != 0) {
         return false;
     }
     // no custom rules for 2-tier
     // check conditions
     foreach ($this->getConditions() as $conditionType => $vars) {
         switch ($conditionType) {
             case self::COND_AFF_SALES_COUNT:
             case self::COND_AFF_ITEMS_COUNT:
             case self::COND_AFF_SALES_AMOUNT:
                 if (empty($vars['count']) || empty($vars['days'])) {
                     return false;
                 }
                 $e = sqlDate($paymentDate);
                 $b = sqlDate($e . '-' . $vars['days'] . ' days');
                 $stats = $this->getDi()->affCommissionTable->getAffStats($aff->pk(), $b, $e);
                 switch ($conditionType) {
                     case self::COND_AFF_ITEMS_COUNT:
                         $key = 'items_count';
                         break;
                     case self::COND_AFF_SALES_COUNT:
                         $key = 'count';
                         break;
                     default:
                         $key = 'amount';
                 }
                 if ($stats[$key] < $vars['count']) {
                     return false;
                 }
                 break;
             case self::COND_AFF_GROUP_ID:
                 if (!array_intersect($aff->getGroups(), (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_ID:
                 if ($item->item_type != 'product' || !in_array($item->item_id, (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_PRODUCT_CATEGORY_ID:
                 if ($item->item_type != 'product') {
                     return false;
                 }
                 $pr = $item->tryLoadProduct();
                 if (!$pr) {
                     return false;
                 }
                 if (!array_intersect($pr->getCategories(), (array) $vars)) {
                     return false;
                 }
                 break;
             case self::COND_COUPON:
                 $coupon = $invoice->getCoupon();
                 switch ($vars['type']) {
                     case 'any':
                         $coupon_cond_match = (bool) $coupon;
                         break;
                     case 'coupon':
                         $coupon_cond_match = $coupon && $vars['code'] == $coupon->code;
                         break;
                     case 'batch':
                         $coupon_cond_match = $coupon && $vars['batch_id'] == $coupon->batch_id;
                         break;
                 }
                 if ($vars['used'] ? !$coupon_cond_match : $coupon_cond_match) {
                     return false;
                 }
                 break;
             case self::COND_PAYSYS_ID:
                 if (!in_array($invoice->paysys_id, (array) $vars)) {
                     return false;
                 }
                 break;
             default:
                 return false;
         }
     }
     return true;
 }
예제 #4
0
파일: Tax.php 프로젝트: grlf/eyedock
 function getRatePerProduct($country, InvoiceItem $item = null)
 {
     $country = strtoupper($country);
     if (!empty($item) && $item->item_type == 'product') {
         $product = $item->tryLoadProduct();
         $rates = unserialize($product->data()->getBlob('vat_eu_rate'));
         $customRate = is_array($rates) && isset($rates[$country]) && !empty($rates[$country]) ? $rates[$country] : null;
     } else {
         $customRate = null;
     }
     return !is_null($customRate) ? $customRate : $this->getConfig('rate.' . strtoupper($country), $this->rates[strtoupper($country)]);
 }