Beispiel #1
0
 protected function bulkCredit($request)
 {
     $credits = json_decode($request['credits'], true);
     if (!is_array($credits) || empty($credits)) {
         return $this->setError('Input json is invalid', $request);
     }
     $filename = md5(microtime()) . ".json";
     $parsed_rows = array();
     foreach ($credits as $credit) {
         $parsed_row = $this->parseRow($credit);
         if (is_null($parsed_row)) {
             return;
         }
         $parsed_row['file'] = $filename;
         $parsed_rows[] = $parsed_row;
     }
     $options = array('type' => 'credit', 'file_name' => $filename, 'file_content' => json_encode($parsed_rows));
     $receiver = Billrun_Receiver::getInstance($options);
     if ($receiver) {
         $files = $receiver->receive();
         if (!$files) {
             return $this->setError('Couldn\'t receive file', $request);
         }
     } else {
         return $this->setError('Receiver cannot be loaded', $request);
     }
     $this->processBulkCredit();
     $this->getController()->setOutput(array(array('status' => 1, 'desc' => 'success', 'operation' => 'credit', 'stamp' => $options['file_name'], 'input' => $request)));
     return true;
 }
Beispiel #2
0
 /**
  * method to execute the receive process
  * it's called automatically by the cli main controller
  */
 public function execute()
 {
     $possibleOptions = array('type' => false, 'path' => true, 'workspace' => true);
     if (($options = $this->_controller->getInstanceOptions($possibleOptions)) === FALSE) {
         return;
     }
     $this->getController()->addOutput("Loading receiver");
     $receiver = Billrun_Receiver::getInstance($options);
     $this->getController()->addOutput("Receiver loaded");
     if ($receiver) {
         $this->getController()->addOutput("Starting to receive. This action can take a while...");
         $files = $receiver->receive();
         $this->getController()->addOutput("Received " . count($files) . " files");
     } else {
         $this->getController()->addOutput("Receiver cannot be loaded");
     }
 }