campo-sirio/src/cg/cg4305.cpp
bonazzi 380ea39b1e Patch level : 12.0 310 316
Files correlati     : cg0.exe cg4.exe cg4300a.msk

Eliminate le richieste di ricalcolo della liquidazione.
Aggiunto il flag di definitiva modificabile dalla liquidazione.
Due campi nuovi in liquidazione Calcola e Definitiva impostati dai flags sul mese.
Da verificare, visto che le richieste erano molte (potrebbero esserne sfuggite), progressivi IVA, Liquidazione, Stampa registri e Visualizzazione liquidazione.

git-svn-id: svn://10.65.10.50/branches/R_10_00@23462 c028cbd2-c16b-5b4b-a496-9718f37d4682
2016-12-18 22:20:47 +00:00

532 lines
14 KiB
C++
Executable File
Raw Blame History

// cg4305: liquidazione IVA
// funzionalita' accessorie (calcolo acconto, estrazione deleghe)
#include <currency.h>
#include <defmask.h>
#include <recarray.h>
#include <progind.h>
#include <prefix.h>
#include <sheet.h>
#include <utility.h>
#include <config.h>
#include <righef24.h>
#include <modaut.h>
#include "cg4300.h"
#include "cg4300b.h"
#include "cg4300c.h"
#include "cg4800b.h"
void TLiquidazione_app::extract_f24(int month)
{
if (main_app().has_module(GVAUT))
{
bool versare = false;
const TRectype & lim = get_lim(month);
if (lim.full())
{
real topay = result_liq(month); // TBC non si puo' fa' accussi'!!!!! pena il casino!
if (month == 12)
versare = topay > _ver->get(I_ANNUALE);
else
versare = topay > _ver->get(I_PERIODICO);
real intr = lim.get_real("R14");
topay += intr; // lo vogliono registrato con interessi
real nrnd = topay;
round_imposta(topay); // importo totale del versamento arrotondato
TLocalisamfile f24(LF_RIGHEF24);
TTable trib("%TRB");
long progr = 0L;
const bool mensile = _freqviva == "M";
const int codtrib = mensile ? 6000 + month : 6031 + (month / 3);
TString descr("IVA ANNUALE");
TDate scad(16, (mensile ? month : ((month + 2) / 3) * 3), atoi(_year));
const long codditta = _nditte->lfile().get_long("CODDITTA");
if (month < 13)
scad.addmonth(mensile ? 1 : 2);
while (scad.wday() > 5)
++scad;
if (month < 13)
{
if (mensile)
descr.format("IVA mese di %s %s", itom(month), (const char *)_year);
else
descr.format("IVA %s Trimestre %s", itor(month / 3 + 1), (const char *)_year);
}
trib.put("CODTAB", codtrib);
if (trib.read() == NOERR)
{
f24.setkey(4);
f24.put(F24_TIPOINTEST, "D");
f24.put(F24_INTEST, codditta);
f24.put(F24_ANNO, _year);
f24.put(F24_TRIBUTO, codtrib);
if (f24.read() == NOERR)
{
if (f24.get(F24_DATAVERS).blank())
{
f24.put(F24_IMPORTODEB, topay);
f24.put(F24_INTIVATRIM, intr);
f24.put(F24_DATASCAD, scad);
const int err = f24.rewrite();
if (err != NOERR)
error_box(FR("Ditta %ld\n%s\nerrore %d"), codditta, (const char *) descr, err);
}
}
else
{
f24.setkey(1);
if (f24.last() == NOERR)
progr = f24.get_long(F24_PROGR);
progr++;
f24.zero();
f24.put(F24_PROGR, progr);
f24.put(F24_TRIBUTO, codtrib);
f24.put(F24_TIPOINTEST, "D");
f24.put(F24_INTEST, codditta);
f24.put(F24_DESCR, descr);
f24.put(F24_DATASCAD, scad);
f24.put(F24_ANNO, _year);
f24.put(F24_IMPORTODEB, topay);
f24.put(F24_INTIVATRIM, intr);
const int err = f24.write();
if (err != NOERR)
error_box(FR("Ditta %ld\n%s\nerrore %d"), codditta, (const char *) descr, err);
}
}
}
}
}
// -------------------------------------------- calcolo acconto dicembre
bool TLiquidazione_app::set_acconto(real& inf, real& ina)
{
TMask m("cg4300c");
m.set(CHK_CGC_PRINT,"X");
m.field(FLD_CGC_YEAR).set_handler(ch_year_handler);
m.field(FLD_CGC_YEAR).set(_year);
int k = 0; long j;
_calcall = FALSE;
for (;;)
{
if (k == K_ESC || k == K_ENTER || k == K_QUIT)
break;
k = m.run();
_year = m.get(FLD_CGC_YEAR);
_isprint = m.get_bool(CHK_CGC_PRINT);
_isbase = m.get_bool(CHK_CGC_BASE);
_basecalc = (tbc)m.get_long(RDB_CGC_BASE);
inf = ina = ZERO;
switch (k)
{
case DLG_SELECT:
// scegli ditte
_ditte->run();
for (j = 0l; j < _ditte->items(); j++)
if (_ditte->checked(j)) _selected.set(j);
break;
case BUT_CGC_ALL:
_ditte->check(-1);
for (j = 0l; j < _ditte->items(); j++)
if (_ditte->checked(j) && !_ditte->row_disabled(j))
_selected.set(j);
_calcall = TRUE;
k = K_ENTER;
break;
}
}
return k == K_ENTER;
}
bool TLiquidazione_app::recalc_acconti(real& inf, real& ina)
{
TString buf(256);
bool onemade = FALSE;
const long firm = TApplication::get_firm();
_prind = new TProgind(_n_ditte,
TR(" Calcolo acconto "
"\n Preparazione archivi "
"\n "),
TRUE,TRUE);
if (_ver->read(atoi(_year),(_month > 12) ? 12 : _month) != NOERR)
warning_box(FR("Errore %d in lettura tabella versamenti ed interessi."),_ver->status());
for (int l = 0; l < _ditte->items(); l++)
{
if (_prind->iscancelled())
break;
if ((_calcall || _selected[l]) && !_ditte->row_disabled(l))
{
if (onemade == FALSE && _isprint)
{
_DescrItem* d = new _DescrItem(ACCHEAD);
d->_f0 = _basecalc == incorso;
d->_f1 = _isbase;
_descr_arr.add(d);
}
_nditte->curr().zero();
_nditte->curr().put("CODDITTA",_ditte->row(l).get(1));
_nditte->read();
const long ditta = _nditte->curr().get_long("CODDITTA");
TApplication::set_firm(ditta);
TIva_round ir;
ir.set_default_iva_mode(atoi(_year), _month > 12, ditta);
_isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74_4");
const TRectype & lia = get_lia();
_freqviva = lia.get("S7");
inf = lia.get_real("R13");
ina = lia.get_real("R14");
buf.format(FR("Calcolo acconto:\nditta %s"),
(const char*)_nditte_r->get("RAGSOC"));
_prind->set_text(buf);
recalc_acconto(inf, ina);
onemade = TRUE;
}
extract_f24(_month);
_prind->addstatus(1);
}
TApplication::set_firm(firm);
delete _prind;
return TRUE;
}
bool TLiquidazione_app::recalc_acconto(real& inf, real& ina)
{
real bc = 0.0;
real acc = 0.0;
real cre = 0.0;
real deb = 0.0;
real iva_ven = 0.0;
real iva_acq = 0.0;
real iva_ret = 0.0;
real iva_rim = 0.0;
real ult_det = 0.0;
real iva_pro = 0.0;
real cre_pre = 0.0;
real acq_intr = 0.0;
const bool isdifferita = is_acconto_differito(); // MI3262...
int error = FALSE;
TString16 tipo_acc;
// TBI rewrite from scratch
// this is absolutely fundamental
if (_basecalc == precedente)
{
// determina casistica
enum { mm, tt, mt, tm, boh } history = boh;
real divide_by_three = 1.0;
const char thh = *_freqviva;
const TString4 thyear = _year;
_year.format("%d", atoi(_year)-1);
const TRectype & lia = get_lia();
if (lia.empty())
error = 3;
else
{
char ohh = lia.get_char("S7");
if (ohh == 'M') history = thh == 'M' ? mm : mt;
if (ohh == 'T') history = thh == 'M' ? tm : tt;
if (history == boh)
{
_year = thyear;
return FALSE;
}
// casino benzinari
TString attprev = _nditte->curr().get("CODATTPREV");
long codd = _nditte->curr().get_long("CODDITTA");
TString16 key;
key.format("%ld|%s", codd, (const char *) attprev);
const TRectype & atts = cache().get(LF_ATTIV, key);
if (atts.get_bool("ART74_4")) // e' proprio un gran benzinaro
history = lia.get_bool("B4") ? mm : tt; // Was CNF_DITTA->GesT74
switch (history)
{
case mm:
{
// base calcolo: 12a anno preced, Rideterminare a seconda dell'acconto
// versato; ris = 88% del debito (0 se credito
const TRectype & lim = get_lim(12);
if (lim.empty())
error = 2;
else
{
bc += lim.get_real("R0");
const real av = lim.get_real("R11");
bc += av;
}
}
break;
case tt:
case tm:
{
// base calcolo: 13a anno precedente. Rideterm. per eventuale acconto
const TRectype & lim = get_lim(13); // TBC sara' 13a davvero? Secondo me e' 12
if (lim.empty())
error = 2;
else
{
bc += lim.get_real("R0");
const real av = lim.get_real("R11");
bc += av;
}
if (history == tm)
// tm come tt ma si divide per 3 la base di calcolo prima di calcolare l'88%
divide_by_three = 3.0;
}
break;
case mt:
{
// basecalcolo: 10, 11, 12 anno prec., 10 e 11 se a debito, 12 vedi acconto;
// sommare e prendi 88% se a debito
const TRectype & lim10 = get_lim(10);
const TRectype & lim11 = get_lim(11);
const TRectype & lim12 = get_lim(12);
if (lim10.empty())
error = 2;
else
{
const real app = lim10.get_real("R0");
if (app > ZERO) //a debito
bc += app;
}
if (lim11.empty())
error = 2;
else
{
const real app = lim11.get_real("R0");
if (app > ZERO) //a debito
bc += app;
}
if (lim12.empty())
error = 2;
else
{
bc += lim12.get_real("R0");
const real av = lim12.get_real("R11");
bc += av;
}
}
break;
}
round_imposta(bc);
if (bc > ZERO) //debito
{
acc = ((bc / divide_by_three) * _ver->get(isdifferita ? B_LIQ_DIFF : B_LIQ_NORM)) / CENTO;
acc.round(TCurrency::get_firm_dec());
}
tipo_acc = "S";
}
_year = thyear;
}
else
if (_basecalc == incorso)
{
// that's pazzesc but as it turns out there's no better way
_comp_acconto = TRUE;
// force recalc of current month
_recalc = one;
/* int need_refresh = FALSE;
for (int mese = 1; mese < _month; mese++)
if (is_month_ok_strict(mese))
{
const TRectype & lim = get_lim(mese);
if (lim.empty() || !lim.get_bool("B0"))
{
need_refresh = true;
break;
}
}
if (need_refresh && yesno_box(FR("Alcuni mesi precedenti non risultano ricalcolati:\n"
"<22> consigliabile il ricalcolo. Si desidera eseguirlo?")))
_recalc = ever;
for (int m = 1; m <= _month; m++)
if (is_month_plain(m) || _recalc == ever)
{
if (_prind->iscancelled())
break;
update_firm(m);
} */
if (is_month_plain(_month) && !_prind->iscancelled())
update_firm(_month, _recalc == one);
// calcola l'acconto
TRectype lim = get_lim(12);
if (lim.not_empty())
{
cre = lim.get_real("R12");
cre -= lim.get_real("R19");
deb = lim.get_real("R13") + inf + ina;
deb -= lim.get_real("R18"); // CM600446
deb -= lim.get_real("R1"); // CM600446
if (lim.get_real("R17") > ZERO)
deb -= lim.get_real("R17");
else
cre += lim.get_real("R17");
bc = deb - cre;
if (bc > ZERO)
acc = bc;
look_lam(12); //posiziona anche la tabella lam
iva_ven = _lam->get_real("R0"); //iva sulle vendite annotate fino al 20/12
iva_acq = _lam->get_real("R1"); //iva sugli acquisti annotati fino al 20/12
cre_pre = _lam->get_real("R2"); //credito precedente
iva_ret = lim.get_real("R5"); //rettifica
iva_rim = lim.get_real("R1"); //iva chiesta a rimborso
ult_det = lim.get_real("R6"); //ulteriori detrazioni
//iva_pro: //iva relativa alla percentuale di prorata
TTable plm ("PLM");
plm.zero();
plm.put("CODTAB",_year);
TRectype rec (plm.curr());
plm.read(_isgteq);
for (; !plm.eof(); plm.next())
{
if (plm.curr() != rec) break;
iva_pro += plm.get_real("R2");
}
//acq_intr
TTable pom ("POM");
pom.zero();
pom.put("CODTAB",_year);
rec = pom.curr();
pom.read(_isgteq);
for (; !pom.eof(); pom.next())
{
if (pom.curr() != rec) break;
acq_intr += pom.get_real("R0");
}
tipo_acc = "A"; //flag per dire che si e' utilizzato il metodo analitico
//stop
}
else error = 1;
// pulisci il water
_comp_acconto = FALSE;
_isprint = FALSE;
/* for (int i = 1; i <= _month; i++)
if (is_month_plain(i))
update_firm(i);
lim.put("B0","");
// put_lim(lim);
// lim = get_lim(13);
// if (lim.not_empty())
{
lim.put("B0","");
put_lim(lim);
}
*/
if (is_month_plain(_month))
update_firm(_month, _recalc == one);
//fine
_isprint = true;
}
// sbatti l'acconto (e non solo!) in LIA
TRectype lia = get_lia();
if (lia.not_empty())
{
if (isdifferita && _basecalc == incorso)
{
acc *= real(2.0);
acc /= real(3.0);
}
lia.put("R4",acc);
lia.put("R7",iva_ven);
lia.put("R8",iva_acq);
lia.put("R9",iva_ret);
lia.put("R10",iva_rim);
lia.put("R11",ult_det);
lia.put("R12",iva_pro);
TToken_string rr("",'!');
rr.add(cre_pre.string(),0);
rr.add(acq_intr.string(),1);
lia.put("S1",rr);
lia.put("S8",tipo_acc);
put_lia(lia);
}
// per questa volta lasciamo perdere la describe_acconto
if (_isprint)
{
// segnalazioni di errore da gesticolare:
// error = 0: no error
// error = 1: manca tabella risultati liquidazione per l'anno indicato
// error = 2: manca tabella risultati liquidazione per l'anno precedente
// error = 3: manca tabella dichiarazione annuale per l'anno precedente
_DescrItem* d = new _DescrItem(ACCONTO);
d->_r0 = bc;
d->_r1 = acc;
d->_r2 = cre;
d->_r3 = deb;
d->_f0 = _basecalc == incorso;
d->_f1 = _isbase;
d->_f2 = error;
d->_f3 = isdifferita;
d->_s0 = _nditte->curr().get("CODDITTA");
d->_s1 = _nditte->curr().get("RAGSOC");
_descr_arr.add(d);
}
return TRUE;
}