265 lines
		
	
	
		
			8.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			265 lines
		
	
	
		
			8.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "velib.h"
 | 
						|
 | 
						|
#ifndef __TABUTIL_H
 | 
						|
#include <tabutil.h>
 | 
						|
#endif
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
// TCodice_numerazione
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
TCodice_numerazione::TCodice_numerazione(const char* codnum)
 | 
						|
               : TRectype(LF_TABCOM), _status(NOERR)
 | 
						|
{
 | 
						|
  settab("NUM");
 | 
						|
  if (codnum && *codnum)
 | 
						|
    _status = read(codnum);
 | 
						|
}
 | 
						|
 | 
						|
TCodice_numerazione::TCodice_numerazione(const TRectype& rec)
 | 
						|
               : TRectype(rec), _status(NOERR)
 | 
						|
{ }
 | 
						|
 | 
						|
TCodice_numerazione::~TCodice_numerazione()
 | 
						|
{                    
 | 
						|
}
 | 
						|
 | 
						|
const char * TCodice_numerazione::complete_num(long num)
 | 
						|
{
 | 
						|
  static TString codnum;
 | 
						|
  codnum = prefisso();
 | 
						|
  codnum << num;
 | 
						|
  codnum << postfisso();
 | 
						|
  return codnum;
 | 
						|
}
 | 
						|
 | 
						|
int TCodice_numerazione::read(const char* codnum)
 | 
						|
{                                   
 | 
						|
  TTable t("%NUM");
 | 
						|
  put("CODTAB", codnum);
 | 
						|
  int err = TRectype::read(t);
 | 
						|
  if (err != NOERR)
 | 
						|
    yesnofatal_box("Codice numerazione errato: %s", codnum);
 | 
						|
  return err;  
 | 
						|
}
 | 
						|
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
//TDocumentoEsteso
 | 
						|
/////////////////////////////////////////////////////////////
 | 
						|
