1415 lines
		
	
	
		
			44 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1415 lines
		
	
	
		
			44 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// ------------------------------------------------------------
 | 
						|
// Calcolo liquidazioni
 | 
						|
// Part 2: calcolo 
 | 
						|
// fv 21-1-94
 | 
						|
// ------------------------------------------------------------
 | 
						|
 | 
						|
#include <progind.h>              
 | 
						|
#include <sheet.h>
 | 
						|
#include <config.h>
 | 
						|
#include <utility.h>
 | 
						|
#include "cg4300.h"
 | 
						|
 | 
						|
// -------------------- QUI comincia l'avventura --------------------------
 | 
						|
// ----------------------------------------------------- ******************
 | 
						|
// che nel gennaio 1995 non solo non e' finita, ma si fa ******************
 | 
						|
// ogni giorno piu' odiosa e nevrastenica                ******************
 | 
						|
// ----------------------------------------------------- ******************
 | 
						|
// 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
 | 
						|
       * --------------------------------------------------------------
 | 
						|
       */
 | 
						|
      
 | 
						|
      _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();               
 | 
						|
      
 | 
						|
      // decidi per stocazzo di annuale
 | 
						|
      // per QUALSIASI annuale il mese diventa 13
 | 
						|
      _isannual    = (_month == 12 && !mens && !_isbenzinaro) || 
 | 
						|
                     (_month == 13 && (mens || _isbenzinaro));    
 | 
						|
      _isriepilogo = _month == 13 && !mens;               
 | 
						|
      if (_isannual) _month = 13;  // che ti piaccia o no
 | 
						|
      
 | 
						|
      
 | 
						|
      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, tutti se annuale
 | 
						|
       * --------------------------------------------------------------
 | 
						|
       */
 | 
						|
 | 
						|
      int need_refresh = FALSE;
 | 
						|
      if (_recalc != ever)
 | 
						|
      { 
 | 
						|
        for (int m = 1; 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_ok(m, _month) || _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 ((is_month_ok_strict(m) || m == 13) && look_lim(m))
 | 
						|
        { 
 | 
						|
          _lim->put("B0","");
 | 
						|
          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);
 | 
						|
  
 | 
						|
  if (_isregis && _lim->get_bool("B1"))  
 | 
						|
  	return TRUE;
 | 
						|
  
 | 
						|
  TConfig cnf(CONFIG_DITTA, "cg");
 | 
						|
  _isdifferita = cnf.get_bool("GeLiDi");
 | 
						|
  TConfig cnf1(CONFIG_STUDIO, "cg");
 | 
						|
  _isricacq =    cnf1.get_bool("RicAcq");
 | 
						|
 | 
						|
  // ricalcolo normale  
 | 
						|
  // TBI lim c'e' solo per i trimestri
 | 
						|
  bool ok   = _lim->get_bool("B0");
 | 
						|
  if (ok && !recalc) return TRUE; 
 | 
						|
  bool calc = (_recalc == ever || (_recalc == one && month == _month));
 | 
						|
  if (!calc && _recalc != never) calc = !ok;
 | 
						|
  bool gheravergot = FALSE;
 | 
						|
  bool quater      = FALSE;
 | 
						|
  
 | 
						|
  TToken_string atts;
 | 
						|
  TToken_string cattivs;
 | 
						|
  
 | 
						|
  _nditte->save_status();  
 | 
						|
  if (_nditte->is_first_match(LF_ATTIV))
 | 
						|
  {
 | 
						|
    char 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;
 | 
						|
      
 | 
						|
      sprintf (buf, _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);
 | 
						|
      _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");
 | 
						|
          _prorata     = _pla->get_real("R8");
 | 
						|
          _isplafond   = !(_p8.is_zero() && _p8b.is_zero() && 
 | 
						|
                           _p9.is_zero());
 | 
						|
          _isservizio  = _pla->get("S7") == "S";
 | 
						|
          _mixed       = _pla->get("S7") == "M" || _pla->get("S7") == "E";          
 | 
						|
        }
 | 
						|
        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");
 | 
						|
        _isvent = FALSE;
 | 
						|
        
 | 
						|
        if (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("S1","0|0");
 | 
						|
          _pla->put("S2","0");
 | 
						|
          _pla->put("S3","0");
 | 
						|
          _pla->rewrite();
 | 
						|
        }
 | 
						|
 | 
						|
        for (_reg->first(); !_isvent && _reg->good(); _reg->next())
 | 
						|
        {
 | 
						|
          if (codatt == _reg->get("S8") && _reg->get_int("I0") == 2)
 | 
						|
            _isvent = _reg->get_bool("B3");
 | 
						|
        }
 | 
						|
 | 
						|
        if (calc || !recalc)
 | 
						|
          if (!update_att(month, cattiv))
 | 
						|
            describe_error("Attivita' non ricalcolate: possibili errori",
 | 
						|
                           codatt);        
 | 
						|
        
 | 
						|
        // 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)
 | 
						|
          describe_att(month,cattiv,gheravergot); 
 | 
						|
        
 | 
						|
        atts.add(cattiv);
 | 
						|
        cattivs.add(cattiv);
 | 
						|
      } // for tipoatt
 | 
						|
 | 
						|
      // se attivita' mista stampa riepilogo
 | 
						|
      if (_mixed && month == _month) 
 | 
						|
        describe_att(month,cattivs, TRUE);
 | 
						|
    } 
 | 
						|
    while (_nditte->next_match(LF_ATTIV));
 | 
						|
 | 
						|
    // se quater stampa riepilogo
 | 
						|
    if (quater && month == _month) 
 | 
						|
      describe_att(month,atts, TRUE);
 | 
						|
    
 | 
						|
    // occorre poterla chiamare altre volte con mesi diversi
 | 
						|
    _nditte->restore_status();
 | 
						|
    
 | 
						|
    // aggiorna le liquidazioni
 | 
						|
    if (calc || !recalc)
 | 
						|
      if (is_month_ok_strict(month) || month == 13) 
 | 
						|
         write_liq(month, atts);
 | 
						|
    
 | 
						|
    // rimborso infraannuale
 | 
						|
    _DescrItem* rimb_d = NULL;
 | 
						|
    if (month == _month && is_trim(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);
 | 
						|
    }
 | 
						|
 | 
						|
    if (month == _month)
 | 
						|
    {
 | 
						|
      describe_firm(month);
 | 
						|
      describe_liq(_month, atts, rimb_d);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  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 (ok && !recalc) return TRUE; 
 | 
						|
  bool calc = _recalc == ever || (_recalc == one && month == _month);
 | 
						|
  if (!calc && _recalc != never) calc = !ok; 
 | 
						|
 | 
						|
  if (calc || !recalc)
 | 
						|
  {
 | 
						|
    zero_att(month,codatt);            
 | 
						|
    recalc_att(month,codatt);          
 | 
						|
    if (month == 13)
 | 
						|
     recalc_annual(codatt);
 | 
						|
    else
 | 
						|
    { 
 | 
						|
      // nei PIM della 13a vanno solo alcune stranezze,
 | 
						|
      // mi rifiuto di pensare che vadano ventilate
 | 
						|
      // o corrispettivizzicizzate
 | 
						|
      recalc_ventilation(month, codatt); 
 | 
						|
      recalc_corrispettivi(month, codatt);  
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return ok || calc;  
 | 
						|
}
 | 
						|
 | 
						|
void TLiquidazione_app::zero_att(int month, const char* codatt)
 | 
						|
{
 | 
						|
  for (_pim->first(); !_pim->eof(); _pim->next())
 | 
						|
  {
 | 
						|
    int       m = atoi(*_pim_mese);
 | 
						|
    TString att = (const char*)*_pim_codatt;
 | 
						|
    if (m == month && att == codatt)
 | 
						|
    {
 | 
						|
      _pim->put("R0","");
 | 
						|
      _pim->put("R1","");
 | 
						|
      _pim->put("R2","");
 | 
						|
      _pim->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       = 0.0;
 | 
						|
  real ammort_iva   = 0.0;
 | 
						|
  real ammort_6     = 0.0;
 | 
						|
  real ammort_6_iva = 0.0;
 | 
						|
  real acq_riv      = 0.0;
 | 
						|
  real acq_riv_iva  = 0.0;
 | 
						|
  real leasing      = 0.0;
 | 
						|
  real leasing_iva  = 0.0;
 | 
						|
  real cess_amm     = 0.0;
 | 
						|
  real cess_amm_iva = 0.0;
 | 
						|
  real acquisti     = 0.0;
 | 
						|
  real acquisti_iva = 0.0;
 | 
						|
  real vendite      = 0.0;
 | 
						|
  real vendite_iva  = 0.0;
 | 
						|
  real esenti_b1    = 0.0;
 | 
						|
  real esenti_b2    = 0.0;
 | 
						|
  real esenti_b3    = 0.0;
 | 
						|
  real esenti_b14   = 0.0;
 | 
						|
  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_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 for_rimb     = 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;
 | 
						|
  
 | 
						|
  *_cur      = 0;
 | 
						|
  long items = _cur->items();
 | 
						|
  TString      trueatt(codatt); 
 | 
						|
  int tipatt = atoi(trueatt.sub(5));
 | 
						|
  trueatt    = trueatt.left(5);
 | 
						|
 | 
						|
  for (; _cur->pos() < items; ++(*_cur))
 | 
						|
  {      
 | 
						|
    TDate date(_mov_r->get("DATAREG"));
 | 
						|
    TString16 reg    = _mov_r->get("REG");
 | 
						|
    bool isreg        = look_reg(_mov_r->get("REG"));
 | 
						|
    TString16 tipodoc = _mov_r->get("TIPODOC");
 | 
						|
    /*
 | 
						|
     * check register present, rmoviva present and date OK
 | 
						|
     */      
 | 
						|
    const bool dok = !is_date_ok(date, month);  
 | 
						|
    const bool sreg = !isreg;
 | 
						|
    const bool rs8  = _reg_r->get("S8") != trueatt;
 | 
						|
    const bool cmt  = !_cur->is_first_match(LF_RMOVIVA);
 | 
						|
    const TRectype& rcs = _cur->curr(LF_CAUSALI);
 | 
						|
    
 | 
						|
    if (dok || sreg || rs8 || cmt) continue;
 | 
						|
    
 | 
						|
    /* 
 | 
						|
     * Fatture in sospensione di imposta non vengono considerate
 | 
						|
     */
 | 
						|
    if (_reg->get_bool("B1"))
 | 
						|
      continue; 
 | 
						|
    
 | 
						|
    /*
 | 
						|
     * Tipo documento da eliminare (Scudler 1994)   
 | 
						|
     * Trattasi per lo piu' di non incassati 
 | 
						|
     */
 | 
						|
    if (tipodoc == "SN" || tipodoc == "CN" || tipodoc == "RN" ||
 | 
						|
        tipodoc == "IN" || tipodoc == "PG")
 | 
						|
      continue;
 | 
						|
    
 | 
						|
    /*
 | 
						|
     * Fatture in ritardo vengono considerate solo in dichiarazione
 | 
						|
     * annuale
 | 
						|
     */
 | 
						|
    if (month != 13 && rcs.get_bool("RITFATT")) 
 | 
						|
      continue;
 | 
						|
    
 | 
						|
    /*
 | 
						|
     * check date: se si calcola l'acconto, solo da 1/12 a 20/12
 | 
						|
     */
 | 
						|
    if (_comp_acconto && date.month() != 12 && date.day() > 20)
 | 
						|
       continue;
 | 
						|
    
 | 
						|
    bool    corrisp  = _reg_r->get_bool("B0");  
 | 
						|
    tiporeg tipomov  = (tiporeg)_reg_r->get_long("I0");
 | 
						|
    
 | 
						|
    do
 | 
						|
    {     
 | 
						|
      look_iva(_rmoviva->get("CODIVA"));
 | 
						|
 | 
						|
      TString codiva     = _iva->get("CODTAB");
 | 
						|
      TString tipoiva    = _iva->get("S1");
 | 
						|
      TString riga11_v   = _iva->get("S0");
 | 
						|
      int     tipoes_v   = (int)_iva->get_long("I3");
 | 
						|
      int     tipoes_a   = (int)_iva->get_long("I4");
 | 
						|
      int     tipoagr    = atoi(_iva->get("S4"));
 | 
						|
      int     tipoag     = atoi(_iva->get("S5"));
 | 
						|
      int     tipopla    = atoi(_iva->get("S3"));
 | 
						|
      int     tipodet    = atoi(_rmoviva->get("TIPODET"));
 | 
						|
      bool    ivarimb    = _iva->get_bool("B3");
 | 
						|
      TString tipocr_s   = _rmoviva->get("TIPOCR");       
 | 
						|
      int     tipocr     = atoi(tipocr_s);        
 | 
						|
      real    imponibile = _rmoviva->get_real("IMPONIBILE");
 | 
						|
      real    imposta    = _rmoviva->get_real("IMPOSTA");
 | 
						|
      bool    intra      = _rmoviva->get_bool("INTRA");
 | 
						|
      int     tipoatt    = _rmoviva->get_int("TIPOATT");
 | 
						|
      int     rigaimp    = _rmoviva->get_int("RIGAIMP");
 | 
						|
      // autofatture art. 17 per non residenti, con trattamento
 | 
						|
      // speciale in liquidazione annuale
 | 
						|
      bool    autodafe = (tipodoc == "AF" && tipocr == 4); 
 | 
						|
      // validi per calcolo volume di affari settano
 | 
						|
      // flag che va in B2 di pim    
 | 
						|
      bool    isvolaff = (tipomov == vendita && tipocr != 4  &&
 | 
						|
                         tipoiva != "NS" && tipoiva != "ES" && 
 | 
						|
                         !(tipoiva == "ES" && 
 | 
						|
                          (riga11_v == "B3" || riga11_v.empty())));
 | 
						|
      
 | 
						|
      /*
 | 
						|
       * 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)
 | 
						|
       */
 | 
						|
      if(rigaimp > 9) continue;                               
 | 
						|
 | 
						|
      /*
 | 
						|
       * In liq. annuale si totalizzano
 | 
						|
       * solo le stranezze che seguono
 | 
						|
       */
 | 
						|
      if (month == 13)
 | 
						|
      {         
 | 
						|
         // si contano soltanto le vendite.
 | 
						|
         bool okc = tipomov == vendita;  
 | 
						|
         // purche' ...
 | 
						|
         bool cond1 = (rcs.get_bool("AUTOFATT") && tipoiva == "NS" && tipodoc == "AF");
 | 
						|
         // oppure ... 
 | 
						|
         bool cond2 = (rcs.get_bool("AUTOFATT") && tipoiva == "NS" && tipodoc != "AF" &&
 | 
						|
                       rcs.get_bool("INTRACOM") && rcs.get_bool("VALINTRA"));
 | 
						|
         if (!(okc && (cond1 || cond2)))
 | 
						|
           continue;
 | 
						|
      } 
 | 
						|
       
 | 
						|
      // ***************************************** 
 | 
						|
      // casi particolari
 | 
						|
      // ***************************************** 
 | 
						|
 | 
						|
      // imposta acquisti intracomunitari
 | 
						|
      if (tipomov == acquisto && intra) 
 | 
						|
        totintra += imposta;
 | 
						|
 | 
						|
      // Altre cose di cui tener conto
 | 
						|
      if (tipomov == acquisto && (tipocr == 1 || tipocr == 5)) 
 | 
						|
        /* 
 | 
						|
         * Acquisto beni per rivendita: sono comunque sommati, ma
 | 
						|
         * vengono considerati in ventilazione solo se l'apposito 
 | 
						|
         * parametro ditta e' settato, piu' altre condizioni (vedi
 | 
						|
         * recalc_ventilation() for spulcing) 
 | 
						|
         */
 | 
						|
      {
 | 
						|
        acq_riv     += imponibile;
 | 
						|
        acq_riv_iva += imposta;
 | 
						|
      }                                 
 | 
						|
      
 | 
						|
      else if (tipomov == acquisto && tipocr == 2)
 | 
						|
        // Acquisto beni ammortizzabili
 | 
						|
      {
 | 
						|
        ammort     += imponibile;
 | 
						|
        ammort_iva += imposta;
 | 
						|
      }
 | 
						|
      else if (tipomov == acquisto && tipocr == 3) 
 | 
						|
        // Acquisto beni ammortizzabili detr. 6%
 | 
						|
      {
 | 
						|
        ammort_6     += imponibile;
 | 
						|
        ammort_6_iva += imposta;
 | 
						|
        ult_detr     += imponibile * real(DETRAZIONE_6PERCENTO);
 | 
						|
      }
 | 
						|
      else if (tipomov == vendita && tipocr == 4) 
 | 
						|
        /*
 | 
						|
         * Vendite strum. art 17 (cess. amm.)
 | 
						|
         * Comprende anche autofatture, anche nell'annuale
 | 
						|
         * (Sergio 1995) 
 | 
						|
         */
 | 
						|
      {
 | 
						|
        cess_amm     += imponibile;
 | 
						|
        cess_amm_iva += imposta;
 | 
						|
      }
 | 
						|
      else if (tipomov == acquisto && tipocr == 8) 
 | 
						|
        // Acquisto beni strum. acquisiti in leasing
 | 
						|
      {
 | 
						|
        leasing      += imponibile;
 | 
						|
        leasing_iva  += imposta;
 | 
						|
      }
 | 
						|
      else if (tipomov == acquisto && tipocr == 9) 
 | 
						|
        // Spese generali
 | 
						|
      {
 | 
						|
        spgen        += imponibile;
 | 
						|
        spgen_iva    += imposta;
 | 
						|
      }
 | 
						|
                        
 | 
						|
      // operazioni per calcolo rimborso infracazzuale
 | 
						|
      // Scudler 1995
 | 
						|
 	  if (ivarimb)
 | 
						|
 	  { 
 | 
						|
 	    bool ok   = _isagricolo ? tipoagr == 2 : FALSE;
 | 
						|
 	    
 | 
						|
 	  	if (tipomov == acquisto && !ok)
 | 
						|
 	  	  ok = (tipocr == 0 || tipocr == 1 || tipocr == 5);
 | 
						|
 | 
						|
 	  	if (tipomov == vendita && !ok)
 | 
						|
 	  	  ok = !tipoiva.empty() && tipodoc != "CR" && 
 | 
						|
 	  	       tipodoc != "SC" && tipodoc != "RF";
 | 
						|
 | 
						|
        if (ok)
 | 
						|
 	  	{
 | 
						|
 	  	  // aggiurna tabedda
 | 
						|
 	  	  look_rmb(month, codiva, tipomov, TRUE);
 | 
						|
 	  	  real imp = _rmb->get_real("R0");
 | 
						|
 	  	  real iva = _rmb->get_real("R1");
 | 
						|
 	  	  imp += imponibile; 
 | 
						|
 	  	  iva += imposta;
 | 
						|
 	  	  _rmb->put("R0", imp);
 | 
						|
 	  	  _rmb->put("R1", iva); 
 | 
						|
 	  	  _rmb->put("R2", _iva->get_real("R0")); 
 | 
						|
 	  	  _rmb->rewrite();
 | 
						|
 	  	}
 | 
						|
 	  }
 | 
						|
 | 
						|
      // operazioni esenti
 | 
						|
      if (tipoiva == "ES")
 | 
						|
      {
 | 
						|
        if (tipomov == vendita)
 | 
						|
        {
 | 
						|
          switch(tipoes_v)
 | 
						|
          {
 | 
						|
          case 1: 
 | 
						|
            esenti_b1 += imponibile; 
 | 
						|
            break;
 | 
						|
          case 2: 
 | 
						|
            esenti_b2 += imponibile; 
 | 
						|
            break;
 | 
						|
          case 3: 
 | 
						|
            esenti_b3 += imponibile; 
 | 
						|
            break;
 | 
						|
          }
 | 
						|
        }
 | 
						|
        else if (tipoes_a == 14)
 | 
						|
          esenti_b14 += imponibile;
 | 
						|
      }
 | 
						|
      
 | 
						|
      // 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;
 | 
						|
          else                     corr_CEE += imponibile;
 | 
						|
          break;
 | 
						|
        case 2:
 | 
						|
          if (tipomov == acquisto) acq_noCEE  += imponibile;
 | 
						|
          else                     corr_noCEE += imponibile;
 | 
						|
          break;
 | 
						|
        case 3: corr_misCEE  += imponibile; break;
 | 
						|
        case 4: acq_misCEE   += imponibile; break;
 | 
						|
        case 5: acq_misnoCEE += imponibile; 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 (tipoagr == 1 && tipoagr == 3)
 | 
						|
            agr_1 += imposta;
 | 
						|
          else if (tipoagr == 2)
 | 
						|
            agr_2 += imposta;
 | 
						|
        }
 | 
						|
        else if (tipodet == 0)
 | 
						|
        {
 | 
						|
          if (tipoagr == 2)
 | 
						|
          {
 | 
						|
            if (tipocr != 2 && tipocr != 3 && tipocr != 8)
 | 
						|
              agr_3 += imposta;  
 | 
						|
            else
 | 
						|
              agr_4 += imposta;
 | 
						|
          }
 | 
						|
          else
 | 
						|
          {
 | 
						|
            if (tipocr != 2 && tipocr != 3 && tipocr != 8)
 | 
						|
              agr_5 += imposta;  
 | 
						|
            else
 | 
						|
              agr_6 += imposta;
 | 
						|
          }            
 | 
						|
        }
 | 
						|
      }
 | 
						|
      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
 | 
						|
      // *****************************************
 | 
						|
 | 
						|
      /*
 | 
						|
       * Calcolo e aggiornamento
 | 
						|
       * cerca o crea progressivo IVA
 | 
						|
       */
 | 
						|
 | 
						|
      look_pim(month, codatt, reg, tipocr_s, codiva, tipodet, TRUE);
 | 
						|
      
 | 
						|
      /*
 | 
						|
       * se liq == FALSE gli importi non contano ai fini
 | 
						|
       * del calcolo liquidazione  
 | 
						|
       */                                        
 | 
						|
      bool liq = !(tipodet == 1 || tipodet == 3 || tipodet == 9);
 | 
						|
      
 | 
						|
      real imp = _pim_r->get_real("R0"); // imponibile
 | 
						|
      real ivp = _pim_r->get_real("R1"); // IVA su imp.
 | 
						|
      real lor = _pim_r->get_real("R2"); // lordo  
 | 
						|
      /*
 | 
						|
       * 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
 | 
						|
       */
 | 
						|
      real ifs = _pim_r->get_real("R5"); // imponibile fatture con scontrino
 | 
						|
      real vfs = _pim_r->get_real("R6"); // 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
 | 
						|
       * NELL'OTTICA di una PIU' CORRETTA e CONSONA ......................       
 | 
						|
       */
 | 
						|
      real adf = _pim_r->get_real("R7");                
 | 
						|
      real adi = _pim_r->get_real("R8");                
 | 
						|
 | 
						|
 | 
						|
      if (liq && tipomov == vendita && !corrisp) 
 | 
						|
       // i corrispettivi sono gestiti a parte
 | 
						|
      {
 | 
						|
        // totale vendite
 | 
						|
        vendite     += imponibile;
 | 
						|
        vendite_iva += imposta;
 | 
						|
      }
 | 
						|
      else if (liq && tipomov == acquisto)
 | 
						|
      {
 | 
						|
        // totale acquisti
 | 
						|
        acquisti     += imponibile;
 | 
						|
        acquisti_iva += imposta;
 | 
						|
      }
 | 
						|
      
 | 
						|
      // corrispettivi               
 | 
						|
      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.
 | 
						|
         */
 | 
						|
        if (tipodoc == "CR" || tipodoc == "RF" || tipodoc == "SC")
 | 
						|
        {
 | 
						|
          _pim_r->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;
 | 
						|
            if (liq) 
 | 
						|
              add_corrisp(month, reg, imponibile, perc, tipodet, codiva);
 | 
						|
          }
 | 
						|
        }
 | 
						|
      else if (tipodoc == "FS")
 | 
						|
      {
 | 
						|
        // queste sono fatture che seguono scontrino, il lordo va detratto
 | 
						|
        // perche' si e' gia' registrato lo scontrino medesimo
 | 
						|
        if (tipoiva == "VE")
 | 
						|
        {
 | 
						|
          real rr  = imponibile + imposta; 
 | 
						|
          imp     += rr;
 | 
						|
          if (liq)
 | 
						|
            vendite += rr;
 | 
						|
          add_vendite(month, reg, tipodet, rr); 
 | 
						|
        }
 | 
						|
        else
 | 
						|
        {
 | 
						|
          if (liq)
 | 
						|
          {
 | 
						|
            vendite     += imponibile;
 | 
						|
            vendite_iva += 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;
 | 
						|
          }
 | 
						|
          imp         += imponibile;
 | 
						|
          ivp         += imposta;
 | 
						|
          ifs         += imponibile;
 | 
						|
          vfs         += imposta; 
 | 
						|
          _pim_r->put("I0",NETTO);
 | 
						|
        }
 | 
						|
      }  // if corrisp
 | 
						|
      else // non corrisp
 | 
						|
      {       // imponibile e imposta separata
 | 
						|
        imp += imponibile;
 | 
						|
        ivp += imposta;
 | 
						|
        _pim_r->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 A35 in caso di liq. annuale
 | 
						|
         */
 | 
						|
        adf += imponibile;
 | 
						|
        adi += imposta;      	
 | 
						|
      }                  
 | 
						|
      
 | 
						|
      _pim_r->put("B2",isvolaff);
 | 
						|
      _pim_r->put("R0",imp);
 | 
						|
      _pim_r->put("R1",ivp);
 | 
						|
      _pim_r->put("R2",lor);   
 | 
						|
      _pim_r->put("R5",ifs);   
 | 
						|
      _pim_r->put("R6",vfs);   
 | 
						|
      _pim_r->put("R7",adf);   
 | 
						|
      _pim_r->put("R8",adi);   
 | 
						|
      _pim->rewrite();
 | 
						|
    }
 | 
						|
    while (_cur->next_match(LF_RMOVIVA));
 | 
						|
  }  
 | 
						|
  
 | 
						|
  // calcolati tutti i movimenti e aggiornati i pim
 | 
						|
  
 | 
						|
  /* 
 | 
						|
   * calcola il lercio prorata  
 | 
						|
   * solo se liq. periodica
 | 
						|
   */
 | 
						|
  real prorata; 
 | 
						|
  if (!_prorata.is_zero() && month != 13)
 | 
						|
  {
 | 
						|
    prorata = acquisti_iva * (_prorata / CENTO);
 | 
						|
    prorata.round(ROUND_LIRA);  
 | 
						|
    acquisti_iva -= prorata;
 | 
						|
  }
 | 
						|
  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)
 | 
						|
   */
 | 
						|
 | 
						|
  _plm->put("R2", prorata);
 | 
						|
 | 
						|
  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)
 | 
						|
    // ---------------------------------------
 | 
						|
  }
 | 
						|
  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);
 | 
						|
 | 
						|
    // Il porco agricoltore spende poco e paga meno
 | 
						|
    vendite_iva  = agr_2;
 | 
						|
    acquisti_iva = agr_3 - agr_4;
 | 
						|
  }
 | 
						|
 | 
						|
  // COSA MI TOCCA FARE  (per campare, of course)
 | 
						|
  // due numeri nello stesso campo ma e' sempre meglio
 | 
						|
  // del TIPO RECORD                   
 | 
						|
  TToken_string s(40);
 | 
						|
 | 
						|
  _plm->put("R0", vendite_iva);
 | 
						|
  _plm->put("R1", acquisti_iva);
 | 
						|
  _plm->put("R3", ult_detr);
 | 
						|
  // probabilmente R4 serviva per il decalage e non si usera'
 | 
						|
  _plm->put("R12", _prorata); // per comodita' in stampa
 | 
						|
  _plm->put("B0", "X");       // calcolato (invalidato dalla primanota)
 | 
						|
  _plm->put("S1",  for_rimb.string());
 | 
						|
  
 | 
						|
  // si riempiano le stringhe di coppie di real
 | 
						|
  s.add(acq_ies.string());
 | 
						|
  s.add(acq_ies_iva.string());
 | 
						|
  _plm->put("S2", (const char*)s);  
 | 
						|
  s = "";
 | 
						|
  s.add(acq_pint.string());
 | 
						|
  s.add(acq_pint_iva.string()); 
 | 
						|
  _plm->put("S3", (const char*)s);  
 | 
						|
  s = "";
 | 
						|
  s.add(spgen.string());
 | 
						|
  s.add(spgen_iva.string()); 
 | 
						|
  _plm->put("S4", (const char*)s);                    
 | 
						|
  _plm->rewrite();
 | 
						|
 | 
						|
  // salva gli altri totali para no ponernos locos despues
 | 
						|
  look_ptm(month,  codatt, TRUE);
 | 
						|
  _ptm->put("R0",  totintra);  
 | 
						|
  _ptm->put("R1",  nond19_imp);  
 | 
						|
  _ptm->put("R2",  nond19_iva);  
 | 
						|
  _ptm->put("R3",  ammort);  
 | 
						|
  _ptm->put("R4",  ammort_iva);  
 | 
						|
  _ptm->put("R5",  ammort_6);  
 | 
						|
  _ptm->put("R6",  acq_riv);  
 | 
						|
  _ptm->put("R7",  acq_riv_iva);  
 | 
						|
  _ptm->put("R8",  leasing);  
 | 
						|
  _ptm->put("R9",  leasing_iva);  
 | 
						|
  _ptm->put("R10", cess_amm);  
 | 
						|
  _ptm->put("R11", cess_amm_iva);  
 | 
						|
  _ptm->put("R12", ammort_6_iva);
 | 
						|
  _ptm->put("R13", esenti_b1);
 | 
						|
  _ptm->put("R14", esenti_b2);
 | 
						|
  _ptm->put("S0",  esenti_b3.string());
 | 
						|
  _ptm->put("S1",  esenti_b14.string());
 | 
						|
  _ptm->put("S2",  acquisti.string());
 | 
						|
  _ptm->put("S3",  vendite.string());  
 | 
						|
  _ptm->rewrite();
 | 
						|
}
 | 
						|
 | 
						|
