Ejemplo n.º 1
0
 public function getFilterFields()
 {
     $months = 6;
     $billruns = array();
     $timestamp = time();
     for ($i = 0; $i < $months; $i++) {
         $billrun_key = Billrun_Util::getBillrunKey($timestamp);
         if ($billrun_key >= '201401') {
             $billruns[$billrun_key] = $billrun_key;
         } else {
             break;
         }
         $timestamp = strtotime("1 month ago", $timestamp);
     }
     arsort($billruns);
     //		$plansModel = new PlansModel();
     //		$plansCursor = $plansModel->getData();
     //		$plans = array();
     //		foreach ($plansCursor as $p) {
     //			$plans[(string) $p->getId()->getMongoID()] = $p["name"];
     //		}
     $usage_filter_values = $this->getBalancesFields();
     unset($usage_filter_values['aid'], $usage_filter_values['sid'], $usage_filter_values['billrun_month'], $usage_filter_values['current_plan']);
     //		$usage_filter_values = array_merge($basic_columns, $extra_columns);
     $planNames = array_unique(array_keys(Billrun_Plan::getPlans()['by_name']));
     $planNames = array_combine($planNames, $planNames);
     $operators = array('equals' => '=', 'lt' => '<', 'lte' => '<=', 'gt' => '>', 'gte' => '>=');
     $filter_fields = array('aid' => array('key' => 'aid', 'db_key' => 'aid', 'input_type' => 'number', 'comparison' => 'equals', 'display' => 'Account id', 'default' => ''), 'sid' => array('key' => 'sid', 'db_key' => 'sid', 'input_type' => 'number', 'comparison' => 'equals', 'display' => 'Subscriber id', 'default' => ''), 'usage_type' => array('key' => 'manual_key', 'db_key' => 'nofilter', 'input_type' => 'multiselect', 'display' => 'Usage', 'values' => $usage_filter_values, 'singleselect' => 1, 'default' => array()), 'usage_filter' => array('key' => 'manual_operator', 'db_key' => 'nofilter', 'input_type' => 'multiselect', 'display' => '', 'values' => $operators, 'singleselect' => 1, 'default' => array()), 'usage_value' => array('key' => 'manual_value', 'db_key' => 'nofilter', 'input_type' => 'number', 'display' => '', 'default' => ''), 'plan' => array('key' => 'plan', 'db_key' => 'current_plan', 'input_type' => 'multiselect', 'comparison' => '$in', 'ref_coll' => 'plans', 'ref_key' => 'name', 'display' => 'Plan', 'values' => $planNames, 'default' => array()), 'billrun' => array('key' => 'billrun', 'db_key' => 'billrun_month', 'input_type' => 'multiselect', 'comparison' => '$in', 'display' => 'Billrun', 'values' => $billruns, 'default' => array()));
     return array_merge($filter_fields, parent::getFilterFields());
 }
Ejemplo n.º 2
0
 public function execute()
 {
     $request = $this->getRequest();
     $aid = $request->get("aid");
     $stamp = Billrun_Util::getBillrunKey(time());
     $subscribers = $request->get("subscribers");
     if (!is_numeric($aid)) {
         die;
     }
     if (is_string($subscribers)) {
         $subscribers = explode(",", $subscribers);
     } else {
         $subscribers = array();
     }
     $options = array('type' => 'balance', 'aid' => $aid, 'subscribers' => $subscribers, 'stamp' => $stamp);
     $generator = Billrun_Generator::getInstance($options);
     if ($generator) {
         $generator->load();
         header('Content-type: text/xml');
         $generator->generate();
         $this->getController()->setOutput(array(false, true));
         // hack
     } else {
         $this->_controller->addOutput("Generator cannot be loaded");
     }
 }
Ejemplo n.º 3
0
 public function load($subscriberId, $billrunKey = NULL)
 {
     Billrun_Factory::log()->log("Trying to load balance " . $billrunKey . " for subscriber " . $subscriberId, Zend_Log::DEBUG);
     $billrunKey = !$billrunKey ? Billrun_Util::getBillrunKey(time()) : $billrunKey;
     $this->data = Billrun_Factory::db(array('name' => 'balances'))->balancesCollection()->query(array('sid' => $subscriberId, 'billrun_month' => $billrunKey))->cursor()->hint(array('sid' => 1, 'billrun_month' => 1))->limit(1)->current();
     $this->data->collection(Billrun_Factory::db(array('name' => 'balances'))->balancesCollection());
 }
Ejemplo n.º 4
0
 public function load($subscriberId, $billrunKey = NULL)
 {
     Billrun_Factory::log()->log("Trying to load balance " . $billrunKey . " for subscriber " . $subscriberId, Zend_Log::DEBUG);
     $billrunKey = !$billrunKey ? Billrun_Util::getBillrunKey(time()) : $billrunKey;
     $this->data = $this->collection->query(array('sid' => $subscriberId, 'billrun_month' => $billrunKey))->cursor()->setReadPreference('RP_PRIMARY')->hint(array('sid' => 1, 'billrun_month' => 1))->limit(1)->current();
     // set the data collection to enable clear save
     $this->data->collection($this->collection);
 }