void TDocumentoEsteso::compile_summary()
 | 
						|
{
 | 
						|
  _sum_filter = 0;
 | 
						|
  _summary_array.destroy();
 | 
						|
  const int ndec = in_valuta() ? 3 : 0;     
 | 
						|
  _summary_table = tabella_iva();
 | 
						|
  _summary_table.restart();
 | 
						|
  for (TRiepilogo_iva * ri = (TRiepilogo_iva *) _summary_table.get(); ri != NULL;
 | 
						|
       ri = (TRiepilogo_iva *) _summary_table.get())
 | 
						|
  {             
 | 
						|
    real imponibile(ri->imponibile());
 | 
						|
    real imposta(ri->imposta());
 | 
						|
    imponibile.round(ndec);
 | 
						|
    if (imposta < ZERO)
 | 
						|
      imposta.floor(ndec);
 | 
						|
    else
 | 
						|
      imposta.ceil(ndec);
 | 
						|
    ri->imp() = imponibile;
 | 
						|
    ri->imp_spese() = ZERO;
 | 
						|
    ri->iva() = imposta;
 | 
						|
    ri->iva_spese() = ZERO;
 | 
						|
  }
 | 
						|
  // Inizializza l'array di ordine
 | 
						|
  for (int 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 TRiepilogo_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 soddisfano 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 con i codici IVA
 | 
						|
    const int items = summary_items();
 | 
						|
    TRiepilogo_iva* curr = (TRiepilogo_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_iva().codice());
 | 
						|
      curr = (TRiepilogo_iva*) _summary_table.succ_item();
 | 
						|
    }
 | 
						|
    codici.restart();
 | 
						|
    summary_set_next(); // setta l'elemento corrente
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TDocumentoEsteso::summary_reset(bool force)
 | 
						|
{
 | 
						|
  const int items = _order_array.items();
 | 
						|
  if (force) _sum_filter = -1;
 | 
						|
  for (int i = 0; i<items; i++)
 | 
						|
  {
 | 
						|
    TToken_string& codici = _order_array.row(i);
 | 
						|
    codici = "";
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
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.
 | 
						|
    TRiepilogo_iva& riep= (TRiepilogo_iva&) _summary_table[codiva];
 | 
						|
    _sum_current = riep;
 | 
						|
  }
 | 
						|
  else            
 | 
						|
  { 
 | 
						|
   TRiepilogo_iva i;
 | 
						|
   _sum_current = i; // se non esiste il codice  azzera l'elemento corrente (non stampera' nulla)
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
const char *  TDocumentoEsteso::summary_get(const TString& w)
 | 
						|
{
 | 
						|
  if (w == "COD")
 | 
						|
    return _sum_current.cod_iva().codice();          // Ritorna il codice IVA
 | 
						|
  else
 | 
						|
    if (w == "IMP")
 | 
						|
      return _sum_current.imp().string(); // Ritorna l'imponibile
 | 
						|
    else
 | 
						|
      if (w == "IVA") 
 | 
						|
        return _sum_current.iva().string(); // Ritorna l'imposta
 | 
						|
      else
 | 
						|
      if (w == "ALI")
 | 
						|
        return _sum_current.cod_iva().aliquota().string(); // Ritorna l'aliquota %
 | 
						|
      else
 | 
						|
        if (w == "DES")
 | 
						|
          return _sum_current.cod_iva().descrizione();          // Ritorna la descrizione ( se il codice e' regime normale la descr. e' vuota)
 | 
						|
  return "";
 | 
						|
}
 | 
						|
 | 
						|
void  TDocumentoEsteso::scadenze_recalc()
 | 
						|
{
 | 
						|
  _scadenze_array.destroy();
 | 
						|
  _scadenze_current = -1;
 | 
						|
  TString16 codpag(head().get("CODPAG"));
 | 
						|
  TString16 data(head().get("DATAINSC"));
 | 
						|
  if (data.empty()) data = head().get("DATADOC");
 | 
						|
  TPagamento pag( codpag, data);
 | 
						|
  real totspese = spese();//tot_spese();
 | 
						|
  real totimposte = imposta();//tot_imposte();
 | 
						|
  real totimponibili = totale_doc() - totimposte - totspese;//tot_documento() - totimposte - totspese;
 | 
						|
  const bool valuta = in_valuta();
 | 
						|
  if (valuta)
 | 
						|
  {
 | 
						|
    const 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++;
 | 
						|
}
 | 
						|
 | 
						|
void TDocumentoEsteso::scadenze_reset()
 | 
						|
{  
 | 
						|
  if (_scadenze_current > 0)
 | 
						|
    _scadenze_current = 0;
 | 
						|
}
 | 
						|
 
 | 
						|
real TDocumentoEsteso::tot_imponibili(byte selector)
 | 
						|
{
 | 
						|
  if (!summary_compiled()) compile_summary();
 | 
						|
  
 | 
						|
  real number = 0.0;
 | 
						|
  const int items = summary_items();
 | 
						|
  TRiepilogo_iva* curr = (TRiepilogo_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 = (TRiepilogo_iva *) _summary_table.succ_item();
 | 
						|
  }
 | 
						|
  return number;
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, TCond_vendita * condv)
 | 
						|
 : TDocumento(rec, condv), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1)
 | 
						|
{
 | 
						|
  _iva = new TTable("%IVA");
 | 
						|
  // Inizializza i parametri di default
 | 
						|
  _parm.pri_lit = 0; _parm.pri_val = 3;
 | 
						|
  _parm.qta_lit = 3; _parm.qta_val = 3;
 | 
						|
  _parm.imp_lit = 0; _parm.imp_val = 3;
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, dec_parm & parm, TCond_vendita * condv)
 | 
						|
 : TDocumento(rec, condv), _sum_filter(-1), _sum_selected(FALSE),  _scadenze_current(-1)
 | 
						|
{ 
 | 
						|
  _parm = parm;
 | 
						|
  _iva = new TTable("%IVA");
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::TDocumentoEsteso()
 | 
						|
 : TDocumento(), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1)
 | 
						|
{
 | 
						|
  _iva = new TTable("%IVA");
 | 
						|
}
 | 
						|
 | 
						|
TDocumentoEsteso::~TDocumentoEsteso()
 | 
						|
{
 | 
						|
  if (_iva != NULL) delete _iva;
 | 
						|
}
 | 
						|
 | 
						|
 |