107 lines
5.2 KiB
PHP
107 lines
5.2 KiB
PHP
@extends('back::layout')
|
|
|
|
@section('title',
|
|
Str::of(__('validation.custom.unique_code'))->plural()->ucfirst())
|
|
@section('description', __('Générer des codes uniques'))
|
|
|
|
@section('content')
|
|
<div class="d-flex justify-content-between flex-md-nowrap align-items-center mb-3 flex-wrap">
|
|
@include('modules.breadcrumbs.breadcrumb-body')
|
|
@can('export', \App\Models\Code::class)
|
|
<button class="btn btn-success float-right" data-bs-toggle="modal" data-bs-target="#exportModal" type="button">
|
|
<i class="fas fa-file-export"></i> {{ __('Export') }}
|
|
</button>
|
|
@endcan
|
|
</div>
|
|
@can('search', \App\Models\Code::class)
|
|
@include('back::pages.codes.search-form')
|
|
@endcan
|
|
<hr>
|
|
<form action="{{ route('bo.codes.generate') }}" method="POST">
|
|
@csrf
|
|
<div class="card-body">
|
|
<p>{{ __('Nombre de code(s)') }}</p>
|
|
<ul class="list-unstyled">
|
|
<li>{{ Str::ucfirst(__('en base')) }} : <strong>{{ $nbCodeBase }}</strong></li>
|
|
<li>{{ Str::ucfirst(__('utilisé(s)')) }} : <strong>{{ $nbCodeUsed }}</strong></li>
|
|
<li>{{ Str::ucfirst(__('déjà exporté(s)')) }} : <strong>{{ $nbCodeExported }}</strong></li>
|
|
<li>{{ Str::ucfirst(__('restant à exporté(s)')) }} : <strong>{{ $nbCodeRemainingToExport }}</strong></li>
|
|
</ul>
|
|
<hr />
|
|
@include('back::pages.codes.form-inputs')
|
|
<small>{{ __('Il est possible de générer') }} <span class="text-danger"
|
|
id="maxCodes">0</span> {{ __('codes uniques.') }}</small><br>
|
|
<small class="text-muted">{{ __('!! Si la longueur des codes est changé l\'export pourra prendre plus de temps. !!') }}</small>
|
|
</div>
|
|
<div class="card-footer text-center">
|
|
<button class="btn btn-success" type="submit"><i class="fas fa-cog"></i> {{ __('Générer') }}</button>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- Export Modal -->
|
|
<div class="modal fade" id="exportModal" aria-labelledby="exportModalLabel" aria-hidden="true" tabindex="-1">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="exportModalLabel">{{ __('Export des codes uniques') }}</h5>
|
|
<button class="btn-close" data-bs-dismiss="modal" type="button" aria-label="Close"></button>
|
|
</div>
|
|
<form method="POST" action="{{ route('bo.codes.export') }}">
|
|
@csrf
|
|
<div class="modal-body">
|
|
<div class="form-group form-row">
|
|
<label class="col-form-label col" for="nb_code_tot">{{ __('Nombre total de codes à exporter') }}</label>
|
|
<input class="form-control col" id="nb_code_tot" name="nb_code_tot" type="number" required>
|
|
</div>
|
|
<div class="form-group form-row">
|
|
<label class="col-form-label col" for="nb_code_fic">{{ __('Nombre de codes par fichier') }}</label>
|
|
<input class="form-control col" id="nb_code_fic" name="nb_code_fic" type="number" required>
|
|
</div>
|
|
<div class="form-group form-row">
|
|
<label class="col-form-label col" for="nb_code_ligne">{{ __('Nombre de codes par ligne') }}</label>
|
|
<input class="form-control col" id="nb_code_ligne" name="nb_code_ligne" type="number" required>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button class="btn btn-sm btn-secondary" data-bs-dismiss="modal" type="button">{{ __('Fermer') }}</button>
|
|
<button class="btn btn-sm btn-success" type="submit">{{ __('Lancer l\'export') }}</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
@endsection
|
|
|
|
@push('scripts')
|
|
<script nonce="{{ $nonce }}">
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const codeLenghtInput = document.getElementById('codeGenerationLength'),
|
|
smallWarning = document.getElementById('maxCodes')
|
|
|
|
/**
|
|
* Fonction factorielle
|
|
*/
|
|
const fact = (nbr) => {
|
|
let i, f = 1
|
|
for (i = 1; i <= nbr; i++) {
|
|
f = f * i; // ou f *= i;
|
|
}
|
|
return f;
|
|
}
|
|
const calculateMax = () => {
|
|
const p = Number.parseInt({{ strlen(config('codes.codeCharList')) }}),
|
|
n = codeLenghtInput.value
|
|
return Math.pow(p, n) - 1 - Number.parseInt({{ $nbCodeBase }});
|
|
}
|
|
const numberWithCommas = (x) => {
|
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
}
|
|
|
|
smallWarning.innerText = numberWithCommas(calculateMax())
|
|
|
|
codeLenghtInput.addEventListener('input', () => {
|
|
smallWarning.innerText = numberWithCommas(calculateMax())
|
|
})
|
|
});
|
|
</script>
|
|
@endpush
|