2005-04-07 12:52:46 +00:00
|
|
|
#include <automask.h>
|
|
|
|
#include <defmask.h>
|
|
|
|
#include <relapp.h>
|
2005-05-17 11:10:41 +00:00
|
|
|
#include <tabutil.h>
|
2005-04-07 12:52:46 +00:00
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#include "li0.h"
|
|
|
|
#include "li0400a.h"
|
|
|
|
|
|
|
|
#include "letint.h"
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
// MASCHERA (li0400a)
|
|
|
|
//-------------------------------------------------------------------
|
|
|
|
class TLetint_mask : public TAutomask
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
|
|
|
|
|
|
|
public:
|
2005-05-17 11:10:41 +00:00
|
|
|
TDate ultima_stampa(int anno);
|
|
|
|
bool is_registro(int anno) { return ultima_stampa(anno) > botime;}
|
2005-04-07 12:52:46 +00:00
|
|
|
TLetint_mask();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool TLetint_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
switch (o.dlg())
|
2005-04-07 13:39:10 +00:00
|
|
|
{
|
2005-05-17 11:10:41 +00:00
|
|
|
case F_ANNO:
|
|
|
|
if (e == fe_modify || e == fe_init || e == fe_close)
|
|
|
|
{
|
|
|
|
if (!is_registro(atoi(o.get())))
|
|
|
|
return error_box(FR("Manca il registro dichiarazioni d'intento per l'anno %d"), atoi(o.get()));
|
|
|
|
}
|
2005-04-07 13:39:10 +00:00
|
|
|
case F_NUMPROT:
|
|
|
|
if (e == fe_close && query_mode())
|
|
|
|
{
|
|
|
|
const long numprot = get_long(F_NUMPROT);
|
|
|
|
if (numprot > 1)
|
|
|
|
{
|
|
|
|
const int anno = get_int(F_ANNO);
|
|
|
|
TLocalisamfile letint(LF_LETINT);
|
|
|
|
letint.put(LETINT_ANNO, anno);
|
|
|
|
letint.put(LETINT_NUMPROT, numprot - 1);
|
|
|
|
if (letint.read() != NOERR)
|
|
|
|
return error_box(TR("Il numero di protocollo deve essere progressivo!"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2005-05-17 11:10:41 +00:00
|
|
|
case F_VSDATA:
|
|
|
|
if (e == fe_modify)
|
|
|
|
{
|
|
|
|
const TDate datareg(o.mask().get(F_DATAREG));
|
|
|
|
const TDate dataem(o.get());
|
|
|
|
if (dataem > datareg)
|
|
|
|
return error_box(FR("Data di emissione %s superiore alla data di registrazione %s"), (const char *) dataem.string(), (const char *) datareg.string());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case F_DATAREG:
|
2005-04-07 13:39:10 +00:00
|
|
|
if (e == fe_close && insert_mode())
|
2005-04-07 12:52:46 +00:00
|
|
|
{
|
|
|
|
const long numprot = get_long(F_NUMPROT);
|
2005-04-07 13:39:10 +00:00
|
|
|
if (numprot > 1)
|
|
|
|
{
|
|
|
|
const int anno = get_int(F_ANNO);
|
|
|
|
TLocalisamfile letint(LF_LETINT);
|
|
|
|
letint.put(LETINT_ANNO, anno);
|
2005-05-17 11:10:41 +00:00
|
|
|
letint.put(LETINT_NUMPROT, numprot - 1);
|
2005-04-07 13:39:10 +00:00
|
|
|
if (letint.read() == NOERR)
|
|
|
|
{
|
|
|
|
const TDate& old_data = letint.get_date(LETINT_DATAREG);
|
|
|
|
if (get_date(F_DATAREG) < old_data)
|
|
|
|
return error_box(TR("La data di registrazione non puo' essere antecedente a %s"), (const char*) old_data.string());
|
|
|
|
}
|
2005-05-17 11:10:41 +00:00
|
|
|
TDate ultima = ultima_stampa(anno);
|
|
|
|
if (get_date(F_DATAREG) <= ultima)
|
|
|
|
return error_box(TR("La data di registrazione non puo' essere antecedente a %s"), (const char*) ultima.string());
|
2005-04-07 13:39:10 +00:00
|
|
|
}
|
2005-04-07 12:52:46 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-17 11:10:41 +00:00
|
|
|
TDate TLetint_mask::ultima_stampa(int anno)
|
|
|
|
{
|
|
|
|
TTable reg("REG");
|
|
|
|
TDate ultima_stampa = botime;
|
|
|
|
TString s; s.format("%0d", anno);
|
|
|
|
|
|
|
|
reg.put("CODTAB", s);
|
|
|
|
for (int err = reg.read(_isgteq); s == reg.get("CODTAB").left(4) && err == NOERR; err = reg.next())
|
|
|
|
if (reg.get_int("I0") == 10)
|
|
|
|
{
|
|
|
|
ultima_stampa = reg.get_date("D3");
|
|
|
|
if (!ultima_stampa.ok())
|
|
|
|
{
|
|
|
|
ultima_stampa.set_day(1);
|
|
|
|
ultima_stampa.set_month(1);
|
|
|
|
ultima_stampa.set_year(anno);
|
|
|
|
--ultima_stampa;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ultima_stampa;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 12:52:46 +00:00
|
|
|
TLetint_mask::TLetint_mask() : TAutomask("li0400a")
|
|
|
|
{
|
|
|
|
first_focus(F_ANNO);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
// APPLICAZIONE
|
|
|
|
//--------------------------------------------------------------
|
|
|
|
class TLetint : public TRelation_application
|
|
|
|
{
|
|
|
|
TLetint_mask* _mask;
|
|
|
|
TRelation* _rel;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool user_create();
|
|
|
|
bool user_destroy();
|
|
|
|
virtual TMask* get_mask(int mode) { return _mask; }
|
|
|
|
virtual bool changing_mask(int mode) { return false; }
|
|
|
|
|
|
|
|
virtual bool get_next_key(TToken_string& key);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata
|
|
|
|
virtual bool check_autorization() const {return true;}
|
|
|
|
|
|
|
|
virtual TRelation* get_relation() const {return (TRelation*)_rel;}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
bool TLetint::get_next_key(TToken_string& key)
|
|
|
|
{
|
|
|
|
TLocalisamfile& letint = _rel->lfile() ;
|
|
|
|
long numprot = 1L ;
|
|
|
|
const int anno(_mask->get_int(F_ANNO)) ;
|
|
|
|
|
|
|
|
if (!letint.empty())
|
|
|
|
{
|
|
|
|
letint.zero() ;
|
|
|
|
letint.setkey(1) ;
|
|
|
|
|
|
|
|
letint.put(LETINT_ANNO, anno);
|
|
|
|
letint.read(_isgteq);
|
|
|
|
if (letint.good()) //se e' tutto ok,si posiziona sull'ultimo record con l'anno selezionato
|
|
|
|
letint.last();
|
|
|
|
|
|
|
|
if (letint.good())
|
|
|
|
{
|
|
|
|
const int year(letint.get_int(LETINT_ANNO));
|
|
|
|
if (year == anno)
|
|
|
|
numprot += letint.get_long(LETINT_NUMPROT);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
key.format("%d|%d|%d|%ld", F_ANNO, anno, F_NUMPROT, numprot);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TLetint::user_create()
|
|
|
|
{
|
|
|
|
_rel = new TRelation(LF_LETINT);
|
|
|
|
_mask = new TLetint_mask;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TLetint::user_destroy()
|
|
|
|
{
|
|
|
|
delete _mask;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int li0400(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TLetint a;
|
|
|
|
a.run(argc, argv, TR("Lettere d'intento"));
|
|
|
|
return 0;
|
|
|
|
}
|