|
|
@@ -6,6 +6,8 @@ use Livewire\Component;
|
|
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
|
+use App\Models\MemberCourse;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
|
|
|
class CourseList extends Component
|
|
|
{
|
|
|
@@ -847,6 +849,120 @@ class CourseList extends Component
|
|
|
return redirect()->to('/in?new=1&memberId=' . $member_id . (sizeof($newMonths) > 0 ? '&causalId=' . $c->causal_id : '') . '&subCausalId=' . $c->sub_causal_id . '&createSubscription=' . ($subscription ? 1 : 0) . (sizeof($newMonths) > 0 ? '&months=' . implode("|", $newMonths) : '') . (sizeof($newMonths) > 0 ? '&price=' . $m->price : '') . '&subscription_price=' . $m->subscription_price . "&courseId=" . $id);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ public function suspendPayment($course_id, $month, $member_id, $id, $subscription)
|
|
|
+ {
|
|
|
+
|
|
|
+ $monthMap = [
|
|
|
+ 1 => 9, // September
|
|
|
+ 2 => 10, // October
|
|
|
+ 3 => 11, // November
|
|
|
+ 4 => 12, // December
|
|
|
+ 5 => 1, // January
|
|
|
+ 6 => 2, // February
|
|
|
+ 7 => 3, // March
|
|
|
+ 8 => 4, // April
|
|
|
+ 9 => 5, // May
|
|
|
+ 10 => 6, // June
|
|
|
+ 11 => 7, // July
|
|
|
+ 12 => 8 // August
|
|
|
+ ];
|
|
|
+
|
|
|
+ $dbMonth = isset($monthMap[$month]) ? $monthMap[$month] : $month;
|
|
|
+
|
|
|
+
|
|
|
+ $memberCourse = MemberCourse::where('id', $id)
|
|
|
+ ->where('member_id', $member_id)
|
|
|
+ ->where('course_id', $course_id)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+
|
|
|
+ if (!$memberCourse) {
|
|
|
+ return response()->json(['error' => 'Non Trovato'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $monthsData = json_decode($memberCourse->months, true);
|
|
|
+ if (!is_array($monthsData)) {
|
|
|
+ return response()->json(['error' => 'Invalid months data format'], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $monthUpdated = false;
|
|
|
+ foreach ($monthsData as &$monthData) {
|
|
|
+ if ($monthData['m'] == $dbMonth) {
|
|
|
+ $monthData['status'] = 2;
|
|
|
+ $monthUpdated = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$monthUpdated) {
|
|
|
+ return response()->json(['error' => 'Month not found in data'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $memberCourse->months = json_encode($monthsData);
|
|
|
+ $memberCourse->save();
|
|
|
+ session()->flash('success', 'Payment suspended successfully');
|
|
|
+ return redirect()->to('/course_list');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function resumePayment($course_id, $month, $member_id, $id, $subscription)
|
|
|
+ {
|
|
|
+ Log::info('resumePayment');
|
|
|
+ Log::info($course_id);
|
|
|
+ Log::info($month);
|
|
|
+ Log::info($member_id);
|
|
|
+ Log::info($id);
|
|
|
+
|
|
|
+ $monthMap = [
|
|
|
+ 1 => 9, // September
|
|
|
+ 2 => 10, // October
|
|
|
+ 3 => 11, // November
|
|
|
+ 4 => 12, // December
|
|
|
+ 5 => 1, // January
|
|
|
+ 6 => 2, // February
|
|
|
+ 7 => 3, // March
|
|
|
+ 8 => 4, // April
|
|
|
+ 9 => 5, // May
|
|
|
+ 10 => 6, // June
|
|
|
+ 11 => 7, // July
|
|
|
+ 12 => 8 // August
|
|
|
+ ];
|
|
|
+
|
|
|
+ $dbMonth = isset($monthMap[$month]) ? $monthMap[$month] : $month;
|
|
|
+
|
|
|
+
|
|
|
+ $memberCourse = MemberCourse::where('id', $id)
|
|
|
+ ->where('member_id', $member_id)
|
|
|
+ ->where('course_id', $course_id)
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ if (!$memberCourse) {
|
|
|
+ return response()->json(['error' => 'Non Trovato'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $monthsData = json_decode($memberCourse->months, true);
|
|
|
+ Log::info('data mese',$monthsData);
|
|
|
+ if (!is_array($monthsData)) {
|
|
|
+ return response()->json(['error' => 'Invalid months data format'], 400);
|
|
|
+ }
|
|
|
+
|
|
|
+ $monthUpdated = false;
|
|
|
+ foreach ($monthsData as &$monthData) {
|
|
|
+ if ($monthData['m'] == $dbMonth) {
|
|
|
+ $monthData['status'] = "";
|
|
|
+ $monthUpdated = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Log::info($monthUpdated);
|
|
|
+
|
|
|
+ if (!$monthUpdated) {
|
|
|
+ return response()->json(['error' => 'Month not found in data'], 404);
|
|
|
+ }
|
|
|
+
|
|
|
+ $memberCourse->months = json_encode($monthsData);
|
|
|
+ $memberCourse->save();
|
|
|
+ session()->flash('success', 'Payment resumed successfully');
|
|
|
+ return redirect()->to('/course_list');
|
|
|
+ }
|
|
|
/*
|
|
|
public function newPayment()
|
|
|
{
|