Added cost import via web

This commit is contained in:
Deon George 2022-08-19 15:12:56 +10:00
parent 798608cebd
commit 73d92f25c1
9 changed files with 111 additions and 17 deletions

View File

@ -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(),

View File

@ -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');
}
/**

View File

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

View File

@ -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",

20
composer.lock generated
View File

@ -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",

View File

@ -0,0 +1,59 @@
<!-- $o = Supplier::class -->
@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')
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body">
<form class="g-0 needs-validation" method="POST" action="{{ url('a/supplier/cost/new',[$o->id]) }}" enctype="multipart/form-data">
@include('adminlte::widget.success')
@csrf
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@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'),
])
</div>
</div>
<div class="row">
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
@include('adminlte::widget.form_file',[
'label'=>'Invoice File',
'icon'=>'fas fa-file',
'id'=>'file',
'name'=>'file',
])
</div>
</div>
<div class="col-12">
@can('wholesaler')
<button type="submit" name="submit" class="btn btn-success mr-0 float-right">@if ($site->exists)Save @else Add @endif</button>
@endcan
</div>
</form>
</div>
</div>
</div>
</div>
@endsection

View File

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

View File

@ -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]+')