From 1108f7aa7cace33cecac42ca8dcd992da36ffdeb Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 14 May 2025 10:21:10 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=BE=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?utf8?q?=D0=B2=D0=BA=D0=B0=20=D0=B3=D1=83=D0=B8=D0=B4=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/BouquetController.php | 47 ++++++++++++++++++++++++ erp24/views/bouquet/get-guid-bouquet.php | 35 ++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 erp24/views/bouquet/get-guid-bouquet.php diff --git a/erp24/controllers/BouquetController.php b/erp24/controllers/BouquetController.php index 314a9720..d3312aee 100644 --- a/erp24/controllers/BouquetController.php +++ b/erp24/controllers/BouquetController.php @@ -3,8 +3,10 @@ namespace app\controllers; use Exception; +use PhpOffice\PhpSpreadsheet\IOFactory; use Yii; use yii\base\DynamicModel; +use yii\data\ArrayDataProvider; use yii\db\Expression; use yii\filters\AccessControl; use yii\helpers\ArrayHelper; @@ -12,6 +14,7 @@ use yii\helpers\Url; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\web\Response; +use yii\web\UploadedFile; use yii_app\helpers\DataHelper; use yii_app\records\{BouquetComposition, BouquetCompositionPrice, @@ -22,6 +25,7 @@ use yii_app\records\{BouquetComposition, Files, MatrixType, PricesDynamic, + Products1c, Products1cNomenclature, SelfCostProduct, StoreType, @@ -295,4 +299,47 @@ class BouquetController extends Controller 'year' => $year, ]); } + + public function actionGetGuidBouquets() + { + $model = new DynamicModel(['excelFile']); + $model->addRule('excelFile', 'file', ['extensions' => ['xls', 'xlsx'], 'skipOnEmpty' => false]); + + $data = []; + + if (Yii::$app->request->isPost) { + $model->excelFile = UploadedFile::getInstance($model, 'excelFile'); + + if ($model->validate()) { + $filePath = Yii::getAlias('@runtime') . '/import_' . uniqid() . '.' . $model->excelFile->extension; + $model->excelFile->saveAs($filePath); + + $spreadsheet = IOFactory::load($filePath); + $rows = $spreadsheet->getActiveSheet()->toArray(); + + $names = array_filter(array_column($rows, 0)); + var_dump($names); die(); + $products = Products1c::find() + ->select(['id', 'name']) + ->where(['name' => $names]) + ->asArray() + ->all(); + + $data = $products; + + Yii::$app->session->set('productExportData', $data); + } + } + + $provider = new ArrayDataProvider([ + 'allModels' => $data, + 'pagination' => false, + ]); + + return $this->render('get-guid-bouquet', [ + 'model' => $model, + 'provider' => $provider, + ]); + } + } diff --git a/erp24/views/bouquet/get-guid-bouquet.php b/erp24/views/bouquet/get-guid-bouquet.php new file mode 100644 index 00000000..4203b808 --- /dev/null +++ b/erp24/views/bouquet/get-guid-bouquet.php @@ -0,0 +1,35 @@ +title = 'Импорт товаров из Excel'; +?> + +

title) ?>

+ + ['enctype' => 'multipart/form-data']]) ?> +field($model, 'excelFile')->fileInput() ?> +
+ 'btn btn-primary']) ?> +
+ + +getCount()): ?> +

Результаты поиска

+ $provider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + 'id', + 'name', + ], + ]) ?> + + 'btn btn-success']) ?> + \ No newline at end of file -- 2.39.5