7d509dda34
git-svn-id: svn://10.65.10.50/trunk@6143 c028cbd2-c16b-5b4b-a496-9718f37d4682
642 lines
15 KiB
C++
Executable File
642 lines
15 KiB
C++
Executable File
#include <applicat.h>
|
|
#include <mask.h>
|
|
#include <printer.h>
|
|
#include <progind.h>
|
|
#include <real.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
#include <urldefid.h>
|
|
#include <utility.h>
|
|
|
|
#include "at3.h"
|
|
|
|
// nomi campi maschera
|
|
#include "at3200a.h"
|
|
|
|
// nomi dei campi
|
|
#include "soggetti.h"
|
|
#include "donaz.h"
|
|
#include "atstatd.h"
|
|
#include "sezioni.h"
|
|
|
|
// classe per la definizione di una riga di statistica
|
|
class TRigaMDxG : public TObject
|
|
{
|
|
int _anno, _mese;
|
|
TArray _valori;
|
|
|
|
protected:
|
|
const TRigaMDxG& copy(const TRigaMDxG& riga);
|
|
public:
|
|
const int anno() const { return _anno; }
|
|
const int mese() const { return _mese; }
|
|
TObject* dup() const { return new TRigaMDxG(*this); }
|
|
const TRigaMDxG& operator = (const TRigaMDxG& riga);
|
|
const real& operator [] (int colonna) const;
|
|
void aggiorna_valore(int colonna, const real& numero) ;
|
|
void azzera_valori();
|
|
// costruttore
|
|
TRigaMDxG(int anno, int mese) {_anno = anno; _mese = mese;}
|
|
// costruttore di copia
|
|
TRigaMDxG(const TRigaMDxG& riga) { copy(riga); }
|
|
virtual ~TRigaMDxG() {};
|
|
};
|
|
|
|
const TRigaMDxG& TRigaMDxG::copy(const TRigaMDxG& riga)
|
|
{
|
|
_anno = riga._anno;
|
|
_mese = riga._mese;
|
|
_valori = riga._valori;
|
|
return (*this);
|
|
}
|
|
|
|
const TRigaMDxG& TRigaMDxG::operator = (const TRigaMDxG& riga)
|
|
{
|
|
copy(riga);
|
|
return (*this);
|
|
}
|
|
|
|
const real& TRigaMDxG::operator [] (int colonna) const
|
|
{
|
|
real* valore = (real*)_valori.objptr(colonna);
|
|
if (valore == NULL)
|
|
return ZERO;
|
|
else
|
|
return *valore;
|
|
}
|
|
|
|
void TRigaMDxG::aggiorna_valore(int colonna, const real& numero)
|
|
{
|
|
real* valore = (real*)_valori.objptr(colonna);
|
|
if (valore == NULL)
|
|
_valori.add(new real(numero), colonna);
|
|
else
|
|
*valore += numero;
|
|
}
|
|
|
|
void TRigaMDxG::azzera_valori()
|
|
{
|
|
_valori.destroy();
|
|
}
|
|
|
|
class TMensileDonxGr : public TApplication
|
|
{
|
|
TMask* _msk;
|
|
TRelation* _rel;
|
|
TCursor* _cur;
|
|
TLocalisamfile* _sezioni;
|
|
TLocalisamfile* _soggetti;
|
|
TLocalisamfile* _donaz;
|
|
TLocalisamfile* _atstatd;
|
|
TDate _dataini, _datafin;
|
|
TAssoc_array* _colonne;
|
|
TArray _righe; // array per riepilogo donazioni
|
|
TString16 _sezini, _sotini, _sezfin, _sotfin;
|
|
|
|
protected:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual bool menu(MENU_TAG m);
|
|
virtual TMask& get_mask() { return *_msk; }
|
|
virtual TRelation* get_relation() const { return _rel; }
|
|
int data2row(const int anno, const int mese);
|
|
TString16 gruppo2col(TString16 gruppo, TString16 rh);
|
|
bool riepilogo();
|
|
bool stampa();
|
|
bool crea_colonne();
|
|
bool crea_righe();
|
|
void azzera_righe();
|
|
void stampa_sezione(TString16 codsez, TString16 codsot);
|
|
void crea_intestazione();
|
|
TString16 int2month(const int month);
|
|
public:
|
|
TMensileDonxGr() {}
|
|
|
|
};
|
|
|
|
HIDDEN inline TMensileDonxGr& app() { return (TMensileDonxGr&) main_app(); }
|
|
|
|
TString16 TMensileDonxGr::int2month(const int month)
|
|
{
|
|
TString16 mese = "";
|
|
switch (month)
|
|
{
|
|
case 1:
|
|
mese << "GENNAIO ";
|
|
break;
|
|
case 2:
|
|
mese << "FEBBRAIO ";
|
|
break;
|
|
case 3:
|
|
mese << "MARZO ";
|
|
break;
|
|
case 4:
|
|
mese << "APRILE ";
|
|
break;
|
|
case 5:
|
|
mese << "MAGGIO ";
|
|
break;
|
|
case 6:
|
|
mese << "GIUGNO ";
|
|
break;
|
|
case 7:
|
|
mese << "LUGLIO ";
|
|
break;
|
|
case 8:
|
|
mese << "AGOSTO ";
|
|
break;
|
|
case 9:
|
|
mese << "SETTEMBRE";
|
|
break;
|
|
case 10:
|
|
mese << "OTTOBRE ";
|
|
break;
|
|
case 11:
|
|
mese << "NOVEMBRE ";
|
|
break;
|
|
case 12:
|
|
mese << "DICEMBRE ";
|
|
break;
|
|
}
|
|
return mese;
|
|
}
|
|
|
|
int TMensileDonxGr::data2row(const int anno, const int mese)
|
|
{
|
|
const int annoini = _dataini.year();
|
|
return (anno-annoini)*12 + mese;
|
|
}
|
|
|
|
bool TMensileDonxGr::crea_colonne()
|
|
{
|
|
_colonne->destroy();
|
|
real contatore(ZERO);
|
|
real* oggetto = new real(contatore);
|
|
const char* indice = "0P";
|
|
_colonne->add(indice,(TObject*)oggetto);
|
|
indice = "0N";
|
|
contatore = contatore+1;
|
|
real* oggetto2 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto2);
|
|
indice = "AP";
|
|
contatore = contatore+1;
|
|
real* oggetto3 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto3);
|
|
indice = "AN";
|
|
contatore = contatore+1;
|
|
real* oggetto4 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto4);
|
|
indice = "BP";
|
|
contatore = contatore+1;
|
|
real* oggetto5 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto5);
|
|
indice = "BN";
|
|
contatore = contatore+1;
|
|
real* oggetto6 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto6);
|
|
indice = "CP";
|
|
contatore = contatore+1;
|
|
real* oggetto7 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto7);
|
|
indice = "CN";
|
|
contatore = contatore+1;
|
|
real* oggetto8 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto8);
|
|
indice = "NN";
|
|
contatore = contatore+1;
|
|
real* oggetto9 = new real(contatore);
|
|
_colonne->add(indice,(TObject*)oggetto9);
|
|
return TRUE;
|
|
}
|
|
|
|
TString16 TMensileDonxGr::gruppo2col(TString16 gruppo, TString16 rh)
|
|
{
|
|
TString16 indice = "NN";
|
|
if (gruppo == "0")
|
|
indice = "0";
|
|
if (gruppo == "A")
|
|
indice = "A";
|
|
if (gruppo == "A1")
|
|
indice = "A";
|
|
if (gruppo == "A2")
|
|
indice = "A";
|
|
if (gruppo == "A1B")
|
|
indice = "C";
|
|
if (gruppo == "A2B")
|
|
indice = "C";
|
|
if (gruppo == "AB")
|
|
indice = "C";
|
|
if (gruppo == "B")
|
|
indice = "B";
|
|
if (rh.empty())
|
|
indice = "NN";
|
|
if (rh == "POS")
|
|
indice << "P";;
|
|
if (rh == "NEG")
|
|
indice << "N";;
|
|
return indice;
|
|
}
|
|
bool TMensileDonxGr::crea_righe()
|
|
{
|
|
int anno = _dataini.year();
|
|
int meseini, mesefin;
|
|
while (anno<=_datafin.year())
|
|
{
|
|
if (anno == _dataini.year())
|
|
meseini = _dataini.month();
|
|
else
|
|
meseini = 1;
|
|
if (anno == _datafin.year())
|
|
mesefin = _datafin.month();
|
|
else
|
|
mesefin = 12;
|
|
for (int mese=meseini;mese<=mesefin;mese++)
|
|
_righe.add(new TRigaMDxG(anno, mese), data2row(anno, mese));
|
|
anno++;
|
|
}
|
|
return _righe.items()>0;
|
|
}
|
|
|
|
bool TMensileDonxGr::create()
|
|
{
|
|
TApplication::create();
|
|
_msk = new TMask("at3200a");
|
|
_rel = new TRelation(LF_DONAZ);
|
|
_rel->add(LF_SOGGETTI, "CODICE==CODICE");
|
|
_soggetti = new TLocalisamfile(LF_SOGGETTI);
|
|
_donaz = new TLocalisamfile(LF_DONAZ);
|
|
_atstatd = new TLocalisamfile(LF_ATSTATD);
|
|
_sezioni = new TLocalisamfile(LF_SEZIONI);
|
|
_colonne = new TAssoc_array();
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
return TRUE;
|
|
}
|
|
|
|
bool TMensileDonxGr::destroy()
|
|
{
|
|
delete _rel;
|
|
delete _msk;
|
|
delete _soggetti;
|
|
delete _donaz;
|
|
delete _atstatd;
|
|
delete _sezioni;
|
|
delete _colonne;
|
|
return TApplication::destroy();
|
|
}
|
|
|
|
bool TMensileDonxGr::menu(MENU_TAG m)
|
|
{
|
|
TMask& msk = get_mask();
|
|
KEY tasto;
|
|
tasto = msk.run();
|
|
if (tasto == K_ENTER)
|
|
{
|
|
_dataini = msk.get(F_DATAINI);
|
|
_datafin = msk.get(F_DATAFIN);
|
|
_sezini = _msk->get(F_SEZINI);
|
|
_sotini = _msk->get(F_SOTINI);
|
|
_sezfin = _msk->get(F_SEZFIN);
|
|
_sotfin = _msk->get(F_SOTFIN);
|
|
if (riepilogo())
|
|
stampa();
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
void TMensileDonxGr::crea_intestazione()
|
|
{
|
|
TPrintrow row;
|
|
TString256 sep;
|
|
sep = "MENSILE DONAZIONI PER GRUPPO E RH";
|
|
sep.center_just(80);
|
|
row.put(sep);
|
|
row.put("@>", 1);
|
|
row.put("Pag. @#", 70);
|
|
printer().setheaderline(2, row);
|
|
row.reset();
|
|
sep = "";
|
|
if (_dataini.ok())
|
|
{
|
|
sep << " dal ";
|
|
sep << _dataini.string();
|
|
}
|
|
if (_datafin.ok())
|
|
{
|
|
sep << " al ";
|
|
sep << _datafin.string();
|
|
}
|
|
sep.center_just(80);
|
|
row.put(sep);
|
|
printer().setheaderline(3, row);
|
|
row.reset();
|
|
printer().setheaderline(4, row);
|
|
sep = "Mese ";
|
|
int pos = 21;
|
|
sep.overwrite("0 POS 0 NEG A POS A NEG B POS B NEG AB POS AB NEG NON DEF. TOTALE",pos);
|
|
//sep.overwrite("Totale",pos);
|
|
row.put(sep);
|
|
printer().setheaderline(5, row);
|
|
sep = "";
|
|
sep.fill('-');
|
|
row.reset();
|
|
row.put(sep);
|
|
printer().setheaderline(6, row);
|
|
}
|
|
|
|
bool TMensileDonxGr::stampa()
|
|
{
|
|
if (printer().open())
|
|
{
|
|
crea_intestazione();
|
|
TRelation* relstat = new TRelation(LF_ATSTATD);
|
|
TCursor* curstat = new TCursor(relstat, "", 1);
|
|
TString16 oldsez = "**";
|
|
TString16 oldsot = "**";
|
|
double numero;
|
|
TString16 actsez, actsot, gruppo, rh;
|
|
int anno, mese;
|
|
long last = curstat->items();
|
|
for ( *curstat=0; curstat->pos() < last; ++(*curstat) )
|
|
{
|
|
actsez = curstat->curr().get(ATS_CODSEZ);
|
|
actsot = curstat->curr().get(ATS_CODSOT);
|
|
anno = curstat->curr().get_int(ATS_ANNO);
|
|
mese = curstat->curr().get_int(ATS_MESE);
|
|
gruppo = curstat->curr().get(ATS_GRUPPO);
|
|
rh = curstat->curr().get(ATS_RH);
|
|
numero = (double)curstat->curr().get_int(ATS_NUMERO);
|
|
if (actsez != oldsez || actsot != oldsot)
|
|
{
|
|
if (oldsez != "**" && oldsot != "**")
|
|
{
|
|
stampa_sezione(oldsez,oldsot);
|
|
azzera_righe();
|
|
}
|
|
oldsez = actsez;
|
|
oldsot = actsot;
|
|
}
|
|
TRigaMDxG& riga = (TRigaMDxG&)_righe[data2row(anno,mese)];
|
|
TString16 indcol = gruppo2col(gruppo,rh);
|
|
real& colonna = (real&)_colonne->find((const char*)indcol);
|
|
real n = numero;
|
|
riga.aggiorna_valore((int) colonna.integer(),n);
|
|
}
|
|
if (oldsez != "**" && oldsot != "**")
|
|
stampa_sezione(oldsez,oldsot);
|
|
delete curstat;
|
|
delete relstat;
|
|
printer().close();
|
|
return TRUE;
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
void TMensileDonxGr::azzera_righe()
|
|
{
|
|
int anno = _dataini.year();
|
|
int meseini, mesefin;
|
|
while (anno<=_datafin.year())
|
|
{
|
|
if (anno == _dataini.year())
|
|
meseini = _dataini.month();
|
|
else
|
|
meseini = 1;
|
|
if (anno == _datafin.year())
|
|
mesefin = _datafin.month();
|
|
else
|
|
mesefin = 12;
|
|
for (int mese=meseini;mese<=mesefin;mese++)
|
|
{
|
|
TRigaMDxG& riga = (TRigaMDxG&)_righe[data2row(anno,mese)];
|
|
riga.azzera_valori();
|
|
}
|
|
anno++;
|
|
}
|
|
}
|
|
|
|
void TMensileDonxGr::stampa_sezione(TString16 codsez, TString16 codsot)
|
|
{
|
|
TPrintrow row;
|
|
TString256 rigastampa;
|
|
rigastampa = "Sezione: ";
|
|
rigastampa << codsez;
|
|
if (codsot.not_empty())
|
|
{
|
|
rigastampa << "/";
|
|
rigastampa << codsot;
|
|
}
|
|
rigastampa << " ";
|
|
TLocalisamfile sezioni(LF_SEZIONI);
|
|
sezioni.setkey(1);
|
|
sezioni.zero();
|
|
sezioni.put(SEZ_CODSEZ,codsez);
|
|
sezioni.put(SEZ_CODSOT,codsot);
|
|
if (sezioni.read() == NOERR)
|
|
{
|
|
TString80 den = sezioni.get(SEZ_DENSEZ);
|
|
rigastampa << den;
|
|
den = sezioni.get(SEZ_DENSOT);
|
|
if (den.not_empty())
|
|
{
|
|
rigastampa << "/";
|
|
rigastampa << den;
|
|
}
|
|
}
|
|
rigastampa.center_just(80);
|
|
row.put(rigastampa);
|
|
printer().setheaderline(1, row);
|
|
|
|
TRigaMDxG rigatotali(0,0);
|
|
int anno = _dataini.year();
|
|
int meseini, mesefin;
|
|
real totalemese = ZERO;
|
|
TString16 valore;
|
|
while (anno<=_datafin.year())
|
|
{
|
|
if (anno == _dataini.year())
|
|
meseini = _dataini.month();
|
|
else
|
|
meseini = 1;
|
|
if (anno == _datafin.year())
|
|
mesefin = _datafin.month();
|
|
else
|
|
mesefin = 12;
|
|
for (int mese=meseini;mese<=mesefin;mese++)
|
|
{
|
|
TRigaMDxG& riga = (TRigaMDxG&)_righe[data2row(anno,mese)];
|
|
row.reset();
|
|
rigastampa = "";
|
|
rigastampa.format("%s %4d", (const char*)int2month(mese), anno);
|
|
totalemese = ZERO;
|
|
int pos = 16;
|
|
for (int i=0;i<_colonne->items();i++)
|
|
{
|
|
rigatotali.aggiorna_valore(i,riga[i]);
|
|
totalemese+=riga[i];
|
|
valore = "";
|
|
valore.format("%8d",riga[i].integer());
|
|
rigastampa.overwrite((const char*)valore, pos);
|
|
pos = pos+8;
|
|
}
|
|
valore = "";
|
|
valore.format("%8d",totalemese.integer());
|
|
rigastampa.overwrite((const char*)valore, pos+4);
|
|
row.put((const char*) rigastampa);
|
|
printer().print(row);
|
|
}
|
|
anno++;
|
|
}
|
|
// stampa totali per sezione
|
|
rigastampa = "";
|
|
rigastampa.fill('-');
|
|
row.reset();
|
|
row.put(rigastampa);
|
|
printer().print(row);
|
|
row.reset();
|
|
rigastampa = "";
|
|
rigastampa = "Totale periodo";
|
|
totalemese = ZERO;
|
|
int pos = 16;
|
|
for (int i=0;i<_colonne->items();i++)
|
|
{
|
|
totalemese+=rigatotali[i];
|
|
valore = "";
|
|
valore.format("%8d",rigatotali[i].integer());
|
|
rigastampa.overwrite((const char*)valore, pos);
|
|
pos = pos+8;
|
|
}
|
|
valore = "";
|
|
valore.format("%8d",totalemese.integer());
|
|
rigastampa.overwrite((const char*)valore, pos+4);
|
|
row.put((const char*) rigastampa);
|
|
printer().print(row);
|
|
printer().formfeed();
|
|
}
|
|
|
|
bool TMensileDonxGr::riepilogo()
|
|
{
|
|
if (crea_colonne() && crea_righe())
|
|
{
|
|
// cancello i risultati della elaborazione precedente
|
|
TLocalisamfile stat(LF_ATSTATD);
|
|
for (stat.first(); !stat.eof(); stat.next())
|
|
stat.remove();
|
|
stat.setkey(1);
|
|
// filtro per data
|
|
TRectype da(LF_DONAZ);
|
|
TRectype a (LF_DONAZ);
|
|
if (_dataini.ok())
|
|
da.put(DON_DATADON, _dataini);
|
|
if (_datafin.ok())
|
|
a.put(DON_DATADON, _datafin);
|
|
_cur = new TCursor(_rel, "", 2, &da, &a);
|
|
TString256 filtro = "";
|
|
|
|
// filtro per sezione/sottogruppo
|
|
if (_sezini.not_empty())
|
|
{
|
|
if (filtro.empty())
|
|
filtro = format("(90->CODSEZ >= \"%s\")",(const char*)_sezini);
|
|
else
|
|
{
|
|
filtro << " && ";
|
|
filtro << format("(90->CODSEZ >= \"%s\")",(const char*)_sezini);
|
|
}
|
|
if (_sotini.not_empty())
|
|
{
|
|
if (filtro.empty())
|
|
filtro = format("(90->CODSOT >= \"%s\")",(const char*)_sotini);
|
|
else
|
|
{
|
|
filtro << " && ";
|
|
filtro << format("(90->CODSOT >= \"%s\")",(const char*)_sotini);
|
|
}
|
|
}
|
|
}
|
|
if (_sezfin.not_empty())
|
|
{
|
|
if (filtro.empty())
|
|
filtro = format("(90->CODSEZ <= \"%s\")",(const char*)_sezfin);
|
|
else
|
|
{
|
|
filtro << " && ";
|
|
filtro << format("(90->CODSEZ <= \"%s\")",(const char*)_sezfin);
|
|
}
|
|
if (_sotfin.not_empty())
|
|
{
|
|
if (filtro.empty())
|
|
filtro = format("(90->CODSOT <= \"%s\")",(const char*)_sotfin);
|
|
else
|
|
{
|
|
filtro << " && ";
|
|
filtro << format("(90->CODSOT <= \"%s\")",(const char*)_sotfin);
|
|
}
|
|
}
|
|
}
|
|
_cur->setfilter((const char*) filtro, TRUE);
|
|
TString16 codsez, codsot, gruppo, rh;
|
|
TDate datadon;
|
|
int anno, mese;
|
|
long numero;
|
|
TRectype& recdon = _cur->curr();
|
|
TRectype& recsog = _cur->curr(LF_SOGGETTI);
|
|
long last = _cur->items();
|
|
TProgind prg (last, "Elaborazione in corso... Prego attendere", FALSE, TRUE, 30);
|
|
for ( *_cur=0; _cur->pos() < last; ++(*_cur) )
|
|
{
|
|
prg.addstatus(1);
|
|
codsez = recdon.get(DON_CODSEZ);
|
|
codsot = recdon.get(DON_CODSOT);
|
|
if (codsez.empty())
|
|
{
|
|
codsez = recsog.get(SOG_CODSEZ);
|
|
codsot = recsog.get(SOG_CODSOT);
|
|
}
|
|
datadon = recdon.get_date(DON_DATADON);
|
|
anno = datadon.year();
|
|
mese = datadon.month();
|
|
gruppo = recsog.get(SOG_GRUPPOAB0);
|
|
rh = recsog.get(SOG_RHANTID);
|
|
stat.zero();
|
|
stat.put(ATS_CODSEZ, codsez);
|
|
stat.put(ATS_CODSOT, codsot);
|
|
stat.put(ATS_ANNO, anno);
|
|
stat.put(ATS_MESE, mese);
|
|
stat.put(ATS_TIPODON, " ");
|
|
stat.put(ATS_GRUPPO, gruppo);
|
|
stat.put(ATS_RH, rh);
|
|
if (stat.read() == NOERR)
|
|
{
|
|
numero = stat.get_long(ATS_NUMERO);
|
|
numero++;
|
|
stat.put(ATS_NUMERO, numero);
|
|
stat.rewrite();
|
|
}
|
|
else
|
|
{
|
|
stat.zero();
|
|
stat.put(ATS_CODSEZ, codsez);
|
|
stat.put(ATS_CODSOT, codsot);
|
|
stat.put(ATS_ANNO, anno);
|
|
stat.put(ATS_MESE, mese);
|
|
stat.put(ATS_TIPODON, " ");
|
|
stat.put(ATS_GRUPPO, gruppo);
|
|
stat.put(ATS_RH, rh);
|
|
numero = 1;
|
|
stat.put(ATS_NUMERO, numero);
|
|
stat.write();
|
|
}
|
|
}
|
|
return (stat.eod() > 0);
|
|
}
|
|
else
|
|
return FALSE;
|
|
}
|
|
|
|
int at3200(int argc, char* argv[])
|
|
{
|
|
TMensileDonxGr a;
|
|
a.run(argc, argv, "Mensile donazioni per gruppo e rh");
|
|
return 0;
|
|
} |