TDocumento. (Separato da ve1100). In ve0100.h e ve0100.cpp ho spostato la definizione di app(). (Dal .cpp al .h). git-svn-id: svn://10.65.10.50/trunk@3404 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			282 lines
		
	
	
		
			9.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			282 lines
		
	
	
		
			9.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "velib02.h"
 | 
						|
 | 
						|
////////////////
 | 
						|
// Riepilogo IVA
 | 
						|
////////////////
 | 
						|
Riepilogo_Iva& Riepilogo_Iva::operator=(Riepilogo_Iva& a)
 | 
						|
{ 
 | 
						|
  _imp = a.imp(); _iva = a.iva(); _ali = a.ali();
 | 
						|
  _cod = a.cod(); _tipo = a.tipo(); _des = a.des();
 | 
						|
  return *this;
 | 
						|
}
 | 
						|
 | 
						|
//////////////////
 | 
						|
//TDocumentoEsteso
 | 
						|
//////////////////
 | 
						|
void TDocumentoEsteso::compile_summary()
 | 
						|
{
 | 
						|
  _sum_filter = 0;
 | 
						|
  const int items = rows();
 | 
						|
  
 | 
						|
  _summary_table.destroy();
 | 
						|
  _imposte = 0.0;
 | 
						|
  _importi_netti = 0.0;
 | 
						|
  const bool val = in_valuta();
 | 
						|
  // Scorre tutte le righe e compila la tabellina _summary_table
 | 
						|
  for (int i = 1; i <= items; i++)
 | 
						|
  {
 | 
						|
    TRectype& r = row(i);
 | 
						|
    int nriga = r.get_int("NRIGA");
 | 
						|
    real price = r.get_real("PREZZO");
 | 
						|
    real qta = r.get_real("QTA");
 | 
						|
    real aliquota, sc, imponibile, iva;
 | 
						|
    TString sconto(r.get("SCONTO"));
 | 
						|
    TString codiva(r.get("CODIVA"));
 | 
						|
    _iva->put("CODTAB", codiva);
 | 
						|
    if (_iva->read() != NOERR) continue; // Se non trova il codice salta questa riga
 | 
						|
    
 | 
						|
    aliquota = _iva->get_real("R0");
 | 
						|
    if (_condv != NULL && sconto.not_empty()) // Se c'e' la condizione di vendita, calcola lo sconto...
 | 
						|
    {
 | 
						|
      _condv->set_sconto(sconto);
 | 
						|
      sc = 100.0 - _condv->sconto_val();
 | 
						|
      price = ((price * sc) / 100.0);
 | 
						|
    }
 | 
						|
    price.round(val ? _parm.pri_val : _parm.pri_lit); // prezzo scontato
 | 
						|
    qta.round(val ? _parm.qta_val : _parm.qta_lit);
 | 
						|
    imponibile = price * qta;
 | 
						|
    imponibile.round (val? _parm.imp_val : _parm.imp_lit); // imponibile di riga
 | 
						|
    iva = (imponibile * aliquota) / 100.0;
 | 
						|
    iva.ceil(val ? _parm.imp_val : _parm.imp_lit); // imposta calcolata
 | 
						|
 | 
						|
    // Aggiorna o aggiunge l'elemento se non esiste    
 | 
						|
    Riepilogo_Iva riepilogo_tmp;
 | 
						|
    const bool exists = _summary_table.is_key(codiva);
 | 
						|
    Riepilogo_Iva& riepilogo  = (exists ? (Riepilogo_Iva&)_summary_table[codiva] : riepilogo_tmp);
 | 
						|
    // Aggiorna anche il totale importi netti ed il totale imposte
 | 
						|
    _importi_netti += imponibile;
 | 
						|
    _imposte += iva;
 | 
						|
    riepilogo.imp() += imponibile; riepilogo.iva() += iva;
 | 
						|
    riepilogo.ali() = aliquota; riepilogo.cod() = codiva; 
 | 
						|
    TString16 tipo(_iva->get("S1"));
 | 
						|
    if (tipo == "VE") riepilogo.tipo() = 2;
 | 
						|
    else if (tipo == "ES") riepilogo.tipo() = 4;
 | 
						|
    else if (tipo == "NI") riepilogo.tipo() = 8;
 | 
						|
    else if (tipo == "NS") riepilogo.tipo() = 16;
 | 
						|
    else riepilogo.tipo() = 1; // Regime IVA normale
 | 
						|
    if (riepilogo.tipo() != 1) // Se non e' regime normale salva anche la descrizione
 | 
						|
      riepilogo.des() = _iva->get("S0");
 | 
						|
    _summary_table.add(codiva,riepilogo,exists);
 | 
						|
  }
 | 
						|
  // Inizializza l'array di ordine
 | 
						|
  for (i = 0; i<32;i++) 
 | 
						|
  {
 | 
						|
    TToken_string s;
 | 
						|
    _order_array.add(s);
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TDocumentoEsteso::summary_filter(byte selector)
 | 
						|
{
 | 
						|
  if (_sum_filter == -1) compile_summary(); // Crea la tabella se deve ancora farlo
 | 
						|
  // se ha selezionato una riga in precedenza deve finire di stamparla  
 | 
						|
  // ovvero non seleziona il filtro fino a quando non ha ricevuto una summary_set_next()
 | 
						|
  if (_sum_selected) return;
 | 
						|
  //
 | 
						|
  // Procedimento:
 | 
						|
  // Memorizza in un TString_array tante TToken_string quanti sono i filtri possibili
 | 
						|
  // (al massimo 31 [1+2+4+8+16]). Ogni TToken_string contiene i codici IVA
 | 
						|
  // delle righe di Riepilogo_Iva che soddisfano la condizione di filtro
 | 
						|
  _sum_selected = TRUE;
 | 
						|
  _sum_filter = selector;
 | 
						|
  TToken_string& codici = _order_array.row(_sum_filter-1);
 | 
						|
  if (codici.items() == 0) // Se non c'e' nemmeno un codice IVA allora deve effettuare il filtro
 | 
						|
  { // ovvero mette in <<codici>> tutti i codici IVA che soffisfano tale filtro
 | 
						|
    // sara' poi la summary_set_next() a selezionare sequenzialmente il giusto codice a seconda del filtro corrente
 | 
						|
 | 
						|
    // Scorre sequenzialmente la tabella _summary_table e compone la TToken_string coni codici IVA
 | 
						|
    const int items = _summary_table.items();
 | 
						|
    Riepilogo_Iva* curr = (Riepilogo_Iva *) _summary_table.first_item();
 | 
						|
    for (int i = 0; i < items && curr != NULL; i++)
 | 
						|
    {
 | 
						|
      if (curr->tipo() & _sum_filter) // se fa parte del filtro selezionato schiaffa il codice nella TToken_string
 | 
						|
        codici.add(curr->cod());
 | 
						|
      curr = (Riepilogo_Iva*) _summary_table.succ_item();
 | 
						|
    }
 | 
						|
    codici.restart();
 | 
						|
    summary_set_next(); // setta l'elemento corrente
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TDocumentoEsteso::summary_set_next()
 | 
						|
{
 | 
						|
  _sum_selected = FALSE;
 | 
						|
  TToken_string& codici = _order_array.row(_sum_filter-1);
 | 
						|
  
 | 
						|
  TString16 codiva(codici.get()); // Reperisce il prossimo codice nella lista. (son gia' ordinati per codice)
 | 
						|
  if (codiva.not_empty() && _summary_table.is_key(codiva))
 | 
						|
  {
 | 
						|
    // Estrae da _summary_table i dati relativio al codice corrispondente.
 | 
						|
    Riepilogo_Iva& riep= (Riepilogo_Iva&) _summary_table[codiva];
 | 
						|
    _sum_current = riep;
 | 
						|
  }
 | 
						|
  else
 | 
						|
    _sum_current.zero(); // se non esiste il codice  azzera l'elemento corrente (non stampera' nulla)
 | 
						|
}
 | 
						|
 | 
						|
const char *  TDocumentoEsteso::summary_get(const TString& w)
 | 
						|
{
 | 
						|
  TString ret;
 | 
						|
  if (w == "COD") ret = _sum_current.cod();          // Ritorna il codice IVA
 | 
						|
  if (w == "IMP" && _sum_current.imp() != 0.0) ret = _sum_current.imp().string(); // Ritorna l'imponibile
 | 
						|
  if (w == "IVA" && _sum_current.iva() != 0.0) ret = _sum_current.iva().string(); // Ritorna l'imposta
 | 
						|
  if (w == "ALI" && _sum_current.ali() != 0.0) ret = _sum_current.ali().string(); // Ritorna l'aliquota %
 | 
						|
  if (w == "DES") ret = _sum_current.des();          // Ritorna la descrizione ( se il codice e' regime normale la descr. e' vuota)
 | 
						|
  return (const char *)ret;
 | 
						|
}
 | 
						|
 | 
						|
void  TDocumentoEsteso::scadenze_recalc()
 | 
						|
{
 | 
						|
  _scadenze_array.destroy();
 | 
						|
  _scadenze_current = -1;
 | 
						|
  TString16 codpag(head().get("CODPAG"));
 | 
						|
  TString16 data(head().get("DATAINSC"));
 | 
						|
  TPagamento pag( codpag, data);
 | 
						|
  real totspese = tot_spese();
 | 
						|
  real totimposte = tot_imposte();
 | 
						|
  real totimponibili = tot_documento() - totimposte - totspese;
 | 
						|
  const bool valuta = in_valuta();
 | 
						|
  if (valuta)
 | 
						|
  {
 | 
						|
    real change(cambio());
 | 
						|
    real val1 = totimponibili * change;
 | 
						|
    real val2 = totimposte * change;
 | 
						|
    real val3 = totspese * change;
 | 
						|
    pag.set_total_valuta( totimponibili, totimposte, totspese, change, val1, val2 ,val3);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    pag.set_total( totimponibili, totimposte, totspese );
 | 
						|
  pag.set_rate_auto( );      
 | 
						|
  const int numrate = pag.n_rate( );
 | 
						|
  for (int i = 0; i< numrate; i++)
 | 
						|
  {
 | 
						|
    TToken_string t;
 | 
						|
    t.add(pag.data_rata(i));
 | 
						|
    t.add(pag.importo_rata(i,valuta).string());
 | 
						|
    _scadenze_array.add(t);
 | 
						|
  }
 | 
						|
  if (numrate > 0) _scadenze_current++;
 | 
						|
}
 | 
						|
 | 
						|
const char *  TDocumentoEsteso::scadenze_get(const TString& w)
 | 
						|
{
 | 
						|
  TString ret;
 | 
						|
  
 | 
						|
  if (_scadenze_current == -1)
 | 
						|
    // calcola le scadenze e le mette in _scadenze_array
 | 
						|
    scadenze_recalc();
 | 
						|
  if (_scadenze_current > -1 && _scadenze_current < _scadenze_array.items())
 | 
						|
  {
 | 
						|
    if (w == "DATA") ret = _scadenze_array.row(_scadenze_current).get(0);    // ritorna la data di scadenza
 | 
						|
    if (w == "IMPORTO") ret = _scadenze_array.row(_scadenze_current).get(1); // ritorna l'importo in scadenza
 | 
						|
  }  
 | 
						|
  return (const char*)ret;
 | 
						|
}
 | 
						|
 | 
						|
void TDocumentoEsteso::scadenze_set_next()
 | 
						|
{
 | 
						|
  if (_scadenze_current < _scadenze_array.items() && _scadenze_current >= 0)
 | 
						|
    _scadenze_current++;
 | 
						|
}
 | 
						|
 | 
						|
real& TDocumentoEsteso::tot_importi_netti()
 | 
						|
{
 | 
						|
  if (!summary_compiled()) compile_summary();
 | 
						|
  return _importi_netti;  
 | 
						|
}
 | 
						|
 | 
						|
real& TDocumentoEsteso::tot_imposte()
 | 
						|
{
 | 
						|
  if (!summary_compiled()) compile_summary();
 | 
						|
  return _imposte;  
 | 
						|
}
 | 
						|
 | 
						|
real TDocumentoEsteso::tot_spese()
 | 
						|
{
 | 
						|
  TString16 t("TOTSP");
 | 
						|
  real number(get_head_info(t));
 | 
						|
  return number;
 | 
						|
}
 | 
						|
 | 
						|
real TDocumentoEsteso::tot_documento()
 | 
						|
{
 | 
						|
  if (!summary_compiled()) compile_summary();
 | 
						|
  real number = _imposte + _importi_netti;
 | 
						|
  return number;  
 | 
						|
}
 | 
						|
 | 
						|
real TDocumentoEsteso::tot_imponibili(byte selector)
 | 
						|
{
 | 
						|
  if (!summary_compiled()) compile_summary();
 | 
						|
  
 | 
						|
  real number = 0.0;
 | 
						|
  const int items = _summary_table.items();
 | 
						|
  Riepilogo_Iva* curr = (Riepilogo_Iva *) _summary_table.first_item();
 | 
						|
  for (int i = 0; i < items && curr != NULL; i++)
 | 
						|
  {
 | 
						|
    if (curr->tipo() & selector) // se fa parte del filtro selezionato schiaffa il codice nella TToken_string
 | 
						|
      number += curr->imp();
 | 
						|
    curr = (Riepilogo_Iva*) _summary_table.succ_item();
 | 
						|
  }
 | 
						|
  return number;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
const char* TDocumentoEsteso::get_head_info(const TString & what)
 | 
						|
{
 | 
						|
  TToken_string memo(head().get("G1"),'\n'); // prende il campo memo con i totalizzatori. Un totalizzatore per riga nella forma <MACRO>=<VALORE>
 | 
						|
  TString rt;
 | 
						|
  const int items = memo.items();
 | 
						|
  for (int i = 0; i<items; i++) // scorre le righe del memo
 | 
						|
  {
 | 
						|
    TToken_string item(memo.get(),'=');
 | 
						|
    if (what == item.get())
 | 
						|
    {
 | 
						|
      rt = item.get();
 | 
						|
      break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return (const char*) rt;
 | 
						|
}
 | 
						|
 | 
						|
void TDocumentoEsteso::set_condv(TCliFor* cli)
 | 
						|
{
 | 
						|
  if (_condv != NULL)
 | 
						|
   delete _condv;
 | 
						|
  if (cli != NULL)
 | 
						|
    _condv = new TCond_vendita(*cli);
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, TCliFor *cli)
 | 
						|
 : TDocumento(rec), _condv(NULL), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1)
 | 
						|
{
 | 
						|
  _iva = new TTable("%IVA");
 | 
						|
  if (cli != NULL) _condv = new TCond_vendita(*cli);
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, dec_parm & parm, TCliFor *cli)
 | 
						|
 : TDocumento(rec), _condv(NULL), _sum_filter(-1), _sum_selected(FALSE),  _scadenze_current(-1)
 | 
						|
{ 
 | 
						|
  _parm = parm;
 | 
						|
  _iva = new TTable("%IVA");
 | 
						|
  if (cli != NULL) _condv = new TCond_vendita(*cli);
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::~TDocumentoEsteso()
 | 
						|
{
 | 
						|
  if (_iva != NULL) delete _iva;
 | 
						|
  if (_condv != NULL) delete _condv;
 | 
						|
}
 | 
						|
 | 
						|
 |