|
|
@@ -32,6 +32,9 @@ class Course extends Component
|
|
|
|
|
|
public $selectedYear = '';
|
|
|
|
|
|
+ public $msgPrices = '';
|
|
|
+ public $msgWhen = '';
|
|
|
+
|
|
|
public $course_types = [];
|
|
|
public $course_durations = [];
|
|
|
public $course_frequencies = [];
|
|
|
@@ -51,16 +54,23 @@ class Course extends Component
|
|
|
|
|
|
protected $rules = [
|
|
|
'name' => 'required',
|
|
|
- /*'course_type_id' => 'required',
|
|
|
- 'course_duration_id' => 'required',
|
|
|
'course_frequency_id' => 'required',
|
|
|
'course_level_id' => 'required',
|
|
|
+ 'date_from' => 'required',
|
|
|
+ 'date_to' => 'required',
|
|
|
+ 'year' => 'required',
|
|
|
+ 'subscription_price' => 'required|min:0|not_in:0',
|
|
|
+ /*'course_type_id' => 'required',
|
|
|
+ 'course_duration_id' => 'required',
|
|
|
+
|
|
|
'causal_id' => 'required',
|
|
|
'sub_causal_id' => 'required',*/
|
|
|
];
|
|
|
|
|
|
protected $messages = [
|
|
|
'name.required' => 'Il nome è obbligatorio',
|
|
|
+ 'subscription_price.required' => 'Deve essere maggionre di zero',
|
|
|
+ 'subscription_price.not_in' => 'Deve essere maggionre di zero',
|
|
|
/*'causal_id' => 'Campo obbligatorio',
|
|
|
'sub_causal_id' => 'Campo obbligatorio',*/
|
|
|
];
|
|
|
@@ -77,7 +87,7 @@ class Course extends Component
|
|
|
$this->sub_causal_id = null;
|
|
|
$this->max_members = 0;
|
|
|
$this->instructor_id = null;
|
|
|
- $this->year = date("Y");
|
|
|
+ $this->year = null;
|
|
|
$this->price = 0;
|
|
|
$this->subscription_price = 0;
|
|
|
$this->date_from = null;
|
|
|
@@ -172,88 +182,102 @@ class Course extends Component
|
|
|
{
|
|
|
$this->validate();
|
|
|
try {
|
|
|
- $course = new \App\Models\Course();
|
|
|
-
|
|
|
- $course->name = $this->name;
|
|
|
- $course->parent_id = $this->parent_id;
|
|
|
- $course->course_type_id = $this->course_type_id;
|
|
|
- $course->course_duration_id = $this->course_duration_id;
|
|
|
- $course->course_frequency_id = $this->course_frequency_id;
|
|
|
- $course->course_level_id = $this->course_level_id;
|
|
|
- $course->date_from = $this->date_from;
|
|
|
- $course->date_to = $this->date_to;
|
|
|
- $course->category_id = $this->category_id;
|
|
|
- //$course->causal_id = $this->causal_id;
|
|
|
- //$course->sub_causal_id = $this->sub_causal_id;
|
|
|
- $course->max_members = $this->max_members;
|
|
|
- $course->instructor_id = $this->instructor_id;
|
|
|
- $course->year = $this->year;
|
|
|
- $course->price = currencyToDouble($this->price);
|
|
|
- $course->subscription_price = currencyToDouble($this->subscription_price);
|
|
|
- $course->months = json_encode($this->months);
|
|
|
- $course->type = $this->type;
|
|
|
- $course->when = json_encode($this->when);
|
|
|
- $course->prices = json_encode($this->prices);
|
|
|
- $course->enabled = $this->enabled;
|
|
|
- $course->save();
|
|
|
-
|
|
|
- $lev = '';
|
|
|
- if ($this->course_level_id > 0)
|
|
|
- $lev = \App\Models\CourseLevel::findOrFail($this->course_level_id)->name;
|
|
|
-
|
|
|
- $freq = '';
|
|
|
- if ($this->course_frequency_id > 0)
|
|
|
- $freq = \App\Models\CourseFrequency::findOrFail($this->course_frequency_id)->name;
|
|
|
-
|
|
|
- $mFrom = getMonthName(date("n", strtotime($this->date_from)));
|
|
|
- $mTo = getMonthName(date("n", strtotime($this->date_to)));
|
|
|
- // Creo le causali di pagamento
|
|
|
- //$causal = "PAGAMENTO CORSO [nome corso]-LIVELLO-FREQUENZA-ANNO-[tipo abbonamento]-[mese inizio]/[mese fine]
|
|
|
-
|
|
|
- $causal = "PAGAMENTO CORSO " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
|
|
|
- $cp = \App\Models\Causal::where('name', $causal)->first();
|
|
|
- if (!$cp)
|
|
|
- {
|
|
|
- $cp = new \App\Models\Causal();
|
|
|
- $cp->name = $causal;
|
|
|
- $cp->type = "IN";
|
|
|
- $cp->parent_id = null;
|
|
|
- $cp->money = false;
|
|
|
- $cp->corrispettivo_fiscale = false;
|
|
|
- $cp->no_receipt = false;
|
|
|
- $cp->user_status = false;
|
|
|
- $cp->no_first = false;
|
|
|
- $cp->no_records = false;
|
|
|
- $cp->enabled = true;
|
|
|
- $cp->save();
|
|
|
- }
|
|
|
- $course->causal_id = $cp->id;
|
|
|
|
|
|
- $causal = "PAGAMENTO ISCRIZIONE " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
|
|
|
- $ci = \App\Models\Causal::where('name', $causal)->first();
|
|
|
- if (!$ci)
|
|
|
+ $this->msgPrices = '';
|
|
|
+ $this->msgWhen = '';
|
|
|
+
|
|
|
+ if ($this->when[0]['from'] == '')
|
|
|
+ $this->msgWhen = 'Devi inserire almeno un giorno';
|
|
|
+
|
|
|
+ if ($this->prices[0]['course_subscription_id'] == null)
|
|
|
+ $this->msgPrices = 'Devi inserire almeno un prezzo';
|
|
|
+
|
|
|
+ if ($this->msgPrices == '' && $this->msgWhen == '')
|
|
|
{
|
|
|
- $ci = new \App\Models\Causal();
|
|
|
- $ci->name = $causal;
|
|
|
- $ci->type = "IN";
|
|
|
- $ci->parent_id = null;
|
|
|
- $ci->money = false;
|
|
|
- $ci->corrispettivo_fiscale = false;
|
|
|
- $ci->no_receipt = false;
|
|
|
- $ci->user_status = false;
|
|
|
- $ci->no_first = false;
|
|
|
- $ci->no_records = false;
|
|
|
- $ci->enabled = true;
|
|
|
- $ci->save();
|
|
|
- }
|
|
|
- $course->sub_causal_id = $ci->id;
|
|
|
|
|
|
- $course->save();
|
|
|
-
|
|
|
- session()->flash('success','Corso creato');
|
|
|
- $this->resetFields();
|
|
|
- $this->add = false;
|
|
|
- $this->emit('setEdit', false);
|
|
|
+ $course = new \App\Models\Course();
|
|
|
+
|
|
|
+ $course->name = $this->name;
|
|
|
+ $course->parent_id = $this->parent_id;
|
|
|
+ $course->course_type_id = $this->course_type_id;
|
|
|
+ $course->course_duration_id = $this->course_duration_id;
|
|
|
+ $course->course_frequency_id = $this->course_frequency_id;
|
|
|
+ $course->course_level_id = $this->course_level_id;
|
|
|
+ $course->date_from = $this->date_from;
|
|
|
+ $course->date_to = $this->date_to;
|
|
|
+ $course->category_id = $this->category_id;
|
|
|
+ //$course->causal_id = $this->causal_id;
|
|
|
+ //$course->sub_causal_id = $this->sub_causal_id;
|
|
|
+ $course->max_members = $this->max_members;
|
|
|
+ $course->instructor_id = $this->instructor_id;
|
|
|
+ $course->year = $this->year;
|
|
|
+ $course->price = currencyToDouble($this->price);
|
|
|
+ $course->subscription_price = currencyToDouble($this->subscription_price);
|
|
|
+ $course->months = json_encode($this->months);
|
|
|
+ $course->type = $this->type;
|
|
|
+ $course->when = json_encode($this->when);
|
|
|
+ $course->prices = json_encode($this->prices);
|
|
|
+ $course->enabled = $this->enabled;
|
|
|
+ $course->save();
|
|
|
+
|
|
|
+ $lev = '';
|
|
|
+ if ($this->course_level_id > 0)
|
|
|
+ $lev = \App\Models\CourseLevel::findOrFail($this->course_level_id)->name;
|
|
|
+
|
|
|
+ $freq = '';
|
|
|
+ if ($this->course_frequency_id > 0)
|
|
|
+ $freq = \App\Models\CourseFrequency::findOrFail($this->course_frequency_id)->name;
|
|
|
+
|
|
|
+ $mFrom = getMonthName(date("n", strtotime($this->date_from)));
|
|
|
+ $mTo = getMonthName(date("n", strtotime($this->date_to)));
|
|
|
+ // Creo le causali di pagamento
|
|
|
+ //$causal = "PAGAMENTO CORSO [nome corso]-LIVELLO-FREQUENZA-ANNO-[tipo abbonamento]-[mese inizio]/[mese fine]
|
|
|
+
|
|
|
+ $causal = "PAGAMENTO CORSO " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
|
|
|
+ $cp = \App\Models\Causal::where('name', $causal)->first();
|
|
|
+ if (!$cp)
|
|
|
+ {
|
|
|
+ $cp = new \App\Models\Causal();
|
|
|
+ $cp->name = $causal;
|
|
|
+ $cp->type = "IN";
|
|
|
+ $cp->parent_id = null;
|
|
|
+ $cp->money = false;
|
|
|
+ $cp->corrispettivo_fiscale = false;
|
|
|
+ $cp->no_receipt = false;
|
|
|
+ $cp->user_status = false;
|
|
|
+ $cp->no_first = false;
|
|
|
+ $cp->no_records = false;
|
|
|
+ $cp->enabled = true;
|
|
|
+ $cp->save();
|
|
|
+ }
|
|
|
+ $course->causal_id = $cp->id;
|
|
|
+
|
|
|
+ $causal = "PAGAMENTO ISCRIZIONE " . $this->name . " - " . $lev . " - " . $freq . " - " . $this->year . " - " . $mFrom . "/" . $mTo;
|
|
|
+ $ci = \App\Models\Causal::where('name', $causal)->first();
|
|
|
+ if (!$ci)
|
|
|
+ {
|
|
|
+ $ci = new \App\Models\Causal();
|
|
|
+ $ci->name = $causal;
|
|
|
+ $ci->type = "IN";
|
|
|
+ $ci->parent_id = null;
|
|
|
+ $ci->money = false;
|
|
|
+ $ci->corrispettivo_fiscale = false;
|
|
|
+ $ci->no_receipt = false;
|
|
|
+ $ci->user_status = false;
|
|
|
+ $ci->no_first = false;
|
|
|
+ $ci->no_records = false;
|
|
|
+ $ci->enabled = true;
|
|
|
+ $ci->save();
|
|
|
+ }
|
|
|
+ $course->sub_causal_id = $ci->id;
|
|
|
+
|
|
|
+ $course->save();
|
|
|
+
|
|
|
+ session()->flash('success','Corso creato');
|
|
|
+ $this->resetFields();
|
|
|
+ $this->add = false;
|
|
|
+ $this->emit('setEdit', false);
|
|
|
+ }
|
|
|
} catch (\Exception $ex) {
|
|
|
session()->flash('error','Errore (' . $ex->getMessage() . ')');
|
|
|
}
|