diff --git a/cg/cg2100.cpp b/cg/cg2100.cpp index cbdb2d18b..b1db08409 100755 --- a/cg/cg2100.cpp +++ b/cg/cg2100.cpp @@ -29,76 +29,75 @@ TMask* TPrimanota_application::load_mask(int n) switch (n) { - case 0: + case 0: + { 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"); const bool dr = c.get_bool("PoCuDr"); // Scelta primo campo col focus m->first_focus(dr ? F_DATAREG : F_CODCAUS); - } - break; - case 1: - m->set_handler(F_VISVAL, visval_handler); - m->set_handler(F_DESCR, descr_handler); - break; - case 2: - m->set_handler(F_CODREG, reg_handler); - m->set_handler(F_CLIENTE, clifo_handler); - m->set_handler(F_FORNITORE, clifo_handler); - m->set_handler(F_TOTALE, totale_handler); - m->set_handler(F_RITFIS, ritfis_handler); - m->set_handler(F_RITSOC, ritsoc_handler); - m->set_handler(F_VISVAL, visval_handler); - m->set_handler(F_OCCASEDIT, occas_handler); - m->set_handler(F_SOLAIVA, solaiva_handler); - m->set_handler(F_SHEETIVA, iva_handler); - { - TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA); - is.set_notify(iva_notify); - TMask& ism = is.sheet_mask(); - ism.set_handler(101, imponibile_handler); - ism.set_handler(102, codiva_handler); - ism.set_handler(104, imposta_handler); - ism.set_handler(108, conto_handler); - ism.set_handler(109, suspended_handler); - ism.set_handler(209, suspended_handler); - ism.set_handler(309, suspended_handler); } - break; - case 3: - m->set_handler(O_CODICE, occas_code_handler); - break; - default: - CHECKD(0, "Che cavolo di maschera e' la ", n); - break; - } - if (n == 1 || n == 2) - { - m->set_handler(F_DATAREG, datareg_handler); - m->set_handler(F_DATACOMP, datacomp_handler); - m->set_handler(F_CODCAUS, caus_modify_handler); - m->set_handler(F_SHEETCG, cg_handler); - { - TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG); - cg.set_notify(cg_notify); - TMask& cgm = cg.sheet_mask(); - cgm.set_handler(101, dareavere_handler); - cgm.set_handler(102, dareavere_handler); - cgm.set_handler(105, suspended_handler); - cgm.set_handler(106, suspended_handler); - cgm.set_handler(206, suspended_handler); - cgm.set_handler(306, suspended_handler); - cgm.set_handler(112, suspended_handler); - cgm.set_handler(113, suspended_handler); - cgm.set_handler(213, suspended_handler); - cgm.set_handler(313, suspended_handler); - } - } - - return _msk[n] = m; + break; + case 1: + m->set_handler(F_VISVAL, visval_handler); + m->set_handler(F_DESCR, descr_handler); + break; + case 2: +{ + m->set_handler(F_CODREG, reg_handler); + m->set_handler(F_CLIENTE, clifo_handler); + m->set_handler(F_FORNITORE, clifo_handler); + m->set_handler(F_TOTALE, totale_handler); + m->set_handler(F_RITFIS, ritfis_handler); + m->set_handler(F_RITSOC, ritsoc_handler); + m->set_handler(F_VISVAL, visval_handler); + m->set_handler(F_OCCASEDIT, occas_handler); + m->set_handler(F_SOLAIVA, solaiva_handler); + m->set_handler(F_SHEETIVA, iva_handler); + + TSheet_field& is = (TSheet_field&)m->field(F_SHEETIVA); + is.set_notify(iva_notify); + TMask& ism = is.sheet_mask(); + ism.set_handler(101, imponibile_handler); + ism.set_handler(102, codiva_handler); + ism.set_handler(104, imposta_handler); + ism.set_handler(109, suspended_handler); + ism.set_handler(209, suspended_handler); + ism.set_handler(309, suspended_handler); +} +break; + case 3: + m->set_handler(O_CODICE, occas_code_handler); + break; +default: +CHECKD(0, "Che cavolo di maschera e' la ", n); +break; +} +if (n == 1 || n == 2) +{ + m->set_handler(F_DATAREG, datareg_handler); + m->set_handler(F_DATACOMP, datacomp_handler); + m->set_handler(F_CODCAUS, caus_modify_handler); + m->set_handler(F_SHEETCG, cg_handler); + + TSheet_field& cg = (TSheet_field&)m->field(F_SHEETCG); + cg.set_notify(cg_notify); + TMask& cgm = cg.sheet_mask(); + cgm.set_handler(101, dareavere_handler); + cgm.set_handler(102, dareavere_handler); + cgm.set_handler(105, suspended_handler); + cgm.set_handler(106, suspended_handler); + cgm.set_handler(206, suspended_handler); + cgm.set_handler(306, suspended_handler); + cgm.set_handler(112, suspended_handler); + cgm.set_handler(113, suspended_handler); + cgm.set_handler(213, suspended_handler); + cgm.set_handler(313, suspended_handler); +} + +return _msk[n] = m; } @@ -225,12 +224,6 @@ void TPrimanota_application::init_mask(TMask& m) if (_iva != nessuna_iva) { - /* - TString16 fil; fil = "I0="; fil << (_iva == iva_acquisti ? '2' : '1'); - TEdit_field& f = (TEdit_field&)m.field(F_CODREG); - f.browse()->cursor()->filter(fil); - */ - char clig, forg; if (_iva == iva_acquisti) { @@ -331,9 +324,11 @@ void TPrimanota_application::init_insert_mode(TMask& m) desc = rcaus->get(RCA_DESC); + const TImporto zero('D', ZERO); + if (iva() == nessuna_iva) { - set_cgs_row(-1,ZERO,tc,desc,' '); + set_cgs_row(-1,zero,tc,desc,' '); } else { @@ -349,7 +344,7 @@ void TPrimanota_application::init_insert_mode(TMask& m) else { const char tipo = nriga < 2 ? 'T' : ' '; - set_cgs_row(-1,ZERO,tc,desc,tipo); + set_cgs_row(-1,zero,tc,desc,tipo); if (nriga == 1 && tc.tipo() > ' ' && tc.sottoconto() > 0) m.set(tc.tipo() == 'C' ? F_CLIENTE : F_FORNITORE, tc.sottoconto()); @@ -374,8 +369,18 @@ bool TPrimanota_application::get_conto(int r, TConto& c) const } -int TPrimanota_application::read(TMask& m) +bool TPrimanota_application::test_swap(bool ritsoc) { + bool s = FALSE; + + const char sez = ritsoc ? causale().sezione_ritsoc() : causale().sezione_clifo(); + s = (iva() == iva_vendite) ^ sez == 'D'; + return s; +} + + +int TPrimanota_application::read(TMask& m) +{ m.autoload(_rel); if (_iva != nessuna_iva) @@ -408,22 +413,23 @@ int TPrimanota_application::read(TMask& m) _saldi.set_data_ulmov((TDate)m.get(F_DATAREG)); TToken_string riga(180); - + for (int i = 0; i < _rel->cg_items(); i++) { TRectype& r = _rel->cg(i); riga.cut(0); // Vuota la riga - const real im(r.get_real("IMPORTO")); - const char sezione = toupper(r.get_char("SEZIONE")); const int rcontr = r.get_int("RCONTR") -1; #ifdef DBG if (rcontr < -1 || rcontr >= _rel->cg_items() || rcontr == i) error_box("La riga %d non puo' avere per contropartita la %d", i+1, rcontr+1); #endif - const bool dare = sezione == 'D'; - riga.add(dare ? im.string() : " "); // Dare 101 - riga.add(dare ? " " : im.string()); // Avere 102 + + const real im(r.get_real("IMPORTO")); + const char sezione = toupper(r.get_char("SEZIONE")); + + TImporto import(sezione, im); + import.add_to(riga); // Dare/Avere 101-102 TConto conto; get_conto(i, conto); riga.add(conto.string(0x3)); // Conto 103-107 @@ -440,11 +446,11 @@ int TPrimanota_application::read(TMask& m) } else riga.add(" | | | | "); - const char* tipo = r.get("ROWTYPE"); // Tipo di riga 115 - riga.add(tipo); + const char tipo = r.get_char("ROWTYPE"); + riga.add(tipo); // Tipo di riga 115 cgs.row(i) = riga; - disable_cgs_cells(i, *tipo); + disable_cgs_cells(i, tipo); } if (_iva == nessuna_iva) @@ -456,13 +462,18 @@ int TPrimanota_application::read(TMask& m) TSheet_field& ivas = (TSheet_field&)m.field(F_SHEETIVA); ivas.reset(); + + const bool to_swap = test_swap(FALSE); for (i = 0; i < _rel->iva_items(); i++) { TRectype& r = _rel->iva(i); riga.cut(0); + + real imponibile(r.get("IMPONIBILE")); + if (to_swap) imponibile = -imponibile; + riga.add(imponibile.string()); // Imponibile 101 - riga.add(r.get("IMPONIBILE")); // Imponibile 101 riga.add(r.get("CODIVA")); // IVA 102 riga.add(r.get("TIPODET")); // Detrazione 103 riga.add(r.get("IMPOSTA")); // Imposta 104 @@ -515,40 +526,30 @@ void TPrimanota_application::mask2rel(const TMask& m) TArray& rows = cgs().rows_array(); int cur = 1; - + // Controlla se e' un movimento con righe contabili if (iva() == nessuna_iva || !m.get_bool(F_SOLAIVA)) + { for (int i = 0; i < rows.items(); i++) { TToken_string& row = (TToken_string&)rows[i]; + TImporto n; n = row; + const TConto conto(row, 2, 0x3); + if (conto.ok()) + _saldi.aggiorna(conto, n.valore(), n.sezione(), TRUE); + TRectype &r = _rel->cg(cur-1); r.zero(); + + r.put("IMPORTO", n.valore()); // Importo + r.put("SEZIONE", n.sezione()); // Sezione + r.put("NUMREG", numreg); r.put("ANNOES", annoes); r.put("DATAREG", datareg); r.put("NUMRIG", cur); - char sezione = 'D'; - - const char* n = row.get(0); - real val0(n); // Dare - n = row.get(); - real val1(n); // Avere - - if (val0.is_zero()) - { - sezione = 'A'; - val0 = val1; - } - - r.put("IMPORTO", val0); // Importo - r.put("SEZIONE", sezione); // Sezione - - const TConto conto(row, -1, 0x3); - if (conto.ok()) - _saldi.aggiorna(conto, val0, sezione, TRUE); - r.put("TIPOC", conto.tipo()); // Conto r.put("GRUPPO", conto.gruppo()); r.put("CONTO", conto.conto()); @@ -561,7 +562,7 @@ void TPrimanota_application::mask2rel(const TMask& m) const TConto contro(row, -1, 0x3); // Conto contropartita if (contro.ok()) { - rcontr = bill2contr(contro, sezione)+1; + rcontr = bill2contr(contro, n.sezione())+1; if (rcontr < 1) { warning_box("La riga contabile %d non ha una contropartita", cur); @@ -569,10 +570,13 @@ void TPrimanota_application::mask2rel(const TMask& m) } } r.put("RCONTR", rcontr); // Contropartita - r.put("ROWTYPE", row.get()); + + const char tipo = row.get_char(); + r.put("ROWTYPE", tipo); + cur++; } - + } if (_iva == nessuna_iva) return; if (causale().reg().corrispettivi()) @@ -602,6 +606,7 @@ void TPrimanota_application::mask2rel(const TMask& m) if (err) _rel->lfile()->zero("OCFPI"); } + const bool to_swap = test_swap(FALSE); TArray& irows = ivas().rows_array(); cur = 1; for (int i = 0; i < irows.items(); i++) @@ -615,7 +620,11 @@ void TPrimanota_application::mask2rel(const TMask& m) r.put("ANNOES", annoes); r.put("NUMREG", numreg); r.put("NUMRIG", cur); - r.put("IMPONIBILE", row.get(0)); + + real imponibile(row.get(0)); + if (to_swap) imponibile = -imponibile; + r.put("IMPONIBILE", imponibile); + r.put("CODIVA", row.get()); r.put("TIPODET", row.get()); r.put("IMPOSTA", row.get()); diff --git a/cg/cg2100b.uml b/cg/cg2100b.uml index 45ff3318c..265ccbd64 100755 --- a/cg/cg2100b.uml +++ b/cg/cg2100b.uml @@ -188,14 +188,14 @@ END NUMBER F_DARE 17 BEGIN - PROMPT 1 -1 "Saldo Dare " + PROMPT 1 -1 "Sbilancio Dare " FLAGS "DRV" PICTURE "." END NUMBER F_AVERE 17 BEGIN - PROMPT 40 -1 "Saldo Avere " + PROMPT 41 -1 "Sbilancio Avere " FLAGS "DRV" PICTURE "." END diff --git a/cg/cg2100c.uml b/cg/cg2100c.uml index 1cc039d5b..8a071003d 100755 --- a/cg/cg2100c.uml +++ b/cg/cg2100c.uml @@ -1,9 +1,7 @@ #include "cg2100.h" TOOLBAR "" 0 20 0 2 - #include - ENDPAGE PAGE "OPERAZIONE DI PRIMA NOTA" -1 -1 77 20 @@ -556,7 +554,7 @@ END NUMBER F_IMPOSTE 17 BEGIN - PROMPT 40 11 "Totale imposte " + PROMPT 41 11 "Totale imposte " FLAGS "DRV" PICTURE "." END @@ -583,14 +581,14 @@ END NUMBER F_DARE 17 BEGIN - PROMPT 1 -1 "Saldo Dare " + PROMPT 1 -1 "Sbilancio Dare " FLAGS "DRV" PICTURE "." END NUMBER F_AVERE 17 BEGIN - PROMPT 40 -1 "Saldo Avere " + PROMPT 41 -1 "Sbilancio Avere " FLAGS "DRV" PICTURE "." END diff --git a/cg/cg2102.cpp b/cg/cg2102.cpp index 248ccb40e..d1de44c0d 100755 --- a/cg/cg2102.cpp +++ b/cg/cg2102.cpp @@ -208,53 +208,55 @@ TSheet_field& TPrimanota_application::cgs() const } -// Certified 99% -// Dato un importo stabilisce se deve andare in DARE o AVERE -// ritornandolo poi col segno opportuno + o - -real TPrimanota_application::imp2sez(const real& imp) -{ - const int dare = (imp >= 0.0) ^ (app().iva() == iva_vendite); - return abs(imp) * (dare ? +1.0 : -1.0); -} - - // Certified 99% // Scrive l'importo imp nella opportuna sezione della riga n -void TPrimanota_application::set_cgs_imp(int n, const real& imp) +void TPrimanota_application::set_cgs_imp(int n, const TImporto& imp) { - TToken_string& row = cgs().row(n); - const char* val = imp.string(); - if (*val == '-') - { - row.add(" ", 0); - row.add(val+1, 1); - } - else - { - row.add(val, 0); - row.add(" ", 1); - } + imp.add_to(cgs().row(n)); cgs().force_update(n); } - // Legge l'importo della riga n e lo ritorna col segno dovuto // Certified 99% -real TPrimanota_application::get_cgs_imp(int n) +TImporto TPrimanota_application::get_cgs_imp(int n) +{ + TImporto importo; + importo = cgs().row(n); + return importo; +} + +// Certified 90% +void TPrimanota_application::add_cgs_imp(int n, const TImporto& imp) { - TToken_string& row = cgs().row(n); - const real dare(row.get(0)); - if (dare > 0.0) return dare; - const real avere(row.get()); - return -avere; + TImporto tot(get_cgs_imp(n)); + tot.set(imp.sezione(), tot.valore() + imp.valore()); + set_cgs_imp(n, tot); +} + +// Certified 90% +void TPrimanota_application::sub_cgs_imp(int n, const real& imp) +{ + TImporto tot(get_cgs_imp(n)); + tot.set(tot.sezione(), tot.valore() - imp); + set_cgs_imp(n, tot); } -// Certified 90% -void TPrimanota_application::add_cgs_imp(int n, const real& imp) -{ - const real tot = get_cgs_imp(n) + imp; - set_cgs_imp(n, tot); +TImporto TPrimanota_application::real2imp(const real& r, char row_type) +{ + bool dare; + if (row_type == 'S') + { + dare = causale().sezione_ritsoc() == 'D'; + } + else + { + dare = causale().sezione_clifo() == 'D'; + if (row_type != 'T' && row_type != 'F') dare = !dare; + } + + TImporto importo(dare ? 'D' : 'A', r); + return importo; } // Disabilita le celle della riga contabile n in base al suo tipo @@ -290,7 +292,7 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo) } -int TPrimanota_application::set_cgs_row(int n, const real& imp, +int TPrimanota_application::set_cgs_row(int n, const TImporto& imp, TConto& conto, const char* desc, char tipo) { @@ -298,7 +300,7 @@ int TPrimanota_application::set_cgs_row(int n, const real& imp, if (n < 0) n = cg.first_empty(); TToken_string& row = cg.row(n); row = ""; - set_cgs_imp(n, imp); + imp.add_to(row); row.add(conto.string(0x3)); row.add(""); row.add(desc); @@ -347,8 +349,8 @@ void TPrimanota_application::cgs_pack() del = TRUE; else { - const real imp = get_cgs_imp(i); - if (imp == 0.0) + const TImporto& imp = get_cgs_imp(i); + if (imp.valore() == ZERO) del = TRUE; } if (del) @@ -368,24 +370,20 @@ real TPrimanota_application::calcola_saldo() const for (int i = 0; i < max; i++) { TToken_string& r = (TToken_string&)rows[i]; - const real dare(r.get(0)); - const real avere(r.get()); - - tdare += dare; - tavere += avere; + tdare += real(r.get(0)); + tavere += real(r.get()); } - real saldo = tdare-tavere; - switch (saldo.sign()) + real sbilancio = abs(tdare)-abs(tavere); + switch (sbilancio.sign()) { case 1: - mask().set(F_DARE, saldo.string()); + mask().set(F_DARE, (tdare-tavere).string()); mask().reset(F_AVERE); break; case -1: mask().reset(F_DARE); - saldo = -saldo; - mask().set(F_AVERE, saldo.string()); + mask().set(F_AVERE, (tavere-tdare).string()); break; default: mask().reset(F_DARE); @@ -393,7 +391,7 @@ real TPrimanota_application::calcola_saldo() const break; } - return saldo; + return sbilancio; } @@ -411,7 +409,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) return f.error_box("Il movimento e' sbilanciato di %s lire.", ss); } else - if (app().get_cgs_imp(0) == ZERO) + if (app().get_cgs_imp(0).valore() == ZERO) return f.error_box("Il movimento non ha una prima riga contabile valida!"); } return TRUE; @@ -519,7 +517,12 @@ bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key) TMask_field& i = f.mask().field(101); i.set_dirty(); return imponibile_handler(i, key); - } + } else + if (key == K_ENTER) + { + if (f.get().empty() && f.mask().get(101).not_empty()) + return f.error_box("Codice IVA obbligatorio"); + } return TRUE; } @@ -578,73 +581,80 @@ real TPrimanota_application::calcola_imp() const return imponibili+imposte; } - // Certified 50% bool TPrimanota_application::iva_notify(int r, KEY k) { - static int oldpos; - static real oldimp; - - static int oldposiva; - static real oldiva; - + static int oldpos,oldposiva; + static real oldimp, oldiva; + TSheet_field& iva = app().ivas(); TToken_string& row = iva.row(r); if (k == K_SPACE) { - const TConto oldconto(row, 5, 0x1); + oldimp = real(row.get(0)); // Imponibile 0 + oldiva = real(row.get(3)); // Imposta 3 + oldposiva = type2pos(detraibile(row.get_int()) ? 'D' : 'N'); // Tipodet 4 + const TConto oldconto(row, 5, 0x1); // t/g/c/s 5 6 7 8 oldpos = bill2pos(oldconto, 'I'); - oldimp = imp2sez(real(row.get(0))); - oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N'); - oldiva = imp2sez(real(row.get(3))); } if (k == K_DEL) { - row.add("0", 0); // Azzera imponibile + row.add("0", 0); // Azzera imponibile row.add("0", 3); // Azzera imposta - k = K_ENTER; // Elegante o Sporco trucco + k = K_ENTER; // Elegante o Sporco trucco (dipende dai gusti!) } if (k == K_ENTER) { - if (oldpos >= 0) // Il conto esisteva anche prima + if (oldpos >= 0) // Il conto esisteva anche prima { - app().add_cgs_imp(oldpos, -oldimp); - oldimp = 0.0; + app().sub_cgs_imp(oldpos, oldimp); } if (oldposiva >= 0) // Il conto IVA esisteva anche prima { - app().add_cgs_imp(oldposiva, -oldiva); - oldiva = 0.0; + app().sub_cgs_imp(oldposiva, oldiva); } // Aggiorna conto sulla riga contabile - real imp = imp2sez(real(row.get(0))); // Imponibile + real imp(row.get(0)); // Imponibile TConto conto(row, 5, 0x3); - oldpos = bill2pos(conto, 'I'); - - if (oldpos < 0) - app().set_cgs_row(-1, imp-oldimp, conto, "", 'I'); + const int newpos = bill2pos(conto, 'I'); + + if (newpos < 0) + { + const TImporto val(app().real2imp(oldpos >= 0 ? imp-oldimp : imp, 'I')); + if (val.valore() != ZERO) + app().set_cgs_row(-1, val, conto, "", 'I'); + } else - app().add_cgs_imp(oldpos, imp-oldimp); + { + const TImporto val(app().real2imp(imp, 'I')); + app().add_cgs_imp(newpos, val); + } oldimp = imp; + oldpos = newpos; // Aggiorna conto IVA sulla riga contabile - imp = imp2sez(real(row.get(3))); // Imposta - const bool detrarre = detraibile(row.get_int(4)); // Determina se IVA detraibile + imp = real(row.get(3)); // Imposta + const bool detrarre = detraibile(row.get_int()); // Determina se IVA detraibile app().causale().bill(detrarre ? 3 : 4, conto); const char tipod = detrarre ? 'D' : 'N'; - oldposiva = type2pos(tipod); - if (oldposiva < 0) + const int newposiva = type2pos(tipod); + + if (newposiva < 0) { - const real val = imp-oldiva; - if (!val.is_zero()) + const TImporto val(app().real2imp(oldposiva >= 0 ? imp-oldiva : imp, 'I')); + if (val.valore() != ZERO) app().set_cgs_row(-1, val, conto, "", tipod); } else - app().add_cgs_imp(oldposiva, imp-oldiva); + { + const TImporto val(app().real2imp(imp, 'I')); + app().add_cgs_imp(newposiva, val); + } oldiva = imp; + oldposiva = newposiva; app().calcola_imp(); app().calcola_saldo(); @@ -662,9 +672,16 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) const real imp = app().calcola_imp(); const TMask& m = f.mask(); + + const bool swapt = app().test_swap(FALSE); + const bool swaps = app().test_swap(TRUE); + real tot(m.get(F_TOTALE)); tot += real(m.get(F_RITFIS)); - tot += real(m.get(F_RITSOC)); + if (swapt ^ swaps) + tot -= real(m.get(F_RITSOC)); + else + tot += real(m.get(F_RITSOC)); if (imp != tot) { @@ -746,29 +763,32 @@ bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key) } -// Handler of the F_DATAREG field on the modify mask +// Handler of the F_DATAREG field // Certified 70% bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) { bool ok = TRUE; - if (f.to_check(key)) + if ((key == K_TAB && f.focusdirty()) || key == K_ENTER) { const TDate dr(f.get()); // Data dell'operazione if (dr > TDate(TODAY)) return f.error_box("La data dell'operazione e' superiore quella di sistema"); - TMask& m = f.mask(); - const int ae = date2esc(dr); // Anno esercizio + TMask& m = f.mask(); - if (m.query_mode()) - { - if (ae == 0) - return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); + const int ae = date2esc(dr); // Anno esercizio + if (ae == 0) + return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); + + if (m.query_mode() || app().giornale().year() != ae) ok = app().giornale().read(ae); - if (!ok) - return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); - } + else + ok = TRUE; + + if (!ok) + return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); + if (dr < app().giornale().last_print()) return f.error_box("La data dell'operazione e' antecedente alla " "data di stampa del libro giornale dell'esercizio %d", ae); @@ -941,12 +961,14 @@ void TPrimanota_application::add_cgs_tot(TMask& m) real tot(m.get(F_TOTALE)); // Creazione/Aggiornamento riga totale - int pos = type2pos('T'); - pos = set_cgs_row(pos, -imp2sez(tot), c, "Totale documento", 'T'); + const int pos = type2pos('T'); + set_cgs_row(pos, real2imp(tot, 'T'), c, "Totale documento", 'T'); - TToken_string& row = ivas().row(0); const TCodiceIVA iva(m.get(F_CODIVA)); - if (iva.ok()) + TToken_string& row = ivas().row(0); + + const real imp(row.get(0)); + if (imp == ZERO && iva.ok()) { iva_notify(0, K_SPACE); const real imposta = scorpora(tot, iva.percentuale()); @@ -967,7 +989,6 @@ void TPrimanota_application::add_cgs_tot(TMask& m) bill.set(m.get_int(F_GRUPPORIC), m.get_int(F_CONTORIC), m.get_long(F_SOTTOCONTORIC)); if (!bill.ok()) _causale.bill(2, bill); - row.add(bill.tipo(), 5); row.add(bill.gruppo(), 6); row.add(bill.conto(), 7); @@ -976,7 +997,7 @@ void TPrimanota_application::add_cgs_tot(TMask& m) app().ivas().force_update(0); iva_notify(0, K_ENTER); - } + } } @@ -1027,10 +1048,10 @@ void TPrimanota_application::add_cgs_rit(bool fiscali) TString80 desc("Ritenute "); desc << (fiscali ? "fiscali" : "sociali"); - set_cgs_row(-1, -imp2sez(imp), conto, desc, tipo); + set_cgs_row(-1, real2imp(imp, tipo), conto, desc, tipo); } else - set_cgs_imp(pos, -imp2sez(imp)); + set_cgs_imp(pos, real2imp(imp, tipo)); } @@ -1105,14 +1126,3 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) } -// Fill missing bill -// Certified 50% -bool TPrimanota_application::conto_handler(TMask_field& f, KEY k) -{ - if (k == K_ENTER && f.get().empty()) - { - if (f.mask().get(101).empty()) return TRUE; // Se non c'e' importo ignora la riga - return f.error_box("Il conto e' obbligatorio sulla riga IVA"); - } - return TRUE; -} diff --git a/cg/cg2102.h b/cg/cg2102.h index 4859c6a58..d87675bfa 100755 --- a/cg/cg2102.h +++ b/cg/cg2102.h @@ -67,7 +67,6 @@ class TPrimanota_application : public TRelation_application static bool codiva_handler(TMask_field& f, KEY key); static bool imposta_handler(TMask_field& f, KEY key); static bool dareavere_handler(TMask_field& f, KEY k); - static bool conto_handler(TMask_field& f, KEY key); static bool iva_notify(int r, KEY key); static bool iva_handler(TMask_field& f, KEY key); @@ -106,7 +105,6 @@ protected: TSheet_field& cgs() const; TSheet_field& ivas() const; - static real imp2sez(const real& importo); static int bill2pos(const TConto& conto, char tipo); static TipoIVA reg2IVA(const char* registro, int anno); static TipoIVA cau2IVA(const char* causale, int anno); @@ -123,15 +121,20 @@ protected: TCausale& causale() { return _causale; } TLibro_giornale& giornale() { return _giornale; } - void set_cgs_imp(int n, const real& importo); - real get_cgs_imp(int n); - void add_cgs_imp(int n, const real& importo); + bool test_swap(bool ritsoc); + TImporto real2imp(const real& r, char tipo); + + void set_cgs_imp(int n, const TImporto& importo); + TImporto get_cgs_imp(int n); + void add_cgs_imp(int n, const TImporto& importo); + void sub_cgs_imp(int n, const real& imp); + void cgs_pack(); real calcola_saldo() const; real calcola_imp() const; void set_ivas_row(int n, const char* codiva, TConto& tc, const char* desc); - int set_cgs_row(int n, const real& importo, TConto& conto, const char* desc, char tipo); + int set_cgs_row(int n, const TImporto& importo, TConto& conto, const char* desc, char tipo); void disable_cgs_cells(int n, char tipo); void add_cgs_tot(TMask& m); void add_cgs_rit(bool fisc); diff --git a/cg/cg2103.cpp b/cg/cg2103.cpp index 72273fe00..266af20e9 100755 --- a/cg/cg2103.cpp +++ b/cg/cg2103.cpp @@ -203,7 +203,8 @@ TLibro_giornale::TLibro_giornale(int y) /////////////////////////////////////////////////////////// TCausale::TCausale(const char* cod, int year) -: TArray(12), _rec(LF_CAUSALI), _iva(iva_errata) +: TArray(12), _rec(LF_CAUSALI), _iva(iva_errata), + _sezione_clifo(' '), _sezione_ritsoc(' ') { if (*cod) read(cod, year); } @@ -214,9 +215,11 @@ bool TCausale::read(const char* cod, int year) { destroy(); // Delete all rows + _iva = iva_errata; + _sezione_clifo = _sezione_ritsoc = ' '; + if (*cod > ' ') { - _iva = iva_errata; TLocalisamfile caus(LF_CAUSALI); caus.setkey(1); @@ -299,13 +302,37 @@ bool TCausale::intra() const bool TCausale::corrval() const { return _rec.ok() ? _rec.get_bool("VALINTRA") : FALSE; } - const char* TCausale::causale_inc_imm() const { return _rec.ok() ? _rec.get("CODCAUSIM") : ""; } const char* TCausale::tipo_doc() const { return _rec.ok() ? _rec.get("TIPODOC") : ""; } +char TCausale::sezione(int riga) const +{ + const TRectype& r = row(riga); + char sez = toupper(r.get_char("SEZIONE")); + if (sez <= ' ') // Guess section on tipocf + { + const char tipocf = toupper(row(1).get_char("TIPOCF")); + sez = (tipocf == 'C') ? 'D' : 'A'; + } + return sez; +} + +char TCausale::sezione_clifo() +{ + if (_sezione_clifo == ' ') + _sezione_clifo = sezione(1); + return _sezione_clifo; +} + +char TCausale::sezione_ritsoc() +{ + if (_sezione_ritsoc == ' ') + _sezione_ritsoc = sezione(9); + return _sezione_ritsoc; +} TipoIVA TCausale::iva() const { @@ -365,3 +392,68 @@ bool TCodiceIVA::read(const char* cod) if (err != NOERR) zero(); return err == NOERR; } + + +/////////////////////////////////////////////////////////// +// Importo +/////////////////////////////////////////////////////////// + +const TImporto& TImporto::add_to(TToken_string& s) const +{ + const bool dare = sezione() == 'D'; + const char* v = valore().string(); + s.add(dare ? v : "", 0); + s.add(dare ? "" : v, 1); + return *this; +} + +// Cerified 99% +// Ambigous section for ZERO +const TImporto& TImporto::operator =(TToken_string& sv) +{ + _valore = real(sv.get(0)); + if (_valore == ZERO) + { + _valore = real(sv.get()); + _sezione = 'A'; + } + else + _sezione = 'D'; + return *this; +} + + +const TImporto& TImporto::set(char s, const real& v) +{ + CHECKD(s == 'D' || s == 'A', "Sezione errata per importo: codice ", (int)s); + _sezione = s; _valore = v; + return *this; +} + + +const TImporto& TImporto::operator += (const TImporto& i) +{ + if (_sezione == i._sezione) + _valore += i._valore; + else + _valore -= i._valore; + return *this; +} + + +const TImporto& TImporto::operator -= (const TImporto& i) +{ + if (_sezione == i._sezione) + _valore -= i._valore; + else + _valore += i._valore; + return *this; +} + +const TImporto& TImporto::swap() +{ + _sezione = (_sezione == 'D') ? 'A' : 'D'; + _valore = -_valore; + return *this; +} + diff --git a/cg/cg2103.h b/cg/cg2103.h index 34cf78074..d5d3796bb 100755 --- a/cg/cg2103.h +++ b/cg/cg2103.h @@ -9,7 +9,8 @@ #include "conto.h" #endif -enum TipoIVA { +enum TipoIVA +{ iva_errata = -1, nessuna_iva = 0, iva_vendite = 1, @@ -19,7 +20,6 @@ enum TipoIVA { const char* iva2name(TipoIVA i); - class TRegistro : public TObject { bool read_att(); @@ -65,10 +65,12 @@ public: class TCausale : public TArray { - TipoIVA _iva; TRectype _rec; TRegistro _reg; + TipoIVA _iva; + char _sezione_clifo, _sezione_ritsoc; + protected: const TRectype& row(int num) const; @@ -91,6 +93,10 @@ public: virtual bool ok() const { return !_rec.empty(); } bool similar(const TCausale& c) const; + char sezione(int riga) const; + char sezione_clifo(); + char sezione_ritsoc(); + bool read(const char* cod, int year); TCausale(const char* code = "", int year = 0); @@ -108,4 +114,27 @@ public: const TString& tipo() const { return get("S1"); } }; +class TImporto : public TObject +{ + char _sezione; + real _valore; + +public: + char sezione() const { return _sezione; } + const real& valore() const { return _valore; } + + const TImporto& operator=(const TImporto& i) { return set(i.sezione(), i.valore()); } + const TImporto& operator=(TToken_string& sv); + const TImporto& operator+=(const TImporto& i); + const TImporto& operator-=(const TImporto& i); + const TImporto& swap(); + const TImporto& TImporto::normalize() { if (_valore < ZERO) swap(); return *this; } + + const TImporto& set(char s, const real& v); + const TImporto& add_to(TToken_string& s) const; + + TImporto(char s = 'D', const real& v = ZERO) { set(s, v); } + TImporto(const TImporto& i) : _sezione(i._sezione), _valore(i._valore) {} +}; + #endif diff --git a/cg/cg21cg.uml b/cg/cg21cg.uml index d83a7cf7a..2e7a3cab5 100755 --- a/cg/cg21cg.uml +++ b/cg/cg21cg.uml @@ -94,7 +94,7 @@ BEGIN ADD RUN cg0 -0 CHECKTYPE NORMAL VALIDATE REQIF_FUNC 2 101 102 - WARNING "Sottoconto inesistente o mancante sulla riga contabile" + WARNING "Sottoconto inesistente sulla riga contabile" END NUMBER 206 6 @@ -113,6 +113,7 @@ BEGIN MESSAGE COPY,106 ADD RUN cg0 -1 CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 2 101 102 WARNING "Cliente inesistente sulla riga contabile" END @@ -133,6 +134,7 @@ BEGIN ADD RUN cg0 -1 MESSAGE COPY,106 CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 2 101 102 WARNING "Fornitore inesistente sulla riga contabile" END diff --git a/cg/cg21iva.uml b/cg/cg21iva.uml index 7d6960b8b..76ae73997 100755 --- a/cg/cg21iva.uml +++ b/cg/cg21iva.uml @@ -65,6 +65,7 @@ BEGIN OUTPUT 110 DESCR ADD RUN cg0 -0 CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 1 101 WARNING "Sottoconto inesistente nella riga IVA" END @@ -85,6 +86,8 @@ BEGIN ADD RUN cg0 -1 FLAGS "G" MESSAGE COPY,109|RESET,105 + VALIDATE REQIF_FUNC 1 101 + WARNING "Cliente inesistente nella riga IVA" END NUMBER 309 6 @@ -103,6 +106,8 @@ BEGIN ADD RUN cg0 -1 FLAGS "G" MESSAGE COPY,109|RESET,105 + VALIDATE REQIF_FUNC 1 101 + WARNING "Fornitore inesistente nella riga IVA" END STRING 110 50 @@ -177,6 +182,7 @@ BEGIN OUTPUT 102 CODTAB OUTPUT 211 S0 CHECKTYPE NORMAL + VALIDATE REQIF_FUNC 1 101 END STRING 211 50