diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index ca5334c..716deef 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -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 * diff --git a/app/Http/Controllers/CostController.php b/app/Http/Controllers/CostController.php deleted file mode 100644 index 9b714b2..0000000 --- a/app/Http/Controllers/CostController.php +++ /dev/null @@ -1,16 +0,0 @@ -$o]); - } -} diff --git a/app/Http/Controllers/SupplierController.php b/app/Http/Controllers/SupplierController.php new file mode 100644 index 0000000..a34caac --- /dev/null +++ b/app/Http/Controllers/SupplierController.php @@ -0,0 +1,83 @@ +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); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/SuppliersController.php b/app/Http/Controllers/SuppliersController.php deleted file mode 100644 index 2ab7e02..0000000 --- a/app/Http/Controllers/SuppliersController.php +++ /dev/null @@ -1,102 +0,0 @@ -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 here'; - } - - /** - * 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) - { - // - } -} diff --git a/app/Http/Requests/SupplierAddEdit.php b/app/Http/Requests/SupplierAddEdit.php new file mode 100644 index 0000000..c1d5897 --- /dev/null +++ b/app/Http/Requests/SupplierAddEdit.php @@ -0,0 +1,44 @@ +isWholesaler(); + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + 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', + ]; + } +} \ No newline at end of file diff --git a/app/Jobs/ImportCosts.php b/app/Jobs/ImportCosts.php index 8060f5d..0136b37 100644 --- a/app/Jobs/ImportCosts.php +++ b/app/Jobs/ImportCosts.php @@ -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]); diff --git a/app/Models/Cost.php b/app/Models/Cost.php index 98bd986..97408ea 100644 --- a/app/Models/Cost.php +++ b/app/Models/Cost.php @@ -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(); + } } \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/a/supplier/details.blade.php b/resources/views/theme/backend/adminlte/a/supplier/details.blade.php deleted file mode 100644 index 65112eb..0000000 --- a/resources/views/theme/backend/adminlte/a/supplier/details.blade.php +++ /dev/null @@ -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') -
-
- @include('adminlte::widget.status') -
-
- -
-
-
- - -
-
-
- @include('a.supplier.widgets.detail') -
- -
- @include('a.supplier.widgets.products') -
- -
- @include('a.supplier.widgets.offerings') -
- -
- @include('a.supplier.widgets.connections') -
-
-
-
-
-
-@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/r/supplier/create.blade.php b/resources/views/theme/backend/adminlte/r/supplier/create.blade.php deleted file mode 100644 index 57e1a44..0000000 --- a/resources/views/theme/backend/adminlte/r/supplier/create.blade.php +++ /dev/null @@ -1,15 +0,0 @@ -@extends('layouts.auth') - -@section('htmlheader_title') - Supplier Add -@endsection - -@section('content') - -
- {{ csrf_field() }} - Name:
- -
- -@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/r/supplier/index.blade.php b/resources/views/theme/backend/adminlte/r/supplier/index.blade.php deleted file mode 100644 index 4d43e4b..0000000 --- a/resources/views/theme/backend/adminlte/r/supplier/index.blade.php +++ /dev/null @@ -1,25 +0,0 @@ -@extends('layouts.auth') - -@section('htmlheader_title') - Supplier List -@endsection - -@section('content') - - - - - - - - @foreach (\App\Models\Supplier::all() as $o) - - - - - @endforeach -
IDName
{{ $o->id }}{{ $o->name }}
- - Add new Supplier. - -@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/a/cost/home.blade.php b/resources/views/theme/backend/adminlte/supplier/cost.blade.php similarity index 99% rename from resources/views/theme/backend/adminlte/a/cost/home.blade.php rename to resources/views/theme/backend/adminlte/supplier/cost.blade.php index 970ebf9..9055da6 100644 --- a/resources/views/theme/backend/adminlte/a/cost/home.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/cost.blade.php @@ -1,3 +1,4 @@ + @extends('adminlte::layouts.app') @section('htmlheader_title') @@ -16,7 +17,7 @@ @php($charge = 0) @section('main-content')
-
+
diff --git a/resources/views/theme/backend/adminlte/supplier/details.blade.php b/resources/views/theme/backend/adminlte/supplier/details.blade.php new file mode 100644 index 0000000..bf5c00d --- /dev/null +++ b/resources/views/theme/backend/adminlte/supplier/details.blade.php @@ -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') +
+
+
+
+ +
+ +
+
+
+ @include('supplier.widget.detail') +
+ + @if($o->exists) +
+ @include('supplier.widget.products') +
+ +
+ @include('supplier.widget.offerings') +
+ +
+ @include('supplier.widget.connections') +
+ +
+ @include('supplier.widget.costs') +
+ @endif +
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/a/supplier/home.blade.php b/resources/views/theme/backend/adminlte/supplier/home.blade.php similarity index 76% rename from resources/views/theme/backend/adminlte/a/supplier/home.blade.php rename to resources/views/theme/backend/adminlte/supplier/home.blade.php index c61d72a..2735738 100644 --- a/resources/views/theme/backend/adminlte/a/supplier/home.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/home.blade.php @@ -16,7 +16,6 @@ @section('main-content')
-

Supplier Configuration

@@ -33,8 +32,12 @@ @@ -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 : ''); }); }); diff --git a/resources/views/theme/backend/adminlte/a/supplier/widgets/connections.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/connections.blade.php similarity index 100% rename from resources/views/theme/backend/adminlte/a/supplier/widgets/connections.blade.php rename to resources/views/theme/backend/adminlte/supplier/widget/connections.blade.php diff --git a/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php new file mode 100644 index 0000000..569e32d --- /dev/null +++ b/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php @@ -0,0 +1,34 @@ + +
+
+
+ + + + @error('name') + {{ $message }} + @else + Date is required. + @enderror + + Suppliers Invoice +
+
+
+ +@section('page-scripts') + +@append \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/a/supplier/widgets/detail.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/detail.blade.php similarity index 100% rename from resources/views/theme/backend/adminlte/a/supplier/widgets/detail.blade.php rename to resources/views/theme/backend/adminlte/supplier/widget/detail.blade.php diff --git a/resources/views/theme/backend/adminlte/a/supplier/widgets/offerings.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/offerings.blade.php similarity index 100% rename from resources/views/theme/backend/adminlte/a/supplier/widgets/offerings.blade.php rename to resources/views/theme/backend/adminlte/supplier/widget/offerings.blade.php diff --git a/resources/views/theme/backend/adminlte/a/supplier/widgets/products.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/products.blade.php similarity index 100% rename from resources/views/theme/backend/adminlte/a/supplier/widgets/products.blade.php rename to resources/views/theme/backend/adminlte/supplier/widget/products.blade.php diff --git a/routes/web.php b/routes/web.php index 1809711..287abb6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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