1994-12-07 11:08:53 +00:00
|
|
|
#include <applicat.h>
|
|
|
|
#include <isam.h>
|
|
|
|
#include <mask.h>
|
|
|
|
#include <prefix.h>
|
|
|
|
#include <progind.h>
|
|
|
|
#include <relation.h>
|
|
|
|
#include <tabutil.h>
|
|
|
|
#include <utility.h>
|
|
|
|
|
|
|
|
#include <mov.h>
|
|
|
|
#include <urldefid.h>
|
|
|
|
|
|
|
|
#include "cg5.h"
|
|
|
|
#include "cg5400.h"
|
|
|
|
|
|
|
|
class TRipristina_stampa : public TApplication
|
|
|
|
{
|
|
|
|
TMask* _msk;
|
|
|
|
long _default_firm;
|
|
|
|
|
|
|
|
virtual bool create() ;
|
|
|
|
virtual bool destroy() ;
|
|
|
|
bool menu(MENU_TAG);
|
1995-01-16 15:08:33 +00:00
|
|
|
bool do_restore(long firm, const char * reg, int year, int month,
|
|
|
|
int day, bool giornale);
|
1994-12-07 11:08:53 +00:00
|
|
|
static bool firm_handler(TMask_field& f, KEY key);
|
|
|
|
|
|
|
|
public:
|
|
|
|
TRipristina_stampa() : _msk(NULL) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TRipristina_stampa::firm_handler(TMask_field& f, KEY key)
|
|
|
|
{
|
|
|
|
if (f.to_check(key))
|
|
|
|
{
|
|
|
|
const long firm = atol(f.get());
|
|
|
|
|
|
|
|
if (firm < 0)
|
1995-01-18 14:39:53 +00:00
|
|
|
return f.error_box("Codice ditta errato");
|
1994-12-07 11:08:53 +00:00
|
|
|
else
|
|
|
|
if (firm == 0)
|
|
|
|
return f.error_box("La ditta e' obbligatoria");
|
|
|
|
else
|
|
|
|
if (!prefhndl->exist(firm))
|
1995-01-18 14:39:53 +00:00
|
|
|
return f.error_box("Gli archivi della ditta %ld non sono stati ancora generati", firm);
|
1994-12-07 11:08:53 +00:00
|
|
|
else
|
1995-01-18 14:39:53 +00:00
|
|
|
{
|
|
|
|
if (main_app().get_firm() != firm)
|
|
|
|
main_app().set_firm(firm);
|
|
|
|
|
|
|
|
TMask_field& r = f.mask().field(F_REG);
|
|
|
|
r.set_dirty();
|
|
|
|
r.on_key(K_TAB);
|
|
|
|
}
|
1994-12-07 11:08:53 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRipristina_stampa::do_restore(long firm, const char * regist,
|
1995-01-16 15:08:33 +00:00
|
|
|
int year, int month, int day,
|
1994-12-07 11:08:53 +00:00
|
|
|
bool giornale)
|
|
|
|
{
|
|
|
|
bool ok = TRUE;
|
|
|
|
CHECK(firm > 0, "Non posso ripristinare sui dati comuni");
|
1995-01-18 14:39:53 +00:00
|
|
|
CHECKS(regist && *regist && strlen(regist) <= 3, "Registro errato ", regist);
|
|
|
|
CHECKD(month > 0 && month < 13, "Mese errato ", month);
|
1994-12-07 11:08:53 +00:00
|
|
|
set_firm(firm);
|
|
|
|
|
|
|
|
const char * const fieldname = giornale ? MOV_STAMPATO : MOV_REGST;
|
|
|
|
TRelation rel(LF_MOV);
|
|
|
|
TLocalisamfile & mov = rel.lfile();
|
|
|
|
TTable reg("REG");
|
1995-01-18 14:39:53 +00:00
|
|
|
TString16 s; s.format("%04d%s", year, regist);
|
1994-12-07 11:08:53 +00:00
|
|
|
|
|
|
|
reg.zero();
|
|
|
|
reg.put("CODTAB", s);
|
1995-01-19 13:58:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
TDate inizio_anno(1, 1, year);
|
1994-12-07 11:08:53 +00:00
|
|
|
if (reg.read(_isequal, _lock) == NOERR)
|
|
|
|
{
|
|
|
|
TDate dlast(reg.get_date("D3"));
|
|
|
|
|
|
|
|
if (giornale)
|
|
|
|
{
|
|
|
|
TTable esc("ESC");
|
|
|
|
esc.zero();
|
1995-01-18 14:39:53 +00:00
|
|
|
esc.put("CODTAB", format("%04d", year));
|
1994-12-07 11:08:53 +00:00
|
|
|
if (esc.read() != NOERR)
|
|
|
|
{
|
|
|
|
set_firm(_default_firm);
|
|
|
|
return error_box("Esercizio %s assente", year);
|
|
|
|
}
|
|
|
|
|
|
|
|
TDate wd(esc.get_date("D0"));
|
1995-01-19 13:58:07 +00:00
|
|
|
inizio_anno = wd;
|
|
|
|
|
|
|
|
// Determina il corretto anno solare dell'esercizio: se il giorno di inizio esercizio
|
|
|
|
// e successivo alla data di ripristino allora mi trovo nell'anno solare successivo
|
1995-01-16 15:08:33 +00:00
|
|
|
year = wd.year();
|
1995-01-19 13:58:07 +00:00
|
|
|
if (wd.month() > month || (wd.month() == month && wd.day() > day))
|
1995-01-16 15:08:33 +00:00
|
|
|
year++;
|
1995-01-19 13:58:07 +00:00
|
|
|
}
|
|
|
|
|
1995-01-18 14:39:53 +00:00
|
|
|
const int ld = TDate::last_day(month, year);
|
|
|
|
if (day > ld) day = ld;
|
1995-01-16 15:08:33 +00:00
|
|
|
TDate d(day, month, year);
|
1994-12-07 11:08:53 +00:00
|
|
|
|
|
|
|
TRectype from(mov.curr()); from.zero();
|
|
|
|
TRectype to(from);
|
|
|
|
TString16 filter;
|
|
|
|
|
|
|
|
from.put(MOV_DATAREG, d);
|
|
|
|
to.put(MOV_DATAREG, dlast);
|
|
|
|
if (!giornale)
|
|
|
|
filter.format("%s==\"%s\"", MOV_REG, regist);
|
|
|
|
|
|
|
|
TCursor cursor(&rel, filter, 2, &from, &to);
|
|
|
|
long last_num = 0L;
|
|
|
|
|
|
|
|
cursor = 0L;
|
|
|
|
const long nitems = cursor.items();
|
|
|
|
|
|
|
|
TProgind p(nitems ? nitems : 1, format("Ripristino stampa del registro %s", (const char *) regist) , TRUE, TRUE, 70);
|
|
|
|
|
|
|
|
if (giornale)
|
|
|
|
{
|
|
|
|
last_num = mov.get_long(MOV_NUMGIO);
|
|
|
|
if (last_num > 0) last_num--;
|
|
|
|
CHECK(last_num >= 0, "Ultimo numero stampato impossibile");
|
|
|
|
}
|
|
|
|
for (; ok && cursor.pos() < cursor.items(); ++cursor)
|
|
|
|
{
|
|
|
|
p.addstatus(1);
|
|
|
|
mov.read(_isequal, _lock);
|
1995-01-19 13:58:07 +00:00
|
|
|
mov.zero(fieldname); // Azzera flag STAMPATO o REGST
|
1994-12-07 11:08:53 +00:00
|
|
|
ok = (mov.rewrite() == NOERR);
|
|
|
|
if (!ok)
|
1995-01-18 14:39:53 +00:00
|
|
|
error_box("Errore nell'aggiornamento del movimento %ld.\n Errore n. %d",
|
1994-12-07 11:08:53 +00:00
|
|
|
mov.get_long(MOV_NUMREG), mov.status());
|
|
|
|
}
|
1995-01-19 13:58:07 +00:00
|
|
|
|
1994-12-07 11:08:53 +00:00
|
|
|
--d;
|
1995-01-19 13:58:07 +00:00
|
|
|
if (d > inizio_anno) // Aggiorna data ultima stampa
|
|
|
|
reg.put("D3", d);
|
|
|
|
else
|
|
|
|
reg.zero("D3");
|
|
|
|
|
1994-12-07 11:08:53 +00:00
|
|
|
ok = (reg.rewrite() == NOERR);
|
|
|
|
if (!ok)
|
1995-01-18 14:39:53 +00:00
|
|
|
error_box("Errore nell'aggiornamento del registro %s.\n Errore n. %d",
|
1994-12-07 11:08:53 +00:00
|
|
|
(const char * ) regist, mov.status());
|
|
|
|
}
|
|
|
|
else
|
1995-01-18 14:39:53 +00:00
|
|
|
ok = error_box("Impossibile leggere il registro %s anno %s", (const char *) regist, (const char *) year);
|
1994-12-07 11:08:53 +00:00
|
|
|
|
|
|
|
set_firm(_default_firm);
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRipristina_stampa::create()
|
|
|
|
{
|
|
|
|
TApplication::create();
|
|
|
|
_msk = new TMask("cg5400a") ;
|
|
|
|
_msk->set_handler(F_FIRM, firm_handler);
|
|
|
|
_default_firm = get_firm();
|
|
|
|
dispatch_e_menu(BAR_ITEM(1));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRipristina_stampa::destroy()
|
|
|
|
{
|
|
|
|
if (_msk != NULL) delete _msk;
|
|
|
|
return TApplication::destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TRipristina_stampa::menu(MENU_TAG)
|
|
|
|
{
|
|
|
|
while (_msk->run() == K_ENTER)
|
|
|
|
{
|
|
|
|
const long firm = _msk->get_long(F_FIRM);
|
1995-01-16 15:08:33 +00:00
|
|
|
const TString16 reg = _msk->get(F_REG);
|
1994-12-07 11:08:53 +00:00
|
|
|
const bool giornale = _msk->get_int(F_TIPO) == 5;
|
1995-01-16 15:08:33 +00:00
|
|
|
const int year = _msk->get_int(giornale ? F_ESER : F_YEAR);
|
|
|
|
const int month = _msk->get_int(F_MESE);
|
1995-01-18 14:39:53 +00:00
|
|
|
int day = giornale ? _msk->get_int(F_DAY) : 1;
|
|
|
|
if (day < 1) day = 1;
|
1994-12-07 11:08:53 +00:00
|
|
|
|
|
|
|
if (prefhndl->exist(firm))
|
|
|
|
{
|
1995-01-18 14:39:53 +00:00
|
|
|
TString256 mess("Attenzione sara' ripristinata la stampa del registro ");
|
|
|
|
mess << reg << "\ndell'" << (giornale ? "esercizio " : "anno ") << year
|
|
|
|
<< " della ditta " << firm << " dal " << day << '-' << month << '-' << year;
|
1995-01-16 15:08:33 +00:00
|
|
|
|
1994-12-07 11:08:53 +00:00
|
|
|
if (yesno_box((const char *) mess))
|
|
|
|
{
|
1995-01-16 15:08:33 +00:00
|
|
|
mess << "\nSi desidera veramente continuare";
|
1994-12-07 11:08:53 +00:00
|
|
|
if (yesno_box((const char *) mess))
|
1995-01-16 15:08:33 +00:00
|
|
|
do_restore(firm, reg, year, month, day, giornale);
|
1994-12-07 11:08:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else error_box("Gli archivi della ditta %d non sono stati ancora generati",firm);
|
|
|
|
_msk->reset();
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cg5400(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TRipristina_stampa a ;
|
|
|
|
a.run(argc, argv, "Ripristino stampa registri");
|
|
|
|
return 0;
|
|
|
|
}
|