فهرست منبع

Modifiche logica creazione rate

Luca Parisio 9 ماه پیش
والد
کامیت
015725985d

+ 9 - 1
app/Http/Livewire/CourseSubscription.php

@@ -6,7 +6,7 @@ use Livewire\Component;
 
 class CourseSubscription extends Component
 {
-    public $records, $name, $months, $enabled, $dataId, $update = false, $add = false;
+    public $records, $name, $months, $month_day, $when_start, $enabled, $dataId, $update = false, $add = false;
 
     protected $rules = [
         'name' => 'required'
@@ -34,6 +34,8 @@ class CourseSubscription extends Component
     public function resetFields(){
         $this->name = '';
         $this->months = 0;
+        $this->month_day = 0;
+        $this->when_start = '';
         $this->enabled = true;
         $this->emit('load-data-table');
     }
@@ -58,6 +60,8 @@ class CourseSubscription extends Component
             \App\Models\CourseSubscription::create([
                 'name' => $this->name,
                 'months' => $this->months,
+                'month_day' => $this->month_day,
+                'when_start' => $this->when_start,
                 'enabled' => $this->enabled
             ]);
             session()->flash('success','Dato creato');
@@ -76,6 +80,8 @@ class CourseSubscription extends Component
             } else {
                 $this->name = $course_subscription->name;
                 $this->months = $course_subscription->months;
+                $this->month_day = $course_subscription->month_day;
+                $this->when_start = $course_subscription->when_start;
                 $this->enabled = $course_subscription->enabled;
                 $this->dataId = $course_subscription->id;
                 $this->update = true;
@@ -93,6 +99,8 @@ class CourseSubscription extends Component
             \App\Models\CourseSubscription::whereId($this->dataId)->update([
                 'name' => $this->name,
                 'months' => $this->months,
+                'month_day' => $this->month_day,
+                'when_start' => $this->when_start,
                 'enabled' => $this->enabled
             ]);
             session()->flash('success','Dato aggiornato');

+ 17 - 0
app/Http/Livewire/Member.php

@@ -1565,6 +1565,23 @@ class Member extends Component
             $rate->is_subscription = true;
             $rate->save();
 
+            // Se la data inizio pagamenti è "inizio corso" allora prendo quella come start date
+            if ($r->when_start == 'COURSE')
+                $start = $c->date_from;
+
+            // 
+            $month_day = $r->month_day;
+            if ($month_day > 0)
+            {              
+                if ($month_day >= 29)  
+                    $start = date("Y-m-t", strtotime($start));
+                else
+                    $start = date('Y-m-d', strtotime('+' . ($month_day - 1) . ' days', strtotime('first day of ' . ((int)date('j', strtotime($start)) < $month_day ? 'this' : 'next' ) . ' month', strtotime($start))));
+            }
+
+            if ($r->months > 1)
+                $start = date('Y-m-' . ($month_day >= 29 ? 't' : 'd'), strtotime("+" . ($r->months - 1) . " months", strtotime($start)));
+
             $go = true;
             while ($go) {
 

+ 34 - 0
database/migrations/2025_04_16_1750000_add_fields_to_course_subscriptions_table.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('course_subscriptions', function (Blueprint $table) {
+            $table->integer('month_day')->default(1);
+            $table->enum('when_start', ['COURSE', 'MEMBER', 'CUSTOM']);
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('course_subscriptions', function (Blueprint $table) {
+            $table->dropColumn('month_day');
+            $table->dropColumn('when_start');
+        });
+    }
+};

+ 22 - 1
resources/views/livewire/course_subscription.blade.php

@@ -84,7 +84,28 @@
                                     </select>
                                 </div>
                             </div>
-                            <div class="col">
+                            <div class="col-6 mt-4">
+                                <div class="form--item">
+                                    <label for="month_day" class="form-label">Giorno del mese</label>
+                                    <select class="form-control" id="month_day" wire:model="month_day">
+                                        <option value=""></option>
+                                        @for($i=1;$i<=31;$i++)
+                                            <option value="{{$i}}">{{$i}} {{$i == 31 ? ' (fine mese)' : ''}}</option>
+                                        @endfor
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="col-6 mt-4">
+                                <div class="form--item">
+                                    <label for="when_start" class="form-label">Data inizio conteggio</label>
+                                    <select class="form-control" id="when_start" wire:model="when_start">
+                                        <option value=""></option>
+                                        <option value="COURSE">Data inizio corso</option>
+                                        <option value="MEMBER">Data iscrizione corso</option>
+                                    </select>
+                                </div>
+                            </div>
+                            <div class="col mt-4">
                                 <div class="form--item">
                                     <label for="enabled" class="form-label">Abilitato</label>
                                     <input class="form-check-input form-control" style="width:22px; height:22px;" type="checkbox" id="enabled" wire:model="enabled">

+ 2 - 2
resources/views/livewire/rate.blade.php

@@ -78,10 +78,10 @@
         <div class="compare--chart_wrapper d-none"></div>
 
         <div class="row">
-            <div class="col-6">
+            <div class="col-10">
                 <h3 class="mt-4">{{$detail}}</h3><br>
             </div>
-            <div class="col-6 right" style="margin-top:20px;text-align:right">
+            <div class="col-2 right" style="margin-top:20px;text-align:right">
                 <button id="btRemove" style="display:none;" class="btn--ui" >ELIMINA SELEZIONATI</button>
             </div>
         </div>