develop #7
@@ -100,7 +100,7 @@ HARIM_NEED_GUARANTEE_LETTER_USERNAME=
|
||||
|
||||
BACKUP_TARGET_DIR=
|
||||
BACKUP_USER=
|
||||
BACKUP_PASSWORD=
|
||||
BACKUP_PASSWORD=1qaz
|
||||
|
||||
|
||||
HARIM_ENCRYPTION_KEY="TestKey"
|
||||
|
||||
@@ -10,9 +10,11 @@ use Maatwebsite\Excel\Concerns\WithEvents;
|
||||
use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
|
||||
class CountryReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
|
||||
class CountryReport implements FromView, ShouldAutoSize, WithDrawings, WithEvents
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
public function __construct(private array $data)
|
||||
{
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
@@ -20,32 +22,34 @@ class CountryReport implements FromView, WithEvents, ShouldAutoSize, WithDrawing
|
||||
$national = null;
|
||||
|
||||
foreach ($this->data as $r) {
|
||||
$pid = (int) $r->province_id;
|
||||
$pid = (int) $r->province_id;
|
||||
$name = $r->province_name;
|
||||
|
||||
if ($pid === -1) {
|
||||
$national = [
|
||||
'province_name' => $name,
|
||||
'no_mission_count' => (int) ($r->no_mission_count ?? 0),
|
||||
'province_name' => $name,
|
||||
'no_mission_count' => (int) ($r->no_mission_count ?? 0),
|
||||
'out_of_area_count' => (int) ($r->out_of_area_count ?? 0),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($grid[$pid])) {
|
||||
if (! isset($grid[$pid])) {
|
||||
$grid[$pid] = [
|
||||
'province_name' => $name,
|
||||
];
|
||||
}
|
||||
|
||||
$grid[$pid]['no_mission_count'] = (int) ($r->no_mission_count ?? 0);
|
||||
$grid[$pid]['no_mission_count'] = (int) ($r->no_mission_count ?? 0);
|
||||
$grid[$pid]['out_of_area_count'] = (int) ($r->out_of_area_count ?? 0);
|
||||
|
||||
}
|
||||
|
||||
$exportRows = [];
|
||||
if ($national) $exportRows[] = $national;
|
||||
if ($national) {
|
||||
$exportRows[] = $national;
|
||||
}
|
||||
foreach ($grid as $row) {
|
||||
$exportRows[] = $row;
|
||||
}
|
||||
@@ -85,6 +89,7 @@ class CountryReport implements FromView, WithEvents, ShouldAutoSize, WithDrawing
|
||||
$drawing2->setOffsetX(5);
|
||||
$drawing2->setOffsetY(5);
|
||||
$drawing2->setCoordinates('C1');
|
||||
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Exports\V3\Mission\Report;
|
||||
|
||||
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
@@ -12,9 +11,11 @@ use Maatwebsite\Excel\Events\AfterSheet;
|
||||
use PhpOffice\PhpSpreadsheet\Exception;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
|
||||
|
||||
class ProvinceReport implements FromView, WithEvents, ShouldAutoSize, WithDrawings
|
||||
class ProvinceReport implements FromView, ShouldAutoSize, WithDrawings, WithEvents
|
||||
{
|
||||
public function __construct(private array $data){}
|
||||
public function __construct(private array $data)
|
||||
{
|
||||
}
|
||||
|
||||
public function view(): View
|
||||
{
|
||||
@@ -22,37 +23,38 @@ class ProvinceReport implements FromView, WithEvents, ShouldAutoSize, WithDrawin
|
||||
$province = null;
|
||||
|
||||
foreach ($this->data as $r) {
|
||||
$cid = (int) $r->city_id;
|
||||
$cid = (int) $r->city_id;
|
||||
$name = $r->city_name;
|
||||
|
||||
if ($cid === -1) {
|
||||
$province = [
|
||||
'city_name' => $name,
|
||||
'no_mission_count' => (int) ($r->no_mission_count ?? 0),
|
||||
'city_name' => $name,
|
||||
'no_mission_count' => (int) ($r->no_mission_count ?? 0),
|
||||
'out_of_area_count' => (int) ($r->out_of_area_count ?? 0),
|
||||
];
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!isset($grid[$cid])) {
|
||||
if (! isset($grid[$cid])) {
|
||||
$grid[$cid] = [
|
||||
'city_name' => $name,
|
||||
];
|
||||
}
|
||||
|
||||
$grid[$cid]['no_mission_count'] = (int) ($r->no_mission_count ?? 0);
|
||||
$grid[$cid]['no_mission_count'] = (int) ($r->no_mission_count ?? 0);
|
||||
$grid[$cid]['out_of_area_count'] = (int) ($r->out_of_area_count ?? 0);
|
||||
|
||||
}
|
||||
|
||||
$exportRows = [];
|
||||
if ($province) $exportRows[] = $province;
|
||||
if ($province) {
|
||||
$exportRows[] = $province;
|
||||
}
|
||||
foreach ($grid as $row) {
|
||||
$exportRows[] = $row;
|
||||
}
|
||||
|
||||
|
||||
return view('v3.Reports.Mission.Report.ProvinceActivityReport', [
|
||||
'rows' => $exportRows,
|
||||
]);
|
||||
@@ -61,7 +63,7 @@ class ProvinceReport implements FromView, WithEvents, ShouldAutoSize, WithDrawin
|
||||
public function registerEvents(): array
|
||||
{
|
||||
return [
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
AfterSheet::class => function (AfterSheet $event) {
|
||||
$event->sheet->getDelegate()->setRightToLeft(true);
|
||||
},
|
||||
];
|
||||
@@ -91,6 +93,7 @@ class ProvinceReport implements FromView, WithEvents, ShouldAutoSize, WithDrawin
|
||||
$drawing2->setOffsetX(5);
|
||||
$drawing2->setOffsetY(5);
|
||||
$drawing2->setCoordinates('C1');
|
||||
|
||||
return [$drawing, $drawing2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
|
||||
use App\Enums\MissionStates;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
@@ -19,16 +18,14 @@ class ControlUnitService
|
||||
$user = Auth::user();
|
||||
|
||||
$query = Mission::query()->whereIn('state_id', [
|
||||
MissionStates::PENDING_CONFIRMATION->value, MissionStates::START_MISSION->value
|
||||
]);
|
||||
MissionStates::PENDING_CONFIRMATION->value, MissionStates::START_MISSION->value,
|
||||
]);
|
||||
|
||||
if ($user->hasPermissionTo('manage-control-unit-station')) {
|
||||
$query->where('station_id', '=', $user->station_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-control-unit-city')) {
|
||||
} elseif ($user->hasPermissionTo('manage-control-unit-city')) {
|
||||
$query->where('city_id', '=', $user->city_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-control-unit-province')) {
|
||||
} elseif ($user->hasPermissionTo('manage-control-unit-province')) {
|
||||
$query->where('province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
@@ -41,8 +38,8 @@ class ControlUnitService
|
||||
'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
|
||||
'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id',
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time',
|
||||
'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name'
|
||||
'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,9 @@ class DailyMoveMachineService
|
||||
|
||||
if ($user->hasPermissionTo('manage-violation-station')) {
|
||||
$query->whereRelation('machine', 'station_id', '=', $user->station_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-violation-city')) {
|
||||
} elseif ($user->hasPermissionTo('manage-violation-city')) {
|
||||
$query->whereRelation('machine', 'city_id', '=', $user->city_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-violation-province')) {
|
||||
} elseif ($user->hasPermissionTo('manage-violation-province')) {
|
||||
$query->whereRelation('machine', 'province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\Mission;
|
||||
use App\Models\MissionViolation;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,7 +14,7 @@ class ReportService
|
||||
{
|
||||
$user = auth()->user();
|
||||
|
||||
$query =MissionViolation::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
||||
$query = MissionViolation::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
||||
|
||||
return DataTableFacade::run(
|
||||
$query,
|
||||
@@ -28,67 +27,68 @@ class ReportService
|
||||
public function countryActivity(Request $request): array
|
||||
{
|
||||
$from = $request->from_date ?? today()->startOfDay();
|
||||
$to = Carbon::parse($request->to_date)->endOfDay()?? today()->endOfDay();
|
||||
$to = Carbon::parse($request->to_date)->endOfDay() ?? today()->endOfDay();
|
||||
|
||||
$sql = "
|
||||
WITH r AS (
|
||||
SELECT
|
||||
p.id AS province_id,
|
||||
p.name_fa AS province_name,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mv.type = 1
|
||||
AND mv.created_at >= :from_mv AND mv.created_at <= :to_mv
|
||||
THEN mv.id
|
||||
END) AS no_mission_count,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN m.mission_duration != m.in_area_duration
|
||||
AND m.created_at >= :from_m AND m.created_at <= :to_m
|
||||
THEN m.id
|
||||
END) AS out_of_area_count
|
||||
|
||||
|
||||
COUNT(DISTINCT mv.id) AS no_mission_count,
|
||||
COUNT(DISTINCT m.id) AS out_of_area_count
|
||||
|
||||
FROM provinces p
|
||||
|
||||
LEFT JOIN cmms_machines cm
|
||||
ON cm.province_id = p.id
|
||||
|
||||
LEFT JOIN mission_violations mv
|
||||
ON TRIM(cm.machine_code) = TRIM(mv.machine_code)
|
||||
AND mv.type = 1
|
||||
AND mv.created_at >= :from_mv
|
||||
AND mv.created_at <= :to_mv
|
||||
|
||||
LEFT JOIN missions m
|
||||
ON m.province_id = p.id
|
||||
|
||||
AND m.mission_duration != m.in_area_duration
|
||||
AND m.created_at >= :from_m
|
||||
AND m.created_at <= :to_m
|
||||
|
||||
GROUP BY p.id, p.name_fa
|
||||
)
|
||||
|
||||
|
||||
SELECT
|
||||
-1 AS province_id,
|
||||
'کل کشور' AS province_name,
|
||||
SUM(no_mission_count) AS no_mission_count,
|
||||
SUM(out_of_area_count) AS out_of_area_count
|
||||
FROM r
|
||||
|
||||
|
||||
UNION ALL
|
||||
|
||||
|
||||
SELECT
|
||||
province_id, province_name, no_mission_count, out_of_area_count
|
||||
FROM r
|
||||
|
||||
|
||||
ORDER BY
|
||||
CASE WHEN province_name = 'کل کشور' THEN 0 ELSE 1 END,
|
||||
CASE WHEN province_id = -1 THEN 0 ELSE 1 END,
|
||||
province_name
|
||||
";
|
||||
";
|
||||
|
||||
return DB::select($sql, [
|
||||
'from_mv' => $from,
|
||||
'to_mv' => $to,
|
||||
'from_m' => $from,
|
||||
'to_m' => $to,
|
||||
'to_mv' => $to,
|
||||
'from_m' => $from,
|
||||
'to_m' => $to,
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinceActivity(Request $request): array
|
||||
{
|
||||
$provinceId = $request->province_id ?? auth()->user()->province_id;
|
||||
$from = $request->from_date ?? today()->startOfDay();
|
||||
$to = Carbon::parse($request->to_date)->endOfDay() ?? today()->endOfDay();
|
||||
$to = Carbon::parse($request->to_date)->endOfDay() ?? today()->endOfDay();
|
||||
|
||||
$sql = "
|
||||
WITH r AS (
|
||||
@@ -96,31 +96,30 @@ class ReportService
|
||||
c.id AS city_id,
|
||||
c.name_fa AS city_name,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN mv.type = 1
|
||||
AND mv.created_at >= :from_mv AND mv.created_at <= :to_mv
|
||||
THEN mv.id
|
||||
END) AS no_mission_count,
|
||||
|
||||
COUNT(DISTINCT CASE
|
||||
WHEN m.mission_duration != m.in_area_duration
|
||||
AND m.created_at >= :from_m AND m.created_at <= :to_m
|
||||
THEN m.id
|
||||
END) AS out_of_area_count
|
||||
COUNT(DISTINCT mv.id) AS no_mission_count,
|
||||
COUNT(DISTINCT m.id) AS out_of_area_count
|
||||
|
||||
FROM cities c
|
||||
|
||||
LEFT JOIN cmms_machines cm
|
||||
ON cm.city_id = c.id
|
||||
|
||||
LEFT JOIN mission_violations mv
|
||||
ON TRIM(cm.machine_code) = TRIM(mv.machine_code)
|
||||
AND mv.type = 1
|
||||
AND mv.created_at >= :from_mv
|
||||
AND mv.created_at <= :to_mv
|
||||
|
||||
LEFT JOIN missions m
|
||||
ON m.city_id = c.id
|
||||
AND m.mission_duration != m.in_area_duration
|
||||
AND m.created_at >= :from_m
|
||||
AND m.created_at <= :to_m
|
||||
|
||||
WHERE c.province_id = :province_id
|
||||
|
||||
AND (
|
||||
c.type_id = 1
|
||||
OR c.name_fa IN ('اداره ماشينآلات', 'اداره نقلیه')
|
||||
)
|
||||
GROUP BY c.id, c.name_fa
|
||||
)
|
||||
|
||||
@@ -145,9 +144,9 @@ class ReportService
|
||||
return DB::select($sql, [
|
||||
'province_id' => $provinceId,
|
||||
'from_mv' => $from,
|
||||
'to_mv' => $to,
|
||||
'from_m' => $from,
|
||||
'to_m' => $to,
|
||||
'to_mv' => $to,
|
||||
'from_m' => $from,
|
||||
'to_m' => $to,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Mission;
|
||||
@@ -19,11 +18,9 @@ class RequestPortalService
|
||||
|
||||
if ($user->hasPermissionTo('manage-request-portal-station')) {
|
||||
$query->where('station_id', '=', $user->station_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-request-portal-city')) {
|
||||
} elseif ($user->hasPermissionTo('manage-request-portal-city')) {
|
||||
$query->where('city_id', '=', $user->city_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-request-portal-province')) {
|
||||
} elseif ($user->hasPermissionTo('manage-request-portal-province')) {
|
||||
$query->where('province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
@@ -36,8 +33,8 @@ class RequestPortalService
|
||||
'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
|
||||
'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id',
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time',
|
||||
'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name'
|
||||
'code', 'category_id', 'category_name', 'explanation', 'city_id', 'city_name', 'province_id', 'station_name',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,9 @@ class TransportationUnitService
|
||||
|
||||
if ($user->hasPermissionTo('manage-transportation-unit-station')) {
|
||||
$query->where('station_id', '=', $user->station_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-transportation-unit-city')) {
|
||||
} elseif ($user->hasPermissionTo('manage-transportation-unit-city')) {
|
||||
$query->where('city_id', '=', $user->city_id);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('manage-transportation-unit-province')) {
|
||||
} elseif ($user->hasPermissionTo('manage-transportation-unit-province')) {
|
||||
$query->where('province_id', '=', $user->province_id);
|
||||
}
|
||||
|
||||
@@ -35,8 +33,8 @@ class TransportationUnitService
|
||||
'id', 'user_id', 'username', 'state_name', 'province_name', 'edare_shahri_name',
|
||||
'description', 'requested_machines', 'type', 'type_fa', 'start_date', 'state_id',
|
||||
'end_date', 'request_date', 'end_point', 'area', 'zone', 'zone_fa', 'start_time', 'finish_time',
|
||||
'code', 'category_id', 'category_name', 'explanation', 'km', 'city_id', 'city_name', 'province_id', 'station_name'
|
||||
'code', 'category_id', 'category_name', 'explanation', 'km', 'city_id', 'city_name', 'province_id', 'station_name',
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user