From 643681129b7e456516130d6598dbc2e8d2fb34df Mon Sep 17 00:00:00 2001 From: guy Date: Tue, 24 Feb 2015 08:35:08 +0000 Subject: [PATCH] Modello C.U. git-svn-id: svn://10.65.10.50/branches/R_10_00@23042 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- m770/770100.cpp | 15 +- m770/770101.cpp | 3 +- m770/770102.cpp | 15 +- m770/771230.cpp | 27 +- m770/774.cpp | 16 +- m770/777.cpp | 2 +- m770/777.h | 1 + m770/777100.cpp | 804 ++------------------ m770/777100a.h | 2 - m770/777100a.uml | 41 +- m770/777200.cpp | 1812 +++++++++++++++++++++++++--------------------- m770/777201.cpp | 825 +++++++++++++++++++++ m770/777202.cpp | 289 ++++++++ m770/77lib01.cpp | 3 + m770/77menu.men | 9 +- 15 files changed, 2235 insertions(+), 1629 deletions(-) create mode 100644 m770/777201.cpp create mode 100644 m770/777202.cpp diff --git a/m770/770100.cpp b/m770/770100.cpp index 375fc19fa..6b041f826 100755 --- a/m770/770100.cpp +++ b/m770/770100.cpp @@ -10,9 +10,6 @@ #include "../cg/cgsaldac.h" #include -#include -#include -#include // per dinamica non riprendere #include "../ve/velib.h" #include "770101.h" @@ -2153,17 +2150,17 @@ Pag_struct& TSchedaPercipienti::calcola_riga_pag(Pag_struct& s, // calcolo CPA c.impcpa = s.compenso * h_PercCassaPrev / (CENTO + h_PercCassaPrev); c.impcpa.round(fdec); - if (s.impcpa == ZERO || force) + if (s.impcpa.is_zero() || force) s.impcpa = c.impcpa; // calcolo imponibile c.imponibile = (s.compenso - s.impcpa) * h_PercAssImp / CENTO; c.imponibile.round(fdec); - if (s.imponibile == ZERO || force) + if (s.imponibile.is_zero() || force) s.imponibile = c.imponibile; // percentuale ritenuta acconto - if (s.perc == ZERO || force) + if (s.perc.is_zero() || force) s.perc = h_PercRitenuta; // calcolo ritenuta lorda @@ -2179,17 +2176,17 @@ Pag_struct& TSchedaPercipienti::calcola_riga_pag(Pag_struct& s, // calcolo ritenuta c.ritenuta = s.ritlorda - s.totdet; - if (s.ritenuta == ZERO || force) + if (s.ritenuta.is_zero() || force) s.ritenuta = c.ritenuta; // percentuale assoggettamento Inps - if (s.alqimp10 == ZERO || force) + if (s.alqimp10.is_zero() || force) s.alqimp10 = h_PercAssImpInps; // calcolo contributo Inps complessivo c.ctssncomp = ((s.compenso * s.alqimp10 / CENTO) * h_PercInps) / CENTO; c.ctssncomp.round(fdec); - if (s.ctssncomp == ZERO || force) + if (s.ctssncomp.is_zero() || force) s.ctssncomp = c.ctssncomp; // calcolo contributo Inps del percipiente diff --git a/m770/770101.cpp b/m770/770101.cpp index 89dce6948..8b0bd0585 100755 --- a/m770/770101.cpp +++ b/m770/770101.cpp @@ -8,8 +8,7 @@ // Scheda Percipiente /////////////////////////////////////////////////////////// -TSchedaPE::TSchedaPE() -: TRelation(LF_SCPERC), _old_ver(0), _old_pag(0) +TSchedaPE::TSchedaPE() : TRelation(LF_SCPERC), _old_ver(0), _old_pag(0) { add(LF_RVER, "CODDITTA==CODDITTA|TIPOA==TIPOA|CODANAGR==CODANAGR|NPROG==NPROG"); add(LF_RPAG, "CODDITTA==CODDITTA|TIPOA==TIPOA|CODANAGR==CODANAGR|NPROG==NPROG"); diff --git a/m770/770102.cpp b/m770/770102.cpp index 595b3e48b..f0b439a37 100755 --- a/m770/770102.cpp +++ b/m770/770102.cpp @@ -98,10 +98,10 @@ bool TSchedaPercipienti::vers_notify(TSheet_field& s, int r, KEY k) // Pulisco descrizioni luogo e tipo versamento (solo se non gia' indicati!) TSheet_field& vers = app().vers(); TMask& mp = vers.sheet_mask(); - TString16 tipo(mp.get(F_TIPOVERS)); - TString16 luo (mp.get(F_LUOVERS)); + const TString& tipo = mp.get(F_TIPOVERS); if (tipo.empty()) mp.reset(70); + const TString& luo = mp.get(F_LUOVERS); if (luo.empty()) mp.reset(71); break; @@ -827,7 +827,8 @@ bool TSchedaPercipienti::pag_standard_handler(TMask_field& f, KEY k) { // non proseguo se riga vuota - if (s == nullpag) return TRUE; + if (s == nullpag) + return true; // reperisco nome campo su record const TString& name = f.field()->name(); @@ -871,19 +872,19 @@ bool TSchedaPercipienti::pag_standard_handler(TMask_field& f, KEY k) { // if ((d_codqua != "SC" && d_codqua != "SE") && s.somregconv != ZERO) nell'ultima versione dei quadri le SOMREGCONV valgono per tutti i tipi di quadro (SC,SE,SF,SG) // return f.error_box("Somme reg.conv. valido solo per causali con quadro SC e SE"); 12/07/2000 - if (!app()._soggnres && s.somregconv != ZERO) + if (!app()._soggnres && !s.somregconv.is_zero()) return f.error_box("Somme reg.conv. valido solo se percipiente non residente"); } // controllo contributo 10% percipiente if (name == "CTSSNPERC" && !d_forzatura) if (s.ctssnperc != c.ctssnperc) - return f.error_box("Contributo Inps percipiente diverso da importo calcolato"); + return f.error_box("Contributo INPS percipiente diverso da importo calcolato"); // controllo contributo 10% complessivo if (name == "CTSSNCOMP" && !d_forzatura) if (s.ctssncomp != c.ctssncomp) - return f.error_box("Contributo Inps complessivo diverso da importo calcolato"); + return f.error_box("Contributo INPS complessivo diverso da importo calcolato"); // controllo numero quote if (name == "NQUOTE" && !d_forzatura) @@ -892,6 +893,6 @@ bool TSchedaPercipienti::pag_standard_handler(TMask_field& f, KEY k) } } - return TRUE; + return true; } diff --git a/m770/771230.cpp b/m770/771230.cpp index 12c6a2b72..6bbbcf5f7 100755 --- a/m770/771230.cpp +++ b/m770/771230.cpp @@ -70,7 +70,7 @@ const TRectype* TRighe_pagamento::prospetto_e1(char caus) void TRighe_pagamento::add_riga(const TRectype& scheda, const TRectype& riga) { - TString16 chiave; + TString chiave; const char causqua = toupper(scheda.get_char(SPR_CAUSQUA)); chiave << causqua; @@ -98,8 +98,8 @@ void TRighe_pagamento::add_riga(const TRectype& scheda, const TRectype& riga) *rec += riga; if (_quadro == "C") // Nel caso di quadro C somma anche i giorni detr dip. { - const int gglav = rec->get_int(PAG_GIOLAVDIP) + riga.get_int(PAG_GIOLAVDIP); - rec->put(PAG_GIOLAVDIP,gglav); + const real gglav = riga.get(PAG_GIOLAVDIP); + rec->add(PAG_GIOLAVDIP, gglav); } } else @@ -725,8 +725,10 @@ void TQuadroC_E2::genera_e1(TRectype& quadro, const TRectype& riga) const void TQuadroC_E2::genera_la(TRectype& quadro, const TRectype& riga) const { + const TDate datapag = riga.get(PAG_DATAPAG); const real imponibile = riga.get(PAG_IMPONIBILE); + quadro.put("ANNO", datapag.year()); quadro.put(QUD_PERC, riga.get(PAG_PERC)); real ammlordo = imponibile; @@ -762,7 +764,7 @@ void TQuadroC_E2::genera_la(TRectype& quadro, const TRectype& riga) const void TQuadroC_E2::genera_righe(TRighe_pagamento& righe) const { - TLocalisamfile file(_file); + TFast_isamfile file(_file); TRectype& curr = file.curr(); int nriga = 1; righe.restart(); @@ -777,7 +779,7 @@ void TQuadroC_E2::genera_righe(TRighe_pagamento& righe) const curr.put(PAG_CODANAGR, riga.get(PAG_CODANAGR)); curr.put("NPROG", nriga); curr.put("CAUSALE", chiave[0]); - curr.put("GENERATA", bool(TRUE)); + curr.put("GENERATA", true); switch (_quadro[0]) { @@ -824,10 +826,10 @@ void TQuadroC_E2::genera_righe(TRighe_pagamento& righe) const // genera prospetto e1; if (QuadroE1()) { - TLocalisamfile prospe1(LF_PROSPE1); + TFast_isamfile prospe1(LF_PROSPE1); TRectype& rec = prospe1.curr(); - bool first = TRUE; + bool first = true; for (char caus = 'C'; caus <= 'E'; caus++) { const TRectype* riga = righe.prospetto_e1(caus); @@ -890,7 +892,7 @@ void TQuadroC_E2::generazione() const TRectype& scheda = cur.curr(); const TRectype& riga = cur.curr(LF_RPAG); - TProgind pi (items, "Generazione da schede.", TRUE, TRUE, 60); + TProgress_monitor pi(items, TR("Generazione da schede.")); distruzione(); @@ -901,8 +903,7 @@ void TQuadroC_E2::generazione() for (cur = 0; cur.pos() < items; ++cur) { - pi.addstatus(1); - if (pi.iscancelled()) + if (!pi.add_status()) break; const char tipoa = scheda.get_char(SPR_TIPOA); @@ -918,13 +919,11 @@ void TQuadroC_E2::generazione() last_code = codanagr; } - bool ok = cur.is_first_match(LF_RPAG); - while (ok) + for (bool ok = cur.is_first_match(LF_RPAG); ok; ok = cur.next_match(LF_RPAG)) { const TDate datapag = riga.get(PAG_DATAPAG); if (datapag.year() == anno770) righe.add_riga(scheda, riga); - ok = cur.next_match(LF_RPAG); } } @@ -1221,7 +1220,7 @@ bool TQuadroC_E2::ricalcola_imposte_la(TMask_field& f, KEY key) } } - const real imposta_v = m.get_real(102) * imponibile / 100.0; + const real imposta_v = m.get_real(102) * imponibile / CENTO; real imposta = m.get(109); if (imposta.is_zero()) { diff --git a/m770/774.cpp b/m770/774.cpp index 67dd774bd..50ea75567 100755 --- a/m770/774.cpp +++ b/m770/774.cpp @@ -1,26 +1,16 @@ #include -#include #include "774.h" -#define usage "Error - usage : %s -{0|1|2|3}" - int main(int argc,char** argv) { int n = (argc > 1) ? atoi(argv[1]+1) : -1; - switch (n) { - case 0: - m74100(argc,argv) ; break; - case 1: - riporti_dich(argc,argv) ; break; - case 2: - azzeramento_archivi(argc,argv) ; break; - default: - error_box(usage, argv[0]) ; + case 1: riporti_dich(argc,argv); break; + case 2: azzeramento_archivi(argc,argv); break; + default: m74100(argc,argv); break; } - exit(0); return 0; } diff --git a/m770/777.cpp b/m770/777.cpp index 845a28d19..a45128801 100755 --- a/m770/777.cpp +++ b/m770/777.cpp @@ -7,7 +7,7 @@ int main(int argc,char** argv) const int n = (argc > 1) ? atoi(argv[1]+1) : -1; switch(n) { - case 0: + case 1: m777200(argc, argv); break; default: m777100(argc, argv); break; } return 0; diff --git a/m770/777.h b/m770/777.h index 173e36865..5d64c5ca2 100755 --- a/m770/777.h +++ b/m770/777.h @@ -1 +1,2 @@ int m777100(int argc, char* argv[]); +int m777200(int argc, char* argv[]); diff --git a/m770/777100.cpp b/m770/777100.cpp index 15add5269..c8c536bfd 100755 --- a/m770/777100.cpp +++ b/m770/777100.cpp @@ -7,8 +7,10 @@ #include #include "777.h" +#include "777lib.h" #include "777100a.h" + #include #include #include @@ -25,20 +27,14 @@ // Utility /////////////////////////////////////////////////////////// -// Codice fiscale di Sirio spa -#define CF_PRODUTTORE "04879210963" - const int ANNO_DIC = 2013; /////////////////////////////////////////////////////////// // TForm770 /////////////////////////////////////////////////////////// -class TRecord770; class TTrasferimento770; -enum M770FieldType { AN, CF, CN, PI, DA, DT, NU, PN, PR, CB, VP, VN }; - class TForm770 : public TForm { TCursor* _sortedcur; @@ -71,132 +67,6 @@ public: virtual ~TForm770(); }; -/////////////////////////////////////////////////////////// -// TRecord770 -/////////////////////////////////////////////////////////// - -enum { CODE_SIZE = 8, FIELD_SIZE = 16, BLOCK_SIZE = 24, HEADER_SIZE = 89, USEABLE_SIZE = 1800, TOTAL_SIZE = 1900 }; - -struct TField770 : public TObject -{ - TString _desc; - int _pos; // Base 1 - int _len; - M770FieldType _type; // AN,NU,... -}; - -class TTracciato770 : public TObject -{ - char _tipo; - TArray _fields; - -protected: - void add_field(const char* name, M770FieldType tipo, int pos, int len, int filedno = 0); - void add_filler(int pos, int len, M770FieldType tipo = AN) - { add_field("Filler", tipo, pos, len); } - -public: - const TField770& field(int pos) const; - void auto_fill(TString& buffer) const; - - TTracciato770(char tipo); - virtual ~TTracciato770(); -}; - -class TTracciati770 : public TObject -{ - TArray _trc; - TAssoc_array _form; - bool _centesimi; // Salva importi in centesimi invece che in euro - -public: - const TTracciato770& tracciato(char tipo); - TForm770& form(const char* quadro, char& tipo, int& rpm); - - void destroy(); - - void set_cent_mode(bool cb) { _centesimi = cb; } - bool importi_in_centesimi() const { return _centesimi; } - bool importi_in_euro() const { return !_centesimi; } - - TTracciati770(); - virtual ~TTracciati770(); -} _trc770; - -class TCache770 : public TObject -{ - TArray _files; - TAssoc_array _tables; - -public: - const TRectype& get(int num, const char* key); - const TRectype& get(int num, long key); - void destroy(); -} _cache770; - -class TRecord770 : public TObject -{ - TString _buffer; - -protected: // TObject - virtual TObject* dup() const { return new TRecord770(*this); } - virtual void print_on(ostream& outs) const; - virtual void read_from(istream& ins); - -protected: // TObject - const TTracciato770& tracciato() const - { return _trc770.tracciato(tipo_record()); } - - const TField770& get_field(int pos) const - { return tracciato().field(pos); } - - void set(const TField770& fld, const char* val); - int calculate_blocks(const char* val) const; - -public: - void set(int pos, const char* val); - void set(int pos, int val); - void set(int pos, long val); - void set(int pos, const real& val); - void set(int pos, const TDate& val); - void set(int pos, char val); - void set(int pos, bool val); - bool np_put(const char* code, const char* val); - bool np_put(const char* code, const real& val); - bool np_put(const char* code, long val); - - const char* get(int pos, TString& str) const; - int get_int(int pos) const; - char get_char(int pos) const; - - bool np_get(int pos, TString& key, TString& val) const; - bool np_get_real(int pos, TString& key, real& val) const; - - const TRecord770& operator=(const TRecord770& rec) - { _buffer = rec._buffer; return *this; } - - char tipo_record() const { return _buffer[0]; } - void tipo_record(char tipo) - { _buffer[0] = tipo; tracciato().auto_fill(_buffer); } - - void azzera_campi_non_posizionali(); - bool ha_campi_non_posizionali() const { return strchr("DEFGHJ", tipo_record()) != NULL; } - bool ha_campi_non_posizionali_compilati() const - { return _buffer[90] > ' '; } - - bool valid() const; - - TRecord770(); - TRecord770(char tipo); - TRecord770(const TRecord770& rec); - TRecord770(const TRectype& rec); - virtual ~TRecord770(); -}; - -/////////////////////////////////////////////////////////// -// TTrasferimento770 -/////////////////////////////////////////////////////////// - class TTrasferimento770 : public TObject { TFilename _name; @@ -209,19 +79,27 @@ class TTrasferimento770 : public TObject TString16 _codfis_dic; TString _ragsoc_dic; bool _save_headers; + bool _centesimi; // Salva importi in centesimi invece che in euro + + TAssoc_array _form; protected: void riepiloga_ss(const TRecord770& rec, TArray& riep_ss) const; void riepiloga_sx(const TRecord770& rec, TArray& riep_sx) const; - + TForm770& form(const char* quadro, char& tiporec, int& rpm); + public: + const char* default_name() const; + bool open(const char* path = "", char mode = 'r', int volume = 0); bool close(); bool write(const TRecord770& rec); bool read(TRecord770& rec); bool eof() const { return _in_stream && _in_stream->eof(); } - const char* default_name() const; + void set_cent_mode(bool cb) { _centesimi = cb; } + bool importi_in_centesimi() const { return _centesimi; } + bool importi_in_euro() const { return !_centesimi; } TTrasferimento770& operator<<(const TRecord770& rec) { write(rec); return *this; } @@ -235,7 +113,7 @@ public: bool casella_prospetto_st() const; bool casella_prospetto_sx() const; bool append_record_b(); - long append_quadro(const char* quadro, long codditta, TProgind& pi); + long append_quadro(const char* quadro, long codditta, TProgress_monitor& pi); bool split(const char* dest_path); void remove(); @@ -247,10 +125,6 @@ public: virtual ~TTrasferimento770(); }; -/////////////////////////////////////////////////////////// -// Implementazioni -/////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////// // TForm770 /////////////////////////////////////////////////////////// @@ -320,7 +194,7 @@ void TForm770::transfer_section(TPrint_section& body, int rigo, if (xvt_str_compare_ignoring_case(fi.class_name(), "VALUTA") == 0) { real val = str; - if (_trc770.importi_in_centesimi()) + if (file.importi_in_centesimi()) { val *= CENTO; str = val.stringa(16, 0); @@ -368,7 +242,7 @@ void TForm770::transfer_section(TPrint_section& body, int rigo, if (xvt_str_compare_ignoring_case(fi.class_name(), "VALUTA") == 0) { real val = str; - if (_trc770.importi_in_centesimi()) + if (file.importi_in_centesimi()) val *= CENTO; str = val.string(16, 0); } @@ -639,335 +513,16 @@ TForm770::~TForm770() delete _sortedcur; } -/////////////////////////////////////////////////////////// -// TTracciato770 -/////////////////////////////////////////////////////////// - -void TTracciato770::add_field(const char* name, M770FieldType type, int pos, int len, int fldno) -{ - switch (type) - { - case AN: - break; - case CB: - CHECKD(len == 1, "Booleano di lunghezza sospetta ", len); - type = NU; - break; - case CF: - CHECKD(len == 16, "Codice fiscale di lunghezza sospetta ", len); - type = AN; - break; - case CN: - CHECKD(len == 11, "Codice fiscale numerico di lunghezza sospetta ", len); - type = NU; - break; - case DA: - CHECKD(len == 6, "Mese+Anno di lunghezza sospetta ", len); - type = NU; - break; - case DT: - CHECKD(len == 8, "Data di lunghezza sospetta ", len); - type = NU; - break; - case NU: - break; - case PN: - case PR: - CHECKD(len == 2, "provincia di lunghezza sospetta ", len); - type = AN; - break; - default: - CHECK(false, "tipo campo sospetto"); - break; - } - - TField770* info = new TField770; - info->_desc = name; - info->_type = type; - info->_pos = pos; - info->_len = len; - - if (fldno <= 0) - fldno = _fields.add(info)+1; - else - _fields.add(info, fldno-1); -} - -const TField770& TTracciato770::field(int pos) const +class TCache770 : public TObject { - TField770* info = (TField770*)_fields.objptr(pos-1); -#ifdef DBG - if (info == NULL) - fatal_box("Non esiste il campo %d sul tipo record %c", pos, _tipo); -#endif - return *info; -} + TArray _files; + TAssoc_array _tables; -void TTracciato770::auto_fill(TString& buffer) const -{ - buffer.fill(' ', TOTAL_SIZE); - char* ptr = buffer.get_buffer(); - for (int f = _fields.last(); f >= 0; f = _fields.pred(f)) - { - const TField770& info = (const TField770&)_fields[f]; - if (info._type == NU || info._type == CB || info._type == DA || info._type == DT || info._type == CN) - memset(ptr + info._pos - 1, '0', info._len); - } - buffer[0] = _tipo; - buffer.overwrite("A\r\n", TOTAL_SIZE-3); -} - -TTracciato770::TTracciato770(char tipo) : _tipo(tipo) -{ - if (strchr("ABEFHJZ", tipo) == NULL) - NFCHECK("Tipo record non valido: %c", tipo); - - add_field("Tipo record", AN, 1, 1); // 1 - - if (tipo == 'A') - { - add_filler(2, 14); // 2 - add_field("Codice fornitura", AN, 16, 5); // 3 - add_field("Tipo fornitore", NU, 21, 2); // 4 - add_field("Codice fiscale del fornitore", CF, 23, 16); - add_filler(39, 483); - // Dichiarazione su pił invii - add_field("Progressivo dell'invio", NU, 522, 4); // 7 - add_field("Numero totale degli invii", NU, 526, 4); - } else - if (tipo == 'B') - { - add_field("Codice fiscale dichiarante", CF, 2, 16); // 2 - add_field("Progressivo modulo", NU, 18, 8); - add_filler( 26, 3); - add_filler( 29,25); - add_field("Spazio a disposizione", AN, 54, 20); - add_field("CF del produttore del software", CF, 74, 16); // 7 - - add_field("Flag conferma", CB, 90, 1); - - // Tipo di dichiarazione - add_field("Dichiarazione correttiva nei termini", CB, 91, 1); // 9 - add_field("Dichiarazione correttiva parziale", CB, 92, 1); - add_field("Dichiarazione integrativa", CB, 93, 1); - add_field("Eventi eccezzziunali veramente", NU, 94, 1); // 12 - - // Dati del contribuente - add_field("Cognome", AN, 95, 24); // 13 - add_field("Nome", AN,119, 20); - add_field("Denominazione (Alternativo a 25 e 26)",AN,139, 60); - add_filler(199,11); - add_filler(210, 1); - add_filler(211, 1); - - add_field("Codice Attivitą", NU, 212, 6); // 19 - add_field("Indirizzo E-mail", AN, 218, 100); - add_field("Telefono o Cellulare", AN, 318, 12); - add_field("FAX", AN, 330, 12); // 22 - - add_field("Data di nascita", DT, 384, 8, 25); // 25 - add_field("C.a.p. residenza", NU, 435, 5, 29); // 29 - add_field("Data variazione", DT, 479, 8, 32); // 32 - - // Saltiamo a pie' pari i dati delle persone fisiche - - add_field("Natura giuridica", NU, 487, 2, 33); // 33 - add_field("Data variazione sede legale", DA, 489, 6); - add_field("Comune della sede legale", AN, 495,40); - add_field("Sigla della provincia sede legale", PR, 535, 2); - add_field("CAP del comune della sede legale", NU, 537, 5); - add_field("Codice comune", AN, 542, 4); - add_field("Indirizzo della sede legale", AN, 546,35); - add_field("Data variazione domicilio fiscale", NU, 581, 6); // 40 - add_field("Comune del domicilio fiscale", AN, 587,40); - add_field("Provincia del domicilio fiscale", PR, 627, 2); - add_field("CAP del domicilio fiscale", NU, 629, 5); - add_field("Codice comune", AN, 634, 5); - add_field("Indirizzo del domicilio fiscale", AN, 638,35); - add_field("Stato", NU, 673, 1); - add_field("Situazione", NU, 674, 1); - add_field("Dicastero di appartenenza", CN, 675, 11); - - add_field("Redazione della dichiarazione", NU, 797, 1, 75); // 75 - add_field("Numero comunicaz. lavoro dipendente", NU, 798, 8); - add_field("Numero comunicaz. lavoro autonomo", NU, 806, 8); - add_field("Casella prospetto SS", CB, 814, 1); // 78 - add_field("Casella prospetto ST", CB, 815, 1); - add_field("Casella prospetto SV", CB, 816, 1); - add_field("Casella prospetto SX", CB, 817, 1); // 81 - add_field("Casella prospetto SY", CB, 818, 1); - add_field("Presenza 770 ordinario 2011", CB, 819, 1); - add_field("Codice fiscale parte restante", CF, 820,16); - add_field("Protocollo telematico", NU, 836,17); // 85 - add_field("Progressivo telematico", NU, 853, 6); - - // dichiarazioni integrative o parziali - add_field("Casella prospetto SS", CB, 859, 1); // 87 - add_field("Casella prospetto ST", CB, 860, 1); - add_field("Casella prospetto SV", CB, 861, 1); - add_field("Casella prospetto SX", CB, 862, 1); - add_field("Casella prospetto SY", CB, 863, 1); - add_field("Numero comunicaz. lavoro dipendente", NU, 864, 8); - add_field("Numero comunicaz. lavoro autonomo", NU, 872, 8); // 93 - - add_field("Firma del dichiarante", CB, 880, 1, 94); // 94 - add_field("Codice fiscale", CF, 881,16); - add_field("Soggetto", NU, 897, 1); - add_field("Firma", CB, 898, 1); // 97 - add_field("Codice fiscale", CF, 899,16); - add_field("Soggetto", NU, 915, 1); - add_field("Firma", CB, 916, 1); // 100 - add_field("Codice fiscale", CF, 917,16); - add_field("Soggetto", NU, 933, 1); - add_field("Firma", CB, 934, 1); // 103 - add_field("Codice fiscale", CF, 935,16); - add_field("Soggetto", NU, 951, 1); - add_field("Firma", CB, 952, 1); // 106 - add_field("Codice fiscale", CF, 953,16); - add_field("Soggetto", NU, 969, 1); - add_field("Firma", CB, 970, 1); // 109 - add_field("Non trasmissione ST, SV e/o SX", NU, 971, 1); - add_field("Casella Attestazione", CB, 972, 1); - - add_field("Situazioni particolari", NU,1180,2, 116); // 116 - - add_field("Codice fiscale del rappresentante", CF,1396,16,126); // 126 - add_field("Codice carica del rappresentante", NU,1412, 2); - add_field("Data carica del rappresentante", DT,1414, 8); - - add_field("Cognome", AN,1493,24, 131); // 131 - add_field("Nome", AN,1517,20); - add_field("Sesso", AN,1537, 1); - add_field("Data di nascita rappresentante", DT,1538, 8); - add_field("Comune di nascita", AN,1546,40); // 135 - add_field("Provincia di nascita", PN,1586, 2); - - add_field("Codice stato estero", NU,1588, 3); // 137 - add_field("Stato federato, provincia, contea", AN,1591,24); - add_field("Localitą di residenza", AN,1615,24); - add_field("Indirizzo estero", AN,1639,35); // 140 - - add_field("Data apertura fallimento", DT,1686, 8, 142); // 142 - add_field("Codice fiscale societa o dichiarante", NU,1694,11); - - add_field("Invio avviso telematico", CB,1715, 1, 147); // 147 - add_field("Ricezione avviso telematico", CB,1716, 1); - add_field("Codice fiscale intermediario", CF,1717,16); - add_field("Numero iscrizione C.A.F.", NU,1733, 5); - add_field("Impegno a trasmettere la dichiaraz.", NU,1738, 1); // 151 - add_field("Data dell'impegno", DT,1739, 8); - add_field("Firma dell'intermediario", CB,1747, 1); - add_field("Codice fiscale responsabile C.A.F.", CF,1748,16); - add_field("Codice fiscale C.A.F.", CN,1764,11); - add_field("Codice fiscale professionista", CF,1775,16); // 156 - add_field("Firma", CB,1791, 1); - } else - if (tipo == 'E' || tipo == 'F') - { - add_field("Codice fiscale del dichiarante", CF, 2, 16); // 2 - add_field("Progressivo modulo", NU, 18, 8); - add_field("Spazio a disposizione", AN, 26, 3); - add_field("Tipo operazione", AN, 29, 1); - add_filler(30, 24); - add_field("Spazio a disposizione", AN, 54, 20); - add_field("Identificativo produttore software", AN, 74, 16); // 8 - } else - if (tipo == 'H') - { - add_field("Codice fiscale del dichiarante", CF, 2, 16); // 2 - add_field("Progressivo comunicazione", NU, 18, 8); - add_field("Spazio a disposizione", AN, 26, 3); - add_field("Tipo operazione", AN, 29, 1); - add_field("Codice fiscale del percipiente", AN, 30, 16); // 6 - add_filler(46, 8); - add_field("Spazio a disposizione", AN, 54, 20); - add_field("Identificativo produttore software", AN, 74, 16); // 9 - } else - if (tipo == 'J') - { - add_field("Codice fiscale del dichiarante", CF, 2, 16); // 2 - add_field("Progressivo modulo", NU, 18, 8); - add_field("Spazio a disposizione", AN, 26, 3); - add_field("Tipo operazione", AN, 29, 1); - add_filler(30, 24); - add_field("Spazio a disposizione", AN, 54, 20); - add_field("Identificativo produttore software", AN, 74, 16); // 8 - } else - if (tipo == 'Z') - { - add_filler(2, 14); - add_field("Numero record di tipo 'B'", NU, 16, 9); // 3 - add_field("Numero record di tipo 'D'", NU, 25, 9); - add_field("Numero record di tipo 'E'", NU, 34, 9); - add_field("Numero record di tipo 'F'", NU, 43, 9); // 6 - add_field("Numero record di tipo 'G'", NU, 52, 9); - add_field("Numero record di tipo 'H'", NU, 61, 9); - add_field("Numero record di tipo 'I'", NU, 70, 9); - add_field("Numero record di tipo 'J'", NU, 79, 9); // 10 - add_filler(88, 1810); - } -} - -TTracciato770::~TTracciato770() -{ -} - -/////////////////////////////////////////////////////////// -// TTracciati770 -/////////////////////////////////////////////////////////// - -const TTracciato770& TTracciati770::tracciato(char tipo) -{ - CHECK(tipo >= 'A' && tipo <= 'Z', "Tipo record non valido"); - const int pos = tipo - 'A'; - TTracciato770* trc = (TTracciato770*)_trc.objptr(pos); - if (trc == NULL) - { - trc = new TTracciato770(tipo); - _trc.add(trc, pos); - } - return *trc; -} - -// Determina a partire dal codice quadro (LA o ST) il tipo record (H o E) ed il numero di record per modulo (1 o 12) -// Ritorna il form da cui prelevare i codici (come AUXXX010) da inserire nei tracciati -TForm770& TTracciati770::form(const char* quadro, char& tiporec, int& rpm) -{ - CHECK(quadro && *quadro != '\0' && quadro[1] != '\0', - "Codice quadro non valido"); - - const char* name; - switch(quadro[1]) - { - case 'A': name = "77qla"; tiporec = 'H'; rpm = 1; break; - case 'T': name = "77qst"; tiporec = 'E'; rpm = 12; break; - default : name = NULL; break; - } - - TForm770* frm = (TForm770*)_form.objptr(name); - if (frm == NULL) - { - frm = new TForm770(name); - _form.add(name, frm); - } - - return *frm; -} - -void TTracciati770::destroy() -{ - _trc.destroy(); - _form.destroy(); -} - -TTracciati770::TTracciati770() : _centesimi(false) -{ -} - -TTracciati770::~TTracciati770() -{ - destroy(); // Non viene mai chiamato! -} +public: + const TRectype& get(int num, const char* key); + const TRectype& get(int num, long key); + void destroy(); +} _cache770; /////////////////////////////////////////////////////////// // TCache770 @@ -996,252 +551,6 @@ void TCache770::destroy() _tables.destroy(); } -/////////////////////////////////////////////////////////// -// TRecord770 -/////////////////////////////////////////////////////////// - -void TRecord770::print_on(ostream& outs) const -{ - outs.write(_buffer, TOTAL_SIZE); -} - -void TRecord770::read_from(istream& ins) -{ - _buffer.fill(' ', TOTAL_SIZE); - ins.read(_buffer.get_buffer(), TOTAL_SIZE); -} - -void TRecord770::set(const TField770& fld, const char* val) -{ - TString80 str(val); - if (fld._type == AN) - str.upper(); - int lenstr = str.len(); - if (lenstr > fld._len) - { -#ifdef DBG - NFCHECK("Campo troppo lungo: '%s' (max. %d)", val, fld._len); -#endif - str.cut(lenstr = fld._len); - } - if (lenstr != fld._len) - { - str.trim(); - if (fld._type == NU) - str.right_just(fld._len, '0'); - else - str.left_just(fld._len); - } - _buffer.overwrite(str, fld._pos-1); -} - -void TRecord770::set(int pos, const char* val) -{ - const TField770& fld = tracciato().field(pos); - set(fld, val); -} - -void TRecord770::set(int pos, int val) -{ - const TField770& fld = tracciato().field(pos); - CHECKD(fld._type == NU, "Invalid numeric field ", pos); - TString16 str; str.format("%d", val); - set(fld, str); -} - -void TRecord770::set(int pos, long val) -{ - const TField770& fld = tracciato().field(pos); - CHECKD(fld._type == NU, "Invalid numeric field ", pos); - TString16 str; str.format("%ld", val); - set(fld, str); -} - -void TRecord770::set(int pos, const real& val) -{ - const TField770& fld = tracciato().field(pos); - CHECKD(fld._type == NU, "Invalid numeric field ", pos); - const char* str = val.string(fld._len, 0); - set(fld, str); -} - -void TRecord770::set(int pos, const TDate& val) -{ - const TField770& fld = tracciato().field(pos); - CHECKD(fld._type == NU && (fld._len == 6 || fld._len == 8), - "Invalid date field ", pos); - const char* str; - if (fld._len == 8) - str = val.string(full, '\0', full, full, gma_date); - else - str = val.string(brief, '\0', full, full, gma_date); - set(fld, str); -} - -void TRecord770::set(int pos, char val) -{ - const TField770& fld = get_field(pos); - CHECKD(fld._type == AN && fld._len == 1, "Invalid char field ", pos); - const char str[2] = { val, '\0' }; - set(fld, str); -} - -void TRecord770::set(int pos, bool val) -{ - const TField770& fld = get_field(pos); - CHECKD((fld._type == CB || fld._type == NU)&& fld._len == 1, "Invalid boolean field ", pos); - set(fld, val ? "1" : "0"); -} - -const char* TRecord770::get(int pos, TString& str) const -{ - const TField770& fld = get_field(pos); - str = _buffer.mid(fld._pos-1, fld._len); - return str.trim(); -} - -int TRecord770::get_int(int pos) const -{ - TString16 str; get(pos, str); - return atoi(str); -} - -char TRecord770::get_char(int pos) const -{ - const TField770& fld = get_field(pos); - CHECKD(fld._type == AN, "Invalid char field ", pos); - return _buffer[fld._pos-1]; -} - -// Calcola i blocchi necessari per contenere la stringa val -int TRecord770::calculate_blocks(const char* val) const -{ - // Il primo blocco contiene 16 caratteri, gli altri solo 15 perche' c'e' anche il + - int blocks = 1; - if (val && *val) - { - const int len = strlen(val); - if (len > FIELD_SIZE) - blocks += (len-FIELD_SIZE-1) / (FIELD_SIZE-1) + 1; - } - return blocks; -} - -// Azzera tutti i campi non posizionali dei record di tipo E -void TRecord770::azzera_campi_non_posizionali() -{ - CHECK(ha_campi_non_posizionali(), "Impossibile azzerare un record senza campi non posizionali"); - char* buf = _buffer.get_buffer() + HEADER_SIZE; - memset(buf, ' ', USEABLE_SIZE); -} - -// Aggiunge un campo non posizionale ai record di tipo E,F,G,H,J -bool TRecord770::np_put(const char* code, const char* val) -{ - CHECK(ha_campi_non_posizionali(), "Impossibile aggiungere campi non posizionali"); - CHECKS(code && strlen(code) == CODE_SIZE, "Invalid field code ", code); - CHECKS(val && *val, "Can't add empty field ", code); - - // Cerca il primo posto libero - int pos; - for (pos = HEADER_SIZE; pos < HEADER_SIZE+USEABLE_SIZE; pos += BLOCK_SIZE) - { - if (_buffer[pos] == ' ') - break; - } - const int free_blocks = (USEABLE_SIZE - pos) / BLOCK_SIZE; - const int needed_blocks = calculate_blocks(val); - const bool ok = free_blocks >= needed_blocks; - - if (ok) // Se ci sono abbastanza blocchi liberi - { - TString80 str(val); str.upper(); - const int lenstr = str.len(); - for (int i = 0; i < lenstr; ) - { - _buffer.overwrite(code, pos); - pos += CODE_SIZE; - int maxlen = FIELD_SIZE; - if (i > 0) - { - _buffer.overwrite("+", pos); - pos++; - maxlen--; - } - const TString& substr = str.mid(i, maxlen); - _buffer.overwrite(substr, pos); - pos += maxlen; - i += maxlen; - } - } - return ok; -} - -bool TRecord770::np_put(const char* code, long val) -{ - TString16 str; str.format("%16ld", val); - return np_put(code, str); -} - -bool TRecord770::np_put(const char* code, const real& val) -{ - const TString& str = val.stringa(16, 2); - return np_put(code, str); -} - -bool TRecord770::np_get(int pos, TString& key, TString& val) const -{ - CHECK(ha_campi_non_posizionali(), "Impossibile leggere campi non posizionali"); - const int n = HEADER_SIZE + pos * BLOCK_SIZE; - bool ok = false; - if (n < HEADER_SIZE + USEABLE_SIZE) - { - ok = _buffer[n] > ' '; - if (ok) - { - key = _buffer.mid(n, CODE_SIZE); - val = _buffer.mid(n+CODE_SIZE, FIELD_SIZE); - } - } - return ok; -} - -bool TRecord770::np_get_real(int pos, TString& key, real& val) const -{ - TString16 str; - const bool ok = np_get(pos, key, str); - if (ok && str.full()) - { - str.replace(',', '.'); - val = real(str); - } - else - val = ZERO; - return ok; -} - -bool TRecord770::valid() const -{ - const char tipo = tipo_record(); - const bool ok = (tipo > ' ') && (strchr("ABEHJZ", tipo) != NULL); - return ok; -} - -TRecord770::TRecord770() : _buffer(TOTAL_SIZE, ' ') -{ -} - -TRecord770::TRecord770(char tipo) : _buffer(TOTAL_SIZE, ' ') -{ - tipo_record(tipo); -} - -TRecord770::TRecord770(const TRecord770& rec) : _buffer(rec._buffer) -{ } - -TRecord770::~TRecord770() -{ } - /////////////////////////////////////////////////////////// // TTrasferimento770 /////////////////////////////////////////////////////////// @@ -1480,7 +789,32 @@ bool TTrasferimento770::append_record_b() return ok; } -long TTrasferimento770::append_quadro(const char* quadro, long codditta, TProgind& pi) +// Determina a partire dal codice quadro (LA o ST) il tipo record (H o E) ed il numero di record per modulo (1 o 12) +// Ritorna il form da cui prelevare i codici (come AUXXX010) da inserire nei tracciati +TForm770& TTrasferimento770::form(const char* quadro, char& tiporec, int& rpm) +{ + CHECK(quadro && *quadro != '\0' && quadro[1] != '\0', + "Codice quadro non valido"); + + const char* name = NULL; + switch(quadro[1]) + { + case 'A': name = "77qla"; tiporec = 'H'; rpm = 1; break; + case 'T': name = "77qst"; tiporec = 'E'; rpm = 12; break; + default : name = NULL; break; + } + + TForm770* frm = (TForm770*)_form.objptr(name); + if (frm == NULL) + { + frm = new TForm770(name); + _form.add(name, frm); + } + + return *frm; +} + +long TTrasferimento770::append_quadro(const char* quadro, long codditta, TProgress_monitor& pi) { TString str; str << TR("Trasferimento quadro ") << quadro << TR(" ditta ") << codditta; @@ -1488,7 +822,7 @@ long TTrasferimento770::append_quadro(const char* quadro, long codditta, TProgin char tipo; int rpm; - TForm770& frm = _trc770.form(quadro, tipo, rpm); + TForm770& frm = form(quadro, tipo, rpm); long items = frm.trasfer(codditta, *this, tipo, rpm); return items; } @@ -1704,7 +1038,7 @@ void TTrasferimento770::remove() } TTrasferimento770::TTrasferimento770(const char* path, char mode, int volume) -: _in_stream(NULL), _out_stream(NULL), _save_headers(false) +: _in_stream(NULL), _out_stream(NULL), _save_headers(false), _centesimi(false) { open(path, mode, volume); } @@ -1748,7 +1082,7 @@ bool TTransfer770_msk::on_field_event(TOperable_field& of, TField_event fe, long TTransfer770_msk::TTransfer770_msk() : TAutomask("777100a") { /* - int anno = ini_get_int(CONFIG_STUDIO, "77", "AnnoDic"); + int anno = ini_get_int(CONFIG_STUDIO, "77", ANNO_SEL); if (anno <= 0) { const TDate oggi(TODAY); @@ -1774,7 +1108,7 @@ void TTransfer770_app::main_loop() TFilename tmp; tmp.tempdir(); TTrasferimento770 t(tmp, 'w'); t.save_headers(m.get_bool(F_HEADERS)); - _trc770.set_cent_mode(m.get_bool(F_CENT)); + t.set_cent_mode(m.get_bool(F_CENT)); TRelation rel_base(LF_BASE); TRectype da_rec(LF_BASE), a_rec(LF_BASE); @@ -1790,25 +1124,23 @@ void TTransfer770_app::main_loop() const TRecnotype items = cur_base.items(); cur_base.freeze(); - TProgind pi(items, TR("Generazione file di trasferimento"), false, true); - for (cur_base = 0; cur_base.ok(); ++cur_base) + if (items > 0) { - const TRectype& base = cur_base.curr(); - const long codditta = base.get_long(BSE_CODDITTA); - pi.addstatus(1); - t.read_codfis_dic(base); + TProgress_monitor pi(items, TR("Generazione file di trasferimento")); + for (cur_base = 0; cur_base.ok(); ++cur_base) + { + const TRectype& base = cur_base.curr(); + const long codditta = base.get_long(BSE_CODDITTA); + pi.addstatus(1); + t.read_codfis_dic(base); - t.append_record_b(); - t.append_quadro("ST", codditta, pi); - t.append_quadro("LA", codditta, pi); + t.append_record_b(); + t.append_quadro("ST", codditta, pi); + t.append_quadro("LA", codditta, pi); + } } - pi.close_modal(); - - if (m.get(F_SUPPORTO) == "D") - tmp = m.get(F_DISK); - else - tmp = m.get(F_PATH); + tmp = m.get(F_PATH); if (t.split(tmp)) { tmp.add(t.default_name()); @@ -1822,13 +1154,11 @@ void TTransfer770_app::main_loop() } t.remove(); } - - _trc770.destroy(); } int m777100(int argc, char* argv[]) { TTransfer770_app app; - app.run(argc, argv, "Invio"); + app.run(argc, argv, TR("Invio 770")); return 0; } diff --git a/m770/777100a.h b/m770/777100a.h index 3d5366bd7..6d44d1914 100755 --- a/m770/777100a.h +++ b/m770/777100a.h @@ -1,6 +1,4 @@ -#define F_SUPPORTO 101 #define F_PATH 102 -#define F_DISK 103 #define F_ANNO 104 #define F_DADITTA 105 #define F_DADESC 106 diff --git a/m770/777100a.uml b/m770/777100a.uml index 414dcdd5c..4b126d425 100755 --- a/m770/777100a.uml +++ b/m770/777100a.uml @@ -1,37 +1,23 @@ #include "777100a.h" -PAGE "Invio" -1 -1 72 10 +PAGE "Invio 770" -1 -1 72 8 NUMBER F_ANNO 4 BEGIN - PROMPT 47 2 "Anno dichiarazione " + PROMPT 47 1 "Anno dichiarazione " FLAGS "D" END -RADIOBUTTON F_SUPPORTO 1 16 +STRING F_PATH 260 53 BEGIN - PROMPT 1 1 "Tipo" - ITEM "T|Telematico" - MESSAGE SHOW,F_PATH|HIDE,F_DISK - ITEM "D|Dischetti" - MESSAGE HIDE,F_PATH|SHOW,F_DISK -END - -LIST F_DISK 2 8 -BEGIN - PROMPT 20 2 "" - ITEM "A:|Disco A" - ITEM "B:|Disco B" -END - -STRING F_PATH 50 -BEGIN - PROMPT 20 3 "" + PROMPT 1 2 "Destinazione " + DSELECT + CHECTYPE REQUIRED END NUMBER F_DADITTA 5 BEGIN - PROMPT 1 5 "Da ditta " + PROMPT 1 3 "Da ditta " USE LF_BASE JOIN LF_NDITTE INTO CODDITTA=CODDITTA INPUT CODDITTA F_DADITTA @@ -40,18 +26,18 @@ BEGIN DISPLAY "Ragione sociale@50" LF_NDITTE->RAGSOC OUTPUT F_DADITTA CODDITTA OUTPUT F_DADESC LF_NDITTE->RAGSOC - CHECKTYPE SEARCH + CHECKTYPE NORMAL END STRING F_DADESC 50 BEGIN - PROMPT 20 5 "" + PROMPT 20 3 "" FLAGS "D" END NUMBER F_ADITTA 5 BEGIN - PROMPT 1 6 "A ditta " + PROMPT 1 4 "A ditta " COPY USE F_DADITTA INPUT CODDITTA F_ADITTA COPY DISPLAY F_DADITTA @@ -64,18 +50,19 @@ END STRING F_ADESC 50 BEGIN - PROMPT 20 6 "" + PROMPT 20 4 "" FLAGS "D" END BOOLEAN F_HEADERS BEGIN - PROMPT 1 8 "Genera record di testata (tipo A, B, Z)" + PROMPT 1 6 "Genera record di testata (tipo A, B, Z)" END BOOLEAN F_CENT BEGIN - PROMPT 1 9 "Salva importi in centesimi (x 100)" + PROMPT 1 7 "Salva importi in centesimi (x 100)" + FLAGS "H" END diff --git a/m770/777200.cpp b/m770/777200.cpp index 03a85b4a4..4757fae60 100755 --- a/m770/777200.cpp +++ b/m770/777200.cpp @@ -1,813 +1,999 @@ -#include -#include -#include -#include -#include - -#include "777.h" -#include "777100a.h" - -#include -#include -#include -#include -#include -#include "base.h" -#include "quadroc.h" - -/////////////////////////////////////////////////////////// -// Dichiarazioni -/////////////////////////////////////////////////////////// - -HIDDEN int anno_dic() -{ - static int anno = 0; - if (anno == 0) - { - TConfig ini(CONFIG_STUDIO, "77"); - anno = ini.get_int("AnnoDic"); - } - return anno; -} - -/////////////////////////////////////////////////////////// -// TFormDylog -/////////////////////////////////////////////////////////// - -class TRecordDylog; -class TTrasferimentoDylog; - -class TFormDylog : public TForm -{ - TCursor* _sortedcur; - - int _index; - TArray _records; - TPointer_array _positions; - -protected: - bool compatible(const TRectype& r1, const TRectype& r2); - void add_rec(TRectype& r1, const TRectype& r2); - - long raggruppa_c(); - int first(); - int next(); - - void transfer_section(TPrint_section& body, TRecordDylog& rec, - TTrasferimentoDylog& file, int extra_offset = 0); - char log2rec(int num, int& rpm) const; - -protected: - - virtual TCursor* cursor() { return _sortedcur ? _sortedcur : TForm::cursor(); } - -public: - long trasfer(long codditta, TTrasferimentoDylog& file, const char* tipo); - - TFormDylog(const char* name); - virtual ~TFormDylog(); -}; - -/////////////////////////////////////////////////////////// -// TTracciatiDylog -/////////////////////////////////////////////////////////// - -class TTracciatiDylog : public TObject -{ - TAssoc_array _form; - -public: - TFormDylog& form(const char* quadro); - - void destroy(); - - TTracciatiDylog(); - virtual ~TTracciatiDylog(); -} _trcDylog; - - -/////////////////////////////////////////////////////////// -// TRecordDylog -/////////////////////////////////////////////////////////// - -const int REC_SIZE = 940; // Lunghezza intero record -const int HDR_SIZE = 35; // Lunghezza testata record - -class TRecordDylog : public TObject -{ - TString _buffer; - -protected: // TObject - virtual TObject* dup() const { return new TRecordDylog(*this); } - virtual void print_on(ostream& outs) const; - virtual void read_from(istream& ins); - -public: - void set(const char* val, char tipo, int pos, int len); - - const TRecordDylog& operator=(const TRecordDylog& rec) - { _buffer = rec._buffer; return *this; } - - void tipo_record(const char* tipo); - - bool valid() const; - - TRecordDylog(); - TRecordDylog(const char* tipo, const char* cfdich); - TRecordDylog(const TRecordDylog& rec); - virtual ~TRecordDylog(); -}; - -/////////////////////////////////////////////////////////// -// TTrasferimentoDylog -/////////////////////////////////////////////////////////// - -class TTrasferimentoDylog : public TObject -{ - TFilename _name; - ifstream* _in_stream; - ofstream* _out_stream; - - TString16 _defname; - -public: - bool open(const char* path = "", char mode = 'r'); - bool close(); - bool write(const TRecordDylog& rec); - bool read(TRecordDylog& rec); - bool eof() const { return _in_stream && _in_stream->eof(); } - - virtual bool ok() const; - - const TString& default_name(); - - TTrasferimentoDylog& operator<<(const TRecordDylog& rec) - { write(rec); return *this; } - TTrasferimentoDylog& operator>>(TRecordDylog& rec) - { read(rec); return *this; } - - long append_quadro(const char* quadro, long codditta, TProgind& pi); - - bool split(const char* dest_path); - void remove(); - - TTrasferimentoDylog(const char* name = "", char mode = 'r'); - virtual ~TTrasferimentoDylog(); -}; - -/////////////////////////////////////////////////////////// -// Implementazioni -/////////////////////////////////////////////////////////// - -/////////////////////////////////////////////////////////// -// TFormDylog -/////////////////////////////////////////////////////////// - -void TFormDylog::transfer_section(TPrint_section& body, TRecordDylog& rec, - TTrasferimentoDylog& file, int extra_offset) -{ - TToken_string trc(32, ','); - TString80 str; - -// body.update(); // Per un errore sui form 1.4 lo faccio io a mano - body.reset(); - for (word i = 0; i < body.fields(); i++) - { - TForm_item& fi = body.field(i); - if (fi.enabled()) - fi.update(); - } - - for (word f = 0; f < body.fields(); f++) - { - TForm_item& fi = body.field(f); - str = fi.get(); str.trim(); - if (fi.shown() && fi.enabled()) - { - trc = fi.get_special_value("DYLOG"); - if (trc.not_empty()) - { - const char tipo = trc[0]; - const int pos = trc.get_int(1); - const int len = trc.get_int(); - rec.set(str, tipo, pos + HDR_SIZE + extra_offset, len); - } - } - } -} - -// Obsoleto -bool TFormDylog::compatible(const TRectype& r1, const TRectype& r2) -{ - if (r1.empty() || r2.empty()) - return TRUE; - - if (r1.get_long(QUC_CODDITTA) != r2.get_long(QUC_CODDITTA)) - return FALSE; - if (r1.get_char(QUC_TIPOA) != r2.get_char(QUC_TIPOA)) - return FALSE; - if (r1.get_long(QUC_CODANAGR) != r2.get_long(QUC_CODANAGR)) - return FALSE; - if (r1.get_char(QUC_CAUSALE) != r2.get_char(QUC_CAUSALE)) - return FALSE; - if (r1.get_int(QUC_TASSAZIONE) != r2.get_int(QUC_TASSAZIONE)) - return FALSE; - - const real p1 = r1.get_real(QUC_PERC); - const real p2 = r2.get_real(QUC_PERC); - bool yes = (p1 == ZERO && p2 != ZERO) || (p1 == p2); - return yes; -} - -void TFormDylog::add_rec(TRectype& r1, const TRectype& r2) -{ - if (r1.empty()) - r1 = r2; - else - { - for (int f = r1.items()-1; f >= 0; f--) - { - const char* name = r1.fieldname(f); - if (r1.type(name) == _realfld) - { - real val = r1.get_real(name); - val += r2.get_real(name); - r1.put(name, val); - } - } - r1.put(QUC_PERC, r2.get(QUC_PERC)); - } -} - -// Obsoleto -long TFormDylog::raggruppa_c() -{ - TCursor& cur = *cursor(); - TRectype& rc = cur.curr(); - _records.destroy(); - for (cur = 0; cur.ok(); ++cur) - { - bool append = TRUE; - const int last = _records.items()-1; - if (last >= 0) - { - TRectype& sum = (TRectype&)_records[last]; - if (compatible(sum, rc)) - { - add_rec(sum, rc); - append = FALSE; - } - } - if (append) - { - _records.add(rc); - _positions.add_long(cur.pos()+1); - } - } - - return _records.items(); -} - -int TFormDylog::first() -{ - TCursor& cur = *cursor(); - - cur = 0; - bool ok = cur.ok(); - - if (cur.file().num() == LF_QUAC) // Obsoleto - { - if (ok) - { - raggruppa_c(); - _index = 0; - cur.curr() = (TRectype&)_records[0]; - } - } - - return ok ? NOERR : _iseof; -} - -int TFormDylog::next() -{ - TCursor& cur = *cursor(); - - bool ok; - if (cur.file().num() == LF_QUAC) // Obsoleto - { - _index++; - ok = _index < _records.items(); - if (ok) - { - cur = _positions.get_long(_index) - 1; - cur.curr() = (TRectype&)_records[_index]; - } - } - else - { - ++cur; - ok = cur.ok(); - } - - return ok ? NOERR : _iseof; -} - - -long TFormDylog::trasfer(long codditta, TTrasferimentoDylog& file, const char* tipo) -{ - TCursor& cur = *cursor(); - - // Filtra il cursore sulla ditta corrente - TRectype filter(cur.curr()); - filter.zero(); - filter.put(BSE_CODDITTA, codditta); - cur.setregion(filter, filter); - - const TRectype& ditta = cache().get(LF_NDITTE, codditta); - TString16 codanagr; codanagr << ditta.get_char(NDT_TIPOA) << '|' << ditta.get_long(NDT_CODANAGR); - const TRectype& pers = cache().get(LF_ANAG, codanagr); - const TString16 cfdich = pers.get(ANA_COFI); - - const char* td = NULL; - switch (tipo[1]) - { - case 'A': td = "AU"; break; - case 'T': td = "T0"; break; - default : break; - } - - const long items = cur.items(); - if (items > 0) // Se c'e almeno un record ... - { - cur.freeze(TRUE); // Per efficienza congela il cursore - - TPrint_section& body = section('B', odd_page); - - for (int err = first(); err == NOERR; err = next()) - { - // Inizializza record col primo modulo - TRecordDylog rec(td, cfdich); - transfer_section(body, rec, file); - - // Il quadro ST contiene un array di 3 sotto-record da azzerare per la Dylog! - if (stricmp(td, "T0") == 0) - { - cur.curr().zero(); - for (int i = 1; i < 3; i++) - transfer_section(body, rec, file, i*91); - } - - file << rec; - } - - cur.freeze(FALSE); - } - - return items; -} - -TFormDylog::TFormDylog(const char* name) -: TForm(name), _sortedcur(NULL) -{ - const char* key = NULL; - - switch (TForm::cursor()->file().num()) - { - case LF_QUALA: key = "CODDITTA|216@->RAGSOC|TIPOA|CODANAGR"; break; - default : break; - } - if (key) - _sortedcur = new TSorted_cursor(TForm::relation(), key); -} - -TFormDylog::~TFormDylog() -{ - if (_sortedcur) - delete _sortedcur; -} - -/////////////////////////////////////////////////////////// -// TTracciatiDylog -/////////////////////////////////////////////////////////// - -TFormDylog& TTracciatiDylog::form(const char* quadro) -{ - CHECK(quadro && *quadro != '\0' && quadro[1] != '\0', "Codice quadro non valido"); - - const char* name; - switch(quadro[1]) - { - case 'A': name = "77qla"; break; - case 'T': name = "77qst"; break; - default : name = NULL; break; - } - - TFormDylog* frm = (TFormDylog*)_form.objptr(name); - if (frm == NULL) - { - frm = new TFormDylog(name); - _form.add(name, frm); - } - - return *frm; -} - -void TTracciatiDylog::destroy() -{ - _form.destroy(); -} - -TTracciatiDylog::TTracciatiDylog() -{ -} - -TTracciatiDylog::~TTracciatiDylog() -{ - destroy(); // Non viene mai chiamato! -} - -/////////////////////////////////////////////////////////// -// TRecordDylog -/////////////////////////////////////////////////////////// - -void TRecordDylog::print_on(ostream& outs) const -{ - outs.write(_buffer, _buffer.size()); -} - -void TRecordDylog::read_from(istream& ins) -{ - ins.read(_buffer.get_buffer(), _buffer.size()); -} - -void TRecordDylog::set(const char* val, char tipo, int pos, int len) -{ - TString80 str(val); str.upper(); - int lenstr = str.len(); - - if (tipo == 'N') - { - // Controlla date - if (len == 8 && lenstr == 10 && str[2] == '-' && str[5] == '-') - { - int aaaa, mm, gg; - sscanf(str, "%d-%d-%d", &gg, &mm, &aaaa); - str.format("%02d%02d%04d", gg, mm, aaaa); - lenstr = 8; - } else - // Controlla numeri reali - if (len == 11) - { - const int point = str.find('.'); - if (point >= 0) - str.cut(lenstr = point); - if (real::is_null(str)) - { - str = "0"; - lenstr = 1; - } - } else - // Controlla booleani - if (len == 1 && lenstr <= 1 && (str[0] == 'X' || str[0] <= ' ')) - { - str = str[0] == 'X' ? "1" : "0"; - lenstr = 1; - } - } - - if (lenstr > len) - { -#ifdef DBG - if (tipo == 'N') - NFCHECK("Campo troppo lungo: %s (max. %d)", val, len); -#endif - str.cut(lenstr = len); - } - if (lenstr != len) - { - if (tipo == 'N') - str.right_just(len, '0'); - else - str.left_just(len); - } - _buffer.overwrite(str, pos); -} - -bool TRecordDylog::valid() const -{ - if (_buffer[0] != 'P') - return FALSE; - - if (_buffer[1] == ' ' || _buffer[2] == ' ') - return FALSE; - - return TRUE; -} - -void TRecordDylog::tipo_record(const char* tipo) -{ - _buffer.spaces(REC_SIZE); - _buffer[0] = 'P'; // Linea Prassi - if (tipo && *tipo) - { - _buffer[1] = tipo[0]; - _buffer[2] = tipo[1]; - } -} - -TRecordDylog::TRecordDylog() -{ - tipo_record(NULL); -} - -TRecordDylog::TRecordDylog(const char* tipo, const char* cf) -{ - tipo_record(tipo); - if (cf && *cf) - set(cf, 'A', 3, 16); // Codice fiscale dichiarante -} - -TRecordDylog::TRecordDylog(const TRecordDylog& rec) : _buffer(rec._buffer) -{ } - -TRecordDylog::~TRecordDylog() -{ } - -/////////////////////////////////////////////////////////// -// TTrasferimentoDylog -/////////////////////////////////////////////////////////// - -const TString& TTrasferimentoDylog::default_name() -{ - if (_defname.empty()) - { - const int anno = anno_dic()+1; - _defname.format("TRA7%02d", anno % 100); - } - return _defname; -} - -bool TTrasferimentoDylog::open(const char* path, char mode) -{ - CHECK(mode == 'r' || mode == 'w', "Invalid open mode"); - close(); - - if (path && *path) - { - _name = path; - _name.add(default_name()); - } - if (_name.empty()) - _name = default_name(); - if (mode == 'r') - _in_stream = new ifstream(_name, ios::in | ios::binary); - else - _out_stream = new ofstream(_name, ios::out | ios::binary); - - return TRUE; -} - -bool TTrasferimentoDylog::ok() const -{ - if (_in_stream) - return _in_stream->good() != 0; - - if (_out_stream) - return _out_stream->good() != 0; - - return FALSE; -} - -bool TTrasferimentoDylog::close() -{ - if (_in_stream) - { - delete _in_stream; - _in_stream = NULL; - } - if (_out_stream) - { - delete _out_stream; - _out_stream = NULL; - } - return TRUE; -} - -bool TTrasferimentoDylog::write(const TRecordDylog& rec) -{ - bool ok = _out_stream != NULL; - if (ok) - (*_out_stream) << rec; - return ok; -} - -bool TTrasferimentoDylog::read(TRecordDylog& rec) -{ - bool ok = _in_stream != NULL && !_in_stream->eof(); - if (ok) - { - rec.tipo_record(NULL); // Invalida il record - (*_in_stream) >> rec; - ok = rec.valid(); - } - return ok; -} - -long TTrasferimentoDylog::append_quadro(const char* quadro, long codditta, - TProgind& pi) -{ - TString str; - str << "Trasferimento quadro " << quadro << " ditta " << codditta; - pi.set_text(str); - - TFormDylog& frm = _trcDylog.form(quadro); - long items = frm.trasfer(codditta, *this, quadro); - return items; -} - -bool TTrasferimentoDylog::split(const char* path) -{ - close(); - - long records = 0; - - TRecordDylog rec; - - long records_per_disk = 0; - int volumes = 1; - const bool magnetic = ::xvt_fsys_is_removable_drive(path) != 0; - if (magnetic) - { - if (!yesno_box("Inserire il primo disco del trasferimento nell'unita' %s\n" - "Tutti i dischi devono essere vuoti ed avere la stesso formato.\n" - "Si desidera iniziare il trasferimento?", path)) - return FALSE; - - unsigned long disk_size = ::xvt_fsys_get_disk_size(path, 'b') != 0; - records_per_disk = long(disk_size / REC_SIZE - 2); - volumes = int((records-1)/records_per_disk)+1; - } - - TProgind pi(records, "Trasferimento records", FALSE, TRUE); - - // Read from start - open("", 'r'); - - for (int volume = 1; volume <= volumes; volume++) - { - if (magnetic && volume > 1) - { - if (!yesno_box("Inserire il disco %d di %d:\n" - "Si desidera proseguire il trasferimento?", - volume, volumes)) - { - break; - } - } - - TTrasferimentoDylog outfile(path, 'w'); - while (!outfile.ok()) - { - if (magnetic) - { - if (yesno_box("Errore di scrittura in %s\n" - "Si desidera ritentare?", (const char*)path)) - outfile.open(path, 'w'); - else - break; - } - else - { - error_box("Errore di scrittura in %s", (const char*)path); - break; - } - } - - // Azzera totali - long written = 0; - - while (read(rec)) - { - outfile << rec; - written++; - pi.addstatus(1); - - if (magnetic && written >= records_per_disk) - break; - } - } - return TRUE; -} - -// Cancella il file -void TTrasferimentoDylog::remove() -{ - close(); - ::remove(_name); -} - -TTrasferimentoDylog::TTrasferimentoDylog(const char* path, char mode) -: _in_stream(NULL), _out_stream(NULL) -{ - open(path, mode); -} - -TTrasferimentoDylog::~TTrasferimentoDylog() -{ - close(); -} - -/////////////////////////////////////////////////////////// -// main -/////////////////////////////////////////////////////////// - -class TTransferDylog_msk : public TAutomask -{ -protected: - virtual bool on_field_event(TOperable_field& of, TField_event fe, long jolly); - -public: - TTransferDylog_msk(); - virtual ~TTransferDylog_msk() { } -}; - -bool TTransferDylog_msk::on_field_event(TOperable_field& of, TField_event fe, long jolly) -{ - switch (of.dlg()) - { - case F_PATH: - if (fe == fe_modify || fe == fe_close) - { - TFilename name = of.get(); - if (!name.exist()) - return error_box("Il percorso non e' valido"); - } - break; - default: - break; - } - return TRUE; -} - -TTransferDylog_msk::TTransferDylog_msk() : TAutomask("777100a") -{ - set(F_ANNO, anno_dic()); -} - -class TTransferDylog_app : public TSkeleton_application -{ -protected: - virtual void main_loop(); -}; - -void TTransferDylog_app::main_loop() -{ - TTransferDylog_msk m; - - while (m.run() == K_ENTER) - { - TFilename tmp; tmp.tempdir(); - TTrasferimentoDylog t(tmp, 'w'); - TRecordDylog rec; - - TRelation rel_base(LF_BASE); - TRectype da_rec(LF_BASE), a_rec(LF_BASE); - da_rec.put(BSE_CODDITTA, m.get(F_DADITTA)); - a_rec.put(BSE_CODDITTA, m.get(F_ADITTA)); - - TCursor cur_base(&rel_base, "", 1, &da_rec, &a_rec); - - TProgind pi(cur_base.items(), "Generazione file di trasferimento", FALSE, TRUE); - cur_base.freeze(); - for (cur_base = 0; cur_base.ok(); ++cur_base) - { - pi.addstatus(1); - const TRectype& base = cur_base.curr(); - const long codditta = base.get_long(BSE_CODDITTA); - if (codditta > 0) // Strano, ma puo' succedere - { - t.append_quadro("LA", codditta, pi); - t.append_quadro("ST", codditta, pi); - } - } - pi.close_modal(); - - if (m.get(F_SUPPORTO) == "D") - tmp = m.get(F_DISK); - else - tmp = m.get(F_PATH); - - t.split(tmp); - t.remove(); - } - - _trcDylog.destroy(); -} - -int m777200(int argc, char* argv[]) -{ - TTransferDylog_app app; - app.run(argc, argv, "Invio Dylog"); - return 0; -} - +#include +#include +#include +#include +#include +#include + +#include "777.h" +#include "777lib.h" +#include "777200a.h" + +#include "777200.h" +#include "../fe/felib.h" + +#include +#include +#include +#include +#include +#include +#include "base.h" +#include "quadroc.h" + +/////////////////////////////////////////////////////////// +// Utilities +/////////////////////////////////////////////////////////// + +// Forma un numero di telefono composto di sole cifre da prefisso+numero +const TString& get_telephone(const TRectype& rec, const char* pref, const char* numf) +{ + TString& num = get_tmp_string(); + num << rec.get(pref) << rec.get(numf); + char* dst = num.get_buffer(); + for (const char* src = dst; *src; src++) + { + if (*src >= '0' && *src <= '9') + { + if (src > dst) + *dst = *src; + dst++; + } + } + *dst = '\0'; + return num; +} + +/////////////////////////////////////////////////////////// +// TTracciatoCU +/////////////////////////////////////////////////////////// + +const char* cu_default_name() { return "MODCUR15"; } + +class TTracciatoCU : public TTracciato770 +{ +public: + TTracciatoCU(char tipo); +}; + +TTracciatoCU::TTracciatoCU(char tipo) +{ + if (strchr("ABCDHZ", tipo) == NULL) + NFCHECK("Tipo record non valido: %c", tipo); + set_tipo(tipo); + + add_field("Tipo record", AN, 1, 1); // 1 + + if (tipo == 'A') + { + add_filler(2, 14); // 2 + add_field("Codice fornitura", AN, 16, 5); // 3 + add_field("Tipo fornitore", NU, 21, 2); // 4 + add_field("Codice fiscale del fornitore", CF, 23, 16); + } else + if (tipo == 'B') + { + add_field("Codice fiscale dichiarante", CF, 2, 16); // 2 + add_field("Progressivo modulo", NU, 18, 8); + add_filler( 26, 1); + add_filler( 27, 8); + add_filler( 35, 25); + add_field("Spazio a disposizione", AN, 60, 14); // 7 + add_field("CF del produttore del software", CF, 74, 16); + add_filler( 90, 1); + + // Tipo di dichiarazione + add_field("Annullamento", CB, 91, 1); // 10 + add_field("Sostituzione", CB, 92, 1); + + // Dati del contribuente + add_field("Cognome", AN, 93, 24); // 12 + add_field("Nome", AN,117, 20); + add_field("Denominazione (Alternativo a 12 e 13)",AN,137, 60); + add_field("Indirizzo E-mail", AN,197,100); + add_field("Telefono o Cellulare", AN,297, 12); + add_field("FAX", AN,309, 12); // 17 + + add_field("Codice fiscale del rappresentante", CF,321,16); // 18 + add_field("Codice carica del rappresentante", NU,337, 2); + add_field("Cognome", AN,339,24); + add_field("Nome", AN,363,20); + add_field("Codice fiscale del dichiarante", CN,383,11); + + add_field("Numero comunicaz. lavoro dipendente", NU, 394, 8); // 23 + add_field("Numero comunicaz. lavoro autonomo", NU, 402, 8); + add_field("Casella quadro CT", CB, 410, 1); + add_field("Firma del dichiarante", CB, 411, 1); + + add_field("Codice fiscale intermediario", CF, 412,16); // 27 + add_field("Impegno a trasmettere la dichiaraz.", NU, 428, 1); + add_field("Data dell'impegno", DT, 429, 8); + add_field("Firma dell'intermediario", CB, 437, 1); + add_filler(438, 1); + add_field("Comune di Residenza", AN, 439,40); // 32 + add_field("Provincia di Residenza", PR, 479, 2); + add_field("CAP di Residenza", NU, 481, 5); + add_field("Indirizzo di Residenza", AN, 486,35); + add_field("Codice Attivitą", NU, 521, 6); + add_field("Codice Sede", NU, 527, 3); + } else + if (tipo == 'D') + { + add_field("Codice fiscale del sostituto", CF, 2, 16); // 2 + add_field("Progressivo modulo", NU, 18, 8); // 3 + add_field("Codice fiscale percipiente", CF, 26, 16); // 4 + add_field("Progressivo certificazione", NU, 42, 5); // 5 + add_field("Identificativo dell'invio", NU, 47, 17); // 6 + add_field("Progressivo singola C.U.", NU, 64, 6); // 7 + add_field("Tipo Operazione", AN, 84, 1, 9); // 9 + add_filler(85, 4); + add_field("Conferma singola certificazione", CB, 89, 1); // 11 + } else + if (tipo == 'H') + { + add_field("Codice fiscale del sostituto", CF, 2, 16); // 2 + add_field("Progressivo modulo", NU, 18, 8); // 3 + add_field("Codice fiscale percipiente", CF, 26, 16); // 4 + add_field("Progressivo certificazione", NU, 42, 5); // 5 + } else + if (tipo == 'Z') + { + add_filler(2, 14); + add_field("Numero record di tipo 'B'", NU, 16, 9); // 3 + add_field("Numero record di tipo 'C'", NU, 25, 9); + add_field("Numero record di tipo 'D'", NU, 34, 9); + add_field("Numero record di tipo 'G'", NU, 43, 9); // 6 + add_field("Numero record di tipo 'H'", NU, 52, 9); + } +} + +/////////////////////////////////////////////////////////// +// TTracciatiCU +/////////////////////////////////////////////////////////// + +class TTracciatiCU : public TObject +{ + TArray _trc; +public: + const TTracciato770& tracciato(char tipo); +} _trcCU; + +const TTracciato770& TTracciatiCU::tracciato(char tipo) +{ + CHECK(tipo >= 'A' && tipo <= 'Z', "Tipo record non valido"); + const int pos = tipo - 'A'; + TTracciatoCU* trc = (TTracciatoCU*)_trc.objptr(pos); + if (trc == NULL) + { + trc = new TTracciatoCU(tipo); + _trc.add(trc, pos); + } + return *trc; +} + +class TRecordCU : public TRecord770 +{ +private: + virtual TObject* dup() const { return new TRecordCU(*this); } + +protected: + virtual const TTracciato770& tracciato() const + { return _trcCU.tracciato(tipo_record()); } + +public: + virtual bool valid() const + { + const char tipo = tipo_record(); + return (tipo > ' ') && (strchr("ABCDGHZ", tipo) != NULL); + } + + virtual bool ha_campi_non_posizionali() const { return strchr("DGH", tipo_record()) != NULL; } + bool ha_campo_posizionale(int fld) const { return tracciato().exists(fld); } + + TRecordCU() { } + TRecordCU(const TRecordCU& rec) : TRecord770(rec) { } + TRecordCU(char tipo) { tipo_record(tipo); } +}; + +/////////////////////////////////////////////////////////// +// TTrasferimentoCU +/////////////////////////////////////////////////////////// + +const TVariant& TTrasferimentoCU::get_var(const char* name) const +{ + if (_cur_pos >= 0 && _cur_pos < items()) + { + const TRecordCU& cur_rec = (const TRecordCU&)_data[_cur_pos]; + const TFixed_string varname(name+1); + if (real::is_natural(varname)) + { + const int n = atoi(varname); + if (n > 0 && cur_rec.ha_campo_posizionale(n)) + { + TVariant& var = get_tmp_var(); + switch (column_info(n-1)._type) + { + case _nullfld: + break; + case _boolfld: + { + TString4 str; cur_rec.get(n, str); + var = str == "1" || str == "X"; + } + break; + case _datefld: + { + TString8 str; cur_rec.get(n, str); + if (str.full() && str != "00000000") + var = str; + } + break; + case _realfld: + { + TString80 str; cur_rec.get(n, str); + var = real(str); + } + break; + default: + { + TString256 str; cur_rec.get(n, str); + var = str; + } + break; + } + return var; + } + } + else + { + if (cur_rec.ha_campi_non_posizionali_compilati()) + { + TString80 str; + TString8 key; + TString16 val; + for (int p = 0; cur_rec.np_get(p, key, val); p++) + { + if (p == 0 && key[0] != varname[0]) // Record di tipo errato! + return NULL_VARIANT; + if (key == varname) + { + str = val; + while (cur_rec.np_get(++p, key, val) && key == varname) + str << val.mid(1); + str.rtrim(); + break; + } + if (key > varname) + break; + } + return get_tmp_var() = str; + } + } + } + return NULL_VARIANT; +} + + +bool TTrasferimentoCU::load(const char* path) +{ + if (path && *path) + { + _name = path; + if (_name.find(cu_default_name()) < 0) + _name.add(cu_default_name()); + } + if (_name.empty()) + _name = cu_default_name(); + + ifstream is(_name, ios::in | ios::binary); + TRecordCU rec; + while (!is.eof()) + { + is >> rec; + if (rec.valid()) + _data.add(rec); + } + _cur_pos = _data.empty() ? 0 : -1; + return _cur_pos>=0; +} + +TTrasferimentoCU& TTrasferimentoCU::operator<<(const TRecordCU& rec) +{ + _data.add(rec); + return *this; +} + +TTrasferimentoCU& TTrasferimentoCU::operator>>(TRecordCU& rec) +{ + if (_cur_pos < items()) + rec = (const TRecordCU&)_data[_cur_pos++]; + return *this; +} + +unsigned int TTrasferimentoCU::columns() const +{ + int f = 1; + if (_cur_pos >= 0 && _cur_pos < items()) + { + const TRecordCU& cur_rec = (const TRecordCU&)_data[_cur_pos]; + f = cur_rec.campi_posizionali(); + if (cur_rec.ha_campi_non_posizionali_compilati()) + { + TString16 key, val; + for (int i = 0; cur_rec.np_get(i, key, val); i++) + f++; + } + } + return f; +} + +const TRecordset_column_info& TTrasferimentoCU::column_info(unsigned int column) const +{ + static TRecordset_column_info ci; + if (column >= 0 && column < columns()) + { + const TRecordCU& cur_rec = (const TRecordCU&)_data[_cur_pos]; + const TTracciato770& trc = _trcCU.tracciato(cur_rec.tipo_record()); + if (column < (unsigned int)trc.campi_posizionali()) + { + if (trc.exists(column+1)) + { + const TField770& fld = trc.field(column+1); + ci._name = fld._desc; + switch (fld._type) + { + case VN: + case VP: ci._type = _realfld; break; + case DT: ci._type = _datefld; break; + case CB: ci._type = _boolfld; break; + default: ci._type = (ci._name == "Filler") ? _nullfld : _alfafld; break; + } + ci._width = fld._len; + } + else + { + ci._name = "Filler"; + ci._type = _nullfld; + ci._width = 0; + } + } + else + { + TString16 key, val; + const int f = column - trc.campi_posizionali(); + cur_rec.np_get(f, key, val); + ci._name = key; + ci._type = _alfafld; + ci._width = 16; + } + } + else + { + ci._name.cut(0); + ci._type = _nullfld; + ci._width = 0; + } + return ci; +} + +const TVariant& TTrasferimentoCU::get(unsigned int column) const +{ + if (column < columns()) + { + const TRecordCU& cur_rec = (const TRecordCU&)_data[_cur_pos]; + if (column <= 0) + { + const char str[2] = { cur_rec.tipo_record(), '\0' }; + return get_tmp_var() = str; + } + else + { + if (column < (unsigned int)cur_rec.campi_posizionali()) + { + TString4 fld; fld.format("#%d", column+1); + return get_var(fld); + } + else + { + TString16 key, val; + const int f = column - cur_rec.campi_posizionali(); + cur_rec.np_get(f, key, val); + return get_tmp_var() = val; + } + } + } + return NULL_VARIANT; +} + +bool TTrasferimentoCU::set_field(int n, const TVariant& var) +{ + bool done = _data.objptr(_cur_pos) != NULL; + if (done) + { + TRecordCU& cur_rec = (TRecordCU&)_data[_cur_pos]; + done = cur_rec.ha_campo_posizionale(n); + if (done) + cur_rec.set(n, var.as_string()); + } + return done; +} + +const TString& TTrasferimentoCU::read_codfis_dic(const TRectype& rec) +{ + TToken_string key; // Stringa multiuso + + key = rec.get(BSE_CODDIC); + if (key.empty()) + key = rec.get(BSE_CODDITTA); + + const TRectype& rec_nditte = cache().get(LF_NDITTE, key); + if (rec_nditte.empty()) + { + error_box(FR("Non esiste la ditta %s"), (const char*)key); + return EMPTY_STRING; + } + _cod_ditta = atol(key); + _tipoa_dic = rec_nditte.get_char(NDT_TIPOA); + _codan_dic = rec_nditte.get_long(NDT_CODANAGR); + + _codatt_dic = rec_nditte.get(NDT_CODATTPREV); // Codice attivita' prevalente + key.add(_codatt_dic); // key = CODDITTA|CODATTPREV + const TRectype& attiv = cache().get(LF_ATTIV, key); + if (attiv.exist(ATT_CODATECO)) // Non e' detto che il campo esista sempre + { + const TString& codateco = attiv.get(ATT_CODATECO); + if (codateco.full()) + _codatt_dic = codateco; + } + + key.cut(0) << _tipoa_dic; + key.add(rec_nditte.get(NDT_CODANAGR)); + const TRectype& rec_anagr = cache().get(LF_ANAG, key); + if (rec_anagr.empty()) + { + error_box(FR("Non esiste la persona %s"), (const char*)key); + return EMPTY_STRING; + } + _codfis_dic = rec_anagr.get(ANA_COFI); // Codice fiscale del dichiarante + if (_codfis_dic.len() > 11) + _codfis_dic = rec_anagr.get(ANA_PAIV); + _ragsoc_dic = rec_nditte.get(NDT_RAGSOC); // Denominazione del dichiarante + + return _codfis_dic; +} + +void TTrasferimentoCU::set_operazione(char t, const TString& iden) +{ + _tipo_operazione = (t == 'A' || t == 'S') ? t : ' '; + _certificazione = 0; + if (_tipo_operazione >= 'A') + _identificativo = iden; + else + _identificativo.cut(0); +} + + +TRecnotype TTrasferimentoCU::conta_certificazioni() const +{ + int anno = _anno; + if (anno < 2010) + anno = 2014; + + TString query; + if (_anagiu) + query.format("USE %d SELECT ANNO=%d\nFROM CODDITTA=%ld\nTO CODDITTA=%ld", + LF_QUALA, anno, _cod_ditta, _cod_ditta); + else + query.format("USE %d SELECT (ANNO=%d)&&(TIPOA=\"F\")\nFROM CODDITTA=%ld\nTO CODDITTA=%ld", + LF_QUALA, anno, _cod_ditta, _cod_ditta); + + TRecnotype nc = 0; + TISAM_recordset recset(query); + long last_cod = 0; + for (bool ok = recset.move_first(); ok; ok = recset.move_next()) + { + const long codanagr = recset.get("CODANAGR").as_int(); + if (codanagr > 0 && codanagr != last_cod) + { + nc++; + last_cod = codanagr; + } + } + CHECKD(nc <= recset.items(), "Numero certificazioni errato:", nc); + return nc; +} + +bool TTrasferimentoCU::append_record_b() +{ + if (!save_headers()) + return false; + + TRecordCU rec('B'); // Compila record di testata B + rec.set(2, cod_fis_dic()); + rec.set(3, 1); // Modulo (deve essere sempre 1) + rec.set(8, CF_PRODUTTORE); // CF del produttore Sirio + rec.set(10, _tipo_operazione == 'A'); + rec.set(11, _tipo_operazione == 'S'); + + if (_tipoa_dic == 'F') + { + rec.set(12, _ragsoc_dic.left(24)); + rec.set(13, _ragsoc_dic.mid(30,20)); + } + else + rec.set(14, _ragsoc_dic); + + const TRectype& rec_nditte = cache().get(LF_NDITTE, _cod_ditta); + rec.set(15, rec_nditte.get(NDT_MAIL)); + + TString80 numtel = get_telephone(rec_nditte, NDT_PTEL, NDT_TEL); + if (numtel.blank()) + numtel = get_telephone(rec_nditte, NDT_PFAX, NDT_FAX); + rec.set(16, numtel); + + const TAnagrafica rapp(LF_ANAG, 'F', rec_nditte.get_long(NDT_RAPPR)); + if (rapp.ok()) + { + _codfis_rap = rapp.codice_fiscale(); + rec.set(18, _codfis_rap); + rec.set(19, rec_nditte.get(NDT_CARRAPP)); + rec.set(20, rapp.cognome().left(24)); + rec.set(21, rapp.nome()); + rec.set(22, _codfis_dic); + } + else + { + _codfis_rap = _codfis_dic; + cantread_box("legale rappresentante"); + } + + rec.set(23, 0); // Dichiarazioni relative a dipendenti + rec.set(24, conta_certificazioni()); // Certificazioni per autonomi e provvigioni + rec.set(26, true); // Firma + + if (_codfis_int.full()) + { + rec.set(27, _codfis_int); + rec.set(28, 1); // Impegno alla trasmissione (1 o 2) + rec.set(29, _data_imp); // Data impegno alla trasmissione + rec.set(30, true); // Firma intermediario + } + + _data.add(rec); + return true; +} + +bool TTrasferimentoCU::append_record_d(const TRectype& qla, TLog_report& log) +{ + const char tipoanag = qla.get_char("TIPOA"); + const long codanagr = qla.get_long("CODANAGR"); + if ((tipoanag != 'F' && !_anagiu) || codanagr <= 0) + { + TString msg; msg.format(FR("Scartato percipiente non valido %c/%ld"), tipoanag, codanagr); + log.log(2, msg); + return false; + } + + const TAnagrafica perc(LF_ANAG, tipoanag, codanagr); + if (!perc.ok()) + { + TString msg; msg.format(FR("Scartato percipiente non valido %c/%ld"), tipoanag, codanagr); + log.log(2, msg); + return false; + } + + if (perc.codice_fiscale().blank()) + { + TString msg; msg.format(FR("Scartato percipiente %c/%ld senza codice fiscale"), tipoanag, codanagr); + log.log(2, msg); + return false; + } + + TRecordCU rec('D'); // Compila record percipiente D + rec.set(2, cod_fis_dic()); + rec.set(3, 1); // Modulo (deve essere sempre 1) + rec.set(4, perc.codice_fiscale()); + rec.set(5, ++_certificazione); // Progressivo certificazione + rec.set(9, _tipo_operazione); + if (_tipo_operazione >= 'A') + { + rec.set(6, _identificativo); + rec.set(7, _certificazione); + } + rec.set(11, false); // Conferma singola certificazione + + const TAnagrafica sost(LF_NDITTE, _cod_ditta); + rec.np_put("DA001001", cod_fis_dic()); + if (sost.fisica()) + { + rec.np_put("DA001002", sost.cognome()); + rec.np_put("DA001003", sost.nome()); + } + else + rec.np_put("DA001002", sost.ragione_sociale()); + + rec.np_put("DA001004", sost.comune_residenza()); + rec.np_put("DA001005", sost.provincia_residenza()); + rec.np_put("DA001006", sost.CAP_residenza()); + rec.np_put("DA001007", sost.indirizzo_residenza()); + + const TRectype& rec_nditte = cache().get(LF_NDITTE, _cod_ditta); + rec.np_put("DA001008", get_telephone(rec_nditte, NDT_PTEL, NDT_TEL)); + rec.np_put("DA001009", rec_nditte.get(NDT_MAIL)); + rec.np_put("DA001010", _codatt_dic); + // rec.np_put("DA001011", "1"); // Codice Sede ??? + + rec.np_put("DA002001", perc.codice_fiscale()); + if (perc.fisica()) + { + rec.np_put("DA002002", perc.cognome()); + rec.np_put("DA002003", perc.nome()); + rec.np_put("DA002004", perc.sesso()); + rec.np_put("DA002005", perc.data_nascita()); + rec.np_put("DA002006", perc.comune_nascita()); + rec.np_put("DA002007", perc.provincia_nascita()); + } + else + { + rec.np_put("DA002002", perc.ragione_sociale()); + } + + const TRectype& anag = cache().get_rec(LF_ANAG, qla.get("TIPOA"), qla.get("CODANAGR")); + rec.np_put("DA002008", anag.get(ANA_CATPAR)); + rec.np_put("DA002009", anag.get_long(ANA_EVECC)); + rec.np_put("DA002010", anag.get_long(ANA_ESCPRECOMP)); + + const TString& causale = qla.get("CAUSALE"); + if (causale == "N") + { + rec.np_put("DA002020", perc.comune_residenza()); + rec.np_put("DA002021", perc.provincia_residenza()); + rec.np_put("DA002022", perc.codice_comune_residenza()); + } + + // rec.np_put("DA002030", ""); // Codice fiscale del rappresentante un incapace + + if (perc.estero()) + { + rec.np_put("DA002040", perc.codice_fiscale()); + rec.np_put("DA002041", perc.localita_residenza()); + rec.np_put("DA002042", perc.indirizzo_residenza()); + rec.np_put("DA002043", perc.stato_estero_UNICO()); + } + + rec.np_put("DA003001", TDate(TODAY)); + rec.np_put("DA003002", true); + + _data.add(rec); + return true; +} + +bool TTrasferimentoCU::append_record_h(const TRectype& qla, int modulo, TLog_report& log) +{ + const char tipoanag = qla.get_char("TIPOA"); + if (tipoanag != 'F') + int cazzone = 1; + + const long codanagr = qla.get_long("CODANAGR"); + if ((tipoanag != 'F' && !_anagiu) || codanagr <= 0) + { + TString msg; msg.format(FR("Scartato percipiente non valido %c/%ld"), tipoanag, codanagr); + log.log(2, msg); + return false; + } + + TAnagrafica perc(LF_ANAG, tipoanag, codanagr); + if (!perc.ok()) + { + TString msg; msg.format(FR("Scartato percipiente non valido %c/%ld"), tipoanag, codanagr); + log.log(2, msg); + return false; + } + + TRecordCU rec('H'); // Compila record H + rec.set(2, cod_fis_dic()); // Codice fiscale sostituto + rec.set(3, modulo); // Progressivo modulo + rec.set(4, perc.codice_fiscale()); // Codice fiscale del percipiente + rec.set(5, _certificazione); // Progressivo certificazione + + const TString4 causale = qla.get("CAUSALE"); + rec.np_put("AU001001", causale); + if (causale >= "G" && causale <= "I") + rec.np_put("AU001002", qla.get_long("ANNO")); // Potrebbe essere anche l'anno precedente + + // rec.np_put("AU001003", ""); + rec.np_put("AU001004", qla.get_real("TOTALE")); + + if (perc.estero()) + rec.np_put("AU001005", qla.get_real("SOMREGCONV")); + + const real altre_somme = qla.get_real("SOMME"); + if (!altre_somme.is_zero()) + { + rec.np_put("AU001006", 3L); // 1, 2, 3 + rec.np_put("AU001007", altre_somme); + } + rec.np_put("AU001008", qla.get_real("IMPONIBILE")); // 004 - 005 - 007 + rec.np_put("AU001009", qla.get_real("IMPORTO")); // ritenute a titolo di acconto + //rec.np_put("AU001010", ZERO); // ritenute a titolo di imposta + rec.np_put("AU001011", qla.get_real("RITSOSPESE")); // ritenute sospese + if (causale == "N") + rec.np_put("AU001012", qla.get_real("ADDREG")); // addizionale regionale + + rec.np_put("AU001018", qla.get_real("IMPANNIPRE")); // imponibile anni precedenti + rec.np_put("AU001019", qla.get_real("RITANNIPRE")); // ritenute anni precedenti + rec.np_put("AU001020", qla.get_real("CTINPSEROG")); // contributi a carico erogante + rec.np_put("AU001021", qla.get_real("CTINPSPERC")); // contributi a carico percipiente + //rec.np_put("AU001022", qla.get_real("SPESERIMB")); // spese rimborsate + //rec.np_put("AU001023", qla.get_rea;("RITRIMB")); // ritenute rimborsate + + _data.add(rec); + return true; +} + +static real& real_at(TArray& riep, int idx) +{ + real* r = (real*)riep.objptr(idx); + if (r == NULL) + riep.add(r = new real, idx); + return *r; +} + +bool TTrasferimentoCU::save(const char* path) +{ + ofstream of(path && *path ? path : _name, ios::binary); + for (_cur_pos = 0; _cur_pos < items(); _cur_pos++) + of << cur_rec(); + return of.good(); +} + +bool TTrasferimentoCU::split(const char* path) +{ + TRecnotype totale[26]; memset(totale, 0, sizeof(totale)); + + bool good = move_first(); + + const unsigned long disk_size = 15*1024*1024; // Max 15 Mb per fornitura + const long records = items(); + const long records_per_disk = long(disk_size / TOTAL_SIZE) - 3; // Tolgo A,B,Z + const int volumes = int((records-1)/records_per_disk)+1; + + TProgress_monitor pi(records, TR("Generazione file trasferimento")); + for (int volume = 1; good && volume <= volumes; volume++) + { + // Specifica volume solo se necessario + TFilename fn = path; fn.add(cu_default_name()); + if (volumes > 1) fn << '_' << volume; + TTrasferimentoCU outfile(fn, 'w'); + + if (save_headers()) + { + TRecordCU rec; + rec.tipo_record('A'); // Compila record di testata A + rec.set(3, "CUR15"); // Codice fornitura + rec.set(4, 1); // Tipo fornitore 01 = Soggetto che invia la propria dichiarazione + rec.set(5, cod_fis_dic()); // Codice fiscale del fornitore + outfile << rec; // Scrive record testata + } + + long written = 0; + + for (; good; good = move_next()) + { + const TRecordCU& rec = cur_rec(); + const char tipo_rec = rec.tipo_record(); + if (tipo_rec <= 'A' || tipo_rec >= 'Z') + continue; + + outfile << rec; + written++; + + totale[tipo_rec-'A']++; + + if (written >= records_per_disk) + break; + + if (!pi.addstatus(1)) + { + good = false; + break; + } + } + + if (save_headers()) + { + // Compi la record di coda + TRecordCU rec; + rec.tipo_record('Z'); + rec.set(3, totale['B'-'A']); // Totale B + rec.set(4, totale['C'-'A']); // Totale C + rec.set(5, totale['D'-'A']); // Totale D + rec.set(6, totale['G'-'A']); // Totale G + rec.set(7, totale['H'-'A']); // Totale H + + // Scrive record di coda + outfile << rec; + } + outfile.save(); + } + return true; +} + +// Cancella il file +void TTrasferimentoCU::remove() +{ + ::remove(_name); +} + +TTrasferimentoCU::TTrasferimentoCU(const char* path, char mode) + : _save_headers(true), _anagiu(true), _data_imp(TODAY), _tipo_operazione(' ') +{ + if (mode == 'r') + load(path); + else + _name = path; +} + +TTrasferimentoCU::~TTrasferimentoCU() +{ } + +/////////////////////////////////////////////////////////// +// TCU_mask +/////////////////////////////////////////////////////////// + +class TCU_mask : public TAutomask +{ +protected: + virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + +public: + TCU_mask() : TAutomask("777200a") {} +}; + +bool TCU_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) +{ + switch (o.dlg()) + { + case F_PATH: + if (e == fe_init || e == fe_modify) + { + TFilename f = o.get(); + f.add(cu_default_name()); + enable(DLG_PREVIEW, f.exist()); + } + break; + case DLG_PREVIEW: + if (e == fe_button) + { + TFilename tmp = get(F_PATH); + tmp.add(cu_default_name()); + if (tmp.exist()) + { + const int quality = get_bool(F_QUALITY) ? 2 : 1; + print_cu(tmp, quality); + } + else + cantread_box(tmp); + return false; // don't close mask + } + break; + case DLG_EDIT: + if (e == fe_button) + { + TFilename tmp = get(F_PATH); + tmp.add(cu_default_name()); + if (tmp.input() && tmp.exist()) + { + const int quality = get_bool(F_QUALITY) ? 2 : 1; + edit_cu(tmp, quality); + } + return false; // don't close mask + } + break; + default: break; + } + return true; +} + + +/////////////////////////////////////////////////////////// +// TCU_app +/////////////////////////////////////////////////////////// + +class TCU_app : public TSkeleton_application +{ +public: + virtual void main_loop(); +}; + +void TCU_app::main_loop() +{ + const int anno = ini_get_int(CONFIG_STUDIO, "77", "AnnoDic", 2014); + TCU_mask m; + m.set(F_ANNO, anno); + + while (m.run() == K_ENTER) + { + TFilename tmp; tmp.tempdir(); + TTrasferimentoCU t(tmp, 'w'); + t.set_inter(m.get(F_INTER_CODFIS), m.get_date(F_INTER_DATA), anno); + t.set_operazione(m.get(F_INVIO)[0], m.get(F_IDENTIFICATIVO)); + + TString query; + query.format("USE %d\nFROM CODDITTA=%ld\nTO CODDITTA=%ld", + LF_BASE, m.get_long(F_DADITTA), m.get_long(F_ADITTA)); + TISAM_recordset cur_base(query); + const TRecnotype ditte = cur_base.items(); + if (ditte > 0) + { + TLog_report log; log.kill_duplicates(); + + const TRectype& base = cur_base.cursor()->curr(); + for (bool ok = cur_base.move_first(); ok; ok = cur_base.move_next()) + { + const long codditta = base.get_long(BSE_CODDITTA); + TString msg; msg.format(FR("Generazione C.U. ditta %ld"), codditta); + log.log(0, ""); + log.log(0, msg); + + t.read_codfis_dic(base); + t.append_record_b(); + + if (t.anagiu_included()) + query.format("USE %d SELECT (ANNO=%d)\nFROM CODDITTA=%ld\nTO CODDITTA=%ld", + LF_QUALA, anno, codditta, codditta); + else + query.format("USE %d SELECT (TIPOA=\"F\")&&(ANNO=%d)\nFROM CODDITTA=%ld\nTO CODDITTA=%ld", + LF_QUALA, anno, codditta, codditta); + TISAM_recordset perc(query); + const TRecnotype nperc = perc.items(); + if (nperc > 0) + { + TProgress_monitor pp(nperc, TR("Generazione record percipienti")); + const TRectype& rec = perc.cursor()->curr(); + long last_perc = 0; + int modulo = 1; + for (bool ok = perc.move_first(); ok; ok = perc.move_next()) + { + const long codanagr = rec.get_long("CODANAGR"); + if (codanagr != last_perc) + { + last_perc = codanagr; + t.append_record_d(rec, log); + modulo = 1; + } + if (t.append_record_h(rec, modulo, log)) + modulo++; + pp.add_status(); + } + } + } + if (log.errors() || log.warnings()) + log.preview(); + } + + tmp = m.get(F_PATH); + if (t.split(tmp)) + { + tmp.add(cu_default_name()); + if (yesno_box(FR("E' stato generato il file %s\nSi desidera visualizzarlo in anteprima?"), (const char*) tmp)) + m.send_key(K_SPACE, DLG_PREVIEW); + } + else + { + tmp.add(cu_default_name()); + cantwrite_box(tmp); + } + t.remove(); + } +} + +int m777200(int argc, char* argv[]) +{ + TCU_app app; + app.run(argc, argv, "Invio C.U."); + return 0; +} + + + diff --git a/m770/777201.cpp b/m770/777201.cpp new file mode 100644 index 000000000..b3498cc4d --- /dev/null +++ b/m770/777201.cpp @@ -0,0 +1,825 @@ +#include "777200.h" + +#include +#include + +const COLOR CU_BACKGROUND = XVT_MAKE_COLOR(224,224,224); + +const TReport_font& best_font(const char* name, int size, XVT_FONT_STYLE_MASK fs) +{ + static TAssoc_array fonts; + static const long famax = 1024; + static char* family[famax] = { 0 }; + static long families = 0; + + TToken_string key; + key = name; key.add(size); key.add((long)fs); + TReport_font* fnt = (TReport_font*)fonts.objptr(key); + if (fnt == NULL) + { + if (families == 0) + families = xvt_fmap_get_families(NULL, family, famax); + + int best = -1; + double score = 0.5; + for (long i = 0; i < families; i++) if (*name == *family[i]) + { + const double s = xvt_str_fuzzy_compare(name, family[i]); + if (s > score) + { + best = i; + score = s; + if (score >= 1.0) + break; + } + } + if (best >= 0) + name = family[best]; + fnt = new TReport_font; + fnt->create(name, size, fs); + fonts.add(key, fnt); + } + return *fnt; +} + +class TCU_report : public TReport +{ + TReport_font _fnt_rep, _fnt_prm, _fnt_lbl, _fnt_sub, _fnt_prg; + int _quality; // 0=text only; 1=borders only; 2=filled bars + +private: + const TReport_field& last_field() const; + void set_field_pos(int row, int col, int width, TReport_field& fld) const; + TReport_field& add_break(TReport_section& sec, int row, bool small); + void add_field_label(const TReport_field& fld, const char* text, char alignment = 'L'); + TReport_field& add_prompt(TReport_section& sec, int row, int col, int len, const char* text); + void add_field_sublabel(const TReport_field& fld, const char* text); + void add_field_grid(const TReport_field& fld, bool underlined, bool date); + TReport_field& add_field(TReport_section& sec, int row, int col, int width, const char* field); + +protected: + TReport_field& add_prompted_field(TReport_section& sec, int row, int col, int width, const char* field, const char* prompt, int promptlen = -1); + TReport_field& add_prompted_bool(TReport_section& sec, int row, int col, int width, const char* field, const char* prompt, int promptlen = -1); + TReport_field& add_labeled_field (TReport_section& sec, int row, int col, int width, const char* field, const char* label, char alignment = 'B'); + TReport_field& add_labeled_number(TReport_section& sec, int row, int col, int width, const char* field, const char* label, char alignment = 'B'); + TReport_field& add_boxed_field (TReport_section& sec, int row, int col, int width, const char* field, const char* prompt, int flags = 0x0); + TReport_field& add_gridded_field (TReport_section& sec, int row, int col, int len, + const char* field, const char* prompt); + void add_underlined_text(TReport_section& body, int row, const char* text); + + TReport_field& add_big_text(TReport_section& sec, int row, int col, const char* label, COLOR rgb); + void add_band(TReport_section& sec, int row, int height, COLOR rgb = CU_BACKGROUND); + void add_long_break (TReport_section& sec, int row); + void add_short_break(TReport_section& sec, int row); + void begin_paragraph(TReport_section& sec, int row, int height, const char* label, int mode = 0); + void end_paragraph(TReport_section& sec); + + void create_logo(TReport_section& header); + void create_B(); + void create_D(); + void create_H(); + +public: + TCU_report(int quality); +}; + +#define CU_FORM_WIDTH 7800 +#define CU_FORM_BORDER 100 +#define CU_HEAD_WIDTH 1000 + +#define CU_AFTER_LAST -1 +#define CU_BEFORE_LAST -2 +#define CU_ALIGN_RIGHT -3 + +#define CU_EURO_LEN 16 + +static int _row_offset = 0; +static int _row_height = 300; +static int _row_last = 0; +static TReport_field* _last_fld = NULL; + +const TReport_field& TCU_report::last_field() const +{ + return *_last_fld; +} + + +void TCU_report::set_field_pos(int row, int col, int len, TReport_field& fld) const +{ + TReport_section& sec = fld.section(); + + int dimx = (len+1) * 100; + int dimy = 150; + int posx = 0; + if (col < 0) + { + switch(col) + { + case CU_BEFORE_LAST: posx = last_field().get_rect().left() - dimx - 100; break; + case CU_ALIGN_RIGHT: posx = CU_FORM_BORDER+CU_FORM_WIDTH - dimx - 100; break; + default : posx = last_field().get_rect().right() + 100; break; + } + } + else + { + if (_row_offset > 0) // in paragraph + posx = CU_FORM_BORDER+CU_HEAD_WIDTH + (col+1)*100; + else + posx = CU_FORM_BORDER + col*100; // in header + } + + int posy = 0; + if (_row_offset > 0) // in paragraph + posy = _row_offset + (row+1)*_row_height - dimy; + else + posy = (row+1)*100 - dimy; // in header + + if (len <= 0) + dimx = CU_FORM_BORDER+CU_FORM_WIDTH - posx - 100; + + fld.set_pos(posx, posy); + fld.set_size(dimx, dimy); +} + + +void TCU_report::begin_paragraph(TReport_section& sec, int row, int height, const char* label, int mode) +{ + if (row < 0) + _row_offset = _row_last; + else + _row_offset = row*100; + _row_last = _row_offset + height*100; + _row_height = height <= 2 ? 200 : (height%3 ? 400 : 300); + _last_fld = NULL; + + TString str1 = label, str2; + int delta2 = 0; + if (mode & 0x2) + { + if (mode == 0x2) + { + str2 = str1; + str1.cut(0); + } + else + { + const int due_paragrafi = str1.find('\n'); + str2 = str1.mid(due_paragrafi+1); + str1.cut(due_paragrafi); + delta2 = 200; + } + } + + if (str1.full()) + { + TReport_field* txt = new TReport_field(&sec); + txt->set_vertical_alignment('T'); + txt->set_horizontal_alignment('L'); + txt->set_pos(CU_FORM_BORDER, _row_offset); + txt->set_size(CU_HEAD_WIDTH, height*100); + txt->set_pattern(PAT_HOLLOW); + txt->set_text_color(COLOR_BLACK); + txt->set_back_color(COLOR_INVALID); + txt->set_picture(str1); + txt->set_font(_fnt_prg); + sec.add(txt); + } + + if (str2.full()) + { + TReport_font fnt2; + fnt2.create(_fnt_lbl.name(), _fnt_lbl.size(), XVT_FS_BOLD); + + TReport_field* txt2 = new TReport_field(&sec); + txt2->set_vertical_alignment('T'); + txt2->set_horizontal_alignment('L'); + txt2->set_pos(CU_FORM_BORDER, _row_offset+delta2); + txt2->set_size(CU_HEAD_WIDTH, (height*100)-delta2); + txt2->set_pattern(PAT_HOLLOW); + txt2->set_text_color(COLOR_BLACK); + txt2->set_back_color(COLOR_INVALID); + txt2->set_picture(str2); + txt2->set_font(fnt2); + sec.add(txt2); + } +} + +void TCU_report::end_paragraph(TReport_section& sec) +{ + add_long_break(sec, _row_last/100); +} + +void TCU_report::add_field_label(const TReport_field& fld, const char* text, char alignment) +{ + TReport_section& sec = fld.section(); + TReport_field* label = new TReport_field(&sec); + label->set_type('T'); + label->set_pattern(PAT_HOLLOW); + label->set_text_color(COLOR_BLACK); + label->set_back_color(COLOR_INVALID); + label->set_font(_fnt_lbl); + const TReport_rct& rct = fld.get_rect(); + label->set_pos(rct.x, rct.y-100); + label->set_size(rct.width(), 100); + label->set_picture(text); + label->set_vertical_alignment('B'); + if (alignment == 'C') + { + label->set_horizontal_alignment('C'); + label->set_pos(rct.x-400, rct.y-100); + label->set_size(rct.width()+800, 75); + } + + sec.add(label); +} + +void TCU_report::add_field_sublabel(const TReport_field& fld, const char* text) +{ + TReport_section& sec = fld.section(); + TReport_field* label = new TReport_field(&sec); + label->set_type('T'); + label->set_pattern(PAT_HOLLOW); + label->set_back_color(COLOR_INVALID); + label->set_text_color(COLOR_BLACK); + label->set_font(_fnt_sub); + const TReport_rct& rct = fld.get_rect(); + label->set_pos(rct.x, rct.y); + label->set_size(rct.width(), rct.height()/3); + label->set_picture(text); + sec.add(label); +} + +TReport_field& TCU_report::add_field(TReport_section& sec, int row, int col, int len, const char* field) +{ + TReport_field* txt = new TReport_field(&sec); + txt->set_type('S'); + txt->set_vertical_alignment('B'); + txt->set_dynamic_height(false); + if (_quality >= 2) + { + txt->set_pattern(PAT_SOLID); + txt->set_back_color(COLOR_WHITE); + } + else + { + txt->set_pattern(PAT_HOLLOW); + txt->set_back_color(COLOR_INVALID); + txt->set_fore_color(COLOR_GRAY); + txt->set_border(1); + } + txt->set_field(field); + set_field_pos(row, col, len, *txt); + sec.add(txt); + _last_fld = txt; + return *txt; +} + +int estimated_prompt_len(const char* text) +{ + static XVT_FNTID font_id = NULL; + if (font_id == NULL) + { + font_id = xvt_font_create(); + xvt_font_set_family(font_id, XVT_FFN_HELVETICA); + xvt_font_set_size(font_id, 12); + xvt_dwin_set_font(TASK_WIN, font_id); + } + else + { + if (text == NULL) + { + xvt_font_destroy(font_id); + font_id = NULL; + } + } + + const int len = (text && *text) ? xvt_dwin_get_text_width(TASK_WIN, text, -1) : 0; + return len / 6; +} + +TReport_field& TCU_report::add_prompt(TReport_section& sec, int row, int col, int len, const char* text) +{ + TReport_field* label = new TReport_field(&sec); + label->set_type('T'); + label->set_vertical_alignment('C'); + label->set_pattern(PAT_HOLLOW); + label->set_back_color(COLOR_INVALID); + label->set_text_color(COLOR_BLACK); + label->set_font(_fnt_prm); + label->set_picture(text); + if (len < 0) + len = estimated_prompt_len(text)/2; + set_field_pos(row, col, len, *label); + const TReport_rct& rct = label->get_rect(); + if (rct.height() > 100) + { + const int delta = rct.height() - 100; + label->set_pos(rct.left(), rct.top()+delta); + label->set_size(rct.width(), rct.height()-delta); + } + sec.add(label); + _last_fld = label; + return *label; +} + +TReport_field& TCU_report::add_labeled_field(TReport_section& body, int row, int col, int len, + const char* field, const char* label, char alignment) +{ + if (alignment != 'C' && len > 0 && label && int(strlen(label)) > 2*len) + alignment = 'C'; + + TReport_field& txt = add_field(body, row, col, len, field); + if (alignment == 'C') + txt.set_horizontal_alignment(alignment); + if (field && *field && field[1] >= 'A') + { + TString4 num = field+7; + if (num[0] == '0') num.ltrim(1); + add_field_sublabel(txt, num); + } + if (label && *label) + add_field_label(txt, label, alignment); + return txt; +} + +TReport_field& TCU_report::add_labeled_number(TReport_section& body, int row, int col, int width, + const char* field, const char* label, char alignment) +{ + TReport_field& txt = add_labeled_field(body, row, col, width, field, label, alignment); + txt.set_horizontal_alignment('R'); + if (width == CU_EURO_LEN) + { + txt.set_type('S'); // avoid obnoxious x100 + } + else + { + txt.set_type('N'); + txt.hide_zeroes(true); + } + return txt; +} + +TReport_field& TCU_report::add_prompted_field(TReport_section& body, int row, int col, int width, const char* field, const char* prompt, int promptlen) +{ + if (col == CU_ALIGN_RIGHT && width > 0) + { + TReport_field& fld = add_field(body, row, col, width, field); + if ((prompt && *prompt) || promptlen > 0) + add_prompt(body, row, CU_BEFORE_LAST, promptlen, prompt); + return fld; + } + if ((prompt && *prompt) || promptlen > 0) + { + add_prompt(body, row, col, promptlen, prompt); + col = CU_AFTER_LAST; + } + return add_field(body, row, col, width, field); +} + +TReport_field& TCU_report::add_prompted_bool(TReport_section& sec, int row, int col, int width, const char* field, const char* prompt, int promptlen) +{ + TReport_field& cb = add_prompted_field(sec, row, col, width, field, prompt, promptlen); + cb.set_type('B'); + cb.set_horizontal_alignment('C'); + cb.set_vertical_alignment('C'); + return cb; +} + +TReport_field& TCU_report::add_boxed_field(TReport_section& sec, int row, int col, int width, + const char* field, const char* prompt, int flags) +{ + TReport_field* fld = NULL; + if (flags & 0x2) + fld = &add_gridded_field (sec, row, col, width, field, prompt); + else + fld = &add_prompted_field(sec, row, col, width, field, prompt); + + TReport_field& txt = *fld; + if (width < 16) + txt.set_type('N'); + txt.set_border(2); + txt.set_fore_color(COLOR_BLACK); + txt.set_horizontal_alignment('C'); + + if (flags & 0x1) // Half height + { + const TReport_rct& rct = txt.get_rect(); + TReport_field* line = new TReport_field(&sec); + line->set_type('R'); + line->set_pos(rct.left()-10, rct.top()-10); + line->set_size(rct.width()+20, rct.height()/3); + line->set_pattern(PAT_SOLID); + line->set_back_color(COLOR_WHITE); + sec.add(line); + } + + return txt; +} + + +void TCU_report::add_field_grid(const TReport_field& fld, bool underlined, bool date) +{ + TReport_section& sec = fld.section(); + const TReport_rct& rct = fld.get_rect(); + + if ((rct.width() / 100) & 1) // Campo di lunghezza dispari! + { + TReport_field& f = (TReport_field&)fld; + f.set_width(rct.width()-100); + } + + if (underlined) + { + TReport_field* line = new TReport_field(&sec); + line->set_type('L'); + line->set_pos(rct.left(), rct.bottom()); + line->set_size(rct.width(), 0); + line->set_border(1); + line->set_fore_color(COLOR_BLACK); + sec.add(line); + } + + int fr, to, len, spc; + if (date) + { + len = 4; + fr = 1; + to = 2; + spc = 50; + } + else + { + len = rct.width() / 200; + fr = underlined ? 0 : 1; + to = len - (underlined ? 0 : 1); + spc = underlined ? 0 : 50; + } + for (int y = fr; y <= to; y++) + { + TReport_field* line = new TReport_field(&sec); + line->set_type('L'); + line->set_pos(rct.left()+y*rct.width()/len, rct.top()+spc); + line->set_size(0, rct.height()-spc); + line->set_border(1); + line->set_fore_color(COLOR_BLACK); + sec.add(line); + } +} + +TReport_field& TCU_report::add_gridded_field(TReport_section& sec, int row, int col, int len, + const char* field, const char* label) +{ + const bool is_date = len == 10; + const bool underlined = len>=16 && _row_offset <= 0; // Underlined grid in the header + TString80 str; + if (is_date) + { + str = "## ## ####"; + len = 5; + } + else + { + for (int i = 0; i < len; i++) + { + if (i) str << ' '; + str << "#"; + } + str.rtrim(); + } + TReport_field& fld = add_labeled_field(sec, row, col, len*2, field, label); + fld.set_picture(str); + if (is_date) + fld.set_horizontal_alignment('C'); + else + fld.set_horizontal_alignment('R'); + add_field_grid(fld, underlined, is_date); + + return fld; +} + +TReport_field& TCU_report::add_big_text(TReport_section& sec, int row, int col, const char* label, COLOR rgb) +{ + const TReport_font& fnt_big = best_font("Arial Black", _fnt_prg.size()*3, _fnt_prg.style()); + + TReport_field* txt = new TReport_field(&sec); + txt->set_type('T'); + txt->set_picture(label); + txt->set_pos(CU_FORM_BORDER+col*100, row*100); + txt->set_size(strlen(label)*300, 200); + txt->set_pattern(PAT_HOLLOW); + txt->set_back_color(COLOR_INVALID); + txt->set_text_color(rgb); + txt->set_font(fnt_big); + + sec.add(txt); + return *txt; +} + +TReport_field& TCU_report::add_break(TReport_section& sec, int row, bool small) +{ + TReport_field* line = new TReport_field(&sec); + line->set_type('L'); + if (small) + { + line->set_pos(CU_FORM_BORDER+CU_HEAD_WIDTH, row*100); + line->set_size(CU_FORM_WIDTH-CU_HEAD_WIDTH, 0); + line->set_border(1); + } + else + { + line->set_pos(CU_FORM_BORDER, row*100); + line->set_size(CU_FORM_WIDTH, 0); + line->set_border(2); + } + line->set_fore_color(COLOR_BLACK); + sec.add(line); + return *line; +} + +void TCU_report::add_long_break(TReport_section& sec, int row) +{ add_break(sec, row, false); } + +void TCU_report::add_short_break(TReport_section& sec, int row) +{ add_break(sec, row, true); } + +void TCU_report::add_band(TReport_section& sec, int row, int height, COLOR rgb) +{ + TReport_field* rct = new TReport_field(&sec); + if (rgb == COLOR_INVALID) + rgb = CU_BACKGROUND; + rct->set_pos(CU_FORM_BORDER+CU_HEAD_WIDTH, row *100); + rct->set_size(CU_FORM_WIDTH-CU_HEAD_WIDTH, height*100); + if (_quality >= 2) + { + rct->set_pattern(PAT_SOLID); + rct->set_back_color(rgb); + } + else + { + rct->set_pattern(PAT_HOLLOW); + rct->set_border(2); + rct->set_fore_color(rgb); + rct->set_back_color(COLOR_INVALID); + } + sec.add(rct); + + add_long_break(sec, row); +} + +void TCU_report::add_underlined_text(TReport_section& body, int row, const char* text) +{ + TReport_field& line = add_break(body, _row_offset/100+row+1, true); + const TReport_rct rct = line.get_rect(); + line.set_pos(rct.left()+100, rct.top()+25); + line.set_size(rct.width()-200, rct.height()); + add_field_label(line, text, 'C'); +} + +void TCU_report::create_logo(TReport_section& header) +{ + add_big_text(header, 4, 0, "CERTIFICAZIONE", COLOR_GRAY).set_vertical_alignment('T'); + add_big_text(header, 6, 0, "UNICA", COLOR_BLACK).set_vertical_alignment('B'); + add_big_text(header, 6,12, "2015", COLOR_LTGRAY).set_vertical_alignment('B'); + + TReport_field* txt = new TReport_field(&header); + txt->set_type('I'); + txt->set("res/AgenziaEntrate.gif"); + txt->set_pos(CU_FORM_BORDER, 900); + txt->set_size(1200, 200); + header.add(txt); +} + +void TCU_report::create_B() +{ + TReport_section& header = section('B', 1); + header.set_condition("#1=\"B\""); + + _row_offset = 0; + estimated_prompt_len(NULL); // Reset font computer + + create_logo(header); + add_gridded_field(header, 11, CU_ALIGN_RIGHT, 16, "#2", ""); // Codice fiscale dichiarante + add_prompt(header, 11, CU_BEFORE_LAST, 7, "Codice fiscale"); + + add_band(header, 13, 27); + + begin_paragraph(header, 13, 2, "TIPO DI COMUNICAZIONE"); + add_prompted_bool(header, 0, 0, 2, "#10", "Annullamento"); + add_prompted_bool(header, 0, 28, 2, "#11", "Sostituzione"); + end_paragraph(header); + + begin_paragraph(header, CU_AFTER_LAST, 9, "DATI RELATIVI\nAL SOSTITUTO"); + add_labeled_field(header, 0, 0, 32, "#2", "Codice Fiscale"); + add_labeled_field(header, 1, 0, 36, "#12", "Cognome o Denominazione").set_alternate_field("#14"); + add_labeled_field(header, 1,CU_AFTER_LAST, CU_ALIGN_RIGHT, "#13", "Nome"); // La colonna segue il cognome + TReport_field& tel = add_labeled_field(header, 2, 0, 16, "#16", "Telefono o fax"); + add_field_sublabel(tel, "prefisso numero"); + tel.set_alternate_field("#17"); + add_labeled_field(header, 2, CU_AFTER_LAST, CU_ALIGN_RIGHT, "#15", "Indirizzo di posta elettronica"); // La colonna segue il telefono + end_paragraph(header); + + begin_paragraph(header, CU_AFTER_LAST, 6, "DATI RELATIVI AL RAPPRESENTANTE FIRMATARIO DELLA COMUNICAZIONE"); + add_labeled_field(header, 0, 0, 24, "#18", "Codice Fiscale"); + add_labeled_field(header, 0,32, 3, "#19", "Codice carica", 'C'); + add_gridded_field(header, 0,CU_ALIGN_RIGHT, 11, "#2", "Codice fiscale societą o ente dichiarante"); + add_labeled_field(header, 1, 0, 36, "#20", "Cognome"); + add_labeled_field(header, 1,CU_AFTER_LAST, CU_ALIGN_RIGHT, "#21", "Nome"); + end_paragraph(header); + + begin_paragraph(header, CU_AFTER_LAST, 3, "FIRMA DELLA COMUNICAZIONE"); + add_labeled_number(header, 0, 4, 5, "#23", "Numero certificazioni\nlavoro dipendente ed assimilati", 'C'); + add_labeled_number(header, 0, 15, 5, "#24", "Numero certificazioni\nlavoro autonomo e provvigioni", 'C'); + add_labeled_field (header, 0, 25, 3, "#25", "Quadro CT", 'C'); + add_prompted_field(header, 0, CU_ALIGN_RIGHT, 24, "", "FIRMA"); + end_paragraph(header); + + begin_paragraph(header, CU_AFTER_LAST, 7, "IMPEGNO ALLA PRESENTAZIONE TELEMATICA"); + _row_height = 300; + add_prompted_field(header, 0, 0, 16, "#27", "Codice fiscale dell'intermediario"); + add_break(header, _row_offset/100+3, true); + end_paragraph(header); + + begin_paragraph(header, _row_offset/100+3, 2, "Riservato\nall'intermediario"); + add_prompt(header, 0, 0, 30, "Impegno a presentare in via telematica la comunicazione"); + TReport_field& ipt = add_field(header, 0, CU_ALIGN_RIGHT, 2, "#28"); + ipt.set_type('N'); + ipt.set_horizontal_alignment('C'); + ipt.hide_zeroes(true); + add_break(header, _row_offset/100+2, true); + add_prompt(header, 1,0, -1, "Data dell'impegno"); + TReport_field& dit = add_gridded_field(header, 1, 10, 10, "#29", ""); + dit.set_type('N'); + dit.hide_zeroes(true); + add_prompted_field(header,1, CU_ALIGN_RIGHT,24, "", "FIRMA DELL'INTERMEDIARIO", 15); + add_break(header, _row_offset/100+4, false); +} + +void TCU_report::create_D() +{ + TReport_section& body = section('B', 2); + body.set_condition("#1=\"D\""); + body.force_page_break(true); + + _row_offset = 0; + create_logo(body); + + TReport_font fnt_big; fnt_big.create(_fnt_prg.name(), 3*_fnt_prg.size()/2, _fnt_prg.style()); + TReport_field* txt = new TReport_field(&body); + txt->set_type('T'); + txt->set_picture("CERTIFICAZIONE DI CUI ALL'ART.4, COMMI 6-ter e 6-quater,\n" + "DEL D.P.R. 22 LUGLIO 1998, n. 322, RELATIVA ALL'ANNO"); + txt->set_pos(CU_FORM_BORDER+28*100, 7*100); + txt->set_size(7000, 300); + txt->set_pattern(PAT_HOLLOW); + txt->set_back_color(COLOR_INVALID); + txt->set_text_color(COLOR_BLACK); + txt->set_font(fnt_big); + body.add(txt); + + add_boxed_field(body, 8, 68, 4, "2014", ""); + + add_band(body, 12, 35); + + begin_paragraph(body, 12, 9, "DATI ANAGRAFICI\nDATI RELATIVI\nAL DATORE DI LAVORO,\nENTE PENSIONISTICO O\nALTRO SOSTITUTO\nD'IMPOSTA", 0x3); + add_labeled_field(body, 0, 0, 16, "#DA001001", "Codice Fiscale"); + add_labeled_field(body, 0, CU_AFTER_LAST, 30, "#DA001002", "Cognome o Denominazione"); + add_labeled_field(body, 0, CU_AFTER_LAST, CU_ALIGN_RIGHT, "#DA001003", "Nome"); // La colonna segue il cognome + + add_labeled_field(body, 1, 0, 24, "#DA001004", "Comune"); + add_labeled_field(body, 1, CU_AFTER_LAST, 2, "#DA001005", "Prov."); + add_labeled_field(body, 1, CU_AFTER_LAST, 5, "#DA001006", "Cap"); + add_labeled_field(body, 1, CU_AFTER_LAST, CU_ALIGN_RIGHT, "#DA001007", "Indirizzo"); + + TReport_field& tel = add_labeled_field(body, 2, 0, 16, "#DA001008", "Telefono o fax"); + add_field_sublabel(tel, " prefisso numero"); + add_labeled_field(body, 2, CU_AFTER_LAST, 30, "#DA001009", "Indirizzo di posta elettronica"); + add_labeled_field(body, 2, CU_AFTER_LAST, 6, "#DA001010", "Codice attivitą"); + add_labeled_number(body, 2, CU_AFTER_LAST, CU_ALIGN_RIGHT, "#DA001011", "Codice sede"); + end_paragraph(body); + + begin_paragraph(body, CU_AFTER_LAST, 6, "DATI RELATIVI\nAL DIPENDENTE,\nPENSIONATO O\nALTRO PERCETTORE\nDELLE SOMME", 0x2); + add_labeled_field(body, 0, 0, 16, "#DA002001", "Codice Fiscale"); + add_labeled_field(body, 0, CU_AFTER_LAST, 30, "#DA002002", "Cognome o Denominazione"); + add_labeled_field(body, 0, CU_AFTER_LAST, CU_ALIGN_RIGHT, "#DA002003", "Nome"); // La colonna segue il cognome + add_labeled_field(body, 1, 0, 1, "#DA002004", "Sesso\n(M o F)", 'C'); + add_gridded_field(body, 1, CU_AFTER_LAST, 10, "#DA002005", "Data di nascita"); + add_labeled_field(body, 1, 16, 24, "#DA002006", "Comune (o Stato estero) di nascita"); + add_labeled_field(body, 1, CU_AFTER_LAST, 3, "#DA002007", "Prov. nasc.\n(sigla)", 'C'); + add_labeled_field(body, 1, 49, 3, "#DA002008", "Categorie\nparticolari", 'C'); + add_labeled_number(body,1, 55, 3, "#DA002009", "Eventi\neccezionali", 'C'); + add_labeled_number(body,1, 61, 3, "#DA002010", "Casi di esclusione\ndalla precompilata", 'C'); + end_paragraph(body); + + begin_paragraph(body, CU_AFTER_LAST, 8, ""); + add_underlined_text(body, 0, "DOMICILIO FISCALE ALL'1/1/2014"); + add_labeled_field(body, 0, 0, 50, "#DA002020", "Comune"); + add_labeled_field(body, 0, CU_AFTER_LAST, 3, "#DA002021", "Provincia (sigla)"); + add_labeled_field(body, 0, CU_ALIGN_RIGHT, 6, "#DA002022", "Codice comune"); + add_underlined_text(body, 4, "DOMICILIO FISCALE ALL'1/1/2015"); + add_labeled_field(body, 1, 0, 50, "#DA002023", "Comune"); + add_labeled_field(body, 1, CU_AFTER_LAST, 3, "#DA002024", "Provincia (sigla)"); + add_labeled_field(body, 1, CU_ALIGN_RIGHT, 6, "#DA002025", "Codice comune"); + end_paragraph(body); + + begin_paragraph(body, CU_AFTER_LAST, 3, "DATI RELATIVI\nAL RAPPRESENTANTE", 0x2); + add_labeled_field(body, 0, 0, 16, "#DA002030", "Codice Fiscale"); + end_paragraph(body); + + begin_paragraph(body, CU_AFTER_LAST, 6, "RISERVATO\nAI PERCIPIENTI ESTERI", 0x2); + add_labeled_field(body, 0, 0, 16, "#DA002040", "Codice di identificazione fiscale estero"); + add_labeled_field(body, 0, CU_AFTER_LAST, CU_ALIGN_RIGHT, "#DA002041", "Localitą di residenza estera"); + add_labeled_field(body, 1, 0, 50, "#DA002042", "Via e numero civico"); + add_labeled_field(body, 1, CU_ALIGN_RIGHT, 5, "#DA002043", "Codice Stato estero", 'C'); + end_paragraph(body); + begin_paragraph(body, CU_AFTER_LAST, 3, ""); + add_gridded_field(body, 0, 0, 10, "#DA003001", "DATA"); + add_labeled_field(body, 0, 15, CU_ALIGN_RIGHT, "", "FIRMA DEL SOSTITUTO DI IMPOSTA", 'C'); + end_paragraph(body); +} + +void TCU_report::create_H() +{ + TReport_section& body = section('B', 3); + body.set_condition("#1=\"H\""); + body.force_page_break(true); + _row_offset = 0; + + add_prompt (body, 4, 0, 14, "Codice fiscale del percipiente"); + add_boxed_field(body, 4,CU_AFTER_LAST, 16, "#4", "", 0x1); + + add_boxed_field(body, 4, 74, 2, "#3", "", 0x3); + add_prompt(body, 4, CU_BEFORE_LAST, -1, "Mod. N."); + + const TReport_font& fnt_big = best_font(_fnt_prg.name(), 3*_fnt_prg.size()/2, _fnt_prg.style()); + TReport_field* title = new TReport_field(&body); + title->set_pos(CU_FORM_BORDER+CU_HEAD_WIDTH, 700); + title->set_size(CU_FORM_WIDTH-CU_HEAD_WIDTH, 200); + title->set_horizontal_alignment('C'); + title->set_vertical_alignment('C'); + title->set_picture("CERTIFICAZIONE LAVORO AUTONOMO,\nPROVVIGIONI E REDDITI DIVERSI"); + title->set_font(fnt_big); + body.add(title); + add_band(body, 10, 25); + + const int tab0 = 2, tab1 = 6, tab2 = 27, tab3 = CU_ALIGN_RIGHT; + + begin_paragraph(body, 10, 4, "DATI RELATIVI ALLE SOMME EROGATE\nTIPOLOGIA REDDITUALE", 0x3); + add_labeled_field(body, 0, tab0, 1, "#AU001001", "Causale"); + end_paragraph(body); + + begin_paragraph(body, -1, 21, "DATI FISCALI"); + add_labeled_number(body, 0, tab1-1, 4, "#AU001002", "Anno", 'C'); + add_labeled_field (body, 0, CU_AFTER_LAST, 2, "#AU001003", "Anticipazione", 'C'); + add_labeled_number(body, 0, tab2, CU_EURO_LEN, "#AU001004", "Ammontare lordo corrisposto", 'C'); + add_labeled_number(body, 0, tab3, CU_EURO_LEN, "#AU001005", "Somme non soggette a ritenuta\nper regime convenzionale", 'C'); + + add_labeled_number(body, 1, tab0, 2, "#AU001006", "Codice"); + add_labeled_number(body, 1, tab1, CU_EURO_LEN, "#AU001007", "Altre somme non soggette a ritenuta", 'C'); + add_labeled_number(body, 1, tab2, CU_EURO_LEN, "#AU001008", "Imponibile", 'C'); + add_labeled_number(body, 1, tab3, CU_EURO_LEN, "#AU001009", "Ritenute a titolo di acconto", 'C'); + + add_labeled_number(body, 2, tab1, CU_EURO_LEN, "#AU001010", "Ritenute a titolo d'imposta", 'C'); + add_labeled_number(body, 2, tab2, CU_EURO_LEN, "#AU001011", "Ritenute sospese", 'C'); + add_labeled_number(body, 2, tab3, CU_EURO_LEN, "#AU001012", "Addizionale regionale a titolo d'acconto", 'C'); + + add_labeled_number(body, 3, tab1, CU_EURO_LEN, "#AU001013", "Addizionale regionale a titolo d'imposta", 'C'); + add_labeled_number(body, 3, tab2, CU_EURO_LEN, "#AU001014", "Addizionale regionale sospesa", 'C'); + add_labeled_number(body, 3, tab3, CU_EURO_LEN, "#AU001015", "Addizionale comunale a titolo d'acconto", 'C'); + + add_labeled_number(body, 4, tab1, CU_EURO_LEN, "#AU001016", "Addizionale comunale a titolo d'imposta", 'C'); + add_labeled_number(body, 4, tab2, CU_EURO_LEN, "#AU001017", "Addizionale comunale sospesa", 'C'); + add_labeled_number(body, 4, tab3, CU_EURO_LEN, "#AU001018", "Imponibile anni precedenti", 'C'); + + add_labeled_number(body, 5, tab1, CU_EURO_LEN, "#AU001019", "Ritenute operate anni precedenti", 'C'); + add_labeled_number(body, 5, tab2, CU_EURO_LEN, "#AU001020", "Contributi previdenziali\na carico del soggetto erogante", 'C'); + add_labeled_number(body, 5, tab3, CU_EURO_LEN, "#AU001021", "Contributi previdenziali\na carico del percipiente", 'C'); + + add_labeled_number(body, 6, tab1, CU_EURO_LEN, "#AU001022", "Spese rimborsate", 'C'); + add_labeled_number(body, 6, tab2, CU_EURO_LEN, "#AU001023", "Ritenute rimborsate", 'C'); + end_paragraph(body); +} + + +TCU_report::TCU_report(int quality) : _quality(quality) +{ + set_lpi(6); + set_cpi(10); + _fnt_rep.create("Courier New", 12, 0); + set_font(_fnt_rep); + _fnt_lbl.create("Arial", _fnt_rep.size()/2, 0); + _fnt_sub.create(_fnt_lbl.name(), _fnt_lbl.size(), XVT_FS_BOLD); + _fnt_prg.create(_fnt_lbl.name(), _fnt_rep.size()/2+1, XVT_FS_BOLD); + _fnt_prm.create(_fnt_lbl.name(), 2*_fnt_rep.size()/3, 0); + + create_B(); + create_D(); + create_H(); +} + +void print_cu(const TFilename& datafile, int quality) +{ + TCU_report cur(quality); + cur.set_recordset(new TTrasferimentoCU(datafile, 'r')); + cur.preview(); + xvtil_statbar_set(NULL); +} diff --git a/m770/777202.cpp b/m770/777202.cpp new file mode 100644 index 000000000..88b87009b --- /dev/null +++ b/m770/777202.cpp @@ -0,0 +1,289 @@ +#include +#include + +#include "777200.h" +#include "777200a.h" + +class TCU_editor : public TAutomask +{ + TTrasferimentoCU* _recset; + int _quality; + + TBit_array _dirty_row; + bool _dirty_file; + TString _txt; + +protected: + void save_page(); + bool save_page_if_dirty(); + void load(); + void save_file(); + bool find_text(); + +public: + virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + TCU_editor(const TFilename& fn, int quality); + ~TCU_editor() { delete _recset; } +}; + +void TCU_editor::load() +{ + TSheet_field& sheet = sfield(F_PATH); + sheet.hide(); + sheet.destroy(); + + const unsigned int cols = _recset->columns(); + + TString8 name, last; + for (unsigned int c = 0; c < cols; c++) + { + const TRecordset_column_info& ci = _recset->column_info(c); + if (ci._type == _nullfld) + continue; + + const TVariant& var = _recset->get(c); + if (ci._name.len() == 8 && isdigit(ci._name[2])) + name = ci._name; + else + name.format("%d", int(c+1)); + if (name == last) + { + TToken_string& prev = sheet.row(sheet.items()-1); + TString tmp; + tmp << prev.get(2) << var.as_string().mid(1); + prev.add(tmp, 2); + continue; + } + last = name; + + TToken_string row; + row = name; + switch (ci._type) + { + case _charfld: + case _alfafld: + row.add(" "); + row.add(var.as_string()); + break; + case _datefld: + row.add("D"); + row.add(var.as_date().string()); + break; + case _realfld: + row.add("V"); + row.add(var.as_string()); + break; + case _boolfld: + row.add("B"); + row.add(var.as_bool() ? "1" : "0"); + break; + default : + row.add("N"); + row.add(var.as_string()); + break; + } + row.add(ci._name, 3); + const int nr = sheet.rows_array().add(row); + if (c == 0 || name.len() == 8) + sheet.disable_row(nr); + } + sheet.force_update(); + sheet.show(); + _dirty_row.reset(); + + const TFilename n = _recset->query_text(); + TString80 msg; msg.format(FR("%s Record n. %ld"), n.name(), _recset->current_row()+1); + xvtil_statbar_set(msg); +} + +void TCU_editor::save_page() +{ + TSheet_field& sheet = sfield(F_PATH); + TString8 code; + FOR_EACH_SHEET_ROW(sheet, r, row) if (_dirty_row[r]) + { + code = row->get(0); + const bool positional = real::is_natural(code); + if (positional) + { + TVariant var = row->get(2); + _recset->set_field(atoi(code), var); + } + } + _dirty_row.reset(); +} + +void TCU_editor::save_file() +{ + const TFilename fn = _recset->query_text(); + save_page(); + if (_recset->save(fn)) + _dirty_file = false; + else + cantwrite_box(fn); +} + +bool TCU_editor::save_page_if_dirty() +{ + bool go = true; + if (_dirty_row.first_one() >= 0) + { + const KEY k = yesnocancel_box(TR("Alcuni campi risultano modificati:\nSi desidera aggiornarli prima di proseguire?")); + go = k != K_ESC; + if (k == K_YES) + save_page(); + } + return go; +} + +bool TCU_editor::find_text() +{ + _txt.trim(); _txt.upper(); + const int txtlen = _txt.len(); + if (txtlen <= 0) + return false; + + const TRecnotype cur_pos = _recset->current_row(); + + TRecnotype best = cur_pos; + double score = (txtlen-1.1)/txtlen; + TString str; + + while (score < 1.0) + { + if (!_recset->move_next()) + if (!_recset->move_first()) + break; + if (_recset->current_row() == cur_pos) + break; + + const unsigned int cols = _recset->columns(); + for (unsigned int i = 1; i < cols; i++) + { + const TVariant& var = _recset->get(i); + if (var.type() == _alfafld) + { + str = var.as_string(); str.trim(); + const int slen = str.len(); + if (slen >= txtlen-1) + { + str.upper(); + if (str.find(_txt) >= 0) + { + best = _recset->current_row(); + score = 1.0; + break; + } + else + { + if (score > 0.75) // Provo a cercare la sottostringa pił simile + { + for (int i = str.find(_txt[0]); i >= 0; i = str.find(_txt[0], i+1)) + { + const double k = xvt_str_fuzzy_compare(str.mid(i, txtlen), _txt); + if (k > score) + { + best = _recset->current_row(); + score = k; + } + } + } + } + } + } + } + } + _recset->move_to(best); + return best != cur_pos; +} + +bool TCU_editor::on_field_event(TOperable_field& o, TField_event e, long jolly) +{ + switch (o.dlg()) + { + case DLG_FIRSTREC: if (e == fe_button && save_page_if_dirty() && _recset->move_first()) load(); return false; + case DLG_PREVREC : if (e == fe_button && save_page_if_dirty() && _recset->move_prev()) load(); return false; + case DLG_NEXTREC : if (e == fe_button && save_page_if_dirty() && _recset->move_next()) load(); return false; + case DLG_LASTREC : if (e == fe_button && save_page_if_dirty() && _recset->move_last()) load(); return false; + case DLG_PREVIEW : + { + const TFilename fn = _recset->query_text(); + if (fn.exist()) + print_cu(fn, _quality); + } + return false; + case DLG_SAVEREC: + if (e == fe_button && _dirty_file) + { + save_file(); + o.enable(_dirty_file); + } + break; + case DLG_FINDREC: + if (e == fe_button) + { + ::xvt_dm_post_string_prompt(TR("Inserire il codice da ricercare"), _txt.get_buffer(81), 80); + if (_txt.full() && save_page_if_dirty()) + { + if (find_text()) + load(); + else + warning_box("Nessuna corrispondenza"); + } + return false; + } + break; + case F_PATH: + switch (e) + { + case fe_init : + if (jolly <= 0) + load(); + break; + case fe_close : + if (_dirty_file) + { + const KEY k = yesnocancel_box(TR("Alcuni record risultano modificati:\nSi desidera salvare il file?")); + if (k == K_ESC) + return false; + if (k == K_YES) + save_file(); + } + break; + case se_notify_modify: + if (o.shown()) + { + _dirty_row.set(jolly); + enable(DLG_SAVEREC, _dirty_file = true); + } + break; + case se_query_modify : + return ((TSheet_field&)o).row_enabled(jolly); + case se_query_del : + return false; + default: break; + } + break; + default: break; + } + return true; +} + +TCU_editor::TCU_editor(const TFilename& fn, int quality) : TAutomask("777200b"), _quality(quality) +{ + _recset = new TTrasferimentoCU(fn, 'r'); + _recset->move_first(); + enable(DLG_SAVEREC, _dirty_file = false); +} + +void edit_cu(const TFilename& datafile, int quality) +{ + if (datafile.exist()) + { + TCU_editor m(datafile, quality); + m.run(); + xvtil_statbar_set(NULL); + } + else + cantread_box(datafile); +} diff --git a/m770/77lib01.cpp b/m770/77lib01.cpp index a628e786a..109eceda5 100755 --- a/m770/77lib01.cpp +++ b/m770/77lib01.cpp @@ -144,9 +144,12 @@ int conta_tipiper(const long codit, TString& quadro, int* NumFisiche, int* NumNo // Ritorna l'anno di dichiarazione sui parametri di studio int anno_770() { + /* TConfig conf(CONFIG_STUDIO, "77"); const int anno = conf.get_int(ANNO_SEL, NULL, -1, TDate(TODAY).year()); return anno; + */ + return ini_get_int(CONFIG_STUDIO, "77", ANNO_SEL, TDate(TODAY).year()); } long get_firm_770() diff --git a/m770/77menu.men b/m770/77menu.men index f4c6923c1..f3d08e50f 100755 --- a/m770/77menu.men +++ b/m770/77menu.men @@ -5,10 +5,11 @@ Module = 4 Flags = "" Item_01 = "Attivazione sostituto", "776mod -1", "" Item_02 = "Gestione percipienti", "776mod -0", "" -Item_03 = "Stampe",[77MENU_002] -Item_04 = "Tabella causali", "773mod -3 %ca7", "" -Item_05 = "Azzeramento archivi", "774 -2 T", "" -Item_06 = "Parametri di studio", "773mod -0", "" +Item_03 = "Tabella causali", "773mod -3 %ca7", "" +Item_04 = "Azzeramento archivi", "774 -2 T", "" +Item_05 = "Parametri di studio", "773mod -0", "" +Item_06 = "Certificazione Unica", "777 -1", "" +Item_07 = "Stampe",[77MENU_002] [77MENU_002] Caption = "Stampe"