88e6243dc4
git-svn-id: svn://10.65.10.50/trunk@4208 c028cbd2-c16b-5b4b-a496-9718f37d4682
345 lines
11 KiB
C++
Executable File
345 lines
11 KiB
C++
Executable File
#include "velib02.h"
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
// 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)
|
|
{
|
|
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;
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
// TRiepilogo IVA
|
|
/////////////////////////////////////////////////////////////
|
|
TRiepilogo_Iva& TRiepilogo_Iva::operator=(TRiepilogo_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();
|
|
_summary_array.destroy();
|
|
_imposte = 0.0;
|
|
_importi_netti = 0.0;
|
|
const bool val = in_valuta();
|
|
// Scorre tutte le righe e compila la tabellina _summary_table, per codice iva,
|
|
// nonche' il galactic_array _summary_array dove le informazioni sono registrate per singola riga
|
|
// cio' ad usi generici: porco diavolo!
|
|
for (int i = 1; i <= items; i++)
|
|
{
|
|
TRiga_documento& 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");
|
|
price = prezzo_scontato(price, sconto);
|
|
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 = r.iva(val ? _parm.imp_val : _parm.imp_lit);
|
|
//iva = (imponibile * aliquota) / 100.0;
|
|
//iva.ceil(val ? _parm.imp_val : _parm.imp_lit); // imposta calcolata
|
|
|
|
// Aggiorna o aggiunge l'elemento se non esiste
|
|
TRiepilogo_Iva riepilogo_tmp,row_riep;
|
|
const bool exists = _summary_table.is_key(codiva);
|
|
TRiepilogo_Iva& riepilogo = (exists ? (TRiepilogo_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;
|
|
row_riep.imp() = imponibile; row_riep.iva() = iva;
|
|
riepilogo.ali() = aliquota; riepilogo.cod() = codiva;
|
|
row_riep.ali() = aliquota; row_riep.cod() = codiva;
|
|
TString16 tipo(_iva->get("S1"));
|
|
int tipo_i = 1;// Regime IVA normale
|
|
if (tipo == "VE") tipo = 2;
|
|
else if (tipo == "ES") tipo = 4;
|
|
else if (tipo == "NI") tipo = 8;
|
|
else if (tipo == "NS") tipo= 16;
|
|
riepilogo.tipo() = tipo_i;
|
|
row_riep.tipo() = tipo_i;
|
|
if (riepilogo.tipo() != 1) // Se non e' regime normale salva anche la descrizione
|
|
{
|
|
TString s(_iva->get("S0"));
|
|
riepilogo.des() = s;
|
|
row_riep.des() = s;
|
|
}
|
|
_summary_table.add(codiva,riepilogo,exists);
|
|
_summary_array.add(row_riep,nriga);
|
|
}
|
|
// 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 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_table.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());
|
|
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
|
|
_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"));
|
|
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_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();
|
|
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;
|
|
}
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, TCliFor *cli)
|
|
: TDocumento(rec), _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, TCliFor *cli)
|
|
: TDocumento(rec), _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;
|
|
}
|
|
|
|
|