Gestione tabelle contabili + tabella esercizi (finito)
git-svn-id: svn://10.65.10.50/trunk@2662 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
parent
0f6fba3f4c
commit
703f1302d3
314
cg/cg0600.cpp
314
cg/cg0600.cpp
@ -1,94 +1,220 @@
|
||||
// --------------------------------------------------------------
|
||||
// fv: cg0 -5 <tab>: gestione maschere contabilita'
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include <tabapp.h>
|
||||
#include <saldi.h>
|
||||
#include "../ba/batbesc.h"
|
||||
#include <defmask.h>
|
||||
|
||||
class CGTab_application : public Tab_application
|
||||
{
|
||||
TLocalisamfile* _saldi;
|
||||
|
||||
protected:
|
||||
|
||||
// virtual bool protected_record(TRectype& rec);
|
||||
// virtual void init_query_mode(TMask& m);
|
||||
virtual void init_modify_mode(TMask& m);
|
||||
|
||||
virtual bool user_create();
|
||||
virtual bool user_destroy();
|
||||
|
||||
public:
|
||||
|
||||
// ------------- handlers tabella esercizi ----
|
||||
static bool escdate_handler(TMask_field&, KEY);
|
||||
// --------------------------------------------
|
||||
|
||||
CGTab_application& app() { return (CGTab_application&)main_app(); }
|
||||
|
||||
CGTab_application() : Tab_application() {}
|
||||
virtual ~CGTab_application() {}
|
||||
};
|
||||
|
||||
|
||||
// virtual bool protected_record(TRectype& rec);
|
||||
// virtual void init_query_mode(TMask& m);
|
||||
void CGTab_application::init_modify_mode(TMask& m)
|
||||
{
|
||||
if (get_tabname() == "ESC")
|
||||
{
|
||||
// cerca saldo con questo esercizio
|
||||
TString cod(m.get(F_ANNO));
|
||||
_saldi->zero();
|
||||
_saldi->put(SLD_ANNOES, cod);
|
||||
// se ce n'e' uno non si puo' cancellare
|
||||
if (_saldi->read() == NOERR)
|
||||
m.disable(DLG_DELREC);
|
||||
else m.enable(DLG_DELREC);
|
||||
}
|
||||
}
|
||||
|
||||
bool CGTab_application::user_create()
|
||||
{
|
||||
Tab_application::user_create();
|
||||
|
||||
if (get_tabname() == "ESC")
|
||||
{
|
||||
_saldi = new TLocalisamfile(LF_SALDI);
|
||||
// set handlers
|
||||
TMask& m = *get_mask();
|
||||
m.set_handler(F_DATAINI, escdate_handler);
|
||||
m.set_handler(F_DATAFIN, escdate_handler);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CGTab_application::user_destroy()
|
||||
{
|
||||
if (get_tabname() == "ESC")
|
||||
delete _saldi;
|
||||
|
||||
return Tab_application::user_destroy();
|
||||
}
|
||||
|
||||
|
||||
// -- specifiche per tabella esercizi --------------------------
|
||||
bool CGTab_application::escdate_handler(TMask_field&, KEY)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
// -------------------------------------------------------------
|
||||
|
||||
int cg0600(int argc, char* argv[])
|
||||
{
|
||||
CGTab_application a;
|
||||
|
||||
a.run(argc, argv, "Gestione tabelle contabili");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --------------------------------------------------------------
|
||||
// fv: cg0 -5 <tab>: gestione maschere contabilita'
|
||||
// --------------------------------------------------------------
|
||||
|
||||
#include <tabapp.h>
|
||||
#include <saldi.h>
|
||||
#include <defmask.h>
|
||||
#include <sheet.h>
|
||||
#include "../ba/batbesc.h"
|
||||
#include "cglib.h"
|
||||
|
||||
class CGTab_application : public Tab_application
|
||||
{
|
||||
// ------------- specifiche tabella esercizi ----
|
||||
TLocalisamfile* _saldi;
|
||||
static bool dataini_handler(TMask_field& f, KEY k);
|
||||
static bool checkbut_handler(TMask_field& f, KEY k);
|
||||
void check_sheet();
|
||||
bool check_esercizio(TString& cod, TDate s1, TDate f1);
|
||||
// --------------------------------------------
|
||||
|
||||
protected:
|
||||
|
||||
virtual void init_modify_mode(TMask& m);
|
||||
|
||||
virtual bool user_create();
|
||||
virtual bool user_destroy();
|
||||
|
||||
public:
|
||||
|
||||
static CGTab_application& app() { return (CGTab_application&)main_app(); }
|
||||
|
||||
CGTab_application() : Tab_application() {}
|
||||
virtual ~CGTab_application() {}
|
||||
};
|
||||
|
||||
void CGTab_application::init_modify_mode(TMask& m)
|
||||
{
|
||||
if (get_tabname() == "ESC")
|
||||
{
|
||||
// cerca saldo con questo esercizio
|
||||
TString cod(m.get(F_ANNO));
|
||||
_saldi->zero();
|
||||
_saldi->put(SLD_ANNOES, cod);
|
||||
// se ce n'e' uno non si puo' cancellare
|
||||
if (_saldi->read() == NOERR)
|
||||
m.disable(DLG_DELREC);
|
||||
else m.enable(DLG_DELREC);
|
||||
}
|
||||
}
|
||||
|
||||
bool CGTab_application::user_create()
|
||||
{
|
||||
Tab_application::user_create();
|
||||
|
||||
if (get_tabname() == "ESC")
|
||||
{
|
||||
_saldi = new TLocalisamfile(LF_SALDI);
|
||||
get_mask()->set_handler(F_DATAINI, dataini_handler);
|
||||
get_mask()->set_handler(BUT_CHECK, checkbut_handler);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CGTab_application::user_destroy()
|
||||
{
|
||||
if (get_tabname() == "ESC")
|
||||
delete _saldi;
|
||||
|
||||
return Tab_application::user_destroy();
|
||||
}
|
||||
|
||||
|
||||
// - esercizi-specific --------------------------------------------------------
|
||||
|
||||
bool CGTab_application::dataini_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
if (k == K_ENTER && f.mask().is_running() && !f.mask().query_mode())
|
||||
{
|
||||
TString16 cod = f.mask().get(F_ANNO);
|
||||
TDate s1 = f.mask().get_date(F_DATAINI);
|
||||
TDate f1 = f.mask().get_date(F_DATAFIN);
|
||||
|
||||
return app().check_esercizio(cod, s1, f1);
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool CGTab_application::check_esercizio(TString& cod, TDate s1, TDate f1)
|
||||
{
|
||||
// -----------------------------------------------------------------------------------------
|
||||
// chiamata prima di registrare. Controlla:
|
||||
// - se non ci sono altri esercizi, ok;
|
||||
// - se ce ne sono altri:
|
||||
// 1) controllo non sovrapposizione date
|
||||
// 2) se ci sono es. con date inferiori, datainizio -1 deve essere = data fine altro es;
|
||||
// 3) se ci sono es. con date superiori, datafine +1 deve essere = data inizio altro
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
byte err = 0x00; bool ret = TRUE;
|
||||
TLocalisamfile& esc = get_relation()->lfile();
|
||||
|
||||
bool basta1 = FALSE, basta2 = FALSE;
|
||||
|
||||
for (esc.first(); !esc.eof(); esc.next())
|
||||
{
|
||||
if (esc.get("CODTAB") == cod)
|
||||
continue;
|
||||
|
||||
TDate s2 = esc.get_date("D0");
|
||||
TDate f2 = esc.get_date("D1");
|
||||
TDate s1d = s1; --s1d;
|
||||
TDate s2d = s2; --s2d;
|
||||
|
||||
// check sovrapposizione
|
||||
if (s1 <= f2 && s2 <= f1)
|
||||
err |= 0x01;
|
||||
else
|
||||
{
|
||||
if (!basta1 && f1 < s2 && f1 != s2d)
|
||||
err |= 0x02;
|
||||
if (f1 < s2 && f1 == s2d)
|
||||
{
|
||||
err &= ~0x02;
|
||||
basta1 = TRUE;
|
||||
}
|
||||
if (!basta2 && s1 > f2 && f2 != s1d)
|
||||
err |= 0x04;
|
||||
if (s1 > f2 && f2 == s1d)
|
||||
{
|
||||
err &= ~0x04;
|
||||
basta2 = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (err)
|
||||
{
|
||||
ret = FALSE;
|
||||
TString errstr(120);
|
||||
errstr << "Date esercizio errate: \n";
|
||||
// build error string
|
||||
if (err & 0x01)
|
||||
errstr << "\n - l'esercizio si sovrappone ad altro gia' esistente";
|
||||
if (err & 0x02)
|
||||
errstr << "\n - l'esercizio non e' contiguo ad esercizi successivi";
|
||||
if (err & 0x04)
|
||||
errstr << "\n - l'esercizio non e' contiguo ad esercizi precedenti";
|
||||
|
||||
if (!(err & 0x01))
|
||||
{
|
||||
errstr << "\nSi desidera registrare ugualmente?";
|
||||
ret = yesno_box(errstr);
|
||||
}
|
||||
else error_box(errstr);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void CGTab_application::check_sheet()
|
||||
{
|
||||
// crea 'nu bellu shit co'tutte le informazion e un messaggino
|
||||
// di error se ce n'e' bisogn
|
||||
TLocalisamfile& esc = get_relation()->lfile();
|
||||
TArray escarr(10);
|
||||
for (esc.first(); !esc.eof(); esc.next())
|
||||
escarr.add(new TEsercizio(esc.curr()));
|
||||
|
||||
escarr.sort();
|
||||
|
||||
TArray_sheet as(-1,-1,70,20,"Esercizi contabili",
|
||||
"Codice|Inizio@10|Fine@10|Scarico@10|Chiusura@10|Note@20",
|
||||
0x18);
|
||||
|
||||
TDate s1;
|
||||
|
||||
for (int i = 0; i < escarr.items(); i++)
|
||||
{
|
||||
// sovrapposti non possono essere, perche' non si possono
|
||||
// registrare; possono solo esserci discontinuita'
|
||||
TEsercizio& e = (TEsercizio&)escarr[i];
|
||||
TToken_string* tt = new TToken_string(80);
|
||||
tt->add(e.codice());
|
||||
tt->add(e.inizio().string());
|
||||
tt->add(e.fine().string());
|
||||
tt->add(e.scarico().string());
|
||||
tt->add(e.chiusura().string());
|
||||
|
||||
if (i > 0 && e.inizio() != ++s1)
|
||||
tt->add("*** non contiguo ***");
|
||||
else tt->add("ok");
|
||||
|
||||
s1 = e.fine();
|
||||
|
||||
as.add(tt);
|
||||
}
|
||||
|
||||
as.run();
|
||||
}
|
||||
|
||||
bool CGTab_application::checkbut_handler(TMask_field& f, KEY k)
|
||||
{
|
||||
if (k == K_SPACE && f.mask().is_running())
|
||||
app().check_sheet();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
int cg0600(int argc, char* argv[])
|
||||
{
|
||||
CGTab_application a;
|
||||
|
||||
a.run(argc, argv, "Gestione tabelle contabili");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
11
cg/cglib.h
11
cg/cglib.h
@ -162,16 +162,17 @@ public:
|
||||
class TEsercizio : public TSortable
|
||||
{
|
||||
int _codice;
|
||||
TDate _inizio, _fine, _scarico;
|
||||
TDate _inizio, _fine, _scarico, _chiusura;
|
||||
|
||||
protected: // TSortable
|
||||
int compare(const TSortable& s) const;
|
||||
|
||||
public:
|
||||
int codice() const { return _codice; }
|
||||
const TDate& inizio() const { return _inizio; }
|
||||
const TDate& fine() const { return _fine; }
|
||||
const TDate& scarico() const { return _scarico; }
|
||||
int codice() const { return _codice; }
|
||||
const TDate& inizio() const { return _inizio; }
|
||||
const TDate& fine() const { return _fine; }
|
||||
const TDate& scarico() const { return _scarico; }
|
||||
const TDate& chiusura() const { return _chiusura; }
|
||||
|
||||
TEsercizio(const TRectype& rec);
|
||||
virtual ~TEsercizio() {}
|
||||
|
@ -264,10 +264,11 @@ void TSaldo_agg::registra()
|
||||
|
||||
TEsercizio::TEsercizio(const TRectype& rec)
|
||||
{
|
||||
_codice = rec.get_int("CODTAB");
|
||||
_inizio = rec.get("D0");
|
||||
_fine = rec.get("D1");
|
||||
_scarico = rec.get("D2");
|
||||
_codice = rec.get_int("CODTAB");
|
||||
_inizio = rec.get("D0");
|
||||
_fine = rec.get("D1");
|
||||
_scarico = rec.get("D2");
|
||||
_chiusura = rec.get("D3");
|
||||
}
|
||||
|
||||
int TEsercizio::compare(const TSortable& s) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user