Files correlati : cg4.exe Ricompilazione Demo : [ ] Commento : Bug: 0000713 Il quadro VT non viene calcolato correttamente se la ditta ha piu' attività git-svn-id: svn://10.65.10.50/trunk@15126 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			3521 lines
		
	
	
		
			120 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			3521 lines
		
	
	
		
			120 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // ------------------------------------------------------------
 | ||
| // Calcolo liquidazioni
 | ||
| // Part 2: calcolo 
 | ||
| // fv 21-1-94
 | ||
| // ------------------------------------------------------------
 | ||
| 
 | ||
| #include <config.h>
 | ||
| #include <recarray.h> 
 | ||
| #include <progind.h>              
 | ||
| #include <sheet.h>
 | ||
| 
 | ||
| #include "cg4300.h"
 | ||
| 
 | ||
| #include <nditte.h>
 | ||
| #include <attiv.h>
 | ||
| #include <tab1100.h>
 | ||
| #include <mov.h>
 | ||
| #include <rmoviva.h>
 | ||
| #include <pconti.h>
 | ||
| #include <utility.h>
 | ||
| #include <clifo.h>
 | ||
| #include <occas.h>
 | ||
| #include <comuni.h>
 | ||
| 
 | ||
| // -------------------- QUI comincia l'avventura --------------------------
 | ||
| // Datemi un punto di appoggio                           ******************
 | ||
| //           e mi ci appoggero'                          ******************
 | ||
| // ----------------------------------------------------- ******************
 | ||
|                         
 | ||
| bool TLiquidazione_app::recalc_all() 
 | ||
| {  
 | ||
|   _prind = new TProgind(_selected.ones()*2,  _printonly ? 
 | ||
|                         TR("       Stampa liquidazione...     \n"
 | ||
|                            "       Preparazione archivi      \n"
 | ||
|                            "                                    ") : 
 | ||
|                         TR("       Calcolo liquidazione...     \n"
 | ||
|                            "       Preparazione archivi      \n"
 | ||
|                            "                                    "),
 | ||
|                         TRUE,TRUE);
 | ||
| 
 | ||
|   for (int l = 0; l < _ditte->items(); l++)
 | ||
|   {                           
 | ||
|     if (_prind->iscancelled())
 | ||
|       break;
 | ||
| 
 | ||
|     if (_selected[(long)l])
 | ||
|     {                                     
 | ||
|       TToken_string& nomeditta = _ditte->row(l);
 | ||
|       const long codditta = nomeditta.get_long(1);
 | ||
|       const int save_month = _month;
 | ||
|       
 | ||
|       /* -------------------------------------------------------------
 | ||
|        * leggi parametri ditta necessari; stabilisci se annuale, 
 | ||
|        * se si' metti _month a 13
 | ||
|        *   istanzia _freqviva, _isbenzinaro, _isannual, _isriepilogo
 | ||
|        * --------------------------------------------------------------
 | ||
|        */
 | ||
|       
 | ||
|       _reg_arr.destroy(); // Azzera la cache dei registri per ogni ditta.
 | ||
|       _nditte->zero(); 
 | ||
|       _nditte->curr().put("CODDITTA",codditta);
 | ||
|       _nditte->read(); 
 | ||
|       _freqviva = nomeditta.get(3);
 | ||
|       bool mens = _freqviva == "M"; 
 | ||
| 
 | ||
|       // determina attivita' prevalente e istanzia cazzuole
 | ||
|       // per vedere che Kazzo di liquidazione calcolare
 | ||
|       TString attprev = _nditte->curr().get("CODATTPREV");
 | ||
| 			TString16 key;
 | ||
| 
 | ||
| 			key.format("%ld|%s", codditta, (const char *) attprev);
 | ||
| 	  
 | ||
| 			const TRectype & atts = cache().get(LF_ATTIV, key);
 | ||
|       // istanzia benzinaro
 | ||
|       _isbenzinaro = atts.get_bool("ART74_4");
 | ||
|       
 | ||
|       // riaggiusta relazione
 | ||
|       _nditte->read();               
 | ||
|       
 | ||
|       // strasemplificato: per l'annuale si sceglie annuale, altrimenti
 | ||
|       // e' la 12ma anche per le trimestrali.
 | ||
|       _isannual = _isriepilogo = _month == 13;
 | ||
|       
 | ||
|       TApplication::set_firm(codditta);
 | ||
|       
 | ||
|       // Imposta metodo arrotondamento imposte 
 | ||
|       TIva_round ir; 
 | ||
|       ir.set_default_iva_mode(atoi(_year), _isannual, codditta);
 | ||
|       
 | ||
|       _prind->addstatus(1);              
 | ||
|       
 | ||
|       /*
 | ||
|        * trimestrali impropriamente selezionate per mesi intermedi
 | ||
|        * provocano il ricalcolo dei progressivi mensili ma non la stampa    
 | ||
|        */
 | ||
|       _canprint = is_month_ok_strict(_month) || _month == 13;
 | ||
| 
 | ||
|       /* --------------------------------------------------------------
 | ||
|        * Ricalcola i mesi necessari: annuale e' un mese unico da 1/1 al 31/12
 | ||
|        * --------------------------------------------------------------
 | ||
|        */
 | ||
| 
 | ||
|       int need_refresh = FALSE;
 | ||
|       if (_recalc != ever)
 | ||
|       { 
 | ||
|         int m = _month == 13 ? _month : 1;
 | ||
|         for (; m < _month; m++)
 | ||
|           if (is_month_ok_strict(m) && (!look_lim(m) || !_lim->get_bool("B0")))
 | ||
|           {
 | ||
|              need_refresh = TRUE; 
 | ||
|              break;
 | ||
|           }
 | ||
| 
 | ||
|         if (need_refresh && yesno_box(TR("Alcuni mesi precedenti non "
 | ||
|             "risultano ricalcolati. E' consigliabile il ricalcolo. "
 | ||
|             "Si desidera eseguirlo?")))
 | ||
|             _recalc = ever;
 | ||
|        }         
 | ||
|        int m;
 | ||
|        for (m = 1; m <= _month; m++)   // fino a 13 compreso
 | ||
|          if (is_month_plain(m) || _recalc == ever)
 | ||
|          {               
 | ||
|            if (_prind->iscancelled()) break;
 | ||
|            update_firm(m);
 | ||
|          }
 | ||
|       
 | ||
|       // se ci sono altri mesi dopo l'ultimo calcolato, invalida il 
 | ||
|       // flag 'calcolato' del primo, per causare il ricalcolo dei
 | ||
|       // successivi (evitando problemi per credito precedente)
 | ||
|       for (m = _month+1; m <= 13; m++)
 | ||
|         if (look_lim(m))
 | ||
|         { 
 | ||
|           _lim->put("B0","");
 | ||
|           _lim->rewrite();
 | ||
|           break; 
 | ||
|         } 
 | ||
|         
 | ||
|       _month = save_month;      
 | ||
|     }  
 | ||
|   }
 | ||
|   bool canc = _prind->iscancelled();
 | ||
|   if (!canc) _prind->addstatus(1);
 | ||
| 
 | ||
|   TApplication::set_firm(__firm);
 | ||
|   delete _prind;  _prind = NULL;
 | ||
|   
 | ||
|   return !canc;
 | ||
| }
 | ||
| 
 | ||
| bool TLiquidazione_app::update_firm(int month, bool recalc)
 | ||
| {
 | ||
|   // Se recalc e' TRUE considera la necessita' di ricalcolare e le
 | ||
|   // opzioni utente. Se FALSE se ne impipa dell'utente e ricalcola 
 | ||
|   // se necessario (serve nelle chiamate ricorsive)
 | ||
|   // Ritorna FALSE soltanto se il ricalcolo era necessario e non e'
 | ||
|   // stato effettuato per scelta dello stronzo commercialista.
 | ||
| 	if (month == 13 && recalc)
 | ||
| 	{
 | ||
| 		TTable pem("PEM");
 | ||
| 
 | ||
| 		for (int reg = 0; reg < 23; reg++)
 | ||
| 		{
 | ||
| 			look_pem(pem, reg);			
 | ||
| 			pem.zero("R0");
 | ||
| 			pem.zero("R1");
 | ||
| 			pem.rewrite();
 | ||
| 		}
 | ||
| 	}
 | ||
| 
 | ||
| 
 | ||
|   look_lim(liq_month(month), TRUE);
 | ||
|   _isdiffacc  = is_differita();
 | ||
|  _isdifferita = _isdiffacc;
 | ||
| 
 | ||
|   look_lia();
 | ||
|   _isintr = _freqviva == "T" && !_lia->get_bool("B3");  // was CNF_DITTA->InTrtr
 | ||
|   _gest4  = _isbenzinaro && _lia->get_bool("B4");       // was CNF_DITTA->Gest74
 | ||
| 
 | ||
|   // controlla che il periodo corrente non sia l'inizio dell'attivita'
 | ||
|   // nel caso, differita va a FALSE                  
 | ||
|   _monthinatt = 1;
 | ||
|   const TDate inatt = _nditte->curr().get("DINIZIOATT");
 | ||
|   if (is_in_liq_period(inatt)) 
 | ||
|     _isdifferita = FALSE;
 | ||
|   if (inatt.year() == atoi(_year)) 
 | ||
|     _monthinatt = inatt.month();
 | ||
| 
 | ||
|   {
 | ||
|     TConfig cnf1(CONFIG_STUDIO, "cg");
 | ||
|     _isricacq = cnf1.get_bool("RicAcq") && month == 13;
 | ||
|   }
 | ||
| 
 | ||
|   // ricalcolo normale  
 | ||
|   // lim c'e' solo per i trimestri
 | ||
|   bool ok = _lim->get_bool("B0");
 | ||
|   if (ok && !recalc) return TRUE; 
 | ||
|   if (_recalc_regis)
 | ||
|     ok = FALSE; // Se sta ricalcolando i PRM/PRP se ne sbatte delle LIM
 | ||
|   bool calc = (_recalc == ever || (_recalc == one && is_month_ok(month,_month)));
 | ||
|   if (!calc && _recalc != never) calc = !ok;
 | ||
|   bool gheravergot = FALSE;
 | ||
|   bool quater      = FALSE;
 | ||
|   
 | ||
|   TToken_string atts;
 | ||
|   TToken_string cattivs;
 | ||
|   
 | ||
|   // casini per stampa minchie in coda ai registri                           
 | ||
|   bool riepliq = _isregis ? _riepilogo : FALSE; 
 | ||
|   bool stliq = TRUE;
 | ||
|   
 | ||
|   _nditte->save_status();  
 | ||
|   if (_nditte->is_first_match(LF_ATTIV))
 | ||
|   {
 | ||
|     TString buf(256);
 | ||
|     do
 | ||
|     {
 | ||
|       const TString8 codatt = _nditte->curr(LF_ATTIV).get("CODATT");
 | ||
|       TString80 desatt = _nditte->curr(LF_ATTIV).get("DESCR");
 | ||
|       quater           = _nditte->curr().get_bool("FLIVA11Q");
 | ||
| 
 | ||
|       // attivita' mista: ce ne sono in realta' due
 | ||
|       // viene calcolato nel ciclo su tipoatt (che viene ripetuto solo
 | ||
|       // se diventa TRUE);
 | ||
|       _mixed     = FALSE;
 | ||
|       
 | ||
|       buf.format( _printonly ? FR("Stampa liquidazione (%d)...\n%s: %s\n") : 
 | ||
|                FR("Calcolo liquidazione (%d)...\n%s: %s\n"),
 | ||
|                month,
 | ||
|                (const char*)_nditte_r->get("RAGSOC"),
 | ||
|                (const char*)desatt); 
 | ||
|                
 | ||
|       if (_prind) _prind->set_text(buf);
 | ||
|       
 | ||
|       // se ricalcola l'annuale si tiene tutte le vendite e corrispettivi di
 | ||
|       // tutti i lerci mesi. Analogamente se sta calcolando una trimestrale.
 | ||
|       // Nel caso di trimestrale con ricalcolo trimestri precedenti azzera
 | ||
|       // ad ogni inizio di trimestre.
 | ||
|       if (!(_freqviva == "T" && (month != 1 && month != 4 && month != 7 && month != 10 && month != 13)))
 | ||
|       { 
 | ||
|         _vend_arr.destroy();
 | ||
|         _corr_arr.destroy();
 | ||
|       } 
 | ||
|       
 | ||
|       cattivs = "";
 | ||
|       
 | ||
|       for (int tipoatt = 1; tipoatt <= (_mixed ? 2 : 1); tipoatt++)
 | ||
|       {
 | ||
|         TString8 cattiv(codatt); bool waspla;
 | ||
|         
 | ||
|         cattiv << tipoatt;
 | ||
|         if (tipoatt == 1 && (waspla = look_pla(cattiv, FALSE)))
 | ||
|         {
 | ||
|           _p8          = _pla->get_real("R5");
 | ||
|           _p8b         = _pla->get_real("R6");
 | ||
|           _p9          = _pla->get_real("R7");
 | ||
|           _isplafond   = !(_p8.is_zero() && _p8b.is_zero() && 
 | ||
|                            _p9.is_zero());
 | ||
|           _isservizio  = _pla->get("S7") == "S";
 | ||
|           _mixed       = _pla->get("S7") == "M" || _pla->get("S7") == "E";
 | ||
|           
 | ||
|           const TString4 yr(_year);
 | ||
|           TAssoc_array& pa = _prorata.perc_array();
 | ||
| 
 | ||
|           pa.destroy();
 | ||
|           pa.add("DEF", _pla->get_real("R8")); // Percentuale di default, anno corrente
 | ||
| 
 | ||
|           const int anno  = atoi(_year) - 2;
 | ||
|           
 | ||
|           for (int i = atoi(_year); i>=anno; i--)
 | ||
|           {
 | ||
|             _year = format("%d", i);
 | ||
|             if (look_pla(cattiv, FALSE)) // Reperisce percentuale prorata anno indicato (se esiste la tabella)
 | ||
|               pa.add(_year, _pla->get_real("R8"));
 | ||
|           }
 | ||
|           _year = yr;     // Risetta l'anno corretto e riposiziona la tabella...
 | ||
|           look_pla(cattiv, FALSE);
 | ||
|         }
 | ||
|         else
 | ||
|           _isservizio  = _nditte->curr(LF_ATTIV).get("TIPOATT") == "S";
 | ||
| 
 | ||
|         _isviaggio   = _nditte->curr(LF_ATTIV).get_bool("REG74TER");
 | ||
|         _isagricolo  = _nditte->curr(LF_ATTIV).get_bool("REGAGR");
 | ||
|         _isagr98     = _isagricolo && atoi(_year) >= 1998;
 | ||
|         _isvent = FALSE; 
 | ||
| 
 | ||
|         if (!_recalc_regis && tipoatt == 1 && waspla && month == 13)
 | ||
|         {
 | ||
|           // azzera pla dove serve             
 | ||
|           _pla->put("R0","");
 | ||
|           _pla->put("R1","");
 | ||
|           _pla->put("R2","");
 | ||
|           _pla->put("R3","");
 | ||
|           _pla->put("R4","");
 | ||
|           _pla->put("R13","");
 | ||
|           _pla->put("R9","");
 | ||
|           _pla->put("R10","");
 | ||
|           _pla->put("R11","");
 | ||
|           _pla->put("R12","");
 | ||
|           _pla->put("R14","");
 | ||
|           _pla->put("R15","");
 | ||
|           _pla->put("R16","");
 | ||
|           _pla->put("R17","");
 | ||
|           _pla->put("S1","0");
 | ||
|           _pla->put("S2","0");
 | ||
|           _pla->put("S3","0");
 | ||
|           _pla->rewrite();
 | ||
|         }
 | ||
|         
 | ||
|         for (_reg->first(); _reg->good(); _reg->next())
 | ||
|         {
 | ||
|           if (codatt == _reg->get("S8"))          
 | ||
|           {
 | ||
|             if (_reg->get_int("I0") == 2) 
 | ||
|               if (!_isvent) _isvent = _reg->get_bool("B3"); 
 | ||
|           }  
 | ||
|         }
 | ||
|         
 | ||
|         if (!_isregis)
 | ||
|           stliq = riepliq = TRUE;
 | ||
|         
 | ||
|         if (_comp_acconto)
 | ||
|           stliq = riepliq = FALSE;
 | ||
|         
 | ||
|         if (calc || !recalc)
 | ||
|           if (!update_att(month, cattiv) && stliq)
 | ||
|             describe_error(TR("Attivita' non ricalcolate: possibili errori"),
 | ||
|                            codatt);        
 | ||
|         if (_recalc_regis)
 | ||
|           continue;
 | ||
|           
 | ||
|         if (month == 13)
 | ||
|           recalc_annual(cattiv);
 | ||
|         
 | ||
|         // vediamo se c'e' qualcosa da raccontare
 | ||
|         gheravergot = _isannual || _isriepilogo;
 | ||
|         if (!gheravergot) 
 | ||
|         {
 | ||
|           look_plm(month,cattiv);
 | ||
|           gheravergot = !_plm->get_real("R0").is_zero() ||
 | ||
|                         !_plm->get_real("R1").is_zero();
 | ||
|         }                            
 | ||
| 
 | ||
|         if (month == _month && riepliq)
 | ||
|           describe_att(month, cattiv, gheravergot, 
 | ||
|                        '0' + (_mixed ? tipoatt : 0)); 
 | ||
|         
 | ||
|         atts.add(cattiv);
 | ||
|         cattivs.add(cattiv);
 | ||
|       } // for tipoatt
 | ||
|       
 | ||
|       if (_recalc_regis)
 | ||
|         continue;
 | ||
| 
 | ||
|       // se attivita' mista stampa riepilogo
 | ||
|       if (_mixed && month == _month && riepliq) 
 | ||
|         describe_att(month,cattivs, TRUE, 'M');
 | ||
|         
 | ||
|       // se sta calcolando l'annuale, scrive tutti i dati calcolati per il trasferimento
 | ||
|       // sui files adibiti a mantenere le informazioni per IVA 11: tab1100a e tab1100b
 | ||
|       if (_is_interactive && month == 13)
 | ||
|         iva11_set_arr_phase_2(codatt); // scorre tutti i maledetti PIM di questa ditta/attivita' per completare _iva11_arr
 | ||
|     } 
 | ||
|     while (_nditte->next_match(LF_ATTIV));
 | ||
| 
 | ||
|     if (_recalc_regis)
 | ||
|     {
 | ||
|       _nditte->restore_status();
 | ||
|       // Se trattasi di ricalcolo per registri, setta il flag relativo, onde evitare ricalcoli 
 | ||
|       // nel caso di registro riepilogativo: se i PRM esistono gia' (perche' creati
 | ||
|       // da stampa bollato precedente o altro riepilogo) non vanno ricalcolati.
 | ||
|       look_lim(month, TRUE); // Crea se non esiste
 | ||
|      _lim->put("B1","X");
 | ||
|      _lim->rewrite();
 | ||
|       return TRUE;
 | ||
|     }
 | ||
| 
 | ||
|     // se quater stampa riepilogo
 | ||
|     if (quater && month == _month && riepliq) 
 | ||
|       describe_att(month,atts, TRUE, 'Q');
 | ||
|     
 | ||
|     // occorre poterla chiamare altre volte con mesi diversi
 | ||
|     _nditte->restore_status();
 | ||
|     
 | ||
|     // aggiorna le liquidazioni
 | ||
|     //13/12/1995. 
 | ||
|     //Concordato con Ferdinando che, visto che qualche
 | ||
|     //calcoluccio viene fatto anche in write_liq, essa
 | ||
|     //verra' sempre richiamata. 
 | ||
|     //if (calc || !recalc)
 | ||
|     //fine
 | ||
|       
 | ||
|     // Se siamo in annuale e se non e' stato indicato di ricalcolare (stampa liquidazione chiamata
 | ||
|     // dalla stampa registri) non riscrivere i risultati delle liquidazioni,
 | ||
|     if ((is_month_ok_strict(month) && _month != 13 && _recalc != never) || _is_interactive /*month == 13*/ )
 | ||
|        write_liq(month, atts);
 | ||
|          
 | ||
|     // occorre poterla chiamare altre volte con mesi diversi
 | ||
|     _nditte->restore_status();
 | ||
| 
 | ||
|     // rimborso infraannuale
 | ||
|     _DescrItem* rimb_d = NULL;
 | ||
|     if (month == _month)
 | ||
|     {
 | ||
|       // unica nel suo genere, recalc_rimborso ritorna
 | ||
|       // un bel descritem (NULL se non si rimborsa un cas)
 | ||
|       // da passare a describe_liq
 | ||
|       rimb_d = recalc_rimborso(month,atts, stliq);
 | ||
|       if (stliq)
 | ||
|       {
 | ||
|         describe_firm(month);
 | ||
|         //describe_liq(_month, atts, _isregis ? NULL : rimb_d);
 | ||
|         describe_liq(_month, atts, rimb_d);
 | ||
|       }
 | ||
|       if (_month == 13 && look_lim(_month)) // scrive i risultati solo in annuale
 | ||
|       {
 | ||
|         real r0 = _lim->get_real("R0");
 | ||
|         iva11_write(rimb_d == NULL || r0.sign() >= 0);      // scrive su tab1100 at last.
 | ||
|       }
 | ||
|     }
 | ||
| 
 | ||
|     //in caso di stampa registri e in caso sia 
 | ||
|     //stato calcolato l'acconto (metodo analitico)
 | ||
|     //deve essere stampato il prospetto di liquidazione
 | ||
|     //dell'acconto in coda al resto
 | ||
|     if (_isregis && stliq)
 | ||
|     {
 | ||
|       if ((month == 12 && _freqviva == "M") || 
 | ||
|           (month == 12 && _isbenzinaro && _gest4) ||
 | ||
|           (month == 13 && _freqviva == "T" && !_isbenzinaro) ||
 | ||
|           (month == 13 && _isbenzinaro && !_gest4))  
 | ||
|         describe_liqacc();
 | ||
|     }
 | ||
|   }
 | ||
|   return ok || calc;
 | ||
| }
 | ||
| 
 | ||
| bool TLiquidazione_app::update_att(int month, const char* codatt,
 | ||
|                                    bool recalc)
 | ||
|   // viene passato un codice attivita' con codatt+tipoatt
 | ||
|   // vedi update_firm per il burdel dei calc e recalc
 | ||
