Esempio n. 1
0
 /**
  * Load a subscriber for a given CDR line.
  * @param type $row
  * @return type
  */
 protected function loadSubscriberForLine($row)
 {
     $params = $this->getIdentityParams($row);
     if (count($params) == 0) {
         Billrun_Factory::log('Couldn\'t identify caller for line of stamp ' . $row->get('stamp'), Zend_Log::ALERT);
         return;
     }
     $params['time'] = date(Billrun_Base::base_dateformat, $row->get('urt')->sec);
     $params['stamp'] = $row->get('stamp');
     return $this->subscriber->load($params);
 }
Esempio n. 2
0
 /**
  * Creates and saves a flat line to the db
  * @param Billrun_Subscriber $subscriber the subscriber to create a flat line to
  * @param string $billrun_key the billrun for which to add the flat line
  * @return array the inserted line or the old one if it already exists
  */
 protected function saveFlatLine($subscriber, $billrun_key)
 {
     $flat_entry = $subscriber->getFlatEntry($billrun_key, true);
     try {
         $this->lines->insert($flat_entry->getRawData(), array("w" => 1));
     } catch (Exception $e) {
         if ($e->getCode() == 11000) {
             Billrun_Factory::log("Flat line already exists for subscriber " . $subscriber->sid . " for billrun " . $billrun_key, Zend_log::ALERT);
         } else {
             Billrun_Factory::log("Problem inserting flat line for subscriber " . $subscriber->sid . " for billrun " . $billrun_key . ". error message: " . $e->getMessage() . ". error code: " . $e->getCode(), Zend_log::ALERT);
             Billrun_Util::logFailedCreditRow($flat_entry->getRawData());
         }
     }
     return $flat_entry;
 }
Esempio n. 3
0
 /**
  * method to retrieve the subscriber instance
  * 
  * @return Billrun_Subscriber
  */
 public static function subscriber()
 {
     if (!self::$subscriber) {
         $subscriberSettings = self::config()->getConfigValue('subscriber', array());
         self::$subscriber = Billrun_Subscriber::getInstance($subscriberSettings);
     }
     return self::$subscriber;
 }
Esempio n. 4
0
 /**
  * Updates the billrun costs, lines & breakdown with the input line if the line is not already included in it
  * @param string $billrun_key the billrun_key to insert into the billrun
  * @param array $counters keys - usage type. values - amount of usage. Currently supports only arrays of one element
  * @param array $pricingData the output array from updateSubscriberBalance function
  * @param Mongodloid_Entity $row the input line
  * @param boolean $vatable is the line vatable or not
  * @return Mongodloid_Entity the billrun doc of the line, false if no such billrun exists
  */
 public function updateBillrun($billrun_key, $counters, $pricingData, $row, $vatable)
 {
     $sid = $row['sid'];
     $sraw = $this->getSubRawData($sid);
     if ($sraw) {
         // it could be that this sid hasn't been returned on active_subscribers...
         $this->addLineToSubscriber($counters, $row, $pricingData, $vatable, $billrun_key, $sraw);
         $this->updateCosts($pricingData, $row, $vatable, $sraw);
         $this->setSubRawData($sraw);
     } else {
         Billrun_Factory::log("Subscriber {$sid} is not active, yet has lines", Zend_log::ALERT);
         $subscriber_general_settings = Billrun_Config::getInstance()->getConfigValue('subscriber', array());
         $null_subscriber_params = array('data' => array('aid' => $row['aid'], 'sid' => $sid, 'plan' => null, 'next_plan' => null));
         $subscriber_settings = array_merge($subscriber_general_settings, $null_subscriber_params);
         $subscriber = Billrun_Subscriber::getInstance($subscriber_settings);
         $this->addSubscriber($subscriber, "closed");
         $this->updateBillrun($billrun_key, $counters, $pricingData, $row, $vatable);
     }
 }