Files
backend/app/Exports/V2/RoadItems/OperatorCartableExport.php
2024-02-01 09:53:53 +00:00

111 lines
3.8 KiB
PHP

<?php
namespace App\Exports\V2\RoadItems;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use App\Models\RoadItemsProject;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Hekmatinasser\Verta\Verta;
class OperatorCartableExport implements FromView, ShouldAutoSize, WithEvents, WithDrawings, WithStyles
{
public function __construct($id, $item, $status, $fromDate, $toDate)
{
$this->id = $id;
$this->item = $item;
$this->status = $status;
$this->fromDate = $fromDate;
$this->toDate = $toDate;
}
public function view(): View
{
$fromDate = $this->fromDate ? $this->fromDate . ' 00:00:00': null;
$toDate = $this->toDate ? $this->toDate . ' 23:59:59': null;
$status = $this->status;
$data = RoadItemsProject::where('is_new', 1)
->where('user_id', auth()->user()->id)
->when($this->id, function($query, $id){
return $query->where('id', $id);
})
->when($this->item, function($query, $item){
return $query->where('item', $item);
})
->when(!is_null($status), function($query) use ($status){
return $query->where('status', $status);
})
->when(($fromDate && $toDate), function($query) use($fromDate, $toDate){
return $query->whereBetween('activity_date_time', [$fromDate, $toDate]);
})
->select('id', 'item', 'item_fa', 'sub_item', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng', 'end_lat', 'end_lng',
'created_at', 'activity_date_time', 'status', 'status_fa', 'supervisor_description')
->orderBy('status', 'desc')
->orderBy('id', 'desc')
->get();
return view('excel.V2.RoadItems.operator_cartable', [
'data' => $data,
'fromDate' => $fromDate,
'toDate' => $toDate
]);
}
/**
* @return array
*/
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$event->sheet->getDelegate()->setRightToLeft(true);
},
];
}
public function drawings()
{
$drawing = new Drawing();
$drawing->setName('Logo');
$drawing->setDescription('This is my logo');
$drawing->setPath(public_path('/dist/logo.png'));
$drawing->setWidth(50);
$drawing->setHeight(50);
$drawing->setOffsetX(5);
$drawing->setOffsetY(5);
$drawing->setCoordinates('A1');
$drawing2 = new Drawing();
$drawing2->setName('Logo');
$drawing2->setDescription('This is my logo');
$drawing2->setPath(public_path('/dist/141icon.png'));
$drawing2->setWidth(50);
$drawing2->setHeight(50);
$drawing2->setOffsetX(5);
$drawing2->setOffsetY(5);
$drawing2->setCoordinates('B1');
return [$drawing, $drawing2];
}
public function styles(Worksheet $sheet)
{
return [
// Style the first row as bold text.
'A:BA' => [
'font' => [
'name' => 'B Nazanin'
]
],
];
}
}