From 2627cea3b5fe8206b261b8f42cccc05623aea320 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 24 Aug 2024 17:37:55 +1000 Subject: [PATCH] Update supplier/cost with components --- app/Http/Controllers/SupplierController.php | 23 +--- app/Jobs/ImportCosts.php | 4 +- app/Models/Cost/Type.php | 6 +- app/Providers/AppServiceProvider.php | 3 +- .../adminlte/supplier/cost/add.blade.php | 51 ++++---- .../adminlte/supplier/cost/view.blade.php | 113 +++++++----------- .../adminlte/supplier/widget/costs.blade.php | 25 +--- routes/web.php | 10 +- 8 files changed, 89 insertions(+), 146 deletions(-) diff --git a/app/Http/Controllers/SupplierController.php b/app/Http/Controllers/SupplierController.php index 27f1cd7..02b2c18 100644 --- a/app/Http/Controllers/SupplierController.php +++ b/app/Http/Controllers/SupplierController.php @@ -8,7 +8,7 @@ use Illuminate\Support\Arr; use App\Http\Requests\{SupplierAddEdit,SupplierProductAddEdit}; use App\Jobs\ImportCosts; -use App\Models\{Cost,Supplier,SupplierDetail}; +use App\Models\{Supplier,SupplierDetail}; class SupplierController extends Controller { @@ -24,7 +24,7 @@ class SupplierController extends Controller foreach (Arr::except($request->validated(),['supplier_details','api_key','api_secret','submit']) as $key => $item) $o->{$key} = $item; - $o->active = (bool)$request->active; + $o->active = (bool)$request->validated('active'); try { $o->save(); @@ -50,25 +50,6 @@ class SupplierController extends Controller ->with('success','Supplier Saved'); } - /** - * 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('theme.backend.adminlte.supplier.cost.view') - ->with('o',$o); - } - - public function cost_add(Supplier $o) - { - return view('theme.backend.adminlte.supplier.cost.add') - ->with('o',$o); - } - public function cost_submit(Request $request,Supplier $o) { $request->validate([ diff --git a/app/Jobs/ImportCosts.php b/app/Jobs/ImportCosts.php index 56e3ef3..755c2cd 100644 --- a/app/Jobs/ImportCosts.php +++ b/app/Jobs/ImportCosts.php @@ -126,7 +126,7 @@ class ImportCosts implements ShouldQueue $cost = ($x=$this->getColumnKey('PRICETOTAL')) ? str_replace([',','$'],'',$fields[$x]) : NULL; $start_at = Carbon::createFromFormat('d M Y',$m[3]); $stop_at = Carbon::createFromFormat('d M Y',$m[4]); - $so = Service::search($m[1])->active()->with(['type','product.type.supplied'])->single(); + $so = Service::search($m[1])->ServiceActive()->with(['type','product.type.supplied'])->single(); if ($so) { // r[1] = Monthly Charge or Extra Charge,r[2] = "On Plan", r[3] = Plan Info @@ -197,7 +197,7 @@ class ImportCosts implements ShouldQueue } } else { - dump(['line'=>$line,'sql'=>Service::search($m[1])->active()->with(['type','product.type.supplied'])->toSql()]); + dump(['line'=>$line,'sql'=>Service::search($m[1])->ServiceActive()->with(['type','product.type.supplied'])->toSql()]); $to = Cost\Generic::where('site_id',$this->co->site_id) ->where('cost_id',$this->co->id) diff --git a/app/Models/Cost/Type.php b/app/Models/Cost/Type.php index bc82271..b1d705b 100644 --- a/app/Models/Cost/Type.php +++ b/app/Models/Cost/Type.php @@ -8,9 +8,9 @@ abstract class Type extends Model { public $timestamps = FALSE; - protected $dates = [ - 'start_at', - 'end_at', + protected $casts = [ + 'start_at' => 'datetime:Y-m-d', + 'end_at' => 'datetime:Y-m-d', ]; /* RELATIONS */ diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 40a4cbf..a7697e8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Route; use Illuminate\Support\ServiceProvider; use Intuit\Traits\IntuitSocialite; -use App\Models\{Checkout,Payment,Product,Service,Supplier}; +use App\Models\{Checkout,Cost,Payment,Product,Service,Supplier}; class AppServiceProvider extends ServiceProvider { @@ -36,6 +36,7 @@ class AppServiceProvider extends ServiceProvider $this->bootIntuitSocialite(); Route::model('co',Checkout::class); + Route::model('cso',Cost::class); Route::model('po',Payment::class); Route::model('pdo',Product::class); Route::model('so',Service::class); diff --git a/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php b/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php index 704c21d..ffe5f19 100644 --- a/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php @@ -1,4 +1,6 @@ - +@use(Carbon\Carbon) + + @extends('adminlte::layouts.app') @section('htmlheader_title') @@ -9,47 +11,44 @@ Add Cost @endsection @section('contentheader_description') - {{ $o->name }} + {{ $spo->name }} @endsection @section('main-content')
-
+
-
-
- @include('adminlte::widget.success') +
+
+
+

{{ $spo->name }}

+
+
+ +
+
+ + @csrf
-
- @include('adminlte::widget.form_date',[ - 'label'=>'Invoice Date', - 'icon'=>'fas fa-calendar', - 'id'=>'billed_at', - 'old'=>'billed_at', - 'name'=>'billed_at', - 'value'=>\Carbon\Carbon::now()->format('Y-m-d'), - ]) +
+
-
- @include('adminlte::widget.form_file',[ - 'label'=>'Invoice File', - 'icon'=>'fas fa-file', - 'id'=>'file', - 'name'=>'file', - ]) +
+
-
- @can('wholesaler') - - @endcan +
+
+ + Save +
diff --git a/resources/views/theme/backend/adminlte/supplier/cost/view.blade.php b/resources/views/theme/backend/adminlte/supplier/cost/view.blade.php index 9055da6..96e4c1f 100644 --- a/resources/views/theme/backend/adminlte/supplier/cost/view.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/cost/view.blade.php @@ -1,18 +1,17 @@ - + @extends('adminlte::layouts.app') @section('htmlheader_title') - Cost #{{ $o->id }} + Cost #{{ $cso->id }} @endsection @section('contentheader_title') - Cost #{{ $o->id }} + Cost #{{ $cso->id }} @endsection @section('contentheader_description') @endsection - @php($cost = 0) @php($charge = 0) @section('main-content') @@ -39,96 +38,57 @@ - - Broadband -   -   - {{ $o->broadbands->min('start_at')->format('Y-m-d') }} - {{ $o->broadbands->max('end_at')->format('Y-m-d') }} - ${{ number_format($a=$o->broadbands->sum('base'),2) }} - ${{ number_format($o->broadbands->sum('excess'),2) }} - ${{ number_format($x=$o->broadbands->sum('cost'),2) }} - ${{ number_format($b=$o->broadbands->sum('service.billing_monthly_price'),2) }} - ${{ number_format($b-$a,2) }} - - @php($cost += $x) - @php($charge += $b) - - @foreach ($o->broadbands->groupBy('service_broadband_id') as $oo) + @foreach ($cso->broadbands->groupBy('service_broadband_id') as $oo) -   + Broadband {{ $oo->first()->service->name }} {{ $oo->first()->service->active ? 'YES' : 'NO' }} {{ $oo->min('start_at')->format('Y-m-d') }} {{ $oo->max('end_at')->format('Y-m-d') }} ${{ number_format($a=$oo->sum('base'),2) }} ${{ number_format($oo->sum('excess'),2) }} - ${{ number_format($oo->sum('cost'),2) }} - ${{ number_format($b=$oo->first()->service->billing_monthly_price,2) }} + ${{ number_format($x=$oo->sum('cost'),2) }} + ${{ number_format($b=$oo->first()->service->billing_charge_normalised,2) }} ${{ number_format($b-$a,2) }} + @php($cost += $x) + @php($charge += $b) @endforeach - - Phone -   -   - {{ $o->phones->min('start_at')->format('Y-m-d') }} - {{ $o->phones->max('end_at')->format('Y-m-d') }} - ${{ number_format($a=$o->phones->sum('base'),2) }} - ${{ number_format($o->phones->sum('excess'),2) }} - ${{ number_format($x=$o->phones->sum('cost'),2) }} - ${{ number_format($b=$o->phones->sum('service.billing_monthly_price'),2) }} - ${{ number_format($b-$a,2) }} - - @php($cost += $x) - @php($charge += $b) - - @foreach ($o->phones->groupBy('service_phone_id') as $oo) + @foreach ($cso->phones->groupBy('service_phone_id') as $oo) -   + Phone {{ $oo->first()->service->name }} {{ $oo->first()->service->active ? 'YES' : 'NO' }} {{ $oo->min('start_at')->format('Y-m-d') }} {{ $oo->max('end_at')->format('Y-m-d') }} ${{ number_format($a=$oo->sum('base'),2) }} ${{ number_format($oo->sum('excess'),2) }} - ${{ number_format($oo->sum('cost'),2) }} - ${{ number_format($b=$oo->first()->service->billing_monthly_price,2) }} + ${{ number_format($x=$oo->sum('cost'),2) }} + ${{ number_format($b=$oo->first()->service->billing_charge_normalised,2) }} ${{ number_format($b-$a,2) }} + @php($cost += $x) + @php($charge += $b) @endforeach - - Generic -   -   - {{ ($x=$o->generics)->count() ? $x->min('start_at')->format('Y-m-d') : '-' }} - {{ $x->count() ? $x->max('end_at')->format('Y-m-d') : '-' }} - ${{ number_format($a=$o->generics->sum('base'),2) }} - ${{ number_format($o->generics->sum('excess'),2) }} - ${{ number_format($x=$o->generics->sum('cost'),2) }} - $0.00 - ${{ number_format(0-$a,2) }} - - - @php($cost += $x) - - @foreach ($o->generics->groupBy('service_generic_id') as $oo) + @foreach ($cso->generics->groupBy('service_generic_id') as $oo) -   - {{ ($x=$oo->first()->service) ? $x->name : '-' }} - {{ $x ? ($x->active ? 'YES' : 'NO') : '-' }} + Generic + {{ ($xx=$oo->first()->service) ? $xx->name : '-' }} + {{ $xx ? ($xx->active ? 'YES' : 'NO') : '-' }} {{ $oo->min('start_at')->format('Y-m-d') }} {{ $oo->max('end_at')->format('Y-m-d') }} ${{ number_format($a=$oo->sum('base'),2) }} ${{ number_format($oo->sum('excess'),2) }} - ${{ number_format($oo->sum('cost'),2) }} - ${{ number_format($b=$x ? $x->billing_monthly_price : 0,2) }} + ${{ number_format($x=$oo->sum('cost'),2) }} + ${{ number_format($b=($xx ? $xx->billing_monthly_price : 0),2) }} ${{ number_format($b-$a,2) }} + + @php($cost += $x) @endforeach @@ -147,18 +107,33 @@
@endsection -@section('page-scripts') - @css(datatables,bootstrap4|rowgroup) - @js(datatables,bootstrap4|rowgroup) +@pa(datatables,rowgroup) +@section('page-scripts') diff --git a/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php b/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php index 9e18eac..f319b84 100644 --- a/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php @@ -1,24 +1,9 @@ - + +@use(App\Models\Cost) +
-
- - - - @error('name') - {{ $message }} - @else - Date is required. - @enderror - - Suppliers Invoice -
+
@@ -27,7 +12,7 @@ $(document).ready(function() { $('#cost_id') .on('change',function(item) { - window.location.href = '{{ url('a/supplier/cost') }}/'+(item.target.value ? item.target.value : 'new/'+{{ $o->id }}); + window.location.href = '{{ url('a/supplier/cost') }}/'+(item.target.value !== 'new' ? item.target.value : 'new/'+{{ $spo->id }}); }); }); diff --git a/routes/web.php b/routes/web.php index d447243..c4f1ced 100644 --- a/routes/web.php +++ b/routes/web.php @@ -102,10 +102,12 @@ Route::group(['middleware'=>['auth','role:wholesaler'],'prefix'=>'a'],function() // Supplier Setup Route::view('supplier','theme.backend.adminlte.supplier.home'); - Route::get('supplier/cost/new/{o}',[SupplierController::class,'cost_add']); - Route::post('supplier/cost/new/{o}',[SupplierController::class,'cost_submit']); - Route::get('supplier/cost/{o}',[SupplierController::class,'cost']) - ->where('o','[0-9]+'); + Route::view('supplier/cost/new/{spo}','theme.backend.adminlte.supplier.cost.add') + ->where('spo','[0-9]+'); + Route::post('supplier/cost/new/{spo}',[SupplierController::class,'cost_submit']) + ->where('spo','[0-9]+'); + Route::view('supplier/cost/{cso}','theme.backend.adminlte.supplier.cost.view') + ->where('cso','[0-9]+'); Route::view('supplier/details/{spo}','theme.backend.adminlte.supplier.details') ->where('spo','[0-9]+'); Route::post('supplier/details/{o?}',[SupplierController::class,'addedit'])