Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 1010 git-svn-id: svn://10.65.10.50/trunk@16333 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			271 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			271 lines
		
	
	
		
			6.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | ||
| #include <assoc.h>
 | ||
| #include <automask.h>
 | ||
| #include <currency.h>
 | ||
| #include <filetext.h>
 | ||
| #include <msksheet.h>
 | ||
| #include <printer.h>
 | ||
| #include <recarray.h>
 | ||
| #include <relation.h>
 | ||
| #include <sort.h>
 | ||
|    
 | ||
| #include "..\ve\velib.h"
 | ||
| 
 | ||
| #include "ps0544.h"
 | ||
| #include "ps0544300a.h"
 | ||
|  
 | ||
| class TSpics_file: public TFile_text
 | ||
| {
 | ||
| protected:
 | ||
|   virtual void validate(TCursor& cur,TRecord_text& rec, TToken_string& val, TString& str);
 | ||
| 
 | ||
| public:
 | ||
|   TSpics_file(const TString& file_name, const TString& config_name);
 | ||
|   virtual ~TSpics_file() { }
 | ||
| };
 | ||
| 
 | ||
| TSpics_file::TSpics_file(const TString& file_name, const TString& config_name)
 | ||
|           : TFile_text(file_name, config_name)
 | ||
| {
 | ||
| }
 | ||
| 
 | ||
| class TSpics_mask : public TAutomask
 | ||
| {
 | ||
| protected:
 | ||
|   bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| public:
 | ||
| 
 | ||
|   TSpics_mask();
 | ||
|   
 | ||
|   virtual ~TSpics_mask(){};
 | ||
| };
 | ||
|   
 | ||
| TSpics_mask::TSpics_mask() :TAutomask ("ps0544300a")
 | ||
| {
 | ||
| }  
 | ||
|   
 | ||
