mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-06-05 22:09:38 +02:00
Miglioramento informativa numerazioni
Aggiunto controllo su numerazioni di Fatture di acquisto e DDT in entrata, miglioramento delle informazioni sulla numerazione delle Fatture di vendita.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Modules\Fatture\Fattura;
|
||||
use Util\Generator;
|
||||
|
||||
/**
|
||||
* Funzione per generare un nuovo numero per la fattura.
|
||||
@@ -461,3 +462,49 @@ function add_articolo_infattura($iddocumento, $idarticolo, $descrizione, $idiva,
|
||||
|
||||
return $idriga;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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(Fattura $fattura)
|
||||
{
|
||||
if (empty($fattura->numero_esterno)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$id_segment = $fattura->id_segment;
|
||||
$data = $fattura->data;
|
||||
|
||||
$documenti = Fattura::where('id_segment', $id_segment)
|
||||
->where('data', $data)
|
||||
->get();
|
||||
|
||||
// Recupero maschera per questo segmento
|
||||
$maschera = Generator::getMaschera($id_segment);
|
||||
|
||||
$ultimo = Generator::getPreviousFrom($maschera, 'co_documenti', 'numero_esterno', [
|
||||
'data < '.prepare(date('Y-m-d', strtotime($data))),
|
||||
'YEAR(data) = '.prepare(date('Y', strtotime($data))),
|
||||
'id_segment = '.prepare($id_segment),
|
||||
]);
|
||||
|
||||
do {
|
||||
$numero = Generator::generate($maschera, $ultimo, 1, Generator::dateToPattern($data));
|
||||
|
||||
$filtered = $documenti->reject(function ($item, $key) use ($numero) {
|
||||
return $item->numero_esterno == $numero;
|
||||
});
|
||||
|
||||
if ($documenti->count() == $filtered->count()) {
|
||||
return $numero;
|
||||
}
|
||||
|
||||
$documenti = $filtered;
|
||||
$ultimo = $numero;
|
||||
} while ($numero != $fattura->numero_esterno);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user