Added payment recording, minor CSS fixes, enabled Search
This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\Http\Controllers;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
use App\Models\{Service,SiteDetail};
|
||||
use App\Models\{Account,Payment,PaymentItem,Service,SiteDetail};
|
||||
|
||||
class AdminController extends Controller
|
||||
{
|
||||
@@ -14,6 +14,66 @@ class AdminController extends Controller
|
||||
return View('a.service',['o'=>$o]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Record payments on an account.
|
||||
*
|
||||
* @param Request $request
|
||||
* @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)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$validation = $request->validate([
|
||||
'account_id' => 'required|exists:ab_account,id',
|
||||
'date_payment' => 'required|date',
|
||||
'checkout_id' => 'required|exists:ab_checkout,id',
|
||||
'total_amt' => 'required|numeric|min:0.01',
|
||||
'fees_amt' => 'nullable|numeric|lt:total_amt',
|
||||
'source_id' => 'nullable|exists:ab_account,id',
|
||||
'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'))
|
||||
$fail('Allocation is greater than payment total.');
|
||||
}],
|
||||
'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();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Payment recorded');
|
||||
}
|
||||
|
||||
return view('a.payment.add')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a list of invoices to apply payments to
|
||||
*
|
||||
* @param Account $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function pay_invoices(Account $o)
|
||||
{
|
||||
return view('a.payment.widgets.invoices')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site setup
|
||||
*
|
||||
|
@@ -60,7 +60,7 @@ class SearchController extends Controller
|
||||
->orderBy('id')
|
||||
->limit(10)->get() as $o)
|
||||
{
|
||||
$result->push(['name'=>sprintf('%s #%s',$o->account->name,$o->invoice_id),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
|
||||
$result->push(['name'=>sprintf('%s: %s',$o->sid,$o->account->name),'value'=>'/u/invoice/'.$o->id,'category'=>'Invoices']);
|
||||
}
|
||||
|
||||
# Look for an ADSL/NBN Service
|
||||
|
@@ -185,7 +185,7 @@ class Account extends Model implements IDs
|
||||
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->company ?: $this->user->SurFirstName;
|
||||
return $this->company ?: ($this->user_id ? $this->user->SurFirstName : 'AID:'.$this->id);
|
||||
}
|
||||
|
||||
public function getServicesCountHtmlAttribute()
|
||||
|
@@ -48,11 +48,13 @@ class Invoice extends Model implements IDs
|
||||
// Array of items that can be updated with PushNew
|
||||
protected $pushable = ['items'];
|
||||
|
||||
/*
|
||||
protected $with = [
|
||||
'account.country.currency',
|
||||
'items.taxes',
|
||||
'paymentitems'
|
||||
];
|
||||
*/
|
||||
|
||||
// Caching variables
|
||||
private int $_paid = 0;
|
||||
|
@@ -32,7 +32,7 @@ class Payment extends Model implements IDs
|
||||
protected $table = 'ab_payment';
|
||||
protected $dates = ['date_payment'];
|
||||
protected $dateFormat = 'U';
|
||||
protected $with = ['account.country.currency','items'];
|
||||
//protected $with = ['account.country.currency','items'];
|
||||
|
||||
// Array of items that can be updated with PushNew
|
||||
protected $pushable = ['items'];
|
||||
|
@@ -4,8 +4,7 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use App\Traits\NextKey;
|
||||
use App\Traits\PushNew;
|
||||
use App\Traits\{NextKey,PushNew};
|
||||
|
||||
class PaymentItem extends Model
|
||||
{
|
||||
@@ -13,11 +12,14 @@ class PaymentItem extends Model
|
||||
const RECORD_ID = 'payment_item';
|
||||
public $incrementing = FALSE;
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
const CREATED_AT = 'date_orig';
|
||||
const UPDATED_AT = 'date_last';
|
||||
|
||||
protected $table = 'ab_payment_item';
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function payment() {
|
||||
return $this->belongsTo(Payment::class);
|
||||
}
|
||||
|
Reference in New Issue
Block a user