예제 #1
0
 public function load()
 {
     $this->date = date(Billrun_Base::base_dateformat, $this->now);
     $subscriber = Billrun_Factory::subscriber();
     $this->account_data = array();
     $res = $subscriber->getList(0, 1, $this->date, $this->aid);
     if (!empty($res)) {
         $this->account_data = current($res);
     }
     $previous_billrun_key = Billrun_Util::getPreviousBillrunKey($this->stamp);
     if (Billrun_Billrun::exists($this->aid, $previous_billrun_key)) {
         $start_time = 0;
         // maybe some lines are late (e.g. tap3)
     } else {
         $start_time = Billrun_Util::getStartTime($this->stamp);
         // to avoid getting lines of previous billruns
     }
     $billrun_params = array('aid' => $this->aid, 'billrun_key' => $this->stamp, 'autoload' => false);
     $billrun = Billrun_Factory::billrun($billrun_params);
     $flat_lines = array();
     foreach ($this->account_data as $subscriber) {
         if ($billrun->subscriberExists($subscriber->sid)) {
             Billrun_Factory::log()->log("Billrun " . $this->stamp . " already exists for subscriber " . $subscriber->sid, Zend_Log::ALERT);
             continue;
         }
         $next_plan_name = $subscriber->getNextPlanName();
         if (is_null($next_plan_name) || $next_plan_name == "NULL") {
             $subscriber_status = "closed";
         } else {
             $subscriber_status = "open";
             $flat_lines[] = new Mongodloid_Entity($subscriber->getFlatEntry($this->stamp));
         }
         $billrun->addSubscriber($subscriber, $subscriber_status);
     }
     $this->lines = $billrun->addLines(false, $start_time, $flat_lines);
     $this->data = $billrun->getRawData();
 }
예제 #2
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;
 }