Aggiunta selezione righe nei documenti per eliminazione e duplicazione

This commit is contained in:
MatteoPistorello 2022-04-01 09:58:53 +02:00
parent 9cf9c7e4ba
commit a3bfaa5fc3
12 changed files with 899 additions and 171 deletions

View File

@ -299,16 +299,40 @@ switch (post('op')) {
// Eliminazione riga
case 'delete_riga':
$id_riga = post('riga_id');
$type = post('riga_type');
$riga = $contratto->getRiga($type, $id_riga);
if (!empty($riga)) {
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$riga->delete();
flash()->info(tr('Riga eliminata!'));
$riga = null;
}
flash()->info(tr('Righe eliminate!'));
break;
// Duplicazione riga
case 'copy_riga':
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$new_riga = $riga->replicate();
$new_riga->setDocument($contratto);
$new_riga->qta_evasa = 0;
$new_riga->save();
$riga = null;
}
flash()->info(tr('Righe duplicate!'));
break;
// Scollegamento intervento da contratto

View File

@ -19,11 +19,21 @@
include_once __DIR__.'/init.php';
$block_edit = $record['is_completato'];
$righe = $contratto->getRighe();
echo '
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th width="5" class="text-center">';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<input id="check_all" type="checkbox"/>';
}
echo '
</th>
<th width="35" class="text-center" >'.tr('#').'</th>
<th>'.tr('Descrizione').'</th>
<th class="text-center tip" width="150" title="'.tr('da evadere').' / '.tr('totale').'">'.tr('Q.').' <i class="fa fa-question-circle-o"></i></th>
@ -34,16 +44,23 @@ echo '
</tr>
</thead>
<tbody class="sortable">';
<tbody class="sortable" id="righe">';
// Righe documento
$righe = $contratto->getRighe();
$num = 0;
foreach ($righe as $riga) {
++$num;
echo '
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'">
<td class="text-center">';
if (!$block_edit) {
echo '
<input class="check" type="checkbox"/>';
}
echo '
</td>
<td class="text-center">
'.$num.'
</td>
@ -126,7 +143,7 @@ foreach ($righe as $riga) {
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga(this)">
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga([$(this).closest(\'tr\').data(\'id\')])">
<i class="fa fa-trash"></i>
</a>
@ -156,7 +173,7 @@ $netto_a_pagare = $contratto->netto;
// Totale totale imponibile
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -169,7 +186,7 @@ echo '
if (!empty($sconto)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
<td class="text-right">
@ -181,7 +198,7 @@ if (!empty($sconto)) {
// Totale totale imponibile
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -194,7 +211,7 @@ if (!empty($sconto)) {
// Totale iva
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Iva', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -206,7 +223,7 @@ echo '
// Totale contratto
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -219,7 +236,7 @@ echo '
if (!empty($sconto_finale)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -233,7 +250,7 @@ if (!empty($sconto_finale)) {
if ($totale != $netto_a_pagare) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -244,10 +261,22 @@ if ($totale != $netto_a_pagare) {
}
echo '
</table>
</div>';
</table>';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default disabled" id="elimina_righe" onclick="duplicaRiga(getSelectData());">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="duplica_righe" onclick="rimuoviRiga(getSelectData());">
<i class="fa fa-trash"></i>
</button>
</div>';
}
echo '
</div>
<script>
async function modificaRiga(button) {
let riga = $(button).closest("tr");
@ -265,18 +294,24 @@ async function modificaRiga(button) {
openModal("'.tr('Modifica riga').'", "'.$module->fileurl('row-edit.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&riga_id=" + id + "&riga_type=" + type);
}
function rimuoviRiga(button) {
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'#righe\').find(\'.check:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
function rimuoviRiga(id) {
swal({
title: "'.tr('Rimuovere questa riga?').'",
html: "'.tr('Sei sicuro di volere rimuovere questa riga dal documento?').' '.tr("L'operazione è irreversibile").'.",
title: "'.tr('Rimuovere queste righe?').'",
html: "'.tr('Sei sicuro di volere rimuovere queste righe dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
let riga = $(button).closest("tr");
let id = riga.data("id");
let type = riga.data("type");
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
@ -285,8 +320,35 @@ function rimuoviRiga(button) {
id_module: globals.id_module,
id_record: globals.id_record,
op: "delete_riga",
riga_type: type,
riga_id: id,
righe: id,
},
success: function (response) {
location.reload();
},
error: function() {
location.reload();
}
});
}).catch(swal.noop);
}
function duplicaRiga(id) {
swal({
title: "'.tr('Duplicare queste righe?').'",
html: "'.tr('Sei sicuro di volere queste righe del documento?').'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "copy_riga",
righe: id,
},
success: function (response) {
location.reload();
@ -316,4 +378,37 @@ $(document).ready(function() {
});
});
});
$(".check").on("change", function() {
let checked = 0;
$(".check").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#elimina_righe").removeClass("disabled");
$("#duplica_righe").removeClass("disabled");
} else {
$("#elimina_righe").addClass("disabled");
$("#duplica_righe").addClass("disabled");
}
});
$("#check_all").click(function(){
if( $(this).is(":checked") ){
$(".check").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';

View File

@ -386,24 +386,50 @@ switch (filter('op')) {
break;
// Scollegamento riga generica da ddt
// Eliminazione riga
case 'delete_riga':
$id_riga = post('riga_id');
$type = post('riga_type');
$riga = $ddt->getRiga($type, $id_riga);
if (!empty($riga)) {
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
try {
$riga->delete();
flash()->info(tr('Riga rimossa!'));
} catch (InvalidArgumentException $e) {
flash()->error(tr('Alcuni serial number sono già stati utilizzati!'));
}
$riga = null;
}
ricalcola_costiagg_ddt($id_record);
flash()->info(tr('Righe eliminate!'));
break;
// Duplicazione riga
case 'copy_riga':
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$new_riga = $riga->replicate();
$new_riga->setDocument($ddt);
$new_riga->qta_evasa = 0;
$new_riga->save();
if ($new_riga->isArticolo()) {
$new_riga->movimenta($new_riga->qta);
}
$riga = null;
}
flash()->info(tr('Righe duplicate!'));
break;
@ -474,7 +500,9 @@ switch (filter('op')) {
$copia_riga->save();
// Movimentazione forzata in direzione del documento
$copia_riga->movimenta($riga->qta);
if ($copia_riga->isArticolo()) {
$copia_riga->movimenta($copia_riga->qta);
}
}
// Salvataggio riferimento

View File

@ -19,11 +19,21 @@
include_once __DIR__.'/init.php';
$block_edit = $record['flag_completato'];
$righe = $ddt->getRighe();
echo '
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th width="5" class="text-center">';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<input id="check_all" type="checkbox"/>';
}
echo '
</th>
<th width="35" class="text-center" >'.tr('#').'</th>
<th>'.tr('Descrizione').'</th>
<th class="text-center tip" width="150" title="'.tr('da evadere').' / '.tr('totale').'">'.tr('Q.').' <i class="fa fa-question-circle-o"></i></th>
@ -34,10 +44,9 @@ echo '
</tr>
</thead>
<tbody class="sortable">';
<tbody class="sortable" id="righe">';
// Righe documento
$righe = $ddt->getRighe();
$num = 0;
foreach ($righe as $riga) {
++$num;
@ -59,6 +68,14 @@ foreach ($righe as $riga) {
echo '
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'" '.$extra.'>
<td class="text-center">';
if (!$block_edit) {
echo '
<input class="check" type="checkbox"/>';
}
echo '
</td>
<td class="text-center">
'.$num.'
</td>
@ -174,7 +191,7 @@ foreach ($righe as $riga) {
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga(this)">
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga([$(this).closest(\'tr\').data(\'id\')])">
<i class="fa fa-trash"></i>
</a>
@ -204,7 +221,7 @@ $netto_a_pagare = $ddt->netto;
// IMPONIBILE
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
@ -219,7 +236,7 @@ echo '
if (!empty($sconto)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
@ -233,7 +250,7 @@ if (!empty($sconto)) {
// TOTALE IMPONIBILE
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
@ -248,7 +265,7 @@ if (!empty($sconto)) {
// IVA
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('IVA', [], ['upper' => true]).':</b>
</td>
@ -262,7 +279,7 @@ echo '
// TOTALE
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
@ -277,7 +294,7 @@ echo '
if (!empty($sconto_finale)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -291,7 +308,7 @@ if (!empty($sconto_finale)) {
if ($totale != $netto_a_pagare) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -302,10 +319,22 @@ if ($totale != $netto_a_pagare) {
}
echo '
</table>
</div>';
</table>';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default disabled" id="elimina_righe" onclick="duplicaRiga(getSelectData());">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="duplica_righe" onclick="rimuoviRiga(getSelectData());">
<i class="fa fa-trash"></i>
</button>
</div>';
}
echo '
</div>
<script>
async function modificaRiga(button) {
let riga = $(button).closest("tr");
@ -323,18 +352,24 @@ async function modificaRiga(button) {
openModal("'.tr('Modifica riga').'", "'.$module->fileurl('row-edit.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&riga_id=" + id + "&riga_type=" + type);
}
function rimuoviRiga(button) {
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'#righe\').find(\'.check:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
function rimuoviRiga(id) {
swal({
title: "'.tr('Rimuovere questa riga?').'",
html: "'.tr('Sei sicuro di volere rimuovere questa riga dal documento?').' '.tr("L'operazione è irreversibile").'.",
title: "'.tr('Rimuovere queste righe?').'",
html: "'.tr('Sei sicuro di volere rimuovere queste righe dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
let riga = $(button).closest("tr");
let id = riga.data("id");
let type = riga.data("type");
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
@ -343,8 +378,35 @@ function rimuoviRiga(button) {
id_module: globals.id_module,
id_record: globals.id_record,
op: "delete_riga",
riga_type: type,
riga_id: id,
righe: id,
},
success: function (response) {
location.reload();
},
error: function() {
location.reload();
}
});
}).catch(swal.noop);
}
function duplicaRiga(id) {
swal({
title: "'.tr('Duplicare queste righe?').'",
html: "'.tr('Sei sicuro di volere queste righe del documento?').'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "copy_riga",
righe: id,
},
success: function (response) {
location.reload();
@ -390,4 +452,37 @@ $(document).ready(function() {
});
});
});
$(".check").on("change", function() {
let checked = 0;
$(".check").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#elimina_righe").removeClass("disabled");
$("#duplica_righe").removeClass("disabled");
} else {
$("#elimina_righe").addClass("disabled");
$("#duplica_righe").addClass("disabled");
}
});
$("#check_all").click(function(){
if( $(this).is(":checked") ){
$(".check").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';

View File

@ -631,22 +631,52 @@ switch (post('op')) {
// Scollegamento riga generica da documento
case 'delete_riga':
$id_riga = post('riga_id');
$type = post('riga_type');
$riga = $fattura->getRiga($type, $id_riga);
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
if (!empty($riga)) {
try {
$riga->delete();
// Ricalcolo inps, ritenuta e bollo
ricalcola_costiagg_fattura($id_record);
flash()->info(tr('Riga rimossa!'));
} catch (InvalidArgumentException $e) {
flash()->error(tr('Alcuni serial number sono già stati utilizzati!'));
}
$riga = null;
}
flash()->info(tr('Righe eliminate!'));
break;
// Duplicazione riga
case 'copy_riga':
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$new_riga = $riga->replicate();
$new_riga->setDocument($fattura);
$new_riga->qta_evasa = 0;
$new_riga->save();
if ($new_riga->isArticolo()) {
$new_riga->movimenta($new_riga->qta);
}
$riga = null;
}
flash()->info(tr('Righe duplicate!'));
break;
case 'add_serial':

View File

@ -21,11 +21,21 @@ use Modules\Interventi\Intervento;
include_once __DIR__.'/init.php';
$block_edit = !empty($note_accredito) || in_array($record['stato'], ['Emessa', 'Pagato', 'Parzialmente pagato']) || !$abilita_genera;
$righe = $fattura->getRighe();
echo '
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th width="5" class="text-center">';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<input id="check_all" type="checkbox"/>';
}
echo '
</th>
<th width="35" class="text-center" >'.tr('#').'</th>
<th>'.tr('Descrizione').'</th>
<th class="text-center" width="150">'.tr('Q.').'</th>
@ -35,10 +45,9 @@ echo '
<th width="120"></th>
</tr>
</thead>
<tbody class="sortable">';
<tbody class="sortable" id="righe">';
// Righe documento
$righe = $fattura->getRighe();
$num = 0;
foreach ($righe as $riga) {
++$num;
@ -90,6 +99,14 @@ foreach ($righe as $riga) {
echo '
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'" '.$extra.'>
<td class="text-center">';
if (!$block_edit) {
echo '
<input class="check" type="checkbox"/>';
}
echo '
</td>
<td class="text-center">
'.$num.'
</td>
@ -227,7 +244,7 @@ foreach ($righe as $riga) {
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga(this)">
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga([$(this).closest(\'tr\').data(\'id\')])">
<i class="fa fa-trash"></i>
</a>
@ -260,7 +277,7 @@ $ritenuta_contributi = $fattura->totale_ritenuta_contributi;
// IMPONIBILE
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -273,7 +290,7 @@ echo '
if (!empty($sconto)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"><i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
<td class="text-right">
@ -285,7 +302,7 @@ if (!empty($sconto)) {
// TOTALE IMPONIBILE
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -299,7 +316,7 @@ if (!empty($sconto)) {
if (!empty($rivalsa_inps)) {
echo '
<tr>
<td colspan="5" class="text-right">';
<td colspan="6" class="text-right">';
if ($dir == 'entrata') {
$descrizione_rivalsa = $database->fetchOne('SELECT CONCAT_WS(\' - \', codice, descrizione) AS descrizione FROM fe_tipo_cassa WHERE codice = '.prepare(setting('Tipo Cassa Previdenziale')));
@ -323,7 +340,7 @@ if (!empty($rivalsa_inps)) {
if (!empty($iva)) {
echo '
<tr>
<td colspan="5" class="text-right">';
<td colspan="6" class="text-right">';
if ($records[0]['split_payment']) {
echo '<b>'.tr('Iva a carico del destinatario', [], ['upper' => true]).':</b>';
@ -342,7 +359,7 @@ if (!empty($iva)) {
// TOTALE
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -355,7 +372,7 @@ echo '
if (!empty($ritenuta_acconto)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr("Ritenuta d'acconto", [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -369,7 +386,7 @@ if (!empty($ritenuta_acconto)) {
if (!empty($ritenuta_contributi)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Ritenuta previdenziale', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -383,7 +400,7 @@ if (!empty($ritenuta_contributi)) {
if (!empty($sconto_finale)) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -397,7 +414,7 @@ if (!empty($sconto_finale)) {
if ($totale != $netto_a_pagare) {
echo '
<tr>
<td colspan="5" class="text-right">
<td colspan="6" class="text-right">
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -408,10 +425,22 @@ if ($totale != $netto_a_pagare) {
}
echo '
</table>
</div>';
</table>';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default disabled" id="elimina_righe" onclick="duplicaRiga(getSelectData());">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="duplica_righe" onclick="rimuoviRiga(getSelectData());">
<i class="fa fa-trash"></i>
</button>
</div>';
}
echo '
</div>
<script>
async function modificaRiga(button) {
let riga = $(button).closest("tr");
@ -429,18 +458,24 @@ async function modificaRiga(button) {
openModal("'.tr('Modifica riga').'", "'.$module->fileurl('row-edit.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&riga_id=" + id + "&riga_type=" + type);
}
function rimuoviRiga(button) {
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'#righe\').find(\'.check:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
function rimuoviRiga(id) {
swal({
title: "'.tr('Rimuovere questa riga?').'",
html: "'.tr('Sei sicuro di volere rimuovere questa riga dal documento?').' '.tr("L'operazione è irreversibile").'.",
title: "'.tr('Rimuovere queste righe?').'",
html: "'.tr('Sei sicuro di volere rimuovere queste righe dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
let riga = $(button).closest("tr");
let id = riga.data("id");
let type = riga.data("type");
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
@ -449,8 +484,35 @@ function rimuoviRiga(button) {
id_module: globals.id_module,
id_record: globals.id_record,
op: "delete_riga",
riga_type: type,
riga_id: id,
righe: id,
},
success: function (response) {
location.reload();
},
error: function() {
location.reload();
}
});
}).catch(swal.noop);
}
function duplicaRiga(id) {
swal({
title: "'.tr('Duplicare queste righe?').'",
html: "'.tr('Sei sicuro di volere queste righe del documento?').'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "copy_riga",
righe: id,
},
success: function (response) {
location.reload();
@ -496,4 +558,37 @@ $(document).ready(function() {
});
});
});
$(".check").on("change", function() {
let checked = 0;
$(".check").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#elimina_righe").removeClass("disabled");
$("#duplica_righe").removeClass("disabled");
} else {
$("#elimina_righe").addClass("disabled");
$("#duplica_righe").addClass("disabled");
}
});
$("#check_all").click(function(){
if( $(this).is(":checked") ){
$(".check").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';

View File

@ -406,20 +406,46 @@ switch (post('op')) {
break;
case 'delete_riga':
$id_riga = post('riga_id');
$type = post('riga_type');
$riga = $intervento->getRiga($type, $id_riga);
if (!empty($riga)) {
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
try {
$riga->delete();
flash()->info(tr('Riga rimossa!'));
} catch (InvalidArgumentException $e) {
flash()->error(tr('Alcuni serial number sono già stati utilizzati!'));
}
$riga = null;
}
flash()->info(tr('Righe eliminate!'));
break;
// Duplicazione riga
case 'copy_riga':
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$new_riga = $riga->replicate();
$new_riga->setDocument($intervento);
$new_riga->qta_evasa = 0;
$new_riga->save();
if ($new_riga->isArticolo()) {
$new_riga->movimenta($new_riga->qta);
}
$riga = null;
}
flash()->info(tr('Righe duplicate!'));
break;
case 'manage_barcode':
@ -773,6 +799,10 @@ switch (post('op')) {
$new_riga->qta_evasa = 0;
$new_riga->save();
if ($new_riga->isArticolo()) {
$new_riga->movimenta($new_riga->qta);
}
}
}

View File

@ -19,15 +19,23 @@
include_once __DIR__.'/init.php';
$show_prezzi = Auth::user()['gruppo'] != 'Tecnici' || (Auth::user()['gruppo'] == 'Tecnici' && setting('Mostra i prezzi al tecnico'));
$block_edit = $record['flag_completato'];
$righe = $intervento->getRighe();
echo '
$show_prezzi = Auth::user()['gruppo'] != 'Tecnici' || (Auth::user()['gruppo'] == 'Tecnici' && setting('Mostra i prezzi al tecnico'));
echo '
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th width="5" class="text-center">';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<input id="check_all" type="checkbox"/>';
}
echo '
</th>
<th>'.tr('Descrizione').'</th>
<th class="text-center" width="80">'.tr('Q.').'</th>';
@ -47,7 +55,7 @@ $righe = $intervento->getRighe();
</tr>
</thead>
<tbody class="sortable">';
<tbody class="sortable" id="righe">';
foreach ($righe as $riga) {
$extra = '';
@ -59,6 +67,13 @@ $righe = $intervento->getRighe();
echo '
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'" '.$extra.'>
<td class="text-center">';
if (!$block_edit) {
echo '
<input class="check" type="checkbox"/>';
}
echo '
</td>
<td>';
// Informazioni aggiuntive sulla destra
@ -155,7 +170,7 @@ $righe = $intervento->getRighe();
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga(this)">
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga([$(this).closest(\'tr\').data(\'id\')])">
<i class="fa fa-trash"></i>
</a>
@ -179,7 +194,7 @@ $righe = $intervento->getRighe();
// IMPONIBILE
echo '
<tr>
<td colspan="'.((!$record['flag_completato']) ? 5 : 4).'" class="text-right">
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -192,7 +207,7 @@ $righe = $intervento->getRighe();
if (!empty($intervento->sconto)) {
echo '
<tr>
<td colspan="'.((!$record['flag_completato']) ? 5 : 4).'" class="text-right">
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
<td class="text-right">
@ -204,7 +219,7 @@ $righe = $intervento->getRighe();
// Totale imponibile scontato
echo '
<tr>
<td colspan="'.((!$record['flag_completato']) ? 5 : 4).'" class="text-right">
<td colspan="'.((!$record['flag_completato']) ? 6 : 5).'" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -217,10 +232,22 @@ $righe = $intervento->getRighe();
}
echo'
</table>
</div>';
</table>';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default disabled" id="elimina_righe" onclick="duplicaRiga(getSelectData());">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="duplica_righe" onclick="rimuoviRiga(getSelectData());">
<i class="fa fa-trash"></i>
</button>
</div>';
}
echo '
</div>
<script type="text/javascript">
async function modificaRiga(button) {
let riga = $(button).closest("tr");
@ -238,18 +265,24 @@ async function modificaRiga(button) {
openModal("'.tr('Modifica sessione').'", "'.$module->fileurl('row-edit.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&riga_id=" + id + "&riga_type=" + type);
}
function rimuoviRiga(button) {
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'#righe\').find(\'.check:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
function rimuoviRiga(id) {
swal({
title: "'.tr('Rimuovere questa riga?').'",
html: "'.tr('Sei sicuro di volere rimuovere questa riga dal documento?').' '.tr("L'operazione è irreversibile").'.",
title: "'.tr('Rimuovere queste righe?').'",
html: "'.tr('Sei sicuro di volere rimuovere queste righe dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
let riga = $(button).closest("tr");
let id = riga.data("id");
let type = riga.data("type");
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
@ -258,8 +291,35 @@ function rimuoviRiga(button) {
id_module: globals.id_module,
id_record: globals.id_record,
op: "delete_riga",
riga_type: type,
riga_id: id,
righe: id,
},
success: function (response) {
location.reload();
},
error: function() {
location.reload();
}
});
}).catch(swal.noop);
}
function duplicaRiga(id) {
swal({
title: "'.tr('Duplicare queste righe?').'",
html: "'.tr('Sei sicuro di volere queste righe del documento?').'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "copy_riga",
righe: id,
},
success: function (response) {
location.reload();
@ -297,4 +357,37 @@ $(document).ready(function() {
});
});
});
$(".check").on("change", function() {
let checked = 0;
$(".check").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#elimina_righe").removeClass("disabled");
$("#duplica_righe").removeClass("disabled");
} else {
$("#elimina_righe").addClass("disabled");
$("#duplica_righe").addClass("disabled");
}
});
$("#check_all").click(function(){
if( $(this).is(":checked") ){
$(".check").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';

View File

@ -322,22 +322,47 @@ switch (post('op')) {
// Scollegamento riga generica da ordine
case 'delete_riga':
$id_riga = post('riga_id');
$type = post('riga_type');
$riga = $ordine->getRiga($type, $id_riga);
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
if (!empty($riga)) {
try {
$riga->delete();
flash()->info(tr('Riga rimossa!'));
} catch (InvalidArgumentException $e) {
flash()->error(tr('Alcuni serial number sono già stati utilizzati!'));
}
$riga = null;
}
ricalcola_costiagg_ordine($id_record);
flash()->info(tr('Righe eliminate!'));
break;
// Duplicazione riga
case 'copy_riga':
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$new_riga = $riga->replicate();
$new_riga->setDocument($ordine);
$new_riga->qta_evasa = 0;
$new_riga->save();
$riga = null;
}
flash()->info(tr('Righe duplicate!'));
break;
// Eliminazione ordine

View File

@ -19,11 +19,21 @@
include_once __DIR__.'/init.php';
$block_edit = $record['flag_completato'];
$righe = $ordine->getRighe();
echo '
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th width="5" class="text-center">';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<input id="check_all" type="checkbox"/>';
}
echo '
</th>
<th width="35" class="text-center" >'.tr('#').'</th>
<th>'.tr('Descrizione').'</th>
<th width="120">'.tr('Prev. evasione').'</th>
@ -35,12 +45,11 @@ echo '
</tr>
</thead>
<tbody class="sortable">';
<tbody class="sortable" id="righe">';
// Righe documento
$today = new Carbon\Carbon();
$today = $today->startOfDay();
$righe = $ordine->getRighe();
$num = 0;
foreach ($righe as $riga) {
++$num;
@ -62,6 +71,14 @@ foreach ($righe as $riga) {
echo '
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'" '.$extra.'>
<td class="text-center">';
if (!$block_edit) {
echo '
<input class="check" type="checkbox"/>';
}
echo '
</td>
<td class="text-center">
'.$num.'
</td>
@ -213,7 +230,7 @@ foreach ($righe as $riga) {
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga(this)">
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga([$(this).closest(\'tr\').data(\'id\')])">
<i class="fa fa-trash"></i>
</a>
@ -243,7 +260,7 @@ $netto_a_pagare = $ordine->netto;
// IMPONIBILE
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -256,7 +273,7 @@ echo '
if (!empty($sconto)) {
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
<td class="text-right">
@ -268,7 +285,7 @@ if (!empty($sconto)) {
// TOTALE IMPONIBILE
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -281,7 +298,7 @@ if (!empty($sconto)) {
// IVA
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Iva', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -293,7 +310,7 @@ echo '
// TOTALE
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -306,7 +323,7 @@ echo '
if (!empty($sconto_finale)) {
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -320,7 +337,7 @@ if (!empty($sconto_finale)) {
if ($totale != $netto_a_pagare) {
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -331,10 +348,22 @@ if ($totale != $netto_a_pagare) {
}
echo '
</table>
</div>';
</table>';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default disabled" id="elimina_righe" onclick="duplicaRiga(getSelectData());">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="duplica_righe" onclick="rimuoviRiga(getSelectData());">
<i class="fa fa-trash"></i>
</button>
</div>';
}
echo '
</div>
<script>
async function modificaRiga(button) {
let riga = $(button).closest("tr");
@ -352,18 +381,24 @@ async function modificaRiga(button) {
openModal("'.tr('Modifica riga').'", "'.$module->fileurl('row-edit.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&riga_id=" + id + "&riga_type=" + type);
}
function rimuoviRiga(button) {
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'#righe\').find(\'.check:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
function rimuoviRiga(id) {
swal({
title: "'.tr('Rimuovere questa riga?').'",
html: "'.tr('Sei sicuro di volere rimuovere questa riga dal documento?').' '.tr("L'operazione è irreversibile").'.",
title: "'.tr('Rimuovere queste righe?').'",
html: "'.tr('Sei sicuro di volere rimuovere queste righe dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
let riga = $(button).closest("tr");
let id = riga.data("id");
let type = riga.data("type");
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
@ -372,8 +407,35 @@ function rimuoviRiga(button) {
id_module: globals.id_module,
id_record: globals.id_record,
op: "delete_riga",
riga_type: type,
riga_id: id,
righe: id,
},
success: function (response) {
location.reload();
},
error: function() {
location.reload();
}
});
}).catch(swal.noop);
}
function duplicaRiga(id) {
swal({
title: "'.tr('Duplicare queste righe?').'",
html: "'.tr('Sei sicuro di volere queste righe del documento?').'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "copy_riga",
righe: id,
},
success: function (response) {
location.reload();
@ -419,4 +481,37 @@ $(document).ready(function() {
});
});
});
$(".check").on("change", function() {
let checked = 0;
$(".check").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#elimina_righe").removeClass("disabled");
$("#duplica_righe").removeClass("disabled");
} else {
$("#elimina_righe").addClass("disabled");
$("#duplica_righe").addClass("disabled");
}
});
$("#check_all").click(function(){
if( $(this).is(":checked") ){
$(".check").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';

View File

@ -354,17 +354,40 @@ switch (post('op')) {
// Eliminazione riga
case 'delete_riga':
$id_riga = post('riga_id');
$type = post('riga_type');
$riga = $preventivo->getRiga($type, $id_riga);
if (!empty($riga)) {
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$riga->delete();
flash()->info(tr('Riga eliminata!'));
$riga = null;
}
flash()->info(tr('Righe eliminate!'));
break;
// Duplicazione riga
case 'copy_riga':
$id_righe = (array)post('righe');
foreach ($id_righe as $id_riga) {
$riga = Articolo::find($id_riga) ?: Riga::find($id_riga);
$riga = $riga ?: Descrizione::find($id_riga);
$riga = $riga ?: Sconto::find($id_riga);
$new_riga = $riga->replicate();
$new_riga->setDocument($preventivo);
$new_riga->qta_evasa = 0;
$new_riga->save();
$riga = null;
}
flash()->info(tr('Righe duplicate!'));
break;
case 'add_revision':

View File

@ -19,11 +19,21 @@
include_once __DIR__.'/init.php';
$block_edit = $record['is_completato'];
$righe = $preventivo->getRighe();
echo '
<div class="table-responsive">
<table class="table table-striped table-hover table-condensed table-bordered">
<thead>
<tr>
<th width="5" class="text-center">';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<input id="check_all" type="checkbox"/>';
}
echo '
</th>
<th width="35" class="text-center" >'.tr('#').'</th>
<th>'.tr('Descrizione').'</th>
<th width="120">'.tr('Prev. evasione').'</th>
@ -34,18 +44,25 @@ echo '
<th width="100"></th>
</tr>
</thead>
<tbody class="sortable">';
<tbody class="sortable" id="righe">';
// Righe documento
$today = new Carbon\Carbon();
$today = $today->startOfDay();
$righe = $preventivo->getRighe();
$num = 0;
foreach ($righe as $riga) {
++$num;
echo '
<tr data-id="'.$riga->id.'" data-type="'.get_class($riga).'">
<td class="text-center">';
if (!$block_edit) {
echo '
<input class="check" type="checkbox"/>';
}
echo '
</td>
<td class="text-center">
'.$num.'
</td>
@ -165,7 +182,7 @@ foreach ($righe as $riga) {
<i class="fa fa-edit"></i>
</a>
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga(this)">
<a class="btn btn-xs btn-danger" title="'.tr('Rimuovi riga').'" onclick="rimuoviRiga([$(this).closest(\'tr\').data(\'id\')])">
<i class="fa fa-trash"></i>
</a>
@ -195,7 +212,7 @@ $netto_a_pagare = $preventivo->netto;
// Totale imponibile scontato
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -208,7 +225,7 @@ echo '
if (!empty($sconto)) {
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b><span class="tip" title="'.tr('Un importo positivo indica uno sconto, mentre uno negativo indica una maggiorazione').'"> <i class="fa fa-question-circle-o"></i> '.tr('Sconto/maggiorazione', [], ['upper' => true]).':</span></b>
</td>
<td class="text-right">
@ -220,7 +237,7 @@ if (!empty($sconto)) {
// Totale imponibile scontato
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Totale imponibile', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -233,7 +250,7 @@ if (!empty($sconto)) {
// Totale iva
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Iva', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -245,7 +262,7 @@ echo '
// Totale
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Totale', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -258,7 +275,7 @@ echo '
if (!empty($sconto_finale)) {
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Sconto in fattura', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -272,7 +289,7 @@ if (!empty($sconto_finale)) {
if ($totale != $netto_a_pagare) {
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
<b>'.tr('Netto a pagare', [], ['upper' => true]).':</b>
</td>
<td class="text-right">
@ -289,7 +306,7 @@ $margine_icon = ($margine <= 0 and $preventivo->totale > 0) ? 'warning' : 'check
echo '
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
'.tr('Costi').':
</td>
<td class="text-right">
@ -299,7 +316,7 @@ echo '
</tr>
<tr>
<td colspan="6" class="text-right">
<td colspan="7" class="text-right">
'.tr('Margine (_PRC_%)', [
'_PRC_' => numberFormat($preventivo->margine_percentuale),
]).':
@ -311,10 +328,22 @@ echo '
</tr>';
echo '
</table>
</div>';
</table>';
if (!$block_edit && sizeof($righe) > 0) {
echo '
<div class="btn-group">
<button type="button" class="btn btn-xs btn-default disabled" id="elimina_righe" onclick="duplicaRiga(getSelectData());">
<i class="fa fa-copy"></i>
</button>
<button type="button" class="btn btn-xs btn-default disabled" id="duplica_righe" onclick="rimuoviRiga(getSelectData());">
<i class="fa fa-trash"></i>
</button>
</div>';
}
echo '
</div>
<script>
async function modificaRiga(button) {
let riga = $(button).closest("tr");
@ -332,18 +361,24 @@ async function modificaRiga(button) {
openModal("'.tr('Modifica riga').'", "'.$module->fileurl('row-edit.php').'?id_module=" + globals.id_module + "&id_record=" + globals.id_record + "&riga_id=" + id + "&riga_type=" + type);
}
function rimuoviRiga(button) {
// Estraggo le righe spuntate
function getSelectData() {
let data=new Array();
$(\'#righe\').find(\'.check:checked\').each(function (){
data.push($(this).closest(\'tr\').data(\'id\'));
});
return data;
}
function rimuoviRiga(id) {
swal({
title: "'.tr('Rimuovere questa riga?').'",
html: "'.tr('Sei sicuro di volere rimuovere questa riga dal documento?').' '.tr("L'operazione è irreversibile").'.",
title: "'.tr('Rimuovere queste righe?').'",
html: "'.tr('Sei sicuro di volere rimuovere queste righe dal documento?').' '.tr("L'operazione è irreversibile").'.",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
let riga = $(button).closest("tr");
let id = riga.data("id");
let type = riga.data("type");
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
@ -352,8 +387,35 @@ function rimuoviRiga(button) {
id_module: globals.id_module,
id_record: globals.id_record,
op: "delete_riga",
riga_type: type,
riga_id: id,
righe: id,
},
success: function (response) {
location.reload();
},
error: function() {
location.reload();
}
});
}).catch(swal.noop);
}
function duplicaRiga(id) {
swal({
title: "'.tr('Duplicare queste righe?').'",
html: "'.tr('Sei sicuro di volere queste righe del documento?').'",
type: "warning",
showCancelButton: true,
confirmButtonText: "'.tr('Sì').'"
}).then(function () {
$.ajax({
url: globals.rootdir + "/actions.php",
type: "POST",
dataType: "json",
data: {
id_module: globals.id_module,
id_record: globals.id_record,
op: "copy_riga",
righe: id,
},
success: function (response) {
location.reload();
@ -383,4 +445,37 @@ $(document).ready(function() {
});
});
});
$(".check").on("change", function() {
let checked = 0;
$(".check").each(function() {
if ($(this).is(":checked")) {
checked = 1;
}
});
if (checked) {
$("#elimina_righe").removeClass("disabled");
$("#duplica_righe").removeClass("disabled");
} else {
$("#elimina_righe").addClass("disabled");
$("#duplica_righe").addClass("disabled");
}
});
$("#check_all").click(function(){
if( $(this).is(":checked") ){
$(".check").each(function(){
if( !$(this).is(":checked") ){
$(this).trigger("click");
}
});
}else{
$(".check").each(function(){
if( $(this).is(":checked") ){
$(this).trigger("click");
}
});
}
});
</script>';