Exemplo n.º 1
0
 /**
  * Cutoff Action - change status for clients
  *
  * @package     las
  * @version     1.0
  */
 public function cutoffAction()
 {
     $balances = Payments::sum(['conditions' => 'status=' . Payments::SUCCESS, 'column' => 'amount', 'group' => 'client_id']);
     foreach ($balances as $balance) {
         if ($balance->sumatory < 0) {
             $client = Clients::findFirst($balance->client_id);
             $tariff = $client->getTariff();
             // Change status
             $client->status = $balance->sumatory < -$tariff->amount ? Clients::DISCONNECTED : Clients::INDEBTED;
             $client->save();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Edit action - edit the client
  *
  * @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]) && ($client = Clients::findFirst($params[0]))) {
         $tariffs = Tariffs::find(['status=:status:', 'bind' => ['status' => Tariffs::ACTIVE]]);
         if (!count($tariffs)) {
             $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the tariff first") . ': ' . $this->tag->linkTo('admin/tariffs/add', __('Add')));
         }
         // Set title, pick view and send variables
         $this->tag->setTitle(__('Clients') . ' / ' . __('Edit'));
         $this->view->pick('clients/write');
         $this->view->setVars(['tariffs' => $tariffs, 'status' => Clients::status(true)]);
         // Check if the form has been sent
         if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
             $client->__set('tariffs', $tariffs);
             $valid = $client->write('update');
             // Check if data are valid
             if ($valid instanceof Clients) {
                 $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 {
             // Values to fill out the form
             $this->tag->setDefaults(['fullName' => $client->fullName, 'address' => $client->address, 'tariff' => $client->tariff_id, 'description' => $client->description, 'status' => $client->status]);
         }
     } else {
         parent::notFoundAction();
     }
 }