Exemple #1
0
 /**
  * Returns the minimum billrun key greater than all the billrun keys in billrun collection
  * @return string billrun_key
  * @todo create an appropriate index on billrun collection
  */
 public static function getActiveBillrun()
 {
     $now = time();
     $sort = array('billrun_key' => -1);
     $fields = array('billrun_key' => 1);
     $runtime_billrun_key = Billrun_Util::getBillrunKey($now);
     $last = Billrun_Factory::db(array('name' => 'billrun'))->billrunCollection()->query()->cursor()->limit(1)->fields($fields)->sort($sort)->current();
     if ($last->isEmpty()) {
         $active_billrun = $runtime_billrun_key;
     } else {
         $active_billrun = Billrun_Util::getFollowingBillrunKey($last['billrun_key']);
         $billrun_start_time = Billrun_Util::getStartTime($active_billrun);
         if ($now - $billrun_start_time > 5184000) {
             // more than two months diff (60*60*24*30*2)
             $active_billrun = $runtime_billrun_key;
         }
     }
     return $active_billrun;
 }
Exemple #2
0
 /**
  * 
  * @param array $subscriber subscriber entry from billrun collection
  * @return array
  */
 protected function getFlatCosts($subscriber)
 {
     $plan_name = $this->getNextPlanName($subscriber);
     if (!$plan_name) {
         //@error
         return array();
     }
     $planObj = Billrun_Factory::plan(array('name' => $plan_name, 'time' => Billrun_Util::getStartTime(Billrun_Util::getFollowingBillrunKey($this->stamp))));
     if (!$planObj->get('_id')) {
         Billrun_Factory::log("Couldn't get plan {$plan_name} data", Zend_Log::ALERT);
         return array();
     }
     $plan_price = $planObj->get('price');
     return array('vatable' => $plan_price, 'vat_free' => 0);
 }
Exemple #3
0
 public function __construct($options = array())
 {
     if (isset($options['autoload'])) {
         $autoload = $options['autoload'];
     } else {
         $autoload = true;
     }
     $options['autoload'] = false;
     parent::__construct($options);
     if (isset($options['calculator']['limit'])) {
         $this->limit = $options['calculator']['limit'];
     }
     if (isset($options['calculator']['vatable'])) {
         $this->vatable = $options['calculator']['vatable'];
     }
     if (isset($options['calculator']['months_limit'])) {
         $this->months_limit = $options['calculator']['months_limit'];
     }
     if (isset($options['calculator']['unlimited_to_balances'])) {
         $this->unlimited_to_balances = (bool) $options['calculator']['unlimited_to_balances'];
     }
     $this->billrun_lower_bound_timestamp = is_null($this->months_limit) ? 0 : strtotime($this->months_limit . " months ago");
     // set months limit
     if ($autoload) {
         $this->load();
     }
     $this->loadRates();
     $this->loadPlans();
     $this->balances = Billrun_Factory::db(array('name' => 'balances'))->balancesCollection()->setReadPreference('RP_PRIMARY');
     $this->active_billrun = Billrun_Billrun::getActiveBillrun();
     $this->active_billrun_end_time = Billrun_Util::getEndTime($this->active_billrun);
     $this->next_active_billrun = Billrun_Util::getFollowingBillrunKey($this->active_billrun);
     // max recursive retrues for value=oldValue tactic
     $this->concurrentMaxRetries = (int) Billrun_Factory::config()->getConfigValue('updateValueEqualOldValueMaxRetries', 8);
     $this->sidsQueuedForRebalance = array_flip(Billrun_Factory::db()->rebalance_queueCollection()->distinct('sid'));
 }