103 lines
3.2 KiB
PHP
103 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Exports\AxisReport;
|
|
|
|
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;
|
|
|
|
class ActivityReports implements FromView, ShouldAutoSize, WithEvents, WithDrawings, WithStyles
|
|
{
|
|
public function __construct($activities, $date_to, $date_from)
|
|
{
|
|
$this->activities = $activities ?? null;
|
|
$this->date_to = $date_to;
|
|
$this->date_from = $date_from;
|
|
}
|
|
|
|
public function view(): View
|
|
{
|
|
$ids = $this->activities;
|
|
$roadItemsProject = RoadItemsProject::whereIn('id', $ids ?? [])
|
|
->select('user_id' ,'province_fa', 'item_fa', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'created_at_fa', 'start_lat', 'start_lng')
|
|
->with('user:id,name')
|
|
->get();
|
|
$array = [];
|
|
foreach ($roadItemsProject as $item) {
|
|
$array[] = [
|
|
'province_fa' => $item->province_fa,
|
|
'item_fa' => $item->item_fa,
|
|
'sub_item_fa' => $item->sub_item_fa,
|
|
'sub_item_data' => $item->sub_item_data,
|
|
'unit_fa' => $item->unit_fa,
|
|
'created_at_fa' => $item->created_at_fa,
|
|
'start_lat' => $item->start_lat,
|
|
'start_lng' => $item->start_lng,
|
|
'user' => $item->user->name
|
|
];
|
|
}
|
|
return view('axisReport.activity-reports', [
|
|
'array' => $array,
|
|
'dateFrom' => $this->date_from,
|
|
'dateTo' => $this->date_to
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @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'
|
|
]
|
|
],
|
|
];
|
|
|
|
}
|
|
}
|