From 92ea99051c5ecc1a4dc29a61d1f6ace68bce021c Mon Sep 17 00:00:00 2001 From: Nurmuhammet Allanov Date: Sun, 24 Nov 2024 15:38:28 +0500 Subject: [PATCH] wip --- app/Helpers/helpers.php | 5 +- .../Actions/MakePaymentNovaVisaMaster.php | 48 ++++++++++++++----- 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/app/Helpers/helpers.php b/app/Helpers/helpers.php index 4f3f18a..d6a0616 100644 --- a/app/Helpers/helpers.php +++ b/app/Helpers/helpers.php @@ -212,11 +212,8 @@ function convertToOriginalFormat($apiPrice) function lastDayOfMonth($month, $year) { - // Create a DateTime object for the first day of the given month $date = new DateTime("$year-$month-01"); - // Modify the date to the last day of the same month $date->modify('last day of this month'); - // Return the formatted date - return $date->format('d'); + return $date; } diff --git a/app/Nova/Actions/MakePaymentNovaVisaMaster.php b/app/Nova/Actions/MakePaymentNovaVisaMaster.php index 0c997a3..6829a4e 100644 --- a/app/Nova/Actions/MakePaymentNovaVisaMaster.php +++ b/app/Nova/Actions/MakePaymentNovaVisaMaster.php @@ -70,17 +70,12 @@ class MakePaymentNovaVisaMaster extends Action ]); } - // if (lastDayOfMonth($today->format('m'), $today->format('Y'))) { - // return Action::modal('modal-response', [ - // 'title' => 'Bu gun aýyn sonky guni!', - // 'body' => 'Ayyn sonky guni toleg alynmayar.', - // ]); - // } - - // in sonky gun otduh gune dushse 6 gunem toleg gecmeli dal, 5 gecirmeli dal; - // in sonky gun 6 dushse gunem 5 gunem dushindim; - - + if ($this->canAcceptPayment($today)) { + return Action::modal('modal-response', [ + 'title' => 'Bu gun aýyn sonky guni!', + 'body' => 'Ayyn sonky guni toleg alynmayar.', + ]); + } if (! $resource->branch || ! $resource->branch->billing_visa_master_username) { return Action::modal('modal-response', [ @@ -260,4 +255,35 @@ class MakePaymentNovaVisaMaster extends Action 'usd_payment_amount' => $usd_payment, ]); } + + public function canAcceptPayment($today) + { + $year = $today->format('Y'); + $month = $today->format('m'); + $lastDay = lastDayOfMonth($year, $month); + + // Condition 1: Check if today is the last day of the month + if ($today->format('Y-m-d') === $lastDay->format('Y-m-d')) { + return false; + } + + // Determine the day of the week for the last day of the month + $lastDayOfWeek = $lastDay->format('l'); // e.g., 'Sunday', 'Saturday' + + // Condition 2: If the last day is Sunday, disallow Friday, Saturday, Sunday + if ($lastDayOfWeek === 'Sunday') { + $forbiddenDays = ['Friday', 'Saturday', 'Sunday']; + if (in_array($today->format('l'), $forbiddenDays)) { + return false; + } + } + + // Condition 3: If the last day is Saturday, disallow Friday + if ($lastDayOfWeek === 'Saturday' && $today->format('l') === 'Friday') { + return false; + } + + // If none of the conditions match, allow payment + return true; + } }