Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@21400 c028cbd2-c16b-5b4b-a496-9718f37d4682
434 lines
12 KiB
C++
Executable File
434 lines
12 KiB
C++
Executable File
#include "halib.h"
|
||
#include "hacnvlib.h"
|
||
#include "hacnv200a.h"
|
||
|
||
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <defmask.h>
|
||
#include <execp.h>
|
||
#include <progind.h>
|
||
#include <reprint.h>
|
||
#include <reputils.h>
|
||
#include <tabutil.h>
|
||
#include <utility.h>
|
||
|
||
#include <mov.h>
|
||
#include <rmov.h>
|
||
#include <rmoviva.h>
|
||
|
||
const char* const APPNAME = TR("Conversione movimenti");
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// Movimenti
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class THardy_movimenti : public THardy_transfer
|
||
{
|
||
int _anno;
|
||
TDate _dadata, _adata;
|
||
TConfig* _conf;
|
||
long _kmovcont;
|
||
TArray* _righeiva;
|
||
TArray* _righecont;
|
||
|
||
protected:
|
||
bool scrivi_righe();
|
||
bool scrivi_righecont();
|
||
bool test_movcont();
|
||
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);
|
||
|
||
public:
|
||
virtual bool trasferisci();
|
||
THardy_movimenti(const int anno, const TDate dadata, const TDate adata);
|
||
};
|
||
|
||
void THardy_movimenti::conto2campo(const TString& hd_tipoc, const TString& hd_key, TString4& tipoc, int& gr, int& co, long& so)
|
||
{
|
||
TConfig& ini = config();
|
||
char tipocc = hd_tipoc[0];
|
||
switch (tipocc)
|
||
{
|
||
case 'S':
|
||
{
|
||
tipoc = " ";
|
||
hd_key2conto(hd_key, gr, co, so);
|
||
}
|
||
break;
|
||
case 'C':
|
||
{
|
||
tipoc = "C";
|
||
gr = ini.get_int("CLI_GRUPPO", "Mastri");
|
||
co = ini.get_int("CLI_CONTO", "Mastri");
|
||
so = hd_key2cli(hd_key);
|
||
}
|
||
break;
|
||
case 'F':
|
||
{
|
||
tipoc = "F";
|
||
gr = ini.get_int("FOR_GRUPPO", "Mastri");
|
||
co = ini.get_int("FOR_CONTO", "Mastri");
|
||
so = hd_key2forn(hd_key);
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
bool THardy_movimenti::conto_is_costoricavo(const int gr)
|
||
{
|
||
TConfig& ini = config();
|
||
const int costi = ini.get_int("COSTI_GRUPPO", "Mastri");
|
||
const int ricavi = ini.get_int("RICAVI_GRUPPO", "Mastri");
|
||
return ((gr == costi) || (gr == ricavi));
|
||
}
|
||
|
||
bool THardy_movimenti::test_moviva()
|
||
{
|
||
// verifico se <20> un movimento iva: esiste un record in MovIvaT
|
||
TString query;
|
||
query << query_header();
|
||
query << "SELECT * "
|
||
"FROM dbo.MovIvaT "
|
||
"WHERE KMovconT=";
|
||
query << _kmovcont;
|
||
TODBC_recordset recset(query);
|
||
long kregivat = -1;
|
||
if (recset.items() > 0)
|
||
{
|
||
bool ok=recset.move_first();
|
||
if (ok)
|
||
{
|
||
kregivat = recset.get("KRegivaT").as_int();
|
||
// aggiorna_testata movimento gi<67> scritta su ini con i nuovi dati di testata
|
||
const TString& key = recset.get("IdConto").as_string();
|
||
TString4 hdtipoc = recset.get("IdContoTp").as_string();
|
||
TString4 tipoc = " ";
|
||
int gr, co;
|
||
long so;
|
||
gr = 0;
|
||
co = 0;
|
||
so = 0;
|
||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||
_conf->set(MOV_TIPO, tipoc);
|
||
_conf->set(MOV_CODCF, so);
|
||
real totdoc = recset.get("TotDocumento").as_real();
|
||
_conf->set(MOV_TOTDOC, totdoc.string(0,2));
|
||
}
|
||
}
|
||
// leggo le righe iva e costrisco array corrispondente
|
||
TString_array lista_campi_righeiva;
|
||
TConfig& ini = config();
|
||
ini.list_variables(lista_campi_righeiva, true, "RMOVIVA", true);
|
||
TString query_righe;
|
||
query_righe << query_header();
|
||
query_righe << "SELECT * "
|
||
"FROM dbo.MovIva "
|
||
"WHERE KRegivaT=";
|
||
query_righe << kregivat;
|
||
TODBC_recordset recset_righe(query_righe);
|
||
_righeiva->destroy();
|
||
TLocalisamfile rmoviva(LF_RMOVIVA);
|
||
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);
|
||
const TString& key = recset_righe.get("IdConto").as_string();
|
||
TString4 hdtipoc = recset_righe.get("IdContoTp").as_string();
|
||
TString4 tipoc;
|
||
tipoc = " ";
|
||
int gr, co;
|
||
long so;
|
||
gr = 0;
|
||
co = 0;
|
||
so = 0;
|
||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||
rec_rmoviva.put(RMI_TIPOC, tipoc);
|
||
rec_rmoviva.put(RMI_GRUPPO, gr);
|
||
rec_rmoviva.put(RMI_CONTO, co);
|
||
rec_rmoviva.put(RMI_SOTTOCONTO, so);
|
||
_righeiva->add(new TObject(rec_rmoviva));
|
||
}
|
||
return (kregivat > 0);
|
||
}
|
||
|
||
bool THardy_movimenti::test_movcont()
|
||
{
|
||
TString_array lista_campi_righe;
|
||
TConfig& ini = config();
|
||
ini.list_variables(lista_campi_righe, true, "RMOV", true);
|
||
TString query_righe;
|
||
query_righe << query_header();
|
||
query_righe << "SELECT * "
|
||
"FROM dbo.MovContabili "
|
||
"WHERE KMovconT=";
|
||
query_righe << _kmovcont;
|
||
TODBC_recordset recset_righe(query_righe);
|
||
_righecont->destroy();
|
||
TLocalisamfile rmov(LF_RMOV);
|
||
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);
|
||
const TString& key = recset_righe.get("IdConto").as_string();
|
||
TString4 hdtipoc = recset_righe.get("IdContoTp").as_string();
|
||
TString4 tipoc;
|
||
tipoc = " ";
|
||
int gr, co;
|
||
long so;
|
||
gr = 0;
|
||
co = 0;
|
||
so = 0;
|
||
conto2campo(hdtipoc, key, tipoc, gr, co, so);
|
||
TString4 sezione = "D";
|
||
real imp_dare = recset_righe.get("Dare").as_real();
|
||
real imp_avere = recset_righe.get("Avere").as_real();
|
||
if (imp_dare.is_zero())
|
||
sezione = "A";
|
||
rec_rmov.put(RMV_SEZIONE, sezione);
|
||
rec_rmov.put(RMV_IMPORTO, (imp_avere.is_zero() ? imp_dare : imp_avere));
|
||
rec_rmov.put(RMV_TIPOC, tipoc);
|
||
rec_rmov.put(RMV_GRUPPO, gr);
|
||
rec_rmov.put(RMV_CONTO, co);
|
||
rec_rmov.put(RMV_SOTTOCONTO, so);
|
||
_righecont->add(new TObject(rec_rmov));
|
||
}
|
||
return true;
|
||
}
|
||
|
||
bool THardy_movimenti::scrivi_righecont()
|
||
{
|
||
return true;
|
||
}
|
||
bool THardy_movimenti::scrivi_righe()
|
||
{
|
||
TConfig& ini = config();
|
||
TToken_string gruppi_mov = ini.get("GRUPPI_MOV", "Mastri");
|
||
// se <20> un movimento iva metto in atto il meccanismo di ricerca per assegnare le aliquote ai conti
|
||
if (_righeiva->items()>0)
|
||
{
|
||
// 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);
|
||
if (!gruppi_mov.find(gruppo))
|
||
_righecont->remove(i);
|
||
}
|
||
// 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
|
||
for (int i=0;i<_righeiva->items();i++)
|
||
{
|
||
TRectype* rec_rmoviva = (TRectype*)_righeiva->objptr(i);
|
||
real imponibile = rec_rmoviva->get(RMI_IMPONIBILE);
|
||
}
|
||
|
||
}
|
||
// scrivo su ini le righe contabili rimaste (tutte se il mov non <20> iva)
|
||
scrivi_righecont();
|
||
return true;
|
||
}
|
||
|
||
bool THardy_movimenti::trasferisci()
|
||
{
|
||
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());
|
||
|
||
TString query =
|
||
"SELECT * "
|
||
"FROM dbo.MovContabiliT "
|
||
"WHERE Esercizio=";
|
||
query << _anno;
|
||
query << " AND DataMovimento>= '";
|
||
query << dastr;
|
||
query << "' AND DataMovimento<= '";
|
||
query << astr;
|
||
query << "' ORDER BY DataMovimento ";
|
||
|
||
TRecordset& recset = create_recordset(query);
|
||
TConfig& ini = config();
|
||
|
||
TString_array lista_campi;
|
||
ini.list_variables(lista_campi, true, "MOV", true);
|
||
|
||
TFilename outdir;
|
||
outdir = ini.get("PATH", "Main");
|
||
TString80 listfiles = outdir;
|
||
listfiles << "\\ha*.ini";
|
||
TString_array transactions;
|
||
list_files(listfiles, transactions);
|
||
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
||
remove(*name);
|
||
|
||
_conf = NULL;
|
||
long ntran = 1L;
|
||
TString paragraph;
|
||
|
||
THardy_iterator hi(this);
|
||
while (++hi)
|
||
{
|
||
_kmovcont = recset.get("KMovconT").as_int(); // numero movimento testata
|
||
if (_conf != NULL)
|
||
delete _conf;
|
||
_conf = NULL;
|
||
TFilename temp(outdir);
|
||
temp.add(format("ha%06ld", ntran++));
|
||
temp.ext("ini");
|
||
if (temp.exist())
|
||
temp.fremove();
|
||
_conf = new TConfig(temp);
|
||
_conf->set_paragraph("Transaction");
|
||
_conf->set("Action","INSERT");
|
||
_conf->set("Mode", "AUTO");
|
||
paragraph.format("%d",LF_MOV);
|
||
_conf->set_paragraph(paragraph); // testata movimento
|
||
aggiorna_ini(*_conf, lista_campi);
|
||
// verifica se <20> un mov. iva e nel caso aggiorna testata e array righe iva
|
||
bool iva = test_moviva();
|
||
// legge righe contabili e aggiorna array righe cont.
|
||
test_movcont();
|
||
// scrive RMOV e /o RMOVIVA a partire da array righe letti da db hardy
|
||
bool ok = scrivi_righe();
|
||
TString msg;
|
||
if (ok)
|
||
msg << (iva ? TR("Movimento iva "): TR("Movimento contabile ")) << _kmovcont << " generato nel file " << temp;
|
||
else
|
||
{
|
||
ntran--;
|
||
if (temp.exist())
|
||
temp.fremove();
|
||
msg << (iva ? TR("Il movimento iva "): TR("Il movimento contabile ")) << _kmovcont << " ha generato un errore, non <20> stato convertito ";
|
||
}
|
||
log(msg);
|
||
}
|
||
if (_conf != NULL)
|
||
delete _conf;
|
||
if (yesno_box(FR("Si desidera confermare l'importazione di %ld movimenti"), ntran-1))
|
||
{
|
||
TString app;
|
||
app << "cg2 -0 -i" << outdir << "/ha*.ini";
|
||
TExternal_app primanota(app);
|
||
primanota.run(true);
|
||
}
|
||
return true;
|
||
}
|
||
|
||
THardy_movimenti::THardy_movimenti(const int anno, const TDate dadata, const TDate adata) : _anno(anno), _dadata(dadata), _adata(adata)
|
||
{
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TConvMovimentiHardy_mask
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TConvMovimentiHardy_mask : public TAutomask
|
||
{
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
void serialize(bool bSave);
|
||
|
||
public:
|
||
void trasferisci();
|
||
|
||
TConvMovimentiHardy_mask();
|
||
virtual ~TConvMovimentiHardy_mask();
|
||
};
|
||
|
||
// Funzione di trasferimento dati da/verso file .ini con lo stesso nome della maschera
|
||
// Andrebbe messo in libreria
|
||
void TConvMovimentiHardy_mask::serialize(bool bSave)
|
||
{
|
||
TFilename n = source_file(); n.ext("ini"); // Construisce il nome del .ini in base al .msk
|
||
TConfig cfg(n, "Main"); // Crea il file di configurazione
|
||
TString4 id;
|
||
for (int i = fields()-1; i >= 0; i--) // Scandisce tutti i campi della maschera ...
|
||
{
|
||
TMask_field& f = fld(i);
|
||
if (f.active() && f.is_loadable()) // ... selezionando solo quelli editabili
|
||
{
|
||
id.format("%d", f.dlg());
|
||
if (bSave) // A seconda del flag di scrittura ...
|
||
cfg.set(id, f.get()); // ... o scrive sul .ini
|
||
else
|
||
f.set(cfg.get(id)); // ... o legge dal .ini
|
||
}
|
||
}
|
||
}
|
||
|
||
void TConvMovimentiHardy_mask::trasferisci()
|
||
{
|
||
TString query_header;
|
||
query_header << "ODBC(" << get(F_DSN) << ',' << get(F_USR) << ',' << get(F_PWD) << ")\n";
|
||
|
||
TReport_book book;
|
||
THardy_log log;
|
||
|
||
bool rep_to_print = false;
|
||
bool go_on = true;
|
||
|
||
const int anno = get_int(F_ANNO);
|
||
const TDate dadata = get_date(F_DADATA);
|
||
const TDate adata = get_date(F_ADATA);
|
||
if (go_on && (anno!=0))
|
||
{
|
||
THardy_movimenti pc(anno, dadata, adata);
|
||
pc.init(TR("Movimenti contabili"), query_header, log);
|
||
go_on = pc.trasferisci();
|
||
book.add(log);
|
||
rep_to_print = true;
|
||
}
|
||
if (rep_to_print && book.pages() > 0)
|
||
book.preview();
|
||
}
|
||
|
||
bool TConvMovimentiHardy_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case DLG_OK:
|
||
if (e == fe_button)
|
||
serialize(true);
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
TConvMovimentiHardy_mask::TConvMovimentiHardy_mask() : TAutomask("hacnv200a")
|
||
{
|
||
serialize(false);
|
||
}
|
||
|
||
TConvMovimentiHardy_mask::~TConvMovimentiHardy_mask()
|
||
{
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TConvMovimentiHardy
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TConvMovimentiHardy : public TSkeleton_application
|
||
{
|
||
protected:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
void TConvMovimentiHardy::main_loop()
|
||
{
|
||
TConvMovimentiHardy_mask mask;
|
||
while (mask.run() == K_ENTER)
|
||
mask.trasferisci();
|
||
}
|
||
|
||
int hacnv200(int argc, char* argv[])
|
||
{
|
||
TConvMovimentiHardy ih;
|
||
ih.run(argc, argv, APPNAME);
|
||
return 0;
|
||
}
|
||
|