]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-102 Приёмник для эксель файла (корректировка)
authormarina <m.zozirova@gmail.com>
Fri, 9 Aug 2024 01:37:38 +0000 (04:37 +0300)
committermarina <m.zozirova@gmail.com>
Fri, 9 Aug 2024 01:37:38 +0000 (04:37 +0300)
erp24/actions/motivation/IndexAction.php
erp24/records/Motivation.php
erp24/services/MotivationService.php
erp24/uploads/template_adjustment.xlsx [new file with mode: 0644]
erp24/views/motivation/index.php
erp24/web/js/motivation/index.js

index f745fa062253454a944aac23ccc3b4ceb772d390..74a6c22d8ebbed59a72f5f3255d35a293273931c 100644 (file)
@@ -9,6 +9,7 @@ use yii\base\Action;
 use yii\base\DynamicModel;
 use yii\helpers\ArrayHelper;
 use yii\web\UploadedFile;
+use yii_app\records\Admin;
 use yii_app\records\CityStore;
 use yii_app\records\Motivation;
 use yii_app\records\MotivationCostsItem;
@@ -29,10 +30,17 @@ class IndexAction extends Action
         if (Yii::$app->request->isPost) {
             $file = UploadedFile::getInstanceByName('myfile');
             if ($file) {
-                $path1 = Yii::getAlias('@uploads') . '/template_plan_temp.xlsx';
+                $adjustment = Yii::$app->request->post('adjustment');
+
+                if ($adjustment && array_key_exists(Admin::findOne(Yii::$app->user->id)->group_id, Motivation::getAdjustmentEditors())) {
+                return implode('<br>', 'Вы не можете вносить корректировку');
+                }
+
+                $fileName =  $adjustment ? '/template_adjustment_temp.xlsx' : '/template_plan_temp.xlsx';
+                $path1 = Yii::getAlias('@uploads') . $fileName;
                 $file->saveAs($path1);
 
-                $data = MotivationService::uploadTemplatePlan($path1);
+                $data = MotivationService::uploadTemplatePlan($path1, !$adjustment);
 
                 return implode('<br>', $data['errors']);
             } else {
index e843bd00fd99583eac94f3048066263252bcfed0..6002e5fb4ed9de970f1cfcc2d6aa7005758a74fc 100644 (file)
@@ -64,4 +64,11 @@ class Motivation extends \yii\db\ActiveRecord
             'created_at' => 'Created At',
         ];
     }
+
+    public static function getAdjustmentEditors() {
+        return array(
+            AdminGroup::GROUP_IT,
+            AdminGroup::GROUP_OPERATIONAL_DIRECTOR
+        );
+    }
 }
index 06e071aa8c8fedcbb9658b000d963de733d1dc08..932320bd53ee0a5d7b86d49939e0bd410acdd50a 100644 (file)
@@ -154,7 +154,7 @@ class MotivationService
         return $result;
     }
 
