From 4dfa755e87d971fd98e757c7bc7c2350d421ad18 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 9 Nov 1995 08:05:53 +0000 Subject: [PATCH] Gestione allineamento numero partita git-svn-id: svn://10.65.10.50/trunk@2115 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg2100.cpp | 100 ++++++++++++++++++------------- cg/cg2102.cpp | 2 +- cg/cg2102.h | 1 + cg/cg2105.cpp | 79 ++++++++++++++----------- cg/cg21rata.uml | 1 + cg/saldacon.cpp | 152 +++++++++++++++++++++++++++++++++++++++++------- cg/saldacon.h | 10 ++-- 7 files changed, 242 insertions(+), 103 deletions(-) diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index 9e2be18d1..2793042df 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -410,9 +410,11 @@ void TPrimanota_application::on_config_change() TConfig cnf(CONFIG_DITTA); _ges_val = cnf.get_bool("GesVal"); _ges_sal = cnf.get_bool("GesSal"); + _npart_is_prot = cnf.get_bool("RifPro"); + _num_cli = cnf.get_bool("NrCliDx"); _num_for = cnf.get_bool("NrForDx"); - _npart_is_prot = cnf.get_bool("RifPro"); + TPartita::carica_allineamento(); } @@ -466,7 +468,7 @@ void TPrimanota_application::init_mask(TMask& m) } // Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_DATACAMBIO (GROUP 3) - const bool valuta = _ges_val && causale().valuta(); + const bool valuta = _ges_val && is_saldaconto() && causale().valuta(); m.show(-3, valuta); } @@ -1138,6 +1140,16 @@ void TPrimanota_application::genera_incasso(const char* causimm) } } +bool TPrimanota_application::is_percipient(long forn, char& tipper, long& codper) const +{ + TLocalisamfile fornitori(LF_CLIFO); + fornitori.put("TIPOCF", "F"); + fornitori.put("CODCF", forn); + fornitori.read(); + tipper = fornitori.get_char(CLI_TIPOAPER); + codper = fornitori.get_long(CLI_CODANAGPER); + return codper > 0; +} long TPrimanota_application::calcola_m770(int tipo_coll, real& spese, real& compenso, real& iva, real& ritfis) @@ -1176,34 +1188,36 @@ long TPrimanota_application::calcola_m770(int tipo_coll, real& spese, real& comp } } - if (tipo_coll == 3 || tipo_coll == 6) + if (tipo_coll == 3 || tipo_coll == 7) { - TBill zio; causale().bill(1, zio); TImporto imp; - TString_array& rcg = cgs().rows_array(); for (int i = 0; i < rcg.items(); i++) { TToken_string& row = rcg.row(i); imp = row; - if (tipo_coll == 3) - { - const char cf = row.get_char(2); - if (cf == 'F') + + const char cf = row.get_char(2); + if (cf == 'F') // Evviva, e' un fornitore! + { + const long cod = row.get_long(5); + char tipper; + long codper; + if (!is_percipient(cod, tipper, codper)) + continue; // Se non e' percipente ignoralo + + if (forn == 0 && tipo_coll == 3) { - if (forn == 0) - forn = row.get_long(5); - else - { - forn = 0; - compenso = ZERO; - break; - } - compenso = imp.valore(); + forn = cod; // E' il primo che trovo! } - } else - if (tipo_coll == 6) - compenso += imp.valore(); + else // Fine ricerca. + { + forn = 0; + compenso = ZERO; + break; + } + compenso = imp.valore(); + } } } @@ -1225,10 +1239,22 @@ long TPrimanota_application::calcola_m770(int tipo_coll, real& spese, real& comp } } + if (tipo_coll == 6) + { + TString_array& rcg = cgs().rows_array(); + TImporto imp; + + for (int i = 0; i < rcg.items(); i++) + { + TToken_string& row = rcg.row(i); + imp = row; + compenso += imp.valore(); + } + } + return forn; } - bool TPrimanota_application::link_m770() { const int m770 = causale().link_m770(); @@ -1244,32 +1270,22 @@ bool TPrimanota_application::link_m770() { if (m770 == 1 || m770 == 5) { - TLocalisamfile fornitori(LF_CLIFO); - fornitori.put("TIPOCF", "F"); - fornitori.put("CODCF", curr_mask().get(F_FORNITORE)); - fornitori.read(); - tipper = fornitori.get_char(CLI_TIPOAPER); - codper = fornitori.get_long(CLI_CODANAGPER); - if (codper > 0) + const long forn = curr_mask().get_long(F_FORNITORE); + if (is_percipient(forn, tipper, codper)) calcola_m770(tipo_coll = 1, spese, compenso, imposte, ritenute); } } - else + else // Movimento puramente contabile switch (m770) { case 1: - { - const long f = calcola_m770(tipo_coll = 3, spese, compenso, imposte, ritenute); - if (f != 0) - { - TLocalisamfile fornitori(LF_CLIFO); - fornitori.put("TIPOCF", "F"); - fornitori.put("CODCF", f); - fornitori.read(); - tipper = fornitori.get_char(CLI_TIPOAPER); - codper = fornitori.get_long(CLI_CODANAGPER); - } - else tipo_coll = 7; + { + tipo_coll = is_saldaconto() ? 7 : 3; + const long forn = calcola_m770(tipo_coll, spese, compenso, imposte, ritenute); + if (forn != 0) + is_percipient(forn, tipper, codper); + else + tipo_coll = 7; } break; case 2: diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index e537354dc..913ab5453 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -324,7 +324,7 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo) } break; case 'K': // Riga cliente/fornitore per saldaconto - if (n == cg.items()-1) + if (curr_mask().is_running() && n == cg.items()-1) // Sono in inserimento di una riga nuova break; first = 2; case 'I': diff --git a/cg/cg2102.h b/cg/cg2102.h index 648333a72..e75006c52 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -218,6 +218,7 @@ protected: bool notify_cgline_deletion(TPartita& partita, long nreg, int numrig); bool notify_cgline_deletion(int numrig); + bool is_percipient(long forn, char& tipper, long& codper) const; long calcola_m770(int tipo_coll, real& spese, real& compenso, real& iva, real& ritfis); bool link_m770(); diff --git a/cg/cg2105.cpp b/cg/cg2105.cpp index fdd3b37a3..6311210f9 100755 --- a/cg/cg2105.cpp +++ b/cg/cg2105.cpp @@ -245,6 +245,7 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga) set_handler(P_CAMBIO, cambio_handler); partite().set_notify(partite_notify); + scadenze().set_notify(scadenze_notify); scadenze().sheet_mask().set_handler(100, edit_scadenza_handler); } @@ -319,19 +320,21 @@ bool TGame_mask::cambio_handler(TMask_field& f, KEY k) // Metodi dei campi e della maschera principale /////////////////////////////////////////////////////////// +// Aggiorna il campo con il residuo da spendere sui pagamenti real TGame_mask::aggiorna_residuo() { #ifdef __EXTRA__ return ZERO; #else - _importo = app().get_cgs_imp(_numrig-1); + _importo = app().get_cgs_imp(_numrig-1); // Importo sulla riga contabile TImporto residuo(_importo); - residuo -= app().partite().importo_speso(_numreg, _numrig); - set(P_RESIDUO, residuo.valore().string()); + residuo -= app().partite().importo_speso(_numreg, _numrig); // Sottraggo importi spesi + set(P_RESIDUO, residuo.valore()); return residuo.valore(); #endif } +// Scandisce tutte le partite per cercare la prima del movimento corrente e la sua valuta bool TGame_mask::cerca_valuta(TValuta& val) const { bool found = FALSE; @@ -441,7 +444,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) const TRiga_partite& riga = game->riga(ri); const bool in_valuta = riga.in_valuta(); - if (riga.rate() != 0) + if (riga.rate() > 0) // Se ci sono rate stampa la riga con la fattura { riga_fattura.add(ri); riga_fattura.add(""); @@ -763,28 +766,37 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) const TString16 numero = gm.get(P_NUMERO); TPartita& game = app().partite().partita(bill, anno, numero); - - const int nrata = m.get_int(102); // Rata selezionata (puo' essere 0) - int nrigp = m.get_int(112); // Pagamento selezionato (puo' essere 0) + + long nreg = m.get_long(108); // Numero registrazione + const int nrata = m.get_int(102); // Rata selezionata (puo' essere 0) + int nrigp = m.get_int(112); // Pagamento selezionato (puo' essere 0) + if (nrata != 0 && nrigp == 0) + { nrigp = gm.nuovo_pagamento(game, nriga, nrata); + nreg = gm._numreg; + } if (nrigp > 0) // Si vuole editare un pagamento { - const bool dirty = gm.edit_pagamento(game, nriga, nrata, nrigp); - if (dirty) - { - gm.update_partita(game, gm._riga_partite); - partite_notify(gm.partite(), gm._riga_partite, K_TAB); - gm._changed = TRUE; - - if (!game.esiste(nriga, nrata, nrigp)) - m.stop_run(K_ESC); - } + if (nreg == gm._numreg) + { + const bool dirty = gm.edit_pagamento(game, nriga, nrata, nrigp); + if (dirty) + { + gm.update_partita(game, gm._riga_partite); + partite_notify(gm.partite(), gm._riga_partite, K_TAB); + gm._changed = TRUE; + + if (!game.esiste(nriga, nrata, nrigp)) + m.stop_run(K_ESC); + } + } + else + return f.error_box("Modificare il movimento %ld", nreg); } else { // Si vogliono editare le rate - const long nreg = m.get_long(108); #ifdef __EXTRA__ if (nreg > 0) { @@ -1030,7 +1042,7 @@ void TGame_mask::fill_partite(int annorif, const char* numrif) for (TPartita* gioco = app().partite().first(); gioco != NULL; gioco = app().partite().next()) { - const int added = update_partita(*gioco, -1); + const int added = update_partita(*gioco, -1); // Memorizza posizione di inserimento if (first_game < 0 && gioco->anno() == annorif && gioco->numero() == numrif) first_game = added; } @@ -1040,9 +1052,10 @@ void TGame_mask::fill_partite(int annorif, const char* numrif) if (conto().tipo() > ' ') // Ignora gruppo e conto dei clifo { partita.put(PART_TIPOCF, conto().tipo()); - partita.put(PART_SOTTOCONTO, conto().sottoconto()); + partita.put(PART_SOTTOCONTO, conto().codclifo()); } - else conto().put(partita.curr()); // Scrive completamente i conti normali + else + conto().put(partita.curr()); // Scrive completamente i conti normali const TRectype filter(partita.curr()); // Record campione @@ -1117,22 +1130,22 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co m.reset(S_IMPORTOVAL); // .. anche in valuta m.reset(S_RITENUTE); // Azzera ritenute } -else -{ - somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti) -} -TRectype newpag(oldpag); -m.get_pag(newpag); - -const TValuta val; // Non cambiare valuta! + else + { + somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti) + } + TRectype newpag(oldpag); + m.get_pag(newpag); + + const TValuta val; // Non cambiare valuta! #ifdef __EXTRA__ -p.modifica_pagamento(newpag); + p.modifica_pagamento(newpag); #else -app().notify_edit_pagamento(p, newpag, val); + app().notify_edit_pagamento(p, newpag, val); #endif -} + } -return key != K_ESC; + return key != K_ESC; } #ifndef __EXTRA__ diff --git a/cg/cg21rata.uml b/cg/cg21rata.uml index 1341a156f..670321af0 100755 --- a/cg/cg21rata.uml +++ b/cg/cg21rata.uml @@ -62,6 +62,7 @@ BEGIN DISPLAY "Classificazione" CODTAB[2,2] DISPLAY "Descrizione@50" S0 OUTPUT 106 CODTAB[2,2] + OUTPUT 107 S0 CHECKTYPE NORMAL END diff --git a/cg/saldacon.cpp b/cg/saldacon.cpp index f34563eef..ec4822fb7 100755 --- a/cg/saldacon.cpp +++ b/cg/saldacon.cpp @@ -1,3 +1,4 @@ +#include #include #include "saldacon.h" @@ -143,7 +144,6 @@ int TValuta::compare(const TSortable& s) const return c.sign(); } - void TValuta::get(const TRectype& rec) { _cod = rec.get("CODVAL"); @@ -600,17 +600,19 @@ int TRiga_partite::rata_con_abbuoni_diffcam() const // TPartita /////////////////////////////////////////////////////////// -char TPartita::_cli_align = 'L'; -char TPartita::_for_align = 'L'; +char TPartita::_cli_align = ' '; +char TPartita::_for_align = ' '; TPartita::TPartita(const TBill& clifo, int anno, const char* num) -: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP") +: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP"), + _align(' ') { read(clifo, anno, num); } TPartita::TPartita(const TRectype& r) -: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP") +: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP"), + _align(' ') { TBill clifo; clifo.get(r); if (clifo.gruppo() == 0) @@ -627,12 +629,12 @@ TPartita::TPartita(const TRectype& r) const char* TPartita::build_key(TString& key) const { if (_conto.tipo() > ' ') - key.format("%c%3d%3d%6ld%4d%s", _conto.tipo(), 0, 0, _conto.sottoconto(), - _anno, (const char*)_num); + key.format("%c%3d%3d%6ld%4d%*s", _conto.tipo(), 0, 0, _conto.sottoconto(), + _anno, NUMLEN, (const char*)_num); else - key.format("%c%3d%3d%6ld%4d%s", + key.format("%c%3d%3d%6ld%4d%*s", _conto.tipo(), _conto.gruppo(), _conto.conto(), _conto.sottoconto(), - _anno, (const char*)_num); + _anno, NUMLEN, (const char*)_num); return key; } @@ -644,30 +646,105 @@ int TPartita::compare(const TSortable& s) const return strcmp(key, par); } -void TPartita::modifica_allineamento(char ac, char af) +void TPartita::carica_allineamento() { - CHECK(ac == 'L' || ac == 'R', "Allineamento clienti errato"); - _cli_align = ac; - CHECK(af == 'L' || af == 'R', "Allineamento fornitori errato"); - _for_align = af; + TConfig cd(CONFIG_DITTA, "cg"); + _cli_align = cd.get_bool("NrCliDx") ? 'R' : 'L'; + _for_align = cd.get_bool("NrForDx") ? 'R' : 'L'; } +char TPartita::allineamento_richiesto() const +{ + char all; + if (_cli_align <= ' ' || _for_align <= ' ') + carica_allineamento(); + switch (conto().tipo()) + { + case 'C': all = _cli_align; break; + case 'F': all = _for_align; break; + default : all = ' '; break; + } + return all; +} + + // Ritorna l'allineamento corrente del numero partita // L = Sinistra, R = Destra, ' ' = indeterminato char TPartita::allineamento_corrente() const { - char all = numero()[0] == ' ' ? 'R' : 'L'; - if (all == 'L' && numero()[6] != ' ') + const TString& n = numero(); + + char all = n[0] == ' ' ? 'R' : 'L'; + if (all == 'L' && n.len() == NUMLEN && n[6] != ' ') all = ' '; return all; } +void TPartita::allinea(char all) +{ + if (all <= ' ') + all = allineamento_richiesto(); + + if (_num.len() < NUMLEN) + { + if (all == 'R') + _num.right_just(NUMLEN); + else + _num.trim(); + + if (ok()) + { + _part.renum_key(PART_NUMPART, _num); + _unassigned.renum_key(PAGSCA_NUMPART, _num); + } + } +} + + // Costruisce le righe della partita bool TPartita::read(const TBill& clifo, int year, const char* num) { _conto = clifo; _anno = year; _num = num; + + if (_conto.tipo() > ' ' && allineamento_corrente() > ' ') + { + // Prepara la chiave per verificare l'esistenza della partita specificata + TLocalisamfile part(LF_PARTITE); + part.zero(); + part.put(PART_TIPOCF, _conto.tipo()); + part.put(PART_SOTTOCONTO, _conto.codclifo()); + part.put(PART_ANNO, _anno); + part.put(PART_NUMPART, _num); + TRectype filter(part.curr()); + + + // Cerca la partita usando l'allineamento richiesto dai parametri ditta + if (part.read(_isgteq) == NOERR && part.curr() == filter) + { + // Memorizza l'allineamento utilizzato per la lettura + _align = allineamento_corrente(); + } + else + { + // Se non la trova inverte l'allineamento + if (allineamento_corrente() == 'R') + _num.trim(); + else + _num.right_just(NUMLEN); + + // Riprova a cercarla col nuovo allineamento + filter.put(PART_NUMPART, _num); + if (part.read(_isgteq) == NOERR && part.curr() == filter) + _align = allineamento_corrente(); // Esiste: memorizzo l'allineamento + else + allinea(); // Non esite: e' una nuova partita! + } + } + else + _num.trim(); + TRiga_partite* partita = new TRiga_partite(this); // Record campione della partita TString16 str; str << clifo.tipo(); @@ -702,21 +779,52 @@ bool TPartita::reread() bool TPartita::write(bool re) const { - if (conto().tipo() > ' ') + if (ok() && conto().tipo() > ' ') { for (int r = last(); r > 0; r = pred(r)) { TRiga_partite& row = riga(r); row.put(PART_GRUPPOCL, conto().gruppo()); row.put(PART_CONTOCL, conto().conto()); + } + + const char cur_align = allineamento_corrente(); + const char req_align = allineamento_richiesto(); + if (cur_align > ' ' && cur_align != req_align) + { + if (yesno_box("La partita %d '%s' non rispetta l'allineamento " + "specificato nei parametri ditta: si desidera correggerlo?", + anno(), (const char*)numero())) + { + // Riallinea tutti i numeri partita nelle righe. rate e pagamenti + ((TPartita*)this)->allinea(req_align); + } } } + int err = _part.write(re); if (err == NOERR) err = _unassigned.write(re); + + // Se l'allineamento e' cambiato cancello la vecchia partita + if (err == NOERR && allineamento_corrente() != allineamento_iniziale()) + { + // Costruisce il vecchio numero partita + TString16 num = numero(); + if (allineamento_iniziale() == 'R') + num.right_just(NUMLEN); + else + num.trim(); + + // Cancella vecchia partita + TPartita canc(conto(), anno(), num); + canc.remove(); + } + return err == NOERR; } +// Cancella tutta una partita bool TPartita::remove() { _part.destroy_rows(); @@ -1182,10 +1290,12 @@ void TPartita::scollega_pagamenti(int r, int s) const TString& TPartite_array::key(const TBill& clifo, int anno, const char* num) { if (clifo.tipo() > ' ') - _key.format("%c%3d%3d%6ld%4d%s", clifo.tipo(), 0, 0, clifo.sottoconto(), anno, num); + _key.format("%c%3d%3d%6ld%4d%*s", clifo.tipo(), 0, 0, clifo.sottoconto(), + anno, TPartita::NUMLEN, num); else - _key.format("%c%3d%3d%6ld%4d%s", - clifo.tipo(), clifo.gruppo(), clifo.conto(), clifo.sottoconto(), anno, num); + _key.format("%c%3d%3d%6ld%4d%*s", + clifo.tipo(), clifo.gruppo(), clifo.conto(), clifo.sottoconto(), + anno, TPartita::NUMLEN, num); return _key; } @@ -1208,7 +1318,7 @@ TPartita* TPartite_array::find(const TRectype& r, bool create) if (zio.gruppo() == 0) { zio.set(r.get_int(PART_GRUPPOCL), r.get_int(PART_CONTOCL), - zio.sottoconto(), zio.tipo()); + zio.codclifo(), zio.tipo()); } const int anno = r.get_int(PART_ANNO); const char* num = r.get_str(PART_NUMPART); diff --git a/cg/saldacon.h b/cg/saldacon.h index f4487fd12..38fb60263 100755 --- a/cg/saldacon.h +++ b/cg/saldacon.h @@ -198,7 +198,7 @@ public: // TObject virtual int compare(const TSortable& s) const; public: - enum { UNASSIGNED = 9999 }; + enum { NUMLEN = 7, UNASSIGNED = 9999 }; TRiga_partite& riga(int r) const { return (TRiga_partite&)_part.row(r); } TRiga_partite& new_row(int r = 0); @@ -250,13 +250,11 @@ public: bool update); bool modifica_pagamento(const TRectype& new_pag); - static void modifica_allineamento(char a_cli, char a_for); - static char allineamento_clienti() { return _cli_align; } - static char allineamento_fornitori() { return _for_align; } - - bool allinea(); + static void carica_allineamento(); char allineamento_iniziale() const { return _align; } char allineamento_corrente() const; + char allineamento_richiesto() const; + void allinea(char all = ' '); TPartita(const TBill& clifo, int anno, const char* num); TPartita(const TRectype& part);