1999-02-22 15:19:07 +00:00
|
|
|
#include <currency.h>
|
|
|
|
#include <defmask.h>
|
|
|
|
#include <prefix.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <recarray.h>
|
|
|
|
#include <relation.h>
|
|
|
|
|
|
|
|
#include "inlib01.h"
|
|
|
|
#include "in0500a.h"
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TIntra_mask
|
|
|
|
// Maschera generica con dati utili a tutte quelle intra
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void TIntra_mask::on_firm_change()
|
|
|
|
{
|
|
|
|
if (is_running())
|
|
|
|
TAutomask::on_firm_change();
|
|
|
|
long firm = prefix().get_codditta();
|
|
|
|
const TRectype& ditta = cache().get(LF_NDITTE, firm);
|
|
|
|
_freq_ces = ditta.get_char("FREQCES");
|
|
|
|
_freq_acq = ditta.get_char("FREQACQ");
|
|
|
|
if (_freq_ces <= ' ') _freq_ces = 'T';
|
|
|
|
if (_freq_acq <= ' ') _freq_acq = 'T';
|
|
|
|
}
|
|
|
|
|
|
|
|
short TIntra_mask::type_field() const
|
|
|
|
{
|
|
|
|
NFCHECK("Non e' stato specificato il campo del tipo");
|
|
|
|
return DLG_NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
short TIntra_mask::period_field() const
|
|
|
|
{ return DLG_NULL; }
|
|
|
|
|
|
|
|
char TIntra_mask::tipo() const
|
|
|
|
{
|
|
|
|
short id = type_field();
|
|
|
|
char t = get(id)[0];
|
|
|
|
return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
char TIntra_mask::frequenza() const
|
|
|
|
{
|
|
|
|
const char t = tipo();
|
|
|
|
return (t == 'A' || t == 'B') ? _freq_acq : _freq_ces;
|
|
|
|
}
|
|
|
|
|
1999-04-22 14:23:18 +00:00
|
|
|
const char* TIntra_mask::periodo_str() const
|
1999-02-22 15:19:07 +00:00
|
|
|
{
|
|
|
|
const short id = period_field();
|
1999-04-22 14:23:18 +00:00
|
|
|
const char* pe = "01";
|
1999-02-22 15:19:07 +00:00
|
|
|
if (id != DLG_NULL)
|
|
|
|
{
|
|
|
|
switch(frequenza())
|
|
|
|
{
|
1999-04-22 14:23:18 +00:00
|
|
|
case 'M': pe = get(id); break;
|
|
|
|
case 'T': pe = get(id+1); break;
|
|
|
|
default : break;
|
1999-02-22 15:19:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
NFCHECK("Non e' stato specificato il campo del periodo");
|
|
|
|
return pe;
|
|
|
|
}
|
|
|
|
|
1999-04-22 14:23:18 +00:00
|
|
|
int TIntra_mask::periodo() const
|
|
|
|
{
|
|
|
|
return atoi(periodo_str());
|
|
|
|
}
|
|
|
|
|
1999-02-22 15:19:07 +00:00
|
|
|
bool TIntra_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
if (jolly == 0 && o.dlg() == type_field())
|
|
|
|
{
|
|
|
|
if (e == fe_modify || e == fe_init)
|
|
|
|
{
|
|
|
|
const short id = period_field();
|
|
|
|
if (id != DLG_NULL)
|
|
|
|
{
|
|
|
|
const char freq = frequenza();
|
|
|
|
show(id+0, freq == 'M');
|
|
|
|
show(id+1, freq == 'T');
|
|
|
|
show(id+2, freq == 'A');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TIntra_mask::TIntra_mask(const char* name)
|
|
|
|
: TAutomask(name)
|
|
|
|
{
|
|
|
|
on_firm_change();
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TDati_riepilogo
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TDati_riepilogo : public TSortable
|
|
|
|
{
|
1999-04-22 14:23:18 +00:00
|
|
|
TToken_string _key;
|
1999-02-22 15:19:07 +00:00
|
|
|
TCurrency _ammlire, _ammvaluta;
|
|
|
|
real _valstat, _massakg, _massaums;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual TObject* dup() const { return new TDati_riepilogo(*this); }
|
|
|
|
virtual int compare(const TSortable& s) const;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TDati_riepilogo& operator +=(const TDati_riepilogo& r);
|
|
|
|
void write(TRectype& rec) const;
|
|
|
|
|
1999-04-22 14:23:18 +00:00
|
|
|
const TString& stato(TString& c) const { _key.get(0, c); return c; }
|
|
|
|
const TString& partita_iva(TString& c) const { _key.get(1, c); return c; }
|
|
|
|
const TString& natura(TString& c) const { _key.get(3, c); return c; }
|
|
|
|
const TString& nomenclatura(TString& c) const { _key.get(4, c); return c; }
|
|
|
|
const TString& consegna(TString& c) const { _key.get(5, c); return c; }
|
|
|
|
const TString& trasporto(TString& c) const { _key.get(6, c); return c; }
|
|
|
|
const TString& paese(TString& c) const { _key.get(7, c); return c; }
|
|
|
|
const TString& paese_orig(TString& c) const { _key.get(8, c); return c; }
|
|
|
|
const TString& provincia(TString& c) const { _key.get(9, c); return c; }
|
|
|
|
|
1999-02-22 15:19:07 +00:00
|
|
|
TDati_riepilogo(const TDati_riepilogo& r);
|
1999-04-22 14:23:18 +00:00
|
|
|
TDati_riepilogo(const TToken_string& key, const TRectype& rec, const TString& codval);
|
1999-02-22 15:19:07 +00:00
|
|
|
virtual ~TDati_riepilogo() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
int TDati_riepilogo::compare(const TSortable& s) const
|
|
|
|
{
|
|
|
|
const TDati_riepilogo& r = (const TDati_riepilogo&)s;
|
|
|
|
return _key.compare(r._key);
|
|
|
|
}
|
|
|
|
|
|
|
|
TDati_riepilogo& TDati_riepilogo::operator +=(const TDati_riepilogo& r)
|
|
|
|
{
|
|
|
|
_ammlire += r._ammlire;
|
|
|
|
_ammvaluta += r._ammvaluta;
|
|
|
|
_valstat += r._valstat;
|
|
|
|
_massakg += r._massakg;
|
|
|
|
_massaums += r._massaums;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TDati_riepilogo::write(TRectype& rec) const
|
|
|
|
{
|
1999-04-22 14:23:18 +00:00
|
|
|
TString str;
|
|
|
|
rec.put("STATO", stato(str));
|
|
|
|
rec.put("PIVA", partita_iva(str));
|
|
|
|
rec.put("NATURA", natura(str));
|
|
|
|
rec.put("NOMENCL", nomenclatura(str));
|
|
|
|
rec.put("CONSEGNA", consegna(str));
|
|
|
|
rec.put("TRASPORTO", trasporto(str));
|
|
|
|
rec.put("PAESE", paese(str));
|
|
|
|
rec.put("PAESEORIG", paese_orig(str));
|
|
|
|
rec.put("PROV", provincia(str));
|
|
|
|
|
1999-02-22 15:19:07 +00:00
|
|
|
rec.put("AMMLIRE", _ammlire.get_num());
|
|
|
|
rec.put("AMMVALUTA", _ammvaluta.get_num());
|
|
|
|
rec.put("CODVAL", _ammvaluta.get_value());
|
|
|
|
rec.put("VALSTAT", _valstat);
|
|
|
|
rec.put("MASSAKG", _massakg);
|
|
|
|
rec.put("MASSAUMS", _massaums);
|
1999-04-22 14:23:18 +00:00
|
|
|
|
1999-02-22 15:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TDati_riepilogo::TDati_riepilogo(const TDati_riepilogo& r)
|
|
|
|
: _key(r._key), _valstat(r._valstat),
|
|
|
|
_ammlire(r._ammlire), _ammvaluta(r._ammvaluta),
|
|
|
|
_massakg(r._massakg), _massaums(r._massaums)
|
|
|
|
{ }
|
|
|
|
|
1999-04-22 14:23:18 +00:00
|
|
|
TDati_riepilogo::TDati_riepilogo(const TToken_string& key,
|
1999-02-22 15:19:07 +00:00
|
|
|
const TRectype& rec,
|
|
|
|
const TString& codval)
|
|
|
|
: _key(key), _ammlire(rec.get_real("AMMLIRE"), "_FIRM"),
|
|
|
|
_ammvaluta(rec.get_real("AMMVALUTA"), codval),
|
|
|
|
_valstat(rec.get_real("VALSTAT")),
|
|
|
|
_massakg(rec.get_real("MASSAKG")),
|
|
|
|
_massaums(rec.get_real("MASSAUMS"))
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TRiepiloghi
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TRiepiloghi : public TObject
|
|
|
|
{
|
|
|
|
TPointer_array _arr;
|
|
|
|
TAssoc_array _ass;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void add(const TRectype& rec, const TRectype& mov);
|
|
|
|
|
|
|
|
int items() const { return _arr.items(); }
|
|
|
|
int sort() { _arr.sort(); return items(); }
|
|
|
|
|
|
|
|
const TDati_riepilogo& operator[](int r) const
|
|
|
|
{ return (const TDati_riepilogo&)_arr[r]; }
|
|
|
|
};
|
|
|
|
|
|
|
|
void TRiepiloghi::add(const TRectype& rec, const TRectype& mov)
|
|
|
|
{
|
|
|
|
TString16 cod;
|
1999-04-22 14:23:18 +00:00
|
|
|
const char tipocf = mov.get_char("TIPOCF");
|
|
|
|
cod << tipocf << '|' << mov.get_long("CODCF");
|
1999-02-22 15:19:07 +00:00
|
|
|
const TRectype& clifo = cache().get(LF_CLIFO, cod);
|
|
|
|
|
|
|
|
cod = mov.get("CODVAL");
|
|
|
|
|
|
|
|
TToken_string key;
|
|
|
|
key.add(clifo.get("STATOPAIV"));
|
|
|
|
key.add(clifo.get("PAIV"));
|
|
|
|
key.add(cod); // Non e' chiaro se raggruppare per valuta!
|
|
|
|
key.add(rec.get("NATURA"));
|
|
|
|
key.add(rec.get("NOMENCL"));
|
1999-04-22 14:23:18 +00:00
|
|
|
key.add(rec.get("CONSEGNA"));
|
1999-02-22 15:19:07 +00:00
|
|
|
key.add(rec.get("TRASPORTO"));
|
|
|
|
key.add(rec.get("PAESE"));
|
1999-04-22 14:23:18 +00:00
|
|
|
key.add(rec.get("PAESEORIG")); // Campo solo per Acquisti
|
1999-02-22 15:19:07 +00:00
|
|
|
key.add(rec.get("PROV"));
|
|
|
|
|
|
|
|
TDati_riepilogo* data = (TDati_riepilogo*)_ass.objptr(key);
|
|
|
|
if (data == NULL)
|
|
|
|
{
|
|
|
|
data = new TDati_riepilogo(key, rec, cod);
|
|
|
|
_ass.add(key, data);
|
|
|
|
_arr.add(data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const TDati_riepilogo dr(key, rec, cod);
|
|
|
|
*data += dr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TGenerazione_mask
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TGenerazione_mask : public TIntra_mask
|
|
|
|
{
|
|
|
|
TRiepiloghi _riep;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual short type_field() const { return R_TIPO; }
|
|
|
|
virtual short period_field() const { return R_PERIODO_M; }
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool genera_riepiloghi();
|
|
|
|
|
|
|
|
TGenerazione_mask();
|
|
|
|
virtual ~TGenerazione_mask() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TGenerazione_mask::genera_riepiloghi()
|
|
|
|
{
|
|
|
|
const char tipo = get(R_TIPO)[0];
|
|
|
|
const int anno = get_int(R_ANNO);
|
|
|
|
const int peri = periodo();
|
|
|
|
int da_mese, a_mese;
|
|
|
|
switch (frequenza())
|
|
|
|
{
|
|
|
|
case 'T':
|
|
|
|
da_mese = (peri-1) * 3 + 1;
|
|
|
|
a_mese = da_mese+2;
|
|
|
|
break;
|
|
|
|
case 'A':
|
|
|
|
da_mese = 1; a_mese = 12;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
da_mese = a_mese = peri;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TDate da_data(1, da_mese, anno);
|
|
|
|
const TDate a_data(TDate::last_day(a_mese, anno), a_mese, anno);
|
|
|
|
|
|
|
|
TRectype filter_da(LF_INTRA), filter_a(LF_INTRA);
|
|
|
|
filter_da.put("DATAREG", da_data);
|
|
|
|
filter_a.put("DATAREG", a_data);
|
|
|
|
|
|
|
|
TRelation rel(LF_INTRA);
|
|
|
|
rel.add(LF_RINTRA, "NUMREG==NUMREG");
|
|
|
|
|
|
|
|
TString filter; filter << "TIPOMOV==\"" << tipo << '"';
|
|
|
|
TCursor cur(&rel, filter, 2, &filter_da, &filter_a);
|
|
|
|
const long items = cur.items();
|
|
|
|
if (items > 0)
|
|
|
|
{
|
|
|
|
TProgind pi(items, "Lettura movimenti intra...", TRUE, TRUE);
|
|
|
|
cur.freeze();
|
|
|
|
for (cur = 0; cur.pos() < items; ++cur)
|
|
|
|
{
|
|
|
|
pi.addstatus(1);
|
|
|
|
if (pi.iscancelled())
|
|
|
|
return warning_box("Operazione annullata");
|
|
|
|
bool rowok = rel.is_first_match(LF_RINTRA);
|
|
|
|
while (rowok)
|
|
|
|
{
|
|
|
|
_riep.add(rel.curr(LF_RINTRA), rel.curr());
|
|
|
|
rowok = rel.next_match(LF_RINTRA);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return warning_box("Non ci sono movimenti nel periodo specificato");
|
|
|
|
|
|
|
|
const int riepiloghi = _riep.sort();
|
|
|
|
if (riepiloghi > 0)
|
|
|
|
{
|
|
|
|
TProgind pi(riepiloghi, "Scrittura riepiloghi intra...", FALSE, TRUE);
|
|
|
|
TLocalisamfile riep(LF_RIEPRETT);
|
|
|
|
riep.put("TIPO", tipo);
|
|
|
|
riep.put("ANNO", anno);
|
|
|
|
riep.put("PERIODO", peri);
|
|
|
|
riep.put("NUMRIG", 1);
|
|
|
|
int err = riep.read();
|
|
|
|
for (int r = 0; r < riepiloghi; r++)
|
|
|
|
{
|
|
|
|
pi.addstatus(1);
|
|
|
|
riep.put("TIPO", tipo);
|
|
|
|
riep.put("ANNO", anno);
|
|
|
|
riep.put("PERIODO", peri);
|
|
|
|
riep.put("NUMRIG", r+1);
|
|
|
|
_riep[r].write(riep.curr());
|
|
|
|
|
|
|
|
const int werr = err == NOERR ? riep.rewrite() : riep.write();
|
|
|
|
if (werr != NOERR)
|
|
|
|
return error_box("Errore %d durante la scrittura dei riepiloghi", werr);
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
err = riep.next();
|
|
|
|
if (err == NOERR && riep.get_long("NUMRIG") == 1)
|
|
|
|
err = _iseof;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (err == NOERR)
|
|
|
|
{
|
|
|
|
riep.remove();
|
|
|
|
err = riep.next();
|
|
|
|
if (err == NOERR && riep.get_long("NUMRIG") == 1)
|
|
|
|
err = _iseof;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
TGenerazione_mask::TGenerazione_mask()
|
|
|
|
: TIntra_mask("in0500b")
|
|
|
|
{ }
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Generazione riepiloghi
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1999-04-22 14:23:18 +00:00
|
|
|
void genera_riepiloghi(char tipo, int anno, int periodo)
|
1999-02-22 15:19:07 +00:00
|
|
|
{
|
|
|
|
TGenerazione_mask m;
|
1999-04-22 14:23:18 +00:00
|
|
|
|
|
|
|
int num_fields = 0;
|
|
|
|
if (tipo > ' ' )
|
|
|
|
{
|
|
|
|
m.set(R_TIPO, tipo);
|
|
|
|
num_fields++;
|
|
|
|
}
|
|
|
|
if (anno > 0)
|
|
|
|
{
|
|
|
|
m.set(R_ANNO, anno);
|
|
|
|
num_fields++;
|
|
|
|
}
|
|
|
|
if (periodo > 0)
|
|
|
|
{
|
|
|
|
m.set(R_PERIODO_M, periodo);
|
|
|
|
m.set(R_PERIODO_T, periodo);
|
|
|
|
num_fields++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_fields == 3 || m.run() == K_ENTER)
|
1999-02-22 15:19:07 +00:00
|
|
|
m.genera_riepiloghi();
|
|
|
|
}
|