HEX
Server: nginx/1.24.0
System: Linux DGT-WORDPRESS-VM-SERVER 6.14.0-1017-azure #17~24.04.1-Ubuntu SMP Mon Dec 1 20:10:50 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 8.4.12
Disabled: NONE
Upload Files
File: /mnt/data/ghayatcom/ghayatcom-api/app/Http/Controllers/Api/WebController.php
<?php

namespace App\Http\Controllers\Api;

use App\AuthenticateRelationship;
use App\Country;
use App\DependantAccountHolder;
use App\DependentRelationship;
use App\Http\Controllers\Controller;
use App\Http\Requests\AddDependantRequest;
use App\Http\Requests\DependentAuthenticateRequest;
use App\Http\Requests\UpdateDependantRequest;
use App\Http\Resources\DependantHpResource;
use App\Library\S3Library;
use App\User;
use App\UserAddress;
use Auth;
use DB;
use Exception;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
use Spatie\Permission\Models\Role;
use Storage;
use Throwable;

class WebController extends Controller
{
    // public function dependantPersonalDetailCreate(AddDependantRequest $request) {
    // 	try {
    // 		$DependantLibrary = new \App\Library\DependantLibrary;

 //            $checkPassportPatient = User::role(['patient','doctor'])->where('passport_number', $request->id_card_or_passport_no)->get();
 //            if(count($checkPassportPatient) > 0) {
 //                return self::sentResponse(409, [], __('digimed_validation.error_response.passport_id_conflict'));
 //            }

 //            $checkPassportDependant = User::role('dependant')->with(['dependantAccountHolder'])->where('passport_number', $request->id_card_or_passport_no)->whereHas('dependantAccountHolder', function($q) {$q->where('status', 1);})->get();
 //            if(count($checkPassportDependant) > 0) {
 //                return self::sentResponse(409, [], __('digimed_validation.error_response.passport_id_conflict'));
 //            }

    // 		$validated = $request->validated();
 //            $data_dob = $request->dob;
 //            /** @var string $data_dob */
    // 		$dob = date('Y-m-d',strtotime(str_replace('/', '-', $data_dob)));
 //            $addressArr = $request->address;
 //            $authID = auth()->user()->id;

 //            //Enum Role Need To Implement
 //            /** @var \App\User $queryAccountHolder */
 //            $queryAccountHolder = Auth::user();
 //            $accountHolderAddress = $queryAccountHolder->address;
 //            $accountHolderID = $queryAccountHolder->id;

 //            $countryISO3 = Country::where('iso3', 'MLT')->first();
 //            if(!empty($countryISO3)) {
 //                // $array['country_id'] = $countryISO3->id;
 //                $array['country_code'] = $countryISO3->phone_code;
 //            }

 //            $linkedAccount = ($DependantLibrary->addPreConditions($authID,$dob,$request->id_card_or_passport_no));
 //            if($linkedAccount['is_error']) {
 //                if($linkedAccount['code'] == 500) {
 //                    return self::sentResponse($linkedAccount['code'], [], $linkedAccount['message']);
 //                } else if($linkedAccount['code'] == 200) {
 //                    $linkedData = $linkedAccount['data'];

 //                    if(!empty($linkedData)) {
 //                        //Pivot & Autheniticate Relationship
 //                        DB::beginTransaction();
 //                        DependantAccountHolder::create(['user_id' => $accountHolderID,'dependant_id' => $linkedData->id,'dependent_relationship_id' => $request->dependent_relationship,'status' => 0,'created_by' => $authID,'updated_by' => $authID]);
 //                        DB::commit();
 //                        $is_linked = true;
 //                        $listOut = ($DependantLibrary->list($linkedData->id));
 //                        return new DependantHpResource($listOut, 200, __('digimed_validation.error_response.created_by_dependant'), $is_linked);
 //                    } else {
 //                        $legacyData = $linkedAccount['legacy_data'];
 //                        $is_linked = false;
 //                        $listOut = ($DependantLibrary->list($legacyData->id));
 //                        return new DependantHpResource($listOut, 200, __('digimed_validation.success_response.dependant_personal_address_updated'), $is_linked);
 //                    }
 //                }
 //            }

