#include #include #include #include #include #include #include "ce3.h" #include "ammce.h" #include "ammmv.h" #include "cespi.h" #include "movam.h" #include "movce.h" #include "salce.h" #include "ce3100a.h" #include "ce3100.h" #include "celib.h" #include "..\cg\cglib01.h" class TForm_registroce : public TForm_cespiti { TRelation* _newrelation; TCursor* _newcursor; public: virtual bool validate(TForm_item& fld, TToken_string& val); TForm_registroce(const char *name); virtual ~TForm_registroce(); void set_testata() { set_header(1, TRUE); }; void set_piede() { set_footer(0,FALSE); set_footer(0, TRUE);}; void set_pagina() { set_footer(0, TRUE);}; TPrint_section& get_testata_cespite() { return section('H', odd_page); }; TPrint_section& get_testata_categoria() { return section('H', even_page); }; TPrint_section& get_piede_categoria() { return section('F', even_page); }; TPrint_section& get_piede_registro() { return section('F', odd_page); }; TPrint_section& get_saldiiniziali() { return section('H', last_page); }; TPrint_section& get_movimenti() { return section('B', first_page); }; TPrint_section& get_valorifinali() { return section('B', even_page); }; TPrint_section& get_totali() { return section('B', odd_page); }; virtual TCursor* cursor() const {return _newcursor; }; virtual TRelation* relation() const {return _newrelation; }; }; TForm_registroce::TForm_registroce(const char *name): TForm_cespiti(name) { _newrelation = new TRelation(LF_CESPI); _newrelation->add("%CAC","CODTAB[1,2]==CODCGRA|CODTAB[3,6]==CODSPA|CODTAB[7,8]==CODCAT",1,0,101); _newrelation->add(LF_SALCE,"IDCESPITE==IDCESPITE",1,0,102); _newrelation->add("ESC","CODTAB==CODES",1,LF_SALCE,103); _newrelation->add(LF_AMMCE,"IDCESPITE==IDCESPITE|CODES==CODES|TPSALDO==TPSALDO",1,LF_SALCE,104); _newrelation->add(LF_MOVCE,"IDCESPITE==IDCESPITE",2,0,105); _newrelation->add(LF_MOVAM,"IDCESPITE==IDCESPITE|IDMOV==IDMOV",1,LF_MOVCE,106); _newrelation->add(LF_AMMMV,"IDCESPITE==IDCESPITE|IDMOV==IDMOV",1,LF_MOVCE,107); _newrelation->add("%TMC","CODTAB==CODMOV",1,LF_MOVCE,108); _newcursor = new TCursor(_newrelation,"",2); } TForm_registroce::~TForm_registroce() { delete _newrelation; delete _newcursor; } bool TForm_registroce::validate(TForm_item& fld, TToken_string& val) { return TForm_cespiti::validate(fld, val); } ///////////////////////////////////////////////////// // Applicazione ///////////////////////////////////////////////////// class TRegistro_cespiti : public TSkeleton_application { TMask* _mask; TForm_registroce* _form; TDitta_cespiti* _dittace; int _tipoamm; bool _bollato; TEsercizi_contabili _esc; protected: virtual bool create(); virtual bool destroy(); virtual void main_loop(); static bool attivita_handler(TMask_field& f, KEY k); public: void header_registro(); void footer_registro(); void footer_categoria(); void header_categoria(const int categoria); void print_cespite(); void header_cespite(); void print_saldiiniziali(); void print_movimenti(); void print_valorifinali(); void aggiorna_bollato(); void stampa_movimento(TRectype& removce, TRectype& removam, TRectype& recammmv); void stampa_sezione(TPrint_section& section); TRegistro_cespiti() {} virtual ~TRegistro_cespiti() {}; }; bool TRegistro_cespiti::create() { open_files(LF_CESPI,0); _mask = new TMask("ce3100a"); _mask->set_handler(F_SPECIE,attivita_handler); _dittace = new TDitta_cespiti(); _dittace->init_mask(*_mask); _form = new TForm_registroce("ce3100a"); return TSkeleton_application::create(); } bool TRegistro_cespiti::destroy() { delete _form; delete _dittace; delete _mask; return TSkeleton_application::destroy(); } bool TRegistro_cespiti::attivita_handler(TMask_field& f, KEY k) { TMask& m = f.mask(); if (f.to_check(k) || (k == K_TAB && !m.is_running())) { const int esercizio = m.get_int(F_ESERCIZIO); const TString16 gruppo = m.get(F_GRUPPO); const TString16 specie = m.get(F_SPECIE); TString80 key; key.format("%4d%s%s",esercizio, (const char*) gruppo, (const char*) specie); const TRectype& ccb = cache().get("CCB", key); TDate dataultcalc = ccb.get_date("D0"); m.set(F_DATAULTCALC, dataultcalc); if (ccb.get_bool("B2")) { if (m.is_running()) return f.error_box("Attenzione! Esercizio chiuso. \nNon é possibile stampare il registro."); } else { if (dataultcalc.empty()) { m.set(F_CALCOLO, "X"); m.disable(F_CALCOLO); m.set(F_TIPOREGISTRO,"B"); m.disable(F_TIPOREGISTRO); } if (ccb.get_bool("B1")) { m.set(F_TIPOREGISTRO,"B"); m.disable(F_TIPOREGISTRO); m.disable(F_CALCOLO); } } } return TRUE; } void TRegistro_cespiti::main_loop() { while (_mask->run() == K_ENTER) { TRectype darec(LF_CESPI),arec(LF_CESPI); TString filtro; // filtro sulla attivitá e categorie const int esercizio = _mask->get_int(F_ESERCIZIO); const int catini = _mask->get_int(F_CATINI); const int catfin = _mask->get_int(F_CATFIN); darec.put(CESPI_CODCGRA, _mask->get_int(F_GRUPPO)); darec.put(CESPI_CODSPA, _mask->get(F_SPECIE)); darec.put(CESPI_CODCAT, _mask->get_int(F_CATINI)); arec.put(CESPI_CODCGRA, _mask->get_int(F_GRUPPO)); arec.put(CESPI_CODSPA, _mask->get(F_SPECIE)); arec.put(CESPI_CODCAT, _mask->get_int(F_CATFIN)); // filtro sulle date di acquisizione e alienazione const TDate datainizio = _mask->get_date(F_DATAINIZIO); const TDate datafine = _mask->get_date(F_DATAFINE); filtro.format("(ANSI(%d->DTCOMP)<=\"",LF_CESPI) << datafine.string(ANSI) << "\")"; filtro << format(" && ((ANSI(%d->DTALIEN)>=\"",LF_CESPI) << datainizio.string(ANSI); filtro << format("\") || (%d->DTALIEN==\"\"))",LF_CESPI); // filtro su ammortamenti fiscali o civilistici _tipoamm = _mask->get_int(F_AMMORTAMENTI); _form->find_field('H', last_page, FR_SI_RIVGF).enable(_tipoamm==1); _form->find_field('H', last_page, FR_SI_RIVGC).enable(_tipoamm==2); _form->find_field('B', first_page, FR_MV_RIVGF).enable(_tipoamm==1); _form->find_field('B', first_page, FR_MV_RIVGC).enable(_tipoamm==2); _form->find_field('B', even_page, FR_FE_RIVGF).enable(_tipoamm==1); _form->find_field('B', even_page, FR_FE_RIVGC).enable(_tipoamm==2); _form->find_field('H', last_page, FR_SI_RIVGF).hide(); _form->find_field('H', last_page, FR_SI_RIVGC).hide(); _form->find_field('B', first_page, FR_MV_RIVGF).hide(); _form->find_field('B', first_page, FR_MV_RIVGC).hide(); _form->find_field('B', even_page, FR_FE_RIVGF).hide(); _form->find_field('B', even_page, FR_FE_RIVGC).hide(); // flag bollato per aggiornamenti _bollato = (_mask->get_int(F_TIPOREGISTRO)==1); _form->cursor()->setregion(darec,arec); _form->cursor()->setfilter(filtro,TRUE); long num = _form->cursor()->items(); _form->cursor()->freeze(); printer().open(); header_registro(); TRectype& reccesp = _form->cursor()->curr(); int catatt = -1; for (*_form->cursor()=0; _form->cursor()->pos()cursor())) { if (catatt != reccesp.get_int(CESPI_CODCAT)) { if (catatt != -1) footer_categoria(); catatt = reccesp.get_int(CESPI_CODCAT); header_categoria(catatt); } print_cespite(); } if (catatt != -1) { footer_categoria(); footer_registro(); } _form->cursor()->freeze(FALSE); printer().close(); if (_bollato) aggiorna_bollato(); } return ; } void TRegistro_cespiti::aggiorna_bollato() { return; } void TRegistro_cespiti::header_registro() { _form->find_field('H', first_page, FR_CODDITTA).set(_mask->get(F_CODDITTA)); _form->find_field('H', first_page, FR_RAGSOC).set(_mask->get(F_RAGSOC)); _form->find_field('H', first_page, FR_GRUPPO).set(_mask->get(F_GRUPPO)); _form->find_field('H', first_page, FR_D_GRUPPO).set(_mask->get(F_D_GRUPPO)); _form->find_field('H', first_page, FR_SPECIE).set(_mask->get(F_SPECIE)); _form->find_field('H', first_page, FR_D_SPECIE).set(_mask->get(F_D_SPECIE)); _form->find_field('H', first_page, FR_DATAINIZIO).set(_mask->get(F_DATAINIZIO)); _form->find_field('H', first_page, FR_DATAFINE).set(_mask->get(F_DATAFINE)); TString80 key; key.format("%04d",_mask->get_int(F_ESERCIZIO)); const TRectype& cce = cache().get("CCE", key); _form->find_field('H', first_page, FR_NUMGIORNI).set(cce.get("I3")); long giorni = (_mask->get_date(F_DATAFINE) - _mask->get_date(F_DATAINIZIO) + 1); key.format("%3d",giorni); _form->find_field('H', first_page, FR_NUMGIOSOL).set(key); _form->find_field('H', first_page, FR_LIBROCESPITI).enable(_bollato); _form->set_testata(); _form->set_piede(); } void TRegistro_cespiti::print_cespite() { // stampa i dati del cespite const long pos = _form->cursor()->pos(); //memorizza posizione cursore header_cespite(); print_saldiiniziali(); print_movimenti(); print_valorifinali(); *_form->cursor() = pos; //riposiziona il cursore return; } void TRegistro_cespiti::header_cespite() { // intestazione cespite TPrint_section& section = _form->get_testata_cespite(); section.update(); _form->set_pagina(); for (word i = 0; i < section.height(); i++) printer().print(section.row(i)); return; } void TRegistro_cespiti::print_saldiiniziali() { // saldi iniziali cespite (da salce e ammce con tpsaldo=1(saldo iniziale) ed esercizio = esercizio selezionato) const int esercizio = _mask->get_int(F_ESERCIZIO); TRectype& recsalce = _form->cursor()->curr(LF_SALCE); bool continua = _form->cursor()->is_first_match(LF_SALCE); while (continua && (recsalce.get_int(SALCE_TPSALDO) != 1 || recsalce.get_int(SALCE_CODES) != esercizio)) continua = _form->cursor()->next_match(LF_SALCE); if (!continua) recsalce.zero(); TRectype& recammce = _form->cursor()->curr(LF_AMMCE); continua = _form->cursor()->is_first_match(LF_AMMCE); while (continua && recammce.get_int(AMMCE_TPAMM)!= _tipoamm) //l'esercizio é quello selezionato poiché é nella chiave continua = _form->cursor()->next_match(LF_AMMCE); if (!continua) _form->cursor()->curr(LF_AMMCE).zero(); TPrint_section& section = _form->get_saldiiniziali(); section.update(); _form->set_pagina(); for (word i = 0; i < section.height(); i++) printer().print(section.row(i)); return; } void TRegistro_cespiti::stampa_sezione(TPrint_section& section) { section.update(); _form->set_pagina(); word y1 = section.find_field(FR_MV_QNOR).y(); word y2 = section.find_field(FR_MV_QANT).y(); for (word i = 0; i < section.height(); i++) { if (i+1>=y1 && i+1<= y2) { TPrintrow& row = section.row(i); TString rowstr = row.row(); if (!rowstr.blank()) printer().print(section.row(i)); } else printer().print(section.row(i)); } } void TRegistro_cespiti::stampa_movimento(TRectype& recmovce, TRectype& recmovam, TRectype& recammmv) { TPrint_section& section = _form->get_movimenti(); _form->cursor()->curr(LF_MOVCE) = recmovce; // _form->cursor()->curr(LF_MOVAM) = recmovam; //copia il record del cursore che scannerizza movimenti e rettifiche nel _form->cursor()->curr(LF_AMMMV) = recammmv; //cursore principale del form if (recmovce.get_char(MOVCE_SEGNO)=='-') { section.find_field(FR_MV_SEGNO).set("-1"); // section.find_field(FR_MV_QNORMENO).enable(); // section.find_field(FR_MV_QACCMENO).enable(); // section.find_field(FR_MV_QANTMENO).enable(); // section.find_field(FR_MV_MINUSVALENZA).enable(); // section.find_field(FR_MV_PLUSVALENZA).enable(); } else { section.find_field(FR_MV_SEGNO).set("1"); // section.find_field(FR_MV_QNORMENO).disable(); // section.find_field(FR_MV_QACCMENO).disable(); // section.find_field(FR_MV_QANTMENO).disable(); // section.find_field(FR_MV_MINUSVALENZA).disable(); // section.find_field(FR_MV_PLUSVALENZA).disable(); } section.update(); _form->set_pagina(); for (word i = 0; i < section.height(); i++) { TPrintrow& row = section.row(i); TString rowstr = row.row(); if (!rowstr.blank()) printer().print(row); } } void TRegistro_cespiti::print_movimenti() { TPrint_section& totali = _form->get_totali(); // movimenti for (bool ok=_form->cursor()->is_first_match(LF_MOVCE); ok; ok=_form->cursor()->next_match(LF_MOVCE)) { TRectype& recmovce = _form->cursor()->curr(LF_MOVCE); const TString16 idret = recmovce.get(MOVCE_IDRET); if (idret.not_empty()) continue; const TDate dtmov = recmovce.get(MOVCE_DTMOV); const int esmov = _esc.date2esc(dtmov); if (_mask->get_int(F_ESERCIZIO) != esmov) continue; for(word t = 0; t < totali.fields(); t++) //azzera i campi dei totali totali.field(t).set(""); TRectype& recmovam = _form->cursor()->curr(LF_MOVAM); bool continua = _form->cursor()->is_first_match(LF_MOVAM); while (recmovam.get_int(MOVAM_TPAMM) != _tipoamm && continua) continua = _form->cursor()->next_match(LF_MOVAM); if (!continua) recmovam.zero(); TRectype& recammmv = _form->cursor()->curr(LF_AMMMV); continua = _form->cursor()->is_first_match(LF_AMMMV); while (recammmv.get_int(AMMMV_TPAMM) != _tipoamm && continua) continua = _form->cursor()->next_match(LF_AMMMV); if (!continua) recammmv.zero(); stampa_movimento(recmovce,recmovam,recammmv); //stampa i movimenti SENZA rettifiche // rettifiche (é necessario utilizzare un nuovo cursore, quindi si comincia con la relazione...) TRelation rel_rettif(LF_MOVCE); TString expr; expr << "IDCESPITE==IDCESPITE|IDMOV==IDMOV|TPAMM==\"" << _tipoamm << '"'; rel_rettif.add(LF_MOVAM, expr); rel_rettif.add(LF_AMMMV, expr); const TString16 id = recmovce.get(MOVCE_IDCESPITE); // e quindi si passa al cursore...; notare che il cursore delle rettifiche usa la chiave 2: IDCESPITE+IDMOV; // per cui parte per selezionare le possibili rettifiche del movimento da rettificare da lui... TRectype fromret(LF_MOVCE); fromret.put(MOVCE_IDCESPITE, id); //IDCESPITE della chiave 2 fromret.put(MOVCE_IDMOV, recmovce.get(MOVCE_IDMOV)); //IDMOV della chiave 2 //...in poi TRectype toret(LF_MOVCE); toret.put(MOVCE_IDCESPITE, id); TString filtro; filtro << MOVCE_IDRET << "==" << recmovce.get(MOVCE_IDMOV); //confronta numericamente IDRET e IDMOV //ed ecco il cursore! TCursor rettcur(&rel_rettif, filtro, 2, &fromret, &toret); const long items = rettcur.items(); if (items > 0) { rettcur.freeze(); for (rettcur = 0l ; rettcur.pos()get_int(F_ESERCIZIO); TRectype& recsalce = _form->cursor()->curr(LF_SALCE); const TString16 idcespite = _form->cursor()->curr().get(CESPI_IDCESPITE); bool continua = recsalce.get(SALCE_IDCESPITE) == idcespite; while (continua && (recsalce.get_int(SALCE_TPSALDO) !=2 || recsalce.get_int(SALCE_CODES) != esercizio)) continua = _form->cursor()->next_match(LF_SALCE); if (!continua) recsalce.zero(); TRectype& recammce = _form->cursor()->curr(LF_AMMCE); continua = recammce.get(AMMCE_IDCESPITE) == idcespite; while (recammce.get_int(AMMCE_TPAMM) != _tipoamm && continua) continua = _form->cursor()->next_match(LF_AMMCE); if (!continua) recammce.zero(); TPrint_section& section = _form->get_valorifinali(); bool msg = _form->cursor()->curr(LF_AMMCE).get_bool(AMMCE_MSG01); section.find_field(FR_FE_MSG1).enable(msg); msg = _form->cursor()->curr(LF_AMMCE).get_bool(AMMCE_MSG02); TString80 key; key.format("%04d",_mask->get_int(F_ESERCIZIO)); const TRectype& cce = cache().get("CCE", key); long giorni = (_mask->get_date(F_DATAFINE) - _mask->get_date(F_DATAINIZIO) + 1); key.format("Amm.to ragguagliato all'esercizio di %3d giorni su %3d",giorni, cce.get("I3")); section.find_field(FR_FE_MSG2).set(key); section.find_field(FR_FE_MSG2).enable(msg); msg = _form->cursor()->curr(LF_AMMCE).get_bool(AMMCE_MSG03); const int usoprom = _form->cursor()->curr().get_int(CESPI_USOPROM); if (usoprom==2 || usoprom==4) key="Ammortamento ridotto al 50% per bene in uso promiscuo"; else if (usoprom==3 || usoprom==5) key="Ammortamento ridotto all'80% per bene in uso promiscuo"; section.find_field(FR_FE_MSG3).set(key); section.find_field(FR_FE_MSG3).enable(msg); msg = _form->cursor()->curr(LF_AMMCE).get_bool(AMMCE_MSG04); section.find_field(FR_FE_MSG4).enable(msg); msg = _form->cursor()->curr(LF_AMMCE).get_bool(AMMCE_MSG05); section.find_field(FR_FE_MSG5).enable(msg); msg = _form->cursor()->curr(LF_AMMCE).get_bool(AMMCE_MSG06); section.find_field(FR_FE_MSG6).enable(msg); section.update(); _form->set_pagina(); word y1 = section.find_field(FR_FE_QNOR).y(); word y2 = section.find_field(FR_FE_MSG6).y(); for (word i = 0; i < section.height(); i++) { if (i+1>=y1 && i+1<= y2) { TPrintrow& row = section.row(i); TString256 rowstr = row.row(); if (!rowstr.blank()) printer().print(section.row(i)); } else printer().print(section.row(i)); } return; } void TRegistro_cespiti::header_categoria(const int categoria) { // intestazione della categoria TPrint_section& section = _form->get_testata_categoria(); section.update(); _form->set_pagina(); for (word i = 0; i < section.height(); i++) printer().print(section.row(i)); return ; } void TRegistro_cespiti::footer_categoria() { // stampa il footer della categoria TPrint_section& section = _form->get_piede_categoria(); section.update(); _form->set_pagina(); for (word i = 0; i < section.height(); i++) printer().print(section.row(i)); return ; } void TRegistro_cespiti::footer_registro() { // stampa il footer del registro (totali generali) TPrint_section& section = _form->get_piede_registro(); section.update(); _form->set_pagina(); for (word i = 0; i < section.height(); i++) printer().print(section.row(i)); return ; } int ce3100(int argc, char* argv[]) { TRegistro_cespiti a; a.run(argc,argv,"Stampa registro cespiti"); return 0; }