Пример #1
0
 /**
  * method to execute remove of billing lines (only credit and active)
  * it's called automatically by the api main controller
  */
 public function execute()
 {
     Billrun_Factory::log()->log("Execute api remove", Zend_Log::INFO);
     $request = $this->getRequest()->getRequest();
     // supports GET / POST requests
     Billrun_Factory::log()->log("Input: " . print_R($request, 1), Zend_Log::INFO);
     $stamps = array();
     foreach ($request['stamps'] as $line_stamp) {
         $clear_stamp = Billrun_Util::filter_var($line_stamp, FILTER_SANITIZE_STRING, FILTER_FLAG_ALLOW_HEX);
         if (!empty($clear_stamp)) {
             $stamps[] = $clear_stamp;
         }
     }
     if (empty($stamps)) {
         Billrun_Factory::log()->log("remove action failed; no correct stamps", Zend_Log::INFO);
         $this->getController()->setOutput(array(array('status' => false, 'desc' => 'failed - invalid stamps input', 'input' => $request)));
         return true;
     }
     $model = new LinesModel();
     $query = array('source' => 'api', 'stamp' => array('$in' => $stamps), '$or' => array(array('billrun' => array('$gte' => Billrun_Billrun::getActiveBillrun())), array('billrun' => array('$exists' => false))));
     $ret = $model->remove($query);
     if (!isset($ret['ok']) || !$ret['ok'] || !isset($ret['n'])) {
         Billrun_Factory::log()->log("remove action failed pr miscomplete", Zend_Log::INFO);
         $this->getController()->setOutput(array(array('status' => false, 'desc' => 'remove failed', 'input' => $request)));
         return true;
     }
     Billrun_Factory::log()->log("remove success", Zend_Log::INFO);
     $this->getController()->setOutput(array(array('status' => $ret['n'], 'desc' => 'success', 'input' => $request)));
 }
Пример #2
0
 public function __construct($options = array())
 {
     if (isset($options['autoload'])) {
         $autoload = $options['autoload'];
     } else {
         $autoload = true;
     }
     $options['autoload'] = false;
     parent::__construct($options);
     if (isset($options['calculator']['limit'])) {
         $this->limit = $options['calculator']['limit'];
     }
     if (isset($options['calculator']['vatable'])) {
         $this->vatable = $options['calculator']['vatable'];
     }
     if (isset($options['calculator']['months_limit'])) {
         $this->months_limit = $options['calculator']['months_limit'];
     }
     if (isset($options['calculator']['unlimited_to_balances'])) {
         $this->unlimited_to_balances = (bool) $options['calculator']['unlimited_to_balances'];
     }
     $this->billrun_lower_bound_timestamp = is_null($this->months_limit) ? 0 : strtotime($this->months_limit . " months ago");
     // set months limit
     if ($autoload) {
         $this->load();
     }
     $this->loadRates();
     $this->loadPlans();
     $this->balances = Billrun_Factory::db(array('name' => 'balances'))->balancesCollection()->setReadPreference('RP_PRIMARY');
     $this->active_billrun = Billrun_Billrun::getActiveBillrun();
     $this->active_billrun_end_time = Billrun_Util::getEndTime($this->active_billrun);
     $this->next_active_billrun = Billrun_Util::getFollowingBillrunKey($this->active_billrun);
     // max recursive retrues for value=oldValue tactic
     $this->concurrentMaxRetries = (int) Billrun_Factory::config()->getConfigValue('updateValueEqualOldValueMaxRetries', 8);
     $this->sidsQueuedForRebalance = array_flip(Billrun_Factory::db()->rebalance_queueCollection()->distinct('sid'));
 }