|   // occhecasino. Se _comp_acconto e' TRUE, i movimenti considerati
 | ||
|   // saranno solo quelli di dicembre per data <= 20/12; 
 | ||
|   // il ricalcolo e' FORZATO da _recalc messo a one
 | ||
| { 
 | ||
|   look_plm(month, codatt, TRUE);
 | ||
|   bool ok = _plm->get_bool("B0");
 | ||
|   if (_recalc_regis)
 | ||
|     ok = FALSE; // Se sta ricalcolando i PRM/PRP se ne sbatte dei PLM
 | ||
|   if (ok && !recalc) return TRUE; 
 | ||
|   bool calc = _recalc == ever || (_recalc == one && is_month_ok(month,_month));
 | ||
|   if (!calc && _recalc != never) calc = !ok; 
 | ||
| 
 | ||
|   if (calc || !recalc)
 | ||
|   {
 | ||
|     zero_att(month,codatt);            
 | ||
|     recalc_att(month,codatt);
 | ||
|     if (!_recalc_regis)
 | ||
|     {
 | ||
|       // Ricalcolo ventilazione e ag. viaggio: 
 | ||
|       //  - tutti i mesi se e' mensile
 | ||
|       //  - nei mesi 3,6,9,12,13 se trimestrale
 | ||
|       if (_freqviva == "M" || (_freqviva == "T" && (is_trim(month) || month == 13)))
 | ||
|       {
 | ||
|         recalc_ventilation(month, codatt); 
 | ||
|         recalc_viaggio(month, codatt);
 | ||
|       }
 | ||
|       recalc_corrispettivi(month, codatt);  
 | ||
|     }
 | ||
|   }
 | ||
|    
 | ||
|   return ok || calc;  
 | ||
| }
 | ||
|      
 | ||
| void TLiquidazione_app::zero_att(int month, const char* codatt)
 | ||
