Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1092 git-svn-id: svn://10.65.10.50/trunk@16297 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1361 lines
		
	
	
		
			38 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1361 lines
		
	
	
		
			38 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| //********************************
 | ||
| //*  Riepilogo Progressivi IVA   *
 | ||
| //********************************
 | ||
| 
 | ||
| #include <execp.h>
 | ||
| #include <mailbox.h>
 | ||
| #include <mask.h>
 | ||
| #include <printapp.h>
 | ||
| #include <progind.h>
 | ||
| #include <recarray.h>
 | ||
| #include <tabutil.h>
 | ||
| 
 | ||
| #include "cg0.h"
 | ||
| #include "cg0400.h"
 | ||
| 
 | ||
| #include "cgpim.h"
 | ||
| 
 | ||
| #include <anagr.h>
 | ||
| #include <comuni.h>   
 | ||
| #include <attiv.h>   
 | ||
| #include <nditte.h>   
 | ||
| 
 | ||
| 
 | ||
| enum liste {
 | ||
|   ListaPerAliquota=1,
 | ||
|   ListaPerPeriodo=2,
 | ||
| };
 | ||
| 
 | ||
| enum tipo_sospensione { nessuna, normale, vol_affari, liquidazione };
 | ||
| 
 | ||
| struct Importi {
 | ||
|   real imponibile;
 | ||
|   real imposta;
 | ||
| };
 | ||
| 
 | ||
| struct TRiga_gen : public TArray
 | ||
| {
 | ||
|   TString16 _codiva;
 | ||
|   real      _impoven, _imposven;    //imponibile e imposta vendite
 | ||
|   real      _impoacq, _imposacq;    //imponibile e imposta acquisti
 | ||
|   real      _impobd, _imposbd;      //imponibile e imposta importazioni (ovvero bolle doganali)
 | ||
|   
 | ||
|   TRiga_gen (const char* codiva, const real& impov, const real& imposv, const real& impoa, const real& imposa, const real& impobd, const real& imposbd):
 | ||
|   _codiva(codiva),_impoven(impov),_imposven(imposv),_impoacq(impoa),_imposacq(imposa),_impobd(impobd),_imposbd(imposbd) {} 
 | ||
| };
 | ||
| 
 | ||
| class TGen_array : public TArray
 | ||
| {
 | ||
| public:
 | ||
|   bool add_riga(const char* codiva, const real& imponibilev, const real& impostav, const real& imponibilea, const real& impostaa, const real& imponibilebd, const real& impostabd); 
 | ||
|   TRiga_gen& riga(int i) { return (TRiga_gen&)(*this)[i]; }
 | ||
| };  
 | ||
| 
 | ||
| bool TGen_array::add_riga(const char* codiva, const real& imponibilev, const real& impostav, const real& imponibilea, const real& impostaa, const real& imponibilebd, const real& impostabd)
 | ||
| {
 | ||
|   bool found = FALSE;
 | ||
|   for (int i = 0; i < items(); i++)
 | ||
|   {
 | ||
|     TRiga_gen& r = riga(i);
 | ||
|     if (r._codiva==codiva)
 | ||
|     {
 | ||
|       found = TRUE;
 | ||
|       r._impoven  += imponibilev;
 | ||
|       r._imposven += impostav;
 | ||
|       r._impoacq  += imponibilea;
 | ||
|       r._imposacq += impostaa;
 | ||
|       r._impobd   += imponibilebd;
 | ||
|       r._imposbd  += impostabd;
 | ||
|     }
 | ||
|   }
 | ||
|   if (!found)
 | ||
|   {
 | ||
|     TRiga_gen* r = new TRiga_gen(codiva,imponibilev,impostav,imponibilea,impostaa,imponibilebd,impostabd);
 | ||
|     add(r);
 | ||
|   }
 | ||
|   return found;
 | ||
| };
 | ||
| 
 | ||
| struct TRiga_iva : public TArray
 | ||
| {
 | ||
|   tiporec _tipo;
 | ||
|   real    _imponibile, _imposta, _detrazione;
 | ||
|   
 | ||
|   TRiga_iva (const tiporec& tipo, const real& impo, const real& impos, const real& detr):
 | ||
|   _tipo(tipo),_imponibile(impo),_imposta(impos), _detrazione(detr) {}
 | ||
| };                            
 | ||
| 
 | ||
| class TIva_array : public TArray
 | ||
| {
 | ||
| public:
 | ||
|   bool add_riga(const tiporec& tipo, const real& imponibile, 
 | ||
|                 const real& imposta, const real& detr); 
 | ||
|   TRiga_iva& riga(int i) { return (TRiga_iva&)(*this)[i]; }
 | ||
| };
 | ||
| 
 | ||
| bool TIva_array::add_riga(const tiporec& tipo, const real& imponibile, 
 | ||
|                           const real& imposta, const real& detr)
 | ||
| {
 | ||
|   bool found = FALSE;
 | ||
|   for (int i = 0; i < items(); i++)
 | ||
|   {
 | ||
|     TRiga_iva& r = riga(i);
 | ||
|     if (r._tipo == tipo)
 | ||
|     {
 | ||
|       found = TRUE;
 | ||
|       r._imponibile += imponibile;
 | ||
|       r._imposta    += imposta;
 | ||
|       r._detrazione += detr;
 | ||
|     }
 | ||
|   }
 | ||
|   if (!found)
 | ||
|   {
 | ||
|     TRiga_iva* r = new TRiga_iva(tipo,imponibile,imposta,detr);
 | ||
|     add(r);
 | ||
|   }
 | ||
|   return found;
 | ||
| };
 | ||
| 
 | ||
| class TProgressivi_iva : public TPrintapp
 | ||
| {
 | ||
|   TMask*          _msk;
 | ||
|   TDate           _data;
 | ||
|   int             _sospmsk, _tipoprog, _livelloprog, _tipo_aliq, _tipo_attiv, _annoiva, _i;
 | ||
|   int             _mese, _anno;
 | ||
|   long            _codditta;
 | ||
|   char            _tipo_prog_reg;
 | ||
|   bool            _st_inizio_anno, _prima_pagina;
 | ||
|   TIva_array      _iva_array,_iva1_array;
 | ||
|   TGen_array      _gen_array,_gen1_array;
 | ||
|   TAssoc_array    _corr_array;
 | ||
|   TString         _cap,_cofi,_paiva,_ragsoc,_comunefis,_provfis,_viafis,_codivamsk,_codattmsk;
 | ||
|   TString         _datast, _cod_att;
 | ||
|   Importi         _mesi[14];          // Era 13: bestie!  I mesi sono da 1 a 13
 | ||
|   liste           _tipo_lista;
 | ||
| 
 | ||
| protected:  
 | ||
|    static bool tipo_handler(TMask_field& f, KEY k);
 | ||
|    static bool selection_handler(TMask_field& f, KEY k);
 | ||
|    static bool period_handler(TMask_field& f, KEY k);
 | ||
|    static void check_period(TMask& m);
 | ||
|    
 | ||
| public:            
 | ||
| 
 | ||
|   virtual bool user_create();
 | ||
|   virtual bool user_destroy();
 | ||
|   virtual bool set_print(int);
 | ||
|   virtual void preprocess_header();
 | ||
|   virtual bool preprocess_page(int,int);
 | ||
|   virtual print_action postprocess_page(int,int);
 | ||
| 
 | ||
|   bool        is_month_plain(int x, int m, const char f);
 | ||
|   void        lordo2netto(const real& totale, real& imponibile, real& imposta, const real& aliquota);
 | ||
|   void        cerca_i_pim();
 | ||
|   void        azzera_mesi();
 | ||
|   void        get_dati_ditta();
 | ||
|   void        setta_intestazione();
 | ||
|   void        calcola_totali(real&,real&);
 | ||
|   void        cerca_tipo(TIva_array&, tiporec, real&, real&, real&);
 | ||
|   void        prospetto_pagina(TGen_array&, TIva_array&);
 | ||
|   int         stampa_intestazione_ditta(); 
 | ||
|   const char* desc_attivita(const char*);
 | ||
|   const char* desc_iva(const TString&);
 | ||
|   char        frequenza_versamenti(long ditta, int anno);
 | ||
|   void        look_pim();
 | ||
|   void        ricalcola_liquidazione_se_necessario(int anno, int ultimo_mese);
 | ||
| 
 | ||
|   TProgressivi_iva(){};
 | ||
| };
 | ||
