Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione aga 1.7 patch 413 git-svn-id: svn://10.65.10.50/trunk@10856 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			4186 lines
		
	
	
		
			124 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			4186 lines
		
	
	
		
			124 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// 
 | 
						||
// Stampa registri IVA
 | 
						||
// Usurpatore di Liberta'...
 | 
						||
//    Nemico ed Oscuro Messo di Malvagita'...
 | 
						||
#include <currency.h>
 | 
						||
#include <os_dep.h>
 | 
						||
#include <recarray.h>
 | 
						||
 | 
						||
#include "cg4.h"
 | 
						||
#include "cg4400.h"
 | 
						||
#include "cg4400a.h"
 | 
						||
#include "cg4400b.h"
 | 
						||
#include "cglib01.h"
 | 
						||
#include <mask.h>
 | 
						||
#include <sheet.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <mailbox.h>
 | 
						||
#include <execp.h>
 | 
						||
#include <utility.h>
 | 
						||
#include <defmask.h>
 | 
						||
#include <prefix.h>
 | 
						||
 | 
						||
#include <mov.h>
 | 
						||
#include <clifo.h>
 | 
						||
#include <nditte.h>
 | 
						||
#include <anagr.h>
 | 
						||
#include <occas.h>
 | 
						||
#include <comuni.h>
 | 
						||
#include <unloc.h>
 | 
						||
#include <causali.h>
 | 
						||
#include <rmoviva.h>
 | 
						||
 | 
						||
 | 
						||
static enum tipo_sospensione { nessuna, normale, vol_affari,  liquidazione };
 | 
						||
 | 
						||
inline TStampa_registri_app& app() { return (TStampa_registri_app&)main_app(); }
 | 
						||
 | 
						||
#define RIGHE_FOOTER 1 // Righe da saltare nel footer per evitare di scrivere sulla perforazione
 | 
						||
 | 
						||
 | 
						||
