Pārlūkot izejas kodu

Log export time, fixes handle images when export, move template templates dir, fixed js select/deselect, fixed vite config (for build)

Alexander Musikhin 2 gadi atpakaļ
vecāks
revīzija
662eaaf357

+ 8 - 8
app/Http/Controllers/ExportController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 
 use App\Models\Product;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Log;
 
 class ExportController extends Controller
 {
@@ -11,15 +12,17 @@ class ExportController extends Controller
         $ids = json_decode($request->ids,true);
         $products = Product::query()->whereIn('id', $ids)->orderBy('series', 'asc')->get();
 
-        $my_template = new \PhpOffice\PhpWord\TemplateProcessor(storage_path('template_maf.docx'));
+        $my_template = new \PhpOffice\PhpWord\TemplateProcessor(storage_path('templates/template_maf.docx'));
 
         $vars_for_template = [];
         $i = 1;
         foreach ($products as $product){
             $vars_for_template = array_merge($vars_for_template, [
                 'series#' . $i        => $product->series,
+                'product_group#' .$i  => $product->product_group,
                 'num#' . $i           => $i,
                 'name#' . $i          => $product->name,
+                'name_for_form#' . $i          => $product->name_for_form,
                 'price#' . $i         => number_format($product->price, 0, '', ' '),
                 'image#' . $i         => $product->image_path,
                 'description#' . $i   => str_replace("\n", '</w:t><w:br/><w:t xml:space="preserve">', $product->characteristics . "\r\n" . $product->tech_description),
@@ -31,19 +34,14 @@ class ExportController extends Controller
         $my_template->cloneBlock('product_block', count($products), true, true, $vars_for_template);
 
         foreach ($vars_for_template as $k => $v){
-            if(str_starts_with($k, 'image')){
-                $my_template->setImageValue($k, ['path' => public_path() . '/' . env('IMAGES_PATH') . '/' . $v,
+            if(str_starts_with($k, 'image') && file_exists($file = public_path() . '/' . env('IMAGES_PATH') . '/' . $v)){
+                $my_template->setImageValue($k, ['path' => $file,
                         'width' => 270, 'height' => 180
                 ]);
             } else {
                 $my_template->setValue($k, $v);
             }
 
-            if(str_starts_with($k, 'series')) {
-//                $my_template->cloneRow($k, 5);
-            }
-
-
         }
 
 
@@ -60,6 +58,8 @@ class ExportController extends Controller
         header('Expires: 0');
         ob_clean();
         $my_template->saveAs("php://output");
+        Log::notice('Execution time: ' . microtime(true) - LARAVEL_START);
+
         exit();
     }
 }

+ 2 - 2
resources/views/products/index.blade.php

@@ -142,8 +142,8 @@
 
             if(status.checked){
                 // console.log('select '+id);
-                if(!selected_products.includes(id)){
-                    selected_products.push(id);
+                if(!selected_products.includes(id.toString())){
+                    selected_products.push(id.toString());
                 }
 
             } else {

BIN
storage/templates/template_maf.docx


+ 0 - 1
todo.txt

@@ -4,7 +4,6 @@
 + редактирование товара (все поля, кроме изображения и артикула)
 + при редатировании товара можно загружать изображения
 + если несколько изображений найдено по артикулу - можно выбрать одно
-
 + выбор товаров с запоминаннием при переходах между страницами
 
 

+ 2 - 0
vite.config.js

@@ -6,7 +6,9 @@ export default defineConfig({
     plugins: [
         laravel({
             input: [
+                'resources/sass/app.scss',
                 'resources/js/app.js',
+
             ],
             refresh: true,
         }),