| {
 | ||
|   TTable *arr[4]      = { _pim, _pis, _prm, _prp };
 | ||
|   const char* flds[]  = { "R0", "R1", "R2", "R3", "R4", "R5", "R6", "R7", "R8",
 | ||
|                           "R9", "R10", "R11", "R12", "R13", "R14", "S0", "S1", "S2" };
 | ||
|                           
 | ||
|   TString att, year, codtab;
 | ||
|   int m, start, stop;
 | ||
| 
 | ||
|   start = 0; stop = 1;
 | ||
| 
 | ||
|   if (_recalc_regis)
 | ||
|   {
 | ||
|     // Se stiamo ricalcolando per registri(_recalc_regis) azzera PRM e PRP
 | ||
|     start = 2; stop = 3;
 | ||
|   }
 | ||
|   else
 | ||
|     if (atoi(_year) < 1998)
 | ||
|       stop = 0; // Solo PIM 
 | ||
|   
 | ||
|   for (int i = start; i <= stop; i++) // Ciclo per le tabelle da azzerare
 | ||
|   {
 | ||
|     TTable * tab = (TTable*) arr[i];
 | ||
|     CHECK(tab, "Invalid table element");
 | ||
|     for (tab->first(); !tab->eof(); tab->next()) // Ciclo per i record di tabella
 | ||
|     {
 | ||
|       codtab = tab->get("CODTAB");
 | ||
|       m = atoi(codtab.mid(13,2));
 | ||
|       att = codtab.mid(4,6);
 | ||
|       year = codtab.mid(0,4);
 | ||
|       if (m == month && att == codatt && year == _year)
 | ||
|       {
 | ||
|         for (int j = 0; j < 18; j++) // Ciclo per i campi del record da azzerare
 | ||
|           tab->zero(flds[j]);
 | ||
|         tab->rewrite();
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
|   
 | ||
|   if (!_recalc_regis)
 | ||
|   {
 | ||
|     if (look_plm(month, codatt))
 | ||
|     {
 | ||
|       // zero PLM, POM, PAM, PUM
 | ||
|       TString codtab(_plm->get("CODTAB"));
 | ||
|       _plm->zero();
 | ||
|       _pom->zero();   
 | ||
|       _pam->zero();   
 | ||
|       _pum->zero();
 | ||
|       _plm->put("CODTAB", codtab);   
 | ||
|       _pom->put("CODTAB", codtab);   
 | ||
|       _pam->put("CODTAB", codtab);   
 | ||
|       _pum->put("CODTAB", codtab);   
 | ||
|       _plm->rewrite();
 | ||
|       _pam->rewrite();
 | ||
|       _pom->rewrite();
 | ||
|       _pum->rewrite();
 | ||
|     }
 | ||
|     
 | ||
|     // Azzera i progressivi per il prospetto agricolo dal 1998
 | ||
|     if (_isagr98)
 | ||
|     {
 | ||
|       for (_pia->first(); !_pia->eof(); _pia->next())
 | ||
|       {
 | ||
|         const int m = atoi(*_pia_mese);
 | ||
|         const TString16 att = (const char*)*_pia_codatt;
 | ||
|         if (m == month && att == codatt && (_year == *_pia_anno))
 | ||
|         {
 | ||
|           _pia->put("R0",""); // Imponibile
 | ||
|           _pia->put("R1",""); // Imposta
 | ||
|           _pia->rewrite();
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
|   if (_isplafond && month != 13)
 | ||
|     zero_plafond(month,codatt);
 | ||
| }
 | ||
| 
 | ||
| void TLiquidazione_app::recalc_att(int month, const char* codatt)
 | ||
|   // il codatt passato e' codice att + tipo att ( IN {1|2} )
 | ||
|   // occhecasino. Se _comp_acconto e' TRUE, i movimenti considerati
 | ||
|   // saranno solo quelli di dicembre per data <= 20/12; 
 | ||
| { 
 | ||
|   real totintra         = 0.0;
 | ||
|   real nond19_imp       = 0.0;
 | ||
|   real nond19_iva       = 0.0;
 | ||
|   real ammort_det       = 0.0;
 | ||
|   real ammort_det_iva   = 0.0;
 | ||
|   real ammort_indet     = 0.0;
 | ||
|   real ammort_indet_iva = 0.0;
 | ||
|   real ammort_6         = 0.0;
 | ||
|   real ammort_6_iva     = 0.0;
 | ||
|   real acq_riv          = 0.0;
 | ||
|   real acq_riv_iva      = 0.0;
 | ||
|   real leasing          = 0.0;
 | ||
|   real leasing_iva      = 0.0;
 | ||
|   real cess_amm         = 0.0;
 | ||
|   real cess_amm_iva     = 0.0;
 | ||
|   real acquisti         = 0.0;
 | ||
|   real acquisti_iva     = 0.0;
 | ||
|   real vendite          = 0.0;
 | ||
|   real vendite_iva      = 0.0;
 | ||
|   real esenti_c1        = 0.0;
 | ||
|   real esenti_c2        = 0.0;
 | ||
|   real esenti_c3        = 0.0;
 | ||
|   real esenti_c1a       = 0.0;
 | ||
|   real esenti_c3_bam    = 0.0;   // Beni ammorizzabili esenti c3
 | ||
|   real esenti_c1a_bam   = 0.0;   // Beni ammorizzabili esenti c1a
 | ||
|   real esenti_b14       = 0.0;
 | ||
|   
 | ||
|   // Comunicazione dati iva annuale (dal 2003)
 | ||
|   real cessioni_cd1_1   = 0.0;   // Totale operazioni attive
 | ||
|   real cessioni_cd1_2   = 0.0;   // non imponibili
 | ||
|   real cessioni_cd1_3   = 0.0;   // esenti
 | ||
|   real cessioni_cd1_4   = 0.0;   // intra
 | ||
|   real acquisti_cd2_1   = 0.0;   // Totale operazioni passive
 | ||
|   real acquisti_cd2_2   = 0.0;   // non imponibili
 | ||
|   real acquisti_cd2_3   = 0.0;   // esenti
 | ||
|   real acquisti_cd2_4   = 0.0;   // intra
 | ||
|   real oroargento_cd3_1 = 0.0;   // imponibile acquisto oro e argento
 | ||
|   real oroargento_cd3_2 = 0.0;   // imposta acquisto oro e argento
 | ||
|   real rottami_cd3_3    = ZERO;  // imponibile acquisto rottami
 | ||
|   real rottami_cd3_4    = ZERO;  // imposta acquisto rottami
 | ||
|   
 | ||
|   real vt_imponibile[23];
 | ||
|   real vt_imposta[23];
 | ||
| 	
 | ||
| 	real esni_rimb        = 0.0;   // ci sommo tutti esenti e ni validi per rimborso
 | ||
|   real corr_CEE         = 0.0;
 | ||
|   real corr_noCEE       = 0.0;
 | ||
|   real acq_CEE          = 0.0;
 | ||
|   real acq_noCEE        = 0.0;
 | ||
|   real corr_misCEE      = 0.0;
 | ||
|   real acq_misCEE       = 0.0;
 | ||
|   real acq_misnoCEE     = 0.0;
 | ||
|   real agr_detIA        = 0.0;
 | ||
|   real agr_1i           = 0.0;
 | ||
|   real agr_2i           = 0.0;
 | ||
|   real agr_1            = 0.0;
 | ||
|   real agr_2            = 0.0;
 | ||
|   real agr_3            = 0.0;
 | ||
|   real agr_4            = 0.0;
 | ||
|   real agr_5            = 0.0;
 | ||
|   real agr_6            = 0.0;
 | ||
|   real agr_7            = 0.0;
 | ||
|   real acq_ies          = 0.0;
 | ||
|   real acq_ies_iva      = 0.0;                                    
 | ||
|   real ult_detr         = 0.0;
 | ||
|   real acq_pint         = 0.0;
 | ||
|   real acq_pint_iva     = 0.0;
 | ||
|   real spgen            = 0.0;
 | ||
|   real spgen_iva        = 0.0;
 | ||
|   real assp_imp         = 0.0;
 | ||
|   real assp_iva         = 0.0;
 | ||
|   real vssp_imp         = 0.0;
 | ||
|   real vssp_iva         = 0.0;
 | ||
|   real assl_imp         = 0.0;
 | ||
|   real assl_iva         = 0.0;
 | ||
|   real vssl_imp         = 0.0;
 | ||
|   real vssl_iva         = 0.0;
 | ||
|   real bdog_imp         = 0.0;
 | ||
|   real bdog_iva         = 0.0;
 | ||
|   real agr_imp          = 0.0;
 | ||
|   real agr_iva          = 0.0;
 | ||
|   
 | ||
|   for (int j = 0; j < 23; j++)
 | ||
| 	{
 | ||
| 		vt_imponibile[j] = ZERO;
 | ||
| 		vt_imposta[j] = ZERO;
 | ||
| 	}
 | ||
| 
 | ||
| 	// Nel seguente assoc, vengono memorizzati gli acquisti iva registrati quest'anno
 | ||
|   // ma con anno documento precedente. Di conseguenza per un corretto calcolo prorata
 | ||
|   // e' necessario distinguire gli importi, appunto, per anno.
 | ||
|   // Questo nuovo calcolo prorata, vale solo per gli anni oltre il 1998.
 | ||
|   TAssoc_array    acq_iva_anni_prec; 
 | ||
|   
 | ||
|   TTable *arr[4]      = { _pim, _pis, _prm, _prp }; //Tabelle con la stessa struttura
 | ||
|   
 | ||
|   const int year_int    = atoi(_year); // Basta con le atoi()...
 | ||
| 
 | ||
|   // Nuova selezione filtro dal 1998. Rende molto piu' pesante il calcolo, complimenti a tutti.
 | ||
|   // Il campo MESELIQ sulla testata dei movimenti indica il mese di liquidazione in cui considerare
 | ||
|   // il movimento stesso. Tale campo e' un intero che va da 0 a 12, dove i numeri da 1 a 12 rappresentano
 | ||
|   // i rispettivi mesi (Gennaio...Dicembre) e lo zero significa che questo movimento va considerato
 | ||
|   // seguendo la data di  registrazione, ovvero NORMALMENTE.
 | ||
|   // Questo significa che:
 | ||
|   //   si includano nel cursore tutti i movimenti da questo inizio mese fino all fine dell'anno 
 | ||
|   // Il primo periodo dell'anno successivo (1 o 3 mesi se Trim.) va incluso se sto calcolando dicembre o l'annuale:
 | ||
|   // puo' esistere un doc. con DATAREG di gennaio dell'anno dopo ma MESELIQ==12; tale movimento va considerato in dicembre
 | ||
|   // dell'anno precedente (4 trimestre nel cazo di trimestruali).
 | ||
|   // Ovviamente un tale movimento siffatto andra' considerato allo stesso modo anche in liquidazione annuale.
 | ||
|   // Default date per agenzie viaggio: da inizio anno fino per considerare la DATA74TER
 | ||
|   // Esemplificazione dei cursori nei vari casi:
 | ||
|   // month < 12  : la regione andra' dal 01/month/_year al 31/12/_year
 | ||
|   //              selezione movimenti: datareg.month() == month && meseliq == 0 || meseliq == month
 | ||
|   // month == 12 : la regione andra' dal 01/month/_year al lastday/firstperiod/_year+1
 | ||
|   //              selezione movimenti: datareg.month() == month && meseliq == 0 || meseliq == month
 | ||
|   // month == 13 : la regione andra' dal 01/01/_year al lastday/firstperiod/_year+1
 | ||
|   //              selezione movimenti: datareg.year() == _year && meseliq != 12 || datareg.year() == _year+1 && meseliq == 12
 | ||
|   // Attenzione: nel caso si tratti di ricalcolo chiamato dalla stampa registri bollati, il cursore
 | ||
|   // sara' leggermente diverso: i movimenti sono solo quelli del mese, tutto l'anno se annuale (month == 13).
 | ||
|   // I movimenti del periodo selezionato dovranno essere tutti inclusi; in particolare quelli che
 | ||
|   // avranno il mese liquidazione != 0 dovranno essere messi nella tabella PRP, come riferimento
 | ||
|   // a Progressivi Registri periodo Precedente.
 | ||
|   
 | ||
|   TRectype  from(_cur->curr()); from.zero();
 | ||
|   TRectype  to(from);
 | ||
|   
 | ||
|   TDate f(1, month == 13 ? 1 : month, year_int); 
 | ||
|   TDate t;
 | ||
| 
 | ||
|   // Spiegazione dell'arcano segreto sulle agenzie viaggio:
 | ||
|   // non viene applicato lo stesso metodo delle ditte normali perche' si deve
 | ||
|   // tenere conto della DATA74TER se presente.   
 | ||
|   // Per le agenzie di viaggio si parte da inizio anno precedente
 | ||
|   if (_isviaggio)
 | ||
|     f = TDate(1, 1, year_int-1);
 | ||
|   
 | ||
|   if (year_int < 1998 || _recalc_regis) // Vecchia selezione o calcolo progoressivi per stampa registri bollati
 | ||
|   {
 | ||
|     t.set_month(month == 13 ? 12 : month);
 | ||
|     t.set_year(year_int);
 | ||
|   }
 | ||
|   else //Nuova selezione dal 1998 in poi
 | ||
|   {
 | ||
|     t.set_year(month < 12 ? year_int : year_int+1);
 | ||
|     t.set_month(month < 12 ? 12 : _freqviva == "M" ? 1 : 3);
 | ||
|   }
 | ||
|   
 | ||
|   t.set_end_month();
 | ||
| 
 | ||
|   from.put(MOV_DATAREG, f);
 | ||
|   to.put(MOV_DATAREG, t);
 | ||
|   
 | ||
|   _cur->freeze(FALSE);
 | ||
|   _cur->setregion(from, to);
 | ||
|   const long items = _cur->items();
 | ||
|   _cur->freeze();
 | ||
| 
 | ||
|   *_cur      = 0;
 | ||
| 
 | ||
|   TString16 trueatt(codatt); 
 | ||
|   const int tipatt = atoi(trueatt.sub(5));
 | ||
|   //trueatt    = trueatt.left(5);
 | ||
|   trueatt.cut(5);
 | ||
| 
 | ||
|   for (; _cur->pos() < items; ++(*_cur))
 | ||
|   {                               
 | ||
|     if ((_cur->pos() & 0x7F) == 0)
 | ||
|     {
 | ||
| #ifdef DBG
 | ||
|       TString msgdbg;
 | ||
|       msgdbg.format(FR("Ricalcolo attivita': %ld/%ld"),_cur->pos(),items);
 | ||
|       long freespace = xvt_sys_get_free_memory_kb();
 | ||
|       msgdbg << TR(" Memoria libera: ") << freespace << TR(" Kbytes.");
 | ||
|       xvtil_statbar_set(msgdbg);
 | ||
| #endif  
 | ||
|       do_events();
 | ||
|     }
 | ||
|     
 | ||
|     TDate date(_mov->get(MOV_DATAREG));
 | ||
|     const int liqmonth     = _mov->get_int(MOV_MESELIQ);
 | ||
|     const TString4 reg     = _mov->get("REG");
 | ||
|     const bool isreg       = look_reg(_mov->get("REG"));
 | ||
|     const TString4 tipodoc = _mov->get(MOV_TIPODOC);
 | ||
|     const bool corrisp     = _reg->get_bool("B0");  
 | ||
|     const tiporeg tipomov  = (tiporeg)_reg->get_int("I0");
 | ||
|     
 | ||
|     // Controlla se la data del documento si riferisce all'anno precedente (PRORATA 1998)
 | ||
|     TDate datedoc(_mov->get(MOV_DATADOC));
 | ||
|     
 | ||
|     if (_isviaggio)
 | ||
|     {
 | ||
|       if (tipomov == vendita && !(_mov->get(MOV_DATA74TER).empty())) 
 | ||
|         date = _mov->get_date(MOV_DATA74TER);
 | ||
|       if (date.year() != year_int)  // Controlla anno di appartenenza, altrimenti is_date_ok potrebbe non funzionare
 | ||
|         continue;
 | ||
|     }  
 | ||
|     /*
 | ||
|      * check register present, rmoviva present and date OK
 | ||
|      *
 | ||
|      * In un futuro prossimo, molto remoto, quando implementeremo il Client/Server, questo
 | ||
|      * filtro sulla data registrazione/mese liq.  andra' nel cursore stesso.
 | ||
|      * Ora viene implementato qui [is_date_ok()] per non appesantire ulteriormente 
 | ||
|      * la lettura dei movimenti.
 | ||
|      */
 | ||
|     const bool dok      = !is_date_ok(date, month, liqmonth, year_int);  
 | ||
|     const bool sreg     = !isreg;
 | ||
|     const bool rs8      = _reg->get("S8") != trueatt;
 | ||
|     const bool cmt      = !_cur->is_first_match(LF_RMOVIVA);
 | ||
|     
 | ||
|     if (dok || sreg || rs8 || cmt) 
 | ||
|       continue;
 | ||
| 
 | ||
|     const tipo_sospensione sosp_imp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna;
 | ||
|     const TRectype& rcs = _cur->curr(LF_CAUSALI);
 | ||
|     const bool fattrit  = rcs.get_bool("RITFATT");
 | ||
|     const bool cau_intra    = rcs.get_bool("INTRACOM");
 | ||
|     const bool cau_valintra = rcs.get_bool("VALINTRA");
 | ||
|     
 | ||
|     /*
 | ||
|      * Tipo documento da eliminare (Scudler 1994)   
 | ||
|      * Trattasi per lo piu' di non incassati
 | ||
|      * Da oggi vengono sommati nei real di S2 in pim 
 | ||
|      * assieme alle FS per stampa registri 
 | ||
|      */
 | ||
|      bool noninc = (tipodoc == "SN" || tipodoc == "CN" || tipodoc == "RN" ||
 | ||
|                     tipodoc == "IN" || tipodoc == "PG");
 | ||
|     
 | ||
|     /*
 | ||
|      * check date: se si calcola l'acconto, solo da 1/12 a 20/12 
 | ||
|      */     
 | ||
|     int accmonth = _isdifferita ? 11 : 12; 
 | ||
|     
 | ||
|     /* 
 | ||
|      * Patrizia: se e' differita i mov. vanno da 1/11 a 30/11 
 | ||
|      * potrei allora andarmi a leggere i risultati della liq di 11
 | ||
|      * ma il cliente potrebbe voler calcolare l'acconto prima
 | ||
|      * di aver calcolato la liquidazione (perche' cosi' complicato?)
 | ||
|      */  
 | ||
|     //if (_comp_acconto && date.month() == accmonth && date.day() > 20)
 | ||
|     if (_comp_acconto && date.month() == accmonth)
 | ||
|       if (!_isdifferita && date.day() > 20)
 | ||
|        continue;
 | ||
|     
 | ||
|     do
 | ||
|     {     
 | ||
|       int tipoatt= _rmoviva->get_int(RMI_TIPOATT);
 | ||
|       /*
 | ||
|        * puo' capitare per motivi brutalmente prassici
 | ||
|        * SENSU Sergio 1995, Guido
 | ||
|        */
 | ||
|       if (tipoatt == 0) tipoatt = 1;
 | ||
|       if (tipoatt != tipatt) 
 | ||
|         continue;    
 | ||
| 
 | ||
|       // totali parziali registrati nei pim per motivi ignoti
 | ||
|       real bolld_imp = 0.0;         // imponibile bolle doganali
 | ||
|       real bolld_iva = 0.0;         // imposta bolle doganali
 | ||
|       real asimp_imp = 0.0;         // imponibile acquisti sosp. imposta
 | ||
|       real asimp_iva = 0.0;         // imposta acquisti sosp. imposta
 | ||
|       real vsimp_imp = 0.0;         // imponibile vendite sosp. imposta
 | ||
|       real vsimp_iva = 0.0;         // imposta vendite sosp. imposta
 | ||
|       real rit_imp   = 0.0;         // imponibile fatture in ritardo
 | ||
|       real rit_iva   = 0.0;         // imposta fatture in ritardo
 | ||
|       real nin_imp   = 0.0;         // imponibile non incassati
 | ||
|       real nin_iva   = 0.0;         // imposta non incassati
 | ||
|       
 | ||
|       look_iva(_rmoviva->get(RMI_CODIVA));
 | ||
|       TString4 codiva     = _iva->get("CODTAB");
 | ||
|       TString4 tipoiva    = _iva->get("S1");
 | ||
|       TString8 tipoes_v   = _iva->get("S2");
 | ||
|       TString8 tipoes_a   = _iva->get("S9");
 | ||
|       const int     tipoagr    = _iva->get_int("S4");
 | ||
|       const int     tipoag     = _iva->get_int("S5");
 | ||
|       const int     tipopla    = _iva->get_int("S3");
 | ||
|       int     isrimbinfr = _iva->get_bool("B3");     // vale per calcolo rimborso se ES o NI
 | ||
|       const real perciva = _iva->get_real("R0") / CENTO;
 | ||
|       int     ivarimb    = !_iva->get_bool("B4");    // non escluso calcolo rimb. per al. media
 | ||
| 
 | ||
|       const TString8 tipocr_s   = _rmoviva->get(RMI_TIPOCR);       
 | ||
|       const int tipocr     = atoi(tipocr_s);        
 | ||
|       const bool intra      = _rmoviva->get_bool(RMI_INTRA);
 | ||
| 
 | ||
|       // autofatture art. 17 per non residenti, con trattamento
 | ||
|       // speciale in liquidazione annuale
 | ||
|       const bool autodafe = tipodoc == "AF";  //Adesso il tipocr==4 non c'entra piu' un tubo
 | ||
|       // vendite art. 40 c. 5/6/8 acq.intra., con trattamento
 | ||
|       // speciale in liquidazione annuale (VA7 in stampa)
 | ||
|       const bool art40 = (tipodoc != "AF" &&  tipoiva != "NS" && !rcs.get_bool("AUTOFATT") && rcs.get_bool("VALINTRA") && !intra);
 | ||
|       // indica acquisti per rivendita; viene messo in B4 di PIM per
 | ||
|       // indicare che e' soggetto al ricalcolo IVA (se voluto) in modo
 | ||
|       // da evitare di dover controllare mese e anno sul PIM
 | ||
|       const bool was_riv = (tipoiva != "NS") && (tipocr == 1 || tipocr ==5);
 | ||
|       real percind;
 | ||
|       const int tipoind = get_tipodet_from_rmi(_rmoviva->curr(), percind);
 | ||
| 
 | ||
|       const real imponibile_orig = _rmoviva->get_real(RMI_IMPONIBILE);
 | ||
|       const real imposta_orig    = _rmoviva->get_real(RMI_IMPOSTA);
 | ||
|       
 | ||
|       const int decimals = TCurrency::get_firm_dec();
 | ||
| 			real impon_ind, impon_det, impos_ind, impos_det; 
 | ||
| 
 | ||
| 			if (percind <= ZERO)
 | ||
| 			{
 | ||
| 				impon_det = imponibile_orig;
 | ||
| 				impos_det = imposta_orig;
 | ||
| 			}
 | ||
| 			else
 | ||
| 				if (percind >= CENTO)
 | ||
| 				{
 | ||
| 					impon_ind = imponibile_orig;
 | ||
| 					impos_ind = imposta_orig;
 | ||
| 				}
 | ||
| 				else
 | ||
| 				{
 | ||
| 					impon_ind = imponibile_orig * percind / CENTO; impon_ind.round(decimals);
 | ||
| 					impon_det = imponibile_orig - impon_ind;
 | ||
| 					impos_ind = impon_ind * perciva; impos_ind.round(decimals);
 | ||
| 					impos_det = imposta_orig - impos_ind;
 | ||
| 				}
 | ||
| 
 | ||
|       for (int is_detraibile = 0; is_detraibile < 2; is_detraibile++)
 | ||
|       {
 | ||
|         const int tipodet = is_detraibile ? 0 : tipoind;
 | ||
|         const real imponibile = is_detraibile ? impon_det : impon_ind;
 | ||
|         const real imposta    = is_detraibile ? impos_det : impos_ind;
 | ||
|         if (imponibile.is_zero() && imposta.is_zero())
 | ||
|           continue;
 | ||
|       
 | ||
|         /*
 | ||
|          * Riga imponibile > 9 = ritenute; non si
 | ||
|          * considerano (Scudler 1994)
 | ||
|          */          
 | ||
| 
 | ||
|         // Filling dell'array per IVA11
 | ||
|         if (_is_interactive && month == 13)
 | ||
|           iva11_set_arr_phase_1(trueatt);
 | ||
|       
 | ||
| 
 | ||
|         // Cumula l'ammontare delle operazioni attive/passive 
 | ||
|         // per la dichiarazione annuale fati iva
 | ||
|         if (month == 13 && !fattrit) 
 | ||
|         {
 | ||
|           const TString& iva_vpn = _iva->get(tipomov == vendita ? "S10" : "S11");
 | ||
| 
 | ||
| 				  if (tipomov == vendita)
 | ||
| 				  {
 | ||
| 					  const long codcf = _mov->get_long(MOV_CODCF);
 | ||
| 					  
 | ||
| 					  if (tipoiva.empty() && codcf != 0)
 | ||
| 					  {
 | ||
| 						  TString8 key(_mov->get(MOV_TIPO)); key << "|" << codcf;
 | ||
| 						  const TRectype & clifo = cache().get(LF_CLIFO, key);
 | ||
| 						  int codreg = 0; // codice regione x privati 22 == partite iva 0 == senza codice
 | ||
| 						  const int tipoalleg = clifo.get_int(CLI_ALLEG);
 | ||
| 
 | ||
| 						  if (tipoalleg == 6)  // privato
 | ||
| 						  {
 | ||
| 							  if (clifo.get_bool(CLI_OCCAS))
 | ||
| 							  {
 | ||
| 								  const TString80 key_occ(_mov->get(MOV_OCFPI));
 | ||
| 								  const TRectype & occas = cache().get(LF_OCCAS, key_occ);
 | ||
| 								  
 | ||
| 								  key = occas.get(OCC_STATO);
 | ||
| 								  key << "|" << occas.get(OCC_COM);
 | ||
| 							  }
 | ||
| 							  else
 | ||
| 							  {
 | ||
| 								  key = clifo.get(CLI_STATOCF);
 | ||
| 								  key << "|" << clifo.get(CLI_COMCF);
 | ||
| 							  }
 | ||
| 							  
 | ||
| 							  const TRectype & comune = cache().get(LF_COMUNI, key);
 | ||
| 
 | ||
| 							  codreg = comune.get_int(COM_CODREG) + 1;
 | ||
| 						  }
 | ||
| 						  vt_imponibile[codreg] += imponibile;
 | ||
| 						  vt_imposta[codreg] += imposta;
 | ||
| 					  }
 | ||
| 				  }
 | ||
| 
 | ||
|           if (iva_vpn.not_empty())
 | ||
|           {
 | ||
|             switch (tipomov)
 | ||
|             {
 | ||
|               case vendita: // CD1 - 1 2 3 4
 | ||
| 							  {
 | ||
| 								  if (!corrisp && tipodoc != "AF" && (cau_intra || !cau_valintra) &&
 | ||
| 										  sosp_imp != normale && sosp_imp != liquidazione)
 | ||
| 								  {
 | ||
| 									  cessioni_cd1_1 += imponibile;
 | ||
| 									  if (!cau_intra)
 | ||
| 									  {
 | ||
| 										  if (iva_vpn == "CD12")
 | ||
| 											  cessioni_cd1_2 += imponibile; else
 | ||
| 										  if (iva_vpn == "CD13")
 | ||
| 											  cessioni_cd1_3 += imponibile;
 | ||
| 									  }
 | ||
| 									  else
 | ||
| 									  {
 | ||
| 										  if (iva_vpn == "CD14")
 | ||
| 											  cessioni_cd1_4 += imponibile;
 | ||
| 									  }
 | ||
| 								  }
 | ||
| 
 | ||
| 							  }
 | ||
|               break;
 | ||
|               case acquisto: // CD2 - 1 2 3 4 
 | ||
| 							  {		
 | ||
| 								  acquisti_cd2_1 += imponibile;
 | ||
| 								  if (!cau_intra)
 | ||
| 								  {
 | ||
| 									  if (iva_vpn == "CD22")
 | ||
| 										  acquisti_cd2_2 += imponibile; else
 | ||
| 									  if (iva_vpn == "CD23")
 | ||
| 										  acquisti_cd2_3 += imponibile;
 | ||
| 								  }
 | ||
| 								  else
 | ||
| 								  {
 | ||
| 									  if (iva_vpn == "CD24")
 | ||
| 										  acquisti_cd2_4 += imponibile;
 | ||
| 								  }
 | ||
| 								  if (iva_vpn == "CD31")
 | ||
| 								  {
 | ||
| 									  oroargento_cd3_1 += imponibile;
 | ||
| 									  oroargento_cd3_2 += imposta;
 | ||
| 								  }
 | ||
| 								  if (iva_vpn == "CD33")
 | ||
| 								  {
 | ||
| 									  rottami_cd3_3 += imponibile;
 | ||
| 									  rottami_cd3_4 += imposta;
 | ||
| 								  }
 | ||
| 							  }
 | ||
|               break;
 | ||
|               default:
 | ||
|               break;
 | ||
|             }
 | ||
|           }
 | ||
|         }        
 | ||
|       
 | ||
|         if (noninc)   // non incassati: non devono entrare in nessun altro calcolo
 | ||
|         {              
 | ||
|           nin_imp = imponibile;
 | ||
|           nin_iva = imposta;
 | ||
|         }
 | ||
|         else if (sosp_imp != nessuna)    // sospensione di imposta
 | ||
|         {
 | ||
|           if (tipomov == vendita)
 | ||
|           {
 | ||
|             vsimp_imp = imponibile;
 | ||
|             vsimp_iva = imposta;
 | ||
|           }
 | ||
|           else
 | ||
|           {
 | ||
|             asimp_imp = imponibile;
 | ||
|             asimp_iva = imposta;
 | ||
|           }       
 | ||
| 
 | ||
|           switch (sosp_imp)
 | ||
|           {
 | ||
|             case normale:
 | ||
|               assp_imp += asimp_imp;
 | ||
|               assp_iva += asimp_iva;
 | ||
|               vssp_imp += vsimp_imp;
 | ||
|               vssp_iva += vsimp_iva;
 | ||
|              break;
 | ||
|             case liquidazione:
 | ||
|               assl_imp += asimp_imp;
 | ||
|               assl_iva += asimp_iva;
 | ||
|               vssl_imp += vsimp_imp;
 | ||
|               vssl_iva += vsimp_iva;
 | ||
|             default:
 | ||
|              break;
 | ||
|           }        
 | ||
|         }
 | ||
|         else if (fattrit) // Possono essere solo acquisti
 | ||
|         {
 | ||
|           rit_imp = imponibile;
 | ||
|           rit_iva = imposta;
 | ||
|         }      
 | ||
|       
 | ||
|         // Le fatture in ritardo non vanno considerate nel periodo ma solo nell'annuale
 | ||
|         if (!fattrit || (fattrit /*&& _isagricolo*/ && _month == 13))  // normale
 | ||
|         {
 | ||
|        
 | ||
|           // ***************************************** 
 | ||
|           // casi particolari
 | ||
|           // ***************************************** 
 | ||
| 
 | ||
|           // imposta acquisti intracomunitari
 | ||
|           if (tipomov == acquisto && intra) 
 | ||
|             totintra += imposta;
 | ||
| 
 | ||
|           // Altre cose di cui tener conto
 | ||
|           // Separo pazientemente per movimenti d'acquisto e movimenti di vendita
 | ||
|           // onde evitare rompicapi, rompicazzi ecc...
 | ||
| 
 | ||
|           switch (tipomov)
 | ||
|           {
 | ||
|             case acquisto: // ACQUISTO (per chi non l'avesse capito)
 | ||
|                 // Per le anguille delle Antille e le Saracche delle Molucche...
 | ||
|                 // Gli acquisti con tipocr 1,2,3,5,8 vanno totalizzati se e solo se
 | ||
|                 // il tipo iva e' diverso da NON SOGGETTO,
 | ||
|                 if (tipoiva != "NS")
 | ||
|                 {
 | ||
|                   if (tipocr == 1 || tipocr ==5)
 | ||
|                     // Acquisto beni per rivendita
 | ||
|                   {
 | ||
|                     acq_riv     += imponibile;
 | ||
|                     acq_riv_iva += imposta;
 | ||
|                   }
 | ||
|                   else if (tipocr == 2 && tipodet == 0)
 | ||
|                     // Acquisto beni ammortizzabili detraibili
 | ||
|                   {
 | ||
|                     ammort_det     += imponibile;
 | ||
|                     ammort_det_iva += imposta;
 | ||
|                   }
 | ||
|                   else if (tipocr == 2 && tipodet != 0)
 | ||
|                     // Acquisto beni ammortizzabili indetraibili
 | ||
|                   {
 | ||
|                     ammort_indet     += imponibile;
 | ||
|                     ammort_indet_iva += imposta;
 | ||
|                   }
 | ||
|                   else if (tipocr == 3) 
 | ||
|                     // Acquisto beni ammortizzabili detr. 6%
 | ||
|                   {
 | ||
|                     ammort_6     += imponibile;
 | ||
|                     ammort_6_iva += imposta;
 | ||
|                     // ult_detr     += imponibile * real(DETRAZIONE_6PERCENTO); // CM500159
 | ||
|                   }
 | ||
|                   else if (tipocr == 8) 
 | ||
|                     // Acquisto beni strum. acquisiti in leasing
 | ||
|                   {
 | ||
|                     leasing      += imponibile;
 | ||
|                     leasing_iva  += imposta;
 | ||
|                   }
 | ||
|                 } // fine if per tipo iva != da NON SOGGETTO
 | ||
|               
 | ||
|                 // Mi chiedo se effettivamente il tipo 9 sia esente da qualsiasi criterio...
 | ||
|                 if (tipocr == 9)
 | ||
|                   // Spese generali
 | ||
|                 {
 | ||
|                   spgen        += imponibile;
 | ||
|                   spgen_iva    += imposta;
 | ||
|                 }
 | ||
|                 // else fuck it up, dirty dick head.
 | ||
|               break;
 | ||
|             case vendita: // VENDITA
 | ||
|               if (tipoiva != "NS") /* Segnalazione CM000219: I non soggetti non vanno considerati */
 | ||
|               {
 | ||
|                 if (tipocr == 4) 
 | ||
|                   /*
 | ||
|                    * Vendite strum. art 17 (cess. amm.)
 | ||
|                    * Comprende anche autofatture, anche nell'annuale
 | ||
|                    * (Sergio 1995) 
 | ||
|                    */
 | ||
|                 { 
 | ||
|                    /* NO!      
 | ||
|                    * Invece non le deve comprendere nell'annuale 
 | ||
|                    * (Vladimiro 1995, piu' tardi)
 | ||
|                    */
 | ||
|                   if (!(_month == 13 && autodafe))  
 | ||
|                   {
 | ||
|                     cess_amm     += imponibile;
 | ||
|                     cess_amm_iva += imposta;   
 | ||
|                   }
 | ||
|                 }  
 | ||
|               }
 | ||
|               break;
 | ||
|             default: // Chissa'... forse in futuro vi sara' un ulteriore tipo di movimento...
 | ||
|               break;
 | ||
|           }  // Fine del malefico switch
 | ||
|         
 | ||
|                          
 | ||
|           // operazioni per calcolo rimborso infraanale
 | ||
|           // Scudler 1995 e molti dopo di lei
 | ||
|           // La breve estate vissuta dal metodo del 51% rende
 | ||
|           // oramai superflua la tabella rimborsi, eliminata
 | ||
|           // senza entusiasmo ed interrogandomi sul senso della vita
 | ||
|           if (ivarimb)
 | ||
|           { 
 | ||
|             bool ok   = _isagricolo ? tipoagr == 2 : FALSE;
 | ||
|           
 | ||
|             if (tipomov == acquisto && !ok)
 | ||
|                ok = (tipocr == 0 || tipocr == 1 || tipocr == 5 || tipocr == 9);
 | ||
| 
 | ||
|             if (tipomov == vendita && !ok)
 | ||
|               ok = tipoiva != "NS" && tipocr != 4;
 | ||
|           
 | ||
|             ivarimb = ok;
 | ||
|           }
 | ||
| 
 | ||
|           // operazioni esenti
 | ||
|           if (tipoiva == "ES")
 | ||
|           {
 | ||
|             if (tipomov == vendita)
 | ||
|             {
 | ||
|               if (sosp_imp != normale && sosp_imp != vol_affari)   // CM500308
 | ||
|               {
 | ||
|                 if (tipoes_v == "B1")      // C1
 | ||
|                   esenti_c1 += imponibile; 
 | ||
|                 else if (tipoes_v == "B2") // C2
 | ||
|                   esenti_c2 += imponibile; 
 | ||
|                 else if (tipoes_v == "B3") // C3
 | ||
|                 {
 | ||
|                   esenti_c3 += imponibile; 
 | ||
|                   if (tipocr == 4)
 | ||
|                     esenti_c3_bam += imponibile;
 | ||
|                 }
 | ||
|                 else if (tipoes_v == "B4") // C1A
 | ||
|                 {
 | ||
|                   esenti_c1a += imponibile; 
 | ||
|                   if (tipocr == 4)
 | ||
|                     esenti_c1a_bam += imponibile;
 | ||
|                 }
 | ||
|                 // se e' il caso sommare esenti per rimborso 
 | ||
|                 if (isrimbinfr)
 | ||
|                   esni_rimb += imponibile;
 | ||
|               }
 | ||
|             }
 | ||
|             else if (tipoes_a == "14")
 | ||
|               esenti_b14 += imponibile;
 | ||
|           }
 | ||
|         
 | ||
|           // non imponibili per rimborso
 | ||
|           if (tipoiva == "NI" && tipomov == vendita && isrimbinfr)
 | ||
|              esni_rimb += imponibile;
 | ||
|         
 | ||
|           // bolle doganali
 | ||
|           if (tipodoc == "BD")
 | ||
|           {
 | ||
|             bolld_imp = imponibile;
 | ||
|             bolld_iva = imposta; 
 | ||
|           
 | ||
|             bdog_imp += bolld_imp;
 | ||
|             bdog_iva += bolld_iva;
 | ||
|           }                       
 | ||
|                                
 | ||
|           // plafond
 | ||
|           if (_isplafond && tipomov == acquisto && month != 13 && 
 | ||
|               tipoiva == "NI" && tipopla != 0)
 | ||
|           { 
 | ||
|             add_plafond(month, codatt, tipopla, imponibile, tipodoc == "BD");
 | ||
|           }
 | ||
| 
 | ||
|           // agenzie viaggio (CHECK imponibili etc.)
 | ||
|           if (_isviaggio)
 | ||
|             switch (tipoag)
 | ||
|             {
 | ||
|             case 1: 
 | ||
|               if (tipomov == acquisto) acq_CEE  += imponibile + imposta;
 | ||
|               else                     corr_CEE += imponibile + imposta;
 | ||
|               break;
 | ||
|             case 2:
 | ||
|               if (tipomov == acquisto) acq_noCEE  += imponibile + imposta;
 | ||
|               else                     corr_noCEE += imponibile + imposta;
 | ||
|               break;
 | ||
|             case 3: if (tipomov == vendita)
 | ||
|                       corr_misCEE  += imponibile + imposta;
 | ||
|                     break;
 | ||
|             case 4: if (tipomov == acquisto)
 | ||
|                       acq_misCEE   += imponibile + imposta; 
 | ||
|                     break;
 | ||
|             case 5: if (tipomov == acquisto)
 | ||
|                       acq_misnoCEE += imponibile + imposta; 
 | ||
|                     break;
 | ||
|             }
 | ||
|       
 | ||
| 
 | ||
|           if (_isagricolo) 
 | ||
|           {
 | ||
|             /*
 | ||
|              * rifatto sensu Scudler 1995 con invidiabile sicurezza
 | ||
|              * senza porsi domande e mettendo NUMERI uguali
 | ||
|              * al TIPO RECORD del frigorifero     
 | ||
|              */
 | ||
|             if (tipomov == vendita)
 | ||
|             {
 | ||
|               if (!noninc) // Salta i non incassati
 | ||
|               {
 | ||
|                 agr_imp = imponibile;
 | ||
|                 agr_iva = imposta;
 | ||
|                 const real p = perciva;
 | ||
|                 const bool is_not_fs = tipodoc != "FS";
 | ||
|               
 | ||
|                 // Se si tratta di Fattura Fiscale o Fattura Scontrino, non scorpora
 | ||
|                 // In particolare le FS non vengono incluse ne' nello specchietto ne' nel totale
 | ||
|                 if (corrisp && tipodoc != "FF" && is_not_fs)
 | ||
|                   lordo2netto(agr_imp,agr_iva,p);
 | ||
|               
 | ||
|                 if (tipoagr == 1 && is_not_fs) // Ora si utilizza solo il segnalino 1
 | ||
|                 { 
 | ||
|                   agr_1  += agr_iva;       
 | ||
|                   agr_1i += agr_imp;
 | ||
|   
 | ||
|                   // Nuovo regime agricolo dal 1998: si sommino per codice iva di compensazione (da reperire su PCON)
 | ||
|                   if (_isagr98)
 | ||
|                   {
 | ||
|                     TString ivacomp("00"); // Se non esiste o non si trova il conto questo e' il default (fa un poco schifo ma e' cosi')
 | ||
|                   
 | ||
|                     if (_cur->is_first_match(-AGR_PCON1)) // Esiste il conto ? 
 | ||
|                       // Bien, allora controlliamo se e' un ricavo...
 | ||
|                       if (_pcon_1_r->get_int(PCN_INDBIL) == 4)
 | ||
|                         if (_cur->is_first_match(-AGR_PCON2)) // Esiste il sottoconto ?
 | ||
|                         {
 | ||
|                           if (look_iva(_pcon_2_r->get(PCN_IVACOMP)))
 | ||
|                             ivacomp = _iva->get("CODTAB");  // Ecco il codice IVA di compensazione
 | ||
|                         }
 | ||
|                     look_pia(month, codatt, codiva, ivacomp, TRUE); // Crea il record in tabella se non esiste
 | ||
|                     real pia_imp = _pia->get_real("R0") + agr_imp; // Aggiorna...
 | ||
|                     _pia->put("R0", pia_imp);
 | ||
|                     _pia->put("B0", TRUE); // Seguo l'esempio dei PIM per il ricalcolo acquisti alla fine del ciclo
 | ||
|                     _pia->rewrite(); // infine scrive
 | ||
|                   }
 | ||
|                 }
 | ||
|                 else if (tipoagr == 2 && is_not_fs)
 | ||
|                 {
 | ||
|                   agr_2  += agr_iva;
 | ||
|                   agr_2i += agr_imp;
 | ||
|                 }
 | ||
|               }
 | ||
|             }
 | ||
|             else if (tipodet == 0)
 | ||
|             {
 | ||
|               if (tipoagr == 2)
 | ||
|               {
 | ||
|                 if (tipocr != 2 && tipocr != 3 && tipocr != 8)
 | ||
|                   agr_3 += imposta;  
 | ||
|                 else
 | ||
|                   agr_4 += imposta;
 | ||
|               }
 | ||
|               else if (tipoagr == 3)
 | ||
|               {    
 | ||
|                 if (tipocr != 2 && tipocr != 3 && tipocr != 8)
 | ||
|                   agr_7 += imposta;  
 | ||
|               }
 | ||
|               else   // ne' 2 ne' 3
 | ||
|               {
 | ||
|                 if (tipocr != 2 && tipocr != 3 && tipocr != 8)
 | ||
|                   agr_5 += imposta;
 | ||
|                 else
 | ||
|                   agr_6 += imposta;
 | ||
|               }            
 | ||
|             }
 | ||
|           } // __end of _agricolo
 | ||
| 
 | ||
|           if (tipodet == 1)    // acquisti indeducibili su ricavi esenti art. 10 
 | ||
|           {                                                       
 | ||
|             acq_ies     += imponibile;
 | ||
|             acq_ies_iva += imposta;
 | ||
|           }
 | ||
|       
 | ||
|           if (tipodet == 3)  // passaggi interni (solo per ventilaz)
 | ||
|           {  
 | ||
|             acq_pint     += imponibile;
 | ||
|             acq_pint_iva += imposta;
 | ||
|           }
 | ||
| 
 | ||
|           // acquisti non detraibili art. 19
 | ||
|           // possono valere per la ventilazione
 | ||
|           if (tipodet == 9)
 | ||
|           {
 | ||
|             nond19_imp += imponibile;
 | ||
|             nond19_iva += imposta;
 | ||
|           }
 | ||
|       
 | ||
|           // ***************************************** 
 | ||
|           // Fine casi particolari
 | ||
|           // Non che i casi normali siano tanto meglio
 | ||
|           // *****************************************
 | ||
|         } // non sosp_imp ne' altre casistiche che escludono la liq.
 | ||
| 
 | ||
|         /* 
 | ||
|          * se ign == TRUE non bisogna neppure PROGRESSIVARLI
 | ||
|          */
 | ||
|         const bool sosp_vaf = sosp_imp == vol_affari;
 | ||
|         const bool sosp_liq = sosp_imp == liquidazione;
 | ||
|         bool ign = sosp_imp == normale || (fattrit && month != 13) || noninc;
 | ||
| 
 | ||
|         /*
 | ||
|          * se liq == FALSE gli importi non contano ai fini
 | ||
|          * del calcolo liquidazione  
 | ||
|          */                                        
 | ||
|         bool liq = !(tipodet == 1 || tipodet == 3 || tipodet == 9 || ign || sosp_vaf);
 | ||
|       
 | ||
|         real imp;    // imponibile
 | ||
|         real ivp;    // IVA su imp.
 | ||
|         real lor;    // lordo  
 | ||
|         real lorcor; // lordo corrispettivi (da non ventilare)
 | ||
| 
 | ||
|         /*
 | ||
|          * le maledette fatture con scontrino sono sul registro dei
 | ||
|          * corrispettivi, ma vanno riportate nelle vendite in stampa;
 | ||
|          * dunque, le sommiamo in R5 e R6 di PIM anche se continuiamo
 | ||
|          * a sommarle anche in R0 e R1. La stampa (describe_pim)
 | ||
|          * dovra' scorporarle. 
 | ||
|          * 
 | ||
|          * 5.7.1996. Mi permetto di aggiungere una cosa: le bastardissime fatture con scontrino
 | ||
|          *           possono anche essere sul registro vendite. Indi le schiaffo dentro
 | ||
|          *           a R5 e R6 anche nel caso vi sia un documento FS registrato sul registro
 | ||
|          *           delle vendite. Nel caso in futuro si accorgessero finalmente della puttanata
 | ||
|          *           galattica che mi hanno fatto fare basta eliminare il controllo su FS 
 | ||
|          *           nel caso si tratti di non corrispettivi (vedi sotto). 
 | ||
|          *           Da togliere anche nella :describe_pim() in cg4304.cpp.
 | ||
|          *           
 | ||
|          */
 | ||
|         real ifs; // imponibile fatture con scontrino
 | ||
|         real vfs; // IVA fatt. con scontrino
 | ||
| 
 | ||
|         /*
 | ||
|          * le maledette autofatture non residenti art. 17
 | ||
|          * vedi al calcolo if (autodafe) si tengono da parte 
 | ||
|          * La stampa le scorpora solo IN SEDE di dichiarazione annuale
 | ||
|          */
 | ||
|         real adf;
 | ||
|         real adi;
 | ||
|                       
 | ||
|         /* le fottute fatture in sospensione di imposta */
 | ||
|         real fsi;
 | ||
|         real fsv;
 | ||
|       
 | ||
|         /* le putride bolle doganali */
 | ||
|         real bdi;
 | ||
|         real bdv;
 | ||
|       
 | ||
|         /* i luridi falsi corrispettivi */
 | ||
|         real fci;
 | ||
|         real fcv;
 | ||
|       
 | ||
|         /* i conturbanti art. 40 c. 5/6/8 a.i. */
 | ||
|         real va7i;
 | ||
|         real va7v;
 | ||
| 
 | ||
|         /* le porche fatture in ritardo */
 | ||
|         real rti;
 | ||
|         real rtv;
 | ||
|       
 | ||
|         /* 
 | ||
|          * la stramadonna dei corrispettivi gia' scorporati 
 | ||
|          * Gli si aggiungono i non incassati, sperando in bene
 | ||
|          */
 | ||
|         real csi;
 | ||
|         real csv;
 | ||
|         /* incrociamm'e dituozz' */
 | ||
|         csi += nin_imp;                
 | ||
|         csv += nin_iva;                
 | ||
|                       
 | ||
|         rti   += rit_imp;
 | ||
|         rtv   += rit_iva;
 | ||
|       
 | ||
|         if (tipomov == vendita)
 | ||
|         {
 | ||
|           fsi += vsimp_imp;
 | ||
|           fsv += vsimp_iva;
 | ||
|         }
 | ||
|         else
 | ||
|         { 
 | ||
|           fsi += asimp_imp;
 | ||
|           fsv += asimp_iva;
 | ||
|           bdi += bolld_imp;
 | ||
|           bdv += bolld_iva;
 | ||
|         }
 | ||
| 
 | ||
|         if (liq && tipomov == vendita && !corrisp) 
 | ||
|         // i corrispettivi sono gestiti a parte
 | ||
|         {
 | ||
|           // totale vendite
 | ||
|           vendite     += imponibile;
 | ||
|           vendite_iva += imposta;
 | ||
|         }
 | ||
|         else if ((liq || fattrit && month == 13) && tipomov == acquisto)
 | ||
|         {
 | ||
|           // totale acquisti
 | ||
|           acquisti     += imponibile;
 | ||
|           acquisti_iva += imposta;
 | ||
| 
 | ||
|           const int yr  = datedoc.year();
 | ||
|         
 | ||
|           if (year_int > 1997 && (yr < (year_int-1) && yr > (year_int-4))) // Prende un intervallo di 2 anni al massimo
 | ||
|           {                                                               // Quelli relativi all'anno in corso e precedente vanno assieme.
 | ||
|             // Se abilitato, somma l'iva acquisti relativi ai documenti memorizzati con anni precedenti
 | ||
|             TString16 yy;
 | ||
|             yy << datedoc.year();
 | ||
|             const bool is_key = acq_iva_anni_prec.is_key(yy);
 | ||
|             if (!is_key)
 | ||
|               acq_iva_anni_prec.add(yy, new real, is_key);
 | ||
|             real& aip = (real&) acq_iva_anni_prec[yy];          
 | ||
|             aip += imposta;
 | ||
|           }
 | ||
|         }
 | ||
|      
 | ||
|         // corrispettivi  
 | ||
|         bool true_corrisp = FALSE;             
 | ||
|         if (corrisp)
 | ||
|         {
 | ||
|           /*
 | ||
|            * ennesimo casino: non tutti i corrispettivi sono
 | ||
|            * corrispettivi; in effetti, alcuni corrispettivi
 | ||
|            * non sono corrispettivi. Ci si potrebbe domandare
 | ||
|            * se gli altri corrispettivi sono corrispettivi o
 | ||
|            * no; ebbene, gli altri corrispettivi risultano
 | ||
|            * fortunatamente essere corrispettivi, a meno di
 | ||
|            * indicazioni contrarie.
 | ||
|            */
 | ||
|           if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC")
 | ||
|           {                      
 | ||
|             true_corrisp = TRUE;
 | ||
|             _pim->put("I0",LORDO);
 | ||
|             // questi sono corrispettivi davvero; comportamento normale 
 | ||
|             if (tipoiva == "VE")   // da ventilare
 | ||
|             {
 | ||
|               lor += imponibile;
 | ||
|               add_vendite(month, reg, tipodet, imponibile);
 | ||
|             }                    
 | ||
|             else // non da ventilare, con imposta gia' conteggiata
 | ||
|             {
 | ||
|               lor += imponibile + imposta;   
 | ||
|               lorcor += imponibile+imposta;
 | ||
|               real tot = imponibile+imposta;   
 | ||
|               if (liq) add_corrisp(month, reg, tot, perciva, tipodet, codiva, codatt);
 | ||
|             }
 | ||
|           } 
 | ||
|           else if (tipodoc == "FF")   // CM500415: prima non c'era questo if
 | ||
|           {
 | ||
|             // queste sono fatture fiscali
 | ||
|             true_corrisp = TRUE; 
 | ||
|  
 | ||
|             real tot = imponibile + imposta;   
 | ||
|             lor += tot;   
 | ||
|             lorcor += tot;
 | ||
|             if (liq) 
 | ||
|               add_corrisp(month, reg, tot, perciva, tipodet, codiva, codatt);
 | ||
|           }
 | ||
|           else if (tipodoc == "FS")
 | ||
|           {
 | ||
|             // queste sono fatture che seguono scontrino, il lordo va detratto
 | ||
|             // perche' si e' gia' registrato lo scontrino medesimo   
 | ||
|             true_corrisp = TRUE; // non e' vero ma non devono essere sommate ai falsi
 | ||
|                                  // corrispettivi
 | ||
|             if (tipoiva == "VE")
 | ||
|             {
 | ||
|               real rr  = imponibile + imposta; 
 | ||
|               imp     += rr;
 | ||
|               if (liq)
 | ||
|                 vendite += rr;
 | ||
|               add_vendite(month, reg, tipodet, rr); 
 | ||
|             } 
 | ||
|             if (liq)
 | ||
|             {
 | ||
|               csi += imponibile;
 | ||
|               csv += imposta;
 | ||
|             }
 | ||
|             imp -= imponibile;
 | ||
|             ivp -= imposta;
 | ||
|             lor -= imponibile + imposta;
 | ||
|             ifs += imponibile;
 | ||
|             vfs += imposta; 
 | ||
|           }
 | ||
|           else  // vendite normali a tutti gli effetti
 | ||
|           {     
 | ||
|             if (liq)
 | ||
|             {
 | ||
|               vendite     += imponibile;
 | ||
|               vendite_iva += imposta;
 | ||
|               csi += imponibile;
 | ||
|               csv += imposta;
 | ||
|             }
 | ||
|             imp += imponibile;
 | ||
|             ivp += imposta;
 | ||
|             _pim->put("I0",NETTO);
 | ||
|           }
 | ||
|         }  // if corrisp
 | ||
|         else // non corrisp
 | ||
|         {       // imponibile e imposta separata
 | ||
|           imp += imponibile;
 | ||
|           ivp += imposta; 
 | ||
|           if (tipodoc == "FS") // Questo e' per l'errore MI3404
 | ||
|           {
 | ||
|             ifs += imponibile; 
 | ||
|             vfs += imposta;    
 | ||
|           }
 | ||
|           _pim->put("I0",NETTO);
 | ||
|         }
 | ||
|       
 | ||
|         // Rettifica il valore da memorizzare in PAM->R1, utilizzato nel calcolo Vol.Affari      
 | ||
|         // Solo nel caso in cui l'importo corrente deve far parte di tale calcolo
 | ||
|         // Se e' valido per calcolo solo vol.aff aggiunge gli importi non aggiunti a causa del !liq
 | ||
|         // Se e' valido per calcolo solo liq. sottrae gli importi aggiunti a causa del liq.
 | ||
|         // Nel caso di sosp. normale non viene ne progressivato ne liquidato e ne considerato per vol. aff.
 | ||
|         if (sosp_vaf || sosp_liq)
 | ||
|         {
 | ||
|           real iii    = imponibile;
 | ||
|           real iiimmm = imponibile + imposta;
 | ||
| 
 | ||
|           if (sosp_liq)
 | ||
|           {
 | ||
|             iii    *= -1;
 | ||
|             iiimmm *= -1;
 | ||
|           }
 | ||
|         
 | ||
|           if (corrisp)
 | ||
|             if (tipodoc == "FS")
 | ||
|             {
 | ||
|              if  (tipoiva == "VE")
 | ||
|                vendite +=  iiimmm;
 | ||
|             }
 | ||
|             else
 | ||
|               vendite += iii;
 | ||
|           else
 | ||
|             if (tipomov == vendita)
 | ||
|               vendite += iii;
 | ||
|         } 
 | ||
|       
 | ||
|         if (autodafe)  // autofatture non residenti art, 17
 | ||
|         {                    
 | ||
|           /*
 | ||
|            * Si devono riportare a parte in annuale
 | ||
|            * e non comparire nel riepilogo del codice IVA 
 | ||
|            * corrispondente, solo se la liq. e' annuale
 | ||
|            * Li metto in R7/R8 di pim e li sommo anche nelle
 | ||
|            * vendite; la describe_pim() dovra' sommarli su tutti i 
 | ||
|            * pim, scorporarli dalle rispettive vendite 
 | ||
|            * e assegnarli al codice IVA AF in caso di liq. annuale
 | ||
|            */
 | ||
|           adf += imponibile;
 | ||
|           adi += imposta;       
 | ||
|         }
 | ||
|         
 | ||
|         if (art40)  // ammontare acq. intr. art40 c. 5/6/8
 | ||
|         {           // Analogamente alle autofatture, si devono riportare a parte in annuale
 | ||
|                     // Vengono piazzati in una TToken_string con separatore = a '!'.
 | ||
|                     // La TToken_string viene registrata in S0.
 | ||
|                     // La describe_pim() sommera' tutte le storie, scorporandoli
 | ||
|                     // dalle vendite e assegnandoli al codice VA7 in caso di liq annuale.
 | ||
|           va7i += imponibile;
 | ||
|           va7v += imposta;       
 | ||
|         }
 | ||
|         
 | ||
|         if (corrisp && !true_corrisp)
 | ||
|         {
 | ||
|           fci += imponibile; 
 | ||
|           fcv += imposta;
 | ||
|         } 
 | ||
| 
 | ||
|         /*
 | ||
|          * Calcolo e aggiornamento
 | ||
|          * cerca o crea progressivo IVA.
 | ||
|          * Onde evitare ripetizioni di codice adotto il metodo sottoindicato,
 | ||
|          * come nell'azzeramento di zero_att().
 | ||
|          */
 | ||
|         int start = 0, stop = 1;
 | ||
|         if (_recalc_regis) // ricalcolo solo per registri.
 | ||
|         {
 | ||
|           start = 2;
 | ||
|           stop  = 3;
 | ||
|         }
 | ||
|         else
 | ||
|           if (year_int < 1998)
 | ||
|             stop = 0; // Solo PIM 
 | ||
|           
 | ||
|         for (int i=start; i<=stop; i++) // Ciclo per le tabelle
 | ||
|         { 
 | ||
|           if (i == 1 || i == 3) //Is it a valid PIS/PRP (vedi anche sel. cursore & date_ok())?
 | ||
|            if ((liqmonth == 0 && month < 13) || (month == 13 && liqmonth  != 12)) 
 | ||
|              continue;
 | ||
| 
 | ||
|           switch (i)
 | ||
|           {
 | ||
|             case 1: // Progressivi Iva mensili da periodo Successivo
 | ||
|               look_pis(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE);
 | ||
|               break;
 | ||
|             case 2: // Progressivi Registri iva Mensili
 | ||
|               look_prm(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE);
 | ||
|               break;
 | ||
|             case 3: // Progressivi Registri iva Mensili da periodo Precedente
 | ||
|               look_prp(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE);
 | ||
|               break;
 | ||
|             default: // Progressivi Iva Mensili normali
 | ||
|               look_pim(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE);
 | ||
|               break;
 | ||
|           }
 | ||
|         
 | ||
|           TTable *tab = arr[i];
 | ||
|       
 | ||
|           if (!ign) 
 | ||
|           {
 | ||
|             tab->put("R0",  tab->get_real("R0")  + imp);
 | ||
|             tab->put("R1",  tab->get_real("R1")  + ivp);
 | ||
|             tab->put("R2",  tab->get_real("R2")  + lor);   
 | ||
|             tab->put("R3",  tab->get_real("R3")  + lorcor);   // Corrispettivi, non inclusi quelli da ventilare
 | ||
|             tab->put("R5",  tab->get_real("R5")  + ifs);   
 | ||
|             tab->put("R6",  tab->get_real("R6")  + vfs);   
 | ||
|             tab->put("R7",  tab->get_real("R7")  + adf);   
 | ||
|             tab->put("R8",  tab->get_real("R8")  + adi);  
 | ||
|             tab->put("R9",  tab->get_real("R9")  + bdi);         
 | ||
|             tab->put("R10", tab->get_real("R10") + bdv);         
 | ||
|             tab->put("R13", tab->get_real("R13") + fci);         
 | ||
|             tab->put("R14", tab->get_real("R14") + fcv);       
 | ||
|           } 
 | ||
|                            
 | ||
|           // questi servono per i ricalcoli altrui (classify_pim) o 
 | ||
|           // per trucchetti di ricalcolo successivi
 | ||
|           tab->put("R11",tab->get_real("R11")+fsi);         
 | ||
|           tab->put("R12",tab->get_real("R12")+fsv);         
 | ||
|           tab->put("I1", (long)tipomov);  
 | ||
|           tab->put("B3", ivarimb ?   "X" : "");  
 | ||
|           tab->put("B4", (_isricacq && was_riv) ? "X" : "");  
 | ||
|           tab->put("S5", tipoiva);              
 | ||
|       
 | ||
|           // art 40 c. 5/6/8 per VA7.
 | ||
|           real r,v;
 | ||
|           TToken_string kr(tab->get("S0"),'!'); 
 | ||
|           r = real(kr.get(0)) + va7i;
 | ||
|           v = real(kr.get(1)) + va7v;
 | ||
|           kr.add(r.string(), 0);
 | ||
|           kr.add(v.string(), 1);
 | ||
|           tab->put("S0",kr);
 | ||
|                            
 | ||
|           // fatture in ritardo                     
 | ||
|           TToken_string fr(tab->get("S1"),'!'); 
 | ||
|           r = real(fr.get(0)) + rti;
 | ||
|           v = real(fr.get(1)) + rtv;
 | ||
|           fr.add(r.string(), 0);
 | ||
|           fr.add(v.string(), 1);
 | ||
|           tab->put("S1",fr);
 | ||
|       
 | ||
|           // corrispettivi gia' scorporati; anche questi servono per
 | ||
|           // non cannare la stampa dei registri; contengono anche
 | ||
|           // tutti i non incassati (vedi definizione di bool nonimp)
 | ||
|           TToken_string cs(tab->get("S2"),'!'); 
 | ||
|           r = real(cs.get(0)) + csi;
 | ||
|           v = real(cs.get(1)) + csv;
 | ||
|           cs.add(r.string(), 0);
 | ||
|           cs.add(v.string(), 1);
 | ||
|           tab->put("S2",cs);
 | ||
|         
 | ||
|           tab->rewrite(); // rewrite current table 
 | ||
|         } // for per tabelle
 | ||
|       } // for is_detraibile
 | ||
|     } while (_cur->next_match(LF_RMOVIVA));
 | ||
|   } // fine calcolo progressivi IVA 
 | ||
|   
 | ||
|   
 | ||
|   if (!_recalc_regis)
 | ||
|   {  
 | ||
|     /*  
 | ||
|      * calcolati tutti i movimenti e aggiornati i pim
 | ||
|      * se necessario risistema le imposte acquisti beni
 | ||
|      * per rivendita   
 | ||
|      */
 | ||
|      
 | ||
|     if (_isricacq)  // flag settato parametri studio
 | ||
|     {
 | ||
|       for (_pim->first(); !_pim->eof(); _pim->next())
 | ||
|       {
 | ||
|         // this is much furber than doing all of the checks
 | ||
|         if (_pim->get_bool("B4"))
 | ||
|         {
 | ||
|           // ricalcola l'imposta a partire dal codice IVA
 | ||
|           look_iva(*_pim_codiva);   
 | ||
|           real old_iva = _pim->get_real("R1");
 | ||
|           real perc    = _iva->get_real("R0");
 | ||
|           
 | ||
|           real new_iva = (_pim->get_real("R0") * perc)/CENTO; 
 | ||
|           round_alla_lira(new_iva, TRUE);
 | ||
|           
 | ||
|           if (new_iva != old_iva)
 | ||
|           {
 | ||
|              // ricalcola: acquisti_iva, acq_riv_iva   
 | ||
|              acquisti_iva -= old_iva;
 | ||
|              acquisti_iva += new_iva;
 | ||
|              acq_riv_iva  -= old_iva;
 | ||
|              acq_riv_iva  += new_iva;
 | ||
|              _pim->put("R1", new_iva);  
 | ||
|              // resetta in modo da non vederlo il mese dopo 
 | ||
|              _pim->put("B4", "");
 | ||
|              _pim->rewrite();
 | ||
|           }
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     
 | ||
|     
 | ||
|     // Ricalcola le imposte per regime agricolo dal 1998 (PIA)
 | ||
|     if (_isagr98)
 | ||
|     {
 | ||
|       for (_pia->first(); !_pia->eof(); _pia->next())
 | ||
|       {
 | ||
|         if (_pia->get_bool("B0"))
 | ||
|         {
 | ||
|           // calcola l'imposta a partire dal codice IVA di compensazione
 | ||
|           look_iva(*_pia_codcom);   
 | ||
|           real perc = _iva->get_real("R0");
 | ||
|           
 | ||
|           real iva = (_pia->get_real("R0") * perc)/CENTO; 
 | ||
|           round_alla_lira(iva, TRUE);
 | ||
|           agr_detIA += iva;
 | ||
|           _pia->put("R1",iva);
 | ||
|           // resetta in modo da non vederlo il mese dopo 
 | ||
|           _pia->put("B0", "");
 | ||
|           _pia->rewrite();
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     
 | ||
|     /* 
 | ||
|      * calcola il lercio prorata  
 | ||
|      * solo se liq. periodica
 | ||
|      */
 | ||
|     real prorata, prorata_precedente1, prorata_precedente2; 
 | ||
|     real percentuale1, percentuale2;
 | ||
|     if (month != 13)
 | ||
|     {
 | ||
|       TString4 yy;
 | ||
|       // Prorata per documenti registrati con anno doc 2 anni fa...
 | ||
|       yy.format("%d", year_int - 2);
 | ||
|       real* rr1 = (real*)acq_iva_anni_prec.objptr(yy);
 | ||
|       yy.format("%d", year_int - 1); // Reperire la % prorata dell'anno successivo a quello del documento
 | ||
|       percentuale1 = _prorata.percentuale(yy);
 | ||
|       prorata_precedente1 =  rr1 ? _prorata.calc_prorata(*rr1, yy) : ZERO;
 | ||
|       // Se sono presenti documenti di anni precedenti senza % prorata, si deve segnalare l'incongruenza (solo in prova)
 | ||
|       if (percentuale1 == INVALID_PRORATA && rr1 && *rr1 != ZERO)
 | ||
|         percentuale1 = INVALID_PRORATA_ASSERT;
 | ||
|       
 | ||
|       // Prorata per documenti registrati con anno doc 3 anni fa...
 | ||
|       yy.format("%d", year_int - 3);
 | ||
|       real *rr2 = (real*)acq_iva_anni_prec.objptr(yy);
 | ||
|       yy.format("%d", year_int - 2); // Reperire la % prorata dell'anno successivo a quello del documento
 | ||
|       percentuale2 = _prorata.percentuale(yy);
 | ||
|       prorata_precedente2 =  rr2 ? _prorata.calc_prorata(*rr2, yy) : ZERO;
 | ||
|       // Se sono presenti documenti di anni precedenti senza % prorata, si deve segnalare l'incongruenza (solo in prova)      
 | ||
|       if (percentuale2 == INVALID_PRORATA && rr2 && *rr2 != ZERO)
 | ||
|         percentuale2 = INVALID_PRORATA_ASSERT;
 | ||
| 
 | ||
|       // Prorata per l'anno corrente + quelli eventuali dello scorso anno e quelli che sono oltre 3 anni fa...
 | ||
|       // E quelli che non hanno la % prorata settata in tabella
 | ||
|       real aaa = acquisti_iva;
 | ||
|       if (percentuale1 != INVALID_PRORATA && percentuale1 != INVALID_PRORATA_ASSERT)
 | ||
|         aaa  -= rr1 ? *rr1 : ZERO;
 | ||
|       if (percentuale2 != INVALID_PRORATA && percentuale2 != INVALID_PRORATA_ASSERT)
 | ||
|         aaa  -= rr2 ? *rr2 : ZERO;
 | ||
|       prorata = _prorata.calc_prorata(aaa, _year);
 | ||
|       
 | ||
|       // Somma i vari prorata calcolati per gli anni precedenti
 | ||
|       prorata += prorata_precedente1 + prorata_precedente2;
 | ||
|       
 | ||
|       acquisti_iva -= prorata; // Rettifica acquisti_iva
 | ||
|     }
 | ||
|     look_plm(month, codatt, TRUE);   
 | ||
|     
 | ||
|     /*
 | ||
|      * ACHTUNG: l'iva sulle vendite e' calcolata sommando anche i 
 | ||
|      * corrispettivi che sono corrispettivi, a differenza dei corrispettivi
 | ||
|      * che non sono corrispettivi, ma tanto quelli (come si sa) non sono
 | ||
|      * corrispettivi. Dunque, non si tiene conto delle imposte calcolate
 | ||
|      * con la ventilazione (che vanno sottratte) ne' di quelle 
 | ||
|      * calcolate per le agenzie di viaggio (che sembra non vadano
 | ||
|      * comunque sottratte nel calcolo del volume di affari)
 | ||
|      */
 | ||
|     
 | ||
|     /*
 | ||
|      * Il prorata pagato in annuale viene scritto a 0, perche' in realta' sarebbe
 | ||
|      * la somma di quelli pagati nei mesi precedenti.
 | ||
|      */
 | ||
|     _plm->put("R2", prorata);             // Prorata complessivo (acq. rif. anno attuale + acq. rif. anni precedenti)
 | ||
|     _plm->put("R14", prorata_precedente1); // Prorata acq. rif. anno addietro
 | ||
|     _plm->put("R15", prorata_precedente2); // Prorata acq. rif. 2 anni addietro
 | ||
|   
 | ||
|     if (_isviaggio)
 | ||
|     {  
 | ||
|       _plm->put("R5", corr_CEE);
 | ||
|       _plm->put("R6", corr_noCEE);
 | ||
|       _plm->put("R7", acq_CEE);
 | ||
|       _plm->put("R8", acq_noCEE);
 | ||
|       _plm->put("R9", corr_misCEE);
 | ||
|       _plm->put("R10",acq_misCEE);
 | ||
|       _plm->put("R11",acq_misnoCEE);       
 | ||
|       
 | ||
|       // ---- NOTA BENE ------------------------
 | ||
|       // l'iva vendite nei plm non comprende 
 | ||
|       // l'iva agenzie di viaggio, calcolata
 | ||
|       // in liquidazione (mensile o trimestrale): recalc_viaggio()
 | ||
|     }
 | ||
|     else if (_isagricolo)
 | ||
|     {                                
 | ||
|       _plm->put("R5",  agr_1);
 | ||
|       _plm->put("R6",  agr_2);
 | ||
|       _plm->put("R7",  agr_3);
 | ||
|       _plm->put("R8",  agr_4);
 | ||
|       _plm->put("R9",  agr_5);
 | ||
|       _plm->put("R10", agr_6);
 | ||
|       _plm->put("R11", agr_7); 
 | ||
|       _pum->put("R10", agr_1i);
 | ||
|       _pum->put("R11", agr_2i);
 | ||
|       
 | ||
|       // Il porco agricoltore spende poco e paga meno
 | ||
|       vendite_iva  = agr_2;   
 | ||
|       acquisti_iva = agr_1 + agr_3;
 | ||
|   
 | ||
|       // nuovo calcolo IVA detraibile 
 | ||
|       if (!agr_7.is_zero())
 | ||
|       {         
 | ||
|         real pdetr = (agr_2i / (agr_1i + agr_2i));  
 | ||
|         pdetr.round(2);
 | ||
|         acquisti_iva += agr_7 * pdetr;
 | ||
|         round_alla_lira(acquisti_iva, true);
 | ||
|       }
 | ||
|       
 | ||
|       if (_isagr98)
 | ||
|       {
 | ||
|         _plm->put("R13", agr_detIA); 
 | ||
|         acquisti_iva += agr_detIA;
 | ||
|       }
 | ||
|     }
 | ||
|      
 | ||
|     _plm->put("R12", _prorata.percentuale(_year));  // per comodita' in stampa
 | ||
|     _plm->put("R4",  percentuale1);
 | ||
|     _plm->put("R16", percentuale2);
 | ||
|     _plm->put("R0",  vendite_iva);
 | ||
|     _plm->put("R1",  acquisti_iva);
 | ||
|     _plm->put("R3",  ult_detr);
 | ||
|     _plm->put("B0",  "X");       // calcolato (invalidato dalla primanota)
 | ||
|     // Setta il flag di stampa errore: se siamo oltre 1997 e non esiste tabella anno prec e vi sono docs con tale riferimento
 | ||
|     _pom->put("R9",  acq_ies);
 | ||
|     _pom->put("R10", acq_ies_iva);  
 | ||
|     _pum->put("R8",  acq_pint);
 | ||
|     _pum->put("R9",  acq_pint_iva); 
 | ||
|     _pam->put("R10", spgen);
 | ||
|     _pam->put("R11", spgen_iva); 
 | ||
|     _pom->put("R0",  totintra);  
 | ||
|     _pom->put("R1",  nond19_imp);  
 | ||
|     _pom->put("R2",  nond19_iva);  
 | ||
|     _pom->put("R3",  ammort_det);  
 | ||
|     _pom->put("R4",  ammort_det_iva);  
 | ||
|     _pom->put("R5",  acq_riv);  
 | ||
|     _pom->put("R6",  acq_riv_iva);  
 | ||
|     _pom->put("R7",  leasing);  
 | ||
|     _pom->put("R8",  leasing_iva);  
 | ||
|     _pom->put("R11", ammort_indet);  
 | ||
|     _pom->put("R12", ammort_indet_iva);  
 | ||
|     _pum->put("R0",  cess_amm);  
 | ||
|     _pum->put("R1",  cess_amm_iva);  
 | ||
|     _pum->put("R2",  ammort_6);  
 | ||
|     _pum->put("R3",  ammort_6_iva);
 | ||
|     _pum->put("R4",  esenti_c1);
 | ||
|     _pum->put("R5",  esenti_c2);
 | ||
|     _pum->put("R6",  esenti_c3);
 | ||
|     _pum->put("R13", esenti_c1a);
 | ||
|     _pum->put("S4",  esenti_c3_bam);
 | ||
|     _pum->put("S5",  esenti_c1a_bam);
 | ||
|     _pum->put("R7",  esenti_b14); 
 | ||
|     _pum->put("R12", esni_rimb);
 | ||
|     _pum->put("R14", cessioni_cd1_1);
 | ||
|     _pum->put("R15", cessioni_cd1_2);
 | ||
|     _pum->put("R16", cessioni_cd1_3);
 | ||
|     _pum->put("R17", cessioni_cd1_4);
 | ||
|     _pum->put("R18", acquisti_cd2_1);
 | ||
|     _pum->put("R19", acquisti_cd2_2);
 | ||
|     _pum->put("R20", acquisti_cd2_3);
 | ||
|     _pum->put("R21", acquisti_cd2_4);
 | ||
|     _pum->put("R22", oroargento_cd3_1);
 | ||
|     _pum->put("R23", oroargento_cd3_2);
 | ||
|     _pum->put("R24", rottami_cd3_3);
 | ||
|     _pum->put("R25", rottami_cd3_4);
 | ||
|     _pam->put("R0",  acquisti);
 | ||
|     _pam->put("R1",  vendite);  
 | ||
|     _pam->put("R6",  assp_imp);
 | ||
|     _pam->put("R7",  assp_iva);  
 | ||
|     _pam->put("R8",  vssp_imp);
 | ||
|     _pam->put("R9",  vssp_iva);
 | ||
|     _pam->put("R4",  bdog_imp);
 | ||
|     _pam->put("R5",  bdog_iva);  
 | ||
|     _pam->put("R12", assl_imp);  
 | ||
|     _pam->put("R13", assl_iva);  
 | ||
|     _pam->put("R14", vssl_imp);  
 | ||
|     _pam->put("R15", vssl_iva);  
 | ||
|     
 | ||
|     _plm->rewrite();
 | ||
|     _pam->rewrite();
 | ||
|     _pum->rewrite();
 | ||
|     _pom->rewrite();        
 | ||
| 
 | ||
| 		if (month == 13)
 | ||
| 		{
 | ||
| 		TTable pem("PEM");
 | ||
| 
 | ||
| 		for (int reg = 0; reg < 23; reg++)
 | ||
| 		{
 | ||
| 			look_pem(pem, reg);			
 | ||
| 				real r = pem.get_real("R0") + vt_imponibile[reg];
 | ||
| 				pem.put("R0", r);
 | ||
| 				r = pem.get_real("R1") + vt_imposta[reg];
 | ||
| 				pem.put("R1", r);
 | ||
| 			pem.rewrite();
 | ||
| 		}
 | ||
|   }
 | ||
|   }
 | ||
| }          
 | ||
| 
 | ||
| void TLiquidazione_app::iva11_set_arr_phase_1(const TString& codatt)
 | ||
| // viene chiamata quando vengono scorsi i movimenti del mese, settando gran parte degli elementi di _iva11_arr.
 | ||
| {
 | ||
|   // My God! Che 2 palle riestrarre tutte le informazioni
 | ||
|   const TString4 tipodoc = _mov->get(MOV_TIPODOC);
 | ||
|   const bool intra  = _rmoviva->get_bool(RMI_INTRA);
 | ||
|   const int  tipocr = _rmoviva->get_int(RMI_TIPOCR);       
 | ||
|   //  A partire dalla versione 3.1 la gestione dell'IVA 11 non viene piu' supportata ...
 | ||
|   // ... ergo non stiamo a gestire la indetraibilita' parziale
 | ||
|   real percind;
 | ||
|   const int tipodet    = get_tipodet_from_rmi(_rmoviva->curr(), percind);
 | ||
|   real  imponibile     = _rmoviva->get_real(RMI_IMPONIBILE);
 | ||
|   real  imposta        = _rmoviva->get_real(RMI_IMPOSTA);
 | ||
|   const TString4 codiva  = _iva->get("CODTAB");
 | ||
|   const TString4 tipoiva = _iva->get("S1");
 | ||
|   const real  ali          = _iva->get_real("R0");
 | ||
|   const TString16 tipoes_v = _iva->get("S2");
 | ||
|   const TString16 tipoes_a = _iva->get("S9");
 | ||
|   const int tipoagr        = _iva->get_int("S4");
 | ||
|   const TRectype& rcs      = _cur->curr(LF_CAUSALI);
 | ||
|   const bool autofattura   = rcs.get_bool("AUTOFATT");
 | ||
|   const bool valintra      = rcs.get_bool("VALINTRA");
 | ||
|   const bool intracom      = rcs.get_bool("INTRACOM");
 | ||
|   const tipo_sospensione sosp_imp = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna;
 | ||
|   const bool corrisp       = _reg->get_bool("B0");
 | ||
|   const tiporeg tipomov    = (tiporeg)_reg->get_long("I0");
 | ||
|   const bool is_vendita    = tipomov == vendita;
 | ||
|   const bool is_acquisto   = tipomov == acquisto;
 | ||
|   
 | ||
|   const bool is_key = _iva11_arr.is_key(codatt);
 | ||
|   if (!is_key) // Aggiunge l'elemento se non c'e'
 | ||
|     _iva11_arr.add(codatt,(_Iva11Array*)new _Iva11Array,is_key);
 | ||
|   _Iva11Array& array = (_Iva11Array&)_iva11_arr[codatt] ;
 | ||
| 
 | ||
| 
 | ||
|   // TAB11_RQA34  ovvero  "RQA34" non viene trasferito!
 | ||
|   // Sebbene per motivi di pieta' viene comunque lasciato nel tracciato record (esigenze PRASSI)
 | ||
|   if (codiva.empty()) return;
 | ||
| 
 | ||
|   if (is_acquisto)
 | ||
|   {
 | ||
|     if (_isagricolo && tipodet == 0)
 | ||
|     {
 | ||
|       if (tipoagr == 2)
 | ||
|       {
 | ||
|         if (tipocr == 2 || tipocr == 3  || tipocr == 8)
 | ||
|         {
 | ||
|           array.sub(imponibile,TAB11_G30I,LF_TAB1100B);
 | ||
|           array.sub(imposta,TAB11_G30V,LF_TAB1100B);
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           array.add(imponibile,TAB11_G30I,LF_TAB1100B);
 | ||
|           array.add(imposta,TAB11_G30V,LF_TAB1100B);
 | ||
|         }
 | ||
|       }  
 | ||
|       else if (tipoagr == 3 && tipocr !=2 && tipocr != 3 && tipocr != 8)
 | ||
|       {
 | ||
|         array.add(imponibile,TAB11_G31I,LF_TAB1100B);
 | ||
|         array.add(imposta,TAB11_G31V,LF_TAB1100B);
 | ||
|       }
 | ||
|     }
 | ||
|     
 | ||
|     if (sosp_imp == nessuna && tipodet == 0 && (tipocr == 2 || tipocr == 8))
 | ||
|     {
 | ||
|       array.add(imposta,TAB11_R6,LF_TAB1100B); 
 | ||
|     }
 | ||
|     
 | ||
|     if (sosp_imp == nessuna || sosp_imp == vol_affari)
 | ||
|     {
 | ||
|       if (tipodoc == "BD" && tipodet == 9)
 | ||
|       {
 | ||
|         array.add(imponibile,TAB11_F76);
 | ||
|         if (_sind11) 
 | ||
|           array.add(imposta,TAB11_F76);
 | ||
|       }
 | ||
|       
 | ||
|       if (tipodoc != "BD")
 | ||
|       {   // Compila prima i campi FC1nn ed FC2nn, poi i campi SBFnn ed SBInn
 | ||
|         if (tipodet != 9)
 | ||
|         {
 | ||
|           if (ali == 2.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC101);
 | ||
|             array.add(imposta,TAB11_FC201);
 | ||
|           }
 | ||
|           else if (ali == 4.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC102);
 | ||
|             array.add(imposta,TAB11_FC202);
 | ||
|           }
 | ||
|           else if (ali == 6.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC103);
 | ||
|             array.add(imposta,TAB11_FC203);
 | ||
|           }
 | ||
|           else if (ali == 7.50)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC104);
 | ||
|             array.add(imposta,TAB11_FC204);
 | ||
|           }
 | ||
|           else if (ali == 8.50)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC105);
 | ||
|             array.add(imposta,TAB11_FC205);
 | ||
|           }
 | ||
|           else if (ali == 9.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC106);
 | ||
|             array.add(imposta,TAB11_FC206);
 | ||
|           }
 | ||
|           else if (ali == 10.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC107);
 | ||
|             array.add(imposta,TAB11_FC207);
 | ||
|           }
 | ||
|           else if (ali == 16.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC108);
 | ||
|             array.add(imposta,TAB11_FC208);
 | ||
|           }
 | ||
|           else if (ali == 19.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC109);
 | ||
|             array.add(imposta,TAB11_FC209);
 | ||
|           }
 | ||
|           else if (ali == 20.00)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_FC110);
 | ||
|             array.add(imposta,TAB11_FC210);
 | ||
|           }
 | ||
|             
 | ||
|           if (tipoes_a == "15")
 | ||
|             array.add(imponibile,TAB11_FC111);
 | ||
|           else if (tipoes_a == "12")
 | ||
|             array.add(imponibile,TAB11_FC112);
 | ||
|           else if (tipoes_a == "13")
 | ||
|             array.add(imponibile,TAB11_FC113);
 | ||
|           else if (tipoes_a == "14")
 | ||
|             array.add(imponibile,TAB11_FC114);
 | ||
|           else if (tipoes_a == "16")
 | ||
|             array.add(imponibile,TAB11_FC115);
 | ||
|         } 
 | ||
|         else
 | ||
|         {
 | ||
|           array.add(imponibile,TAB11_FC116);
 | ||
|           if (_sind11) 
 | ||
|             array.add(imposta,TAB11_FC116);
 | ||
|         }
 | ||
|         
 | ||
|         if (intra) // Compila i campi SBFnn
 | ||
|         {
 | ||
|           if (tipodet != 9)
 | ||
|           {
 | ||
|             if (ali == 4.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF01);
 | ||
|               array.add(imposta,TAB11_SBI01);
 | ||
|             }
 | ||
|             else if (ali == 6.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF02);
 | ||
|               array.add(imposta,TAB11_SBI02);
 | ||
|             }
 | ||
|             else if (ali == 7.50)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF03);
 | ||
|               array.add(imposta,TAB11_SBI03);
 | ||
|             }
 | ||
|             else if (ali == 9.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF04);
 | ||
|               array.add(imposta,TAB11_SBI04);
 | ||
|             }
 | ||
|             else if (ali == 10.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF05);
 | ||
|               array.add(imposta,TAB11_SBI05);
 | ||
|             }
 | ||
