diff --git a/src/cg/cg2100.cpp b/src/cg/cg2100.cpp index ee30462ea..99bee7146 100755 --- a/src/cg/cg2100.cpp +++ b/src/cg/cg2100.cpp @@ -49,6 +49,7 @@ public: long _movcoll; TString4 _causale_originale; TipoIVA _iva_originale; + TString_array _iva; }; /////////////////////////////////////////////////////////// @@ -56,15 +57,16 @@ public: /////////////////////////////////////////////////////////// TPrimanota_application::TPrimanota_application() -: _rel(NULL), _mode(0), _iva(nessuna_iva), _causale(NULL), _giornale(NULL), - _lastreg(0), _last_dreg(TODAY), _last_dcom(TODAY), _automatico(NULL), _swap_mask(false), _is_set_fpcheck(false), _f1_ini(false), _f1_liq(false) +: _rel(nullptr), _mode(0), _iva(nessuna_iva), _causale(nullptr), _giornale(nullptr), + _lastreg(0), _last_dreg(TODAY), _last_dcom(TODAY), _automatico(nullptr), _swap_mask(false), _is_set_fpcheck(false), _f1_ini(false), _f1_liq(false), + _skip_giornale_check(false), _skip_bollato_check(false) { memset(_msk, 0, sizeof(_msk)); } TMask* TPrimanota_application::load_mask(int n) { - if (_msk[n] != NULL) + if (_msk[n] != nullptr) return _msk[n]; TString8 name = "cg2100"; name << char(n == 3 ? 'o' : 'a'+n); @@ -120,29 +122,30 @@ TMask* TPrimanota_application::load_mask(int n) TSheet_field& is = m->sfield(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(103, detrazione_handler); - ism.set_handler(104, imposta_handler); - ism.set_handler(107, cg_gruppo_handler); - ism.set_handler(109, iva_sottoconto_handler); - ism.set_handler(110, iva_sottoconto_handler); - ism.set_handler(209, sheet_clifo_handler); - ism.set_handler(309, sheet_clifo_handler); + + ism.set_handler(IVA_IMPONIBILE, imponibile_handler); + ism.set_handler(IVA_CODIVA, codiva_handler); + ism.set_handler(IVA_INDETRAIBILE, detrazione_handler); + ism.set_handler(IVA_IMPOSTA, imposta_handler); + ism.set_handler(IVA_GRUPPO, cg_gruppo_handler); + ism.set_handler(IVA_SOTTOCONTO, iva_sottoconto_handler); + ism.set_handler(IVA_DESCRCONTO, iva_sottoconto_handler); + ism.set_handler(IVA_CLIENTE, sheet_clifo_handler); + ism.set_handler(IVA_FORNITORE, sheet_clifo_handler); ism.set_handler(CG_RATEO, sheet_rateo_handler); ism.set_handler(CG_RISCONTO, sheet_risconto_handler); if (!has_module(FPAUT)) { - if (m->find_by_id(F_COLFPPRO) != NULL) + if (m->find_by_id(F_COLFPPRO) != nullptr) m->hide(F_COLFPPRO); - if (m->find_by_id(DLG_LINK) != NULL) + if (m->find_by_id(DLG_LINK) != nullptr) { m->disable(DLG_LINK); m->disable(DLG_EDIT); } } else - if (m->find_by_id(DLG_LINK) != NULL) + if (m->find_by_id(DLG_LINK) != nullptr) { m->set_handler(DLG_LINK, fppro_mask); m->set_handler(DLG_EDIT, scollega_handler); @@ -273,7 +276,7 @@ bool TPrimanota_application::user_create() set_search_field(F_NUMREG); // Set field for default search - _pag = NULL; + _pag = nullptr; _is_saldaconto = false; TFilename tmp; @@ -315,17 +318,13 @@ bool TPrimanota_application::is_transaction() const bool TPrimanota_application::user_destroy() { for (int m = 3; m >= 0; m--) - if (_msk[m] != NULL) delete _msk[m]; - - if (_pag) delete _pag; - - delete _giornale; - delete _causale; - delete _rel; - - delete _automatico; - - return true; + SAFE_DELETE(_msk[m]); + SAFE_DELETE(_pag); + SAFE_DELETE(_giornale); + SAFE_DELETE(_causale); + SAFE_DELETE(_rel); + SAFE_DELETE(_automatico); + return true; } // Legge la causale di codice cod ed il relativo registro dell'anno year @@ -334,7 +333,7 @@ bool TPrimanota_application::read_caus(const char* cod, int year) { bool ok = true; - if (cod != NULL) + if (cod != nullptr) { ok = causale().read(cod, year); _iva = causale().iva(); @@ -355,7 +354,7 @@ bool TPrimanota_application::read_caus(const char* cod, int year) } // Se sono chiamato dai campi di query ho belle che finito - if (_mode == MODE_QUERY || m == NULL) + if (_mode == MODE_QUERY || m == nullptr) return true; const bool ins = check_insert_mode(); @@ -366,9 +365,10 @@ bool TPrimanota_application::read_caus(const char* cod, int year) const bool nota_credito = is_nota_credito(); const bool show_games = is_pagamento() || nota_credito; - TSheet_field& cgsheet = m->sfield(F_SHEETCG); + TSheet_field& cgsheet = cgs(); TMask& cgm = cgsheet.sheet_mask(); - cgm.set_handler(DLG_USER, show_games ? showpartite_handler : NULL); // bottoncino riga + + cgm.set_handler(DLG_USER, show_games ? showpartite_handler : nullptr); // bottoncino riga cgm.enable(DLG_USER, show_games); if (iva == nessuna_iva) { @@ -394,12 +394,15 @@ bool TPrimanota_application::read_caus(const char* cod, int year) TRegistro& r = c.reg(); const bool reg_vendite = r.iva() == iva_vendite && !r.corrispettivi(); - const bool show_notevar = iva == iva_vendite || iva == iva_acquisti; - TSheet_field& ivasheet = m->sfield(F_SHEETIVA); + const bool show_notevar = iva == iva_vendite || iva == iva_acquisti; + const bool show_active_revcharge = iva == iva_acquisti && causale().reverse_charge_pubb(); + TSheet_field& ivasheet = m->sfield(F_SHEETIVA); ivasheet.enable_column(IVA_NOTAVARECF, show_notevar); ivasheet.sheet_mask().enable(IVA_NOTAVARECF, show_notevar); - } + ivasheet.enable_column(IVA_REVCHARGE, show_active_revcharge); + ivasheet.sheet_mask().enable(IVA_REVCHARGE, show_active_revcharge); + } if (ins && !ci_sono_importi(cgsheet)) { @@ -407,7 +410,8 @@ bool TPrimanota_application::read_caus(const char* cod, int year) for (int i = 1; i < causale().size(); i++) { const TRectype* rcaus = (TRectype*)causale().objptr(i); - if (rcaus == NULL) continue; // Evita eventuali righe nulle + + if (rcaus == nullptr) continue; // Evita eventuali righe nulle const int nriga = rcaus->get_int(RCA_NRIGA); if (nriga <= 0) continue; // Considera solo righe reali (non riempimenti) @@ -593,7 +597,7 @@ void TPrimanota_application::on_config_change() TConfig cnf(CONFIG_DITTA, "cg"); _ges_val = cnf.get_bool("GesVal"); _ges_sal = cnf.get_bool("GesSal"); - _easy_sal = _ges_sal && cnf.get_bool("EasySal", NULL, -1, false) && xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_VERSION_YEAR) > 2101; + _easy_sal = _ges_sal && cnf.get_bool("EasySal", nullptr, -1, false) && xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_VERSION_YEAR) > 2101; _npart_is_prot = cnf.get_bool("RifPro"); _npart_is_month = cnf.get_bool("RifMonth"); @@ -614,7 +618,7 @@ void TPrimanota_application::init_mask(TMask& m) disable_menu_item(M_FILE_PRINT); disable_menu_item(M_FONT); - read_caus(NULL, 0); // Setta campi obbligatori + read_caus(nullptr, 0); // Setta campi obbligatori if (_iva == nessuna_iva) { @@ -657,7 +661,8 @@ void TPrimanota_application::init_mask(TMask& m) if (is_fattura()) { const TPartita* game = partite().first(); - _scad_free = game == NULL || !game->esistono_abbuoni_diffcam(m.get_long(F_NUMREG)); + + _scad_free = game == nullptr || !game->esistono_abbuoni_diffcam(m.get_long(F_NUMREG)); if (m.edit_mode() && !_scad_free) m.enable(DLG_DELREC, _scad_free); // Disabilita tasto elimina m.enable(-1, _scad_free); // Disabilita cliente @@ -675,30 +680,21 @@ void TPrimanota_application::init_mask(TMask& m) m.show(F_ADJUST_IVA, _quadratura); - TMask_field* ixc = m.find_by_id(F_IVAXCASSA); - if (ixc) - { - const TDate dr = m.get(F_DATAREG); - ixc->show(gestione_IVAxCassa(dr)); - } + const TDate dr = m.get(F_DATAREG); - TEdit_field& rc = m.efield(F_REVCHARGE); - rc.show(cc.iva() == iva_acquisti && cc.reverse_charge_pubb()); - - m.efield(F_MOVCOLL).show((cc.iva() == iva_acquisti && cc.reverse_charge_pubb()) || - (cc.iva() == iva_vendite && cc.causale_reg_iva())); - // m.efield(F_GOCOLL).show((c.iva() == iva_acquisti && c.reverse_charge()) || - // (c.iva() == iva_vendite && c.causale_reg_iva())); + m.show(F_IVAXCASSA, gestione_IVAxCassa(dr)); + m.show(F_REVCHARGE, cc.iva() == iva_acquisti && cc.reverse_charge_pubb()); + m.show(F_MOVCOLL, (cc.iva() == iva_acquisti && cc.reverse_charge_pubb()) || + (cc.iva() == iva_vendite && cc.causale_reg_iva())); activate_split_payment(m); } // Show/Hide campi valuta: F_VALUTA, F_CAMBIO, F_DATACAMBIO (GROUP 3) const bool valuta = _ges_val && is_saldaconto() && causale().valuta(); + m.show(-3, valuta); _sal_dirty = false; // Azzero il flag di modifica del saldaconto - fill_sheet(m); // Riempe righe contabili coi conti della causale - m.hide(F_LINKDOC); set_has_f1_db(&m); } @@ -881,15 +877,16 @@ bool TPrimanota_application::get_next_key(TToken_string& tmp) void TPrimanota_application::init_insert_mode(TMask& m) { - init_mask(m); + init_mask(m); m.first_focus(_firstfocus); if (causale().reg().agenzia_viaggi()) m.set(F_DATA74TER, m.get(F_DATAREG)); - if (iva() != nessuna_iva) + + if (iva() != nessuna_iva) { - occas_mask().reset(); + occas_mask().reset(); m.hide(F_OCCASEDIT); const TString & tipo = clifo(); @@ -927,19 +924,21 @@ void TPrimanota_application::init_insert_mode(TMask& m) if (is_fattura()) { activate_numrif(m, false); + const TString& dt = m.get(F_DATADOC); - set_pagamento(NULL,dt); + + set_pagamento(nullptr, dt); set_scadenze(m); } else { - set_pagamento(NULL,NULL); // Annulla gestione rate + set_pagamento(nullptr, nullptr); // Annulla gestione rate } _saldi.reset(); // Inizializza saldi if (_automatico->_step == 1) - genera_automatico(_automatico->_tipo, NULL); + genera_automatico(_automatico->_tipo, nullptr); else { m.reset(F_DATACOMP); // Azzera quasi sempre la data di competenza @@ -990,7 +989,7 @@ void TPrimanota_application::init_insert_mode(TMask& m) m.set(F_PROTIVA, protiva, true); // Aggiorna protocollo IVA } // Controllo se abilitare il fornitore per bolla doganale - if(m.find_by_id(F_BOLLACODCLI) != NULL) + if(m.find_by_id(F_BOLLACODCLI) != nullptr) { m.enable(F_BOLLACODCLI, causale().tipo_doc() == "BD"); m.enable(F_BOLLARAGCLI, causale().tipo_doc() == "BD"); @@ -1000,13 +999,15 @@ void TPrimanota_application::init_insert_mode(TMask& m) void TPrimanota_application::f1_init_modify(TMask& m, const TRectype& mov) { const bool after_data_inizio_fe = TDate(mov.get(MOV_DATADOC)) >= TDate(fp_settings().get_data_start_fatt()); - if (m.find_by_id(F_COLFPPRO) != NULL && after_data_inizio_fe) + + if (m.find_by_id(F_COLFPPRO) != nullptr && after_data_inizio_fe) m.set(F_COLFPPRO, mov.get(MOV_KEYFPPRO).empty() ? " " : "X"); - else if(m.find_by_id(F_COLFPPRO) != NULL && !after_data_inizio_fe) - { - m.field(F_COLFPPRO).hide(); - m.field(DLG_LINK).disable(); - } + else + if(m.find_by_id(F_COLFPPRO) != nullptr && !after_data_inizio_fe) + { + m.field(F_COLFPPRO).hide(); + m.field(DLG_LINK).disable(); + } } void TPrimanota_application::init_modify_mode(TMask& m) @@ -1051,40 +1052,40 @@ void TPrimanota_application::init_modify_mode(TMask& m) m.field(F_RITFIS).set_prompt("IVA intracomun. "); else m.field(F_RITFIS).set_prompt("Ritenute fiscali "); +#ifdef PRORATA100 + // Non controllare il prorata durante la cancellazione automatica + if (autodeleting() != 0x3) + { + if (!test_prorata()) // Controlla prorata + { + m.show(F_ADJUST_PRORATA); + m.set_handler(F_ADJUST_PRORATA, prorata_handler); + + warning_box(TR("Questo movimento è stato registrato con una percentuale\n" + "prorata non compatibile con quella corrente:\n" + "Premere il bottone di correzione automatica delle righe.")); + } + else + { + // Nascondi il bottone del prorata se esiste + if (m.id2pos(F_ADJUST_PRORATA) >= 0) + { + m.set_handler(F_ADJUST_PRORATA, nullptr); + m.hide(F_ADJUST_PRORATA); + } + } + } +#endif } if (_as400 && is_pagamento()) { m.set(SK_TIPORIGA, "A"); // Forza il tipo riga normale m.disable(SK_TIPORIGA); // Disabilita la sua modifica } - - #ifdef PRORATA100 - // Non controllare il prorata durante la cancellazione automatica - if (autodeleting() != 0x3) - { - if (!test_prorata()) // Controlla prorata - { - m.show(F_ADJUST_PRORATA); - m.set_handler(F_ADJUST_PRORATA, prorata_handler); - - warning_box(TR("Questo movimento è stato registrato con una percentuale\n" - "prorata non compatibile con quella corrente:\n" - "Premere il bottone di correzione automatica delle righe.")); - } - else - { - // Nascondi il bottone del prorata se esiste - if (m.id2pos(F_ADJUST_PRORATA) >= 0) - { - m.set_handler(F_ADJUST_PRORATA, NULL); - m.hide(F_ADJUST_PRORATA); - } - } - } -#endif - + const TRectype& mov = get_relation()->curr(); - if (!mov.empty()) + + if (!mov.empty()) { if (navigating()) { @@ -1109,7 +1110,7 @@ void TPrimanota_application::init_modify_mode(TMask& m) activate_split_payment(m); } // Controllo se abilitare il fornitore per bolla doganale - if(m.find_by_id(F_BOLLACODCLI) != NULL) + if(m.find_by_id(F_BOLLACODCLI) != nullptr) { m.enable(F_BOLLACODCLI, causale().tipo_doc() == "BD"); m.enable(F_BOLLARAGCLI, causale().tipo_doc() == "BD"); @@ -1133,9 +1134,10 @@ void TPrimanota_application::add_cup_or_cig(short id, const TRectype& rec, TToke const TString& cod = rec.get(cup ? RMV_CUP : RMV_CIG); if (cod.full()) { - riga.add(cod, id-FIRST_FIELD); // Tipo di riga 115 o 117 - const TString& desc = cache().get(cup ? "%CUP" : "%CIG", cod, "S0"); - riga.add(desc, (cup ? CG_DCUP : CG_DCIG) - FIRST_FIELD); + const TString& desc = cache().get(cup ? "%CUP" : "%CIG", cod, "S0"); + + riga.add(cod, cid2index(id)); // Tipo di riga 115 o 117 + riga.add(desc, cid2index(cup ? CG_DCUP : CG_DCIG)); } } @@ -1145,9 +1147,10 @@ void TPrimanota_application::add_cup_or_cig(short id, TConfig& ini, TToken_strin const TString& cod = ini.get(cup ? RMV_CUP : RMV_CIG); if (cod.full()) { - riga.add(cod, id-FIRST_FIELD); // Tipo di riga 115 o 117 - const TString& desc = cache().get(cup ? "%CUP" : "%CIG", cod, "S0"); - riga.add(desc, (cup ? CG_DCUP : CG_DCIG) - FIRST_FIELD); + const TString& desc = cache().get(cup ? "%CUP" : "%CIG", cod, "S0"); + + riga.add(cod, cid2index(id)); // Tipo di riga 115 o 117 + riga.add(desc, cid2index(cup ? CG_DCUP : CG_DCIG)); } } @@ -1208,7 +1211,7 @@ int TPrimanota_application::read(TMask& m) add_cup_or_cig(CG_CIG, r, riga); // CIG 117-118 const char tipo = r.get_char(RMV_ROWTYPE); - riga.add(tipo, CG_ROWTYPE-FIRST_FIELD); // Tipo di riga 119 + riga.add(tipo, cid2index(CG_ROWTYPE)); // Tipo di riga 119 disable_cgs_cells(i, tipo); //cgs().check_row(i); // Fare le decodifche a mano: NON USARE! @@ -1220,7 +1223,7 @@ int TPrimanota_application::read(TMask& m) if (!read_scadenze(m)) // Se non esiste fattura { const TString& dd = m.get(F_DATADOC); - set_pagamento(NULL, dd); // Ignora codice pagamento in testata + set_pagamento(nullptr, dd); // Ignora codice pagamento in testata } } @@ -1241,7 +1244,8 @@ int TPrimanota_application::read(TMask& m) } const bool to_swap = test_swap(false); - if (to_swap) + + if (to_swap) { real totdoc(m.get(F_TOTALE)); totdoc = -totdoc; @@ -1271,19 +1275,21 @@ int TPrimanota_application::read(TMask& m) TBill c; c.get(r); c.add_to(riga, 4, 0x7); // Conto 105-110 riga.add(r.get(RMI_NAVP), cid2index(IVA_NOTAVARECF)); + riga.add(r.get(RMI_REVCHARGE), cid2index(IVA_REVCHARGE)); } - calcola_imp(); // Calcola totale imponibile ed imposte - - if (is_fattura()) // Ci dovrebbero essere delle scadenze + ivas().update_original_rows(); + if (is_fattura()) // Ci dovrebbero essere delle scadenze { pags().reset(); // Azzera sheet rate if (!read_scadenze(m)) // Se non esiste fattura { const TString& dd = m.get(F_DATADOC); - set_pagamento(NULL, dd); // Ignora codice pagamento in testata + + set_pagamento(nullptr, dd); // Ignora codice pagamento in testata } } + return _rel->status(); } @@ -1355,10 +1361,10 @@ void TPrimanota_application::mask2rel(const TMask& m) r.put(RMV_CONTOC, row.get()); r.put(RMV_SOTTOCONTOC, row.get()); - r.put(RMV_CUP, row.get(CG_CUP-FIRST_FIELD)); // CUP - r.put(RMV_CIG, row.get(CG_CIG-FIRST_FIELD)); // CIG + r.put(RMV_CUP, row.get(cid2index(CG_CUP))); // CUP + r.put(RMV_CIG, row.get(cid2index(CG_CIG))); // CIG - r.put(RMV_ROWTYPE, row.get(CG_ROWTYPE-FIRST_FIELD)); // Tipo riga + r.put(RMV_ROWTYPE, row.get(cid2index(CG_ROWTYPE))); // Tipo riga } } @@ -1434,25 +1440,26 @@ void TPrimanota_application::mask2rel(const TMask& m) r.put(RMI_ANNOES, annoes); // Anno d'esercizio della testata (che ca$$ata!) r.put(RMI_INTRA, intra); // Causale intra (che ca$$ata!) - real imponibile(row.get(0)); + real imponibile(row.get(cid2index(IVA_IMPONIBILE))); if (to_swap) imponibile = -imponibile; r.put(RMI_IMPONIBILE, imponibile); - r.put(RMI_CODIVA, row.get()); - r.put(RMI_TIPODET, row.get()); + r.put(RMI_CODIVA, row.get(cid2index(IVA_CODIVA))); + r.put(RMI_TIPODET, row.get(cid2index(IVA_INDETRAIBILE))); - real imposta(row.get()); + real imposta(row.get(cid2index(IVA_IMPOSTA))); if (to_swap) imposta = -imposta; r.put(RMI_IMPOSTA, imposta); - r.put(RMI_TIPOCR, row.get()); + r.put(RMI_TIPOCR, row.get(cid2index(IVA_TIPOCOSTORIC))); // Roba obsoleta allo stato brado - const TBill c(row, 6); + const TBill c(row, cid2index(IVA_TIPO), 0x1); const int rimp = bill2pos(c, 'I')+1; r.put(RMI_RIGAIMP, rimp); c.put(r); - r.put(RMI_NAVP, row.get(10)); + r.put(RMI_NAVP, row.get(cid2index(IVA_NOTAVARECF))); + r.put(RMI_REVCHARGE, row.get(cid2index(IVA_REVCHARGE))); } } @@ -1479,13 +1486,13 @@ void TPrimanota_application::check_saldi() void TPrimanota_application::write_fppro() { - // Controllo se la registrazione ha avuto effetto anche su FPPRO allora salvo riferimento sul mov - if (save_fppro() > 0 && !save_dbmov()) - message_box( - TString("ATTENZIONE:") << - " non è stato possibile salvare i riferimenti del documento in ingresso per questo movimento.\n" << - "Movimento registrato senza collegamento ai documenti in ingresso."); -} + // Controllo se la registrazione ha avuto effetto anche su FPPRO allora salvo riferimento sul mov + if (save_fppro() > 0 && !save_dbmov()) + message_box( + TString("ATTENZIONE:") << + " non è stato possibile salvare i riferimenti del documento in ingresso per questo movimento.\n" << + "Movimento registrato senza collegamento ai documenti in ingresso."); + } bool TPrimanota_application::has_tot_doc(TToken_string& fppro_keys) { @@ -1539,27 +1546,28 @@ void TPrimanota_application::set_movcoll(const long movcoll, const long numreg) const int err = mov.rewrite(TLocalisamfile(LF_MOV)); } } -int TPrimanota_application::controlli_f1(const TMask& m){ - if (m.find_by_id(F_PROKEY) != NULL && m.get(F_PROKEY).full() && has_f1_db((TMask*)&m) && fp_db().sq_is_connect() && check_causale(m.get(F_CODCAUS))) - { - TToken_string keys(m.get(F_PROKEY), ';'); - const TDate dataoraric = fppro_db().set_keys(keys).get_dataorarioric(); - // Devo controllare che la data operazione sia maggiore della data ric - const TDate data_operazione(m.get(F_DATAREG)); - if (data_operazione < dataoraric) - return pro_dataric_err; - const int numreg = fppro_db().set_keys(keys).get_numregcont(); - if (numreg != 0 && numreg != m.get_int(F_NUMREG)) +int TPrimanota_application::controlli_f1(const TMask& m) +{ + if (m.find_by_id(F_PROKEY) != nullptr && m.get(F_PROKEY).full() && has_f1_db((TMask*)&m) && fp_db().sq_is_connect() && check_causale(m.get(F_CODCAUS))) { - const TDate data_documento(m.get(F_DATADOC)); - TString msg; msg << "Attenzione il documento " << data_documento.year() << " / " << m.get(F_NUMDOCEXT) << - " appena registrato e' gia' stato inserito con la registrazione numero " << numreg << - "\nSe si vuole registrare questo documento elettronico, scollegarlo prima dalla precedente registrazione."; - error_box(msg); - return pro_numreg_err; + TToken_string keys(m.get(F_PROKEY), ';'); + const TDate dataoraric = fppro_db().set_keys(keys).get_dataorarioric(); + // Devo controllare che la data operazione sia maggiore della data ric + const TDate data_operazione(m.get(F_DATAREG)); + if (data_operazione < dataoraric) + return pro_dataric_err; + const int numreg = fppro_db().set_keys(keys).get_numregcont(); + if (numreg != 0 && numreg != m.get_int(F_NUMREG)) + { + const TDate data_documento(m.get(F_DATADOC)); + TString msg; msg << "Attenzione il documento " << data_documento.year() << " / " << m.get(F_NUMDOCEXT) << + " appena registrato e' gia' stato inserito con la registrazione numero " << numreg << + "\nSe si vuole registrare questo documento elettronico, scollegarlo prima dalla precedente registrazione."; + error_box(msg); + return pro_numreg_err; + } } - } - //app().curr_mask().set(FS_RECALC, ""); + //app().curr_mask().set(FS_RECALC, ""); return pro_noerr; } @@ -1775,7 +1783,7 @@ void TPrimanota_application::clean_fppro() void TPrimanota_application::set_has_f1_db(TMask* m) { - if (m->find_by_id(F_DATAREG) != NULL && !m->get(F_DATAREG).empty()) + if (m->find_by_id(F_DATAREG) != nullptr && !m->get(F_DATAREG).empty()) { if (TDate(m->get(F_DATAREG)) >= TDate(fp_settings().get_data_start_fatt())) _isf1 = has_module(F1AUT) && !fp_settings().get_db_indirizzo().empty(); @@ -1856,11 +1864,26 @@ void TPrimanota_application::genera_automatico(int tipo, const char* causimm) // Solo regolarizzazioni IVA if (_automatico->_tipo == 2) { - _automatico->_totale += m.get_real(F_REVCHARGE) + m.get_real(F_RITFIS); + TSheet_field & iva = app().ivas(); + const int items = iva.items(); + _automatico->_movcoll = m.get_long(F_NUMREG); - _automatico->_codiva = m.get(F_CODIVA); - if (_automatico->_codiva.blank() && _rel->iva_items() > 0) - _automatico->_codiva = _rel->iva(0).get(RMI_CODIVA); + _automatico->_iva.destroy(); + _automatico->_totale = ZERO; + for (int i = 0; i < items; i++) + { + TToken_string row = iva.row(i); + + if (row.get_bool(cid2index(IVA_REVCHARGE))) + { + const real imponibile = row.get(cid2index(IVA_IMPONIBILE)); + const real imposta = row.get(cid2index(IVA_IMPOSTA)); + + row.add("", cid2index(IVA_REVCHARGE)); + _automatico->_totale += imponibile+imposta; + _automatico->_iva.add(row); + } + } } else if (_automatico->_tipo == 4) @@ -1934,9 +1957,18 @@ void TPrimanota_application::genera_automatico(int tipo, const char* causimm) const TString& clnt = cache().get(LF_CLIFO, forn, CLI_CODCFASS); m.set(F_CODCLIFOR, clnt); } + TSheet_field & iva = m.sfield(F_SHEETIVA); + const int items = _automatico->_iva.items(); + m.set(F_TOTALE, _automatico->_totale); // Imposta il totale documento e ... - m.set(F_MOVCOLL, _automatico->_movcoll); // Imposta il movimenti collegato e ... - m.set(F_CODIVA, _automatico->_codiva, true); // ... scatena creazione prima riga IVA + m.set(F_MOVCOLL, _automatico->_movcoll); // Imposta il movimenti collegato comp_han le righe iva + for (int i = 0; i < items; i++) + { + TToken_string & original_row = _automatico->_iva.row(i); + TToken_string & row = iva.row(i); + + row = original_row; + } if (TRelation_application::is_transaction()) m.send_key(K_CTRL+'R', 0); @@ -1948,9 +1980,11 @@ void TPrimanota_application::genera_automatico(int tipo, const char* causimm) m.set(F_DATACOMP, _automatico->_datadoc); TBill conto; caus.bill(1, conto); TBill contro; caus.bill(2, contro); - cgs().reset(); + cgs().reset(); + TToken_string& row1 = cgs().row(0); TImporto imp(caus.sezione_clifo(), _automatico->_totale); + imp.add_to(row1, 0); row1.add(conto.string(0x3)); row1.add(" "); @@ -1958,6 +1992,7 @@ void TPrimanota_application::genera_automatico(int tipo, const char* causimm) row1.add(contro.string(0x3)); TToken_string& row2 = cgs().row(1); + imp.swap_section(); imp.add_to(row2, 0); row2.add(contro.string(0x3)); @@ -2277,13 +2312,14 @@ void TPrimanota_application::ini2mask(TConfig& ini, TMask& msk, bool query) // Genera eventuali righe per ritenute fiscali e sociali const short frit[4] = { F_RITFIS, F_RITSOC, F_REVCHARGE, 0 }; const char trit[4] = { 'F', 'S', 'V', '\0' }; + + for (int i = 0; frit[i]; i++) { TEdit_field& ritfld = msk.efield(frit[i]); if (!ritfld.empty() && ritfld.active()) add_cgs_ritenute(trit[i]); } - calcola_imp(); // Calcola totale imponibile ed imposte } @@ -2302,7 +2338,7 @@ void TPrimanota_application::ini2mask(TConfig& ini, TMask& msk, bool query) { numrig = -1; // Normalmente aggiungi la riga in fondo // Cerca una riga che abbia già il tipo ed il conto richiesto - if (strchr(" DINT", tipo) != NULL) + if (strchr(" DINT", tipo) != nullptr) { int nr = -1; if (tipo == 'I' || tipo == ' ') @@ -2408,7 +2444,7 @@ void TPrimanota_application::ini2mask(TConfig& ini, TMask& msk, bool query) pagamento().set_sheet(pag); } } - if (_f1_ini && msk.find_by_id(FS_RECALC) != NULL) + if (_f1_ini && msk.find_by_id(FS_RECALC) != nullptr) { msk.set(F_COLFPPRO, "X"); if (scad_from_ini) @@ -2417,10 +2453,11 @@ void TPrimanota_application::ini2mask(TConfig& ini, TMask& msk, bool query) set_scad_f1(msk); } } - if (_f1_liq && msk.find_by_id(F_DIFFERITA) != NULL) + if (_f1_liq && msk.find_by_id(F_DIFFERITA) != nullptr) { TDate datadoc(msk.get(F_DATADOC)); datadoc.set_day(1); TDate datareg(msk.get(F_DATAREG)); datareg.set_day(1); + if(datadoc < datareg && (double)datadoc.year() == real(msk.get(F_ANNOIVA))) msk.set(F_DIFFERITA, "X"); } @@ -2571,7 +2608,8 @@ void TPrimanota_application::mask2ini(const TMask& msk, TConfig& ini) else { int pref = 1; - for (TPartita* game = p.first(); game != NULL; game = p.next()) + + for (TPartita* game = p.first(); game != nullptr; game = p.next()) { const int lastrow = game->last(); @@ -2814,7 +2852,7 @@ bool TPrimanota_application::link_intra(const TMask& m, const char* action) if (n > last_rett) last_rett = n; if (curr.get_long("NUMREG") == m.get_long(F_NUMREG)) - return curr.edit(0, NULL, "in0 -6"); + return curr.edit(0, nullptr, "in0 -6"); } intro.set("Action", "Insert"); @@ -2919,7 +2957,7 @@ bool TPrimanota_application::link_anal(const TMask& msk, const char* action) // Cerco se c'e' almeno un conto interessato all'analitica bool bAnalBill = false; - TSheet_field& sheet = msk.sfield(F_SHEETCG); + TSheet_field& sheet = cgs(); FOR_EACH_SHEET_ROW(sheet, i, row) { const TBill bill(*row, 3, 0x0); diff --git a/src/cg/cg2100.h b/src/cg/cg2100.h index aa93e8bca..4323a16f3 100755 --- a/src/cg/cg2100.h +++ b/src/cg/cg2100.h @@ -122,9 +122,15 @@ #define IVA_GRUPPO 107 #define IVA_CONTO 108 #define IVA_SOTTOCONTO 109 +#define IVA_CLIENTE 209 +#define IVA_FORNITORE 309 +#define IVA_DESCRCONTO 110 +#define IVA_DESCRCONTOC 210 +#define IVA_DESCRCONTOF 310 #define IVA_PERCIVA 111 #define IVA_NATURIVA 112 #define IVA_NOTAVARECF 113 +#define IVA_REVCHARGE 114 // Campi ripetuti sulla seconda pagina #define H_DATAREG 201 diff --git a/src/cg/cg2100c.uml b/src/cg/cg2100c.uml index 1d8605a1c..2de62fd68 100755 --- a/src/cg/cg2100c.uml +++ b/src/cg/cg2100c.uml @@ -554,13 +554,6 @@ BEGIN FLAGS "U#" END -DATE F_DATAINC -BEGIN - PROMPT 52 19 "Data incasso " - WARNING "Data di incasso per liquidazione differita" - FIELD DATAINC -END - BOOLEAN F_COLFPPRO BEGIN PROMPT 1 19 "Registrazione collegata a FPPRO" @@ -571,8 +564,8 @@ STRING F_PROKEY 80 BEGIN PROMPT 1 19 "db key" HELP "Chiave database" - FIELD KEYFPPRO - FLAGS "H" + FIELD KEYFPPRO + FLAGS "H" END BOOLEAN F_IVAXCASSA @@ -582,7 +575,6 @@ BEGIN MODULE IC END - BOOLEAN F_LIQDIFF BEGIN PROMPT 25 20 "Liquidazione differita" @@ -593,9 +585,16 @@ BEGIN FLAGS "HG" END +DATE F_DATAINC +BEGIN + PROMPT 52 20 "Data incasso " + WARNING "Data di incasso per liquidazione differita" + FIELD DATAINC +END + LIST F_SPLITPAY 1 2 BEGIN - PROMPT 51 20 "Scissione pagamenti " + PROMPT 51 21 "Scissione pagamenti " FIELD SPLITPAY ITEM "| " ITEM "S|Si" @@ -604,7 +603,7 @@ END STRING F_VALUTAINTRA 3 BEGIN - PROMPT 1 21 "Cambio intracom. " + PROMPT 1 22 "Cambio intracom. " FIELD CODVALI FLAGS "UZ" GROUP 4 @@ -631,20 +630,20 @@ END DATE F_DATAINTRA BEGIN - PROMPT 43 21 "Data competenza intra " + PROMPT 43 22 "Data competenza intra " FIELD DATACOMPI END CURRENCY F_CORRISPETTIVO 18 BEGIN - PROMPT 1 22 "Corrispettivo " + PROMPT 1 23 "Corrispettivo " FIELD CORRLIRE GROUP 4 END CURRENCY F_CORRVALUTA 18 BEGIN - PROMPT 39 22 "Corrispet. valuta " + PROMPT 39 23 "Corrispet. valuta " FIELD CORRVALUTA GROUP 4 VALIDATE REQIF_FUNC 1 F_VALUTAINTRA @@ -653,20 +652,13 @@ END BOOLEAN F_RITFATT BEGIN - PROMPT 1 23 "Fattura in ritardo " + PROMPT 1 24 "Fattura in ritardo " FIELD RITFATT END -#ifdef PRORATA100 -BUTTON F_ADJUST_PRORATA 40 -BEGIN - PROMPT 1 -1 "Corre~zione automatica righe contabili" - FLAGS "H" -END -#endif STRING NP_CONTSEP 6 BEGIN - PROMPT 1 23 "Cont. separata " + PROMPT 1 24 "Cont. separata " USE &NPENT INPUT CODTAB NP_CONTSEP DISPLAY "Codice@6" CODTAB @@ -688,6 +680,14 @@ BEGIN CHECKTYPE NORMAL END +#ifdef PRORATA100 +BUTTON F_ADJUST_PRORATA 40 +BEGIN + PROMPT 1 -1 "Corre~zione automatica righe contabili" + FLAGS "H" +END +#endif + ENDPAGE PAGE "IVA" -1 -1 77 20 @@ -745,8 +745,10 @@ BEGIN ITEM "Co." ITEM "Sottoc.@6" ITEM "Descrizione Conto@50" - ITEM "%IVA@5" - ITEM "Natura@5" + ITEM "%IVA@5" + ITEM "Natura@5" + ITEM "Nota.Var.@9" + ITEM "Reverse Charge@13" END CURRENCY F_IMPONIBILI 18 diff --git a/src/cg/cg2101.cpp b/src/cg/cg2101.cpp index eb8c2ff88..c978e4f19 100755 --- a/src/cg/cg2101.cpp +++ b/src/cg/cg2101.cpp @@ -51,6 +51,45 @@ void TMovimentoPN::destroy_iva_row(int i) _iva.destroy_row(i+1, true); } +void TMovimentoPN::update_rev_charge() +{ + const int year = lfile().get_int(MOV_ANNOIVA); + const TString & codcaus = lfile().get(MOV_CODCAUS); + const TCausale & caus = cached_causale(codcaus, year); + const TipoIVA t = caus.iva(); + + if (t == iva_acquisti) + { + const bool rev_charge = caus.reverse_charge_pubb(); + + if (rev_charge) + { + int rows = _iva.rows(); + real imp_revcharge; + bool has_revcharge = false; + + for (int i = _iva.first_row(); !has_revcharge && i <= rows; i = _iva.succ_row(i)) + { + has_revcharge |= _iva[i].get_bool(RMI_REVCHARGE); + imp_revcharge += _iva[i].get_real(RMI_IMPOSTA); + } + if (!has_revcharge) + { + TRectype & h = head(); + + if (h.get_real(MOV_REVCHARGE) <= ZERO) + { + h.put(MOV_REVCHARGE, imp_revcharge); + h.sub(MOV_RITFIS, imp_revcharge); + if (h.get_real(MOV_RITFIS) < ZERO) + h.zero(MOV_RITFIS); + } + for (int i = _iva.first_row(); i <= rows; i = _iva.succ_row(i)) + _iva[i].put(RMI_REVCHARGE, true); + } + } + } +} int TMovimentoPN::read_mov_rows() { const TRectype& mov = curr(); @@ -63,7 +102,7 @@ int TMovimentoPN::read_mov_rows() TRectype* ivafilter = new TRectype(LF_RMOVIVA); ivafilter->put(RMI_NUMREG, numreg); _iva.read(ivafilter); - + update_rev_charge(); _old_iva = _iva; /* if (_cg.rows() > 0 && _iva.rows() > 0 && cg(0).get_char(RMV_ROWTYPE) != 'T') @@ -85,9 +124,8 @@ int TMovimentoPN::read(TIsamop op, TReclock lockop) _olddataliq.set_day(1); // Evita problemi coi mesi corti! _olddataliq.set_month(meseliq); } - read_mov_rows(); // Riempie i due record array - } + } return err; } @@ -225,6 +263,7 @@ int TMovimentoPN::registra(bool re, bool force) TRegistro registro(reg, annoiva); const bool att_mista = reg.empty() ? false : registro.attivita_mista(); + update_rev_charge(); for (int i = 0 ; i < iva_items(); i++) { TRectype& r = iva(i); @@ -298,7 +337,7 @@ int TMovimentoPN::registra(bool re, bool force) const int npart = partarray.items(); - for (TPartita * part = partarray.first(); !reset && part != NULL; part = partarray.next()) + for (TPartita * part = partarray.first(); !reset && part != nullptr; part = partarray.next()) { const int nrpart = part->last(); @@ -381,11 +420,12 @@ bool TConti_array::add(const TBill& conto, const real& importo) { const char* key = conto.string(); real* imp = (real*)objptr(key); - if (imp == NULL) + + if (imp == nullptr) TAssoc_array::add(key, importo); else *imp += importo; - return imp != NULL; + return imp != nullptr; } real TConti_array::importo(const TBill& conto) @@ -403,17 +443,19 @@ bool TConti_array::remove(const TBill& conto) bool TConti_array::add_iva(bool det, const real& importo) { - real* imp = NULL; + real* imp = nullptr; + if (!importo.is_zero()) { const char* const key = det ? "D" : "N"; + imp = (real*)objptr(key); - if (imp == NULL) + if (imp == nullptr) TAssoc_array::add(key, importo); else *imp += importo; } - return imp != NULL; + return imp != nullptr; } real TConti_array::importo_iva(bool det) diff --git a/src/cg/cg2101.h b/src/cg/cg2101.h index d066b18e0..ce079851d 100755 --- a/src/cg/cg2101.h +++ b/src/cg/cg2101.h @@ -46,6 +46,7 @@ protected: int registra(bool re, bool force); int read_mov_rows(); + void update_rev_charge(); // @END @@ -68,6 +69,7 @@ public: TRecord_array& iva_rows() { return _iva; } TRectype& cg(int i); TRectype& iva(int i); + TRectype & head() { return lfile().curr(); } int cg_items() const { return _cg.rows(); } int iva_items() const { return _iva.rows(); } void destroy_rows(long numreg); diff --git a/src/cg/cg2102.cpp b/src/cg/cg2102.cpp index 4afd90b1b..476aad3f1 100755 --- a/src/cg/cg2102.cpp +++ b/src/cg/cg2102.cpp @@ -30,9 +30,10 @@ char TPrimanota_application::row_type(const TToken_string& s) { char t = ' '; + if (s.full()) { - s.get(CG_ROWTYPE%DLG_USER-1, t); // Can't use cgs().cid2index() here! + s.get(cid2index(CG_ROWTYPE), t); if (!((t >= 'A' && t <= 'Z')||((t >= '0' && t <= '9')))) // is not alphanumeric? t = ' '; } @@ -87,30 +88,21 @@ real TPrimanota_application::scorpora(real& imponibile, const real& percent) real TPrimanota_application::totale_documento() { const TMask& m = curr_mask(); - real tot = m.get(F_TOTALE); // Legge totale - const real ritfis = m.get(F_RITFIS); - tot += ritfis; // Somma ritenute fiscali - - TEdit_field& rc = m.efield(F_REVCHARGE); - if (rc.active()) - { - const real revcha = rc.get(); - tot += revcha; // Somma eventuale reverse charge - } - - const real ritsoc = m.get(F_RITSOC); - if (!ritsoc.is_zero()) - { - const bool swapt = test_swap(false); // Totale invertito ? - const bool swaps = test_swap(true); // Ritenute sociali invertite ? - if (swapt ^ swaps) // Somma ritenute sociali con segno - tot -= ritsoc; - else - tot += ritsoc; - } + tot += m.get_real(F_RITFIS); // Somma ritenute fiscali +// tot += m.get_real(F_REVCHARGE); // Somma eventuale reverse charge + const real ritsoc = m.get_real(F_RITSOC); + if (!ritsoc.is_zero()) + { + const bool swapt = test_swap(false); // Totale invertito ? + const bool swaps = test_swap(true); // Ritenute sociali invertite ? + if (swapt ^ swaps) // Somma ritenute sociali con segno + tot -= ritsoc; + else + tot += ritsoc; + } return tot; } @@ -144,6 +136,7 @@ bool TPrimanota_application::suspended_handler(TMask_field& f, KEY k) int TPrimanota_application::type2pos(char tipo) { TString_array& a = app().cgs().rows_array(); + FOR_EACH_ARRAY_ROW(a, i, s) { const char t = row_type(*s); @@ -160,9 +153,11 @@ int TPrimanota_application::bill2pos(const TBill& conto, char tipo) FOR_EACH_ARRAY_ROW(a, i, s) { const char t = row_type(*s); + if (t == tipo) { const TBill c(*s, 3, 0x0); + if (c == conto) return i; } @@ -256,6 +251,7 @@ TImporto TPrimanota_application::get_cgs_imp(int n) const bool TPrimanota_application::add_cgs_imp(int n, const TImporto& imp) { TImporto tot(get_cgs_imp(n)); + tot += imp; tot.normalize(); set_cgs_imp(n, tot); @@ -350,7 +346,7 @@ void TPrimanota_application::disable_cgs_cells(int n, char tipo) if (first == 0) { for (short cc = CG_CUP; cc <= CG_DCIG; cc++) - cg.disable_cell(n, cc - FIRST_FIELD); + cg.disable_cell(n, cid2index(cc)); } needs_update = true; } @@ -374,22 +370,23 @@ void TPrimanota_application::reset_sheet_row(TSheet_field& s, int n) } int TPrimanota_application::set_cgs_row(int n, const TImporto& imp, - TBill& conto, const char* desc, + const TBill& conto, const char* desc, char tipo, const char* cms, const char* fas) { TSheet_field& cg = cgs(); if (n < 0) n = cg.first_empty(); TToken_string& row = cg.row(n); + row.cut(0); imp.add_to(row, 0); row.add(conto.string(0x3)); row.add(""); // Codice decrizione row.add(desc); // Descrizione aggiuntiva - if (tipo == 'T') // Calcolo contropartita { - TToken_string& irow = ivas().row(0); + TToken_string & irow = ivas().row(0); TBill contro(irow, 5, 0x3); + if (contro.ok()) // Errore MI3599 row.add(contro.string(0x3)); else @@ -398,6 +395,7 @@ int TPrimanota_application::set_cgs_row(int n, const TImporto& imp, else { const int pos = type2pos('T'); + if (pos >= 0) { TBill contro(cg.row(pos), 2, 0x3); @@ -408,7 +406,7 @@ int TPrimanota_application::set_cgs_row(int n, const TImporto& imp, row.add(" | | | | "); } - row.add(tipo, CG_ROWTYPE-FIRST_FIELD); + row.add(tipo, cid2index(CG_ROWTYPE)); disable_cgs_cells(n, tipo); @@ -432,13 +430,15 @@ HIDDEN int compare_rows(const TSortable& o1, const TSortable& o2, void* jolly) HIDDEN bool can_remove(TToken_string& s) { const char* dare = s.get(0); - bool yes = dare == NULL ; + + bool yes = dare == nullptr; if (!yes) { if (*dare == '\0' || *dare == ' ' || strcmp(dare,"0") == 0) { const char* avere = s.get(); - yes = (avere == NULL || *avere == '\0' || *avere == ' ' || strcmp(avere,"0") == 0); + + yes = (avere == nullptr || *avere == '\0' || *avere == ' ' || strcmp(avere,"0") == 0); } } return yes; @@ -510,8 +510,9 @@ real TPrimanota_application::calcola_saldo() const bilancio += importo; if (pag) { - const char tipo = row_type(*r); - if (strchr("GK", tipo) != NULL) // Abbuoni attivi, differenze cambio, spese, ... // (A o P) Abbuoni e (C) Differenze cambio perchè c'erano ? non (T) totolae documento perchè pagamento + const char tipo = row_type(*r); + + if (strchr("GK", tipo) != nullptr) // Abbuoni attivi, differenze cambio, spese, ... // (A o P) Abbuoni e (C) Differenze cambio perchè c'erano ? non (T) totolae documento perchè pagamento saldaconto += importo; } } @@ -705,7 +706,7 @@ bool TPrimanota_application::cg_handler(TMask_field& f, KEY k) return false; } } - if (strchr("GKT", tipo) != NULL) // Abbuoni attivi, differenze cambio, spese, ... // (A o P) Abbuoni e (C) Differenze cambio perchè c'erano ? + if (strchr("GKT", tipo) != nullptr) // Abbuoni attivi, differenze cambio, spese, ... // (A o P) Abbuoni e (C) Differenze cambio perchè c'erano ? { saldaconto += importo; if (in_valuta) @@ -922,7 +923,7 @@ void TPrimanota_application::update_saldo_riga(int r) if (m.id2pos(F_SHEETCG) < 0) return; - TSheet_field& sheet = m.sfield(F_SHEETCG); + TSheet_field& sheet = cgs(); TToken_string row = sheet.row(r); TBill bill; bill.get(row, 2, 0x1); @@ -937,7 +938,8 @@ void TPrimanota_application::update_saldo_riga(int r) // Sottrae (somma algebricamente) il valore iniziale del conto const TConto* conto = _saldi.find(bill, annoes); - if (conto != NULL) + + if (conto != nullptr) { saldo += TImporto('D', conto->dare()); saldo += TImporto('A', conto->avere()); @@ -1067,6 +1069,7 @@ bool TPrimanota_application::cg_notify(TSheet_field& cg, int r, KEY k) if (tipo == 'G') { TImporto growth; growth = row; growth -= old_spesa; + if (!growth.is_zero()) { const int s = type2pos('L'); @@ -1285,7 +1288,6 @@ bool TPrimanota_application::imponibile_handler(TMask_field& f, KEY key) return true; } - // Gestione del codice IVA sullo sheet iva // Certified 90% bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key) @@ -1298,7 +1300,7 @@ bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key) TMask& m = f.mask(); const TCodiceIVA iva(f.get()); - if (m.get_int(107) == 0) + if (m.get_int(IVA_GRUPPO) == 0) { TBill b; app().IVA2bill(iva, b); @@ -1306,21 +1308,28 @@ bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key) m.set(105, *cr > '0' ? cr : ""); const char tipo[2] = { b.tipo(), '\0' }; - m.set(106, tipo); - m.set(107, b.gruppo()); - m.set(108, b.conto()); - const short id = b.tipo() == 'C' ? 209 : (b.tipo() == 'F' ? 309 : 109); + + m.set(IVA_TIPO, tipo); + m.set(IVA_GRUPPO, b.gruppo()); + m.set(IVA_CONTO, b.conto()); + const short id = b.tipo() == 'C' ? IVA_CLIENTE : (b.tipo() == 'F' ? IVA_FORNITORE : IVA_SOTTOCONTO); m.set(id, b.sottoconto()); m.set(id+1, b.descrizione()); } - - TString4 det; if (app().iva() == iva_acquisti) - det = iva.indetraibilita(); - m.set(103, det); + m.set(IVA_INDETRAIBILE, iva.indetraibilita()); + else + m.reset(IVA_INDETRAIBILE); + + TMask & main_mask = *app().mask(CGMaskType::_iva); + const int anno = main_mask.get_int(F_ANNOIVA); + const TString & codcaus = main_mask.get(F_CODCAUS); + + m.set(IVA_REVCHARGE, cached_causale(codcaus, anno).reverse_charge_pubb() && iva.reverse_charge_attivo() ? "X" : "", 0x03); - TMask_field& im = m.field(101); + TMask_field& im = m.field(IVA_IMPONIBILE); + im.set_dirty(); im.on_hit(); } @@ -1328,7 +1337,7 @@ bool TPrimanota_application::codiva_handler(TMask_field& f, KEY key) { if (key == K_ENTER) { - if (f.get().empty() && f.mask().get(101).not_empty()) + if (f.get().empty() && f.mask().get(IVA_IMPONIBILE).not_empty()) return f.error_box(TR("Codice IVA obbligatorio")); } } @@ -1406,10 +1415,12 @@ real TPrimanota_application::calcola_imp() const TArray& rows = ivas().rows_array(); real imponibili, imposte; + FOR_EACH_ARRAY_ROW(rows, r, row) if (!row->empty_items()) { - imponibili += real(row->get(0)); - imposte += real(row->get(3)); + imponibili += row->get_real(cid2index(IVA_IMPONIBILE)); + if (!row->get_bool(cid2index(IVA_REVCHARGE))) + imposte += row->get(cid2index(IVA_IMPOSTA)); } TMask& m = curr_mask(); @@ -1420,8 +1431,6 @@ real TPrimanota_application::calcola_imp() const if (is_fattura()) { real tot = m.get(F_TOTALE); - if (!m.efield(F_REVCHARGE).active()) - tot -= imposte; m.set(FS_IMPONIBILI, tot); m.set(FS_IMPOSTE, imposte); } @@ -1445,7 +1454,6 @@ void TPrimanota_application::ivas_pack() if (!imposta.is_zero()) continue; rows.destroy(i, false); } - rows.pack(); // Pack array } @@ -1468,302 +1476,255 @@ int TPrimanota_application::get_importi_iva(const TToken_string& row, const TCausale& caus = app().causale(); const TMovimentoPN& mov = (const TMovimentoPN&)*app().get_relation(); + return mov.analizza_riga_IVA(imptot, ivatot, caus, annodoc, zanicchi, codind, imp_det, iva_det, imp_ind, iva_ind); } -// Certified 50% -bool TPrimanota_application::iva_notify(TSheet_field& iva, int r, KEY k) +void TPrimanota_application::add2cg_row(TSheet_field& s, TToken_string & row, TString_array & saved_descr, const bool add) { - static int oldpos[2],oldposiva[2]; - static TImporto oldimp[2], oldiva[2]; - static bool selecting = false; + TPrimanota_application& a = app(); + const TCausale& cau = a.causale(); + const bool acquisto = (a.iva() == iva_acquisti); + const int last = acquisto ? 3 : 2; + const char tipi[3] = { 'N', 'D', 'V' }; + real imp_det, iva_det, imp_ind, iva_ind; + const bool revcharge = row.get_bool(cid2index(IVA_REVCHARGE)); + get_importi_iva(row, imp_det, iva_det, imp_ind, iva_ind); - TPrimanota_application& a = app(); - if (a._as400) - return true; - - if (k == K_INS || k == K_CTRL+K_DEL) - return true; - - TToken_string& row = iva.row(r); - const TCausale& cau = a.causale(); + for (int d = 0; d < last; d++) + { + const char tipod = tipi[d]; - if (k == K_TAB) - { - if (!selecting && row.empty_items()) - { - selecting = true; - iva.select(r, 1); // Vado alla prima colonna delle righe vuote - selecting = false; + if (d < 2) + { + const TBill conto(row, cid2index(IVA_TIPO), 0x1); + const int pos = bill2pos(conto, 'I'); // Riga in cui andra' l'imponibile + const TImporto imp = a.real2imp(d > 0 ? imp_det : imp_ind, tipod); // Imponibile - } - return true; - } + if (pos >= 0) // Se il conto esisteva anche prima ... + { + TImporto i(a.get_cgs_imp(pos)); - if (k == K_SPACE) - { - real imp_det, iva_det, imp_ind, iva_ind; - get_importi_iva(row, imp_det, iva_det, imp_ind, iva_ind); - for (int d = 0; d < 2; d++) - { - const char tipod = d ? 'D' : 'N'; - oldimp[d] = a.real2imp(d ? imp_det : imp_ind, 'I'); // Imponibile - oldiva[d] = a.real2imp(d ? iva_det : iva_ind, tipod); // Imposta - oldposiva[d] = type2pos(tipod); - if (oldposiva[d] < 0 && !oldiva[d].is_zero()) - { - TBill c; + if (add) + i += imp; + else + { + i -= imp; + saved_descr.add(a.cgs().row(pos).get(cid2index(CG_DESCR)), d); // Memorizza vecchia descrizionei += iva; + } + i.normalize(); + if (i.is_zero()) + a.reset_cgs_row(pos); + else + a.set_cgs_imp(pos, i); + } + else + { + if (add && conto.ok() && !imp.is_zero()) // Se c'e' imponibile ... + a.set_cgs_row(-1, imp, conto, (saved_descr.objptr(d) == nullptr || saved_descr.row(d).blank()) ? cau.desc_agg(2) : saved_descr.row(d), 'I'); + } + } + // Aggiorna conto IVA sulla riga contabile + const int posiva = type2pos(tipod); + real imposta(d > 0 ? iva_det : iva_ind); + + if (d == 2) + imposta = revcharge ? imposta : ZERO; + + TImporto iva = a.real2imp(imposta, tipod); // Imponibile + TImporto i(a.get_cgs_imp(posiva)); + + if (posiva >= 0) // Se conto IVA esisteva anche prima ... + { + if (add) + i += iva; + else + i -= iva; + i.normalize(); + if (i.is_zero()) + a.reset_cgs_row(posiva); + else + a.set_cgs_imp(posiva, i); + } + else + if (add & !iva.is_zero()) // Se c'e' imposta ... + { // ... crea nuova riga per l'IVA + TBill contoiva; int ri = 0; - if (d) - { - if (iva.mask().get_bool(F_LIQDIFF)) - cau.bill(ri = RIGA_IVA_DIFFERITA, c); else - if (iva.mask().get_bool(F_IVAXCASSA)) - cau.bill(ri = RIGA_IVA_PER_CASSA, c); - if (!c.ok()) - cau.bill(ri = RIGA_IVA_DETRAIBILE, c); + TMask & main_mask = s.mask(); + + if (d > 0) + { + if (d == 2 && revcharge) + cau.bill(ri = RIGA_REVERSE_CHARGE, contoiva); + else + { + if (main_mask.active(F_LIQDIFF) && main_mask.get_bool(F_LIQDIFF)) + cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); + else + if (main_mask.active(F_IVAXCASSA) && main_mask.get_bool(F_IVAXCASSA)) + cau.bill(ri = RIGA_IVA_PER_CASSA, contoiva); + if (!contoiva.ok()) + cau.bill(ri = RIGA_IVA_DETRAIBILE, contoiva); + } } else - cau.bill(ri = RIGA_IVA_NON_DETRAIBILE, c); - if (c.ok()) - { - const TString80 desc(cau.desc_agg(ri)); - oldposiva[d] = a.set_cgs_row(-1, a.real2imp(ZERO, 'I'), c, desc, tipod); - } - } - - TBill oldconto(row, 6); - if (oldconto.ok()) - { - oldpos[d] = bill2pos(oldconto, 'I'); - if (oldpos[d] < 0) - { - const TString desc(cau.desc_agg(2)); - oldpos[d] = a.set_cgs_row(-1, a.real2imp(ZERO, 'I'), oldconto, desc, 'I'); - } - } - else - oldpos[d] = -1; // Se il conto e' incompleto ignoralo - } - - } - if (k == K_DEL) // Cancellazione di una riga - { - row.add("0", 0); // Azzera imponibile - row.add("0", 3); // Azzera imposta - k = K_ENTER; // Elegante o Sporco trucco (dipende dai gusti!) - } - if (k == K_ENTER) - { - real imp_det, iva_det, imp_ind, iva_ind; - get_importi_iva(row, imp_det, iva_det, imp_ind, iva_ind); - for (int d = 0; d < 2; d++) - { - const real imponibile = d ? imp_det : imp_ind; - const real imposta = d ? iva_det : iva_ind; + cau.bill(ri = RIGA_IVA_NON_DETRAIBILE, contoiva); + a.set_cgs_row(-1, iva, contoiva, cau.desc_agg(ri), tipod); + } + } // for (int d = 0; d < 2; d++) +} - int delimp = -1, deliva = -1; // Eventuali righe contabili da cancellare - if (oldpos[d] >= 0) // Se il conto esisteva anche prima ... - { // sottrai il vecchio imponibile - TImporto i(a.get_cgs_imp(oldpos[d])); - i -= oldimp[d]; - i.normalize(); - a.set_cgs_imp(oldpos[d], i); - if (i.is_zero()) - delimp = oldpos[d]; - } - if (oldposiva[d] >= 0) // Se conto IVA esisteva anche prima ... - { // sottrai la vecchia imposta - TImporto i(a.get_cgs_imp(oldposiva[d])); - i -= oldiva[d]; - i.normalize(); - a.set_cgs_imp(oldposiva[d], i); - if (i.is_zero()) - deliva = oldposiva[d]; - } - - TBill conto(row, 6); - int newpos = bill2pos(conto, 'I'); // Riga in cui andra' l'imponibile - - TImporto newimp = a.real2imp(imponibile, 'I'); - newimp.normalize(); - - // Aggiorna conto sulla riga contabile - if (newpos < 0) - { - TString saved_descr; - if (delimp >= 0) - { - TSheet_field& s = a.cgs(); - saved_descr = s.row(delimp).get(8); // Memorizza vecchia descrizione - a.reset_cgs_row(delimp); // Cancella vecchia riga - if (deliva > delimp) deliva--; - } +bool TPrimanota_application::iva_notify(TSheet_field& s, int r, KEY k) +{ + static bool selecting = false; + TPrimanota_application& a = app(); - if (conto.ok() && !newimp.is_zero()) // Se c'e' imponibile ... - { // crea una nuova riga contabile - if (saved_descr.blank()) - saved_descr = cau.desc_agg(2); - newpos = a.set_cgs_row(-1, newimp, conto, saved_descr, 'I'); - } - } - else - { - const bool empty = a.add_cgs_imp(newpos, newimp); - if (empty) // Se la riga si e' azzerata ... - { // ... cancellala - a.reset_cgs_row(newpos); - newpos = -1; - } - else - { - if (delimp >= 0 && delimp != newpos) - { - a.reset_cgs_row(delimp); // Cancella vecchia riga - if (deliva > delimp) deliva--; - } - } - } - oldimp[d] = newimp; - oldpos[d] = newpos; - - // Aggiorna conto IVA sulla riga contabile + if (!a._as400) + { + TToken_string& row = s.row(r); + const TCausale& cau = a.causale(); - const char tipod = d ? 'D' : 'N'; - int newposiva = type2pos(tipod); - if (deliva >= 0 && newposiva != deliva) // E' cambiato il tipo d'imposta - a.reset_cgs_row(deliva); // Azzera il vecchio tipo se necessario - - TImporto newiva = a.real2imp(imposta, 'I'); - - newiva.normalize(); - if (newposiva < 0) - { - if (!imposta.is_zero()) // Se c'e' imposta ... - { // ... crea nuova riga per l'IVA - TBill contoiva; - int ri = 0; + if (k == K_TAB) + { + if (!selecting && row.empty_items()) + { + selecting = true; + s.select(r, 1); // Vado alla prima colonna delle righe vuote + selecting = false; - if (d) - { - if (iva.mask().get_bool(F_LIQDIFF)) - cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); else - if (iva.mask().get_bool(F_IVAXCASSA)) - cau.bill(ri = RIGA_IVA_PER_CASSA, contoiva); - if (!contoiva.ok()) - cau.bill(ri = RIGA_IVA_DETRAIBILE, contoiva); + } + return true; + } + + if (k == K_DEL) // Cancellazione di una riga + { + row.add("0", cid2index(IVA_IMPONIBILE)); // Azzera imponibile + row.add("0", cid2index(IVA_IMPOSTA)); // Azzera imposta + k = K_ENTER; // Elegante o Sporco trucco (dipende dai gusti!) + } + if (k == K_ENTER) + { + TToken_string& original_row = s.original_row(r); + TToken_string& row = s.row(r); + TString_array saved_descr; + + a.sub2cg_row(s, original_row, saved_descr); + a.add2cg_row(s, row, saved_descr); + + const bool acquisto_revcharge = (a.iva() == iva_acquisti) && (cau.reverse_charge_pubb()); + + if (acquisto_revcharge) + { + TImporto tot_revcharge; + const int posiva = type2pos('V'); + TEdit_field & revcharge = a.curr_mask().efield(F_REVCHARGE); + + if (posiva >= 0) + tot_revcharge = a.get_cgs_imp(posiva); + revcharge.set(tot_revcharge.valore().string()); + revcharge.on_hit(); + } + + // Controllo split-payment (dalla versione 12) + TMask& m = a.curr_mask(); + const TString4 tipocf(a.clifo()); + + if (m.get_int(F_ANNOIVA) >= 2015 && (tipocf == "C") && a.get_version() >= 12) + { + const int r_norm = type2pos('D'); + const bool split_needed = r_norm >= 0 && a.is_split_payment(); + + if (split_needed) + { + TImporto imp_split = a.get_cgs_imp(r_norm); + const int r_split1 = type2pos('1'); + + if (r_split1 < 0) + { + const int r_tot = max(0, type2pos('T')); + TToken_string row_tot = a.cgs().row(r_tot); + TBill cliente_split(row_tot, 2, 0x1); // Imposta anche tipo = Cliente + const char* desc = TR("IVA art.17-ter D.P.R. 633/1972"); + + a.set_cgs_row(-1, imp_split, cliente_split, desc, '1'); } else - cau.bill(ri = RIGA_IVA_NON_DETRAIBILE, contoiva); + a.set_cgs_imp(r_split1, imp_split); - const TString desc(cau.desc_agg(ri)); - cau.bill(ri, contoiva); - newposiva = a.set_cgs_row(-1, newiva, contoiva, desc, tipod); - } - } - else - { - const bool empty = a.add_cgs_imp(newposiva, newiva); - if (empty) // Se l'imposta si e' azzerata ... - { - a.reset_cgs_row(newposiva); // ... cancellala - newposiva = -1; - } - } + const int r_split2 = type2pos('2'); - oldiva[d] = newiva; - oldposiva[d] = newposiva; - - } // for (int d = 0; d < 2; d++) + imp_split.swap_section(); + if (r_split2 < 0) + { + TToken_string row_norm = a.cgs().row(r_norm); + TBill iva_split(row_norm, 3); + const char* desc = TR("IVA art.17-ter D.P.R. 633/1972"); - TMask& m = a.curr_mask(); + a.set_cgs_row(-1, imp_split, iva_split, desc, '2'); + } + else + a.set_cgs_imp(r_split2, imp_split); + } + else + { + const int r_split2 = type2pos('2'); - // Controllo split-payment (dalla versione 12) - const TString4 tipocf(a.clifo()); + if (r_split2 >= 0) + a.reset_cgs_row(r_split2); - if (m.get_int(F_ANNOIVA) >= 2015 && (tipocf == "C") && a.get_version() >= 12) - { - const int r_norm = type2pos('D'); - const bool split_needed = r_norm >= 0 && a.is_split_payment(); - if (split_needed) - { - TImporto imp_split = a.get_cgs_imp(r_norm); - const int r_split1 = type2pos('1'); - if (r_split1 < 0) - { - const int r_tot = max(0, type2pos('T')); - TToken_string row_tot = a.cgs().row(r_tot); - TBill cliente_split(row_tot, 2, 0x1); // Imposta anche tipo = Cliente - const char* desc = TR("IVA art.17-ter D.P.R. 633/1972"); - a.set_cgs_row(-1, imp_split, cliente_split, desc, '1'); - } - else - a.set_cgs_imp(r_split1, imp_split); - - const int r_split2 = type2pos('2'); - imp_split.swap_section(); - if (r_split2 < 0) - { - TToken_string row_norm = a.cgs().row(r_norm); - TBill iva_split(row_norm, 3); - const char* desc = TR("IVA art.17-ter D.P.R. 633/1972"); - a.set_cgs_row(-1, imp_split, iva_split, desc, '2'); - } - else - a.set_cgs_imp(r_split2, imp_split); - } - else - { - const int r_split2 = type2pos('2'); - if (r_split2 >= 0) - a.reset_cgs_row(r_split2); - const int r_split1 = type2pos('1'); - if (r_split1 >= 0) - a.reset_cgs_row(r_split1); - } - } - - if (r == 0) // Se cambio la prima riga ... - { - a.add_cgs_tot(m); // ... ricalcola conti e imponibili - } - else - { - a.calcola_saldo(); // Calcola sbilancio - a.calcola_imp(); // Calcola imponibili - } - - if (m.insert_mode() && a.is_fattura()) - { - TPagamento& pag = a.pagamento(); - const TValuta cambio(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); - const bool inv = cambio.in_valuta(); - real imposta, imponibile; - if (inv) - { - const real il = m.get(F_IMPOSTE); - imposta = cambio.eur2val(il); - imponibile = m.get_real(SK_TOTDOCVAL) - imposta; - } - else - { - imposta = m.get_real(F_IMPOSTE); - imponibile = m.get_real(F_TOTALE) - imposta; - } - imposta.round(pag.round(inv)); - imponibile.round(pag.round(inv)); - - real pimposta(pag.imposta(inv)); - pimposta.round(pag.round(inv)); - - real pimponibile(pag.imponibile(inv)); - pimponibile.round(pag.round(inv)); - - if ((pimposta != imposta || pimponibile != imponibile) && (!a._f1_ini && (a._pro_mask == nullptr || !a._pro_mask->should_bring_back()))) - a.set_scadenze(m); // Ricalcola rate - } - } + const int r_split1 = type2pos('1'); + + if (r_split1 >= 0) + a.reset_cgs_row(r_split1); + } + } + + if (r == 0) // Se cambio la prima riga ... + { + a.add_cgs_tot(m); // ... ricalcola conti e imponibili + } + else + { + a.calcola_saldo(); // Calcola sbilancio + a.calcola_imp(); // Calcola imponibili + } + + if (m.insert_mode() && a.is_fattura()) + { + TPagamento& pag = a.pagamento(); + const TValuta cambio(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); + const bool inv = cambio.in_valuta(); + real imposta, imponibile; + + if (inv) + { + const real il = m.get(F_IMPOSTE); + + imposta = cambio.eur2val(il); + imponibile = m.get_real(SK_TOTDOCVAL) - imposta; + } + else + { + imposta = m.get_real(F_IMPOSTE); + imponibile = m.get_real(F_TOTALE) - imposta; + } + imposta.round(pag.round(inv)); + imponibile.round(pag.round(inv)); + + real pimposta(pag.imposta(inv)); + + pimposta.round(pag.round(inv)); + + real pimponibile(pag.imponibile(inv)); + + pimponibile.round(pag.round(inv)); + if ((pimposta != imposta || pimponibile != imponibile) && (!a._f1_ini && (a._pro_mask == nullptr || !a._pro_mask->should_bring_back()))) + a.set_scadenze(m); // Ricalcola rate + } + } + } return true; } @@ -1775,6 +1736,7 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) if ((k == K_TAB && !f.mask().is_running()) || k == K_ENTER) { const TCurrency imp(app().calcola_imp()); + if (k == K_ENTER) { const TCurrency tot(app().totale_documento()); @@ -1782,6 +1744,7 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) { const TString t = tot.string(true); const TString i = imp.string(true); + return error_box(FR("La somma del totale documento e delle ritenute (%s) è diverso dalla " "somma degli imponibili e delle imposte (%s)"), (const char*)t, (const char*)i); @@ -1792,13 +1755,16 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) { TToken_string& row = iva.row(i); const real im(row.get(0)); + if (!im.is_zero()) { const TFixed_string codiva = row.get(1); + if (codiva.blank()) return error_box(FR("Il codice IVA della riga %d è obbligatorio"), i+1); TBill c(row, 5, 0x1); + if (!c.ok() || !c.find()) return error_box(FR("Il conto della riga iva %d è errato o incompleto"), i+1); } @@ -1816,6 +1782,7 @@ bool TPrimanota_application::cg_gruppo_handler(TMask_field& f, KEY key) { TEdit_field& conto = f.mask().efield(f.dlg()+1); const TRectype& curr = conto.browse()->cursor()->curr(); + if (curr.get(RMV_GRUPPO) != f.get()) // Se non e' gia' posizionato ... conto.check(RUNNING_CHECK); // ... forza ricerca sul conto } @@ -1829,6 +1796,7 @@ bool TPrimanota_application::cg_conto_handler(TMask_field& f, KEY key) if (key == K_ENTER) { TMask& m = f.mask(); + if (m.get(CG_ROWTYPE)[0] == 'T' && !app().causale().corrispettivi()) { const TString4 tipo = app().clifo(); // Tipo conto richiesto dal movimento @@ -1838,6 +1806,7 @@ bool TPrimanota_application::cg_conto_handler(TMask_field& f, KEY key) if (cf != tipo) // Incongruenza! { const char* d = tipo == "C" ? TR("clienti") : TR("fornitori"); + ok = f.error_box(FR("La riga totale richiede un conto %s."), d); } } @@ -1871,7 +1840,9 @@ bool TPrimanota_application::iva_sottoconto_handler(TMask_field& f, KEY key) spric = 4; } } + TString16 s; if (spric > 0) s << spric; + m.set(105, s, true); // Setta il campo spesa-ricavo della riga IVA } @@ -1880,20 +1851,15 @@ bool TPrimanota_application::iva_sottoconto_handler(TMask_field& f, KEY key) bool TPrimanota_application::cg_sottoconto_handler(TMask_field& f, KEY k) { - if (!suspended_handler(f, k)) - return false; - - return true; + return suspended_handler(f, k); } bool TPrimanota_application::sheet_clifo_handler(TMask_field& f, KEY k) { - if (!suspended_handler(f, k)) - return false; - - if (k == K_TAB || k == K_ENTER) + if (suspended_handler(f, k) && (k == K_TAB || k == K_ENTER)) { - const long codice = atol(f.get()); + const long codice = f.get_long(); + if (codice > 0L) { TMask& m = f.mask(); @@ -1901,9 +1867,11 @@ bool TPrimanota_application::sheet_clifo_handler(TMask_field& f, KEY k) const short gid = cid-1; const int conto = m.get_int(cid); const int gruppo = m.get_int(gid); + if ((k == K_TAB && f.focusdirty()) || (gruppo == 0 && conto == 0)) { TBill c(0, 0, codice, f.dlg() > 300 ? 'F' : 'C'); + c.find(); // Carica gruppo e conto if (c.ok()) { @@ -1923,11 +1891,12 @@ void TPrimanota_application::link_mastrino(const TBill& bill) const { TPrimanota_application& a = app(); const TMask& cm = a.curr_mask(); - int anno = cm.get_int(F_ANNOES); + if (anno <= 0) { TDate date = cm.get(F_DATACOMP); + if (!date.ok()) { date = cm.get_date(F_DATAREG); @@ -1941,6 +1910,7 @@ void TPrimanota_application::link_mastrino(const TBill& bill) const if (anno > 0) { TConfig ini(ininame, "Transaction"); + ini.set("Action", "Modify"); ini.set_paragraph("24"); ini.set(RMV_ANNOES, anno); @@ -1953,6 +1923,7 @@ void TPrimanota_application::link_mastrino(const TBill& bill) const if (ininame.exist()) { TString cmd; + cmd << "cg3 -5 -i" << ininame; TExternal_app app(cmd); app.run(); @@ -1967,6 +1938,7 @@ bool TPrimanota_application::mastrino_handler(TMask_field& f, KEY k) { const TMask& m = f.mask(); TBill bill; bill.get(m, F_GRUPPO, F_CONTO, F_SOTTOCONTO); + app().link_mastrino(bill); } return true; @@ -1980,6 +1952,7 @@ bool TPrimanota_application::sheet_mastrino_handler(TMask_field& f, KEY k) const char tipo = m.get(CG_TIPO)[0]; const short id_sotto = CG_SOTTOCONTO + (tipo <= ' ' ? 0 : (tipo == 'C' ? 100 : 200)); TBill bill; bill.get(m, CG_GRUPPO, CG_CONTO, id_sotto, CG_TIPO); + app().link_mastrino(bill); } return true; @@ -2010,15 +1983,16 @@ void TRR_mask::notify(TSheet_field& s, int row, KEY k) const bool TRR_mask::test_date(TOperable_field& d, int signum) { const TDate date = d.get(); + if (!date.ok()) return error_box(TR("Data non valida")); const int codes = app().curr_mask().get_int(F_ANNOES); TEsercizi_contabili esc; TDate inies, fines; + if (!esc.code2range(codes, inies, fines)) return error_box(TR("E' necessario specificare una esercizio valido")); - if (signum < 0 && date >= inies) return error_box(FR("La data deve precedere il %s"), inies.stringa()); if (signum == 0 && (date < inies || date > fines)) @@ -2032,6 +2006,7 @@ bool TRR_mask::test_date(TOperable_field& d, int signum) bool TRR_mask::on_field_event(TOperable_field& o, TField_event e, long jolly) { bool ok = true; + switch (o.dlg()) { case 101: @@ -2052,30 +2027,28 @@ bool TRR_mask::split_row(TSheet_field& s) { const int sel = s.selected(); CHECKD(sel >= 0 && sel < s.items(), "Bad selection:", sel); - TMask& main_mask = s.mask(); TMask& row_mask = s.sheet_mask(); TEsercizi_contabili esc; const int codes = main_mask.get_int(F_ANNOES); TDate inies, fines; - if (!esc.code2range(codes, inies, fines)) + + if (!esc.code2range(codes, inies, fines)) return error_box(TR("Specificare una data di competenza per il movimento")); const TDate dataini = get_date(101), datafin = get_date(102); const real tot_range = datafin - dataini + 1; const real in_range = (_rateo ? (fines-dataini) : (datafin-inies)) + 1; const real out_range = tot_range - in_range; - const bool iva_sheet = s.dlg() == F_SHEETIVA; const short col1 = iva_sheet ? IVA_IMPONIBILE : CG_DARE; const short col2 = iva_sheet ? IVA_IMPOSTA : CG_AVERE; const short col3 = iva_sheet ? IVA_GRUPPO : CG_GRUPPO; - const real old_imp1 = row_mask.get(col1); const real old_imp2 = row_mask.get(col2); - - real new_imp1[2], new_imp2[2]; + real new_imp1[2], new_imp2[2]; + new_imp1[0] = real(old_imp1 * in_range / tot_range).round(2); new_imp2[0] = real(old_imp2 * in_range / tot_range).round(2); new_imp1[1] = old_imp1 - new_imp1[0]; @@ -2085,6 +2058,7 @@ bool TRR_mask::split_row(TSheet_field& s) { TToken_string& new_row = s.row(-1); const int new_sel = s.rows_array().find(new_row); + notify(s, new_sel, K_SPACE); // Notifica l'intenzione di modificare i valori row_mask.set(col1, new_imp1[i]); @@ -2094,6 +2068,7 @@ bool TRR_mask::split_row(TSheet_field& s) { // Utilizza i conti scritti nei paramentri ditta TConfig ini(CONFIG_DITTA, "cg"); + row_mask.reset(col3-1); // Forza conto normale if (_rateo) { @@ -2111,13 +2086,11 @@ bool TRR_mask::split_row(TSheet_field& s) // Trasferisce tutta la maschera nella rispettiva riga dello sheet FOR_EACH_MASK_FIELD(row_mask, j, f) if (f->shown() && f->dlg() > DLG_USER) - new_row.add(f->get(), s.cid2index(f->dlg())); + new_row.add(f->get(), cid2index(f->dlg())); notify(s, new_sel, K_ENTER); // Notifica l'avvenuta modifica dei valori } - notify(s, sel, K_SPACE); // Riposiziona selezione sulla riga corrente da cancellare - return true; } @@ -2136,9 +2109,11 @@ bool TPrimanota_application::sheet_rateo_handler(TMask_field& f, KEY k) if (k == K_SPACE) { TMask& row_mask = f.mask(); + if (row_mask.is_running() && row_mask.check_fields()) { TRR_mask rateo_mask(true); + if (rateo_mask.run() == K_ENTER) { TSheet_field& s = *row_mask.get_sheet(); @@ -2155,6 +2130,7 @@ bool TPrimanota_application::sheet_risconto_handler(TMask_field& f, KEY k) if (k == K_SPACE) { TMask& row_mask = f.mask(); + if (row_mask.is_running() && row_mask.check_fields()) { TRR_mask risconto_mask(false); @@ -2176,61 +2152,32 @@ bool TPrimanota_application::sheet_risconto_handler(TMask_field& f, KEY k) // Certified 99% bool TPrimanota_application::num_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.to_check(key, true)) + bool ok = true; + TPrimanota_application& a = app(); + + if (f.final_check(key) && a.autodeleting() != 0x3) { TMask& m = f.mask(); - TPrimanota_application& a = app(); + const TRectype& mov = cache().get(LF_MOV, f.get()); - if (a.autodeleting() == 0x3) - return true; // Non effettuare controlli inutili in cancellazione - a._skip_giornale_check = false; a._skip_bollato_check = false; - - const TRectype& mov = cache().get(LF_MOV, f.get()); - if (!mov.empty()) + if (!mov.empty()) { - bool ok = true; - - if (mov.get_bool(MOV_STAMPATO)) - { - ok = f.yesno_box(TR("Il movimento è già stato stampato sul libro giornale:\n" - "si desidera continuare ugualmente?")); - a._skip_giornale_check = ok; - } - - if (ok && mov.get_bool(MOV_REGST)) - { - ok = f.yesno_box(TR("Il movimento è già stato stampato sul bollato:\n" - "si desidera continuare ugualmente?")); - a._skip_bollato_check = ok; - } - + if (mov.get_bool(MOV_STAMPATO)) + ok = f.yesno_box(TR("Il movimento è già stato stampato sul libro giornale:\n" + "si desidera continuare ugualmente?")); + a._skip_giornale_check = true; + if (ok && mov.get_bool(MOV_REGST)) + ok = f.yesno_box(TR("Il movimento è già stato stampato sul bollato:\n" + "si desidera continuare ugualmente?")); + a._skip_bollato_check = true; if (ok && mov.get_bool(MOV_INVIATO)) - { ok = f.yesno_box(TR("Il movimento è stato inviato ad un'altra contabilità:\n" "si desidera continuare ugualmente?")); - } - - if (ok) - { - // Riempie a mano i campi necessari nel caso non sia stato usata la ricerca F9 - m.set(F_DATAREG, mov.get(MOV_DATAREG), true); - m.set(F_CODCAUS, mov.get(MOV_CODCAUS)); - - f.set_focusdirty(false); - ok = m.stop_run(K_AUTO_ENTER); - } - else - { - m.reset(F_NUMREG); - if (a.lnflag()) - m.stop_run(K_FORCE_CLOSE); - } - return ok; } } - return true; + return ok; } @@ -2244,12 +2191,14 @@ bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) const TString& cau = f.get(); const int ann = m.get_int(F_ANNOIVA); const TipoIVA i = app().cau2IVA(cau, ann); // Cerca causale e suo tipo - if (i == iva_errata && m.is_running()) + + if (i == iva_errata && m.is_running()) return f.error_box(TR("Causale non presente in archivio")); TEdit_field& numreg = m.efield(F_NUMREG); TString16 filter; - if (cau.full()) + + if (cau.full()) filter << MOV_CODCAUS << "==\"" << cau << '"'; numreg.browse()->set_filter(filter); numreg.browse()->cursor()->setfilter(filter, true); @@ -2263,18 +2212,19 @@ bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) void TPrimanota_application::check_fppro_fields(TMask& m) { const bool after_data = TDate(m.get(F_DATAREG)) >= TDate(fp_settings().get_data_start_fatt()); + if (!check_causale(m.get(F_CODCAUS)) || !app().has_module(FPAUT) || !after_data) { - if(m.find_by_id(DLG_LINK) != NULL) + if(m.find_by_id(DLG_LINK) != nullptr) m.disable(DLG_LINK); - if (m.find_by_id(F_COLFPPRO) != NULL) + if (m.find_by_id(F_COLFPPRO) != nullptr) m.hide(F_COLFPPRO); } else { - if (m.find_by_id(DLG_LINK) != NULL) + if (m.find_by_id(DLG_LINK) != nullptr) m.enable(DLG_LINK); - if (m.find_by_id(F_COLFPPRO) != NULL) + if (m.find_by_id(F_COLFPPRO) != nullptr) m.show(F_COLFPPRO); } } @@ -2283,77 +2233,64 @@ void TPrimanota_application::check_fppro_fields(TMask& m) // Certified 99% bool TPrimanota_application::caus_modify_handler(TMask_field& f, KEY key) { - if (f.to_check(key)) - { - if (!suspended_handler(f, key)) - return false; - - TMask& m = f.mask(); - const int ann = m.get_int(F_ANNOIVA); - const TString& cau = f.get(); - - const TCausale c(cau, ann); - if (!c.ok()) - return false; - - bool init_provv_rev = false; - bool mask_ok = true; - - TPrimanota_application& a = app(); - const TCausale& k = a.causale(); - const TipoIVA t = k.iva(); - const TString& msg = c.compatible(k); - if (msg.not_empty()) // La causale non è compatibile - { - if (m.insert_mode() && !a._sal_dirty) - { - // Cambio la maschera al volo - if (a.force_mask_swap(k, c)) - init_provv_rev = true; - } - if (!init_provv_rev) - return error_box(msg); - mask_ok = a._msk[c.iva() == nessuna_iva ? 1 : 2] != NULL; - } - - if (key == K_TAB) - { - a.read_caus(cau, ann); - if (mask_ok) // Non tentare di aggiornare sheet al momento inesistente essendo la causale incompatibile - a.cgs().force_update(); - } - - if (init_provv_rev) - { - TString4 provv; provv << c.provvisorio(); - m.set(F_PROVVISORIO, provv); - if (c.iva() != nessuna_iva && mask_ok) - m.set(F_SOLAIVA, c.soloiva() ? "X" : " "); - } - if (c.iva() != nessuna_iva && mask_ok) + if (f.running_check(key)) + { + if (suspended_handler(f, key)) { - m.efield(F_REVCHARGE).show(c.iva() == iva_acquisti && c.reverse_charge_pubb()); - m.efield(F_MOVCOLL).show((c.iva() == iva_acquisti && c.reverse_charge_pubb()) || - (c.iva() == iva_vendite && c.causale_reg_iva())); - // m.efield(F_GOCOLL).show((c.iva() == iva_acquisti && c.reverse_charge()) || - // (c.iva() == iva_vendite && c.causale_reg_iva())); - a.activate_split_payment(m); - } - // Se la causale ha come tipo documento una bolla doganale, se si abilito i campi per collegare il fornitore - if(m.find_by_id(F_BOLLACODCLI) != NULL) - { - f.mask().enable(F_BOLLACODCLI, c.tipo_doc() == "BD"); - f.mask().enable(F_BOLLARAGCLI, c.tipo_doc() == "BD"); - } - if (t != nessuna_iva && app().causale().iva() != nessuna_iva) - { - const long protocol = app().causale().reg().protocol() + 1; + TMask& m = f.mask(); + const int ann = m.get_int(F_ANNOIVA); + const TString& cau = f.get(); + const TCausale c(cau, ann); - m.set(F_PROTIVA, protocol); - m.set(F_RITFATT, app().causale().fattura_in_ritardo() ? "X" : " "); + if (c.ok()) + { + TPrimanota_application& a = app(); + const TCausale& k = a.causale(); + TString8 codice = c.codice(); + const TipoIVA t = k.iva(); + TMask * new_mask = &m; + + if (codice != k.codice()) + { + const TString& msg = c.compatible(k); + + if (msg.not_empty()) // La causale non è compatibile + { + if (!m.insert_mode() || a._sal_dirty || !a.force_mask_swap(k, c)) // Cambio la maschera al volo + return error_box(msg); + new_mask = a._msk[c.iva() == nessuna_iva ? 1 : 2]; + } + a.read_caus(cau, ann); + if (new_mask != nullptr) // Non tentare di aggiornare sheet al momento inesistente essendo la causale incompatibile + { + TString4 provv; provv << c.provvisorio(); + + a.cgs().force_update(); + new_mask->set(F_PROVVISORIO, provv); + if (c.iva() != nessuna_iva) + { + new_mask->set(F_SOLAIVA, c.soloiva() ? "X" : " "); + new_mask->show(F_REVCHARGE, c.iva() == iva_acquisti && c.reverse_charge_pubb()); + new_mask->show(F_MOVCOLL, (c.iva() == iva_acquisti && c.reverse_charge_pubb()) || + (c.iva() == iva_vendite && c.causale_reg_iva())); + a.activate_split_payment(m); + // Se la causale ha come tipo documento una bolla doganale, se si abilito i campi per collegare il fornitore + new_mask->enable(F_BOLLACODCLI, c.tipo_doc() == "BD"); + new_mask->enable(F_BOLLARAGCLI, c.tipo_doc() == "BD"); + + const long protocol = app().causale().reg().protocol() + 1; + + new_mask->set(F_PROTIVA, protocol); + new_mask->set(F_RITFATT, app().causale().fattura_in_ritardo() ? "X" : " "); + } + check_fppro_fields(*new_mask); + } + } + } } - } - check_fppro_fields(f.mask()); + else + return false; + } return true; } @@ -2364,10 +2301,12 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) { bool ok = true; - if (key == K_TAB && f.focusdirty() || key == K_ENTER) - { + // if (key == K_TAB && f.focusdirty() || key == K_ENTER) + if (f.to_check(key)) + { const TDate oggi(TODAY); TDate dr(f.get()); // Data dell'operazione + if (dr > oggi) { #ifdef DBG @@ -2378,96 +2317,66 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) #endif } - TMask& m = f.mask(); - if (dr == oggi && m.query_mode() && !m.field(F_NUMREG).empty()) - { - TLocalisamfile mov(LF_MOV); - mov.put(MOV_NUMREG, m.get(F_NUMREG)); - if (mov.read() == NOERR) - dr = mov.get_date(MOV_DATAREG); - } + TMask& m = f.mask(); + TPrimanota_application& a = app(); - TPrimanota_application& a = app(); - TMask_field* ixc = m.find_by_id(F_IVAXCASSA); - if (ixc) - ixc->enable(gestione_IVAxCassa(dr)); + if (dr == oggi && m.query_mode() && !m.field(F_NUMREG).empty()) + dr = TDate(cache().get(LF_MOV, m.get_long(F_NUMREG), MOV_DATAREG)); + if (!m.query_mode() && a.iva() != nessuna_iva) + m.enable(F_IVAXCASSA, gestione_IVAxCassa(dr)); const int ae = a._esercizi.date2esc(dr); // Codice esercizio + if (ae <= 0) return f.error_box(TR("La data dell'operazione non appartiene a nessun esercizio")); TLibro_giornale& gio = a.giornale(); const int ag = a._esercizi[ae].inizio().year(); // Anno libro giornale + if (m.query_mode() || gio.year() != ag) - { - ok = gio.read(ag); - if (!ok) + if (!gio.read(ag)) return f.error_box(FR("Non esiste il libro giornale del %d"), ag); - } - else - ok = true; if (key == K_ENTER || f.focusdirty()) { - const long numreg = m.get_long(F_NUMREG); - const bool error = numreg == 0 || numreg > a._lastreg; - if (key != K_ENTER && !a._skip_giornale_check) { - if (dr < gio.last_print()) - { - f.error_box(FR("La data dell'operazione è antecedente al %s,\n" - "ultima stampa del libro giornale del %d"), - gio.last_print().string(), ag); - if (error) return false; - } + if (dr < gio.last_print()) + return error_box(FR("La data dell'operazione è antecedente al %s,\n" + "ultima stampa del libro giornale del %d"), + gio.last_print().string(), ag); if (key == K_TAB && dr < gio.last_reg()) - f.warning_box(FR("La data dell'operazione è antecedente al %s,\n" - "ultima registrazione sul libro giornale del %d"), - gio.last_reg().string(), ag); - } - - const int ar = dr.year(); // Anno solare registri - if (m.query_mode()) - a.read_caus(m.get(F_CODCAUS), ar); - - TRegistro& reg = a.causale().reg(); - const TString4 codreg = reg.name(); - if (codreg.full()) - { - if (reg.year() != ar) - { - const bool ok = reg.read(codreg, ar); - if (!ok) return false; - a.read_caus(NULL, 0); - if (a.iva() != nessuna_iva) - m.field(F_CODREG).on_hit(); - } - - if (!a._skip_bollato_check) - { - if (dr < reg.last_print()) - { - f.error_box(FR("La data dell'operazione è antecedente al %s,\n" - "ultima stampa del registro '%s' del %d"), - reg.last_print().string(), (const char*)codreg, ar); - if (error) return false; - } - if (f.dirty() && dr < reg.last_reg()) - f.warning_box(FR("La data dell'operazione è antecedente al %s,\n" - "ultima registrazione sul registro '%s' del %d"), - reg.last_reg().string(), (const char*)codreg, ar); - } - - if (reg.iva() != nessuna_iva && a._rel->controlla_liquidazione(dr, reg) == true) - { - const char* const mese = itom(dr.month()); - f.warning_box(FR("La liquidazione IVA relativa al mese di %s è già stata calcolata"), mese); - } - } - } + warning_box(FR("La data dell'operazione è antecedente al %s,\n" + "ultima registrazione sul libro giornale del %d"), + gio.last_reg().string(), ag); + } + if (a.iva() != nessuna_iva) + { + const int ar = dr.year(); // Anno solare registri + const TCausale & caus = cached_causale(m.get(F_CODCAUS), ar); + TRegistro& reg = caus.reg(); + const TString4 codreg = reg.name(); + + if (codreg.full()) + { + if (!a._skip_bollato_check) + { + if (a._rel->controlla_liquidazione(dr, reg) == true) + f.warning_box(FR("La liquidazione IVA relativa al mese di %s è già stata calcolata"), itom(dr.month())); + if (f.dirty() && dr < reg.last_reg()) + f.warning_box(FR("La data dell'operazione è antecedente al %s,\n" + "ultima registrazione sul registro '%s' del %d"), + reg.last_reg().string(), (const char*)codreg, ar); + if (dr < reg.last_print()) + ok = yesno_box(FR("La data dell'operazione è antecedente al %s,\n" + "ultima stampa del registro '%s' del %d\nSi desidera continuare ugualmente?"), + reg.last_print().string(), (const char*)codreg, ar); + } + } + } + } + check_fppro_fields(f.mask()); } - check_fppro_fields(f.mask()); return ok; } @@ -2480,29 +2389,29 @@ bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) if (key == K_TAB || key == K_ENTER) { const TDate dr(m.get(F_DATAREG)); // Data operazione - - TString16 datacomp = f.get(); - if (datacomp.empty()) + TDate datacomp = f.get_date(); + + if (!datacomp.ok()) { - datacomp = dr.string(); - // DATACOMP new way + datacomp = dr; if (key == K_ENTER) f.set(datacomp); } - const TDate dc(datacomp); // Data di competenza + TEsercizi_contabili& esc = app()._esercizi; - const int ae = esc.date2esc(dc); // Esercizio corrispondente - - const char* data = TR("La data del 74/ter"); + const int ae = esc.date2esc(datacomp); // Esercizio corrispondente + TString dmsg(TR("La data del 74/ter")); + if (f.dlg() == F_DATACOMP) { m.set(F_ANNOES, ae, true); // Aggiorna anno esercizio in entrambe le pagine - data = TR("La data di competenza"); + dmsg = TR("La data di competenza"); - if (dc > dr) + if (datacomp > dr) { bool ok = false; const TString& ca = m.get(F_CODCAUS); + if (ca.not_empty()) // Controlla ratei e risconti { TConfig ini(CONFIG_DITTA, "cg"); @@ -2519,35 +2428,29 @@ bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) { const int ar = esc.date2esc(dr); // Esercizio in corso const int pr = esc.pred(ar); // Esercizio precedente + if (ae != ar && ae != pr) { TString e(80); - e.format(FR("%s deve appartenere all'esercizio %d"), data, ar); + + e.format(FR("%s deve appartenere all'esercizio %d"), (const char *) dmsg, ar); if (pr > 0) e << TR(" o all'esercizio ") << pr; return f.error_box(e); } const TDate chiusura = app()._esercizi[ae].chiusura(); - if (chiusura.ok() && dc < chiusura) - { - f.error_box(FR("%s è antecedente al %s,\ndata di chiusura dell'esercizio %d"), - data, chiusura.stringa(), ae); - // Errore non bloccante - } - else - if (chiusura.ok() && dc == chiusura) - { - f.error_box(FR("%s è uguale al %s,\ndata di chiusura dell'esercizio %d"), - data, chiusura.stringa(), ae); - // Errore non bloccante - } + if (chiusura.ok() && datacomp < chiusura) + f.error_box(FR("%s è antecedente al %s,\ndata di chiusura dell'esercizio %d"), + (const char *) dmsg, chiusura.stringa(), ae); // Errore non bloccante + else + if (chiusura.ok() && datacomp == chiusura) + f.error_box(FR("%s è uguale al %s,\ndata di chiusura dell'esercizio %d"), + (const char *) dmsg, chiusura.stringa(), ae); // Errore non bloccante } else - { if (m.is_running()) - return f.error_box(FR("%s non appartiene a nessun esercizio"), data); - } + return f.error_box(FR("%s non appartiene a nessun esercizio"), (const char *) dmsg); } return true; } @@ -2561,12 +2464,12 @@ bool TPrimanota_application::datacompcr_handler(TMask_field& f, KEY key) if (key == K_ENTER) { const TDate dr(m.get(F_DATAREG)); // Data operazione - TDate datacompcr(f.get()); + TDate datacompcr = f.get_date(); - if (datacompcr.empty()) + if (!datacompcr.ok()) { - f.set(dr); - datacompcr = dr; + datacompcr = dr; + f.set(datacompcr); } if (datacompcr > dr) @@ -2579,27 +2482,28 @@ bool TPrimanota_application::datacompcr_handler(TMask_field& f, KEY key) // Certified 90% bool TPrimanota_application::data74ter_handler(TMask_field& f, KEY key) { - if (!f.to_check(key)) - return true; + if (f.to_check(key)) + { + const TDate dr = f.mask().get_date(F_DATAREG); // Data operazione + const TDate d74 = f.get_date(); // Data 74/ter - const TDate dr(f.mask().get(F_DATAREG)); // Data operazione - const TDate d74(f.get()); // Data 74/ter - if (d74 > dr) - return true; + if (d74 <= dr) + { + if (d74.year() < dr.year() - 1) + return error_box(FR("La data 74/ter non puo' essere antecedente all'anno %d"), dr.year() - 1); - if (d74.year() < dr.year()-1) - return error_box(FR("La data 74/ter non puo' essere antecedente all'anno %d"), dr.year()-1); - - const TLibro_giornale g(d74.year()); - if (!g.ok()) - return error_box(TR("La data 74/ter non appartiene ad un esercizio valido")); - - if (d74 < g.last_print()) - { - const char* lp = g.last_print().string(); - return f.error_box(FR("La data 74/ter e' antecedente al %s,\n" - "data di stampa del libro giornale del %d"), lp, g.year()); - } + const TLibro_giornale g(d74.year()); + if (!g.ok()) + return error_box(TR("La data 74/ter non appartiene ad un esercizio valido")); + + if (d74 < g.last_print()) + { + const char* lp = g.last_print().string(); + return f.error_box(FR("La data 74/ter e' antecedente al %s,\n" + "data di stampa del libro giornale del %d"), lp, g.year()); + } + } + } return true; } @@ -2608,6 +2512,7 @@ bool TPrimanota_application::numdoc_handler(TMask_field& f, KEY key) if (f.to_check(key, true)) { TMask& m = f.mask(); + if (key == K_TAB && m.insert_mode() && app().is_saldaconto()) { if (!f.empty() && !app().npart_is_prot()) // Copiare numero documento nel numero partita? @@ -2622,9 +2527,9 @@ bool TPrimanota_application::numdoc_handler(TMask_field& f, KEY key) if (key == K_ENTER && !f.empty() && app().iva() != nessuna_iva) { TMask& m = f.mask(); - const int annodoc = m.get_date(F_DATADOC).year(); const long fornitore = m.get_long(F_CODCLIFOR); + if (annodoc > 0 && fornitore > 0) { // SELECT NUMREG,DATAREG,DATADOC,NUMDOC FROM MOV @@ -2632,27 +2537,31 @@ bool TPrimanota_application::numdoc_handler(TMask_field& f, KEY key) // NUMDOC=F_NUMDOC AND DATAREG>=F_DATADOC AND NUMREG<>F_NUMREG TString filter; - filter << '(' << MOV_NUMDOC << "=\"" << f.get() << "\")&&(" << MOV_REG << "!=\"\")"; + + filter << '(' << MOV_NUMDOC << "=\"" << f.get() << "\")&&(" << MOV_REG << "!=\"\")"; if (m.edit_mode()) filter << "&&(" << MOV_NUMREG << "!=\"" << m.get(F_NUMREG) << "\")"; TRelation rel(LF_MOV); TRectype& rec = rel.curr(); - TRectype recfrom(rec); + recfrom.put(MOV_TIPO, app().iva() == iva_acquisti ? "F" : "C"); recfrom.put(MOV_CODCF, fornitore); recfrom.put(MOV_DATAREG, TDate(1, 1, annodoc)); TRectype recto(recfrom); + recto.put(MOV_DATAREG, TDate(31, 12, annodoc+1)); TCursor cur(&rel, filter, 3, &recfrom, &recto); const TRecnotype items = cur.items(); + cur.freeze(); for (cur = 0; cur.pos() < items; ++cur) { const int ad = rec.get_date(MOV_DATADOC).year(); + if (ad == annodoc) return yesno_box("Il documento %d / %s è già stato inserito con la registrazione %ld\nSi desidera continuare ugualmente?", annodoc, (const char*)f.get(), rec.get_long(MOV_NUMREG)); @@ -2666,10 +2575,12 @@ bool TPrimanota_application::numdoc_handler(TMask_field& f, KEY key) bool TPrimanota_application::ndocext_handler(TMask_field& f, KEY key) { TMask& m = f.mask(); + if (key == K_TAB && f.to_check(key, true) && m.get(F_NUMDOC).empty() && !f.empty()) { // Mi precarico la dimensione del campo numdoc, così in caso di aggiornamenti non devo cambiare static const int numdoc_size = TRectype(LF_MOV).length(MOV_NUMDOC); + m.set(F_NUMDOC, f.get().right(numdoc_size)); if (!app().npart_is_prot()) // Copiare numero documento nel numero partita? { @@ -2687,12 +2598,14 @@ bool TPrimanota_application::datadoc_handler(TMask_field& f, KEY key) if (key == K_TAB && f.to_check(key, true) && app().is_saldaconto()) { const TDate dd(f.get()); // Fattura o nota credito + if (dd.ok()) { if (m.insert_mode() && m.field(F_ANNORIF).active() && m.get(F_ANNORIF).empty()) m.set(F_ANNORIF, dd.year()); // copia anno documento - TPrimanota_application& a = app(); + TPrimanota_application& a = app(); + if (a.is_fattura()) { if (m.insert_mode()) @@ -2708,19 +2621,21 @@ bool TPrimanota_application::datadoc_handler(TMask_field& f, KEY key) } } } - return true; } bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key) { TMask& m = f.mask(); + if (key == K_TAB && (f.dirty() || !m.is_running())) { const TString& code = f.get(); + if (code.full()) { TRelation occas(LF_OCCAS); + occas.curr().put(OCC_CFPI, code); if (occas.read(_isequal) == NOERR) { @@ -2742,15 +2657,18 @@ bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key) bool TPrimanota_application::occas_cfpi_handler(TMask_field& f, KEY key) { TMask& om = f.mask(); + if (key == K_TAB && (f.focusdirty() || !om.is_running())) { TString16 cofi = om.get(O_COFI); + if (cofi.empty()) cofi = om.get(O_CODICE); if (cf_check(om.get(O_STATONAS), cofi)) { int giorno = atoi(cofi.mid(9,2)); + om.set(O_SESSO, giorno > 40 ? "F" : "M"); if (om.field(O_COMUNENAS).empty()) @@ -2761,6 +2679,7 @@ bool TPrimanota_application::occas_cfpi_handler(TMask_field& f, KEY key) const TFixed_string mesi("ABCDEHLMPRST"); const int mese = mesi.find(cofi[8])+1; int anno = atoi(cofi.mid(6,2)); + if (giorno > 0 && mese > 0 && anno > 0) { giorno %= 40; @@ -2778,6 +2697,7 @@ bool TPrimanota_application::occas_handler(TMask_field& f, KEY key) if (key == K_SPACE && f.mask().is_running()) { TMask& om = app().occas_mask(); + om.run(); f.set_focus(); } @@ -2792,7 +2712,6 @@ void TPrimanota_application::add_cgs_tot(TMask& m) const TString4 tipo = corri ? " " : app().clifo(); int gruppo = 0, conto = 0; long codice = corri ? 0L : m.get_long(F_CODCLIFOR); - TSheet_field& ss = cgs(); const int riga_totale = type2pos('T'); @@ -2818,6 +2737,7 @@ void TPrimanota_application::add_cgs_tot(TMask& m) } TBill nuovo(gruppo, conto, codice, tipo[0]); + if (!corri && (gruppo == 0 || conto == 0)) nuovo.find(); // Compila anche gruppo e conto in base al codice clifo @@ -2835,12 +2755,14 @@ void TPrimanota_application::add_cgs_tot(TMask& m) { TToken_string& row = ss.row(riga_totale); const TBill vecchio(row, 2, 0x1); + if (!vecchio.empty() && nuovo != vecchio) // Se cambio cliente/fornitore { for (int i = 0; i < ss.items(); i++) if (i != riga_totale) { TToken_string& r = ss.row(i); const TBill tacchia(r, 9, 0x1); + if (tacchia == vecchio) { nuovo.add_to(r, 9, 0x3); // Aggiorna contropartite @@ -2855,6 +2777,7 @@ void TPrimanota_application::add_cgs_tot(TMask& m) if (riga_totale >= 0) // Dare e Avere potrebbero essere disabilitati { TToken_string& r = ss.row(riga_totale); + if (row_type(r) == 'T') { r.rtrim(2); @@ -2870,11 +2793,14 @@ void TPrimanota_application::add_cgs_tot(TMask& m) if (riga_totale >= 0) { const int idx_des = ss.cid2index(CG_DESCR); + descr = ss.row(riga_totale).get(idx_des); } if (descr.blank()) descr = m.get(F_DESCR); + TImporto imp = real2imp(m.get_real(F_TOTALE), 'T'); + set_cgs_row(riga_totale, imp.normalize(), nuovo, descr, 'T'); } @@ -2897,14 +2823,16 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) if (f.focusdirty() && a.is_nota_credito()) { TPartite_array& p = a.partite(); - const TPartita* game = p.first(); - if (game != NULL && atol(f.get()) != game->conto().codclifo()) + + if (game != nullptr && atol(f.get()) != game->conto().codclifo()) { const bool del = f.yesno_box(TR("Si desidera cancellare i pagamenti effettuati?")); + if (!del) // Ripristina codice copiandolo dalla prima partita { TString8 cod; cod << game->conto().codclifo(); + f.set(cod); return true; } @@ -2928,6 +2856,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) TRelation cliforel(LF_CLIFO); cliforel.add(LF_CFVEN, "TIPOCF=TIPOCF|CODCF=CODCF"); TRectype& clifo = cliforel.curr(); + clifo.put(CLI_TIPOCF, cf); clifo.put(CLI_CODCF, codice); cliforel.read(); @@ -2945,13 +2874,16 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) const int alleg = clifo.get_int(CLI_ALLEG); TEdit_field& upi = m.efield(F_RIEPILOGO); + upi.check_type(alleg == 3 ? CHECK_REQUIRED : CHECK_NORMAL); TEdit_field& cp = m.efield(F_CODPAG); + if ((f.focusdirty() && m.is_running()) || (cp.empty() && !m.is_running())) { const TString& oldpag = cp.get(); const TString& s = clifo.get(CLI_CODPAG); + if (s != oldpag) { if (cp.active()) // Se il campo F_CODPAG e' attivo @@ -2964,6 +2896,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) if (cf == 'F' && app().causale().valintra()) { const TString& valintra = clifo.get(CLI_VALINTRA); + if (valintra.full()) m.set(F_VALUTAINTRA, valintra, true); } @@ -2974,6 +2907,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) if (m.field(SK_VALUTA).active() && m.get(SK_VALUTA).empty()) { const TString& valuta = clifo.get(CLI_CODVAL); + if (valuta.not_empty()) m.set(SK_VALUTA, valuta, true); } @@ -2994,7 +2928,9 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) m.set(FS_NSCAB, clifov.get(CFV_CODCABPR)); m.send_key(K_TAB, FS_NSCAB); } + const TString& agente = clifov.get(CLI_CODAG); + if (agente.full()) { m.set(FS_AGENTE, agente, true); @@ -3005,6 +2941,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) } const bool occas = clifo.get_bool(CLI_OCCAS); + m.show(F_OCCASEDIT, occas); // Bottone Dati anagrafici m.show(F_STATOPAIV, !occas); // Stato partita IVA if (!occas) @@ -3012,7 +2949,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) m.show(F_PIVA, !occas); // Partita IVA m.show(F_COFI, !occas); // Codice Fiscale - if (occas && a.is_fattura() && a.partite().first() != NULL) + if (occas && a.is_fattura() && a.partite().first() != nullptr) { f.warning_box(TR("Attenzione, il saldaconto verrà eliminato!")); f.set_dirty(); // warning_box cleans the field! @@ -3027,20 +2964,23 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) m.send_key(K_SPACE, F_OCCASEDIT); // Lancia maschera occasionali TMask_field* ixc = m.find_by_id(F_IVAXCASSA); - if (ixc) + + if (ixc != nullptr) { TString16 paiv = clifo.get(CLI_PAIV); + if (paiv.blank() && occas) paiv = a.occas_mask().get(O_PAIV); + const int alleg = clifo.get_int(CLI_ALLEG); const bool ic = ixc->active() && (alleg < 5 || alleg == 7) && paiv.full() && !m.get_bool(F_LIQDIFF); + ixc->set(ic ? "X" : ""); } if(m.get(F_PROKEY).empty() && app().has_module(F1AUT)) fppro_mask(f, key); } } - return true; } @@ -3048,6 +2988,7 @@ bool TPrimanota_application::clifo_handler(TMask_field& f, KEY key) bool TPrimanota_application::IVA2bill(const TCodiceIVA& iva, TBill& bill) { const TCausale& cau = causale(); + if (!cau.corrispettivi()) bill = _conto_ricavo; return cau.IVA2bill(iva, bill); @@ -3060,72 +3001,81 @@ bool TPrimanota_application::main_codiva_handler(TMask_field& f, KEY key) { static bool __in_handler = false; - if (key == K_TAB && !f.empty() && !__in_handler) + if (f.mask().mode() == MODE_INS && f.running_check(key)) { - if (!suspended_handler(f, key)) - return false; - - __in_handler = true; - - TPrimanota_application& a = app(); - const real imp(a.ivas().row(1).get(0)); - - if (a.iva() == iva_acquisti) + if (!__in_handler && f.full() && suspended_handler(f, key)) { - TMask& mm = f.mask(); // Main mask - const TCodiceIVA codiva(f.get()); - if (a.causale().intra()) - { - const real iva = f.mask().get(F_RITFIS); // Le ritenute fiscali vengono usate come IVA intra - if (iva.is_zero()) - { - const real totale = mm.get_real(F_TOTALE); - const real imposta = codiva.imposta(totale); - mm.set(F_RITFIS, imposta, true); - } - } else - if (a.causale().reverse_charge_pubb()) - { - const real totale = mm.get_real(F_TOTALE) + mm.get_real(F_RITFIS); - const real imposta = codiva.imposta(totale); - mm.set(F_REVCHARGE, imposta, true); - } + TPrimanota_application& a = app(); + TSheet_field & iva = a.ivas(); + int i; + TString imp; + + __in_handler = true; + for (i = iva.items() - 1; i >= 0; i--) + { + imp = iva.row(i).get(cid2index(IVA_IMPONIBILE)); + if (imp.full()) + break; + } + if (i < 1) + { + const real imp(iva.row(0).get(cid2index(IVA_IMPONIBILE))); + const bool acquisto = a.iva() == iva_acquisti; + const TCodiceIVA codiva(f.get()); + TMask & mask = f.mask(); // Main mask + + if (acquisto) + { + if (a.causale().intra()) + { + const real iva = f.mask().get(F_RITFIS); // Le ritenute fiscali vengono usate come IVA intra + + if (iva.is_zero()) + { + const real totale = mask.get_real(F_TOTALE); + const real imposta = codiva.imposta(totale); + + mask.set(F_RITFIS, imposta, true); + } + } + } + + TSheet_field & iva = a.ivas(); + TToken_string& row = iva.row(0); + + const bool corr = a.causale().corrispettivi(); + const bool acq3 = (acquisto) && (codiva.tipo_indetraibilita() == 3 || row.get_int(2) == 3); + const bool reverse_charge_attivo = acquisto && a.causale().reverse_charge() && codiva.reverse_charge_attivo(); + real tot = a.totale_documento(); // Calcola totale documento + real imposta; // Calcola imposta + + iva.notify(0, K_SPACE); + if (!corr && !acq3) + if (reverse_charge_attivo) + imposta = codiva.imposta(tot); + else + imposta = codiva.scorpora(tot); + row.add(tot.string(), cid2index(IVA_IMPONIBILE)); // imponibile + row.add(imposta.string(), cid2index(IVA_IMPOSTA)); // imposta + row.add(codiva.codice(), cid2index(IVA_CODIVA)); // Aggiorna codice IVA + if (acquisto) + { + row.add(codiva.indetraibilita(), cid2index(IVA_INDETRAIBILE)); + row.add(a.causale().reverse_charge_pubb() && reverse_charge_attivo ? "X" : "", cid2index(IVA_REVCHARGE)); + } + + TBill bill(row, cid2index(IVA_TIPO), 0x1); + + if (!bill.ok()) + { + a.IVA2bill(codiva, bill); // Aggiorna conto della prima riga IVA + bill.add_to(row, cid2index(IVA_TIPOCOSTORIC), 0x7); + } + iva.force_update(0); + iva.notify(0, K_ENTER); + } + __in_handler = false; } - if (imp.is_zero()) // Se il totale documento non è stato spezzato - { - TToken_string& row = a.ivas().row(0); - iva_notify(a.ivas(), 0, K_SPACE); - - const TCodiceIVA iva(f.get()); - const bool corr = a.causale().corrispettivi(); - const bool acq3 = (a.iva() == iva_acquisti) && (iva.tipo_indetraibilita() == 3 || row.get_int(2) == 3); - - real tot = a.totale_documento(); // Calcola totale documento - real imposta; // Calcola imposta - if (!corr && !acq3) - imposta = iva.scorpora(tot); - - row.add(tot.string(), 0); // imponibile - row.add(imposta.string(), 3); // imposta - - if (iva.codice() != row.get(1)) - { - row.add(iva.codice(), 1); // Aggiorna codice IVA - - TString4 det; - if (a.iva() == iva_acquisti) - det = iva.indetraibilita(); - row.add(det, 2); - - TBill bill; // Aggiorna conto della prima riga IVA - a.IVA2bill(iva, bill); - bill.add_to(row, 4, 0x7); - } - a.ivas().force_update(0); - - iva_notify(a.ivas(), 0, K_ENTER); - } - __in_handler = false; } return true; } @@ -3133,39 +3083,34 @@ bool TPrimanota_application::main_codiva_handler(TMask_field& f, KEY key) // Scandisce le righe IVA detraibili e forza il conto corretto in base ai flag IVA in testata static void force_iva_det_bill() { - TSheet_field& cgs = app().cgs(); - TMask& mask = cgs.mask(); - - const TCausale& cau = app().causale(); + TSheet_field & cgs = app().cgs(); + TMask & mask = cgs.mask(); + const TCausale& cau = app().causale(); TBill contoiva; int ri = 0; - if (mask.get_bool(F_LIQDIFF)) + + if (mask.active(F_LIQDIFF) && mask.get_bool(F_LIQDIFF)) cau.bill(ri = RIGA_IVA_DIFFERITA, contoiva); else - if (mask.get_bool(F_IVAXCASSA)) + if (mask.active(F_IVAXCASSA) && mask.get_bool(F_IVAXCASSA)) cau.bill(ri = RIGA_IVA_PER_CASSA, contoiva); if (ri <= 0 || !contoiva.ok()) cau.bill(ri = RIGA_IVA_DETRAIBILE, contoiva); TToken_string conto(contoiva.string(0x3)); const TString80 descragg(cau.desc_agg(ri)); - const int rt = cgs.cid2index(CG_ROWTYPE); - const int tp = cgs.cid2index(CG_TIPO); - const int gr = cgs.cid2index(CG_GRUPPO); - const int co = cgs.cid2index(CG_CONTO); - const int sc = cgs.cid2index(CG_SOTTOCONTO); - const int des = cgs.cid2index(CG_DESCR); FOR_EACH_SHEET_ROW(cgs, r, row) { - const char rtype = row->get_char(rt); + const char rtype = row->get_char(cid2index(CG_ROWTYPE)); + if (rtype == 'D') { - row->add(conto.get(0), tp); - row->add(conto.get(), gr); - row->add(conto.get(), co); - row->add(conto.get(), sc); - row->add(conto.get(), sc + 1); - row->add(descragg, des); + row->add(conto.get(0), cid2index(CG_TIPO)); + row->add(conto.get(), cid2index(CG_GRUPPO)); + row->add(conto.get(), cid2index(CG_CONTO)); + row->add(conto.get(), cid2index(CG_SOTTOCONTO)); + row->add(conto.get(), cid2index(CG_DESCR)); // sc + 1); + row->add(descragg, cid2index(CG_DESCR)); } } cgs.force_update(); @@ -3174,25 +3119,24 @@ static void force_iva_det_bill() bool TPrimanota_application::activate_split_payment(TMask& m) { bool yes = false; - TMask_field* sp = m.find_by_id(F_SPLITPAY); - if (sp != NULL) + TMask_field & sp = m.field(F_SPLITPAY); + + if (clifo() == "C" && m.get_int(F_ANNOIVA) >= 2015 && !causale().reverse_charge_pubb()) { - if (clifo() == "C" && m.get_int(F_ANNOIVA) >= 2015 && !causale().reverse_charge_pubb()) - { - const TRectype& cliente = cache().get_rec(LF_CLIFO, "C", m.get(F_CODCLIFOR)); - yes = cliente.get_bool(CLI_SPLITPAY); - } - if (yes) - { - sp->show(); - if (sp->get().blank()) - sp->set("S"); // Set - } - else - { - sp->hide(); - sp->reset(); - } + const TRectype& cliente = cache().get_rec(LF_CLIFO, "C", m.get(F_CODCLIFOR)); + + yes = cliente.get_bool(CLI_SPLITPAY); + } + if (yes) + { + sp.show(); + if (sp.get().blank()) + sp.set("S"); // Set + } + else + { + sp.hide(); + sp.reset(); } return yes; } @@ -3216,7 +3160,7 @@ bool TPrimanota_application::is_split_payment() const char s = ' '; TMask_field* sp = m.find_by_id(F_SPLITPAY); - if (sp != NULL) + if (sp != nullptr) { if (sp->shown()) s = sp->get()[0]; @@ -3231,9 +3175,11 @@ bool TPrimanota_application::is_split_payment() const if (clifo() == "C" && m.get_int(F_ANNOIVA) >= 2015 && !causale().reverse_charge_pubb()) { const TRectype& cliente = cache().get_rec(LF_CLIFO, "C", m.get(F_CODCLIFOR)); + if (cliente.get_bool(CLI_SPLITPAY)) { TRelation rel(LF_MOV); + rel.add(LF_PARTITE, "NREG==NUMREG", 2); m.autosave(rel); if (::is_split_payment(rel.curr())) @@ -3263,7 +3209,6 @@ bool TPrimanota_application::liqdiff_handler(TMask_field& f, KEY key) if (app().is_fattura_split()) return f.error_box(TR("Non è ammessa la liquidazione differita con split payment")); } - return true; } @@ -3272,9 +3217,9 @@ bool TPrimanota_application::liqdiff_handler(TMask_field& f, KEY key) bool TPrimanota_application::ivaxcassa_handler(TMask_field& f, KEY key) { const TMask& m = f.mask(); + if (key == K_SPACE && m.is_running()) force_iva_det_bill(); - if (key == K_ENTER && f.get().full()) { if (app().is_fattura_split()) @@ -3283,11 +3228,11 @@ bool TPrimanota_application::ivaxcassa_handler(TMask_field& f, KEY key) { TString8 key; key.format("C|%ld", m.get_long(F_CODCLIFOR)); const TRectype& clifo = cache().get(LF_CLIFO, key); + if (clifo.get_int(CLI_ALLEG) == 6) return f.error_box(TR("Non è ammessa IVA per cassa con clienti privati")); } } - return true; } @@ -3296,39 +3241,41 @@ bool TPrimanota_application::ivaxcassa_handler(TMask_field& f, KEY key) void TPrimanota_application::gioca_cambi(int force) { TMask& m = curr_mask(); - if (m.get(SK_VALUTA).empty()) - return; - - const real totale = m.get_real(F_TOTALE); - const real totval = m.get_real(SK_TOTDOCVAL); - const real cambio = m.get_real(SK_CAMBIO); - if ( (force == 0x1 || totale.is_zero()) && !(totval.is_zero() || cambio.is_zero()) ) - { - const TValuta cam(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); - const real new_totale = cam.val2eur(totval); - if (new_totale != totale) - m.set(F_TOTALE, new_totale, true); - } - - if ( (force == 0x2 || totval.is_zero()) && !(totale.is_zero() || cambio.is_zero()) ) - { - const TValuta cam(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); - const real new_totval = cam.eur2val(totale); - if (new_totval != totval) - m.set(SK_TOTDOCVAL, new_totval, true); - } - - if ( (force == 0x4 || cambio.is_zero()) && !(totale.is_zero() || totval.is_zero()) ) - { - real new_cambio = totale / totval; - new_cambio.round(6); - if (new_cambio != cambio) - m.set(SK_CAMBIO, new_cambio, true); - } + if (m.get(SK_VALUTA).full()) + { + const real totale = m.get_real(F_TOTALE); + const real totval = m.get_real(SK_TOTDOCVAL); + const real cambio = m.get_real(SK_CAMBIO); + + if ((force == 0x1 || totale.is_zero()) && !(totval.is_zero() || cambio.is_zero())) + { + const TValuta cam(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); + const real new_totale = cam.val2eur(totval); + + if (new_totale != totale) + m.set(F_TOTALE, new_totale, true); + } + + if ((force == 0x2 || totval.is_zero()) && !(totale.is_zero() || cambio.is_zero())) + { + const TValuta cam(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); + const real new_totval = cam.eur2val(totale); + + if (new_totval != totval) + m.set(SK_TOTDOCVAL, new_totval, true); + } + if ((force == 0x4 || cambio.is_zero()) && !(totale.is_zero() || totval.is_zero())) + { + real new_cambio = totale / totval; + + new_cambio.round(6); + if (new_cambio != cambio) + m.set(SK_CAMBIO, new_cambio, true); + } + } } - // Handler of the F_TOTALE // Certified 99% bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) @@ -3337,15 +3284,19 @@ bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) TMask& m = f.mask(); TPrimanota_application& a = app(); - if (key == K_TAB && f.focusdirty()) + if (f.running_check(key)) { a.gioca_cambi(); - if (a.iva() != nessuna_iva) { a.add_cgs_tot(m); - if (m.insert_mode()) // Se si e' in inserimento provoca ricalcolo - m.field(F_CODIVA).on_hit(); // dello sheet iva e delle scadenze + if (m.insert_mode()) // Se si e' in inserimento provoca ricalcolo + { + TEdit_field & codiva = m.efield(F_CODIVA); + + codiva.set_focusdirty(); + codiva.on_hit(); // dello sheet iva e delle scadenze + } } else { @@ -3359,7 +3310,6 @@ bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) m.show(K_TOTALE, f.get().full()); } - if (key == K_ENTER) { if (a.is_pagamento()&& ! a._as400) @@ -3370,7 +3320,8 @@ bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) FOR_EACH_SHEET_ROW_BACK(cgrows, i, r) { const char tipo = row_type(*r); - if (strchr("GK", tipo) != NULL) // Abbuoni attivi, differenze cambio, spese, ... // (A o P) Abbuoni e (C) Differenze cambio perchè c'erano ? non (T) totolae documento perchè pagamento + + if (strchr("GK", tipo) != nullptr) // Abbuoni attivi, differenze cambio, spese, ... // (A o P) Abbuoni e (C) Differenze cambio perchè c'erano ? non (T) totolae documento perchè pagamento { TImporto importo; @@ -3400,6 +3351,7 @@ bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) { const real totval(m.get(SK_TOTDOCVAL)); const TCurrency totlit(cambio.val2eur(totval)); + if (totale != totlit) ok = f.yesno_box(FR("Il totale documento dovrebbe essere %s: continuare ugualmente?"), totlit.string(true)); @@ -3410,16 +3362,17 @@ bool TPrimanota_application::totdoc_handler(TMask_field& f, KEY key) { TBill bill; const int riga_cf = a.cerca_conto_cf(bill); + if (riga_cf >= 0) { TImporto imp = a.get_cgs_imp(riga_cf); + if (imp.valore() != m.get_real(F_TOTALE)) ok = f.error_box(FR("Il totale documento non corrisponde alla riga %d:\ndovrebbe essere %s"), riga_cf+1, imp.valore().string()); } } } - return ok; } @@ -3428,17 +3381,16 @@ bool TPrimanota_application::totdocval_handler(TMask_field& f, KEY key) if (key == K_TAB && f.focusdirty()) { TPrimanota_application& a = app(); + TMask& m = f.mask(); + a.gioca_cambi(); - - TMask& m = f.mask(); if (a.is_fattura() && m.insert_mode()) a.set_scadenze(m); } - return true; } -// Aggiunge o aggiorna la riga delle ritenute fiscali o sociali +// Aggiunge o aggiorna la riga delle ritenute fiscali o sociali o iva vendite reverse charge // Certified 99% void TPrimanota_application::add_cgs_ritenute(char tipo) { @@ -3448,6 +3400,7 @@ void TPrimanota_application::add_cgs_ritenute(char tipo) TMask& m = curr_mask(); const real imp = m.get(tipo=='F' ? F_RITFIS : (tipo=='S' ? F_RITSOC : F_REVCHARGE)); // Determina importo const int pos = type2pos(tipo); // Cerca la riga contabile + if (pos < 0) // Se non c'e' ... { if (!imp.is_zero()) // ... e l'importo e' valido crea una nuova riga di ritenute @@ -3455,6 +3408,7 @@ void TPrimanota_application::add_cgs_ritenute(char tipo) const int riga = tipo=='F' ? RIGA_RITENUTE_FISCALI : (tipo== 'S' ? RIGA_RITENUTE_SOCIALI : RIGA_REVERSE_CHARGE); TBill conto; causale().bill(riga, conto); const TString desc = causale().desc_agg(riga); + set_cgs_row(-1, real2imp(imp, tipo), conto, desc, tipo); } } @@ -3466,9 +3420,17 @@ void TPrimanota_application::add_cgs_ritenute(char tipo) set_cgs_imp(pos, real2imp(imp, tipo)); // ... aggiorna importo } - if (m.insert_mode()) - m.field(F_CODIVA).on_hit(); // Ricalcola sheet iva e contabile - else + if (m.insert_mode()) + { + if (tipo != 'V') + { + TEdit_field & iva = m.efield(F_CODIVA); + + iva.set_focusdirty(); + iva.on_hit(); // Ricalcola sheet iva e contabile + } + } + else app().calcola_saldo(); // Ricalcola solo lo sbilancio } @@ -3484,6 +3446,7 @@ bool TPrimanota_application::protiva_handler(TMask_field& f, KEY key) { const long protiva = atol(f.get()); const long protocol = app().causale().reg().protocol() + 1; + if (protiva != protocol) ok = f.yesno_box(FR("Accettare il protocollo IVA fuori sequenza: %ld invece di %ld"), protiva, protocol); @@ -3523,34 +3486,42 @@ bool TPrimanota_application::ritsoc_handler(TMask_field& f, KEY key) // Certified 100% bool TPrimanota_application::revcharge_handler(TMask_field& f, KEY key) { - if (f.active()) + if (f.running_check(key)) { - if (key == K_TAB && f.focusdirty()) - app().add_cgs_ritenute('V'); - if (f.to_check(key, true)) - { - if (f.get().full()) - f.mask().field(F_IVAXCASSA).clear(); - else - f.mask().field(F_IVAXCASSA).enable(); - } + TMask & m = f.mask(); + const bool revcharge = f.get().full(); + + m.enable(F_IVAXCASSA, !revcharge); + if (revcharge) + m.set(F_IVAXCASSA, ""); + m.field(F_IVAXCASSA).on_hit(); } + else + if (f.final_check(key)) + { + const bool revcharge = f.get().full(); + + if (!revcharge) + return f.error_box(TR("Movimento di reverse charge senza righe di reverse charge")); + } return true; } - HIDDEN void inventa_cambio_intra(TMask& m) { const TString& codval = m.get(F_VALUTAINTRA); + if (codval.not_empty() && TCurrency::get_firm_val() != codval) { TTable cam("CAM"); + cam.put("CODTAB", codval); const int err = cam.read(_isgteq); bool yes = err != NOERR; if (!yes) { TString16 v = cam.get("CODTAB"); + v.cut(3).rtrim(); yes = v != codval; } @@ -3569,7 +3540,6 @@ bool TPrimanota_application::dataintra_handler(TMask_field& f, KEY key) return true; } - // Handler of F_CORRLIRE // Certified 99% bool TPrimanota_application::corrlire_handler(TMask_field& f, KEY key) @@ -3587,7 +3557,6 @@ bool TPrimanota_application::corrlire_handler(TMask_field& f, KEY key) else key = K_F8; } - if (key == K_F8) { f.set(m.get(F_IMPONIBILI)); @@ -3601,25 +3570,27 @@ bool TPrimanota_application::corrlire_handler(TMask_field& f, KEY key) { if (m.field(F_CAMBIOINTRA).empty()) inventa_cambio_intra(m); + const TExchange cambio(m.get(F_VALUTAINTRA), m.get_real(F_CAMBIOINTRA)); TCurrency imp(real(f.get())); + imp.change_value(cambio); cv.set(imp.get_num().string()); } } - - if (key == K_ENTER) + if (key == K_ENTER) { const real im(m.get(F_IMPONIBILI)); const real cl(f.get()); + if (im != cl) { const TRectype& rec = cache().get("%VAL", TCurrency::get_firm_val()); const char* name = (const char*)rec.get("S0"); + warning_box(FR("Il corrispettivo in %s e' diverso dal totale degli imponibili"), name); } } - return true; } @@ -3630,14 +3601,16 @@ bool TPrimanota_application::corrvaluta_handler(TMask_field& f, KEY key) TMask& m = f.mask(); TMask_field& cl = m.field(F_CORRISPETTIVO); - if (key == K_TAB && f.focusdirty()) + if (f.running_check(key)) { if (cl.empty()) { if (m.field(F_CAMBIOINTRA).empty()) inventa_cambio_intra(m); + const TExchange cambio(m.get(F_VALUTAINTRA), m.get_real(F_CAMBIOINTRA)); TCurrency imp(real(f.get()), cambio); + imp.change_to_firm_val(); cl.set(imp.get_num().string()); } @@ -3663,6 +3636,7 @@ bool TPrimanota_application::activate_numrif(TMask& m, bool init_pag) if (m.id2pos(F_SOLAIVA) >= 0) // Maschera moviventi IVA { const bool hide = m.get_bool(F_SOLAIVA) || m.field(F_OCCASEDIT).shown(); + if (hide) shown = false; } @@ -3690,6 +3664,7 @@ bool TPrimanota_application::activate_numrif(TMask& m, bool init_pag) // Gestione pagina 3 const bool page = shown && is_fattura() && !m.get(F_NUMRIF).blank(); + if (page != m.page_enabled(2)) { m.enable_page(2, page); @@ -3698,7 +3673,8 @@ bool TPrimanota_application::activate_numrif(TMask& m, bool init_pag) if (m.edit_mode()) { const TString& dt = m.get(F_DATADOC); - set_pagamento(NULL, dt); // Reset pagamento + + set_pagamento(nullptr, dt); // Reset pagamento set_totale_pagamento(true); } else @@ -3718,7 +3694,6 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) if ((key == K_TAB && f.focusdirty()) || !run) { TPrimanota_application& a = app(); - bool anchecg = f.get()[0] != 'X'; bool recalcg = anchecg; @@ -3728,7 +3703,7 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) if (anchecg) { - if (game != NULL) + if (game != nullptr) { m.set(F_ANNORIF, game->anno()); m.set(F_NUMRIF, game->numero()); @@ -3737,7 +3712,7 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) else { bool del = true; - if (game != NULL) + if (game != nullptr) del = f.yesno_box(TR("Si desidera cancellare il saldaconto?")); if (!del) { @@ -3758,27 +3733,28 @@ bool TPrimanota_application::solaiva_handler(TMask_field& f, KEY key) TSheet_field& iva = a.ivas(); const int righe = iva.items(); TProgind pi(righe, TR("Generazione righe contabilità"), false, true); - TSheet_field& cg = a.cgs(); - cg.reset(); + cg.reset(); a.add_cgs_tot(m); // Genera totale documento - if (!m.efield(F_RITFIS).empty()) a.add_cgs_ritenute('F'); // Genera ritenute fiscali - if (!m.efield(F_RITSOC).empty()) a.add_cgs_ritenute('S'); // Genera ritenute sociali - if (!m.efield(F_REVCHARGE).empty() && !m.efield(F_REVCHARGE).active()) - a.add_cgs_ritenute('V'); // Genera reverse charge + if (!m.empty(F_RITFIS)) a.add_cgs_ritenute('F'); // Genera ritenute fiscali + if (!m.empty(F_RITSOC)) a.add_cgs_ritenute('S'); // Genera ritenute sociali +// if (!m.empty(F_REVCHARGE) && !m.active(F_REVCHARGE)) +// a.add_cgs_ritenute('V'); // Genera reverse charge TToken_string oldrow(128); + for (int i = 0; i < righe; i++) { TToken_string& r = iva.row(i); + if (!r.empty_items()) { oldrow = r; r = ""; - iva_notify(iva, i, K_SPACE); // Simula la creazione di una nuova riga iva + iva.notify(i, K_SPACE); r = oldrow; - iva_notify(iva, i, K_ENTER); + iva.notify(i, K_ENTER); } pi.setstatus(i+1); } @@ -3797,6 +3773,7 @@ bool TPrimanota_application::linkdoc_handler(TMask_field& f, KEY key) { const TRectype& mov = app().get_relation()->curr(); TRectype doc(LF_DOC); + doc.put(DOC_PROVV, mov.get(MOV_DPROVV)); doc.put(DOC_ANNO, mov.get(MOV_DANNO)); doc.put(DOC_CODNUM,mov.get(MOV_DCODNUM)); @@ -3806,17 +3783,16 @@ bool TPrimanota_application::linkdoc_handler(TMask_field& f, KEY key) return true; } - bool TPrimanota_application::quadratura_handler(TMask_field& f, KEY key) { if (key == K_SPACE) { TMask& m = f.mask(); TSheet_field& shiva = m.sfield(F_SHEETIVA); - const real totdoc = app().totale_documento(); TGeneric_distrib distrib(totdoc, TCurrency::get_firm_dec()); real totdist; + if (!shiva.empty()) { FOR_EACH_SHEET_ROW(shiva, o, orow) @@ -3854,18 +3830,20 @@ bool TPrimanota_application::quadratura_handler(TMask_field& f, KEY key) { const real o_imponibile = nrow->get(0); const real o_imposta = nrow->get(3); - if (!o_imponibile.is_zero() || !o_imposta.is_zero()) + + if (!o_imponibile.is_zero() || !o_imposta.is_zero()) { const TString4 zanicchi(nrow->get(1)); // Codice IVA const TCodiceIVA i(zanicchi); real n_imponibile = distrib.get(); real n_imposta = i.scorpora(n_imponibile); + if (n_imponibile != o_imponibile || n_imposta != o_imposta) { - app().iva_notify(shiva, n, K_SPACE); + shiva.notify(n, K_SPACE); nrow->add(n_imponibile.string(), 0); nrow->add(n_imposta.string(), 3); - app().iva_notify(shiva, n, K_ENTER); + shiva.notify(n, K_ENTER); } } } @@ -3879,17 +3857,19 @@ void TPrimanota_application::write_righe_iva_f1(TMask& cg_msk, const shared_ptr< TSheet_field& sf = cg_msk.sfield(F_SHEETIVA); const vector& righe = msk->get_righeiva(); int i = 0; + for (auto it = righe.begin(); it != righe.end(); ++it) { if(it->imponibile != 0 || it->imposta != 0) { TToken_string& row = sf.row(i); - iva_notify(sf, i, K_SPACE); + + sf.notify(i, K_SPACE); row.add(it->imponibile, cid2index(IVA_IMPONIBILE)); row.add(it->imposta, cid2index(IVA_IMPOSTA)); row.add(it->aliquota, cid2index(IVA_PERCIVA)); row.add(it->natura, cid2index(IVA_NATURIVA)); - iva_notify(sf, i, K_ENTER); + sf.notify(i, K_ENTER); i++; } } @@ -3900,13 +3880,13 @@ bool TPrimanota_application::write_scad_f1(const TMask& cg_msk, const shared_ptr const int items = sf.items(); const vector& righe = msk->get_scadenze(); int i = 0; + for (auto it = righe.begin(); it != righe.end(); ++it, ++i) { TToken_string& row = app().pags().row(i); if(i >= items) pag_notify(sf, i, K_CTRL+K_INS); - pag_notify(sf, i, K_SPACE); row.add(it->data, cid2index(101)); row.add(it->importo, cid2index(102)); @@ -3921,6 +3901,7 @@ void TPrimanota_application::write_clifo(TMask& cg_msk, const shared_ptrget_fpprokeys(), ';'); TString codforn = TFppro(keys).get_codforn(); + if (codforn.empty()) codforn = msk->get_codforn(); if (codforn.empty()) @@ -3965,9 +3946,12 @@ void TPrimanota_application::write_clifo(TMask& cg_msk, const shared_ptr& msk) { real totale = msk->get_totdoc(); + if(totale == ZERO) totale = app().calcola_imp(); + const real rit = msk->get_ritenute(); + if (rit != ZERO) { totale -= rit; @@ -3982,6 +3966,7 @@ void TPrimanota_application::set_totale(TMask& cg_msk, const shared_ptr& msk) { const bool bring = msk->should_bring_back(); + if (bring) { if (msk->get_numdoc().full() && cg_msk.get(F_CODCLIFOR).empty()) @@ -4006,11 +3991,16 @@ void TPrimanota_application::riporta_dati_f1(TMask& cg_msk, const shared_ptr(cg_msk); + app()._pro_mask = msk; + const TString datadoc = cg_msk.get(F_DATADOC); + if(datadoc.full()) { msk->set(F_ENABDATE, "X"); @@ -4027,16 +4017,18 @@ bool TPrimanota_application::fppro_mask(TMask_field& f, KEY key) is_collegato(cg_msk.field(F_COLFPPRO)); cg_msk.set(F_ANNORIF, cg_msk.get(F_ANNOIVA)); } - return true; } bool TPrimanota_application::scollega(const bool set) { static bool scollega = false; + if (set) return scollega = true; + const bool last = scollega; + scollega = false; return last; } @@ -4044,13 +4036,16 @@ bool TPrimanota_application::scollega(const bool set) bool TPrimanota_application::scollega_handler(TMask_field& f, KEY key) { TMask& cg_msk = f.mask(); + if (!app().has_module(FPAUT) || key != K_SPACE && key != K_TAB || !check_causale(cg_msk.get(F_CODCAUS))) return true; if (cg_msk.get_bool(F_COLFPPRO)) { scollega(true); app().clean_fppro(); + const bool ok = app().save_dbmov(true); + if (ok) { app().curr_mask().set(F_PROKEY, ""); @@ -4065,6 +4060,7 @@ bool TPrimanota_application::is_collegato(TMask_field& f) { TMask& cg_msk = f.mask(); const bool has_prokey = !cg_msk.get(F_PROKEY).empty(); + f.set(has_prokey ? "X" : " "); return has_prokey; } @@ -4079,7 +4075,9 @@ bool TPro_msk::load_fppro_mask(TMask* msk, KEY k) message_box("Attenzione connessione al database non riuscita.\nImpossibile collegarsi ai documenti in entrata."); return false; } + const int forn = msk->get_int(F_CODCLIFORS); + if (forn == 0) { msk->set(F_ENABSEARCH, "X"); @@ -4093,17 +4091,17 @@ bool TPro_msk::load_fppro_mask(TMask* msk, KEY k) const TString& piva = msk->get(F_PIVAS); TString query; TString date = ""; + if (msk->get_bool(F_ENABDATE)) - date = TDate(msk->get_date(F_DATESEARCH)); + date = msk->get_date(F_DATESEARCH); if(!msk->get_bool(F_ENABSEARCH)) query = query_fppro(msk->get(F_CODCLIFORS), date); else query = query_fppro(stato_piva, piva, date); - - fp_db().sq_set_exec(query, false); TSheet_field& sf = msk->sfield(F_SHEETFPPROS); + sf.hide(); if (sf.items() > 0) sf.destroy(); @@ -4111,13 +4109,14 @@ bool TPro_msk::load_fppro_mask(TMask* msk, KEY k) { TString numreg = fp_db().sq_get("PZ_NUMREGCONT"); const bool show_all = msk->get_bool(F_SHOWALL); + if (numreg != "0" && !show_all) continue; TToken_string& row = sf.row(-1); TToken_string keys(fp_db().sq_get("PZ_KEYPRGINVIO"), ';'); - keys.add(fp_db().sq_get("PZ_KEYHEADERFATT")); keys.add(fp_db().sq_get("PZ_KEYBODYFATT")); + keys.add(fp_db().sq_get("PZ_KEYHEADERFATT")); keys.add(fp_db().sq_get("PZ_KEYBODYFATT")); row.add("", 0); row.add(fp_db().sq_get("P7_TIPODOC")); row.add(TDate(fp_db().sq_get_date("P1_DATAORARIC"))); @@ -4141,6 +4140,7 @@ bool TPro_msk::load_fppro_mask(TMask* msk, KEY k) bool TPro_msk::fppro_handler(TMask_field& f, KEY k) { TMask& msk = f.mask(); + const bool load = load_fppro_mask(&msk, k); return load; } @@ -4189,6 +4189,7 @@ bool TPro_msk::piva_handler(TMask_field& f, KEY k) { TMask& msk = f.mask(); bool ok = true; + if(k == K_TAB && f.active() && f.focusdirty()) { ok = load_fppro_mask(&msk, K_SPACE); @@ -4200,6 +4201,7 @@ bool TPro_msk::date_handler(TMask_field& f, KEY k) { TMask& msk = f.mask(); bool ok = true; + if (k == K_TAB && f.active() && f.focusdirty()) { ok = load_fppro_mask(&msk, K_SPACE); @@ -4211,6 +4213,7 @@ void TPro_msk::fppro_selfatt() const { const TMask& mask = *this; TSheet_field& sf = mask.sfield(F_SHEETFPPROS); + sf.hide(); FOR_EACH_SHEET_ROW(sf, nr, row) { @@ -4268,6 +4271,7 @@ void TPro_msk::set_righeiva(const char* fpprokeys) { TToken_string keys(fpprokeys, ';'); TString query; + query << "SELECT PL_ALIQUOTAIVA AS ALIQUOTA, PL_NATURA AS NATURA, PL_IMPONIBILE AS IMPONIBILE, PL_IMPOSTA AS IMPOSTA, PL_ESIGIVA AS ESIGIBILITA\nFROM PAA2200F\n" << "WHERE PL_KEYPRGINVIO = '" << keys.get(0) << "' AND PL_KEYHEADERFATT = '" << keys.get(1) << "' AND PL_KEYBODYFATT = '" << keys.get(2) << "';"; fp_db().sq_set_exec(query, false); @@ -4286,6 +4290,7 @@ void TPro_msk::set_scadenze(const char* fpprokeys) TToken_string keys(fpprokeys, ';'); TString query; query << "SELECT PO_RIGA AS RIGA, PO_DATASCADENZA AS DATA, PO_IMPORTO AS IMPORTO \nFROM PAA2500F \n" << "WHERE PO_KEYPRGINVIO = '" << keys.get(0) << "' AND PO_KEYHEADERFATT = '" << keys.get(1) << "' AND PO_KEYBODYFATT = '" << keys.get(2) << "';"; + fp_db().sq_set_exec(query, false); for(bool ok = fp_db().sq_next(); ok; ok = fp_db().sq_next()) { @@ -4310,6 +4315,7 @@ void TPro_msk::set_doc(const char* numero, const char* datadoc, const char* totd real TPro_msk::get_tot_imp_riva() { real tot = ZERO; + for(riga_iva_s const& riga : _righe_iva) { if (riga.imposta > ZERO) @@ -4342,6 +4348,7 @@ TString& TPro_msk::query_fppro(const TString& codforn, const TString& stato_piva { TString id_fornitore; TString keys; + if(piva_research && !piva.empty()) { id_fornitore << " (P2_FISCIVAPAESE = "; @@ -4392,13 +4399,13 @@ TString& TPro_msk::query_fppro(const TString& codforn, const TString& stato_piva query.cut(0) << query.left(query.len() - 6); query << "\nORDER BY P1_DATAORARIC ASC, PZ_TIPOPROT ASC, PZ_NUMPROT ASC;"; } - return query; } TString& TPro_msk::query_string() { static TString query; + query.cut(0) << "SELECT PZ_CLIFOR, PZ_DATA, CAST(P1_DATAORARIC AS DATE) AS P1_DATAORARIC, P7_TIPODOC, PQ_IMPTOTDOC, PZ_NUMERO, PZ_NUMREGCONT, PZ_TIPOPROT, " << "PZ_NUMPROT, P2_ANADENOMIN, P2_FISCIVAPAESE, P2_FISCIVACOD, P2_CODFISCALE, PZ_KEYPRGINVIO, PZ_KEYHEADERFATT, PZ_KEYBODYFATT\n" << "FROM PAA0200F \nJOIN FPPRO00F\n" << " ON P2_KEYPRGINVIO = PZ_KEYPRGINVIO AND P2_KEYHEADERFATT = PZ_KEYHEADERFATT AND P2_KEYBODYFATT = PZ_KEYBODYFATT\n" << diff --git a/src/cg/cg2102.h b/src/cg/cg2102.h index 3839dd387..d1705bf38 100755 --- a/src/cg/cg2102.h +++ b/src/cg/cg2102.h @@ -312,7 +312,7 @@ protected: void set_type_color(char tipor, char tipoc, COLOR col); void set_colors(); - bool read_caus(const char* cod, int year); + bool read_caus(const char* cod = nullptr, int year = 0); TLibro_giornale& giornale() { return *_giornale; } bool test_swap(bool ritsoc); @@ -325,8 +325,8 @@ protected: real calcola_imp() const; void add_cgs_tot(TMask& m); - int set_cgs_row(int n, const TImporto& importo, TBill& conto, const char* desc, char tipo, - const char* cms = NULL, const char* fas = NULL); + int set_cgs_row(int n, const TImporto& importo, const TBill& conto, const char* desc, char tipo, + const char* cms = nullptr, const char* fas = nullptr); void set_cgs_imp(int n, const TImporto& importo); bool add_cgs_imp(int n, const TImporto& importo); bool sub_cgs_imp(int n, const TImporto& importo); @@ -378,7 +378,9 @@ protected: public: static int type2pos(char tipo); static char row_type(const TToken_string& s); - static bool iva_notify(TSheet_field& s, int r, KEY key); + void add2cg_row(TSheet_field& s, TToken_string & row, TString_array & saved_desc, const bool add = true); + void sub2cg_row(TSheet_field& s, TToken_string & row, TString_array & saved_desc) { add2cg_row(s, row, saved_desc, false) ; } + static bool iva_notify(TSheet_field& s, int r, KEY k); static bool cg_notify(TSheet_field& s, int r, KEY key); bool get_isf1() const { return _isf1; } int get_lastdate() { return _last_date; } diff --git a/src/cg/cg2103.cpp b/src/cg/cg2103.cpp index e539c4860..fb044c96c 100755 --- a/src/cg/cg2103.cpp +++ b/src/cg/cg2103.cpp @@ -97,7 +97,8 @@ bool TCausale::read(const char* cod, int year) TBill& TCausale::bill(int num, TBill& conto) const { const TRectype* rec = row(num); - if (rec != NULL) + + if (rec != nullptr) conto.set(rec->get_int(RCA_GRUPPO), rec->get_int(RCA_CONTO), rec->get_long(RCA_SOTTOCONTO), rec->get_char(RCA_TIPOCF)); return conto; @@ -318,7 +319,8 @@ void TCausale::calcIVA() const TString& TCausale::compatible(const TCausale& c) const { - const char* err = NULL; + const char* err = nullptr; + if (sezionale() != c.sezionale()) err = TR("il segnale di sezionale"); if (intra() != c.intra()) @@ -334,9 +336,10 @@ const TString& TCausale::compatible(const TCausale& c) const if (tipomov() != c.tipomov()) err = TR("il tipo di movimento"); - if (err != NULL) + if (err != nullptr) { TString& msg = get_tmp_string(); + msg.format(FR("Causale incompatibile per %s"), err); return msg; } diff --git a/src/cg/cg2104.cpp b/src/cg/cg2104.cpp index e4a65c58d..1ae1971a6 100755 --- a/src/cg/cg2104.cpp +++ b/src/cg/cg2104.cpp @@ -26,7 +26,7 @@ bool TPrimanota_application::pag_notify(TSheet_field& ps, int r, KEY k) TMask* msk = &(ps.mask()); // if (!msk->is_running()) return true; // Necessario per evitare il CHECK sul pagamento nullo - if (!app().is_fattura() || app()._pag == NULL) return true; // Necessario per evitare il CHECK sul pagamento nullo + if (!app().is_fattura() || app()._pag == nullptr) return true; // Necessario per evitare il CHECK sul pagamento nullo TPagamento& pag = app().pagamento(); TString_array& rws = app().pag_rows(); @@ -138,11 +138,11 @@ bool TPrimanota_application::pag_notify(TSheet_field& ps, int r, KEY k) // ricalcola sheet come sai fare tu ahiahi = pag.recalc_rate(r, m_perc, ((m_perc || m_impv) ? - (m_perc ? (const char*)newp : (const char*)newv) : NULL), - (m_impl ? (const char*)newl : NULL), - (m_scad ? (const char*)news : NULL), - (m_tipo ? (const char*)newt : NULL), - (m_ulc ? (const char*)newu : NULL), + (m_perc ? (const char*)newp : (const char*)newv) : nullptr), + (m_impl ? (const char*)newl : nullptr), + (m_scad ? (const char*)news : nullptr), + (m_tipo ? (const char*)newt : nullptr), + (m_ulc ? (const char*)newu : nullptr), rdiff, mcomm, need_recalc); // see if rdiff changed @@ -301,10 +301,11 @@ bool TPrimanota_application::pag_sheet_handler(TMask_field& f, KEY key) bool TPrimanota_application::tipopag_handler(TMask_field& f, KEY key) { - if ((key == K_TAB || key == K_ENTER) && f.dirty()) + if (f.to_check(key)) { TMask& m = f.mask(); int t = m.get_int(105); + if (t <= 0) { t = 1; @@ -607,7 +608,7 @@ bool TPrimanota_application::recalc_handler(TMask_field& f, KEY key) bool TPrimanota_application::nrate_handler(TMask_field& f, KEY key) { - if (key == K_TAB && f.focusdirty()) + if (f.running_check(K_TAB)) { TPagamento& pag = app().pagamento(); pag.set_numero_rate(atoi(f.get())); @@ -701,18 +702,14 @@ void TPrimanota_application::recalc_scadenze(const TDate& d) void TPrimanota_application::set_pagamento(const char* c, const char* d) { - if (_pag != NULL) - { - delete _pag; - _pag = NULL; - } - if (c != NULL || d != NULL) + SAFE_DELETE(_pag); + if (c != nullptr || d != nullptr) { if (!TDate::isdate(d)) d = ""; _pag = new TPagamento(c, d); } - if (_pag != NULL && iva() == iva_vendite) + if (_pag != nullptr && iva() == iva_vendite) _pag->set_clifo(curr_mask().get_long(F_CODCLIFOR)); // Dato indispensabile per non accettazione effetti } @@ -968,7 +965,7 @@ void TPrimanota_application::write_scadenze(const TMask& m) const TString numpart(m.get(F_NUMRIF)); TPartita* oldgame = partite().first(); - TPartita* newgame = NULL; + TPartita* newgame = nullptr; int nuova_riga = 0; @@ -1085,14 +1082,15 @@ void TPrimanota_application::write_scadenze(const TMask& m) } } - if (oldgame != NULL) + if (oldgame != nullptr) { const int rigafatt = oldgame->prima_fattura(nreg); if (rigafatt > 0) { - if (newgame == NULL || *oldgame != *newgame) + if (newgame == nullptr || *oldgame != *newgame) { - bool sposta = newgame != NULL; + bool sposta = newgame != nullptr; + if (sposta) { sposta = (oldgame->conto().sottoconto() == newgame->conto().sottoconto()); @@ -1117,8 +1115,7 @@ void TPrimanota_application::write_scadenze(const TMask& m) } } } - - if (newgame != NULL) // Se non ho cancellato il numero partita ... + if (newgame != nullptr) // Se non ho cancellato il numero partita ... { newgame->write(); // Salva nuova partita delete newgame; @@ -1258,11 +1255,11 @@ bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pa TBill contro; contro.get(cli_row, 9, 0x3); if (!contro.ok()) // Completa controparita della riga cliente se necessario new_conto.add_to(cli_row, 9, 0x3); - TString80 descr = cli_row.get(CG_DESCR-FIRST_FIELD); + TString80 descr = cli_row.get(cid2index(CG_DESCR)); if (descr.blank()) // Compila descrizione della riga cliente se necessario { descr = somma.get(PART_DESCR); - cli_row.add(descr, CG_DESCR-FIRST_FIELD); + cli_row.add(descr, cid2index(CG_DESCR)); } // Compila contropartita della nuova riga diff --git a/src/cg/cg2105.cpp b/src/cg/cg2105.cpp index 280991d60..01bff9fb0 100755 --- a/src/cg/cg2105.cpp +++ b/src/cg/cg2105.cpp @@ -46,7 +46,7 @@ protected: static bool nuovo_handler(TMask_field& f, KEY k); static bool cambio_handler(TMask_field& f, KEY k); - void add_importo(TToken_string& s, const TImporto& i, const char* val = NULL, int pos = -1); + void add_importo(TToken_string& s, const TImporto& i, const char* val = nullptr, int pos = -1); void add_descrizione(TToken_string& s, const TRiga_partite& riga, int pos = -1); TImporto get_importo(TToken_string& s, int pos) const; @@ -650,7 +650,8 @@ void TGame_mask::init(const TBill& bill, long numreg, int riga) #else TValuta val; const TRiga_partite* row = cerca_prima_riga(); - if (row != NULL) + + if (row != nullptr) { val.get(*row); // Legge valuta standard dalla partita set(P_ANNO, row->get(PART_ANNO)); // Propone anno e partita @@ -868,13 +869,15 @@ TToken_string& TGame_mask::add_colored_row(TSheet_field& sheet, char type) const TPartita* TGame_mask::partita_corrente() const { if (_riga_partite < 0) - return NULL; + return nullptr; + TToken_string& row = partite().row(_riga_partite); const int anno = row.get_int(0); // Anno partita const TNumero_partita num = row.get(); // Numero partita const TBill& zio = conto(); TPartita* game = app().partite().exist(zio, anno, num); - return game; + + return game; } bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) @@ -915,7 +918,8 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) const TBill& zio = gm.conto(); // Conto cliente/fornitore TPartita* game = app().partite().exist(zio, anno, num); // Cerca la partita tra quelle editate - const bool should_delete_game = (game == NULL); // Ricorda di fare delete + const bool should_delete_game = (game == nullptr); // Ricorda di fare delete + if (should_delete_game) // Se non c'era ... game = new TPartita(zio, anno, num); // ... creane una temporanea @@ -958,7 +962,7 @@ bool TGame_mask::partite_notify(TSheet_field& partite, int r, KEY k) row = riga_fattura; row.add(ra, 1); row.add(scad.get(SCAD_DATASCAD), 3); - gm.add_importo(row, scad.importo(false), NULL, 5); + gm.add_importo(row, scad.importo(false), nullptr, 5); if (in_valuta) gm.add_importo(row, scad.importo(true), prima_valuta.codice(), 6); @@ -1383,8 +1387,9 @@ int TGame_mask::nuova_riga(TPartita& partita, tipo_movimento tm) const part.put(PART_DATAPAG, cm.get(F_DATAREG)); part.put(PART_TIPOPAG, 1); - const TRiga_partite* prima = (tm != tm_fattura) ? cerca_prima_riga() : NULL; - if (prima != NULL && prima != &part) + const TRiga_partite* prima = (tm != tm_fattura) ? cerca_prima_riga() : nullptr; + + if (prima != nullptr && prima != &part) { part.put(PART_DESCR, prima->get(PART_DESCR)); part.put(PART_DATAPAG, prima->get(PART_DATAPAG)); @@ -1497,7 +1502,7 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) { if (m.get_bool(114)) { - if (was == NULL) + if (was == nullptr) giochi.destroy(game); return f.error_box(FR("La rata %d risulta bloccata."), nrata); } @@ -1510,7 +1515,8 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) TString4 c = parval.codice(); if (c.empty()) c = TCurrency::get_firm_val(); - if (was == NULL) giochi.destroy(game); + + if (was == nullptr) giochi.destroy(game); return f.error_box(FR("La fattura deve essere pagata in %s."), (const char*)c); } #endif @@ -1522,11 +1528,11 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) // nm->set(P_NUMERO, game.numero()); // Non deve proporre nulla: CM000206 const KEY k = nm->run(); tm = (tipo_movimento)nm->get_int(P_NUOVO); - delete nm; nm = NULL; + SAFE_DELETE(nm); if (k != K_ENTER) { - if (was == NULL) + if (was == nullptr) giochi.destroy(game); return false; } @@ -1558,7 +1564,8 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) gm.prima_nota(nreg); if (m.is_running()) m.set_focus(); #else - if (was == NULL) giochi.destroy(game); + if (was == nullptr) + giochi.destroy(game); return f.error_box(FR("Modificare il movimento %ld"), nreg); #endif } @@ -1580,7 +1587,8 @@ bool TGame_mask::edit_scadenza_handler(TMask_field& f, KEY k) f.error_box(TR("Utilizzare la gestione extra-contabile")); else f.error_box(FR("Modificare il movimento %ld"), nreg); - if (was == NULL) giochi.destroy(game); + if (was == nullptr) + giochi.destroy(game); return FALSE; } #endif @@ -1626,8 +1634,9 @@ bool TGame_mask::nuovo_handler(TMask_field& f, KEY k) const bool allow_fatt = FALSE; #endif - static TNew_mask* new_game = NULL; - if (new_game == NULL) + static TNew_mask* new_game = nullptr; + + if (new_game == nullptr) new_game = new TNew_mask(gm.conto().tipo(), allow_fatt, true); else new_game->init(gm.conto().tipo(), allow_fatt, true); @@ -1949,10 +1958,11 @@ void TGame_mask::fill_partite() const bool all = get(P_SHOWALL).not_empty(); // Visualizza anche partite chiuse partite().destroy(); - TString_array& a = partite().rows_array(); - + + TString_array& a = partite().rows_array(); TPartite_array& giochi = app().partite(); - for (TPartita* gioco = giochi.first(); gioco != NULL; gioco = giochi.next()) + + for (TPartita* gioco = giochi.first(); gioco != nullptr; gioco = giochi.next()) { // Visualizza solo le partite con almeno una riga! Non posso scaricarle a priori in quanto // potrebbero essere state cancellate proprio ora e quindi devo tenerle cosi' per aggiornare @@ -2020,7 +2030,8 @@ void TGame_mask::fill_partite() found = r; TPartita* gioco = app().partite().exist(conto(), anno, numero); - if (gioco != NULL && gioco->mov2rig(_numreg, _numrig) > 0) + + if (gioco != nullptr && gioco->mov2rig(_numreg, _numrig) > 0) { COLOR back, fore; app().type2colors('X', back, fore); @@ -2053,8 +2064,9 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co oldpag.get_real(PAGSCA_RITSOC).is_zero(); // We must create masks on the heap - static TPay_mask* pm = NULL; - if (pm == NULL) + static TPay_mask* pm = nullptr; + + if (pm == nullptr) pm = new TPay_mask(this, nuovo ? MODE_INS : MODE_MOD); else pm->init(this, nuovo ? MODE_INS : MODE_MOD); @@ -2117,9 +2129,6 @@ bool TGame_mask::edit_pagamento(TPartita& p, int nriga, int nrata, int nrigp) co app().notify_edit_pagamento(p, newpag, val); #endif } - - // delete pm; pm = NULL; // commentata in quanto statica - #ifdef __EXTRA__ xvtil_statbar_set(TR("Estratto conto"), true); #endif @@ -2171,7 +2180,8 @@ static bool genera_riferimento(int riga, TString& rif) if (field.file() == LF_MOV) { const TMask_field* mf = mov_mask.find_by_fieldname(field.name()); - if (mf != NULL) + + if (mf != nullptr) { val = mf->get(); if (field.to() > 0) @@ -2183,7 +2193,8 @@ static bool genera_riferimento(int riga, TString& rif) { TMask& row_mask = app().cgs().sheet_row_mask(riga); const TMask_field* rf = row_mask.find_by_fieldname(field.name()); - if (rf != NULL) + + if (rf != nullptr) { val = rf->get(); if (field.to() > 0) @@ -2265,8 +2276,9 @@ bool TPrimanota_application::edit_partite(const TMask& m, int riga) if (_easy_sal) { // Nuova maschera di gestione partite - static TEasySolder_mask* mask = NULL; - if (mask == NULL) + static TEasySolder_mask* mask = nullptr; + + if (mask == nullptr) mask = new TEasySolder_mask(b, numreg, riga+1); else mask->init(b, numreg, riga+1); @@ -2275,8 +2287,9 @@ bool TPrimanota_application::edit_partite(const TMask& m, int riga) else { // Maschera tradizionale di gestione partite - static TGame_mask* mask = NULL; - if (mask == NULL) + static TGame_mask* mask = nullptr; + + if (mask == nullptr) mask = new TGame_mask(b, numreg, riga+1); else mask->init(b, numreg, riga+1); diff --git a/src/cg/cg2106.cpp b/src/cg/cg2106.cpp index 13fbc4d0b..b81a0b927 100755 --- a/src/cg/cg2106.cpp +++ b/src/cg/cg2106.cpp @@ -91,7 +91,7 @@ void TColor_mask::load_props() a.type2colors(*k, back, fore); prop[0] = *k; prop[1] = '\0'; - ps.set_property(prop, (const char*)NULL, desc[d]); + ps.set_property(prop, (const char*)nullptr, desc[d]); prop[0] = *k; prop[1] = '_'; prop[2] = 'B'; ps.set_property(prop, back, TR("Sfondo")); @@ -188,7 +188,8 @@ COLOR TPrimanota_application::type2color(char tipor, char tipoc) { const char key[3] = { tipoc, tipor, '\0' }; TString* colstr = (TString*)_colori.objptr(key); - if (colstr == NULL) + + if (colstr == nullptr) { colstr = new TString(8); if (tipor == 'X') @@ -212,7 +213,8 @@ void TPrimanota_application::set_type_color(char tipor, char tipoc, COLOR col) { const char key[3] = { tipoc, tipor, '\0' }; TString* colstr = (TString*)_colori.objptr(key); - if (colstr == NULL) + + if (colstr == nullptr) { colstr = new TString(8); _colori.add(key, colstr); diff --git a/src/cg/cg2107.cpp b/src/cg/cg2107.cpp index b5d5b77e9..a94be1a20 100755 --- a/src/cg/cg2107.cpp +++ b/src/cg/cg2107.cpp @@ -8,6 +8,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////// // TNew_game_mask @@ -90,42 +91,6 @@ void TEasySolder_mask::set_imp(short id, const TImporto& imp) e.reset(); } -#define get_row_bool(sheet, row, id) (row).get_char(sheet.cid2index(id))=='X' -#define get_row_int(sheet, row, id) (row).get_int(sheet.cid2index(id)) -#define get_row_str(sheet, row, id) (row).get(sheet.cid2index(id)) -#define get_row_real(sheet, row, id) real((row).get(sheet.cid2index(id))) - -#define set_row_bool(sheet, row, id, n) (row).add(n ? "X" : "", sheet.cid2index(id)) -#define set_row_int(sheet, row, id, n) (row).add(n, sheet.cid2index(id)) -#define set_row_str(sheet, row, id, n) (row).add(n, sheet.cid2index(id)) - -static bool set_row_currency(const TSheet_field& sheet, TToken_string& row, short id, const real& n) -{ - const TMask& m = sheet.sheet_mask(); - const TCurrency_field& cf = (const TCurrency_field&)m.field(id); - TOperable_field* vf = cf.driver(0); - if (vf != NULL && !vf->empty()) // E' un importo in valuta? - { - const TString& codval = vf->get(); - if (is_true_value(codval)) // La valuta e' diversa dall'euro? - { - if (n.is_zero()) - set_row_str(sheet, row, id, ""); - else - { - const TCurrency cur(n, codval); - set_row_str(sheet, row, id, cur.get_num().string()); - } - return true; - } - } - if (n.is_zero()) - set_row_str(sheet, row, id, ""); - else - set_row_str(sheet, row, id, n.string(-1, 2)); - return false; -} - void TEasySolder_mask::save_sheet() { // Memorizza i dati del cambio da salvare sulle righe di partita @@ -137,27 +102,30 @@ void TEasySolder_mask::save_sheet() FOR_EACH_SHEET_ROW(s, r, row_ptr) { TToken_string& row = *row_ptr; - const int anno = get_row_int(s, row, S_ANNO); - const TString8 numpart = get_row_str(s, row, S_PARTITA); - const int rigaf = get_row_int(s, row, S_RIGAF); - const int nrata = get_row_int(s, row, S_RATA); + + const int anno = s.get_int_row_cell(row, S_ANNO); + const TString8 numpart = s.get_str_row_cell(row, S_PARTITA); + const int rigaf = s.get_int_row_cell(row, S_RIGAF); + const int nrata = s.get_int_row_cell(row, S_RATA); const bool goodrat = nrata > 0 && nrata < TPartita::UNASSIGNED; - int nrigp = get_row_int(s, row, S_RIGAP); - const real importo = get_row_real(s, row, S_IMPORTO); - const real ritfis = valuta.in_valuta() ? ZERO : get_row_real(s, row, S_RITFIS); - const real ritsoc = valuta.in_valuta() ? ZERO : get_row_real(s, row, S_RITSOC); - const bool a_saldo = goodrat && get_row_bool(s, row, S_SALDO); - const TTipo_pag tipopag = (TTipo_pag)get_row_int(s, row, S_MODOPAG); - const TDate datapag = get_row_str(s, row, S_DATAPAG); + int nrigp = s.get_int_row_cell(row, S_RIGAP); + const real importo = s.get_real_row_cell(row, S_IMPORTO); + const real ritfis = valuta.in_valuta() ? ZERO : s.get_real_row_cell(row, S_RITFIS); + const real ritsoc = valuta.in_valuta() ? ZERO : s.get_real_row_cell(row, S_RITSOC); + const bool a_saldo = goodrat && s.get_bool_row_cell(row, S_SALDO); + const TTipo_pag tipopag = (TTipo_pag) s.get_int_row_cell(row, S_MODOPAG); + const TDate datapag = s.get_date_row_cell(row, S_DATAPAG); if (a_saldo || !importo.is_zero() || !ritfis.is_zero() || !ritsoc.is_zero() || nrigp > 0) { TPartita& partita = app().partite().partita(_conto, anno, numpart); + if (nrigp <= 0) { TRiga_partite& part = partita.new_row(); // Creazione nuova riga vuota + nrigp = part.get_int(PART_NRIGA); // Nuova riga - set_row_int(s, row, S_RIGAP, nrigp); + s.set_row_cell(row, S_RIGAP, nrigp); part.put(PART_SEZ, calcola_sezione()); } @@ -191,9 +159,10 @@ void TEasySolder_mask::save_sheet() if (valuta.in_valuta()) { - newpag.put(PAGSCA_IMPORTOVAL, importo); - const real impeur = get_row_str(s, row, S_IMPORTO_EUR); - newpag.put(PAGSCA_IMPORTO, impeur); + const real impeur = s.get_real_row_cell(row, S_IMPORTO_EUR); + + newpag.put(PAGSCA_IMPORTOVAL, importo); + newpag.put(PAGSCA_IMPORTO, impeur); } else { @@ -237,7 +206,8 @@ long TEasySolder_mask::handler(WINDOW w, EVENT* ep) { if (s->parent() == w && s->point2cell(ep->v.mouse.where, id, rec) && rec < 0) { - const char* st = NULL; + const char* st = nullptr; + switch (id) { case S_DATADOC : @@ -385,6 +355,7 @@ real TEasySolder_mask::eur2val(const real& eur) const const TMask& mm = app().curr_mask(); const real toteur = mm.get(F_TOTALE); const real totval = mm.get(SK_TOTDOCVAL); + if (toteur.is_zero() || totval.is_zero()) { const TValuta valuta(mm, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO); @@ -401,6 +372,7 @@ real TEasySolder_mask::eur2val(const real& eur) const TImporto TEasySolder_mask::eur2val(const TImporto& imp) const { TImporto eur = imp; + eur.valore() = eur2val(imp.valore()); return eur; } @@ -441,11 +413,12 @@ bool TEasySolder_mask::on_field_event(TOperable_field& o, TField_event e, long j { TSheet_field& s = (TSheet_field&)o; TToken_string& row = s.row(jolly); - _anno = get_row_int(s, row, S_ANNO); - _numpart = get_row_str(s, row, S_PARTITA); - const int rigaf = get_row_int(s, row, S_RIGAF); - const int nrata = get_row_int(s, row, S_RATA); - const int nrigp = get_row_int(s, row, S_RIGAP); + + _anno = s.get_int_row_cell(row, S_ANNO); + _numpart = s.get_str_row_cell(row, S_PARTITA); + const int rigaf = s.get_int_row_cell(row, S_RIGAF); + const int nrata = s.get_int_row_cell(row, S_RATA); + const int nrigp = s.get_int_row_cell(row, S_RIGAP); if (_tree->goto_single_game(_anno, _numpart, rigaf, nrata, nrigp)) { @@ -459,6 +432,7 @@ bool TEasySolder_mask::on_field_event(TOperable_field& o, TField_event e, long j case se_query_add: { TNew_game_mask m(_conto); + if (m.run() == K_ENTER) { // Memorizzo il codice partita in modo da poterlo mettere nella nuova riga @@ -474,10 +448,11 @@ bool TEasySolder_mask::on_field_event(TOperable_field& o, TField_event e, long j // Metto nella nuova riga il codice partita memorizzato sopra TSheet_field& sheet = (TSheet_field&)o; TToken_string& row = sheet.row(jolly); - set_row_int(sheet, row, S_ANNO, _anno); - set_row_str(sheet, row, S_PARTITA, _numpart); - set_row_int(sheet, row, S_RIGAF, TPartita::UNASSIGNED); - set_row_int(sheet, row, S_RATA, TPartita::UNASSIGNED); + + sheet.set_row_cell(row, S_ANNO, _anno); + sheet.set_row_cell(row, S_PARTITA, _numpart); + sheet.set_row_cell(row, S_RIGAF, TPartita::UNASSIGNED); + sheet.set_row_cell(row, S_RATA, TPartita::UNASSIGNED); sheet.disable_cell(jolly, S_SALDO); } break; @@ -644,7 +619,8 @@ static int nrigp_pagamento_locale(const TSolder_tree& st) if (level == 3) { const TRiga_scadenze* scad = st.scadenza(); - if (scad != NULL) // Vera scadenza + + if (scad != nullptr) // Vera scadenza { for (int nrigp = scad->last(); nrigp > 0; nrigp = scad->pred(nrigp)) { @@ -687,7 +663,6 @@ static int has_lonely_nc(TPartita& game) return ncs; } - // Aggiunge una nota di credito non associata a fattura static bool add_lonely_nc(TPartita& game, TSheet_field& sheet, int rigasheet) { @@ -703,27 +678,29 @@ static bool add_lonely_nc(TPartita& game, TSheet_field& sheet, int rigasheet) TImporto res = game.calcola_saldo(true); res.normalize(expected_section); - set_row_currency(sheet, row, S_RESIDUO, res.valore()); + sheet.set_row_cell_currency(row, S_RESIDUO, res.valore()); TImporto tot = riga.importo(true); + tot.normalize(expected_section); - set_row_currency(sheet, row, S_TOTALE, tot.valore()); + sheet.set_row_cell_currency(row, S_TOTALE, tot.valore()); - set_row_int(sheet, row, S_ANNO, game.anno()); - set_row_str(sheet, row, S_PARTITA, game.numero()); - set_row_int(sheet, row, S_RIGAF, TPartita::UNASSIGNED); - set_row_int(sheet, row, S_RATA, TPartita::UNASSIGNED); - set_row_int(sheet, row, S_RIGAP, 0); // Lasciare 0 e NON mettere assultamente nrigp o la scambia per pagamento! - set_row_str(sheet, row, S_DATASCAD, riga.get(PART_DATAPAG)); + sheet.set_row_cell(row, S_ANNO, game.anno()); + sheet.set_row_cell(row, S_PARTITA, game.numero()); + sheet.set_row_cell(row, S_RIGAF, TPartita::UNASSIGNED); + sheet.set_row_cell(row, S_RATA, TPartita::UNASSIGNED); + sheet.set_row_cell(row, S_RIGAP, 0); // Lasciare 0 e NON mettere assultamente nrigp o la scambia per pagamento! + sheet.set_row_cell(row, S_DATASCAD, riga.get(PART_DATAPAG)); if (game.in_valuta()) { - row.add(game.codice_valuta(), sheet.cid2index(S_VALUTA)); TImporto reseur = riga.importo(false); - reseur.normalize(expected_section); - set_row_currency(sheet, row, S_RESIDUO_EUR, reseur.valore()); + + sheet.set_row_cell(row, S_VALUTA, game.codice_valuta()); + reseur.normalize(expected_section); + sheet.set_row_cell_currency(row, S_RESIDUO_EUR, reseur.valore()); } - set_row_str(sheet, row, S_NUMDOC, riga.get(PART_NUMDOC)); - set_row_str(sheet, row, S_DATADOC, riga.get(PART_DATADOC)); + sheet.set_row_cell(row, S_NUMDOC, riga.get(PART_NUMDOC)); + sheet.set_row_cell(row, S_DATADOC, riga.get(PART_DATADOC)); const int nrow = sheet.items()-1; sheet.disable_cell(nrow, S_SALDO); @@ -752,8 +729,9 @@ bool TEasySolder_mask::sheet_rate_filler(TTree& tree, void* jolly, word /* flags bool good_rat = level >= 3 && nrata > 0 && nrata < TPartita::UNASSIGNED; bool good_pag = level == 4 && nrigp > 0; - const TRiga_scadenze* scad = good_rat ? st.scadenza() : NULL; - if (good_rat && scad == NULL) + const TRiga_scadenze* scad = good_rat ? st.scadenza() : nullptr; + + if (good_rat && scad == nullptr) { CHECKD(false, "Rata nulla inattesa ", nrata); // Segnalazione 1867 return false; @@ -812,37 +790,40 @@ bool TEasySolder_mask::sheet_rate_filler(TTree& tree, void* jolly, word /* flags res = scad->residuo(true); res.normalize(rat_section); } - set_row_currency(sheet, row, S_RESIDUO, res.valore()); + sheet.set_row_cell_currency(row, S_RESIDUO, res.valore()); const TImporto tot = scad->importo(true); - set_row_currency(sheet, row, S_TOTALE, tot.valore()); - set_row_int(sheet, row, S_ANNO, game.anno()); - set_row_str(sheet, row, S_PARTITA, game.numero()); - set_row_int(sheet, row, S_RIGAF, nriga); - set_row_int(sheet, row, S_RATA, nrata); - set_row_str(sheet, row, S_DATASCAD, scad->get(SCAD_DATASCAD)); - set_row_str(sheet, row, S_MODOPAG, scad->get(SCAD_TIPOPAG)); // Solo proposta + sheet.set_row_cell_currency(row, S_TOTALE, tot.valore()); + sheet.set_row_cell(row, S_ANNO, game.anno()); + sheet.set_row_cell(row, S_PARTITA, game.numero()); + sheet.set_row_cell(row, S_RIGAF, nriga); + sheet.set_row_cell(row, S_RATA, nrata); + sheet.set_row_cell(row, S_DATASCAD, scad->get_date(SCAD_DATASCAD)); + sheet.set_row_cell(row, S_MODOPAG, scad->get(SCAD_TIPOPAG)); // Solo proposta if (game.in_valuta()) { // Calcola il residuo rata utilizzando il cambio della fattura e non quello del pagamento const TImporto reseur = tm == tm_insoluto ? scad->importo_pagato(false) : scad->residuo(false); - set_row_currency(sheet, row, S_RESIDUO_EUR, reseur.valore()); + + sheet.set_row_cell_currency(row, S_RESIDUO_EUR, reseur.valore()); } if (nriga > 0 && nriga < TPartita::UNASSIGNED) // Dovrebbe sempre essere vero, ma ... { const TRiga_partite& riga = game.riga(nriga); - set_row_str(sheet, row, S_NUMDOC, riga.get(PART_NUMDOC)); - set_row_str(sheet, row, S_DATADOC, riga.get(PART_DATADOC)); - - set_row_str(sheet, row, S_NOTE, scad->get(SCAD_DESCR)); + + sheet.set_row_cell(row, S_NUMDOC, riga.get(PART_NUMDOC)); + sheet.set_row_cell(row, S_DATADOC, riga.get(PART_DATADOC)); + sheet.set_row_cell(row, S_NOTE, scad->get(SCAD_DESCR)); if (scad->get_bool(SCAD_BLOCCATA)) { - set_row_bool(sheet, row, S_BLOCCO, true); + sheet.set_row_cell(row, S_BLOCCO, true); sheet.disable_cell(sheet.items()-1, -1); + const TString8 cbp = scad->get(SCAD_MOTIVO); + if (cbp.full()) { - set_row_str(sheet, row, S_MOTIVO, cbp); - set_row_str(sheet, row, S_NOTE, cache().get("%CBP", cbp, "S0")); + sheet.set_row_cell(row, S_MOTIVO, cbp); + sheet.set_row_cell(row, S_NOTE, cache().get("%CBP", cbp, "S0")); } } } @@ -851,13 +832,15 @@ bool TEasySolder_mask::sheet_rate_filler(TTree& tree, void* jolly, word /* flags if (!good_pag) { TDate dp(TODAY); + if (scad->get_int(SCAD_TIPOPAG) > 1) { - const TDate ds = scad->get(SCAD_DATASCAD); + const TDate ds = scad->get_date(SCAD_DATASCAD); + if (ds > dp) dp = ds; } - set_row_str(sheet, row, S_DATAPAG, dp); + sheet.set_row_cell(row, S_DATAPAG, dp); } } if (good_pag) @@ -866,42 +849,45 @@ bool TEasySolder_mask::sheet_rate_filler(TTree& tree, void* jolly, word /* flags add_lonely_nc(game, sheet, sheet.items()-1); const TRiga_partite& rigp = game.riga(nrigp); - set_row_int(sheet, row, S_RIGAP, nrigp); - set_row_int(sheet, row, S_NREG, rigp.get_long(PART_NREG)); - set_row_int(sheet, row, S_NRIG, rigp.get_int(PART_NUMRIG)); + + sheet.set_row_cell(row, S_RIGAP, nrigp); + sheet.set_row_cell(row, S_NREG, rigp.get_long(PART_NREG)); + sheet.set_row_cell(row, S_NRIG, rigp.get_int(PART_NUMRIG)); const TRectype& pag = *st.pagamento(); const real imp = pag.get_real(PAGSCA_IMPORTO); + if (!imp.is_zero()) { - set_row_bool(sheet, row, S_SPUNTA, true); + sheet.set_row_cell(row, S_SPUNTA, true); if (rigp.in_valuta()) { const real impval = pag.get_real(PAGSCA_IMPORTOVAL); - set_row_currency(sheet, row, S_IMPORTO, impval); - set_row_currency(sheet, row, S_IMPORTO_EUR, imp); + + sheet.set_row_cell_currency(row, S_IMPORTO, impval); + sheet.set_row_cell_currency(row, S_IMPORTO_EUR, imp); } else - set_row_currency(sheet, row, S_IMPORTO, imp); + sheet.set_row_cell_currency(row, S_IMPORTO, imp); } - set_row_str(sheet, row, S_SALDO, (good_rat && pag.get_char(PAGSCA_ACCSAL)=='S') ? "X" : ""); - set_row_int(sheet, row, S_MODOPAG, rigp.get_int(PART_TIPOPAG)); - set_row_currency(sheet, row, S_RITFIS, pag.get_real(PAGSCA_RITENUTE)); - set_row_currency(sheet, row, S_RITSOC, pag.get_real(PAGSCA_RITSOC)); + sheet.set_row_cell(row, S_SALDO, (good_rat && pag.get_char(PAGSCA_ACCSAL)=='S') ? "X" : ""); + sheet.set_row_cell(row, S_MODOPAG, rigp.get_int(PART_TIPOPAG)); + sheet.set_row_cell_currency(row, S_RITFIS, pag.get_real(PAGSCA_RITENUTE)); + sheet.set_row_cell_currency(row, S_RITSOC, pag.get_real(PAGSCA_RITSOC)); - set_row_int(sheet, row, S_ANNO, game.anno()); - set_row_str(sheet, row, S_PARTITA, game.numero()); - set_row_int(sheet, row, S_RIGAF, nriga); - set_row_int(sheet, row, S_RATA, nrata); - set_row_str(sheet, row, S_MODOPAG, rigp.get(PART_TIPOPAG)); + sheet.set_row_cell(row, S_ANNO, game.anno()); + sheet.set_row_cell(row, S_PARTITA, game.numero()); + sheet.set_row_cell(row, S_RIGAF, nriga); + sheet.set_row_cell(row, S_RATA, nrata); + sheet.set_row_cell(row, S_MODOPAG, rigp.get(PART_TIPOPAG)); if (good_rat) - { - set_row_str(sheet, row, S_DATAPAG, rigp.get(PART_DATAPAG)); - } + sheet.set_row_cell(row, S_DATAPAG, rigp.get_date(PART_DATAPAG)); else { - set_row_str(sheet, row, S_DATASCAD, rigp.get(PART_DATAPAG)); + sheet.set_row_cell(row, S_DATASCAD, rigp.get_date(PART_DATAPAG)); + const int nrow = sheet.items()-1; + sheet.disable_cell(nrow, S_SALDO); } } @@ -997,14 +983,14 @@ void TEasySolder_mask::calcola_residuo() { if (in_val) { - _tot_val += get_row_real(s, *row, S_IMPORTO); - _tot_eur += get_row_real(s, *row, S_IMPORTO_EUR); + _tot_val += s.get_real_row_cell(*row, S_IMPORTO); + _tot_eur += s.get_real_row_cell(*row, S_IMPORTO_EUR); } else { - _tot_eur += get_row_real(s, *row, S_IMPORTO); - _tot_eur += get_row_real(s, *row, S_RITFIS); - _tot_eur += get_row_real(s, *row, S_RITSOC) * segno_ritsoc; + _tot_eur += s.get_real_row_cell(*row, S_IMPORTO); + _tot_eur += s.get_real_row_cell(*row, S_RITFIS); + _tot_eur += s.get_real_row_cell(*row, S_RITSOC) * segno_ritsoc; _tot_val = _tot_eur; } @@ -1013,9 +999,9 @@ void TEasySolder_mask::calcola_residuo() void TEasySolder_mask::aggiorna_residuo() { - const TCausale& caus = app().causale(); + const TCausale & caus = app().causale(); const real segno_ritsoc = caus.sezione_clifo() == caus.sezione_ritsoc() ? UNO : -UNO; - const TSheet_field& s = sfield(G_SHEET); + TSheet_field & s = sfield(G_SHEET); const bool in_val = in_valuta(); real totval, toteur; @@ -1023,16 +1009,16 @@ void TEasySolder_mask::aggiorna_residuo() { if (in_val) { - totval += get_row_real(s, *row, S_IMPORTO); - toteur += get_row_real(s, *row, S_IMPORTO_EUR); + totval += s.get_real_row_cell(*row, S_IMPORTO); + toteur += s.get_real_row_cell(*row, S_IMPORTO_EUR); } else { - toteur += get_row_real(s, *row, S_IMPORTO); + toteur += s.get_real_row_cell(*row, S_IMPORTO); // Gestisco le ritenute solo per i movimenti in Euro - toteur += get_row_real(s, *row, S_RITFIS); // Ritfis ha sempre la sezione dell'importo - toteur += get_row_real(s, *row, S_RITSOC) * segno_ritsoc; // Ritsoc puo' avere segno contrario + toteur += s.get_real_row_cell(*row, S_RITFIS); // Ritfis ha sempre la sezione dell'importo + toteur += s.get_real_row_cell(*row, S_RITSOC) * segno_ritsoc; // Ritsoc puo' avere segno contrario } } @@ -1050,7 +1036,8 @@ void TEasySolder_mask::aggiorna_residuo() void TEasySolder_mask::fill_sheet() { TSheet_field& s = sfield(G_SHEET); - s.destroy(); + + s.destroy(); const TString& codval = get(G_VALUTA); const real cambio = get(G_CAMBIO); @@ -1150,7 +1137,7 @@ void TEasySolder_mask::init(const TBill& conto, long numreg, int numrig) for (short id = G_ABI; id <= G_DESCONTOC; id++) show(id, _tipomov != tm_nota_credito); - if (_tree == NULL) + if (_tree == nullptr) { _tree = new TSolder_tree; tfield(G_PARTITE).set_tree(_tree); @@ -1160,12 +1147,11 @@ void TEasySolder_mask::init(const TBill& conto, long numreg, int numrig) } TEasySolder_mask::TEasySolder_mask(const TBill& conto, long numreg, int numrig) - : TAutomask("cg2100e"), _tree(NULL) + : TAutomask("cg2100e"), _tree(nullptr) { init(conto, numreg, numrig); } TEasySolder_mask::~TEasySolder_mask() { - if (_tree != NULL) - delete _tree; + SAFE_DELETE(_tree); } diff --git a/src/cg/cg21iva.uml b/src/cg/cg21iva.uml index a0ec7a18d..6126ec2f8 100755 --- a/src/cg/cg21iva.uml +++ b/src/cg/cg21iva.uml @@ -1,4 +1,4 @@ -PAGE "RIGA IVA" -1 -1 78 13 +PAGE "RIGA IVA" -1 -1 78 19 GROUPBOX DLG_NULL 76 5 BEGIN @@ -61,47 +61,53 @@ BEGIN FLAGS "D" END -STRING IVA_NATURIVA 4 -BEGIN - PROMPT 40 4 "Nat." - FLAGS "D" -END - CURRENCY IVA_IMPOSTA 18 BEGIN PROMPT 48 4 "Imposta " HELP "Importo dell'IVA. Se e' nullo, col tasto F8 si puo' effettuare lo scorporo" END +STRING IVA_NATURIVA 4 +BEGIN + PROMPT 2 6 "Natura" + FLAGS "D" +END + +BOOLEAN IVA_REVCHARGE +BEGIN + PROMPT 48 6 "Reverse charge" + FLAGS "D" +END + GROUPBOX DLG_NULL 76 5 BEGIN - PROMPT 1 6 "@BConto" + PROMPT 1 8 "@BConto" END LIST IVA_TIPO 1 12 BEGIN - PROMPT 2 7 "" + PROMPT 2 9 "" HELP "Tipo del conto" FIELD TIPOC ITEM " |Conto" - MESSAGE SHOW,109|HIDE,209|HIDE,309|SHOW,110|HIDE,210|HIDE,310 + MESSAGE SHOW,IVA_SOTTOCONTO|HIDE,IVA_CLIENTE|HIDE,IVA_FORNITORE|SHOW,IVA_DESCRCONTO|HIDE,IVA_DESCRCONTOC|HIDE,IVA_DESCRCONTOF ITEM "C|Cliente" - MESSAGE SHOW,209|HIDE,109|HIDE,309|SHOW,210|HIDE,110|HIDE,310 + MESSAGE SHOW,IVA_CLIENTE|HIDE,IVA_SOTTOCONTO|HIDE,IVA_FORNITORE|SHOW,IVA_DESCRCONTOC|HIDE,IVA_DESCRCONTO|HIDE,IVA_DESCRCONTOF ITEM "F|Fornitore" - MESSAGE SHOW,309|HIDE,109|HIDE,209|SHOW,310|HIDE,110|HIDE,210 + MESSAGE SHOW,IVA_FORNITORE|HIDE,IVA_SOTTOCONTO|HIDE,IVA_CLIENTE|SHOW,IVA_DESCRCONTOF|HIDE,IVA_DESCRCONTO|HIDE,IVA_DESCRCONTOC FLAGS "U" END NUMBER IVA_GRUPPO 3 BEGIN - PROMPT 22 7 "Gruppo " + PROMPT 22 9 "Gruppo " HELP "Codice del gruppo" FIELD GRUPPO END NUMBER IVA_CONTO 3 BEGIN - PROMPT 38 7 "Conto " + PROMPT 38 9 "Conto " FIELD CONTO USE LF_PCON SELECT (CONTO!="")&&(SOTTOCONTO="") INPUT GRUPPO IVA_GRUPPO @@ -113,9 +119,9 @@ BEGIN OUTPUT IVA_TIPO TMCF OUTPUT IVA_GRUPPO GRUPPO OUTPUT IVA_CONTO CONTO - OUTPUT 110 DESCR + OUTPUT IVA_DESCRCONTO DESCR ADD RUN cg0 -0 - MESSAGE DIRTY,109|DIRTY,209|DIRTY,309 + MESSAGE DIRTY,IVA_SOTTOCONTO|DIRTY,IVA_CLIENTE|DIRTY,IVA_FORNITORE CHECKTYPE NORMAL WARNING "Conto assente" END @@ -123,7 +129,7 @@ END NUMBER IVA_SOTTOCONTO 6 BEGIN - PROMPT 55 7 "Sottoconto " + PROMPT 55 9 "Sottoconto " FIELD SOTTOCONTO USE LF_PCON SELECT SOTTOCONTO!="" INPUT GRUPPO IVA_GRUPPO @@ -137,27 +143,26 @@ BEGIN OUTPUT IVA_SOTTOCONTO SOTTOCONTO OUTPUT IVA_GRUPPO GRUPPO OUTPUT IVA_CONTO CONTO - OUTPUT 110 DESCR + OUTPUT IVA_DESCRCONTO DESCR ADD RUN cg0 -0 CHECKTYPE NORMAL VALIDATE REQIF_FUNC 1 IVA_IMPONIBILE WARNING "Sottoconto assente" END - -NUMBER 209 6 +NUMBER IVA_CLIENTE 6 BEGIN - PROMPT 55 7 "Cliente " + PROMPT 55 9 "Cliente " HELP "Codice del cliente" USE LF_CLIFO INPUT TIPOCF "C" - INPUT CODCF 209 + INPUT CODCF IVA_CLIENTE DISPLAY "Codice" CODCF DISPLAY "Ragione Sociale Cliente@50" RAGSOC DISPLAY "Gruppo" GRUPPO DISPLAY "Conto" CONTO - OUTPUT 209 CODCF - OUTPUT 210 RAGSOC + OUTPUT IVA_CLIENTE CODCF + OUTPUT IVA_DESCRCONTOC RAGSOC CHECKTYPE NORMAL ADD RUN cg0 -1 C MESSAGE COPY,IVA_SOTTOCONTO @@ -165,17 +170,17 @@ BEGIN WARNING "Cliente assente" END -NUMBER 309 6 +NUMBER IVA_FORNITORE 6 BEGIN - PROMPT 55 7 "Fornitore " + PROMPT 55 9 "Fornitore " HELP "Codice del fornitore" USE LF_CLIFO INPUT TIPOCF "F" - INPUT CODCF 309 + INPUT CODCF IVA_FORNITORE DISPLAY "Codice" CODCF DISPLAY "Ragione Sociale Fornitore@50" RAGSOC - OUTPUT 309 CODCF - OUTPUT 310 RAGSOC + OUTPUT IVA_FORNITORE CODCF + OUTPUT IVA_DESCRCONTOF RAGSOC CHECKTYPE NORMAL ADD RUN cg0 -1 F MESSAGE COPY,IVA_SOTTOCONTO @@ -183,12 +188,12 @@ BEGIN WARNING "Fornitore assente" END -STRING 110 50 +STRING IVA_DESCRCONTO 50 BEGIN - PROMPT 2 8 "Descrizione " + PROMPT 2 10 "Descrizione " FIELD LF_PCON->DESCR USE LF_PCON KEY 2 - INPUT DESCR 110 + INPUT DESCR IVA_DESCRCONTO DISPLAY "Descrizione@50" DESCR DISPLAY "Gruppo" GRUPPO DISPLAY "Conto" CONTO @@ -198,41 +203,41 @@ BEGIN ADD RUN cg0 -0 END -STRING 210 50 +STRING IVA_DESCRCONTOC 50 BEGIN - PROMPT 2 8 "Cliente " + PROMPT 2 10 "Cliente " FIELD LF_CLIFO->RAGSOC USE LF_CLIFO KEY 2 INPUT TIPOCF "C" - INPUT RAGSOC 210 + INPUT RAGSOC IVA_DESCRCONTOC DISPLAY "Ragione Sociale Cliente@55" RAGSOC DISPLAY "Gruppo" GRUPPO DISPLAY "Conto" CONTO DISPLAY "Codice" CODCF - COPY OUTPUT 209 - MESSAGE COPY,110 + COPY OUTPUT IVA_CLIENTE + MESSAGE COPY,IVA_DESCRCONTO ADD RUN cg0 -1 C END -STRING 310 50 +STRING IVA_DESCRCONTOF 50 BEGIN - PROMPT 2 8 "Fornitore " + PROMPT 2 10 "Fornitore " FIELD LF_PCON->SOTTOCONTO USE LF_CLIFO KEY 2 INPUT TIPOCF "F" - INPUT RAGSOC 310 + INPUT RAGSOC IVA_DESCRCONTOF DISPLAY "Ragione Sociale Fornitore@55" RAGSOC DISPLAY "Gruppo" GRUPPO DISPLAY "Conto" CONTO DISPLAY "Codice" CODCF - COPY OUTPUT 309 - MESSAGE COPY,110 + COPY OUTPUT IVA_FORNITORE + MESSAGE COPY,IVA_DESCRCONTO ADD RUN cg0 -1 F END LIST IVA_TIPOCOSTORIC 2 51 BEGIN - PROMPT 2 9 "Tipo Costo/Ricavo " + PROMPT 2 11 "Tipo Costo/Ricavo " ITEM " |0. Acquisti o vendite in genere" ITEM "1|1. Acquisti beni per rivendita" ITEM "2|2. Acquisti beni ammortizzabili" @@ -241,14 +246,14 @@ BEGIN ITEM "5|5. Beni per rivendita da non ventilare" ITEM "8|8. Altri beni strumentali acquistati in leasing" ITEM "9|9. Spese generali" - ITEM "17|17. Operazioni nei confronti dei condominii" + ITEM "17|17. Operazioni nei confronti dei condominii" FLAGS "D" HELP "Tipo Costo/Ricavo del conto" END BOOLEAN IVA_NOTAVARECF BEGIN - PROMPT 2 15 "Nota di variazione riferita ad anni precedenti (per Elenco Clienti/Fornitori)" + PROMPT 2 17 "Nota di variazione riferita ad anni precedenti (per Elenco Clienti/Fornitori)" FIELD NOTAVARECF END diff --git a/src/cg/cg2200.cpp b/src/cg/cg2200.cpp index 88a953562..684eb0a71 100755 --- a/src/cg/cg2200.cpp +++ b/src/cg/cg2200.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include @@ -47,7 +48,7 @@ public: ~TProvvisori_msk(); }; -TProvvisori_msk* TProvvisori_msk::_msk = NULL; +TProvvisori_msk* TProvvisori_msk::_msk = nullptr; bool TProvvisori_msk::filter(const TRelation* rel) { @@ -96,9 +97,9 @@ TCursor& TProvvisori_msk::update_cursor(bool use_argv) _provv = main_app().argv(2)[0]; } - if (_rel == NULL) + if (_rel == nullptr) _rel = new TRelation(LF_MOV); - if (_cur == NULL) + if (_cur == nullptr) _cur = new TCursor(_rel, "", 2); TRectype from_rec(LF_MOV), to_rec(LF_MOV); @@ -137,7 +138,7 @@ TCursor_sheet* TProvvisori_msk::get_selection_sheet() sel_items = total; set(F_SELECTED, sel_items); // Aggiorno campo a video - return sel_items < total ? _sheet : NULL; // Ritorno NULL se tutti selezionati + return sel_items < total ? _sheet : nullptr; // Ritorno NULL se tutti selezionati } void TProvvisori_msk::update_search(short id, const TString& fil) @@ -185,7 +186,7 @@ bool TProvvisori_msk::on_field_event(TOperable_field& o, TField_event e, long jo case DLG_SELECT: if (e == fe_button) { - if (_sheet == NULL) // Devo creare sheet di delezione + if (_sheet == nullptr) // Devo creare sheet di delezione { TBrowse* br = efield(F_FROMREG).browse(); // Copia intestazione dal campo della maschera! TToken_string head = br->head(); head.insert("@1|"); // Aggiunge prima colonna di selezione @@ -196,7 +197,7 @@ bool TProvvisori_msk::on_field_event(TOperable_field& o, TField_event e, long jo update_cursor(); _sheet->run(); // Mostra sheet di selezione get_selection_sheet(); // Aggiorna F_SELECTED - return FALSE; + return false; } break; default: @@ -208,20 +209,17 @@ bool TProvvisori_msk::on_field_event(TOperable_field& o, TField_event e, long jo } TProvvisori_msk::TProvvisori_msk() - : TAutomask("cg2200a"), _sheet(NULL), _rel(NULL), _cur(NULL), _update_cursor(true) + : TAutomask("cg2200a"), _sheet(nullptr), _rel(nullptr), _cur(nullptr), _update_cursor(true) { _msk = this; } TProvvisori_msk::~TProvvisori_msk() { - _msk = NULL; - if (_sheet != NULL) - delete _sheet; - if (_cur) - delete _cur; - if (_rel) - delete _rel; + _msk = nullptr; + SAFE_DELETE(_sheet); + SAFE_DELETE(_cur); + SAFE_DELETE(_rel); } class TProvvisori_app : public TSkeleton_application @@ -242,8 +240,8 @@ public: void aggiorna_saldi(); void aggiorna_analitica(const long numreg); - bool confirm_provv(TCursor& cur, TProgind& pi, TCursor_sheet* sheet= NULL); - bool delete_provv(TCursor& cur, TProgind& pi, TCursor_sheet* sheet= NULL); + bool confirm_provv(TCursor& cur, TProgind& pi, TCursor_sheet* sheet= nullptr); + bool delete_provv(TCursor& cur, TProgind& pi, TCursor_sheet* sheet= nullptr); void auto_delete(TCursor& cur); @@ -257,7 +255,7 @@ inline TProvvisori_app& app() bool TProvvisori_app::create() { - open_files(LF_TAB, LF_MOV, LF_CAUSALI, LF_SALDI, NULL); + open_files(LF_TAB, LF_MOV, LF_CAUSALI, LF_SALDI, nullptr); return TSkeleton_application::create(); } @@ -327,7 +325,7 @@ bool TProvvisori_app::confirm_provv(TCursor& cur, TProgind& pi, TCursor_sheet* s TLocalisamfile rmov(LF_RMOV); if (sheet && sheet->checked() == 0) - sheet = NULL; + sheet = nullptr; for (cur = 0; cur.pos() < cur.items(); ++cur) { @@ -372,7 +370,7 @@ bool TProvvisori_app::delete_provv(TCursor& cur, TProgind& pi, TCursor_sheet* sh TLocalisamfile rmoviva(LF_RMOVIVA); if (sheet && sheet->checked() == 0) - sheet = NULL; + sheet = nullptr; TString error(256); diff --git a/src/cg/cg2300.cpp b/src/cg/cg2300.cpp index 422e4e968..3ed788090 100644 --- a/src/cg/cg2300.cpp +++ b/src/cg/cg2300.cpp @@ -127,10 +127,9 @@ void TCompetenze_mask::fill_contc() sf.hide(); sf.reset(); - _conts.clear(); // Per ogni registrazione - for (int i = 0; i < _regs.size(); ++i) + for (int i = 0; i < (int)_regs.size(); ++i) { const int numreg = _regs[i]; rmovs.zero(); @@ -209,13 +208,14 @@ void TCompetenze_mask::fill() const TDate dataini(1, mese, anno); TDate dataend(dataini); dataend.set_end_month(); movs.put(MOV_DATAREG, dataini); - if (movs.read() != NULL) + if (movs.read() != NOERR) { for (; movs.next() == NOERR && movs.get_date(MOV_DATAREG) <= dataend; ) { const int month_liq = movs.get_int(MOV_MESELIQ); const TDate datareg(movs.get(MOV_DATAREG)); const TDate datacomp(movs.get(MOV_DATACOMP)); + if (month_liq != 0) { _regs.insert(_regs.end(), movs.get_int(MOV_NUMREG)); diff --git a/src/cg/cglib01.cpp b/src/cg/cglib01.cpp index c97e3ed50..8f3a0e91b 100755 --- a/src/cg/cglib01.cpp +++ b/src/cg/cglib01.cpp @@ -416,7 +416,7 @@ bool TRegistro::read(const char* cod, int year) const TDate oggi(TODAY); year = oggi.year(); } - if (cod == NULL) + if (cod == nullptr) cod = ""; TString8 chiave; chiave.format("%04d%s", year, cod); @@ -537,7 +537,8 @@ real* TRegistro::read_prorata(int anno) const chiave.format("%05ld", prefix().get_codditta()); chiave << anno << attivita() << "1"; - real* prorata = NULL; + real* prorata = nullptr; + const TRectype& pla = cache().get("%PLA", chiave); if (!pla.empty()) prorata = new real(pla.get("R8")); @@ -554,13 +555,13 @@ real TRegistro::prorata(int annodoc) TString16 chiave; chiave << annopro; real* pr = (real*)_prorata.objptr(chiave); - if (pr == NULL) + if (pr == nullptr) { pr = read_prorata(annopro); - if (pr == NULL && annopro != annoiva) + if (pr == nullptr && annopro != annoiva) pr = read_prorata(annoiva); - if (pr == NULL) + if (pr == nullptr) pr = new real(ZERO); _prorata.add(chiave, pr, true); } @@ -715,7 +716,7 @@ real TCodiceIVA::scorpora(real& lordo, int ndec, const char* codval) const real TCodiceIVA::lordo(const real& imponibile, int ndec, const char* codval) const { return imponibile + imposta(imponibile, ndec, codval); } -bool TCodiceIVA::reverse_charge() const +/* bool TCodiceIVA::reverse_charge() const { const int rsi = regime_speciale(); return rsi == 13 || rsi == 50 || rsi == 51; // Reverse charge! @@ -725,7 +726,7 @@ bool TCodiceIVA::reverse_charge_pubb() const { const int rsi = regime_speciale(); return rsi == 13 || rsi == 19 || rsi == 50 || rsi == 51; // Reverse charge! con aggiunta dienti pubblici -} +} */ /////////////////////////////////////////////////////////// // TBill @@ -760,7 +761,7 @@ const TBill& TBill::get(TToken_string& s, int from, int mode) else _tipo = ' '; - if (strchr(" CF", _tipo) == NULL) + if (strchr(" CF", _tipo) == nullptr) { #ifdef DBG error_box(FR("Tipo conto errato: '%c'"), _tipo); @@ -831,41 +832,40 @@ const char* TBill::field_name(int n, const TRectype& r, bool contro) const { CHECKD(n >= 0 && n <= 3, "Invalid bill field ", n); - const char* f = NULL; if (contro) { CHECKD(r.num() == LF_RMOV || r.num() == LF_PAGSCA, "Record non valido per contropartita: ", r.num()); switch(n) { - case 0: f = RMV_GRUPPOC; break; - case 1: f = RMV_CONTOC; break; - case 2: f = RMV_SOTTOCONTOC; break; - default:f = RMV_TIPOCC; break; + case 0: return RMV_GRUPPOC; break; + case 1: return RMV_CONTOC; break; + case 2: return RMV_SOTTOCONTOC; break; + default:return RMV_TIPOCC; break; } } else { switch(n) { - case 0: f = RMV_GRUPPO; break; - case 1: f = RMV_CONTO; break; + case 0: return RMV_GRUPPO; break; + case 1: return RMV_CONTO; break; case 2: if (r.num() == LF_CLIFO) - f = CLI_CODCF; + return CLI_CODCF; else - f = RMV_SOTTOCONTO; + return RMV_SOTTOCONTO; break; default: switch(r.num()) { - case LF_CLIFO : f = CLI_TIPOCF; break; - case LF_RCAUSALI: f = RCA_TIPOCF; break; - default : f = RMV_TIPOC; break; + case LF_CLIFO : return CLI_TIPOCF; break; + case LF_RCAUSALI: return RCA_TIPOCF; break; + default : return RMV_TIPOC; break; } break; } } - return f; + return ""; } void TBill::put(TRectype& r, bool c) const @@ -887,7 +887,7 @@ bool TBill::get(const TRectype& r, bool c) r.get_long(field_name(2, r, c)), t); - set_description(NULL); + set_description(nullptr); _tipo_cr = -1; _sezione = ' '; @@ -1059,8 +1059,9 @@ int TBill::tipo_att() const TString& TBill::descrizione() const { TBill& myself = (TBill&)*this; + // Se il conto e' valido (c'e' almeno il gruppo) cerca la sua descrizione su file - if ((_descrizione == NULL || _descrizione->blank()) && + if ((_descrizione == nullptr || _descrizione->blank()) && (gruppo() != 0 || (tipo() > ' ' && codclifo()>0))) { if (!myself.find()) @@ -1223,4 +1224,3 @@ const char* num2str(const TString& s) } return (const char*)str; } - diff --git a/src/cg/cglib01.h b/src/cg/cglib01.h index 32806ce55..0482823cc 100755 --- a/src/cg/cglib01.h +++ b/src/cg/cglib01.h @@ -162,19 +162,20 @@ public: // TObject bool sospeso() const { return get_bool("B2"); } bool escluso_esenti() const { return get_bool("B5"); } bool numeratore_pro_rata() const { return get_bool("B6"); } - bool denominatore_pro_rata() const { return get_bool("B7"); } + bool denominatore_pro_rata() const { return get_bool("B7"); } + bool reverse_charge_attivo() const { return get_bool("B8"); } real imposta(const real& imponibile, int ndec = AUTO_DECIMALS, const char * codval = "") const; // Calcola l'imposta sull'imponibile l'imposta e la ritorna real scorpora(real& imponibile, int ndec = AUTO_DECIMALS, const char * codval = "") const; // Scorpora dall'imponibile l'imposta e la ritorna real lordo(const real& imponibile, int ndec = AUTO_DECIMALS, const char * codval = "") const; // Calcola il lordo dell'imponibile l'imposta e la ritorna - bool reverse_charge() const; - bool reverse_charge_pubb() const; +// bool reverse_charge() const; +// bool reverse_charge_pubb() const; int regime_speciale() const { return get_int("I5");} const TString& natura() const { return get("S12"); } - TCodiceIVA(const char* codice = NULL); + TCodiceIVA(const char* codice = nullptr); TCodiceIVA(const TRectype & rec) : TRectype(rec) {} TCodiceIVA(const TCodiceIVA & iva) : TRectype(iva) {} virtual ~TCodiceIVA() {} @@ -205,27 +206,27 @@ public: // TObject virtual bool ok() const; // Gruppo, Conto e Sottoconto non nulli public: - TBill(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, int r = -1) - : _tipo(t), _gruppo(g), _conto(c), _sottoconto(s), _descrizione(NULL), + TBill(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = nullptr, int r = -1) + : _tipo(t), _gruppo(g), _conto(c), _sottoconto(s), _descrizione(nullptr), _sezione(' '), _sospeso(false) { set(g,c,s,t,d,r);} TBill(TToken_string& tgcsd, int from, int mode = 0) - : _descrizione(NULL), _sezione(' '), _sospeso(false) + : _descrizione(nullptr), _sezione(' '), _sospeso(false) { get(tgcsd, from, mode); } TBill(const TRectype& rec, bool contro = false) - : _descrizione(NULL), _sezione(' '), _sospeso(false) + : _descrizione(nullptr), _sezione(' '), _sospeso(false) { get(rec, contro); } TBill(const TBill& b) - : _descrizione(NULL) + : _descrizione(nullptr) { copy(b); } virtual ~TBill(); const TBill& set(int g = 0, int c = 0, long s = 0L, char t = ' ', - const char* d = NULL, int r = -1); + const char* d = nullptr, int r = -1); const TBill& get(TToken_string& ts, int from, int mode = 0); const TBill& add_to(TToken_string& ts, int from, int mode = 0); diff --git a/src/cg/cglib02.cpp b/src/cg/cglib02.cpp index 7f4698da6..137ce44ba 100755 --- a/src/cg/cglib02.cpp +++ b/src/cg/cglib02.cpp @@ -222,7 +222,7 @@ bool TSaldo::data_limite_bilancio(int bilancio, int g, int c, long s, const TDat cur.freeze(); // Anche se non movimentato vado a vedere il saldo - if ((provv & 0x1) && (filter == NULL || *filter == '\0')) + if ((provv & 0x1) && (filter == nullptr || *filter == '\0')) _saldo = calcola_saldo_iniziale(g,c,s,indbil,provv); for (cur = 0L; cur.pos() < items; ++cur) @@ -516,18 +516,13 @@ const real& TSaldo::saldo_periodo(int g, int c, long s, const TDate& dal, const { cur.freeze(); - TProgind* p = NULL; - if (items > 100) // E' proprio utile la progind? - { - TString80 prompt; - prompt.format(FR("Calcolo saldo del conto %d.%d.%ld"), g, c, s); - p = new TProgind(items, prompt, false); - } + TString80 prompt; + prompt.format(FR("Calcolo saldo del conto %d.%d.%ld"), g, c, s); + TProgress_monitor p(items, prompt, false); for (cur = 0L; cur.pos() < items; ++cur) { - if (p != NULL) - p->addstatus(1L); + p.addstatus(1L); const long num_reg = rmov.get_long(RMV_NUMREG); const real importo = rmov.get_real(RMV_IMPORTO); @@ -569,10 +564,6 @@ const real& TSaldo::saldo_periodo(int g, int c, long s, const TDate& dal, const } } } - - - if (p != NULL) - delete p; } _saldo = _saldo_iniziale + _prg_dare - _prg_avere; return _saldo; @@ -667,18 +658,13 @@ bool TSaldo::saldo_cont_sep(int g, int c, long s, const int codes, TDate al, { cur.freeze(); - TProgind* p = NULL; - if (items > 100) // E' proprio utile la progind? - { - TString80 prompt; - prompt.format(FR("Calcolo saldo del conto %d.%d.%ld"), g, c, s); - p = new TProgind(items, prompt, false); - } + TString80 prompt; + prompt.format(FR("Calcolo saldo del conto %d.%d.%ld"), g, c, s); + TProgress_monitor p(items, prompt, false); for (cur = 0L; cur.pos() < items; ++cur) { - if (p != NULL) - p->addstatus(1L); + p.addstatus(1L); const long num_reg = rmov.get_long(RMV_NUMREG); const real importo = rmov.get_real(RMV_IMPORTO); @@ -691,7 +677,7 @@ bool TSaldo::saldo_cont_sep(int g, int c, long s, const int codes, TDate al, if (ok) { - if (( cont_sep != NULL && *cont_sep == '\0') || mov.get(MOV_CONTSEP) == cont_sep) + if (( cont_sep != nullptr && *cont_sep == '\0') || mov.get(MOV_CONTSEP) == cont_sep) { _codcaus = mov.get(MOV_CODCAUS); _datareg = mov.get(MOV_DATAREG); @@ -739,8 +725,6 @@ bool TSaldo::saldo_cont_sep(int g, int c, long s, const int codes, TDate al, NFCHECK("Testata assente: %ld", num_reg); } } - if (p != NULL) - delete p; } _saldo = _saldo_iniziale + _prg_dare - _prg_avere; return _movimentato; @@ -759,7 +743,7 @@ public: bool scaricato() const { return _scaricato; } - TContoExt(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL, bool sc = false) + TContoExt(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = nullptr, bool sc = false) : TConto(g, c, s, t, d), _scaricato(sc) {} TContoExt(TToken_string& tgcsd, int from, int mode = 0, bool sc = false) : TConto(tgcsd, from, mode), _scaricato(sc) {} @@ -777,8 +761,9 @@ TConto* TTab_conti::add(const TBill& c, int anno, bool scar) { const TString& key = build_key(c, anno, scar); TContoExt* tc = new TContoExt(c.gruppo(), c.conto(), c.sottoconto(), - c.tipo(), NULL, scar); + c.tipo(), nullptr, scar); TAssoc_array::add(key, tc); + return tc; } @@ -800,7 +785,8 @@ void TTab_conti::aggiorna_conto(const TBill& tcon, char provv, bool somma, bool movimentato, bool scaricato) { TContoExt* tc = (TContoExt*)find(tcon, anno_es, scaricato); - if (tc == NULL) + + if (tc == nullptr) tc = (TContoExt*)add(tcon, anno_es, scaricato); const real i(somma ? importo.valore() : -importo.valore()); diff --git a/src/cg/cglib02.h b/src/cg/cglib02.h index 1ede96fbd..26a90f457 100755 --- a/src/cg/cglib02.h +++ b/src/cg/cglib02.h @@ -21,7 +21,7 @@ class TConto : public TBill TImporto _saldo_finale; public: - TConto(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = NULL) + TConto(int g = 0, int c = 0, long s = 0L, char t = ' ', const char* d = nullptr) : TBill(g, c, s, t, d) {} TConto (TToken_string& tgcsd, int from, int mode = 0) : TBill(tgcsd, from, mode) {} @@ -129,7 +129,7 @@ public: bool ultima_immissione_bilancio(int annoes, int g,int c,long s,int indbil,int provv = 0x1,bool saldo_chiusura = true); bool ultima_immissione_verifica(int annoes, int g,int c,long s,int indbil,int provv = 0x1); - bool data_limite_bilancio(int annoes,int g,int c,long s,const TDate& data_inf,const TDate& data_suo,int indbil, int provv = 0x1, const char* filter = NULL); + bool data_limite_bilancio(int annoes,int g,int c,long s,const TDate& data_inf,const TDate& data_suo,int indbil, int provv = 0x1, const char* filter = nullptr); const real& saldo_periodo(int g, int c, long s, const TDate& dal, const TDate& al, int indbil, int provv = 0x1); bool saldo_cont_sep(int g, int c, long s, const int codes, TDate al, int indbil, const char * cont_sep, int provv = 0x1, bool chiusura = false, bool first = true); bool ricerca_progr_prec(int, int, int, long); diff --git a/src/cg/cglib03.cpp b/src/cg/cglib03.cpp index 1b66bfc17..ce6ce4b2c 100755 --- a/src/cg/cglib03.cpp +++ b/src/cg/cglib03.cpp @@ -117,13 +117,17 @@ bool gestione_IVAxCassa(const TDate& data_mov, long firm) const TDate data = data_mov.ok() ? data_mov : TDate(TODAY); const int anno = data.year(); bool yes = anno >= 2012 && dongle().active(ICAUT) && dongle().active(SCAUT); + if (yes) { if (firm <= 0) firm = prefix().get_codditta(); - TString16 codtab; + TString16 codtab; + codtab.format("%05ld%04d", firm, anno); + const TRectype& lia = cache().get("%LIA", codtab); + yes = lia.get_bool("B5"); if (yes) { @@ -532,4 +536,3 @@ TIva_round::TIva_round() _mode = _def_mode; _decimals = _def_decimals; } - diff --git a/src/cg/cglib04.cpp b/src/cg/cglib04.cpp index 30e8a75b5..ca966b8b3 100755 --- a/src/cg/cglib04.cpp +++ b/src/cg/cglib04.cpp @@ -11,8 +11,8 @@ #include #include -const int sizeT = 256; //Lunghezza del record del TRASFER -const int sizeH = 1024; //Lunghezza del record dell'HEADER +const size_t sizeT = 256; //Lunghezza del record del TRASFER +const size_t sizeH = 1024; //Lunghezza del record dell'HEADER const int RIC_SIZE = 512; @@ -476,7 +476,7 @@ bool TTransfer_file::read_control_rec() // va all'inizio del file fseek(_trasfer, 0L, SEEK_SET); - const word letti = fread(_control_rec->get_buffer(sizeH), 1, sizeH, _trasfer); + const size_t letti = fread(_control_rec->get_buffer(sizeH), 1, sizeH, _trasfer); _control_rec->cut(sizeH); _tiporec = _control_rec->left(2); @@ -506,7 +506,7 @@ bool TTransfer_file::read_control_rec_t() // va all'inizio del file fseek (_trasfer, 0L, SEEK_SET); - const word letti = fread((char*)(const char*)_control_rec_t,sizeof(char),sizeT,_trasfer); + const size_t letti = fread((char*)(const char*)_control_rec_t,sizeof(char),sizeT,_trasfer); _tiporec = _control_rec_t.sub(0,2); @@ -3029,7 +3029,7 @@ bool TTransfer_file::ordina_trasfer(const char* orig) while (ok) { - const word letti = fread(buffer.get_buffer(), 1, sizeT, i); + const size_t letti = fread(buffer.get_buffer(), 1, sizeT, i); buffer.cut(sizeT); // A causa di errori di invio da parte del sistema diff --git a/src/cg/cgpagame.cpp b/src/cg/cgpagame.cpp index 67b3ebbb6..d98f63f61 100755 --- a/src/cg/cgpagame.cpp +++ b/src/cg/cgpagame.cpp @@ -46,17 +46,6 @@ TDate TPagamento::_rata_dfield(int n, int f) const return v; } -/* Funzione sgradita al nuovo C ed anche a Guy: static bleah! -const char* TPagamento::_rata_sfield(int n, int f) const -{ - TToken_string& t = (TToken_string&)_rate[n]; - TString & s = get_tmp_string(30); - - s = t.get(f); - return s; -} -*/ - // Funzione digeribile dal nuovo C const TString& TPagamento::_rata_sfield(int n, int f) const { @@ -88,7 +77,7 @@ void TPagamento::set_inizio(const TDate& d, bool rispetta_date) next_scad(data, scad_rata(0), _mcomm, 0); bool dummy; - recalc_rate(0, false, NULL, NULL, data.string(), NULL, NULL, _rdiff, _mcomm, dummy); + recalc_rate(0, false, nullptr, nullptr, data.string(), nullptr, nullptr, _rdiff, _mcomm, dummy); } void TPagamento::set_intervallo_rate(int in) @@ -568,15 +557,16 @@ TToken_string& TPagamento::set_rata (int index, real perc, int day, int type, bool val, const char* ulc, const char* imp, const char* data) { TToken_string* tt = (TToken_string*)_rate.objptr(index); - const bool nwr = (tt == NULL); + const bool nwr = (tt == nullptr); + if (nwr) tt = new TToken_string(64); tt->add(day,0); // scadenza tt->add(perc.string(),1); // percentuale tt->add(type,2); // tipo - tt->add(data == NULL ? "" : data, 3); - tt->add(imp == NULL ? "" : imp, val ? 4 : 7); - tt->add(ulc == NULL ? "" : ulc, 5); + tt->add(data == nullptr ? "" : data, 3); + tt->add(imp == nullptr ? "" : imp, val ? 4 : 7); + tt->add(ulc == nullptr ? "" : ulc, 5); if (!nwr) { @@ -634,8 +624,7 @@ TToken_string& TPagamento::set_rata(int index, const real& impval, const real& i // calcola percentuali e scadenze a partire dagli importi TToken_string* tt = _rate.rowptr(index); const int first = _tpr < 4 ? 0 : 1; - - const bool nwr = (tt == NULL); // nuova rata + const bool nwr = (tt == nullptr); // nuova rata if (nwr) tt = new TToken_string(64); @@ -827,8 +816,10 @@ const char* TPagamento::desc_tpr() const const char* TPagamento::desc_tipo(int tipo, char ulc, bool* ok) const { - const char* o = ""; - if (ok != NULL) *ok = true; + const char* o = ""; + + if (ok != nullptr) + *ok = true; if (ulc > ' ') { // const char key[3] = { tipo+'0', toupper(ulc), '\0' }; @@ -849,7 +840,10 @@ const char* TPagamento::desc_tipo(int tipo, char ulc, bool* ok) const case 7: o = TR("Tratta accettata"); break; case 8: o = TR("Rapporti interban. diretti"); break; case 9: o = TR("Bonifici"); break; - default: if (ok != NULL) *ok = false; break; + default: + if (ok != nullptr) + *ok = false; + break; } } return o; @@ -867,7 +861,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified, // possibile modificare entrambi; se succede viene data // priorita' alla percentuale. { - CHECK(!(!is_perc_modified && (new_value != NULL || new_lire != NULL) && !_inited), + CHECK(!(!is_perc_modified && (new_value != nullptr || new_lire != nullptr) && !_inited), "A'stronzo! E famme 'na pippa! Me dai n'importo che nun ce sta? Ma Vaffanculo!"); if (_rate.items() == 0) return P_OK; @@ -887,7 +881,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified, { if (i == row) { - if (typ != NULL) + if (typ != nullptr) { for (int k = 0; k < srate.items(); k++) { @@ -907,7 +901,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified, } } - if (ulc != NULL) + if (ulc != nullptr) { for (int k = 0; k < srate.items(); k++) { @@ -924,8 +918,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified, } } } - - if (scad != NULL) + if (scad != nullptr) { // if !_inited scad e' il n. giorni, se no e' la rata if (_inited) @@ -982,14 +975,14 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified, } } - if (new_value != NULL) + if (new_value != nullptr) { need_recalc = true; // questa la subappaltiamo, per evitare l'inferno return change_value(row, real(new_value), rdiff, is_perc_modified, mcomm, true); } - if (new_lire != NULL) + if (new_lire != nullptr) { need_recalc = true; // questa pure la subappaltiamo, sempre per evitare l'inferno @@ -1001,7 +994,7 @@ word TPagamento::recalc_rate(int row, bool is_perc_modified, if (rdiff == 2) continue; - if (scad != NULL) + if (scad != nullptr) { // check sulle scadenze solo se si sono modificate lastdate = data_rata(i); @@ -1475,7 +1468,8 @@ bool TPagamento::read(TTable* t, TTable* r) { // puo' chiamarla chiunque bool istnew = false; - if (t == NULL) + + if (t == nullptr) { t = new TTable("%CPG"); istnew = true; @@ -1506,7 +1500,8 @@ bool TPagamento::read(TTable* t, TTable* r) // leggi rate e scadenze bool isrnew = false; - if (r == NULL) + + if (r == nullptr) { r = new TTable("%RPG"); isrnew = true; @@ -1694,7 +1689,7 @@ void TPagamento::set_total(const real& ib, const real& im, const real& sp) { _in_valuta = false; _firstr = _secndr = ZERO; // Azzera importi in valuta - init_total(ib, im, sp, NULL); // setta regolarmente totali in lire + init_total(ib, im, sp, nullptr); // setta regolarmente totali in lire } void TPagamento::set_total_valuta(const real& ib, const real& im, const real& sp, const real& c, @@ -1705,7 +1700,7 @@ void TPagamento::set_total_valuta(const real& ib, const real& im, const real& _in_valuta = true; // setta regolarmente totali in lire - init_total(ibl, iml, spl, NULL); + init_total(ibl, iml, spl, nullptr); // ripeti tutto con la valuta init_total(ib, im, sp, codval); @@ -1715,7 +1710,8 @@ void TPagamento::set_total_valuta(const real& ib, const real& im, const real& void TPagamento::init_total(const real& ib, const real& im, const real& sp, const char* codval) { - const bool valuta = (codval != NULL) && *codval && TCurrency::get_firm_val() != codval; + const bool valuta = (codval != nullptr) && *codval && TCurrency::get_firm_val() != codval; + if (valuta) { const TCurrency cur(ZERO, codval); @@ -1986,7 +1982,7 @@ TPagamento::TPagamento(const char* codtab, const char* data) : _def_tpr(1), _def_ulc(""), _was_tpr4(false), _in_valuta(false), _tipocf('C'), _codcf(0L) { _fixd[0] = _fixd[1] = _fixd[2] = 0; - if (data != NULL && *data) + if (data != nullptr && *data) _inizio = data; else _inizio = TDate(TODAY); diff --git a/src/cg/cgsalda3.cpp b/src/cg/cgsalda3.cpp index 7982b08b5..641816e33 100755 --- a/src/cg/cgsalda3.cpp +++ b/src/cg/cgsalda3.cpp @@ -61,13 +61,14 @@ void TPartite_cache::set_bill(TPartite_array& games, const TBill& conto, long nu TCursor cur(&partite, filter, 1, &rec, &rec); cur.scan(fill_games, this); - for (TPartita* p = games.first(); p != NULL; p = games.next()) if (!p->is_on_file()) + for (TPartita* p = games.first(); p != nullptr; p = games.next()) if (!p->is_on_file()) add_game(*p); } TPartita* TPartite_cache::find(int idx) const { - TPartita* g = NULL; + TPartita* g = nullptr; + if (has_game(idx)) { const TToken_string& str = row(idx); @@ -142,11 +143,13 @@ TPartita* TSolder_tree::partita() const TRiga_partite* TSolder_tree::riga_partita() const { - TRiga_partite* fatt = NULL; + TRiga_partite* fatt = nullptr; + if (_curr.items() >= 2) { TPartita* g = partita(); - if (g != NULL) + + if (g != nullptr) { int nriga = 1; _curr.get(1, nriga); if (nriga > 0 && nriga < g->UNASSIGNED) @@ -158,11 +161,13 @@ TRiga_partite* TSolder_tree::riga_partita() const TRiga_scadenze* TSolder_tree::scadenza() const { - TRiga_scadenze* scad = NULL; + TRiga_scadenze* scad = nullptr; + if (_curr.items() >= 3) { TPartita* g = partita(); - if (g != NULL) + + if (g != nullptr) { int nriga = 1; _curr.get(1, nriga); int nrata = 1; _curr.get(2, nrata); @@ -175,11 +180,13 @@ TRiga_scadenze* TSolder_tree::scadenza() const TRectype* TSolder_tree::pagamento() const { - TRectype* rpag = NULL; + TRectype* rpag = nullptr; + if (_curr.items() >= 4) { TPartita* g = partita(); - if (g != NULL) + + if (g != nullptr) { int nriga = 1; _curr.get(1, nriga); int nrata = 1; _curr.get(2, nrata); @@ -208,7 +215,8 @@ bool TSolder_tree::goto_firstson() return false; TPartita* g = partita(); - if (g == NULL) // Dovrebbe funzionare sempre per level > 0 + + if (g == nullptr) // Dovrebbe funzionare sempre per level > 0 return false; if (level == 1) @@ -270,7 +278,8 @@ bool TSolder_tree::goto_rbrother() const int index = _curr.get_int(0); if (level == 1) // Esite la prossima partita? { - const bool ok = _cache.find(index+1) != NULL; + const bool ok = _cache.find(index+1) != nullptr; + if (ok) _curr.add(index+1, 0); return ok; @@ -343,7 +352,8 @@ bool TSolder_tree::could_have_son() const return false; // Sono su di un pagamento const TPartita* g = partita(); - if (g == NULL) + + if (g == nullptr) return false; int riga = 0; _curr.get(1, riga); @@ -880,4 +890,3 @@ bool TSolder_tree::goto_single_game(int anno, const char* numpart, int nriga, in // Posiziono l'albero normalmente return goto_game(anno, numpart, nriga, nrata, nrigp); } - diff --git a/src/cg/cgsalda3.h b/src/cg/cgsalda3.h index 17d435109..e89e02e8d 100755 --- a/src/cg/cgsalda3.h +++ b/src/cg/cgsalda3.h @@ -43,7 +43,7 @@ public: bool add_game(const TRectype& rec); bool add_game(const TPartita& part); - TPartite_cache() : _games(NULL) {} + TPartite_cache() : _games(nullptr) {} }; /////////////////////////////////////////////////////////// diff --git a/src/cg/cgsaldac.cpp b/src/cg/cgsaldac.cpp index 672ec6c25..b89b7f8cf 100755 --- a/src/cg/cgsaldac.cpp +++ b/src/cg/cgsaldac.cpp @@ -203,6 +203,7 @@ void TValuta::set(const TValuta& v) real TValuta::eur2val(const real& lit) const { TCurrency cur(lit); + cur.change_value(_cod, _cam); return cur.get_num(); } @@ -210,6 +211,7 @@ real TValuta::eur2val(const real& lit) const real TValuta::val2eur(const real& val) const { TCurrency cur(val, _cod, _cam); + cur.change_to_firm_val(); return cur.get_num(); } @@ -217,6 +219,7 @@ real TValuta::val2eur(const real& val) const void TValuta::val2eur(real& val) const { TCurrency cur(val, _cod, _cam); + cur.change_to_firm_val(); val = cur.get_num(); } @@ -313,15 +316,13 @@ TImporto TPartita::importo_pagsca(const TRectype& pag, bool val, int mode) const const TRiga_partite& sum = riga(nrigp); - // Inizio aggiunte di Bonazzi del 16/02/2012 if (mode & 0x10) // solo le note di credito { const tipo_movimento tm = sum.tipo(); if (tm != tm_nota_credito) return totale; // = ZERO } - // Fine aggiunte di Bonazzi del 16/02/2012 - + const bool in_val = sum.in_valuta(); const char* imp_field = (val && in_val) ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO; @@ -1228,7 +1229,7 @@ int TRiga_partite::calcola_pagato_periodo(const TDate& dal, const TDate& al, TIm pg += imp; flag |= 1; } - if (pagsca != NULL) + if (pagsca != nullptr) pagsca->add(obj); } @@ -1242,7 +1243,7 @@ int TRiga_partite::calcola_pagato_periodo(const TDate& dal, const TDate& al, TIm // Filtra le righe saldo per non creare array di 9999 elementi nulli! int TRiga_partite_array::add_row(TRectype* row) { - if (row == NULL) + if (row == nullptr) return -1; if (row->get_int(PART_NRIGA) >= TPartita::UNASSIGNED) { @@ -1480,7 +1481,7 @@ int TPartita::write_saldo(bool re, TRectype* rec) const // sld.put(PART_CHIUSA, row.get(PART_CHIUSA)); // Copia il flag di chiusura sld.put(PART_CHIUSA, chiusa(true)); - if (rec != NULL) + if (rec != nullptr) *rec = sld; // Scrittura del record di saldo @@ -2340,7 +2341,8 @@ TPartita* TPartite_array::find(const TBill& clifo, int anno, const char* num, bo { const TString& k = key(clifo, anno, num); TPartita* p = (TPartita*)objptr(k); - if (p == NULL && create) + + if (p == nullptr && create) { p = new TPartita(clifo, anno, num); add(k, p); @@ -2379,9 +2381,11 @@ bool TPartite_array::insert(TPartita* p) { const TString& k = key(p->conto(), p->anno(), p->numero()); TPartita* old = (TPartita*)objptr(k); - if (old != NULL) remove(k); + + if (old != nullptr) + remove(k); add(k, p); - return old != NULL; + return old != nullptr; } bool TPartite_array::destroy(const TBill& clifo, int anno, const char* num) @@ -2399,10 +2403,10 @@ bool TPartite_array::destroy(TPartita& game) bool TPartite_array::write(bool re) { bool ok = true; - TPartita* game; + restart(); - while ((game = (TPartita*)get()) != NULL) + while ((game = (TPartita*)get()) != nullptr) { ok = game->write(re); if (!ok) // L'errore viene gia' segnalato dalla partita @@ -2506,8 +2510,9 @@ TRiga_partite* TPartite_array::mov2rig(long numreg, int numrig) for (TPartita* game = first(); game; game = next()) { const int r = game->mov2rig(numreg, numrig); + if (r > 0) return &game->riga(r); } - return NULL; + return nullptr; } diff --git a/src/cg/f25.dir b/src/cg/f25.dir index b63dcaa4c..6a0e16588 100755 --- a/src/cg/f25.dir +++ b/src/cg/f25.dir @@ -1,3 +1,3 @@ 25 0 -$rmoviva|0|0|110|0|Righe movimento IVA|NMOV*2|| +$rmoviva|0|0|111|0|Righe movimento IVA|NMOV*2|| diff --git a/src/cg/f25.trr b/src/cg/f25.trr index caa718317..70f69cf2a 100755 --- a/src/cg/f25.trr +++ b/src/cg/f25.trr @@ -1,5 +1,5 @@ 25 -19 +20 ANNOES|2|4|0|Codice esercizio NUMREG|3|7|0|Numero operazione NUMRIG|2|3|0|Numero riga @@ -19,5 +19,6 @@ SOTTOCONTO|3|6|0|Sottoconto o codice cliente/fornitore CODCMS|1|20|0|Codice Commessa FASCMS|1|10|0|Fase Commessa NAVP|8|1|0|Nota di variazione anni precedenti x Elenco CF +REVCHARGE|8|1|0|Riga IVA reverse charge 1 NUMREG+NUMRIG|