campo-sirio/tc/tc0700.cpp
alex 797e8900fb Patch level : 4.0 673
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :

Riportata la versione 3.1 patch 873


git-svn-id: svn://10.65.10.50/trunk@15151 c028cbd2-c16b-5b4b-a496-9718f37d4682
2007-03-30 13:51:17 +00:00

352 lines
7.7 KiB
C++
Executable File

#include "tc0.h"
#include "tc0701.h"
#include "tc0700a.h"
#include <automask.h>
#include <progind.h>
#include <reprint.h>
#include <anagr.h>
#include <anafis.h>
#include <clifo.h>
#include <comuni.h>
#include <causali.h>
#include <nditte.h>
#include <mov.h>
#include <rmov.h>
#include <rmoviva.h>
#include <multirel.h>
#include "../cg/cglib01.h"
///////////////////////////////////////////////////////////
// TTS_mask
///////////////////////////////////////////////////////////
class TTS_mask : public TAutomask
{
clock_t _next_update;
bool _updating;
private:
bool apply_filter(const TRecordset& righe) const;
void serialize(bool bSave);
protected:
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
public:
TTS_mask();
~TTS_mask();
};
bool TTS_mask::apply_filter(const TRecordset& righe) const
{
const TDate dal = get(F_DATA_DA);
const TDate al = get(F_DATA_AL);
if (dal.ok() || al.ok())
{
const TDate scad = righe.get("DATASCAD").as_date();
if ((dal.ok() && scad < dal) || (al.ok() && scad > al))
return false;
}
return true;
}
bool TTS_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
{
bool ok = true;
switch (o.dlg())
{
case F_DATA_DA:
case F_DATA_AL:
break;
default:
break;
}
return ok;
}
void TTS_mask::serialize(bool bSave)
{
const char* defpar = "tc";
TConfig ini(CONFIG_DITTA, defpar);
for (int i = fields()-1; i >= 0; i--)
{
TMask_field& f = fld(i);
const TFieldref* fr = f.field();
if (fr != NULL)
{
if (bSave)
fr->write(ini, defpar, f.get());
else
f.set(fr->read(ini, defpar));
}
}
}
TTS_mask::TTS_mask()
: TAutomask("tc0700a"), _updating(false), _next_update(0)
{
serialize(false);
}
TTS_mask::~TTS_mask()
{
serialize(true);
}
///////////////////////////////////////////////////////////
// TTS_campo_sender
///////////////////////////////////////////////////////////
class TTS_campo_sender : public TTS_sender
{
TTS_mask * _mask;
TAssoc_array _caus_regolarizzazione;
protected:
virtual TRecordset & movrecset();
virtual TRecordset & rmovrecset(const TRecordset & mov);
virtual TRecordset & rivarecset(const TRecordset & mov);
virtual const TRecordset & clirecset(const char tipocf, const long codcf);
virtual TMask & get_mask();
protected:
virtual const char * decode_causale(const TRecordset& mov);
virtual bool test_swap(const TRecordset& mov);
virtual bool swap_ritsoc(const TRecordset& mov);
virtual bool mov_regolarizzazione(const TRecordset& mov);
virtual bool mov_intra(const TRecordset& mov);
virtual bool mov_reverse_charge(const TRecordset& mov);
public:
virtual void postprocess_movs(TRecordset & mov);
virtual bool create();
TTS_campo_sender() : TTS_sender(), _mask(NULL) {}
~TTS_campo_sender();
};
TTS_campo_sender::~TTS_campo_sender()
{
delete _mask;
}
TRecordset & TTS_campo_sender::movrecset()
{
const TMask & m = get_mask();
const TDate from = m.get_date(F_DATA_DA);
const TDate to = m.get_date(F_DATA_AL);
TRecordset * mov = get_recset(LF_MOV);
if (mov == NULL)
{
TString query = "USE MOV KEY 2 SELECT INVIATO!=\"X\"";
query << "\nFROM DATAREG=#DATA_DA";
query << "\nTO DATAREG=#DATA_AL";
mov = set_recset(LF_MOV, ::create_recordset(query));
}
mov->set_var("#DATA_DA", TVariant(from));
mov->set_var("#DATA_AL", TVariant(to));
return *mov;
}
TRecordset & TTS_campo_sender::rmovrecset(const TRecordset & mov)
{
TRecordset * rmov = get_recset(LF_RMOV);
if (rmov == NULL)
rmov = set_recset(LF_RMOV, ::create_recordset("USE RMOV\nFROM NUMREG=#NUMREG\nTO NUMREG=#NUMREG"));
const TVariant & numreg = mov.get(MOV_NUMREG);
if (numreg != rmov->get("#NUMREG"))
rmov->set_var("#NUMREG", numreg);
return *rmov;
}
TRecordset & TTS_campo_sender::rivarecset(const TRecordset & mov)
{
TRecordset * rmoviva = get_recset(LF_RMOVIVA);
if (rmoviva == NULL)
rmoviva = set_recset(LF_RMOVIVA, ::create_recordset("USE RMOVIVA\nFROM NUMREG=#NUMREG\nTO NUMREG=#NUMREG"));
const TVariant & numreg = mov.get(MOV_NUMREG);
if (numreg != rmoviva->get("#NUMREG"))
rmoviva->set_var("#NUMREG", numreg);
return *rmoviva;
}
const TRecordset& TTS_campo_sender::clirecset(const char tipocf, const long codcf)
{
TRecordset * clifo = get_recset(LF_CLIFO);
if (clifo == NULL)
clifo = set_recset(LF_CLIFO, ::create_recordset("USE CLIFO\nFROM TIPOCF=#TIPOCF CODCF=#CODCF\nTO TIPOCF=#TIPOCF CODCF=#CODCF"));
TString4 w; w << tipocf;
TVariant t(w);
clifo->set_var("#TIPOCF", t);
clifo->set_var("#CODCF", codcf);
clifo->move_first();
return *clifo;
}
bool TTS_campo_sender::test_swap(const TRecordset& mov)
{
TRecordset & rmov = rmovrecset(mov);
rmov.move_first();
const char sez = rmov.get(RMV_SEZIONE).as_string()[0];
const bool vendite = mov.get(MOV_TIPO).as_string()[0] != 'F';
const bool s = vendite ^ (sez == 'D');
return s;
}
bool TTS_campo_sender::swap_ritsoc(const TRecordset& mov)
{
TRecordset & rmov = rmovrecset(mov);
bool ok = rmov.move_first();
const char sez = rmov.get(RMV_SEZIONE).as_string()[0];
char sezrit = sez;
for (; ok; ok = rmov.move_next())
{
const char tiporiga = rmov.get(RMV_ROWTYPE).as_string()[0];
if (tiporiga =='S')
{
sezrit = rmov.get(RMV_SEZIONE).as_string()[0];
break;
}
}
const bool s = sez != sezrit;
return s;
}
bool TTS_campo_sender::mov_regolarizzazione(const TRecordset& mov)
{
const TString& codcaus = mov.get(MOV_CODCAUS).as_string();
return _caus_regolarizzazione.objptr(codcaus) != NULL;
}
bool TTS_campo_sender::mov_intra(const TRecordset& mov)
{
const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
return caus.get_bool(CAU_INTRACOM);
}
bool TTS_campo_sender::mov_reverse_charge(const TRecordset& mov)
{
const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
const int regsp = caus.get_int(CAU_REGSPIVA);
return regsp == 13 || regsp == 50 || regsp == 51;
}
TMask & TTS_campo_sender::get_mask()
{
if (_mask == NULL)
{
_mask = new TTS_mask;
TDate to(TODAY);
TConfig configtc(CONFIG_DITTA, "tc");
const TDate from(configtc.get("TSULTINV"));
to.addmonth(-1);
to.set_end_month();
if (to <= from)
{
to = from;
to.addmonth(1);
to.set_end_month();
}
_mask->set(F_DATA_DA, from);
_mask->set(F_DATA_AL, to);
}
return * _mask;
}
const char * TTS_campo_sender::decode_causale(const TRecordset& mov)
{
const TRectype& caus = cache().get(LF_CAUSALI, mov.get(MOV_CODCAUS).as_string());
return caus.get(CAU_DESCR);
}
void TTS_campo_sender::postprocess_movs(TRecordset & mov)
{
if (yesno_box(TR("Confermare il traferimento")))
{
TConfig configtc(CONFIG_DITTA);
TMask & m = get_mask();
configtc.set("TSULTINV", m.get_date(F_DATA_AL));
if (mov.items() > 0L)
{
TProgind pi(mov.items(), TR("Conferma movimenti"), true, true);
TLocalisamfile cgmov(LF_MOV);
for (bool ok = mov.move_first(); ok; ok = mov.move_next())
{
if (!pi.addstatus(1))
break;
const long numreg = mov.get(MOV_NUMREG).as_int();
cgmov.put(MOV_NUMREG, numreg);
if (cgmov.read(_isequal, _lock) == NOERR)
{
cgmov.put(MOV_INVIATO, true);
cgmov.rewrite();
}
}
}
}
}
bool search_reg(const TRelation& rel, void* pJolly)
{
TAssoc_array * _caus_regolarizzazione = (TAssoc_array *) pJolly;
const TString codcaus = rel.lfile().get(CAU_CODCAUREG);
if (codcaus.full())
_caus_regolarizzazione->add(codcaus, codcaus);
return true;
}
bool TTS_campo_sender::create()
{
bool ok = TTS_sender::create();
if (ok)
{
TCursor c(new TRelation(LF_CAUSALI));
ok = c.scan(search_reg, &_caus_regolarizzazione, "Ricerca causali di regolarizzazione");
}
return ok;
}
int tc0700(int argc, char* argv[])
{
TTS_campo_sender app;
app.run(argc, argv, "Invio a TeamSystem");
return 0;
}