209 lines
6.4 KiB
PHP
209 lines
6.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Backend;
|
||
|
|
|
||
|
|
use App\Models\Chaturmas;
|
||
|
|
use App\Models\Sangh;
|
||
|
|
use App\Models\Sant;
|
||
|
|
use App\Http\Requests\Chaturmas\StoreChaturmasRequest;
|
||
|
|
use App\Http\Requests\Chaturmas\UpdateChaturmasRequest;
|
||
|
|
use App\Http\Controllers\BaseController;
|
||
|
|
use App\Repositories\Backend\Chaturmas\ChaturmasService;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use Exception;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
use App\Constant\Constant;
|
||
|
|
use App\Models\ThanaMember;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
|
||
|
|
class ChaturmasController extends BaseController
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* @var ChaturmasService
|
||
|
|
*/
|
||
|
|
protected $chaturmasService;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* ChaturmasController constructor.
|
||
|
|
* @param ChaturmasService $chaturmasService
|
||
|
|
*/
|
||
|
|
public function __construct(ChaturmasService $chaturmasService)
|
||
|
|
{
|
||
|
|
$this->chaturmasService = $chaturmasService;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This function is returning the Datatable columns response
|
||
|
|
*
|
||
|
|
* @param Request $request
|
||
|
|
* @return array|object
|
||
|
|
*/
|
||
|
|
public function getChaturmasListing(Request $request, Sant $sant)//Sant given to perform ajax request
|
||
|
|
{
|
||
|
|
$response = [];
|
||
|
|
try {
|
||
|
|
$response = $this->chaturmasService->getForDataTable($request->all(), $sant);
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return $response;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display a listing of the resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function index(Sant $sant)//Sant given to pass in view
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('backend.sant.sant-chaturmas.list', compact('sant'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for creating a new resource.
|
||
|
|
*
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function create(Sant $sant)//Sant given to create method form
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$years = getChaturmasYears();
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
return view('backend.sant.sant-chaturmas.create',compact('sant', 'years'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Store a newly created resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\StoreChaturmasRequest $request
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function store(StoreChaturmasRequest $request, Sant $sant)//
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$response = $this->chaturmasService->create($request->all(), $sant);
|
||
|
|
if ($response) {
|
||
|
|
return redirect(route('admin.sant.chaturmas.index', compact('sant')))
|
||
|
|
->with('flash_success', __('message.create_chaturmas_success'));
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('flash_error', __('message.create_chaturmas_error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Display the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Chaturmas $chaturmas
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function show(Chaturmas $chaturmas)
|
||
|
|
{
|
||
|
|
//
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Show the form for editing the specified resource.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Chaturmas $chaturma
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function edit(Sant $sant,Chaturmas $chaturma)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$sanghAddress = '';
|
||
|
|
if ($chaturma->sangh_id) {
|
||
|
|
$sanghAddress = Sangh::find($chaturma->sangh_id);
|
||
|
|
$sanghAddress = $sanghAddress->address;
|
||
|
|
}
|
||
|
|
$thanaID = Chaturmas::where('sant_id', $sant->id)->where('thana_sant_id', '!=', null)->value('thana_sant_id');
|
||
|
|
$thanaSantID = ThanaMember::where('thana_id', $thanaID)->pluck('sant_id');
|
||
|
|
$santName = Sant::whereIn('id', $thanaSantID)->pluck('name')->toArray();
|
||
|
|
$years = getChaturmasYears();
|
||
|
|
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return view('backend.sant.sant-chaturmas.edit', compact('sant', 'chaturma', 'years', 'santName', 'sanghAddress'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Update the specified resource in storage.
|
||
|
|
*
|
||
|
|
* @param \App\Http\Requests\UpdateChaturmasRequest $request
|
||
|
|
* @param \App\Models\Chaturmas $chaturmas
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function update(UpdateChaturmasRequest $request, Sant $sant, Chaturmas $chaturma)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$response = $this->chaturmasService->update($chaturma, $request->all(), $sant);
|
||
|
|
|
||
|
|
if ($response) {
|
||
|
|
return redirect(route('admin.sant.chaturmas.index', compact('sant')))
|
||
|
|
->with('flash_success', __('message.update_chaturmas_success'));
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return redirect()->back()->with('flash_error', __('message.update_chaturmas_error'));
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Remove the specified resource from storage.
|
||
|
|
*
|
||
|
|
* @param \App\Models\Chaturmas $chaturmas
|
||
|
|
* @return \Illuminate\Http\Response
|
||
|
|
*/
|
||
|
|
public function destroy(Chaturmas $chaturmas)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
|
||
|
|
$response = $chaturmas->delete();
|
||
|
|
if ($response) {
|
||
|
|
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.delete_chaturmas_success')]);
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.delete_chaturmas_error')]);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This function is for the grid checkbox multiple records actions
|
||
|
|
*
|
||
|
|
* @param Request $request
|
||
|
|
* @return JsonResponse
|
||
|
|
*/
|
||
|
|
public function gridRecordsAction(Request $request): JsonResponse
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$actionType = $request->action_type ?? Constant::NULL;
|
||
|
|
$checkedRecords = $request->checked_records ?? [];
|
||
|
|
$updateStatus = $this->chaturmasService->gridActions($actionType, $checkedRecords);
|
||
|
|
|
||
|
|
if ($updateStatus) {
|
||
|
|
return response()->json(['success' => Constant::STATUS_TRUE, 'message' => __('message.delete_chaturmas_success')]);
|
||
|
|
}
|
||
|
|
} catch (Exception $ex) {
|
||
|
|
Log::error($ex->getMessage());
|
||
|
|
}
|
||
|
|
|
||
|
|
return response()->json(['error' => Constant::STATUS_TRUE, 'message' => __('message.something_went_wrong')]);
|
||
|
|
}
|
||
|
|
}
|