diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 0f3aba58f..c13bbcfa1 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -733,6 +733,8 @@ void TPrimanota_application::mask2rel(const TMask& m) { m.autosave(_rel); + TRectype& rec = _rel->curr(); // Record della testata + const long numreg = m.get_long(F_NUMREG); const TDate datareg(m.get(F_DATAREG)); const int annoes = m.get_int(F_ANNOES); @@ -742,6 +744,17 @@ void TPrimanota_application::mask2rel(const TMask& m) _saldi.set_anno_es(annoes); _saldi.set_num_ulmov(numreg); _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); + + const int tm = causale().tipomov(); + char s[2]; + if (tm > 0) + { + s[0] = tm+'0'; + s[1] = '\0'; + } + else + s[0] = '\0'; + rec.put(MOV_TIPOMOV, s); // Tolto dalla maschera (su file e' alfanumerico)! _rel->destroy_rows(numreg); // Destroy all records cgs_pack(); // Destroy all null rows @@ -788,8 +801,6 @@ void TPrimanota_application::mask2rel(const TMask& m) if (_iva == nessuna_iva) return; - TRectype& rec = _rel->curr(); // Record della testata - if (causale().corrispettivi()) { rec.put("TIPO", ""); diff --git a/cg/cg2100.h b/cg/cg2100.h index cfbe1e9c0..60567413a 100755 --- a/cg/cg2100.h +++ b/cg/cg2100.h @@ -39,7 +39,6 @@ #define F_ANNORIF 124 #define F_NUMRIF 125 #define F_PROVVISORIO 129 -#define F_TIPOMOV 130 #define F_OCCASEDIT 131 #define F_SOLAIVA 132 #define F_CORRLIRE 133 diff --git a/cg/cg2100c.uml b/cg/cg2100c.uml index 8b22ffff7..d95938100 100755 --- a/cg/cg2100c.uml +++ b/cg/cg2100c.uml @@ -82,7 +82,7 @@ END STRING F_CODREG 3 BEGIN PROMPT 57 4 "Registro IVA " - FLAGS "DGUZ" + FLAGS "DUZ" FIELD REG END @@ -101,7 +101,6 @@ BEGIN OUTPUT F_DESCRCAUS DESCR OUTPUT F_CODREG REG OUTPUT F_TIPODOC TIPODOC - OUTPUT F_TIPOMOV TIPOMOV MESSAGE COPY,H_CODCAUS CHECKTYPE REQUIRED ADD RUN cg0 -4 @@ -137,13 +136,6 @@ BEGIN FLAGS "D" END -NUMBER F_TIPOMOV 1 -BEGIN - PROMPT 32 6 "Tipo movimento " - FIELD TIPOMOV - FLAGS "H" -END - STRING F_NUMDOC 7 BEGIN PROMPT 57 6 "Documento n. " diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 97407c73d..9bf2292e8 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -514,14 +514,15 @@ HIDDEN bool imptot_error(const TImporto& imptot, const TImporto& impsal, bool va const TMask& m = a.curr_mask(); TString msg(255); - msg << "Il totale documento " << (val ? "in valuta" : "inserito") - << " e' " << imptot.valore().string(pic) << ' ' << imptot.sezione() << ",\n"; + msg << "Il totale documento "; + if (val) + msg << "in valuta " << m.get(SK_VALUTA); + else + msg << "inserito"; + msg << " e' " << imptot.valore().string(pic) << ' ' << imptot.sezione() << ",\n"; msg << "i pagamenti e le spese ammontano a " << impsal.valore().string(pic) << ' ' << impsal.sezione() << ",\n"; - msg << "per cui il residuo e' " << residuo.valore().string(pic); - if (val) - msg << ' ' << m.get(SK_VALUTA); - msg << '.'; + msg << "per cui il residuo e' " << residuo.valore().string(pic) << '.'; if (m.edit_mode() && impsal.is_zero()) { diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index 7f6d9498f..f97541cb6 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -477,25 +477,14 @@ bool TPrimanota_application::cambio_handler(TMask_field& f, KEY key) TMask& m = f.mask(); TPrimanota_application& a = app(); - bool update = FALSE; // Devo ricopiarmi a pagina 3? + bool update = a.is_fattura(); // Devo ricopiarmi a pagina 3? if (f.focusdirty()) { // Forza il ricalcolo del totale in lire se necessario a.gioca_cambi(m.insert_mode() ? 0x1 : 0x0); - - if (a.is_fattura()) - { - TPagamento& pag = a.pagamento(); -// pag.set_cambio(m, m.get_bool(FS_RECALC)); // Aggiorna cambio sul pagamento - update = TRUE; - - TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); - pag.set_sheet(ps); - a.pag_rows() = ps.rows_array(); - } } else - update = a.is_fattura() && !m.is_running(); + update &= !m.is_running(); if (update) m.set(FS_CAMBIO, f.get()); // Copia a pagina 3 diff --git a/cg/cg2105.cpp b/cg/cg2105.cpp index a749daccb..0f4e9dc67 100755 --- a/cg/cg2105.cpp +++ b/cg/cg2105.cpp @@ -33,7 +33,7 @@ class TGame_mask : public TMask tipo_movimento _tipomov; // Dati per la creazione di un nuovo movimento char _sezione; - TDate _datadoc; + TDate _datad; TString _codpag, _descr, _numdoc; TDecoder _causali; // Decodificatore delle causali @@ -54,7 +54,7 @@ protected: void fill_partite(); - real aggiorna_residuo(); + void aggiorna_residuo(); int update_partita(const TPartita& game, int prow); void update_saldo_clifo(); @@ -563,34 +563,35 @@ bool TGame_mask::cambio_handler(TMask_field& f, KEY k) /////////////////////////////////////////////////////////// // Aggiorna il campo con il residuo da spendere sui pagamenti -real TGame_mask::aggiorna_residuo() +void TGame_mask::aggiorna_residuo() { #ifdef __EXTRA__ return ZERO; #else _importo = app().get_cgs_imp(_numrig-1); // Importo sulla riga contabile _residuo = _importo; - _residuo -= app().partite().importo_speso(_numreg, _numrig); // Residuo della riga + + TPartite_array& giochi = app().partite(); + const TImporto speso = giochi.importo_speso(_numreg, _numrig); + _residuo -= speso; // Residuo della riga const char sez = calcola_sezione(); // Sezione di riferimento _residuo.normalize(sez); - - const real& res = _residuo.valore(); - set(P_RESIDUO, res); + set(P_RESIDUO, _residuo.valore()); - if (field(P_CAMBIO).enabled()) - { - const TValuta cambio(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO); - if (cambio.in_valuta()) - { - _resval = _importo; cambio.lit2val(_resval); - _resval -= app().partite().importo_speso(_numreg, _numrig, TRUE); // Residuo della riga - _resval.normalize(sez); - set(P_RESIDUOVAL, _resval.valore()); - } + const TValuta cambio(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO); + if (cambio.in_valuta()) + { + // Importo della riga contabile senza differenza cambi + _resval = _importo; + const TImporto diffcam = giochi.importo_speso(_numreg, _numrig, FALSE, 0x4); + _resval -= diffcam; + cambio.lit2val(_resval); + const TImporto spesoval = giochi.importo_speso(_numreg, _numrig, TRUE); + _resval -= spesoval; // Residuo della riga + _resval.normalize(sez); + set(P_RESIDUOVAL, _resval.valore()); } - - return res; #endif } @@ -678,7 +679,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) gm.set(P_ANNO, anno); // Aggiorna campi di ricerca gm.set(P_NUMERO, num); - TString prima_valuta; // Codice prima valuta + TString prima_valuta; // Codice prima valuta if (anno > 0) { @@ -1084,8 +1085,10 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) const TBill& bill = gm.conto(); const int anno = gm.get_int(P_ANNO); const TString16 numero = gm.get(P_NUMERO); - - TPartita& game = app().partite().partita(bill, anno, numero); + + TPartite_array& giochi = app().partite(); + TPartita* was = giochi.exist(bill, anno, numero); // Controlla esistenza nell'array + TPartita& game = was ? *was : giochi.partita(bill, anno, numero); long nreg = m.get_long(108); // Numero registrazione const int nrata = m.get_int(102); // Rata selezionata (puo' essere 0) @@ -1094,7 +1097,10 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) if (nrata != 0 && nrigp == 0) { if (m.get_bool(114)) + { + if (was == NULL) giochi.destroy(game); return f.error_box("La rata %d e' bloccata.", nrata); + } const TValuta parval(game.riga(nriga)); const TValuta curval(gm, P_VALUTA, P_DATACAMBIO, P_CAMBIO); @@ -1102,6 +1108,8 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) { TString c = parval.codice(); if (c.empty()) c = "lire"; + + if (was == NULL) giochi.destroy(game); return f.error_box("La fattura deve essere pagata in %s.", (const char*)c); } @@ -1124,7 +1132,8 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) { cambiato = gm.edit_pagamento(game, nriga, nrata, nrigp); if (cambiato) - { + { + // Se ho cancellato il pagamento chiudo la maschera if (m.is_running() && !game.esiste(nriga, nrata, nrigp)) m.stop_run(K_FORCE_CLOSE); } @@ -1134,6 +1143,7 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) #ifdef __EXTRA__ gm.prima_nota(nreg); #else + if (was == NULL) giochi.destroy(game); return f.error_box("Modificare il movimento %ld", nreg); #endif } @@ -1148,6 +1158,7 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) #else if (nreg != gm._numreg || nrata == 0) { + if (was == NULL) giochi.destroy(game); if (nreg == 0) f.error_box("Utilizzare la gestione extra-contabile"); else @@ -1182,7 +1193,7 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) // Se la partita e' presente anche su file non posso cancellarla: // altrimenti non verra' rimossa alla registrazione! if (!game.is_on_file()) - app().partite().destroy(game); + giochi.destroy(game); if (on_sheet) gm.fill_partite(); } @@ -1453,8 +1464,14 @@ void TGame_mask::fill_partite() if (gioco->ok()) { const TBill& k = gioco->conto(); - const bool u = (k.tipo() > ' ' && k.sottoconto() == conto().sottoconto()) || - k == conto(); + bool u = (k.tipo() > ' ' && k.sottoconto() == conto().sottoconto()) || k == conto(); + +#ifdef DBG + if (u && !all && gioco->chiusa() && gioco->mov2rig(_numreg, _numrig) <= 0) + u = error_box("Tentativo di visualizzare partita %d %s!", + gioco->anno(), (const char*)gioco->numero()); +#endif + if (u) update_partita(*gioco, -1); } diff --git a/cg/cg21sld.uml b/cg/cg21sld.uml index 0a393f2a7..c87a1e047 100755 --- a/cg/cg21sld.uml +++ b/cg/cg21sld.uml @@ -52,6 +52,7 @@ NUMBER FS_NRATE 3 BEGIN PROMPT 36 6 "Numero di rate " CHECKTYPE REQUIRED + FLAGS "U" END STRING FS_VALUTA 3 diff --git a/cg/pagament.cpp b/cg/pagament.cpp index 576f44f18..685dd6ccb 100755 --- a/cg/pagament.cpp +++ b/cg/pagament.cpp @@ -185,7 +185,7 @@ void TPagamento::set_tipo_prima_rata(int v, int sscad) void TPagamento::set_numero_rate(int n, int sscad, int rdiff) { - if (n == 0) return; + if (n <= 0) return; _dirty = FALSE; const int nr = n_rate(); @@ -427,49 +427,9 @@ void TPagamento::set_numero_rate(int n, int sscad, int rdiff) } adjust_fixed_scad(); - _dirty = TRUE; } -void TPagamento::set_cambio(const TMask& m, bool recalc_lit) -{ - const int first = _tpr < 4 ? 0 : 1; - const bool era_valuta = in_valuta(); - - _cambio = m.get_real(SK_CAMBIO); - if (_cambio.sign() <= 0) - _cambio = 1.0; - - const bool in_val = m.get(SK_VALUTA).not_empty(); - - real imp; // Importo di parcheggio - - if (era_valuta) - { - if (in_val) // Da valuta a valuta - { - if (recalc_lit) - adjust_perc_imp(TRUE, _rdiff, FALSE); - } - else // Da valuta a lire - { - _firstr = _secndr = ZERO; - for (int i = _rate.items()-1; i >= 0; i--) - set_imprata(i, ZERO, TRUE); - } - } - else - { - if (in_val) // Da lire a valuta - { - real imponibile = m.get(SK_TOTDOCVAL); - real imposta = _imposlit / _cambio; imposta.round(_roundval); - real spese = _speselit / _cambio; spese.round(_roundval); - init_total(imponibile, imposta, spese, TRUE); - adjust_perc_imp(TRUE, _rdiff, TRUE); - } - } -} /* void TPagamento::adjust_importo_lire(int start) diff --git a/cg/pagament.h b/cg/pagament.h index ab8bdc5be..73473accd 100755 --- a/cg/pagament.h +++ b/cg/pagament.h @@ -162,7 +162,6 @@ public: void set_inizio_scadenza(char v) { _inscad = v; } void set_code(const char* c) { _code = c; } void set_roundval(int n) { _roundval = n; } - void set_cambio(const TMask& m, bool recalc_lit); bool in_valuta() const { return _in_valuta; } const real& cambio() const { return _cambio; } diff --git a/cg/saldacon.cpp b/cg/saldacon.cpp index 5a00350b0..c531a2fc1 100755 --- a/cg/saldacon.cpp +++ b/cg/saldacon.cpp @@ -1125,7 +1125,7 @@ bool TPartita::esiste(int nriga, int nrata, int nrigp) const } // Ritorna l'importo in lire speso su di una riga contabile -TImporto TPartita::importo_speso(long nreg, int numrig, bool valuta) const +TImporto TPartita::importo_speso(long nreg, int numrig, bool valuta, int mode) const { TImporto imp; @@ -1133,7 +1133,7 @@ TImporto TPartita::importo_speso(long nreg, int numrig, bool valuta) const { const TRiga_partite& row = riga(r); if (nreg == row.get_long(PART_NREG) && numrig == row.get_int(PART_NUMRIG)) - imp += row.importo(valuta); + imp += row.importo(valuta, mode); } return imp; @@ -1673,18 +1673,17 @@ int TPartite_array::add_numreg(long nreg) { if (nreg != _numreg) { - TLocalisamfile rel(LF_PARTITE); - rel.setkey(2); // Chiave per NREG + TRelation rel(LF_PARTITE); TRectype& part = rel.curr(); part.zero(); part.put(PART_NREG, nreg); - for (int err = rel.read(_isgreat); - err == NOERR && part.get_long(PART_NREG) == nreg; - err = rel.next()) - { + + // Uso un cursore per evitare conflitti di lettura con l'oggetta partita + TCursor cur(&rel, "", 2, &part, &part); + for (cur = 0; cur.ok(); ++cur) partita(part); // Aggiungi partita se non esiste gia' - } + _numreg = nreg; } @@ -1702,12 +1701,12 @@ bool TPartite_array::utilizzata(long numreg, int numrig) return ok; } -TImporto TPartite_array::importo_speso(long nreg, int numrig, bool valuta) +TImporto TPartite_array::importo_speso(long nreg, int numrig, bool valuta, int mode) { TImporto imp; add_numreg(nreg); for (TPartita* game = first(); game; game = next()) - imp += game->importo_speso(nreg, numrig, valuta); + imp += game->importo_speso(nreg, numrig, valuta, mode); imp.normalize(); return imp; } diff --git a/cg/saldacon.h b/cg/saldacon.h index 98cc17707..604b42c7e 100755 --- a/cg/saldacon.h +++ b/cg/saldacon.h @@ -286,7 +286,7 @@ public: const TString& numero() const { return _num; } const TString& descrizione() const; - TImporto importo_speso(long numreg, int numrig, bool valuta) const; + TImporto importo_speso(long numreg, int numrig, bool valuta, int mode = 0xF) const; void update_reg(long nreg, const TRectype& mov, const TRecord_array& cg); void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const; TImporto calcola_saldo(bool valuta) const; @@ -336,7 +336,7 @@ public: bool rewrite() { return write(TRUE); } int add_numreg(long numreg); // Carica tutte le partite relative alla registrazione numreg - TImporto importo_speso(long numreg, int numrig, bool valuta = FALSE); + TImporto importo_speso(long numreg, int numrig, bool valuta = FALSE, int mode = 0xF); void update_reg(const TRectype& mov, const TRecord_array& cg, long old_reg = 0); // Controlla se esistono righe di pagamento relative alla riga numrig