git-svn-id: svn://10.65.10.50/branches/R_10_00@22612 c028cbd2-c16b-5b4b-a496-9718f37d4682
359 lines
9.1 KiB
C++
359 lines
9.1 KiB
C++
#include "sc0300a.h"
|
|
#include "../cg/cgsalda3.h"
|
|
|
|
#include <applicat.h>
|
|
#include <automask.h>
|
|
#include <progind.h>
|
|
#include <recset.h>
|
|
#include <relation.h>
|
|
#include <treectrl.h>
|
|
|
|
#include <mov.h>
|
|
|
|
class TPareggio_tree : public TObject_tree
|
|
{
|
|
TPartite_array _games;
|
|
|
|
protected:
|
|
virtual TFieldtypes get_var(const TString& name, TVariant& var) const;
|
|
virtual bool marked() const { return rand() % 2 != 0; }
|
|
const TPartita& partita(const TRectype& rec) const;
|
|
|
|
public:
|
|
bool init(const TBill& bill, const TString& valuta, bool nc, int stato); // Stato- 1=aperte; 2=chiuse; 0 o 3 = tutte
|
|
};
|
|
|
|
const TPartita& TPareggio_tree::partita(const TRectype& rec) const
|
|
{
|
|
return ((TPartite_array&)_games).partita(rec);
|
|
}
|
|
|
|
TFieldtypes TPareggio_tree::get_var(const TString& name, TVariant& var) const
|
|
{
|
|
TFieldtypes ft = _nullfld;
|
|
const TObject* obj = curr_node();
|
|
if (obj != NULL)
|
|
{
|
|
if (obj->is_kind_of(CLASS_RECTYPE))
|
|
{
|
|
const TRectype& rec = *(const TRectype*)obj;
|
|
ft = rec.type(name);
|
|
if (ft != _nullfld)
|
|
{
|
|
if (ft == _realfld)
|
|
{
|
|
var = rec.get_real(name).stringa(0, 2);
|
|
ft = _alfafld;
|
|
}
|
|
else
|
|
var = rec.get(name);
|
|
}
|
|
else
|
|
{
|
|
if (name.starts_with("PART.", true))
|
|
{
|
|
const TString& fld = name.after(".");
|
|
if (rec.num() == LF_SCADENZE)
|
|
{
|
|
const int nriga = rec.get_int(SCAD_NRIGA);
|
|
const TPartita& game = partita(rec);
|
|
var = game.riga(nriga).get(fld);
|
|
ft = _alfafld;
|
|
}
|
|
else
|
|
{
|
|
var = rec.get(fld);
|
|
ft = _alfafld;
|
|
}
|
|
} else
|
|
if (name == "RESIDUO")
|
|
{
|
|
TImporto saldo;
|
|
switch (rec.num())
|
|
{
|
|
case LF_SCADENZE:
|
|
if (!rec.get_bool(SCAD_PAGATA))
|
|
{
|
|
const TPartita& game = partita(rec);
|
|
const TRiga_scadenze& s = game.rata(rec.get_int(SCAD_NRIGA), rec.get_int(SCAD_NRATA));
|
|
saldo = s.residuo(true);
|
|
}
|
|
break;
|
|
case LF_PARTITE:
|
|
if (!rec.get_bool(PART_CHIUSA))
|
|
{
|
|
const TPartita& game = partita(rec);
|
|
saldo = game.calcola_saldo(true);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
var = saldo.valore().stringa(0, 2);
|
|
ft = _alfafld;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (name == PART_NUMPART)
|
|
{
|
|
const real& year = *(real*)obj;
|
|
var = year.integer();
|
|
ft = _intfld;
|
|
}
|
|
}
|
|
}
|
|
return ft;
|
|
}
|
|
|
|
|
|
bool TPareggio_tree::init(const TBill& bill, const TString& valuta, bool nc, int stato)
|
|
{
|
|
goto_root();
|
|
kill_node();
|
|
|
|
TString filter;
|
|
if (bill.tipo() > ' ')
|
|
filter << PART_TIPOCF << '=' << bill.tipo();
|
|
else
|
|
{
|
|
filter << PART_GRUPPO << '=' << bill.gruppo() << ' ';
|
|
filter << PART_CONTO << '=' << bill.conto();
|
|
}
|
|
filter << ' ' << PART_SOTTOCONTO << '=' << bill.sottoconto();
|
|
|
|
TString query;
|
|
query << "USE PART SELECT (NRIGA<9999)&&(TIPOMOV<=" << (nc ? tm_nota_credito : tm_fattura) << ')'
|
|
<< "\nFROM " << filter << "\nTO " << filter;
|
|
TISAM_recordset games(query);
|
|
const TRectype& rec = games.cursor()->curr();
|
|
|
|
int last_year = 0;
|
|
TString80 id_year, id_rec;
|
|
|
|
TProgind pi(games.items(), nc ? TR("Caricamento note di credito") : TR("Caricamento fatture"));
|
|
for (bool ok = games.move_first(); ok; ok = games.move_next())
|
|
{
|
|
if (!pi.addstatus(1))
|
|
break;
|
|
|
|
const TString& codval = rec.get(PART_CODVAL);
|
|
if (!same_values(codval, valuta))
|
|
continue;
|
|
|
|
const tipo_movimento tm = (tipo_movimento)rec.get_int(PART_TIPOMOV);
|
|
bool add_riga = true;
|
|
if (nc)
|
|
{
|
|
add_riga = !rec.get_bool(PART_CHIUSA);
|
|
if (add_riga)
|
|
{
|
|
// Se filtro le note di credito cerco di riconoscere le fatture negative
|
|
if (tm == tm_fattura)
|
|
{
|
|
const char sezione_positiva = bill.tipo() == 'C' ? 'D' : 'A';
|
|
TImporto importo(rec.get_char(PART_SEZ), rec.get_real(PART_IMPORTO));
|
|
importo.normalize();
|
|
add_riga = sezione_positiva != importo.sezione(); // Ignora fattura positiva
|
|
}
|
|
else
|
|
{
|
|
const int nriga = rec.get_int(PART_NRIGA);
|
|
const TPartita& game = partita(rec);
|
|
add_riga = ((TPartita&)game).unassigned().exist(nriga);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (stato == 1 || stato == 2)
|
|
{
|
|
const bool chiusa = rec.get_bool(PART_CHIUSA);
|
|
if (chiusa)
|
|
add_riga = stato == 2;
|
|
else
|
|
add_riga = stato == 1;
|
|
}
|
|
if (add_riga)
|
|
{
|
|
const char sezione_positiva = bill.tipo() == 'C' ? 'D' : 'A';
|
|
TImporto importo(rec.get_char(PART_SEZ), rec.get_real(PART_IMPORTO));
|
|
importo.normalize();
|
|
add_riga = sezione_positiva == importo.sezione(); // Ignora fattura negativa
|
|
}
|
|
}
|
|
|
|
if (!add_riga)
|
|
continue;
|
|
|
|
const int year = rec.get_int(PART_ANNO);
|
|
if (year != last_year)
|
|
{
|
|
goto_root();
|
|
while(goto_rbrother());
|
|
add_rbrother(real(year));
|
|
|
|
last_year = year;
|
|
curr_id(id_year);
|
|
id_rec.cut(0);
|
|
}
|
|
|
|
if (nc)
|
|
{
|
|
if (id_rec.full())
|
|
{
|
|
goto_node(id_rec);
|
|
add_rbrother(rec);
|
|
}
|
|
else
|
|
add_son(rec);
|
|
curr_id(id_rec);
|
|
}
|
|
else
|
|
{
|
|
TPartita game(rec);
|
|
const TRiga_partite& riga = game.riga(rec.get_int(PART_NRIGA));
|
|
for (int rata = 1; rata <= riga.rate(); rata++)
|
|
{
|
|
const TRiga_scadenze& s = riga.rata(rata);
|
|
bool add_rata = true;
|
|
if (stato == 1 || stato == 2)
|
|
{
|
|
const bool chiusa = s.get_bool(SCAD_PAGATA);
|
|
if (chiusa)
|
|
add_rata = stato == 2;
|
|
else
|
|
add_rata = stato == 1;
|
|
}
|
|
if (add_rata)
|
|
{
|
|
if (id_rec.full())
|
|
add_rbrother(s);
|
|
else
|
|
add_son(s);
|
|
curr_id(id_rec);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (goto_node(id_year))
|
|
expand();
|
|
|
|
return goto_root();
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TPareggio_mask
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPareggio_mask : public TAutomask
|
|
{
|
|
TPareggio_tree _nc, _ft;
|
|
long _numreg;
|
|
|
|
protected:
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
public:
|
|
TPareggio_mask();
|
|
};
|
|
|
|
bool TPareggio_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
{
|
|
switch (o.dlg())
|
|
{
|
|
//case F_SOTTOCONTO:
|
|
case F_CLIENTE:
|
|
case F_FORNITORE:
|
|
case F_CODVAL:
|
|
case F_TUTTE:
|
|
if (e == fe_modify)
|
|
{
|
|
TWait_cursor hourglass;
|
|
const short id = efield(F_FORNITORE).active() ? F_FORNITORE :
|
|
(efield(F_SOTTOCONTO).active() ? F_SOTTOCONTO : F_CLIENTE);
|
|
TBill bill; bill.get(*this, F_GRUPPO, F_CONTO, id, F_TIPO);
|
|
const int tipo = get_int(F_TUTTE);
|
|
const TString& codval = get(F_CODVAL);
|
|
_nc.init(bill, codval, true, 1); // Solo aperte
|
|
_ft.init(bill, codval, false, tipo);
|
|
|
|
tfield(F_NC_TREE).set_tree(&_nc);
|
|
tfield(F_FT_TREE).set_tree(&_ft);
|
|
_numreg = 0;
|
|
disable(DLG_LINK);
|
|
}
|
|
break;
|
|
case F_NC_TREE:
|
|
case F_FT_TREE:
|
|
if (e == fe_button || e == fe_modify)
|
|
{
|
|
TTree_field& tf = (TTree_field&)o;
|
|
TVariant var;
|
|
if (tf.tree()->get_var("PART.NREG", var))
|
|
_numreg = var.as_int();
|
|
else
|
|
_numreg = 0L;
|
|
enable(DLG_LINK, _numreg > 0);
|
|
}
|
|
break;
|
|
case DLG_LINK:
|
|
if (_numreg > 0)
|
|
{
|
|
TRectype mov(LF_MOV); mov.put(MOV_NUMREG, _numreg);
|
|
if (mov.edit())
|
|
send_key(K_SPACE, F_TUTTE, &o);
|
|
}
|
|
break;
|
|
default: break;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
TPareggio_mask::TPareggio_mask() : TAutomask("sc0300a"), _numreg(0L)
|
|
{
|
|
RCT rct_nc; field(F_NC_TREE).get_rect(rct_nc);
|
|
RCT rct_ft; field(F_FT_TREE).get_rect(rct_ft);
|
|
|
|
rct_nc.right = rct_ft.left-8;
|
|
rct_ft.right = rct_ft.left + rct_nc.right - rct_nc.left;
|
|
|
|
field(F_NC_TREE).set_rect(rct_nc);
|
|
field(F_FT_TREE).set_rect(rct_ft);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// TPareggio_partite
|
|
///////////////////////////////////////////////////////////
|
|
|
|
class TPareggio_partite : public TSkeleton_application
|
|
{
|
|
protected:
|
|
virtual void main_loop();
|
|
};
|
|
|
|
void TPareggio_partite::main_loop()
|
|
{
|
|
const int anno = xvt_vobj_get_attr(NULL_WIN, ATTR_APPL_VERSION_YEAR);
|
|
if (anno > 2101)
|
|
{
|
|
TPareggio_mask pm;
|
|
pm.run();
|
|
}
|
|
else
|
|
error_box(TR("Versione non supportata: %d"), anno);
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////
|
|
// Main
|
|
///////////////////////////////////////////////////////////
|
|
|
|
int sc0300(int argc, char* argv[])
|
|
{
|
|
TPareggio_partite pp;
|
|
pp.run(argc, argv, TR("Pareggio Partite"));
|
|
return 0;
|
|
}
|