diff --git a/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php b/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php new file mode 100644 index 0000000..fcc87a3 --- /dev/null +++ b/app/Http/Controllers/APIs/RestaurantApi/RestAuthApiController.php @@ -0,0 +1,69 @@ +RestAuthApiService = $RestAuthApiService; + } + + public function viewresyaurant() + { + try { + $response = $this->RestAuthApiService->viewresyaurant(); + return jsonResponseWithSuccessMessageApi(__('success.data_fetched_successfully'), $response, 200); + } catch (\Exception $e) { + Log::error('FAW get data controller function failed: ' . $e->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function restRegister(Request $request) + { + try { + $validator = Validator::make($request->all(), [ + 'first_name' => 'required|string|min:2|max:100', + 'last_name' => 'required|string|min:2|max:100', + 'role' => 'required|string|min:2|max:100', + 'restaurant_xid' => 'required', + 'date_of_birth' => 'required|date', + 'email_address' => [ + 'required', + 'string', + 'email', + 'max:100', + Rule::unique('iam_principal')->where(function ($query) { + return $query->where('principal_type_xid', 4)->whereNull('deleted_at'); + }), + ], + 'phone_number' => 'required|min:10', + ]); + + if ($validator->fails()) { + $validationErrors = $validator->errors()->all(); + Log::error("Registration validation error: " . implode(", ", $validationErrors)); + return jsonResponseWithErrorMessageApi($validationErrors, 403); + } + return $this->RestAuthApiService->restRegister($request); + } catch (\Exception $ex) { + Log::error("Registration API Failed: " . $ex->getMessage()); + return jsonResponseWithErrorMessage(__('error_message.something_went_wrong'), 500); + } + } + +} diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 0a49154..dc3adc9 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -4,12 +4,151 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\IamPrincipal; +use Illuminate\Support\Facades\DB; +use App\Models\ManageRestaurant; + class DashboardController extends Controller { - public function index(){ + // public function showDashboard(){ - return view('Admin.dashboard'); + // return view('Admin.dashboard'); + // } + public function showDashboard() + { + + + // Fetching data for sorting by day + // $dailyData = OrderedPassport::select(DB::raw("COUNT(*) as count"), DB::raw("DATE(created_at) as date")) + // ->whereBetween('created_at', [now()->subDays(7), now()]) // Fetch data for the last 7 days + // ->groupBy(DB::raw("DATE(created_at)")) + // ->orderBy(DB::raw("DATE(created_at)")) + // ->pluck('count', 'date') + // ->toArray(); + + // Ensure that $dailyData contains zeros for days with no data + $start_date = now()->subDays(7)->startOfDay(); + $end_date = now()->endOfDay(); + $formattedDailyData = []; + while ($start_date <= $end_date) { + $formattedDailyData[$start_date->format('Y-m-d')] = isset($dailyData[$start_date->format('Y-m-d')]) ? $dailyData[$start_date->format('Y-m-d')] : 0; + $start_date->addDay(); + } + + // Default sales chart data (monthly) + // $defaultData = OrderedPassport::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month")) + // ->whereYear('created_at', date('Y')) + // ->groupBy(DB::raw("MONTH(created_at)")) + // ->orderBy(DB::raw("MONTH(created_at)")) + // ->pluck('count', 'month') + // ->toArray(); + + // Ensure that $defaultData contains zeros for months with no data + $months = range(1, 12); + $formattedDefaultData = []; + foreach ($months as $month) { + $formattedDefaultData[$month] = isset($defaultData[$month]) ? $defaultData[$month] : 0; + } + + // $quarterlyData = OrderedPassport::select( + // DB::raw("COUNT(*) as count"), + // DB::raw("QUARTER(created_at) as quarter") + // ) + // ->whereYear('created_at', date('Y')) + // ->groupBy(DB::raw("QUARTER(created_at)")) + // ->orderBy(DB::raw("QUARTER(created_at)")) + // ->pluck('count', 'quarter') + // ->toArray(); + + // Ensure that $quarterlyData contains zeros for quarters with no data + for ($i = 1; $i <= 4; $i++) { + if (!isset($quarterlyData[$i])) { + $quarterlyData[$i] = 0; + } + } + + // Fetching data for yearly option + // $yearlyData = OrderedPassport::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year")) + // ->groupBy(DB::raw("YEAR(created_at)")) + // ->pluck('count', 'year') + // ->toArray(); + // + // Monthly data + $dataMonthlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month")) + ->whereIn('principal_type_xid', [3]) + ->whereYear('created_at', date('Y')) + ->groupBy(DB::raw("MONTH(created_at)")) + ->orderBy(DB::raw("MONTH(created_at)")) + ->pluck('count', 'month') + ->toArray(); + + $dataMonthlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month")) + ->whereIn('principal_type_xid', [4]) + ->whereYear('created_at', date('Y')) + ->groupBy(DB::raw("MONTH(created_at)")) + ->orderBy(DB::raw("MONTH(created_at)")) + ->pluck('count', 'month') + ->toArray(); + + // Quarterly data + $dataQuarterlyWithType3 = IamPrincipal::select( + DB::raw("COUNT(*) as count"), + DB::raw("QUARTER(created_at) as quarter") + ) + ->whereIn('principal_type_xid', [3]) + ->groupBy(DB::raw("QUARTER(created_at)")) + ->orderBy(DB::raw("QUARTER(created_at)")) + ->pluck('count', 'quarter') + ->toArray(); + for ($i = 1; $i <= 4; $i++) { + if (!isset($dataQuarterlyWithType3[$i])) { + $dataQuarterlyWithType3[$i] = 0; + } + } + + $dataQuarterlyWithType4 = IamPrincipal::select( + DB::raw("COUNT(*) as count"), + DB::raw("QUARTER(created_at) as quarter") + ) + ->whereIn('principal_type_xid', [4]) + ->groupBy(DB::raw("QUARTER(created_at)")) + ->orderBy(DB::raw("QUARTER(created_at)")) + ->pluck('count', 'quarter') + ->toArray(); + for ($i = 1; $i <= 4; $i++) { + if (!isset($dataQuarterlyWithType4[$i])) { + $dataQuarterlyWithType4[$i] = 0; + } + } + + // Yearly data + $dataYearlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year")) + ->whereIn('principal_type_xid', [3]) + ->groupBy(DB::raw("YEAR(created_at)")) + ->pluck('count', 'year') + ->toArray(); + // dd($dataYearlyWithType3); + + $dataYearlyWithType4 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year")) + ->whereIn('principal_type_xid', [4]) + ->groupBy(DB::raw("YEAR(created_at)")) + ->pluck('count', 'year') + ->toArray(); + + + $customerCount = IamPrincipal::where('principal_type_xid', '=', 3)->count(); + // $activePassports = ManagePassport::where('is_active', 1)->take(12)->get(); + // $restaurantCount = ManageRestaurant::where('is_redeem', 1)->count(); + $restaurantCount = ManageRestaurant::where('is_active', 1)->count(); + + // $recent_transaction = OrderedPassport::with('order', 'order_passport', 'carts.passport', 'iamPrincipal')->get()->toArray(); + // $datas = MyPassportVoucher::with('passportVouchers', 'passportData', 'customer')->get()->toArray(); + + // Pass the data to the view + // return view('Admin.dashboard', compact('customerCount', 'activePassports', 'restaurantCount', 'recent_transaction', 'datas', 'formattedDefaultData', 'quarterlyData', 'yearlyData', 'dataMonthlyWithType3', 'dataMonthlyWithType4', 'dataQuarterlyWithType3', 'dataQuarterlyWithType4', 'dataYearlyWithType3', 'dataYearlyWithType4','formattedDailyData')); + return view('Admin.dashboard', compact('customerCount','restaurantCount','dataMonthlyWithType3','dataMonthlyWithType4','dataQuarterlyWithType3', 'dataQuarterlyWithType4', 'dataYearlyWithType3', 'dataYearlyWithType4')); + } } diff --git a/app/Models/ManageRestaurant.php b/app/Models/ManageRestaurant.php index 1f2b4bf..dd3d597 100644 --- a/app/Models/ManageRestaurant.php +++ b/app/Models/ManageRestaurant.php @@ -8,7 +8,30 @@ use Illuminate\Database\Eloquent\Model; class ManageRestaurant extends Model { use HasFactory; + protected $table='manage_restaurants'; + protected $fillable=[ + 'id', + 'name', + 'description', + 'restaurant_id', + 'address', + 'image', + 'bio', + 'try_on_1', + 'try_on_2', + 'try_on_3', + 'try_on_4', + 'exclusion', + 'latitude', + 'longtitude', + 'is_active', + 'created_by', + 'modified_by', + 'deleted_at', + 'created_at', + 'updated_at' + ]; public function operatingHours() { return $this->hasMany(OperatingHour::class, 'manage_restaurant_xid'); diff --git a/app/Services/APIs/RestaurantService/RedeemApiService.php b/app/Services/APIs/RestaurantService/RedeemApiService.php new file mode 100644 index 0000000..6146e93 --- /dev/null +++ b/app/Services/APIs/RestaurantService/RedeemApiService.php @@ -0,0 +1,248 @@ +find($rest->id); + + $restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role')->where('principal_xid', $rest->id)->get(); + + $restaurantDetail = []; + foreach ($restaurantRoles as $role) { + $restaurantImage = ManageVoucherModel::select('id', 'coupon_name', 'description', 'thumbnail_image', 'image', 'location_name')->find($role->restaurant_xid); + if ($restaurantImage) { + $restaurantImage->thumbnail_image = ListingImageUrl('voucher_thumbnail_images', $restaurantImage->thumbnail_image); + $restaurantImage->image = ListingImageUrl('voucher_images', $restaurantImage->image); + } + $restaurantDetail[] = $restaurantImage; + + $redeemedVouchers = []; + $redemptionUndoneVouchers = []; + + $vouchers = MyPassportVoucher::select('id', 'order_xid', 'iam_principal_xid', 'manage_passports_xid', 'manage_vouchers_xid', 'is_redeem', 'count', 'redeem_date', 'is_redeemption_undone') + ->where('manage_vouchers_xid', $role->restaurant_xid) + ->where('is_redeem', 1) + ->get(); + + $redeemptionUndone = MyPassportVoucher::select('id', 'order_xid', 'iam_principal_xid', 'manage_passports_xid', 'manage_vouchers_xid', 'is_redeem', 'count', 'redeem_date', 'is_redeemption_undone', 'redeemption_undone_date') + ->where('manage_vouchers_xid', $role->restaurant_xid) + ->where([['is_redeem', 0], ['is_redeemption_undone', 1]]) + ->get(); + + foreach ($vouchers as $voucher) { + $userDetail = IamPrincipal::select('id', 'first_name', 'email_address', 'profile_photo', 'address_line1') + ->where('id', $voucher->iam_principal_xid) + ->first(); + + if ($userDetail) { + if ($userDetail->profile_photo) { + $userDetail->profile_photo = ListingImageUrl('profile_image', $userDetail->profile_photo); + } else { + $userDetail->profile_photo = asset('public/assets/img/blankProfile.png'); + } + + $voucher->user_detail = $userDetail; + $redeemedVouchers[] = $voucher; + } else { + + Log::error('User detail not found for IAM principal ID: ' . $voucher->iam_principal_xid); + } + } + + + foreach ($redeemptionUndone as $undone) { + $userDetail = IamPrincipal::select('id', 'first_name', 'email_address', 'profile_photo', 'address_line1') + ->where('id', $undone->iam_principal_xid) + ->first(); + + if ($userDetail) { + if ($userDetail->profile_photo) { + $userDetail->profile_photo = ListingImageUrl('profile_image', $userDetail->profile_photo); + } else { + $userDetail->profile_photo = asset('public/assets/img/blankProfile.png'); + } + + $undone->user_detail = $userDetail; + $redemptionUndoneVouchers[] = $undone; + } else { + + Log::error('User detail not found for IAM principal ID: ' . $undone->iam_principal_xid); + } + } + + + $restaurantDetail['redeemed_vouchers'] = $redeemedVouchers; + $restaurantDetail['redemption_undone_vouchers'] = $redemptionUndoneVouchers; + } + + return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $restaurantDetail, 200); + } catch (Exception $ex) { + Log::error('Restaurant Get data service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + + public function undoRedemption($restIamId, $request) + { + try { + $voucherDetail = MyPassportVoucher::with('passportData', 'voucherData')->where('id', $request->voucher_id)->first(); + if ($voucherDetail) { + $voucherDetail->update([ + 'is_redeem' => 0, + 'redeem_date' => null, + 'is_redeemption_undone' => 1, + 'redeemption_undone_date' => now(), + + ]); + $imagePath = ListingImageUrl('voucher_images', $voucherDetail->voucherData->image); + $customerTitle = "Your voucher was successfully undo redemption for " . $voucherDetail->passportData->passport_name; + $customerMessage = $voucherDetail->voucherData->coupon_name . " Voucher Undo Redemption Successfully"; + $customerContentType = 'Voucher_UndoRedemption'; + $customerImageUrl = $imagePath; + $customerData = IamPrincipal::where('id', $voucherDetail->iam_principal_xid)->where('notification_status', 1)->where('principal_type_xid', 3)->first(); + if ($customerData) { + $pushNotificationToCustomer = onesignalhelper::sendNotificationApi( + $customerData->one_signal_player_id, + $customerTitle, + $customerMessage, + $customerContentType, + $customerImageUrl, + $id = null + ); + + onesignalhelper::StoreNotificationDetails($customerData->id, $customerContentType, $customerTitle, $customerImageUrl); + } + $restUser = IamPrincipal::where('id', $restIamId)->where('notification_status', 1)->where('principal_type_xid', 4)->first(); + if ($restUser) { + $restImagePath = ListingImageUrl('voucher_images', $voucherDetail->voucherData->image); + $restTitle = "voucher Undo redemption successful for " . $voucherDetail->passportData->passport_name; + $restMessage = $voucherDetail->voucherData->coupon_name . " Voucher Undo Redemption Successfully"; + $restContentType = 'Voucher_UndoRedemption'; + $restImageUrl = $restImagePath; + + $pushNotificationToCustomer = onesignalhelper::restSendNotificationApi( + $restUser->one_signal_player_id, + $restTitle, + $restMessage, + $restContentType, + $restImageUrl, + $id = null + ); + + onesignalhelper::StoreNotificationDetails($restUser->id, $restContentType, $restTitle, $restImageUrl); + } + return jsonResponseWithSuccessMessageApi(__('auth.data_updated_successfully'), 200); + } else { + return jsonResponseWithErrorMessageApi(__('auth.voucher_not_found'), 404); + } + } catch (Exception $ex) { + Log::error('Restaurant update profile service failed: ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + public function searchRedemption($restIamId, $request) + { + try { + $searchQuery = $request->input('search_data'); + + $rest = IamPrincipal::findOrFail($restIamId); + $data['user_detail'] = IamPrincipal::select('id', 'first_name', 'last_name', 'email_address', 'phone_number', 'date_of_birth')->find($rest->id); + + $restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role')->where('principal_xid', $rest->id)->get(); + + $restaurantDetail = []; + foreach ($restaurantRoles as $role) { + $restaurantImage = ManageVoucherModel::select('id', 'coupon_name', 'description', 'thumbnail_image', 'image', 'location_name')->find($role->restaurant_xid); + if ($restaurantImage) { + $restaurantImage->thumbnail_image = ListingImageUrl('voucher_thumbnail_images', $restaurantImage->thumbnail_image); + $restaurantImage->image = ListingImageUrl('voucher_images', $restaurantImage->image); + } + $restaurantDetail[] = $restaurantImage; + + $redeemedVouchers = []; + $redemptionUndoneVouchers = []; + + $vouchers = MyPassportVoucher::select('id', 'order_xid', 'iam_principal_xid', 'manage_passports_xid', 'manage_vouchers_xid', 'is_redeem', 'count', 'redeem_date', 'is_redeemption_undone') + ->where('manage_vouchers_xid', $role->restaurant_xid) + ->where('is_redeem', 1) + ->get(); + + foreach ($vouchers as $voucher) { + $userDetail = IamPrincipal::select('id', 'first_name', 'email_address', 'profile_photo', 'address_line1') + ->where('id', $voucher->iam_principal_xid) + ->first(); + + if ($userDetail && (stripos($userDetail->first_name, $searchQuery) !== false || stripos($voucher->id, $searchQuery) !== false || stripos($voucher->redeem_date, $searchQuery) !== false)) { + if ($userDetail->profile_photo) { + $userDetail->profile_photo = ListingImageUrl('profile_image', $userDetail->profile_photo); + } else { + $userDetail->profile_photo = asset('public/assets/img/blankProfile.png'); + } + + $voucher->user_detail = $userDetail; + $redeemedVouchers[] = $voucher; + } else { + + Log::error('User detail not found for IAM principal ID: ' . $voucher->iam_principal_xid); + } + } + + $redeemptionUndone = MyPassportVoucher::select('id', 'order_xid', 'iam_principal_xid', 'manage_passports_xid', 'manage_vouchers_xid', 'is_redeem', 'count', 'redeem_date', 'is_redeemption_undone', 'redeemption_undone_date') + ->where('manage_vouchers_xid', $role->restaurant_xid) + ->where([['is_redeem', 0], ['is_redeemption_undone', 1]]) + ->get(); + + foreach ($redeemptionUndone as $undone) { + $userDetail = IamPrincipal::select('id', 'first_name', 'email_address', 'profile_photo', 'address_line1') + ->where('id', $undone->iam_principal_xid) + ->first(); + + if ($userDetail && (stripos($userDetail->first_name, $searchQuery) !== false || stripos($undone->id, $searchQuery) !== false || stripos($undone->redeemption_undone_date, $searchQuery) !== false)) { + if ($userDetail->profile_photo) { + $userDetail->profile_photo = ListingImageUrl('profile_image', $userDetail->profile_photo); + } else { + $userDetail->profile_photo = asset('public/assets/img/blankProfile.png'); + } + + $undone->user_detail = $userDetail; + $redemptionUndoneVouchers[] = $undone; + } else { + + Log::error('User detail not found for IAM principal ID: ' . $undone->iam_principal_xid); + } + } + + if (empty($searchQuery)) { + $restaurantDetail['redeemed_vouchers'] = $redeemedVouchers; + $restaurantDetail['redemption_undone_vouchers'] = $redemptionUndoneVouchers; + } + + $restaurantDetail['redeemed_vouchers'] = $redeemedVouchers; + $restaurantDetail['redemption_undone_vouchers'] = $redemptionUndoneVouchers; + } + + return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $restaurantDetail, 200); + } catch (Exception $ex) { + Log::error('Restaurant Get data service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } +} diff --git a/app/Services/APIs/RestaurantService/RestAuthApiService.php b/app/Services/APIs/RestaurantService/RestAuthApiService.php new file mode 100644 index 0000000..9529edb --- /dev/null +++ b/app/Services/APIs/RestaurantService/RestAuthApiService.php @@ -0,0 +1,364 @@ +where('is_active', 1)->get()->toArray(); + return $data; + } catch (Exception $ex) { + DB::rollBack(); + Log::error('Terms and condition Get service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + public function restRegister($request) + { + try { + DB::beginTransaction(); + $restaurantId = $request->input('restaurant_xid'); + + // Fetch the restaurant details based on the selected restaurantId + $selectedRestaurant = ManageVoucherModel::find($restaurantId); + + if (!$selectedRestaurant) { + return jsonResponseWithErrorMessageApi(__('auth.restaurant_data_not_found'), 403); + } + + // Create a new restaurant user record + $restaurantuser = IamPrincipal::create([ + 'one_signal_player_id' => $request->one_signal_player_id, + 'first_name' => $request->first_name, + 'last_name' => $request->last_name, + 'email_address' => $request->email_address, + // 'password' => Hash::make('Cheers@123'), + 'principal_type_xid' => 4, //4 for restaurant + 'principal_source_xid' => 2, //2 for mobile + 'phone_number' => $request->phone_number, + 'date_of_birth' => $request->date_of_birth, + 'is_active' => '0', + ]); + + $restaurantUserRole = IamPrincipalRestaurantRole::create([ + 'principal_xid' => $restaurantuser->id, + 'role' => $request->role, + 'restaurant_xid' => $restaurantId, + ]); + + DB::commit(); + + // $token = auth()->login($restaurantuser); + + // Return response with user details, access token, and status + $response = [ + 'user' => $restaurantuser, + // 'restaurant_details' => $restaurantId, + // 'access_token' => $token, + 'token_type' => 'bearer', + 'status' => 'Your request has been sent. Kindly check your email.' + ]; + return jsonResponseWithSuccessMessage(__('auth.Rest_user_created'), $response, 200); + } catch (QueryException $e) { + // Rollback transaction in case of an error + DB::rollBack(); + Log::error('Restaurant Registration Failed ' . $e->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403); + } + } + + + public function login($request) + { + try { + $credentials = [ + 'email_address' => $request->email_address, + 'password' => $request->password, + ]; + + $isExistEmail = IamPrincipal::where('email_address', $request->email_address) + ->where('principal_type_xid', 4) + ->whereNull('deleted_at') + ->first(); + if ($isExistEmail == null) { + Log::error('Email not exist'); + return jsonResponseWithErrorMessageApi(__('auth.incorrect_email_passport'), 403); + } + if ($isExistEmail && !(Hash::check($request->password, $isExistEmail->password))) { + Log::error('Entered Password is wrong.'); + return jsonResponseWithErrorMessageApi(__('auth.incorrect_email_passport'), 403); + } + if (!$token = auth()->login($isExistEmail)) { + Log::error('Customer Login Failed'); + return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403); + } + + $isExistEmail->one_signal_player_id = $request->one_signal_player_id; + $isExistEmail->save(); + $response = [ + 'userId' => $isExistEmail->id, + 'access_token' => $token, + ]; + return jsonResponseWithSuccessMessage(__('auth.data_fetched_successfully'), $response, 200); + } catch (QueryException $e) { + + + Log::error('Customer Login Failed ' . $e->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.authentication_failed'), 403); + } + } + + + protected function responseWithToken($token, $isExistEmail) + { + return [ + 'message' => 'You have logged in successfully', + 'access_token' => $token, + 'token_type' => 'bearer', + 'status' => 'success', + 'iam_principal_id' => $isExistEmail->id + ]; + } + + + public function restForgotPassword($request) + { + try { + DB::beginTransaction(); + $user = IamPrincipal::where('email_address', $request->email_address) + ->where('principal_type_xid', 4) + ->whereNull('deleted_at') + ->first(); + //use this for both customer and restaurant just change principal_type_xid 4 + if ($user == null) { + Log::error('Email not exist'); + return jsonResponseWithErrorMessageApi(__('auth.incorrect_email'), 403); + } + // Define the generateOTP function + $otp = $this->generateOTP(); + + IamPrincipalOTP::updateOrCreate( + ['principal_xid' => $user->id], + [ + 'otp_code' => $otp, + 'otp_purpose' => 'forgot password', + 'valid_till' => Carbon::now()->addMinutes(2), + 'is_used' => 0, + ] + ); + + // $this->email_address = $user->email_address; + + $mail = Mail::send( + 'frontend.Mail.customer_forgot_password_mail', + [ + 'user' => $user, + 'otp_code' => $otp, + 'valid_till' => Carbon::now()->addMinutes(2) + ], + function ($message) use ($user) { + $message->to($user->email_address); + $message->subject('Forgot Password Mail Page'); + } + ); + + //sendmail end + $response = ['iam_principal_xid' => $user->id]; + DB::commit(); + Log::info('Customer Forgot Password otp sent successfully'); + return jsonResponseWithSuccessMessage(__('auth.otp_sent_successfully'), $response, 200); + } catch (\Exception $e) { + DB::rollBack(); + Log::error('Customer Forgot Password OTP function failed: ' . $e->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function restVerifyOTP($request) + { + try { + DB::beginTransaction(); + // Retrieve the user's OTP record + $User = IamPrincipal::where('email_address', $request->email_address) + ->where('principal_type_xid', 4) + ->whereNull('deleted_at') + ->first(); + + + $iamPrincipal = IamPrincipalOTP::where('principal_xid', $User->id) + ->first(); + + // Check if OTP record exists for the user + $errors = []; + + if (!$iamPrincipal) { + $errors[] = __('auth.failed_to_verify_otp'); + return jsonResponseWithErrorMessageApi( + $errors,403 + ); + } + + // Check if the provided OTP matches the stored OTP + if ($iamPrincipal->otp_code !== $request->otp) { + $errors[] = __('auth.invalid_otp'); + return jsonResponseWithErrorMessageApi( + $errors,403 + ); + } + + // Check if the OTP is still valid + if (Carbon::now()->gt($iamPrincipal->valid_till)) { + $errors[] = __('auth.otp_expired'); + return jsonResponseWithErrorMessageApi( + $errors,403 + ); + } + + // Check if the OTP has already been used + if ($iamPrincipal->is_used === 1) { + $errors[] = __('auth.otp_already_used'); + return jsonResponseWithErrorMessageApi( + $errors,403 + ); + } + + + + // Mark OTP as used + $iamPrincipal->is_used = 1; + $iamPrincipal->save(); + DB::commit(); + $response = [ + 'iam_principal_xid' => $User->id + ]; + Log::info('Customer OTP verified successfully'); + return jsonResponseWithSuccessMessageApi(__('auth.otp_verified'), $response, 200); + } catch (\Exception $e) { + DB::rollBack(); + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function restChangePassword($request) + { + try { + DB::beginTransaction(); + + $User = IamPrincipal::where('id', $request->iam_principal_xid) + ->where('is_active', 1) + ->first(); + + + $User->password = Hash::make($request->password); + $User->save(); + DB::commit(); + return $User; + } catch (\Exception $e) { + DB::rollBack(); + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage()); + return response()->json(__('something_went_wrong'), 500); + } + } + public function restResendOtp($request) + { + try { + DB::beginTransaction(); + // Retrieve the user's OTP record + $iamPrincipal = IamPrincipalOTP::where('principal_xid', $request->iam_principal_xid) + ->first(); + $user = IamPrincipal::where('id', $request->iam_principal_xid) + ->where('is_active', '1') + ->first(); + + // Check if OTP record exists for the user + if (!$iamPrincipal) { + return jsonResponseWithErrorMessageApi(__('auth.not_found_otp'), 203); + } + + // Calculate the allowed resend interval (2 minutes) + $allowedResendInterval = Carbon::now()->subMinutes(2); + + // Check if the user can resend OTP only after a 2-minute interval + if ($iamPrincipal->updated_at >= $allowedResendInterval) { + + return jsonResponseWithErrorMessageApi(__('auth.try_resend_otp'), 429); + } + + // Generate a new OTP for the user + $otp = $this->generateOTP(); + + // Update the OTP record with the new OTP and validity + $iamPrincipal->principal_xid = $request->iam_principal_xid; + $iamPrincipal->otp_code = $otp; + $iamPrincipal->otp_purpose = $request->otp_purpose; + $iamPrincipal->valid_till = Carbon::now()->addMinutes(2); + $iamPrincipal->is_used = 0; + $iamPrincipal->save(); + + + // $this->email_address = $user->email_address; + + $mail = Mail::send( + 'frontend.Mail.customer_forgot_password_mail', + [ + 'user' => $user, + 'otp_code' => $otp, + 'valid_till' => Carbon::now()->addMinutes(2) + ], + function ($message) use ($user) { + $message->to($user->email_address); + $message->subject('Forgot Password Mail Page'); + } + ); + + + DB::commit(); + $response = [ + 'iam_principal_xid' => $iamPrincipal->principal_xid, + 'email_address' => $user->email_address + + ]; + + return jsonResponseWithSuccessMessageApi(__('auth.otp_resend_sent_successfully'), $response, 200); + } catch (\Exception $e) { + + DB::rollBack(); + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage()); + return response()->json(__('something_went_wrong'), 500); + } + } + + function generateOTP() + { + // Define the length of the OTP + $otpLength = 4; + + // Generate a random OTP with $otpLength digits + $otp = ''; + for ($i = 0; $i < $otpLength; $i++) { + $otp .= rand(0, 9); + } + return $otp; + } +} diff --git a/app/Services/APIs/RestaurantService/RestCMSService.php b/app/Services/APIs/RestaurantService/RestCMSService.php new file mode 100644 index 0000000..ac13202 --- /dev/null +++ b/app/Services/APIs/RestaurantService/RestCMSService.php @@ -0,0 +1,176 @@ +where([['is_active', '1'], ['faq_category_id', '1']]) + ->get() + ->toArray(); + + $data['restaurant'] = Faq::select('id', 'question', 'answers') + ->where([['is_active', '1'], ['faq_category_id', '2']]) + ->get() + ->toArray(); + + return $data; + } catch (Exception $ex) { + DB::rollBack(); + Log::error('Faq Get service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function RestAboutUs() + { + try { + $data['customer'] = Aboutus::select('id', 'title', 'thumbnail_image', 'description', 'aboutus_category_xid') + ->where('aboutus_category_xid', '1') + ->get() + ->map(function ($item) { + $item['description'] = strip_tags($item['description']); + return $item; + }) + ->toArray(); + + $data['restaurant'] = Aboutus::select('id', 'title', 'thumbnail_image', 'description', 'aboutus_category_xid') + ->where('aboutus_category_xid', '2') + ->get() + ->map(function ($item) { + $item['description'] = strip_tags($item['description']); + return $item; + }) + ->toArray(); + foreach ($data['customer'] as $k => $val) { + $data['customer'][$k]['thumbnail_image'] = ListingImageUrl('about_images', $val['thumbnail_image']); + } + + foreach ($data['restaurant'] as $k => $val) { + $data['restaurant'][$k]['thumbnail_image'] = ListingImageUrl('about_images', $val['thumbnail_image']); + } + + return $data; + } catch (Exception $ex) { + DB::rollBack(); + Log::error('About us Get service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function RestPrivacyPolicy() + { + try { + $data['customer'] = PrivacyPolicy::select('id', 'description') + ->where('terms_category_id', '1') + ->get() + ->map(function ($item) { + $item['description'] = strip_tags($item['description']); + return $item; + }) + ->toArray(); + + $data['restaurant'] = PrivacyPolicy::select('id', 'description') + ->where('terms_category_id', '2') + ->get() + ->map(function ($item) { + $item['description'] = strip_tags($item['description']); + return $item; + }) + ->toArray(); + return $data; + } catch (Exception $ex) { + DB::rollBack(); + Log::error('Privacy policy Get service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function RestNewsArticles() + { + try { + $data['customer'] = NewsArticle::select('id', 'name', 'description', 'thumbnail_image', 'image') + ->where([['is_active', '1'], ['news_articles_category_xid', '1']]) + ->get() + ->map(function ($item) { + $item['description'] = strip_tags($item['description']); + return $item; + }) + ->toArray(); + + $data['restaurant'] = NewsArticle::select('id', 'name', 'description', 'thumbnail_image', 'image') + ->where([['is_active', '1'], ['news_articles_category_xid', '2']]) + ->get() + ->map(function ($item) { + $item['description'] = strip_tags($item['description']); + return $item; + }) + ->toArray(); + + //thumbnail_image for 'customer' data + foreach ($data['customer'] as $k => $val) { + $data['customer'][$k]['thumbnail_image'] = ListingImageUrl('news_article_thumb', $val['thumbnail_image']); + $data['customer'][$k]['image'] = ListingImageUrl('news_article', $val['image']); + } + + //thumbnail_image for 'restaurant' data + foreach ($data['restaurant'] as $k => $val) { + $data['restaurant'][$k]['thumbnail_image'] = ListingImageUrl('news_article_thumb', $val['thumbnail_image']); + $data['restaurant'][$k]['image'] = ListingImageUrl('news_article', $val['image']); + } + + return $data; + } catch (Exception $ex) { + DB::rollBack(); + Log::error('News and articles Get service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function RestContactUs($request) + { + try { + DB::beginTransaction(); + //create user_data + $user_data = IamPrincipal::where('id', $request['iam_principal_id'])->first(); + if ($user_data) { + // Create a new instance of ManageContactus model + $contact = new ManageContactus(); + $contact->principal_xid = $user_data->id; + $contact->name = $request->name; + $contact->email = $request->email; + $contact->message = $request->message; + // Save the contact data + $contact->save(); + + DB::commit(); + + //response data + Log::info('Contact form data Created successfully'); + return jsonResponseWithSuccessMessageApi(__('success.save_data'), [], 201); + } else { + Log::error('Contact not found in addVendorContactForm.'); + return jsonResponseWithErrorMessageApi(__('auth.validation_failed'), 403); + } + } catch (Throwable $ex) { + DB::rollBack(); + Log::error('Contact API failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } +} diff --git a/app/Services/APIs/RestaurantService/RestaurantApiService.php b/app/Services/APIs/RestaurantService/RestaurantApiService.php new file mode 100644 index 0000000..4ff9e9a --- /dev/null +++ b/app/Services/APIs/RestaurantService/RestaurantApiService.php @@ -0,0 +1,213 @@ +findOrFail($restIamId); + + // Set profile photo + if ($userDetail->profile_photo) { + $userDetail->profile_photo = ListingImageUrl('profile_image', $userDetail->profile_photo); + } else { + $userDetail->profile_photo = asset('public/assets/img/blankProfile.png'); + } + + // Find restaurant roles associated with the user + $restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role') + ->where('principal_xid', $userDetail->id) + ->get(); + + // $restaurantDetails = []; + + foreach ($restaurantRoles as $restaurantRole) { + $restaurant = ManageVoucherModel::select('id', 'coupon_name', 'description', 'coupon_id', 'thumbnail_image', 'image', 'location_name', 'bio', 'try_on_1', 'try_on_2', 'try_on_3', 'try_on_4', 'try_on_5', 'phone_number') + ->where('id', $restaurantRole->restaurant_xid) + ->where('is_active', 1) + ->first(); + + if ($restaurant) { + $restaurant->image = ListingImageUrl('voucher_images', $restaurant->image); + $restaurant->thumbnail_image = ListingImageUrl('voucher_thumbnail_images', $restaurant->thumbnail_image); + $restaurant->description = strip_tags($restaurant->description); + + // $restaurantDetails[] = $restaurant; + } + } + + // Construct response + $response = [ + 'user_detail' => $userDetail, + 'restaurant_details' => $restaurant, + ]; + + // Return JSON response with success message + return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $response, 200); + } catch (Exception $ex) { + // Log error and return error response + Log::error('Restaurant Get data service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + + public function updateRestaurantDetail($restIamId, $request) + { + try { + DB::beginTransaction(); + $data = IamPrincipal::findOrFail($restIamId); + if (!$data) { + DB::rollBack(); + return jsonResponseWithErrorMessageApi(__('auth.user_not_found'), 404); + } + $restaurantRoles = IamPrincipalRestaurantRole::select('id', 'principal_xid', 'restaurant_xid', 'role')->where('principal_xid', $restIamId)->get(); + if ($restaurantRoles->isEmpty()) { + DB::rollBack(); + return jsonResponseWithErrorMessageApi(__('auth.restaurant_data_not_found'), 404); + } + $restaurantRole = $restaurantRoles->first(); + $restaurant = ManageVoucherModel::findOrFail($restaurantRole->restaurant_xid); + if (!$restaurant) { + DB::rollBack(); + return jsonResponseWithErrorMessageApi(__('error_message.restaurant_data_not_found'), 404); + } + + $restaurant->update([ + 'coupon_name' => $request['restaurant_name'], + 'description' => $request['description'], + 'location_name' => $request['location'], + 'bio' => $request['bio'], + 'try_on_1' => $request['try_on_1'], + 'try_on_2' => $request['try_on_2'], + 'try_on_3' => $request['try_on_3'], + 'try_on_4' => $request['try_on_4'], + 'try_on_5' => $request['try_on_5'], + 'phone_number' => $request['phone_number'], + ]); + $restaurant->description = strip_tags($restaurant->description); + + DB::commit(); + return jsonResponseWithSuccessMessageApi(__('auth.data_updated_successfully'), $restaurant, 200); + } catch (Exception $ex) { + DB::rollBack(); + Log::error('Restaurant update profile service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + + + public function updateRestProfileDetail($restIamId, $request) + { + try { + DB::beginTransaction(); + $data = IamPrincipal::select('id', 'first_name', 'last_name', 'email_address', 'phone_number', 'date_of_birth')->findOrFail($restIamId); + if (!$data) { + DB::rollBack(); + return jsonResponseWithErrorMessage(__('error_message.user_details_not_found'), 404); + } + + if ($request->has('image')) { + $image = $request->image; + $tnormalImage = saveSingleImageWithoutCrop($image, 'profile_image', null); + $data->update(['profile_photo' => $tnormalImage]); + DB::commit(); + + } + if ($request->has('first_name')) { + $data->first_name = $request->first_name; + $data->save(); + DB::commit(); + } + if ($request->has('last_name')) { + $data->last_name = $request->last_name; + $data->save(); + DB::commit(); + } + if ($request->has('date_of_birth')) { + $data->date_of_birth = $request->date_of_birth; + $data->save(); + DB::commit(); + } + if ($request->has('phone_number')) { + $data->phone_number = $request->phone_number; + $data->save(); + DB::commit(); + } + + if ($request->has('email_address')) { + $email = $request->input('email_address'); + if ($email !== $data->email_address) { + $existingUser = IamPrincipal::where('email_address', $email) + ->where('id', '!=', $restIamId) + ->whereNull('deleted_at') + ->where('principal_type_xid', 4) + ->exists(); + + if ($existingUser) { + DB::rollBack(); + return jsonResponseWithErrorMessageApi(__('auth.email_already_exist'), 400); + } + } + } + // $data->update([ + // 'first_name' => $request['first_name'], + // 'last_name' => $request['last_name'], + // 'email_address' => $request['email_address'], + // 'phone_number' => $request['phone_number'], + // 'date_of_birth' => $request['date_of_birth'], + // ]); + $data->save(); + DB::commit(); + return jsonResponseWithSuccessMessageApi(__('auth.data_updated_successfully'), $data, 200); + } catch (Exception $ex) { + DB::rollBack(); + + Log::error('Restaurant update profile service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } + + public function resetRestPassword($restIamId, $request) + { + try { + DB::beginTransaction(); + $user = IamPrincipal::findOrFail($restIamId); + if (!Hash::check($request->current_password, $user->password)) { + DB::rollBack(); + return jsonResponseWithErrorMessageApi(__('auth.invalid_current_passsword'), 403); + } else { + $user->update([ + 'password' => Hash::make($request->new_password) + ]); + DB::commit(); + return jsonResponseWithSuccessMessageApi(__('auth.password_updated_successfully'), $user); + } + } catch (Exception $ex) { + DB::rollBack(); + Log::error('Update password service failed : ' . $ex->getMessage()); + return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500); + } + } +} diff --git a/resources/views/Admin/dashboard.blade.php b/resources/views/Admin/dashboard.blade.php index 2afaced..b6b7578 100644 --- a/resources/views/Admin/dashboard.blade.php +++ b/resources/views/Admin/dashboard.blade.php @@ -18,7 +18,7 @@
No of Customers
-

08

+

{{ $customerCount }}

@@ -55,7 +55,7 @@
No of Restaurants
-

05

+

{{ $restaurantCount }}

@@ -66,7 +66,7 @@
User Graph
- @@ -664,5 +664,58 @@ // --------- Sales chart ends ------------ }); + // Add event listener to the filter select element + document.getElementById('graph-filter').addEventListener('change', function(event) { + var selectedFilter = event.target.value; + userChartData = getUserChartData(selectedFilter); // Get data based on selected filter + userCategories = getUserChartCategories(selectedFilter); // Update x-axis categories + + userChart.updateSeries(userChartData); // Update chart data + userChart.updateOptions({ + xaxis: { + categories: userCategories + } + }); // Update chart options + }); + // Function to fetch data based on selected filter + function getUserChartData(filter) { + switch (filter) { + case 'monthly': + return [{ + name: 'Customer', + data: + }, + { + name: 'Restaurant', + data: + } + ]; + case 'quarterly': + return [{ + name: 'Customer', + data: + }, + { + name: 'Restaurant', + data: + } + ]; + case 'yearly': + return [{ + name: 'Customer', + data: + }, + { + name: 'Restaurant', + data: + } + ]; + default: + return []; + } + } + + + @endsection diff --git a/resources/views/Admin/pages/manage_cms/manage_cms.blade.php b/resources/views/Admin/pages/manage_cms/manage_cms.blade.php index 9dc2ab6..63b8326 100644 --- a/resources/views/Admin/pages/manage_cms/manage_cms.blade.php +++ b/resources/views/Admin/pages/manage_cms/manage_cms.blade.php @@ -30,18 +30,7 @@
-
- -
-
- -

Newsletter

-
-
-
-
+
@@ -88,6 +77,18 @@
+ diff --git a/resources/views/Admin/pages/manage_cms/manage_new/manage_news_add.blade.php b/resources/views/Admin/pages/manage_cms/manage_new/manage_news_add.blade.php index 243e64f..c3d4393 100644 --- a/resources/views/Admin/pages/manage_cms/manage_new/manage_news_add.blade.php +++ b/resources/views/Admin/pages/manage_cms/manage_new/manage_news_add.blade.php @@ -28,7 +28,7 @@
- +
Add News & Articles
diff --git a/routes/restaurant_api.php b/routes/restaurant_api.php new file mode 100644 index 0000000..a640150 --- /dev/null +++ b/routes/restaurant_api.php @@ -0,0 +1,54 @@ +group(function () { + // Define your routes here + Route::get('/v1/list-restaurant', [RestAuthApiController::class, 'viewresyaurant']); + Route::post('/v1/rest-register', [RestAuthApiController::class, 'restRegister']); + Route::post('/v1/rest-login', [RestAuthApiController::class, 'login']); + Route::post('/v1/rest-forgot-password', [RestAuthApiController::class, 'restForgotPassword']); + Route::post('/v1/rest-verify-otp', [RestAuthApiController::class, 'restVerifyOTP']); + Route::post('/v1/rest-change-password', [RestAuthApiController::class, 'restChangePassword']); + Route::post('/v1/rest-resend-otp', [RestAuthApiController::class, 'restResendOtp']); + + // Route::group(['middleware' => ['restaurant.jwt.verify']], function () { + // //*******************************************************Restaurant profile******************************************************** + // Route::get('/v1/fetch-restaurant-profile', [RestaurantControllerApi::class, 'getRestProfileDetail']); + // Route::post('/v1/update-restaurant-profile', [RestaurantControllerApi::class, 'updateRestProfileDetail']); + // Route::post('/v1/update-restaurant-detail', [RestaurantControllerApi::class, 'updateRestaurantDetail']); + // Route::post('/v1/reset-restaurant-password', [RestaurantControllerApi::class, 'resetRestPassword']); + // Route::post('/v1/restaurant-logout', [RestaurantControllerApi::class, 'restaurantLogout']); + // Route::post('/v1/restaurant-delete_account', [RestaurantControllerApi::class, 'restDeleteAccount']); + + + + + // //*******************************************************Redeemption Data******************************************************** + + // Route::get('/v1/fetch-redeem-data', [RedeemControllerApi::class, 'getRedemedData']); + // Route::post('/v1/undo-redemption', [RedeemControllerApi::class, 'undoRedemption']); + // Route::post('/v1/search-Redemption-data', [RedeemControllerApi::class, 'searchRedemption']); + + // //*******************************************************CMS******************************************************** + + // Route::get('/v1/list-of-restaurant-faqs', [RestCMSController::class, 'RestGetFaq']); + // Route::get('/v1/list-of-restaurant-about-us', [RestCMSController::class, 'RestAboutUs']); + // Route::get('/v1/list-of-restaurant-privacy-policy', [RestCMSController::class, 'RestPrivacyPolicy']); + // Route::get('/v1/list-of-restaurant-news-articles', [RestCMSController::class, 'RestNewsArticles']); + // Route::post('/v1/restaurant-contact-us', [RestCMSController::class, 'RestContactUs']); + + + // //*******************************************************notification******************************************************** + // Route::get('/v1/get-notification', [RestNotificationController::class, 'getRestNotificationApi']); + // Route::post('/v1/send-notification', [RestNotificationController::class, 'sendRestNotificationApi']); + // Route::post('/v1/alert-notification', [RestNotificationController::class, 'sendAlertNotificationApi']); + // }); +}); diff --git a/routes/web.php b/routes/web.php index 8f6c9d5..320bffb 100644 --- a/routes/web.php +++ b/routes/web.php @@ -35,7 +35,8 @@ Route::get('/logout', [LoginController::class, 'logout'])->name('logout'); Route::group(['middleware' => ['checkStatus']], function () { -Route::get('/dashboard', [DashboardController ::class, 'index'])->name('dashboard'); +// Route::get('/dashboard', [DashboardController ::class, 'index'])->name('dashboard'); +Route::get('/dashboard', [DashboardController::class, 'showDashboard'])->name('dashboard'); Route::get('/profile', [ManageProfileController ::class, 'index'])->name('profile');