|
|
@@ -2,12 +2,17 @@
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
+use App\Helpers\CountHelper;
|
|
|
use App\Helpers\DateHelper;
|
|
|
use App\Helpers\ExcelHelper;
|
|
|
use App\Models\Contract;
|
|
|
+use App\Models\File;
|
|
|
use App\Models\Order;
|
|
|
+use App\Models\ProductSKU;
|
|
|
use App\Models\Reclamation;
|
|
|
+use App\Models\Ttn;
|
|
|
use Exception;
|
|
|
+use Faker\Guesser\Name;
|
|
|
use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
use Illuminate\Support\Str;
|
|
|
@@ -523,4 +528,84 @@ class GenerateDocumentsService
|
|
|
return $fileModel;
|
|
|
}
|
|
|
|
|
|
+ public function generateTtnPack(Ttn $ttn, int $userId): string
|
|
|
+ {
|
|
|
+ $skus = ProductSKU::query()->whereIn('id', json_decode($ttn->skus))->get();
|
|
|
+ $volume = $weight = $places = 0;
|
|
|
+ foreach ($skus as $sku) {
|
|
|
+ if(!isset($order)) {
|
|
|
+ $order = $sku->order;
|
|
|
+ }
|
|
|
+ $volume += $sku->product->volume;
|
|
|
+ $weight += $sku->product->weight;
|
|
|
+ $places += $sku->product->places;
|
|
|
+ }
|
|
|
+
|
|
|
+ $installationDate = ($order->installation_date) ? DateHelper::getHumanDate($order->installation_date, true) : '-';
|
|
|
+ $ttnNumber = ($ttn->ttn_number_suffix) ? $ttn->ttn_number . '-' . $ttn->ttn_number_suffix : $ttn->ttn_number;
|
|
|
+
|
|
|
+ $inputFileType = 'Xlsx';
|
|
|
+ $inputFileName = './templates/Ttn.xlsx';
|
|
|
+
|
|
|
+ $reader = IOFactory::createReader($inputFileType);
|
|
|
+ $spreadsheet = $reader->load($inputFileName);
|
|
|
+ $sheet = $spreadsheet->getActiveSheet();
|
|
|
+
|
|
|
+ $sheet->setCellValue('D8', $installationDate);
|
|
|
+ $sheet->setCellValue('R8', $ttnNumber);
|
|
|
+ $sheet->setCellValue('AF8', DateHelper::getHumanDate($ttn->order_date, true));
|
|
|
+ $sheet->setCellValue('AT8', $ttn->order_number);
|
|
|
+
|
|
|
+ $sheet->setCellValue('B19', $order->object_address ?? '');
|
|
|
+
|
|
|
+ $sheet->setCellValue('AD22', CountHelper::humanCount($places, 'место', 'места', 'мест') . ', способ упаковки: поддон, ящик, картон, полиэтилен');
|
|
|
+
|
|
|
+ $sheet->setCellValue('B24', $weight . ' кг, ' . $volume . ' м.куб');
|
|
|
+
|
|
|
+ $sheet->setCellValue('B36', $installationDate);
|
|
|
+
|
|
|
+ $sheet->setCellValue('AB57', $installationDate . ' 8-00');
|
|
|
+ $sheet->setCellValue('B59', $installationDate . ' 8-10');
|
|
|
+ $sheet->setCellValue('AB59', $installationDate . ' 8-40');
|
|
|
+
|
|
|
+ $sheet->setCellValue('B61', $weight . ' кг');
|
|
|
+
|
|
|
+ $sheet->setCellValue('B63', CountHelper::humanCount($places, 'место', 'места', 'мест'));
|
|
|
+
|
|
|
+ $sheet->setCellValue('B75', $order->object_address ?? '');
|
|
|
+ $sheet->setCellValue('AB75', $installationDate);
|
|
|
+ $sheet->setCellValue('B77', $installationDate);
|
|
|
+ $sheet->setCellValue('AB77', $installationDate);
|
|
|
+
|
|
|
+ $sheet->setCellValue('AB79', CountHelper::humanCount($places, 'место', 'места', 'мест'));
|
|
|
+ $sheet->setCellValue('B81', $weight . ' кг');
|
|
|
+ $sheet->setCellValue('B83', $order->brigadier?->name ?? '');
|
|
|
+
|
|
|
+ $sheet->setCellValue('B89', $ttn->order_sum);
|
|
|
+ $sheet->setCellValue('AD89', $ttn->order_sum);
|
|
|
+ $sheet->setCellValue('AS89', $ttn->order_sum);
|
|
|
+
|
|
|
+ // save file
|
|
|
+ $fileName = 'ТТН №' . $ttn->ttn_number . ' от ' . DateHelper::getHumanDate($ttn->order_date) . '.xlsx';
|
|
|
+ $writer = new Xlsx($spreadsheet);
|
|
|
+ $fd = 'ttn/' . $ttn->year;
|
|
|
+ Storage::disk('public')->makeDirectory($fd);
|
|
|
+ $fp = storage_path('app/public/ttn/') . $ttn->year . '/' . $fileName;
|
|
|
+ Storage::disk('public')->delete($fd . '/' . $fileName);
|
|
|
+ $writer->save($fp);
|
|
|
+
|
|
|
+
|
|
|
+ $fileModel = File::query()->updateOrCreate([
|
|
|
+ 'link' => url('/storage/') . '/ttn/' . $ttn->year . '/' .$fileName,
|
|
|
+ 'path' => $fp . '/' .$fileName,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'original_name' => $fileName,
|
|
|
+ 'mime_type' => 'application/xlsx',
|
|
|
+ ]);
|
|
|
+ $ttn->file_id = $fileModel->id;
|
|
|
+ $ttn->save();
|
|
|
+
|
|
|
+ return $fileModel->link ?? '';
|
|
|
+ }
|
|
|
+
|
|
|
}
|