Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@18348 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			289 lines
		
	
	
		
			8.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			289 lines
		
	
	
		
			8.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <automask.h>
 | |
| #include <progind.h>
 | |
| 
 | |
| #include "../ve/velib.h"
 | |
| #include "../pr/agenti.h" 
 | |
| 
 | |
| #include <comuni.h> 
 | |
| 
 | |
| #include "ps0077.h"
 | |
| #include "ps0077600a.h"
 | |
| 
 | |
| #define ALIAS_TIP 201
 | |
| 
 | |
| class TRDoc2JBI_mask : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
| public:
 | |
|   TRDoc2JBI_mask();
 | |
|   virtual ~TRDoc2JBI_mask(){};
 | |
| };
 | |
|   
 | |
| TRDoc2JBI_mask::TRDoc2JBI_mask() :TAutomask ("ps0077600a")
 | |
| {
 | |
| }  
 | |
| 
 | |
| bool TRDoc2JBI_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | |
| { 
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| class TRDoc2JBI : public TSkeleton_application
 | |
| { 
 | |
|   TRDoc2JBI_mask* _msk;
 | |
| 	TConfig* _config;
 | |
|                                             
 | |
| protected:
 | |
| 
 | |
|   virtual const char * extra_modules() const {return "ve";}
 | |
| 
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();  
 | |
|   virtual void main_loop();
 | |
|   void transfer(void);
 | |
| 	bool insert_tab(TExternisamfile& filetab, const char* tipo, const char* codice, const char* descri);
 | |
| 	void update_tab(TExternisamfile& filetab, const TRectype rectab);
 | |
| 
 | |
| public:
 | |
|   TRDoc2JBI_mask& mask() { return *_msk; };
 | |
|   TRDoc2JBI() {};
 | |
|   virtual ~TRDoc2JBI() {}
 | |
| };
 | |
| 
 | |
| bool TRDoc2JBI::create()
 | |
| {      
 | |
| 	open_files(LF_DOC, LF_RIGHEDOC, LF_ANAMAG, LF_CLIFO, LF_CFVEN, LF_COMUNI, LF_NDITTE, 0);
 | |
| 	_msk = new TRDoc2JBI_mask();
 | |
| 	_config = new TConfig("ps0077600.ini");
 | |
| 
 | |
|   return TSkeleton_application::create();
 | |
| }
 | |
| 
 | |
| bool TRDoc2JBI::destroy()
 | |
| { 
 | |
|   delete _config;
 | |
| 	delete _msk;
 | |
|   return TSkeleton_application::destroy();
 | |
| }
 | |
| 
 | |
| void TRDoc2JBI::main_loop()
 | |
| {                  
 | |
| 	// preimposto i valori specificati sulla riga di comando oppure faccio partire la maschera
 | |
| 	KEY key = K_ENTER;
 | |
|   if (argc() >= 4)    
 | |
| 	{
 | |
|     _msk->set(F_PERCORSO, argv(3));
 | |
|     _msk->set(F_ANNO, argv(2));
 | |
| 	}
 | |
| 	else
 | |
| 	{
 | |
|     _msk->set(F_PERCORSO, _config->get("PERCORSO", "PARAMETRI"));
 | |
|     _msk->set(F_ANNO, _config->get("ANNO", "PARAMETRI") );	
 | |
|     key = _msk->run();
 | |
| 	}
 | |
|   if (key == K_ENTER)
 | |
|     transfer();
 | |
| }
 | |
| 
 | |
| bool TRDoc2JBI::insert_tab(TExternisamfile& filetab, const char* tipo, const char* codice, const char* descri)
 | |
| {
 | |
| 	int err = NOERR;
 | |
| 	TString codstr(codice);
 | |
| 	if (codstr.not_empty())
 | |
| 	{
 | |
| 		filetab.zero();
 | |
| 		filetab.put("TIPO", tipo);
 | |
| 		filetab.put("CODICE", codice);
 | |
| 
 | |
| 		TString descstr(descri);
 | |
| 		if (descstr.not_empty())
 | |
| 			filetab.put("DESCRI", descri);
 | |
| 		else
 | |
| 			filetab.put("DESCRI", "manca descrizione");
 | |
| 		err = filetab.write();
 | |
| 	}
 | |
| 	return (err == NOERR); 
 | |
| }
 | |
| 
 | |
| void TRDoc2JBI::transfer()
 | |
| {                                       
 | |
|   TRelation rel(LF_RIGHEDOC);
 | |
|   rel.add(LF_DOC, "CODNUM==CODNUM|ANNO==ANNO|NDOC==NDOC|PROVV==PROVV");
 | |
|   rel.add("%TIP", "CODTAB==TIPODOC", 1, LF_DOC, ALIAS_TIP);
 | |
| 
 | |
|   TRDoc2JBI_mask& m = mask();
 | |
| 
 | |
|   TString expr;
 | |
| 	const int anno = m.get_int(F_ANNO);
 | |
| 	_config->set("ANNO", anno, "PARAMETRI");
 | |
| 	expr.format("33->TIPOCF==\"C\"");
 | |
| 	TRectype da(LF_RIGHEDOC);
 | |
| 	da.zero();
 | |
| 	da.put(RDOC_PROVV, 'D');
 | |
| 	da.put(RDOC_ANNO, anno);
 | |
| 	TCursor cur(&rel, "", 3, &da, &da);
 | |
|   cur.setfilter(expr, true);
 | |
|   
 | |
| 	const TString& path = m.get(F_PERCORSO);
 | |
| 	_config->set("PERCORSO", path, "PARAMETRI");
 | |
| 	
 | |
| 	TFilename rdocname = path;
 | |
| 	rdocname << _config->get("RIGHEDOC", "ARCHIVI");
 | |
| 	rdocname.ext("dbf");
 | |
|   TFilename rdoctrr = "jbi_rdoc.trr"; 
 | |
|   rdoctrr.custom_path();
 | |
| 	TExternisamfile filerdoc(rdocname, rdoctrr);
 | |
| 	filerdoc.zap();
 | |
| 	
 | |
| 	TFilename tabname = path;
 | |
| 	tabname << _config->get("TABELLE", "ARCHIVI");
 | |
| 	tabname.ext("dbf");
 | |
| 	TFilename tabtrr = "jbi_tab.trr";
 | |
| 	tabtrr.custom_path();
 | |
| 	TExternisamfile filetab(tabname, tabtrr);
 | |
| 	filetab.zap();
 | |
| 	
 | |
| 	// aggiungo il record ditta
 | |
| 
 | |
| 	TString80 ragsoc = cache().get(LF_NDITTE, get_firm(), "RAGSOC");
 | |
| 	TString16 firm;
 | |
| 	firm.format("%d", get_firm());
 | |
| 	insert_tab(filetab, "DIT", (const char*) firm, ragsoc);
 | |
| 		
 | |
| 	const long items = cur.items();
 | |
| 	TProgind p(items, "Elaborazione righe documenti in corso ...", true, true, 10);
 | |
| 	p.setstatus(1);
 | |
| 	int err = NOERR;
 | |
| 	for (cur=0; cur.pos()<items && !p.iscancelled() && err==NOERR; ++(cur))    
 | |
| 	{
 | |
| 		TDocumento* doc = new TDocumento(cur.curr(LF_DOC));
 | |
| 		p.addstatus(1);        
 | |
| 		const TRectype& rec_tipodoc = cur.curr(-ALIAS_TIP);
 | |
| 		const int tipodoc = rec_tipodoc.get_int("I1");
 | |
| 		const bool notacredito = rec_tipodoc.get_bool("B7");
 | |
| 		char tipo = ' ';
 | |
| 		if (tipodoc == 2)
 | |
| 		{
 | |
| 			if (notacredito)
 | |
| 				tipo = 'R';
 | |
| 			else
 | |
| 				tipo = 'F';
 | |
| 		}
 | |
| 		else if (tipodoc == 3)
 | |
| 			tipo = 'O';
 | |
| 		if (tipo != ' ')
 | |
| 		{
 | |
| 			const int nriga = cur.curr().get_int(RDOC_NRIGA);
 | |
| 			TRiga_documento& rigadoc = (*doc)[nriga];
 | |
| 			const real qta = cur.curr().get_real(RDOC_QTA);
 | |
| 			real importo = rigadoc.importo(FALSE, FALSE);
 | |
| 			if (!qta.is_zero() || !importo.is_zero())
 | |
| 			{
 | |
| 				filerdoc.zero();		
 | |
| 				filerdoc.put("CODDITTA", get_firm()); // ditta
 | |
| 				filerdoc.put("TIPO", tipo); // tipologia documento
 | |
| 				TDate data = cur.curr(LF_DOC).get(DOC_DATADOC);
 | |
| 				filerdoc.put("DATADOC", data.string()); // data doc.
 | |
| 				// record anamag
 | |
| 				const TRectype& rec_anamag = cache().get(LF_ANAMAG, cur.curr().get(RDOC_CODARTMAG));	
 | |
| 				// record clifo e cfven
 | |
| 				TToken_string key; 
 | |
| 				key.add(cur.curr(LF_DOC).get(DOC_TIPOCF)); 
 | |
| 				key.add(cur.curr(LF_DOC).get(DOC_CODCF));          
 | |
| 				const TRectype& rec_cfven = cache().get(LF_CFVEN, key);              
 | |
| 				const TRectype& rec_clifo = cache().get(LF_CLIFO, key);
 | |
| 				// record comuni
 | |
| 				key = "";
 | |
| 				key.add(rec_clifo.get(CLI_STATOCF));
 | |
| 				key.add(rec_clifo.get(CLI_COMCF));
 | |
| 				const TRectype& rec_comuni = cache().get(LF_COMUNI, key);
 | |
| 				TString16 tmp = cur.curr().get(RDOC_CODMAG);
 | |
| 				filerdoc.put("CODDEP", tmp); // codice deposito
 | |
| 				tmp = tmp.left(3);
 | |
| 				filerdoc.put("CODMAG", tmp); // codice magazzino
 | |
| 				tmp = rec_anamag.get(ANAMAG_GRMERC);
 | |
| 				filerdoc.put("SOTTOGR", tmp); // sottogruppo merceologico
 | |
| 				tmp = tmp.left(3);
 | |
| 				filerdoc.put("GRUPPO", tmp); //gruppo merceologico
 | |
| 				tmp = cur.curr(LF_DOC).get(DOC_ZONA); 
 | |
| 				if (tmp.empty())
 | |
| 					tmp = rec_cfven.get(CFV_CODZONA);
 | |
| 				filerdoc.put("ZONA", tmp); // zona 
 | |
| 				filerdoc.put("REGIONE", rec_comuni.get("CODREG")); // regione
 | |
| 				filerdoc.put("PROV", rec_comuni.get(COM_PROVCOM)); // provincia
 | |
| 				tmp = cur.curr(LF_DOC).get(DOC_CATVEN);
 | |
| 				if (tmp.empty())
 | |
| 					tmp = rec_cfven.get(CFV_CATVEN);
 | |
| 				filerdoc.put("CATMERCLI", tmp); // cat. merceologica
 | |
| 				filerdoc.put("CODCLI", cur.curr(LF_DOC).get(DOC_CODCF)); // codice cliente
 | |
| 				tmp = cur.curr(LF_DOC).get(DOC_CODAG);
 | |
| 				if (tmp.empty())
 | |
| 					tmp = rec_cfven.get(CFV_CODAG);
 | |
| 				filerdoc.put("CODAG", tmp); // codice agente
 | |
| 				filerdoc.put("CODART", cur.curr().get(RDOC_CODARTMAG)); // codice articolo
 | |
| 				filerdoc.put("TIPODOC", cur.curr(LF_DOC).get(DOC_TIPODOC)); // tipo documento
 | |
| 				filerdoc.put("QTA", cur.curr().get(RDOC_QTA)); // quantita
 | |
| 				filerdoc.put("IMPORTO", importo); 
 | |
| 				importo = rigadoc.importo(TRUE, FALSE);
 | |
| 				filerdoc.put("SCONTATO", importo); 
 | |
| 				update_tab(filetab, filerdoc.curr());
 | |
| 				err = filerdoc.write();	
 | |
| 			}
 | |
| 		}	  	
 | |
| 		if (err != NOERR)
 | |
| 			error_box("Errore %d in scrittura file dbf. Elaborazione non terminata.", err);	
 | |
| 		delete doc;
 | |
| 	}
 | |
| }     
 | |
| 
 | |
| void TRDoc2JBI::update_tab(TExternisamfile& filetab, const TRectype rectab)
 | |
| {
 | |
| 	// TIP tipo documento 
 | |
| 	TString codice;;
 | |
| 	TString80 descr = cache().get("%TIP", rectab.get("TIPODOC"), "S0");
 | |
| 	insert_tab(filetab, "TIP", rectab.get("TIPODOC"), descr);
 | |
| 	// AGE agente
 | |
| 	descr = cache().get(LF_AGENTI, rectab.get("CODAG"), AGE_RAGSOC);
 | |
| 	insert_tab(filetab, "AGE", rectab.get("CODAG"), descr);
 | |
| 	// CVE cat.ven.
 | |
| 	descr = cache().get("%CVE", rectab.get("CATMERCLI"), "S0");
 | |
| 	insert_tab(filetab, "CVE", rectab.get("CATMERCLI"), descr);
 | |
| 	// CLI cliente
 | |
| 	codice = "C|";
 | |
| 	long codcli = rectab.get_long("CODCLI");
 | |
| 	codice.format("C|%06d", codcli);
 | |
| 	descr = cache().get(LF_CLIFO, codice, CLI_RAGSOC);
 | |
| 	codice.format("%06d", codcli);
 | |
| 	insert_tab(filetab, "CLI", codice, descr);
 | |
| 	// GRM gruppo merc.
 | |
| 	descr = cache().get("GMC", rectab.get("GRUPPO"), "S0");
 | |
| 	insert_tab(filetab, "GRM", rectab.get("GRUPPO"), descr);
 | |
| 	// SGM sottogruppo merceol.
 | |
| 	descr = cache().get("GMC", rectab.get("SOTTOGR"), "S0");
 | |
| 	insert_tab(filetab, "SGM", rectab.get("SOTTOGR"), descr);
 | |
| 	// ART codart
 | |
| 	descr = cache().get(LF_ANAMAG, rectab.get("CODART"), ANAMAG_DESCR);
 | |
| 	insert_tab(filetab, "ART", rectab.get("CODART"), descr);
 | |
| 	// ZON zona
 | |
| 	descr = cache().get("ZON", rectab.get("ZONA"), "S0");
 | |
| 	insert_tab(filetab, "ZON", rectab.get("ZONA"), descr);
 | |
| 	// RGI regioni
 | |
| 	descr = cache().get("%RGI", rectab.get("REGIONE"), "S0");
 | |
| 	insert_tab(filetab, "RGI", rectab.get("REGIONE"), descr);
 | |
| 	// MAG mag
 | |
| 	descr = cache().get("MAG", rectab.get("CODMAG"), "S0");
 | |
| 	insert_tab(filetab, "MAG", rectab.get("CODMAG"), descr);
 | |
| 	// DEP dep
 | |
| 	descr = cache().get("MAG", rectab.get("CODDEP"), "S0");
 | |
| 	insert_tab(filetab, "DEP", rectab.get("CODDEP"), descr);
 | |
| }
 | |
|            
 | |
| int ps0077600(int argc, char** argv)
 | |
| {
 | |
|   TRDoc2JBI app;
 | |
|   app.run(argc, argv, "Trasferimento JBI");    
 | |
|   return 0;
 | |
| }
 |