Corretto caricamento campi di default
Corretto calcolo tabella IVA (1a fase le stampa non vanno) git-svn-id: svn://10.65.10.50/trunk@5091 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
0a3e2c483d
commit
ccc3eeabd5
88
ve/velib.h
88
ve/velib.h
@ -410,6 +410,35 @@ public:
|
||||
|
||||
enum TTipo_importo { _lordo, _netto, _imposta };
|
||||
|
||||
class TRiepilogo_iva : public TObject
|
||||
{
|
||||
TIVA _codiva;
|
||||
real _imp;
|
||||
real _imp_spese;
|
||||
real _iva;
|
||||
real _iva_spese;
|
||||
byte _tipo;
|
||||
|
||||
protected:
|
||||
virtual TObject* dup() const { return new TRiepilogo_iva(*this); }
|
||||
virtual TRiepilogo_iva & copy(const TRiepilogo_iva & a);
|
||||
|
||||
public:
|
||||
real imponibile(bool spese = TRUE) const { return _imp + (spese ? _imp_spese : ZERO);} // Imponibile
|
||||
real imposta(bool spese = TRUE) const { return _iva + (spese ? _iva_spese : ZERO);} // Iva
|
||||
real & imp() { return _imp;};
|
||||
real & imp_spese() { return _imp_spese;};
|
||||
real & iva() { return _iva;};
|
||||
real & iva_spese() { return _iva_spese;};
|
||||
const TIVA & cod_iva() const { return _codiva;}
|
||||
byte tipo(){ return _tipo;}// Tipo (Vedi opzioni per la selzione di filtro nella validate())
|
||||
TRiepilogo_iva& operator = (const TRiepilogo_iva & a) {return copy(a);}
|
||||
TRiepilogo_iva(const TIVA & codiva);
|
||||
TRiepilogo_iva(const TRiepilogo_iva & a) {copy(a);}
|
||||
TRiepilogo_iva() : _tipo(0) {}
|
||||
~TRiepilogo_iva() {};
|
||||
};
|
||||
|
||||
class TDocumento : public TMultiple_rectype // velib03
|
||||
{
|
||||
TRecfield *_tipocf;
|
||||
@ -417,6 +446,9 @@ class TDocumento : public TMultiple_rectype // velib03
|
||||
TRecfield *_cod_occas;
|
||||
static TAssoc_array _tipi;
|
||||
static TAssoc_array _numerazioni;
|
||||
static long _firm;
|
||||
static TString16 _codiva_spese;
|
||||
static TString16 _codiva_bolli;
|
||||
|
||||
int _liv_len[4];
|
||||
|
||||
@ -429,6 +461,7 @@ class TDocumento : public TMultiple_rectype // velib03
|
||||
TPagamento _pag;
|
||||
TRiga_documento * _sconto; // Riga per lo sconto di testata
|
||||
TRiga_documento * _esenzione; // Riga per l' esenzione iva
|
||||
TAssoc_array _tabella_iva; // tabella di imponibili ed imposte
|
||||
|
||||
protected:
|
||||
virtual TRectype * new_body_record(int logicnum = 0) { return new TRiga_documento(this); }
|
||||
@ -444,12 +477,16 @@ protected:
|
||||
int write_rewrite(TBaseisamfile & f, bool re) const;
|
||||
virtual TDocumento & copy(const TDocumento & d);
|
||||
TObject* dup() const { return new TDocumento(*this); }
|
||||
void update_tabella_iva();
|
||||
void dirty_tabella_iva() { _tabella_iva.destroy();}
|
||||
static void test_firm();
|
||||
const TString16 & codiva_spese() const { ((TDocumento *)this)->test_firm(); return _codiva_spese;}
|
||||
const TString16 & codiva_bolli() const { ((TDocumento *)this)->test_firm(); return _codiva_bolli;}
|
||||
|
||||
public:
|
||||
void dirty_fields();
|
||||
// const TAuto_variable_rectype& head() const { return *this; } // Ritorna la testata del documento
|
||||
// TAuto_variable_rectype& head() { return *this; } // Ritorna la testata del documento
|
||||
|
||||
TAssoc_array & tabella_iva() { update_tabella_iva(); return _tabella_iva; }
|
||||
TCond_vendita & condv() const {CHECK(_condv, "Condizioni di vendita nulle"); return *_condv;}
|
||||
TCli_for & clifor() const;
|
||||
TOccasionale & occas() const;
|
||||
@ -952,31 +989,6 @@ struct dec_parm {
|
||||
// classe TDocumentoEsteso: oggetto che ha come finalita' il calcolo dei riepiloghi IVA
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TRiepilogo_Iva : public TObject
|
||||
{
|
||||
real _imp;
|
||||
real _iva;
|
||||
real _ali;
|
||||
byte _tipo;
|
||||
TString16 _cod;
|
||||
TString _des;
|
||||
|
||||
protected:
|
||||
|
||||
public:
|
||||
real& imp() { return _imp;} // Imponibile
|
||||
real& iva() { return _iva;} // Iva
|
||||
real& ali() { return _ali;} // Aliquota
|
||||
TString& cod() { return _cod;} // Descrizione
|
||||
TString& des() { return _des;} // Descrizione
|
||||
byte& tipo(){ return _tipo;}// Tipo (Vedi opzioni per la selzione di filtro nella validate())
|
||||
void zero(){ _imp = 0.0; _iva = 0.0; _ali = 0.0; _tipo = 0; _cod = ""; _des = ""; }
|
||||
virtual TObject* dup() const { return new TRiepilogo_Iva(*this); }
|
||||
TRiepilogo_Iva& operator = (TRiepilogo_Iva& a);
|
||||
TRiepilogo_Iva() {_imp = 0.0; _iva = 0.0; _ali = 0.0; _tipo = 0;}
|
||||
~TRiepilogo_Iva() {};
|
||||
};
|
||||
|
||||
class TDocumentoEsteso : public TDocumento
|
||||
{
|
||||
// Parametri del documento
|
||||
@ -984,15 +996,15 @@ class TDocumentoEsteso : public TDocumento
|
||||
TTable * _iva; // Tabella codici IVA
|
||||
|
||||
// Totali del documento ricalcolati non appena la tabellina di riepilogo IVA e' completa
|
||||
real _importi_netti, _imposte;
|
||||
// real _importi_netti, _imposte;
|
||||
|
||||
// membri per il calcolo del riepilogo IVA
|
||||
bool _sum_selected; // TRUE se ha selezionato una riga del riepilogo, funge da semaforo per leggere la prossima
|
||||
int _sum_filter; // Filtro corrente della riga TRiepilogo_Iva in corso di stampa (-1 se non ha ancora calcolato la tabella)
|
||||
int _sum_filter; // Filtro corrente della riga TRiepilogo_iva in corso di stampa (-1 se non ha ancora calcolato la tabella)
|
||||
TString_array _order_array; // Array di TToken_string contenenti i codici IVA soddisfacenti ad ogni tipo di filtro
|
||||
TAssoc_array _summary_table; // Array dove vengono memorizzate le imposte per aliquota
|
||||
TAssoc_array _summary_table; // Array associativo contenete imonibili ed imposte pronte per la stampa;
|
||||
TArray _summary_array; // Array dove vengono memorizzate le imposte/imponibili per riga
|
||||
TRiepilogo_Iva _sum_current; // Riga corrente del riepilogo
|
||||
TRiepilogo_iva _sum_current; // Riga corrente del riepilogo
|
||||
|
||||
// membri per il calcolo del riepilogo scadenze
|
||||
TString_array _scadenze_array;// Array che contiene le scadenze ("<data>|<importo>")
|
||||
@ -1007,9 +1019,9 @@ public:
|
||||
void summary_filter(byte selector); // filtra la tabellina secondo il filtro corrente se non e' gia' stato fatto
|
||||
void summary_reset(bool force=FALSE); // riposiziona l'array dei codici IVA (_order_array). Se il parametro e' TRUE forza il ricalcolo della tabella
|
||||
void summary_set_next(); // seleziona il prossimo elemento del filtro
|
||||
const TRiepilogo_Iva& sum_current() { return _sum_current; } // ritorna la riga corrente del filtro corrente
|
||||
const TRiepilogo_iva& sum_current() { return _sum_current; } // ritorna la riga corrente del filtro corrente
|
||||
const char * summary_get(const TString& w); // ritorna l'informazione richiesta estratta dall'elemento corrente
|
||||
int summary_items() { return _summary_table.items();} // ritorna il numero di righe in totale della tabellina
|
||||
int summary_items() { return tabella_iva().items();} // ritorna il numero di righe in totale della tabellina
|
||||
const TAssoc_array& summary() { return _summary_table; }
|
||||
const TArray& summary_array() { return _summary_array;}
|
||||
|
||||
@ -1023,10 +1035,10 @@ public:
|
||||
TString_array& scadenze() { return _scadenze_array; }
|
||||
|
||||
// Funzioni di totalizzazione
|
||||
real& tot_importi_netti();
|
||||
real& tot_imposte();
|
||||
real tot_spese();
|
||||
real tot_documento();
|
||||
// real& tot_importi_netti();
|
||||
// real& tot_imposte();
|
||||
// real tot_spese();
|
||||
// real tot_documento();
|
||||
// restituisce tot_imponibili, tot_esenti, tot_nonsoggetti a seconda del selettore:
|
||||
// 1 = regime normale
|
||||
// 2 = da ventilare (non usato)
|
||||
@ -1038,7 +1050,7 @@ public:
|
||||
real tot_imponibili(byte selector);
|
||||
|
||||
// Reperisce l'informazione <what> dal campo G1 della testata
|
||||
const char* get_head_info(const TString& what);
|
||||
/* const char* get_head_info(const TString& what); */
|
||||
|
||||
// Funzioni per settare i parametri
|
||||
void set_decimals(dec_parm & parm) { _parm = parm ; }
|
||||
|
@ -680,9 +680,12 @@ int TExpr_documento::parse_user_func(const char * name, int nparms) const
|
||||
else
|
||||
if (strcmp(name, "SCONTO") == 0)
|
||||
return nparms < 2 ? _sconto : -1;
|
||||
else
|
||||
if (strcmp(name, "IMPONIBILE") == 0)
|
||||
return nparms == 0 ? _imponibile : -1;
|
||||
else
|
||||
if (strcmp(name, "IVA") == 0)
|
||||
return nparms < 2 ? _iva : -1;
|
||||
return nparms == 0 ? _iva : -1;
|
||||
else
|
||||
if (strcmp(name, "PROVV") == 0)
|
||||
return nparms < 2 ? _provv : -1;
|
||||
@ -706,20 +709,22 @@ void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & st
|
||||
case _somma:
|
||||
{
|
||||
const TString cond(nparms == 2 ? stack.pop_string() : "STR(1)");
|
||||
const TString & fieldname = stack.pop_string();
|
||||
const TString & field = stack.pop_string();
|
||||
real somma;
|
||||
|
||||
if (_doc != NULL)
|
||||
{
|
||||
TExpr_documento cond_expr(cond, _strexpr, _doc);
|
||||
const int cond_nvars = cond_expr.numvar();
|
||||
TExpr_documento expr(field, _numexpr, _doc);
|
||||
const int nvars = expr.numvar();
|
||||
const int nrows = _doc->rows();
|
||||
const int nvars = cond_expr.numvar();
|
||||
|
||||
for (int i = nrows; i > 0 ; i--)
|
||||
{
|
||||
TRiga_documento & riga = (TRiga_documento &) (*_doc)[i];
|
||||
|
||||
for (int j = nvars - 1; j >= 0; j--)
|
||||
for (int j = cond_nvars - 1; j >= 0; j--)
|
||||
{
|
||||
const char* s = cond_expr.varname(j);
|
||||
TFieldref f(s,0);
|
||||
@ -727,7 +732,16 @@ void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & st
|
||||
}
|
||||
cond_expr.set_row(&riga);
|
||||
if ((bool)cond_expr)
|
||||
somma += riga.get_real(fieldname);
|
||||
{
|
||||
for (j = nvars - 1; j >= 0; j--)
|
||||
{
|
||||
const char* s = expr.varname(j);
|
||||
TFieldref f(s,0);
|
||||
expr.setvar(j, f.read(riga));
|
||||
}
|
||||
expr.set_row(&riga);
|
||||
somma += (real)expr;
|
||||
}
|
||||
}
|
||||
}
|
||||
stack.push(somma);
|
||||
@ -836,6 +850,15 @@ void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & st
|
||||
val = ZERO;
|
||||
}
|
||||
break;
|
||||
case _imponibile:
|
||||
{
|
||||
real r;
|
||||
|
||||
if (_row)
|
||||
r = _row->imponibile();
|
||||
stack.push(r);
|
||||
}
|
||||
break;
|
||||
case _sconto:
|
||||
{
|
||||
int ndec = _doc && _doc->in_valuta() ? 3 : 0;
|
||||
@ -859,19 +882,11 @@ void TExpr_documento::evaluate_user_func(int index, int nparms, TEval_stack & st
|
||||
break;
|
||||
case _iva:
|
||||
{
|
||||
int ndec = _doc && _doc->in_valuta() ? 3 : 0;
|
||||
|
||||
if (nparms > 0)
|
||||
ndec = (int) stack.peek_real().integer();
|
||||
else
|
||||
stack.push(ZERO);
|
||||
|
||||
real & val = stack.peek_real();
|
||||
real r;
|
||||
|
||||
if (_row)
|
||||
val = _row->imposta();
|
||||
else
|
||||
val = ZERO;
|
||||
r = _row->imposta();
|
||||
stack.push(r);
|
||||
}
|
||||
break;
|
||||
case _provv:
|
||||
|
@ -71,16 +71,15 @@ void TTipo_riga_documento::read_formule()
|
||||
_formule.add(profile.get("CALCOLI", "MAIN"));
|
||||
_imponibile = profile.get("IMPONIBILE", "MAIN");
|
||||
if (_imponibile.empty())
|
||||
{
|
||||
_imponibile = "IMPONIBILE";
|
||||
if (_formule.find(_imponibile) < 0)
|
||||
_formule.add("IMPONIBILE=IMPORTO(1)");
|
||||
}
|
||||
if (_imponibile.not_empty() && _formule.find(_imponibile) < 0)
|
||||
TFormula_documento * o = (TFormula_documento*)_formule_riga.objptr(_imponibile);
|
||||
if (o == NULL)
|
||||
{
|
||||
error_box("Campo imponibile (%s) sconosciuto nel tipo riga %s", (const char *) _imponibile, (const char *) codice());
|
||||
_imponibile.cut(0);
|
||||
o = new TFormula_documento(_riga, _imponibile, "IMPORTO(1)");
|
||||
_formule_riga.add(_imponibile, o);
|
||||
}
|
||||
if (_formule.find(_imponibile) < 0)
|
||||
_formule.add(_imponibile);
|
||||
}
|
||||
|
||||
TFormula_documento * TTipo_riga_documento::succ_formula(bool restart)
|
||||
|
247
ve/velib03.cpp
247
ve/velib03.cpp
@ -6,6 +6,10 @@
|
||||
#include <applicat.h>
|
||||
#endif
|
||||
|
||||
#ifndef __PREFIX_H
|
||||
#include <prefix.h>
|
||||
#endif
|
||||
|
||||
#ifndef __VEUML_H
|
||||
#include "veuml.h"
|
||||
#endif
|
||||
@ -115,42 +119,41 @@ void TTipo_documento::read_formule()
|
||||
_formule.add(profile.get("CALCOLI", "MAIN"));
|
||||
_totale = profile.get("TOTALE", "MAIN");
|
||||
if (_totale.empty())
|
||||
{
|
||||
_totale = "TOTDOC";
|
||||
if (_formule.find(_totale) < 0)
|
||||
_formule.add("TOTDOC=IMPONIBILI()+IMPOSTE()");
|
||||
TFormula_documento * o = (TFormula_documento*)_formule_documento.objptr(_totale);
|
||||
if (o == NULL)
|
||||
{
|
||||
o = new TFormula_documento(_documento, _totale, "IMPONIBILI()+IMPOSTE()");
|
||||
_formule_documento.add(_totale, o);
|
||||
}
|
||||
if (_formule.find(_totale) < 0)
|
||||
_formule.add(_totale);
|
||||
_totale_netto = "_";
|
||||
_totale_netto << _totale;
|
||||
if (_totale.not_empty() && _formule.find(_totale) < 0)
|
||||
{
|
||||
error_box("Campo totale documento (%s) sconosciuto nel tipo documento %s", (const char *) _totale, (const char *) codice());
|
||||
_totale.cut(0);
|
||||
}
|
||||
|
||||
_basesconto = profile.get("BASESCONTO", "MAIN");
|
||||
if (_basesconto.empty())
|
||||
{
|
||||
_basesconto = "BASESCONTO";
|
||||
if (_formule.find(_basesconto) < 0)
|
||||
_formule.add("BASESCONTO=SOMMA(\"IMPONIBILE()\", \"(TIPO() != 'S') && (TIPO() != 'C')\")");
|
||||
}
|
||||
if (_basesconto.not_empty() && _formule.find(_basesconto) < 0)
|
||||
o = (TFormula_documento*)_formule_documento.objptr(_basesconto);
|
||||
if (o == NULL)
|
||||
{
|
||||
error_box("Campo sconto documento (%s) sconosciuto nel tipo documento %s", (const char *) _basesconto, (const char *) codice());
|
||||
_basesconto.cut(0);
|
||||
o = new TFormula_documento(_documento, _basesconto, "SOMMA(\"IMPONIBILE()\", \"(TIPO() != 'S') && (TIPO() != 'C')\")");
|
||||
_formule_documento.add(_basesconto, o);
|
||||
}
|
||||
if (_formule.find(_basesconto) < 0)
|
||||
_formule.add(_basesconto);
|
||||
|
||||
_spese = profile.get("SPESE", "MAIN");
|
||||
if (_spese.empty())
|
||||
{
|
||||
_spese = "SPESE";
|
||||
if (_formule.find(_spese) < 0)
|
||||
_formule.add("SPESE=SOMMA(\"IMPONIBILE()\", \"TIPO() != 'S'\")");
|
||||
}
|
||||
if (_spese.not_empty() && _formule.find(_spese) < 0)
|
||||
o = (TFormula_documento*)_formule_documento.objptr(_spese);
|
||||
if (o == NULL)
|
||||
{
|
||||
error_box("Campo spese (%s) sconosciuto nel tipo documento %s", (const char *) _spese, (const char *) codice());
|
||||
_spese.cut(0);
|
||||
o = new TFormula_documento(_documento, _spese, "SOMMA(\"IMPONIBILE()\", \"TIPO() != 'S'\")");
|
||||
_formule_documento.add(_spese, o);
|
||||
}
|
||||
if (_formule.find(_spese) < 0)
|
||||
_formule.add(_spese);
|
||||
}
|
||||
|
||||
bool TTipo_documento::stato_with_mov_mag(const char stato) const
|
||||
@ -190,12 +193,47 @@ TFormula_documento * TTipo_documento::succ_formula(bool restart)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////
|
||||
// TRiepilogo IVA
|
||||
/////////////////////////////////////////////////////////////
|
||||
TRiepilogo_iva& TRiepilogo_iva::copy(const TRiepilogo_iva& a)
|
||||
{
|
||||
_codiva = a._codiva;
|
||||
_imp = a._imp;
|
||||
_imp_spese = a._imp_spese;
|
||||
_iva = a._iva;
|
||||
_iva_spese = a._iva_spese;
|
||||
_tipo = a._tipo;
|
||||
return *this;
|
||||
}
|
||||
|
||||
TRiepilogo_iva::TRiepilogo_iva(const TIVA & codiva) : _codiva(codiva)
|
||||
{
|
||||
const TString & t =_codiva.tipo();
|
||||
if (t == "VE")
|
||||
_tipo = 2;
|
||||
else
|
||||
if (t == "ES")
|
||||
_tipo = 4;
|
||||
else
|
||||
if (t == "NI")
|
||||
_tipo = 8;
|
||||
else
|
||||
if (t == "NS")
|
||||
_tipo = 16;
|
||||
else
|
||||
_tipo = 1;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// Documento per vendite
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TAssoc_array TDocumento::_tipi;
|
||||
TAssoc_array TDocumento::_numerazioni;
|
||||
long TDocumento::_firm = -1;
|
||||
TString16 TDocumento::_codiva_spese;
|
||||
TString16 TDocumento::_codiva_bolli;
|
||||
|
||||
TDocumento::TDocumento()
|
||||
: TMultiple_rectype(LF_DOC), _condv(NULL),
|
||||
@ -263,6 +301,19 @@ TDocumento::~TDocumento()
|
||||
if (_esenzione != NULL) delete _esenzione;
|
||||
}
|
||||
|
||||
void TDocumento::test_firm()
|
||||
{
|
||||
const long new_firm = prefix().get_codditta();
|
||||
|
||||
if (_firm != new_firm)
|
||||
{
|
||||
TConfig conf(CONFIG_DITTA);
|
||||
|
||||
_codiva_spese = conf.get("SPINCODIVA", "ve");
|
||||
_codiva_bolli = conf.get("SPBOCODIVA", "ve");
|
||||
_firm = new_firm;
|
||||
}
|
||||
}
|
||||
real TDocumento::spese_incasso(real & imp, int ndec, TTipo_importo t) const
|
||||
{
|
||||
real imp_spese;
|
||||
@ -295,18 +346,8 @@ real TDocumento::spese_incasso(real & imp, int ndec, TTipo_importo t) const
|
||||
|
||||
if (cambio == ZERO)
|
||||
cambio = 1.0;
|
||||
static TString16 codiva;
|
||||
static long firm = -1;
|
||||
long new_firm = main_app().get_firm();
|
||||
|
||||
if (firm != new_firm)
|
||||
{
|
||||
TConfig conf(CONFIG_DITTA);
|
||||
|
||||
codiva = conf.get("SPINCODIVA", "ve");
|
||||
firm = new_firm;
|
||||
}
|
||||
real iva_spese(iva(imp_spese, TRiga_documento::iva(codiva), ndec));
|
||||
real iva_spese(iva(imp_spese, TRiga_documento::iva(codiva_spese()), ndec));
|
||||
if (t == _lordo)
|
||||
imp_spese += iva_spese;
|
||||
else
|
||||
@ -422,18 +463,7 @@ real TDocumento::bolli(real & imp, int ndec, TTipo_importo t) const
|
||||
break;
|
||||
}
|
||||
}
|
||||
static TString16 codiva;
|
||||
static long firm = -1;
|
||||
long new_firm = main_app().get_firm();
|
||||
|
||||
if (firm != new_firm)
|
||||
{
|
||||
TConfig conf(CONFIG_DITTA);
|
||||
|
||||
codiva = conf.get("SPBOCODIVA", "ve");
|
||||
firm = new_firm;
|
||||
}
|
||||
iva_bolli = iva(tot_bolli, TRiga_documento::iva(codiva), ndec);
|
||||
iva_bolli = iva(tot_bolli, TRiga_documento::iva(codiva_bolli()), ndec);
|
||||
importo += (tot_bolli + iva_bolli - old_bolli);
|
||||
}
|
||||
if (t == _lordo)
|
||||
@ -667,6 +697,7 @@ void TDocumento::dirty_fields()
|
||||
for (TDocumento_variable_field * f = (TDocumento_variable_field *) first_variable_field();
|
||||
f != NULL; f = (TDocumento_variable_field *) succ_variable_field())
|
||||
f->set_dirty();
|
||||
dirty_tabella_iva();
|
||||
for (int i = loaded_rows(); i > 0; i--)
|
||||
{
|
||||
TRiga_documento & r = (TRiga_documento &) row(i);
|
||||
@ -971,7 +1002,6 @@ const TCodice_numerazione& TDocumento::codice_numerazione() const
|
||||
return *o;
|
||||
}
|
||||
|
||||
|
||||
bool TDocumento::raggruppabile(const TDocumento& doc, TToken_string& campi) const
|
||||
{
|
||||
bool ok = raggruppabile() && doc.raggruppabile();
|
||||
@ -1055,44 +1085,111 @@ real TDocumento::imponibile(bool spese, int ndec) const
|
||||
return val;
|
||||
}
|
||||
|
||||
void TDocumento::update_tabella_iva()
|
||||
{
|
||||
const int items = rows();
|
||||
TAssoc_array & table = _tabella_iva;
|
||||
|
||||
if (table.items() > 0 || items == 0)
|
||||
{
|
||||
if (items == 0)
|
||||
table.destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
real tot_doc;
|
||||
real tot_sconti;
|
||||
|
||||
for (int i = items; i > 0; i--)
|
||||
{
|
||||
const TRiga_documento& r = row(i);
|
||||
const real imponibile = r.imponibile();
|
||||
|
||||
tot_doc += imponibile;
|
||||
if (r.is_sconto())
|
||||
tot_sconti += imponibile;
|
||||
else
|
||||
if (!r.is_descrizione())
|
||||
{
|
||||
const real imposta = r.imposta(FALSE);
|
||||
// Aggiorna o aggiunge l'elemento se non esiste
|
||||
const TIVA & iva = r.iva();
|
||||
const TString16 cod(iva.codice());
|
||||
TRiepilogo_iva * aliquota = (TRiepilogo_iva *) table.objptr(cod);
|
||||
|
||||
if (aliquota == NULL)
|
||||
{
|
||||
aliquota = new TRiepilogo_iva(iva);
|
||||
table.add(cod, aliquota);
|
||||
}
|
||||
aliquota->imp() += imponibile;
|
||||
aliquota->iva() += imposta;
|
||||
tot_doc += imposta;
|
||||
}
|
||||
}
|
||||
if (tot_sconti != ZERO)
|
||||
{
|
||||
TGeneric_distrib d(tot_sconti);
|
||||
|
||||
table.restart();
|
||||
for (TRiepilogo_iva * ri = (TRiepilogo_iva *) table.get(); ri != NULL;
|
||||
ri = (TRiepilogo_iva *) table.get())
|
||||
d.add(ri->imp());
|
||||
|
||||
table.restart();
|
||||
for (ri = (TRiepilogo_iva *) table.get(); ri != NULL;
|
||||
ri = (TRiepilogo_iva *) table.get())
|
||||
{
|
||||
const char * codiva = ri->cod_iva().codice();
|
||||
const real i(d.get());
|
||||
real & iva = ri->iva();
|
||||
const real imposta(::iva(i, TIVA(codiva), ALL_DECIMALS));
|
||||
|
||||
iva += imposta;
|
||||
tot_doc += imposta;
|
||||
}
|
||||
}
|
||||
|
||||
TRiepilogo_iva * ri = (TRiepilogo_iva *) table.objptr(codiva_spese());
|
||||
if (ri == NULL)
|
||||
ri = new TRiepilogo_iva(TIVA(codiva_spese()));
|
||||
|
||||
real val = spese_incasso(tot_doc, ALL_DECIMALS, _netto);
|
||||
ri->imp_spese() += val;
|
||||
tot_doc += val;
|
||||
val = spese_incasso(tot_doc, ALL_DECIMALS, _imposta);
|
||||
ri->iva_spese() += val;
|
||||
tot_doc += val;
|
||||
|
||||
ri = (TRiepilogo_iva *) table.objptr(codiva_bolli());
|
||||
if (ri == NULL)
|
||||
ri = new TRiepilogo_iva(TIVA(codiva_bolli()));
|
||||
val = bolli(tot_doc, ALL_DECIMALS, _netto);
|
||||
ri->imp_spese() += val;
|
||||
tot_doc += val;
|
||||
val = bolli(tot_doc, ALL_DECIMALS, _imposta);
|
||||
ri->iva_spese() += val;
|
||||
tot_doc += val;
|
||||
}
|
||||
|
||||
real TDocumento::imposta(bool spese, int ndec) const
|
||||
{
|
||||
TAssoc_array ive;
|
||||
TAssoc_array table = ((TDocumento *)this)->tabella_iva();
|
||||
real val;
|
||||
|
||||
if (ndec == AUTO_DECIMALS)
|
||||
ndec = in_valuta() ? 3 : 0;
|
||||
|
||||
for (int i = rows(); i > 0; i--)
|
||||
for (TRiepilogo_iva * ri = (TRiepilogo_iva *) table.get(); ri != NULL;
|
||||
ri = (TRiepilogo_iva *) table.get())
|
||||
{
|
||||
TRiga_documento & r = ((TRiga_documento &) ((TDocumento *)this)->row(i));
|
||||
real iva(r.imposta(FALSE));
|
||||
const TString & cod_iva = r.get("CODIVA");
|
||||
|
||||
real * tot = (real *) ive.objptr(cod_iva);
|
||||
if (tot == NULL)
|
||||
ive.add(cod_iva, iva);
|
||||
real iva = ri->imposta(spese);
|
||||
if (iva < ZERO)
|
||||
iva.floor(ndec);
|
||||
else
|
||||
*tot += iva;
|
||||
iva.ceil(ndec);
|
||||
val += iva;
|
||||
}
|
||||
real val;
|
||||
|
||||
ive.restart();
|
||||
for (real * iva = (real *) ive.get(); iva != NULL; iva = (real *) ive.get())
|
||||
{
|
||||
if (*iva < ZERO)
|
||||
iva->floor(ndec);
|
||||
else
|
||||
iva->ceil(ndec);
|
||||
val += *iva;
|
||||
}
|
||||
if (spese)
|
||||
{
|
||||
real tot_doc = val + imponibile(FALSE, ndec);
|
||||
val += spese_incasso(tot_doc, ndec, _imposta);
|
||||
tot_doc += spese_incasso(tot_doc, ndec);
|
||||
val += bolli(tot_doc, ndec, _imposta);
|
||||
}
|
||||
val.round(ndec);
|
||||
return val;
|
||||
}
|
||||
|
||||
|
144
ve/velib05.cpp
144
ve/velib05.cpp
@ -42,84 +42,35 @@ int TCodice_numerazione::read(const char* 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++)
|
||||
// _imposte = ZERO;
|
||||
// _importi_netti = ZERO;
|
||||
const int ndec = in_valuta() ? 3 : 0;
|
||||
update_tabella_iva();
|
||||
_summary_table = tabella_iva();
|
||||
for (TRiepilogo_iva * ri = (TRiepilogo_iva *) _summary_table.get(); ri != NULL;
|
||||
ri = (TRiepilogo_iva *) _summary_table.get());
|
||||
{
|
||||
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);
|
||||
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 (i = 0; i<32;i++)
|
||||
for (int i = 0; i<32;i++) // ??
|
||||
{
|
||||
TToken_string s;
|
||||
_order_array.add(s);
|
||||
@ -136,7 +87,7 @@ void TDocumentoEsteso::summary_filter(byte selector)
|
||||
// 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
|
||||
// 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);
|
||||
@ -145,13 +96,13 @@ void TDocumentoEsteso::summary_filter(byte selector)
|
||||
// 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();
|
||||
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());
|
||||
curr = (TRiepilogo_Iva*) _summary_table.succ_item();
|
||||
codici.add(curr->cod_iva().codice());
|
||||
curr = (TRiepilogo_iva*) _summary_table.succ_item();
|
||||
}
|
||||
codici.restart();
|
||||
summary_set_next(); // setta l'elemento corrente
|
||||
@ -178,22 +129,33 @@ void TDocumentoEsteso::summary_set_next()
|
||||
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];
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
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()
|
||||
@ -257,6 +219,7 @@ void TDocumentoEsteso::scadenze_reset()
|
||||
_scadenze_current = 0;
|
||||
}
|
||||
|
||||
/*
|
||||
real& TDocumentoEsteso::tot_importi_netti()
|
||||
{
|
||||
if (!summary_compiled()) compile_summary();
|
||||
@ -271,9 +234,10 @@ real& TDocumentoEsteso::tot_imposte()
|
||||
|
||||
real TDocumentoEsteso::tot_spese()
|
||||
{
|
||||
TString16 t("TOTSP");
|
||||
real number(get_head_info(t));
|
||||
return number;
|
||||
// TString16 t("TOTSP");
|
||||
// real number(get_head_info(t));
|
||||
// return number;
|
||||
return spese();
|
||||
}
|
||||
|
||||
real TDocumentoEsteso::tot_documento()
|
||||
@ -282,24 +246,26 @@ real TDocumentoEsteso::tot_documento()
|
||||
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();
|
||||
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();
|
||||
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>
|
||||
@ -315,7 +281,7 @@ const char* TDocumentoEsteso::get_head_info(const TString & what)
|
||||
}
|
||||
}
|
||||
return (const char*) rt;
|
||||
}
|
||||
} */
|
||||
|
||||
TDocumentoEsteso::TDocumentoEsteso(const TRectype& rec, TCond_vendita * condv)
|
||||
: TDocumento(rec, condv), _sum_filter(-1), _sum_selected(FALSE), _scadenze_current(-1)
|
||||
|
@ -1,5 +1,5 @@
|
||||
|
||||
enum _formule {_somma, _bolli, _bolli_int, _spinc, _prezzo, _importo, _sconto, _iva, _provv, _tipo, _imponibili, _imposte};
|
||||
enum _formule {_somma, _bolli, _bolli_int, _spinc, _prezzo, _importo, _imponibile, _sconto, _iva, _provv, _tipo, _imponibili, _imposte};
|
||||
enum TTipo_calcolo { _nessun_calcolo, _qtaprezzo, _valore, _percentuale, _scontoimp, _scontoperc};
|
||||
|
||||
void row_set_handler( TMask& m, const int field, const int index );
|
||||
|
Loading…
x
Reference in New Issue
Block a user