2009-04-17 07:45:43 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <automask.h>
|
|
|
|
#include <execp.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <textset.h>
|
|
|
|
#include <recarray.h>
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
#include <rcausali.h>
|
|
|
|
#include <clifo.h>
|
|
|
|
#include <mov.h>
|
|
|
|
#include <rmov.h>
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
#include "tabutil.h"
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
#include "../ca/calib01.h"
|
|
|
|
#include "../ca/calib02.h"
|
|
|
|
#include "../ca/movana.h"
|
|
|
|
#include "../ca/rmovana.h"
|
|
|
|
|
2009-04-17 07:45:43 +00:00
|
|
|
#include "ps0713500a.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
//////////////////////////////////////
|
|
|
|
//// TIMPORTA_SPESE_ANROW ////
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
//classe TImporta_spese_anrow
|
|
|
|
class TImporta_spese_anrow: public TToken_string
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
const long idlavoro();
|
|
|
|
const int gruppo();
|
|
|
|
const int conto();
|
|
|
|
const int sotco();
|
|
|
|
|
|
|
|
TImporta_spese_anrow& operator= (const char* key){ set(key); return *this; }
|
|
|
|
|
|
|
|
TImporta_spese_anrow(const long idlavoro, const int gruppo, const int conto, const int sotco);
|
|
|
|
TImporta_spese_anrow(const char* key):TToken_string(key){}
|
|
|
|
TImporta_spese_anrow(const TToken_string& key):TToken_string(key){}
|
|
|
|
TImporta_spese_anrow(const TImporta_spese_anrow& key):TToken_string(key){}
|
|
|
|
TImporta_spese_anrow():TToken_string(){}
|
|
|
|
};
|
|
|
|
|
|
|
|
//IDLAVORO: metodo che restituisce l'Idlavoro
|
|
|
|
const long TImporta_spese_anrow::idlavoro()
|
|
|
|
{
|
|
|
|
return get_long(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
//GRUPPO: metodo che restituisce il gruppo
|
|
|
|
const int TImporta_spese_anrow::gruppo()
|
|
|
|
{
|
|
|
|
return get_int(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
//CONTO: metodo che restituisce il conto
|
|
|
|
const int TImporta_spese_anrow::conto()
|
|
|
|
{
|
|
|
|
return get_int(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
//SOTCO: metodo che restituisce il sottoconto
|
|
|
|
const int TImporta_spese_anrow::sotco()
|
|
|
|
{
|
|
|
|
return get_int(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
//metodo costruttore
|
|
|
|
TImporta_spese_anrow::TImporta_spese_anrow(const long idlavoro, const int gruppo, const int conto, const int sotco)
|
|
|
|
{
|
|
|
|
add(idlavoro);
|
|
|
|
add(gruppo);
|
|
|
|
add(conto);
|
|
|
|
add(sotco);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////
|
|
|
|
//// TIMPORTA_SPESE_MSK ////
|
|
|
|
//////////////////////////////////
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
//Clase TImporta_spese_msk
|
|
|
|
class TImporta_spese_msk : public TAutomask
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
public:
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_msk(const char* name);
|
2009-04-17 07:45:43 +00:00
|
|
|
};
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_msk::TImporta_spese_msk(const char* name)
|
|
|
|
:TAutomask (name) {}
|
|
|
|
|
|
|
|
//ON_FIELD_EVENT: metodo che gestisce i comportamenti dei vari campi della maschera
|
|
|
|
//(per adesso segnaposto)
|
|
|
|
bool TImporta_spese_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
//////////////////////////////////
|
|
|
|
//// TIMPORTA_SPESE_REC ////
|
|
|
|
//////////////////////////////////
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
//Clase TImporta_spese_rec
|
|
|
|
class TImporta_spese_rec : public TCSV_recordset
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual TRecnotype new_rec(const char* buf = NULL);
|
|
|
|
|
|
|
|
public:
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_rec(const char * fileName);
|
2009-04-17 07:45:43 +00:00
|
|
|
};
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TRecnotype TImporta_spese_rec::new_rec(const char* buf)
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
TToken_string str(256,'\t'); //nuovo record tab separator
|
|
|
|
|
|
|
|
if(buf && *buf)
|
|
|
|
{
|
|
|
|
bool apici=false;
|
|
|
|
|
|
|
|
for (const char* c = buf; *c ; c++)
|
|
|
|
{
|
|
|
|
if (*c == '"')
|
|
|
|
{
|
|
|
|
apici = !apici;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (*c == ',')
|
|
|
|
{
|
|
|
|
if (!apici)
|
|
|
|
str << str.separator();
|
|
|
|
else
|
|
|
|
str << *c;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
str << *c;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const TRecnotype n = TText_recordset::new_rec(str);
|
|
|
|
|
|
|
|
if (n >= 0)
|
|
|
|
row(n).separator(str.separator());
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_rec::TImporta_spese_rec(const char * fileName)
|
2009-04-17 07:45:43 +00:00
|
|
|
: TCSV_recordset("CSV(,)")
|
|
|
|
{
|
|
|
|
load_file(fileName);
|
|
|
|
}
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
//////////////////////////////////
|
|
|
|
//// TIMPORTA_SPESE_APP ////
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
//Classe TImporta_spese_app
|
|
|
|
class TImporta_spese_app : public TSkeleton_application
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_msk* _msk;
|
|
|
|
protected:
|
|
|
|
virtual bool check_autorization() const {return false;}
|
2009-04-17 07:45:43 +00:00
|
|
|
virtual const char * extra_modules() const {return "ve";}
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
void chiudi_movimento(TConfig& configfile, TImporto& tot_doc, TDate& data, const long numreg, TAssoc_array& righean);
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
virtual void main_loop();
|
2010-05-12 15:14:54 +00:00
|
|
|
long genera_movcg();
|
|
|
|
void genera_movana(const long numreg, TAssoc_array& righean);
|
|
|
|
bool transfer();
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_app() {};
|
2009-04-17 07:45:43 +00:00
|
|
|
};
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
const char* const nomeini = "ps0713500ats.ini";
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
void TImporta_spese_app::chiudi_movimento(TConfig& configfile, TImporto& tot_doc, TDate& data, const long numreg, TAssoc_array& righean)
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
2010-05-12 15:14:54 +00:00
|
|
|
genera_movana(numreg, righean);
|
2009-04-17 07:45:43 +00:00
|
|
|
//aggiungo i campi che mancano in testata
|
|
|
|
configfile.set_paragraph("23");
|
|
|
|
configfile.set(MOV_DATAREG, data);
|
|
|
|
configfile.set(MOV_DATADOC, data);
|
|
|
|
configfile.set(MOV_DATACOMP, data);
|
|
|
|
|
|
|
|
tot_doc.normalize();
|
|
|
|
|
|
|
|
//aggiungo la prima riga che bilancia le righe successive
|
|
|
|
TString8 paragraph;
|
|
|
|
paragraph.format("%d,%d",LF_RMOV,1);
|
|
|
|
configfile.set_paragraph(paragraph);
|
|
|
|
configfile.set(RMV_IMPORTO,tot_doc.valore().string());
|
|
|
|
configfile.set(RMV_SEZIONE,tot_doc.sezione());
|
|
|
|
|
|
|
|
configfile.set_paragraph("Transaction");
|
|
|
|
|
|
|
|
TString app;
|
|
|
|
app << "cg2 -0 -i" << nomeini;
|
|
|
|
TExternal_app primanota(app);
|
|
|
|
primanota.run();
|
|
|
|
}
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
long TImporta_spese_app::genera_movcg()
|
|
|
|
{
|
|
|
|
TISAM_recordset movrec("USE MOV");
|
|
|
|
movrec.move_last();
|
|
|
|
long numreg = movrec.get(MOV_NUMREG).as_int(); numreg++;
|
|
|
|
|
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
|
|
mov.put(MOV_NUMREG, numreg);
|
|
|
|
mov.rewrite();
|
|
|
|
|
|
|
|
return numreg;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TImporta_spese_app::genera_movana(const long numreg, TAssoc_array& righean)
|
|
|
|
{
|
|
|
|
TProgind pi(righean.items(), "Importazione analitica in corso...", true, true);
|
|
|
|
|
|
|
|
const TDate datareg(TODAY);
|
|
|
|
const int anno = datareg.year();
|
|
|
|
|
|
|
|
TToken_string key;
|
|
|
|
key.add(_msk->get(F_CODCAU));
|
|
|
|
key.add(1);
|
|
|
|
key.add(1);
|
|
|
|
const TRectype& causale = cache().get(LF_RCAUSALI, key);
|
|
|
|
|
|
|
|
//instanzio il movimento di analitica
|
|
|
|
TAnal_mov anmo(0);
|
|
|
|
anmo.put(MOVANA_NUMREGCG, numreg);
|
|
|
|
anmo.put(MOVANA_DATACOMP, datareg);
|
|
|
|
anmo.put(MOVANA_DATAREG, datareg);
|
|
|
|
anmo.put(MOVANA_CODCAUS, _msk->get(F_CODCAU));
|
|
|
|
anmo.put(MOVANA_ANNOES, anno);
|
|
|
|
|
|
|
|
//per ogni oggetto dell'assoc_array, creo una riga di analitica
|
|
|
|
FOR_EACH_ASSOC_OBJECT(righean, obj, keyar, itm)
|
|
|
|
{
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
break;
|
|
|
|
|
|
|
|
TImporta_spese_anrow& row = (TImporta_spese_anrow)keyar;
|
|
|
|
const long idlav = row.idlavoro();
|
|
|
|
const int gruppo = row.gruppo(); TString8 grup; grup.format("%03d", gruppo);
|
|
|
|
const int conto = row.conto(); TString8 cont; cont.format("%03d", conto);
|
|
|
|
const int sotco = row.sotco(); TString16 sotc; sotc.format("%06ld", sotco);
|
|
|
|
TString80 codconto; codconto << grup << cont << sotc;
|
|
|
|
|
|
|
|
real& imp = *(real*)itm; imp.round(2);
|
|
|
|
|
|
|
|
if (!imp.is_zero())
|
|
|
|
{
|
|
|
|
TImporto importo('D', imp);
|
|
|
|
importo.normalize();
|
|
|
|
|
|
|
|
TRectype& ranmo = anmo.new_row();
|
|
|
|
ranmo.put(RMOVANA_ANNOES, anno);
|
|
|
|
ranmo.put(RMOVANA_SEZIONE, causale.get("SEZIONE"));
|
|
|
|
ranmo.put(RMOVANA_CODCONTO, codconto);
|
|
|
|
ranmo.put(RMOVANA_CODCMS, idlav);
|
|
|
|
ranmo.put(RMOVANA_IMPORTO, importo.valore().string());
|
|
|
|
ranmo.put(RMOVANA_SEZIONE, importo.sezione());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TImporta_spese_app::transfer()
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
//genero il nome del file da caricare
|
2010-05-12 15:14:54 +00:00
|
|
|
TFilename name = _msk->get(F_PATH);
|
|
|
|
name.add(_msk->get(F_NAME));
|
|
|
|
TImporta_spese_rec s(name);
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
TProgind pi(s.items(),"Importazione spese in corso ...",true,true);
|
|
|
|
|
|
|
|
xvt_fsys_removefile(nomeini);
|
|
|
|
TConfig configfile (nomeini, "Transaction"); //setto il paragrafo [Transaction] del file ini
|
|
|
|
|
|
|
|
TDate dataold, data;
|
|
|
|
|
|
|
|
int nriga = 2;
|
|
|
|
TImporto tot_doc;
|
2010-05-12 15:14:54 +00:00
|
|
|
TAssoc_array righean;
|
|
|
|
long numreg;
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
const TRectype& causale = cache().get(LF_RCAUSALI, _msk->get(F_CODCAU));
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
for (bool ok = s.move_first(); ok; ok = s.move_next())
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
break;
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TString80 tmp;
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
//importo
|
|
|
|
tmp = s.get(2).as_string();
|
|
|
|
|
|
|
|
//evito di analizzare eventuali righe vuote
|
|
|
|
if (tmp.blank())
|
|
|
|
continue;
|
|
|
|
|
|
|
|
tmp.replace(',','.');
|
|
|
|
tmp.strip("\"");
|
|
|
|
const real imp = tmp;
|
|
|
|
|
|
|
|
if (!imp.is_zero())
|
|
|
|
{
|
|
|
|
|
|
|
|
//codice commessa
|
|
|
|
tmp = s.get(0).as_string();
|
|
|
|
tmp.strip("\"");
|
2010-05-12 15:14:54 +00:00
|
|
|
const TString80 codcms = tmp;
|
2009-04-17 07:45:43 +00:00
|
|
|
const TRectype& commessa = cache().get("CMS", tmp);
|
|
|
|
|
|
|
|
//data
|
|
|
|
tmp = s.get(1).as_string();
|
|
|
|
tmp.strip("\"");
|
|
|
|
|
|
|
|
data.set_day(atoi(tmp.mid(0,2)));
|
|
|
|
data.set_month(atoi(tmp.mid(3,2)));
|
|
|
|
data.set_year(atoi(tmp.mid(6,4)));
|
|
|
|
|
|
|
|
//descrizione
|
|
|
|
tmp = s.get(3).as_string();
|
|
|
|
tmp.strip("\"");
|
|
|
|
|
|
|
|
if(data != dataold)
|
|
|
|
{
|
|
|
|
if (dataold.ok())
|
2010-05-12 15:14:54 +00:00
|
|
|
chiudi_movimento(configfile, tot_doc, data, numreg, righean);
|
|
|
|
|
|
|
|
numreg = genera_movcg();
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
TFilename filename(nomeini);
|
|
|
|
filename.fremove();
|
|
|
|
|
|
|
|
configfile.set_paragraph("Transaction");
|
2010-05-12 15:14:54 +00:00
|
|
|
configfile.set("Action","MODIFY");
|
2009-04-17 07:45:43 +00:00
|
|
|
configfile.set("Mode","AUTO");
|
|
|
|
|
|
|
|
configfile.set_paragraph("23"); //setto il paragrafo [23] del file ini (testata)
|
2010-05-12 15:14:54 +00:00
|
|
|
configfile.set(MOV_NUMREG, numreg);
|
2009-04-17 07:45:43 +00:00
|
|
|
configfile.set(MOV_CODCAUS, causale.get(RCA_CODCAUS));
|
|
|
|
|
|
|
|
configfile.set_paragraph("24,1");
|
|
|
|
configfile.set(RMV_NUMRIG,1);
|
|
|
|
configfile.set(RMV_GRUPPO, causale.get(RCA_GRUPPO));
|
|
|
|
configfile.set(RMV_CONTO, causale.get(RCA_CONTO));
|
|
|
|
configfile.set(RMV_SOTTOCONTO, causale.get(RCA_SOTTOCONTO));
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
righean.destroy();
|
|
|
|
tot_doc.reset();
|
2009-04-17 07:45:43 +00:00
|
|
|
nriga = 2;
|
|
|
|
dataold = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
TImporto importo('D', imp);
|
|
|
|
importo.normalize();
|
|
|
|
tot_doc -= importo;
|
|
|
|
|
|
|
|
TString8 paragraph;
|
|
|
|
paragraph.format("%d,%d",LF_RMOV,nriga++);
|
|
|
|
configfile.set_paragraph(paragraph);
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
configfile.set(RMV_IMPORTO, importo.valore().string());
|
|
|
|
configfile.set(RMV_SEZIONE, importo.sezione());
|
|
|
|
configfile.set(RMV_CODCMS, commessa.get("CODTAB"));
|
|
|
|
configfile.set(RMV_DATAREG, data);
|
|
|
|
configfile.set(RMV_GRUPPO, commessa.get("I1"));
|
|
|
|
configfile.set(RMV_CONTO, commessa.get("I2"));
|
|
|
|
configfile.set(RMV_SOTTOCONTO, commessa.get("I3"));
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_anrow ankey(commessa.get_long("CODTAB"), commessa.get_int("I1"), commessa.get_int("I2"), commessa.get_int("I3"));
|
|
|
|
if(righean.is_key(ankey))
|
|
|
|
{
|
|
|
|
real& imponibile = *(real*)righean.objptr(ankey);
|
|
|
|
imponibile += importo.valore();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
righean.add(ankey, importo.valore());
|
|
|
|
}
|
2009-04-17 07:45:43 +00:00
|
|
|
}
|
2010-05-12 15:14:54 +00:00
|
|
|
chiudi_movimento(configfile, tot_doc, data, numreg, righean);
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
void TImporta_spese_app::main_loop()
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
2010-05-12 15:14:54 +00:00
|
|
|
_msk = new TImporta_spese_msk("ps0713500a");
|
2009-04-17 07:45:43 +00:00
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
if (_msk->run() == K_ENTER)
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
2010-05-12 15:14:54 +00:00
|
|
|
if (transfer())
|
2009-04-17 07:45:43 +00:00
|
|
|
{
|
|
|
|
message_box(TR("Importazione spese completata"));
|
|
|
|
xvt_fsys_removefile(nomeini);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_app& app() { return (TImporta_spese_app&) main_app(); }
|
2009-04-17 07:45:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
int ps0713500 (int argc, char* argv[])
|
|
|
|
{
|
2010-05-12 15:14:54 +00:00
|
|
|
TImporta_spese_app main_app;
|
2009-04-17 07:45:43 +00:00
|
|
|
main_app.run(argc, argv, TR("Importazione Spese"));
|
|
|
|
return true;
|
|
|
|
}
|