Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
cg2100k.uml     Tolta ultima riga commentata
cg2102.cpp      Sosotituito TConto con TBill
cg2105.cpp      Riga vuota
cg4301.cpp      aggiunto cast a real in una somma di stringa+real
                metodo TProrata_item::flag() in TProrata_item::previous_ok()
cg4400.cpp      Corretto data.ok in data.ok()
cg4600.cpp      Migliorati messaggi d'errore
cg4600a.uml     Aggiunto ADD RUN
git-svn-id: svn://10.65.10.50/trunk@7016 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
	
			
		
			
				
	
	
		
			2981 lines
		
	
	
		
			101 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			2981 lines
		
	
	
		
			101 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// ------------------------------------------------------------
 | 
						|
// Calcolo liquidazioni
 | 
						|
// Part 2: calcolo 
 | 
						|
// fv 21-1-94
 | 
						|
// ------------------------------------------------------------
 | 
						|
 | 
						|
#include <config.h>
 | 
						|
#include <os_dep.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>
 | 
						|
 | 
						|
// -------------------- 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 ? 
 | 
						|
                        "       Stampa liquidazione...     \n"
 | 
						|
                        "       Preparazione archivi      \n"
 | 
						|
                        "                                    " : 
 | 
						|
                        "       Calcolo liquidazione...     \n"
 | 
						|
                        "       Preparazione archivi      \n"
 | 
						|
                        "                                    ",
 | 
						|
                        TRUE,TRUE,45);
 | 
						|
 | 
						|
  for (int l = 0; l < _ditte->items(); l++)
 | 
						|
  {                           
 | 
						|
    if (_prind->iscancelled())
 | 
						|
      break;
 | 
						|
 | 
						|
    if (_selected[(long)l])
 | 
						|
    {                                     
 | 
						|
      TToken_string& nomeditta = _ditte->row(l);
 | 
						|
      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",nomeditta.get_long(1));
 | 
						|
      _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");
 | 
						|
      TLocalisamfile& atts = _nditte->lfile(LF_ATTIV);
 | 
						|
      atts.zero();
 | 
						|
      atts.put("CODDITTA",nomeditta.get_long(1));
 | 
						|
      atts.put("CODATT",  attprev);
 | 
						|
      if (atts.read() != NOERR) atts.zero();
 | 
						|
      // 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(nomeditta.get_long(1));
 | 
						|
      _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("Alcuni mesi precedenti non "
 | 
						|
               "risultano ricalcolati. E' consigliabile il ricalcolo. "
 | 
						|
               "Si desidera eseguirlo?"))
 | 
						|
            _recalc = ever;
 | 
						|
       }         
 | 
						|
       
 | 
						|
       for (int 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.
 | 
						|
 | 
						|
  look_lim(liq_month(month), TRUE);
 | 
						|
 | 
						|
  {
 | 
						|
    TConfig cnf(CONFIG_DITTA, "cg");
 | 
						|
    
 | 
						|
    _isdiffacc = is_differita();
 | 
						|
    _isdifferita = _isdiffacc;
 | 
						|
    _isintr      = !cnf.get_bool("InTrTr") && _freqviva != "M";
 | 
						|
    if (_isbenzinaro)
 | 
						|
      _gest4 = cnf.get_bool("GesT74");
 | 
						|
    // controlla che il periodo corrente non sia l'inizio dell'attivita'
 | 
						|
    // nel caso, differita va a FALSE                  
 | 
						|
    _monthinatt = 1;
 | 
						|
  }
 | 
						|
  TDate inatt(_nditte->lfile().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
 | 
						|
    {
 | 
						|
      TString16 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 ? "Stampa liquidazione (%d)...\n%s: %s\n" : 
 | 
						|
               "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++)
 | 
						|
      {
 | 
						|
        TString 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";
 | 
						|
          
 | 
						|
          TString yr(_year);
 | 
						|
          real pr1        = _pla->get_real("R8");    // Percentuale prorata anno attuale
 | 
						|
          const int anno  = atoi(_year);
 | 
						|
          _year.format("%d", anno - 1);
 | 
						|
          const bool flag = look_pla(cattiv, FALSE); // Reperisce percentuale prorata anno precedente
 | 
						|
          real pr2        = _pla->get_real("R8");
 | 
						|
          _year = yr;     // Risetta l'anno corretto e riposiziona la tabella...
 | 
						|
          look_pla(cattiv, FALSE);
 | 
						|
          _prorata.set(anno, pr1, pr2, flag);
 | 
						|
        }
 | 
						|
        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) > 1997;
 | 
						|
        _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("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("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())
 | 
						|
      {
 | 
						|
        int       m = atoi(*_pia_mese);
 | 
						|
        TString 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 acquisti_iva_annoprec
 | 
						|
                        = 0.0;
 | 
						|
  real vendite          = 0.0;
 | 
						|
  real vendite_iva      = 0.0;
 | 
						|
  real esenti_b1        = 0.0;
 | 
						|
  real esenti_b2        = 0.0;
 | 
						|
  real esenti_b3        = 0.0;
 | 
						|
  real esenti_b14       = 0.0;          
 | 
						|
  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 bdog_imp         = 0.0;
 | 
						|
  real bdog_iva         = 0.0;
 | 
						|
  real agr_imp          = 0.0;
 | 
						|
  real agr_iva          = 0.0;
 | 
						|
  
 | 
						|
  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, 1, year_int); // Per le agenzie di viaggio si parte da inizio anno (sempre)
 | 
						|
  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.
 | 
						|
  if (!_isviaggio)
 | 
						|
    f.set_month(month == 13 ? 1 : month);
 | 
						|
  
 | 
						|
  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->setregion(from, to);
 | 
						|
  
 | 
						|
  *_cur      = 0;
 | 
						|
 | 
						|
  long items = _cur->items();
 | 
						|
  TString      trueatt(codatt); 
 | 
						|
  int tipatt = atoi(trueatt.sub(5));
 | 
						|
  //trueatt    = trueatt.left(5);
 | 
						|
  trueatt.cut(5);
 | 
						|
#ifdef DBG
 | 
						|
  TString msgdbg;
 | 
						|
  long freespace;
 | 
						|
#endif  
 | 
						|
 | 
						|
  for (; _cur->pos() < items; ++(*_cur))
 | 
						|
  {                               
 | 
						|
    if ((_cur->pos() & 0x7F) == 0)
 | 
						|
    {
 | 
						|
#ifdef DBG
 | 
						|
      msgdbg.format("Ricalcolo attivita': %ld/%ld",_cur->pos(),items);
 | 
						|
      freespace = os_get_free_memory();
 | 
						|
      msgdbg << " Memoria libera: " << freespace/1024 << " Kbytes.";
 | 
						|
      xvt_statbar_set(msgdbg);
 | 
						|
#endif  
 | 
						|
      do_events();
 | 
						|
    }
 | 
						|
    
 | 
						|
    TDate date(_mov->get(MOV_DATAREG));
 | 
						|
    const int liqmonth = _mov->get_int(MOV_MESELIQ);
 | 
						|
    TString16 reg      = _mov->get("REG");
 | 
						|
    bool isreg         = look_reg(_mov->get("REG"));
 | 
						|
    TString16 tipodoc  = _mov->get(MOV_TIPODOC);
 | 
						|
    bool    corrisp    = _reg->get_bool("B0");  
 | 
						|
    tiporeg tipomov    = (tiporeg)_reg->get_long("I0");
 | 
						|
    // Controlla se la data del documento si riferisce all'anno precedente (PRORATA 1998)
 | 
						|
    TDate datedoc(_mov->get(MOV_DATADOC));
 | 
						|
    bool anno_doc_prec = (year_int > 1997) && (datedoc.year() == year_int - 1);
 | 
						|
    
 | 
						|
    if (_isviaggio && tipomov == vendita && !(_mov->get(MOV_DATA74TER).empty())) 
 | 
						|
      date = _mov->get_date(MOV_DATA74TER);
 | 
						|
      
 | 
						|
    /*
 | 
						|
     * 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);
 | 
						|
    const bool sosp_imp = _reg->get_bool("B1");
 | 
						|
    const TRectype& rcs = _cur->curr(LF_CAUSALI);
 | 
						|
    const bool fattrit  = rcs.get_bool("RITFATT");
 | 
						|
    
 | 
						|
    if (dok || sreg || rs8 || cmt) continue;
 | 
						|
    
 | 
						|
    /*
 | 
						|
     * 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
 | 
						|
    {     
 | 
						|
      look_iva(_rmoviva->get(RMI_CODIVA));
 | 
						|
 | 
						|
      // 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
 | 
						|
      
 | 
						|
      TString codiva     = _iva->get("CODTAB");
 | 
						|
      TString tipoiva    = _iva->get("S1");
 | 
						|
      TString tipoes_v   = _iva->get("S2");
 | 
						|
      TString tipoes_a   = _iva->get("S9");
 | 
						|
      int     tipoagr    = atoi(_iva->get("S4"));
 | 
						|
      int     tipoag     = atoi(_iva->get("S5"));
 | 
						|
      int     tipopla    = atoi(_iva->get("S3"));
 | 
						|
      int     tipodet    = atoi(_rmoviva->get(RMI_TIPODET));
 | 
						|
      int     isrimbinfr = _iva->get_bool("B3");     // vale per calcolo rimborso se ES o NI
 | 
						|
      int     ivarimb    = !_iva->get_bool("B4");    // non escluso calcolo rimb. per al. media
 | 
						|
      TString tipocr_s   = _rmoviva->get(RMI_TIPOCR);       
 | 
						|
      int     tipocr     = atoi(tipocr_s);        
 | 
						|
      real    imponibile = _rmoviva->get_real(RMI_IMPONIBILE);
 | 
						|
      real    imposta    = _rmoviva->get_real(RMI_IMPOSTA);
 | 
						|
      bool    intra      = _rmoviva->get_bool(RMI_INTRA);
 | 
						|
      int     tipoatt    = _rmoviva->get_int(RMI_TIPOATT);
 | 
						|
      // autofatture art. 17 per non residenti, con trattamento
 | 
						|
      // speciale in liquidazione annuale
 | 
						|
      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)
 | 
						|
      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
 | 
						|
      bool    was_riv = FALSE;
 | 
						|
      /*
 | 
						|
       * puo' capitare per motivi brutalmente prassici
 | 
						|
       * SENSU Sergio 1995, Guido
 | 
						|
       */
 | 
						|
      if (tipoatt == 0) tipoatt = 1;
 | 
						|
      
 | 
						|
      if(tipoatt != tipatt) 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);
 | 
						|
        
 | 
						|
      if (noninc)   // non incassati: non devono entrare in nessun altro calcolo
 | 
						|
      {              
 | 
						|
        nin_imp = imponibile;
 | 
						|
        nin_iva = imposta;
 | 
						|
      }
 | 
						|
      else if (sosp_imp)    // sospensione di imposta
 | 
						|
      {
 | 
						|
        if (tipomov == vendita)
 | 
						|
        {
 | 
						|
          vsimp_imp = imponibile;
 | 
						|
          vsimp_iva = imposta;
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          asimp_imp = imponibile;
 | 
						|
          asimp_iva = imposta;
 | 
						|
        }       
 | 
						|
        assp_imp += asimp_imp;
 | 
						|
        assp_iva += asimp_iva;
 | 
						|
        vssp_imp += vsimp_imp;
 | 
						|
        vssp_iva += vsimp_iva;
 | 
						|
      }
 | 
						|
      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;
 | 
						|
                  was_riv      = TRUE;
 | 
						|
                }
 | 
						|
                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);
 | 
						|
                }
 | 
						|
                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 (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 (tipoes_v == "B1")
 | 
						|
              esenti_b1 += imponibile; 
 | 
						|
            else if (tipoes_v == "B2")
 | 
						|
              esenti_b2 += imponibile; 
 | 
						|
            else if (tipoes_v == "B3") 
 | 
						|
              esenti_b3 += 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 = _iva->get_real("R0") / CENTO;
 | 
						|
              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
 | 
						|
       */
 | 
						|
      bool ign = sosp_imp || (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);
 | 
						|
      
 | 
						|
 | 
						|
 | 
						|
      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;
 | 
						|
        if (anno_doc_prec) // Se abilitato, somma l'iva acquisti relativi a documenti anno precedente
 | 
						|
          acquisti_iva_annoprec += 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
 | 
						|
          {
 | 
						|
            real perc = _iva->get_real("R0")/CENTO;
 | 
						|
            lor += imponibile + imposta;   
 | 
						|
            lorcor += imponibile+imposta;
 | 
						|
            real tot = imponibile+imposta;   
 | 
						|
            if (liq) add_corrisp(month, reg, tot, perc, 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);
 | 
						|
      }
 | 
						|
 | 
						|
      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 i,v;
 | 
						|
        TToken_string kr(tab->get("S0"),'!'); 
 | 
						|
        i = real(kr.get(0)) + va7i;
 | 
						|
        v = real(kr.get(1)) + va7v;
 | 
						|
        kr.add(i.string(), 0);
 | 
						|
        kr.add(v.string(), 1);
 | 
						|
        tab->put("S0",kr);
 | 
						|
                           
 | 
						|
        // fatture in ritardo                     
 | 
						|
        TToken_string fr(tab->get("S1"),'!'); 
 | 
						|
        i = real(fr.get(0)) + rti;
 | 
						|
        v = real(fr.get(1)) + rtv;
 | 
						|
        fr.add(i.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"),'!'); 
 | 
						|
        i = real(cs.get(0)) + csi;
 | 
						|
        v = real(cs.get(1)) + csv;
 | 
						|
        cs.add(i.string(), 0);
 | 
						|
        cs.add(v.string(), 1);
 | 
						|
        tab->put("S2",cs);
 | 
						|
        
 | 
						|
        tab->rewrite(); // rewrite current table 
 | 
						|
      } // for per tabelle
 | 
						|
    }
 | 
						|
    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; 
 | 
						|
          new_iva.ceil(ROUND_LIRA);  // TBC check ceil
 | 
						|
          
 | 
						|
          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; 
 | 
						|
          iva.ceil(ROUND_LIRA);
 | 
						|
          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_precedente; 
 | 
						|
    if (month != 13)
 | 
						|
    {
 | 
						|
      const real& current  = _prorata.current();
 | 
						|
      const real& previous = _prorata.previous();
 | 
						|
      bool b = TRUE;
 | 
						|
 | 
						|
      if (!_prorata.previous_ok() || (previous == current && _prorata.previous_ok())) // Se le percentuali sono uguali 
 | 
						|
        b = FALSE;                                                      // o non esiste la tabella prec. 
 | 
						|
                                                                        // considera tutto sull'anno corrente
 | 
						|
                                      
 | 
						|
      const real acq_res = acquisti_iva - (b ? acquisti_iva_annoprec : ZERO);
 | 
						|
 | 
						|
      if (!current.is_zero())
 | 
						|
        prorata   = _prorata.calc_prorata(acq_res);
 | 
						|
 | 
						|
      if (!previous.is_zero() && b)
 | 
						|
      {
 | 
						|
        prorata_precedente = _prorata.calc_prorata(acquisti_iva_annoprec, FALSE);
 | 
						|
        prorata += prorata_precedente;
 | 
						|
      }
 | 
						|
      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. anno precedente)
 | 
						|
    _plm->put("R14", prorata_precedente); // Prorata acq. rif. anno precedente (in stampa prorata attuale sara' totale - precedente)
 | 
						|
  
 | 
						|
    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;
 | 
						|
        acquisti_iva.round(ROUND_LIRA);
 | 
						|
      }
 | 
						|
      
 | 
						|
      if (_isagr98)
 | 
						|
      {
 | 
						|
        _plm->put("R13", agr_detIA); 
 | 
						|
        acquisti_iva += agr_detIA;
 | 
						|
      }
 | 
						|
    }
 | 
						|
  
 | 
						|
    _plm->put("R0",  vendite_iva);
 | 
						|
    _plm->put("R1",  acquisti_iva);
 | 
						|
    _plm->put("R3",  ult_detr);
 | 
						|
    _plm->put("R4",  _prorata.previous()); // per comodita' in stampa
 | 
						|
    _plm->put("R12", _prorata.current());  // per comodita' in stampa
 | 
						|
    _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
 | 
						|
    _plm->put("B1",  !_prorata.previous_ok() && acquisti_iva_annoprec != ZERO && year_int > 1997);
 | 
						|
    _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_b1);
 | 
						|
    _pum->put("R5",  esenti_b2);
 | 
						|
    _pum->put("R6",  esenti_b3);
 | 
						|
    _pum->put("R7",  esenti_b14); 
 | 
						|
    _pum->put("R12", esni_rimb);
 | 
						|
    _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);  
 | 
						|
    
 | 
						|
    _plm->rewrite();
 | 
						|
    _pam->rewrite();
 | 
						|
    _pum->rewrite();
 | 
						|
    _pom->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 TString16 tipodoc  = _mov->get(MOV_TIPODOC);
 | 
						|
  const bool    intra      = _rmoviva->get_bool(RMI_INTRA);
 | 
						|
  const int     tipocr     = _rmoviva->get_int(RMI_TIPOCR);       
 | 
						|
  const int     tipodet    = _rmoviva->get_int(RMI_TIPODET);
 | 
						|
  real  imponibile         = _rmoviva->get_real(RMI_IMPONIBILE);
 | 
						|
  real  imposta            = _rmoviva->get_real(RMI_IMPOSTA);
 | 
						|
  const TString16 codiva   = _iva->get("CODTAB");
 | 
						|
  const TString 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    = atoi(_iva->get("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 bool sosp_imp      = _reg->get_bool("B1");
 | 
						|
  const bool corrisp       = _reg->get_bool("B0");
 | 
						|
  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 && tipodet == 0 && (tipocr == 2 || tipocr == 8))
 | 
						|
    {
 | 
						|
      array.add(imposta,TAB11_R6,LF_TAB1100B); 
 | 
						|
    }
 | 
						|
    
 | 
						|
    if (!sosp_imp)
 | 
						|
    {
 | 
						|
      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)
 | 
						|
        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 && 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("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 char* tmpatt;     
 | 
						|
  const int year_int = atoi(_year);
 | 
						|
  
 | 
						|
  if (_ver->read(atoi(_year),_month)!=NOERR)
 | 
						|
    warning_box("Errore %d in lettura tabella versamenti ed interessi.",_ver->status());
 | 
						|
  // evita casino se differita ma si sta ricalcolando il primo
 | 
						|
  // mese con ricalcolo di piu' mesi
 | 
						|
  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;
 | 
						|
                
 | 
						|
  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;
 | 
						|
  
 | 
						|
  // 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'
 | 
						|
  
 | 
						|
  TLocalisamfile& attiv = _nditte->lfile(LF_ATTIV);
 | 
						|
  
 | 
						|
  while ((tmpatt = atts.get()) != NULL)
 | 
						|
  {
 | 
						|
    TString 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;
 | 
						|
      TString yr(_year);
 | 
						|
      _year.format("%d", year_int-1);
 | 
						|
      if (!look_lim(12)) //controlla solamente, il vero posizionamento lo fa dopo
 | 
						|
      { 
 | 
						|
        _year = yr; 
 | 
						|
        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)
 | 
						|
      {
 | 
						|
        risultato += _lim->get_real("R1"); 
 | 
						|
        rimborsi  += _lim->get_real("R1"); 
 | 
						|
        res_debt  += _lim->get_real("R1");
 | 
						|
      }                               
 | 
						|
      
 | 
						|
      /*
 | 
						|
       * rettifiche gia' col loro bravo segno
 | 
						|
       */
 | 
						|
      if (attc == 0 && is_lim)
 | 
						|
      {
 | 
						|
        // 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   
 | 
						|
        TString descrett(_lim->get("S0"));
 | 
						|
        bool isforbenzinaro = descrett[0] == '$' ||
 | 
						|
                              (descrett[0] == '>' && descrett[1] == '>');
 | 
						|
                                
 | 
						|
        if (/*(isforbenzinaro && _isannual) ||  ...alla cincia quest'idea non piaceva piu'
 | 
						|
            (!isforbenzinaro && !_isannual)    adesso la storia e' cosi':
 | 
						|
             in ANNUALE solo se benzinaro, altrimenti niente; diversamente tutto*/
 | 
						|
            !(month == 13 && !isforbenzinaro) && m < 13)  
 | 
						|
        {
 | 
						|
          risultato  += _lim->get_real("R5"); 
 | 
						|
          rettifiche += _lim->get_real("R5"); 
 | 
						|
          if (_lim->get_real("R5").sign() < 0)
 | 
						|
            res_cred += abs(_lim->get_real("R5"));
 | 
						|
          else
 | 
						|
            res_debt += abs(_lim->get_real("R5"));
 | 
						|
        }
 | 
						|
      }
 | 
						|
    } // 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 * CENTO)/(a_mCEE + a_meCEE); perc_r.round(2);
 | 
						|
        real ivm = (c_mCEE * perc_r)/CENTO; ivm.round(ROUND_LIRA);
 | 
						|
        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); 
 | 
						|
          cred_cost.round(ROUND_LIRA);
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          deb_mens    = (bi /((CENTO + aliquota_agvia())/CENTO)) *
 | 
						|
                        (aliquota_agvia()/CENTO);
 | 
						|
          deb_mens.ceil(ROUND_LIRA);   // 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 /(imp_agr1 + imp_agr2);
 | 
						|
      perc.round(2);
 | 
						|
      iva_ded = acq_noCEE * perc;
 | 
						|
      iva_ded.round(ROUND_LIRA);
 | 
						|
      iva_acq   += iva_ded;
 | 
						|
      res_debt  += iva_vend;
 | 
						|
      res_cred  += iva_acq;
 | 
						|
      risultato += (iva_vend - iva_acq);
 | 
						|
    } // __ end of agricolo
 | 
						|
  } // end ciclo su attivita'
 | 
						|
  
 | 
						|
  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;
 | 
						|
  }
 | 
						|
  else 
 | 
						|
  { 
 | 
						|
    // per l'annuale considera solo il credito a inizio anno
 | 
						|
//    const real cred_res = _lia->get_real("R15");
 | 
						|
    cred_prec = credito_prec(_freqviva == "M" ? 1 : 3);
 | 
						|
//    cred_trasf= cred_res > ZERO ? cred_res - cred_prec : ZERO; vacca la pt
 | 
						|
    cred_trasf = _lia->get_real("R15");        
 | 
						|
    const real cred_res = cred_prec - cred_trasf;
 | 
						|
//    risultato -=  cred_prec - cred_trasf; 
 | 
						|
//    res_cred  +=  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_b1 = _pla->get_real("R1");
 | 
						|
        real es_b2 = _pla->get_real("R2");
 | 
						|
        real es_b3 = _pla->get_real("R3");
 | 
						|
        real csamm = _pla->get_real("R4");
 | 
						|
        
 | 
						|
        // calcola nuovo prorata per ogni attivita' (miste: 1+2)
 | 
						|
        real ris = vol_aff_t;  // gia' esclusi: NS, B3, cess. amm
 | 
						|
        real prorata(0.0); 
 | 
						|
        if (!ris.is_zero())
 | 
						|
          prorata = (es_b1/ris) * CENTO;
 | 
						|
        real conguaglio = 0.0;
 | 
						|
        real topay      = 0.0;
 | 
						|
        prorata.round(ROUND_LIRA);
 | 
						|
        //if (prorata != _prorata.current())
 | 
						|
        {
 | 
						|
          // calcolo conguaglio -- se positivo e' a debito
 | 
						|
          if (prorata > 0.0)
 | 
						|
          {
 | 
						|
            topay = (iaq + ppg) * (prorata / CENTO); 
 | 
						|
            //topay.round(ROUND_MILLELIRE);
 | 
						|
            round_mille_lire(topay);
 | 
						|
          }
 | 
						|
          conguaglio = topay - ppg;
 | 
						|
          //conguaglio.round(ROUND_MILLELIRE);
 | 
						|
          round_mille_lire(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
 | 
						|
        TString yr = _year;
 | 
						|
        _year.format("%d", atoi(_year) + 1);
 | 
						|
        look_pla(att, TRUE);
 | 
						|
        _pla->put("R8", prorata);
 | 
						|
        _pla->rewrite();
 | 
						|
        if (look_lia(0l, TRUE))
 | 
						|
        {
 | 
						|
          _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 (tot_cong.sign() > 0) res_debt += tot_cong;
 | 
						|
  if (tot_cong.sign() < 0) res_cred += abs(tot_cong);
 | 
						|
                
 | 
						|
  look_lim(month+deltam,TRUE);       
 | 
						|
  // azzeriamo tutto (tranne r1, r5, s1, s0, s7)
 | 
						|
  TString codtab = _lim->get("CODTAB");
 | 
						|
 | 
						|
  real    r5 = _lim->get("R5");
 | 
						|
  real    r1 = _lim->get("R1");
 | 
						|
  TString s7 = _lim->get("S7");  
 | 
						|
  TString s0 = _lim->get("S0");  
 | 
						|
  TString s1 = _lim->get("S1");  
 | 
						|
  bool wasb0 = _lim->get_bool("B0");
 | 
						|
  bool wasb1 = _lim->get_bool("B1");
 | 
						|
 | 
						|
  _lim->zero();
 | 
						|
  _lim->put("CODTAB", codtab);
 | 
						|
  _lim->put("R1", r1);  
 | 
						|
  _lim->put("R5", r5);  
 | 
						|
  _lim->put("S0", s0);  
 | 
						|
  _lim->put("S1", s1);  
 | 
						|
  _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'
 | 
						|
      (month == 12 && _isbenzinaro && _gest4) ||    //essere differita
 | 
						|
      (month == 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
 | 
						|
  risultato.round(ROUND_LIRA);
 | 
						|
                                
 | 
						|
  _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)
 | 
						|
  {
 | 
						|
    // scrivi totali rettifiche e rimborsi
 | 
						|
    // nella finale oppure se copiati da
 | 
						|
    // anno precedente
 | 
						|
    _lim->put("R1",rimborsi);
 | 
						|
    _lim->put("R5",rettifiche);
 | 
						|
  }
 | 
						|
                                 
 | 
						|
  /*
 | 
						|
   * 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)) ))
 | 
						|
  {
 | 
						|
    real interesse = interesse_trimestrale(_month);
 | 
						|
    real ivi = risultato * (interesse / CENTO); 
 | 
						|
    ivi.ceil(ROUND_LIRA);
 | 
						|
    _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));       
 | 
						|
  
 | 
						|
  // totale conguaglio su tutte le attivita'
 | 
						|
  _lim->put("R7",  tot_cong);
 | 
						|
  _lim->put("R8",  versamenti);
 | 
						|
  _lim->put("R9",  vers_int);
 | 
						|
  _lam->put("R0",  iva_vend);
 | 
						|
  _lam->put("R1",  iva_acq);
 | 
						|
  _lam->put("R2",  cred_prec);
 | 
						|
  _lam->put("R3",  debt_precd);
 | 
						|
  _lim->put("R11", acc_dec);
 | 
						|
  _lim->put("R12", res_cred);  
 | 
						|
  _lim->put("R13", res_debt);  
 | 
						|
  
 | 
						|
  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");
 | 
						|
  
 | 
						|
  if (wasdifferita) _isdifferita = TRUE;
 | 
						|
 | 
						|
  // AWFUL! se siamo in annuale, occorre arrotondare alle 1000 lire
 | 
						|
  // TUTTI gli ADDENDI e non il risultato. Cio' e' disonesto e mostruoso;
 | 
						|
  // siccome sa di ricorso al TAR nonche' di errore della Prassi
 | 
						|
  // schiaffo tutto il codice nell'IF che segue, e se lo si vuole togliere
 | 
						|
  // non si fara' che scancellare tutto il blocco
 | 
						|
  if (month == 13)
 | 
						|
  {
 | 
						|
    // molto codice duplicato, ma ne val la pena (vedi sopra)
 | 
						|
    round_mille_lire(iva_vend);
 | 
						|
    round_mille_lire(iva_acq);
 | 
						|
    round_mille_lire(detrazioni);
 | 
						|
    round_mille_lire(versamenti);
 | 
						|
    round_mille_lire(vers_int);
 | 
						|
    round_mille_lire(rimborsi);
 | 
						|
    round_mille_lire(rettifiche);
 | 
						|
    round_mille_lire(deb_mens);
 | 
						|
    round_mille_lire(cred_prec);
 | 
						|
    round_mille_lire(cred_trasf);
 | 
						|
    round_mille_lire(tot_cong);
 | 
						|
    round_mille_lire(acc_dec);
 | 
						|
    round_mille_lire(debt_precd);
 | 
						|
    
 | 
						|
 | 
						|
//    res_cred  = iva_acq + versamenti + vers_int + cred_prec + cred_trasf + acc_dec;
 | 
						|
    res_cred  = iva_acq + versamenti + vers_int + cred_prec - cred_trasf + acc_dec;
 | 
						|
    res_debt  = iva_vend + rimborsi + debt_precd;  // Tolto la somma di deb_mens, perche' gia' presente in iva_vend
 | 
						|
    
 | 
						|
    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 (almeno_una_normale)
 | 
						|
      res_cred  += detrazioni; 
 | 
						|
 | 
						|
    risultato = res_debt - res_cred;
 | 
						|
 | 
						|
    // tut ricalcule', riscrivem
 | 
						|
    _lim->put("R0",  risultato);          
 | 
						|
    _lim->put("R2",  cred_cost); 
 | 
						|
    _lim->put("R3",  deb_mens); 
 | 
						|
    _lim->put("R1",  rimborsi);
 | 
						|
    _lim->put("R5",  rettifiche);
 | 
						|
    _lim->put("R6",  detrazioni);
 | 
						|
    _lim->put("R7",  tot_cong);
 | 
						|
    _lim->put("R8",  versamenti);
 | 
						|
    _lim->put("R9",  vers_int);
 | 
						|
    _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("R11", acc_dec);
 | 
						|
    _lim->put("R12", res_cred);  
 | 
						|
    _lim->put("R13", res_debt);       
 | 
						|
    // 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_b1    = 0.0;
 | 
						|
  real es_b2    = 0.0;
 | 
						|
  real es_b3    = 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_b1    = _pla->get_real("R1");
 | 
						|
  es_b2    = _pla->get_real("R2");
 | 
						|
  es_b3    = _pla->get_real("R3");
 | 
						|
  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";
 | 
						|
    tiporeg   treg = (tiporeg)_reg->get_long("I0");
 | 
						|
    const bool corrisp = _reg->get_bool("B0");
 | 
						|
    const bool simp = _reg->get_bool("B1");
 | 
						|
    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)                              //   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_b1     += _pum->get_real("R4");
 | 
						|
    es_b2     += _pum->get_real("R5");
 | 
						|
    es_b3     += _pum->get_real("R6");
 | 
						|
    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_b1);
 | 
						|
  _pla->put("R2",  es_b2);
 | 
						|
  _pla->put("R3",  es_b3);
 | 
						|
  _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();
 | 
						|
}
 | 
						|
 |