#include #include #include #include #include "celib.h" #include "ce3400.h" #include "ce3400a.h" #include "../cg/cglib01.h" #include "ammce.h" #include "cespi.h" #include "salce.h" /////////////////////////////////////////////////////////// // Main Form /////////////////////////////////////////////////////////// class TECFE_form : public TCespi_list_form { TCursor* _cur; int _order, _tipo_sit; TString _str; protected: virtual TRelation* relation() const { return _cur->relation(); } virtual TCursor* cursor() const { return _cur; } virtual bool validate(TForm_item& fld, TToken_string& val); public: const TString& decode_group(const char* codtab, int mode = 0); TPrint_section& cespite() { return section('B', odd_page); } TPrint_section& totale() { return section('B', even_page); } void set_cursor(TCursor& cur) { _cur = &cur; } void set_testata(const TMask& m, const TString& codtab); TECFE_form(); }; void TECFE_form::set_testata(const TMask& m, const TString& codtab) { TCespi_list_form::set_testata(m); _order = m.get_int(F_ORDINAMENTO); _tipo_sit = m.get_int(F_SITUAZIONE); TPrint_section& header = section('H', odd_page); header.find_field(F_CODTAB).set(decode_group(codtab)); } const TString& TECFE_form::decode_group(const char* codtab, int mode) { const int order = mode > 0 ? mode : _order; _str = "@b"; _str << (order==1 ? TR("Categoria") : TR("Impianto")) << "@r " << codtab << ' '; if (order == 1) { const TRectype& cat = ditta_cespiti().categoria(0, NULL, atoi(codtab)); _str << cat.get("S0"); } else _str << cache().get("CIM", codtab, "S0"); return _str; } bool TECFE_form::validate(TForm_item& fld, TToken_string& val) { const char* cmd = val.get(0); if (xvt_str_compare_ignoring_case(cmd, "_INVCODTAB") == 0) { const TRectype& cespi = relation()->curr(); // Se la stampa è ordinata per categoria allora stampo l'impianto e viceversa const TString16 codtab = cespi.get(_order == 1 ? CESPI_CODIMP : CESPI_CODCAT); if (codtab.not_empty()) fld.set(decode_group(codtab, 3-_order)); else fld.set(""); return TRUE; } if (xvt_str_compare_ignoring_case(cmd, "_VALAMM") == 0) { const TRectype& salpro = relation()->curr(LF_SALCE); real val = salpro.get_real(SALCE_CSTO)-salpro.get_real(SALCE_PLUSREIN)+ salpro.get_real(SALCE_RIV75)+salpro.get_real(SALCE_RIV83)+salpro.get_real(SALCE_RIV90)+salpro.get_real(SALCE_RIV91); val += salpro.get_real(_tipo_sit == 2 ? SALCE_RIVGC : SALCE_RIVGF); val -= salpro.get_real(_tipo_sit == 2 ? SALCE_VNONAMMC : SALCE_VNONAMM); val -= salpro.get_real(SALCE_VNONAMM06); fld.set(val.string()); return TRUE; } return TCespi_list_form::validate(fld, val); } TECFE_form::TECFE_form() : TCespi_list_form("ce3800a") { } /////////////////////////////////////////////////////////// // Main Mask /////////////////////////////////////////////////////////// class TECFE_mask : public TAutomask { protected: virtual bool on_field_event(TOperable_field& f, TField_event e, long jolly); public: TECFE_mask() : TAutomask("ce3400a") { } }; bool TECFE_mask::on_field_event(TOperable_field& f, TField_event e, long jolly) { bool ok = TRUE; switch (f.dlg()) { case F_FROM_CAT: case F_D_FROM_CAT: case F_TO_CAT: case F_D_TO_CAT: { TDitta_cespiti& dc = ditta_cespiti(); ok = dc.on_category_event(f, e, jolly); } break; default: break; } return ok; } /////////////////////////////////////////////////////////// // Main Application /////////////////////////////////////////////////////////// class TECFE_app : public TSkeleton_application { TECFE_form* _form; int _tipo_sit; int _order; static bool elenco_filter(const TRelation* rel); protected: virtual void main_loop(); public: void print_cespite(); void print_totale(const char* cod); }; void TECFE_app::print_cespite() { TPrint_section& ces = _form->cespite(); _form->print_section(ces); } void TECFE_app::print_totale(const char* cod) { TPrint_section& tot = _form->totale(); tot.find_field(F_CODTAB).set(_form->decode_group(cod)); _form->print_separator(); _form->print_section(tot); for (unsigned int i = 0; i < tot.fields(); i++) tot.field(i).set(""); printer().formfeed(); } bool TECFE_app::elenco_filter(const TRelation* rel) { const TRectype& salpro = rel->curr(LF_SALCE); const real num = salpro.get_real(SALCE_NUMELE); return num > ZERO; } void TECFE_app::main_loop() { TECFE_mask m; m.set_caption(TR("Elenco fine esercizio")); ditta_cespiti().init_mask(m); while (m.run() != K_QUIT) { const int ese = m.get_int(F_ESERCIZIO); const int gruppo = m.get_int(F_GRUPPO); const TString4 specie = m.get(F_SPECIE); ditta_cespiti().set_attivita(ese, gruppo, specie); _tipo_sit = m.get_int(F_SITUAZIONE); _order = m.get_int(F_ORDINAMENTO); TRelation rel(LF_CESPI); TString expr; expr << "IDCESPITE==IDCESPITE|CODES==" << m.get(F_ESERCIZIO) << "|TPSALDO==2"; rel.add(LF_SALCE, expr); expr << "|TPAMM==" << _tipo_sit; rel.add(LF_AMMCE, expr); TString filter; if (_order == 1) { const int fc = m.get_int(F_FROM_CAT); const int tc = m.get_int(F_TO_CAT); if (fc != 0) { if (filter.not_empty()) filter << "&&"; filter << '(' << CESPI_CODCAT << ">=" << fc << ')'; } if (tc != 0) { if (filter.not_empty()) filter << "&&"; filter << '(' << CESPI_CODCAT << "<=" << tc << ')' ; } } else { const TString& fi = m.get(F_FROM_IMP); const TString& ti = m.get(F_TO_IMP); if (!fi.blank()) { if (filter.not_empty()) filter << "&&"; filter << '(' << CESPI_CODIMP << ">=\"" << fi << "\")"; } if (!fi.blank()) { if (filter.not_empty()) filter << "&&"; filter << '(' << CESPI_CODIMP << "<=\"" << ti << "\")"; } } const char* orderby = _order == 1 ? "CODCAT|DTCOMP|IDCESPITE" : "CODIMP|DTCOMP|IDCESPITE"; TSorted_cursor cur(&rel, orderby, filter); cur.set_filterfunction(elenco_filter, TRUE); const long items = cur.items(); if (items > 0) { const TRectype& cespi = rel.curr(); TECFE_form form; form.set_cursor(cur); _form = &form; printer().open(); TString16 last_group = "@"; // Simbolo speciale per indicare nessuna stampa! cur.freeze(); for (cur = 0L; cur.pos() < items; ++cur) { // Controllo qui la validità per non incasinare il valutatore con stringhe e numeri const int gra = cespi.get_int(CESPI_CODCGRA); const TString& spa = cespi.get(CESPI_CODSPA); if (gra != gruppo || spa != specie) continue; const TString16 curr_group = cespi.get(_order == 1 ? CESPI_CODCAT : CESPI_CODIMP); if (curr_group != last_group) { if (last_group != "@") print_totale(last_group); last_group = curr_group; form.set_testata(m, curr_group); } print_cespite(); } if (last_group != "@") print_totale(last_group); printer().close(); xvtil_statbar_set(""); } } } int ce3800(int argc, char* argv[]) { TECFE_app app; app.run(argc, argv, TR("Elenco fine esercizio")); return 0; }