Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@20511 c028cbd2-c16b-5b4b-a496-9718f37d4682
291 lines
8.0 KiB
C++
Executable File
291 lines
8.0 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <execp.h>
|
|
#include <progind.h>
|
|
#include <tabutil.h>
|
|
|
|
#include <causali.h>
|
|
#include <clifo.h>
|
|
#include <mov.h>
|
|
#include <rmov.h>
|
|
#include <rmoviva.h>
|
|
|
|
#include "ps0713lib.h"
|
|
|
|
#include "../ca/calib01.h"
|
|
#include "../ca/calib02.h"
|
|
#include "../ca/movana.h"
|
|
#include "../ca/rmovana.h"
|
|
|
|
#include "ps0713300a.h"
|
|
|
|
///////////////////////////////////
|
|
//// TIMPORTA_FATACQ_MSK ////
|
|
///////////////////////////////////
|
|
|
|
//Classe TImporta_fatacq_msk
|
|
class TImporta_fatacq_msk : public TAutomask
|
|
{
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TImporta_fatacq_msk();
|
|
};
|
|
|
|
TImporta_fatacq_msk::TImporta_fatacq_msk() :TAutomask ("ps0713300a")
|
|
{
|
|
}
|
|
|
|
//ON_FIELD_EVENT: metodo che gestisce i comportamenti dei vari campi della maschera
|
|
//(per adesso segnaposto)
|
|
bool TImporta_fatacq_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
{
|
|
return true;
|
|
}
|
|
///////////////////////////////////
|
|
//// TIMPORTA_FATACQ_APP ////
|
|
///////////////////////////////////
|
|
|
|
//Classe TImporta_fatacq_app
|
|
class TImporta_fatacq_app : public TSkeleton_application
|
|
{
|
|
TImporta_fatacq_msk* _msk;
|
|
TConfig* _configfile;
|
|
|
|
protected:
|
|
virtual bool check_autorization() const {return false;}
|
|
virtual const char * extra_modules() const {return "ve";}
|
|
|
|
public:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
long genera_movcg();
|
|
void genera_analitica(const long numreg, TAssoc_array& righean);
|
|
bool transfer(const TFilename& file, const long numreg, TAssoc_array& righean);
|
|
|
|
TImporta_fatacq_app() {};
|
|
};
|
|
|
|
long TImporta_fatacq_app::genera_movcg()
|
|
{
|
|
TISAM_recordset movrec("USE MOV");
|
|
movrec.move_last();
|
|
long numreg = movrec.cursor()->curr().get_int(MOV_NUMREG); numreg++;
|
|
|
|
TLocalisamfile mov(LF_MOV);
|
|
mov.put(MOV_NUMREG, numreg);
|
|
mov.put(MOV_DATACOMP, _msk->get_date(F_DATAREG));
|
|
mov.put(MOV_DATAREG, _msk->get_date(F_DATAREG));
|
|
mov.put(MOV_CODCAUS, _msk->get(F_CODCAU));
|
|
mov.write();
|
|
|
|
return numreg;
|
|
}
|
|
|
|
void TImporta_fatacq_app::genera_analitica(const long numreg, TAssoc_array& righean)
|
|
{
|
|
TProgind pi(righean.items(), "Importazione analitica in corso...", true, true);
|
|
|
|
const TDate datareg = _msk->get_date(F_DATAREG);
|
|
const int anno = _msk->get_date(F_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;
|
|
|
|
TCommessa_string& row = (TCommessa_string)keyar;
|
|
const TString& 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())
|
|
{
|
|
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, imp);
|
|
}
|
|
}
|
|
TLocalisamfile fmov(LF_MOVANA);
|
|
anmo.write(fmov);
|
|
}
|
|
|
|
bool TImporta_fatacq_app::transfer(const TFilename& file, const long numreg, TAssoc_array& righean)
|
|
{
|
|
TLocalisamfile mov(LF_MOV);
|
|
mov.put(MOV_NUMREG, numreg);
|
|
mov.remove();
|
|
|
|
TVB_recset s(file, ',');
|
|
|
|
TProgind pi(s.items(),"Importazione fatture in corso ...",true,true);
|
|
|
|
_configfile->set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini
|
|
_configfile->set("Action","INSERT");
|
|
_configfile->set("Mode","AUTO");
|
|
_configfile->set_paragraph("23"); //setto il paragrafo [23] del file ini (testata)
|
|
_configfile->set(MOV_NUMREG, numreg);
|
|
_configfile->set("SOLAIVA", "");
|
|
_configfile->set(MOV_TIPO, 'F');
|
|
_configfile->set(MOV_CODCF, _msk->get(F_CODCF));
|
|
|
|
int nriga = 1;
|
|
real totimponibile = ZERO;
|
|
real totimposta = ZERO;
|
|
const TString16 codiva = _msk->get(F_CODIVA);
|
|
const real iva = cache().get("%IVA", codiva, "R0");
|
|
const int anno = _msk->get_date(F_DATAREG).year();
|
|
|
|
TString caus = _msk->get(F_CODCAU);
|
|
|
|
_configfile->set(MOV_CODCAUS, caus);
|
|
|
|
TToken_string key(caus);
|
|
key.add("1");
|
|
const TRectype& causale = cache().get(LF_RCAUSALI, key);
|
|
|
|
for (bool ok = s.move_first(); ok; ok = s.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
TString8 paragraph;
|
|
paragraph.format("%d,%d", LF_RMOVIVA, nriga++);
|
|
_configfile->set_paragraph(paragraph);
|
|
|
|
TString16 codcom = s.get(0).as_string();
|
|
if(codcom.empty())
|
|
continue;
|
|
TString16 tmp = s.get(1).as_string();
|
|
tmp.strip(".");
|
|
tmp.replace(',', '.');
|
|
real imp(tmp); imp.round(2);
|
|
|
|
totimponibile += imp;
|
|
|
|
TCommessa cms(codcom);
|
|
TCommessa_string ankey = cms.cmsstr();
|
|
|
|
if(righean.is_key(ankey))
|
|
{
|
|
real& imponibile = *(real*)righean.objptr(ankey);
|
|
imponibile += imp;
|
|
}
|
|
else
|
|
righean.add(ankey, imp);
|
|
|
|
real rimposta = imp * iva / CENTO; rimposta.round(2);
|
|
totimposta += rimposta;
|
|
|
|
_configfile->set(RMI_ANNOES, anno);
|
|
_configfile->set(RMI_IMPONIBILE, imp.string());
|
|
_configfile->set(RMI_CODIVA, codiva);
|
|
_configfile->set(RMI_IMPOSTA, rimposta.string());
|
|
_configfile->set(RMI_GRUPPO, ankey.gruppo());
|
|
_configfile->set(RMI_CONTO, ankey.conto());
|
|
_configfile->set(RMI_SOTTOCONTO, ankey.sotco());
|
|
_configfile->set(RMI_TIPOATT, 1);
|
|
}
|
|
|
|
const real totdoc = totimponibile + totimposta;
|
|
TImporto importo(causale.get("SEZIONE")[0], totdoc);
|
|
|
|
TString8 paragraph;
|
|
paragraph.format("%d,%d", LF_RMOV, 1);
|
|
_configfile->set_paragraph(paragraph);
|
|
_configfile->set(RMV_NUMRIG, 1);
|
|
_configfile->set(RMV_ANNOES, anno);
|
|
_configfile->set(RMV_SEZIONE, causale.get("SEZIONE"));
|
|
_configfile->set(RMV_IMPORTO, importo.valore().string());
|
|
_configfile->set(RMV_GRUPPO, causale.get("GRUPPO"));
|
|
_configfile->set(RMV_CONTO, causale.get("CONTO"));
|
|
_configfile->set(RMV_SOTTOCONTO, _msk->get_long(F_CODCF));
|
|
_configfile->set(RMV_TIPOC, "F");
|
|
_configfile->set(RMV_ROWTYPE, "T");
|
|
|
|
_configfile->set_paragraph("23");
|
|
_configfile->set(MOV_TOTDOC, totdoc.string());
|
|
|
|
_configfile->set_paragraph("Transaction");
|
|
|
|
return true;
|
|
}
|
|
|
|
const char* nomeini = "ps0713300fatt.ini";
|
|
|
|
bool TImporta_fatacq_app::create()
|
|
{
|
|
xvt_fsys_removefile(nomeini);
|
|
_configfile = new TConfig(nomeini);
|
|
|
|
_msk = new TImporta_fatacq_msk();
|
|
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TImporta_fatacq_app::destroy()
|
|
{
|
|
delete _msk;
|
|
delete _configfile;
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
void TImporta_fatacq_app::main_loop()
|
|
{
|
|
KEY tasto;
|
|
tasto = _msk->run();
|
|
if (tasto == K_ENTER)
|
|
{
|
|
|
|
//genero il nome del file da caricare
|
|
TFilename name = _msk->get(F_PATH);
|
|
name.add(_msk->get(F_NAME));
|
|
TAssoc_array righean;
|
|
const long numreg = genera_movcg();
|
|
if (transfer(name, numreg, righean))
|
|
{
|
|
genera_analitica(numreg, righean);
|
|
|
|
TString app;
|
|
app << "cg2 -0 -i" << nomeini;
|
|
TExternal_app primanota(app);
|
|
primanota.run();
|
|
|
|
message_box(TR("Importazione fatture completata"));
|
|
}
|
|
}
|
|
}
|
|
|
|
TImporta_fatacq_app& app() { return (TImporta_fatacq_app&) main_app(); }
|
|
|
|
|
|
int ps0713300 (int argc, char* argv[])
|
|
{
|
|
TImporta_fatacq_app main_app;
|
|
main_app.run(argc, argv, TR("Importazione Fatture"));
|
|
return true;
|
|
} |