#include #include #include #include #include #include #include "ce1.h" #include "ce1500a.h" #include "ce2101.h" #include "celib.h" #include "../cg/cglib01.h" #include #include #include #include #include "ammce.h" #include "ammmv.h" #include "cespi.h" #include "movce.h" #include "salce.h" /////////////////////////////////////////////////////////// // Maschera di selezione /////////////////////////////////////////////////////////// class TMov_qmask; class TMov_emask; class TMovicespi : public TRelation_application { TRelation* _rel; TMov_qmask* _qmask; TMov_emask* _emask; TFilename _prima_nota; int _cg_line; private: void kill_mov(const TString& idcespite, const TString& idmov, int lfile); void kill_rett(const TString& id, const TString& idmov); protected: virtual bool changing_mask(int mode) { return TRUE; } virtual TMask* get_mask(int mode); virtual TRelation* get_relation() const { return _rel; } virtual const char* get_next_key(); virtual bool protected_record(TRelation &r); virtual bool user_create(); virtual bool user_destroy(); virtual void init_query_mode(TMask& m); virtual void init_insert_mode(TMask& m); virtual void init_modify_mode(TMask& m); virtual bool remove(); public: int tipo_cr(int gruppo, int conto, long sottoconto) const; void cg_mode(); bool select_mov(long numreg, TString& idmov) const; int init_mask(TMask& m); void save_if_dirty() { save(TRUE); } }; TMovicespi& app() { return (TMovicespi&)main_app(); } /////////////////////////////////////////////////////////// // Maschera di selezione /////////////////////////////////////////////////////////// class TMov_qmask : public TAutomask { int _staat; protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); int calcola_stato_attivita(); public: int stato_attivita() const { return _staat; } TMov_qmask(); }; int TMov_qmask::calcola_stato_attivita() { const int ese = get_int(F_ESERCIZIO); const int gru = get_int(F_GRUPPO); const char* spe = get(F_SPECIE); TString16 str; str.format("%04d%02d%-4s", ese, gru, spe); const TRectype& curr_ccb = cache().get("CCB", str); if (curr_ccb.get_bool("B1")) // Bollato stampato _staat = 3; else { TEsercizi_contabili esc; str.format("%04d%02d%-4s", esc.pred(ese), gru, spe); const TRectype& prev_ccb = cache().get("CCB", str); _staat = prev_ccb.get_bool("B1") ? 2 : 1; } ditta_cespiti().set_attivita(ese, gru, spe); return _staat; } bool TMov_qmask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_ESERCIZIO: case F_GRUPPO: case F_SPECIE: calcola_stato_attivita(); enable(DLG_NEWREC, _staat != 3); break; case F_IMPIANTO: case F_IDCESPITE: if (e == fe_modify) { const TString& ces = get(F_IDCESPITE); const TString& imp = get(F_IMPIANTO); const bool cesok = !real::is_null(ces); const bool impok = !real::is_null(imp); TString80 filter; if (cesok) filter << MOVCE_IDCESPITE << "==\"" << ces << '"'; if (impok) { if (cesok) filter << ")&&("; filter << LF_CESPI << "->" << CESPI_CODIMP << "==\"" << imp << '"'; if (cesok) { filter << ')'; filter.insert("(", 0); } } TEdit_field& m = efield(F_IDMOV); m.browse()->set_filter(filter); } break; default: break; } return TRUE; } TMov_qmask::TMov_qmask() : TAutomask("ce1500a") { first_focus(F_IDMOV); } /////////////////////////////////////////////////////////// // Applicazione principale /////////////////////////////////////////////////////////// class TMov_emask : public TAutomask { int _staat; TCespite _cespite; TString _s5; private: void set_inputability(short id, char flag); void set_inputability(const short* id, char flag); bool test_inputability(const short* id, char flag); void set_fondi_inputability(); real calc_riv(const TRectype& salpro, int tipo) const; void calc_amm(int tipo); bool cespite_nuovo() const; TCurrency sum_fields(const short* f) const; protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); virtual bool on_key(KEY k); public: void set_stato_attivita(int s) { _staat = s; } TMov_emask(); }; // Determina se siamo in presenza di un cespite nuovo bool TMov_emask::cespite_nuovo() const { const TDate dtacq = _cespite.get(CESPI_DTCOMP); const TDate dtmov = get(F_DTMOV); return !dtacq.ok() || dtacq >= dtmov; } TCurrency TMov_emask::sum_fields(const short* f) const { TCurrency sum, val; for (int i = 0; f[i] != 0; i++) { get_currency(abs(f[i]), val); if (f[i] > 0) sum += val; else sum -= val; } return sum; } void TMov_emask::set_inputability(short id, char flag) { TMask_field& f = field(id); if (flag=='S' || flag=='O') f.enable(); else { f.reset(); f.disable(); } f.check_type(flag=='O' ? CHECK_REQUIRED : CHECK_NORMAL); } void TMov_emask::set_inputability(const short* id, char flag) { if (flag == 'O') flag = 'S'; for (; *id > 0; id++) set_inputability(*id, flag); } bool TMov_emask::test_inputability(const short* id, char flag) { bool ok = flag != 'O'; if (!ok) { for (int i = 0; id[i] > 0; i++) { if (!field(id[i]).empty()) { ok = TRUE; break; } } } if (!ok) error_box("E' necessario specificare almeno uno dei valori previsti dal tipo movimento"); return ok; } HIDDEN const short doc_ids[] = { F_TPDOC, F_NDOC, F_DTDOC, 0 }; HIDDEN const short riv_ids[] = { F_RIV75, F_RIV83, F_RIV90, F_RIV91, 0 }; HIDDEN const short fis_ids[] = { F_NORMALE, F_ACCELERATO, F_ANTICIPATO, 0 }; HIDDEN const short civ_ids[] = { F_NORMALE2, F_ACCELERATO2, F_ANTICIPATO2, 0 }; HIDDEN const short prv_ids[] = { F_FPRIVATO, F_QPERSEPRIV, 0 }; bool TMov_emask::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) { case F_CODMOV: if ((e == fe_modify || e == fe_init)) { const TRectype& tpmov = cache().get("%TMC", o.get()); const bool insert_rett = tpmov.get_int("I0") == 2 && insert_mode(); enable(F_IDRET, insert_rett); if (insert_rett) { TString filter; // Filtro su movimenti rettificabili filter << '(' << MOVCE_CODMOV << "=\"" << tpmov.get("S8") << "\")"; filter << "&&(ANSI(" << MOVCE_DTMOV << ")>=" << get_date(F_INIZIO_ES).string(ANSI) << ')'; filter << "&&(ANSI(" << MOVCE_DTMOV << ")<=" << get_date(F_FINE_ES).string(ANSI) << ')'; efield(F_IDRET).browse()->set_filter(filter); } _s5 = tpmov.get("S5"); if (_s5.empty()) _s5.spaces(16); set_inputability(doc_ids, _s5[0]); set_inputability(F_IMPVEN, _s5[2]); set_inputability(F_ELEMENTI, _s5[3]); set_inputability(F_COSTO, _s5[4]); set_inputability(F_VNONAMM, _s5[5]); set_inputability(F_PLUSREIN, _s5[6]); set_inputability(riv_ids, _s5[7]); set_inputability(F_RIVGF, _s5[8]); set_inputability(F_RIVGC, _s5[9]); // Determina segni possibili switch (tpmov.get_char("S7")) { case '+': disable(F_SEGNO); set(F_SEGNO, "+"); break; case '-': disable(F_SEGNO); set(F_SEGNO, "-"); break; default : enable(F_SEGNO); break; } } break; case F_IDRET: if (e == fe_modify) { TString16 ces; if (!o.empty()) { TEdit_field& e = (TEdit_field&)o; ces = e.browse()->cursor()->curr().get(MOVCE_IDCESPITE); TEdit_field& c = efield(F_IDCESPITE); c.set(ces); c.check(); } enable(F_IDCESPITE, ces.empty()); // Dis/abilita codice cespite enable(F_DESC_CES, ces.empty()); // Dis/abilita descrizione cespite } break; case F_IDCESPITE: if (e == fe_init || e == fe_modify || e == fe_close) { const TString& id = o.get(); if (_cespite.get(CESPI_IDCESPITE) != id) _cespite.read(id); enable_page(3, id.not_empty()); if (id.not_empty()) { const TRectype& cat = _cespite.categoria(); set(F_CATEGORIA, _cespite.get(CESPI_CODCAT), TRUE); set(F_DESC_CAT, cat.get("S0"), TRUE); if (o.enabled()) { const TRectype& tpmov = cache().get("%TMC", get(F_CODMOV)); switch (_cespite.tipo()) { case tc_immateriale: if (!tpmov.get_bool("B1")) return error_box("Movimento non applicabile a beni immateriali"); break; case tc_pluriennale: if (!tpmov.get_bool("B2")) return error_box("Movimento non applicabile a costi pluriennali"); break; default: if (!tpmov.get_bool("B0")) return error_box("Movimento non applicabile a beni materiali"); break; } } } else { reset(F_CATEGORIA); reset(F_DESC_CAT); } const TDate dtcomp = _cespite.get(CESPI_DTCOMP); if (dtcomp.ok()) { const TDate dtmov = get(F_DTMOV); if (dtcomp > dtmov) return error_box("La data di acquisizione del cespite non può precedere quella del movimento"); } } break; case F_DTMOV: if (e == fe_init || e == fe_modify || e == fe_close) { TEdit_field& dd = efield(F_DTDOC); if (dd.required() && dd.empty()) dd.set(o.get()); const TDate dtret = get(F_DTMOV_RET); if (dtret.ok()) { const TDate dtmov = o.get(); if (dtmov < dtret) return error_box("La data del movimento di rettifica deve seguire la data del movimento rettificato"); } } break; case F_TPDOC: if (e == fe_button) { TArray_sheet sci(3, 3, -3, -3, o.prompt(), "Tipo|Descrizione@20"); sci.add("FA|Fattura d'acquisto"); sci.add("FV|Fattura di vendita"); sci.add("NC|Nota di credito"); sci.add("ND|Nota di debito"); if (sci.run() == K_ENTER) { TToken_string& str = sci.row(-1); o.set(str.get(0)); } } if (e == fe_close) return test_inputability(doc_ids, _s5[0]); break; case F_RIV75: if (e == fe_close) return test_inputability(riv_ids, _s5[7]); break; case F_ELEMENTI: if (e == fe_modify || e == fe_close) { if (o.empty() && cespite_nuovo()) return error_box("È necessario inserire il numero di elementi del nuovo cespite"); } break; case F_VNONAMM: if (e == fe_modify || e == fe_close) { TCurrency csto, vnon; get_currency(F_COSTO, csto); get_currency(F_VNONAMM, vnon); if (vnon > csto) return error_box("Il valore non ammortizzabile non puo' superare %s", csto.string(TRUE)); } break; case F_PLUSREIN: if (e == fe_modify || e == fe_close) { TCurrency csto, vnon, plus; get_currency(F_COSTO, csto); get_currency(F_VNONAMM, vnon); get_currency(F_PLUSREIN, plus); const TCurrency val = csto-vnon; if (plus > val) return error_box("La plusvalenza reinvestita non puo' superare %s", val.string(TRUE)); } break; case F_NORMALE: if (e == fe_close) { if (!test_inputability(fis_ids, _s5[10])) return FALSE; const short fv[] = { F_COSTO, -F_VNONAMM, F_RIV75, F_RIV83, F_RIV90, F_RIV91, F_RIVGF, 0 }; const short fa[] = { F_NORMALE, F_ACCELERATO, F_ANTICIPATO, F_QPERSE, F_FPRIVATO, F_QPERSEPRIV, 0 }; const TCurrency val_amm = sum_fields(fv); const TCurrency fon_amm = sum_fields(fa); if (fon_amm > val_amm) { TString msg; msg << "Il fondo ammortamento fiscale (" << fon_amm.string(TRUE) << ')'; msg << "non puo' superare il valore da ammortizzare (" << val_amm.string(TRUE) << ')'; return error_box(msg); } } break; case F_NORMALE2: if (e == fe_close) { if (!test_inputability(civ_ids, _s5[11])) return FALSE; const short fv[] = { F_COSTO, F_RIV75, F_RIV83, F_RIV90, F_RIV91, F_RIVGC, 0 }; const short fa[] = { F_NORMALE2, F_ACCELERATO2, F_ANTICIPATO2, 0 }; const TCurrency val_amm = sum_fields(fv); const TCurrency fon_amm = sum_fields(fa); if (fon_amm > val_amm) { TString msg; msg << "Il fondo ammortamento civilistico (" << fon_amm.string(TRUE) << ')'; msg << "non puo' superare il valore da ammortizzare (" << val_amm.string(TRUE) << ')'; return error_box(msg); } } break; case S_TIPO: if (e == fe_modify) calc_amm(atoi(o.get())); break; default: break; } return TRUE; } real TMov_emask::calc_riv(const TRectype& salpro, int tipo) const { const char* riv_ids[] = { SALCE_RIV75, SALCE_RIV83, SALCE_RIV90, SALCE_RIV91, NULL }; real riv; for (int i = 0; riv_ids[i]; i++) riv += salpro.get_real(riv_ids[i]); if (tipo == 2) riv += salpro.get_real(SALCE_RIVGC); else riv += salpro.get_real(SALCE_RIVGF); return riv; } void TMov_emask::calc_amm(int tipo) { const TDate dtlim = get(F_DTMOV); _cespite.calc_amm(tipo, FALSE, dtlim); set(S_DATAMOV, dtlim); const TRectype& s = _cespite.sal_pro(); set(S_ELEMENTI, s.get(SALCE_NUMELE)); set(S_COSTO, s.get_real(SALCE_CSTO)); set(S_VNONAMM, s.get(SALCE_VNONAMM)); set(S_PLUSREIN, s.get(SALCE_PLUSREIN)); set(S_TOTRIV, calc_riv(s, tipo)); real tot_val; tot_val += get_real(S_COSTO); tot_val -= get_real(S_VNONAMM); tot_val -= get_real(S_PLUSREIN); tot_val += get_real(S_TOTRIV); set(S_TOTVAL, tot_val); const TRectype& a = _cespite.amm_pro(); set(S_NORMALE, a.get(AMMCE_QNOR)); set(S_ACCELERATO, a.get(AMMCE_QACC)); set(S_ANTICIPATO, a.get(AMMCE_QANT)); set(S_QPERSE, a.get(AMMCE_QPERSE)); set(S_FPRIVATO, a.get(AMMCE_FPRIVATO)); set(S_QPERSEP, a.get(AMMCE_QPERSEP)); real tot_fon; tot_fon += get_real(S_NORMALE); tot_fon += get_real(S_ACCELERATO); tot_fon += get_real(S_ANTICIPATO); tot_fon += get_real(S_QPERSE); tot_fon += get_real(S_FPRIVATO); tot_fon += get_real(S_QPERSEP); set(S_TOTFON, tot_fon); const real tot_res = tot_val-tot_fon; set(S_RESIDUO, tot_res); TString key; key << get(F_IDCESPITE) << '|' << get(F_IDMOV) << '|' << tipo; const TRectype& ammmv = cache().get(LF_AMMMV, key); set(S_PLUS, ammmv.get(AMMMV_PLUS)); set(S_MINUS, ammmv.get(AMMMV_MINUS)); } void TMov_emask::set_fondi_inputability() { if (cespite_nuovo()) { // Disabilito tutti i campi della pagina per i nuovi cespiti set_inputability(fis_ids, ' '); set_inputability(civ_ids, ' '); set_inputability(F_QPERSE, ' '); set_inputability(prv_ids, ' '); } else { set_inputability(fis_ids, _s5[10]); set_inputability(civ_ids, _s5[11]); set_inputability(F_QPERSE, _s5[12]); bool should_be_on = _s5[10] == 'S' || _s5[10] == 'O'; // Test preliminare basato su %TMC if (should_be_on) should_be_on = _cespite.get_int(CESPI_USOPROM) > 1; // Test aggiuntivo su uso promiscuo set_inputability(prv_ids, should_be_on ? _s5[10] : ' '); // Dis/abilita fondo privato e quote perse private } } bool TMov_emask::on_key(KEY k) { // Try to predict next page! const int old_page = curr_page()+1; int new_page = old_page; switch (k) { case K_CTRL+K_F1: new_page = 1; break; case K_CTRL+K_F2: new_page = 2; break; case K_CTRL+K_F3: new_page = 3; break; case K_CTRL+K_F4: new_page = 4; break; case K_PREV : new_page--; break; case K_NEXT : new_page++; break; default: break; } // If page will change ... if (old_page != new_page) switch(new_page) { case 3: set_fondi_inputability(); break; case 4: if (dirty() < S_TIPO) { app().save_if_dirty(); for (int f = fields()-1; f >= 0; f--) { TMask_field& c = fld(f); c.set_dirty(FALSE); } } set(S_TIPO, 1, TRUE); break; default: break; } return TAutomask::on_key(k); } TMov_emask::TMov_emask() : TAutomask("ce1500b") { } /////////////////////////////////////////////////////////// // Applicazione principale /////////////////////////////////////////////////////////// TMask* TMovicespi::get_mask(int mode) { return mode == MODE_QUERY ? (TMask*)_qmask : (TMask*)_emask; } bool TMovicespi::user_create() { open_files(LF_TAB, LF_TABCOM, LF_CESPI, LF_AMMCE, LF_SALCE, LF_MOVCE, LF_MOVAM, LF_AMMMV, 0); _rel = new TRelation(LF_MOVCE); _rel->add(LF_MOVAM, "IDCESPITE==IDCESPITE|IDMOV==IDMOV|TPAMM==1"); _rel->add(LF_MOVAM, "IDCESPITE==IDCESPITE|IDMOV==IDMOV|TPAMM==2", 1, 0, 2); _rel->add(LF_MOVAM, "IDCESPITE==IDCESPITE|IDMOV==IDMOV|TPAMM==3", 1, 0, 3); _rel->write_enable(); _qmask = new TMov_qmask; _emask = new TMov_emask; // Collegamento da prima nota if (argc() > 2 && strncmp(argv(2), "/c", 2) == 0) { _prima_nota = argv(2); _prima_nota.ltrim(2); _cg_line = 1; } else { _prima_nota.cut(0); _cg_line = 0; } return TRUE; } bool TMovicespi::user_destroy() { delete _emask; delete _qmask; delete _rel; return TRUE; } const char* TMovicespi::get_next_key() { real num = 1; TLocalisamfile& cespi = _rel->lfile(LF_MOVCE); if (cespi.last() == NOERR) num = cespi.get_real(MOVCE_IDMOV) + 1; return format("%d|%s", F_IDMOV, num.string()); } bool TMovicespi::protected_record(TRelation &r) { bool stampato = r.curr().get_bool(MOVCE_STAMPATO); return stampato; } int TMovicespi::tipo_cr(int gruppo, int conto, long sottoconto) const { TString16 str; str.format("%d|%d|%ld", gruppo, conto, sottoconto); const TRectype& pcon = cache().get(LF_PCON, str); const int t = pcon.get_int(PCN_TIPOSPRIC); return t; } bool TMovicespi::select_mov(long numreg, TString& idmov) const { TRelation rel(LF_MOVCE); TString filter; filter << MOV_NUMREG << "==" << numreg; TCursor cur(&rel, filter, 3); long items = cur.items(); if (items == 0L) { cur.setkey(1); cur.setfilter(""); items = cur.items(); } bool ok = items > 0; if (ok) { long selected = 0; if (items > 1) { TCursor_sheet sheet(&cur, "NUMREG|IDMOV|DTMOV|DESC", "Movimenti cespiti", "Registazione|Movimento@11|Data@10|Descrizione Movimento@50", 0, 1); ok = sheet.run() == K_ENTER; if (ok) selected = sheet.selected(); } if (ok) { cur = selected; idmov = cur.curr().get(MOVCE_IDMOV); } } return ok; } void TMovicespi::cg_mode() { TConfig ini(_prima_nota, "Transaction"); char action = ini.get("Action")[0]; TString8 para; para.format("%d", LF_MOV); ini.set_paragraph(para); // Al primo inserimento devo impostare anche l'anno e l'attività if (_cg_line == 1 && action == 'I') { _qmask->set(F_ESERCIZIO, ini.get(MOV_ANNOES), TRUE); if (!_qmask->efield(F_SPECIE).on_key(K_F9)) action = ' '; } if (action == 'I') { for (int i = _cg_line; ; i++) { para.format("%d,%d", LF_RMOV, i); if (ini.set_paragraph(para)) { const int gruppo = ini.get_int(RMV_GRUPPO); const int conto = ini.get_int(RMV_CONTO); const int sottoconto = ini.get_int(RMV_SOTTOCONTO); const int tipo = tipo_cr(gruppo, conto, sottoconto); if (tipo == 2 || tipo == 3 || tipo == 4 || tipo == 8) { _cg_line = i; _qmask->send_key(K_SPACE, DLG_NEWREC); break; } } else { action = ' '; break; } } } else if (action == 'M' || action == 'D') { const long numreg = ini.get_long(MOV_NUMREG); TString16 idmov; if (select_mov(numreg, idmov)) { _qmask->set(F_IDMOV, idmov, TRUE); _qmask->send_key(K_AUTO_ENTER, 0); } else action = ' '; } // Caso artificiale per terminare la transazione if (action == ' ') stop_run(); } void TMovicespi::init_query_mode(TMask& m) { TDitta_cespiti& dc = ditta_cespiti(); dc.init_mask(m); // Collegamento da prima nota if (_cg_line > 0) cg_mode(); } int TMovicespi::init_mask(TMask& m) { TDitta_cespiti& dc = ditta_cespiti(); dc.init_mask(m); const int staat = _qmask->stato_attivita(); _emask->set_stato_attivita(staat); m.enable(DLG_NEWREC, staat != 3); return staat; } void TMovicespi::init_insert_mode(TMask& m) { const int staat = init_mask(m); m.enable(F_IDCESPITE); m.enable(F_DESC_CES); m.enable(DLG_SAVEREC, staat != 3); if (_cg_line > 0) { TString16 para; para.format("%d", LF_MOV); TConfig ini(_prima_nota, para); const TRectype& cau = cache().get(LF_CAUSALI, ini.get(MOV_CODCAUS)); m.set(F_CODMOV, cau.get(CAU_COLLCESP), TRUE); if (m.field(F_TPDOC).active()) m.set(F_TPDOC, ini.get(MOV_TIPODOC), TRUE); if (m.field(F_NDOC).active()) m.set(F_NDOC, ini.get(MOV_NUMDOC), TRUE); if (m.field(F_DTDOC).active()) m.set(F_DTDOC, ini.get(MOV_DATADOC), TRUE); TString desc = ini.get(MOV_DESCR); if (desc.empty()) desc = cau.get(CAU_DESCR); m.set(F_DESC_MOV, desc, TRUE); if (m.field(F_COSTO).enabled()) { para.format("%d,%d", LF_RMOV, _cg_line); m.set(F_COSTO, ini.get(RMV_IMPORTO, para)); } _cg_line++; } } void TMovicespi::init_modify_mode(TMask& m) { const int staat = init_mask(m); TEsercizi_contabili esc; m.disable(F_IDCESPITE); m.disable(F_DESC_CES); const TRectype& rec = get_relation()->curr(); const TDate dtmov = rec.get(MOVCE_DTMOV); bool bollato = rec.get_bool(MOVCE_STAMPATO); if (!bollato) // Se proprio non ci fidiamo del flag { const TEsercizio& e = esc[m.get_int(F_ESERCIZIO)]; const TDate dtini = e.inizio(); const TDate dtfin = e.fine(); bollato = (staat == 3 && dtmov <= dtfin) || (staat == 2 && dtmov < dtini); } if (bollato) { m.disable(DLG_SAVEREC); m.disable(DLG_DELREC); TString msg = "Movimento già stampato sul Bollato dell'esercizio "; msg << esc.date2esc(dtmov); xvt_statbar_set(msg); } } void TMovicespi::kill_mov(const TString& idcespite, const TString& idmov, int lfile) { CHECKD(lfile == LF_MOVAM || lfile == LF_AMMMV, "Invalid file ", lfile); TRelation rel(lfile); TRectype& filter = rel.curr(); filter.put("IDCESPITE", idcespite); filter.put("IDMOV", idmov); TCursor cur(&rel, "", 1, &filter, &filter); const long items = cur.items(); cur.freeze(); for (cur = 0L; cur.pos() < items; ++cur) rel.remove(); } void TMovicespi::kill_rett(const TString& id, const TString& idmov) { TRelation rel(LF_MOVCE); // Il cursore delle rettifiche usa la chiave 2: IDCESPITE+IDMOV // Per cui parto a selezionare le possibili rettifiche dal movimento da rettificare ... TRectype fromret(LF_MOVCE); fromret.put(MOVCE_IDCESPITE, id); fromret.put(MOVCE_IDMOV, idmov); // ... in poi TRectype toret(LF_MOVCE); toret.put(MOVCE_IDCESPITE, id); TString filtro; filtro << MOVCE_IDRET << "==" << idmov; // Confronto numerico! TCursor movcur(&rel, filtro, 2, &fromret, &toret); const long items = movcur.items(); if (items > 0) // Se ci sono rettifiche { const TRectype& curr = movcur.curr(); movcur.freeze(); for (movcur = 0L; movcur.pos() < items; ++movcur) { const TString16 idmov = curr.get(MOVCE_IDMOV); if (rel.remove() == NOERR) { kill_mov(id, idmov, LF_MOVAM); kill_mov(id, idmov, LF_AMMMV); } } } } bool TMovicespi::remove() { const TRectype& curr = get_relation()->curr(); const TString16 idcespite = curr.get(MOVCE_IDCESPITE); const TString16 idmov = curr.get(MOVCE_IDMOV); TRelation_application::remove(); kill_mov(idcespite, idmov, LF_MOVAM); kill_mov(idcespite, idmov, LF_AMMMV); kill_rett(idcespite, idmov); return TRUE; } int ce1500(int argc, char* argv[]) { TMovicespi mc; mc.run(argc, argv, "Movimenti cespiti"); return 0; }