bug fix in commodity import/export
This commit is contained in:
parent
f25b6ab8dc
commit
3ad815ec7f
|
@ -497,7 +497,31 @@ class CommodityController extends AbstractController
|
||||||
throw new \Exception('هیچ کالایی برای خروجی یافت نشد');
|
throw new \Exception('هیچ کالایی برای خروجی یافت نشد');
|
||||||
}
|
}
|
||||||
|
|
||||||
$filePath = $provider->createExcell($items);
|
$array = [];
|
||||||
|
foreach ($items as $item) {
|
||||||
|
$temp = [];
|
||||||
|
$temp[] = $item->isKhadamat() ? '0' : '1';
|
||||||
|
$temp[] = $item->isSpeedAccess() ? '1' : '0';
|
||||||
|
$temp[] = $item->getName();
|
||||||
|
$temp[] = $item->getPriceSell();
|
||||||
|
$temp[] = $item->getPriceBuy();
|
||||||
|
$temp[] = $item->getMinOrderCount();
|
||||||
|
$temp[] = $item->getDes();
|
||||||
|
$temp[] = $item->getUnit()->getName();
|
||||||
|
$temp[] = $item->getCat()->getName();
|
||||||
|
$array[] = $temp;
|
||||||
|
}
|
||||||
|
$filePath = $provider->createExcellFromArray($array, [
|
||||||
|
'کالا(۱) خدمات (۰)',
|
||||||
|
'دسترسی سریع ۱ فعال',
|
||||||
|
'نام کالا',
|
||||||
|
'قیمت فروش',
|
||||||
|
'قیمت خرید',
|
||||||
|
'حداقل سفارش',
|
||||||
|
'توضیحات',
|
||||||
|
'واحد شمارش',
|
||||||
|
'دسته بندی',
|
||||||
|
]);
|
||||||
$response = new BinaryFileResponse($filePath);
|
$response = new BinaryFileResponse($filePath);
|
||||||
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'commodities.xlsx');
|
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'commodities.xlsx');
|
||||||
$response->deleteFileAfterSend(true);
|
$response->deleteFileAfterSend(true);
|
||||||
|
@ -756,7 +780,6 @@ class CommodityController extends AbstractController
|
||||||
'Success' => true,
|
'Success' => true,
|
||||||
'result' => 1,
|
'result' => 1,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
#[Route('/api/commodity/mod/{code}', name: 'app_commodity_mod')]
|
#[Route('/api/commodity/mod/{code}', name: 'app_commodity_mod')]
|
||||||
public function app_commodity_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
public function app_commodity_mod(Provider $provider, Request $request, Access $access, Log $log, EntityManagerInterface $entityManager, $code = 0): JsonResponse
|
||||||
|
@ -1499,5 +1522,4 @@ class CommodityController extends AbstractController
|
||||||
$log->insert('کالا/خدمات', 'قیمت تعدادی از کالاها به صورت گروهی ویرایش شد.', $this->getUser(), $acc['bid']->getId());
|
$log->insert('کالا/خدمات', 'قیمت تعدادی از کالاها به صورت گروهی ویرایش شد.', $this->getUser(), $acc['bid']->getId());
|
||||||
return $this->json($extractor->operationSuccess());
|
return $this->json($extractor->operationSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -189,12 +189,72 @@ class Provider
|
||||||
*/
|
*/
|
||||||
public function createExcellFromArray(array $entities, array $headers = null)
|
public function createExcellFromArray(array $entities, array $headers = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
$spreadsheet = new Spreadsheet();
|
$spreadsheet = new Spreadsheet();
|
||||||
$activeWorksheet = $spreadsheet->getActiveSheet();
|
$activeWorksheet = $spreadsheet->getActiveSheet();
|
||||||
$activeWorksheet->fromArray($entities, null, 'A1');
|
|
||||||
|
// تنظیم هدرها اگر وجود داشته باشند
|
||||||
|
if ($headers !== null) {
|
||||||
|
$activeWorksheet->fromArray($headers, null, 'A1');
|
||||||
|
|
||||||
|
// استایلدهی به هدرها
|
||||||
|
$headerStyle = [
|
||||||
|
'font' => [
|
||||||
|
'bold' => true,
|
||||||
|
'color' => ['rgb' => 'FFFFFF'],
|
||||||
|
'size' => 12,
|
||||||
|
],
|
||||||
|
'fill' => [
|
||||||
|
'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
|
||||||
|
'startColor' => ['rgb' => '4472C4'],
|
||||||
|
],
|
||||||
|
'alignment' => [
|
||||||
|
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
|
||||||
|
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
|
||||||
|
],
|
||||||
|
'borders' => [
|
||||||
|
'allBorders' => [
|
||||||
|
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||||
|
'color' => ['rgb' => '000000'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$activeWorksheet->getStyle('A1:' . $activeWorksheet->getHighestColumn() . '1')->applyFromArray($headerStyle);
|
||||||
|
|
||||||
|
// اضافه کردن دادهها از ردیف دوم
|
||||||
|
$activeWorksheet->fromArray($entities, null, 'A2');
|
||||||
|
} else {
|
||||||
|
$activeWorksheet->fromArray($entities, null, 'A1');
|
||||||
|
}
|
||||||
|
|
||||||
|
// تنظیم جهت راست به چپ
|
||||||
$activeWorksheet->setRightToLeft(true);
|
$activeWorksheet->setRightToLeft(true);
|
||||||
$activeWorksheet->getHeaderFooter()->setOddHeader('&CHeader of the Document');
|
|
||||||
|
// تنظیم عرض ستونها به صورت خودکار
|
||||||
|
foreach (range('A', $activeWorksheet->getHighestColumn()) as $column) {
|
||||||
|
$activeWorksheet->getColumnDimension($column)->setAutoSize(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// فریز کردن ردیف هدر
|
||||||
|
$activeWorksheet->freezePane('A2');
|
||||||
|
|
||||||
|
// تنظیم استایل برای سلولهای داده
|
||||||
|
$dataStyle = [
|
||||||
|
'alignment' => [
|
||||||
|
'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER,
|
||||||
|
'vertical' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
|
||||||
|
],
|
||||||
|
'borders' => [
|
||||||
|
'allBorders' => [
|
||||||
|
'borderStyle' => \PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN,
|
||||||
|
'color' => ['rgb' => '000000'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
|
$dataRange = 'A1:' . $activeWorksheet->getHighestColumn() . $activeWorksheet->getHighestRow();
|
||||||
|
$activeWorksheet->getStyle($dataRange)->applyFromArray($dataStyle);
|
||||||
|
|
||||||
$writer = new Xlsx($spreadsheet);
|
$writer = new Xlsx($spreadsheet);
|
||||||
$filePath = __DIR__ . '/../../var/' . $this->RandomString(12) . '.xlsx';
|
$filePath = __DIR__ . '/../../var/' . $this->RandomString(12) . '.xlsx';
|
||||||
$writer->save($filePath);
|
$writer->save($filePath);
|
||||||
|
|
Loading…
Reference in a new issue