Patch level : 10.0 hardy
Files correlati : Ricompilazione Demo : [ ] Commento : conversione movimenti: manca solo gestione iva con % indetraibilità git-svn-id: svn://10.65.10.50/branches/R_10_00@21410 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
855f0faad6
commit
0973fe757a
@ -550,8 +550,8 @@ ANNOES = Anno
|
||||
NUMREG =
|
||||
NUMRIG =
|
||||
CODIVA = IdIva
|
||||
IMPONIBILE=Imponibile
|
||||
IMPOSTA =Imposta
|
||||
IMPONIBILE= Imponibile
|
||||
IMPOSTA = Imposta
|
||||
TIPODET =
|
||||
TIPOCR =
|
||||
INTRA =
|
||||
|
210
ha/hacnv200.cpp
210
ha/hacnv200.cpp
@ -24,12 +24,13 @@ const char* const APPNAME = TR("Conversione movimenti");
|
||||
|
||||
class THardy_movimenti : public THardy_transfer
|
||||
{
|
||||
int _anno;
|
||||
TDate _dadata, _adata;
|
||||
TConfig* _conf;
|
||||
long _kmovcont;
|
||||
TArray* _righeiva;
|
||||
TArray* _righecont;
|
||||
int _anno; // parametri per la query
|
||||
TDate _dadata, _adata; // parametri per la query
|
||||
TConfig* _conf; // ini in compilazione
|
||||
long _kmovcont; // movimento contabile in esame
|
||||
TArray* _righeiva; // array dele righe iva hardy
|
||||
TArray* _righecont; // array delle righe contabili hardy
|
||||
|
||||
|
||||
protected:
|
||||
bool scrivi_righe();
|
||||
@ -38,12 +39,100 @@ protected:
|
||||
bool conto_is_costoricavo(const int gr);
|
||||
bool test_moviva();
|
||||
void conto2campo(const TString& hd_tipoc, const TString& hd_key, TString4& tipoc, int& gr, int& co, long& so);
|
||||
void rec2ini(const TRectype& rec);
|
||||
void recset2rec(TODBC_recordset& recset, TRectype& rec, const TString_array& lista_campi);
|
||||
|
||||
public:
|
||||
virtual bool trasferisci();
|
||||
THardy_movimenti(const int anno, const TDate dadata, const TDate adata);
|
||||
};
|
||||
|
||||
// carica il record campo con il record hardy in base alla configurazione
|
||||
void THardy_movimenti::recset2rec(TODBC_recordset& recset, TRectype& rec, const TString_array& lista_campi)
|
||||
{
|
||||
TString campo_dest, campo_orig, valore, str;
|
||||
FOR_EACH_ARRAY_ROW(lista_campi,i,row)
|
||||
{
|
||||
row->get(0, campo_dest);
|
||||
row->get(1, campo_orig);
|
||||
if (campo_orig.full())
|
||||
{
|
||||
if (campo_orig[0] == '_')
|
||||
{
|
||||
if (campo_orig.starts_with("_SCONTO")) // è uno sconto (ca..o!)
|
||||
{
|
||||
valore.cut(0);
|
||||
real sconto;
|
||||
TString8 field;
|
||||
for (int i = 1; i < 6; i++)
|
||||
{
|
||||
field.format("Sconto%1d",i);
|
||||
sconto = get_real(field);
|
||||
sconto.round(2);
|
||||
if (sconto != ZERO)
|
||||
{
|
||||
valore << sconto.string();
|
||||
valore << "+";
|
||||
}
|
||||
}
|
||||
if (valore.len()>0)
|
||||
valore = valore.left(valore.len()-1);
|
||||
} else
|
||||
if (campo_orig.starts_with("_REAL")) // è un real
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
real r = recset.get(campo).as_real();
|
||||
valore = r.string();
|
||||
} else
|
||||
if (campo_orig.starts_with("_ROUND")) // arrotondo a due decimali
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
real contenuto = recset.get(campo).as_real();
|
||||
contenuto.round(2);
|
||||
valore = contenuto.string();
|
||||
} else
|
||||
if (campo_orig.starts_with("_FISSO")) // valore fisso indicato in configurazione
|
||||
{
|
||||
valore = campo_orig.after(',');
|
||||
valore.trim();
|
||||
} else
|
||||
if (campo_orig.starts_with("_STREXPR")) // formato _STREXPR, espressione
|
||||
{
|
||||
TExpression expr(campo_orig.after(','), _strexpr);
|
||||
for (int v = 0; v < expr.numvar(); v++)
|
||||
{
|
||||
const char* varname = expr.varname(v);
|
||||
expr.setvar(v, recset.get(varname).as_string());
|
||||
}
|
||||
valore = expr.as_string();
|
||||
valore.trim();
|
||||
} else
|
||||
if (campo_orig.starts_with("_TAB")) // formato _TAB,<tabella da leggere>,<valore CODTAB>, <campo da leggere>
|
||||
{
|
||||
TToken_string elabora(campo_orig, ',');
|
||||
const TString4 tab = elabora.get(1); // tabella da leggere
|
||||
const TString16 codtab = recset.get(elabora.get()).as_string();
|
||||
const TString16 campotab = elabora.get();
|
||||
valore = cache().get(tab, codtab, campotab);
|
||||
} else
|
||||
if (campo_orig.starts_with("_TRADUCI"))
|
||||
{
|
||||
const TString80 campo = campo_orig.after(',');
|
||||
const TString80 contenuto = recset.get(campo).as_string();
|
||||
TConfig& ini = config();
|
||||
valore = ini.get(contenuto,campo);
|
||||
}
|
||||
else
|
||||
valore.cut(0);
|
||||
}
|
||||
else
|
||||
valore = recset.get(campo_orig).as_string();
|
||||
rec.put(campo_dest, valore);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// calcola conto campo a partire da conto hardy
|
||||
void THardy_movimenti::conto2campo(const TString& hd_tipoc, const TString& hd_key, TString4& tipoc, int& gr, int& co, long& so)
|
||||
{
|
||||
TConfig& ini = config();
|
||||
@ -77,6 +166,7 @@ void THardy_movimenti::conto2campo(const TString& hd_tipoc, const TString& hd_ke
|
||||
}
|
||||
}
|
||||
|
||||
// verifica in configurazione se il conto è costo o ricavo
|
||||
bool THardy_movimenti::conto_is_costoricavo(const int gr)
|
||||
{
|
||||
TConfig& ini = config();
|
||||
@ -85,6 +175,7 @@ bool THardy_movimenti::conto_is_costoricavo(const int gr)
|
||||
return ((gr == costi) || (gr == ricavi));
|
||||
}
|
||||
|
||||
// verifica se il movimento è iva e nel caso riempie array delle righe iva
|
||||
bool THardy_movimenti::test_moviva()
|
||||
{
|
||||
// verifico se è un movimento iva: esiste un record in MovIvaT
|
||||
@ -134,7 +225,7 @@ bool THardy_movimenti::test_moviva()
|
||||
TRectype& rec_rmoviva = rmoviva.curr();
|
||||
for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next())
|
||||
{
|
||||
aggiorna_record(rec_rmoviva, lista_campi_righeiva);
|
||||
recset2rec(recset_righe, rec_rmoviva, lista_campi_righeiva);
|
||||
const TString& key = recset_righe.get("IdConto").as_string();
|
||||
TString4 hdtipoc = recset_righe.get("IdContoTp").as_string();
|
||||
TString4 tipoc;
|
||||
@ -149,11 +240,12 @@ bool THardy_movimenti::test_moviva()
|
||||
rec_rmoviva.put(RMI_GRUPPO, gr);
|
||||
rec_rmoviva.put(RMI_CONTO, co);
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, so);
|
||||
_righeiva->add(new TObject(rec_rmoviva));
|
||||
_righeiva->add(new TRectype(rec_rmoviva));
|
||||
}
|
||||
return (kregivat > 0);
|
||||
}
|
||||
|
||||
// riempie array delle righe contabili
|
||||
bool THardy_movimenti::test_movcont()
|
||||
{
|
||||
TString_array lista_campi_righe;
|
||||
@ -171,7 +263,7 @@ bool THardy_movimenti::test_movcont()
|
||||
TRectype& rec_rmov = rmov.curr();
|
||||
for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next())
|
||||
{
|
||||
aggiorna_record(rec_rmov, lista_campi_righe);
|
||||
recset2rec(recset_righe, rec_rmov, lista_campi_righe);
|
||||
const TString& key = recset_righe.get("IdConto").as_string();
|
||||
TString4 hdtipoc = recset_righe.get("IdContoTp").as_string();
|
||||
TString4 tipoc;
|
||||
@ -193,17 +285,44 @@ bool THardy_movimenti::test_movcont()
|
||||
rec_rmov.put(RMV_GRUPPO, gr);
|
||||
rec_rmov.put(RMV_CONTO, co);
|
||||
rec_rmov.put(RMV_SOTTOCONTO, so);
|
||||
_righecont->add(new TObject(rec_rmov));
|
||||
_righecont->add(new TRectype(rec_rmov));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// scrive il record passato sull'ini corrente
|
||||
void THardy_movimenti::rec2ini(const TRectype& rec)
|
||||
{
|
||||
for (int i=0; i<rec.items(); i++)
|
||||
{
|
||||
const char* fieldname = rec.fieldname(i);
|
||||
const TString& value = rec.get(fieldname);
|
||||
if (!value.empty())
|
||||
_conf->set(fieldname, value);
|
||||
}
|
||||
}
|
||||
|
||||
// scrive su ini le righe contabili
|
||||
bool THardy_movimenti::scrivi_righecont()
|
||||
{
|
||||
TString paragraph;
|
||||
int nrigac = 1;
|
||||
for (int i=0;i<_righecont->items();i++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(i);
|
||||
paragraph.format("%d,%d",LF_RMOV, nrigac++);
|
||||
_conf->set_paragraph(paragraph); // riga contabile
|
||||
rec2ini(rec_rmov);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// gestisce tutto il procedimento di scrittura su ini delle righe iva e contabili
|
||||
bool THardy_movimenti::scrivi_righe()
|
||||
{
|
||||
const int ndec = TCurrency::get_firm_dec(false);
|
||||
TString paragraph;
|
||||
int nrigai = 1; // contatore righe iva
|
||||
TConfig& ini = config();
|
||||
TToken_string gruppi_mov = ini.get("GRUPPI_MOV", "Mastri");
|
||||
// se è un movimento iva metto in atto il meccanismo di ricerca per assegnare le aliquote ai conti
|
||||
@ -212,27 +331,82 @@ bool THardy_movimenti::scrivi_righe()
|
||||
// primo passo: scartare le righe contabili con gruppi non presenti nella lista GRUPPI_MOV
|
||||
for (int i=0;i<_righecont->items();i++)
|
||||
{
|
||||
TRectype* rec_rmov = (TRectype*)_righecont->objptr(i);
|
||||
const char* gruppo = rec_rmov->get(RMV_GRUPPO);
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(i);
|
||||
const char* gruppo = rec_rmov.get(RMV_GRUPPO);
|
||||
if (!gruppi_mov.find(gruppo))
|
||||
_righecont->remove(i);
|
||||
_righecont->destroy(i, true);
|
||||
}
|
||||
// secondo passo: per ogni riga iva cerco importo uguale in righe contabili,
|
||||
// se lo trovo assegno quel codice iva il conto contabile trovato e cancello la riga iva
|
||||
// se lo trovo assegno quel codice iva al conto contabile trovato e cancello la riga iva e la riga contabile
|
||||
for (int i=0;i<_righeiva->items();i++)
|
||||
{
|
||||
TRectype* rec_rmoviva = (TRectype*)_righeiva->objptr(i);
|
||||
real imponibile = rec_rmoviva->get(RMI_IMPONIBILE);
|
||||
TRectype& rec_rmoviva = *(TRectype*)_righeiva->objptr(i);
|
||||
real imponibile = rec_rmoviva.get_real(RMI_IMPONIBILE);
|
||||
for (int j=0;j<_righecont->items();j++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
real importo = rec_rmov.get_real(RMV_IMPORTO);
|
||||
if (importo == imponibile)
|
||||
{
|
||||
rec_rmoviva.put(RMI_TIPOC, rec_rmov.get(RMV_TIPOC));
|
||||
rec_rmoviva.put(RMI_GRUPPO, rec_rmov.get(RMV_GRUPPO));
|
||||
rec_rmoviva.put(RMI_CONTO, rec_rmov.get(RMV_CONTO));
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, rec_rmov.get(RMV_SOTTOCONTO));
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(rec_rmoviva);
|
||||
_righecont->destroy(j, true);
|
||||
_righeiva->destroy(i, true);
|
||||
i = _righeiva->items();
|
||||
j = _righecont->items();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// terzo passo: per ogni riga iva rimasta distribuisco importo su tutti i conti rimasti in righe cont.
|
||||
for (int i=0;i<_righeiva->items();i++)
|
||||
{
|
||||
TRectype& rec_rmoviva = *(TRectype*)_righeiva->objptr(i);
|
||||
real imponibile = rec_rmoviva.get_real(RMI_IMPONIBILE);
|
||||
real imposta = rec_rmoviva.get_real(RMI_IMPOSTA);
|
||||
TGeneric_distrib dimponibile(imponibile, ndec);
|
||||
TGeneric_distrib dimposta(imposta, ndec);
|
||||
for (int j=0;j<_righecont->items();j++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
real importo = rec_rmov.get_real(RMV_IMPORTO);
|
||||
dimponibile.add(importo);
|
||||
dimposta.add(importo);
|
||||
}
|
||||
for (int j=0;j<_righecont->items();j++)
|
||||
{
|
||||
TRectype& rec_rmov = *(TRectype*)_righecont->objptr(j);
|
||||
real importo = dimponibile.get();
|
||||
real imposta = dimposta.get();
|
||||
rec_rmoviva.put(RMI_TIPOC, rec_rmov.get(RMV_TIPOC));
|
||||
rec_rmoviva.put(RMI_GRUPPO, rec_rmov.get(RMV_GRUPPO));
|
||||
rec_rmoviva.put(RMI_CONTO, rec_rmov.get(RMV_CONTO));
|
||||
rec_rmoviva.put(RMI_SOTTOCONTO, rec_rmov.get(RMV_SOTTOCONTO));
|
||||
rec_rmoviva.put(RMI_IMPONIBILE, importo);
|
||||
rec_rmoviva.put(RMI_IMPOSTA, imposta);
|
||||
paragraph.format("%d,%d",LF_RMOVIVA, nrigai++);
|
||||
_conf->set_paragraph(paragraph); // riga iva
|
||||
rec2ini(rec_rmoviva);
|
||||
}
|
||||
_righeiva->destroy(i, true);
|
||||
}
|
||||
_righecont->destroy();
|
||||
}
|
||||
// scrivo su ini le righe contabili rimaste (tutte se il mov non è iva)
|
||||
scrivi_righecont();
|
||||
return true;
|
||||
}
|
||||
|
||||
// procedura principale di conversione
|
||||
bool THardy_movimenti::trasferisci()
|
||||
{
|
||||
// creazione array delle aliquote iva con % indetraibilitaà
|
||||
// leggere la tabella hardy AliquoteIVA
|
||||
|
||||
TString16 dastr, astr;
|
||||
dastr.format("%4d-%2d-%2d", _dadata.year(), _dadata.month(), _dadata.day());
|
||||
astr.format("%4d-%2d-%2d", _adata.year(), _adata.month(), _adata.day());
|
||||
@ -318,6 +492,8 @@ bool THardy_movimenti::trasferisci()
|
||||
|
||||
THardy_movimenti::THardy_movimenti(const int anno, const TDate dadata, const TDate adata) : _anno(anno), _dadata(dadata), _adata(adata)
|
||||
{
|
||||
_righeiva = new TArray;
|
||||
_righecont = new TArray;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
|
Loading…
x
Reference in New Issue
Block a user