Patch level :

Files correlati     : fe0.exe fe0100a.msk
Ricompilazione Demo : [ ]
Commento            :
Ultima versione dichiarazione dati rilevanti


git-svn-id: svn://10.65.10.50/branches/R_10_00@22406 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
guy 2011-09-09 11:11:53 +00:00
parent d5967babb3
commit b98a473b3d
4 changed files with 642 additions and 245 deletions

View File

@ -17,6 +17,7 @@
#include <mov.h>
#include <nditte.h>
#include <occas.h>
#include <partite.h>
#include <pconti.h>
#include <rmoviva.h>
@ -26,6 +27,8 @@
// Data limite da cui si cominciano a dichiarare anche gli scontrini
const TDate data_limite_scontrini(1,7,2011);
const long INVALID_NUMREG = 9999999L;
///////////////////////////////////////////////////////////
// Utility
///////////////////////////////////////////////////////////
@ -271,7 +274,7 @@ bool TAnagrafica::init(const TRectype& rec)
{
const TRectype& anafis = cache().get(LF_ANAGFIS, rec.get_long(ANA_CODANAGR));
_data_nasc = anafis.get(ANF_DATANASC);
_com_nasc = rec.get(ANF_COMNASC);
_com_nasc = anafis.get(ANF_COMNASC);
}
else
_tipo = 'G';
@ -334,7 +337,7 @@ bool TAnagrafica::init(char tipo, long codice, const TString& ocfpi)
#define AN _alfafld
#define CF _alfafld
#define DT _datefld
#define NU _intfld
#define NU _longzerofld
#define PI _alfafld
#define OBBLIG true
@ -523,26 +526,36 @@ public:
bool set(unsigned int n, const TString& v) { return set_val(n, v); }
bool set(unsigned int n, char v) { TString4 str; str << v; return set_val(n, str); }
bool set(unsigned int n, int v) { return set_val(n, long(v)); }
bool set(unsigned int n, const real& v) { return set_val(n, v.integer()); }
bool set(unsigned int n, const real& v) { return set_val(n, v); }
bool set(unsigned int n, const TDate& v) { return set_val(n, v); }
void add_control_rec(int zero_o_nove);
void add_control_rec(int zero_o_nove, int num_inv = 1, int tot_inv = 1);
bool split(const TFilename& name, const TRecnotype maxalleg = 15000);
TDati_rilevanti_set(int anno);
};
bool TDati_rilevanti_set::set_field(const TAS400_column_info& fi, const TVariant& var)
{
// Salva le date in formato GGMMAAAA invece dello standard ANSI AAAAMMGG
if (fi._type == _datefld && fi._width == 8)
if (fi._type == DT && fi._width == 8)
{
const TDate d = var.as_date();
TString8 str; str.format("%02d%02d%04d", d.day(), d.month(), d.year());
row().overwrite(str, fi._pos);
return true;
} else
// Salva gli importi in formato 000001234 (non sappiamo ancora gestire i negativi)
if (fi._type == NU && fi._width == 9)
{
const char* str = var.as_real().string(9, 0, '0');
row().overwrite(str, fi._pos);
return true;
}
return TAS400_recordset::set_field(fi, var);
}
void TDati_rilevanti_set::add_control_rec(int zon)
void TDati_rilevanti_set::add_control_rec(int zon, int num_inv, int tot_inv)
{
CHECKD(zon == 0 || zon == 9, "Tipo record di testa o coda non valido ", zon);
@ -570,6 +583,61 @@ void TDati_rilevanti_set::add_control_rec(int zon)
set(16, ditta.provincia_nascita());
}
set(17, _anno);
if (tot_inv < 1) tot_inv = 1;
if (num_inv <= 0) num_inv = 1;
if (num_inv > tot_inv) num_inv = tot_inv;
set(19, num_inv);
set(20, tot_inv);
}
bool TDati_rilevanti_set::split(const TFilename& name, const TRecnotype maxalleg)
{
const TRecnotype totrec = items();
bool done = totrec <= maxalleg;
if (!done)
{
const TRecnotype rows_x_file = maxalleg-2;
const int totf = int((totrec-2.0) / rows_x_file + 0.99);
TString msg;
msg.format(FR("Spezzatura del file %s in blocchi da %d righe"), (const char*)name, maxalleg);
TProgind pi(totrec, msg);
move_first();
for (int f = 1; f <= totf; f++)
{
TDati_rilevanti_set outset(_anno);
outset.add_control_rec(0, f, totf);
for (TRecnotype sent = 0; sent < rows_x_file && move_next(); sent++)
{
const TRecnotype r = current_row();
if (!pi.setstatus(r))
{
f = totf; // Procedura interrotta dall'utente
break;
}
const TString& rec = row(r);
if (rec[0] == '0') continue; // Ignora un eventuale record iniziale "spurio"
if (rec[0] == '9') break; // Termina quando incontra il record finale
outset.new_rec(rec);
}
outset.add_control_rec(9, f, totf);
// Costruisce il nome del file di invio parziale, es: datiril_1_3.txt
TFilename outname = name;
const TString8 saved_ext = outname.ext();
outname.ext(""); outname << '_' << f << '_' << totf;
outname.ext(saved_ext);
done = outset.save_as(outname);
if (!done)
{
cantwrite_box(outname);
break;
}
}
}
return done;
}
TDati_rilevanti_set::TDati_rilevanti_set(int anno)
@ -587,11 +655,18 @@ TDati_rilevanti_set::TDati_rilevanti_set(int anno)
#define MANUAL_ROW 900000L
enum TExclusion_mode { em_incluso, em_importo_limite, em_nullo, em_no_allegato,
em_fiscalita_agevolata, em_estero, em_intra,
em_data_limite, em_art8, em_passaggi_interni,
em_altro };
class TDati_rilevanti_msk : public TAutomask
{
TMaskmode _mode;
bool _sheet_dirty, _send_all;
TAssoc_array _contratti;
TExclusion_mode _why;
TLog_report* _log;
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
@ -608,41 +683,63 @@ protected:
bool send_nc(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
bool send_fatt(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
bool send_rec(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz);
TExclusion_mode segnala_movimento(const TRectype& mov, TExclusion_mode motivo);
bool is_nota_variazione(const TRectype& mov) const;
real importo_limite(int anno) const;
bool imponibile_imposta(long numreg, real& imponibile, real& imposta) const;
void elabora_note(const TArray& note, TFast_isamfile& falleg, long& nprog);
public:
TRecnotype genera_alleg();
bool elabora_alleg();
bool send_alleg();
bool azzera_alleg(bool manual, TRecnotype first) const;
bool elabora_movimento(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr, TLog_report& log);
TExclusion_mode elabora_movimento(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr);
bool salva_allegato(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr,
const real& corrispettivo, const real& imposta, int natope, int tipope,
TLog_report& log);
bool convalida_clifo(const TRectype& mov, TLog_report& log) const;
bool convalida_mov(const TRectype& mov, TLog_report& log) const;
bool ignora_movimento(const TRectype& mov, const char* motivo, TLog_report& log) const;
const real& corrispettivo, const real& imposta, int natope, int tipope);
TExclusion_mode validate_clifo(const TRectype& mov);
TExclusion_mode validate_mov(const TRectype& mov);
TDati_rilevanti_msk() : TAutomask("fe0100a"), _mode(MODE_QUERY) { set_dirty(false); }
TDati_rilevanti_msk() : TAutomask("fe0100a"), _mode(MODE_QUERY), _log(NULL) { load_profile(); set_dirty(false); }
~TDati_rilevanti_msk() { save_profile(); }
};
bool TDati_rilevanti_msk::ignora_movimento(const TRectype& mov, const char* motivo, TLog_report& log) const
TExclusion_mode TDati_rilevanti_msk::segnala_movimento(const TRectype& mov, TExclusion_mode motivo)
{
if (_why == em_incluso)
{
const long numreg = mov.get_long(MOV_NUMREG);
TString msg; msg.format(FR("%7ld Scartato: %s"), numreg, motivo);
log.log(1, msg);
return false;
const char* tipocf = mov.get_char(MOV_TIPO) == 'F' ? TR("Fornitore") : TR("Cliente");
const long codcf = mov.get_long(MOV_CODCF);
TString msg; msg.format(FR("%s %6ld - Registrazione %7ld scartata: "), tipocf, codcf, numreg);
switch (motivo)
{
case em_nullo : msg << TR("Soggetto con codice nullo"); break;
case em_importo_limite : msg << TR("importo inferiore al limite della comunicazione"); break;
case em_no_allegato : msg << TR("Soggetto da non inserire in allegato"); break;
case em_fiscalita_agevolata: msg << TR("Soggetto residente in stato a fiscalità agevolata"); break;
case em_estero : msg << TR("Soggetto residente all'estero"); break;
case em_intra : msg << TR("Movimento intra"); break;
case em_data_limite : msg << TR("Data movimento fuori dal limite della comunicazione"); break;
case em_art8 : msg << TR("soggetto all'articolo 8 (del dpr 26-10-1972)"); break;
case em_passaggi_interni : msg << TR("passaggi interni"); break;
default : msg << TR("Altri motivi"); break;
}
_why = motivo;
if (motivo > em_importo_limite)
_log->log(1, msg);
}
return motivo;
}
bool TDati_rilevanti_msk::convalida_clifo(const TRectype& mov, TLog_report& log) const
TExclusion_mode TDati_rilevanti_msk::validate_clifo(const TRectype& mov)
{
const char tipocf = mov.get_char(MOV_TIPO);
const long codcf = mov.get_long(MOV_CODCF);
const TString16 ocfpi = mov.get(MOV_OCFPI);
if (tipocf <= ' ' || (codcf <= 0 && ocfpi.blank()))
return false;
return segnala_movimento(mov, em_nullo);
if (!_send_all)
{
TString4 stato;
if (ocfpi.full())
{
@ -655,68 +752,79 @@ bool TDati_rilevanti_msk::convalida_clifo(const TRectype& mov, TLog_report& log)
const TRectype& rec_clifo = cache().get(LF_CLIFO, key);
stato = rec_clifo.get(CLI_STATOCF);
// tutti i fornitori esteri vanno esclusi (importazioni)
const int alleg = rec_clifo.get_int(CLI_ALLEG);
if (alleg == 1)
return segnala_movimento(mov, em_no_allegato);
if (tipocf == 'F' && alleg == 5)
return ignora_movimento(mov, TR("Importazione da fornitore estero"), log);
}
return segnala_movimento(mov, em_estero);
if (stato.full())
{
const TRectype& rec_sta = cache().get("%STA", stato);
if (rec_sta.get_bool("B0"))
return ignora_movimento(mov, TR("Soggetto residente in stato a fiscalità agevolata"), log);
return segnala_movimento(mov, em_fiscalita_agevolata);
if (tipocf == 'F')
return ignora_movimento(mov, TR("Importazione da fornitore estero"), log);
return segnala_movimento(mov, em_estero);
}
}
return true; //se arriva qui il clifo è da considerare
return em_incluso; //se arriva qui il clifo è da considerare
}
bool TDati_rilevanti_msk::convalida_mov(const TRectype& mov, TLog_report& log) const
TExclusion_mode TDati_rilevanti_msk::validate_mov(const TRectype& mov)
{
// Ignora eventuale vecchio movimento IVA (ANNOIVA < 2010)
const int anno = mov.get_int(MOV_ANNOIVA);
if (anno < 2010)
return false;
segnala_movimento(mov, em_data_limite);
if (!_send_all)
{
// Ignora i movimenti già comunicati tramite modello INTRA
if (!mov.get_real(MOV_CORRLIRE).is_zero() ||
!mov.get_real(MOV_CORRVALUTA).is_zero())
return ignora_movimento(mov, "INTRA", log);
segnala_movimento(mov, em_intra);
if (anno <= 2011)
{
const TDate datareg = mov.get_date(MOV_DATAREG);
const TString& tipodoc = mov.get(MOV_TIPODOC);
if (tipodoc == "SC" && datareg < data_limite_scontrini)
{
// Ignoro ma segnalo scontrini rilevanti prima della data limite
if (anno == 2011 && mov.get_long(MOV_TOTDOC) >= 3600)
{
TString msg; msg << TR("Scontrino antecedente il ") << data_limite_scontrini;
return ignora_movimento(mov, msg, log);
segnala_movimento(mov, em_data_limite);
}
// Ignoro silenziosamente gli altri
return validate_clifo(mov);
}
bool TDati_rilevanti_msk::is_nota_variazione(const TRectype& mov) const
{
const real totdoc = mov.get_real(MOV_TOTDOC);
if (totdoc < ZERO)
return true;
const int tipomov = mov.get_int(MOV_TIPOMOV);
if (tipomov == 2)
return true;
const TString& tipodoc = mov.get(MOV_TIPODOC);
if (tipodoc == "NC" || tipodoc == "ND")
return true;
return false;
}
}
}
return convalida_clifo(mov, log);
}
bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr,
const real& importo, const real& imposta, int natope, int tipope,
TLog_report& log)
const real& importo, const real& imposta, int natope, int tipope)
{
bool update_contract = false;
bool update_existing_row = false;
const int anno = mov.get_int(MOV_ANNOIVA);
const long numreg_mov = mov.get_long(MOV_NUMREG);
if (numreg_mov == 42297)
int cazzone = 1;
long num_fatt = 0; // Numero di registrazione rettificabile
long num_rett = 0; // Numero di registrazione rettificata
falleg.zero();
TRectype& alleg = falleg.curr();
@ -724,7 +832,7 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
alleg.put(ALL_PROGR, progr);
const TString80 contratto = mov.get(MOV_CONTRATTO);
if (contratto.full())
if (contratto.full()) // Gestione contratti
{
TString80 key;
key.format("%c%06ld_%s_%d%d", mov.get_char(MOV_TIPO), mov.get_long(MOV_CODCF),
@ -746,15 +854,112 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
{
TString msg;
msg << TR("Impossibile aggiornare record da contratto: ") << key;
log.log_error(msg);
_log->log(2, msg);
return false;
}
update_contract = true;
update_existing_row = true;
}
}
else
{
// Gestione note di credito
if (importo < ZERO || is_nota_variazione(mov))
{
TLocalisamfile partite(LF_PARTITE);
TRectype& part = partite.curr();
partite.setkey(2);
part.put(PART_NREG, numreg_mov);
part.put(PART_NUMRIG, 1);
if (partite.read() == NOERR) // Ho trovato la partita ora cerco la fattura di riferimento
{
int nriga = part.get_int(PART_NRIGA);
part.zero(PART_NRIGA); // Uso il record come chiave per leggere l'intera partita
TRecord_array partita(part, PART_NRIGA);
for (nriga = partita.pred_row(nriga); nriga >= 1; nriga = partita.pred_row(nriga))
{
const TRectype& riga = partita.row(nriga);
const int tipomov = riga.get_int(PART_TIPOMOV);
const long nreg_part = riga.get_long(PART_NREG);
if (tipomov == 1 && nreg_part > 0)
{
num_fatt = nreg_part;
TString query;
query << "USE ALLEG KEY 3\n"
<< "FROM NUMREG=" << num_fatt << '\n'
<< "TO NUMREG=" << num_fatt;
TISAM_recordset recset(query);
bool found = false;
if (recset.items() > 1)
{
for (bool ok = recset.move_first(); ok; ok = recset.move_next())
{
const int no = recset.get(ALL_NATOPE).as_int();
const int to = recset.get(ALL_TIPOPE).as_int();
if (no == natope && to == tipope)
{
found = true;
break;
}
}
}
if (!found)
found = recset.move_first();
if (found)
{
const TDate data_fatt = riga.get(PART_DATAREG);
const int anno_fatt = data_fatt.year();
num_rett = num_fatt; // Memorizzo comunque il numero fattura da rettificare
if (num_rett == 42297)
int cazzone = 2;
if (anno_fatt == anno) // Se sono dello stesso anno vario la fattura e non registro la nota di variazione
{
update_existing_row = true;
alleg = recset.cursor()->curr();
} else
if (anno_fatt < 2010)
{
num_rett = 0;
_why = em_data_limite; // Non pertinente
}
break;
}
}
}
}
const char* tipocf = part.get_char(PART_TIPOCF) == 'F' ? TR("Fornitore") : TR("Cliente");
const long codcf = part.get_long(PART_SOTTOCONTO);
TString msg; msg.format(FR("%s %6ld - Nota di variazione %7ld "), tipocf, codcf, numreg_mov);
if (num_rett > 0)
{
if (update_existing_row)
msg << TR("sommata");
else
msg << TR("associata");
msg << TR(" alla registrazione ") << num_rett;
_log->log(update_existing_row ? 0 : 1, msg);
}
else
{
if (num_fatt <= 0)
{
num_rett = INVALID_NUMREG;
msg << TR("NON associata a nessuna fattura!");
_log->log(1, msg);
}
else
{
num_rett = num_fatt;
}
}
}
}
// I dati della registrazione IVA vanno aggiornati comunque
alleg.put(ALL_NUMREG, mov.get(MOV_NUMREG));
alleg.put(ALL_DATAREG, mov.get(MOV_DATAREG));
int modpag = mov.get_int(MOV_MODPAG);
@ -763,11 +968,22 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
alleg.put(ALL_MODPAG, modpag);
int err = 0;
if (update_contract)
if (update_existing_row) // Contratti o note di variazione
{
// Mi limito ad incrementare gli importi
alleg.add(ALL_IMPORTO, importo);
alleg.add(ALL_IMPOSTA, imposta);
// Aggiorno il flag di inclusione se necessario
const TExclusion_mode em_old = (TExclusion_mode)alleg.get_int(ALL_IGNORA);
if (em_old == em_incluso || em_old == em_importo_limite)
{
const real imp_new = alleg.get(ALL_IMPORTO);
const TExclusion_mode em_new = imp_new >= importo_limite(anno) ? em_incluso : em_importo_limite;
if (em_new != em_old)
alleg.put(ALL_IGNORA, int(em_new));
}
err = falleg.rewrite();
}
else
@ -778,6 +994,7 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
alleg.put(ALL_TIPOCF, tipocf);
alleg.put(ALL_CODCF, codcf);
alleg.put(ALL_OCFPI, mov.get(MOV_OCFPI));
alleg.put(ALL_NUMREG, numreg_mov);
alleg.put(ALL_NATOPE, natope);
alleg.put(ALL_TIPOPE, tipope);
alleg.put(ALL_IMPORTO, importo);
@ -792,8 +1009,16 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
cont.totale_annuale(anno, importotot, impostatot);
alleg.put(ALL_IMPORTOTOT, importotot);
alleg.put(ALL_IMPOSTATOT, impostatot);
} else
if (num_rett > 0)
{
alleg.put(ALL_NUMRETT, num_rett);
if (num_rett >= INVALID_NUMREG && _why == em_incluso)
_why = em_altro;
}
alleg.put(ALL_IGNORA, int(_why));
err = falleg.rewrite_write();
if (err == NOERR)
progr++;
@ -803,7 +1028,7 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
{
TString msg;
msg.format(FR("Errore %d di aggiornamento del file %s"), err, (const char*)falleg.name());
log.log_error(msg);
_log->log(2, msg);
}
return err == NOERR;
@ -813,10 +1038,12 @@ bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& fa
struct TCorrimp : public TObject
{ real _corrispettivo, _imposta; };
bool TDati_rilevanti_msk::elabora_movimento(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr, TLog_report& log)
real TDati_rilevanti_msk::importo_limite(int anno) const
{ return anno <= 2010 ? 25000 : 3000; }
TExclusion_mode TDati_rilevanti_msk::elabora_movimento(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr)
{
if (!convalida_mov(mov, log))
return false;
validate_mov(mov);
const char tipocf = mov.get_char(MOV_TIPO);
const TString4 tipodoc = mov.get(MOV_TIPODOC);
@ -844,36 +1071,23 @@ bool TDati_rilevanti_msk::elabora_movimento(const TRectype& mov, TFast_isamfile&
if (natura_operazione == 1 && tipodoc == "SC")
natura_operazione = 4;
if (!_send_all)
{
// Controllo per bene gli scontrini che fossero sfuggiti ai controlli precedenti
if (natura_operazione == 4 && datareg < data_limite_scontrini)
continue;
// Esportazioni
const bool art_8 = ci.get("S2") == "20" && ci.get("S3") == "1";
if (art_8)
{
ignora_movimento(mov, TR("soggetto all'articolo 8 (del dpr 26-10-1972)"), log);
continue;
}
segnala_movimento(mov, em_art8);
const TString4 cod_det = rmi.get(RMI_TIPODET);
const int tip_det = cod_det == "3" ? 3 : atoi(cache().get("%DET", cod_det, "I0"));
if (tip_det == 3)
{
ignora_movimento(mov, TR("passaggi interni"), log);
continue;
}
}
segnala_movimento(mov, em_passaggi_interni);
real rmi_imponibile = rmi.get_real(RMI_IMPONIBILE);
real rmi_imposta = rmi.get_real(RMI_IMPOSTA);
if (natura_operazione == 4 && rmi_imposta.is_zero()) // se l'imposta non è specificata ...
if (natura_operazione == 4 && rmi_imposta.is_zero()) // se l'imposta non è specificata sullo scontrino ...
rmi_imposta = ci.scorpora(rmi_imponibile); // ... scorporo il lordo
// Determina se la riga sia di servizi o merce.
bool srv = ci.get_bool("B8"); // Flag apposito sul codice IVA
bool srv = ci.get_bool("B5"); // Flag apposito sul codice IVA
if (!srv)
{
const TBill bill(rmi);
@ -897,34 +1111,22 @@ bool TDati_rilevanti_msk::elabora_movimento(const TRectype& mov, TFast_isamfile&
tot_imposta += rmi_imposta;
}
bool elabora = true;
if (!_send_all)
{
if (mov.get(MOV_CONTRATTO).full())
{
// Considera comunque i contratti per ora, alla fine sistemera' situazioni non rilevanti
elabora = true;
}
else
if (mov.get(MOV_CONTRATTO).blank() && tot_imponibile > ZERO)
{
// Considera solo registrazioni con importo rilevante
const real limite = anno == 2010 ? 25000 : 3000;
elabora = tot_imponibile >= limite;
}
if (tot_imponibile < importo_limite(anno))
segnala_movimento(mov, em_importo_limite);
}
if (elabora)
{
FOR_EACH_ASSOC_OBJECT(importi, obj, key, itm)
{
const TCorrimp& corrimp = *(const TCorrimp*)itm;
salva_allegato(mov, falleg, progr,
corrimp._corrispettivo, corrimp._imposta,
key[0]-'0', key[1]-'0', log);
}
key[0]-'0', key[1]-'0');
}
return elabora;
return _why;
}
bool TDati_rilevanti_msk::azzera_alleg(bool manual, TRecnotype first) const
@ -1010,38 +1212,67 @@ TRecnotype TDati_rilevanti_msk::nuovo_progr() const
return progr+1;
}
void TDati_rilevanti_msk::elabora_note(const TArray& note, TFast_isamfile& falleg, long& nprog)
{
FOR_EACH_ARRAY_ITEM(note, i, obj)
{
const TRectype& not_var = *(const TRectype*)obj;
_why = em_incluso;
elabora_movimento(not_var, falleg, nprog);
}
}
TRecnotype TDati_rilevanti_msk::genera_alleg()
{
const int anno = get_int(F_ANNO);
_contratti.destroy(); // Azzera cache contratti
TString str_pi;
str_pi << TR("Movimenti ") << anno;
TLog_report log(str_pi);
_log = new TLog_report(str_pi);
TRecnotype nprog = 1;
if (anno >= 2010) // Dummy test for bracing TFast_isamfiles
{
TFast_isamfile falleg(LF_ALLEG);
TFast_isamfile fmov(LF_MOV);
TString query;
query << "USE MOV KEY 2 SELECT CODCF!=''"
<< "\nFROM DATAREG=01-01-" << anno
<< "\nTO DATAREG=31-12-" << anno;
query << "USE MOV KEY 3 SELECT BETWEEN(DATAREG," << anno << "0101," << anno << "1231)"
<< "\nFROM TIPO=C\nTO TIPO=F";
TISAM_recordset mov(query);
const TRectype& mov_rec = mov.cursor()->curr();
const TRecnotype items = mov.items();
long last_clifo = 0;
TArray note;
TProgind pi(items, str_pi);
TRecnotype nprog = 1;
_contratti.destroy();
for (bool ok = mov.move_first(); ok; ok = mov.move_next())
{
if (!pi.addstatus(1))
break;
elabora_movimento(mov_rec, falleg, nprog, log);
const long curr_clifo = mov_rec.get_long(MOV_CODCF);
if (curr_clifo != last_clifo)
{
elabora_note(note, falleg, nprog);
last_clifo = curr_clifo;
note.destroy();
}
_why = em_incluso;
if (is_nota_variazione(mov_rec))
note.add(mov_rec); // Posticipa l'elaborazione delle note di varizione
else
elabora_movimento(mov_rec, falleg, nprog); // Elabora immediatamente i documenti normali
}
elabora_note(note, falleg, nprog); // Elabora le eventuali note dell'ultimo fornitore
}
log.preview();
_log->preview();
delete _log;
_log = NULL;
return nprog;
}
@ -1051,16 +1282,99 @@ bool TDati_rilevanti_msk::elabora_alleg()
if (!check_fields()) // Controlla che l'anno sia valido
return false;
_send_all = get_bool(F_SENDALL);
const TRecnotype prog = genera_alleg();
azzera_alleg(false, prog);
return prog > 1;
}
// Calcola il totale degli imponibili e delle imposte di un movimento IVA
bool TDati_rilevanti_msk::imponibile_imposta(long numreg, real& imponibile, real& imposta) const
{
TString8 key; key << numreg;
TRecord_array righe_iva(key, LF_RMOVIVA);
imponibile = imposta = ZERO;
for (int r = righe_iva.rows(); r > 0; r--)
{
const TRectype& ri = righe_iva.row(r);
imponibile += ri.get_real(RMI_IMPONIBILE);
imposta += ri.get_real(RMI_IMPOSTA);
}
return !imponibile.is_zero();
}
bool TDati_rilevanti_msk::send_nc(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz)
{
return false; // TBI
const long num_rett = alleg.get(ALL_NUMRETT).as_int();
if (num_rett <= 0 || num_rett >= INVALID_NUMREG)
return false;
TRectype rec_fatt(LF_MOV);
TRectype rec_nota(LF_MOV);
TLocalisamfile mov(LF_MOV);
mov.put(MOV_NUMREG, num_rett);
if (mov.read() == NOERR)
rec_fatt = mov.curr();
else
return false;
const long numreg = alleg.get(ALL_NUMREG).as_int();
mov.put(MOV_NUMREG, numreg);
if (mov.read() == NOERR)
rec_nota = mov.curr();
const TAnagrafica anag(alleg.cursor()->curr());
const real importo = alleg.get(ALL_IMPORTO).as_real();
const real imposta = alleg.get(ALL_IMPOSTA).as_real();
const TString& paiv = anag.partita_IVA();
real imp_fatt, iva_fatt;
imponibile_imposta(num_rett, imp_fatt, iva_fatt);
if (anag.stato_estero() > 0)
{
operaz.new_rec("5"); // Note di variazione a soggetti non residenti
if (anag.fisica())
{
operaz.set(2, anag.cognome());
operaz.set(3, anag.nome());
operaz.set(4, anag.data_nascita());
operaz.set(5, anag.comune_nascita());
operaz.set(6, anag.provincia_nascita());
operaz.set(7, anag.stato_estero());
}
else
{
operaz.set(8, anag.ragione_sociale());
operaz.set(9, anag.comune_residenza());
operaz.set(10, anag.stato_estero());
operaz.set(11, EMPTY_STRING); // TBI? Indirizzo estero
}
operaz.set(12, alleg.get(ALL_DATAREG));
operaz.set(13, rec_nota.get(MOV_NUMDOC).left(10));
operaz.set(14, importo);
operaz.set(15, imposta);
operaz.set(16, rec_fatt.get_date(MOV_DATAREG));
operaz.set(17, rec_fatt.get(MOV_NUMDOC).left(10));
operaz.set(18, imp_fatt);
operaz.set(19, iva_fatt);
}
else
{
operaz.new_rec("4"); // Note di variazione a soggetti residenti - titolari di partita IVA
operaz.set(2, paiv);
operaz.set(3, alleg.get(ALL_DATAREG));
operaz.set(4, rec_nota.get(MOV_NUMDOC).left(10));
operaz.set(5, alleg.get(ALL_IMPORTO));
operaz.set(6, alleg.get(ALL_IMPOSTA));
operaz.set(7, rec_fatt.get_date(MOV_DATAREG));
operaz.set(8, rec_fatt.get(MOV_NUMDOC).left(10));
operaz.set(9, imp_fatt);
operaz.set(10,iva_fatt);
}
return true;
}
bool TDati_rilevanti_msk::send_fatt(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz)
@ -1086,7 +1400,7 @@ bool TDati_rilevanti_msk::send_fatt(const TISAM_recordset& alleg, TDati_rilevant
else
{
// Se l'importo della fattura o l'importo del contratto superano la soglia ...
const real limit = anno == 2010 ? 25000 : 3000;
const real limit = importo_limite(anno);
send = importo >= limit || importo_tot >= limit;
}
if (!send)
@ -1153,10 +1467,6 @@ bool TDati_rilevanti_msk::send_fatt(const TISAM_recordset& alleg, TDati_rilevant
bool TDati_rilevanti_msk::send_rec(const TISAM_recordset& alleg, TDati_rilevanti_set& operaz)
{
const bool ignora = alleg.get(ALL_IGNORA).as_bool();
if (ignora)
return false;
const long numrett = alleg.get(ALL_NUMRETT).as_int();
return numrett > 0 ? send_nc(alleg, operaz) : send_fatt(alleg, operaz);
}
@ -1165,24 +1475,34 @@ bool TDati_rilevanti_msk::send_rec(const TISAM_recordset& alleg, TDati_rilevanti
bool TDati_rilevanti_msk::send_alleg()
{
const int anno = get_int(F_ANNO);
_send_all = get_bool(F_SENDALL);
_send_all = get_int(F_SENDALL) != 1; // Devo inviare anche dati NON rilevanti?
TFilename temp; temp.tempdir();
TFilename temp = get(F_OUTFOLDER);
if (temp.blank())
temp.tempdir();
temp.add("datiril.txt");
TDati_rilevanti_set recset(anno);
recset.add_control_rec(0);
TString query;
query << "USE " << LF_ALLEG << " SELECT " << ALL_IGNORA << "==\"\""
<< "\nFROM " << ALL_ANNO << '=' << anno
query << "USE " << LF_ALLEG;
if (!_send_all)
query << " SELECT STR(" << ALL_IGNORA << "==0)";
query << "\nFROM " << ALL_ANNO << '=' << anno
<< "\nTO " << ALL_ANNO << '=' << anno;
TISAM_recordset alleg(query);
for (bool ok = alleg.move_first(); ok; ok = alleg.move_next())
send_rec(alleg, recset);
recset.add_control_rec(9);
return recset.save_as(temp);
bool done = recset.save_as(temp);
const long maxalleg = get_long(F_MAXREC);
if (recset.items() > maxalleg)
done = recset.split(temp, maxalleg);
return done;
}
void TDati_rilevanti_msk::set_dirty(bool d)
@ -1193,25 +1513,43 @@ void TDati_rilevanti_msk::set_dirty(bool d)
void TDati_rilevanti_msk::load_sheet()
{
const int anno = get_int(F_ANNO);
TString16 limit; limit << ALL_ANNO << '=' << anno;
const char tipocf = get(F_TIPOCF)[0];
const long codcf = get_long(F_CODCF);
const TString& ocfpi = get(F_OCFPI);
const int show_all = get_int(F_SHOWALL);
TSheet_field& s = sfield(F_RIGHE);
s.hide(); // Nascondo lo sheet per guadagnare un 20% di velocità di caricamento
s.destroy();
TString query;
query << "USE " << LF_ALLEG;
if (codcf > 0 || (show_all > 0 && show_all < 7))
{
query << " SELECT ";
if (codcf > 0)
{
query << " SELECT (" << ALL_TIPOCF << "='" << tipocf << "')&&(" << ALL_CODCF << "='" << codcf << "')";
query << "(" << ALL_TIPOCF << "='" << tipocf << "')&&(" << ALL_CODCF << "='" << codcf << "')";
if (ocfpi.full())
query << "&&(" << ALL_OCFPI << "='" << ocfpi << "')";
}
if (show_all > 0 && show_all < 7)
{
if (codcf > 0) query << "&&";
query << "(STR(" << ALL_IGNORA;
switch (show_all)
{
case 1: query << '<'; break; // Importi superiori al limite (20000 o 3000)
case 2: query << '='; break; // Importi inferiori al limite (20000 o 3000)
default: query << '>'; break; // Importi scartati (esteri o leggi speciali)
}
query << "1))";
}
}
const int anno = get_int(F_ANNO);
TString16 limit; limit << ALL_ANNO << '=' << anno;
query << "\nFROM " << limit << "\nTO " << limit;
TISAM_recordset alleg(query);
const TRecnotype items = alleg.items();
if (items > 0)
@ -1223,13 +1561,12 @@ void TDati_rilevanti_msk::load_sheet()
for (bool ok = alleg.move_first(); ok; ok = alleg.move_next())
{
if (!pi.addstatus(1)) break;
s.autoload_line(rec+1, curr);
s.check_row(rec);
rec++;
s.autoload_line(++rec, curr);
}
}
s.force_update();
s.show();
set_dirty(false);
if (s.items() > 0)
@ -1342,9 +1679,9 @@ bool TDati_rilevanti_msk::on_field_event(TOperable_field& o, TField_event e, lon
}
break;
case DLG_CANCEL:
if (e == fe_button && _mode != MODE_QUERY && jolly == 0)
if (e == fe_button && jolly == 0)
{
if (save_if_dirty())
if (_mode != MODE_QUERY && save_if_dirty())
{
TSheet_field& s = sfield(F_RIGHE);
s.destroy();
@ -1370,7 +1707,20 @@ bool TDati_rilevanti_msk::on_field_event(TOperable_field& o, TField_event e, lon
if (e == fe_button && check_fields())
send_alleg();
break;
case F_OUTFOLDER:
if (e == fe_init && o.empty())
{
TFilename tmp; tmp.tempdir();
o.set(tmp);
}
break;
case F_MAXREC:
if (e == fe_init && o.empty())
o.set(15000L);
break;
case F_RIGHE:
if (e == fe_init)
load_sheet(); else
if (e == se_notify_modify)
set_dirty( true); else
if (e == se_query_add)
@ -1425,6 +1775,18 @@ bool TDati_rilevanti_msk::on_field_event(TOperable_field& o, TField_event e, lon
m.set(A_IMPOSTATOT, imposta);
}
break;
case DLG_USER:
if (e == fe_button)
{
const long numreg = o.mask().get_long(A_NUMREG);
if (numreg > 0)
{
TRectype mov(LF_MOV);
mov.put(MOV_NUMREG, numreg);
mov.edit();
}
}
break;
default:
break;
}
@ -1446,11 +1808,14 @@ public:
bool TDati_rilevanti_app::create()
{
// Teoricamente è possibile visulizzare tutti i movimenti di un anno, per cui allargo il numero riga
TSheet_field::set_line_number_width(6);
// Controllo preventivo dell'avvenuta conversione del tracciato record
const TRectype alleg(LF_ALLEG);
if (!alleg.exist(ALL_IMPORTO))
if (alleg.type(ALL_IGNORA) != _intfld)
return error_box(TR("Il database non è stato ancora convertito per il modulo FE"));
return TSkeleton_application::create();
}
@ -1470,6 +1835,3 @@ int fe0100(int argc, char* argv[])
app.run(argc, argv, TR("Gestione dati rilevanti"));
return 0;
}

View File

@ -1,9 +1,9 @@
#define F_DITTA 301
#define F_RAGSOCD 302
#define F_ANNO 303
#define F_DESCATT 305
#define F_SENDALL 306
#define F_ANNO 301
#define F_DESCATT 302
#define F_SHOWALL 303
#define F_SENDALL 304
#define F_OUTFOLDER 305
#define F_MAXREC 306
#define F_TIPOCF 310
#define F_CODCF 311

View File

@ -4,7 +4,8 @@ TOOLBAR "topbar" 0 0 0 2
BUTTON DLG_OK 2 2
BEGIN
PROMPT 1 1 "Selezione"
PROMPT 1 1 "Aggiorna"
PICTURE TOOL_CONVERT
END
BUTTON DLG_SAVEREC 2 2
@ -28,14 +29,15 @@ END
BUTTON DLG_ELABORA 2 2
BEGIN
PROMPT 1 4 "Genera"
PICTURE TOOL_ELABORA
PROMPT 1 4 "Invia"
PICTURE TOOL_EXPORT
END
BUTTON DLG_EXPORT 2 2
BEGIN
PROMPT 1 5 "Excel"
PICTURE TOOL_EXCEL
MODULE rs
END
#include <helpbar.h>
@ -44,30 +46,14 @@ ENDPAGE
PAGE "Dati rilevanti" 0 2 0 0
GROUPBOX DLG_NULL 78 6
GROUPBOX DLG_NULL 78 5
BEGIN
PROMPT 1 0 "@bDitta"
END
NUMBER F_DITTA 5
BEGIN
PROMPT 2 1 "Ditta "
FLAGS "DF"
END
STRING F_RAGSOCD 50
BEGIN
PROMPT 15 1 ""
USE LF_NDITTE
INPUT CODDITTA F_DITTA
OUTPUT F_RAGSOCD RAGSOC
CHECKTYPE REQUIRED
FLAGS "D"
PROMPT 1 0 "@bFiltri di visualizzazione"
END
NUMBER F_ANNO 4
BEGIN
PROMPT 2 2 "Anno "
PROMPT 2 1 "Anno "
CHECKTYPE REQUIRED
FLAGS "AU"
GROUP 1
@ -75,19 +61,19 @@ BEGIN
WARNING "Anno non valido"
END
BOOLEAN F_SENDALL
LIST F_SHOWALL 1 25
BEGIN
PROMPT 15 2 "Invia anche operazioni escluse dall'obbligo di comunicazione"
END
GROUPBOX DLG_NULL 78 4
BEGIN
PROMPT 1 6 "@bFiltro su selezione"
PROMPT 33 1 "Mostra movimenti "
ITEM "1|Rilevanti"
ITEM "2|NON rilevanti"
ITEM "4|Scartati"
ITEM "7|Tutti"
GROUP 1
END
LIST F_TIPOCF 1 10
BEGIN
PROMPT 2 7 ""
PROMPT 2 2 ""
ITEM "C|Cliente"
ITEM "F|Fornitore"
GROUP 1
@ -95,8 +81,8 @@ END
NUMBER F_CODCF 6
BEGIN
PROMPT 16 7 ""
USE CLIFO
PROMPT 16 2 ""
USE LF_CLIFO
INPUT TIPOCF F_TIPOCF SELECT
INPUT CODCF F_CODCF
DISPLAY "Codice" CODCF
@ -109,10 +95,10 @@ BEGIN
GROUP 1
END
STRING F_RAGSOC 50
STRING F_RAGSOC 50 49
BEGIN
PROMPT 26 7 ""
USE CLIFO KEY 2
PROMPT 26 2 ""
USE LF_CLIFO KEY 2
INPUT TIPOCF F_TIPOCF SELECT
INPUT RAGSOC F_RAGSOC
DISPLAY "Ragione Sociale@50" RAGSOC
@ -123,29 +109,30 @@ END
STRING F_OCFPI 16
BEGIN
PROMPT 2 8 "Occ."
USE OCCAS
PROMPT 2 3 "Occ."
USE LF_OCCAS
INPUT CFPI F_OCFPI
DISPLAY "Codice@16" CFPI
DISPLAY "Ragione Sociale@50" RAGSOC
OUTPUT F_OCFPI CFPI
OUTPUT F_RAGOCC RAGSOC
CHEKTYPE NORMAL
ADD RUN cg0 -6
GROUP 1
MESSAGE EMPTY SHOW,F_RAGSOC|HIDE,F_RAGOCC
MESSAGE HIDE,F_RAGSOC|SHOW,F_RAGOCC
END
STRING F_RAGOCC 50
STRING F_RAGOCC 50 49
BEGIN
PROMPT 26 8 ""
PROMPT 26 3 ""
FLAGS "H"
GROUP 1
END
SPREADSHEET F_RIGHE
BEGIN
PROMPT 0 10 ""
PROMPT 0 5 ""
ITEM "Riga@6F"
ITEM "Non\nInv.@2@F"
ITEM "C/F@2F"
@ -165,6 +152,40 @@ BEGIN
ITEM "N. Reg.\nrettif.@7"
ITEM "Partita IVA@15"
ITEM "Codice Fiscale@17"
DEFAULT "*" // Impedisce il salvataggio su profilo .ini
END
ENDPAGE
PAGE "Opzioni" 0 2 0 0
GROUPBOX DLG_NULL 78 5
BEGIN
PROMPT 1 1 "@bFiltri per invio"
END
LIST F_SENDALL 1 25
BEGIN
PROMPT 2 2 "Movimenti "
ITEM "1|Rilevanti"
ITEM "7|Tutti"
END
STRING F_OUTFOLDER 255 50
BEGIN
PROMPT 2 3 "Cartella "
DSELECT
CHECKTYPE REQUIRED
WARNING "Specificare una cartella di destinazione valida"
END
NUMBER F_MAXREC 5
BEGIN
PROMPT 2 4 "Numero massimo di record per file "
NUM_EXPR (#THIS_FIELD>=100)&&(#THIS_FIELD<=15000)
FLAGS "U"
CHECKTYPE REQUIRED
WARNING "Specificare una valore compreso tra 100 e 15000"
END
ENDPAGE
@ -175,14 +196,25 @@ PAGE "Riga" -1 -1 69 13
NUMBER A_RIGA 7
BEGIN
PROMPT 1 1 "Numero progressivo "
PROMPT 1 0 "Numero progressivo "
FLAGS "D"
FIELD PROGR
END
BOOLEAN A_IGNORA
LIST A_IGNORA 2 55
BEGIN
PROMPT 31 1 "Esclusa da invio"
PROMPT 1 1 "Non inv."
ITEM "| 0. Rilevante al fine della dichiarazione"
ITEM "1| 1. Importo inferiore al limite della comunicazione"
ITEM "2| 2. Soggetto con codice nullo"
ITEM "3| 3. Soggetto da non inserire in allegato"
ITEM "4| 4. Soggetto residente in stato a fiscalità agevolata"
ITEM "5| 5. Soggetto residente all'estero"
ITEM "6| 6. Movimento intra"
ITEM "7| 7. Data movimento fuori dai limiti della comunicazione"
ITEM "8| 8. Soggetto all'articolo 8 (del dpr 26-10-1972)"
ITEM "9| 9. Passaggi interni"
ITEM "10|10. Altri motivi"
FIELD IGNORA
END
@ -197,7 +229,7 @@ END
NUMBER A_CODCF 6
BEGIN
PROMPT 17 2 ""
USE CLIFO
USE LF_CLIFO
INPUT TIPOCF A_TIPOCF SELECT
INPUT CODCF A_CODCF
DISPLAY "Codice" CODCF
@ -207,13 +239,14 @@ BEGIN
DISPLAY "Codice fiscale@16" COFI
OUTPUT A_CODCF CODCF
CHEKTYPE REQUIRED
ADD RUN cg0 -1
FIELD CODCF
END
STRING A_OCFPI 16
BEGIN
PROMPT 34 2 "Occasionale "
USE OCCAS
USE LF_OCCAS
INPUT CFPI A_OCFPI
DISPLAY "Codice@16" CFPI
DISPLAY "Ragione Sociale@50" RAGSOC
@ -222,6 +255,7 @@ BEGIN
OUTPUT A_OCFPI CFPI
CHEKTYPE NORMAL
GROUP 3
ADD RUN cg0 -6
FIELD OCFPI
END
@ -254,7 +288,7 @@ NUMBER A_NUMREG 7
BEGIN
PROMPT 41 5 "N. operazione "
FIELD NUMREG
USE MOV SELECT (TIPO==#A_TIPOCF)&&(BETWEEN(CODCF,#A_CODCF,#A_CODCF))
USE LF_MOV SELECT (TIPO==#A_TIPOCF)&&(BETWEEN(CODCF,#A_CODCF,#A_CODCF))
JOIN LF_CLIFO INTO TIPOCF==TIPO CODCF==CODCF
INPUT NUMREG A_NUMREG
DISPLAY "Numero@7" NUMREG
@ -265,6 +299,8 @@ BEGIN
OUTPUT A_NUMREG NUMREG
CHECKTYPE NORMAL
ADD RUN cg2 -0
MESSAGE EMPTY DISABLE,DLG_USER
MESSAGE ENABLE,DLG_USER
END
LIST A_MODPAG 1 20
@ -346,9 +382,9 @@ BEGIN
INPUT NUMREG A_NUMRETT
COPY DISPLAY A_NUMREG
OUTPUT A_NUMRETT NUMREG
CHECKTYPE NORMAL
CHECKTYPE SEARCH
ADD RUN cg2 -0
NUM_EXPR (#A_NUMRETT=0)||(#A_NUMRETT!=#A_NUMREG)
NUM_EXPR (#A_NUMRETT=0)||(#A_NUMRETT=9999999)||(#A_NUMRETT!=#A_NUMREG)
WARNING "Inserire un numero registrazione diverso da quello principale"
END
@ -361,14 +397,20 @@ BEGIN
PROMPT 1 1 ""
END
BUTTON DLG_USER 2 2
BEGIN
PROMPT 2 1 "Collega"
PICTURE TOOL_LINK
END
BUTTON DLG_DELREC 2 2
BEGIN
PROMPT 2 1 ""
PROMPT 3 1 ""
END
BUTTON DLG_CANCEL 2 2
BEGIN
PROMPT 3 1 ""
PROMPT 4 1 ""
END
ENDPAGE

View File

@ -135,13 +135,6 @@ TMask* TFE_table_app::user_create_mask()
else
m = TTable_module_application::user_create_mask();
if (m != NULL)
{
TString str; m->get_caption(str);
if (str.full())
main_app().set_title(str);
}
return m;
}