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"
|
2005-06-09 14:50:21 +00:00
|
|
|
#include "calibmsk.h"
|
2004-11-29 09:52:49 +00:00
|
|
|
#include "ca0400a.h"
|
2005-06-09 14:50:21 +00:00
|
|
|
|
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())
|
|
|
|
{
|
2005-06-09 14:50:21 +00:00
|
|
|
case F_SHEET:
|
|
|
|
if (e == fe_init)
|
|
|
|
{
|
|
|
|
_ind_bilancio = 0;
|
|
|
|
TSheet_field & s = (TSheet_field &) o;
|
|
|
|
if (s.items() > 0)
|
2005-04-20 22:59:40 +00:00
|
|
|
{
|
2005-06-09 14:50:21 +00:00
|
|
|
TToken_string str = s.row(0);
|
|
|
|
TString key;
|
2005-04-20 22:59:40 +00:00
|
|
|
|
2005-06-09 14:50:21 +00:00
|
|
|
key << str.get(0) << "|";
|
|
|
|
key << str.get();
|
2005-04-20 22:59:40 +00:00
|
|
|
|
2008-01-21 16:18:11 +00:00
|
|
|
// _ind_bilancio = atoi(cache().get(LF_PCON, key, PCN_INDBIL));
|
2005-04-20 22:59:40 +00:00
|
|
|
}
|
2005-06-09 14:50:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (e == se_leave)
|
|
|
|
{
|
2008-01-21 16:18:11 +00:00
|
|
|
const int master_indbil = get_int(F_INDBIL);
|
|
|
|
if (master_indbil > 0)
|
2005-04-20 22:59:40 +00:00
|
|
|
{
|
2008-01-21 16:18:11 +00:00
|
|
|
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 (master_indbil != ind_bilancio)
|
|
|
|
return error_box("Indicatore di bilancio errato %d", ind_bilancio);
|
|
|
|
}
|
2005-04-20 22:59:40 +00:00
|
|
|
}
|
2008-01-21 16:18:11 +00:00
|
|
|
return true;
|
2005-06-09 14:50:21 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2005-04-20 22:59:40 +00:00
|
|
|
}
|
|
|
|
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;
|
2008-01-21 16:18:11 +00:00
|
|
|
bool _riclassificato;
|
2005-04-20 22:59:40 +00:00
|
|
|
|
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);
|
2005-04-21 06:37:44 +00:00
|
|
|
void row2rec(const TMask& m);
|
2005-04-20 22:59:40 +00:00
|
|
|
virtual int read(TMask& m);
|
|
|
|
virtual int write(const TMask& m);
|
|
|
|
virtual int rewrite(const TMask& m);
|
|
|
|
virtual bool remove();
|
2007-02-07 09:12:08 +00:00
|
|
|
virtual bool protected_record(TRectype& rec);
|
2005-06-09 14:50:21 +00:00
|
|
|
|
|
|
|
void init_indbil(TMask& mask);
|
|
|
|
virtual void init_query_mode(TMask& mask);
|
|
|
|
virtual void init_insert_mode(TMask& mask);
|
|
|
|
virtual void init_modify_mode(TMask& mask);
|
2005-04-20 22:59:40 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-21 06:37:44 +00:00
|
|
|
void TAnalisi_app::row2rec(const TMask& m)
|
2005-04-20 22:59:40 +00:00
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TAnalisi_app::write(const TMask& m)
|
|
|
|
{
|
|
|
|
TRelation * r = get_relation();
|
|
|
|
|
2005-04-21 06:37:44 +00:00
|
|
|
m.autosave(*r);
|
|
|
|
_rows->head() = r->lfile().curr();
|
2005-04-20 22:59:40 +00:00
|
|
|
row2rec(m);
|
|
|
|
const int err = _rows->write();
|
|
|
|
|
2005-04-21 06:37:44 +00:00
|
|
|
r->read();
|
|
|
|
((TSimple_anal_msk &)m).update_tree_field();
|
2005-04-20 22:59:40 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TAnalisi_app::rewrite(const TMask& m)
|
|
|
|
{
|
|
|
|
TRelation * r = get_relation();
|
|
|
|
|
2005-04-21 06:37:44 +00:00
|
|
|
m.autosave(*r);
|
|
|
|
_rows->head() = r->lfile().curr();
|
2005-04-20 22:59:40 +00:00
|
|
|
row2rec(m);
|
2005-04-21 06:37:44 +00:00
|
|
|
|
|
|
|
r->read();
|
2005-04-20 22:59:40 +00:00
|
|
|
const int err = _rows->rewrite();
|
|
|
|
|
2005-04-21 06:37:44 +00:00
|
|
|
((TSimple_anal_msk &)m).update_tree_field();
|
2005-04-20 22:59:40 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TAnalisi_app::remove()
|
|
|
|
{
|
|
|
|
TRelation * r = get_relation();
|
|
|
|
const int err = _rows->remove();
|
|
|
|
|
|
|
|
return err == NOERR;
|
|
|
|
}
|
|
|
|
|
2007-02-07 09:12:08 +00:00
|
|
|
bool TAnalisi_app::protected_record(TRectype& rec)
|
|
|
|
{
|
|
|
|
TLocalisamfile pconana(LF_PCONANA);
|
|
|
|
pconana.curr() = rec;
|
|
|
|
if (pconana.read() == NOERR && pconana.next() == NOERR)
|
|
|
|
{
|
|
|
|
const TString key = rec.get(PANA_CODCONTO);
|
|
|
|
const TString new_key = pconana.get(PANA_CODCONTO);
|
|
|
|
|
|
|
|
return new_key.starts_with(key);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-06-09 14:50:21 +00:00
|
|
|
void TAnalisi_app::init_indbil(TMask& mask)
|
|
|
|
{
|
|
|
|
bool enabled = true;
|
|
|
|
if ((_maxlev > 0) && (mask.insert_mode() || mask.edit_mode()))
|
|
|
|
{
|
|
|
|
int level = 0;
|
|
|
|
for (level = _maxlev; level > 0; level--)
|
|
|
|
{
|
|
|
|
if (mask.field(F_KEY1+level).shown())
|
|
|
|
break;
|
|
|
|
}
|
2008-01-21 16:18:11 +00:00
|
|
|
enabled = level < _maxlev || _riclassificato; // Le foglie sono sempre disabilitate
|
2005-06-09 14:50:21 +00:00
|
|
|
if (level > 0) // Devo controllare i nodi padre
|
|
|
|
{
|
|
|
|
TString code; // Codice del piano dei conti
|
2008-01-21 16:18:11 +00:00
|
|
|
for (int i = 0; i < level; i++)
|
2005-06-09 14:50:21 +00:00
|
|
|
{
|
|
|
|
code << mask.get(F_KEY1+i); // Allungo il codice
|
|
|
|
const TRectype& rec = cache().get(LF_PCONANA, code);
|
|
|
|
const int indbil = rec.get_int(PANA_INDBIL);
|
|
|
|
if (indbil > 0) // Controllo se ha impostato l'indicatore
|
|
|
|
{
|
|
|
|
enabled = false;
|
|
|
|
mask.set(F_INDBIL, indbil);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mask.enable(F_INDBIL, enabled);
|
|
|
|
}
|
|
|
|
|
2005-04-20 22:59:40 +00:00
|
|
|
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());
|
2005-06-09 14:50:21 +00:00
|
|
|
|
|
|
|
TAnal_app::init_modify_mode(mask);
|
|
|
|
init_indbil(mask);
|
2005-04-20 22:59:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
2005-06-09 14:50:21 +00:00
|
|
|
|
|
|
|
TAnal_app::init_insert_mode(mask);
|
|
|
|
init_indbil(mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TAnalisi_app::init_query_mode(TMask& mask)
|
|
|
|
{
|
|
|
|
TAnal_app::init_query_mode(mask);
|
|
|
|
init_indbil(mask);
|
2005-04-20 22:59:40 +00:00
|
|
|
}
|
|
|
|
|
2004-12-15 13:55:45 +00:00
|
|
|
bool TAnalisi_app::create()
|
|
|
|
{
|
2005-09-19 15:03:13 +00:00
|
|
|
TConfig& cfg = ca_config();
|
2005-04-12 15:54:05 +00:00
|
|
|
const TString& pdc = cfg.get("Pdci", NULL, 1);
|
2008-01-21 16:18:11 +00:00
|
|
|
const bool use_pdcc = cfg.get_bool("UsePdcc");
|
|
|
|
|
|
|
|
_riclassificato = pdc.full() && use_pdcc;
|
|
|
|
|
2005-04-12 15:54:05 +00:00
|
|
|
if (pdc.blank())
|
|
|
|
{
|
2008-01-21 16:18:11 +00:00
|
|
|
if (use_pdcc)
|
2005-04-12 15:54:05 +00:00
|
|
|
{
|
|
|
|
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;
|
2005-06-09 14:50:21 +00:00
|
|
|
app.run(argc, argv, TR("Piano dei conti"));
|
2004-11-29 09:52:49 +00:00
|
|
|
return 0;
|
2004-12-15 13:55:45 +00:00
|
|
|
}
|