BiFace_Server_Lite/controllers/CaptureLogsController.php
2021-08-23 15:19:49 +07:00

121 lines
3.9 KiB
PHP

<?php
namespace app\controllers;
use Yii;
use app\models\CaptureLogs;
use app\models\CaptureLogsSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\ListManagement;
/**
* CaptureLogsController implements the CRUD actions for CaptureLogs model.
*/
class CaptureLogsController extends Controller {
public function init() {
parent::init();
Yii::$app->language = Yii::$app->session->get("language") ? Yii::$app->session->get("language")["name"] : "vi-VI";
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionIndex($from = "", $to = "", $all = false) {
$f = date_format(date_create_from_format('H:i d/m/Y', "00:00 " . date("d/m/Y")), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', "23:59 " . date("d/m/Y")), 'U');
if ($from !== "" && $to !== "") {
$f = date_format(date_create_from_format('H:i d/m/Y', $from), 'U');
$t = date_format(date_create_from_format('H:i d/m/Y', $to), 'U');
}
$this->view->title = Yii::t("app", "LICH_SU_HE_THONG");
$searchModel = new CaptureLogsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
if (!$all)
$dataProvider->query->andWhere(["capture_logs.staff_id" => 0]);
$dataProvider->query->andWhere(["BETWEEN", "capture_logs.time", $f, $t]);
// $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
// 'http' => [
// 'header' => "Content-Type: application/json",
// 'method' => "POST"
// ]
// ])), true);
// $data = json_decode($tempConfig['data'], true);
// $last = \app\models\ListManagement::find()->orderBy(['id' => SORT_DESC])->limit(1)->one();
// if (!is_object($last))
// $last = (object) ['id' => 0];
// $idAuto = $data['data']['box_id'] . "_" . ($last->id + 1);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'statusArray' => CaptureLogs::$statusArray,
'f' => $f,
't' => $t,
// 'idAuto' => $idAuto,
"staffArray" => ListManagement::staffArray(),
"typeArray" => ListManagement::typeArray(),
"genderArray" => ListManagement::genderArray(),
]);
}
public function actionView($id) {
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
public function actionCreate() {
$model = new CaptureLogs();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
public function actionUpdate($id) {
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
public function actionDelete($id) {
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
protected function findModel($id) {
if (($model = CaptureLogs::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException(Yii::t("app", "KHONG_TIM_THAY_THONG_TIN"));
}
}