From 13913bf1861e9d0b018f1c0e43bd9ea4e6b046a5 Mon Sep 17 00:00:00 2001 From: guy Date: Thu, 23 Nov 1995 14:20:03 +0000 Subject: [PATCH] Gestione valuta e ritenute nel saldaconto git-svn-id: svn://10.65.10.50/trunk@2200 c028cbd2-c16b-5b4b-a496-9718f37d4682 --- cg/cg2100.cpp | 127 ++++++++++++++++++++++++---------------- cg/cg2100.h | 10 ++-- cg/cg2100b.uml | 32 +++++----- cg/cg2100c.uml | 34 +++++------ cg/cg2100p.h | 9 +++ cg/cg2100p.uml | 14 ++--- cg/cg2100s.uml | 37 +++++++++++- cg/cg2102.cpp | 91 +++++++++++++++-------------- cg/cg2102.h | 10 ++-- cg/cg2103.cpp | 2 +- cg/cg2104.cpp | 88 ++++++++++++++++++---------- cg/cg2105.cpp | 151 +++++++++++++++++++++++++++++++----------------- cg/cg21sld.uml | 9 +-- cg/saldacon.cpp | 68 +++++++++++++++------- cg/saldacon.h | 8 ++- 15 files changed, 429 insertions(+), 261 deletions(-) diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index a728193ca..3e0ce5e82 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -22,11 +22,24 @@ TPrimanota_application::TPrimanota_application() } TMask* TPrimanota_application::load_mask(int n) -{ - if (n == 2 && _msk[0] != NULL) - { - delete _msk[0]; - _msk[0] = NULL; +{ + int max_pages = 2; // Numero massimo di pagine della maschera + + if (n == 2) + { + if (is_fattura()) + max_pages = 3; + if (_msk[2] != NULL) + { + // Controlla se esiste pagina 3 + const int pages = (_msk[2]->id2pos(FS_RATESHEET) > 0) ? 3 : 2; + // Se i numeri di pagine non coincidono distruggi la maschera + if (pages != max_pages) + { + delete _msk[2]; + _msk[2] = NULL; + } + } } if (_msk[n] != NULL) @@ -34,7 +47,7 @@ TMask* TPrimanota_application::load_mask(int n) if (n == 1 || n == 2) { - for (int i = 3; i > 0; i--) + for (int i = 3; i >= 0; i--) { if (_msk[i] != NULL) { @@ -45,16 +58,16 @@ TMask* TPrimanota_application::load_mask(int n) } TFilename name("cg2100"); name << char(n == 3 ? 'o' : 'a'+n); - TMask* m = new TMask(name); + TMask* m = new TMask(name, 0, max_pages); switch (n) { case 0: if (m) { - m->set_handler(F_NUMREG, num_handler); - m->set_handler(F_CODCAUS, caus_query_handler); - m->set_handler(F_DATAREG, datareg_handler); + m->set_handler(F_NUMREG, num_handler); + m->set_handler(F_CODCAUS, caus_query_handler); + m->set_handler(F_DATAREG, datareg_handler); m->set_handler(F_DATACOMP, datacomp_handler); TConfig c(CONFIG_STUDIO, "cg"); @@ -85,7 +98,7 @@ TMask* TPrimanota_application::load_mask(int n) m->set_handler(F_SOLAIVA, solaiva_handler); m->set_handler(F_SHEETIVA, iva_handler); m->set_handler(F_CODPAG, codpag_handler); - m->set_handler(S_CAMBIO, cambio_handler); + m->set_handler(SK_CAMBIO, cambio_handler); TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA); is.set_notify(iva_notify); @@ -98,16 +111,19 @@ TMask* TPrimanota_application::load_mask(int n) ism.set_handler(209, sheet_clifo_handler); ism.set_handler(309, sheet_clifo_handler); - // add saldaconto - TSheet_field& ps = (TSheet_field&)m->field(FS_RATESHEET); - ps.set_notify(pag_notify); - m->set_handler(F_NUMRIF, numrif_handler); - m->set_handler(FS_RATESHEET, pag_sheet_handler); - m->set_handler(FS_RESET, reset_handler); - m->set_handler(FS_NRATE, nrate_handler); - m->set_handler(FS_RECALC, recalc_handler); - m->set_handler(FS_NSCAB, codcab_handler); - m->set_handler(FS_VSCAB, codcab_handler); + // Se esiste lo sheet delle rate + if (is_fattura()) + { + TSheet_field& ps = (TSheet_field&)m->field(FS_RATESHEET); + ps.set_notify(pag_notify); + m->set_handler(FS_RATESHEET, pag_sheet_handler); + m->set_handler(F_NUMRIF, numrif_handler); + m->set_handler(FS_RESET, reset_handler); + m->set_handler(FS_NRATE, nrate_handler); + m->set_handler(FS_RECALC, recalc_handler); + m->set_handler(FS_NSCAB, codcab_handler); + m->set_handler(FS_VSCAB, codcab_handler); + } } case 1: if (m) @@ -118,7 +134,7 @@ TMask* TPrimanota_application::load_mask(int n) m->set_handler(F_DESCR, descr_handler); m->set_handler(F_CODCAUS, caus_modify_handler); m->set_handler(F_TOTALE, totdoc_handler); - m->set_handler(S_TOTDOCVAL, totdocval_handler); + m->set_handler(SK_TOTDOCVAL, totdocval_handler); m->set_handler(F_SHEETCG, cg_handler); TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG); @@ -225,16 +241,19 @@ bool TPrimanota_application::read_caus(const char* cod, int year) nob = _is_saldaconto | causale().num_doc(); iva = causale().iva(); } - - TMask* m = _msk[iva == nessuna_iva ? 1 : 2]; - if (m == NULL) return TRUE; + TMask* m = _msk[iva == nessuna_iva ? 1 : 2]; + + // Se sono chiamato dai campi di query ho belle che finito + if (_mode == MODE_QUERY || m == NULL) + return TRUE; + const bool ins = m->insert_mode(); m->efield(F_NUMDOC).check_type(nob ? CHECK_REQUIRED : CHECK_NORMAL); // Num. doc. obbligatorio m->efield(F_DATADOC).check_type(dob ? CHECK_REQUIRED : CHECK_NORMAL); // Data doc. obbligatoria - const bool nota_credito = _is_saldaconto && causale().tipomov() == 2; + const bool nota_credito = is_nota_credito(); const bool show_games = is_pagamento() || nota_credito; TMask& cgm = cgs().sheet_mask(); cgm.set_handler(100, show_games ? showpartite_handler : NULL); // bottoncino riga @@ -242,14 +261,13 @@ bool TPrimanota_application::read_caus(const char* cod, int year) if (iva == nessuna_iva) { m->enable(F_PROVVISORIO, !_is_saldaconto); // Il saldaconto vieta i movimenti provvisori - m->show(S_TIPORIGA, is_pagamento()); + m->show(SK_TIPORIGA, is_pagamento()); } else { m->efield(F_CODPAG).check_type(_is_saldaconto ? CHECK_REQUIRED : CHECK_NORMAL); m->efield(F_CODPAG).enable(!nota_credito); - m->enable_page(2, _is_saldaconto && !nota_credito); m->show(F_ANNORIF, _is_saldaconto); // Mostra/nasconde anno e riferimento partita m->show(F_NUMRIF, _is_saldaconto); @@ -374,9 +392,9 @@ TMask* TPrimanota_application::get_mask(int mode) switch (mode) { case MODE_INS: - annoes = _msk[0]->get_int(F_ANNOES); + annoes = _msk[0]->get_int(F_ANNOES); annoiva = _msk[0]->get_int(F_ANNOIVA); - caus = _msk[0]->get(F_CODCAUS); + caus = _msk[0]->get(F_CODCAUS); break; case MODE_MOD: annoes = _rel->lfile().get_int("ANNOES"); @@ -390,10 +408,11 @@ TMask* TPrimanota_application::get_mask(int mode) if (giornale().year() != annoes) giornale().read(annoes); - if (caus != causale().codice() || causale().reg().year() != annoiva) - causale().read(caus, annoiva); - _iva = causale().iva(); - + const TCausale& c = causale(); + if (caus != c.codice() || (c.iva() != nessuna_iva && c.reg().year() != annoiva)) + read_caus(caus, annoiva); + + _iva = c.iva(); return load_mask(_iva == nessuna_iva ? 1 : 2); } @@ -457,17 +476,20 @@ void TPrimanota_application::init_mask(TMask& m) m.show(F_CODIVA, m.mode() == MODE_INS); // Codice IVA standard - const TPartita* game = partite().first(); - const bool scad_free = game == NULL || !game->esistono_abbuoni_diffcam(m.get_long(F_NUMREG)); - - m.enable(DLG_DELREC, scad_free); // Disabilita tasto cancella - m.enable(-1, scad_free); // Disabilita cliente - m.enable(-2, scad_free); - - m.enable(F_CODPAG, scad_free); // Disabilita codice pagamento - m.enable(FS_RESET, scad_free); // Disabilita tasto di reset - if (!scad_free) m.set(FS_RECALC, "", TRUE); - m.enable(FS_RECALC, scad_free); // Disabilita ricalcolo automatico + if (pagamento() != NULL) + { + const TPartita* game = partite().first(); + const bool scad_free = game == NULL || !game->esistono_abbuoni_diffcam(m.get_long(F_NUMREG)); + + m.enable(DLG_DELREC, scad_free); // Disabilita tasto cancella + m.enable(-1, scad_free); // Disabilita cliente + m.enable(-2, scad_free); + + m.enable(F_CODPAG, scad_free); // Disabilita codice pagamento + m.enable(FS_RESET, scad_free); // Disabilita tasto di reset + if (!scad_free) m.set(FS_RECALC, "", TRUE); + m.enable(FS_RECALC, scad_free); // Disabilita ricalcolo automatico + } } // Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_DATACAMBIO (GROUP 3) @@ -545,10 +567,13 @@ void TPrimanota_application::init_insert_mode(TMask& m) if (iva() != nessuna_iva) { occas_mask().reset(); - - const TString16 dt(m.get(F_DATAREG)); - set_pagamento(NULL,dt); - set_scadenze(m); + + if (is_fattura()) + { + const TString16 dt(m.get(F_DATAREG)); + set_pagamento(NULL,dt); + set_scadenze(m); + } } else partite().destroy(); @@ -955,7 +980,9 @@ bool TPrimanota_application::remove() if (_is_saldaconto) { if (iva() == nessuna_iva) - { + { + const long nreg = curr_mask().get_long(F_NUMREG); + partite().add_numreg(nreg); notify_cgline_deletion(-1); // Notify deletion of all cg lines partite().rewrite(); } diff --git a/cg/cg2100.h b/cg/cg2100.h index 69d09ad47..43b024fad 100755 --- a/cg/cg2100.h +++ b/cg/cg2100.h @@ -102,11 +102,11 @@ #define I_SOTTOCONTO4 234 // Saldaconto -#define S_TOTDOCVAL 301 -#define S_VALUTA 302 -#define S_DATACAMBIO 303 -#define S_CAMBIO 304 -#define S_TIPORIGA 305 +#define SK_TOTDOCVAL 301 +#define SK_VALUTA 302 +#define SK_DATACAMBIO 303 +#define SK_CAMBIO 304 +#define SK_TIPORIGA 305 // copie 2a pag. #define K_CODDITTA 401 diff --git a/cg/cg2100b.uml b/cg/cg2100b.uml index 0c9a3e140..f1eb56c3c 100755 --- a/cg/cg2100b.uml +++ b/cg/cg2100b.uml @@ -179,7 +179,7 @@ BEGIN GROUP 5 END -STRING S_VALUTA 3 +STRING SK_VALUTA 3 BEGIN PROMPT 2 11 "Valuta " HELP "Codice della valuta per movimento" @@ -187,42 +187,42 @@ BEGIN FLAGS "UZ" GROUP 3 5 USE %VAL - INPUT CODTAB S_VALUTA + INPUT CODTAB SK_VALUTA DISPLAY "Codice" CODTAB DISPLAY "Nome@50" S0 - OUTPUT S_VALUTA CODTAB + OUTPUT SK_VALUTA CODTAB CHECKTYPE NORMAL - MESSAGE EMPTY CLEAR,S_CAMBIO|CLEAR,S_TOTDOCVAL - MESSAGE ENABLE,S_CAMBIO|ENABLE,S_TOTDOCVAL + MESSAGE EMPTY CLEAR,SK_CAMBIO|CLEAR,SK_TOTDOCVAL + MESSAGE ENABLE,SK_CAMBIO|ENABLE,SK_TOTDOCVAL END -DATE S_DATACAMBIO +DATE SK_DATACAMBIO BEGIN PROMPT 22 11 "Data cambio " FIELD DATACAM FLAGS "R" USE CAM - INPUT CODTAB[1,3] S_VALUTA - INPUT CODTAB[4,11] S_DATACAMBIO + INPUT CODTAB[1,3] SK_VALUTA SELECT + INPUT CODTAB[4,11] SK_DATACAMBIO DISPLAY "Valuta" CODTAB[1,3] DISPLAY "Data@10" D0 DISPLAY "Cambio@18" R10 - OUTPUT S_VALUTA CODTAB[1,3] - OUTPUT S_DATACAMBIO D0 - OUTPUT S_CAMBIO R10 + OUTPUT SK_VALUTA CODTAB[1,3] + OUTPUT SK_DATACAMBIO D0 + OUTPUT SK_CAMBIO R10 GROUP 3 5 CHECKTYPE NORMAL END -NUMBER S_CAMBIO 15 5 +NUMBER SK_CAMBIO 15 5 BEGIN PROMPT 54 11 "Cambio " - HELP "Cambio della valuta" FIELD CAMBIO FLAGS "RU" GROUP 3 5 PICTURE ".5" CHECKTYPE REQUIRED + WARNING "E' stata specificata una valuta senza il cambio relativo" END NUMBER F_TOTALE 15 @@ -231,11 +231,11 @@ BEGIN PICTURE "." GROUP 5 FIELD TOTDOC - VALIDATE REQIF_FUNC 1 S_TOTDOCVAL + VALIDATE REQIF_FUNC 1 SK_TOTDOCVAL MESSAGE COPY,K_TOTALE END -NUMBER S_TOTDOCVAL 15 2 +NUMBER SK_TOTDOCVAL 15 2 BEGIN PROMPT 44 12 "Totale in valuta " HELP "" @@ -336,7 +336,7 @@ BEGIN GROUP 5 END -LIST S_TIPORIGA 1 13 +LIST SK_TIPORIGA 1 13 BEGIN PROMPT 60 7 "Riga " ITEM "K|Saldaconto" diff --git a/cg/cg2100c.uml b/cg/cg2100c.uml index e38d93e8e..15576dc3d 100755 --- a/cg/cg2100c.uml +++ b/cg/cg2100c.uml @@ -392,43 +392,42 @@ BEGIN FLAGS "H" END -STRING S_VALUTA 3 +STRING SK_VALUTA 3 BEGIN PROMPT 1 12 "Valuta " FIELD CODVAL FLAGS "UZ" GROUP 3 USE %VAL - INPUT CODTAB S_VALUTA + INPUT CODTAB SK_VALUTA DISPLAY "Codice" CODTAB DISPLAY "Nome@50" S0 - OUTPUT S_VALUTA CODTAB + OUTPUT SK_VALUTA CODTAB CHECKTYPE NORMAL WARNING "Codice valuta assente" - MESSAGE EMPTY CLEAR,S_CAMBIO|CLEAR,S_TOTDOCVAL|RESET,FS_VALUTA - MESSAGE ENABLE,S_CAMBIO|ENABLE,S_TOTDOCVAL|COPY,FS_VALUTA + MESSAGE EMPTY CLEAR,SK_CAMBIO|CLEAR,SK_TOTDOCVAL + MESSAGE ENABLE,SK_CAMBIO|ENABLE,SK_TOTDOCVAL END -DATE S_DATACAMBIO +DATE SK_DATACAMBIO BEGIN PROMPT 28 12 "Data cambio " FIELD DATACAM FLAGS "R" USE CAM - INPUT CODTAB[1,3] S_VALUTA SELECT - INPUT CODTAB[4,11] S_DATACAMBIO + INPUT CODTAB[1,3] SK_VALUTA SELECT + INPUT CODTAB[4,11] SK_DATACAMBIO DISPLAY "Valuta" CODTAB[1,3] DISPLAY "Data@10" D0 DISPLAY "Cambio@18" R10 - OUTPUT S_VALUTA CODTAB[1,3] - OUTPUT S_DATACAMBIO D0 - OUTPUT S_CAMBIO R10 + OUTPUT SK_VALUTA CODTAB[1,3] + OUTPUT SK_DATACAMBIO D0 + OUTPUT SK_CAMBIO R10 GROUP 3 CHECKTYPE NORMAL - MESSAGE COPY,FS_DATACAMBIO END -NUMBER S_CAMBIO 15 5 +NUMBER SK_CAMBIO 15 5 BEGIN PROMPT 55 12 "Cambio " FIELD CAMBIO @@ -436,7 +435,6 @@ BEGIN GROUP 3 PICTURE ".5" CHECKTYPE REQUIRED - MESSAGE COPY,FS_CAMBIO END NUMBER F_TOTALE 15 @@ -446,7 +444,7 @@ BEGIN PICTURE "." END -NUMBER S_TOTDOCVAL 15 2 +NUMBER SK_TOTDOCVAL 15 2 BEGIN PROMPT 35 13 "Tot. in valuta " FIELD TOTDOCVAL @@ -613,17 +611,15 @@ END NUMBER F_IMPONIBILI 15 BEGIN PROMPT 1 11 "Totale imponibili " - FLAGS "DGV" + FLAGS "DV" PICTURE "." - MESSAGE COPY,FS_IMPONIBILI END NUMBER F_IMPOSTE 15 BEGIN PROMPT 41 11 "Totale imposte " - FLAGS "DGV" + FLAGS "DV" PICTURE "." - MESSAGE COPY,FS_IMPOSTE END SPREADSHEET F_SHEETCG diff --git a/cg/cg2100p.h b/cg/cg2100p.h index fe02ff131..b4d73a18b 100755 --- a/cg/cg2100p.h +++ b/cg/cg2100p.h @@ -1,3 +1,6 @@ +#ifndef __CG2100P_H +#define __CG2100P_H + #define P_TIPOC 101 #define P_GRUPPO 102 #define P_CONTO 103 @@ -61,3 +64,9 @@ #define S_DESPAG 135 #define S_CODDESC 136 #define S_RESIDUOPAG 137 +#define S_VALUTA 138 +#define S_DATACAMBIO 139 +#define S_CAMBIO 140 + +#endif + diff --git a/cg/cg2100p.uml b/cg/cg2100p.uml index dd55e4c57..e8b882445 100755 --- a/cg/cg2100p.uml +++ b/cg/cg2100p.uml @@ -2,15 +2,15 @@ TOOLBAR "" 0 20 0 2 -BUTTON P_NUOVO 10 2 -BEGIN - PROMPT -12 -1 "~Nuovo" - PICTURE 105 -END - BUTTON DLG_OK 10 2 BEGIN - PROMPT -22 -1 "" + PROMPT -12 -1 "" +END + +BUTTON P_NUOVO 10 2 +BEGIN + PROMPT -22 -1 "~Nuovo" + PICTURE 105 END ENDPAGE diff --git a/cg/cg2100s.uml b/cg/cg2100s.uml index 74c82d953..3fba51f8b 100755 --- a/cg/cg2100s.uml +++ b/cg/cg2100s.uml @@ -152,7 +152,7 @@ BEGIN PROMPT 38 8 "Ritenute professionali " PICTURE "." FIELD RITENUTE - GROUP 2 + MESSAGE DIRTY,S_IMPORTO|K_TAB,S_IMPORTO END RADIOBUTTON S_SALDOACC 1 24 @@ -162,7 +162,6 @@ BEGIN ITEM "A|Acconto" ITEM "S|Saldo" FIELD ACCSAL - GROUP 2 END LIST S_TIPOPAG 2 35 @@ -190,6 +189,7 @@ END TEXT DLG_NULL BEGIN PROMPT 2 12 "@bContropartita" + GROUP 2 END LIST S_TIPO 1 12 @@ -251,6 +251,39 @@ BEGIN GROUP 2 END +STRING S_VALUTA 3 +BEGIN + PROMPT 2 12 "Valuta " + FLAGS "DHUZ" + GROUP 4 +END + +DATE S_DATACAMBIO +BEGIN + PROMPT 24 12 "Data cambio " + FLAGS "RH" + USE CAM + INPUT CODTAB[1,3] S_VALUTA SELECT + INPUT CODTAB[4,11] S_DATACAMBIO + DISPLAY "Valuta" CODTAB[1,3] + DISPLAY "Data@10" D0 + DISPLAY "Cambio@18" R10 + OUTPUT S_VALUTA CODTAB[1,3] + OUTPUT S_DATACAMBIO D0 + OUTPUT S_CAMBIO R10 + GROUP 4 + CHECKTYPE NORMAL +END + +NUMBER S_CAMBIO 15 5 +BEGIN + PROMPT 51 12 "Cambio " + FLAGS "HRU" + GROUP 4 + PICTURE ".5" + CHECKTYPE REQUIRED +END + STRING S_CODDESC 5 BEGIN PROMPT 2 14 "Descriz. agg. " diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 2376b4af8..059560e11 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -22,23 +22,11 @@ char TPrimanota_application::row_type(const TToken_string& s) // Determina il tipo IVA da causale+anno // Certified 100% -TipoIVA TPrimanota_application::cau2IVA(const char* causale, int annoiva) +TipoIVA TPrimanota_application::cau2IVA(const char* cod, int annoiva) { - TipoIVA i = nessuna_iva; - - if (*causale > ' ') - { - TCausale& c = app().causale(); - if (c.read(causale, annoiva)) - i = c.iva(); - else - { - error_box("Causale errata: '%s'", causale); - i = iva_errata; - } - } - - return i; + if (!read_caus(cod, annoiva)) + error_box("Causale errata: '%s'", cod); + return causale().iva(); } // Calcolo della percentuale di un dato codice IVA @@ -291,7 +279,8 @@ TImporto TPrimanota_application::real2imp(const real& r, char row_type) else { dare = causale().sezione_clifo() == 'D'; - if (row_type != 'T' && row_type != 'F') dare = !dare; + if (row_type != 'T' && row_type != 'F') + dare = !dare; } TImporto importo(dare ? 'D' : 'A', r); @@ -306,6 +295,12 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo) int first = 0, last = 0; switch(tipo) { + case 'T': // Totale documento + if (!causale().corrispettivi()) + { + cg.disable_cell(n, 5); + cg.disable_cell(n, 6); + } case 'A': // Abbuoni attivi case 'C': // Differenza cambio case 'D': // IVA Detraibile @@ -315,13 +310,7 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo) case 'P': // Abbuoni passsivi case 'R': // Ritenute professionali case 'S': // Ritenute Sociali - case 'T': // Totale documento last = 3; - if (!causale().corrispettivi()) - { - cg.disable_cell(n, 5); - cg.disable_cell(n, 6); - } break; case 'K': // Riga cliente/fornitore per saldaconto if (curr_mask().is_running() && n == cg.items()-1) // Sono in inserimento di una riga nuova @@ -762,7 +751,7 @@ bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k) case K_CTRL+K_INS: // Post inserimento if (app().is_pagamento()) { - const char tipo = cg.mask().get(S_TIPORIGA)[0]; + const char tipo = cg.mask().get(SK_TIPORIGA)[0]; if (tipo == 'K' || tipo == 'G') { const int k = tipo == 'K' ? 1 : 10; @@ -987,18 +976,24 @@ bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key) real TPrimanota_application::calcola_imp() const { TArray& rows = ivas().rows_array(); - const int max = rows.items(); real imponibili, imposte; - for (int r = 0; r < max; r++) + for (int r = rows.items()-1; r >= 0; r--) { TToken_string& row = (TToken_string&)rows[r]; imponibili += real(row.get(0)); imposte += real(row.get(3)); } - curr_mask().set(F_IMPONIBILI, imponibili.string(), TRUE); - curr_mask().set(F_IMPOSTE, imposte.string(), TRUE); + curr_mask().set(F_IMPONIBILI, imponibili); + curr_mask().set(F_IMPOSTE, imposte); + + // Se e' attiva la terza pagina allora riporta i totali in testata + if (is_fattura()) + { + curr_mask().set(FS_IMPONIBILI, imponibili); + curr_mask().set(FS_IMPOSTE, imposte); + } return imponibili+imposte; } @@ -1186,7 +1181,7 @@ else if (r == 0) // Se cambio la prima riga ... app().add_cgs_tot(m); // ... ricalcola conti - if (app().is_saldaconto() && m.insert_mode()) + if (app().is_fattura() && m.insert_mode()) app().set_scadenze(m); // Aggiorna rate } return TRUE; @@ -1333,7 +1328,7 @@ bool TPrimanota_application::num_handler(TMask_field& f, KEY key) } if (ok && mov.get_bool("INVIATO")) - { + { ok = yesno_box("Il movimento e' stato inviato ad un'altra contabilita':\n" "si desidera continuare ugualmente"); } @@ -1360,15 +1355,16 @@ bool TPrimanota_application::num_handler(TMask_field& f, KEY key) // Handler of the F_CODCAUS field on the query mask // Certified 99% bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) -{ - if (!f.mask().is_running()) return TRUE; +{ + const TMask& m = f.mask(); + if (!m.is_running()) return TRUE; if (f.to_check(key)) { - const int ann = f.mask().get_int(F_ANNOIVA); - const char* cau = f.get(); + const TString16 cau = f.get(); + const int ann = m.get_int(F_ANNOIVA); - const TipoIVA i = cau2IVA(cau, ann); // Cerca causale e suo tipo + const TipoIVA i = app().cau2IVA(cau, ann); // Cerca causale e suo tipo if (i != iva_errata) { const bool ok = suspended_handler(f, key); // Controlla sospensione @@ -1397,7 +1393,8 @@ bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key) if (!c.ok()) return FALSE; ok = app().causale().similar(c); - if (!ok) return FALSE; + if (!ok) + return FALSE; // L'errore viene gia' segnalato dalla similar if (key == K_TAB) { app().read_caus(cau, ann); @@ -1456,7 +1453,7 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) } if (m.query_mode()) - app().causale().read(m.get(F_CODCAUS), dr.year()); + app().read_caus(m.get(F_CODCAUS), dr.year()); TRegistro& reg = app().causale().reg(); const TString16 codreg(reg.name()); @@ -1727,11 +1724,11 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) if (app().is_saldaconto() && f.focusdirty()) { - if (m.field(S_VALUTA).active()) + if (m.field(SK_VALUTA).active()) { const TString& valuta = clifo.get(CLI_CODVAL); if (valuta.not_empty()) - m.set(S_VALUTA, valuta, TRUE); + m.set(SK_VALUTA, valuta, TRUE); } if (clifo.get(CLI_CODCAB).not_empty()) @@ -1856,10 +1853,10 @@ bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) app().calcola_saldo(); } - TMask_field& totval = m.field(S_TOTDOCVAL); + TMask_field& totval = m.field(SK_TOTDOCVAL); if (totval.active() && totval.get().empty()) { - const real cambio(m.get(S_CAMBIO)); + const real cambio(m.get(SK_CAMBIO)); if (!cambio.is_zero()) { real tot(f.get()); @@ -1881,7 +1878,7 @@ bool TPrimanota_application::totdocval_handler(TMask_field& f, KEY key) { TMask& m = f.mask(); real totval(f.get()); - real cambio(m.get(S_CAMBIO)); + real cambio(m.get(SK_CAMBIO)); real totale(m.get(F_TOTALE)); if (totale.is_zero()) { @@ -1893,9 +1890,17 @@ bool TPrimanota_application::totdocval_handler(TMask_field& f, KEY key) if (cambio.is_zero()) { totale /= totval; - m.set(S_CAMBIO, totale.string(), TRUE); + m.set(SK_CAMBIO, totale.string(), TRUE); } } + + TPagamento* pag = app().pagamento(); + if (pag != NULL) // Se e' una vera fattura + { + pag->set_total(totval, ZERO, ZERO); + pag->set_rate_auto(); + pag->set_sheet(app().pags()); + } } return TRUE; diff --git a/cg/cg2102.h b/cg/cg2102.h index 55abc0ad9..e7720ecf1 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -158,22 +158,24 @@ protected: char clifo() const { return iva() == iva_vendite ? 'C' : 'F'; } bool gestione_valuta() const { return _ges_val; } bool gestione_saldaconto() const { return _ges_sal; } - bool is_saldaconto() const { return _is_saldaconto; } - void set_saldaconto(bool b) { _is_saldaconto = b; } - bool is_pagamento() const { return is_saldaconto() && iva() == nessuna_iva; } bool npart_is_prot() { return _npart_is_prot; } + bool is_saldaconto() const { return _is_saldaconto; } + bool is_fattura() const { return gestione_saldaconto() && causale().tipomov() == 1; } + bool is_nota_credito() const { return gestione_saldaconto() && causale().tipomov() == 2; } + bool is_pagamento() const { return gestione_saldaconto() && causale().tipomov() >= 3; } + void fill_sheet(TMask& m) const; void init_mask(TMask& m); static TipoIVA reg2IVA(const char* registro, int anno); - static TipoIVA cau2IVA(const char* causale, int anno); static int type2pos(char tipo); static const real& cod2IVA(const TMask& m); static real scorpora(real& imponibile, const real& percentuale); static bool detraibile(TToken_string& row); static int bill2pos(const TBill& conto, char tipo); + TipoIVA cau2IVA(const char* causale, int anno); bool IVA2bill(const TCodiceIVA& iva, TBill& bill); int bill2contr(const TBill& c, char sezione) const; int bill_used(const TBill& conto) const; diff --git a/cg/cg2103.cpp b/cg/cg2103.cpp index d1f1fd9a2..56abdc4a8 100755 --- a/cg/cg2103.cpp +++ b/cg/cg2103.cpp @@ -268,7 +268,7 @@ bool TCausale::read(const char* cod, int year) { TLocalisamfile caus(LF_CAUSALI); - _rec = caus.curr(); _rec.zero(); // Delete header + _rec.zero(); // Delete header destroy(); // Delete all rows _iva = iva_errata; // Delete misc info _sezione_clifo = _sezione_ritsoc = ' '; diff --git a/cg/cg2104.cpp b/cg/cg2104.cpp index 1235d3044..cf690d61f 100755 --- a/cg/cg2104.cpp +++ b/cg/cg2104.cpp @@ -215,10 +215,17 @@ bool TPrimanota_application::cambio_handler(TMask_field& f, KEY key) { const real ex(f.get()); pag->set_cambio(ex); - - TSheet_field& ps = app().pags(); - pag->set_sheet(ps); - ps.force_update(); + + TMask& m = f.mask(); + if (m.insert_mode()) + { + pag->set_rate_auto(); + TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); + pag->set_sheet(ps); + app().pag_rows() = ps.rows_array(); + } + const TValuta val(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); + val.set(m, FS_VALUTA, FS_DATACAMBIO, FS_CAMBIO); } } return TRUE; @@ -226,11 +233,10 @@ bool TPrimanota_application::cambio_handler(TMask_field& f, KEY key) bool TPrimanota_application::reset_handler(TMask_field& f, KEY key) { - TMask& m = f.mask(); - - if (key == K_SPACE && m.is_running() && app().is_saldaconto()) - { - app().reset_pagamento(f.mask()); + if (key == K_SPACE) + { + TMask& m = f.mask(); + app().reset_pagamento(m); app().set_scadenze(m); } return TRUE; @@ -323,15 +329,16 @@ void TPrimanota_application::reset_pagamento(TMask& m) void TPrimanota_application::recalc_scadenze(const TDate& d) { - if (_pag == NULL) return; + CHECK(_pag != NULL, "Can't handle null pagament"); + _pag->set_inizio(d); - // ridefinisci lo sheet sulla base delle nuove rate - TSheet_field& ps = pags(); - TString_array& rws = pag_rows(); + // ridefinisci lo sheet sulla base delle nuove rate + TSheet_field& ps = pags(); + TString_array& rws = pag_rows(); - _pag->set_sheet(ps); - rws = ps.rows_array(); - ps.force_update(); + _pag->set_sheet(ps); + rws = ps.rows_array(); +// ps.force_update(); } void TPrimanota_application::set_pagamento(const char* c, const char* d) @@ -344,10 +351,10 @@ void TPrimanota_application::set_scadenze(TMask& m) { real imponibile, imposta; const real spese(0.0); - const real cambio(m.get(S_CAMBIO)); + const real cambio(m.get(SK_CAMBIO)); TPagamento& pag = *pagamento(); - if (cambio.is_zero()) + if (cambio <= 1.0) { imponibile = real(m.get(F_IMPONIBILI)); imposta = real(m.get(F_IMPOSTE)); @@ -355,23 +362,22 @@ void TPrimanota_application::set_scadenze(TMask& m) else { pag.set_cambio(cambio); - imponibile = real(m.get(S_TOTDOCVAL)); + imponibile = real(m.get(SK_TOTDOCVAL)); imposta = ZERO; } - pag.set_total(imponibile, imposta, spese); - pag.set_rate_auto(); - if (m.field(FS_RECALC).enabled()) { m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2"); m.set(FS_NAMEPAG, pag.name()); m.set(FS_TIPOPR, pag.desc_tpr()); m.set(FS_MCOMM, pag.mese_commerciale() ? "X" : ""); - m.set(FS_RECALC, m.edit_mode() ? "" : "X", TRUE); + m.set(FS_RECALC, m.insert_mode() ? "X" : "", TRUE); m.set(FS_NRATE, pag.n_rate()); } + pag.set_total(imponibile, imposta, spese); + pag.set_rate_auto(); TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET); pag.set_sheet(ps); // prepara lo sheet _pag_rows = ps.rows_array(); // copia sheet @@ -400,10 +406,10 @@ bool TPrimanota_application::read_scadenze(TMask& m) bool in_valuta = FALSE; if (cambio.sign() > 0) { - pag.set_cambio(cambio); - imponibile = real(m.get(S_TOTDOCVAL)); - imposta = ZERO; in_valuta = TRUE; + pag.set_cambio(cambio); + imponibile = real(m.get(SK_TOTDOCVAL)); + imposta = ZERO; } else { @@ -450,7 +456,7 @@ bool TPrimanota_application::read_scadenze(TMask& m) " all'ultima registrazione. Si desidera mantenere" " comunque la rateazione precedente"); // nel qual caso, of course, si disabilitano gli automatismi - if(!fromscratch) m.set(FS_RECALC, "", TRUE); + m.set(FS_RECALC, fromscratch ? "X" : "", TRUE); } } @@ -494,8 +500,8 @@ bool TPrimanota_application::read_scadenze(TMask& m) m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2"); m.set(FS_NAMEPAG, pag.name()); m.set(FS_TIPOPR, pag.desc_tpr()); - m.set(FS_MCOMM, pag.mese_commerciale() ? "X" : ""); - m.set(FS_RECALC, m.edit_mode() ? "" : "X", TRUE); + m.set(FS_MCOMM, pag.mese_commerciale() ? "X" : "", TRUE); + m.set(FS_RECALC, m.insert_mode() ? "X" : "", TRUE); m.set(FS_NRATE, pag.n_rate()); } //else } @@ -535,8 +541,8 @@ void TPrimanota_application::write_scadenze(const TMask& m) const TString desc(m.get(F_DESCR)); const long protiva = m.get_long(F_PROTIVA); const TString codcaus(causale().codice()); - const TString codval (m.get(S_VALUTA)); - const real cambio (m.get(S_CAMBIO)); + const TString codval (m.get(SK_VALUTA)); + const real cambio (m.get(SK_CAMBIO)); const TString agente (m.get(FS_AGENTE)); const char sezione = get_cgs_imp(0).sezione(); // Dare/Avere @@ -840,7 +846,7 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg for (int p = partita.last(); p > 0; p = partita.pred(p)) { TRiga_partite& part = partita.riga(p); - if (part.get_int(PART_TIPOMOV) == 1) + if (part.is_fattura()) { for (int r = part.rate(); r > 0; r--) { @@ -869,6 +875,24 @@ bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg part.put(PART_NUMRIG, numrig-1); } } + + TRecord_array& unas = partita.unassigned(); + for (int u = unas.last_row(); u > 0; u = unas.pred_row(u)) + { + const TRiga_partite& sum = partita.riga(u); + if (sum.get_long(PART_NREG) == nreg && + (numrig <= 0 || sum.get_int(PART_NUMRIG) == numrig)) + { + TRectype nul_pag(unas.row(u, FALSE)); + nul_pag.zero(PAGSCA_IMPORTO); + nul_pag.zero(PAGSCA_IMPORTOVAL); + nul_pag.zero(PAGSCA_RITENUTE); + nul_pag.put(PAGSCA_ACCSAL, 'A'); // Inutile, ma l'ho copiato da sopra + const TValuta val; // Non cambiare valuta + notify_edit_pagamento(partita, nul_pag, val, numrig); + found = TRUE; + } + } return found; } diff --git a/cg/cg2105.cpp b/cg/cg2105.cpp index 79a2eec51..b31b8c9b8 100755 --- a/cg/cg2105.cpp +++ b/cg/cg2105.cpp @@ -1,17 +1,12 @@ -#include -#include - #include // Serve per DLG_NEWREC -#ifndef __EXTRA__ - -#include "cg2102.h" // Applicazione di prima nota -#include "cg2100.h" // Campi maschere prima nota - -#endif - #include "cg2100p.h" // Campi maschere partite e pagamenti +#ifndef __EXTRA__ +#include "cg2100.h" // Campi maschere prima nota +#include "cg2102.h" // Applicazione di prima nota +#endif + #include // Archivio clienti/fornitori #include // Archivio movimenti di prima nota #include // Archivio pagamenti @@ -25,15 +20,14 @@ class TPay_mask : public TMask { real _da_pagare, _pagabile; - TValuta _valuta; protected: static bool importo_handler(TMask_field& f, KEY k); + static bool cambio_handler(TMask_field& f, KEY k); public: void set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, const TImporto& importo); void get_pag(TRectype& oldpag) const; - const TValuta& valuta() const { return _valuta; } TPay_mask(); virtual ~TPay_mask() {} @@ -63,9 +57,10 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, set(S_DATA_SCAD, scad.get(SCAD_DATASCAD)); // Data della scadenza set(S_SEZIONE_SCAD, scad.riga().sezione()); // Sezione della rata set(S_IMPORTO_SCAD, scad.get(SCAD_IMPORTO)); // Importo della rata - set(S_IMPORTOVAL_SCAD, scad.get(SCAD_IMPORTOVAL)); // Importo in valuta + set(S_IMPORTOVAL_SCAD, scad.get(SCAD_IMPORTOVAL)); // Importo in valuta const bool in_valuta = scad.in_valuta(); + _da_pagare = scad.residuo(in_valuta).valore(); // Calcola residuo in valuta TReal_field& res = (TReal_field&)field(S_RESIDUORATA); @@ -74,26 +69,30 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, set_handler(in_valuta ? S_IMPORTOVAL : S_IMPORTO, importo_handler); - // Ricorda l'importo da pagare - _da_pagare += oldpag.get_real(in_valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO); + real oldimp = oldpag.get_real(in_valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO); + if (!in_valuta) + oldimp += oldpag.get_real(PAGSCA_RITENUTE); - // Attiva campi relativi alla valuta - show(-3, in_valuta); + // Ricorda l'importo da pagare + _da_pagare += oldimp; + + TValuta val; val.get(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); - _valuta.get(sum); TReal_field& resp = (TReal_field&)field(S_RESIDUOPAG); resp.set_decimals(in_valuta ? 2 : 0); TImporto r(importo); r -= app().partite().importo_speso(numreg, numrig); if (in_valuta) - _pagabile = _valuta.lit2val(r.valore()); + _pagabile = val.lit2val(r.valore()); else _pagabile = r.valore(); resp.set(_pagabile.string()); - _pagabile += oldpag.get_real(in_valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO); + + _pagabile += oldimp; // Il flag di saldo/acconto e' attivo solo se non ci sono acconti bool sa = oldpag.get_int(PAGSCA_NRIGA) != TPartita::UNASSIGNED; @@ -107,16 +106,22 @@ void TPay_mask::set_pag(const TRectype& oldpag, const TRiga_scadenze& scad, { hide(S_RESIDUORATA); } - enable(S_SALDOACC, sa); - + enable(S_SALDOACC, sa); // Mostra saldo solo se non e' un acconto + + show(-3, in_valuta); // Attiva campi relativi alla valuta + #ifdef __EXTRA__ + set_handler(S_CAMBIO, cambio_handler); hide(S_RESIDUOPAG); - const bool disabilita = TRUE; + const bool mostra_conto = FALSE; + show(-4, in_valuta); // Attiva campi relativi al cambio #else - const bool disabilita = app().causale().tipomov() == 2; + const bool mostra_conto = !sum.is_nota_credito(); #endif - if (disabilita) - send_key(K_CTRL + K_SHIFT + 'c', -2); // Disabilita contropartita e ritenute + show(-2, mostra_conto); // mostra/nasconde conto contropartita + + 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 @@ -133,33 +138,57 @@ bool TPay_mask::importo_handler(TMask_field& f, KEY k) if (k == K_F8) { - const real& imp = fnc_min(m._da_pagare, m._pagabile); + real imp; + if (m.field(S_RESIDUORATA).shown() && m.field(S_RESIDUOPAG).shown()) + imp = fnc_min(m._da_pagare, m._pagabile); + else + imp = m.field(S_RESIDUORATA).shown() ? m._da_pagare : m._pagabile; + + if (m.field(S_RITENUTE).active()) + imp -= real(m.get(S_RITENUTE)); + f.set(imp.string()); k = K_TAB; } if (k == K_TAB && f.focusdirty()) { - const real i(f.get()); + real i(f.get()); + if (m.field(S_RITENUTE).active()) + i += real(m.get(S_RITENUTE)); + if (i >= m._da_pagare && m.field(S_SALDOACC).active()) m.set(S_SALDOACC, "S"); const real residuo(m._da_pagare - i); - m.set(S_RESIDUORATA, residuo.string()); + m.set(S_RESIDUORATA, residuo); const real residuopag(m._pagabile - i); - m.set(S_RESIDUOPAG, residuopag.string()); + m.set(S_RESIDUOPAG, residuopag); if (f.dlg() == S_IMPORTOVAL) - { - const real lit = m.valuta().val2lit(i); - m.set(S_IMPORTO, lit.string()); + { + TValuta val; val.get(m, S_VALUTA, S_DATACAMBIO, S_CAMBIO); + val.val2lit(i); + m.set(S_IMPORTO, i); } } return TRUE; } +bool TPay_mask::cambio_handler(TMask_field& f, KEY k) +{ + if (k == K_TAB && f.focusdirty()) + { + TMask_field& i = f.mask().field(S_IMPORTOVAL); + i.set_dirty(); + i.on_hit(); + } + return TRUE; +} + + /////////////////////////////////////////////////////////// // Maschera partite /////////////////////////////////////////////////////////// @@ -236,7 +265,7 @@ TGame_mask::TGame_mask(const TBill& bill, long numreg, int riga) TValuta val; #ifndef __EXTRA__ TMask& cm = app().curr_mask(); - val.get(cm, S_VALUTA, S_DATACAMBIO, S_CAMBIO); + val.get(cm, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); cerca_valuta(val); val.set(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO); #endif @@ -390,8 +419,8 @@ void TGame_mask::aggiorna_valuta(const TValuta& val) val.val2lit(imp); pag.put(PAGSCA_IMPORTO, imp); // Converte in lire l'importo in valuta #ifdef __EXTRA__ - game->modifica_pagamento(pag); -#else + game->modifica_pagamento(pag, val, TRUE); +#else app().notify_edit_pagamento(*game, pag, val); #endif } @@ -497,11 +526,19 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) row.add(scad.get(SCAD_DATASCAD)); row.add(sum.get(PART_DATADOC)); row.add(sum.get(PART_DESCR)); - add_importo(row, TImporto(sez, pag.get_real(PAGSCA_IMPORTO))); + + TImporto imp(sez, pag.get_real(PAGSCA_IMPORTO)); if (in_valuta) + { + add_importo(row, imp); add_importo(row, TImporto(sez, pag.get_real(PAGSCA_IMPORTOVAL)), 2); + } else + { + imp.valore() += pag.get_real(PAGSCA_RITENUTE); + add_importo(row, imp); row.add(""); + } row.add(sum.get(PART_NREG)); row.add(sum.get(PART_DATAREG)); row.add(sum.get(PART_NUMDOC)); @@ -572,6 +609,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) row.add(sum.get(PART_DATADOC)); row.add(sum.get(PART_DESCR)); TImporto i(sum.sezione(), pag.get_real(PAGSCA_IMPORTO)); + i.valore() += pag.get_real(PAGSCA_RITENUTE); i.normalize(); add_importo(row, i); tot_lit += i; @@ -641,10 +679,8 @@ int TGame_mask::nuova_riga(TPartita& partita) const part.put(PART_CONTOCL, conto().conto()); // Setta il cambio corrente - const real cambio(get(P_CAMBIO)); - part.put(PART_CAMBIO, cambio); - part.put(PART_CODVAL, get(P_VALUTA)); - part.put(PART_DATACAM, get(P_DATACAMBIO)); + TValuta valuta; valuta.get(*this, P_VALUTA, P_DATACAMBIO, P_CAMBIO); + valuta.put(part); #ifdef __EXTRA__ part.put(PART_TIPOMOV, _tipomov); @@ -658,11 +694,9 @@ int TGame_mask::nuova_riga(TPartita& partita) const if (_tipomov == 1) { part.put(PART_IMPORTO, _importo.valore()); - if (!cambio.is_zero()) + if (valuta.in_valuta()) { - real impval = _importo.valore(); - impval /= cambio; - impval.round(2); + const real impval = valuta.lit2val(_importo.valore()); part.put(PART_IMPORTOVAL, impval); } } @@ -711,10 +745,15 @@ int TGame_mask::nuova_riga(TPartita& partita) const int TGame_mask::nuovo_pagamento(TPartita& partita, int nriga, int rata) const { - const TBill& conto = partita.conto(); // Legge conto principale - #ifdef __EXTRA__ const int nrigp = nuova_riga(partita); + if (nriga > 0) + { + const TRiga_partite& fattura = partita.riga(nriga); + const TValuta val(fattura); + TRiga_partite& somma = partita.riga(nrigp); + val.put(somma); + } #else int nrigp = partita.mov2rig(_numreg, _numrig); // Cerca riga partita relativa alla riga rmov if (nrigp <= 0) // Devo creare una nuova riga di partita @@ -1134,9 +1173,9 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co { nriga = p.primo_pagamento(); TRiga_partite& riga = p.riga(nriga); - TRiga_scadenze& scaden = riga.new_row(); + const TRiga_scadenze& scaden = riga.new_row(); // Crea una rata falsa m.set_pag(oldpag, scaden, _importo); - riga.destroy_rows(); + riga.destroy_rows(); // Distrugge la rata falsa } else { @@ -1164,16 +1203,20 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co } else { - somma.put(PART_DESCR, m.get(S_DESCAGG)); // Aggiorna descrizione (comune ai pagamenti) + 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! + TValuta val; #ifdef __EXTRA__ - p.modifica_pagamento(newpag); -#else - app().notify_edit_pagamento(p, newpag, val); + val.get(m, S_VALUTA, S_DATACAMBIO, S_CAMBIO); + p.modifica_pagamento(newpag, val, TRUE); +#else + if (somma.is_nota_credito()) + p.modifica_pagamento(newpag, val, TRUE); + else + app().notify_edit_pagamento(p, newpag, val); #endif } diff --git a/cg/cg21sld.uml b/cg/cg21sld.uml index bf1798310..f3ee36afb 100755 --- a/cg/cg21sld.uml +++ b/cg/cg21sld.uml @@ -25,8 +25,8 @@ BEGIN PROMPT 31 1 "In valuta " PICTURE ".2" FLAGS "HU" - VALIDATE REQIF_FUNC 1 FS_VALUTA - WARNING "E' stata specificata una valuta ma non il relativo totale documento" + VALIDATE REQIF_FUNC 1 FS_IMPONIBILI + WARNING "Manca il totale documento in valuta" END NUMBER FS_SPESE 15 @@ -36,7 +36,6 @@ BEGIN FLAGS "DR" END - RADIOBUTTON FS_RDIFFER 31 BEGIN PROMPT 1 2 "Opzioni ricalcolo rate" @@ -76,6 +75,7 @@ BEGIN CHECKTYPE NORMAL WARNING "Codice valuta assente" MESSAGE EMPTY RESET,FS_CAMBIO + GROUP 3 END DATE FS_DATACAMBIO @@ -88,10 +88,10 @@ BEGIN DISPLAY "Valuta" CODTAB[1,3] DISPLAY "Data@10" D0 DISPLAY "Cambio@18" R10 -// OUTPUT FS_VALUTA CODTAB[1,3] OUTPUT FS_DATACAMBIO D0 OUTPUT FS_CAMBIO R10 CHECKTYPE NORMAL + GROUP 3 END NUMBER FS_CAMBIO 15 5 @@ -101,6 +101,7 @@ BEGIN PICTURE ".5" VALIDATE REQIF_FUNC 1 FS_VALUTA WARNING "E' stata specificata una valuta ma non il cambio relativo" + GROUP 3 END STRING FS_NAMEPAG 27 diff --git a/cg/saldacon.cpp b/cg/saldacon.cpp index 6714473fe..8f7310d9e 100755 --- a/cg/saldacon.cpp +++ b/cg/saldacon.cpp @@ -258,7 +258,7 @@ bool TRiga_scadenze::chiusa(bool update) const if (update) { TImporto imp(importo_da_pagare(TRUE)); - imp += importo_pagato(TRUE, 0x3); + imp += importo_pagato(TRUE); chiusa = imp.is_zero(); ((TRectype*)this)->put(SCAD_PAGATA, chiusa ? "X" : ""); } @@ -271,7 +271,7 @@ bool TRiga_scadenze::chiusa(bool update) const // Calcola il totale dei pagamenti (eventualmente in valuta) TImporto TRiga_scadenze::importo_pagato(bool val, int mode) const { - CHECKD(mode > 0 && mode < 8, "Bad importo_pagato mode ", mode); + CHECKD(mode > 0x0 && mode < 0x8, "Bad importo_pagato mode ", mode); const TPartita& game = partita(); const bool in_val = in_valuta(); const char* imp_field = (val && in_val) ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; @@ -283,13 +283,17 @@ TImporto TRiga_scadenze::importo_pagato(bool val, int mode) const const TRiga_partite& sum = game.riga(p); // Riga partite const char sez = sum.sezione(); - if (mode & 0x1) + if (mode & 0x1) + { totale += TImporto(sez, pag.get_real(imp_field)); + if (!in_val) + totale += TImporto(sez, pag.get_real(PAGSCA_RITENUTE)); + } if (mode & 0x2) // Voglio anche gli abbuoni { real abb(pag.get_real(PAGSCA_ABBUONI)); - if (!val && in_val) + if (in_val && !val) { abb *= sum.get_real(PART_CAMBIO); abb.round(); @@ -297,7 +301,7 @@ TImporto TRiga_scadenze::importo_pagato(bool val, int mode) const totale += TImporto(sez, abb); } - if (!val && (mode & 0x4)) // Voglio anche le differenze cambi + if (in_val && !val && (mode & 0x4)) // Voglio anche le differenze cambio { const TImporto diffcam(sez, pag.get_real(PAGSCA_DIFFCAM)); totale += diffcam; @@ -382,7 +386,7 @@ TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update) { diffcam = importo_da_pagare(FALSE); pag.zero(PAGSCA_DIFFCAM); - diffcam += importo_pagato(FALSE, 0x7); // Conta anche gli abbuoni e le altre diffcam + diffcam += importo_pagato(FALSE); // Conta anche gli abbuoni e le altre diffcam diffcam.swap_section(); diffcam.normalize(sez); pag.put(PAGSCA_DIFFCAM, diffcam.valore()); @@ -457,8 +461,9 @@ bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta& chiusa(TRUE); partita().chiusa(TRUE); - const bool empty = new_pag.get_char(PAGSCA_ACCSAL) != 'S' && - new_pag.get_real(PAGSCA_IMPORTO).is_zero(); + const bool empty = new_pag.get_char(PAGSCA_ACCSAL) != 'S' && + new_pag.get_real(PAGSCA_IMPORTO).is_zero() && + new_pag.get_real(PAGSCA_RITENUTE).is_zero(); if (empty) rows_array().destroy_row(nrigp); @@ -470,8 +475,10 @@ bool TRiga_scadenze::elimina_pagamento(int p) TRectype old_pag(row(p)); old_pag.put(PAGSCA_ACCSAL, "A"); old_pag.zero(PAGSCA_IMPORTO); - old_pag.zero(PAGSCA_IMPORTOVAL); - return partita().modifica_pagamento(old_pag); + old_pag.zero(PAGSCA_IMPORTOVAL); + old_pag.zero(PAGSCA_RITENUTE); + TValuta val; + return partita().modifica_pagamento(old_pag, val, TRUE); } /////////////////////////////////////////////////////////// @@ -534,6 +541,10 @@ bool TRiga_partite::is_fattura() const return get_int(PART_TIPOMOV) == 1; } +bool TRiga_partite::is_nota_credito() const +{ + return get_int(PART_TIPOMOV) == 2; +} int TRiga_partite::read(TBaseisamfile& f, word op) { @@ -944,14 +955,24 @@ TImporto TPartita::importo_speso(long nreg, int numrig) const { const TRiga_partite& part = riga(r); if (nreg == part.get_long(PART_NREG) && numrig == part.get_int(PART_NUMRIG)) - { + { + // Importo dei pagamenti imp += TImporto(part.sezione(), part.get_real(PART_IMPORTO)); - + + // Abbuoni (in valuta) TImporto abbuoni(part.get_char(PART_SEZABB), part.get_real(PART_ABBUONI)); const TValuta valuta(part); - if (!valuta.in_lire()) + + if (valuta.in_lire()) { - valuta.val2lit(abbuoni); + // Se in lire ci possono essere le ritenute + imp += TImporto(part.sezione(), part.get_real(PART_RITENUTE)); + } + else + { + // Se in valuta bisogna convertire in lire gli abbuoni ... + valuta.val2lit(abbuoni); + // ... e considerare le differenze cambio imp += TImporto(part.get_char(PART_SEZDIFCAM), part.get_real(PART_DIFFCAM)); } imp += abbuoni; @@ -1039,8 +1060,13 @@ void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImp for (int r = last(); r > 0; r = pred(r)) { const TRiga_partite& row = riga(r); - TImporto i(row.get_char(PART_SEZ), row.get_real(PART_IMPORTO)); - switch (row.get_int(PART_TIPOMOV)) + const int tipo = row.get_int(PART_TIPOMOV); + + TImporto i(row.sezione(), row.get_real(PART_IMPORTO)); + if (tipo >= 3) + i.valore() += row.get_real(PART_RITENUTE); + + switch (tipo) { case 1: case 2: @@ -1135,14 +1161,13 @@ bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta } -bool TPartita::modifica_pagamento(const TRectype& new_pag) +bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool update) { char old_ap, new_ap; TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam; - TValuta valuta; return modifica_pagamento(new_pag, valuta, old_ap, old_abbuono, old_diffcam, - new_ap, new_abbuono, new_diffcam, FALSE); + new_ap, new_abbuono, new_diffcam, update); } @@ -1265,8 +1290,9 @@ void TPartita::sposta_riga(int r, TPartita& part) if (knames.get_pos(fnam) < 0) npg.put(fnam, pag.get(fnam)); } - } - part.modifica_pagamento(npg); + } + const TValuta val; + part.modifica_pagamento(npg, val, FALSE); scd.elimina_pagamento(j); } } diff --git a/cg/saldacon.h b/cg/saldacon.h index a8a0d3e38..6143d9e41 100755 --- a/cg/saldacon.h +++ b/cg/saldacon.h @@ -97,6 +97,7 @@ public: TValuta(); TValuta(const char* cod, const TDate& dat, const real& cam); TValuta(const TRectype& rec) { get(rec); } + TValuta(const TMask& m, short v, short d, short c) { get(m, v, d, c); } virtual ~TValuta() {} }; @@ -133,9 +134,9 @@ public: TPartita& partita() const; TRiga_partite& riga() const { return *_riga; } // Riga partite - TImporto importo_pagato(bool val, int mode = 0x1) const; + TImporto importo_pagato(bool val, int mode = 0x7) const; TImporto importo_da_pagare(bool val) const; - TImporto residuo(bool val, int mode = 0x1) const; // Differenza delle due funzioni precedenti + TImporto residuo(bool val, int mode = 0x7) const; // Differenza delle due funzioni precedenti TRiga_scadenze(TRiga_partite* riga); TRiga_scadenze(const TRiga_scadenze& s); @@ -165,6 +166,7 @@ public: TRiga_scadenze& new_row(int r = 0); bool is_fattura() const; + bool is_nota_credito() const; int ultima_ratapagata() const; int ultimo_pagamento(int rata) const; int rata_con_abbuoni_diffcam() const; @@ -256,7 +258,7 @@ public: char& old_ap, TImporto& old_abb, TImporto& old_diffcam, char& new_ap, TImporto& new_abb, TImporto& new_diffcam, bool update); - bool modifica_pagamento(const TRectype& new_pag); + bool modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool update); static void carica_allineamento(); char allineamento_richiesto() const;