예제 #1
0
파일: Remove.php 프로젝트: ngchie/system
 /**
  * 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
 protected function parseRow($credit_row)
 {
     // @TODO: take to config
     $required_fields = array(array('credit_type', 'charge_type'), 'amount_without_vat', 'reason', 'account_id', 'subscriber_id', 'credit_time', 'service_name');
     // @TODO: take to config
     $optional_fields = array('vatable' => '1');
     $filtered_request = array();
     foreach ($required_fields as $field) {
         $found_field = false;
         if (is_array($field)) {
             foreach ($field as $req) {
                 if (isset($credit_row[$req])) {
                     if ($found_field) {
                         unset($credit_row[$req]);
                         // so the stamp won't be calculated on it.
                     } else {
                         $filtered_request[$req] = $credit_row[$req];
                         $found_field = true;
                     }
                 }
             }
         } else {
             if (isset($credit_row[$field])) {
                 $filtered_request[$field] = $credit_row[$field];
                 $found_field = true;
             }
         }
         if (!$found_field) {
             return $this->setError('required field(s) missing: ' . print_r($field, true), $credit_row);
         }
     }
     foreach ($optional_fields as $field => $default_value) {
         if (!isset($credit_row[$field])) {
             $filtered_request[$field] = $default_value;
         } else {
             $filtered_request[$field] = $credit_row[$field];
         }
     }
     if (isset($filtered_request['charge_type'])) {
         $filtered_request['credit_type'] = $filtered_request['charge_type'];
         unset($filtered_request['charge_type']);
     }
     if ($filtered_request['credit_type'] != 'charge' && $filtered_request['credit_type'] != 'refund') {
         return $this->setError('credit_type could be either "charge" or "refund"', $credit_row);
     }
     $amount_without_vat = Billrun_Util::filter_var($filtered_request['amount_without_vat'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
     if (!is_numeric($filtered_request['amount_without_vat']) || $amount_without_vat === false) {
         return $this->setError('amount_without_vat is not a number', $credit_row);
     } else {
         // TODO: Temporary conversion. Remove it once they send negative values!
         if ($filtered_request['credit_type'] == 'refund' && floatval($amount_without_vat) > 0) {
             $filtered_request['amount_without_vat'] = -floatval($amount_without_vat);
         } else {
             $filtered_request['amount_without_vat'] = floatval($amount_without_vat);
         }
     }
     if (is_string($filtered_request['reason'])) {
         $filtered_request['reason'] = preg_replace('/[^a-zA-Z0-9-_]+/', '_', $filtered_request['reason']);
         // removes unwanted characters from the string (especially dollar sign and dots)
     } else {
         return $this->setError('reason error', $credit_row);
     }
     if (!empty($filtered_request['service_name']) && is_string($filtered_request['service_name'])) {
         $filtered_request['service_name'] = preg_replace('/[^a-zA-Z0-9-_]+/', '_', $filtered_request['service_name']);
         // removes unwanted characters from the string (especially dollar sign and dots) as they are not allowed as mongo keys
     } else {
         return $this->setError('service_name error', $credit_row);
     }
     if (isset($filtered_request['account_id'])) {
         $filtered_request['aid'] = (int) $filtered_request['account_id'];
         unset($filtered_request['account_id']);
     }
     if (isset($filtered_request['subscriber_id'])) {
         $filtered_request['sid'] = (int) $filtered_request['subscriber_id'];
         unset($filtered_request['subscriber_id']);
     }
     if ($filtered_request['aid'] == 0 || $filtered_request['sid'] == 0) {
         return $this->setError('account, subscriber ids must be positive integers', $credit_row);
     }
     $credit_time = new Zend_Date($filtered_request['credit_time']);
     $filtered_request['urt'] = new MongoDate($credit_time->getTimestamp());
     unset($filtered_request['credit_time']);
     $filtered_request['vatable'] = filter_var($filtered_request['vatable'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
     if (!is_null($filtered_request['vatable'])) {
         $filtered_request['vatable'] = (int) $filtered_request['vatable'];
     } else {
         return $this->setError('vatable could be either "0" or "1"', $credit_row);
     }
     $filtered_request['source'] = 'api';
     $filtered_request['usaget'] = $filtered_request['type'] = 'credit';
     ksort($filtered_request);
     $filtered_request['stamp'] = Billrun_Util::generateArrayStamp($filtered_request);
     return $filtered_request;
 }
예제 #3
0
 public function logDetailsAction()
 {
     $coll = Billrun_Util::filter_var($this->getRequest()->get('coll'), FILTER_SANITIZE_STRING);
     $stamp = Billrun_Util::filter_var($this->getRequest()->get('stamp'), FILTER_SANITIZE_STRING);
     $type = Billrun_Util::filter_var($this->getRequest()->get('type'), FILTER_SANITIZE_STRING);
     $model = self::getModel($coll);
     $entity = $model->getDataByStamp(array("stamp" => $stamp));
     // passing values into the view
     $this->getView()->entity = $entity;
     $this->getView()->protectedKeys = $model->getProtectedKeys($entity, $type);
     $this->getView()->collectionName = $coll;
     $this->getView()->type = $type;
 }