2010-11-25 08:52:50 +00:00
|
|
|
|
#include <applicat.h>
|
2010-11-29 15:44:14 +00:00
|
|
|
|
#include <assoc.h>
|
2010-11-25 08:52:50 +00:00
|
|
|
|
#include <automask.h>
|
|
|
|
|
#include <execp.h>
|
|
|
|
|
#include <progind.h>
|
|
|
|
|
#include <reputils.h>
|
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
|
|
#include <mov.h>
|
2010-11-25 11:11:48 +00:00
|
|
|
|
#include <scadenze.h>
|
2010-11-25 08:52:50 +00:00
|
|
|
|
#include <rmoviva.h>
|
|
|
|
|
|
|
|
|
|
#include "../ce/ammce.h"
|
|
|
|
|
#include "../ce/cespi.h"
|
|
|
|
|
#include "../ce/salce.h"
|
|
|
|
|
|
|
|
|
|
#include "../cg/cg2103.h"
|
|
|
|
|
#include "../cg/cglib01.h"
|
|
|
|
|
|
|
|
|
|
#include "lv4.h"
|
|
|
|
|
#include "lv4100.h"
|
|
|
|
|
#include "lv4500a.h"
|
2010-11-29 15:44:14 +00:00
|
|
|
|
#include "lvlib.h"
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
#define T_N "N"
|
|
|
|
|
#define T_X "X"
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////
|
|
|
|
|
//// LAUNDRY_RECORDSET ////
|
|
|
|
|
/////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Classe TLaundry_recordset: <20> un TAS400_recordset "intelligente"
|
|
|
|
|
class TLaundry_recordset : public TAS400_recordset
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
void add_field(const char* name, const char* tipo, int pos, int len);
|
|
|
|
|
TLaundry_recordset(const int rec_length);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//ADD_FIELD: aggiunge i campi al recordset
|
|
|
|
|
void TLaundry_recordset::add_field(const char* name, const char* tipo, int pos, int len)
|
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
CHECK(name[1]=='.', "Campo orfano di tracciato");
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const TFixed_string str_tipo(tipo);
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TFieldtypes ft = _alfafld;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
if (str_tipo.ends_with("N"))
|
2010-11-29 15:44:14 +00:00
|
|
|
|
ft = _intzerofld;
|
|
|
|
|
create_field(name, -1, len, ft);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//costruttore
|
2010-11-25 08:52:50 +00:00
|
|
|
|
TLaundry_recordset::TLaundry_recordset(const int rec_lenght)
|
|
|
|
|
: TAS400_recordset("AS400()")
|
|
|
|
|
{
|
|
|
|
|
TString16 query;
|
|
|
|
|
query << "AS400(" << rec_lenght << ")";
|
|
|
|
|
TFilename cazzone;
|
|
|
|
|
parse_query(query, cazzone);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
////////////////////////////
|
|
|
|
|
//// TCONTI_CACHE ////
|
|
|
|
|
////////////////////////////
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//classe TConti_cache
|
|
|
|
|
class TConti_cache : public TCache
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
|
|
|
|
protected:
|
2010-11-29 15:44:14 +00:00
|
|
|
|
virtual TObject* key2obj(const char* key);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
public:
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const TBill& decodifica_conti(const long mastro, const long conto);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
};
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//KEY2OBJ: ridefinisco il metodo virtuale key2obj in modo che mi restituisca quello di cui ho bisogno
|
|
|
|
|
TObject* TConti_cache::key2obj(const char* key)
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TLocalisamfile riclpdc(LF_RICLPDC);
|
|
|
|
|
riclpdc.setkey(3);
|
|
|
|
|
riclpdc.put("TIPORIC", "CGCONTI");
|
|
|
|
|
riclpdc.put("CODICE", key);
|
2010-12-02 06:57:29 +00:00
|
|
|
|
if(riclpdc.read(_isgteq) == NOERR && riclpdc.get("CODICE") == key)
|
2010-11-29 15:44:14 +00:00
|
|
|
|
return new TBill(riclpdc.get_int("GRUPPO"), riclpdc.get_int("CONTO"), riclpdc.get_long("SOTTOCONTO"));
|
|
|
|
|
return new TBill;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_CONTI: restituisce il TBill dato codice mastro e conto del COGECO
|
|
|
|
|
const TBill& TConti_cache::decodifica_conti(const long mastro, const long conto)
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TString16 codice;
|
|
|
|
|
codice.format("%06ld%06ld", mastro, conto);
|
|
|
|
|
const TBill* bill = (TBill*)objptr(codice);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
return *bill;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//////////////////////////////////
|
|
|
|
|
//// TDECODIFICA_CODICI ////
|
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//classe TDecodifica_codici
|
2010-11-25 14:58:06 +00:00
|
|
|
|
class TDecodifica_codici : public TObject
|
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TAssoc_array _tab;
|
|
|
|
|
TConti_cache _conti;
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
2010-11-29 15:44:14 +00:00
|
|
|
|
void riempi_array();
|
|
|
|
|
const TString& decodifica(const char* tabella, const int codice);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
|
|
|
|
public:
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const TString& decodifica_causali(const int cau_cog);
|
|
|
|
|
const TString& decodifica_condpag(const int condpag_cog);
|
|
|
|
|
const TString& decodifica_codiva(const int codiva_cog);
|
|
|
|
|
const TString& decodifica_regiva(const int regiva_cog);
|
|
|
|
|
const TString& decodifica_valute(const int val_cog);
|
|
|
|
|
const TBill& decodifica_conto(const long mastro, const long conto);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
|
|
|
|
TDecodifica_codici();
|
|
|
|
|
};
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//RIEMPI_ARRAY: riempe l'Assoc_array che contiene i dati per fare la decodifica
|
|
|
|
|
void TDecodifica_codici::riempi_array()
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
|
|
|
|
TString query;
|
|
|
|
|
query << "USE MULTIREL\n"
|
2010-11-29 15:44:14 +00:00
|
|
|
|
<< "FROM COD=\"CG\"\n"
|
|
|
|
|
<< "TO COD=\"CG\"";
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
|
|
|
|
TISAM_recordset recset(query);
|
|
|
|
|
|
|
|
|
|
for(bool ok = recset.move_first(); ok; ok = recset.move_next())
|
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const TString& codice = recset.get("COD").as_string().mid(2);
|
|
|
|
|
const TString& data = recset.get("DATA").as_string();
|
|
|
|
|
const TString& first = recset.get("FIRST").as_string();
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//faccio un Assoc_array di Assoc_array
|
|
|
|
|
TAssoc_array* tab = (TAssoc_array*)_tab.objptr(codice);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
if(tab == NULL)
|
|
|
|
|
{
|
|
|
|
|
tab = new TAssoc_array;
|
|
|
|
|
_tab.add(codice, tab);
|
|
|
|
|
}
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
tab->add(data, first);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA: fa la decodica vera e propria
|
|
|
|
|
const TString& TDecodifica_codici::decodifica(const char* tabella, const int codice)
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//se non ho ancora caricato l'array, lo faccio
|
|
|
|
|
if(_tab.empty())
|
|
|
|
|
riempi_array();
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TAssoc_array* tab = (TAssoc_array*)_tab.objptr(tabella);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//se esite, restituisco la decodifica, altrimenti stringa vuota
|
|
|
|
|
if(tab != NULL && codice > 0)
|
|
|
|
|
{
|
|
|
|
|
TString8 cod; cod << codice;
|
|
|
|
|
const TString* data = (const TString*)tab->objptr(cod);
|
|
|
|
|
|
|
|
|
|
if(data != NULL)
|
|
|
|
|
return *data;
|
|
|
|
|
}
|
|
|
|
|
return EMPTY_STRING;
|
2010-11-25 14:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_CAUSALI: decodifico da COGECO a Campo la causale
|
|
|
|
|
const TString& TDecodifica_codici::decodifica_causali(const int cau_cog)
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
return decodifica("CAU", cau_cog);
|
|
|
|
|
}
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_CONDPAG: decodifico da COGECO a Campo la condizione di pagamento
|
|
|
|
|
const TString& TDecodifica_codici::decodifica_condpag(const int condpag_cog)
|
|
|
|
|
{
|
|
|
|
|
return decodifica("CDP", condpag_cog);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_CODIVA: decodifico da COGECO a Campo il codice IVA
|
|
|
|
|
const TString& TDecodifica_codici::decodifica_codiva(const int codiva_cog)
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
return decodifica("IVA", codiva_cog);
|
|
|
|
|
}
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_REGIVA: decodifico da COGECO a Campo il registro IVA
|
|
|
|
|
const TString& TDecodifica_codici::decodifica_regiva(const int regiva_cog)
|
|
|
|
|
{
|
|
|
|
|
return decodifica("REG", regiva_cog);
|
|
|
|
|
}
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_VALUTE: decodifico da COGECO a Campo la valuta
|
|
|
|
|
const TString& TDecodifica_codici::decodifica_valute(const int val_cog)
|
|
|
|
|
{
|
|
|
|
|
return decodifica("VAL", val_cog);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//DECODIFICA_CONTO: decodifico da COGECO a Campo il conto
|
|
|
|
|
const TBill& TDecodifica_codici::decodifica_conto(const long mastro, const long conto)
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
return _conti.decodifica_conti(mastro, conto);
|
|
|
|
|
}
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//costruttore
|
|
|
|
|
TDecodifica_codici::TDecodifica_codici()
|
|
|
|
|
{}
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
////////////////////////////////
|
|
|
|
|
//// TIMPORTA_FAT_REC ////
|
|
|
|
|
////////////////////////////////
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//Classe TImporta_fat_rec
|
|
|
|
|
class TImporta_fat_rec : public TLaundry_recordset
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
protected:
|
|
|
|
|
virtual TRecnotype new_rec(const char* trc);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
public:
|
|
|
|
|
TImporta_fat_rec(const TFilename& filename);
|
|
|
|
|
};
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
// Recordset specifici per i dati da trasferire INPUT
|
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TRecnotype TImporta_fat_rec::new_rec(const char* trc)
|
|
|
|
|
{
|
|
|
|
|
if (trc && *trc > ' ')
|
|
|
|
|
{
|
|
|
|
|
TString rec; rec << trc << "\r\n";
|
|
|
|
|
return TText_recordset::new_rec(rec);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
2010-11-25 14:58:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
//questo invece <20> il metodo magico che vale per il caricamento da file esterno
|
|
|
|
|
TImporta_fat_rec::TImporta_fat_rec(const TFilename& filename)
|
|
|
|
|
: TLaundry_recordset(89)
|
2010-11-25 14:58:06 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TFilename cazzone;
|
|
|
|
|
//as400 con lunghezza 89 e chiave lunga 1 (a partire dal ventesimo carattere): <20> il tipo record
|
|
|
|
|
parse_query("AS400(89,1,20)", cazzone);
|
|
|
|
|
|
|
|
|
|
//Tipo record C
|
|
|
|
|
add_field("C.NDOC", T_N, 1, 6);
|
|
|
|
|
add_field("C.DATADOC", T_N, 7, 8);
|
|
|
|
|
add_field("C.NPART", T_N, 15, 6);
|
|
|
|
|
add_field("C.TIPOMOV", T_X, 21, 1);
|
|
|
|
|
add_field("C.SEZIONE", T_X, 22, 1);
|
|
|
|
|
add_field("C.CODCF", T_N, 23, 6);
|
|
|
|
|
add_field("C.IMPORTO", T_X, 29, 13);
|
|
|
|
|
add_field("C.CODVAL", T_X, 42, 4);
|
|
|
|
|
add_field("C.CODPAG", T_X, 46, 4);
|
|
|
|
|
add_field("C.DATASCAD", T_N, 50, 8);
|
|
|
|
|
add_field("C.ABICAB", T_N, 58, 12);
|
|
|
|
|
add_field("C.CODCAU", T_N, 70, 4);
|
|
|
|
|
add_field("C.REGIVA", T_X, 74, 1);
|
|
|
|
|
add_field("C.NREGIVA", T_N, 75, 2);
|
|
|
|
|
add_field("C.NPROG", T_N, 77, 11);
|
|
|
|
|
|
|
|
|
|
//Tipo record G
|
|
|
|
|
add_field("G.NDOC", T_N, 1, 6);
|
|
|
|
|
add_field("G.DATADOC", T_N, 7, 8);
|
|
|
|
|
add_field("G.NPART", T_N, 15, 6);
|
|
|
|
|
add_field("G.TIPOMOV", T_X, 21, 1);
|
|
|
|
|
add_field("G.SEZIONE", T_X, 22, 1);
|
|
|
|
|
add_field("G.IMPORTO", T_X, 23, 13);
|
|
|
|
|
add_field("G.CODMASTRO", T_N, 36, 6);
|
|
|
|
|
add_field("G.CODCONTO", T_N, 42, 6);
|
|
|
|
|
|
|
|
|
|
//Tipo record I
|
|
|
|
|
add_field("I.NDOC", T_N, 1, 6);
|
|
|
|
|
add_field("I.DATADOC", T_N, 7, 8);
|
|
|
|
|
add_field("I.NPART", T_N, 15, 6);
|
|
|
|
|
add_field("I.TIPOMOV", T_X, 21, 1);
|
|
|
|
|
add_field("I.SEZIONE", T_X, 22, 1);
|
|
|
|
|
add_field("I.IMPONIBILE", T_X, 23, 13);
|
|
|
|
|
add_field("I.IMPOSTA", T_X, 36, 11);
|
|
|
|
|
add_field("I.CODIVA", T_N, 47, 4);
|
|
|
|
|
add_field("I.CODMASTRO", T_N, 36, 6);
|
|
|
|
|
add_field("I.CODCONTO", T_N, 42, 6);
|
|
|
|
|
|
|
|
|
|
//Tipo record R
|
|
|
|
|
add_field("R.NDOC", T_N, 1, 6);
|
|
|
|
|
add_field("R.DATADOC", T_N, 7, 8);
|
|
|
|
|
add_field("R.NPART", T_N, 15, 6);
|
|
|
|
|
add_field("R.TIPOMOV", T_X, 21, 1);
|
|
|
|
|
add_field("R.NRATA", T_N, 22, 6);
|
|
|
|
|
add_field("R.IMPRATA", T_X, 28, 13);
|
|
|
|
|
add_field("R.TIPORATA", T_X, 41, 1);
|
|
|
|
|
add_field("R.DATASCAD", T_N, 42, 8);
|
|
|
|
|
|
|
|
|
|
TText_recordset::load_file(filename);
|
2010-11-25 14:58:06 +00:00
|
|
|
|
}
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
////////////////////////////////
|
|
|
|
|
//// TIMPORTA_FAT_MSK ////
|
|
|
|
|
////////////////////////////////
|
|
|
|
|
|
|
|
|
|
//Classe TImporta_fat_msk
|
2010-11-25 08:52:50 +00:00
|
|
|
|
class TImporta_fat_msk : public TAutomask
|
|
|
|
|
{
|
|
|
|
|
protected:
|
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
TImporta_fat_msk();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TImporta_fat_msk::TImporta_fat_msk() :TAutomask ("lv4500a")
|
2010-11-29 15:44:14 +00:00
|
|
|
|
{}
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
bool TImporta_fat_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
2010-11-29 15:44:14 +00:00
|
|
|
|
{
|
2010-11-25 08:52:50 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
////////////////////////////////
|
|
|
|
|
//// TIMPORTA_FAT_APP ////
|
|
|
|
|
////////////////////////////////
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//Classe TImporta_fat_app
|
2010-11-25 08:52:50 +00:00
|
|
|
|
class TImporta_fat_app : public TSkeleton_application
|
|
|
|
|
{
|
2010-11-25 14:58:06 +00:00
|
|
|
|
TImporta_fat_msk* _msk;
|
|
|
|
|
TDecodifica_codici* _codici;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
bool search_gr_sp_ca(const int gruppo, const char* specie, const int categoria);
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
const TFilename crea_tmpdir() const;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const TFilename crea_nomefile(const long ndoc) const;
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
const int segno_testata(const char sezione, const TCausale& cau) const;
|
|
|
|
|
const int segno_riga(const char sezione, const TCausale& cau) const;
|
|
|
|
|
const TString16 genera_real(const TVariant importo, const int segno = 1) const;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
const TString80 riclassifica_pconti();
|
2010-11-25 14:58:06 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TConfig* genera_testata(TImporta_fat_rec& recset, TFilename& tmpdir);
|
2010-11-30 08:27:00 +00:00
|
|
|
|
void genera_righe_iva(TImporta_fat_rec& recset, TConfig& conf, int nriga, const TString& codcau);
|
2010-11-29 15:44:14 +00:00
|
|
|
|
void genera_rate(TImporta_fat_rec& recset, TConfig& conf, int nriga);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
void elabora_file(const TFilename& tmpdir);
|
|
|
|
|
void elimina_file(const TFilename& tmpdir);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
virtual bool create();
|
|
|
|
|
virtual bool destroy();
|
|
|
|
|
virtual void main_loop();
|
|
|
|
|
void transfer(const TFilename& file);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool TImporta_fat_app::search_gr_sp_ca(const int gruppo, const char* specie, const int categoria)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//CREA_TMPDIR: crea la directory temporanea e restituisce il suo nome
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const TFilename TImporta_fat_app::crea_tmpdir() const
|
|
|
|
|
{
|
|
|
|
|
TFilename tmpdir;
|
|
|
|
|
tmpdir.tempdir();
|
|
|
|
|
tmpdir.add("fatture");
|
|
|
|
|
make_dir(tmpdir);
|
|
|
|
|
|
|
|
|
|
return tmpdir;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//CREA_NOMEFILE: genera il nome del file dal numero documento
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const TFilename TImporta_fat_app::crea_nomefile(const long ndoc) const
|
|
|
|
|
{
|
|
|
|
|
TString strname;
|
2010-11-29 15:44:14 +00:00
|
|
|
|
strname.format("%06ld", ndoc);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
strname << ".ini";
|
|
|
|
|
|
|
|
|
|
return strname;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//SEGNO_TESTATA: restituisce + o - uno a seconda che la sezione della riga in esame
|
|
|
|
|
//e quella della prima riga della causale siano uguali o opposte
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const int TImporta_fat_app::segno_testata(const char sezione, const TCausale& cau) const
|
|
|
|
|
{
|
|
|
|
|
return cau.sezione_clifo() == sezione ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//SEGNO_TESTATA: restituisce + o - uno a seconda che la sezione della riga in esame
|
|
|
|
|
//e quella della prima riga della causale siano opposte o uguali
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const int TImporta_fat_app::segno_riga(const char sezione, const TCausale& cau) const
|
|
|
|
|
{
|
|
|
|
|
return cau.sezione_clifo() == sezione ? -1 : 1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//GENERA_REAL: crea il numero reale, aggiungendo i decimali e tenendo conto del segno corretto
|
2010-11-25 08:52:50 +00:00
|
|
|
|
const TString16 TImporta_fat_app::genera_real(const TVariant importo, const int segno) const
|
|
|
|
|
{
|
|
|
|
|
real imp = importo.as_real();
|
|
|
|
|
imp /= CENTO;
|
|
|
|
|
imp *= segno;
|
|
|
|
|
return imp.string();
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 14:58:06 +00:00
|
|
|
|
//GENERA_TESTATA: genero il paragrafo testata
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TConfig* TImporta_fat_app::genera_testata(TImporta_fat_rec& recset, TFilename& tmpdir)
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const long ndoc = recset.get("C.NDOC").as_int();
|
|
|
|
|
const TDate datadoc = recset.get("C.DATADOC").as_date();
|
|
|
|
|
const TCausale cau(recset.get("C.CODCAU").as_string());
|
|
|
|
|
const int segno = segno_testata(recset.get("C.SEZIONE").as_string()[0], cau);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-25 11:11:48 +00:00
|
|
|
|
TFilename nomefile = tmpdir;
|
2010-11-29 15:44:14 +00:00
|
|
|
|
nomefile << '\\' << crea_nomefile(ndoc);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TConfig* conf = new TConfig(nomefile);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
conf->set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini
|
|
|
|
|
conf->set("Action","INSERT");
|
|
|
|
|
conf->set("Mode", "AUTO");
|
|
|
|
|
|
|
|
|
|
TString paragraph;
|
|
|
|
|
paragraph.format("%d", LF_MOV);
|
|
|
|
|
conf->set_paragraph(paragraph); //setto il paragrafo [23] del file ini (testata)
|
|
|
|
|
conf->set(MOV_ANNOES, datadoc.year());
|
|
|
|
|
conf->set(MOV_DATAREG, datadoc);
|
|
|
|
|
conf->set(MOV_DATACOMP, datadoc);
|
|
|
|
|
conf->set(MOV_DATADOC, datadoc);
|
|
|
|
|
conf->set(MOV_NUMDOC, ndoc);
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf->set(MOV_CODCAUS, _msk->get_bool(F_DECCAU) ? atol(_codici->decodifica_causali(recset.get("C.CODCAU").as_int())) : recset.get("C.CODCAU").as_int());
|
2010-11-25 08:52:50 +00:00
|
|
|
|
conf->set(MOV_ANNOIVA, datadoc.year());
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf->set(MOV_REG, _codici->decodifica_regiva(recset.get("C.REGIVA").as_int()));
|
|
|
|
|
conf->set(MOV_PROTIVA, recset.get("C.NREGIVA").as_int());
|
|
|
|
|
conf->set(MOV_CODVAL, _msk->get_bool(F_DECVAL) ? _codici->decodifica_valute(recset.get("C.CODVAL").as_int()) : recset.get("C.CODVAL").as_string());
|
2010-11-25 08:52:50 +00:00
|
|
|
|
conf->set(MOV_TIPO, 'C');
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf->set(MOV_CODCF, recset.get("C.CODCF").as_int());
|
|
|
|
|
conf->set(MOV_TOTDOC, genera_real(recset.get("C.IMPORTO"), segno));
|
|
|
|
|
conf->set(MOV_CODPAG, _msk->get_bool(F_DECCDP) ? atol(_codici->decodifica_condpag(recset.get("C.CODPAG").as_int())) : recset.get("C.CODPAG").as_int());
|
|
|
|
|
|
|
|
|
|
return conf;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 14:58:06 +00:00
|
|
|
|
//GENERA_RIGHE_IVA: genero le righe IVA
|
2010-11-30 08:27:00 +00:00
|
|
|
|
void TImporta_fat_app::genera_righe_iva(TImporta_fat_rec& recset, TConfig& conf, int nriga, const TString& codcau)
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const TDate datadoc = recset.get("I.DATADOC").as_date();
|
2010-11-30 08:27:00 +00:00
|
|
|
|
const char sezione = recset.get("I.SEZIONE").as_string()[0];
|
|
|
|
|
const TCausale cau(codcau);
|
|
|
|
|
const int segno = segno_riga(sezione, cau);
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const TBill& conto = _codici->decodifica_conto(recset.get("I.CODMASTRO").as_int(), recset.get("I.CODCONTO").as_int());
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
TString paragraph;
|
2010-11-30 08:27:00 +00:00
|
|
|
|
paragraph.format("%d,%d", LF_RMOVIVA, ++nriga);
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf.set_paragraph(paragraph);
|
|
|
|
|
|
|
|
|
|
conf.set(RMI_ANNOES, datadoc.year());
|
|
|
|
|
conf.set(RMI_CODIVA, _msk->get_bool(F_DECCODIVA) ? atol(_codici->decodifica_codiva(recset.get("I.CODIVA").as_int())) : recset.get("I.CODIVA").as_int());
|
|
|
|
|
conf.set(RMI_IMPONIBILE, genera_real(recset.get("I.IMPONIBILE"), segno));
|
2010-11-30 08:27:00 +00:00
|
|
|
|
conf.set(RMI_IMPOSTA, genera_real(recset.get("I.IMPOSTA"), segno));
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf.set(RMI_GRUPPO, conto.gruppo());
|
|
|
|
|
conf.set(RMI_CONTO, conto.conto());
|
|
|
|
|
conf.set(RMI_SOTTOCONTO, conto.sottoconto());
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 14:58:06 +00:00
|
|
|
|
//GENERA_RATE: genero le righe su SCAD
|
2010-11-29 15:44:14 +00:00
|
|
|
|
void TImporta_fat_app::genera_rate(TImporta_fat_rec& recset, TConfig& conf, int nriga)
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
2010-11-25 11:11:48 +00:00
|
|
|
|
TString paragraph;
|
2010-11-30 08:27:00 +00:00
|
|
|
|
paragraph.format("%d,%d", LF_RMOVIVA, ++nriga);
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf.set_paragraph(paragraph);
|
2010-11-25 11:11:48 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
const TDate datadoc = recset.get("R.DATADOC").as_date();
|
2010-11-25 11:11:48 +00:00
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf.set(SCAD_ANNO, datadoc.year());
|
|
|
|
|
conf.set(SCAD_NUMPART, recset.get("R.NPART").as_int());
|
|
|
|
|
conf.set(SCAD_NRIGA, nriga);
|
|
|
|
|
conf.set(SCAD_NRATA, recset.get("R.NRATA").as_int());
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//??? CODPAG ???//
|
2010-11-29 15:44:14 +00:00
|
|
|
|
conf.set(SCAD_TIPOPAG, recset.get("R.TIPOPAG").as_int());
|
|
|
|
|
conf.set(SCAD_IMPORTO, genera_real(recset.get("R.IMPORTO")));
|
|
|
|
|
conf.set(SCAD_IMPORTOVAL, genera_real(recset.get("R.IMPORTO"))); //NON SO IN QUALE DEI DUE VADA
|
|
|
|
|
conf.set(SCAD_DATASCAD, recset.get("R.DATASCAD").as_date());
|
2010-11-25 11:11:48 +00:00
|
|
|
|
//??? ABI CAB GRUPPO CONTO SOTTOCONTO ???//
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 14:58:06 +00:00
|
|
|
|
//ELABORA_FILE: chiamo la prima nota su tutti gli ini che ho generato
|
2010-11-25 08:52:50 +00:00
|
|
|
|
void TImporta_fat_app::elabora_file(const TFilename& tmpdir)
|
|
|
|
|
{
|
|
|
|
|
TString app;
|
|
|
|
|
app << "cg2 -0 -i" << tmpdir << "/*.ini";
|
|
|
|
|
TExternal_app primanota(app);
|
|
|
|
|
primanota.run(true);
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-25 14:58:06 +00:00
|
|
|
|
//ELIMINA_FILE: elimino tutti i file che ho elaborato DA IMPLEMENTARE
|
2010-11-25 08:52:50 +00:00
|
|
|
|
void TImporta_fat_app::elimina_file(const TFilename& tmpdir)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TImporta_fat_app::transfer(const TFilename& file)
|
|
|
|
|
{
|
|
|
|
|
TImporta_fat_rec recset(file);
|
|
|
|
|
|
|
|
|
|
TConfig* configfile = NULL;
|
|
|
|
|
|
|
|
|
|
TFilename tmpdir = crea_tmpdir();
|
|
|
|
|
|
|
|
|
|
int nrigai, nrigar;
|
2010-11-25 11:11:48 +00:00
|
|
|
|
|
|
|
|
|
TProgind pi(recset.items(), "Importazione in corso...", true, true);
|
2010-11-30 08:27:00 +00:00
|
|
|
|
TString16 codcau;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
for(bool ok = recset.move_first(); ok; ok = recset.move_next())
|
|
|
|
|
{
|
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
|
break;
|
|
|
|
|
|
2010-11-30 08:27:00 +00:00
|
|
|
|
const char tipomov = recset.get("TIPOMOV").as_string()[0];
|
2010-11-25 08:52:50 +00:00
|
|
|
|
|
|
|
|
|
switch(tipomov)
|
|
|
|
|
{
|
2010-11-29 15:44:14 +00:00
|
|
|
|
case 'C':
|
|
|
|
|
{
|
|
|
|
|
if(configfile != NULL)
|
|
|
|
|
delete configfile;
|
2010-11-30 08:27:00 +00:00
|
|
|
|
codcau = recset.get("C.CODCAU").as_string();
|
2010-11-29 15:44:14 +00:00
|
|
|
|
configfile = genera_testata(recset, tmpdir); nrigai = nrigar = 0;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2010-11-30 08:27:00 +00:00
|
|
|
|
case 'I':
|
|
|
|
|
genera_righe_iva(recset, *configfile, nrigai, codcau);
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
genera_rate(recset, *configfile, nrigar);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2010-11-25 08:52:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-11-29 15:44:14 +00:00
|
|
|
|
if(configfile != NULL)
|
|
|
|
|
delete configfile;
|
|
|
|
|
|
2010-11-25 08:52:50 +00:00
|
|
|
|
elabora_file(tmpdir);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TImporta_fat_app::create()
|
|
|
|
|
{
|
2010-11-25 14:58:06 +00:00
|
|
|
|
_msk = new TImporta_fat_msk();
|
|
|
|
|
_codici = new TDecodifica_codici();
|
2010-11-25 08:52:50 +00:00
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TImporta_fat_app::destroy()
|
|
|
|
|
{
|
|
|
|
|
delete _msk;
|
|
|
|
|
return TApplication::destroy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TImporta_fat_app::main_loop()
|
|
|
|
|
{
|
2010-11-30 08:27:00 +00:00
|
|
|
|
if ( _msk->run() == K_ENTER)
|
2010-11-25 08:52:50 +00:00
|
|
|
|
{
|
|
|
|
|
//genero il nome del file da caricare
|
2010-11-29 15:44:14 +00:00
|
|
|
|
TFilename file = _msk->get(F_NAME);
|
2010-11-25 08:52:50 +00:00
|
|
|
|
if(!file.exist())
|
|
|
|
|
{
|
|
|
|
|
error_box(TR("Il file selezionato non esiste; si prega di controllare"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
transfer(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int lv4500 (int argc, char* argv[])
|
|
|
|
|
{
|
|
|
|
|
TImporta_fat_app main_app;
|
|
|
|
|
main_app.run(argc, argv, TR("Importazione fatture COGECO"));
|
|
|
|
|
return true;
|
|
|
|
|
}
|