public function actionRemoveDevice()
 {
     while (1) {
         $deviceModel = Devices::find()->all();
         foreach ($deviceModel as $device) {
             $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
             if (empty($deviceLogs)) {
                 $device->status = 0;
                 $device->server_id = NULL;
                 if ($device->save()) {
                     echo "Device with id " . $device->controller_id . " Successfully offlined \n";
                 } else {
                     print_r($device);
                 }
             } else {
                 $deviceTime = date("Y-m-d H:i:s", strtotime($deviceLogs->created . " +1 minute"));
                 if (strtotime($deviceTime) < strtotime(date("Y-m-d H:i:s"))) {
                     $device->status = 0;
                     $device->server_id = NULL;
                     if ($device->save()) {
                         echo date("Y-m-d H:i:s", strtotime($deviceTime)) . " = " . date("Y-m-d H:i:s") . "\n";
                         echo "Device with id " . $device->controller_id . " Successfully offlined \n";
                     } else {
                         print_r($device->getErrors());
                     }
                 } else {
                     echo "Device with id " . $device->controller_id . " is Online. \n";
                 }
             }
         }
         sleep(10);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Devices::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'region_id' => $this->region_id, 'controller_id' => $this->controller_id, 'type' => $this->type, 'created' => $this->created]);
     $query->andFilterWhere(['like', 'latitude', $this->latitude])->andFilterWhere(['like', 'longitude', $this->longitude])->andFilterWhere(['like', 'sim_number', $this->sim_number])->andFilterWhere(['like', 'imei_number', $this->imei_number])->andFilterWhere(['like', 'contact_1_name', $this->contact_1_name])->andFilterWhere(['like', 'contact__1_phone', $this->contact__1_phone])->andFilterWhere(['like', 'contact_1_email', $this->contact_1_email])->andFilterWhere(['like', 'contact_2_name', $this->contact_2_name])->andFilterWhere(['like', 'contact_2_phone', $this->contact_2_phone])->andFilterWhere(['like', 'contact_2_email', $this->contact_2_email]);
     return $dataProvider;
 }
