Files
opensem/resources/views/Shop/Admin/PriceGenerics/partials/prices.blade.php
Ludovic CANDELLIER bba5f6d984 Fixes
2021-04-05 23:58:37 +02:00

103 lines
2.8 KiB
PHP

@include('Shop.Admin.PriceGenerics.partials.block_price_new')
<div id="append_price" class="row">
@include('Shop.Admin.PriceGenerics.partials.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_prices();
handle_prices_taxed();
handle_change_package();
// handle_append_attribute();
// $('.select2').select2();
}
$("#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_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.PriceGenericValues.destroy', {id : id}), function() {
$selector.remove();
});
});
}
function handle_prices() {
$('.price-item').change(function() {
$col_tax = $(this).parent().prev();
tax_selected = $col_tax.find('select option:selected').text();
price_taxed = $(this).val() * (1 + (tax_selected / 100));
price_taxed = price_taxed.toFixed(2);
$(this).parent().parent().find('.price-taxed-item').val(price_taxed);
})
}
function handle_prices_taxed() {
$('.price-taxed-item').change(function() {
$col_tax = $(this).parent().prev().prev();
tax_selected = $col_tax.find('select option:selected').text();
price = $(this).val() / (1 + (tax_selected / 100));
price = price.toFixed(2);
$(this).parent().parent().find('.price-item').val(price);
})
}
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('Shop.Admin.Unities.getOptionsByPackage') }}",
method : 'POST',
data: { package_id: package_id },
success : function(data) {
setOptions($selector, data);
// $selector.empty().select2({data: data});
}
});
}
</script>
@endpush