diff --git a/app/Console/Commands/ReinstateRestaurant.php b/app/Console/Commands/ReinstateRestaurant.php index 4a65f03..bf676c4 100644 --- a/app/Console/Commands/ReinstateRestaurant.php +++ b/app/Console/Commands/ReinstateRestaurant.php @@ -41,10 +41,10 @@ class ReinstateRestaurant extends Command foreach ($recordsToUpdate as $record) { $managerestaurant = ManageRestaurant::where('id', $record->manage_restaurants_xid)->first(); $restTime = RestaurantTimeInterval::select('time_hours')->where('manage_restaurants_xid', $managerestaurant->id)->first(); - $stateTime = TimeInterval::select('time_hours')->where('manage_state_xid', $managerestaurant->state_xid)->first(); + // $stateTime = TimeInterval::select('time_hours')->where('manage_state_xid', $managerestaurant->state_xid)->first(); $restTimeHours = $restTime ? $restTime->time_hours : 0; - $stateTimeHours = $stateTime ? $stateTime->time_hours : 0; + // $stateTimeHours = $stateTime ? $stateTime->time_hours : 0; $customerData = IamPrincipal::where('id', $record->iam_principal_xid) ->where('notification_status', 1) @@ -55,12 +55,12 @@ class ReinstateRestaurant extends Command $redeemDate = Carbon::parse($record->redeem_date); // Calculate the state time plus record time - $stateHourPlusTimeOfRecord = $redeemDate->copy()->addHours($stateTimeHours); - Log::info('state time' . $stateHourPlusTimeOfRecord); + // $stateHourPlusTimeOfRecord = $redeemDate->copy()->addHours($stateTimeHours); + // Log::info('state time' . $stateHourPlusTimeOfRecord); $currentTime = Carbon::now(); - if ($currentTime > $stateHourPlusTimeOfRecord) { + // if ($currentTime > $stateHourPlusTimeOfRecord) { // Only proceed if state time condition is met $restHourPlusTimeOfRecord = $redeemDate->copy()->addHours($restTimeHours); Log::info('Restaurant time ' . $restHourPlusTimeOfRecord); @@ -92,7 +92,7 @@ class ReinstateRestaurant extends Command onesignalhelper::StoreNotificationDetails($customerData->id, $content_type, $title, $restImage); } - } + // } } } diff --git a/app/Exports/DashboardExportUser.php b/app/Exports/DashboardExportUser.php index 0d693e4..0969c94 100644 --- a/app/Exports/DashboardExportUser.php +++ b/app/Exports/DashboardExportUser.php @@ -21,10 +21,15 @@ class DashboardExportUser implements FromCollection, WithHeadings $mappedTransactions = collect($this->recentTransactions)->map(function ($transaction) use (&$serial) { return [ 'Sr No.' => $serial++, // Increment serial number - 'Name' => $transaction['subscription']['first_name'] . ' ' . $transaction['subscription']['last_name'], + 'Full Name' => $transaction['subscription']['first_name'] . ' ' . $transaction['subscription']['last_name'], 'Customer Id' => $transaction['subscription']['id'], - 'Amount' => $transaction['amount'], - 'Payment Details' => $transaction['stripe_customer_id'], // Adjust as needed + 'Amount' => '$ ' . $transaction['amount'], + 'Subscription ID' => $transaction['subscription_id'], + 'Stripe Customer Id' => $transaction['stripe_customer_id'], + 'Subscription Status' => $transaction['subscription_status'], + 'Current Start Period' => $transaction['current_period_start'], + 'Current End Period' => $transaction['current_period_end'], + 'Next Period Date' => $transaction['next_payment_date'], ]; }); @@ -35,10 +40,15 @@ class DashboardExportUser implements FromCollection, WithHeadings { return [ 'Sr No.', - 'Name', + 'Full Name', 'Customer Id', 'Amount', - 'Payment Details', + 'Subscription ID', + 'Stripe Customer Id', + 'Subscription Status', + 'Current Start Period', + 'Current End Period', + 'Next Period Date', ]; } } diff --git a/app/Exports/DashboardSelectedExportUser.php b/app/Exports/DashboardSelectedExportUser.php index 22587b0..3b2d7f2 100644 --- a/app/Exports/DashboardSelectedExportUser.php +++ b/app/Exports/DashboardSelectedExportUser.php @@ -27,13 +27,17 @@ class DashboardSelectedExportUser implements FromCollection, WithHeadings $mappedTransactions = collect($selectedTransactions)->map(function ($transaction) use (&$serial) { return [ 'Sr No.' => $serial++, // Increment serial number - 'Name' => $transaction['subscription']['first_name'] . ' ' . $transaction['subscription']['last_name'], + 'Full Name' => $transaction['subscription']['first_name'] . ' ' . $transaction['subscription']['last_name'], 'Customer Id' => $transaction['subscription']['id'], - 'Amount' => $transaction['amount'], - 'Payment Details' => $transaction['stripe_customer_id'], // Adjust as needed - - ]; + 'Amount' => '$ ' . $transaction['amount'], + 'Subscription ID' => $transaction['subscription_id'], + 'Stripe Customer Id' => $transaction['stripe_customer_id'], + 'Subscription Status' => $transaction['subscription_status'], + 'Current Start Period' => $transaction['current_period_start'], + 'Current End Period' => $transaction['current_period_end'], + 'Next Period Date' => $transaction['next_payment_date'], + ]; }); return new Collection($mappedTransactions); @@ -43,10 +47,15 @@ class DashboardSelectedExportUser implements FromCollection, WithHeadings { return [ 'Sr No.', - 'Name', + 'Full Name', 'Customer Id', 'Amount', - 'Payment Details', + 'Subscription ID', + 'Stripe Customer Id', + 'Subscription Status', + 'Current Start Period', + 'Current End Period', + 'Next Period Date', ]; } } diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index d7a89be..c21700d 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -134,7 +134,7 @@ class DashboardController extends Controller $restaurantCount = Subscriptions::where('is_active', 1)->count(); $dateTime = now(); $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); - $recent_transaction = Subscriptions::where('next_payment_date', '>=', $formattedDateTime)->with('subscription')->get()->toArray(); + $recent_transaction = Subscriptions::where('next_payment_date', '>=', $formattedDateTime)->with('subscription')->orderBy('id', 'desc')->get()->toArray(); return view('Admin.dashboard', compact( @@ -162,7 +162,7 @@ class DashboardController extends Controller Created at : 08 July 2024 Use : To Get Excel. */ - + public function exportRecentTransactions(Request $request) { diff --git a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php index e646c4b..79a7bca 100644 --- a/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php +++ b/app/Services/APIs/CustomerAPIs/RestaurantApiServices.php @@ -126,19 +126,17 @@ class RestaurantApiServices ->where('is_redeem', "1") ->first(); - $Timeinterval = TimeInterval::where('manage_state_xid', $rest->state_xid)->first(); + // $Timeinterval = TimeInterval::where('manage_state_xid', $rest->state_xid)->first(); $restTime = RestaurantTimeInterval::where('manage_restaurants_xid', $rest->id)->first(); - $timeIntervalHours = $Timeinterval->time_hours; + // $timeIntervalHours = $Timeinterval->time_hours; $restTimeHours = $restTime->time_hours; - $greaterTime = max($timeIntervalHours, $restTimeHours); - - + // $greaterTime = max($timeIntervalHours, $restTimeHours); if ($redeem) { $rest->is_Redeemed = true; - $rest->redeem_date = \Carbon\Carbon::parse($redeem->redeem_date)->addHours($greaterTime)->toDateTimeString(); + $rest->redeem_date = \Carbon\Carbon::parse($redeem->redeem_date)->addHours($restTimeHours)->toDateTimeString(); } else { $rest->is_Redeemed = false; $rest->redeem_date = null; @@ -283,6 +281,7 @@ class RestaurantApiServices // Get the last redeem time $lastRedeem = RedeemRestaurant::where('iam_principal_xid', $customerIamId) + ->where('state_xid', $restaurant->state_xid) ->where('is_redeem', 1) ->orderBy('redeem_date', 'desc') ->first(); @@ -299,20 +298,26 @@ class RestaurantApiServices $lastRedeemTime = Carbon::parse($lastRedeem->redeem_date); $currentTime = Carbon::now(); - // Calculate the allowed redeem time based on rest and state time intervals - $allowedRedeemTime = $lastRedeemTime->copy()->addHours($stateTimeHours); + $stateAllowedRedeemTime = $lastRedeemTime->copy()->addHours($stateTimeHours); + $restAllowedRedeemTime = $lastRedeemTime->copy()->addHours($restTimeHours); - if ($currentTime < $allowedRedeemTime) { - return jsonResponseWithErrorMessageApi(__('auth.redeem_not_allowed_yet'), 404); + if ($currentTime < $stateAllowedRedeemTime) { + $remainingTime = $currentTime->diff($stateAllowedRedeemTime); + $hours = $remainingTime->h; + $minutes = $remainingTime->i; + return jsonResponseWithErrorMessageApi(__('auth.redeem_not_allowed_yet') . " {$hours} hours and {$minutes} minutes remaining.", 404); } - $allowedRedeemTime = $lastRedeemTime->copy()->addHours($restTimeHours); - - if ($currentTime < $allowedRedeemTime) { - return jsonResponseWithErrorMessageApi(__('auth.redeem_not_allowed_yet'), 404); + if ($currentTime < $restAllowedRedeemTime) { + $remainingTime = $currentTime->diff($restAllowedRedeemTime); + $hours = $remainingTime->h; + $minutes = $remainingTime->i; + return jsonResponseWithErrorMessageApi(__('auth.redeem_not_allowed_yet') . " {$hours} hours and {$minutes} minutes remaining.", 404); } } + + // Create a new redeem entry if it doesn't exist $redeemRestaurant = new RedeemRestaurant(); $redeemRestaurant->iam_principal_xid = $customerIamId;