diff --git a/fe/fe0.cpp b/fe/fe0.cpp index 8fb729110..5331a65b8 100755 --- a/fe/fe0.cpp +++ b/fe/fe0.cpp @@ -6,10 +6,10 @@ int main(int argc, char** argv) const int n = argc > 1 ? argv[1][1]-'0' : 0; switch (n) { - case 1: fe0200(argc, argv); break; // Immissione / Generazione Spesometro + case 1: fe0200(argc, argv); break; // Gestione tabelle (contratti) case 2: fe0300(argc, argv); break; // Somma file Spesometro (Dorotee) case 3: fe0400(argc, argv); break; // Controllo contratti su movimenti - default: fe0100(argc, argv); break; // Gestione tabelle (contratti) + default: fe0100(argc, argv); break; // Immissione / Generazione Spesometro } return 0; } \ No newline at end of file diff --git a/fe/fe0100.cpp b/fe/fe0100.cpp index 47613ae90..7421035c9 100755 --- a/fe/fe0100.cpp +++ b/fe/fe0100.cpp @@ -1,1808 +1,1486 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "fe0100a.h" -#include "felib.h" -#include "../cg/cglib01.h" - -const char* const INVALID_NUMDOC = "???????"; -const long MANUAL_ROW = 900000L; - - -/////////////////////////////////////////////////////////// -// Utility -/////////////////////////////////////////////////////////// - -enum TExclusion_mode { em_incluso, em_importo_limite, em_no_allegato, - em_fiscalita_agevolata, em_estero, em_intra, - em_art8, em_data_limite, em_passaggi_interni, - em_inviato, em_altro }; - -static const char* mode2string(TExclusion_mode motivo) -{ - const char* msg = ""; - switch (motivo) - { - case em_importo_limite : msg = TR("importo inferiore al limite della comunicazione"); break; - case em_no_allegato : msg = TR("Soggetto da non inserire in allegato"); break; - case em_fiscalita_agevolata: msg = TR("Soggetto residente in stato a fiscalità agevolata"); break; - case em_estero : msg = TR("Soggetto residente all'estero"); break; - case em_intra : msg = TR("Movimento intra"); break; - case em_data_limite : msg = TR("Data fuori dal limite della comunicazione"); break; - case em_art8 : msg = TR("Soggetto all'articolo 8 (del dpr 26-10-1972)"); break; - case em_passaggi_interni : msg = TR("Passaggi interni"); break; - case em_inviato : msg = TR("Inviato l'anno precedente"); break; - default : msg = TR("Altri motivi"); break; - } - return msg; -} - -/////////////////////////////////////////////////////////// -// TDati_rilevanti_array -/////////////////////////////////////////////////////////// - -class TBase_contract_cache : public TCache -{ - TContratto _c; - -protected: - virtual TObject* key2obj(const char* c); - -public: - const TString& base_contract(const TRectype& a); -}; - -TObject* TBase_contract_cache::key2obj(const char* c) -{ - const TFixed_string codice (c); - _c.init(codice); - return new TString(_c.codice_base()); -} - -const TString& TBase_contract_cache::base_contract(const TRectype& a) -{ - const char* cod = a.get(ALL_CONTRATTO); - if (*cod > ' ') - { - _c.init(a); - return *(TString*)objptr(_c.chiave()); - } - return EMPTY_STRING; -} - -class TDati_rilevanti_array : public TObject -{ - TArray _data; - TBase_contract_cache _base; - -protected: - TExclusion_mode segnala_riga(const TRectype& alleg, TExclusion_mode motivo, TLog_report& log) const; - const TString& get_base_contract(const TRectype& alleg); - -public: - int items() const { return _data.items(); } - const TRectype& operator[](int i) { return (const TRectype&)_data[i]; } - TExclusion_mode add(const TRectype& alleg, bool send_all, TLog_report& log); - void add(TArray& fatture, TArray& note, bool send_all, TLog_report& log); -}; - -TExclusion_mode TDati_rilevanti_array::segnala_riga(const TRectype& alleg, TExclusion_mode motivo, TLog_report& log) const -{ - if (motivo > em_importo_limite) - { - const TAnagrafica a(alleg); - TString msg; - msg.format(FR("%s %s - Riga %7ld: "), alleg.get_char(ALL_TIPOCF) == 'F' ? TR("For.") : TR("Cli."), - (const char*)a.ragione_sociale(), alleg.get_long(ALL_PROGR)); - msg << mode2string(motivo); - log.log(1, msg); - } - return motivo; -} - -TExclusion_mode TDati_rilevanti_array::add(const TRectype& alleg, bool send_all, TLog_report& log) -{ - TExclusion_mode ignora = TExclusion_mode(alleg.get_int(ALL_IGNORA)); - if (ignora > em_importo_limite) - return ignora; - - const real importo = alleg.get_real(ALL_IMPORTO); - const real imposta = alleg.get_real(ALL_IMPOSTA); - if (importo.is_zero() && imposta.is_zero()) - return segnala_riga(alleg, em_importo_limite, log); - - const TAnagrafica a(alleg); - if (a.codice_fiscale().blank() && a.partita_IVA().blank() && a.italiano()) - return segnala_riga(alleg, em_no_allegato, log); - - const int anno = alleg.get_int(ALL_ANNO); - - if (fe_is_nota_variazione(alleg)) - { - TRectype& a = (TRectype&)alleg; // Triste necessità - if (!send_all && ignora <= em_importo_limite) - { - const real importo = abs(alleg.get_real(ALL_IMPORTO)); - if (importo < fe_importo_limite(anno)) - { - ignora = segnala_riga(alleg, em_importo_limite, log); - a.put(ALL_IGNORA, ignora); - } - } - - if (ignora <= em_importo_limite) - { - TDate datarett = a.get(ALL_DATARETT); - if (datarett.ok()) - { - const int a = datarett.year(); - if (a < 2010 || a > anno) - ignora = segnala_riga(alleg, em_data_limite, log); - } - else - { - const TDate datareg = a.get(ALL_DATAREG); - const int ar = datareg.year(); - if (ar == anno) - a.put(ALL_DATARETT, TDate(31, 12, anno-1)); - else - ignora = segnala_riga(alleg, em_data_limite, log); - } - - const TString& numrett = a.get(ALL_NUMRETT); - if (numrett == INVALID_NUMDOC || !datarett.ok()) - a.zero(ALL_NUMRETT); - } - } - else - { - const TString80 contratto = get_base_contract(alleg); - if (ignora <= em_importo_limite) - { - TExclusion_mode new_mode = (alleg.get_real(ALL_IMPORTO) < fe_importo_limite(anno)) ? em_importo_limite : em_incluso; - if (new_mode == em_importo_limite && contratto.full()) - { - const TContratto c(alleg); - real imp, iva; - if (c.totale_annuale(anno, imp, iva)) - new_mode = (imp < fe_importo_limite(anno)) ? em_importo_limite : em_incluso; - } - if (ignora != new_mode) - ((TRectype&)alleg).put(ALL_IGNORA, ignora = new_mode); - } - } - - if (ignora > em_importo_limite || (!send_all && ignora == em_importo_limite)) - return ignora; - - // Creo un nuovo record - _data.add(alleg); - return em_incluso; -} - -const TString& TDati_rilevanti_array::get_base_contract(const TRectype& alleg) -{ - CHECKD(alleg.num() == LF_ALLEG, "Record non valido ", alleg.num()); - return _base.base_contract(alleg); -} - -void TDati_rilevanti_array::add(TArray& fatture, TArray& note, bool send_all, TLog_report& log) -{ - // Cerca di scalare le note dalle relative fatture - FOR_EACH_ARRAY_ITEM_BACK(note, n, pnota) - { - const TRectype& nota = *(const TRectype*)pnota; - const TString8 numrett = nota.get(ALL_NUMRETT); - if (numrett.full() && numrett != INVALID_NUMDOC) - { - if (numrett == "190") - int cazzone = 1; - - const TDate datarett = nota.get(ALL_DATARETT); - FOR_EACH_ARRAY_ITEM(fatture, f, pfatt) - { - TRectype& fatt= *(TRectype*)pfatt; - if (fatt.get(ALL_NUMDOC) == numrett && fatt.get_date(ALL_DATAREG) == datarett) - { - fatt.add(ALL_IMPORTO, nota.get_real(ALL_IMPORTO)); - fatt.add(ALL_IMPOSTA, nota.get_real(ALL_IMPOSTA)); - note.destroy(n); - break; - } - } - } - } - - // Cerca di raggruppare le fatture per contratto - FOR_EACH_ARRAY_ITEM_BACK(fatture, c, pcont) - { - const TRectype& cont = *(const TRectype*)pcont; - const TString80 contratto = get_base_contract(cont); - if (contratto.full()) - { - FOR_EACH_ARRAY_ITEM(fatture, f, pfatt) if (f < c) - { - TRectype& fatt= *(TRectype*)pfatt; - if (get_base_contract(fatt) == contratto) - { - fatt.add(ALL_IMPORTO, cont.get_real(ALL_IMPORTO)); - fatt.add(ALL_IMPOSTA, cont.get_real(ALL_IMPOSTA)); - - const TDate sum_data = fatt.get(ALL_DATAREG); - const TDate all_data = cont.get(ALL_DATAREG); - if (all_data > sum_data) - { - fatt.put(ALL_DATAREG, all_data); - fatt.put(ALL_NUMDOC, cont.get(ALL_NUMDOC)); - } - fatture.destroy(c); - break; - } - } - } - } - - // Aggiunge fatture - FOR_EACH_ARRAY_ITEM(fatture, nf, pfatt) - { - const TRectype& fatt = *(const TRectype*)pfatt; - add(fatt, send_all, log); - } - - // Aggiunge note - FOR_EACH_ARRAY_ITEM(note, nn, pnot) - { - const TRectype& nota = *(const TRectype*)pnot; - add(nota, send_all, log); - } -} - -/////////////////////////////////////////////////////////// -// TDati_rilevanti_msk -/////////////////////////////////////////////////////////// - -class TDati_rilevanti_msk : public TAutomask -{ - TMaskmode _mode; - bool _sheet_dirty; - TExclusion_mode _why; - TLog_report* _log; - -protected: - virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); - void alleg_sort(TSheet_field& s) const; - void load_sheet(); - bool save_sheet(); - bool save_if_dirty(); - void set_dirty(bool d = true); - - bool send_nota_variazione(const TRectype& alleg, TDati_rilevanti_set& operaz); - bool send_fatt(const TRectype& alleg, TDati_rilevanti_set& operaz); - void build_outname(TFilename& n) const; - -protected: - TRecnotype last_user_progr() const; - TRecnotype nuovo_progr() const; - bool check_rows(bool show_error); - void enable_buttons(); - - bool send_rec(const TRectype& alleg, TDati_rilevanti_set& operaz); - TExclusion_mode segnala_movimento(const TRectype& mov, TExclusion_mode motivo); - - bool fattura_associata(long numreg_var, TDate& datafatt, TString& numdoc) const; - bool controlla_mov(TRectype& mrec) const; - bool azzera_alleg(TAssoc_array& manuali) const; - void collega_variazioni() const; - const TString& primo_contratto() const; - -public: - TRecnotype genera_alleg(); - bool elabora_alleg(); - bool send_alleg(); - bool recall_alleg() const; - - TExclusion_mode elabora_movimento(const TRectype& mov, TBaseisamfile& falleg); - - bool salva_allegato(const TRectype& mov, TBaseisamfile& falleg, TRecnotype& progr, - const real& corrispettivo, const real& imposta, int tipope); - - TExclusion_mode validate_clifo(const TRectype& mov); - TExclusion_mode validate_mov(const TRectype& mov); - - TDati_rilevanti_msk() : TAutomask("fe0100a"), _mode(MODE_QUERY), _log(NULL) { load_profile(); set_dirty(false); } - ~TDati_rilevanti_msk() { save_profile(); } -}; - -TExclusion_mode TDati_rilevanti_msk::segnala_movimento(const TRectype& mov, TExclusion_mode motivo) -{ - if (_why <= em_importo_limite) // Aggiorna motivo esclusione se attualemte incluso o non rilevante - { - _why = motivo; - if (motivo > em_importo_limite) // Non segnalare pippate - { - const long numreg = mov.get_long(MOV_NUMREG); - const char tipocf = mov.get_char(MOV_TIPO); ; - const long codcf = mov.get_long(MOV_CODCF); - const TAnagrafica a(tipocf, codcf, mov.get(MOV_OCFPI)); - TString msg; - msg.format(FR("Mov. %7ld %s %s: "), numreg, - tipocf=='F' ? TR("For.") : TR("Cli."), (const char*)a.ragione_sociale()); - msg << mode2string(motivo); - msg.strip_double_spaces(); - _log->log(1, msg); - } - } - return motivo; -} - -TExclusion_mode TDati_rilevanti_msk::validate_clifo(const TRectype& mov) -{ - const char tipocf = mov.get_char(MOV_TIPO); - const long codcf = mov.get_long(MOV_CODCF); - const TString16 ocfpi = mov.get(MOV_OCFPI); - if (tipocf <= ' ' || (codcf <= 0 && ocfpi.blank())) - return segnala_movimento(mov, em_no_allegato); - - TString8 key; key.format("%c|%ld", tipocf, codcf); - const TRectype& rec_clifo = cache().get(LF_CLIFO, key); - const int alleg = rec_clifo.get_int(CLI_ALLEG); - - TString4 stato; - if (ocfpi.full()) - { - const TRectype& rec_occas = cache().get(LF_OCCAS, ocfpi); - stato = rec_occas.get(OCC_STATO); - } - else - { - if (alleg == 1) - return segnala_movimento(mov, em_no_allegato); - - if (alleg == 5) - return segnala_movimento(mov, em_intra); - - stato = rec_clifo.get(CLI_STATOCF); - } - - if (stato.full()) - { - if (tipocf == 'C') - { - // I clienti privati vanno inclusi anche se residenti in stati esteri in black list - if (ocfpi.blank() && alleg != 6) - { - const TRectype& rec_sta = cache().get("%STA", stato); - if (rec_sta.get_bool("B0")) - return segnala_movimento(mov, em_fiscalita_agevolata); - } - } - else - return segnala_movimento(mov, em_estero); - } - - return em_incluso; //se arriva qui il clifo è da considerare -} - -TExclusion_mode TDati_rilevanti_msk::validate_mov(const TRectype& mov) -{ - // Ignora eventuale vecchio movimento IVA (ANNOIVA < 2010) - const int anno = mov.get_int(MOV_ANNOIVA); - if (anno < 2010) - segnala_movimento(mov, em_data_limite); - - // Ignora i movimenti già comunicati tramite modello INTRA - if (!mov.get_real(MOV_CORRLIRE).is_zero() || - !mov.get_real(MOV_CORRVALUTA).is_zero()) - segnala_movimento(mov, em_intra); - - return validate_clifo(mov); -} - -bool TDati_rilevanti_msk::fattura_associata(long numreg_var, TDate& datafatt, TString& numdoc) const -{ - long numreg_fatt = 0; - if (main_app().has_module(SCAUT)) - { - TLocalisamfile partite(LF_PARTITE); - partite.setkey(2); - TRectype& part = partite.curr(); - part.put(PART_NREG, numreg_var); - part.put(PART_NUMRIG, 1); - if (partite.read() == NOERR) // Ho trovato la partita ora cerco la fattura di riferimento - { - int nriga = part.get_int(PART_NRIGA); - part.zero(PART_NRIGA); // Uso il record come chiave per leggere l'intera partita - TRecord_array partita(part, PART_NRIGA); - for (nriga = partita.pred_row(nriga); nriga >= 1; nriga = partita.pred_row(nriga)) - { - const TRectype& riga = partita.row(nriga); - const int tipomov = riga.get_int(PART_TIPOMOV); - const long nreg_part = riga.get_long(PART_NREG); - if (tipomov == 1 && nreg_part > 0) // Fattura - { - datafatt = riga.get(PART_DATAREG); - numdoc = riga.get(PART_NUMDOC); - break; - } - } - } - } - return numdoc.full(); -} - -TExclusion_mode TDati_rilevanti_msk::elabora_movimento(const TRectype& mov, TBaseisamfile& falleg) -{ - validate_mov(mov); - - const char tipocf = mov.get_char(MOV_TIPO); - const long codcf = mov.get_long(MOV_CODCF); - const TString4 tipodoc = mov.get(MOV_TIPODOC); - const TDate datareg = mov.get_date(MOV_DATAREG); - const int anno = get_int(F_ANNO); - - const TString& keytok = mov.get(MOV_NUMREG); - TRecord_array righe_iva(keytok, LF_RMOVIVA); - - real tot_imponibile, tot_imposta; - - //calcolo di imponibile ed imposta di tutte le righe iva del movimento - for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r)) - { - const TRectype& rmi = righe_iva.row(r); - const TCodiceIVA ci(rmi.get(RMI_CODIVA)); - int natura_operazione = ci.allegato(tipocf); - if (natura_operazione <= 0 || natura_operazione > 5) - continue; - - // Esportazioni - const bool art_8 = ci.get("S2") == "20" && ci.get("S3") == "1"; - if (art_8) - segnala_movimento(mov, em_art8); - - const TString4 cod_det = rmi.get(RMI_TIPODET); - const int tip_det = cod_det == "3" ? 3 : atoi(cache().get("%DET", cod_det, "I0")); - if (tip_det == 3) - segnala_movimento(mov, em_passaggi_interni); - - real rmi_imponibile = rmi.get_real(RMI_IMPONIBILE); - real rmi_imposta = rmi.get_real(RMI_IMPOSTA); - - if (natura_operazione == 4 && rmi_imposta.is_zero()) // se l'imposta non è specificata sullo scontrino ... - rmi_imposta = ci.scorpora(rmi_imponibile); // ... scorporo il lordo - - tot_imponibile += rmi_imponibile; - tot_imposta += rmi_imposta; - } - - const int modpag = mov.get_int(MOV_MODPAG); - if (modpag == 1 && _why == em_incluso) - { - // Considera solo registrazioni con importo rilevante - if (abs(tot_imponibile) < fe_importo_limite(anno)) - _why = em_importo_limite; // Non segnalare migliaia di movimenti inutilmente - } - - const long numreg = mov.get_long(MOV_NUMREG); - - // Registro tutti i dati del cliente e gli importi - falleg.zero(); - falleg.put(ALL_ANNO, anno); - falleg.put(ALL_PROGR, numreg); - falleg.put(ALL_IGNORA, int(_why)); - falleg.put(ALL_TIPOCF, tipocf); - falleg.put(ALL_CODCF, codcf); - falleg.put(ALL_OCFPI, mov.get(MOV_OCFPI)); - falleg.put(ALL_DATAREG, mov.get(MOV_DATAREG)); - falleg.put(ALL_NUMDOC, mov.get(MOV_NUMDOC)); - falleg.put(ALL_TIPOPE, tipocf == 'C' ? 1 : 2); - falleg.put(ALL_IMPORTO, tot_imponibile); - falleg.put(ALL_IMPOSTA, tot_imposta); - falleg.put(ALL_MODPAG, modpag); - if (modpag == 1) - { - falleg.put(ALL_DATARETT, mov.get(MOV_DATARETT)); - falleg.put(ALL_NUMRETT, mov.get(MOV_NUMRETT)); - } - else - falleg.put(ALL_CONTRATTO, mov.get(MOV_CONTRATTO)); - - const int err = falleg.rewrite_write(); - if (err != NOERR) - { - TString msg; - msg.format(FR("Errore %d di aggiornamento del record %d/%ld sul file %s"), - err, anno, numreg, (const char*)falleg.name()); - _log->log(2, msg); - } - - return _why; -} - -// Test di coerenza tra MODPAG, CONTRATTO e NUMRETT -bool TDati_rilevanti_msk::controlla_mov(TRectype& mrec) const -{ - const long numreg = mrec.get_long(MOV_NUMREG); - TString80 contratto = mrec.get(MOV_CONTRATTO); - - int old_modpag = mrec.get_int(MOV_MODPAG); - int new_modpag = 1; - - bool update = false; - - if (fe_is_nota_variazione(mrec)) - { - TDate datarett = mrec.get(MOV_DATARETT); - TString8 numrett = mrec.get(MOV_NUMRETT); - if (contratto.full()) - { - mrec.put(MOV_CONTRATTO, contratto.cut(0)); - update = true; // Peccato veniale - } - if (numrett.blank()) - { - if (!fattura_associata(numreg, datarett, numrett)) - numrett = INVALID_NUMDOC; - mrec.put(MOV_DATARETT, datarett); - mrec.put(MOV_NUMRETT, numrett); - update = true; - } - const TAnagrafica a(mrec); - TString msg; - if (numrett != INVALID_NUMDOC) - { - msg.format(FR("Nota n. %ld di %s associata al doc. %s del %s"), - numreg, (const char*)a.ragione_sociale(), (const char*)numrett, datarett.string()); - msg.strip_double_spaces(); - _log->log(0, msg); - } - else - { - msg.format(FR("Nota n. %ld di %s non associata ad una fattura"), - numreg, (const char*)a.ragione_sociale()); - msg.strip_double_spaces(); - _log->log(1, msg); - } - } - else - { - if (contratto.full()) - { - const TContratto c(mrec); - new_modpag = c.modalita_pagamento(); - } - if (get(MOV_NUMRETT).full() || get(MOV_DATARETT).full()) - { - mrec.zero(MOV_DATARETT); - mrec.zero(MOV_NUMRETT); - update = true; // Peccato veniale - } - - if (mrec.get(MOV_NUMDOC).blank() || mrec.get(MOV_DATADOC).blank()) - { - const TAnagrafica a(mrec); - TString msg; - msg.format(FR("Movimento n. %ld di %s privo di numero o data documento"), - numreg, (const char*)a.ragione_sociale()); - _log->log(1, msg); - } - } - if (old_modpag != new_modpag) - { - if (old_modpag > 0) // I vecchi movimenti hanno per forza 0: li perdoniamo! - { - const TAnagrafica a(mrec); - TString msg; - msg.format(FR("Movimento n. %ld di %s con modalità di pagamento incongruente: %d->%d"), - numreg, (const char*)a.ragione_sociale(), old_modpag, new_modpag); - msg.strip_double_spaces(); - _log->log(0, msg); - } - mrec.put(MOV_MODPAG, new_modpag); - update = true; - } - - return update; -} - -bool TDati_rilevanti_msk::azzera_alleg(TAssoc_array& manuali) const -{ - const int anno = get_int(F_ANNO); - const TDate data = get(F_DATA); - - TFast_isamfile fast_alleg(LF_ALLEG); - TFast_isamfile fast_mov(LF_MOV); - - TString query; - query << "USE " << LF_ALLEG - << "\nJOIN MOV INTO NUMREG==PROGR" - << "\nFROM ANNO=" << anno - << "\nTO ANNO=" << anno << " PROGR=" << MANUAL_ROW; - TISAM_recordset alleg(query); - - TLocalisamfile& falleg = alleg.cursor()->file(); - TRectype& arec = falleg.curr(); - - TLocalisamfile& fmov = alleg.cursor()->file(LF_MOV); - TRectype& mrec = fmov.curr(); - - TString msg; msg << TR("Azzeramento ") << falleg.description() << ' ' << anno; - TProgind pi(alleg.items(), msg, false); - - manuali.destroy(); - for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) - { - pi.addstatus(1); - - const long progr = arec.get_long(ALL_PROGR); - const long numreg = mrec.get_long(MOV_NUMREG); - const TDate datareg = mrec.get_long(MOV_DATAREG); - const int annoiva = mrec.get_long(MOV_ANNOIVA); - - bool kill = numreg != progr || annoiva < anno; - if (!kill) - { - const bool forzata = arec.get_bool(ALL_FORZATURA); - if (forzata) - manuali.add(arec.get(ALL_PROGR)); - else - kill = annoiva == data.year() && datareg > data; - } - if (kill) - falleg.remove(); // Riga generata dalla vecchia versione - } - return !manuali.empty(); -} - -// Cerca l'ultimo numero di riga immesso manualmente -TRecnotype TDati_rilevanti_msk::last_user_progr() const -{ - const int anno = get_int(F_ANNO); - - TRecnotype progr = MANUAL_ROW; - TString query; - query << "USE " << LF_ALLEG - << "\nFROM " << ALL_ANNO << '=' << anno << ' ' << ALL_PROGR << '=' << MANUAL_ROW - << "\nTO " << ALL_ANNO << '=' << anno; - TISAM_recordset alleg(query); - if (alleg.move_last()) - progr = alleg.get(ALL_PROGR).as_int(); - return progr; -} - -TRecnotype TDati_rilevanti_msk::nuovo_progr() const -{ - TRecnotype progr = last_user_progr(); - - TSheet_field& righe = sfield(F_RIGHE); - const int items = righe.items(); - if (items > 0) - { - const int col = righe.cid2index(A_RIGA); - for (int i = items-1; i >= 0; i--) - { - const TRecnotype sheet_progr = atol(righe.cell(i,col)); - if (sheet_progr > progr) - progr = sheet_progr; - } - } - - return progr+1; -} - -static int sort_alleg(const TSortable& s1, const TSortable& s2, void* jolly) -{ - const TRectype& a1 = (const TRectype&)s1; - const TRectype& a2 = (const TRectype&)s2; - - const TString& c1 = a1.get(ALL_CONTRATTO); - const TString& c2 = a2.get(ALL_CONTRATTO); - int cmp = c1.compare(c2, -1, true); - - if (cmp == 0 && c1.blank()) - { - const int n1 = fe_is_nota_variazione(a1); - const int n2 = fe_is_nota_variazione(a2); - cmp = n1 - n2; - } - - if (cmp == 0) - { - const TDate d1 = a1.get(ALL_DATAREG); - const TDate d2 = a2.get(ALL_DATAREG); - cmp = d1 - d2; - } - - return cmp; -} - -TRecnotype TDati_rilevanti_msk::genera_alleg() -{ - const int anno = get_int(F_ANNO); - const TDate data_estrazione = get(F_DATA); - - TString str_pi; - str_pi << TR("Movimenti ") << anno; - _log = new TLog_report(str_pi); - - TAssoc_array manuali; - azzera_alleg(manuali); - - TRecnotype nprog = 1; - - if (anno >= 2010) // Dummy test for bracing TFast_isamfiles - { - TFast_isamfile falleg(LF_ALLEG); - TFast_isamfile fmov(LF_MOV); - - TString query; - query << "USE MOV KEY 3 SELECT BETWEEN(DATAREG," << anno << "0101," << data_estrazione.date2ansi() << ")" - << "\nFROM TIPO=C\nTO TIPO=F"; - TISAM_recordset mov(query); - TRectype& mov_rec = mov.cursor()->curr(); - const TRecnotype items = mov.items(); - - TProgind pi(items, str_pi); - for (bool ok = mov.move_first(); ok; ok = mov.move_next()) - { - if (!pi.addstatus(1)) - break; - _why = em_incluso; - - const int annofe = mov_rec.get_int(MOV_ANNOFE); - if (annofe >= 2010) // Non elaborae i movimenti gia' inviati in definitivo! - { - segnala_movimento(mov_rec, em_inviato); - continue; - } - - const TString& key = mov_rec.get(MOV_NUMREG); - if (manuali.is_key(key)) - { - manuali.remove(key); - continue; - } - - controlla_mov(mov_rec); - const TDate datareg = mov_rec.get(MOV_DATAREG); - if (fe_is_nota_variazione(mov_rec)) - { - const TDate datarett = mov_rec.get(MOV_DATARETT); - if (!datarett.ok() || datarett.year() == anno) - elabora_movimento(mov_rec, falleg); // Elabora nota di variazione - } - else - { - if (datareg.year() == anno) // Scarta fatture dell'anno dopo - elabora_movimento(mov_rec, falleg); - } - } - } - collega_variazioni(); - - _log->preview(); - delete _log; - _log = NULL; - - return nprog; -} - -void TDati_rilevanti_msk::collega_variazioni() const -{ - const int anno = get_int(F_ANNO); - TString query; - query << "USE ALLEG KEY 2 SELECT (STR(IGNORA<=" << int(em_importo_limite) << "))&&(NUMDOC!=\"\")"; - query << "\nJOIN ALLEG KEY 3 ALIAS 220 INTO ANNO=ANNO TIPOCF=TIPOCF CODCF==CODCF NUMRETT==NUMDOC"; - query << "\nFROM ANNO=" << anno << "\nTO ANNO=" << anno; - TISAM_recordset fatture(query); - - TProgind pi(fatture.items(), TR("Collegamento note di variazione"), false, true); - TRelation& rel = *fatture.cursor()->relation(); - - for (bool ok = fatture.move_first(); ok; ok = fatture.move_next()) - { - pi.addstatus(1); - if (rel.is_first_match(-220)) - { - real importo = fatture.get(ALL_IMPORTO).as_real(); - for (bool ok = true; ok; ok = rel.next_match(-220)) - importo += rel.curr(-220).get_real(ALL_IMPORTO); - - const TExclusion_mode old_mode = TExclusion_mode(fatture.get(ALL_IGNORA).as_int()); - const TExclusion_mode new_mode = importo < fe_importo_limite(anno) ? em_importo_limite : em_incluso; - if (old_mode != new_mode) - { - TLocalisamfile& f = fatture.cursor()->file(); - f.put(ALL_IGNORA, new_mode); - f.rewrite(); - } - } - } -} - -// Analizza tutti i movimenti dell'anno dell'attività corrente e genera i record rilevanti -bool TDati_rilevanti_msk::elabora_alleg() -{ - if (!check_fields()) // Controlla che l'anno sia valido - return false; - - const TRecnotype prog = genera_alleg(); - return prog > 1; -} - -bool TDati_rilevanti_msk::send_nota_variazione(const TRectype& alleg, TDati_rilevanti_set& operaz) -{ - real imponibile = alleg.get_real(ALL_IMPORTO); - real imposta = alleg.get_real(ALL_IMPOSTA); - if (imponibile.is_zero() && imposta.is_zero()) - return false; - - const TAnagrafica anag(alleg); - if (!anag.ok()) - return false; - - const char tipocf = alleg.get_char(ALL_TIPOCF); - char segno_imponibile = tipocf == 'C' ? 'D' : 'C'; // Normalmente sono negative e quindi a debito del dichiarante - char segno_imposta = segno_imponibile; - - if (imponibile >= ZERO) - segno_imponibile = segno_imponibile == 'D' ? 'C' : 'D'; - else - imponibile = -imponibile; - - if (imposta >= ZERO) - { - if (imposta > ZERO) - segno_imposta = segno_imposta == 'D' ? 'C' : 'D'; - else - segno_imposta = segno_imponibile; - } - else - imposta = -imposta; - - TString16 numrett = alleg.get(ALL_NUMRETT); - if (numrett == INVALID_NUMDOC) - numrett.cut(0); - - if (anag.estero()) - { - operaz.new_rec("5"); // Note di variazione a soggetti non residenti - if (anag.fisica()) - { - operaz.set(2, anag.cognome()); - operaz.set(3, anag.nome()); - operaz.set(4, anag.data_nascita()); - operaz.set(5, anag.comune_nascita()); - operaz.set(6, anag.provincia_nascita()); - operaz.set(7, anag.stato_estero_UNICO()); - } - else - { - operaz.set(8, anag.ragione_sociale()); - operaz.set(9, anag.comune_residenza()); - operaz.set(10, anag.stato_estero_UNICO()); - operaz.set(11, anag.indirizzo_residenza()); - } - operaz.set(12, alleg.get(ALL_DATAREG)); - operaz.set(13, alleg.get(ALL_NUMDOC)); - operaz.set(14, imponibile); - operaz.set(15, imposta); - operaz.set(16, alleg.get(ALL_DATARETT)); - operaz.set(17, numrett); - operaz.set(18, segno_imponibile); - operaz.set(19, segno_imposta); - } - else - { - operaz.new_rec("4"); // Note di variazione a soggetti residenti - if (anag.partita_IVA().full()) - operaz.set(2, anag.partita_IVA()); - else - operaz.set(3, anag.codice_fiscale()); - - operaz.set(4, alleg.get(ALL_DATAREG)); - operaz.set(5, alleg.get(ALL_NUMDOC)); - operaz.set(6, imponibile); - operaz.set(7, imposta); - operaz.set(8, alleg.get(ALL_DATARETT)); - operaz.set(9, numrett); - operaz.set(10, segno_imponibile); - operaz.set(11, segno_imposta); - } - - return true; -} - -bool TDati_rilevanti_msk::send_fatt(const TRectype& alleg, TDati_rilevanti_set& operaz) -{ - const real importo = alleg.get_real(ALL_IMPORTO); - const real imposta = alleg.get_real(ALL_IMPOSTA); - if (importo.is_zero() && imposta.is_zero()) - return false; - - const TAnagrafica anag(alleg); - if (!anag.ok()) - return false; - - if (anag.estero()) - { - operaz.new_rec("3"); // Operazioni con soggetti non residenti - if (anag.fisica()) - { - operaz.set(2, anag.cognome()); - operaz.set(3, anag.nome()); - operaz.set(4, anag.data_nascita()); - operaz.set(5, anag.comune_nascita()); - operaz.set(6, anag.provincia_nascita()); - operaz.set(7, anag.stato_estero_UNICO()); - } - else - { - operaz.set(8, anag.ragione_sociale()); - if (anag.comune_residenza().blank()) - operaz.set(9, anag.localita_residenza()); - else - operaz.set(9, anag.comune_residenza()); - operaz.set(10, anag.stato_estero_UNICO()); - operaz.set(11, anag.indirizzo_residenza()); - } - operaz.set(12, alleg.get(ALL_DATAREG)); - operaz.set(13, alleg.get(ALL_NUMDOC)); - operaz.set(14, alleg.get(ALL_MODPAG)); - operaz.set(15, importo); - operaz.set(16, imposta); - operaz.set(17, alleg.get(ALL_TIPOPE)); - } - else - { - const TString& paiv = anag.partita_IVA(); - if (paiv.blank()) - { - const real tot = real(importo+imposta); - if (tot < 3600) // Limite imposto dal programma di controllo dal 2011 in poi - return false; - operaz.new_rec("1"); // Operazioni con soggetti residenti non titolari di partita IVA - operaz.set(2, anag.codice_fiscale()); - operaz.set(3, alleg.get(ALL_DATAREG)); - operaz.set(4, alleg.get(ALL_MODPAG)); - operaz.set(5, tot); - } - else - { - operaz.new_rec("2"); // Operazioni con soggetti residenti - titolari di partita IVA - operaz.set(2, paiv); - operaz.set(3, alleg.get(ALL_DATAREG)); - operaz.set(4, alleg.get(ALL_NUMDOC)); - operaz.set(5, alleg.get(ALL_MODPAG)); - operaz.set(6, alleg.get(ALL_IMPORTO)); - operaz.set(7, alleg.get(ALL_IMPOSTA)); - operaz.set(8, alleg.get(ALL_TIPOPE)); - } - } - - return true; -} - -bool TDati_rilevanti_msk::send_rec(const TRectype& alleg, TDati_rilevanti_set& operaz) -{ - bool done = false; - if (fe_is_nota_variazione(alleg)) - done = send_nota_variazione(alleg, operaz); - else - done = send_fatt(alleg, operaz); - return done; -} - -bool TDati_rilevanti_msk::recall_alleg() const -{ - const int anno = get_int(F_ANNO); - if (!yesno_box(FR("Si desidera annullare l'invio definitivo dei movimenti del %d?"), anno)) - return false; - - TFast_isamfile mov(LF_MOV); - - TString query; - query << "USE MOV KEY 2 SELECT ANNOFE=" << anno; - query << "\nFROM DATAREG=01-01-" << anno; - TISAM_recordset recset(query); - TLocalisamfile& file = recset.cursor()->file(); - - TProgind pi(recset.items(), TR("Aggiornamento movimenti di prima nota")); - for (bool ok = recset.move_first(); ok; ok = recset.move_next()) - { - if (!pi.addstatus(1)) - break; - file.zero(MOV_ANNOFE); - file.rewrite(); - } - - return true; -} - -void TDati_rilevanti_msk::build_outname(TFilename& n) const -{ - const int anno = get_int(F_ANNO); - n = get(F_OUTFOLDER); - if (n.blank()) - n.tempdir(); - - TString f; f.format("Spesometro%04d_%05d", anno, prefix().get_codditta()); - n.add(f); - n.ext("txt"); -} - -// Genera file per invio telematico -bool TDati_rilevanti_msk::send_alleg() -{ - const int anno = get_int(F_ANNO); - const bool send_all = get_int(F_SENDALL) != 1; - - TFilename temp; build_outname(temp); - - TDati_rilevanti_array data; - - TString query; - query << "USE ALLEG KEY 2" - << "\nFROM " << ALL_ANNO << '=' << anno - << "\nTO " << ALL_ANNO << '=' << anno; - - TISAM_recordset alleg(query); - const TRecnotype tot_alleg = alleg.items(); - - if (tot_alleg > 0) - { - _log = new TLog_report(temp); - - const TRectype& rec = alleg.cursor()->curr(); - - TString16 last_clifo; - TArray fatt, note; - - TProgind pi(tot_alleg, TR("Elaborazione file")); - for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) - { - if (!pi.addstatus(1)) - break; - - TString16 clifo = rec.get(ALL_OCFPI); - if (clifo.blank()) - clifo = rec.get(ALL_CODCF); - - if (clifo != last_clifo) - { - if (!fatt.empty() || !note.empty()) - { - data.add(fatt, note, send_all, *_log); - fatt.destroy(); - note.destroy(); - } - last_clifo = clifo; - } - - if (fe_is_nota_variazione(rec)) - note.add(rec); - else - fatt.add(rec); - } - if (!fatt.empty() || !note.empty()) - data.add(fatt, note, send_all, *_log); - - if (_log->recordset()->items()) - _log->preview(); - delete _log; - _log = NULL; - } - - TDati_rilevanti_set recset(anno); - const int tipologia = recset.add_header(*this); - - if (tipologia != 2) // Invio i record tranne che in caso di annullamento - { - const int tot = data.items(); - if (tot > 0) - { - TProgind pi(tot, TR("Generazione file per Agenzia delle Entrate")); - for (int a = 0; a < tot; a++) - { - if (!pi.addstatus(1)) - break; - const TExclusion_mode em = (TExclusion_mode)data[a].get_int(ALL_IGNORA); - if (em == em_incluso || (em == em_importo_limite && send_all)) - send_rec(data[a], recset); - } - } - } - recset.add_footer(); - recset.sort(); - bool done = recset.save_as(temp); - - const long maxalleg = get_long(F_MAXREC); - if (recset.items() > maxalleg) - done = recset.split(temp, maxalleg); - - if (done && get_bool(F_DEFINITIVO) && yesno_box(TR("Si desidera confermare l'invio definitivo della comunicazione?"))) - { - TFast_isamfile mov(LF_MOV); - TProgind pi(data.items(), TR("Aggiornamento movimenti di prima nota"), false); - for (int i = data.items()-1; i >= 0; i--) - { - pi.addstatus(1); - const TRectype& alleg = data[i]; - const long numreg = alleg.get_long(ALL_PROGR); - const int ignora = alleg.get_int(ALL_IGNORA); - if (numreg > 0 && numreg < MANUAL_ROW && !ignora) - { - mov.put(MOV_NUMREG, numreg); - int err = mov.read(_isequal, _lock); - if (err == NOERR) - { - const int modpag = alleg.get_int(ALL_MODPAG); - mov.put(MOV_MODPAG, modpag); - if (modpag < 2) - { - const TString& nr = alleg.get(ALL_NUMRETT); - if (nr.full() && nr != INVALID_NUMDOC) - { - mov.put(MOV_DATARETT, alleg.get(ALL_DATARETT)); - mov.put(MOV_NUMRETT, nr); - } - } - else - mov.put(MOV_CONTRATTO, alleg.get(ALL_CONTRATTO)); - mov.put(MOV_ANNOFE, anno); - err = mov.rewrite(); - } - if (err != NOERR) - { - error_box(FR("Impossibile aggiornare il movimento %ld: errore %d"), numreg, err); - break; - } - } - } - } - - return done; -} - -void TDati_rilevanti_msk::set_dirty(bool d) -{ - _sheet_dirty = d; - enable(DLG_SAVEREC, d); -} - -void TDati_rilevanti_msk::alleg_sort(TSheet_field& s) const -{ - const int c_codcf = s.cid2index(A_CODCF); - const int c_numdoc = s.cid2index(A_NUMDOC); - const int c_numrett = s.cid2index(A_NUMRETT); - const int c_forzata = s.cid2index(A_FORZATA); - const int c_ignora = s.cid2index(A_IGNORA); - const int c_importo = s.cid2index(A_IMPORTO); - const int tot = s.items(); - - for (int k = 0; k < 3; k++) - { - bool swapped = false; // Something swapped? - for (int i = tot-1; i >= 0; i--) - { - const TString8 numrett = s.cell(i, c_numrett); - if (numrett.full() && numrett != INVALID_NUMDOC) - { - const long codcf_i = atol(s.cell(i, c_codcf)); - int j = -1; - if (codcf_i == 37789) - int cazzone = 1; - // Cerca la fattura andando in su - for (j = i-1; j >= 0; j--) - { - const long codcf_j = atol(s.cell(j, c_codcf)); - if (codcf_j != codcf_i) - { - j = -1; - break; - } - if (numrett == s.cell(j, c_numdoc) || numrett == s.cell(j, c_numrett)) - break; - } - if (j < 0) // Non l'ho trovata - { - // Cerca la fattura andando in giù - for (j = i+1; j < tot; j++) - { - const long codcf_j = atol(s.cell(j, c_codcf)); - if (codcf_j != codcf_i) - { - j = tot; - break; - } - if (numrett == s.cell(j, c_numdoc)) - break; - } - } - if (j >= 0 && j < tot) // L'ho trovata - { - if (i != j+1) - { - swapped = true; - s.move_row(i, j+1); - } - if (*s.cell(j, c_numrett) <= ' ') - s.set_back_and_fore_color(REQUIRED_BACK_COLOR, NORMAL_COLOR, j, c_numdoc); - s.set_back_and_fore_color(REQUIRED_BACK_COLOR, NORMAL_COLOR, j+1, c_numrett); - } - } - } - if (!swapped) - break; // No row swapping -> exit - } -} - -void TDati_rilevanti_msk::load_sheet() -{ - TWait_cursor hourglass; - const char tipocf = get(F_TIPOCF)[0]; - const long codcf = get_long(F_CODCF); - const TString& ocfpi = get(F_OCFPI); - const int show_all = get_int(F_SHOWALL); - - TSheet_field& s = sfield(F_RIGHE); - s.hide(); // Nascondo lo sheet per guadagnare un 20% di velocità di caricamento - s.destroy(); - - _mode = MODE_QUERY; - - const int anno = get_int(F_ANNO); - - TString limit; limit << ALL_ANNO << '=' << anno; - if (codcf > 0) - limit << ' ' << ALL_TIPOCF << '=' << tipocf << ' ' << ALL_CODCF << '=' << codcf; - - TString sel; - if (ocfpi.full() || (show_all > 0 && show_all < 7)) - { - if (ocfpi.full()) - sel << "(" << ALL_OCFPI << "='" << ocfpi << "')"; - if (show_all > 0 && show_all < 7) - { - if (sel.full()) sel << "&&"; - sel << "(STR(" << ALL_IGNORA; - switch (show_all) - { - case 1: sel << '<'; break; // Importi superiori al limite (20000 o 3000) - case 2: sel << '='; break; // Importi inferiori al limite (20000 o 3000) - default: sel << '>'; break; // Importi scartati (esteri o leggi speciali) - } - sel << "1))"; - } - } - - TString query; - query << "USE " << LF_ALLEG << " KEY 2"; - if (sel.full()) - query << " SELECT " << sel; - if (limit.full()) - query << "\nFROM " << limit << "\nTO " << limit; - - TISAM_recordset alleg(query); - const TRecnotype items = alleg.items(); - if (items > 0) - { - TString pi_str; pi_str << TR("Caricamento ") << items << TR(" movimenti del ") << anno; - TProgind pi(items, pi_str); - const TRectype& curr = alleg.cursor()->curr(); - int rec = 0; - for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) - { - if (!pi.addstatus(1)) break; - s.autoload_line(++rec, curr); - - const int modpag = curr.get_int(ALL_MODPAG); - if (modpag == 1) - s.enable_cell(rec-1, A_CONTRATTO, false); - else - { - s.enable_cell(rec-1, A_DATARETT, false); - s.enable_cell(rec-1, A_NUMRETT, false); - } - } - } - alleg_sort(s); - - s.force_update(); - s.show(); - set_dirty(false); - - if (s.items() > 0) - { - _mode = MODE_MOD; - disable(-1); - } - else - { - _mode = MODE_QUERY; - enable(-1); - } - enable_buttons(); -} - -bool TDati_rilevanti_msk::save_sheet() -{ - if (!check_rows(false)) - return false; - - bool done = true; - - const int anno = get_int(F_ANNO); - - TSheet_field& s = sfield(F_RIGHE); - const TRecnotype items = s.items(); - - if (items > 0) - { - TFast_isamfile alleg(LF_ALLEG); - TRectype& rec = alleg.curr(); - TProgind pi(items, TR("Registrazione righe"), false); - - FOR_EACH_SHEET_ROW(s, r, row) - { - if (!pi.addstatus(1)) - break; - - alleg.zero(); - rec.put(ALL_ANNO, anno); - s.autosave_line(r+1, rec); - // Il tipo operazione non è più visibile, per cui lo calcolo ora - rec.put(ALL_TIPOPE, rec.get_char(ALL_TIPOCF) == 'F' ? 2 : 1); - const int err = alleg.rewrite_write(); - if (err != NOERR) - { - done = cantwrite_box(alleg.name()); - break; - } - } - } - - if (done) - { - set_dirty(false); - } - - return done; -} - -bool TDati_rilevanti_msk::check_rows(bool show_error) -{ - const int anno = get_int(F_ANNO); - bool ok = anno >= 2010; - if (!ok) - { - if (show_error) - check_fields(); // Provoco segnalazione automatica - return false; - } - - long codcf = 0L; - TString16 ocfpi; - TSheet_field& s = sfield(F_RIGHE); - FOR_EACH_SHEET_ROW(s, i, row) - { - row->get(s.cid2index(A_CODCF), codcf); - row->get(s.cid2index(A_OCFPI), ocfpi); - if (codcf <= 0L && ocfpi.blank()) - { - ok = show_error && error_box(FR("Soggetto mancante alla riga %d"), i+1); - break; - } - } - - return ok; -} - -const TString& TDati_rilevanti_msk::primo_contratto() const -{ - const TSheet_field& s = sfield(F_RIGHE); - const int c = s.cid2index(A_CONTRATTO); - FOR_EACH_SHEET_ROW(s, r, row) - { - const char* cc = row->get(c); - if (cc && *cc > ' ') - return get_tmp_string() = cc; - } - return EMPTY_STRING; -} - - -bool TDati_rilevanti_msk::save_if_dirty() -{ - bool done = true; - if (_sheet_dirty && yesno_box(TR("Si desiderano registrare le modifiche?"))) - { - done = check_rows(true); - if (done) - done = save_sheet(); - } - return done; -} - -void TDati_rilevanti_msk::enable_buttons() -{ - TSheet_field& s = sfield(F_RIGHE); - const int anno = get_int(F_ANNO); - const bool good_year = anno >= 2010; - const bool def = get_bool(F_DEFINITIVO); - const bool full_rows = good_year && !s.empty(); - - bool one_sent = false; // Ho spedito almeno un movimento in definitivo - if (good_year) - { - TString query; - query << "USE MOV KEY 2 SELECT ANNOFE=" << anno; - query << "\nFROM DATAREG=01-01-" << anno; - TISAM_recordset recset(query); - one_sent = recset.move_first(); - } - - if (id2pos(DLG_COPY) > 0) // Solo 10.0 - enable(DLG_COPY, full_rows); - enable(DLG_CANCEL, full_rows); - enable(DLG_SAVEREC,full_rows && _sheet_dirty); - enable(DLG_EXPORT, full_rows); - enable(DLG_RECALC, !full_rows && good_year && !one_sent); - enable(DLG_ELABORA, good_year && !(one_sent && def)); - enable(DLG_DELREC, one_sent); - enable(F_DEFINITIVO, !def); - if (def) reset(F_DEFINITIVO); - - TFilename temp; build_outname(temp); - enable(DLG_PREVIEW, temp.exist()); -} - -bool TDati_rilevanti_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) -{ - switch (o.dlg()) - { - case DLG_OK: // Salva - if (e == fe_button && jolly == 0) // Selezione su maschera principale - { - if (_mode == MODE_QUERY || save_if_dirty()) - load_sheet(); - return false; - } - break; - case DLG_CANCEL: - if (e == fe_button && jolly == 0) - { - if (_mode != MODE_QUERY && save_if_dirty()) - { - TSheet_field& s = sfield(F_RIGHE); - s.destroy(); - s.force_update(); - _mode = MODE_QUERY; - enable(-1); - enable_buttons(); - } - return false; - } - break; - case DLG_SAVEREC: - if (e == fe_button) - save_if_dirty(); - break; - case DLG_EXPORT: - if (e == fe_button) - return sfield(F_RIGHE).esporta(); - break; - case DLG_RECALC: - if (e == fe_button && check_fields()) - { - if (elabora_alleg()) - load_sheet(); - } - break; - case DLG_ELABORA: - if (e == fe_button && check_fields()) - { - send_alleg(); - enable_buttons(); // Disabilita bottone se definitivo - } - break; - case DLG_DELREC: - if (e == fe_button && o.active()) - { - if (jolly == 0) // Toolbar principale - { - recall_alleg(); - enable_buttons(); // Disabilita bottone - return false; - } - else // Maschera di riga - { - const long progr = o.mask().get_long(A_RIGA); - if (progr >= MANUAL_ROW) - { - TLocalisamfile alleg(LF_ALLEG); - alleg.put(ALL_ANNO, get(F_ANNO)); - alleg.put(ALL_PROGR, progr); - const int err = alleg.remove(); - if (err != NOERR) - return error_box(FR("Errore di cancellazione: %d"), err); - } - else - return error_box(TR("Riga non cancellabile")); - } - } - break; - case DLG_PREVIEW: - if (e == fe_button) - { - TFilename temp; build_outname(temp); - if (temp.exist()) - { - TDati_rilevanti_rep rep(temp); - rep.preview(); - } - } - break; - case F_ANNO: - if (e == fe_init || e == fe_modify) - { - int anno = atoi(o.get()); - if (anno < 2010) - { - anno = TDate(TODAY).year()-1; - o.set(anno); - } - on_field_event(efield(F_DATA), fe_modify, jolly); - enable_buttons(); - } - break; - case F_DATA: - if (e == fe_init || e == fe_modify) - { - const int anno = max(2010, get_int(F_ANNO)); - TDate d = o.get(); - if (d < TDate(31,12,anno) || d > TDate(31,12,anno+1)) - { - if (anno == 2010) - d = TDate(31,12,2011); - else - d = TDate(30,4,anno+1); - set(F_DATA, d); - } - } - break; - case DLG_COPY: - if (e == fe_button) - { - TSheet_field& s = sfield(F_RIGHE); - const int sel = s.selected(); - const char tipocf1 = *s.cell(sel, A_TIPOCF); - const long codcf1 = atol(s.cell(sel, A_CODCF)); - int modpag1 = atoi(s.cell(sel, A_MODPAG)); - TString80 contratto1 = s.cell(sel, A_CONTRATTO); - contratto1.trim(); - if (contratto1.empty()) - { - TMask m("fe0100c"); - m.set(F_ANNO, get(F_ANNO)); - m.set(F_TIPOCF, tipocf1 == 'F' ? "F" : "C"); - m.set(F_CODCF, codcf1); - m.set(F_RAGSOC, s.cell(sel, A_RAGSOC)); - TString80 k; k << codcf1; - m.set(A_CONTRATTO, k); - k.cut(0) << "Contratto " << codcf1 << " anno " << get(F_ANNO); - m.set(F_RAGOCC, k); - if (m.run() == K_ENTER) - { - contratto1 = m.get(A_CONTRATTO); - modpag1 = m.get_int(A_MODPAG); - TString80 codtab; - codtab.format("%c%6ld%s", tipocf1, codcf1, (const char*)contratto1); - TModule_table con("CON"); - con.put("CODTAB", codtab); - con.put("S0", m.get(F_RAGOCC)); - con.put("S6", modpag1); - const int err = con.write(); - if (err != NOERR) - { - if (err == _isreinsert) - { - if (!yesno_box(FR("Il contratto '%s' esiste già: si desidera continuare ugualmente?"), (const char*)contratto1)) - { - modpag1 = 1; - contratto1.cut(0); - } - } - else - { - cantwrite_box(con.description()); - modpag1 = 1; - contratto1.cut(0); - } - } - } - } - - if (modpag1 > 1 && contratto1.not_empty() && yesno_box("Si desidera applicare il contratto '%s' alle righe successive?", (const char*)contratto1)) - { - const int tcf = s.cid2index(A_TIPOCF); - const int ccf = s.cid2index(A_CODCF); - const int frz = s.cid2index(A_FORZATA); - const int con = s.cid2index(A_CONTRATTO); - const int ret = s.cid2index(A_NUMRETT); - const int mod = s.cid2index(A_MODPAG); - - TString80 contratto; - TString16 numrett; - for (int r = sel; r < s.items(); r++) - { - TToken_string& row = s.row(r); - - const char tipocf = row.get_char(tcf); - const long codcf = row.get_long(ccf); - if (tipocf != tipocf1 || codcf != codcf1) - break; // Sconfinamento in altro cliente - - row.get(ret, numrett); - row.get(con, contratto); - if (numrett.blank() && contratto.blank()) - { - row.add("X", frz); - row.add(modpag1, mod); - row.add(contratto1, con); - s.enable_cell(r, con); - } - } - s.force_update(); - _sheet_dirty = true; - enable_buttons(); - - } - } - break; - case F_OUTFOLDER: - if (e == fe_init && o.empty()) - { - TFilename tmp; tmp.tempdir(); - o.set(tmp); - } - break; - case F_MAXREC: - if (e == fe_init && o.empty()) - o.set(15000L); - break; - case F_RIGHE: - if (e == fe_init) - load_sheet(); else - if (e == se_query_modify) - { - TSheet_field& s = (TSheet_field&)o; - TToken_string& row = s.row(jolly); - const TRecnotype progr = row.get_long(0); - s.sheet_mask().enable(DLG_DELREC, progr >= MANUAL_ROW); - s.sheet_mask().enable(DLG_USER, progr < MANUAL_ROW); - } else - if (e == se_notify_modify) - { - set_dirty(true); - enable_buttons(); - } else - if (e == se_query_add) - { - if (!check_rows(false)) - return false; - } else - if (e == se_notify_add) - { - TSheet_field& s = (TSheet_field&)o; - TToken_string& row = s.row(jolly); - row.add(nuovo_progr(), s.cid2index(A_RIGA)); - row.add(1, s.cid2index(A_MODPAG)); - } else - if (e == se_query_del) - { - TSheet_field& s = (TSheet_field&)o; - TToken_string& row = s.row(jolly); - const TRecnotype progr = row.get_long(0); - return progr >= MANUAL_ROW; - } - break; - case A_CODCF: - case A_OCFPI: - if (e == fe_modify || (e == fe_init && !o.empty())) - { - TMask& m = o.mask(); - const TAnagrafica anag(m.get(A_TIPOCF)[0], m.get_long(A_CODCF), m.get(A_OCFPI)); - m.set(A_RAGSOC, anag.ragione_sociale()); - m.set(A_PAIV, anag.partita_IVA()); - m.set(A_COFI, anag.codice_fiscale()); - } - break; - case DLG_USER: - if (e == fe_button || e == fe_init) - { - const long numreg = o.mask().get_long(A_RIGA); - const bool enab = (numreg > 0 && numreg < MANUAL_ROW); - if (e == fe_button && enab) - { - TRectype mov(LF_MOV); - mov.put(MOV_NUMREG, numreg); - mov.edit(); - } - else - o.enable(enab); - } - break; - default: - break; - } - - if (e == fe_modify && jolly == 1 && _mode == MODE_MOD) - { - const short id = o.dlg(); - if (id >= A_RIGA && id < A_COFI && id != A_FORZATA) - o.mask().set(A_FORZATA, true); - } - - return true; -} - -/////////////////////////////////////////////////////////// -// TDati_rilevanti_app -/////////////////////////////////////////////////////////// - -class TDati_rilevanti_app : public TSkeleton_application -{ -protected: - virtual bool create(); - -public: - virtual void main_loop(); -}; - -bool TDati_rilevanti_app::create() -{ - // Controllo preventivo dell'avvenuta conversione del tracciato record - TRectype alleg(LF_ALLEG); - if (alleg.type(ALL_NUMDOC) == _nullfld) - return error_box(TR("Il database non è stato ancora convertito per il modulo FE")); - - // Teoricamente è possibile visualizzare tutti i movimenti di un anno, per cui allargo il numero riga - TSheet_field::set_line_number_width(6); - - return TSkeleton_application::create(); -} - -void TDati_rilevanti_app::main_loop() -{ - TDati_rilevanti_msk msk; - msk.run(); -} - -/////////////////////////////////////////////////////////// -// main -/////////////////////////////////////////////////////////// - -int fe0100(int argc, char* argv[]) -{ - TDati_rilevanti_app app; - app.run(argc, argv, TR("Gestione dati rilevanti")); - return 0; -} - +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "fe0100a.h" +#include "felib.h" +#include "../cg/cglib01.h" + +const char* const INVALID_NUMDOC = "???????"; +long MANUAL_ROW = 900000L; + + +/////////////////////////////////////////////////////////// +// Utility +/////////////////////////////////////////////////////////// + +enum TExclusion_mode { em_normale, em_importo_limite, em_no_allegato, + em_fiscalita_agevolata, em_estero, em_intra, + em_art8, em_data_limite, em_passaggi_interni, + em_inviato, em_altro }; + +static const char* mode2string(TExclusion_mode motivo) +{ + const char* msg = ""; + switch (motivo) + { + case em_importo_limite : msg = TR("Importo non rilevante"); break; + case em_no_allegato : msg = TR("Soggetto da non inserire in allegato"); break; + case em_fiscalita_agevolata: msg = TR("Soggetto residente in stato a fiscalità agevolata"); break; + case em_estero : msg = TR("Soggetto residente all'estero"); break; + case em_intra : msg = TR("Movimento intra"); break; + case em_data_limite : msg = TR("Data fuori dal limite della comunicazione"); break; + case em_art8 : msg = TR("Soggetto all'articolo 8 (del dpr 26-10-1972)"); break; + case em_passaggi_interni : msg = TR("Passaggi interni"); break; + case em_inviato : msg = TR("Inviato in definitivo"); break; + default : msg = TR("Altri motivi"); break; + } + return msg; +} + +/////////////////////////////////////////////////////////// +// TSpesometro_msk +/////////////////////////////////////////////////////////// + +class TSpesometro_msk : public TAutomask +{ + TMaskmode _mode; + bool _sheet_dirty; + TExclusion_mode _why; + TLog_report* _log; + TString16 _partita_IVA, _codice_fiscale; + +protected: + virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); + void alleg_sort(TSheet_field& s) const; + void load_sheet(); + bool save_sheet(); + bool save_if_dirty(); + void set_dirty(bool d = true); + + bool send_fatt(const TRectype& alleg, const TAnagrafica& anag, TSpesometro_set& operaz) const; + bool send_nota_variazione(const TRectype& alleg, const TAnagrafica& anag, TSpesometro_set& operaz) const; + bool send_estero(const TRectype& alleg, const TAnagrafica& anag, TSpesometro_set& operaz) const; + + void build_outname(TFilename& n) const; + int get_date_range(TDate& dal, TDate& al) const; + +protected: + TRecnotype last_user_progr() const; + TRecnotype nuovo_progr() const; + bool check_rows(bool show_error); + void enable_buttons(); + + void save_anagr(const TAnagrafica& anag, TSpesometro_set& operaz) const; + bool send_rec(const TRectype& alleg, TSpesometro_set& operaz); + TExclusion_mode segnala_movimento(const TRectype& mov, TExclusion_mode motivo); + + //bool fattura_associata(long numreg_var, TDate& datafatt, TString& numdoc) const; + bool azzera_alleg(TAssoc_array& manuali) const; + +public: + TRecnotype genera_alleg(); + bool elabora_alleg(); + bool send_alleg(); + bool recall_alleg() const; + + TExclusion_mode elabora_movimento(const TRectype& mov, TBaseisamfile& falleg); + + bool salva_allegato(const TRectype& mov, TBaseisamfile& falleg, TRecnotype& progr, + const real& corrispettivo, const real& imposta, int tipope); + + TExclusion_mode validate_clifo(const TRectype& mov); + TExclusion_mode validate_mov(const TRectype& mov); + + TSpesometro_msk(); + ~TSpesometro_msk() { save_profile(); } +}; + +TSpesometro_msk::TSpesometro_msk() : TAutomask("fe0100a"), _mode(MODE_QUERY), _log(NULL) +{ + load_profile(); + set_dirty(false); + const long codditta = prefix().get_codditta(); + const TAnagrafica ditta(LF_NDITTE, codditta); + _partita_IVA = ditta.partita_IVA(); + if (_partita_IVA.blank()) + _codice_fiscale = ditta.codice_fiscale(); + else + { + if (_partita_IVA[0] == '8' || _partita_IVA[0] == '9') + { + _codice_fiscale = _partita_IVA; + _partita_IVA.cut(0); + } + } +} + +TExclusion_mode TSpesometro_msk::segnala_movimento(const TRectype& mov, TExclusion_mode motivo) +{ + if (_why == em_normale) // Aggiorna motivo esclusione se normale + { + _why = motivo; + + bool segnala = true; + if (_why != em_fiscalita_agevolata && get(F_TIPO) == "BL") // Segnalo solo black list + segnala = false; + if (segnala) + { + const long numreg = mov.get_long(MOV_NUMREG); + const char tipocf = mov.get_char(MOV_TIPO); + const long codcf = mov.get_long(MOV_CODCF); + const TAnagrafica a(tipocf, codcf, mov.get(MOV_OCFPI)); + TString msg; + msg.format(FR("Mov. %7ld %s %s: "), numreg, + tipocf=='F' ? TR("For.") : TR("Cli."), (const char*)a.ragione_sociale()); + msg << mode2string(motivo); + + if (a.estero() && a.stato_estero_UNICO().blank()) + msg << " (Codice UNICO non specificato)"; + + msg.strip_double_spaces(); + _log->log(1, msg); + } + } + return motivo; +} + +TExclusion_mode TSpesometro_msk::validate_clifo(const TRectype& mov) +{ + const char tipocf = mov.get_char(MOV_TIPO); + const long codcf = mov.get_long(MOV_CODCF); + const TString16 ocfpi = mov.get(MOV_OCFPI); + if (tipocf <= ' ' || (codcf <= 0 && ocfpi.blank())) + return segnala_movimento(mov, em_no_allegato); + + TString8 key; key.format("%c|%ld", tipocf, codcf); + const TRectype& rec_clifo = cache().get(LF_CLIFO, key); + const int alleg = rec_clifo.get_int(CLI_ALLEG); + + if (alleg == 4) + { + const long codalleg = rec_clifo.get_long(CLI_CODALLEG); + key; key.format("%c|%ld", tipocf, codalleg); + const TRectype& rec_alleg = cache().get(LF_CLIFO, key); + if (!rec_alleg.empty()) + { + ((TRectype&)mov).put(MOV_CODCF, codalleg); + return validate_clifo(mov); + } + } + + TString4 stato; + if (ocfpi.full()) + { + const TRectype& rec_occas = cache().get(LF_OCCAS, ocfpi); + stato = rec_occas.get(OCC_STATO); + } + else + { + if (alleg == 1) + return segnala_movimento(mov, em_no_allegato); + + if (alleg == 5) + return segnala_movimento(mov, em_intra); + + stato = rec_clifo.get(CLI_STATOCF); + + if (stato.blank() && alleg == 9) // Flag extra CEE incoerente + return segnala_movimento(mov, em_estero); + } + + if (stato.full()) + { + // I clienti privati vanno inclusi anche se residenti in stati esteri in black list + if (ocfpi.blank() && alleg != 6) + { + const TRectype& rec_sta = cache().get("%STA", stato); + if (rec_sta.get_bool("B0") || rec_sta.get_bool("B1")) // Black list o San Marino + return segnala_movimento(mov, em_fiscalita_agevolata); + } + return segnala_movimento(mov, em_estero); + } + + return em_normale; // se arriva qui il clifo è da considerare +} + +TExclusion_mode TSpesometro_msk::validate_mov(const TRectype& mov) +{ + // Ignora eventuale vecchio movimento IVA (ANNOIVA < 2012) + const int anno = mov.get_int(MOV_ANNOIVA); + if (anno < 2012) + return segnala_movimento(mov, em_data_limite); + + // Trova i movimenti INTRA + if (!mov.get_real(MOV_CORRLIRE).is_zero() || + !mov.get_real(MOV_CORRVALUTA).is_zero()) + return segnala_movimento(mov, em_intra); + + const TString& keytok = mov.get(MOV_NUMREG); + const char tipocf = mov.get_char(MOV_TIPO); + TRecord_array righe_iva(keytok, LF_RMOVIVA); + real tot_imponibile, tot_imposta; + //calcolo di imponibile ed imposta di tutte le righe iva del movimento + for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r)) + { + const TRectype& rmi = righe_iva.row(r); + const TCodiceIVA ci(rmi.get(RMI_CODIVA)); + const int natura_operazione = ci.allegato(tipocf); + if (natura_operazione <= 0 || natura_operazione > 5) + continue; + tot_imponibile += rmi.get_real(RMI_IMPONIBILE); + tot_imposta += rmi.get_real(RMI_IMPOSTA); + } + + if (tot_imponibile.is_zero() && tot_imposta.is_zero()) + { + TExclusion_mode em = validate_clifo(mov); + if (em == em_normale) + em = segnala_movimento(mov, em_importo_limite); + return em; + } + + return validate_clifo(mov); +} + +TExclusion_mode TSpesometro_msk::elabora_movimento(const TRectype& mov, TBaseisamfile& falleg) +{ + TExclusion_mode em = validate_mov(mov); + + const char tipocf = mov.get_char(MOV_TIPO); + const long codcf = mov.get_long(MOV_CODCF); + const TString4 tipodoc = mov.get(MOV_TIPODOC); + const TDate datareg = mov.get_date(MOV_DATAREG); + const int anno = get_int(F_ANNO); + + TString4 tipope = "FE"; // Default = Fattura emessa + + if (em == em_fiscalita_agevolata) + { + tipope = "BL"; + } else + if (em == em_estero) + { + if (tipocf == 'C') + tipope = "FN"; + } + else + { + const bool is_nota = fe_is_nota_variazione(mov); + if (tipocf == 'F') + { + tipope = is_nota ? "NR" : "FR"; + } + else + { + tipope = is_nota ? "NE" : "FE"; + } + } + + const TString& keytok = mov.get(MOV_NUMREG); + TRecord_array righe_iva(keytok, LF_RMOVIVA); + int tipo_iva = 1; // Normale + real tot_imponibile, tot_imposta; + real ser_imponibile, mer_imponibile; + //calcolo di imponibile ed imposta di tutte le righe iva del movimento + for (int r = righe_iva.last_row(); r > 0; r = righe_iva.pred_row(r)) + { + const TRectype& rmi = righe_iva.row(r); + const TCodiceIVA ci(rmi.get(RMI_CODIVA)); + int natura_operazione = ci.allegato(tipocf); + if (natura_operazione <= 0 || natura_operazione > 5) + continue; // Scarta codici IVA non rilevanti + if (natura_operazione > tipo_iva) + tipo_iva = natura_operazione; + // Esportazioni + const bool art_8 = ci.get("S2") == "20" && ci.get("S3") == "1"; + if (art_8) + segnala_movimento(mov, em_art8); + + const TString4 cod_det = rmi.get(RMI_TIPODET); + const int tip_det = cod_det == "3" ? 3 : atoi(cache().get("%DET", cod_det, "I0")); + if (tip_det == 3) + segnala_movimento(mov, em_passaggi_interni); + + real rmi_imponibile = rmi.get_real(RMI_IMPONIBILE); + real rmi_imposta = rmi.get_real(RMI_IMPOSTA); + + if (natura_operazione == 4 && rmi_imposta.is_zero()) // se l'imposta non è specificata sullo scontrino ... + rmi_imposta = ci.scorpora(rmi_imponibile); // ... scorporo il lordo + + tot_imponibile += rmi_imponibile; + tot_imposta += rmi_imposta; + + if (tipope == "SE") + { + const TBill zio(rmi); + const TRectype& rec = cache().get(LF_PCON, zio.string()); + if (rec.get_int(PCN_RICSER) == 1) // 0=Altro; 1=Servizi; 2=Merce + ser_imponibile += rmi_imponibile; + else + mer_imponibile += rmi_imponibile; + } + } + + const long numreg = mov.get_long(MOV_NUMREG); + + // Registro tutti i dati del cliente e gli importi + falleg.zero(); + + switch (em) + { + case em_normale: + { + TString8 key; key << tipocf << '|' << codcf; + const TRectype& clifo = cache().get(LF_CLIFO, key); + if (clifo.get_char(CLI_ALLEG) == 'C') // Carta carburanti + falleg.put(ALL_CARBURAN, true); + else + { + if (tipocf == 'C') + { + bool af = false; + if (_partita_IVA.full()) + af = _partita_IVA == clifo.get(CLI_PAIV); + else + af = _codice_fiscale == clifo.get(CLI_COFI) && clifo.get(CLI_PAIV).blank(); // Agriturismo + if (af) + { + falleg.put(ALL_AUTOFATT, af); + if (tot_imponibile.is_zero() && !tot_imposta.is_zero()) + tot_imponibile = tot_imposta.sign(); + } + } + if (mov.get_int(MOV_UPROTIVA) > 0) + falleg.put(ALL_RIEPILOG, true); + } + } + break; + case em_fiscalita_agevolata: + if (abs(tot_imponibile) <= 500) + falleg.put(ALL_IGNORA, em = em_importo_limite); // Ignora importo <= 500 Euro + break; // Non ignorare! + case em_estero: + if (tot_imponibile.is_zero()) + falleg.put(ALL_IGNORA, em = em_importo_limite); // Ignora importo nullo + else + { + if (tipocf == 'F') // Considera solo fatture servizi + { + if (ser_imponibile > mer_imponibile) + falleg.put(ALL_SERVIZI, true); + else + falleg.put(ALL_IGNORA, em); // Ignora importazioni di merce + } + } + break; + case em_intra: + if (tipocf == 'C' && !tot_imposta.is_zero()) + { + tipope = "FN"; + em = em_estero; + break; + } + default: + falleg.put(ALL_IGNORA, em); // Ignora + break; + } + if (mov.get_date(MOV_INVIOFE).ok()) + { + falleg.put(ALL_IGNORA, em_inviato); + segnala_movimento(mov, em_inviato); + } + + if (em == em_normale || em_intra) + { + if (tipocf == 'F') + { + const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS)); + const int reg_spec = caus.get_int(CAU_REGSPIVA); + if (reg_spec == 13 || reg_spec == 50 || reg_spec == 51) // reverse charge + falleg.put(ALL_REVERSE, true); + } + } + if (tipope == "SE") + { + const TAnagrafica anag(mov); + bool good = anag.comune_residenza().full(); + if (good) + { + if (anag.fisica()) + good = anag.cognome().full() && anag.data_nascita().ok(); + else + good = anag.ragione_sociale().full(); + } + if (!good) + { + falleg.put(ALL_AUTOFATT, true); + if (tot_imponibile.is_zero() && !tot_imposta.is_zero()) + tot_imponibile = tot_imposta.sign(); + } + } + + falleg.put(ALL_ANNO, anno); + falleg.put(ALL_PROGR, numreg); + falleg.put(ALL_TIPOPE, tipope); + falleg.put(ALL_TIPOCF, tipocf); + falleg.put(ALL_CODCF, codcf); + falleg.put(ALL_OCFPI, mov.get(MOV_OCFPI)); + falleg.put(ALL_DATAREG, mov.get(MOV_DATAREG)); + falleg.put(ALL_NUMDOC, mov.get(MOV_NUMDOC)); + falleg.put(ALL_DATADOC, mov.get(MOV_DATADOC)); + falleg.put(ALL_NOLEGGIO,mov.get(MOV_NOLEGGIO)); + falleg.put(ALL_TIPOIVA, tipo_iva); + falleg.put(ALL_IMPORTO, tot_imponibile); + falleg.put(ALL_IMPOSTA, tot_imposta); + + const int err = falleg.rewrite_write(); + if (err != NOERR) + { + TString msg; + msg.format(FR("Errore %d di aggiornamento del record %d/%ld sul file %s"), + err, anno, numreg, (const char*)falleg.name()); + _log->log(2, msg); + } + + return _why; +} + +bool TSpesometro_msk::azzera_alleg(TAssoc_array& manuali) const +{ + TDate dataini, datafin; + const int anno = get_date_range(dataini, datafin); + if (!delete_box(FR("Si desiderano eliminare le righe dal %s al %s"), + dataini.stringa(), datafin.stringa())) + return false; + + TFast_isamfile fast_alleg(LF_ALLEG); + TFast_isamfile fast_mov(LF_MOV); + + TString query; + query << "USE " << LF_ALLEG + << "\nSELECT BETWEEN(DATAREG," << dataini.date2ansi() << ',' << datafin.date2ansi() << ')' + << "\nJOIN MOV INTO NUMREG==PROGR" + << "\nFROM ANNO=" << anno + << "\nTO ANNO=" << anno << " PROGR=" << MANUAL_ROW; + TISAM_recordset alleg(query); + + TLocalisamfile& falleg = alleg.cursor()->file(); + TRectype& arec = falleg.curr(); + + TLocalisamfile& fmov = alleg.cursor()->file(LF_MOV); + TRectype& mrec = fmov.curr(); + + TString msg; msg << TR("Azzeramento ") << falleg.description() << ' ' << anno; + TProgind pi(alleg.items(), msg, false); + + manuali.destroy(); + for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) + { + pi.addstatus(1); + + const long progr = arec.get_long(ALL_PROGR); + const long numreg = mrec.get_long(MOV_NUMREG); + const TDate datareg = mrec.get_long(MOV_DATAREG); + const int annoiva = mrec.get_long(MOV_ANNOIVA); + + bool kill = numreg != progr || annoiva < anno; + if (!kill) + { + const bool forzata = arec.get_bool(ALL_FORZATURA); + if (forzata) + manuali.add(arec.get(ALL_PROGR)); + else + kill = annoiva == anno; + } + if (kill) + falleg.remove(); // Riga generata dalla vecchia versione + } + return !manuali.empty(); +} + +// Cerca l'ultimo numero di riga immesso manualmente +TRecnotype TSpesometro_msk::last_user_progr() const +{ + const int anno = get_int(F_ANNO); + + TRecnotype progr = MANUAL_ROW; + TString query; + query << "USE " << LF_ALLEG + << "\nFROM " << ALL_ANNO << '=' << anno << ' ' << ALL_PROGR << '=' << MANUAL_ROW + << "\nTO " << ALL_ANNO << '=' << anno; + TISAM_recordset alleg(query); + if (alleg.move_last()) + progr = alleg.get(ALL_PROGR).as_int(); + return progr; +} + +TRecnotype TSpesometro_msk::nuovo_progr() const +{ + TRecnotype progr = last_user_progr(); + + TSheet_field& righe = sfield(F_RIGHE); + const int items = righe.items(); + if (items > 0) + { + const int col = righe.cid2index(A_RIGA); + for (int i = items-1; i >= 0; i--) + { + const TRecnotype sheet_progr = atol(righe.cell(i,col)); + if (sheet_progr > progr) + progr = sheet_progr; + } + } + + return progr+1; +} + +static int sort_alleg(const TSortable& s1, const TSortable& s2, void* jolly) +{ + const TRectype& a1 = (const TRectype&)s1; + const TRectype& a2 = (const TRectype&)s2; + + const TDate d1 = a1.get(ALL_DATAREG); + const TDate d2 = a2.get(ALL_DATAREG); + int cmp = d1 - d2; + + return cmp; +} + +TRecnotype TSpesometro_msk::genera_alleg() +{ + const int anno = get_int(F_ANNO); + + TString str_pi; + str_pi << TR("Movimenti"); + str_pi << ' ' << anno; + _log = new TLog_report(str_pi); + + TAssoc_array manuali; + azzera_alleg(manuali); + + TRecnotype nprog = 1; + + if (anno >= 2012) // Dummy test for bracing TFast_isamfiles + { + TFast_isamfile falleg(LF_ALLEG); + TFast_isamfile fmov(LF_MOV); + + const TDate dal(1,1,anno); + const TDate al(31,12,anno); + + TString query; + query << "USE MOV KEY 3 SELECT (BETWEEN(DATAREG," + << dal.date2ansi() << ',' << al.date2ansi() << "))&&(REG!=\"\")" + << "\nFROM TIPO=C\nTO TIPO=F"; + TISAM_recordset mov(query); + TRectype& mov_rec = mov.cursor()->curr(); + const TRecnotype items = mov.items(); + + TProgind pi(items, str_pi); + for (bool ok = mov.move_first(); ok; ok = mov.move_next()) + { + if (!pi.addstatus(1)) + break; + _why = em_normale; + + const TDate datafe = mov_rec.get(MOV_INVIOFE); + if (datafe.ok()) // Non elaborare i movimenti già inviati in definitivo! + { + segnala_movimento(mov_rec, em_inviato); + continue; + } + + const TString& key = mov_rec.get(MOV_NUMREG); + if (manuali.is_key(key)) + { + manuali.remove(key); + continue; + } + elabora_movimento(mov_rec, falleg); + } + } + + _log->preview(); + delete _log; + _log = NULL; + + return nprog; +} + +// Analizza tutti i movimenti dell'anno dell'attività corrente e genera i record rilevanti +bool TSpesometro_msk::elabora_alleg() +{ + if (!check_fields()) // Controlla che l'anno sia valido + return false; + + const TRecnotype prog = genera_alleg(); + return prog > 1; +} + +bool TSpesometro_msk::send_nota_variazione(const TRectype& alleg, const TAnagrafica& anag, TSpesometro_set& operaz) const +{ + const real imp = alleg.get_real(ALL_IMPORTO); + operaz.set(11, imp > ZERO ? "ND" : "NC"); + return true; +} + +bool TSpesometro_msk::send_fatt(const TRectype& alleg, const TAnagrafica& anag, TSpesometro_set& operaz) const +{ + return true; +} + +bool TSpesometro_msk::send_estero(const TRectype& alleg, const TAnagrafica& anag, TSpesometro_set& operaz) const +{ + const char tipocf = alleg.get_char(ALL_TIPOCF); + const bool is_nota = fe_is_nota_variazione(alleg); + + if (is_nota) // Le istruzioni dicono di ignorarla, ma Sirio non ha ancora deciso + send_nota_variazione(alleg, anag, operaz); // Imposta solamente il campo 11 a ND o NC + + const char cayman = anag.is_black_list(); + const bool servizi = tipocf == 'F' && alleg.get_bool(ALL_SERVIZI); + + if (servizi && alleg.get_bool(ALL_AUTOFATT)) + { + // Trasforma la fattura da non residente ad autofattura + operaz.set(0, "FR"); + // Azzera campi anagrafici e sostituiscili con quelli del dichiarante + const long codditta = prefix().get_codditta(); + const TAnagrafica ditta(LF_NDITTE, codditta); + for (int f = 14; f <= 26; f++) + operaz.set(f, ""); + save_anagr(ditta, operaz); + return true; + } + + + // I flag 27,28,29 sono obbligatori e mutuamente esclusivi + if (cayman > ' ') // Residente in paese a fiscalità agevolata (o San Marino) + { + const char str[2] = { cayman, '\0' }; // Convert char to string + operaz.set(27, str); + } + else + { + if (servizi) + operaz.set(29, true); // Acquisto servizi all'estero + else + operaz.set(28, true); // Residente all'estero + } + + const char* sez = "BL30"; + if (cayman > ' ') + { + if (is_nota) + sez = "BL50"; + else + { + if (alleg.get_int(ALL_TIPOIVA) == 4) // Non esposta + sez = "BL41"; + } + } + operaz.set(30, sez); // Tipologia imponibile BL + + return true; +} + +void TSpesometro_msk::save_anagr(const TAnagrafica& anag, TSpesometro_set& operaz) const +{ + // Partita IVA e Codice fiscale sono alternativi + const TString& piva = anag.partita_IVA(); + if (piva.full()) + { + if (piva[0] >= '8' && piva.len() == 11 && anag.italiano()) // Ente pubblico! + operaz.set(2, piva); // In realtà trattasi di codice fiscale speciale! + else + operaz.set(1, piva); + } + else + operaz.set( 2, anag.codice_fiscale()); + + if (anag.fisica()) + { + operaz.set(14, anag.cognome()); + operaz.set(15, anag.nome()); + operaz.set(16, anag.data_nascita()); + operaz.set(17, anag.comune_nascita()); + operaz.set(18, anag.provincia_nascita()); + operaz.set(19, anag.stato_estero_UNICO()); + operaz.set(20, anag.comune_residenza()); + operaz.set(21, anag.indirizzo_residenza()); + } + else + { + operaz.set(22, anag.ragione_sociale()); + operaz.set(23, anag.comune_residenza()); + operaz.set(24, anag.stato_estero_UNICO()); + operaz.set(25, anag.indirizzo_residenza()); + operaz.set(26, piva); + } +} + +bool TSpesometro_msk::send_rec(const TRectype& alleg, TSpesometro_set& operaz) +{ + bool done = false; + + const real importo = abs(alleg.get_real(ALL_IMPORTO)); + const real imposta = abs(alleg.get_real(ALL_IMPOSTA)); + if (importo.is_zero() && imposta.is_zero()) + return false; // should never happen + + const TAnagrafica anag(alleg); + if (!anag.ok()) + return false; // should never happen + + const char tipocf = alleg.get_char(ALL_TIPOCF); + + const TString4 tipo = alleg.get(ALL_TIPOPE); + operaz.new_rec(tipo); + + operaz.set(31, alleg.get_int(ALL_ATTAGG)); // Provoca nascita dei 34 campi vuoti precedenti + operaz.set(32, alleg.get_int(ALL_PASAGG)); + operaz.set(33, alleg.get_bool(ALL_RIEPILOG)); + operaz.set(34, alleg.get_bool(ALL_CARBURAN)); + + operaz.set( 3, alleg.get_int(ALL_TIPOIVA) == 4); // IVA non esposta in fattura + operaz.set( 4, alleg.get(ALL_NOLEGGIO)); // Noleggio + operaz.set( 5, alleg.get_bool(ALL_AUTOFATT)); // Autofattura + operaz.set( 6, alleg.get_bool(ALL_REVERSE)); // Reverse charge + + operaz.set( 7, alleg.get(ALL_DATADOC)); + operaz.set( 8, alleg.get(ALL_DATAREG)); + operaz.set( 9, alleg.get(ALL_NUMDOC)); + operaz.set(10, tipocf == 'F' ? "A" : "C"); // Acquisto o Cessione + + operaz.set(12, importo); + operaz.set(13, imposta); + save_anagr(anag, operaz); + + if (anag.estero()) + done = send_estero(alleg, anag, operaz); + else + { + if (fe_is_nota_variazione(alleg)) + done = send_nota_variazione(alleg, anag, operaz); + else + done = send_fatt(alleg, anag, operaz); + } + return done; +} + +bool TSpesometro_msk::recall_alleg() const +{ + TDate dal, al; + const int anno = get_date_range(dal, al); + + if (!delete_box(FR("Si desidera annullare l'invio definitivo dal %s al %s?"), + dal.stringa(), al.stringa())) + return false; + + TFast_isamfile mov(LF_MOV); + + TString query; + query << "USE MOV KEY 2"; + query << "\nFROM DATAREG=" << dal; + query << "\nTO DATAREG=" << al; + TISAM_recordset recset(query); + TLocalisamfile& file = recset.cursor()->file(); + + TString msg; + msg << TR("Aggiornamento movimenti di prima nota dal ") + << dal.stringa() << TR(" al ") << al.stringa(); + TProgind pi(recset.items(), msg); + for (bool ok = recset.move_first(); ok; ok = recset.move_next()) + { + if (!pi.addstatus(1)) + break; + if (file.get_date(MOV_INVIOFE).ok()) + { + file.zero(MOV_INVIOFE); + file.rewrite(); + } + } + + return true; +} + +void TSpesometro_msk::build_outname(TFilename& n) const +{ + TDate dal, al; + const int anno = get_date_range(dal,al); + n = get(F_OUTFOLDER); + if (n.blank()) + n.tempdir(); + + TString80 f; + if (get(F_TIPO) == "BL") + { + const int dm = dal.month(), am = al.month(); + if (dm == am) + { + TString16 m = itom(dal.month()); m.cut(3); + f.format("BlackList%05ld%s%04d", prefix().get_codditta(), (const char*)m, anno); + } else + if (am-dm == 2) + { + TString16 m; m << TR("Trim") << itor(am/3); + f.format("BlackList%05ld%s%04d", prefix().get_codditta(), (const char*)m, anno); + } + else + f.format("BlackList%05ld%04d", prefix().get_codditta(), anno); + } + else + f.format("Spesometro%05ld%04d", prefix().get_codditta(), anno); + n.add(f); + n.ext("csv"); +} + +// Genera file per invio telematico +bool TSpesometro_msk::send_alleg() +{ + const TString& tipo = get(F_TIPO); + + TDate dal, al; + const int anno = get_date_range(dal, al); + + TString query; + query << "USE ALLEG KEY 2\nSELECT "; + if (tipo == "BL") + { + query << "(BETWEEN(DATAREG," << dal.date2ansi() << ',' << al.date2ansi() << "))&&" + << "(TIPOPE==\"BL\")"; + } + else + query << "(TIPOPE!=\"BL\")"; + + query << "\nFROM " << ALL_ANNO << '=' << anno + << "\nTO " << ALL_ANNO << '=' << anno; + + TISAM_recordset alleg(query); + const TRectype& rec = alleg.cursor()->curr(); + const TRecnotype tot_alleg = alleg.items(); + + bool done = tot_alleg > 0; + if (done) + { + TSpesometro_set recset; + recset.add_header(*this); + + TFilename temp; build_outname(temp); + _log = new TLog_report(temp); + + TProgind pi(tot_alleg, temp); + for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) + { + if (!pi.addstatus(1)) + break; + + const int ignora = alleg.get(ALL_IGNORA).as_int(); // Non mi fido di "", " " e "0" per questo campo + if (ignora == 0) + send_rec(rec, recset); + } + recset.add_footer(*this); + done = recset.save_as(temp); + + if (_log->recordset()->items()) + _log->preview(); + delete _log; + _log = NULL; + } + + const char* const jar = "spesometro.jar"; + if (xvt_fsys_file_exists(jar)) + xvt_sys_goto_url(jar, "run"); // open doesn't work right now + + if (done && get_bool(F_DEFINITIVO) && yesno_box(TR("Si conferma l'invio definitivo della comunicazione?"))) + { + TFast_isamfile mov(LF_MOV); + TProgind pi(tot_alleg, TR("Aggiornamento movimenti di prima nota"), false); + for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) + { + if (!pi.addstatus(1)) + break; + const int ignora = rec.get_int(ALL_IGNORA); + if (ignora) + continue; + + const long numreg = rec.get_long(ALL_PROGR); + if (numreg > 0 && numreg < MANUAL_ROW) + { + mov.put(MOV_NUMREG, numreg); + int err = mov.read(_isequal, _lock); + if (err == NOERR) + { + if (!mov.get_date(MOV_INVIOFE).ok()) + { + mov.put(MOV_INVIOFE, al); + err = mov.rewrite(); + } + else + mov.reread(_unlock); + } + if (err != NOERR) + { + error_box(FR("Impossibile aggiornare il movimento %ld: errore %d"), numreg, err); + break; + } + } + if (numreg > 0) + { + TLocalisamfile& fall = alleg.cursor()->file(); + fall.put(ALL_IGNORA, em_inviato); + fall.rewrite(); + } + } + } + + return done; +} + +void TSpesometro_msk::set_dirty(bool d) +{ + _sheet_dirty = d; + enable(DLG_SAVEREC, d); +} + +void TSpesometro_msk::alleg_sort(TSheet_field& s) const +{ + s.sort(); +} + +void TSpesometro_msk::load_sheet() +{ + TWait_cursor hourglass; + const char tipocf = get(F_TIPOCF)[0]; + const long codcf = get_long(F_CODCF); + const TString& ocfpi = get(F_OCFPI); + + TSheet_field& s = sfield(F_RIGHE); + s.hide(); // Nascondo lo sheet per guadagnare un 20% di velocità di caricamento + s.destroy(); + + _mode = MODE_QUERY; + + const TString& tipope = get(F_TIPO); + TDate dal, al; + const int anno = get_date_range(dal, al); + + TString limit; limit << ALL_ANNO << '=' << anno; + if (codcf > 0) + limit << ' ' << ALL_TIPOCF << '=' << tipocf << ' ' << ALL_CODCF << '=' << codcf; + + TString sel; + if (ocfpi.full()) + sel << "&&(" << ALL_OCFPI << "='" << ocfpi << "')"; + + if (tipope != "**") // Tutto + { + if (tipope == "XX") + { + sel << "&&(STR(IGNORA>0))"; + } else + if (tipope == "IN") + { + sel << "&&(STR(IGNORA==9))"; + } + else + { + if (tipope == "BL") + sel << "&&(TIPOPE=\"BL\")"; // Black List + else + sel << "&&(TIPOPE!=\"BL\")"; // Spesometro + sel << "&&(STR(IGNORA==0))"; + } + } + + if (dal.month() != 1 || al.month() != 12) + sel << "&&(BETWEEN(DATAREG," << dal.date2ansi() << ',' << al.date2ansi() << "))"; + + TString query; + query << "USE " << LF_ALLEG << " KEY 2"; + if (sel.full()) + { + sel.ltrim(2); + query << " SELECT " << sel; + } + if (limit.full()) + query << "\nFROM " << limit << "\nTO " << limit; + + TISAM_recordset alleg(query); + const TRecnotype items = alleg.items(); + if (items > 0) + { + TString pi_str; + pi_str << TR("Caricamento ") << items << TR(" movimenti "); + if (dal.month() != 1 || al.month() != 12) + { + if (dal.month() == al.month()) + pi_str << itom(dal.month()) << ' '; + else + pi_str << itom(dal.month()) << '/' << itom(al.month()) << ' '; + + } + pi_str << anno; + TProgind pi(items, pi_str); + TRectype& curr = alleg.cursor()->curr(); + int rec = 0; + for (bool ok = alleg.move_first(); ok; ok = alleg.move_next()) + { + if (!pi.addstatus(1)) + break; + if (anno <= 2012) + { + const int t = curr.get_int(ALL_TIPOPE); + switch (t) + { + case 1: curr.put(ALL_TIPOPE, "FE"); break; + case 2: curr.put(ALL_TIPOPE, "FR"); break; + default: break; + } + } + s.autoload_line(++rec, curr); + } + } + //alleg_sort(s); + + s.force_update(); + s.show(); + set_dirty(false); + + if (s.items() > 0) + { + _mode = MODE_MOD; + disable(-1); + } + else + { + _mode = MODE_QUERY; + enable(-1); + } + enable_buttons(); +} + +bool TSpesometro_msk::save_sheet() +{ + if (!check_rows(false)) + return false; + + bool done = true; + + const int anno = get_int(F_ANNO); + + TSheet_field& s = sfield(F_RIGHE); + const TRecnotype items = s.items(); + + if (items > 0) + { + TFast_isamfile alleg(LF_ALLEG); + TRectype& rec = alleg.curr(); + TProgind pi(items, TR("Registrazione righe"), false); + + FOR_EACH_SHEET_ROW(s, r, row) + { + if (!pi.addstatus(1)) + break; + + alleg.zero(); + rec.put(ALL_ANNO, anno); + s.autosave_line(r+1, rec); + const int err = alleg.rewrite_write(); + if (err != NOERR) + { + done = cantwrite_box(alleg.name()); + break; + } + } + } + + if (done) + { + set_dirty(false); + } + + return done; +} + +bool TSpesometro_msk::check_rows(bool show_error) +{ + const int anno = get_int(F_ANNO); + bool ok = anno >= 2012; + if (!ok) + { + if (show_error) + check_fields(); // Provoco segnalazione automatica + return false; + } + + long codcf = 0L; + TString16 ocfpi; + TSheet_field& s = sfield(F_RIGHE); + FOR_EACH_SHEET_ROW(s, i, row) + { + row->get(s.cid2index(A_CODCF), codcf); + row->get(s.cid2index(A_OCFPI), ocfpi); + if (codcf <= 0L && ocfpi.blank()) + { + ok = show_error && error_box(FR("Soggetto mancante alla riga %d"), i+1); + break; + } + } + + return ok; +} + +bool TSpesometro_msk::save_if_dirty() +{ + bool done = true; + if (_sheet_dirty && yesno_box(TR("Si desiderano registrare le modifiche?"))) + { + done = check_rows(true); + if (done) + done = save_sheet(); + } + return done; +} + +int TSpesometro_msk::get_date_range(TDate& dal, TDate& al) const +{ + const TDate oggi(TODAY); + int anno = get_int(F_ANNO); + if (anno < 2012) + anno = oggi.year(); + + dal = TDate( 1, 1, anno); + al = TDate(31, 12, anno); + + if (get(F_TIPO) == "BL") + { + const TString& m = get(F_PERIODO); + if (m[0] == 'T') + { + const int t = m[1]-'1'; + dal = TDate( 1, 3*t+1, anno); + al = TDate(28, 3*t+3, anno); + } + else + { + const int mese = atoi(m); + if (mese > 0) + dal = al = TDate(1, mese, anno); + } + al.set_end_month(); + } + + return anno; +} + +void TSpesometro_msk::enable_buttons() +{ + TSheet_field& s = sfield(F_RIGHE); + TDate dal, al; + const int anno = get_date_range(dal, al); + const bool good_year = anno >= 2012; + const bool def = get_bool(F_DEFINITIVO); + const bool full_rows = good_year && !s.empty(); + + bool one_sent = false; // Ho spedito almeno un movimento in definitivo + if (good_year) + { + TString query; + query << "USE MOV KEY 2 SELECT INVIOFE!=\"\""; + query << "\nFROM DATAREG=" << dal; + query << "\nTO DATAREG=" << al; + TISAM_recordset recset(query); + one_sent = recset.move_first(); + } + + enable(DLG_CANCEL, full_rows); + enable(DLG_SAVEREC,full_rows && _sheet_dirty); + enable(DLG_EXPORT, full_rows); + enable(DLG_RECALC, !full_rows && good_year && !one_sent); + enable(DLG_ELABORA, good_year && !(one_sent && def)); + enable(DLG_DELREC, one_sent); + enable(F_DEFINITIVO, !def); + if (def) reset(F_DEFINITIVO); + + TFilename temp; build_outname(temp); + enable(DLG_PREVIEW, temp.exist()); +} + +bool TSpesometro_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) +{ + switch (o.dlg()) + { + case DLG_OK: // Salva + if (e == fe_button && jolly == 0) // Selezione su maschera principale + { + if (_mode == MODE_QUERY || save_if_dirty()) + load_sheet(); + return false; + } + break; + case DLG_CANCEL: + if (e == fe_button && jolly == 0) + { + if (_mode != MODE_QUERY && save_if_dirty()) + { + TSheet_field& s = sfield(F_RIGHE); + s.destroy(); + s.force_update(); + _mode = MODE_QUERY; + enable(-1); + enable_buttons(); + } + return false; + } + break; + case DLG_SAVEREC: + if (e == fe_button) + save_if_dirty(); + break; + case DLG_EXPORT: + if (e == fe_button) + return sfield(F_RIGHE).esporta(); + break; + case DLG_RECALC: + if (e == fe_button && check_fields()) + { + if (elabora_alleg()) + load_sheet(); + } + break; + case DLG_ELABORA: + if (e == fe_button && check_fields()) + { + const TString& tipo = get(F_TIPO); + if (tipo != "FE" && tipo != "BL") + return error_box("Non è possibile inviare i record che verrebbero scartati"); + TDate dal, al; + get_date_range(dal, al); + if (tipo == "BL" && (al-dal) > 93) + return error_box("E' necessario specificare il mese o il trimestre per la Black List"); + send_alleg(); + enable_buttons(); // Disabilita bottone se definitivo + } + break; + case DLG_DELREC: + if (e == fe_button && o.active()) + { + if (jolly == 0) // Toolbar principale + { + recall_alleg(); + enable_buttons(); // Disabilita bottone + return false; + } + else // Maschera di riga + { + const long progr = o.mask().get_long(A_RIGA); + if (progr >= MANUAL_ROW) + { + TLocalisamfile alleg(LF_ALLEG); + alleg.put(ALL_ANNO, get(F_ANNO)); + alleg.put(ALL_PROGR, progr); + const int err = alleg.remove(); + if (err != NOERR) + return error_box(FR("Errore di cancellazione: %d"), err); + } + else + return error_box(TR("Riga non cancellabile")); + } + } + break; + case DLG_PREVIEW: + if (e == fe_button) + { + TFilename temp; build_outname(temp); + if (temp.exist()) + { + TSpesometro_rep rep(temp); + rep.preview(); + } + } + break; + case F_ANNO: + if (e == fe_init || e == fe_modify) + { + int anno = atoi(o.get()); + if (anno < 2013) + { + anno = TDate(TODAY).year()-1; + o.set(anno); + } + enable_buttons(); + } + break; + case F_OUTFOLDER: + if (e == fe_init && o.empty()) + { + TFilename tmp; tmp.tempdir(); + o.set(tmp); + } + break; + case F_RIGHE: + if (e == fe_init) + load_sheet(); else + if (e == se_query_modify) + { + TSheet_field& s = (TSheet_field&)o; + TToken_string& row = s.row(jolly); + const TRecnotype progr = row.get_long(0); + s.sheet_mask().enable(DLG_DELREC, progr >= MANUAL_ROW); + s.sheet_mask().enable(DLG_USER, progr < MANUAL_ROW); + } else + if (e == se_notify_modify) + { + set_dirty(true); + enable_buttons(); + } else + if (e == se_query_add) + { + if (!check_rows(false)) + return false; + } else + if (e == se_notify_add) + { + TSheet_field& s = (TSheet_field&)o; + TToken_string& row = s.row(jolly); + row.add(nuovo_progr(), s.cid2index(A_RIGA)); + } else + if (e == se_query_del) + { + TSheet_field& s = (TSheet_field&)o; + TToken_string& row = s.row(jolly); + const TRecnotype progr = row.get_long(0); + return progr >= MANUAL_ROW; + } + break; + case A_CODCF: + case A_OCFPI: + if (e == fe_modify || (e == fe_init && !o.empty())) + { + TMask& m = o.mask(); + const TAnagrafica anag(m.get(A_TIPOCF)[0], m.get_long(A_CODCF), m.get(A_OCFPI)); + m.set(A_RAGSOC, anag.ragione_sociale()); + m.set(A_PAIV, anag.partita_IVA()); + m.set(A_COFI, anag.codice_fiscale()); + } + break; + case DLG_USER: + if (e == fe_button || e == fe_init) + { + const long numreg = o.mask().get_long(A_RIGA); + const bool enab = (numreg > 0) && (numreg < MANUAL_ROW); + if (e == fe_button && enab) + { + o.disable(); // Tecnica anti doppio click! + TRectype mov(LF_MOV); + mov.put(MOV_NUMREG, numreg); + mov.edit(); + o.enable(); + } + else + o.enable(enab); + } + break; + default: + break; + } + + if (e == fe_modify && jolly == 1 && _mode == MODE_MOD) + { + const short id = o.dlg(); + if (id >= A_RIGA && id < A_COFI && id != A_FORZATA) + { + o.mask().set(A_FORZATA, true); + set_dirty(); + } + } + + return true; +} + +/////////////////////////////////////////////////////////// +// TSpesometro_app +/////////////////////////////////////////////////////////// + +class TSpesometro_app : public TSkeleton_application +{ +protected: + virtual bool create(); + +public: + virtual void main_loop(); +}; + +bool TSpesometro_app::create() +{ + if (!has_module(F3AUT)) + { + TString html; + html << "" + << "
Attenzione: Il modulo FE deve essere attivato in congiunzione a F3.
\n" + << "

Al fine di poter attivare l'utilizzo della Comunicazione Polivalente 2013 " + << "La preghiamo di contattare Sirio informatica e sistemi al seguente riferimento:


" + << "" + << ""; + return warning_box(html); + } + + // Controllo preventivo dell'avvenuta conversione del tracciato record + TRectype alleg(LF_ALLEG); + if (alleg.type(ALL_CARBURAN) == _nullfld) + return error_box(TR("Database non convertito per la Comunicazione Polivalente")); + + TLocalisamfile mov(LF_MOV); + if (mov.last() == NOERR) + { + const long numreg = mov.get_long(MOV_NUMREG); + while (numreg > MANUAL_ROW) + MANUAL_ROW *= 10; + } + + // Teoricamente è possibile visualizzare tutti i movimenti di un anno, per cui allargo il numero riga + TSheet_field::set_line_number_width(7); + + return TSkeleton_application::create(); +} + +void TSpesometro_app::main_loop() +{ + TSpesometro_msk msk; + msk.run(); +} + +/////////////////////////////////////////////////////////// +// main +/////////////////////////////////////////////////////////// + +int fe0100(int argc, char* argv[]) +{ + TSpesometro_app app; + app.run(argc, argv, TR("Comunicazione Polivalente")); + return 0; +} + diff --git a/fe/fe0100.rep b/fe/fe0100.rep index 6469755a7..ffe7adde8 100644 --- a/fe/fe0100.rep +++ b/fe/fe0100.rep @@ -2,9 +2,8 @@
- + - "Dati rilevanti " + ANNO + " tipo " + TIPO @@ -14,22 +13,18 @@ - + - - COFI - + - - + + - - - +
@@ -50,64 +45,47 @@ #RECORD.NUMBER - COFI + CodiceFiscale - PAIV + PartitaIVA - RAGSOC + RagSoc + Cognome+" "+Nome - - DATAREG + + DataReg - NUMDOC + NumDoc - - MODPAG - -
  • -
  • -
  • -
  • - + + Tipo - TIPOPE - -
  • -
  • -
  • - + Noleggio + +
  • +
  • +
  • +
  • +
  • +
  • + - - IMPORTO + + Imponibile - - IMPOSTA + + Imposta - - DATARETT + + StatoEstero + StatoEsteroSede - - NUMRETT - - - SIMPORTO - -
  • -
  • -
  • - - - - SIMPOSTA - -
  • -
  • -
  • - + + BlackList
  • diff --git a/fe/fe0100a.h b/fe/fe0100a.h index b4eabc7ae..5af457ecb 100755 --- a/fe/fe0100a.h +++ b/fe/fe0100a.h @@ -1,9 +1,7 @@ -#define F_ANNO 301 -#define F_DATA 302 -#define F_SHOWALL 303 -#define F_SENDALL 304 +#define F_TIPO 301 +#define F_ANNO 302 +#define F_PERIODO 303 #define F_OUTFOLDER 305 -#define F_MAXREC 306 #define F_DEFINITIVO 307 #define F_OUTFILE 308 @@ -14,33 +12,32 @@ #define F_RAGSOC 314 #define F_RAGOCC 315 -#define F_INTER_COM 320 -#define F_INTER_DATE 321 -#define F_INTER_COFI 322 -#define F_INTER_CAF 323 - -#define F_TIPOLOGIA 330 -#define F_PROTELE 331 -#define F_PROTDOC 332 - #define F_RIGHE 300 #define A_RIGA 101 #define A_FORZATA 102 #define A_IGNORA 103 -#define A_TIPOCF 104 -#define A_CODCF 105 -#define A_OCFPI 106 -#define A_RAGSOC 107 -#define A_DATAREG 108 -#define A_NUMDOC 109 -#define A_IMPORTO 110 -#define A_IMPOSTA 111 -#define A_MODPAG 112 -#define A_CONTRATTO 113 -#define A_DATARETT 114 -#define A_NUMRETT 115 -#define A_PAIV 116 -#define A_COFI 117 +#define A_TIPO 104 +#define A_TIPOCF 105 +#define A_CODCF 106 +#define A_OCFPI 107 +#define A_RAGSOC 108 +#define A_DATAREG 109 +#define A_NUMDOC 110 +#define A_DATADOC 111 +#define A_TIPOIVA 112 +#define A_IMPORTO 113 +#define A_IMPOSTA 114 +#define A_NOLEGGIO 115 +#define A_REVERSE 116 +#define A_AUTOFATT 117 +#define A_SERVIZI 118 +#define A_TURISMO 119 +#define A_CARBURAN 120 +#define A_RIEPILOG 121 +#define A_ATTAGG 122 +#define A_PASAGG 123 +#define A_PAIV 124 +#define A_COFI 125 #define A_OCCAS 155 diff --git a/fe/fe0100a.uml b/fe/fe0100a.uml index 1e7441549..8829f137f 100755 --- a/fe/fe0100a.uml +++ b/fe/fe0100a.uml @@ -1,502 +1,462 @@ -#include "fe0100a.h" - -TOOLBAR "topbar" 0 0 0 2 - -BUTTON DLG_OK 2 2 -BEGIN - PROMPT 1 1 "Aggiorna" - PICTURE TOOL_CONVERT -END - -BUTTON DLG_SAVEREC 2 2 -BEGIN - PROMPT 1 1 "Registra" - PICTURE TOOL_SAVEREC - FLAGS "D" -END - -BUTTON DLG_CANCEL 2 2, -BEGIN - PROMPT 1 2 "Annulla" -END - -BUTTON DLG_NULL 2 2 -BEGIN -END - -BUTTON DLG_RECALC 2 2 -BEGIN - PROMPT 1 3 "Ricalcola" - PICTURE TOOL_RECALC -END - -BUTTON DLG_COPY 2 2 -BEGIN - PROMPT 1 3 "+Contratto" - PICTURE TOOL_COPY -END - -BUTTON DLG_EXPORT 2 2 -BEGIN - PROMPT 1 4 "Excel" - PICTURE TOOL_EXCEL - MODULE rs -END - -BUTTON DLG_ELABORA 2 2 -BEGIN - PROMPT 1 5 "Invia" - PICTURE TOOL_EXPORT -END - -BUTTON DLG_DELREC 2 2 -BEGIN - PROMPT 1 6 "Azzera Invio" - PICTURE TOOL_RESET -END - -BUTTON DLG_PREVIEW 2 2 -BEGIN - PROMPT 1 7 "Anteprima" - PICTURE TOOL_PREVIEW -END - -#include - -ENDPAGE - -PAGE "Dati rilevanti" 0 2 0 0 - -GROUPBOX DLG_NULL 78 5 -BEGIN - PROMPT 1 0 "@bFiltri di visualizzazione" -END - -NUMBER F_ANNO 4 -BEGIN - PROMPT 2 1 "Anno " - CHECKTYPE REQUIRED - FLAGS "AU" - GROUP 1 - NUM_EXPR #THIS_FIELD>=2010 - WARNING "Anno non valido" -END - -DATE F_DATA -BEGIN - PROMPT 15 1 "Limite note variazione " - CHECKTYPE REQUIRED -END - -LIST F_SHOWALL 1 13 -BEGIN - PROMPT 52 1 "Movimenti " - ITEM "1|Rilevanti" - ITEM "2|NON rilevanti" - ITEM "4|Scartati" - ITEM "7|Tutti" - GROUP 1 -END - -LIST F_TIPOCF 1 10 -BEGIN - PROMPT 2 2 "" - ITEM "C|Cliente" - ITEM "F|Fornitore" - GROUP 1 -END - -NUMBER F_CODCF 6 -BEGIN - PROMPT 16 2 "" - USE LF_CLIFO - INPUT TIPOCF F_TIPOCF SELECT - INPUT CODCF F_CODCF - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Occasionale@C" OCCAS - DISPLAY "Codice Fiscale@16" COFI - DISPLAY "Partita IVA@15" PAIV - OUTPUT F_CODCF CODCF - OUTPUT F_RAGSOC RAGSOC - CHEKTYPE NORMAL - ADD RUN CG0 -1 - GROUP 1 -END - -STRING F_RAGSOC 50 49 -BEGIN - PROMPT 26 2 "" - USE LF_CLIFO KEY 2 - INPUT TIPOCF F_TIPOCF SELECT - INPUT RAGSOC F_RAGSOC - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Codice" CODCF - DISPLAY "Codice Fiscale@16" COFI - DISPLAY "Partita IVA@15" PAIV - COPY OUTPUT F_CODCF - ADD RUN CG0 -1 - GROUP 1 -END - -STRING F_OCFPI 16 -BEGIN - PROMPT 2 3 "Occ." - USE LF_OCCAS - INPUT CFPI F_OCFPI - DISPLAY "Codice@16" CFPI - DISPLAY "Ragione Sociale@50" RAGSOC - OUTPUT F_OCFPI CFPI - OUTPUT F_RAGOCC RAGSOC - CHEKTYPE NORMAL - ADD RUN cg0 -6 - GROUP 1 - MESSAGE EMPTY SHOW,F_RAGSOC|HIDE,F_RAGOCC - MESSAGE HIDE,F_RAGSOC|SHOW,F_RAGOCC -END - -STRING F_RAGOCC 50 49 -BEGIN - PROMPT 26 3 "" - FLAGS "H" - GROUP 1 -END - -SPREADSHEET F_RIGHE -BEGIN - PROMPT 0 5 "" - ITEM "Numero\nRegistraz.@7F" - ITEM "Forzata@C" - ITEM "Non\nInv.@2@F" - ITEM "C/F@2F" - ITEM "Codice@F" - ITEM "Occasionale@16F" - ITEM "Ragione Sociale@24" - ITEM "Data\nOperazione@10" - ITEM "Numero\nDocum.@7" - ITEM "Importo\ndovuto@12" - ITEM "Imposta@12" - ITEM "Mod.\nPag.@4" - ITEM "Contratto@18" - ITEM "Data Doc.\nrettif.@10" - ITEM "N. Doc.\nrettif.@7" - ITEM "Partita IVA@15" - ITEM "Codice Fiscale@17" - DEFAULT "*" // Impedisce il salvataggio su profilo .ini -END - -ENDPAGE - -PAGE "Opzioni" 0 2 0 0 - -GROUPBOX DLG_NULL 78 5 -BEGIN - PROMPT 1 1 "@bOpzioni per invio" -END - -LIST F_SENDALL 1 25 -BEGIN - PROMPT 2 2 "Movimenti " - ITEM "1|Rilevanti" - ITEM "7|Tutti" -END - -BOOLEAN F_DEFINITIVO -BEGIN - PROMPT 50 2 "Invio definitivo" -END - -STRING F_OUTFOLDER 255 50 -BEGIN - PROMPT 2 3 "Cartella " - DSELECT - CHECKTYPE REQUIRED - WARNING "Specificare una cartella di destinazione valida" -END - -NUMBER F_MAXREC 5 -BEGIN - PROMPT 2 4 "Numero massimo di record per file " - NUM_EXPR (#THIS_FIELD>=100)&&(#THIS_FIELD<=15000) - FLAGS "U" - CHECKTYPE REQUIRED - WARNING "Specificare una valore compreso tra 100 e 15000" -END - -GROUPBOX DLG_NULL 78 6 -BEGIN - PROMPT 1 6 "@bDati del soggetto che assume l'impegno alla presentazione telematica" -END - -LIST F_INTER_COM 1 20 -BEGIN - PROMPT 2 7 "Comunicazione predisposta da " - ITEM "|" - ITEM "1|contribuente" - ITEM "2|chi effettua l'invio" -END - -STRING F_INTER_COFI 16 -BEGIN - PROMPT 2 8 "Codice fiscale dell'intermediario " - FLAGS "U" -END - -NUMBER F_INTER_CAF 5 -BEGIN - PROMPT 2 9 "Numero iscrizione all'albo C.A.F. " -END - -DATE F_INTER_DATE -BEGIN - PROMPT 2 10 "Data dell'impegno alla trasmissione " -END - -GROUPBOX DLG_NULL 78 5 -BEGIN - PROMPT 1 12 "@bAnnullamento o sostituzione" -END - -LIST F_TIPOLOGIA 1 15 -BEGIN - PROMPT 2 13 "Tipologia invio " - ITEM "0|Normale" - MESSAGE DISABLE,F_PROTELE|DISABLE,F_PROTDOC - ITEM "1|Sostitutivo" - MESSAGE ENABLE,F_PROTELE|ENABLE,F_PROTDOC - ITEM "2|Annullamento" - MESSAGE ENABLE,F_PROTELE|ENABLE,F_PROTDOC -END - -STRING F_PROTELE 17 -BEGIN - PROMPT 2 14 "Protocollo da sostituire o annullare " - FLAGS "U" - CHECKTYPE REQUIRED -END - -STRING F_PROTDOC 6 -BEGIN - PROMPT 2 15 "Protocollo documento " - FLAGS "U" - CHECKTYPE REQUIRED -END - -ENDPAGE - -ENDMASK - -PAGE "Riga" -1 -1 69 11 - -NUMBER A_RIGA 7 -BEGIN - PROMPT 1 0 "Numero progressivo " - FLAGS "D" - FIELD PROGR -END - -BOOLEAN A_FORZATA -BEGIN - PROMPT 40 0 "Forzatura manuale" - FIELD FORZATURA -END - -LIST A_IGNORA 2 55 -BEGIN - PROMPT 1 1 "Non inv." - ITEM "| 0. Rilevante al fine della dichiarazione" - ITEM "1| 1. Importo inferiore al limite della comunicazione" - ITEM "2| 2. Soggetto da non inserire in allegato" - ITEM "3| 3. Soggetto residente in stato a fiscalità agevolata" - ITEM "4| 4. Soggetto residente all'estero" - ITEM "5| 5. Movimento intra" - ITEM "6| 6. Soggetto all'articolo 8 (del dpr 26-10-1972)" - ITEM "7| 7. Data movimento fuori dai limiti della comunicazione" - ITEM "8| 8. Passaggi interni" - ITEM "9| 9. Già inviato" - ITEM "10|10.Altri motivi" - FIELD IGNORA -END - -LIST A_TIPOCF 1 10 -BEGIN - PROMPT 1 2 "" - ITEM "C|Cliente" - ITEM "F|Fornitore" - FIELD TIPOCF -END - -NUMBER A_CODCF 6 -BEGIN - PROMPT 17 2 "" - USE LF_CLIFO - INPUT TIPOCF A_TIPOCF SELECT - INPUT CODCF A_CODCF - DISPLAY "Codice" CODCF - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Occasionale@C" OCCAS - DISPLAY "Partita IVA" PAIV - DISPLAY "Codice fiscale@16" COFI - OUTPUT A_CODCF CODCF - CHEKTYPE REQUIRED - ADD RUN cg0 -1 - FIELD CODCF - FLAGS "G" -END - -STRING A_OCFPI 16 -BEGIN - PROMPT 36 2 "Occasionale " - USE LF_OCCAS - INPUT CFPI A_OCFPI - DISPLAY "Codice@16" CFPI - DISPLAY "Ragione Sociale@50" RAGSOC - DISPLAY "Partita IVA" PAIV - DISPLAY "Codice fiscale@16" COFI - OUTPUT A_OCFPI CFPI - CHEKTYPE NORMAL - GROUP 3 - ADD RUN cg0 -6 - FIELD OCFPI - FLAGS "G" -END - -STRING A_RAGSOC 50 47 -BEGIN - PROMPT 1 3 "Ragione Sociale " - FLAGS "D" -END - -STRING A_PAIV 12 -BEGIN - PROMPT 1 4 "Partita IVA " - FLAGS "D" -END - -STRING A_COFI 16 -BEGIN - PROMPT 33 4 "Codice Fiscale " - FLAGS "D" -END - -DATE A_DATAREG -BEGIN - PROMPT 29 5 "Data " - USE LF_MOV KEY 3 - INPUT TIPO A_TIPOCF SELECT - INPUT CODCF A_CODCF SELECT - INPUT DATAREG A_DATAREG - DISPLAY "Data.Reg.@10" DATAREG - DISPLAY "Num.Reg.@7" NUMREG - DISPLAY "Descrizione@50" DESCR - DISPLAY "Data Doc.@10" DATADOC - DISPLAY "Num.Doc.@7" NUMDOC - OUTPUT A_DATAREG DATAREG - OUTPUT A_NUMDOC NUMDOC - FIELD DATAREG - VALIDATE NOT_EMPTY_FUNC -END - -STRING A_NUMDOC 7 -BEGIN - PROMPT 49 5 "Fattura " - FLAGS "U" - COPY ALL A_DATAREG - ADD RUN cg2 -0 - FIELD NUMDOC -END - -LIST A_MODPAG 1 20 -BEGIN - PROMPT 1 6 "Modalità di pagamento " - ITEM "1|1 - Non frazionato" - MESSAGE DISABLE,A_CONTRATTO|ENABLE,A_DATARETT|ENABLE,A_NUMRETT - ITEM "2|2 - Frazionato" - MESSAGE ENABLE,A_CONTRATTO|DISABLE,A_DATARETT|DISABLE,A_NUMRETT - ITEM "3|3 - Periodico" - MESSAGE ENABLE,A_CONTRATTO|DISABLE,A_DATARETT|DISABLE,A_NUMRETT - FIELD MODPAG -END - -STRING A_CONTRATTO 18 -BEGIN - PROMPT 1 7 "Contratto riferimento " - USE &CON - INPUT CODTAB[1,1] A_TIPOCF SELECT - INPUT CODTAB[2,7] A_CODCF SELECT - INPUT CODTAB[8,25] A_CONTRATTO - DISPLAY "Contratto@18" CODTAB[8,25] - DISPLAY "Descrizione@50" S0 - OUTPUT A_CONTRATTO CODTAB[8,25] - ADD RUN fe0 -1 &CON - CHEKCTYPE REQUIRED - FIELD CONTRATTO -END - -DATE A_DATARETT -BEGIN - PROMPT 1 8 "Documento rettificato " - FIELD DATARETT - USE LF_MOV KEY 3 - INPUT TIPO A_TIPOCF SELECT - INPUT CODCF A_CODCF SELECT - INPUT DATAREG A_DATARETT - COPY DISPLAY A_DATAREG - OUTPUT A_DATARETT DATAREG - OUTPUT A_NUMRETT NUMDOC - ADD RUN cg2 -0 - NUM_EXPR IF((#A_IMPORTO<0)&&(#A_IGNORA<=0);#A_DATARETT!="";1) - WARNING "Inserire la data della fattura rettificata" -END - -STRING A_NUMRETT 7 -BEGIN - PROMPT 50 8 "Numero " - FIELD NUMRETT - COPY ALL A_DATARETT - ADD RUN cg2 -0 - VALIDATE REQIF_FUNC 1 A_DATARETT - WARNING "Inserire il numero della fattura rettificata" -END - -CURRENCY A_IMPORTO 12 -BEGIN - PROMPT 1 10 "Importo dovuto " - FIELD IMPORTO -END - -CURRENCY A_IMPOSTA 12 -BEGIN - PROMPT 44 10 "Imposta " - FIELD IMPOSTA -END - -ENDPAGE - -TOOLBAR "topbar" 0 0 0 2 - -BUTTON DLG_OK 2 2 -BEGIN - PROMPT 1 1 "" -END - -BUTTON DLG_USER 2 2 -BEGIN - PROMPT 2 1 "Collega" - PICTURE TOOL_LINK -END - -BUTTON DLG_DELREC 2 2 -BEGIN - PROMPT 2 1 "Elimina" - PICTURE TOOL_DELREC -END - -BUTTON DLG_CANCEL 2 2 -BEGIN - PROMPT 4 1 "" -END - -ENDPAGE - -ENDMASK +#include "fe0100a.h" + +TOOLBAR "topbar" 0 0 0 2 + +BUTTON DLG_OK 2 2 +BEGIN + PROMPT 1 1 "Aggiorna" + PICTURE TOOL_CONVERT +END + +BUTTON DLG_SAVEREC 2 2 +BEGIN + PROMPT 1 1 "Registra" + PICTURE TOOL_SAVEREC + FLAGS "D" +END + +BUTTON DLG_CANCEL 2 2, +BEGIN + PROMPT 1 2 "Annulla" +END + +BUTTON DLG_NULL 2 2 +BEGIN +END + +BUTTON DLG_RECALC 2 2 +BEGIN + PROMPT 1 3 "Ricalcola" + PICTURE TOOL_RECALC +END + +BUTTON DLG_EXPORT 2 2 +BEGIN + PROMPT 1 4 "Excel" + PICTURE TOOL_EXCEL + MODULE rs +END + +BUTTON DLG_ELABORA 2 2 +BEGIN + PROMPT 1 5 "Invia" + PICTURE TOOL_EXPORT +END + +BUTTON DLG_DELREC 2 2 +BEGIN + PROMPT 1 6 "Azzera Invio" + PICTURE TOOL_RESET +END + +BUTTON DLG_PREVIEW 2 2 +BEGIN + PROMPT 1 7 "Anteprima" + PICTURE TOOL_PREVIEW +END + +#include + +ENDPAGE + +PAGE "Comunicazione Polivalente" 0 2 0 0 + +GROUPBOX DLG_NULL 78 6 +BEGIN + PROMPT 1 0 "@bFiltri di visualizzazione" +END + +NUMBER F_ANNO 4 +BEGIN + PROMPT 2 1 "Anno " + CHECKTYPE REQUIRED + FLAGS "AU" + GROUP 1 + NUM_EXPR #THIS_FIELD>=2012 + WARNING "Anno non valido" +END + +LIST F_TIPO 2 10 +BEGIN + PROMPT 21 1 "Tipo " + ITEM "FE|Spesometro" + MESSAGE HIDE,F_PERIODO + ITEM "BL|Black List" + MESSAGE SHOW,F_PERIODO + ITEM "XX|Ignorati" + MESSAGE HIDE,F_PERIODO + ITEM "IN|Inviati" + MESSAGE HIDE,F_PERIODO + ITEM "**|Tutti" + MESSAGE HIDE,F_PERIODO +END + +LIST F_PERIODO 2 16 +BEGIN + PROMPT 51 1 "Periodo " + ITEM "|Annuale" + ITEM "T1|I Trimestre" + ITEM "T2|II Trimestre" + ITEM "T3|III Trimestre" + ITEM "T4|IV Trimestre" + FLAGS "M" +END + +LIST F_TIPOCF 1 10 +BEGIN + PROMPT 2 2 "" + ITEM "C|Cliente" + ITEM "F|Fornitore" + GROUP 1 +END + +NUMBER F_CODCF 6 +BEGIN + PROMPT 16 2 "" + USE LF_CLIFO + INPUT TIPOCF F_TIPOCF SELECT + INPUT CODCF F_CODCF + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Occasionale@C" OCCAS + DISPLAY "Codice Fiscale@16" COFI + DISPLAY "Partita IVA@15" PAIV + OUTPUT F_CODCF CODCF + OUTPUT F_RAGSOC RAGSOC + CHEKTYPE NORMAL + ADD RUN CG0 -1 + GROUP 1 +END + +STRING F_RAGSOC 50 49 +BEGIN + PROMPT 26 2 "" + USE LF_CLIFO KEY 2 + INPUT TIPOCF F_TIPOCF SELECT + INPUT RAGSOC F_RAGSOC + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Codice" CODCF + DISPLAY "Codice Fiscale@16" COFI + DISPLAY "Partita IVA@15" PAIV + COPY OUTPUT F_CODCF + ADD RUN CG0 -1 + GROUP 1 +END + +STRING F_OCFPI 16 +BEGIN + PROMPT 2 3 "Occ." + USE LF_OCCAS + INPUT CFPI F_OCFPI + DISPLAY "Codice@16" CFPI + DISPLAY "Ragione Sociale@50" RAGSOC + OUTPUT F_OCFPI CFPI + OUTPUT F_RAGOCC RAGSOC + CHEKTYPE NORMAL + ADD RUN cg0 -6 + GROUP 1 + MESSAGE EMPTY SHOW,F_RAGSOC|HIDE,F_RAGOCC + MESSAGE HIDE,F_RAGSOC|SHOW,F_RAGOCC +END + +STRING F_RAGOCC 50 49 +BEGIN + PROMPT 26 3 "" + FLAGS "H" + GROUP 1 +END + +STRING F_OUTFOLDER 255 45 +BEGIN + PROMPT 2 4 "Cartella " + DSELECT + CHECKTYPE REQUIRED + FLAGS "M" + WARNING "Specificare una cartella di destinazione valida" +END + +BOOLEAN F_DEFINITIVO +BEGIN + PROMPT 65 4 "Definitivo" +END + +SPREADSHEET F_RIGHE +BEGIN + PROMPT 0 6 "" + ITEM "Numero\nRegistraz.@7F" + ITEM "Forzata@C" + ITEM "Ignora@5" + ITEM "Tipo@2@F" + ITEM "C/F@2F" + ITEM "Codice@F" + ITEM "Occasionale@16F" + ITEM "Ragione Sociale@32" + ITEM "Data\nOperazione@10" + ITEM "Numero\nDocum.@7" + ITEM "Data\nDocum.@10" + ITEM "Tipo\nIVA@4" + ITEM "Imponibile@12" + ITEM "Imposta@12" + ITEM "Noleggio@10" + ITEM "Rev.\nCharge@7" + ITEM "Auto\nfatt.@6" + ITEM "Servizi\nEsteri@6" + ITEM "Operaz.\nTurismo@6" + ITEM "Scheda\nCarbur.@6" + ITEM "Fatt.\nRiep.@6" + ITEM "Op. Att.\nAggreg.@6" + ITEM "Op. Pass.\nAggreg.@6" + ITEM "Partita IVA@15" + ITEM "Codice Fiscale@16" + DEFAULT "*" // Impedisce il salvataggio su profilo .ini +END + +ENDPAGE + +ENDMASK + +PAGE "Riga" -1 -1 69 14 + +NUMBER A_RIGA 7 +BEGIN + PROMPT 1 0 "Numero progressivo " + FLAGS "D" + FIELD PROGR +END + +BOOLEAN A_FORZATA +BEGIN + PROMPT 40 0 "Forzatura manuale" + FIELD FORZATURA +END + +LIST A_IGNORA 2 55 +BEGIN + PROMPT 1 1 "Ignora " + ITEM "|" + ITEM "1| 1. Importo non rilevante" + ITEM "2| 2. Soggetto da non inserire in allegato" + ITEM "3| 3. Residente in un paese della black list" + ITEM "4| 4. Soggetto residente all'estero" + ITEM "5| 5. Movimento intra" + ITEM "7| 7. Data movimento fuori dai limiti della comunicazione" + ITEM "9| 9. Già inviato" + ITEM "10|10.Altri motivi" + FIELD IGNORA +END + +STRING A_TIPO 2 +BEGIN + PROMPT 1 2 "Tipo " + FIELD TIPOPE + FLAGS "U" + STR_EXPR LEN(#THIS_FIELD)==2 + WARNING "Tipo record di lunghezza errata" + CHECKTYPE REQUIRED +END + +LIST A_TIPOCF 1 10 +BEGIN + PROMPT 1 3 "" + ITEM "C|Cliente" + ITEM "F|Fornitore" + FIELD TIPOCF +END + +NUMBER A_CODCF 6 +BEGIN + PROMPT 17 3 "" + USE LF_CLIFO + INPUT TIPOCF A_TIPOCF SELECT + INPUT CODCF A_CODCF + DISPLAY "Codice" CODCF + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Occasionale@C" OCCAS + DISPLAY "Partita IVA" PAIV + DISPLAY "Codice fiscale@16" COFI + OUTPUT A_CODCF CODCF + CHEKTYPE REQUIRED + ADD RUN cg0 -1 + FIELD CODCF + FLAGS "G" +END + +STRING A_OCFPI 16 +BEGIN + PROMPT 36 3 "Occasionale " + USE LF_OCCAS + INPUT CFPI A_OCFPI + DISPLAY "Codice@16" CFPI + DISPLAY "Ragione Sociale@50" RAGSOC + DISPLAY "Partita IVA" PAIV + DISPLAY "Codice fiscale@16" COFI + OUTPUT A_OCFPI CFPI + CHEKTYPE NORMAL + GROUP 3 + ADD RUN cg0 -6 + FIELD OCFPI + FLAGS "G" +END + +STRING A_RAGSOC 50 47 +BEGIN + PROMPT 1 4 "Ragione Sociale " + FLAGS "D" +END + +STRING A_PAIV 12 +BEGIN + PROMPT 1 5 "Partita IVA " + FLAGS "D" +END + +STRING A_COFI 16 +BEGIN + PROMPT 33 5 "Codice Fiscale " + FLAGS "D" +END + +DATE A_DATAREG +BEGIN + PROMPT 1 6 "Data reg. " + USE LF_MOV KEY 3 + INPUT TIPO A_TIPOCF SELECT + INPUT CODCF A_CODCF SELECT + INPUT DATAREG A_DATAREG + DISPLAY "Data.Reg.@10" DATAREG + DISPLAY "Num.Reg.@7" NUMREG + DISPLAY "Descrizione@50" DESCR + DISPLAY "Data Doc.@10" DATADOC + DISPLAY "Num.Doc.@7" NUMDOC + OUTPUT A_DATAREG DATAREG + OUTPUT A_NUMDOC NUMDOC + OUTPUT A_DATADOC DATADOC + FIELD DATAREG + VALIDATE NOT_EMPTY_FUNC +END + +DATE A_DATADOC +BEGIN + PROMPT 27 6 "Data doc. " + FIELD DATADOC +END + +STRING A_NUMDOC 7 +BEGIN + PROMPT 49 6 "Num. doc. " + FLAGS "U" + FIELD NUMDOC +END + +LIST A_NOLEGGIO 1 12 +BEGIN + PROMPT 1 7 "Noleggio " + ITEM " |Nessuno" + ITEM "A|Automobile" + ITEM "B|Camper" + ITEM "C|Altro" + ITEM "D|Diporto" + ITEM "E|Aeromobile" + FIELD NOLEGGIO +END + +LIST A_TIPOIVA 1 24 +BEGIN + PROMPT 27 7 "Tipo IVA " + ITEM "1|Imponibile" + ITEM "2|Non imponibile" + ITEM "3|Esente" + ITEM "4|Non esposta in fattura" + ITEM "5|Margine" + FIELD TIPOIVA +END + +CURRENCY A_IMPORTO 12 +BEGIN + PROMPT 1 8 "Imponibile " + FIELD IMPORTO +END + +CURRENCY A_IMPOSTA 12 +BEGIN + PROMPT 44 8 "Imposta " + FIELD IMPOSTA +END + +BOOLEAN A_REVERSE +BEGIN + PROMPT 1 9 "Reverse charge" + FIELD REVERSE +END + +BOOLEAN A_AUTOFATT +BEGIN + PROMPT 38 9 "Autofattura" + FIELD AUTOFATT +END + +BOOLEAN A_SERVIZI +BEGIN + PROMPT 1 10 "Acquisto servizi all'estero" + FIELD SERVIZI +END + +BOOLEAN A_TURISMO +BEGIN + PROMPT 38 10 "Operazioni turismo" + FIELD TURISMO +END + +BOOLEAN A_CARBURAN +BEGIN + PROMPT 1 11 "Scheda carburanti" + FIELD CARBURAN +END + +BOOLEAN A_RIEPILOG +BEGIN + PROMPT 38 11 "Fattura riepilogativa" + FIELD RIEPILOG +END + +NUMBER A_ATTAGG 4 +BEGIN + PROMPT 1 12 "Operazioni aggregate: Attive " + FIELD ATTAGG +END + +NUMBER A_PASAGG 4 +BEGIN + PROMPT 44 12 "Passive " + FIELD PASAGG +END + +ENDPAGE + +TOOLBAR "topbar" 0 0 0 2 + +BUTTON DLG_OK 2 2 +BEGIN + PROMPT 1 1 "" +END + +BUTTON DLG_USER 2 2 +BEGIN + PROMPT 2 1 "Collega" + PICTURE TOOL_LINK +END + +BUTTON DLG_DELREC 2 2 +BEGIN + PROMPT 2 1 "Elimina" + PICTURE TOOL_DELREC +END + +BUTTON DLG_CANCEL 2 2 +BEGIN + PROMPT 4 1 "" +END + +ENDPAGE + +ENDMASK diff --git a/fe/fe0200.cpp b/fe/fe0200.cpp index 633b9d178..63b2caa02 100755 --- a/fe/fe0200.cpp +++ b/fe/fe0200.cpp @@ -141,6 +141,6 @@ TMask* TFE_table_app::user_create_mask() int fe0200(int argc, char* argv[]) { TFE_table_app a; - a.run(argc, argv, TR("Tabella modulo dati rilevanti")); + a.run(argc, argv, TR("Tabella Spesometro")); return 0; } diff --git a/fe/fe0300.cpp b/fe/fe0300.cpp index db99be503..3cefe5835 100644 --- a/fe/fe0300.cpp +++ b/fe/fe0300.cpp @@ -16,7 +16,6 @@ protected: void elabora(const TString_array& a, const TFilename& n) const; bool str2fname(const TString& name, TFilename& n) const; - bool row2fname(const TToken_string& row, TFilename& n) const; void enable_buttons(); public: @@ -40,59 +39,6 @@ bool TSomma_spesometro_msk::str2fname(const TString& name, TFilename& n) const return n.exist(); } -bool TSomma_spesometro_msk::row2fname(const TToken_string& row, TFilename& n) const -{ - TString80 name; row.get(0, name); - return str2fname(name, n); -} - -void TSomma_spesometro_msk::elabora(const TString_array& infiles, const TFilename& outfile) const -{ - int anno = 2010; - - TFilename n; - if (row2fname(infiles.row(0), n)) - { - const TDati_rilevanti_set s(n); - anno = s.anno(); - } - - TDati_rilevanti_set outset(anno); - const int tipologia = outset.add_header(*this); - - if (tipologia != 2) // Invio i record solo quando non si tratta di annullamento - { - FOR_EACH_ARRAY_ROW(infiles, r, row) if (row2fname(*row, n)) - { - const int len = outset.record_length(); - ifstream s(n, ios::binary); - TString row(len); - while (!s.eof()) - { - s.read(row.get_buffer(), len); - if (row[0] != '0' && row[0] != '9') - outset.new_rec(row); - } - } - } - - outset.add_footer(); - outset.sort(); - outset.save_as(outfile); - - if (outset.items() > 15000) - { - outset.split(outfile); - const int n = (outset.items()-1) / 15000 + 1; - warning_box(FR("E' stato generato il file %s, separato in %d parti da 15000 record."), (const char*)outfile, n); - } - else - message_box(FR("E' stato generato il file %s"), (const char*)outfile); - - TDati_rilevanti_rep rep(outfile); - rep.preview(); -} - void TSomma_spesometro_msk::enable_buttons() { const TSheet_field& righe = sfield(F_RIGHE); @@ -102,6 +48,11 @@ void TSomma_spesometro_msk::enable_buttons() enable(DLG_PREVIEW, str2fname(get(F_OUTFILE), n)); } +void TSomma_spesometro_msk::elabora(const TString_array& a, const TFilename& n) const +{ +} + + bool TSomma_spesometro_msk::on_field_event(TOperable_field& o, TField_event e, long jolly) { switch (o.dlg()) @@ -126,7 +77,7 @@ bool TSomma_spesometro_msk::on_field_event(TOperable_field& o, TField_event e, l TFilename fn; if (str2fname(o.mask().get(101), fn)) { - TDati_rilevanti_rep rep(fn); + TSpesometro_rep rep(fn); rep.preview(); } } @@ -137,7 +88,7 @@ bool TSomma_spesometro_msk::on_field_event(TOperable_field& o, TField_event e, l TFilename fn; if (str2fname(get(F_OUTFILE), fn)) { - TDati_rilevanti_rep rep(fn); + TSpesometro_rep rep(fn); rep.preview(); } } @@ -167,21 +118,6 @@ bool TSomma_spesometro_msk::on_field_event(TOperable_field& o, TField_event e, l } } - // Elimina dalla lista il file di output - if (str2fname(get(F_OUTFILE), fn)) - { - TFilename fr; - FOR_EACH_ARRAY_ROW(a, r, row) - { - row2fname(*row, fr); - if (fr.compare(fn, -1, true) == 0) - { - a.destroy(r, true); - break; - } - } - } - righe.force_update(); enable_buttons(); } diff --git a/fe/fe0400.cpp b/fe/fe0400.cpp index 84cab8c73..9e57f73c2 100644 --- a/fe/fe0400.cpp +++ b/fe/fe0400.cpp @@ -141,42 +141,6 @@ bool TTest_spesometro_msk::elabora(int num, TLog_report& log) { if (!pi.addstatus(1)) break; - const int tipopag = curr.get_int(MOV_MODPAG); - const TString& contratto = curr.get(MOV_CONTRATTO); - if (contratto.full()) - { - if (is_nota_variazione(curr)) - { - curr.put(MOV_MODPAG, 1); - curr.zero(MOV_CONTRATTO); - done = update_file(file, TR("Azzerato contratto su nota di variazione"), log); - } - else - { - const TContratto c(curr); - const int t = c.modalita_pagamento(); - if (t != tipopag) - { - str.cut(0) << TR("Cambiata modalità di pagamento ") << tipopag << " -> " << t; - curr.put(MOV_MODPAG, t); - if (num == LF_MOV) - { - curr.zero(MOV_DATARETT); - curr.zero(MOV_NUMRETT); - } - done = update_file(file, str, log); - } - } - } - else - { - if (tipopag > 1) - { - log_msg(curr, str, log); - curr.put(MOV_MODPAG, 1); - done = update_file(file, TR("Forzato pagamento non frazionato in assenza di contratto"), log); - } - } } return done; } diff --git a/fe/felib.cpp b/fe/felib.cpp index 495c21e23..d3192173d 100644 --- a/fe/felib.cpp +++ b/fe/felib.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -24,9 +25,6 @@ // Utility /////////////////////////////////////////////////////////// -real fe_importo_limite(int anno) -{ return anno > 2010 ? 3000.0 : 25000.0; } - bool fe_is_nota_variazione(const TRectype& mov) { const int logicnum = mov.num(); @@ -50,11 +48,9 @@ bool fe_is_nota_variazione(const TRectype& mov) } else if (logicnum == LF_ALLEG) { - if (mov.get_int(ALL_MODPAG) > 1) - return false; - - if (mov.get(ALL_NUMRETT).full() || mov.get(ALL_DATARETT).full()) - return true; + const TString& tipo = mov.get(ALL_TIPOPE); + if (tipo.len() == 2) + return tipo == "NE" || tipo == "NR"; const real importo = mov.get_real(ALL_IMPORTO); const real imposta = mov.get_real(ALL_IMPOSTA); @@ -101,41 +97,54 @@ bool fe_is_nota_variazione(const TRectype& mov) // TAnagrafica /////////////////////////////////////////////////////////// -static const TString& comune_di(const TString& codcom) +static const TString& comune_di(const TString& codcom, int stato) { if (codcom.blank() || codcom.len() != 4) return EMPTY_STRING; - TString8 key; key << " |" << codcom; - TString& den = get_tmp_string(); - den = cache().get(LF_COMUNI, key, COM_DENCOM); - den.cut(40); - den.trim(); - return den; + TString8 key; + if (stato > 0) + key.format("%03d", stato); + key << '|' << codcom; + return cache().get(LF_COMUNI, key, COM_DENCOM); } static const TString& provincia_di(const TString& codcom) { if (codcom.blank() || codcom.len() != 4) return EMPTY_STRING; - TString8 key; key << '|' << codcom; TString& prov = get_tmp_string(); - prov = cache().get(LF_COMUNI, key, COM_PROVCOM); - if (prov.len() > 2) prov = "RM"; + if (codcom.starts_with("Z")) + prov == "EE"; + else + { + TString8 key; key << '|' << codcom; + prov = cache().get(LF_COMUNI, key, COM_PROVCOM); + if (prov.len() > 2) prov = "RM"; + } return prov; } const TString& TAnagrafica::comune_nascita() const -{ return comune_di(_com_nasc); } +{ return comune_di(_com_nasc, 0); } const TString& TAnagrafica::provincia_nascita() const { return provincia_di(_com_nasc); } const TString& TAnagrafica::comune_residenza() const -{ return comune_di(_com_res); } +{ + const TString& cr = comune_di(_com_res, _stato_estero); + if (cr.full()) + return cr; + return _loc_res; +} const TString& TAnagrafica::provincia_residenza() const -{ return provincia_di(_com_res); } +{ + if (estero()) + return get_tmp_string() = "EE"; + return provincia_di(_com_res); +} void TAnagrafica::build_ind_res(const TRectype& rec, const char* ind, const char* civ) { @@ -151,12 +160,24 @@ void TAnagrafica::build_ind_res(const TRectype& rec, const char* ind, const char } } +const TString& TAnagrafica::cognome() const +{ + TString80 c = _ragsoc.left(30); + return get_tmp_string() = c.trim(); +} + +const TString& TAnagrafica::nome() const +{ + CHECK(fisica(), "Non chiedere nome giuridico!"); + return _ragsoc.mid(30,20); +} + bool TAnagrafica::italiano() const -{ return _stato_estero <= 0; } +{ return _stato_estero == 0; } const TString& TAnagrafica::stato_estero_UNICO() const { - if (italiano()) + if (_stato_estero <= 0) return EMPTY_STRING; TString4 u; u.format("%03d", _stato_estero); @@ -166,6 +187,22 @@ const TString& TAnagrafica::stato_estero_UNICO() const return get_tmp_string() = u; } +char TAnagrafica::is_black_list() const +{ + char is_black = ' '; + if (_stato_estero > 0) + { + TString4 u; u.format("%03d", _stato_estero); + const TRectype& sta = cache().get("%STA", u); + + if (sta.get_bool("B1")) // San Marino + is_black = 'M'; else + if (sta.get_bool("B0")) // Black List + is_black = 'S'; + } + return is_black; +} + void TAnagrafica::split_ragsoc() { if (_tipo == 'F') @@ -173,7 +210,7 @@ void TAnagrafica::split_ragsoc() if (nome().blank()) { const int space = _ragsoc.find(' '); - if (space > 0) + if (space >= 4) { TString80 nom = _ragsoc.mid(space+1); nom.cut(20); @@ -191,6 +228,7 @@ bool TAnagrafica::init(const TRectype& rec) _tipo = '\0'; _stato_estero = 0; _allegato = 0; + _ragsoc.cut(0); if (rec.empty()) return false; @@ -300,24 +338,42 @@ bool TAnagrafica::init(const TRectype& rec) if (rec.get(CLI_PAIV).not_empty()) _paiv = rec.get(CLI_PAIV); - // Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota! - // I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente. - if (_paiv.blank() && pi_check("", _cofi) && _cofi[0] < '8') - _paiv = _cofi; + if (_allegato != 5 && _allegato != 9) + { + const TString4 stato_paiv = rec.get(CLI_STATOPAIV); + if (stato_paiv.blank() || stato_paiv == "IT") + { + // Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota! + // I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente. + if (_paiv.blank() && pi_check(stato_paiv, _cofi) && _cofi[0] < '8') + _paiv = _cofi; + if (_paiv.len() == 11 && pi_check(stato_paiv, _paiv) && (_paiv[0] == '8' || _paiv[0] == '9')) + { + if (_cofi.blank()) + _cofi = _paiv; + _paiv.cut(0); + } + } + } build_ind_res(rec, CLI_INDCF, CLI_CIVCF); // Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione". _ragsoc = rec.get(CLI_RAGSOC); - _stato_estero = rec.get_int(CLI_STATOCF); _loc_res = rec.get(CLI_LOCCF); + _stato_estero = rec.get_int(CLI_STATOCF); + if (_stato_estero <= 0 && (_allegato == 5 || _allegato == 9)) // Estero CEE o extra-CEE + _stato_estero = -1; // Stato estero ignoto + _com_res = rec.get(CLI_COMCF); + if (_tipo != 'F' && _tipo != 'G') { switch (_allegato) { - case 6: _tipo = 'F'; break; - case 7: _tipo = 'G'; break; + case 6: _tipo = 'F'; break; // Privato + case 7: _tipo = 'G'; break; // Ente pubblico + case 8: _tipo = 'G'; break; // Fallimento default: if (_com_nasc.full()) _tipo = 'F'; @@ -352,7 +408,7 @@ bool TAnagrafica::init(int num, long codice) bool TAnagrafica::init(int num, char tipo, long codice) { - TString16 key; key << tipo << '|' << codice; + TString8 key; key.format("%c|%ld", tipo, codice); return init(cache().get(num, key)); } @@ -371,388 +427,63 @@ bool TAnagrafica::init(char tipocf, long codice, const TString& ocfpi) } /////////////////////////////////////////////////////////// -// TContratto +// TSpesometro_set /////////////////////////////////////////////////////////// -bool TContratto::importo_annuale(int anno, real& importo, real& imposta) const +const TVariant& TSpesometro_set::get(unsigned int column) const { - if (_rec.empty() || anno < 2010) - return false; - - // Determina l'indice i [0..3] degli importi del contratto per l'anno richiesto - char fld[] = "I3"; - int i = 3; - for (i = 3; i > 0; i--) + const TRecordset_column_info& info = column_info(column); + if (info._type == _realfld || info._type == _datefld) { - fld[1] = '0'+i; - const int y = _rec.get_int(fld); - if (y > 0 && y <= anno) - break; - } - - // Determina il nome del campo importo corrispondente all'indice i: 0 -> R0; 1 -> R2; 2 -> R4; 3 -> R6 - fld[0] = 'R'; - fld[1] = '0'+(i*2); - importo = _rec.get_real(fld); - - fld[1]++; // Il campo imposta è sempre quello successivo a quello dell'importo - imposta = _rec.get_real(fld); - - return importo > ZERO; -} - -bool TContratto::importo_figli(int anno, real& importo, real& imposta) const -{ - const TString& codtab = _rec.get("CODTAB"); - const TString& prefix = codtab.left(7); - const TString& suffix = codtab.mid(7); - - TString query; - query << "USE &CON SELECT S1=\"" << suffix << '\"' - << "\nFROM CODTAB=\"" << prefix << '\"' - << "\nTO CODTAB=\"" << prefix << '\"'; - - TISAM_recordset recset(query); - - importo = imposta = ZERO; - for (bool ok = recset.move_first(); ok; ok = recset.move_next()) - { - const TContratto child(recset.cursor()->curr()); - real imp, iva; child.importo_figli(anno, imp, iva); - importo += imp; - imposta += iva; - } - if (importo <= ZERO) - importo_annuale(anno, importo, imposta); - - return !importo.is_zero(); -} - -bool TContratto::totale_annuale(int anno, real& importo, real& imposta) const -{ - importo = imposta = ZERO; - if (!_rec.empty() && anno >= 2010) - { - const TString& padre = _rec.get("S1"); - if (padre.full()) + TString80 val = row().get(column); + TVariant& var = get_tmp_var(); + if (info._type == _realfld) { - const TString& codtab = _rec.get("CODTAB"); - const TContratto master(codtab[0], atol(codtab.mid(1,6)), padre); - master.totale_annuale(anno, importo, imposta); + val.replace(',', '.'); + var = real(val); } else - importo_figli(anno, importo, imposta); - } - return importo > ZERO; -} - -int TContratto::modalita_pagamento() const -{ - int modpag = _rec.get_int("S6"); - if (modpag != 2 && modpag != 3) - modpag = 2; - return modpag; -} - -const TString& TContratto::codice_base() const -{ - TString80 c = codice(), p = codice_padre(); - if (p.full()) - { - TAssoc_array antiloop; - antiloop.add(c); - while (p.full() && !antiloop.is_key(p)) // Verifico loop assurdo { - c = p; - antiloop.add(c); - TString80 key = chiave().left(7); - key << p; - p = cache().get("&CON", key, "S1"); - } - } - return get_tmp_string() = c; -} - -bool TContratto::init(const TString& codtab) -{ return init(cache().get("&CON", codtab)); } - -bool TContratto::init(char tipocf, long codcf, const TString& codcont) -{ - if (tipocf >= 'C' && codcf > 0 && codcont.full()) - { - TString80 key; key.format("%c%6ld%s", tipocf, codcf, (const char*)codcont); - return init(key); - } - else - _rec.zero(); - return false; -} - -bool TContratto::init(const TRectype& rec) -{ - switch (rec.num()) - { - case LF_TABMOD: - _rec = rec; - if (!_rec.empty()) - { - int primo_anno = _rec.get_int("I0"); - if (primo_anno < 2010) + if (val.len() == 8) { - const TDate inizio = _rec.get("D0"); - primo_anno = inizio.year(); - if (primo_anno < 2010) - primo_anno = 2010; - _rec.put("I0", primo_anno); + val.insert("-", 2); + val.insert("-", 5); } - - real importo = _rec.get("R0"); - if (importo <= ZERO) - { - importo = fe_importo_limite(primo_anno); - _rec.put("R0", importo); - } - } - break; - case LF_ALLEG: - { - const char tipocf = rec.get_char(ALL_TIPOCF); - const long codcf = rec.get_long(ALL_CODCF); - const TString& contr = rec.get(ALL_CONTRATTO); - init(tipocf, codcf, contr); + var = TDate(val); } - break; - case LF_MOV: - { - const char tipocf = rec.get_char(MOV_TIPO); - const long codcf = rec.get_long(MOV_CODCF); - const TString& contr = rec.get(MOV_CONTRATTO); - init(tipocf, codcf, contr); - } - break; - case LF_DOC: - { - const char tipocf = rec.get_char(DOC_TIPOCF); - const long codcf = rec.get_long(DOC_CODCF); - const TString& contr = rec.get(DOC_CONTRATTO); - init(tipocf, codcf, contr); - } - break; - default: - CHECKD(false, "Record non valido per contratto FE", rec.num()); - break; + return var; } - return ok(); + return TCSV_recordset::get(column); } -/////////////////////////////////////////////////////////// -// TDati_rilevanti_trc -/////////////////////////////////////////////////////////// - -#define AN _alfafld -#define CF _alfafld -#define DT _datefld -#define NU _longzerofld -#define PI _alfafld -#define OBBLIG true - -class TDati_rilevanti_trc : public TObject +bool TSpesometro_set::set(unsigned int fld, const TVariant& var) { - int _tipo; - TAS400_recordset* _recset; + const TRecordset_column_info& fi = column_info(fld); -protected: - bool add_field(int n, int da, int a, int len, const char* descr, TFieldtypes tipo = AN, - const char* def = NULL, bool required = false); -public: - void create_fields(int tipo, TAS400_recordset& recset); -}; - - -bool TDati_rilevanti_trc::add_field(int n, int da, int a, int len, const char* descr, TFieldtypes tipo, - const char* def, bool required) -{ - CHECKD(descr && *descr, "Campo ignoto ", n); - CHECKS(n > 0 && da > 0 && a >= da && a <= 1800 && len == (a-da+1), "Campo inconsistente ", descr); - TString8 name; - name.format("%d.%d", _tipo, n); - bool ok = _recset->create_field(name, da-1, len, tipo, required, def); - CHECKS(ok, "Can't create field ", descr); - return ok; -} - -void TDati_rilevanti_trc::create_fields(int tipo, TAS400_recordset& recset) -{ - CHECKD(tipo >= 0 && tipo <= 5 || tipo == 9, "Tipo record non valido ", tipo); - _tipo = tipo; - _recset = &recset; - - TString4 def; def << _tipo; - add_field(1, 1, 1, 1, "Tipo record", NU, def, OBBLIG); - - if (_tipo == 0 || _tipo == 9) - { - add_field( 2, 2, 6, 5, "Codice identificativo fornitura", AN, "ART21", OBBLIG); - add_field( 3, 7, 8, 2, "Codice numerico fornitura", NU, "47", OBBLIG); - add_field( 4, 9, 9, 1, "Tipologia di invio", NU, "0", OBBLIG); - add_field( 5, 10, 26,17, "Protocollo da sostituire", AN); // ex NU - add_field( 6, 27, 32, 6, "Protocollo documento", AN); // ex NU - - add_field( 7, 33, 48,16, "Codice fiscale", CF, "", OBBLIG); - add_field( 8, 49, 59,11, "Partita IVA", PI); - - add_field( 9, 60,119,60, "Denominazione", AN); - add_field(10,120,159,40, "Comune domicilio fiscale", AN); - add_field(11,160,161, 2, "Provincia domicilio fiscale", AN); - - add_field(12,162,185,24, "Cognome", AN); - add_field(13,186,205,20, "Nome", AN); - add_field(14,206,206, 1, "Sesso", AN); - add_field(15,207,214, 8, "Data di nascita", DT); - add_field(16,215,254,40, "Comune o stato di nascita", AN); - add_field(17,255,256, 2, "Provincia di nascita", AN); - - add_field(18,257,260, 4, "Anno di riferimento", NU); - add_field(19,261,261, 1, "Comunicazione società incorp.", AN, "0", OBBLIG); - add_field(20,262,265, 4, "Progressivo invio telmatico", NU, "1"); - add_field(21,266,269, 4, "Numero totale invii telematici", NU, "1"); - - add_field(22,270,285,16, "Codice fiscale intermediario", CF); - add_field(23,286,290, 5, "Numero iscrizione C.A.F.", AN); // Ex NU - add_field(24,291,291, 1, "Impegno alla trasmissione", AN ); // Ex NU - add_field(25,292,299, 8, "Data dell'impegno", DT); - - add_field(26,300,1797,1498, "Filler", AN); - add_field(27,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG); - add_field(28,1799,1800,2,"Caratteri di fine riga", AN, "\r\n"); - } else - if (_tipo == 1) - { - add_field(2, 2,17,16, "Codice fiscale", CF, "", OBBLIG); - add_field(3,18,25, 8, "Data dell'operazione", DT); - add_field(4,26,26, 1, "Modalità di pagamento", NU, "3", OBBLIG); - add_field(5,27,35, 9, "Importo dovuto", NU); - add_field(6,36,1797,1762, "Filler", AN); - add_field(7,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG); - add_field(8,1799,1800,2,"Caratteri di fine riga", AN, "\r\n"); - } else - if (_tipo == 2) - { - add_field( 2, 2,12,11, "Partita IVA", PI, "", OBBLIG); - add_field( 3,13,20, 8, "Data dell'operazione", DT); - add_field( 4,21,35,15, "Numero della fattura", AN); - add_field( 5,36,36, 1, "Modalità di pagamento", NU, "1", OBBLIG); - add_field( 6,37,45, 9, "Importo dovuto", NU); - add_field( 7,46,54, 9, "Imposta", NU); - add_field( 8,55,55, 1, "Tipologia dell'operazione", NU, "1", OBBLIG); - - add_field( 9,56,1797,1742, "Filler", AN); - add_field(10,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG); - add_field(11,1799,1800,2,"Caratteri di fine riga", AN, "\r\n"); - } else - if (_tipo == 3) - { - add_field( 2, 2, 25,24, "Cognome", AN); - add_field( 3, 26, 45,20, "Nome", AN); - add_field( 4, 46, 53, 8, "Data di nascita", DT); - add_field( 5, 54, 93,40, "Comune o stato estero di nascita", AN); - add_field( 6, 94, 95, 2, "Provincia di nascita", AN); - add_field( 7, 96, 98, 3, "Stato estero del domicilio", AN); - - add_field( 8, 99,158,60, "Ragione sociale", AN); - add_field( 9,159,198,40, "Città estera della sede legale", AN); - add_field(10,199,201, 3, "Stato estero della sede legale", AN); - add_field(11,202,241,40, "Indirizzo estero della sede legale", AN); - - add_field(12,242,249, 8, "Data dell'operazione", DT); - add_field(13,250,264,15, "Numero della fattura", AN); - add_field(14,265,265, 1, "Modalità di pagamento", NU, "1", OBBLIG); - add_field(15,266,274, 9, "Importo dovuto", NU); - add_field(16,275,283, 9, "Imposta", NU); - add_field(17,284,284, 1, "Tipologia dell'operazione", NU, "1", OBBLIG); - - add_field(18,285,1797,1513, "Filler", AN); - add_field(19,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG); - add_field(20,1799,1800,2,"Caratteri di fine riga", AN, "\r\n"); - } else - if (_tipo == 4) - { - add_field( 2, 2,12,11, "Partita IVA", PI); - add_field( 3,13,28,16, "Codice Fiscale", CF); - add_field( 4,29,36, 8, "Data dell'operazione", DT, "", OBBLIG); - add_field( 5,37,51,15, "Numero della Nota di Variazione", AN, "", OBBLIG); - add_field( 6,52,60, 9, "Imponibile Nota di Variazione", NU); - add_field( 7,61,69, 9, "Imposta Nota di Variazione", NU); - add_field( 8,70,77, 8, "Data della Fattura da rettificare", DT, "", OBBLIG); - add_field( 9,78,92,15, "Numero della Fattura da rettificare", AN, "", OBBLIG); - add_field(10,93,93, 1, "Variazione imponib. (Debito/Credito)",AN); - add_field(11,94,94, 1, "Variazione imposta (Debito/Credito)", AN); - - add_field(11,95,1797,1703, "Filler", AN); - add_field(12,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG); - add_field(13,1799,1800,2,"Caratteri di fine riga", AN, "\r\n"); - } else - if (_tipo == 5) - { - add_field( 2, 2, 25,24, "Cognome", AN); - add_field( 3, 26, 45,20, "Nome", AN); - add_field( 4, 46, 53, 8, "Data di nascita", DT); - add_field( 5, 54, 93,40, "Comune o stato estero di nascita", AN); - add_field( 6, 94, 95, 2, "Provincia di nascita", AN); - add_field( 7, 96, 98, 3, "Stato estero del domicilio", AN); - add_field( 8, 99,158,60, "Ragione sociale", AN); - add_field( 9,159,198,40, "Città estera della sede legale", AN); - add_field(10,199,201, 3, "Stato estero della sede legale", AN); - add_field(11,202,241,40, "Indirizzo estero della sede legale", AN); - add_field(12,242,249, 8, "Data dell'operazione", DT, "", OBBLIG); - add_field(13,250,264,15, "Numero della Nota di Variazione", AN, "", OBBLIG); - add_field(14,265,273, 9, "Imponibile Nota di Variazione", NU); - add_field(15,274,282, 9, "Imposta Nota di Variazione", NU); - add_field(16,283,290, 8, "Data della Fattura da rettificare", DT, "", OBBLIG); - add_field(17,291,305,15, "Numero della Fattura da rettificare", AN, "", OBBLIG); - add_field(18,306,306, 1, "Variazione imponib. (Debito/Credito)",AN); - add_field(19,307,307, 1, "Variazione imposta (Debito/Credito)", AN); - - add_field(20,308,1797,1490, "Filler", AN); - add_field(21,1798,1798,1,"Carattere di controllo", AN, "A", OBBLIG); - add_field(22,1799,1800,2,"Caratteri di fine riga", AN, "\r\n"); - } - - _recset = NULL; -} - -/////////////////////////////////////////////////////////// -// TDati_rilevanti_set -/////////////////////////////////////////////////////////// - -bool TDati_rilevanti_set::set_field(const TAS400_column_info& fi, const TVariant& var) -{ // Salva le date in formato GGMMAAAA invece dello standard ANSI AAAAMMGG - if (fi._type == DT && fi._width == 8) + if (fi._type == _datefld) { const TDate d = var.as_date(); if (d.ok()) { TFixed_string str = d.string(full, '\0', full, full, gma_date); - row().overwrite(str, fi._pos); + row().add(str, fld); } else - row().overwrite(" ", fi._pos); + row().add("", fld); return true; } else - // Salva gli importi in formato 000001234 (non possono essere negativi) - if (fi._type == NU && fi._width == 9) + // Salva gli importi in italiano (non possono essere negativi) + if (fi._type == _realfld) { - TString16 str = var.as_string(); - CHECKS(str[0] != '-', "Importo negativo non ammesso:", (const char*)str); - // Tiene la sola parte intera e riempie di zeri - const int dot = str.find('.'); - if (dot >= 0) str.cut(dot); - str.right_just(fi._width, '0'); - row().overwrite(str, fi._pos); - return true; + real r = var.as_real(); + row().add(r.stringa(0, 2), fld); } else - if (fi._type == AN) + if (fi._type == _boolfld) + { + row().add(var.as_bool() ? "S" : " ", fld); + } + else { TString256 str = var.as_string(); str.upper(); @@ -760,162 +491,156 @@ bool TDati_rilevanti_set::set_field(const TAS400_column_info& fi, const TVariant str.replace('ñ', 'N'); str.replace('ö', 'O'); str.replace('ü', 'U'); - row().overwrite(str, fi._pos, fi._width); - return true; + row().add(str, fld); } - return TAS400_recordset::set_field(fi, var); + return true; } -const TVariant& TDati_rilevanti_set::get_field(const TAS400_column_info& ci) const +void TSpesometro_set::add_header_data(int n, const TString& value) { - if (ci._type == DT && ci._width == 8) - { - const TRecnotype n = current_row(); - if (n >= 0 && n < items()) - { - const TString& str = row(n).mid(ci._pos, ci._width); - const int gg = atoi(str.left(2)); - const int mm = atoi(str.mid(2,2)); - const int aa = atoi(str.mid(4,4)); - if (aa > 1800 && aa < 2100) - { - TVariant& var = get_tmp_var(); - var.set(TDate(gg, mm, aa)); - return var; - } - } - return NULL_VARIANT; - } - return TAS400_recordset::get_field(ci); + CHECKD(n > 0 && n <= 16, "Bad SO record type ", n); + TString8 fld; fld.format("SO%03d", n); + new_rec(fld); + set(1, value); } -int TDati_rilevanti_set::add_header(const TMask& msk, int num_inv, int tot_inv) +bool TSpesometro_set::add_header(const TMask& msk) { - const TAnagrafica ditta(LF_NDITTE, prefix().get_codditta()); + const long codditta = prefix().get_codditta(); + const TAnagrafica ditta(LF_NDITTE, codditta); - new_rec("0"); + add_header_data(1, ditta.codice_fiscale()); + add_header_data(2, ditta.partita_IVA()); - const int tipologia = msk.get_int(F_TIPOLOGIA); - set(4, tipologia); - if (tipologia > 0) + TString16 key; + key.format("%ld", codditta); + const TRectype& ndt = cache().get(LF_NDITTE, key); + const char* codatt = ndt.get(NDT_CODATTPREV); + key.format("%ld|%s", codditta, codatt); + const TRectype& att = cache().get(LF_ATTIV, key); + const TString8 ateco = att.get(ATT_CODATECO); + add_header_data(3, ateco); + + TString80 tel; + tel << ndt.get(NDT_PTEL) << ndt.get(NDT_TEL); + add_header_data(4, tel); + + tel.cut(0) << ndt.get(NDT_PFAX) << ndt.get(NDT_FAX); + add_header_data(5, tel); + add_header_data(6, EMPTY_STRING); + if (ditta.fisica()) { - set(5, msk.get(F_PROTELE)); - set(6, msk.get(F_PROTDOC)); - } - - set(7, ditta.codice_fiscale()); - set(8, ditta.partita_IVA()); - - if (ditta.giuridica()) - { - set( 9, ditta.ragione_sociale()); - set(10, ditta.comune_residenza()); - set(11, ditta.provincia_residenza()); + add_header_data( 7, ditta.cognome()); + add_header_data( 8, ditta.nome()); + add_header_data( 9, ditta.sesso() == 'F' ? "F" : "M"); + add_header_data(10, ditta.data_nascita().string(full, '\0', full, full, gma_date)); + add_header_data(11, ditta.comune_nascita()); + add_header_data(12, ditta.provincia_nascita()); + add_header_data(13, EMPTY_STRING); } else { - set(12, ditta.cognome()); - set(13, ditta.nome()); - set(14, ditta.sesso()); - set(15, ditta.data_nascita()); - set(16, ditta.comune_nascita()); - set(17, ditta.provincia_nascita()); - } - set(18, _anno); - - if (tot_inv < 1) tot_inv = 1; - if (num_inv <= 0) num_inv = 1; - if (num_inv > tot_inv) num_inv = tot_inv; - set(20, num_inv); - set(21, tot_inv); - - const TString& cofi = msk.get(F_INTER_COFI); - if (cofi.full()) - { - set(22, cofi); - set(23, msk.get(F_INTER_CAF)); - set(24, msk.get(F_INTER_COM)); - set(25, msk.get(F_INTER_DATE)); - } - else - { - set(25, TDate()); // Svuota data impegno + add_header_data( 7, EMPTY_STRING); + add_header_data( 8, EMPTY_STRING); + add_header_data( 9, EMPTY_STRING); + add_header_data(10, EMPTY_STRING); + add_header_data(11, EMPTY_STRING); + add_header_data(12, EMPTY_STRING); + add_header_data(13, ditta.ragione_sociale()); } - return tipologia; + add_header_data(14, msk.get(F_ANNO)); + add_header_data(15, msk.get(F_TIPO)=="BL" ? msk.get(F_PERIODO) : EMPTY_STRING); + add_header_data(16, TFixed_string("04879210963")); + + if (ateco.blank()) + return error_box("Manca il codice attività ATECO nell'anagrafica della ditta %ld", codditta); + + return true; } -void TDati_rilevanti_set::add_footer() +bool TSpesometro_set::add_footer(const TMask& /*msk*/) { - TString f = row(0); - f.overwrite("9"); - new_rec(f); -} - -bool TDati_rilevanti_set::split(const TFilename& name, const TRecnotype maxalleg) -{ - const TRecnotype totrec = items(); - bool done = totrec <= maxalleg; - if (!done) + // Elimina elementi composti da un solo spazio + for (TRecnotype i = items()-1; i >= 0; i--) { - TString msg; - msg.format(FR("Spezzatura del file %s in blocchi da %d righe"), (const char*)name, maxalleg); - TProgind pi(totrec, msg); - - TDati_rilevanti_set outset(_anno); - int f = 0; - for (TRecnotype r = 0; r < totrec; r++) + TToken_string& r = row(i); + if (r.empty_items()) { - if (!pi.setstatus(r)) - break; // Procedura interrotta dall'utente - outset.new_rec(row(r)); - if (outset.items() >= maxalleg || r == totrec-1) - { - // Costruisce il nome del file di invio parziale, es: Spesometro00001_2.txt - TFilename outname = name; - const TString8 saved_ext = outname.ext(); - outname.ext(""); outname << '_' << (++f); - outname.ext(saved_ext); - done = outset.save_as(outname); - if (done) - outset.destroy(); - else - { - cantwrite_box(outname); - break; - } - } + destroy(i); + continue; } - if (f > 1) - message_box(FR("Sono stati generati %d file nella cartella %s"), f, name.path()); + + for (;;) + { + const int p = r.find("| |"); + if (p > 0) + { + r.overwrite(r.mid(p+2), p+1); + r.rtrim(1); + } + else + break; + } + r.rtrim(); } - return done; + return true; } -void TDati_rilevanti_set::init() + +void TSpesometro_set::init() { - TDati_rilevanti_trc trc; - for (int i = 0; i <= 5; i++) - trc.create_fields(i, *this); - trc.create_fields(9, *this); + create_column("Tipo", _alfafld); // 0 + create_column("PartitaIVA", _alfafld); + create_column("CodiceFiscale", _alfafld); + create_column("IVANonEsposta", _boolfld); + create_column("Noleggio", _alfafld); + create_column("Autofattura", _boolfld); // 5 + create_column("ReverseCharge", _boolfld); + create_column("DataDoc", _datefld); + create_column("DataReg", _datefld); + create_column("NumDoc", _alfafld); + create_column("TipoOperazione", _alfafld); // 10 + create_column("TipoDocumento", _alfafld); + create_column("Imponibile", _realfld); // 12 + create_column("Imposta", _realfld); + + create_column("Cognome", _alfafld); // 14 + create_column("Nome", _alfafld); + create_column("DataNasc", _datefld); + create_column("ComNasc", _alfafld); + create_column("Provincia", _alfafld); + create_column("StatoEstero", _alfafld); // 19 + create_column("CittaEstera", _alfafld); + create_column("IndirEstero", _alfafld); + create_column("RagSoc", _alfafld); // 22 + create_column("CittaEsteraSede", _alfafld); + create_column("StatoEsteroSede", _alfafld); + create_column("IndirEsteroSede", _alfafld); + create_column("CodiceIVAEstero", _alfafld); + + create_column("BlackList", _boolfld); // 27 + create_column("NonResidente", _boolfld); + create_column("AcquistoDaNonRes", _boolfld); + create_column("TipoImponibile", _alfafld); + + create_column("OperazAggAttive", _intfld); // 31 + create_column("OperazAggPassive", _intfld); + + create_column("FatturaRiepilogativa", _boolfld); + create_column("SchedaCarburante", _boolfld); // 34 } -TDati_rilevanti_set::TDati_rilevanti_set(const TFilename& file) - : TAS400_recordset("AS400(1800,1)"), _anno(2011) +TSpesometro_set::TSpesometro_set(const TFilename& file) : TCSV_recordset("CSV(|)") { init(); - if (load_file(file) && move_first()) - { - const int anno = get(17).as_int(); - if (anno > 2010) - _anno = anno; - } + load_file(file); + move_first(); } -TDati_rilevanti_set::TDati_rilevanti_set(int anno) - : TAS400_recordset("AS400(1800,1)"), _anno(anno) +TSpesometro_set::TSpesometro_set() : TCSV_recordset("CSV(|)") { init(); } @@ -1053,214 +778,43 @@ const TString& TCofi_cache::paiv2ragsoc(char tipocf, const TString& paiv) } /////////////////////////////////////////////////////////// -// TDati_rilevanti_rep +// TSpesometro_rep /////////////////////////////////////////////////////////// -bool TDati_rilevanti_rep::get_usr_val(const TString& name, TVariant& var) const +bool TSpesometro_rep::get_usr_val(const TString& name, TVariant& var) const { - const TDati_rilevanti_set& set = *(TDati_rilevanti_set*)recordset(); - const int tipo = set.rec_type()[0] - '0'; - if (name == "ANNO") { - var.set(set.anno()); + const TFixed_string d("DataReg"); + TVariant var; + if (!get_record_field(d, var)) + var = "2013"; + else + var = var.as_string().right(4); return true; - } - if (name == "TIPO") - { - var.set(tipo); - return true; - } - if (name == "COFI") - { - switch (tipo) - { - case 1: var = set.get("1.2"); break; - case 4: var = set.get("4.3"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "PAIV") - { - switch (tipo) - { - case 2: var = set.get("2.2"); break; - case 4: var = set.get("4.2"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "RAGSOC") - { - switch (tipo) - { - case 1: var = cofi2ragsoc(' ', set.get("1.2").as_string()); break; - case 2: - { - const char tipocf = set.get("2.8").as_int() == 2 ? 'F' : 'C'; - var = paiv2ragsoc(tipocf, set.get("2.2").as_string()); - } - break; - case 3: - var = set.get("3.8"); - if (var.as_string().blank()) - { - TString80 rs; - rs << set.get("3.2") << ' ' << set.get("3.3"); - var = rs.trim(); - } - break; - case 4: - { - const TString16 paiv = set.get("4.2").as_string(); - if (paiv.full()) - var = paiv2ragsoc(' ', paiv); - else - { - const TString16 cofi = set.get("4.3").as_string(); - var = cofi2ragsoc(' ', cofi); - } - } - break; - case 5: - var = set.get("5.8"); - if (var.as_string().blank()) - { - TString80 rs; - rs << set.get("5.2") << ' ' << set.get("5.3"); - var = rs.trim(); - } - break; - default: var.set_null(); break; - } - return true; - } - if (name == "DATAREG") - { - switch (tipo) - { - case 1: var = set.get("1.3"); break; - case 2: var = set.get("2.3"); break; - case 3: var = set.get("3.12"); break; - case 4: var = set.get("4.4"); break; - case 5: var = set.get("5.12"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "NUMDOC") - { - switch (tipo) - { - case 2: var = set.get("2.4"); break; - case 3: var = set.get("3.13"); break; - case 4: var = set.get("4.5"); break; - case 5: var = set.get("5.13"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "IMPORTO") - { - switch (tipo) - { - case 1: var = set.get("1.5"); break; - case 2: var = set.get("2.6"); break; - case 3: var = set.get("3.15"); break; - case 4: var = set.get("4.6"); break; - case 5: var = set.get("5.14"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "IMPOSTA") - { - switch (tipo) - { - case 2: var = set.get("2.7"); break; - case 3: var = set.get("3.16"); break; - case 4: var = set.get("4.7"); break; - case 5: var = set.get("5.15"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "DATARETT") - { - switch (tipo) - { - case 4: var = set.get("4.8"); break; - case 5: var = set.get("5.16"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "NUMRETT") - { - switch (tipo) - { - case 4: var = set.get("4.9"); break; - case 5: var = set.get("5.17"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "SIMPORTO") - { - switch (tipo) - { - case 4: var = set.get("4.10"); break; - case 5: var = set.get("5.18"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "SIMPOSTA") - { - switch (tipo) - { - case 4: var = set.get("4.11"); break; - case 5: var = set.get("5.19"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "MODPAG") - { - switch (tipo) - { - case 1: var = set.get("1.4"); break; - case 2: var = set.get("2.5"); break; - case 3: var = set.get("3.14"); break; - default: var.set_null(); break; - } - return true; - } - if (name == "TIPOPE") - { - switch (tipo) - { - case 2: var = set.get("2.8"); break; - case 3: var = set.get("3.17"); break; - default: var.set_null(); break; - } - return true; - } - + } return TReport::get_usr_val(name, var); } -TDati_rilevanti_rep::TDati_rilevanti_rep(const TFilename& file) +TSpesometro_rep::TSpesometro_rep(const TFilename& file) { load("fe0100"); - TDati_rilevanti_set* set = new TDati_rilevanti_set(file); + TSpesometro_set* set = new TSpesometro_set(file); - // Elimina testata e coda - set->destroy(0); - set->destroy(set->items()-1); + // Elimina dati di testata e coda + for (TRecnotype i = set->items()-1; i >= 0; i--) + { + if (set->move_to(i)) + { + const TString& t = set->get(0).as_string(); + if (t.blank() || t.starts_with("SO")) + set->destroy(i); + } + else + break; + } set_recordset(set); } diff --git a/fe/felib.h b/fe/felib.h index aee6382c8..2bffb21bf 100644 --- a/fe/felib.h +++ b/fe/felib.h @@ -25,6 +25,7 @@ class TAnagrafica : public TObject TAnagrafica& operator =(const TAnagrafica&) { CHECK(false, "Can't copy TAnagrafica"); } TAnagrafica(const TAnagrafica&) { CHECK(false, "Can't copy TAnagrafica"); } + protected: void build_ind_res(const TRectype& rec, const char* ind, const char* civ); void split_ragsoc(); @@ -38,14 +39,15 @@ public: const TString& partita_IVA() const { return _paiv; } const TString& ragione_sociale() const { return _ragsoc; } - const TString& cognome() const { return _ragsoc.left(24); } - const TString& nome() const { CHECK(fisica(), "Non chiedere nome giuridico!"); return _ragsoc.mid(30,20); } + const TString& cognome() const; + const TString& nome() const; char sesso() const { CHECK(fisica(), "Solo sesso fisico!"); return (_cofi[9] >= '4') ? 'F' : 'M'; } const TDate& data_nascita() const { return _data_nasc; } bool italiano() const; bool estero() const { return !italiano(); } const TString& stato_estero_UNICO() const; int inserimento_in_allegato() const { return _allegato; } + char is_black_list() const; const TString& comune_nascita() const; const TString& provincia_nascita() const; @@ -69,68 +71,35 @@ public: }; /////////////////////////////////////////////////////////// -// TContratto +// TSpesometro_set /////////////////////////////////////////////////////////// -class TContratto : public TObject +class TSpesometro_set : public TCSV_recordset { - TRectype _rec; - protected: - bool importo_annuale(int anno, real& importo, real& imposta) const; - bool importo_figli(int anno, real& importo, real& imposta) const; - -public: - virtual bool ok() const { return !_rec.empty(); } - const TString& chiave() const { return _rec.get("CODTAB"); } - const TString& codice() const { return chiave().mid(7); } - const TString& codice_padre() const { return _rec.get("S1"); } - const TString& codice_base() const; - bool totale_annuale(int anno, real& importo, real& imposta) const; - int modalita_pagamento() const; - - bool init(const TString& codtab); - bool init(char tipocf, long codcf, const TString& codcont); - bool init(const TRectype& rec); - - TContratto() : _rec(LF_TABMOD) {} - TContratto(char tipocf, long codcf, const char* codcont) : _rec(LF_TABMOD) { init(tipocf, codcf, codcont); } - TContratto(const TRectype& rec) : _rec(LF_TABMOD) { init(rec); } -}; - -/////////////////////////////////////////////////////////// -// TDati_rilevanti_set -/////////////////////////////////////////////////////////// - -class TDati_rilevanti_set : public TAS400_recordset -{ - int _anno; - -protected: - virtual bool set_field(const TAS400_column_info& fi, const TVariant& var); - virtual const TVariant& get_field(const TAS400_column_info& fi) const; + virtual bool set(unsigned int fld, const TVariant& var); void init(); - bool set_val(int n, const TVariant& v) { return TAS400_recordset::set(n-1, v); } + void add_header_data(int n, const TString& value); public: - bool set(unsigned int n, const TVariant& v) { return set_val(n, v); } - bool set(unsigned int n, const TString& v) { return set_val(n, v); } - bool set(unsigned int n, char v) { TString4 str; str << v; return set_val(n, str); } - bool set(unsigned int n, int v) { return set_val(n, long(v)); } - bool set(unsigned int n, const real& v) { return set_val(n, v); } - bool set(unsigned int n, const TDate& v) { return set_val(n, v); } - int add_header(const TMask& msk, int num_inv = 1, int tot_inv = 1); - void add_footer(); - bool split(const TFilename& name, const TRecnotype maxalleg = 15000); - int anno() const { return _anno; } + virtual const TVariant& get(unsigned int column) const; + bool set(unsigned int n, const char* v) { return set(n, TVariant(v)); } + bool set(unsigned int n, const TString& v) { return set(n, TVariant(v)); } + bool set(unsigned int n, char v) { TString4 str; str << v; return set(n, str); } + bool set(unsigned int n, int v) { return set(n, TVariant(long(v))); } + bool set(unsigned int n, bool v) { return set(n, TVariant(v)); } + bool set(unsigned int n, const real& v) { return set(n, TVariant(v)); } + bool set(unsigned int n, const TDate& v) { return set(n, TVariant(v)); } + bool add_header(const TMask& msk); + bool add_footer(const TMask& msk); - TDati_rilevanti_set(int anno); - TDati_rilevanti_set(const TFilename& file); + TSpesometro_set(); + TSpesometro_set(const TFilename& file); }; /////////////////////////////////////////////////////////// -// TDati_rilevanti_rep +// TSpesometro_rep /////////////////////////////////////////////////////////// class TCofi_cache : public TCache @@ -147,25 +116,24 @@ public: TCofi_cache() : _clifo(LF_CLIFO), _occas(LF_OCCAS) { } }; -class TDati_rilevanti_rep : public TReport +class TSpesometro_rep : public TReport { TCofi_cache _cofi; protected: const TString& cofi2ragsoc(char tipocf, const TString& cofi) const - { return ((TDati_rilevanti_rep*)this)->_cofi.cofi2ragsoc(tipocf, cofi); } + { return ((TSpesometro_rep*)this)->_cofi.cofi2ragsoc(tipocf, cofi); } const TString& paiv2ragsoc(char tipocf, const TString& cofi) const - { return ((TDati_rilevanti_rep*)this)->_cofi.paiv2ragsoc(tipocf, cofi); } + { return ((TSpesometro_rep*)this)->_cofi.paiv2ragsoc(tipocf, cofi); } virtual bool get_usr_val(const TString& name, TVariant& var) const; public: - TDati_rilevanti_rep(const TFilename& file); + TSpesometro_rep(const TFilename& file); }; // Utility -real fe_importo_limite(int anno); bool fe_is_nota_variazione(const TRectype& rec); #endif \ No newline at end of file