Un insieme di modifiche al saldaconto della prima nota, piu' una neceesaria
depurazione di pagament.cpp onde evitare conflitti con Guido git-svn-id: svn://10.65.10.50/trunk@1732 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
4f99dae39a
commit
79ff0b8518
@ -66,6 +66,7 @@ TMask* TPrimanota_application::load_mask(int n)
|
||||
{
|
||||
m->set_handler(F_DATADOC, doc_handler);
|
||||
m->set_handler(F_NUMDOC, doc_handler);
|
||||
m->set_handler(F_NUMRIF, numrif_handler);
|
||||
m->set_handler(F_DATA74TER, data74ter_handler);
|
||||
m->set_handler(F_PROTIVA, protiva_handler);
|
||||
m->set_handler(F_CLIENTE, clifo_handler);
|
||||
@ -95,7 +96,7 @@ TMask* TPrimanota_application::load_mask(int n)
|
||||
// add saldaconto
|
||||
TSheet_field& ps = (TSheet_field&)m->field(FS_RATESHEET);
|
||||
ps.set_notify(pag_notify);
|
||||
|
||||
m->set_handler(FS_RESET, reset_handler);
|
||||
}
|
||||
_iva_showed = FALSE;
|
||||
case 1:
|
||||
@ -419,6 +420,7 @@ void TPrimanota_application::on_config_change()
|
||||
_ges_sal = cnf.get_bool("GesSal");
|
||||
_num_cli = cnf.get_bool("NrCliDx");
|
||||
_num_for = cnf.get_bool("NrForDx");
|
||||
_npart_is_prot = cnf.get_bool("RifPro");
|
||||
}
|
||||
|
||||
|
||||
|
@ -509,8 +509,8 @@ STRING F_NUMRIF 7
|
||||
BEGIN
|
||||
PROMPT 68 15 "/ "
|
||||
FIELD LF_PARTITE->NUMPART
|
||||
FLAGS "D"
|
||||
HELP "Numero documento di riferimento"
|
||||
FLAGS "U"
|
||||
HELP "Numero di riferimento partita (documento o protocollo)"
|
||||
WARNING "E' richiesto il numero di riferimento partita"
|
||||
CHECKTYPE REQUIRED
|
||||
END
|
||||
|
@ -1514,7 +1514,7 @@ bool TPrimanota_application::doc_handler(TMask_field& f, KEY key)
|
||||
if (key == K_TAB)
|
||||
{
|
||||
TMask& m = f.mask();
|
||||
const TString& val = f.get();
|
||||
const TString16 val(f.get());
|
||||
|
||||
if (!val.empty() && m.field(F_ANNORIF).active())
|
||||
{ // Se c'e' gestione saldaconto
|
||||
@ -1523,9 +1523,13 @@ bool TPrimanota_application::doc_handler(TMask_field& f, KEY key)
|
||||
const TDate dd(val);
|
||||
m.set(F_ANNORIF, dd.year()); // copia data documento
|
||||
}
|
||||
else
|
||||
else if (!app().npart_is_prot())
|
||||
{
|
||||
if (m.get(F_NUMRIF).empty())
|
||||
{
|
||||
m.set(F_NUMRIF, val); // copia numero documento
|
||||
app().set_numrif(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1533,6 +1537,52 @@ bool TPrimanota_application::doc_handler(TMask_field& f, KEY key)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool TPrimanota_application::numrif_handler(TMask_field& f, KEY key)
|
||||
{
|
||||
if (key == K_TAB)
|
||||
{
|
||||
TMask& m = f.mask();
|
||||
const TString& val = f.get();
|
||||
|
||||
if (f.focusdirty())
|
||||
{
|
||||
// se cambiato chiedo conferma:
|
||||
// se svuotato, azzero il cazzoconto
|
||||
if (val.empty())
|
||||
{
|
||||
if (yesno_box("Si desidera l'azzeramento delle scadenze?"))
|
||||
{
|
||||
// sbraga giu' il saldaconto: andra' tutto kancellato
|
||||
// se c'era
|
||||
app().remove_scadenze(f.mask(), app().get_numrif());
|
||||
f.mask().disable_page(2);
|
||||
}
|
||||
else f.set(app().get_numrif());
|
||||
}
|
||||
else
|
||||
{
|
||||
if (yesno_box("Si desidera la ridefinizione delle scadenze?"))
|
||||
{
|
||||
// lo ridefinisco da capo
|
||||
// con il nuovo porcodio, riabilitando se
|
||||
// non c'era
|
||||
app().remove_scadenze(f.mask(), app().get_numrif());
|
||||
|
||||
app().reset_pagamento();
|
||||
app().set_scadenze(m);
|
||||
f.mask().enable_page(2);
|
||||
|
||||
}
|
||||
else f.set(app().get_numrif());
|
||||
}
|
||||
}
|
||||
app().set_numrif(f.get());
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool TPrimanota_application::occas_code_handler(TMask_field& f, KEY key)
|
||||
{
|
||||
if (key == K_TAB)
|
||||
@ -1805,6 +1855,7 @@ void TPrimanota_application::add_cgs_rit(bool fiscali)
|
||||
bool TPrimanota_application::protiva_handler(TMask_field& f, KEY key)
|
||||
{
|
||||
bool ok = TRUE;
|
||||
const TString16 piva(f.get());
|
||||
if (key == K_ENTER && f.dirty() && f.mask().mode() == MODE_INS)
|
||||
{
|
||||
const long protiva = atol(f.get());
|
||||
@ -1812,6 +1863,15 @@ bool TPrimanota_application::protiva_handler(TMask_field& f, KEY key)
|
||||
if (protiva != protocol)
|
||||
ok = f.yesno_box("Accettare il protocollo IVA fuori sequenza: %ld invece di %ld",
|
||||
protiva, protocol);
|
||||
|
||||
}
|
||||
else if (key == K_TAB && app().is_saldaconto() && f.mask().get(F_NUMRIF).empty())
|
||||
{
|
||||
if (app().npart_is_prot())
|
||||
{
|
||||
f.mask().set(F_NUMRIF, piva);
|
||||
app().set_numrif(piva);
|
||||
}
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ class TPrimanota_application : public TRelation_application
|
||||
TipoIVA _iva; // Tipo di IVA corrente
|
||||
bool _ges_val, _ges_sal; // Gestione valuta e saldaconto
|
||||
bool _num_cli, _num_for; // Riferimento partita allineato a destra
|
||||
bool _npart_is_prot; // Riferimento partita = n. prot. IVA anziche' doc
|
||||
|
||||
bool _skip_giornale_check; // Ignora controllo data stampa libro giornale
|
||||
bool _skip_bollato_check; // Ignora controllo data stampa bollato
|
||||
@ -65,6 +66,7 @@ class TPrimanota_application : public TRelation_application
|
||||
|
||||
TBill _conto_ricavo; // Conto di ricavo del clifo
|
||||
TString_array _pag_rows;
|
||||
TString16 _numrif; // memorizza numrif per undo
|
||||
|
||||
static bool showpartite_handler(TMask_field& f, KEY k);
|
||||
static bool speserimb_handler(TMask_field& f, KEY k);
|
||||
@ -81,6 +83,7 @@ class TPrimanota_application : public TRelation_application
|
||||
static bool datacomp_handler(TMask_field& f, KEY key);
|
||||
static bool data74ter_handler(TMask_field& f, KEY key);
|
||||
static bool doc_handler(TMask_field& f, KEY key);
|
||||
static bool numrif_handler(TMask_field& f, KEY key);
|
||||
static bool protiva_handler(TMask_field& f, KEY key);
|
||||
static bool clifo_handler(TMask_field& f, KEY key);
|
||||
static bool totale_handler(TMask_field& f, KEY key);
|
||||
@ -104,6 +107,7 @@ class TPrimanota_application : public TRelation_application
|
||||
static bool dareavere_handler(TMask_field& f, KEY k);
|
||||
static bool cg_conto_handler(TMask_field& f, KEY key);
|
||||
static bool codpag_handler(TMask_field& f, KEY key);
|
||||
static bool reset_handler(TMask_field& f, KEY key);
|
||||
|
||||
static bool iva_notify(TSheet_field& s, int r, KEY key);
|
||||
static bool iva_handler(TMask_field& f, KEY key);
|
||||
@ -113,6 +117,9 @@ class TPrimanota_application : public TRelation_application
|
||||
|
||||
void reset_sheet_row(TSheet_field& s, int n);
|
||||
|
||||
void set_numrif(const char* s) { _numrif = s; }
|
||||
const char* get_numrif() { return _numrif; }
|
||||
|
||||
protected: // TApplication
|
||||
virtual void on_firm_change();
|
||||
virtual void on_config_change();
|
||||
@ -150,6 +157,7 @@ protected:
|
||||
bool gestione_saldaconto() const { return _ges_sal; }
|
||||
bool is_saldaconto() const { return _is_saldaconto; }
|
||||
void set_saldaconto(bool b) { _is_saldaconto = b; }
|
||||
bool npart_is_prot() { return _npart_is_prot; }
|
||||
|
||||
void fill_sheet(TMask& m) const;
|
||||
void init_mask(TMask& m);
|
||||
@ -202,6 +210,7 @@ protected:
|
||||
void set_scadenze(TMask& m);
|
||||
bool read_scadenze(TMask& m);
|
||||
void write_scadenze(const TMask& m);
|
||||
void remove_scadenze(const TMask& m, const char* rif);
|
||||
|
||||
bool edit_partite(int riga);
|
||||
|
||||
|
@ -44,8 +44,8 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
|
||||
ts = rws.row(r);
|
||||
|
||||
news = ns.get(0);
|
||||
newp = ns.get(1);
|
||||
newi = ns.get(2);
|
||||
newp = ns.get(2);
|
||||
newi = ns.get(1);
|
||||
newt = ns.get(3);
|
||||
|
||||
// qui viene il bello, si fa per dire
|
||||
@ -53,11 +53,11 @@ bool TPrimanota_application::pag_notify(TSheet_field&, int r, KEY k)
|
||||
{
|
||||
mod = m_scad = TRUE;
|
||||
}
|
||||
if (newp != ts.get(1)) // modificata percentuale
|
||||
if (newp != ts.get(2)) // modificata percentuale
|
||||
{
|
||||
mod = m_perc = TRUE;
|
||||
}
|
||||
if (newi != ts.get(2)) // modificato importo
|
||||
if (newi != ts.get(1)) // modificato importo
|
||||
{
|
||||
// se si modifica la percentuale l'importo non viene cagato
|
||||
if ((recalc && !m_perc) || (!recalc))
|
||||
@ -153,6 +153,29 @@ bool TPrimanota_application::codpag_handler(TMask_field& f, KEY key)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool TPrimanota_application::reset_handler(TMask_field& f, KEY key)
|
||||
{
|
||||
TMask& m = f.mask();
|
||||
|
||||
if (key == K_SPACE && m.is_running() && app().is_saldaconto())
|
||||
{
|
||||
app().reset_pagamento();
|
||||
app().set_scadenze(m);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void TPrimanota_application::reset_pagamento()
|
||||
{
|
||||
if (_pag != NULL)
|
||||
{
|
||||
_pag->read();
|
||||
_pag->set_rate_auto();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void TPrimanota_application::set_pagamento(const char* c, const char* d)
|
||||
{
|
||||
if (_pag != NULL) delete _pag;
|
||||
@ -254,7 +277,7 @@ bool TPrimanota_application::read_scadenze(TMask& m)
|
||||
if (pag.code() != partita.get("CODPAG"))
|
||||
fromscratch = TRUE;
|
||||
// se invece la maschera contiene importi diversi da quelli
|
||||
// registrati si passa la palla al culano
|
||||
// registrati si passa la palla al culano/a
|
||||
else if (imponibile != partita.get_real(PART_IMPORTO) ||
|
||||
imposta != partita.get_real(PART_IMPOSTA) ||
|
||||
spese != partita.get_real(PART_SPESE))
|
||||
@ -262,7 +285,7 @@ bool TPrimanota_application::read_scadenze(TMask& m)
|
||||
fromscratch = !yesno_box("Gli importi totali delle scadenze sono stati modificati rispetto"
|
||||
" all'ultima registrazione. Si desidera mantenere"
|
||||
" comunque la rateazione precedente");
|
||||
// nel caso, of course, si disabilitano gli automatismi
|
||||
// nel qual caso, of course, si disabilitano gli automatismi
|
||||
if(!fromscratch) m.field(FS_RECALC).set("");
|
||||
}
|
||||
if (fromscratch)
|
||||
@ -305,6 +328,17 @@ bool TPrimanota_application::read_scadenze(TMask& m)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void TPrimanota_application::remove_scadenze(const TMask& m, const char* nr)
|
||||
{
|
||||
// TBI se _erase_sld == TRUE occorre cancellare tutte le scadenze
|
||||
// eventualmente presenti; attenzione a riferimenti cambiati
|
||||
TString numrif(nr);
|
||||
if (numrif.empty()) return;
|
||||
|
||||
// rimuovi se ci sono
|
||||
|
||||
}
|
||||
|
||||
void TPrimanota_application::write_scadenze(const TMask& m)
|
||||
{
|
||||
real imponibile(0.0);
|
||||
@ -340,6 +374,8 @@ void TPrimanota_application::write_scadenze(const TMask& m)
|
||||
int gruppo = (tipocf == 'C' || tipocf == 'F') ? 0 : _rel->cg(0).get_char("GRUPPO");
|
||||
int conto = (tipocf == 'C' || tipocf == 'F') ? 0 : _rel->cg(0).get_char("CONTO");
|
||||
long sottoconto = _rel->cg(0).get_long("SOTTOCONTO");
|
||||
|
||||
// TBI deve essere riga iniziale scadenze (puo' essere != 1 sul file)
|
||||
const int nriga = 1;
|
||||
int numrig = 1;
|
||||
|
||||
@ -407,6 +443,8 @@ void TPrimanota_application::write_scadenze(const TMask& m)
|
||||
scadenza.put(SCAD_ANNO, anno);
|
||||
scadenza.put(SCAD_NUMPART, numpart);
|
||||
scadenza.put(SCAD_NRIGA, nriga);
|
||||
// TBI NO! Va visto se ce ne sono altre, con gestione riga
|
||||
// iniziale nella partita
|
||||
scadenza.put(SCAD_NRATA, i+1);
|
||||
|
||||
if (scadenza.read() != NOERR)
|
||||
|
@ -73,8 +73,8 @@ SPREADSHEET F_RATESHEET 80 8
|
||||
BEGIN
|
||||
PROMPT 1 10 "Rate"
|
||||
ITEM "Scadenza@10"
|
||||
ITEM "Percentuale@12"
|
||||
ITEM "Importo@15"
|
||||
ITEM "Percentuale@12"
|
||||
ITEM "Tipo"
|
||||
ITEM "Pagamento@32"
|
||||
END
|
||||
@ -89,14 +89,14 @@ BEGIN
|
||||
PROMPT 1 2 "Scadenza "
|
||||
END
|
||||
|
||||
NUMBER 102 3 0
|
||||
NUMBER 102 15 0
|
||||
BEGIN
|
||||
PROMPT 1 3 "Percentuale "
|
||||
PROMPT 1 3 "Importo "
|
||||
END
|
||||
|
||||
NUMBER 103 15 0
|
||||
NUMBER 103 3 2
|
||||
BEGIN
|
||||
PROMPT 1 4 "Importo "
|
||||
PROMPT 1 4 "Percentuale "
|
||||
END
|
||||
|
||||
NUMBER 104 2 0
|
||||
|
@ -5,20 +5,20 @@ BEGIN
|
||||
PROMPT 1 1 "Scadenza "
|
||||
END
|
||||
|
||||
NUMBER 102 8 3
|
||||
BEGIN
|
||||
PROMPT 1 2 "Percentuale "
|
||||
PICTURE ".3"
|
||||
FLAGS "R"
|
||||
END
|
||||
|
||||
NUMBER 103 15
|
||||
NUMBER 102 15
|
||||
BEGIN
|
||||
PROMPT 1 3 "Importo "
|
||||
PICTURE "."
|
||||
FLAGS "R"
|
||||
END
|
||||
|
||||
NUMBER 103 8 3
|
||||
BEGIN
|
||||
PROMPT 1 2 "Percentuale "
|
||||
PICTURE ".3"
|
||||
FLAGS "R"
|
||||
END
|
||||
|
||||
NUMBER 104 2 0
|
||||
BEGIN
|
||||
PROMPT 1 4 "Tipo pagamento "
|
||||
|
@ -8,3 +8,4 @@
|
||||
#define FS_NAMEPAG 508
|
||||
#define FS_TIPOPR 509
|
||||
#define FS_MCOMM 510
|
||||
#define FS_RESET 511
|
||||
|
@ -65,11 +65,16 @@ SPREADSHEET FS_RATESHEET 0 8
|
||||
BEGIN
|
||||
PROMPT 1 10 "Rate"
|
||||
ITEM "Scadenza@10"
|
||||
ITEM "Percentuale@12"
|
||||
ITEM "Importo@15"
|
||||
ITEM "Percentuale@12"
|
||||
ITEM "Tipo"
|
||||
ITEM "Pagamento@32"
|
||||
END
|
||||
|
||||
BUTTON FS_RESET 7 1
|
||||
BEGIN
|
||||
PROMPT 1 -1 "Reset"
|
||||
END
|
||||
|
||||
ENDPAGE
|
||||
|
||||
|
@ -156,8 +156,8 @@ END
|
||||
|
||||
BOOLEAN CHK_RIFPRO
|
||||
BEGIN
|
||||
PROMPT 4 17 "Riferimento numero protocollo o documento"
|
||||
HELP "Indicare se si desidera il numero protocollo/documento come riferimento"
|
||||
PROMPT 4 17 "Riferimento partita con numero protocollo"
|
||||
HELP "Indicare se si desidera il numero protocollo IVA anziche' il numero documento come riferimento partita"
|
||||
FIELD RifPro
|
||||
GROUP GROUP_SALDACONTO
|
||||
END
|
||||
|
715
cg/pagament.cpp
715
cg/pagament.cpp
@ -7,6 +7,7 @@
|
||||
#include <scadenze.h>
|
||||
#include <pagsca.h>
|
||||
|
||||
|
||||
int TPagamento::_rata_ifield(int n, int f) const
|
||||
{
|
||||
TToken_string& t = (TToken_string&)_rate[n];
|
||||
@ -810,6 +811,8 @@ bool TPagamento::read(TTable* t, TTable* r)
|
||||
t->zero(); t->put("CODTAB",_code);
|
||||
if (t->read() != NOERR) return FALSE;
|
||||
|
||||
_rate.destroy();
|
||||
|
||||
// set everything
|
||||
_rdiff = t->get_bool("B1");
|
||||
_mcomm = t->get_bool("B0");
|
||||
@ -1031,14 +1034,14 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
||||
TToken_string& ts = sf.row(-1);
|
||||
// istanzia, o stronzo
|
||||
ts.add((const char*)data_rata(i));
|
||||
ts.add(perc_rata(i).string());
|
||||
ts.add(tpay_rata(i).string());
|
||||
ts.add(perc_rata(i).string());
|
||||
ts.add(tipo_rata(i));
|
||||
ts.add(desc_tipo(tipo_rata(i)));
|
||||
if (ratapagata(i))
|
||||
{
|
||||
sf.disable_cell(1,1); // percentuale
|
||||
sf.disable_cell(1,2); // importo
|
||||
sf.disable_cell(1,1); // importo
|
||||
sf.disable_cell(1,2); // percentuale
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1079,8 +1082,8 @@ void TPagamento::set_sheet(TSheet_field& sf, int sscad)
|
||||
// disabilita campi da non toccare sulla prima rata
|
||||
if (_inited)
|
||||
{
|
||||
sf.disable_cell(0,1); // percentuale
|
||||
sf.disable_cell(0,2); // importo
|
||||
sf.disable_cell(0,1); // importo
|
||||
sf.disable_cell(0,2); // percentuale
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -1102,705 +1105,3 @@ _def_tpr(1), _def_ulc(""), _round(0), _int_rate(30)
|
||||
_new = TRUE;
|
||||
// if (_new && data != NULL) error_box("Modalita' pagamento inesistente");
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TTree_rectype
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TTree_rectype::TTree_rectype(const TRectype& testa, const TRectype& riga, const char* num)
|
||||
: TRectype(testa), _recarr(riga, num)
|
||||
{
|
||||
}
|
||||
|
||||
TTree_rectype::TTree_rectype(int testa, int riga, const char* num)
|
||||
: TRectype(testa), _recarr(riga, num)
|
||||
{
|
||||
}
|
||||
|
||||
TTree_rectype::TTree_rectype(const TTree_rectype& t)
|
||||
: TRectype(t), _recarr(t._recarr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
TObject* TTree_rectype::dup() const
|
||||
{
|
||||
TTree_rectype* r = new TTree_rectype(*this);
|
||||
return r;
|
||||
}
|
||||
|
||||
void TTree_rectype::copy_key_to_row(TRectype& row) const
|
||||
{
|
||||
const int numkey = 0; // Memento! Gli indici delle chiavi partono da zero!
|
||||
RecDes* recd = rec_des(); // Descrizione del record della testata
|
||||
|
||||
row.zero();
|
||||
for (int i = 0; i < recd->Ky[numkey].NkFields; i++)
|
||||
{
|
||||
const KeyDes& kd = recd->Ky[numkey];
|
||||
const int nf = kd.FieldSeq[i] % MaxFields;
|
||||
const RecFieldDes& rf = recd->Fd[nf];
|
||||
const char* name = rf.Name;
|
||||
const TString& val = get(name);
|
||||
row.put(name, val);
|
||||
}
|
||||
}
|
||||
|
||||
int TTree_rectype::fill_array()
|
||||
{
|
||||
TRectype* row = (TRectype*)_recarr.key().dup();
|
||||
copy_key_to_row(*row);
|
||||
const int err = _recarr.read(row);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
int TTree_rectype::read(TBaseisamfile& f, word op)
|
||||
{
|
||||
int err = TRectype::read(f, op);
|
||||
if (err == NOERR)
|
||||
fill_array();
|
||||
else
|
||||
_recarr.destroy_rows();
|
||||
return err;
|
||||
}
|
||||
|
||||
int TTree_rectype::next(TBaseisamfile& f)
|
||||
{
|
||||
int err = TRectype::next(f);
|
||||
if (err == NOERR)
|
||||
fill_array();
|
||||
else
|
||||
_recarr.destroy_rows();
|
||||
return err;
|
||||
}
|
||||
|
||||
int TTree_rectype::write(TBaseisamfile& f) const
|
||||
{
|
||||
int err = TRectype::write(f);
|
||||
if (err == NOERR)
|
||||
err = _recarr.write();
|
||||
return err;
|
||||
}
|
||||
|
||||
int TTree_rectype::rewrite(TBaseisamfile& f) const
|
||||
{
|
||||
int err = TRectype::rewrite(f);
|
||||
if (err == NOERR)
|
||||
err = _recarr.rewrite();
|
||||
return err;
|
||||
}
|
||||
|
||||
int TTree_rectype::remove(TBaseisamfile& f)
|
||||
{
|
||||
int err = TRectype::remove(f);
|
||||
if (err == NOERR)
|
||||
err = _recarr.remove();
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TRiga_scadenze
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TRiga_scadenze::TRiga_scadenze(TRiga_partite* r)
|
||||
: TTree_rectype(LF_SCADENZE, LF_PAGSCA, "NRIGP"), _riga(r)
|
||||
{
|
||||
CHECK(_riga, "Riga nulla");
|
||||
}
|
||||
|
||||
TRiga_scadenze::TRiga_scadenze(const TRiga_scadenze& s)
|
||||
: TTree_rectype(s), _riga(s._riga)
|
||||
|
||||
{
|
||||
CHECK(_riga, "Riga nulla");
|
||||
}
|
||||
|
||||
TPartita& TRiga_scadenze::partita() const
|
||||
{
|
||||
return riga().partita();
|
||||
}
|
||||
|
||||
|
||||
// Controlla se la rata e' in valuta
|
||||
bool TRiga_scadenze::in_valuta() const
|
||||
{
|
||||
return get(SCAD_CODVAL).not_empty();
|
||||
}
|
||||
|
||||
// Controlla se la rata e' stata completamente pagata
|
||||
int TRiga_scadenze::pagata() const
|
||||
{
|
||||
const TRecord_array& a = rows_array();
|
||||
for (int p = a.last_row(); p > 0; p = a.pred_row(p))
|
||||
{
|
||||
const TRectype& pag = a.row(p);
|
||||
if (pag.get_char("ACCSAL") == 'S')
|
||||
return p;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Calcola il totale dei pagamenti (eventualmente in valuta)
|
||||
TImporto TRiga_scadenze::importo_pagato(bool val) const
|
||||
{
|
||||
const TPartita& game = partita();
|
||||
const char* imp_field = in_valuta() && val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
TImporto totale;
|
||||
const TRecord_array& a = rows_array();
|
||||
for (int p = a.last_row(); p > 0; p = a.pred_row(p))
|
||||
{
|
||||
const TRectype& pag = a.row(p); // Riga pagamento
|
||||
const TRiga_partite& sum = game.riga(p); // Riga partite
|
||||
const TImporto imp(sum.get_char(PART_SEZ), pag.get_real(imp_field));
|
||||
totale += imp;
|
||||
}
|
||||
|
||||
return totale;
|
||||
}
|
||||
|
||||
// Calcola l'importo da pagare (eventualmente in valuta)
|
||||
TImporto TRiga_scadenze::importo_da_pagare(bool val) const
|
||||
{
|
||||
const char* imp_field = in_valuta() && val ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const TRiga_partite& r = riga(); // Riga fattura
|
||||
const TImporto totale(r.get_char(PART_SEZ), get_real(imp_field));
|
||||
return totale;
|
||||
}
|
||||
|
||||
// Calcola l'abbuono della rata e ritorna il suo tipo:
|
||||
// 'A' abbuono attivo; 'P' abbuono passivo
|
||||
// La sezione dell'abbuono calcolato e' quella della riga contabile in cui finira'
|
||||
char TRiga_scadenze::calcola_abbuono(TImporto& abbuono, bool val) const
|
||||
{
|
||||
bool ap = ' ';
|
||||
if (pagata())
|
||||
{
|
||||
abbuono = importo_da_pagare(TRUE);
|
||||
abbuono += importo_pagato(TRUE);
|
||||
|
||||
const int sign = abbuono.valore().sign();
|
||||
if (sign != 0)
|
||||
{
|
||||
if (sign > 0)
|
||||
ap = abbuono.sezione() == 'D' ? 'P' : 'A';
|
||||
else
|
||||
ap = abbuono.sezione() == 'D' ? 'A' : 'P';
|
||||
}
|
||||
|
||||
if (val && in_valuta())
|
||||
{
|
||||
abbuono.valore() *= get_real(SCAD_CAMBIO);
|
||||
abbuono.valore().round();
|
||||
}
|
||||
}
|
||||
else
|
||||
abbuono.valore() = ZERO;
|
||||
|
||||
return ap;
|
||||
}
|
||||
|
||||
// Calcola la differenza cambi con la sezione da mettere nella riga contabile corrispondente
|
||||
TImporto TRiga_scadenze::calcola_differenza_cambio(bool update)
|
||||
{
|
||||
TImporto diffcam;
|
||||
const int riga_saldo = pagata();
|
||||
if (riga_saldo > 0)
|
||||
{
|
||||
TRectype& pag = row(riga_saldo, FALSE);
|
||||
const TRiga_partite& sum = partita().riga(riga_saldo);
|
||||
const char sez = sum.sezione();
|
||||
|
||||
if (update)
|
||||
{
|
||||
diffcam = importo_da_pagare(FALSE);
|
||||
diffcam += importo_pagato(FALSE);
|
||||
|
||||
real a = pag.get_real(PAGSCA_ABBUONI);
|
||||
if (in_valuta())
|
||||
{
|
||||
a *= get_real(SCAD_CAMBIO);
|
||||
a.round();
|
||||
}
|
||||
|
||||
const TImporto abb_lit(sez, a);
|
||||
diffcam += abb_lit;
|
||||
diffcam.normalize(sez);
|
||||
pag.put(PAGSCA_DIFFCAM, diffcam.valore());
|
||||
}
|
||||
else
|
||||
{
|
||||
diffcam.set(sez, pag.get_real(PAGSCA_DIFFCAM));
|
||||
}
|
||||
}
|
||||
return diffcam;
|
||||
}
|
||||
|
||||
real TRiga_scadenze::residuo() const
|
||||
{
|
||||
const char* imp_field = get(SCAD_CODVAL).not_empty() ? SCAD_IMPORTOVAL : SCAD_IMPORTO;
|
||||
const real da_pagare(get(imp_field));
|
||||
const real pagato(get(SCAD_IMPORTOPAG));
|
||||
const real residuo = da_pagare - pagato;
|
||||
return residuo;
|
||||
}
|
||||
|
||||
|
||||
bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag,
|
||||
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
||||
char& new_ap, TImporto& new_abb, TImporto& new_diffcam)
|
||||
{
|
||||
const int nrigp = new_pag.get_int(PAGSCA_NRIGP);
|
||||
const TRectype old_pag(row(nrigp));
|
||||
TRiga_partite& sum = partita().riga(nrigp);
|
||||
|
||||
old_ap = calcola_abbuono(old_abb, FALSE);
|
||||
old_diffcam = calcola_differenza_cambio(FALSE);
|
||||
|
||||
const char* imp_field = get(SCAD_CODVAL).not_empty() ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
||||
const real importo(new_pag.get(imp_field));
|
||||
const bool empty = importo.is_zero();
|
||||
if (empty)
|
||||
rows_array().destroy_row(nrigp);
|
||||
else
|
||||
row(nrigp, FALSE) = new_pag;
|
||||
|
||||
TImporto abbuono;
|
||||
new_ap = calcola_abbuono(abbuono, TRUE); // Calcolo abbuono in valuta
|
||||
|
||||
TImporto imp(abbuono); imp.swap_section();
|
||||
imp.normalize(sum.sezione());
|
||||
if (new_ap != ' ')
|
||||
{
|
||||
CHECK(nrigp == pagata(), "Aggiornamento abbuoni inconsistente");
|
||||
TRectype& pag = row(nrigp, FALSE);
|
||||
pag.put(PAGSCA_ABBUONI, imp.valore());
|
||||
|
||||
new_abb = abbuono;
|
||||
if (in_valuta())
|
||||
{
|
||||
new_abb.valore() *= get_real(SCAD_CAMBIO);
|
||||
new_abb.valore().round();
|
||||
}
|
||||
}
|
||||
else
|
||||
new_abb.valore() = ZERO;
|
||||
|
||||
sum.update(old_abb, new_abb, PART_SEZABB, PART_ABBUONI);
|
||||
|
||||
new_diffcam = calcola_differenza_cambio(TRUE);
|
||||
sum.update(old_diffcam, new_diffcam, PART_SEZDIFCAM, PART_DIFFCAM);
|
||||
|
||||
sum.update(old_pag, new_pag, PART_IMPORTO);
|
||||
sum.update(old_pag, new_pag, PART_IMPORTOVAL);
|
||||
sum.update(old_pag, new_pag, PART_RITENUTE);
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TRiga_partite
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TRiga_partite::TRiga_partite(TPartita* game)
|
||||
: TTree_rectype(LF_PARTITE, LF_SCADENZE, "NRATA"), _partita(game)
|
||||
{
|
||||
CHECK(_partita, "Partita nulla");
|
||||
}
|
||||
|
||||
TRiga_partite::TRiga_partite(const TRiga_partite& r)
|
||||
: TTree_rectype(r), _partita(r._partita)
|
||||
{
|
||||
CHECK(_partita, "Partita nulla");
|
||||
}
|
||||
|
||||
|
||||
int TRiga_partite::read(TBaseisamfile& f, word op)
|
||||
{
|
||||
int err = TRectype::read(f, op);
|
||||
if (err == NOERR && get_int(PART_TIPOMOV) == 1)
|
||||
{
|
||||
TRiga_scadenze* s = new TRiga_scadenze(this);
|
||||
copy_key_to_row(*s);
|
||||
err = _recarr.read(s); // Deve esistere almento una scadenza
|
||||
#ifdef DBG
|
||||
if (_recarr.rows() == 0)
|
||||
yesnofatal_box("Riga di fattura senza nessuna scadenza");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
_recarr.destroy_rows();
|
||||
return err;
|
||||
}
|
||||
|
||||
int TRiga_partite::ultimo_pagamento(int r) const
|
||||
{
|
||||
const TRiga_scadenze& s = rata(r);
|
||||
return s.rows_array().last_row();
|
||||
}
|
||||
|
||||
bool TRiga_partite::update(const TRectype& vec, const TRectype& nuo, const char* field)
|
||||
{
|
||||
real totale(get(field));
|
||||
totale -= vec.get_real(field);
|
||||
totale += nuo.get_real(field);
|
||||
put(field, totale);
|
||||
return totale.is_zero();
|
||||
}
|
||||
|
||||
bool TRiga_partite::update(const TImporto& vec, const TImporto& nuo,
|
||||
const char* sez, const char* val)
|
||||
{
|
||||
bool zero = FALSE;
|
||||
TImporto grow(nuo); grow -= vec; // Variazione al totale
|
||||
|
||||
if (!grow.is_zero())
|
||||
{
|
||||
const char sezione = get_char(sez); // Sezione del totale
|
||||
TImporto totale;
|
||||
if (sezione > ' ') // Se c'era una sezione (e quindi un importo) ...
|
||||
totale.set(sezione, get_real(val)); // ... inizializza il totale
|
||||
else
|
||||
CHECKS(vec.is_zero(), "Sezione errata per l'importo ", val);
|
||||
totale += grow; // incrementa il totale
|
||||
totale.normalize();
|
||||
put(sez, totale.sezione()); // Aggiorna il totale sul record
|
||||
put(val, totale.valore());
|
||||
zero = totale.is_zero();
|
||||
}
|
||||
else
|
||||
zero = get_real(val).is_zero();
|
||||
|
||||
return zero;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TPartita
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
TPartita::TPartita(const TBill& clifo, int anno, const char* num)
|
||||
: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP")
|
||||
{
|
||||
read(clifo, anno, num);
|
||||
}
|
||||
|
||||
TPartita::TPartita()
|
||||
: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP")
|
||||
{}
|
||||
|
||||
// Costruisce le righe della partita
|
||||
bool TPartita::read(const TBill& clifo, int anno, const char* num)
|
||||
{
|
||||
TRiga_partite* partita = new TRiga_partite(this); // Record campione della partita
|
||||
partita->put(PART_TIPOCF, clifo.tipo()); // Tipo clifo
|
||||
if (clifo.tipo() <= ' ')
|
||||
{
|
||||
partita->put(PART_GRUPPO, clifo.gruppo()); // Scrivi gruppo e conto solamente
|
||||
partita->put(PART_CONTO, clifo.conto()); // nei conti normali (no clifo)
|
||||
}
|
||||
partita->put(PART_SOTTOCONTO, clifo.sottoconto()); // Sottoconto o codice clifo
|
||||
partita->put(PART_ANNO, anno); // Anno partita
|
||||
partita->put(PART_NUMPART, num); // Numero partita
|
||||
_part.read(partita);
|
||||
|
||||
#ifdef DBG
|
||||
for (int p = last(); p > 0; p = pred(p))
|
||||
CHECKD(riga(p)._partita == this, "Riga partite inconsistente", p);
|
||||
#endif
|
||||
|
||||
TRectype unas(LF_PAGSCA); // Record campione pagamenti non assegnati
|
||||
unas.zero();
|
||||
unas.put(PART_TIPOCF, partita->get(PART_TIPOCF)); // Copia chiave partite
|
||||
unas.put(PART_GRUPPO, partita->get(PART_GRUPPO));
|
||||
unas.put(PART_CONTO, partita->get(PART_CONTO));
|
||||
unas.put(PART_SOTTOCONTO, partita->get(PART_SOTTOCONTO));
|
||||
unas.put(PART_ANNO, partita->get(PART_ANNO));
|
||||
unas.put(PART_NUMPART, partita->get(PART_NUMPART));
|
||||
unas.put(PART_NRIGA, 0); // Numeri magici di non assegamento
|
||||
unas.put(SCAD_NRATA, 0);
|
||||
_unassigned.read(unas);
|
||||
|
||||
return ok();
|
||||
}
|
||||
|
||||
bool TPartita::reread()
|
||||
{
|
||||
TBill zio;
|
||||
conto(zio);
|
||||
const int year = anno();
|
||||
const TString16 num = numero();
|
||||
return read(zio, year, num);
|
||||
}
|
||||
|
||||
bool TPartita::write(bool re)
|
||||
{
|
||||
const bool ok = _part.write(re);
|
||||
return ok;
|
||||
}
|
||||
|
||||
TImporto TPartita::importo_speso(long nreg, int numrig) const
|
||||
{
|
||||
TImporto imp;
|
||||
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRectype& pag = riga(r);
|
||||
|
||||
const long reg = pag.get_long(PART_NREG);
|
||||
if (reg == nreg)
|
||||
{
|
||||
const int num = pag.get_int(PART_NUMRIG);
|
||||
if (num == numrig)
|
||||
{
|
||||
imp = TImporto(pag.get_char(PART_SEZ), pag.get_real(PART_IMPORTO));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return imp;
|
||||
}
|
||||
|
||||
|
||||
void TPartita::update_reg_num(long nreg, const TRectype& mov)
|
||||
{
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
{
|
||||
TRectype& pag = _part.row(r, FALSE);
|
||||
|
||||
const long reg = pag.get_long(PART_NREG);
|
||||
if (reg == nreg)
|
||||
{
|
||||
pag.put(PART_NREG, mov.get(MOV_NUMREG));
|
||||
pag.put(PART_DATAREG, mov.get(MOV_DATAREG));
|
||||
pag.put(PART_NUMDOC, mov.get(MOV_NUMDOC));
|
||||
pag.put(PART_DATADOC, mov.get(MOV_DATADOC));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Calcola la riga di movimento relativa a una riga partita
|
||||
int TPartita::rig2mov(int rp) const
|
||||
{
|
||||
const TRiga_partite& r = riga(rp);
|
||||
return r.get_int(PART_NUMRIG);
|
||||
}
|
||||
|
||||
// Calcola la riga di partita relativa a una riga movimento
|
||||
int TPartita::mov2rig(long numreg, int rm) const
|
||||
{
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
if (row.get_long(PART_NREG) == numreg && row.get_int(PART_NUMRIG) == rm)
|
||||
return r;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Trova la prima riga della partita contenente una fattura
|
||||
int TPartita::prima_fattura() const
|
||||
{
|
||||
const int lastrow = last();
|
||||
for (int r = first(); r <= lastrow; r = succ(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
const int tipomov = row.get_int(PART_TIPOMOV);
|
||||
if (tipomov == 1 || tipomov == 2)
|
||||
return r;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const
|
||||
{
|
||||
doc = pag = imp = TImporto('D', ZERO);
|
||||
|
||||
for (int r = _part.last_row(); r > 0; r = pred(r))
|
||||
{
|
||||
const TRiga_partite& row = riga(r);
|
||||
TImporto i(row.get_char(PART_SEZ), row.get_real(PART_IMPORTO));
|
||||
switch (row.get_int(PART_TIPOMOV))
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
doc += i; // documenti
|
||||
break;
|
||||
case 3:
|
||||
pag += i; // pagamenti
|
||||
break;
|
||||
default:
|
||||
imp += i; // altri importi
|
||||
break;
|
||||
}
|
||||
|
||||
i.set(row.get_char(PART_SEZ), row.get_real(PART_ABBUONI));
|
||||
imp += i;
|
||||
|
||||
i.set(row.get_char(PART_SEZ), row.get_real(PART_DIFFCAM));
|
||||
imp += i;
|
||||
}
|
||||
|
||||
saldo = doc;
|
||||
saldo += pag;
|
||||
saldo += imp;
|
||||
}
|
||||
|
||||
|
||||
bool TPartita::utilizzata(int nrigp) const
|
||||
{
|
||||
for (int p = _part.last_row(); p > 0; p = pred(p))
|
||||
{
|
||||
const TRiga_partite& fatt = riga(p);
|
||||
const int tipomov = fatt.get_int(PART_TIPOMOV);
|
||||
if (tipomov == 1)
|
||||
{
|
||||
for (int r = fatt.rate(); r > 0; r--)
|
||||
{
|
||||
const TRiga_scadenze& scad = fatt.rata(r);
|
||||
if (scad.rows_array().exist(nrigp))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool TPartita::modifica_pagamento(const TRectype& new_pag,
|
||||
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
||||
char& new_ap, TImporto& new_abb, TImporto& new_diffcam)
|
||||
{
|
||||
const int nriga = new_pag.get_int(PAGSCA_NRIGA);
|
||||
const TRiga_partite& fattura = riga(nriga);
|
||||
|
||||
const int nrata = new_pag.get_int(PAGSCA_NRATA);
|
||||
TRiga_scadenze& scaden = fattura.rata(nrata);
|
||||
|
||||
const int nrigp = new_pag.get_int(PAGSCA_NRIGP);
|
||||
const TRectype& old_pag = scaden.row(nrigp);
|
||||
|
||||
const bool empty = scaden.modifica_pagamento(new_pag,
|
||||
old_ap, old_abb, old_diffcam,
|
||||
new_ap, new_abb, new_diffcam);
|
||||
|
||||
if (empty && !utilizzata(nrigp))
|
||||
_part.destroy_row(nrigp);
|
||||
|
||||
return empty;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////
|
||||
// TPartite_array
|
||||
///////////////////////////////////////////////////////////
|
||||
|
||||
// Certified 99%
|
||||
const TString& TPartite_array::key(const TBill& clifo, int anno, const char* num)
|
||||
{
|
||||
if (clifo.tipo() > ' ')
|
||||
_key.format("%c%3d%3d%6ld%4d%s", clifo.tipo(), 0, 0, clifo.sottoconto(), anno, num);
|
||||
else
|
||||
_key.format("%c%3d%3d%6ld%4d%s",
|
||||
clifo.tipo(), clifo.gruppo(), clifo.conto(), clifo.sottoconto(), anno, num);
|
||||
return _key;
|
||||
}
|
||||
|
||||
// Certified 99%
|
||||
TPartita* TPartite_array::find(const TBill& clifo, int anno, const char* num, bool create)
|
||||
{
|
||||
const TString& k = key(clifo, anno, num);
|
||||
TPartita* p = (TPartita*)objptr(k);
|
||||
if (p == NULL && create)
|
||||
{
|
||||
p = new TPartita(clifo, anno, num);
|
||||
if (p->ok())
|
||||
add(k, p);
|
||||
else
|
||||
{
|
||||
delete p;
|
||||
p = NULL;
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
TPartita* TPartite_array::find(const TRectype& r, bool create)
|
||||
{
|
||||
TBill zio; zio.get(r);
|
||||
const int anno = r.get_int(PART_ANNO);
|
||||
const char* num = r.get_str(PART_NUMPART);
|
||||
return find(zio, anno, num, create);
|
||||
}
|
||||
|
||||
TPartita& TPartite_array::partita(const TBill& clifo, int anno, const char* num)
|
||||
{
|
||||
TPartita* game = find(clifo, anno, num, TRUE);
|
||||
CHECKS(game, "Partita errata ", num);
|
||||
return *game;
|
||||
}
|
||||
|
||||
TPartita& TPartite_array::partita(const TRectype& r)
|
||||
{
|
||||
TPartita* game = find(r, TRUE);
|
||||
CHECK(game, "Partita errata");
|
||||
return *game;
|
||||
}
|
||||
|
||||
bool TPartite_array::write(bool re)
|
||||
{
|
||||
int err = NOERR;
|
||||
|
||||
TPartita* game;
|
||||
restart();
|
||||
while ((game = (TPartita*)get()) != NULL)
|
||||
{
|
||||
err = game->write(re);
|
||||
if (err != NOERR) // L'errore viene gia' segnalato dalla partita
|
||||
break;
|
||||
}
|
||||
|
||||
return err == NOERR;
|
||||
}
|
||||
|
||||
// Aggiunge all'array tutte le partite che si riferiscono alla registrazione nreg
|
||||
int TPartite_array::add_reg_num(long nreg, int numrig)
|
||||
{
|
||||
TRelation rel(LF_PARTITE);
|
||||
TRectype& part = rel.lfile().curr();
|
||||
|
||||
// Costruzione filtro del cursore
|
||||
part.zero();
|
||||
part.put(PART_NREG, nreg);
|
||||
if (numrig > 0)
|
||||
part.put(PART_NUMRIG, numrig);
|
||||
|
||||
const TRectype filter(part);
|
||||
|
||||
TCursor cur(&rel, "", 2, &filter, &filter);
|
||||
|
||||
for (cur = 0; cur.ok(); ++cur)
|
||||
partita(part); // Aggiungi partita se non esiste gia'
|
||||
|
||||
return (int)cur.items();
|
||||
}
|
||||
|
||||
TImporto TPartite_array::importo_speso(long nreg, int numrig)
|
||||
{
|
||||
TImporto imp;
|
||||
add_reg_num(nreg, numrig);
|
||||
for (TPartita* game = first(); game; game = next())
|
||||
imp += game->importo_speso(nreg, numrig);
|
||||
return imp;
|
||||
}
|
||||
|
||||
void TPartite_array::update_reg_num(long nreg, const TRectype& mov)
|
||||
{
|
||||
add_reg_num(nreg, 0);
|
||||
for (TPartita* game = first(); game; game = next())
|
||||
game->update_reg_num(nreg, mov);
|
||||
}
|
||||
|
||||
|
191
cg/pagament.h
191
cg/pagament.h
@ -1,10 +1,6 @@
|
||||
#ifndef __PAGAMENT_H
|
||||
#define __PAGAMENT_H
|
||||
|
||||
#ifndef __ASSOC_H
|
||||
#include <assoc.h>
|
||||
#endif
|
||||
|
||||
#ifndef __MSKSHEET_H
|
||||
#include <msksheet.h>
|
||||
#endif
|
||||
@ -17,10 +13,6 @@
|
||||
#include <tabutil.h>
|
||||
#endif
|
||||
|
||||
#ifndef __CONTO_H
|
||||
#include "conto.h"
|
||||
#endif
|
||||
|
||||
// Error codes for pagation
|
||||
const word P_OK = 0x0000; // ok
|
||||
const word P_RSUM = 0x0001; // percentages do not sum up to 100
|
||||
@ -165,187 +157,4 @@ public:
|
||||
virtual ~TPagamento() {}
|
||||
};
|
||||
|
||||
|
||||
#ifndef __PARTITE_H
|
||||
#include <partite.h>
|
||||
#endif
|
||||
|
||||
class TTree_rectype : public TRectype
|
||||
{
|
||||
protected:
|
||||
TRecord_array _recarr;
|
||||
|
||||
void copy_key_to_row(TRectype& row) const;
|
||||
int fill_array();
|
||||
|
||||
protected: // TRectype
|
||||
virtual TObject* dup() const;
|
||||
|
||||
virtual int read(TBaseisamfile& f, word op = _isequal);
|
||||
virtual int next(TBaseisamfile& f);
|
||||
virtual int write(TBaseisamfile& f) const;
|
||||
virtual int rewrite(TBaseisamfile& f) const;
|
||||
virtual int remove(TBaseisamfile& f);
|
||||
|
||||
public:
|
||||
const TRecord_array& rows_array() const { return _recarr; }
|
||||
TRecord_array& rows_array() { return _recarr; }
|
||||
const TRectype& row(int r) const { return ((TRecord_array&)_recarr).row(r, FALSE); }
|
||||
TRectype& row(int r, bool create) { return _recarr.row(r, create); }
|
||||
|
||||
int last() const { return _recarr.last_row(); }
|
||||
int pred(int r) const { return _recarr.pred_row(r); }
|
||||
|
||||
TTree_rectype(const TRectype& testata, const TRectype& riga, const char* num);
|
||||
TTree_rectype(int testata, int riga, const char* num);
|
||||
TTree_rectype(const TTree_rectype& t);
|
||||
virtual ~TTree_rectype() {}
|
||||
};
|
||||
|
||||
|
||||
class TRiga_scadenze : public TTree_rectype
|
||||
{
|
||||
friend class TPartita;
|
||||
friend class TRiga_partite;
|
||||
|
||||
TRiga_partite* _riga;
|
||||
|
||||
protected:
|
||||
char calcola_abbuono(TImporto& abbuono, bool val) const;
|
||||
TImporto calcola_differenza_cambio(bool update);
|
||||
|
||||
bool modifica_pagamento(const TRectype& new_pag,
|
||||
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
||||
char& new_ap, TImporto& new_abb, TImporto& new_diffcam);
|
||||
|
||||
protected: // TRecord_tree
|
||||
virtual TObject* dup() const { return new TRiga_scadenze(*this); }
|
||||
|
||||
public:
|
||||
int pagata() const; // Riga che chiude la rata o 0 se non pagata completamente
|
||||
|
||||
real residuo() const;
|
||||
|
||||
bool in_valuta() const;
|
||||
|
||||
TPartita& partita() const;
|
||||
TRiga_partite& riga() const { CHECK(_riga, "Riga nulla"); return *_riga; } // Riga partite
|
||||
|
||||
TImporto importo_pagato(bool val) const;
|
||||
TImporto importo_da_pagare(bool val) const;
|
||||
|
||||
TRiga_scadenze(TRiga_partite* riga);
|
||||
TRiga_scadenze(const TRiga_scadenze& s);
|
||||
virtual ~TRiga_scadenze() {}
|
||||
};
|
||||
|
||||
class TRiga_partite : public TTree_rectype
|
||||
{
|
||||
friend class TPartita;
|
||||
friend class TRiga_scadenze;
|
||||
TPartita* _partita;
|
||||
|
||||
protected:
|
||||
bool update(const TRectype& vec, const TRectype& nuo, const char* field);
|
||||
bool update(const TImporto& vec, const TImporto& nuo, const char* sez, const char* val);
|
||||
|
||||
public: // TTree_rectype
|
||||
virtual TObject* dup() const { return new TRiga_partite(*this); }
|
||||
virtual int read(TBaseisamfile& f, word op);
|
||||
|
||||
public:
|
||||
int rate() const { return _recarr.rows(); }
|
||||
TRiga_scadenze& rata(int r) const { return (TRiga_scadenze&)_recarr.row(r); }
|
||||
|
||||
int ultimo_pagamento(int rata) const;
|
||||
char sezione() const { return get_char("SEZ"); }
|
||||
|
||||
TPartita& partita() const { CHECK(_partita, "Partita nulla"); return *_partita; }
|
||||
|
||||
TRiga_partite(TPartita* game);
|
||||
TRiga_partite(const TRiga_partite& r);
|
||||
virtual ~TRiga_partite() {}
|
||||
};
|
||||
|
||||
class TPartita : public TObject
|
||||
{
|
||||
TRecord_array _part;
|
||||
TRecord_array _unassigned;
|
||||
|
||||
public: // TObject
|
||||
virtual bool ok() const { return _part.rows() > 0; }
|
||||
|
||||
public:
|
||||
TRiga_partite& riga(int r) const { return (TRiga_partite&)_part.row(r); }
|
||||
TRiga_partite& nuova_riga() { return (TRiga_partite&)_part.row(last()+1, TRUE); }
|
||||
|
||||
int succ(int r) const { return _part.succ_row(r); }
|
||||
int pred(int r) const { return _part.pred_row(r); }
|
||||
int first() const { return _part.first_row(); }
|
||||
int last() const { return _part.last_row(); }
|
||||
|
||||
bool reread();
|
||||
bool read(const TBill& clifo, int anno, const char* num);
|
||||
bool write(bool re = FALSE);
|
||||
bool rewrite() { return write(TRUE); }
|
||||
|
||||
int mov2rig(long nreg, int rmov) const;
|
||||
int rig2mov(int rmov) const;
|
||||
int prima_fattura() const;
|
||||
bool utilizzata(int r) const; // Controlla se esistono pagamenti sommati alla riga r
|
||||
|
||||
void conto(TBill& c) const { c.get(_part.key()); }
|
||||
int anno() const { return _part.key().get_int(PART_ANNO); }
|
||||
const TString& numero() const { return _part.key().get(PART_NUMPART); }
|
||||
const TString& descrizione() const { return _part.key().get(PART_DESCR); }
|
||||
|
||||
TImporto importo_speso(long numreg, int numrig) const;
|
||||
void update_reg_num(long nreg, const TRectype& mov);
|
||||
void calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const;
|
||||
|
||||
bool modifica_pagamento(const TRectype& new_pag,
|
||||
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
||||
char& new_ap, TImporto& new_abb, TImporto& new_diffcam);
|
||||
|
||||
TPartita(const TBill& clifo, int anno, const char* num);
|
||||
TPartita();
|
||||
};
|
||||
|
||||
|
||||
class TPartite_array : private TAssoc_array
|
||||
{
|
||||
TString80 _key; // Work string
|
||||
|
||||
protected:
|
||||
const TString& key(const TBill& clifo, int anno, const char* num); // Build key for TAssoc_array
|
||||
TPartita* find(const TBill& clifo, int anno, const char* numero, bool create);
|
||||
TPartita* find(const TRectype& part, bool create);
|
||||
|
||||
public: // TAssoc_array
|
||||
virtual void destroy() { TAssoc_array::destroy(); }
|
||||
|
||||
public:
|
||||
TPartita& partita(const TBill& clifo, int anno, const char* numero);
|
||||
TPartita& partita(const TRectype& r);
|
||||
|
||||
TPartita* exist(const TBill& clifo, int anno, const char* numero) const
|
||||
{ return ((TPartite_array*)this)->find(clifo, anno, numero, FALSE); }
|
||||
|
||||
TPartita* exist(const TRectype& part) const
|
||||
{ return ((TPartite_array*)this)->find(part, FALSE); }
|
||||
|
||||
bool write(bool re = FALSE);
|
||||
bool rewrite() { return write(TRUE); }
|
||||
|
||||
int add_reg_num(long numreg, int numrig);
|
||||
TImporto importo_speso(long numreg, int numrig);
|
||||
void update_reg_num(long nreg, const TRectype& mov);
|
||||
|
||||
TPartita* first() { restart(); return next(); }
|
||||
TPartita* next() { return (TPartita*)get(); }
|
||||
|
||||
TPartite_array() {}
|
||||
virtual ~TPartite_array() {}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user