]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-301] new payroll list
authorAlexander Smirnov <fredeom@mail.ru>
Fri, 31 Jan 2025 08:43:58 +0000 (11:43 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Fri, 31 Jan 2025 08:43:58 +0000 (11:43 +0300)
erp24/actions/payroll/ListAdminsAction.php
erp24/actions/payroll/ListShiftAdminsAction.php [new file with mode: 0644]
erp24/controllers/PayrollController.php
erp24/forms/payroll/YearMonthSearchForm.php
erp24/views/payroll/list-admins.php
erp24/views/payroll/list-shift-admins.php [new file with mode: 0644]
erp24/web/js/payroll/list-shift-admins.js [new file with mode: 0644]

index 1c1f955480fa0d8f51ae26badffceff44599bd22..78142921ca306e74340215e1706bf30cc85e0da0 100755 (executable)
@@ -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 (file)
index 0000000..2172513
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+namespace yii_app\actions\payroll;
+
+use Yii;
+use yii\base\Action;
+use yii\base\DynamicModel;
+use yii\helpers\ArrayHelper;
+use yii_app\records\Admin;
+use yii_app\records\AdminPayroll;
+use yii_app\records\AdminGroup;
+use yii_app\records\AdminPayrollValues;
+use yii_app\records\AdminPayrollValuesDict;
+
+class ListShiftAdminsAction extends Action
+{
+    public function run() {
+        $model = DynamicModel::validateData([
+            'month_start' => 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 "<pre>"; var_dump($adminPayroll); die;
+
+        return $this->controller->render('list-shift-admins', compact('model', 'adminGroups', 'adminPayroll'));
+    }
+}
\ No newline at end of file
index fc9d12eaefd60eb683b37420c2b84702b9840c58..c882c938b0c324d57145ac6c0e900f7d75a3481e 100755 (executable)
@@ -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,
         ];
     }
 
index 3f40b52404318f1e5a7e27ddcd71bd60cc2f6305..22921057e584852f7555eb123e197d314033e9e5 100755 (executable)
@@ -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' => 'Должность'
         ];
     }
 
index 4d595ce1b054138888b2f3445525ce3646f5be43..fdd9c5cbf5f536fb0a131f770fdc59447bc1c334 100755 (executable)
@@ -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;
                     );
                 ?>
             </div>
+            <div class="col">
+                <?= $form->field($yearMonthSearchForm, 'admin_name')->textInput()->label(false) ?>
+            </div>
+            <div class="col">
+                <?= $form->field($yearMonthSearchForm, 'admin_group_id')
+                    ->dropDownList($adminGroups)->label(false) ?>
+            </div>
             <div class="col"><?php
 
                 echo Html::submitButton('Применить', ['class' => '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 (file)
index 0000000..7bc4b45
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+use yii\base\DynamicModel;
+
+use dosamigos\datetimepicker\DateTimePicker;
+
+/* @var $model DynamicModel */
+/* @var $adminGroups array */
+/* @var $adminPayroll array */
+
+$this->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]);
+
+?>
+
+<div class="payrollListShiftAdmins m-5">
+
+    <?php $form = ActiveForm::begin([
+        'method' => 'GET',
+        'action' => '/payroll/list-shift-admins'
+    ]) ?>
+
+    <div class="row">
+        <div class="col-2">
+            <?= $form->field($model, 'month_start')->widget(DateTimePicker::class, [
+                    'language' => 'ru',
+                    'template' => '{input}',
+                    'clientOptions' => [
+                        'autoclose' => true,
+                        'format' => 'Y-m',
+                        'todayBtn' => true
+                    ],
+                ])->label(false) ?>
+        </div>
+        <div class="col-2">
+            <?= $form->field($model, 'month_end')->widget(DateTimePicker::class, [
+                'language' => 'ru',
+                'template' => '{input}',
+                'clientOptions' => [
+                    'autoclose' => true,
+                    'format' => 'Y-m',
+                    'todayBtn' => true
+                ],
+            ])->label(false) ?>
+        </div>
+        <div class="col-2">
+            <?= $form->field($model, 'admin_group_id')
+                ->dropDownList($adminGroups)->label(false) ?>
+        </div>
+        <div class="col-2">
+            <?= Html::submitButton('Применить', ['class' => 'btn btn-secondary'])?>
+        </div>
+    </div>
+
+    <?php ActiveForm::end() ?>
+
+    <button id="button" class="btn btn-success mt-5" onclick="htmlTableToExcel()">Экспортировать таблицу в EXCEL</button>
+
+    <div class="table-responsive">
+        <table id="listShiftAdmins">
+            <thead>
+                <tr>
+                    <th>№</th>
+                    <th>id</th>
+                    <th>Фио</th>
+                    <th>Магазин</th>
+                    <th>Должность</th>
+                    <th>Оклад</th>
+                    <th>Смена</th>
+                    <th>Количество смен</th>
+                    <th>Зарплата сотрудника</th>
+                </tr>
+            </thead>
+            <tbody>
+                <?php $num = 0 ?>
+                <?php foreach ($adminPayroll as $apr): ?>
+                    <tr>
+                        <td><?=++$num?></td>
+                        <td><?= $apr['admin_id'] ?></td>
+                        <td><?= $apr['admin']['name_full'] ?></td>
+                        <td><?= $apr['store']['name'] ?></td>
+                        <td><?= $apr['admin']['group_name'] ?></td>
+                        <td><?= $apr['column']['Оклад'] ?></td>
+                        <td>Дневная</td>
+                        <td><?= $apr['column']['Число смен в графике'] ?></td>
+                        <td><?= $apr['column']['Зарплата сотрудника'] ?></td>
+                    </tr>
+                <?php endforeach; ?>
+            </tbody>
+        </table>
+    </div>
+
+</div>
diff --git a/erp24/web/js/payroll/list-shift-admins.js b/erp24/web/js/payroll/list-shift-admins.js
new file mode 100644 (file)
index 0000000..547139b
--- /dev/null
@@ -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