Created Suppliers
This commit is contained in:
@@ -6,15 +6,22 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use App\Models\{Account,Charge,InvoiceItem,Payment,PaymentItem,Service,SiteDetail};
|
||||
use App\Models\{Account,Charge,InvoiceItem,Payment,PaymentItem,Service,SiteDetail,Supplier,SupplierDetail};
|
||||
|
||||
/**
|
||||
* The AdminController governs all routes that are prefixed with 'a/'.
|
||||
*
|
||||
* This is everything about the configuration of the application as a whole, or administration of a site.
|
||||
*/
|
||||
class AdminController extends Controller
|
||||
{
|
||||
// @todo Move to reseller
|
||||
public function service(Service $o)
|
||||
{
|
||||
return View('a.service',['o'=>$o]);
|
||||
}
|
||||
|
||||
// @todo Move to reseller
|
||||
public function charge_addedit(Request $request,Charge $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
@@ -47,6 +54,7 @@ class AdminController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
// @todo Move to reseller
|
||||
public function charge_pending_account(Request $request,Account $o)
|
||||
{
|
||||
return view('a.charge.widgets.pending')
|
||||
@@ -58,6 +66,7 @@ class AdminController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
// @todo Move to reseller
|
||||
public function charge_unprocessed()
|
||||
{
|
||||
return view('a.charge.unprocessed');
|
||||
@@ -70,6 +79,7 @@ class AdminController extends Controller
|
||||
* @param Payment $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
// @todo Move to reseller
|
||||
public function pay_addedit(Request $request,Payment $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
@@ -131,6 +141,7 @@ class AdminController extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
// @todo Move to reseller
|
||||
public function pay_unapplied()
|
||||
{
|
||||
return view('a.payment.unapplied');
|
||||
@@ -143,6 +154,7 @@ class AdminController extends Controller
|
||||
* @param Account $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
// @todo Move to reseller
|
||||
public function pay_invoices(Request $request,Account $o)
|
||||
{
|
||||
return view('a.payment.widgets.invoices')
|
||||
@@ -150,6 +162,71 @@ class AdminController extends Controller
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site up site wide suppliers, or a site's supplier details
|
||||
*
|
||||
* @note This method is protected by the routes
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function supplier()
|
||||
{
|
||||
return view('a.supplier');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a suppliers details
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Supplier $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function supplier_addedit(Request $request,Supplier $o)
|
||||
{
|
||||
if ($request->post()) {
|
||||
$validation = $request->validate([
|
||||
'name' => 'required|string|min:2|max:255',
|
||||
'active' => 'sometimes|accepted',
|
||||
'address1' => 'required|string|min:2|max:255',
|
||||
'address2' => 'nullable|string|min:2|max:255',
|
||||
'city' => 'required|string|min:2|max:64',
|
||||
'state' => 'required|string|min:2|max:32',
|
||||
'postcode' => 'required|string|min:2|max:8',
|
||||
'supplier_details.notes' => 'nullable|string|min:3',
|
||||
'supplier_details.accounts' => 'nullable|email',
|
||||
'supplier_details.support' => 'nullable|email',
|
||||
'supplier_details.payments' => 'nullable|string|min:3',
|
||||
]);
|
||||
|
||||
foreach (collect($validation)->except('supplier_details') as $key => $item)
|
||||
$o->{$key} = $item;
|
||||
|
||||
$o->active = (bool)$request->active;
|
||||
|
||||
try {
|
||||
$o->save();
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->back()->withErrors($e->getMessage())->withInput();
|
||||
}
|
||||
|
||||
$o->load(['detail']);
|
||||
$oo = $o->detail ?: new SupplierDetail;
|
||||
|
||||
foreach (collect($validation)->get('supplier_details',[]) as $key => $item)
|
||||
$oo->{$key} = $item;
|
||||
|
||||
$o->detail()->save($oo);
|
||||
|
||||
return redirect()->back()
|
||||
->with('success','Supplier saved');
|
||||
}
|
||||
|
||||
if (! $o->exists && $request->name)
|
||||
$o = Supplier::where('name',$request->name)->with(['details'])->firstOrNew();
|
||||
|
||||
return view('a.supplierdetails')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site setup
|
||||
*
|
||||
@@ -161,13 +238,13 @@ class AdminController extends Controller
|
||||
{
|
||||
if ($request->post()) {
|
||||
$validated = $request->validate([
|
||||
'site_name' => 'required|string|max:255',
|
||||
'site_name' => 'required|string|min:2|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_address1' => 'required|string|min:2|max:255',
|
||||
'site_address2' => 'nullable|string|min:2|max:255',
|
||||
'site_city' => 'required|string|min:2|max:64',
|
||||
'site_state' => 'required|string|min:2|max:32',
|
||||
'site_postcode' => 'required|string|min:2|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',
|
||||
|
Reference in New Issue
Block a user