diff --git a/app/Http/Controllers/Admin/ManageCustomerController.php b/app/Http/Controllers/Admin/ManageCustomerController.php index 276748a..c90af54 100644 --- a/app/Http/Controllers/Admin/ManageCustomerController.php +++ b/app/Http/Controllers/Admin/ManageCustomerController.php @@ -15,6 +15,8 @@ use App\Exports\customer_export_selected; use App\Exports\CustomerExportSelected; use App\Models\ManageRestaurant; use App\Models\RedeemRestaurant; +use Illuminate\Support\Facades\Validator; +use Illuminate\Validation\Rule; use Barryvdh\DomPDF\PDF as DomPDFPDF; use Exception; use PDF; @@ -84,28 +86,56 @@ class ManageCustomerController extends Controller Created at : 28 May 2024 Use : To Update Customer Form. */ - public function update(Request $request) - { + public function update(Request $request) + { + // Validation rules + $rules = [ + 'email_address' => [ + 'required', + 'string', + 'email', + 'max:100', + Rule::unique('iam_principal')->where(function ($query) use ($request) { + return $query->where('principal_type_xid', 3) + ->whereNull('deleted_at') + ->where('id', '!=', $request->customer_id); + }), + ], + ]; - try { - DB::beginTransaction(); - $customer_data = IamPrincipal::where('id', $request->customer_id)->first(); - $customer_data->first_name = $request->input('name'); - $customer_data->last_name = $request->input('last_name'); + $messages = [ - $customer_data->phone_number = $request->input('phone'); - $customer_data->email_address = $request->input('email_id'); - $customer_data->save(); - DB::commit(); + 'email_address.required' => 'Enter email address', + 'email_address.email' => 'Please enter a valid email address', + 'email_address.unique' => 'This email is already registered', + ]; - return jsonResponseWithSuccessMessage(__('success.update_data')); - } catch (Exception $e) { - DB::rollBack(); - Log::error("updateCustomerNewsArticle Services Page Load Failed " . $e->getMessage()); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + $validator = Validator::make($request->all(), $rules, $messages); + + if ($validator->fails()) { + return response()->json(['errors' => $validator->errors()], 422); + } + + try { + DB::beginTransaction(); + + $customer_data = IamPrincipal::where('id', $request->customer_id)->first(); + $customer_data->first_name = $request->input('name'); + $customer_data->last_name = $request->input('last_name'); + $customer_data->phone_number = $request->input('phone'); + $customer_data->email_address = $request->input('email_address'); + $customer_data->save(); + + DB::commit(); + + return jsonResponseWithSuccessMessage(__('success.update_data')); + } catch (Exception $e) { + DB::rollBack(); + Log::error("updateCustomerNewsArticle Services Page Load Failed " . $e->getMessage()); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } } - } public function archive_customer() { diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index 621d7be..1bef563 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -113,6 +113,9 @@ class RestaurantApiServices ->where('restaurant_xid', $rest->id) ->exists(); $rest->is_favourite = $isFavourite; + + $isRedeem = RedeemRestaurant::where('iam_principal_xid',$customerIamId)->where('manage_restaurants_xid',$rest->id)->exists(); + $rest->is_Redeemed = $isRedeem; } if (!$rest) { return jsonResponseWithErrorMessage(__('auth.restaurant_data_not_found'), 404); diff --git a/public/assets/js/admin/manage_customer/edit.js b/public/assets/js/admin/manage_customer/edit.js index 5c0a3ec..525f950 100644 --- a/public/assets/js/admin/manage_customer/edit.js +++ b/public/assets/js/admin/manage_customer/edit.js @@ -17,7 +17,7 @@ $(document).on("click", "#customer_user_btn", function (e) { required: true, fullNameCharactersOnly: true }, - email_id: { + email_address: { required: true, email: true, }, @@ -34,7 +34,7 @@ $(document).on("click", "#customer_user_btn", function (e) { required: "Enter Passport Name", alphaCharactersOnly: "Please enter only alphabetical characters" }, - email_id: { + email_address: { required: "Enter email address", email: "Please enter a valid email address" }, @@ -66,14 +66,15 @@ $(document).on("click", "#customer_user_btn", function (e) { processData: false, contentType: false, success: function(result) { + console.log(result); if (result.status_code == 200) { - toastr.success('Customer Updated Sucessfully'); + toastr.success('Customer Updated Successfully'); setTimeout(function() { window.location.href = base_url + "/manage-customer"; }, 2000); } else { - toastr.error('Something Went Wrong'); + toastr.error(result.message); setTimeout(function() { window.location.href = base_url + "/manage-customer"; }, 2000); @@ -81,11 +82,29 @@ $(document).on("click", "#customer_user_btn", function (e) { $('#customer_user_btn').attr('disabled', false); $('#customer_user_btn').text('Submit'); }, - + error: function(xhr) { + console.log(xhr); + if (xhr.status === 422) { + var errors = xhr.responseJSON.errors; + for (var key in errors) { + if (errors.hasOwnProperty(key)) { + toastr.error(errors[key][0]); // Show the first error message for each field + } + } + } else { + toastr.error('Something Went Wrong'); + } + $('#customer_user_btn').attr('disabled', false); + $('#customer_user_btn').text('Submit'); + } }); + $('#customer_user_btn').attr('disabled', false); $('#customer_user_btn').text('Submit'); } }); -}); \ No newline at end of file +}); + + + diff --git a/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php b/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php index 1b4dc46..2e4dee3 100644 --- a/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php +++ b/resources/views/Admin/pages/manage_users/manage_customer/customer.blade.php @@ -89,7 +89,7 @@ Full Name User ID Email Id - Redeem restaurant + Redeemed Restaurant Date of birth Phone Number Location diff --git a/resources/views/Admin/pages/manage_users/manage_customer/customer_restaurants.blade.php b/resources/views/Admin/pages/manage_users/manage_customer/customer_restaurants.blade.php index 8dd301f..3373ed4 100644 --- a/resources/views/Admin/pages/manage_users/manage_customer/customer_restaurants.blade.php +++ b/resources/views/Admin/pages/manage_users/manage_customer/customer_restaurants.blade.php @@ -31,21 +31,28 @@ Sr no Restaurant Name Image - Redeem date + Redeem Date and Time - @foreach ($redeemDetails as $redeemDetail) + @if ($redeemDetails->isEmpty()) - {{ $loop->iteration }} - {{ $redeemDetail->restaurant->name }} - - {{ \Carbon\Carbon::parse($redeemDetail->created_at)->format('d/m/y') }} - + No data found - @endforeach + @else + @foreach ($redeemDetails as $redeemDetail) + + {{ $loop->iteration }} + {{ $redeemDetail->restaurant->name }} + + {{ \Carbon\Carbon::parse($redeemDetail->created_at)->format('d/m/y H:i:s') }} + + + @endforeach + @endif + diff --git a/resources/views/Admin/pages/manage_users/manage_customer/edit_customer.blade.php b/resources/views/Admin/pages/manage_users/manage_customer/edit_customer.blade.php index b38a989..f915b7b 100644 --- a/resources/views/Admin/pages/manage_users/manage_customer/edit_customer.blade.php +++ b/resources/views/Admin/pages/manage_users/manage_customer/edit_customer.blade.php @@ -1,7 +1,7 @@ @extends('Admin.layouts.master') @section('content') -@php +@php $currentPage = 'manage-patient'; @endphp
@@ -53,13 +53,13 @@
- +
-
+
@@ -69,7 +69,7 @@
- +
@@ -98,4 +98,4 @@ @section('section_script') -@endsection \ No newline at end of file +@endsection