487 lines
17 KiB
C++
487 lines
17 KiB
C++
// Programma per la stampa del quadro VF
|
||
#include <recarray.h>
|
||
#include <tabutil.h>
|
||
#include <utility.h>
|
||
|
||
#include "cg7401.h"
|
||
#include "cgpim.h"
|
||
|
||
#include "cg7400a.h"
|
||
#include <attiv.h>
|
||
#include "ivadiff.h"
|
||
|
||
#define REP_V12_V16 1
|
||
#define REP_IMPORTAZIONI 2
|
||
#define REP_INTRA 3
|
||
#define REP_SANMARINO 4
|
||
#define REP_RIPACQ 5
|
||
|
||
enum tipo_sospensione { nessuna, sospensione_normale, vol_affari, liquidazione };
|
||
|
||
class TQuadro_VF_recordset : public TQuadro_IVA_recordset
|
||
{
|
||
TQuadro_IVA_mask * _mask;
|
||
|
||
protected:
|
||
virtual void load();
|
||
|
||
public:
|
||
TQuadro_VF_recordset(TQuadro_IVA_mask * mask, const char* use, const int year) : TQuadro_IVA_recordset(mask, use, year) { load(); }
|
||
virtual ~TQuadro_VF_recordset() {}
|
||
};
|
||
|
||
void TQuadro_VF_recordset::load()
|
||
{
|
||
clear();
|
||
|
||
TAssoc_array imponibile;
|
||
TAssoc_array imposta;
|
||
TAssoc_array imponibile_agricolo;
|
||
TAssoc_array imposta_agricola;
|
||
|
||
imponibile.add("2.00", TString8("VF01.1"));
|
||
imposta.add("2.00", TString8("VF01.2"));
|
||
imponibile.add("4.00", TString8("VF02.1"));
|
||
imposta.add("4.00", TString8("VF02.2"));
|
||
imponibile.add("5.00", TString8("VF03.1"));
|
||
imposta.add("5.00", TString8("VF03.2"));
|
||
imponibile.add("7.30", TString8("VF04.1"));
|
||
imposta.add("7.30", TString8("VF04.2"));
|
||
imponibile.add("7.50", TString8("VF05.1"));
|
||
imposta.add("7.50", TString8("VF05.2"));
|
||
imponibile.add("7.65", TString8("VF06.1"));
|
||
imposta.add("7.65", TString8("VF06.2"));
|
||
imponibile.add("7.95", TString8("VF07.1"));
|
||
imposta.add("7.95", TString8("VF07.2"));
|
||
imponibile.add("8.30", TString8("VF08.1"));
|
||
imposta.add("8.30", TString8("VF08.2"));
|
||
imponibile.add("8,50", TString8("VF09.1"));
|
||
imposta.add("8,50", TString8("VF09.2"));
|
||
imponibile.add("8.80", TString8("VF09.1"));
|
||
imposta.add("8.80", TString8("VF09.2"));
|
||
imponibile.add("10.00",TString8("VF10.1"));
|
||
imposta.add("10.00",TString8("VF10.2"));
|
||
imponibile.add("12.30", TString8("VF12.1"));
|
||
imposta.add("12.30", TString8("VF12.2"));
|
||
imponibile.add("22.00", TString8("VF13.1"));
|
||
imposta.add("22.00", TString8("VF13.2"));
|
||
// VF30.1-8 METODO UTILIZZATO PER LA DETERMINAZIONE DELL<4C>IVA AMMESSA IN DETRAZIONE
|
||
TString query; query << "USE ATTIV\nFROM CODDITTA=#F\nTO CODDITTA=#F";
|
||
|
||
TISAM_recordset at(query);
|
||
bool agenziaviaggio = false;
|
||
bool minori = false;
|
||
bool agricolo_misto = false;
|
||
bool agricolo = false;
|
||
bool prorata = false;
|
||
bool prorataprev = false;
|
||
bool prorata100 = false;
|
||
|
||
at.set_var("#F", prefix().get_codditta());
|
||
|
||
for (bool ok = at.move_first(); ok; ok = at.move_next())
|
||
{
|
||
agenziaviaggio |= at.get(ATT_REG74TER).as_bool();
|
||
minori |= at.get(ATT_ART74_4).as_bool();
|
||
agricolo |= at.get(ATT_REGAGR).as_bool();
|
||
agricolo_misto |= !at.get(ATT_REGAGR).as_bool();
|
||
|
||
const TString16 codatt = at.get(ATT_CODATT).as_string();
|
||
const int tipoatt = at.get(ATT_TIPOATT).as_int();
|
||
|
||
for (int t = 1; t < 3; t++)
|
||
{
|
||
const TString16 key = format("%4d%5s%1d13", year(), (const char *)codatt, t);
|
||
const TRectype & plm = cache().get("PLM", key);
|
||
|
||
if (plm.full())
|
||
{
|
||
prorataprev |= plm.get_real("R2") > real(50.0);
|
||
prorata |= plm.get_real("R2") > ZERO;
|
||
prorata100 &= plm.get_real("R2") >= CENTO;
|
||
}
|
||
}
|
||
}
|
||
if (!agricolo)
|
||
agricolo_misto = false;
|
||
|
||
set_bool("VF30.1", agenziaviaggio);
|
||
set_bool("VF30.2");
|
||
set_bool("VF30.3", prorataprev);
|
||
set_bool("VF30.4");
|
||
set_bool("VF30.5");
|
||
set_bool("VF30.6", minori);
|
||
set_bool("VF30.7", agricolo_misto);
|
||
set_bool("VF30.8", agricolo);
|
||
|
||
imponibile_agricolo.add("2.00", TString8("V39.1"));
|
||
imposta_agricola.add("2.00", TString8("VF39.2"));
|
||
imponibile_agricolo.add("4.00", TString8("VF40.2"));
|
||
imposta_agricola.add("4.00", TString8("VF40.2"));
|
||
imponibile_agricolo.add("7.30", TString8("VF41.1"));
|
||
imposta_agricola.add("7.30", TString8("VF41.2"));
|
||
imponibile_agricolo.add("7.50", TString8("VF42.1"));
|
||
imposta_agricola.add("7.50", TString8("VF42.2"));
|
||
imponibile_agricolo.add("7.65", TString8("VF43.1"));
|
||
imposta_agricola.add("7.65", TString8("VF43.2"));
|
||
imponibile_agricolo.add("7.95", TString8("VF44.1"));
|
||
imposta_agricola.add("7.95", TString8("VF44.2"));
|
||
imponibile_agricolo.add("8.30", TString8("VF45.1"));
|
||
imposta_agricola.add("8.30", TString8("VF45.2"));
|
||
imponibile_agricolo.add("8,50", TString8("VF46.1"));
|
||
imposta_agricola.add("8,50", TString8("VF46.2"));
|
||
imponibile_agricolo.add("8.80", TString8("VF47.1"));
|
||
imposta_agricola.add("8.80", TString8("VF47.2"));
|
||
imponibile_agricolo.add("10.00",TString8("VF48.1"));
|
||
imposta_agricola.add("10.00",TString8("VF48.2"));
|
||
imponibile_agricolo.add("12.30", TString8("VF49.1"));
|
||
imposta_agricola.add("12.30", TString8("VF49.2"));
|
||
|
||
query = "USE PIM\nFROM CODTAB=";
|
||
query << year() << "\nTO CODTAB=" << year();
|
||
|
||
TISAM_recordset pim(query);
|
||
bool good = false;
|
||
|
||
for (pim.move_first(); !pim.eof(); pim.move_next())
|
||
{
|
||
|
||
const TString80 codtab = pim.get("CODTAB").as_string();
|
||
|
||
const TString8 codreg(format("%d%-3s",year(), (const char*)codtab.mid(10,3)));
|
||
const TRectype & reg = cache().get("REG", codreg);
|
||
const tiporec tipo = (tiporec) reg.get_int("I9");
|
||
const bool acquisti = reg.get_int("I0") == 2;
|
||
const int month = atoi(codtab.mid(13,2));
|
||
|
||
if (acquisti && tipo != liquidazione && month == 13)
|
||
{
|
||
const TRectype & pimr = pim.cursor()->curr();
|
||
TString8 codiva(codtab.mid(16,4)); codiva.trim();
|
||
const TRectype & ivar = cache().get("%IVA", codiva);
|
||
const TString8 aliquota = ivar.get("R0");
|
||
const int tipocr = atoi(codtab.mid(15,1)); // tipo costo_ricavo
|
||
tiporec tipo;
|
||
const TString4 tipo_aliquota = ivar.get("S1");
|
||
const TString4 tipo_iva11_acq = ivar.get("S9");
|
||
const int int_tipo_iva11_acq = atoi(tipo_iva11_acq);
|
||
const bool non_imponibile = (tipo_aliquota == "NI");
|
||
const bool esente = (tipo_aliquota == "ES");
|
||
const bool non_soggetto = (tipo_aliquota == "NS");
|
||
const bool terremotati = int_tipo_iva11_acq == 16;
|
||
real imp;
|
||
real iva;
|
||
int last_tiporec = -1;
|
||
|
||
if (classify_pim(pimr, imp, iva, tipo, true, last_tiporec, true))
|
||
{
|
||
good = true;
|
||
switch (tipo)
|
||
{
|
||
case acq_norm: // acquisti normali
|
||
if (prorata100)
|
||
{
|
||
if (aliquota.full())
|
||
add_value("VF20.1", imp);
|
||
}
|
||
else
|
||
{
|
||
if (aliquota.full())
|
||
{
|
||
const bool agricolo = ivar.get_int("I4") != 0;
|
||
|
||
if (agricolo)
|
||
{
|
||
const TString * field = (TString *) imponibile_agricolo.objptr(aliquota);
|
||
|
||
if (field != NULL) add_value(*field, imp); // VF39.1 VF48.1 Imprese agricole impobnibil e imposte
|
||
field = (TString *) imposta_agricola.objptr(aliquota);
|
||
if (field != NULL) add_value(*field, iva); // VF39.2 VF48.2 Imprese agricole impobnibil e imposte
|
||
|
||
}
|
||
else
|
||
if (agricolo_misto)
|
||
{
|
||
add_value("VF38.1", imp); // VF38.1 2 Riservato alle imprese agricole miste - Totale operazioni imponibili diverse
|
||
add_value("VF38.2", iva);
|
||
}
|
||
const TString * field = (TString *) imponibile.objptr(aliquota);
|
||
|
||
if (field != NULL) add_value(*field, imp);
|
||
field = (TString *) imposta.objptr(aliquota);
|
||
if (field != NULL) add_value(*field, iva);
|
||
if (prorataprev)
|
||
{
|
||
add_value("VF31.1", imp); // VF31.1 Acquisti destinati alle operazioni imponibili occasionali
|
||
add_value("VF31.2", iva); // VF31.1 Acquisti destinati alle operazioni imponibili occasionali
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case vend_norm: // Vendite normali
|
||
case corr_norm:
|
||
break;
|
||
case acq_simp:
|
||
break;
|
||
case vend_simp: // acq. e vend. sosp. imposta
|
||
break;
|
||
case bolle_doganali: // bolle doganali (acquisti)
|
||
break;
|
||
case acq_beni_riv : // acq. beni per riVFndita
|
||
break;
|
||
case base_ventilazione: // base calcolo per ventil.
|
||
break;
|
||
case corr_simp: // corrispettivi n. e s. imp.
|
||
break;
|
||
case acq_beni_ammort: // acq. beni ammortizz. detr.
|
||
break;
|
||
case acq_beni_ammort_nd: // beni ammort. non detraibili
|
||
break;
|
||
case acq_beni_leasing: // beni strum. acq in leasing
|
||
break;
|
||
case acq_amm_ultdetr: // beni amm. ult. detr 6%
|
||
break;
|
||
case acq_ind_op_es: // acq. indetr. su op.es.
|
||
break;
|
||
case acq_ind_pass_int: // passaggi interni
|
||
break;
|
||
case acq_ind_art_19: // indetr. art. 19
|
||
add_value("VF19.1", imp);
|
||
break;
|
||
case cess_amm: // cessioni amministrative
|
||
case vend_rimborso: // vendite valide per rimborso
|
||
break;
|
||
case acq_rimborso: // acq. validi per rimborso
|
||
break;
|
||
case acq_bd_ind_art_19: // acq. con tipo documento BD e tipo detr 9
|
||
add_value("VF20.1", imp); // *** verificare !!!!!
|
||
break;
|
||
default:
|
||
break;
|
||
|
||
};
|
||
}
|
||
else
|
||
{
|
||
imp = pimr.get_real("R0") - pimr.get_real("R9");
|
||
iva = pimr.get_real("R1") - pimr.get_real("R10");
|
||
}
|
||
if (non_imponibile)
|
||
{
|
||
if (int_tipo_iva11_acq == 12)
|
||
{
|
||
add_value("VF14.1", imp);
|
||
add_value("VF35.2", iva); // VF35.1 IVA non assolta sugli acquisti e importazioni indicati al rigo VF14
|
||
}
|
||
else
|
||
if (int_tipo_iva11_acq == 13)
|
||
add_value("VF15.1", imp);
|
||
}
|
||
if (esente)
|
||
if (int_tipo_iva11_acq == 14)
|
||
add_value("VF16.1", imp);
|
||
if (non_soggetto)
|
||
{
|
||
if (tipo_iva11_acq == "15A" || int_tipo_iva11_acq == 15)
|
||
{
|
||
if (tipo_iva11_acq == "15A")
|
||
add_value("VF17.2", imp);
|
||
add_value("VF17.1", imp);
|
||
}
|
||
}
|
||
if (terremotati)
|
||
add_value("VF18.1", imp);
|
||
|
||
}
|
||
}
|
||
|
||
real val;
|
||
real val1;
|
||
real val2;
|
||
|
||
TToken_string key; key.format("%05ld%04d", prefix().get_codditta(), year());
|
||
const TRectype& lia = cache().get("%LIA", key);
|
||
TDate data_end_cassa = lia.get_date("D1");
|
||
bool end_cassa = lia.get_bool("B5") && data_end_cassa.ok() && (data_end_cassa.month() < 12 && data_end_cassa.day() < 31);
|
||
|
||
if (!end_cassa)
|
||
{
|
||
key.format("%05ld%04d", prefix().get_codditta(), year() + 1);
|
||
const TRectype& lia1 = cache().get("%LIA", key);
|
||
|
||
end_cassa = !lia1.get_bool("B5");
|
||
}
|
||
|
||
query.zap();
|
||
const TDate da_datareg(1, 1, year());
|
||
const TDate a_datareg(31, 12, year());
|
||
|
||
// query << "USE IVADIFF KEY 2 SELECT BETWEEN(DATAREG,#DAL,#AL)";
|
||
query << "USE IVADIFF KEY 4";
|
||
if (!end_cassa)
|
||
query << "\nFROM DATAREG=" << da_datareg;
|
||
query << "\nTO DATAREG=" << a_datareg;
|
||
|
||
|
||
TISAM_recordset id(query);
|
||
TString8 tipo_aliquota, codiva;
|
||
TImporto imp211, imp212;
|
||
|
||
for (bool ok = id.move_first(); ok; ok = id.move_next())
|
||
{
|
||
const long numreg = id.get(RMI_NUMREG).as_int();
|
||
const int tipoiva = id.get(ID_TIPOIVA).as_int();
|
||
const int tipodiff = id.get(ID_TIPODIFF).as_int();
|
||
const TRectype & mov = cache().get(LF_MOV, numreg);
|
||
const char sezione = id.get(ID_SEZIONE).as_string()[0];
|
||
const int tipomov = id.get(ID_TIPOMOV).as_int();
|
||
const TImporto imp(sezione, id.get(RMI_IMPONIBILE).as_real());
|
||
const int annoliq = id.get(ID_ANNOLIQ).as_int();
|
||
const TDate datapag = id.get(ID_DATAREGP).as_date();
|
||
|
||
key.cut(0);
|
||
key.add(numreg);
|
||
key.add(id.get(ID_NUMRIG).as_string());
|
||
codiva = cache().get(LF_RMOVIVA, key, RMI_CODIVA);
|
||
key = codiva;
|
||
tipo_aliquota = cache().get("%IVA", key, "S1");
|
||
|
||
if (tipo_aliquota.blank() && datapag <= a_datareg && tipoiva == 2) // Acquists
|
||
{
|
||
imp211 += imp;
|
||
if (tipodiff == 2)
|
||
imp212 += imp;
|
||
}
|
||
}
|
||
imp211.normalize('A');
|
||
add_value("VF21.1", imp211.valore()); // VE37.1 2 iva sospensione da pagare
|
||
imp212.normalize('A');
|
||
add_value("VF21.2", imp212.valore()); // VE37.2 iva per cassa da pagare
|
||
|
||
query.zap();
|
||
|
||
query << "USE IVADIFF KEY 3";
|
||
query << "\nFROM DATAREGP=" << da_datareg;
|
||
query << "\nTO DATAREGP=" << a_datareg;
|
||
|
||
TISAM_recordset idp(query);
|
||
TImporto imp221;
|
||
|
||
for (bool ok = idp.move_first(); ok; ok = idp.move_next())
|
||
{
|
||
const long numreg = idp.get(RMI_NUMREG).as_int();
|
||
const int tipoiva = idp.get(ID_TIPOIVA).as_int();
|
||
const TRectype & mov = cache().get(LF_MOV, numreg);
|
||
const char sezione = idp.get(ID_SEZIONE).as_string()[0];
|
||
const int tipomov = idp.get(ID_TIPOMOV).as_int();
|
||
const TImporto imp(sezione, idp.get(RMI_IMPONIBILE).as_real());
|
||
const int annoliq = idp.get(ID_DATAREG).as_date().year();
|
||
const int annopag = idp.get(ID_DATAREGP).as_date().year();
|
||
|
||
key.cut(0);
|
||
key.add(numreg);
|
||
key.add(idp.get(ID_NUMRIG).as_string());
|
||
codiva = cache().get(LF_RMOVIVA, key, RMI_CODIVA);
|
||
key = codiva;
|
||
tipo_aliquota = cache().get("%IVA", key, "S1");
|
||
|
||
if (tipo_aliquota.blank() && tipoiva == 2) // Acquisti
|
||
{
|
||
if (annoliq < year() && tipomov == 3)
|
||
imp221 += imp;
|
||
}
|
||
}
|
||
imp221.normalize('D');
|
||
add_value("VF22.1", imp221.valore()); // VE22.1 iva differita pagamenti di anni precedenti
|
||
|
||
// V24.2 Variazioni e arrotondamenti d<>imposta (indicare con il segno +/<2F>)
|
||
// V50.2 Variazioni e arrotondamenti d<>imposta (indicare con il segno +/<2F>)
|
||
// VF70.2 TOTALE rettifiche (indicare con il segno +/<2F>)
|
||
|
||
query = "USE LIM\n FROM CODTAB==";
|
||
query << year() << "13\nTO CODTAB==" << year() << "13";
|
||
|
||
TISAM_recordset lim(query);
|
||
good |= lim.items() > 0;
|
||
|
||
for (lim.move_first(); !lim.eof(); lim.move_next())
|
||
{
|
||
const real var_cred = lim.get("R17").as_real();
|
||
|
||
if (var_cred < ZERO) // ???
|
||
{
|
||
add_value("VF24.2", -var_cred);
|
||
add_value("VF50.2", -var_cred);
|
||
}
|
||
add_value("VF70.2", var_cred);
|
||
}
|
||
|
||
val = evaluate_recordset_imponibile(REP_INTRA, year());
|
||
add_value("VF26.1", val);
|
||
val = evaluate_recordset_imposta(REP_INTRA, year());
|
||
add_value("VF26.2", val);
|
||
val = evaluate_recordset_imponibile(REP_IMPORTAZIONI, year());
|
||
add_value("VF26.3", val);
|
||
val = evaluate_recordset_imposta(REP_IMPORTAZIONI, year());
|
||
add_value("VF26.4", val);
|
||
val = evaluate_recordset_imponibile(REP_SANMARINO, year());
|
||
add_value("VF26.5", val);
|
||
val = evaluate_recordset_imposta(REP_SANMARINO, year());
|
||
add_value("VF24.6", val);
|
||
|
||
val = evaluate_recordset_imponibile(REP_RIPACQ, year(), "RMOVIVA.TIPOCR==2");
|
||
add_value("VF27.1", val);
|
||
val = evaluate_recordset_imponibile(REP_RIPACQ, year(), "RMOVIVA.TIPOCR==8");
|
||
add_value("VF27.2", val);
|
||
val = evaluate_recordset_imponibile(REP_RIPACQ, year(), "RMOVIVA.TIPOCR==1");
|
||
add_value("VF27.3", val);
|
||
val = evaluate_recordset_imponibile(REP_RIPACQ, year(), "(RMOVIVA.TIPOCR==0)||(RMOVIVA.TIPOCR==3)||(RMOVIVA.TIPOCR==5)||(RMOVIVA.TIPOCR==9)||(RMOVIVA.TIPOCR==17)");
|
||
add_value("VF27.4", val);
|
||
|
||
// VF32.1 Se per l<>anno 2016 sono state effettuate esclusivamente operazioni esenti barrare la casella
|
||
set_bool("VF32.1", prorata100);
|
||
// VF33.1 Se per l<>anno 2016 ha avuto effetto l<>opzione di cui all<6C>art. 36-bis barrare la casella
|
||
set_bool("VF33.1");
|
||
// VF34.1-9 Dati per il calcolo della percentuale di detrazione
|
||
|
||
// VF36.1 IVA detraibile per gli acquisti relativi all<6C>oro effettuati dai soggetti diversi dai produttori e trasformatori ai sensi dell<6C>art. 19, comma 5 bis
|
||
// VF53.2 Importo detraibile per le cessioni, anche intracomunitarie, dei prodotti agricoli di cui all<6C>art.34, primo comma, effettuate ai sensi degli articoli 8, primo comma, 38 quater e 72 ???
|
||
// VF60.1 Se le operazioni esenti effettuate sono occasionali ovvero riguardano esclusivamente operazioni di cui ai nn. da 1 a 9 dell<6C>art.10, non rientranti nell<6C>attivit<69> propria dell<6C>impresa o accessorie ad operazioni imponibili barrare la casella
|
||
set_bool("VF60.1", prorata && !prorataprev);
|
||
// VF60.2 Se le operazioni imponibili effettuate sono occasionali barrare la casella
|
||
set_bool("VF60.2", prorataprev);
|
||
// VF61.1 Se sono state effettuate cessioni occasionali di beni usati con l<>applicazione del regime del margine (d.l. n. 41/1995) barrare la casella
|
||
set_bool("VF61.1");
|
||
// VF62.1 2 Operazioni occasionali rientranti nel regime previsto dall<6C>art. 34-bis per le attivit<69> agricole connesse
|
||
}
|
||
|
||
class TQuadro_VF_app : public TQuadro_IVA_app
|
||
{
|
||
|
||
protected:
|
||
virtual char last_quadro_report() const { return 'b';}
|
||
|
||
public:
|
||
virtual TQuadro_IVA_recordset * app_recordset(const char* use, const int year) { return new TQuadro_VF_recordset(mask(), use, year); }
|
||
virtual void load_sheet(TSheet_field & sf);
|
||
|
||
TQuadro_VF_app() : TQuadro_IVA_app("Stampa Quadro VF", "cg7700a") {}
|
||
virtual ~TQuadro_VF_app() {}
|
||
|
||
};
|
||
|
||
void TQuadro_VF_app::load_sheet(TSheet_field & sf)
|
||
{
|
||
TToken_string & row1 = sf.row(sf.items()); row1.add("|1|Dichiarazione IVA Quadro VF - VF12 - VF16|cg7700c");
|
||
TToken_string & row2 = sf.row(sf.items()); row2.add("|2|Stampa importazioni|cg7700d");
|
||
TToken_string & row3 = sf.row(sf.items()); row3.add("|3|Stampa acquisti intracomunitari|cg7700e");
|
||
TToken_string & row4 = sf.row(sf.items()); row4.add("|4|Stampa cessioni verso San Marino|cg7700f");
|
||
TToken_string & row5 = sf.row(sf.items()); row5.add("|5|Ripartizione acquisti|cg7700g");
|
||
}
|
||
|
||
int cg7700(int argc, char* argv[])
|
||
{
|
||
TQuadro_VF_app a;
|
||
a.run(argc, argv, TR("Quadro VF"));
|
||
return 0;
|
||
} |