Separated Checkout and Payment controllers, updates to checkout and payments
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
/**
|
||||
* Editing Suppliers
|
||||
@@ -28,7 +29,13 @@ class CheckoutAddEdit extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|min:2|max:255',
|
||||
'name' => [
|
||||
'required',
|
||||
'string',
|
||||
'min:2',
|
||||
'max:255',
|
||||
Rule::unique('checkouts','name')->ignore($this->route('o')?->id),
|
||||
],
|
||||
'active' => 'sometimes|accepted',
|
||||
'description' => 'nullable|string|min:2|max:255',
|
||||
];
|
||||
|
62
app/Http/Requests/PaymentAddEdit.php
Normal file
62
app/Http/Requests/PaymentAddEdit.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
/**
|
||||
* Editing Suppliers
|
||||
*/
|
||||
class PaymentAddEdit extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::user()->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'paid_at' => 'required|date',
|
||||
'checkout_id' => 'required|exists:checkouts,id',
|
||||
'total_amt' => 'required|numeric|min:0.01',
|
||||
'fees_amt' => 'nullable|numeric|lt:total_amt',
|
||||
'source_id' => 'nullable|exists:accounts,id',
|
||||
'pending' => 'nullable|boolean',
|
||||
'notes' => 'nullable|string',
|
||||
'ip' => 'nullable|ip',
|
||||
'invoices' => [
|
||||
'nullable',
|
||||
'array',
|
||||
function($attribute,$value,$fail) {
|
||||
if (($x=collect($value)->sum()) > request()->post('total_amt'))
|
||||
$fail(sprintf('Allocation %3.2f is greater than payment total %3.2f.',$x,request()->post('total_amt')));
|
||||
}
|
||||
],
|
||||
'invoices.*' => [
|
||||
'nullable',
|
||||
function($attribute,$value,$fail) {
|
||||
if (! ($x=Invoice::where('id',$xx=str_replace('invoices.','',$attribute))->first()))
|
||||
$fail(sprintf('Invoice [%d] doesnt exist in DB',$xx));
|
||||
// @todo The due amount may be influenced by this payment (ie: payment edit)
|
||||
elseif($x->due < $value)
|
||||
$fail(sprintf('Invoice [%d] is over allocated by %3.2f',$x->id,$value-$x->due));
|
||||
}
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user