Files correlati : ci2.exe Ricompilazione Demo : [ ] Commento : Modificata la proposta dei costi nella rilevazione ore git-svn-id: svn://10.65.10.50/branches/R_10_00@21976 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			979 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			979 lines
		
	
	
		
			26 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <defmask.h>
 | |
| #include <recset.h>
 | |
| #include <sheet.h>
 | |
| #include <utility.h>
 | |
| 
 | |
| #include <doc.h>
 | |
| 
 | |
| #include "ci2.h"
 | |
| #include "cilib.h"
 | |
| #include "ci2100a.h"
 | |
| #include "rilore.h"
 | |
| #include "../ca/commesse.h"
 | |
| #include "../ca/calib01.h"
 | |
| #include "../ve/velib.h"
 | |
| 
 | |
|                                       ////////////////////////////////////////////
 | |
|                                       ////    CLASSE TRilevamento_prev_msk    ////
 | |
|                                       ////////////////////////////////////////////
 | |
| 
 | |
| //Classe TRilevamento_prev_msk
 | |
| class TRilevamento_prev_msk : public TAutomask
 | |
| {
 | |
| 	short _cdc_sid, _cdc_lid;
 | |
| 	short _cms_sid, _cms_lid;
 | |
| 	short _fase_sid, _fase_lid;
 | |
| 	short _scdc_sid, _scdc_lid;
 | |
| 	short _scms_sid, _scms_lid;
 | |
| 	short _sfase_sid, _sfase_lid;
 | |
| 	TString _numpr;
 | |
| 	TString _tipopr;
 | |
| 
 | |
| protected:
 | |
|   const TString & proponi_costo(const TMask& msk);
 | |
|   const TString & proponi_costo(TToken_string& riga);
 | |
| 
 | |
| 	void get_anal_fields(TString & cdc, TString & cms, TString & fase);
 | |
| 	void get_row_anal_fields(TToken_string & row, TString & cdc, TString & cms, TString & fase);
 | |
| 	void put_row_anal_fields(TToken_string & row, const TString & cdc, const TString & cms, const TString & fase);
 | |
|   void carica_default();
 | |
| 	void update_column(short sid, bool full);
 | |
|   void riempi_sheet();
 | |
|   void nuova_riga();
 | |
|   void azzera_riga(TSheet_field& sheet);
 | |
|   void azzera_tutto(TSheet_field& sheet);
 | |
|   void registra();
 | |
| 
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
|   
 | |
| public:
 | |
|   void esegui() const;
 | |
|   TRilevamento_prev_msk();
 | |
| };
 | |
| 
 | |
| const TString & TRilevamento_prev_msk::proponi_costo(const TMask& msk)
 | |
