Update with new price management

This commit is contained in:
Ludovic CANDELLIER
2021-03-22 00:47:44 +01:00
parent 083d358fbd
commit 37ffaa938b
64 changed files with 1118 additions and 984 deletions

View File

@@ -52,8 +52,7 @@
</div>
<div class="tab-pane" id="prices">
@include('Shop.Admin.Articles.partials.prices', ['prices' => $prices['prices'] ?? null])
@include('Shop.Admin.Articles.partials.generic_prices', ['generics' => $prices['generics'] ?? null])
@include('Shop.Admin.Articles.partials.prices')
</div>
<div class="tab-pane" id="shipping">

View File

@@ -1,119 +0,0 @@
@include('Shop.Admin.Articles.partials.generic_prices.block_generic_price_new')
<div id="append_generic_price" class="row">
@include('Shop.Admin.Articles.partials.generic_prices.list-generic_prices')
</div>
<button type="button" class="btn btn-sm btn-primary add-new-generic_price">Associer un tarif générique<i class="fa fa-plus"></i></button>
@include('components.select-tree', ['name' => "article_price_generic_id", 'value' => $price['article_price_generic_id'] ?? null, 'list' => $price_generics ?? null, 'required' => false, 'class' => 'form-control-sm w-100'])
@push('js')
<script>
function append_generic_price() {
// handle_append_attribute();
$('.select2').select2();
handle_change_attribute();
load_attribute_values($('.attributes-value'), $('.attributes-family').val());
}
$("#append_generic_price").appender({
rowSection: '.row-new-generic_price',
type: '.row-generic_price',
addBtn: '.add-new-generic_price',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-generic_price-number',
deleteBtn: '.delete-new-generic_price-btn',
callback: append_generic_price,
rowNumberStart: 2,
hideSection: true
});
function append_attribute() {
}
function handle_append_attribute(selector) {
console.log('handle_append_attribute');
$(".append_attribute").appender({
rowSection: '.row-new-attribute',
type: '.row-attribute',
addBtn: '.add-new-attribute',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-attribute-number',
deleteBtn: '.delete-new-attribute-btn',
callback: append_attribute,
rowNumberStart: 2,
hideSection: true
});
}
function handle_change_attribute() {
$('.attributes-family').change( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.attributes-value');
load_attribute_values($selector, family_id);
});
}
function init_attribute_values() {
$('.attributes-family').each( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.attributes-value');
load_attribute_values($selector, family_id);
value_id = $selector.data('id');
$selector.val(value_id).trigger('change');
});
}
function load_attribute_values($selector, family_id) {
$.ajax({
url : "{{ route('Shop.Admin.PriceFamilyValues.getOptionsByFamily') }}",
method : 'POST',
data: { family_id: family_id },
success : function(data) {
$selector.empty().select2({data: data});
}
});
}
function handle_delete_generic_price() {
$('.delete-generic_price-btn').click(function() {
var $selector = $(this).parents('.row-generic_price');
var id = $selector.find('.generic_price_id').val();
confirm_delete(id, laroute.route('Shop.Admin.ArticlePrices.destroy', {id : id}), function() {
$selector.remove();
});
});
}
function handle_generic_prices() {
$('.generic_price-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
generic_price_taxed = $(this).val() * (1 + (tax_selected / 100));
$(this).parent().parent().find('.generic_price-taxed-item').val(generic_price_taxed);
})
}
function handle_generic_prices_taxed() {
$('.generic_price-taxed-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
console.log($(this).parent().prev());
generic_price = $(this).val() / (1 + (tax_selected / 100));
$(this).parent().parent().find('.generic_price-item').val(generic_price);
})
}
</script>
@endpush

View File

