Rework products with components
This commit is contained in:
parent
1b581e9feb
commit
b87e9ff33a
@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use App\Models\{ProviderOauth,User};
|
||||
|
||||
class AccountingController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware('auth');
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the accounting system and get a valid list of accounting codes
|
||||
*
|
||||
* @param string $provider
|
||||
* @return Collection
|
||||
*/
|
||||
public static function list(string $provider): Collection
|
||||
{
|
||||
// @todo This should be a variable
|
||||
$uo = User::findOrFail(1);
|
||||
|
||||
$so = ProviderOauth::where('name',$provider)->singleOrFail();
|
||||
if (! ($to=$so->token($uo)))
|
||||
abort(500,sprintf('Unknown Tokens for [%s]',$uo->email));
|
||||
|
||||
$api = $to->API();
|
||||
|
||||
return $api->getItems()
|
||||
->pluck('pid','Id')
|
||||
->transform(function($item,$value) { return ['id'=>$value,'value'=>$item]; })
|
||||
->values();
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use App\Http\Requests\ProductAddEdit;
|
||||
@ -17,14 +18,14 @@ class ProductController extends Controller
|
||||
* @return Collection
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function api_supplier_products(Request $request): Collection
|
||||
public function api_supplied_products(Request $request): Collection
|
||||
{
|
||||
switch ($request->type) {
|
||||
case Product\Broadband::class:
|
||||
return Product\Broadband::select(['id','supplier_item_id'])
|
||||
->with(['supplied.supplier_detail.supplier'])
|
||||
->get()
|
||||
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)]; })
|
||||
->map(fn($item)=>['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)])
|
||||
->sortBy('name')
|
||||
->values();
|
||||
|
||||
@ -32,7 +33,7 @@ class ProductController extends Controller
|
||||
return Product\Domain::select(['id','supplier_item_id'])
|
||||
->with(['supplied.supplier_detail.supplier'])
|
||||
->get()
|
||||
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)]; })
|
||||
->map(fn($item)=>['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)])
|
||||
->sortBy('name')
|
||||
->values();
|
||||
|
||||
@ -40,7 +41,7 @@ class ProductController extends Controller
|
||||
return Product\Email::select(['id','supplier_item_id'])
|
||||
->with(['supplied.supplier_detail.supplier'])
|
||||
->get()
|
||||
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)]; })
|
||||
->map(fn($item)=>['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)])
|
||||
->sortBy('name')
|
||||
->values();
|
||||
|
||||
@ -48,7 +49,7 @@ class ProductController extends Controller
|
||||
return Product\Generic::select(['id','supplier_item_id'])
|
||||
->with(['supplied.supplier_detail.supplier'])
|
||||
->get()
|
||||
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)]; })
|
||||
->map(fn($item)=>['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)])
|
||||
->sortBy('name')
|
||||
->values();
|
||||
|
||||
@ -56,7 +57,7 @@ class ProductController extends Controller
|
||||
return Product\Host::select(['id','supplier_item_id'])
|
||||
->with(['supplied.supplier_detail.supplier'])
|
||||
->get()
|
||||
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)]; })
|
||||
->map(fn($item)=>['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)])
|
||||
->sortBy('name')
|
||||
->values();
|
||||
|
||||
@ -64,7 +65,7 @@ class ProductController extends Controller
|
||||
return Product\Phone::select(['id','supplier_item_id'])
|
||||
->with(['supplied.supplier_detail.supplier'])
|
||||
->get()
|
||||
->map(function($item) { return ['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)]; })
|
||||
->map(fn($item)=>['id'=>$item->id,'name'=>sprintf('%s: %s',$item->supplied->supplier->name,$item->supplied->name)])
|
||||
->sortBy('name')
|
||||
->values();
|
||||
|
||||
@ -73,77 +74,54 @@ class ProductController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a suppliers details
|
||||
*
|
||||
* @param Request $request
|
||||
* @param Product $o
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function details(Request $request,Product $o)
|
||||
public function addedit(ProductAddEdit $request,Product $o)
|
||||
{
|
||||
if (! $o->exists && $request->name)
|
||||
$o = Product::where('name',$request->name)->firstOrNew();
|
||||
|
||||
return view('theme.backend.adminlte.product.details')
|
||||
->with('breadcrumb',collect(['Products'=>url('a/product')]))
|
||||
->with('o',$o);
|
||||
}
|
||||
|
||||
public function details_addedit(ProductAddEdit $request,Product $o)
|
||||
{
|
||||
foreach ($request->except(['_token','submit','translate','accounting']) as $key => $item)
|
||||
foreach (Arr::except($request->validated(),['translate','accounting','pricing','active']) as $key => $item)
|
||||
$o->{$key} = $item;
|
||||
|
||||
$o->active = (bool)$request->active;
|
||||
|
||||
// Trim down the pricing array, remove null values
|
||||
$o->pricing = $o->pricing->map(function($item) {
|
||||
foreach ($item as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
$v = array_filter($v);
|
||||
$item[$k] = $v;
|
||||
$o->pricing = collect($request->validated('pricing'))
|
||||
->map(function($item) {
|
||||
foreach ($item as $k=>$v) {
|
||||
if (is_array($v)) {
|
||||
$v = array_filter($v);
|
||||
$item[$k] = $v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $item;
|
||||
});
|
||||
return $item;
|
||||
});
|
||||
|
||||
try {
|
||||
$o->save();
|
||||
|
||||
} catch (\Exception $e) {
|
||||
return redirect()->back()->withErrors($e->getMessage())->withInput();
|
||||
return redirect()
|
||||
->back()
|
||||
->withErrors($e->getMessage())
|
||||
->withInput();
|
||||
}
|
||||
|
||||
$o->load(['translate']);
|
||||
$oo = $o->translate ?: new ProductTranslate;
|
||||
foreach ($request->get('translate',[]) as $key => $item)
|
||||
foreach ($request->validated('translate',[]) as $key => $item)
|
||||
$oo->{$key} = $item;
|
||||
|
||||
$o->translate()->save($oo);
|
||||
|
||||
if ($request->accounting)
|
||||
foreach ($request->accounting as $k=>$v)
|
||||
$o->providers()->syncWithoutDetaching([
|
||||
$k => [
|
||||
'ref' => $v,
|
||||
'site_id'=>$o->site_id,
|
||||
],
|
||||
]);
|
||||
foreach ($request->validated('accounting',[]) as $k=>$v) {
|
||||
$o->providers()->syncWithoutDetaching([
|
||||
$k => [
|
||||
'ref' => $v,
|
||||
'site_id'=>$o->site_id,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('success','Product saved');
|
||||
}
|
||||
|
||||
/**
|
||||
* Manage products for a site
|
||||
*
|
||||
* @note This method is protected by the routes
|
||||
* @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
|
||||
*/
|
||||
public function home()
|
||||
{
|
||||
return view('theme.backend.adminlte.product.home');
|
||||
}
|
||||
}
|
@ -3,7 +3,9 @@
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
use App\Models\ProviderOauth;
|
||||
|
||||
/**
|
||||
* Editing Suppliers
|
||||
@ -17,7 +19,7 @@ class ProductAddEdit extends FormRequest
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return Auth::user()->isWholesaler();
|
||||
return Gate::allows('wholesaler');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -34,7 +36,21 @@ class ProductAddEdit extends FormRequest
|
||||
'active' => 'sometimes|accepted',
|
||||
'model' => 'sometimes|string', // @todo Check that it is a valid model type
|
||||
'model_id' => 'sometimes|int', // @todo Check that it is a valid model type
|
||||
'accounting' => 'nullable|array', // @todo Validate that the value is in the accounting system
|
||||
'accounting' => [
|
||||
'nullable',
|
||||
'array',
|
||||
function (string $attribute,mixed $value,\Closure $fail) {
|
||||
if (! is_array($value))
|
||||
$fail("Invalid format for {$attribute}");
|
||||
|
||||
foreach ($value as $k=>$v) {
|
||||
if (! ProviderOauth::where('id',$k)->exists())
|
||||
$fail("Provider doesnt exist [$k]");
|
||||
|
||||
// @todo Validate that the value is in the accounting system
|
||||
}
|
||||
},
|
||||
],
|
||||
'pricing' => 'required|array', // @todo Validate the elements in the pricing
|
||||
];
|
||||
}
|
||||
|
@ -11,10 +11,11 @@ use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Str;
|
||||
use Intuit\Exceptions\NotTokenException;
|
||||
use Intuit\Traits\ProviderTokenTrait;
|
||||
use Leenooks\Traits\ScopeActive;
|
||||
|
||||
use App\Casts\CollectionOrNull;
|
||||
use App\Http\Controllers\AccountingController;
|
||||
use App\Interfaces\{IDs,ProductItem};
|
||||
use App\Traits\{ProductDetails,ProviderRef};
|
||||
|
||||
@ -66,7 +67,7 @@ use App\Traits\{ProductDetails,ProviderRef};
|
||||
*/
|
||||
class Product extends Model implements IDs
|
||||
{
|
||||
use HasFactory,ProductDetails,ScopeActive,ProviderRef;
|
||||
use HasFactory,ProductDetails,ScopeActive,ProviderRef,ProviderTokenTrait;
|
||||
|
||||
protected $casts = [
|
||||
'pricing' => CollectionOrNull::class,
|
||||
@ -368,7 +369,18 @@ class Product extends Model implements IDs
|
||||
|
||||
public function accounting(string $provider): Collection
|
||||
{
|
||||
return AccountingController::list($provider);
|
||||
$so = ProviderOauth::where('name',self::provider)
|
||||
->sole();
|
||||
|
||||
if (! ($to=$so->token(Auth::user())))
|
||||
throw new NotTokenException(sprintf('Unknown Tokens for [%s]',Auth::user()->email));
|
||||
|
||||
return $to
|
||||
->API()
|
||||
->getItems()
|
||||
->pluck('pid','Id')
|
||||
->transform(fn($item,$value)=>['id'=>$value,'value'=>$item])
|
||||
->values();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,5 +35,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
|
||||
Route::model('co',\App\Models\Checkout::class);
|
||||
Route::model('po',\App\Models\Payment::class);
|
||||
Route::model('pdo',\App\Models\Product::class);
|
||||
}
|
||||
}
|
@ -1,14 +1,14 @@
|
||||
@extends('adminlte::layouts.app')
|
||||
|
||||
@section('htmlheader_title')
|
||||
{{ $o->name ?: 'New Product' }}
|
||||
{{ $pdo->name ?: 'New Product' }}
|
||||
@endsection
|
||||
@section('page_title')
|
||||
{{ $o->name ?: 'New Product' }}
|
||||
{{ $pdo->name ?: 'New Product' }}
|
||||
@endsection
|
||||
|
||||
@section('contentheader_title')
|
||||
{{ $o->name ?: 'New Product' }}
|
||||
{{ $pdo->name ?: 'New Product' }}
|
||||
@endsection
|
||||
@section('contentheader_description')
|
||||
@endsection
|
||||
@ -23,8 +23,8 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header bg-dark d-flex p-0">
|
||||
<ul class="nav nav-pills w-100 p-2">
|
||||
<div class="card-header bg-dark p-2">
|
||||
<ul class="nav nav-pills">
|
||||
<li class="nav-item"><a class="nav-link active" href="#details" data-toggle="tab">Detail</a></li>
|
||||
<li class="nav-item"><a class="nav-link" href="#services" data-toggle="tab">Services</a></li>
|
||||
</ul>
|
||||
|
@ -1,54 +1,32 @@
|
||||
<!-- $o = Product::class -->
|
||||
<!-- $pdo=Product::class -->
|
||||
@use(App\Models\Group)
|
||||
@use(App\Models\Invoice)
|
||||
@use(App\Models\Product)
|
||||
@use(App\Models\ProviderOauth)
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h3>Product Details @include('adminlte::widget.success_button')</h3>
|
||||
<h3>Product Details <x-leenooks::button.success class="float-right"/></h3>
|
||||
<hr>
|
||||
|
||||
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
|
||||
<form method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="row">
|
||||
<!-- Product ID -->
|
||||
<div class="col-12 col-sm-9 col-md-4 col-xl-3">
|
||||
@include('adminlte::widget.form_text',[
|
||||
'label'=>'Product ID',
|
||||
'icon'=>'fas fa-atom',
|
||||
'id'=>'translate.name_short',
|
||||
'old'=>'translate.name_short',
|
||||
'name'=>'translate[name_short]',
|
||||
'value'=>$o->pid,
|
||||
])
|
||||
<x-leenooks::form.text id="translate.name_short" name="translate[name_short]" icon="fa-atom" label="Product ID" old="translate.name_short" :value="$pdo->pid"/>
|
||||
</div>
|
||||
|
||||
<!-- Product Name -->
|
||||
<div class="col-12 col-sm-9 col-md-8 col-xl-9">
|
||||
@include('adminlte::widget.form_text',[
|
||||
'label'=>'Product Name',
|
||||
'icon'=>'fas fa-atom',
|
||||
'id'=>'translate.name_detail',
|
||||
'old'=>'translate.name_detail',
|
||||
'name'=>'translate[name_detail]',
|
||||
'value'=>$o->name,
|
||||
])
|
||||
<x-leenooks::form.text id="translate.name_detail" name="translate[name_detail]" icon="fa-atom" label="Product Name" old="translate.name_detail" :value="$pdo->name"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group @error('description') is-invalid @enderror">
|
||||
<!-- Product Description -->
|
||||
<label for="description_full" class="col-form-label">Product Description</label>
|
||||
<div class="input-group">
|
||||
<div class="w-100">
|
||||
<textarea class="textarea" id="description" name="translate[description]" placeholder="Full Description">{!! old('description',$o->description) ?? '' !!}</textarea>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
@error('description')
|
||||
{{ $message }}
|
||||
@enderror
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<x-leenooks::form.textarea id="translate.description" name="translate[description]" label="Product Description" placeholder="Full Description..." old="translate.description" :value="$pdo->description"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -57,48 +35,21 @@
|
||||
<div class="row">
|
||||
<!-- Active -->
|
||||
<div class="col-6">
|
||||
@include('adminlte::widget.form_toggle',[
|
||||
'label'=>'Active',
|
||||
'id'=>'active',
|
||||
'old'=>'active',
|
||||
'name'=>'active',
|
||||
'value'=>$o->active ?? '',
|
||||
])
|
||||
<x-leenooks::form.toggle name="active" label="Active" :value="$pdo->active"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Product Type -->
|
||||
<div class="col-12">
|
||||
@include('adminlte::widget.form_select',[
|
||||
'label'=>'Product Type',
|
||||
'icon'=>'fas fa-list',
|
||||
'id'=>'model',
|
||||
'old'=>'model',
|
||||
'name'=>'model',
|
||||
'options'=>\App\Models\Product::availableTypes()->transform(function($item) { return ['id'=>$item,'value'=>$item]; }),
|
||||
'value'=>get_class($o->type),
|
||||
])
|
||||
<x-leenooks::form.select name="model" icon="fa-list" label="Product" choose="true" groupby="active" :value="get_class($pdo->type)" :options="Product::availableTypes()->transform(fn($item)=>['id'=>$item,'value'=>$item])"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Supplied Product -->
|
||||
<div class="col-12" id="supplier_product">
|
||||
<div class="form-group">
|
||||
<label for="model_id">Supplied Product</label>
|
||||
<div class="input-group has-validation">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa-fw fas fa-shopping-cart"></i></span>
|
||||
</div>
|
||||
<select class="form-control @error('model_id') is-invalid @enderror" id="model_id" name="model_id"></select>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
@error('model_id')
|
||||
{{ $message }}
|
||||
@enderror
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12" id="supplied_product">
|
||||
<x-leenooks::form.select name="model_id" icon="fa-shopping-cart" label="Supplied Product"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -107,26 +58,10 @@
|
||||
<div class="col-12">
|
||||
<span class="h5">Accounting</span>
|
||||
<hr>
|
||||
@foreach (\App\Models\ProviderOauth::providers() as $apo)
|
||||
<div class="form-group">
|
||||
<label for="{{ $x=sprintf('acc_%d',$apo->id) }}">{{ ucfirst($apo->name) }}</label>
|
||||
<div class="input-group has-validation">
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa-fw fas fa-calculator"></i></span>
|
||||
</div>
|
||||
<select class="form-control @error($x) is-invalid @enderror select" id="{{ $x }}" name="{{ sprintf('accounting[%d]',$apo->id) }}">
|
||||
<option></option>
|
||||
@foreach ($o->accounting($apo->name) as $v)
|
||||
<option value="{{ $v['id'] }}" @if($o->provider_ref($apo) === (string)$v['id'])selected @endif>{{ $v['value'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
@error($x)
|
||||
{{ $message }}
|
||||
@enderror
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- @todo When returning with a bad value old() is not selecting the previous value, may need to have the full html here instead of a component -->
|
||||
@foreach (ProviderOauth::providers() as $apo)
|
||||
<x-leenooks::form.select :id="sprintf('acc_%d',$apo->id)" :name="sprintf('accounting[%d]',$apo->id)" icon="fa-calculator" :label="ucfirst($apo->name)" :choose="true" :value="$pdo->provider_ref($apo)" old="accounting" :options="$pdo->accounting($apo->name)"/>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@ -136,20 +71,20 @@
|
||||
<span class="h5">Pricing</span><small> Ex Taxes</small>
|
||||
<hr>
|
||||
@error('pricing')
|
||||
@include('adminlte::widget.errors')
|
||||
<x-leenooks::errors/>
|
||||
@enderror
|
||||
|
||||
<ul class="nav nav-pills w-100 pl-0 pt-2 pb-2">
|
||||
@foreach(\App\Models\Group::pricing()->active()->get() as $go)
|
||||
@foreach($g=Group::pricing()->active()->get() as $go)
|
||||
<li class="nav-item"><a class="nav-link @if(! $loop->index)active @endif" href="#pg_{{ $go->id }}" data-toggle="tab">{{ $go->name }}</a></li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
<div class="tab-content">
|
||||
@foreach(\App\Models\Group::pricing()->active()->get() as $go)
|
||||
<div class="tab-pane fade @if(! $loop->index)show active @endif" id="pg_{{ $go->id }}" role="tabpanel">
|
||||
@foreach($g as $go)
|
||||
<div class="tab-pane fade @if(! $loop->index)show active @endif" id="pg_{{ $go->id }}">
|
||||
|
||||
@foreach(\App\Models\Invoice::billing_periods as $bp=>$detail)
|
||||
@foreach(Invoice::billing_periods as $bp=>$detail)
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
@ -158,13 +93,13 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa-fw fas fa-calculator"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control text-right @error($x) is-invalid @enderror" id="{{ $x }}" name="{{ sprintf('pricing[%d][%d][base]',$bp,$go->id) }}" {{ ($ca=$o->charge_available($bp,$go)) ? 'value' : 'placeholder' }}="{{ $c=$o->charge($bp,$go,'base') }}" @if(is_null($c) || ! $ca) disabled @endif>
|
||||
<input type="text" class="form-control text-right @error($x) is-invalid @enderror" id="{{ $x }}" name="{{ sprintf('pricing[%d][%d][base]',$bp,$go->id) }}" {{ ($ca=$pdo->charge_available($bp,$go)) ? 'value' : 'placeholder' }}="{{ $c=$pdo->charge($bp,$go,'base') }}" @if(is_null($c) || ! $ca) disabled @endif>
|
||||
<div class="input-group-append">
|
||||
<div class="input-group-text">
|
||||
<input type="checkbox" name="{{ sprintf('pricing[%d][show]',$bp) }}" @if($c && $ca)checked @endif>
|
||||
</div>
|
||||
</div>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
<span class="invalid-feedback">
|
||||
@error($x)
|
||||
{{ $message }}
|
||||
@enderror
|
||||
@ -180,8 +115,8 @@
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text"><i class="fa-fw fas fa-cog"></i></span>
|
||||
</div>
|
||||
<input type="text" class="form-control text-right @error($x) is-invalid @enderror" id="{{ $x }}" name="{{ sprintf('pricing[%d][%d][setup]',$bp,$go->id) }}" {{ $ca ? 'value' : 'placeholder' }}="{{ $c=$o->charge($bp,$go,'setup') }}" @if(is_null($c) || ! $ca) disabled @endif>
|
||||
<span class="invalid-feedback" role="alert">
|
||||
<input type="text" class="form-control text-right @error($x) is-invalid @enderror" id="{{ $x }}" name="{{ sprintf('pricing[%d][%d][setup]',$bp,$go->id) }}" {{ $ca ? 'value' : 'placeholder' }}="{{ $c=$pdo->charge($bp,$go,'setup') }}" @if(is_null($c) || ! $ca) disabled @endif>
|
||||
<span class="invalid-feedback">
|
||||
@error($x)
|
||||
{{ $message }}
|
||||
@enderror
|
||||
@ -198,12 +133,9 @@
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<!-- Buttons -->
|
||||
<div class="col-12">
|
||||
<a href="{{ url('/home') }}" class="btn btn-danger">Cancel</a>
|
||||
@can('wholesaler')
|
||||
<button type="submit" name="submit" class="btn btn-success mr-0 float-right">@if ($o->exists)Save @else Add @endif</button>
|
||||
@endcan
|
||||
<div class="col">
|
||||
<x-leenooks::button.reset/>
|
||||
<x-leenooks::button.submit class="float-right">Save</x-leenooks::button.submit>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -211,14 +143,9 @@
|
||||
</div>
|
||||
|
||||
@section('page-scripts')
|
||||
@css(select2)
|
||||
@css(simplemde)
|
||||
@js(select2,autofocus)
|
||||
@js(simplemde)
|
||||
|
||||
<script type="text/javascript">
|
||||
// Get a list of supplier items matching this type to populate model_id
|
||||
function supplier_products(type,destination,selected) {
|
||||
function supplied_products(type,destination,selected) {
|
||||
destination.prop('disabled',true);
|
||||
|
||||
$.ajax({
|
||||
@ -226,11 +153,10 @@
|
||||
dataType: 'json',
|
||||
data: {type: type},
|
||||
cache: false,
|
||||
url: '{{ url('api/a/supplier_products') }}',
|
||||
url: '{{ url('a/supplied_products') }}',
|
||||
timeout: 2000,
|
||||
error: function(x) {
|
||||
// @todo add a spinner
|
||||
//spinner.toggleClass('d-none').toggleClass('fa-spin');
|
||||
alert('Failed to submit');
|
||||
},
|
||||
success: function(data) {
|
||||
@ -246,28 +172,24 @@
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
new SimpleMDE({ element: $('.textarea')[0], forceSync: true });
|
||||
|
||||
$('#model').on('change',function(item) {
|
||||
if ($(this).val()) {
|
||||
$('#supplier_product').show();
|
||||
supplier_products($(this).val(),$('#model_id'));
|
||||
$('#supplied_product').show();
|
||||
supplied_products($(this).val(),$('#model_id'));
|
||||
|
||||
} else {
|
||||
$('#supplier_product').hide();
|
||||
$('#supplied_product').hide();
|
||||
}
|
||||
});
|
||||
|
||||
$('#model_id').select2();
|
||||
$('.select').select2();
|
||||
|
||||
// After we render the page, hide the supplier_product if this product has no model.
|
||||
// After we render the page, hide the supplied_product if this product has no model.
|
||||
// We do this here, because adding d-none to the div results in the select2 input not presenting correctly
|
||||
if (! $('#model').val())
|
||||
$('#supplier_product').hide();
|
||||
$('#supplied_product').hide();
|
||||
else
|
||||
supplier_products($('#model').val(),$('#model_id'),{{ old('model_id',$o->model_id) }});
|
||||
supplied_products($('#model').val(),$('#model_id'),{{ old('model_id',$pdo->model_id) }});
|
||||
|
||||
// @todo when there is a value in 1 of the two boxes in the row, the toggle incorrectly disables one and enables the other
|
||||
$('input[type=checkbox]').on('click',function(item) {
|
||||
var input = $(this).parent().parent().parent().find('input[type="text"]');
|
||||
input.prop('disabled',(i,v)=>!v);
|
||||
|
@ -1,25 +1,18 @@
|
||||
<!-- $o = Product::class -->
|
||||
<!-- $o=Product::class -->
|
||||
@use(App\Models\Product)
|
||||
|
||||
<div class="card card-dark">
|
||||
<div class="card-header">
|
||||
<h1 class="card-title">Product Configuration</h1>
|
||||
</div>
|
||||
|
||||
<div class="card-body">
|
||||
<form class="g-0 needs-validation" method="POST" enctype="multipart/form-data" role="form">
|
||||
<form method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 col-sm-9 col-md-6 col-xl-5">
|
||||
@include('adminlte::widget.form_select',[
|
||||
'label'=>'Product',
|
||||
'icon'=>'fas fa-list',
|
||||
'id'=>'product_id',
|
||||
'old'=>'product_id',
|
||||
'name'=>'product_id',
|
||||
'groupby'=>'active',
|
||||
'options'=>\App\Models\Product::get()->sortBy(function($item) { return ($item->active ? '0' : '1').$item->name; })->transform(function($item) { return ['id'=>$item->id,'value'=>$item->name,'active'=>$item->active]; }),
|
||||
'value'=>isset($o) ? $o->id : NULL,
|
||||
])
|
||||
<x-leenooks::form.select name="product_id" icon="fa-list" label="Product" choose="true" groupby="active" :value="$po?->id ?? ''" :options="Product::get()->sortBy(fn($item)=>($item->active ? '0' : '1').$item->name)->transform(fn($item)=>['id'=>$item->id,'value'=>$item->name,'active'=>$item->active])"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@ -27,13 +20,10 @@
|
||||
</div>
|
||||
|
||||
@section('page-scripts')
|
||||
@css(select2)
|
||||
@js(select2,autofocus)
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$('#product_id').on('change',function(item) {
|
||||
window.location.href = '{{ url('a/product/details') }}/'+item.target.value;
|
||||
window.location.href = '{{ url('a/product') }}/'+item.target.value;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
@ -1,8 +1,8 @@
|
||||
<!-- $o = Product::class -->
|
||||
<!-- $pdo=Product::class -->
|
||||
<div class="row">
|
||||
@if(count($o->services))
|
||||
@if(count($pdo->services))
|
||||
<div class="col-7">
|
||||
<table class="table table-hover w-100" id="table">
|
||||
<table class="table table-hover" id="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
@ -17,7 +17,7 @@
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach ($o->services as $so)
|
||||
@foreach ($pdo->services as $so)
|
||||
<tr>
|
||||
<td><a href="{{ url('u/service',[$so->id]) }}">{{ $so->sid }}</a></td>
|
||||
<td>{{ $so->start_at ? $so->start_at->format('Y-m-d') : '-' }}</td>
|
||||
@ -38,24 +38,12 @@
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@pa(datatables,select)
|
||||
|
||||
@section('page-scripts')
|
||||
@css(datatables,bootstrap4|rowgroup|select|searchpanes|searchpanes-left)
|
||||
@js(datatables,bootstrap4|rowgroup|select|searchpanes)
|
||||
|
||||
<style>
|
||||
tr.odd td:first-child,
|
||||
tr.even td:first-child {
|
||||
padding-left: 3em;
|
||||
}
|
||||
table.dataTable tr.dtrg-group.dtrg-level-1 td {
|
||||
background-color: #e0e0e0;
|
||||
color: #4c110f;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
@if(count($o->services))
|
||||
@if(count($pdo->services))
|
||||
$('#table').DataTable({
|
||||
paging: true,
|
||||
pageLength: 25,
|
||||
@ -66,34 +54,12 @@
|
||||
autoWidth: false,
|
||||
fixedHeader: true,
|
||||
order: [[4,'desc'],[0,'asc']],
|
||||
rowGroup: {
|
||||
dataSrc: 4,
|
||||
},
|
||||
columnDefs: [
|
||||
{
|
||||
targets: [4],
|
||||
visible: false,
|
||||
}
|
||||
],
|
||||
language: {
|
||||
searchPanes: {
|
||||
clearMessage: 'Clear',
|
||||
title: 'Filters: %d',
|
||||
collapse: 'Filter',
|
||||
}
|
||||
},
|
||||
searchPanes: {
|
||||
cascadePanes: true,
|
||||
viewTotal: true,
|
||||
layout: 'columns-1',
|
||||
dataLength: 20,
|
||||
controls: false,
|
||||
},
|
||||
dom: '<"dtsp-verticalContainer"<"dtsp-verticalPanes"P><"dtsp-dataTable"Bfrtip>>',
|
||||
});
|
||||
|
||||
$('tbody').on('click','tr', function () {
|
||||
$(this).toggleClass('selected');
|
||||
});
|
||||
@endif
|
||||
});
|
||||
|
@ -3,11 +3,6 @@
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Intuit\Controllers\Webhook;
|
||||
|
||||
use App\Http\Controllers\{AccountingController,
|
||||
AdminController,
|
||||
CheckoutController,
|
||||
ProductController};
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
@ -19,13 +14,4 @@ use App\Http\Controllers\{AccountingController,
|
||||
|
|
||||
*/
|
||||
|
||||
// Wholesaler API calls
|
||||
Route::group(['middleware'=>['auth:api','role:wholesaler']], function() {
|
||||
Route::get('a/supplier_products',[ProductController::class,'api_supplier_products']);
|
||||
});
|
||||
|
||||
Route::group(['middleware'=>'auth:api'], function() {
|
||||
Route::any('/intuit/accounting/list',[AccountingController::class,'list']);
|
||||
});
|
||||
|
||||
Route::any('/intuit/webhook',[Webhook::class,'webhook']);
|
@ -90,12 +90,14 @@ Route::group(['middleware'=>['auth','role:wholesaler'],'prefix'=>'a'],function()
|
||||
->where('o','[0-9]+');
|
||||
|
||||
// Product Setup
|
||||
Route::match(['get'],'product',[ProductController::class,'home']);
|
||||
Route::get('product/details/{o?}',[ProductController::class,'details'])
|
||||
->where('o','[0-9]+');
|
||||
Route::post('product/details/{o?}',[ProductController::class,'details_addedit'])
|
||||
Route::view('product','theme.backend.adminlte.product.home',['breadcrumb'=>collect(['x'=>'foobar'])]);
|
||||
Route::view('product/{pdo}','theme.backend.adminlte.product.details',['breadcrumb'=>collect(['Products'=>url('a/product')])])
|
||||
->where('pdo','[0-9]+');
|
||||
Route::post('product/{o?}',[ProductController::class,'addedit'])
|
||||
->where('o','[0-9]+');
|
||||
|
||||
Route::get('supplied_products',[ProductController::class,'api_supplied_products']);
|
||||
|
||||
// Supplier Setup
|
||||
Route::get('supplier',[SupplierController::class,'admin_home']);
|
||||
Route::get('supplier/cost/new/{o}',[SupplierController::class,'cost_add']);
|
||||
@ -127,11 +129,6 @@ Route::group(['middleware'=>['auth','role:wholesaler'],'prefix'=>'a'],function()
|
||||
// @todo This should probably go to resellers - implement a change audit log first
|
||||
Route::post('service/update/{o}',[ServiceController::class,'update'])
|
||||
->where('o','[0-9]+');
|
||||
|
||||
//@deprecated
|
||||
// Route::get('service/{o}','AdminHomeController@service');
|
||||
// Route::post('service/{o}','AdminHomeController@service_update');
|
||||
// Route::get('accounting/connect','AccountingController@connect');
|
||||
});
|
||||
|
||||
// Our Reseller Routes
|
||||
|
Loading…
Reference in New Issue
Block a user