| {
 | |
|   const TString8 codlist = msk.get(S_CODLIST);
 | |
|   const char tipo  = msk.get(S_RISOATT)[0];
 | |
|   TString80 codice;
 | |
|   switch(tipo)
 | |
|   {
 | |
|   case 'R': codice = msk.get(S_CODRIS); break;
 | |
|   case 'A': codice = msk.get(S_CODATT); break;
 | |
|   default : break;
 | |
|   }
 | |
| 	TDate dal = msk.get_date(S_DADATA);
 | |
|   const TString4 tpora = msk.get(S_TPORA);
 | |
| 
 | |
| 	if (!dal.ok())
 | |
| 		dal = eotime;
 | |
| 	else 
 | |
| 		dal.set_day(1);
 | |
| 
 | |
|   TRisoatt_key chiave(codlist, tipo, codice, dal, tpora);
 | |
| 	const TRectype & rec = cache().get("&ROA", chiave);
 | |
| 	
 | |
| 	if (rec.empty())
 | |
| 	{
 | |
| 		if (chiave.cod().full() && chiave.tpora().full())
 | |
| 		{
 | |
| 			TModule_table tab("ROA");
 | |
| 
 | |
| 			dal = msk.get_date(S_ADATA);
 | |
| 			if (!dal.ok())
 | |
| 				dal = eotime;
 | |
| 			else
 | |
| 				dal.set_day(1);
 | |
| 
 | |
| 			TRisoatt_key chiave_sec(codlist, tipo, codice, dal, tpora);
 | |
| 
 | |
| 			tab.put("CODTAB", chiave_sec);
 | |
| 			const int err = tab.read();
 | |
| 			if (err != _isemptyfile)
 | |
| 			{
 | |
| 				chiave.overwrite("????????", 21, 8);
 | |
| 				if (err != _iseof)
 | |
| 					tab.prev();
 | |
| 				if (tab.get("CODTAB").match(chiave))
 | |
| 					return tab.get("R2");
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	else
 | |
| 		return rec.get("R2");
 | |
| 	return EMPTY_STRING;
 | |
| }
 | |
| 
 | |
| const TString &  TRilevamento_prev_msk::proponi_costo(TToken_string& riga)
 | |
| {
 | |
|   real costo = ZERO;
 | |
|   TSheet_field& sheet = sfield(F_SHEET);
 | |
|   const TString8 codlist  = riga.get(sheet.cid2index(S_CODLIST));
 | |
|   const char tipo  = riga.get_char(sheet.cid2index(S_RISOATT));
 | |
|   TString80 codice;
 | |
|   switch(tipo)
 | |
|   {
 | |
|   case 'R': codice = riga.get(sheet.cid2index(S_CODRIS)); break;
 | |
|   case 'A': codice = riga.get(sheet.cid2index(S_CODATT)); break;
 | |
|   default : break;
 | |
|   }
 | |
| 
 | |
|   TDate dal(riga.get(sheet.cid2index(S_DADATA)));
 | |
|   const TString4 tpora = riga.get(sheet.cid2index(S_TPORA));
 | |
| 
 | |
| 	if (!dal.ok())
 | |
| 		dal = eotime;
 | |
| 	else
 | |
| 		dal.set_day(1);
 | |
| 
 | |
| 	TRisoatt_key chiave(codlist, tipo, codice, dal, tpora);
 | |
| 	const TRectype & rec = cache().get("&ROA", chiave);
 | |
| 	
 | |
| 	if (rec.empty())
 | |
| 	{
 | |
| 		if (chiave.cod().full() && chiave.tpora().full())
 | |
| 		{
 | |
| 			TModule_table tab("ROA");
 | |
| 
 | |
| 			dal = riga.get(sheet.cid2index(S_ADATA));
 | |
| 			if (!dal.ok())
 | |
| 				dal = eotime;
 | |
| 			else
 | |
| 				dal.set_day(1);
 | |
| 
 | |
| 			TRisoatt_key chiave_sec(codlist, tipo, codice, dal, tpora);
 | |
| 
 | |
| 			tab.put("CODTAB", chiave_sec);
 | |
| 			const int err = tab.read();
 | |
| 			if (err != _isemptyfile)
 | |
| 			{
 | |
| 				chiave.overwrite("????????", 21, 8);
 | |
| 				if (err != _iseof)
 | |
| 					tab.prev();
 | |
| 				if (tab.get("CODTAB").match(chiave))
 | |
| 					return tab.get("R2");
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	else
 | |
| 		return rec.get("R2");
 | |
| 	return EMPTY_STRING;
 | |
| }
 | |
| 
 | |
| void TRilevamento_prev_msk::get_anal_fields(TString & cdc, TString & cms, TString & fase)
 | |
| {
 | |
| 	TString val;
 | |
| 
 | |
| 	cdc.cut(0);
 | |
| 	if (_cdc_sid >= 0)
 | |
| 		for ( short id = _cdc_sid; id <= _cdc_lid; id++)
 | |
| 		{
 | |
| 			val = get(id);
 | |
| 			val.rpad(field(id).size());
 | |
| 			cdc << val;
 | |
| 		}
 | |
| 	cdc.trim();
 | |
| 	cms.cut(0);
 | |
| 	if (_cms_sid >= 0)
 | |
| 		for ( short id = _cms_sid; id <= _cms_lid; id++)
 | |
| 		{
 | |
| 			val = get(id);
 | |
| 			val.rpad(field(id).size());
 | |
| 			cms << val;
 | |
| 		}
 | |
| 	cms.trim();
 | |
| 	fase.cut(0);
 | |
| 	if (_fase_sid >= 0)
 | |
| 		for ( short id = _fase_sid; id <= _fase_lid; id++)
 | |
| 		{
 | |
| 			val = get(id);
 | |
| 			val.rpad(field(id).size());
 | |
| 			fase << val;
 | |
| 		}
 | |
| 	fase.trim();
 | |
| }
 | |
| 
 | |
| void TRilevamento_prev_msk::get_row_anal_fields(TToken_string & row, TString & cdc, TString & cms, TString & fase)
 | |
| {
 | |
| 	TSheet_field & s = sfield(F_SHEET);
 | |
| 	TMask & m = s.sheet_mask();
 | |
| 	TString val;
 | |
| 
 | |
| 	cdc.cut(0);
 | |
| 	if (_scdc_sid >= 0)
 | |
| 		for ( short id = _scdc_sid; id <= _scdc_lid; id++)
 | |
| 		{
 | |
| 			val = row.get(s.cid2index(id));
 | |
| 			val.rpad(m.field(id).size());
 | |
| 			cdc << val;
 | |
| 		}
 | |
| 	cdc.trim();
 | |
| 	cms.cut(0);
 | |
| 	if (_scms_sid >= 0)
 | |
| 		for ( short id = _scms_sid; id <= _scms_lid; id++)
 | |
| 		{
 | |
| 			val = row.get(s.cid2index(id));
 | |
| 			val.rpad(m.field(id).size());
 | |
| 			cms << val;
 | |
| 		}
 | |
| 	cms.trim();
 | |
| 	fase.cut(0);
 | |
| 	if (_sfase_sid >= 0)
 | |
| 		for ( short id = _sfase_sid; id <= _sfase_lid; id++)
 | |
| 		{
 | |
| 			val = row.get(s.cid2index(id));
 | |
| 			val.rpad(m.field(id).size());
 | |
| 			fase << val;
 | |
| 		}
 | |
| 	fase.trim();
 | |
| }
 | |
| 
 | |
| void TRilevamento_prev_msk::put_row_anal_fields(TToken_string & row, const TString & cdc, const TString & cms, const TString & fase)
 | |
| {
 | |
| 	TSheet_field & s = sfield(F_SHEET);
 | |
| 	TMask & m = s.sheet_mask();
 | |
| 	int pos = 0;
 | |
| 
 | |
| 	if (_scdc_sid >= 0)
 | |
| 		for (short id = _scdc_sid; id <= _scdc_lid; id++)
 | |
| 		{
 | |
| 			const int len = m.field(id).size();
 | |
| 			row.add(cdc.mid(pos, len), s.cid2index(id));
 | |
| 			pos += len;
 | |
| 		}
 | |
| 	pos = 0;
 | |
| 	if (_scms_sid >= 0)
 | |
| 		for (short id = _scms_sid; id <= _scms_lid; id++)
 | |
| 		{
 | |
| 			const int len = m.field(id).size();
 | |
| 			row.add(cms.mid(pos, len), s.cid2index(id));
 | |
| 			pos += len;
 | |
| 		}
 | |
| 	pos = 0;
 | |
| 	if (_sfase_sid >= 0)
 | |
| 		for (short id = _sfase_sid; id <= _sfase_lid; id++)
 | |
| 		{
 | |
| 			const int len = m.field(id).size();
 | |
| 			row.add(fase.mid(pos, len), s.cid2index(id));
 | |
| 			pos += len;
 | |
| 		}
 | |
| }
 | |
| 
 | |
| void TRilevamento_prev_msk::carica_default()
 | |
| {
 | |
|   //leggo dalla maschera i campi chiave di ricerca
 | |
| 	const int       anno     = get_date(F_DADATA).year();
 | |
|   const TString4  risoatt  = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
 | |
|   const int damese = get_date(F_DADATA).month();
 | |
|   const int amese = get_date(F_ADATA).month();
 | |
|   const TString4  tpora    = get(F_TPORA);
 | |
|   TString80 codcosto;
 | |
|   TString80 codcms;
 | |
|   TString16 codfase;
 | |
|   TString16 codice;
 | |
| 
 | |
| 	switch(get(F_RISOATT)[0])
 | |
|   {
 | |
|   case 'R': codice = get(F_CODRIS); break;
 | |
|   case 'A': codice = get(F_CODATT); break;
 | |
|   default: break;
 | |
|   }
 | |
|  
 | |
| 	get_anal_fields(codcosto, codcms, codfase);
 | |
| 
 | |
| 	TString query;
 | |
|   query << "USE " << LF_RILORE << " KEY 2\n";
 | |
| 
 | |
| 	TString select;
 | |
| 	if (risoatt.full())
 | |
| 		query << "(" << RILORE_TIPORA << "=="   << risoatt << ")";
 | |
| 	if (codice.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODICE << "==\"" << codice << "\")";
 | |
| 	}
 | |
| /*	if (anno > 0)
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "STR(" << RILORE_ANNO << "==" << anno  << ")";
 | |
| 	}
 | |
| 	if (damese > 0 || amese > 0)
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(BETWEEN(MESE,\""     << damese   << "\",\"" << amese    << "\"))";
 | |
| 	} */
 | |
| 	if (tpora.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_TPORA << "==\""    << tpora    << "\")";
 | |
| 	}
 | |
| 	if (codcosto.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODCOSTO << "==\"" << codcosto << "\")";
 | |
| 	}
 | |
| 	if (codcms.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODCMS << "==\""   << codcms   << "\")";
 | |
| 	}
 | |
| 	if (codfase.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODFASE << "==\""  << codfase  << "\")";
 | |
| 	}
 | |
| 	if (select.full())
 | |
| 		query << "SELECT " << select << "\n";
 | |
| 
 | |
|   TString fromto = RILORE_TIPO "=\"D\" ";
 | |
| 
 | |
|   if (anno > 0)
 | |
|   {
 | |
|     fromto << "  " << RILORE_ANNO << "=\"" << anno << "\" ";
 | |
|     if (damese > 0)
 | |
|       fromto << RILORE_MESE << "=\"" << damese << "\" ";
 | |
|   }
 | |
| 
 | |
|   query << "FROM " << fromto  << "\n"
 | |
|         << "TO "   << fromto;
 | |
| 
 | |
|   TISAM_recordset def(query);
 | |
| 
 | |
|   TSheet_field& sheet = sfield(F_SHEET);
 | |
|   sheet.destroy();
 | |
| 
 | |
|   const TDate da(1, get_date(F_DADATA).month(), get_date(F_DADATA).year());
 | |
|   TDate a = da; a.set_end_month();
 | |
| 
 | |
|   //riempio lo sheet con i dati che soddisfano il filtro preparato prima
 | |
|   for(bool ok = def.move_first(); ok; ok = def.move_next())
 | |
|   {
 | |
|     TRilevamento_ore rilore(def.cursor()->curr());    
 | |
|     TToken_string& riga = sheet.row(-1);
 | |
| 		const char tipo = rilore.get(RILORE_TIPORA)[0];
 | |
| 		TString16 cod = rilore.get(RILORE_CODICE);
 | |
|     
 | |
| 		riga.add(tipo, sheet.cid2index(S_RISOATT));
 | |
|     switch (tipo)
 | |
|     {
 | |
| 			case 'R': riga.add(cod, sheet.cid2index(S_CODRIS)); break;
 | |
| 			case 'A': riga.add(cod, sheet.cid2index(S_CODATT)); break;
 | |
| 			default : break;
 | |
|     }
 | |
|     riga.add(rilore.get(RILORE_TPORA), sheet.cid2index(S_TPORA));
 | |
| 		riga.add(da.string(), sheet.cid2index(S_DADATA));
 | |
| 	  riga.add(a.string(), sheet.cid2index(S_ADATA));
 | |
| 		put_row_anal_fields(riga, rilore.get(RILORE_CODCOSTO), rilore.get(RILORE_CODCMS), rilore.get(RILORE_CODFASE));
 | |
|     riga.add(rilore.get(RILORE_QTAORE), sheet.cid2index(S_QTAORE));
 | |
|     riga.add(proponi_costo(riga), sheet.cid2index(S_COSTO));
 | |
| 		sheet.check_row(sheet.items() - 1);
 | |
|   }
 | |
|   sheet.force_update();
 | |
| }
 | |
| 
 | |
| void TRilevamento_prev_msk::update_column(short sid, bool full)
 | |
| {
 | |
|   TSheet_field& sf = sfield(F_SHEET);
 | |
|   sf.enable_column(sid, !full);
 | |
| 	if (full)
 | |
| 		sf.set_column_width(sid, 0);
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| //RIEMPI_SHEET: metodo che riempie lo sheet in base ai campi chiave
 | |
| //compilati sulla maschera
 | |
| void TRilevamento_prev_msk::riempi_sheet()
 | |
| {
 | |
|   TSheet_field& sheet = sfield(F_SHEET);
 | |
| 	TMask & sm = sheet.sheet_mask();
 | |
| 
 | |
| 	if (sheet.items() > 0 && sheet.dirty() && yesno_box("Vuoi salvare le modifiche"))
 | |
| 		registra();
 | |
| 	sheet.destroy();
 | |
| 
 | |
|   //leggo dalla maschera i campi chiave di ricerca
 | |
|   const TDate da = get_date(F_DADATA);
 | |
|   const TDate a = get_date(F_ADATA);
 | |
|   const int daanno = da.year();
 | |
|   int aanno = a.year();
 | |
| 
 | |
| 	if (aanno == 0)
 | |
| 		aanno = 2100;
 | |
|   const TString4  risoatt  = get(F_RISOATT) == "T" ? "" : get(F_RISOATT);
 | |
|   const TString4  tpora    = get(F_TPORA);
 | |
|   TString80 codcosto;
 | |
|   TString80 codcms;
 | |
|   TString16 codfase;
 | |
|   TString16 codice;
 | |
|   switch(get(F_RISOATT)[0])
 | |
|   {
 | |
|   case 'R': codice = get(F_CODRIS); break;
 | |
|   case 'A': codice = get(F_CODATT); break;
 | |
|   default: break;
 | |
|   }
 | |
|   
 | |
| 	get_anal_fields(codcosto, codcms, codfase);
 | |
| 
 | |
| 	sheet.set_columns_order();
 | |
| 	update_column(S_DADATA, da.ok());
 | |
| 	update_column(S_ADATA, a.ok());
 | |
| 	update_column(S_RISOATT, risoatt.full());
 | |
| 	update_column(S_CODRIS, codice.full());
 | |
| 	update_column(S_DESRIS, codice.full());
 | |
| 	update_column(S_CODATT, codice.full());
 | |
| 	update_column(S_DESATT, codice.full());
 | |
| 	update_column(S_TPORA, tpora.full());
 | |
| 	if (_scdc_sid >= 0)
 | |
| 		for ( short id = _scdc_sid; id <= _scdc_lid; id++)
 | |
| 		{
 | |
| 			update_column(id - 100, codcosto.full());
 | |
| 			sm.enable(id + 50, codcosto.blank());
 | |
| 		}
 | |
| 	if (_scms_sid >= 0)
 | |
| 		for ( short id = _scms_sid; id <= _scms_lid; id++)
 | |
| 		{
 | |
| 			update_column(id - 100, codcms.full());
 | |
| 			sm.enable(id + 50, codcms.blank());
 | |
| 		}
 | |
| 	if (_sfase_sid >= 0)
 | |
| 		for ( short id = _sfase_sid; id <= _sfase_lid; id++)
 | |
| 		{
 | |
| 			update_column(id - 100, codfase.full());
 | |
| 			sm.enable(id + 50, codfase.blank());
 | |
| 		}
 | |
| 
 | |
| 	TString query;
 | |
|   query << "USE " << LF_RILORE  << " KEY 2\n" ;
 | |
| 
 | |
| 	TString select;
 | |
| 	if (risoatt.full())
 | |
| 		select << "(" << RILORE_TIPORA << "==\""  << risoatt << "\")";
 | |
| 	if (codice.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODICE << "==\"" << codice << "\")";
 | |
| 	}
 | |
| 	if (select.full()) select << "&&";
 | |
| 	select << "(BETWEEN(" << RILORE_DADATA << ",\"" << da << "\",\"" << a << "\"))";
 | |
| 	if (tpora.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_TPORA << "==\""    << tpora    << "\")";
 | |
| 	}
 | |
| 	if (codcosto.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODCOSTO << "==\"" << codcosto << "\")";
 | |
| 	}
 | |
| 	if (codcms.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODCMS << "==\""   << codcms   << "\")";
 | |
| 	}
 | |
| 	if (codfase.full())
 | |
| 	{
 | |
| 		if (select.full()) select << "&&";
 | |
| 		select << "(" << RILORE_CODFASE << "==\""  << codfase  << "\")";
 | |
| 	}
 | |
| 	if (select.full())
 | |
| 		query << "SELECT " << select << "\n";
 | |
| 
 | |
|   TString from = RILORE_TIPO "=\"P\" ";
 | |
| 	TString to = from;
 | |
| 
 | |
|   if (daanno > 0)
 | |
|     from << "  " << RILORE_ANNO << "=" << daanno << " ";
 | |
|   to << "  " << RILORE_ANNO << "=" << aanno << " ";
 | |
| 
 | |
|   query << "FROM " << from  << "\n"
 | |
|         << "TO "   << to;
 | |
| 
 | |
|   TISAM_recordset def(query);
 | |
| 
 | |
|   //riempio lo sheet con i dati che soddisfano il filtro preparato prima
 | |
|   for(bool ok = def.move_first(); ok; ok = def.move_next())
 | |
|   {
 | |
|     TRilevamento_ore rilore(def.cursor()->curr());    
 | |
|     TToken_string& riga = sheet.row(-1);
 | |
| 		const char tipo = rilore.get(RILORE_TIPORA)[0];
 | |
| 		TString16 cod = rilore.get(RILORE_CODICE);
 | |
| 
 | |
|     riga.add(tipo, sheet.cid2index(S_RISOATT));
 | |
|     switch(tipo)
 | |
|     {
 | |
|     case 'R': riga.add(cod, sheet.cid2index(S_CODRIS)); break;
 | |
|     case 'A': riga.add(cod, sheet.cid2index(S_CODATT)); break;
 | |
|     default : break;
 | |
|     }
 | |
|     riga.add(rilore.get(RILORE_DADATA), sheet.cid2index(S_DADATA));
 | |
|     riga.add(rilore.get(RILORE_ADATA), sheet.cid2index(S_ADATA));
 | |
|     riga.add(rilore.get(RILORE_TPORA), sheet.cid2index(S_TPORA));
 | |
| 		put_row_anal_fields(riga, rilore.get(RILORE_CODCOSTO), rilore.get(RILORE_CODCMS), rilore.get(RILORE_CODFASE));
 | |
|     riga.add(rilore.get(RILORE_QTAORE), sheet.cid2index(S_QTAORE));
 | |
|     riga.add(rilore.get(RILORE_CODLIST), sheet.cid2index(S_CODLIST));
 | |
|     riga.add(rilore.get(RILORE_COSTO), sheet.cid2index(S_COSTO));
 | |
|     riga.add(rilore.get(RILORE_ID), sheet.cid2index(S_ID));
 | |
| 		sheet.check_row(sheet.items() - 1);
 | |
| 	}
 | |
|   sheet.force_update();
 | |
| }
 | |
| 
 | |
| //NUOVA_RIGA: metodo che aggiunge una riga allo sheet
 | |
| //tenendo conto dei campi chiave compilati in testata
 | |
| void TRilevamento_prev_msk::nuova_riga()
 | |
| {
 | |
|   TSheet_field& sheet = sfield(F_SHEET);
 | |
|   TToken_string & riga = sheet.row(-1);
 | |
| 	const int r = sheet.items() - 1;
 | |
|   TMask& msk = sheet.sheet_mask();
 | |
|   
 | |
|   //guardo il tipo risorsa / attrezzatura che sto ricercando
 | |
| 
 | |
| 	const bool tutti = get(F_RISOATT)[0] == 'T';
 | |
|   const TString4  tipo = tutti ? "R" : get(F_RISOATT);
 | |
|   TString codice;
 | |
| 	TString16 dadata(get(F_DADATA));
 | |
| 	TString16 adata(get(F_ADATA));
 | |
|   TString tpora    = get(F_TPORA);
 | |
|   TString codcosto;
 | |
|   TString codcms;
 | |
|   TString codfase;
 | |
| 
 | |
| 	riga.add(tipo, sheet.cid2index(S_RISOATT));
 | |
| 	if (!tutti)
 | |
| 	{
 | |
| 		if (tipo == "R") 
 | |
| 			riga.add(get(F_CODRIS), sheet.cid2index(S_CODRIS));
 | |
| 		else
 | |
| 		riga.add(get(F_CODATT), sheet.cid2index(S_CODATT));
 | |
| 	}
 | |
|   riga.add(dadata, sheet.cid2index(S_DADATA));
 | |
|   riga.add(adata, sheet.cid2index(S_ADATA));
 | |
| 	riga.add(tpora, sheet.cid2index(S_TPORA));
 | |
| 	get_anal_fields(codcosto, codcms, codfase);
 | |
| 	put_row_anal_fields(riga, codcosto, codcms, codfase);
 | |
| 	sheet.select(r);
 | |
| 	sheet.check_row(r);
 | |
| 	riga.add(proponi_costo(riga), sheet.cid2index(S_COSTO));
 | |
| 	sheet.force_update();
 | |
| }
 | |
| 
 | |
| //AZZERA_RIGA: metodo che azzera il valore unitario della riga selezionata
 | |
| void TRilevamento_prev_msk::azzera_riga(TSheet_field& sheet)
 | |
| {
 | |
|   TMask& msk = sheet.sheet_mask();
 | |
|   msk.set(S_DEL, "X");  
 | |
| }
 | |
| 
 | |
| //AZZERA_TUTTO: metodo che azzera il valore unitario di tutte le righe visualizzate sullo sheet
 | |
| void TRilevamento_prev_msk::azzera_tutto(TSheet_field& sheet)
 | |
| {
 | |
|   FOR_EACH_SHEET_ROW(sheet, r, row)
 | |
|   {
 | |
|     TToken_string& row = sheet.row(r);
 | |
| 
 | |
| 		row.add("X", sheet.cid2index(S_DEL));
 | |
|   }
 | |
| }
 | |
| 
 | |
| //REGISTRA: metodo che salva nella tabella di modulo le
 | |
| //righe dello sheet che hanno valore > 0, ed elimina quelle che hanno
 | |
| //vaoler pari a zero, e poi ricarica lo sheet
 | |
| void TRilevamento_prev_msk::registra()
 | |
| {
 | |
| 	TDoc_cache ca;
 | |
|   TRilevamento_ore rilroa;
 | |
|   TSheet_field& sheet = sfield(F_SHEET);
 | |
| 	int err = NOERR;
 | |
|   
 | |
| 	FOR_EACH_SHEET_ROW(sheet, r, row)
 | |
|   {
 | |
|     TToken_string&  riga = *(TToken_string*)row;
 | |
| 		const TString4 del = riga.get(sheet.cid2index(S_DEL));
 | |
|     const char      tipora = riga.get_char(sheet.cid2index(S_RISOATT));
 | |
|     const TString16 codice = tipora == 'R' ? riga.get(sheet.cid2index(S_CODRIS)) : riga.get(sheet.cid2index(S_CODATT));
 | |
|     const TDate&    dadata = riga.get(sheet.cid2index(S_DADATA));
 | |
|     const TDate&    adata  = riga.get(sheet.cid2index(S_ADATA));
 | |
|     const TString4  tpora = riga.get(sheet.cid2index(S_TPORA));
 | |
| 		const long id = riga.get_long(sheet.cid2index(S_ID));
 | |
|     TString80 codcosto;
 | |
|     TString80 codcms;
 | |
|     TString80 codfase;
 | |
|     const real  qtaore(riga.get(sheet.cid2index(S_QTAORE)));
 | |
|     const TString8 codlist = riga.get(sheet.cid2index(S_CODLIST));
 | |
|     const real costo(riga.get(sheet.cid2index(S_COSTO)));
 | |
|     
 | |
| 		get_row_anal_fields(riga, codcosto, codcms, codfase);
 | |
| 		const bool found = rilroa.read('P', id) == NOERR;
 | |
| 		if (del == "X")
 | |
| 		{
 | |
| 			if (found)
 | |
| 			{
 | |
| 				err = rilroa.remove();
 | |
| 				if (_numpr.full() && _tipopr.full())
 | |
| 				{
 | |
| 					TDocumento & doc = ca.doc(rilroa);
 | |
| 					const int docrow = doc.id2rownum(rilroa.get_long(RILORE_IDRIGA));
 | |
| 					
 | |
| 					if (docrow > 0)
 | |
| 						doc.destroy_row(docrow, true);
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
|     else
 | |
|     {
 | |
| 			const int anno = dadata.year();
 | |
| 			const int mese = dadata.month();
 | |
| 			const int giorno = dadata.day();
 | |
| 			rilroa.put(RILORE_TIPO, "P");
 | |
|       rilroa.put(RILORE_ID,  id);
 | |
| 			rilroa.put(RILORE_ANNO,     anno);
 | |
| 			rilroa.put(RILORE_MESE,     mese);
 | |
| 			rilroa.put(RILORE_GIORNO,   giorno);
 | |
| 			rilroa.put(RILORE_TIPORA,   tipora);
 | |
| 			rilroa.put(RILORE_CODICE,   codice);
 | |
| 			rilroa.put(RILORE_TPORA,    tpora);
 | |
| 			rilroa.put(RILORE_CODCOSTO, codcosto);
 | |
| 			rilroa.put(RILORE_CODCMS,   codcms);
 | |
| 			rilroa.put(RILORE_CODFASE,  codfase);
 | |
| 			rilroa.put(RILORE_DADATA, dadata);
 | |
|       rilroa.put(RILORE_ADATA, adata);
 | |
|       rilroa.put(RILORE_QTAORE, qtaore);
 | |
|       rilroa.put(RILORE_CODLIST, codlist);
 | |
|       rilroa.put(RILORE_COSTO, costo);
 | |
| 			if (_numpr.full() && _tipopr.full())
 | |
| 			{
 | |
| 				TDoc_key oldkey(rilroa);
 | |
| 				const long ndoc = date2ndoc(dadata) * 10000L + (adata.year() - dadata.year()) * 1000L+ date2ndoc(adata);
 | |
| 
 | |
| 				if (oldkey.provv() != 'D')
 | |
| 				{
 | |
| 					oldkey.set_provv();
 | |
| 					oldkey.set_anno(anno);
 | |
| 					oldkey.set_codnum(_numpr);
 | |
| 					oldkey.set_ndoc(ndoc);
 | |
| 				}
 | |
| 
 | |
| 				TDocumento & olddoc = ca.doc(oldkey);
 | |
| 				
 | |
| 				int docrow = olddoc.id2rownum(rilroa.get_long(RILORE_IDRIGA));
 | |
| 				TDoc_key key(olddoc);
 | |
| 				
 | |
| 				if (found && (key.anno() != anno || ndoc != olddoc.get_long(DOC_NDOC)))
 | |
| 				{
 | |
| 					if (docrow > 0)
 | |
| 						olddoc.destroy_row(docrow, true);
 | |
| 					docrow = -1;
 | |
| 					key.set_ndoc(ndoc);
 | |
| 				}
 | |
| 				
 | |
| 				TDocumento & doc = ca.doc(key);
 | |
| 
 | |
| 				doc.set_tipo(_tipopr);
 | |
| 				doc.put(DOC_DATADOC, dadata);
 | |
| 				doc.put(DOC_DATACOMP, dadata);
 | |
| 				doc.put(DOC_DATAFCOMP, adata);
 | |
| 
 | |
| 				TSpesa_prest risatt(codice, tipora);
 | |
| 
 | |
| 				if (docrow < 0)
 | |
| 				{
 | |
| 					doc.new_row(risatt.tipo_riga());
 | |
| 					docrow = doc.physical_rows();
 | |
| 					doc.set_row_ids();
 | |
| 				}
 | |
| 				TRiga_documento & rdoc = doc[docrow];
 | |
| 				rdoc.put(RDOC_TIPORIGA, risatt.tipo_riga());
 | |
| 				rdoc.put(RDOC_CODART,   codice);
 | |
| 				rdoc.put(RDOC_CHECKED, "X");
 | |
| 				rdoc.put(RILORE_TPORA,  tpora); // campo virtuale
 | |
| 				rdoc.put(RDOC_CODCOSTO, codcosto);
 | |
| 				rdoc.put(RDOC_CODCMS,   codcms);
 | |
| 				rdoc.put(RDOC_FASCMS,		codfase);
 | |
| 				rdoc.put(RDOC_QTA,			qtaore);
 | |
| 				rdoc.put(RDOC_UMQTA, risatt.um());
 | |
| 				rdoc.put(RDOC_PREZZO, costo);
 | |
| 				rdoc.put(RDOC_PREZZOL, rdoc.iva(risatt.cod_iva()).lordo(costo, ALL_DECIMALS));
 | |
| 				rdoc.put(RDOC_CODIVA, risatt.cod_iva());
 | |
| 				rilroa.put(RILORE_PROVV, key.provv());
 | |
| 				rilroa.put(RILORE_ANNOD, key.anno());
 | |
| 				rilroa.put(RILORE_CODNUM, key.codnum());
 | |
| 				rilroa.put(RILORE_NDOC, key.ndoc());
 | |
| 				rilroa.put(RILORE_IDRIGA, rdoc.get_long(RDOC_IDRIGA));
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				rilroa.zero(RILORE_PROVV);
 | |
| 				rilroa.zero(RILORE_ANNOD);
 | |
| 				rilroa.zero(RILORE_CODNUM);
 | |
| 				rilroa.zero(RILORE_NDOC);
 | |
| 				rilroa.zero(RILORE_IDRIGA);
 | |
| 			}
 | |
| 			err = rilroa.rewrite_write();
 | |
|     }
 | |
| 		if (err != NOERR)
 | |
| 			break;
 | |
|   }
 | |
| 	if (err == NOERR)
 | |
| 	{
 | |
| 		ca.destroy();
 | |
| 		sheet.destroy();
 | |
| 		riempi_sheet();
 | |
| 	}
 | |
| 	else
 | |
| 		error_box(FR("Errore %d in scrittura"), err);
 | |
| }
 | |
| 
 | |
| //ON_FIELD_EVENT: metodo che gestisce gli eventi sui vari campi della maschera
 | |
| bool TRilevamento_prev_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | |
| {
 | |
|  	if (e == fe_modify && f.dlg() >= F_ANAL && f.dlg() < F_ANAL+12)
 | |
| 	  riempi_sheet();
 | |
| 	if (f.dlg() == _scms_lid)
 | |
| 	{
 | |
| 		if (e == fe_init || e == fe_modify)
 | |
| 		{
 | |
| 			const TRectype & curr = f.mask().efield(_scms_lid).browse()->cursor()->curr();
 | |
| 			const TString codcms = curr.get(COMMESSE_CODCMS);
 | |
| 			TMask & m = f.mask();
 | |
| 
 | |
| 			m.set(S_CMSH, codcms);
 | |
| 	
 | |
| 			const TRectype & commesse = cache().get(LF_COMMESSE, codcms);
 | |
| 
 | |
| 			if (m.get(S_CODLIST).blank())
 | |
| 				m.set(S_CODLIST, commesse.get(COMMESSE_LISRILPR), 3);
 | |
| 		}
 | |
| 	}
 | |
|   switch (f.dlg())
 | |
| 	{
 | |
|   case DLG_DEFAULT:
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       carica_default();
 | |
|       return false;
 | |
|     }
 | |
|   case DLG_CERCA:
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       riempi_sheet();
 | |
|       return false;
 | |
|     }
 | |
|   case DLG_NEWREC:
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       nuova_riga();
 | |
|       return false;
 | |
|     }
 | |
|   case DLG_SAVEREC:
 | |
|     if (e == fe_button)
 | |
|     {
 | |
|       registra();
 | |
|       return false;
 | |
|     }
 | |
|     break;
 | |
|   case DLG_RESET:
 | |
|     if(e == fe_button)
 | |
|     {
 | |
|       TSheet_field& sheet = sfield(F_SHEET);
 | |
|       switch(jolly)
 | |
|       {
 | |
|       case  0: azzera_tutto(sheet); break;
 | |
|       case  1: azzera_riga(sheet);  break;
 | |
|       default:                      break;
 | |
|       }
 | |
|       sheet.force_update();
 | |
|       return false;
 | |
|     }
 | |
|     break;
 | |
| 	case F_DADATA:
 | |
| 	case F_ADATA:
 | |
|   case F_RISOATT:
 | |
|   case F_CODRIS:
 | |
|   case F_CODATT:
 | |
|   case F_TPORA:
 | |
|     if (e == fe_modify)
 | |
|       riempi_sheet();
 | |
|     break;
 | |
|   case F_SHEET:
 | |
|     if (e == se_query_add)
 | |
|     {
 | |
|       send_key(K_SPACE, DLG_NEWREC);
 | |
|       return false;
 | |
|     }
 | |
|   case S_CODRIS:
 | |
|   case S_CODATT:
 | |
|   case S_CODLIST:
 | |
|   case S_DADATA:
 | |
|   case S_TPORA:
 | |
|     if (e == fe_modify && f.mask().get(S_COSTO).blank())
 | |
| 			f.mask().set(S_COSTO, proponi_costo(f.mask()));
 | |
|   default: break;
 | |
|   }
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| void TRilevamento_prev_msk::esegui() const
 | |
| {
 | |
| }
 | |
| 
 | |
| TRilevamento_prev_msk::TRilevamento_prev_msk() 
 | |
|                      : TAutomask("ci2100a")
 | |
| {
 | |
|   const TMultilevel_code_info& fasinfo = ca_multilevel_code_info(LF_FASI);
 | |
| 	TConfig& ini = ca_config();
 | |
| 	TSheet_field & s = sfield(F_SHEET);
 | |
| 	TMask & sm = s.sheet_mask();
 | |
| 	int y = 3;
 | |
| 	int sy = 8;
 | |
|   short dlg = F_ANAL;        // id del primo campo da generare
 | |
|   short sdlg = S_CDC1 + 100; // id del primo campo da generare
 | |
| 
 | |
| 	_cdc_sid = _cdc_lid = _cms_sid = _cms_lid =	_fase_sid = _fase_lid =	-1;
 | |
| 	_scdc_sid = _scdc_lid =	_scms_sid = _scms_lid =	_sfase_sid = _sfase_lid = -1;
 | |
| 
 | |
| 	for (int i = 0; i < 2; i++)
 | |
|   {
 | |
|     const TString& level = ini.get("Level", NULL, i+1);  // Legge il livello 1 o 2
 | |
| 
 | |
| 		if (level == "CDC")                                  // Crea centro di costo 
 | |
|     {
 | |
|       if (fasinfo.parent() == LF_CDC)
 | |
| 			{
 | |
| 				int h = ca_multilevel_code_info(LF_CDC).levels();
 | |
|         const int h1 = ca_create_fields_compact(*this, 0, LF_FASI, 2, y, dlg, dlg + 100);
 | |
| 				y += 2;
 | |
| 				_cdc_sid = dlg;
 | |
| 				_cdc_lid = dlg + h - 1;
 | |
| 				_fase_sid = _cdc_lid + 1;
 | |
| 				_fase_lid = dlg + h1 - 1;
 | |
| 				dlg += h1;
 | |
|         const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy, sdlg, sdlg + 50);
 | |
| 				sy += 2;
 | |
| 				_scdc_sid = sdlg;
 | |
| 				_scdc_lid = sdlg + h - 1;
 | |
| 				_sfase_sid = _scdc_lid + 1;
 | |
| 				_sfase_lid = sdlg + sh - 1;
 | |
| 				sdlg += sh;
 | |
|       }
 | |
| 			else
 | |
| 			{
 | |
| 				const int h = ca_create_fields_compact(*this, 0, LF_CDC, 2, y++, dlg, dlg + 100);
 | |
| 				_cdc_sid = dlg;
 | |
| 				_cdc_lid = dlg + h - 1;
 | |
| 				dlg += h;
 | |
| 				const int sh = ca_create_fields_compact(sm, 0, LF_CDC, 2, sy++, sdlg, sdlg + 50);
 | |
| 				_scdc_sid = sdlg;
 | |
| 				_scdc_lid = sdlg + sh - 1;
 | |
| 				sdlg += h;
 | |
| 			}
 | |
|     }
 | |
| 	else
 | |
| 		if (level == "CMS")                                   // Crea commessa
 | |
| 		{
 | |
| 		  if (fasinfo.parent() == LF_COMMESSE)
 | |
| 			{
 | |
| 				int h = ca_multilevel_code_info(LF_COMMESSE).levels();
 | |
|         const int h1 = ca_create_fields_compact(*this, 0, LF_FASI, 2, y, dlg, dlg + 100);
 | |
| 				y += 2;
 | |
| 				_cms_sid = dlg;
 | |
| 				_cms_lid = dlg + h - 1;
 | |
| 				_fase_sid = _cms_lid + 1;
 | |
| 				_fase_lid = dlg + h1 - 1;
 | |
| 				dlg += h1;
 | |
|         const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy, sdlg, sdlg + 50);
 | |
| 				sy += 2;
 | |
| 				_scms_sid = sdlg;
 | |
| 				_scms_lid = sdlg + h - 1;
 | |
| 				_sfase_sid = _scms_lid + 1;
 | |
| 				_sfase_lid = sdlg + sh - 1;
 | |
| 				sdlg += sh;
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				const int h = ca_create_fields_compact(*this, 0, LF_COMMESSE, 2, y++, dlg, dlg + 100);
 | |
| 				_cms_sid = dlg;
 | |
| 				_cms_lid = dlg + h - 1;
 | |
| 				dlg += h;
 | |
| 				const int sh = ca_create_fields_compact(sm, 0, LF_COMMESSE, 2, sy++, sdlg, sdlg + 50);
 | |
| 				_scms_sid = sdlg;
 | |
| 				_scms_lid = sdlg + sh - 1;
 | |
| 				sdlg += sh;
 | |
| 			}
 | |
| 		}
 | |
|   }
 | |
|   if (fasinfo.levels() > 0 && fasinfo.parent() <= 0)
 | |
| 	{
 | |
|     const int h = ca_create_fields_compact(*this, 0, LF_FASI, 2, y++, dlg, dlg + 100);
 | |
| 		_fase_sid = dlg;
 | |
| 		_fase_lid = dlg + h - 1;
 | |
| 		dlg += h;
 | |
|     const int sh = ca_create_fields_compact(sm, 0, LF_FASI, 2, sy++, sdlg, sdlg + 50);
 | |
| 		_sfase_sid = sdlg;
 | |
| 		_sfase_lid = sdlg + sh - 1;
 | |
| 		sdlg += h;
 | |
| 	}
 | |
| 
 | |
|   for (int i = 0; i < 12; i++)
 | |
|   {
 | |
| 		const short id = F_ANAL + i;
 | |
| 
 | |
|     const int pos = id2pos(id);
 | |
|     if (pos >= 0)
 | |
|     {
 | |
| 			set_universal_handler(id);
 | |
| 			set_universal_handler(id + 100);
 | |
| 		}
 | |
| 	}
 | |
|   for (short id = S_CDC12 + 100; id >= S_CDC1 + 100; id--)
 | |
|   {
 | |
|     const int pos = sm.id2pos(id);
 | |
|     if (pos >= 0)
 | |
|     {
 | |
|       TMask_field& f = sm.fld(pos);
 | |
|       const int size = f.size();
 | |
|       const TString prompt = ((TEditable_field &)f).get_warning();
 | |
|       s.set_column_header(id, prompt);
 | |
|       s.set_column_justify(id, f.is_kind_of(CLASS_REAL_FIELD));
 | |
|       s.set_column_width(id, (max(3+size, prompt.len()+1)) * CHARX);
 | |
| 			s.update_column_width(id);
 | |
| 			s.enable_column(id);
 | |
| 			set_insheet_universal_handler(F_SHEET, id);
 | |
| 			set_insheet_universal_handler(F_SHEET, id + 50);
 | |
|     }
 | |
|     else
 | |
|       s.delete_column(id);
 | |
|   }
 | |
| 	_numpr = ini_get_string(CONFIG_DITTA, "ci", "CODNUMPR");
 | |
| 	_tipopr = ini_get_string(CONFIG_DITTA, "ci", "TIPODOCPR");
 | |
| }
 | |
| 
 | |
|                                       ////////////////////////////////////////////
 | |
|                                       ////    CLASSE TRilevamento_prev_app    ////
 | |
|                                       ////////////////////////////////////////////
 | |
| 
 | |
| //classe TRilevamento_prev_app
 | |
| class TRilevamento_prev_app : public TSkeleton_application
 | |
| {
 | |
| public:
 | |
|   virtual void main_loop();  
 | |
| };
 | |
| 
 | |
| void TRilevamento_prev_app::main_loop()
 | |
| {
 | |
| 	open_files(LF_DOC, LF_RIGHEDOC, LF_RILORE, 0);
 | |
|   TRilevamento_prev_msk msk; 
 | |
|   while (msk.run() != K_QUIT)
 | |
| 	  msk.esegui();
 | |
| }
 | |
| 
 | |
| int ci2100(int argc, char *argv[])
 | |
| {
 | |
|   TRilevamento_prev_app a;
 | |
|   a.run (argc, argv, TR("Rilevamento Ore Preventivo"));
 | |
|   return TRUE;
 | |
| }
 |