@@ -1,54 +1,9 @@
<div class="col-12 row-new-price row-price">
<div class="col-12 row-new-generic row-generic">
<input type="hidden" name="prices[][id]" value="">
<div class="card card-light">
<div class="card-body pt-2">
<div class="row">
@include('Shop.Admin.PriceGenerics.partials.table-prices', ['generic' => $generic['generic'] ?? null ])
<div class="col-lg-3">
{{ Form::label('price_generic_id', 'Générique') }}<br/>
@include('components.select-tree', ['name' => "prices[0][article_price_generic_id]", 'value' => $price['article_price_generic_id'] ?? null, 'list' => $price_generics ?? null, 'required' => false, 'class' => 'form-control-sm'])
</div>
<div class="col-lg-1">
{{ Form::label('quantity', 'Quantité') }}<br/>
@include('components.number', ['name' => 'prices[0][quantity]', 'value' => $quantity ?? 1, 'required' => true, 'class' => 'form-control-sm'])
</div>
<div class="col-lg-4">
@include('Shop.Admin.Articles.partials.prices.block_attribute_new')
</div>
<div class="col-lg-6">
<div class="col-2">
{{ Form::label('tax_id', 'TVA') }}<br/>
@include('components.select', ['name' => 'prices[0][tax_id]', 'value' => $tax_id ?? null, 'list' => $taxes_options ?? null, 'required' => true, 'class' => 'form-control form-control-sm'])
</div>
<div class="col-3">
{{ Form::label('price', 'Prix HT') }}
@include('components.money', ['name' => 'prices[0][price]', 'value' => $price ?? 0, 'required' => true, 'class' => 'form-control-sm price-item'])
</div>
<div class="col-3">
{{ Form::label('price_taxed', 'Prix TTC') }}
@include('components.money', ['name' => 'prices[0][price_taxed]', 'value' => $price_taxed ?? 0, 'required' => true, 'class' => 'form-control-sm price-taxed-item'])
</div>
</div>
<div class="col-lg-1 text-right">
<br/>
<button type="button" class="btn btn-xs btn-danger delete-new-price-btn mt-2" data-card-widget="collapse" data-toggle="tooltip" title="supprimer">
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
</div>
</div>

View File

@@ -0,0 +1,52 @@
@include('Shop.Admin.Articles.partials.generic_prices.block_generic_price_new')
<div id="append_generic_price" class="row">
@include('Shop.Admin.Articles.partials.generic_prices.list-generic_prices')
</div>
<button type="button" class="btn btn-sm btn-primary add-new-generic_price">Associer un tarif générique<i class="fa fa-plus"></i></button>
@include('components.select-tree', ['name' => "article_price_generic_id", 'value' => $price['article_price_generic_id'] ?? null, 'list' => $price_generics ?? null, 'required' => false, 'class' => 'form-control-sm w-100'])
@push('js')
<script>
function append_generic_price() {
// handle_append_attribute();
$('.select2').select2();
// handle_change_attribute();
// load_attribute_values($('.attributes-value'), $('.attributes-family').val());
}
$("#append_generic_price").appender({
rowSection: '.row-new-generic_price',
type: '.row-generic_price',
addBtn: '.add-new-generic_price',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-generic_price-number',
deleteBtn: '.delete-new-generic_price-btn',
callback: append_generic_price,
rowNumberStart: 2,
hideSection: true
});
function handle_delete_generic_price() {
$('.delete-generic_price-btn').click(function() {
var $selector = $(this).parents('.row-generic_price');
var id = $selector.find('.generic_price_id').val();
/*
confirm_delete(id, "{## route('Shop.Admin.ArticlePrices.destroy') }}", function() {
$selector.remove();
});
*/
});
}
</script>
@endpush

View File