-    public static function uploadTemplatePlan($path)
+    public static function uploadTemplatePlan($path, $is_plan = true)
     {
         $motivationCostsItems = MotivationCostsItem::find()->indexBy('code')->all();
         try {
@@ -282,19 +282,20 @@ class MotivationService
                     . " Ожидается, например: '" . $motivationCostsItems[$keys[0]]->name . "'";
             }
             if (empty($error)) {
-                $motivationValueGroupPlan = MotivationValueGroup::find()->where(['alias' => 'plan'])->one();
-                /** @var $motivationValueGroupPlan MotivationValueGroup */
+                $alias = $is_plan ? 'plan' : 'adjustment';
+                $motivationValueGroup = MotivationValueGroup::find()->where(['alias' => $alias])->one();
+                /** @var $motivationValueGroup MotivationValueGroup */
                 foreach ($rows as $row) {
                     $motivationValue = MotivationValue::find()->where([
                         'motivation_id' => $motivation->id,
-                        'motivation_group_id' => $motivationValueGroupPlan->id,
+                        'motivation_group_id' => $motivationValueGroup->id,
                         'value_id' => $row[0]
                     ])->one();
                     /** @var $motivationValue MotivationValue */
                     if (!$motivationValue) {
                         $motivationValue = new MotivationValue;
                         $motivationValue->motivation_id = $motivation->id;
-                        $motivationValue->motivation_group_id = $motivationValueGroupPlan->id;
+                        $motivationValue->motivation_group_id = $motivationValueGroup->id;
                         $motivationValue->value_id = $row[0];
                     }
                     $motivationValue->value_type = $motivationCostsItems[$row[0]]->data_type;
diff --git a/erp24/uploads/template_adjustment.xlsx b/erp24/uploads/template_adjustment.xlsx
new file mode 100644 (file)
index 0000000..fb63fb9
Binary files /dev/null and b/erp24/uploads/template_adjustment.xlsx differ
index 38386efcadefcf479a0a223c760884edfa182d43..a42c6013c5cbd252b2aa78c92eaf01f2da480e06 100644 (file)
@@ -5,6 +5,8 @@ use kartik\select2\Select2;
 use yii\widgets\ActiveForm;
 use yii\base\DynamicModel;
 use kartik\grid\GridView;
+use yii_app\records\Admin;
+use yii_app\records\Motivation;
 use yii_app\records\MotivationCostsItem;
 /** @var $model DynamicModel */
 /** @var $stores array */
@@ -73,6 +75,14 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
                 <div class="mb-3"><?= Html::button('Загрузка плановых значений', ['class' => 'btn btn-success btn-sm',
                         'onclick' => 'openUploadDictionary();'])?></div>
             </div>
+            <div class="d-flex justify-content-around align-items-center gap-2">
+                <div class="mb-3"><?php
+                    if (array_key_exists(Admin::findOne(Yii::$app->user->id)->group_id, Motivation::getAdjustmentEditors())) {
+                        echo Html::button('Внесение корректировок', ['class' => 'btn btn-warning btn-sm btn-adjustment',
+                            'onclick' => 'openUploadDictionary("btn-adjustment");']);
+                    } ?>
+                </div>
+            </div>
         </div>
 
         <?php ActiveForm::end() ?>
index e7432015359f6cfdc3757e270fc5dde92297b7a0..db6b338f5cdad2e98a882d972d19d64fa63b862e 100644 (file)
@@ -1,31 +1,58 @@
-/* jshint esversion: 8 */
-
 const param10 = $("meta[name=csrf-param]").attr("content");
 const token10 = $("meta[name=csrf-token]").attr("content");
 
-/* jshint unused: false */
-function openUploadDictionary() {
-    'use strict'
+function openUploadDictionary(buttonType) {
+    'use strict';
     const $mainModal = $('#mainModal');
     const $modalBody = $mainModal.find('.modal-body');
-    const $modalFooter = $mainModal.find('.modal-footer');
+    const $modalTitle = $mainModal.find('.modal-title');
+
     $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); });
-    $mainModal.find('.modal-title').html('Загрузка плановых значений');
-    $modalFooter.html('');
-    $modalBody.html('<div class="row"><div class="col-12">'
-                   + '<form class="d-flex justify-content-left align-items-center" enctype="multipart/form-data">'
-                   + '<div class="d-none"><input type="file" name="myfile" accept=".xlsx"/></div>'
-                   + '<div><input class="btn btn-success btn-sm" type="submit" value="Загрузить" /></div></form></div></div>'
-                   + '<div class="row mt-2"><div class="col-12" id="infoModal"></div></div>'
-                   + '<div class="row mt-2"><div class="col-12 border-2 bg-gray-200"></div></div>'
-                   + '<div class="row mt-5"><div class="col-12" style="font-size: 1rem;">Скачать шаблон</div></div>'
-                   + '<div class="row mt-2"><div class="col-12">'
-                   + '<a href="/files/download?url=/uploads/template_plan.xlsx" style="font-size: 1rem; color: #23389c;'
-                   + ' text-decoration: underline; " target="_blank">Шаблон. Загрузка плановых значений</a></div></div>');
+
+    let title = 'Загрузка плановых значений';
+    let downloadLink = '/files/download?url=/uploads/template_plan.xlsx';
+    let linkText = 'Шаблон. Загрузка плановых значений';
+    let additionalParams = {};
+
+    if (buttonType === 'btn-adjustment') {
+        title = 'Внесение корректировок';
+        downloadLink = '/files/download?url=/uploads/template_adjustment.xlsx';
+        linkText = 'Шаблон. Внесение корректировок';
+        additionalParams = { adjustment: true }; // Add additional parameters for adjustment
+    }
+
+    $modalTitle.html(title);
+
+    $modalBody.html(`
+        <div class="row">
+            <div class="col-12">
+                <form class="d-flex justify-content-left align-items-center" enctype="multipart/form-data">
+                    <div class="d-none"><input type="file" name="myfile" accept=".xlsx"/></div>
+                    <div><input class="btn btn-success btn-sm" type="submit" value="Загрузить" /></div>
+                </form>
+            </div>
+        </div>
+        <div class="row mt-2">
+            <div class="col-12" id="infoModal"></div>
+        </div>
+        <div class="row mt-2">
+            <div class="col-12 border-2 bg-gray-200"></div>
+        </div>
+        <div class="row mt-5">
+            <div class="col-12" style="font-size: 1rem;">Скачать шаблон</div>
+        </div>
+        <div class="row mt-2">
+            <div class="col-12">
+                <a href="${downloadLink}" style="font-size: 1rem; color: #23389c; text-decoration: underline;" target="_blank">${linkText}</a>
+            </div>
+        </div>
+    `);
+
     const browse = $modalBody.find('input[type=file]').get(0);
     const btn = $modalBody.find('input[type=submit]').get(0);
     const info = $modalBody.find('#infoModal').get(0);
     const form = $modalBody.find('form').get(0);
+
     async function UploadDict() {
         info.innerHTML = 'загрузка...';
         if (browse.files[0].size > 200000) {
@@ -34,6 +61,12 @@ function openUploadDictionary() {
         }
         const formData = new FormData(form);
         formData.append(param10, token10);
+
+        // Append additional parameters if present
+        Object.keys(additionalParams).forEach(key => {
+            formData.append(key, additionalParams[key]);
+        });
+
         try {
             const response = await fetch("/motivation/index", {
                 method: "POST",
@@ -51,17 +84,18 @@ function openUploadDictionary() {
             console.error(e);
         }
     }
+
     browse.addEventListener('change', (event) => {
         event.preventDefault();
         event.stopPropagation();
         UploadDict();
-    })
+    });
 
     btn.addEventListener('click', (event) => {
         event.preventDefault();
         event.stopPropagation();
         browse.click();
-    })
+    });
 
     $mainModal.modal('show');
-}
\ No newline at end of file
+}