Ejemplo n.º 5
0
 /**
  * method to clean account cache
  * 
  * @param int $aid
  * 
  * @return true on success, else false
  */
 protected function cleanAccountCache($aid)
 {
     $cache = Billrun_Factory::cache();
     if (empty($cache)) {
         return false;
     }
     $aids = array_unique(array_diff(Billrun_Util::verify_array(explode(',', $aid), 'int'), array(0)));
     $billrunKey = Billrun_Util::getBillrunKey(time());
     $cachePrefix = 'balance_';
     // this is not the action name because it's clear the balance cache
     foreach ($aids as $aid) {
         $cleanCacheKeys = array(Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => array(), 'stamp' => $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => null, 'stamp' => (int) $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => "", 'stamp' => (int) $billrunKey))), Billrun_Util::generateArrayStamp(array_values(array('aid' => $aid, 'subscribers' => 0, 'stamp' => (int) $billrunKey))));
         foreach ($cleanCacheKeys as $cacheKey) {
             $cache->remove($cacheKey, $cachePrefix);
         }
     }
     return true;
 }
Ejemplo n.º 6
0
 public function execute()
 {
     $request = $this->getRequest();
     $aid = $request->get("aid");
     Billrun_Factory::log()->log("Execute balance api call to " . $aid, Zend_Log::INFO);
     $stamp = Billrun_Util::getBillrunKey(time());
     $subscribers = $request->get("subscribers");
     if (!is_numeric($aid)) {
         return $this->setError("aid is not numeric", $request);
     } else {
         settype($aid, 'int');
     }
     if (is_string($subscribers)) {
         $subscribers = explode(",", $subscribers);
     } else {
         $subscribers = array();
     }
     $cacheParams = array('fetchParams' => array('aid' => $aid, 'subscribers' => $subscribers, 'stamp' => $stamp));
     $output = $this->cache($cacheParams);
     header('Content-type: text/xml');
     $this->getController()->setOutput(array($output, true));
     // hack
 }
Ejemplo n.º 7
0
 public function execute()
 {
     Billrun_Factory::log()->log("Execute recreate invoices", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     if (empty($request['account_id'])) {
         return $this->setError('Please supply at least one account id', $request);
     }
     $billrun_key = Billrun_Util::getPreviousBillrunKey(Billrun_Util::getBillrunKey(time()));
     // Warning: will convert half numeric strings / floats to integers
     $account_ids = array_unique(array_diff(Billrun_Util::verify_array(explode(',', $request['account_id']), 'int'), array(0)));
     if ($account_ids) {
         $options = array('autoload' => 0, 'stamp' => $billrun_key);
         $customer_aggregator_options = array('override_accounts' => $account_ids, 'bulk_account_preload' => 0);
         $customerOptions = array('type' => 'customer', 'aggregator' => $customer_aggregator_options);
         $customerAgg = Billrun_Aggregator::getInstance(array_merge($options, $customerOptions));
         $customerAgg->load();
         $successfulAccounts = $customerAgg->aggregate();
     } else {
         return $this->setError('Illegal aids', $request);
     }
     $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'input' => $request, 'successfulAccounts' => $successfulAccounts)));
     return TRUE;
 }
Ejemplo n.º 8
0
 public function __construct()
 {
     $this->min_time = Billrun_Util::getStartTime(Billrun_Util::getBillrunKey(time()));
 }
Ejemplo n.º 9
0
 public function getFilterFields()
 {
     $months = 6;
     $previous_billruns = array();
     $timestamp = time();
     for ($i = 1; $i <= $months; $i++) {
         $timestamp = strtotime("1 month ago", $timestamp);
         $billrun_key = Billrun_Util::getBillrunKey($timestamp);
         if ($billrun_key >= '201401') {
             $previous_billruns[$billrun_key] = $billrun_key;
         }
     }
     arsort($previous_billruns);
     $current_billrun_key = '000000';
     $current_billrun = array($current_billrun_key => 'Current billrun');
     $billruns = $current_billrun + $previous_billruns;
     $filter_fields = array('aid' => array('key' => 'aid', 'db_key' => 'aid', 'input_type' => 'number', 'comparison' => 'equals', 'display' => 'Account id', 'default' => ''), 'sid' => array('key' => 'sid', 'db_key' => 'sid', 'input_type' => 'number', 'comparison' => 'equals', 'display' => 'Subscriber id', 'default' => ''), 'from' => array('key' => 'from', 'db_key' => 'urt', 'input_type' => 'date', 'comparison' => '$gte', 'display' => 'From', 'default' => (new Zend_Date(strtotime('2013-01-01'), null, new Zend_Locale('he_IL')))->toString('YYYY-MM-dd HH:mm:ss')), 'to' => array('key' => 'to', 'db_key' => 'urt', 'input_type' => 'date', 'comparison' => '$lte', 'display' => 'To', 'default' => (new Zend_Date(strtotime("next month"), null, new Zend_Locale('he_IL')))->toString('YYYY-MM-dd HH:mm:ss')), 'usage' => array('key' => 'usage', 'db_key' => 'usaget', 'input_type' => 'multiselect', 'comparison' => '$in', 'display' => 'Usage', 'values' => Billrun_Factory::config()->getConfigValue('admin_panel.line_usages'), 'default' => array()), 'billrun' => array('key' => 'billrun', 'db_key' => 'billrun', 'input_type' => 'multiselect', 'comparison' => '$in', 'display' => 'Billrun', 'values' => $billruns, 'default' => $current_billrun_key));
     return array_merge($filter_fields, parent::getFilterFields());
 }
Ejemplo n.º 10
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;
 }
Ejemplo n.º 11
0
 /**
  * removes the transactions from the subscriber's balance to save space.
  * @param type $row
  */
 public function removeBalanceTx($row)
 {
     $sid = $row['sid'];
     $billrun_key = Billrun_Util::getBillrunKey($row['urt']->sec);
     $query = array('billrun_month' => $billrun_key, 'sid' => $sid);
     $values = array('$unset' => array('tx.' . $row['stamp'] => 1));
     $this->balances->update($query, $values);
 }