|             else if (ali == 16.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF06);
 | ||
|               array.add(imposta,TAB11_SBI06);
 | ||
|             }
 | ||
|             else if (ali == 19.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF07);
 | ||
|               array.add(imposta,TAB11_SBI07);
 | ||
|             }
 | ||
|             else if (ali == 20.00)
 | ||
|             {
 | ||
|               array.add(imponibile,TAB11_SBF08);
 | ||
|               array.add(imposta,TAB11_SBI08);
 | ||
|             }
 | ||
|             
 | ||
|             if (tipoes_a == "15")
 | ||
|               array.add(imponibile,TAB11_SBF09);
 | ||
|             else if (tipoes_a == "12")
 | ||
|               array.add(imponibile,TAB11_SBF10);
 | ||
|             else if (tipoes_a == "13")
 | ||
|               array.add(imponibile,TAB11_SBF11);
 | ||
|             else if (tipoes_a == "14")
 | ||
|               array.add(imponibile,TAB11_SBF12);
 | ||
|           }
 | ||
|           else         
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_SBF13);
 | ||
|             if (_sind11) 
 | ||
|               array.add(imposta,TAB11_SBF13);
 | ||
|           }
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|   }    
 | ||
| 
 | ||
|   if (is_vendita)
 | ||
|   {
 | ||
|     if (tipodoc == "CN" || tipodoc == "SN" || tipodoc == "RN") // salta i non incassati
 | ||
|        return;
 | ||
|   
 | ||
|     if (intracom || !valintra)
 | ||
|     {
 | ||
|       if (tipoes_v.not_empty()) // Inutile fare troppi controlli...
 | ||
|       {
 | ||
|         if (tipoes_v == "24")
 | ||
|           array.add(imponibile,TAB11_EC106);
 | ||
|         if (tipoes_v == "21") 
 | ||
|           array.add(imponibile,TAB11_EC107);
 | ||
|         else if (tipoes_v == "B1") 
 | ||
|           array.add(imponibile,TAB11_EC108);
 | ||
|         else if (tipoes_v == "B2")                        
 | ||
|           array.add(imponibile,TAB11_EC109);
 | ||
|         else if (tipoes_v == "B3") 
 | ||
|           array.add(imponibile,TAB11_EC110);
 | ||
|         else if (tipoes_v == "25") 
 | ||
|           array.add(imponibile,TAB11_EC111);
 | ||
|         else if (tipoes_v == "22")
 | ||
|           array.add(imponibile,TAB11_EC113);
 | ||
|         else if (tipoes_v == "20")
 | ||
|           array.add(imponibile,TAB11_EC114);
 | ||
|         else if (tipoes_v == "G7A")
 | ||
|           array.add(imponibile,TAB11_EC115);
 | ||
|         else if (tipoes_v == "G7B")
 | ||
|           array.add(imponibile,TAB11_EC116);
 | ||
|         else if (tipoes_v == "R9") // Divenuto obsoleto prima ancora di utilizzarlo...
 | ||
|           array.add(imponibile,TAB11_R9,LF_TAB1100B);
 | ||
|       }
 | ||
| 
 | ||
|       if (tipocr == 4 && tipodoc != "AF" && (sosp_imp == nessuna || sosp_imp == vol_affari))
 | ||
|         array.add(imponibile,TAB11_EC112);
 | ||
|     }
 | ||
| 
 | ||
|     if (!(corrisp && tipoiva != "VE" && (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC")))
 | ||
|     {
 | ||
|       if (!autofattura && tipoiva != "NS")
 | ||
|         if (tipodoc == "AF")
 | ||
|         {
 | ||
|           array.add(imponibile,TAB11_A35);
 | ||
|           array.add(imposta,TAB11_L2,LF_TAB1100B);
 | ||
|         }
 | ||
|         else if (valintra && !intra) 
 | ||
|         {
 | ||
|           array.add(imponibile,TAB11_A35BIS);
 | ||
|           array.add(imposta,TAB11_L2BIS,LF_TAB1100B);
 | ||
|         }
 | ||
|     
 | ||
|       if (!autofattura && (sosp_imp == nessuna || sosp_imp == vol_affari) && intra && tipoes_v == "22")
 | ||
|         array.add(imponibile,TAB11_E52);
 | ||
|     
 | ||
|       if (_isagricolo && (tipodoc != "CR" && tipodoc != "SC" && tipodoc != "RF" && tipodoc != "FS"))
 | ||
|       {
 | ||
|         const bool t1 = tipoagr == 1;
 | ||
|         const bool t1_3 = tipoagr == 1 || tipoagr == 3;
 | ||
|         if (ali == 2.00)
 | ||
|         {
 | ||
|           if (t1)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_AGME01,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_AGVE01,LF_TAB1100B);
 | ||
|           }
 | ||
|           if (intra && t1_3)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_ABME01,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_ABVE01,LF_TAB1100B);
 | ||
|           }
 | ||
|         }
 | ||
|         else if (ali == 4.00)
 | ||
|         {
 | ||
|           if (t1)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_AGME02,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_AGVE02,LF_TAB1100B);
 | ||
|           }
 | ||
|           if (intra && t1_3)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_ABME02,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_ABVE02,LF_TAB1100B);
 | ||
