mirror of
https://github.com/devcode-it/openstamanager.git
synced 2025-03-12 09:10:19 +01:00
Miglioramento dei controlli automatici
Inizio dell'automazione delle verifiche sugli stati dei documenti.
This commit is contained in:
parent
093d534e10
commit
2450c638b5
@ -13,7 +13,7 @@ if (empty($id_record) && !empty($id_module)) {
|
|||||||
include_once App::filepath('include|custom|', 'top.php');
|
include_once App::filepath('include|custom|', 'top.php');
|
||||||
|
|
||||||
Util\Query::setSegments(false);
|
Util\Query::setSegments(false);
|
||||||
$query = Util\Query::getQuery($module, [
|
$query = Util\Query::getQuery($structure, [
|
||||||
'id' => $id_record,
|
'id' => $id_record,
|
||||||
]);
|
]);
|
||||||
Util\Query::setSegments(true);
|
Util\Query::setSegments(true);
|
||||||
|
@ -29,7 +29,7 @@ if (empty($id_conto)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Selezione articoli dell'ordine da portare nel ddt
|
// Selezione articoli dell'ordine da portare nel ddt
|
||||||
$righe = $dbo->fetchArray('SELECT *, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),"") AS codice, (qta - qta_evasa) AS qta_rimanente FROM '.$table.' INNER JOIN '.$rows.' ON '.$table.'.id='.$rows.'.'.$id_rows.' WHERE '.$table.'.id='.prepare($id_record).' HAVING qta_rimanente > 0 OR is_descrizione = 1 ORDER BY `order`');
|
$righe = $dbo->fetchArray('SELECT *, IFNULL((SELECT codice FROM mg_articoli WHERE id=idarticolo),"") AS codice, (qta - qta_evasa) AS qta_rimanente FROM '.$table.' INNER JOIN '.$rows.' ON '.$table.'.id='.$rows.'.'.$id_rows.' WHERE '.$table.'.id='.prepare($id_record).' HAVING qta_rimanente > 0 ORDER BY `order`');
|
||||||
|
|
||||||
if (!empty($righe)) {
|
if (!empty($righe)) {
|
||||||
echo '
|
echo '
|
||||||
|
@ -169,6 +169,18 @@ abstract class Article extends Row
|
|||||||
return parent::save($options);
|
return parent::save($options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
$this->serials = [];
|
||||||
|
|
||||||
|
$this->qta = 0; // Fix movimentazione automatica
|
||||||
|
if (!empty($this->qta_movimentazione)) {
|
||||||
|
$this->movimenta($this->qta_movimentazione);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::delete();
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected function movimentaMagazzino($qta);
|
abstract protected function movimentaMagazzino($qta);
|
||||||
|
|
||||||
protected static function boot()
|
protected static function boot()
|
||||||
|
@ -72,8 +72,11 @@ abstract class Description extends Model
|
|||||||
public function delete()
|
public function delete()
|
||||||
{
|
{
|
||||||
$this->qta = 0;
|
$this->qta = 0;
|
||||||
|
$result = parent::delete();
|
||||||
|
|
||||||
return parent::delete();
|
$this->parent->controllo($this);
|
||||||
|
|
||||||
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,6 +117,9 @@ abstract class Description extends Model
|
|||||||
// Attributi dell'oggetto da copiare
|
// Attributi dell'oggetto da copiare
|
||||||
$attributes = $this->getAttributes();
|
$attributes = $this->getAttributes();
|
||||||
unset($attributes['id']);
|
unset($attributes['id']);
|
||||||
|
unset($attributes['original_id']);
|
||||||
|
unset($attributes['original_type']);
|
||||||
|
unset($attributes['order']);
|
||||||
|
|
||||||
if ($qta !== null) {
|
if ($qta !== null) {
|
||||||
$attributes['qta'] = $qta;
|
$attributes['qta'] = $qta;
|
||||||
@ -124,9 +130,15 @@ abstract class Description extends Model
|
|||||||
// Creazione del nuovo oggetto
|
// Creazione del nuovo oggetto
|
||||||
$model = new $object();
|
$model = new $object();
|
||||||
|
|
||||||
|
// Rimozione attributo in conflitto
|
||||||
|
unset($attributes[$model->getParentID()]);
|
||||||
|
|
||||||
$model->original_id = $this->id;
|
$model->original_id = $this->id;
|
||||||
$model->original_type = $current;
|
$model->original_type = $current;
|
||||||
|
|
||||||
|
// Impostazione del genitore
|
||||||
|
$model->setParent($document);
|
||||||
|
|
||||||
// Azioni specifiche di inizalizzazione
|
// Azioni specifiche di inizalizzazione
|
||||||
$model->customInitCopiaIn($this);
|
$model->customInitCopiaIn($this);
|
||||||
|
|
||||||
@ -142,9 +154,6 @@ abstract class Description extends Model
|
|||||||
$attributes = array_intersect_key($attributes, $accepted);
|
$attributes = array_intersect_key($attributes, $accepted);
|
||||||
$model->fill($attributes);
|
$model->fill($attributes);
|
||||||
|
|
||||||
// Impostazione del genitore
|
|
||||||
$model->setParent($document);
|
|
||||||
|
|
||||||
// Azioni specifiche successive
|
// Azioni specifiche successive
|
||||||
$model->customAfterDataCopiaIn($this);
|
$model->customAfterDataCopiaIn($this);
|
||||||
|
|
||||||
@ -177,6 +186,15 @@ abstract class Description extends Model
|
|||||||
return $this instanceof Article;
|
return $this instanceof Article;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function save(array $options = [])
|
||||||
|
{
|
||||||
|
$result = parent::save($options);
|
||||||
|
|
||||||
|
$this->parent->controllo($this);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Azione personalizzata per la copia dell'oggetto (inizializzazione della copia).
|
* Azione personalizzata per la copia dell'oggetto (inizializzazione della copia).
|
||||||
*
|
*
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace Common;
|
namespace Common;
|
||||||
|
|
||||||
|
use Common\Components\Description;
|
||||||
|
|
||||||
abstract class Document extends Model
|
abstract class Document extends Model
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@ -130,6 +132,20 @@ abstract class Document extends Model
|
|||||||
return parent::delete();
|
return parent::delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effettua un controllo sui campi del documento.
|
||||||
|
* Viene richiamatp dalle modifiche alle righe del documento.
|
||||||
|
*
|
||||||
|
* @param Description $trigger
|
||||||
|
*/
|
||||||
|
public function controllo(Description $trigger)
|
||||||
|
{
|
||||||
|
$this->load('righe');
|
||||||
|
$this->load('articoli');
|
||||||
|
$this->load('descrizioni');
|
||||||
|
$this->load('sconti');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calcola la somma degli attributi indicati come parametri.
|
* Calcola la somma degli attributi indicati come parametri.
|
||||||
* Il metodo **non** deve essere adattato per ulteriori funzionalità: deve esclusivamente calcolare la somma richiesta in modo esplicito dagli argomenti.
|
* Il metodo **non** deve essere adattato per ulteriori funzionalità: deve esclusivamente calcolare la somma richiesta in modo esplicito dagli argomenti.
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
namespace Modules\Contratti;
|
namespace Modules\Contratti;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Common\Components\Description;
|
||||||
use Common\Document;
|
use Common\Document;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
use Modules\Interventi\Intervento;
|
use Modules\Interventi\Intervento;
|
||||||
|
use Modules\Ordini\Ordine;
|
||||||
use Modules\TipiIntervento\Tipo as TipoSessione;
|
use Modules\TipiIntervento\Tipo as TipoSessione;
|
||||||
use Traits\RecordTrait;
|
use Traits\RecordTrait;
|
||||||
use Util\Generator;
|
use Util\Generator;
|
||||||
@ -149,6 +151,47 @@ class Contratto extends Document
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effettua un controllo sui campi del documento.
|
||||||
|
* Viene richiamatp dalle modifiche alle righe del documento.
|
||||||
|
*
|
||||||
|
* @param Description $trigger
|
||||||
|
*/
|
||||||
|
public function controllo(Description $trigger)
|
||||||
|
{
|
||||||
|
parent::controllo($trigger);
|
||||||
|
|
||||||
|
$righe = $this->getRighe();
|
||||||
|
|
||||||
|
$qta_evasa = $righe->sum('qta_evasa');
|
||||||
|
$qta = $righe->sum('qta');
|
||||||
|
$parziale = $qta != $qta_evasa;
|
||||||
|
|
||||||
|
// Impostazione del nuovo stato
|
||||||
|
if ($qta_evasa == 0) {
|
||||||
|
$descrizione = 'In lavorazione';
|
||||||
|
$descrizione_intervento = 'Completato';
|
||||||
|
} elseif ($trigger->parent instanceof Ordine) {
|
||||||
|
$descrizione = $this->stato->descrizione;
|
||||||
|
$descrizione_intervento = 'Completato';
|
||||||
|
} else {
|
||||||
|
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
||||||
|
$descrizione_intervento = 'Fatturato';
|
||||||
|
}
|
||||||
|
|
||||||
|
$stato = Stato::where('descrizione', $descrizione)->first();
|
||||||
|
$this->stato()->associate($stato);
|
||||||
|
$this->save();
|
||||||
|
|
||||||
|
// Trasferimento degli interventi collegati
|
||||||
|
$interventi = $this->interventi;
|
||||||
|
$stato_intervento = \Modules\Interventi\Stato::where('descrizione', $descrizione_intervento)->first();
|
||||||
|
foreach ($interventi as $intervento) {
|
||||||
|
$intervento->stato()->associate($stato_intervento);
|
||||||
|
$intervento->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Metodi statici
|
// Metodi statici
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace Modules\DDT;
|
namespace Modules\DDT;
|
||||||
|
|
||||||
use Auth;
|
use Auth;
|
||||||
|
use Common\Components\Description;
|
||||||
use Common\Document;
|
use Common\Document;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
use Traits\RecordTrait;
|
use Traits\RecordTrait;
|
||||||
@ -130,6 +131,36 @@ class DDT extends Document
|
|||||||
return $this->hasMany(Components\Descrizione::class, 'idddt');
|
return $this->hasMany(Components\Descrizione::class, 'idddt');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effettua un controllo sui campi del documento.
|
||||||
|
* Viene richiamatp dalle modifiche alle righe del documento.
|
||||||
|
*
|
||||||
|
* @param Description $trigger
|
||||||
|
*/
|
||||||
|
public function controllo(Description $trigger)
|
||||||
|
{
|
||||||
|
parent::controllo($trigger);
|
||||||
|
|
||||||
|
if (setting('Cambia automaticamente stato ddt fatturati')) {
|
||||||
|
$righe = $this->getRighe();
|
||||||
|
|
||||||
|
$qta_evasa = $righe->sum('qta_evasa');
|
||||||
|
$qta = $righe->sum('qta');
|
||||||
|
$parziale = $qta != $qta_evasa;
|
||||||
|
|
||||||
|
// Impostazione del nuovo stato
|
||||||
|
if ($qta_evasa == 0) {
|
||||||
|
$descrizione = 'Bozza';
|
||||||
|
} else {
|
||||||
|
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
||||||
|
}
|
||||||
|
|
||||||
|
$stato = Stato::where('descrizione', $descrizione)->first();
|
||||||
|
$this->stato()->associate($stato);
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Metodi statici
|
// Metodi statici
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -637,17 +637,16 @@ switch (post('op')) {
|
|||||||
|
|
||||||
// Scollegamento riga generica da documento
|
// Scollegamento riga generica da documento
|
||||||
case 'unlink_riga':
|
case 'unlink_riga':
|
||||||
if (post('idriga') !== null) {
|
$id_riga = post('idriga');
|
||||||
$idriga = post('idriga');
|
|
||||||
|
|
||||||
rimuovi_riga_fattura($id_record, $idriga, $dir);
|
if (!empty($id_riga)) {
|
||||||
|
$riga = $fattura->getRighe()->find($id_riga);
|
||||||
|
$riga->delete();
|
||||||
|
|
||||||
|
//rimuovi_riga_fattura($id_record, $idriga, $dir);
|
||||||
|
|
||||||
// Ricalcolo inps, ritenuta e bollo
|
// Ricalcolo inps, ritenuta e bollo
|
||||||
if ($dir == 'entrata') {
|
ricalcola_costiagg_fattura($id_record);
|
||||||
ricalcola_costiagg_fattura($id_record);
|
|
||||||
} else {
|
|
||||||
ricalcola_costiagg_fattura($id_record);
|
|
||||||
}
|
|
||||||
|
|
||||||
flash()->info(tr('Riga rimossa!'));
|
flash()->info(tr('Riga rimossa!'));
|
||||||
}
|
}
|
||||||
@ -699,7 +698,6 @@ switch (post('op')) {
|
|||||||
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
||||||
$id_conto = post('id_conto');
|
$id_conto = post('id_conto');
|
||||||
|
|
||||||
$parziale = false;
|
|
||||||
$righe = $ordine->getRighe();
|
$righe = $ordine->getRighe();
|
||||||
foreach ($righe as $riga) {
|
foreach ($righe as $riga) {
|
||||||
if (post('evadere')[$riga->id] == 'on') {
|
if (post('evadere')[$riga->id] == 'on') {
|
||||||
@ -723,18 +721,8 @@ switch (post('op')) {
|
|||||||
|
|
||||||
$copia->save();
|
$copia->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($riga->qta != $riga->qta_evasa) {
|
|
||||||
$parziale = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Impostazione del nuovo stato
|
|
||||||
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
|
||||||
$stato = \Modules\Ordini\Stato::where('descrizione', $descrizione)->first();
|
|
||||||
$ordine->stato()->associate($stato);
|
|
||||||
$ordine->save();
|
|
||||||
|
|
||||||
ricalcola_costiagg_fattura($id_record);
|
ricalcola_costiagg_fattura($id_record);
|
||||||
aggiorna_sedi_movimenti('documenti', $id_record);
|
aggiorna_sedi_movimenti('documenti', $id_record);
|
||||||
|
|
||||||
@ -769,7 +757,6 @@ switch (post('op')) {
|
|||||||
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
||||||
$id_conto = post('id_conto');
|
$id_conto = post('id_conto');
|
||||||
|
|
||||||
$parziale = false;
|
|
||||||
$righe = $ddt->getRighe();
|
$righe = $ddt->getRighe();
|
||||||
foreach ($righe as $riga) {
|
foreach ($righe as $riga) {
|
||||||
if (post('evadere')[$riga->id] == 'on') {
|
if (post('evadere')[$riga->id] == 'on') {
|
||||||
@ -791,18 +778,8 @@ switch (post('op')) {
|
|||||||
|
|
||||||
$copia->save();
|
$copia->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($riga->qta != $riga->qta_evasa) {
|
|
||||||
$parziale = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Impostazione del nuovo stato
|
|
||||||
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
|
||||||
$stato = \Modules\DDT\Stato::where('descrizione', $descrizione)->first();
|
|
||||||
$ddt->stato()->associate($stato);
|
|
||||||
$ddt->save();
|
|
||||||
|
|
||||||
ricalcola_costiagg_fattura($id_record);
|
ricalcola_costiagg_fattura($id_record);
|
||||||
aggiorna_sedi_movimenti('documenti', $id_record);
|
aggiorna_sedi_movimenti('documenti', $id_record);
|
||||||
|
|
||||||
@ -836,7 +813,6 @@ switch (post('op')) {
|
|||||||
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
||||||
$id_conto = post('id_conto');
|
$id_conto = post('id_conto');
|
||||||
|
|
||||||
$parziale = false;
|
|
||||||
$righe = $preventivo->getRighe();
|
$righe = $preventivo->getRighe();
|
||||||
foreach ($righe as $riga) {
|
foreach ($righe as $riga) {
|
||||||
if (post('evadere')[$riga->id] == 'on') {
|
if (post('evadere')[$riga->id] == 'on') {
|
||||||
@ -856,24 +832,6 @@ switch (post('op')) {
|
|||||||
|
|
||||||
$copia->save();
|
$copia->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($riga->qta != $riga->qta_evasa) {
|
|
||||||
$parziale = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Impostazione del nuovo stato
|
|
||||||
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
|
||||||
$stato = \Modules\Preventivi\Stato::where('descrizione', $descrizione)->first();
|
|
||||||
$preventivo->stato()->associate($stato);
|
|
||||||
$preventivo->save();
|
|
||||||
|
|
||||||
// Trasferimento degli interventi collegati
|
|
||||||
$interventi = $preventivo->interventi;
|
|
||||||
$stato_intervento = \Modules\Interventi\Stato::where('descrizione', 'Fatturato')->first();
|
|
||||||
foreach ($interventi as $intervento) {
|
|
||||||
$intervento->stato()->associate($stato_intervento);
|
|
||||||
$intervento->save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ricalcola_costiagg_fattura($id_record);
|
ricalcola_costiagg_fattura($id_record);
|
||||||
@ -909,7 +867,6 @@ switch (post('op')) {
|
|||||||
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
$calcolo_ritenuta_acconto = setting("Metodologia calcolo ritenuta d'acconto predefinito");
|
||||||
$id_conto = post('id_conto');
|
$id_conto = post('id_conto');
|
||||||
|
|
||||||
$parziale = false;
|
|
||||||
$righe = $contratto->getRighe();
|
$righe = $contratto->getRighe();
|
||||||
foreach ($righe as $riga) {
|
foreach ($righe as $riga) {
|
||||||
if (post('evadere')[$riga->id] == 'on') {
|
if (post('evadere')[$riga->id] == 'on') {
|
||||||
@ -929,24 +886,6 @@ switch (post('op')) {
|
|||||||
|
|
||||||
$copia->save();
|
$copia->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($riga->qta != $riga->qta_evasa) {
|
|
||||||
$parziale = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Impostazione del nuovo stato
|
|
||||||
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
|
||||||
$stato = \Modules\Contratti\Stato::where('descrizione', $descrizione)->first();
|
|
||||||
$contratto->stato()->associate($stato);
|
|
||||||
$contratto->save();
|
|
||||||
|
|
||||||
// Trasferimento degli interventi collegati
|
|
||||||
$interventi = $contratto->interventi;
|
|
||||||
$stato_intervento = \Modules\Interventi\Stato::where('descrizione', 'Fatturato')->first();
|
|
||||||
foreach ($interventi as $intervento) {
|
|
||||||
$intervento->stato()->associate($stato_intervento);
|
|
||||||
$intervento->save();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ricalcola_costiagg_fattura($id_record);
|
ricalcola_costiagg_fattura($id_record);
|
||||||
|
@ -253,7 +253,7 @@ foreach ($righe as $row) {
|
|||||||
<form action='".$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record."' method='post' id='delete-form-".$riga['id']."' role='form'>
|
<form action='".$rootdir.'/editor.php?id_module='.$id_module.'&id_record='.$id_record."' method='post' id='delete-form-".$riga['id']."' role='form'>
|
||||||
<input type='hidden' name='backto' value='record-edit'>
|
<input type='hidden' name='backto' value='record-edit'>
|
||||||
<input type='hidden' name='idriga' value='".$riga['id']."'>
|
<input type='hidden' name='idriga' value='".$riga['id']."'>
|
||||||
<input type='hidden' name='op' value='".$delete."'>";
|
<input type='hidden' name='op' value='unlink_riga'>";
|
||||||
|
|
||||||
if ($row->isArticolo()) {
|
if ($row->isArticolo()) {
|
||||||
echo "
|
echo "
|
||||||
|
@ -39,6 +39,7 @@ $_SESSION['superselect']['idanagrafica'] = $record['idanagrafica'];
|
|||||||
|
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
if (setting('Cambia automaticamente stato ordini fatturati')) {
|
if (setting('Cambia automaticamente stato ordini fatturati')) {
|
||||||
if ($record['stato'] == 'Evaso' || $record['stato'] == 'Parzialmente evaso' || $record['stato'] == 'Fatturato' || $record['stato'] == 'Parzialmente fatturato') {
|
if ($record['stato'] == 'Evaso' || $record['stato'] == 'Parzialmente evaso' || $record['stato'] == 'Fatturato' || $record['stato'] == 'Parzialmente fatturato') {
|
||||||
?>
|
?>
|
||||||
|
@ -6,9 +6,9 @@ if (isset($id_record)) {
|
|||||||
$ordine = Modules\Ordini\Ordine::with('tipo', 'stato')->find($id_record);
|
$ordine = Modules\Ordini\Ordine::with('tipo', 'stato')->find($id_record);
|
||||||
|
|
||||||
// Aggiornamento stato di questo ordine (?)
|
// Aggiornamento stato di questo ordine (?)
|
||||||
if (!empty(get_stato_ordine($id_record)) && setting('Cambia automaticamente stato ordini fatturati')) {
|
//if (!empty(get_stato_ordine($id_record)) && setting('Cambia automaticamente stato ordini fatturati')) {
|
||||||
$dbo->query('UPDATE or_ordini SET idstatoordine=(SELECT id FROM or_statiordine WHERE descrizione="'.get_stato_ordine($id_record).'") WHERE id='.prepare($id_record));
|
// $dbo->query('UPDATE or_ordini SET idstatoordine=(SELECT id FROM or_statiordine WHERE descrizione="'.get_stato_ordine($id_record).'") WHERE id='.prepare($id_record));
|
||||||
}
|
//}
|
||||||
|
|
||||||
$record = $dbo->fetchOne('SELECT *,
|
$record = $dbo->fetchOne('SELECT *,
|
||||||
or_ordini.note,
|
or_ordini.note,
|
||||||
|
@ -2,8 +2,10 @@
|
|||||||
|
|
||||||
namespace Modules\Ordini;
|
namespace Modules\Ordini;
|
||||||
|
|
||||||
|
use Common\Components\Description;
|
||||||
use Common\Document;
|
use Common\Document;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
|
use Modules\DDT\DDT;
|
||||||
use Traits\RecordTrait;
|
use Traits\RecordTrait;
|
||||||
use Util\Generator;
|
use Util\Generator;
|
||||||
|
|
||||||
@ -120,6 +122,38 @@ class Ordine extends Document
|
|||||||
return $this->hasMany(Components\Descrizione::class, 'idordine');
|
return $this->hasMany(Components\Descrizione::class, 'idordine');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effettua un controllo sui campi del documento.
|
||||||
|
* Viene richiamatp dalle modifiche alle righe del documento.
|
||||||
|
*
|
||||||
|
* @param Description $trigger
|
||||||
|
*/
|
||||||
|
public function controllo(Description $trigger)
|
||||||
|
{
|
||||||
|
parent::controllo($trigger);
|
||||||
|
|
||||||
|
if (setting('Cambia automaticamente stato ordini fatturati')) {
|
||||||
|
$righe = $this->getRighe();
|
||||||
|
|
||||||
|
$qta_evasa = $righe->sum('qta_evasa');
|
||||||
|
$qta = $righe->sum('qta');
|
||||||
|
$parziale = $qta != $qta_evasa;
|
||||||
|
|
||||||
|
// Impostazione del nuovo stato
|
||||||
|
if ($qta_evasa == 0) {
|
||||||
|
$descrizione = 'Bozza';
|
||||||
|
} elseif ($trigger->parent instanceof DDT) {
|
||||||
|
$descrizione = $parziale ? 'Parzialmente evaso' : 'Evaso';
|
||||||
|
} else {
|
||||||
|
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
||||||
|
}
|
||||||
|
|
||||||
|
$stato = Stato::where('descrizione', $descrizione)->first();
|
||||||
|
$this->stato()->associate($stato);
|
||||||
|
$this->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Metodi statici
|
// Metodi statici
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
namespace Modules\Preventivi;
|
namespace Modules\Preventivi;
|
||||||
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use Common\Components\Description;
|
||||||
use Common\Document;
|
use Common\Document;
|
||||||
use Modules\Anagrafiche\Anagrafica;
|
use Modules\Anagrafiche\Anagrafica;
|
||||||
use Modules\Interventi\Intervento;
|
use Modules\Interventi\Intervento;
|
||||||
|
use Modules\Ordini\Ordine;
|
||||||
use Modules\TipiIntervento\Tipo as TipoSessione;
|
use Modules\TipiIntervento\Tipo as TipoSessione;
|
||||||
use Traits\RecordTrait;
|
use Traits\RecordTrait;
|
||||||
use Util\Generator;
|
use Util\Generator;
|
||||||
@ -155,6 +157,47 @@ class Preventivo extends Document
|
|||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Effettua un controllo sui campi del documento.
|
||||||
|
* Viene richiamatp dalle modifiche alle righe del documento.
|
||||||
|
*
|
||||||
|
* @param Description $trigger
|
||||||
|
*/
|
||||||
|
public function controllo(Description $trigger)
|
||||||
|
{
|
||||||
|
parent::controllo($trigger);
|
||||||
|
|
||||||
|
$righe = $this->getRighe();
|
||||||
|
|
||||||
|
$qta_evasa = $righe->sum('qta_evasa');
|
||||||
|
$qta = $righe->sum('qta');
|
||||||
|
$parziale = $qta != $qta_evasa;
|
||||||
|
|
||||||
|
// Impostazione del nuovo stato
|
||||||
|
if ($qta_evasa == 0) {
|
||||||
|
$descrizione = 'In lavorazione';
|
||||||
|
$descrizione_intervento = 'Completato';
|
||||||
|
} elseif ($trigger->parent instanceof Ordine) {
|
||||||
|
$descrizione = $this->stato->descrizione;
|
||||||
|
$descrizione_intervento = 'Completato';
|
||||||
|
} else {
|
||||||
|
$descrizione = $parziale ? 'Parzialmente fatturato' : 'Fatturato';
|
||||||
|
$descrizione_intervento = 'Fatturato';
|
||||||
|
}
|
||||||
|
|
||||||
|
$stato = Stato::where('descrizione', $descrizione)->first();
|
||||||
|
$this->stato()->associate($stato);
|
||||||
|
$this->save();
|
||||||
|
|
||||||
|
// Trasferimento degli interventi collegati
|
||||||
|
$interventi = $this->interventi;
|
||||||
|
$stato_intervento = \Modules\Interventi\Stato::where('descrizione', $descrizione_intervento)->first();
|
||||||
|
foreach ($interventi as $intervento) {
|
||||||
|
$intervento->stato()->associate($stato_intervento);
|
||||||
|
$intervento->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Metodi statici
|
// Metodi statici
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,8 +19,18 @@ switch (filter('op')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (FatturaElettronica::isValid($file)) {
|
if (FatturaElettronica::isValid($file)) {
|
||||||
|
// Individuazione ID fisico
|
||||||
|
$files = Interaction::fileToImport();
|
||||||
|
foreach ($files as $key => $value) {
|
||||||
|
if ($value['name'] == $file) {
|
||||||
|
$index = $key;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'filename' => $file,
|
'id' => $index + 1,
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
|
@ -4,6 +4,12 @@ include_once __DIR__.'/../../core.php';
|
|||||||
|
|
||||||
use Plugins\ImportFE\Interaction;
|
use Plugins\ImportFE\Interaction;
|
||||||
|
|
||||||
|
if (!empty($fattura_pa)) {
|
||||||
|
include $structure->filepath('generate.php');
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<script>
|
<script>
|
||||||
function upload(btn) {
|
function upload(btn) {
|
||||||
@ -28,7 +34,7 @@ echo '
|
|||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
|
|
||||||
if (!data.already) {
|
if (!data.already) {
|
||||||
launch_modal("'.tr('Righe fattura').'", globals.rootdir + "/actions.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&op=list&filename=" + data.filename);
|
redirect(globals.rootdir + "/editor.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&id_record=" + data.id);
|
||||||
} else {
|
} else {
|
||||||
swal({
|
swal({
|
||||||
title: "'.tr('Fattura già importata').'.",
|
title: "'.tr('Fattura già importata').'.",
|
||||||
@ -37,6 +43,7 @@ echo '
|
|||||||
|
|
||||||
$("#blob").val("");
|
$("#blob").val("");
|
||||||
}
|
}
|
||||||
|
|
||||||
buttonRestore(btn, restore);
|
buttonRestore(btn, restore);
|
||||||
},
|
},
|
||||||
error: function(xhr) {
|
error: function(xhr) {
|
||||||
|
@ -2,23 +2,9 @@
|
|||||||
|
|
||||||
include_once __DIR__.'/../../core.php';
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
$filename = get('filename');
|
|
||||||
$fattura_pa = \Plugins\ImportFE\FatturaElettronica::manage($filename);
|
|
||||||
|
|
||||||
$filename = basename($filename, '.p7m');
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<form action="'.$rootdir.'/actions.php" method="post">
|
|
||||||
<input type="hidden" name="id_module" value="'.$id_module.'">
|
|
||||||
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
|
|
||||||
<input type="hidden" name="filename" value="'.$filename.'">
|
|
||||||
<input type="hidden" name="id_segment" value="'.get('id_segment').'">
|
|
||||||
<input type="hidden" name="id" value="'.get('id').'">
|
|
||||||
<input type="hidden" name="backto" value="record-edit">
|
|
||||||
<input type="hidden" name="op" value="generate">';
|
|
||||||
|
|
||||||
// Fornitore
|
// Fornitore
|
||||||
$fornitore = $fattura_pa->getAnagrafe();
|
$fornitore = $fattura_pa->getAnagrafe();
|
||||||
|
|
||||||
$ragione_sociale = $fornitore['ragione_sociale'] ?: $fornitore['cognome'].' '.$fornitore['nome'];
|
$ragione_sociale = $fornitore['ragione_sociale'] ?: $fornitore['cognome'].' '.$fornitore['nome'];
|
||||||
$codice_fiscale = $fornitore['codice_fiscale'];
|
$codice_fiscale = $fornitore['codice_fiscale'];
|
||||||
$partita_iva = $fornitore['partita_iva'];
|
$partita_iva = $fornitore['partita_iva'];
|
||||||
@ -31,13 +17,32 @@ $provincia = $sede['provincia'];
|
|||||||
|
|
||||||
// Dati generali
|
// Dati generali
|
||||||
$dati_generali = $fattura_pa->getBody()['DatiGenerali']['DatiGeneraliDocumento'];
|
$dati_generali = $fattura_pa->getBody()['DatiGenerali']['DatiGeneraliDocumento'];
|
||||||
$descrizione_documento = database()->fetchOne('SELECT CONCAT("(", codice, ") ", descrizione) AS descrizione FROM fe_tipi_documento WHERE codice = '.prepare($dati_generali['TipoDocumento']));
|
|
||||||
|
$tipo_documento = $database->fetchOne('SELECT CONCAT("(", codice, ") ", descrizione) AS descrizione FROM fe_tipi_documento WHERE codice = '.prepare($dati_generali['TipoDocumento']))['descrizione'];
|
||||||
|
|
||||||
|
$pagamenti = $fattura_pa->getBody()['DatiPagamento'];
|
||||||
|
$metodi = $pagamenti['DettaglioPagamento'];
|
||||||
|
$metodi = isset($metodi[0]) ? $metodi : [$metodi];
|
||||||
|
|
||||||
|
$codice_modalita_pagamento = $metodi[0]['ModalitaPagamento'];
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="row" >
|
<form action="'.$rootdir.'/actions.php" method="post">
|
||||||
<div class="col-md-6">
|
<input type="hidden" name="id_module" value="'.$id_module.'">
|
||||||
<h4>'.
|
<input type="hidden" name="id_plugin" value="'.$id_plugin.'">
|
||||||
$ragione_sociale.' '.((empty($idanagrafica = $dbo->fetchOne('SELECT idanagrafica FROM an_anagrafiche WHERE ( codice_fiscale = '.prepare($codice_fiscale).' AND codice_fiscale != \'\' ) OR ( piva = '.prepare($partita_iva).' AND piva != \'\' ) ')['idanagrafica'])) ? '<span class="badge badge-success" >'.tr('Nuova anagrafica').'</span>' : '<small>'.Modules::link('Anagrafiche', $idanagrafica, '', null, '')).'</small>'.'<br>
|
<input type="hidden" name="filename" value="'.$filename.'">
|
||||||
|
<input type="hidden" name="id_segment" value="'.get('id_segment').'">
|
||||||
|
<input type="hidden" name="id" value="'.get('id').'">
|
||||||
|
<input type="hidden" name="backto" value="record-edit">
|
||||||
|
<input type="hidden" name="op" value="generate">
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<h4>
|
||||||
|
'.$ragione_sociale.'
|
||||||
|
|
||||||
|
'.(empty($anagrafica) ? '<span class="badge badge-success">'.tr('Nuova anagrafica').'</span>' : '<small>'.Modules::link('Anagrafiche', $idanagrafica)).'</small><br>
|
||||||
|
|
||||||
<small>
|
<small>
|
||||||
'.(!empty($codice_fiscale) ? (tr('Codice Fiscale').': '.$codice_fiscale.'<br>') : '').'
|
'.(!empty($codice_fiscale) ? (tr('Codice Fiscale').': '.$codice_fiscale.'<br>') : '').'
|
||||||
'.(!empty($partita_iva) ? (tr('Partita IVA').': '.$partita_iva.'<br>') : '').'
|
'.(!empty($partita_iva) ? (tr('Partita IVA').': '.$partita_iva.'<br>') : '').'
|
||||||
@ -46,128 +51,111 @@ echo '
|
|||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-md-6">
|
<div class="col-md-3">
|
||||||
<h4>'.$dati_generali['Numero'];
|
<h4>
|
||||||
|
'.$dati_generali['Numero'].'
|
||||||
|
|
||||||
echo '
|
|
||||||
<a href="'.$structure->fileurl('view.php').'?filename='.$filename.'" class="btn btn-info btn-xs" target="_blank" >
|
<a href="'.$structure->fileurl('view.php').'?filename='.$filename.'" class="btn btn-info btn-xs" target="_blank" >
|
||||||
<i class="fa fa-eye"></i> '.tr('Visualizza').'
|
<i class="fa fa-eye"></i> '.tr('Visualizza').'
|
||||||
</a>';
|
</a>
|
||||||
|
|
||||||
echo '
|
|
||||||
<br><small>
|
<br><small>
|
||||||
'.database()->fetchOne('SELECT CONCAT("(", codice, ") ", descrizione) AS descrizione FROM fe_tipi_documento WHERE codice = '.prepare($dati_generali['TipoDocumento']))['descrizione'].'
|
'.$tipo_documento.'
|
||||||
<br>'.Translator::dateToLocale($dati_generali['Data']).'
|
<br>'.Translator::dateToLocale($dati_generali['Data']).'
|
||||||
<br>'.$dati_generali['Divisa'].'
|
<br>'.$dati_generali['Divisa'].'
|
||||||
</small>
|
</small>
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>';
|
||||||
|
|
||||||
|
// Blocco DatiPagamento è valorizzato (opzionale)
|
||||||
|
if (!empty($pagamenti)) {
|
||||||
|
echo '
|
||||||
|
<div class="col-md-6">
|
||||||
|
<h4>'.tr('Pagamento').'</h4>
|
||||||
|
|
||||||
|
<p>'.tr('La fattura importata presenta _NUM_ rat_E_ di pagamento con le seguenti scadenze', [
|
||||||
|
'_NUM_' => count($metodi),
|
||||||
|
'_E_' => ((count($metodi) > 1) ? 'e' : 'a'),
|
||||||
|
]).':</p>
|
||||||
|
<ol>';
|
||||||
|
|
||||||
|
// Scadenze di pagamento
|
||||||
|
foreach ($metodi as $metodo) {
|
||||||
|
$descrizione = !empty($metodo['ModalitaPagamento']) ? $database->fetchOne('SELECT descrizione FROM fe_modalita_pagamento WHERE codice = '.prepare($metodo['ModalitaPagamento']))['descrizione'] : '';
|
||||||
|
$data = !empty($metodo['DataScadenzaPagamento']) ? Translator::dateToLocale($metodo['DataScadenzaPagamento']).' ' : '';
|
||||||
|
|
||||||
|
echo '
|
||||||
|
<li>
|
||||||
|
'.$data.'
|
||||||
|
'.moneyFormat($metodo['ImportoPagamento']).'
|
||||||
|
('.$descrizione.')
|
||||||
|
</li>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '
|
||||||
|
</ol>
|
||||||
|
</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
echo '
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
// Tipo del documento
|
// Tipo del documento
|
||||||
$query = 'SELECT id, CONCAT (descrizione, IF((codice_tipo_documento_fe IS NULL), \'\', CONCAT( \' (\', codice_tipo_documento_fe, \')\' ) )) AS descrizione FROM co_tipidocumento WHERE dir = \'uscita\'';
|
$query = "SELECT id, CONCAT (descrizione, IF((codice_tipo_documento_fe IS NULL), '', CONCAT(' (', codice_tipo_documento_fe, ')' ) )) AS descrizione FROM co_tipidocumento WHERE dir = 'uscita'";
|
||||||
if (database()->fetchNum('SELECT id FROM co_tipidocumento WHERE codice_tipo_documento_fe = '.prepare($dati_generali['TipoDocumento']))) {
|
$query_tipo = $query.' AND codice_tipo_documento_fe = '.prepare($dati_generali['TipoDocumento']);
|
||||||
$query .= ' AND codice_tipo_documento_fe = '.prepare($dati_generali['TipoDocumento']);
|
if ($database->fetchNum($query_tipo)) {
|
||||||
|
$query = $query_tipo;
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-6">
|
<div class="col-md-3">
|
||||||
{[ "type": "select", "label": "'.tr('Tipo fattura').'", "name": "id_tipo", "required": 1, "values": "query='.$query.'" ]}
|
{[ "type": "select", "label": "'.tr('Tipo fattura').'", "name": "id_tipo", "required": 1, "values": "query='.$query.'" ]}
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
// Sezionale
|
// Sezionale
|
||||||
echo '
|
echo '
|
||||||
<div class="col-md-6">
|
<div class="col-md-3">
|
||||||
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.$id_module.' ORDER BY name", "value": "'.$_SESSION['module_'.$id_module]['id_segment'].'" ]}
|
{[ "type": "select", "label": "'.tr('Sezionale').'", "name": "id_segment", "required": 1, "values": "query=SELECT id, name AS descrizione FROM zz_segments WHERE id_module='.$id_module.' ORDER BY name", "value": "'.$_SESSION['module_'.$id_module]['id_segment'].'" ]}
|
||||||
</div>
|
</div>';
|
||||||
</div>';
|
|
||||||
|
|
||||||
// Data ricezione
|
// Data di registrazione
|
||||||
echo '
|
echo '
|
||||||
<div class="row" >
|
<div class="col-md-3">
|
||||||
<div class="col-md-6">
|
|
||||||
{[ "type": "date", "label": "'.tr('Data di registrazione').'", "name": "data_registrazione", "required": 1, "value": "'.get('data_registrazione').'", "max-date": "-now-", "min-date": "'.$dati_generali['Data'].'", "readonly": "'.(intval(get('data_registrazione') != null)).'" ]}
|
{[ "type": "date", "label": "'.tr('Data di registrazione').'", "name": "data_registrazione", "required": 1, "value": "'.get('data_registrazione').'", "max-date": "-now-", "min-date": "'.$dati_generali['Data'].'", "readonly": "'.(intval(get('data_registrazione') != null)).'" ]}
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
// Riferimenti ad altre fatture
|
if (!empty($anagrafica)) {
|
||||||
if (in_array($dati_generali['TipoDocumento'], ['TD04', 'TD05'])) {
|
|
||||||
$anagrafica = $fattura_pa->saveAnagrafica();
|
|
||||||
$query = "SELECT
|
$query = "SELECT
|
||||||
co_documenti.id,
|
co_documenti.id,
|
||||||
CONCAT('Fattura num. ', co_documenti.numero_esterno, ' del ', DATE_FORMAT(co_documenti.data, '%d/%m/%Y')) AS descrizione
|
CONCAT('Fattura num. ', co_documenti.numero_esterno, ' del ', DATE_FORMAT(co_documenti.data, '%d/%m/%Y')) AS descrizione
|
||||||
FROM co_documenti
|
FROM co_documenti
|
||||||
INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
|
INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
|
||||||
WHERE
|
WHERE
|
||||||
co_tipidocumento.dir = 'uscita' AND
|
co_tipidocumento.dir = 'uscita' AND
|
||||||
(co_documenti.data BETWEEN NOW() - INTERVAL 1 YEAR AND NOW()) AND
|
(co_documenti.data BETWEEN NOW() - INTERVAL 1 YEAR AND NOW()) AND
|
||||||
co_documenti.idstatodocumento IN (SELECT id FROM co_statidocumento WHERE descrizione != 'Bozza') AND
|
co_documenti.idstatodocumento IN (SELECT id FROM co_statidocumento WHERE descrizione != 'Bozza') AND
|
||||||
co_documenti.idanagrafica = ".prepare($anagrafica->id);
|
co_documenti.idanagrafica = ".prepare($anagrafica->id);
|
||||||
|
|
||||||
echo '
|
// Riferimenti ad altre fatture
|
||||||
<div class="col-md-6">
|
if (in_array($dati_generali['TipoDocumento'], ['TD04', 'TD05'])) {
|
||||||
|
echo '
|
||||||
|
<div class="col-md-3">
|
||||||
{[ "type": "select", "label": "'.tr('Fattura collegata').'", "name": "ref_fattura", "required": 1, "values": "query='.$query.'" ]}
|
{[ "type": "select", "label": "'.tr('Fattura collegata').'", "name": "ref_fattura", "required": 1, "values": "query='.$query.'" ]}
|
||||||
</div>';
|
</div>';
|
||||||
} elseif ($dati_generali['TipoDocumento'] == 'TD06') {
|
} elseif ($dati_generali['TipoDocumento'] == 'TD06') {
|
||||||
$anagrafica = $fattura_pa->saveAnagrafica();
|
$query .= "AND co_documenti.id_segment = (SELECT id FROM zz_segments WHERE name = 'Fatture pro-forma' AND id_module = ".prepare($id_module).')';
|
||||||
$query = "SELECT
|
|
||||||
co_documenti.id,
|
|
||||||
CONCAT('Fattura num. ', co_documenti.numero_esterno, ' del ', DATE_FORMAT(co_documenti.data, '%d/%m/%Y')) AS descrizione
|
|
||||||
FROM co_documenti
|
|
||||||
INNER JOIN co_tipidocumento ON co_tipidocumento.id = co_documenti.idtipodocumento
|
|
||||||
WHERE
|
|
||||||
co_tipidocumento.dir = 'uscita' AND
|
|
||||||
(co_documenti.data BETWEEN NOW() - INTERVAL 1 YEAR AND NOW()) AND
|
|
||||||
co_documenti.idstatodocumento IN (SELECT id FROM co_statidocumento WHERE descrizione != 'Bozza') AND
|
|
||||||
co_documenti.id_segment = (SELECT id FROM zz_segments WHERE name = 'Fatture pro-forma' AND id_module = ".prepare($id_module).') AND
|
|
||||||
co_documenti.idanagrafica = '.prepare($anagrafica->id);
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="col-md-6">
|
<div class="col-md-3">
|
||||||
{[ "type": "select", "label": "'.tr('Fattura pro-forma').'", "name": "ref_fattura", "values": "query='.$query.'" ]}
|
{[ "type": "select", "label": "'.tr('Fattura pro-forma').'", "name": "ref_fattura", "values": "query='.$query.'" ]}
|
||||||
</div>';
|
</div>';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
</div>';
|
</div>';
|
||||||
|
|
||||||
// Blocco DatiPagamento è valorizzato (opzionale)
|
|
||||||
$pagamenti = $fattura_pa->getBody()['DatiPagamento'];
|
|
||||||
if (!empty($pagamenti)) {
|
|
||||||
$metodi = $pagamenti['DettaglioPagamento'];
|
|
||||||
$metodi = isset($metodi[0]) ? $metodi : [$metodi];
|
|
||||||
|
|
||||||
$codice_modalita_pagamento = $metodi[0]['ModalitaPagamento'];
|
|
||||||
|
|
||||||
echo '
|
|
||||||
<h4>'.tr('Pagamento').'</h4>
|
|
||||||
|
|
||||||
<p>'.tr('La fattura importata presenta _NUM_ rat_E_ di pagamento con le seguenti scadenze', [
|
|
||||||
'_NUM_' => count($metodi),
|
|
||||||
'_E_' => ((count($metodi) > 1) ? 'e' : 'a'),
|
|
||||||
]).':</p>
|
|
||||||
<ol>';
|
|
||||||
|
|
||||||
// Scadenze di pagamento
|
|
||||||
foreach ($metodi as $metodo) {
|
|
||||||
echo '
|
|
||||||
<li>';
|
|
||||||
|
|
||||||
//DataScadenzaPagamento è un nodo opzionale per il blocco DatiPagamento
|
|
||||||
if (!empty($metodo['DataScadenzaPagamento'])) {
|
|
||||||
echo Translator::dateToLocale($metodo['DataScadenzaPagamento']).' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
$descrizione = !empty($metodo['ModalitaPagamento']) ? database()->fetchOne('SELECT descrizione FROM fe_modalita_pagamento WHERE codice = '.prepare($metodo['ModalitaPagamento']))['descrizione'] : '';
|
|
||||||
|
|
||||||
echo Translator::numberToLocale($metodo['ImportoPagamento']).' €
|
|
||||||
('.$descrizione.')
|
|
||||||
</li>';
|
|
||||||
}
|
|
||||||
|
|
||||||
echo '
|
|
||||||
</ol>';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!empty($codice_modalita_pagamento)) {
|
if (!empty($codice_modalita_pagamento)) {
|
||||||
$_SESSION['superselect']['codice_modalita_pagamento_fe'] = $codice_modalita_pagamento;
|
$_SESSION['superselect']['codice_modalita_pagamento_fe'] = $codice_modalita_pagamento;
|
||||||
}
|
}
|
||||||
@ -240,7 +228,6 @@ if (!empty($righe)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*###*/
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<tr>
|
<tr>
|
||||||
@ -325,4 +312,10 @@ echo '
|
|||||||
</form>';
|
</form>';
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
$("#save").hide();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
<script src="'.$rootdir.'/lib/init.js"></script>';
|
<script src="'.$rootdir.'/lib/init.js"></script>';
|
21
plugins/importFE/init.php
Normal file
21
plugins/importFE/init.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
include_once __DIR__.'/../../core.php';
|
||||||
|
|
||||||
|
use Plugins\ImportFE\FatturaElettronica;
|
||||||
|
use Plugins\ImportFE\Interaction;
|
||||||
|
|
||||||
|
if (isset($id_record)) {
|
||||||
|
$files = Interaction::fileToImport();
|
||||||
|
$file = $files[$id_record - 1];
|
||||||
|
|
||||||
|
$filename = $file['name'];
|
||||||
|
|
||||||
|
try {
|
||||||
|
$fattura_pa = FatturaElettronica::manage($filename);
|
||||||
|
$anagrafica = $fattura_pa->findAnagrafica();
|
||||||
|
|
||||||
|
$record = $file;
|
||||||
|
} catch (Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
@ -124,17 +124,17 @@ function download(button, file, data_registrazione) {
|
|||||||
data = JSON.parse(data);
|
data = JSON.parse(data);
|
||||||
|
|
||||||
if (!data.already) {
|
if (!data.already) {
|
||||||
launch_modal("'.tr('Righe fattura').'", globals.rootdir + "/actions.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&op=list&filename=" + data.filename +"&data_registrazione=" + data_registrazione);
|
redirect(globals.rootdir + "/editor.php?id_module=" + globals.id_module + "&id_plugin=" + '.$id_plugin.' + "&id_record=" + data.id);
|
||||||
buttonRestore(button, restore);
|
|
||||||
} else {
|
} else {
|
||||||
swal({
|
swal({
|
||||||
title: "'.tr('Fattura già importata.').'",
|
title: "'.tr('Fattura già importata.').'",
|
||||||
type: "info",
|
type: "info",
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonRestore(button, restore);
|
|
||||||
$(button).prop("disabled", true);
|
$(button).prop("disabled", true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buttonRestore(button, restore);
|
||||||
},
|
},
|
||||||
error: function(xhr) {
|
error: function(xhr) {
|
||||||
alert("'.tr('Errore').': " + xhr.responseJSON.error.message);
|
alert("'.tr('Errore').': " + xhr.responseJSON.error.message);
|
||||||
|
@ -187,14 +187,7 @@ class FatturaElettronica
|
|||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function findAnagrafica()
|
||||||
* Restituisce l'anagrafica collegata alla fattura, eventualmente generandola con i dati forniti.
|
|
||||||
*
|
|
||||||
* @param string $type
|
|
||||||
*
|
|
||||||
* @return Anagrafica
|
|
||||||
*/
|
|
||||||
public function saveAnagrafica($type = 'Fornitore')
|
|
||||||
{
|
{
|
||||||
$info = $this->getAnagrafe();
|
$info = $this->getAnagrafe();
|
||||||
|
|
||||||
@ -212,12 +205,26 @@ class FatturaElettronica
|
|||||||
$anagrafica->where('codice_fiscale', $info['codice_fiscale']);
|
$anagrafica->where('codice_fiscale', $info['codice_fiscale']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$anagrafica = $anagrafica->first();
|
return $anagrafica->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restituisce l'anagrafica collegata alla fattura, eventualmente generandola con i dati forniti.
|
||||||
|
*
|
||||||
|
* @param string $type
|
||||||
|
*
|
||||||
|
* @return Anagrafica
|
||||||
|
*/
|
||||||
|
public function saveAnagrafica($type = 'Fornitore')
|
||||||
|
{
|
||||||
|
$anagrafica = $this->findAnagrafica();
|
||||||
|
|
||||||
if (!empty($anagrafica)) {
|
if (!empty($anagrafica)) {
|
||||||
return $anagrafica;
|
return $anagrafica;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$info = $this->getAnagrafe();
|
||||||
|
|
||||||
$anagrafica = Anagrafica::build($info['ragione_sociale'], $info['nome'], $info['cognome'], [
|
$anagrafica = Anagrafica::build($info['ragione_sociale'], $info['nome'], $info['cognome'], [
|
||||||
TipoAnagrafica::where('descrizione', $type)->first()->id,
|
TipoAnagrafica::where('descrizione', $type)->first()->id,
|
||||||
]);
|
]);
|
||||||
|
@ -28,6 +28,18 @@ class Interaction extends Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ricerca fisica
|
||||||
|
$files = self::fileToImport($names);
|
||||||
|
|
||||||
|
$list = array_merge($list, $files);
|
||||||
|
|
||||||
|
return $list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fileToImport($names = [])
|
||||||
|
{
|
||||||
|
$list = [];
|
||||||
|
|
||||||
// Ricerca fisica
|
// Ricerca fisica
|
||||||
$directory = FatturaElettronica::getImportDirectory();
|
$directory = FatturaElettronica::getImportDirectory();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user