git-svn-id: svn://10.65.10.50/branches/R_10_00@22342 c028cbd2-c16b-5b4b-a496-9718f37d4682
1254 lines
38 KiB
C++
Executable File
1254 lines
38 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <defmask.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include <textset.h>
|
|
#include <relation.h>
|
|
#include <reputils.h>
|
|
#include <validate.h>
|
|
|
|
#include <alleg.h>
|
|
#include <anafis.h>
|
|
#include <anagr.h>
|
|
#include <attiv.h>
|
|
#include <clifo.h>
|
|
#include <comuni.h>
|
|
#include <mov.h>
|
|
#include <nditte.h>
|
|
#include <occas.h>
|
|
#include <pconti.h>
|
|
#include <rmoviva.h>
|
|
|
|
#include "fe0100a.h"
|
|
#include "../cg/cglib01.h"
|
|
|
|
// Data limite da cui si cominciano a dichiarare anche gli scontrini
|
|
const TDate data_limite_scontrini(1,7,2011);
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Utilities
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Classe per estrarre il codice attività di un movimento di prima nota
|
|
class TAttivita_cache : public TAssoc_array
|
|
{
|
|
public:
|
|
const TString& mov2att(const TRectype& mov);
|
|
const TString& att2ateco(const TString& att) const;
|
|
} _att_cache;
|
|
|
|
const TString& TAttivita_cache::mov2att(const TRectype& mov)
|
|
{
|
|
const TString& reg = mov.get(MOV_REG);
|
|
if (reg.blank())
|
|
return EMPTY_STRING;
|
|
|
|
TString8 key;
|
|
key << mov.get(MOV_ANNOIVA) << reg;
|
|
|
|
TString* codatt = (TString*)objptr(key);
|
|
if (codatt == NULL)
|
|
{
|
|
codatt = new TString8(cache().get("REG", key, "S8"));
|
|
add(key, codatt);
|
|
}
|
|
|
|
return *codatt;
|
|
}
|
|
|
|
const TString& TAttivita_cache::att2ateco(const TString& att) const
|
|
{
|
|
TToken_string key;
|
|
key.add(prefix().get_codditta());
|
|
key.add(att);
|
|
const TRectype& attiv = cache().get(LF_ATTIV, key);
|
|
if (!attiv.empty() && attiv.exist(ATT_CODATECO)) // Non e' detto che il campo esista sempre
|
|
return attiv.get(ATT_CODATECO);
|
|
return att;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Utility
|
|
///////////////////////////////////////////////////////////
|
|
|
|
static bool comune_di(const TString& codcom, TString& den, TString& prov)
|
|
{
|
|
if (codcom.blank() || codcom.len() != 4)
|
|
return false;
|
|
|
|
TString8 key; key << " |" << codcom;
|
|
const TRectype& rec = cache().get(LF_COMUNI, key);
|
|
if (rec.empty())
|
|
{
|
|
den = prov = "";
|
|
}
|
|
else
|
|
{
|
|
den = rec.get(COM_DENCOM); den.cut(40);
|
|
den.upper();
|
|
prov = rec.get(COM_PROVCOM);
|
|
prov.upper();
|
|
if (codcom[0] == 'Z' && prov.blank())
|
|
prov = "EE";
|
|
}
|
|
return den.not_empty();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TAnagrafica
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TAnagrafica : public TObject
|
|
{
|
|
char _tipo; // F o G
|
|
TString16 _cofi, _paiv;
|
|
TString80 _key, _ragsoc;
|
|
TString80 _com_nasc, _com_res;
|
|
TString4 _prov_nasc, _prov_res;
|
|
TDate _data_nasc;
|
|
|
|
TAnagrafica(const TAnagrafica&) { CHECK(false, "Can't copy TAnagrafica"); }
|
|
|
|
public:
|
|
virtual bool ok() const { return _tipo=='F' || _tipo == 'G'; }
|
|
bool fisica() const { return _tipo == 'F'; }
|
|
bool giuridica() const { return _tipo == 'G'; }
|
|
const TString& key() const { return _key; }
|
|
|
|
const TString& codice_fiscale() const { return _cofi; }
|
|
const TString& partita_IVA() const { return _paiv; }
|
|
|
|
const TString& ragione_sociale() const { return _ragsoc; }
|
|
const TString& cognome() const { return _ragsoc.left(24); }
|
|
const TString& nome() const { return _ragsoc.mid(30,20); }
|
|
char sesso() const { return (_cofi[9] >= '4') ? 'F' : 'M'; }
|
|
const TDate& data_nascita() const { return _data_nasc; }
|
|
|
|
const TString& comune_nascita() const { return _com_nasc; }
|
|
const TString& provincia_nascita() const { return _prov_nasc; }
|
|
const TString& comune_residenza() const { return _com_res; }
|
|
const TString& provincia_residenza() const { return _prov_res; }
|
|
|
|
bool init(const TRectype& rec);
|
|
bool init(int num, const char* codice) { return init(cache().get(num, codice)); }
|
|
bool init(int num, long codice) { return init(cache().get(num, codice)); }
|
|
bool init(int num, char tipo, long codice);
|
|
|
|
TAnagrafica() : _tipo('\0') {}
|
|
TAnagrafica(int num, long codice) { init(num, codice); }
|
|
TAnagrafica(int num, char tipo, long codice) { init(num, tipo, codice); }
|
|
TAnagrafica(const TRectype& rec) { init(rec); }
|
|
};
|
|
|
|
bool TAnagrafica::init(const TRectype& rec)
|
|
{
|
|
_tipo = '\0';
|
|
_key.cut(0);
|
|
if (rec.empty())
|
|
return false;
|
|
|
|
_key << rec.num() << '|' << rec.build_key(1);
|
|
|
|
switch (rec.num())
|
|
{
|
|
case LF_OCCAS:
|
|
_tipo = 'F';
|
|
_cofi = rec.get(OCC_COFI);
|
|
_paiv = rec.get(OCC_PAIV);
|
|
if (_cofi.blank() || _paiv.blank())
|
|
{
|
|
const TString& codice = rec.get(OCC_CFPI);
|
|
if (_cofi.blank() && cf_check("", codice))
|
|
_cofi = codice;
|
|
if (_paiv.blank() && pi_check("", codice))
|
|
_paiv = codice;
|
|
}
|
|
_ragsoc = rec.get(OCC_RAGSOC); _ragsoc.upper();
|
|
_data_nasc = rec.get(OCC_DNASC);
|
|
comune_di(rec.get(OCC_COMNASC), _com_nasc, _prov_nasc);
|
|
comune_di(rec.get(OCC_COM), _com_res, _prov_res);
|
|
break;
|
|
case LF_ANAG:
|
|
_tipo = rec.get_char(ANA_TIPOA);
|
|
_ragsoc = rec.get(ANA_RAGSOC); _ragsoc.upper();
|
|
_cofi = rec.get(ANA_COFI);
|
|
_paiv = rec.get(ANA_PAIV);
|
|
|
|
// Comune di residenza fiscale o domicilio
|
|
if (!comune_di(rec.get(ANA_COMRF), _com_res, _prov_res))
|
|
comune_di(rec.get(ANA_COMRES), _com_res, _prov_res);
|
|
|
|
// Dati di nascita persone fisiche
|
|
if (_tipo == 'F')
|
|
{
|
|
const TRectype& anafis = cache().get(LF_ANAGFIS, rec.get_long(ANA_CODANAGR));
|
|
_data_nasc = anafis.get(ANF_DATANASC);
|
|
comune_di(rec.get(ANF_COMNASC), _com_nasc, _prov_nasc);
|
|
}
|
|
break;
|
|
case LF_NDITTE:
|
|
{
|
|
const bool good = init(LF_ANAG, rec.get_char(NDT_TIPOA), rec.get_long(NDT_CODANAGR));
|
|
_ragsoc = rec.get(NDT_RAGSOC); _ragsoc.upper();
|
|
return good;
|
|
}
|
|
break;
|
|
case LF_CLIFO:
|
|
_tipo = rec.get_char(CLI_TIPOAPER);
|
|
if (_tipo == 'F')
|
|
init(LF_ANAG, _tipo, rec.get_long(CLI_CODANAGPER));
|
|
// Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
|
|
if (rec.get(CLI_COFI).not_empty())
|
|
_cofi = rec.get(CLI_COFI);
|
|
if (rec.get(CLI_PAIV).not_empty())
|
|
_paiv = rec.get(CLI_PAIV);
|
|
_ragsoc = rec.get(CLI_RAGSOC); _ragsoc.upper(); // Prevale sempre la ragione sociale del cliente
|
|
break;
|
|
case LF_MOV:
|
|
{
|
|
const TString& ocfpi = rec.get(MOV_OCFPI);
|
|
return ocfpi.full() ? init(LF_OCCAS, ocfpi) : init(LF_CLIFO, rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF));
|
|
}
|
|
break;
|
|
default:
|
|
CHECKD(false, "Record non valido per TAnagrafica ", rec.num());
|
|
break;
|
|
}
|
|
|
|
return _tipo == 'F' || _tipo == 'G';
|
|
}
|
|
|
|
bool TAnagrafica::init(int num, char tipo, long codice)
|
|
{
|
|
TString16 key; key << tipo << '|' << codice;
|
|
return init(cache().get(num, key));
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TDati_rilevanti_trc
|
|
///////////////////////////////////////////////////////////
|
|
|
|
#define AN _alfafld
|
|
#define CF _alfafld
|
|
#define DT _datefld
|
|
#define NU _intfld
|
|
#define PI _alfafld
|
|
#define OBBLIG true
|
|
|
|
class TDati_rilevanti_trc : public TObject
|
|
{
|
|
int _tipo;
|
|
TAS400_recordset* _recset;
|
|
|
|
protected:
|
|
bool add_field(int n, int da, int a, int len, const char* descr, TFieldtypes tipo = AN,
|
|
const char* def = NULL, bool required = false);
|
|
public:
|
|
void create_fields(int tipo, TAS400_recordset& recset);
|
|
};
|
|
|
|
bool TDati_rilevanti_trc::add_field(int n, int da, int a, int len, const char* descr, TFieldtypes tipo,
|
|
const char* def, bool required)
|
|
{
|
|
CHECKD(descr && *descr, "Campo ignoto ", n);
|
|
CHECKS(n > 0 && da > 0 && a >= da && a <= 1800 && len == (a-da+1), "Campo inconsistente ", descr);
|
|
TString8 name;
|
|
name.format("%d.%d", _tipo, n);
|
|
bool ok = _recset->create_field(name, da-1, len, tipo, required, def);
|
|
CHECKS(ok, "Can't create field ", descr);
|
|
return ok;
|
|
}
|
|
|
|
void TDati_rilevanti_trc::create_fields(int tipo, TAS400_recordset& recset)
|
|
{
|
|
CHECKD(tipo >= 0 && tipo <= 5 || tipo == 9, "Tipo record non valido ", tipo);
|
|
_tipo = tipo;
|
|
_recset = &recset;
|
|
|
|
TString4 def; def << _tipo;
|
|
add_field(1, 1, 1, 1, "Tipo record", NU, def, OBBLIG);
|
|
|
|
if (_tipo == 0 || _tipo == 9)
|
|
{
|
|
add_field( 2, 2, 6, 5, "Codice identificativo fornitura", AN, "ART21", OBBLIG);
|
|
add_field( 3, 7, 8, 2, "Codice numerico fornitura", NU, "47", OBBLIG);
|
|
add_field( 4, 9, 9, 1, "Tipologia di invio", NU, "0", OBBLIG);
|
|
add_field( 5, 10, 26,17, "Protocollo da sostituire", NU);
|
|
add_field( 6, 27, 42,16, "Codice fiscale", CF, "", OBBLIG);
|
|
add_field( 7, 43, 53,11, "Partita IVA", PI);
|
|
|
|
add_field( 8, 54,113,60, "Denominazione", AN);
|
|
add_field( 9,114,153,40, "Comune domicilio fiscale", AN);
|
|
add_field(10,154,155, 2, "Provincia domicilio fiscale", AN);
|
|
|
|
add_field(11,156,179,24, "Cognome", AN);
|
|
add_field(12,180,199,20, "Nome", AN);
|
|
add_field(13,200,200, 1, "Sesso", AN);
|
|
add_field(14,201,208, 8, "Data di nascita", DT);
|
|
add_field(15,209,248,40, "Comune o stato di nascita", AN);
|
|
add_field(16,249,250, 2, "Provincia di nascita", AN);
|
|
|
|
add_field(17,251,254, 4, "Anno di riferimento", NU);
|
|
add_field(18,255,255, 1, "Comunicazione società incorp.", AN, "0", OBBLIG);
|
|
add_field(19,256,259, 4, "Progressivo invio telmatico", NU, "1");
|
|
add_field(20,260,263, 4, "Numero totale invii telematici", NU, "1");
|
|
|
|
add_field(21,264,279,16, "Codice fiscale intermediario", CF);
|
|
add_field(22,280,284, 5, "Numero iscrizione C.A.F.", NU);
|
|
add_field(23,285,285, 1, "Impegno alla trasmissione", NU, "1");
|
|
add_field(24,286,293, 8, "Data dell'impegno", DT);
|
|
|
|
add_field(25,294,1797,1504, "Filler", AN);
|
|
add_field(26,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
|
add_field(27,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
|
|
} else
|
|
if (_tipo == 1)
|
|
{
|
|
add_field( 2, 2,17,16, "Codice fiscale", CF, "", OBBLIG);
|
|
add_field( 3,18,25, 8, "Data dell'operazione", DT);
|
|
add_field( 4,26,26, 1, "Modalità di pagamento", NU, "3", OBBLIG);
|
|
add_field( 5,27,35, 9, "Importo dovuto", NU);
|
|
add_field( 6,36,36, 1, "Natura operazione", NU, "1", OBBLIG);
|
|
add_field( 7,37,37, 1, "Tipologia dell'operazione", NU, "1", OBBLIG);
|
|
add_field( 8,38,46, 9, "Importo totale operazione", NU);
|
|
|
|
add_field( 9,47,1797,1751, "Filler", AN);
|
|
add_field(10,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
|
add_field(11,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
|
|
} else
|
|
if (_tipo == 2)
|
|
{
|
|
add_field( 2, 2,12,11, "Partita IVA", PI, "", OBBLIG);
|
|
add_field( 3,13,20, 8, "Data dell'operazione", DT);
|
|
add_field( 4,21,21, 1, "Modalità di pagamento", NU, "3", OBBLIG);
|
|
add_field( 5,22,30, 9, "Importo dovuto", NU);
|
|
add_field( 6,31,39, 9, "Imposta", NU);
|
|
add_field( 6,40,40, 1, "Natura operazione", NU, "1", OBBLIG);
|
|
add_field( 7,41,41, 1, "Tipologia dell'operazione", NU, "1", OBBLIG);
|
|
add_field( 8,42,50, 9, "Importo totale operazione", NU);
|
|
add_field( 9,51,59, 9, "Imposta totale operazione", NU);
|
|
|
|
add_field(10,60,1797,1738, "Filler", AN);
|
|
add_field(11,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
|
add_field(12,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
|
|
} else
|
|
if (_tipo == 3)
|
|
{
|
|
add_field( 2, 2, 25,24, "Cognome", AN);
|
|
add_field( 3, 26, 45,20, "Nome", AN);
|
|
add_field( 4, 46, 53, 8, "Data di nascita", DT);
|
|
add_field( 5, 54, 93,40, "Comune o stato estero di nascita", AN);
|
|
add_field( 6, 94, 95, 2, "Provincia di nascita", AN);
|
|
add_field( 7, 96, 98, 3, "Stato estero del domicilio", AN);
|
|
add_field( 8, 99,158,60, "Ragione sociale", AN);
|
|
add_field( 9,159,198,40, "Città estera della sede legale", AN);
|
|
add_field(10,199,201, 3, "Stato estero della sede legale", AN);
|
|
add_field(11,202,241,40, "Indirizzo estero della sede legale", AN);
|
|
add_field(12,242,249, 8, "Data dell'operazione", DT);
|
|
add_field(13,250,250, 1, "Modalità di pagamento", NU, "3", OBBLIG);
|
|
add_field(14,251,259, 9, "Importo dovuto", NU);
|
|
add_field(15,260,268, 9, "Imposta", NU);
|
|
add_field(16,269,269, 1, "Natura operazione", NU, "1", OBBLIG);
|
|
add_field(17,270,270, 1, "Tipologia dell'operazione", NU, "1", OBBLIG);
|
|
add_field(18,271,279, 9, "Importo totale operazione", NU);
|
|
add_field(19,280,288, 9, "Imposta totale operazione", NU);
|
|
|
|
add_field(20,289,1797,1509, "Filler", AN);
|
|
add_field(21,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
|
add_field(22,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
|
|
} else
|
|
if (_tipo == 4)
|
|
{
|
|
add_field( 2, 2,12,11, "Partita IVA", PI);
|
|
add_field( 3,13,20, 8, "Data dell'operazione", DT, "", OBBLIG);
|
|
add_field( 4,21,30,10, "Numero della Nota di Variazione", AN, "", OBBLIG);
|
|
add_field( 5,31,39, 9, "Imponibile Nota di Variazione", NU);
|
|
add_field( 6,40,48, 9, "Imposta Nota di Variazione", NU);
|
|
add_field( 7,49,56, 8, "Data della Fattura da rettificare", DT, "", OBBLIG);
|
|
add_field( 8,57,66,10, "Numero della Fattura da rettificare", AN, "", OBBLIG);
|
|
add_field( 9,67,75, 9, "Imponibile Fattura da rettificare", NU);
|
|
add_field(10,76,84, 9, "Imposta Fattura da rettificare", NU);
|
|
|
|
add_field(11,85,1797,1713, "Filler", AN);
|
|
add_field(12,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
|
add_field(13,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
|
|
} else
|
|
if (_tipo == 5)
|
|
{
|
|
add_field( 2, 2, 25,24, "Cognome", AN);
|
|
add_field( 3, 26, 45,20, "Nome", AN);
|
|
add_field( 4, 46, 53, 8, "Data di nascita", DT);
|
|
add_field( 5, 54, 93,40, "Comune o stato estero di nascita", AN);
|
|
add_field( 6, 94, 95, 2, "Provincia di nascita", AN);
|
|
add_field( 7, 96, 98, 3, "Stato estero del domicilio", AN);
|
|
add_field( 8, 99,158,60, "Ragione sociale", AN);
|
|
add_field( 9,159,198,40, "Città estera della sede legale", AN);
|
|
add_field(10,199,201, 3, "Stato estero della sede legale", AN);
|
|
add_field(11,202,241,40, "Indirizzo estero della sede legale", AN);
|
|
add_field(12,242,249, 8, "Data dell'operazione", DT, "", OBBLIG);
|
|
add_field(13,250,259,10, "Numero della Nota di Variazione", AN, "", OBBLIG);
|
|
add_field(14,260,268, 9, "Imponibile Nota di Variazione", NU);
|
|
add_field(15,269,277, 9, "Imposta Nota di Variazione", NU);
|
|
add_field(16,278,285, 8, "Data della Fattura da rettificare", DT, "", OBBLIG);
|
|
add_field(17,286,295,10, "Numero della Fattura da rettificare",AN, "", OBBLIG);
|
|
add_field(18,296,304, 9, "Imponibile Fattura da rettificare", NU);
|
|
add_field(19,305,313, 9, "Imposta Fattura da rettificare", NU);
|
|
|
|
add_field(20,314,1797,1484, "Filler", AN);
|
|
add_field(21,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG);
|
|
add_field(22,1799,1800,2,"Caratteri di fine riga", AN, "\r\n");
|
|
}
|
|
|
|
_recset = NULL;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TDati_rilevanti_set
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TDati_rilevanti_set : public TAS400_recordset
|
|
{
|
|
int _anno;
|
|
TString8 _codatt;
|
|
|
|
protected:
|
|
virtual bool set_field(const TAS400_column_info& fi, const TVariant& var);
|
|
void init();
|
|
|
|
public:
|
|
void set(unsigned int n, const TString& v) { TAS400_recordset::set(n-1, TVariant(v)); }
|
|
void set(unsigned int n, char v) { TString4 str; str << v; TAS400_recordset::set(n-1, TVariant(str)); }
|
|
void set(unsigned int n, int v) { TAS400_recordset::set(n-1, TVariant(long(v))); }
|
|
void set(unsigned int n, const real& v) { TAS400_recordset::set(n-1, v.integer()); }
|
|
void set(unsigned int n, const TDate& v) { TAS400_recordset::set(n-1, TVariant(v)); }
|
|
void add_control_rec(int zero_o_nove);
|
|
TDati_rilevanti_set(int anno, const TString& codatt);
|
|
};
|
|
|
|
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)
|
|
{
|
|
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;
|
|
}
|
|
return TAS400_recordset::set_field(fi, var);
|
|
}
|
|
|
|
void TDati_rilevanti_set::add_control_rec(int zon)
|
|
{
|
|
CHECKD(zon == 0 || zon == 9, "Tipo record di testa o coda non valido ", zon);
|
|
|
|
const TAnagrafica ditta(LF_NDITTE, prefix().get_codditta());
|
|
|
|
TString4 tipo; tipo << zon;
|
|
new_rec(tipo);
|
|
set(6, ditta.codice_fiscale());
|
|
set(7, ditta.partita_IVA());
|
|
|
|
if (ditta.giuridica())
|
|
{
|
|
TString den;
|
|
set(8, ditta.ragione_sociale());
|
|
set(9, ditta.comune_residenza());
|
|
set(10, ditta.provincia_residenza());
|
|
}
|
|
else
|
|
{
|
|
set(11, ditta.cognome());
|
|
set(12, ditta.nome());
|
|
set(13, ditta.sesso());
|
|
set(14, ditta.data_nascita());
|
|
set(15, ditta.comune_nascita());
|
|
set(16, ditta.provincia_nascita());
|
|
}
|
|
set(17, _anno);
|
|
}
|
|
|
|
TDati_rilevanti_set::TDati_rilevanti_set(int anno, const TString& codatt)
|
|
: TAS400_recordset("AS400(1800,1)"),
|
|
_anno(anno), _codatt(codatt)
|
|
{
|
|
TDati_rilevanti_trc trc;
|
|
for (int i = 0; i <= 5; i++)
|
|
trc.create_fields(i, *this);
|
|
trc.create_fields(9, *this);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TDati_rilevanti_msk
|
|
///////////////////////////////////////////////////////////
|
|
|
|
#define MANUAL_ROW 900000L
|
|
|
|
class TDati_rilevanti_msk : public TAutomask
|
|
{
|
|
TMaskmode _mode;
|
|
bool _sheet_dirty, _send_all;
|
|
TAssoc_array _contratti;
|
|
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
void load_sheet();
|
|
bool save_sheet();
|
|
bool save_if_dirty();
|
|
void set_dirty(bool d = true);
|
|
|
|
protected:
|
|
const TString& mov2att(const TRectype& mov) const { return _att_cache.mov2att(mov); }
|
|
TRecnotype last_user_progr() const;
|
|
TRecnotype nuovo_progr() const;
|
|
bool check_rows(bool show_error);
|
|
|
|
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);
|
|
bool salva_allegato(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr,
|
|
const real& corrispettivo, const real& imposta, int tipimp, 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;
|
|
|
|
TDati_rilevanti_msk() : TAutomask("fe0100a"), _mode(MODE_QUERY) { set_dirty(false); }
|
|
};
|
|
|
|
bool TDati_rilevanti_msk::ignora_movimento(const TRectype& mov, const char* motivo, TLog_report& log) const
|
|
{
|
|
const long numreg = mov.get_long(MOV_NUMREG);
|
|
TString msg; msg.format(FR("%7ld Scartato: %s"), numreg, motivo);
|
|
log.log(1, msg);
|
|
return false;
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::convalida_clifo(const TRectype& mov, TLog_report& log) const
|
|
{
|
|
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;
|
|
|
|
if (!_send_all)
|
|
{
|
|
TString4 stato;
|
|
if (ocfpi.full())
|
|
{
|
|
const TRectype& rec_occas = cache().get(LF_OCCAS, ocfpi);
|
|
stato = rec_occas.get(OCC_STATO);
|
|
}
|
|
else
|
|
{
|
|
TString8 key; key.format("%c|%ld", tipocf, codcf);
|
|
const TRectype& rec_clifo = cache().get(LF_CLIFO, key);
|
|
stato = rec_clifo.get(CLI_STATOCF);
|
|
|
|
const int alleg = rec_clifo.get_int(CLI_ALLEG);
|
|
if (alleg == 1)
|
|
return ignora_movimento(mov, TR("Soggetto escluso da comunicazione (Stato, Regioni, Province,...)"), log);
|
|
|
|
// tutti i fornitori esteri vanno esclusi (importazioni)
|
|
if (tipocf == 'F' && alleg == 5)
|
|
return ignora_movimento(mov, TR("Importazione da fornitore estero"), log);
|
|
}
|
|
|
|
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);
|
|
|
|
if (tipocf == 'F')
|
|
return ignora_movimento(mov, TR("Importazione da fornitore estero"), log);
|
|
}
|
|
}
|
|
|
|
return true; //se arriva qui il clifo è da considerare
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::convalida_mov(const TRectype& mov, TLog_report& log) const
|
|
{
|
|
// Ignora eventuale vecchio movimento IVA (ANNOIVA < 2010)
|
|
const int anno = mov.get_int(MOV_ANNOIVA);
|
|
if (anno < 2010)
|
|
return false;
|
|
|
|
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);
|
|
|
|
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);
|
|
}
|
|
// Ignoro silenziosamente gli altri
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
return convalida_clifo(mov, log);
|
|
}
|
|
|
|
|
|
bool TDati_rilevanti_msk::salva_allegato(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr,
|
|
const real& corrispettivo, const real& imposta, int tipimp, int natope,
|
|
TLog_report& log)
|
|
{
|
|
bool update_contract = false;
|
|
|
|
falleg.zero();
|
|
TRectype& alleg = falleg.curr();
|
|
alleg.put(ALL_ANNO, mov.get(MOV_ANNOIVA));
|
|
alleg.put(ALL_CODATT, mov2att(mov));
|
|
alleg.put(ALL_PROGR, progr);
|
|
|
|
TString80 contratto = mov.get(MOV_CONTRATTO);
|
|
real totale;
|
|
if (contratto.full())
|
|
{
|
|
TString80 key;
|
|
key.format("%c%06ld_%s_%d%d", mov.get_char(MOV_TIPO), mov.get_long(MOV_CODCF),
|
|
(const char*)contratto, tipimp, natope);
|
|
real* first_progr = (real*)_contratti.objptr(key);
|
|
if (first_progr == NULL) // Primo movimento del contratto
|
|
{
|
|
first_progr = new real;
|
|
*first_progr = progr;
|
|
_contratti.add(key, first_progr);
|
|
}
|
|
else
|
|
{
|
|
// Aggiorno il record generato col primo movimento del contratto
|
|
const TRecnotype old_progr = first_progr->integer();
|
|
CHECKD(old_progr > 0 && old_progr < progr, "Numero progressivo da contratto non valido ", old_progr);
|
|
alleg.put(ALL_PROGR, old_progr);
|
|
if (falleg.read() != NOERR)
|
|
{
|
|
TString msg;
|
|
msg << "Impossibile aggiornare record da contratto: " << key;
|
|
log.log_error(msg);
|
|
return false;
|
|
}
|
|
update_contract = true;
|
|
}
|
|
}
|
|
|
|
// 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 err = 0;
|
|
if (update_contract)
|
|
{
|
|
// Mi limito ad incrementare gli importi
|
|
alleg.add(ALL_IMPORTO, corrispettivo);
|
|
alleg.add(ALL_IMPOSTA, imposta);
|
|
err = falleg.rewrite();
|
|
}
|
|
else
|
|
{
|
|
// Registro tutti i dati del cliente e gli importi
|
|
alleg.put(ALL_TIPOCF, mov.get(MOV_TIPO));
|
|
alleg.put(ALL_CODCF, mov.get(MOV_CODCF));
|
|
alleg.put(ALL_OCFPI, mov.get(MOV_OCFPI));
|
|
alleg.put(ALL_TIPOPE, tipimp);
|
|
alleg.put(ALL_NATOPE, natope);
|
|
alleg.put(ALL_IMPORTO, corrispettivo);
|
|
alleg.put(ALL_IMPOSTA, imposta);
|
|
alleg.put(ALL_CONTRATTO, contratto);
|
|
alleg.put(ALL_TOTALE, totale);
|
|
|
|
err = falleg.rewrite_write();
|
|
if (err == NOERR)
|
|
progr++;
|
|
}
|
|
|
|
if (err != NOERR)
|
|
{
|
|
TString msg;
|
|
msg.format(FR("Errore %d di aggiornamento del file %s"), err, (const char*)falleg.name());
|
|
log.log_error(msg);
|
|
}
|
|
|
|
return err == NOERR;
|
|
}
|
|
|
|
// Struttura di comodo per memorizzare importi da sommare prima di spedire
|
|
struct TCorrimp : public TObject
|
|
{ real _corrispettivo, _imposta; };
|
|
|
|
bool TDati_rilevanti_msk::elabora_movimento(const TRectype& mov, TFast_isamfile& falleg, TRecnotype& progr, TLog_report& log)
|
|
{
|
|
if (!convalida_mov(mov, log))
|
|
return false;
|
|
|
|
const char tipocf = mov.get_char(MOV_TIPO);
|
|
const TString4 tipodoc = mov.get(MOV_TIPODOC);
|
|
const TDate datareg = mov.get_date(MOV_DATAREG);
|
|
const int anno = datareg.year();
|
|
|
|
const TString& keytok = mov.get(MOV_NUMREG);
|
|
TRecord_array righe_iva(keytok, LF_RMOVIVA);
|
|
|
|
// Corrispettivi ed imposte raggruppate per tipologia imponibile [1..4] e tipologia movimento [1..4]
|
|
TAssoc_array importi;
|
|
|
|
real tot_imponibile, tot_imposta;
|
|
|
|
//calcolo di imponibile ed imposta di tutte le righe iva del movimento
|
|
for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r))
|
|
{
|
|
const TRectype& rmi = righe_iva.row(r);
|
|
const TCodiceIVA ci(rmi.get(RMI_CODIVA));
|
|
int natura_operazione = ci.allegato(tipocf);
|
|
if (natura_operazione <= 0 || natura_operazione > 5)
|
|
continue;
|
|
|
|
// Tratto a parte gli scontrini: devono sempre essere di tipo 4
|
|
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;
|
|
|
|
const bool com_obbl = ci.get_bool("B6");
|
|
if (com_obbl)
|
|
{
|
|
// Le bollette vengono già spedite dal Enel, per cui non si devono spedire nuovamente
|
|
ignora_movimento(mov, TR("oggetto di comunicazione obbligatoria all'anagrafe tributaria"), log);
|
|
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;
|
|
}
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
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 ...
|
|
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
|
|
if (!srv)
|
|
{
|
|
const TBill bill(rmi);
|
|
const TRectype& pcon = cache().get(LF_PCON, bill.string());
|
|
srv = pcon.get_bool(PCN_SERVIZI); // Flag apposito sul sottoconto
|
|
}
|
|
// Cessione o acquisto di beni (1 o 3) o servizi (2 o 4)
|
|
const int tipope = (tipocf == 'C' ? 1 : 3) + (srv ? 1 : 0);
|
|
|
|
const char key[3] = { natura_operazione+'0', tipope+'0', '\0' };
|
|
TCorrimp* imp = (TCorrimp*)importi.objptr(key);
|
|
if (imp == NULL)
|
|
{
|
|
imp = new TCorrimp;
|
|
importi.add(key, imp);
|
|
}
|
|
imp->_corrispettivo += rmi_imponibile;
|
|
imp->_imposta += rmi_imposta;
|
|
|
|
tot_imponibile += rmi_imponibile;
|
|
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
|
|
{
|
|
// Considera solo registrazioni con importo rilevante
|
|
const real limite = anno == 2010 ? 25000 : 3000;
|
|
elabora = tot_imponibile >= 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);
|
|
}
|
|
}
|
|
|
|
return elabora;
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::azzera_alleg(bool manual, TRecnotype first) const
|
|
{
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
|
|
TFast_isamfile falleg(LF_ALLEG);
|
|
|
|
// Azzeramento anno/attività selezionati
|
|
TString limit;
|
|
limit << ALL_ANNO << '=' << anno << ' '
|
|
<< ALL_CODATT << '=' << codatt
|
|
<< ' ' << ALL_PROGR << '=';
|
|
|
|
TRecnotype daprog = manual ? MANUAL_ROW : first;
|
|
TRecnotype aprog = manual ? 0 : MANUAL_ROW;
|
|
|
|
TString query;
|
|
query << "USE " << LF_ALLEG;
|
|
|
|
if (manual) // Elimina i record immessi manualmente ed ignorati
|
|
query << "\nSELECT " << ALL_IGNORA << "=='X'";
|
|
|
|
if (daprog > 0) query << "\nFROM " << limit << daprog;
|
|
if (aprog > 0) query << "\nTO " << limit << aprog;
|
|
|
|
TISAM_recordset alleg(query);
|
|
|
|
const TRecnotype items = alleg.items();
|
|
TString str_pi;
|
|
str_pi << TR("Compattazione dati rilevanti ") << anno << TR(" attività ") << codatt;
|
|
|
|
TProgind pi(items, str_pi);
|
|
const TRectype& rec = alleg.cursor()->curr();
|
|
for (bool ok = alleg.move_first(); ok; ok = alleg.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
falleg.curr() = rec;
|
|
int err = falleg.remove();
|
|
if (err != NOERR)
|
|
return cantwrite_box(falleg.name());
|
|
}
|
|
return items > 0;
|
|
}
|
|
|
|
TRecnotype TDati_rilevanti_msk::last_user_progr() const
|
|
{
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
|
|
TString limit;
|
|
limit << ALL_ANNO << '=' << anno << ' '
|
|
<< ALL_CODATT << '=' << codatt
|
|
<< ' ' << ALL_PROGR << '=';
|
|
|
|
TRecnotype progr = MANUAL_ROW;
|
|
TString query;
|
|
query << "USE " << LF_ALLEG
|
|
<< "\nFROM " << limit << MANUAL_ROW
|
|
<< "\nTO " << limit << (progr+90000);
|
|
TISAM_recordset alleg(query);
|
|
if (alleg.move_last())
|
|
progr = alleg.get(ALL_PROGR).as_int();
|
|
return progr;
|
|
}
|
|
|
|
TRecnotype TDati_rilevanti_msk::nuovo_progr() const
|
|
{
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
|
|
TString limit;
|
|
limit << ALL_ANNO << '=' << anno << ' '
|
|
<< ALL_CODATT << '=' << codatt
|
|
<< ' ' << ALL_PROGR << '=';
|
|
|
|
TRecnotype progr = last_user_progr();
|
|
|
|
TSheet_field& righe = sfield(F_RIGHE);
|
|
const int items = righe.items();
|
|
if (items > 0)
|
|
{
|
|
const int col = righe.cid2index(A_RIGA);
|
|
for (int i = items-1; i >= 0; i--)
|
|
{
|
|
const TRecnotype sheet_progr = atol(righe.cell(i,col));
|
|
if (sheet_progr > 0)
|
|
{
|
|
if (sheet_progr > progr)
|
|
progr = sheet_progr;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return progr+1;
|
|
}
|
|
|
|
TRecnotype TDati_rilevanti_msk::genera_alleg()
|
|
{
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
|
|
TString str_pi;
|
|
str_pi << TR("Movimenti ") << anno << TR(" attività ") << codatt;
|
|
TLog_report log(str_pi);
|
|
|
|
TFast_isamfile falleg(LF_ALLEG);
|
|
TFast_isamfile fmov(LF_MOV);
|
|
|
|
TString query;
|
|
query << "USE MOV KEY 2 SELECT TIPO!=''"
|
|
<< "\nFROM DATAREG=01-01-" << anno
|
|
<< "\nTO DATAREG=31-12-" << anno;
|
|
TISAM_recordset mov(query);
|
|
const TRectype& mov_rec = mov.cursor()->curr();
|
|
|
|
const TRecnotype items = mov.items();
|
|
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;
|
|
if (codatt == mov2att(mov_rec))
|
|
elabora_movimento(mov_rec, falleg, nprog, log);
|
|
}
|
|
|
|
log.preview();
|
|
return nprog;
|
|
}
|
|
|
|
// Analizza tutti i movimenti dell'anno dell'attività corrente e genera i record rilevanti
|
|
bool TDati_rilevanti_msk::elabora_alleg()
|
|
{
|
|
if (!check_fields()) // Controlla che anno ed attività siano validi
|
|
return false;
|
|
|
|
_send_all = get_bool(F_SENDALL);
|
|
|
|
const TRecnotype prog = genera_alleg();
|
|
azzera_alleg(false, prog);
|
|
return prog > 1;
|
|
}
|
|
|
|
|
|
// Genera file per invio telematico
|
|
bool TDati_rilevanti_msk::send_alleg()
|
|
{
|
|
TFilename temp; temp.tempdir();
|
|
temp.add("datiril.txt");
|
|
|
|
TDati_rilevanti_set recset(get_int(F_ANNO), get(F_CODATT));
|
|
recset.add_control_rec(0);
|
|
|
|
TISAM_recordset alleg("");
|
|
|
|
recset.add_control_rec(9);
|
|
return recset.save_as(temp);
|
|
}
|
|
|
|
void TDati_rilevanti_msk::set_dirty(bool d)
|
|
{
|
|
_sheet_dirty = d;
|
|
enable(DLG_SAVEREC, d);
|
|
}
|
|
|
|
void TDati_rilevanti_msk::load_sheet()
|
|
{
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
TString limit;
|
|
limit << ALL_ANNO << '=' << anno << ' ' << ALL_CODATT << '=' << codatt;
|
|
|
|
const char tipocf = get(F_TIPOCF)[0];
|
|
const long codcf = get_long(F_CODCF);
|
|
const TString& ocfpi = get(F_OCFPI);
|
|
|
|
TSheet_field& s = sfield(F_RIGHE);
|
|
s.destroy();
|
|
|
|
TString query;
|
|
query << "USE " << LF_ALLEG;
|
|
if (codcf > 0)
|
|
{
|
|
query << " SELECT (" << ALL_TIPOCF << "='" << tipocf << "')&&(" << ALL_CODCF << "='" << codcf << "')";
|
|
if (ocfpi.full())
|
|
query << "&&(" << ALL_OCFPI << "='" << ocfpi << "')";
|
|
}
|
|
query << "\nFROM " << limit << "\nTO " << limit;
|
|
TISAM_recordset alleg(query);
|
|
const TRecnotype items = alleg.items();
|
|
if (items > 0)
|
|
{
|
|
TString pi_str; pi_str << TR("Caricamento ") << anno << TR(" attività ") << codatt;
|
|
TProgind pi(items, pi_str);
|
|
const TRectype& curr = alleg.cursor()->curr();
|
|
int rec = 0;
|
|
for (bool ok = alleg.move_first(); ok; ok = alleg.move_next())
|
|
{
|
|
if (!pi.addstatus(1)) break;
|
|
s.autoload_line(++rec, curr);
|
|
}
|
|
}
|
|
|
|
s.force_update();
|
|
set_dirty(false);
|
|
|
|
if (s.items() > 0)
|
|
{
|
|
_mode = MODE_MOD;
|
|
disable(-1);
|
|
}
|
|
else
|
|
{
|
|
_mode = MODE_QUERY;
|
|
enable(-1);
|
|
}
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::save_sheet()
|
|
{
|
|
if (!check_rows(false))
|
|
return false;
|
|
|
|
bool done = true;
|
|
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
|
|
TSheet_field& s = sfield(F_RIGHE);
|
|
const TRecnotype items = s.items();
|
|
TFast_isamfile alleg(LF_ALLEG);
|
|
TRectype& rec = alleg.curr();
|
|
TProgind pi(items, TR("Registrazione righe"), false);
|
|
|
|
FOR_EACH_SHEET_ROW(s, r, row)
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
alleg.zero();
|
|
rec.put(ALL_ANNO, anno);
|
|
rec.put(ALL_CODATT, codatt);
|
|
s.autosave_line(r+1, rec);
|
|
const int err = alleg.rewrite_write();
|
|
if (err != NOERR)
|
|
{
|
|
done = cantwrite_box(alleg.name());
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (done)
|
|
{
|
|
azzera_alleg(true, MANUAL_ROW);
|
|
set_dirty(false);
|
|
}
|
|
|
|
return done;
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::check_rows(bool show_error)
|
|
{
|
|
TSheet_field& s = sfield(F_RIGHE);
|
|
|
|
const int anno = get_int(F_ANNO);
|
|
const TString& codatt = get(F_CODATT);
|
|
|
|
bool ok = anno >= 2010 && codatt.full();
|
|
if (!ok)
|
|
{
|
|
if (show_error)
|
|
check_fields(); // Provoco segnalazione automatica
|
|
return false;
|
|
}
|
|
|
|
long codcf = 0L;
|
|
TString16 ocfpi;
|
|
FOR_EACH_SHEET_ROW(s, i, row)
|
|
{
|
|
row->get(s.cid2index(A_CODCF), codcf);
|
|
row->get(s.cid2index(A_OCFPI), ocfpi);
|
|
if (codcf <= 0L && ocfpi.blank())
|
|
{
|
|
ok = show_error && error_box(FR("Soggetto mancante alla riga %d"), i);
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ok;
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::save_if_dirty()
|
|
{
|
|
bool done = true;
|
|
if (_sheet_dirty && yesno_box(TR("Si desiderano registrare le modifiche?")))
|
|
{
|
|
done = check_rows(true);
|
|
if (done)
|
|
done = save_sheet();
|
|
}
|
|
return done;
|
|
}
|
|
|
|
bool TDati_rilevanti_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
case F_CODATT:
|
|
if (e == fe_init)
|
|
{
|
|
TBrowse& b = *((TEdit_field&)o).browse();
|
|
*b.cursor() = 0L;
|
|
b.do_output();
|
|
}
|
|
break;
|
|
case DLG_OK: // Salva
|
|
if (e == fe_button && jolly == 0) // Selezione su maschera principale
|
|
{
|
|
if (_mode == MODE_QUERY || save_if_dirty())
|
|
load_sheet();
|
|
return false;
|
|
}
|
|
break;
|
|
case DLG_CANCEL:
|
|
if (e == fe_button && _mode != MODE_QUERY && jolly == 0)
|
|
{
|
|
if (save_if_dirty())
|
|
{
|
|
TSheet_field& s = sfield(F_RIGHE);
|
|
s.destroy();
|
|
s.force_update();
|
|
_mode = MODE_QUERY;
|
|
enable(-1);
|
|
}
|
|
return false;
|
|
}
|
|
break;
|
|
case DLG_SAVEREC:
|
|
if (e == fe_button)
|
|
save_if_dirty();
|
|
break;
|
|
case DLG_RECALC:
|
|
if (e == fe_button && check_fields())
|
|
{
|
|
if (elabora_alleg())
|
|
load_sheet();
|
|
}
|
|
break;
|
|
case DLG_ELABORA:
|
|
if (e == fe_button && check_fields())
|
|
send_alleg();
|
|
break;
|
|
case F_RIGHE:
|
|
if (e == se_notify_modify)
|
|
set_dirty( true); else
|
|
if (e == se_query_add)
|
|
{
|
|
if (!check_rows(false))
|
|
return false;
|
|
} else
|
|
if (e == se_notify_add)
|
|
{
|
|
TSheet_field& s = (TSheet_field&)o;
|
|
TToken_string& row = s.row(jolly);
|
|
row.add(nuovo_progr(), s.cid2index(A_RIGA));
|
|
row.add(TDate(TODAY), s.cid2index(A_DATAREG));
|
|
row.add(3, s.cid2index(A_MODPAG));
|
|
row.add(1, s.cid2index(A_NATOPE));
|
|
row.add(1, s.cid2index(A_TIPOPE));
|
|
} else
|
|
if (e == se_query_del)
|
|
return false;
|
|
break;
|
|
case DLG_DELREC:
|
|
if (e == fe_button)
|
|
{
|
|
// La cancellazione fisica non si puo' fare subito
|
|
o.mask().set(A_IGNORA, "X");
|
|
return false;
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TDati_rilevanti_app
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TDati_rilevanti_app : public TSkeleton_application
|
|
{
|
|
protected:
|
|
virtual bool create();
|
|
|
|
public:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
bool TDati_rilevanti_app::create()
|
|
{
|
|
TSheet_field::set_line_number_width(6);
|
|
|
|
const TRectype alleg(LF_ALLEG);
|
|
if (!alleg.exist(ALL_IMPORTO))
|
|
return error_box(TR("Il database non è stato ancora convertito per il modulo FE"));
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
void TDati_rilevanti_app::main_loop()
|
|
{
|
|
TDati_rilevanti_msk msk;
|
|
msk.run();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// main
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int fe0100(int argc, char* argv[])
|
|
{
|
|
TDati_rilevanti_app app;
|
|
app.run(argc, argv, TR("Gestione dati rilevanti"));
|
|
return 0;
|
|
}
|
|
|
|
|