Optimising Supplier Layout and source code placement

This commit is contained in:
Deon George 2022-06-28 23:20:56 +10:00
parent 464407e7ee
commit fb416306e7
19 changed files with 269 additions and 301 deletions

View File

@ -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
*

View File

@ -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]);
}
}

View 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);
}
}

View File

@ -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)
{
//
}
}

View 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',
];
}
}

View File

@ -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]);

View File

@ -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();
}
}

View File

@ -1,57 +0,0 @@
@extends('adminlte::layouts.app')
@section('htmlheader_title')
{{ $o->name ?: 'New Supplier' }}
@endsection
@section('page_title')
{{ $o->name ?: 'New Supplier' }}
@endsection
@section('contentheader_title')
{{ $o->name ?: 'New Supplier' }}
@endsection
@section('contentheader_description')
@endsection
@section('main-content')
<div class="row">
<div class="col-12">
@include('adminlte::widget.status')
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header bg-dark d-flex p-0">
<ul class="nav nav-pills w-100 p-2">
<li class="nav-item"><a class="nav-link active" href="#details" data-toggle="tab">Detail</a></li>
<li class="nav-item"><a class="nav-link" href="#products" data-toggle="tab">Products</a></li>
<li class="nav-item"><a class="nav-link" href="#offerings" data-toggle="tab">Offerings</a></li>
<li class="nav-item"><a class="nav-link" href="#connections" data-toggle="tab">Connections</a></li>
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane fade active show" id="details" role="tabpanel">
@include('a.supplier.widgets.detail')
</div>
<div class="tab-pane fade" id="products" role="tabpanel">
@include('a.supplier.widgets.products')
</div>
<div class="tab-pane fade" id="offerings" role="tabpanel">
@include('a.supplier.widgets.offerings')
</div>
<div class="tab-pane fade" id="connections" role="tabpanel">
@include('a.supplier.widgets.connections')
</div>
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -1,15 +0,0 @@
@extends('layouts.auth')
@section('htmlheader_title')
Supplier Add
@endsection
@section('content')
<body>
<form method="POST" action="/r/supplier/store">
{{ csrf_field() }}
Name: <input name="name" > <br>
<button>Submit</button>
</form>
</body>
@endsection

View File

@ -1,25 +0,0 @@
@extends('layouts.auth')
@section('htmlheader_title')
Supplier List
@endsection
@section('content')
<body>
<table>
<tr>
<th>ID</th>
<th>Name</th>
</tr>
@foreach (\App\Models\Supplier::all() as $o)
<tr>
<td>{{ $o->id }}</td>
<td>{{ $o->name }}</td>
</tr>
@endforeach
</table>
Add new <a href="{{ url('r/supplier/create') }}">Supplier</a>.
</body>
@endsection

View File

@ -1,3 +1,4 @@
<!-- $o = Cost::class -->
@extends('adminlte::layouts.app')
@section('htmlheader_title')
@ -16,7 +17,7 @@
@php($charge = 0)
@section('main-content')
<div class="row">
<div class="col-6">
<div class="col-12">
<div class="card card-dark">
<div class="card-body">
<table class="table table-striped" id="table">

View File

@ -0,0 +1,61 @@
@extends('adminlte::layouts.app')
@section('htmlheader_title')
{{ $o->name ?: 'New Supplier' }}
@endsection
@section('page_title')
{{ $o->name ?: 'New Supplier' }}
@endsection
@section('contentheader_title')
{{ $o->name ?: 'New Supplier' }}
@endsection
@section('contentheader_description')
@include('adminlte::widget.status')
@endsection
@section('main-content')
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header bg-dark d-flex p-0">
<ul class="nav nav-pills w-100 p-2">
<li class="nav-item"><a class="nav-link active" href="#details" data-toggle="tab">Detail</a></li>
@if($o->exists)
<li class="nav-item"><a class="nav-link" href="#products" data-toggle="tab">Products</a></li>
<li class="nav-item"><a class="nav-link" href="#offerings" data-toggle="tab">Offerings</a></li>
<li class="nav-item"><a class="nav-link" href="#connections" data-toggle="tab">Connections</a></li>
<li class="nav-item"><a class="nav-link" href="#costs" data-toggle="tab">Costs</a></li>
@endif
</ul>
</div>
<div class="card-body">
<div class="tab-content">
<div class="tab-pane fade active show" id="details" role="tabpanel">
@include('supplier.widget.detail')
</div>
@if($o->exists)
<div class="tab-pane fade" id="products" role="tabpanel">
@include('supplier.widget.products')
</div>
<div class="tab-pane fade" id="offerings" role="tabpanel">
@include('supplier.widget.offerings')
</div>
<div class="tab-pane fade" id="connections" role="tabpanel">
@include('supplier.widget.connections')
</div>
<div class="tab-pane fade" id="costs" role="tabpanel">
@include('supplier.widget.costs')
</div>
@endif
</div>
</div>
</div>
</div>
</div>
@endsection

