Added: Payments For Purchase Returns
This commit is contained in:
parent
f65d180d5e
commit
e98ade9ffb
|
@ -2,51 +2,146 @@
|
|||
|
||||
namespace Modules\PurchasesReturn\Http\Controllers;
|
||||
|
||||
use App\DataTables\PurchaseReturnPaymentsDataTable;
|
||||
use Illuminate\Contracts\Support\Renderable;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Modules\PurchasesReturn\Entities\PurchaseReturn;
|
||||
use Modules\PurchasesReturn\Entities\PurchaseReturnPayment;
|
||||
|
||||
class PurchaseReturnPaymentsController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return view('purchasesreturn::index');
|
||||
public function index($purchase_return_id, PurchaseReturnPaymentsDataTable $dataTable) {
|
||||
abort_if(Gate::denies('access_purchase_return_payments'), 403);
|
||||
|
||||
$purchase_return = PurchaseReturn::findOrFail($purchase_return_id);
|
||||
|
||||
return $dataTable->render('purchasesreturn::payments.index', compact('purchase_return'));
|
||||
}
|
||||
|
||||
|
||||
public function create()
|
||||
{
|
||||
return view('purchasesreturn::create');
|
||||
public function create($purchase_return_id) {
|
||||
abort_if(Gate::denies('access_purchase_return_payments'), 403);
|
||||
|
||||
$purchase_return = PurchaseReturn::findOrFail($purchase_return_id);
|
||||
|
||||
return view('purchasesreturn::payments.create', compact('purchase_return'));
|
||||
}
|
||||
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
public function store(Request $request) {
|
||||
abort_if(Gate::denies('access_purchase_return_payments'), 403);
|
||||
|
||||
$request->validate([
|
||||
'date' => 'required|date',
|
||||
'reference' => 'required|string|max:255',
|
||||
'amount' => 'required|numeric',
|
||||
'note' => 'nullable|string|max:1000',
|
||||
'purchase_return_id' => 'required',
|
||||
'payment_method' => 'required|string|max:255'
|
||||
]);
|
||||
|
||||
DB::transaction(function () use ($request) {
|
||||
PurchaseReturnPayment::create([
|
||||
'date' => $request->date,
|
||||
'reference' => $request->reference,
|
||||
'amount' => $request->amount,
|
||||
'note' => $request->note,
|
||||
'purchase_return_id' => $request->purchase_return_id,
|
||||
'payment_method' => $request->payment_method
|
||||
]);
|
||||
|
||||
$purchase_return = PurchaseReturn::findOrFail($request->purchase_return_id);
|
||||
|
||||
$due_amount = $purchase_return->due_amount - $request->amount;
|
||||
|
||||
if ($due_amount == $purchase_return->total_amount) {
|
||||
$payment_status = 'Unpaid';
|
||||
} elseif ($due_amount > 0) {
|
||||
$payment_status = 'Partial';
|
||||
} else {
|
||||
$payment_status = 'Paid';
|
||||
}
|
||||
|
||||
$purchase_return->update([
|
||||
'paid_amount' => ($purchase_return->paid_amount + $request->amount) * 100,
|
||||
'due_amount' => $due_amount * 100,
|
||||
'payment_status' => $payment_status
|
||||
]);
|
||||
});
|
||||
|
||||
toast('Purchase Return Payment Created!', 'success');
|
||||
|
||||
return redirect()->route('purchase-returns.index');
|
||||
}
|
||||
|
||||
|
||||
public function show($id)
|
||||
{
|
||||
return view('purchasesreturn::show');
|
||||
public function edit($purchase_return_id, PurchaseReturnPayment $purchaseReturnPayment) {
|
||||
abort_if(Gate::denies('access_purchase_return_payments'), 403);
|
||||
|
||||
$purchase_return = PurchaseReturn::findOrFail($purchase_return_id);
|
||||
|
||||
return view('purchasesreturn::payments.edit', compact('purchaseReturnPayment', 'purchase_return'));
|
||||
}
|
||||
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
return view('purchasesreturn::edit');
|
||||
public function update(Request $request, PurchaseReturnPayment $purchaseReturnPayment) {
|
||||
abort_if(Gate::denies('access_purchase_return_payments'), 403);
|
||||
|
||||
$request->validate([
|
||||
'date' => 'required|date',
|
||||
'reference' => 'required|string|max:255',
|
||||
'amount' => 'required|numeric',
|
||||
'note' => 'nullable|string|max:1000',
|
||||
'purchase_return_id' => 'required',
|
||||
'payment_method' => 'required|string|max:255'
|
||||
]);
|
||||
|
||||
DB::transaction(function () use ($request, $purchaseReturnPayment) {
|
||||
$purchase_return = $purchaseReturnPayment->purchaseReturn;
|
||||
|
||||
$due_amount = ($purchase_return->due_amount + $purchaseReturnPayment->amount) - $request->amount;
|
||||
|
||||
if ($due_amount == $purchase_return->total_amount) {
|
||||
$payment_status = 'Unpaid';
|
||||
} elseif ($due_amount > 0) {
|
||||
$payment_status = 'Partial';
|
||||
} else {
|
||||
$payment_status = 'Paid';
|
||||
}
|
||||
|
||||
$purchase_return->update([
|
||||
'paid_amount' => (($purchase_return->paid_amount - $purchaseReturnPayment->amount) + $request->amount) * 100,
|
||||
'due_amount' => $due_amount * 100,
|
||||
'payment_status' => $payment_status
|
||||
]);
|
||||
|
||||
$purchaseReturnPayment->update([
|
||||
'date' => $request->date,
|
||||
'reference' => $request->reference,
|
||||
'amount' => $request->amount,
|
||||
'note' => $request->note,
|
||||
'purchase_return_id' => $request->purchase_return_id,
|
||||
'payment_method' => $request->payment_method
|
||||
]);
|
||||
});
|
||||
|
||||
toast('Purchase Return Payment Updated!', 'info');
|
||||
|
||||
return redirect()->route('purchase-returns.index');
|
||||
}
|
||||
|
||||
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
public function destroy(PurchaseReturnPayment $purchaseReturnPayment) {
|
||||
abort_if(Gate::denies('access_purchase_return_payments'), 403);
|
||||
|
||||
$purchaseReturnPayment->delete();
|
||||
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
toast('Purchase Return Payment Deleted!', 'warning');
|
||||
|
||||
return redirect()->route('purchase-returns.index');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,114 @@
|
|||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Create Payment')
|
||||
|
||||
@section('breadcrumb')
|
||||
<ol class="breadcrumb border-0 m-0">
|
||||
<li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('purchase-returns.index') }}">Purchase Returns</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('purchase-returns.show', $purchase_return) }}">{{ $purchase_return->reference }}</a></li>
|
||||
<li class="breadcrumb-item active">Add Payment</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="container-fluid">
|
||||
<form id="payment-form" action="{{ route('purchase-return-payments.store') }}" method="POST">
|
||||
@csrf
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
@include('utils.alerts')
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary">Create Payment <i class="bi bi-check"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label for="reference">Reference <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="reference" required readonly value="INV/{{ $purchase_return->reference }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label for="date">Date <span class="text-danger">*</span></label>
|
||||
<input type="date" class="form-control" name="date" required value="{{ now()->format('Y-m-d') }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="due_amount">Due Amount <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="due_amount" required value="{{ format_currency($purchase_return->due_amount) }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="amount">Amount <span class="text-danger">*</span></label>
|
||||
<div class="input-group">
|
||||
<input id="amount" type="text" class="form-control" name="amount" required value="{{ old('amount') }}">
|
||||
<div class="input-group-append">
|
||||
<button id="getTotalAmount" class="btn btn-primary" type="button">
|
||||
<i class="bi bi-check-square"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="from-group">
|
||||
<div class="form-group">
|
||||
<label for="payment_method">Payment Method <span class="text-danger">*</span></label>
|
||||
<select class="form-control" name="payment_method" id="payment_method" required>
|
||||
<option value="Cash">Cash</option>
|
||||
<option value="Credit Card">Credit Card</option>
|
||||
<option value="Bank Transfer">Bank Transfer</option>
|
||||
<option value="Cheque">Cheque</option>
|
||||
<option value="Other">Other</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="note">Note</label>
|
||||
<textarea class="form-control" rows="4" name="note">{{ old('note') }}</textarea>
|
||||
</div>
|
||||
|
||||
<input type="hidden" value="{{ $purchase_return->id }}" name="purchase_return_id">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script src="{{ asset('js/jquery-mask-money.js') }}"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#amount').maskMoney({
|
||||
prefix:'{{ settings()->currency->symbol }}',
|
||||
thousands:'{{ settings()->currency->thousand_separator }}',
|
||||
decimal:'{{ settings()->currency->decimal_separator }}',
|
||||
});
|
||||
|
||||
$('#getTotalAmount').click(function () {
|
||||
$('#amount').maskMoney('mask', {{ $purchase_return->due_amount }});
|
||||
});
|
||||
|
||||
$('#payment-form').submit(function () {
|
||||
var amount = $('#amount').maskMoney('unmasked')[0];
|
||||
$('#amount').val(amount);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Edit Payment')
|
||||
|
||||
@section('breadcrumb')
|
||||
<ol class="breadcrumb border-0 m-0">
|
||||
<li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('purchase-returns.index') }}">Purchase Returns</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('purchase-returns.show', $purchase_return) }}">{{ $purchase_return->reference }}</a></li>
|
||||
<li class="breadcrumb-item active">Edit Payment</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="container-fluid">
|
||||
<form id="payment-form" action="{{ route('purchase-return-payments.update', $purchaseReturnPayment) }}" method="POST">
|
||||
@csrf
|
||||
@method('patch')
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
@include('utils.alerts')
|
||||
<div class="form-group">
|
||||
<button class="btn btn-primary">Update Payment <i class="bi bi-check"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-12">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="form-row">
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label for="reference">Reference <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="reference" required readonly value="{{ $purchaseReturnPayment->reference }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6">
|
||||
<div class="form-group">
|
||||
<label for="date">Date <span class="text-danger">*</span></label>
|
||||
<input type="date" class="form-control" name="date" required value="{{ $purchaseReturnPayment->getAttributes()['date'] }}">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="due_amount">Due Amount <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="due_amount" required value="{{ format_currency($purchase_return->due_amount) }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="form-group">
|
||||
<label for="amount">Amount <span class="text-danger">*</span></label>
|
||||
<div class="input-group">
|
||||
<input id="amount" type="text" class="form-control" name="amount" required value="{{ old('amount') ?? $purchaseReturnPayment->amount }}">
|
||||
<div class="input-group-append">
|
||||
<button id="getTotalAmount" class="btn btn-primary" type="button">
|
||||
<i class="bi bi-check-square"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<div class="from-group">
|
||||
<div class="form-group">
|
||||
<label for="payment_method">Payment Method <span class="text-danger">*</span></label>
|
||||
<select class="form-control" name="payment_method" id="payment_method" required>
|
||||
<option {{ $purchaseReturnPayment->payment_method == 'Cash' ? 'selected' : '' }} value="Cash">Cash</option>
|
||||
<option {{ $purchaseReturnPayment->payment_method == 'Credit Card' ? 'selected' : '' }} value="Credit Card">Credit Card</option>
|
||||
<option {{ $purchaseReturnPayment->payment_method == 'Bank Transfer' ? 'selected' : '' }} value="Bank Transfer">Bank Transfer</option>
|
||||
<option {{ $purchaseReturnPayment->payment_method == 'Cheque' ? 'selected' : '' }} value="Cheque">Cheque</option>
|
||||
<option {{ $purchaseReturnPayment->payment_method == 'Other' ? 'selected' : '' }} value="Other">Other</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="note">Note</label>
|
||||
<textarea class="form-control" rows="4" name="note">{{ old('note') ?? $purchaseReturnPayment->note }}</textarea>
|
||||
</div>
|
||||
|
||||
<input type="hidden" value="{{ $purchase_return->id }}" name="purchase_return_id">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
<script src="{{ asset('js/jquery-mask-money.js') }}"></script>
|
||||
<script>
|
||||
$(document).ready(function () {
|
||||
$('#amount').maskMoney({
|
||||
prefix:'{{ settings()->currency->symbol }}',
|
||||
thousands:'{{ settings()->currency->thousand_separator }}',
|
||||
decimal:'{{ settings()->currency->decimal_separator }}',
|
||||
});
|
||||
|
||||
$('#amount').maskMoney('mask');
|
||||
|
||||
$('#getTotalAmount').click(function () {
|
||||
$('#amount').maskMoney('mask', {{ $purchase_return->due_amount }});
|
||||
});
|
||||
|
||||
$('#payment-form').submit(function () {
|
||||
var amount = $('#amount').maskMoney('unmasked')[0];
|
||||
$('#amount').val(amount);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
@extends('layouts.app')
|
||||
|
||||
@section('title', 'Sale Payments')
|
||||
|
||||
@section('third_party_stylesheets')
|
||||
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.25/css/dataTables.bootstrap4.min.css">
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
<ol class="breadcrumb border-0 m-0">
|
||||
<li class="breadcrumb-item"><a href="{{ route('home') }}">Home</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('purchase-returns.index') }}">Purcase Returns</a></li>
|
||||
<li class="breadcrumb-item"><a href="{{ route('purchases.show', $purchase_return) }}">{{ $purchase_return->reference }}</a></li>
|
||||
<li class="breadcrumb-item active">Payments</li>
|
||||
</ol>
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
@include('utils.alerts')
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
{!! $dataTable->table() !!}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@push('page_scripts')
|
||||
{!! $dataTable->scripts() !!}
|
||||
@endpush
|
|
@ -24,7 +24,7 @@ class SaleReturnPaymentsController extends Controller
|
|||
|
||||
|
||||
public function create($sale_return_id) {
|
||||
abort_if(Gate::denies('access_sale_payments'), 403);
|
||||
abort_if(Gate::denies('access_sale_return_payments'), 403);
|
||||
|
||||
$sale_return = SaleReturn::findOrFail($sale_return_id);
|
||||
|
||||
|
@ -33,7 +33,7 @@ class SaleReturnPaymentsController extends Controller
|
|||
|
||||
|
||||
public function store(Request $request) {
|
||||
abort_if(Gate::denies('access_sale_payments'), 403);
|
||||
abort_if(Gate::denies('access_sale_return_payments'), 403);
|
||||
|
||||
$request->validate([
|
||||
'date' => 'required|date',
|
||||
|
|
Loading…
Reference in New Issue