 //            //Personal Information
 //            $array['type'] = 'dependant';
 //            $array['first_name'] = $request->first_name;
 //            $array['last_name'] = $request->last_name;
 //            $array['gender'] = $request->gender;
 //            $array['dob'] = $dob;
 //            $array['passport_number'] = $request->id_card_or_passport_no;
 //            $array['status'] = '0';
 //            $array['created_by'] = $authID;
 //            $array['updated_by'] = $authID;

 //            $use_account_holder_address = $request->use_account_holder_address;
 //            if($use_account_holder_address) {
 //                $array['country_id'] = $countryISO3->id;
 //                $array['address'] = (!empty($accountHolderAddress)) ? $accountHolderAddress : NULL;
 //            } else {
 //                if(!empty($addressArr)) {
 //                    /** @var array $addressArr */
 //                    $addressArrShift = array_filter($addressArr);

 //                    $primayAddress = [];
 //                    foreach ($addressArrShift as $key => $val) {
 //                    	if ($val['type'] === 'primary') {
 //                            $json['address'] = $val['address'];
 //                            $json['country_id'] = $val['country_id'];
 //                            $json['post_code'] = $val['post_code'];
 //                            array_push($primayAddress,$json);
 //                      	}
 //                    }

 //                    if(count($primayAddress) > 0) {
 //                        $array['country_id'] = $primayAddress[0]['country_id'];
 //                        $array['address'] = $primayAddress[0]['address'];
 //                        $array['post_code'] = $primayAddress[0]['post_code'];
 //                    } else {
 //                        $array['country_id'] = $countryISO3->id;
 //                        $array['address'] = NULL;
 //                    }
 //                } else {
 //                    $array['country_id'] = $countryISO3->id;
 //                    $array['address'] = NULL;
 //                }
 //            }

 //            //User Table
 //            DB::beginTransaction();
 //            $dependantQ = new User();
 //            $dependantQ->fill($array);
 //            $dependantQ->save();
 //            $last_id = $dependantQ->id;
 //            $dependantQ->assignRole('dependant');//Enum Role Need To Implement

 //            if(!empty($addressArr)) {
 //                /** @var array $addressArr */
 //                $addressArrShift = array_filter($addressArr);
 //                foreach ($addressArrShift as $key => $val) {
 //                 	if ($val['type']=== 'secondary') {
    //                     $userAddressQ = new UserAddress();
    //                     $userAddressQ->user_id = $last_id;
    //                     $userAddressQ->type = 'secondary';
    //                     $userAddressQ->address = $val['address'];
 //                        $userAddressQ->country_id = $val['country_id'];
 //                        $userAddressQ->post_code = $val['post_code'];
    //                     $userAddressQ->created_by = $authID;
    //                     $userAddressQ->updated_by = $authID;
    //                     $userAddressQ->save();
    //                 }
    //             }
    //         }

    //         //Pivot & Autheniticate Relationship
 //            DependantAccountHolder::create(['user_id' => $accountHolderID,'dependant_id' => $last_id,'dependent_relationship_id' => $request->dependent_relationship,'status' => 0,'created_by' => $authID,'updated_by' => $authID]);

    // 		$listOut = ($DependantLibrary->list($last_id));
    // 		$is_linked = false;
    // 		DB::commit();

    // 		return new DependantHpResource($listOut, 200, __('digimed_validation.success_response.dependant_personal_address_updated'), $is_linked);
    // 	} catch(Exception | Throwable | QueryException $e) {
    // 		DB::rollback();
    // 		return self::sentResponse(500, [], $e->getMessage());
    // 	}
    // }

    // public function dependantAuthenticateCreate(DependentAuthenticateRequest $request, S3Library $S3Library) {
 //        $validated = $request->validated();
    // 	try {
    // 		$DependantLibrary = new \App\Library\DependantLibrary;
    // 		$authID = auth()->user()->id;
    // 		$accountHolderID = $authID;
    // 		$last_id = $request->dependant_id;

    // 		DB::beginTransaction();
    // 		if ($request->hasFile('authenticate_relationship')) {

