Files

145 lines
5.3 KiB
PHP

<?php
namespace App\Exports\V2\Receipt\RecieptTable;
use Illuminate\Contracts\View\View;
use Maatwebsite\Excel\Concerns\FromView;
use App\Models\Accident;
use App\Models\Province;
use App\Models\City;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Events\AfterSheet;
use Maatwebsite\Excel\Concerns\WithEvents;
use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Concerns\WithDrawings;
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
class Cities implements FromView, ShouldAutoSize, WithEvents, WithDrawings
{
public function __construct($from_date, $date_to)
{
$this->from_date = $from_date;
$this->date_to = $date_to;
}
public function view(): View
{
$from_date = $this->from_date ?? Date('Y-m-d'). " 00:00:00";
$date_to = $this->date_to ?? Date('Y-m-d')." 23:59:59";
$all_province_data = Accident::provinceReceiptData($from_date, $date_to);
$temp = '';
foreach (Province::all() as $province) {
$city_data = Accident::cityReceiptData($from_date, $date_to, $province->id);
foreach (City::where("province_id", $province->id)->get() as $city) {
$temp = array_search($city->id, array_column($city_data, 'city_id'));
if ($temp !== false) {
$array[] = [
'name' => $city->name_fa,
'is_province' => 0,
'tedade' => $city_data[$temp]->tedade,
'police_rah' => $city_data[$temp]->police_rah,
'gozaresh_gasht' => $city_data[$temp]->gozaresh_gasht,
'kol_sabt_shode' => $city_data[$temp]->kol_sabt_shode,
'vasel_shode' => $city_data[$temp]->vasel_shode ?? 0,
'vasel_shode_bimeh' => $city_data[$temp]->vasel_shode_bimeh ?? 0,
'vasel_shode_daghi' => $city_data[$temp]->vasel_shode_daghi ?? 0,
'vasel_shode_final' => $city_data[$temp]->vasel_shode_final ?? 0,
];
} else {
$array[] = [
'name' => $city->name_fa,
'is_province' => 0,
'tedade' => "",
'police_rah' => "",
'gozaresh_gasht' => "",
'kol_sabt_shode' => "",
'vasel_shode' => "",
'vasel_shode_bimeh' => "",
'vasel_shode_daghi' => "",
'vasel_shode_final' => "",
];
}
}
$temp = array_search($province->id, array_column($all_province_data, 'province_id'));
if ($temp) {
$array[] = [
'name' => $province->name_fa,
'is_province' => 1,
'tedade' => $all_province_data[$temp]->tedade,
'police_rah' => $all_province_data[$temp]->police_rah,
'gozaresh_gasht' => $all_province_data[$temp]->gozaresh_gasht,
'kol_sabt_shode' => $all_province_data[$temp]->kol_sabt_shode,
'vasel_shode' => $all_province_data[$temp]->vasel_shode ?? 0,
'vasel_shode_bimeh' => $all_province_data[$temp]->vasel_shode_bimeh ?? 0,
'vasel_shode_daghi' => $all_province_data[$temp]->vasel_shode_daghi ?? 0,
'vasel_shode_final' => $all_province_data[$temp]->vasel_shode_final ?? 0,
];
} else {
$array[] = [
'name' => $province->name_fa,
'is_province' => 1,
'tedade' => "",
'police_rah' => "",
'gozaresh_gasht' => "",
'kol_sabt_shode' => "",
'vasel_shode' => "",
'vasel_shode_bimeh' => "",
'vasel_shode_daghi' => "",
'vasel_shode_final' => "",
];
}
}
return view('excel.V2.Receipt.ReceiptTable.City', [
'data' => $array,
'fromFa' => $from_date,
'toFa' => $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('H1');
return [$drawing, $drawing2];
}
}