create excel files
This commit is contained in:
70
app/Services/Reports/RoadItemReportService.php
Normal file
70
app/Services/Reports/RoadItemReportService.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Reports;
|
||||
|
||||
use App\Enums\InfoItem;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class RoadItemReportService
|
||||
{
|
||||
public function countryActivityPerSubItem(int $item, string $fromDate, string $toDate): Collection
|
||||
{
|
||||
$subItems = InfoItem::subItems($item);
|
||||
|
||||
$query = DB::table('road_items_projects')
|
||||
->selectRaw('province_id, province_fa');
|
||||
|
||||
foreach ($subItems as $key => $name) {
|
||||
$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
|
||||
");
|
||||
}
|
||||
|
||||
$query->where('item', '=', $item)
|
||||
->where('status', '=', 1)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->groupBy('province_id', 'province_fa')
|
||||
->orderBy('province_id');
|
||||
|
||||
$activities = $query->get();
|
||||
|
||||
return collect([
|
||||
'data' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinceActivityPerSubItem(int $item, string $fromDate, string $toDate, int $provinceId): Collection
|
||||
{
|
||||
$subItems = InfoItem::subItems($item);
|
||||
|
||||
$query = DB::table('road_items_projects')
|
||||
->selectRaw('province_id, province_fa, user_name as city_fa, city_id');
|
||||
|
||||
foreach ($subItems as $key => $name) {
|
||||
$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
|
||||
");
|
||||
}
|
||||
|
||||
$query->where('item', '=', $item)
|
||||
->where('status', '=', 1)
|
||||
->where('province_id', '=', $provinceId)
|
||||
->whereBetween('activity_date_time', [$fromDate, $toDate])
|
||||
->groupBy('city_id')
|
||||
->orderBy('province_id');
|
||||
|
||||
$activities = $query->get();
|
||||
|
||||
return collect([
|
||||
'data' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user