83 lines
2.1 KiB
PHP
83 lines
2.1 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Http\Requests\SupplierAddEdit;
|
||
|
use App\Models\{Cost,Supplier,SupplierDetail};
|
||
|
|
||
|
class SupplierController extends Controller
|
||
|
{
|
||
|
/**
|
||
|
* Update a suppliers details
|
||
|
*
|
||
|
* @param SupplierAddEdit $request
|
||
|
* @param Supplier $o
|
||
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||
|
*/
|
||
|
public function addedit(SupplierAddEdit $request,Supplier $o)
|
||
|
{
|
||
|
$this->middleware(['auth','wholesaler']);
|
||
|
|
||
|
foreach ($request->except(['_token','supplier_details','submit']) 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 ($request->get('supplier_details',[]) as $key => $item)
|
||
|
$oo->{$key} = $item;
|
||
|
|
||
|
$o->detail()->save($oo);
|
||
|
|
||
|
return redirect()->back()
|
||
|
->with('success','Supplier saved');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 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 admin_home()
|
||
|
{
|
||
|
$this->middleware(['auth','wholesaler']);
|
||
|
|
||
|
return view('supplier.home');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the suppliers invoice
|
||
|
*
|
||
|
* @param Cost $o
|
||
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||
|
*/
|
||
|
public function cost(Cost $o)
|
||
|
{
|
||
|
// @todo Need to add the services that are active that are not on the bill for the supplier.
|
||
|
return view('supplier.cost',['o'=>$o]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* View a supplier.
|
||
|
*
|
||
|
* @param Supplier|null $o
|
||
|
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||
|
*/
|
||
|
public function view(?Supplier $o)
|
||
|
{
|
||
|
$this->middleware(['auth','wholesaler']);
|
||
|
|
||
|
return view('supplier.details')
|
||
|
->with('o',$o);
|
||
|
}
|
||
|
}
|