Optimising Supplier Layout and source code placement
This commit is contained in:
@@ -176,71 +176,6 @@ 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.home');
|
||||
}
|
||||
|
||||
/**
|
||||
* 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' => 'nullable|string|min:2|max:255',
|
||||
'address2' => 'nullable|string|min:2|max:255',
|
||||
'city' => 'nullable|string|min:2|max:64',
|
||||
'state' => 'nullable|string|min:2|max:32',
|
||||
'postcode' => 'nullable|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.supplier.details')
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Site setup
|
||||
*
|
||||
|
@@ -1,16 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Models\Cost;
|
||||
|
||||
class CostController extends Controller
|
||||
{
|
||||
public function home(Cost $o)
|
||||
{
|
||||
// @todo Need to add the services that are active that are not on the bill for the supplier.
|
||||
return view('a.cost.home',['o'=>$o]);
|
||||
}
|
||||
}
|
83
app/Http/Controllers/SupplierController.php
Normal file
83
app/Http/Controllers/SupplierController.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Supplier;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SuppliersController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('r/supplier/index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('r/supplier/create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// @todo Insure site index is included.
|
||||
$o = new Supplier;
|
||||
$o->name = $request->input('name');
|
||||
$o->active = 1;
|
||||
$o->account_mgr = '';
|
||||
$o->account_email = '';
|
||||
$o->email_provision = '';
|
||||
$o->email_support = '';
|
||||
$o->phone_provision = '';
|
||||
$o->phone_support = '';
|
||||
$o->save();
|
||||
|
||||
echo 'REDIRECT TO <a href="'.url('r/supplier/index').'">here</a>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\suppliers $suppliers
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(suppliers $suppliers)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\suppliers $suppliers
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(suppliers $suppliers)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\suppliers $suppliers
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, suppliers $suppliers)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\suppliers $suppliers
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(suppliers $suppliers)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
44
app/Http/Requests/SupplierAddEdit.php
Normal file
44
app/Http/Requests/SupplierAddEdit.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
/**
|
||||
* Editing Suppliers
|
||||
*/
|
||||
class SupplierAddEdit extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::user()->isWholesaler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|min:2|max:255',
|
||||
'active' => 'sometimes|accepted',
|
||||
'address1' => 'nullable|string|min:2|max:255',
|
||||
'address2' => 'nullable|string|min:2|max:255',
|
||||
'city' => 'nullable|string|min:2|max:64',
|
||||
'state' => 'nullable|string|min:2|max:32',
|
||||
'postcode' => 'nullable|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',
|
||||
];
|
||||
}
|
||||
}
|
@@ -116,8 +116,10 @@ class ImportCosts implements ShouldQueue
|
||||
// m[1] = Service, m[2] = Desc, m[3] = From Date, m[4] = To Date
|
||||
preg_match('#^([0-9]{10})\s+-\s+(.*)\(([0-9]+\s+[JFMASOND].*\s+[0-9]+)+\s+-\s+([0-9]+\s+[JFMASOND].*\s+[0-9]+)+\)$#',$fields[$x],$m);
|
||||
|
||||
if (count($m) !== 5)
|
||||
throw new \Exception(sprintf('ERROR: Description didnt parse [%s] on line [%d]',$fields[$x],$c));
|
||||
if (count($m) !== 5) {
|
||||
dump(sprintf('ERROR: Description didnt parse [%s] on line [%d]',$fields[$x],$c));
|
||||
continue;
|
||||
}
|
||||
|
||||
$cost = ($x=$this->getColumnKey('PRICETOTAL')) ? str_replace([',','$'],'',$fields[$x]) : NULL;
|
||||
$start_at = Carbon::createFromFormat('d M Y',$m[3]);
|
||||
|
@@ -15,6 +15,12 @@ class Cost extends Model
|
||||
'billed_at',
|
||||
];
|
||||
|
||||
protected $with = [
|
||||
'broadbands',
|
||||
'generics',
|
||||
'phones',
|
||||
];
|
||||
|
||||
/* RELATIONS */
|
||||
|
||||
public function broadbands()
|
||||
@@ -37,4 +43,24 @@ class Cost extends Model
|
||||
|
||||
/* ATTRIBUTES */
|
||||
|
||||
public function getTotalBroadbandAttribute(): float
|
||||
{
|
||||
return $this->broadbands->sum('base')+$this->broadbands->sum('excess');
|
||||
}
|
||||
|
||||
public function getTotalGenericAttribute(): float
|
||||
{
|
||||
return $this->generics->sum('base')+$this->generics->sum('excess');
|
||||
}
|
||||
|
||||
public function getTotalPhoneAttribute(): float
|
||||
{
|
||||
return $this->phones->sum('base')+$this->phones->sum('excess');
|
||||
}
|
||||
|
||||
public function getTotalAttribute(): float
|
||||
{
|
||||
|
||||
return $this->getTotalBroadbandAttribute()+$this->getTotalGenericAttribute()+$this->getTotalPhoneAttribute();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user