Files correlati : Ricompilazione Demo : [ ] Commento : Rportata la versione 3.2 patch 1314 git-svn-id: svn://10.65.10.50/trunk@18269 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			226 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			226 lines
		
	
	
		
			6.3 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <config.h>
 | |
| 
 | |
| #include "../ve/velib.h"
 | |
| 
 | |
| #include "colib.h"
 | |
| #include "socicoop.h"
 | |
| #include "mercaticoop.h"
 | |
| 
 | |
| static bool add_socio(const TRelation& rel, void* pJolly)
 | |
| {
 | |
|   TString_array& a = *(TString_array*)pJolly;
 | |
|   TString16 key, last_key;
 | |
|   
 | |
|   const TRectype& rec = rel.curr();
 | |
|   key.format("%6d", rec.get_int(SC_CODCF));
 | |
| 
 | |
|   const int last = a.items()-1;
 | |
|   if (last >= 0)
 | |
|     last_key = a.row(last);
 | |
| 
 | |
|   if (key != last_key)
 | |
|     a.add(key);
 | |
| 
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| static real get_perc_socio(const long codsocio, const TString& codcomp)
 | |
| {
 | |
| 	real perc = ZERO;
 | |
| 	const TRectype& socio = cache().get(LF_SOCICOOP, codsocio);
 | |
| 	if (socio.get(SC_COMPAGNIA1) == codcomp)
 | |
| 		perc = socio.get_real(SC_QUOTA1);
 | |
| 	else
 | |
| 		if (socio.get(SC_COMPAGNIA2) == codcomp)
 | |
| 			perc = socio.get_real(SC_QUOTA2);
 | |
| 		else
 | |
| 			if (socio.get(SC_COMPAGNIA3) == codcomp)
 | |
| 				perc = socio.get_real(SC_QUOTA3);
 | |
| 	return perc;
 | |
| }
 | |
| 
 | |
| // funzione che restituisce il codice spesa data il nome della spesa in configurazione
 | |
| static const TString& cod_spesa(const char* spesa)
 | |
| {
 | |
| 	static TAssoc_array _spese;
 | |
| 	static long _ditta = 0;
 | |
| 	if (prefix().get_codditta() != _ditta)
 | |
| 	{
 | |
| 		TConfig d(CONFIG_DITTA, "co");
 | |
| 		_spese = d.list_variables();
 | |
| 		_ditta = prefix().get_codditta();
 | |
| 	}
 | |
| 	TString* cod = (TString*) _spese.objptr(spesa);
 | |
| 	if (cod != NULL)
 | |
| 		return *cod;
 | |
| 	return EMPTY_STRING;
 | |
| }
 | |
| 
 | |
| // aggiorna le spese sul documento
 | |
| void update_spese_doc(const long codmercato, TDocumento& doc)
 | |
| {
 | |
| 	TAssoc_array spese_doc;
 | |
| 	const TRectype& mercato = cache().get(LF_MERCATICOOP, codmercato);
 | |
| 	spese_doc.add(cod_spesa("SpesaRitAcc"));		// spesa ritenuta accantonamento
 | |
| 	real perc = mercato.get_real(MC_DIRITTI1);
 | |
| 	if (!perc.is_zero())
 | |
| 		spese_doc.add(cod_spesa("SpesaDiritti1")); // spesa diritti di mercato 1
 | |
| 	perc = mercato.get_real(MC_DIRITTI2);
 | |
| 	if (!perc.is_zero())
 | |
| 		spese_doc.add(cod_spesa("SpesaDiritti2")); // spesa diritti di mercato 2
 | |
| 	real spesa = mercato.get_real(MC_SPESEFACC);
 | |
| 	if (!spesa.is_zero())
 | |
| 		spese_doc.add(cod_spesa("SpesaFacc"));		// spesa facchinaggio
 | |
| 	spesa = mercato.get_real(MC_SPESECASSE);
 | |
| 	if (!spesa.is_zero())
 | |
| 		spese_doc.add(cod_spesa("SpesaCasse"));		// spesa casse
 | |
| 	// chiamo la funzione che aggiunge in automatico le spese
 | |
| 	TString_array array_spese;
 | |
| 	spese_doc.get_keys(array_spese);
 | |
| 	doc.zero(DOC_SPESEUPD);
 | |
| 	doc.update_spese_aut(array_spese);
 | |
| 
 | |
| 	// devo ora sistemare le % e qta/prezzo sulle spese
 | |
| 	real totqta = ZERO;
 | |
| 	real totcasse = ZERO;
 | |
|   int i;
 | |
|   for (i = 1; i <= doc.rows(); i++)
 | |
|   {
 | |
| 		const TRiga_documento& riga_doc = doc[i];
 | |
| 		if (riga_doc.is_merce())
 | |
| 		{
 | |
| 			totqta+=riga_doc.quantita();
 | |
| 			totcasse+=riga_doc.get_long(DOC_NCOLLI);
 | |
| 		}
 | |
| 	}
 | |
|   for (i = 1; i <= doc.rows(); i++)
 | |
|   {
 | |
| 		TRiga_documento& riga_doc = doc[i];
 | |
| 		if (riga_doc.is_spese())
 | |
| 		{
 | |
| 			const char* codspesa = riga_doc.get(RDOC_CODART);
 | |
| 			if (spese_doc.is_key(codspesa))
 | |
| 			{
 | |
| 				const TString& spesadiritti1 = cod_spesa("SpesaDiritti1");
 | |
| 				if (spesadiritti1 == codspesa) // sistemo la qta/valore/codice iva
 | |
| 				{
 | |
| 					real perc = mercato.get_real(MC_DIRITTI1);
 | |
| 					if (!perc.is_zero())
 | |
| 					{
 | |
| 						riga_doc.put(RDOC_QTA, perc);
 | |
| 						riga_doc.put(RDOC_CODIVA, mercato.get(MC_CODIVA1));
 | |
| 					}
 | |
| 				}
 | |
| 				const TString& spesadiritti2 = cod_spesa("SpesaDiritti2");
 | |
| 				if (spesadiritti2 == codspesa) // sistemo la qta/valore/codice iva
 | |
| 				{
 | |
| 					real perc = mercato.get_real(MC_DIRITTI2);
 | |
| 					if (!perc.is_zero())
 | |
| 					{
 | |
| 						riga_doc.put(RDOC_QTA, perc);
 | |
| 						riga_doc.put(RDOC_CODIVA, mercato.get(MC_CODIVA2));
 | |
| 					}
 | |
| 				}
 | |
| 				const TString& spesafacc = cod_spesa("SpesaFacc");
 | |
| 				if (spesafacc == codspesa) // sistemo la qta/valore/codice iva
 | |
| 				{
 | |
| 					riga_doc.put(RDOC_QTA, totqta);
 | |
| 					riga_doc.put(RDOC_PREZZO, mercato.get(MC_SPESEFACC));
 | |
| 					riga_doc.put(RDOC_CODIVA, mercato.get(MC_CODIVAFACC));
 | |
| 				}
 | |
| 				const TString& spesacasse = cod_spesa("SpesaCasse");
 | |
| 				if (spesacasse == codspesa) // sistemo la qta/valore/codice iva
 | |
| 				{
 | |
| 					riga_doc.put(RDOC_QTA, totcasse);
 | |
| 					riga_doc.put(RDOC_PREZZO, mercato.get(MC_SPESECASSE));
 | |
| 					riga_doc.put(RDOC_CODIVA, mercato.get(MC_CODIVACASS));
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| // crea una lista documenti a partire da un conferimento per compagnia
 | |
| int compagnia2soci(const TDocumento& doc_orig, const TString& codcomp, const long codmercato, const long nfasta, TLista_documenti& listadoc)
 | |
| {
 | |
| 	TString_array listasoci;
 | |
| 	TRelation relsoci(LF_SOCICOOP);
 | |
| 	TString filtro = "(COMPAGNIA1=\"";
 | |
| 	filtro << codcomp;
 | |
| 	filtro << "\") || (COMPAGNIA2=\"";
 | |
| 	filtro << codcomp;
 | |
| 	filtro << "\") || (COMPAGNIA3=\"";
 | |
| 	filtro << codcomp;
 | |
| 	filtro << "\")";
 | |
| 	TCursor cursoci(&relsoci, filtro);
 | |
| 	cursoci.scan(add_socio, &listasoci);
 | |
| 	FOR_EACH_ARRAY_ROW(listasoci, r, row)
 | |
| 	{
 | |
| 		long codsocio = row->get_long();
 | |
| 		TDocumento docnew(doc_orig);
 | |
| 		docnew.put(DOC_CODCF, codsocio);
 | |
| 		docnew.put(DOC_TIPOCF, "F");
 | |
| 		docnew.put("MERCATO", codmercato);
 | |
| 		docnew.put("NFASTA", nfasta);
 | |
| 		listadoc.add(docnew);
 | |
| 	}
 | |
|   for (int i = 1; i <= doc_orig.rows(); i++)
 | |
|   {
 | |
| 		const TRiga_documento& riga_doc = doc_orig[i];
 | |
| 		if (riga_doc.is_merce())
 | |
| 		{
 | |
| 			const char avalore = riga_doc.get_char(RDOC_CODAGG1);
 | |
| 			if (avalore == 'X')
 | |
| 			{
 | |
| 				TGeneric_distrib prezzo_dist(riga_doc.prezzo(false, false), 2);
 | |
| 				for (int j = 0; j < listadoc.items(); j++)
 | |
| 				{
 | |
| 					long codsocio = listadoc[j].codcf();
 | |
| 					real perc = get_perc_socio(codsocio, codcomp);
 | |
| 					prezzo_dist.add(perc);
 | |
| 				}	
 | |
| 				for (int k = 0; k < listadoc.items(); k++)
 | |
| 				{
 | |
| 					real prezzosocio = prezzo_dist.get();
 | |
| 					listadoc[k][i].put(RDOC_PREZZO, prezzosocio);
 | |
| 				}	
 | |
| 			}
 | |
| 			
 | |
| 			TGeneric_distrib qta_dist(riga_doc.quantita(), 5);
 | |
| 			int j;
 | |
| 			
 | |
| 			for (j = 0; j < listadoc.items(); j++)
 | |
| 			{
 | |
| 				long codsocio = listadoc[j].codcf();
 | |
| 				real perc = get_perc_socio(codsocio, codcomp);
 | |
| 				qta_dist.add(perc);
 | |
| 			}	
 | |
| 			for (j = 0; j < listadoc.items(); j++)
 | |
| 			{
 | |
| 				real qtasocio = qta_dist.get();
 | |
| 				listadoc[j][i].put(RDOC_QTA, qtasocio);
 | |
| 			}	
 | |
| 			TGeneric_distrib qtagg_dist(riga_doc.get_real(RDOC_QTAGG1), 5);
 | |
| 			
 | |
| 			for (j = 0; j < listadoc.items(); j++)
 | |
| 			{
 | |
| 				long codsocio = listadoc[j].codcf();
 | |
| 				real perc = get_perc_socio(codsocio, codcomp);
 | |
| 				qtagg_dist.add(perc);
 | |
| 			}	
 | |
| 			for (j = 0; j < listadoc.items(); j++)
 | |
| 			{
 | |
| 				real qtasocio = qtagg_dist.get();
 | |
| 				listadoc[j][i].put(RDOC_QTAGG1, qtasocio);
 | |
| 			}	
 | |
| 		}
 | |
|   } 
 | |
| 	for (int i = 0; i < listadoc.items(); i++)
 | |
| 	{
 | |
| 		listadoc[i].put(DOC_RAGGR, true);
 | |
| 		update_spese_doc(codmercato, listadoc[i]);
 | |
| 	}
 | |
| 	return listadoc.items();
 | |
| }
 | |
| 
 |