bool TStampa_registri_app::filter_func (const TRelation * r)
 | 
						||
{
 | 
						||
  const TRectype& mov = r->curr(LF_MOV);
 | 
						||
  TString16 codreg  = mov.get(MOV_REG);
 | 
						||
  TDate   datareg = mov.get_date(MOV_DATAREG);  
 | 
						||
  int     annoiva = mov.get_int(MOV_ANNOIVA);
 | 
						||
  bool    regst   = mov.get_bool(MOV_REGST);
 | 
						||
 | 
						||
  if (codreg != (app()._codreg) || annoiva != (app()._annoes)) 
 | 
						||
    return FALSE;           
 | 
						||
  
 | 
						||
  //if (app()._data_da.string() != "" && app()._data_a.string() != "")
 | 
						||
  //  if ( (datareg < app()._data_da || datareg > app()._data_a ) || (!datareg.ok()) )
 | 
						||
  //    return FALSE;           
 | 
						||
  //if (!datareg.ok())
 | 
						||
  //  return FALSE;
 | 
						||
    
 | 
						||
  if (app()._tipo_stampa != prova) //stampa di bollato
 | 
						||
  {
 | 
						||
    const tipo_sospensione ts = (tipo_sospensione) r->lfile("REG").get_int("I9");
 | 
						||
    if (ts == liquidazione)    // Movimento valido solo ai fini della liquidazione
 | 
						||
      return FALSE;
 | 
						||
    if (regst)                 //il movimento e' gia' 
 | 
						||
      return FALSE;            //stato stampato in forma definitiva
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (datareg.month() < app()._stampa_mese)
 | 
						||
    app()._stampa_mese = datareg.month(); 
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
HIDDEN int compare_rows(const TObject** o1, const TObject** o2)
 | 
						||
{
 | 
						||
  TRiga* r1 = (TRiga*)*o1;
 | 
						||
  TRiga* r2 = (TRiga*)*o2;
 | 
						||
  
 | 
						||
  return (strcmp((const char*)r1->_codiva, (const char*)r2->_codiva));
 | 
						||
}
 | 
						||
 | 
						||
HIDDEN int compare_fields(const TObject** o1, const TObject** o2)
 | 
						||
{
 | 
						||
  TRigaiva* r1 = (TRigaiva*)*o1;
 | 
						||
  TRigaiva* r2 = (TRigaiva*)*o2;
 | 
						||
  TString16 campo1;
 | 
						||
  TString16 campo2;
 | 
						||
  
 | 
						||
  campo1.format("%d%4s", r1->_tipodet, (const char*)r1->_codiva); 
 | 
						||
  campo2.format("%d%4s", r2->_tipodet, (const char*)r2->_codiva); 
 | 
						||
  return strcmp(campo1, campo2);
 | 
						||
}
 | 
						||
 | 
						||
//********* funzioni accessorie e di ricerca *********//
 | 
						||
 | 
						||
bool TStampa_registri_app::stampa_totali_finali()
 | 
						||
{
 | 
						||
  TConfig conf(CONFIG_DITTA);
 | 
						||
  return conf.get_bool("StTfFr");
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::stampa_datareg()
 | 
						||
{
 | 
						||
  TConfig conf(CONFIG_STUDIO);
 | 
						||
  return conf.get_bool("NoDtRg");
 | 
						||
}
 | 
						||
 | 
						||
const char* TStampa_registri_app::descr_doc()
 | 
						||
{
 | 
						||
  TTable  tab_tpd("%TPD");
 | 
						||
  TString16 codtab;
 | 
						||
  codtab.format("%-2s",(const char*)_tipodoc);
 | 
						||
  
 | 
						||
  tab_tpd.zero();
 | 
						||
  tab_tpd.put("CODTAB", codtab);
 | 
						||
  if (tab_tpd.read()==NOERR)
 | 
						||
    TMP = tab_tpd.get("S0");
 | 
						||
  else
 | 
						||
    TMP = "";
 | 
						||
 | 
						||
  return TMP;
 | 
						||
} 
 | 
						||
 | 
						||
const char* TStampa_registri_app::descr_iva(const char* cod)
 | 
						||
{
 | 
						||
  TTable  tab_iva("%IVA");
 | 
						||
  TString16 codtab;
 | 
						||
  codtab.format ("%-4s", cod);
 | 
						||
  
 | 
						||
  tab_iva.zero();
 | 
						||
  tab_iva.put("CODTAB", codtab);
 | 
						||
  if (tab_iva.read()==NOERR)
 | 
						||
    TMP = tab_iva.get("S0");
 | 
						||
  else
 | 
						||
    TMP = "";
 | 
						||
 | 
						||
  return TMP;
 | 
						||
} 
 | 
						||
 | 
						||
const char* TStampa_registri_app::tipo_attivita()
 | 
						||
{
 | 
						||
  TLocalisamfile attiv (LF_ATTIV);
 | 
						||
  
 | 
						||
  attiv.zero();
 | 
						||
  attiv.put("CODDITTA", get_firm());
 | 
						||
  attiv.put("CODATT", _codatt);
 | 
						||
  if (attiv.read() == NOERR)
 | 
						||
    TMP = attiv.get("TIPOATT");
 | 
						||
  else TMP = "";
 | 
						||
  return TMP;   
 | 
						||
}
 | 
						||
 | 
						||
const char* TStampa_registri_app::desc_attivita(const TString& cod)
 | 
						||
{
 | 
						||
  TLocalisamfile attiv (LF_ATTIV);
 | 
						||
  attiv.zero();
 | 
						||
  attiv.put("CODDITTA", get_firm());
 | 
						||
  attiv.put("CODATT", cod);
 | 
						||
  if (attiv.read() == NOERR)
 | 
						||
    TMP = attiv.get("DESCR");
 | 
						||
  else 
 | 
						||
    TMP = "";
 | 
						||
  return TMP;
 | 
						||
}
 | 
						||
 | 
						||
const TRectype& TStampa_registri_app::ricerca_cf(char tipocf, long codcf)
 | 
						||
{
 | 
						||
  _clifo->zero();
 | 
						||
  _clifo->put(CLI_TIPOCF, tipocf);
 | 
						||
  _clifo->put(CLI_CODCF, codcf);
 | 
						||
  _clifo->read();
 | 
						||
  if (_clifo->bad())
 | 
						||
    _clifo->zero();
 | 
						||
  return _clifo->curr();
 | 
						||
}
 | 
						||
 | 
						||
const TRectype& TStampa_registri_app::ricerca_occ(const char* occ)
 | 
						||
{
 | 
						||
/*
 | 
						||
  TLocalisamfile occas (LF_OCCAS);
 | 
						||
  occas.zero();
 | 
						||
  occas.put(OCC_CFPI, occ);
 | 
						||
  occas.read();
 | 
						||
  if (occas.bad())
 | 
						||
    occas.zero();
 | 
						||
  return occas.curr();
 | 
						||
*/
 | 
						||
  return cache().get(LF_OCCAS, occ);
 | 
						||
}
 | 
						||
 | 
						||
const TRectype& TStampa_registri_app::look_comuni(const TString& stato, const TString& cod)
 | 
						||
{
 | 
						||
/*
 | 
						||
  _com->zero();
 | 
						||
  _com->put(COM_STATO, stato);
 | 
						||
  _com->put(COM_COM, cod);
 | 
						||
  _com->read();
 | 
						||
  if (_com->bad())
 | 
						||
    _com->zero();
 | 
						||
  return _com->curr();
 | 
						||
*/ 
 | 
						||
  TString16 key;
 | 
						||
  key << stato << '|' << cod;
 | 
						||
  return cache().get(LF_COMUNI, key);
 | 
						||
}
 | 
						||
 | 
						||
const TRectype& TStampa_registri_app::look_comuni (const char* cod)
 | 
						||
{ 
 | 
						||
  const TString16 stato;
 | 
						||
  const TString16 comune = cod;
 | 
						||
  return look_comuni(stato, comune);
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::get_dati_ditta()
 | 
						||
{
 | 
						||
/*  
 | 
						||
  TLocalisamfile nditte(LF_NDITTE); 
 | 
						||
  nditte.zero();
 | 
						||
  nditte.put(NDT_CODDITTA, get_firm());   
 | 
						||
  nditte.read();
 | 
						||
  if (nditte.bad()) nditte.zero();
 | 
						||
*/
 | 
						||
  const TRectype& nditte = cache().get(LF_NDITTE, get_firm());
 | 
						||
  _ragsoc  = nditte.get(NDT_RAGSOC);
 | 
						||
 | 
						||
  const char tipoa    = nditte.get_char(NDT_TIPOA);
 | 
						||
  const long codanagr = nditte.get_long(NDT_CODANAGR);
 | 
						||
/*
 | 
						||
  TLocalisamfile anag(LF_ANAG);
 | 
						||
  TString        codanagr;
 | 
						||
  TString        tipoa;
 | 
						||
  anag.setkey(1);
 | 
						||
  anag.zero();
 | 
						||
  anag.put (ANA_TIPOA, tipoa);
 | 
						||
  anag.put (ANA_CODANAGR, codanagr);
 | 
						||
  anag.read();
 | 
						||
  if (anag.bad()) anag.zero();
 | 
						||
*/
 | 
						||
  const TRectype& anag = cache().get(LF_ANAG, format("%c|%ld", tipoa, codanagr));
 | 
						||
  
 | 
						||
  _cofi      = anag.get(ANA_COFI);
 | 
						||
  _paiva     = anag.get(ANA_PAIV);
 | 
						||
  _comunefis = anag.get(ANA_COMRF);
 | 
						||
  _cap       = anag.get(ANA_CAPRF);
 | 
						||
 | 
						||
  if (_comunefis.empty()) 
 | 
						||
    _comunefis = anag.get(ANA_COMRES);
 | 
						||
  if (_cap.empty()) 
 | 
						||
    _cap = anag.get(ANA_CAPRES);
 | 
						||
 | 
						||
  const TRectype& dep = look_comuni (_comunefis);
 | 
						||
 | 
						||
  _comunefis   = dep.get(COM_DENCOM);
 | 
						||
  _provfis     = dep.get(COM_PROVCOM);
 | 
						||
  if (_comunefis.empty()) 
 | 
						||
  {
 | 
						||
    _viafis = anag.get(ANA_INDRF);
 | 
						||
    _viafis.rtrim();
 | 
						||
    _viafis << " " << anag.get (ANA_CIVRF); 
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    _viafis = anag.get(ANA_INDRES);
 | 
						||
    _viafis.rtrim();
 | 
						||
    _viafis << ' ' << anag.get (ANA_CIVRES); 
 | 
						||
  } 
 | 
						||
  
 | 
						||
  if (_cod_un_loc)
 | 
						||
  {
 | 
						||
/*  
 | 
						||
    TLocalisamfile unloc(LF_UNLOC);
 | 
						||
    unloc.zero();
 | 
						||
    unloc.put(ULC_CODDITTA, get_firm());
 | 
						||
    unloc.put(ULC_CODULC, _cod_un_loc);
 | 
						||
    unloc.read();
 | 
						||
    if (unloc.read() == NOERR) 
 | 
						||
*/
 | 
						||
    const TRectype& unloc = cache().get(LF_UNLOC, format("%ld|%d", get_firm(), _cod_un_loc));
 | 
						||
    if (!unloc.empty())
 | 
						||
    {  
 | 
						||
      const TRectype& dep = look_comuni (unloc.get(ULC_COMULC));
 | 
						||
      _comunefis   = dep.get(COM_DENCOM);
 | 
						||
      _provfis     = dep.get(COM_PROVCOM);
 | 
						||
      _cap         = unloc.get(ULC_CAPULC);
 | 
						||
      _viafis      = unloc.get(ULC_INDULC);
 | 
						||
      _viafis.rtrim();
 | 
						||
      _viafis << ' ' << unloc.get(ULC_CIVULC);
 | 
						||
    }
 | 
						||
  }   
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::look_lia(long ditta)
 | 
						||
{
 | 
						||
  if (ditta == 0l) ditta = get_firm();
 | 
						||
  
 | 
						||
  TString16 y; y.format("%05ld%04d", ditta, _annoes);
 | 
						||
  
 | 
						||
  _tablia->zero();
 | 
						||
  _tablia->put("CODTAB", y);
 | 
						||
  _tablia->read();
 | 
						||
  const bool ok = _tablia->good(); 
 | 
						||
  if (ok) 
 | 
						||
    _credito = _tablia->get_real("R0");
 | 
						||
  else _credito = ZERO;  
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
//guarda tutti i mesi a partire da gennaio e controlla 
 | 
						||
//se ce ne' almeno uno per cui e' necessario rilanciare 
 | 
						||
//il calcolo (il flag B1 e' invalidato dalla prima nota). 
 | 
						||
//In tal caso si richiamera' il prg di liquidazione con 
 | 
						||
//'C' e sara' tale prg che si preoccupera' di ricalcolare 
 | 
						||
//tutti i mesi a partire dall'inizio dell'anno (e a settare
 | 
						||
//B1 nelle lim di tutti i mesi calcolati)
 | 
						||
bool TStampa_registri_app::ricalcola(int mese)
 | 
						||
{
 | 
						||
  TTable lim ("LIM");        
 | 
						||
  //controllo i periodi precedenti al mese passato
 | 
						||
  for (int m = 1; m < mese; m++)
 | 
						||
  { 
 | 
						||
    //L'if seguente e' necessario perche' se la ditta ha
 | 
						||
    //_frequiva == 'T' => esiste la lim solo se m == 3/6/9/12
 | 
						||
    //(no problem: la Prima Nota pensa lei a invalidare B0 e B1
 | 
						||
    //dei trimestri a cui appartiene il mese modificato)
 | 
						||
    if (_frequiva == 'M' ||
 | 
						||
       (m == 3 || m == 6 || m == 9 || m == 12))
 | 
						||
    {   
 | 
						||
     TString16 key; key.format("%04d%02d", _annoes, m);
 | 
						||
     lim.setkey(1);
 | 
						||
     lim.put("CODTAB", key);
 | 
						||
     if (lim.read() != NOERR || !lim.get_bool("B1"))
 | 
						||
       return TRUE;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  //controllo il mese passato
 | 
						||
  if (_frequiva == 'M')
 | 
						||
  {
 | 
						||
    TString16 key; key.format("%04d%02d", _annoes, mese);
 | 
						||
    lim.setkey(1);
 | 
						||
    lim.put("CODTAB", key);
 | 
						||
    if (lim.read() != NOERR || !lim.get_bool("B1"))
 | 
						||
      return TRUE;
 | 
						||
  }    
 | 
						||
  else
 | 
						||
  {  
 | 
						||
    //aggiusta il mese al trimestre a cui appartiene
 | 
						||
    mese += 2 - ((mese-1) % 3);  
 | 
						||
    TString16 key; key.format("%04d%02d", _annoes, mese);
 | 
						||
    lim.setkey(1);
 | 
						||
    lim.put("CODTAB", key);
 | 
						||
    if (lim.read() != NOERR || !lim.get_bool("B1"))
 | 
						||
      return TRUE;     
 | 
						||
  }         
 | 
						||
  return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::look_reg()
 | 
						||
{
 | 
						||
  _liquidazione  = _tabreg->get_bool("B7");
 | 
						||
  _riep_liq      = _tabreg->get_bool("B6");
 | 
						||
  _corrispettivi = _tabreg->get_bool("B0");   
 | 
						||
  _sosp_imposta  = _tabreg->get_bool("B1"); 
 | 
						||
  _pagine_stampate  = _tabreg->get_long("I1");
 | 
						||
  _numini           = _pagine_stampate;
 | 
						||
  _cod_un_loc       = _tabreg->get_int("I7");
 | 
						||
  _mese_ultima_liq  = _tabreg->get_int("I4");
 | 
						||
  _mese_credito     = _tabreg->get_int("I8");
 | 
						||
  _codatt           = _tabreg->get("S8");
 | 
						||
  _tipoatt          = tipo_attivita();
 | 
						||
  _attivita         = desc_attivita(_codatt);
 | 
						||
  _desc_lib         = _tabreg->get ("S0");
 | 
						||
  _stampa_ind_ditta = _tabreg->get_bool ("B9");
 | 
						||
  _stampa_ind_comp  = _tabreg->get_bool ("B5"); 
 | 
						||
  _stampa_cred_pre  = _tabreg->get_bool ("B4"); 
 | 
						||
  _freq_riepilogo   = _tabreg->get_char ("S9");
 | 
						||
  _stampa_plafonds  = _tabreg->get_char ("S10") == 'X';
 | 
						||
  _stampa_num_pag   = _tabreg->get_char ("S11") == 'X';
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::compila_reg(const TMask& m)
 | 
						||
{       
 | 
						||
  int anno;
 | 
						||
  TString16 codtab = ""; 
 | 
						||
  TString16 cod_lib_un;
 | 
						||
  TDate sca_vid;
 | 
						||
  
 | 
						||
  _tipo_stampa = (tipo_stampa) m.get_int(TIPO_STAMPA);
 | 
						||
  if (_tipo_stampa == libro_unico)  //stampa su libro unico di studio
 | 
						||
    _codreg = m.get(CODICE_LIBRO_IVA);
 | 
						||
  else if (_tipo_stampa == prova) //stampa di prova
 | 
						||
    _codreg = m.get(CODICE_LIBRO_PROVA);        
 | 
						||
  else _codreg = m.get(CODICE_LIBRO);
 | 
						||
  
 | 
						||
  if (_codreg.trim().empty())
 | 
						||
  {
 | 
						||
    _stampa_tutti_i_registri = TRUE;
 | 
						||
    _tabreg->first(); 
 | 
						||
    if (!_tabreg->eof()) 
 | 
						||
    { 
 | 
						||
      codtab = _tabreg->get("CODTAB");
 | 
						||
      anno   = atoi(codtab.mid(0,4));
 | 
						||
      if (anno > _annoes) 
 | 
						||
      {
 | 
						||
        if (_tipo_stampa != libro_unico)  //per il libro unico e' gia' stato controllato nell'handler
 | 
						||
          warning_box("Non esistono registri IVA della Ditta %ld per l'anno %d", 
 | 
						||
                      _ditta, _annoes);
 | 
						||
        return FALSE;
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }  
 | 
						||
  else   // stampa un solo registro
 | 
						||
  {
 | 
						||
    _stampa_tutti_i_registri = FALSE;
 | 
						||
    codtab << _annoes << _codreg;         
 | 
						||
    _tabreg->zero();
 | 
						||
    _tabreg->put("CODTAB", codtab);
 | 
						||
    if (_tabreg->read() != NOERR)
 | 
						||
    {
 | 
						||
      if (_tipo_stampa != libro_unico)
 | 
						||
        warning_box("Il registro IVA specificato non esiste nella \n Ditta %ld", _ditta);
 | 
						||
      return FALSE;
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      _tipo_reg = (tiporeg) _tabreg->get_int("I0");
 | 
						||
      if (_tipo_reg == vendita || _tipo_reg == acquisto || _tipo_reg == riepilogativo)
 | 
						||
      {
 | 
						||
        cod_lib_un = _tabreg->get("S6"); 
 | 
						||
        sca_vid    = _tabreg->get_date("D1");
 | 
						||
        if (_tipo_stampa != prova) 
 | 
						||
          _u_data = _tabreg->get_date ("D3");
 | 
						||
        if ( _tipo_stampa == bollato || _tipo_stampa == rif_giornale )
 | 
						||
        {
 | 
						||
          if (cod_lib_un.not_empty())
 | 
						||
          {
 | 
						||
            warning_box ("Ditta %ld: sul registro non deve essere indicato il codice del libro unico", _ditta);
 | 
						||
            return FALSE;
 | 
						||
          }  
 | 
						||
          if (sca_vid.ok())
 | 
						||
            if (sca_vid.month() < _fino_a_mese)
 | 
						||
            {
 | 
						||
              warning_box ("Ditta %ld: il mese della data scadenza vidimazione riportata sul registro non deve essere inferiore al mese indicato", _ditta);
 | 
						||
              return FALSE;
 | 
						||
            }
 | 
						||
          if (_u_data.ok())
 | 
						||
            if (_data_a < _u_data)
 | 
						||
            {
 | 
						||
              return warning_box ("Ditta %ld: la data specificata non deve essere inferiore al %s (ultima data di stampa specificata sul registro)", _ditta, (const char*)_u_data.string());    
 | 
						||
            }
 | 
						||
          if (_tipo_stampa == rif_giornale) //stampa con riferimenti al libro giornale
 | 
						||
          {
 | 
						||
            TDate datas; 
 | 
						||
            bool good;
 | 
						||
            bool found = cerca_libro_gio(datas, good);
 | 
						||
            if (!found || !good)
 | 
						||
            {
 | 
						||
              warning_box ("Ditta %ld: la data indicata non deve essere superiore al %s (ultima data di stampa del libro giornale)", _ditta, (const char*)datas.string());
 | 
						||
              return FALSE;
 | 
						||
            }  
 | 
						||
          } 
 | 
						||
        }
 | 
						||
        _pagine_stampate = _tabreg->get_long("I1");
 | 
						||
        _numini          = _pagine_stampate;
 | 
						||
        _corrispettivi   = _tabreg->get_bool("B0");
 | 
						||
        _sosp_imposta    = _tabreg->get_bool("B1");
 | 
						||
        _liquidazione    = _tabreg->get_bool("B7");
 | 
						||
        _riep_liq        = _tabreg->get_bool("B6");
 | 
						||
        _stampa_cred_pre = _tabreg->get_bool("B4");
 | 
						||
        _stampa_ind_ditta = _tabreg->get_bool("B9");
 | 
						||
        _stampa_ind_comp  = _tabreg->get_bool("B5");
 | 
						||
        _stampa_plafonds  = _tabreg->get_char ("S10") == 'X';
 | 
						||
        _stampa_num_pag   = _tabreg->get_char ("S11") == 'X';
 | 
						||
        _cod_un_loc       = _tabreg->get_int ("I7");
 | 
						||
        _mese_credito     = _tabreg->get_int ("I8"); //campo nascosto sulla tabella dei registri: mese di stampa credito anno precedente
 | 
						||
        _mese_ultima_liq  = _tabreg->get_int ("I4");
 | 
						||
        _codatt           = _tabreg->get("S8");
 | 
						||
        _tipoatt          = tipo_attivita(); 
 | 
						||
        _attivita         = desc_attivita(_codatt);
 | 
						||
        _desc_lib         = _tabreg->get("S0");
 | 
						||
        _freq_riepilogo   = _tabreg->get_char("S9");
 | 
						||
      }
 | 
						||
      else return FALSE;  
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::compila_lib()
 | 
						||
{       
 | 
						||
  TTable tab_lib ("%LBU");
 | 
						||
  TString16 cod;
 | 
						||
  
 | 
						||
  cod << _annoes << _codlib;
 | 
						||
  tab_lib.zero();
 | 
						||
  tab_lib.put("CODTAB", cod);
 | 
						||
  
 | 
						||
  if (tab_lib.read() == NOERR)
 | 
						||
  {
 | 
						||
    _stampa_ind_ditta = tab_lib.get_bool("B1");
 | 
						||
    return TRUE;
 | 
						||
  }
 | 
						||
  return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::cerca_libro_gio(TDate& datas, bool& good)
 | 
						||
{       
 | 
						||
/*
 | 
						||
  TString app(4);
 | 
						||
  app.format("%04d", _annoes);
 | 
						||
  
 | 
						||
  good = FALSE;
 | 
						||
  bool found = FALSE;
 | 
						||
  
 | 
						||
  const TRecnotype rec = _tabreg->recno();
 | 
						||
  _tabreg->zero();
 | 
						||
  _tabreg->put ("CODTAB", app);
 | 
						||
  const TRectype r (_tabreg->curr());
 | 
						||
  _tabreg->read(_isgteq);
 | 
						||
  for (; !_tabreg->eof(); _tabreg->next())
 | 
						||
  {
 | 
						||
    if (_tabreg->curr() != r) break;
 | 
						||
    
 | 
						||
    tiporeg tipo_reg = (tiporeg)_tabreg->get_int("I0");
 | 
						||
    if (tipo_reg == giornale) //libro giornale
 | 
						||
    {    
 | 
						||
      datas = _tabreg->get_date("D3");  // Data ultima stampa
 | 
						||
//      if (datas < _data_a)
 | 
						||
      if (datas.month() < _data_a.month()) // CM000027
 | 
						||
        good = FALSE;     
 | 
						||
      else
 | 
						||
        good = TRUE;  
 | 
						||
      found = TRUE;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  _tabreg->readat(rec);
 | 
						||
  return found;
 | 
						||
*/
 | 
						||
  TRelation reg("REG");
 | 
						||
  TRectype& curr = reg.curr();
 | 
						||
  TString16 filter; 
 | 
						||
  filter.format("%04d", _annoes);
 | 
						||
  curr.put("CODTAB", filter);
 | 
						||
  filter.format("I0=%d", giornale);
 | 
						||
  TCursor cur(®, filter, 1, &curr, &curr);
 | 
						||
  const bool found = cur.items() > 0;
 | 
						||
  good = FALSE;
 | 
						||
  if (found)
 | 
						||
  {  
 | 
						||
    cur = 0L;
 | 
						||
    datas = curr.get_date("D3");  // Data ultima stampa
 | 
						||
    // good = datas >= _data_a; 
 | 
						||
    good = datas.month() >= _data_a.month(); // CM000027
 | 
						||
  }
 | 
						||
  return found;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::is_mese_ok(int x, int month)
 | 
						||
{
 | 
						||
  bool ret = x == month;
 | 
						||
  if (!ret && _freq_riepilogo == 'T')
 | 
						||
  {  
 | 
						||
    month += 2 - ((month-1) % 3);   
 | 
						||
    ret = x > (month - 3) && x <= month; 
 | 
						||
  }
 | 
						||
  return ret; 
 | 
						||
}
 | 
						||
 | 
						||
//********* handlers *********/
 | 
						||
 | 
						||
bool TStampa_registri_app::mask_azzera (TMask_field& f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_SPACE)
 | 
						||
  {
 | 
						||
    app()._selected.reset();  
 | 
						||
    f.mask().reset(F_SELECT);
 | 
						||
    f.mask().reset(DA_CODICE);
 | 
						||
    f.mask().reset(A_CODICE);
 | 
						||
    app()._ditte->check(-1, FALSE);
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::mask_tipo_stampa(TMask_field& f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_SPACE)
 | 
						||
  {
 | 
						||
    TMask& m = f.mask();
 | 
						||
    int tipo_stampa = m.get_int(TIPO_STAMPA);
 | 
						||
    if (tipo_stampa == 3) //stampa su libro unico
 | 
						||
    {
 | 
						||
      m.enable_page(1);
 | 
						||
      TMask_field& cc = f.mask().field(CODICE_LIB_UN);
 | 
						||
      cc.set_dirty();
 | 
						||
    }
 | 
						||
    else
 | 
						||
      m.disable_page(1);
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}  
 | 
						||
 | 
						||
bool TStampa_registri_app::mask_mese (TMask_field& f, KEY k)
 | 
						||
{      
 | 
						||
  if (k == K_SPACE)
 | 
						||
  {
 | 
						||
    const short id = f.dlg();
 | 
						||
    int mese;
 | 
						||
    if (id == MESE) //Per stampa su libro unico
 | 
						||
      mese = f.mask().get_int(MESE);
 | 
						||
    if (id == FINO_A_MESE)
 | 
						||
      mese = f.mask().get_int(FINO_A_MESE); //Per stampa su bollato
 | 
						||
    if (id == MESE)
 | 
						||
    {
 | 
						||
      if (mese == 12)
 | 
						||
      {
 | 
						||
        f.mask().show (TIPO_RIEPILOGATIVO);
 | 
						||
        f.mask().show (RIF_VID);
 | 
						||
      }  
 | 
						||
      else
 | 
						||
      {
 | 
						||
        f.mask().hide (TIPO_RIEPILOGATIVO);
 | 
						||
        f.mask().hide (RIF_VID);
 | 
						||
      }
 | 
						||
    }   
 | 
						||
    if (id == FINO_A_MESE) 
 | 
						||
    {
 | 
						||
      if (mese == 12)
 | 
						||
        f.mask().show (TIPO_RIEPILOGATIVO);
 | 
						||
      else f.mask().hide (TIPO_RIEPILOGATIVO);
 | 
						||
    }
 | 
						||
  }
 | 
						||
  if (k==K_TAB && f.mask().is_running())
 | 
						||
  {
 | 
						||
    const short id = f.dlg();
 | 
						||
    if (id == MESE)
 | 
						||
      f.mask().send_key(K_TAB, CODICE_LIBRO_IVA);  
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::look_reg(int i, int anno, TString& codlib, int m, const char* cod, int* umese, long ditta)
 | 
						||
{
 | 
						||
  TString16 y; 
 | 
						||
  
 | 
						||
  y << anno << cod;
 | 
						||
  _tabreg->zero();
 | 
						||
  _tabreg->put("CODTAB", y);
 | 
						||
 | 
						||
  if (_tabreg->read() == NOERR)
 | 
						||
  {
 | 
						||
    tiporeg tipo = (tiporeg)_tabreg->get_int("I0");
 | 
						||
    if (tipo == vendita || tipo == acquisto || tipo == riepilogativo)
 | 
						||
    {
 | 
						||
      TString16 cod_lib_un = _tabreg->get("S6");
 | 
						||
      TDate u_data = _tabreg->get_date("D3");
 | 
						||
      TDate sca_vid = _tabreg->get_date("D1");
 | 
						||
      if (codlib != cod_lib_un)
 | 
						||
      {
 | 
						||
        if (_selected.ones() == 1L)
 | 
						||
          if (_selected[i])
 | 
						||
            message_box("Ditta %ld: il codice libro unico del registro non e' uguale al codice libro unico indicato", ditta);
 | 
						||
        return FALSE;
 | 
						||
      }
 | 
						||
      if (m < *umese)
 | 
						||
      { 
 | 
						||
        if (_selected.ones() == 1L) 
 | 
						||
          if (_selected[i])
 | 
						||
            message_box("Ditta %ld: il mese indicato e' inferiore al mese dell'ultima data di stampa del registro", ditta);
 | 
						||
        return FALSE;
 | 
						||
      }   
 | 
						||
      if (u_data.ok())
 | 
						||
        *umese = u_data.month();
 | 
						||
      else *umese = 0;
 | 
						||
      
 | 
						||
      if (sca_vid.ok())
 | 
						||
        if (sca_vid.month() < m)
 | 
						||
        {
 | 
						||
          if (_selected.ones() == 1L) 
 | 
						||
            if (_selected[i])
 | 
						||
              message_box("Ditta %ld: la data scadenza di vidimazione del registro non deve essere inferiore al mese indicato", ditta);
 | 
						||
          return FALSE;
 | 
						||
        } 
 | 
						||
    }
 | 
						||
    return TRUE;   
 | 
						||
  }
 | 
						||
  return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::look_regs(int anno, TString& codlib, int m, int* umese, long ditta, TProgind* prog)
 | 
						||
{ 
 | 
						||
  int a;
 | 
						||
  TString16 codtab;
 | 
						||
  bool ok = FALSE;
 | 
						||
  *umese = 13;
 | 
						||
  
 | 
						||
  for (_tabreg->first(); !_tabreg->eof(); _tabreg->next())
 | 
						||
  { 
 | 
						||
    tiporeg tipo   = (tiporeg)_tabreg->get_int("I0");
 | 
						||
    codtab = _tabreg->get("CODTAB");
 | 
						||
    a = atoi(codtab.mid(0,4));
 | 
						||
    if (a > anno)
 | 
						||
      break;
 | 
						||
    if (a == anno)   
 | 
						||
      if (tipo == vendita || tipo == acquisto || tipo == riepilogativo) //registro iva
 | 
						||
      {
 | 
						||
        TString16 cod_lib_un = _tabreg->get("S6");
 | 
						||
        TDate     sca_vid    = _tabreg->get_date("D1");
 | 
						||
        TDate     u_data     = _tabreg->get_date("D3");
 | 
						||
        if (codlib != cod_lib_un)
 | 
						||
          continue;
 | 
						||
        if (u_data.ok())
 | 
						||
          if (m < u_data.month())
 | 
						||
            continue;
 | 
						||
        if (u_data.ok())
 | 
						||
          *umese = (*umese < u_data.month()) ? *umese : u_data.month(); 
 | 
						||
        if (sca_vid.ok())
 | 
						||
          if (sca_vid.month() < m)
 | 
						||
            continue;
 | 
						||
        int month;  
 | 
						||
        if (!u_data.ok())
 | 
						||
          month = 0;
 | 
						||
        else month = u_data.month();
 | 
						||
        if (month < m - 1)
 | 
						||
        {
 | 
						||
          prog->addstatus(1);
 | 
						||
          app().set_firm(__firm);
 | 
						||
          delete prog;
 | 
						||
          error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta);
 | 
						||
          app().stop_run();
 | 
						||
        }
 | 
						||
        ok = TRUE;  
 | 
						||
      }    
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
//funzione di controllo parametri prima di stampare su libro unico
 | 
						||
//una fra le cose piu' orrende che mi potessero capitare
 | 
						||
bool TStampa_registri_app::mask_libun (TMask_field& f, KEY k)
 | 
						||
{    
 | 
						||
  if (k==K_TAB && f.mask().is_running())
 | 
						||
  {
 | 
						||
    TString16 codlib(f.mask().get(CODICE_LIB_UN));
 | 
						||
    if (codlib.empty())
 | 
						||
    {
 | 
						||
      app()._test = TRUE;
 | 
						||
      //f.error_box("Nessun Codice Libro Unico selezionato.");
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    
 | 
						||
    if (app()._selected.ones() == 0l) 
 | 
						||
    {
 | 
						||
      //f.error_box("Nessuna ditta selezionata.");
 | 
						||
      return TRUE;
 | 
						||
    }
 | 
						||
    
 | 
						||
    TProgind* p = new TProgind(2,"Verifica parametri in corso...",FALSE,TRUE,30);
 | 
						||
    
 | 
						||
    TString16 cod(f.mask().get(CODICE_LIBRO_IVA));
 | 
						||
    int fino_a_mese = f.mask().get_int(MESE);
 | 
						||
    int  anno = f.mask().get_int(ANNO);
 | 
						||
    bool ok   = FALSE;
 | 
						||
    int last_mese = 13;
 | 
						||
    int mese = 0;
 | 
						||
    
 | 
						||
    p->addstatus(1);    
 | 
						||
    app().__firm = app().get_firm(); 
 | 
						||
    
 | 
						||
    for (int i = 0; i < app()._ditte->items(); i++)
 | 
						||
    {
 | 
						||
      long ditta = app()._ditte->row(i).get_long(1);
 | 
						||
      if (prefix().exist(ditta))
 | 
						||
      {
 | 
						||
        app().set_firm(ditta);   
 | 
						||
        if (cod.not_empty())
 | 
						||
        {
 | 
						||
          ok = app().look_reg(i,anno,codlib,fino_a_mese,cod,&mese,ditta);
 | 
						||
          if (!ok)
 | 
						||
            continue;             
 | 
						||
          if (mese < fino_a_mese - 1) //indipendentemente se si tratta di una ditta selezionata oppure no
 | 
						||
          {
 | 
						||
            p->addstatus(1);    
 | 
						||
            app().set_firm(app().__firm);
 | 
						||
            delete p;
 | 
						||
            f.error_box("Ditta %ld: Stampare i registri dei mesi precedenti", ditta);
 | 
						||
            app().stop_run();
 | 
						||
          }
 | 
						||
        }     
 | 
						||
        else
 | 
						||
        {
 | 
						||
          ok = app().look_regs(anno,codlib,fino_a_mese,&mese,ditta,p);
 | 
						||
          if (!ok)
 | 
						||
          {
 | 
						||
            if (app()._selected.ones() == 1L)  //solo se ho selezionato 1 ditta devo dare il messaggio
 | 
						||
              if (app()._selected[i])          //ed e' proprio quella selezionata
 | 
						||
              {
 | 
						||
                p->addstatus(1);    
 | 
						||
                app().set_firm(app().__firm);
 | 
						||
                delete p;
 | 
						||
                f.message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", ditta);
 | 
						||
                app().stop_run();
 | 
						||
              }  
 | 
						||
            continue;
 | 
						||
          } 
 | 
						||
        }
 | 
						||
        last_mese = (last_mese < mese) ? last_mese : mese;
 | 
						||
      }    
 | 
						||
    }             
 | 
						||
    p->addstatus(1);    
 | 
						||
    app().set_firm(app().__firm); 
 | 
						||
 | 
						||
    if (last_mese == 13)
 | 
						||
      last_mese = 0; //l'ultima data di stampa sul/sui registri specificati e' vuota  
 | 
						||
                     //(cioe' non sono ancora stati stampati sul libro unico specificato) 
 | 
						||
    TString16 me;
 | 
						||
    me.format("%02d", last_mese);   
 | 
						||
    f.mask().set(ULTIMO_MESE, me);
 | 
						||
    delete p;
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}  
 | 
						||
 | 
						||
bool TStampa_registri_app::mask_cod (TMask_field& f, KEY k)
 | 
						||
{ 
 | 
						||
  if (k == K_TAB)
 | 
						||
  {
 | 
						||
    TTable TabLbu ("%LBU");
 | 
						||
    TString codtab; 
 | 
						||
    int anno;
 | 
						||
    
 | 
						||
    TString16 codlib(f.get());
 | 
						||
    anno = f.mask().get_int(ANNO);
 | 
						||
    TabLbu.zero();
 | 
						||
    codtab.format ("%04d%-3s", anno, (const char*)codlib);
 | 
						||
    TabLbu.put ("CODTAB", codtab);
 | 
						||
    TabLbu.read();
 | 
						||
    if ( TabLbu.good() )
 | 
						||
    {
 | 
						||
      f.mask().set(ULTIMA_PAGINA,TabLbu.get_long("I1"));
 | 
						||
      app()._codice_vidi = TabLbu.get("S4");
 | 
						||
    }
 | 
						||
    if (app()._test) 
 | 
						||
    {
 | 
						||
      f.mask().send_key(K_TAB, CODICE_LIBRO_IVA);
 | 
						||
      app()._test = FALSE;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::mask_data (TMask_field& f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_TAB && f.mask().is_running())
 | 
						||
  {
 | 
						||
    const int anno = f.mask().get_int(ANNO);
 | 
						||
    TDate data(f.get());
 | 
						||
    if (data.ok()) 
 | 
						||
      if (data.year() != anno)
 | 
						||
      {
 | 
						||
        f.warning_box("L'anno delle date limite deve essere uguale all'anno iva specificato");
 | 
						||
        return FALSE;
 | 
						||
      }
 | 
						||
    if (f.dlg() == A_DATA)
 | 
						||
      if (data.ok())
 | 
						||
      {
 | 
						||
        if ( data.day() == 31 && data.month() == 12 )
 | 
						||
          f.mask().show (TIPO_RIEPILOGATIVO);
 | 
						||
        else f.mask().hide (TIPO_RIEPILOGATIVO);
 | 
						||
      }
 | 
						||
  } 
 | 
						||
  return TRUE;
 | 
						||
} 
 | 
						||
 | 
						||
bool TStampa_registri_app::year_handler(TMask_field& f, KEY key)
 | 
						||
{                                                    
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {                         
 | 
						||
    TWait_cursor hourglass;
 | 
						||
    app().set_year(atoi(f.get()));
 | 
						||
    app().build_nomiditte();
 | 
						||
    app().build_ditte_sheet();    
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
} 
 | 
						||
 | 
						||
void TStampa_registri_app::build_ditte_sheet()
 | 
						||
{
 | 
						||
  // build sheet
 | 
						||
  _ditte->destroy();
 | 
						||
  _ditte->enable_row(-1);
 | 
						||
  for (int i = 0; i < _nomiditte.items(); i++)
 | 
						||
  {
 | 
						||
    TToken_string* d = new TToken_string(64);
 | 
						||
    *d = (TToken_string&)_nomiditte[i];
 | 
						||
    const char vers = d->get_char(2);
 | 
						||
    bool selectable = vers == '?';
 | 
						||
    d->insert(" |", 0);        
 | 
						||
    const long pos = _ditte->add(d);     
 | 
						||
    if (selectable) 
 | 
						||
      _ditte->disable_row(pos);
 | 
						||
    else if (_selected[i]) 
 | 
						||
      _ditte->check(pos);
 | 
						||
  }     
 | 
						||
}
 | 
						||
 | 
						||
// --------- handlers per selezione ditte
 | 
						||
 | 
						||
bool TStampa_registri_app::to_ditt_handler(TMask_field& f, KEY key)
 | 
						||
{
 | 
						||
  TMask& m = f.mask();
 | 
						||
  if (key == K_F9)
 | 
						||
  {
 | 
						||
    TArray_sheet* sh = app().get_ditte_sheet();
 | 
						||
    TMask& m = f.mask();
 | 
						||
    
 | 
						||
    sh->disable_check();    
 | 
						||
    sh->disable(DLG_USER);
 | 
						||
    if (sh->run() == K_ENTER)
 | 
						||
    {
 | 
						||
      app().select_firm_range(m.get_long(DA_CODICE),sh->row(sh->selected()).get_long(1)); 
 | 
						||
      app().set_choice_limits(m);           
 | 
						||
    }
 | 
						||
    sh->enable(DLG_USER);
 | 
						||
  }
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); 
 | 
						||
    app().set_choice_limits(m);
 | 
						||
    m.set(F_SELECT, l);
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::fr_ditt_handler(TMask_field& f, KEY key)
 | 
						||
{                          
 | 
						||
  TMask& m = f.mask();
 | 
						||
  if (key == K_F9)
 | 
						||
  {
 | 
						||
    TMask& m = f.mask();
 | 
						||
    TArray_sheet* sh = app().get_ditte_sheet();
 | 
						||
 | 
						||
    sh->disable_check();    
 | 
						||
    sh->disable(DLG_USER);
 | 
						||
    if (sh->run() == K_ENTER)
 | 
						||
    {
 | 
						||
      app().select_firm_range(sh->row(sh->selected()).get_long(1), m.get_long(A_CODICE)); 
 | 
						||
      app().set_choice_limits(m);
 | 
						||
    }
 | 
						||
    sh->enable(DLG_USER);
 | 
						||
 }
 | 
						||
  else if (key == K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    const long l = app().select_firm_range(m.get_long(DA_CODICE), m.get_long(A_CODICE)); 
 | 
						||
    app().set_choice_limits(m);
 | 
						||
    m.set(F_SELECT, l); 
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::set_choice_limits(TMask& m)
 | 
						||
{     
 | 
						||
  long first = -1l, last = -1l;
 | 
						||
  for (int i = 0; i < _ditte->items(); i++)
 | 
						||
  {
 | 
						||
    if (_selected[i])
 | 
						||
    {
 | 
						||
      long dit = _ditte->row(i).get_long(1);
 | 
						||
      if (first == -1l) first = dit;
 | 
						||
      if (last < dit)   last  = dit;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  if (first != -1) m.set(DA_CODICE, first);                        
 | 
						||
  if (last  != -1) m.set(A_CODICE, last);                        
 | 
						||
  m.set(F_SELECT, _selected.ones());
 | 
						||
  if (m.is_running()) 
 | 
						||
    if (first != -1l) app().set_firm(first);   
 | 
						||
}
 | 
						||
 | 
						||
long TStampa_registri_app::select_firm_range(long from, long to)
 | 
						||
{
 | 
						||
  if (to == 0l) to = 99999L;                              
 | 
						||
  for (int i = 0; i < _ditte->items(); i++)
 | 
						||
  {
 | 
						||
    if (_ditte->row_disabled(i))
 | 
						||
      continue;
 | 
						||
 | 
						||
    TToken_string& d = _ditte->row(i);
 | 
						||
    const char vers = d.get_char(3);
 | 
						||
    if (vers == '?')
 | 
						||
      continue;
 | 
						||
 | 
						||
    const long cod = d.get_long(1);
 | 
						||
    if (cod >= from && cod <= to)
 | 
						||
    {
 | 
						||
      _selected.set(i); 
 | 
						||
      _ditte->check(i);
 | 
						||
    }
 | 
						||
    else 
 | 
						||
    {
 | 
						||
      _selected.set(i,FALSE);
 | 
						||
      _ditte->uncheck(i);
 | 
						||
    }
 | 
						||
  } 
 | 
						||
  return _selected.ones();
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::build_nomiditte(TProgind* pnd)
 | 
						||
{                 
 | 
						||
  _nomiditte.destroy();
 | 
						||
  // ricostruire _nomiditte e rifare build_ditte_sheet
 | 
						||
  TLocalisamfile& dt = _nditte->lfile();
 | 
						||
 | 
						||
  for (dt.first(); !dt.eof(); dt.next())
 | 
						||
  {     
 | 
						||
    // check no archivi
 | 
						||
    bool good = prefix().exist(dt.get_long("CODDITTA"));                        
 | 
						||
    if (good) 
 | 
						||
    {   
 | 
						||
      // check no parametri liquidazione                                               
 | 
						||
      if (!look_lia(dt.get_long("CODDITTA"))) good = FALSE; 
 | 
						||
    }
 | 
						||
    _n_ditte++;
 | 
						||
    TToken_string* d = new TToken_string(64);
 | 
						||
    d->add(dt.get("CODDITTA"));
 | 
						||
    d->add(dt.get("RAGSOC"));
 | 
						||
    if (good) d->add(_tablia->get("S7"));
 | 
						||
    else d->add("??");
 | 
						||
    
 | 
						||
    _nomiditte.add(d);  
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::set_ditte(TMask& m)
 | 
						||
{
 | 
						||
  m.field(TIPO_STAMPA).set("1");
 | 
						||
  m.field(DA_DATA).set("");
 | 
						||
  m.field(A_DATA).set("");
 | 
						||
  m.field(CODICE_LIBRO_PROVA).set("");
 | 
						||
  
 | 
						||
  KEY tasto;
 | 
						||
  do
 | 
						||
  {
 | 
						||
    tasto = m.run();
 | 
						||
    if (tasto == DLG_SELECT)
 | 
						||
    {
 | 
						||
      _ditte->enable_check();
 | 
						||
      // seleziona e aggiungi alle gia' selezionate 
 | 
						||
      if (_ditte->run() == K_ENTER)
 | 
						||
      {
 | 
						||
        for (long j = 0l; j < _ditte->items(); j++)
 | 
						||
          _selected.set(j, _ditte->checked(j));
 | 
						||
        set_choice_limits(m);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  } while (tasto != K_ENTER && tasto != K_QUIT);
 | 
						||
  return tasto == K_ENTER;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::user_create()
 | 
						||
{
 | 
						||
  _com    = new TLocalisamfile(LF_COMUNI);
 | 
						||
  _anag   = new TLocalisamfile(LF_ANAG);
 | 
						||
  _unloc  = new TLocalisamfile(LF_UNLOC);
 | 
						||
  _attiv  = new TLocalisamfile(LF_ATTIV);
 | 
						||
  _indlib = new TLocalisamfile(LF_INDLIB);
 | 
						||
  _clifo  = new TLocalisamfile(LF_CLIFO);
 | 
						||
  _occas  = new TLocalisamfile(LF_OCCAS);
 | 
						||
  _tabreg = new TTable("REG");
 | 
						||
  _tabpim = new TTable("PIM");
 | 
						||
  _tabprm = new TTable("PRM");
 | 
						||
  _tabprp = new TTable("PRP");
 | 
						||
  _tablia = new TTable("%LIA");
 | 
						||
  
 | 
						||
  _desc27 = new TParagraph_string("", 23);
 | 
						||
  
 | 
						||
  _nditte = new TRelation(LF_NDITTE);
 | 
						||
  
 | 
						||
  _rel    = new TRelation (LF_MOV);
 | 
						||
  _rel->add(LF_CAUSALI,"CODCAUS=CODCAUS",1,LF_MOV);
 | 
						||
  _rel->add(LF_RMOVIVA,"NUMREG=NUMREG",1,LF_MOV); 
 | 
						||
  _rel->add ("REG", "CODTAB[1,4]=ANNOIVA|CODTAB[5,7]=REG");
 | 
						||
  
 | 
						||
  _cur = new TSorted_cursor(_rel, "DATAREG|PROTIVA|NUMREG","", 2);
 | 
						||
  
 | 
						||
  _ditte = new TArray_sheet(-1, -1, -4, -4, "Selezione Ditte",
 | 
						||
                            "@1|Cod.@5R|Ragione Sociale@50|Vers.");
 | 
						||
 | 
						||
  _n_ditte = 0l;
 | 
						||
  __firm = TApplication::get_firm();
 | 
						||
 | 
						||
  TDate oggi(TODAY);                    
 | 
						||
  _annoes = oggi.year();
 | 
						||
  
 | 
						||
  build_nomiditte();            
 | 
						||
  build_ditte_sheet();
 | 
						||
  
 | 
						||
  add_cursor(_cur);
 | 
						||
  add_file(LF_MOV);
 | 
						||
  add_file(LF_RMOVIVA);
 | 
						||
  
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::user_destroy()
 | 
						||
{
 | 
						||
  delete _ditte;
 | 
						||
  delete _nditte;
 | 
						||
  delete _com;
 | 
						||
  delete _unloc;
 | 
						||
  delete _anag;
 | 
						||
  delete _attiv;
 | 
						||
  delete _indlib;
 | 
						||
  delete _clifo;
 | 
						||
  delete _occas;
 | 
						||
  delete _tabreg; 
 | 
						||
  delete _tablia;
 | 
						||
  delete _tabpim; 
 | 
						||
  delete _tabprm;
 | 
						||
  delete _tabprp;
 | 
						||
  //delete _cur;
 | 
						||
  delete _rel;
 | 
						||
  delete _desc27;
 | 
						||
  
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
//********* funzioni di calcolo e di controllo *********//
 | 
						||
 | 
						||
// Questa funzione calcola i progressivi del periodo e totali, oltre a quelli 
 | 
						||
// del periodo precedente.
 | 
						||
void TStampa_registri_app::calcola_progressivi() 
 | 
						||
{
 | 
						||
  TString80 chiave, codtab;
 | 
						||
  TString16 codreg, codiva;
 | 
						||
  int i, num=0;
 | 
						||
  
 | 
						||
  if (_tipo_stampa == libro_unico)
 | 
						||
    num = _fino_a_mese;
 | 
						||
  if ( _tipo_stampa == bollato || _tipo_stampa == rif_giornale )  
 | 
						||
    num = _datareg.month();
 | 
						||
 | 
						||
  // Chiave per selezione records progressivi
 | 
						||
  chiave << _annoes << _codatt;  
 | 
						||
 | 
						||
  
 | 
						||
  //calcolo i totali del periodo; calcola anche i totali da Periodo Precedente (se _annoes > 1997)
 | 
						||
  //_codatt e' gia' Z perche' lo leggo dal registro
 | 
						||
  //calcolo i totali progressivi e del periodo (tra questi anche quelli di cui periodo precedente)
 | 
						||
  for (i=1; i<=num; i++)
 | 
						||
  { 
 | 
						||
    int start = 0, stop = 0;
 | 
						||
    if (i == num && _annoes > 1997) // Per il mese attuale 
 | 
						||
      stop = 1;                     // si calcolano anche i progressivi precedenti a questo periodo (PRP)
 | 
						||
                                    // solo se siamo oltre il 1997
 | 
						||
      
 | 
						||
    for (int j = start; j <= stop; j++)
 | 
						||
    {
 | 
						||
      const bool calc_prp = j == 1;
 | 
						||
      TTable* tabula = calc_prp ?  _tabprp : _table ;
 | 
						||
        
 | 
						||
      tabula->zero();
 | 
						||
      tabula->put("CODTAB", chiave);
 | 
						||
      TRectype r (tabula->curr());
 | 
						||
      tabula->read(_isgteq);
 | 
						||
      for (; !tabula->eof(); tabula->next())
 | 
						||
      {
 | 
						||
        if (tabula->curr() != r) break;
 | 
						||
        codtab   = tabula->get("CODTAB");
 | 
						||
        codreg   = codtab.mid(10,3);
 | 
						||
        int mese = atoi(codtab.mid(13,2)); 
 | 
						||
        if (_codreg == codreg.trim() && mese == i)
 | 
						||
        {
 | 
						||
          codiva = codtab.mid(16,4);
 | 
						||
          int tipodet = atoi(codtab.mid(20,1));
 | 
						||
          real impo   = tabula->get_real("R0");
 | 
						||
          real impos  = tabula->get_real("R1");
 | 
						||
          real implo  = tabula->get_real("R2"); 
 | 
						||
          //se il registro e' corrispettivi l'imponibile e l'iva li trovo in S2
 | 
						||
          if (_corrispettivi) 
 | 
						||
          {
 | 
						||
            TToken_string cs (tabula->get("S2"),'!'); 
 | 
						||
            impo = cs.get(0);                 
 | 
						||
            impos = cs.get(1);
 | 
						||
          }
 | 
						||
          //se in sospensione d'imposta l'imponibile e l'iva li trovo in R11 e R12
 | 
						||
          if (_sosp_imposta) 
 | 
						||
          {
 | 
						||
            impo = tabula->get_real("R11");
 | 
						||
            impos = tabula->get_real("R12");
 | 
						||
          }
 | 
						||
          TToken_string fatt_rit (tabula->get("S1"),'!');
 | 
						||
          real im (fatt_rit.get(0));
 | 
						||
          real is (fatt_rit.get(1));
 | 
						||
          impo  += im; 
 | 
						||
          impos += is;
 | 
						||
          implo += im+is;
 | 
						||
          if (impo != ZERO || impos != ZERO || implo != ZERO)
 | 
						||
          {
 | 
						||
            if (!calc_prp && _tipo_stampa != prova)
 | 
						||
              _tot_iva_array.add_riga(ZERO,ZERO,ZERO,impo,impos,implo,codiva);  // progressivi
 | 
						||
            if (mese == num)
 | 
						||
              if (calc_prp)
 | 
						||
                _tot_prec_iva_array.add_riga(impo,impos,implo,ZERO,ZERO,ZERO,codiva); // periodo prec
 | 
						||
              else
 | 
						||
                _tot_iva_array.add_riga(impo,impos,implo,ZERO,ZERO,ZERO,codiva); // periodo
 | 
						||
          }
 | 
						||
          
 | 
						||
          if (!calc_prp && _tipo_reg == acquisto) //registro acquisti
 | 
						||
            if (impo != ZERO || impos != ZERO)
 | 
						||
            {
 | 
						||
              if (_tipo_stampa != prova)
 | 
						||
                _iva_array.add_riga(ZERO,ZERO,impo,impos,codiva,tipodet,0,TRUE); //progressivi
 | 
						||
              if (mese == num)
 | 
						||
                _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE); // periodo
 | 
						||
            } 
 | 
						||
        }   
 | 
						||
      } // for table
 | 
						||
    }   // for start to stop
 | 
						||
  }     // for i to num     
 | 
						||
}
 | 
						||
 | 
						||
int TStampa_registri_app::riga_rmoviva()
 | 
						||
{ 
 | 
						||
  TLocalisamfile& rmoviva = _cur->file(LF_RMOVIVA);
 | 
						||
  bool ok = _cur->is_first_match(LF_RMOVIVA);
 | 
						||
  if (!ok) 
 | 
						||
    return 0;
 | 
						||
 | 
						||
  TString  codiva;
 | 
						||
  real     impo, impos;
 | 
						||
  int      tipodet, tipocr, tipoatt; 
 | 
						||
  bool     intra;
 | 
						||
  
 | 
						||
  const int mese_liq = _cur->file(LF_MOV).get_int(MOV_MESELIQ);
 | 
						||
  int nrec = 0;
 | 
						||
  const TRecnotype nr = rmoviva.recno();
 | 
						||
  
 | 
						||
  while (ok)
 | 
						||
  {
 | 
						||
    nrec++;
 | 
						||
    const TRectype& iva = rmoviva.curr();
 | 
						||
    tipodet = iva.get_int(RMI_TIPODET);
 | 
						||
    tipocr  = iva.get_int(RMI_TIPOCR); 
 | 
						||
    impo    = iva.get_real(RMI_IMPONIBILE);
 | 
						||
    impos   = iva.get_real(RMI_IMPOSTA);
 | 
						||
    codiva  = iva.get(RMI_CODIVA);
 | 
						||
    intra   = iva.get_bool(RMI_INTRA); 
 | 
						||
    tipoatt = iva.get_int(RMI_TIPOATT);
 | 
						||
    
 | 
						||
    _riga_rmi.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,tipocr,intra,tipoatt);
 | 
						||
    
 | 
						||
    if (_tipo_stampa == prova) //stampa di prova, cumula progressivi dai movimenti, anziche dalle tabelle (solo bollato)
 | 
						||
    {
 | 
						||
      if (_tipodoc == "FS")
 | 
						||
      {
 | 
						||
        real somma = -(impo + impos);
 | 
						||
        _tot_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); 
 | 
						||
        if (mese_liq != 0)
 | 
						||
          _tot_prec_iva_array.add_riga(ZERO,ZERO,somma,ZERO,ZERO,ZERO,codiva); 
 | 
						||
      }      
 | 
						||
      else if (_tipodoc == "CR" || _tipodoc == "RF" || _tipodoc == "SC")
 | 
						||
      {
 | 
						||
        _tot_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva);
 | 
						||
        if (mese_liq != 0)
 | 
						||
          _tot_prec_iva_array.add_riga(ZERO,ZERO,impo+impos,ZERO,ZERO,ZERO,codiva);
 | 
						||
      }
 | 
						||
      
 | 
						||
      if (_tipodoc != "CR" && _tipodoc != "SC" && _tipodoc != "RF")
 | 
						||
      {
 | 
						||
        _tot_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); 
 | 
						||
        if (mese_liq != 0)
 | 
						||
          _tot_prec_iva_array.add_riga(impo,impos,ZERO,ZERO,ZERO,ZERO,codiva); 
 | 
						||
      }
 | 
						||
      
 | 
						||
      if (_tipo_reg == acquisto) //registro acquisti (non ha senso parlare di importi lordi)
 | 
						||
        _iva_array.add_riga(impo,impos,ZERO,ZERO,codiva,tipodet,0,TRUE);
 | 
						||
    }
 | 
						||
    
 | 
						||
    ok = _cur->next_match(LF_RMOVIVA);
 | 
						||
  }
 | 
						||
  rmoviva.readat(nr);
 | 
						||
  
 | 
						||
  return nrec;   
 | 
						||
}
 | 
						||
 | 
						||
int TStampa_registri_app::setta_riga(int r, const TRigaiva& riga, real& tot1, 
 | 
						||
                                   real& tot2, real& tot3, real& tot4)
 | 
						||
{
 | 
						||
  set_row(r, "%-4s", (const char*)riga._codiva);
 | 
						||
  TString descr = descr_iva(riga._codiva); 
 | 
						||
  set_row(r, "@5g%-.23s",(const char*)descr);
 | 
						||
  if (riga._imponibile != ZERO)
 | 
						||
    set_row(r, "@29g%r", &riga._imponibile);
 | 
						||
  if (riga._imposta != ZERO)
 | 
						||
    set_row(r, "@45g%r", &riga._imposta);
 | 
						||
  if (_tipo_stampa != prova)
 | 
						||
  {
 | 
						||
    if (riga._imponibilep != ZERO)
 | 
						||
      set_row(r, "@81g%r", &riga._imponibilep);
 | 
						||
    if (riga._impostap != ZERO)
 | 
						||
      set_row(r, "@98g%r", &riga._impostap); 
 | 
						||
  }       
 | 
						||
  r++;   // Incrementa sempre: cazzone!
 | 
						||
    
 | 
						||
  tot1 += riga._imponibile;
 | 
						||
  tot2 += riga._imposta;
 | 
						||
  tot3 += riga._imponibilep;
 | 
						||
  tot4 += riga._impostap;
 | 
						||
  
 | 
						||
  return r;
 | 
						||
}
 | 
						||
 | 
						||
messaggio TStampa_registri_app::controlla_liquidazione()
 | 
						||
{
 | 
						||
  TTable lim ("LIM");
 | 
						||
  TString mesi_cal = "";
 | 
						||
  TString16 chiave = "";
 | 
						||
  TString16 ditta  = "";
 | 
						||
  int i, mese;
 | 
						||
  bool continua;
 | 
						||
  ditta << get_firm();
 | 
						||
  
 | 
						||
  if (_tipo_stampa == prova) //stampa di prova
 | 
						||
    mese = _data_a.month();
 | 
						||
  else 
 | 
						||
    mese = _fino_a_mese;   
 | 
						||
  
 | 
						||
  if (_tipo_riepilogativo == ' ' || _tipo_riepilogativo == 'P')
 | 
						||
  {
 | 
						||
    if (_frequiva == 'T') //la LIM esiste solo per i mesi 3, 6, 9, 12
 | 
						||
    {
 | 
						||
      for (i=3; i<=mese; i+=3)
 | 
						||
      {
 | 
						||
        chiave = "";
 | 
						||
        TString16 m; m.format("%02d", i);
 | 
						||
        chiave << _annoes << m;
 | 
						||
        lim.put("CODTAB", chiave);      
 | 
						||
        if (lim.read() != NOERR || !lim.get_bool("B0"))
 | 
						||
          mesi_cal << itom(i) << "\n";
 | 
						||
      }
 | 
						||
    }                
 | 
						||
    if (_frequiva == 'M')
 | 
						||
    {
 | 
						||
      for (i=1 ; i<=mese; i++)
 | 
						||
      {
 | 
						||
        chiave = "";
 | 
						||
        TString16 m; m.format("%02d", i);
 | 
						||
        chiave << _annoes << m;
 | 
						||
        lim.put("CODTAB", chiave);
 | 
						||
        if (lim.read() != NOERR || !lim.get_bool("B0"))
 | 
						||
          mesi_cal << itom(i) << "\n"; 
 | 
						||
      } 
 | 
						||
    }      
 | 
						||
    if (mesi_cal.not_empty())
 | 
						||
    {
 | 
						||
      warning_box ("Ditta %s: la liquidazione da stampare sul registro %s relativa ai mesi di \n %s non e' stata ancora calcolata", (const char*)ditta, (const char*) _codreg, (const char *)mesi_cal);
 | 
						||
      continua = yesno_box("Si desidera ugualmente proseguire?");
 | 
						||
      if (!continua) return non_proseguire;
 | 
						||
      continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa liquidazione)");
 | 
						||
      if (!continua) return prosegui_stampa;
 | 
						||
      return prosegui_cal_stampa;
 | 
						||
    }       
 | 
						||
  }
 | 
						||
  else if (_tipo_riepilogativo == 'A')
 | 
						||
  {
 | 
						||
    chiave = "";
 | 
						||
    chiave << _annoes << 13;
 | 
						||
    lim.put("CODTAB", chiave);
 | 
						||
    if (lim.read() != NOERR || !lim.get_bool("B0"))
 | 
						||
    {
 | 
						||
      continua = yesno_box("Ditta %s: non eseguito calcolo liquidazione annuale da stampare sul registro %s. Si desidera ugualmente proseguire?", (const char*)ditta, (const char*) _codreg);
 | 
						||
      if (!continua) return non_proseguire;
 | 
						||
      continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa liquidazione)");
 | 
						||
      if (!continua) return prosegui_stampa;
 | 
						||
      return prosegui_cal_stampa;
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      bool need_refresh = FALSE;
 | 
						||
      for (int m=1; m<13; m++)
 | 
						||
         if (_frequiva == 'M' ||
 | 
						||
            (m==3 || m==6 || m==9 || m==12))
 | 
						||
         {
 | 
						||
           chiave = "";
 | 
						||
           TString16 m; m.format("%02d", m);
 | 
						||
           chiave << _annoes << m;
 | 
						||
           lim.put("CODTAB", chiave);
 | 
						||
           if (lim.read() != NOERR || !lim.get_bool("B0"))
 | 
						||
           {
 | 
						||
             need_refresh = TRUE;
 | 
						||
             break;
 | 
						||
           }
 | 
						||
         }
 | 
						||
      if (need_refresh)
 | 
						||
      {
 | 
						||
        continua = yesno_box("Ditta %s: la liquidazione di alcuni mesi precedenti deve "
 | 
						||
                             "essere ricalcolata.\n"
 | 
						||
                             "Si desidera ugualmente proseguire?",(const char*)ditta);
 | 
						||
        if (!continua) return non_proseguire;
 | 
						||
        continua = yesno_box("Si desidera proseguire con il calcolo e la stampa di liquidazione? \n (altrimenti si prosegue con la sola stampa liquidazione)");
 | 
						||
        if (!continua) return prosegui_stampa;
 | 
						||
        return prosegui_cal_stampa;
 | 
						||
      }   
 | 
						||
    }
 | 
						||
  }  
 | 
						||
  return B0_settato;   
 | 
						||
}
 | 
						||
 | 
						||
//controlla che i movimenti con anno data di registrazione < dell'anno indicato a video siano stati gia' stampati in forma definitiva*/ 
 | 
						||
//questo controllo viene fatto solo per stampa di bollato (non su libro unico)
 | 
						||
bool TStampa_registri_app::controlla_mov()
 | 
						||
{
 | 
						||
  TLocalisamfile mov (LF_MOV);
 | 
						||
  bool ok = TRUE;
 | 
						||
  tiporeg tipo;
 | 
						||
  TString16 ditta = "";
 | 
						||
  TRecnotype rec = _tabreg->recno();
 | 
						||
  for (mov.first(); !mov.eof(); mov.next())
 | 
						||
  {
 | 
						||
    const TString16 reg = mov.get(MOV_REG);
 | 
						||
    if (reg.empty()) continue; //non e' un movimento iva
 | 
						||
    TDate datareg = mov.get_date(MOV_DATAREG);
 | 
						||
    if (_stampa_tutti_i_registri)
 | 
						||
      tipo = cerca_reg (reg);
 | 
						||
    if ( (_stampa_tutti_i_registri && (tipo == vendita || tipo == acquisto || tipo == riepilogativo))
 | 
						||
        || (!_stampa_tutti_i_registri && reg == _codreg) )
 | 
						||
    {    
 | 
						||
      bool stampato = mov.get_bool(MOV_REGST);
 | 
						||
      if ( datareg.year() < _annoes )
 | 
						||
      {  
 | 
						||
        long numreg   = mov.get_long(MOV_NUMREG);
 | 
						||
        if (!stampato)
 | 
						||
          ok = FALSE;
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  _tabreg->readat(rec);
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
tiporeg TStampa_registri_app::cerca_reg(const TString& c)
 | 
						||
{
 | 
						||
  tiporeg t;
 | 
						||
  TString16 cod = "";
 | 
						||
  
 | 
						||
  t = vendita;
 | 
						||
  cod << _annoes << c;
 | 
						||
  _tabreg->zero();
 | 
						||
  _tabreg->put("CODTAB", cod); 
 | 
						||
  if (_tabreg->read() == NOERR)
 | 
						||
    t = (tiporeg)_tabreg->get_int ("I0");
 | 
						||
  return t;
 | 
						||
}
 | 
						||
 | 
						||
/*
 | 
						||
bool TStampa_registri_app::ventilazione(const char* iva)
 | 
						||
{
 | 
						||
  const TString16 chiave = iva;
 | 
						||
  const TRectype& rec = cache().get("%IVA", chiave);
 | 
						||
  const TString& vent = rec.get("S1");
 | 
						||
  return vent == "VE";
 | 
						||
}
 | 
						||
*/
 | 
						||
 | 
						||
int TStampa_registri_app::stampa_prospetto(int rr, bool print_prec)
 | 
						||
{
 | 
						||
  TString riga(_stampa_width);
 | 
						||
 | 
						||
  if (!print_prec) // Stampa il prospetto iniziale per progressivi attuali (periodo)
 | 
						||
  {
 | 
						||
    reset_print();
 | 
						||
    riga.fill('-');
 | 
						||
    set_row(rr, "%s", (const char*)riga);
 | 
						||
    rr++;
 | 
						||
    set_row(rr, "Legenda Tipo Operazione:  1=operazione intracomunitaria  2=AF art.34 comma 3");  
 | 
						||
    if (_auto_intraf)
 | 
						||
      set_row(rr, "@78g3=operazione intracomunitaria e AF art.34 comma 3");
 | 
						||
    rr++;
 | 
						||
    
 | 
						||
    _stampa = _st_tot_fin;
 | 
						||
    if (_stampa)
 | 
						||
    {
 | 
						||
      set_row(++rr, "Tipo documento@54gTotale documento");
 | 
						||
      rr+=2; 
 | 
						||
      for (int j = 0; j < _doc_array.items(); j++)
 | 
						||
      {
 | 
						||
        TTipodoc& doc = (TTipodoc&)_doc_array[j];
 | 
						||
        set_row(rr, "%2s",    (const char*) doc._tipodoc);
 | 
						||
        set_row(rr, "@3g%s",  (const char*) doc._descrdoc);
 | 
						||
        set_row(rr, "@54g%r", &doc._totdoc); 
 | 
						||
        rr++;
 | 
						||
      }
 | 
						||
      _doc_array.destroy(); 
 | 
						||
    } 
 | 
						||
 | 
						||
    if (_stampa && _tipo_reg == acquisto)
 | 
						||
    {
 | 
						||
      if (_stampa_cred_pre && _datareg.month() == 1 && _credito > ZERO)
 | 
						||
      {
 | 
						||
        set_row (++rr, "** CREDITO INIZIO ANNO @39g%r", &_credito);
 | 
						||
        rr++;
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  
 | 
						||
  if (_esiste_riga_iva && _stampa)
 | 
						||
  {
 | 
						||
    if (print_prec)
 | 
						||
      set_row(++rr, "DI CUI PERIODO PRECEDENTE");
 | 
						||
    
 | 
						||
    if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
      set_row(++rr, "@30g------------------ P E R I O D O -------------------");
 | 
						||
    else
 | 
						||
      set_row(++rr, "@30g---------- P E R I O D O -----------");
 | 
						||
    if (_tipo_stampa != prova && !print_prec)
 | 
						||
    {
 | 
						||
      if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
        set_row(rr,"@84g----------- P R O G R E S S I V I --------------");
 | 
						||
      else
 | 
						||
        set_row(rr,"@82g------ P R O G R E S S I V I ------");
 | 
						||
    }
 | 
						||
    rr++;
 | 
						||
    set_row(rr, "Cod.");
 | 
						||
    if (_tipo_reg == acquisto)
 | 
						||
    {
 | 
						||
      set_row(rr, "@40gA C Q U I S T I");
 | 
						||
      if (_tipo_stampa != prova && !print_prec)
 | 
						||
        set_row(rr, "@92gA C Q U I S T I");
 | 
						||
    }
 | 
						||
    if (_tipo_reg == vendita) //un registro corrispettivi puo' solo essere un registro vendite 
 | 
						||
    {
 | 
						||
      set_row(rr, "@41gV E N D I T E");
 | 
						||
      if (_corrispettivi)
 | 
						||
        set_row(rr, "@67gCORRISPETTIVI");
 | 
						||
      if (_tipo_stampa != prova && !print_prec)
 | 
						||
      {  
 | 
						||
        if (_corrispettivi)
 | 
						||
          set_row(rr, "@94gV E N D I T E@118gCORRISPETTIVI"); 
 | 
						||
        else
 | 
						||
          set_row(rr, "@93gV E N D I T E");
 | 
						||
      }  
 | 
						||
    }      
 | 
						||
    rr++;
 | 
						||
    set_row(rr, "iva  Descrizione@34gImponibile@53gImposta");
 | 
						||
    if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
      set_row(rr, "@67gImporti lordi");
 | 
						||
    if (_tipo_stampa != prova && !print_prec)
 | 
						||
    {
 | 
						||
      if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
        set_row(rr++, "@87gImponibile@107gImposta@118gImporti lordi");
 | 
						||
      else
 | 
						||
        set_row(rr++, "@86gImponibile@106gImposta");
 | 
						||
    }
 | 
						||
    else rr++;
 | 
						||
    rr++;
 | 
						||
  }
 | 
						||
  return rr;  
 | 
						||
}  
 | 
						||
 | 
						||
//*** stampa "tipi di indetraibilita'" : solo per gli acquisti! ***//
 | 
						||
int TStampa_registri_app::stampa_acquisti(int row)
 | 
						||
{
 | 
						||
  real tot_imponib, tot_imposta, tot_imponibp, tot_impostap;
 | 
						||
  row+=2;
 | 
						||
  int tdetprec = -1;
 | 
						||
  int rw = row;
 | 
						||
  tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
  
 | 
						||
  _iva_array.sort(compare_fields);
 | 
						||
  for (int s = 0; s < _iva_array.items(); s++)
 | 
						||
  {
 | 
						||
    TRigaiva& riga = (TRigaiva&)_iva_array[s];
 | 
						||
    switch (riga._tipodet)
 | 
						||
    {
 | 
						||
     case 1: 
 | 
						||
       if (tdetprec == 3 || tdetprec == 9)
 | 
						||
       {
 | 
						||
        set_row(++rw, "TOTALE");
 | 
						||
        if (tot_imponib != ZERO)
 | 
						||
          set_row(rw, "@29g%r", &tot_imponib);
 | 
						||
        if (tot_imposta != ZERO)
 | 
						||
          set_row(rw, "@45g%r", &tot_imposta);
 | 
						||
        if (_tipo_stampa != prova)
 | 
						||
        {
 | 
						||
         if (tot_imponibp != ZERO)
 | 
						||
           set_row(rw, "@81g%r", &tot_imponibp);
 | 
						||
         if (tot_impostap != ZERO)
 | 
						||
           set_row(rw, "@98g%r", &tot_impostap);
 | 
						||
        }  
 | 
						||
        tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
        rw+=2;        
 | 
						||
       }
 | 
						||
       if (riga._tipodet != tdetprec)
 | 
						||
       {    
 | 
						||
        set_row(rw++, "----- Indetraibile su op.es. -----");
 | 
						||
        set_row(rw, "Cod.");
 | 
						||
        rw++;
 | 
						||
        set_row(rw, "iva  Descrizione@34gImponibile@53gImposta");
 | 
						||
        if (_tipo_stampa != prova) set_row(rw, "@86gImponibile@106gImposta"); 
 | 
						||
        rw+=2;
 | 
						||
       } 
 | 
						||
       rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap);
 | 
						||
       tdetprec = riga._tipodet;
 | 
						||
       break;
 | 
						||
     case 3: 
 | 
						||
       if (tdetprec == 1 || tdetprec == 9)
 | 
						||
       {
 | 
						||
        set_row(++rw, "TOTALE");
 | 
						||
        if (tot_imponib != ZERO)
 | 
						||
          set_row(rw, "@29g%r", &tot_imponib);
 | 
						||
        if (tot_imposta != ZERO)
 | 
						||
          set_row(rw, "@45g%r", &tot_imposta);
 | 
						||
        if (_tipo_stampa != prova)
 | 
						||
        {
 | 
						||
         if (tot_imponibp != ZERO)
 | 
						||
           set_row(rw, "@81g%r", &tot_imponibp);
 | 
						||
         if (tot_impostap != ZERO)
 | 
						||
           set_row(rw, "@98g%r", &tot_impostap);
 | 
						||
        }  
 | 
						||
        tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
        rw+=2;        
 | 
						||
       }   
 | 
						||
       if (riga._tipodet != tdetprec)
 | 
						||
       { 
 | 
						||
        set_row(rw++, "----- Passaggi interni -----");
 | 
						||
        set_row(rw, "Cod.");
 | 
						||
        rw++;
 | 
						||
        set_row(rw, "iva  Descrizione@34gImponibile@53gImposta");
 | 
						||
        if (_tipo_stampa != prova)
 | 
						||
          set_row(rw, "@86gImponibile@106gImposta");
 | 
						||
        rw+=2;             
 | 
						||
       }
 | 
						||
       rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap);
 | 
						||
       tdetprec = riga._tipodet;
 | 
						||
       break;
 | 
						||
     case 9: 
 | 
						||
       if (tdetprec == 1 || tdetprec == 3)
 | 
						||
       {
 | 
						||
        set_row(++rw, "TOTALE");
 | 
						||
        if (tot_imponib != ZERO)
 | 
						||
          set_row(rw, "@29g%r", &tot_imponib);
 | 
						||
        if (tot_imposta != ZERO)
 | 
						||
          set_row(rw, "@45g%r", &tot_imposta);
 | 
						||
        if (_tipo_stampa != prova) 
 | 
						||
        {
 | 
						||
         if (tot_imponibp != ZERO)
 | 
						||
           set_row(rw, "@81g%r", &tot_imponibp);
 | 
						||
         if (tot_impostap != ZERO)
 | 
						||
           set_row(rw, "@98g%r", &tot_impostap); 
 | 
						||
        }
 | 
						||
        tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
        rw+=2;
 | 
						||
       }
 | 
						||
       if (riga._tipodet != tdetprec)
 | 
						||
       {  
 | 
						||
        set_row(rw++, "----- N.D. 9 - acquisti indeducibili per ART.19 -----");
 | 
						||
        set_row(rw, "Cod.");
 | 
						||
        rw++;
 | 
						||
        set_row(rw, "iva  Descrizione@34gImponibile@53gImposta");
 | 
						||
        if (_tipo_stampa != prova)
 | 
						||
          set_row(rw, "@86gImponibile@106gImposta");
 | 
						||
        rw+=2;
 | 
						||
       }
 | 
						||
       rw = setta_riga(rw, riga, tot_imponib, tot_imposta, tot_imponibp, tot_impostap);
 | 
						||
       tdetprec = riga._tipodet; 
 | 
						||
       break;
 | 
						||
     default: break;                         
 | 
						||
    }
 | 
						||
  }  
 | 
						||
  if (_iva_array.items() > 0)
 | 
						||
    if (tdetprec == 1 || tdetprec == 3 || tdetprec == 9)
 | 
						||
    {
 | 
						||
     set_row(++rw, "TOTALE");
 | 
						||
     if (tot_imponib != ZERO)
 | 
						||
       set_row(rw, "@29g%r", &tot_imponib);
 | 
						||
     if (tot_imposta != ZERO)
 | 
						||
       set_row(rw, "@45g%r", &tot_imposta);
 | 
						||
     if (_tipo_stampa != prova)
 | 
						||
     {
 | 
						||
      if (tot_imponibp != ZERO)
 | 
						||
        set_row(rw, "@81g%r", &tot_imponibp);
 | 
						||
      if (tot_impostap != ZERO)
 | 
						||
        set_row(rw, "@98g%r", &tot_impostap);
 | 
						||
     }
 | 
						||
    }   
 | 
						||
  _iva_array.destroy(); 
 | 
						||
  rw++;
 | 
						||
  return rw;
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::set_page_tot_reg()
 | 
						||
{
 | 
						||
  int rr=1;
 | 
						||
  
 | 
						||
  rr = stampa_prospetto(rr, FALSE);
 | 
						||
  
 | 
						||
  if (_esiste_riga_iva && _stampa)
 | 
						||
  {  
 | 
						||
    for (int prospetto = 0; prospetto < 2; prospetto++)
 | 
						||
    {
 | 
						||
      TRiga_array& array = prospetto == 0 ? _tot_iva_array : _tot_prec_iva_array;
 | 
						||
      
 | 
						||
      real tot_imponib, tot_imposta, tot_lordo, tot_imponibp, tot_impostap, tot_lordop;
 | 
						||
      tot_imponib = tot_imposta = tot_lordo = tot_imponibp = tot_impostap = tot_lordop = ZERO;
 | 
						||
      
 | 
						||
      array.sort(compare_rows); //viene ordinato per codice iva
 | 
						||
      
 | 
						||
      for (int k = 0; k < array.items(); k++) // Mamma mia, mamma mia...
 | 
						||
      {
 | 
						||
        TRiga& riga = (TRiga&)array[k];
 | 
						||
 | 
						||
        if (_tipo_stampa == prova && riga._imponibile == ZERO && riga._imposta == ZERO && riga._implordo == ZERO)
 | 
						||
          continue;
 | 
						||
 | 
						||
        set_row(rr, "%-4s", (const char*)riga._codiva);
 | 
						||
        TString80 descr = descr_iva(riga._codiva);
 | 
						||
        set_row(rr, "@5g%-.23s",(const char*)descr);
 | 
						||
        if (riga._imponibile != ZERO)
 | 
						||
          set_row(rr, "@29g%r", &riga._imponibile);
 | 
						||
        if (riga._imposta != ZERO)
 | 
						||
          set_row(rr, "@45g%r", &riga._imposta);
 | 
						||
        if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
          if (riga._implordo != ZERO)
 | 
						||
            set_row(rr, "@65g%r", &riga._implordo);
 | 
						||
        if (_tipo_stampa != prova)
 | 
						||
        {   
 | 
						||
          if (riga._imponibilep != ZERO)
 | 
						||
            set_row(rr, "@81g%r", &riga._imponibilep);
 | 
						||
          if (riga._impostap != ZERO)
 | 
						||
            set_row(rr, "@98g%r", &riga._impostap);
 | 
						||
          if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
            if (riga._implordop != ZERO)
 | 
						||
              set_row(rr, "@116g%r", &riga._implordop);    
 | 
						||
        }
 | 
						||
        rr++;  
 | 
						||
        tot_imponib += riga._imponibile;
 | 
						||
        tot_imposta += riga._imposta;
 | 
						||
        tot_lordo   += riga._implordo;
 | 
						||
        tot_imponibp+= riga._imponibilep;
 | 
						||
        tot_impostap+= riga._impostap;
 | 
						||
        tot_lordop  += riga._implordop;
 | 
						||
      }  
 | 
						||
      array.destroy(); // Azzera il marciume
 | 
						||
      rr++;
 | 
						||
      set_row(rr, "TOTALE");
 | 
						||
      if (tot_imponib != ZERO)
 | 
						||
        set_row(rr, "@29g%r", &tot_imponib);
 | 
						||
      if (tot_imposta != ZERO)
 | 
						||
        set_row(rr, "@45g%r", &tot_imposta);
 | 
						||
      if (_tipo_reg == vendita && _corrispettivi)
 | 
						||
        if (tot_lordo != ZERO) 
 | 
						||
          set_row(rr, "@65g%r", &tot_lordo);
 | 
						||
      if (_tipo_stampa != prova)
 | 
						||
      {
 | 
						||
        if (tot_imponibp != ZERO)
 | 
						||
          set_row(rr, "@81g%r", &tot_imponibp);
 | 
						||
        if (tot_impostap != ZERO)
 | 
						||
          set_row(rr, "@98g%r", &tot_impostap);   
 | 
						||
        if (_tipo_reg == vendita && _corrispettivi) 
 | 
						||
          if (tot_lordop != ZERO)
 | 
						||
            set_row(rr, "@116g%r", &tot_lordop);
 | 
						||
      } 
 | 
						||
      if (prospetto == 0) // Solo per il primo prospetto complessivo
 | 
						||
      {
 | 
						||
        if (_tipo_reg == acquisto)
 | 
						||
          rr = stampa_acquisti(rr); 
 | 
						||
        else
 | 
						||
          rr += 3;
 | 
						||
        
 | 
						||
        if (_tot_prec_iva_array.items() > 0)
 | 
						||
          rr = stampa_prospetto(rr, TRUE); // Prospetto per progressivi da periodo precedente
 | 
						||
        else
 | 
						||
          break;
 | 
						||
      }
 | 
						||
    } // for
 | 
						||
  }
 | 
						||
  if (_stampa_plafonds)
 | 
						||
    stampa_plafonds(rr);
 | 
						||
}
 | 
						||
 | 
						||
HIDDEN void print_real(TPrintrow& row, const real& num, int pos) 
 | 
						||
{
 | 
						||
  const TCurrency cur(num);
 | 
						||
  TString80 str = cur.string(TRUE);
 | 
						||
  str.right_just(15);
 | 
						||
  row.put(str, pos);
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::stampa_plafonds(int r, bool test_mode)
 | 
						||
{
 | 
						||
  TTable pla ("%PLA");  
 | 
						||
  TTable ppa ("PPA"); 
 | 
						||
  TString80 chiave;
 | 
						||
  int num;
 | 
						||
  real r1, r2, r3, r8, r8b, r9, disponibile;
 | 
						||
  
 | 
						||
  r1 = r2 = r3 = ZERO;
 | 
						||
  
 | 
						||
  if (_tipo_stampa == libro_unico)
 | 
						||
    num = _fino_a_mese;
 | 
						||
  if ( _tipo_stampa == bollato || _tipo_stampa == prova || _tipo_stampa == rif_giornale )  
 | 
						||
    num = _datareg.month();
 | 
						||
  
 | 
						||
  TString16 nm; nm.format("%02d", num);
 | 
						||
  
 | 
						||
  // forza il tipoatt a 1
 | 
						||
  //char buf[10]; strcpy(buf,_codatt);
 | 
						||
  //buf[strlen(buf) - 1] = '1';
 | 
						||
  
 | 
						||
  chiave.format("%05ld", get_firm());
 | 
						||
  chiave << _annoes;
 | 
						||
  chiave << _codatt << "1";
 | 
						||
  pla.put("CODTAB", chiave);
 | 
						||
  
 | 
						||
  const bool print_now = r == -1;
 | 
						||
  TPrintrow riga;
 | 
						||
  TPrinter& pr = printer();
 | 
						||
  
 | 
						||
  if (pla.read() == NOERR)
 | 
						||
  {
 | 
						||
    r1  = pla.get_real("R5"); //totali esp. art.8
 | 
						||
    r2  = pla.get_real("R6"); //totali esp. art.8 bis
 | 
						||
    r3  = pla.get_real("R7"); //totali esp. art 9
 | 
						||
    r8  = stampa_valori_plafonds(r1, num, ppa, "1"); // Disponibile art. 8
 | 
						||
    r8b = stampa_valori_plafonds(r2, num, ppa, "2"); // Disponibile art. 8 bis
 | 
						||
    r9  = stampa_valori_plafonds(r3, num, ppa, "3"); // Disponibile art. 9
 | 
						||
    disponibile = r8 + r8b + r9;
 | 
						||
  }
 | 
						||
  
 | 
						||
  const bool print_prospect = (r1 > ZERO || r2 > ZERO || r3 > ZERO) && disponibile > ZERO;
 | 
						||
  
 | 
						||
  if (test_mode)
 | 
						||
    return print_prospect;
 | 
						||
  
 | 
						||
  if (print_prospect)
 | 
						||
  {
 | 
						||
    if (print_now)
 | 
						||
    {
 | 
						||
      riga.reset();
 | 
						||
      pr.print(riga);
 | 
						||
      riga.put("QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS",0);
 | 
						||
      pr.print(riga);
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      set_row(++r, "QUADRO RELATIVO ALLA DISPONIBILITA' E UTILIZZAZIONE MENSILE DEI PLAFONDS");
 | 
						||
      r++;
 | 
						||
    }
 | 
						||
    TString mese(9);
 | 
						||
    mese = itom(num);
 | 
						||
    mese.right_just();
 | 
						||
 | 
						||
    if (print_now)
 | 
						||
    {
 | 
						||
      riga.reset();
 | 
						||
      pr.print(riga);
 | 
						||
      riga.put((const char*)mese, 0);
 | 
						||
      riga.put("Disponibile", 35);
 | 
						||
      print_real(riga, disponibile, 55);
 | 
						||
      pr.print(riga);
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      set_row(++r, "%s@35gDisponibile @55g%r", (const char*) mese, &disponibile);
 | 
						||
      set_row(++r, ""); 
 | 
						||
      r++;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  else
 | 
						||
    return FALSE;
 | 
						||
  
 | 
						||
  const bool is_bollato = _tipo_stampa == bollato;
 | 
						||
  
 | 
						||
  if (r1 > ZERO) 
 | 
						||
  {
 | 
						||
    if (r8 > ZERO && is_bollato || !is_bollato && !r8.is_zero())
 | 
						||
    {
 | 
						||
      real pri = ZERO;
 | 
						||
      real pre = ZERO;
 | 
						||
      chiave = "";
 | 
						||
      chiave << _annoes << _codatt << "1" << nm << "1";
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        pri = ppa.get_real("R0"); 
 | 
						||
        pre = ppa.get_real("R1");
 | 
						||
      }
 | 
						||
      chiave = "";
 | 
						||
      chiave << _annoes << _codatt << "2" << nm << "1";
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        pri += ppa.get_real("R0"); 
 | 
						||
        pre += ppa.get_real("R1");
 | 
						||
      }
 | 
						||
      disponibile -= pri + pre;
 | 
						||
      if (print_now)
 | 
						||
      {
 | 
						||
        riga.reset();
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("ART. 8 1<> comma lettere a-b", 0);
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("Utilizzato all'interno",0);
 | 
						||
        print_real(riga, pri, 55);
 | 
						||
 | 
						||
 
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("Utilizzato per l'importazione",0);
 | 
						||
        print_real(riga, pre, 55);
 | 
						||
        pr.print(riga);
 | 
						||
      }
 | 
						||
      else
 | 
						||
      {
 | 
						||
        set_row(r++, "ART. 8 1<> comma lettere a-b");
 | 
						||
        set_row(r++, "Utilizzato all'interno@55g%r", &pri);
 | 
						||
        set_row(r++, "Utilizzato per l'importazione@55g%r", &pre);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (r2 > ZERO) 
 | 
						||
  {
 | 
						||
    if (r8b > ZERO && is_bollato || !is_bollato && !r8b.is_zero())
 | 
						||
    {
 | 
						||
      real pri = ZERO;
 | 
						||
      real pre = ZERO;
 | 
						||
      chiave = ""; 
 | 
						||
      chiave << _annoes << _codatt << "1" << nm << "2";
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        pri = ppa.get_real("R0"); 
 | 
						||
        pre = ppa.get_real("R1");
 | 
						||
      } 
 | 
						||
      chiave = "";
 | 
						||
      chiave << _annoes << _codatt << "2" << nm << "2";
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        pri += ppa.get_real("R0"); 
 | 
						||
        pre += ppa.get_real("R1");
 | 
						||
      }
 | 
						||
      disponibile -= pri + pre;
 | 
						||
      r++;
 | 
						||
      if (print_now)
 | 
						||
      {
 | 
						||
        riga.reset();
 | 
						||
        pr.print(riga); pr.print(riga);
 | 
						||
        riga.put("ART. 8 bis 1<> comma", 0);
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("Utilizzato all'interno",0);
 | 
						||
        print_real(riga, pri, 55);
 | 
						||
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("Utilizzato per l'importazione",0);
 | 
						||
        print_real(riga, pre, 55);
 | 
						||
        pr.print(riga);
 | 
						||
      }
 | 
						||
      else
 | 
						||
      {
 | 
						||
        set_row(r++, "ART. 8 bis 1<> comma");
 | 
						||
        set_row(r++, "Utilizzato all'interno@55g%r", &pri);
 | 
						||
        set_row(r++, "Utilizzato per l'importazione@55g%r", &pre);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (r3 > ZERO) 
 | 
						||
  {
 | 
						||
    if (r9 > ZERO && is_bollato || !is_bollato && !r9.is_zero())
 | 
						||
    {
 | 
						||
      real pri = ZERO;
 | 
						||
      real pre = ZERO;
 | 
						||
      chiave = "";
 | 
						||
      chiave << _annoes << _codatt << "1" << nm << "3";
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        pri = ppa.get_real("R0"); 
 | 
						||
        pre = ppa.get_real("R1");
 | 
						||
      }
 | 
						||
      chiave = "";
 | 
						||
      chiave << _annoes << _codatt << "2" << nm << "3";
 | 
						||
      ppa.put("CODTAB", chiave);                    
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        pri += ppa.get_real("R0"); 
 | 
						||
        pre += ppa.get_real("R1");
 | 
						||
      }
 | 
						||
      disponibile -= pri + pre;
 | 
						||
      r++;
 | 
						||
      if (print_now)
 | 
						||
      {
 | 
						||
        riga.reset();
 | 
						||
        pr.print(riga);pr.print(riga);
 | 
						||
        riga.put("ART. 9 1<> comma", 0);
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("Utilizzato all'interno",0);
 | 
						||
        print_real(riga, pri, 55);
 | 
						||
        pr.print(riga);
 | 
						||
        riga.reset();
 | 
						||
        riga.put("Utilizzato per l'importazione",0);
 | 
						||
        print_real(riga, pre, 55);
 | 
						||
        pr.print(riga);
 | 
						||
      }
 | 
						||
      else
 | 
						||
      {
 | 
						||
        set_row(r++, "ART. 9 1<> comma");
 | 
						||
        set_row(r++, "Utilizzato all'interno@55g%r", &pri);
 | 
						||
        set_row(r++, "Utilizzato per l'importazione@55g%r", &pre);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }  
 | 
						||
  if (r1 > ZERO || r2 > ZERO || r3 > ZERO)
 | 
						||
    if (print_now)
 | 
						||
    {
 | 
						||
      riga.reset();
 | 
						||
      pr.print(riga);
 | 
						||
      riga.put("Riporto",35);
 | 
						||
      print_real(riga, disponibile, 55);
 | 
						||
      pr.print(riga);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      set_row(++r, "@35gRiporto     @55g%r", &disponibile);
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
real TStampa_registri_app::stampa_valori_plafonds(const real& r1, const int mese, TTable& ppa, const char* tipo)
 | 
						||
{ 
 | 
						||
  real r, si8, se8;
 | 
						||
  TString80 chiave;
 | 
						||
  int i;
 | 
						||
  
 | 
						||
  r = r1;
 | 
						||
  si8 = se8 = ZERO;
 | 
						||
  if (mese > 1)
 | 
						||
  {
 | 
						||
    for (i=1; i<mese; i++)
 | 
						||
    {
 | 
						||
      chiave = "";
 | 
						||
      TString16 m; m.format("%02d", i);
 | 
						||
      chiave << _annoes << _codatt << "1" << m << tipo;
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        si8 += ppa.get_real("R0");
 | 
						||
        se8 += ppa.get_real("R1");
 | 
						||
      }
 | 
						||
      chiave = "";
 | 
						||
      chiave << _annoes << _codatt << "2" << m << tipo;
 | 
						||
      ppa.put("CODTAB", chiave);
 | 
						||
      if (ppa.read() == NOERR)
 | 
						||
      {
 | 
						||
        si8 += ppa.get_real("R0");
 | 
						||
        se8 += ppa.get_real("R1");
 | 
						||
      }  
 | 
						||
    }
 | 
						||
    r = r1 - si8 - se8;
 | 
						||
  }
 | 
						||
  return r;
 | 
						||
}     
 | 
						||
 | 
						||
//********* PRINT!!! *********//
 | 
						||
 | 
						||
bool TStampa_registri_app::preprocess_print(int file, int counter)
 | 
						||
{ 
 | 
						||
  if (file == LF_MOV)
 | 
						||
  {       
 | 
						||
    long items = _cur->items();
 | 
						||
    if (!items)
 | 
						||
      return FALSE;
 | 
						||
    _iva_array.destroy();
 | 
						||
    _riga_rmi.destroy();
 | 
						||
    _tot_iva_array.destroy();
 | 
						||
    _tot_prec_iva_array.destroy();
 | 
						||
    _doc_array.destroy();
 | 
						||
    _dataregp  = "";
 | 
						||
    _esiste_riga_iva = FALSE;
 | 
						||
    _auto_intraf = FALSE;
 | 
						||
    _intesta_liq = FALSE;
 | 
						||
    set_print_zero();
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
} 
 | 
						||
 | 
						||
bool TStampa_registri_app::preprocess_page(int file, int counter)
 | 
						||
{ 
 | 
						||
  if (file == LF_MOV)
 | 
						||
  {
 | 
						||
    if (counter) return TRUE; 
 | 
						||
    
 | 
						||
    reset_print();
 | 
						||
    int rr = 0, riga = 0;
 | 
						||
    bool intra;
 | 
						||
    TString80 comune, prov, comcf, capcf, civcf, stacf;
 | 
						||
    TString80 viacf;
 | 
						||
    TString ragsoc, codfis, piva;
 | 
						||
    TString tipo_op = "";
 | 
						||
 | 
						||
    TLocalisamfile& mov  = _cur->file(LF_MOV);
 | 
						||
    TLocalisamfile& caus = _cur->file(LF_CAUSALI);
 | 
						||
    
 | 
						||
    _datareg = mov.get_date(MOV_DATAREG);
 | 
						||
    
 | 
						||
    if (_tipo_stampa != libro_unico && _liquidazione)
 | 
						||
    {
 | 
						||
      const int da = (_tipo_stampa == prova) ? _data_da.month() : 1;
 | 
						||
      const int a = _datareg.month();
 | 
						||
      for (int m = da; m < a; m++)
 | 
						||
      {
 | 
						||
        if (!_st_liq[m])
 | 
						||
          if (stampo_liquidazione(m))
 | 
						||
          {
 | 
						||
            _datareg = TDate(1, m, _annoes); // Meglio cosi'
 | 
						||
            TFilename t;
 | 
						||
            t.temp("reg");    
 | 
						||
            if (_scelta == B0_settato || _scelta == prosegui_stampa)
 | 
						||
            {
 | 
						||
              if (_tipo_stampa == prova)
 | 
						||
                send_message('S',t, m); 
 | 
						||
              else 
 | 
						||
                send_message('s',t, m);
 | 
						||
            }
 | 
						||
            else //_scelta == prosegui_cal_stampa
 | 
						||
            {
 | 
						||
              if (_tipo_stampa == prova)
 | 
						||
                send_message('L', t, m);  
 | 
						||
              else
 | 
						||
                send_message('l', t, m);   
 | 
						||
            }
 | 
						||
            //TString80 nomef; nomef = t.path(); nomef << "\\" << t.name();
 | 
						||
            //if (fexist(nomef))
 | 
						||
            if (t.exist())
 | 
						||
            {  
 | 
						||
              _intesta_liq = TRUE; 
 | 
						||
              if (!_mov_empty) printer().formfeed();
 | 
						||
              merge_export_file(t,FALSE,TRUE); 
 | 
						||
              _intesta_liq = FALSE; 
 | 
						||
              reset_print();
 | 
						||
              remove(t);
 | 
						||
            }  
 | 
						||
          }
 | 
						||
        _st_liq[m] = TRUE;
 | 
						||
      }
 | 
						||
    }
 | 
						||
    
 | 
						||
    _datareg = mov.get_date(MOV_DATAREG);
 | 
						||
    _mov_empty = FALSE;
 | 
						||
 | 
						||
    if ( _datareg.month() != _dataregp.month() && _dataregp.ok() )
 | 
						||
    {
 | 
						||
      _auto_intraf = FALSE;  
 | 
						||
      printer().formfeed();
 | 
						||
    }
 | 
						||
    
 | 
						||
    _dataregp = _datareg;
 | 
						||
 | 
						||
    TDate     datadoc  = mov.get_date(MOV_DATADOC);
 | 
						||
    long      numreg   = mov.get_long(MOV_NUMREG);
 | 
						||
    long      protiva  = mov.get_long(MOV_PROTIVA);
 | 
						||
    long      uprotiva = mov.get_long(MOV_UPROTIVA);                   
 | 
						||
    TString16 numdoc   = mov.get(MOV_NUMDOC);
 | 
						||
    int       meseliq  = mov.get_int(MOV_MESELIQ);
 | 
						||
    char      tipocf   = mov.get(MOV_TIPO)[0];
 | 
						||
    TString16 ocfpi    = mov.get(MOV_OCFPI);
 | 
						||
    long      codcf    = mov.get_long(MOV_CODCF);
 | 
						||
    long      numgio   = mov.get_long(MOV_NUMGIO);
 | 
						||
    bool      stampato = mov.get_bool(MOV_REGST);
 | 
						||
    TString16 codval   = mov.get(MOV_CODVALI);  
 | 
						||
    real      corrval  = mov.get_real(MOV_CORRVALUTA);
 | 
						||
    bool      autof    = caus.get_bool(CAU_AUTOFATT);
 | 
						||
    TString80 descrcau = caus.get(CAU_DESCR);
 | 
						||
 | 
						||
    real      totdoc   = mov.get_real(MOV_TOTDOC);
 | 
						||
    real      ritsoc   = mov.get_real(MOV_RITSOC);
 | 
						||
    real      ritfis   = mov.get_real(MOV_RITFIS);
 | 
						||
    if (totdoc < ZERO)   // Controlla il segno corretto da assegnare alle ritenute
 | 
						||
    {
 | 
						||
      ritsoc = -ritsoc;
 | 
						||
      ritfis = -ritfis;
 | 
						||
    }
 | 
						||
    
 | 
						||
    if (_cur->pos() == 0)
 | 
						||
      _uprotivap = uprotiva ? uprotiva : protiva;
 | 
						||
    
 | 
						||
    //aggiornamento di mov
 | 
						||
    if (_tipo_stampa != prova)
 | 
						||
      if (!stampato)
 | 
						||
      {
 | 
						||
        mov.put(MOV_REGST,TRUE);
 | 
						||
        mov.rewrite();
 | 
						||
      }      
 | 
						||
    
 | 
						||
    if (codcf == 0l)
 | 
						||
      ragsoc = descrcau;
 | 
						||
    else
 | 
						||
    {
 | 
						||
      ocfpi.trim();
 | 
						||
      comune = "";
 | 
						||
      prov = "";
 | 
						||
      if (ocfpi.empty())
 | 
						||
      {
 | 
						||
        TRectype dep = ricerca_cf(tipocf, codcf);
 | 
						||
        ragsoc = dep.get (CLI_RAGSOC);
 | 
						||
        viacf  = dep.get (CLI_INDCF);
 | 
						||
        civcf  = dep.get (CLI_CIVCF);
 | 
						||
        capcf  = dep.get (CLI_CAPCF);
 | 
						||
        comcf  = dep.get (CLI_COMCF);
 | 
						||
        comune = dep.get (CLI_LOCCF);
 | 
						||
        stacf  = dep.get (CLI_STATOCF);
 | 
						||
        codfis = dep.get (CLI_COFI);
 | 
						||
        piva   = dep.get (CLI_STATOPAIV);
 | 
						||
        if (piva.not_empty()) 
 | 
						||
          piva << ' ';
 | 
						||
        piva << dep.get (CLI_PAIV);
 | 
						||
        char tipoa = dep.get_char(CLI_TIPOAPER);
 | 
						||
        if (tipoa == 'F')
 | 
						||
        {
 | 
						||
          TString80 cognome, nome;
 | 
						||
          cognome = ragsoc.mid(0,30);
 | 
						||
          nome    = ragsoc.mid(30,20);
 | 
						||
          cognome.trim(); nome.trim();
 | 
						||
          ragsoc = cognome;
 | 
						||
          ragsoc << " " << nome;
 | 
						||
        }
 | 
						||
      }
 | 
						||
      else
 | 
						||
      {
 | 
						||
        const TRectype& dep = ricerca_occ(ocfpi);
 | 
						||
        ragsoc = dep.get (OCC_RAGSOC);
 | 
						||
        viacf  = dep.get (OCC_INDIR);
 | 
						||
        civcf  = dep.get (OCC_CIV);
 | 
						||
        capcf  = dep.get (OCC_CAP);
 | 
						||
        comcf  = dep.get (OCC_COM);
 | 
						||
        stacf  = dep.get (OCC_STATO);
 | 
						||
        codfis = "";
 | 
						||
        piva   = "";
 | 
						||
      }
 | 
						||
      const TRectype& com = look_comuni(stacf,comcf);
 | 
						||
      if (!com.empty())
 | 
						||
      {
 | 
						||
        comune       = com.get(COM_DENCOM);
 | 
						||
        prov         = com.get(COM_PROVCOM);  
 | 
						||
      }
 | 
						||
    }
 | 
						||
    
 | 
						||
    _tipodoc   = mov.get(MOV_TIPODOC);
 | 
						||
    _descr_doc = descr_doc();
 | 
						||
    TString app(datadoc.string(brief, '/'));
 | 
						||
    
 | 
						||
    totdoc += ritsoc+ritfis;
 | 
						||
    
 | 
						||
    if (_st_tot_fin)
 | 
						||
      _doc_array.add_riga(_tipodoc,_descr_doc,totdoc); 
 | 
						||
 | 
						||
    //setto le righe di stampa
 | 
						||
    _r = 1;
 | 
						||
    if (!_stampa_data_reg) 
 | 
						||
      set_row(_r, "%s", (const char* ) _datareg.string(brief, '/'));
 | 
						||
    set_row(_r, "@9g%5ld", protiva);
 | 
						||
    if (datadoc.ok())
 | 
						||
      set_row(_r, "@15g%s", (const char*) app);
 | 
						||
    set_row(_r, "@24g%s",   (const char*) numdoc);
 | 
						||
    if (codcf != 0l)
 | 
						||
      set_row(_r, "@31g%6ld", codcf);
 | 
						||
    *_desc27 = (const char*) ragsoc;  
 | 
						||
    if (meseliq > 0)
 | 
						||
      set_row(_r, "@62g%02d", meseliq);
 | 
						||
    set_row(_r, "@68g%2s",  (const char*) _tipodoc);
 | 
						||
    if (_stampa_width == 132)
 | 
						||
      set_row(_r, "@70g%r", &totdoc);
 | 
						||
    else set_row(_r, "@78g%r", &totdoc);
 | 
						||
 | 
						||
    if (_tipo_stampa == prova)    //in caso di stampa di prova
 | 
						||
    {
 | 
						||
      if (! (_tipo_reg == vendita && _corrispettivi)) //e se non si tratta di registro vendite corrispettivi
 | 
						||
      {
 | 
						||
        if (_cur->pos()!=0 || protiva <= 0) //il primo movimento non va controllato
 | 
						||
        {
 | 
						||
          if (protiva != _uprotivap + 1)
 | 
						||
          {
 | 
						||
            set_row(_r+1, "@2g*** NUM.PROT.FUORI SEQUENZA");
 | 
						||
            riga = _r+2;
 | 
						||
          }
 | 
						||
          _uprotivap = uprotiva ? uprotiva : protiva;
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
    
 | 
						||
    const char* r;
 | 
						||
    int i = 1;
 | 
						||
    while ((r = _desc27->get()) != NULL)
 | 
						||
    {
 | 
						||
      set_row (i, "@38g%s", r);
 | 
						||
      i++; 
 | 
						||
    }
 | 
						||
    if (i > riga) riga = i; 
 | 
						||
    
 | 
						||
    if (codcf != 0l && _stampa_ind_comp)
 | 
						||
    {
 | 
						||
      if (viacf.not_empty())  
 | 
						||
      {  
 | 
						||
        set_row (i++, "@38g%-.23s %-3s",(const char *)viacf, (const char *)civcf);
 | 
						||
        if (comune.not_empty())
 | 
						||
          set_row ( i++, "@38g%s %-.21s (%2s)", (const char *)capcf, (const char *)comune, (const char *)prov);
 | 
						||
        riga =  i;
 | 
						||
      }  
 | 
						||
      else if (comune.not_empty())
 | 
						||
      {
 | 
						||
        set_row ( i++, "@38g%s %-.21s (%2s)", (const char *)capcf, (const char *)comune, (const char *)prov);
 | 
						||
        riga =  i;  
 | 
						||
      }
 | 
						||
      
 | 
						||
      if (codfis.not_empty() || piva.not_empty())
 | 
						||
      {
 | 
						||
        if (codfis.not_empty() && codfis != piva)
 | 
						||
          set_row ( i++, "@38gC.F. %s", (const char*)codfis);
 | 
						||
        if (piva.not_empty())
 | 
						||
          set_row ( i++, "@38gP.I. %s", (const char*)piva);
 | 
						||
        riga = i;
 | 
						||
      }
 | 
						||
    }
 | 
						||
    
 | 
						||
    const TRecnotype nrec = riga_rmoviva();   
 | 
						||
    if (nrec > 0L)
 | 
						||
    {
 | 
						||
      _esiste_riga_iva = TRUE;
 | 
						||
      for (int j = 0; j < _riga_rmi.items(); j++)
 | 
						||
      {
 | 
						||
        TRigaiva& riga = (TRigaiva&)_riga_rmi[j];
 | 
						||
        rr = _r+j;
 | 
						||
        intra = riga._intra;
 | 
						||
        if (_stampa_width == 132)
 | 
						||
        {
 | 
						||
          set_row(rr, "@85g%r",   &riga._imponibile);
 | 
						||
          set_row(rr, "@101g%4s",(const char*)riga._codiva);
 | 
						||
          if (_tipo_reg == acquisto)
 | 
						||
            set_row(rr, "@106g%d", riga._tipodet);
 | 
						||
          set_row(rr, "@107g%r",  &riga._imposta);
 | 
						||
          set_row(rr, "@123g%d",  riga._tipocr);
 | 
						||
          if (_tipoatt == "E" && _tipo_reg != acquisto)
 | 
						||
            set_row(rr, "@125g%d", riga._tipoatt);
 | 
						||
          if (_tipo_stampa == rif_giornale) //stampa con riferimento al libro giornale
 | 
						||
            set_row(rr, "@126g%5ld", numgio); 
 | 
						||
        }
 | 
						||
        else  //stampa a 198
 | 
						||
        {
 | 
						||
          set_row(rr, "@93g%r",   &riga._imponibile);
 | 
						||
          set_row(rr, "@109g%4s",(const char*)riga._codiva);
 | 
						||
          if (_tipo_reg == acquisto)
 | 
						||
            set_row(rr, "@114g%d", riga._tipodet);
 | 
						||
          set_row(rr, "@116g%r",  &riga._imposta);
 | 
						||
          if (_tipoatt == "E" && _tipo_reg != acquisto)
 | 
						||
            set_row(rr, "@132g%d", riga._tipoatt);
 | 
						||
          set_row(rr, "@134g%d",  riga._tipocr);
 | 
						||
          if (_tipo_stampa == rif_giornale) //stampa con riferimento al libro giornale
 | 
						||
            set_row(rr, "@136g%7ld", numgio);
 | 
						||
        }    
 | 
						||
      } 
 | 
						||
      _riga_rmi.destroy();
 | 
						||
    }
 | 
						||
    
 | 
						||
    if ( intra && autof)
 | 
						||
    {
 | 
						||
      _auto_intraf = TRUE;
 | 
						||
      tipo_op = "3";
 | 
						||
    }  
 | 
						||
    else if (intra) 
 | 
						||
      tipo_op = "1";
 | 
						||
    else if (autof)
 | 
						||
      tipo_op = "2";
 | 
						||
 | 
						||
    set_row(_r, "@66g%s",   (const char*) tipo_op);
 | 
						||
    
 | 
						||
    if (_tipo_stampa == prova) //stampa di prova
 | 
						||
    {
 | 
						||
      if (_stampa_width == 132)
 | 
						||
      {  
 | 
						||
        set_row(_r, "@126g%5ld", numreg);
 | 
						||
        if (stampato)
 | 
						||
          set_row(_r, "@131g*"); //solo in stampa di prova!
 | 
						||
      }
 | 
						||
      else //198 
 | 
						||
      {
 | 
						||
        set_row(_r, "@136g%7ld", numreg); 
 | 
						||
        if (stampato)
 | 
						||
          set_row(_r, "@144g*");
 | 
						||
      }  
 | 
						||
    }
 | 
						||
    if (_tipo_stampa == rif_giornale && _stampa_width == 198)
 | 
						||
    {
 | 
						||
      TLocalisamfile rmoviva (LF_RMOVIVA);
 | 
						||
      rmoviva.zero();
 | 
						||
      rmoviva.put(RMI_NUMREG,numreg);
 | 
						||
      TRectype rec(rmoviva.curr());
 | 
						||
      rmoviva.read(_isgteq);     
 | 
						||
      for ( ; !rmoviva.eof(); rmoviva.next())
 | 
						||
      {
 | 
						||
        if (rmoviva.curr() != rec) break;
 | 
						||
 | 
						||
        int  gruppo = rmoviva.get_int("GRUPPO");
 | 
						||
        int  conto  = rmoviva.get_int("CONTO");
 | 
						||
        long sottoc = rmoviva.get_long("SOTTOCONTO");
 | 
						||
        TBill tc (gruppo,conto,sottoc);
 | 
						||
        TString80 descr = tc.descrizione();
 | 
						||
        set_row(_r, "@144g%3d %3d %6d", gruppo, conto, sottoc);
 | 
						||
        set_row(_r, "@159g%-.39s", (const char*) descr); 
 | 
						||
        break;
 | 
						||
      }
 | 
						||
    }   
 | 
						||
    
 | 
						||
    if (riga <= rr) riga = ++rr;
 | 
						||
    
 | 
						||
    if (corrval != ZERO)
 | 
						||
    {   
 | 
						||
      TCurrency curr(corrval, codval);
 | 
						||
      TString80 vall = curr.string(TRUE);
 | 
						||
      vall.right_just(19);
 | 
						||
      set_row(riga, "@24gCodice valuta %-3s Corrispettivo in valuta %s", (const char*) codval, (const char*) vall);
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
print_action TStampa_registri_app::postprocess_page (int file, int counter)
 | 
						||
{
 | 
						||
  if (file == LF_MOV)
 | 
						||
  {   
 | 
						||
    if (counter)  //dopo aver fatto un REPEAT_PAGE (cioe' dopo aver stampato 
 | 
						||
                  //le righe settate in set_page_tot_reg()), in pratica a rottura di mese o alla fine
 | 
						||
    {
 | 
						||
      reset_print(); 
 | 
						||
 | 
						||
      TRecnotype pos   = _cur->pos();
 | 
						||
      long       items = _cur->items();
 | 
						||
      const bool last_mov = pos == items-1;
 | 
						||
      
 | 
						||
      if (_stampa_plafonds && !last_mov)
 | 
						||
      {
 | 
						||
        // Nel caso sia richiesta la stampa prospetto mensile plafond e vi siano mesi
 | 
						||
        // senza movimenti, <20> necessario forzarne la stampa 
 | 
						||
        TDate save_date(_datareg);
 | 
						||
        
 | 
						||
        // Caso speciale, in cui non vi siano movimenti sull'ultimo mese indicato in stampa
 | 
						||
        //const bool print_over = last_mov && _dataregp == _dataregs && _dataregp.month() < _data_a.month();
 | 
						||
 | 
						||
        const int m1 = _dataregp.month()+1;
 | 
						||
        const int m2 = _dataregs.month();
 | 
						||
        for (int kk = m1; kk < m2; kk++)
 | 
						||
        {
 | 
						||
          _datareg = TDate(1, kk, _annoes);
 | 
						||
          if (stampa_plafonds(-1, TRUE))
 | 
						||
          {
 | 
						||
            printer().formfeed();
 | 
						||
            stampa_plafonds(-1);
 | 
						||
          }
 | 
						||
        }
 | 
						||
        _datareg = save_date;
 | 
						||
      }
 | 
						||
 | 
						||
      if (_liquidazione) 
 | 
						||
        if (!_st_liq[_datareg.month()] && stampo_liquidazione(_datareg.month()))
 | 
						||
        {
 | 
						||
          _st_liq[_datareg.month()] = TRUE;
 | 
						||
          if (_scelta == B0_settato)
 | 
						||
            liq_b0_settato();
 | 
						||
          if (_scelta == prosegui_stampa || _scelta == prosegui_cal_stampa)
 | 
						||
          {  
 | 
						||
            if (_t.exist())
 | 
						||
            {
 | 
						||
              printer().formfeed();
 | 
						||
              _intesta_liq = TRUE;
 | 
						||
              merge_export_file(_t,FALSE,TRUE);
 | 
						||
              _intesta_liq = FALSE;
 | 
						||
              remove(_t);
 | 
						||
            }
 | 
						||
          }   
 | 
						||
        }
 | 
						||
 | 
						||
      if (last_mov) 
 | 
						||
      { 
 | 
						||
        if (_stampa_plafonds || (_tipo_stampa != libro_unico && _liquidazione))
 | 
						||
          stampa_liq_mesi_succ(); 
 | 
						||
        if (_tipo_stampa != prova) 
 | 
						||
        {
 | 
						||
          int da = _datareg.month() + 1;
 | 
						||
          int a  = _data_a.month();   
 | 
						||
          for (int m=da; m<=a; m++)
 | 
						||
          {
 | 
						||
            TDate data(1, m, _annoes); 
 | 
						||
            data.set_end_month(); 
 | 
						||
            scrivi_reg(data);    
 | 
						||
          }   
 | 
						||
        }
 | 
						||
      }    
 | 
						||
    } 
 | 
						||
    if (!counter)
 | 
						||
    {
 | 
						||
      bool FINITO = FALSE;
 | 
						||
      TRecnotype pos   = _cur->pos();
 | 
						||
      long       items = _cur->items();
 | 
						||
      
 | 
						||
      FINITO = (pos == items-1);
 | 
						||
      
 | 
						||
      if ( FINITO )  
 | 
						||
      {
 | 
						||
        liq_other_case();
 | 
						||
        if (_tipo_stampa != prova)
 | 
						||
          calcola_progressivi();
 | 
						||
        set_page_tot_reg();
 | 
						||
        return REPEAT_PAGE;
 | 
						||
      }
 | 
						||
      else 
 | 
						||
      {
 | 
						||
        TLocalisamfile& mov = _cur->file(LF_MOV);
 | 
						||
        _cur->save_status();
 | 
						||
        ++(*_cur);
 | 
						||
        _dataregs = mov.get_date(MOV_DATAREG);
 | 
						||
        --(*_cur);
 | 
						||
        _cur->restore_status();
 | 
						||
 | 
						||
        if (_dataregs.month() != _dataregp.month())
 | 
						||
        {
 | 
						||
          liq_other_case();
 | 
						||
          if (_tipo_stampa != prova)
 | 
						||
            calcola_progressivi();
 | 
						||
          set_page_tot_reg();
 | 
						||
          return REPEAT_PAGE; 
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }   
 | 
						||
  return NEXT_PAGE;
 | 
						||
}
 | 
						||
 | 
						||
//--------- Intestazione (un casino allucinante!!!) ---------//
 | 
						||
 | 
						||
int TStampa_registri_app::stampa_intestazione()
 | 
						||
{
 | 
						||
  int r = 1;
 | 
						||
  TString riga(_stampa_width);
 | 
						||
  
 | 
						||
  get_dati_ditta();
 | 
						||
  riga.format("Ditta %ld %s %s %s %s %s", get_firm(),
 | 
						||
              (const char*)_ragsoc, (const char*)_viafis,
 | 
						||
              (const char*)_cap, (const char*)_comunefis,
 | 
						||
              (const char*)_provfis);
 | 
						||
 | 
						||
  set_header (r++, riga);            
 | 
						||
  
 | 
						||
  riga.format("");
 | 
						||
  if (_tipo_stampa == prova)
 | 
						||
  {
 | 
						||
    riga.format("REGISTRO DI PROVA   Data %s", TDate(TODAY).string());
 | 
						||
    riga.right_just(_stampa_width);
 | 
						||
  }
 | 
						||
  
 | 
						||
  TString80 tmp;  
 | 
						||
  tmp.format("Partita iva %s Codice fiscale %s", (const char*)_paiva, (const char*)_cofi);
 | 
						||
  riga.overwrite(tmp);
 | 
						||
  set_header (r, riga);
 | 
						||
  
 | 
						||
  return r; 
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::preprocess_header()
 | 
						||
{
 | 
						||
  int r=1;
 | 
						||
  char cor, nd1, nd2;
 | 
						||
  char tipo = ' ';
 | 
						||
  char type = ' '; 
 | 
						||
  int  mese, anno;
 | 
						||
  TString riga(_stampa_width);
 | 
						||
  TString data(30);   
 | 
						||
  
 | 
						||
  riga.fill('-');   
 | 
						||
  
 | 
						||
  if (_tipo_stampa != libro_unico)
 | 
						||
  {
 | 
						||
    mese = _datareg.month();
 | 
						||
    anno = _datareg.year();
 | 
						||
  }
 | 
						||
  else //se _tipo_stampa == 3 (su libro unico) sto stampando un solo mese
 | 
						||
  {
 | 
						||
    mese = _fino_a_mese;
 | 
						||
    anno = _annoes;
 | 
						||
  }
 | 
						||
  
 | 
						||
  data.format("%s %s %d", "mese di", itom(mese), anno);
 | 
						||
 | 
						||
  reset_header();
 | 
						||
 | 
						||
  if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
  {
 | 
						||
    if (_stampa_ind_ditta)
 | 
						||
      r = stampa_intestazione();  
 | 
						||
    else
 | 
						||
     r+=2;
 | 
						||
  }
 | 
						||
  else // se stampa di prova o su libro unico l'intestazione della ditta 
 | 
						||
       // va sempre stampata  
 | 
						||
    r = stampa_intestazione();
 | 
						||
    
 | 
						||
  if (_stampa_num_pag) // Stampa numero di pagina in alto a destra
 | 
						||
  {
 | 
						||
    TString16 numpag, riga;
 | 
						||
    numpag.format("%d/%d", _annoes, _numini+printer().getcurrentpage());
 | 
						||
    const int tab = _stampa_width - numpag.len();
 | 
						||
    riga.format("@%dg%s", tab, (const char*)numpag);
 | 
						||
    set_header(1, riga); // Sempre sulla prima riga!
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (_tipo_stampa == libro_unico && !_intesta_vidi)
 | 
						||
  {
 | 
						||
    ++_u_stampata;
 | 
						||
    ++_pagine_stampate; 
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
    ++_pagine_stampate;
 | 
						||
  
 | 
						||
  if (_tipo_stampa == libro_unico)
 | 
						||
    set_header(r, "@94gProgr.Studio %ld@114gProgr.Utente %ld", _u_stampata, _pagine_stampate);
 | 
						||
 | 
						||
  // cosi' sono sicura che l'aggiornamento viene fatto ad ogni salto pagina 
 | 
						||
  // (cioe' a rottura di mese)  
 | 
						||
  if (_tipo_stampa != prova) aggiorna_reg(_ok_vidi); 
 | 
						||
  
 | 
						||
  r++;
 | 
						||
  
 | 
						||
  if (!_intesta_vidi)
 | 
						||
  {
 | 
						||
    if (_intesta_liq)
 | 
						||
      set_header(r, "Registro IVA: %s %s   %s", (const char*)_codreg, 
 | 
						||
                 (const char*)_desc_lib, (const char*) data);
 | 
						||
    else set_header(r, "Registro IVA: %s %s   %s    Attivita\' %s %s",
 | 
						||
                    (const char*) _codreg, (const char*) _desc_lib, 
 | 
						||
                    (const char*) data, (const char*) _codatt, 
 | 
						||
                    (const char*) _attivita); 
 | 
						||
  }
 | 
						||
  else 
 | 
						||
  {
 | 
						||
    set_header(r++, "Registro IVA: %s %s", (const char *) _codreg, (const char *) _desc_lib); 
 | 
						||
    set_header(r, "RIFERIMENTI VIDIMAZIONE"); 
 | 
						||
  }
 | 
						||
  
 | 
						||
  //se sto stampando sul registro la liquidazione
 | 
						||
  //l'intestazione (piuttosto dettagliata) e' gestita
 | 
						||
  //dal prg di liquidazione perche' molte info che devono 
 | 
						||
  //comparire in questa intestazione la stampa reg. non le conosce.
 | 
						||
     
 | 
						||
  //non sto stampando la liquidazione
 | 
						||
  if (!_intesta_liq)
 | 
						||
  {
 | 
						||
    r++;
 | 
						||
    set_header(r, riga);
 | 
						||
    r++;
 | 
						||
    if (_tipo_reg == vendita)  //registro vendite
 | 
						||
    {
 | 
						||
      cor = 'R';
 | 
						||
      nd1 = ' ';
 | 
						||
      nd2 = ' ';
 | 
						||
    }  
 | 
						||
    if (_tipo_reg == acquisto)
 | 
						||
    { 
 | 
						||
      cor = 'C';
 | 
						||
      nd1 = 'N';
 | 
						||
      nd2 = 'D';
 | 
						||
    }
 | 
						||
    if (_tipoatt == "E") //attivita' mista
 | 
						||
    {
 | 
						||
      tipo = 'A';
 | 
						||
      type = 'T';
 | 
						||
    }
 | 
						||
    if (_tipo_stampa == prova) //stampa di prova (_intesta_vidi e' di sicuro FALSE)
 | 
						||
    {
 | 
						||
      if (_tipo_reg == riepilogativo)
 | 
						||
        set_header(r++,"RIEPILOGO TOTALI REGISTRI IVA");
 | 
						||
      else
 | 
						||
      {  
 | 
						||
       if (_stampa_width == 132) 
 | 
						||
       {
 | 
						||
        set_header(r,"@10gNum.@19gDocumento@61gMese@66gT Tipo@102gCod %c@123gT %c@128gNum", nd1, tipo);
 | 
						||
        r++;
 | 
						||
        set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descr. liq.@66gO Doc.@74gTotale doc.@90gImponibile  Iva %c@115gImposta@123g%c %c@128gReg", nd2, cor, type);
 | 
						||
        r++;
 | 
						||
       }
 | 
						||
       else  //stampa a 198
 | 
						||
       {
 | 
						||
        set_header(r,"Registrazione Documento@61gMese@66gT Tipo@110gCod %c@132g%c T@139gNum.", nd1, tipo, cor);
 | 
						||
        r++;
 | 
						||
        set_header(r, "Data Protocollo  Data@24gNumero Codice Ragione sociale/descr. liq.@66gO Documento@80gTot.Documento@98gImponibile  Iva %c@124gImposta@132g%c %c@139gReg.", nd2, type, cor);
 | 
						||
        r++;
 | 
						||
       }
 | 
						||
      }   
 | 
						||
    }
 | 
						||
    else if (!_intesta_vidi)
 | 
						||
    {
 | 
						||
     if (_tipo_reg == riepilogativo)
 | 
						||
       set_header(r++,"RIEPILOGO TOTALI REGISTRI IVA");
 | 
						||
     else
 | 
						||
     {   
 | 
						||
      if (_stampa_width == 132)
 | 
						||
      {
 | 
						||
       set_header(r,"@10gNum.@19gDocumento@61gMese@66gT Tipo@102gCod %c@123gT %c", nd1, tipo);
 | 
						||
       if (_tipo_stampa == rif_giornale) //stampa definitiva con rif. al libro giornale
 | 
						||
         set_header(r, "@128gNum."); 
 | 
						||
       r++;
 | 
						||
       set_header(r, "Data reg. prot.@17gData@24gNumero Codice Ragione sociale/descr. liq.@66gO Doc.@74gTotale doc.@90gImponibile  Iva %c@115gImposta@123g%c %c", 
 | 
						||
                  nd2, cor, type);
 | 
						||
       if (_tipo_stampa == rif_giornale)
 | 
						||
         set_header(r, "@128gop."); 
 | 
						||
       r++;
 | 
						||
      }
 | 
						||
      else //stampa a 198
 | 
						||
      {
 | 
						||
       set_header(r,"Registrazione Documento@61gMese@66gT Tipo@110gCod %c@132g%c T", nd1, tipo);
 | 
						||
       if (_tipo_stampa == rif_giornale)
 | 
						||
         set_header(r, "@139gNum.");
 | 
						||
       r++;
 | 
						||
       set_header(r, "Data Protocollo  Data@24gNumero Codice Ragione sociale/descr. liq.@66gO Documento@80gTot.Documento@98gImponibile  Iva %c@124gImposta@132g%c %c", nd2, type, cor);
 | 
						||
       if (_tipo_stampa == rif_giornale)
 | 
						||
         set_header(r, "@139gop. @144gCodice conto @159gDescrizione sottoconto");
 | 
						||
       r++;
 | 
						||
      }
 | 
						||
     }    
 | 
						||
    }
 | 
						||
    else if (_tipo_stampa == libro_unico && _intesta_vidi)
 | 
						||
    {
 | 
						||
     TString tr(52);
 | 
						||
     tr.fill('-');
 | 
						||
     set_header(r++,"@10gPagine studio  Pagine utente ----------------  V I D I M A Z I O N E  %s", (const char*)tr);
 | 
						||
     set_header(r++,"Mese@12gda@20ga@27gda@35ga   Intestatario@71gN.fogli Pag.in. Pag.fin.  Data     Ufficio");
 | 
						||
    }
 | 
						||
    
 | 
						||
    if (_tipo_reg != riepilogativo)
 | 
						||
      if (_stampa_ind_comp && !_intesta_vidi)
 | 
						||
        set_header(r++, "@38gGeneralita'");
 | 
						||
    
 | 
						||
    set_header(r, riga);
 | 
						||
  } 
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::stampo_liquidazione(int mese)
 | 
						||
{
 | 
						||
  //test tradotti alla lettera da AS/400
 | 
						||
  //assolutamente incongruenti !!!
 | 
						||
  const bool trim_month_flag = (_frequiva == 'T' && (mese == 3 || mese == 6 || mese == 9 || mese == 12)) 
 | 
						||
                          ||_frequiva != 'T' || (mese == 12 && _tipo_riepilogativo == 'A');
 | 
						||
        
 | 
						||
  if (_tipo_stampa == prova)
 | 
						||
  {
 | 
						||
    if (trim_month_flag) 
 | 
						||
      return TRUE;
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    if (trim_month_flag) 
 | 
						||
      if ( (mese == 12 && _tipo_riepilogativo == 'A' && _mese_ultima_liq != 13) 
 | 
						||
          || (mese != 12 && mese > _mese_ultima_liq)
 | 
						||
          || (mese == 12 && _tipo_riepilogativo != 'A' && mese > _mese_ultima_liq) )
 | 
						||
        return TRUE;
 | 
						||
  }                 
 | 
						||
  return FALSE;            
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::liq_b0_settato()
 | 
						||
{
 | 
						||
  TFilename f;
 | 
						||
  f.temp("rg");
 | 
						||
  if (_tipo_stampa == prova)
 | 
						||
    send_message('S',f, _datareg.month()); 
 | 
						||
  else send_message('s',f, _datareg.month()); 
 | 
						||
  //TString80 nomef; 
 | 
						||
  //nomef = f.path(); nomef << "\\" << f.name();
 | 
						||
  //if (fexist(nomef))
 | 
						||
  if (f.exist())
 | 
						||
  {
 | 
						||
    printer().formfeed();
 | 
						||
    _intesta_liq = TRUE;
 | 
						||
    merge_export_file(f,FALSE,TRUE);
 | 
						||
    _intesta_liq = FALSE;
 | 
						||
    remove(f);
 | 
						||
  } 
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::liq_other_case()
 | 
						||
{
 | 
						||
  const bool calc_reg = _annoes > 1997; // Flag per effettuare nuovo calcolo registri
 | 
						||
  char tipo_messaggio;                  // Tipo messaggio per chiamata a programma calcolo/stampa liquidazione
 | 
						||
  
 | 
						||
  switch (_scelta)
 | 
						||
  {
 | 
						||
    case prosegui_cal_stampa:
 | 
						||
        tipo_messaggio = 'L'; // Stampa Liquidazione con ricalcolo
 | 
						||
        break;
 | 
						||
    case prosegui_stampa:
 | 
						||
        tipo_messaggio = 'S'; // Stampa Liquidazione senza ricalcolo
 | 
						||
        break;
 | 
						||
    default:
 | 
						||
        tipo_messaggio = '\0';
 | 
						||
        break;
 | 
						||
  }
 | 
						||
   
 | 
						||
  if (_tipo_stampa != prova)
 | 
						||
    tipo_messaggio = tolower(tipo_messaggio); // Prova o definitiva ?
 | 
						||
 | 
						||
  // Calcolo/Stampa liquidazione
 | 
						||
  if (stampo_liquidazione(_datareg.month()) && tipo_messaggio != '\0')
 | 
						||
  {
 | 
						||
    _t.temp("reg");    
 | 
						||
    send_message(tipo_messaggio, _t, _datareg.month());  
 | 
						||
  }
 | 
						||
  
 | 
						||
  // Ricalcolo Progressivi Registri. Il vecchio calcolo viene mantenuto. Nel
 | 
						||
  // caso si tratti di un nuovo anno, chiama il nuovo calcolo specifico per registri.
 | 
						||
  if (_tipo_stampa != prova)
 | 
						||
  {  // Se sta stampando i bollati ricalcola sempre (ignorando il flag LIM->B1, a causa delle nuove norme)
 | 
						||
     // Cio' viene fatto poiche' in caso di ripristino di stampa registro bollato
 | 
						||
     // sarebbe necessario un ricalcolo progressivi per sicurezza.
 | 
						||
    if (ricalcola(_fino_a_mese) || calc_reg) 
 | 
						||
    {
 | 
						||
     TFilename app;
 | 
						||
     app.temp();                 
 | 
						||
     int mese = _fino_a_mese;            
 | 
						||
     //se la frequenza e' trimestrale
 | 
						||
     //aggiusta il mese al trimestre a cui appartiene
 | 
						||
     if (_frequiva == 'T')
 | 
						||
       mese += 2 - ((mese-1) % 3);
 | 
						||
     send_message(calc_reg ? 'R' : 'C', app, calc_reg ? _datareg.month() : mese); 
 | 
						||
    } 
 | 
						||
  }  
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::stampa_vidi()
 | 
						||
{
 | 
						||
  TLocalisamfile IndBil (LF_INDLIB);
 | 
						||
  TTable    TabVid ("%VID");
 | 
						||
  TString16 codreg;
 | 
						||
  TString16 vid;
 | 
						||
  long      ditta, pagfin, pagfinut;
 | 
						||
  int       mese;
 | 
						||
  TPrintrow row;
 | 
						||
  
 | 
						||
  _ok_vidi = FALSE;
 | 
						||
  
 | 
						||
  if (!printer().isopen())
 | 
						||
    printer().open();
 | 
						||
  
 | 
						||
  IndBil.zero();
 | 
						||
  IndBil.put("ANNO", _annoes);
 | 
						||
  IndBil.put("CODLIB", _codlib);
 | 
						||
  TRectype rec (IndBil.curr());
 | 
						||
  IndBil.read (_isgteq);
 | 
						||
  for (; !IndBil.eof(); IndBil.next())
 | 
						||
  { 
 | 
						||
    if (IndBil.curr() != rec) break;
 | 
						||
    ditta  = IndBil.get_long("CODDITTA");
 | 
						||
    codreg = IndBil.get("CODREG");
 | 
						||
    if (ditta == _ditta && codreg == _codreg)
 | 
						||
    {
 | 
						||
      if (!_ok_vidi)
 | 
						||
      {
 | 
						||
        ++_u_stampata;
 | 
						||
        ++_pagine_stampate;
 | 
						||
        _ok_vidi = TRUE;
 | 
						||
      }
 | 
						||
      mese = IndBil.get_int("MESEREG");
 | 
						||
      pagfin = IndBil.get_long("PAGFIN");
 | 
						||
      pagfinut = IndBil.get_long("PAGFINUT");
 | 
						||
      if (mese == 12)
 | 
						||
      {
 | 
						||
        ++pagfin;
 | 
						||
        ++pagfinut; 
 | 
						||
        TRectype nuovo (IndBil.curr());
 | 
						||
        nuovo.put("PAGFIN", pagfin);
 | 
						||
        nuovo.put("PAGFINUT", pagfinut);
 | 
						||
        IndBil.rewrite(nuovo);
 | 
						||
      }
 | 
						||
      row.reset();
 | 
						||
      row.put(format("%s", itom(mese)), 0);
 | 
						||
      row.put(format("%5ld", IndBil.get_long("PAGINI")), 10);
 | 
						||
      row.put(format("%5ld", pagfin), 17);
 | 
						||
      row.put(format("%5ld", IndBil.get_long("PAGINIUT")), 25);
 | 
						||
      row.put(format("%5ld", pagfinut), 32);
 | 
						||
      vid  = IndBil.get("CODVID");
 | 
						||
      TabVid.zero();
 | 
						||
      TabVid.put("CODTAB", vid);
 | 
						||
      if (TabVid.read() == NOERR)
 | 
						||
      {
 | 
						||
        row.put(format("%-.32s", (const char*)TabVid.get("S0")), 39);
 | 
						||
        row.put(format("%7d",TabVid.get_long("I0")), 71);
 | 
						||
        row.put(format("%7d",TabVid.get_long("I1")), 79);
 | 
						||
        row.put(format("%7d",TabVid.get_long("I2")), 87);
 | 
						||
        TDate d(TabVid.get_long("D0"));
 | 
						||
        row.put(format("%s", (const char*)d.string()), 95);
 | 
						||
        row.put(format("%-.26s", (const char*)TabVid.get("S1")), 106);
 | 
						||
      }   
 | 
						||
      printer().print(row);
 | 
						||
    } 
 | 
						||
  }
 | 
						||
  printer().close();
 | 
						||
}
 | 
						||
 | 
						||
//------ dopo la stampa devo aggiornare i registri, ecc. ------//
 | 
						||
 | 
						||
void TStampa_registri_app::scrivi_reg(const TDate& data)
 | 
						||
{
 | 
						||
  TString16 codtab; 
 | 
						||
  TTable Tabreg ("REG");
 | 
						||
  
 | 
						||
  codtab << _annoes << _codreg;
 | 
						||
  Tabreg.zero();
 | 
						||
  Tabreg.put("CODTAB", codtab);  
 | 
						||
  if (Tabreg.read() == NOERR)
 | 
						||
  {
 | 
						||
    const TDate d = Tabreg.get_date("D3");
 | 
						||
    if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina
 | 
						||
    {
 | 
						||
      TDate ultima_data(data); 
 | 
						||
      ultima_data.set_end_month();       // Meglio cosi'
 | 
						||
      
 | 
						||
      if (ultima_data > d) 
 | 
						||
        Tabreg.put("D3", ultima_data);
 | 
						||
    }  
 | 
						||
    else if (_data_a > d) 
 | 
						||
      Tabreg.put("D3", _data_a);
 | 
						||
 | 
						||
    if (_tipo_reg == acquisto && _stampa_cred_pre)
 | 
						||
      if (_mese_credito == 0 && _credito > ZERO)
 | 
						||
        if (_mov_empty) 
 | 
						||
          Tabreg.put("I8", (long)_fino_a_mese);
 | 
						||
        else Tabreg.put("I8", (long)_datareg.month());
 | 
						||
 | 
						||
    Tabreg.rewrite();
 | 
						||
  }  
 | 
						||
  
 | 
						||
  if (_tipo_stampa == libro_unico)
 | 
						||
  {
 | 
						||
    TString16 cod = ""; 
 | 
						||
    TTable lbu ("%LBU");
 | 
						||
    
 | 
						||
    cod << _annoes << _codlib;
 | 
						||
    lbu.zero();
 | 
						||
    lbu.put("CODTAB", cod);  
 | 
						||
    if (lbu.read() == NOERR)
 | 
						||
    {
 | 
						||
      lbu.put("I0", (long) _fino_a_mese);
 | 
						||
      lbu.rewrite();
 | 
						||
    } 
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::aggiorna_reg(const bool aggiorna_vidi)
 | 
						||
{
 | 
						||
  TString16 codtab; 
 | 
						||
  TTable Tabreg ("REG");
 | 
						||
  TLocalisamfile IndBil (LF_INDLIB);
 | 
						||
  
 | 
						||
  codtab << _annoes << _codreg;
 | 
						||
  Tabreg.zero();
 | 
						||
  Tabreg.put("CODTAB", codtab);  
 | 
						||
  if (Tabreg.read() == NOERR)
 | 
						||
  {
 | 
						||
    TDate d = Tabreg.get_date("D3");
 | 
						||
    if (!_mov_empty) //cioe' se e' stata stampata almeno una pagina
 | 
						||
    {                //controllo inutile visto che e' chiamata nella
 | 
						||
                     //preprocess_header
 | 
						||
      TDate ultima_data(_datareg); 
 | 
						||
      ultima_data.set_end_month();       
 | 
						||
 | 
						||
      if (ultima_data > d) 
 | 
						||
        Tabreg.put("D3", ultima_data);
 | 
						||
    }  
 | 
						||
    else if (_data_a > d) 
 | 
						||
      Tabreg.put("D3", _data_a);
 | 
						||
 | 
						||
    Tabreg.put("I1", _pagine_stampate);
 | 
						||
    
 | 
						||
    if (_intesta_liq)
 | 
						||
      if (_tipo_riepilogativo == 'A')
 | 
						||
        Tabreg.put("I4", 13L);
 | 
						||
      else Tabreg.put("I4", (long)_datareg.month());
 | 
						||
 | 
						||
    if (_tipo_reg == acquisto && _stampa_cred_pre)
 | 
						||
      if (_mese_credito == 0 && _credito > ZERO)
 | 
						||
        if (_mov_empty) 
 | 
						||
          Tabreg.put("I8", (long)_fino_a_mese);
 | 
						||
        else Tabreg.put("I8", (long)_datareg.month());
 | 
						||
    
 | 
						||
    Tabreg.rewrite();
 | 
						||
  }
 | 
						||
 | 
						||
  if (_tipo_stampa == libro_unico) //stampa su libro unico
 | 
						||
 | 
						||
    // sul file indlib (indice libro unico) devo generare una riga per ogni 
 | 
						||
    // registro stampato (ricordarsi che la stampa su libro unico deve 
 | 
						||
    // avvenire mese per mese!) 
 | 
						||
    // inoltre non posso stampare due volte lo stesso mese perche' la stampa 
 | 
						||
    // avviene a fine mese
 | 
						||
  {       
 | 
						||
    long numero_riga = 1L;
 | 
						||
    if (!aggiorna_vidi)
 | 
						||
    {                        
 | 
						||
      bool trovato = FALSE;
 | 
						||
      
 | 
						||
      IndBil.zero(); 
 | 
						||
 | 
						||
      TRectype nuovo   (IndBil.curr());
 | 
						||
 | 
						||
      IndBil.put("ANNO", _annoes);
 | 
						||
      IndBil.put("CODLIB", _codlib);
 | 
						||
      TRectype rec (IndBil.curr());
 | 
						||
      
 | 
						||
      for (IndBil.read(_isgteq); !IndBil.eof(); IndBil.next())
 | 
						||
      { 
 | 
						||
        if (IndBil.curr() != rec) break;
 | 
						||
        
 | 
						||
        int annoreg = IndBil.get_int("ANNOREG");
 | 
						||
        int mesereg = IndBil.get_int("MESEREG");
 | 
						||
        long cditta = IndBil.get_long("CODDITTA");
 | 
						||
        TString16 codreg = IndBil.get("CODREG");
 | 
						||
        TString16 codvid = IndBil.get("CODVID");
 | 
						||
        if (_annoes == annoreg && _fino_a_mese == mesereg
 | 
						||
            && _ditta == cditta && codreg == _codreg && _codice_vidi == codvid)
 | 
						||
        {    
 | 
						||
          trovato = TRUE;
 | 
						||
          numero_riga = IndBil.get_long("NUMREG");
 | 
						||
          break;                              
 | 
						||
        }
 | 
						||
        else numero_riga = IndBil.get_long("NUMREG") + 1;        
 | 
						||
        // cosi' mi posiziono su quel mese (altrimenti rischio di generare 
 | 
						||
        // due righe per lo stesso mese e registro => la stampa di vidimazione 
 | 
						||
        // mi sballa!!!,
 | 
						||
      }        
 | 
						||
      nuovo.put("ANNO", _annoes);
 | 
						||
      nuovo.put("CODLIB", _codlib);
 | 
						||
      nuovo.put("NUMREG", numero_riga);
 | 
						||
      
 | 
						||
      nuovo.put("ANNOREG", _annoes);
 | 
						||
      nuovo.put("MESEREG", _fino_a_mese);  // su libro unico ho un solo mese in gioco!
 | 
						||
      nuovo.put("PAGINI", _primast + 1);   // numero iniziale pagina libro unico
 | 
						||
      nuovo.put("PAGFIN", _u_stampata);    // numero finale pagina libro unico
 | 
						||
      nuovo.put("CODDITTA", _ditta);
 | 
						||
      nuovo.put("CODREG", _codreg);
 | 
						||
      nuovo.put("CODVID", _codice_vidi);
 | 
						||
      nuovo.put("PAGINIUT", _numini + 1);
 | 
						||
      nuovo.put("PAGFINUT", _pagine_stampate);
 | 
						||
      
 | 
						||
      if (!trovato)
 | 
						||
        IndBil.write(nuovo);                                              
 | 
						||
      else IndBil.rewrite(nuovo);                                              
 | 
						||
    } 
 | 
						||
    aggiorna_lib();
 | 
						||
  } 
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::aggiorna_lib()
 | 
						||
{
 | 
						||
  TString16 cod = ""; 
 | 
						||
  TTable lbu ("%LBU");
 | 
						||
  
 | 
						||
  cod << _annoes << _codlib;
 | 
						||
  lbu.zero();
 | 
						||
  lbu.put("CODTAB", cod);  
 | 
						||
  if (lbu.read() == NOERR)
 | 
						||
  {
 | 
						||
    lbu.put("I0", (long) _fino_a_mese);
 | 
						||
    lbu.put("I1", (long) _u_stampata);
 | 
						||
    lbu.rewrite();
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::clear_stliq() 
 | 
						||
{
 | 
						||
  for (int i=0; i <= 12; i++)
 | 
						||
    _st_liq[i] = FALSE;
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::setta_mask(long i)
 | 
						||
{
 | 
						||
  if (_stampa_mese == 13) _stampa_mese = 0;          
 | 
						||
  if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
  {
 | 
						||
    TMask mb("cg4400b"); 
 | 
						||
    mb.set(F_CODDITTA, _ditta);
 | 
						||
    mb.set(F_RAGSOC, _ditte->row(i).get(2));
 | 
						||
    mb.set(COD_LIB, _codreg);
 | 
						||
    const char* m = "";
 | 
						||
    m = format("%02d", _stampa_mese);
 | 
						||
    mb.set(U_MESE, m);
 | 
						||
    mb.set(U_PAGINA, _pagine_stampate);
 | 
						||
    if (_u_data.ok())
 | 
						||
      mb.set(U_DATA, _u_data.string());
 | 
						||
    KEY tasto = mb.run();
 | 
						||
    if (tasto != K_ENTER) return FALSE;  
 | 
						||
    //MI3213
 | 
						||
    _pagine_stampate = mb.get_long(U_PAGINA);
 | 
						||
    _numini = _pagine_stampate;
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
} 
 | 
						||
 | 
						||
//In questa funzione veniva gestita la stampa della liquidazione 
 | 
						||
//(anche se in un mese non si hanno movimenti occorre comunque 
 | 
						||
//stampare la liquidazione (se sul registro che sto stampando
 | 
						||
//c'e' il flag di stampa liquidazione e, in caso di bollato, non
 | 
						||
//era gia' scesa precedentemente)).
 | 
						||
//Viene anche gestita la stampa del registro
 | 
						||
//RIEPILOGATIVO (essendo un registro su cui non vengono registrati
 | 
						||
//movimenti) 
 | 
						||
void TStampa_registri_app::no_movimenti()
 | 
						||
{
 | 
						||
  TRecnotype rec = _tabreg->recno();
 | 
						||
  _mov_empty = TRUE;   
 | 
						||
  int da, a;
 | 
						||
  if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
    da = 1;
 | 
						||
  if (_tipo_stampa == libro_unico)
 | 
						||
    da = _fino_a_mese;
 | 
						||
  if (_tipo_stampa == prova) 
 | 
						||
    da = _data_da.month();
 | 
						||
  if (_tipo_stampa == prova)
 | 
						||
    a = _data_a.month();
 | 
						||
  else a = _fino_a_mese;   
 | 
						||
    
 | 
						||
  //RICALCOLO PROGRESSIVI per registro riepilogativo
 | 
						||
  //il ricalcolo dei progressivi mensili viene sempre
 | 
						||
  //fatto, se B1 e' FALSE, anche se poi il riepilogativo
 | 
						||
  //non verra' stampato (se il mese richiesto non e'
 | 
						||
  //in accordo con la frequenza di stampa del registro stesso)
 | 
						||
  //Il ricalcolo nel caso di riepilogativo avviene sempre, 
 | 
						||
  //a causa della separazione dei progressivi per registri, ma 
 | 
						||
  //solo se l'anno in questione e oltre il 1997, cio<69> prima della effettiva
 | 
						||
  //separazione dei progressivi.
 | 
						||
  const bool calc = _tipo_reg == riepilogativo && _annoes > 1997;
 | 
						||
  if (ricalcola(a) || calc)
 | 
						||
  {
 | 
						||
    TFilename app;
 | 
						||
    app.temp();
 | 
						||
    int mese = a;       
 | 
						||
    //se la frequenza e' trimestrale
 | 
						||
    //aggiusta il mese al trimestre a cui appartiene
 | 
						||
    if (_frequiva == 'T')
 | 
						||
    {
 | 
						||
      mese += 2 - ((mese-1) % 3);
 | 
						||
      if (calc)
 | 
						||
      {
 | 
						||
        send_message('R', app, mese-2); // Guy!!!
 | 
						||
        send_message('R', app, mese-1); // Guy!!!
 | 
						||
      }
 | 
						||
    }
 | 
						||
    send_message(calc ? 'R' : 'C', app, calc ? a : mese);
 | 
						||
  }
 | 
						||
    
 | 
						||
  if (_tipo_reg == riepilogativo || _liquidazione || _stampa_plafonds)
 | 
						||
  {      
 | 
						||
    for (int m = da; m <= a; m++)
 | 
						||
    {
 | 
						||
      if (_tipo_reg == riepilogativo)
 | 
						||
      {
 | 
						||
        bool stsbol = FALSE;
 | 
						||
        if (_tipo_stampa != prova) //stampa su bollato
 | 
						||
          if (_u_data.ok())
 | 
						||
            if (m <= _u_data.month()) stsbol = TRUE;
 | 
						||
                              
 | 
						||
        if (!stsbol) //cioe' se il mese che sto considerando e'
 | 
						||
                     //maggiore dell'ultima data di stampa del registro
 | 
						||
        {
 | 
						||
          if (_freq_riepilogo == 'M' ||
 | 
						||
            (m == 3 || m == 6 || m == 9 || m == 12))    
 | 
						||
          {    
 | 
						||
            _datareg = TDate(1, m, _annoes);                
 | 
						||
            if (stampa_riepilogo(m))    
 | 
						||
              printer().formfeed();
 | 
						||
          }
 | 
						||
        }
 | 
						||
      }  
 | 
						||
    
 | 
						||
      // In prova va stampato per ogni mese (sia Mensile che Trimestrale; 
 | 
						||
      // in bollato, solo per i mesi che ancora mancano)
 | 
						||
      const bool print_plafond_bollato = _tipo_stampa != prova && (m == 1 || m > _u_data.month());
 | 
						||
      if (_stampa_plafonds && (_tipo_stampa == prova || print_plafond_bollato))
 | 
						||
      {
 | 
						||
        if (! printer().isopen())
 | 
						||
          printer().open();
 | 
						||
        _datareg = TDate(1, m, _annoes);
 | 
						||
        if (stampa_plafonds(-1)) // Con -1 compone e stampa printrows all'istante
 | 
						||
          printer().formfeed();
 | 
						||
      }
 | 
						||
                
 | 
						||
      //la funzione stampo_liquidazione non stampera' la liquidazione sul 
 | 
						||
      //registro il cui mese di stampa ultima liq. e' > del mese in esame
 | 
						||
      //caso a parte il mese 12 (che posso ristampare 2 volte) 
 | 
						||
      if (_liquidazione)
 | 
						||
        if (stampo_liquidazione(m))
 | 
						||
        {
 | 
						||
          if (_tipo_reg == riepilogativo)
 | 
						||
          { 
 | 
						||
            if (!(_freq_riepilogo == 'M' ||
 | 
						||
              (m == 3 || m == 6 || m == 9 || m == 12))) continue;
 | 
						||
          }
 | 
						||
                   
 | 
						||
          if (! printer().isopen())
 | 
						||
            printer().open();
 | 
						||
          TFilename f;
 | 
						||
          f.temp("rgp");
 | 
						||
          _datareg = TDate(1, m, _annoes);  // serve alla preprocess_header
 | 
						||
          if (_scelta == B0_settato || _scelta == prosegui_stampa)
 | 
						||
          {
 | 
						||
            if (_tipo_stampa == prova)
 | 
						||
              send_message('S',f, m); 
 | 
						||
            else 
 | 
						||
              send_message('s',f, m);
 | 
						||
          }
 | 
						||
          else //_scelta == prosegui_cal_stampa
 | 
						||
          {
 | 
						||
          if (_tipo_stampa == prova)
 | 
						||
            send_message('L', f, m);  
 | 
						||
          else
 | 
						||
            send_message('l', f, m);  
 | 
						||
          }
 | 
						||
          if (fexist(f))
 | 
						||
          {  
 | 
						||
            _intesta_liq = TRUE;
 | 
						||
            merge_export_file(f,FALSE,TRUE);
 | 
						||
            printer().formfeed();
 | 
						||
            _intesta_liq = FALSE;
 | 
						||
            remove(f); 
 | 
						||
          }  
 | 
						||
      }
 | 
						||
    }//for
 | 
						||
  }
 | 
						||
  _tabreg->readat(rec);
 | 
						||
    
 | 
						||
  if (printer().isopen()) printer().close();
 | 
						||
                                            
 | 
						||
  //aggiorno il registro anche se non ho stampato proprio nulla per quel mese!        
 | 
						||
  if (_tipo_stampa != prova)
 | 
						||
    scrivi_reg(_datareg);    
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::stampa_liq_mesi_succ()
 | 
						||
{
 | 
						||
  int da = _datareg.month() + 1;
 | 
						||
  int a  = _data_a.month();   
 | 
						||
  for (int m = da; m <= a; m++)
 | 
						||
  {
 | 
						||
    _datareg = TDate(1, m, _annoes);     
 | 
						||
    if (_stampa_plafonds && stampa_plafonds(-1, TRUE))
 | 
						||
    {
 | 
						||
      printer().formfeed();
 | 
						||
      stampa_plafonds(-1);
 | 
						||
    }
 | 
						||
    
 | 
						||
    if (stampo_liquidazione(m))
 | 
						||
    {
 | 
						||
      TFilename t;
 | 
						||
      t.temp("iva");    
 | 
						||
      
 | 
						||
      if (_scelta == B0_settato || _scelta == prosegui_stampa)
 | 
						||
      {
 | 
						||
        if (_tipo_stampa == prova)
 | 
						||
          send_message('S',t, m); 
 | 
						||
        else
 | 
						||
          send_message('s',t, m);
 | 
						||
      }
 | 
						||
      else //_scelta == prosegui_cal_stampa
 | 
						||
      {
 | 
						||
        if (_tipo_stampa == prova)
 | 
						||
          send_message('L', t, m);  
 | 
						||
        else
 | 
						||
          send_message('l', t, m);
 | 
						||
      }
 | 
						||
            
 | 
						||
      if (fexist(t))
 | 
						||
      {  
 | 
						||
        _intesta_liq = TRUE;
 | 
						||
        printer().formfeed(); 
 | 
						||
        merge_export_file(t,FALSE,TRUE);  
 | 
						||
        _intesta_liq = FALSE;
 | 
						||
        remove(t);  
 | 
						||
      } 
 | 
						||
    }
 | 
						||
  }
 | 
						||
}  
 | 
						||
 | 
						||
void TStampa_registri_app::send_message(char tipo, const TFilename& nome, int mese)
 | 
						||
{
 | 
						||
  const char* app; 
 | 
						||
 | 
						||
  if (tipo == 'S' || tipo == 's')
 | 
						||
    app = "cg4 -2 -S";
 | 
						||
  else if (tipo == 'C' || tipo == 'R')
 | 
						||
    app = "cg4 -2 -C";
 | 
						||
  else app = "cg4 -2";
 | 
						||
 | 
						||
  TToken_string ss(36);
 | 
						||
  ss.add(_annoes);
 | 
						||
  if (_tipo_riepilogativo == 'A' && mese == 12)
 | 
						||
    ss.add(13);
 | 
						||
  else
 | 
						||
    ss.add(mese);                                     
 | 
						||
  ss.add(_ditta);
 | 
						||
  ss.add(tipo);
 | 
						||
  ss.add(_data_stampa.string()); 
 | 
						||
  ss.add(nome);    
 | 
						||
  if (_riep_liq)  
 | 
						||
    ss.add('X');
 | 
						||
  else ss.add(' ');
 | 
						||
  //ss.add(_size_header+RIGHE_FOOTER);
 | 
						||
  ss.add(printer().formlen() - _size_header - RIGHE_FOOTER);
 | 
						||
  
 | 
						||
  TMessage liq (app, "RCL", ss);
 | 
						||
  liq.send();
 | 
						||
  
 | 
						||
  TExternal_app pn(app);
 | 
						||
  pn.run();              
 | 
						||
  
 | 
						||
  os_sleep(1000);
 | 
						||
}
 | 
						||
 | 
						||
bool TStampa_registri_app::set_print(int n)
 | 
						||
{
 | 
						||
  TMask m ("cg4400a");
 | 
						||
  int giorni_del_mese; 
 | 
						||
  bool ok;
 | 
						||
 | 
						||
  m.set_handler (TIPO_STAMPA, mask_tipo_stampa); 
 | 
						||
  m.set_handler (DA_DATA,  mask_data);
 | 
						||
  m.set_handler (A_DATA,   mask_data);
 | 
						||
  m.set_handler (MESE,     mask_mese);
 | 
						||
  m.set_handler (FINO_A_MESE, mask_mese);
 | 
						||
  m.set_handler (CODICE_LIB_UN, mask_cod);
 | 
						||
  m.set_handler (CODICE_LIBRO_IVA, mask_libun);
 | 
						||
  m.set_handler (F_ANNULLA,  mask_azzera);
 | 
						||
  m.set_handler (A_CODICE,  to_ditt_handler);
 | 
						||
  m.set_handler (DA_CODICE, fr_ditt_handler);
 | 
						||
  m.set_handler (ANNO, year_handler);
 | 
						||
  
 | 
						||
  m.field(F_SELECT).set(format("%ld",_selected.ones()));
 | 
						||
  set_choice_limits(m);
 | 
						||
  
 | 
						||
  set_real_picture("###.###.###.###");
 | 
						||
  set_magic_currency(TRUE);
 | 
						||
  
 | 
						||
  while (ok = set_ditte(m)) 
 | 
						||
  {
 | 
						||
    if (_selected.ones() > 0l)
 | 
						||
    {
 | 
						||
      _annoes      = m.get_int(ANNO);//in realta' e' l'anno IVA !!!
 | 
						||
      _tipo_stampa = (tipo_stampa) m.get_int(TIPO_STAMPA);
 | 
						||
      _stampa_width = m.get_int(STAMPA_WIDTH);
 | 
						||
      _stampa_len   = m.get_int(STAMPA_LEN);
 | 
						||
      _table = (_annoes > 1997) ? _tabprm : _tabpim; // Dal 1998 in poi utilizza i PRM e non i PIM
 | 
						||
      if (_stampa_width == 1)
 | 
						||
        _stampa_width = 132;
 | 
						||
      else _stampa_width = 198;
 | 
						||
      if (_stampa_len != 0)
 | 
						||
        printer().formlen(_stampa_len);
 | 
						||
      printer().footerlen(RIGHE_FOOTER);
 | 
						||
      //Se stampa di prova l'utente indica data_da e data_a
 | 
						||
      if (_tipo_stampa == prova)                            
 | 
						||
      {
 | 
						||
        _data_stampa = m.get(DATA_STAMPA);
 | 
						||
        _data_da     = m.get(DA_DATA);
 | 
						||
        _data_a      = m.get(A_DATA);
 | 
						||
        
 | 
						||
        if (!_data_da.ok())
 | 
						||
          _data_da = TDate(1, 1, _annoes);    // Meglio cosi'
 | 
						||
        
 | 
						||
        if (!_data_a.ok())
 | 
						||
          _data_a = TDate(31, 12, _annoes);    // Meglio cosi'
 | 
						||
        
 | 
						||
        const TDate d(31,12,_annoes);
 | 
						||
        if (_data_a == d)
 | 
						||
          _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0];
 | 
						||
        else _tipo_riepilogativo = ' ';  
 | 
						||
        printer().setdate(_data_stampa);
 | 
						||
      }
 | 
						||
      else   //stampe definitive
 | 
						||
      {
 | 
						||
        if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
        {
 | 
						||
          _fino_a_mese = m.get_int(FINO_A_MESE);
 | 
						||
          _data_da = TDate(1, 1, _annoes);        // Meglio cosi'
 | 
						||
        }
 | 
						||
        else  //stampa su libro unico
 | 
						||
        { 
 | 
						||
          _codlib      = m.get(CODICE_LIB_UN);      
 | 
						||
          _fino_a_mese = m.get_int(MESE);
 | 
						||
          _u_stampata  = m.get_int(ULTIMA_PAGINA);
 | 
						||
          _rif_vid     = m.get_bool(RIF_VID);
 | 
						||
          _primast     = _u_stampata;
 | 
						||
          _data_da     = TDate(1, _fino_a_mese, _annoes);   // Meglio cosi'
 | 
						||
        }     
 | 
						||
        if (_fino_a_mese == 12)
 | 
						||
        {
 | 
						||
          giorni_del_mese = 31;
 | 
						||
          _tipo_riepilogativo = m.get(TIPO_RIEPILOGATIVO)[0];
 | 
						||
        }
 | 
						||
        else
 | 
						||
        {
 | 
						||
          _tipo_riepilogativo = ' ';
 | 
						||
          TDate primo(1, _fino_a_mese, _annoes); 
 | 
						||
          primo.set_end_month();                    // Meglio cosi'
 | 
						||
          
 | 
						||
          giorni_del_mese = primo.day();
 | 
						||
        }
 | 
						||
        _data_a = TDate(giorni_del_mese, _fino_a_mese, _annoes);  // Meglio cosi'
 | 
						||
      }
 | 
						||
      _stampa_data_reg = stampa_datareg();
 | 
						||
      if (_tipo_stampa == libro_unico)
 | 
						||
        compila_lib();
 | 
						||
      stampa_registri_IVA(m);
 | 
						||
    }
 | 
						||
    else 
 | 
						||
    {
 | 
						||
      warning_box("Nessuna ditta selezionata!");
 | 
						||
      continue;
 | 
						||
    } 
 | 
						||
  }
 | 
						||
  return FALSE;
 | 
						||
}
 | 
						||
 | 
						||
//********* FUNZIONE PRINCIPALE *********//
 | 
						||
 | 
						||
bool TStampa_registri_app::stampa_registri_IVA(const TMask& m) 
 | 
						||
{
 | 
						||
  bool ok = FALSE;
 | 
						||
  TRectype mov_from(LF_MOV), mov_to(LF_MOV);
 | 
						||
  for (int i = 0; i < _ditte->items(); i++)
 | 
						||
  {
 | 
						||
    if (_selected[(long)i])
 | 
						||
    {
 | 
						||
      bool msg = TRUE;
 | 
						||
      _ditta       = _ditte->row(i).get_long(1);
 | 
						||
      _frequiva    = _ditte->row(i).get_char(3);
 | 
						||
      _intesta_liq = FALSE;
 | 
						||
      _intesta_vidi = FALSE;
 | 
						||
      _primast = _u_stampata; 
 | 
						||
      _ok_vidi = FALSE;
 | 
						||
      _stampa_mese = 13;
 | 
						||
      
 | 
						||
      TApplication::set_firm(_ditta);
 | 
						||
      _st_tot_fin = stampa_totali_finali();
 | 
						||
      look_lia();
 | 
						||
      ok = compila_reg(m);   
 | 
						||
      if (!ok) continue;
 | 
						||
      if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
        if (!controlla_mov())
 | 
						||
        {
 | 
						||
          TApplication::set_firm(__firm);
 | 
						||
          return error_box("Finire di stampare registri anno precedente");
 | 
						||
        }
 | 
						||
      if (!_stampa_tutti_i_registri)
 | 
						||
      {
 | 
						||
        _scelta = no_liquidazione;
 | 
						||
        mov_from.put(MOV_DATAREG, _data_da);
 | 
						||
        mov_to.put(MOV_DATAREG, _data_a);
 | 
						||
        _cur->setregion(mov_from, mov_to);
 | 
						||
        _cur->set_filterfunction(filter_func, TRUE);
 | 
						||
        //la filter function viene chiamata quando posiziono il cursore
 | 
						||
        //e' lei che determina _stampa_mese da settare in setta_mask
 | 
						||
        (*_cur) = 0L; 
 | 
						||
        ok = setta_mask(i); 
 | 
						||
        if (!ok) continue;
 | 
						||
        if (_liquidazione)
 | 
						||
        {
 | 
						||
          _size_header = 3;
 | 
						||
          if ((_tipo_stampa == bollato || _tipo_stampa == rif_giornale) && !_stampa_ind_ditta) _size_header++;
 | 
						||
          clear_stliq(); 
 | 
						||
          //l'inizializzazione di _scelta vale per tutti
 | 
						||
          //i mesi da stampare di un certo registro (su 
 | 
						||
          //cui c'e' la X di stampa liquidazione). Cio'
 | 
						||
          //e' molto importante (per capire vedi appunti)
 | 
						||
          _scelta = controlla_liquidazione();
 | 
						||
          if (_scelta == non_proseguire) 
 | 
						||
            return FALSE;
 | 
						||
        } 
 | 
						||
        const long item = _cur->items();
 | 
						||
 | 
						||
        // 17.5.95 Leggo parametri di stampa del registro  
 | 
						||
        TString16   config;
 | 
						||
        const long  codditta = get_firm();   
 | 
						||
        const char* reg      = (const char*)_codreg;
 | 
						||
        config.format("REG%05ld%s", codditta, reg);
 | 
						||
        printer().read_configuration(config);
 | 
						||
        
 | 
						||
        _mov_empty = TRUE;
 | 
						||
        
 | 
						||
        if (item > 0l)
 | 
						||
        {
 | 
						||
          print(); 
 | 
						||
          if (is_cancelled()) 
 | 
						||
            return FALSE;
 | 
						||
        }
 | 
						||
        //non ci sono movimenti da stampare nel periodo richiesto!
 | 
						||
        else 
 | 
						||
          no_movimenti(); 
 | 
						||
        
 | 
						||
        if (_tipo_stampa == libro_unico && _rif_vid)
 | 
						||
        { 
 | 
						||
          _intesta_vidi = TRUE;
 | 
						||
          stampa_vidi(); //stampa riferimenti vidimazione
 | 
						||
        }    
 | 
						||
      }  
 | 
						||
      else //stampa tutti i registri 
 | 
						||
      {
 | 
						||
        TString16 codtab, cod_lib_un;
 | 
						||
        int anno; 
 | 
						||
        TDate sca_vid;
 | 
						||
        bool one_printed = FALSE; // Flag per vedere se ha stampato almeno un registro (solo per rif. al libro giornale)
 | 
						||
        for (_tabreg->first(); !_tabreg->eof(); _tabreg->next())
 | 
						||
        { 
 | 
						||
          _tipo_reg = (tiporeg)_tabreg->get_int("I0");
 | 
						||
          codtab = _tabreg->get("CODTAB");
 | 
						||
          anno = atoi(codtab.mid(0,4));
 | 
						||
          if (anno > _annoes)
 | 
						||
            break;
 | 
						||
          if (anno == _annoes)                                       
 | 
						||
            //registro iva
 | 
						||
            if (_tipo_reg == vendita || _tipo_reg == acquisto || _tipo_reg == riepilogativo) 
 | 
						||
            {
 | 
						||
              _codreg    = codtab.mid(4,3);
 | 
						||
              cod_lib_un = _tabreg->get("S6");
 | 
						||
              sca_vid    = _tabreg->get_date("D1");
 | 
						||
              _stampa_plafonds  = _tabreg->get_char ("S10") == 'X';
 | 
						||
              _stampa_num_pag   = _tabreg->get_char ("S11") == 'X';
 | 
						||
              _stampa_ind_ditta = _tabreg->get_bool("B9");
 | 
						||
              _liquidazione     = _tabreg->get_bool("B7");
 | 
						||
              if (_tipo_stampa != prova)
 | 
						||
                _u_data = _tabreg->get_date("D3");
 | 
						||
              if (_tipo_stampa == bollato || _tipo_stampa == rif_giornale)
 | 
						||
              {
 | 
						||
                if (cod_lib_un.not_empty())
 | 
						||
                  continue; 
 | 
						||
                if (sca_vid.ok())
 | 
						||
                  if (sca_vid.month() < _fino_a_mese)
 | 
						||
                    continue;
 | 
						||
                if (_u_data.ok())
 | 
						||
                  if (_data_a < _u_data)  //e' molto imp. che rimanga < e non <= !!! 
 | 
						||
                  {                       //(per via del discorso liq. annuale)
 | 
						||
                    message_box("Ditta %ld: Il registro %s e' gia' stato stampato come bollato di %s", _ditta, (const char*) _codreg, itom(_fino_a_mese)); 
 | 
						||
                    continue;
 | 
						||
                  }   
 | 
						||
              }
 | 
						||
              if (_tipo_stampa == rif_giornale) //stampa con riferimenti al libro giornale
 | 
						||
              {
 | 
						||
                TDate d;
 | 
						||
                bool good;
 | 
						||
                bool trovato = cerca_libro_gio(d, good);
 | 
						||
                if (trovato)  
 | 
						||
                  one_printed = TRUE;
 | 
						||
                else 
 | 
						||
                  continue; 
 | 
						||
              }
 | 
						||
              if (_tipo_stampa == libro_unico) //stampa su libro unico
 | 
						||
              {
 | 
						||
                if (cod_lib_un != _codlib)
 | 
						||
                  continue;
 | 
						||
                if (sca_vid.ok())
 | 
						||
                  if (sca_vid.month() < _fino_a_mese)   
 | 
						||
                    continue;
 | 
						||
                if (_u_data.ok())
 | 
						||
                  if (_fino_a_mese < _u_data.month()) //significa che e' gia' 
 | 
						||
                    continue;                         //stato stampato        
 | 
						||
              }
 | 
						||
              msg = FALSE;
 | 
						||
              
 | 
						||
              look_reg();
 | 
						||
              
 | 
						||
              _intesta_liq  = FALSE;
 | 
						||
              _intesta_vidi = FALSE; 
 | 
						||
              _primast = _u_stampata; //per la numerazione dei registri successivi
 | 
						||
              _ok_vidi = FALSE;
 | 
						||
              _stampa_mese = 13;
 | 
						||
              _scelta = no_liquidazione;    
 | 
						||
              
 | 
						||
              //modifica del 09/11/1995
 | 
						||
              mov_from.put(MOV_DATAREG, _data_da);
 | 
						||
              mov_to.put(MOV_DATAREG, _data_a);
 | 
						||
              _cur->setregion(mov_from, mov_to);
 | 
						||
              _cur->set_filterfunction(NULL);
 | 
						||
              _cur->set_filterfunction(filter_func, TRUE); 
 | 
						||
              (*_cur) = 0L;
 | 
						||
              ok = setta_mask(i);    
 | 
						||
              if (!ok) continue;
 | 
						||
              
 | 
						||
              if (_liquidazione)
 | 
						||
              {
 | 
						||
                _size_header = 3;
 | 
						||
                if ((_tipo_stampa == bollato || _tipo_stampa == rif_giornale) && !_stampa_ind_ditta) _size_header++;
 | 
						||
                clear_stliq();
 | 
						||
                //N.B. E' fondamentale che _scelta venga ri-inizializzata ad ogni
 | 
						||
                //registro(cioe' dopo la stampa di ciascuno). Infatti il B0 di un
 | 
						||
                //certo mese puo' essere cambiato durante la stampa di un certo 
 | 
						||
                //registro   
 | 
						||
                _scelta = controlla_liquidazione();
 | 
						||
                if (_scelta == non_proseguire) 
 | 
						||
                  return FALSE;
 | 
						||
              } 
 | 
						||
              // Guardo se ci sono movimenti
 | 
						||
              const long items = _cur->items();
 | 
						||
 | 
						||
              //Leggo parametri di stampa del registro  
 | 
						||
              TString16   config;
 | 
						||
              const long  codditta = get_firm();   
 | 
						||
              const char* reg = (const char*)_codreg;
 | 
						||
              config.format("REG%05ld%s", codditta, reg);
 | 
						||
              printer().read_configuration(config);
 | 
						||
              
 | 
						||
              _mov_empty = TRUE;
 | 
						||
              
 | 
						||
              if (items > 0l)
 | 
						||
              {  
 | 
						||
                print(); 
 | 
						||
                if (is_cancelled())
 | 
						||
                  return FALSE;
 | 
						||
              }
 | 
						||
              else
 | 
						||
                no_movimenti();
 | 
						||
              
 | 
						||
              if (_tipo_stampa == libro_unico && _rif_vid)
 | 
						||
              { 
 | 
						||
                _intesta_vidi = TRUE;
 | 
						||
                stampa_vidi(); //stampa riferimenti vidimazione
 | 
						||
              } 
 | 
						||
            }  
 | 
						||
        } //for
 | 
						||
        
 | 
						||
        if (_tipo_stampa == rif_giornale && !one_printed) // stampa con rif libro giornale
 | 
						||
          message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", _ditta);
 | 
						||
        
 | 
						||
        if (msg)
 | 
						||
          if(_tipo_stampa == libro_unico && _fino_a_mese == 1 && _selected.ones() == 1L)
 | 
						||
            message_box("Ditta %ld: nessun registro soddisfa i parametri indicati", _ditta);                 //viene gia' dato nell'handler 
 | 
						||
      }                                                                                                      //da Gennaio)  
 | 
						||
    }
 | 
						||
  }              
 | 
						||
  printer().read_configuration();
 | 
						||
  TApplication::set_firm(__firm);
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
//Stampa registro riepilogativo
 | 
						||
bool TStampa_registri_app::stampa_riepilogo(int m)
 | 
						||
{
 | 
						||
  TString80 chiave,ctab;
 | 
						||
  TString16 codtab, codreg, creg, codatt, codiva;
 | 
						||
  TRiga_array vect, vect_prec;  
 | 
						||
  TRigaiva_array vect_det;
 | 
						||
  bool stampato = FALSE;
 | 
						||
  if (!printer().isopen()) printer().open();
 | 
						||
  
 | 
						||
  for (_tabreg->first(); !_tabreg->eof(); _tabreg->next()) // Scorre i registri
 | 
						||
  {
 | 
						||
    codtab = _tabreg->get("CODTAB");
 | 
						||
    const int a = atoi(codtab.mid(0,4));
 | 
						||
 | 
						||
    if (a > _annoes) break; 
 | 
						||
 | 
						||
    const tiporeg tipo = (tiporeg)_tabreg->get_int("I0");
 | 
						||
 | 
						||
    if (a == _annoes && (tipo == vendita || tipo == acquisto))
 | 
						||
    {
 | 
						||
      codreg = codtab.mid(4,3);
 | 
						||
      codatt = _tabreg->get("S8");
 | 
						||
      //devo stampare sul riepilogativo
 | 
						||
      //solo i registri movimentati!!!
 | 
						||
      vect.destroy();
 | 
						||
      vect_prec.destroy();
 | 
						||
      vect_det.destroy();
 | 
						||
      chiave.cut(0);
 | 
						||
      chiave << _annoes << _tabreg->get("S8");
 | 
						||
 | 
						||
      // Calcolo riepilogo del periodo e progressivi in caso di stampa su bollato
 | 
						||
      for (int i=1; i<=m; i++) 
 | 
						||
      {
 | 
						||
        int start = 0, stop = 0;
 | 
						||
        if (i == m && _annoes > 1997) // Per il mese attuale 
 | 
						||
          stop = 1;                   // si calcolano anche i progressivi precedenti a questo periodo (PRP)
 | 
						||
                                      // solo se siamo oltre il 1997
 | 
						||
        for (int j = start; j <= stop; j++)
 | 
						||
        {
 | 
						||
          const bool calc_prp = j == 1;
 | 
						||
          
 | 
						||
          TTable* tabula = calc_prp ?  _tabprp : _table ;
 | 
						||
          tabula->zero();
 | 
						||
          tabula->put("CODTAB", chiave);
 | 
						||
          const TRectype r(tabula->curr());
 | 
						||
          tabula->read(_isgteq);
 | 
						||
          for (; !tabula->eof(); tabula->next())
 | 
						||
          {
 | 
						||
            if (tabula->curr() != r) break;
 | 
						||
            ctab   = tabula->get("CODTAB");
 | 
						||
            creg   = ctab.mid(10,3); creg.trim();
 | 
						||
            const int mese = atoi(ctab.mid(13,2)); 
 | 
						||
            if (codreg == creg && mese == i)
 | 
						||
            {
 | 
						||
              codiva = ctab.mid(16,4);           
 | 
						||
              int tipodet = atoi(ctab.mid(20,1));
 | 
						||
              real impon = tabula->get_real("R0");
 | 
						||
              real impos = tabula->get_real("R1");
 | 
						||
              real impol = tabula->get_real("R2"); 
 | 
						||
              if (_tabreg->get_bool("B0"))
 | 
						||
              {
 | 
						||
                TToken_string cs(tabula->get("S2"),'!');
 | 
						||
                impon = cs.get(0);
 | 
						||
                impos = cs.get(1);       
 | 
						||
              }                   
 | 
						||
              if (_tabreg->get_bool("B1"))
 | 
						||
              {
 | 
						||
                impon = tabula->get_real("R11");
 | 
						||
                impos = tabula->get_real("R12");
 | 
						||
              } 
 | 
						||
              TToken_string fatt_rit(tabula->get("S1"),'!');
 | 
						||
              real im(fatt_rit.get(0));
 | 
						||
              real is(fatt_rit.get(1));
 | 
						||
              impon += im;
 | 
						||
              impos += is;
 | 
						||
              impol += im+is;
 | 
						||
              if (impon != ZERO || impos != ZERO || impol != ZERO)
 | 
						||
              {
 | 
						||
                if (!calc_prp && _tipo_stampa != prova)
 | 
						||
                  vect.add_riga(ZERO, ZERO, ZERO, impon,impos,impol,codiva); 
 | 
						||
                
 | 
						||
                if (mese == m || (_frequiva == 'T' && mese >= m-2 && mese <= m))  // Guy!!!
 | 
						||
                  if (calc_prp)
 | 
						||
                    vect_prec.add_riga(impon,impos,impol,ZERO,ZERO,ZERO,codiva); 
 | 
						||
                  else
 | 
						||
                    vect.add_riga(impon,impos,impol,ZERO,ZERO,ZERO,codiva); 
 | 
						||
              }
 | 
						||
              
 | 
						||
              if (!calc_prp && tipo == acquisto) //registro acquisti
 | 
						||
                if (impon != ZERO || impos != ZERO) 
 | 
						||
                {
 | 
						||
                  if (_tipo_stampa != prova)
 | 
						||
                    vect_det.add_riga(ZERO,ZERO,impon,impos,codiva,tipodet,0,TRUE);  
 | 
						||
                  if (mese == m || (_frequiva == 'T' && mese >= m-2 && mese <= m)) // Guy!!!
 | 
						||
                    vect_det.add_riga(impon,impos,ZERO,ZERO,codiva,tipodet,0,TRUE);  
 | 
						||
                }
 | 
						||
            }
 | 
						||
          } // for table
 | 
						||
        } // for start to stop
 | 
						||
      } // for i to m
 | 
						||
      
 | 
						||
      if (vect.items() > 0)
 | 
						||
      {
 | 
						||
        stampato = TRUE;
 | 
						||
        TPrintrow row;
 | 
						||
        row.reset();
 | 
						||
        printer().print(row);
 | 
						||
        row.put("Registro iva:", 0);
 | 
						||
        row.put(codreg, 14); 
 | 
						||
        row.put(format("%-.40s",(const char*)_tabreg->get("S0")), 18);
 | 
						||
        row.put("Attivita\'", 60);
 | 
						||
        row.put(codatt, 70);
 | 
						||
        TString80 desc = desc_attivita(codatt);
 | 
						||
        row.put(desc, 76);       
 | 
						||
        printer().print(row);
 | 
						||
        row.reset();
 | 
						||
        printer().print(row);
 | 
						||
        if (tipo == 1 && _tabreg->get_bool("B0"))
 | 
						||
          row.put("------------------ P E R I O D O -------------------", 30);
 | 
						||
        else
 | 
						||
          row.put("---------- P E R I O D O -----------", 30);
 | 
						||
        if (_tipo_stampa != 1)
 | 
						||
        {
 | 
						||
         if (tipo == 1 && _tabreg->get_bool("B0"))
 | 
						||
           row.put("----------- P R O G R E S S I V I --------------", 84);
 | 
						||
         else
 | 
						||
           row.put("------ P R O G R E S S I V I ------", 84);
 | 
						||
        }                     
 | 
						||
        printer().print(row);
 | 
						||
        row.reset();
 | 
						||
        row.put("Cod.", 0);
 | 
						||
        if (tipo == 2)
 | 
						||
        {
 | 
						||
          const bool print_prec = i == 1;
 | 
						||
          stampa_prospetto_riepilogo(tipo, codreg, codatt, print_prec);
 | 
						||
          stampa_progressivi(print_prec ? vect_prec : vect, vect_det, tipo, print_prec);
 | 
						||
          if (vect_prec.items() == 0)
 | 
						||
            break;
 | 
						||
        }
 | 
						||
      } 
 | 
						||
    }
 | 
						||
  }   
 | 
						||
  return stampato;
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::stampa_prospetto_riepilogo(tiporeg tipo, const TString& codreg, const TString& codatt, const bool print_prec)
 | 
						||
{
 | 
						||
  TString80 desc(desc_attivita(codatt));
 | 
						||
  TPrinter& pr = printer();
 | 
						||
  TPrintrow row;
 | 
						||
  
 | 
						||
  row.reset();
 | 
						||
  pr.print(row);
 | 
						||
 | 
						||
  if (!print_prec)
 | 
						||
  {
 | 
						||
    row.put("Registro iva:", 0);
 | 
						||
    row.put(codreg, 14); 
 | 
						||
    row.put(format("%-.40s",(const char*)_tabreg->get("S0")), 18);
 | 
						||
    row.put("Attivita\'", 60);
 | 
						||
    row.put(codatt, 70);
 | 
						||
    row.put(desc, 76);       
 | 
						||
    pr.print(row);
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    row.put("DI CUI PERIODO PRECEDENTE");
 | 
						||
    pr.print(row);
 | 
						||
  }
 | 
						||
  
 | 
						||
  row.reset();
 | 
						||
  pr.print(row);
 | 
						||
  if (tipo == vendita && _tabreg->get_bool("B0"))
 | 
						||
    row.put("------------------ P E R I O D O -------------------", 30);
 | 
						||
  else
 | 
						||
    row.put("---------- P E R I O D O -----------", 30);
 | 
						||
  if (_tipo_stampa != prova && !print_prec)
 | 
						||
  {
 | 
						||
   if (tipo == vendita && _tabreg->get_bool("B0"))
 | 
						||
     row.put("----------- P R O G R E S S I V I --------------", 84);
 | 
						||
   else
 | 
						||
     row.put("------ P R O G R E S S I V I ------", 84);
 | 
						||
  }                     
 | 
						||
  pr.print(row);
 | 
						||
  row.reset();
 | 
						||
  row.put("Cod.", 0);
 | 
						||
  if (tipo == acquisto)
 | 
						||
  {
 | 
						||
   row.put("A C Q U I S T I", 40);
 | 
						||
   if (_tipo_stampa != prova && !print_prec)
 | 
						||
     row.put("A C Q U I S T I", 94);
 | 
						||
  }
 | 
						||
  if (tipo == vendita) 
 | 
						||
  {
 | 
						||
   row.put("V E N D I T E", 41);
 | 
						||
   if (_tabreg->get_bool("B0"))
 | 
						||
     row.put("CORRISPETTIVI", 67);
 | 
						||
   if (_tipo_stampa != prova && !print_prec)
 | 
						||
   {  
 | 
						||
    if (_tabreg->get_bool("B0"))                   
 | 
						||
    {
 | 
						||
     row.put("V E N D I T E", 94); 
 | 
						||
     row.put("CORRISPETTIVI", 118);           
 | 
						||
    }
 | 
						||
    else row.put("V E N D I T E", 95);
 | 
						||
   }                   
 | 
						||
  }
 | 
						||
  pr.print(row);
 | 
						||
  row.reset();      
 | 
						||
  row.put("iva  Descrizione", 0);
 | 
						||
  row.put("Imponibile", 34);
 | 
						||
  row.put("Imposta", 53);
 | 
						||
  if (tipo == vendita && _tabreg->get_bool("B0"))
 | 
						||
    row.put("Importi lordi", 67);
 | 
						||
  if (_tipo_stampa != prova && !print_prec)
 | 
						||
  {
 | 
						||
   row.put("Imponibile", 87);
 | 
						||
   row.put("Imposta", 107);
 | 
						||
   if (tipo == vendita && _tabreg->get_bool("B0"))
 | 
						||
     row.put("Importi lordi", 118);
 | 
						||
  }
 | 
						||
  pr.print(row);
 | 
						||
  row.reset();
 | 
						||
  pr.print(row); 
 | 
						||
}
 | 
						||
 | 
						||
void TStampa_registri_app::stampa_progressivi(TRiga_array& vect,
 | 
						||
                                     TRigaiva_array& vect_det, tiporeg treg, const bool print_prec)
 | 
						||
{
 | 
						||
  real t_impon, t_impos, t_impol, t_imponp, t_imposp, t_impolp;
 | 
						||
  t_impon = t_impos = t_impol = t_imponp = t_imposp = t_impolp = ZERO;
 | 
						||
  TPrintrow riga;
 | 
						||
  
 | 
						||
  riga.reset();
 | 
						||
  //ordinamento per codice iva
 | 
						||
  vect.sort(compare_rows);    
 | 
						||
  for (int k=0; k<vect.items(); k++)
 | 
						||
  {
 | 
						||
    TRiga& r = (TRiga&)vect[k];
 | 
						||
    riga.reset();
 | 
						||
    riga.put(format("%-4s",(const char*)r._codiva),0);
 | 
						||
    TString80 d = descr_iva(r._codiva);
 | 
						||
    riga.put(format("%-.23s",(const char*)d),5);    
 | 
						||
    if (r._imponibile != ZERO)
 | 
						||
      print_real(riga, r._imponibile, 29);
 | 
						||
    if (r._imposta != ZERO)
 | 
						||
      print_real(riga, r._imposta, 45);
 | 
						||
    if (treg == vendita && _tabreg->get_bool("B0"))
 | 
						||
      if (r._implordo != ZERO)
 | 
						||
        print_real(riga, r._implordo, 65);
 | 
						||
    if (_tipo_stampa != prova && !print_prec)
 | 
						||
    {
 | 
						||
      if (r._imponibilep != ZERO)
 | 
						||
        print_real(riga, r._imponibilep, 82);
 | 
						||
      if (r._impostap != ZERO)
 | 
						||
        print_real(riga, r._impostap, 99);
 | 
						||
      if (treg == vendita && _tabreg->get_bool("B0"))
 | 
						||
        if (r._implordop != ZERO)
 | 
						||
          print_real(riga, r._implordop, 116);
 | 
						||
    }
 | 
						||
    printer().print(riga);
 | 
						||
    riga.reset();
 | 
						||
    t_impon += r._imponibile;
 | 
						||
    t_impos += r._imposta;
 | 
						||
    t_impol += r._implordo;
 | 
						||
    t_imponp += r._imponibilep;
 | 
						||
    t_imposp += r._impostap;
 | 
						||
    t_impolp += r._implordop;     
 | 
						||
  }
 | 
						||
  
 | 
						||
  printer().print(riga);
 | 
						||
  riga.put("TOTALE", 0);
 | 
						||
  if (t_impon != ZERO)
 | 
						||
    print_real(riga, t_impon, 29);
 | 
						||
  if (t_impos != ZERO)
 | 
						||
    print_real(riga, t_impos, 45);
 | 
						||
  if (treg == vendita && _tabreg->get_bool("B0"))
 | 
						||
    if (t_impol != ZERO)
 | 
						||
      print_real(riga, t_impol, 65);
 | 
						||
  if (_tipo_stampa != prova && !print_prec)
 | 
						||
  {
 | 
						||
   if (t_imponp != ZERO)
 | 
						||
     print_real(riga, t_imponp, 82);
 | 
						||
   if (t_imposp != ZERO)
 | 
						||
     print_real(riga, t_imposp, 99);
 | 
						||
   if (treg == vendita && _tabreg->get_bool("B0"))
 | 
						||
     if (t_impolp != ZERO)
 | 
						||
       print_real(riga, t_impolp, 116);
 | 
						||
  }  
 | 
						||
  printer().print(riga); 
 | 
						||
  
 | 
						||
  //stampa tipi di indetraibilita' se registro acquisti
 | 
						||
  if (treg == acquisto && !print_prec) 
 | 
						||
  {
 | 
						||
    real tot_imponib, tot_imposta, tot_imponibp, tot_impostap;
 | 
						||
    int tdetprec = -1;
 | 
						||
    tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
    vect_det.sort(compare_fields);
 | 
						||
    for (int s=0; s<vect_det.items(); s++)
 | 
						||
    {
 | 
						||
      TRigaiva& r = (TRigaiva&)vect_det[s];
 | 
						||
      switch (r._tipodet)
 | 
						||
      {
 | 
						||
       case 1: 
 | 
						||
       {
 | 
						||
         if (tdetprec == 3 || tdetprec == 9)
 | 
						||
         {
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
          riga.put("TOTALE", 0);
 | 
						||
          if (tot_imponib != ZERO)
 | 
						||
            print_real(riga, tot_imponib, 29);
 | 
						||
 | 
						||
          if (tot_imposta != ZERO)                             
 | 
						||
            print_real(riga, tot_imposta, 45);
 | 
						||
          if (_tipo_stampa != prova)
 | 
						||
          {
 | 
						||
           if (tot_imponibp != ZERO)    
 | 
						||
             print_real(riga, tot_imponibp, 82);
 | 
						||
           if (tot_impostap != ZERO)
 | 
						||
             print_real(riga, tot_impostap, 99);
 | 
						||
          }  
 | 
						||
          printer().print(riga);
 | 
						||
          tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
         }
 | 
						||
         if (r._tipodet != tdetprec)
 | 
						||
         {    
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
          riga.put("----- Indetraibile su op.es. -----", 0);
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          riga.put("Cod.", 0);
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          riga.put("iva  Descrizione", 0);
 | 
						||
          riga.put("Imponibile", 34);
 | 
						||
          riga.put("Imposta", 53);
 | 
						||
          if (_tipo_stampa != prova) 
 | 
						||
          {
 | 
						||
           riga.put("Imponibile", 87);
 | 
						||
           riga.put("Imposta", 107);
 | 
						||
          }
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
         } 
 | 
						||
         riga.put(format("%-4s",(const char*)r._codiva),0);
 | 
						||
         TString descr = descr_iva(r._codiva);
 | 
						||
         riga.put(format("%-.23s",(const char*)descr),5);    
 | 
						||
         if (r._imponibile != ZERO)
 | 
						||
           print_real(riga, r._imponibile, 29);
 | 
						||
         if (r._imposta != ZERO)
 | 
						||
           print_real(riga, r._imposta, 45);
 | 
						||
         if (_tipo_stampa != prova)
 | 
						||
         {
 | 
						||
          if (r._imponibilep != ZERO)
 | 
						||
            print_real(riga, r._imponibilep, 82);
 | 
						||
          if (r._impostap != ZERO)
 | 
						||
            print_real(riga, r._impostap, 99);
 | 
						||
         }
 | 
						||
         printer().print(riga);
 | 
						||
         tot_imponib += r._imponibile;
 | 
						||
         tot_imposta += r._imposta;
 | 
						||
         tot_imponibp += r._imponibilep;
 | 
						||
         tot_impostap += r._impostap;
 | 
						||
         tdetprec = r._tipodet;
 | 
						||
       }  
 | 
						||
       break;
 | 
						||
       case 3: 
 | 
						||
       {
 | 
						||
         if (tdetprec == 1 || tdetprec == 9)
 | 
						||
         {
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
          riga.put("TOTALE", 0);
 | 
						||
          if (tot_imponib != ZERO)
 | 
						||
            print_real(riga, tot_imponib, 29);
 | 
						||
 | 
						||
          if (tot_imposta != ZERO)                             
 | 
						||
            print_real(riga, tot_imposta, 45);
 | 
						||
          if (_tipo_stampa != prova)
 | 
						||
          {
 | 
						||
           if (tot_imponibp != ZERO)    
 | 
						||
             print_real(riga, tot_imponibp, 82);
 | 
						||
           if (tot_impostap != ZERO)
 | 
						||
             print_real(riga, tot_impostap, 99);
 | 
						||
          }
 | 
						||
          printer().print(riga);
 | 
						||
          tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
         }   
 | 
						||
         if (r._tipodet != tdetprec)
 | 
						||
         { 
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
          riga.put("----- Passaggi interni -----",0);
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          riga.put("Cod.", 0);
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          riga.put("iva  Descrizione", 0);
 | 
						||
          riga.put("Imponibile", 34);
 | 
						||
          riga.put("Imposta", 53);
 | 
						||
          if (_tipo_stampa != prova) 
 | 
						||
          {
 | 
						||
           riga.put("Imponibile", 87);
 | 
						||
           riga.put("Imposta", 107);
 | 
						||
          }
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
         }
 | 
						||
         riga.put(format("%-4s",(const char*)r._codiva),0);
 | 
						||
         TString descr = descr_iva(r._codiva);
 | 
						||
         riga.put(format("%-.23s",(const char*)descr),5);    
 | 
						||
         if (r._imponibile != ZERO)
 | 
						||
           print_real(riga, r._imponibile, 29);
 | 
						||
         if (r._imposta != ZERO)
 | 
						||
           print_real(riga, r._imposta, 45);
 | 
						||
         if (_tipo_stampa != prova)
 | 
						||
         {
 | 
						||
          if (r._imponibilep != ZERO)
 | 
						||
            print_real(riga, r._imponibilep, 82);
 | 
						||
 | 
						||
          if (r._impostap != ZERO)
 | 
						||
            print_real(riga, r._impostap, 99);
 | 
						||
         }
 | 
						||
         printer().print(riga);
 | 
						||
         tot_imponib += r._imponibile;
 | 
						||
         tot_imposta += r._imposta;
 | 
						||
         tot_imponibp += r._imponibilep;
 | 
						||
         tot_impostap += r._impostap;
 | 
						||
         tdetprec = r._tipodet;
 | 
						||
       }
 | 
						||
       break;
 | 
						||
       case 9:
 | 
						||
       { 
 | 
						||
         if (tdetprec == 1 || tdetprec == 3)
 | 
						||
         {
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
          riga.put("TOTALE", 0);
 | 
						||
          if (tot_imponib != ZERO)
 | 
						||
            print_real(riga, tot_imponib, 29);
 | 
						||
 | 
						||
          if (tot_imposta != ZERO)                             
 | 
						||
            print_real(riga, tot_imposta, 45);
 | 
						||
          if (_tipo_stampa != prova)
 | 
						||
          {
 | 
						||
           if (tot_imponibp != ZERO)    
 | 
						||
             print_real(riga, tot_imponibp, 82);
 | 
						||
           if (tot_impostap != ZERO)
 | 
						||
             print_real(riga, tot_impostap, 99);
 | 
						||
          }
 | 
						||
          printer().print(riga);
 | 
						||
          tot_imponib = tot_imposta = tot_imponibp = tot_impostap = ZERO;
 | 
						||
         }
 | 
						||
         if (r._tipodet != tdetprec)
 | 
						||
         {  
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
          riga.put("----- N.D. 9 - acquisti indeducibili per ART.19 -----", 0);
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          riga.put("Cod.", 0);
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          riga.put("iva  Descrizione", 0);
 | 
						||
          riga.put("Imponibile", 34);
 | 
						||
          riga.put("Imposta", 53);
 | 
						||
          if (_tipo_stampa != prova) 
 | 
						||
          {
 | 
						||
           riga.put("Imponibile", 87);
 | 
						||
           riga.put("Imposta", 107);
 | 
						||
          }
 | 
						||
          printer().print(riga);
 | 
						||
          riga.reset();
 | 
						||
          printer().print(riga);
 | 
						||
         }
 | 
						||
         riga.put(format("%-4s",(const char*)r._codiva),0);
 | 
						||
         TString descr = descr_iva(r._codiva);
 | 
						||
         riga.put(format("%-.23s",(const char*)descr),5);    
 | 
						||
         if (r._imponibile != ZERO)
 | 
						||
           print_real(riga, r._imponibile, 29);
 | 
						||
 | 
						||
         if (r._imposta != ZERO)
 | 
						||
           print_real(riga, r._imposta, 45);
 | 
						||
         if (_tipo_stampa != prova)
 | 
						||
         {
 | 
						||
          if (r._imponibilep != ZERO)
 | 
						||
            print_real(riga, r._imponibilep, 82);
 | 
						||
          if (r._impostap != ZERO)
 | 
						||
            print_real(riga, r._impostap, 99);
 | 
						||
         }
 | 
						||
         printer().print(riga);
 | 
						||
         tot_imponib += r._imponibile;
 | 
						||
         tot_imposta += r._imposta;
 | 
						||
         tot_imponibp += r._imponibilep;
 | 
						||
         tot_impostap += r._impostap;
 | 
						||
         tdetprec = r._tipodet; 
 | 
						||
       }  
 | 
						||
       break;
 | 
						||
       default: break;                         
 | 
						||
      }
 | 
						||
    }  
 | 
						||
    if (vect_det.items() > 0)
 | 
						||
      if (tdetprec == 1 || tdetprec == 3 || tdetprec == 9)
 | 
						||
      {
 | 
						||
       riga.reset();
 | 
						||
       printer().print(riga);
 | 
						||
       riga.put("TOTALE", 0);
 | 
						||
       if (tot_imponib != ZERO)
 | 
						||
         print_real(riga, tot_imponib, 29);
 | 
						||
       if (tot_imposta != ZERO)                             
 | 
						||
         print_real(riga, tot_imposta, 45);
 | 
						||
       if (_tipo_stampa != prova)
 | 
						||
       {
 | 
						||
        if (tot_imponibp != ZERO)    
 | 
						||
          print_real(riga, tot_imponibp, 82);
 | 
						||
        if (tot_impostap != ZERO)
 | 
						||
          print_real(riga, tot_impostap, 99);
 | 
						||
       }  
 | 
						||
       printer().print(riga);
 | 
						||
      }   
 | 
						||
  }
 | 
						||
}  
 | 
						||
 | 
						||
int cg4400 (int argc, char * argv[])
 | 
						||
{  
 | 
						||
  TStampa_registri_app* a = new TStampa_registri_app;
 | 
						||
  a->run(argc, argv, "Stampa registri IVA");
 | 
						||
  delete a;
 | 
						||
  return 0;
 | 
						||
}
 |