Merge branch 'feature/ReportDataTables' into 'develop'
Feature/report data tables See merge request witelgroup/rms_v2!101
This commit is contained in:
@@ -19,13 +19,13 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->data;
|
||||
$existedProvinces = array_keys($data['activities']);
|
||||
$existedProvinces = array_keys($data);
|
||||
|
||||
foreach (\App\Models\Province::all() as $value) {
|
||||
$provinceId = $value->id;
|
||||
|
||||
if (!array_key_exists($provinceId, $existedProvinces)) {
|
||||
$data['activities'][] = (object) [
|
||||
$data[] = (object) [
|
||||
'province_id' => $provinceId,
|
||||
'name_fa' => $value->name_fa,
|
||||
'sum' => 0,
|
||||
@@ -37,9 +37,7 @@ class CountryActivityReport implements FromView, WithEvents, ShouldAutoSize, Wit
|
||||
}
|
||||
|
||||
return view('v3.Reports.SafetyAndPrivacy.CountryActivityReport', [
|
||||
'data' => $data['activities'],
|
||||
'fromDate' => $data['fromDate'],
|
||||
'toDate' => $data['toDate'],
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,14 +21,14 @@ class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, Wi
|
||||
public function view(): View
|
||||
{
|
||||
$data = $this->data;
|
||||
$existedCities = array_keys($data['activities']);
|
||||
$existedCities = array_keys($data);
|
||||
$edarat = EdarateShahri::query()->where('province_id', '=', $this->request->province_id)->get(['id', 'name_fa']);
|
||||
|
||||
foreach ($edarat as $value) {
|
||||
$edareId = $value->id;
|
||||
|
||||
if (!array_key_exists($edareId, $existedCities)) {
|
||||
$data['activities'][] = (object) [
|
||||
$data[] = (object) [
|
||||
'edare_shahri_id' => $edareId,
|
||||
'name_fa' => $value->name_fa,
|
||||
'sum' => 0,
|
||||
@@ -40,9 +40,7 @@ class ProvinceActivityReport implements FromView, WithEvents, ShouldAutoSize, Wi
|
||||
}
|
||||
|
||||
return view('v3.Reports.SafetyAndPrivacy.ProvinceActivityReport', [
|
||||
'data' => $data['activities'],
|
||||
'fromDate' => $data['fromDate'],
|
||||
'toDate' => $data['toDate'],
|
||||
'data' => $data,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,8 @@ class DataTable
|
||||
array $allowedFilters = [],
|
||||
array $allowedRelations = [],
|
||||
array $allowedSortings = [],
|
||||
array $allowedSelects = []
|
||||
array $allowedSelects = [],
|
||||
array $allowedGroupBy = []
|
||||
): array
|
||||
{
|
||||
|
||||
@@ -43,7 +44,8 @@ class DataTable
|
||||
$sorting,
|
||||
$rels,
|
||||
$allowedFilters,
|
||||
$allowedSortings
|
||||
$allowedSortings,
|
||||
$allowedGroupBy
|
||||
);
|
||||
|
||||
$query = $this->makeQueryFromModel($mixed);
|
||||
@@ -52,7 +54,8 @@ class DataTable
|
||||
->setAllowedFilters($allowedFilters)
|
||||
->setAllowedRelations($allowedRelations)
|
||||
->setAllowedSortings($allowedSortings)
|
||||
->setAllowedSelects($allowedSelects);
|
||||
->setAllowedSelects($allowedSelects)
|
||||
->setAllowedGroupBy($allowedGroupBy);
|
||||
|
||||
return $dataTableService->getData();
|
||||
}
|
||||
|
||||
@@ -104,4 +104,9 @@ class File
|
||||
fclose($file);
|
||||
return trim($output);
|
||||
}
|
||||
|
||||
public function deleteDirectory(string $path, string $disk = 'public'): void
|
||||
{
|
||||
Storage::disk($disk)->deleteDirectory($path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ class AccidentReceiptController extends Controller
|
||||
|
||||
public function destroy(Accident $accident): JsonResponse
|
||||
{
|
||||
FileFacade::delete('storage/receipts_files/'.$accident->id);
|
||||
FileFacade::deleteDirectory('receipts_files/'.$accident->id);
|
||||
|
||||
DB::transaction(function () use ($accident) {
|
||||
|
||||
@@ -240,9 +240,9 @@ class AccidentReceiptController extends Controller
|
||||
DB::transaction(function () use ($request, $accident) {
|
||||
|
||||
$accident->update([
|
||||
'deposit_insurance_image' => $request->deposit_insurance_image != null ? FileFacade::save($request->deposit_insurance_image, "receipts_files/{$accident->id}/deposit_insurance/") : null,
|
||||
'deposit_insurance_image' => $request->has('deposit_insurance_image') ? FileFacade::save($request->deposit_insurance_image, "receipts_files/{$accident->id}/deposit_insurance") : null,
|
||||
'deposit_insurance_amount' => $request->deposit_insurance_amount ?? 0,
|
||||
'deposit_daghi_image' => $request->deposit_insurance_image != null ? FileFacade::save($request->deposit_daghi_image, "receipts_files/{$accident->id}/deposit_daghi/") : null,
|
||||
'deposit_daghi_image' => $request->has('deposit_daghi_image') ? FileFacade::save($request->deposit_daghi_image, "receipts_files/{$accident->id}/deposit_daghi") : null,
|
||||
'deposit_daghi_amount' => $request->deposit_daghi_amount ?? 0,
|
||||
'status' => AccidentStates::SABT_FISH->value,
|
||||
'status_fa' => AccidentStates::name(AccidentStates::SABT_FISH->value),
|
||||
|
||||
@@ -22,7 +22,7 @@ class SafetyAndPrivacyReportController extends Controller
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->countryActivity($request);
|
||||
return $this->successResponse([
|
||||
'activities' => $data['activities'],
|
||||
'activities' => $data,
|
||||
'provinces' => Province::all(['id', 'name_fa'])
|
||||
]);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ class SafetyAndPrivacyReportController extends Controller
|
||||
{
|
||||
$data = $safetyAndPrivacyTableService->provinceActivity($request);
|
||||
return $this->successResponse([
|
||||
'activities' => $data['activities'],
|
||||
'activities' => $data,
|
||||
'edarateShahri' => EdarateShahri::query()->where('province_id', '=', $request->province_id)->get(['id', 'name_fa']),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@ class RoadMaintenanceStationController extends Controller
|
||||
|
||||
public function images(RahdariPoint $rahdariPoint): JsonResponse
|
||||
{
|
||||
return $this->successResponse($rahdariPoint->files()->get(['path']));
|
||||
return $this->successResponse($rahdariPoint->files()->orderBy('id')->get(['path']));
|
||||
}
|
||||
|
||||
public function map(Request $request): JsonResponse
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\V3\Dashboard;
|
||||
use App\Exports\V3\RoadObservation\ComplaintsReport;
|
||||
use App\Exports\V3\RoadObservation\OperatorCartableReport;
|
||||
use App\Exports\V3\RoadObservation\SupervisorCartableReport;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Facades\File\FileFacade;
|
||||
use App\Facades\Sms\Sms;
|
||||
use App\Http\Controllers\Controller;
|
||||
@@ -24,6 +25,7 @@ use Hekmatinasser\Verta\Verta;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\Cartables\RoadObservationTableService;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use SoapFault;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
@@ -117,8 +119,8 @@ class RoadObservationController extends Controller
|
||||
$roadObserved->files()->where('path', 'like', '%_image_before%')->delete();
|
||||
$roadObserved->files()->where('path', 'like', '%_image_after%')->delete();
|
||||
|
||||
$image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}/");
|
||||
$image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}/");
|
||||
$image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}");
|
||||
$image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}");
|
||||
|
||||
$files_path[0]['path'] = $image_before;
|
||||
$files_path[1]['path'] = $image_after;
|
||||
@@ -135,20 +137,15 @@ class RoadObservationController extends Controller
|
||||
$roadObservedHistoryData['new_files'] = $files;
|
||||
}
|
||||
|
||||
$roadObserved->problemHistories()->create($roadObservedHistoryData);
|
||||
$roadObserved->update($roadObservedData);
|
||||
DB::transaction(function () use ($roadObserved, $roadObservedHistoryData, $roadObservedData, $request, $nikarayanService) {
|
||||
$roadObserved->problemHistories()->create($roadObservedHistoryData);
|
||||
$roadObserved->update($roadObservedData);
|
||||
|
||||
auth()->user()->addActivityComplete(1142);
|
||||
auth()->user()->addActivityComplete(1142);
|
||||
|
||||
try {
|
||||
$nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, json_encode($roadObservedHistoryData['new_files']));
|
||||
}
|
||||
catch (SoapFault $e) {
|
||||
|
||||
$msg = "error in send to nikarayan at" . date("Y-m-d H:i:s") . "\n";
|
||||
$msg .= $e->getMessage();
|
||||
Sms::sendSms(env('RMS_CTO_PHONE_NUMBER'), $msg);
|
||||
}
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
@@ -182,7 +179,7 @@ class RoadObservationController extends Controller
|
||||
if ($roadObserved->image_before) {
|
||||
FileFacade::delete($roadObserved->image_before, true);
|
||||
}
|
||||
$image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}/");
|
||||
$image_before = FileFacade::save($request->image_before, "road_observeds/{$roadObserved->id}");
|
||||
$roadObservedData['image_before'] = $image_before;
|
||||
$files_path[0]['path'] = $image_before;
|
||||
}
|
||||
@@ -191,7 +188,7 @@ class RoadObservationController extends Controller
|
||||
if ($roadObserved->image_after) {
|
||||
FileFacade::delete($roadObserved->image_after, true);
|
||||
}
|
||||
$image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}/");
|
||||
$image_after = FileFacade::save($request->image_after, "road_observeds/{$roadObserved->id}");
|
||||
$roadObservedData['image_after'] = $image_after;
|
||||
$files_path[1]['path'] = $image_after;
|
||||
}
|
||||
@@ -206,20 +203,14 @@ class RoadObservationController extends Controller
|
||||
$roadObservedHistoryData['new_files'] = $files;
|
||||
}
|
||||
|
||||
$roadObserved->problemHistories()->create($roadObservedHistoryData);
|
||||
$roadObserved->update($roadObservedData);
|
||||
DB::transaction(function () use ($roadObserved, $roadObservedHistoryData, $roadObservedData, $request, $nikarayanService) {
|
||||
$roadObserved->problemHistories()->create($roadObservedHistoryData);
|
||||
$roadObserved->update($roadObservedData);
|
||||
|
||||
auth()->user()->addActivityComplete(1142);
|
||||
auth()->user()->addActivityComplete(1142);
|
||||
|
||||
try {
|
||||
$nikarayanService->updateRoadObservedInfoByNikarayan($request, $roadObserved, json_encode($roadObservedHistoryData['new_files']));
|
||||
}
|
||||
catch (SoapFault $e) {
|
||||
|
||||
$msg = "error in send to nikarayan at" . date("Y-m-d H:i:s") . "\n";
|
||||
$msg .= $e->getMessage();
|
||||
Sms::sendSms(env('RMS_CTO_PHONE_NUMBER'), $msg);
|
||||
}
|
||||
});
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
@@ -305,4 +296,15 @@ class RoadObservationController extends Controller
|
||||
|
||||
return $this->successResponse();
|
||||
}
|
||||
|
||||
public function map(Request $request): JsonResponse
|
||||
{
|
||||
return response()->json(DataTableFacade::run(
|
||||
RoadObserved::query(),
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedSelects: ['id', 'lat', 'lng', 'status']
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,16 +24,23 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Throwable;
|
||||
|
||||
class SafetyAndPrivacyController extends Controller
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function index(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): JsonResponse
|
||||
{
|
||||
return response()->json($safetyAndPrivacyTableService->datatable($request));
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function excelReport(Request $request, SafetyAndPrivacyTableService $safetyAndPrivacyTableService): BinaryFileResponse
|
||||
{
|
||||
$name = 'گزارش از نگهداری حریم راه ' . verta()->now()->format('Y-m-d H-i') . '.xlsx';
|
||||
|
||||
@@ -144,56 +144,44 @@ class NotificationController extends Controller
|
||||
'supervise_cnt' => 0
|
||||
];
|
||||
|
||||
$conditions = [];
|
||||
$complaintConditions = [
|
||||
['rms_status', '=', 0],
|
||||
['edarate_shahri_id', '!=', null]
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('show-fast-react')) {
|
||||
$conditions[] = ['status', '=', 2];
|
||||
$road_observations['supervise_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '<>', 0],
|
||||
['status', '=', 0]
|
||||
])->count();
|
||||
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where('rms_status', '=', 0)->count();
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-province')) {
|
||||
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
$conditions = [
|
||||
['status', '=', 2],
|
||||
['rms_province_id', '=', $user->province_id]
|
||||
];
|
||||
$complaintConditions[] = ['province_id', '=', $user->province_id];
|
||||
|
||||
$road_observations['supervise_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '<>', 0],
|
||||
['status', '=', 0],
|
||||
['province_id', '=', $user->province_id]
|
||||
])->count();
|
||||
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '=', 0],
|
||||
['province_id', '=', $user->province_id]
|
||||
])->count();
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-fast-react-edarate-shahri')) {
|
||||
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
$conditions = [
|
||||
|
||||
$road_observations['operation_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '<>', 0],
|
||||
['status', '=', 2],
|
||||
['edarate_shahri_id', '=', $user->edarate_shahri_id]
|
||||
];
|
||||
$complaintConditions[] = ['edarate_shahri_id', '=', $user->edarate_shahri_id];
|
||||
])->count();
|
||||
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where([
|
||||
['rms_status', '=', 0],
|
||||
['edarate_shahri_id', '=', $user->edarate_shahri_id]
|
||||
])->count();
|
||||
}
|
||||
|
||||
if (!empty($conditions)) {
|
||||
$road_observations['operation_cnt'] = RoadObserved::query()->where($conditions)->count();
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count();
|
||||
$road_observations['total'] += $road_observations['operation_cnt'] + $road_observations['complaint_cnt'];
|
||||
}
|
||||
|
||||
$superviseConditions = [
|
||||
['status', '=', 0]
|
||||
];
|
||||
|
||||
if ($user->hasPermissionTo('supervise-fast-react')) {
|
||||
$road_observations['supervise_cnt'] = RoadObserved::query()->where($superviseConditions)->count();
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count();
|
||||
$road_observations['total'] += $road_observations['supervise_cnt'] + $road_observations['complaint_cnt'];
|
||||
}
|
||||
elseif ($user->hasPermissionTo('supervise-fast-react-province')) {
|
||||
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
$superviseConditions[] = ['province_id', '=', $user->province_id];
|
||||
$complaintConditions[] = ['province_id', '=', $user->province_id];
|
||||
|
||||
$road_observations['supervise_cnt'] = RoadObserved::query()->where($superviseConditions)->count();
|
||||
$road_observations['complaint_cnt'] = RoadObserved::query()->where($complaintConditions)->count();
|
||||
$road_observations['total'] += $road_observations['supervise_cnt'] + $road_observations['complaint_cnt'];
|
||||
}
|
||||
$road_observations['total'] += $road_observations['operation_cnt'] + $road_observations['complaint_cnt'] + $road_observations['supervise_cnt'];
|
||||
|
||||
return $road_observations;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ class RahdariPointHistory extends Model
|
||||
*/
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'previous_province_id',
|
||||
'previous_province_name',
|
||||
'previous_city_id',
|
||||
'previous_city_name',
|
||||
'previous_name',
|
||||
'previous_status',
|
||||
'previous_type',
|
||||
'previous_team_num',
|
||||
|
||||
@@ -108,14 +108,20 @@ class RoadObserved extends Model
|
||||
protected function imageAfter(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
|
||||
get: fn($value) => $value == null ? null :
|
||||
(filter_var($value, FILTER_VALIDATE_URL)
|
||||
? $value
|
||||
: Storage::disk('public')->url($value))
|
||||
);
|
||||
}
|
||||
|
||||
protected function imageBefore(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn($value) => $value == null ? null : Storage::disk('public')->url($value)
|
||||
get: fn($value) => $value == null ? null :
|
||||
(filter_var($value, FILTER_VALIDATE_URL)
|
||||
? $value
|
||||
: Storage::disk('public')->url($value))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ class RoadItemTableService
|
||||
$allowedSortings = ['*'];
|
||||
|
||||
$query = RoadItemsProject::query()
|
||||
->select(['id', 'supervisor_description', 'item', 'item_fa', 'sub_item', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng',
|
||||
->select(['id', 'province_fa', 'edarat_name', 'supervisor_description', 'item', 'item_fa', 'sub_item', 'sub_item_fa', 'sub_item_data', 'unit_fa', 'start_lat', 'start_lng',
|
||||
'end_lat', 'end_lng', 'activity_date_time', 'created_at', 'status_fa', 'status'])
|
||||
->where('is_new', 1)
|
||||
->where('user_id', auth()->user()->id)
|
||||
|
||||
@@ -2,17 +2,22 @@
|
||||
|
||||
namespace App\Services\Cartables;
|
||||
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Http\Traits\ApiResponse;
|
||||
use App\Models\Province;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Throwable;
|
||||
|
||||
class SafetyAndPrivacyTableService
|
||||
{
|
||||
use ApiResponse;
|
||||
|
||||
/**
|
||||
* @throws Throwable
|
||||
*/
|
||||
public function dataTable(Request $request, $loadRelations = false)
|
||||
{
|
||||
$user = auth()->user();
|
||||
@@ -27,16 +32,12 @@ class SafetyAndPrivacyTableService
|
||||
$query = SafetyAndPrivacy::query()->select($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-province')) {
|
||||
if (is_null($user->province_id)) {
|
||||
return $this->errorResponse('استانی برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
throw_if(is_null($user->province_id), new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$query = SafetyAndPrivacy::query()->where('province_id', '=', $user->province_id)->select($fields);
|
||||
}
|
||||
elseif ($user->hasPermissionTo('show-safety-and-privacy-operator-cartable-edarate-shahri')) {
|
||||
if (is_null($user->edarate_shahri_id)) {
|
||||
return $this->errorResponse('اداره ای برای شما در سامانه ثبت نشده است!');
|
||||
}
|
||||
throw_if(is_null($user->edarate_shahri_id), new ProhibitedAction('اداره ای برای شما در سامانه ثبت نشده است!'));
|
||||
|
||||
$query = SafetyAndPrivacy::query()->where('edare_shahri_id', '=', $user->edarate_shahri_id);
|
||||
}
|
||||
@@ -51,74 +52,45 @@ class SafetyAndPrivacyTableService
|
||||
|
||||
public function countryActivity(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();
|
||||
$axisTypeId = $request->axis_type_id;
|
||||
|
||||
$activities = [];
|
||||
$countryQuery = SafetyAndPrivacy::query()->selectRaw('COUNT(*) as qty,info_id, step');
|
||||
|
||||
$country = SafetyAndPrivacy::query()
|
||||
->selectRaw('COUNT(*) as qty,info_id, step')
|
||||
->whereBetween('created_at', [$fromDate, $toDate])
|
||||
->when($axisTypeId, function ($query) use ($axisTypeId) {
|
||||
$query->where('axis_type_id', '=', $axisTypeId);
|
||||
})
|
||||
->groupBy('info_id', 'step')
|
||||
->get();
|
||||
|
||||
// $country = DB::select(
|
||||
// "SELECT COUNT(*) as qty,info_id, step
|
||||
// FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."'
|
||||
// GROUP BY info_id,step"
|
||||
// );
|
||||
$country = DataTableFacade::run(
|
||||
$countryQuery,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedGroupBy: ['info_id', 'step']
|
||||
);
|
||||
|
||||
$countryTotalSum = 0;
|
||||
$countryData = [
|
||||
'name_fa' => 'کشوری',
|
||||
'province_id' => -1,
|
||||
'sum' => 0,
|
||||
'89' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'90' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'91' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'89' => ['1' => 0, '2' => 0, '3' => 0,],
|
||||
'90' => ['1' => 0, '2' => 0, '3' => 0,],
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0,],
|
||||
];
|
||||
foreach ($country as $key => $value) {
|
||||
foreach ($country['data'] as $key => $value) {
|
||||
$countryTotalSum += $value->qty;
|
||||
$countryData[$value->info_id][$value->step] = $value->qty;
|
||||
$countryData["sum"] = $countryTotalSum;
|
||||
}
|
||||
|
||||
$activities[] = (object) $countryData;
|
||||
$provinceQuery = SafetyAndPrivacy::query()->selectRaw('province_id, province_fa, COUNT(*) as qty,info_id, step');
|
||||
$provinces = DataTableFacade::run(
|
||||
$provinceQuery,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedGroupBy: ['info_id', 'step', 'province_id', 'province_fa']
|
||||
);
|
||||
|
||||
$provinces = SafetyAndPrivacy::query()
|
||||
->selectRaw('province_id, province_fa, COUNT(*) as qty,info_id, step')
|
||||
->whereBetween('created_at', [$fromDate, $toDate])
|
||||
->when($axisTypeId, function ($query) use ($axisTypeId) {
|
||||
$query->where('axis_type_id', '=', $axisTypeId);
|
||||
})
|
||||
->groupBy('info_id', 'step', 'province_id', 'province_fa')
|
||||
->get();
|
||||
|
||||
// $provinces = DB::select(
|
||||
// "SELECT province_id, province_fa, COUNT(*) as qty,info_id, step
|
||||
// FROM safety_and_privacy where created_at BETWEEN '".$fromDate."' and '".$toDate."'
|
||||
// GROUP BY info_id,step,province_id,province_fa"
|
||||
// );
|
||||
|
||||
foreach ($provinces as $value) {
|
||||
foreach ($provinces['data'] as $value)
|
||||
{
|
||||
$provinceId = $value->province_id;
|
||||
|
||||
// Check if the province already exists in the activities array
|
||||
if (!isset($activities[$provinceId])) {
|
||||
$activities[$provinceId] = (object) [
|
||||
'province_id' => $provinceId,
|
||||
@@ -129,92 +101,53 @@ class SafetyAndPrivacyTableService
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0],
|
||||
];
|
||||
}
|
||||
|
||||
$activities[$provinceId]->{$value->info_id}[$value->step] = $value->qty;
|
||||
$activities[$provinceId]->sum += $value->qty;
|
||||
}
|
||||
|
||||
$activities = array_values($activities);
|
||||
|
||||
return [
|
||||
'activities' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
];
|
||||
return array_values($activities);
|
||||
}
|
||||
|
||||
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;
|
||||
$axisTypeId = $request->axis_type_id;
|
||||
$activities = [];
|
||||
|
||||
$province = SafetyAndPrivacy::query()
|
||||
->selectRaw('COUNT(*) as qty,info_id, step')
|
||||
->where('province_id', '=', $provinceId)
|
||||
->whereBetween('created_at', [$fromDate, $toDate])
|
||||
->when($axisTypeId, function ($query) use ($axisTypeId) {
|
||||
$query->where('axis_type_id', '=', $axisTypeId);
|
||||
})
|
||||
->groupBy('info_id', 'step')
|
||||
->get();
|
||||
|
||||
// $province = DB::select('
|
||||
// SELECT COUNT(*) as qty,info_id, step
|
||||
// FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'"
|
||||
// GROUP BY info_id,step
|
||||
// ');
|
||||
$provinceQuery = SafetyAndPrivacy::query()->selectRaw('COUNT(*) as qty,info_id, step');
|
||||
$province = DataTableFacade::run(
|
||||
$provinceQuery,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedGroupBy: ['info_id', 'step']
|
||||
);
|
||||
|
||||
$provinceTotalSum = 0;
|
||||
$provinceData = [
|
||||
'name_fa' => 'استانی',
|
||||
'edare_shahri_id' => -1,
|
||||
'sum' => 0,
|
||||
'89' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'90' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'91' => [
|
||||
'1' => 0,
|
||||
'2' => 0,
|
||||
'3' => 0,
|
||||
],
|
||||
'89' => ['1' => 0, '2' => 0, '3' => 0,],
|
||||
'90' => ['1' => 0, '2' => 0, '3' => 0,],
|
||||
'91' => ['1' => 0, '2' => 0, '3' => 0,],
|
||||
];
|
||||
foreach ($province as $key => $value) {
|
||||
foreach ($province['data'] as $key => $value) {
|
||||
$provinceTotalSum += $value->qty;
|
||||
$provinceData["sum"] = $provinceTotalSum;
|
||||
$provinceData[$value->info_id][$value->step] = $value->qty;
|
||||
}
|
||||
$activities[] = (object) $provinceData;
|
||||
|
||||
$cities = SafetyAndPrivacy::query()
|
||||
->selectRaw('edare_shahri_id, COUNT(*) as qty,info_id, step')
|
||||
->where('province_id', '=', $provinceId)
|
||||
->whereBetween('created_at', [$fromDate, $toDate])
|
||||
->when($axisTypeId, function ($query) use ($axisTypeId) {
|
||||
$query->where('axis_type_id', '=', $axisTypeId);
|
||||
})
|
||||
->groupBy('info_id', 'step', 'edare_shahri_id')
|
||||
->get();
|
||||
$citiesQuery = SafetyAndPrivacy::query()->selectRaw('edare_shahri_id, COUNT(*) as qty,info_id, step');
|
||||
$cities = DataTableFacade::run(
|
||||
$citiesQuery,
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
allowedGroupBy: ['info_id', 'step', 'edare_shahri_id']
|
||||
);
|
||||
|
||||
// $cities = DB::select('
|
||||
// SELECT edare_shahri_id, COUNT(*) as qty,info_id, step
|
||||
// FROM safety_and_privacy where province_id ='.$provinceId.' and created_at BETWEEN "'.$fromDate.'" and "'.$toDate.'"
|
||||
// GROUP BY info_id,step,edare_shahri_id
|
||||
// ');
|
||||
|
||||
foreach ($cities as $value) {
|
||||
foreach ($cities['data'] as $value)
|
||||
{
|
||||
$cityId = $value->edare_shahri_id;
|
||||
|
||||
// Initialize data for each unique city
|
||||
if (!isset($activities[$cityId])) {
|
||||
$activities[$cityId] = (object) [
|
||||
'edare_shahri_id' => $cityId,
|
||||
@@ -229,12 +162,6 @@ class SafetyAndPrivacyTableService
|
||||
$activities[$cityId]->sum += $value->qty;
|
||||
}
|
||||
|
||||
$activities = array_values($activities);
|
||||
|
||||
return [
|
||||
'activities' => $activities,
|
||||
'fromDate' => $fromDate,
|
||||
'toDate' => $toDate,
|
||||
];
|
||||
return array_values($activities);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ class DataTableInput
|
||||
private array $rels,
|
||||
private array $allowedFilters,
|
||||
private array $allowedSortings,
|
||||
private ?array $GroupBy,
|
||||
)
|
||||
{
|
||||
}
|
||||
@@ -74,4 +75,9 @@ class DataTableInput
|
||||
{
|
||||
return $this->rels;
|
||||
}
|
||||
|
||||
public function getGroupBy(): ?array
|
||||
{
|
||||
return $this->GroupBy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ class DataTableService
|
||||
protected array $allowedRelations;
|
||||
protected array $allowedSortings;
|
||||
protected array $allowedSelects;
|
||||
protected array $allowedGroupBy;
|
||||
private int $totalRowCount;
|
||||
|
||||
public function __construct(
|
||||
@@ -46,6 +47,12 @@ class DataTableService
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAllowedGroupBy(array $allowedGroupBy): DataTableService
|
||||
{
|
||||
$this->allowedGroupBy = $allowedGroupBy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle 'getData' operations
|
||||
* @return array
|
||||
@@ -73,6 +80,7 @@ class DataTableService
|
||||
|
||||
$query = $this->applySelect($query, $this->allowedSelects);
|
||||
$query = $this->includeRelationsInQuery($query, $this->allowedRelations);
|
||||
$query = $this->applyGroupBy($query, $this->allowedGroupBy);
|
||||
|
||||
$this->totalRowCount = $query->count();
|
||||
|
||||
@@ -88,7 +96,7 @@ class DataTableService
|
||||
foreach ($sorting as $sort){
|
||||
$query = (new ApplySort($query, $sort))->apply();
|
||||
}
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
@@ -101,6 +109,11 @@ class DataTableService
|
||||
return $query;
|
||||
}
|
||||
|
||||
protected function applyGroupBy(Builder $query, array $groupBy): Builder
|
||||
{
|
||||
return empty($groupBy) ? $query : $query->groupBy($groupBy);
|
||||
}
|
||||
|
||||
protected function includeRelationsInQuery(Builder $query, array $rels): Builder
|
||||
{
|
||||
if (!empty($rels)) {
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
<td style="border: 1px solid black;text-align: center;">
|
||||
{{ $item['sub_item_data'] ? ($item['unit_fa'] ? $item['sub_item_data'] . '(' . $item['unit_fa'] . ')' : $item['sub_item_data'] . '(-)') : '-' }}
|
||||
</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">
|
||||
{{ isset($item['start_lat']) && isset($item['start_lng']) ? $item['start_lat'] . ' ' . $item['start_lng'] : '-' }}
|
||||
@@ -114,5 +114,4 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
<td style="border: 1px solid black;text-align: center;">
|
||||
{{ $item['sub_item_data'] ? ($item['unit_fa'] ? $item['sub_item_data'] . '(' . $item['unit_fa'] . ')' : $item['sub_item_data'] . '(-)') : '-' }}
|
||||
</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">
|
||||
{{ isset($item['start_lat']) && isset($item['start_lng']) ? $item['start_lat'] . ' ' . $item['start_lng'] : '-' }}
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['id'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['province_fa'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['edare_name'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['start_time'] ? verta($item['start_time'])->format('Y/n/j H:i:s') : '-' }}
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['end_time'] ? verta($item['end_time'])->format('Y/n/j H:i:s') : '-' }}
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="9"
|
||||
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13;">
|
||||
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">
|
||||
گزارش کارتابل ارزیابی گشت راهداری
|
||||
</th>
|
||||
</tr>
|
||||
@@ -74,7 +74,7 @@
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['id'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['province_fa'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['edare_name'] ?? '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmms_machines'] != null ? $item['cmms_machines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['cmmsMachines'] != null ? $item['cmmsMachines']->pluck('machine_code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['rahdaran'] != null ? $item['rahdaran']->pluck('code')->implode(', ') : '-' }}</td>
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['start_time'] ? verta($item['start_time'])->format('Y/n/j H:i:s') : '-' }}
|
||||
<td style="border: 1px solid black;text-align: center;">{{ $item['end_time'] ? verta($item['end_time'])->format('Y/n/j H:i:s') : '-' }}
|
||||
|
||||
@@ -28,12 +28,7 @@
|
||||
<tr>
|
||||
<th colspan="11"
|
||||
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">
|
||||
گزارش نگهداری حریم راه از تاریخ
|
||||
{{ verta($fromDate)->format('Y/n/j') }}
|
||||
تا
|
||||
تاریخ
|
||||
{{ verta($toDate)->format('Y/n/j') }}
|
||||
|
||||
گزارش نگهداری حریم راه
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -27,13 +27,8 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<th colspan="11"
|
||||
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') }}
|
||||
|
||||
style="background-color: #DAEEF3;text-align: center;border-right:1px solid black;font-weight:bolder;font-size: 13px;">
|
||||
گزارش نگهداری حریم راه
|
||||
</th>
|
||||
</tr>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user