campo-sirio/ce/ce2400.cpp
alex 5a4e83275c *** empty log message ***
git-svn-id: svn://10.65.10.50/trunk@11857 c028cbd2-c16b-5b4b-a496-9718f37d4682
2004-03-13 09:12:24 +00:00

233 lines
5.6 KiB
C++
Executable File
Raw Blame History

#include <applicat.h>
#include <automask.h>
#include <execp.h>
#include <progind.h>
#include <relation.h>
#include "celib.h"
#include "ce2101.h"
#include "ce2400a.h"
#include "cespi.h"
#include "movce.h"
class TCesp_tras_mask : public TAutomask
{
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
protected:
void fill_dates();
public:
TCesp_tras_mask() : TAutomask("ce2400a") { }
};
void TCesp_tras_mask::fill_dates()
{
TSheet_field& s = sfield(F_DATE_CALC);
TRelation rel("CCB");
rel.add("%CAT", "CODTAB=CODTAB[5,10]");
TString expr;
expr << "CODTAB[1,4]==" << get(F_ESERCIZIO);
TCursor cur(&rel, expr);
const long items = cur.items();
cur.freeze();
s.destroy();
const TRectype& curr = rel.curr();
const TRectype& cat = rel.curr(LF_TABCOM);
bool some_empty = FALSE;
for (cur = 0; cur.pos() < items; ++cur)
{
TToken_string& row = s.row(-1);
const TString& data = curr.get("D0");
some_empty |= data.blank();
row.add(data);
row.add(curr.get("CODTAB").mid(4,2));
row.add(curr.get("CODTAB").mid(6,4));
row.add(cat.get("S0"));
}
s.force_update();
if (some_empty)
{
disable(F_CALC);
set(F_CALC, "X");
}
else
enable(F_CALC);
}
bool TCesp_tras_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
switch(o.dlg())
{
case F_ESERCIZIO:
if (e == fe_init || e == fe_modify)
fill_dates();
break;
case F_DATE_CALC:
if (e == se_query_add || e == se_query_del)
return FALSE;
break;
default: break;
}
return TRUE;
}
///////////////////////////////////////////////////////////
// Iteratori
///////////////////////////////////////////////////////////
typedef bool (*RecordHandler)(TRelation& rel, void* jolly);
unsigned long scan_cursor(TCursor& cur, RecordHandler rh, void* jolly)
{
unsigned long processed = 0;
const long items = cur.items();
if (items > 0)
{
TProgind* pi = items < 16 ? NULL : new TProgind(items, "Elaborazione in corso...");
TRelation& rel = *cur.relation();
cur.freeze();
for (cur = 0; cur.pos() < items; ++cur)
{
if (pi)
pi->addstatus(1);
if (rh(rel, jolly))
processed++;
}
if (pi)
delete pi;
}
return processed;
}
unsigned long scan_file(int lf, RecordHandler rh, void* jolly)
{
TRelation rel(lf);
TCursor cur(&rel);
return scan_cursor(cur, rh, jolly);
}
///////////////////////////////////////////////////////////
// Applicazione principale
///////////////////////////////////////////////////////////
class TCesp_tras : public TSkeleton_application
{
protected:
virtual void main_loop();
public:
void calcolo(const TMask& m);
void trasferimento(const TMask& m);
};
void TCesp_tras::calcolo(const TMask& m)
{
TExternal_app a("ce2 -0 A");
TSheet_field& s = m.sfield(F_DATE_CALC);
for (int i = 0; i < s.items(); i++)
{
TToken_string& row = s.row(i);
const int anno = m.get_int(F_ESERCIZIO);
const int gruppo = row.get_int(1);
const TString4 specie = row.get();
ditta_cespiti().set_attivita(anno, gruppo, specie);
a.run();
}
}
struct TTras_data
{
int _anno;
TDate _inizio, _fine;
const TCespite* _cespite;
};
static bool MovHandler(TRelation& rel, void* jolly)
{
const TTras_data& data = *(const TTras_data*)jolly;
const TRectype& movce = rel.curr();
if (movce.get_bool(MOVCE_STAMPATO)) // Salta i movimenti gi<67> stampati su bollato
return FALSE;
const TDate dtmov = movce.get_date(MOVCE_DTMOV);
const TDate dtacq = data._cespite->get_date(CESPI_DTCOMP);
if (dtmov < dtacq) // Ignora movimenti precedenti l'acquisizione del cespite
return FALSE;
return TRUE;
}
static bool CespHandler(TRelation& rel, void* jolly)
{
const TCespite cespite(rel.curr());
TTras_data& data = *(TTras_data*)jolly;
data._cespite = &cespite; // Inizializza cespite corrente
const TDate dtalien = cespite.get_date(CESPI_DTALIEN);
if (dtalien.ok() && dtalien < data._inizio) // Escludi cespiti alienati
return FALSE;
const TDate dtcomp = cespite.get_date(CESPI_DTCOMP);
if (!dtcomp.ok() || dtcomp > data._fine) // Escludi cespiti non in funzione
return FALSE;
const TRectype& cat = cespite.categoria();
if (cat.get_bool("B0")) // Categoria non ammortizzabile
return FALSE;
// Scansione di tutti i movimenti dell'anno relativi al cespite corrente
TRelation rel_movce(LF_MOVCE);
rel_movce.add(LF_MOVAM, "IDCESPITE==IDCESPITE|IDMOV==IDMOV|TPAMM==1"); // Solo situazione fiscale
rel_movce.add(LF_AMMMV, "IDCESPITE==IDCESPITE|IDMOV==IDMOV|TPAMM==1");
TRectype& movce = rel_movce.curr();
movce.put(MOVCE_IDCESPITE, cespite.get(CESPI_IDCESPITE));
TString expr;
expr << "(ANSI(DTMOV)>=" << data._inizio.string(ANSI) << ")&&";
expr << "(ANSI(DTMOV)<=" << data._fine.string(ANSI) << ")";
TCursor cur_movce(&rel_movce, expr, 1, &movce, &movce);
scan_cursor(cur_movce, MovHandler, jolly);
return TRUE;
}
void TCesp_tras::trasferimento(const TMask& m)
{
TTras_data data;
data._anno = m.get_int(F_ESERCIZIO);
data._inizio = m.get(F_INIZIO_ES);
data._fine = m.get(F_FINE_ES);
scan_file(LF_CESPI, CespHandler, &data);
}
void TCesp_tras::main_loop()
{
TDitta_cespiti& dc = ditta_cespiti();
TCesp_tras_mask m;
dc.init_mask(m);
if (m.run() == K_ENTER)
{
if (m.get_bool(F_CALC))
calcolo(m);
trasferimento(m);
}
}
int ce2400(int argc, char* argv[])
{
TCesp_tras a;
a.run(argc, argv, TR("Trasferimento movimenti"));
return 0;
}