git-svn-id: svn://10.65.10.50/branches/R_10_00@23042 c028cbd2-c16b-5b4b-a496-9718f37d4682
1218 lines
31 KiB
C++
Executable File
1218 lines
31 KiB
C++
Executable File
// 77lib01.cpp
|
||
#include <dongle.h>
|
||
#include <tabutil.h>
|
||
#include <relation.h>
|
||
#include <recarray.h>
|
||
|
||
#include <anagr.h>
|
||
#include <comuni.h>
|
||
#include <nditte.h>
|
||
|
||
#include "scperc.h"
|
||
#include "perc.h"
|
||
#include "rver.h"
|
||
#include "rpag.h"
|
||
#include "quadrol.h"
|
||
#include "dipend.h" // per is_erede
|
||
#include "77lib.h"
|
||
|
||
HIDDEN TString __tmp;
|
||
HIDDEN const char* _build_key(TVersamento& vers);
|
||
HIDDEN long _codditta_770 = 0L; // La ditta corrente 770
|
||
|
||
#define QUALIF_EREDE "11"
|
||
|
||
//////////////////////////////////////////////////////////////////////////////
|
||
// Utility varie
|
||
//////////////////////////////////////////////////////////////////////////////
|
||
bool ricerca(const TMask& m)
|
||
{
|
||
return (m.mode() == MODE_QUERY) || (m.mode() == MODE_QUERYINS);
|
||
}
|
||
|
||
bool modifica(const TMask& m)
|
||
{
|
||
return m.mode() == MODE_MOD;
|
||
}
|
||
|
||
bool inserimento(const TMask& m)
|
||
{
|
||
return m.mode() == MODE_INS;
|
||
}
|
||
|
||
bool esiste_perc(char tipoa, const long codanagr)
|
||
{
|
||
// Controllo che l'anagrafica esista
|
||
TLocalisamfile anag(LF_ANAG);
|
||
anag.zero();
|
||
anag.put("TIPOA", tipoa);
|
||
anag.put("CODANAGR", (long)codanagr);
|
||
const bool esiste_anagr = anag.read() == NOERR;
|
||
return esiste_anagr;
|
||
/*
|
||
bool ok=FALSE;
|
||
TLocalisamfile fp(LF_PERC);
|
||
fp.zero();
|
||
fp.put("CODDITTA", (long)codditta);
|
||
fp.put("TIPOA", tipoa);
|
||
fp.put("CODANAGR", (long) codanag);
|
||
ok = fp.read();
|
||
return ok;*/
|
||
}
|
||
|
||
// Ritorna il codice fiscale del titolare di codditta
|
||
const char* cod_fis(const long codditta)
|
||
{
|
||
TLocalisamfile ditte(LF_NDITTE);
|
||
ditte.zero();
|
||
ditte.put("CODDITTA", (long)codditta);
|
||
int err = ditte.read();
|
||
if (err) return NULL;
|
||
const char tipoa = ditte.get("TIPOA")[0];
|
||
const long codanagr = ditte.get_long("CODANAGR");
|
||
TLocalisamfile anagr(LF_ANAG);
|
||
anagr.zero();
|
||
anagr.put(ANA_TIPOA, tipoa);
|
||
anagr.put(ANA_CODANAGR,(long)codanagr);
|
||
err = anagr.read();
|
||
if (err) return NULL;
|
||
return anagr.get(ANA_COFI);
|
||
}
|
||
|
||
const char* get_desc_cau(const char* codcau)
|
||
{
|
||
return cache().get("%CA7", codcau, "S0");
|
||
}
|
||
|
||
|
||
//
|
||
// Round_770
|
||
//
|
||
// Round adattata per 770 - 1.12.95
|
||
//
|
||
real round_770(const real& importo)
|
||
{
|
||
real imp = importo;
|
||
imp.round(); // Arrotonda all'Euro
|
||
return imp;
|
||
}
|
||
|
||
int conta_tipiper(const long codit, TString& quadro, int* NumFisiche, int* NumNoFisiche)
|
||
{
|
||
int file;
|
||
int ctrf=0, ctr_nof=0;
|
||
|
||
if (quadro == "C")
|
||
file = LF_QUAC;
|
||
|
||
if (quadro == "D")
|
||
file = LF_QUAD;
|
||
|
||
if (quadro == "D1")
|
||
file = LF_QUAD1;
|
||
|
||
if (quadro == "E")
|
||
file = LF_QUAE;
|
||
|
||
if (quadro == "E1")
|
||
file = LF_QUAE1;
|
||
|
||
if (quadro == "G")
|
||
file = LF_QUAGD;
|
||
|
||
TLocalisamfile fl(file);
|
||
fl.put("CODDITTA", (long) codit);
|
||
TRectype dep(fl.curr());
|
||
for (fl.read(); !fl.eof(); fl.next())
|
||
{
|
||
if (fl.curr() > dep)
|
||
break;
|
||
const char tipoa = fl.get("TIPOA")[0];
|
||
if (tipoa == 'F')
|
||
ctrf++;
|
||
else
|
||
ctr_nof++;
|
||
}
|
||
*NumFisiche = ctrf;
|
||
*NumNoFisiche = ctr_nof;
|
||
return 0;
|
||
}
|
||
|
||
//////////////////////////////////////////////////////////////////////////////
|
||
// Gestione ditta 770
|
||
//////////////////////////////////////////////////////////////////////////////
|
||
// Ritorna l'anno di dichiarazione sui parametri di studio
|
||
int anno_770()
|
||
{
|
||
/*
|
||
TConfig conf(CONFIG_STUDIO, "77");
|
||
const int anno = conf.get_int(ANNO_SEL, NULL, -1, TDate(TODAY).year());
|
||
return anno;
|
||
*/
|
||
return ini_get_int(CONFIG_STUDIO, "77", ANNO_SEL, TDate(TODAY).year());
|
||
}
|
||
|
||
long get_firm_770()
|
||
{
|
||
if (_codditta_770 <= 0)
|
||
{
|
||
TConfig cnf(CONFIG_USER, "77");
|
||
_codditta_770 = cnf.get_long(DITTA_770);
|
||
if (dongle().active(CGAUT))
|
||
{
|
||
const long codditta_cg = prefix().get_codditta();
|
||
if (codditta_cg != _codditta_770)
|
||
{
|
||
if (codditta_cg <= 0)
|
||
prefix().set_codditta(_codditta_770, true);
|
||
else
|
||
cnf.set(DITTA_770, _codditta_770 = codditta_cg);
|
||
}
|
||
}
|
||
}
|
||
|
||
return _codditta_770;
|
||
}
|
||
|
||
void set_firm_770(const long codditta)
|
||
{
|
||
CHECKD(codditta > 0, "Ditta non valida:", codditta);
|
||
if (_codditta_770 <= 0 || codditta != _codditta_770)
|
||
{
|
||
TConfig cnf(CONFIG_USER, "77");
|
||
cnf.set(DITTA_770, codditta);
|
||
if (dongle().active(CGAUT))
|
||
{
|
||
const long codditta_cg = prefix().get_codditta();
|
||
if (codditta_cg != codditta)
|
||
prefix().set_codditta(codditta, true);
|
||
}
|
||
}
|
||
_codditta_770 = codditta;
|
||
}
|
||
|
||
// Cerca di stabilire se il titolare della ditta e' PF o PG
|
||
char tipo_persona(long codditta)
|
||
{
|
||
const char tipoa = cache().get(LF_NDITTE, codditta, NDT_TIPOA)[0];
|
||
return tipoa >= 'F' ? tipoa : '\0';
|
||
}
|
||
|
||
// Stabilisce se coddip esiste
|
||
bool esiste_dipendente(const long codditta, const long coddip)
|
||
{
|
||
TLocalisamfile dip (LF_DIPEND);
|
||
dip.zero();
|
||
dip.put(DIP_CODDITTA, codditta);
|
||
dip.put(DIP_CODIP, coddip);
|
||
return dip.read() == NOERR;
|
||
}
|
||
|
||
// Stabilisce se coddip e' un dipendente non erede e non deceduto
|
||
bool is_dipendente(const long codditta, const long coddip)
|
||
{
|
||
return !(is_erede(codditta,coddip) || is_deceduto(codditta,coddip));
|
||
}
|
||
|
||
// Stabilisce se il dipendente e' un erede
|
||
// SE QUALIFICA=11 17.7.96
|
||
bool is_erede(const long codditta, const long coddip)
|
||
{
|
||
TLocalisamfile dip (LF_DIPEND);
|
||
TString sQualif;
|
||
dip.setkey(1);
|
||
dip.zero();
|
||
dip.put(DIP_CODDITTA, (long)codditta);
|
||
dip.put(DIP_CODIP, (long)coddip);
|
||
if (dip.read() == NOERR)
|
||
sQualif = dip.get(DIP_QUALIFICA);
|
||
sQualif.trim();
|
||
return sQualif == QUALIF_EREDE;
|
||
}
|
||
|
||
// Stabilisce se il dipendente e' un deceduto
|
||
// Se un qualunque codice erede e' stato compilato => e' un deceduto
|
||
bool is_deceduto(const long codditta, const long coddip)
|
||
{
|
||
TLocalisamfile dip(LF_DIPEND);
|
||
dip.zero();
|
||
dip.put(DIP_CODDITTA, codditta);
|
||
dip.put(DIP_CODIP, coddip);
|
||
bool ok = dip.read() == NOERR;
|
||
if (!ok) return FALSE;
|
||
for (int i=0; i < 10; i++)
|
||
{
|
||
TString campo("CODEREDE");
|
||
campo << i;
|
||
TString16 dep = dip.get(campo);
|
||
if (dep.full())
|
||
return true;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
const int MAX_EREDI = 10;
|
||
|
||
bool scrivi_erede(const long codditta, const long deceduto, const long coddip)
|
||
{
|
||
bool esiste=FALSE, trovato=FALSE;
|
||
TLocalisamfile dip (LF_DIPEND);
|
||
|
||
dip.zero();
|
||
dip.put(DIP_CODDITTA, (long)codditta);
|
||
dip.put(DIP_CODIP, (long)deceduto);
|
||
esiste = dip.read(_isequal, _lock) == NOERR;
|
||
|
||
if (!esiste) return false;
|
||
|
||
for (int i=0; i<MAX_EREDI; i++)
|
||
{
|
||
TString NomeCampo("CODEREDE");
|
||
NomeCampo << i;
|
||
TString ValCampo(dip.get(NomeCampo));
|
||
ValCampo.trim();
|
||
TString sCodErede; sCodErede << coddip;
|
||
|
||
// Se c'e' gia' non lo riscrive
|
||
if (sCodErede == ValCampo)
|
||
{
|
||
trovato = true;
|
||
break;
|
||
}
|
||
|
||
if (ValCampo.empty() || ValCampo == "0")
|
||
{
|
||
trovato = true;
|
||
dip.put(NomeCampo, sCodErede);
|
||
dip.rewrite();
|
||
break;
|
||
}
|
||
}
|
||
if (!trovato)
|
||
dip.reread(_unlock);
|
||
return trovato;
|
||
}
|
||
|
||
bool riscrivi_erede(const long codditta, const long deceduto, const long erede, const long value)
|
||
{
|
||
bool esiste=FALSE, trovato=FALSE;
|
||
TLocalisamfile dip (LF_DIPEND);
|
||
dip.put(DIP_CODDITTA, (long)codditta);
|
||
dip.put(DIP_CODIP, (long)deceduto);
|
||
esiste = dip.read(_isequal, _lock) == NOERR;
|
||
|
||
if (!esiste) return FALSE;
|
||
|
||
for (int i=0; i<MAX_EREDI; i++)
|
||
{
|
||
TString16 NomeCampo("CODEREDE");
|
||
NomeCampo << i;
|
||
TString ValCampo(dip.get(NomeCampo));
|
||
ValCampo.trim();
|
||
TString sCodErede; sCodErede << erede;
|
||
|
||
// Se c'e' gia' non lo riscrive
|
||
if (sCodErede == ValCampo)
|
||
{
|
||
trovato = TRUE;
|
||
dip.put(NomeCampo,(long)value);
|
||
dip.rewrite();
|
||
break;
|
||
}
|
||
}
|
||
if (!trovato) dip.reread(_unlock);
|
||
// return trovato; // Cosi' fallirebbe anche nel caso di un codice gia'
|
||
// cancellato (per es. azzero il codice e faccio registra due volte la seconda
|
||
// fallirebbe).
|
||
return TRUE;
|
||
}
|
||
|
||
bool esiste_pag_in_periodo(const TSchedaP& sch, const TDate& data_da, const TDate& data_a)
|
||
{ return esiste_pag_in_anno(sch, 0, data_da, data_a); }
|
||
|
||
// Determina se esiste un pagamento con annopag = anno passato come par.
|
||
// oppure se passato, sostituisce anno pagamento con anno competenza
|
||
bool esiste_pag_in_anno(const TSchedaP& sch, const int annodic, const TDate& data_da, const TDate& data_a, const int annocomp)
|
||
{
|
||
TLocalisamfile rpag(LF_RPAG);
|
||
rpag.put(PAG_CODDITTA, sch.codditta());
|
||
rpag.put(PAG_TIPOA, sch.tipoa());
|
||
rpag.put(PAG_CODANAGR, sch.codanagr());
|
||
rpag.put(PAG_NPROG, sch.nprog());
|
||
const TRectype mst(rpag.curr());
|
||
for (int err = rpag.read(_isgteq); err == NOERR; err = rpag.next())
|
||
{
|
||
if (rpag.curr() > mst)
|
||
break;
|
||
|
||
const TDate datapag = rpag.get_date(PAG_DATAPAG);
|
||
|
||
if (annodic != 0)
|
||
{
|
||
const int annopag = annocomp > 0 ? annocomp : datapag.year();
|
||
if (annopag == annodic)
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
if (datapag >= data_da && datapag <= data_a)
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
// in: tipo e codice anagrafico di cui si vuole l'indirizzo
|
||
// out: localit<69>|indirizzo|num.civico|cap|provincia
|
||
TToken_string get_anag_address(char tip_anag, long cod_anag)
|
||
{
|
||
TToken_string address;
|
||
TString cod_comune_df;
|
||
TString cod_comune_re;
|
||
TString cod_comune;
|
||
TString indirizzo;
|
||
TString numerociv;
|
||
TString cap;
|
||
TString localita;
|
||
TString provincia;
|
||
TLocalisamfile anag(LF_ANAG);
|
||
TLocalisamfile comuni(LF_COMUNI);
|
||
|
||
// lettura anagrafica persone
|
||
anag.setkey(1);
|
||
anag.zero();
|
||
anag.put(ANA_TIPOA, tip_anag);
|
||
anag.put(ANA_CODANAGR, cod_anag);
|
||
|
||
// decodifica indirizzo
|
||
if (anag.read() == NOERR)
|
||
{
|
||
cod_comune_df = anag.get(ANA_COMRF);
|
||
cod_comune_re = anag.get(ANA_COMRES);
|
||
|
||
// indicato domicilio fiscale
|
||
if (cod_comune_df != "")
|
||
{
|
||
indirizzo = anag.get(ANA_INDRF);
|
||
numerociv = anag.get(ANA_CIVRF);
|
||
cap = anag.get(ANA_CAPRF);
|
||
cod_comune= cod_comune_df;
|
||
}
|
||
|
||
// indicato residenza
|
||
else
|
||
{
|
||
indirizzo = anag.get(ANA_INDRES);
|
||
numerociv = anag.get(ANA_CIVRES);
|
||
cap = anag.get(ANA_CAPRES);
|
||
cod_comune= cod_comune_re;
|
||
}
|
||
|
||
// lettura anagrafica comuni
|
||
comuni.setkey(1);
|
||
comuni.zero();
|
||
comuni.put(COM_COM,cod_comune);
|
||
|
||
// decodifica localit<69> e provincia
|
||
if (comuni.read() == NOERR)
|
||
{
|
||
localita = comuni.get(COM_DENCOM);
|
||
provincia= comuni.get(COM_PROVCOM);
|
||
}
|
||
|
||
// preparazione token_string
|
||
address=localita;
|
||
address.add(indirizzo);
|
||
address.add(numerociv);
|
||
address.add(cap);
|
||
address.add(provincia);
|
||
}
|
||
|
||
return address;
|
||
}
|
||
//////////////////////////////////////////////////////////////////////////////
|
||
// Dichiarazioni
|
||
//////////////////////////////////////////////////////////////////////////////
|
||
//
|
||
// Controlla se esiste il record sul base. Se (dichiarante) => controlla se c'e'
|
||
// il record del quadro I "globale" di codditta (che deve essere quindi
|
||
// un dichiarante)
|
||
//
|
||
bool exist_dichiar_770(long codditta, bool dichiarante)
|
||
{
|
||
int status;
|
||
TLocalisamfile base(LF_BASE);
|
||
|
||
base.zero();
|
||
base.setkey(1);
|
||
if (dichiarante)
|
||
base.put("TIPOQUA", COD_QUA_I_DIC);
|
||
base.put("CODDITTA", (long)codditta);
|
||
status = base.read();
|
||
return status == NOERR;
|
||
}
|
||
|
||
//
|
||
// Idem come sopra. Se (sogg_dich) s'intende che voglio creare il quadro I
|
||
// "globale" per un sogg. dichiarante
|
||
//
|
||
bool enter_dichiar_770(long codditta, int anno_dic, bool sogg_dich)
|
||
{
|
||
int rc1, rc1wr, rc1rw, rc2, rc2wr, rc2rw;
|
||
TLocalisamfile base(LF_BASE);
|
||
TLocalisamfile basebis(LF_BASEBIS);
|
||
|
||
rc1wr = NOERR;
|
||
rc1rw = NOERR;
|
||
rc2wr = NOERR;
|
||
rc2rw = NOERR;
|
||
|
||
base.zero();
|
||
base.put("CODDITTA", (long)codditta);
|
||
base.put("ANNODIC", (long)anno_dic);
|
||
if (sogg_dich)
|
||
base.put("TIPOQUA", COD_QUA_I_DIC);
|
||
TRectype dep1(base.curr());
|
||
|
||
rc1 = base.read();
|
||
if (rc1 == NOERR)
|
||
rc1rw = base.rewrite();
|
||
else
|
||
{
|
||
base.curr() = dep1;
|
||
rc1wr = base.write();
|
||
}
|
||
|
||
#ifdef DBG
|
||
if (rc1wr != NOERR)
|
||
warning_box("write su base fallita codice %d", rc1wr);
|
||
if (rc1rw != NOERR)
|
||
warning_box("rewrite su base fallita codice %d", rc1rw);
|
||
#endif
|
||
|
||
// Devo scrivere anche su BASEBIS !
|
||
basebis.zero();
|
||
basebis.put("CODDITTA", (long)codditta);
|
||
if (sogg_dich)
|
||
basebis.put("TIPOQUA", COD_QUA_I_DIC);
|
||
TRectype dep2(basebis.curr());
|
||
rc2 = basebis.read();
|
||
if (rc2 == NOERR)
|
||
rc2rw = basebis.rewrite();
|
||
else
|
||
{
|
||
basebis.curr() = dep2;
|
||
rc2wr = basebis.write();
|
||
}
|
||
|
||
#ifdef DBG
|
||
if (rc2wr != NOERR)
|
||
warning_box("write su basebis fallita codice %d", rc2wr);
|
||
if (rc2rw != NOERR)
|
||
warning_box("rewrite su basebis fallita codice %d", rc2rw);
|
||
#endif
|
||
|
||
// return (rc1 == NOERR && rc2 == NOERR);
|
||
return TRUE;
|
||
}
|
||
|
||
// Ritorna numero quadri L aggiuntivi
|
||
int num_quadri_L_agg(const long codditta)
|
||
{
|
||
// numero righe su modulo base
|
||
const int rbase = 15;
|
||
|
||
// numero righe su modulo aggiuntivo
|
||
const int ragg = 27;
|
||
|
||
// filtro per cursori
|
||
TString filt;
|
||
filt.format("CODDITTA=%ld", codditta);
|
||
|
||
// istanza relazione per cursore
|
||
TRelation rl(LF_QUAL);
|
||
|
||
// istanza cursore
|
||
TCursor cl (&rl,filt,1);
|
||
|
||
// numero righe compilate
|
||
int righe = (int)cl.items();
|
||
|
||
// quadri esauriti sul modulo base
|
||
righe -= rbase;
|
||
if (righe <= 0)
|
||
return 0;
|
||
|
||
// calcola numero quadri aggiuntivi
|
||
div_t div_result;
|
||
div_result = div(righe, ragg);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
return div_result.quot;
|
||
}
|
||
|
||
// Ritorna numero quadri N,P,Q,R,S,T aggiuntivi
|
||
int num_quadri_N_agg(const long codditta)
|
||
{
|
||
// numero righe su modulo base
|
||
const int rbasen = 6;
|
||
const int rbasep = 4;
|
||
const int rbaseq = 4;
|
||
const int rbaser = 4;
|
||
const int rbases = 5;
|
||
const int rbaset = 4;
|
||
|
||
// numero righe su modulo aggiuntivo
|
||
const int raggn = 8;
|
||
const int raggp = 11;
|
||
const int raggq = 4;
|
||
const int raggr = 6;
|
||
const int raggs = 7;
|
||
const int raggt = 4;
|
||
|
||
// filtro per cursori
|
||
TString filt;
|
||
filt.format("CODDITTA=%ld", codditta);
|
||
|
||
// istanza relazioni per cursori
|
||
TRelation* rn;
|
||
rn = new TRelation (LF_QUAN);
|
||
TRelation* rp;
|
||
rp = new TRelation (LF_QUAP);
|
||
TRelation* rq;
|
||
rq = new TRelation (LF_QUAQ);
|
||
TRelation* rr;
|
||
rr = new TRelation (LF_QUAR);
|
||
TRelation* rs;
|
||
rs = new TRelation (LF_QUAS);
|
||
TRelation* rt;
|
||
rt = new TRelation (LF_QUAT);
|
||
|
||
// istanza cursori
|
||
TCursor* cn;
|
||
cn = new TCursor(rn,filt,1);
|
||
TCursor* cp;
|
||
cp = new TCursor(rp,filt,1);
|
||
TCursor* cq;
|
||
cq = new TCursor(rq,filt,1);
|
||
TCursor* cr;
|
||
cr = new TCursor(rr,filt,1);
|
||
TCursor* cs;
|
||
cs = new TCursor(rs,filt,1);
|
||
TCursor* ct;
|
||
ct = new TCursor(rt,filt,1);
|
||
|
||
// numero righe compilate
|
||
int righen = (int)cn->items();
|
||
int righep = (int)cp->items();
|
||
int righeq = (int)cq->items();
|
||
int righer = (int)cr->items();
|
||
int righes = (int)cs->items();
|
||
int righet = (int)ct->items();
|
||
|
||
// libera istanze
|
||
delete cn;
|
||
delete rn;
|
||
delete cp;
|
||
delete rp;
|
||
delete cq;
|
||
delete rq;
|
||
delete cr;
|
||
delete rr;
|
||
delete cs;
|
||
delete rs;
|
||
delete ct;
|
||
delete rt;
|
||
|
||
// quadri esauriti sul modulo base
|
||
righen -= rbasen;
|
||
righep -= rbasep;
|
||
righeq -= rbaseq;
|
||
righer -= rbaser;
|
||
righes -= rbases;
|
||
righet -= rbaset;
|
||
if (righen<=0 && righep<=0 && righeq<=0 && righer<=0 && righes<=0 && righet<=0)
|
||
return 0;
|
||
|
||
// calcola numero quadri aggiuntivi
|
||
int qagg = 0;
|
||
div_t div_result;
|
||
// quadri N
|
||
div_result = div(righen, raggn);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
if (div_result.quot > qagg)
|
||
qagg = div_result.quot;
|
||
// quadri P
|
||
div_result = div(righep, raggp);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
if (div_result.quot > qagg)
|
||
qagg = div_result.quot;
|
||
// quadri Q
|
||
div_result = div(righeq, raggq);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
if (div_result.quot > qagg)
|
||
qagg = div_result.quot;
|
||
// quadri R
|
||
div_result = div(righer, raggr);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
if (div_result.quot > qagg)
|
||
qagg = div_result.quot;
|
||
// quadri S
|
||
div_result = div(righes, raggs);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
if (div_result.quot > qagg)
|
||
qagg = div_result.quot;
|
||
// quadri T
|
||
div_result = div(righet, raggt);
|
||
if (div_result.rem)
|
||
div_result.quot++;
|
||
if (div_result.quot > qagg)
|
||
qagg = div_result.quot;
|
||
|
||
return qagg;
|
||
}
|
||
|
||
long sogg_estinto(const long codditta)
|
||
{
|
||
TLocalisamfile base(LF_BASE);
|
||
long coddic = 0L;
|
||
|
||
base.zero();
|
||
base.setkey(1);
|
||
base.put("TIPOQUA", "");
|
||
base.put("CODDITTA", (long)codditta);
|
||
const int rc = base.read();
|
||
if (rc != NOERR)
|
||
base.zero();
|
||
coddic = base.get_long("CODDIC");
|
||
return coddic;
|
||
}
|
||
|
||
bool sogg_dic(const long codditta)
|
||
{
|
||
TLocalisamfile base(LF_BASE);
|
||
|
||
base.zero();
|
||
base.setkey(2);
|
||
base.put("CODDIC", codditta);
|
||
const int rc = base.read();
|
||
if (rc == _iseof) base.zero();
|
||
const long codic = base.get_long("CODDIC");
|
||
return codic == codditta;
|
||
}
|
||
|
||
////////////////////////////////////////////////////////////////////////////
|
||
// Array sheet 'modificato'
|
||
////////////////////////////////////////////////////////////////////////////
|
||
TToken_string& TNikArray_sheet::row(int i)
|
||
{
|
||
return (TToken_string&)_interno[i];
|
||
}
|
||
|
||
long TNikArray_sheet::add(TToken_string& s)
|
||
{
|
||
_interno.add(s);
|
||
TToken_string vis(40);
|
||
for (int i = 0; i < _visible_items; i++)
|
||
{
|
||
const char* tmp = s.get(i);
|
||
vis.add(tmp);
|
||
}
|
||
|
||
return TArray_sheet::add(vis);
|
||
}
|
||
|
||
bool TNikArray_sheet::destroy(int i)
|
||
{
|
||
_interno.destroy();
|
||
return TArray_sheet::destroy(i);
|
||
}
|
||
|
||
////////////////////////////////////////////////////////////////////////////
|
||
// Collegamento CG - 770
|
||
////////////////////////////////////////////////////////////////////////////
|
||
TLink770::TLink770()
|
||
{
|
||
_tipo_coll = nessuno;
|
||
_immissione = _tipo = NULL;
|
||
_codanagr = _numreg = 0L;
|
||
_totdoc = _spese = _compenso = _imposte = _ritenute = ZERO;
|
||
}
|
||
|
||
bool TLink770::read(const char* msg)
|
||
{
|
||
TToken_string mesg(msg);
|
||
|
||
_tipo_coll = (TTipo_coll)mesg.get_int(0);
|
||
_immissione = mesg.get_char(1);
|
||
_tipo = mesg.get_char(2);
|
||
_codanagr = mesg.get_long(3);
|
||
_numreg = mesg.get_long(4);
|
||
_numdoc = mesg.get(5);
|
||
_datadoc = mesg.get(6);
|
||
_totdoc = real(mesg.get(7));
|
||
_spese = real(mesg.get(8));
|
||
_compenso = real(mesg.get(9));
|
||
_imposte = real(mesg.get(10));
|
||
_ritenute = real(mesg.get(11));
|
||
|
||
if (_tipo_coll == fattura)
|
||
if ( (_tipo != 'F' && _tipo != 'G') || _codanagr <= 0L )
|
||
return FALSE;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
TPercipiente::TPercipiente(const TRectype& rec)
|
||
{
|
||
_codditta = rec.get_long(PRC_CODDITTA);
|
||
_tipoa = rec.get(PRC_TIPOA)[0];
|
||
_codanagr = rec.get_long(PRC_CODANAGR);
|
||
}
|
||
|
||
// Determina se per il percipiente esiste almeno una scheda
|
||
bool TPercipiente::esiste_scheda()
|
||
{
|
||
TLocalisamfile sch(LF_SCPERC);
|
||
sch.zero();
|
||
sch.put(SCH_CODDITTA, _codditta);
|
||
sch.put(SCH_TIPOA, _tipoa);
|
||
sch.put(SCH_CODANAGR, _codanagr);
|
||
TRectype dep(sch.curr());
|
||
sch.read();
|
||
return sch.curr() == dep;
|
||
}
|
||
|
||
bool TPercipiente::elimina_schede()
|
||
{
|
||
TLocalisamfile sch(LF_SCPERC);
|
||
sch.zero();
|
||
sch.put(SCH_CODDITTA, codditta());
|
||
sch.put(SCH_TIPOA, tipoa());
|
||
sch.put(SCH_CODANAGR, codanagr());
|
||
TRectype dep(sch.curr());
|
||
for (sch.read(); !sch.eof(); sch.next())
|
||
{
|
||
if (sch.curr() > dep)
|
||
break;
|
||
TSchedaP scheda(sch.curr());
|
||
scheda.remove();
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
int TSchedaP::anno_doc() const
|
||
{
|
||
int anno_doc;
|
||
anno_doc = _data_doc.year();
|
||
return anno_doc;
|
||
}
|
||
|
||
real TSchedaP::compenso_doc() const
|
||
{
|
||
return _compenso_doc;
|
||
}
|
||
|
||
real TSchedaP::spese_doc() const
|
||
{
|
||
return _spese_doc;
|
||
}
|
||
|
||
|
||
int TSchedaP::remove()
|
||
{
|
||
int err1=0, err2=0;
|
||
|
||
TLocalisamfile sch(LF_SCPERC);
|
||
sch.put(SCH_CODDITTA, codditta());
|
||
sch.put(SCH_TIPOA, tipoa());
|
||
sch.put(SCH_CODANAGR, codanagr());
|
||
sch.put(SCH_NPROG, nprog());
|
||
err1 = sch.read(_isequal, _testandlock);
|
||
bool esiste = err1 == NOERR;
|
||
if (!esiste)
|
||
{
|
||
sch.reread(_unlock);
|
||
return SCHEDA_NON_ESISTENTE;
|
||
}
|
||
|
||
// Elimino i pagamenti
|
||
TLocalisamfile rpag(LF_RPAG);
|
||
rpag.put(PAG_CODDITTA, codditta());
|
||
rpag.put(PAG_TIPOA, tipoa());
|
||
rpag.put(PAG_CODANAGR, codanagr());
|
||
rpag.put(PAG_NPROG, nprog());
|
||
TRectype pagrec(rpag.curr());
|
||
for (rpag.read(_isgteq); !rpag.eof(); rpag.next())
|
||
{
|
||
if (rpag.curr() > pagrec)
|
||
break;
|
||
rpag.reread(_testandlock);
|
||
err1 = rpag.remove();
|
||
if (err1 != NOERR)
|
||
{
|
||
warning_box("Elimina righe pag. errore: %d", err1);
|
||
rpag.reread(_unlock);
|
||
break;
|
||
}
|
||
rpag.reread(_unlock);
|
||
}
|
||
|
||
// E poi i versamenti
|
||
TLocalisamfile rver(LF_RVER);
|
||
rver.put(VER_CODDITTA, codditta());
|
||
rver.put(VER_TIPOA, tipoa());
|
||
rver.put(VER_CODANAGR, codanagr());
|
||
rver.put(VER_NPROG, nprog());
|
||
TRectype verrec(rver.curr());
|
||
for (rver.read(_isgteq); !rver.eof(); rver.next())
|
||
{
|
||
if (rver.curr() > verrec)
|
||
break;
|
||
rver.reread(_testandlock);
|
||
err2 = rver.remove();
|
||
if (err2 != NOERR)
|
||
{
|
||
warning_box("Elimina righe ver. errore: %d", err2);
|
||
rver.reread(_unlock);
|
||
break;
|
||
}
|
||
rver.reread(_unlock);
|
||
}
|
||
|
||
// Alla fine se tutto e' andato bene rimuovo la testata della scheda
|
||
if (err1 == NOERR && err2 == NOERR) err1 = sch.remove();
|
||
return err1 + err2; // (NOERR e' 0)
|
||
}
|
||
|
||
bool TSchedaP::read()
|
||
{
|
||
bool ok = FALSE;
|
||
TLocalisamfile sch(LF_SCPERC);
|
||
sch.put(SCH_CODDITTA, codditta());
|
||
sch.put(SCH_TIPOA, tipoa());
|
||
sch.put(SCH_CODANAGR, codanagr());
|
||
sch.put(SCH_NPROG, nprog());
|
||
const int rc = sch.read();
|
||
ok = rc == NOERR;
|
||
if (ok)
|
||
{
|
||
_compenso_doc = sch.get_real(SCH_COMPENSO);
|
||
_spese_doc = sch.get_real(SCH_SPESE);
|
||
_data_doc = sch.get_date(SCH_DATADOC);
|
||
}
|
||
return ok;
|
||
}
|
||
|
||
TSchedaP::~TSchedaP()
|
||
{
|
||
}
|
||
|
||
TSchedaP::TSchedaP (const long codditta, const char tipoa, const long codanagr, const int nprog)
|
||
: _codditta(codditta), _tipoa(tipoa), _codanagr(codanagr), _nprog(nprog)
|
||
{
|
||
_compenso_doc = _spese_doc = ZERO;
|
||
}
|
||
|
||
TSchedaP::TSchedaP(const TRectype& rec)
|
||
{
|
||
_codditta = rec.get_long(SCH_CODDITTA);
|
||
_tipoa = rec.get_char(SCH_TIPOA);
|
||
_codanagr = rec.get_long(SCH_CODANAGR);
|
||
_nprog = rec.get_int(SCH_NPROG);
|
||
}
|
||
|
||
TVersamento::TVersamento(const TRectype& rec)
|
||
{
|
||
_codditta = rec.get_long(VER_CODDITTA);
|
||
_tipoa = rec.get_char(VER_TIPOA);
|
||
_codanagr = rec.get_long(VER_CODANAGR);
|
||
_nprog = rec.get_int(VER_NPROG);
|
||
_nriga = rec.get_int(VER_NRIGA);
|
||
}
|
||
|
||
void TVersamento::set(TToken_string& row)
|
||
{
|
||
_codditta = atol(row.get(0));
|
||
_tipoa = row.get()[0];
|
||
_codanagr = atol(row.get());
|
||
_nprog = atoi(row.get());
|
||
_nriga = atoi(row.get());
|
||
_importo_versato = real(row.get());
|
||
}
|
||
|
||
void TVersamento::set(const long codditta, const char tipoa, const long codanagr,
|
||
const int nprog, const int nriga, const real& impvers)
|
||
{
|
||
_codditta=codditta;
|
||
_tipoa=tipoa;
|
||
_codanagr=codanagr;
|
||
_nprog=nprog;
|
||
_nriga = nriga;
|
||
_importo_versato = impvers;
|
||
}
|
||
|
||
|
||
TVersamento_stampa::TVersamento_stampa(const long codditta, const char tipoa, const long codanagr, const int nprog, const int nriga, const real& impvers) :
|
||
TVersamento(codditta, tipoa, codanagr, nprog, nriga, impvers)
|
||
{
|
||
_gia_letti_pag = FALSE;
|
||
_num_last_pag = 0;
|
||
}
|
||
|
||
|
||
void TVersamento_stampa::set(const long codditta, const char tipoa, const long codanagr,
|
||
const int nprog, const int nriga, const real& impvers)
|
||
{
|
||
// se sto cambiando versamento resetto il flag "pagamenti gia' letti"
|
||
if ((_nriga && nriga != _nriga) || (_nprog && nprog != _nprog) ||
|
||
(_tipoa != '\0' && tipoa != _tipoa) || (_codditta != 0 && _codditta != codditta) ||
|
||
(_codanagr != 0 && _codanagr != codanagr) )
|
||
{
|
||
_gia_letti_pag = FALSE;
|
||
_importo_versato = ZERO;
|
||
_importo_versato_residuo = ZERO;
|
||
}
|
||
|
||
_codditta = codditta;
|
||
_tipoa = tipoa;
|
||
_codanagr = codanagr;
|
||
_nprog = nprog;
|
||
_nriga = nriga;
|
||
_importo_versato = impvers;
|
||
}
|
||
|
||
int TVersamento_stampa::num_pags(TLocalisamfile* pag)
|
||
{
|
||
if (!_gia_letti_pag)
|
||
_num_pags = read_pags(pag);
|
||
return _num_pags;
|
||
}
|
||
|
||
int TVersamento_stampa::read_pags(TLocalisamfile* frpag)
|
||
{
|
||
const bool exists = frpag == NULL;
|
||
if (!exists)
|
||
frpag = new TLocalisamfile(LF_RPAG);
|
||
|
||
TLocalisamfile& rpag = *frpag;
|
||
int ctr = 0;
|
||
const TRecnotype recno = exists ? frpag->recno() : 0L;
|
||
|
||
rpag.zero();
|
||
rpag.put(PAG_CODDITTA, (long)_codditta);
|
||
rpag.put(PAG_TIPOA, _tipoa);
|
||
rpag.put(PAG_CODANAGR, (long)_codanagr);
|
||
rpag.put(PAG_NPROG, _nprog);
|
||
TRectype mst(rpag.curr());
|
||
for (rpag.read(_isgteq); !rpag.eof(); rpag.next())
|
||
{
|
||
if (rpag.curr() > mst) break;
|
||
const int numvers = rpag.get_int(PAG_NUMVERS);
|
||
if (numvers != _nriga) continue;
|
||
const int nriga = rpag.get_int(PAG_NRIGA);
|
||
_num_last_pag = nriga;
|
||
ctr++;
|
||
}
|
||
_gia_letti_pag = true;
|
||
if (exists)
|
||
frpag->readat(recno); // ripristina la posizione prec.
|
||
else
|
||
delete frpag;
|
||
return ctr;
|
||
}
|
||
|
||
HIDDEN TVersamento __vers;
|
||
|
||
// stampa solo la quota di versamento corrispondente al pagamento
|
||
real TVersamento_stampa::vers_stampa(TLocalisamfile* rpag, const int nriga_pag,
|
||
const real& impvers, const real& ritenpag)
|
||
{
|
||
real vers_stampa = ZERO;
|
||
real vers_residuo = ZERO;
|
||
const int numpags = num_pags(rpag);
|
||
|
||
// se l'importo versato e' minore della ritenuta oppure c'e' solo un
|
||
// pagamento collegato stampo l'intera somma versata, altrimenti solo
|
||
// quella che copre la ritenuta
|
||
const bool ultimo_pagamento = numpags == 1 || last_pag(nriga_pag);
|
||
vers_stampa = ultimo_pagamento || (impvers < ritenpag) ? impvers : ritenpag;
|
||
_importo_versato_residuo = impvers - vers_stampa;
|
||
return vers_stampa;
|
||
}
|
||
|
||
HIDDEN const char* _build_key(TVersamento& vers)
|
||
{
|
||
__tmp.format("%5ld%c%5ld%d%d", vers.codditta(),vers.tipoa(),vers.codanagr(),vers.nprog(),vers.nriga());
|
||
return __tmp;
|
||
}
|
||
|
||
void TVersamento_stampa::add(TVersamento& vers)
|
||
{
|
||
TString80 key;
|
||
real dep(vers.importo_versato());
|
||
TString vvv(dep.string());
|
||
key = _build_key(vers);
|
||
_vers.add(key, vvv, TRUE);
|
||
}
|
||
|
||
bool TVersamento_stampa::find(TVersamento& vers)
|
||
{
|
||
TString80 key;
|
||
bool truovato = FALSE;
|
||
|
||
key = _build_key(vers);
|
||
truovato = _vers.is_key(key);
|
||
|
||
if (truovato)
|
||
{
|
||
TString& vvv = (TString&)_vers.find(key);
|
||
real dep(vvv);
|
||
_importo_versato_residuo = dep;
|
||
}
|
||
return truovato;
|
||
}
|
||
|
||
// overloading operatore di confronto per la struct dei pagamenti
|
||
bool Pag_struct::operator==(const Pag_struct& s) const
|
||
{
|
||
if (this->datapag != s.datapag)
|
||
return 0;
|
||
if (this->imponibile != s.imponibile)
|
||
return 0;
|
||
if (this->perc != s.perc)
|
||
return 0;
|
||
if (this->ritenuta != s.ritenuta)
|
||
return 0;
|
||
if (this->compenso != s.compenso)
|
||
return 0;
|
||
if (this->netto != s.netto)
|
||
return 0;
|
||
if (this->numvers != s.numvers)
|
||
return 0;
|
||
if (this->spesa != s.spesa)
|
||
return 0;
|
||
if (this->ctssnperc != s.ctssnperc)
|
||
return 0;
|
||
if (this->ctssncomp != s.ctssncomp)
|
||
return 0;
|
||
if (this->ritlorda != s.ritlorda)
|
||
return 0;
|
||
if (this->controbb != s.controbb)
|
||
return 0;
|
||
if (this->detfamil != s.detfamil)
|
||
return 0;
|
||
if (this->detlavdip != s.detlavdip)
|
||
return 0;
|
||
if (this->totdet != s.totdet)
|
||
return 0;
|
||
if (this->giolavdip != s.giolavdip)
|
||
return 0;
|
||
if (this->impcpa != s.impcpa)
|
||
return 0;
|
||
if (this->somregconv != s.somregconv)
|
||
return 0;
|
||
if (this->alqimp10 != s.alqimp10)
|
||
return 0;
|
||
if (this->cod10 != s.cod10)
|
||
return 0;
|
||
if (this->utpagati != s.utpagati)
|
||
return 0;
|
||
if (this->utspett != s.utspett)
|
||
return 0;
|
||
if (this->ritutpag != s.ritutpag)
|
||
return 0;
|
||
if (this->ritutspe != s.ritutspe)
|
||
return 0;
|
||
if (this->nquote != s.nquote)
|
||
return 0;
|
||
if (this->somnsrit != s.somnsrit)
|
||
return 0;
|
||
if (this->ammlordo != s.ammlordo)
|
||
return 0;
|
||
if (this->quotaprov != s.quotaprov)
|
||
return 0;
|
||
if (this->impnetto != s.impnetto)
|
||
return 0;
|
||
if (this->comnetto != s.comnetto)
|
||
return 0;
|
||
|
||
// strutture uguali
|
||
return 1;
|
||
}
|
||
|
||
// overloading operatore di assegnazione per la struct dei pagamenti
|
||
// partendo da un TRectype
|
||
Pag_struct& Pag_struct::operator=(const TRectype& rec)
|
||
{
|
||
// compila struttura con valori del record
|
||
this->datapag = rec.get_date("DATAPAG");
|
||
this->imponibile = rec.get_real("IMPONIBILE");
|
||
this->perc = rec.get_real("PERC");
|
||
this->ritenuta = rec.get_real("RITENUTA");
|
||
this->compenso = rec.get_real("COMPENSO");
|
||
this->netto = rec.get_real("NETTO");
|
||
this->numvers = rec.get_long("NUMVERS");
|
||
this->spesa = rec.get_real("SPESA");
|
||
this->ctssnperc = rec.get_real("CTSSNPERC");
|
||
this->ctssncomp = rec.get_real("CTSSNCOMP");
|
||
this->ritlorda = rec.get_real("RITLORDA");
|
||
this->controbb = rec.get_real("CONTROBB");
|
||
this->detfamil = rec.get_real("DETFAMIL");
|
||
this->detlavdip = rec.get_real("DETLAVDIP");
|
||
this->totdet = rec.get_real("TOTDET");
|
||
this->giolavdip = rec.get_int("GIOLAVDIP");
|
||
this->impcpa = rec.get_real("IMPCPA");
|
||
this->somregconv = rec.get_real("SOMREGCONV");
|
||
this->alqimp10 = rec.get_real("ALQIMP10");
|
||
this->cod10 = rec.get("COD10");
|
||
this->utpagati = rec.get_real("UTPAGATI");
|
||
this->utspett = rec.get_real("UTSPETT");
|
||
this->ritutpag = rec.get_real("RITUTPAG");
|
||
this->ritutspe = rec.get_real("RITUTSPE");
|
||
this->nquote = rec.get_real("NQUOTE");
|
||
this->somnsrit = rec.get_real("SOMNSRIT");
|
||
this->ammlordo = rec.get_real("AMMLORDO");
|
||
this->quotaprov = rec.get_real("QUOTAPROV");
|
||
this->impnetto = rec.get_real("IMPNETTO");
|
||
this->comnetto = rec.get_real(PAG_COMNETTO);
|
||
this->numreg = rec.get_long(PAG_NUMREG);
|
||
return *this;
|
||
}
|
||
|
||
// overloading operatore di assegnazione per la struct dei pagamenti
|
||
// aggiunge i valori della struttura passata
|
||
Pag_struct& Pag_struct::operator+=(const Pag_struct& s)
|
||
{
|
||
// aggiunge agli importi i valori della struttura passata
|
||
this->imponibile += s.imponibile;
|
||
this->ritenuta += s.ritenuta;
|
||
this->compenso += s.compenso;
|
||
this->netto += s.netto;
|
||
this->spesa += s.spesa;
|
||
this->ctssnperc += s.ctssnperc;
|
||
this->ctssncomp += s.ctssncomp;
|
||
this->ritlorda += s.ritlorda;
|
||
this->controbb += s.controbb;
|
||
this->detfamil += s.detfamil;
|
||
this->detlavdip += s.detlavdip;
|
||
this->totdet += s.totdet;
|
||
this->impcpa += s.impcpa;
|
||
this->somregconv += s.somregconv;
|
||
this->utpagati += s.utpagati;
|
||
this->utspett += s.utspett;
|
||
this->ritutpag += s.ritutpag;
|
||
this->ritutspe += s.ritutspe;
|
||
this->somnsrit += s.somnsrit;
|
||
this->ammlordo += s.ammlordo;
|
||
this->quotaprov += s.quotaprov;
|
||
this->impnetto += s.impnetto;
|
||
this->comnetto += s.comnetto;
|
||
|
||
return *this;
|
||
} |