From 7d724bdc9492ec75450da6c050931f83cc28809f Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Fri, 31 Jan 2025 11:43:58 +0300 Subject: [PATCH] [ERP-301] new payroll list --- erp24/actions/payroll/ListAdminsAction.php | 8 +- .../actions/payroll/ListShiftAdminsAction.php | 77 +++++++++++++++ erp24/controllers/PayrollController.php | 1 + erp24/forms/payroll/YearMonthSearchForm.php | 11 ++- erp24/views/payroll/list-admins.php | 9 +- erp24/views/payroll/list-shift-admins.php | 95 +++++++++++++++++++ erp24/web/js/payroll/list-shift-admins.js | 20 ++++ 7 files changed, 218 insertions(+), 3 deletions(-) create mode 100644 erp24/actions/payroll/ListShiftAdminsAction.php create mode 100644 erp24/views/payroll/list-shift-admins.php create mode 100644 erp24/web/js/payroll/list-shift-admins.js diff --git a/erp24/actions/payroll/ListAdminsAction.php b/erp24/actions/payroll/ListAdminsAction.php index 1c1f9554..78142921 100755 --- a/erp24/actions/payroll/ListAdminsAction.php +++ b/erp24/actions/payroll/ListAdminsAction.php @@ -111,6 +111,8 @@ class ListAdminsAction extends Action $adminPayrollQuery = AdminPayroll::find() ->andWhere(['admin_payroll.date' => $yearSelect . '-' . $monthWithZeroSelect]) + ->andFilterWhere(['admin.group_id' => $yearMonthSearchForm->admin_group_id > 0 ? $yearMonthSearchForm->admin_group_id : null]) + ->andFilterWhere(['like', 'admin.name_full', '%' . $yearMonthSearchForm->admin_name . '%', false]) ->with('admin') ->with('store') ->leftJoin('admin','admin_payroll.admin_id = admin.id') @@ -260,6 +262,9 @@ class ListAdminsAction extends Action $dateFromMonth = date('m', strtotime($dateFrom)); $dateFromYear = date('Y', strtotime($dateFrom)); + $adminGroups = ArrayHelper::map(\yii_app\records\AdminGroup::find()->all(), 'id', 'name'); + $adminGroups = [0 => 'Не выбрано'] + $adminGroups; + return $this->controller->render('/payroll/list-admins', [ 'payrollStore' => $adminPayroll, 'payrollStoreColumn' => $payrollStoreColumn, @@ -275,6 +280,7 @@ class ListAdminsAction extends Action 'sumColumnByAlias' => $sumColumnByAlias, 'monthNameSelect' => $monthNameSelect, 'lastPacketDate' => $lastPacketDate, + 'adminGroups' => $adminGroups, ]); } -} \ No newline at end of file +} diff --git a/erp24/actions/payroll/ListShiftAdminsAction.php b/erp24/actions/payroll/ListShiftAdminsAction.php new file mode 100644 index 00000000..21725135 --- /dev/null +++ b/erp24/actions/payroll/ListShiftAdminsAction.php @@ -0,0 +1,77 @@ + date("Y-m", strtotime("-3 month", time())), + 'month_end' => date('Y-m'), + 'admin_group_id' => 0, + ],[ + [['month_start', 'month_end', 'admin_group_id'], 'safe'] + ]); + + $model->load(Yii::$app->request->get()); + + $adminGroups = ArrayHelper::map(AdminGroup::find()->where(['id' => Admin::ADMIN_CABINET_GROUP_IDS])->all(), 'id', 'name'); + $adminGroups = [0 => 'Должность'] + $adminGroups; + + $adminPayrollQuery = AdminPayroll::find() + ->andWhere(['between', 'admin_payroll.date', $model->month_start, $model->month_end]) + ->andFilterWhere(['admin.group_id' => $model->admin_group_id > 0 ? $model->admin_group_id : null]) + ->with('admin') + ->with('store') + ->leftJoin('admin','admin_payroll.admin_id = admin.id') + ->orderBy(['admin.name_full' => SORT_ASC]) + ; + $adminPayroll = $adminPayrollQuery -> asArray()->all(); + + $aliasSumFields = [ + 'oklad', // Оклад + 'worksDayByTableFromSelectDay', // Число смен в графике + 'allTotalPayroll', // ЗП + ]; + + $payrollStoreColumn = []; + + $adminPayrollValuesDict = AdminPayrollValuesDict::find() + ->select(['alias', 'id', 'name']) + ->indexBy('alias') + ->asArray() + ->all(); + + foreach ($adminPayroll as $key => $rowAdmins) { + $payrollIds = $rowAdmins['id']; + $adminIdRow = $rowAdmins['admin_id']; + foreach ($aliasSumFields as $keyAlias => $alias) { + if (isset($adminPayrollValuesDict[$alias])) { + $keyRow = $alias.'.id'; + $keyAliasNameRow = $alias.'.name'; + $adminPayrollValuesId = ArrayHelper::getValue($adminPayrollValuesDict, $keyRow); + $aliasNameRow = ArrayHelper::getValue($adminPayrollValuesDict, $keyAliasNameRow); + $sumRow = AdminPayrollValues::getSumByAlias($adminPayrollValuesId, $payrollIds); + $adminPayroll[$key]['column'][$aliasNameRow] = $sumRow; +// var_dump($adminPayroll[$key]['column']); + $payrollStoreColumn[$aliasNameRow] = $aliasNameRow; + $sumColumnByAlias[$keyAlias] = ($sumColumnByAlias[$keyAlias] ?? 0) + ($sumRow ?? 0); + } + } + } +//die; +// echo "
"; var_dump($adminPayroll); die;
+
+        return $this->controller->render('list-shift-admins', compact('model', 'adminGroups', 'adminPayroll'));
+    }
+}
\ No newline at end of file
diff --git a/erp24/controllers/PayrollController.php b/erp24/controllers/PayrollController.php
index fc9d12ea..c882c938 100755
--- a/erp24/controllers/PayrollController.php
+++ b/erp24/controllers/PayrollController.php
@@ -19,6 +19,7 @@ class PayrollController extends \yii\web\Controller
             'make-payroll-days' => \yii_app\actions\payroll\MakePayrollDaysAction::class,
             'list' => \yii_app\actions\payroll\ListAction::class,
             'list-admins' => \yii_app\actions\payroll\ListAdminsAction::class,
