Rework payment tables, enable payment editing

This commit is contained in:
Deon George
2021-07-23 17:25:26 +10:00
parent fa62a47680
commit d463239b17
19 changed files with 352 additions and 116 deletions

View File

@@ -21,12 +21,12 @@ class AdminController extends Controller
* @param Payment $o
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
*/
public function pay_add(Request $request,Payment $o)
public function pay_addedit(Request $request,Payment $o)
{
if ($request->post()) {
$validation = $request->validate([
'account_id' => 'required|exists:accounts,id',
'date_payment' => 'required|date',
'payment_date' => 'required|date',
'checkout_id' => 'required|exists:ab_checkout,id',
'total_amt' => 'required|numeric|min:0.01',
'fees_amt' => 'nullable|numeric|lt:total_amt',
@@ -41,36 +41,64 @@ class AdminController extends Controller
'invoices.*.id' => 'nullable|exists:ab_invoice,id',
]);
$oo = new Payment;
$oo->forceFill($request->only(['account_id','date_payment','checkout_id','checkout_id','total_amt','fees_amt','source_id','pending','notes','ip']));
$oo->site_id = config('SITE')->site_id;
$oo->save();
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->site_id = config('SITE')->site_id;
$o->save();
}
foreach ($validation['invoices'] as $id => $amount) {
$ooo = new PaymentItem;
$ooo->invoice_id = $id;
$ooo->alloc_amt = $amount;
$ooo->site_id = config('SITE')->site_id;
$oo->items()->save($ooo);
// See if we already have a payment item that we need to update
$items = $o->items->filter(function($item) use ($id) { return $item->invoice_id == $id; });
if ($items->count() == 1) {
$oo = $items->pop();
if (! $amount) {
$oo->delete();
continue;
}
} else {
$oo = new PaymentItem;
$oo->invoice_id = $id;
}
$oo->alloc_amt = $amount;
$oo->site_id = config('SITE')->site_id;
$o->items()->save($oo);
}
return redirect()->back()
->with('success','Payment recorded');
}
return view('a.payment.add')
return view('a.payment.addedit')
->with('o',$o);
}
/**
* List unapplied payments
*
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function pay_unapplied()
{
return view('a.payment.unapplied');
}
/**
* Show a list of invoices to apply payments to
*
* @param Request $request
* @param Account $o
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
*/
public function pay_invoices(Account $o)
public function pay_invoices(Request $request,Account $o)
{
return view('a.payment.widgets.invoices')
->with('pid',$request->pid)
->with('o',$o);
}

View File

@@ -217,7 +217,7 @@ class PaypalController extends Controller
break;
}
$po->date_payment = Carbon::parse($cap->create_time);
$po->payment_date = Carbon::parse($cap->create_time);
$po->checkout_id = $this->o->id;
$po->checkout_data = $cap->id;

View File

@@ -5,8 +5,9 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;
use App\Models\{Account,Invoice,Service,Service\Adsl,Service\Voip,User};
use App\Models\{Account,Invoice,Payment,Service,Service\Adsl,Service\Voip,User};
class SearchController extends Controller
{
@@ -90,6 +91,16 @@ class SearchController extends Controller
$result->push(['name'=>sprintf('%s (%s)',$o->service_name,$o->service->sid),'value'=>'/u/service/'.$o->id,'category'=>'Domains']);
}
if (Gate::any(['wholesaler'],new Payment)) {
# Look for Payments
foreach (Payment::Search($request->input('term'))
->whereIN('account_id',$accounts)
->limit(10)->get() as $o)
{
$result->push(['name'=>sprintf('%s ($%s)',$o->id,number_format($o->total,2)),'value'=>'/a/payment/edit'.$o->id,'category'=>'Payments']);
}
}
return $result;
}
}