campo-sirio/cg/cg4305.cpp

331 lines
7.2 KiB
C++
Executable File

// cg4306: liquidazione IVA
// funzionalita' accessorie (calcolo acconto, estrazione deleghe)
#include "cg4300.h"
#include "cg4300b.h"
#include "cg4300c.h"
static char buf[256];
// -------------------------------------------------- estrazione deleghe
bool CG4300_App::set_deleghe()
{
TMask m("cg4300b.msk");
int k = 0;
long l, j;
_calcall = FALSE;
for (;;)
{
if (k == K_ESC)
break;
if (k == K_ENTER && (_calcall || _selected.ones() > 0l))
break;
k = m.run();
// _isprint = m.get_bool(CHK_CGB_PRINT);
// _isbase = m.get_bool(CHK_CGB_BASE);
// _basecalc = (tbc)m.get_long(RDB_CGB_BASE);
switch (k)
{
case DLG_SELECT:
_selected.reset();
_ditte->destroy();
// build sheet
for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next())
{
TString cod = _nditte_r->get("CODDITTA");
TString vers = _nditte_r->get("FREQVIVA");
TToken_string d(" ");
// add record
d.add(cod);
d.add(_nditte_r->get("RAGSOC"));
d.add(vers);
_ditte->add(d);
if (_selected[l]) _ditte->check(l);
}
// scegli ditte
_ditte->run();
for (j = 0l; j < _ditte->items(); j++)
if (_ditte->checked(j)) _selected.set(j);
break;
case BUT_CGB_ALL:
_calcall = TRUE;
k = K_ENTER;
break;
}
}
if (k == K_ENTER)
{
_year = m.get(FLD_CGB_YEAR);
_month = atoi(m.get(FLD_CGB_MONTH));
}
return k == K_ENTER;
}
bool CG4300_App::extract_deleghe()
{
long firm = TApplication::get_firm();
_prind = new TProgind(_n_ditte,
" Estrazione deleghe "
"\n Preparazione archivi ",
TRUE,TRUE,40);
long l;
for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next())
{
if (_prind->iscancelled())
break;
if (!(_calcall || _selected[l])) continue;
TApplication::set_firm(_nditte->curr().get_long("CODDITTA"));
sprintf (buf,"Estrazione deleghe (%d):\nditta %s",
_month,
(const char*)_nditte_r->get("RAGSOC"));
_prind->set_text(buf);
if (is_month_ok(_month))
{
_isbenzinaro = _nditte->curr(LF_ATTIV).get_bool("ART74/4");
_freqviva = _nditte->curr().get("FREQVIVA");
bool mens = _freqviva == "M";
_isannual = (_month == 12 && !mens && !_isbenzinaro) ||
(_month == 13 && (mens || _isbenzinaro));
_isriepilogo = _month == 13;
extract_delega(_month);
}
_prind->addstatus(1);
}
TApplication::set_firm(firm);
delete _prind;
return TRUE;
}
bool CG4300_App::extract_delega(int month)
{
if (_isriepilogo && !_isannual)
return FALSE;
if (look_lim(month))
{
real topay = _lim->get_real("R0");
if (topay.sign() <= 0) return TRUE;
if (_isannual)
{
if (look_del(12,7))
{
topay -= _del->get_real("R0");
}
}
else
{
// importo rettifiche solo se non e' annuale
topay += _lim->get_real("R5");
}
if (topay.sign() > 0)
{
look_del(month, _isannual ? 2 : 1, TRUE);
_del->put("R0",topay);
_del->rewrite();
}
}
return TRUE;
}
// -------------------------------------------- calcolo acconto dicembre
bool CG4300_App::set_acconto()
{
TMask m("cg4300c.msk");
m.set(CHK_CGC_PRINT,"X");
int k = 0;
_calcall = FALSE;
_selected.reset();
long j;
for (;;)
{
if (k == K_ESC)
break;
if (k == K_ENTER && (_calcall || _selected.ones() > 0l))
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);
switch (k)
{
case DLG_SELECT:
_selected.reset();
_ditte->destroy();
// build sheet
long l;
for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next())
{
TString cod = _nditte_r->get("CODDITTA");
TString vers = _nditte_r->get("FREQVIVA");
TToken_string d(" ");
// add record
d.add(cod);
d.add(_nditte_r->get("RAGSOC"));
d.add(vers);
_ditte->add(d);
if (_selected[l]) _ditte->check(l);
}
// scegli ditte
_ditte->run();
for (j = 0l; j < _ditte->items(); j++)
if (_ditte->checked(j)) _selected.set(j);
break;
case BUT_CGC_ALL:
_calcall = TRUE;
k = K_ENTER;
break;
}
}
return k == K_ENTER;
}
bool CG4300_App::recalc_acconti()
{
long l; bool onemade = FALSE;
long firm = TApplication::get_firm();
_prind = new TProgind(_n_ditte,
" Calcolo acconto "
"\n Preparazione archivi ",
TRUE,TRUE,40);
for (l = 0l, _nditte->first(); !_nditte->eof(); l++, _nditte->next())
{
if (_prind->iscancelled())
break;
if (_calcall || _selected[l])
{
if (onemade == FALSE && _isprint)
{
_DescrItem* d = new _DescrItem(ACCHEAD);
d->_f0 = _basecalc == incorso;
d->_f1 = _isbase;
_descr_arr.add(d);
}
TApplication::set_firm(_nditte->curr().get_long("CODDITTA"));
sprintf (buf,"Calcolo acconto:\nditta %s",
(const char*)_nditte_r->get("RAGSOC"));
_prind->set_text(buf);
recalc_acconto();
onemade = TRUE;
}
_prind->addstatus(1);
}
TApplication::set_firm(firm);
delete _prind;
return TRUE;
}
bool CG4300_App::recalc_acconto()
{
real basecalcolo, acconto;
bool isdifferita = FALSE;
bool error = FALSE;
// this is absolutely fundamental
if (_basecalc == incorso)
{
// that's pazzesc but it turns out there's no better way
_comp_acconto = TRUE;
// force recalc of current month
_recalc = one;
update_firm(12);
// TBI calcola l'acconto!!!
if (look_lim(12))
{
basecalcolo = _lim->get_real("R0");
if (basecalcolo.sign() > 0)
acconto = basecalcolo * ACCONTO_DICEMBRE;
}
else
{
acconto = real(-1);
}
// riaggiustati le palle
_comp_acconto = FALSE;
update_firm(12);
}
else if (_basecalc == precedente)
{
int yr = atoi(_year) - 1;
_lim->zero();
*_lim_anno = yr;
*_lim_mese = 12;
if (_lim->read() == NOERR)
{
basecalcolo = _lim->get_real("R0");
if (basecalcolo.sign() > 0)
acconto = basecalcolo * ACCONTO_DICEMBRE;
}
else error = TRUE;
}
// sbatti l'acconto in LIA
if (look_lia())
{
_lia->put("R4",acconto);
isdifferita = _lia->get_bool("B1");
_lia->rewrite();
}
if (acconto.sign() > 0)
{
// crea o aggiorna delega
look_del(12,7,TRUE);
_del->put("R0", acconto);
_del->rewrite();
}
// per questa volta lasciamo perdere la describe_acconto
if (_isprint)
{
_DescrItem* d = new _DescrItem(ACCONTO);
d->_r0 = basecalcolo;
d->_r1 = acconto;
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;
}