diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 9ec6a86..37aa591 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -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', diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 932779f..6d0d1c7 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -3,8 +3,18 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Leenooks\Traits\ScopeActive; class Supplier extends Model { - // -} + use ScopeActive; + + public $timestamps = FALSE; + + /* RELATIONS */ + + public function detail() + { + return $this->hasOne(SupplierDetail::class); + } +} \ No newline at end of file diff --git a/app/Models/SupplierDetail.php b/app/Models/SupplierDetail.php new file mode 100644 index 0000000..fed2446 --- /dev/null +++ b/app/Models/SupplierDetail.php @@ -0,0 +1,19 @@ +belongsTo(Supplier::class); + } +} \ No newline at end of file diff --git a/database/migrations/2021_12_17_162247_create_suppliers.php b/database/migrations/2021_12_17_162247_create_suppliers.php new file mode 100644 index 0000000..ceb7c6e --- /dev/null +++ b/database/migrations/2021_12_17_162247_create_suppliers.php @@ -0,0 +1,55 @@ +integer('id',TRUE)->unsigned(); + $table->boolean('active'); + $table->string('name')->unique(); + $table->string('address1'); + $table->string('address2')->nullable(); + $table->string('city',64); + $table->string('state',32); + $table->string('postcode',8); + }); + + Schema::create('supplier_details', function (Blueprint $table) { + $table->integer('id',TRUE)->unsigned(); + $table->timestamps(); + $table->text('notes')->nullable(); + $table->string('accounts')->nullable(); + $table->string('support')->nullable(); + $table->string('payments')->nullable(); + + $table->integer('supplier_id')->unsigned(); + $table->integer('site_id'); + + $table->unique(['supplier_id','site_id']); + + $table->foreign(['supplier_id'])->references(['id'])->on('suppliers'); + $table->foreign(['site_id'])->references(['id'])->on('sites'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('supplier_details'); + Schema::dropIfExists('suppliers'); + } +} diff --git a/public/css/fixes.css b/public/css/fixes.css index 4dd6979..9081cfb 100644 --- a/public/css/fixes.css +++ b/public/css/fixes.css @@ -82,7 +82,6 @@ table.dataTable thead .sorting { /* Fix selected item is positioned correctly */ span.select2-selection.select2-selection--single > span.select2-selection__rendered { - margin-top: -9px; margin-left: -9px; } @@ -90,3 +89,19 @@ span.select2-selection.select2-selection--single > span.select2-selection__rende .select2-selection.select2-selection--single { height: calc(2.25rem + 2px) !important; } + +/* Fix dark background nav pills */ +.card-header.bg-dark .nav-pills .nav-link.active, .nav-pills .show>.nav-link { + background-color: #ffffff; + color: #343a40; +} + +.card-header.bg-dark .nav-pills .nav-link:hover { + background-color: #6c757d; + color: #ffffff; +} + +.card-header.bg-dark .nav-pills .nav-link:not(.active):hover { + background-color: #6c757d; + color: #ffffff; +} \ No newline at end of file diff --git a/public/plugin/select2/fix-autofocus.js b/public/plugin/select2/fix-autofocus.js new file mode 100644 index 0000000..94b965c --- /dev/null +++ b/public/plugin/select2/fix-autofocus.js @@ -0,0 +1,8 @@ +$(document).on('select2:open',(event) => { + const searchField = document.querySelector( + `.select2-search__field[aria-controls="select2-${event.target.getAttribute('data-select2-id')}-results"]`, + ); + if (searchField) { + searchField.focus(); + } +}); diff --git a/resources/views/theme/backend/adminlte/a/setup.blade.php b/resources/views/theme/backend/adminlte/a/setup.blade.php index b36949b..faf4049 100644 --- a/resources/views/theme/backend/adminlte/a/setup.blade.php +++ b/resources/views/theme/backend/adminlte/a/setup.blade.php @@ -99,7 +99,7 @@
- + @error('site_city') @@ -115,7 +115,7 @@
- + @error('site_state') @@ -127,7 +127,7 @@
- + @error('site_postcode') diff --git a/resources/views/theme/backend/adminlte/a/supplier.blade.php b/resources/views/theme/backend/adminlte/a/supplier.blade.php new file mode 100644 index 0000000..4a2fc54 --- /dev/null +++ b/resources/views/theme/backend/adminlte/a/supplier.blade.php @@ -0,0 +1,70 @@ +@extends('adminlte::layouts.app') + +@section('htmlheader_title') + Supplier +@endsection +@section('page_title') + Supplier +@endsection + +@section('contentheader_title') + Supplier +@endsection +@section('contentheader_description') +@endsection + +@section('main-content') +
+
+ +
+
+

Supplier Configuration

+
+ +
+
+ @csrf + +
+
+
+ + + + @error('name') + {{ $message }} + @else + Supplier Name is required. + @enderror + + Suppliers Name +
+
+
+
+
+
+
+
+@endsection + +@section('page-scripts') + @css(select2) + @js(select2,autofocus) + + +@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/a/supplierdetails.blade.php b/resources/views/theme/backend/adminlte/a/supplierdetails.blade.php new file mode 100644 index 0000000..0a64a95 --- /dev/null +++ b/resources/views/theme/backend/adminlte/a/supplierdetails.blade.php @@ -0,0 +1,225 @@ +@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') +
+
+ +
+
+
+
+ +
+ +
+
+
+

Supplier Details

+
+ @if(session()->has('success')) + {{ session()->get('success') }} + @endif + +
+ @csrf + +
+
+
+ +
+
+ + + + @error('name') + {{ $message }} + @else + Supplier Name required. + @enderror + +
+
+ + +
+
+
+ active) ? 'checked' : '' }}> + +
+
+
+
+ +
+ +
+
+ + + + + @error('address1') + {{ $message }} + @else + Atleast 1 address line required. + @enderror + +
+
+
+ +
+ +
+
+ + + + @error('city') + {{ $message }} + @else + City is required. + @enderror + +
+
+
+ +
+ +
+
+ + + + @error('state') + {{ $message }} + @else + State is required. + @enderror + +
+
+ + +
+
+ + + + @error('postcode') + {{ $message }} + @else + Postcode is required. + @enderror + +
+
+
+
+ +
+
+ +
+
+ + + + @error('supplier_details.accounts') + {{ $message }} + @enderror + +
+
+
+ +
+ +
+
+ + + + @error('supplier_details.support') + {{ $message }} + @enderror + +
+
+
+ +
+ +
+
+ + + + @error('supplier_details.payments') + {{ $message }} + @enderror + +
+
+
+
+
+ +
+ +
+
+ + + Notes. + + @error('supplier_details.notes') + {{ $message }} + @enderror + +
+
+
+ +
+ +
+ Cancel + @can('wholesaler') + + @endcan +
+
+
+
+
+ Products. +
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/u/service/home.blade.php b/resources/views/theme/backend/adminlte/u/service/home.blade.php index 966f7c8..1384fe8 100644 --- a/resources/views/theme/backend/adminlte/u/service/home.blade.php +++ b/resources/views/theme/backend/adminlte/u/service/home.blade.php @@ -101,23 +101,4 @@
-@endsection - -@section('page-scripts') - -@append \ No newline at end of file +@endsection \ No newline at end of file diff --git a/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php b/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php index 7044bee..a2429ec 100644 --- a/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php +++ b/resources/views/vendor/adminlte/layouts/partials/sidebarmenu.blade.php @@ -77,6 +77,12 @@ + +