#include #include #include #include #include #include #include #include "at0.h" #include "atlib.h" #define ALIAS_TCS 200 #define ALIAS_CTD 700 #define FINE_SOSPENSIONE "FS" // nomi campi maschera #include "at0700a.h" // nomi dei campi #include "soggetti.h" #include "contsan.h" #include "idoneita.h" #include "sezioni.h" class TSbloccoSospesi : public TPrintapp { TMask* _msk; TRelation* _rel; TLocalisamfile* _contsan; TLocalisamfile* _idoneita; TRecord_array* _scontrolli; TRecord_array* _sidoneita; int _cur; int _contatore, _totale; TDate _data_sblocco; // data scadenza sospensione fino a _data_sblocco TDate _data_stampa; TString16 _tiposo; // tipo sospesione da sbloccare TString16 _codsez, _codsot; bool _definitiva, _anchedimessi; TParagraph_string _cognome_nome, _operazione; TString16 _finesospensione; int _intsi_f1, _intsi_f2, _intsi_m, _intaf_m, _etadonne; static bool filter_func_sbloccosospesi(const TRelation* rel); protected: virtual bool user_create(); virtual bool user_destroy(); virtual bool set_print(int m); virtual void set_page(int file, int cnt); virtual bool preprocess_page(int file, int counter); virtual print_action postprocess_print(int file, int counter); public: void filtra_sezioni(); void crea_intestazione(); void header_sezione(const TString16 codsez, const TString16 codsot); void footer_sezione(); void fine_stampa(); TSbloccoSospesi() : _data_sblocco(TODAY), _data_stampa(TODAY), _tiposo(""), _cognome_nome("",25), _operazione("",40) {} }; HIDDEN inline TSbloccoSospesi& app() { return (TSbloccoSospesi&) main_app(); } print_action TSbloccoSospesi::postprocess_print(int file, int counter) { if (_contatore > 0) footer_sezione(); fine_stampa(); return NEXT_PAGE; } void TSbloccoSospesi::fine_stampa() { // stampa totale soggetti a fine stampa reset_footer(); TString sep(80); sep.fill('-'); set_footer(2, (const char *) sep); if (_totale > 0) { if (_totale != _contatore) set_footer(3,"TOTALE SOGGETTI SBLOCCATI %d", _totale); } else set_footer(3,"NON CI SONO SOGGETTI SOSPESI DA SBLOCCARE"); printer().formfeed(); reset_footer(); } void TSbloccoSospesi::footer_sezione() { reset_footer(); TString sep(80); sep.fill('-'); set_footer(2, (const char *) sep); set_footer(3,"TOTALE SOGGETTI STAMPATI %d", _contatore); printer().formfeed(); reset_footer(); } void TSbloccoSospesi::filtra_sezioni() { const TString16 sezini = _msk->get(F_SEZINI); const TString16 sotini = _msk->get(F_SOTINI); const TString16 sezfin = _msk->get(F_SEZFIN); const TString16 sotfin = _msk->get(F_SOTFIN); TRectype da(LF_SOGGETTI); TRectype a(LF_SOGGETTI); if (sezini.not_empty()) da.put(SOG_CODSEZ, sezini); if (sotini.not_empty()) da.put(SOG_CODSOT, sotini); if (sezfin.not_empty()) a.put(SOG_CODSEZ, sezfin); if (sotfin.not_empty()) a.put(SOG_CODSOT, sotfin); current_cursor()->setregion(da, a); } bool TSbloccoSospesi::preprocess_page(int file, int counter) { TRectype& recsog = current_cursor()->curr(); TString80 nome = recsog.get(SOG_COGNOME); nome << " "; nome << recsog.get(SOG_NOME); _cognome_nome = nome; const TString16 stato = recsog.get(SOG_STATO); const TString16 pros_stato = recsog.get(SOG_PROS_STATO); const TString16 statosi = recsog.get(SOG_STATOSI); const TString16 statoaf = recsog.get(SOG_STATOAF); const TDate datafine = recsog.get_date(SOG_DATA_PROS); TDate datafinesi(NULLDATE); TDate datafineaf(NULLDATE); if (statosi == "SO") datafinesi = recsog.get_date(SOG_FINESOSSI); if (statoaf == "SO") datafineaf = recsog.get_date(SOG_FINESOSAF); TString80 operazione = ""; if (stato=="SO" && pros_stato==FINE_SOSPENSIONE && datafine.ok() && datafine<=app()._data_sblocco) { const TDate datastato = recsog.get_date(SOG_DATASTATO); operazione << datastato.string(); operazione << " "; operazione << datafine.string(); operazione << " "; operazione << "-- -- -- SO FS"; } else if (statosi == "SO" && datafinesi.ok() && datafinesi <= app()._data_sblocco) { const TDate datastato = recsog.get_date(SOG_DATASI); operazione << datastato.string(); operazione << " "; operazione << datafinesi.string(); operazione << " "; operazione << "SI SO ID"; } else if (statoaf == "SO" && datafineaf.ok() && datafineaf <= app()._data_sblocco) { const TDate datastato = recsog.get_date(SOG_DATAAF); operazione << datastato.string(); operazione << " "; operazione << datafineaf.string(); operazione << " "; operazione << "AF SO ID"; } _operazione = operazione; if (_definitiva) { if (stato == "SO" && datafine.ok() && datafine <= app()._data_sblocco) { TRectype* key = new TRectype(LF_CONTSAN); long codice = recsog.get_long(SOG_CODICE); key->put(CON_CODICE, codice); int err = _scontrolli->read(key); int progcon = _scontrolli->rows()+1; TRectype& reccon = _contsan->curr(); reccon.zero(); reccon.put(CON_CODICE, codice); reccon.put(CON_PROGCON, progcon); reccon.put(CON_DATACON, _data_stampa); reccon.put(CON_TIPOCON, FINE_SOSPENSIONE); _scontrolli->add_row(reccon); _scontrolli->rewrite(); //current_cursor()->file().rewrite(); } if ((statosi == "SO" && datafinesi.ok() && datafinesi <= app()._data_sblocco) || (statoaf == "SO" && datafineaf.ok() && datafineaf <= app()._data_sblocco)) { TRectype* key = new TRectype(LF_IDONEITA); long codice = recsog.get_long(SOG_CODICE); key->put(IDO_CODICE, codice); int err = _sidoneita->read(key); if (statosi == "SO" && datafinesi.ok() && datafinesi <= app()._data_sblocco) { int progido = _sidoneita->rows()+1; TRectype& recido = _idoneita->curr(); recido.zero(); recido.put(IDO_CODICE, codice); recido.put(IDO_PROGIDO, progido); recido.put(IDO_DATAIDO, _data_stampa); recido.put(IDO_IDO_SOS, "ID"); recido.put(IDO_TIPOIDO, "SI"); recido.put(IDO_INTERVALLO, recsog.get(SOG_INTSI)); if (recsog.get_int(SOG_INTSI) == 0) { TString16 sesso = recsog.get(SOG_SESSO); if (sesso == 2) { TDate datanasc = recsog.get_date(SOG_DATANASC); int eta = _data_stampa.year() - datanasc.year(); if(eta <= _etadonne) recido.put(IDO_INTERVALLO, _intsi_f1); else recido.put(IDO_INTERVALLO, _intsi_f2); } else recido.put(IDO_INTERVALLO, _intsi_m); } _sidoneita->add_row(recido); _sidoneita->rewrite(); } if (statoaf == "SO" && datafineaf.ok() && datafineaf <= app()._data_sblocco) { int progido = _sidoneita->rows()+1; TRectype& recido = _idoneita->curr(); recido.zero(); recido.put(IDO_CODICE, codice); recido.put(IDO_PROGIDO, progido); recido.put(IDO_DATAIDO, _data_stampa); recido.put(IDO_IDO_SOS, "ID"); recido.put(IDO_TIPOIDO, "AF"); recido.put(IDO_INTERVALLO, recsog.get(SOG_INTAF)); if (recsog.get_int(SOG_INTAF) == 0) recido.put(IDO_INTERVALLO, _intaf_m); _sidoneita->add_row(recido); _sidoneita->rewrite(); } con_reord(recsog, _scontrolli, _sidoneita); current_cursor()->file().rewrite(); } } // salto pagina se cambio sezione const TString16 codsez = recsog.get(SOG_CODSEZ); const TString16 codsot = recsog.get(SOG_CODSOT); if ((_codsez!=codsez)||(_codsot!=codsot)) { if ((_codsez != "**") && (_contatore > 0)) footer_sezione(); _contatore = 0; _codsez = codsez; _codsot = codsot; header_sezione(codsez, codsot); } _contatore++; _totale++; return TRUE; } void TSbloccoSospesi::set_page(int file, int cnt) { set_row(1,"@0g@pn", FLD(LF_SOGGETTI,SOG_CODICE,"########")); set_row(1,"@9g@S", FLD(LF_SOGGETTI,SOG_CATDON)); set_row(1,"@12g#a", &_cognome_nome); set_row(1,"@38g@ld", FLD(LF_SOGGETTI,SOG_DATANASC)); set_row(1,"@49g@S", FLD(LF_SOGGETTI,SOG_TESSAVIS)); //set_row(1,"@57g@ld", FLD(LF_SOGGETTI,SOG_DATASTATO)); //set_row(1,"@68g@ld", FLD(LF_SOGGETTI,SOG_DATA_PROS)); //set_row(1,"@79g#a", &_operazione); set_row(1,"@57g#a", &_operazione); } bool TSbloccoSospesi::filter_func_sbloccosospesi(const TRelation* rel) { bool filtrato = TRUE; TRectype& recsog = rel->lfile().curr(); if (!app()._anchedimessi) filtrato = !(rel->lfile(-ALIAS_CTD).get_bool("B0")); if (filtrato) { filtrato = FALSE; const TString16 stato = recsog.get(SOG_STATO); const TString16 statopros = recsog.get(SOG_PROS_STATO); const TString16 statosi = recsog.get(SOG_STATOSI); const TString16 statoaf = recsog.get(SOG_STATOAF); TDate datafine(NULLDATE); if (statopros == "FS") datafine = recsog.get_date(SOG_DATA_PROS); TDate datafinesi(NULLDATE); TDate datafineaf(NULLDATE); if (statosi == "SO") datafinesi = recsog.get_date(SOG_FINESOSSI); if (statoaf == "SO") datafineaf = recsog.get_date(SOG_FINESOSAF); filtrato = (datafine.ok()) && (datafine <= app()._data_sblocco); if ((!filtrato) && (datafinesi.ok() || datafineaf.ok())) filtrato = ((datafinesi.ok() && (datafinesi <= app()._data_sblocco)) || (datafineaf.ok() && (datafineaf <= app()._data_sblocco))); } return filtrato; } void TSbloccoSospesi::header_sezione(const TString16 codsez, const TString16 codsot) { const TString80 densez = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSEZ); const TString80 densot = current_cursor()->curr(LF_SEZIONI).get(SEZ_DENSOT); TString intestazione(100); intestazione = "Sezione: "; intestazione << codsez; intestazione << "/"; intestazione << codsot; intestazione << " "; intestazione << densez; if ((densot.ok())&& (densot.not_empty())) { intestazione << "/"; intestazione << densot; } intestazione.center_just(); set_header(1,"@0g%s", (const char*) intestazione); return; } bool TSbloccoSospesi::set_print(int) { KEY tasto; tasto = _msk->run(); if (tasto == K_ENTER) { _codsez = "**"; _codsot = "**"; _data_sblocco = _msk->get(F_DATA); _tiposo = _msk->get(F_TIPO); _definitiva = _msk->get_bool(F_DEFINITIVA); _anchedimessi = _msk->get_bool(F_ANCHEDIMESSI); _contatore = 0; _totale = 0; reset_files(); add_file(LF_SOGGETTI); filtra_sezioni(); // filtro per tipo sospensione TString256 filtro = ""; if (_tiposo.not_empty()) filtro.format("(((STATO == \"%s\") && (PROS_STATO == \"FS\"))",(const char*)_tiposo); else filtro << "(((TCS->S6 == \"S\") && (PROS_STATO == \"FS\"))"; filtro << " || (STATOSI == \"SO\") || (STATOAF == \"SO\"))"; current_cursor()->setfilter(filtro, TRUE); current_cursor()->set_filterfunction(filter_func_sbloccosospesi,TRUE); reset_print(); crea_intestazione(); return TRUE; } else return FALSE; } void TSbloccoSospesi::crea_intestazione() { reset_header(); TString sep(100); if (_definitiva) sep = "SBLOCCO DEFINITIVO SOSPESI "; else sep = "STAMPA PROVVISORIA PER SBLOCCO SOSPESI "; sep << _tiposo; sep << " FINO ALLA DATA "; TString16 data_stampa = _data_sblocco.string(); sep << data_stampa; sep.center_just(); set_header(2, "@0g%s", (const char*) sep); data_stampa = _data_stampa.string(); set_header(2,"@0g%10s", (const char*) data_stampa); sep = ""; sep << "Pag. @#"; set_header(2, "@88g%s", (const char*) sep); sep = ""; sep.fill('-'); set_header(3, (const char *) sep); set_header(4,"@0gCod.@9gC.@12gCognome e nome@38gNato il@49gTessera@57gData sosp.@68gScadenza@79gDo Da A Sogg."); set_header(5,"@0g------@9g--@12g-------------------------@38g----------@49g-------@57g----------@68g----------@79g---------------"); printer().footerlen(3); } bool TSbloccoSospesi::user_create() { _msk = new TMask("at0700a"); _rel = new TRelation(LF_SOGGETTI); _rel->add(LF_SEZIONI,"CODSEZ==CODSEZ|CODSOT==CODSOT"); _rel->add("TCS", "CODTAB==STATO",1,0,ALIAS_TCS); _rel->add("CTD", "CODTAB==CATDON",1,0,ALIAS_CTD); //cursore ordinamento per sezione+sottogruppo+cognome+nome _cur = add_cursor(new TCursor(_rel, "", 3)); _contsan = new TLocalisamfile(LF_CONTSAN); _idoneita = new TLocalisamfile(LF_IDONEITA); _scontrolli = new TRecord_array(LF_CONTSAN, CON_PROGCON); _sidoneita = new TRecord_array(LF_IDONEITA, IDO_PROGIDO); TConfig config(CONFIG_STUDIO); _etadonne = config.get_int("EtaDonne"); _intsi_f1 = config.get_int("IntSI_F1"); _intsi_f2 = config.get_int("IntSI_F2"); _intsi_m = config.get_int("IntSI_M"); _intaf_m = config.get_int("IntAF_M"); return TRUE; } bool TSbloccoSospesi::user_destroy() { delete _rel; delete _msk; delete _contsan; delete _idoneita; delete _scontrolli; delete _sidoneita; return TRUE; } int at0700(int argc, char* argv[]) { TSbloccoSospesi a; a.run(argc, argv, "Sblocco sospesi"); return 0; }