Esempio n. 1
0
 /**
  * method to receive the balances lines that over requested date usage
  * 
  * @return Mongodloid_Cursor Mongo cursor for iteration
  */
 public function getBalancesVolume($plan, $data_usage, $from_account_id, $to_account_id, $billrun)
 {
     $params = array('name' => $plan, 'time' => Billrun_Util::getStartTime($billrun));
     $plan_id = Billrun_Factory::plan($params);
     $id = $plan_id->get('_id')->getMongoID();
     $data_usage_bytes = Billrun_Util::megabytesToBytesFormat((int) $data_usage);
     $query = array('aid' => array('$gte' => (int) $from_account_id, '$lte' => (int) $to_account_id), 'billrun_month' => $billrun, 'balance.totals.data.usagev' => array('$gt' => (double) $data_usage_bytes), 'current_plan' => Billrun_Factory::db()->plansCollection()->createRef($id));
     //		print_R($query);die;
     return $this->collection->query($query)->cursor()->setReadPreference(Billrun_Factory::config()->getConfigValue('read_only_db_pref'))->hint(array('aid' => 1, 'billrun_month' => 1))->limit($this->size);
 }
Esempio n. 2
0
 /**
  * Get the data resource
  * 
  * @return Mongo Cursor
  */
 public function getData($filter_query = array(), $fields = false)
 {
     $cursor = $this->getRates($filter_query);
     $this->_count = $cursor->count();
     $resource = $cursor->sort($this->sort)->skip($this->offset())->limit($this->size);
     $ret = array();
     foreach ($resource as $item) {
         if ($fields) {
             foreach ($fields as $field) {
                 $row[$field] = $item->get($field);
             }
             if (isset($row['rates'])) {
                 // convert plan ref to plan name
                 foreach ($row['rates'] as &$rate) {
                     if (isset($rate['plans'])) {
                         $plans = array();
                         foreach ($rate['plans'] as $plan) {
                             $plan_id = $plan['$id'];
                             $plans[] = Billrun_Factory::plan(array('id' => $plan_id))->getName();
                         }
                         $rate['plans'] = $plans;
                     }
                 }
             }
             $ret[] = $row;
         } else {
             if ($item->get('rates') && !$this->showprefix) {
                 foreach ($item->get('rates') as $key => $rate) {
                     if (is_array($rate)) {
                         $added_columns = array('t' => $key, 'tprice' => $rate['rate'][0]['price'], 'taccess' => isset($rate['access']) ? $rate['access'] : 0);
                         if (strpos($key, 'call') !== FALSE) {
                             $added_columns['tduration'] = Billrun_Util::durationFormat($rate['rate'][0]['interval']);
                         } else {
                             if ($key == 'data') {
                                 $added_columns['tduration'] = Billrun_Util::byteFormat($rate['rate'][0]['interval'], '', 0, true);
                             } else {
                                 $added_columns['tduration'] = $rate['rate'][0]['interval'];
                             }
                         }
                         $ret[] = new Mongodloid_Entity(array_merge($item->getRawData(), $added_columns, $rate));
                     }
                 }
             } else {
                 if ($this->showprefix && (isset($filter_query['$and'][0]['key']) || isset($filter_query['$and'][0]['params.prefix']))) {
                     foreach ($item->get('params.prefix') as $prefix) {
                         $item_raw_data = $item->getRawData();
                         unset($item_raw_data['params']['prefix']);
                         // to prevent high memory usage
                         $entity = new Mongodloid_Entity(array_merge($item_raw_data, array('prefix' => $prefix)));
                         $ret[] = $entity;
                     }
                 } else {
                     $ret[] = $item;
                 }
             }
         }
     }
     return $ret;
 }
Esempio n. 3
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);
 }
Esempio n. 4
0
 /**
  * Add plan reference to line
  * @param Mongodloid_Entity $row
  * @param string $plan
  */
 protected function addPlanRef($row, $plan)
 {
     $planObj = Billrun_Factory::plan(array('name' => $plan, 'time' => $row['urt']->sec, 'disableCache' => true));
     if (!$planObj->get('_id')) {
         Billrun_Factory::log("Couldn't get plan for CDR line : {$row['stamp']} with plan {$plan}", Zend_Log::ALERT);
         return;
     }
     $row['plan_ref'] = $planObj->createRef();
     return $row->get('plan_ref', true);
 }