+            'list-shift-admins' => \yii_app\actions\payroll\ListShiftAdminsAction::class,
         ];
     }
 
diff --git a/erp24/forms/payroll/YearMonthSearchForm.php b/erp24/forms/payroll/YearMonthSearchForm.php
index 3f40b524..22921057 100755
--- a/erp24/forms/payroll/YearMonthSearchForm.php
+++ b/erp24/forms/payroll/YearMonthSearchForm.php
@@ -12,12 +12,15 @@ class YearMonthSearchForm extends Model
     public string $dateFrom;
     public string $dateTo;
     public string $store_id;
+    public string $admin_name;
+    public int $admin_group_id;
 
     public function rules(): array
     {
         return [
-            [['year', 'month', 'dateFrom', 'dateTo', 'store_id'], 'string'],
+            [['year', 'month', 'dateFrom', 'dateTo', 'store_id', 'admin_name'], 'string'],
             [['year', 'month'], 'required'],
+            [['admin_group_id'], 'integer'],
         ];
     }
     public function __construct()
@@ -30,6 +33,10 @@ class YearMonthSearchForm extends Model
         $this->year = date("Y", strtotime(date("Y-m-d",time()) . $modifier));
 
         $this->month = date("m", strtotime(date("Y-m-d",time()) . $modifier));
+
+        $this->admin_name = '';
+
+        $this->admin_group_id = 0;
     }
 
 
@@ -40,6 +47,8 @@ class YearMonthSearchForm extends Model
             'month' => 'Месяц',
             'dateFrom' => 'dateFrom',
             'store_id' => 'Магазин',
+            'admin_name' => 'Фрагмент ФИО',
+            'admin_group_id' => 'Должность'
         ];
     }
 
diff --git a/erp24/views/payroll/list-admins.php b/erp24/views/payroll/list-admins.php
index 4d595ce1..fdd9c5cb 100755
--- a/erp24/views/payroll/list-admins.php
+++ b/erp24/views/payroll/list-admins.php
@@ -24,7 +24,7 @@ use yii_app\helpers\HtmlHelper;
 /* @var $lastPacketDate string */
 /* @var $allowedPayrollUpdate bool */
 /* @var $yearMonthSearchForm yii_app\forms\payroll\YearMonthSearchForm */
-
+/* @var $adminGroups array */
 
 $this->title = 'Зарплаты за ' . $monthNameSelect . '  сотрудников';
 $this->params['breadcrumbs'][] = $this->title;
@@ -81,6 +81,13 @@ $this->params['breadcrumbs'][] = $this->title;
                     );
                 ?>
             
+            
+ field($yearMonthSearchForm, 'admin_name')->textInput()->label(false) ?> +
+
+ field($yearMonthSearchForm, 'admin_group_id') + ->dropDownList($adminGroups)->label(false) ?> +
'btn btn-primary']); diff --git a/erp24/views/payroll/list-shift-admins.php b/erp24/views/payroll/list-shift-admins.php new file mode 100644 index 00000000..7bc4b455 --- /dev/null +++ b/erp24/views/payroll/list-shift-admins.php @@ -0,0 +1,95 @@ +registerJsFile('/js/xlsx.full.min.js', ['position' => \yii\web\View::POS_END]); +$this->registerJsFile('/js/payroll/list-shift-admins.js', ['position' => \yii\web\View::POS_END]); + +?> + +
+ + 'GET', + 'action' => '/payroll/list-shift-admins' + ]) ?> + +
+
+ field($model, 'month_start')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m', + 'todayBtn' => true + ], + ])->label(false) ?> +
+
+ field($model, 'month_end')->widget(DateTimePicker::class, [ + 'language' => 'ru', + 'template' => '{input}', + 'clientOptions' => [ + 'autoclose' => true, + 'format' => 'Y-m', + 'todayBtn' => true + ], + ])->label(false) ?> +
+
+ field($model, 'admin_group_id') + ->dropDownList($adminGroups)->label(false) ?> +
+
+ 'btn btn-secondary'])?> +
+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
№idФиоМагазинДолжностьОкладСменаКоличество сменЗарплата сотрудника
Дневная
+
+ +
diff --git a/erp24/web/js/payroll/list-shift-admins.js b/erp24/web/js/payroll/list-shift-admins.js new file mode 100644 index 00000000..547139be --- /dev/null +++ b/erp24/web/js/payroll/list-shift-admins.js @@ -0,0 +1,20 @@ +/* jshint esversion: 6 */ + +function htmlTableToExcel(){ + const type = 'xlsx' + var data = document.getElementById('listShiftAdmins'); + var excelFile = XLSX.utils.table_to_book(data, {sheet: "sheet1"}); + XLSX.write(excelFile, { bookType: type, bookSST: true, type: 'base64' }); + moment.locale('ru'); + XLSX.writeFile(excelFile, 'PayrollTable_' + moment().format('L') + '.' + type); +} + + +$(document).ready(() => { + $("#listShiftAdmins").DataTable({ + info: false, + paging: false, + searching: true, + language: data_table_language + }); +}); \ No newline at end of file -- 2.39.5