From 7713a41a744a5a65fc6148cc2b195d37464e7b4b Mon Sep 17 00:00:00 2001 From: villa Date: Tue, 5 Mar 1996 11:18:15 +0000 Subject: [PATCH] Sistemata apertura esercizi Corrette quattro cagate che, come sempre, impediscono di compilare cg4400 git-svn-id: svn://10.65.10.50/trunk@2664 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg4400.cpp | 8 +- cg/cg4500.cpp | 203 +++++++++++++++++++++++++++++++++---------------- cg/cg4500a.uml | 6 +- 3 files changed, 144 insertions(+), 73 deletions(-) diff --git a/cg/cg4400.cpp b/cg/cg4400.cpp index 638138374..dedf2ee06 100755 --- a/cg/cg4400.cpp +++ b/cg/cg4400.cpp @@ -3658,8 +3658,8 @@ bool CG4400_application::stampa_riepilogo(int m) impos = pim.get_real("R12"); } TToken_string fatt_rit(pim.get("S1")); - impon += fatt_rit.get(0); - impos += fatt_rit.get(1); + impon += real(fatt_rit.get(0)); + impos += real(fatt_rit.get(1)); if (impon != ZERO || impos != ZERO || impol != ZERO) vect.add_riga(impon,impos,impol,ZERO,ZERO,ZERO,codiva); if (tipo == 2) //registro acquisti @@ -3704,8 +3704,8 @@ bool CG4400_application::stampa_riepilogo(int m) impos = pim.get_real("R12"); } TToken_string fatt_rit(pim.get("S1")); - impon += fatt_rit.get(0); - impos += fatt_rit.get(1); + impon += real(fatt_rit.get(0)); + impos += real(fatt_rit.get(1)); if (impon != ZERO || impos != ZERO || impol != ZERO) vect.add_riga(ZERO,ZERO,ZERO,impon,impos,impol,codiva); if (tipo == 2) diff --git a/cg/cg4500.cpp b/cg/cg4500.cpp index 0e142f35a..9042aa762 100755 --- a/cg/cg4500.cpp +++ b/cg/cg4500.cpp @@ -9,6 +9,8 @@ class TAp_eser : public TApplication TDate _dataini, _datafin, _datainp, _datafip; protected: + + bool check_esercizio(TString& cod, TDate s1, TDate f1); static bool mask_dataini (TMask_field&, KEY); static bool mask_newanno (TMask_field&, KEY); @@ -23,44 +25,43 @@ public: TAp_eser() {} }; -TDate InizioEsercizio(int anno) -{ - TTable TabEs ("ESC"); - TString codtab; - TDate inizio_es; +//TDate InizioEsercizio(int anno) +//{ +// TTable TabEs ("ESC"); +// TString codtab; +// TDate inizio_es; +// +// TabEs.zero(); +// codtab.format ("%04d", anno); +// TabEs.put ("CODTAB", codtab); +// TabEs.read(); +// if (TabEs.good()) +// inizio_es= TabEs.get_date ("D0"); +// +// return inizio_es; +//} - TabEs.zero(); - codtab.format ("%04d", anno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - inizio_es= TabEs.get_date ("D0"); - - return inizio_es; -} - -TDate FineEsercizio(int anno) -{ - TTable TabEs ("ESC"); - TString codtab; - TDate fine_es; - - TabEs.zero(); - codtab.format ("%04d", anno); - TabEs.put ("CODTAB", codtab); - TabEs.read(); - if (TabEs.good()) - fine_es= TabEs.get_date ("D1"); - - return fine_es; -} +//TDate FineEsercizio(int anno) +//{ +// TTable TabEs ("ESC"); +// TString codtab; +// TDate fine_es; +// +// TabEs.zero(); +// codtab.format ("%04d", anno); +// TabEs.put ("CODTAB", codtab); +// TabEs.read(); +// if (TabEs.good()) +// fine_es= TabEs.get_date ("D1"); +// +// return fine_es; +//} bool TAp_eser::mask_newanno (TMask_field& f, KEY k) { - TTable TabEs ("ESC"); + TTable TabEs("ESC"); TString codtab; - // if ( (k == K_TAB) && f.mask().is_running() ) if ( (k == K_ENTER) && f.to_check(k) ) { int newanno = f.mask().get_int(F_NUOVOANNO); @@ -71,15 +72,9 @@ bool TAp_eser::mask_newanno (TMask_field& f, KEY k) TabEs.read(); if ( TabEs.good() ) { - f.warning_box ("L'anno inserito e' gia' presente nella tabella degli esercizi!"); + f.warning_box ("Il codice inserito e' gia' presente nella tabella degli esercizi!"); return FALSE; } - - if (newanno != anno + 1) - { - f.warning_box ("L'anno del nuovo esercizio deve essere successivo all'anno esercizio precedente"); - return FALSE; - } } return TRUE; } @@ -90,13 +85,6 @@ bool TAp_eser::mask_dataini (TMask_field& f, KEY k) { TDate data(f.mask().get(F_DATAINI)); TDate fine(f.mask().get(F_DATAFINC)); - /* - if ( data.year() != FineEsercizio(anno).year() + 1 ) - { - warning_box ("L'anno del nuovo esercizio deve essere successivo a quello della fine dell'esercizio precedente"); - return FALSE; - } - */ if ( data <= fine ) { f.warning_box ("La data di inizio del nuovo esercizio deve essere superiore alla data di fine esercizio precedente"); @@ -133,15 +121,30 @@ bool TAp_eser::menu(MENU_TAG m) if (TabEs.last() != NOERR) return error_box("Non e' ancora stato aperto alcun esercizio!"); + TabEs.first(); + TRecnotype rn = TabEs.recno(); + int anno = TabEs.get_int ("CODTAB"); + TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso + TDate fine = TabEs.get_date("D1"); //data fine es. in corso + + // determina esercizio con data fine piu' alta + for ( ; !TabEs.eof(); TabEs.next()) + if (TabEs.get_date("D1") > fine) + { + rn = TabEs.recno(); + fine = TabEs.get_date("D1"); + } - int anno = TabEs.get_int ("CODTAB"); - TDate inizio = TabEs.get_date("D0"); //data inizio es. in corso - TDate fine = TabEs.get_date("D1"); //data fine es. in corso + TabEs.readat(rn); + // rilegge dati + anno = TabEs.get_int ("CODTAB"); + inizio = TabEs.get_date("D0"); //data inizio es. in corso + fine = TabEs.get_date("D1"); //data fine es. in corso msk.set(F_ANNO, anno); msk.set(F_DATAINIC, inizio.string()); msk.set(F_DATAFINC, fine.string()); - msk.set(F_NUOVOANNO, anno+1); +// msk.set(F_NUOVOANNO, anno+1); msk.set_handler (F_NUOVOANNO, mask_newanno); msk.set_handler (F_DATAINI, mask_dataini); @@ -220,25 +223,93 @@ bool TAp_eser::apertura_es() TabReg.write(nuovo); } } - /* - if (!ok) - { - error_box("Non esiste il registro libro giornale relativo all'es. precedente"); - return FALSE; - } - */ - //viene aggiornata la tabella degli esercizi - TabEs.zero(); - annonew = format ("%04d", _newanno); - TabEs.put ("CODTAB", annonew); - TabEs.put ("D0", _dataini); - TabEs.put ("D1", _datafin); - TabEs.write(); - - message_box("Apertura nuovo esercizio completata"); + // se tutto ok viene aggiornata la tabella degli esercizi + if (check_esercizio(annonew, _dataini, _datafin)) + { + TabEs.zero(); + annonew = format ("%04d", _newanno); + TabEs.put ("CODTAB", annonew); + TabEs.put ("D0", _dataini); + TabEs.put ("D1", _datafin); + TabEs.write(); + message_box("Apertura nuovo esercizio completata"); + } return TRUE; } +bool TAp_eser::check_esercizio(TString& cod, TDate s1, TDate f1) +{ + // ----------------------------------------------------------------------------------------- + // chiamata prima di registrare. Controlla: + // - se non ci sono altri esercizi, ok; + // - se ce ne sono altri: + // 1) controllo non sovrapposizione date + // 2) se ci sono es. con date inferiori, datainizio -1 deve essere = data fine altro es; + // 3) se ci sono es. con date superiori, datafine +1 deve essere = data inizio altro + // ---------------------------------------------------------------------------------------- + + byte err = 0x00; bool ret = TRUE; + TTable esc("ESC"); + + bool basta1 = FALSE, basta2 = FALSE; + + for (esc.first(); !esc.eof(); esc.next()) + { + if (esc.get("CODTAB") == cod) + continue; + + TDate s2 = esc.get_date("D0"); + TDate f2 = esc.get_date("D1"); + TDate s1d = s1; --s1d; + TDate s2d = s2; --s2d; + + // check sovrapposizione + if (s1 <= f2 && s2 <= f1) + err |= 0x01; + else + { + if (!basta1 && f1 < s2 && f1 != s2d) + err |= 0x02; + if (f1 < s2 && f1 == s2d) + { + err &= ~0x02; + basta1 = TRUE; + } + if (!basta2 && s1 > f2 && f2 != s1d) + err |= 0x04; + if (s1 > f2 && f2 == s1d) + { + err &= ~0x04; + basta2 = TRUE; + } + } + } + + if (err) + { + ret = FALSE; + TString errstr(120); + errstr << "Date esercizio errate: \n"; + // build error string + if (err & 0x01) + errstr << "\n - l'esercizio si sovrappone ad altro gia' esistente"; + if (err & 0x02) + errstr << "\n - l'esercizio non e' contiguo ad esercizi successivi"; + if (err & 0x04) + errstr << "\n - l'esercizio non e' contiguo ad esercizi precedenti"; + + if (!(err & 0x01)) + { + errstr << "\nSi desidera registrare ugualmente?"; + ret = yesno_box(errstr); + } + else error_box(errstr); + } + return ret; +} + + + int cg4500 (int argc, char* argv[]) { switch (*argv[2]) diff --git a/cg/cg4500a.uml b/cg/cg4500a.uml index 05dc4def3..ee56e4a4c 100755 --- a/cg/cg4500a.uml +++ b/cg/cg4500a.uml @@ -23,7 +23,7 @@ END NUMBER F_ANNO 4 BEGIN - PROMPT 1 3 "Anno esercizio prec. " + PROMPT 1 3 "Cod. esercizio prec. " FLAGS "DRZ" END @@ -41,8 +41,8 @@ END NUMBER F_NUOVOANNO 4 BEGIN - PROMPT 1 7 "Nuovo anno esercizio " - HELP "Anno di cui si vuole aprire un nuovo esercizio contabile" + PROMPT 1 7 "Nuovo codice esercizio " + HELP "Codice del nuovo esercizio contabile" FLAGS "RZ" CHECKTYPE REQUIRED END