|
@@ -3,19 +3,52 @@
|
|
|
namespace App\Services;
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\Product;
|
|
use App\Models\Product;
|
|
|
|
|
+use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
|
|
+use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
|
|
|
|
class ExportService
|
|
class ExportService
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
- public function handle(): string
|
|
|
|
|
|
|
+ public function handle(array $filters = []): string
|
|
|
{
|
|
{
|
|
|
$products = Product::cursor();
|
|
$products = Product::cursor();
|
|
|
|
|
+ $inputFileType = 'Xlsx'; // Xlsx - Xml - Ods - Slk - Gnumeric - Csv
|
|
|
|
|
+ $inputFileName = './templates/ExportCatalogTemplate.xlsx';
|
|
|
|
|
+
|
|
|
|
|
+ $reader = IOFactory::createReader($inputFileType);
|
|
|
|
|
+ $spreadsheet = $reader->load($inputFileName);
|
|
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
|
|
+
|
|
|
|
|
+ $i = 2;
|
|
|
|
|
+ $sum_format = '#,##0.00\ "₽";[Red]\-#,##0.00\ "₽"';
|
|
|
|
|
|
|
|
foreach ($products as $product) {
|
|
foreach ($products as $product) {
|
|
|
- dump($product->id);
|
|
|
|
|
|
|
+ $sheet->setCellValue('B' . $i, $product->name_tz);
|
|
|
|
|
+ $sheet->setCellValue('C' . $i, $product->type_tz);
|
|
|
|
|
+ $sheet->setCellValue('D' . $i, $product->nomenclature_number);
|
|
|
|
|
+ $sheet->setCellValue('E' . $i, $product->sizes);
|
|
|
|
|
+ $sheet->setCellValue('F' . $i, $product->manufacturer);
|
|
|
|
|
+ $sheet->setCellValue('G' . $i, $product->unit);
|
|
|
|
|
+ $sheet->setCellValue('H' . $i, $product->type);
|
|
|
|
|
+ $sheet->setCellValue('I' . $i, $product->price_status);
|
|
|
|
|
+ $sheet->setCellValue('J' . $i, $product->product_price);
|
|
|
|
|
+ $sheet->setCellValue('K' . $i, $product->installation_price);
|
|
|
|
|
+ $sheet->setCellValue('L' . $i, $product->service_price);
|
|
|
|
|
+ $sheet->setCellValue('M' . $i, $product->total_price);
|
|
|
|
|
+ $sheet->setCellValue('N' . $i, $product->manufacturer_name);
|
|
|
|
|
+ $sheet->setCellValue('O' . $i, $product->article);
|
|
|
|
|
+ $sheet->setCellValue('P' . $i, $product->note);
|
|
|
|
|
+
|
|
|
|
|
+ $sheet->getStyle("J{$i}:M{$i}")->getNumberFormat()->setFormatCode($sum_format);
|
|
|
|
|
+
|
|
|
|
|
+ $i++;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return 'path';
|
|
|
|
|
|
|
+ $fileName = 'product_export_' . date('Y-m-d_H-i-s') . '.xlsx';
|
|
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
|
|
+ $writer->save(storage_path('app/public/export') . '/' . $fileName);
|
|
|
|
|
+
|
|
|
|
|
+ return $fileName;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|