 //                $digimedFile = $S3Library->fileUpload(true, 'jpeg|JPEG|jpg|JPG|png|PNG|pdf|docx|doc|DOCX|DOC', true, $request->file('authenticate_relationship'), 'digimed/images/authenticate_relationship/'.$last_id.'/');
 //                if($digimedFile['code'] == 500) {
 //                    DB::rollback();
 //                    return self::sentResponse(500, $digimedFile['data'], $digimedFile['msg']);
 //                }
 //                $dependent_relationship_proof = NUll;
 //                if($digimedFile['code'] == 200) {
 //                    $dependent_relationship_proof = $digimedFile['data'];
 //                }

 //                //Pivot & Autheniticate Relationship Update
 //                $update = DependantAccountHolder::where('user_id', $accountHolderID)->where('dependant_id', $last_id)->first();
 //                if($update != "") {
 //                	$update->dependent_relationship_proof = $dependent_relationship_proof;
    //                 $update->updated_by = $authID;
    //                 $update->save();
 //                } else {
 //                	DB::rollback();
 //                    return self::sentResponse(401, [], __('digimed_validation.error_response.not_authorized'));
 //                }
 //            }

 //            $listOut = ($DependantLibrary->list($last_id));
    // 		DB::commit();

    // 		return new DependantHpResource($listOut, 200, __('digimed_validation.success_response.dependant_authenticate_updated'));

    // 	} catch(Exception | Throwable | QueryException $e) {
    //         DB::rollback();
    //         return self::sentResponse(500, [], $e->getMessage());
    //     }
    // }

    // public function dependantProfilePictureCreate(Request $request, S3Library $S3Library) {
    // 	try {
    // 		$DependantLibrary = new \App\Library\DependantLibrary;
    // 		DB::beginTransaction();

 //            $addressArr = $request->address;
 //            $authID = auth()->user()->id;
    // 		$last_id = $request->dependant_id;

 //            //Enum Role Need To Implement
 //            /** @var \App\User $queryAccountHolder */
 //            $queryAccountHolder = Auth::user();
 //            $accountHolderAddress = $queryAccountHolder->address;
 //            $accountHolderID = $queryAccountHolder->id;
 //            $countryISO3 = Country::where('iso3', 'MLT')->first();
 //            //User Table
 //            $dependantQ = User::find($last_id);

 //            //Profile Picture
 //            $profileImage = "";
 //            $data_profile_image = $request->profile_image;
 //            /**
 //            * @var string|null $data_profile_image
 //            */

 //            if (!empty($data_profile_image)) {
 //                if(($S3Library->is_base64($data_profile_image))) {  //Base 64
 //                    $digimedFile = ($S3Library->base64($data_profile_image, $last_id, ['image'], 'digimed/images/profile-images/'));
 //                    if($digimedFile['code'] == 200) {
 //                        $dependantQ->profile_image = $digimedFile['data'];
 //                    }

 //                    if($digimedFile['code'] == 500) {
 //                        DB::rollback();
 //                        return self::sentResponse($digimedFile['code'], $digimedFile['data'], $digimedFile['msg']);
 //                    }
 //                }
 //            }

 //            $dependantQ->updated_by = $authID;
 //            $dependantQ->save();

    // 		$listOut = ($DependantLibrary->list($last_id));
    // 		DB::commit();

    // 		return new DependantHpResource($listOut, 200, __('digimed_validation.success_response.dependant_profile_picture_updated'));
    // 	} catch(Exception | Throwable | QueryException $e) {
    // 		DB::rollback();
    // 		return self::sentResponse(500, [], $e->getMessage());
    // 	}
    // }

 //    public function dependantPersonalDetailUpdate(UpdateDependantRequest $request) {
 //        try {
 //            $DependantLibrary = new \App\Library\DependantLibrary;
 //            $validated = $request->validated();
 //            $authID = auth()->user()->id;
 //            $update_id = $request->update_id;
 //            $data_dob = $request->dob;
 //            /** @var string $data_dob */
 //            $dob = date('Y-m-d',strtotime(str_replace('/', '-', $data_dob)));
 //            $addressArr = $request->address;

 //            $error = ($DependantLibrary->updatePreConditions($update_id, $authID, $data_dob, $request->id_card_or_passport_no));
 //            if($error['is_error']) {
 //                return self::sentResponse($error['code'], [], $error['message']);
 //            }

 //            DB::beginTransaction();
 //            $userModel = new User();
 //            $updateQ = $userModel->role('dependant')->where('id', $update_id)->first();