@@ -1,115 +1,2 @@
@include('Shop.Admin.Articles.partials.prices.block_price_new')
<div id="append_price" class="row">
@include('Shop.Admin.Articles.partials.prices.list-prices')
</div>
<button type="button" class="btn btn-sm btn-primary add-new-price">Ajouter un tarif <i class="fa fa-plus"></i></button>
@push('js')
<script>
function append_price() {
// handle_append_attribute();
$('.select2').select2();
handle_change_attribute();
load_attribute_values($('.attributes-value'), $('.attributes-family').val());
}
$("#append_price").appender({
rowSection: '.row-new-price',
type: '.row-price',
addBtn: '.add-new-price',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-price-number',
deleteBtn: '.delete-new-price-btn',
callback: append_price,
rowNumberStart: 2,
hideSection: true
});
function append_attribute() {
}
function handle_append_attribute(selector) {
console.log('handle_append_attribute');
$(".append_attribute").appender({
rowSection: '.row-new-attribute',
type: '.row-attribute',
addBtn: '.add-new-attribute',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-attribute-number',
deleteBtn: '.delete-new-attribute-btn',
callback: append_attribute,
rowNumberStart: 2,
hideSection: true
});
}
function handle_change_attribute() {
$('.attributes-family').change( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.attributes-value');
load_attribute_values($selector, family_id);
});
}
function init_attribute_values() {
$('.attributes-family').each( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.attributes-value');
load_attribute_values($selector, family_id);
value_id = $selector.data('id');
$selector.val(value_id).trigger('change');
});
}
function load_attribute_values($selector, family_id) {
$.ajax({
url : "{{ route('Shop.Admin.PriceFamilyValues.getOptionsByFamily') }}",
method : 'POST',
data: { family_id: family_id },
success : function(data) {
$selector.empty().select2({data: data});
}
});
}
function handle_delete_price() {
$('.delete-price-btn').click(function() {
var $selector = $(this).parents('.row-price');
var id = $selector.find('.price_id').val();
confirm_delete(id, laroute.route('Shop.Admin.ArticlePrices.destroy', {id : id}), function() {
$selector.remove();
});
});
}
function handle_prices() {
$('.price-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
price_taxed = $(this).val() * (1 + (tax_selected / 100));
$(this).parent().parent().find('.price-taxed-item').val(price_taxed);
})
}
function handle_prices_taxed() {
$('.price-taxed-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
console.log($(this).parent().prev());
price = $(this).val() / (1 + (tax_selected / 100));
$(this).parent().parent().find('.price-item').val(price);
})
}
</script>
@endpush
@include('Shop.Admin.Articles.partials.prices.prices', ['prices' => $prices['prices'] ?? null])
@include('Shop.Admin.Articles.partials.generic_prices.generic_prices', ['generics' => $prices['generics'] ?? null])

View File

@@ -1,24 +0,0 @@
<div class="row row-attribute">
<div class="col-12 col-lg-7">
{{ Form::label('attribute_family_id', 'Type') }}<br/>
@include('components.select', [
'name' => "prices[$key][price_family_id]",
'value' => $price['price_family_id'] ?? null,
'list' => $attribute_families_options,
'required' => true,
'class' => 'select2 form-control-sm attributes-family'
])
</div>
<div class="col-12 col-lg-5">
{{ Form::label('attribute_value_id', 'Unité') }}<br/>
@include('components.select', [
'name' => "prices[$key][unity_id]",
'value' => $price['unity_id'] ?? null,
'list' => $unities ?? null,
'required' => true,
'class' => 'select2 form-control-sm attributes-value w-100',
])
</div>
</div>

View File

@@ -1,24 +0,0 @@
<div class="row row-new-attribute row-attribute">
<input type="hidden" name="prices[][attribute][quantity]" value="1">
<div class="col-12 col-lg-6 1">
{{ Form::label('attribute_family_id', 'Attributs') }}<br/>
@include('components.select', [
'name' => 'prices[][attribute][attribute_family_id]',
'value' => $attribute_value['article_attribute_family_id'] ?? null,
'list' => $attribute_families_options,
'required' => true,
'class' => 'select2 form-control-sm attributes-family'
])
</div>
<div class="col-12 col-lg-6 2">
{{ Form::label('attribute_value_id', 'Valeur') }}<br/>
@include('components.select', [
'name' => 'prices[][attribute][attribute_value_id]',
'value' => $attribute_value['id'] ?? null,
'list' => $attribute_values ?? null,
'required' => true,
'class' => 'select2 form-control-sm attributes-value'
])
</div>
</div>

View File

