diff --git a/app/Http/Controllers/BranchesController.php b/app/Http/Controllers/BranchesController.php new file mode 100644 index 0000000..d4d37b6 --- /dev/null +++ b/app/Http/Controllers/BranchesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(BranchesController::class, 'index', ' Branches index'); + $data = Branches::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.branches.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(BranchesController::class, 'create', ' Branches create'); + $TableData = Branches::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.branches.create",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(BranchesController::class, 'store', ' Branches store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_branches')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(BranchesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Branches Created Successfully.'], 200); + } + return redirect()->route('branches.index')->with('success','The Branches created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Branches::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Branches::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(BranchesController::class, 'show', ' Branches show'); + $data = Branches::findOrFail($id); + + return view("crud.generated.branches.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(BranchesController::class, 'edit', ' Branches edit'); + $TableData = Branches::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Branches::findOrFail($id); + $editable=true; + return view("crud.generated.branches.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(BranchesController::class, 'update', ' Branches update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('branch_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(BranchesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Branches updated Successfully.'], 200); + } + // return redirect()->route('branches.index')->with('success','The Branches updated Successfully.'); + return redirect()->back()->with('success', 'The Branches updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(BranchesController::class, 'destroy', ' Branches destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(BranchesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Branches Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(BranchesController::class, 'destroy', ' Branches destroy'); + $data = Branches::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(BranchesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Branches Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(BranchesController::class, 'clone', ' Branches clone'); + $data = Branches::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(BranchesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Branches Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/CastesController.php b/app/Http/Controllers/CastesController.php new file mode 100644 index 0000000..01652e6 --- /dev/null +++ b/app/Http/Controllers/CastesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(CastesController::class, 'index', ' Castes index'); + $data = Castes::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.castes.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(CastesController::class, 'create', ' Castes create'); + $TableData = Castes::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.castes.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(CastesController::class, 'store', ' Castes store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_castes')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CastesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Castes Created Successfully.'], 200); + } + return redirect()->route('castes.index')->with('success','The Castes created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Castes::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Castes::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(CastesController::class, 'show', ' Castes show'); + $data = Castes::findOrFail($id); + + return view("crud.generated.castes.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(CastesController::class, 'edit', ' Castes edit'); + $TableData = Castes::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Castes::findOrFail($id); + $editable=true; + return view("crud.generated.castes.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(CastesController::class, 'update', ' Castes update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('caste_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CastesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Castes updated Successfully.'], 200); + } + // return redirect()->route('castes.index')->with('success','The Castes updated Successfully.'); + return redirect()->back()->with('success', 'The Castes updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(CastesController::class, 'destroy', ' Castes destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CastesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Castes Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(CastesController::class, 'destroy', ' Castes destroy'); + $data = Castes::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CastesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Castes Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(CastesController::class, 'clone', ' Castes clone'); + $data = Castes::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CastesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Castes Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/CitiesController.php b/app/Http/Controllers/CitiesController.php new file mode 100644 index 0000000..87a743f --- /dev/null +++ b/app/Http/Controllers/CitiesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(CitiesController::class, 'index', ' Cities index'); + $data = Cities::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.cities.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(CitiesController::class, 'create', ' Cities create'); + $TableData = Cities::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.cities.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(CitiesController::class, 'store', ' Cities store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_cities')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CitiesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Cities Created Successfully.'], 200); + } + return redirect()->route('cities.index')->with('success','The Cities created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Cities::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Cities::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(CitiesController::class, 'show', ' Cities show'); + $data = Cities::findOrFail($id); + + return view("crud.generated.cities.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(CitiesController::class, 'edit', ' Cities edit'); + $TableData = Cities::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Cities::findOrFail($id); + $editable=true; + return view("crud.generated.cities.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(CitiesController::class, 'update', ' Cities update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('city_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CitiesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Cities updated Successfully.'], 200); + } + // return redirect()->route('cities.index')->with('success','The Cities updated Successfully.'); + return redirect()->back()->with('success', 'The Cities updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(CitiesController::class, 'destroy', ' Cities destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CitiesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Cities Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(CitiesController::class, 'destroy', ' Cities destroy'); + $data = Cities::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CitiesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Cities Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(CitiesController::class, 'clone', ' Cities clone'); + $data = Cities::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CitiesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Cities Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/CompaniesController.php b/app/Http/Controllers/CompaniesController.php new file mode 100644 index 0000000..4ed27cf --- /dev/null +++ b/app/Http/Controllers/CompaniesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(CompaniesController::class, 'index', ' Companies index'); + $data = Companies::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.companies.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(CompaniesController::class, 'create', ' Companies create'); + $TableData = Companies::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.companies.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(CompaniesController::class, 'store', ' Companies store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_companies')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompaniesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Companies Created Successfully.'], 200); + } + return redirect()->route('companies.index')->with('success','The Companies created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Companies::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Companies::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(CompaniesController::class, 'show', ' Companies show'); + $data = Companies::findOrFail($id); + + return view("crud.generated.companies.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(CompaniesController::class, 'edit', ' Companies edit'); + $TableData = Companies::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Companies::findOrFail($id); + $editable=true; + return view("crud.generated.companies.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(CompaniesController::class, 'update', ' Companies update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('company_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompaniesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Companies updated Successfully.'], 200); + } + // return redirect()->route('companies.index')->with('success','The Companies updated Successfully.'); + return redirect()->back()->with('success', 'The Companies updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(CompaniesController::class, 'destroy', ' Companies destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompaniesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Companies Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(CompaniesController::class, 'destroy', ' Companies destroy'); + $data = Companies::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompaniesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Companies Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(CompaniesController::class, 'clone', ' Companies clone'); + $data = Companies::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompaniesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Companies Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/CompanytypesController.php b/app/Http/Controllers/CompanytypesController.php new file mode 100644 index 0000000..352c96f --- /dev/null +++ b/app/Http/Controllers/CompanytypesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(CompanytypesController::class, 'index', ' Companytypes index'); + $data = Companytypes::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.companytypes.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(CompanytypesController::class, 'create', ' Companytypes create'); + $TableData = Companytypes::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.companytypes.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(CompanytypesController::class, 'store', ' Companytypes store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_companytypes')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompanytypesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Companytypes Created Successfully.'], 200); + } + return redirect()->route('companytypes.index')->with('success','The Companytypes created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Companytypes::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Companytypes::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(CompanytypesController::class, 'show', ' Companytypes show'); + $data = Companytypes::findOrFail($id); + + return view("crud.generated.companytypes.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(CompanytypesController::class, 'edit', ' Companytypes edit'); + $TableData = Companytypes::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Companytypes::findOrFail($id); + $editable=true; + return view("crud.generated.companytypes.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(CompanytypesController::class, 'update', ' Companytypes update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('companytype_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompanytypesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Companytypes updated Successfully.'], 200); + } + // return redirect()->route('companytypes.index')->with('success','The Companytypes updated Successfully.'); + return redirect()->back()->with('success', 'The Companytypes updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(CompanytypesController::class, 'destroy', ' Companytypes destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompanytypesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Companytypes Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(CompanytypesController::class, 'destroy', ' Companytypes destroy'); + $data = Companytypes::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompanytypesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Companytypes Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(CompanytypesController::class, 'clone', ' Companytypes clone'); + $data = Companytypes::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CompanytypesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Companytypes Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/CountriesController.php b/app/Http/Controllers/CountriesController.php new file mode 100644 index 0000000..5a66f25 --- /dev/null +++ b/app/Http/Controllers/CountriesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(CountriesController::class, 'index', ' Countries index'); + $data = Countries::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.countries.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(CountriesController::class, 'create', ' Countries create'); + $TableData = Countries::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.countries.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(CountriesController::class, 'store', ' Countries store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_countries')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CountriesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Countries Created Successfully.'], 200); + } + return redirect()->route('countries.index')->with('success','The Countries created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Countries::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Countries::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(CountriesController::class, 'show', ' Countries show'); + $data = Countries::findOrFail($id); + + return view("crud.generated.countries.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(CountriesController::class, 'edit', ' Countries edit'); + $TableData = Countries::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Countries::findOrFail($id); + $editable=true; + return view("crud.generated.countries.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(CountriesController::class, 'update', ' Countries update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('country_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CountriesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Countries updated Successfully.'], 200); + } + // return redirect()->route('countries.index')->with('success','The Countries updated Successfully.'); + return redirect()->back()->with('success', 'The Countries updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(CountriesController::class, 'destroy', ' Countries destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CountriesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Countries Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(CountriesController::class, 'destroy', ' Countries destroy'); + $data = Countries::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CountriesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Countries Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(CountriesController::class, 'clone', ' Countries clone'); + $data = Countries::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(CountriesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Countries Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/DagsController.php b/app/Http/Controllers/DagsController.php new file mode 100644 index 0000000..f4e544f --- /dev/null +++ b/app/Http/Controllers/DagsController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(DagsController::class, 'index', ' Dags index'); + $data = Dags::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.dags.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(DagsController::class, 'create', ' Dags create'); + $TableData = Dags::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.dags.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(DagsController::class, 'store', ' Dags store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_dags')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DagsController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Dags Created Successfully.'], 200); + } + return redirect()->route('dags.index')->with('success','The Dags created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Dags::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Dags::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(DagsController::class, 'show', ' Dags show'); + $data = Dags::findOrFail($id); + + return view("crud.generated.dags.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(DagsController::class, 'edit', ' Dags edit'); + $TableData = Dags::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Dags::findOrFail($id); + $editable=true; + return view("crud.generated.dags.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(DagsController::class, 'update', ' Dags update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('dag_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DagsController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Dags updated Successfully.'], 200); + } + // return redirect()->route('dags.index')->with('success','The Dags updated Successfully.'); + return redirect()->back()->with('success', 'The Dags updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(DagsController::class, 'destroy', ' Dags destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DagsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Dags Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(DagsController::class, 'destroy', ' Dags destroy'); + $data = Dags::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DagsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Dags Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(DagsController::class, 'clone', ' Dags clone'); + $data = Dags::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DagsController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Dags Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/DepartmentsController.php b/app/Http/Controllers/DepartmentsController.php new file mode 100644 index 0000000..4c42e42 --- /dev/null +++ b/app/Http/Controllers/DepartmentsController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(DepartmentsController::class, 'index', ' Departments index'); + $data = Departments::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.departments.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(DepartmentsController::class, 'create', ' Departments create'); + $TableData = Departments::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.departments.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(DepartmentsController::class, 'store', ' Departments store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_departments')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DepartmentsController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Departments Created Successfully.'], 200); + } + return redirect()->route('departments.index')->with('success','The Departments created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Departments::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Departments::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(DepartmentsController::class, 'show', ' Departments show'); + $data = Departments::findOrFail($id); + + return view("crud.generated.departments.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(DepartmentsController::class, 'edit', ' Departments edit'); + $TableData = Departments::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Departments::findOrFail($id); + $editable=true; + return view("crud.generated.departments.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(DepartmentsController::class, 'update', ' Departments update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('department_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DepartmentsController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Departments updated Successfully.'], 200); + } + // return redirect()->route('departments.index')->with('success','The Departments updated Successfully.'); + return redirect()->back()->with('success', 'The Departments updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(DepartmentsController::class, 'destroy', ' Departments destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DepartmentsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Departments Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(DepartmentsController::class, 'destroy', ' Departments destroy'); + $data = Departments::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DepartmentsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Departments Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(DepartmentsController::class, 'clone', ' Departments clone'); + $data = Departments::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DepartmentsController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Departments Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/DesignationsController.php b/app/Http/Controllers/DesignationsController.php new file mode 100644 index 0000000..7add074 --- /dev/null +++ b/app/Http/Controllers/DesignationsController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(DesignationsController::class, 'index', ' Designations index'); + $data = Designations::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.designations.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(DesignationsController::class, 'create', ' Designations create'); + $TableData = Designations::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.designations.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(DesignationsController::class, 'store', ' Designations store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_designations')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DesignationsController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Designations Created Successfully.'], 200); + } + return redirect()->route('designations.index')->with('success','The Designations created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Designations::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Designations::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(DesignationsController::class, 'show', ' Designations show'); + $data = Designations::findOrFail($id); + + return view("crud.generated.designations.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(DesignationsController::class, 'edit', ' Designations edit'); + $TableData = Designations::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Designations::findOrFail($id); + $editable=true; + return view("crud.generated.designations.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(DesignationsController::class, 'update', ' Designations update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('designation_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DesignationsController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Designations updated Successfully.'], 200); + } + // return redirect()->route('designations.index')->with('success','The Designations updated Successfully.'); + return redirect()->back()->with('success', 'The Designations updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(DesignationsController::class, 'destroy', ' Designations destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DesignationsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Designations Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(DesignationsController::class, 'destroy', ' Designations destroy'); + $data = Designations::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DesignationsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Designations Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(DesignationsController::class, 'clone', ' Designations clone'); + $data = Designations::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DesignationsController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Designations Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/DistrictsController.php b/app/Http/Controllers/DistrictsController.php new file mode 100644 index 0000000..14ecb3b --- /dev/null +++ b/app/Http/Controllers/DistrictsController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(DistrictsController::class, 'index', ' Districts index'); + $data = Districts::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.districts.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(DistrictsController::class, 'create', ' Districts create'); + $TableData = Districts::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.districts.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(DistrictsController::class, 'store', ' Districts store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_districts')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DistrictsController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Districts Created Successfully.'], 200); + } + return redirect()->route('districts.index')->with('success','The Districts created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Districts::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Districts::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(DistrictsController::class, 'show', ' Districts show'); + $data = Districts::findOrFail($id); + + return view("crud.generated.districts.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(DistrictsController::class, 'edit', ' Districts edit'); + $TableData = Districts::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Districts::findOrFail($id); + $editable=true; + return view("crud.generated.districts.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(DistrictsController::class, 'update', ' Districts update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('district_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DistrictsController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Districts updated Successfully.'], 200); + } + // return redirect()->route('districts.index')->with('success','The Districts updated Successfully.'); + return redirect()->back()->with('success', 'The Districts updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(DistrictsController::class, 'destroy', ' Districts destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DistrictsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Districts Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(DistrictsController::class, 'destroy', ' Districts destroy'); + $data = Districts::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DistrictsController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Districts Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(DistrictsController::class, 'clone', ' Districts clone'); + $data = Districts::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(DistrictsController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Districts Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/EthnicitiesController.php b/app/Http/Controllers/EthnicitiesController.php new file mode 100644 index 0000000..c11a38d --- /dev/null +++ b/app/Http/Controllers/EthnicitiesController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(EthnicitiesController::class, 'index', ' Ethnicities index'); + $data = Ethnicities::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.ethnicities.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(EthnicitiesController::class, 'create', ' Ethnicities create'); + $TableData = Ethnicities::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.ethnicities.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(EthnicitiesController::class, 'store', ' Ethnicities store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_ethnicities')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(EthnicitiesController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Ethnicities Created Successfully.'], 200); + } + return redirect()->route('ethnicities.index')->with('success','The Ethnicities created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Ethnicities::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Ethnicities::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(EthnicitiesController::class, 'show', ' Ethnicities show'); + $data = Ethnicities::findOrFail($id); + + return view("crud.generated.ethnicities.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(EthnicitiesController::class, 'edit', ' Ethnicities edit'); + $TableData = Ethnicities::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Ethnicities::findOrFail($id); + $editable=true; + return view("crud.generated.ethnicities.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(EthnicitiesController::class, 'update', ' Ethnicities update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('ethnicity_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(EthnicitiesController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Ethnicities updated Successfully.'], 200); + } + // return redirect()->route('ethnicities.index')->with('success','The Ethnicities updated Successfully.'); + return redirect()->back()->with('success', 'The Ethnicities updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(EthnicitiesController::class, 'destroy', ' Ethnicities destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(EthnicitiesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Ethnicities Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(EthnicitiesController::class, 'destroy', ' Ethnicities destroy'); + $data = Ethnicities::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(EthnicitiesController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Ethnicities Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(EthnicitiesController::class, 'clone', ' Ethnicities clone'); + $data = Ethnicities::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(EthnicitiesController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Ethnicities Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/GendersController.php b/app/Http/Controllers/GendersController.php new file mode 100644 index 0000000..569784b --- /dev/null +++ b/app/Http/Controllers/GendersController.php @@ -0,0 +1,218 @@ +modelService = new CommonModelService($model); + } + public function index(Request $request) + { + createActivityLog(GendersController::class, 'index', ' Genders index'); + $data = Genders::where('status','<>',-1)->orderBy('display_order')->get(); + + return view("crud.generated.genders.index", compact('data')); + } + + public function create(Request $request) + { + createActivityLog(GendersController::class, 'create', ' Genders create'); + $TableData = Genders::where('status','<>',-1)->orderBy('display_order')->get(); + $editable=false; + return view("crud.generated.genders.edit",compact('TableData','editable')); + } + + public function store(Request $request) + { + createActivityLog(GendersController::class, 'store', ' Genders store'); + $validator = Validator::make($request->all(), [ + //ADD REQUIRED FIELDS FOR VALIDATION + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $request->request->add(['alias' => slugify($request->title)]); + $request->request->add(['display_order' => getDisplayOrder('tbl_genders')]); + $request->request->add(['created_at' => date("Y-m-d h:i:s")]); + $request->request->add(['updated_at' => date("Y-m-d h:i:s")]); + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $operationNumber = getOperationNumber(); + $this->modelService->create($operationNumber, $operationNumber, null, $requestData); + } catch (\Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(GendersController::class, 'store', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Genders Created Successfully.'], 200); + } + return redirect()->route('genders.index')->with('success','The Genders created Successfully.'); + } + + public function sort(Request $request) + { + $idOrder = $request->input('id_order'); + + foreach ($idOrder as $index => $id) { + $companyArticle = Genders::find($id); + $companyArticle->display_order = $index + 1; + $companyArticle->save(); + } + + return response()->json(['status' => true, 'content' => 'The articles sorted successfully.'], 200); + } + public function updatealias(Request $request) + { + + $articleId = $request->input('articleId'); + $newAlias = $request->input('newAlias'); + $companyArticle = Genders::find($articleId); + if (!$companyArticle) { + return response()->json(['status' => false, 'content' => 'Company article not found.'], 404); + } + $companyArticle->alias = $newAlias; + $companyArticle->save(); + return response()->json(['status' => true, 'content' => 'Alias updated successfully.'], 200); + } + + + + + public function show(Request $request, $id) + { + createActivityLog(GendersController::class, 'show', ' Genders show'); + $data = Genders::findOrFail($id); + + return view("crud.generated.genders.show", compact('data')); + } + + + public function edit(Request $request, $id) + { + createActivityLog(GendersController::class, 'edit', ' Genders edit'); + $TableData = Genders::where('status','<>',-1)->orderBy('display_order')->get(); + $data = Genders::findOrFail($id); + $editable=true; + return view("crud.generated.genders.edit", compact('data','TableData','editable')); + } + + + public function update(Request $request, $id) + { + createActivityLog(GendersController::class, 'update', ' Genders update'); + $validator = Validator::make($request->all(), [ + //ADD VALIDATION FOR REQIRED FIELDS + ]); + + if ($validator->fails()) { + return response()->json([ + 'error' => $validator->errors(), + ],500); + } + $requestData=$request->all(); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL').'/', '', $value); + }); + array_walk_recursive($requestData, function (&$value) { + $value = str_replace(env('APP_URL'), '', $value); + }); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $request->input('gender_id')); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(GendersController::class, 'update', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + if ($request->ajax()) { + return response()->json(['status' => true, 'message' => 'The Genders updated Successfully.'], 200); + } + // return redirect()->route('genders.index')->with('success','The Genders updated Successfully.'); + return redirect()->back()->with('success', 'The Genders updated successfully.'); + } + + public function destroy(Request $request,$id) + { + createActivityLog(GendersController::class, 'destroy', ' Genders destroy'); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->destroy($OperationNumber, $OperationNumber, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(GendersController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Genders Deleted Successfully.'],200); + } + public function toggle(Request $request,$id) + { + createActivityLog(GendersController::class, 'destroy', ' Genders destroy'); + $data = Genders::findOrFail($id); + $requestData=['status'=>($data->status==1)?0:1]; + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->update($OperationNumber, $OperationNumber, null, $requestData, $id); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(GendersController::class, 'destroy', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Genders Deleted Successfully.'],200); + } + public function clone(Request $request,$id) + { + createActivityLog(GendersController::class, 'clone', ' Genders clone'); + $data = Genders::findOrFail($id); + unset($data['updatedby']); + unset($data['createdby']); + $requestData=$data->toArray(); + DB::beginTransaction(); + try { + $OperationNumber = getOperationNumber(); + $this->modelService->create($OperationNumber, $OperationNumber, null, $requestData); + } catch (Exception $e) { + DB::rollBack(); + Log::info($e->getMessage()); + createErrorLog(GendersController::class, 'clone', $e->getMessage()); + return response()->json(['status' => false, 'message' => $e->getMessage()], 500); + } + DB::commit(); + return response()->json(['status'=>true,'message'=>'The Genders Clonned Successfully.'],200); + } + + + + } + \ No newline at end of file diff --git a/app/Http/Controllers/GeneralFormController.php b/app/Http/Controllers/GeneralFormController.php new file mode 100644 index 0000000..d70ba25 --- /dev/null +++ b/app/Http/Controllers/GeneralFormController.php @@ -0,0 +1,1358 @@ +initializeFields(); + } + + protected function initializeFields() + { + self::$imageFields = array( + 'image', + 'logo', + 'signature', + 'cover_photo', + 'featured_image', + 'image_thumb', + 'primary_logo', + 'secondary_logo', + 'thumb_image', + 'thumb', + 'cover', + 'photo', + 'passport_copy', + 'icon', + 'favicon', + 'og_image', + 'no_image' + ); + self::$textEditorFields = array('details', 'description', 'text', 'qualification', 'experience', 'required_documents', 'biodata', 'privacy_policy', 'content1', 'content2', 'content3'); + self::$textAreaFields = array('copyright', 'remarks', 'seo_keywords', 'seo_description', 'seo_descriptions', 'intro', 'meta_tags', 'google_map', 'og_tags'); + self::$dateFields = array('dob', 'postedon', 'valid_till', 'startdate', 'enddate', 'from', 'to', 'starts', 'ends'); + self::$passwordFields = array('password'); + self::$HiddenCols = array("createdby", "updatedby", "updated_at", "created_at", "status", "alias", "display_order", "is_main", 'email_verified_at'); + } + + protected function getImageFields() + { + return $this->imageFields; + } + + protected function gettextEditorFields() + { + return $this->textEditorFields; + } + + public function create() + { + $tables = DB::select('SHOW TABLES'); + try { + $databasdeName = DB::connection()->getDatabaseName(); + $allTables = []; + foreach ($tables as $table) { + + $table_field = "Tables_in_$databasdeName"; + // dd($table->$table_field); + if(strpos($table->$table_field,"_logs")){continue;} + $allTables[$table->$table_field] = $table->$table_field; + } + return view('crud.form.create', compact('allTables')); + } catch (Exception $e) { + dd($e->getMessage()); + } + } + + + public function store(Request $request) + { + // dd($request->all()); + $request->validate([ + 'type' => 'required', + 'tableName' => 'required', + ]); + + $name = trim($request->type); + $command = $name; + + $tableName = trim($request->tableName); + $directoryName = trim($request->directoryName); + + switch ($command) { + case 'dictonary': + $data['tableName'] = "tbl_dictonary"; + if ($tableName != "") { + switch ($tableName) { + case 'add': + $data['TableCols'] = DB::select("describe " . $data['tableName']); + return view("crud.settings.dictonary/add", $data); + default: + $data['TableRows'] = DB::select("select * from " . $data['tableName']); + return view("crud.settings.dictonary.list", $data); + } + } + $data['TableName'] = "tbl_dictonary"; + $data['TableRows'] = DB::select("select * from " . $data['TableName']); + return view("crud.settings.dictonary", $data); + + + + case 'curd': + $data['tableName'] = $tableName; + $data['directoryName'] = $directoryName; + return view("crud.settings.curd", $data); + break; + case 'ajax-curd': + $data['tableName'] = $tableName; + $data['directoryName'] = $directoryName; + $columns = DB::select("describe $tableName"); // users table + return view("crud.settings.ajax-curd", $data); + break; + + default: + + return view("crud.settings.home"); + } + } + + public function getTableNullablecreate() + { + return view("crud.settings.ajax-curd"); + } + + public function tables() + { + $AllTables = DB::select('SHOW TABLES'); + try { + $databasdeName = DB::connection()->getDatabaseName(); + $allTables = []; + foreach ($AllTables as $table) { + $myTable = new stdClass; + //$allTables[]=$table['Tables_in_'.$databasdeName]; + $key = "Tables_in_" . $databasdeName; + $table->columns = DB::select("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" . $table->$key . "'"); + $myTable->tablename = $table->$key; + $myTable->tablecolumns = $table->columns; + $allTables[] = $myTable; + } + return view('crud.form.tables', compact('allTables')); + } catch (Exception $e) { + dd($e->getMessage()); + } + } + + public static function getForeignTable($all_columns) + { + $string = '_id'; + $foreign = []; + foreach ($all_columns as $key => $column) { + if (str_contains($column, $string) !== FALSE) { // Yoshi version + $foreign[] = $column; + } + } + unset($foreign[0]); + $strArray = []; + foreach ($foreign as $key => $foreignKey) { + $strArray[$key] = explode('_id', $foreignKey); + unset($strArray[$key][1]); + } + if ($strArray) { + $all_Foreign_Key_Table = call_user_func_array('array_merge', $strArray); + foreach ($all_Foreign_Key_Table as $column) { + $tableName[] = "tbl_" . $column; + } + return $tableName; + } else { + return []; + } + } + + public static function getTableColumns($TableName) + { + return array_column(DB::select("SHOW COLUMNS FROM $TableName"), 'Field'); + } + + + + public static function ajaxShowContent($TableName, $directoryName) + { + $TableName = strtolower($TableName); + $TableCols = DB::select("describe " . $TableName); + $TableRows = DB::select("select * from " . $TableName); + $folder = ''; + $routeName = ''; + if (!empty($directoryName)) { + $folder .= strtolower($directoryName) . '/'; + $routeName .= strtolower($directoryName) . '.'; + } + $routeName .= strtolower(str_replace("tbl_", "", $TableName)); + $folder .= str_replace("tbl_", "", $TableName); + $Table_pk = str_replace("tbl_", "", $TableName) . "_id"; + $title = ucwords(str_replace("tbl_", "", $TableName)); + $showContent = " + + + "; + + foreach ($TableCols as $key => $TableCol): + $TableCol = $TableCol->Field; + if ($key == 0 || $TableCol == 'createdOn' || $TableCol == 'createdBy' || $TableCol == 'updatedBy' || $TableCol == 'created_at' || $TableCol == 'updated_at') + continue; + $TableColLabel = ucwords(str_replace("_", " ", $TableCol)); + if ($TableCol == 'status') + $showContent .= "
Status : $TableCol == 1 ? 'text-success' : 'text-danger'}}\">{{\$data->$TableCol == 1 ? 'Active' : 'Inactive'}}
"; + else + $showContent .= '' . $TableColLabel . " : {{\$data->$TableCol}}
"; + + endforeach; + $showContent .= "Created On : {{\$data->created_at}}
+Created By : {{\$data->createdBy}}
+Updated On : {{\$data->updated_at}}
+Updated By : {{\$data->updatedBy}}
+ +