1997-06-19 14:33:52 +00:00
|
|
|
// Esercizi contabili e registri IVA
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
#include <mask.h>
|
|
|
|
#include <prefix.h>
|
|
|
|
#include <tabutil.h>
|
|
|
|
#include <utility.h>
|
1996-11-29 14:58:01 +00:00
|
|
|
|
1998-05-04 07:43:58 +00:00
|
|
|
#include <pconti.h>
|
|
|
|
#include <rmov.h>
|
|
|
|
#include <rmoviva.h>
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
#include "cglib01.h"
|
1995-07-21 10:12:15 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
1997-06-19 14:33:52 +00:00
|
|
|
// Gestione Tabella esercizi
|
1995-07-21 10:12:15 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TArray TEsercizi_contabili::_esercizi;
|
|
|
|
long TEsercizi_contabili::_firm = 0;
|
|
|
|
|
|
|
|
TEsercizio::TEsercizio(const TRectype& rec)
|
|
|
|
{
|
|
|
|
_codice = rec.get_int("CODTAB");
|
|
|
|
_inizio = rec.get("D0");
|
|
|
|
_fine = rec.get("D1");
|
|
|
|
_scarico = rec.get("D2");
|
|
|
|
_chiusura = rec.get("D3");
|
|
|
|
_chiusura_mag = rec.get("D4");
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizio::compare(const TSortable& s) const
|
|
|
|
{
|
|
|
|
const TEsercizio& e = (const TEsercizio&)s;
|
|
|
|
int c = 0;
|
|
|
|
if (_inizio != e._inizio)
|
|
|
|
c = _inizio > e._inizio ? +1 : -1;
|
|
|
|
return c;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TEsercizi_contabili::TEsercizi_contabili()
|
1996-11-29 14:58:01 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TEsercizi_contabili::update()
|
|
|
|
{
|
|
|
|
_firm = prefix().get_codditta();
|
|
|
|
|
|
|
|
_esercizi.destroy();
|
|
|
|
TTable tab_esc("ESC");
|
|
|
|
for (int err = tab_esc.first(); err == NOERR; err = tab_esc.next())
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
TEsercizio* e = new TEsercizio(tab_esc.curr());
|
|
|
|
_esercizi.add(e);
|
|
|
|
}
|
|
|
|
_esercizi.sort();
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
void TEsercizi_contabili::check()
|
|
|
|
{
|
|
|
|
if (_firm != prefix().get_codditta())
|
|
|
|
{
|
|
|
|
#ifdef DBG
|
|
|
|
if (_firm != 0)
|
|
|
|
error_box("Questo programma carinissimo usa gli esercizi,\n"
|
|
|
|
"purtroppo non tiene conto del cambio ditta!");
|
|
|
|
#endif
|
|
|
|
update();
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::date2index(const TDate& d) const
|
|
|
|
{
|
|
|
|
check();
|
|
|
|
for (int i = items()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
const TEsercizio& e = esc(i);
|
|
|
|
if (d >= e.inizio() && d <= e.fine())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::esc2index(int codice) const
|
|
|
|
{
|
|
|
|
check();
|
|
|
|
for (int i = items()-1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
const TEsercizio& e = esc(i);
|
|
|
|
if (codice == e.codice())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::date2esc(const TDate& d) const
|
|
|
|
{
|
|
|
|
const int i = date2index(d);
|
|
|
|
return i >= 0 ? esc(i).codice() : 0;
|
|
|
|
}
|
1996-11-29 14:58:01 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::first() const
|
|
|
|
{
|
|
|
|
check();
|
|
|
|
return items() ? esc(0).codice() : 0;
|
|
|
|
}
|
1996-11-29 14:58:01 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::last() const
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
check();
|
|
|
|
return items() ? esc(items()-1).codice() : 0;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::pred(int codice) const
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
const int i = esc2index(codice);
|
|
|
|
return i > 0 ? esc(i-1).codice() : 0;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TEsercizi_contabili::next(int anno) const
|
|
|
|
{
|
|
|
|
const int i = esc2index(anno);
|
|
|
|
return i < items()-1 ? esc(i+1).codice() : 0;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
bool TEsercizi_contabili::exist(int codice) const
|
|
|
|
{
|
|
|
|
const int i = esc2index(codice);
|
|
|
|
return i >= 0;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
const TEsercizio& TEsercizi_contabili::esercizio(int codice) const
|
|
|
|
{
|
|
|
|
const int i = esc2index(codice);
|
|
|
|
return esc(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* iva2name(TipoIVA iva)
|
|
|
|
{
|
|
|
|
const char* i;
|
|
|
|
switch(iva)
|
|
|
|
{
|
|
|
|
case nessuna_iva:
|
|
|
|
i = "Nessuna IVA"; break;
|
|
|
|
case iva_acquisti:
|
|
|
|
i = "IVA Acquisti"; break;
|
|
|
|
case iva_vendite:
|
|
|
|
i = "IVA Vendite"; break;
|
|
|
|
case iva_generica:
|
|
|
|
i = "IVA Generica"; break;
|
|
|
|
default:
|
|
|
|
i = "IVA ERRATA!"; break;
|
|
|
|
}
|
|
|
|
return i;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1996-11-29 14:58:01 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
1997-06-19 14:33:52 +00:00
|
|
|
// Registro
|
1996-11-29 14:58:01 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
1998-05-04 07:43:58 +00:00
|
|
|
TRegistro::TRegistro(const char* cod, int year)
|
|
|
|
: _rec(LF_TAB), _att(LF_ATTIV)
|
1997-06-19 14:33:52 +00:00
|
|
|
{
|
|
|
|
read(cod, year);
|
|
|
|
}
|
1996-11-29 14:58:01 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
bool TRegistro::read(const char* cod, int year)
|
|
|
|
{
|
|
|
|
if (year <= 0)
|
|
|
|
{
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
year = oggi.year();
|
|
|
|
}
|
1996-05-20 09:26:39 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int err = ~NOERR;
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TTable reg("REG");
|
|
|
|
reg.setkey(1);
|
|
|
|
if (cod && *cod > ' ')
|
|
|
|
{
|
|
|
|
TString16 chiave; chiave.format("%04d%s", year, cod);
|
|
|
|
reg.put("CODTAB", chiave);
|
|
|
|
err = reg.read();
|
|
|
|
}
|
|
|
|
_rec = reg.curr();
|
1996-10-07 15:12:27 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
if (err != NOERR)
|
|
|
|
_rec.zero();
|
|
|
|
read_att();
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
return err == NOERR;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
bool TRegistro::reread()
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
if (ok())
|
|
|
|
{
|
|
|
|
const TString16 n(name());
|
|
|
|
const int y = year();
|
|
|
|
return read(n, y);
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
1997-06-19 14:33:52 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TRegistro::year() const
|
|
|
|
{
|
|
|
|
TString16 anno(_rec.get("CODTAB"));
|
|
|
|
anno.cut(4);
|
|
|
|
return atoi(anno);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const TString& TRegistro::name() const
|
|
|
|
{
|
|
|
|
return _rec.get("CODTAB").mid(4);
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
|
|
|
|
TRegistro& TRegistro::operator =(const TRegistro& r)
|
|
|
|
{
|
|
|
|
_rec = r._rec;
|
|
|
|
_att = r._att;
|
|
|
|
_prorata = r._prorata;
|
|
|
|
return *this;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
|
|
|
|
int TRegistro::tipo() const
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
const int t = _rec.get_int("I0");
|
|
|
|
return t;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
|
|
|
|
bool TRegistro::corrispettivi() const
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
const bool c = _rec.get_bool("B0");
|
|
|
|
return c;
|
|
|
|
}
|
1996-11-29 14:58:01 +00:00
|
|
|
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TipoIVA TRegistro::iva() const
|
|
|
|
{
|
|
|
|
TipoIVA i = (TipoIVA)tipo();
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case nessuna_iva:
|
|
|
|
case iva_vendite:
|
|
|
|
case iva_acquisti:
|
|
|
|
break;
|
|
|
|
case libro_giornale:
|
|
|
|
i = nessuna_iva;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error_box("Il registro '%s' non e' un registro IVA o contabile: tipo %d",
|
|
|
|
(const char*)name(), i);
|
|
|
|
i = nessuna_iva;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
bool TRegistro::read_att()
|
|
|
|
{
|
|
|
|
if (!_att.empty())
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
TLocalisamfile attiv(LF_ATTIV);
|
|
|
|
attiv.setkey(1);
|
|
|
|
attiv.put("CODDITTA", prefix().get_codditta());
|
|
|
|
attiv.put("CODATT", attivita());
|
|
|
|
const int err = attiv.read();
|
|
|
|
_att = attiv.curr();
|
|
|
|
if (err != NOERR)
|
|
|
|
_att.zero();
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TString16 chiave; // Ditta - Anno - Attivita' - Tipo Attivita' (fissata a 1)
|
|
|
|
chiave.format("%05ld", prefix().get_codditta());
|
|
|
|
chiave << year(); // non fare << year() << attivita()
|
|
|
|
chiave << attivita() << "1";
|
1997-12-24 09:40:34 +00:00
|
|
|
|
|
|
|
_prorata.destroy();
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TTable pla("%PLA");
|
|
|
|
pla.put("CODTAB", chiave);
|
|
|
|
if (pla.read() == NOERR)
|
|
|
|
{
|
1997-12-24 09:40:34 +00:00
|
|
|
chiave.format("%d", year());
|
|
|
|
_prorata.add(chiave, pla.get_real("R8"));
|
1997-06-19 14:33:52 +00:00
|
|
|
_att.put("TIPOATT", pla.get("S7")); // Aggiorna tipo attivita'
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
return err == NOERR;
|
|
|
|
}
|
1996-11-29 14:58:01 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
bool TRegistro::agenzia_viaggi()
|
|
|
|
{
|
|
|
|
bool av = FALSE;
|
|
|
|
if (iva() == iva_vendite)
|
|
|
|
av = _att.get_bool("REG74TER");
|
|
|
|
return av;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
const TString& TRegistro::tipo_attivita()
|
|
|
|
{
|
|
|
|
return _att.get("TIPOATT");
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-12-24 09:40:34 +00:00
|
|
|
real* TRegistro::read_prorata(int anno) const
|
|
|
|
{
|
|
|
|
TString16 chiave; // Ditta - Anno - Attivita' - Tipo Attivita' (fissata a 1)
|
|
|
|
chiave.format("%05ld", prefix().get_codditta());
|
|
|
|
chiave << anno << attivita() << "1";
|
|
|
|
|
|
|
|
TTable pla("%PLA");
|
|
|
|
pla.put("CODTAB", chiave);
|
|
|
|
|
|
|
|
real* prorata = NULL;
|
|
|
|
const int err = pla.read();
|
|
|
|
if (err == NOERR)
|
|
|
|
prorata = new real(pla.get("R8"));
|
|
|
|
return prorata;
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
1996-11-29 14:58:01 +00:00
|
|
|
|
1997-12-24 09:40:34 +00:00
|
|
|
real TRegistro::prorata(int annodoc)
|
|
|
|
{
|
|
|
|
const int annoiva = year();
|
1998-04-30 15:59:34 +00:00
|
|
|
const int annopro = (annoiva < 1998 || annodoc < 1900) ? annoiva : annodoc;
|
1997-12-24 09:40:34 +00:00
|
|
|
|
|
|
|
TString16 chiave; chiave << annopro;
|
|
|
|
real* pr = (real*)_prorata.objptr(chiave);
|
|
|
|
|
|
|
|
if (pr == NULL)
|
|
|
|
{
|
|
|
|
pr = read_prorata(annopro);
|
|
|
|
if (pr == NULL && annopro != annoiva)
|
1998-04-30 15:59:34 +00:00
|
|
|
{
|
1998-05-04 07:43:58 +00:00
|
|
|
// warning_box("Non esistono i dati relativi al prorata per il %d:\n"
|
|
|
|
// "verra' considerato l'anno %d", annopro, annoiva);
|
|
|
|
pr = read_prorata(annoiva);
|
1998-04-30 15:59:34 +00:00
|
|
|
}
|
1997-12-24 09:40:34 +00:00
|
|
|
if (pr == NULL)
|
1998-04-30 15:59:34 +00:00
|
|
|
{
|
1998-05-04 07:43:58 +00:00
|
|
|
// warning_box("Non esistono i dati relativi al prorata per il %d:\n"
|
|
|
|
// "verra' considerato allo 0%%", annoiva);
|
|
|
|
pr = new real(ZERO);
|
1998-04-30 15:59:34 +00:00
|
|
|
}
|
1997-12-24 09:40:34 +00:00
|
|
|
_prorata.add(chiave, pr, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return *pr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TRegistro::set_prorata(int annodoc, const real& pro)
|
|
|
|
{
|
|
|
|
int annoiva = year();
|
1998-05-04 07:43:58 +00:00
|
|
|
int annopro = (annoiva < 1998 || annodoc <= 0) ? annoiva : annodoc;
|
1997-12-24 09:40:34 +00:00
|
|
|
TString16 chiave; chiave << annopro;
|
|
|
|
_prorata.add(chiave, pro, TRUE);
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Certified 99%
|
|
|
|
bool TRegistro::update(long protiva, const TDate& datareg)
|
|
|
|
{
|
|
|
|
bool updated = TRUE;
|
|
|
|
|
|
|
|
if (protiva > _rec.get_long("I5"))
|
|
|
|
{
|
|
|
|
_rec.put("I5", protiva);
|
|
|
|
updated = FALSE;
|
|
|
|
}
|
|
|
|
if (datareg > _rec.get_date("D2"))
|
|
|
|
{
|
|
|
|
_rec.put("D2", datareg);
|
|
|
|
updated = FALSE;
|
|
|
|
}
|
|
|
|
if (!updated)
|
|
|
|
{
|
|
|
|
TTable reg("REG");
|
|
|
|
updated = reg.rewrite(_rec) == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return updated;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Libro giornale
|
|
|
|
///////////////////////////////////////////////////////////
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
// Legge il libro giornale dell'anno specificato
|
|
|
|
bool TLibro_giornale::read(int y)
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
bool found = FALSE;
|
|
|
|
|
|
|
|
if (y <= 0)
|
|
|
|
{
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
y = oggi.year();
|
|
|
|
}
|
1995-10-30 10:17:14 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
TString16 anno; anno.format("%04d", y);
|
|
|
|
TTable reg("REG");
|
|
|
|
reg.put("CODTAB", anno); // Cerca il primo registro dell'anno
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
for (int err = reg.read(_isgteq); err == NOERR; err = reg.next())
|
|
|
|
{
|
|
|
|
if (reg.get("CODTAB").compare(anno, 4) != 0)
|
|
|
|
break; // Sono arrivato all'anno dopo
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
if (reg.get_int("I0") == libro_giornale)
|
|
|
|
{
|
|
|
|
found = TRUE;
|
1995-10-30 10:17:14 +00:00
|
|
|
break;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
1997-06-19 14:33:52 +00:00
|
|
|
|
|
|
|
if (!found) reg.zero(); // Memorizza record (anche vuoto)
|
|
|
|
_rec = reg.curr();
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
TLibro_giornale::TLibro_giornale(int y)
|
|
|
|
{
|
|
|
|
read(y);
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Codice IVA
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TCodiceIVA::TCodiceIVA(const char* cod) : TRectype(LF_TABCOM)
|
|
|
|
{
|
|
|
|
read(cod);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TCodiceIVA::read(const char* cod)
|
|
|
|
{
|
|
|
|
int err = ~NOERR;
|
|
|
|
if (cod && *cod)
|
|
|
|
{
|
|
|
|
TTable iva("%IVA");
|
|
|
|
iva.put("CODTAB", cod);
|
|
|
|
err = iva.read();
|
|
|
|
TRectype::operator=(iva.curr());
|
|
|
|
}
|
|
|
|
if (err != NOERR)
|
|
|
|
zero();
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
real TCodiceIVA::scorpora(real& imponibile) const
|
|
|
|
{
|
|
|
|
const real percent = percentuale();
|
|
|
|
real imposta = abs(imponibile) * percent / (percent + 100.0); imposta.ceil();
|
|
|
|
if (imponibile.sign() < 0) imposta = -imposta;
|
|
|
|
imponibile -= imposta;
|
|
|
|
return imposta;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TBill
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
TBill::~TBill()
|
|
|
|
{
|
|
|
|
if (_descrizione)
|
|
|
|
delete _descrizione;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TBill::set_description(const char* d)
|
|
|
|
{
|
|
|
|
if (_descrizione || (d && *d))
|
|
|
|
{
|
|
|
|
if (_descrizione)
|
|
|
|
*_descrizione = d;
|
|
|
|
else
|
|
|
|
_descrizione = new TString(d);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Certified 90%
|
|
|
|
const TBill& TBill::get(TToken_string& s, int from, int mode)
|
|
|
|
{
|
|
|
|
const char* first = s.get(from);
|
|
|
|
if (mode & 0x1)
|
|
|
|
{
|
|
|
|
_tipo = first ? toupper(*first) : ' ';
|
|
|
|
first = s.get();
|
|
|
|
} else _tipo = ' ';
|
|
|
|
|
|
|
|
#ifdef DBG
|
|
|
|
if (strchr(" CF", _tipo) == NULL)
|
|
|
|
{
|
|
|
|
error_box("Tipo conto errato: '%c'", _tipo);
|
|
|
|
_tipo = ' ';
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
_gruppo = first ? atoi(first) : 0;
|
|
|
|
_conto = s.get_int();
|
|
|
|
_sottoconto = s.get_long();
|
|
|
|
if (mode & 0x2)
|
|
|
|
set_description(s.get());
|
|
|
|
|
|
|
|
_tipo_cr = -1;
|
|
|
|
_sezione = ' ';
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TBill& TBill::copy(const TBill& bill)
|
|
|
|
{
|
|
|
|
_tipo = bill._tipo;
|
|
|
|
_gruppo = bill._gruppo;
|
|
|
|
_conto = bill._conto;
|
|
|
|
_sottoconto = bill._sottoconto;
|
|
|
|
set_description(bill.descrizione());
|
|
|
|
_tipo_cr = bill._tipo_cr;
|
|
|
|
_sospeso = bill._sospeso;
|
|
|
|
_sezione = bill._sezione;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Certified 100%
|
|
|
|
const TBill& TBill::set(int g, int c, long s, char t, const char* d, int r)
|
|
|
|
{
|
|
|
|
_tipo = (t > ' ') ? toupper(t) : ' ';
|
|
|
|
_gruppo = g;
|
|
|
|
_conto = c;
|
|
|
|
_sottoconto = s;
|
|
|
|
set_description(d);
|
|
|
|
_tipo_cr = r;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
const TBill& TBill::add_to(TToken_string& ts, int from, int mode)
|
|
|
|
{
|
|
|
|
if (mode & 0x4)
|
|
|
|
{
|
|
|
|
const int cr = tipo_cr();
|
|
|
|
if (cr > 0) ts.add(cr, from++); else ts.add(" ", from++);
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
if (mode & 0x1)
|
|
|
|
ts.add(_tipo, from++);
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
if (_gruppo > 0) ts.add(_gruppo, from++); else ts.add(" ", from++);
|
|
|
|
if (_conto > 0) ts.add(_conto, from++); else ts.add(" ", from++);
|
|
|
|
if (_sottoconto > 0L) ts.add(_sottoconto, from++); else ts.add(" ", from++);
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
if (mode & 0x2)
|
|
|
|
ts.add(descrizione(), from++);
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char* TBill::field_name(int n, bool contro) const
|
|
|
|
{
|
1998-05-04 07:43:58 +00:00
|
|
|
CHECKD(n >= 0 && n <= 3, "Invalid bill field ", n);
|
1997-06-19 14:33:52 +00:00
|
|
|
|
|
|
|
const char* f;
|
|
|
|
if (contro)
|
|
|
|
{
|
|
|
|
switch(n)
|
|
|
|
{
|
1998-05-04 07:43:58 +00:00
|
|
|
case 0: f = RMV_GRUPPOC; break;
|
|
|
|
case 1: f = RMV_CONTOC; break;
|
|
|
|
case 2: f = RMV_SOTTOCONTOC; break;
|
|
|
|
default:f = RMV_TIPOCC; break;
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch(n)
|
|
|
|
{
|
1998-05-04 07:43:58 +00:00
|
|
|
case 0: f = RMV_GRUPPO; break;
|
|
|
|
case 1: f = RMV_CONTO; break;
|
|
|
|
case 2: f = RMV_SOTTOCONTO; break;
|
|
|
|
default:f = RMV_TIPOC; break;
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TBill::put(TRectype& r, bool c) const
|
|
|
|
{
|
|
|
|
r.put(field_name(0, c), gruppo());
|
|
|
|
r.put(field_name(1, c), conto());
|
|
|
|
r.put(field_name(2, c), sottoconto());
|
|
|
|
r.put(field_name(3, c), tipo());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TBill::get(const TRectype& r, bool c)
|
|
|
|
{
|
|
|
|
set(r.get_int(field_name(0, c)),
|
|
|
|
r.get_int(field_name(1, c)),
|
|
|
|
r.get_long(field_name(2, c)),
|
|
|
|
r.get_char(field_name(3, c)));
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
set_description(NULL);
|
|
|
|
_tipo_cr = -1;
|
|
|
|
_sezione = ' ';
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
if (r.num() == LF_RMOVIVA)
|
1998-05-04 07:43:58 +00:00
|
|
|
tipo_cr(r.get_int(RMI_TIPOCR));
|
1996-07-09 13:00:08 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
return ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TBill::set(TMask& m, short g, short c, short s, short t, short d) const
|
|
|
|
{
|
|
|
|
m.set(g, gruppo());
|
|
|
|
m.set(c, conto());
|
|
|
|
m.set(s, sottoconto());
|
|
|
|
if (t)
|
|
|
|
{
|
|
|
|
char typ[2] = { tipo(), '\0' };
|
|
|
|
m.set(t, typ);
|
|
|
|
}
|
|
|
|
if (d)
|
|
|
|
m.set(d, descrizione());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TBill::get(const TMask& m, short g, short c, short s, short t, short d)
|
|
|
|
{
|
|
|
|
const int gr = m.get_int(g);
|
|
|
|
const int co = m.get_int(c);
|
|
|
|
const long so = m.get_long(s);
|
|
|
|
char ti = ' ';
|
|
|
|
if (t)
|
|
|
|
ti = m.get(t)[0];
|
|
|
|
TString80 de;
|
|
|
|
if (d)
|
|
|
|
de = m.get(d);
|
|
|
|
set(gr, co, so, ti, de);
|
|
|
|
}
|
|
|
|
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
// Certified 100%
|
|
|
|
bool TBill::ok() const
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
return _gruppo != 0 && _conto != 0 && _sottoconto != 0L;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Certified 99%
|
|
|
|
int TBill::compare(const TSortable& s) const
|
|
|
|
{
|
|
|
|
CHECK(class_name()==s.class_name(), "Can't compare TBill with TObject");
|
|
|
|
const TBill& c = (const TBill&)s;
|
|
|
|
|
|
|
|
int res = _gruppo - c._gruppo;
|
|
|
|
if (res) return res;
|
|
|
|
|
|
|
|
res = _conto - c._conto;
|
|
|
|
if (res) return res;
|
|
|
|
|
|
|
|
const long lres = _sottoconto - c._sottoconto;
|
|
|
|
if (lres < 0L) res = -1; else
|
|
|
|
if (lres > 0L) res = +1;
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Certified 95%
|
|
|
|
bool TBill::find()
|
|
|
|
{
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
|
|
|
if ((_tipo != 'C' && _tipo != 'F') || _sottoconto == 0L)
|
|
|
|
{
|
|
|
|
TRectype pcon(LF_PCON);
|
|
|
|
ok = read(pcon);
|
1998-05-04 07:43:58 +00:00
|
|
|
if (!ok && _sottoconto != 0L)
|
1997-06-19 14:33:52 +00:00
|
|
|
{
|
1998-05-04 07:43:58 +00:00
|
|
|
const long sotto = _sottoconto;
|
|
|
|
_sottoconto = 0L;
|
|
|
|
ok = read(pcon);
|
1997-06-19 14:33:52 +00:00
|
|
|
if (ok)
|
1998-05-04 07:43:58 +00:00
|
|
|
_tipo = toupper(pcon.get_char(PCN_TMCF));
|
|
|
|
_sottoconto = sotto;
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
1998-05-04 07:43:58 +00:00
|
|
|
}
|
1997-06-19 14:33:52 +00:00
|
|
|
|
1998-05-04 07:43:58 +00:00
|
|
|
if ((_tipo == 'C' || _tipo == 'F') && _sottoconto != 0L)
|
|
|
|
{
|
|
|
|
TLocalisamfile clifo(LF_CLIFO);
|
|
|
|
clifo.setkey(1);
|
|
|
|
clifo.put("TIPOCF", _tipo);
|
|
|
|
clifo.put("CODCF", _sottoconto);
|
|
|
|
ok = clifo.read() == NOERR;
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
set_description(clifo.get("RAGSOC"));
|
|
|
|
if (_tipo_cr < 0)
|
|
|
|
{
|
|
|
|
_tipo_cr = 0;
|
|
|
|
_sezione = ' ';
|
|
|
|
}
|
|
|
|
_sospeso = clifo.get_bool("SOSPESO");
|
|
|
|
|
|
|
|
const char tipoa = clifo.get_char("TIPOPERS");
|
|
|
|
if (tipoa == 'F') // Se persona fisica allora aggiusta la ragione sociale
|
|
|
|
{
|
|
|
|
TString nome(descrizione().mid(30));
|
|
|
|
if (nome.not_empty())
|
|
|
|
{
|
|
|
|
_descrizione->cut(30);
|
|
|
|
_descrizione->trim(); nome.trim();
|
|
|
|
*_descrizione << ' ' << nome;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (_gruppo == 0 || _conto == 0)
|
|
|
|
{
|
|
|
|
_gruppo = clifo.get_int("GRUPPO");
|
|
|
|
_conto = clifo.get_int("CONTO");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1997-06-19 14:33:52 +00:00
|
|
|
return ok;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
|
|
|
|
bool TBill::read(TRectype &r)
|
1995-07-21 10:12:15 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
TLocalisamfile pcon(LF_PCON);
|
1998-05-04 07:43:58 +00:00
|
|
|
pcon.put(PCN_GRUPPO, _gruppo);
|
|
|
|
pcon.put(PCN_CONTO, _conto);
|
|
|
|
pcon.put(PCN_SOTTOCONTO, _sottoconto);
|
1996-05-20 09:26:39 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
const int err = pcon.read();
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
r = pcon.curr();
|
1998-05-04 07:43:58 +00:00
|
|
|
_tipo_cr = r.get_int(PCN_TIPOSPRIC);
|
|
|
|
_sezione = r.get_char(PCN_SEZSALDI);
|
|
|
|
set_description(r.get(PCN_DESCR));
|
|
|
|
_sospeso = r.get_bool(PCN_SOSPESO);
|
1997-06-19 14:33:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
r.zero();
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TBill::tipo_att()
|
|
|
|
{
|
|
|
|
int tipo_att = 1;
|
|
|
|
if (tipo() <= ' ' && ok())
|
1996-05-20 09:26:39 +00:00
|
|
|
{
|
1997-06-19 14:33:52 +00:00
|
|
|
TBill bill(gruppo(), conto());
|
|
|
|
TRectype rec(LF_PCON); bill.read(rec);
|
1998-05-04 07:43:58 +00:00
|
|
|
const TIndbil ib = (TIndbil)rec.get_int(PCN_INDBIL);
|
1997-06-19 14:33:52 +00:00
|
|
|
if (ib == ib_passivita || ib == ib_ricavi)
|
|
|
|
{
|
|
|
|
read(rec);
|
1998-05-04 07:43:58 +00:00
|
|
|
const int ricser = rec.get_int(PCN_RICSER); // 0 = Altre attivita 1 = Servizi
|
1997-06-19 14:33:52 +00:00
|
|
|
tipo_att = (ricser == 1) ? 1 : 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tipo_att;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Certified 99%
|
|
|
|
const TString& TBill::descrizione() const
|
|
|
|
{
|
|
|
|
TBill& myself = (TBill&)*this;
|
1997-07-09 10:05:15 +00:00
|
|
|
// Se il conto e' valido (c'e' almeno il gruppo) cerca la sua descrizione su file
|
1997-06-19 14:33:52 +00:00
|
|
|
if ((_descrizione == NULL || _descrizione->blank()) && gruppo() != 0)
|
|
|
|
{
|
|
|
|
if (!myself.find())
|
|
|
|
myself.set_description("Sconosciuto");
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
1997-06-19 14:33:52 +00:00
|
|
|
if (_descrizione == NULL)
|
|
|
|
myself._descrizione = new TString;
|
|
|
|
|
|
|
|
return *_descrizione;
|
1995-07-21 10:12:15 +00:00
|
|
|
}
|
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
int TBill::tipo_cr() const
|
|
|
|
{
|
|
|
|
if (_tipo_cr < 0)
|
|
|
|
{
|
|
|
|
TBill& myself = (TBill&)*this;
|
|
|
|
myself.find();
|
|
|
|
}
|
|
|
|
return _tipo_cr;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
1997-06-19 14:33:52 +00:00
|
|
|
// Certified 99% (uses __tmp_string)
|
|
|
|
const char* TBill::string(int mode) const
|
|
|
|
{
|
|
|
|
TFixed_string s(&__tmp_string[256], 80);
|
|
|
|
s.cut(0);
|
|
|
|
|
|
|
|
if (mode & 0x4)
|
|
|
|
{
|
|
|
|
const int cr = tipo_cr();
|
|
|
|
if (cr > 0) s << cr << '|';
|
|
|
|
else s << " |";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode & 0x1)
|
|
|
|
s << _tipo << '|';
|
|
|
|
|
|
|
|
if (_gruppo > 0) s << _gruppo << '|';
|
|
|
|
else s << " |";
|
|
|
|
|
|
|
|
if (_conto > 0) s << _conto << '|';
|
|
|
|
else s << " |";
|
|
|
|
|
|
|
|
if (_sottoconto > 0L) s << _sottoconto;
|
|
|
|
else s << ' ';
|
|
|
|
|
|
|
|
if (mode & 0x2)
|
|
|
|
s << '|' << descrizione();
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
1995-07-21 10:12:15 +00:00
|
|
|
|
|
|
|
|