Rename Admin views directory, add some functions on models

This commit is contained in:
Ludovic CANDELLIER
2021-07-27 22:12:58 +02:00
parent daeece59c9
commit 9a0601d473
229 changed files with 81 additions and 349 deletions

View File

@@ -0,0 +1,4 @@
<div id="attributes" class="appender" data-id="">
@include('Admin.Shop.Articles.partials.prices.block_attribute_new')
<div class="append_attribute"></div>
</div>

View File

@@ -0,0 +1,75 @@
<div class="col-12 row-price">
<input type="hidden" name="prices[{{ $key }}][id]" value="@if (isset($price['id'])){{ $price['id'] }}@endif" class="price_id">
<div class="card card-light">
<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-3">
{{ Form::label('package_id', 'Type Package') }}<br/>
@include('components.select', [
'name' => "prices[$key][package_id]",
'value' => $price['package_id'] ?? null,
'list' => $packages ?? null,
'required' => true,
'class' => 'select2 form-control-sm packages w-100',
])
</div>
<div class="col-lg-1">
{{ Form::label('package_qty', 'Pack Qté') }}<br/>
@include('components.number', [
'name' => "prices[$key][package_quantity]",
'value' => $price['package_quantity'] ?? null,
'required' => true,
'class' => 'form-control-sm',
])
</div>
<div class="col-lg-3">
{{ 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',
'with_empty' => ''
])
</div>
<div class="col-lg-3">
<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>
<div class="col-lg-1 text-right">
<br/>
<button type="button" class="btn btn-xs btn-danger delete-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,80 @@
<div class="col-12 row-new-price row-price">
<input type="hidden" name="prices[0][article_id]" value="{{ $id ?? null }}">
<div class="card card-light">
<div class="card-body pt-2">
<div class="row">
<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-3">
{{ Form::label('package_id', 'Type Package') }}<br/>
@include('components.select', [
'name' => "prices[0][package_id]",
'value' => $price['package_id'] ?? null,
'list' => $packages ?? null,
'required' => true,
'class' => 'select2 form-control-sm packages w-100',
])
</div>
<div class="col-lg-1">
{{ Form::label('package_qty', 'Pack Qté') }}<br/>
@include('components.number', [
'name' => "prices[0][package_quantity]",
'value' => $price['package_quantity'] ?? null,
'required' => true,
'class' => 'form-control-sm',
])
</div>
<div class="col-lg-3">
{{ 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',
'with_empty' => ''
])
</div>
<div class="col-lg-3">
<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-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-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>
<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,18 @@
@if (isset($prices) && (count($prices)))
@for ($i = 0; $i < count($prices); $i++)
@include('Admin.Shop.Articles.partials.prices.block_price', ['key' => $i, 'price' => $prices[$i]])
@endfor
@endif
@push('js')
<script>
$(function () {
handle_delete_price();
init_unities();
handle_change_package();
handle_prices();
handle_prices_taxed();
});
</script>
@endpush

View File

@@ -0,0 +1,98 @@
@include('Admin.Shop.Articles.partials.prices.block_price_new')
<div id="append_price" class="row">
@include('Admin.Shop.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() {
$('.select2').select2();
handle_change_package();
load_unities($('.unities'), $('.packages').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_package() {
$('.packages').change( function() {
var package_id = $(this).val();
var $package = $(this);
var $parent = $package.parent().parent();
var $selector = $parent.find('.unities');
load_unities($selector, package_id);
});
}
function init_unities() {
$('.packages').each( function() {
var package_id = $(this).val();
var $package = $(this);
var $parent = $package.parent().parent();
var $selector = $parent.find('.unities');
load_unities($selector, package_id);
value_id = $selector.data('id');
$selector.val(value_id).trigger('change');
});
}
function load_unities($selector, package_id) {
$.ajax({
url : "{{ route('Admin.Shop.Unities.getOptionsByPackage') }}",
method : 'POST',
data: { package_id: package_id },
success : function(data) {
setOptions($selector, 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('Admin.Shop.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);
})
}
$(function() {
handle_change_package();
});
</script>
@endpush