Skip to content

Commit

Permalink
Added create payment page
Browse files Browse the repository at this point in the history
  • Loading branch information
yungifez committed Mar 4, 2023
1 parent 9cb75a6 commit 8bc0980
Show file tree
Hide file tree
Showing 11 changed files with 140 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
# ensure the UID and GID of the container user you create matches your local user.
# See https://aka.ms/vscode-remote/containers/non-root for details.
#
# user: vscode
user: sail

# Uncomment if you want to override the service's Dockerfile to one in the .devcontainer
# folder. Note that the path of the Dockerfile and context is relative to the *primary*
Expand Down
9 changes: 9 additions & 0 deletions app/Http/Controllers/FeeInvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,13 @@ public function destroy(FeeInvoice $feeInvoice): RedirectResponse
{
//
}

public function payView(FeeInvoice $feeInvoice) : View
{
$this->authorize('update', $feeInvoice);

return view('pages.fee.fee-invoice.pay', compact('feeInvoice'));
}


}
18 changes: 13 additions & 5 deletions app/Http/Controllers/FeeInvoiceRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace App\Http\Controllers;

use App\Http\Requests\StoreFeeInvoiceRecordRequest;
use App\Http\Requests\UpdateFeeInvoiceRecordRequest;
use Illuminate\Http\Response;
use App\Models\FeeInvoiceRecord;
use App\Services\Fee\FeeInvoiceRecordService;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Response;
use App\Http\Requests\PayFeeInvoiceRequest;
use App\Services\Fee\FeeInvoiceRecordService;
use App\Http\Requests\StoreFeeInvoiceRecordRequest;
use App\Http\Requests\UpdateFeeInvoiceRecordRequest;

class FeeInvoiceRecordController extends Controller
{
Expand Down Expand Up @@ -73,10 +74,17 @@ public function update(UpdateFeeInvoiceRecordRequest $request, FeeInvoiceRecord
/**
* Remove the specified resource from storage.
*/
public function destroy(FeeInvoiceRecord $feeInvoiceRecord)
public function destroy(FeeInvoiceRecord $feeInvoiceRecord) : RedirectResponse
{
$this->feeInvoiceRecordService->deleteFeeInvoiceRecord($feeInvoiceRecord);

return back()->with('success', 'Fee Removed From Fee Invoice Successfully');
}

public function pay(FeeInvoiceRecord $feeInvoiceRecord, PayFeeInvoiceRequest $request) : RedirectResponse
{
$this->feeInvoiceRecordService->addPayment($feeInvoiceRecord, $request->validated());

return back()->with('success', 'Payment added to Fee Successfully');
}
}
8 changes: 7 additions & 1 deletion app/Http/Livewire/Datatable.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ class Datatable extends Component

public $search = null;

public int $perPage = 10;
public $perPage = 10;

protected $rules = [
'perPage' => 'nullable|integer',
'search' => 'nullable|string'
];

/**
* @param string|Builder $model Pass model or query builder
Expand Down Expand Up @@ -62,6 +67,7 @@ public function verifyIsModel($model)

public function BuildPagination()
{
$this->validate();
$model = app()->make($this->model);
$this->verifyIsModel($model);

Expand Down
19 changes: 19 additions & 0 deletions app/Http/Livewire/PayInvoiceForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Http\Livewire;

use Livewire\Component;

class PayInvoiceForm extends Component
{
public $feeInvoice;

public function mount()
{
$this->feeInvoice->loadMissing('feeInvoiceRecords', 'feeInvoiceRecords.fee');
}
public function render()
{
return view('livewire.pay-invoice-form');
}
}
20 changes: 20 additions & 0 deletions app/Http/Requests/PayFeeInvoiceRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class PayFeeInvoiceRequest extends FormRequest
{
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\Rule|array|string>
*/
public function rules(): array
{
return [
'pay' => "required|integer:min:-10000000000000|max:10000000000000",
];
}
}
24 changes: 23 additions & 1 deletion app/Services/Fee/FeeInvoiceRecordService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

use App\Exceptions\InvalidValueException;
use App\Models\Fee;
use App\Models\FeeInvoice;
use App\Models\FeeInvoiceRecord;
use Brick\Money\Money;

