openstamanager/modules/articoli/plugins/articoli.lotti.php

483 lines
21 KiB
PHP
Raw Normal View History

<?php
2020-09-07 15:04:06 +02:00
/*
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
2021-01-20 15:08:51 +01:00
* Copyright (C) DevCode s.r.l.
2020-09-07 15:04:06 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
include_once __DIR__.'/../../../core.php';
2019-07-08 10:21:35 +02:00
$record['abilita_serial'] = ($record['serial'] > 0) ? 1 : $record['abilita_serial'];
if (empty($record['abilita_serial'])) {
echo '
2019-07-08 12:25:51 +02:00
<script>$("#link-tab_'.$plugin['id'].'").addClass("disabled");</script>';
2019-07-08 10:21:35 +02:00
}
2019-08-28 11:52:04 +02:00
// Visualizzo, in base alle impostazioni scelte, se il magazzino verrà movimentato
$message = setting("Movimenta il magazzino durante l'inserimento o eliminazione dei lotti/serial number") ? tr("L'inserimento e la rimozione dei seriali modificherà la quantità dell'articolo!") : tr("L'inserimento e la rimozione dei seriali non movimenterà la quantità dell'articolo!");
echo '
2019-08-28 11:52:04 +02:00
<div class="alert alert-info">
'.$message.'
</div>';
2019-08-28 11:52:04 +02:00
// Inserimento seriali
echo '
2019-08-28 11:52:04 +02:00
<div class="nav-tabs-custom">
<ul class="nav nav-tabs nav-justified">
2024-05-16 18:02:50 +02:00
<li class="active"><a class="nav-link" href="#generazione" data-widget="tab">'.tr('Generazione multipla').'</a></li>
<li><a class="nav-link" href="#inserimento" data-widget="tab">'.tr('Inserimento singolo').'</a></li>
2019-08-28 11:52:04 +02:00
</ul>
2019-12-13 16:32:53 +01:00
2019-08-28 11:52:04 +02:00
<div class="tab-content">
<form action="" method="post" role="form" class="tab-pane active" id="generazione">
<input type="hidden" name="backto" value="record-edit">
2019-08-28 11:52:04 +02:00
<input type="hidden" name="op" value="generate_serials">
2023-07-05 11:43:07 +02:00
<input type="hidden" name="id_module" value="'.$id_module.'">
<input type="hidden" name="id_record" value="'.$id_record.'">
2019-12-13 16:32:53 +01:00
2019-08-28 11:52:04 +02:00
<div class="row">
<div class="col-md-5">
{[ "type": "text", "label": "'.tr('Inizio').'", "name": "serial_start", "extra": "onkeyup=\"$(\'#serial_end\').val( $(this).val()); ricalcola_generazione();\"" ]}
</div>
2019-12-13 16:32:53 +01:00
2019-08-28 11:52:04 +02:00
<div class="col-md-2 text-center" style="padding-top: 20px;">
2018-07-04 15:38:10 +02:00
<i class="fa fa-arrow-circle-right fa-2x"></i>
2019-08-28 11:52:04 +02:00
</div>
2019-12-13 16:32:53 +01:00
2018-07-04 15:38:10 +02:00
<div class="col-md-5">
2019-08-28 11:52:04 +02:00
{[ "type": "text", "label": "'.tr('Fine').'", "name": "serial_end", "extra": "onkeyup=\"ricalcola_generazione();\"" ]}
</div>
</div>
2019-12-13 16:32:53 +01:00
2019-08-28 11:52:04 +02:00
<div class="row">
<div class="col-md-9">
<p class="text-danger">'.tr('Totale prodotti da inserire').': <span id="totale_generazione">0</span></p>
</div>
2019-12-13 16:32:53 +01:00
2019-08-28 11:52:04 +02:00
<div class="col-md-3 text-right">
<button type="button" class="btn btn-primary" onclick="addSerial(\'#generazione\', $(\'#totale_generazione\').text())"><i class="fa fa-plus"></i> '.tr('Aggiungi').'</button>
</div>
</div>
</form>
2019-12-13 16:32:53 +01:00
<form action="" method="post" role="form" class="tab-pane" id="inserimento">
2019-08-28 11:52:04 +02:00
<input type="hidden" name="backto" value="record-edit">
<input type="hidden" name="op" value="add_serials">
2023-07-05 11:43:07 +02:00
<input type="hidden" name="id_module" value="'.$id_module.'">
<input type="hidden" name="id_record" value="'.$id_record.'">
2019-12-13 16:32:53 +01:00
<div class="row">
<div class="col-md-12">
2019-08-28 11:52:04 +02:00
{[ "type": "select", "label": "'.tr('Nuovi seriali').'", "name": "serials[]", "extra": "onchange=\"ricalcola_inserimento();\"", "multiple": 1, "values": [] ]}
</div>
</div>
2019-08-28 11:52:04 +02:00
<div class="row">
<div class="col-md-9">
<p class="text-danger">'.tr('Totale prodotti da inserire').': <span id="totale_inserimento">0</span></p>
</div>
2019-12-13 16:32:53 +01:00
2019-08-28 11:52:04 +02:00
<div class="col-md-3 text-right">
<button type="button" class="btn btn-primary" onclick="addSerial(\'#inserimento\', $(\'#totale_inserimento\').text())"><i class="fa fa-plus"></i> '.tr('Aggiungi').'</button>
</div>
</div>
</form>
</div>
</div>';
2019-08-28 11:52:04 +02:00
// Elenco
2023-07-05 11:43:07 +02:00
if (empty(get('modal'))) {
2023-08-04 14:54:28 +02:00
echo '
2024-05-16 18:02:50 +02:00
<div class="card">
<div class="card-header with-border">
<h3 class="card-title">'.tr('Elenco seriali').'</h3>
</div>
2024-05-16 18:02:50 +02:00
<div class="card-body">';
2023-08-04 14:54:28 +02:00
// Conteggio totale prodotti
$rs = $dbo->fetchArray('SELECT COUNT(id) AS tot FROM mg_prodotti WHERE id_articolo='.prepare($id_record));
$tot_prodotti = $rs[0]['tot'];
2023-08-04 14:54:28 +02:00
// Visualizzazione di tutti i prodotti
$search_serial = get('search_serial');
$query = 'SELECT id, serial, created_at FROM mg_prodotti WHERE serial IS NOT NULL AND id_articolo='.prepare($id_record).(!empty($search_serial) ? ' AND serial LIKE '.prepare('%'.$search_serial.'%') : '').' GROUP BY serial ORDER BY created_at DESC, serial DESC, lotto DESC, altro DESC';
$rs2 = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
echo '
2020-04-15 16:43:23 +02:00
<table id="table-serials" class="table table-striped table-hover table-condensed table-bordered text-center datatables">
<thead>
<tr>
<th>'.tr('Serial').'</th>
<th>'.tr('Data di creazione').'</th>
<th>'.tr('Documento di acquisto').'</th>
<th>'.tr('Prezzo di acquisto').'</th>
<th>'.tr('Documento di vendita').'</th>
<th>'.tr('Prezzo di vendita').'</th>
<th class="text-center">#</th>
</tr>
</thead>
<tbody>';
2023-08-04 14:54:28 +02:00
for ($i = 0; $i < count($rs2); ++$i) {
echo '
<tr>
<td>'.$rs2[$i]['serial'].'</td>';
2023-08-04 14:54:28 +02:00
echo '
<td>'.Translator::timestampToLocale($rs2[$i]['created_at']).'</td>';
2023-08-04 14:54:28 +02:00
// Ricerca acquisti
$acquisti = $dbo->fetchArray('SELECT * FROM mg_prodotti WHERE dir=\'uscita\' AND id_articolo='.prepare($id_record).' AND (id_riga_documento IS NOT NULL OR id_riga_ordine IS NOT NULL OR id_riga_ddt IS NOT NULL) AND serial='.prepare($rs2[$i]['serial']));
2023-08-04 14:54:28 +02:00
if (!empty($acquisti)) {
echo '
<td>';
2023-08-04 14:54:28 +02:00
$totali = [];
2023-08-04 14:54:28 +02:00
foreach ($acquisti as $acquisto) {
// Acquistato su fatture
if (!empty($acquisto['id_riga_documento'])) {
2024-03-08 11:54:00 +01:00
$module = 'Fatture di acquisto';
2023-08-04 14:54:28 +02:00
// Ricerca vendite su fatture
2024-04-18 17:44:05 +02:00
$query = 'SELECT *, `co_tipidocumento_lang`.`title` AS tipo_documento, `co_tipidocumento`.`dir`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`, `co_documenti`.`data` FROM `co_righe_documenti` INNER JOIN `co_documenti` ON `co_righe_documenti`.`iddocumento` = `co_documenti`.`id` INNER JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento` = `co_tipidocumento`.`id` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id` = `co_tipidocumento_lang`.`id_record` AND `co_tipidocumento_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).') WHERE `co_righe_documenti`.`id`='.prepare($acquisto['id_riga_documento']);
2023-08-04 14:54:28 +02:00
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['iddocumento'];
}
2023-08-04 14:54:28 +02:00
// Acquistato su ddt
elseif (!empty($acquisto['id_riga_ddt'])) {
$module = 'Ddt in entrata';
2024-02-27 15:51:13 +01:00
$query = 'SELECT
*,
2024-04-18 17:44:05 +02:00
`dt_tipiddt_lang`.`title` AS tipo_documento,
2024-02-27 15:51:13 +01:00
`dt_tipiddt`.`dir` AS `dir`,
`dt_ddt`.`numero` AS numero,
`dt_ddt`.`data` AS data,
`dt_ddt`.`numero_esterno` AS numero_esterno
FROM
`dt_righe_ddt`
INNER JOIN `dt_ddt` ON `dt_righe_ddt`.`idddt` = `dt_ddt`.`id`
INNER JOIN `dt_tipiddt` ON `dt_ddt`.`idtipoddt` = `dt_tipiddt`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `dt_tipiddt_lang` ON (`dt_tipiddt`.`id` = `dt_tipiddt_lang`.`id_record` AND `dt_tipiddt_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-02-27 15:51:13 +01:00
WHERE
`dt_righe_ddt`.`id`='.prepare($acquisto['id_riga_ddt']);
2023-08-04 14:54:28 +02:00
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['idddt'];
}
2023-08-04 14:54:28 +02:00
// Inserito su ordini
elseif (!empty($acquisto['id_riga_ordine'])) {
2024-03-08 11:54:00 +01:00
$module = 'Ordini cliente';
2023-08-04 14:54:28 +02:00
// Ricerca inserimenti su ordini
2024-03-01 11:49:21 +01:00
$query = 'SELECT
*,
2024-04-18 17:44:05 +02:00
`or_tipiordine_lang`.`title` AS tipo_documento,
2024-03-01 11:49:21 +01:00
`or_tipiordine`.`dir`,
`or_ordini`.`numero`,
`or_ordini`.`numero_esterno`,
`or_ordini`.`data`
FROM
`or_righe_ordini`
INNER JOIN `or_ordini` ON `or_righe_ordini`.`idordine`=`or_ordini`.`id`
INNER JOIN `or_tipiordine` ON `or_ordini`.`ididtipordine`=`or_tipiordine`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `or_tipiordine_lang` ON (`or_tipiordine`.`id` = `or_tipiordine_lang`.`id_record` AND `or_tipiordine_lang`.`id_lang` = '.prepare(Models\Locale::getDefault()->id).')
2024-03-01 11:49:21 +01:00
WHERE
`or_righe_ordini`.`id`='.prepare($acquisto['id_riga_ordine']);
2023-08-04 14:54:28 +02:00
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['idordine'];
}
2024-01-15 15:30:45 +01:00
$totali[] = [$data[0]['prezzo_unitario'] - $data[0]['sconto_unitario'], $data[0]['iva_unitaria']];
2023-08-04 14:54:28 +02:00
$numero = !empty($data[0]['numero_esterno']) ? $data[0]['numero_esterno'] : $data[0]['numero'];
2023-08-04 14:54:28 +02:00
$text = tr('_DOC_ num. _NUM_ del _DATE_', [
2024-03-22 15:52:24 +01:00
'_DOC_' => $data[0]['tipo_documento'],
'_NUM_' => $numero,
'_DATE_' => Translator::dateToLocale($data[0]['data']),
]).(!empty($extra) ? ' '.$extra : '');
2024-03-08 11:54:00 +01:00
echo Modules::link($module, $id, $text).'<br>';
2023-08-04 14:54:28 +02:00
}
echo '
</td>
<td class="text-center">';
2023-08-04 14:54:28 +02:00
foreach ($totali as $value) {
$subtotale = $value[0];
$iva = $value[1];
echo '
2023-08-04 14:54:28 +02:00
<span>'.moneyFormat($subtotale + $iva).'</span>';
if (!empty($subtotale) && !empty($iva)) {
echo '
<small style="color:#555;">('.Translator::numberToLocale($subtotale).' + '.Translator::numberToLocale($iva).')</small>';
2023-08-04 14:54:28 +02:00
}
echo '
<br>';
}
2023-08-04 14:54:28 +02:00
echo '
</td>';
2023-08-04 14:54:28 +02:00
}
2023-08-04 14:54:28 +02:00
// Non venduto
else {
echo '
<td></td>
<td></td>';
2023-08-04 14:54:28 +02:00
}
2023-08-04 14:54:28 +02:00
// Ricerca vendite
$vendite = $dbo->fetchArray('SELECT * FROM mg_prodotti WHERE dir=\'entrata\' AND id_articolo='.prepare($id_record).' AND serial='.prepare($rs2[$i]['serial']));
2023-08-04 14:54:28 +02:00
if (!empty($vendite)) {
echo '
<td>';
2023-08-04 14:54:28 +02:00
$totali = [];
2023-08-04 14:54:28 +02:00
foreach ($vendite as $vendita) {
// Venduto su fatture
if (!empty($vendita['id_riga_documento'])) {
2024-03-08 11:54:00 +01:00
$module = 'Fatture di vendita';
2023-08-04 14:54:28 +02:00
// Ricerca vendite su fatture
2024-04-18 17:44:05 +02:00
$query = 'SELECT *, `co_tipidocumento_lang`.`title` AS tipo_documento, `co_tipidocumento`.`dir`, `co_documenti`.`numero`, `co_documenti`.`numero_esterno`,`co_documenti`.`data` FROM `co_righe_documenti` INNER JOIN `co_documenti` ON `co_righe_documenti`.`iddocumento`=`co_documenti`.`id` INNER JOIN `co_tipidocumento` ON `co_documenti`.`idtipodocumento`=`co_tipidocumento`.`id` LEFT JOIN `co_tipidocumento_lang` ON (`co_tipidocumento`.`id`=`co_tipidocumento_lang`.`id_record` AND `co_tipidocumento_lang`.`id_lang`='.prepare(Models\Locale::getDefault()->id).') WHERE `co_righe_documenti`.`id`='.prepare($vendita['id_riga_documento']);
2023-08-04 14:54:28 +02:00
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['iddocumento'];
}
2023-08-04 14:54:28 +02:00
// Venduto su ddt
elseif (!empty($vendita['id_riga_ddt'])) {
$module = 'Ddt in uscita';
2024-02-27 15:51:13 +01:00
$query = 'SELECT
*,
2024-04-18 17:44:05 +02:00
`dt_tipiddt_lang`.`title` AS tipo_documento,
2024-02-27 15:51:13 +01:00
`dt_ddt`.`dir`,
`dt_ddt`.`numero`,
`dt_ddt`.`numero_esterno`,
`dt_ddt`.`data`
FROM
`dt_righe_ddt`
INNER JOIN `dt_ddt` ON `dt_righe_ddt`.`idddt`=`dt_ddt`.`id`
INNER JOIN `dt_tipiddt` ON `dt_ddt`.`idtipoddt`=`dt_tipiddt`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `dt_tipiddt_lang` ON (`dt_tipiddt_lang`.`id_record`=`dt_tipiddt`.`id` AND `dt_tipiddt_lang`.`id_lang`='.prepare(Models\Locale::getDefault()->id).')
2024-02-27 15:51:13 +01:00
WHERE
`dt_righe_ddt`.`id`='.prepare($vendita['id_riga_ddt']);
2023-08-04 14:54:28 +02:00
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['idddt'];
}
2023-08-04 14:54:28 +02:00
// Inserito su ordini
elseif (!empty($vendita['id_riga_ordine'])) {
2024-03-08 11:54:00 +01:00
$module = 'Ordini cliente';
2023-08-04 14:54:28 +02:00
// Ricerca inserimenti su ordini
2024-03-01 11:49:21 +01:00
$query = 'SELECT
*,
2024-04-18 17:44:05 +02:00
`or_tipiordine_lang`.`title` AS tipo_ordine,
2024-03-01 11:49:21 +01:00
`or_ordini`.`dir`,
`or_ordini`.`numero`,
`or_ordini`.`numero_esterno`,
`or_ordini`.`data`
FROM
`or_righe_ordini`
INNER JOIN `or_ordini` ON `or_righe_ordini`.`idordine`=`or_ordini`.`id`
INNER JOIN `or_tipiordine` ON `or_ordini`.`idtipoordine`=`or_tipiordine`.`id`
2024-03-22 15:52:24 +01:00
LEFT JOIN `or_tipiordine_lang` ON (`or_tipiordine_lang`.`id_record`=`or_tipiordine`.`id` AND `or_tipiordine_lang`.`id_lang`='.prepare(Models\Locale::getDefault()->id).')
2024-03-01 11:49:21 +01:00
WHERE
`or_righe_ordini`.`id`='.prepare($vendita['id_riga_ordine']);
2023-08-04 14:54:28 +02:00
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['idordine'];
}
2023-08-04 14:54:28 +02:00
// Inserito su intervento
elseif (!empty($vendita['id_riga_intervento'])) {
2024-03-08 11:54:00 +01:00
$module = 'Interventi';
2023-08-04 14:54:28 +02:00
// Ricerca inserimenti su interventi
$query = 'SELECT in_righe_interventi.*, in_interventi.codice, ( SELECT orario_inizio FROM in_interventi_tecnici WHERE idintervento=in_righe_interventi.idintervento LIMIT 0,1 ) AS data FROM in_righe_interventi JOIN in_interventi ON in_interventi.id = in_righe_interventi.idintervento WHERE in_righe_interventi.id='.prepare($vendita['id_riga_intervento']);
$data = $dbo->fetchArray($query);
2023-08-04 14:54:28 +02:00
$id = $data[0]['idintervento'];
2023-08-04 14:54:28 +02:00
$data[0]['tipo_documento'] = tr('Intervento').' '.$data[0]['codice'];
2023-11-13 15:38:27 +01:00
}
2023-11-13 15:38:27 +01:00
// Inserito su contratto
elseif (!empty($vendita['id_riga_contratto'])) {
2024-03-08 11:54:00 +01:00
$module = 'Contratti';
2023-11-13 15:38:27 +01:00
// Ricerca vendite su contratti
$query = 'SELECT *, "Contratto" AS tipo_documento, ( SELECT data_bozza FROM co_contratti WHERE id=idcontratto ) AS data, ( SELECT numero FROM co_contratti WHERE id=idcontratto ) AS numero FROM co_righe_contratti WHERE co_righe_contratti.id='.prepare($vendita['id_riga_contratto']);
$data = $dbo->fetchArray($query);
$id = $data[0]['idcontratto'];
}
2023-11-15 14:10:33 +01:00
// Inserito su vendita banco
elseif (!empty($vendita['id_riga_venditabanco'])) {
2024-03-08 11:54:00 +01:00
$module = 'Vendita al banco';
2023-11-13 15:38:27 +01:00
// Ricerca vendite su contratti
$query = 'SELECT *, "Vendita al banco" AS tipo_documento, ( SELECT data FROM vb_venditabanco WHERE id=idvendita ) AS data, ( SELECT numero FROM vb_venditabanco WHERE id=idvendita ) AS numero FROM vb_righe_venditabanco WHERE vb_righe_venditabanco.id='.prepare($vendita['id_riga_venditabanco']);
$data = $dbo->fetchArray($query);
$id = $data[0]['idvendita'];
2023-08-04 14:54:28 +02:00
}
2024-01-15 15:30:45 +01:00
$totali[] = [$data[0]['prezzo_unitario'] - $data[0]['sconto_unitario'], $data[0]['iva_unitaria']];
2023-08-04 14:54:28 +02:00
$numero = !empty($data[0]['numero_esterno']) ? $data[0]['numero_esterno'] : $data[0]['numero'];
2023-08-04 14:54:28 +02:00
$text = tr('_DOC_ num. _NUM_ del _DATE_', [
2023-11-13 15:38:27 +01:00
'_DOC_' => $data[0]['tipo_documento'],
'_NUM_' => $numero,
'_DATE_' => Translator::dateToLocale($data[0]['data']),
]);
2024-03-08 11:54:00 +01:00
echo Modules::link($module, $id, $text).'<br>';
2023-08-04 14:54:28 +02:00
}
echo '
</td>
<td class="text-center">';
2023-08-04 14:54:28 +02:00
foreach ($totali as $value) {
$subtotale = $value[0];
$iva = $value[1];
echo '
2023-08-04 14:54:28 +02:00
<span>'.moneyFormat($subtotale + $iva).'</span>';
if (!empty($subtotale) && !empty($iva)) {
echo '
<small style="color:#555;">('.Translator::numberToLocale($subtotale).' + '.Translator::numberToLocale($iva).')</small>';
2023-08-04 14:54:28 +02:00
}
echo '
<br>';
2023-08-04 14:54:28 +02:00
}
2023-08-04 14:54:28 +02:00
echo '
</td>
<td></td>';
2023-08-04 14:54:28 +02:00
}
2023-08-04 14:54:28 +02:00
// Non venduto
else {
// Documento di vendita
echo '
<td></td>
<td></td>
<td class="text-center">
<a class="btn btn-danger btn-sm ask" data-backto="record-edit" data-op="delprodotto" data-idprodotto="'.$rs2[$i]['id'].'">
<i class="fa fa-trash"></i>
</a>
</td>';
2023-08-04 14:54:28 +02:00
}
echo '
</tr>';
}
echo '
</tbody>
</table>
</div>
</div>';
2023-07-05 11:43:07 +02:00
}
2019-08-28 11:52:04 +02:00
echo '
<script type="text/javascript">
2019-08-28 11:52:04 +02:00
$(document).ready(function() {
2020-04-15 16:43:23 +02:00
$("#table-serials").DataTable().draw();
2019-08-28 11:52:04 +02:00
$("#serials").removeClass("superselect");
$("#serials").select2().select2("destroy");
$("#serials").select2({
2024-05-20 13:17:14 +02:00
theme: "bootstrap4",
2019-08-28 11:52:04 +02:00
language: "it",
allowClear: true,
tags: true,
tokenSeparators: [\',\']
});
});
2019-12-13 16:32:53 +01:00
function addSerial(form_id, numero) {
2019-08-28 11:52:04 +02:00
if (numero > 0){
swal({
2019-08-28 16:58:47 +02:00
title: "'.tr('Nuovi seriali').'",
html: "'.tr("Confermi l'inserimento di _NUM_ nuovi seriali?", [
2024-03-22 15:52:24 +01:00
'_NUM_' => '" + numero + "',
]).'",
2019-08-28 11:52:04 +02:00
type: "success",
showCancelButton: true,
2019-08-28 16:58:47 +02:00
confirmButtonText: "'.tr('Continua').'"
2019-08-28 11:52:04 +02:00
}).then(function (result) {
2023-07-05 11:43:07 +02:00
if ($("div[id^=bs-popup").is(":visible")) {
salvaForm($(form_id), {
}).then(function(response) {
$(form_id).closest("div[id^=bs-popup").modal("hide");
});
} else {
$(form_id).submit();
}
2019-08-28 11:52:04 +02:00
})
} else {
swal("'.tr('Errore').'", "'.tr('Nessun seriale inserito').'", "error");
}
}
2019-08-28 11:52:04 +02:00
function ricalcola_generazione(){
if($("#serial_start").val() == undefined) return 0;
2019-08-28 11:52:04 +02:00
var serial_start = get_last_numeric_part( $("#serial_start").val().toString() );
var serial_end = get_last_numeric_part( $("#serial_end").val().toString() );
var serial = Math.abs(parseInt(serial_end, 10) - parseInt(serial_start, 10))+1;
2019-08-28 11:52:04 +02:00
// Se tutti i campi sono vuoti, il numero di prodotti è zero!
if(isNaN(serial)) {
serial = 0;
}
2019-08-28 11:52:04 +02:00
$("#totale_generazione").text(serial);
}
2019-08-28 11:52:04 +02:00
function ricalcola_inserimento(){
$("#totale_inserimento").text($("#serials").select2("data").length);
}
/*
Questa funzione restituisce la parte numerica di una stringa
*/
2019-08-28 11:52:04 +02:00
function get_last_numeric_part(str){
var matches = str.match(/(.*?)([\d]*$)/);
return matches[2];
}
2019-08-28 11:52:04 +02:00
</script>';