Implement discount calculations that apply to the piece (sold unit) for products invoiced by weight.
180 lines
7.4 KiB
PHP
180 lines
7.4 KiB
PHP
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="mb-3 border p-3">
|
|
<legend>{{ __('Promotion configuration') }}</legend>
|
|
<div class="row mb-3">
|
|
|
|
{{-- DISCOUNT TYPE --}}
|
|
<div class="col-12 col-md-6 form-group">
|
|
<label class="col-form-label" for="discount-type">
|
|
<b>{{ Str::ucfirst(__('validation.custom.attributes.discount_type')) }}*</b>
|
|
</label>
|
|
<select class="form-select" id="discount-type" name="type" required>
|
|
<option value="" @if (!old('type', $discount->type ?? null)) selected @endif disabled>
|
|
{{ __('Select') . ' ' . __('validation.custom.attributes.discount_type') }}
|
|
</option>
|
|
@foreach ($discountTypes as $type)
|
|
<option value="{{ $type->value() }}" @selected(old('type', optional($discount ?? null)->type?->value() ?? null) == $type->value())>
|
|
{{ $type->label() }}
|
|
</option>
|
|
@endforeach
|
|
</select>
|
|
@include('bo.modules.input-error', ['inputName' => 'type'])
|
|
</div>
|
|
|
|
{{-- DISCOUNT VALUE --}}
|
|
@php
|
|
$isPercent = old('type', optional($discount ?? null)->type?->value()) == \Domain\Enums\DiscountType::PERCENT->value;
|
|
$isAmount = old('type', optional($discount ?? null)->type?->value()) == \Domain\Enums\DiscountType::AMOUNT->value;
|
|
@endphp
|
|
|
|
<div class="col-12 col-md-6 form-group">
|
|
<span class="col-form-label">
|
|
<b>{{ Str::ucfirst(__('validation.custom.attributes.discount_value')) }}*</b>
|
|
<span data-bs-toggle="tooltip" title="{{ __('The discount applies to the piece (sold unit).') }}">
|
|
<i class="fas fa-question-circle"></i>
|
|
</span>
|
|
</span>
|
|
|
|
{{-- INPUT MONTANT --}}
|
|
<div class="input-group {{ $isAmount ? '' : 'd-none' }} mb-3" id="wrapper-discount-amount">
|
|
<input class="form-control" id="discount-value-amount" name="value" data-money-input type="number"
|
|
value="{{ $isAmount ? old('value', $discount->value?->value()->getAmount() ?? '') : '' }}" step="0.01" min="0"
|
|
aria-describedby="discount-value-help" {{ $isAmount ? 'required' : 'disabled' }}>
|
|
<span class="input-group-text">@currency()</span>
|
|
</div>
|
|
|
|
{{-- INPUT POURCENT --}}
|
|
<div class="input-group {{ $isPercent ? '' : 'd-none' }} mb-3" id="wrapper-discount-percent">
|
|
<input class="form-control" id="discount-value-percent" name="value" type="number"
|
|
value="{{ $isPercent ? old('value', $discount->value?->value() ?? '') : '' }}" step="1" min="0"
|
|
max="100" aria-describedby="discount-value-help" {{ $isPercent ? 'required' : 'disabled' }}>
|
|
<span class="input-group-text">%</span>
|
|
</div>
|
|
|
|
@include('bo.modules.input-error', [
|
|
'inputName' => 'value',
|
|
'helperId' => 'discount-value-help',
|
|
'helper' => __('The discount applies to the piece (sold unit).'),
|
|
])
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class="row mb-3">
|
|
{{-- IS OLD PRICE DISPLAYED --}}
|
|
<div class="col-12 form-group pt-3">
|
|
<input class="form-check-input mt-2" id="is-old-price-displayed" name="is_old_price_displayed" type="checkbox" value="1"
|
|
@checked(old('is_old_price_displayed', $discount->is_old_price_displayed ?? '0'))>
|
|
<label class="col-form-label form-check-label pt-1" for="is-old-price-displayed">
|
|
<b>{{ Str::ucfirst(__('validation.custom.attributes.is_old_price_displayed')) }}</b>
|
|
</label><br>
|
|
@include('bo.modules.input-error', ['inputName' => 'is_old_price_displayed'])
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="mb-3 border p-3">
|
|
<legend>{{ __('Validity period') }}</legend>
|
|
<div class="row mb-3">
|
|
|
|
{{-- DATE START --}}
|
|
<div class="col-12 col-md-6 form-group">
|
|
<label class="col-form-label" for="date-start">
|
|
<b>{{ Str::ucfirst(__('validation.custom.attributes.date_start_show')) }}</b>
|
|
</label>
|
|
<input class="form-control" id="date-start" name="date_start" type="datetime-local"
|
|
value="{{ old('date_start', Date::toLocalInput($discount->date_start ?? '')) }}">
|
|
@include('bo.modules.input-error', ['inputName' => 'date_start'])
|
|
</div>
|
|
|
|
{{-- DATE END --}}
|
|
<div class="col-12 col-md-6 form-group">
|
|
<label class="col-form-label" for="date-end">
|
|
<b>{{ Str::ucfirst(__('validation.custom.attributes.date_end_show')) }}</b>
|
|
</label>
|
|
<input class="form-control" id="date-end" name="date_end" type="datetime-local"
|
|
value="{{ old('date_end', Date::toLocalInput($discount->date_end ?? '')) }}">
|
|
@include('bo.modules.input-error', ['inputName' => 'date_end'])
|
|
</div>
|
|
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row">
|
|
<div class="col">
|
|
<fieldset class="mb-3 border p-3">
|
|
<legend><span class="h4">{{ Str::ucfirst(__('validation.custom.attributes.associated_products')) }}</span></legend>
|
|
|
|
<div class="row">
|
|
<div class="col form-group">
|
|
@php
|
|
$json = [
|
|
'name' => 'associated_products',
|
|
'available' => $existingProds ?? [],
|
|
'selected' => $selectedProds ?? [],
|
|
];
|
|
@endphp
|
|
|
|
<div id="product-drag-and-drop" data-json='@json($json)'></div>
|
|
|
|
@include('bo.modules.input-error', [
|
|
'inputName' => 'associated_products',
|
|
'helperId' => 'associated-products-help',
|
|
'helper' => __('Drag and drop products to associate them.'),
|
|
])
|
|
</div>
|
|
</div>
|
|
</fieldset>
|
|
</div>
|
|
</div>
|
|
<input id="client-timezone" name="client_timezone" type="hidden">
|
|
|
|
@push('scripts')
|
|
<script nonce="{{ Vite::cspNonce() }}">
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const tz = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
document.getElementById('client-timezone').value = tz;
|
|
});
|
|
</script>
|
|
@endpush
|
|
|
|
@push('scripts')
|
|
<script nonce="{{ Vite::cspNonce() }}">
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const typeSelect = document.getElementById('discount-type');
|
|
const amountWrapper = document.getElementById('wrapper-discount-amount');
|
|
const percentWrapper = document.getElementById('wrapper-discount-percent');
|
|
|
|
function toggleDiscountInput() {
|
|
const isPercent = typeSelect.value === '{{ \Domain\Enums\DiscountType::PERCENT->value() }}';
|
|
|
|
if (isPercent) {
|
|
amountWrapper.classList.add('d-none');
|
|
amountWrapper.querySelectorAll('input').forEach(i => i.disabled = true);
|
|
|
|
percentWrapper.classList.remove('d-none');
|
|
percentWrapper.querySelectorAll('input').forEach(i => i.disabled = false);
|
|
} else {
|
|
percentWrapper.classList.add('d-none');
|
|
percentWrapper.querySelectorAll('input').forEach(i => i.disabled = true);
|
|
|
|
amountWrapper.classList.remove('d-none');
|
|
amountWrapper.querySelectorAll('input').forEach(i => i.disabled = false);
|
|
}
|
|
}
|
|
|
|
typeSelect.addEventListener('change', toggleDiscountInput);
|
|
|
|
if (typeSelect.value) {
|
|
toggleDiscountInput();
|
|
}
|
|
});
|
|
</script>
|
|
@endpush
|