2004-11-29 09:52:49 +00:00
|
|
|
// Gestione Contabilita' Analitica
|
2004-12-15 13:55:45 +00:00
|
|
|
#include <execp.h>
|
2004-11-29 09:52:49 +00:00
|
|
|
#include <relapp.h>
|
|
|
|
|
|
|
|
#include "calib01.h"
|
|
|
|
#include "ca0400a.h"
|
2005-04-20 22:59:40 +00:00
|
|
|
#include "pdcana.h"
|
|
|
|
#include "panapdc.h"
|
|
|
|
#include <pconti.h>
|
2004-11-29 09:52:49 +00:00
|
|
|
|
|
|
|
class TPiano_conti_anal_msk : public TSimple_anal_msk
|
|
|
|
{
|
2005-04-20 22:59:40 +00:00
|
|
|
int _ind_bilancio;
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
protected:
|
|
|
|
virtual int get_logicnum() const { return LF_PCONANA; }
|
2005-04-20 22:59:40 +00:00
|
|
|
virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
|
2004-11-29 09:52:49 +00:00
|
|
|
|
|
|
|
public:
|
2004-12-20 10:26:43 +00:00
|
|
|
TPiano_conti_anal_msk() { read("ca0400a"); }
|
2004-11-29 09:52:49 +00:00
|
|
|
};
|
|
|
|
|
2005-04-20 22:59:40 +00:00
|
|
|
bool TPiano_conti_anal_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
|
|
|
|
{
|
|
|
|
switch (o.dlg())
|
|
|
|
{
|
|
|
|
case F_SHEET:
|
|
|
|
if (e == fe_init)
|
|
|
|
{
|
|
|
|
_ind_bilancio = 0;
|
|
|
|
TSheet_field & s = (TSheet_field &) o;
|
|
|
|
if (s.items() > 0)
|
|
|
|
{
|
|
|
|
TToken_string str = s.row(0);
|
|
|
|
TString key;
|
|
|
|
|
|
|
|
key << str.get(0) << "|";
|
|
|
|
key << str.get();
|
|
|
|
|
|
|
|
_ind_bilancio = atoi(cache().get(LF_PCON, key, PCN_INDBIL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (e == se_leave)
|
|
|
|
{
|
|
|
|
TSheet_field & s = (TSheet_field &) o;
|
|
|
|
TToken_string str = s.row(s.selected());
|
|
|
|
TString key;
|
|
|
|
|
|
|
|
key << str.get(0) << "|";
|
|
|
|
key << str.get();
|
|
|
|
|
|
|
|
const TRectype & pcon = cache().get(LF_PCON, key);
|
|
|
|
if (!pcon.empty())
|
|
|
|
{
|
|
|
|
const int ind_bilancio = pcon.get_int(PCN_INDBIL);
|
|
|
|
if (_ind_bilancio == 0)
|
|
|
|
_ind_bilancio = ind_bilancio;
|
|
|
|
if (_ind_bilancio != ind_bilancio)
|
|
|
|
return error_box("Indicatore di bilancio errato %d", ind_bilancio);
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TSimple_anal_msk::on_field_event(o, e, jolly);
|
|
|
|
}
|
|
|
|
|
|
|
|
class TAnalisi_rec : public TMultiple_rectype
|
|
|
|
{
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
TAnalisi_rec();
|
|
|
|
};
|
|
|
|
|
|
|
|
TAnalisi_rec::TAnalisi_rec() : TMultiple_rectype(LF_PCONANA)
|
|
|
|
{
|
|
|
|
add_file(LF_PANAPDC, PANAPDC_NRIGA);
|
|
|
|
}
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TAnalisi_app
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class TAnalisi_app : public TAnal_app
|
|
|
|
{
|
2005-04-20 22:59:40 +00:00
|
|
|
TAnalisi_rec * _rows;
|
|
|
|
int _maxlev;
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
protected:
|
2005-01-14 15:14:34 +00:00
|
|
|
virtual TSimple_anal_msk* create_mask() const { return new TPiano_conti_anal_msk; }
|
2004-12-15 13:55:45 +00:00
|
|
|
|
2005-04-20 22:59:40 +00:00
|
|
|
void rec2row(const TMask& m);
|
|
|
|
int row2rec(const TMask& m);
|
|
|
|
virtual int read(TMask& m);
|
|
|
|
virtual int write(const TMask& m);
|
|
|
|
virtual int rewrite(const TMask& m);
|
|
|
|
virtual bool remove();
|
|
|
|
void init_modify_mode(TMask& mask);
|
|
|
|
void init_insert_mode(TMask& mask);
|
|
|
|
|
2004-12-15 13:55:45 +00:00
|
|
|
virtual bool create();
|
2005-04-20 22:59:40 +00:00
|
|
|
virtual bool user_create();
|
|
|
|
virtual bool user_destroy();
|
2004-11-29 09:52:49 +00:00
|
|
|
};
|
|
|
|
|
2005-04-20 22:59:40 +00:00
|
|
|
void TAnalisi_app::rec2row(const TMask& m)
|
|
|
|
{
|
|
|
|
TSheet_field & s = m.sfield(F_SHEET);
|
|
|
|
const TMultiple_rectype & r = *_rows;
|
|
|
|
const int items = r.rows();
|
|
|
|
|
|
|
|
s.destroy();
|
|
|
|
|
|
|
|
if (items > 0)
|
|
|
|
{
|
|
|
|
for (int i = 1; i <= items; i++)
|
|
|
|
{
|
|
|
|
const TRectype & rec = r.body(0)[i];
|
|
|
|
TToken_string & str = s.row(i - 1);
|
|
|
|
|
|
|
|
str.add(rec.get(PANAPDC_GRUPPO));
|
|
|
|
str.add(rec.get(PANAPDC_CONTO));
|
|
|
|
str.add(rec.get(PANAPDC_SOTTOCONTO));
|
|
|
|
s.check_row(i - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s.force_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TAnalisi_app::read(TMask& m)
|
|
|
|
{
|
|
|
|
int err = TAnal_app::read(m);
|
|
|
|
|
|
|
|
if (err == NOERR)
|
|
|
|
{
|
|
|
|
const TRelation * r = get_relation();
|
|
|
|
|
|
|
|
_rows->zero();
|
|
|
|
_rows->put(PANAPDC_CODCONTO, r->curr().get(PANA_CODCONTO));
|
|
|
|
if (_rows->read() == NOERR)
|
|
|
|
rec2row(m);
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TAnalisi_app::row2rec(const TMask& m)
|
|
|
|
{
|
|
|
|
TSheet_field & s = m.sfield(F_SHEET);
|
|
|
|
TMultiple_rectype & r = *_rows;
|
|
|
|
|
|
|
|
const int items = s.items();
|
|
|
|
|
|
|
|
r.destroy_rows();
|
|
|
|
|
|
|
|
if (items > 0)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < items; i++)
|
|
|
|
{
|
|
|
|
TRectype & rec = r.new_row();
|
|
|
|
TToken_string & str = s.row(i);
|
|
|
|
|
|
|
|
rec.put(PANAPDC_GRUPPO, str.get(0));
|
|
|
|
rec.put(PANAPDC_CONTO, str.get());
|
|
|
|
rec.put(PANAPDC_SOTTOCONTO, str.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TAnalisi_app::write(const TMask& m)
|
|
|
|
{
|
|
|
|
TRelation * r = get_relation();
|
|
|
|
((TSimple_anal_msk &)m).update_tree_field();
|
|
|
|
|
|
|
|
row2rec(m);
|
|
|
|
const int err = _rows->write();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TAnalisi_app::rewrite(const TMask& m)
|
|
|
|
{
|
|
|
|
TRelation * r = get_relation();
|
|
|
|
((TSimple_anal_msk &)m).update_tree_field();
|
|
|
|
|
|
|
|
row2rec(m);
|
|
|
|
const int err = _rows->rewrite();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnalisi_app::remove()
|
|
|
|
{
|
|
|
|
TRelation * r = get_relation();
|
|
|
|
const int err = _rows->remove();
|
|
|
|
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAnalisi_app::init_modify_mode(TMask& mask)
|
|
|
|
{
|
|
|
|
const short id = ((TPiano_conti_anal_msk &)mask).get_field_id(_maxlev, 1);
|
|
|
|
|
|
|
|
mask.enable_page(1, mask.get(id).not_empty());
|
|
|
|
TAnal_app::init_modify_mode(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAnalisi_app::init_insert_mode(TMask& mask)
|
|
|
|
{
|
|
|
|
const short id = ((TPiano_conti_anal_msk &)mask).get_field_id(_maxlev, 1);
|
|
|
|
|
|
|
|
mask.enable_page(1, mask.get(id).not_empty());
|
|
|
|
TAnal_app::init_insert_mode(mask);
|
|
|
|
}
|
|
|
|
|
2004-12-15 13:55:45 +00:00
|
|
|
bool TAnalisi_app::create()
|
|
|
|
{
|
2005-03-16 12:12:22 +00:00
|
|
|
TConfig_anal cfg;
|
2005-04-12 15:54:05 +00:00
|
|
|
const TString& pdc = cfg.get("Pdci", NULL, 1);
|
|
|
|
if (pdc.blank())
|
|
|
|
{
|
|
|
|
const bool use_cg0 = cfg.get_bool("UsePdcc");
|
|
|
|
if (use_cg0)
|
|
|
|
{
|
|
|
|
TExternal_app app("cg0 -0");
|
|
|
|
app.run(true);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
2005-03-31 16:06:22 +00:00
|
|
|
return error_box(TR("Il piano dei conti analitico non e' stato configurato"));
|
|
|
|
}
|
2005-04-20 22:59:40 +00:00
|
|
|
|
2004-12-15 13:55:45 +00:00
|
|
|
return TAnal_app::create();
|
|
|
|
}
|
2004-11-29 09:52:49 +00:00
|
|
|
|
2005-04-20 22:59:40 +00:00
|
|
|
bool TAnalisi_app::user_create()
|
|
|
|
{
|
|
|
|
const bool ok = TAnal_app::user_create();
|
|
|
|
|
|
|
|
if (ok)
|
|
|
|
{
|
|
|
|
_rows = new TAnalisi_rec();
|
|
|
|
TPiano_conti_anal_msk * m = (TPiano_conti_anal_msk * ) get_mask(0);
|
|
|
|
|
|
|
|
for (int i = 0; i < 4; i++)
|
|
|
|
{
|
|
|
|
const short id = m->get_field_id(i, 1);
|
|
|
|
if (id <= 0 || m->id2pos(id) < 0)
|
|
|
|
break;
|
|
|
|
_maxlev = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnalisi_app::user_destroy()
|
|
|
|
{
|
|
|
|
delete _rows;
|
|
|
|
return TAnal_app::user_destroy();
|
|
|
|
}
|
|
|
|
|
2004-11-29 09:52:49 +00:00
|
|
|
int ca0400(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TAnalisi_app app;
|
|
|
|
app.run(argc, argv, TR("Gestione Piano dei conti analitico"));
|
|
|
|
return 0;
|
2004-12-15 13:55:45 +00:00
|
|
|
}
|