/** * 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'])]); }
/** * 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'])]); } }
/** * 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(); } } }