2005-01-11 11:01:25 +00:00
|
|
|
#include <automask.h>
|
|
|
|
#include <config.h>
|
|
|
|
#include <currency.h>
|
|
|
|
#include <execp.h>
|
|
|
|
#include <printapp.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <recarray.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
2005-03-21 16:08:20 +00:00
|
|
|
#include "velib.h"
|
|
|
|
|
2005-01-11 11:01:25 +00:00
|
|
|
#include "ve7.h"
|
|
|
|
#include "ve7600a.h"
|
|
|
|
|
|
|
|
#include <..\pr\agenti.h>
|
|
|
|
#include <..\mg\anamag.h>
|
|
|
|
#include <clifo.h>
|
|
|
|
#include <cfven.h>
|
|
|
|
#include <comuni.h>
|
|
|
|
#include <doc.h>
|
|
|
|
#include <rdoc.h>
|
|
|
|
|
|
|
|
#define ALIAS_TIP 201
|
|
|
|
|
|
|
|
class TRDoc2JBI_mask : public TAutomask
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRDoc2JBI_mask();
|
|
|
|
virtual ~TRDoc2JBI_mask(){};
|
|
|
|
};
|
|
|
|
|
|
|
|
TRDoc2JBI_mask::TRDoc2JBI_mask() :TAutomask ("ve7600a")
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRDoc2JBI_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
class TRDoc2JBI : public TSkeleton_application
|
|
|
|
{
|
|
|
|
TRDoc2JBI_mask* _msk;
|
|
|
|
TConfig* _config;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual bool create();
|
|
|
|
virtual bool destroy();
|
|
|
|
virtual void main_loop();
|
|
|
|
void transfer(void);
|
|
|
|
bool insert_tab(TExternisamfile& filetab, const char* tipo, const char* codice, const char* descri);
|
|
|
|
void update_tab(TExternisamfile& filetab, const TRectype rectab);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRDoc2JBI_mask& mask() { return *_msk; };
|
|
|
|
TRDoc2JBI() {};
|
|
|
|
virtual ~TRDoc2JBI() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TRDoc2JBI::create()
|
|
|
|
{
|
|
|
|
open_files(LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_CLIFO, LF_CFVEN, LF_COMUNI, LF_NDITTE, 0);
|
|
|
|
_msk = new TRDoc2JBI_mask();
|
|
|
|
_config = new TConfig("ve7600.ini");
|
|
|
|
|
|
|
|
return TSkeleton_application::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRDoc2JBI::destroy()
|
|
|
|
{
|
|
|
|
delete _config;
|
|
|
|
delete _msk;
|
|
|
|
return TSkeleton_application::destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRDoc2JBI::main_loop()
|
|
|
|
{
|
|
|
|
// preimposto i valori specificati sulla riga di comando oppure faccio partire la maschera
|
|
|
|
KEY key = K_ENTER;
|
|
|
|
if (argc() >= 4)
|
|
|
|
{
|
|
|
|
_msk->set(F_PERCORSO, argv(3));
|
|
|
|
_msk->set(F_ANNO, argv(2));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_msk->set(F_PERCORSO, _config->get("PERCORSO", "PARAMETRI"));
|
|
|
|
_msk->set(F_ANNO, _config->get("ANNO", "PARAMETRI") );
|
|
|
|
key = _msk->run();
|
|
|
|
}
|
|
|
|
if (key == K_ENTER)
|
|
|
|
transfer();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRDoc2JBI::insert_tab(TExternisamfile& filetab, const char* tipo, const char* codice, const char* descri)
|
|
|
|
{
|
2005-03-21 16:08:20 +00:00
|
|
|
int err = NOERR;
|
|
|
|
TString codstr(codice);
|
|
|
|
if (codstr.not_empty())
|
|
|
|
{
|
|
|
|
filetab.zero();
|
|
|
|
filetab.put("TIPO", tipo);
|
|
|
|
filetab.put("CODICE", codice);
|
|
|
|
|
|
|
|
TString descstr(descri);
|
|
|
|
if (descstr.not_empty())
|
|
|
|
filetab.put("DESCRI", descri);
|
|
|
|
else
|
|
|
|
filetab.put("DESCRI", "manca descrizione");
|
|
|
|
err = filetab.write();
|
|
|
|
}
|
2005-01-11 11:01:25 +00:00
|
|
|
return (err == NOERR);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRDoc2JBI::transfer()
|
|
|
|
{
|
|
|
|
TRelation rel(LF_RIGHEDOC);
|
|
|
|
rel.add(LF_DOC, "CODNUM==CODNUM|ANNO==ANNO|NDOC==NDOC|PROVV==PROVV");
|
|
|
|
rel.add("%TIP", "CODTAB==TIPODOC", 1, LF_DOC, ALIAS_TIP);
|
|
|
|
|
|
|
|
TRDoc2JBI_mask& m = mask();
|
|
|
|
|
|
|
|
TString expr;
|
|
|
|
const int anno = m.get_int(F_ANNO);
|
|
|
|
_config->set("ANNO", anno, "PARAMETRI");
|
2005-01-24 10:17:09 +00:00
|
|
|
expr.format("33->TIPOCF==\"C\"");
|
2005-01-13 14:23:42 +00:00
|
|
|
TRectype da(LF_RIGHEDOC);
|
|
|
|
da.zero();
|
|
|
|
da.put(RDOC_PROVV, 'D');
|
|
|
|
da.put(RDOC_ANNO, anno);
|
2005-01-24 10:17:09 +00:00
|
|
|
TCursor cur(&rel, "", 3, &da, &da);
|
|
|
|
cur.setfilter(expr, true);
|
2005-01-13 14:23:42 +00:00
|
|
|
|
|
|
|
const TString& path = m.get(F_PERCORSO);
|
2005-01-11 11:01:25 +00:00
|
|
|
_config->set("PERCORSO", path, "PARAMETRI");
|
|
|
|
|
|
|
|
TFilename rdocname = path;
|
|
|
|
rdocname << _config->get("RIGHEDOC", "ARCHIVI");
|
|
|
|
rdocname.ext("dbf");
|
|
|
|
TFilename rdoctrr = "jbi_rdoc.trr";
|
|
|
|
rdoctrr.custom_path();
|
|
|
|
TExternisamfile filerdoc(rdocname, rdoctrr);
|
|
|
|
filerdoc.zap();
|
|
|
|
|
|
|
|
TFilename tabname = path;
|
|
|
|
tabname << _config->get("TABELLE", "ARCHIVI");
|
|
|
|
tabname.ext("dbf");
|
|
|
|
TFilename tabtrr = "jbi_tab.trr";
|
|
|
|
tabtrr.custom_path();
|
|
|
|
TExternisamfile filetab(tabname, tabtrr);
|
|
|
|
filetab.zap();
|
|
|
|
|
|
|
|
// aggiungo il record ditta
|
|
|
|
|
|
|
|
TString80 ragsoc = cache().get(LF_NDITTE, get_firm(), "RAGSOC");
|
|
|
|
TString16 firm;
|
|
|
|
firm.format("%d", get_firm());
|
|
|
|
insert_tab(filetab, "DIT", (const char*) firm, ragsoc);
|
|
|
|
|
|
|
|
const long items = cur.items();
|
2005-01-24 10:17:09 +00:00
|
|
|
TProgind p(items, "Elaborazione righe documenti in corso ...", true, true, 10);
|
2005-01-11 11:01:25 +00:00
|
|
|
p.setstatus(1);
|
|
|
|
int err = NOERR;
|
|
|
|
for (cur=0; cur.pos()<items && !p.iscancelled() && err==NOERR; ++(cur))
|
|
|
|
{
|
2005-03-21 16:08:20 +00:00
|
|
|
TDocumento* doc = new TDocumento(cur.curr(LF_DOC));
|
2005-01-11 11:01:25 +00:00
|
|
|
p.addstatus(1);
|
|
|
|
const TRectype& rec_tipodoc = cur.curr(-ALIAS_TIP);
|
|
|
|
const int tipodoc = rec_tipodoc.get_int("I1");
|
|
|
|
const bool notacredito = rec_tipodoc.get_bool("B7");
|
|
|
|
char tipo = ' ';
|
|
|
|
if (tipodoc == 2)
|
|
|
|
{
|
|
|
|
if (notacredito)
|
|
|
|
tipo = 'R';
|
|
|
|
else
|
|
|
|
tipo = 'F';
|
|
|
|
}
|
|
|
|
else if (tipodoc == 3)
|
|
|
|
tipo = 'O';
|
|
|
|
if (tipo != ' ')
|
|
|
|
{
|
2005-03-17 18:21:37 +00:00
|
|
|
const int nriga = cur.curr().get_int(RDOC_NRIGA);
|
|
|
|
TRiga_documento& rigadoc = (*doc)[nriga];
|
|
|
|
const real qta = cur.curr().get_real(RDOC_QTA);
|
|
|
|
real importo = rigadoc.importo(FALSE, FALSE);
|
|
|
|
if (!qta.is_zero() || !importo.is_zero())
|
|
|
|
{
|
|
|
|
filerdoc.zero();
|
|
|
|
filerdoc.put("CODDITTA", get_firm()); // ditta
|
|
|
|
filerdoc.put("TIPO", tipo); // tipologia documento
|
|
|
|
TDate data = cur.curr(LF_DOC).get(DOC_DATADOC);
|
|
|
|
filerdoc.put("DATADOC", data.string()); // data doc.
|
|
|
|
// record anamag
|
|
|
|
const TRectype& rec_anamag = cache().get(LF_ANAMAG, cur.curr().get(RDOC_CODARTMAG));
|
|
|
|
// record clifo e cfven
|
|
|
|
TToken_string key;
|
|
|
|
key.add(cur.curr(LF_DOC).get(DOC_TIPOCF));
|
|
|
|
key.add(cur.curr(LF_DOC).get(DOC_CODCF));
|
|
|
|
const TRectype& rec_cfven = cache().get(LF_CFVEN, key);
|
|
|
|
const TRectype& rec_clifo = cache().get(LF_CLIFO, key);
|
|
|
|
// record comuni
|
|
|
|
key = "";
|
|
|
|
key.add(rec_clifo.get(CLI_STATOCF));
|
|
|
|
key.add(rec_clifo.get(CLI_COMCF));
|
|
|
|
const TRectype& rec_comuni = cache().get(LF_COMUNI, key);
|
|
|
|
TString16 tmp = cur.curr().get(RDOC_CODMAG);
|
|
|
|
filerdoc.put("CODDEP", tmp); // codice deposito
|
|
|
|
tmp = tmp.left(3);
|
|
|
|
filerdoc.put("CODMAG", tmp); // codice magazzino
|
|
|
|
tmp = rec_anamag.get(ANAMAG_GRMERC);
|
|
|
|
filerdoc.put("SOTTOGR", tmp); // sottogruppo merceologico
|
|
|
|
tmp = tmp.left(3);
|
|
|
|
filerdoc.put("GRUPPO", tmp); //gruppo merceologico
|
|
|
|
tmp = cur.curr(LF_DOC).get(DOC_ZONA);
|
|
|
|
if (tmp.empty())
|
|
|
|
tmp = rec_cfven.get(CFV_CODZONA);
|
|
|
|
filerdoc.put("ZONA", tmp); // zona
|
|
|
|
filerdoc.put("REGIONE", rec_comuni.get("CODREG")); // regione
|
|
|
|
filerdoc.put("PROV", rec_comuni.get(COM_PROVCOM)); // provincia
|
|
|
|
tmp = cur.curr(LF_DOC).get(DOC_CATVEN);
|
|
|
|
if (tmp.empty())
|
|
|
|
tmp = rec_cfven.get(CFV_CATVEN);
|
|
|
|
filerdoc.put("CATMERCLI", tmp); // cat. merceologica
|
|
|
|
filerdoc.put("CODCLI", cur.curr(LF_DOC).get(DOC_CODCF)); // codice cliente
|
|
|
|
tmp = cur.curr(LF_DOC).get(DOC_CODAG);
|
|
|
|
if (tmp.empty())
|
|
|
|
tmp = rec_cfven.get(CFV_CODAG);
|
|
|
|
filerdoc.put("CODAG", tmp); // codice agente
|
|
|
|
filerdoc.put("CODART", cur.curr().get(RDOC_CODARTMAG)); // codice articolo
|
|
|
|
filerdoc.put("TIPODOC", cur.curr(LF_DOC).get(DOC_TIPODOC)); // tipo documento
|
|
|
|
filerdoc.put("QTA", cur.curr().get(RDOC_QTA)); // quantita
|
|
|
|
filerdoc.put("IMPORTO", importo);
|
|
|
|
importo = rigadoc.importo(TRUE, FALSE);
|
|
|
|
filerdoc.put("SCONTATO", importo);
|
|
|
|
update_tab(filetab, filerdoc.curr());
|
|
|
|
err = filerdoc.write();
|
2005-03-21 16:08:20 +00:00
|
|
|
}
|
2005-01-11 11:01:25 +00:00
|
|
|
}
|
|
|
|
if (err != NOERR)
|
|
|
|
error_box("Errore %d in scrittura file dbf. Elaborazione non terminata.", err);
|
2005-03-21 16:08:20 +00:00
|
|
|
delete doc;
|
2005-01-11 11:01:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRDoc2JBI::update_tab(TExternisamfile& filetab, const TRectype rectab)
|
|
|
|
{
|
|
|
|
// TIP tipo documento
|
2005-03-21 16:08:20 +00:00
|
|
|
TString codice;;
|
2005-01-11 11:01:25 +00:00
|
|
|
TString80 descr = cache().get("%TIP", rectab.get("TIPODOC"), "S0");
|
|
|
|
insert_tab(filetab, "TIP", rectab.get("TIPODOC"), descr);
|
|
|
|
// AGE agente
|
|
|
|
descr = cache().get(LF_AGENTI, rectab.get("CODAG"), AGE_RAGSOC);
|
|
|
|
insert_tab(filetab, "AGE", rectab.get("CODAG"), descr);
|
|
|
|
// CVE cat.ven.
|
|
|
|
descr = cache().get("%CVE", rectab.get("CATMERCLI"), "S0");
|
|
|
|
insert_tab(filetab, "CVE", rectab.get("CATMERCLI"), descr);
|
|
|
|
// CLI cliente
|
2005-03-21 16:08:20 +00:00
|
|
|
codice = "C|";
|
|
|
|
long codcli = rectab.get_long("CODCLI");
|
|
|
|
codice.format("C|%06d", codcli);
|
|
|
|
descr = cache().get(LF_CLIFO, codice, CLI_RAGSOC);
|
|
|
|
codice.format("%06d", codcli);
|
|
|
|
insert_tab(filetab, "CLI", codice, descr);
|
2005-01-11 11:01:25 +00:00
|
|
|
// GRM gruppo merc.
|
2005-03-21 16:08:20 +00:00
|
|
|
descr = cache().get("GMC", rectab.get("GRUPPO"), "S0");
|
2005-01-11 11:01:25 +00:00
|
|
|
insert_tab(filetab, "GRM", rectab.get("GRUPPO"), descr);
|
|
|
|
// SGM sottogruppo merceol.
|
2005-03-21 16:08:20 +00:00
|
|
|
descr = cache().get("GMC", rectab.get("SOTTOGR"), "S0");
|
2005-01-11 11:01:25 +00:00
|
|
|
insert_tab(filetab, "SGM", rectab.get("SOTTOGR"), descr);
|
|
|
|
// ART codart
|
2005-01-13 14:23:42 +00:00
|
|
|
descr = cache().get(LF_ANAMAG, rectab.get("CODART"), ANAMAG_DESCR);
|
2005-01-11 11:01:25 +00:00
|
|
|
insert_tab(filetab, "ART", rectab.get("CODART"), descr);
|
|
|
|
// ZON zona
|
2005-03-21 16:08:20 +00:00
|
|
|
descr = cache().get("ZON", rectab.get("ZONA"), "S0");
|
2005-01-11 11:01:25 +00:00
|
|
|
insert_tab(filetab, "ZON", rectab.get("ZONA"), descr);
|
|
|
|
// RGI regioni
|
|
|
|
descr = cache().get("%RGI", rectab.get("REGIONE"), "S0");
|
|
|
|
insert_tab(filetab, "RGI", rectab.get("REGIONE"), descr);
|
|
|
|
// MAG mag
|
2005-03-21 16:08:20 +00:00
|
|
|
descr = cache().get("MAG", rectab.get("CODMAG"), "S0");
|
2005-01-11 11:01:25 +00:00
|
|
|
insert_tab(filetab, "MAG", rectab.get("CODMAG"), descr);
|
|
|
|
// DEP dep
|
2005-03-21 16:08:20 +00:00
|
|
|
descr = cache().get("MAG", rectab.get("CODDEP"), "S0");
|
2005-01-11 11:01:25 +00:00
|
|
|
insert_tab(filetab, "DEP", rectab.get("CODDEP"), descr);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ve7600(int argc, char** argv)
|
|
|
|
{
|
|
|
|
TRDoc2JBI app;
|
|
|
|
app.run(argc, argv, "Trasferimento JBI");
|
|
|
|
return 0;
|
2005-03-21 16:08:20 +00:00
|
|
|
}
|