1997-06-03 15:56:27 +00:00
|
|
|
#include <execp.h>
|
1997-06-27 09:21:13 +00:00
|
|
|
|
2005-05-06 10:58:49 +00:00
|
|
|
#include "velib04.h"
|
1998-08-25 18:07:30 +00:00
|
|
|
|
1997-06-03 15:56:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Lista di documenti
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TDate TLista_documenti::num2date(char provv, int anno, const char* codnum, long num) const
|
|
|
|
{
|
|
|
|
TLocalisamfile doc(LF_DOC);
|
|
|
|
CHECK(num > 0, "Numero documento nullo.");
|
|
|
|
TDocumento::set_key(doc.curr(), provv, anno, codnum, num);
|
|
|
|
|
|
|
|
if (doc.read(_isgteq) != NOERR) // In caso d'errore ...
|
|
|
|
doc.last(); // prendi l'ultimo
|
|
|
|
|
2004-04-28 22:23:16 +00:00
|
|
|
return doc.get_date(DOC_DATADOC);
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
|
|
|
|
2005-05-25 11:32:58 +00:00
|
|
|
bool TLista_documenti::find(char provv, int anno, const char * codnum, long ndoc) const
|
|
|
|
{
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
if (ndoc > 0)
|
|
|
|
{
|
|
|
|
const int it = items();
|
|
|
|
for (int i = 0; !found && i < it; i++)
|
|
|
|
{
|
|
|
|
const TDocumento & d = doc(i);
|
|
|
|
|
|
|
|
found = ((d.head().get_long(DOC_NDOC) == ndoc) &&
|
|
|
|
(d.head().get_char(DOC_PROVV) == provv) &&
|
|
|
|
(d.head().get_int(DOC_ANNO) == anno) &&
|
|
|
|
(d.head().get(DOC_CODNUM) == codnum));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
2005-09-20 12:51:40 +00:00
|
|
|
|
1997-06-03 15:56:27 +00:00
|
|
|
int TLista_documenti::read(char provv, char tipocf, long clifo, int anno,
|
|
|
|
TToken_string& tipidoc, TToken_string& statidoc,
|
|
|
|
const TDate& dd, const TDate& ad,
|
|
|
|
const char* codnum, long dn, long an)
|
|
|
|
{
|
|
|
|
CHECK(provv == 'D' || provv == 'P', "Provvisorio o Definitivo?");
|
|
|
|
CHECK(tipocf == 'C' || tipocf == 'F', "Il tipo deve essere Cliente o Fornitore");
|
|
|
|
CHECKD(clifo > 0L, "Codice cliente non valido", clifo);
|
|
|
|
CHECKD(anno > 1900, "Anno non valido: ", anno);
|
|
|
|
CHECK(!tipidoc.empty_items(), "Lista dei tipi documento vuota");
|
|
|
|
CHECK(!statidoc.empty_items(), "Lista degli stati documento vuota");
|
|
|
|
|
|
|
|
TRelation doc(LF_DOC);
|
|
|
|
TRectype start(LF_DOC), stop(LF_DOC);
|
1999-10-22 10:00:18 +00:00
|
|
|
int anno_start, anno_stop;
|
1997-06-03 15:56:27 +00:00
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_TIPOCF, tipocf);
|
|
|
|
stop.put(DOC_TIPOCF, tipocf);
|
1997-06-03 15:56:27 +00:00
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_CODCF, clifo);
|
|
|
|
stop.put(DOC_CODCF, clifo);
|
1997-06-03 15:56:27 +00:00
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_PROVV, provv);
|
|
|
|
stop.put(DOC_PROVV, provv);
|
1997-06-03 15:56:27 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
anno_start = anno_stop = anno;
|
|
|
|
|
|
|
|
if (dd.ok())
|
|
|
|
{
|
|
|
|
anno_start = dd.year();
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_ANNO, anno_start);
|
1999-10-22 10:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ad.ok())
|
|
|
|
{
|
|
|
|
anno_stop = ad.year();
|
2003-11-10 15:18:25 +00:00
|
|
|
stop.put(DOC_ANNO, anno_stop);
|
1999-10-22 10:00:18 +00:00
|
|
|
}
|
1997-06-03 15:56:27 +00:00
|
|
|
|
|
|
|
if (dn > 0)
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
const TDate d(num2date(provv, anno_start, codnum, dn));
|
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_DATADOC, d);
|
|
|
|
start.put(DOC_ANNO, d.year());
|
|
|
|
start.put(DOC_NDOC, dn);
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dd.ok() && dd > botime)
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_DATADOC, dd);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
|
|
if (anno_start <= anno_stop)
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_ANNO, anno_start);
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (an > 0)
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
const TDate d(num2date(provv, anno_stop, codnum, an));
|
2003-11-10 15:18:25 +00:00
|
|
|
stop.put(DOC_DATADOC, d);
|
|
|
|
stop.put(DOC_ANNO, d.year());
|
|
|
|
stop.put(DOC_NDOC, an);
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ad.ok() && ad < eotime)
|
2003-11-10 15:18:25 +00:00
|
|
|
stop.put(DOC_DATADOC, ad);
|
1999-10-22 10:00:18 +00:00
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
stop.put(DOC_ANNO, anno_stop);
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TString filter(16);
|
|
|
|
if (codnum && *codnum)
|
|
|
|
{
|
|
|
|
bool numfilter = FALSE;
|
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
if (start.get(DOC_DATADOC).empty())
|
1997-06-03 15:56:27 +00:00
|
|
|
numfilter = TRUE;
|
|
|
|
else
|
2003-11-10 15:18:25 +00:00
|
|
|
start.put(DOC_CODNUM, codnum);
|
1997-06-03 15:56:27 +00:00
|
|
|
|
2003-11-10 15:18:25 +00:00
|
|
|
if (stop.get(DOC_DATADOC).empty())
|
1997-06-03 15:56:27 +00:00
|
|
|
numfilter = TRUE;
|
|
|
|
else
|
2003-11-10 15:18:25 +00:00
|
|
|
stop.put(DOC_CODNUM, codnum);
|
1997-06-03 15:56:27 +00:00
|
|
|
|
|
|
|
if (numfilter)
|
|
|
|
filter << "CODNUM=\"" << codnum << '"';
|
|
|
|
}
|
|
|
|
|
|
|
|
TCursor cur(&doc, filter, 2, &start, &stop);
|
|
|
|
const TRectype& head = cur.curr();
|
|
|
|
|
|
|
|
_documenti.destroy();
|
|
|
|
for (cur = 0; cur.ok(); ++cur)
|
|
|
|
{
|
2006-02-02 13:49:19 +00:00
|
|
|
const TString4 tipodoc = head.get(DOC_TIPODOC);
|
|
|
|
const TString4 statodoc = head.get(DOC_STATO);
|
2008-02-01 06:39:03 +00:00
|
|
|
bool match = false;
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
|
|
for (int i = tipidoc.items()-1; i>=0; i--)
|
|
|
|
{
|
2008-02-01 06:39:03 +00:00
|
|
|
const TString & tipo = tipidoc.get(i);
|
|
|
|
|
|
|
|
if (tipo.blank() || tipodoc == tipo)
|
|
|
|
{
|
|
|
|
const TString & stato = statidoc.get(i);
|
|
|
|
|
|
|
|
if (stato.blank() || statodoc == stato)
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
2008-02-01 06:39:03 +00:00
|
|
|
match = true;
|
1999-10-22 10:00:18 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-02-01 06:39:03 +00:00
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (match)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
|
|
|
TDocumento* d = new TDocumento(head);
|
|
|
|
_documenti.add(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return _documenti.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_documenti::write(bool re) const
|
|
|
|
{
|
|
|
|
int err = NOERR;
|
|
|
|
for (int i = 0; i < _documenti.items() && err == NOERR; i++)
|
1999-06-18 15:35:05 +00:00
|
|
|
{
|
1997-06-03 15:56:27 +00:00
|
|
|
err = doc(i).write(re);
|
1999-06-18 15:35:05 +00:00
|
|
|
((TDocumento&)doc(i)).flush_rows();
|
|
|
|
}
|
1997-06-03 15:56:27 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-06-11 11:31:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TLista_clifo
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TLista_clifo::TClifo::init(const TRectype& rec, const TRectype& ven)
|
|
|
|
{
|
|
|
|
_codice = rec.get_long(CLI_CODCF);
|
|
|
|
CHECK(_codice > 0, "Codice cliente nullo");
|
|
|
|
|
|
|
|
if (!ven.empty())
|
|
|
|
{
|
|
|
|
_agente = ven.get_long(CLI_CODAG);
|
|
|
|
_zona = ven.get_long(CLI_CODZONA);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
_agente = _zona = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TLista_clifo::TClifo::read(char tipo, long cod)
|
|
|
|
{
|
|
|
|
TRelation clifo(LF_CLIFO);
|
|
|
|
clifo.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF");
|
|
|
|
|
|
|
|
TRectype& curr = clifo.curr();
|
|
|
|
curr.put(CLI_TIPOCF, tipo);
|
|
|
|
curr.put(CLI_CODCF, cod);
|
|
|
|
if (clifo.read() == NOERR)
|
|
|
|
init(curr, clifo.curr(LF_CFVEN));
|
|
|
|
else
|
|
|
|
zero();
|
|
|
|
|
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
TLista_clifo::TClifo::TClifo(const TRectype& rec)
|
|
|
|
{
|
|
|
|
CHECK(rec.num() == LF_CLIFO, "Record non clienti");
|
|
|
|
const char tipo = rec.get_char(CLI_TIPOCF);
|
|
|
|
const long codice = rec.get_long(CLI_CODCF);
|
|
|
|
read(tipo, codice);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::leggi(long dc, long ac, long da, long aa, const char * dz, const char * az)
|
|
|
|
{
|
|
|
|
TRelation clifo(LF_CLIFO);
|
|
|
|
clifo.add(LF_CFVEN, "TIPOCF==TIPOCF|CODCF==CODCF");
|
|
|
|
|
|
|
|
TRectype start(LF_CLIFO), stop(LF_CLIFO);
|
|
|
|
|
|
|
|
start.put(CLI_TIPOCF, tipo());
|
|
|
|
if (dc > 0)
|
|
|
|
start.put(CLI_CODCF, dc);
|
|
|
|
|
|
|
|
stop.put(CLI_TIPOCF, tipo());
|
|
|
|
if (ac > 0)
|
|
|
|
stop.put(CLI_CODCF, ac);
|
|
|
|
|
|
|
|
TString filter(32);
|
|
|
|
if (da > 0)
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODAG << ">=" << da << ')';
|
|
|
|
if (aa > 0)
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODAG << "<=" << aa << ')';
|
|
|
|
}
|
|
|
|
if (dz && (*dz !='\0'))
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODZONA << ">=\"" << dz << "\")";
|
|
|
|
}
|
|
|
|
if (az && (*az !='\0'))
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODZONA << "<=\"" << az << "\")";
|
|
|
|
}
|
|
|
|
|
|
|
|
TCursor cur(&clifo, "", 1, &start, &stop);
|
|
|
|
if (filter.not_empty())
|
|
|
|
cur.setfilter(filter, TRUE);
|
|
|
|
const TRectype& cli = cur.curr();
|
|
|
|
const TRectype& ven = cur.curr(LF_CFVEN);
|
|
|
|
for (cur = 0; cur.ok(); ++cur)
|
|
|
|
{
|
|
|
|
TClifo* c = new TClifo(cli, ven);
|
|
|
|
_clifo.add(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dc > 0 || ac > 0)
|
|
|
|
ordina_per_codice();
|
|
|
|
else
|
|
|
|
if (da > 0 || aa > 0)
|
|
|
|
ordina_per_agente();
|
|
|
|
else
|
|
|
|
if ((dz && (*dz !='\0')) || (az && (*dz !='\0')))
|
|
|
|
ordina_per_zona();
|
|
|
|
|
|
|
|
return _clifo.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::leggi_ragsoc(const char *dr, const char * ar, long da, long aa, const char * dz, const char * az)
|
|
|
|
{
|
|
|
|
TRelation clifo(LF_CLIFO);
|
|
|
|
clifo.add(LF_CFVEN, "TIPOCF==TIPOCF|CODCF==CODCF");
|
|
|
|
|
|
|
|
TRectype start(LF_CLIFO), stop(LF_CLIFO);
|
|
|
|
|
|
|
|
start.put(CLI_TIPOCF, tipo());
|
|
|
|
if (dr && *dr)
|
|
|
|
start.put(CLI_RAGSOC, dr);
|
|
|
|
|
|
|
|
stop.put(CLI_TIPOCF, tipo());
|
|
|
|
if (ar && *ar)
|
|
|
|
stop.put(CLI_RAGSOC, ar);
|
|
|
|
|
|
|
|
TString filter(32);
|
|
|
|
if (da > 0)
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODAG << ">=" << da << ')';
|
|
|
|
if (aa > 0)
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODAG << "<=" << aa << ')';
|
|
|
|
}
|
|
|
|
if (dz && (*dz !='\0'))
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODZONA << ">=\"" << dz << "\")";
|
|
|
|
}
|
|
|
|
if (az && (*az !='\0'))
|
|
|
|
{
|
|
|
|
if (filter.not_empty()) filter << "&&";
|
|
|
|
filter << '(' << LF_CFVEN << "->" << CLI_CODZONA << "<=\"" << az << "\")";
|
|
|
|
}
|
|
|
|
|
|
|
|
TCursor cur(&clifo, "", 2, &start, &stop);
|
|
|
|
if (filter.not_empty())
|
|
|
|
cur.setfilter(filter, TRUE);
|
|
|
|
const TRectype& cli = cur.curr();
|
|
|
|
const TRectype& ven = cur.curr(LF_CFVEN);
|
|
|
|
for (cur = 0; cur.ok(); ++cur)
|
|
|
|
{
|
|
|
|
TClifo* c = new TClifo(cli, ven);
|
|
|
|
_clifo.add(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
return _clifo.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::sort_by_code(const TObject** o1, const TObject** o2)
|
|
|
|
{
|
|
|
|
TLista_clifo::TClifo* c1 = (TLista_clifo::TClifo*)*o1;
|
|
|
|
TLista_clifo::TClifo* c2 = (TLista_clifo::TClifo*)*o2;
|
|
|
|
const long d = c1->codice() - c2->codice();
|
|
|
|
return d == 0L ? 0 : (d > 0 ? +1 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::sort_by_agent(const TObject** o1, const TObject** o2)
|
|
|
|
{
|
|
|
|
TLista_clifo::TClifo* c1 = (TLista_clifo::TClifo*)*o1;
|
|
|
|
TLista_clifo::TClifo* c2 = (TLista_clifo::TClifo*)*o2;
|
|
|
|
const long d = c1->agente() - c2->agente();
|
|
|
|
return d == 0L ? 0 : (d > 0 ? +1 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::sort_by_zone(const TObject** o1, const TObject** o2)
|
|
|
|
{
|
|
|
|
TLista_clifo::TClifo* c1 = (TLista_clifo::TClifo*)*o1;
|
|
|
|
TLista_clifo::TClifo* c2 = (TLista_clifo::TClifo*)*o2;
|
|
|
|
const long d = c1->zona() - c2->zona();
|
|
|
|
return d == 0L ? 0 : (d > 0 ? +1 : -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::ordina_per_codice()
|
|
|
|
{
|
|
|
|
_clifo.sort(sort_by_code);
|
|
|
|
return _clifo.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::ordina_per_agente()
|
|
|
|
{
|
|
|
|
_clifo.sort(sort_by_agent);
|
|
|
|
return _clifo.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::ordina_per_zona()
|
|
|
|
{
|
|
|
|
_clifo.sort(sort_by_zone);
|
|
|
|
return _clifo.items();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::find(long cod) const
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = items()-1; i >= 0; i--)
|
|
|
|
if (clifo(i).codice() == cod) break;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLista_clifo::add(long cod)
|
|
|
|
{
|
|
|
|
int pos = find(cod);
|
|
|
|
if (pos < 0)
|
|
|
|
{
|
|
|
|
TClifo* c = new TClifo(tipo(), cod);
|
|
|
|
pos = _clifo.add(c);
|
|
|
|
}
|
|
|
|
return pos;
|
|
|
|
}
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TParametri_elaborazione
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TParametri_elaborazione::set(const char * name, const char * val)
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
_par.add(name, new TString(val), TRUE);
|
1999-07-16 14:59:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const TString & TParametri_elaborazione::get(const char * name) const
|
|
|
|
{
|
2000-05-05 15:25:49 +00:00
|
|
|
TObject *val = _par.objptr(name);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
2000-05-05 15:25:49 +00:00
|
|
|
if (val == NULL)
|
|
|
|
return EMPTY_STRING;
|
|
|
|
else
|
|
|
|
return (const TString &) *val;
|
1999-07-16 14:59:11 +00:00
|
|
|
}
|
|
|
|
|
1997-06-03 15:56:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TElaborazione
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TElaborazione::TElaborazione(const char* cod) : TRectype(LF_TABCOM)
|
|
|
|
{
|
|
|
|
settab("ELD");
|
|
|
|
if (cod && *cod)
|
|
|
|
read(cod);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TElaborazione::read(const char* cod)
|
|
|
|
{
|
2005-05-17 15:39:29 +00:00
|
|
|
int err = NOERR;
|
|
|
|
|
|
|
|
*this = cache().get("%ELD", cod);
|
|
|
|
if (empty())
|
|
|
|
{
|
1997-06-03 15:56:27 +00:00
|
|
|
yesnofatal_box("Codice elaborazione non valido: %s", cod);
|
2005-05-17 15:39:29 +00:00
|
|
|
err = _iskeynotfound;
|
|
|
|
}
|
1997-06-03 15:56:27 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2008-11-12 11:54:24 +00:00
|
|
|
bool TElaborazione::is_document_ok(const TRectype & doc) const
|
|
|
|
{
|
|
|
|
bool ok = false;
|
|
|
|
const TString4 codnum(doc.get(DOC_CODNUM));
|
|
|
|
const TString4 tipodoc(doc.get(DOC_TIPODOC));
|
|
|
|
const char stato(doc.get_char(DOC_STATO));
|
|
|
|
const TString & codnumel = codice_numerazione_iniziale();
|
|
|
|
|
|
|
|
if (codnumel.blank() || codnum == codnumel)
|
|
|
|
{
|
|
|
|
for (int i = 0; !ok && i < TElaborazione::_max_tipi_doc_elab; i++)
|
|
|
|
{
|
|
|
|
const TString & tipel = tipo_iniziale(i);
|
|
|
|
if (tipel.blank())
|
|
|
|
break;
|
|
|
|
if (tipodoc == tipel && stato == stato_iniziale(i))
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
1997-06-03 15:56:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
1998-08-25 18:07:30 +00:00
|
|
|
// TElaborazione_esterna
|
1997-06-03 15:56:27 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
TElaborazione_esterna::TElaborazione_esterna(const char* cod)
|
|
|
|
: TElaborazione(cod)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
1998-08-25 18:07:30 +00:00
|
|
|
bool TElaborazione_esterna::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
1998-06-10 16:38:58 +00:00
|
|
|
const TDate& data_elab, bool interattivo)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
if (applicazione_esterna().blank())
|
|
|
|
error_box("Non e' stato specificato il nome del'applicazione esterna");
|
1997-06-03 15:56:27 +00:00
|
|
|
CHECK(doc_in.items() == 1, "Si deve specificare uno e un solo documento in entrata");
|
|
|
|
CHECK(doc_out.items() == 1, "Si deve specificare uno e un solo documento in uscita");
|
|
|
|
TFilename name; name.temp("ext");
|
1999-10-22 10:00:18 +00:00
|
|
|
|
|
|
|
TDocumento& d = doc_in[0];
|
|
|
|
const int doc_fields = d.items();
|
|
|
|
TString16 par;
|
|
|
|
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
TConfig c(name, "Transaction");
|
|
|
|
c.set("Action", codice());
|
2006-04-13 17:56:02 +00:00
|
|
|
c.set("ProvvOut", doc_out[0].get(DOC_PROVV));
|
|
|
|
c.set("AnnoOut", doc_out[0].get(DOC_ANNO));
|
|
|
|
c.set("CodNumOut", doc_out[0].get(DOC_CODNUM));
|
|
|
|
c.set("NDocOut", doc_out[0].get(DOC_NDOC));
|
1997-06-03 15:56:27 +00:00
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
par.format("%d", LF_DOC);
|
|
|
|
|
|
|
|
for (int i = 0; i < doc_fields; i++)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
|
|
|
const TString16 fname(d.fieldname(i));
|
|
|
|
TFieldref f(fname, LF_DOC);
|
|
|
|
f.write(c, par, d.get(fname));
|
|
|
|
}
|
|
|
|
for (TVariable_field * v = d.first_variable_field(); v ; v = d.succ_variable_field())
|
|
|
|
c.set(v->name(), v->get(), par);
|
|
|
|
const int rows = d.physical_rows();
|
|
|
|
if (rows > 0)
|
|
|
|
{
|
2004-04-28 22:23:16 +00:00
|
|
|
const int row_fields = d[1].items();
|
1997-06-03 15:56:27 +00:00
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
for (int r = 1; r <= rows; r++)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
|
|
|
TRiga_documento row = d[r];
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
par.format("%d,%d", LF_RIGHEDOC, r);
|
1999-10-22 10:00:18 +00:00
|
|
|
for (int i = 0; i < row_fields; i++)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
|
|
|
const TString16 fname(row.fieldname(i));
|
|
|
|
TFieldref f(fname, LF_RIGHEDOC);
|
|
|
|
f.write(c, par, row.get(fname));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
TString command_line(applicazione_esterna()); command_line << " /i" << name;
|
1997-06-03 15:56:27 +00:00
|
|
|
TExternal_app app(command_line);
|
|
|
|
if (app.run() == 0)
|
|
|
|
{
|
2008-03-26 11:24:36 +00:00
|
|
|
TConfig c(name, "Transaction");
|
2006-04-13 17:56:02 +00:00
|
|
|
const TString & res = c.get("Result");
|
|
|
|
if (res == "SUCCESS")
|
1999-10-22 10:00:18 +00:00
|
|
|
{
|
|
|
|
par.format("%d", LF_DOC);
|
|
|
|
for (int i = 0; i < doc_fields; i++)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
const TString16 fname(d.fieldname(i));
|
|
|
|
TFieldref f(fname, LF_DOC);
|
|
|
|
d.put(fname, f.read(c, par));
|
|
|
|
}
|
|
|
|
for (TVariable_field * v = d.first_variable_field(); v ; v = d.succ_variable_field())
|
|
|
|
v->put(c.get(v->name(), par));
|
|
|
|
|
|
|
|
TString_array p;
|
|
|
|
c.list_paragraphs(p);
|
|
|
|
d.destroy_rows();
|
|
|
|
|
|
|
|
int r = 1 ;
|
1997-06-03 15:56:27 +00:00
|
|
|
par.format("%d,%d", LF_RIGHEDOC, r);
|
1999-10-22 10:00:18 +00:00
|
|
|
while (p.find(par) >= 0)
|
|
|
|
{
|
|
|
|
const TString& tiporiga = c.get(RDOC_TIPORIGA, par);
|
|
|
|
TRiga_documento& row = d.new_row(tiporiga);
|
|
|
|
for (int i = row.items()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
const TString16 fname(row.fieldname(i));
|
|
|
|
TFieldref f(fname, LF_RIGHEDOC);
|
2000-05-05 15:25:49 +00:00
|
|
|
const TString& val = f.read(c, par);
|
|
|
|
if (val.not_empty())
|
|
|
|
row.put(fname, val);
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
r++;
|
|
|
|
par.format("%d,%d", LF_RIGHEDOC, r);
|
2006-04-13 17:56:02 +00:00
|
|
|
}
|
2008-03-26 11:24:36 +00:00
|
|
|
d.stato(stato_finale_doc_iniziale()[0]);
|
2006-04-13 17:56:02 +00:00
|
|
|
return true;
|
1999-10-22 10:00:18 +00:00
|
|
|
}
|
2006-04-13 17:56:02 +00:00
|
|
|
else
|
|
|
|
if (res == "OUTDOC")
|
|
|
|
{
|
|
|
|
doc_out[0].read();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
2006-04-13 17:56:02 +00:00
|
|
|
return false;
|
1997-06-03 15:56:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TCopia_documento
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TCopia_documento::TCopia_documento(const char* cod)
|
1998-08-25 18:07:30 +00:00
|
|
|
: TElaborazione(cod)
|
2007-09-17 15:33:04 +00:00
|
|
|
{ }
|
1997-06-03 15:56:27 +00:00
|
|
|
|
|
|
|
bool TCopia_documento::elabora(TLista_documenti& doc_in, TLista_documenti& doc_out,
|
2007-09-17 15:33:04 +00:00
|
|
|
const TDate& data_elab, bool /*interattivo*/)
|
1997-06-03 15:56:27 +00:00
|
|
|
{
|
1998-08-25 18:07:30 +00:00
|
|
|
CHECK(doc_in.items() == doc_out.items(), "Si deve specificare un numero uguale di documenti in entrata ed in uscita");
|
|
|
|
for (int d = 0; d < doc_in.items(); d++)
|
|
|
|
{
|
2007-09-17 15:33:04 +00:00
|
|
|
const TDocumento& doc_src = doc_in[d];
|
|
|
|
TDocumento& doc_dest = doc_out[d];
|
|
|
|
|
|
|
|
doc_dest.copy_contents(doc_src);
|
|
|
|
// Scancello tutti gli inutili riferimenti al documento origine
|
|
|
|
for (int r = doc_dest.physical_rows(); r > 0; r--)
|
|
|
|
doc_dest[r].reset_original_rdoc_key();
|
|
|
|
|
|
|
|
if (data_elab.ok())
|
|
|
|
doc_dest.put(DOC_DATADOC, data_elab);
|
1998-08-25 18:07:30 +00:00
|
|
|
}
|
1997-06-03 15:56:27 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|