first commit
This commit is contained in:
78
app/Export/PropertyBookingListExport.php
Normal file
78
app/Export/PropertyBookingListExport.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Export;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Shared\Date;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class PropertyBookingListExport implements FromArray, WithHeadings, ShouldAutoSize, WithEvents, WithColumnFormatting
|
||||
{
|
||||
public function __construct($dataTableData = "")
|
||||
{
|
||||
$this->dataTableData = $dataTableData;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$cellRange = 'A1:J1'; // All headers
|
||||
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setBold(true);
|
||||
//$event->sheet->setAutoFilter($cellRange);
|
||||
$event->sheet->setTitle('Property Booking List');
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function columnFormats(): array
|
||||
{
|
||||
return [
|
||||
'D' => NumberFormat::FORMAT_DATE_DDMMYYYY,
|
||||
'E' => NumberFormat::FORMAT_DATE_DDMMYYYY,
|
||||
'J' => NumberFormat::FORMAT_DATE_DATETIME,
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
$resetData = reset($this->dataTableData);
|
||||
$header = array_keys($resetData);
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
|
||||
$dataTableData = [];
|
||||
|
||||
foreach ($this->dataTableData as $dataOrderKey => $dataBooking) {
|
||||
|
||||
foreach ($dataBooking as $dataKey => $value) {
|
||||
|
||||
if (in_array($dataKey, ['checkin_date', 'checkout_date', 'reservation_time'])) {
|
||||
$value = Date::dateTimeToExcel(Carbon::parse($value));
|
||||
}
|
||||
|
||||
$dataTableData[$dataOrderKey][$dataKey] = $value;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return [$dataTableData];
|
||||
}
|
||||
|
||||
}
|
||||
75
app/Export/PropertyCompetitorExport.php
Normal file
75
app/Export/PropertyCompetitorExport.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Export;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
use Maatwebsite\Excel\Concerns\FromArray;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
|
||||
|
||||
class PropertyCompetitorExport implements FromArray, WithHeadings, ShouldAutoSize, WithEvents
|
||||
{
|
||||
public function __construct($dataTableData = "")
|
||||
{
|
||||
$this->dataTableData = $dataTableData;
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function(AfterSheet $event) {
|
||||
$cellRange = 'A1:Q1'; // All headers
|
||||
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setBold(true);
|
||||
//$event->sheet->setAutoFilter($cellRange);
|
||||
$event->sheet->setTitle('Property Competitor Export');
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
|
||||
$header = [
|
||||
'Property'
|
||||
];
|
||||
|
||||
foreach ($this->dataTableData['date'] as $date) {
|
||||
$header[] = $date;
|
||||
}
|
||||
|
||||
$header[] = 'Currency';
|
||||
|
||||
return $header;
|
||||
}
|
||||
|
||||
public function array(): array
|
||||
{
|
||||
|
||||
$dataTableData = [];
|
||||
|
||||
foreach ($this->dataTableData['value'] as $propertyKey => $propertyValue) {
|
||||
|
||||
$dataTableData[$propertyKey] = [
|
||||
'name' => $this->dataTableData['property'][$propertyKey]
|
||||
];
|
||||
|
||||
foreach ($propertyValue as $dateKey => $value) {
|
||||
$dataTableData[$propertyKey][$dateKey] = $value['amount'];
|
||||
}
|
||||
|
||||
$dataTableData[$propertyKey]['currency'] = $value['currency'];
|
||||
|
||||
}
|
||||
|
||||
|
||||
return [$dataTableData];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user