reports extract

This commit is contained in:
2024-04-03 18:31:17 +03:00
parent 28f9f3a87e
commit a27c8a933e
7 changed files with 734 additions and 65 deletions

View File

@ -3,6 +3,9 @@
namespace backend\modules\reports\controllers;
use backend\modules\card\models\UserCardSearch;
use backend\modules\reports\models\ExtractForm;
use common\classes\Debug;
use common\models\ReportsTask;
use Yii;
use common\models\Reports;
use backend\modules\reports\models\ReportsSearch;
@ -58,7 +61,7 @@ class ReportsController extends Controller
return Reports::getFio($report);
}
],
]),'user_card_id', 'fio');
]), 'user_card_id', 'fio');
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index');
@ -74,7 +77,7 @@ class ReportsController extends Controller
return Reports::getFio($report);
}
],
]),'user_card_id', 'fio');
]), 'user_card_id', 'fio');
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('list', [
@ -110,8 +113,8 @@ class ReportsController extends Controller
],
]);
if (!$dataProvider->getCount()){
return $this->render('non-exist_user_id', ['id' => $user_id]);
if (!$dataProvider->getCount()) {
return $this->render('non-exist_user_id', ['id' => $user_id]);
}
return $this->render('calendarOneUser', [
'reports' => $reports_array,
@ -199,6 +202,44 @@ class ReportsController extends Controller
return $this->redirect(['index']);
}
public function actionExtractForm(): string
{
$model = new ExtractForm();
return $this->render('extract-form', ['model' => $model]);
}
public function actionExtract()
{
$model = new ExtractForm();
if ($model->load(Yii::$app->request->post())) {
$query = ReportsTask::find()->joinWith('reports')
->where(['reports.user_id' => $model->user_id])
->andWhere(['between', 'reports.created_at', $model->date_from, $model->date_to]);
$file = \Yii::createObject([
'class' => 'codemix\excelexport\ExcelFile',
'sheets' => [
'Reports' => [
'class' => 'codemix\excelexport\ActiveExcelSheet',
'query' => $query,
'attributes' => [
'reports.created_at',
'task',
'hours_spent'
],
]
]
]);
$file->send('reports.xlsx');
} else {
return $this->render('extract-form', ['model' => $model]);
}
}
/**
* Finds the Reports model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.

View File

@ -0,0 +1,29 @@
<?php
namespace backend\modules\reports\models;
class ExtractForm extends \yii\base\Model
{
public $user_id;
public $date_from;
public $date_to;
public function rules()
{
return [
[['date_from', 'date_to', 'user_id'], 'required'],
[['date_from', 'date_to'], 'safe'],
[['user_id'], 'integer'],
];
}
public function attributeLabels()
{
return [
'user_id' => 'Пользователь',
'date_from' => 'Дата начала',
'date_to' => 'Дата окончания',
];
}
}

View File

@ -0,0 +1,42 @@
<?php
use kartik\date\DatePicker;
use kartik\select2\Select2;
use unclead\multipleinput\MultipleInput;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $model \backend\modules\reports\models\ExtractForm */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="reports-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'user_id')->widget(
Select2::class,
[
'data' => \common\models\UserCard::getListUserWithUserId(),
'options' => ['placeholder' => '...', 'class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<?= $form->field($model, 'date_from')->textInput(['type' => 'date']) ?>
<?= $form->field($model, 'date_to')->textInput(['type' => 'date']) ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>