campo-sirio/cg/cg0600.cpp
alex 981678913a Patch level : 2.0.369
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Riportata la versione P@rtners  2.0 patch 349


git-svn-id: svn://10.65.10.50/trunk@10709 c028cbd2-c16b-5b4b-a496-9718f37d4682
2002-12-20 17:08:30 +00:00

226 lines
6.3 KiB
C++
Executable File

// --------------------------------------------------------------
// fv: cg0 -5 <tab>: gestione maschere contabilita'
// --------------------------------------------------------------
#include <tabapp.h>
#include <saldi.h>
#include <defmask.h>
#include <sheet.h>
#include "../ba/batbesc.h"
#include "cglib01.h"
class CGTTable_application : public TTable_application
{
// ------------- specifiche tabella esercizi ----
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 bool protected_record(TRectype & rec);
virtual bool user_create();
virtual bool user_destroy();
public:
// @cmember Disabilita la verifica del modulo : essendo una anagrafica, va sempre abilitata
virtual bool check_autorization() const
{return FALSE;}
static CGTTable_application& app() { return (CGTTable_application&)main_app(); }
CGTTable_application() : TTable_application() {}
virtual ~CGTTable_application() {}
};
bool CGTTable_application::protected_record(TRectype &rec)
{
if (get_tabname() == "ESC")
{
// cerca saldo con questo esercizio
const TString16 cod(rec.get("CODTAB"));
TLocalisamfile saldi(LF_SALDI);
saldi.put(SLD_ANNOES, cod);
// se ce n'e' uno non si puo' cancellare
if (saldi.read(_isgteq) == NOERR && cod == rec.get("CODTAB"))
return TRUE;
}
return TTable_application::protected_record(rec);
}
bool CGTTable_application::user_create()
{
bool ok = TTable_application::user_create();
if (ok)
{
if (get_tabname() == "ESC")
{
get_mask()->set_handler(F_DATAINI, dataini_handler);
get_mask()->set_handler(BUT_CHECK, checkbut_handler);
}
}
return ok;
}
bool CGTTable_application::user_destroy()
{
return TTable_application::user_destroy();
}
// - esercizi-specific --------------------------------------------------------
bool CGTTable_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 CGTTable_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 << TR("Date esercizio errate: \n");
// build error string
if (err & 0x01)
errstr << TR("\n - l'esercizio si sovrappone ad altro gia' esistente");
if (err & 0x02)
errstr << TR("\n - l'esercizio non e' contiguo ad esercizi successivi");
if (err & 0x04)
errstr << TR("\n - l'esercizio non e' contiguo ad esercizi precedenti");
if (!(err & 0x01))
{
errstr << TR("\nSi desidera registrare ugualmente?");
ret = yesno_box(errstr);
}
else error_box(errstr);
}
return ret;
}
void CGTTable_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,TR("Esercizi contabili"),
FR("Codice|Inizio@10|Fine@10|Scarico@10|Chiusura@10|Note@20"),
0x10);
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)
{
TString nc; nc << "***" << TR("non contiguo") << "***";
tt->add(nc);
}
else tt->add("");
s1 = e.fine();
as.add(tt);
}
as.run();
}
bool CGTTable_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[])
{
CGTTable_application a;
a.run(argc, argv, TR("Gestione tabelle contabili"));
return 0;
}