diff --git a/src/ce/ce0400.cpp b/src/ce/ce0400.cpp index ba29c88c8..d0bb62b71 100755 --- a/src/ce/ce0400.cpp +++ b/src/ce/ce0400.cpp @@ -1,10 +1,12 @@ #include #include #include +#include #include #include #include "ce0400a.h" +#include "../cg/cglib.h" //------------------------------------------------------ // Maschera di configurazione @@ -23,6 +25,17 @@ bool TConfig_mask::on_field_event(TOperable_field& f, TField_event e, long jolly { switch (f.dlg()) { +/* case F_ESERCORR: + if (e == fe_init) + { + const TEsercizio & esc = esercizi().esercizio(f.get_int()); + bool covid_19 = esc.inizio().year() > 2019; + + show(F_SOSPAMM, covid_19); + if (!covid_19) + reset(F_SOSPAMM); + } + break; */ case F_NAME_USER: if (e == fe_button) { diff --git a/src/ce/ce0400a.h b/src/ce/ce0400a.h index 5aab2b0d8..b45bb3723 100755 --- a/src/ce/ce0400a.h +++ b/src/ce/ce0400a.h @@ -13,6 +13,7 @@ #define F_DATACONS 110 #define F_ANNOTUIR 111 #define F_AMMPROP 112 +#define F_SOSPAMM 113 //Pagina 2 //sheet elenco files personalizzati e relative righe diff --git a/src/ce/ce0400a.uml b/src/ce/ce0400a.uml index 14fe205dd..a815957bf 100755 --- a/src/ce/ce0400a.uml +++ b/src/ce/ce0400a.uml @@ -134,6 +134,12 @@ BEGIN FIELD AMMPROP END +BOOLEAN F_SOSPAMM +BEGIN + PROMPT 1 10 "Sospensione ammortamento per COVID-19" + FIELD SOSPAMM +END + ENDPAGE //-----------------------------------------------------------------------------------------------// diff --git a/src/ce/ce1400.cpp b/src/ce/ce1400.cpp index b5aea8660..6e34c3390 100755 --- a/src/ce/ce1400.cpp +++ b/src/ce/ce1400.cpp @@ -86,14 +86,18 @@ bool TSac_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) if (e == fe_modify || e == fe_close) { TDitta_cespiti& dc = ditta_cespiti(); + const int ese = get_int(F_ESERCIZIO); const int gr = get_int(F_GRUPPO); - const char* sp = get(F_SPECIE); + const TString16 sp = get(F_SPECIE); const int ca = get_int(F_CATEGORIA2); const TRectype& cac = dc.categoria(gr, sp, ca); bool ok = !cac.empty(); - if (ok && (o.dlg() == F_CATEGORIA || o.dlg() == F_CATEGORIA2)) + const short dlg = o.dlg(); + + if (ok && (dlg == F_CATEGORIA || dlg == F_CATEGORIA2)) { - set(o.dlg() == F_CATEGORIA ? F_DESC_CAT : F_DESC_CAT2, cac.get("S0")); + set(dlg == F_CATEGORIA ? F_DESC_CAT : F_DESC_CAT2, cac.get("S0")); + const bool sospamm = ini_get_bool(CONFIG_DITTA, "ce", "SOSPAMM", false) && ese == 2020; if (cac.get_bool("B0")) return error_box(TR("Categoria non ammortizzabile")); @@ -105,7 +109,8 @@ bool TSac_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) case 1: // Beni immateriali { const bool amm_per_anni = cac.get_int("I1") <= 1; - if (amm_per_anni) + + if (!sospamm && amm_per_anni) return error_box(TR("La categoria prevede un ammortamento per anni:\n" "Effettuare le scelte sul cespite")); } @@ -113,7 +118,8 @@ bool TSac_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) case 2: // Costi pluriennali { const int vincolo = cac.get_int("I2"); - if (vincolo == 3) // Quote + + if (!sospamm && vincolo == 3) // Quote return error_box(TR("La categoria prevede un ammortamento per quote costanti:\n" "Effettuare le scelte sul cespite")); } @@ -122,10 +128,17 @@ bool TSac_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) break; } } - if (!ok && !o.empty() && o.dlg() == F_CATEGORIA2) - return error_box(TR("E' neccessario specificare una categoria valida")); - if (ok && e == fe_button && o.dlg() == F_CATEGORIA) - send_key(K_ENTER, 0); + if (ok) + { + if (dlg == F_CATEGORIA) + send_key(K_ENTER, 0); + } + else + { + if (ca > 0 && dlg == F_CATEGORIA2) + return error_box(TR("E' neccessario specificare una categoria valida")); + } + } break; default: @@ -278,7 +291,7 @@ protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: - TImm_mask() : TAutomask("ce1400c") { } + TImm_mask() : TAutomask("ce1400c") {} }; bool TImm_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) @@ -307,7 +320,7 @@ protected: virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: - TPlu_mask() : TAutomask("ce1400d") { } + TPlu_mask() : TAutomask("ce1400d") {} }; bool TPlu_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) @@ -419,23 +432,36 @@ void TScelta_amm_cat::init_mask(TMask& m) const int gru = _msk[0]->get_int(F_GRUPPO); const char* spe = _msk[0]->get(F_SPECIE); const int cat = _msk[0]->get_int(F_CATEGORIA2); + dc.set_attivita(ese, gru, spe); dc.init_mask(m); m.set(F_CATEGORIA, cat); - + const TRectype& cac = dc.categoria(gru, spe, cat); + switch (_tipo) { case 1: // Immateriali - m.set(F_TIPOAMM, cac.get("I1")); - m.set(F_MAX_AMM, cac.get("R13")); - m.set(F_ANNI, cac.get("I3")); + { + m.set(F_TIPOAMM, cac.get("I1")); + m.set(F_MAX_AMM, cac.get("R13")); + m.set(F_ANNI, cac.get("I3")); + + const bool amm_per_anni = cac.get_int("I1") <= 1; + + m.enable(F_NORFIS, !amm_per_anni); + } break; case 2: // Pluriennali - m.set(F_TIPOVINC, cac.get("I2")); - m.set(F_MIN_AMM, cac.get("R14")); - m.set(F_MAX_AMM, cac.get("R15")); - m.set(F_ANNI, cac.get("I3")); + { + const int vincolo = cac.get_int("I2"); + + m.set(F_TIPOVINC, vincolo); + m.set(F_MIN_AMM, cac.get("R14")); + m.set(F_MAX_AMM, cac.get("R15")); + m.set(F_ANNI, cac.get("I3")); + m.enable(F_NORFIS, vincolo != 3); + } break; default: // Materiali { diff --git a/src/ce/ce2101.cpp b/src/ce/ce2101.cpp index e3b35a98d..31ea6dec7 100755 --- a/src/ce/ce2101.cpp +++ b/src/ce/ce2101.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -925,36 +926,44 @@ real TCespite::calc_quota(const real& valamm, const real& perric, // Calcolo delle quote perse // Certified 50% -real TCespite::calc_quote_perse(const real& valamm, const real& peric, const real& residuo, +// non piu' previste dalla legge tolto nel 2021 +/* real TCespite::calc_quote_perse(const real& valamm, const real& peric, const real& residuo, const real& quotamm, bool mov_vend, const TDate& dtmov) { const TDitta_cespiti& cce = ditta_cespiti(); const real coeff_durata = cce.coefficiente_durata_esercizio(); real quota = valamm * coeff_durata * peric / CENTO; - if (mov_vend) - { - TDate inies, fines; - cce.esercizio_corrente(inies, fines); - const TDate dtcomp = get_date(CESPI_DTCOMP); - const real giorni_possesso = dtmov - fnc_max(inies, dtcomp) + 1; - const real giorni_esercizio = fines - inies + 1; - quota = quota * giorni_possesso / giorni_esercizio; - } - cce.arrotonda(quota); - - if (quota < residuo) + const bool skip = _tipo_sit != 1 && _sosp_covid && cce.esercizio_corrente() == 2020; + + if (skip) + quota = ZERO; + else { - const bool amm_rit = ammini_get_bool(AMMCE_AMMRIT); - if (quota > quotamm && !amm_rit) - quota -= quotamm; - else + if (mov_vend) + { + TDate inies, fines; + cce.esercizio_corrente(inies, fines); + const TDate dtcomp = get_date(CESPI_DTCOMP); + const real giorni_possesso = dtmov - fnc_max(inies, dtcomp) + 1; + const real giorni_esercizio = fines - inies + 1; + quota = quota * giorni_possesso / giorni_esercizio; + } + cce.arrotonda(quota); + + if (quota < residuo) + { + const bool amm_rit = ammini_get_bool(AMMCE_AMMRIT); + if (quota > quotamm && !amm_rit) + quota -= quotamm; + else + quota = ZERO; + } + else quota = ZERO; } - else - quota = ZERO; - return quota; } +*/ void TCespite::agg_quota(const real& movvalamm, TRectype& rec, const char* field, bool calcq) { @@ -992,18 +1001,20 @@ void TCespite::agg_quota(const real& movvalamm, TRectype& rec, const char* field } } +const char * rewrite_fname(const char* name, int sit) +{ + TString16 fname = get_tmp_string(20); + + fname = name; + if (fname.starts_with("PF") && sit != 1) + fname.overwrite("PC", 0); + return fname; +} + HIDDEN const TString& catdi_get(const TRectype* pcatdi, const char* name, int sit) { - if (pcatdi != NULL) - { - if (sit != 1) - { - TString16 fname(name); - fname.overwrite("PC", 0); - return pcatdi->get(fname); - } - return pcatdi->get(name); - } + if (pcatdi != nullptr) + return pcatdi->get(rewrite_fname(name, sit)); else CHECK(false, "NULL CATDI record"); @@ -1024,6 +1035,7 @@ const TString& TCespite::ammini_get(const char* pstar) const const TDitta_cespiti& dc = ditta_cespiti(); const TRectype* pcatdi = NULL; const TRectype* pcac = NULL; + const bool sospamm = _sosp_covid && dc.esercizio_corrente() == 2020; // L'utente fa le sue scelte: ma saranno sensate e coerenti? int scelte = _ammini.get_int(AMMCE_SCELTE); @@ -1035,6 +1047,10 @@ const TString& TCespite::ammini_get(const char* pstar) const const int categ = get_int(CESPI_CODCAT); TString80 key; key.format("%d|%d|%s|%d", anno, gruppo, (const char*)specie, categ); const TRectype& catdi = cache().get(LF_CATDI, key); + + if (get_int(CESPI_IDCESPITE) == 452 && _tipo_sit != 3) + int i = 1; + if (!catdi.empty()) { pcatdi = &catdi; @@ -1085,14 +1101,16 @@ const TString& TCespite::ammini_get(const char* pstar) const } break; case tc_immateriale: + // if (scelte == 2 || (_tipo_sit != 1 && sospamm)) if (scelte == 2) val = catdi_get(pcatdi, CATDI_PFNORVN, _tipo_sit); else val = pcac->get("R13"); break; case tc_pluriennale: +// if (scelte == 2 || (_tipo_sit != 1 && sospamm)) if (scelte == 2) - val = catdi_get(pcatdi, CATDI_PFNORVN, _tipo_sit); + val = catdi_get(pcatdi, CATDI_PFNORVN, _tipo_sit); else val = pcac->get("R15"); break; @@ -1312,7 +1330,8 @@ void TCespite::calc_perc(TRelation& rel, const TRectype& tmv, const TRectype& tm // Calcolare quote perse const TDate dtmov = tmv.get_date(MOVCE_DTMOV); - const real quote_perse = calc_quote_perse(valamm, per_eff, resamm, qnor, true, dtmov); + // non piu' previste dalla legge tolto nel 2021 + // const real quote_perse = calc_quote_perse(valamm, per_eff, resamm, qnor, true, dtmov); if (_tipo_sit == 1 && get_int(CESPI_USOPROM) > 1) agg_quota(valamm, ammmv, "QNOR", true); @@ -1864,8 +1883,9 @@ void TCespite::calc_amm_residui(bool is_valid) _ammpro.put(AMMCE_QNOR, qnor); ammpro_put_perc(AMMCE_PNOR, per_eff); - const real quote_perse = calc_quote_perse(valamm, pmat, resamm, qnor, false, TDate()); - _ammpro.put(AMMCE_QPERSE, quote_perse); + // non piu' previste dalla legge tolto nel 2021 +// const real quote_perse = calc_quote_perse(valamm, pmat, resamm, qnor, false, TDate()); + _ammpro.zero(AMMCE_QPERSE); const int uso_promiscuo = get_int(CESPI_USOPROM); if (_tipo_sit == 1 && uso_promiscuo > 1) @@ -1875,7 +1895,7 @@ void TCespite::calc_amm_residui(bool is_valid) resamm -= qnor + _ammpro.get_real(AMMCE_FPRIVATO); const real pacc = _ammpro.get_real(AMMCE_PACC); - if (resamm > ZERO && pacc > ZERO && quote_perse.is_zero()) + if (resamm > ZERO && pacc > ZERO) // non piu' previste dalla legge tolto nel 2021 && quote_perse.is_zero()) { const real qacc = calc_quota(val_amm(), pacc, resamm, per_eff); _ammpro.put(AMMCE_QACC, qacc); @@ -2059,7 +2079,8 @@ bool TCespite::calc_amm(int tipo_sit, const TDate& data_limite, const TString16 idcespite = get(CESPI_IDCESPITE); // Keep it handy for debug purposes log(FR("* Inizio calcolo situazione %d cespite %s"), tipo_sit, (const char*)idcespite); - + + #ifdef DBG if (tipo_sit == 1 && atol(idcespite) == 1362) tipo_sit = 1; // Put your breakpoint here @@ -2175,15 +2196,18 @@ void TCespite::load_saldi(const int tiposit, const int esercizio) TCespite::TCespite() : TRectype(LF_CESPI), _salini(LF_SALCE), _salpro(LF_SALCE), _ammini(LF_AMMCE), _ammpro(LF_AMMCE) { + _sosp_covid = ini_get_bool(CONFIG_DITTA, "ce", "SOSPAMM", false); } TCespite::TCespite(const char* id) : TRectype(LF_CESPI), _salini(LF_SALCE), _salpro(LF_SALCE), _ammini(LF_AMMCE), _ammpro(LF_AMMCE) { + _sosp_covid = ini_get_bool(CONFIG_DITTA, "ce", "SOSPAMM", false); read(id); } TCespite::TCespite(const TRectype& rec) : TRectype(rec), _salini(LF_SALCE), _salpro(LF_SALCE), _ammini(LF_AMMCE), _ammpro(LF_AMMCE) { + _sosp_covid = ini_get_bool(CONFIG_DITTA, "ce", "SOSPAMM", false); } diff --git a/src/ce/ce2101.h b/src/ce/ce2101.h index e2b032206..0b3b9e27b 100755 --- a/src/ce/ce2101.h +++ b/src/ce/ce2101.h @@ -12,6 +12,7 @@ enum TTipoVeicolo { tv_nessuno, tv_automobile, tv_motociclo, tv_ciclomotore, class TCespite : public TRectype { int _tipo_sit; + bool _sosp_covid; TRectype _salini, _salpro; TRectype _ammini, _ammpro; diff --git a/src/ce/ce3900.cpp b/src/ce/ce3900.cpp index 0c1d300e8..eff401b44 100755 --- a/src/ce/ce3900.cpp +++ b/src/ce/ce3900.cpp @@ -32,11 +32,13 @@ class TStampa_sintetica_mask : public TAutomask { bool _preview; + bool _excel; protected: bool on_field_event(TOperable_field& o, TField_event e, long jolly); public: bool preview() const { return _preview; } + bool excel() const { return _excel; } TStampa_sintetica_mask(); }; @@ -82,12 +84,23 @@ bool TStampa_sintetica_mask::on_field_event(TOperable_field& o, TField_event e, break; case DLG_PRINT: if (e == fe_button) + { _preview = false; + _excel = false; + } break; case DLG_PREVIEW: if (e == fe_button) { _preview = true; + _excel = false; + stop_run(K_ENTER); + } + break; + case DLG_EXPORT_EXCEL: + if (e == fe_button) + { + _excel = true; stop_run(K_ENTER); } break; @@ -96,7 +109,7 @@ bool TStampa_sintetica_mask::on_field_event(TOperable_field& o, TField_event e, return ok; } -TStampa_sintetica_mask::TStampa_sintetica_mask() : TAutomask("ce3900"), _preview(false) +TStampa_sintetica_mask::TStampa_sintetica_mask() : TAutomask("ce3900"), _preview(false), _excel(false) { } @@ -236,6 +249,8 @@ bool TStampa_sintetica_rep::get_usr_val(const TString& name, TVariant& var) cons { const TRecordset& recset = *recordset(); const TString& idcespite = recset.get(CESPI_IDCESPITE).as_string(); + + if (idcespite != _cespite.get(CESPI_IDCESPITE)) { TCespite& c = (TCespite&)_cespite; @@ -411,13 +426,30 @@ void TStampa_sintetica::main_loop() rep.load("ce3900b"); rep.set_filter(mask); + if (mask.excel()) + { + rep.section('H', 2).hide(); + rep.section('H', 3).hide(); + rep.section('H', 4).hide(); + rep.section('F', 2).hide(); + rep.section('F', 3).hide(); + rep.section('F', 4).hide(); + } book.add(rep); //stampa il book dei report - if (mask.preview()) - book.preview(); + if (mask.excel()) + { + TFilename out; + + out.tempdir(); out.add("cespsint.xls"); + book.export_excel(out, false, true, true); + } else - book.print(); + if (mask.preview()) + book.preview(); + else + book.print(); } } diff --git a/src/ce/ce3900.uml b/src/ce/ce3900.uml index e9f0a76cf..25011a2c9 100755 --- a/src/ce/ce3900.uml +++ b/src/ce/ce3900.uml @@ -1,6 +1,9 @@ #include "ce3900.h" TOOLBAR "topbar" 0 0 0 2 + +#define EXPORT_EXCEL + #include ENDPAGE diff --git a/src/ce/ce3900a.rep b/src/ce/ce3900a.rep index 4077f258c..45d037511 100755 --- a/src/ce/ce3900a.rep +++ b/src/ce/ce3900a.rep @@ -1,13 +1,13 @@ Registro cespiti sintetico - + USE CESPI KEY 2 \ No newline at end of file diff --git a/src/ce/ce3900b.rep b/src/ce/ce3900b.rep index ce6e4b0f7..96255ab24 100644 --- a/src/ce/ce3900b.rep +++ b/src/ce/ce3900b.rep @@ -1,13 +1,13 @@ Registro cespiti sintetico per codice cespite - + USE CESPI KEY 2 \ No newline at end of file