class FeeInvoiceRecordService
{
Expand Down Expand Up @@ -62,4 +62,26 @@ public function deleteFeeInvoiceRecord(FeeInvoiceRecord $feeInvoiceRecord)
{
$feeInvoiceRecord->delete();
}

/**
* Add a new paymeny
*
* @param FeeInvoiceRecord $feeInvoiceRecord
* @param array $records
* @return void
*/
public function addPayment(FeeInvoiceRecord $feeInvoiceRecord, $records)
{
$pay = Money::of($records['pay'], config('app.currency'));

$paid = $feeInvoiceRecord->paid;

$newAmount = $paid->plus($pay);

$feeInvoiceRecord->update([
'paid' => $newAmount
]);

return;
}
}
1 change: 1 addition & 0 deletions resources/views/livewire/list-fee-invoices-table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
['name' => 'Actions', 'type' => 'dropdown' , 'links' => [
['href' => 'fee-invoices.edit', 'text' => 'edit', 'icon' => 'fas fa-cog'],
['href' => 'fee-invoices.show', 'text' => 'view', 'icon' => 'fas fa-eye'],
['href' => 'fee-invoices.pay', 'text' => 'Add Payment ', 'icon' => 'fas fa-money-check-alt'],
]],
['type' => 'delete', 'name' => 'Delete', 'action' => 'fee-invoices.destroy',]
]"
Expand Down
27 changes: 27 additions & 0 deletions resources/views/livewire/pay-invoice-form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="card">
<div class="card-header">
<h2 class="card-title">{{$feeInvoice->name}}</h2>
</div>
<div class="card-body">
<x-display-validation-errors/>
@foreach ($feeInvoice->feeInvoiceRecords as $record)
<form action="{{route('fee-invoices-records.pay', $record->id)}}" method="POST" class="col-span-5 overflow-scroll beautify-scrollbar grid grid-rows-1 md:grid-cols-5 gap-2 items-center border-b p-2 md:py-0" x-data="{'amount': {{$record->amount->getAmount()->toInt()}}, 'waiver': {{$record->waiver->getAmount()->toInt()}}, 'fine': {{$record->fine->getAmount()->toInt()}}, 'paid': {{$record->paid->getAmount()->toInt()}}, 'payment_amount' : 0 }">
<p class="font-bold md:font-bold">{{$record->fee->name }}</p>
<x-input id="amount-{{$record['id']}}" name="pay" label="Payment Amount" type="number" x-model.number="payment_amount" error-bag="some-random-thing"/>
<div class="md:place-self-center">
<p x-text="'Fee Amount: ' + amount"></p>
<p x-text="'Fee Waiver: ' + waiver"></p>
<p x-text="'Fee Fine: ' + fine"></p>
<p x-text="'Fee Amount Paid: ' + paid"></p>
</div>
<p x-text="'Due: ' + (amount - waiver + fine - paid - payment_amount).toLocaleString()" class="md:place-self-center"></p>
<input type="hidden" value="{{$record->fee->id}}">
<x-button label="Add Payment" class="self-" icon="fas fa-money-check-alt"/>
@csrf
</form>
@endforeach
<p class="my-3">
Note: The due stated might not be fully precise
</p>
</div>
</div>
14 changes: 14 additions & 0 deletions resources/views/pages/fee/fee-invoice/pay.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@extends('layouts.app', ['breadcrumbs' => [
['href'=> route('dashboard'), 'text'=> 'Dashboard'],
['href'=> route('fees.index'), 'text'=> 'Fees'],
['href'=> route('fee-invoices.index'), 'text'=> 'Fee Invoices'],
['href'=> route('fee-invoices.pay', $feeInvoice->id), 'text'=> 'Pay', 'active'],
]])

@section('title', __('Add Payments to Fees Invoice'))

@section('page_heading', __('Add Payments to Fees Invoice'))

@section('content', )
@livewire('pay-invoice-form' , compact('feeInvoice'))
@endsection
8 changes: 6 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@
Route::middleware(['App\Http\Middleware\EnsureSemesterIsSet'])->group(function () {
//fee categories routes
Route::resource('fees/fee-categories', FeeCategoryController::class);
//fee invoice routes

//fee invoice record routes
Route::post('fees/fee-invoices/fee-invoice-records/{fee_invoice_record}/pay', ['App\Http\Controllers\FeeInvoiceRecordController', 'pay'])->name('fee-invoices-records.pay');
Route::resource('fees/fee-invoices/fee-invoice-records', FeeInvoiceRecordController::class);

//fee incvoice routes
Route::get('fees/fee-invoices/{fee_invoice}/pay', ['App\Http\Controllers\FeeInvoiceController', 'payView'])->name('fee-invoices.pay');
Route::get('fees/fee-invoices/{fee_invoice}/print', ['App\Http\Controllers\FeeInvoiceController', 'print'])->name('fee-invoices.print');

Route::resource('fees/fee-invoices', FeeInvoiceController::class);

//fee routes
Route::resource('fees', FeeController::class);

Expand Down

0 comments on commit 8bc0980

Please sign in to comment.