예제 #1
0
파일: Balances.php 프로젝트: ngchie/system
 /**
  * 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);
 }
예제 #2
0
 /**
  * Removes lines from queue, reset added fields off lines and re-insert to queue first stage
  * @todo support update/removal of credit lines
  */
 protected function resetLines()
 {
     $lines_coll = Billrun_Factory::db()->linesCollection();
     $queue_coll = Billrun_Factory::db()->queueCollection();
     if (!empty($this->sids) && !empty($this->billrun_key)) {
         $offset = 0;
         while ($update_count = count($update_sids = array_slice($this->sids, $offset, 10))) {
             Billrun_Factory::log()->log('Resetting lines of subscribers ' . implode(',', $update_sids), Zend_Log::INFO);
             $query = array('$or' => array(array('billrun' => $this->billrun_key), array('billrun' => array('$exists' => FALSE), 'urt' => array('$gte' => new MongoDate(Billrun_Util::getStartTime($this->billrun_key)), '$lte' => new MongoDate(Billrun_Util::getEndTime($this->billrun_key))))), 'sid' => array('$in' => $update_sids), 'type' => array('$ne' => 'credit'), 'process_time' => array('$lt' => date(Billrun_Base::base_dateformat, strtotime($this->process_time_offset . ' ago'))));
             $lines = $lines_coll->query($query);
             $stamps = array();
             $queue_lines = array();
             foreach ($lines as $line) {
                 $stamps[] = $line['stamp'];
                 $queue_line = array('calc_name' => false, 'calc_time' => false, 'stamp' => $line['stamp'], 'type' => $line['type'], 'urt' => $line['urt'], 'skip_fraud' => true);
                 // todo: refactoring
                 $advancedProperties = Billrun_Factory::config()->getConfigValue("queue.advancedProperties", array('imsi', 'msisdn', 'called_number', 'calling_number'));
                 foreach ($advancedProperties as $property) {
                     if (isset($line[$property]) && !isset($queue_line[$property])) {
                         $queue_line[$property] = $line[$property];
                     }
                 }
                 $queue_lines[] = $queue_line;
             }
             $stamps_query = array('stamp' => array('$in' => $stamps));
             $update = array('$unset' => array('apr' => 1, 'aprice' => 1, 'arate' => 1, 'arategroup' => 1, 'billrun' => 1, 'in_arate' => 1, 'in_group' => 1, 'in_plan' => 1, 'out_plan' => 1, 'over_arate' => 1, 'over_group' => 1, 'over_plan' => 1, 'plan' => 1, 'usagesb' => 1, 'usagev' => 1), '$set' => array('rebalance' => new MongoDate()));
             if ($stamps) {
                 $ret = $queue_coll->remove($stamps_query, array('w' => 1));
                 // ok == 1, err null
                 if (isset($ret['err']) && !is_null($ret['err'])) {
                     return FALSE;
                 } else {
                     $ret = $this->resetBalances($update_sids);
                     // err null
                     if (isset($ret['err']) && !is_null($ret['err'])) {
                         return FALSE;
                     } else {
                         if (Billrun_Factory::db()->compareServerVersion('2.6', '>=') === true) {
                             $ret = $queue_coll->batchInsert($queue_lines, array('w' => 1));
                             // ok==true, nInserted==0 if w was 0
                             if (isset($ret['err']) && !is_null($ret['err'])) {
                                 return FALSE;
                             }
                         } else {
                             foreach ($queue_lines as $qline) {
                                 $ret = $queue_coll->insert($qline, array('w' => 1));
                                 // ok==1, err null
                                 if (isset($ret['err']) && !is_null($ret['err'])) {
                                     return FALSE;
                                 }
                             }
                         }
                         $ret = $lines_coll->update($stamps_query, $update, array('multiple' => 1, 'w' => 1));
                         // err null
                         if (isset($ret['err']) && !is_null($ret['err'])) {
                             return FALSE;
                         }
                     }
                 }
             }
             $offset += 10;
         }
     }
     return TRUE;
 }
예제 #3
0
파일: fraud.php 프로젝트: ngchie/system
 public function __construct()
 {
     $this->min_time = Billrun_Util::getStartTime(Billrun_Util::getBillrunKey(time()));
 }
예제 #4
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);
 }
예제 #5
0
파일: Compare.php 프로젝트: ngchie/system
 protected function matchSubscribers()
 {
     $this->subs_mappings = array();
     foreach ($this->source->subs as $source_id => $source_sub) {
         $params = array();
         $line_params['NDC_SN'] = intval($source_sub['identity']);
         if (is_numeric($line_params['NDC_SN']) && (in_array($line_params['NDC_SN'], $this->excluded_ndcsns) || in_array('972' . $line_params['NDC_SN'], $this->excluded_ndcsns))) {
             $this->displayMsg('skipping ndc_sn' . $line_params['NDC_SN']);
             return false;
         }
         $line_params['DATETIME'] = date(Billrun_Base::base_dateformat, Billrun_Util::getStartTime($this->billrun_key));
         $params[] = $line_params;
         $output = $this->subscriber->getSubscribersByParams($params, array('sid' => 'subscriber_id'));
         if ($output && ($sid = current($output)->sid)) {
             foreach ($this->target->subs as $target_id => $target_sub) {
                 if ($target_sub['identity'] == strval($sid)) {
                     $this->subs_mappings[$source_id] = $target_id;
                     break;
                 }
             }
         }
     }
     return true;
 }
예제 #6
0
파일: Billrun.php 프로젝트: ngchie/system
 /**
  * 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;
 }