Exemplo n.º 1
0
 /**
  * Index Action - admin panel home page
  *
  * @package     las
  * @version     1.0
  */
 public function indexAction()
 {
     $this->tag->setTitle(__('Admin panel'));
     $this->assets->addJs('js/plugins/refresh.js');
     $this->scripts = ["\$('.refresh').refresh(" . ($this->url->getBaseUri() != '/' ? "{ base_uri: '" . $this->url->getBaseUri() . "'}" : '') . ");"];
     $this->view->setVars(['clients' => Clients::find(), 'devices' => Devices::find(), 'balances' => Payments::sum(['conditions' => 'status=' . Payments::SUCCESS, 'column' => 'amount'])]);
 }
Exemplo n.º 2
0
 /**
  * Write method - add/edit the payment
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type of method: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->add('client', new Validator\PresenceOf());
     $validation->add('client', new Validator\InclusionIn(['domain' => Arr::from_model($this->clients, NULL, 'id')]));
     $validation->add('amount', new Validator\PresenceOf());
     $validation->add('amount', new Validator\Regex(['pattern' => '/[-]?\\d+(\\.\\d{2})?/']));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Payments::status()]));
     $validation->setLabels(['client' => __('Client'), 'amount' => __('Amount'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->client_id = $this->request->getPost('client', 'int');
         $this->amount = $this->request->getPost('amount');
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Index Action
  *
  * @package     las
  * @version     1.0
  */
 public function indexAction()
 {
     $this->tag->setTitle(__('Home'));
     $this->site_desc = __('Home');
     $ip = \Las\Library\Info::ip();
     $this->view->setVar('ip', $ip);
     if ($device = Devices::findFirst(['IP = :ip:', 'bind' => ['ip' => ip2long($ip)]])) {
         $client = $device->getClient();
         $this->view->setVars(['device' => $device, 'client' => $client, 'tariff' => $client->getTariff(), 'balance' => Payments::sum(['conditions' => 'status=' . Payments::SUCCESS . ' AND client_id=' . $client->id, 'column' => 'amount'])]);
     }
 }
Exemplo n.º 4
0
 /**
  * Update status Action
  *
  * @package     las
  * @version     1.0
  */
 public function statusAction()
 {
     $params = $this->router->getParams();
     if (isset($params[0]) && ($adapter = $params[0])) {
         $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
         switch ($adapter) {
             case 'dotpay':
                 $dotpay = Payment::instance('dotpay');
                 if ($dotpay->get('control') && ($payment = Payments::findFirst(array('control=:control:', 'bind' => array(':control' => $dotpay->get('control')))))) {
                     switch ($dotpay->get('t_status')) {
                         case 1:
                             $state = 'NEW';
                             break;
                         case 2:
                             $state = 'SUCCESS';
                             $payment->total_response = $dotpay->get('amount');
                             break;
                         case 3:
                             $state = 'REFUSAL';
                             break;
                         case 4:
                             $state = 'CANCEL/RETURN';
                             break;
                         case 5:
                             $state = 'RECLAMATION';
                             break;
                     }
                     $payment->state = $state;
                     $payment->date_update = date('Y-m-d H:i:s');
                     $payment->response = json_encode($dotpay->get());
                     $payment->save();
                     return $this->response->setContent('OK');
                 } else {
                     return $this->response->setContent('FAIL');
                 }
                 break;
             default:
                 $this->response->redirect(NULL);
                 break;
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Edit action - edit the payment
  *
  * @package     las
  * @version     1.0
  */
 public function editAction()
 {
     // Get id from url params and check if record exist
     $params = $this->router->getParams();
     if (isset($params[0]) && ($payment = Payments::findFirst($params[0]))) {
         $clients = Clients::find(['status!=:status:', 'bind' => ['status' => Clients::UNACTIVE]]);
         if (!count($clients)) {
             $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the client first") . ': ' . $this->tag->linkTo('admin/clients/add', __('Add')));
         }
         // Set title, pick view and send variables
         $this->tag->setTitle(__('Payment') . ' / ' . __('Edit'));
         $this->view->pick('payments/write');
         $this->view->setVars(['clients' => $clients, 'status' => Payments::status(true)]);
         // Check if the form has been sent
         if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
             $payment->__set('clients', $clients);
             $valid = $payment->write('update');
             // Check if data are valid
             if ($valid instanceof Payments) {
                 $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("The data has been saved."));
             } else {
                 $this->view->setVar('errors', $valid);
                 $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
             }
         } else {
             $diff = ['client' => $payment->client_id];
             // Values to fill out the form
             $this->tag->setDefaults(array_merge(get_object_vars($payment), $diff));
         }
     } else {
         parent::notFoundAction();
     }
 }
Exemplo n.º 6
0
 /**
  * Payment Action - charge the subscription
  *
  * @package     las
  * @version     1.0
  */
 public function paymentAction()
 {
     $clients = Clients::find('status IN (' . Clients::ACTIVE . ',' . Clients::INDEBTED . ')');
     foreach ($clients as $client) {
         $tariff = $client->getTariff();
         // Add new payment
         $payment = new Payments();
         $payment->client_id = $client->id;
         $payment->amount = -$tariff->amount;
         $payment->description = __('Subscription :month', [':month' => __(strftime('%B', strtotime('-1 month')))]);
         $payment->status = Payments::SUCCESS;
         $payment->date = date('Y-m-d H:i:s');
         $payment->save();
     }
 }