 //            $updateQ->first_name = $request->first_name;
 //            $updateQ->last_name = $request->last_name;
 //            $updateQ->gender = $request->gender;
 //            $updateQ->dob = $dob;
 //            $updateQ->passport_number = $request->id_card_or_passport_no;
 //            $updateQ->updated_by = auth()->user()->id;
 //            $updateQ->save();

 //            $listOut = ($DependantLibrary->list($update_id));
 //            DB::commit();
 //            return new DependantHpResource($listOut, 200, __('digimed_validation.success_response.dependant_personal_updated'));

 //        } catch(Exception | Throwable | QueryException $e) {
 //            DB::rollback();
 //            return self::sentResponse(500, [], $e->getMessage());
 //        }
 //    }

 //    public function dependantAddressUpdate(Request $request) {
 //        try {
 //            $DependantLibrary = new \App\Library\DependantLibrary;

 //            $addressArr = $request->address;
 //            $authID = auth()->user()->id;
 //            $last_id = $request->dependant_id;

 //            //Enum Role Need To Implement
 //            /** @var \App\User $queryAccountHolder */
 //            $queryAccountHolder = Auth::user();
 //            $accountHolderAddress = $queryAccountHolder->address;
 //            $accountHolderID = $queryAccountHolder->id;
 //            $countryISO3 = Country::where('iso3', 'MLT')->first();
 //            //User Table
 //            DB::beginTransaction();
 //            $userQ = User::find($last_id);

 //            $use_account_holder_address = $request->use_account_holder_address;
 //            if($use_account_holder_address) {
 //                $userQ->address = (!empty($accountHolderAddress)) ? $accountHolderAddress : NULL;
 //            } else {
 //                if(!empty($addressArr)) {
 //                    /** @var array $addressArr */
 //                    $addressArrShift = array_filter($addressArr);

 //                    $primayAddress = [];
 //                    foreach ($addressArrShift as $key => $val) {
 //                        if ($val['type'] === 'primary') {
 //                            $json['address'] = $val['address'];
 //                            $json['country_id'] = $val['country_id'];
 //                            $json['post_code'] = $val['post_code'];
 //                            array_push($primayAddress,$json);
 //                        }
 //                    }

 //                    if(count($primayAddress) > 0) {
 //                        $userQ->country_id = $primayAddress[0]['country_id'];
 //                        $userQ->address = $primayAddress[0]['address'];
 //                        $userQ->post_code = $primayAddress[0]['post_code'];
 //                    } else {
 //                        $userQ->country_id = $countryISO3->id;
 //                        $userQ->address = NULL;
 //                    }
 //                } else {
 //                    $userQ->country_id = $countryISO3->id;
 //                    $userQ->address = NULL;
 //                }
 //            }

 //            $userQ->updated_by = $authID;
 //            $userQ->save();

 //            if(!empty($addressArr)) {
 //                //Delete
 //                $existBuilder = UserAddress::where('user_id', $last_id);
 //                if($existBuilder->count() > 0) {
 //                    $existBuilder->update(['deleted_by' => $authID]);
 //                    $existBuilder->delete();
 //                }
 //                /** @var array $addressArr */
 //                $addressArrShift = array_filter($addressArr);
 //                foreach ($addressArrShift as $key => $val) {
 //                    if ($val['type']=== 'secondary') {
 //                        $userAddressQ = new UserAddress();
 //                        $userAddressQ->user_id = $last_id;
 //                        $userAddressQ->type = 'secondary';
 //                        $userAddressQ->address = $val['address'];
 //                        $userAddressQ->country_id = $val['country_id'];
 //                        $userAddressQ->post_code = $val['post_code'];
 //                        $userAddressQ->created_by = $authID;
 //                        $userAddressQ->updated_by = $authID;
 //                        $userAddressQ->save();
 //                    }
 //                }
 //            }

 //            $listOut = ($DependantLibrary->list($last_id));
 //            DB::commit();

 //            return new DependantHpResource($listOut, 200, __('digimed_validation.success_response.dependant_personal_address_updated'));
 //        } catch(Exception | Throwable | QueryException $e) {
 //            DB::rollback();
 //            return self::sentResponse(500, [], $e->getMessage());
 //        }
 //    }
}