| bool TSpics_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| { 
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| class TSpics : public TSkeleton_application
 | ||
| {                     
 | ||
| 	TCursor*						_cur;
 | ||
| 	TSpics_mask*	 			_msk;
 | ||
| 	TDate								_dataini, _datafin;
 | ||
| 	TSpics_file* 				_trasfile;
 | ||
| 	TConfig*						_configfile;
 | ||
| 	long								_nrecords;
 | ||
| 	TRiga_documento*		_riga_doc_curr;
 | ||
| 
 | ||
| virtual const char * extra_modules() const {return "ve";}
 | ||
|   
 | ||
| protected:
 | ||
|   virtual bool create(void);
 | ||
|   virtual bool destroy(void);
 | ||
|   virtual void main_loop() ;
 | ||
|   void elabora_documenti();
 | ||
|   
 | ||
| public:   
 | ||
| 	const long nrecords() { return _nrecords;};
 | ||
| 	const TRiga_documento& riga_doc_curr() { return *_riga_doc_curr;};
 | ||
| 	TConfig configfile() {return *_configfile;};
 | ||
| 	TSpics() {} ;
 | ||
| 	virtual ~TSpics() {} ;
 | ||
| };  
 | ||
| 
 | ||
| // restituisce un riferimento all' applicazione
 | ||
| inline TSpics& app() { return (TSpics&) main_app();}
 | ||
| 
 | ||
| // gestione dei messaggi estesi nei campi
 | ||
| void TSpics_file::validate(TCursor& cur,TRecord_text &rec, TToken_string &s, TString& str)
 | ||
| {
 | ||
|   const TString code(s.get(0));
 | ||
|   TString valore;
 | ||
|   if (code == "_FISSO")
 | ||
|   {
 | ||
|     // gestione dei campi fissi per i record delle riba
 | ||
|     // sintassi: _FISSO,!<valore>
 | ||
|     // dove: <valore> <20> la stringa fissa da emettere
 | ||
|     TString in(s.get());
 | ||
|     CHECK(in[0]=='!',"Macro _FISSO senza carattere '!'");
 | ||
|     in.ltrim(1);
 | ||
|     in.trim();
 | ||
|     valore = in;
 | ||
|   }
 | ||
|    
 | ||
|   else if (code == "_DARIGA")
 | ||
|   {
 | ||
| 		valore = "";
 | ||
|  		TString in(s.get());
 | ||
| 		if (in == "QTA")
 | ||
| 		{
 | ||
| 			real qta = app().riga_doc_curr().quantita();
 | ||
| 			valore = qta.string(7,2,'0');
 | ||
| 			valore.strip(".");
 | ||
| 		}
 | ||
| 		else if (in=="CODART")
 | ||
| 		{
 | ||
| 			TString80 codart = app().riga_doc_curr().get(RDOC_CODART);
 | ||
| 			if (codart[0]!='A' ||  codart.len()<=10)
 | ||
| 				valore=codart;
 | ||
| 			else
 | ||
| 				valore=(codart.len()==12?valore << codart.left(10) << "  " << codart.mid(11,2):valore << codart.left(10) << "    " << codart.mid(11,4));                     
 | ||
| 		}
 | ||
|   }
 | ||
|   else if (code == "_PARAMETRI")
 | ||
|   {
 | ||
|  		TString in(s.get()); 	
 | ||
|  		valore = app().configfile().get(in);
 | ||
|   }
 | ||
|   else if (code == "_OGGI")
 | ||
|   {
 | ||
|     TDate data(TODAY);
 | ||
|   	valore = data.string(brief, '-', full, full, amg_date);
 | ||
|   	valore.strip("-");
 | ||
|   }
 | ||
|   else if (code == "_ADESSO")
 | ||
|   {        
 | ||
|   	char time[128];
 | ||
|   	_strtime(time);
 | ||
|   	valore.format("%s", time);
 | ||
|   	valore.strip(":");
 | ||
|   }
 | ||
|   else if (code == "_NRECORDS")
 | ||
|   {
 | ||
|   	valore.format("%ld", app().nrecords());
 | ||
|   }
 | ||
|   else if (code == "_UPPERCASE")
 | ||
| 	{
 | ||
| 		valore = str;
 | ||
| 		valore.upper();
 | ||
| 	}
 | ||
|   else NFCHECK("Macro non definita: %s", (const char *)code);
 | ||
|   
 | ||
|   str = valore;
 | ||
| }
 | ||
| 
 | ||
| bool TSpics::create()
 | ||
| {      
 | ||
| 	open_files(LF_DOC, LF_CLIFO, 0);
 | ||
| 	_msk = new TSpics_mask();
 | ||
| 	_trasfile = NULL;
 | ||
| 	_configfile = new TConfig("ps0544300a.ini", "TRASFERIMENTO");
 | ||
|   return TSkeleton_application::create();
 | ||
| }
 | ||
| 
 | ||
| bool TSpics::destroy()
 | ||
| {             
 | ||
| 	if (_trasfile)  
 | ||
|   	delete _trasfile;
 | ||
| 	if (_configfile)  
 | ||
|   	delete _configfile;
 | ||
|   delete _msk;
 | ||
| 
 | ||
|   return TSkeleton_application::destroy();
 | ||
| }
 | ||
| 
 | ||
| void TSpics::main_loop()
 | ||
| {
 | ||
| 	TFilename filename = _configfile->get("NOMEFILE");
 | ||
| 	if (filename.exist())
 | ||
| 		remove(filename);
 | ||
|   while (_msk->run()!=K_QUIT)
 | ||
|   {                     
 | ||
|   	_trasfile = new TSpics_file(filename, "ps0544300.ini");
 | ||
|   	_trasfile->open(filename,'w');
 | ||
|     _trasfile->force_record_separator(TRUE);
 | ||
|   	
 | ||
|     _dataini = _msk->get_date(F_DATAINI);
 | ||
|     _datafin = _msk->get_date(F_DATAFIN);
 | ||
| 		elabora_documenti(); 		
 | ||
| 		_trasfile->close();
 | ||
| 		delete _trasfile;
 | ||
| 		_trasfile = NULL;
 | ||
| 	}	
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TSpics::elabora_documenti()
 | ||
| {                
 | ||
|   TSheet_field& sheet = _msk->sfield(F_SHEETDOC);
 | ||
| 
 | ||
|   TRelation doc_rel(LF_DOC);
 | ||
|   doc_rel.add(LF_RIGHEDOC, "CODNUM==CODNUM|ANNO==ANNO|PROVV==PROVV|NDOC==NDOC");
 | ||
|   doc_rel.add(LF_CLIFO, "TIPOCF==TIPOCF|CODCF==CODCF");
 | ||
|   TRectype da(LF_DOC);
 | ||
|   TRectype a(LF_DOC);
 | ||
|   const long items = sheet.items();
 | ||
|   TString filt_expr;
 | ||
| 	
 | ||
| 	_nrecords = 0;
 | ||
|   if (items > 0)
 | ||
|   {
 | ||
| 	  bool ok = TRUE;
 | ||
| 	  TString16 codnum;
 | ||
| 
 | ||
| 	  da.put("DATADOC", _dataini);
 | ||
| 	  a.put("DATADOC", _datafin);
 | ||
| 	  
 | ||
| 	  filt_expr << "(";
 | ||
| 	  FOR_EACH_SHEET_ROW(sheet, r, row)
 | ||
| 	  {
 | ||
| 	    codnum = row->get(0);
 | ||
| 	    if (codnum.not_empty())
 | ||
| 	    {
 | ||
| 	    	filt_expr << "(CODNUM==\"";
 | ||
| 	    	filt_expr << codnum << "\")||";
 | ||
| 	    }
 | ||
| 	  }
 | ||
| 	  filt_expr.rtrim(2);  
 | ||
| 	  filt_expr << ")";
 | ||
| 
 | ||
| 	  doc_rel.lfile().set_curr(new TDocumento);
 | ||
| 	  _cur = new TCursor(&doc_rel,filt_expr,3,&da,&a);
 | ||
| 	  const long cur_items = _cur ->items(); // Scorre tutti i documenti che rientrano nell'intervallo selezionato
 | ||
| 	  if (cur_items != 0) 
 | ||
| 	  {
 | ||
| 			TRecord_text rech;
 | ||
| 			rech.set_type("OP");
 | ||
| 			_trasfile->autoload(rech, *_cur); 
 | ||
| 			_trasfile->write(rech);
 | ||
| 			for (*_cur = 0; _cur->pos() < cur_items; ++(*_cur))
 | ||
| 			{
 | ||
| 												
 | ||
| 				TRecord_text rec;
 | ||
|  				rec.set_type("01");
 | ||
|  				_trasfile->autoload(rec, *_cur); 
 | ||
|  				_trasfile->write(rec);
 | ||
| 				_nrecords++;
 | ||
|  				TDocumento documento = doc_rel.curr();
 | ||
| 		    for (int i=1;i<=documento.rows();i++)
 | ||
| 				{             
 | ||
| 					const TRiga_documento& rec_rdoc = documento[i];
 | ||
| 					_riga_doc_curr = new TRiga_documento(rec_rdoc);
 | ||
| 					doc_rel.curr(LF_RIGHEDOC) = rec_rdoc;
 | ||
| 					rec.set_type("02");
 | ||
| 					_trasfile->autoload(rec, *_cur); 
 | ||
|   				_trasfile->write(rec);
 | ||
| 					_nrecords++;
 | ||
| 					delete _riga_doc_curr;
 | ||
|  				}
 | ||
| 			}
 | ||
| 			TRecord_text recf;
 | ||
| 			recf.set_type("CL");
 | ||
| 			_trasfile->autoload(recf, *_cur); 
 | ||
| 			_trasfile->write(recf);
 | ||
| 		}                  
 | ||
| 	  delete _cur;
 | ||
| 	}  
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| int ps0544300(int argc, char **argv) 
 | ||
| {
 | ||
|   TSpics a;
 | ||
|   a.run(argc, argv, "Trasferimento a SPICS");
 | ||
|   return 0;
 | ||
| }
 | ||
| 
 |