From: Alexander Smirnov Date: Fri, 26 Jul 2024 11:25:10 +0000 (+0300) Subject: Добавляется ссылка для скачивания шаблона X-Git-Tag: 1.4~45^2~18 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=5d61a3b0c8da8c940cee7864b307de9e76623d58;p=erp24_rep%2Fyii-erp24%2F.git Добавляется ссылка для скачивания шаблона --- diff --git a/erp24/actions/motivation/IndexAction.php b/erp24/actions/motivation/IndexAction.php index 6c3c7ae4..f394a6f5 100644 --- a/erp24/actions/motivation/IndexAction.php +++ b/erp24/actions/motivation/IndexAction.php @@ -20,10 +20,15 @@ class IndexAction extends Action if (Yii::$app->request->isPost) { $file = UploadedFile::getInstanceByName('myfile'); if ($file) { - $path = Yii::getAlias('@uploads') . '/template_plan.xslx'; - $file->saveAs($path); + $path1 = Yii::getAlias('@uploads') . '/template_plan_temp.xlsx'; + $file->saveAs($path1); - $data = MotivationService::uploadTemplatePlan($path); + $data = MotivationService::uploadTemplatePlan($path1); + + if (empty(array_filter($data['errors'], function ($x) { return !empty($x); }))) { + $path2 = Yii::getAlias('@uploads') . '/template_plan.xlsx'; + copy($path1, $path2); + } return implode('
', $data['errors']); } else { diff --git a/erp24/views/motivation/index.php b/erp24/views/motivation/index.php index 5a91c905..626d1f19 100644 --- a/erp24/views/motivation/index.php +++ b/erp24/views/motivation/index.php @@ -58,7 +58,7 @@ $this->registerJsFile('/js/motivation/index.js', ['position' => \yii\web\View::P
'btn btn-success btn-sm', - 'onclick' => 'openUploadDictionary();'])?>
+ 'onclick' => 'openUploadDictionary(' . (file_exists(Yii::getAlias('@uploads') . '/template_plan.xlsx') ? 'true' : 'false'). ');'])?>
diff --git a/erp24/web/js/motivation/index.js b/erp24/web/js/motivation/index.js index 6d2ea843..4522c800 100644 --- a/erp24/web/js/motivation/index.js +++ b/erp24/web/js/motivation/index.js @@ -4,7 +4,7 @@ const param10 = $("meta[name=csrf-param]").attr("content"); const token10 = $("meta[name=csrf-token]").attr("content"); /* jshint unused: false */ -function openUploadDictionary() { +function openUploadDictionary(showDownloadLink) { 'use strict' const $mainModal = $('#mainModal'); const $modalBody = $mainModal.find('.modal-body'); @@ -12,7 +12,7 @@ function openUploadDictionary() { $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); }); $mainModal.find('.modal-title').html('Загрузка плановых значений'); $modalFooter.html(''); - $modalBody.html('
'); + $modalBody.html('
' + (!showDownloadLink ? '' : '') + '
'); 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);