Files correlati : tf Commento : - Tolto controllo fornitore bolla doganale - Sistemati filtri maschera spesometro - Invertito ordine "Sogg. Fatt. Elettr" e Esteri in fornitori (era diverso rispetto ai clienti) - Refactor dei nomi generale
233 lines
8.0 KiB
C++
233 lines
8.0 KiB
C++
#include <recarray.h> // cache()
|
||
|
||
#include "../ve/velib05.h"
|
||
#include "../cg/cglib03.h"
|
||
#include "../fe/felib.h"
|
||
#include "tfutility.h"
|
||
#include "../fp/fplib.h"
|
||
#include "tf0100b.h"
|
||
|
||
|
||
// Ritorna il record da trasfatt
|
||
TRectype getTrasFatt(TString reg, TString codiva)
|
||
{
|
||
TString key = reg; key << "|" << codiva;
|
||
return cache().get(LF_TRASFATT, key);
|
||
}
|
||
|
||
// Ritorna il cliente
|
||
TRectype getCli(const TString& tipocf, const TString& codcf, const TString& ocfpi)
|
||
{
|
||
TString key = tipocf; key << "|" << codcf;
|
||
const TRectype& cli = cache().get(LF_CLIFO, key);
|
||
if(cli.get_bool("OCCAS"))
|
||
{
|
||
TRectype clifo(LF_CLIFO);
|
||
TRectype occas = cache().get(LF_OCCAS, ocfpi);
|
||
clifo.put("RAGSOC" , occas.get("RAGSOC"));
|
||
clifo.put("CODRFSO" , "");
|
||
clifo.put("PAIV" , occas.get("PAIV"));
|
||
clifo.put("COFI" , occas.get("COFI"));
|
||
return clifo;
|
||
}
|
||
else
|
||
return cli;
|
||
}
|
||
|
||
// Controlla se l'azienda ha un RFSO
|
||
bool have_rfso(TString& codrfso)
|
||
{
|
||
codrfso = cache().get(LF_NDITTE, prefix().firm().codice(), "CODRFSO");
|
||
return codrfso.full();
|
||
}
|
||
|
||
const char * natura(const TString& codiva)
|
||
{
|
||
const TRectype& ai = cache().get("%IVA", codiva);
|
||
TString & natura = get_tmp_string(4);
|
||
|
||
natura = ai.get("S12");
|
||
return natura;
|
||
}
|
||
|
||
TString find_detraib(const TString& tipodet)
|
||
{
|
||
real perc = static_cast<const char*>(cache().get("%DET", tipodet, "R0"));
|
||
return perc.stringa(6,2);
|
||
}
|
||
|
||
real get_iva(const TString& codiva)
|
||
{
|
||
const TRectype& ai = cache().get("%IVA", codiva);
|
||
return ai.get_real("R0");
|
||
}
|
||
|
||
TString rev_charge(const TString& numreg, const int year)
|
||
{
|
||
// Controllo se la causale ha il reverse charge, se il cliente non l'ha impostata giusta sono ARAZZI suoi
|
||
const TString& key = numreg;
|
||
TCausale caus(cache().get(LF_MOV, key, "CODCAUS"), year);
|
||
if(caus.reverse_charge())
|
||
bool tolla = true;
|
||
return caus.reverse_charge() ? "X" : "";
|
||
}
|
||
|
||
TString get_rfso(TString codrfso)
|
||
{
|
||
TString key; key << codrfso[0] << "|" << codrfso.mid(1);
|
||
return cache().get(LF_ANAG, key, "RAGSOC");
|
||
}
|
||
|
||
/* Utilizzo questa funzione per filtrare al meglio i record, tutti i casi che devo omettere verranno rilevati e ritorneranno false
|
||
* Nota bene: viene sfruttato un puntatore di TISAM_Recordset per non creare nuovi oggetti e velocizzare la chiamata
|
||
* a questo punto il programma non ha ancora creato un record di $trasfatt con i dati che mi interessano
|
||
*
|
||
* ********************************************************************************************************************************
|
||
* Aggiornamento 06/03/2019: Aggiunta modalit<69> esterometro! Che succede se abilito questa magia?
|
||
*
|
||
* Movimenti Attivi:
|
||
* Il ragionamento parte con questo presupposto: filtro in automatico che esclude tutti i soggetti che normalmente dovrebbero ricevere la fattura.
|
||
* Overrides:
|
||
* paf_sent: Anzich<63> filtrare codesti soggetti vado a vedere direttamente sui PAFFI per capire cosa ho inviato
|
||
* paf_not_sent: Stessa roba ma mostro solo i non inviati
|
||
* paf_sog_fat: Questo flag si considera solo se i primi due non sono abilitati, aggiunge allo sheet anche i soggetti a fattura (quindi <20> come se disabilitasse il filtro)
|
||
* paf_esteri: Questo flag si considera solo se i primi due non sono abilitati, aggiunge i clienti esteri
|
||
* I booleani paf_sent && paf_not_sent sono complementari cos<6F> come paf_sog_fat && paf_esteri
|
||
* MA NOTA BENE CHE senza mod_esterometro nessun booleano viene preso in considerazione!
|
||
*
|
||
* Movimenti Passivi:
|
||
* Stessa roba sopra ma con paa_*
|
||
*/
|
||
bool check_record(TISAM_recordset* rec, const bool mod_esterometro,
|
||
const bool paf_not_sent, const bool paf_sent, const bool paf_sog_fat, const bool paf_esteri,
|
||
const bool paa_not_sent, const bool paa_sent, const bool paa_sog_fat, const bool paa_esteri)
|
||
{
|
||
// Il record non <20> valido se non <20> presente un cliente
|
||
if(rec->get("23.TIPO").as_string()[0] == '\0' || rec->get("23.CODCF").as_int() == 0)
|
||
return false;
|
||
|
||
TAnagrafica ana_cli(rec->get("23.TIPO").as_string()[0], rec->get("23.CODCF").as_int(), rec->get("23.OCFPI").as_string());
|
||
|
||
static TString key_clifo; key_clifo.cut(0) << rec->get("23.TIPO").as_string() << "|" << rec->get("23.CODCF").as_string();
|
||
TRectype rclifo = cache().get(LF_CLIFO, key_clifo);
|
||
// Salto le schede carburanti
|
||
if(rclifo.get_char("ALLEG") == 'C')
|
||
return false;
|
||
|
||
// Clienti
|
||
if(rec->get("23.TIPO").as_string() == "C")
|
||
{
|
||
// Tolgo tutti i movimenti di sola IVA e in reverse charge o di tipo 3 (Acquisto di beni e servizi di soggetti non residenti)
|
||
TCausale caus(rec->get("23.CODCAUS").as_string(), rec->get("23.DATAREG").as_date().year());
|
||
if(caus.soloiva() && (caus.reverse_charge() || caus.regime_speciale() == 3))
|
||
return false;
|
||
|
||
|
||
if (mod_esterometro)
|
||
{
|
||
// Parte Sirio FP w/ WebApp
|
||
// Faccio controlli per evitare controlli
|
||
if(paf_not_sent && paf_sent)
|
||
{
|
||
return true;
|
||
}
|
||
else if (paf_not_sent || paf_sent)
|
||
{
|
||
// controllo se la fattura non <20> gi<67> stata spedita con la fatt. elettronica
|
||
static TPaf_record paf0100f("PAF0100F");
|
||
// controllo se il movimento <20> agganciato a un documento
|
||
if (rec->get("23.DPROVV").is_full() && rec->get("23.DANNO").is_full() && rec->get("23.DCODNUM").is_full() && rec->get("23.DNDOC").is_full())
|
||
{
|
||
TString hfatt, bfatt;
|
||
TRectype rdoc(LF_DOC);
|
||
static TLocalisamfile doc(LF_DOC);
|
||
rdoc.put(DOC_PROVV, rec->get("23.DPROVV").as_string());
|
||
rdoc.put(DOC_ANNO, rec->get("23.DANNO").as_string());
|
||
rdoc.put(DOC_CODNUM, rec->get("23.DCODNUM").as_string());
|
||
rdoc.put(DOC_NDOC, rec->get("23.DNDOC").as_string());
|
||
|
||
// Se riesco a generare la chiave, trovo il record e non ha il flag di gestione in errore o un errore esterno, so che <20> stato inviato
|
||
const bool is_sent = rdoc.read(doc) == NOERR && chiave_paf(rdoc, hfatt, bfatt) && paf0100f.search(nullptr, hfatt, bfatt) && paf0100f.sq_get("P1_GESTIONE") != "E" && paf0100f.sq_get("P1_ERREST") != "*";
|
||
|
||
// Se voglio solo quelli inviati e non <20> stato inviato o
|
||
// voglio solo quelli non inviati ed <20> stato inviato, RUSPA!
|
||
if ((is_sent && paf_sent) || (!is_sent && paf_not_sent))
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
static bool warn_user = true;
|
||
if(warn_user)
|
||
{
|
||
TString msg;
|
||
msg << "Attenzione: il movimento " << rec->get("23.NUMREG") << " non deriva da nessuna fattura.\nSi desidera includerlo nella ricerca?";
|
||
switch (yesnoall_box(msg))
|
||
{
|
||
case K_YES:
|
||
return true;
|
||
break;
|
||
case K_SPACE:
|
||
warn_user = false;
|
||
case K_NO:
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
// Se non dovrebbe capitare
|
||
return false;
|
||
}
|
||
}
|
||
// Parte tirchi che non comprano la mia WebApp
|
||
// Solito controllo per evitare controlli
|
||
else if(paf_sog_fat && paf_esteri)
|
||
{
|
||
return true;
|
||
}
|
||
else if(paf_sog_fat || paf_esteri)
|
||
{
|
||
const bool is_fatturabile = ana_cli.stato_partita_IVA() == "IT" || ana_cli.stato_partita_IVA() == "SM";
|
||
if ((is_fatturabile && paf_sog_fat) || (!is_fatturabile && paf_esteri))
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
} else
|
||
{
|
||
// Salto tutti i fornitori con cod cf che inizia per 8 o 9 e con p.iva non valida
|
||
if (ana_cli.italiano() && ana_cli.partita_IVA()[0] != '0' && ana_cli.partita_IVA()[0] != '1' && ana_cli.codice_fiscale()[0] > '8')
|
||
return false;
|
||
|
||
if (mod_esterometro)
|
||
{
|
||
// Parte Sirio FP w/ WebApp
|
||
// Faccio controlli per evitare controlli
|
||
if (paa_not_sent && paa_sent)
|
||
{
|
||
return true;
|
||
}
|
||
else if (paa_not_sent || paa_sent)
|
||
{
|
||
// Disabilitato, non si vuole implementare al momento
|
||
return false;
|
||
}
|
||
// Parte tirchi che non comprano la mia WebApp
|
||
// Solito controllo per evitare controlli
|
||
else if (paa_sog_fat && paa_esteri)
|
||
{
|
||
return true;
|
||
}
|
||
else if (paa_sog_fat || paa_esteri)
|
||
{
|
||
const bool is_fatturabile = ana_cli.stato_partita_IVA() == "IT" || ana_cli.stato_partita_IVA() == "SM";
|
||
if ((is_fatturabile && paa_sog_fat) || (!is_fatturabile && paa_esteri))
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
}
|
||
|
||
return true;
|
||
} |