add detail to api

This commit is contained in:
2025-01-25 13:34:45 +03:30
parent dab16915da
commit ac2cb74398
6 changed files with 98 additions and 15 deletions

View File

@@ -24,10 +24,11 @@ class CountryActivityPerSubItemReport implements FromView, WithEvents, ShouldAut
{
$activities = $this->activities;
return view('', [
return view('v3.Reports.RoadItems.CountryActivityPerSubItem', [
'activities' => $activities->data,
'fromDate' => $activities->fromDate,
'toDate' => $activities->toDate
'toDate' => $activities->toDate,
'details' => $activities->details
]);
}

View File

@@ -658,7 +658,7 @@ class DevelopController extends Controller
$save = $file->move(storage_path('images'), $fileName);
\App\Helpers\Compress::resize($save);
// \App\Helpers\Compress::resize($save);
return response()->json(['msg' => 'ok']);
}

View File

@@ -154,13 +154,13 @@ class RoadItemsProjectController extends Controller
$after = $request->file('after_image')->store('road_items_projects_new/after', 'public');
$roadItems->files()->create(['path' => $after]);
$urlAfter = "/var/www/rms/public/storage/{$after}";
\App\Helpers\Compress::resize($urlAfter);
// \App\Helpers\Compress::resize($urlAfter);
}
if ($request->has('before_image')) {
$before = $request->file('before_image')->store('/road_items_projects_new/before', 'public');
$roadItems->files()->create(['path' => $before]);
$urlBefore = "/var/www/rms/public/storage/{$before}";
\App\Helpers\Compress::resize($urlBefore);
// \App\Helpers\Compress::resize($urlBefore);
}
if (auth()->user()) {

View File

@@ -372,7 +372,7 @@ class RoadItemsProjectController extends Controller
]);
// $road_item->files()->create(['path' => $after]);
$urlAfter = "/var/www/rms/public/storage/{$after}";
\App\Helpers\Compress::resize($urlAfter);
// \App\Helpers\Compress::resize($urlAfter);
}
if ($request->has('before_image')) {
Storage::delete('public/'. $road_item->files[1]->path);
@@ -383,7 +383,7 @@ class RoadItemsProjectController extends Controller
]);
// $road_item->files()->create(['path' => $before]);
$urlBefore = "/var/www/rms/public/storage/{$before}";
\App\Helpers\Compress::resize($urlBefore);
// \App\Helpers\Compress::resize($urlBefore);
}
}

View File

@@ -11,10 +11,10 @@ class RoadItemReportService
{
public function countryActivityPerSubItem(int $item, string $fromDate, string $toDate): Collection
{
$subItems = InfoItem::query()->where('item', $item)->get(['sub_item', 'sub_item_str']);
$subItems = InfoItem::query()->where('item', $item)->get(['sub_item', 'sub_item_str', 'sub_item_unit']);
$query = DB::table('road_items_projects')
->selectRaw('province_id, province_fa');
->selectRaw('province_id, province_fa, sub_item');
foreach ($subItems as $subItem) {
$query->selectRaw("
@@ -31,25 +31,36 @@ class RoadItemReportService
$activities = $query->get();
$totalItemCount = [
'province_fa' => 'کشوری'
];
foreach ($subItems as $subItem) {
$totalItemCount = [
"total_count_{$subItem->sub_item}" => $activities->sum("Count_{$subItem->sub_item}"),
"total_sum_{$subItem->sub_item}" => $activities->sum("Sum_{$subItem->sub_item}"),
];
}
return collect([
'data' => $activities,
'data' => $activities->push($totalItemCount),
'fromDate' => $fromDate,
'toDate' => $toDate,
'titles' => $subItems->pluck('sub_item_str')
'details' => $subItems,
]);
}
public function provinceActivityPerSubItem(int $item, string $fromDate, string $toDate, int $provinceId): Collection
{
$subItems = InfoItem::subItems($item);
$subItems = InfoItem::query()->where('item', $item)->get(['sub_item', 'sub_item_str', 'sub_item_unit']);
$query = DB::table('road_items_projects')
->selectRaw('province_id, province_fa, user_name as city_fa, city_id');
foreach ($subItems as $key => $name) {
foreach ($subItems as $subItem) {
$query->selectRaw("
COUNT(CASE WHEN sub_item = {$key} THEN 1 END) as {$name}Count,
SUM(CASE WHEN sub_item = {$key} THEN sub_item_data END) as {$name}Sum
COUNT(CASE WHEN sub_item = {$subItem->sub_item} THEN 1 END) as Count_{$subItem->sub_item},
SUM(CASE WHEN sub_item = {$subItem->sub_item} THEN sub_item_data END) as Sum_{$subItem->sub_item}
");
}
@@ -66,6 +77,7 @@ class RoadItemReportService
'data' => $activities,
'fromDate' => $fromDate,
'toDate' => $toDate,
'details' => $subItems
]);
}
}

View File

@@ -0,0 +1,70 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>کشوری</title>
</head>
<body dir="rtl" style="text-align: center;">
<table>
<thead>
<tr>
<th colspan="25" style="background-color: #DAEEF3;text-align: center;border-right: 1px solid black;font-weight:bolder;">
تاریخ دریافت گزارش: {{verta()->now()->format('Y/m/d H:i')}}
</th>
</tr>
<tr>
<th colspan="25" style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;"></th>
</tr>
<tr>
<th colspan="26" style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13;">
تعداد و احجام فعالیت های روزانه و جاری راهداری ثبت شده از تاریخ
{{verta($fromDate)->format('Y/n/j')}}
تا
تاریخ
{{verta($toDate)->format('Y/n/j')}}
</th>>
</tr>
<tr>
<th rowspan="3" style="border: 1px solid black;text-align: center;background-color: #EBF1DE;">اداره کل</th>
</tr>
@foreach($details as $detail)
<tr>
<th style="border:1px solid black;text-align:center;background-color: #C4D79B;">
<div style="display: flex; flex-direction: column; align-items: center;">
<span>{{ $detail->sub_item_str }}</span>
<div style="background-color: #FDE9D9;border: 1px solid black;text-align: center;">
<span>تعداد</span>
<span>{{ $detail->unit }}مجموع</span>
</div>
</div>
</th>
</tr>
</thead>
<tbody>
@foreach ($activities as $activity)
<tr>
<td style="border: 1px solid black;text-align: center;">{{ $activity->province_fa }}</td>
@if($activity->sub_item == $detail->sub_item)
<td style="border: 1px solid black;text-align: center;">{{ $activity->Count_ }}</td>
<td style="border: 1px solid black;text-align: center;">{{ round($activity->Sum_, 1) }}</td>
@endif
</tr>
@endforeach
@endforeach
</tbody>
</table>
</body>
</html>