Ejemplo n.º 3
0
 /**
  *
  * @return string
  */
 public function actionAindex()
 {
     $count = Devices::find()->count();
     //        $query = (new Query())
     //            ->select('title, type_id, COUNT(devices.id) as count')
     //            ->from('device_type, devices')
     //            ->where('type_id = device_type.id')
     //            ->groupBy('type_id, title')
     //            ->orderBy('title');
     //
     //        $dp = new ActiveDataProvider([
     //            'query' => $query,
     //        ]);
     $searchModel = new ReportsSearch();
     $dp = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('a_index', ['count' => $count, 'sm' => $searchModel, 'dp' => $dp]);
 }
 /**
  * Добавление строки в табличную часть документа Акт списания.
  *
  * @param integer $id идентификатор устройсва
  * @param string $param параметры УРЛ
  * @return mixed
  */
 public function actionCreate($id, $param)
 {
     parse_str($param, $arr);
     $model = new DtDefsheetDevices();
     $device = Devices::findOne($id);
     if ($device->workplace_id != 1) {
         Yii::$app->session->setFlash('error', 'Устройство должно находится на Складе ОИ');
         return $this->redirect(['dt-defsheets/view', 'id' => $arr['target_id']]);
     }
     //var_dump($arr);
     $model->dt_defsheets_id = $arr['target_id'];
     $model->devices_id = $id;
     //if ($model->load(Yii::$app->request->post()) && $model->save()) {
     if ($model->save()) {
         return $this->redirect(['dt-defsheets/view', 'id' => $arr['target_id']]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 5
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $id_wp = 0, $id = 0)
 {
     if ($id > 0) {
         $query = Devices::find()->where(['parent_device_id' => $id]);
     } elseif ($id_wp > 0) {
         $query = Devices::find()->where(['workplace_id' => $id_wp]);
     } else {
         $query = Devices::find()->select(['id' => 'd.id', 'dt_title' => 'device_type.title', 'dev_comp' => 'device_type.comp', 'brand' => 'd.brand', 'model' => 'd.model', 'sn' => 'd.sn', 'specification' => 'd.specification', 'imei1' => 'd.imei1', 'parent_device_id' => 'd.parent_device_id', 'device_note' => 'd.device_note', 'workplace_id' => 'd.workplace_id', 'wp_title' => 'workplaces.workplaces_title', 'snp' => 'MAX(employees.snp)'])->from(['d' => 'devices'])->leftJoin('workplaces', 'workplaces.id = workplace_id')->leftJoin('device_type', 'device_type.id = type_id')->leftJoin('wp_owners', 'wp_owners.workplace_id = d.workplace_id')->leftJoin('employees', 'employees.id = wp_owners.employee_id')->groupBy('d.id, device_type.title, device_type.comp,	d.brand,' . 'd.model,	d.sn,	d.specification,	d.imei1,' . 'd.parent_device_id,	d.workplace_id,	workplaces.workplaces_title')->orderBy(['d.id' => SORT_DESC]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]], 'pagination' => false]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     //$query->joinWith('deviceType');
     $query->andFilterWhere(['d.id' => $this->id, 'd.workplace_id' => $this->workplace_id, 'device_type.comp' => $this->dev_comp]);
     $query->andFilterWhere(['like', 'LOWER(device_note)', mb_strtolower($this->device_note)])->andFilterWhere(['like', 'LOWER(device_type.title)', mb_strtolower($this->dt_title)])->andFilterWhere(['like', 'LOWER(brand)', mb_strtolower($this->brand)])->andFilterWhere(['like', 'LOWER(model)', mb_strtolower($this->model)])->andFilterWhere(['like', 'LOWER(sn)', mb_strtolower($this->sn)])->andFilterWhere(['like', 'LOWER(specification)', mb_strtolower($this->specification)])->andFilterWhere(['like', 'LOWER(imei1)', mb_strtolower($this->imei1)]);
     return $dataProvider;
 }
Ejemplo n.º 6
0
 /**
  * @param $id
  * @param $param
  * @return string|\yii\web\Response
  */
 public function actionCreate2($id, $param)
 {
     /* @var $device Devices */
     parse_str($param, $arr);
     $id_doc = $arr['id_doc'];
     $model = new DtEnquiryDevices();
     $device = Devices::findOne($id);
     $model->dt_enquiries_id = $id_doc;
     $model->type_id = $device->type_id;
     if ($device->parent_device_id) {
         $model->parent_device_id = $device->parent_device_id;
     }
     if ($model->save()) {
     } else {
         Yii::$app->session->setFlash('error', 'Ошибка при добавлении устройства');
     }
     if ($id_doc > 0) {
         return $this->redirect(['dt-enquiries/view', 'id' => $id_doc]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Finds the Devices model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Devices the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Devices::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Ejemplo n.º 8
0
 public static function arraySpecifications()
 {
     return Devices::find()->select('specification as value, specification as label, count(*) as count')->where("specification > ''")->groupBy('specification')->orderBy('count DESC')->asArray()->all();
 }
Ejemplo n.º 9
0
 public function getDevices()
 {
     return $this->hasOne(Devices::className(), ['id' => 'devices_id']);
 }
Ejemplo n.º 10
0
<?php

/**
 * User: ivan
 * Date: 09.02.2016
 * Time: 12:31
 *
 * @var $this yii\web\View
 * @var $dp yii\data\ActiveDataProvider
 */
use yii\grid\GridView;
use yii\helpers\Html;
use yii\grid\Column;
use backend\models\Devices;
$this->title = '' . $title;
$this->params['breadcrumbs'][] = ['label' => 'Отчет', 'url' => ['reports/aindex']];
$this->params['breadcrumbs'][] = $this->title;
echo 'Отчет по устройству';
echo '<h1>' . $title . '</h1>';
echo GridView::widget(['dataProvider' => $dp, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'branch_id', 'label' => 'Подразделение'], ['attribute' => 'workplaces_title', 'label' => 'Рабочее место', 'value' => function ($dp) {
    return Html::a($dp['workplaces_title'], ['workplaces/view', 'id' => $dp['workplace_id']]);
}, 'format' => 'raw'], ['class' => Column::className(), 'header' => 'Кол-во', 'content' => function ($dp) use($type_id) {
    return Devices::getCountOnWp($type_id, $dp['workplace_id']);
}], ['attribute' => 'snp', 'label' => 'Ответственное лицо'], ['attribute' => 'job_title', 'label' => 'Должность'], ['attribute' => 'date', 'label' => 'Дата']]]);
Ejemplo n.º 11
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\models\Devices;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$this->title = 'Device Junk Data';
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="container-fluid">
    <div class="panel panel-primary">
        <div class="panel-heading">
            <h3 class="panel-title"><?php 
echo Html::encode($this->title);
?>
</h3>
        </div>
        <div class="panel-body pd-0" id="device-overview-container">
            <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'layout' => "{items}\n{pager}", 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'device_id', 'label' => 'Controller ID', 'value' => function ($row) {
    return Devices::find()->where(['id' => $row->device_id])->one()->controller_id;
}], ['attribute' => 'device_data', 'label' => 'Device Data'], ['attribute' => 'created', 'label' => 'Logging Time']]]);
?>
        </div>
    </div>
