create blade files for report
This commit is contained in:
62
app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php
Normal file
62
app/Exports/V3/SafetyAndPrivacy/CountryActivityReport.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\V3\SafetyAndPrivacy;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->data;
|
||||
|
||||
return view('v3.Reports.SafetyAndPrivacy.CountryActivityReport', [
|
||||
'data' => $data['activities'],
|
||||
'fromDate' => $data['fromDate'],
|
||||
'toDate' => $data['toDate'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function drawings(): array
|
||||
{
|
||||
$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('K1');
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
}
|
||||
62
app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php
Normal file
62
app/Exports/V3/SafetyAndPrivacy/ProvinceActivityReport.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports\V3\SafetyAndPrivacy;
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithDrawings;
|
||||
use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
|
||||
class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->data;
|
||||
|
||||
return view('v3.Reports.SafetyAndPrivacy.ProvinceActivityReport', [
|
||||
'data' => $data['activities'],
|
||||
'fromDate' => $data['fromDate'],
|
||||
'toDate' => $data['toDate'],
|
||||
]);
|
||||
}
|
||||
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
public function drawings(): array
|
||||
{
|
||||
$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('K1');
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,43 @@
|
||||
|
||||
namespace App\Http\Controllers\V3\Dashboard\Reports;
|
||||
|
||||
use App\Exports\V3\SafetyAndPrivacy\CountryActivityReport;
|
||||
use App\Exports\V3\SafetyAndPrivacy\ProvinceActivityReport;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Services\Cartables\SafetyAndPrivacyTableService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
class SafetyAndPrivacyReportController extends Controller
|
||||
{
|
||||
public function countryActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService)
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
public function countryActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->countryActivity($request);
|
||||
return $this->successResponse($data['activities']);
|
||||
}
|
||||
|
||||
public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService)
|
||||
public function provinceActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->provinceActivity($request);
|
||||
return $this->successResponse($data['activities']);
|
||||
}
|
||||
|
||||
public function countryExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->countryActivity($request);
|
||||
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new CountryActivityReport($data), $name);
|
||||
}
|
||||
|
||||
public function provinceExcelActivity(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->provinceActivity($request);
|
||||
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
return Excel::download(new ProvinceActivityReport($data), $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,10 +176,10 @@ class SafetyAndPrivacyController extends Controller
|
||||
return $this->successResponse($result);
|
||||
}
|
||||
|
||||
public function subItem(): JsonResponse
|
||||
public function subItems(): JsonResponse
|
||||
{
|
||||
return $this->successResponse(InfoItem::query()
|
||||
->where('item', 17)
|
||||
->where('item', '=', 17)
|
||||
->select('id', 'item', 'item_str', 'sub_item_str as name', 'sub_item_unit as unit', 'needs_image', 'needs_end_point', 'sub_item')
|
||||
->get());
|
||||
}
|
||||
|
||||
@@ -59,9 +59,6 @@ class SafetyAndPrivacyTableService
|
||||
$country = DB::select(
|
||||
"SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step"
|
||||
);
|
||||
$provinces = DB::select(
|
||||
"SELECT province_id, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa"
|
||||
);
|
||||
|
||||
$countryTotalSum = 0;
|
||||
foreach ($country as $key => $value) {
|
||||
@@ -86,9 +83,12 @@ class SafetyAndPrivacyTableService
|
||||
|
||||
$activities[$value->id]["sum"] = 0;
|
||||
$activities[$value->id]["name_fa"] = $value->name_fa;
|
||||
$activities[$value->id]["id"] = $value->id;
|
||||
}
|
||||
|
||||
$provinces = DB::select(
|
||||
"SELECT province_id, province_fa, COUNT(*) as qty,info_id, step, step_fa, info_fa FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."' GROUP BY info_id,step,province_id,province_fa"
|
||||
);
|
||||
|
||||
$provinceTotalSum = 0;
|
||||
foreach ($provinces as $key => $value) {
|
||||
$provinceTotalSum += $value->qty;
|
||||
@@ -103,4 +103,59 @@ class SafetyAndPrivacyTableService
|
||||
'toDate' => $toDate,
|
||||
];
|
||||
}
|
||||
|
||||
public function provinceActivity(Request $request): array
|
||||
{
|
||||
$fromDate = $request->from_date ? $request->from_date . ' 00:00:00' : now()->startOfDay()->toDateTimeString();
|
||||
$toDate = $request->date_to ? $request->date_to . ' 23:59:59' : now()->endOfDay()->toDateTimeString();
|
||||
$provinceId = $request->province_id;
|
||||
$activities = [];
|
||||
|
||||
$province = DB::select('
|
||||
SELECT COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step
|
||||
');
|
||||
|
||||
$provinceTotalSum = 0;
|
||||
foreach ($province as $key => $value) {
|
||||
$provinceTotalSum += $value->qty;
|
||||
$activities[-1]["info-".$value->info_id]["step-".$value->step] = $value->qty;
|
||||
$activities[-1]["sum"] = $provinceTotalSum;
|
||||
}
|
||||
|
||||
foreach (\App\Models\EdarateShahri::query()->where('province_id', $provinceId)->get() as $key => $value) {
|
||||
$activities[$value->id]["info-89"]["step-1"] = 0;
|
||||
$activities[$value->id]["info-89"]["step-2"] = 0;
|
||||
$activities[$value->id]["info-89"]["step-3"] = 0;
|
||||
|
||||
$activities[$value->id]["info-90"]["step-1"] = 0;
|
||||
$activities[$value->id]["info-90"]["step-2"] = 0;
|
||||
$activities[$value->id]["info-90"]["step-3"] = 0;
|
||||
|
||||
$activities[$value->id]["info-91"]["step-1"] = 0;
|
||||
$activities[$value->id]["info-91"]["step-2"] = 0;
|
||||
$activities[$value->id]["info-91"]["step-3"] = 0;
|
||||
|
||||
$activities[$value->id]["sum"] = 0;
|
||||
$activities[$value->id]["name_fa"] = $value->name_fa;
|
||||
}
|
||||
|
||||
|
||||
$cities = DB::select('
|
||||
SELECT edare_shahri_id, COUNT(*) as qty,info_id, step,step_fa, info_fa FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'" GROUP BY info_id,step,edare_shahri_id
|
||||
');
|
||||
|
||||
$cityTotalSum = 0;
|
||||
foreach ($cities as $key => $value) {
|
||||
$cityTotalSum += $value->qty;
|
||||
$activities[$value->edare_shahri_id]["info-".$value->info_id]["step-".$value->step] = $value->qty;
|
||||
$activities[$value->edare_shahri_id][""] = $value;
|
||||
$activities[$value->edare_shahri_id]["sum"] = $cityTotalSum;
|
||||
}
|
||||
|
||||
return [
|
||||
'activities' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user