mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-02-16 19:40:44 +01:00
Aggiunto controllo di sequenzialità sui codici Attività
This commit is contained in:
parent
7160591262
commit
b268093d54
@ -77,8 +77,9 @@ if ($dir == 'entrata' && !empty($fattura->dichiarazione) && $fattura->stato->des
|
||||
}
|
||||
}
|
||||
|
||||
// Verifica aggiuntive sulla sequenzialità dei numeri
|
||||
if ($dir == 'entrata') {
|
||||
$numero_previsto = verifica_numero($fattura);
|
||||
$numero_previsto = verifica_numero_fattura($fattura);
|
||||
if (!empty($numero_previsto)) {
|
||||
echo '
|
||||
<div class="alert alert-warning">
|
||||
|
@ -498,7 +498,7 @@ function add_articolo_infattura($iddocumento, $idarticolo, $descrizione, $idiva,
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
function verifica_numero(Fattura $fattura)
|
||||
function verifica_numero_fattura(Fattura $fattura)
|
||||
{
|
||||
if (empty($fattura->numero_esterno)) {
|
||||
return null;
|
||||
@ -507,8 +507,8 @@ function verifica_numero(Fattura $fattura)
|
||||
$id_segment = $fattura->id_segment;
|
||||
$data = $fattura->data;
|
||||
|
||||
$documenti = Fattura::where('id_segment', $id_segment)
|
||||
->where('data', $data)
|
||||
$documenti = Fattura::where('id_segment', '=', $id_segment)
|
||||
->where('data', '=', $data)
|
||||
->get();
|
||||
|
||||
// Recupero maschera per questo segmento
|
||||
|
@ -43,6 +43,7 @@ switch (post('op')) {
|
||||
}
|
||||
|
||||
// Salvataggio modifiche intervento
|
||||
$intervento->codice = post('codice');
|
||||
$intervento->data_richiesta = post('data_richiesta');
|
||||
$intervento->data_scadenza = post('data_scadenza') ?: null;
|
||||
$intervento->richiesta = post('richiesta');
|
||||
|
@ -25,6 +25,18 @@ include_once __DIR__.'/../../core.php';
|
||||
$block_edit = $record['flag_completato'];
|
||||
$module_anagrafiche = Modules::get('Anagrafiche');
|
||||
|
||||
// Verifica aggiuntive sulla sequenzialità dei numeri
|
||||
$numero_previsto = verifica_numero_intervento($intervento);
|
||||
if (!empty($numero_previsto)) {
|
||||
echo '
|
||||
<div class="alert alert-warning">
|
||||
<i class="fa fa-warning"></i> '.tr("E' assente una attività di numero _NUM_ in data precedente o corrispondente a _DATE_: si potrebbero verificare dei problemi con la numerazione corrente delle attività", [
|
||||
'_DATE_' => dateFormat($intervento->data_richiesta),
|
||||
'_NUM_' => '"'.$numero_previsto.'"',
|
||||
]).'.</b>
|
||||
</div>';
|
||||
}
|
||||
|
||||
echo '
|
||||
<form action="" method="post" id="edit-form">
|
||||
<input type="hidden" name="op" value="update">
|
||||
@ -242,7 +254,7 @@ echo '
|
||||
<!-- RIGA 3 -->
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
{[ "type": "span", "label": "<?php echo tr('Numero'); ?>", "name": "codice", "value": "$codice$", "readonly": "<?php echo $record['flag_completato']; ?>" ]}
|
||||
{[ "type": "text", "label": "<?php echo tr('Numero'); ?>", "name": "codice", "value": "$codice$", "readonly": "<?php echo $record['flag_completato']; ?>" ]}
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
|
@ -28,6 +28,7 @@ use Modules\Fatture\Components\Riga;
|
||||
use Modules\Fatture\Fattura;
|
||||
use Modules\Interventi\Components\Sessione;
|
||||
use Modules\Interventi\Intervento;
|
||||
use Util\Generator;
|
||||
use Util\Ini;
|
||||
|
||||
/**
|
||||
@ -287,3 +288,51 @@ function aggiungi_intervento_in_fattura($id_intervento, $id_fattura, $descrizion
|
||||
// Metto l'intervento in stato "Fatturato"
|
||||
$dbo->query("UPDATE in_interventi SET idstatointervento=(SELECT idstatointervento FROM in_statiintervento WHERE codice='FAT') WHERE id=".prepare($id_intervento));
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifica che il numero_esterno della fattura indicata sia correttamente impostato, a partire dai valori delle fatture ai giorni precedenti.
|
||||
* Restituisce il numero_esterno mancante in caso di numero errato.
|
||||
*
|
||||
* @return bool|string
|
||||
*/
|
||||
function verifica_numero_intervento(Intervento $intervento)
|
||||
{
|
||||
if (empty($intervento->codice)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $intervento->data_richiesta;
|
||||
$documenti = Intervento::where('data_richiesta', '=', $data)
|
||||
->get();
|
||||
|
||||
// Recupero maschera per questo segmento
|
||||
$maschera = setting('Formato codice attività');
|
||||
|
||||
if ((strpos($maschera, 'YYYY') !== false) or (strpos($maschera, 'yy') !== false)) {
|
||||
$ultimo = Generator::getPreviousFrom($maschera, 'in_interventi', 'codice', [
|
||||
'DATE(data_richiesta) < '.prepare(date('Y-m-d', strtotime($data))),
|
||||
'YEAR(data_richiesta) = '.prepare(date('Y', strtotime($data))),
|
||||
], $data);
|
||||
} else {
|
||||
$ultimo = Generator::getPreviousFrom($maschera, 'in_interventi', 'codice', [
|
||||
'DATE(data_richiesta) < '.prepare(date('Y-m-d', strtotime($data))),
|
||||
]);
|
||||
}
|
||||
|
||||
do {
|
||||
$numero = Generator::generate($maschera, $ultimo, 1, Generator::dateToPattern($data), $data);
|
||||
|
||||
$filtered = $documenti->reject(function ($item, $key) use ($numero) {
|
||||
return $item->codice == $numero;
|
||||
});
|
||||
|
||||
if ($documenti->count() == $filtered->count()) {
|
||||
return $numero;
|
||||
}
|
||||
|
||||
$documenti = $filtered;
|
||||
$ultimo = $numero;
|
||||
} while ($numero != $intervento->codice);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user