feat: updates
This commit is contained in:
@@ -10,7 +10,6 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\View;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithDefaultStyles;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
@@ -19,25 +18,21 @@ use PhpOffice\PhpSpreadsheet\Exception;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Alignment;
|
||||
use PhpOffice\PhpSpreadsheet\Style\Style;
|
||||
|
||||
class TransmittalsExport implements FromCollection, WithMapping, ShouldAutoSize, ShouldQueue, WithDefaultStyles, WithHeadings
|
||||
class TransmittalsExport implements FromCollection, ShouldAutoSize, ShouldQueue, WithDefaultStyles, WithHeadings, WithMapping
|
||||
{
|
||||
|
||||
use Exportable, Queueable, SerializesModels;
|
||||
|
||||
|
||||
public function __construct(
|
||||
private readonly array $id
|
||||
)
|
||||
{}
|
||||
|
||||
) {}
|
||||
|
||||
public function view(): \Illuminate\Contracts\View\View
|
||||
{
|
||||
$transmittals = Transmittal::query()->with(['client','branch', 'files.notes', 'files.remarks'])->whereIn('id', Arr::flatten($this->id))->get();
|
||||
$transmittals = Transmittal::query()->with(['client', 'branch', 'files.notes', 'files.remarks'])->whereIn('id', Arr::flatten($this->id))->get();
|
||||
|
||||
return View::make('transmittal.export.transmittal-export-table')->with(['transmittals' => $transmittals]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -58,37 +53,57 @@ class TransmittalsExport implements FromCollection, WithMapping, ShouldAutoSize,
|
||||
'series',
|
||||
'files',
|
||||
'notes',
|
||||
'remarks'
|
||||
'remarks',
|
||||
];
|
||||
}
|
||||
|
||||
public function collection()
|
||||
{
|
||||
$transmittals = Transmittal::query()->with(['client','branch', 'files.notes', 'files.remarks'])
|
||||
->withCount(['files','notes','remarks'])->with(['files' => function($files) {
|
||||
$files->withCount(['notes','remarks']);
|
||||
$transmittals = Transmittal::query()->with(['client', 'branch', 'files.notes', 'files.remarks'])
|
||||
->withCount(['files', 'notes', 'remarks'])->with(['files' => function ($files) {
|
||||
$files->withCount(['notes', 'remarks']);
|
||||
}])
|
||||
->whereIn('id', Arr::flatten($this->id))->get();
|
||||
|
||||
|
||||
|
||||
return $transmittals;
|
||||
}
|
||||
|
||||
public function map($transmittal): array
|
||||
{
|
||||
|
||||
|
||||
|
||||
$data = [];
|
||||
|
||||
|
||||
|
||||
$firstFile = $transmittal->files->first();
|
||||
|
||||
$data[] = [
|
||||
$transmittal->series,
|
||||
$firstFile?->description,
|
||||
$firstFile->notes->first()?->comment,
|
||||
$firstFile->remarks->first()?->remark,
|
||||
];
|
||||
|
||||
$data[] = [$transmittal->series, $firstFile?->description, $firstFile->notes->first()?->comment, $firstFile->remarks->first()?->remark];
|
||||
//iterate comments and remarks for first file
|
||||
$notes = $firstFile->notes->pluck('comment');
|
||||
$remarks = $firstFile->remarks->pluck('remark');
|
||||
|
||||
$fileNoteCount = count($notes);
|
||||
$fileRemarkCount = count($remarks);
|
||||
|
||||
$fileRowCount = $fileNoteCount;
|
||||
if ($fileRemarkCount > $fileNoteCount) {
|
||||
$fileRowCount = $fileRemarkCount;
|
||||
}
|
||||
|
||||
for ($i = 1; $i < $fileRowCount; $i++) {
|
||||
$data[] = [
|
||||
'',
|
||||
'',
|
||||
$notes[$i] ?? '',
|
||||
$remarks[$i] ?? '',
|
||||
];
|
||||
}
|
||||
|
||||
//file iteration except for first file
|
||||
$fileRowCounter = 0;
|
||||
foreach ($transmittal->files as $file) {
|
||||
$notes = $file->notes->pluck('comment');
|
||||
@@ -98,20 +113,20 @@ class TransmittalsExport implements FromCollection, WithMapping, ShouldAutoSize,
|
||||
$fileRemarkCount = count($remarks);
|
||||
|
||||
$fileRowCount = $fileNoteCount;
|
||||
if($fileRemarkCount > $fileNoteCount) {
|
||||
if ($fileRemarkCount > $fileNoteCount) {
|
||||
$fileRowCount = $fileRemarkCount;
|
||||
}
|
||||
|
||||
|
||||
if($fileRowCounter != 0) {
|
||||
if ($fileRowCounter != 0) {
|
||||
$data[] = [
|
||||
'',
|
||||
$file->description ,
|
||||
$notes[$fileRowCounter - 1] ?? '',
|
||||
$remarks[$fileRowCounter - 1] ?? '',
|
||||
$file->description,
|
||||
$file->notes->first()?->comment ?? '',
|
||||
$file->remarks->first()?->remark ?? '',
|
||||
];
|
||||
|
||||
for ($i = 0; $i < $fileRowCount; $i++) {
|
||||
//iterate for remaining notes and remarks
|
||||
for ($i = 1; $i < $fileRowCount; $i++) {
|
||||
$data[] = [
|
||||
'',
|
||||
'',
|
||||
@@ -124,10 +139,6 @@ class TransmittalsExport implements FromCollection, WithMapping, ShouldAutoSize,
|
||||
$fileRowCounter++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user