@@ -6,35 +6,37 @@
<div class="card-body pt-2">
<div class="row">
<div class="col-lg-1">
{{ Form::label('quantity', 'Qté.') }}<br/>
@include('components.number', ['name' => "prices[$key][quantity]", 'value' => $price['quantity'] ?? 1, 'required' => true, 'class' => 'form-control-sm'])
</div>
<div class="col-lg-11">
<div class="col-lg-5">
{{ Form::label('unity_id', 'Unité') }}<br/>
@include('components.select', [
'name' => "prices[$key][unity_id]",
'value' => $price['unity_id'] ?? null,
'list' => $unities ?? null,
'required' => true,
'class' => 'select2 form-control-sm unities w-100',
])
</div>
<div class="col-lg-5">
<div class="row">
<div class="col-lg-1">
{{ Form::label('quantity', 'Qté.') }}<br/>
@include('components.number', ['name' => "prices[$key][quantity]", 'value' => $price['quantity'] ?? 1, 'required' => true, 'class' => 'form-control-sm'])
<div class="col-4">
{{ Form::label('tax_id', 'TVA') }}<br/>
@include('components.select', ['name' => "prices[$key][tax_id]", 'value' => $price['tax_id'] ?? null, 'list' => $taxes_options ?? null, 'required' => true, 'class' => 'form-control form-control-sm'])
</div>
<div class="col-lg-6">
@include('Shop.Admin.Articles.partials.prices.block_attribute')
<div class="col-4">
{{ Form::label('price', 'Prix HT') }}
@include('components.money', ['name' => "prices[$key][price]", 'value' => $price['price'] ?? 0, 'required' => true, 'class' => 'form-control-sm price-item'])
</div>
<div class="col-lg-5">
<div class="row">
<div class="col-4">
{{ Form::label('tax_id', 'TVA') }}<br/>
@include('components.select', ['name' => "prices[$key][tax_id]", 'value' => $price['tax_id'] ?? null, 'list' => $taxes_options ?? null, 'required' => true, 'class' => 'form-control form-control-sm'])
</div>
<div class="col-4">
{{ Form::label('price', 'Prix HT') }}
@include('components.money', ['name' => "prices[$key][price]", 'value' => $price['price'] ?? 0, 'required' => true, 'class' => 'form-control-sm price-item'])
</div>
<div class="col-4">
{{ Form::label('price_taxed', 'Prix TTC') }}
@include('components.money', ['name' => "prices[$key][price_taxed]", 'value' => $price['price_taxed'] ?? 0, 'required' => true, 'class' => 'form-control-sm price-taxed-item'])
</div>
</div>
<div class="col-4">
{{ Form::label('price_taxed', 'Prix TTC') }}
@include('components.money', ['name' => "prices[$key][price_taxed]", 'value' => $price['price_taxed'] ?? 0, 'required' => true, 'class' => 'form-control-sm price-taxed-item'])
</div>
</div>
</div>
@@ -45,10 +47,7 @@
<i class="fas fa-trash"></i>
</button>
</div>
</div>
</div>
</div>
</div>

View File

@@ -7,35 +7,39 @@
<div class="row">
<div class="col-lg-3">
{{ Form::label('price_generic_id', 'Générique') }}<br/>
@include('components.select-tree', ['name' => "prices[0][article_price_generic_id]", 'value' => $price['article_price_generic_id'] ?? null, 'list' => $price_generics ?? null, 'required' => false, 'class' => 'form-control-sm'])
</div>
<div class="col-lg-1">
{{ Form::label('quantity', 'Quantité') }}<br/>
@include('components.number', ['name' => 'prices[0][quantity]', 'value' => $quantity ?? 1, 'required' => true, 'class' => 'form-control-sm'])
</div>
<div class="col-lg-4">
@include('Shop.Admin.Articles.partials.prices.block_attribute_new')
<div class="col-lg-5">
{{ Form::label('unity_id', 'Unité') }}<br/>
@include('components.select', [
'name' => "prices[0][unity_id]",
'value' => $price['unity_id'] ?? null,
'list' => $unities ?? null,
'required' => true,
'class' => 'select2 form-control-sm unities w-100',
])
</div>
<div class="col-lg-6">
<div class="col-lg-5">
<div class="col-2">
{{ Form::label('tax_id', 'TVA') }}<br/>
@include('components.select', ['name' => 'prices[0][tax_id]', 'value' => $tax_id ?? null, 'list' => $taxes_options ?? null, 'required' => true, 'class' => 'form-control form-control-sm'])
</div>
<div class="row">
<div class="col-4">
{{ Form::label('tax_id', 'TVA') }}<br/>
@include('components.select', ['name' => 'prices[0][tax_id]', 'value' => $tax_id ?? null, 'list' => $taxes_options ?? null, 'required' => true, 'class' => 'form-control form-control-sm'])
</div>
<div class="col-3">
{{ Form::label('price', 'Prix HT') }}
@include('components.money', ['name' => 'prices[0][price]', 'value' => $price ?? 0, 'required' => true, 'class' => 'form-control-sm price-item'])
</div>
<div class="col-4">
{{ Form::label('price', 'Prix HT') }}
@include('components.money', ['name' => 'prices[0][price]', 'value' => $price ?? 0, 'required' => true, 'class' => 'form-control-sm price-item'])
</div>
<div class="col-3">
{{ Form::label('price_taxed', 'Prix TTC') }}
@include('components.money', ['name' => 'prices[0][price_taxed]', 'value' => $price_taxed ?? 0, 'required' => true, 'class' => 'form-control-sm price-taxed-item'])
<div class="col-4">
{{ Form::label('price_taxed', 'Prix TTC') }}
@include('components.money', ['name' => 'prices[0][price_taxed]', 'value' => $price_taxed ?? 0, 'required' => true, 'class' => 'form-control-sm price-taxed-item'])
</div>
</div>
</div>

