diff --git a/ha/hacnv100a.ini b/ha/hacnv100a.ini index 52d0948c4..98a345a2f 100755 --- a/ha/hacnv100a.ini +++ b/ha/hacnv100a.ini @@ -476,7 +476,7 @@ DATAPRZSTO = ANNOES = Esercizio NUMREG = DATAREG = DataMovimento -DATACOMP = DataCompetenza +DATACOMP = DATADOC = DataDocumento DATA74TER = MESELIQ = @@ -544,10 +544,10 @@ CODCMS = FASCMS = [RMOVIVA] -ANNOES = +ANNOES = Anno NUMREG = NUMRIG = -CODIVA = +CODIVA = IdIva IMPONIBILE= IMPOSTA = TIPODET = diff --git a/ha/hacnv200.cpp b/ha/hacnv200.cpp index 70fa148f7..806a614b0 100755 --- a/ha/hacnv200.cpp +++ b/ha/hacnv200.cpp @@ -30,22 +30,95 @@ class THardy_movimenti : public THardy_transfer long _kmovcont; protected: bool trasferisci_righe(); - bool is_mov_iva(); + bool trasferisci_righeiva(); public: virtual bool trasferisci(); THardy_movimenti(const int anno, const TDate dadata, const TDate adata); }; -bool THardy_movimenti::is_mov_iva() +bool THardy_movimenti::trasferisci_righeiva() { - TString query_righe; - query_righe << query_header(); - query_righe << "SELECT * " - "FROM dbo.MovIvaT" + TString_array lista_campi_righeiva; + TConfig& ini = config(); + ini.list_variables(lista_campi_righeiva, true, "RMOVIVA", true); + TString query; + query << query_header(); + query << "SELECT * " + "FROM dbo.MovIvaT " "WHERE KMovconT="; - query_righe << _kmovcont; - TODBC_recordset recset_righe(query_righe); - bool is_iva = (recset_righe.items() > 0); + query << _kmovcont; + TODBC_recordset recset(query); + bool is_iva = (recset.items() > 0); + if (is_iva) + { + bool ok=recset.move_first(); + if (ok) + { + // aggiorna_testata movimento già scritta su ini con i nuovi dati di testata + } + // aggiungo le righe iva + long kregivat = recset.get("KRegivaT").as_int(); + TString query_righe; + query_righe << query_header(); + query_righe << "SELECT * " + "FROM dbo.MovIva " + "WHERE KRegivaT="; + query_righe << kregivat; + TODBC_recordset recset_righe(query_righe); + TString paragraph; + int nrigac = 1; + for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next()) + { + paragraph.format("%d,%d",LF_RMOVIVA,nrigac++); + _conf->set_paragraph(paragraph); + aggiorna_ini(*_conf, lista_campi_righeiva); + + // calcolo dei campi non importabili direttamente + TString4 sezione = "D"; + TImporto imponibile(sezione[0], recset_righe.get("Imponibile").as_real()); + TImporto imposta(sezione[0], recset_righe.get("Imposta").as_real()); + _conf->set(RMI_IMPONIBILE, imponibile.valore().string(0,2)) ; + _conf->set(RMI_IMPOSTA, imposta.valore().string(0,2)); + const TString& key = recset_righe.get("IdConto").as_string(); + TString4 tipoc = recset_righe.get("IdContoTp").as_string(); + const char tipocc = tipoc[0]; + int gr, co; + long so; + switch (tipocc) + { + case 'S': + { + tipoc = " "; + gr = atoi(key.mid(1,2)); + co = atoi(key.mid(3,2)); + so = atoi(key.mid(5,3)); + } + break; + case 'C': + { + tipoc = "C"; + gr = ini.get_int("CLI_GRUPPO", "Mastri"); + co = ini.get_int("CLI_CONTO", "Mastri"); + so = hd_key2cli(key); + } + break; + case 'F': + { + tipoc = "F"; + gr = ini.get_int("FOR_GRUPPO", "Mastri"); + co = ini.get_int("FOR_CONTO", "Mastri"); + so = hd_key2forn(key); + } + break; + default: + break; + } + _conf->set(RMI_TIPOC, tipoc); + _conf->set(RMI_GRUPPO, gr); + _conf->set(RMI_CONTO, co); + _conf->set(RMI_SOTTOCONTO, so); + } + } return is_iva; } @@ -64,7 +137,6 @@ bool THardy_movimenti::trasferisci_righe() TODBC_recordset recset_righe(query_righe); TString paragraph; int nrigac = 1; - int nrigai = 1; for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next()) { paragraph.format("%d,%d",LF_RMOV,nrigac++); @@ -78,7 +150,7 @@ bool THardy_movimenti::trasferisci_righe() if (imp_dare.is_zero()) sezione = "A"; _conf->set(RMV_SEZIONE, sezione); - _conf->set(RMV_IMPORTO, (imp_avere.is_zero() ? imp_dare.valore().stringa(0,2) : imp_avere.valore().stringa(0,2))); + _conf->set(RMV_IMPORTO, (imp_avere.is_zero() ? imp_dare.valore().string(0,2) : imp_avere.valore().string(0,2))); const TString& key = recset_righe.get("IdConto").as_string(); TString4 tipoc = recset_righe.get("IdContoTp").as_string(); const char tipocc = tipoc[0]; @@ -161,35 +233,27 @@ bool THardy_movimenti::trasferisci() while (++hi) { _kmovcont = recset.get("KMovconT").as_int(); - if (is_mov_iva()) - { - TString msg; - msg << TR("Movimento IVA ") << _kmovcont << " non generato"; - log(msg); - } - else - { - if (_conf != NULL) - delete _conf; - _conf = NULL; - TFilename temp(outdir); - temp.add(format("ha%06ld", ntran++)); - temp.ext("ini"); - if (temp.exist()) - temp.fremove(); - _conf = new TConfig(temp); - _conf->set_paragraph("Transaction"); - _conf->set("Action","INSERT"); - _conf->set("Mode", "AUTO"); - paragraph.format("%d",LF_MOV); - _conf->set_paragraph(paragraph); // testata movimento - aggiorna_ini(*_conf, lista_campi); - // righe movimento - trasferisci_righe(); - TString msg; - msg << TR("Movimento contabile ") << _kmovcont << " generato nel file " << temp; - log(msg); - } + if (_conf != NULL) + delete _conf; + _conf = NULL; + TFilename temp(outdir); + temp.add(format("ha%06ld", ntran++)); + temp.ext("ini"); + if (temp.exist()) + temp.fremove(); + _conf = new TConfig(temp); + _conf->set_paragraph("Transaction"); + _conf->set("Action","INSERT"); + _conf->set("Mode", "AUTO"); + paragraph.format("%d",LF_MOV); + _conf->set_paragraph(paragraph); // testata movimento + aggiorna_ini(*_conf, lista_campi); + // righe movimento + trasferisci_righe(); + bool iva = trasferisci_righeiva(); + TString msg; + msg << (iva ? TR("Movimento contabile "): TR("Movimento iva ")) << _kmovcont << " generato nel file " << temp; + log(msg); } if (_conf != NULL) delete _conf;