Files correlati : Ricompilazione Demo : [ ] Commento :aggiunto metodo con diversa chiamata parametri git-svn-id: svn://10.65.10.50/trunk@18309 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1350 lines
		
	
	
		
			39 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1350 lines
		
	
	
		
			39 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "gv0.h"
 | |
| #include "gv0600a.h"
 | |
| #include "gvlib.h"
 | |
| 
 | |
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <modaut.h>
 | |
| #include <progind.h>
 | |
| #include <recarray.h>
 | |
| #include <relation.h>
 | |
| #include <reprint.h>
 | |
| #include <tabutil.h>
 | |
| #include <textset.h>
 | |
| 
 | |
| #include <anagr.h>
 | |
| #include <anafis.h>
 | |
| #include <clifo.h>
 | |
| #include <comuni.h>
 | |
| #include <nditte.h>
 | |
| #include <righef24.h>
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TF24_textset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TF24_textset : public TAS400_recordset
 | |
| {
 | |
|   TAssoc_array _contatori;
 | |
| 	real				 _totale_positivi;
 | |
| 
 | |
| protected:
 | |
|   long add_count(const char* type, long n = 1);
 | |
| 
 | |
| protected:
 | |
|   void add_field(const char* trc, int from, int to, bool req = false, char tipo = 'a', 
 | |
|                  const char* name = "Filler", const char* def = NULL);
 | |
| 
 | |
| public:
 | |
|   virtual TRecnotype new_rec(const char* tipo);
 | |
|   virtual bool destroy(TRecnotype r);
 | |
|   virtual const TString& rec_type(TRecnotype r = -1) const;
 | |
|   virtual bool set(const char* field, const TVariant& v);
 | |
|   
 | |
|   TRecnotype get_count(const char* tipo) const;
 | |
| 	real & totale_positivi() { return _totale_positivi;}
 | |
|   
 | |
|   TF24_textset(const char* query = "");
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TF24_sender
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TF4_sender : public TSkeleton_application
 | |
| {
 | |
|   TF24_textset* _f24;
 | |
|   TLog_report* _log;
 | |
|   bool _errors_logged;
 | |
| 	bool _has_cg;
 | |
| 
 | |
| protected:
 | |
|   bool new_rec(const char* t) { CHECK(t && *t, "Tipo non valido"); return _f24->new_rec(t) > 0; }
 | |
|   void set(const char* field, const TVariant& var);
 | |
|   void set(const char* field, const TString& s)  { set(field, TVariant(s)); }
 | |
|   void set(const char* field, const int n)    { set(field, TVariant((long)n)); }
 | |
|   void set(const char* field, const char* s)  { set(field, TVariant(s)); }
 | |
|   void set(const char* field, const TDate& d) { set(field, TVariant(d)); }
 | |
|   void set(const char* field, const real& v)  { set(field, TVariant(v)); }
 | |
| 
 | |
|   char trib2sec(const TString& tributo);
 | |
|   void split_ragsoc(const TString& ragsoc, bool bPhysical, TString& cognome, TString& nome) const;
 | |
| 
 | |
|   void add_header(const TMask& m);
 | |
|   void add_10_20(const TRecordset& riga, const TMask& m);
 | |
|   void add_erario(TRecordset& riga, real& saldo_tot, real& credito_tot);
 | |
|   void add_inps(TRecordset& riga, real& saldo_tot, real& credito_tot);
 | |
| 	void add_regioni(TRecordset& riga, real& saldo_tot, real& credito_tot);
 | |
| 	void add_ici(TRecordset& riga, real& saldo_tot, real& credito_tot);
 | |
| 	void add_inail(TRecordset& riga, real& saldo_tot, real& credito_tot);
 | |
|   void add_50(TRecordset& riga, const real& saldo_tot, const real& credito_tot, const TMask& m);
 | |
|   void add_delega(long nDelega, const TMask& m);
 | |
|   void add_footer(const TMask& m);
 | |
|   bool set_data_versamento(long nDelega, const TDate& datavers);
 | |
| 
 | |
| public:
 | |
|   void log(int sev, const char* msg);
 | |
| 
 | |
|   virtual void main_loop();
 | |
|   TF4_sender() {}
 | |
| };
 | |
| 
 | |
| TF4_sender& app() { return (TF4_sender&)main_app(); }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TF24_textset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| long TF24_textset::add_count(const char* type, long i)
 | |
| {
 | |
| 	TString4 tipo; tipo.strncpy(type, 2);
 | |
| 
 | |
|   CHECK(strlen(tipo) == 2, "Tipo record non valido");
 | |
|   real* n = (real*)_contatori.objptr(tipo);
 | |
|   if (n == NULL)
 | |
|   {
 | |
|     n = new real;
 | |
|     _contatori.add(tipo, n);
 | |
|   }
 | |
|   *n += i;
 | |
|   return n->integer();
 | |
| }
 | |
| 
 | |
| TRecnotype TF24_textset::get_count(const char* tipo) const
 | |
| {
 | |
|   long i = 0;
 | |
|   if (tipo && *tipo)
 | |
|   {
 | |
|     CHECK(strlen(tipo) == 2, "Tipo record non valido");
 | |
|     real* n = (real*)_contatori.objptr(tipo);
 | |
|     if (n != NULL)
 | |
|       i = n->integer();
 | |
|   }
 | |
|   else
 | |
|     i = items();
 | |
|   return i;
 | |
| }
 | |
| 
 | |
| TRecnotype TF24_textset::new_rec(const char* tipo)
 | |
| {
 | |
|   CHECK(tipo && *tipo, "Tipo record nullo");
 | |
| 
 | |
|   const TRecnotype n = TAS400_recordset::new_rec(tipo);
 | |
|   if (n >= 0)
 | |
|   {
 | |
|     add_count(tipo);
 | |
|     if (strlen(tipo) == 5)
 | |
|     {
 | |
|       TString& str = row(n);
 | |
|       str.overwrite(tipo+3, 10);
 | |
|     }
 | |
|   }
 | |
|   return n;
 | |
| }
 | |
| 
 | |
| const TString& TF24_textset::rec_type(TRecnotype r) const
 | |
| {
 | |
|   const TString& t = TAS400_recordset::rec_type(r);
 | |
|   if (t == "40" || t == "50")
 | |
|   {
 | |
|     TString& tmp = get_tmp_string();
 | |
|     tmp << t << '-' << row(r).mid(10, 2);  // TIPO-SUBTIPO
 | |
|     return tmp;
 | |
|   }
 | |
|   return t;
 | |
| }
 | |
| 
 | |
| bool TF24_textset::destroy(TRecnotype r)
 | |
| {
 | |
|   const bool ok = TAS400_recordset::destroy(r);
 | |
|   if (ok)
 | |
|   {
 | |
|     if (r >= 0)
 | |
|     {
 | |
|       const TString& t = TAS400_recordset::rec_type(r); // Igora subtipo record!
 | |
|       add_count(t, -1);
 | |
|     }
 | |
|     else
 | |
|       _contatori.destroy();
 | |
|   }
 | |
|   return ok; 
 | |
| }
 | |
| 
 | |
| void TF24_textset::add_field(const char* trc, int from, int to, bool required, 
 | |
|                                char tipo, const char* name, const char* def)
 | |
| {
 | |
|   CHECK(trc && *trc, "Tracciato nullo");
 | |
|   TString80 fname; fname << trc << '.' << name;
 | |
| 
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   const int len = to >= from ? to-from+1 : record_length()-pos;
 | |
|   if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(fname, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(fname, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| bool TF24_textset::set(const char* field, const TVariant& var)
 | |
| {
 | |
|   const char* err = NULL;
 | |
|   int c = -1;
 | |
|   const TAS400_column_info* info = parse_field(field, c, false);
 | |
|   bool ok = info != NULL;
 | |
|   if (ok)
 | |
|   {
 | |
|     switch (var.type())
 | |
|     {
 | |
|     case _datefld:
 | |
|       if (var.is_zero())
 | |
|         ok = set_field(*info, NULL_VARIANT);  
 | |
|       else
 | |
|       {
 | |
|         long ansi = 0;
 | |
|         const TDate d = var.as_date();
 | |
|         if (info->_width == 6)
 | |
|           ansi = d.day()*10000 + d.month()*100 + d.year()%100;
 | |
|         else
 | |
|           ansi = d.date2ansi();
 | |
|         ok = set_field(*info, TVariant(ansi)); 
 | |
|       }
 | |
|       break;
 | |
|     case _realfld:
 | |
|       if (var.is_zero())
 | |
|         ok = set_field(*info, NULL_VARIANT);  
 | |
|       else
 | |
|       {
 | |
|         real v = var.as_real(); v *= CENTO;
 | |
|         ok = set_field(*info, TVariant(v.integer()));  
 | |
|       }
 | |
|       break;
 | |
|     default:
 | |
|       ok = set_field(*info, var); 
 | |
|       break;
 | |
|     }
 | |
|     if (!ok)
 | |
|       err = TR("Campo obbligatorio non compilato");
 | |
|   }
 | |
|   else
 | |
|     err = TR("Campo non riconosciuto");
 | |
|   
 | |
|   if (err != NULL)
 | |
|   {
 | |
|     TString msg;
 | |
|     msg  << field << ": " << err;
 | |
|     app().log(2, msg);
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| TF24_textset::TF24_textset(const char* query)
 | |
|              : TAS400_recordset(TString("AS400(120,2,1)\n") << query)
 | |
| {
 | |
|   const char an = 'a';
 | |
|   const char n  = 'n';
 | |
|   const bool o = true;
 | |
|   const bool f = false;
 | |
|   
 | |
|   add_field("F4",  1,  1);
 | |
|   add_field("F4",  2,  3, o, an, "TipoRecord", "F4");
 | |
|   add_field("F4",  4,  8, o, an, "Mittente");
 | |
|   add_field("F4",  9, 13, o,  n, "Ricevente");
 | |
|   add_field("F4", 14, 19, o,  n, "DataCreazione");
 | |
|   add_field("F4", 20, 39, o, an, "NomeSupporto");
 | |
|   add_field("F4", 40, 45, f, an, "Riferimenti");
 | |
|   add_field("F4", 46,104);
 | |
|   add_field("F4",105,105, o, an, "TipoFlusso", "2");
 | |
|   add_field("F4",106,106, o, an, "QualificatoreFlusso", "$");
 | |
|   add_field("F4",107,111, o, an, "SoggettoVeicolatore");
 | |
|   add_field("F4",112,113);
 | |
|   add_field("F4",114,114, o, an, "CodiceDivisa", "E");
 | |
|   add_field("F4",115,120);
 | |
| 
 | |
|   add_field("EF",  1,  1);
 | |
|   add_field("EF",  2,  3, o, an, "TipoRecord", "EF");
 | |
|   add_field("EF",  4,  8, o, an, "Mittente");
 | |
|   add_field("EF",  9, 13, o,  n, "Ricevente");
 | |
|   add_field("EF", 14, 19, o,  n, "DataCreazione");
 | |
|   add_field("EF", 20, 39, o, an, "NomeSupporto");
 | |
|   add_field("EF", 40, 45, f, an, "Riferimenti");
 | |
|   add_field("EF", 46, 52, o,  n, "NumeroDisposizioni");
 | |
|   add_field("EF", 53, 67, o,  n, "TotImportiPositivi");
 | |
|   add_field("EF", 68, 82, o,  n, "TotImportiNegativi");
 | |
|   add_field("EF", 83, 89, o,  n, "NumeroRecord");
 | |
|   add_field("EF", 90,113);
 | |
|   add_field("EF",114,114, o, an, "CodiceDivisa", "E");
 | |
|   add_field("EF",115,120);
 | |
| 
 | |
|   add_field("10",  1,  1);
 | |
|   add_field("10",  2,  3, o, an, "TipoRecord", "10");
 | |
|   add_field("10",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("10", 11, 26, o, an, "CodiceFiscale");
 | |
|   add_field("10", 27, 50, o, an, "Cognome");
 | |
|   add_field("10", 51, 70, f, an, "Nome");
 | |
|   add_field("10", 71, 71, f, an, "Sesso");
 | |
|   add_field("10", 72, 96, f, an, "ComuneNascita");
 | |
|   add_field("10", 97, 98, f, an, "ProvinciaNascita");
 | |
|   add_field("10", 99,106, f,  n, "DataNascita");
 | |
|   add_field("10",107,113, o,  n, "ProtocolloDelega");
 | |
|   add_field("10",114,120);
 | |
| 
 | |
|   add_field("20",  1,  1);
 | |
|   add_field("20",  2,  3, o, an, "TipoRecord", "20");
 | |
|   add_field("20",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("20", 11, 35, o, an, "Comune");
 | |
|   add_field("20", 36, 37, o, an, "Provincia");
 | |
|   add_field("20", 38, 72, o, an, "Indirizzo");
 | |
|   add_field("20", 73, 80, o,  n, "DataPagamento");
 | |
|   add_field("20", 81, 81, f,  n, "FlagAnnoImposta");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("20", 82,120);
 | |
| 
 | |
|   add_field("40-01",  1,  1);
 | |
|   add_field("40-01",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-01",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-01", 11, 12, o, an, "SubtipoRecord", "01");
 | |
|   add_field("40-01", 13, 14, o,  n, "ProgressivoTributo");
 | |
|   add_field("40-01", 15, 18, o, an, "CodiceTributo");
 | |
|   add_field("40-01", 19, 26, o, an, "RiferimentiTributo");
 | |
|   add_field("40-01", 27, 41, f,  n, "ImportoDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-01", 42, 56, f,  n, "ImportoCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-01", 57, 59, f, an, "CodiceUfficio");
 | |
|   add_field("40-01", 60, 70, f,  n, "CodiceAtto");
 | |
|   add_field("40-01", 71,120);
 | |
| 
 | |
|   add_field("40-02",  1,  1);
 | |
|   add_field("40-02",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-02",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-02", 11, 12, o, an, "SubtipoRecord", "02");
 | |
|   add_field("40-02", 13, 27, f,  n, "TotaleDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-02", 28, 42, f,  n, "TotaleCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-02", 43, 43, o, an, "SegnoSezione");
 | |
|   add_field("40-02", 44, 58, f,  n, "SaldoSezione");
 | |
|   add_field("40-02", 59,120);
 | |
| 
 | |
|   add_field("40-03",  1,  1);
 | |
|   add_field("40-03",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-03",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-03", 11, 12, o, an, "SubtipoRecord", "03");
 | |
|   add_field("40-03", 13, 14, o,  n, "ProgressivoContributo");
 | |
|   add_field("40-03", 15, 18, o,  n, "CodiceSede");
 | |
|   add_field("40-03", 19, 22, o, an, "CausaleContributo");
 | |
|   add_field("40-03", 23, 39, o, an, "MatricolaINPS");
 | |
|   add_field("40-03", 40, 45, o,  n, "PeriodoInizio");
 | |
|   add_field("40-03", 46, 51, f,  n, "PeriodoFine");
 | |
|   add_field("40-03", 52, 66, f,  n, "ImportoDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-03", 67, 81, f,  n, "ImportoCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-03", 82,120);
 | |
| 
 | |
|   add_field("40-04",  1,  1);
 | |
|   add_field("40-04",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-04",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-04", 11, 12, o, an, "SubtipoRecord", "04");
 | |
|   add_field("40-04", 13, 27, f,  n, "TotaleDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-04", 28, 42, f,  n, "TotaleCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-04", 43, 43, o, an, "SegnoSezione");
 | |
|   add_field("40-04", 44, 58, f,  n, "SaldoSezione");
 | |
|   add_field("40-04", 59,120);
 | |
| 
 | |
|   add_field("40-05",  1,  1);
 | |
|   add_field("40-05",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-05",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-05", 11, 12, o, an, "SubtipoRecord", "05");
 | |
|   add_field("40-05", 13, 14, o,  n, "CodiceRegione");
 | |
|   add_field("40-05", 15, 16, o,  n, "ProgressivoContributo");
 | |
|   add_field("40-05", 17, 20, o, an, "CodiceTributo");
 | |
|   add_field("40-05", 21, 28, o, an, "RiferimentiTributo");
 | |
|   add_field("40-05", 29, 43, f,  n, "ImportoDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-05", 44, 58, f,  n, "ImportoCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-05", 59,120);
 | |
| 
 | |
|   add_field("40-06",  1,  1);
 | |
|   add_field("40-06",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-06",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-06", 11, 12, o, an, "SubtipoRecord", "06");
 | |
|   add_field("40-05", 13, 14);
 | |
|   add_field("40-06", 15, 29, f,  n, "TotaleDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-06", 30, 44, f,  n, "TotaleCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-06", 45, 45, o, an, "SegnoSezione");
 | |
|   add_field("40-06", 46, 60, f,  n, "SaldoSezione");
 | |
|   add_field("40-06", 61,120);
 | |
| 
 | |
|   add_field("40-07",  1,  1);
 | |
|   add_field("40-07",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-07",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-07", 11, 12, o, an, "SubtipoRecord", "07");
 | |
|   add_field("40-07", 13, 16, o, an, "CodiceEnte");
 | |
|   add_field("40-07", 17, 18, o,  n, "ProgressivoContributo");
 | |
|   add_field("40-07", 19, 22, o, an, "CodiceTributo");
 | |
|   add_field("40-07", 23, 30, o, an, "RiferimentiTributo");
 | |
|   add_field("40-07", 31, 45, f,  n, "ImportoDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-07", 46, 60, f,  n, "ImportoCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-07", 61, 61, f,  n, "Ravvedimento");
 | |
|   add_field("40-07", 62, 62, f,  n, "ImmobiliVariati");
 | |
|   add_field("40-07", 63, 63, f,  n, "Acconto");
 | |
|   add_field("40-07", 64, 64, f,  n, "Saldo");
 | |
|   add_field("40-07", 65, 66, f,  n, "NumeroFabbricati");
 | |
|   add_field("40-07", 67, 82, f,  n, "DetrazioneICI"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-07", 83,120);
 | |
| 
 | |
|   add_field("40-08",  1,  1);
 | |
|   add_field("40-08",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-08",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-08", 11, 12, o, an, "SubtipoRecord", "08");
 | |
|   add_field("40-08", 13, 16);
 | |
|   add_field("40-08", 17, 31, f,  n, "TotaleDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-08", 32, 46, f,  n, "TotaleCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-08", 47, 47, o, an, "SegnoSezione");
 | |
|   add_field("40-08", 48, 62, f,  n, "SaldoSezione");
 | |
|   add_field("40-08", 63,120);
 | |
|   
 | |
|   add_field("40-09",  1,  1);
 | |
|   add_field("40-09",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-09",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-09", 11, 12, o, an, "SubtipoRecord", "09");
 | |
|   add_field("40-09", 13, 14, o,  n, "ProgressivoContributo");
 | |
|   add_field("40-09", 15, 19, o,  n, "CodiceSede");
 | |
|   add_field("40-09", 20, 27, o,  n, "NumeroPosizioneAssicurativa");
 | |
|   add_field("40-09", 28, 29, o,  n, "CCNumeroPosizioneAssicurativa");
 | |
|   add_field("40-09", 30, 30, o, an, "Causale");
 | |
|   add_field("40-09", 31, 34);
 | |
|   add_field("40-09", 35, 40, o,  n, "NumeroDiRiferimento");
 | |
|   add_field("40-09", 41, 55, f,  n, "ImportoDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-09", 56, 70, f,  n, "ImportoCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-09", 71,120);
 | |
| 
 | |
|   add_field("40-10",  1,  1);
 | |
|   add_field("40-10",  2,  3, o, an, "TipoRecord", "40");
 | |
|   add_field("40-10",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("40-10", 11, 12, o, an, "SubtipoRecord", "10");
 | |
|   add_field("40-10", 13, 27, f,  n, "TotaleDebito");  // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-10", 28, 42, f,  n, "TotaleCredito"); // non sarebbe f, ma 0 e' valido
 | |
|   add_field("40-10", 43, 43, o, an, "SegnoSezione");
 | |
|   add_field("40-10", 44, 58, f,  n, "SaldoSezione");
 | |
|   add_field("40-10", 59,120);
 | |
|   
 | |
| 	add_field("50-01",  1,  1);
 | |
|   add_field("50-01",  2,  3, o, an, "TipoRecord", "50");
 | |
|   add_field("50-01",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("50-01", 11, 12, o, an, "SubtipoRecord", "01");
 | |
|   add_field("50-01", 13, 17, o,  n, "BancaPassiva");
 | |
|   add_field("50-01", 18, 22, o,  n, "SportelloPassivo");
 | |
|   add_field("50-01", 23, 34, o,  n, "ContoAddebito");
 | |
|   add_field("50-01", 35, 35, f, an, "Cin");
 | |
|   add_field("50-01", 36, 50, f,  n, "SaldoFinale");
 | |
|   add_field("50-01", 51, 51, f,  n, "FlagFirmatario");
 | |
|   add_field("50-01", 52, 53);
 | |
|   add_field("50-01", 54, 69, o, an, "CodiceFiscale");
 | |
|   add_field("50-01", 70, 70, o,  n, "TitolarePagamento");
 | |
|   add_field("50-01", 71, 78, o,  n, "DataPagamento");
 | |
|   add_field("50-01", 79, 93, f,  n, "TotaleImportiCredito");
 | |
|   add_field("50-01", 94, 95);
 | |
|   add_field("50-01", 96, 96, o,  n, "CodiceIndividuale", "3");
 | |
|   add_field("50-01", 97,120);
 | |
| 
 | |
|   add_field("50-02",  1,  1);
 | |
|   add_field("50-02",  2,  3, o, an, "TipoRecord", "50");
 | |
|   add_field("50-02",  4, 10, o,  n, "ProgressivoDelega");
 | |
|   add_field("50-02", 11, 12, o, an, "SubtipoRecord", "02");
 | |
|   add_field("50-02", 13, 28, o, an, "CodiceFiscaleMittente");
 | |
|   add_field("50-02", 29, 32);
 | |
|   add_field("50-02", 33, 37, o,  n, "ABI");
 | |
|   add_field("50-02", 38, 42, o,  n, "CAB");
 | |
|   add_field("50-02", 43, 62, f,  an, "CodiceClienteBancario");
 | |
|   add_field("50-02", 63, 63, o,  an, "DestinatarioStampa", "1");
 | |
|   add_field("50-02", 64,108, o, an, "Denominazione");
 | |
|   add_field("50-02",109,120);
 | |
| 
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TF4_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TF24_mask : public TAutomask
 | |
| {
 | |
|   clock_t _next_update;
 | |
|   bool _updating;
 | |
| 
 | |
| private:
 | |
|   bool apply_filter(const TRecordset& righe) const;
 | |
|   void update_sheet();
 | |
|   void invalidate_sheet();
 | |
|   void serialize(bool bSave);
 | |
| 
 | |
| protected:
 | |
|   virtual void on_idle();
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   TF24_mask();
 | |
|   ~TF24_mask();
 | |
| };
 | |
| 
 | |
| bool TF24_mask::apply_filter(const TRecordset& righe) const
 | |
| {
 | |
|   const TDate dal = get(F_DATA_DA);
 | |
|   const TDate al = get(F_DATA_AL);
 | |
|   if (dal.ok() || al.ok())
 | |
|   {
 | |
|     const TDate scad = righe.get("DATASCAD").as_date();
 | |
|     if ((dal.ok() && scad < dal) || (al.ok() && scad > al))
 | |
|       return false;
 | |
|   }
 | |
| 
 | |
|   const long abi = get_long(F_ABI);
 | |
|   const long cab = get_long(F_CAB);
 | |
|   if (abi > 0 || cab > 0)
 | |
|   {
 | |
|     const long rabi = righe.get("ABI").as_int();
 | |
|     const long rcab = righe.get("CAB").as_int();
 | |
|     if ((abi > 0 && abi != rabi) || (cab > 0 && cab != rcab))
 | |
|       return false;
 | |
|   }
 | |
| 
 | |
|   const char tipoint = get(F_TIPOINTEST)[0];
 | |
|   if (tipoint > ' ')
 | |
|   {
 | |
|     const char rtipoint = righe.get("TIPOINTEST").as_string()[0];
 | |
|     if (tipoint != rtipoint)
 | |
|       return false;
 | |
| 
 | |
|     long codint = 0;
 | |
|     switch (tipoint)
 | |
|     {
 | |
|     case 'C': codint = get_long(F_CLIFO); break;
 | |
|     case 'F':
 | |
|     case 'G': codint = get_long(F_PERSON); break;
 | |
|     default : break;
 | |
|     }
 | |
|     if (codint != 0)
 | |
|     {
 | |
|       const long rcodint = righe.get("INTEST").as_int();
 | |
|       if (codint != rcodint)
 | |
|         return false;
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| void TF24_mask::update_sheet()
 | |
| {
 | |
|   if (!_updating)
 | |
|   {
 | |
|     _updating = true;
 | |
|     _next_update = 0;
 | |
| 
 | |
|     TSheet_field& s = sfield(F_DISTINTE);
 | |
|     TMask& m = s.sheet_mask();
 | |
| 
 | |
|     s.destroy();
 | |
| 
 | |
|     int flags = 1;
 | |
|     switch (get(F_FILTER)[0])
 | |
|     {
 | |
|     case 'Q': flags = 0; break; // Tutte
 | |
|     case 'I': flags = 2; break; // Inviate
 | |
|     default : flags = 1; break; // Da inviare
 | |
|     }
 | |
| 
 | |
|     TElencoF24_set righe(flags);
 | |
|     TProgind pi(righe.items(), "Lettura F24", true, true);
 | |
|     for (bool ok = righe.move_first(); ok; ok = righe.move_next())
 | |
|     {
 | |
|       if (apply_filter(righe))
 | |
|       {
 | |
|         TToken_string& row = s.row(-1);
 | |
|         for (int i = m.fields()-1; i > 0; i--)
 | |
|         {
 | |
|           const TMask_field& f = m.fld(i);
 | |
|           const TFieldref* fr = f.field();
 | |
|           if (fr != NULL)
 | |
|           {
 | |
|             const int pos = s.cid2index(f.dlg());
 | |
|             row.add(righe.get(fr->name()).as_string(), pos);
 | |
|           }
 | |
|         }
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     s.force_update();
 | |
|     _updating = false;
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TF24_mask::invalidate_sheet()
 | |
| {
 | |
|   _next_update = clock()+CLOCKS_PER_SEC/2; // Aspetta mezzo secondo!
 | |
| }
 | |
| 
 | |
| void TF24_mask::on_idle()
 | |
| {
 | |
|   // Aggiorna lo sheet, ma non troppo spesso!
 | |
|   if (_next_update != 0 && !_updating && clock() > _next_update)
 | |
|     update_sheet();
 | |
| }
 | |
| 
 | |
| bool TF24_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   bool ok = true;
 | |
|   switch (o.dlg())
 | |
|   {
 | |
|   case F_FILTER:
 | |
|   case F_DATA_DA:
 | |
|   case F_DATA_AL:
 | |
|   case F_ABI:
 | |
|   case F_CAB:
 | |
|   case F_TIPOINTEST:
 | |
|   case F_CLIFO:
 | |
|   case F_PERSON:
 | |
|     if (e == fe_modify)
 | |
|       invalidate_sheet();
 | |
|     break;
 | |
|   case F_DISTINTE:
 | |
|     switch (e)
 | |
|     {
 | |
|     case fe_init: 
 | |
|       update_sheet();
 | |
|       break;
 | |
|     case se_query_modify:
 | |
|     case se_query_add:
 | |
|     case se_query_del:
 | |
|       ok = false;
 | |
|     default:
 | |
|       break;
 | |
|     }
 | |
|     break;
 | |
|   default:
 | |
|     break;
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| void TF24_mask::serialize(bool bSave)
 | |
| {
 | |
|   const char* defpar = "gv";
 | |
|   TConfig ini(CONFIG_DITTA, defpar);
 | |
|   for (int i = fields()-1; i >= 0; i--)
 | |
|   {
 | |
|     TMask_field& f = fld(i);
 | |
|     const TFieldref* fr = f.field();
 | |
|     if (fr != NULL)
 | |
|     {
 | |
|       if (bSave)
 | |
|         fr->write(ini, defpar, f.get());
 | |
|       else
 | |
|         f.set(fr->read(ini, defpar));
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| TF24_mask::TF24_mask() 
 | |
|          : TAutomask("gv0600a"), _updating(false), _next_update(0)
 | |
| {
 | |
|   serialize(false);
 | |
| 	enable(F_CONTABILIZZA, app().has_module(CGAUT));
 | |
| }
 | |
| 
 | |
| TF24_mask::~TF24_mask()
 | |
| {
 | |
|   serialize(true);
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TF4_sender
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| void TF4_sender::log(int sev, const char* msg)
 | |
| { 
 | |
|   if (sev > 0)
 | |
|   {
 | |
|     TString m;
 | |
|     m << TR("Record") << ' ' << _f24->rec_type() << ": " << msg;
 | |
|     _log->log(sev, m); 
 | |
|     _errors_logged = true;
 | |
|   }
 | |
|   else
 | |
|     _log->log(sev, msg);
 | |
| }
 | |
| 
 | |
| void TF4_sender::set(const char* field, const TVariant& var) 
 | |
| { 
 | |
|   _f24->set(field, var);
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_header(const TMask& m)
 | |
| {
 | |
|   new_rec("F4");
 | |
|   set("Mittente",      m.get(F_MITTENTE));
 | |
|   set("Ricevente",     m.get(F_ABI));
 | |
|   set("DataCreazione", m.get_date(F_DATA));
 | |
|   set("NomeSupporto",  m.get(F_FILE));  // Somma dei tre campi precedenti
 | |
| 	set("SoggettoVeicolatore", m.get(F_MITTENTE));
 | |
| }
 | |
| 
 | |
| void TF4_sender::split_ragsoc(const TString& ragsoc, bool bPhysical, 
 | |
|                               TString& cognome, TString& nome) const
 | |
| {
 | |
|   const int maxc = 24, maxn = 20;  // Sarebbe bello prenderli dal tracciato, ma ...
 | |
|   if (bPhysical)
 | |
|   {
 | |
|     TParagraph_string rs(ragsoc, maxc);
 | |
|     cognome = rs.get();
 | |
|     nome = ragsoc.mid(30);
 | |
|     if (nome.len() > maxn)
 | |
|     {
 | |
|       TParagraph_string rs(nome, maxn);
 | |
|       nome = rs.get();
 | |
|     }
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     TParagraph_string rs(ragsoc, maxc+maxn);
 | |
|     cognome = rs.get();
 | |
|     nome = cognome.mid(maxc);
 | |
|     cognome.cut(maxc);
 | |
|   }
 | |
|   CHECKS(cognome.len()<=maxc && nome.len()<=maxn, "Ragsoc balorda", (const char*)ragsoc);
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_10_20(const TRecordset& riga, const TMask& m)
 | |
| {
 | |
|   const char tipointest = riga.get("TIPOINTEST").as_string()[0];
 | |
|   const long intest = riga.get("INTEST").as_int();
 | |
| 
 | |
|   TString80 codfis, ragsoc;
 | |
| 
 | |
|   char tipoa = tipointest;
 | |
|   long codanagr = intest; 
 | |
| 
 | |
|   TString16 key;
 | |
| 
 | |
|   if (tipointest == 'C')
 | |
|   {
 | |
|     key.cut(0) << "C|" << intest;
 | |
|     const TRectype& cli = cache().get(LF_CLIFO, key);
 | |
|     codfis = cli.get(CLI_COFI);
 | |
|     ragsoc = cli.get(CLI_RAGSOC);
 | |
|     
 | |
|     tipoa = cli.get_char(CLI_TIPOAPER);
 | |
|     codanagr = cli.get_long(CLI_CODANAGPER);
 | |
|     if (codfis.blank())
 | |
|       codfis = cli.get(CLI_PAIV);
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     if (tipoa == 'D')
 | |
|     {
 | |
|       tipoa = prefix().firm().get(NDT_TIPOA)[0];
 | |
|       codanagr = prefix().firm().get_long(NDT_CODANAGR);
 | |
|     }
 | |
|     key.cut(0) << tipoa << '|' << codanagr;
 | |
|     const TRectype& anag = cache().get(LF_ANAG, key);
 | |
|     ragsoc = anag.get(ANA_RAGSOC);
 | |
|     codfis = anag.get(ANA_COFI);
 | |
|     if (codfis.blank())
 | |
|       codfis = anag.get(ANA_PAIV);
 | |
|   }
 | |
| 
 | |
|   /////////////////////////////////////////////////////////
 | |
|   // Tipo record 10
 | |
|   /////////////////////////////////////////////////////////
 | |
| 
 | |
|   const long nProgr = _f24->get_count("10")+1;  // Sfrutto il suo contatore!
 | |
|   if (new_rec("10"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgr);
 | |
|     set("CodiceFiscale", codfis);
 | |
| 
 | |
|     TString80 cognome, nome;
 | |
|     split_ragsoc(ragsoc, tipoa == 'F', cognome, nome);
 | |
|     set("Cognome", cognome);
 | |
|     set("Nome", nome);
 | |
| 
 | |
|     if (tipoa == 'F' && codanagr > 0)
 | |
|     {
 | |
|       const TRectype& anf = cache().get(LF_ANAGFIS, codanagr);
 | |
|       set("Sesso", anf.get(ANF_SESSO));
 | |
|       const TString4 comnasc = anf.get(ANF_COMNASC);
 | |
|       set("ComuneNascita", comnasc);
 | |
|       if (comnasc < "Z") // Nato in Italia
 | |
|       {
 | |
|         key = " |"; key << comnasc;
 | |
|         const TRectype& com = cache().get(LF_COMUNI, key);
 | |
|         set("ProvinciaNascita", com.get(COM_PROVCOM));
 | |
|       }
 | |
|       else
 | |
|         set("ProvinciaNascita", "EE");
 | |
|     }
 | |
| 		set("ProtocolloDelega", riga.get("F24"));
 | |
| 
 | |
|   }
 | |
|   
 | |
|   /////////////////////////////////////////////////////////
 | |
|   // Tipo record 20
 | |
|   /////////////////////////////////////////////////////////
 | |
|   if (new_rec("20"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgr);
 | |
|     set("DataPagamento", m.get_date(F_DATAPAG));
 | |
| 
 | |
|     TString80 indirizzo;
 | |
|     if (tipointest == 'C')
 | |
|     {
 | |
|       key.cut(0) << "C|" << intest;
 | |
|       const TRectype& cli = cache().get(LF_CLIFO, key);
 | |
|       key.cut(0) << cli.get(CLI_STATOCF) << '|' << cli.get(CLI_COMCF);
 | |
| 
 | |
|       indirizzo << cli.get(CLI_INDCF) << ' ' << cli.get(CLI_CIVCF) 
 | |
|                 << ' ' << cli.get(CLI_LOCCF);
 | |
| 
 | |
|     } else
 | |
|     if (tipoa == 'F' || tipoa == 'G')
 | |
|     {
 | |
|       key.cut(0) << tipoa << '|' << codanagr;
 | |
|       const TRectype& anag = cache().get(LF_ANAG, key);
 | |
| 
 | |
|       key.cut(0) << anag.get(ANA_STATORES) << '|' << anag.get(ANA_COMRES);
 | |
|       indirizzo << anag.get(ANA_INDRES) << ' ' << anag.get(ANA_CIVRES);
 | |
|     }
 | |
|   
 | |
|     const TRectype& com = cache().get(LF_COMUNI, key);
 | |
|     set("Comune", com.get(COM_DENCOM));
 | |
|     set("Provincia", com.get(COM_PROVCOM));
 | |
| 
 | |
|     TParagraph_string ind(indirizzo, 35);
 | |
|     set("Indirizzo", ind.get()); // Salva i primi 35 caratteri dell'indirizzo
 | |
|   }
 | |
| }
 | |
| 
 | |
| char TF4_sender::trib2sec(const TString& tributo)
 | |
| {
 | |
|   const char* err = NULL;
 | |
|   char sec = ' ';
 | |
|   const TRectype& trb = cache().get("%TRB", tributo);
 | |
|   if (trb.empty())
 | |
|   {
 | |
|     err = TR("Non presente in tabella");  
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     sec = toupper(trb.get_char("S6"));
 | |
|     if (!isalpha(sec))
 | |
|       err = TR("Sezione F24 non valida");
 | |
|   }
 | |
|   if (err)
 | |
|   {
 | |
|     TString msg;
 | |
|     msg << TR("Codice tributo") << " (" <<  tributo << ") :" << err;
 | |
|     log(2, msg);
 | |
|   }
 | |
|   return sec;
 | |
| }
 | |
| 
 | |
| 
 | |
| void TF4_sender::add_erario(TRecordset& riga, real& saldo_tot, real& credito_tot)
 | |
| {
 | |
|   const long nProgDelega = _f24->get_count("10");
 | |
| 
 | |
|   int nProgr = 0;
 | |
|   real debito, credito;
 | |
| 
 | |
|   for (bool ok = riga.move_first(); ok ; ok = riga.move_next())
 | |
|   {
 | |
|     const TString4 tributo = riga.get("TRIBUTO").as_string();
 | |
|     const char sezione = trib2sec(tributo);
 | |
|     if (sezione == 'E')
 | |
|     {
 | |
|       if (new_rec("40-01"))
 | |
|       {
 | |
|         set("ProgressivoDelega", nProgDelega);
 | |
|         set("ProgressivoTributo", ++nProgr);
 | |
|         set("CodiceTributo", tributo);
 | |
| 				TString16 rif(riga.get("RATEAZIONE").as_string());
 | |
| 
 | |
| 				if (riga.get("ANNO").as_int() > 0)
 | |
| 					rif << riga.get("ANNO").as_string();
 | |
| 				if (rif.blank())
 | |
| 					rif ="00000000";
 | |
| 				set("RiferimentiTributo", rif);
 | |
|         
 | |
|         const real d = riga.get("IMPORTODEB").as_real();
 | |
|         set("ImportoDebito", d);
 | |
|         debito += d;
 | |
| 
 | |
|         const real c = riga.get("IMPORTOCRE").as_real();
 | |
|         set("ImportoCredito", c);
 | |
|         credito += c;
 | |
|         
 | |
|         if (nProgr > 6)
 | |
|           log(2, "Numero eccessivo di righe nella sezione Erario");
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   const real saldo = debito-credito;
 | |
|   if (nProgr > 0 && new_rec("40-02"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
|     set("TotaleDebito", debito);
 | |
|     set("TotaleCredito", credito);
 | |
|     set("SegnoSezione", saldo < ZERO ? "N" : "P");
 | |
|     set("SaldoSezione", saldo < ZERO ? -saldo : saldo);
 | |
|   }
 | |
| 
 | |
|   saldo_tot += saldo;
 | |
|   credito_tot += credito;
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_inps(TRecordset& riga, real& saldo_tot, real& credito_tot)
 | |
| {
 | |
|   const long nProgDelega = _f24->get_count("10");
 | |
| 
 | |
|   int nProgr = 0;
 | |
|   real debito, credito;
 | |
| 
 | |
|   for (bool ok = riga.move_first(); ok ; ok = riga.move_next())
 | |
|   {
 | |
|     const TString4 tributo = riga.get("TRIBUTO").as_string();
 | |
|     const char sezione = trib2sec(tributo);
 | |
|     if (sezione == 'I')
 | |
|     {
 | |
|       if (new_rec("40-03"))
 | |
|       {
 | |
|         set("ProgressivoDelega", nProgDelega);
 | |
|         set("ProgressivoContributo", ++nProgr);
 | |
|         set("CausaleContributo", tributo);
 | |
| 				set("CodiceSede", riga.get("SEDE"));
 | |
| 				set("MatricolaINPS", riga.get("MATRICOLA"));
 | |
| 				set("PeriodoInizio", riga.get("PERIODODA"));
 | |
| 				set("PeriodoFine", riga.get("PERIODOA"));        
 | |
|         const real d = riga.get("IMPORTODEB").as_real();
 | |
|         set("ImportoDebito", d);
 | |
|         debito += d;
 | |
| 
 | |
|         const real c = riga.get("IMPORTOCRE").as_real();
 | |
|         set("ImportoCredito", c);
 | |
|         credito += c;
 | |
| 
 | |
|         if (nProgr > 4)
 | |
|           log(2, "Numero eccessivo di righe nella sezione INPS");
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   const real saldo = debito-credito;
 | |
|   if (nProgr > 0 && new_rec("40-04"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
|     set("TotaleDebito", debito);
 | |
|     set("TotaleCredito", credito);
 | |
|     set("SegnoSezione", saldo < ZERO ? "N" : "P");
 | |
|     set("SaldoSezione", saldo < ZERO ? -saldo : saldo);
 | |
|   }
 | |
| 
 | |
|   saldo_tot += saldo;
 | |
|   credito_tot += credito;
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_regioni(TRecordset& riga, real& saldo_tot, real& credito_tot)
 | |
| {
 | |
|   const long nProgDelega = _f24->get_count("10");
 | |
| 
 | |
|   int nProgr = 0;
 | |
|   real debito, credito;
 | |
| 
 | |
|   for (bool ok = riga.move_first(); ok ; ok = riga.move_next())
 | |
|   {
 | |
|     const TString4 tributo = riga.get("TRIBUTO").as_string();
 | |
|     const char sezione = trib2sec(tributo);
 | |
|     if (sezione == 'R')
 | |
|     {
 | |
|       if (new_rec("40-05")) // qui
 | |
|       {
 | |
| 
 | |
|         set("ProgressivoDelega", nProgDelega);
 | |
|         set("ProgressivoContributo", ++nProgr);
 | |
|         set("CodiceRegione", riga.get("CODREG").as_int());
 | |
|         set("CodiceTributo", tributo);
 | |
| 
 | |
| 				TString16 rif(riga.get("RATEAZIONE").as_string());
 | |
| 
 | |
| 				if (riga.get("ANNO").as_int() > 0)
 | |
| 					rif << riga.get("ANNO").as_string();
 | |
| 				if (rif.blank())
 | |
| 					rif ="00000000";
 | |
| 				set("RiferimentiTributo", rif);
 | |
|         
 | |
|         const real d = riga.get("IMPORTODEB").as_real();
 | |
|         set("ImportoDebito", d);
 | |
|         debito += d;
 | |
| 
 | |
|         const real c = riga.get("IMPORTOCRE").as_real();
 | |
|         set("ImportoCredito", c);
 | |
|         credito += c;
 | |
| 
 | |
|         if (nProgr > 4)
 | |
|           log(2, "Numero eccessivo di righe nella sezione Regione");
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   const real saldo = debito-credito;
 | |
|   if (nProgr > 0 && new_rec("40-06"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
|     set("TotaleDebito", debito);
 | |
|     set("TotaleCredito", credito);
 | |
|     set("SegnoSezione", saldo < ZERO ? "N" : "P");
 | |
|     set("SaldoSezione", saldo < ZERO ? -saldo : saldo);
 | |
|   }
 | |
| 
 | |
|   saldo_tot += saldo;
 | |
|   credito_tot += credito;
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_ici(TRecordset& riga, real& saldo_tot, real& credito_tot)
 | |
| {
 | |
|   const long nProgDelega = _f24->get_count("10");
 | |
| 
 | |
|   int nProgr = 0;
 | |
|   real debito, credito;
 | |
| 
 | |
|   for (bool ok = riga.move_first(); ok ; ok = riga.move_next())
 | |
|   {
 | |
|     const TString4 tributo = riga.get("TRIBUTO").as_string();
 | |
|     const char sezione = trib2sec(tributo);
 | |
|     if (sezione == 'L')
 | |
|     {
 | |
|       if (new_rec("40-07")) // qui
 | |
|       {
 | |
|         set("ProgressivoDelega", nProgDelega);
 | |
|         set("ProgressivoContributo", ++nProgr);
 | |
|         set("CodiceEnte", riga.get("ENTECOM").as_string());
 | |
|         set("CodiceTributo", tributo);
 | |
|         
 | |
| 				TString16 rif(riga.get("RATEAZIONE").as_string());
 | |
| 
 | |
| 				if (riga.get("ANNO").as_int() > 0)
 | |
| 					rif << riga.get("ANNO").as_string();
 | |
| 				if (rif.blank())
 | |
| 					rif ="00000000";
 | |
| 				set("RiferimentiTributo", rif);
 | |
| 
 | |
|         const real d = riga.get("IMPORTODEB").as_real();
 | |
|         set("ImportoDebito", d);
 | |
|         debito += d;
 | |
| 
 | |
|         const real c = riga.get("IMPORTOCRE").as_real();
 | |
|         set("ImportoCredito", c);
 | |
|         credito += c;
 | |
| 
 | |
| 				set("Ravvedimento", riga.get("RAVVED").as_bool() ? 1 : 0);
 | |
| 				set("ImmobiliVariati", riga.get("IMMVAR").as_bool() ? 1 : 0);
 | |
| 				set("Acconto", riga.get("ACCONTO").as_bool() ? 1 : 0);
 | |
| 				set("Saldo", riga.get("SALDO").as_bool() ? 1 : 0);
 | |
| 				set("NumeroFabbricati", riga.get("NUMIMM").as_int());
 | |
| 				set("DetrazioneICI", 0L);
 | |
| 
 | |
|         if (nProgr > 4)
 | |
|           log(2, "Numero eccessivo di righe nella sezione ICI/Altri tributi locali");
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   const real saldo = debito-credito;
 | |
|   if (nProgr > 0 && new_rec("40-08"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
|     set("TotaleDebito", debito);
 | |
|     set("TotaleCredito", credito);
 | |
|     set("SegnoSezione", saldo < ZERO ? "N" : "P");
 | |
|     set("SaldoSezione", saldo < ZERO ? -saldo : saldo);
 | |
|   }
 | |
| 
 | |
|   saldo_tot += saldo;
 | |
|   credito_tot += credito;
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_inail(TRecordset& riga, real& saldo_tot, real& credito_tot)
 | |
| {
 | |
|   const long nProgDelega = _f24->get_count("10");
 | |
| 
 | |
|   int nProgr = 0;
 | |
|   real debito, credito;
 | |
| 
 | |
|   for (bool ok = riga.move_first(); ok ; ok = riga.move_next())
 | |
|   {
 | |
|     const TString4 tributo = riga.get("TRIBUTO").as_string();
 | |
|     const char sezione = trib2sec(tributo);
 | |
|     if (sezione == 'N')
 | |
|     {
 | |
|       if (new_rec("40-09")) // qui
 | |
|       {
 | |
|         set("ProgressivoDelega", nProgDelega);
 | |
|         set("ProgressivoContributo", ++nProgr);
 | |
|         set("CodiceSede", riga.get("SEDE").as_string());
 | |
| 				set("NumeroPosizioneAssicurativa", riga.get("POSASS").as_real());
 | |
| 				set("CCNumeroPosizioneAssicurativa", riga.get("CIN").as_real());
 | |
| 				set("Causale", riga.get("CAUSINAIL").as_string());
 | |
| 				set("NumeroDiRiferimento", riga.get("NUMRIF").as_real());
 | |
|         
 | |
| 				const real d = riga.get("IMPORTODEB").as_real();
 | |
|         set("ImportoDebito", d);
 | |
|         debito += d;
 | |
| 
 | |
|         const real c = riga.get("IMPORTOCRE").as_real();
 | |
|         set("ImportoCredito", c);
 | |
|         credito += c;
 | |
| 
 | |
|         if (nProgr > 3)
 | |
|           log(2, "Numero eccessivo di righe nella sezione INAIL");
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   const real saldo = debito-credito;
 | |
|   if (nProgr > 0 && new_rec("40-10"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
|     set("TotaleDebito", debito);
 | |
|     set("TotaleCredito", credito);
 | |
|     set("SegnoSezione", saldo < ZERO ? "N" : "P");
 | |
|     set("SaldoSezione", saldo < ZERO ? -saldo : saldo);
 | |
|   }
 | |
| 
 | |
|   saldo_tot += saldo;
 | |
|   credito_tot += credito;
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_50(TRecordset& riga, const real& saldo_tot, const real& credito_tot, const TMask& m)
 | |
| {
 | |
|   riga.move_first();
 | |
| 
 | |
|   const long nProgDelega = _f24->get_count("10");
 | |
| 	const TString8 abi(riga.get("ABI").as_string());
 | |
| 	const TString8 cab(riga.get("CAB").as_string());
 | |
|   TString16 key;
 | |
| 
 | |
| 	key << prefix().firm().get(NDT_TIPOA) << '|' << prefix().firm().get_long(NDT_CODANAGR);
 | |
| 
 | |
| 	TString16 cofi = cache().get(LF_ANAG, key, ANA_COFI);
 | |
| 
 | |
| 	if (cofi.blank())
 | |
| 		cofi = cache().get(LF_ANAG, key, ANA_PAIV);
 | |
| 
 | |
| 	if (new_rec("50-01"))
 | |
|   {
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
|     set("BancaPassiva", abi);
 | |
|     set("SportelloPassivo", cab);
 | |
| 
 | |
|     TString16 banca; banca << abi << cab;
 | |
|     const TString& iban = cache().get("BNP", banca, "S3");
 | |
|     set("ContoAddebito", iban.mid(15));
 | |
|     set("Cin", iban.mid(4, 1));
 | |
|     set("SaldoFinale", saldo_tot);
 | |
| 
 | |
|     set("CodiceFiscale", cofi);
 | |
| 
 | |
|     int titpag = 1;  // Saldo zero
 | |
|     if (!saldo_tot.is_zero())
 | |
|     {
 | |
|       const char tipointes = riga.get("TIPOINTEST").as_string()[0];
 | |
|       titpag = tipointes == 'C' ? 3 : 2;
 | |
|     }
 | |
|     set("TitolarePagamento", titpag);
 | |
|     set("DataPagamento", m.get_date(F_DATAPAG));
 | |
|     set("TotaleImportiCredito", credito_tot);
 | |
|   }
 | |
|   if (new_rec("50-02"))
 | |
| 	{
 | |
|     set("ProgressivoDelega", nProgDelega);
 | |
| 	  set("CodiceFiscaleMittente", cofi);
 | |
| 	  set("ABI", abi);
 | |
| 	  set("CAB", cab);
 | |
| 	  set("Denominazione", prefix().firm().get(NDT_RAGSOC));
 | |
| 	}
 | |
| 
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_delega(long nDelega, const TMask& m)
 | |
| {
 | |
|   TString msg; msg << TR("Delega") << ' ' << nDelega;
 | |
|   log(0, msg);
 | |
| 
 | |
|   TF24_set delega(nDelega);
 | |
|   
 | |
|   real saldo_tot, credito_tot;
 | |
|   
 | |
|   add_10_20(delega, m);
 | |
|   add_erario(delega, saldo_tot, credito_tot);
 | |
|   add_inps(delega, saldo_tot, credito_tot);
 | |
|   add_regioni(delega, saldo_tot, credito_tot);
 | |
|   add_ici(delega, saldo_tot, credito_tot);
 | |
|   add_inail(delega, saldo_tot, credito_tot);
 | |
|   add_50(delega, saldo_tot, credito_tot, m);
 | |
| 	_f24->totale_positivi() += saldo_tot;
 | |
| 
 | |
| }
 | |
| 
 | |
| bool TF4_sender::set_data_versamento(long nDelega, const TDate& datavers)
 | |
| {
 | |
|   TLocalisamfile righe(LF_RIGHEF24);
 | |
|   TF24_set f24(nDelega);
 | |
|   for (bool ok = f24.move_first(); ok; ok = f24.move_next())
 | |
|   {
 | |
|     const long progr = f24.get("PROGR").as_int();
 | |
|     righe.put("PROGR", progr);
 | |
|     int err = righe.read(_isequal, _lock);
 | |
|     if (err == NOERR)
 | |
|     {
 | |
|       righe.put("DATAVERS", datavers);
 | |
|       err = righe.rewrite();
 | |
|     }
 | |
|     if (err != NOERR)
 | |
|       return error_box(FR("Errore %d durante l'aggiornamento della riga %ld"), err, progr);
 | |
|   }
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| void TF4_sender::add_footer(const TMask& m)
 | |
| {
 | |
|   if (new_rec("EF"))
 | |
|   {
 | |
|     set("Mittente",      m.get(F_MITTENTE));
 | |
|     set("Ricevente",     m.get(F_ABI));
 | |
|     set("DataCreazione", m.get_date(F_DATA));
 | |
|     set("NomeSupporto",  m.get(F_FILE));  // Somma dei tre campi precedenti
 | |
| 
 | |
|     set("NumeroDisposizioni", _f24->get_count("10"));
 | |
|     set("NumeroRecord",       _f24->get_count(NULL));
 | |
|     set("TotImportiPositivi", _f24->totale_positivi());
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TF4_sender::main_loop()
 | |
| {
 | |
| 	_has_cg = app().has_module(CGAUT);
 | |
|   TF24_mask m;
 | |
|   while (m.run() != K_QUIT)
 | |
|   {
 | |
|     const char* const title = TR("Generazione F24");
 | |
| 		const bool contabilizza = m.get_bool(F_CONTABILIZZA);
 | |
|     _f24 = new TF24_textset;
 | |
|     _log = new TLog_report(title);
 | |
|     _errors_logged = false;
 | |
| 
 | |
|     add_header(m);
 | |
| 
 | |
|     TSheet_field& sheet = m.sfield(F_DISTINTE);
 | |
|     if (sheet.items() > 0)
 | |
|     {
 | |
|       TProgind pi(sheet.items(), title, true, true);
 | |
|       FOR_EACH_SHEET_ROW(sheet, r, row) if (row->get(0)[0] > ' ')
 | |
|       {
 | |
|         if (!pi.setstatus(r+1))
 | |
|           break;
 | |
|         const long nDelega = row->get_long(1);
 | |
|         add_delega(nDelega, m);
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     add_footer(m);
 | |
| 
 | |
|     TReport_book book;
 | |
|     book.add(*_log);
 | |
| #ifdef DBG
 | |
|     TAS400_report rep(*_f24);
 | |
|     book.add(rep);
 | |
| #endif
 | |
|     book.preview();
 | |
| 
 | |
|     bool save = true;
 | |
|     if (_errors_logged)
 | |
|     {
 | |
|       save = yesno_box(TR("Sono stati riscontrati uno o piu' errori:\n"
 | |
|                           "Si desidera salvare il file ugualmente?"));
 | |
|     }
 | |
|     if (save)
 | |
|     {
 | |
|       TFilename name = m.get(F_PATH);
 | |
|       name.add(m.get(F_FILE));
 | |
|       _f24->save_as(name);
 | |
| 
 | |
|       if (!_errors_logged)
 | |
|       {
 | |
|         TProgind pi(sheet.items(), TR("Aggiornamento data versamento"), true, true);
 | |
|         const TDate datavers = m.get(F_DATA);
 | |
| 
 | |
| 				_log->reset();
 | |
|         FOR_EACH_SHEET_ROW(sheet, r, row) if (row->get(0)[0] > ' ')
 | |
|         {
 | |
|           if (!pi.setstatus(r+1))
 | |
|             break;
 | |
|           
 | |
|           const long nDelega = row->get_long(1);
 | |
|           if (!set_data_versamento(nDelega, datavers))
 | |
| 	           break;
 | |
| 					if (_has_cg)
 | |
| 					{
 | |
| 						TTable del("%DEL");
 | |
| 						TString key;
 | |
| 						TF24_set d(nDelega);
 | |
| 						const int codtrib = d.get(F24_TRIBUTO).as_int();
 | |
| 						const bool acconto = (codtrib == 6013 || codtrib == 6035) && d.get(F24_DATAVERS).as_date().month() == 12;
 | |
| 						const int type = acconto ? 7 : 1;
 | |
| 						int month = codtrib - 6000;
 | |
| 						
 | |
| 						if (acconto)
 | |
| 							month = 12;
 | |
| 						else
 | |
| 							if (month > 30)
 | |
| 								month = (month - 30) * 3;
 | |
| 						key.format("%05ld%04ld%02d%1d", get_firm(), d.get(F24_ANNO).as_int(), month, type);
 | |
| 						del.put("CODTAB", key);
 | |
| 
 | |
| 						if (del.read() != NOERR)
 | |
| 						{
 | |
| 							del.put("CODTAB", key);
 | |
| 							del.write();
 | |
| 						}
 | |
| 						del.put("D0", d.get(F24_DATAVERS).as_date());
 | |
| 						del.put("S7", d.get(F24_ABI).as_string());
 | |
| 						del.put("S8", d.get(F24_CAB).as_string());
 | |
| 						const real saldo = d.get(F24_IMPORTODEB).as_real() - d.get(F24_IMPORTOCRE).as_real();
 | |
| 						if (saldo > 0)
 | |
| 							del.put("R0", saldo);
 | |
| 						del.put("R1", d.get(F24_INTIVATRIM).as_real());
 | |
| 						del.put("B0", "X");
 | |
| 						del.rewrite();
 | |
| 						if (contabilizza)
 | |
| 							d.contabilizza(*_log);
 | |
| 					}
 | |
|         }
 | |
| 				if (contabilizza)
 | |
| 				{
 | |
| 					TReport_book book;
 | |
| 				
 | |
| 					book.add(*_log);
 | |
| 				  book.preview();
 | |
| 				}
 | |
|       }
 | |
|     }
 | |
| 
 | |
|     delete _log;
 | |
|     delete _f24;
 | |
|   }
 | |
| }
 | |
| 
 | |
| int gv0600(int argc, char* argv[])
 | |
| {
 | |
|   TF4_sender app;
 | |
|   app.run(argc, argv, "Invio F24");
 | |
|   return 0;
 | |
| }
 |