deb2d098cb
Files correlati : fe0.exe fe0400a.msk Ricompilazione Demo : [ ] Commento : Aggiunto programma per controllo archivi dati rilevanti git-svn-id: svn://10.65.10.50/branches/R_10_00@22558 c028cbd2-c16b-5b4b-a496-9718f37d4682
241 lines
5.6 KiB
C++
241 lines
5.6 KiB
C++
#include <applicat.h>
|
||
#include <automask.h>
|
||
#include <recarray.h>
|
||
#include <recset.h>
|
||
#include <relation.h>
|
||
#include <progind.h>
|
||
#include <reputils.h>
|
||
|
||
#include "felib.h"
|
||
#include "../cg/cg2103.h"
|
||
|
||
#include <alleg.h>
|
||
#include <causali.h>
|
||
#include <doc.h>
|
||
#include <mov.h>
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TTest_spesometro_msk
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TTest_spesometro_msk : public TAutomask
|
||
{
|
||
private:
|
||
void log_msg(const TRectype& mov, const char* msg, TLog_report& log) const;
|
||
bool update_file(TLocalisamfile& f, const char* msg, TLog_report& log) const;
|
||
bool is_nota_variazione(const TRectype& mov) const;
|
||
bool elabora(int num, TLog_report& log);
|
||
|
||
bool _definitiva;
|
||
|
||
protected:
|
||
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
||
|
||
public:
|
||
TTest_spesometro_msk() : TAutomask("fe0400a") {}
|
||
};
|
||
|
||
void TTest_spesometro_msk::log_msg(const TRectype& mov, const char* msg, TLog_report& log) const
|
||
{
|
||
TString str;
|
||
switch (mov.num())
|
||
{
|
||
case LF_ALLEG: str << "Riga " << mov.get(ALL_PROGR); break;
|
||
case LF_MOV : str << "Movimento " << mov.get(MOV_NUMREG); break;
|
||
case LF_DOC : str << "Documento " << mov.get(DOC_CODNUM) << ' ' << mov.get(DOC_ANNO) << '/' << mov.get(DOC_NDOC); break;
|
||
default: break;
|
||
}
|
||
if (str.full())
|
||
{
|
||
str << ": " << msg;
|
||
log.log(1, str);
|
||
}
|
||
}
|
||
|
||
bool TTest_spesometro_msk::update_file(TLocalisamfile& f, const char* msg, TLog_report& log) const
|
||
{
|
||
int err = NOERR;
|
||
log_msg(f.curr(), msg, log);
|
||
if (_definitiva)
|
||
{
|
||
err = f.rewrite();
|
||
if (err != NOERR)
|
||
{
|
||
TString msg;
|
||
msg << TR("Impossibile aggiornare il file ") << f.description() << TR(": errore ") << err;
|
||
log.log(2, msg);
|
||
}
|
||
}
|
||
return err == NOERR;
|
||
}
|
||
|
||
bool TTest_spesometro_msk::is_nota_variazione(const TRectype& mov) const
|
||
{
|
||
bool yes = false;
|
||
switch (mov.num())
|
||
{
|
||
case LF_MOV:
|
||
yes = mov.get_int(MOV_TIPOMOV) == 2; // Nota di credito/debito per saldaconto
|
||
break;
|
||
case LF_DOC:
|
||
{
|
||
const TString& tipodoc = mov.get(DOC_TIPODOC);
|
||
const TString& codcaus = cache().get("%TIP", tipodoc, "S6");
|
||
if (codcaus.full())
|
||
{
|
||
const TRectype& caus = cache().get(LF_CAUSALI, codcaus);
|
||
yes = caus.get_int(CAU_TIPOMOV) == 2; // Nota di credito/debito per saldaconto
|
||
}
|
||
}
|
||
break;
|
||
default:
|
||
yes = fe_is_nota_variazione(mov);
|
||
break;
|
||
}
|
||
return yes;
|
||
}
|
||
|
||
|
||
bool TTest_spesometro_msk::elabora(int num, TLog_report& log)
|
||
{
|
||
const TString& anno = get(101);
|
||
|
||
TString str;
|
||
str << "USE " << num;
|
||
switch (num)
|
||
{
|
||
case LF_ALLEG:
|
||
str << "\nFROM ANNO=" << anno << "\nTO ANNO=" << anno;
|
||
break;
|
||
case LF_MOV:
|
||
str << "KEY 2\nFROM DATAREG=" << anno << "0101\nTO DATAREG=" << anno << "1231";
|
||
break;
|
||
case LF_DOC:
|
||
str << "\nFROM PROVV=D ANNO=" << anno << "\nTO PROVV=D ANNO=" << anno;
|
||
default:
|
||
break;
|
||
}
|
||
|
||
TISAM_recordset recset(str);
|
||
TLocalisamfile& file = recset.cursor()->file();
|
||
TRectype& curr = file.curr();
|
||
|
||
_definitiva = get_bool(102);
|
||
|
||
if (_definitiva)
|
||
str = TR("Aggiornamento");
|
||
else
|
||
str = TR("Controllo");
|
||
|
||
str << ' ' << file.description();
|
||
str << TR(" Anno ") << anno;
|
||
|
||
log.log(0, "");
|
||
log.log(1, str);
|
||
log.log(0, "");
|
||
|
||
TProgind pi(recset.items(), str, true, true);
|
||
|
||
bool done = true;
|
||
for (bool ok = recset.move_first(); ok && done; ok = recset.move_next())
|
||
{
|
||
if (!pi.addstatus(1))
|
||
break;
|
||
const int tipopag = curr.get_int(MOV_MODPAG);
|
||
const TString& contratto = curr.get(MOV_CONTRATTO);
|
||
if (contratto.full())
|
||
{
|
||
if (is_nota_variazione(curr))
|
||
{
|
||
curr.put(MOV_MODPAG, 1);
|
||
curr.zero(MOV_CONTRATTO);
|
||
done = update_file(file, TR("Azzerato contratto su nota di variazione"), log);
|
||
}
|
||
else
|
||
{
|
||
const TContratto c(curr);
|
||
const int t = c.modalita_pagamento();
|
||
if (t != tipopag)
|
||
{
|
||
str.cut(0) << TR("Cambiata modalit<69> di pagamento ") << tipopag << " -> " << t;
|
||
curr.put(MOV_MODPAG, t);
|
||
if (num == LF_MOV)
|
||
{
|
||
curr.zero(MOV_DATARETT);
|
||
curr.zero(MOV_NUMRETT);
|
||
}
|
||
done = update_file(file, str, log);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (tipopag > 1)
|
||
{
|
||
log_msg(curr, str, log);
|
||
curr.put(MOV_MODPAG, 1);
|
||
done = update_file(file, TR("Forzato pagamento non frazionato in assenza di contratto"), log);
|
||
}
|
||
}
|
||
}
|
||
return done;
|
||
}
|
||
|
||
|
||
bool TTest_spesometro_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
||
{
|
||
switch (o.dlg())
|
||
{
|
||
case DLG_OK:
|
||
case DLG_ELABORA:
|
||
if (e == fe_button)
|
||
{
|
||
TLog_report log;
|
||
for (int pos = id2pos(100+LF_ALLEG); pos >= 0 && pos < fields(); pos++)
|
||
{
|
||
const TMask_field& f = fld(pos);
|
||
if (!f.is_kind_of(CLASS_BOOLEAN_FIELD))
|
||
break;
|
||
if (f.get().full())
|
||
{
|
||
if (!elabora(f.dlg() - 100, log))
|
||
break;
|
||
}
|
||
}
|
||
log.preview();
|
||
return false;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// TTest_spesometro_app
|
||
///////////////////////////////////////////////////////////
|
||
|
||
class TTest_spesometro_app : public TSkeleton_application
|
||
{
|
||
public:
|
||
virtual void main_loop();
|
||
};
|
||
|
||
void TTest_spesometro_app::main_loop()
|
||
{
|
||
TTest_spesometro_msk msk;
|
||
msk.run();
|
||
}
|
||
|
||
///////////////////////////////////////////////////////////
|
||
// main
|
||
///////////////////////////////////////////////////////////
|
||
|
||
int fe0400(int argc, char* argv[])
|
||
{
|
||
TTest_spesometro_app app;
|
||
app.run(argc, argv, TR("Controllo file Spesometro"));
|
||
return 0;
|
||
}
|