1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Adminetic\Website\Http\Livewire\Admin\Payment; |
4
|
|
|
|
5
|
|
|
use Adminetic\Website\Models\Admin\Payment; |
6
|
|
|
use Illuminate\Support\Facades\Auth; |
7
|
|
|
use Livewire\Component; |
8
|
|
|
|
9
|
|
|
class PaymentPanel extends Component |
10
|
|
|
{ |
11
|
|
|
public $toggle_modal = false; |
12
|
|
|
|
13
|
|
|
public $model; |
14
|
|
|
public $type; |
15
|
|
|
|
16
|
|
|
public $amount; |
17
|
|
|
public $particular; |
18
|
|
|
|
19
|
|
|
public $payment_id; |
20
|
|
|
|
21
|
|
|
public function mount($model, $type) |
22
|
|
|
{ |
23
|
|
|
$this->model = $model; |
24
|
|
|
$this->type = $type; |
25
|
|
|
$this->particular = ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function updatedAmount() |
29
|
|
|
{ |
30
|
|
|
$this->particular = ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function store() |
34
|
|
|
{ |
35
|
|
|
$this->validate([ |
36
|
|
|
'amount' => 'required|numeric', |
37
|
|
|
]); |
38
|
|
|
|
39
|
|
|
$particular = $this->particular ?? ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id); |
40
|
|
|
|
41
|
|
|
$this->model->payments()->create([ |
42
|
|
|
'user_id' => Auth::user()->id, |
|
|
|
|
43
|
|
|
'type' => $this->type, |
44
|
|
|
'amount' => $this->amount, |
45
|
|
|
'particular' => $particular, |
46
|
|
|
]); |
47
|
|
|
$this->amount = null; |
48
|
|
|
|
49
|
|
|
$this->model->refresh(); |
50
|
|
|
$this->emitSelf('payment_success', $particular); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function update() |
54
|
|
|
{ |
55
|
|
|
$this->validate([ |
56
|
|
|
'amount' => 'required|numeric', |
57
|
|
|
]); |
58
|
|
|
|
59
|
|
|
$particular = $this->particular ?? ('An '.($this->type ? 'income' : 'expense').' of '.currency().$this->amount.' is registered under '.class_basename($this->model).' : '.$this->model->track_id.'(Updated)'); |
60
|
|
|
|
61
|
|
|
Payment::find($this->payment_id)->update([ |
62
|
|
|
'user_id' => Auth::user()->id, |
|
|
|
|
63
|
|
|
'type' => $this->type, |
64
|
|
|
'amount' => $this->amount, |
65
|
|
|
'particular' => $particular, |
66
|
|
|
]); |
67
|
|
|
$this->amount = null; |
68
|
|
|
$this->payment_id = null; |
69
|
|
|
|
70
|
|
|
$this->model->refresh(); |
71
|
|
|
$this->emitSelf('payment_success', $particular); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function setEdit(Payment $payment) |
75
|
|
|
{ |
76
|
|
|
$this->payment_id = $payment->id; |
77
|
|
|
$this->amount = $payment->amount; |
|
|
|
|
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function render() |
81
|
|
|
{ |
82
|
|
|
$payments = $this->model->payments; |
83
|
|
|
|
84
|
|
|
return view('website::livewire.admin.payment.payment-panel', compact('payments')); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|