api code global jain
This commit is contained in:
577
app/Repositories/Backend/Sant/SantService.php
Normal file
577
app/Repositories/Backend/Sant/SantService.php
Normal file
@@ -0,0 +1,577 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Backend\Sant;
|
||||
|
||||
use Exception;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Sant;
|
||||
use App\Models\Thana;
|
||||
use App\Models\SantTemp;
|
||||
use App\Constant\Constant;
|
||||
use App\Models\ThanaMember;
|
||||
use App\Imports\SantsImport;
|
||||
use App\Models\SantRelation;
|
||||
use App\Services\BaseService;
|
||||
use App\Models\SantTempRelation;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Exceptions\GeneralException;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Traits\PushNotificationTraits;
|
||||
use Yajra\DataTables\Facades\DataTables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Jobs\Notifications\Sant\SendRejectSant;
|
||||
use App\Jobs\Notifications\Sant\SendApproveSant;
|
||||
use App\Jobs\Notifications\Sant\SendRejectThana;
|
||||
use App\Jobs\Notifications\Sant\SendSentBackSant;
|
||||
|
||||
class SantService extends BaseService
|
||||
{
|
||||
use PushNotificationTraits;
|
||||
|
||||
/**
|
||||
* Associated Service Model.
|
||||
*/
|
||||
protected const MODEL = SantTemp::class;
|
||||
|
||||
/**
|
||||
* This function is use for search query in Datatable.
|
||||
* Also for sorting function we are using join query for appropriate sorting result
|
||||
* @param $request
|
||||
* @return $this|array|Builder
|
||||
*/
|
||||
public function prepareSearchQuery($request)
|
||||
{
|
||||
$searchQuery = [];
|
||||
|
||||
try {
|
||||
$searchQuery = $this->query()->with('dharm','sampraday','chaturmas','thanaMember')->select(
|
||||
'id',
|
||||
'sant_id',
|
||||
'name',
|
||||
'dharma_id',
|
||||
'sampraday_id',
|
||||
'status',
|
||||
'verification_status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
);
|
||||
$columns = ['id', 'name', 'dharma_id', 'sampraday_id', 'status', 'updated_at'];
|
||||
|
||||
if (isset($request['status']) && $request['status'] != '') {
|
||||
$searchQuery = $searchQuery->where('status', $request['status']);
|
||||
}
|
||||
|
||||
if (isset($request['verification_status']) && $request['verification_status'] != '') {
|
||||
$searchQuery = $searchQuery->where('verification_status', $request['verification_status']);
|
||||
}
|
||||
|
||||
if (isset($request['verification_status']) && $request['verification_status'] == Constant::STATUS_TWO) {
|
||||
$searchQuery = $searchQuery->where('verification_status', $request['verification_status'])
|
||||
->orWhereHas('thanaMember', function ($query) use ($request) {
|
||||
return $query->where('thana_members.is_approved', Constant::STATUS_ZERO);
|
||||
})
|
||||
->orWhereHas('chaturmas', function ($query) use ($request) {
|
||||
return $query->where('chaturmas.is_approved', Constant::STATUS_ZERO);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($request['dharma_id']) && $request['dharma_id'] != '') {
|
||||
$searchQuery = $searchQuery->where('dharma_id', $request['dharma_id']);
|
||||
}
|
||||
|
||||
if (isset($request['sampraday_id']) && $request['sampraday_id'] != '') {
|
||||
$searchQuery = $searchQuery->where('sampraday_id', $request['sampraday_id']);
|
||||
}
|
||||
|
||||
if (isset($request['name']) && $request['name'] != '') {
|
||||
$searchQuery = $searchQuery->where('name', 'like', '%' . $request['name'] . '%');
|
||||
}
|
||||
|
||||
if (isset($request['order']) && $request['order'] != "") {
|
||||
$searchQuery = $searchQuery->orderBy(
|
||||
$columns[$request['order'][0]['column']],
|
||||
$request['order'][0]['dir']
|
||||
);
|
||||
}
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return $searchQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is for the format the Datatable columns
|
||||
*
|
||||
* @param $request
|
||||
* @return object
|
||||
*/
|
||||
public function getForDataTable($request): object
|
||||
{
|
||||
$response = (object)[];
|
||||
|
||||
try {
|
||||
$dataTableQuery = $this->prepareSearchQuery($request);
|
||||
|
||||
$response = Datatables::of($dataTableQuery)
|
||||
->addColumn(
|
||||
'checkbox_action',
|
||||
function ($sant) {
|
||||
return $sant->sant_checkbox_action;
|
||||
}
|
||||
)
|
||||
->addIndexColumn()
|
||||
->editColumn('dharma_id', function ($sant) {
|
||||
return $sant->dharm->name ?? '-';
|
||||
})
|
||||
->editColumn('sampraday_id', function ($sant) {
|
||||
return $sant->sampraday->name ?? '-';
|
||||
})
|
||||
->addColumn(
|
||||
'status',
|
||||
function ($sant) {
|
||||
return $sant->sant_status_action;
|
||||
}
|
||||
)
|
||||
->addColumn(
|
||||
'created_at',
|
||||
function ($user) {
|
||||
return (($user->created_at) ? defaultDateTimeFormat($user->created_at) : '-');
|
||||
}
|
||||
)
|
||||
->addColumn(
|
||||
'updated_at',
|
||||
function ($user) {
|
||||
return (($user->updated_at) ? defaultDateTimeFormat($user->updated_at) : '-');
|
||||
}
|
||||
)
|
||||
->addColumn(
|
||||
'verification_status',
|
||||
function ($sant) {
|
||||
return $sant->verification_status_action;
|
||||
}
|
||||
)
|
||||
->addColumn(
|
||||
'thana',
|
||||
function ($sant) {
|
||||
$approvedThanaMember = ThanaMember::where('sant_id', $sant->sant_id)->where('is_approved', 1)->select('thana_id')->first();
|
||||
$pendingThanaMember = ThanaMember::where('sant_id', $sant->sant_id)->where('is_approved', 0)->select('thana_id')->first();
|
||||
$count = 0;
|
||||
if ($approvedThanaMember) {
|
||||
// $thanaOfSant = $sant->ownedThana()->first();
|
||||
|
||||
// if (isset($thanaOfSant) && !empty($thanaOfSant)) {
|
||||
// $createdThanaId = Thana::find($thanaOfSant->id);
|
||||
// } else {
|
||||
// $createdThanaId = Thana::find($approvedThanaMember->thana_id);
|
||||
// }
|
||||
|
||||
// $count = $createdThanaId->getThanaMember()->count();
|
||||
// if ($count > 0) {
|
||||
return '<span class="label label-lg label-light-success label-inline">' . __('label.approved_thana') . '</span>';
|
||||
// }
|
||||
} else if ($pendingThanaMember) {
|
||||
// $thanaOfSant = $sant->ownedThana()->first();
|
||||
|
||||
// if (isset($thanaOfSant) && !empty($thanaOfSant)) {
|
||||
// $createdThanaId = Thana::find($thanaOfSant->id);
|
||||
// } else {
|
||||
// $createdThanaId = Thana::find($pendingThanaMember->thana_id);
|
||||
// }
|
||||
|
||||
// $count = $createdThanaId->getThanaMember()->count();
|
||||
// if ($count > 0) {
|
||||
return '<span class="label label-lg label-light-warning label-inline">' . __('label.in_review') . '</span>';
|
||||
// }
|
||||
} else {
|
||||
return '-';
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
)
|
||||
->addColumn(
|
||||
'action',
|
||||
function ($sant) {
|
||||
if (
|
||||
!empty($sant->roles[0]['name']) != config('access.users.admin_role')
|
||||
|| !empty($sant->roles[0]['name']) != config('access.users.super_admin_role')
|
||||
|| loggedInUser()->isSuperAdmin()
|
||||
|| loggedInUser()->isAdmin()
|
||||
) {
|
||||
return $sant->sant_action_buttons;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
)
|
||||
->setRowId(
|
||||
function ($sant) {
|
||||
return 'recordRow-' . $sant->id;
|
||||
}
|
||||
)
|
||||
->rawColumns(['status', 'verification_status', 'thana','action', 'checkbox_action'])
|
||||
->make(true);
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is for the create sant
|
||||
*
|
||||
* @param $request
|
||||
* @return response
|
||||
* @throws GeneralException
|
||||
*/
|
||||
public function create($request)
|
||||
{
|
||||
try {
|
||||
if (isset($request['honor']) && !empty($request['honor'])) {
|
||||
$honors = jsonToArray($request['honor']);
|
||||
} else {
|
||||
$honors = [];
|
||||
}
|
||||
$user = loggedInUser();
|
||||
$santData['user_id'] = $user->id ?? Constant::NULL;
|
||||
$santData['name'] = $request['name'] ?? Constant::NULL;
|
||||
$santData['father_name'] = $request['father_name'] ?? Constant::NULL;
|
||||
$santData['mother_name'] = $request['mother_name'] ?? Constant::NULL;
|
||||
$santData['gender'] = $request['gender'] ?? Constant::NULL;
|
||||
$santData['honor'] = $honors;
|
||||
$santData['qualification'] = $request['qualification'] ?? Constant::NULL;
|
||||
$santData['dharma_id'] = $request['dharma_id'] ?? Constant::NULL;
|
||||
$santData['sampraday_id'] = $request['sampraday_id'] ?? Constant::NULL;
|
||||
$santData['guru_id'] = $request['guru_id'] ?? Constant::NULL;
|
||||
$santData['birth_date'] = $request['birth_date'] ?? Constant::NULL;
|
||||
$santData['diksha_date'] = $request['diksha_date'] ?? Constant::NULL;
|
||||
$santData['diksha_place'] = $request['diksha_place'] ?? Constant::NULL;
|
||||
$santData['diksha_place_latitude'] = $request['diksha_place_latitude'] ?? Constant::NULL;
|
||||
$santData['diksha_place_longitude'] = $request['diksha_place_longitude'] ?? Constant::NULL;
|
||||
$santData['about'] = $request['about'] ?? Constant::NULL;
|
||||
$santData['status'] = $request['status'] == 2 ? Constant::STATUS_ONE : Constant::STATUS_TWO;
|
||||
$santData['created_by'] = $user->id ?? Constant::NULL;
|
||||
|
||||
if(!empty($request['avatar'])) {
|
||||
$imageName = uploadImage($request, 'avatar', Constant::SANT_IMAGE_UPLOAD_PATH . Constant::SLASH);
|
||||
$santData['avatar'] = $imageName['image_name'] ?? Constant::NULL;
|
||||
}
|
||||
$sant = Sant::create($santData);
|
||||
$santTempImage = $sant->getRawOriginal('avatar');
|
||||
$santTemp = $sant->toArray();
|
||||
$santTemp['sant_id'] = $sant->id;
|
||||
$santTemp['avatar'] = $santTempImage;
|
||||
$santTemp = $this->query()->create($santTemp);
|
||||
|
||||
if ($sant) {
|
||||
return $sant;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
throw new GeneralException(__('message.create_sant_error'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param object $sant
|
||||
* @param $data
|
||||
* @return sant
|
||||
*/
|
||||
public function update(object $sant,$request)
|
||||
{
|
||||
$santData['reviewed_fields'] = [];
|
||||
|
||||
try {
|
||||
$user = loggedInUser();
|
||||
$santMain = Sant::where('id', $sant->sant_id)->first();
|
||||
$rejectDesc = $request['reject_desc'] ?? Constant::NULL;
|
||||
$senBackDesc = $request['send_back_desc'] ?? Constant::NULL;
|
||||
|
||||
if ($request['modalBtn'] == 'send_back') {
|
||||
//Storing json for fields needs to update/change
|
||||
$santData['reviewed_fields']['name'] = isset($request['nameCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['dharma'] = isset($request['dharmaCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['sampraday'] = isset($request['sampradayCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['birth_date'] = isset($request['birthDateCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['gender'] = isset($request['genderCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['diksha_date'] = isset($request['dikshaDateCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['diksha_place'] = isset($request['dikshaPlaceCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['guru'] = isset($request['guruCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['father_name'] = isset($request['fatherCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['mother_name'] = isset($request['motherCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['about'] = isset($request['aboutCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['avatar'] = isset($request['avatarCheckbox']) ? Constant::STATUS_TRUE : Constant::STATUS_FALSE;
|
||||
|
||||
$santData['description'] = $request['send_back_desc'] ?? Constant::NULL;
|
||||
|
||||
if ($sant->verification_status === Constant::STATUS_FOUR) {
|
||||
$santData['verification_status'] = Constant::STATUS_FIVE;
|
||||
|
||||
//Always true when profile is approved & sent back
|
||||
$santData['reviewed_fields']['name'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['dharma'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['sampraday'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['birth_date'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['gender'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['diksha_date'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['diksha_place'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['guru'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['father_name'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['mother_name'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['about'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['avatar'] = Constant::STATUS_TRUE;
|
||||
|
||||
$santMain['verification_status'] = Constant::STATUS_FIVE;
|
||||
$santMain->save();
|
||||
} else {
|
||||
$santData['verification_status'] = Constant::STATUS_THREE;
|
||||
$santMain['verification_status'] = Constant::STATUS_THREE;
|
||||
$santMain->save();
|
||||
}
|
||||
|
||||
//Push Notification when profile sent back
|
||||
dispatch(new SendSentBackSant($user, $sant, $senBackDesc));
|
||||
|
||||
} elseif ($request['modalBtn'] == 'reject') {
|
||||
$santData['description'] = $request['reject_desc'] ?? Constant::NULL;
|
||||
|
||||
if ($sant->verification_status === Constant::STATUS_FOUR) {
|
||||
$santData['verification_status'] = Constant::STATUS_ONE;
|
||||
} else {
|
||||
$santData['verification_status'] = Constant::STATUS_SIX;
|
||||
}
|
||||
|
||||
//Push Notification when profile rejected
|
||||
dispatch(new SendRejectSant($user, $sant, $rejectDesc));
|
||||
|
||||
} else {
|
||||
//honors
|
||||
if (!empty($request['honor'])) {
|
||||
$honors = jsonToArray($request['honor']);
|
||||
} else if (isset($request['honor']) === false) {
|
||||
$honors = $sant->honor;
|
||||
} else {
|
||||
$honors = [];
|
||||
}
|
||||
//Birth date
|
||||
if (!empty($request['birth_date'])) {
|
||||
$birthDate = $request['birth_date'];
|
||||
} else {
|
||||
$birthDate = Constant::NULL;
|
||||
}
|
||||
//Diksha date
|
||||
if (!empty($request['diksha_date'])) {
|
||||
$dikshaDate = $request['diksha_date'];
|
||||
} else {
|
||||
$dikshaDate = Constant::NULL;
|
||||
}
|
||||
//Storing/Updating sant's data
|
||||
$santData['name'] = $request['name'] ?? $sant->name;
|
||||
$santData['father_name'] = $request['father_name'] ?? $sant->father_name;
|
||||
$santData['mother_name'] = $request['mother_name'] ?? $sant->mother_name;
|
||||
$santData['gender'] = $request['gender'] ?? $sant->gender;
|
||||
$santData['honor'] = $honors;
|
||||
$santData['qualification'] = $request['qualification'] ?? $sant->qualification;
|
||||
$santData['dharma_id'] = $request['dharma_id'] ?? $sant->dharma_id;
|
||||
$santData['sampraday_id'] = $request['sampraday_id'] ?? $sant->sampraday_id;
|
||||
$santData['guru_id'] = $request['guru_id'] ?? $sant->guru_id;
|
||||
$santData['birth_date'] = $birthDate;
|
||||
$santData['diksha_date'] = $dikshaDate;
|
||||
$santData['diksha_place'] = $request['diksha_place'] ?? $sant->diksha_place;
|
||||
$santData['diksha_place_latitude'] = $request['diksha_place_latitude'] ?? $sant->diksha_place_latitude;
|
||||
$santData['diksha_place_longitude'] = $request['diksha_place_longitude'] ?? $sant->diksha_place_longitude;
|
||||
$santData['about'] = $request['about'] ?? $sant->about;
|
||||
$santData['status'] = Constant::STATUS_TWO;
|
||||
$santData['verification_status'] = Constant::STATUS_ONE;
|
||||
$santData['profile_verified_at'] = Carbon::now();
|
||||
$santData['updated_by'] = $sant->updated_by;
|
||||
|
||||
$santData['reviewed_fields']['name'] = Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['dharma'] = Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['sampraday'] = Constant::STATUS_FALSE;
|
||||
$santData['reviewed_fields']['birth_date'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['gender'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['diksha_date'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['diksha_place'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['guru'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['father_name'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['mother_name'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['about'] = Constant::STATUS_TRUE;
|
||||
$santData['reviewed_fields']['avatar'] = Constant::STATUS_TRUE;
|
||||
|
||||
if(!empty($request['avatar'])) {
|
||||
$imageName = uploadImage($request, 'avatar', Constant::SANT_IMAGE_UPLOAD_PATH . Constant::SLASH, $sant->getRawOriginal('avatar'));
|
||||
$santData['avatar'] = $imageName['image_name'] ?? Constant::NULL;
|
||||
} else if (!empty($sant->getRawOriginal('avatar')) && $request['is_remove_avatar_image'] != Constant::STATUS_ONE) {
|
||||
$santData['avatar'] = $sant->getRawOriginal('avatar');
|
||||
} else {
|
||||
$santData['avatar'] = Constant::NULL;
|
||||
}
|
||||
$santMain->update($santData);
|
||||
|
||||
//Updating sant relation data
|
||||
$santTempRelations = SantTempRelation::where('sant_temp_id', $sant->sant_id)->get()->toArray();
|
||||
|
||||
if (!empty($santTempRelations)) {
|
||||
$santRelations = SantRelation::where('sant_id', $santTempRelations[0]['sant_temp_id'])->get()->toArray();
|
||||
}
|
||||
|
||||
if (empty($santRelations)) {
|
||||
foreach ($santTempRelations as $santRelation) {
|
||||
SantRelation::create([
|
||||
'relation_type' => $santRelation['relation_type'],
|
||||
'relation_id' => $santRelation['relation_id'],
|
||||
'sant_id' => $santRelation['sant_temp_id'],
|
||||
'type' => $santRelation['type'],
|
||||
]);
|
||||
}
|
||||
} else {
|
||||
foreach ($santTempRelations as $santRelation) {
|
||||
$santRelationData = [
|
||||
'relation_type' => $santRelation['relation_type'],
|
||||
'relation_id' => $santRelation['relation_id'],
|
||||
'sant_id' => $santRelation['sant_temp_id'],
|
||||
'type' => $santRelation['type'],
|
||||
];
|
||||
$santRelations = SantRelation::where('sant_id', $santRelation['sant_temp_id'])->where('type', $santRelation['type'])->update($santRelationData);
|
||||
}
|
||||
}
|
||||
// Add karma points on sant approve
|
||||
$santMain->addKarmaPoints($santMain, $santMain->updated_by, config('config-variables.karma_points_message.add_new_sant'), config('config-variables.karma_points.add_new_sant'), config('config-variables.karma_points_key.add_new_sant'), []);
|
||||
|
||||
// Update existing record
|
||||
$thanaMemberStatus = collect($request->status)->keys();
|
||||
|
||||
if ($thanaMemberStatus->count() > 0) {
|
||||
$santLive = Sant::find($sant->sant_id);
|
||||
$thanaMemberExist = ThanaMember::where('sant_id', $sant->sant_id)->select('thana_id')->first();
|
||||
|
||||
if (!empty($thanaMemberExist)) {
|
||||
$thanaOfSant = $santLive->ownedThana()->first();
|
||||
$thana = Thana::find($thanaMemberExist->thana_id);
|
||||
}
|
||||
$thana->getThanaMember()
|
||||
->newPivotStatement()
|
||||
->whereNotIn('id', $thanaMemberStatus->toArray())->whereIn('thana_id', [$thanaMemberExist->thana_id])->update(['is_approved' => Constant::STATUS_ZERO]);
|
||||
|
||||
$thana->getThanaMember()
|
||||
->newPivotStatement()
|
||||
->whereIn('id', $thanaMemberStatus->toArray())->where('thana_id', [$thanaMemberExist->thana_id])->update(['is_approved' => Constant::STATUS_ONE]);
|
||||
} else {
|
||||
$santLive = Sant::find($sant->sant_id);
|
||||
$thanaMemberExist = ThanaMember::where('sant_id', $sant->sant_id)->select('thana_id')->first();
|
||||
|
||||
if (!empty($thanaMemberExist)) {
|
||||
$thanaOfSant = $santLive->ownedThana()->first();
|
||||
$thana = Thana::find($thanaMemberExist->thana_id);
|
||||
$thana->getThanaMember()
|
||||
->newPivotStatement()
|
||||
->whereIn('thana_id', [$thanaMemberExist->thana_id])->update(['is_approved' => Constant::STATUS_ZERO]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($santData['verification_status'] === Constant::STATUS_ONE) {
|
||||
$santData['status'] = Constant::STATUS_TWO;
|
||||
//Push Notification when profile approved
|
||||
dispatch(new SendApproveSant($user, $sant, $santMain));
|
||||
|
||||
$santProfileCompletion = calculateSantActivity($santData);
|
||||
$santData['profile_statistics'] = $santProfileCompletion;
|
||||
$santMain['profile_statistics'] = $santProfileCompletion;
|
||||
$santMain->save();
|
||||
}
|
||||
$santExist = $this->query()->where('id',$sant->id)->update($santData);
|
||||
|
||||
if ($santExist) {
|
||||
return $santExist;
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
throw new GeneralException(__('message.create_sant_error'));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is for the multiple records action from the grid
|
||||
*
|
||||
* @param string $actionType
|
||||
* @param array $data
|
||||
* @return bool
|
||||
* @throws GeneralException
|
||||
*/
|
||||
public function gridActions(string $actionType, array $data): bool
|
||||
{
|
||||
try {
|
||||
switch ($actionType) {
|
||||
case Constant::STATUS_ACTIVE:
|
||||
$this->query()->whereIn('sant_id', $data)->update(['status' => Constant::STATUS_TWO]);
|
||||
Sant::whereIn('id', $data)->update(['status' => Constant::STATUS_TWO]);
|
||||
return Constant::STATUS_TRUE;
|
||||
case Constant::STATUS_INACTIVE:
|
||||
$this->query()->whereIn('sant_id', $data)->update(['status' => Constant::STATUS_ONE]);
|
||||
Sant::whereIn('id', $data)->update(['status' => Constant::STATUS_ONE]);
|
||||
return Constant::STATUS_TRUE;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
throw new GeneralException(__('message.delete_sant_error'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is for the multiple records action from the grid
|
||||
*
|
||||
* @param array $data
|
||||
* @throws GeneralException
|
||||
*/
|
||||
public function importSant($request)
|
||||
{
|
||||
try {
|
||||
Excel::import(new SantsImport, $request->file('file'));
|
||||
|
||||
} catch (Exception $ex) {
|
||||
Log::error($ex->getMessage());
|
||||
throw new GeneralException(__('message.something_went_wrong'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is to remove thana memeber
|
||||
*
|
||||
* @param $request
|
||||
* @return response
|
||||
* @throws GeneralException
|
||||
*/
|
||||
public function removeThanaMember($santID, $thanaID)
|
||||
{
|
||||
try {
|
||||
$thanaMemberExist = ThanaMember::where('sant_id', $santID)->where('id', $thanaID)->first();
|
||||
$thana = Thana::where('id', $thanaMemberExist['thana_id'])->first();
|
||||
$removedSant = Sant::where('id', $thanaMemberExist->sant_id)->first();
|
||||
|
||||
if (!empty($thanaMemberExist)) {
|
||||
$thanaMemberExist->delete();
|
||||
|
||||
if (!empty($thana)) {
|
||||
//Push Notification
|
||||
dispatch(new SendRejectThana($thana, $removedSant));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
} catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
throw new GeneralException(__('message.remove_thana_error'));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user