Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 848 (ve mancano i file con nomi doficati git-svn-id: svn://10.65.10.50/trunk@15004 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			265 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			265 lines
		
	
	
		
			7.8 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "velib05.h"
 | |
| 
 | |
| /////////////////////////////////////////////////////////////
 | |
| //TDocumentoEsteso
 | |
| /////////////////////////////////////////////////////////////
 | |
| void TDocumentoEsteso::compile_summary()
 | |
| {     
 | |
|   const int ndec = decimals();
 | |
|   
 | |
|   _sum_filter = 0;
 | |
|   _summary_array.destroy();
 | |
|   
 | |
|   _summary_table = tabella_iva();
 | |
|   _summary_table.restart();
 | |
|   for (TRiepilogo_iva * ri = (TRiepilogo_iva *) _summary_table.get(); ri != NULL;
 | |
|        ri = (TRiepilogo_iva *) _summary_table.get())
 | |
|   {             
 | |
|     const real imponibile = ri->imponibile();
 | |
|     real imposta = ri->imposta();
 | |
|     if (ndec == 0)
 | |
|     {
 | |
|       if (imposta < ZERO)
 | |
|         imposta.floor();
 | |
|       else              
 | |
|         imposta.ceil();
 | |
|     }  
 | |
|     else
 | |
|       imposta.round(ndec);
 | |
|     
 | |
|     ri->imp() = imponibile;
 | |
|     ri->imp_spese() = ZERO;
 | |
|     ri->iva() = imposta;
 | |
|     ri->iva_spese() = ZERO;
 | |
|   }              
 | |
|    
 | |
|   // Inizializza l'array di ordine
 | |
|   if (_order_array.items() == 0)
 | |
|   {
 | |
|     TToken_string s;
 | |
|     for (int i = 0; i < 32; i++) // ??
 | |
|       _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;             
 | |
|   CHECKD(_sum_filter > 0 && _sum_filter <= 32, "Bad selector ", _sum_filter);
 | |
|   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)
 | |
| {
 | |
|   if (force) 
 | |
|   {
 | |
|     _sum_filter = -1;
 | |
|     _sum_selected = false;
 | |
|   }
 | |
|   FOR_EACH_ARRAY_ROW(_order_array, i, row)
 | |
|     row->cut(0);
 | |
| }
 | |
| 
 | |
| void TDocumentoEsteso::summary_set_next()
 | |
| {
 | |
|   _sum_selected = FALSE;
 | |
|   TToken_string& codici = _order_array.row(_sum_filter-1);
 | |
|   
 | |
|   const TString4 codiva(codici.get()); // Reperisce il prossimo codice nella lista. (son gia' ordinati per codice)
 | |
|   if (codiva.full() && _summary_table.is_key(codiva))
 | |
|   {
 | |
|     // Estrae da _summary_table i dati relativio al codice corrispondente.
 | |
|     const TRiepilogo_iva& riep= (const TRiepilogo_iva&) _summary_table[codiva];
 | |
|     _sum_current = riep;
 | |
|   }
 | |
|   else            
 | |
|   { 
 | |
|     const 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") // Ritorna il codice IVA
 | |
|     return _sum_current.cod_iva().codice(); else 
 | |
|   if (w == "IMP") // Ritorna l'imponibile
 | |
|     return _sum_current.imp().string(); else
 | |
|   if (w == "IVA") // Ritorna l'imposta
 | |
|     return _sum_current.iva().string(); else
 | |
|   if (w == "ALI") // Ritorna l'aliquota % 
 | |
|     return _sum_current.cod_iva().percentuale().string(); else
 | |
|   if (w == "DES") // Ritorna la descrizione ( se il codice e' regime normale la descr. e' vuota)
 | |
|   {
 | |
|     if (_sum_current.cod_iva().tipo().not_empty())
 | |
|       return _sum_current.cod_iva().descrizione();  
 | |
|   }
 | |
|   return "";
 | |
| }
 | |
| 
 | |
| void  TDocumentoEsteso::scadenze_recalc()
 | |
| {
 | |
|   _scadenze_array.destroy();
 | |
|   _scadenze_current = -1;
 | |
|   TRectype& hh = head();
 | |
|   TPagamento& pag = pagamento();
 | |
|   real totspese = spese();
 | |
|   real totimposte = imposta(TRUE);
 | |
|   real pagato = hh.get_real(DOC_IMPPAGATO);
 | |
|   const bool saldo = hh.get_bool(DOC_ACCSALDO);
 | |
|   real totimponibili = totale_doc() - ritenute() - totimposte - totspese;//tot_documento() - totimposte - totspese;
 | |
|   const bool is_in_valuta = in_valuta();
 | |
|   
 | |
|   if (saldo || pagato > totale_doc())
 | |
|   {
 | |
|     totimponibili = ZERO;
 | |
|     totimposte = ZERO;
 | |
|     totspese = ZERO;
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     TGeneric_distrib d(pagato, decimals());
 | |
|   
 | |
|     d.add(totimponibili);
 | |
|     d.add(totimposte);
 | |
|     d.add(totspese);
 | |
|           
 | |
|     totimponibili -= d.get();
 | |
|     totimposte    -= d.get();
 | |
|     totspese      -= d.get();
 | |
|   }
 | |
|   
 | |
|   if (is_in_valuta)
 | |
|   {
 | |
|     const real change(cambio());
 | |
|     TCurrency_documento val1(totimponibili, *this); val1.change_to_firm_val();
 | |
|     TCurrency_documento val2(totimposte, *this); val2.change_to_firm_val();
 | |
|     TCurrency_documento val3(totspese, *this); val3.change_to_firm_val();
 | |
|     TString16 codval = valuta();
 | |
|     pag.set_total_valuta(totimponibili, totimposte, totspese, change, val1.get_num(), val2.get_num() ,val3.get_num(), codval);
 | |
|   }
 | |
|   else
 | |
|     pag.set_total(totimponibili, totimposte, totspese);
 | |
|   pag.set_rate_auto();
 | |
|   const int numrate = pag.n_rate( );
 | |
|   real rata;
 | |
|   for (int i = 0; i< numrate; i++)
 | |
|   {
 | |
|     rata = pag.importo_rata(i, is_in_valuta);
 | |
|     TToken_string t;
 | |
|     t.add(pag.data_rata(i));
 | |
|     t.add(rata.string());
 | |
|     _scadenze_array.add(t);
 | |
|   }
 | |
|   if (_scadenze_array.items() > 0) 
 | |
|     _scadenze_current++;
 | |
| }
 | |
| 
 | |
| const char*  TDocumentoEsteso::scadenze_get(const TString& w)
 | |
| {
 | |
|   // TString ret;        // Pena di morte
 | |
|   const char* 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 ret;
 | |
| }
 | |
| 
 | |
| void TDocumentoEsteso::scadenze_set_next()
 | |
| {
 | |
|   if (_scadenze_current >= 0 &&
 | |
|       _scadenze_current < _scadenze_array.items() )
 | |
|     _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;
 | |
| }
 | |
| 
 | |
| int TDocumentoEsteso::readat(TBaseisamfile& file, TRecnotype nrec, word lockop)
 | |
| {
 | |
|   int err = TDocumento::readat(file, nrec, lockop);
 | |
|   dirty_tabella_iva();
 | |
|   summary_reset(true);
 | |
|   scadenze_reset();
 | |
|   return err;
 | |
| }
 | |
| 
 | |
| TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec)
 | |
|  : TDocumento(rec), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1)
 | |
| {
 | |
|   // Inizializza i parametri di default
 | |
|   _parm.qta_lit = 3; _parm.qta_val = 3;
 | |
| }
 | |
| 
 | |
| TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, dec_parm & parm)
 | |
|  : TDocumento(rec), _sum_filter(-1), _sum_selected(FALSE),  _scadenze_current(-1)
 | |
| { 
 | |
|   _parm = parm;
 | |
| }
 | |
| 
 | |
| TDocumentoEsteso::TDocumentoEsteso()
 | |
|  : TDocumento(), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1)
 | |
| { }
 | |
| 
 | |
| TDocumentoEsteso::~TDocumentoEsteso()
 | |
| { }
 | |
| 
 | |
| 
 |