|
@@ -19,6 +19,18 @@ use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
|
|
|
|
|
class ExportCommonCatalogService
|
|
class ExportCommonCatalogService
|
|
|
{
|
|
{
|
|
|
|
|
+ public const TECHNICAL_DESCRIPTIONS_SHEET = 'Техописания';
|
|
|
|
|
+
|
|
|
|
|
+ public const TECHNICAL_DESCRIPTION_HEADERS = [
|
|
|
|
|
+ 'Артикул',
|
|
|
|
|
+ 'Наименование',
|
|
|
|
|
+ 'Наименование для формы',
|
|
|
|
|
+ 'Группа продукции',
|
|
|
|
|
+ 'Характеристики',
|
|
|
|
|
+ 'Техническое описание',
|
|
|
|
|
+ 'Краткое техническое описание',
|
|
|
|
|
+ ];
|
|
|
|
|
+
|
|
|
public const HEADERS = [
|
|
public const HEADERS = [
|
|
|
'Артикул',
|
|
'Артикул',
|
|
|
'Наименование',
|
|
'Наименование',
|
|
@@ -94,13 +106,18 @@ class ExportCommonCatalogService
|
|
|
$sheet->fromArray(self::SUBHEADERS, null, 'A2');
|
|
$sheet->fromArray(self::SUBHEADERS, null, 'A2');
|
|
|
$this->mergeHeaders($sheet);
|
|
$this->mergeHeaders($sheet);
|
|
|
$this->styleHeaders($sheet);
|
|
$this->styleHeaders($sheet);
|
|
|
|
|
+ $technicalDescriptionsSheet = $spreadsheet->createSheet();
|
|
|
|
|
+ $technicalDescriptionsSheet->setTitle(self::TECHNICAL_DESCRIPTIONS_SHEET);
|
|
|
|
|
+ $technicalDescriptionsSheet->fromArray(self::TECHNICAL_DESCRIPTION_HEADERS, null, 'A1');
|
|
|
|
|
+ $this->styleTechnicalDescriptionsSheet($technicalDescriptionsSheet);
|
|
|
|
|
|
|
|
$row = 3;
|
|
$row = 3;
|
|
|
|
|
+ $technicalDescriptionRow = 2;
|
|
|
CommonCatalogItem::query()
|
|
CommonCatalogItem::query()
|
|
|
->with('imageFile')
|
|
->with('imageFile')
|
|
|
->orderBy('article')
|
|
->orderBy('article')
|
|
|
->orderBy('calculator_name')
|
|
->orderBy('calculator_name')
|
|
|
- ->chunk(200, function ($items) use ($sheet, &$row): void {
|
|
|
|
|
|
|
+ ->chunk(200, function ($items) use ($sheet, $technicalDescriptionsSheet, &$row, &$technicalDescriptionRow): void {
|
|
|
foreach ($items as $item) {
|
|
foreach ($items as $item) {
|
|
|
$sheet->setCellValueExplicit("A{$row}", $item->article, DataType::TYPE_STRING);
|
|
$sheet->setCellValueExplicit("A{$row}", $item->article, DataType::TYPE_STRING);
|
|
|
$sheet->setCellValue("B{$row}", $item->calculator_name);
|
|
$sheet->setCellValue("B{$row}", $item->calculator_name);
|
|
@@ -137,7 +154,9 @@ class ExportCommonCatalogService
|
|
|
$sheet->setCellValue("AD{$row}", $item->recommended_plus_10_price);
|
|
$sheet->setCellValue("AD{$row}", $item->recommended_plus_10_price);
|
|
|
|
|
|
|
|
$this->addImage($sheet, $item, $row);
|
|
$this->addImage($sheet, $item, $row);
|
|
|
|
|
+ $this->addTechnicalDescription($technicalDescriptionsSheet, $item, $technicalDescriptionRow);
|
|
|
$row++;
|
|
$row++;
|
|
|
|
|
+ $technicalDescriptionRow++;
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -156,6 +175,18 @@ class ExportCommonCatalogService
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$this->setColumnWidths($sheet);
|
|
$this->setColumnWidths($sheet);
|
|
|
|
|
+ if ($technicalDescriptionRow > 2) {
|
|
|
|
|
+ $lastTechnicalDescriptionRow = $technicalDescriptionRow - 1;
|
|
|
|
|
+ $technicalDescriptionsSheet->getStyle("A1:G{$lastTechnicalDescriptionRow}")
|
|
|
|
|
+ ->getBorders()
|
|
|
|
|
+ ->getAllBorders()
|
|
|
|
|
+ ->setBorderStyle(Border::BORDER_THIN);
|
|
|
|
|
+ $technicalDescriptionsSheet->getStyle("A2:G{$lastTechnicalDescriptionRow}")
|
|
|
|
|
+ ->getAlignment()
|
|
|
|
|
+ ->setVertical(Alignment::VERTICAL_TOP)
|
|
|
|
|
+ ->setWrapText(true);
|
|
|
|
|
+ }
|
|
|
|
|
+ $spreadsheet->setActiveSheetIndex(0);
|
|
|
|
|
|
|
|
$directory = 'export/common_catalog';
|
|
$directory = 'export/common_catalog';
|
|
|
$filename = 'common_catalog_'.now()->format('Y-m-d_H-i-s').'.xlsx';
|
|
$filename = 'common_catalog_'.now()->format('Y-m-d_H-i-s').'.xlsx';
|
|
@@ -256,4 +287,45 @@ class ExportCommonCatalogService
|
|
|
$drawing->setWorksheet($sheet);
|
|
$drawing->setWorksheet($sheet);
|
|
|
$sheet->getRowDimension($row)->setRowHeight(56);
|
|
$sheet->getRowDimension($row)->setRowHeight(56);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private function addTechnicalDescription(Worksheet $sheet, CommonCatalogItem $item, int $row): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $sheet->setCellValueExplicit("A{$row}", $item->article, DataType::TYPE_STRING);
|
|
|
|
|
+ $sheet->setCellValue("B{$row}", $item->calculator_name);
|
|
|
|
|
+ $sheet->setCellValue("C{$row}", $item->print_name);
|
|
|
|
|
+ $sheet->setCellValue("D{$row}", $item->product_group);
|
|
|
|
|
+ $sheet->setCellValue("E{$row}", $item->characteristics);
|
|
|
|
|
+ $sheet->setCellValue("F{$row}", $item->technical_description);
|
|
|
|
|
+ $sheet->setCellValue("G{$row}", $item->technical_description_short);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private function styleTechnicalDescriptionsSheet(Worksheet $sheet): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $sheet->getStyle('A1:G1')->applyFromArray([
|
|
|
|
|
+ 'font' => ['bold' => true],
|
|
|
|
|
+ 'fill' => [
|
|
|
|
|
+ 'fillType' => Fill::FILL_SOLID,
|
|
|
|
|
+ 'startColor' => ['rgb' => 'D9EAF7'],
|
|
|
|
|
+ ],
|
|
|
|
|
+ 'alignment' => [
|
|
|
|
|
+ 'horizontal' => Alignment::HORIZONTAL_CENTER,
|
|
|
|
|
+ 'vertical' => Alignment::VERTICAL_CENTER,
|
|
|
|
|
+ 'wrapText' => true,
|
|
|
|
|
+ ],
|
|
|
|
|
+ ]);
|
|
|
|
|
+ $sheet->getRowDimension(1)->setRowHeight(36);
|
|
|
|
|
+ $sheet->freezePane('A2');
|
|
|
|
|
+
|
|
|
|
|
+ foreach ([
|
|
|
|
|
+ 'A' => 14,
|
|
|
|
|
+ 'B' => 38,
|
|
|
|
|
+ 'C' => 38,
|
|
|
|
|
+ 'D' => 28,
|
|
|
|
|
+ 'E' => 55,
|
|
|
|
|
+ 'F' => 70,
|
|
|
|
|
+ 'G' => 55,
|
|
|
|
|
+ ] as $column => $width) {
|
|
|
|
|
+ $sheet->getColumnDimension($column)->setWidth($width);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|