|           }
 | ||
|         }
 | ||
|         else if (ali == 6.00)
 | ||
|         {
 | ||
|           if (t1)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_AGME03,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_AGVE03,LF_TAB1100B);
 | ||
|           }
 | ||
|           if (intra && t1_3)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_ABME03,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_ABVE03,LF_TAB1100B);
 | ||
|           }
 | ||
|         }
 | ||
|         else if (ali == 7.50)
 | ||
|         {
 | ||
|           if (t1)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_AGME04,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_AGVE04,LF_TAB1100B);
 | ||
|           }
 | ||
|           if (intra && t1_3)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_ABME04,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_ABVE04,LF_TAB1100B);
 | ||
|           }
 | ||
|         }
 | ||
|         else if (ali == 8.50)
 | ||
|         {
 | ||
|           if (t1)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_AGME05,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_AGVE05,LF_TAB1100B);
 | ||
|           }
 | ||
|           if (intra && t1_3)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_ABME05,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_ABVE05,LF_TAB1100B);
 | ||
|           }
 | ||
|         }
 | ||
|         else if (ali == 9.00)
 | ||
|         {
 | ||
|           if (t1)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_AGME06,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_AGVE06,LF_TAB1100B);
 | ||
|           }
 | ||
|           if (intra && t1_3)
 | ||
