Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@22135 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			381 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			381 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | |
| #include <automask.h>
 | |
| #include <execp.h>
 | |
| #include <progind.h>
 | |
| #include <recarray.h>
 | |
| #include <recset.h>
 | |
| #include <relation.h>
 | |
| #include <reprint.h>
 | |
| 
 | |
| #include "../cg/cglib01.h"
 | |
| 
 | |
| #include "ammce.h"
 | |
| #include "cespi.h"
 | |
| #include "movce.h"
 | |
| #include "salce.h"
 | |
| #include "celib.h"
 | |
| #include "ce2101.h"
 | |
| 
 | |
| #include "ce4.h"
 | |
| #include "ce4300.h"
 | |
| 
 | |
| ////////////////////////////////////////////////////////
 | |
| //	MASCHERA
 | |
| ////////////////////////////////////////////////////////
 | |
| class TStampa_proiez_ammo_mask : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   TStampa_proiez_ammo_mask();
 | |
|   virtual ~TStampa_proiez_ammo_mask() {}
 | |
| };
 | |
| 
 | |
| 
 | |
| bool TStampa_proiez_ammo_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| { 
 | |
|   bool ok = true;
 | |
|   switch (o.dlg())
 | |
|   {
 | |
|   case F_FROM_CAT:
 | |
|   case F_D_FROM_CAT:
 | |
|   case F_TO_CAT:
 | |
|   case F_D_TO_CAT:
 | |
|     {
 | |
|       TDitta_cespiti& dc = ditta_cespiti();
 | |
|       ok = dc.on_category_event(o, e, jolly);
 | |
|     }
 | |
|     break;
 | |
| 
 | |
| 	case F_ESERCIZIO:
 | |
|   case F_GRUPPO:
 | |
|   case F_SPECIE:
 | |
|     if (e == fe_init || e == fe_modify)
 | |
|     {
 | |
|       const TString& esercizio = get(F_ESERCIZIO);
 | |
|       const TString& gruppo = get(F_GRUPPO);
 | |
|       const TString& specie = get(F_SPECIE);
 | |
|       TString16 key; key << esercizio << gruppo << specie;
 | |
|       TRelation ccb("CCB");
 | |
|       ccb.curr().put("CODTAB", key);
 | |
|       if (ccb.read() == NOERR)
 | |
|         autoload(ccb);
 | |
|     }
 | |
|     break;
 | |
|   default: break;
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| 
 | |
| TStampa_proiez_ammo_mask::TStampa_proiez_ammo_mask()
 | |
| 								:TAutomask("ce4300")
 | |
| {}
 | |
| 
 | |
| 
 | |
| ///////////////////////////////////////////////////////////////
 | |
| //	RECORDSET
 | |
| ///////////////////////////////////////////////////////////////
 | |
| 
 | |
| class TStampa_proiez_ammo_recordset : public TISAM_recordset
 | |
| {
 | |
| public:
 | |
|   void set_filter(const TStampa_proiez_ammo_mask& msk);
 | |
|   TStampa_proiez_ammo_recordset(const TString& sql) : TISAM_recordset(sql) { }
 | |
| };
 | |
| 
 | |
| static const TStampa_proiez_ammo_recordset* myself = NULL;
 | |
| 
 | |
| //metodo per caricare i valori nel recordset dalla maschera...fighissimo!!
 | |
| void TStampa_proiez_ammo_recordset::set_filter(const TStampa_proiez_ammo_mask& msk)
 | |
| {
 | |
| 	const TString& gruppo = msk.get(F_GRUPPO);
 | |
| 	const TString& specie = msk.get(F_SPECIE);
 | |
| 	TString8 attivita;
 | |
| 	attivita.format("%-2s%-4s", (const char*)gruppo, (const char*)specie);
 | |
| 
 | |
| 	const TString& dacat = msk.get(F_FROM_CAT);
 | |
| 	const TString& acat = msk.get(F_TO_CAT);
 | |
| 	TString query = "USE %CAC";
 | |
| 
 | |
| 	query << " SELECT ((CODTAB[1,6]='      ')||(CODTAB[1,6]='" << attivita << "'))";
 | |
| 	if (dacat.full() || acat.full())
 | |
| 	{
 | |
| 		
 | |
| 		if (dacat == acat)
 | |
| 			query << "&&(CODTAB[7,8]=='" << dacat << "')";
 | |
| 		else
 | |
| 		{
 | |
| 			if (dacat.full())
 | |
| 				query << "&&(CODTAB[7,8]>='" << dacat << "')";
 | |
| 			if (acat.full())
 | |
| 				query << "&&(CODTAB[7,8]<='" << acat << "')";
 | |
| 		}
 | |
| 	}
 | |
| 	query << "\nBY I0 CODTAB[7,8]";
 | |
| 	set(query);	//setta la nuova query nel report
 | |
| }
 | |
| 
 | |
| 
 | |
| ////////////////////////////////////////////////////////
 | |
| //	REPORT
 | |
| ////////////////////////////////////////////////////////
 | |
| class TStampa_proiez_ammo_rep : public TReport
 | |
| {
 | |
| 	int _anno;
 | |
| 	//Clamoroso TAssocarray che conterra' tutti i valori dei record di CESPI utili al completamento..
 | |
| 	//..della faticosa stampa..
 | |
| 	TAssoc_array _cat;
 | |
| 
 | |
| protected:
 | |
| 	virtual bool get_usr_val(const TString& name, TVariant& var) const;
 | |
| 	void add_value (const int codcat, const char* field, const real& value);
 | |
| 	real get_value (const int codcat, const char* field) const;
 | |
| 
 | |
| public:
 | |
| 	void set_filter(const TStampa_proiez_ammo_mask& msk);
 | |
| };
 | |
| 
 | |
| 
 | |
| void TStampa_proiez_ammo_rep::add_value (const int codcat, const char* field, const real& value)
 | |
| {
 | |
| 	TString4 key;
 | |
| 	key << codcat;
 | |
| 
 | |
| 	TAssoc_array* cat = (TAssoc_array*)_cat.objptr(key);
 | |
| 	if (cat == NULL)
 | |
| 	{
 | |
| 		cat = new TAssoc_array;
 | |
| 		_cat.add(key, cat);
 | |
| 	}
 | |
| 	real* val = (real*)cat->objptr(field);
 | |
| 	if (val == NULL)
 | |
| 	{
 | |
| 		val = new real;
 | |
| 		cat->add(field, val);
 | |
| 	}
 | |
| 	*val += value;
 | |
| }
 | |
| 
 | |
| 
 | |
| real TStampa_proiez_ammo_rep::get_value (const int codcat, const char* field) const
 | |
| {
 | |
| 	TString4 key;
 | |
| 	key << codcat;
 | |
| 
 | |
| 	TAssoc_array* cat = (TAssoc_array*)_cat.objptr(key);
 | |
| 	if (cat != NULL)
 | |
| 	{
 | |
|   	real* val = (real*)cat->objptr(field);
 | |
| 	  if (val != NULL)
 | |
| 			return *val;
 | |
| 	}
 | |
| 	return ZERO;
 | |
| }
 | |
| 
 | |
| 
 | |
| void TStampa_proiez_ammo_rep::set_filter(const TStampa_proiez_ammo_mask& msk)
 | |
| {
 | |
|   _anno = msk.get_int(F_ESERCIZIO);
 | |
|   const int gruppo = msk.get_int(F_GRUPPO);
 | |
|   const TString& specie = msk.get(F_SPECIE);
 | |
| 	((TStampa_proiez_ammo_recordset*) recordset())->set_filter(msk);
 | |
|   //ditta_cespiti().set_attivita(_anno, gruppo, specie);
 | |
| 
 | |
| 	_cat.destroy();
 | |
| 
 | |
| 	//Si vuole creare una lista di tutti i cespiti che ricadono nei parametri gr/sp/cat della..
 | |
| 	//..maschera di selezione, che verra' poi utilizzato per calcolare i valori del costo di tali..
 | |
| 	//..cespiti riuniti nella categoria di appartenenza
 | |
| 	TRelation rel_cespi(LF_CESPI);
 | |
| 	TRectype darec_cespi(LF_CESPI), arec_cespi(LF_CESPI);
 | |
| 	darec_cespi.put(CESPI_CODCGRA, msk.get(F_GRUPPO));
 | |
| 	darec_cespi.put(CESPI_CODSPA, msk.get(F_SPECIE));
 | |
| 	darec_cespi.put(CESPI_CODCAT, msk.get(F_FROM_CAT));
 | |
| 
 | |
| 	arec_cespi = darec_cespi;
 | |
| 	arec_cespi.put(CESPI_CODCAT, msk.get(F_TO_CAT));
 | |
| 
 | |
| 	//Dalla lista cespiti deve risalire ai costi, agli ammortamenti e alle alienazioni;..
 | |
| 	//..quindi servono i files collegati..
 | |
| 	//TLocalisamfile salce(LF_SALCE);
 | |
| 	//TLocalisamfile ammce(LF_AMMCE);
 | |
| 
 | |
| 	//ISAM query per trovare su MOVCE i movimenti relativi al cespite corrente nell'esercizio selezionato
 | |
| 	TString query;
 | |
| 	TEsercizi_contabili esc;
 | |
|   const TDate& dataini = esc[_anno].inizio();
 | |
| 	const TDate& datafine = esc[_anno].fine();
 | |
|   query << "USE MOVCE KEY 2";
 | |
|   query << "\nSELECT BETWEEN(DTMOV,#DADATA,#ADATA)";
 | |
|   query << "\nFROM IDCESPITE=#CESPITE";
 | |
|   query << "\nTO IDCESPITE=#CESPITE";
 | |
| 	TISAM_recordset movce(query);
 | |
|   movce.set_var("#DADATA", dataini);
 | |
|   movce.set_var("#ADATA", datafine);
 | |
|   //il cespite lo setta di volta in volta nel for sottostante
 | |
| 
 | |
| 	//Ciclo principale per riempire _cat, assoc_array di assoc_array che sara' poi scandito in fase di creazione report
 | |
| 	//Il metodo add_value e' quello che effettivamente aggiunge i valori a _cat
 | |
| 	TCursor cur_cespi(&rel_cespi, "", 2, &darec_cespi, &arec_cespi);
 | |
| 	const TRecnotype num = cur_cespi.items();
 | |
| 	TProgind pi(num, "Calcolo proiezione ammortamenti...");
 | |
| 	for (cur_cespi = 0; cur_cespi.pos() < num; ++cur_cespi)
 | |
| 	{
 | |
| 	  if (!pi.addstatus(1))
 | |
|       break;
 | |
| 
 | |
| 		const TString idcespite = rel_cespi.curr().get(CESPI_IDCESPITE);
 | |
|     const int codcat = rel_cespi.curr().get_int(CESPI_CODCAT);
 | |
| 
 | |
|     //NOVITA'! usa l'ggetto TCespite per completezza di calcoli
 | |
|     TCespite cespite(idcespite);
 | |
|     cespite.load_saldi(1, _anno);
 | |
| 
 | |
|     //valore ammortizzabile (#VALAMM)
 | |
|     const real val_ammortizzabile = cespite.val_amm();
 | |
|     //residuo da ammortizzare (#RESAMM)
 | |
|     const real res_da_ammortizzare = cespite.res_amm();
 | |
|     if (res_da_ammortizzare <= ZERO)
 | |
|       continue;
 | |
| 
 | |
| 		//Colonna ALIENAZIONI e colonna ACQUISIZIONI/INCREMENTI
 | |
| 		//cerca tutti i movimenti di vendita/acquisto relativi al cespite corrente all'interno dell'esercizio.. 
 | |
| 		//..selezionato sulla maschera;somma i loro importi in modo da ricavare l'importo complessivo..
 | |
| 		//..di tutti
 | |
| 
 | |
|     real alienazioni, acquisizioni;
 | |
| 
 | |
| 		movce.set_var("#CESPITE", TVariant(idcespite));		//assegna il vero valore dell'idcespite alla query
 | |
| 		for (bool ok = movce.move_first(); ok; ok = movce.move_next())
 | |
| 		{
 | |
| 			const real vendita = movce.get(MOVCE_IMPVEN).as_real();
 | |
| 			add_value(codcat, "ALIENAZIONI", vendita);
 | |
|       alienazioni += vendita;
 | |
| 
 | |
|       const real acquisto = movce.get(MOVCE_CSTO).as_real();
 | |
|       add_value(codcat, "ACQUISIZIONI", acquisto);
 | |
|       acquisizioni += acquisto;
 | |
| 		}
 | |
| 
 | |
|     add_value(codcat, "VALAMM", val_ammortizzabile - acquisizioni + alienazioni);
 | |
|     add_value(codcat, "RESAMM", res_da_ammortizzare - acquisizioni + alienazioni);
 | |
| 
 | |
|     //colonne AMMORTAMENTI
 | |
|     //anno selezionato nella mascheta
 | |
|     const TRectype& ammce = cespite.amm_pro();
 | |
| 		real qamm;
 | |
| 		qamm += ammce.get_real(AMMCE_QNOR);
 | |
| 		qamm += ammce.get_real(AMMCE_QACC);
 | |
| 		qamm += ammce.get_real(AMMCE_QANT);
 | |
| 		add_value(codcat, "AMMO1", qamm);
 | |
| 
 | |
| 		//Colonne degli ammortamenti successivi all'anno selezionato
 | |
| 		//Si calcolano in questo modo perche' si calcolano cespite x cespite;si usa costo_fin perche' e'..
 | |
| 		//..quello che serve nel futuro!
 | |
| 		real residuo = res_da_ammortizzare - qamm;	//qamm e' AMMO1
 | |
| 		TString8 ammo;
 | |
| 		for (int a = 2; a <= 5 && residuo > ZERO; a++)
 | |
| 		{
 | |
|       ammo.format("AMMO%d", a);
 | |
|       if (qamm >= residuo)
 | |
| 			{
 | |
| 				add_value(codcat, ammo, residuo);
 | |
| 				residuo = ZERO;
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				add_value(codcat, ammo, qamm);
 | |
| 				residuo -= qamm;
 | |
| 			}
 | |
| 		}
 | |
| 		if (residuo > ZERO)
 | |
| 			add_value(codcat, "AMMOX", residuo);
 | |
| 
 | |
| 
 | |
| 	}	//for(cur_cespi...
 | |
| 
 | |
| }
 | |
| 
 | |
| //metodo per il calcolo dei campi da calcolare (ma va'!) nel report
 | |
| bool TStampa_proiez_ammo_rep::get_usr_val(const TString& name, TVariant& var) const
 | |
| {
 | |
| 	const TRecordset& recset = *recordset();
 | |
| 	const int codcat = atoi(recset.get("CODTAB").as_string().mid(6, 2));
 | |
| 
 | |
| 	if (name == "#ANNOES")
 | |
| 	{
 | |
| 		var.set(_anno);
 | |
| 		return true;
 | |
| 	}
 | |
| 	if (name == "#FINESCPREC")
 | |
| 	{
 | |
| 		TEsercizi_contabili esc;
 | |
| 		TDate dal, al;
 | |
| 		esc.code2range(_anno, dal, al);
 | |
| 		var.set(dal - 1L);
 | |
| 		return true;
 | |
| 	}
 | |
| 	if (name == "#VALAMM")	//costo
 | |
| 	{		
 | |
| 		var = get_value(codcat, "VALAMM");
 | |
| 		return true;
 | |
| 	}
 | |
|   if (name == "#RESAMM")	//residuo da ammortizzare
 | |
| 	{		
 | |
| 		var = get_value(codcat, "RESAMM");
 | |
| 		return true;
 | |
| 	}
 | |
| 	if (name == "#ALIENAZIONI")	//movimenti di vendita
 | |
| 	{
 | |
| 		var = get_value(codcat, "ALIENAZIONI");
 | |
| 		return true;
 | |
| 	}
 | |
|   if (name == "#ACQUISIZIONI")	//movimenti di vendita
 | |
| 	{
 | |
| 		var = get_value(codcat, "ACQUISIZIONI");
 | |
| 		return true;
 | |
| 	}
 | |
| 	if (name.starts_with("#AMMO"))	//fondi ammortamento
 | |
| 	{
 | |
| 		var = get_value(codcat, name.mid(1));
 | |
| 		return true;
 | |
| 	}
 | |
| 
 | |
| 	return TReport::get_usr_val(name, var);
 | |
| }
 | |
| 
 | |
| ////////////////////////////////////////////////////////
 | |
| //	APPLICAZIONE
 | |
| ////////////////////////////////////////////////////////
 | |
| class TStampa_proiez_ammo : public TSkeleton_application
 | |
| {
 | |
| protected:
 | |
|   virtual void main_loop();
 | |
| };
 | |
| 
 | |
| 
 | |
| void TStampa_proiez_ammo::main_loop()
 | |
| {
 | |
| 	TStampa_proiez_ammo_mask mask;
 | |
|   while (mask.run() == K_ENTER)
 | |
|   {
 | |
| 		//report e book dei report
 | |
| 		TReport_book book;
 | |
| 		TStampa_proiez_ammo_rep rep;
 | |
| 		rep.load("ce4300a");
 | |
| 
 | |
| 		rep.set_filter(mask);
 | |
| 		book.add(rep);
 | |
| 
 | |
| 		book.print_or_preview();	//stampa il book dei report
 | |
| 	}
 | |
| }
 | |
| 
 | |
| int ce4300(int argc, char* argv[])
 | |
| {
 | |
|   TStampa_proiez_ammo a;
 | |
|   a.run(argc, argv, TR("Stampa proiezione ammortamenti cespiti"));
 | |
|   return 0;
 | |
| } |