272 lines
6.7 KiB
C++
Executable File
272 lines
6.7 KiB
C++
Executable File
#include "cg4501.h"
|
|
#include "cg4500a.h"
|
|
#include "cglib01.h"
|
|
|
|
#include <recarray.h>
|
|
#include <relation.h>
|
|
#include <tabutil.h>
|
|
|
|
|
|
class TAp_eser : public TSkeleton_application
|
|
{
|
|
int _anno, _newanno;
|
|
TDate _dataini, _datafin, _datainp, _datafip;
|
|
TString _conserva;
|
|
TEsercizi_contabili * _esc;
|
|
|
|
protected:
|
|
|
|
bool check_esercizio(const int cod, TDate s1, TDate f1);
|
|
static bool mask_dataini (TMask_field&, KEY);
|
|
static bool mask_newanno (TMask_field&, KEY);
|
|
|
|
public:
|
|
virtual bool create();
|
|
virtual bool destroy();
|
|
virtual void main_loop();
|
|
|
|
bool set();
|
|
bool apertura_es();
|
|
};
|
|
|
|
static TAp_eser& app() { return (TAp_eser&) main_app(); }
|
|
|
|
bool TAp_eser::mask_newanno (TMask_field& f, KEY k)
|
|
{
|
|
if (k == K_ENTER)
|
|
{
|
|
const int newanno = f.mask().get_int(F_NUOVOANNO);
|
|
|
|
if (app()._esc->exist(newanno))
|
|
return f.warning_box (FR("Il codice %04d e' gia' presente nella tabella degli esercizi!"),
|
|
newanno);
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TAp_eser::mask_dataini (TMask_field& f, KEY k)
|
|
{
|
|
if ( (k == K_ENTER) && f.to_check(k) )
|
|
{
|
|
TDate data(f.mask().get(F_DATAINI));
|
|
TDate fine(f.mask().get(F_DATAFINC));
|
|
|
|
if ( data <= fine )
|
|
return f.warning_box (TR("La data di inizio del nuovo esercizio deve essere superiore alla data di fine esercizio precedente"));
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TAp_eser::create()
|
|
{
|
|
open_files(LF_TAB, 0);
|
|
enable_menu_item(M_FILE_NEW, FALSE);
|
|
_esc = new TEsercizi_contabili;
|
|
|
|
return TSkeleton_application::create();
|
|
}
|
|
|
|
bool TAp_eser::destroy()
|
|
{
|
|
delete _esc;
|
|
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
void TAp_eser::main_loop()
|
|
{
|
|
int anno = _esc->last();
|
|
|
|
if (anno > 0)
|
|
{
|
|
TMask msk ("cg4500a");
|
|
msk.set_handler (F_NUOVOANNO, mask_newanno);
|
|
msk.set_handler (F_DATAINI, mask_dataini);
|
|
TDate inizio = _esc->esercizio(anno).inizio(); //data inizio es. in corso
|
|
TDate fine = _esc->esercizio(anno).fine(); //data fine es. in corso
|
|
|
|
msk.set(F_ANNO, anno);
|
|
msk.set(F_DATAINIC, inizio.string());
|
|
msk.set(F_DATAFINC, fine.string());
|
|
|
|
anno++;
|
|
inizio.addyear();
|
|
fine.addyear();
|
|
|
|
msk.set(F_NUOVOANNO, anno);
|
|
msk.set(F_DATAINI, inizio.string());
|
|
msk.set(F_DATAFIN, fine.string());
|
|
if (msk.run() == K_ENTER)
|
|
{
|
|
_anno = msk.get_int(F_ANNO);
|
|
_datainp = msk.get(F_DATAINIC);
|
|
_datafip = msk.get(F_DATAFINC);
|
|
_newanno = msk.get_int(F_NUOVOANNO); //nuovo anno esercizio
|
|
_dataini = msk.get(F_DATAINI);
|
|
_datafin = msk.get(F_DATAFIN);
|
|
|
|
apertura_es();
|
|
}
|
|
}
|
|
else
|
|
error_box(TR("Non e' ancora stato aperto alcun esercizio!"));
|
|
}
|
|
|
|
bool TAp_eser::apertura_es()
|
|
{
|
|
TString8 anno;
|
|
TString8 annonew;
|
|
TDate data;
|
|
TRelation reg("REG");
|
|
TRectype & tabreg = reg.curr();
|
|
bool ok = FALSE;
|
|
|
|
//viene aggiornata la tabella dei registri. Se esisteva gia' un record relativo al nuovo esercizio, viene cancellato.
|
|
//In ogni caso ne viene creato uno nuovo relativo al nuovo esercizio.
|
|
anno.format ("%04d", _datafip.year());
|
|
annonew.format("%04d", _datafin.year());
|
|
|
|
tabreg.put ("CODTAB", annonew);
|
|
|
|
TCursor cur(®, "", 1, &tabreg, &tabreg);
|
|
TRecnotype items = cur.items();
|
|
|
|
cur.freeze();
|
|
for (cur = 0L; cur.pos() < items; ++cur)
|
|
if (tabreg.get_int("I0") == 5)
|
|
reg.remove();
|
|
|
|
cur.freeze(FALSE);
|
|
tabreg.zero();
|
|
tabreg.put ("CODTAB", anno);
|
|
cur.setregion(tabreg, tabreg);
|
|
|
|
items = cur.items();
|
|
|
|
cur.freeze();
|
|
for (cur = 0L; cur.pos() < items; ++cur)
|
|
{
|
|
if (tabreg.get_int("I0") == 5)
|
|
{
|
|
TString16 cod(tabreg.get("CODTAB"));
|
|
|
|
ok = TRUE;
|
|
annonew.format("%04d", _datafin.year());
|
|
cod.overwrite(annonew);
|
|
tabreg.put("CODTAB", cod);
|
|
tabreg.zero("I1");
|
|
tabreg.zero("I6");
|
|
tabreg.zero("S1");
|
|
tabreg.put("D0", data);
|
|
tabreg.put("D2", data);
|
|
tabreg.put("D3", data);
|
|
tabreg.zero("R1");
|
|
tabreg.zero("R2");
|
|
|
|
reg.write();
|
|
}
|
|
}
|
|
// se tutto ok viene aggiornata la tabella degli esercizi
|
|
if (check_esercizio(_newanno, _dataini, _datafin))
|
|
{
|
|
TTable tabesc("ESC");
|
|
tabesc.zero();
|
|
annonew.format("%04d", _newanno);
|
|
tabesc.put ("CODTAB", annonew);
|
|
tabesc.put ("D0", _dataini);
|
|
tabesc.put ("D1", _datafin);
|
|
tabesc.put ("S1", _conserva);
|
|
tabesc.write();
|
|
message_box(TR("Apertura nuovo esercizio completata"));
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
bool TAp_eser::check_esercizio(const int cod_es, 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;
|
|
|
|
bool basta1 = FALSE, basta2 = FALSE;
|
|
|
|
for (int cod = _esc->first(); cod > 0; cod = _esc->next(cod))
|
|
{
|
|
if (cod != cod_es)
|
|
{
|
|
const TEsercizio & e = (*_esc)[cod];
|
|
const TDate s2 = e.inizio();
|
|
const TDate f2 = e.fine();
|
|
|
|
// check sovrapposizione
|
|
if (s1 <= f2 && s2 <= f1)
|
|
err |= 0x01;
|
|
else
|
|
{
|
|
const TDate s1d(s1 - 1L);
|
|
const TDate s2d(s2 - 1L);
|
|
|
|
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;
|
|
}
|
|
|
|
int cg4500 (int argc, char* argv[])
|
|
{
|
|
if (toupper(*argv[2]) == 'I')
|
|
{
|
|
TAp_iva a;
|
|
a.run(argc, argv, TR("Apertura nuovo esercizio IVA"));
|
|
}
|
|
else
|
|
{
|
|
TAp_eser a;
|
|
a.run(argc, argv, TR("Apertura nuovo esercizio"));
|
|
}
|
|
return 0;
|
|
}
|
|
|