|
|
@@ -8,6 +8,7 @@ use App\Models\Contract;
|
|
|
use App\Models\Order;
|
|
|
use App\Models\Reclamation;
|
|
|
use Exception;
|
|
|
+use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
|
@@ -338,6 +339,12 @@ class GenerateDocumentsService
|
|
|
$writer->save(storage_path('app/public/orders/') . $order->id . '/tmp/' . $fileName);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param Reclamation $reclamation
|
|
|
+ * @param int $userId
|
|
|
+ * @return string
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
public function generateReclamationPack(Reclamation $reclamation, int $userId): string
|
|
|
{
|
|
|
Storage::disk('public')->makeDirectory('reclamations/' . $reclamation->id . '/tmp/' . $reclamation->order->object_address . '/ФОТО НАРУШЕНИЯ/');
|
|
|
@@ -366,6 +373,9 @@ class GenerateDocumentsService
|
|
|
return $fileModel?->link ?? '';
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
private function generateReclamationOrder(Reclamation $reclamation): void
|
|
|
{
|
|
|
$inputFileType = 'Xlsx';
|
|
|
@@ -393,12 +403,19 @@ class GenerateDocumentsService
|
|
|
// save file
|
|
|
$fileName = 'Монтажная заявка - ' . $reclamation->order->object_address . '.xlsx';
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
- Storage::disk('public')->makeDirectory('reclamations/' . $reclamation->id . '/tmp/' . $reclamation->order->object_address);
|
|
|
+ $fd = 'reclamations/' . $reclamation->id . '/tmp/' . $reclamation->order->object_address;
|
|
|
+ Storage::disk('public')->makeDirectory($fd);
|
|
|
+ $fp = storage_path('app/public/reclamations/') . $reclamation->id . '/tmp/' . $reclamation->order->object_address . '/' . $fileName;
|
|
|
+ Storage::disk('public')->delete($fd . '/' . $fileName);
|
|
|
+ $writer->save($fp);
|
|
|
+ PdfConverterClient::convert($fp);
|
|
|
|
|
|
- $writer->save(storage_path('app/public/reclamations/') . $reclamation->id . '/tmp/' . $reclamation->order->object_address . '/' . $fileName);
|
|
|
}
|
|
|
|
|
|
- public function generateReclamationAct(Reclamation $reclamation): void
|
|
|
+ /**
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private function generateReclamationAct(Reclamation $reclamation): void
|
|
|
{
|
|
|
$inputFileType = 'Xlsx';
|
|
|
$inputFileName = './templates/ReclamationAct.xlsx';
|
|
|
@@ -431,11 +448,18 @@ class GenerateDocumentsService
|
|
|
// save file
|
|
|
$fileName = 'Акт - ' . $reclamation->order->object_address . '.xlsx';
|
|
|
$writer = new Xlsx($spreadsheet);
|
|
|
- Storage::disk('public')->makeDirectory('reclamations/' . $reclamation->id . '/tmp/' . $reclamation->order->object_address);
|
|
|
- $writer->save(storage_path('app/public/reclamations/') . $reclamation->id . '/tmp/' . $reclamation->order->object_address . '/' . $fileName);
|
|
|
+ $fd = 'reclamations/' . $reclamation->id . '/tmp/' . $reclamation->order->object_address;
|
|
|
+ Storage::disk('public')->makeDirectory($fd);
|
|
|
+ $fp = storage_path('app/public/reclamations/') . $reclamation->id . '/tmp/' . $reclamation->order->object_address . '/' . $fileName;
|
|
|
+ Storage::disk('public')->delete($fd . '/' . $fileName);
|
|
|
+ $writer->save($fp);
|
|
|
+ PdfConverterClient::convert($fp);
|
|
|
}
|
|
|
|
|
|
- public function generateReclamationGuarantee(Reclamation $reclamation): void
|
|
|
+ /**
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private function generateReclamationGuarantee(Reclamation $reclamation): void
|
|
|
{
|
|
|
$inputFileType = 'Xlsx';
|
|
|
$inputFileName = './templates/ReclamationGuarantee.xlsx';
|
|
|
@@ -470,7 +494,33 @@ class GenerateDocumentsService
|
|
|
$fp = storage_path('app/public/reclamations/') . $reclamation->id . '/tmp/' . $reclamation->order->object_address . '/' . $fileName;
|
|
|
Storage::disk('public')->delete($fd . '/' . $fileName);
|
|
|
$writer->save($fp);
|
|
|
+ PdfConverterClient::convert($fp);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ public function generateFilePack(Collection $files, int $userId, string $name = 'files'): \App\Models\File
|
|
|
+ {
|
|
|
+ $dir = Str::random(2);
|
|
|
+ Storage::disk('public')->makeDirectory('files/' . $dir . '/tmp/');
|
|
|
+
|
|
|
+ // copy files
|
|
|
+ foreach ($files as $file) {
|
|
|
+ $from = $file->path;
|
|
|
+ $to = 'files/' . $dir . '/tmp/' . $file->original_name;
|
|
|
+ if (!Storage::disk('public')->exists($to)) {
|
|
|
+ Storage::disk('public')->copy($from, $to);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // create zip archive
|
|
|
+ $fileModel = (new FileService())->createZipArchive('files/' . $dir . '/tmp', $name .'_' . date('Y-m-d_h-i-s') . '.zip', $userId);
|
|
|
+
|
|
|
+ // remove temp files
|
|
|
+ Storage::disk('public')->deleteDirectory('files/' . $dir . '/tmp');
|
|
|
+
|
|
|
+ // return link
|
|
|
+ return $fileModel;
|
|
|
}
|
|
|
|
|
|
}
|