void TLiquidazione_app::write_liq(int month, const char* codatts)
 | 
						|
  // Calcolo liq. mensili e  liq. annuali
 | 
						|
{
 | 
						|
  TToken_string atts(codatts);
 | 
						|
  TToken_string tt(60);
 | 
						|
  const char* tmpatt;
 | 
						|
  
 | 
						|
  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 debt_precd   = 0.0;
 | 
						|
  real acc_dec      = 0.0;
 | 
						|
  real iva_vend     = 0.0;
 | 
						|
  real iva_acq      = 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;
 | 
						|
  int attc = 0; // counter attivita'
 | 
						|
  
 | 
						|
  while ((tmpatt = atts.get()) != NULL)
 | 
						|
  {
 | 
						|
    TString att(tmpatt);
 | 
						|
    
 | 
						|
    if (_isdifferita && is_first_month(month))
 | 
						|
    {
 | 
						|
      // usa i totali del mese di dicembre dell'anno
 | 
						|
      // precedente      
 | 
						|
      differita = TRUE;
 | 
						|
      TString yr(_year);
 | 
						|
      _year = format("%d", atoi(_year)-1);
 | 
						|
      if (!look_lim(12))
 | 
						|
      { 
 | 
						|
      	_year = yr; 
 | 
						|
      	differita = FALSE;
 | 
						|
      }
 | 
						|
    }
 | 
						|
    if (differita)
 | 
						|
    { 
 | 
						|
      if (attc == 0)
 | 
						|
      {
 | 
						|
        risultato = result_liq(12);
 | 
						|
        deb_mens  = _lim->get_real("R3");
 | 
						|
        detrazioni= _lim->get_real("R6");
 | 
						|
        perc_r    = _lim->get_real("R4");
 | 
						|
        cred_cost = _lim->get_real("R2");  
 | 
						|
        rettifiche= _lim->get_real("R5");
 | 
						|
        rimborsi  = _lim->get_real("R1");   
 | 
						|
        // leggi anche tutti gli altri totali
 | 
						|
        tt        = _lim->get("S2");
 | 
						|
        iva_vend  = tt.get(0); iva_acq = tt.get(1);  
 | 
						|
        cred_prec = tt.get(2); debt_precd = tt.get(3);
 | 
						|
          
 | 
						|
        res_debt  = (const char*)_lim->get("S5");
 | 
						|
        res_cred  = (const char*)_lim->get("S4");
 | 
						|
        acc_dec   = (const char*)_lim->get("S3");
 | 
						|
        _year = format("%d", atoi(_year)+1); 
 | 
						|
      }
 | 
						|
    }                             
 | 
						|
    else
 | 
						|
    {
 | 
						|
      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(m, att);  look_ptm(m,att); 
 | 
						|
        bool is_lim = look_lim(m);
 | 
						|
        
 | 
						|
        // gia' conteggiato: prorata
 | 
						|
        // da conteggiare: IVA vendite ag. viaggio
 | 
						|
        // a debito:  IVA vendite, debito precedente
 | 
						|
        // a credito: IVA acquisti, ulteriori detrazioni 1 e 2     
 | 
						|
        
 | 
						|
        iva_vend  += _plm->get_real("R0");
 | 
						|
        iva_acq   += _plm->get_real("R1");
 | 
						|
        risultato += (_plm->get_real("R0") - _plm->get_real("R1"));
 | 
						|
        detrazioni+= (_plm->get_real("R3") + _plm->get_real("R4"));
 | 
						|
        res_debt  += _plm->get_real("R0");
 | 
						|
        res_cred  += _plm->get_real("R1");
 | 
						|
        
 | 
						|
        // detrazioni solo non in regime agricolo
 | 
						|
        if (!_isagricolo)
 | 
						|
        {
 | 
						|
          risultato -= (_plm->get_real("R3") + _plm->get_real("R4")); 
 | 
						|
          res_cred  += (_plm->get_real("R3") + _plm->get_real("R4"));
 | 
						|
        }
 | 
						|
        /* 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
 | 
						|
         */
 | 
						|
        if (attc == 0 && is_lim)
 | 
						|
        {
 | 
						|
          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    
 | 
						|
          TString descrett(_lim->get("S0"));
 | 
						|
          bool isforbenzinaro = descrett[0] == '$' ||
 | 
						|
                                (descrett[0] == '>' && descrett[1] == '>');
 | 
						|
                                
 | 
						|
          if ((isforbenzinaro && _isannual) || 
 | 
						|
              (!isforbenzinaro && !_isannual))  
 | 
						|
          {
 | 
						|
            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"));
 | 
						|
          }
 | 
						|
        }
 | 
						|
 | 
						|
        /* 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");   
 | 
						|
        }        
 | 
						|
      } // fine ciclo sul mese  
 | 
						|
      // counter attivita' per evitare troppi versamenti
 | 
						|
      attc++;                                           
 | 
						|
    } // fine ciclo su attivita'
 | 
						|
    
 | 
						|
    if (!(_isdifferita && is_first_month(month)))
 | 
						|
    {   
 | 
						|
      if (_isviaggio)
 | 
						|
      {
 | 
						|
      // calcolo credito costo, debito mensile, perc. ripart.
 | 
						|
        perc_r  = (a_mCEE * CENTO)/(a_mCEE + a_meCEE);
 | 
						|
        real c  = (c_mCEE * perc_r)/CENTO; c.round(ROUND_LIRA);
 | 
						|
        real tc = (c_iCEE + c);
 | 
						|
        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.round(ROUND_LIRA);    
 | 
						|
          risultato  += deb_mens; 
 | 
						|
          res_debt   += deb_mens;
 | 
						|
        }
 | 
						|
      }      
 | 
						|
    }    
 | 
						|
  }                
 | 
						|
 | 
						|
  if (!(_isdifferita && is_first_month(month)))  
 | 
						|
  { 
 | 
						|
    if (month < 13)
 | 
						|
    {
 | 
						|
      // toglie credito precedente
 | 
						|
	  cred_prec  =  credito_prec(month);
 | 
						|
      risultato -=  cred_prec; 
 | 
						|
      res_cred  +=  cred_prec;
 | 
						|
      // vedi se c'era un debito precedente per debiti < 50.000
 | 
						|
      debt_precd = debt_prec(month);
 | 
						|
      risultato += debt_precd;
 | 
						|
      res_debt  += debt_precd;
 | 
						|
    }
 | 
						|
    else 
 | 
						|
    { 
 | 
						|
      // per l'annuale considera solo il credito a inizio anno
 | 
						|
      cred_prec = credito_prec(1);
 | 
						|
      risultato -=  cred_prec; 
 | 
						|
      res_cred  +=  cred_prec;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  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
 | 
						|
      {
 | 
						|
      	look_pla(att);     
 | 
						|
      	TToken_string tt(_pla->get("S1"));
 | 
						|
      	real vf1(tt.get(0));
 | 
						|
      	real vf2(tt.get(1));              
 | 
						|
      	real iaq(_pla->get("S2")); // IVA acquisti
 | 
						|
      	real ppg(_pla->get("S3")); // 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 + csamm + es_b3;
 | 
						|
      	real prorata(0.0); 
 | 
						|
      	if (!ris.is_zero())
 | 
						|
          prorata = (es_b1/ris) * CENTO;
 | 
						|
        real conguaglio = 0.0;
 | 
						|
        prorata.round(-2);
 | 
						|
        if (prorata != _prorata)
 | 
						|
        {
 | 
						|
          // calcolo conguaglio -- se positivo e' a debito
 | 
						|
          real topay = iaq * (prorata / CENTO);
 | 
						|
          conguaglio = topay - ppg;
 | 
						|
          conguaglio.round(ROUND_LIRA);
 | 
						|
        }
 | 
						|
        _pla->put("R9", conguaglio);      	
 | 
						|
        _pla->put("R10",prorata); 
 | 
						|
        tot_cong += conguaglio;
 | 
						|
        _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();
 | 
						|
        _year = yr;      	
 | 
						|
      } 
 | 
						|
    }                     
 | 
						|
 | 
						|
    look_lia();
 | 
						|
    _lia->put("R1", vol_aff_l);
 | 
						|
    _lia->put("R2", vol_aff_1);
 | 
						|
    _lia->put("R3", vol_aff_2);
 | 
						|
    _lia->put("R4", acc_dec);
 | 
						|
    _lia->put("R5", cred_cost);   
 | 
						|
    _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,TRUE);       
 | 
						|
  // azzeriamo tutto (tranne r1, r5, s7)
 | 
						|
  TString codtab = _lim->get("CODTAB");
 | 
						|
 | 
						|
  real r5(_lim->get("R5")), r1(_lim->get("R1"));
 | 
						|
  TString s7(_lim->get("S7"));  
 | 
						|
 | 
						|
  _lim->zero();
 | 
						|
  _lim->put("CODTAB", codtab);
 | 
						|
  _lim->put("R1", r1);  
 | 
						|
  _lim->put("R5", r5);  
 | 
						|
  _lim->put("S7", s7);  
 | 
						|
  
 | 
						|
  /* 
 | 
						|
   * versamenti effettuati: si conteggiano in R0,
 | 
						|
   * sono > 0 solo se andavano calcolati (vedi sopra)
 | 
						|
   */
 | 
						|
  risultato -= (versamenti + vers_int);
 | 
						|
  /* 
 | 
						|
   * acconto dicembre se previsto
 | 
						|
   */
 | 
						|
  if ((month == 12 && _isbenzinaro)  || 
 | 
						|
      (month >= 12 && _freqviva == "M"))
 | 
						|
  {
 | 
						|
    risultato -= versamenti_IVA(12,"7");
 | 
						|
    acc_dec    = versamenti_IVA(12,"7");        
 | 
						|
    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); 
 | 
						|
  _lim->put("R6",detrazioni);  
 | 
						|
  
 | 
						|
  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,
 | 
						|
   * non benzinari
 | 
						|
   */              
 | 
						|
  if (_freqviva == "T" && risultato.sign() > 0 && 
 | 
						|
      month < 13 && !_isbenzinaro)
 | 
						|
  {
 | 
						|
    real interesse = interesse_trimestrale(_month);
 | 
						|
    real ivi = risultato * (interesse / CENTO); 
 | 
						|
    ivi.ceil(ROUND_LIRA);
 | 
						|
    _lim->put("R11", ivi); 
 | 
						|
    _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);
 | 
						|
 | 
						|
  // scrivi: totali IVA vendite e acquisti, credito prec,
 | 
						|
  // debito prec, acconto, totale conguaglio prorata
 | 
						|
  // cosi' si fa una volta sola in stampa
 | 
						|
  tt = iva_vend.string(); tt.add(iva_acq.string());
 | 
						|
  tt.add(cred_prec.string()); tt.add(debt_precd.string()); 
 | 
						|
  
 | 
						|
  _lim->put("S2", tt);
 | 
						|
  _lim->put("S3", acc_dec.string());
 | 
						|
  _lim->put("S4", res_cred.string());  
 | 
						|
  _lim->put("S5", res_debt.string());  
 | 
						|
    
 | 
						|
   
 | 
						|
  _lim->put("B0","X");
 | 
						|
  if (_isfinal) 
 | 
						|
    _lim->put("B1", "X");
 | 
						|
  _lim->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;
 | 
						|
 | 
						|
  int tipoatt = att[strlen(att) -1] - '0';
 | 
						|
  TString aaa(att);
 | 
						|
  
 | 
						|
  look_pla(aaa);
 | 
						|
  TToken_string tt(_pla->get("S1"));
 | 
						|
  volaff1  = tt.get(0);
 | 
						|
  volaff1  = tt.get(1);
 | 
						|
  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  = (const char*)_pla->get("S3");
 | 
						|
  iva_acq  = (const char*)_pla->get("S2"); 
 | 
						|
  
 | 
						|
  // 1) Calcola volume di affari dai PIM, controllando il
 | 
						|
  //    flag B2 settato da update_att per i progressivi che
 | 
						|
  //    entrano nel calcolo
 | 
						|
  
 | 
						|
  for (_pim->first(); !_pim->eof(); _pim->next())
 | 
						|
  {
 | 
						|
    if (_year != (const char*)_pim_anno || aaa != (const char*)_pim_codatt)
 | 
						|
	  continue;
 | 
						|
	if (_pim->get_bool("B2"))
 | 
						|
	{
 | 
						|
	  if (tipoatt == 1) volaff1 += _pim->get_real("R0");
 | 
						|
	  else              volaff2 += _pim->get_real("R0");
 | 
						|
	}
 | 
						|
  }
 | 
						|
  
 | 
						|
  // 2) calcola esenti, cessioni, lordo vendite, prorata pagato
 | 
						|
  //    e IVA acquisti dai plm/ptm 
 | 
						|
  
 | 
						|
  for (int i = 1; i <= 13; i++)
 | 
						|
  {
 | 
						|
    if (!look_ptm(i,aaa) || !look_plm(i,aaa))
 | 
						|
      continue;
 | 
						|
    
 | 
						|
    // vendite lorde; sa la madonna a cosa servono
 | 
						|
    real vend(_ptm->get("S3"));
 | 
						|
    ven_lrd   += vend;
 | 
						|
    iva_acq   += _plm->get_real("R1");
 | 
						|
    real eb3(_ptm->get("S0"));
 | 
						|
    es_b1     += _ptm->get_real("R13");
 | 
						|
    es_b2     += _ptm->get_real("R14");
 | 
						|
    es_b3     += eb3;
 | 
						|
    cess_amm  += _ptm->get_real("R10"); 
 | 
						|
    pro_pag   += _plm->get_real("R2");
 | 
						|
  }
 | 
						|
  
 | 
						|
  tt = volaff1.string(); tt.add(volaff2.string());                           
 | 
						|
                             
 | 
						|
  _pla->put("R0", ven_lrd);
 | 
						|
  _pla->put("R1", es_b1);
 | 
						|
  _pla->put("R2", es_b2);
 | 
						|
  _pla->put("R3", es_b3);
 | 
						|
  _pla->put("R4", cess_amm);
 | 
						|
  _pla->put("S1", tt);      
 | 
						|
  _pla->put("S2", iva_acq.string());
 | 
						|
  _pla->put("S3", pro_pag.string());
 | 
						|
  _pla->rewrite();
 | 
						|
}
 | 
						|
 |