campo-sirio/cg/cg0100.cpp

332 lines
8.6 KiB
C++
Executable File

#include <relapp.h>
#include <lffiles.h>
#include <pconti.h>
#include "cg0.h"
#include "cg0100.h"
#define ATTIVITA 1
#define PASSIVITA 2
#define COSTI 3
#define RICAVI 4
#define ORDINE 5
class CG0100_application : public TRelation_application
{
TMask* _msk;
TRelation *_rel;
TLocalisamfile* _saldi;
TLocalisamfile* _tabcom;
bool user_create();
bool user_destroy();
virtual TMask* get_mask(int mode) {return _msk;}
virtual bool changing_mask(int mode) {return FALSE;}
virtual bool protected_record(TRectype &rec);
virtual void init_query_mode(TMask& m);
virtual void init_insert_mode(TMask& m);
virtual void init_modify_mode(TMask& m) {init_insert_mode(m);}
public:
virtual TRelation* get_relation() const {return _rel;}
CG0100_application() {}
};
// Controlla se puo' essere effettuata la cancellazione di un conto
bool CG0100_application::protected_record(TRectype &rec)
{
TMask* m = get_mask(MODE_MOD);
TLocalisamfile& pconti = *_rel->lfile();
const int gruppo = atoi(m->get(FLD_CM1_GRUPPO));
const int conto = atoi(m->get(FLD_CM1_CONTO));
const long sottoc = atol(m->get(FLD_CM1_SOTTOCONTO));
// Se e' un sottoconto posso cancellarlo se non esistono saldi
if ((gruppo != 0) && (conto != 0) && (sottoc != 0))
{
_saldi->zero();
_saldi->put(PCN_GRUPPO, gruppo);
_saldi->put(PCN_CONTO, conto);
_saldi->put(PCN_SOTTOCONTO, sottoc);
_saldi->read(_isgteq);
return _saldi->good() && gruppo ==_saldi->get_int(PCN_GRUPPO) &&
conto ==_saldi->get_int(PCN_CONTO) &&
sottoc ==_saldi->get_long(PCN_SOTTOCONTO);
}
pconti.zero() ;
pconti.put(PCN_GRUPPO, gruppo);
// Se e' un conto controllo se ha dei sottoconti
if (conto != 0)
pconti.put(PCN_CONTO, conto);
TRectype rec1(pconti.curr());
pconti.setkey(1) ;
pconti.read();
pconti.next();
return pconti.good() && (pconti.curr() == rec1);
//
// if (pconti.bad()) return FALSE;
// const int ngruppo = pconti.get_int(PCN_GRUPPO);
// const int nconto = pconti.get_int(PCN_CONTO);
// Cercavo di cancellare un gruppo e ho trovato un conto dello stesso gruppo
// if (conto == 0 && gruppo == ngruppo)
// return TRUE;
// Cercavo di cancellare un conto e ho trovato un sottoconto
// dello stesso gruppo e conto
// if (gruppo == ngruppo && conto == nconto)
// return TRUE;
// return FALSE;
}
void CG0100_application::init_query_mode(TMask& m)
{
m.send_key(K_SHIFT + K_CTRL + 's', -1);
m.send_key(K_SHIFT + K_CTRL + 's', -2);
m.send_key(K_SHIFT + K_CTRL + 's', -3);
}
HIDDEN bool tmcf_handler(TMask_field& f, KEY key)
{
if (f.active() && key == K_SPACE)
{
TMask& m = f.mask();
const int conto = atoi(m.get(FLD_CM1_CONTO));
const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO));
const bool enable_sezsaldi = (sottoc != 0) || (sottoc == 0 && conto != 0 && m.get(FLD_CM1_TMCF).not_empty());
m.show(FLD_CM2_SEZSALDI, enable_sezsaldi);
}
return TRUE;
}
HIDDEN bool ivd_enable = TRUE;
HIDDEN bool indbil_handler(TMask_field& f, KEY key)
{
if (f.active() && key == K_SPACE)
{
TMask& m = f.mask();
const int indbil = atoi(f.get());
if (indbil == ORDINE)
{
m.send_key(K_SHIFT + K_CTRL + 'h', -4);
m.show(FLD_CM1_SEZIVDH);
m.enable(FLD_CM1_SEZIVDH);
}
else
{
m.show(FLD_CM1_SEZIVD);
m.hide(FLD_CM1_SEZIVDH);
m.enable(FLD_CM1_SEZIVD, ivd_enable);
m.show(FLD_CM1_LETTIVD, ivd_enable);
m.show(FLD_CM1_NUMRIVD, ivd_enable);
m.show(FLD_CM1_NUMIVD, ivd_enable);
m.show(FLD_CM1_LETTIVDH, !ivd_enable);
m.show(FLD_CM1_NUMRIVDH, !ivd_enable);
m.show(FLD_CM1_NUMIVDH, !ivd_enable);
}
}
return TRUE;
}
void CG0100_application::init_insert_mode(TMask& m)
{
const int gruppo = atoi(m.get(FLD_CM1_GRUPPO));
const int conto = atoi(m.get(FLD_CM1_CONTO));
const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO));
if (conto == 0 && sottoc == 0)
m.send_key(K_SHIFT + K_CTRL + 'h', -1);
else
if (sottoc == 0)
m.send_key(K_SHIFT + K_CTRL + 'h', -2);
else
m.send_key(K_SHIFT + K_CTRL + 'h', -3);
TLocalisamfile& pconti = *_rel->lfile();
TString s(15), s1(1), s2(1), s3(8), s4(2);
pconti.setkey(1) ;
int indbil = 0;
if (sottoc != 0)
{
pconti.zero();
pconti.put(PCN_GRUPPO, gruppo);
pconti.put(PCN_CONTO, conto);
pconti.read();
if (pconti.good())
{
s = pconti.get(PCN_CODCBL);
s1 = pconti.get(PCN_SEZIVD);
s2 = pconti.get(PCN_LETTIVD);
s3 = pconti.get(PCN_NUMRIVD);
s4 = pconti.get(PCN_NUMIVD);
indbil = pconti.get_int(PCN_INDBIL);
m.show(FLD_CM1_RICSER, indbil == PASSIVITA || indbil == RICAVI);
}
if (indbil == ORDINE)
{
m.send_key(K_SHIFT + K_CTRL + 'h', -4);
m.show(FLD_CM1_SEZIVDH);
m.disable(FLD_CM1_SEZIVDH);
m.set(FLD_CM1_SEZIVDH, s1);
ivd_enable = s1.empty();
}
else
{
m.show(FLD_CM1_SEZIVD);
m.hide(FLD_CM1_SEZIVDH);
ivd_enable = s1.empty() && s2.empty() && s3.empty() && s4.empty();
}
}
else ivd_enable = TRUE;
if (conto != 0)
{
if (indbil != ORDINE)
{
m.enable(FLD_CM1_SEZIVD, ivd_enable);
m.show(FLD_CM1_LETTIVD, ivd_enable);
m.show(FLD_CM1_NUMRIVD, ivd_enable);
m.show(FLD_CM1_NUMIVD, ivd_enable);
m.show(FLD_CM1_LETTIVDH, !ivd_enable);
m.show(FLD_CM1_NUMRIVDH, !ivd_enable);
m.show(FLD_CM1_NUMIVDH, !ivd_enable);
if (!ivd_enable)
{
m.set(FLD_CM1_SEZIVD, s1);
m.set(FLD_CM1_LETTIVDH, s2);
m.set(FLD_CM1_NUMRIVDH, s3);
m.set(FLD_CM1_NUMIVDH, s4);
}
}
pconti.zero();
pconti.put(PCN_GRUPPO, gruppo);
pconti.read();
if (pconti.good())
if (s.empty()) s = pconti.get(PCN_CODCBL);
}
if (s.not_empty())
{
m.set(FLD_CM1_CODANALISIH, s);
m.show(FLD_CM1_CODANALISIH);
m.hide(FLD_CM1_CODTABANALISI);
}
else
{
m.show(FLD_CM1_CODTABANALISI);
m.hide(FLD_CM1_CODANALISIH);
}
const bool enable_sezsaldi = (sottoc != 0) || (sottoc == 0 && conto != 0 && m.get(FLD_CM1_TMCF).not_empty());
m.show(FLD_CM2_SEZSALDI, enable_sezsaldi);
}
HIDDEN bool gruppo_handler(TMask_field& f, KEY key)
{
if (key == K_ENTER)
{
const TMask& m = f.mask();
const int gruppo = atoi(m.get(FLD_CM1_GRUPPO));
const int conto = atoi(m.get(FLD_CM1_CONTO));
const long sottoc = atol(m.get(FLD_CM1_SOTTOCONTO));
const TFixed_string descrizione(m.get(FLD_CM1_DESC));
CG0100_application* app = (CG0100_application*) MainApp();
TLocalisamfile& pconti = *app->get_relation()->lfile();
if (gruppo == 0 && conto == 0 && sottoc == 0 && descrizione.not_empty())
return TRUE;
if (gruppo == 0)
{
if (conto != 0 || sottoc != 0)
return f.warning_box("Codice conto impossibile!");
else
return f.error_box("E' obbligatorio l'inserimento del gruppo");
}
if (conto > 0 && sottoc == 0) // conto => ricerca gruppo
{
pconti.zero() ;
pconti.put(PCN_GRUPPO, gruppo) ;
pconti.setkey(1) ;
pconti.read(_isequal, _nolock );
if (pconti.bad())
return f.warning_box ("Non esiste il gruppo relativo a questo conto");
}
if (sottoc > 0) // sottoconto => ricerca conto
{
pconti.zero() ;
pconti.put(PCN_GRUPPO, gruppo) ;
pconti.put(PCN_CONTO, conto) ;
pconti.setkey(1) ;
pconti.read(_isequal, _nolock );
if (pconti.bad())
return f.warning_box ("Non esiste il conto relativo a questo sottoconto");
else
{
TString tmcf = pconti.get(PCN_TMCF);
if (tmcf.not_empty())
return f.warning_box ("Non puoi inserire un sottoconto di un conto relativo ad un cliente/fornitore");
}
}
}
return TRUE;
}
HIDDEN bool sottoc_handler(TMask_field& f, KEY key)
{
if (key == K_TAB)
{
TString gruppo(f.mask().get(FLD_CM1_GRUPPO));
if (gruppo.empty()) return TRUE;
TString conto(f.mask().get(FLD_CM1_CONTO));
TString sottoconto(f.mask().get(FLD_CM1_SOTTOCONTO));
if (sottoconto.not_empty() && conto.empty()) return f.error_box("Manca il CONTO");
dispatch_e_char(f.parent(), K_SHIFT_ENTER);
}
return TRUE;
}
bool CG0100_application::user_create()
{
_msk = new TMask("cg0100a") ;
_msk->set_handler(FLD_CM1_GRUPPO, gruppo_handler);
_msk->set_handler(FLD_CM1_SOTTOCONTO, sottoc_handler);
_msk->set_handler(FLD_CM1_INDBIL, indbil_handler);
_msk->set_handler(FLD_CM1_TMCF, tmcf_handler);
_rel = new TRelation(LF_PCON);
_saldi = new TLocalisamfile(LF_SALDI);
_saldi->setkey(2);
set_search_field(FLD_CM1_GRUPPO);
return TRUE;
}
bool CG0100_application::user_destroy()
{
delete _msk;
delete _rel;
delete _saldi;
return TRUE;
}
int cg0100(int argc, char* argv[])
{
CG0100_application a ;
a.run(argc, argv, "Piano dei conti");
return 0;
}