Fix payment entry
This commit is contained in:
@@ -6,7 +6,16 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Models\{Account,Charge,InvoiceItem,Payment,PaymentItem,Service,SiteDetail,Supplier,SupplierDetail};
|
||||
use App\Models\{Account,
|
||||
Charge,
|
||||
Invoice,
|
||||
InvoiceItem,
|
||||
Payment,
|
||||
PaymentItem,
|
||||
Service,
|
||||
SiteDetail,
|
||||
Supplier,
|
||||
SupplierDetail};
|
||||
|
||||
/**
|
||||
* The AdminController governs all routes that are prefixed with 'a/'.
|
||||
@@ -83,9 +92,10 @@ class AdminController extends Controller
|
||||
public function pay_addedit(Request $request,Payment $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
|
||||
$validation = $request->validate([
|
||||
'account_id' => 'required|exists:accounts,id',
|
||||
'payment_date' => 'required|date',
|
||||
'paid_at' => 'required|date',
|
||||
'checkout_id' => 'required|exists:ab_checkout,id',
|
||||
'total_amt' => 'required|numeric|min:0.01',
|
||||
'fees_amt' => 'nullable|numeric|lt:total_amt',
|
||||
@@ -93,15 +103,18 @@ class AdminController extends Controller
|
||||
'pending' => 'nullable|boolean',
|
||||
'notes' => 'nullable|string',
|
||||
'ip' => 'nullable|ip',
|
||||
'invoices' => ['nullable','array',function ($attribute,$value,$fail) use ($request) {
|
||||
if (collect($value)->sum() > $request->post('total_amt'))
|
||||
'invoices' => ['required','array',function ($attribute,$value,$fail) use ($request) {
|
||||
if (collect($value)->sum('id') > $request->post('total_amt'))
|
||||
$fail('Allocation is greater than payment total.');
|
||||
}],
|
||||
'invoices.*.id' => 'nullable|exists:invoices,id',
|
||||
'invoices.*.id' => ['required',function ($attribute,$value,$fail) {
|
||||
if (! Invoice::exists(str_replace(str_replace($attribute,'invoice\.','',),'.id','')))
|
||||
$fail('Invoice doesnt exist in DB');
|
||||
}],
|
||||
]);
|
||||
|
||||
if (! $o->exists) {
|
||||
$o->forceFill($request->only(['account_id','payment_date','checkout_id','checkout_id','total_amt','fees_amt','source_id','pending','notes','ip']));
|
||||
$o->forceFill($request->only(['account_id','paid_at','checkout_id','checkout_id','total_amt','fees_amt','source_id','pending','notes','ip']));
|
||||
$o->site_id = config('site')->site_id;
|
||||
$o->save();
|
||||
}
|
||||
@@ -113,7 +126,7 @@ class AdminController extends Controller
|
||||
if ($items->count() == 1) {
|
||||
$oo = $items->pop();
|
||||
|
||||
if (! $amount) {
|
||||
if (! $amount['id']) {
|
||||
$oo->delete();
|
||||
continue;
|
||||
}
|
||||
@@ -123,7 +136,7 @@ class AdminController extends Controller
|
||||
$oo->invoice_id = $id;
|
||||
}
|
||||
|
||||
$oo->amount = ($oo->invoice->due >= 0) && ($oo->invoice->due-$amount >= 0) ? $amount : 0;
|
||||
$oo->amount = ($oo->invoice->due >= 0) && ($oo->invoice->due-$amount['id'] >= 0) ? $amount['id'] : 0;
|
||||
$oo->site_id = config('site')->site_id;
|
||||
$o->items()->save($oo);
|
||||
}
|
||||
|
@@ -217,7 +217,7 @@ class PaypalController extends Controller
|
||||
break;
|
||||
}
|
||||
|
||||
$po->payment_date = Carbon::parse($cap->create_time);
|
||||
$po->paid_at = Carbon::parse($cap->create_time);
|
||||
$po->checkout_id = $this->o->id;
|
||||
$po->checkout_data = $cap->id;
|
||||
|
||||
|
Reference in New Issue
Block a user