From: marina Date: Fri, 9 Aug 2024 01:37:38 +0000 (+0300) Subject: ERP-102 Приёмник для эксель файла (корректировка) X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=63fa828844e653bac19577fddcc7d2b30e41a949;p=erp24_rep%2Fyii-erp24%2F.git ERP-102 Приёмник для эксель файла (корректировка) --- diff --git a/erp24/actions/motivation/IndexAction.php b/erp24/actions/motivation/IndexAction.php index f745fa06..74a6c22d 100644 --- a/erp24/actions/motivation/IndexAction.php +++ b/erp24/actions/motivation/IndexAction.php @@ -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('
', 'Вы не можете вносить корректировку'); + } + + $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('
', $data['errors']); } else { diff --git a/erp24/records/Motivation.php b/erp24/records/Motivation.php index e843bd00..6002e5fb 100644 --- a/erp24/records/Motivation.php +++ b/erp24/records/Motivation.php @@ -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 + ); + } } diff --git a/erp24/services/MotivationService.php b/erp24/services/MotivationService.php index 06e071aa..932320bd 100644 --- a/erp24/services/MotivationService.php +++ b/erp24/services/MotivationService.php @@ -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 index 00000000..fb63fb9a Binary files /dev/null and b/erp24/uploads/template_adjustment.xlsx differ diff --git a/erp24/views/motivation/index.php b/erp24/views/motivation/index.php index 38386efc..a42c6013 100644 --- a/erp24/views/motivation/index.php +++ b/erp24/views/motivation/index.php @@ -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
'btn btn-success btn-sm', 'onclick' => 'openUploadDictionary();'])?>
+
+
user->id)->group_id, Motivation::getAdjustmentEditors())) { + echo Html::button('Внесение корректировок', ['class' => 'btn btn-warning btn-sm btn-adjustment', + 'onclick' => 'openUploadDictionary("btn-adjustment");']); + } ?> +
+
diff --git a/erp24/web/js/motivation/index.js b/erp24/web/js/motivation/index.js index e7432015..db6b338f 100644 --- a/erp24/web/js/motivation/index.js +++ b/erp24/web/js/motivation/index.js @@ -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('
' - + '
' - + '
' - + '
' - + '
' - + '
' - + '
Скачать шаблон
' - + '
'); + + 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(` +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Скачать шаблон
+
+
+ +
+ `); + 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 +}