| 
 | ||
| inline TProgressivi_iva& app() { return (TProgressivi_iva&) main_app(); }
 | ||
| 
 | ||
| HIDDEN int compare_rows(const TObject** o1, const TObject** o2)
 | ||
| {
 | ||
|   TRiga_gen* r1 = (TRiga_gen*)*o1;
 | ||
|   TRiga_gen* r2 = (TRiga_gen*)*o2;
 | ||
|   
 | ||
|   return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva));
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::is_month_plain(int x, int m, const char f)
 | ||
|   // la piu' semplice: vero se mese == _month o se fa parte del
 | ||
|   // trimestre indicato da month
 | ||
| {                             
 | ||
|   bool ok = x == m;
 | ||
|   if (!ok && f == 'T')
 | ||
|   {
 | ||
|     // aggiusta al trimestre il mese da calcolare 
 | ||
|     int mto = m;
 | ||
|     mto += 2 - ((mto-1) % 3);   
 | ||
|     ok = x > (mto - 3) && x <= mto;
 | ||
|   }    
 | ||
|   return ok;
 | ||
| }               
 | ||
| 
 | ||
| const char* TProgressivi_iva::desc_attivita(const char* codatt)
 | ||
| {
 | ||
|   const TRectype & attiv = cache().get("%AIS", codatt);
 | ||
| 
 | ||
|   return attiv.get("S0");
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::lordo2netto(const real& totale, real& imponibile, real& imposta, const real& aliquota)
 | ||
| { 
 | ||
|   const int dec = TCurrency::get_firm_dec();
 | ||
|   if (dec == 0)  // Lire
 | ||
|   {
 | ||
|     imposta = (abs(totale) * aliquota)/(aliquota + 1.00);
 | ||
|     imposta.ceil();
 | ||
|     if (totale.sign()  < 0) imposta = -imposta;
 | ||
|     imponibile = totale - imposta;
 | ||
|     // Qui si entra nel regno del mistero: delta e' SEMPRE zero 
 | ||
|     const real delta = totale - imponibile - imposta; 
 | ||
|     if (!delta.is_zero())
 | ||
|       imposta += delta;
 | ||
|   }
 | ||
|   else  // Euro
 | ||
|   {
 | ||
|     imposta = (totale * aliquota)/(aliquota + 1.00);
 | ||
|     imposta.round(dec);
 | ||
|     imponibile = totale - imposta;
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| const char* TProgressivi_iva::desc_iva(const TString& cod)
 | ||
| {
 | ||
|   if (cod == "{AF")
 | ||
|     return TR("Artt.17c3/74c1");
 | ||
| 
 | ||
|   else if (cod == "{VA7")
 | ||
|     return TR("Art.40c5/6/8 a.i.");
 | ||
| 
 | ||
|   else
 | ||
|   {
 | ||
|     TString16 codtab; codtab.format("%-4s", (const char*)cod);
 | ||
|     const TRectype & iva = cache().get("%IVA", codtab);
 | ||
| 
 | ||
| 	return iva.get("S0");
 | ||
|   }
 | ||
|   return "";
 | ||
| } 
 | ||
| 
 | ||
| char TProgressivi_iva::frequenza_versamenti(long ditta, int anno)
 | ||
| {
 | ||
|   if (ditta <= 0L) 
 | ||
|     ditta = get_firm();
 | ||
|   if (anno <= 0L) 
 | ||
|     anno = _anno;
 | ||
|   
 | ||
|   TString16 key; key.format("%05ld%04d", ditta, anno);
 | ||
|   const TRectype& lia = cache().get("%LIA", key);
 | ||
|   return lia.empty() ? 'M' : lia.get_char("S7");
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::user_create()
 | ||
| {
 | ||
| 	open_files(LF_TABCOM, LF_TAB, LF_ANAG, LF_NDITTE, LF_COMUNI, LF_ATTIV, 0);     
 | ||
|   set_real_picture("###.###.###.###");
 | ||
|   set_magic_currency(TRUE);
 | ||
|   set_print_zero(FALSE);
 | ||
|   printer().footerlen(5);
 | ||
|   
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::user_destroy()
 | ||
| {
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::azzera_mesi()
 | ||
| {
 | ||
|   for (int i=0; i<=12; i++)
 | ||
|   {
 | ||
|     _mesi[i].imponibile = ZERO; 
 | ||
|     _mesi[i].imposta = ZERO;
 | ||
|   }   
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::look_pim()
 | ||
| {
 | ||
|   TTable pim("PIM");
 | ||
|   TTable reg("REG");
 | ||
|   TTable tabiva("%IVA");
 | ||
|   TString80 codtab;
 | ||
|   TString16 codatt,codiva,tipoiva,codreg;
 | ||
|   TToken_string va7("",'!');
 | ||
|   real imponibile, imposta,afi,afv,va7i,va7v;
 | ||
|   real corr_item,*cp,aliquota;
 | ||
|   bool is_key;
 | ||
|   const char freq = frequenza_versamenti(_codditta, _anno);
 | ||
|   
 | ||
|   _corr_array.destroy();
 | ||
|   
 | ||
|   for (pim.first(); !pim.eof(); pim.next())
 | ||
|   {
 | ||
|     imponibile = imposta = afi = afv = va7i = va7v = ZERO;
 | ||
|     tiporec tipo;
 | ||
| 
 | ||
|     codtab = pim.get("CODTAB");
 | ||
|     int anno = atoi(codtab.mid(0,4));
 | ||
|     int mese = atoi(codtab.mid(13,2)); 
 | ||
|     codreg.format("%d%-3s",anno, (const char*)codtab.mid(10,3));
 | ||
|     codatt = codtab.mid(4,5);
 | ||
|     codiva = codtab.mid(16,4);         
 | ||
|     tipoiva = pim.get("S5");    
 | ||
|     codiva = codiva.trim();
 | ||
|     codatt = codatt.trim();
 | ||
| 
 | ||
|     if (anno != _anno) continue; 
 | ||
|     
 | ||
|     if (_st_inizio_anno)
 | ||
|       if ((mese > _mese) || (_mese == 13 && mese < 13))
 | ||
|         continue;
 | ||
|     
 | ||
|     if (!_st_inizio_anno)
 | ||
|       //if (mese != _mese)
 | ||
|       if (!is_month_plain(mese, _mese, freq))
 | ||
|         continue;
 | ||
|     
 | ||
|     if (codatt != _cod_att) continue;
 | ||
|     
 | ||
|     //Modifica del 12/07/1995
 | ||
|     if (tipoiva == "VE") continue; //i codici iva di tipo "VE"
 | ||
|     //Fine                         //non devono essere stampati
 | ||
|     
 | ||
|     bool soggetto = TRUE;
 | ||
|     tabiva.put("CODTAB",codiva);
 | ||
|     if (tabiva.read() == NOERR)
 | ||
|       soggetto = tabiva.get("S1") != "NS"; // I non soggetti non vanno sempre considerati
 | ||
|     
 | ||
|     reg.put("CODTAB",codreg);
 | ||
|     if (reg.read() != NOERR) reg.zero();
 | ||
|     const bool corrisp = reg.get_bool("B0");
 | ||
| 
 | ||
|     const tipo_sospensione sosp_imp = reg.get_bool("B1") ? (tipo_sospensione) reg.get_int("I9") : nessuna;
 | ||
| 
 | ||
|     // Se si decide di stampare i progressivi validi per la liquidazione
 | ||
|     // i PIM validi solo per il volume d'affari vanno scartati
 | ||
|     if (_tipo_prog_reg == 'L' && sosp_imp == vol_affari)
 | ||
|       continue;
 | ||
| 
 | ||
|     // Se si decide di stampare i progressivi validi per il vol. d'affari
 | ||
|     // i PIM validi solo per la liquidazione vanno scartati
 | ||
|     if (_tipo_prog_reg == 'V' && sosp_imp == liquidazione)
 | ||
|       continue;
 | ||
|     
 | ||
|     is_key = _corr_array.is_key(codiva);
 | ||
|     corr_item = ZERO;
 | ||
|     real& ci = is_key ? (real&) _corr_array[codiva] : corr_item;
 | ||
|     ci += pim.get_real("R3"); // accumula i corrispettivi
 | ||
|     if (!is_key)
 | ||
|       _corr_array.add(codiva,ci);
 | ||
| 
 | ||
|     while (classify_pim(pim.curr(), imponibile, imposta, tipo, TRUE))
 | ||
|     {
 | ||
|       switch(tipo)
 | ||
|       { 
 | ||
|       case acq_norm:
 | ||
|         if (_mese != 13)
 | ||
|           _gen_array.add_riga(codiva,ZERO,ZERO,imponibile,imposta,ZERO,ZERO);
 | ||
|         if ((_st_inizio_anno && is_month_plain(mese, _mese, freq)) || _mese == 13) //lo metto in un array a parte
 | ||
|           _gen1_array.add_riga(codiva,ZERO,ZERO,imponibile,imposta,ZERO,ZERO);
 | ||
|         break;
 | ||
|       case vend_norm:
 | ||
|         if (corrisp)
 | ||
|         { // Questo perche' i documenti FS sono registrati col segno 
 | ||
|           // negativo in R0/R1 e col segno positivo in R5/R6,
 | ||
|           imponibile += pim.get_real("R5");
 | ||
|           imposta += pim.get_real("R6");
 | ||
|         }
 | ||
|         if (_mese == 13)
 | ||
|         {     // Separa le autofatture non residenti(AF) e gli importi VA7
 | ||
|           afi = pim.get_real("R7");
 | ||
|           afv = pim.get_real("R8");
 | ||
|           va7 = pim.get("S0"); 
 | ||
|           va7i = va7.get(0);
 | ||
|           va7v = va7.get(1);
 | ||
|           imponibile -= afi + va7i;
 | ||
|           imposta -= afv + va7v;   
 | ||
|           _gen1_array.add_riga("{AF",afi,afv,ZERO,ZERO,ZERO,ZERO); // Mette '{' cosi' vengono stampati per ultimi
 | ||
|           _gen1_array.add_riga("{VA7",va7i,va7v,ZERO,ZERO,ZERO,ZERO);
 | ||
|         }
 | ||
|         
 | ||
|         if (_mese != 13)
 | ||
|           _gen_array.add_riga(codiva,imponibile,imposta,ZERO,ZERO,ZERO,ZERO);
 | ||
|         if ((_st_inizio_anno && is_month_plain(mese, _mese, freq)) || _mese == 13) //lo metto in un array a parte
 | ||
|           _gen1_array.add_riga(codiva,imponibile,imposta,ZERO,ZERO,ZERO,ZERO);
 | ||
|         break;
 | ||
|       case bolle_doganali:
 | ||
|         if (_mese != 13)
 | ||
|           _gen_array.add_riga(codiva,ZERO,ZERO,ZERO,ZERO,imponibile,imposta);
 | ||
|         if ((_st_inizio_anno && is_month_plain(mese, _mese, freq)) || _mese == 13)
 | ||
|           _gen1_array.add_riga(codiva,ZERO,ZERO,ZERO,ZERO,imponibile,imposta);
 | ||
|         break;
 | ||
|       case acq_amm_ultdetr:  
 | ||
|         if (soggetto)
 | ||
|         {  
 | ||
|           const real detr = imponibile * real(0.06); 
 | ||
|           if (_mese != 13)
 | ||
|             _iva_array.add_riga(tipo,imponibile,imposta,detr);
 | ||
|           if ((_st_inizio_anno && is_month_plain(mese, _mese, freq)) || _mese == 13)
 | ||
|             _iva1_array.add_riga(tipo,imponibile,imposta,detr);
 | ||
|         }
 | ||
|         break;
 | ||
|       case acq_simp:  
 | ||
|       case vend_simp:  
 | ||
|       case cess_amm:  
 | ||
|       case acq_beni_riv:
 | ||
|       case acq_beni_ammort:
 | ||
|       case acq_beni_ammort_nd:
 | ||
|       case acq_beni_leasing:
 | ||
|         if (soggetto)
 | ||
|         {
 | ||
|           if (_mese != 13)
 | ||
|             _iva_array.add_riga(tipo,imponibile,imposta,ZERO); 
 | ||
|           if ((_st_inizio_anno && is_month_plain(mese, _mese, freq)) || _mese == 13)
 | ||
|             _iva1_array.add_riga(tipo,imponibile,imposta,ZERO);
 | ||
|         }
 | ||
|         break;
 | ||
|       default:
 | ||
|         if (sosp_imp == normale || sosp_imp == nessuna) // Esclude quelli valevoli solo liq o solo vol.aff. dai riepiloghi altri dati
 | ||
|         {
 | ||
|           if (_mese != 13)
 | ||
|             _iva_array.add_riga(tipo,imponibile,imposta,ZERO); 
 | ||
|           if ((_st_inizio_anno && is_month_plain(mese, _mese, freq)) || _mese == 13)
 | ||
|             _iva1_array.add_riga(tipo,imponibile,imposta,ZERO);
 | ||
|         }
 | ||
|         break;    
 | ||
|       }
 | ||
|     } 
 | ||
|   }
 | ||
|   // Scorpora i corrispettivi
 | ||
|   for (cp = (real*) _corr_array.first_item(); cp != NULL; cp = (real*) _corr_array.succ_item())
 | ||
|   {
 | ||
|     codiva = _corr_array.get_hashobj()->key();
 | ||
|     tabiva.put("CODTAB",codiva);
 | ||
|     if (tabiva.read() == NOERR) aliquota = tabiva.get_real("R0");
 | ||
|     else aliquota = ZERO;
 | ||
|     lordo2netto(*cp,imponibile,imposta,aliquota/100.0);
 | ||
|     if (_mese != 13)
 | ||
|       _gen_array.add_riga(codiva,imponibile,imposta,ZERO,ZERO,ZERO,ZERO);
 | ||
|     if (_st_inizio_anno || _mese == 13) //lo metto in un array a parte
 | ||
|       _gen1_array.add_riga(codiva,imponibile,imposta,ZERO,ZERO,ZERO,ZERO);
 | ||
|   }
 | ||
|   _gen_array.sort(compare_rows);  // ordinamento per codice iva
 | ||
|   _gen1_array.sort(compare_rows); // ordinamento per codice iva
 | ||
| }                
 | ||
| 
 | ||
| void TProgressivi_iva::ricalcola_liquidazione_se_necessario(int ultimo_anno, int ultimo_mese)
 | ||
| {
 | ||
|   TRelation rel("LIM");
 | ||
|   TRectype& rec = rel.curr();
 | ||
|   
 | ||
|   TString8 anno; anno.format("%04d", ultimo_anno);
 | ||
|   rec.put("CODTAB", anno);
 | ||
| 
 | ||
|   TCursor cur(&rel, "", 1, &rec, &rec);
 | ||
|   const TRecnotype items = cur.items();
 | ||
|   cur.freeze();
 | ||
| 
 | ||
|   // Scandisce i mesi alla ricerca "spuntando" quelli gia' calcolati
 | ||
|   TBit_array computed;
 | ||
|   for (cur = 0l; cur.pos() < items; ++cur)
 | ||
|   {
 | ||
|     const int mese = atoi(rec.get("CODTAB").mid(4, 2));
 | ||
|     if (mese >= 1 && mese <= ultimo_mese)
 | ||
|     {
 | ||
|       if (rec.get_bool("B0"))  
 | ||
|         computed.set(mese);     // Mese calcolato!
 | ||
|       else
 | ||
|         break;                  // Considera non calcolati anche i successivi
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   const char freq = frequenza_versamenti(0, ultimo_anno);
 | ||
|   const int periods = freq == 'M' ? ultimo_mese : (ultimo_mese/3);
 | ||
|   const bool ok = computed.ones() == periods;
 | ||
| 
 | ||
|   if (!ok && yesno_box(FR("Alcuni periodi non risultano ricalcolati:\n"
 | ||
|                           "<EFBFBD> consigliabile il ricalcolo. Si desidera eseguirlo?")))
 | ||
|   {
 | ||
|     const int recalc = (freq == 'M') ? ultimo_mese : ultimo_mese/3;
 | ||
|     TProgind pi(recalc, "Ricalcolo liquidazione in corso...", TRUE, TRUE);
 | ||
|     for (int mese = (freq == 'M') ? 1 : 3; mese <= ultimo_mese; mese += (freq == 'M') ? 1 : 3)
 | ||
|     {
 | ||
|       pi.addstatus(1);
 | ||
|       if (pi.iscancelled())
 | ||
|         break;
 | ||
|       if (!computed[mese])
 | ||
|       {
 | ||
|         TToken_string body(36);
 | ||
|         body.add(ultimo_anno);
 | ||
|         body.add(mese);
 | ||
|         body.add(get_firm());
 | ||
|         body.add("V");        // visualizzazione: no ff alla fine, zeri stampati
 | ||
|         body.add(""); 
 | ||
|         body.add("");     
 | ||
|         body.add('X');
 | ||
|   
 | ||
|         TMessage msg("cg4 -2 -S", "RCL", body);
 | ||
|         msg.send();
 | ||
| 
 | ||
|         TExternal_app liq("cg4 -2");
 | ||
|         liq.run();
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::cerca_i_pim()
 | ||
| {
 | ||
|   TTable pim("PIM");
 | ||
|   TTable tabiva("%IVA");
 | ||
|   TTable reg("REG");
 | ||
|   TString80 codtab;
 | ||
|   TString16 codatt,codiva,tipoiva,codreg;
 | ||
|   
 | ||
|   for (pim.first(); !pim.eof(); pim.next())
 | ||
|   {
 | ||
|     real imponibile, imposta, impo, impos;
 | ||
|     tiporec tipo;
 | ||
| 
 | ||
|     codtab = pim.get("CODTAB");
 | ||
|     const int anno = atoi(codtab.mid(0,4));
 | ||
|     codatt = codtab.mid(4,5); 
 | ||
|     const int mese = atoi(codtab.mid(13,2)); 
 | ||
|     codreg.format("%d%-3s",anno, (const char*)codtab.mid(10,3));
 | ||
|     codiva = codtab.mid(16,4);         
 | ||
|     tipoiva = pim.get("S5");
 | ||
|     
 | ||
|     if (anno != _annoiva) 
 | ||
|       continue; 
 | ||
|     
 | ||
|     //Modifica del 12/07/1995
 | ||
|     if (tipoiva == "VE") 
 | ||
|       continue;
 | ||
|     //Fine                         
 | ||
|     
 | ||
|     if (_livelloprog == 1) //riepilogo per aliquota 
 | ||
|     { 
 | ||
|       codiva = codiva.trim();
 | ||
|       if (codiva != _codivamsk) 
 | ||
|         continue;
 | ||
|     }
 | ||
| 
 | ||
|     // I non soggetti non vanno considerati
 | ||
|     bool soggetto = TRUE;
 | ||
|     tabiva.put("CODTAB",codiva);
 | ||
|     if (tabiva.read() == NOERR)
 | ||
|       soggetto = tabiva.get("S1") != "NS";
 | ||
|     
 | ||
|     if (_livelloprog == 2) //riepilogo per attivita'
 | ||
|     {
 | ||
|       codatt = codatt.trim();
 | ||
|       if (codatt != _codattmsk) continue;
 | ||
|     }
 | ||
|     
 | ||
|     impo = impos = ZERO;
 | ||
|     
 | ||
|     reg.put("CODTAB",codreg);
 | ||
|     if (reg.read() != NOERR) reg.zero();
 | ||
|     const bool corrisp = reg.get_bool("B0");
 | ||
| 
 | ||
|     if (_livelloprog == 1 && _tipoprog == 1 && _sospmsk == 2)   // CM500309
 | ||
|     {
 | ||
|       const bool sosp = reg.get_bool("B1");
 | ||
|       const int tipo_sosp = reg.get_int("I9");  
 | ||
|       if (sosp && tipo_sosp > 1)
 | ||
|         continue;
 | ||
|     }
 | ||
| 
 | ||
|     while (classify_pim(pim.curr(), imponibile, imposta, tipo, FALSE))
 | ||
|     {
 | ||
|       switch(tipo)
 | ||
|       { 
 | ||
|       case acq_norm:
 | ||
|         if (_tipoprog == 1) break;  //vendite
 | ||
|         if (_tipo_aliq == 1)        //nella maschera e' stato richiesto 
 | ||
|         {                           //acquisti in genere
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case vend_norm:
 | ||
|         if (_tipoprog == 2) break;  //acquisti
 | ||
|         if (_sospmsk == 1)          //nella maschera e' stato richiesto 
 | ||
|         {                           //vendite in genere
 | ||
|           if (corrisp)
 | ||
|           { // Questo perche' i documenti FS sono registrati col segno 
 | ||
|             // negativo in R0/R1 e col segno positivo in R5/R6,
 | ||
|             imponibile += pim.get_real("R5");
 | ||
|             imposta += pim.get_real("R6");
 | ||
|           }
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case vend_simp:     
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 2) break;  //acquisti
 | ||
|         if (_sospmsk == 2)          //nella maschera e' stato richiesto 
 | ||
|         {                           //vendite in sospensione d'imposta
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case acq_ind_op_es:
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_aliq == 2) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case acq_ind_pass_int:
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_aliq == 3) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;     
 | ||
|       case acq_bd_ind_art_19:
 | ||
|       case acq_ind_art_19:
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_aliq == 4) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break; 
 | ||
|       case base_ventilazione:
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_aliq == 5) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;              
 | ||
|       case bolle_doganali:
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_aliq == 6) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case acq_simp:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_aliq == 7) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;  
 | ||
|       case acq_beni_riv:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_attiv == 1) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case acq_beni_ammort:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_attiv == 2) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;              
 | ||
|       case acq_beni_ammort_nd:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_attiv == 3) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;      
 | ||
|       case acq_beni_leasing:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_attiv == 4) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;              
 | ||
|       case acq_amm_ultdetr:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 1) break;  
 | ||
|         if (_tipo_attiv == 5) 
 | ||
|         {
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta;
 | ||
|         }  
 | ||
|         break;
 | ||
|       case cess_amm:
 | ||
|         if (!soggetto) break;
 | ||
|         if (_tipoprog == 2) break;
 | ||
|         if (_livelloprog == 2)  //Nel caso di vendite per attivita' il tipo costo/ricavo
 | ||
|         {                       //viene forzato a 4 => cessione beni ammortizzabili
 | ||
|           impo  += imponibile;
 | ||
|           impos += imposta; 
 | ||
|         }  
 | ||
|       default:
 | ||
|         break;    
 | ||
|       }
 | ||
|     } //fine while
 | ||
|     _mesi[mese].imponibile += impo;
 | ||
|     _mesi[mese].imposta    += impos; 
 | ||
|     impo = impos = ZERO;
 | ||
|   }  
 | ||
| }                  
 | ||
|         
 | ||
| bool TProgressivi_iva::tipo_handler(TMask_field& f, KEY k)
 | ||
| {
 | ||
|   if (k == K_SPACE)
 | ||
|   {
 | ||
|     TMask& m = f.mask();
 | ||
|     const int livello = m.get_int(F_LIVELLO);
 | ||
|     const int tipo = atoi(f.get());
 | ||
|     bool tab = FALSE, tabe = FALSE, tabel = FALSE;
 | ||
|     if (livello == 1)
 | ||
|     {
 | ||
|       tab  = tipo == 1;
 | ||
|       tabe = tipo == 2;
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       tabel = tipo == 2;
 | ||
|     }
 | ||
|     m.show(F_TIPOTAB, tab);
 | ||
|     m.show(F_TIPOTABE, tabe);
 | ||
|     m.show(F_TIPOTABEL, tabel);
 | ||
|   }
 | ||
|   
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::check_period(TMask& m)
 | ||
| {
 | ||
|   app()._anno = m.get_int(F_ANNO);
 | ||
|   const char f = app().frequenza_versamenti(m.get_long(F_CODDITTA), app()._anno);
 | ||
|   m.show(-2);
 | ||
|   m.show(F_MESE, f == 'M');
 | ||
|   m.show(F_TRIMESTRE, f == 'T');
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::selection_handler(TMask_field& f, KEY k)
 | ||
| {
 | ||
|   if (k == K_SPACE)
 | ||
|   {
 | ||
|     TMask& m = f.mask();
 | ||
|     const int sel = atoi(f.get());
 | ||
|     switch (sel)
 | ||
|     {
 | ||
|      case 1:
 | ||
|       {
 | ||
|         const bool b = atoi(m.field(F_LIVELLO).get()) == 1 ? TRUE : FALSE;
 | ||
|         m.show(F_CODIVA,b);
 | ||
|         m.show(F_ATTIVITA,!b);
 | ||
|         tipo_handler(m.field(F_TIPO),K_SPACE);
 | ||
|       }
 | ||
|       break;
 | ||
|      case 2:
 | ||
|         check_period(m);
 | ||
|       break;
 | ||
|      default: break;
 | ||
|     }
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::period_handler(TMask_field& f, KEY k)
 | ||
| {
 | ||
|   if (f.to_check(k))
 | ||
|   {
 | ||
|     TMask& m = f.mask();
 | ||
|     if (m.get_int(F_SELECTION) == 2)
 | ||
|       check_period(m);
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::set_print(int m)
 | ||
| {
 | ||
|   TMask msk("cg0400a");
 | ||
|   
 | ||
|   msk.set_handler(F_CODDITTA, period_handler);
 | ||
|   msk.set_handler(F_ANNO, period_handler);
 | ||
|   msk.set_handler(F_TIPO, tipo_handler);
 | ||
|   msk.set_handler(F_SELECTION, selection_handler);
 | ||
|   
 | ||
|   if (msk.run() != K_ENTER) 
 | ||
|     return FALSE;
 | ||
| 
 | ||
|   _tipo_lista = msk.get_int(F_SELECTION) == 1 ? ListaPerAliquota : ListaPerPeriodo;
 | ||
|   switch (_tipo_lista)
 | ||
|   {
 | ||
|     case ListaPerAliquota:
 | ||
|     {
 | ||
|       _sospmsk = _tipo_aliq = _tipo_attiv = 0;
 | ||
|       _codditta = msk.get_long(F_CODDITTA);
 | ||
|       prefix().set_codditta(_codditta);
 | ||
|       _annoiva = msk.get_int(F_ANNO);
 | ||
|       _tipoprog = msk.get_int(F_TIPO);       // 1 <=> vendite; 2 <=> acquisti 
 | ||
|       _livelloprog = msk.get_int(F_LIVELLO); // 1 <=> aliquota; 2 <=> attivita'
 | ||
|       _codivamsk  = msk.get(F_CODIVA);
 | ||
|       _codattmsk  = msk.get(F_ATTIVITA);
 | ||
|       if (_livelloprog == 1 && _tipoprog == 2) 
 | ||
|         _tipo_aliq  = msk.get_int(F_TIPOTABE);
 | ||
|       if (_livelloprog == 2 && _tipoprog == 2) 
 | ||
|         _tipo_attiv = msk.get_int(F_TIPOTABEL);
 | ||
|       if (_tipoprog == 1 && _livelloprog == 1)
 | ||
|         _sospmsk = msk.get_int(F_TIPOTAB);  //vendite in genere; vendite in sospensione d'imposta
 | ||
|         
 | ||
|       ricalcola_liquidazione_se_necessario(_annoiva, 12);
 | ||
|       setta_intestazione();
 | ||
|       azzera_mesi();
 | ||
|       cerca_i_pim();
 | ||
|     }  
 | ||
|     break;
 | ||
|     case ListaPerPeriodo:
 | ||
|     { 
 | ||
|       _codditta = msk.get_long(F_CODDITTA);
 | ||
|       _anno = msk.get_int(F_ANNO);
 | ||
|       _datast = msk.get(F_DATASTAMPA);
 | ||
|       _mese   = msk.get_int(frequenza_versamenti(_codditta, _anno) == 'M' ? F_MESE : F_TRIMESTRE);
 | ||
|       _st_inizio_anno = msk.get_bool(F_STAMPA);
 | ||
|       _tipo_prog_reg = *msk.get(F_TIPOPROGREG); // L <=> Solo liquidazione, V <=> Solo volume d'affari
 | ||
|       prefix().set_codditta(_codditta);
 | ||
| 
 | ||
|       ricalcola_liquidazione_se_necessario(_anno, _mese);
 | ||
| 
 | ||
|       TLocalisamfile attiv(LF_ATTIV); 
 | ||
|       attiv.zero();
 | ||
|       attiv.put(ATT_CODDITTA, _codditta);   
 | ||
|       TRectype r(attiv.curr());
 | ||
|       //prospetto per ogni codice attivita' della ditta
 | ||
|       for(attiv.read(_isgteq); !attiv.eof(); attiv.next())
 | ||
|       {
 | ||
|         if (attiv.curr() != r) break;
 | ||
|           
 | ||
|         _cod_att = attiv.get("CODATT"); 
 | ||
|         _prima_pagina = TRUE;
 | ||
|       
 | ||
|         _iva_array.destroy();
 | ||
|         _iva1_array.destroy();
 | ||
|         _gen_array.destroy(); 
 | ||
|         _gen1_array.destroy(); 
 | ||
|           
 | ||
|         look_pim();
 | ||
|           
 | ||
|         print();
 | ||
|       } 
 | ||
|       return FALSE; 
 | ||
|     }
 | ||
|     break;
 | ||
|     default:
 | ||
|     break;
 | ||
|   }  
 | ||
| 
 | ||
| return TRUE;
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::calcola_totali(real& imp, real& imps)
 | ||
| {
 | ||
|   for (int i=0; i<=12; i++)
 | ||
|   {
 | ||
|     imp  += _mesi[i].imponibile;
 | ||
|     imps += _mesi[i].imposta;
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::cerca_tipo(TIva_array& iva_array,tiporec t, 
 | ||
|                                     real& imp, real& imps, real& det)
 | ||
| {
 | ||
|   int k = 0;
 | ||
|   bool trovato = FALSE;
 | ||
|   imp = imps = det = ZERO;
 | ||
|   while ( k < iva_array.items() && !trovato)
 | ||
|   {
 | ||
|     TRiga_iva& riga = (TRiga_iva&)iva_array[k];
 | ||
|     if (t == riga._tipo)
 | ||
|       trovato = TRUE;
 | ||
|     else k++;  
 | ||
|   }
 | ||
|   if (trovato)            
 | ||
|   {
 | ||
|     TRiga_iva& riga = (TRiga_iva&)iva_array[k];
 | ||
|     imp = riga._imponibile; 
 | ||
|     imps = riga._imposta;
 | ||
|     det = riga._detrazione; 
 | ||
|   }     
 | ||
| }
 | ||
| 
 | ||
| bool TProgressivi_iva::preprocess_page(int file, int counter)
 | ||
| {
 | ||
|   reset_print();
 | ||
|   
 | ||
|   switch (_tipo_lista)
 | ||
|   {
 | ||
|   case ListaPerPeriodo:
 | ||
|   {
 | ||
|     if (!_st_inizio_anno)
 | ||
|       prospetto_pagina(_gen_array,_iva_array);
 | ||
|     else 
 | ||
|     {
 | ||
|       if (_prima_pagina)
 | ||
|         prospetto_pagina(_gen1_array,_iva1_array);
 | ||
|       else
 | ||
|       {
 | ||
|         printer().formfeed();
 | ||
|         prospetto_pagina(_gen_array,_iva_array);
 | ||
|       }
 | ||
|     }  
 | ||
|   }
 | ||
|   break;
 | ||
|  case ListaPerAliquota:
 | ||
| {
 | ||
|   if (counter)
 | ||
|     _i++;
 | ||
|   else
 | ||
|     _i = 1;
 | ||
|   
 | ||
|   const char* mese = itom(_i);
 | ||
|   set_row(1,"%s", mese);
 | ||
|   set_row(1,"@26g%r", &_mesi[_i].imponibile);
 | ||
|   set_row(1,"@56g%r", &_mesi[_i].imposta);
 | ||
|   if (_i == 12)
 | ||
|   {
 | ||
|     real tot_impo = ZERO;
 | ||
|     real tot_imposta = ZERO;
 | ||
|     calcola_totali(tot_impo, tot_imposta);
 | ||
|     TString dep = "";
 | ||
|     set_row(2,(const char*) dep);
 | ||
|     set_row(3,"@8g%s", TR("Totale"));
 | ||
| 
 | ||
|     set_row(3,"@26g%r", &tot_impo);
 | ||
|     set_row(3,"@56g%r", &tot_imposta);
 | ||
|   }
 | ||
| }
 | ||
| break;
 | ||
| default:
 | ||
| break;
 | ||
| }
 | ||
| return TRUE;
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::prospetto_pagina(TGen_array& gen, TIva_array& iva)
 | ||
| { 
 | ||
|   real t_impov,t_imposv,t_impoa,t_imposa,t_impobd,t_imposbd;
 | ||
|   t_impov = t_imposv = t_impoa = t_imposa = t_impobd = t_imposbd = ZERO;
 | ||
|   int r = 1;
 | ||
|   TString80 descr;
 | ||
|   
 | ||
|   set_row(++r, FR("Cod.@40gVENDITE@77gACQUISTI@113gIMPORTAZIONI"));
 | ||
|   set_row(++r, FR("IVA  Descrizione@29gImponibile@48gImposta@67gImponibile@86gImposta@105gImponibile@124gImposta"));
 | ||
|   r+=2; 
 | ||
| 
 | ||
|   for (int k = 0; k < gen.items(); k++)
 | ||
|   {       
 | ||
|     TRiga_gen& riga = (TRiga_gen&)gen[k];
 | ||
|     descr = desc_iva(riga._codiva);
 | ||
|     if (riga._codiva[0] == '{') riga._codiva.ltrim(1);
 | ||
|     if (riga._impoven != ZERO)
 | ||
|       set_row(r, "@24g%r", &riga._impoven);
 | ||
|     if (riga._imposven != ZERO)
 | ||
|       set_row(r, "@40g%r", &riga._imposven);
 | ||
|     if (riga._impoacq != ZERO)
 | ||
|       set_row(r, "@62g%r", &riga._impoacq);
 | ||
|     if (riga._imposacq != ZERO)
 | ||
|       set_row(r, "@78g%r", &riga._imposacq);
 | ||
|     if (riga._impobd != ZERO)
 | ||
|       set_row(r, "@100g%r", &riga._impobd);
 | ||
|     if (riga._imposbd != ZERO)
 | ||
|       set_row(r, "@116g%r", &riga._imposbd); 
 | ||
|     if (riga._impoven != ZERO || riga._imposven != ZERO || riga._impoacq != ZERO
 | ||
|         || riga._imposacq != ZERO || riga._impobd != ZERO || riga._imposbd != ZERO)  
 | ||
|     {
 | ||
|       set_row(r, "@0g%-4s", (const char*)riga._codiva);
 | ||
|       set_row(r, "@5g%-.18s", (const char*)descr);
 | ||
|       r++;
 | ||
|     } 
 | ||
|     
 | ||
|     t_impov   += riga._impoven;
 | ||
|     t_imposv  += riga._imposven;
 | ||
|     t_impoa   += riga._impoacq;
 | ||
|     t_imposa  += riga._imposacq;
 | ||
|     t_impobd  += riga._impobd;
 | ||
|     t_imposbd += riga._imposbd;
 | ||
|   }
 | ||
|   
 | ||
|   gen.destroy();
 | ||
|   
 | ||
|   r+=2;
 | ||
|   set_row(r++, FR("Totale@24g%r@40g%r@62g%r@78g%r@100g%r@116g%r"), 
 | ||
|           &t_impov,&t_imposv,&t_impoa,&t_imposa,&t_impobd,&t_imposbd);
 | ||
|   r++;
 | ||
|   real im, is, d, im1, is1, d1; //inizializzati in cerca_tipo()
 | ||
|   cerca_tipo(iva,acq_ind_op_es,im,is,d); 
 | ||
|   t_impoa  += im;
 | ||
|   t_imposa += is;
 | ||
|   bool st_riga = FALSE;
 | ||
|   if (im != ZERO || is != ZERO) 
 | ||
|   {
 | ||
|     set_row(r++, FR("Totali acquisti indeducibili su ricavi esenti@62g%r@78g%r"), &im, &is); 
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_ind_art_19,im,is,d);
 | ||
|   cerca_tipo(iva,acq_bd_ind_art_19,im1,is1,d1);
 | ||
|   t_impoa  += im;
 | ||
|   t_imposa += is; 
 | ||
|   t_impobd  += im1;
 | ||
|   t_imposbd += is1; 
 | ||
|   if (im != ZERO || is != ZERO || im1 != ZERO || is1 != ZERO) 
 | ||
|   {
 | ||
|     set_row(r++, FR("Totali acquisti indeducibili per ART.19@62g%r@78g%r@100g%r@116g%r"), &im, &is, &im1, &is1);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_ind_pass_int,im,is,d);
 | ||
|   t_impoa  += im;
 | ||
|   t_imposa += is;    
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Totali acquisti indeducibili per passaggi interni@62g%r@78g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   r+=2;
 | ||
|   if (st_riga)  
 | ||
|     set_row(r++, FR("Totale generale IVA@24g%r@40g%r@62g%r@78g%r@100g%r@116g%r"),
 | ||
|             &t_impov,&t_imposv,&t_impoa,&t_imposa,&t_impobd,&t_imposbd);
 | ||
|   r+=3;
 | ||
|   const int kk = r;  // memorizza riga in cui scrivere "altri dati relativi alla dichiarazione"
 | ||
|   r+=2; 
 | ||
|   
 | ||
|   st_riga = FALSE;
 | ||
|   cerca_tipo(iva,acq_simp,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Acquisti in sospensione d'imposta@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,vend_simp,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)  
 | ||
|   {
 | ||
|     set_row(r++, FR("Vendite in sospensione d'imposta@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,cess_amm,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Cessione beni ammortizzabili@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_beni_riv,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Acquisto beni destinati alla rivendita@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_beni_ammort,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Acquisto beni ammortizzabili iva detraibile@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_beni_ammort_nd,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO) 
 | ||
|   {
 | ||
|     set_row(r++, FR("Acquisto beni ammortizzabili iva non detraibile@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_beni_leasing,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Altri beni strumentali acquisiti in leasing@49g%r@66g%r"), &im, &is);
 | ||
|     st_riga = TRUE;
 | ||
|   }
 | ||
|   cerca_tipo(iva,acq_amm_ultdetr,im,is,d);   
 | ||
|   if (im != ZERO || is != ZERO)
 | ||
|   {
 | ||
|     set_row(r++, FR("Acquisto beni soggetti a detrazione (6%%)@49g%r@66g%r@86g%r"), &im, &is, &d);
 | ||
|     st_riga = TRUE;
 | ||
|   }  
 | ||
|   if (st_riga) 
 | ||
|     set_row(kk, FR("ALTRI DATI RELATIVI ALLA DICHIARAZIONE@54gImponibile@74gImposta@91gDetrazione"));             
 | ||
|   
 | ||
|   iva.destroy();
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::get_dati_ditta()
 | ||
| {
 | ||
|   TString        codanagr;
 | ||
|   TString        tipoa;
 | ||
| 
 | ||
|   const TRectype & ditta = cache().get(LF_NDITTE, _codditta);   
 | ||
| 
 | ||
|   codanagr = ditta.get(NDT_CODANAGR);
 | ||
|   tipoa    = ditta.get(NDT_TIPOA);
 | ||
|   _ragsoc  = ditta.get(NDT_RAGSOC);
 | ||
| 
 | ||
|   TString16 key; key.format("%s|%s", (const char *) tipoa, (const char *) codanagr);
 | ||
|   const TRectype & anag = cache().get(LF_ANAG, key);   
 | ||
|   
 | ||
|   _cofi      = anag.get(ANA_COFI);
 | ||
|   _paiva     = anag.get(ANA_PAIV);
 | ||
|   _comunefis = anag.get(ANA_COMRF);
 | ||
| 
 | ||
|   if (_comunefis.empty()) 
 | ||
|     _comunefis = anag.get(ANA_COMRES);
 | ||
| 
 | ||
|   key = "|"; key << _comunefis;
 | ||
| 	const TRectype & dep = cache().get(LF_COMUNI, key);
 | ||
| 
 | ||
|   _comunefis   = dep.get(COM_DENCOM);
 | ||
|   _provfis     = dep.get(COM_PROVCOM);
 | ||
|   _cap         = dep.get(COM_CAPCOM);
 | ||
|   if (_comunefis.empty()) 
 | ||
|   {
 | ||
|     _viafis    = anag.get(ANA_INDRF);
 | ||
|     _viafis.rtrim();
 | ||
|     _viafis << " " << anag.get (ANA_CIVRF); 
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     _viafis    = anag.get(ANA_INDRES);
 | ||
|     _viafis.rtrim();
 | ||
|     _viafis << " " << anag.get (ANA_CIVRES); 
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| int TProgressivi_iva::stampa_intestazione_ditta()
 | ||
| {
 | ||
|   int r = 1;
 | ||
|   TString riga(132);
 | ||
| 
 | ||
|   get_dati_ditta();
 | ||
| 
 | ||
|   set_header (r, FR("Ditta %ld %s %s %s %s %s"), _codditta,
 | ||
|               (const char*)_ragsoc, (const char*)_viafis,
 | ||
|               (const char*)_cap, (const char*)_comunefis,
 | ||
|               (const char*)_provfis);
 | ||
|   r++;
 | ||
|   riga = FR("Data @>  Pag. @#");
 | ||
|   riga.right_just(123);
 | ||
|   
 | ||
|   TString80 dep; dep.format (FR("Partita iva %s Codice fiscale %s"), 
 | ||
|                               (const char*)_paiva, (const char*)_cofi);
 | ||
|   riga.overwrite(dep);
 | ||
|   set_header (r, riga);
 | ||
|   r+=3;
 | ||
|   
 | ||
|   return r; 
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::setta_intestazione()
 | ||
| {
 | ||
|   int r = 1;
 | ||
| 
 | ||
|   reset_header();
 | ||
| 
 | ||
|   r = stampa_intestazione_ditta();
 | ||
|   
 | ||
|   if (_livelloprog == 1)
 | ||
|     set_header(r++, FR("Gestione Iva@b@50gPROGRESSIVI IVA PER ALIQUOTA"));
 | ||
|   else set_header(r++, FR("Gestione Iva@b@50gPROGRESSIVI IVA PER ATTIVITA'"));
 | ||
|   r++;
 | ||
|   set_header(r++, FR("Anno liquidazione %d"), _annoiva);
 | ||
|   if (_tipoprog == 1) //vendite
 | ||
|   { 
 | ||
|     if (_livelloprog == 1)
 | ||
|     {
 | ||
|       if (_sospmsk == 1)
 | ||
|         set_header(r, TR("Vendite in genere"));
 | ||
|       else set_header(r, TR("Vendite in sospensione d'imposta"));
 | ||
|     } 
 | ||
|     else set_header(r, TR("Cessione beni da ammortizzare"));
 | ||
|   }
 | ||
|   else  //acquisti
 | ||
|   {
 | ||
|     if (_livelloprog == 1) //per codice iva
 | ||
|       switch (_tipo_aliq)
 | ||
|       {
 | ||
|       case 1:
 | ||
|         set_header(r, TR("Acquisti in genere"));
 | ||
|         break;
 | ||
|       case 2:
 | ||
|         set_header(r, TR("Acquisti indetraibili su operazioni esenti"));
 | ||
|         break;
 | ||
|       case 3:
 | ||
|         set_header(r, TR("Acquisti indetraibili passaggi interni"));
 | ||
|         break;
 | ||
|       case 4:
 | ||
|         set_header(r, TR("Acquisti indetraibili art.19"));
 | ||
|         break;
 | ||
|       case 5:
 | ||
|         set_header(r, TR("Acquisti base di calcolo per la ventilazione"));
 | ||
|         break;
 | ||
|       case 6:
 | ||
|         set_header(r, TR("Bolle doganali"));
 | ||
|         break;
 | ||
|       case 7:
 | ||
|         set_header(r, TR("Acquisti in sospensione d'imposta"));
 | ||
|         break;
 | ||
|       default:
 | ||
|         break;            
 | ||
|       }
 | ||
|     else //per attivita'
 | ||
|       switch (_tipo_attiv)
 | ||
|       {
 | ||
|       case 1:
 | ||
|         set_header(r, TR("Acquisti beni per rivendita"));
 | ||
|         break;
 | ||
|       case 2:
 | ||
|         set_header(r, TR("Acquisti beni da ammortizzare detraibili"));
 | ||
|         break;
 | ||
|       case 3:
 | ||
|         set_header(r, TR("Acquisti beni da ammortizzare non detraibili"));
 | ||
|         break;
 | ||
|       case 4:
 | ||
|         set_header(r, TR("Altri beni strumentali acquisiti in leasing"));
 | ||
|         break;
 | ||
|       case 5:
 | ||
|         set_header(r, TR("Acquisti beni da ammortizzare ult.detr. 6%"));
 | ||
|         break;
 | ||
|       default:
 | ||
|         break;            
 | ||
|       }  
 | ||
|   }
 | ||
|   r++;
 | ||
|   if (_livelloprog == 1)
 | ||
|     set_header(r++, "IVA %s",(const char*) _codivamsk);
 | ||
|   else
 | ||
| 	{
 | ||
| 		if (_annoiva > 2007)
 | ||
| 		{
 | ||
| 			TString key;
 | ||
| 
 | ||
| 			key.format("%ld|%s", _codditta, (const char *)_codattmsk);
 | ||
| 			const TString16 codateco = cache().get(LF_ATTIV, key, ATT_CODATECO);
 | ||
| 
 | ||
| 			set_header(r++, FR("ATTIVITA' %s"), (const char*) codateco);
 | ||
| 
 | ||
| 		}
 | ||
| 		else
 | ||
| 			set_header(r++, FR("ATTIVITA' %s"),(const char*) _codattmsk);
 | ||
| 	} 
 | ||
|   set_header(++r, FR("@31gImponibile@64gImposta"));
 | ||
| 
 | ||
| }
 | ||
| 
 | ||
| void TProgressivi_iva::preprocess_header()
 | ||
| {
 | ||
|   if (_tipo_lista == ListaPerPeriodo)
 | ||
|   {
 | ||
|     int soh = 1;       
 | ||
|     TString sep(132);
 | ||
|     TString ragsoc;
 | ||
|     TString16 descf; 
 | ||
|     TString16 key; key << _codditta;
 | ||
|     
 | ||
|     const TRectype & ditta = cache().get(LF_NDITTE, key); 
 | ||
| 
 | ||
| 		ragsoc  = ditta.get(NDT_RAGSOC); 
 | ||
|     
 | ||
| 		TString80 descr = desc_attivita(_cod_att);
 | ||
|     
 | ||
|     reset_header();
 | ||
|     
 | ||
|     const char f = frequenza_versamenti(_codditta, _anno);
 | ||
|     if (f == 'T')
 | ||
|       descf = TR(" TRIMESTRALE");
 | ||
|     else if (f == 'M')
 | ||
|       descf = TR(" MENSILE");
 | ||
|     else 
 | ||
|       descf = "";
 | ||
|     
 | ||
|     sep << TR("Ditta") << "  " << _codditta;
 | ||
|     sep << " " << ragsoc;
 | ||
|     sep << " " << descf;
 | ||
| 
 | ||
|     sep.left_just(132);
 | ||
|     
 | ||
|     set_header (soh++, (const char*) sep);
 | ||
|     
 | ||
|     sep = "";
 | ||
|     sep << TR("Data ") << _datast;
 | ||
|     sep << FR("  Pag. @#");
 | ||
| 
 | ||
|     sep.right_just(127);    
 | ||
|     
 | ||
|     sep.overwrite (TR("RIEPILOGO PROGRESSIVI"));
 | ||
|     set_header (soh++, (const char*)sep);
 | ||
|     sep.fill('-');
 | ||
|     set_header (soh++, (const char *) sep);      
 | ||
|     
 | ||
|     const char* pro_des = _tipo_prog_reg == 'L' ? TR("liquidazione IVA") : TR("Volume Affari");
 | ||
|     
 | ||
|     TString periodo;
 | ||
| 
 | ||
|     if (f == 'M')
 | ||
|       periodo = itom(_mese);
 | ||
|     else
 | ||
|       periodo.format(FR("%d trimestre"), ((_mese-1)/3) +1);
 | ||
|       
 | ||
|     if (_st_inizio_anno)
 | ||
|     {
 | ||
|       if (_mese == 13 || (_mese == 12 && !_prima_pagina))
 | ||
|         set_header(soh++, FR("Riepilogo progressivi %s annuale %d  Cod. Att. %s %s"), pro_des, _anno, (const char*) _cod_att, (const char*) descr);
 | ||
|       else
 | ||
|       if (_prima_pagina)
 | ||
|         set_header(soh++, FR("Riepilogo progressivi %s del periodo  %s  %d  Cod. Att. %s %s"), pro_des, (const char*) periodo, _anno, (const char*) _cod_att, (const char*) descr);
 | ||
|       else set_header(soh++, FR("Riepilogo progressivi %s al%s:  %s  %d  Cod. Att. %s %s"), pro_des, f == 'M' ? TR(" Mese di") : "", (const char*) periodo, _anno, (const char*) _cod_att, (const char*) descr);
 | ||
| 
 | ||
|     }
 | ||
|     else set_header (soh++, FR("Riepilogo progressivi %s del periodo  %s  %d  Cod. Att. %s %s"), pro_des, (const char*) periodo, _anno, (const char*) _cod_att, (const char*) descr);
 | ||
|     set_header (soh, (const char *) sep);
 | ||
|   } 
 | ||
| }
 | ||
| 
 | ||
| print_action TProgressivi_iva::postprocess_page(int file, int counter)
 | ||
| {
 | ||
|   switch (_tipo_lista)
 | ||
|   {
 | ||
|   case ListaPerPeriodo:
 | ||
|   {
 | ||
|     if (_st_inizio_anno && _mese != 13)
 | ||
|       if (_prima_pagina)
 | ||
|       {
 | ||
|         _prima_pagina = FALSE; 
 | ||
|         return REPEAT_PAGE;  
 | ||
|       } 
 | ||
|       else return NEXT_PAGE; 
 | ||
|   }
 | ||
|   break;
 | ||
|  case ListaPerAliquota:
 | ||
| {
 | ||
|   if (_i < 12) return REPEAT_PAGE;
 | ||
|   else return NEXT_PAGE;
 | ||
| }
 | ||
| break;
 | ||
| 
 | ||
| default:
 | ||
| break;
 | ||
| }
 | ||
| return NEXT_PAGE;  
 | ||
| }
 | ||
| 
 | ||
| int cg0400(int argc,char* argv[])
 | ||
| {
 | ||
|   TProgressivi_iva a;
 | ||
|   a.run(argc, argv, TR("Riepilogo progressivi IVA"));
 | ||
|   return 0;
 | ||
| }
 |