1 | <?php |
||
2 | |||
3 | namespace App\Http\Controllers; |
||
4 | |||
5 | use App\Models\Book; |
||
6 | use App\Models\Discount; |
||
7 | use App\Models\Enrollment; |
||
8 | use App\Models\Fee; |
||
9 | use App\Models\InvoiceType; |
||
10 | use App\Models\Paymentmethod; |
||
11 | use App\Models\ScheduledPayment; |
||
12 | use App\Models\Tax; |
||
13 | use Illuminate\Http\Request; |
||
14 | use Illuminate\Support\Facades\Log; |
||
15 | |||
16 | class ScheduledPaymentController extends Controller |
||
17 | { |
||
18 | public function create(Enrollment $enrollment) |
||
19 | { |
||
20 | return view('invoices.create_scheduled_payments', [ |
||
21 | 'enrollment' => $enrollment, |
||
22 | ]); |
||
23 | } |
||
24 | |||
25 | public function store(Enrollment $enrollment, Request $request) |
||
26 | { |
||
27 | // Should only be used to create payments, not to edit them. |
||
28 | foreach ($request->payments as $p => $payment) { |
||
29 | $enrollment->scheduledPayments()->create([ |
||
30 | 'responsable_id' => backpack_user()->id, |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
31 | 'value' => $payment['value'], |
||
32 | 'date' => $payment['date'], |
||
33 | 'status' => 1, |
||
34 | ]); |
||
35 | } |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * Create a new cart with the specified payment |
||
40 | * and display the cart. |
||
41 | */ |
||
42 | public function bill(ScheduledPayment $scheduledPayment) |
||
43 | { |
||
44 | // otherwise create a new one. |
||
45 | Log::info('User # '.backpack_user()->id.' is generating a invoice for a scheduled payment'); |
||
0 ignored issues
–
show
|
|||
46 | |||
47 | // build an array with products to include |
||
48 | $products = []; |
||
49 | |||
50 | $enrollment = $scheduledPayment->enrollment; |
||
51 | |||
52 | array_push($products, [ |
||
53 | 'name' => $enrollment->name, |
||
54 | 'product_code' => $enrollment->product_code, |
||
55 | 'type' => 'scheduledPayment', |
||
56 | 'price' => $scheduledPayment->value, |
||
57 | 'quantity' => 1, |
||
58 | 'id' => $scheduledPayment->id, |
||
59 | ]); |
||
60 | |||
61 | // build an array with all contact data |
||
62 | $clients = []; |
||
63 | |||
64 | array_push($clients, [ |
||
65 | 'name' => $enrollment->student_name, |
||
66 | 'email' => $enrollment->student_email, |
||
67 | 'idnumber' => $enrollment->student->idnumber, |
||
68 | 'address' => $enrollment->student->address, |
||
69 | 'phone' => $enrollment->student->phone, |
||
70 | ]); |
||
71 | |||
72 | foreach ($enrollment->student->contacts as $client) { |
||
73 | array_push($clients, $client); |
||
74 | } |
||
75 | |||
76 | $data = [ |
||
77 | 'enrollment' => $enrollment, |
||
78 | 'products' => $products, |
||
79 | 'invoicetypes' => InvoiceType::all(), |
||
80 | 'clients' => $clients, |
||
81 | 'availableBooks' => Book::all(), |
||
82 | 'availableFees' => Fee::all(), |
||
83 | 'availableDiscounts' => Discount::all(), |
||
84 | 'availablePaymentMethods' => Paymentmethod::all(), |
||
85 | 'availableTaxes' => Tax::all(), |
||
86 | ]; |
||
87 | if (config('invoicing.price_categories_enabled')) { |
||
88 | $data = array_merge( |
||
89 | $data, |
||
90 | [ |
||
91 | 'priceCategories' => collect([ |
||
92 | 'price_a' => $enrollment->course->price, |
||
93 | 'price_b' => $enrollment->course->price_b, |
||
94 | 'price_c' => $enrollment->course->price_c, |
||
95 | ]), |
||
96 | 'studentPriceCategory' => $enrollment->student?->price_category, |
||
97 | ] |
||
98 | ); |
||
99 | } |
||
100 | |||
101 | return view('carts.show', $data); |
||
102 | } |
||
103 | } |
||
104 |