// Programma per la stampa del quadro VL #include #include #include #include "cg7401.h" #include "cgpim.h" #include "cglib.h" #include "cg7a00a.h" #include "rmoviva.h" #include #include "ivaliq.h" #define REP_QUADRO 1 class TQuadro_VL_recordset : public TQuadro_IVA_recordset { protected: virtual void load(const char repid); public: TQuadro_VL_recordset(TQuadro_IVA_mask * mask, const char* use, const int year, const char repid) : TQuadro_IVA_recordset(mask, use, year, repid) { load(repid); } virtual ~TQuadro_VL_recordset() {} }; void TQuadro_VL_recordset::load(const char repid) { real ivadeb; real ivadetr; clear(); TString query("USE PIM\nFROM CODTAB="); query << year() << "\nTO CODTAB=" << year(); TISAM_recordset pim(query); for (pim.move_first(); !pim.eof(); pim.move_next()) { const TString80 codtab = pim.get_string("CODTAB"); TString8 codiva(codtab.smid(16, 4)); codiva.trim(); const TRectype & ivar = cache().get("%IVA", codiva); const TString8 aliquota = ivar.get("R0"); const TString8 codreg(format("%d%-3s", year(), (const char*)codtab.smid(10, 3))); const TRectype & reg = cache().get("REG", codreg); const tiporec tipo = (tiporec)reg.get_int("I9"); const bool vendite = reg.get_int("I0") == 1; const int month = atoi(codtab.smid(13, 2)); if (tipo != liquidazione && month == 13) { const TRectype & pimr = pim.cursor()->curr(); TArray imponibili; TArray imposte; classify_pim_array(pimr, imponibili, imposte, true, true); FOR_EACH_ARRAY_ITEM(imposte, t, obj) { if (obj != nullptr) { real & imp = (real &)*obj; real & iva = (real &)imposte[t]; tiporec tipo = (tiporec)t; if (vendite) { if (tipo == vend_norm || tipo == corr_norm) { add_value("VL01.1", iva); // VL1.1 IVA a debito ivadeb += iva; } if (aliquota == "19.00" || aliquota == "20.00" || aliquota == "21.00") { real imposta_corretta = imp; imposta_corretta *= 0.22; imposta_corretta.round(0); add_value("VL01.1", iva - imposta_corretta); iva = imposta_corretta; } } else { if (tipo == acq_norm) { add_value("VL02.1", iva); // VL2.1 IVA detraibile ivadetr += iva; } if (aliquota == "19.00" || aliquota == "20.00" || aliquota == "21.00") { real imposta_corretta = imp; imposta_corretta *= 0.22; imposta_corretta.round(0); add_value("VL02.1", iva - imposta_corretta); iva = imposta_corretta; } } } } } } /* TISAM_recordset * recset = app().mask()->get_recset(REP_QUADRO); recset->set_var("#ANNO", format("%d", year())); for (recset->move_first(); !recset->eof(); recset->move_next()) { const int regspiva = recset->get("26.REGSPIVA").as_int(); const real iva = recset->get(RMI_IMPOSTA).as_real(); switch (regspiva) { case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 13: case 14: case 15: case 16: case 17: case 18: case 19: case 50: case 51: add_value("VL01.1", iva); ivadeb += iva; break; default: break; } } */ const TRectype & lia = cache().get("%LIA", format("%04d", year())); const bool credito_compensabile = (lia.get("S9") == "CM"); const bool mensile = lia.get("S7") == "M"; const int annual_month = mensile ? 13 : 12; add_value("VL08.1", lia.get_real("R0")); add_value("VL08.2", mask().get_real(F_VL082)); add_value("VL08.3", mask().get_real(F_VL083)); add_value("VL09.1", lia.get_real("R15")); if (!credito_compensabile) { query.reset(); query << "USE LAM\nFROM CODTAB=" << year() << "\nTO CODTAB=" << year(); TISAM_recordset lam(query); for (lam.move_first(); !lam.eof(); lam.move_next()) { int month = atoi(lam.get_string("CODTAB").smid(4)); real iva_credeb = lam.get_real("R0"); iva_credeb -= lam.get_real("R1"); iva_credeb += lam.get_real("R5"); iva_credeb -= lam.get_real("R7"); iva_credeb += lam.get_real("R6"); iva_credeb -= lam.get_real("R8"); if (iva_credeb > ZERO) // dovrei versare { TString lim_key = format("%04d%02d", year(), month); real credito_utilizzato_iva; real risultato(cache().get("LIM", lim_key, "R0")); if (risultato > ZERO && risultato != iva_credeb) // devo versare { if (risultato <= iva_credeb) credito_utilizzato_iva = iva_credeb - risultato; else credito_utilizzato_iva = risultato -iva_credeb; add_value("VL27.1", credito_utilizzato_iva); ivadetr += credito_utilizzato_iva; if (month < 10) { add_value("VL22.1", credito_utilizzato_iva); ivadeb += credito_utilizzato_iva; } } } } } query.reset(); query << "USE LIM\nFROM CODTAB=" << year() << "\nTO CODTAB=" << year(); TISAM_recordset lim(query); for (lim.move_first(); !lim.eof(); lim.move_next()) { int month = atoi(lim.get_string("CODTAB").smid(4)); const real crediva = lim.get_real("R15"); const real credf24 = lim.get_real("R16"); add_value("VL27.1", crediva); // add_value("VL09.1", crediva); // add_value("VL09.1", credf24); ivadetr += crediva; if (month < annual_month) add_value("VL23.1", lim.get_real("R34")); else add_value("VL36.1", lim.get_real("R34")); if (month < 10) { add_value("VL22.1", crediva); ivadeb += crediva; add_value("VL22.1", credf24); ivadeb += credf24; } if (month == 13) { const real var_cred = lim.get("R17").as_real(); if (var_cred < ZERO) // ??? add_value("VF26.2", -var_cred); } } add_value("VL10.1", mask().get_real(F_VL101)); add_value("VL11.1", mask().get_real(F_VL111)); ivadetr += mask().get_real(F_VL111); add_value("VL11.2", mask().get_real(F_VL112)); ivadetr += mask().get_real(F_VL112); add_value("VL12.1", mask().get_real(F_VL121)); add_value("VL12.2", mask().get_real(F_VL122)); add_value("VL20.1", mask().get_real(F_VL201)); ivadeb += mask().get_real(F_VL201); add_value("VL21.1", mask().get_real(F_VL211)); ivadeb += mask().get_real(F_VL211); add_value("VL24.1", mask().get_real(F_VL241)); ivadetr += mask().get_real(F_VL241); add_value("VL25.1", mask().get_real(F_VL251)); ivadetr += mask().get_real(F_VL251); add_value("VL26.1", mask().get_real(F_VL261)); ivadetr += mask().get_real(F_VL261); add_value("VL28.1", mask().get_real(F_VL281)); ivadetr += mask().get_real(F_VL281); add_value("VL29.1", mask().get_real(F_VL291)); ivadetr += mask().get_real(F_VL291); query.reset(); query << "USE " << LF_IVALIQ << " SELECT " << IVAL_GENERATA << "==\"U\"\nFROM " << IVAL_ANNO << "=" << year() << "\nTO " << IVAL_ANNO << "=" << year(); TISAM_recordset ivaliq(query); real ivaperd; real ivaperv; for (ivaliq.move_first(); !ivaliq.eof(); ivaliq.move_next()) { const real ivaver = ivaliq.get_real(IVAL_IVAVER); add_value("VL30.2", ivaver); add_value("VL30.3", ivaver); ivaperd += ivaver; ivaperv += ivaver; ivadetr += ivaver; } add_value("VL30.4", mask().get_real(F_VL304)); ivaperv += mask().get_real(F_VL304); add_value("VL30.5", mask().get_real(F_VL305)); ivaperv += mask().get_real(F_VL305); if (ivaperd >= ivaperv) add_value("VL30.1", ivaperd); else add_value("VL30.1", ivaperv); add_value("VL31.1", mask().get_real(F_VL311)); ivadetr += mask().get_real(F_VL311); if (ivadeb > ivadetr) add_value("VL32.1", ivadeb - ivadetr); else if (ivadeb < ivadetr) add_value("VL33.1", ivadetr - ivadeb); add_value("VL35.1", mask().get_real(F_VL351)); add_value("VL37.1", mask().get_real(F_VL371)); add_value("VL40.1", mask().get_real(F_VL401)); add_value("VL41.1", mask().get_real(F_VL411)); add_value("VL41.2", mask().get_real(F_VL412)); } class TQuadro_VL_app : public TQuadro_IVA_app { protected: virtual bool has_data() const override { return true; } virtual void load_sheet(TSheet_field & sf); public: virtual void load_data(TQuadro_IVA_mask & m) override; virtual void save_data(TQuadro_IVA_mask & m) override; virtual TQuadro_IVA_recordset * app_recordset(const char* use, const int year, const char repid) { return new TQuadro_VL_recordset(mask(), use, year,repid); } TQuadro_VL_app() : TQuadro_IVA_app("Stampa Quadro VL", "cg7a00a") {} virtual ~TQuadro_VL_app() {} }; void TQuadro_VL_app::load_sheet(TSheet_field & sf) { // TToken_string & row1 = sf.row(sf.items()); row1.add("|1|Quadro VJ - VJ1 - VJ19|cg7800b"); } void TQuadro_VL_app::load_data(TQuadro_IVA_mask & m) { TTable div("DIV"); div.put("CODTAB", m.get(F_YEAR)); if (div.read() != NOERR) div.zero(); m.set(F_VL082, div.get("R0")); m.set(F_VL083, div.get("R1")); m.set(F_VL101, div.get("R2")); m.set(F_VL111, div.get("R3")); m.set(F_VL112, div.get("R4")); m.set(F_VL121, div.get("R5")); m.set(F_VL122, div.get("R6")); m.set(F_VL201, div.get("R7")); m.set(F_VL211, div.get("R8")); m.set(F_VL241, div.get("R9")); m.set(F_VL251, div.get("R10")); m.set(F_VL261, div.get("R11")); m.set(F_VL281, div.get("R12")); m.set(F_VL291, div.get("R13")); m.set(F_VL304, div.get("R14")); m.set(F_VL305, div.get("R15")); m.set(F_VL311, div.get("R16")); m.set(F_VL351, div.get("R17")); m.set(F_VL371, div.get("R18")); m.set(F_VL401, div.get("R19")); m.set(F_VL411, div.get("R20")); m.set(F_VL412, div.get("R21")); } void TQuadro_VL_app::save_data(TQuadro_IVA_mask & m) { TTable div("DIV"); div.put("CODTAB", m.get(F_YEAR)); div.put("R0", m.get(F_VL082)); div.put("R1", m.get(F_VL083)); div.put("R2", m.get(F_VL101)); div.put("R3", m.get(F_VL111)); div.put("R4", m.get(F_VL112)); div.put("R5", m.get(F_VL121)); div.put("R6", m.get(F_VL122)); div.put("R7", m.get(F_VL201)); div.put("R8", m.get(F_VL211)); div.put("R9", m.get(F_VL241)); div.put("R10", m.get(F_VL251)); div.put("R11", m.get(F_VL261)); div.put("R12", m.get(F_VL281)); div.put("R13", m.get(F_VL291)); div.put("R14", m.get(F_VL304)); div.put("R15", m.get(F_VL305)); div.put("R16", m.get(F_VL311)); div.put("R17", m.get(F_VL351)); div.put("R18", m.get(F_VL371)); div.put("R19", m.get(F_VL401)); div.put("R20", m.get(F_VL411)); div.put("R21", m.get(F_VL412)); const int err = div.write_rewrite(); if (err != NOERR) error_box("Errore %d nella scrittura dati.", err); } int cg7a00(int argc, char* argv[]) { TQuadro_VL_app a; a.run(argc, argv, TR("Quadro VL")); return 0; }