|           {
 | ||
|             array.add(imponibile,TAB11_ABME06,LF_TAB1100B);
 | ||
|             array.add(imposta,TAB11_ABVE06,LF_TAB1100B);
 | ||
|           }
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
|   
 | ||
|   if (is_acquisto || is_vendita)
 | ||
|     if (autofattura)
 | ||
|       array.add(imponibile,TAB11_A35TER);  
 | ||
| }
 | ||
| 
 | ||
| void TLiquidazione_app::iva11_set_arr_phase_2(const TString& codatt)
 | ||
| // scorre (guarda un poco) tutti i PIM della ditta per COMPLETARE _iva11_arr
 | ||
| // Ribadisco: questa funzione COMPLETA solamente l'array scorrendo i PIM e memorizzando i rimanenti
 | ||
| // campi. Gli  altri sono compilati scorrendo i movimenti! (fatto prima della chiamata a questa funzione)
 | ||
| // Il motivo per cui il trasferimento e' fatto in 2 fasi (iva11_set_arr_phase_1 ed iva11_set_arr_phase_2)
 | ||
| // e' perche' alcune operazioni di calcolo (scorporo corrispettivi, ventilazione...) vengono effettuate
 | ||
| // dopo la recalc_att(), punto in cui viene chiamata la phase_1.
 | ||
| {
 | ||
|   TString16 codiva, reg, tiva;
 | ||
|   TString16 tpla, tvia;
 | ||
|   TString16 v11, a11;
 | ||
|   TToken_string tt("",'!');
 | ||
|   tiporeg   treg;
 | ||
|   int  tipocr,tipodet,tagr;
 | ||
|   real aliq, imp, iva, lor, vtot, atot, ivav, ivaa, adf, adi, va7i, va7v;
 | ||
|   TString16 cur_att;
 | ||
| 
 | ||
|   const bool is_key = _iva11_arr.is_key(codatt);
 | ||
|   if (!is_key)
 | ||
|     _iva11_arr.add(codatt,(_Iva11Array*)new _Iva11Array,is_key);
 | ||
|   _Iva11Array& array = (_Iva11Array&)_iva11_arr[codatt];
 | ||
|   
 | ||
|   // Scorporo corretto dei corrispettivi in R3
 | ||
|   TAssoc_array corr_ann;
 | ||
|   bool is_present;
 | ||
|              
 | ||
|   for (_pim->first(); !_pim->eof();  _pim->next())
 | ||
|   {           
 | ||
|     if (_year != *_pim_anno) continue;
 | ||
|     if (atoi(*_pim_mese) != 13) continue;
 | ||
|     cur_att = *_pim_codatt;
 | ||
|     cur_att.rtrim(1);
 | ||
|     if (codatt != cur_att) continue;  // considera solo quelli dell'anno, obviously.
 | ||
|                                       // Must consider current activity too...
 | ||
|     codiva = *_pim_codiva;
 | ||
|     reg    = *_pim_codreg;
 | ||
|     look_iva(codiva); look_reg(reg);    // posiziona la tabella registri e quella IVA
 | ||
|     tiva   = _iva->get("S1");           // tipo IVA
 | ||
|     tpla   = _iva->get("S3");           // tipo gestione plafond
 | ||
|     tagr   = _iva->get_int("S4");       // tipo gestione regime agricolo
 | ||
|     tvia   = _iva->get("S5");           // tipo gestione ag. viaggio
 | ||
|     v11    = _iva->get("S2");           // n.ro riga vendite per mod. IVA11
 | ||
|     a11    = _iva->get("S9");           // n.ro riga acquisti per mod. IVA11
 | ||
|     aliq   = _iva->get_real("R0");      // aliquota
 | ||
|     treg   = (tiporeg)_reg->get_long("I0");
 | ||
|     const bool is_vendita  = treg == vendita;
 | ||
|     const bool is_acquisto = treg == acquisto;
 | ||
|     tipocr = atoi(*_pim_tipocr);
 | ||
|     tipodet  = atoi(*_pim_tipodet);
 | ||
|     imp = _pim->get_real("R0");
 | ||
|     iva = _pim->get_real("R1");
 | ||
|     lor = _pim->get_real("R3");
 | ||
|     
 | ||
|     if (is_acquisto)
 | ||
|     {
 | ||
|       if (tiva != "NS")
 | ||
|         switch (tipocr)
 | ||
|         {
 | ||
|           case 2:
 | ||
|             array.add(imp,TAB11_IMA01);
 | ||
|             break;
 | ||
|           case 8:
 | ||
|             array.add(imp,TAB11_IMA02);
 | ||
|             break;
 | ||
|           case 1:
 | ||
|           case 5:
 | ||
|               array.add(imp,TAB11_IMA03);
 | ||
|             break;
 | ||
|           default:
 | ||
|             break;
 | ||
|         }
 | ||
|       
 | ||
|       if (tipodet == 1) 
 | ||
|         array.add(iva,TAB11_B14);
 | ||
|       
 | ||
|       // XC???: tipo detr != 9
 | ||
|       if (tipodet != 9)
 | ||
|       { 
 | ||
|         if (aliq == 4.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC101);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC201);
 | ||
|         }
 | ||
|         else if (aliq == 6.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC102);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC202);
 | ||
|         }
 | ||
|         else if (aliq == 7.50) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC103);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC203);
 | ||
|         }
 | ||
|         else if (aliq == 9.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC104);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC204);
 | ||
|         } 
 | ||
|         else if (aliq == 10.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC105);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC205);
 | ||
|         }
 | ||
|         else if (aliq == 16.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC106);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC206);
 | ||
|         }
 | ||
|         else if (aliq == 19.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC107);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC207);
 | ||
|         }
 | ||
|         else if (aliq == 20.00) 
 | ||
|         {
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC108);
 | ||
|           array.add(_pim->get_real("R10"),TAB11_XC208);
 | ||
|         }
 | ||
|                    
 | ||
|         if (a11 == "12") 
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC109);
 | ||
|         if (a11 == "13" || a11 == "14") 
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC110);
 | ||
|         if (a11 == "16") 
 | ||
|           array.add(_pim->get_real("R9"),TAB11_XC111);
 | ||
|       }
 | ||
|     } // is_acquisto
 | ||
|           
 | ||
|     if (is_vendita)
 | ||
|     {
 | ||
|       if ((_isagricolo && tagr==2) || !_isagricolo)
 | ||
|       {
 | ||
|         // Accumula i corrispettivi da scorporare per codice iva
 | ||
|         if (lor != ZERO)
 | ||
|         {
 | ||
|           is_present =  corr_ann.is_key(codiva);
 | ||
|           if (!is_present)  // Aggiungilo se non c'e'
 | ||
|             corr_ann.add(codiva,(_CorrItem*)new _CorrItem,is_present);
 | ||
|           _CorrItem& ca = (_CorrItem&) corr_ann[codiva];
 | ||
|           ca._totale += lor;
 | ||
|           if (!is_present)
 | ||
|             ca._aliquota = _iva->get_real("R0"); // Se e' nuovo setta l'aliquota
 | ||
|         }
 | ||
|         
 | ||
|         tt = _pim->get("S0");
 | ||
|         va7i = tt.get(0);
 | ||
|         va7v = tt.get(1);
 | ||
|         adf = imp - _pim->get_real("R7") - va7i + _pim->get_real("R5");
 | ||
|         adi = iva - _pim->get_real("R8") - va7v + _pim->get_real("R6");
 | ||
|         if (aliq == 4.00)
 | ||
|         {
 | ||
|           array.add(adf,TAB11_EC101);
 | ||
|           array.add(adi,TAB11_EC201);
 | ||
|         }
 | ||
|         else if (aliq == 10.00)
 | ||
|         {
 | ||
|           array.add(adf,TAB11_EC102); 
 | ||
|           array.add(adi,TAB11_EC202); 
 | ||
|         }
 | ||
|         else if (aliq == 16.00)
 | ||
|         {
 | ||
|           array.add(adf,TAB11_EC103); 
 | ||
|           array.add(adi,TAB11_EC203); 
 | ||
|         }
 | ||
|         else if (aliq == 19.00)
 | ||
|         {
 | ||
|           array.add(adf,TAB11_EC104); 
 | ||
|           array.add(adi,TAB11_EC204); 
 | ||
|         }
 | ||
|         else if (aliq == 20.00)
 | ||
|         {
 | ||
|           array.add(adf,TAB11_EC105); 
 | ||
|           array.add(adi,TAB11_EC205); 
 | ||
|         }
 | ||
|       }
 | ||
|     } // is_vendita
 | ||
|     
 | ||
|     // Boia chi linka!
 | ||
|     // Sommatoria per il calcolo aliquote medie vendite/acquisti...
 | ||
|     if (_pim->get_bool("B3")) // E' un record valido per fare questa cosa?
 | ||
|     {
 | ||
|       if ((tiporeg)_pim->get_long("I1") == vendita)
 | ||
|       {  //vendite
 | ||
|         vtot += imp; ivav+=iva;
 | ||
|       }
 | ||
|       else
 | ||
|         //acquisti
 | ||
|         if (tipodet != 9) // Evita di sommare quelli con tipo detraibilita' 9 (MI2209)
 | ||
|         {
 | ||
|           atot += imp; ivaa+=iva;
 | ||
|         }
 | ||
|     }
 | ||
|   }
 | ||
|   
 | ||
|   // Scorre i corrispettivi lordi accumulati, li scorpora ed aggiorna i righi relativi
 | ||
|   _CorrItem* cc;
 | ||
|   for (cc = (_CorrItem *)corr_ann.first_item(); cc != NULL; cc = (_CorrItem *)corr_ann.succ_item())
 | ||
|   {
 | ||
|     lordo2netto(cc->_totale,imp,iva,cc->_aliquota/CENTO);
 | ||
|     vtot += imp; ivav += iva;
 | ||
|     if (cc->_aliquota == 4.00)
 | ||
|     {
 | ||
|       array.add(imp,TAB11_EC101);
 | ||
|       array.add(iva,TAB11_EC201);
 | ||
|     }
 | ||
|     else if (cc->_aliquota == 10.00)
 | ||
|     {
 | ||
|       array.add(imp,TAB11_EC102); 
 | ||
|       array.add(iva,TAB11_EC202); 
 | ||
|     }
 | ||
|     else if (cc->_aliquota == 16.00)
 | ||
|     {
 | ||
|       array.add(imp,TAB11_EC103); 
 | ||
|       array.add(iva,TAB11_EC203); 
 | ||
|     }
 | ||
|     else if (cc->_aliquota == 19.00)
 | ||
|     {
 | ||
|       array.add(imp,TAB11_EC104); 
 | ||
|       array.add(iva,TAB11_EC204); 
 | ||
|     }
 | ||
|     else if (cc->_aliquota == 20.00)
 | ||
|     {
 | ||
|       array.add(imp,TAB11_EC105); 
 | ||
|       array.add(iva,TAB11_EC205); 
 | ||
|     }
 | ||
|   }  
 | ||
|   
 | ||
|   
 | ||
|   // Mmmhh.. Rettifica l'importo di EC114: EC114 = EC115 + EC116 + EC114
 | ||
|   real r15, r16;
 | ||
|   if (array.is_key(TAB11_EC115))
 | ||
|     r15 = ((_Iva11Item&)array[TAB11_EC115]).value();
 | ||
|   if (array.is_key(TAB11_EC116))
 | ||
|     r16 = ((_Iva11Item&)array[TAB11_EC116]).value();
 | ||
|   r16+=r15;
 | ||
|   array.add(r16,TAB11_EC114);
 | ||
|   
 | ||
|   
 | ||
|   // Calcola le maledette aliquote medie...
 | ||
|   real alv,ala;
 | ||
|   if (vtot != 0.0) { alv = ivav/vtot; alv *= CENTO; alv.round(2); }
 | ||
|   if (atot != 0.0) { ala = ivaa/atot; ala *= CENTO; ala.round(2); }
 | ||
|   array.add(ala,TAB11_R1,LF_TAB1100B);
 | ||
|   array.add(alv,TAB11_R2,LF_TAB1100B);
 | ||
|   
 | ||
|   // Mo' si pappa i PLM per compilare T1, T1C, T2, T2C, T3, T5 e T6
 | ||
|   // ATTENZIONE: solo per i regimi 74ter (ag. viaggio)
 | ||
|   for (_plm->first();!_plm->eof();_plm->next())
 | ||