</div>
 public function actionDeviceOverview()
 {
     $deviceModel = Devices::find()->all();
     $this->layout = "dashboard";
     $response = array();
     foreach ($deviceModel as $device) {
         $temp = array();
         $deviceLogs = DeviceLogs::find()->where(['device_id' => $device->id])->orderBy(['id' => SORT_DESC])->one();
         $temp['id'] = $device->id;
         $temp['controller_id'] = $device->controller_id;
         $temp['sim_number'] = $device->sim_number;
         $temp['status'] = $device->status == 1 ? "Online" : "Offline";
         if (!empty($deviceLogs)) {
             $temp['current_voltage'] = $deviceLogs->current_voltage;
             $temp['current_load'] = isset($deviceLogs->current_load) ? $deviceLogs->current_load / 10 : $deviceLogs->current_load;
             $temp['voltage_status'] = Helper::voltageStatus($deviceLogs->voltage_status);
             $temp['light_status'] = Helper::lightStatus($deviceLogs->light_status);
             $temp['overload_status'] = Helper::overloadStatus($deviceLogs->overload_status);
             $temp['created'] = date("d-M-Y H:i:s", strtotime($deviceLogs->created));
         }
         $response[] = $temp;
     }
     $dataProvider = new ArrayDataProvider(['key' => 'id', 'allModels' => $response]);
     return $this->render('deviceOverview', ['dataProvider' => $dataProvider]);
 }
 public function decodeCommand($deviceId, $data)
 {
     $command_id = substr($data, 6, 2);
     $deviceModel = Devices::find()->where(['id' => $deviceId])->one();
     switch ($command_id) {
         case "01":
             break;
         case "03":
             break;
         case "02":
             $v1 = hexdec(substr($data, 8, 2));
             $v2 = hexdec(substr($data, 10, 2));
             $voltage = $v1 * 256 + $v2;
             $l1 = hexdec(substr($data, 14, 2));
             $l2 = hexdec(substr($data, 16, 2));
             $load = $l1 * 256 + $l2;
             $status = str_pad(base_convert(substr($data, 18, 2), 16, 2), 8, "0", STR_PAD_LEFT);
             $voltage_status = base_convert(substr($status, 0, 2), 2, 10);
             $light_status = base_convert(substr($status, 2, 2), 2, 10);
             $overload_staus = base_convert(substr($status, 4, 2), 2, 10);
             $deviceLogs = new DeviceLogs();
             $deviceLogs->region_id = $deviceModel->region_id;
             $deviceLogs->device_id = $deviceModel->id;
             $deviceLogs->current_voltage = $voltage;
             $deviceLogs->current_load = $load;
             $deviceLogs->voltage_status = $voltage_status;
             $deviceLogs->light_status = $light_status;
             $deviceLogs->overload_status = $overload_staus;
             if ($deviceLogs->save()) {
                 return true;
             } else {
                 echo "<pre>";
                 print_r($deviceLogs->getErrors());
                 return false;
             }
             break;
         case "04":
             break;
     }
 }
Ejemplo n.º 14
0
<?php

use yii\helpers\Html;
use yii\grid\GridView;
use backend\models\Devices;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\models\StorydeviceSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$moddev = Devices::findOne($id_dev);
$this->title = 'История изменений';
$this->params['breadcrumbs'][] = ['label' => 'Устройства', 'url' => Url::to(['devices/index'])];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="story-device-index">
    <h4> История изменений </h4>
    <h1><?php 
echo (isset($moddev->deviceType) ? $moddev->deviceType->title : '') . ' ' . $moddev->device_note;
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>



    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'id_device', 'id_wp', 'workplace.workplaces_title', 'date_up', 'event', ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Ejemplo n.º 15
0
 /**
  * Finds the Devices model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Devices the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Devices::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрашиваемой страницы не существует.');
     }
 }