1995-11-09 08:05:53 +00:00
|
|
|
|
#include <config.h>
|
1999-04-06 15:34:39 +00:00
|
|
|
|
#include <currency.h>
|
1995-09-08 10:57:44 +00:00
|
|
|
|
#include <mask.h>
|
1996-12-12 16:17:35 +00:00
|
|
|
|
#include <relation.h>
|
1995-09-08 10:57:44 +00:00
|
|
|
|
|
1997-06-20 08:52:24 +00:00
|
|
|
|
#include "cgsaldac.h"
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
|
|
|
|
#include <mov.h>
|
1995-12-19 15:53:50 +00:00
|
|
|
|
#include <rmov.h>
|
2004-06-25 10:18:43 +00:00
|
|
|
|
#include <rcausali.h>
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TTree_rectype
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TTree_rectype::TTree_rectype(const TRectype& testa, const TRectype& riga, const char* num)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TRectype(testa), _recarr(riga, num)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TTree_rectype::TTree_rectype(int testa, int riga, const char* num)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TRectype(testa), _recarr(riga, num)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TTree_rectype::TTree_rectype(const TTree_rectype& t)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TRectype(t), _recarr(t._recarr)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TObject* TTree_rectype::dup() const
|
|
|
|
|
{
|
|
|
|
|
TTree_rectype* r = new TTree_rectype(*this);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
void TTree_rectype::renum_key(const char* field, const char* val)
|
|
|
|
|
{
|
|
|
|
|
TRectype::renum_key(field, val);
|
|
|
|
|
_recarr.renum_key(field, val);
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
void TTree_rectype::copy_key_to_row(TRectype& row) const
|
|
|
|
|
{
|
2008-12-10 16:55:49 +00:00
|
|
|
|
const RecDes& recd = rec_des(); // Descrizione del record della testata
|
1995-08-25 07:39:49 +00:00
|
|
|
|
row.zero();
|
2008-12-10 16:55:49 +00:00
|
|
|
|
const KeyDes& kd = recd.Ky[0]; // Memento! Gli indici delle chiavi partono da zero!
|
1995-09-19 15:43:43 +00:00
|
|
|
|
for (int i = kd.NkFields-1; i >= 0; i--)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
const int nf = kd.FieldSeq[i] % MaxFields;
|
2008-12-10 16:55:49 +00:00
|
|
|
|
const RecFieldDes& rf = recd.Fd[nf];
|
1995-08-25 07:39:49 +00:00
|
|
|
|
const char* name = rf.Name;
|
|
|
|
|
const TString& val = get(name);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
row.renum_key(name, val);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRectype& TTree_rectype::new_row(int r)
|
|
|
|
|
{
|
|
|
|
|
if (r <= 0)
|
|
|
|
|
r = last()+1;
|
1997-06-02 08:40:24 +00:00
|
|
|
|
CHECKD(!exist(r), "Ue' pirla! Esiste gia' la riga ", r);
|
2010-01-27 15:37:13 +00:00
|
|
|
|
TRectype& row = rows_array().row(r, true);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
int TTree_rectype::fill_array()
|
|
|
|
|
{
|
|
|
|
|
TRectype* row = (TRectype*)_recarr.key().dup();
|
|
|
|
|
copy_key_to_row(*row);
|
|
|
|
|
const int err = _recarr.read(row);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int TTree_rectype::read(TBaseisamfile& f, word op, word lockop)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int err = TRectype::read(f, op, lockop);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
fill_array();
|
|
|
|
|
else
|
|
|
|
|
_recarr.destroy_rows();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int TTree_rectype::write(TBaseisamfile& f) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int err = TRectype::write(f);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
err = _recarr.write();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int TTree_rectype::rewrite(TBaseisamfile& f) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int err = TRectype::rewrite(f);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
err = _recarr.rewrite();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int TTree_rectype::remove(TBaseisamfile& f) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1997-06-02 10:26:09 +00:00
|
|
|
|
int err = TRectype::remove(f);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (err == NOERR)
|
|
|
|
|
err = _recarr.remove();
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// Valuta
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TValuta::TValuta(const char* cod, const TDate& dat, const real& cam, exchange_type eur)
|
|
|
|
|
: _cod(cod), _dat(dat), _cam(cam), _et(eur)
|
1995-09-08 10:57:44 +00:00
|
|
|
|
{
|
|
|
|
|
adjust();
|
|
|
|
|
}
|
|
|
|
|
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TValuta::TValuta() : _cod(""), _dat(TODAY), _cam(ZERO), _et(_exchange_undefined)
|
1999-04-06 15:34:39 +00:00
|
|
|
|
{
|
|
|
|
|
adjust();
|
|
|
|
|
}
|
1995-09-08 10:57:44 +00:00
|
|
|
|
|
|
|
|
|
void TValuta::adjust()
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
const TCurrency this_cur(ZERO, _cod, _cam, _et);
|
|
|
|
|
if (this_cur.is_firm_value())
|
1996-01-03 12:10:02 +00:00
|
|
|
|
{
|
|
|
|
|
_cod.cut(0);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
_cam = ZERO;
|
1999-10-22 10:00:18 +00:00
|
|
|
|
_et = _exchange_undefined;
|
1996-01-29 08:11:28 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (_cam < ZERO)
|
|
|
|
|
_cam = ZERO;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
_cod = this_cur.get_value();
|
1996-01-29 08:11:28 +00:00
|
|
|
|
}
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (_et == _exchange_undefined)
|
|
|
|
|
this_cur.get_change(_et);
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-12 07:58:03 +00:00
|
|
|
|
int TValuta::compare(const TSortable& s) const
|
|
|
|
|
{
|
|
|
|
|
const TValuta& v = (const TValuta&)s;
|
2010-01-27 15:37:13 +00:00
|
|
|
|
return _cod.compare(v._cod, -1, true); // qui verificare
|
1995-09-12 07:58:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
void TValuta::get(const TRectype& rec)
|
|
|
|
|
{
|
|
|
|
|
_cod = rec.get("CODVAL");
|
|
|
|
|
_dat = rec.get("DATACAM");
|
|
|
|
|
_cam = rec.get_real("CAMBIO");
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (rec.exist("CONTROEURO"))
|
1999-10-22 10:00:18 +00:00
|
|
|
|
_et = rec.get_bool("CONTROEURO") ? _exchange_contro : _exchange_base;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
else
|
1999-10-22 10:00:18 +00:00
|
|
|
|
_et = _exchange_undefined;
|
1995-09-08 10:57:44 +00:00
|
|
|
|
adjust();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TValuta::put(TRectype& rec) const
|
|
|
|
|
{
|
1995-09-29 16:21:08 +00:00
|
|
|
|
if (in_lire())
|
|
|
|
|
{
|
|
|
|
|
rec.zero("CODVAL");
|
|
|
|
|
rec.zero("DATACAM");
|
|
|
|
|
rec.zero("CAMBIO");
|
1999-10-22 10:00:18 +00:00
|
|
|
|
if (rec.exist("CONTROEURO"))
|
|
|
|
|
rec.zero("CONTROEURO");
|
1995-09-29 16:21:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
1995-12-23 09:41:46 +00:00
|
|
|
|
rec.put("CODVAL", _cod);
|
1995-09-29 16:21:08 +00:00
|
|
|
|
rec.put("DATACAM", _dat);
|
1995-12-23 09:41:46 +00:00
|
|
|
|
rec.put("CAMBIO", _cam);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (rec.exist("CONTROEURO"))
|
1999-10-22 10:00:18 +00:00
|
|
|
|
rec.put("CONTROEURO", _et == _exchange_contro ? "X" : "");
|
1995-09-29 16:21:08 +00:00
|
|
|
|
}
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
void TValuta::set(TMask& m, short v, short d, short c, short e) const
|
1995-09-08 10:57:44 +00:00
|
|
|
|
{
|
1995-09-29 16:21:08 +00:00
|
|
|
|
if (in_lire())
|
|
|
|
|
{
|
|
|
|
|
m.reset(v);
|
|
|
|
|
m.reset(d);
|
|
|
|
|
m.reset(c);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (e && m.id2pos(e) >= 0)
|
|
|
|
|
m.reset(e);
|
1995-09-29 16:21:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m.set(v, _cod);
|
|
|
|
|
m.set(d, _dat.string());
|
|
|
|
|
m.set(c, _cam.string());
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (e && m.id2pos(e) >= 0)
|
1999-10-22 10:00:18 +00:00
|
|
|
|
m.set(e, _et == _exchange_contro ? "X" : "");
|
1995-09-29 16:21:08 +00:00
|
|
|
|
}
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
void TValuta::get(const TMask& m, short v, short d, short c, short e)
|
1995-09-08 10:57:44 +00:00
|
|
|
|
{
|
1996-01-03 12:10:02 +00:00
|
|
|
|
_cod = m.get(v);
|
|
|
|
|
_dat = m.get(d);
|
1995-12-29 11:55:59 +00:00
|
|
|
|
_cam = m.get_real(c);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
if (e && m.id2pos(e) >= 0)
|
1999-10-22 10:00:18 +00:00
|
|
|
|
_et = m.get_bool(e) ? _exchange_contro : _exchange_base;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
else
|
1999-10-22 10:00:18 +00:00
|
|
|
|
_et = _exchange_undefined;
|
1995-09-08 10:57:44 +00:00
|
|
|
|
adjust();
|
|
|
|
|
}
|
|
|
|
|
|
1995-12-23 09:41:46 +00:00
|
|
|
|
void TValuta::set(const TValuta& v)
|
|
|
|
|
{
|
|
|
|
|
_cod = v._cod;
|
|
|
|
|
_dat = v._dat;
|
1999-07-16 14:59:11 +00:00
|
|
|
|
_cam = v._cam;
|
1999-10-22 10:00:18 +00:00
|
|
|
|
_et = v._et;
|
1995-12-23 09:41:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
real TValuta::lit2val(const real& lit) const
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TCurrency cur(lit);
|
|
|
|
|
cur.change_value(_cod, _cam, _et);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
return cur.get_num();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
real TValuta::val2lit(const real& val) const
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TCurrency cur(val, _cod, _cam, _et);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
cur.change_to_firm_val();
|
|
|
|
|
return cur.get_num();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TValuta::val2lit(real& val) const
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TCurrency cur(val, _cod, _cam, _et);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
cur.change_to_firm_val();
|
|
|
|
|
val = cur.get_num();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-01-25 17:20:49 +00:00
|
|
|
|
void TValuta::lit2val(real& lit) const
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
TCurrency cur(lit);
|
|
|
|
|
cur.change_value(_cod, _cam, _et);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
lit = cur.get_num();
|
1996-01-25 17:20:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
void TValuta::val2lit(TImporto& imp) const
|
|
|
|
|
{
|
|
|
|
|
val2lit(imp.valore());
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1996-01-25 17:20:49 +00:00
|
|
|
|
void TValuta::lit2val(TImporto& imp) const
|
|
|
|
|
{
|
|
|
|
|
lit2val(imp.valore());
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TRiga_scadenze
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
TRiga_scadenze::TRiga_scadenze(TRiga_partite* r)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TTree_rectype(LF_SCADENZE, LF_PAGSCA, "NRIGP"), _riga(r)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK(_riga, "Riga nulla");
|
1995-09-19 15:43:43 +00:00
|
|
|
|
r->copy_key_to_row(*this);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRiga_scadenze::TRiga_scadenze(const TRiga_scadenze& s)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TTree_rectype(s), _riga(s._riga)
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1996-10-09 14:16:22 +00:00
|
|
|
|
TRiga_scadenze::~TRiga_scadenze()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-26 15:07:16 +00:00
|
|
|
|
TObject* TRiga_scadenze::dup() const
|
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze* r = new TRiga_scadenze(*this);
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
TPartita& TRiga_scadenze::partita() const
|
|
|
|
|
{
|
|
|
|
|
return riga().partita();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Controlla se la fattura della rata e' in valuta
|
|
|
|
|
bool TRiga_scadenze::in_valuta() const
|
|
|
|
|
{
|
1995-09-08 10:57:44 +00:00
|
|
|
|
return riga().in_valuta();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
// Controlla se la fattura della rata e' in valuta
|
|
|
|
|
const TString& TRiga_scadenze::codice_valuta() const
|
|
|
|
|
{
|
|
|
|
|
return riga().codice_valuta();
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
// Controlla se la rata e' stata completamente pagata
|
1995-09-22 12:29:00 +00:00
|
|
|
|
bool TRiga_scadenze::chiusa(bool update) const
|
|
|
|
|
{
|
|
|
|
|
bool chiusa;
|
|
|
|
|
if (update)
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
TImporto imp(importo(true));
|
|
|
|
|
imp += importo_pagato(true);
|
1995-09-22 12:29:00 +00:00
|
|
|
|
chiusa = imp.is_zero();
|
|
|
|
|
((TRectype*)this)->put(SCAD_PAGATA, chiusa ? "X" : "");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
chiusa = get_bool(SCAD_PAGATA);
|
|
|
|
|
|
|
|
|
|
return chiusa;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-26 08:58:10 +00:00
|
|
|
|
// Calcola il totale dei pagamenti alla data (eventualmente in valuta)
|
|
|
|
|
TImporto TRiga_scadenze::importo_pagato_al(bool val, const TDate & al, int mode) const
|
|
|
|
|
{
|
|
|
|
|
CHECKD(mode > 0x0 && mode <= 0xFF, "Bad importo_pagato mode ", mode);
|
|
|
|
|
const TPartita& game = partita();
|
|
|
|
|
const bool in_val = in_valuta();
|
|
|
|
|
const char* imp_field = (val && in_val) ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
|
|
|
|
|
|
|
|
TImporto totale;
|
|
|
|
|
for (int p = last(); p > 0; p = pred(p))
|
|
|
|
|
{
|
|
|
|
|
const TRectype& pag = row(p); // Riga pagamento
|
|
|
|
|
const TRiga_partite& sum = game.riga(p); // Riga partite
|
|
|
|
|
const TDate & datapag = sum.get_date(PART_DATAPAG);
|
|
|
|
|
|
|
|
|
|
if (datapag <= al)
|
|
|
|
|
{
|
|
|
|
|
const char sez = sum.sezione();
|
|
|
|
|
|
|
|
|
|
if (mode & 0x1)
|
|
|
|
|
totale += TImporto(sez, pag.get_real(imp_field));
|
|
|
|
|
if (!in_val && (mode & 0x8)) // Le ritenute non esistono nei pagamenti in valuta
|
|
|
|
|
{
|
|
|
|
|
totale += TImporto(sez, pag.get_real(PAGSCA_RITENUTE));
|
|
|
|
|
totale += TImporto(sum.sezione_ritsoc(), pag.get_real(PAGSCA_RITSOC));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mode & 0x2) // Voglio anche gli abbuoni
|
|
|
|
|
{
|
|
|
|
|
real abb = pag.get_real(PAGSCA_ABBUONI);
|
|
|
|
|
if (!abb.is_zero())
|
|
|
|
|
{
|
|
|
|
|
if (in_val && !val) // Gli abbuoni sono sempre in valuta e quindi
|
|
|
|
|
{ // devono essere convertiti opportunamente
|
|
|
|
|
const TExchange cmb(sum);
|
|
|
|
|
TCurrency cur(abb, cmb);
|
|
|
|
|
cur.change_to_firm_val();
|
|
|
|
|
abb = cur.get_num();
|
|
|
|
|
}
|
|
|
|
|
totale += TImporto(sez, abb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_val && !val && (mode & 0x4)) // Voglio anche le differenze cambio
|
|
|
|
|
{ // Esse esistono solo nei pagamenti in valuta
|
|
|
|
|
const TImporto diffcam(sez, pag.get_real(PAGSCA_DIFFCAM));
|
|
|
|
|
totale += diffcam;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return totale.normalize();
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
// Calcola il totale dei pagamenti (eventualmente in valuta)
|
1995-09-08 10:57:44 +00:00
|
|
|
|
TImporto TRiga_scadenze::importo_pagato(bool val, int mode) const
|
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
CHECKD(mode > 0x0 && mode <= 0xFF, "Bad importo_pagato mode ", mode);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
const TPartita& game = partita();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
const bool in_val = in_valuta();
|
|
|
|
|
const char* imp_field = (val && in_val) ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
TImporto totale;
|
|
|
|
|
for (int p = last(); p > 0; p = pred(p))
|
|
|
|
|
{
|
|
|
|
|
const TRectype& pag = row(p); // Riga pagamento
|
|
|
|
|
const TRiga_partite& sum = game.riga(p); // Riga partite
|
1995-09-08 10:57:44 +00:00
|
|
|
|
const char sez = sum.sezione();
|
|
|
|
|
|
1995-11-23 14:20:03 +00:00
|
|
|
|
if (mode & 0x1)
|
1995-09-08 10:57:44 +00:00
|
|
|
|
totale += TImporto(sez, pag.get_real(imp_field));
|
1996-03-15 09:38:11 +00:00
|
|
|
|
if (!in_val && (mode & 0x8)) // Le ritenute non esistono nei pagamenti in valuta
|
2004-06-25 10:18:43 +00:00
|
|
|
|
{
|
1995-12-12 12:37:01 +00:00
|
|
|
|
totale += TImporto(sez, pag.get_real(PAGSCA_RITENUTE));
|
2004-06-25 10:18:43 +00:00
|
|
|
|
totale += TImporto(sum.sezione_ritsoc(), pag.get_real(PAGSCA_RITSOC));
|
|
|
|
|
}
|
1995-09-08 10:57:44 +00:00
|
|
|
|
|
1995-12-13 15:12:13 +00:00
|
|
|
|
if (mode & 0x2) // Voglio anche gli abbuoni
|
1995-09-08 10:57:44 +00:00
|
|
|
|
{
|
1999-10-22 10:00:18 +00:00
|
|
|
|
real abb = pag.get_real(PAGSCA_ABBUONI);
|
|
|
|
|
if (!abb.is_zero())
|
|
|
|
|
{
|
|
|
|
|
if (in_val && !val) // Gli abbuoni sono sempre in valuta e quindi
|
|
|
|
|
{ // devono essere convertiti opportunamente
|
|
|
|
|
const TExchange cmb(sum);
|
|
|
|
|
TCurrency cur(abb, cmb);
|
|
|
|
|
cur.change_to_firm_val();
|
|
|
|
|
abb = cur.get_num();
|
|
|
|
|
}
|
|
|
|
|
totale += TImporto(sez, abb);
|
|
|
|
|
}
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-23 14:20:03 +00:00
|
|
|
|
if (in_val && !val && (mode & 0x4)) // Voglio anche le differenze cambio
|
1995-12-13 15:12:13 +00:00
|
|
|
|
{ // Esse esistono solo nei pagamenti in valuta
|
1995-09-08 10:57:44 +00:00
|
|
|
|
const TImporto diffcam(sez, pag.get_real(PAGSCA_DIFFCAM));
|
|
|
|
|
totale += diffcam;
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-29 16:21:08 +00:00
|
|
|
|
return totale.normalize();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calcola l'importo da pagare (eventualmente in valuta)
|
1995-12-01 11:46:35 +00:00
|
|
|
|
TImporto TRiga_scadenze::importo(bool val) const
|
|
|
|
|
{
|
1995-09-12 07:58:03 +00:00
|
|
|
|
const TRiga_partite& fatt = riga(); // Riga fattura
|
1995-12-01 11:46:35 +00:00
|
|
|
|
const char* const imp = val && in_valuta() ? SCAD_IMPORTOVAL : SCAD_IMPORTO;
|
|
|
|
|
const TImporto i(fatt.sezione(), get_real(imp));
|
|
|
|
|
return i;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
// Calcola l'abbuono in valuta della rata e ritorna il suo tipo:
|
1995-08-25 07:39:49 +00:00
|
|
|
|
// 'A' abbuono attivo; 'P' abbuono passivo
|
1995-10-25 09:34:53 +00:00
|
|
|
|
char TRiga_scadenze::calcola_abbuono(int p, TImporto& abbuono, bool update)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-10-25 09:34:53 +00:00
|
|
|
|
char ap = ' ';
|
|
|
|
|
TRectype& pag = row(p);
|
|
|
|
|
|
|
|
|
|
const char sez = partita().riga(p).sezione();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
|
1995-10-25 09:34:53 +00:00
|
|
|
|
if (update)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-10-25 09:34:53 +00:00
|
|
|
|
if (pag.get_char(PAGSCA_ACCSAL) == 'S')
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
abbuono = importo(true);
|
1995-10-25 09:34:53 +00:00
|
|
|
|
pag.zero(PAGSCA_ABBUONI);
|
2010-01-27 15:37:13 +00:00
|
|
|
|
abbuono += importo_pagato(true, 0x0B); // Somma di importi, abbuoni e ritenute
|
1995-10-25 09:34:53 +00:00
|
|
|
|
abbuono.swap_section();
|
|
|
|
|
|
|
|
|
|
const int sign = abbuono.valore().sign();
|
|
|
|
|
if (sign != 0)
|
|
|
|
|
{
|
|
|
|
|
if (sign > 0)
|
|
|
|
|
ap = abbuono.sezione() == 'D' ? 'A' : 'P';
|
|
|
|
|
else
|
|
|
|
|
ap = abbuono.sezione() == 'D' ? 'P' : 'A';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
abbuono.valore() = ZERO;
|
1995-09-08 10:57:44 +00:00
|
|
|
|
|
1995-10-25 09:34:53 +00:00
|
|
|
|
if (ap > ' ')
|
|
|
|
|
{
|
|
|
|
|
abbuono.normalize(sez);
|
|
|
|
|
pag.put(PAGSCA_ABBUONI, abbuono.valore());
|
|
|
|
|
pag.put(PAGSCA_PASSATT, ap);
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
1995-10-25 09:34:53 +00:00
|
|
|
|
else
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-10-25 09:34:53 +00:00
|
|
|
|
pag.zero(PAGSCA_ABBUONI);
|
|
|
|
|
pag.zero(PAGSCA_PASSATT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
abbuono.set(sez, pag.get_real(PAGSCA_ABBUONI));
|
|
|
|
|
ap = pag.get_char(PAGSCA_PASSATT);
|
|
|
|
|
if (ap < ' ') ap = ' ';
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return ap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calcola la differenza cambi con la sezione da mettere nella riga contabile corrispondente
|
1995-09-08 10:57:44 +00:00
|
|
|
|
TImporto TRiga_scadenze::calcola_differenza_cambio(int p, bool update)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
TImporto diffcam;
|
|
|
|
|
|
1995-09-13 16:01:30 +00:00
|
|
|
|
TRectype& pag = row(p);
|
|
|
|
|
if (pag.get_char(PAGSCA_ACCSAL) == 'S' && in_valuta())
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-09-08 10:57:44 +00:00
|
|
|
|
const char sez = partita().riga(p).sezione();
|
|
|
|
|
|
|
|
|
|
if (update)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-12-01 11:46:35 +00:00
|
|
|
|
diffcam = importo(FALSE);
|
1995-10-25 09:34:53 +00:00
|
|
|
|
pag.zero(PAGSCA_DIFFCAM);
|
1995-11-23 14:20:03 +00:00
|
|
|
|
diffcam += importo_pagato(FALSE); // Conta anche gli abbuoni e le altre diffcam
|
1995-10-25 09:34:53 +00:00
|
|
|
|
diffcam.swap_section();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
diffcam.normalize(sez);
|
1995-10-25 09:34:53 +00:00
|
|
|
|
pag.put(PAGSCA_DIFFCAM, diffcam.valore());
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
else
|
1995-09-12 07:58:03 +00:00
|
|
|
|
{
|
1995-10-25 09:34:53 +00:00
|
|
|
|
diffcam.set(sez, pag.get_real(PAGSCA_DIFFCAM));
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (update)
|
1995-09-13 16:01:30 +00:00
|
|
|
|
pag.zero(PAGSCA_DIFFCAM);
|
1995-09-08 10:57:44 +00:00
|
|
|
|
}
|
1995-09-29 16:21:08 +00:00
|
|
|
|
|
1995-10-25 09:34:53 +00:00
|
|
|
|
return diffcam;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
TImporto TRiga_scadenze::residuo(bool val, int mode) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-12-01 11:46:35 +00:00
|
|
|
|
TImporto residuo(importo(val));
|
1995-09-08 10:57:44 +00:00
|
|
|
|
residuo += importo_pagato(val, mode); // Somma con sezione opposta
|
1995-12-01 11:46:35 +00:00
|
|
|
|
residuo.normalize();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
return residuo;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-08-26 08:58:10 +00:00
|
|
|
|
TImporto TRiga_scadenze::esposto_al(bool valuta, const TDate & al, const TDate & data_scad, const TDate & data_rischio, bool & sbf) const
|
|
|
|
|
{
|
|
|
|
|
TImporto esposto;
|
|
|
|
|
const bool rischio = data_scad != data_rischio;
|
|
|
|
|
TDate data(get(SCAD_DATASCAD));
|
|
|
|
|
const int lasts = last();
|
|
|
|
|
|
|
|
|
|
sbf = false;
|
|
|
|
|
for (int p = first(); p <= lasts; p = succ(p))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite & pag = riga().partita().riga(p);
|
|
|
|
|
TDate datapag = pag.get_date(PART_DATAPAG);
|
|
|
|
|
|
|
|
|
|
if (data.ok() && datapag > data)
|
|
|
|
|
datapag = data;
|
|
|
|
|
if (datapag <= al)
|
|
|
|
|
{
|
|
|
|
|
const int tp = pag.get_int(PART_TIPOPAG);
|
|
|
|
|
|
|
|
|
|
if (tp >= 2 && tp <= 7)
|
|
|
|
|
{
|
|
|
|
|
const char sez = pag.sezione();
|
|
|
|
|
const TImporto imp(sez, pag.get_real(valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO));
|
|
|
|
|
|
|
|
|
|
if (rischio && datapag > data_rischio && datapag <= data_scad)
|
|
|
|
|
{
|
|
|
|
|
esposto += imp;
|
|
|
|
|
sbf = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (datapag > data_scad)
|
|
|
|
|
esposto += imp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return esposto;
|
|
|
|
|
}
|
|
|
|
|
|
2006-01-09 01:15:53 +00:00
|
|
|
|
TImporto TRiga_scadenze::esposto(bool valuta, const TDate & data_scad, const TDate & data_rischio, bool & sbf) const
|
|
|
|
|
{
|
|
|
|
|
TImporto esposto;
|
|
|
|
|
const bool rischio = data_scad != data_rischio;
|
|
|
|
|
TDate data(get(SCAD_DATASCAD));
|
|
|
|
|
const int lasts = last();
|
|
|
|
|
|
|
|
|
|
sbf = false;
|
|
|
|
|
for (int p = first(); p <= lasts; p = succ(p))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite & pag = riga().partita().riga(p);
|
|
|
|
|
const int tp = pag.get_int(PART_TIPOPAG);
|
|
|
|
|
|
|
|
|
|
if (tp >= 2 && tp <= 7)
|
|
|
|
|
{
|
|
|
|
|
const char sez = pag.sezione();
|
|
|
|
|
const TImporto imp(sez, pag.get_real(valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO));
|
|
|
|
|
TDate datapag(pag.get(PART_DATAPAG));
|
|
|
|
|
|
|
|
|
|
if (data.ok() && datapag > data)
|
2009-08-26 08:58:10 +00:00
|
|
|
|
datapag = data; // controllo
|
2006-01-09 01:15:53 +00:00
|
|
|
|
if (rischio && datapag > data_rischio && datapag <= data_scad)
|
|
|
|
|
{
|
|
|
|
|
esposto += imp;
|
|
|
|
|
sbf = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (datapag > data_scad)
|
|
|
|
|
esposto += imp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return esposto;
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
2006-07-11 13:10:51 +00:00
|
|
|
|
|
1995-09-12 07:58:03 +00:00
|
|
|
|
bool TRiga_scadenze::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
|
1995-08-25 07:39:49 +00:00
|
|
|
|
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
1995-10-25 09:34:53 +00:00
|
|
|
|
char& new_ap, TImporto& new_abb, TImporto& new_diffcam,
|
|
|
|
|
bool update)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-09-12 07:58:03 +00:00
|
|
|
|
const bool in_val = in_valuta();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
const int nrigp = new_pag.get_int(PAGSCA_NRIGP);
|
|
|
|
|
const TRectype old_pag(row(nrigp));
|
|
|
|
|
TRiga_partite& sum = partita().riga(nrigp);
|
|
|
|
|
|
|
|
|
|
TImporto old_abbuono;
|
1995-10-25 09:34:53 +00:00
|
|
|
|
old_ap = calcola_abbuono(nrigp, old_abbuono, FALSE); // Vecchio abbuono in valuta
|
1995-08-25 07:39:49 +00:00
|
|
|
|
old_abb = old_abbuono; // Vecchio abbuono in lire
|
1995-09-12 07:58:03 +00:00
|
|
|
|
if (in_val)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const TString4 codval = sum.codice_valuta();
|
1999-10-22 10:00:18 +00:00
|
|
|
|
exchange_type et = _exchange_undefined;
|
2010-01-27 15:37:13 +00:00
|
|
|
|
if (sum.TRectype::exist(PART_CONTROEURO))
|
1999-10-22 10:00:18 +00:00
|
|
|
|
et = sum.get_bool(PART_CONTROEURO) ? _exchange_contro : _exchange_base;
|
|
|
|
|
TCurrency cur(old_abb.valore(), codval, sum.get_real(PART_CAMBIO), et);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
cur.change_to_firm_val();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
old_abb.valore() = cur.get_num();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
1995-10-25 09:34:53 +00:00
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
old_diffcam = calcola_differenza_cambio(nrigp, FALSE);
|
|
|
|
|
|
1995-09-12 07:58:03 +00:00
|
|
|
|
if (in_val && !valuta.in_lire())
|
|
|
|
|
valuta.put(sum);
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
row(nrigp) = new_pag;
|
1995-08-29 13:11:15 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
TImporto new_abbuono;
|
1995-10-25 09:34:53 +00:00
|
|
|
|
new_ap = calcola_abbuono(nrigp, new_abbuono, update); // Calcolo abbuono in valuta
|
|
|
|
|
|
|
|
|
|
new_abb = new_abbuono; // Calcola nuovo abbuono in lire
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (in_valuta())
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const TString4 codval = sum.codice_valuta();
|
1999-10-22 10:00:18 +00:00
|
|
|
|
exchange_type et = _exchange_undefined;
|
|
|
|
|
if (((TRectype&)sum).exist(PART_CONTROEURO))
|
|
|
|
|
et = sum.get_bool(PART_CONTROEURO) ? _exchange_contro : _exchange_base;
|
|
|
|
|
TCurrency cur(new_abb.valore(), codval, sum.get_real(PART_CAMBIO), et);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
cur.change_to_firm_val();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
new_abb.valore() = cur.get_num();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
1995-10-25 09:34:53 +00:00
|
|
|
|
|
|
|
|
|
new_diffcam = calcola_differenza_cambio(nrigp, update);
|
1995-09-08 10:57:44 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
sum.update(old_abbuono, new_abbuono, PART_SEZABB, PART_ABBUONI);
|
1995-10-25 09:34:53 +00:00
|
|
|
|
sum.update(old_diffcam, new_diffcam, PART_SEZDIFCAM, PART_DIFFCAM);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
sum.update(old_pag, new_pag, PART_IMPORTO);
|
|
|
|
|
sum.update(old_pag, new_pag, PART_IMPORTOVAL);
|
|
|
|
|
sum.update(old_pag, new_pag, PART_RITENUTE);
|
2004-06-25 10:18:43 +00:00
|
|
|
|
sum.update(old_pag, new_pag, PART_RITSOC);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1995-11-23 14:20:03 +00:00
|
|
|
|
const bool empty = new_pag.get_char(PAGSCA_ACCSAL) != 'S' &&
|
|
|
|
|
new_pag.get_real(PAGSCA_IMPORTO).is_zero() &&
|
2004-06-25 10:18:43 +00:00
|
|
|
|
new_pag.get_real(PAGSCA_RITENUTE).is_zero() &&
|
|
|
|
|
new_pag.get_real(PAGSCA_RITSOC).is_zero();
|
1995-09-08 10:57:44 +00:00
|
|
|
|
if (empty)
|
|
|
|
|
rows_array().destroy_row(nrigp);
|
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
// Aggiorna flags di chiusura
|
2010-01-27 15:37:13 +00:00
|
|
|
|
chiusa(true);
|
|
|
|
|
partita().chiusa(true);
|
1996-02-21 09:00:03 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return empty;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-11 15:44:06 +00:00
|
|
|
|
bool TRiga_scadenze::esistono_abbuoni_diffcam() const
|
|
|
|
|
{
|
|
|
|
|
bool ad = FALSE;
|
|
|
|
|
for (int p = last(); p > 0; p = pred(p))
|
|
|
|
|
{
|
|
|
|
|
const TRectype& pag = row(p);
|
|
|
|
|
if (pag.get_char(PAGSCA_ACCSAL) == 'S')
|
|
|
|
|
{
|
|
|
|
|
if (!pag.get_real(PAGSCA_ABBUONI).is_zero() ||
|
|
|
|
|
!pag.get_real(PAGSCA_DIFFCAM).is_zero())
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
ad = true;
|
1996-01-11 15:44:06 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return ad;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
bool TRiga_scadenze::elimina_pagamento(int p)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRectype old_pag(row(p));
|
|
|
|
|
old_pag.put(PAGSCA_ACCSAL, "A");
|
2004-06-25 10:18:43 +00:00
|
|
|
|
old_pag.zero(PAGSCA_IMPORTO);
|
|
|
|
|
old_pag.zero(PAGSCA_IMPORTOVAL);
|
|
|
|
|
old_pag.zero(PAGSCA_RITENUTE);
|
|
|
|
|
old_pag.zero(PAGSCA_RITSOC);
|
1995-11-23 14:20:03 +00:00
|
|
|
|
TValuta val;
|
2010-01-27 15:37:13 +00:00
|
|
|
|
return partita().modifica_pagamento(old_pag, val, true);
|
1995-08-29 13:11:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TRiga_partite
|
|
|
|
|
///////////////////////////////////////////////////////////
|
1995-08-29 13:11:15 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
TRiga_partite::TRiga_partite(TPartita* game)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TTree_rectype(LF_PARTITE, LF_SCADENZE, SCAD_NRATA), _partita(game)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
CHECK(_partita, "Partita nulla");
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRiga_scadenze* scad = new TRiga_scadenze(this);
|
|
|
|
|
copy_key_to_row(*this);
|
|
|
|
|
rows_array().set_key(scad); // Altrimenti le righe sarebbero dei TRectype!
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TRiga_partite::TRiga_partite(const TRiga_partite& r)
|
1995-08-29 13:11:15 +00:00
|
|
|
|
: TTree_rectype(r), _partita(r._partita)
|
1995-09-26 15:07:16 +00:00
|
|
|
|
{
|
|
|
|
|
update_rigaptr();
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-09 14:16:22 +00:00
|
|
|
|
TRiga_partite::~TRiga_partite()
|
|
|
|
|
{}
|
|
|
|
|
|
1995-09-26 15:07:16 +00:00
|
|
|
|
void TRiga_partite::update_rigaptr()
|
|
|
|
|
{
|
|
|
|
|
for (int i = rate(); i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze& scad = i == 0 ? (TRiga_scadenze&)rows_array().key() : rata(i);
|
|
|
|
|
scad._riga = this;
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-08-29 13:11:15 +00:00
|
|
|
|
|
1995-08-28 07:50:28 +00:00
|
|
|
|
TRiga_scadenze& TRiga_partite::new_row(int r)
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze& scad = (TRiga_scadenze&)TTree_rectype::new_row(r);
|
|
|
|
|
scad._riga = this;
|
|
|
|
|
return scad;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Elimina la rata r ed i suoi pagamenti, se r < 1 allora elimina tutte le rate
|
|
|
|
|
// Certified 99%
|
1995-11-17 10:27:24 +00:00
|
|
|
|
void TRiga_partite::elimina_rata(int r)
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
1995-11-17 10:27:24 +00:00
|
|
|
|
const int from = r <= 0 ? 1 : r;
|
|
|
|
|
const int to = r <= 0 ? rate() : r;
|
1996-01-03 12:10:02 +00:00
|
|
|
|
for (r = to; r >= from; r--) // E' necessario andare all'indietro perche'
|
|
|
|
|
{ // il metodo rate() funzioni sempre correttamente
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRiga_scadenze& scad = rata(r);
|
|
|
|
|
for (int p = scad.last(); p > 0; p = scad.pred(p))
|
1996-03-15 09:38:11 +00:00
|
|
|
|
scad.elimina_pagamento(p); // Elimina pagamento
|
|
|
|
|
rows_array().destroy_row(r); // Elimina rata
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
1995-08-28 07:50:28 +00:00
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Ritorna il numero dell'ultima rata pagata o 0 se non ce ne sono
|
|
|
|
|
// Certified 100%
|
1995-09-25 11:38:25 +00:00
|
|
|
|
int TRiga_partite::ultima_ratapagata() const
|
|
|
|
|
{
|
2004-04-28 20:36:21 +00:00
|
|
|
|
int r;
|
|
|
|
|
|
|
|
|
|
for (r = rate(); r > 0; r--)
|
1995-09-25 11:38:25 +00:00
|
|
|
|
if (rata(r).chiusa()) break;
|
|
|
|
|
return r;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Ritorna il tipo movimento di una riga di partita
|
|
|
|
|
// Certified 100%
|
1995-12-04 11:04:35 +00:00
|
|
|
|
tipo_movimento TRiga_partite::tipo() const
|
1995-11-10 13:35:00 +00:00
|
|
|
|
{
|
1996-02-16 09:51:28 +00:00
|
|
|
|
const tipo_movimento tm = (tipo_movimento)(get_char(PART_TIPOMOV)-'0');
|
|
|
|
|
#ifdef DBG
|
|
|
|
|
if (tm == tm_nessuno && get_int(PART_NRIGA) != TPartita::UNASSIGNED)
|
1996-03-15 09:38:11 +00:00
|
|
|
|
yesnofatal_box("Riga partite con un tipo losco.");
|
1996-02-16 09:51:28 +00:00
|
|
|
|
#endif
|
1995-12-04 11:04:35 +00:00
|
|
|
|
return tm;
|
1995-11-23 14:20:03 +00:00
|
|
|
|
}
|
1995-11-10 13:35:00 +00:00
|
|
|
|
|
2004-06-25 10:18:43 +00:00
|
|
|
|
// Calcola il segno delle ritenute sociali in base alla causale
|
|
|
|
|
char TRiga_partite::sezione_ritsoc() const
|
|
|
|
|
{
|
|
|
|
|
TString16 key; key << get(PART_CODCAUS) << "|14"; // Riga ritenute sociali
|
2004-09-15 14:50:57 +00:00
|
|
|
|
const char sez_cau = cache().get(LF_RCAUSALI, key, RCA_SEZIONE)[0];
|
|
|
|
|
const char sez_rit = sez_cau > ' ' ? (sez_cau == 'D' ? 'A' : 'D') : sezione();
|
|
|
|
|
return sez_rit;
|
2004-06-25 10:18:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Legge le rate relative ad una riga di fattura
|
|
|
|
|
// Certified 99%
|
1998-02-02 13:38:01 +00:00
|
|
|
|
int TRiga_partite::read(TBaseisamfile& f, word op, word lock)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1998-02-02 13:38:01 +00:00
|
|
|
|
int err = TRectype::read(f, op, lock);
|
1995-11-10 13:35:00 +00:00
|
|
|
|
if (err == NOERR && is_fattura())
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze* s = new TRiga_scadenze(this);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
err = rows_array().read(s); // Deve esistere almento una scadenza
|
1995-09-26 15:07:16 +00:00
|
|
|
|
update_rigaptr();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1995-09-19 15:43:43 +00:00
|
|
|
|
rows_array().destroy_rows();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Registra una riga e le sue eventuali rate
|
|
|
|
|
// Certified 100%
|
1995-11-10 13:35:00 +00:00
|
|
|
|
int TRiga_partite::write(TBaseisamfile& f) const
|
1996-01-31 11:52:54 +00:00
|
|
|
|
{
|
2000-10-03 13:45:12 +00:00
|
|
|
|
const int err = is_fattura() ? TTree_rectype::write(f) : TRectype::write(f);
|
1995-11-10 13:35:00 +00:00
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Aggiorna una riga e le sue eventuali rate
|
|
|
|
|
// Certified 100%
|
1995-11-10 13:35:00 +00:00
|
|
|
|
int TRiga_partite::rewrite(TBaseisamfile& f) const
|
|
|
|
|
{
|
|
|
|
|
const int err = is_fattura() ? TTree_rectype::rewrite(f) : TRectype::rewrite(f);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Elimina una riga e le sue eventuali rate
|
|
|
|
|
// Certified 100%
|
1995-11-10 13:35:00 +00:00
|
|
|
|
int TRiga_partite::remove(TBaseisamfile& f) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-11-10 13:35:00 +00:00
|
|
|
|
const int err = is_fattura() ? TTree_rectype::remove(f) : TRectype::remove(f);
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Ritorna l'indice dell'ultimo pagamento della rata r o 0 se non ce ne sono
|
|
|
|
|
// Certified 100%
|
1995-11-10 13:35:00 +00:00
|
|
|
|
int TRiga_partite::ultimo_pagamento(int r) const
|
|
|
|
|
{
|
1995-08-25 07:39:49 +00:00
|
|
|
|
const TRiga_scadenze& s = rata(r);
|
|
|
|
|
return s.last();
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Aggiorna il campo field contenente un totale sottraendo il corrispondente valore di
|
|
|
|
|
// un record prima (vec) e dopo la sua modifica (nuo)
|
|
|
|
|
// Certified 100%
|
1995-08-25 07:39:49 +00:00
|
|
|
|
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;
|
1995-08-29 13:11:15 +00:00
|
|
|
|
TImporto growth(nuo); growth -= vec; // Variazione al totale
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1995-08-29 13:11:15 +00:00
|
|
|
|
if (!growth.is_zero())
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-08-29 13:11:15 +00:00
|
|
|
|
TImporto totale(get_char(sez), get_real(val));
|
|
|
|
|
totale += growth; // incrementa il totale
|
1995-08-25 07:39:49 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
|
|
|
|
|
// Cerca una rata con abbuoni o differenze cambio
|
|
|
|
|
// Certified 99%
|
1996-01-11 15:44:06 +00:00
|
|
|
|
int TRiga_partite::ultima_rata_con_abbuoni_diffcam() const
|
2004-04-28 20:36:21 +00:00
|
|
|
|
{
|
|
|
|
|
int s;
|
|
|
|
|
|
|
|
|
|
for (s = rate(); s > 0; s--)
|
1995-10-25 09:34:53 +00:00
|
|
|
|
{
|
|
|
|
|
const TRiga_scadenze& scad = rata(s);
|
1996-01-11 15:44:06 +00:00
|
|
|
|
if (scad.esistono_abbuoni_diffcam())
|
|
|
|
|
break;
|
1995-10-25 09:34:53 +00:00
|
|
|
|
}
|
1996-01-11 15:44:06 +00:00
|
|
|
|
return s;
|
1995-10-25 09:34:53 +00:00
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
// Determina il codice valuta
|
|
|
|
|
const TString& TRiga_partite::codice_valuta() const
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
return get(PART_CODVAL);
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-01-03 12:10:02 +00:00
|
|
|
|
// Determina se una riga e' in valuta in base al codice valuta
|
1995-12-29 11:55:59 +00:00
|
|
|
|
bool TRiga_partite::in_valuta() const
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
return codice_valuta().not_empty();
|
1995-12-29 11:55:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-12-01 11:46:35 +00:00
|
|
|
|
// Calcola l'importo in lire o in valuta su di una riga di partita
|
|
|
|
|
// E' possibile considerare o meno IMPORTO, ABBUONI e DIFFCAM
|
|
|
|
|
TImporto TRiga_partite::importo(bool valuta, int mode) const
|
|
|
|
|
{
|
1996-02-21 09:00:03 +00:00
|
|
|
|
CHECKD(mode > 0x0 && mode <= 0xF, "Bad importo mode ", mode);
|
2001-05-01 08:17:07 +00:00
|
|
|
|
const bool in_lire = !in_valuta(); // Partita in lire
|
1995-12-01 11:46:35 +00:00
|
|
|
|
if (valuta && in_lire)
|
2004-06-25 10:18:43 +00:00
|
|
|
|
valuta = false;
|
1995-12-01 11:46:35 +00:00
|
|
|
|
|
|
|
|
|
TImporto i;
|
|
|
|
|
if (mode & 0x1)
|
|
|
|
|
{
|
|
|
|
|
const char* const field = valuta ? PART_IMPORTOVAL : PART_IMPORTO;
|
|
|
|
|
i.set(sezione(), get_real(field));
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
if (!is_fattura() && (mode & 0xE)) // Ci sono abbuoni, differenze cambio o ritenute?
|
1996-02-16 09:51:28 +00:00
|
|
|
|
{
|
|
|
|
|
if (valuta) // Desidero gli abbuoni in valuta
|
1995-12-01 11:46:35 +00:00
|
|
|
|
{
|
1996-02-16 09:51:28 +00:00
|
|
|
|
if (mode & 0x2)
|
|
|
|
|
{
|
1996-02-21 09:00:03 +00:00
|
|
|
|
const TImporto abbuoni(get_char(PART_SEZABB), get_real(PART_ABBUONI));
|
1996-02-16 09:51:28 +00:00
|
|
|
|
i += abbuoni;
|
|
|
|
|
}
|
|
|
|
|
// In valuta ignoro completamente le differenze cambio
|
1995-12-01 11:46:35 +00:00
|
|
|
|
}
|
1996-02-16 09:51:28 +00:00
|
|
|
|
else // Desidero gli abbuoni in lire
|
1995-12-01 11:46:35 +00:00
|
|
|
|
{
|
1995-12-12 12:37:01 +00:00
|
|
|
|
if (in_lire && (mode & 0x8))
|
2004-06-25 10:18:43 +00:00
|
|
|
|
{
|
1995-12-01 11:46:35 +00:00
|
|
|
|
i.valore() += get_real(PART_RITENUTE);
|
2004-06-25 10:18:43 +00:00
|
|
|
|
if (sezione() == sezione_ritsoc())
|
|
|
|
|
i.valore() += get_real(PART_RITSOC);
|
|
|
|
|
else
|
|
|
|
|
i.valore() -= get_real(PART_RITSOC);
|
|
|
|
|
}
|
1995-12-01 11:46:35 +00:00
|
|
|
|
|
1996-02-16 09:51:28 +00:00
|
|
|
|
if (mode & 0x2)
|
|
|
|
|
{
|
|
|
|
|
TImporto abbuoni(get_char(PART_SEZABB), get_real(PART_ABBUONI));
|
|
|
|
|
if (!in_lire) // Converto in lire gli abbuoni che sono memorizzati in valuta
|
1995-12-01 11:46:35 +00:00
|
|
|
|
{
|
2001-05-01 08:17:07 +00:00
|
|
|
|
const real cambio(get(PART_CAMBIO));
|
|
|
|
|
TCurrency cur(abbuoni.valore(), codice_valuta(), cambio);
|
|
|
|
|
cur.change_to_firm_val();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
abbuoni.valore() = cur.get_num();
|
1995-12-01 11:46:35 +00:00
|
|
|
|
}
|
|
|
|
|
i += abbuoni;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-16 09:51:28 +00:00
|
|
|
|
if (!in_lire && (mode & 0x4)) // Se ci sono e desidero le differenze cambio
|
1995-12-01 11:46:35 +00:00
|
|
|
|
{
|
|
|
|
|
const TImporto diffcam(get_char(PART_SEZDIFCAM), get_real(PART_DIFFCAM));
|
|
|
|
|
i += diffcam;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
1996-05-29 08:41:10 +00:00
|
|
|
|
// Calcola l'esposto e l' esposto SBF
|
|
|
|
|
TImporto TRiga_partite::esposto(bool valuta, const TDate & data_scad, const TDate & data_rischio, bool & sbf) const
|
|
|
|
|
{
|
|
|
|
|
TImporto esposto;
|
|
|
|
|
|
|
|
|
|
sbf = FALSE;
|
|
|
|
|
const int nrigp = get_int(PART_NRIGA);
|
|
|
|
|
const char sez = sezione();
|
|
|
|
|
const int last = _partita->last();
|
|
|
|
|
const TDate datapag(get_date(PART_DATAPAG));
|
|
|
|
|
const bool rischio = data_scad != data_rischio;
|
|
|
|
|
bool found_pag = FALSE;
|
|
|
|
|
|
|
|
|
|
for (int row = last; row > 0; row = _partita->pred(row))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite & riga = _partita->riga(row);
|
|
|
|
|
if (riga.is_fattura())
|
|
|
|
|
{
|
|
|
|
|
const int lastr = riga.rate();
|
|
|
|
|
for (int rata = lastr; rata > 0; rata--)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_scadenze& scad = riga.rata(rata);
|
|
|
|
|
if (scad.exist(nrigp))
|
|
|
|
|
{
|
|
|
|
|
const TRectype & pag = scad.row(nrigp);
|
|
|
|
|
const TImporto imp(sez, pag.get_real(valuta ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO));
|
|
|
|
|
TDate data(scad.get(SCAD_DATASCAD));
|
|
|
|
|
const int lasts = scad.last();
|
|
|
|
|
|
2010-01-27 15:37:13 +00:00
|
|
|
|
found_pag = true;
|
1996-05-29 08:41:10 +00:00
|
|
|
|
for (int p = scad.first(); p <= lasts; p = scad.succ(p))
|
|
|
|
|
{
|
|
|
|
|
if (p != nrigp)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite & prow = partita().riga(p);
|
|
|
|
|
const int tp = prow.get_int(PART_TIPOPAG);
|
|
|
|
|
if (tp >= 2 && tp <= 7)
|
|
|
|
|
{
|
2004-04-28 20:36:21 +00:00
|
|
|
|
const TDate dataprow(prow.get(PART_DATAPAG));
|
1996-05-29 08:41:10 +00:00
|
|
|
|
if (dataprow < datapag)
|
|
|
|
|
{
|
|
|
|
|
data = datapag;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (rischio && data > data_rischio && data <= data_scad)
|
|
|
|
|
{
|
|
|
|
|
esposto += imp;
|
2010-01-27 15:37:13 +00:00
|
|
|
|
sbf = true;
|
1996-05-29 08:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (data > data_scad)
|
|
|
|
|
esposto += imp;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!found_pag)
|
|
|
|
|
{
|
|
|
|
|
const TImporto imp(importo(valuta, 0x1));
|
|
|
|
|
if (rischio && datapag > data_rischio && datapag <= data_scad)
|
|
|
|
|
{
|
|
|
|
|
esposto += imp;
|
2009-08-26 08:58:10 +00:00
|
|
|
|
sbf = true;
|
1996-05-29 08:41:10 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
if (datapag > data_scad)
|
|
|
|
|
esposto += imp;
|
|
|
|
|
}
|
|
|
|
|
return esposto;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-26 08:58:10 +00:00
|
|
|
|
TImporto TRiga_partite::calcola_pagato_al(bool valuta,const TDate& al, const TDate & data_scaduto, const TDate& data_rischio, int mode) const
|
|
|
|
|
{
|
|
|
|
|
TImporto pagato;
|
|
|
|
|
|
|
|
|
|
if (is_fattura())
|
|
|
|
|
{
|
|
|
|
|
const int nrigp = get_int(PART_NRIGA);
|
|
|
|
|
const char sez = sezione();
|
|
|
|
|
const bool rischio = data_scaduto != data_rischio;
|
|
|
|
|
const int lastr = rate();
|
|
|
|
|
|
|
|
|
|
for (int r = lastr; r > 0; r--)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_scadenze& scad = rata(r);
|
|
|
|
|
const TImporto pag = scad.importo_pagato_al(valuta, al, mode);
|
|
|
|
|
|
|
|
|
|
pagato += pag;
|
|
|
|
|
if (!pag.is_zero() && rischio)
|
|
|
|
|
{
|
|
|
|
|
bool sbf = false;
|
|
|
|
|
pagato -= scad.esposto_al(valuta, al, data_scaduto, data_rischio, sbf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pagato;
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TPartita
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
1995-11-09 08:05:53 +00:00
|
|
|
|
char TPartita::_cli_align = ' ';
|
|
|
|
|
char TPartita::_for_align = ' ';
|
1995-11-07 10:03:02 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
TPartita::TPartita(const TBill& clifo, int anno, const char* num)
|
1995-11-09 08:05:53 +00:00
|
|
|
|
: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP"),
|
|
|
|
|
_align(' ')
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
read(clifo, anno, num);
|
1995-10-04 15:07:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-10-30 10:17:14 +00:00
|
|
|
|
TPartita::TPartita(const TRectype& r)
|
1995-11-09 08:05:53 +00:00
|
|
|
|
: _part(LF_PARTITE, PART_NRIGA), _unassigned(LF_PAGSCA, "NRIGP"),
|
|
|
|
|
_align(' ')
|
1995-10-30 10:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
TBill clifo; clifo.get(r);
|
|
|
|
|
if (clifo.gruppo() == 0)
|
|
|
|
|
{
|
|
|
|
|
clifo.set(r.get_int(PART_GRUPPOCL), r.get_int(PART_CONTOCL),
|
|
|
|
|
clifo.sottoconto(), clifo.tipo());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int anno = r.get_int(PART_ANNO);
|
2006-12-13 16:22:33 +00:00
|
|
|
|
const TString8 num(r.get(PART_NUMPART));
|
1995-10-30 10:17:14 +00:00
|
|
|
|
read(clifo, anno, num);
|
|
|
|
|
}
|
|
|
|
|
|
1996-10-09 14:16:22 +00:00
|
|
|
|
TPartita::~TPartita()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
1995-10-04 15:07:56 +00:00
|
|
|
|
const char* TPartita::build_key(TString& key) const
|
|
|
|
|
{
|
|
|
|
|
if (_conto.tipo() > ' ')
|
1995-11-09 08:05:53 +00:00
|
|
|
|
key.format("%c%3d%3d%6ld%4d%*s", _conto.tipo(), 0, 0, _conto.sottoconto(),
|
|
|
|
|
_anno, NUMLEN, (const char*)_num);
|
1995-10-04 15:07:56 +00:00
|
|
|
|
else
|
1995-11-09 08:05:53 +00:00
|
|
|
|
key.format("%c%3d%3d%6ld%4d%*s",
|
1995-10-04 15:07:56 +00:00
|
|
|
|
_conto.tipo(), _conto.gruppo(), _conto.conto(), _conto.sottoconto(),
|
1995-11-09 08:05:53 +00:00
|
|
|
|
_anno, NUMLEN, (const char*)_num);
|
1995-10-04 15:07:56 +00:00
|
|
|
|
return key;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
int TPartita::compare(const TSortable& s) const
|
|
|
|
|
{
|
1995-10-04 15:07:56 +00:00
|
|
|
|
TString80 key; build_key(key);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
const TPartita& p = (const TPartita&)s;
|
1995-10-04 15:07:56 +00:00
|
|
|
|
TString80 par; p.build_key(par);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
return strcmp(key, par);
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1995-11-09 08:05:53 +00:00
|
|
|
|
void TPartita::carica_allineamento()
|
1995-11-07 10:03:02 +00:00
|
|
|
|
{
|
1995-11-09 08:05:53 +00:00
|
|
|
|
TConfig cd(CONFIG_DITTA, "cg");
|
|
|
|
|
_cli_align = cd.get_bool("NrCliDx") ? 'R' : 'L';
|
|
|
|
|
_for_align = cd.get_bool("NrForDx") ? 'R' : 'L';
|
1995-11-07 10:03:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
char TPartita::allineamento_richiesto(char tipocf)
|
1995-11-09 08:05:53 +00:00
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
// Controlla se e' gia' stato caricato l'allineamento
|
1995-11-09 08:05:53 +00:00
|
|
|
|
if (_cli_align <= ' ' || _for_align <= ' ')
|
|
|
|
|
carica_allineamento();
|
1996-01-03 12:10:02 +00:00
|
|
|
|
|
1999-07-16 14:59:11 +00:00
|
|
|
|
char all;
|
1996-02-13 16:35:59 +00:00
|
|
|
|
switch (tipocf)
|
1995-11-09 08:05:53 +00:00
|
|
|
|
{
|
|
|
|
|
case 'C': all = _cli_align; break;
|
|
|
|
|
case 'F': all = _for_align; break;
|
2000-05-05 15:25:49 +00:00
|
|
|
|
default : all = (_cli_align == _for_align) ? _cli_align : 'L'; break;
|
1995-11-09 08:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
return all;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1995-11-07 10:03:02 +00:00
|
|
|
|
// Ritorna l'allineamento corrente del numero partita
|
|
|
|
|
// L = Sinistra, R = Destra, ' ' = indeterminato
|
|
|
|
|
char TPartita::allineamento_corrente() const
|
|
|
|
|
{
|
1995-11-09 08:05:53 +00:00
|
|
|
|
const TString& n = numero();
|
|
|
|
|
|
|
|
|
|
char all = n[0] == ' ' ? 'R' : 'L';
|
1996-01-11 15:44:06 +00:00
|
|
|
|
if (all == 'L' && n.len() == NUMLEN && n[NUMLEN-1] != ' ')
|
1995-11-07 10:03:02 +00:00
|
|
|
|
all = ' ';
|
|
|
|
|
return all;
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-09 08:05:53 +00:00
|
|
|
|
void TPartita::allinea(char all)
|
|
|
|
|
{
|
|
|
|
|
if (all <= ' ')
|
1996-02-13 16:35:59 +00:00
|
|
|
|
all = allineamento_richiesto(conto().tipo());
|
1995-11-09 08:05:53 +00:00
|
|
|
|
|
1995-11-10 13:35:00 +00:00
|
|
|
|
if (all == 'R')
|
|
|
|
|
_num.right_just(NUMLEN);
|
|
|
|
|
else
|
|
|
|
|
_num.trim();
|
1995-11-09 08:05:53 +00:00
|
|
|
|
|
1995-11-10 13:35:00 +00:00
|
|
|
|
if (ok())
|
|
|
|
|
{
|
|
|
|
|
_part.renum_key(PART_NUMPART, _num);
|
|
|
|
|
_unassigned.renum_key(PAGSCA_NUMPART, _num);
|
|
|
|
|
}
|
1995-11-09 08:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-01-29 08:11:28 +00:00
|
|
|
|
bool TPartita::is_on_file() const
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile partite(LF_PARTITE);
|
|
|
|
|
TRectype& part = partite.curr();
|
|
|
|
|
part.zero();
|
|
|
|
|
part.put(PART_TIPOCF, _conto.tipo());
|
|
|
|
|
if (_conto.tipo() <= ' ')
|
|
|
|
|
{
|
|
|
|
|
part.put(PART_GRUPPO, _conto.gruppo());
|
|
|
|
|
part.put(PART_CONTO, _conto.conto());
|
|
|
|
|
}
|
|
|
|
|
part.put(PART_SOTTOCONTO, _conto.sottoconto());
|
|
|
|
|
part.put(PART_ANNO, _anno);
|
|
|
|
|
part.put(PART_NUMPART, _num);
|
|
|
|
|
|
|
|
|
|
const TRectype filter(part);
|
|
|
|
|
|
|
|
|
|
// Cerca la partita usando l'allineamento richiesto dall'utente
|
|
|
|
|
const bool found = partite.read(_isgteq) == NOERR && part.compare_key(filter, 1, 1) == 0;
|
|
|
|
|
return found;
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
// Costruisce le righe della partita
|
1995-09-19 15:43:43 +00:00
|
|
|
|
bool TPartita::read(const TBill& clifo, int year, const char* num)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
_conto = clifo;
|
|
|
|
|
_anno = year;
|
|
|
|
|
_num = num;
|
1995-11-09 08:05:53 +00:00
|
|
|
|
|
2001-05-01 08:17:07 +00:00
|
|
|
|
if (allineamento_corrente() > ' ')
|
1995-11-09 08:05:53 +00:00
|
|
|
|
{
|
1995-11-10 13:35:00 +00:00
|
|
|
|
// Cerca la partita usando l'allineamento richiesto dall'utente
|
1996-03-15 09:38:11 +00:00
|
|
|
|
if (!is_on_file())
|
1995-11-09 08:05:53 +00:00
|
|
|
|
{
|
|
|
|
|
// Se non la trova inverte l'allineamento
|
|
|
|
|
if (allineamento_corrente() == 'R')
|
|
|
|
|
_num.trim();
|
|
|
|
|
else
|
|
|
|
|
_num.right_just(NUMLEN);
|
|
|
|
|
|
|
|
|
|
// Riprova a cercarla col nuovo allineamento
|
1996-03-15 09:38:11 +00:00
|
|
|
|
if (!is_on_file())
|
1995-11-09 08:05:53 +00:00
|
|
|
|
allinea(); // Non esite: e' una nuova partita!
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_num.trim();
|
1995-11-10 13:35:00 +00:00
|
|
|
|
_align = allineamento_corrente();
|
1995-11-09 08:05:53 +00:00
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRiga_partite* partita = new TRiga_partite(this); // Record campione della partita
|
|
|
|
|
TString16 str;
|
|
|
|
|
str << clifo.tipo();
|
|
|
|
|
partita->renum_key(PART_TIPOCF, str); // Tipo clifo
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (clifo.tipo() <= ' ')
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
str.cut(0); str << clifo.gruppo();
|
|
|
|
|
partita->renum_key(PART_GRUPPO, str); // Scrivi gruppo e conto solamente
|
|
|
|
|
str.cut(0); str << clifo.conto(); // nei conti normali (no clifo)
|
|
|
|
|
partita->renum_key(PART_CONTO, str);
|
|
|
|
|
}
|
|
|
|
|
str.cut(0); str << clifo.sottoconto();
|
|
|
|
|
partita->renum_key(PART_SOTTOCONTO, str); // Sottoconto o codice clifo
|
1995-10-11 11:39:50 +00:00
|
|
|
|
str.cut(0); str << _anno;
|
1995-09-19 15:43:43 +00:00
|
|
|
|
partita->renum_key(PART_ANNO, str); // Anno partita
|
1995-10-11 11:39:50 +00:00
|
|
|
|
partita->renum_key(PART_NUMPART, _num); // Numero partita
|
1995-08-25 07:39:49 +00:00
|
|
|
|
_part.read(partita);
|
1996-02-13 16:35:59 +00:00
|
|
|
|
|
|
|
|
|
if (_part.exist(UNASSIGNED))
|
|
|
|
|
_part.destroy_row(UNASSIGNED); // Elimina riga saldo;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRectype* unas = new TRectype(LF_PAGSCA); // Record pagamenti non assegnati
|
|
|
|
|
partita->copy_key_to_row(*unas);
|
|
|
|
|
unas->put(PART_NRIGA, (int)UNASSIGNED);
|
|
|
|
|
unas->put(SCAD_NRATA, (int)UNASSIGNED);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
_unassigned.read(unas);
|
|
|
|
|
|
|
|
|
|
return ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool TPartita::reread()
|
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
return read(conto(), anno(), numero());
|
1996-02-13 16:35:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TPartita::write_saldo(bool re, TRectype* rec) const
|
|
|
|
|
{
|
|
|
|
|
TImporto saldo, doc, pag, imp;
|
|
|
|
|
calcola_saldo(saldo, doc, pag, imp);
|
|
|
|
|
|
|
|
|
|
TLocalisamfile part(LF_PARTITE);
|
|
|
|
|
TRectype& sld = part.curr();
|
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
sld = _part.key(); // Copia conto, anno e numero partita
|
|
|
|
|
sld.put(PART_NRIGA, (int)UNASSIGNED); // Assegna magic line number
|
|
|
|
|
sld.put(PART_SEZ, saldo.sezione()); // Sezione saldo
|
|
|
|
|
sld.put(PART_IMPORTO, saldo.valore()); // Saldo
|
|
|
|
|
sld.put(PART_SEZABB, doc.sezione()); // Sezione documenti
|
|
|
|
|
sld.put(PART_ABBUONI, doc.valore()); // Documenti
|
|
|
|
|
sld.put(PART_SEZDIFCAM, pag.sezione()); // Sezione pagamenti
|
|
|
|
|
sld.put(PART_DIFFCAM, pag.valore()); // Pagamenti
|
|
|
|
|
sld.put(PART_REG, imp.sezione()); // Sezione altri importi
|
|
|
|
|
sld.put(PART_IMPOSTA, imp.valore()); // Altri importi
|
1996-02-13 16:35:59 +00:00
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
int r = prima_fattura(); // Cerca la prima fattura ...
|
|
|
|
|
if (r <= 0) r = first(); // ... o la prima riga valida
|
1996-02-13 16:35:59 +00:00
|
|
|
|
const TRiga_partite& row = riga(r);
|
1996-02-21 09:00:03 +00:00
|
|
|
|
|
|
|
|
|
sld.put(PART_NUMDOC, row.get(PART_NUMDOC)); // Copia estremi documento
|
1996-02-13 16:35:59 +00:00
|
|
|
|
sld.put(PART_DATADOC, row.get(PART_DATADOC));
|
|
|
|
|
sld.put(PART_DESCR, row.get(PART_DESCR));
|
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
const TValuta valuta(row); // Copia la valuta
|
|
|
|
|
valuta.put(sld);
|
|
|
|
|
|
2003-07-22 13:22:11 +00:00
|
|
|
|
// sld.put(PART_CHIUSA, row.get(PART_CHIUSA)); // Copia il flag di chiusura
|
2010-01-27 15:37:13 +00:00
|
|
|
|
sld.put(PART_CHIUSA, chiusa(true));
|
1996-02-21 09:00:03 +00:00
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
if (rec != NULL)
|
|
|
|
|
*rec = sld;
|
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
// Scrittura del record di saldo
|
1996-02-13 16:35:59 +00:00
|
|
|
|
int err = re ? part.rewrite() : part.write();
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
err = re ? part.write() : part.rewrite();
|
|
|
|
|
|
|
|
|
|
return err;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int TPartita::read_saldo(TRectype& riga,
|
|
|
|
|
TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp)
|
|
|
|
|
{
|
|
|
|
|
int err = NOERR;
|
|
|
|
|
|
|
|
|
|
if (riga.get_int(PART_NRIGA) != UNASSIGNED)
|
|
|
|
|
{
|
|
|
|
|
TLocalisamfile part(LF_PARTITE);
|
|
|
|
|
TRectype& sld = part.curr();
|
|
|
|
|
sld = riga;
|
|
|
|
|
sld.put(PART_NRIGA, (int)UNASSIGNED);
|
|
|
|
|
|
|
|
|
|
err = part.read();
|
|
|
|
|
if (err != NOERR)
|
|
|
|
|
{
|
|
|
|
|
const TPartita p(riga);
|
|
|
|
|
err = p.write_saldo(FALSE, &sld);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
riga = sld;
|
|
|
|
|
else
|
|
|
|
|
riga.zero();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
saldo.set(riga.get_char(PART_SEZ), riga.get_real(PART_IMPORTO));
|
|
|
|
|
doc.set(riga.get_char(PART_SEZABB), riga.get_real(PART_ABBUONI));
|
|
|
|
|
pag.set(riga.get_char(PART_SEZDIFCAM), riga.get_real(PART_DIFFCAM));
|
|
|
|
|
imp.set(riga.get_char(PART_REG), riga.get_real(PART_IMPOSTA));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return err;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-01 15:06:35 +00:00
|
|
|
|
bool TPartita::write(bool re) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1996-02-13 16:35:59 +00:00
|
|
|
|
if (ok())
|
1996-02-21 09:00:03 +00:00
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
chiusa(true); // Aggiorna flag di chiusura (non si sa mai)
|
1996-02-21 09:00:03 +00:00
|
|
|
|
|
1999-06-18 15:35:05 +00:00
|
|
|
|
if (conto().tipo() > ' ' && conto().gruppo() > 0)
|
1996-02-21 09:00:03 +00:00
|
|
|
|
{
|
|
|
|
|
// Aggiunge conti cliente/fornitore mancanti
|
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
1995-11-10 14:15:45 +00:00
|
|
|
|
{
|
1996-02-21 09:00:03 +00:00
|
|
|
|
TRiga_partite& row = riga(r);
|
|
|
|
|
if (row.get(PART_GRUPPOCL).empty())
|
|
|
|
|
{
|
|
|
|
|
row.put(PART_GRUPPOCL, conto().gruppo());
|
|
|
|
|
row.put(PART_CONTOCL, conto().conto());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-09 08:05:53 +00:00
|
|
|
|
|
|
|
|
|
const char cur_align = allineamento_corrente();
|
1996-02-13 16:35:59 +00:00
|
|
|
|
const char req_align = allineamento_richiesto(conto().tipo());
|
1995-11-09 08:05:53 +00:00
|
|
|
|
if (cur_align > ' ' && cur_align != req_align)
|
|
|
|
|
{
|
|
|
|
|
if (yesno_box("La partita %d '%s' non rispetta l'allineamento "
|
|
|
|
|
"specificato nei parametri ditta: si desidera correggerlo?",
|
|
|
|
|
anno(), (const char*)numero()))
|
|
|
|
|
{
|
|
|
|
|
// Riallinea tutti i numeri partita nelle righe. rate e pagamenti
|
|
|
|
|
((TPartita*)this)->allinea(req_align);
|
|
|
|
|
}
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1995-11-09 08:05:53 +00:00
|
|
|
|
|
1995-09-01 15:06:35 +00:00
|
|
|
|
int err = _part.write(re);
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
err = _unassigned.write(re);
|
1996-02-13 16:35:59 +00:00
|
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
{
|
|
|
|
|
// Se esiste almeno una riga scrive la riga riepilogativa della partita
|
|
|
|
|
if (ok()) write_saldo(re);
|
|
|
|
|
|
|
|
|
|
// Se l'allineamento e' cambiato cancello la vecchia partita
|
|
|
|
|
if (allineamento_corrente() != allineamento_iniziale())
|
|
|
|
|
{
|
|
|
|
|
// Costruisce il vecchio numero partita
|
|
|
|
|
TString16 num = numero();
|
|
|
|
|
if (allineamento_iniziale() == 'R')
|
|
|
|
|
num.right_just(NUMLEN);
|
|
|
|
|
else
|
|
|
|
|
num.trim();
|
|
|
|
|
|
|
|
|
|
// Cancella vecchia partita
|
|
|
|
|
TPartita canc(conto(), anno(), num);
|
|
|
|
|
canc.remove();
|
|
|
|
|
}
|
1995-11-09 08:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-01 15:06:35 +00:00
|
|
|
|
return err == NOERR;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-11-09 08:05:53 +00:00
|
|
|
|
// Cancella tutta una partita
|
1995-11-20 15:25:19 +00:00
|
|
|
|
bool TPartita::remove() const
|
|
|
|
|
{
|
|
|
|
|
const int err = _part.remove();
|
|
|
|
|
if (err == NOERR)
|
|
|
|
|
_unassigned.remove();
|
|
|
|
|
return err == NOERR;
|
1995-08-28 07:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-25 09:24:23 +00:00
|
|
|
|
// Crea una nuova riga partite
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRiga_partite& TPartita::new_row(int r)
|
|
|
|
|
{
|
|
|
|
|
if (r <= 0)
|
|
|
|
|
for (r = 1; esiste(r); r++);
|
|
|
|
|
CHECKD(!esiste(r), "Ue' pirla!, esiste gia' la riga ", r);
|
2010-01-27 15:37:13 +00:00
|
|
|
|
TRiga_partite& nuova = (TRiga_partite&)_part.row(r, true);
|
1995-11-10 14:15:45 +00:00
|
|
|
|
nuova.put(PART_GRUPPOCL, conto().gruppo());
|
|
|
|
|
nuova.put(PART_CONTOCL, conto().conto());
|
1995-08-28 07:50:28 +00:00
|
|
|
|
return nuova;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-10-23 14:14:55 +00:00
|
|
|
|
TRiga_partite& TPartita::riga(int r) const
|
|
|
|
|
{
|
2003-07-25 14:51:45 +00:00
|
|
|
|
if (r > 0 && !_part.exist(r))
|
2002-10-23 14:14:55 +00:00
|
|
|
|
{
|
|
|
|
|
yesnofatal_box("La partita %d %s del conto %c %d %d %ld (%s) <20> incoerente: manca la riga %d",
|
|
|
|
|
anno(), (const char*)numero(),
|
|
|
|
|
_conto.tipo(), _conto.gruppo(), _conto.conto(), _conto.sottoconto(),
|
|
|
|
|
(const char*)_conto.descrizione(), r);
|
|
|
|
|
|
|
|
|
|
// Ricreiamo una riga fasulla tanto per non bloccare il programma
|
|
|
|
|
TRiga_partite& newrow = ((TPartita*)this)->new_row(r);
|
|
|
|
|
for (int p = last(); p > 0; p = pred(p))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& par = riga(p);
|
|
|
|
|
for (int rr = par.rate(); rr > 0; rr--)
|
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze& rat = par.rata(rr);
|
|
|
|
|
if (rat.exist(r)) // Ho trovato un pagamento assegnato alla nuova riga!
|
|
|
|
|
{
|
|
|
|
|
newrow.put(PART_TIPOMOV, (int)tm_pagamento); // Imposta il tipo movimento
|
|
|
|
|
newrow.put(PART_SEZ, par.sezione() == 'D' ? 'A' : 'D'); // Imposta sezione al contrario della fattura
|
|
|
|
|
TValuta val(par); val.put(newrow); // Copia valuta da fattura
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (TRiga_partite&)_part.row(r);
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-29 13:11:15 +00:00
|
|
|
|
TRiga_scadenze& TPartita::rata(int nriga, int nrata) const
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& r = riga(nriga);
|
|
|
|
|
return r.rata(nrata);
|
|
|
|
|
}
|
1995-08-28 07:50:28 +00:00
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
bool TPartita::rata_chiusa(int nriga, int nrata) const
|
1995-09-01 15:06:35 +00:00
|
|
|
|
{
|
2006-12-13 16:22:33 +00:00
|
|
|
|
bool pag = false;
|
1995-09-01 15:06:35 +00:00
|
|
|
|
if (nriga != UNASSIGNED)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_scadenze& r = rata(nriga, nrata);
|
1995-09-08 10:57:44 +00:00
|
|
|
|
pag = r.chiusa();
|
1995-09-01 15:06:35 +00:00
|
|
|
|
}
|
|
|
|
|
return pag;
|
|
|
|
|
}
|
|
|
|
|
|
1995-10-25 09:34:53 +00:00
|
|
|
|
bool TPartita::esistono_abbuoni_diffcam(long nreg) const
|
|
|
|
|
{
|
|
|
|
|
int nrata = 0;
|
|
|
|
|
const int nriga = prima_fattura(nreg);
|
1996-01-11 15:44:06 +00:00
|
|
|
|
if (nriga > 0)
|
|
|
|
|
nrata = riga(nriga).ultima_rata_con_abbuoni_diffcam();
|
1995-10-25 09:34:53 +00:00
|
|
|
|
return nrata > 0;
|
|
|
|
|
}
|
|
|
|
|
|
1999-04-06 15:34:39 +00:00
|
|
|
|
const TString& TPartita::codice_valuta() const
|
|
|
|
|
{
|
|
|
|
|
const int ultima = last();
|
1999-04-16 12:02:04 +00:00
|
|
|
|
return ultima > 0 ? riga(ultima).codice_valuta() : (const TString &) EMPTY_STRING;
|
1999-04-06 15:34:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-03-05 17:35:35 +00:00
|
|
|
|
bool TPartita::in_valuta() const
|
|
|
|
|
{
|
|
|
|
|
const int ultima = last();
|
|
|
|
|
return ultima > 0 ? riga(ultima).in_valuta() : FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-01 15:06:35 +00:00
|
|
|
|
TRectype& TPartita::pagamento(int nriga, int nrata, int nrigp)
|
|
|
|
|
{
|
|
|
|
|
if (nriga == UNASSIGNED)
|
2010-01-27 15:37:13 +00:00
|
|
|
|
return _unassigned.row(nrigp, true);
|
1995-09-01 15:06:35 +00:00
|
|
|
|
TRiga_scadenze& r = rata(nriga, nrata);
|
|
|
|
|
return r.row(nrigp);
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-04 14:51:26 +00:00
|
|
|
|
// Controlla l'esistenza di una riga, rata, pagamento.
|
|
|
|
|
// Gli ultimi parametri possono essere nulli per poter testare una singola riga o rata
|
1995-09-01 15:06:35 +00:00
|
|
|
|
bool TPartita::esiste(int nriga, int nrata, int nrigp) const
|
|
|
|
|
{
|
1996-01-04 14:51:26 +00:00
|
|
|
|
if (nriga == UNASSIGNED) // Cerca solo pagamento non assegnato
|
1995-09-01 15:06:35 +00:00
|
|
|
|
return _unassigned.exist(nrigp);
|
|
|
|
|
|
1996-01-04 14:51:26 +00:00
|
|
|
|
const bool esiste_riga = _part.exist(nriga);
|
1997-05-06 12:33:10 +00:00
|
|
|
|
if (!esiste_riga || nrata <= 0) // Riga non esistente o rata nulla
|
1996-01-04 14:51:26 +00:00
|
|
|
|
return esiste_riga;
|
|
|
|
|
|
|
|
|
|
const TRiga_partite& r = riga(nriga);
|
|
|
|
|
const bool esiste_rata = r.exist(nrata);
|
|
|
|
|
if (!esiste_rata || nrigp <= 0) // Rata inesistente o pagamento nullo
|
|
|
|
|
return esiste_rata;
|
1995-09-01 15:06:35 +00:00
|
|
|
|
|
1996-01-04 14:51:26 +00:00
|
|
|
|
const TRiga_scadenze& scad = r.rata(nrata);
|
|
|
|
|
return scad.exist(nrigp); // Cerca pagamento vero e proprio
|
1998-04-30 15:59:34 +00:00
|
|
|
|
}
|
1995-09-01 15:06:35 +00:00
|
|
|
|
|
1998-03-16 13:55:41 +00:00
|
|
|
|
bool TPartita::elimina_pagamento(int nriga, int nrata, int nrigp)
|
|
|
|
|
{
|
|
|
|
|
const bool ok = esiste(nriga, nrata, nrigp);
|
|
|
|
|
if (ok)
|
|
|
|
|
{
|
|
|
|
|
if (nriga == UNASSIGNED)
|
|
|
|
|
{
|
1999-07-16 14:59:11 +00:00
|
|
|
|
TRectype old_pag(_unassigned.row(nrigp));
|
|
|
|
|
old_pag.put(PAGSCA_ACCSAL, "A");
|
2004-06-25 10:18:43 +00:00
|
|
|
|
old_pag.zero(PAGSCA_IMPORTO);
|
|
|
|
|
old_pag.zero(PAGSCA_IMPORTOVAL);
|
|
|
|
|
old_pag.zero(PAGSCA_RITENUTE);
|
|
|
|
|
old_pag.zero(PAGSCA_RITSOC);
|
1999-07-16 14:59:11 +00:00
|
|
|
|
const TValuta val;
|
2010-01-27 15:37:13 +00:00
|
|
|
|
modifica_pagamento(old_pag, val, true);
|
1998-03-16 13:55:41 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze& scad = rata(nriga, nrata);
|
|
|
|
|
scad.elimina_pagamento(nrigp);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-27 15:37:13 +00:00
|
|
|
|
return true;
|
1998-03-16 13:55:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-08 10:57:44 +00:00
|
|
|
|
// Ritorna l'importo in lire speso su di una riga contabile
|
1996-02-08 15:46:39 +00:00
|
|
|
|
TImporto TPartita::importo_speso(long nreg, int numrig, bool valuta, int mode) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
TImporto imp;
|
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
1995-12-01 11:46:35 +00:00
|
|
|
|
const TRiga_partite& row = riga(r);
|
|
|
|
|
if (nreg == row.get_long(PART_NREG) && numrig == row.get_int(PART_NUMRIG))
|
1996-02-08 15:46:39 +00:00
|
|
|
|
imp += row.importo(valuta, mode);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return imp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
void TPartita::update_reg(long nreg, const TRectype& mov, TPartite_array& pa)
|
1995-08-30 12:14:19 +00:00
|
|
|
|
{
|
1995-08-25 07:39:49 +00:00
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
1995-09-29 16:21:08 +00:00
|
|
|
|
TRiga_partite& rig = riga(r);
|
|
|
|
|
if (rig.get_long(PART_NREG) == nreg)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-09-29 16:21:08 +00:00
|
|
|
|
rig.put(PART_NREG, mov.get(MOV_NUMREG));
|
|
|
|
|
rig.put(PART_DATAREG, mov.get(MOV_DATAREG));
|
|
|
|
|
rig.put(PART_DATADOC, mov.get(MOV_DATADOC));
|
|
|
|
|
rig.put(PART_NUMDOC, mov.get(MOV_NUMDOC));
|
|
|
|
|
rig.put(PART_REG, mov.get(MOV_REG));
|
|
|
|
|
rig.put(PART_PROTIVA, mov.get(MOV_PROTIVA));
|
|
|
|
|
rig.put(PART_CODCAUS, mov.get(MOV_CODCAUS));
|
1995-12-19 15:53:50 +00:00
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
if (rig.tipo() == tm_fattura)
|
1995-12-19 15:53:50 +00:00
|
|
|
|
{
|
1996-02-13 16:35:59 +00:00
|
|
|
|
rig.put(PART_IMPTOTDOC, mov.get(MOV_TOTDOC));
|
|
|
|
|
if (rig.in_valuta())
|
|
|
|
|
rig.put(PART_IMPTOTVAL, mov.get(MOV_TOTDOCVAL));
|
|
|
|
|
else
|
|
|
|
|
rig.zero(PART_IMPTOTVAL);
|
1995-12-19 15:53:50 +00:00
|
|
|
|
}
|
1996-02-13 16:35:59 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const int numrig = rig.get_int(PART_NUMRIG);
|
|
|
|
|
CHECK(numrig > 0, "Bad NUMRIG");
|
|
|
|
|
|
|
|
|
|
const TImporto imptotdoc = pa.importo_speso(nreg, numrig, FALSE, 0x9);
|
|
|
|
|
rig.put(PART_IMPTOTDOC, imptotdoc.valore());
|
|
|
|
|
if (rig.in_valuta())
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
const TImporto imptotval = pa.importo_speso(nreg, numrig, true, 0x1);
|
1996-02-13 16:35:59 +00:00
|
|
|
|
rig.put(PART_IMPTOTVAL, imptotval.valore());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
rig.zero(PART_IMPTOTVAL);
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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 = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
1996-01-11 15:44:06 +00:00
|
|
|
|
if (numreg == row.get_long(PART_NREG))
|
1995-08-28 07:50:28 +00:00
|
|
|
|
{
|
1996-01-11 15:44:06 +00:00
|
|
|
|
if (rm <= 0 || rm == row.get_int(PART_NUMRIG))
|
1995-08-28 07:50:28 +00:00
|
|
|
|
return r;
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
1995-09-29 16:21:08 +00:00
|
|
|
|
return 0;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1996-01-11 15:44:06 +00:00
|
|
|
|
// Trova la prima riga della partita corrispondente alla registrazione nreg
|
|
|
|
|
int TPartita::prima_riga(long nreg, tipo_movimento tipo) const
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
const int lastrow = last();
|
|
|
|
|
for (int r = first(); r <= lastrow; r = succ(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
1996-01-11 15:44:06 +00:00
|
|
|
|
if (tipo == tm_nessuno || tipo == row.tipo())
|
1995-09-13 16:01:30 +00:00
|
|
|
|
if (nreg <= 0 || nreg == row.get_long(PART_NREG))
|
1995-08-29 13:11:15 +00:00
|
|
|
|
return r;
|
1995-08-25 08:00:18 +00:00
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trova la prima riga della partita contenente una fattura
|
1996-01-11 15:44:06 +00:00
|
|
|
|
int TPartita::prima_fattura(long nreg) const
|
|
|
|
|
{
|
|
|
|
|
return prima_riga(nreg, tm_fattura);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Trova la prima riga della partita contenente una pagamento
|
1995-08-25 08:00:18 +00:00
|
|
|
|
int TPartita::primo_pagamento(long nreg) const
|
|
|
|
|
{
|
1996-01-11 15:44:06 +00:00
|
|
|
|
return prima_riga(nreg, tm_pagamento);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TPartita::calcola_saldo(TImporto& saldo, TImporto& doc, TImporto& pag, TImporto& imp) const
|
|
|
|
|
{
|
|
|
|
|
doc = pag = imp = TImporto('D', ZERO);
|
|
|
|
|
|
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
1995-12-12 12:37:01 +00:00
|
|
|
|
const TImporto i(row.importo(FALSE, 0x9));
|
1995-12-01 11:46:35 +00:00
|
|
|
|
|
1995-12-11 11:20:18 +00:00
|
|
|
|
const tipo_movimento tipo = row.tipo();
|
1995-11-23 14:20:03 +00:00
|
|
|
|
switch (tipo)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-12-11 11:20:18 +00:00
|
|
|
|
case tm_fattura:
|
|
|
|
|
case tm_nota_credito:
|
1995-08-29 13:11:15 +00:00
|
|
|
|
doc += i; // documenti
|
|
|
|
|
break;
|
1995-12-11 11:20:18 +00:00
|
|
|
|
case tm_pagamento:
|
1995-08-29 13:11:15 +00:00
|
|
|
|
pag += i; // pagamenti
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
imp += i; // altri importi
|
|
|
|
|
break;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
1995-08-29 13:11:15 +00:00
|
|
|
|
|
1995-12-11 11:20:18 +00:00
|
|
|
|
if (tipo >= tm_pagamento)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-12-01 11:46:35 +00:00
|
|
|
|
const TImporto abbuoni(row.importo(FALSE, 0x2));
|
|
|
|
|
imp += abbuoni;
|
|
|
|
|
|
|
|
|
|
const TImporto diffcam(row.importo(FALSE, 0x4));
|
|
|
|
|
imp += diffcam;
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saldo = doc;
|
|
|
|
|
saldo += pag;
|
|
|
|
|
saldo += imp;
|
1995-09-29 16:21:08 +00:00
|
|
|
|
|
|
|
|
|
saldo.normalize();
|
|
|
|
|
doc.normalize();
|
|
|
|
|
pag.normalize();
|
1996-02-13 16:35:59 +00:00
|
|
|
|
imp.normalize();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-12-01 11:46:35 +00:00
|
|
|
|
TImporto TPartita::calcola_saldo(bool valuta) const
|
|
|
|
|
{
|
|
|
|
|
TImporto saldo;
|
2009-08-26 08:58:10 +00:00
|
|
|
|
|
1995-12-01 11:46:35 +00:00
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
|
|
|
|
saldo += row.importo(valuta);
|
|
|
|
|
}
|
|
|
|
|
return saldo;
|
|
|
|
|
}
|
|
|
|
|
|
2009-08-26 08:58:10 +00:00
|
|
|
|
TImporto TPartita::calcola_pagato_al(bool valuta,const TDate& al, const TDate & data_scaduto, const TDate& data_rischio) const
|
1995-12-01 11:46:35 +00:00
|
|
|
|
{
|
2009-08-26 08:58:10 +00:00
|
|
|
|
TImporto pagato;
|
1995-12-12 12:37:01 +00:00
|
|
|
|
|
1995-12-01 11:46:35 +00:00
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
2009-08-26 08:58:10 +00:00
|
|
|
|
const TDate data(row.get(PART_DATAREG));
|
1995-12-12 12:37:01 +00:00
|
|
|
|
|
1996-01-09 18:47:11 +00:00
|
|
|
|
if (data <= al)
|
1995-12-12 12:37:01 +00:00
|
|
|
|
{
|
2009-08-26 08:58:10 +00:00
|
|
|
|
pagato += row.importo(valuta);
|
|
|
|
|
if (!row.is_fattura())
|
1995-12-12 12:37:01 +00:00
|
|
|
|
{
|
|
|
|
|
const int tipopag = row.get_int(PART_TIPOPAG);
|
2009-08-26 08:58:10 +00:00
|
|
|
|
|
|
|
|
|
if (tipopag >= 2 && tipopag <= 7)
|
1996-05-20 14:08:03 +00:00
|
|
|
|
{
|
2009-08-26 08:58:10 +00:00
|
|
|
|
bool sbf = false;
|
|
|
|
|
pagato -= row.esposto(valuta, data_scaduto, data_rischio, sbf);
|
1996-05-20 14:08:03 +00:00
|
|
|
|
}
|
1995-12-12 12:37:01 +00:00
|
|
|
|
}
|
2009-08-26 08:58:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return pagato;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TImporto TPartita::calcola_saldo_al(bool valuta,const TDate& al, const TDate & data_scaduto, const TDate& data_rischio) const
|
|
|
|
|
{
|
|
|
|
|
TImporto saldo;
|
|
|
|
|
|
|
|
|
|
for (int r = last(); r > 0; r = pred(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
1996-05-31 10:38:03 +00:00
|
|
|
|
const TDate data(row.get(PART_DATAREG));
|
|
|
|
|
|
|
|
|
|
if (data <= al)
|
|
|
|
|
{
|
|
|
|
|
saldo += row.importo(valuta);
|
|
|
|
|
if (!row.is_fattura())
|
|
|
|
|
{
|
|
|
|
|
const int tipopag = row.get_int(PART_TIPOPAG);
|
|
|
|
|
|
|
|
|
|
if (tipopag >= 2 && tipopag <= 7)
|
|
|
|
|
{
|
|
|
|
|
bool sbf = FALSE;
|
|
|
|
|
saldo -= row.esposto(valuta, data_scaduto, data_rischio, sbf);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-12-01 11:46:35 +00:00
|
|
|
|
}
|
|
|
|
|
return saldo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-03-05 17:35:35 +00:00
|
|
|
|
real TPartita::calcola_scaduto_al(bool valuta,const TDate& al) const
|
|
|
|
|
{
|
|
|
|
|
const int ultima = last();
|
|
|
|
|
if (ultima > 0)
|
|
|
|
|
{
|
|
|
|
|
TImporto scaduto;
|
|
|
|
|
const TBill & c = conto();
|
|
|
|
|
char sezione = ' ';
|
|
|
|
|
|
|
|
|
|
if (c.tipo() == 'C') sezione = 'D';
|
|
|
|
|
else
|
|
|
|
|
if (c.tipo() == 'F') sezione = 'A';
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(ultima);
|
|
|
|
|
const tipo_movimento t = row.tipo();
|
|
|
|
|
if (t == tm_fattura || t == tm_insoluto)
|
|
|
|
|
sezione = row.sezione();
|
|
|
|
|
else
|
|
|
|
|
sezione = row.sezione() == 'D' ? 'A' : 'D';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int r = ultima; r > 0; r = pred(r))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(r);
|
|
|
|
|
if (row.is_fattura())
|
|
|
|
|
{
|
|
|
|
|
for (int s = row.rate(); s > 0 ;s--)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_scadenze & rata = row.rata(s);
|
|
|
|
|
const TDate data(rata.get(SCAD_DATASCAD));
|
|
|
|
|
|
|
|
|
|
if (data <= al)
|
|
|
|
|
{
|
|
|
|
|
scaduto += rata.importo(valuta);
|
|
|
|
|
scaduto += rata.importo_pagato(valuta);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
scaduto.normalize(sezione);
|
|
|
|
|
if (scaduto.valore() > 0)
|
|
|
|
|
scaduto += importo_pagato_unassigned(valuta);
|
|
|
|
|
scaduto.normalize(sezione);
|
|
|
|
|
if (scaduto.valore() > 0)
|
|
|
|
|
return scaduto.valore();
|
|
|
|
|
else
|
|
|
|
|
return ZERO;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
return ZERO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Calcola il totale dei pagamenti non assegnati (eventualmente in valuta)
|
|
|
|
|
TImporto TPartita::importo_pagato_unassigned(bool val, int mode) const
|
|
|
|
|
{
|
|
|
|
|
CHECKD(mode > 0x0 && mode <= 0xF, "Bad importo_pagato mode ", mode);
|
|
|
|
|
const bool in_val = in_valuta();
|
|
|
|
|
const char* imp_field = (val && in_val) ? PAGSCA_IMPORTOVAL : PAGSCA_IMPORTO;
|
|
|
|
|
|
|
|
|
|
TImporto totale;
|
|
|
|
|
const int last_row = _unassigned.last_row();
|
|
|
|
|
for (int p = _unassigned.first_row(); p <= last_row; p = _unassigned.succ_row(p))
|
|
|
|
|
{
|
|
|
|
|
const TRectype& pag = _unassigned.row(p); // Riga pagamento
|
2004-06-25 10:18:43 +00:00
|
|
|
|
const TRiga_partite& sum = riga(pag.get_int(PAGSCA_NRIGP)); // Riga partite
|
1996-03-05 17:35:35 +00:00
|
|
|
|
const char sez = sum.sezione();
|
1999-07-16 14:59:11 +00:00
|
|
|
|
// const int tipo = sum.get_int(PART_TIPOPAG);
|
1996-03-05 17:35:35 +00:00
|
|
|
|
|
|
|
|
|
if (mode & 0x1)
|
|
|
|
|
totale += TImporto(sez, pag.get_real(imp_field));
|
|
|
|
|
if (!in_val && (mode & 0x8)) // Le ritenute non esistono nei pagamenti in valuta
|
2004-06-25 10:18:43 +00:00
|
|
|
|
{
|
1996-03-05 17:35:35 +00:00
|
|
|
|
totale += TImporto(sez, pag.get_real(PAGSCA_RITENUTE));
|
2004-06-25 10:18:43 +00:00
|
|
|
|
totale += TImporto(sum.sezione_ritsoc(), pag.get_real(PAGSCA_RITSOC));
|
|
|
|
|
}
|
1996-03-05 17:35:35 +00:00
|
|
|
|
|
|
|
|
|
if (mode & 0x2) // Voglio anche gli abbuoni
|
|
|
|
|
{
|
|
|
|
|
real abb(pag.get_real(PAGSCA_ABBUONI));
|
|
|
|
|
if (in_val && !val) // Gli abbuoni sono sempre in valuta e quindi
|
|
|
|
|
{ // devono essere convertiti opportunamente
|
2002-05-08 16:25:49 +00:00
|
|
|
|
const TExchange cmb(sum);
|
|
|
|
|
TCurrency cur(abb, cmb);
|
|
|
|
|
cur.change_to_firm_val();
|
1999-04-06 15:34:39 +00:00
|
|
|
|
abb = cur.get_num();
|
1996-03-05 17:35:35 +00:00
|
|
|
|
}
|
|
|
|
|
totale += TImporto(sez, abb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (in_val && !val && (mode & 0x4)) // Voglio anche le differenze cambio
|
|
|
|
|
{ // Esse esistono solo nei pagamenti in valuta
|
|
|
|
|
const TImporto diffcam(sez, pag.get_real(PAGSCA_DIFFCAM));
|
|
|
|
|
totale += diffcam;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return totale.normalize();
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
// Controlla se esistono pagamenti riferiti alla riga nrigp
|
1995-08-25 07:39:49 +00:00
|
|
|
|
bool TPartita::utilizzata(int nrigp) const
|
|
|
|
|
{
|
|
|
|
|
for (int p = last(); p > 0; p = pred(p))
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& fatt = riga(p);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
for (int r = fatt.rate(); r > 0; r--)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
const TRiga_scadenze& scad = fatt.rata(r);
|
|
|
|
|
if (scad.rows_array().exist(nrigp))
|
2010-01-27 15:37:13 +00:00
|
|
|
|
return true;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
1995-08-28 07:50:28 +00:00
|
|
|
|
}
|
|
|
|
|
return _unassigned.exist(nrigp);
|
1995-10-12 15:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-12 07:58:03 +00:00
|
|
|
|
bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta,
|
1995-08-25 07:39:49 +00:00
|
|
|
|
char& old_ap, TImporto& old_abb, TImporto& old_diffcam,
|
1995-10-25 09:34:53 +00:00
|
|
|
|
char& new_ap, TImporto& new_abb, TImporto& new_diffcam,
|
|
|
|
|
bool update)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
const int nriga = new_pag.get_int(PAGSCA_NRIGA);
|
|
|
|
|
const int nrata = new_pag.get_int(PAGSCA_NRATA);
|
|
|
|
|
const int nrigp = new_pag.get_int(PAGSCA_NRIGP);
|
|
|
|
|
|
1995-09-01 15:06:35 +00:00
|
|
|
|
bool empty = FALSE;
|
|
|
|
|
|
|
|
|
|
if (nriga != UNASSIGNED)
|
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze& scaden = rata(nriga, nrata);
|
1995-09-12 07:58:03 +00:00
|
|
|
|
empty = scaden.modifica_pagamento(new_pag, valuta,
|
1995-09-01 15:06:35 +00:00
|
|
|
|
old_ap, old_abb, old_diffcam,
|
1995-10-25 09:34:53 +00:00
|
|
|
|
new_ap, new_abb, new_diffcam, update);
|
1995-09-01 15:06:35 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
const TRectype& old_pag = pagamento(nriga, nrata, nrigp);
|
|
|
|
|
|
|
|
|
|
TRiga_partite& sum = riga(nrigp);
|
|
|
|
|
empty = sum.update(old_pag, new_pag, PART_IMPORTO);
|
|
|
|
|
sum.update(old_pag, new_pag, PART_IMPORTOVAL);
|
|
|
|
|
sum.update(old_pag, new_pag, PART_RITENUTE);
|
2004-06-25 10:18:43 +00:00
|
|
|
|
sum.update(old_pag, new_pag, PART_RITSOC);
|
1995-09-01 15:06:35 +00:00
|
|
|
|
|
|
|
|
|
if (new_pag.get_real(PAGSCA_IMPORTO).is_zero())
|
|
|
|
|
_unassigned.destroy_row(nrigp);
|
|
|
|
|
else
|
|
|
|
|
_unassigned.row(nrigp, FALSE) = new_pag;
|
1995-09-19 15:43:43 +00:00
|
|
|
|
|
|
|
|
|
// Non ci possono essere abbuoni o differenze cambio di sorta!
|
|
|
|
|
old_ap = new_ap = ' ';
|
|
|
|
|
old_abb = new_abb = old_diffcam = new_diffcam = TImporto('D', ZERO);
|
1995-09-01 15:06:35 +00:00
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
|
|
|
|
if (empty && !utilizzata(nrigp))
|
1995-09-19 15:43:43 +00:00
|
|
|
|
rimuovi_riga(nrigp);
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return empty;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
|
1995-11-23 14:20:03 +00:00
|
|
|
|
bool TPartita::modifica_pagamento(const TRectype& new_pag, const TValuta& valuta, bool update)
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
|
|
|
|
char old_ap, new_ap;
|
|
|
|
|
TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
|
|
|
|
|
return modifica_pagamento(new_pag, valuta,
|
|
|
|
|
old_ap, old_abbuono, old_diffcam,
|
1995-11-23 14:20:03 +00:00
|
|
|
|
new_ap, new_abbuono, new_diffcam, update);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
1996-02-21 09:00:03 +00:00
|
|
|
|
bool TPartita::chiusa(bool update) const
|
1995-09-01 15:06:35 +00:00
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
bool chiusa = true;
|
1995-11-10 13:35:00 +00:00
|
|
|
|
const int ultima = last();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
if (update)
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
const TImporto saldo = calcola_saldo(true); // Saldo in valuta
|
1996-02-19 14:04:36 +00:00
|
|
|
|
chiusa = saldo.is_zero();
|
1996-02-21 09:00:03 +00:00
|
|
|
|
for (int p = ultima; p > 0; p = pred(p))
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1996-02-19 14:04:36 +00:00
|
|
|
|
TRiga_partite& part = riga(p);
|
|
|
|
|
part.put(PART_CHIUSA, chiusa);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
1996-02-21 09:00:03 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ultima > 0)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& row = riga(ultima);
|
|
|
|
|
chiusa = row.get_bool(PART_CHIUSA);
|
|
|
|
|
}
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
|
|
|
|
return chiusa;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
void TPartita::rimuovi_riga(int r)
|
|
|
|
|
{
|
1995-09-14 07:29:24 +00:00
|
|
|
|
TRiga_partite& row = riga(r);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
if (row.rate() > 0)
|
1995-11-17 10:27:24 +00:00
|
|
|
|
row.elimina_rata(-1);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
else
|
|
|
|
|
CHECKD(!utilizzata(r), "Can't remove still referenced row ", r);
|
|
|
|
|
_part.destroy_row(r);
|
2010-01-27 15:37:13 +00:00
|
|
|
|
chiusa(true);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void somma(const TRectype& vec, TRectype& nuo, const char* field)
|
|
|
|
|
{
|
|
|
|
|
real totale(vec.get(field));
|
|
|
|
|
totale += nuo.get_real(field);
|
|
|
|
|
nuo.put(field, totale);
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
void TPartita::sposta_riga(int from_row, TPartita& part, int to_row)
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
1996-02-13 16:35:59 +00:00
|
|
|
|
const TRiga_partite& row = riga(from_row);
|
|
|
|
|
TRiga_partite& nrw = part.riga(to_row);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
const int address_size = last()+1;
|
|
|
|
|
int* address = new int[address_size];
|
|
|
|
|
memset(address, 0, address_size*sizeof(int));
|
|
|
|
|
|
2002-12-20 16:15:03 +00:00
|
|
|
|
TToken_string knames(64); // Elenco dei campi della chiave 1 dei pagamenti
|
1995-09-19 15:43:43 +00:00
|
|
|
|
knames.add(PART_TIPOCF);
|
|
|
|
|
knames.add(PART_GRUPPO);
|
|
|
|
|
knames.add(PART_CONTO);
|
|
|
|
|
knames.add(PART_SOTTOCONTO);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
knames.add(PART_ANNO);
|
|
|
|
|
knames.add(PART_NUMPART);
|
|
|
|
|
knames.add(PART_NRIGA);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
knames.add(SCAD_NRATA);
|
|
|
|
|
knames.add(PAGSCA_NRIGP);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= row.rate(); i++)
|
|
|
|
|
{
|
|
|
|
|
TRiga_scadenze& scd = row.rata(i);
|
|
|
|
|
for (int j = scd.last(); j > 0; j = scd.pred(j))
|
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
const TRectype& pag = scd.row(j);
|
|
|
|
|
|
|
|
|
|
CHECK(j < address_size, "Bad nrigp address");
|
|
|
|
|
if (address[j] == 0)
|
|
|
|
|
{
|
|
|
|
|
const TRiga_partite& vecchia = riga(j);
|
1996-03-15 09:38:11 +00:00
|
|
|
|
TRiga_partite& nuova = part.new_row(part.esiste(j) ? 0 : j);
|
1996-01-04 14:51:26 +00:00
|
|
|
|
|
|
|
|
|
for (int n = vecchia.items()-1; n >= 0; n--) // Copia tutti i campi non chiave
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
1996-01-04 14:51:26 +00:00
|
|
|
|
const char* f = vecchia.fieldname(n);
|
|
|
|
|
if (knames.get_pos(f) < 0)
|
|
|
|
|
nuova.put(f, vecchia.get(f));
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
|
|
|
|
nuova.zero(PART_IMPORTO);
|
|
|
|
|
nuova.zero(PART_IMPORTOVAL);
|
|
|
|
|
nuova.zero(PART_ABBUONI);
|
|
|
|
|
nuova.zero(PART_DIFFCAM);
|
1996-03-15 09:38:11 +00:00
|
|
|
|
nuova.zero(PART_RITENUTE);
|
2004-06-25 10:18:43 +00:00
|
|
|
|
nuova.zero(PART_RITSOC);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
address[j] = nuova.get_int(PART_NRIGA);
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
int new_row = to_row; // Nuova riga fattura
|
1996-01-04 14:51:26 +00:00
|
|
|
|
int new_sca = i; // Nuovo numero rata (uguale a prima)
|
|
|
|
|
const int nrigp = address[j]; // Nuova riga somma (e pagamento)
|
|
|
|
|
|
1996-01-19 13:09:12 +00:00
|
|
|
|
if (!part.esiste(new_row, new_sca)) // Se la nuova partita non ha la rata
|
1996-01-04 14:51:26 +00:00
|
|
|
|
new_row = new_sca = UNASSIGNED; // allora sposta sui non asseganti
|
|
|
|
|
|
|
|
|
|
TRectype npg(LF_PAGSCA); // Nuovo record di pagamento
|
|
|
|
|
|
|
|
|
|
if (part.esiste(new_row, new_sca, nrigp)) // Se il pagamento esiste di gia'
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
1996-01-04 14:51:26 +00:00
|
|
|
|
npg = part.pagamento(new_row, new_sca, nrigp);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
somma(pag, npg, PART_IMPORTO);
|
1995-12-01 11:46:35 +00:00
|
|
|
|
somma(pag, npg, PART_IMPORTOVAL);
|
|
|
|
|
somma(pag, npg, PART_RITENUTE);
|
2004-06-25 10:18:43 +00:00
|
|
|
|
somma(pag, npg, PART_RITSOC);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
1995-09-14 07:29:24 +00:00
|
|
|
|
{
|
1996-01-04 14:51:26 +00:00
|
|
|
|
if (new_sca == UNASSIGNED)
|
2010-01-27 15:37:13 +00:00
|
|
|
|
npg = part.unassigned().row(nrigp, true);
|
1996-01-04 14:51:26 +00:00
|
|
|
|
else
|
|
|
|
|
npg = nrw.rata(new_sca).new_row(nrigp);
|
|
|
|
|
for (int n = pag.items()-1; n >= 0; n--) // Copia tutti i campi non chiave
|
1995-09-19 15:43:43 +00:00
|
|
|
|
{
|
1996-01-04 14:51:26 +00:00
|
|
|
|
const char* f = pag.fieldname(n);
|
|
|
|
|
if (knames.get_pos(f) < 0)
|
|
|
|
|
npg.put(f, pag.get(f));
|
|
|
|
|
}
|
1995-11-23 14:20:03 +00:00
|
|
|
|
}
|
1996-01-04 14:51:26 +00:00
|
|
|
|
|
1995-11-23 14:20:03 +00:00
|
|
|
|
const TValuta val;
|
|
|
|
|
part.modifica_pagamento(npg, val, FALSE);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
scd.elimina_pagamento(j);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
}
|
1995-09-19 15:43:43 +00:00
|
|
|
|
}
|
1995-09-14 07:29:24 +00:00
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
delete address;
|
1996-02-13 16:35:59 +00:00
|
|
|
|
rimuovi_riga(from_row);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-19 15:43:43 +00:00
|
|
|
|
// Sposta i pagamenti della riga r, dalla rata s compresa in poi, sui non assegnati
|
|
|
|
|
void TPartita::scollega_pagamenti(int r, int s)
|
|
|
|
|
{
|
1995-09-25 17:30:36 +00:00
|
|
|
|
CHECKD(s > 0, "Impossibile scollegare la rata ", s);
|
1995-09-19 15:43:43 +00:00
|
|
|
|
const TRiga_partite& row = riga(r);
|
|
|
|
|
for (int i = row.rate(); i >= s; i--)
|
1995-09-14 07:29:24 +00:00
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRiga_scadenze& sc = row.rata(i);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
for (int j = sc.last(); j > 0; j = sc.pred(j))
|
|
|
|
|
{
|
1995-09-19 15:43:43 +00:00
|
|
|
|
TRectype& pag = sc.row(j);
|
1995-10-25 09:34:53 +00:00
|
|
|
|
CHECK(pag.get_real(PAGSCA_ABBUONI).is_zero(), "Can't detach payment with ABBUONI");
|
|
|
|
|
CHECK(pag.get_real(PAGSCA_DIFFCAM).is_zero(), "Can't detach payment with DIFFCAM");
|
1995-09-14 07:29:24 +00:00
|
|
|
|
pag.put(PAGSCA_NRIGA, (int)TPartita::UNASSIGNED);
|
|
|
|
|
pag.put(PAGSCA_NRATA, (int)TPartita::UNASSIGNED);
|
1995-10-25 09:34:53 +00:00
|
|
|
|
pag.put(PAGSCA_ACCSAL, 'A');
|
1995-10-12 15:02:46 +00:00
|
|
|
|
if (_unassigned.exist(j))
|
|
|
|
|
{
|
|
|
|
|
TRectype& unas = _unassigned.row(j, FALSE);
|
|
|
|
|
somma(pag, unas, PAGSCA_IMPORTO);
|
|
|
|
|
somma(pag, unas, PAGSCA_IMPORTOVAL);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
_unassigned.add_row(pag);
|
1995-09-14 07:29:24 +00:00
|
|
|
|
sc.rows_array().destroy_row(j);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
1995-12-20 16:16:14 +00:00
|
|
|
|
// Trova la riga di causale corrispondente ad un tipo di pagamento
|
|
|
|
|
int TPartita::tipopag2causale(int tipo) const
|
|
|
|
|
{
|
|
|
|
|
int caus = 2;
|
|
|
|
|
switch (tipo)
|
|
|
|
|
{
|
|
|
|
|
case 2: // Tratta
|
|
|
|
|
caus = 3; break;
|
|
|
|
|
case 3: // Ricevuta bancaria
|
|
|
|
|
caus = 4; break;
|
|
|
|
|
case 4: // Cessione
|
|
|
|
|
caus = 5; break;
|
|
|
|
|
case 5: // Paghero'
|
|
|
|
|
caus = 6; break;
|
|
|
|
|
case 6: // Fattura di credito
|
|
|
|
|
caus = 7; break;
|
1996-01-23 15:37:14 +00:00
|
|
|
|
case 7: // Tratta accettata
|
|
|
|
|
caus = 8; break;
|
1995-12-20 16:16:14 +00:00
|
|
|
|
case 1: // Rimessa
|
|
|
|
|
case 8: // Rapporti interbancari diretti
|
|
|
|
|
case 9: // Bonifico
|
|
|
|
|
default:
|
|
|
|
|
caus = 2; break;
|
|
|
|
|
}
|
|
|
|
|
return caus;
|
|
|
|
|
}
|
1995-09-14 07:29:24 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
// TPartite_array
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
// Certified 99%
|
|
|
|
|
const TString& TPartite_array::key(const TBill& clifo, int anno, const char* num)
|
|
|
|
|
{
|
|
|
|
|
if (clifo.tipo() > ' ')
|
1995-11-09 08:05:53 +00:00
|
|
|
|
_key.format("%c%3d%3d%6ld%4d%*s", clifo.tipo(), 0, 0, clifo.sottoconto(),
|
|
|
|
|
anno, TPartita::NUMLEN, num);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
else
|
1995-11-09 08:05:53 +00:00
|
|
|
|
_key.format("%c%3d%3d%6ld%4d%*s",
|
|
|
|
|
clifo.tipo(), clifo.gruppo(), clifo.conto(), clifo.sottoconto(),
|
|
|
|
|
anno, TPartita::NUMLEN, num);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return _key;
|
|
|
|
|
}
|
1995-08-29 13:11:15 +00:00
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
// 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);
|
1995-09-01 15:06:35 +00:00
|
|
|
|
add(k, p);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TPartita* TPartite_array::find(const TRectype& r, bool create)
|
|
|
|
|
{
|
|
|
|
|
TBill zio; zio.get(r);
|
1995-10-04 15:07:56 +00:00
|
|
|
|
if (zio.gruppo() == 0)
|
|
|
|
|
{
|
|
|
|
|
zio.set(r.get_int(PART_GRUPPOCL), r.get_int(PART_CONTOCL),
|
1995-11-09 08:05:53 +00:00
|
|
|
|
zio.codclifo(), zio.tipo());
|
1995-10-04 15:07:56 +00:00
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
const int anno = r.get_int(PART_ANNO);
|
2002-12-20 16:15:03 +00:00
|
|
|
|
const TString8 num = r.get(PART_NUMPART);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return find(zio, anno, num, create);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TPartita& TPartite_array::partita(const TBill& clifo, int anno, const char* num)
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
TPartita* game = find(clifo, anno, num, true);
|
1995-09-01 15:06:35 +00:00
|
|
|
|
CHECK(game, "Partita errata");
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return *game;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TPartita& TPartite_array::partita(const TRectype& r)
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
TPartita* game = find(r, true);
|
1995-08-25 07:39:49 +00:00
|
|
|
|
CHECK(game, "Partita errata");
|
|
|
|
|
return *game;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-16 09:51:28 +00:00
|
|
|
|
bool TPartite_array::insert(TPartita* p)
|
|
|
|
|
{
|
|
|
|
|
const TString& k = key(p->conto(), p->anno(), p->numero());
|
|
|
|
|
TPartita* old = (TPartita*)objptr(k);
|
|
|
|
|
if (old != NULL) remove(k);
|
|
|
|
|
add(k, p);
|
|
|
|
|
return old != NULL;
|
|
|
|
|
}
|
|
|
|
|
|
1995-09-01 15:06:35 +00:00
|
|
|
|
bool TPartite_array::destroy(const TBill& clifo, int anno, const char* num)
|
|
|
|
|
{
|
|
|
|
|
const TString& k = key(clifo, anno, num);
|
|
|
|
|
return remove(k);
|
|
|
|
|
}
|
|
|
|
|
|
1996-01-19 13:09:12 +00:00
|
|
|
|
bool TPartite_array::destroy(TPartita& game)
|
|
|
|
|
{
|
|
|
|
|
const TString& k = key(game.conto(), game.anno(), game.numero());
|
|
|
|
|
return remove(k);
|
|
|
|
|
}
|
|
|
|
|
|
1995-08-25 07:39:49 +00:00
|
|
|
|
bool TPartite_array::write(bool re)
|
|
|
|
|
{
|
2010-01-27 15:37:13 +00:00
|
|
|
|
bool ok = true;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
|
|
|
|
TPartita* game;
|
|
|
|
|
restart();
|
|
|
|
|
while ((game = (TPartita*)get()) != NULL)
|
|
|
|
|
{
|
1995-11-20 15:25:19 +00:00
|
|
|
|
ok = game->write(re);
|
|
|
|
|
if (!ok) // L'errore viene gia' segnalato dalla partita
|
1995-08-25 07:39:49 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
1995-11-20 15:25:19 +00:00
|
|
|
|
return ok;
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-08-30 12:14:19 +00:00
|
|
|
|
void TPartite_array::destroy()
|
|
|
|
|
{
|
|
|
|
|
TAssoc_array::destroy();
|
|
|
|
|
_numreg = 0;
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1995-08-30 12:14:19 +00:00
|
|
|
|
|
|
|
|
|
// Aggiunge all'array tutte le partite che si riferiscono alla registrazione nreg
|
|
|
|
|
int TPartite_array::add_numreg(long nreg)
|
|
|
|
|
{
|
|
|
|
|
if (nreg != _numreg)
|
1995-08-28 07:50:28 +00:00
|
|
|
|
{
|
1996-02-08 15:46:39 +00:00
|
|
|
|
TRelation rel(LF_PARTITE);
|
1995-08-30 12:14:19 +00:00
|
|
|
|
|
1996-02-07 11:51:14 +00:00
|
|
|
|
TRectype& part = rel.curr();
|
|
|
|
|
part.zero();
|
1995-08-30 12:14:19 +00:00
|
|
|
|
part.put(PART_NREG, nreg);
|
1996-02-08 15:46:39 +00:00
|
|
|
|
|
2005-11-08 18:07:06 +00:00
|
|
|
|
// Uso un cursore per evitare conflitti di lettura con l'oggetto partita
|
1996-02-08 15:46:39 +00:00
|
|
|
|
TCursor cur(&rel, "", 2, &part, &part);
|
1998-03-11 11:03:34 +00:00
|
|
|
|
cur.freeze();
|
1996-02-08 15:46:39 +00:00
|
|
|
|
for (cur = 0; cur.ok(); ++cur)
|
1995-09-01 15:06:35 +00:00
|
|
|
|
partita(part); // Aggiungi partita se non esiste gia'
|
1996-02-08 15:46:39 +00:00
|
|
|
|
|
1995-08-30 12:14:19 +00:00
|
|
|
|
_numreg = nreg;
|
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
|
1995-08-30 12:14:19 +00:00
|
|
|
|
return items();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-09-29 16:21:08 +00:00
|
|
|
|
bool TPartite_array::utilizzata(long numreg, int numrig)
|
|
|
|
|
{
|
|
|
|
|
bool ok = FALSE;
|
|
|
|
|
for (TPartita* game = first(); game; game = next())
|
|
|
|
|
{
|
|
|
|
|
ok = game->mov2rig(numreg, numrig) > 0;
|
|
|
|
|
if (ok) break;
|
|
|
|
|
}
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-08 15:46:39 +00:00
|
|
|
|
TImporto TPartite_array::importo_speso(long nreg, int numrig, bool valuta, int mode)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
|
|
|
|
TImporto imp;
|
1998-05-11 15:57:22 +00:00
|
|
|
|
// add_numreg(nreg); // Gia' fatto nella read del movimento nreg
|
1995-08-25 07:39:49 +00:00
|
|
|
|
for (TPartita* game = first(); game; game = next())
|
1996-02-08 15:46:39 +00:00
|
|
|
|
imp += game->importo_speso(nreg, numrig, valuta, mode);
|
1995-09-29 16:21:08 +00:00
|
|
|
|
imp.normalize();
|
1995-08-25 07:39:49 +00:00
|
|
|
|
return imp;
|
|
|
|
|
}
|
|
|
|
|
|
1996-02-13 16:35:59 +00:00
|
|
|
|
void TPartite_array::update_reg(const TRectype& mov, long old_nreg)
|
1995-08-25 07:39:49 +00:00
|
|
|
|
{
|
1998-05-11 15:57:22 +00:00
|
|
|
|
if (old_nreg <= 0 && old_nreg != NUMREG_PROVVISORIO)
|
1995-08-30 12:14:19 +00:00
|
|
|
|
old_nreg = mov.get_long(MOV_NUMREG);
|
1998-05-11 15:57:22 +00:00
|
|
|
|
// add_numreg(nreg); // Non farlo mai piu', carica movimenti registrati contemporaneamente!
|
1996-02-13 16:35:59 +00:00
|
|
|
|
|
|
|
|
|
const int tot = items();
|
|
|
|
|
if (tot > 0)
|
|
|
|
|
{
|
|
|
|
|
TPartita** giochi = new TPartita*[tot];
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (TPartita* game = first(); game; game = next())
|
|
|
|
|
giochi[i++] = game;
|
|
|
|
|
while (--i >= 0)
|
|
|
|
|
giochi[i]->update_reg(old_nreg, mov, *this);
|
|
|
|
|
|
1998-05-11 15:57:22 +00:00
|
|
|
|
delete [] giochi;
|
1996-02-13 16:35:59 +00:00
|
|
|
|
}
|
1995-08-25 07:39:49 +00:00
|
|
|
|
}
|
1995-08-29 13:11:15 +00:00
|
|
|
|
|
1996-01-11 15:44:06 +00:00
|
|
|
|
TRiga_partite* TPartite_array::mov2rig(long numreg, int numrig)
|
|
|
|
|
{
|
|
|
|
|
for (TPartita* game = first(); game; game = next())
|
|
|
|
|
{
|
|
|
|
|
const int r = game->mov2rig(numreg, numrig);
|
|
|
|
|
if (r > 0)
|
|
|
|
|
return &game->riga(r);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
2009-08-26 08:58:10 +00:00
|
|
|
|
}
|