git-svn-id: svn://10.65.10.50/branches/R_10_00@22916 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			348 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			348 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
// Gestione Contabilita' Analitica
 | 
						|
#include <execp.h>
 | 
						|
#include <relapp.h>
 | 
						|
 | 
						|
#include "calib01.h"
 | 
						|
#include "calibmsk.h"
 | 
						|
#include "ca0400a.h"
 | 
						|
 | 
						|
#include "pdcana.h"
 | 
						|
#include "panapdc.h"
 | 
						|
#include <pconti.h>
 | 
						|
 | 
						|
class TPiano_conti_anal_msk : public TSimple_anal_msk
 | 
						|
{
 | 
						|
	int _ind_bilancio;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual int get_logicnum() const { return LF_PCONANA; } 
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TPiano_conti_anal_msk() { read("ca0400a"); }
 | 
						|
};
 | 
						|
 | 
						|
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)
 | 
						|
			{
 | 
						|
				const int master_indbil = get_int(F_INDBIL);
 | 
						|
				if (master_indbil > 0)
 | 
						|
				{
 | 
						|
					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);
 | 
						|
					}
 | 
						|
				}
 | 
						|
				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);
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TAnalisi_app
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TAnalisi_app : public TAnal_app
 | 
						|
{
 | 
						|
  TAnalisi_rec * _rows;
 | 
						|
	int _maxlev;
 | 
						|
	bool _riclassificato;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual const char * extra_modules() const {return "ci|cm";} //funziona anche con autorizzazione CM
 | 
						|
 | 
						|
  virtual TSimple_anal_msk* create_mask() const { return new TPiano_conti_anal_msk; }
 | 
						|
 | 
						|
	void rec2row(const TMask& m);
 | 
						|
	void row2rec(const TMask& m);
 | 
						|
  virtual int read(TMask& m);
 | 
						|
  virtual int write(const TMask& m);
 | 
						|
  virtual int rewrite(const TMask& m);
 | 
						|
  virtual bool remove();
 | 
						|
  virtual bool protected_record(TRectype& rec);
 | 
						|
 | 
						|
  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);
 | 
						|
  
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool user_create();
 | 
						|
  virtual bool user_destroy();
 | 
						|
};
 | 
						|
 | 
						|
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;
 | 
						|
}
 | 
						|
 | 
						|
void 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());
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
int TAnalisi_app::write(const TMask& m)
 | 
						|
{
 | 
						|
	TRelation * r = get_relation();
 | 
						|
 | 
						|
	m.autosave(*r);
 | 
						|
	_rows->head() = r->lfile().curr();
 | 
						|
	row2rec(m);
 | 
						|
	const int	err = _rows->write();
 | 
						|
 | 
						|
  r->read();
 | 
						|
	((TSimple_anal_msk &)m).update_tree_field();
 | 
						|
	return err;
 | 
						|
}
 | 
						|
 | 
						|
int TAnalisi_app::rewrite(const TMask& m)
 | 
						|
{
 | 
						|
	TRelation * r = get_relation();
 | 
						|
 | 
						|
	m.autosave(*r);
 | 
						|
	_rows->head() = r->lfile().curr();
 | 
						|
	row2rec(m);
 | 
						|
 | 
						|
  r->read();
 | 
						|
	const int err = _rows->rewrite();
 | 
						|
 | 
						|
  ((TSimple_anal_msk &)m).update_tree_field();
 | 
						|
	return err;
 | 
						|
}
 | 
						|
 | 
						|
bool TAnalisi_app::remove()
 | 
						|
{
 | 
						|
	TRelation * r = get_relation();
 | 
						|
	const int err = _rows->remove();
 | 
						|
 | 
						|
	return err == NOERR;
 | 
						|
}
 | 
						|
 | 
						|
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;
 | 
						|
}
 | 
						|
 | 
						|
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;
 | 
						|
    }
 | 
						|
    enabled = level < _maxlev || _riclassificato; // Le foglie sono sempre disabilitate
 | 
						|
    if (level > 0) // Devo controllare i nodi padre
 | 
						|
    {
 | 
						|
      TString code;   // Codice del piano dei conti
 | 
						|
      for (int i = 0; i < level; i++)
 | 
						|
      {
 | 
						|
        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);
 | 
						|
}
 | 
						|
 | 
						|
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);
 | 
						|
  init_indbil(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);
 | 
						|
  init_indbil(mask);
 | 
						|
}
 | 
						|
 | 
						|
void TAnalisi_app::init_query_mode(TMask& mask)
 | 
						|
{
 | 
						|
  TAnal_app::init_query_mode(mask);
 | 
						|
  init_indbil(mask);
 | 
						|
}
 | 
						|
 | 
						|
bool TAnalisi_app::create()
 | 
						|
{
 | 
						|
	TConfig& cfg = ca_config();
 | 
						|
  const TString& pdc = cfg.get("Pdci", NULL, 1);
 | 
						|
	const bool use_pdcc = cfg.get_bool("UsePdcc");
 | 
						|
 | 
						|
	_riclassificato = pdc.full() && use_pdcc; 
 | 
						|
	
 | 
						|
  if (pdc.blank())
 | 
						|
	{
 | 
						|
	  if (use_pdcc)
 | 
						|
	  {
 | 
						|
			TExternal_app app("cg0 -0");
 | 
						|
	    app.run(true);
 | 
						|
			return false;
 | 
						|
		}
 | 
						|
		else
 | 
						|
      return error_box(TR("Il piano dei conti analitico non e' stato configurato"));
 | 
						|
  }
 | 
						|
  
 | 
						|
  return TAnal_app::create();
 | 
						|
}
 | 
						|
 | 
						|
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();
 | 
						|
}
 | 
						|
 | 
						|
int ca0400(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TAnalisi_app app;
 | 
						|
  app.run(argc, argv, TR("Piano dei conti"));
 | 
						|
  return 0;
 | 
						|
}
 |