2021-07-01 09:41:12 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
2021-07-02 04:35:43 +00:00
|
|
|
use App\Models\{Account,Payment,PaymentItem,Service,SiteDetail};
|
2021-07-01 09:41:12 +00:00
|
|
|
|
|
|
|
class AdminController extends Controller
|
|
|
|
{
|
|
|
|
public function service(Service $o)
|
|
|
|
{
|
|
|
|
return View('a.service',['o'=>$o]);
|
|
|
|
}
|
|
|
|
|
2021-07-02 04:35:43 +00:00
|
|
|
/**
|
|
|
|
* 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([
|
2021-07-19 06:23:38 +00:00
|
|
|
'account_id' => 'required|exists:accounts,id',
|
2021-07-02 04:35:43 +00:00
|
|
|
'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',
|
2021-07-19 06:23:38 +00:00
|
|
|
'source_id' => 'nullable|exists:accounts,id',
|
2021-07-02 04:35:43 +00:00
|
|
|
'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);
|
|
|
|
}
|
|
|
|
|
2021-07-01 09:41:12 +00:00
|
|
|
/**
|
|
|
|
* Site setup
|
|
|
|
*
|
|
|
|
* @note This method is protected by the routes
|
|
|
|
* @param Request $request
|
|
|
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
|
|
|
*/
|
|
|
|
public function setup(Request $request)
|
|
|
|
{
|
|
|
|
if ($request->post()) {
|
|
|
|
$validated = $request->validate([
|
|
|
|
'site_name' => 'required|string|max:255',
|
|
|
|
'site_email' => 'required|string|email|max:255',
|
|
|
|
'site_address1' => 'required|string|max:255',
|
|
|
|
'site_address2' => 'nullable|string|max:255',
|
|
|
|
'site_city' => 'required|string|max:64',
|
|
|
|
'site_state' => 'required|string|max:32',
|
|
|
|
'site_postcode' => 'required|string|max:8',
|
|
|
|
'site_description' => 'nullable|string|min:5',
|
|
|
|
'site_phone' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
|
|
|
|
'site_fax' => 'nullable|regex:/[0-9 ]+/|min:6|max:12',
|
|
|
|
'site_tax' => 'required|regex:/[0-9 ]+/|size:14',
|
|
|
|
'social' => 'nullable|array',
|
|
|
|
'top_menu' => 'nullable|array',
|
|
|
|
'site_logo' => 'nullable|image',
|
2021-07-01 23:12:34 +00:00
|
|
|
'email_logo' => 'nullable|image',
|
2021-07-01 09:41:12 +00:00
|
|
|
]);
|
|
|
|
|
2021-07-01 23:12:34 +00:00
|
|
|
$site = config('SITE');
|
2021-07-01 09:41:12 +00:00
|
|
|
|
|
|
|
// @todo - not currently rendered in the home page
|
|
|
|
$validated['social'] = [];
|
|
|
|
$validated['top_menu'] = [];
|
|
|
|
|
|
|
|
// Handle the images
|
|
|
|
foreach(['site_logo','email_logo'] as $key)
|
|
|
|
if (array_key_exists($key,$validated))
|
2021-07-01 23:12:34 +00:00
|
|
|
$validated[$key] = ($x=$validated[$key])->storeAs('site/'.$site->site_id,$x->getClientOriginalName(),'public');
|
2021-07-01 09:41:12 +00:00
|
|
|
|
2021-07-01 23:12:34 +00:00
|
|
|
foreach ($site->details as $oo)
|
2021-07-01 09:41:12 +00:00
|
|
|
if (array_key_exists($oo->key,$validated)) {
|
|
|
|
$oo->value = Arr::get($validated,$oo->key);
|
|
|
|
$oo->save();
|
|
|
|
|
|
|
|
unset($validated[$oo->key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Left over values to be created.
|
|
|
|
foreach ($validated as $k=>$v) {
|
2021-07-01 23:12:34 +00:00
|
|
|
$oo = new SiteDetail;
|
2021-07-01 09:41:12 +00:00
|
|
|
$oo->key = $k;
|
|
|
|
$oo->value = $v ?: '';
|
|
|
|
|
2021-07-01 23:12:34 +00:00
|
|
|
$site->details()->save($oo);
|
2021-07-01 09:41:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back()
|
|
|
|
->with('success','Settings saved');
|
|
|
|
}
|
|
|
|
|
|
|
|
return view('a.setup');
|
|
|
|
}
|
|
|
|
}
|