Esempio n. 1
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     if (isset($options['calculator']['prefix_translation'])) {
         $this->prefixTranslation = $options['calculator']['prefix_translation'];
     }
     ksort($this->prefixTranslation);
     $this->loadRates();
 }
Esempio n. 2
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->optional_usage_types = isset($options['calculator']['optional_usage_types']) ? $options['calculator']['optional_usage_types'] : array('incoming_sms');
     $this->loadRates();
 }
Esempio n. 3
0
 public function __construct($options = array())
 {
     parent::__construct($options);
     $this->loadRates();
 }
Esempio n. 4
0
 public function beforeProcessorStore($processor)
 {
     Billrun_Factory::log('Plugin calc cpu triggered before processor store', Zend_Log::INFO);
     $options = array('autoload' => 0);
     $remove_duplicates = Billrun_Factory::config()->getConfigValue('calcCpu.remove_duplicates', true);
     if ($remove_duplicates) {
         $this->removeDuplicates($processor);
     }
     $data =& $processor->getData();
     Billrun_Factory::log('Plugin calc cpu rate', Zend_Log::INFO);
     foreach ($data['data'] as &$line) {
         $entity = new Mongodloid_Entity($line);
         $rateCalc = Billrun_Calculator_Rate::getRateCalculator($entity, $options);
         if ($rateCalc->isLineLegitimate($entity)) {
             if ($rateCalc->updateRow($entity) !== FALSE) {
                 $processor->setQueueRowStep($entity['stamp'], 'rate');
             }
         } else {
             $processor->setQueueRowStep($entity['stamp'], 'rate');
         }
         $line = $entity->getRawData();
         $processor->addAdvancedPropertiesToQueueRow($line);
     }
     Billrun_Factory::log('Plugin calc cpu customer.', Zend_Log::INFO);
     $customerAPISettings = Billrun_Factory::config()->getConfigValue('customer.calculator', array());
     $customerOptions = array('type' => 'customer', 'calculator' => $customerAPISettings);
     $customerCalc = Billrun_Calculator::getInstance(array_merge($options, $customerOptions));
     $queue_data = $processor->getQueueData();
     if ($customerCalc->isBulk()) {
         $customerCalc->loadSubscribers($data['data']);
     }
     $remove_garbage = Billrun_Factory::config()->getConfigValue('calcCpu.remove_garbage', false);
     $garbage_counter = 0;
     foreach ($data['data'] as $key => &$line) {
         if ($remove_garbage) {
             if ($line['type'] == 'ggsn' && isset($line['usagev']) && $line['usagev'] === 0 || in_array($line['type'], array('smsc', 'mmsc', 'smpp')) && isset($line['arate']) && $line['arate'] === false || $line['type'] == 'nsn' && isset($line['usaget']) && $line['usaget'] === 'sms') {
                 $garbage_counter++;
                 $processor->unsetQueueRow($line['stamp']);
                 unset($queue_data[$line['stamp']]);
                 unset($data['data'][$key]);
             }
         }
         if (isset($queue_data[$line['stamp']]) && $queue_data[$line['stamp']]['calc_name'] == 'rate') {
             $entity = new Mongodloid_Entity($line);
             if (!isset($entity['usagev']) || $entity['usagev'] === 0) {
                 $processor->unsetQueueRow($entity['stamp']);
             } else {
                 if ($customerCalc->isLineLegitimate($entity)) {
                     if ($customerCalc->updateRow($entity) !== FALSE) {
                         $processor->setQueueRowStep($entity['stamp'], 'customer');
                         $processor->addAdvancedPropertiesToQueueRow($entity);
                     }
                 } else {
                     $processor->setQueueRowStep($entity['stamp'], 'customer');
                 }
             }
             $line = $entity->getRawData();
         }
     }
     $data['header']['linesStats']['garbage'] = $garbage_counter;
     Billrun_Factory::log('Plugin calc cpu customer pricing', Zend_Log::INFO);
     $customerPricingCalc = Billrun_Calculator::getInstance(array('type' => 'customerPricing', 'autoload' => false));
     $queue_data = $processor->getQueueData();
     $queue_calculators = Billrun_Factory::config()->getConfigValue("queue.calculators");
     foreach ($data['data'] as &$line) {
         if (isset($queue_data[$line['stamp']]) && $queue_data[$line['stamp']]['calc_name'] == 'customer') {
             $entity = new Mongodloid_Entity($line);
             if ($customerPricingCalc->isLineLegitimate($entity)) {
                 if ($customerPricingCalc->updateRow($entity) !== FALSE) {
                     // if this is last calculator, remove from queue
                     if ($queue_calculators[count($queue_calculators) - 1] == 'pricing') {
                         $processor->unsetQueueRow($entity['stamp']);
                     } else {
                         $processor->setQueueRowStep($entity['stamp'], 'pricing');
                     }
                 }
                 if (!empty($entity['tx_saved'])) {
                     $this->tx_saved_rows[] = $entity;
                     unset($entity['tx_saved']);
                 }
             } else {
                 // if this is last calculator, remove from queue
                 if ($queue_calculators[count($queue_calculators) - 1] == 'pricing') {
                     $processor->unsetQueueRow($entity['stamp']);
                 } else {
                     $processor->setQueueRowStep($entity['stamp'], 'pricing');
                 }
             }
             $line = $entity->getRawData();
         }
     }
     if (Billrun_Factory::config()->getConfigValue('calcCpu.wholesale_calculators', true)) {
         $this->wholeSaleCalculators($data, $processor);
     }
     if (in_array('unify', $queue_calculators)) {
         $this->unifyCalc = Billrun_Calculator::getInstance(array('type' => 'unify', 'autoload' => false));
         $this->unifyCalc->init();
         $queue_data = $processor->getQueueData();
         $sucessfulyUnified = array();
         Billrun_Factory::log('Plugin calc Cpu unifying ' . count($queue_data) . ' lines', Zend_Log::INFO);
         foreach ($data['data'] as $key => &$line) {
             if (isset($queue_data[$line['stamp']]) && $queue_data[$line['stamp']]['calc_name'] == 'pricing') {
                 $entity = new Mongodloid_Entity($line);
                 if ($this->unifyCalc->isLineLegitimate($entity)) {
                     if ($this->unifyCalc->updateRow($entity) !== FALSE) {
                         //mark lines that were successfuly unified.
                         $sucessfulyUnified[$entity['stamp']] = $key;
                     }
                 } else {
                     //Billrun_Factory::log("Line $key isnt legitimate : ".print_r($line,1), Zend_Log::INFO);
                     // if this is last calculator, remove from queue
                     if ($queue_calculators[count($queue_calculators) - 1] == 'unify') {
                         $processor->unsetQueueRow($entity['stamp']);
                     } else {
                         $processor->setQueueRowStep($entity['stamp'], 'unify');
                     }
                 }
                 $line = $entity->getRawData();
             }
         }
         //handle update errors unmark  lines that thier unified line failed to update.
         foreach ($this->unifyCalc->updateUnifiedLines() as $failedLine) {
             foreach ($failedLine['lines'] as $stamp) {
                 unset($sucessfulyUnified[$stamp]);
             }
         }
         //remove lines that where succesfully unified.
         foreach ($sucessfulyUnified as $stamp => $dataKey) {
             $processor->unsetQueueRow($stamp);
             unset($data['data'][$dataKey]);
         }
         $this->unifyCalc->saveLinesToArchive();
         //Billrun_Factory::log(count($data['data']), Zend_Log::INFO);
     }
     Billrun_Factory::log('Plugin calc cpu end', Zend_Log::INFO);
 }