|   {
 | ||
|     if (_year != *_plm_anno || atoi(*_plm_mese) != 13) continue;
 | ||
|     cur_att = *_plm_codatt;
 | ||
|     cur_att.rtrim(1);
 | ||
|     if (codatt != cur_att) continue;
 | ||
|     if (_isviaggio)
 | ||
|     {
 | ||
|       array.add(_plm->get_real("R5"),TAB11_T1,LF_TAB1100B);
 | ||
|       array.add(_plm->get_real("R7"),TAB11_T1C,LF_TAB1100B);
 | ||
|       array.add(_plm->get_real("R6"),TAB11_T2,LF_TAB1100B);
 | ||
|       array.add(_plm->get_real("R8"),TAB11_T2C,LF_TAB1100B);
 | ||
|       array.add(_plm->get_real("R9"),TAB11_T3,LF_TAB1100B);
 | ||
|       array.add(_plm->get_real("R10"),TAB11_T5,LF_TAB1100B);
 | ||
|       array.add(_plm->get_real("R11"),TAB11_T6,LF_TAB1100B);
 | ||
|     }
 | ||
|     array.add(_plm->get_real("R0"),TAB11_IVVENR);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void TLiquidazione_app::iva11_write(bool reset_r1r2)
 | ||
| // Trasferisce i dati IVA11 annuali dall'assoc_array al file tab1100
 | ||
| {
 | ||
|   const int items = _iva11_arr.items();
 | ||
|   if (items == 0) return;
 | ||
|   
 | ||
|   TString ditta,attiv,fld_name;
 | ||
|   
 | ||
|   _Iva11Array * iva11_arr;
 | ||
|   _Iva11Item * iva11;
 | ||
|   TLocalisamfile& tab1100a = _tab11->lfile();
 | ||
|   TLocalisamfile& tab1100b = _tab11->lfile(LF_TAB1100B);
 | ||
| 
 | ||
|   int err;
 | ||
|   // Ciclo sulle attivita'
 | ||
|   for (iva11_arr = (_Iva11Array *) _iva11_arr.first_item(); iva11_arr != NULL; iva11_arr = (_Iva11Array*)_iva11_arr.succ_item())
 | ||
|   {
 | ||
|     // Setta i campi chiave per entrambi i files della relazione
 | ||
|     ditta.format("%05ld",_nditte->curr().get_long(NDT_CODDITTA));
 | ||
|     attiv = _iva11_arr.get_hashobj()->key();
 | ||
|     tab1100a.zero();
 | ||
|     tab1100a.put(TAB11_TADITT,ditta);
 | ||
|     tab1100a.put(TAB11_TACATT,attiv);
 | ||
|     tab1100b.zero();
 | ||
|     tab1100b.put(TAB11_TADITT,ditta);
 | ||
|     tab1100b.put(TAB11_TACATT,attiv);
 | ||
|     
 | ||
|     const int iva11_items = iva11_arr->items();
 | ||
|     // Ciclo sugli elementi per compilare i campi della relazione
 | ||
|     for (iva11 = (_Iva11Item *)iva11_arr->first_item(); iva11 != NULL;iva11 = (_Iva11Item *)iva11_arr->succ_item())
 | ||
|     {
 | ||
|       fld_name = iva11_arr->get_hashobj()->key();
 | ||
|       if (reset_r1r2 && (fld_name == TAB11_R1 || fld_name == TAB11_R2)) continue;  // salta R1/R2 se devono rimanere a zero
 | ||
|       _tab11->lfile(iva11->file()).put(fld_name,iva11->value());
 | ||
|     }
 | ||
|     
 | ||
|     if (_tab11->write() != NOERR) 
 | ||
|       if ((err=_tab11->rewrite()) != NOERR)
 | ||
|         error_box(TR("Errore %d tentando di scrivere sul file tab1100."),err);
 | ||
|   }
 | ||
|   
 | ||
|   _iva11_arr.destroy(); // resetta l'array.
 | ||
| }
 | ||
| 
 | ||
| void TLiquidazione_app::write_liq(int month, const char* codatts)
 | ||
|   // Calcolo liq. mensili e  liq. annuali. Scrive le lim
 | ||
| {
 | ||
|   TToken_string atts(codatts);
 | ||
|   const int year_int = atoi(_year);
 | ||
|   
 | ||
|   if (_ver->read(year_int, _month)!=NOERR)
 | ||
|     warning_box(TR("Errore %d in lettura tabella versamenti ed interessi."),_ver->status());
 | ||
|     
 | ||
| /* Cazzata galattica: gi<67> gestito BENE da update_firm, prima di chiamare questa funzione
 | ||
|   // evita casino se differita ma si sta ricalcolando il primo mese con ricalcolo di piu' mesi
 | ||
|   const bool wasdifferita = (_isdifferita && month <= _monthinatt && _month > _monthinatt);
 | ||
|   if (wasdifferita) _isdifferita = FALSE;
 | ||
| */  
 | ||
|   // liq. differita: considera mese precedente (solo per i risultati)                                    
 | ||
|   int deltam = month;                                    
 | ||
|   if (_isdifferita && !is_first_month(month) && month != 13)
 | ||
|     month -= (_freqviva == "T" ? 3 : 1);
 | ||
|   deltam -= month;
 | ||
|   
 | ||
|   look_lia();
 | ||
|   const bool new_age_2000 = (year_int >= 2000) && (_lia->get("S9") == "NV");
 | ||
| 
 | ||
|   real risultato    = 0.0;
 | ||
|   real detrazioni   = 0.0;
 | ||
|   real versamenti   = 0.0;
 | ||
|   real vers_int     = 0.0;
 | ||
|   real rimborsi     = 0.0;
 | ||
|   real rettifiche   = 0.0;   
 | ||
|   real res_debt     = 0.0;
 | ||
|   real res_cred     = 0.0;
 | ||
|   real cred_prec    = 0.0;
 | ||
|   real cred_trasf   = 0.0;
 | ||
|   real debt_precd   = 0.0;
 | ||
|   real acc_dec      = 0.0;
 | ||
|   real iva_vend     = 0.0;
 | ||
|   real iva_acq      = 0.0;
 | ||
|   real conguaglio   = 0.0;
 | ||
|   real variazioni_imposta = 0.0;
 | ||
|   real imposta_non_versata = 0.0;
 | ||
|   real crediti_speciali = 0.0;
 | ||
|     
 | ||
|   // totali per regimi agricoli
 | ||
|   real acq_noCEE    = 0.0;
 | ||
|   real imp_agr1     = 0.0;
 | ||
|   real imp_agr2     = 0.0;
 | ||
|   
 | ||
|   // totali per agenzie viaggio
 | ||
|   real c_iCEE       = 0.0;
 | ||
|   real c_eCEE       = 0.0;
 | ||
|   real a_iCEE       = 0.0;
 | ||
|   real a_eCEE       = 0.0;
 | ||
|   real c_mCEE       = 0.0;
 | ||
|   real a_mCEE       = 0.0;
 | ||
|   real a_meCEE      = 0.0;   
 | ||
|   real cred_cost    = 0.0;
 | ||
|   real deb_mens     = 0.0;
 | ||
|   real perc_r       = 0.0;       
 | ||
|   
 | ||
|   // totali per annuali
 | ||
|   real vol_aff_1    = 0.0;
 | ||
|   real vol_aff_2    = 0.0;
 | ||
|   real vol_aff_t    = 0.0;
 | ||
|   real vol_aff_l    = 0.0;
 | ||
|   real tot_cong     = 0.0;
 | ||
|   
 | ||
|   bool differita           = FALSE;
 | ||
|   bool almeno_una_agricola = FALSE;
 | ||
|   bool almeno_una_normale  = FALSE;
 | ||
|   int attc = 0; // counter attivita'
 | ||
|   
 | ||
|   // nuova liquidazione
 | ||
|   real credito_utilizzabile_inizio_anno = ZERO;
 | ||
|   real credito_utilizzato_inizio_anno = ZERO;
 | ||
|   real credito_utilizzato_iva = ZERO;
 | ||
|   if (new_age_2000) 
 | ||
|   { 
 | ||
|     credito_utilizzato_inizio_anno = _lia->get_real("R15");
 | ||
|     credito_utilizzabile_inizio_anno = _lia->get_real("R0") - credito_utilizzato_inizio_anno;
 | ||
|     if (credito_utilizzabile_inizio_anno < ZERO)
 | ||
|       credito_utilizzabile_inizio_anno = ZERO;
 | ||
|   }
 | ||
|   
 | ||
|   TLocalisamfile& attiv = _nditte->lfile(LF_ATTIV);
 | ||
|   
 | ||
|   const char* tmpatt;     
 | ||
|   while ((tmpatt = atts.get()) != NULL)
 | ||
|   {
 | ||
|     const TString16 att = tmpatt;
 | ||
|     
 | ||
|     // Reperisce il flag di regime agricolo per ogni attivita'...
 | ||
|     attiv.put(ATT_CODATT,att);
 | ||
|     attiv.read();
 | ||
|     const bool attivita_agricola = attiv.get_bool(ATT_REGAGR);
 | ||
|     almeno_una_agricola |= attivita_agricola;
 | ||
|     almeno_una_normale  |= !attivita_agricola;
 | ||
|     
 | ||
|     if (_isdifferita && is_first_month(month+deltam))
 | ||
|     {
 | ||
|       // usa i totali del mese di dicembre dell'anno
 | ||
|       // precedente      
 | ||
|       differita = TRUE;
 | ||
|       const TString16 yr(_year);  // Salvo anno corrente
 | ||
|       _year.format("%d", year_int-1);
 | ||
|       if (!look_lim(12)) //controlla solamente, il vero posizionamento lo fa dopo
 | ||
|       { 
 | ||
|         _year = yr;               // Ripristino anno corrente
 | ||
|         differita = FALSE;
 | ||
|       }
 | ||
|     }
 | ||
|     
 | ||
|     for (int m = 1; m <= 13; m++)
 | ||
|     {                             
 | ||
|       // ciclo su tutti i mesi del caso (1 o 3;
 | ||
|       // tutti se annuale)
 | ||
|       if (!is_month_ok(m, month)) 
 | ||
|         continue;
 | ||
|     
 | ||
|       look_plm(differita ? 12 : m, att); 
 | ||
|       bool is_lim = look_lim(_isdifferita ? m+deltam : m);
 | ||
|       
 | ||
|       // Se trattasi di annuale considera solo PLM/PUM del mese 13
 | ||
|       if ((month == 13 && m == 13) || month != 13)
 | ||
|       {
 | ||
|         // gia' conteggiato: prorata
 | ||
|         // da conteggiare: IVA vendite ag. viaggio
 | ||
|         // a debito:  IVA vendite, debito precedente
 | ||
|         // a credito: IVA acquisti, ulteriori detrazioni 1 e 2     
 | ||
|           
 | ||
|         if (!attivita_agricola)
 | ||
|         {
 | ||
|           iva_vend  += _plm->get_real("R0");
 | ||
|           iva_acq   += _plm->get_real("R1");
 | ||
|           risultato += (_plm->get_real("R0") - _plm->get_real("R1"));
 | ||
|           res_debt  += _plm->get_real("R0");
 | ||
|           res_cred  += _plm->get_real("R1");
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           // Tiene aggiornata l'iva vendite
 | ||
|           iva_vend += _plm->get_real("R6") + _plm->get_real("R5");
 | ||
|           // Tiene aggiornata l'iva acquisti, che andra' rettificata all'uscita del mese
 | ||
|           // secondo la formula:
 | ||
|           // iva_acq = iva_acq + iva detraibile calcolata + iva compensazione
 | ||
|           // L'iva di compensazione e' tratta dall'iva vendite agricole con segnalino 1 (vedi tabella PIA)
 | ||
|           // il cui totale e' memorizzato in plm->R13
 | ||
|           // l'iva detraibile calcolata e' a sua volta fatta cosi'
 | ||
|           // sum(plm->R11) * { sum(pum->R11) / [sum(pum->R11) + sum(pum->R10)]}
 | ||
|           // dove plm->R11 = acquisti misti fuori CEE
 | ||
|           //      pum->R10 = tot. imponibile reg agr. 1
 | ||
|           //      pum->R11 = tot. imponibile reg agr. 2
 | ||
|           // L'iva acquisti viene calcolata in modo diverso se siamo dal 1998 in poi:
 | ||
|           // somma l'iva ammessa in detr. I parte tab. A (R13) anziche' iva vendite (R5)
 | ||
|           iva_acq   += _plm->get_real("R7") + _plm->get_real(year_int > 1997 ? "R13" : "R5");
 | ||
|           acq_noCEE += _plm->get_real("R11");
 | ||
|           imp_agr1  += _pum->get_real("R10");
 | ||
|           imp_agr2  += _pum->get_real("R11");
 | ||
|         }  
 | ||
|         detrazioni+= (_plm->get_real("R3"));
 | ||
|           
 | ||
|         // detrazioni solo non in regime agricolo
 | ||
|         if (!attivita_agricola)
 | ||
|         {
 | ||
|           risultato -= (_plm->get_real("R3")); 
 | ||
|           res_cred  += (_plm->get_real("R3"));
 | ||
|         }
 | ||
|         
 | ||
|         /* totalizza importi 74 ter */           
 | ||
|         if (_isviaggio) 
 | ||
|         {
 | ||
|           // somma totali per calcolo successivo
 | ||
|           c_iCEE  += _plm->get_real("R5");
 | ||
|           c_eCEE  += _plm->get_real("R6");
 | ||
|           a_iCEE  += _plm->get_real("R7");
 | ||
|           a_eCEE  += _plm->get_real("R8");
 | ||
|           c_mCEE  += _plm->get_real("R9");
 | ||
|           a_mCEE  += _plm->get_real("R10");
 | ||
|           a_meCEE += _plm->get_real("R11");   
 | ||
|         }        
 | ||
|       }  // endif per considerare solo PLM del mese 13
 | ||
|       
 | ||
|       // Le seguenti cose (versamenti, rettifiche e rimborsi)
 | ||
|       // vanno considerate per tutti i mesi (tabella lim)
 | ||
|       
 | ||
|       /* se annuale, somma versamenti mesi 1-12 
 | ||
|        * solo una volta (non per tutte le attivita')
 | ||
|        */
 | ||
|       if (attc == 0 && month == 13)
 | ||
|       { 
 | ||
|         // l'acconto a dicembre si conteggia a parte solo
 | ||
|         // nei casi previsti e non in annuale (vedi sotto)     
 | ||
|         real vs(versamenti_IVA(m , m == 12 ? "1" : "1|7"));
 | ||
|         real vi(versamenti_IVA(m,"5"));
 | ||
|         versamenti += vs;
 | ||
|         vers_int   += vi;
 | ||
|         res_cred   += vs + vi;
 | ||
|       }
 | ||
|                 
 | ||
|       /*
 | ||
|        * rimborso se chiesto e previsto 
 | ||
|        * in annuale non si chiede e non va sommato se no lo cumula
 | ||
|        */
 | ||
|       if (attc == 0 && is_lim && m < 13 && is_month_ok_strict(m,month))
 | ||
|       { 
 | ||
|         const real rimborso_richiesto = _lim->get_real("R1"); 
 | ||
|         risultato += rimborso_richiesto;
 | ||
|         rimborsi  += rimborso_richiesto;
 | ||
|         res_debt  += rimborso_richiesto;
 | ||
|       }                               
 | ||
|       
 | ||
|       /*
 | ||
|        * rettifiche gia' col loro bravo segno
 | ||
|        */
 | ||
|       if (attc == 0 && is_lim && is_month_ok_strict(m,month))
 | ||
|       {
 | ||
|         bool somma_rettifiche = FALSE;
 | ||
|         if (year_int < 2000)
 | ||
|         {
 | ||
|           // se sono per benzinaro le conta solo in annuale, 
 | ||
|           // se no vanno solo in periodica 
 | ||
|           // almeno cosi' dicevano fino ad agosto
 | ||
|           // poi, sara' il caldo, mi hanno detto che e' sbagliato   
 | ||
|           const TString& descrett = _lim->get("S0");
 | ||
|           const bool isforbenzinaro = descrett[0] == '$' || (descrett[0] == '>' && descrett[1] == '>');
 | ||
|           somma_rettifiche = !(month == 13 && !isforbenzinaro) && m < 13;
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           somma_rettifiche = month < 13 || m < 13; // CM00278           
 | ||
|         }
 | ||
|         if (somma_rettifiche)
 | ||
|         { 
 | ||
|           const real rett = _lim->get_real("R5");
 | ||
|           risultato  += rett; 
 | ||
|           rettifiche += rett; 
 | ||
|           if (rett.sign() < 0)
 | ||
|             res_cred -= rett;
 | ||
|           else
 | ||
|             res_debt += rett;
 | ||
|         }
 | ||
|       }
 | ||
|       
 | ||
|       /*
 | ||
|       * Somme varie per 13a
 | ||
|       */
 | ||
|       if (attc == 0 && is_lim && m < 13 && is_month_ok_strict(m,month))
 | ||
|       {
 | ||
|         const real r17 = _lim->get_real("R17");
 | ||
|         variazioni_imposta += r17; 
 | ||
|         risultato += r17; 
 | ||
|         if (r17.sign() >= 0)
 | ||
|           res_debt += r17;
 | ||
|         else
 | ||
|           res_cred -= r17;
 | ||
| 
 | ||
|         const real r18 = _lim->get_real("R18");
 | ||
|         imposta_non_versata += r18; 
 | ||
|         risultato += r18; 
 | ||
|         res_debt += r18;
 | ||
|         
 | ||
|         const real r19 = _lim->get_real("R19");
 | ||
|         crediti_speciali += r19;
 | ||
|         risultato -= r19; 
 | ||
|         res_cred += r19;
 | ||
|       }
 | ||
|     } // fine ciclo sul mese  
 | ||
|       
 | ||
|     // counter attivita' per evitare troppi versamenti
 | ||
|     attc++;
 | ||
|     if (differita) 
 | ||
|       _year.format("%d", atoi(_year)+1); 
 | ||
|     
 | ||
|     if (!(_isdifferita && is_first_month(month+deltam)))
 | ||
|     {   
 | ||
|       if (_isviaggio)
 | ||
|       {
 | ||
|         // calcolo credito costo, debito mensile, perc. ripart.
 | ||
|         perc_r   = a_mCEE.is_zero() ? ZERO : (a_mCEE * CENTO)/(a_mCEE + a_meCEE); perc_r.round(2);
 | ||
|         real ivm = (c_mCEE * perc_r)/CENTO; round_alla_lira(ivm, TRUE);
 | ||
|         real tc  = (c_iCEE + ivm);
 | ||
|         real ta  = (a_iCEE + a_mCEE);
 | ||
|         real bi  = tc - ta - credito_costo_prec(month);
 | ||
| 
 | ||
|         if (bi.sign() < 0)
 | ||
|           // credito di costo 
 | ||
|         {
 | ||
|           cred_cost = abs(bi); 
 | ||
|           if (atoi(_year) < 2000)
 | ||
|             round_alla_lira(cred_cost);
 | ||
|           else  
 | ||
|             round_imposta(cred_cost);
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           const real ali_via = aliquota_agvia();
 | ||
|           // deb_mens    = (bi /((CENTO + ali_via)/CENTO)) * (ali_via/CENTO);
 | ||
|           deb_mens    = bi * ali_via / (ali_via+CENTO);
 | ||
|           round_alla_lira(deb_mens, TRUE);   // ceil voluto MI3074 
 | ||
|           risultato  += deb_mens; 
 | ||
|           res_debt   += deb_mens; 
 | ||
|           iva_vend   += deb_mens;
 | ||
|         }
 | ||
|       }      
 | ||
|     }    
 | ||
|     if (attivita_agricola)
 | ||
|     {
 | ||
|       real perc; // percentuale di deducibilita'
 | ||
|       real iva_ded; // iva deducibile
 | ||
|       
 | ||
|       perc = imp_agr2.is_zero() ? ZERO : imp_agr2 / (imp_agr1 + imp_agr2);
 | ||
|       perc.round(2);
 | ||
|       iva_ded = acq_noCEE * perc;
 | ||
|       round_alla_lira(iva_ded);
 | ||
|       iva_acq   += iva_ded;
 | ||
|       res_debt  += iva_vend;
 | ||
|       res_cred  += iva_acq;
 | ||
|       risultato += (iva_vend - iva_acq);
 | ||
|     } // __ end of agricolo
 | ||
|   } // end ciclo su attivita'
 | ||
|   
 | ||
|   real credito_utilizzabile = ZERO;
 | ||
|   
 | ||
|   if (month < 13) // va bene anche se differita sommando deltam (che e' 0 normalmente)
 | ||
|   {
 | ||
|     // toglie credito precedente
 | ||
|     cred_prec  =  credito_prec(month+deltam);
 | ||
|     risultato -=  cred_prec; 
 | ||
|     res_cred  +=  cred_prec;
 | ||
|     // vedi se c'era un debito precedente per debiti < 50.000
 | ||
|     debt_precd = debt_prec(month+deltam);
 | ||
|     risultato += debt_precd;
 | ||
|     res_debt  += debt_precd;
 | ||
|     
 | ||
|     if (new_age_2000 && credito_utilizzabile_inizio_anno > ZERO && 
 | ||
|         (_freqviva == "M" || is_trim(month+deltam)))
 | ||
|     {             
 | ||
|       real debiti = res_debt; round_imposta(debiti);
 | ||
|       real crediti = res_cred; round_imposta(crediti);
 | ||
|       const real risul = debiti - crediti;
 | ||
|       if (risul > ZERO)
 | ||
|       {
 | ||
|         credito_utilizzabile = credito_utilizzabile_inizio_anno;
 | ||
|         credito_utilizzabile -= credito_utilizzato(month+deltam, TRUE, TRUE); 
 | ||
|         if (credito_utilizzabile < ZERO) credito_utilizzabile = ZERO;
 | ||
|         credito_utilizzato_iva = min(risul, credito_utilizzabile);
 | ||
|         res_cred += credito_utilizzato_iva;
 | ||
|         risultato -= credito_utilizzato_iva;
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
|   else 
 | ||
|   { 
 | ||
|     if (new_age_2000)
 | ||
|     {
 | ||
|       cred_prec = ZERO;
 | ||
|       if (credito_utilizzabile_inizio_anno > ZERO)
 | ||
|       {     
 | ||
|         credito_utilizzato_iva = credito_utilizzato(13, TRUE, FALSE); // CM00285
 | ||
|         res_cred += credito_utilizzato_iva;
 | ||
|         risultato -= credito_utilizzato_iva;
 | ||
| 
 | ||
|         // Calcola credito utilizzabile da riportare nell'anno successivo
 | ||
|         credito_utilizzabile = credito_utilizzabile_inizio_anno;
 | ||
|         credito_utilizzabile -= credito_utilizzato(13, TRUE, TRUE); 
 | ||
|         if (credito_utilizzabile < ZERO) credito_utilizzabile = ZERO;
 | ||
|       }
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       // per l'annuale considera solo il credito a inizio anno
 | ||
|       cred_prec = credito_prec(_freqviva == "M" ? 1 : 3);
 | ||
|       cred_trasf = _lia->get_real("R15");        
 | ||
|       const real cred_res = cred_prec - cred_trasf;
 | ||
|       risultato -=  cred_res; 
 | ||
|       res_cred  +=  cred_res;
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   if (month == 13)
 | ||
|   {
 | ||
|     // totalizza volumi affari e calcola nuovo prorata
 | ||
|     // per tutte le attivita' 
 | ||
|     atts.restart();
 | ||
|     while ((tmpatt = atts.get()) != NULL)
 | ||
|     {
 | ||
|       TString att(tmpatt); 
 | ||
|       int tipoatt = att[att.len() -1] - '0';
 | ||
|       if (tipoatt == 1) // su PLA l'attivita' e' sempre 1
 | ||
|       {
 | ||
|         if (!look_pla(att)) continue;
 | ||
|         
 | ||
|         real vf1 = _pla->get_real("R14");
 | ||
|         real vf2(_pla->get("S1"));              
 | ||
|         real iaq = _pla->get_real("R11"); // IVA acquisti
 | ||
|         real ppg = _pla->get_real("R12"); // pro-rata pagato
 | ||
|         
 | ||
|         vol_aff_1 += vf1;
 | ||
|         vol_aff_2 += vf2; 
 | ||
|         vol_aff_t  = vf1 + vf2;
 | ||
|         vol_aff_l += _pla->get_real("R0"); // volume affari lordo
 | ||
|         
 | ||
|         real es_c1     = _pla->get_real("R1");
 | ||
|         real es_c2     = _pla->get_real("R2");
 | ||
|         real es_c3     = _pla->get_real("R3");
 | ||
|         real es_c1a    = _pla->get_real("R15");
 | ||
|         real es_c3_am  = _pla->get_real("R16");
 | ||
|         real es_c1a_am = _pla->get_real("R17");
 | ||
|         real csamm     = _pla->get_real("R4");
 | ||
|         
 | ||
|         real prorata    = 0.0; 
 | ||
|         real conguaglio = 0.0;
 | ||
|         real topay      = 0.0;
 | ||
|         real ris = vol_aff_t;  // gia' esclusi: NS, B3, cess. amm
 | ||
|         
 | ||
|         // calcola nuovo prorata per ogni attivita' (miste: 1+2)
 | ||
|         if (year_int > 1997) // Calcolo dal 1998 in poi
 | ||
|         {
 | ||
|           const real rsa = ris - (es_c1a-es_c1a_am) - (es_c3-es_c3_am);
 | ||
|           const real rsn = rsa - es_c1;
 | ||
|           if (!rsa.is_zero())
 | ||
|             prorata = CENTO - ((rsn/rsa) * CENTO); // Percentuale di indetraibilita: reciproco della percentuale di detraibilita'
 | ||
|         }
 | ||
|         else
 | ||
|         {
 | ||
|           if (!ris.is_zero())
 | ||
|             prorata = (es_c1/ris) * CENTO;
 | ||
|         }
 | ||
| 
 | ||
|         prorata.round(0);
 | ||
|         
 | ||
|         //if (prorata != _prorata.current())
 | ||
|         {
 | ||
|           // calcolo conguaglio -- se positivo e' a debito
 | ||
|           if (prorata > 0.0)
 | ||
|           {
 | ||
|             topay = (iaq + ppg) * (prorata / CENTO); 
 | ||
|             round_imposta(topay);
 | ||
|           }
 | ||
|           conguaglio = topay - ppg;
 | ||
|           round_imposta(conguaglio);
 | ||
|         }
 | ||
|         
 | ||
|         if (prorata < 0.0) prorata = 0.0;
 | ||
|         _pla->put("R9", conguaglio);        
 | ||
|         _pla->put("R10",prorata); 
 | ||
|         
 | ||
|         // Prorata delle mie brame...
 | ||
|         // Chi e' il piu' sfatto del reame?
 | ||
|         // Non va considerata la differenza tra topay e pro-rata pagato
 | ||
|         // ma semplicemente topay. (Vedi cg4304.cpp in set_annual())
 | ||
|         //tot_cong += conguaglio;
 | ||
|         tot_cong += topay;
 | ||
|         _pla->rewrite();
 | ||
|         
 | ||
|         // scrivi nuovo prorata in tabella anno successivo
 | ||
|         const TString16 yr = _year;
 | ||
|         _year.format("%d", atoi(_year) + 1);
 | ||
|         look_pla(att, TRUE);
 | ||
|         _pla->put("R8", prorata);
 | ||
|         _pla->rewrite();
 | ||
|         if (look_lia(0l, TRUE))
 | ||
|         {                          
 | ||
|           if (atoi(_year) >= 2000)
 | ||
|           { 
 | ||
|             real cc = cred_cost;
 | ||
|             round_imposta(cc);
 | ||
|             _lia->put("R5", cc); 
 | ||
|           }
 | ||
|           else
 | ||
|             _lia->put("R5", cred_cost); 
 | ||
|           _lia->rewrite(); 
 | ||
|         }
 | ||
|         _year = yr;         
 | ||
|       } 
 | ||
|     }                     
 | ||
| 
 | ||
|     look_lia();
 | ||
|     _lia->put("R1", vol_aff_l);
 | ||
|     _lia->put("R2", vol_aff_1);
 | ||
|     _lia->put("R3", vol_aff_2); 
 | ||
|     _lia->rewrite();
 | ||
|   }
 | ||
|   
 | ||
|   // comprende anche il conguaglio prorata
 | ||
|   risultato += tot_cong;
 | ||
|   if (atoi(_year) <= 1997)
 | ||
|   {
 | ||
|     if (tot_cong.sign() > 0) res_debt += tot_cong;
 | ||
|     if (tot_cong.sign() < 0) res_cred -= tot_cong;
 | ||
|   }
 | ||
|   else // Nuovo prorata dal 1998, congloba il conguaglio pro-rata nell'IVA ammessa in detrazione
 | ||
|   {
 | ||
|     if (tot_cong.sign() > 0) 
 | ||
|     {
 | ||
|       iva_acq  -= tot_cong;
 | ||
|       res_cred -= tot_cong;
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|       iva_acq  += abs(tot_cong);
 | ||
|       res_cred += abs(tot_cong);
 | ||
|     }
 | ||
|   }
 | ||
|                 
 | ||
|   look_lim(month+deltam,TRUE);       
 | ||
|   // azzeriamo tutto (tranne r1, r5, s1, s0, s7)
 | ||
|   const TString codtab = _lim->get("CODTAB");
 | ||
| 
 | ||
|   real rimborso = _lim->get("R1");
 | ||
|   real r5 = _lim->get("R5"); // Rettifiche
 | ||
|   real credito_utilizzato_f24 = _lim->get("R16"); 
 | ||
|   real r17 = _lim->get("R17"); 
 | ||
|   real r18 = _lim->get("R18"); 
 | ||
|   real r19 = _lim->get("R19");
 | ||
|   TString s7 = _lim->get("S7");  
 | ||
|   const TString s0 = _lim->get("S0");  // Descrizioni rettifiche
 | ||
|   const TString s1 = _lim->get("S1");  
 | ||
|   const TString s2 = _lim->get("S2");  
 | ||
|   const TString s3 = _lim->get("S3");  
 | ||
|   bool wasb0 = _lim->get_bool("B0");
 | ||
|   bool wasb1 = _lim->get_bool("B1");
 | ||
| 
 | ||
|   _lim->zero();
 | ||
|   _lim->put("CODTAB", codtab);
 | ||
|   _lim->put("R1", rimborso);  
 | ||
|   _lim->put("R5", r5); // Rettifiche
 | ||
|   _lim->put("R16", credito_utilizzato_f24);  
 | ||
|   _lim->put("R17", r17);  
 | ||
|   _lim->put("R18", r18);  
 | ||
|   _lim->put("R19", r19);  
 | ||
|   _lim->put("S0", s0);  
 | ||
|   _lim->put("S1", s1);  
 | ||
|   _lim->put("S2", s2);  
 | ||
|   _lim->put("S3", s3);  
 | ||
|   _lim->put("S7", s7);           
 | ||
|   _lim->put("B0", wasb0 ? "X" : "");
 | ||
|   _lim->put("B1", wasb1 ? "X" : "");
 | ||
|   
 | ||
|   /* 
 | ||
|    * versamenti effettuati: si conteggiano in R0,
 | ||
|    * sono > 0 solo se andavano calcolati (vedi sopra)
 | ||
|    */
 | ||
|   risultato -= versamenti + vers_int;
 | ||
|   /* 
 | ||
|    * acconto dicembre se previsto
 | ||
|    */
 | ||
|   if (((month+deltam) >= 12 && _freqviva == "M") || // solo freq. M puo' essere differita
 | ||
|       (month == 12 && _isbenzinaro && _gest4) ||    
 | ||
|       (month >= (atoi(_year) >= 2000 ? 12 : 13) && _freqviva == "T")) 
 | ||
|   {
 | ||
|     acc_dec    = versamenti_IVA(12,"7");
 | ||
|     risultato -= acc_dec;
 | ||
|     res_cred  += acc_dec;
 | ||
|   }
 | ||
|   
 | ||
|   // in annuale si arrotondera' a 1000 in stampa 
 | ||
|   // se no il conguaglio prorata fa casino
 | ||
|   round_alla_lira(risultato);
 | ||
|   
 | ||
|   _lim->put("R0",risultato); 
 | ||
|   _lim->put("R2",cred_cost); 
 | ||
|   _lim->put("R3",deb_mens); 
 | ||
|   _lim->put("R4",perc_r); 
 | ||
|   
 | ||
|   if (almeno_una_normale)
 | ||
|     _lim->put("R6",detrazioni);  
 | ||
|   else // per evitare sbagli nei ricalcoli esterni
 | ||
|     _lim->put("R6","");
 | ||
|     
 | ||
|   if (month == 13 || differita)
 | ||
|   {     
 | ||
|     // Arrotonda totali in quanto possono avere un arrotondamento diverso dal mensile        
 | ||
|     TIva_round ir;
 | ||
|     ir.round(rimborsi);
 | ||
|     ir.round(rettifiche);
 | ||
|     ir.round(variazioni_imposta);
 | ||
|     ir.round(imposta_non_versata);
 | ||
|     ir.round(crediti_speciali);
 | ||
|     
 | ||
|     // scrivi totali rettifiche e rimborsi
 | ||
|     // nella finale oppure se copiati da
 | ||
|     // anno precedente
 | ||
|     _lim->put("R1",rimborsi);
 | ||
|     _lim->put("R5",rettifiche);
 | ||
|     
 | ||
|     _lim->put("R17", variazioni_imposta);
 | ||
|     _lim->put("R18", imposta_non_versata);
 | ||
|     _lim->put("R19", crediti_speciali);
 | ||
|   }
 | ||
|                                  
 | ||
|   /*
 | ||
|    * Interessi dovuti solo da trimestrali in periodica,
 | ||
|    * Era anche non benzinari, smentito da Cinzia (MI0853);
 | ||
|    * Ora gestito esplicitamente nei parametri ditta, forzato 
 | ||
|    * FALSE per ditte mensili e liq. annuale
 | ||
|    * Ulteriormente smentito e rettificato
 | ||
|    */              
 | ||
|   bool true_trim = (month == 3 || month == 6 || month == 9);
 | ||
|   if (_isintr && ( true_trim || (month == 12 && _isbenzinaro && _gest4)
 | ||
|       || (month == 13 && !(_isbenzinaro && _gest4)) ))
 | ||
|   {
 | ||
|     const real interesse = interesse_trimestrale(_month);
 | ||
|     const real r = risultato - imposta_non_versata;           // CM 26-09-2000
 | ||
|     real ivi = r.sign() > 0 ? (r * interesse / CENTO) : ZERO; 
 | ||
|     round_alla_lira(ivi, TRUE);
 | ||
|     _lim->put("R14", ivi); 
 | ||
|   }
 | ||
|   
 | ||
|   //questo serve anche per la visualizzazione e per l'estrazione deleghe  
 | ||
|   if (_isintr && ( true_trim || (month == 12 && _isbenzinaro && _gest4)
 | ||
|       || (month == 13 && !(_isbenzinaro && _gest4)) ))
 | ||
|     _lim->put("R10",interesse_trimestrale(_month));       
 | ||
|   
 | ||
|   _lim->put("R7",  tot_cong); // totale conguaglio su tutte le attivita'
 | ||
|   _lim->put("R8",  versamenti);
 | ||
|   _lim->put("R9",  vers_int);
 | ||
|   _lim->put("R11", acc_dec);
 | ||
|   _lim->put("R12", res_cred);  
 | ||
|   _lim->put("R13", res_debt);  
 | ||
| 
 | ||
|   _lam->put("R0",  iva_vend);
 | ||
|   _lam->put("R1",  iva_acq);
 | ||
|   _lam->put("R2",  cred_prec);
 | ||
|   _lam->put("R3",  debt_precd);
 | ||
|   
 | ||
|   if (!_recalc_only && _recalc != never)
 | ||
|   {
 | ||
|    _lim->put("B0","X");   
 | ||
|    // Dal 1998 questo flag vale solo per i progressivi dei registri IVA, visto che sono separati
 | ||
|    // pertanto il suo settaggio andra' fatto solo in fase di ricalcolo (_recalc_only)
 | ||
|    if (atoi(_year) < 1998)
 | ||
|      _lim->put("B1","X");
 | ||
|   } 
 | ||
|   
 | ||
|   if (_recalc_only) 
 | ||
|     _lim->put("B1", "X");
 | ||
| 
 | ||
| /* Cazzata galattica: vedi sopra  
 | ||
|   if (wasdifferita) _isdifferita = TRUE;
 | ||
| */                              
 | ||
| 
 | ||
|   // AWFUL! se siamo in annuale, occorre arrotondare alle 1000 lire
 | ||
|   // schiaffo tutto il codice nell'IF che segue, e se lo si vuole togliere
 | ||
|   // non si fara' che scancellare tutto il blocco
 | ||
|   const bool after2000 = atoi(_year) >= 2000;  // CM000222
 | ||
|   if (month == 13 || after2000)   
 | ||
|   {
 | ||
|     // molto codice duplicato, ma ne val la pena (vedi sopra)
 | ||
|     round_imposta(iva_vend);
 | ||
|     round_imposta(iva_acq);
 | ||
|     round_imposta(detrazioni);
 | ||
|     round_imposta(versamenti);
 | ||
|     round_imposta(vers_int);
 | ||
|     round_imposta(rimborsi);
 | ||
|     round_imposta(rettifiche);
 | ||
|     round_imposta(deb_mens);
 | ||
|     round_imposta(cred_prec);
 | ||
|     round_imposta(cred_trasf);
 | ||
|     round_imposta(tot_cong);
 | ||
|     round_imposta(acc_dec);
 | ||
|     round_imposta(debt_precd);            
 | ||
|     round_imposta(variazioni_imposta);
 | ||
|     round_imposta(imposta_non_versata);
 | ||
|     round_imposta(credito_utilizzato_iva);
 | ||
|     round_imposta(crediti_speciali);
 | ||
|     
 | ||
|     res_cred  = iva_acq + versamenti + vers_int + cred_prec - cred_trasf + acc_dec + credito_utilizzato_iva + crediti_speciali;
 | ||
|     res_debt  = iva_vend + rimborsi + debt_precd + imposta_non_versata;  
 | ||
|     
 | ||
|     if (atoi(_year) < 1998) // Non vale piu' dal 1998 in poi; iva_acq e' gia' ok e cosi' res_cred.
 | ||
|     {
 | ||
|       if (tot_cong.sign() > 0) 
 | ||
|         res_debt += tot_cong;
 | ||
|       else 
 | ||
|         res_cred -= tot_cong;
 | ||
|     }
 | ||
| 
 | ||
|     if (rettifiche.sign() >= 0) 
 | ||
|       res_debt += rettifiche;
 | ||
|     else 
 | ||
|       res_cred -= rettifiche;
 | ||
|       
 | ||
|     if (variazioni_imposta.sign() >= 0) 
 | ||
|       res_debt += variazioni_imposta;
 | ||
|     else 
 | ||
|       res_cred -= variazioni_imposta;
 | ||
| 
 | ||
|     if (almeno_una_normale)
 | ||
|       res_cred  += detrazioni; 
 | ||
| 
 | ||
|     risultato = res_debt - res_cred;
 | ||
|     
 | ||
|     // tut ricalcule', riscrivem
 | ||
|     _lam->put("R0",  iva_vend);
 | ||
|     _lam->put("R1",  iva_acq);
 | ||
|     _lam->put("R2",  cred_prec);
 | ||
|     _lam->put("R3",  debt_precd);
 | ||
|     _lam->put("R4",  cred_trasf);
 | ||
| 
 | ||
|     _lim->put("R0",  risultato);          
 | ||
|     _lim->put("R1",  rimborsi);
 | ||
|     _lim->put("R2",  cred_cost); 
 | ||
|     _lim->put("R3",  deb_mens); 
 | ||
|     _lim->put("R5",  rettifiche);
 | ||
|     _lim->put("R6",  detrazioni);
 | ||
|     _lim->put("R7",  tot_cong);
 | ||
|     _lim->put("R8",  versamenti);
 | ||
|     _lim->put("R9",  vers_int);
 | ||
|     _lim->put("R11", acc_dec);
 | ||
|     _lim->put("R12", res_cred);  
 | ||
|     _lim->put("R13", res_debt);       
 | ||
|     if (after2000)  // Anche R14
 | ||
|     {
 | ||
|       real ivi = _lim->get("R14");
 | ||
|       round_imposta(ivi);
 | ||
|       _lim->put("R14", ivi);       
 | ||
|     }                               
 | ||
|     _lim->put("R15", credito_utilizzato_iva);
 | ||
|     
 | ||
|     if (month == 13)
 | ||
|     {
 | ||
|       // Riporta eventuale credito nella tabella parametri liquidazione dell'anno successivo
 | ||
|       const real riporto = credito_utilizzabile - risultato;
 | ||
|       if (riporto >= ZERO) // Risultato a credito
 | ||
|       {
 | ||
|         const int anno_prossimo = atoi(_year) + 1;
 | ||
|         if (look_lia(0l, TRUE, anno_prossimo))
 | ||
|         {                                  
 | ||
|           _lia->put("R0", riporto); 
 | ||
|           _lia->rewrite(); 
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     // ciapa
 | ||
|   }
 | ||
| 
 | ||
|   _lim->rewrite();           
 | ||
|   _lam->rewrite();           
 | ||
| }
 | ||
| 
 | ||
| void TLiquidazione_app::recalc_annual(const char* att)
 | ||
| {
 | ||
|   // viene chiamata 2 volte per le att.  miste; PLA e' stata
 | ||
|   // azzerata dove serve da update_firm se siamo all'annuale
 | ||
|   real es_c1    = 0.0;
 | ||
|   real es_c2    = 0.0;
 | ||
|   real es_c3    = 0.0;
 | ||
|   real es_c1a   = 0.0;
 | ||
|   real es_c3_am = 0.0;
 | ||
|   real es_c1a_am= 0.0;
 | ||
|   real cess_amm = 0.0;
 | ||
|   real vendite  = 0.0;
 | ||
|   real pro_pag  = 0.0;
 | ||
|   real iva_acq  = 0.0;
 | ||
|   real ven_lrd  = 0.0;  
 | ||
|   real volaff1  = 0.0;
 | ||
|   real volaff2  = 0.0;
 | ||
|   real imp_ifs  = 0.0;
 | ||
|   real imp_af   = 0.0;
 | ||
|   real imp_va7  = 0.0;
 | ||
|   TString16 codiva,reg,tiva;
 | ||
|   TToken_string va7("",'!');
 | ||
|   
 | ||
|   int tipoatt = att[strlen(att) -1] - '0';
 | ||
|   TString aaa(att);
 | ||
|   
 | ||
|   look_pla(aaa);
 | ||
|   volaff1  = _pla->get_real("R14");
 | ||
|   volaff2  = (const char*)_pla->get("S1");
 | ||
|   vendite  = _pla->get_real("R0");
 | ||
|   es_c1    = _pla->get_real("R1");
 | ||
|   es_c2    = _pla->get_real("R2");
 | ||
|   es_c3    = _pla->get_real("R3");
 | ||
|   es_c1a   = _pla->get_real("R15");
 | ||
|   es_c3_am = _pla->get_real("R16");
 | ||
|   es_c1a_am= _pla->get_real("R17");
 | ||
|   cess_amm = _pla->get_real("R4");  
 | ||
|   pro_pag  = _pla->get_real("R12");
 | ||
|   iva_acq  = _pla->get_real("R11");
 | ||
|   
 | ||
|   // Per avere un risultato corretto, si deve totalizzare PIM->R3 per codice iva
 | ||
|   // e quindi effettuare lo scorporo dell'imponibile e aggiungere al relativo volume d'affari
 | ||
|   TAssoc_array corr_ann;
 | ||
|   _CorrItem *cc;
 | ||
|   bool is_key;
 | ||
|   
 | ||
|   for (_pim->first(); !_pim->eof(); _pim->next())
 | ||
|   {           
 | ||
|     if (_year != *_pim_anno || _month != atoi(*_pim_mese)) // In questo caso _month vale sempre 13
 | ||
|       continue;
 | ||
|     
 | ||
|     int tipocr = atoi(*_pim_tipocr);
 | ||
|     codiva = *_pim_codiva;
 | ||
|     reg    = *_pim_codreg;      
 | ||
|     look_iva(codiva); look_reg(reg);  
 | ||
|     tiva = _iva->get("S1");
 | ||
|     const bool b3 = _iva->get("S2") == "B3" && atoi(_year) < 1998;
 | ||
|     tiporeg   treg = (tiporeg)_reg->get_long("I0");
 | ||
|     const bool corrisp = _reg->get_bool("B0");
 | ||
|     const tipo_sospensione simp  = _reg->get_bool("B1") ? (tipo_sospensione) _reg->get_int("I9") : nessuna;
 | ||
|     imp_ifs = _pim->get_real("R0");
 | ||
|     imp_af  = _pim->get_real("R7");
 | ||
|     va7     = _pim->get("S0");
 | ||
|     imp_va7 = va7.get(0);
 | ||
|     imp_ifs -= imp_af + imp_va7; // Toglie le autofatture e le op. VA7
 | ||
| 
 | ||
|     if (                                        // ESCLUSI:      
 | ||
|         strcmp(att,*_pim_codatt) != 0   ||
 | ||
|         treg != vendita                 || //   non vendite
 | ||
|         tipocr == 4                     || //   cessioni beni ammortizzabili
 | ||
|         tiva == "NS"                    || //   non soggetti
 | ||
|         b3                              || //   bi tre
 | ||
|         simp == normale                 || 
 | ||
|         simp == liquidazione)              //   sospensione di imposta 
 | ||
|       continue;
 | ||
|    
 | ||
|     if  (corrisp)
 | ||
|     {
 | ||
|       imp_ifs += _pim->get_real("R5"); // Se corrisp. aggiunge le FS
 | ||
|       is_key =  corr_ann.is_key(codiva);
 | ||
|       if (!is_key) // Aggiunge se non esiste
 | ||
|         corr_ann.add(codiva, (_CorrItem*) new _CorrItem,is_key);
 | ||
|       _CorrItem& ca = (_CorrItem&) corr_ann[codiva];
 | ||
|       ca._totale += _pim->get_real("R3");
 | ||
|       if (!is_key) // se non c'e' lo aggiunge
 | ||
|         ca._aliquota = _iva->get_real("R0")/CENTO; // Se e' nuovo setta l'aliquota
 | ||
|     }
 | ||
|     if (tipoatt == 1)
 | ||
|      volaff1 += imp_ifs;
 | ||
|     else
 | ||
|      volaff2 += imp_ifs;
 | ||
|   }
 | ||
|   
 | ||
|   // Ora si scorporano i corrispettivi raggruppati per codice IVA  e si totalizzano gli imponibili
 | ||
|   // calcolati, da aggiungere poi a volaff1 o volaff2
 | ||
|   real imp,iva;
 | ||
|   for (cc = (_CorrItem *)corr_ann.first_item(); cc != NULL; cc = (_CorrItem *)corr_ann.succ_item())
 | ||
|   {
 | ||
|     lordo2netto(cc->_totale,imp,iva,cc->_aliquota);
 | ||
|     if (tipoatt == 1)
 | ||
|       volaff1 += imp;
 | ||
|     else 
 | ||
|       volaff2 += imp;
 | ||
|   } 
 | ||
|   
 | ||
|   // calcola esenti, cessioni, lordo vendite, prorata pagato
 | ||
|   // e IVA acquisti dai plm/ptm/pum/pam/pom 
 | ||
|   
 | ||
|   for (int i = 1; i <= 12; i++)
 | ||
|   {
 | ||
|     if (!look_plm(i,aaa))
 | ||
|       continue;
 | ||
| 
 | ||
|     pro_pag   += _plm->get_real("R2"); // Can't do anyway else...
 | ||
|   }
 | ||
|   
 | ||
|   // Modifiche per PIM13
 | ||
|   if (look_plm(13,aaa))
 | ||
|   {
 | ||
|     vendite   += _pam->get_real("R1");
 | ||
|     iva_acq   += _plm->get_real("R1");
 | ||
|     es_c1     += _pum->get_real("R4");
 | ||
|     es_c2     += _pum->get_real("R5");
 | ||
|     es_c3     += _pum->get_real("R6");
 | ||
|     es_c1a    += _pum->get_real("R13");
 | ||
|     es_c3_am  += _pum->get_real("S4");
 | ||
|     es_c1a_am += _pum->get_real("S5");
 | ||
|     cess_amm  += _pum->get_real("R0"); 
 | ||
| 
 | ||
|     // Nota: 
 | ||
|     // l'iva acquisti del mese 13 memorizzata in PLM->R1, e' si' la sommatoria
 | ||
|     // di tutte le imposte relative agli acquisti di tutti i mesi, ma andrebbe sottratto il
 | ||
|     // totale prorata pagato (pro_pag), reperibile dai mesi precedenti (PLM->R2)
 | ||
|     //real iv = _plm->get_real("R1"); // Iva acquisti annuale
 | ||
|     //iv -= pro_pag;      
 | ||
|     iva_acq -= pro_pag; // Si sottraggano i prorata pagati
 | ||
|     //_plm->put("R1",iva_acq); // Si riscriva il tutto
 | ||
|     //_plm->rewrite();
 | ||
|   }
 | ||
|                              
 | ||
|   _pla->put("R0",  vendite);
 | ||
|   _pla->put("R1",  es_c1);
 | ||
|   _pla->put("R2",  es_c2);
 | ||
|   _pla->put("R3",  es_c3);
 | ||
|   _pla->put("R15", es_c1a);
 | ||
|   _pla->put("R16", es_c3_am);
 | ||
|   _pla->put("R17", es_c1a_am);
 | ||
|   _pla->put("R4",  cess_amm);
 | ||
|   _pla->put("R11", iva_acq);
 | ||
|   _pla->put("R12", pro_pag);
 | ||
|   _pla->put("R14", volaff1);      
 | ||
|   _pla->put("S1",  volaff2.string());      
 | ||
|   _pla->rewrite();
 | ||
| }
 |