View File

@ -16,7 +16,6 @@
@section('main-content')
<div class="row">
<div class="col-12">
<div class="card card-dark">
<div class="card-header">
<h1 class="card-title">Supplier Configuration</h1>
@ -33,8 +32,12 @@
<select class="form-control form-control-border" id="name" name="supplier_id">
<option value=""></option>
<option value="">Add New</option>
@foreach(\App\Models\Supplier::orderBy('name')->get() as $o)
<option value="{{ $o->id }}">{{ $o->name }}</option>
@foreach(\App\Models\Supplier::orderBy('active','DESC')->orderBy('name')->get()->groupBy('active') as $o)
<optgroup label="{{ $o->first()->active ? 'Active' : 'Not Active' }}">
@foreach($o as $oo)
<option value="{{ $oo->id }}">{{ $oo->name }}</option>
@endforeach
</optgroup>
@endforeach
</select>
<span class="invalid-feedback" role="alert">
@ -63,7 +66,7 @@
$(document).ready(function() {
$('#name').select2()
.on('change',function(item) {
window.location.href = '{{ url('a/supplier/details') }}/'+item.target.value;
window.location.href = '{{ url('a/supplier/details') }}'+(item.target.value ? '/'+item.target.value : '');
});
});
</script>

View File

@ -0,0 +1,34 @@
<!-- $o = Supplier::class -->
<div class="row">
<div class="col-4">
<div class="form-group has-validation">
<label for="cost_id">Supplier Invoice</label>
<select class="form-control form-control-border" id="cost_id" name="cost_id">
<option value=""></option>
<option value="">Add New</option>
@foreach(\App\Models\Cost::orderBy('billed_at','DESC')->get() as $oo)
<option value="{{ $oo->id }}">{{ $oo->billed_at->format('Y-m-d') }}: ${{ number_format($oo->total,2) }}</option>
@endforeach
</select>
<span class="invalid-feedback" role="alert">
@error('name')
{{ $message }}
@else
Date is required.
@enderror
</span>
<span class="input-helper">Suppliers Invoice</span>
</div>
</div>
</div>
@section('page-scripts')
<script type="text/javascript">
$(document).ready(function() {
$('#cost_id')
.on('change',function(item) {
window.location.href = '{{ url('a/supplier/cost') }}'+(item.target.value ? '/'+item.target.value : '');
});
});
</script>
@append

View File

@ -4,7 +4,6 @@ use Leenooks\Controllers\SwitchUserController;
use App\Http\Controllers\{AdminController,
Auth\LoginController,
Auth\SocialLoginController,
CostController,
CheckoutController,
HomeController,
MediaController,
@ -13,6 +12,7 @@ use App\Http\Controllers\{AdminController,
ProductController,
SearchController,
ServiceController,
SupplierController,
WelcomeController};
/*
@ -65,16 +65,15 @@ Route::group(['middleware'=>['theme:adminlte-be','auth','role:wholesaler'],'pref
->where('o','[0-9]+');
// Supplier Setup
// @todo Move to Supplier Controller
Route::match(['get'],'supplier',[AdminController::class,'supplier']);
Route::match(['get','post'],'supplier/details/{o?}',[AdminController::class,'supplier_addedit'])
Route::get('supplier',[SupplierController::class,'admin_home']);
Route::get('supplier/details/{o?}',[SupplierController::class,'view'])
->where('o','[0-9]+');
Route::post('supplier/details/{o?}',[SupplierController::class,'addedit'])
->where('o','[0-9]+');
Route::get('supplier/cost/{o}',[SupplierController::class,'cost'])
->where('o','[0-9]+');
//Route::get('report/products','Wholesale\ReportController@products');
// Supplier Costs - @todo Move to supplier/cost route
Route::get('cost/{o}',[CostController::class,'home'])
->where('o','[0-9]+');
// Charges - @todo This should probably go to resellers
Route::match(['get','post'],'charge/addedit/{o?}',[AdminController::class,'charge_addedit']);
Route::get('charge/unprocessed',[AdminController::class,'charge_unprocessed']);
@ -116,11 +115,6 @@ Route::group(['middleware'=>['theme:adminlte-be','auth','role:reseller'],'prefix
// Reseller API calls
Route::post('service_change_charges/{o}',[ServiceController::class,'service_change_charges_display'])
->where('o','[0-9]+');
//@deprecated
// Route::get('supplier/index','SuppliersController@index');
// Route::get('supplier/create','SuppliersController@create');
// Route::post('supplier/store','SuppliersController@store');
});
// Our User Routes