diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index b8e53cf31..86d8db2de 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -583,18 +583,22 @@ void TPrimanota_application::init_insert_mode(TMask& m) m.set(F_DATA74TER, m.get(F_DATAREG)); if (iva() != nessuna_iva) + { occas_mask().reset(); - + m.hide(F_OCCASEDIT); + } + partite().destroy(); if (is_fattura()) - { + { + activate_numrif(FALSE); const TString16 dt(m.get(F_DATADOC)); set_pagamento(NULL,dt); set_scadenze(m); } else { - set_pagamento(NULL,NULL); // Annulla pagamento + set_pagamento(NULL,NULL); // Annulla gestione rate } _saldi.reset(); // Inizializza saldi @@ -631,6 +635,7 @@ int TPrimanota_application::read(TMask& m) { ivas().reset(); // Azzera tutte le righe iva + occas_mask().reset(); const TString16 occode(_rel->lfile().get("OCFPI")); occas_mask().set(O_CODICE, occode); diff --git a/cg/cg2100b.uml b/cg/cg2100b.uml index 3503e33b2..cb7b6dcb0 100755 --- a/cg/cg2100b.uml +++ b/cg/cg2100b.uml @@ -184,8 +184,6 @@ BEGIN DISPLAY "Nome@50" S0 OUTPUT SK_VALUTA CODTAB CHECKTYPE NORMAL - MESSAGE EMPTY CLEAR,SK_CAMBIO|CLEAR,SK_TOTDOCVAL - MESSAGE ENABLE,SK_CAMBIO|ENABLE,SK_TOTDOCVAL|DIRTY,SK_DATACAMBIO|K_TAB,SK_DATACAMBIO END DATE SK_DATACAMBIO diff --git a/cg/cg2100s.uml b/cg/cg2100s.uml index fc94b7533..c71b3fb6b 100755 --- a/cg/cg2100s.uml +++ b/cg/cg2100s.uml @@ -242,7 +242,7 @@ BEGIN DISPLAY "Descrizione@50" S0 DISPLAY "Codice" CODTAB COPY OUTPUT S_CODDESC - FIELD LF_PARTITE->DESCAGG + FIELD LF_PARTITE->DESCR END NUMBER S_VSABI 5 diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 0fde32a89..599d8259c 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -63,7 +63,7 @@ real TPrimanota_application::scorpora(real& imponibile, const real& percent) } -// Calcola il totale del documento tenenod conto del segno della prima riga e di quella delle +// Calcola il totale del documento tenendo conto del segno della prima riga e di quella delle // ritenute sociali sulla causale real TPrimanota_application::totale_documento() { @@ -492,10 +492,11 @@ real TPrimanota_application::calcola_saldo() const if (pag) { - const char s(causale().sezione(2)); + const char s(causale().sezione(2)); // Conto della cassa const real t(m.get(F_TOTALE)); TImporto totdoc(s, t); totdoc += saldaconto; + totdoc.normalize(s); m.set(K_RESIDUO, totdoc.valore().string()); } @@ -505,7 +506,8 @@ real TPrimanota_application::calcola_saldo() const HIDDEN bool imptot_error(const TImporto& imptot, const TImporto& impsal, bool val) { bool ok = TRUE; - TImporto residuo(imptot); residuo += impsal; residuo.normalize(); + TImporto cassa(impsal); cassa.swap_section(); + TImporto residuo(imptot); residuo -= cassa; residuo.normalize(imptot.sezione()); if (!residuo.is_zero()) { @@ -521,7 +523,7 @@ HIDDEN bool imptot_error(const TImporto& imptot, const TImporto& impsal, bool va 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"; + << cassa.valore().string(pic) << ' ' << cassa.sezione() << ",\n"; msg << "per cui il residuo e' " << residuo.valore().string(pic) << '.'; if (m.edit_mode() && impsal.is_zero()) @@ -607,7 +609,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) { saldaconto += importo; if (in_valuta) - saldaconto_val += a.partite().importo_speso(numreg, i+1, TRUE); + saldaconto_val += a.partite().importo_speso(numreg, i+1, TRUE, 0x1); } } } @@ -1825,12 +1827,13 @@ bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key) if (*code) { TRelation occas(LF_OCCAS); - occas.lfile().put("CFPI", code); + occas.curr().put("CFPI", code); if (occas.read(_isequal) == NOERR) - { - f.mask().autoload(&occas); - f.mask().send_key(K_TAB, O_COMUNE); // Forza decodifica comuni - f.mask().send_key(K_TAB, O_COMUNENAS); + { + TMask& m = f.mask(); + m.autoload(&occas); + m.send_key(K_TAB, O_COMUNE); // Forza decodifica comuni + m.send_key(K_TAB, O_COMUNENAS); } } } @@ -2371,7 +2374,15 @@ bool TPrimanota_application::activate_numrif(bool init_pag) { m.show(F_ANNORIF, shown); m.show(F_NUMRIF, shown); - if (!shown) + if (shown) + { + if (m.get(F_ANNORIF).empty()) + { + m.set(F_ANNORIF, m.get(F_DATADOC).right(4)); + m.set(F_NUMRIF, m.get(_npart_is_prot ? F_PROTIVA : F_NUMDOC)); + } + } + else { m.reset(F_ANNORIF); m.reset(F_NUMRIF); @@ -2415,11 +2426,11 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) const TPartita* game = a.partite().first(); if (anchecg) - { + { if (game != NULL) { m.set(F_ANNORIF, game->anno()); - m.set(F_NUMRIF, game->numero(), TRUE); + m.set(F_NUMRIF, game->numero()); } } else diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index 8661a42d8..7bbcdcee0 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -316,8 +316,7 @@ bool TPrimanota_application::codpag_handler(TMask_field& f, KEY key) const bool set_scad = a.is_fattura() && m.page_enabled(2); // E' attiva pagina 3 if (key == K_ENTER) { - const bool required = a.is_fattura() && (m.insert_mode() || set_scad); - if (required && f.get().empty()) + if (set_scad && f.get().empty()) { f.error_box("Il codice di pagamento e' obbligatorio!\n" "Se possibile esso verra' proposto, ma potra'\n" @@ -375,14 +374,12 @@ bool TPrimanota_application::numrif_handler(TMask_field& f, KEY key) TPrimanota_application& a = app(); TMask& m = f.mask(); - const bool required = m.insert_mode() && a.is_fattura() && - (key == K_ENTER || f.focusdirty()) && - !(m.get_bool(F_SOLAIVA) || m.field(F_OCCASEDIT).enabled()); + bool required = m.insert_mode() && a.is_fattura(); + required &= key == K_ENTER || f.focusdirty(); + required &= !(m.get_bool(F_SOLAIVA) || m.field(F_OCCASEDIT).active()); if (required && f.get().blank()) { - f.set(m.get(a._npart_is_prot ? F_PROTIVA : F_NUMDOC)); - if (m.get(F_CODPAG).empty()) { TMask_field& clifo = m.field(a.iva() == iva_vendite ? F_CLIENTE : F_FORNITORE); @@ -391,15 +388,15 @@ bool TPrimanota_application::numrif_handler(TMask_field& f, KEY key) } TMask_field& anno = m.field(F_ANNORIF); - if (anno.get().empty()) - { - anno.set_dirty(); - anno.on_hit(); - } + if (m.get(F_ANNORIF).empty()) + m.set(F_ANNORIF, m.get(F_DATADOC).right(4)); + + f.set(m.get(a._npart_is_prot ? F_PROTIVA : F_NUMDOC)); + key = K_TAB; // Forza la successiva activate_numrif - ok = error_box("Il numero di riferimento partita e' obbligatorio!\n" - "Se possibile esso verra' proposto, ma potra'\n" - "essere modificato prima di registrare il movimento."); + ok = f.error_box("Il numero di riferimento partita e' obbligatorio!\n" + "Se possibile esso verra' proposto, ma potra'\n" + "essere modificato prima di registrare il movimento."); } if (key == K_TAB && a.is_fattura()) @@ -861,7 +858,7 @@ void TPrimanota_application::write_scadenze(const TMask& m) int nuova_riga = 0; - if (anno > 0 && !numpart.blank()) + if (m.page_enabled(2)) { const int tmov = causale().tipomov(); const TString desc(m.get(F_DESCR)); @@ -976,7 +973,10 @@ void TPrimanota_application::write_scadenze(const TMask& m) } if (newgame != NULL) // Se non ho cancellato il numero partita ... + { newgame->write(); // Salva nuova partita + delete newgame; + } } @@ -990,8 +990,9 @@ bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k) TMask& m = f.mask(); TPrimanota_application& a = app(); - const char tipo = m.get(CG_ROWTYPE)[0]; - if (tipo == 'K' || (tipo == 'T' && a.causale().tipomov() == 2)) + const char tipo = m.get(CG_ROWTYPE)[0]; + const bool is_nota = tipo == 'T' && a.causale().tipomov() == 2 && m.field(F_NUMRIF).active(); + if (tipo == 'K' || is_nota) { TSheet_field& s = *m.get_sheet(); const int riga = s.selected(); diff --git a/cg/cg2105.cpp b/cg/cg2105.cpp index d9eaa06f5..a7179ef1a 100755 --- a/cg/cg2105.cpp +++ b/cg/cg2105.cpp @@ -62,7 +62,7 @@ protected: int nuovo_pagamento(TPartita& partita, int nriga, int rata, tipo_movimento tm) const; bool edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) const; - char calcola_sezione() const; + char calcola_sezione(tipo_movimento tm = tm_pagamento) const; long number_distance(const char* key, const char* num) const; bool same_number(const char* key, const char* num) const; void append_conto(TString& s) const; @@ -107,23 +107,56 @@ protected: static bool importo_handler(TMask_field& f, KEY k); static bool importolire_handler(TMask_field& f, KEY k); static bool saldo_handler(TMask_field& f, KEY k); - static bool cambio_handler(TMask_field& f, KEY k); static bool datapag_handler(TMask_field& f, KEY k); static bool conto_handler(TMask_field& f, KEY k); + static bool descr_handler(TMask_field& f, KEY k); void gioca_cambi(int force = 0x0); public: void set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, const TImporto& importo); - void get_pag(TRectype& oldpag) const; + void get_pag(TRectype& oldpag, TRectype& somma) const; - TPay_mask(const TGame_mask& parent); + TPay_mask(const TGame_mask& parent, int mode); virtual ~TPay_mask() {} }; -TPay_mask::TPay_mask(const TGame_mask& parent) - : TMask("cg2100s"), _parent(parent), +#ifdef __EXTRA__ +const char* const PAYMASK = "sc0100b"; +#else +const char* const PAYMASK = "cg2100s"; +#endif + +TPay_mask::TPay_mask(const TGame_mask& parent, int mod) + : TMask(PAYMASK), _parent(parent), _causale(LF_CAUSALI, CAU_CODCAUS, CAU_DESCR) -{ +{ + set_mode(mod); + enable(DLG_DELREC, edit_mode()); + +#ifdef __EXTRA__ + enable(E_SEZIONE, insert_mode()); + + set_handler(E_TOTALE, TSaldaconto_app::totale_handler); + if (app().gestione_valuta()) + { + disable(E_VALUTA); // Non posso cambiare codice valuta! + set_handler(E_TOTDOCVAL, TSaldaconto_app::totval_handler); + set_handler(E_VALUTA, TSaldaconto_app::valuta_handler); + set_handler(E_DATACAMBIO, TSaldaconto_app::datacambio_handler); + set_handler(E_CAMBIO, TSaldaconto_app::cambio_handler); + } + else + hide(-3); + + hide(S_RESIDUOPAG); + hide(-2); // I campi relativi alla contropartita non vengono gestiti + + set_handler(E_DESCR, descr_handler); + set_handler(S_DESCAGG, descr_handler); + + disable(E_ANNORIF); + disable(E_NUMRIF); +#endif } void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, @@ -132,11 +165,11 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, const TPartita& p = scad.partita(); const int nrigp = oldpag.get_int(PAGSCA_NRIGP); const TRiga_partite& sum = p.riga(nrigp); - const TRiga_partite& fatt = scad.riga(); const bool assigned = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED; + const TRiga_partite& fatt = assigned ? scad.riga() : sum; TRelation rel(LF_PAGSCA); // Working relation - rel.add(LF_PARTITE, "ANNO=ANNO|NUMERO=NUMERO"); + rel.add(LF_PARTITE, "ANNO=ANNO|NUMPART=NUMPART"); rel.curr() = oldpag; rel.curr(LF_PARTITE) = sum; autoload(&rel); // Load current record on mask @@ -149,9 +182,9 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, { case 'C': prompt << "Cliente"; break; case 'F': prompt << "Fornitore"; break; - default : prompt << "Conto"; break; + default : prompt << "Conto " << k.gruppo() << ' ' << k.conto(); break; } - prompt << ' ' << k.gruppo() << ' ' << k.conto() << ' ' << k.sottoconto() << ' '; + prompt << ' ' << k.sottoconto() << ' '; prompt << "Partita:" << p.anno() << ' ' << p.numero() << " Riga:" << oldpag.get_int(PAGSCA_NRIGA) << " Rata:" << oldpag.get_int(PAGSCA_NRATA) @@ -176,25 +209,26 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, const bool in_valuta = fatt.in_valuta(); + set(S_SEZIONE_SCAD, fatt.sezione() == 'A' ? "A" : "D"); // Sezione della riga if (assigned) { - set(S_SEZIONE_SCAD, fatt.sezione() == 'A' ? "A" : "D"); // Sezione della riga set(S_IMPORTO_SCAD, scad.get(SCAD_IMPORTO)); // Importo della rata if (in_valuta) set(S_IMPORTOVAL_SCAD, scad.get(SCAD_IMPORTOVAL)); // Importo in valuta _da_pagare = scad.residuo(in_valuta).valore(); // Calcola residuo in valuta + + TReal_field& res = (TReal_field&)field(S_RESIDUORATA); + res.set_decimals(in_valuta ? 3 : 0); + if (get(S_SALDOACC)[0] != 'S') + res.set(_da_pagare.string()); } - else + else { - set(S_SEZIONE_SCAD, sum.sezione()); // Sezione della riga + hide(S_RESIDUORATA); // Se non assegnato nascondi residuo rata _da_pagare = ZERO; } - TReal_field& res = (TReal_field&)field(S_RESIDUORATA); - res.set_decimals(in_valuta ? 3 : 0); - if (get(S_SALDOACC)[0] != 'S') - res.set(_da_pagare.string()); - + if (in_valuta) { set_handler(S_IMPORTOVAL, importo_handler); @@ -211,12 +245,10 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, // Ricorda l'importo da pagare _da_pagare += oldimp; - const TValuta val(sum); - val.set(*this, S_VALUTA, S_DATACAMBIO, S_CAMBIO); - - const long numreg = sum.get_long(PART_NREG); - const int numrig = sum.get_int(PART_NUMRIG); +// const long numreg = sum.get_long(PART_NREG); +// const int numrig = sum.get_int(PART_NUMRIG); +#ifndef __EXTRA__ _pagabile = _parent.residuo(in_valuta).valore(); TReal_field& resp = (TReal_field&)field(S_RESIDUOPAG); @@ -224,10 +256,11 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, resp.set(_pagabile.string()); _pagabile += oldimp; +#endif // Il flag di saldo/acconto e' attivo solo se non ci sono acconti, cioe': // pagamento non assegnato o con data documento antecedente quella della fattura - _can_solder = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED; + _can_solder = assigned; if (_can_solder) { const tipo_movimento tm = sum.tipo(); @@ -239,42 +272,39 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, _can_solder = datapag >= datasca; } } - else - { - hide(S_RESIDUORATA); // Se non assegnato nascondi residuo rata - } + // Mostra saldo solo se non e' ne' un acconto, ne' una nota di credito enable(S_SALDOACC, _can_solder); - show(-3, in_valuta); // Attiva campi relativi alla valuta - show(-4, in_valuta); // Attiva campi relativi al cambio -#ifdef __EXTRA__ - set_handler(S_CAMBIO, cambio_handler); - hide(S_RESIDUOPAG); - const bool mostra_conto = FALSE; +#ifdef __EXTRA__ + // La valuta puo' essere cambiata solo su partite nuove + const bool on = p.first() == p.last(); + enable(E_VALUTA, on); #else - disable(-4); - - _datadoc = sum.get_date(PART_DATADOC); - set_handler(S_DATAPAG, datapag_handler); set_handler(S_GRUPPO, conto_handler); set_handler(S_CONTO, conto_handler); - const bool mostra_conto = !sum.is_nota_credito(); -#endif show(-2, mostra_conto); // mostra/nasconde conto contropartita +#endif + +// Gestione data-pagamento: non puo' precedere la data del documento + _datadoc = sum.get_date(PART_DATADOC); + set_handler(S_DATAPAG, datapag_handler); const bool mostra_ritenute = !(sum.is_nota_credito() || in_valuta); show(S_RITENUTE, mostra_ritenute); // mostra/nasconde ritenute } -void TPay_mask::get_pag(TRectype& newpag) const +void TPay_mask::get_pag(TRectype& newpag, TRectype& sum) const { TRelation rel(LF_PAGSCA); // Working relation - rel.curr() = newpag; + rel.add(LF_PARTITE, "ANNO=ANNO|NUMPART=NUMPART"); + rel.curr() = newpag; + rel.curr(LF_PARTITE) = sum; autosave(&rel); // Load current record from mask newpag = rel.curr(); + sum = rel.curr(LF_PARTITE); } // Riempie i campi valuta a zero in base agli altri @@ -282,11 +312,13 @@ void TPay_mask::gioca_cambi(int force) { const real totale = get(S_IMPORTO); const real totval = get(S_IMPORTOVAL); + #ifdef __EXTRA__ const TValuta cambio(*this, E_VALUTA, E_DATACAMBIO, E_CAMBIO); #else const TValuta cambio(_parent, P_VALUTA, P_DATACAMBIO, P_CAMBIO); #endif + if ( (force == 0x1 || totale.is_zero()) && !(totval.is_zero() || cambio.in_lire()) ) { const real new_totale = cambio.val2lit(totval); @@ -300,13 +332,15 @@ void TPay_mask::gioca_cambi(int force) if (new_totval != totval) set(S_IMPORTOVAL, new_totval, TRUE); } - + +#ifdef __EXTRA__ if ( (force == 0x4 || cambio.in_lire()) && !(totale.is_zero() || totval.is_zero())) { real new_cambio = totale / totval; new_cambio.round(5); if (new_cambio != cambio.cambio()) - set(S_CAMBIO, new_cambio, TRUE); + set(E_CAMBIO, new_cambio, TRUE); } +#endif } @@ -391,17 +425,6 @@ bool TPay_mask::saldo_handler(TMask_field& f, KEY k) return TRUE; } - -bool TPay_mask::cambio_handler(TMask_field& f, KEY k) -{ - if (k == K_TAB && f.focusdirty()) - { - TPay_mask& m = (TPay_mask&)f.mask(); - m.gioca_cambi(); - } - return TRUE; -} - bool TPay_mask::datapag_handler(TMask_field& f, KEY k) { if (f.to_check(k)) @@ -434,25 +457,46 @@ bool TPay_mask::conto_handler(TMask_field& f, KEY k) /////////////////////////////////////////////////////////// class TNew_mask : public TMask -{ +{ + bool _allow_fatt; + +protected: + static bool tipomov_handler(TMask_field& f, KEY k); + public: TNew_mask(char tipocf, bool fatt, bool edit); virtual ~TNew_mask() {} }; +bool TNew_mask::tipomov_handler(TMask_field& f, KEY k) +{ + if (k == K_ENTER) + { + TNew_mask& m = (TNew_mask&)f.mask(); + if (!m._allow_fatt && f.get() == "1") + return f.error_box("Non e' possibile utilizzare una fattura per un pagamento"); + } + + return TRUE; +} + TNew_mask::TNew_mask(char tipocf, bool fatt, bool edit) - : TMask(fatt ? "cg2100n" : "sc0100n") -{ + : TMask("cg2100n"), _allow_fatt(fatt) +{ + TMask_field& tipomov = field(P_NUOVO); #ifdef __EXTRA__ - enable(P_NUOVO); + tipomov.set_handler(tipomov_handler); + tipomov.enable(); + tipomov.set(_allow_fatt ? "1" : "3"); + if (!_allow_fatt) + set_caption("Nuovo pagamento"); #else - disable(P_NUOVO); + tipomov.disable(); #endif enable(P_ANNO, edit); enable(P_NUMERO, edit); - if (edit) - first_focus(P_NUMERO); + if (edit) first_focus(P_NUMERO); const char a = TPartita::allineamento_richiesto(tipocf); field(P_NUMERO).set_justify(a == 'R'); @@ -485,13 +529,16 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga) descr << ' ' << ((TBill&)_conto).descrizione(); set(P_DESCR, descr); +#ifdef __EXTRA__ + disable(-3); // Disabilita gestione valuta + hide(P_RESIDUO); + hide(P_RESIDUOVAL); +#else TValuta val; -#ifndef __EXTRA__ const TRiga_partite* row = cerca_prima_riga(); if (row != NULL) { val.get(*row); // Legge valuta standard dalla partita - set(P_ANNO, row->get(PART_ANNO)); // Propone anno e partita set(P_NUMERO, row->get(PART_NUMPART)); } @@ -507,9 +554,8 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga) } } val.set(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO); -#endif - enable(-3, val.in_valuta()); +#endif set_handler(P_ANNO, annopart_handler); set_handler(P_NUMERO, numpart_handler); @@ -615,7 +661,7 @@ void TGame_mask::aggiorna_residuo() 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); set(P_RESIDUO, _residuo.valore()); @@ -625,10 +671,10 @@ void TGame_mask::aggiorna_residuo() { // Importo della riga contabile senza differenza cambi _resval = _importo; - const TImporto diffcam = giochi.importo_speso(_numreg, _numrig, FALSE, 0x4); - _resval -= diffcam; + const TImporto abb_diff = giochi.importo_speso(_numreg, _numrig, FALSE, 0x6); + _resval -= abb_diff; cambio.lit2val(_resval); - const TImporto spesoval = giochi.importo_speso(_numreg, _numrig, TRUE); + const TImporto spesoval = giochi.importo_speso(_numreg, _numrig, TRUE, 0x1); _resval -= spesoval; // Residuo della riga _resval.normalize(sez); set(P_RESIDUOVAL, _resval.valore()); @@ -678,6 +724,7 @@ void TGame_mask::aggiorna_valuta(const TValuta& val) fill_partite(); } +/* void TGame_mask::aggiorna_sorelle(const TRiga_partite& part) const { TPartite_array& pa = app().partite(); @@ -694,7 +741,8 @@ void TGame_mask::aggiorna_sorelle(const TRiga_partite& part) const } } } -} +} +*/ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) { @@ -720,7 +768,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 + TValuta prima_valuta; // Codice prima valuta if (anno > 0) { @@ -736,10 +784,9 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) const int lastrow = game->last(); - if (lastrow > 0 && prima_valuta.empty()) - prima_valuta = game->riga(lastrow).get(PART_CODVAL); - - const bool in_valuta = prima_valuta.not_empty(); + if (lastrow > 0 && prima_valuta.in_lire()) + prima_valuta.get(game->riga(lastrow)); + const bool in_valuta = prima_valuta.in_valuta(); for (int ri = game->first(); ri <= lastrow; ri = game->succ(ri)) { @@ -914,9 +961,11 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) { TToken_string& sp = scadenze.row(scadenze.add("")); sp.add("Saldo partita", 4); - if (prima_valuta.not_empty()) - sp << ' ' << prima_valuta; - + if (prima_valuta.in_valuta()) + sp << ' ' << prima_valuta.codice(); +#ifdef __EXTRA__ + prima_valuta.set(gm, P_VALUTA, P_DATACAMBIO, P_CAMBIO); +#endif gm.add_importo(sp, tot_lit); gm.add_importo(sp, tot_val, TRUE); } @@ -925,10 +974,10 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) delete game; } - if (prima_valuta.not_empty() != gm._valfirst) + if (prima_valuta.in_valuta() != gm._valfirst) { sheet.swap_columns(106, 107); // Scambia le colonne dell'importo in lire e in valuta - gm._valfirst = prima_valuta.not_empty(); + gm._valfirst = !gm._valfirst; } if (sheet.items() > 0) @@ -961,16 +1010,17 @@ bool TGame_mask::scadenze_notify(TSheet_field& scadenze, int r, KEY k) // Complesso algoritmo per calcolare la sezione di una nuova riga partita -char TGame_mask::calcola_sezione() const +char TGame_mask::calcola_sezione(tipo_movimento tm) const { char sezione = ' '; + const char tipoc = conto().tipo(); #ifndef __EXTRA__ const TCausale& causale = app().causale(); - const tipo_movimento tm = (tipo_movimento)causale.tipomov(); - const char tipoc = conto().tipo(); - + tm = (tipo_movimento)causale.tipomov(); sezione = causale.sezione(1); // Usa la sezione della causale +#endif + if (sezione <= ' ') // Se non c'e' la sezione bell'e' ch'e' pronta { if (tm == tm_fattura || tm == tm_insoluto) // calcola in base al tipo movimento e @@ -978,6 +1028,9 @@ char TGame_mask::calcola_sezione() const else sezione = (tipoc == 'C') ? 'A' : 'D'; } + +#ifndef __EXTRA__ + // Gestione compensazioni if (tipoc > ' ') // Se il tipo e' C o F { TBill bill; causale.bill(1, bill); // Legge primo conto causale @@ -991,9 +1044,11 @@ char TGame_mask::calcola_sezione() const } int TGame_mask::nuova_riga(TPartita& partita, tipo_movimento tm) const -{ +{ + const int prima_riga = partita.first(); // Memorizza prima riga + TRiga_partite& part = partita.new_row(); // Creazione nuova riga vuota - const int nriga = part.get_int(PART_NRIGA); + const int nriga = part.get_int(PART_NRIGA); // Nuova riga // Copia dati movimento corrente part.put(PART_NREG, _numreg); // Numero operazione @@ -1003,13 +1058,26 @@ int TGame_mask::nuova_riga(TPartita& partita, tipo_movimento tm) const part.put(PART_GRUPPOCL, conto().gruppo()); part.put(PART_CONTOCL, conto().conto()); + part.put(PART_TIPOMOV, (int)tm); + + if (prima_riga > 0) + { + const char* valuta = partita.riga(prima_riga).get(PART_CODVAL); + part.put(PART_CODVAL, valuta); + } + +#ifdef __EXTRA__ + const TDate oggi(TODAY); + const char* s = oggi.string(); + part.put(PART_DATADOC, s); + part.put(PART_DATAREG, s); + if (tm != tm_fattura) + part.put(PART_DATAPAG, s); +#else // Setta il cambio corrente const TValuta valuta(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO); valuta.put(part); - part.put(PART_TIPOMOV, (int)tm); - -#ifndef __EXTRA__ TMask& cm = app().curr_mask(); const TCausale& causale = app().causale(); part.put(PART_NUMDOC, cm.get(F_NUMDOC)); @@ -1034,14 +1102,14 @@ int TGame_mask::nuova_riga(TPartita& partita, tipo_movimento tm) const part.put(PART_REG, cm.get(F_CODREG)); part.put(PART_PROTIVA, cm.get(F_PROTIVA)); } - - const char sezione = calcola_sezione(); +#endif + + const char sezione = calcola_sezione(tm); // Memorizza solo la sezione (importi nulli) part.put(PART_SEZ, sezione); part.put(PART_SEZABB, sezione); part.put(PART_SEZDIFCAM, sezione); -#endif return nriga; } @@ -1142,7 +1210,6 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) nm->set(P_ANNO, game.anno()); nm->set(P_NUMERO, game.numero()); const KEY k = nm->run(); - delete nm; if (k == K_ENTER) tm = (tipo_movimento)nm->get_int(P_NUOVO); @@ -1151,6 +1218,7 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) if (was == NULL) giochi.destroy(game); return FALSE; } + delete nm; #else tm = (tipo_movimento)app().causale().tipomov(); #endif @@ -1205,36 +1273,10 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) if (cambiato) { - TToken_string& cur_game = gm.partite().row(gm._riga_partite); - const int cur_year = cur_game.get_int(0); - const char* cur_num = cur_game.get(); - const bool on_sheet = game.anno() == cur_year && game.numero() == cur_num; - TSheet_field& ss = gm.scadenze(); const int rs = ss.selected(); // Memorizza la riga corrente - - if (game.ok()) - { - if (on_sheet) - { - gm.update_partita(game, gm._riga_partite); - const int rp = gm._riga_partite; - gm._riga_partite = -1; // Forza aggiornamento sheet - partite_notify(gm.partite(), rp, K_TAB); - } - } - else - { - // Se la partita e' presente anche su file non posso cancellarla: - // altrimenti non verra' rimossa alla registrazione! - if (!game.is_on_file()) - giochi.destroy(game); - if (on_sheet) - gm.fill_partite(); - } - if (rs < ss.items()) - ss.select(rs); // Riporta la selezione sulla riga corrente - + gm.fill_partite(); + ss.select(rs); // Riporta la selezione sulla riga corrente gm._changed = TRUE; } } @@ -1248,8 +1290,13 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k) TGame_mask& gm = (TGame_mask&)f.mask(); int anno; TString numero; - - TMask* new_game = new TNew_mask(gm.conto().tipo(), TRUE, TRUE); + +#ifdef __EXTRA__ + const bool allow_fatt = TRUE; +#else + const bool allow_fatt = FALSE; +#endif + TMask* new_game = new TNew_mask(gm.conto().tipo(), allow_fatt, TRUE); tipo_movimento tm; @@ -1265,24 +1312,21 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k) #endif k = new_game->run(); + tm = (tipo_movimento)new_game->get_int(P_NUOVO); anno = new_game->get_int(P_ANNO); numero = new_game->get(P_NUMERO); - - tm = (tipo_movimento)new_game->get_int(P_NUOVO); + // Distruzione maschera di richiesta delete new_game; new_game = NULL; if (k == K_ENTER) - { + { + // Creazione nuova partita TPartita& game = app().partite().partita(gm.conto(), anno, numero); - if (tm != tm_fattura) + // N.B. Le fatture non possone essere editate in modo contabile + if (tm != tm_fattura) { -#ifndef __EXTRA__ - if (game.ok()) - return error_box("La partita %d '%s' esiste gia'.", anno, (const char*)game.numero()); -#endif - const int nriga = TPartita::UNASSIGNED; const int nrata = TPartita::UNASSIGNED; const int nrigp = gm.nuovo_pagamento(game, nriga, nrata, tm); @@ -1516,6 +1560,11 @@ void TGame_mask::fill_partite() if (u) update_partita(*gioco, -1); } + else + { // Se la partita e' vuota ... + if (!gioco->is_on_file()) // ... e non esiste su file + giochi.destroy(*gioco); // posso eliminarla tranquillamente + } } TLocalisamfile partita(LF_PARTITE); @@ -1574,7 +1623,12 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co TRectype oldpag = p.pagamento(nriga, nrata, nrigp); TRiga_partite& somma = p.riga(nrigp); - TPay_mask* pm = new TPay_mask(*this); // We must create masks on the heap + const bool nuovo = oldpag.get(PAGSCA_ACCSAL) != "S" && + oldpag.get_real(PAGSCA_IMPORTO).is_zero() && + oldpag.get_real(PAGSCA_RITENUTE).is_zero(); + + // We must create masks on the heap + TPay_mask* pm = new TPay_mask(*this, nuovo ? MODE_INS : MODE_MOD); TPay_mask& m = *pm; if (nriga == TPartita::UNASSIGNED) @@ -1590,10 +1644,6 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co m.set_pag(oldpag, scaden, _residuo); } - const bool nuovo = oldpag.get(PAGSCA_ACCSAL) != "S" && - oldpag.get_real(PAGSCA_IMPORTO).is_zero() && - oldpag.get_real(PAGSCA_RITENUTE).is_zero(); - KEY key = m.run(); if (key == K_ESC && nuovo) @@ -1612,15 +1662,12 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co } else { - m.get_pag(newpag); - somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune alla riga) - somma.put(PART_DATAPAG, m.get(S_DATAPAG)); // Aggiorna data pagamento (comune alla riga) - somma.put(PART_TIPOPAG, m.get(S_TIPOPAG)); // Aggiorna tipo pagamento (comune alla riga) + m.get_pag(newpag, somma); } - TValuta val; + const TValuta val(somma); #ifdef __EXTRA__ - val.get(m, S_VALUTA, S_DATACAMBIO, S_CAMBIO); +// val.get(m, E_VALUTA, E_DATACAMBIO, E_CAMBIO); p.modifica_pagamento(newpag, val, TRUE); #else if (somma.is_nota_credito()) @@ -1643,13 +1690,17 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co bool TPrimanota_application::edit_partite(const TMask& m, int riga) { - const char tipo = m.get(103)[0]; - const int gruppo = m.get_int(104); - const int conto = m.get_int(105); - const long sottoconto = m.get_int(106); + const char tipo = m.get(CG_TIPO)[0]; + const int gruppo = m.get_int(CG_GRUPPO); + const int conto = m.get_int(CG_CONTO); + const long sottoconto = m.get_int(CG_SOTTOCONTO); const TBill b(gruppo, conto, sottoconto, tipo); // Legge il conto della riga selezionata if (!b.ok()) return FALSE; // Esci se il conto della riga cliente non e' valido + + const char rt = m.get(CG_ROWTYPE)[0]; + if (rt == 'T' && tipo <= ' ') + return FALSE; TMovimentoPN* pn = (TMovimentoPN*)get_relation(); curr_mask().autosave(pn); // Aggiorna i dati della testata sulle partite diff --git a/cg/saldacon.cpp b/cg/saldacon.cpp index 91d4ef957..668d45ad3 100755 --- a/cg/saldacon.cpp +++ b/cg/saldacon.cpp @@ -640,8 +640,11 @@ int TRiga_partite::ultima_ratapagata() const // Certified 100% tipo_movimento TRiga_partite::tipo() const { - const tipo_movimento tm = (tipo_movimento)get_int(PART_TIPOMOV); - CHECKD(tm != tm_nessuno, "Riga partite con un tipo losco ", tm); + const tipo_movimento tm = (tipo_movimento)(get_char(PART_TIPOMOV)-'0'); +#ifdef DBG + if (tm == tm_nessuno && get_int(PART_NRIGA) != TPartita::UNASSIGNED) + fatal_box("Riga partite con un tipo losco."); +#endif return tm; } @@ -763,21 +766,26 @@ TImporto TRiga_partite::importo(bool valuta, int mode) const i.set(sezione(), get_real(field)); } - if (!is_fattura()) - { - TImporto abbuoni(get_char(PART_SEZABB), get_real(PART_ABBUONI)); - if (valuta) + if (!is_fattura() && (mode & 0x6)) // Esistono abbuoni o differenze cambio? + { + if (valuta) // Desidero gli abbuoni in valuta { - i += abbuoni; + if (mode & 0x2) + { + TImporto abbuoni(get_char(PART_SEZABB), get_real(PART_ABBUONI)); + i += abbuoni; + } + // In valuta ignoro completamente le differenze cambio } - else + else // Desidero gli abbuoni in lire { if (in_lire && (mode & 0x8)) i.valore() += get_real(PART_RITENUTE); - if ((mode & 0x2) && !abbuoni.is_zero()) - { - if (!in_lire) + if (mode & 0x2) + { + TImporto abbuoni(get_char(PART_SEZABB), get_real(PART_ABBUONI)); + if (!in_lire) // Converto in lire gli abbuoni che sono memorizzati in valuta { const real cambio(get(PART_CAMBIO)); abbuoni.valore() *= cambio; @@ -786,7 +794,7 @@ TImporto TRiga_partite::importo(bool valuta, int mode) const i += abbuoni; } - if (!in_lire && (mode & 0x4)) + if (!in_lire && (mode & 0x4)) // Se ci sono e desidero le differenze cambio { const TImporto diffcam(get_char(PART_SEZDIFCAM), get_real(PART_DIFFCAM)); i += diffcam; @@ -1727,6 +1735,15 @@ TPartita& TPartite_array::partita(const TRectype& r) return *game; } +bool TPartite_array::insert(TPartita* p) +{ + const TString& k = key(p->conto(), p->anno(), p->numero()); + TPartita* old = (TPartita*)objptr(k); + if (old != NULL) remove(k); + add(k, p); + return old != NULL; +} + bool TPartite_array::destroy(const TBill& clifo, int anno, const char* num) { const TString& k = key(clifo, anno, num); diff --git a/cg/saldacon.h b/cg/saldacon.h index ffcac091d..da83992c1 100755 --- a/cg/saldacon.h +++ b/cg/saldacon.h @@ -336,6 +336,8 @@ public: TPartita* exist(const TRectype& part) const { return ((TPartite_array*)this)->find(part, FALSE); } + bool insert(TPartita* p); + bool destroy(const TBill& clifo, int anno, const char* num); bool destroy(TPartita& game);