1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Admin; |
4
|
|
|
|
5
|
|
|
use App\Models\Payment; |
6
|
|
|
use Backpack\CRUD\app\Http\Controllers\CrudController; |
7
|
|
|
use Backpack\CRUD\app\Http\Controllers\Operations\ListOperation; |
8
|
|
|
use Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation; |
9
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanel; |
10
|
|
|
use Backpack\CRUD\app\Library\CrudPanel\CrudPanelFacade as CRUD; |
11
|
|
|
use Illuminate\Support\Carbon; |
12
|
|
|
use Illuminate\Support\Facades\Redirect; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PaymentCrudController |
16
|
|
|
* @property-read CrudPanel $crud |
17
|
|
|
*/ |
18
|
|
|
class PaymentCrudController extends CrudController |
19
|
|
|
{ |
20
|
|
|
use ListOperation; |
|
|
|
|
21
|
|
|
use ShowOperation { show as traitShow; } |
|
|
|
|
22
|
|
|
|
23
|
|
|
public function __construct() |
24
|
|
|
{ |
25
|
|
|
parent::__construct(); |
26
|
|
|
$this->middleware('permission:enrollments.edit'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Configure the CrudPanel object. Apply settings to all operations. |
31
|
|
|
*/ |
32
|
|
|
public function setup() |
33
|
|
|
{ |
34
|
|
|
CRUD::setModel(Payment::class); |
35
|
|
|
CRUD::setRoute(config('backpack.base.route_prefix').'/payment'); |
36
|
|
|
CRUD::setEntityNameStrings('payment', 'payments'); |
37
|
|
|
|
38
|
|
|
$this->crud->enableExportButtons(); |
39
|
|
|
|
40
|
|
|
$this->crud->addButtonFromView('top', 'createInvoice', 'createInvoice', 'start'); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Define what happens when the List operation is loaded. |
45
|
|
|
*/ |
46
|
|
|
protected function setupListOperation() |
47
|
|
|
{ |
48
|
|
|
$this->crud->addFilter( |
49
|
|
|
[ |
50
|
|
|
'type' => 'date', |
51
|
|
|
'name' => 'date', |
52
|
|
|
'label' => __('Due Date'), |
53
|
|
|
], |
54
|
|
|
false, |
55
|
|
|
function ($value) { // if the filter is active, apply these constraints |
56
|
|
|
$this->crud->addClause('where', 'date', '>=', Carbon::parse($value)->firstOfMonth()); |
57
|
|
|
$this->crud->addClause('where', 'date', '<=', Carbon::parse($value)->lastOfMonth()); |
58
|
|
|
} |
59
|
|
|
); |
60
|
|
|
|
61
|
|
|
CRUD::column('month'); |
62
|
|
|
|
63
|
|
|
if (config('app.currency_position') === 'before') { |
64
|
|
|
$currency = ['prefix' => config('app.currency_symbol')]; |
65
|
|
|
} else { |
66
|
|
|
$currency = ['suffix' => config('app.currency_symbol')]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
CRUD::addColumn([ |
70
|
|
|
'name' => 'enrollment_name', |
71
|
|
|
'type' => 'attribute', |
72
|
|
|
'label' => __('Enrollment'), |
73
|
|
|
]); |
74
|
|
|
|
75
|
|
|
CRUD::addColumn(array_merge([ |
76
|
|
|
'name' => 'value', |
77
|
|
|
'label' => __('Value'), |
78
|
|
|
'type' => 'number', |
79
|
|
|
], $currency)); |
80
|
|
|
|
81
|
|
|
CRUD::addColumn([ |
82
|
|
|
'name' => 'iban', |
83
|
|
|
'type' => 'attribute', |
84
|
|
|
'label' => 'IBAN', |
85
|
|
|
]); |
86
|
|
|
|
87
|
|
|
CRUD::addColumn([ |
88
|
|
|
'name' => 'bic', |
89
|
|
|
'type' => 'attribute', |
90
|
|
|
'label' => 'BIC', |
91
|
|
|
]); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function show($id) |
95
|
|
|
{ |
96
|
|
|
$payment = Payment::findOrFail($id); |
97
|
|
|
|
98
|
|
|
if (! backpack_user()->can('enrollments.edit')) { |
99
|
|
|
abort(403); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
if (! $payment->invoice) { |
103
|
|
|
abort(404, 'No enrollment found for this payment'); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return Redirect::route('invoice.show', ['id' => $payment->invoice_id]); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|