bd calendar and salary sum

This commit is contained in:
akosse 2020-01-17 16:28:25 +03:00
parent 88b0b13a2a
commit 188758c79c
15 changed files with 221 additions and 8 deletions

View File

@ -15,6 +15,7 @@ class AppAsset extends AssetBundle
'css/site.css',
];
public $js = [
'js/site.js',
];
public $depends = [
'yii\web\YiiAsset',

View File

@ -41,6 +41,9 @@ return [
'notes' => [
'class' => 'backend\modules\notes\Notes',
],
'calendar' => [
'class' => 'backend\modules\calendar\Calendar',
],
],
'components' => [
'request' => [

View File

@ -4,6 +4,7 @@
namespace app\modules\accesses\models;
use common\classes\Debug;
use common\models\FieldsValueNew;
use Yii;
/**
@ -17,5 +18,73 @@ use Yii;
class Accesses extends \common\models\Accesses
{
public $fields;
public function init()
{
parent::init();
$fieldValue = FieldsValueNew::find()->where(
[
'item_id' => \Yii::$app->request->get('id'),
'item_type' => FieldsValueNew::TYPE_ACCESS,
]
)
->all();
$array = [];
if (!empty($fieldValue)) {
foreach ($fieldValue as $item) {
array_push(
$array,
[
'field_id' => $item->field_id,
'value' => $item->value,
'order' => $item->order,
'type_file' => $item->type_file,
'field_name' => $item->field->name
]
);
}
$this->fields = $array;
} else {
$this->fields = [
[
'field_id' => null,
'value' => null,
'order' => null,
'field_name' => null,
'type_file' => null,
],
];
}
}
public function afterSave($insert, $changedAttributes)
{
$post = \Yii::$app->request->post('Aceesses');
if ($post['fields']) {
FieldsValueNew::deleteAll(['item_id' => $this->id, 'item_type' => FieldsValueNew::TYPE_ACCESS]);
foreach ($post['fields'] as $item) {
$item['value'] = urldecode($item['value']);
$fieldsValue = new FieldsValueNew();
$fieldsValue->field_id = $item['field_id'];
$fieldsValue->value = $item['value'];
$fieldsValue->order = $item['order'];
$fieldsValue->item_id = $this->id;
$fieldsValue->item_type = FieldsValueNew::TYPE_ACCESS;
if (is_file(Yii::getAlias('@frontend') . '/web/' . $item['value'])) {
$fieldsValue->type_file = 'file';
} else {
$fieldsValue->type_file = 'text';
}
$fieldsValue->save();
}
}
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
}
}

View File

@ -1,5 +1,7 @@
<?php
use mihaildev\elfinder\InputFile;
use unclead\multipleinput\MultipleInput;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use kartik\select2\Select2;
@ -34,7 +36,6 @@ use kartik\select2\Select2;
</div>
</div>
<div class="row">
<div class="col-xs-12">
<text>Пользователи</text>

View File

@ -0,0 +1,24 @@
<?php
namespace backend\modules\calendar;
/**
* calendar module definition class
*/
class Calendar extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'backend\modules\calendar\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,46 @@
<?php
namespace backend\modules\calendar\controllers;
use backend\modules\card\models\UserCardSearch;
use common\classes\Debug;
use Yii;
use yii\data\ArrayDataProvider;
use yii\web\Controller;
/**
* Default controller for the `calendar` module
*/
class CalendarController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
$searchModel = new UserCardSearch();
$user_card = \common\models\UserCard::find()->all();
$user_array = array();
try {
if($_GET['month'] == 00)
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
else {
foreach ($user_card as $value) {
if (substr(substr($value->dob, 5), 0, 2) == $_GET['month'])
array_push($user_array, $value);
}
$dataProvider = new ArrayDataProvider([
'allModels' => $user_array,
]);
}
} catch (\Exception $e) {
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
}
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
}

View File

@ -0,0 +1,42 @@
<div class="calendar-default-index">
<p>
<select id="options" class="btn btn-secondary dropdown-toggle">
<option selected="selected">Выберите месяц</option>
<option value="?month=00">Показать все</option>
<option value="?month=01">январь</option>
<option value="?month=02">февраль</option>
<option value="?month=03">март</option>
<option value="?month=04">апрель</option>
<option value="?month=05">май</option>
<option value="?month=06">июнь</option>
<option value="?month=07">июль</option>
<option value="?month=08">август</option>
<option value="?month=09">сентябрь</option>
<option value="?month=10">октябрь</option>
<option value="?month=11">ноябрь</option>
<option value="?month=12">декабрь</option>
</select>
</p>
<?php
/* @var $searchModel backend\modules\card\models\UserCardSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
use yii\grid\GridView;
use yii\widgets\Pjax;
Pjax::begin(['id' => 'reload']);
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'fio',
'dob',
['class' => 'yii\grid\ActionColumn'],
],
]);
Pjax::end();
?>

View File

@ -47,9 +47,21 @@ class UserCardController extends Controller
$searchModel = new UserCardSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$total = 0;
if(Yii::$app->request->queryParams)
foreach (Yii::$app->request->queryParams as $params)
$total = \common\models\UserCard::find()->filterWhere([
'fio' => $params['fio'],
'email' => $params['email'],
'status' => $params['status'],
'skills' => $params['skills'],
])->sum('salary');
else $total = \common\models\UserCard::find()->sum('salary');
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'total' => $total,
]);
}

View File

@ -105,7 +105,7 @@ class UserCard extends \common\models\UserCard
parent::afterSave($insert, $changedAttributes); // TODO: Change the autogenerated stub
}
public function generateUser($email, $status)
public static function generateUser($email, $status)
{
$user = new User();
$auth_key = Yii::$app->security->generateRandomString();
@ -121,18 +121,18 @@ class UserCard extends \common\models\UserCard
$user->save();
$log = "Логин: " . $email . " Пароль: " . $password . " | ";
file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
//file_put_contents("log.txt", $log, FILE_APPEND | LOCK_EX);
return $user->id;
}
public function genereateLinlkOnUser($user_card, $user_id)
public static function genereateLinlkOnUser($user_card, $user_id)
{
$user_card->id_user = $user_id;
$user_card->save();
}
public function generateUserForUserCard($card_id = null)
public static function generateUserForUserCard($card_id = null)
{
$userCardQuery = UserCard::find();
$card_id ? $userCardQuery->where(['id' => $card_id]) : $userCardQuery->where(['id_user' => NULL]);

View File

@ -8,6 +8,7 @@ use yii\widgets\ListView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\card\models\UserCardSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $total */
$this->title = 'Профили';
$this->params['breadcrumbs'][] = $this->title;
@ -19,7 +20,8 @@ $this->params['breadcrumbs'][] = $this->title;
<?= Html::a('Сгенерировать пользователей', ['generate'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
<?php
echo GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
@ -83,5 +85,7 @@ $this->params['breadcrumbs'][] = $this->title;
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
]);
echo "<h3>Сумма зарплат: " . $total . "</h3>";
?>
</div>

View File

@ -47,6 +47,7 @@
['label' => 'Отпуска', 'icon' => 'plane', 'url' => ['/holiday/holiday'], 'active' => \Yii::$app->controller->id == 'holiday'],
['label' => 'Доступы', 'icon' => 'key', 'url' => ['/accesses/accesses'], 'active' => \Yii::$app->controller->id == 'accesses'],
['label' => 'Заметки', 'icon' => 'sticky-note', 'url' => ['/notes/notes'], 'active' => \Yii::$app->controller->id == 'notes'],
['label' => 'Календарь ДР', 'icon' => 'calendar', 'url' => ['/calendar/calendar'], 'active' => \Yii::$app->controller->id == 'calendar'],
/*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],
['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug']],

7
backend/web/js/site.js Normal file
View File

@ -0,0 +1,7 @@
$(function(){
$('#options').change(function(){
month = $('#options :selected').val();
history.pushState({}, '', month);
$.pjax.reload({container:"#reload"});
})
});

View File

@ -26,6 +26,7 @@ class FieldsValueNew extends \yii\db\ActiveRecord
const TYPE_COMPANY = 2;
const TYPE_BALANCE = 3;
const TYPE_NOTE = 4;
const TYPE_ACCESS = 5;
/**
* {@inheritdoc}

View File

@ -23,6 +23,7 @@ class UseField extends \yii\db\ActiveRecord
const USE_COMPANY = 2;
const USE_BALANCE = 3;
const USE_NOTE = 4;
const USE_ACCESS = 5;
/**
@ -72,7 +73,8 @@ class UseField extends \yii\db\ActiveRecord
self::USE_PROJECT => 'Проект',
self::USE_COMPANY => 'Компания',
self::USE_BALANCE => 'Баланс',
self::USE_NOTE => 'Заметка'
self::USE_NOTE => 'Заметка',
self::USE_ACCESS => 'Доступ'
];
}

0
frontend/web/log.txt Executable file
View File