|
|
@@ -1,17 +1,20 @@
|
|
|
<?php
|
|
|
|
|
|
namespace App\Http\Livewire;
|
|
|
+
|
|
|
use Livewire\Component;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use App\Http\Middleware\TenantMiddleware;
|
|
|
|
|
|
class PaymentMethod extends Component
|
|
|
{
|
|
|
- public $records, $name, $enabled, $money, $type, $corrispettivo_fiscale, $dataId, $bank_id, $update = false, $add = false;
|
|
|
+ public $records, $name, $enabled, $money, $type, $corrispettivo_fiscale, $dataId, $origin_id, $destination_id, $update = false, $add = false;
|
|
|
public $paymentMethods = [];
|
|
|
- public $banks = array();
|
|
|
public $showHidden = false;
|
|
|
|
|
|
+ public $origins = [];
|
|
|
+ public $destinations = [];
|
|
|
+
|
|
|
protected $rules = [
|
|
|
'name' => 'required'
|
|
|
];
|
|
|
@@ -20,7 +23,7 @@ class PaymentMethod extends Component
|
|
|
'name.required' => 'Il nome è obbligatorio'
|
|
|
];
|
|
|
|
|
|
- public $sortField ='name';
|
|
|
+ public $sortField = 'name';
|
|
|
public $sortAsc = true;
|
|
|
|
|
|
public function boot()
|
|
|
@@ -30,7 +33,7 @@ class PaymentMethod extends Component
|
|
|
|
|
|
public function sortBy($field)
|
|
|
{
|
|
|
- if($this->sortField === $field) {
|
|
|
+ if ($this->sortField === $field) {
|
|
|
$this->sortAsc = ! $this->sortAsc;
|
|
|
} else {
|
|
|
$this->sortAsc = true;
|
|
|
@@ -39,7 +42,8 @@ class PaymentMethod extends Component
|
|
|
$this->sortField = $field;
|
|
|
}
|
|
|
|
|
|
- public function resetFields(){
|
|
|
+ public function resetFields()
|
|
|
+ {
|
|
|
$this->name = '';
|
|
|
$this->money = false;
|
|
|
$this->type = 'ALL';
|
|
|
@@ -48,11 +52,13 @@ class PaymentMethod extends Component
|
|
|
$this->emit('load-data-table');
|
|
|
}
|
|
|
|
|
|
- public function mount(){
|
|
|
- if(Auth::user()->level != env('LEVEL_ADMIN', 0))
|
|
|
+ public function mount()
|
|
|
+ {
|
|
|
+ if (Auth::user()->level != env('LEVEL_ADMIN', 0))
|
|
|
return redirect()->to('/dashboard');
|
|
|
|
|
|
- $this->banks = \App\Models\Bank::select('id', 'name')->get();
|
|
|
+ $this->origins = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', ['OUT', 'ALL'])->get();
|
|
|
+ $this->destinations = \App\Models\Bank::select('id', 'name')->where('enabled', true)->whereIn('visibility', ['IN', 'ALL'])->get();
|
|
|
|
|
|
$this->loadPaymentMethodOptions();
|
|
|
}
|
|
|
@@ -61,7 +67,7 @@ class PaymentMethod extends Component
|
|
|
{
|
|
|
try {
|
|
|
\App\Models\PaymentMethod::whereId($id)->update(['hidden' => true]);
|
|
|
- session()->flash('success', 'Metodo pagamento nascosto');
|
|
|
+ session()->flash('success', 'Metodo di pagamento nascosto');
|
|
|
} catch (\Exception $ex) {
|
|
|
session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
}
|
|
|
@@ -71,7 +77,7 @@ class PaymentMethod extends Component
|
|
|
{
|
|
|
try {
|
|
|
\App\Models\PaymentMethod::whereId($id)->update(['hidden' => false]);
|
|
|
- session()->flash('success', 'Metodo pagamento ripristinato');
|
|
|
+ session()->flash('success', 'Metodo di pagamento ripristinato');
|
|
|
} catch (\Exception $ex) {
|
|
|
session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
}
|
|
|
@@ -92,9 +98,12 @@ class PaymentMethod extends Component
|
|
|
})->get();
|
|
|
}
|
|
|
|
|
|
- foreach($this->records as $r) {
|
|
|
- $r->bank = $r->bank ? $r->bank->name : '';
|
|
|
- }
|
|
|
+ // foreach ($this->records as $r) {
|
|
|
+
|
|
|
+ // dd($r, $r->origin);
|
|
|
+ // $r->origin = $r->origin ? $r->origin->name : '';
|
|
|
+ // $r->destination = $r->destination ? $r->destination->name : '';
|
|
|
+ // }
|
|
|
|
|
|
return view('livewire.payment_method');
|
|
|
}
|
|
|
@@ -112,38 +121,41 @@ class PaymentMethod extends Component
|
|
|
try {
|
|
|
\App\Models\PaymentMethod::create([
|
|
|
'name' => $this->name,
|
|
|
- 'bank_id' => $this->bank_id,
|
|
|
+ 'origin_id' => $this->origin_id != "" ? $this->origin_id : null,
|
|
|
+ 'destination_id' => $this->destination_id != "" ? $this->destination_id : null,
|
|
|
'money' => $this->money,
|
|
|
'type' => $this->type,
|
|
|
'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
|
|
|
'enabled' => $this->enabled
|
|
|
]);
|
|
|
- session()->flash('success','Metodo pagamento creato');
|
|
|
+ session()->flash('success', 'Metodo di pagamento creato');
|
|
|
$this->resetFields();
|
|
|
$this->add = false;
|
|
|
} catch (\Exception $ex) {
|
|
|
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
|
|
|
+ session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public function edit($id){
|
|
|
+ public function edit($id)
|
|
|
+ {
|
|
|
try {
|
|
|
$payment_method = \App\Models\PaymentMethod::findOrFail($id);
|
|
|
- if( !$payment_method) {
|
|
|
- session()->flash('error','Metodo pagamento non trovato');
|
|
|
+ if (!$payment_method) {
|
|
|
+ session()->flash('error', 'Metodo di pagamento non trovato');
|
|
|
} else {
|
|
|
$this->name = $payment_method->name;
|
|
|
$this->enabled = $payment_method->enabled;
|
|
|
$this->corrispettivo_fiscale = $payment_method->corrispettivo_fiscale;
|
|
|
$this->money = $payment_method->money;
|
|
|
$this->type = $payment_method->type;
|
|
|
- $this->bank_id = $payment_method->bank_id;
|
|
|
+ $this->origin_id = $payment_method->origin_id;
|
|
|
+ $this->destination_id = $payment_method->destination_id;
|
|
|
$this->dataId = $payment_method->id;
|
|
|
$this->update = true;
|
|
|
$this->add = false;
|
|
|
}
|
|
|
} catch (\Exception $ex) {
|
|
|
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
|
|
|
+ session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -153,17 +165,18 @@ class PaymentMethod extends Component
|
|
|
try {
|
|
|
\App\Models\PaymentMethod::whereId($this->dataId)->update([
|
|
|
'name' => $this->name,
|
|
|
- 'bank_id' => $this->bank_id,
|
|
|
+ 'origin_id' => $this->origin_id != "" ? $this->origin_id : null,
|
|
|
+ 'destination_id' => $this->destination_id != "" ? $this->destination_id : null,
|
|
|
'money' => $this->money,
|
|
|
'type' => $this->type,
|
|
|
'corrispettivo_fiscale' => $this->corrispettivo_fiscale,
|
|
|
'enabled' => $this->enabled
|
|
|
]);
|
|
|
- session()->flash('success','Metodo pagamento aggiornato');
|
|
|
+ session()->flash('success', 'Metodo di pagamento aggiornato');
|
|
|
$this->resetFields();
|
|
|
$this->update = false;
|
|
|
} catch (\Exception $ex) {
|
|
|
- session()->flash('error','Errore (' . $ex->getMessage() . ')');
|
|
|
+ session()->flash('error', 'Errore (' . $ex->getMessage() . ')');
|
|
|
}
|
|
|
}
|
|
|
|