diff --git a/app/Console/Commands/ImportCosts.php b/app/Console/Commands/ImportCosts.php index 43f40bd..4afd986 100644 --- a/app/Console/Commands/ImportCosts.php +++ b/app/Console/Commands/ImportCosts.php @@ -31,6 +31,9 @@ class ImportCosts extends Command */ public function handle() { + if (! str_starts_with($this->argument('file'),'storage/app/')) + throw new \Exception('Filename must start with storage/app/'); + Job::dispatchSync( Site::findOrFail($this->argument('siteid')), Supplier::where('name',$this->argument('supplier'))->singleOrFail(), diff --git a/app/Http/Controllers/SupplierController.php b/app/Http/Controllers/SupplierController.php index 469cb18..67b549d 100644 --- a/app/Http/Controllers/SupplierController.php +++ b/app/Http/Controllers/SupplierController.php @@ -2,9 +2,13 @@ namespace App\Http\Controllers; +use Carbon\Carbon; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Storage; + use App\Http\Requests\{SupplierAddEdit,SupplierProductAddEdit}; use App\Models\{Cost,Supplier,SupplierDetail}; +use App\Jobs\ImportCosts; class SupplierController extends Controller { @@ -69,7 +73,31 @@ class SupplierController extends Controller 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]); + return view('supplier.cost.view',['o'=>$o]); + } + + public function cost_add(Supplier $o) + { + return view('supplier.cost.add',['o'=>$o]); + } + + public function cost_submit(Request $request,Supplier $o) + { + $request->validate([ + 'file' => 'required|filled', + 'billed_at' => 'required|date', + ]); + + $filename = $request->file('file')->store('cost_import'); + + ImportCosts::dispatch( + config('site'), + $o, + Carbon::create($request->billed_at), + $filename, + )->onQueue('low'); + + return redirect()->back()->with('success','File uploaded'); } /** diff --git a/app/Jobs/ImportCosts.php b/app/Jobs/ImportCosts.php index de12645..d1fd70e 100644 --- a/app/Jobs/ImportCosts.php +++ b/app/Jobs/ImportCosts.php @@ -22,6 +22,7 @@ class ImportCosts implements ShouldQueue private const LOGKEY = 'JIC'; private Cost $co; + private Site $site; private string $file; protected Collection $columns; @@ -33,7 +34,7 @@ class ImportCosts implements ShouldQueue public function __construct(Site $site,Supplier $so,Carbon $invoice_date,string $file) { $this->file = $file; - Config::set('site',$site); + $this->site = $site; $this->co = Cost::where('site_id',$site->site_id) ->where('supplier_id',$so->id) @@ -72,9 +73,10 @@ class ImportCosts implements ShouldQueue */ public function handle() { + Config::set('site',$this->site); $skip = 7; // @todo to be stored in supplier config - $file = fopen($this->file,'r'); + $file = fopen('storage/app/'.$this->file,'r'); $haveHeader = FALSE; $c = 0; diff --git a/composer.json b/composer.json index 2cf3624..ef578d9 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "laravel/ui": "^3.2", "leenooks/dreamscape": "^0.1.0", "leenooks/intuit": "^0.1.0", - "leenooks/laravel": "^9.2.3", + "leenooks/laravel": "^9.2.6", "leenooks/laravel-theme": "^v2.0.18", "nunomaduro/laravel-console-summary": "^1.8", "paypal/paypal-checkout-sdk": "^1.0", diff --git a/composer.lock b/composer.lock index f724c2b..84199bd 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d82522975cd8f5a5e902d49a94527919", + "content-hash": "1f7ec4f69feb761c20af44b8efb2b2b7", "packages": [ { "name": "asm89/stack-cors", @@ -3411,11 +3411,11 @@ }, { "name": "leenooks/laravel", - "version": "9.2.5", + "version": "9.2.6", "source": { "type": "git", "url": "https://dev.leenooks.net/leenooks/laravel", - "reference": "d494400e7eae16626016c6165acf89c18333ff1b" + "reference": "e3ebef90d94e8f04dfeafd1cff3607204bd5e989" }, "require": { "creativeorange/gravatar": "^1.0", @@ -3454,7 +3454,7 @@ "laravel", "leenooks" ], - "time": "2022-08-05T14:19:20+00:00" + "time": "2022-08-19T05:11:09+00:00" }, { "name": "leenooks/laravel-theme", @@ -3523,16 +3523,16 @@ }, { "name": "masterminds/html5", - "version": "2.7.5", + "version": "2.7.6", "source": { "type": "git", "url": "https://github.com/Masterminds/html5-php.git", - "reference": "f640ac1bdddff06ea333a920c95bbad8872429ab" + "reference": "897eb517a343a2281f11bc5556d6548db7d93947" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/f640ac1bdddff06ea333a920c95bbad8872429ab", - "reference": "f640ac1bdddff06ea333a920c95bbad8872429ab", + "url": "https://api.github.com/repos/Masterminds/html5-php/zipball/897eb517a343a2281f11bc5556d6548db7d93947", + "reference": "897eb517a343a2281f11bc5556d6548db7d93947", "shasum": "" }, "require": { @@ -3586,9 +3586,9 @@ ], "support": { "issues": "https://github.com/Masterminds/html5-php/issues", - "source": "https://github.com/Masterminds/html5-php/tree/2.7.5" + "source": "https://github.com/Masterminds/html5-php/tree/2.7.6" }, - "time": "2021-07-01T14:25:37+00:00" + "time": "2022-08-18T16:18:26+00:00" }, { "name": "monolog/monolog", diff --git a/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php b/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php new file mode 100644 index 0000000..704c21d --- /dev/null +++ b/resources/views/theme/backend/adminlte/supplier/cost/add.blade.php @@ -0,0 +1,59 @@ + +@extends('adminlte::layouts.app') + +@section('htmlheader_title') + Add Cost +@endsection + +@section('contentheader_title') + Add Cost +@endsection +@section('contentheader_description') + {{ $o->name }} +@endsection + +@section('main-content') +
+
+
+
+
+ @include('adminlte::widget.success') + + @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 +
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/theme/backend/adminlte/supplier/cost.blade.php b/resources/views/theme/backend/adminlte/supplier/cost/view.blade.php similarity index 100% rename from resources/views/theme/backend/adminlte/supplier/cost.blade.php rename to resources/views/theme/backend/adminlte/supplier/cost/view.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 index d068115..9e18eac 100644 --- a/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php +++ b/resources/views/theme/backend/adminlte/supplier/widget/costs.blade.php @@ -27,7 +27,7 @@ $(document).ready(function() { $('#cost_id') .on('change',function(item) { - window.location.href = '{{ url('a/supplier/cost') }}'+(item.target.value ? '/'+item.target.value : ''); + window.location.href = '{{ url('a/supplier/cost') }}/'+(item.target.value ? item.target.value : 'new/'+{{ $o->id }}); }); }); diff --git a/routes/web.php b/routes/web.php index e4db7a7..59aecc5 100644 --- a/routes/web.php +++ b/routes/web.php @@ -79,12 +79,14 @@ Route::group(['middleware'=>['theme:adminlte-be','auth','role:wholesaler'],'pref // Supplier Setup Route::get('supplier',[SupplierController::class,'admin_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::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('supplier/product/add',[SupplierController::class,'product_add']); Route::get('supplier/product/addedit/{o}/{oo}/{type}',[SupplierController::class,'product_view']) ->where('o','[0-9]+')