diff --git a/at/at9300.cpp b/at/at9300.cpp index 30b7c8199..add98b0b7 100755 --- a/at/at9300.cpp +++ b/at/at9300.cpp @@ -40,7 +40,9 @@ class TProv2com: public TSkeleton_application TIsamtempfile* _filesto; TLocalisamfile* _soggetti; TRecord_array* _sdonazioni; // sheet donazioni + TRecord_array* _scontrolli; // sheet controlli long _lastcod; + bool _print_header; protected: virtual bool create(void); @@ -48,6 +50,7 @@ protected: virtual bool destroy(void) ; void agg_anagrafica(const TRectype& recsog, const bool aggiorna); void agg_donazione(const TRectype& recsog, const TRectype& recdon); + void agg_controllo(const TRectype& recsog, const TRectype& reccon); void transfer(); void print_line(const TString& message=""); @@ -57,6 +60,21 @@ public: virtual ~TProv2com() {} }; +static int compare_date(const TObject** o1, const TObject** o2) +{ + const TRectype& s1 = *((TRectype*)*o1); + const TRectype& s2 = *((TRectype*)*o2); + + const TDate d1(s1.get(CON_DATACON)); + const TDate d2(s2.get(CON_DATACON)); + + int d=0; + if (d1>d2) d=+1; + else + if (d1rewrite(rec); - print_line(intestazione); + if (!_print_header) + { + print_line(intestazione); + _print_header = TRUE; + } message = " INSERITA DONAZIONE in data "; message << datadon.string(); print_line(message); @@ -393,6 +418,67 @@ void TProv2com::agg_donazione(const TRectype& recsog, const TRectype& recdon) } } +void TProv2com::agg_controllo(const TRectype& recsog, const TRectype& reccon) +{ + TString intestazione = ""; + TString message = ""; + const TString80 cognome = recsog.get(SOG_COGNOME); + const TString80 nome = recsog.get(SOG_NOME); + const TDate datanasc = recsog.get_date(SOG_DATANASC); + _soggetti->setkey(2); + TRectype& rec = _rel->curr(); + rec.zero(); + rec.put(SOG_COGNOME, cognome); + rec.put(SOG_NOME, nome); + rec.put(SOG_DATANASC, datanasc); + intestazione = cognome; + intestazione << " "; + intestazione << nome; + intestazione << " "; + intestazione << datanasc.string(); + if (_soggetti->read(rec)==NOERR) + { + const TDate& datacon = reccon.get_date(CON_DATACON); + TLocalisamfile contsan(LF_CONTSAN); + contsan.setkey(2); + contsan.zero(); + contsan.put(CON_CODICE, rec.get(SOG_CODICE)); + contsan.put(CON_DATACON, datacon); + if (contsan.read()==NOERR) + { + // esiste gia il controllo + } + else + { + TRectype* key = new TRectype(LF_CONTSAN); + key->put(CON_CODICE, rec.get(SOG_CODICE)); + int err = _scontrolli->read(key); + if (err == NOERR) + { + TRectype recnew(reccon); + recnew.put(CON_CODICE, rec.get_long(SOG_CODICE)); + recnew.put(CON_PROGCON, _scontrolli->rows()+1); + _scontrolli->add_row(recnew); + _scontrolli->sort(compare_date); + _scontrolli->rewrite(); + calcola_donazioni_lib(rec, _sdonazioni); + TDate oggi(TODAY); + rec.put(SOG_DATAULTAGG, oggi); + rec.put(SOG_UTENULTAGG, "PROV"); + _soggetti->rewrite(rec); + if (!_print_header) + { + print_line(intestazione); + _print_header = TRUE; + } + const char* tipocon = reccon.get(CON_TIPOCON); + message.format(" INSERITO CONTROLLO %s in data %s", tipocon, datacon.string()); + print_line(message); + } + } + } +} + int at9300(int argc, char* argv[]) {