Miglioramenti sulla duplicazione articoli

Suggerimenti da issue #834 e #814
This commit is contained in:
Thomas Zilio 2020-07-31 08:44:05 +02:00
parent 06348886a2
commit edab9a2367
3 changed files with 48 additions and 14 deletions

View File

@ -161,10 +161,13 @@ switch (post('op')) {
// Duplica articolo
case 'copy':
$new = $articolo->replicate();
$new->codice = post('codice');
$new->qta = 0;
$new->save();
// Copia degli allegati
$copia_allegati = post('copia_allegati');
if (!empty($copia_allegati)) {
$allegati = $articolo->uploads();
foreach ($allegati as $allegato) {
$allegato->copia([
@ -172,6 +175,7 @@ switch (post('op')) {
'id_record' => $new->id,
]);
}
}
// Salvataggio immagine relativa
$nome_immagine = $articolo->immagine_upload->name;

View File

@ -3,12 +3,12 @@
include_once __DIR__.'/../../core.php';
echo '
<form action="" class="text-right" method="post" id="form-copy">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="copy">
</form>
<button type="button" class="btn btn-primary" onclick="if( confirm(\'Duplicare questo articolo?\') ){ $(\'#form-copy\').submit(); }">
<button type="button" class="btn btn-primary" onclick="duplicaArticolo()">
<i class="fa fa-copy"></i> '.tr('Duplica articolo').'
</button>';
</button>
<script>
function duplicaArticolo() {
openModal("'.tr('Duplica articolo').'", "'.$module->fileurl('modals/duplicazione.php').'?id_module='.$id_module.'&id_record='.$id_record.'");
}
</script>';

View File

@ -0,0 +1,30 @@
<?php
include_once __DIR__.'/../../../core.php';
echo '
<form action="" method="post" id="form-copy">
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="copy">
<div class="row">
<div class="col-md-9">
{[ "type": "text", "label": "'.tr('Codice').'", "name": "codice", "required": 1, "value": "", "validation": "codice" ]}
</div>
<div class="col-md-3">
{[ "type": "checkbox", "label": "'.tr('Copia allegati').'", "name": "copia_allegati", "value": 1 ]}
</div>
</div>
<!-- PULSANTI -->
<div class="row">
<div class="col-md-12 text-right">
<button type="submit" class="btn btn-primary">
<i class="fa fa-copy"></i>
'.tr('Duplica').'
</button>
</div>
</div>
</form>';