View File

@@ -0,0 +1,96 @@
@include('Shop.Admin.Articles.partials.prices.block_price_new')
<div id="append_price" class="row">
@include('Shop.Admin.Articles.partials.prices.list-prices')
</div>
<button type="button" class="btn btn-sm btn-primary add-new-price">Ajouter un tarif <i class="fa fa-plus"></i></button>
@push('js')
<script>
function append_price() {
// handle_append_attribute();
$('.select2').select2();
handle_change_attribute();
load_attribute_values($('.unities'), $('.price-family').val());
}
$("#append_price").appender({
rowSection: '.row-new-price',
type: '.row-price',
addBtn: '.add-new-price',
appendEffect: 'slide',
addClass: 'animated bounceInLeft',
rowNumber: '.row-price-number',
deleteBtn: '.delete-new-price-btn',
callback: append_price,
rowNumberStart: 2,
hideSection: true
});
function handle_change_attribute() {
$('.price-family').change( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.unities');
load_attribute_values($selector, family_id);
});
}
function init_attribute_values() {
$('.price-family').each( function() {
var family_id = $(this).val();
var $family = $(this);
var $parent = $family.parent().parent();
var $selector = $parent.find('.unities');
load_attribute_values($selector, family_id);
value_id = $selector.data('id');
$selector.val(value_id).trigger('change');
});
}
function load_attribute_values($selector, family_id) {
$.ajax({
url : "{{ route('Shop.Admin.Unities.getOptionsByFamily') }}",
method : 'POST',
data: { family_id: family_id },
success : function(data) {
$selector.empty().select2({data: data});
}
});
}
function handle_delete_price() {
$('.delete-price-btn').click(function() {
var $selector = $(this).parents('.row-price');
var id = $selector.find('.price_id').val();
confirm_delete(id, laroute.route('Shop.Admin.ArticlePrices.destroy', {id : id}), function() {
$selector.remove();
});
});
}
function handle_prices() {
$('.price-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
price_taxed = $(this).val() * (1 + (tax_selected / 100));
$(this).parent().parent().find('.price-taxed-item').val(price_taxed);
})
}
function handle_prices_taxed() {
$('.price-taxed-item').change(function() {
tax_selected = $(this).parent().prev().find('select option:selected').text();
console.log($(this).parent().prev());
price = $(this).val() / (1 + (tax_selected / 100));
$(this).parent().parent().find('.price-item').val(price);
})
}
</script>
@endpush

View File

@@ -1,23 +1,25 @@
<table class="table table-bordered table-hover table-striped w-100 mb-0 dataTable">
@if (count($generic['prices'] ?? []))
<table class="table table-bordered table-hover table-striped w-100 mb-0 dataTable">
<thead>
<th>
{{ $generic['category']['name'] ?? null }}
</th>
@foreach ($generic['prices'] as $price)
<th>
{{ $price['quantity'] ?? null }} {{ $price['unity_id'] ?? null }}
</th>
@endforeach
</thead>
<tr>
<td>
{{ $generic['name'] ?? null }}
</td>
@foreach ($generic['prices'] as $price)
<td>
{{ $price['price_taxed'] ?? null }}
</td>
@endforeach
</tr>
</table>
<thead>
<th>
{{ $generic['category']['name'] ?? null }}
</th>
@foreach ($generic['prices'] as $price)
<th>
{{ $price['quantity'] ?? null }} {{ $price['unity_id'] ?? null }}
</th>
@endforeach
</thead>
<tr>
<td>
{{ $generic['name'] ?? null }}
</td>
@foreach ($generic['prices'] as $price)
<td>
{{ $price['price_taxed'] ?? null }}
</td>
@endforeach
</tr>
</table>
@endif