Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1358 git-svn-id: svn://10.65.10.50/trunk@18723 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			314 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			314 lines
		
	
	
		
			7.2 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <applicat.h>
 | ||
| #include <automask.h>
 | ||
| #include <execp.h>
 | ||
| #include <progind.h>
 | ||
| #include <reputils.h>
 | ||
| #include <utility.h>
 | ||
| #include <relation.h>
 | ||
| #include <reprint.h>
 | ||
| #include <textset.h>
 | ||
| #include <recarray.h>
 | ||
| 
 | ||
| 
 | ||
| #include "tabutil.h"
 | ||
| 
 | ||
| #include "ps0713.h"
 | ||
| #include "ps0713500a.h"
 | ||
| 
 | ||
| #include <rcausali.h>
 | ||
| #include <clifo.h>
 | ||
| #include <mov.h>
 | ||
| #include <rmov.h>
 | ||
| 
 | ||
| 
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| // TAutomask
 | ||
| ///////////////////////////////////////////////////////////
 | ||
| 
 | ||
| class TImportaSpese_mask : public TAutomask
 | ||
| {
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| 
 | ||
| public:
 | ||
|   TImportaSpese_mask();
 | ||
| };
 | ||
|   
 | ||
| TImportaSpese_mask::TImportaSpese_mask() :TAutomask ("ps0713500a")
 | ||
| {
 | ||
| }  
 | ||
| 
 | ||
| bool TImportaSpese_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | ||
| { 
 | ||
| 	switch (f.dlg())
 | ||
| 	{
 | ||
| 		//giochetto per avere la lista dei files validi nella directory di trasferimento!
 | ||
| 		case F_NAME:
 | ||
| 			if (e == fe_button)
 | ||
| 			{
 | ||
| 				TArray_sheet as(-1, -1, 72, 20, TR("Selezione file"), 
 | ||
|                            "File@32");
 | ||
| 				TFilename path = get(F_PATH);
 | ||
| 				path.add("*.csv");	//files delle testate
 | ||
| 				list_files(path, as.rows_array());
 | ||
| 				TFilename name;
 | ||
| 				FOR_EACH_ARRAY_ROW(as.rows_array(), i, row)
 | ||
| 				{
 | ||
| 					name = *row;
 | ||
| 					*row = name.name();
 | ||
| 				}
 | ||
| 				if (as.run() == K_ENTER)
 | ||
| 				{
 | ||
| 					f.set(as.row(as.selected()));
 | ||
| 				}
 | ||
| 			}
 | ||
| 			break;
 | ||
| 		default:
 | ||
| 			break;
 | ||
| 	}
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
|                                       ///////////////////////////////////////////////
 | ||
|                                       //// CLASSI DERIVATE PER IMPORTAZIONE DATI ////
 | ||
|                                       ///////////////////////////////////////////////  
 | ||
| 
 | ||
| /////////////////////////////////////////////////////////////
 | ||
| //	Recordset specifici per i dati da trasferire
 | ||
| /////////////////////////////////////////////////////////////
 | ||
| 
 | ||
| //Piano dei conti
 | ||
| class TImporta_spese_recordset : public TCSV_recordset
 | ||
| {
 | ||
|   protected:
 | ||
|     virtual TRecnotype new_rec(const char* buf = NULL);    
 | ||
|   
 | ||
|   public:
 | ||
|     TImporta_spese_recordset(const char * fileName);
 | ||
| };
 | ||
| 
 | ||
| TRecnotype TImporta_spese_recordset::new_rec(const char* buf)
 | ||
| {
 | ||
|   TToken_string str(256,'\t'); //nuovo record tab separator
 | ||
| 
 | ||
|   if(buf && *buf)
 | ||
|   {
 | ||
|     bool apici=false;
 | ||
| 
 | ||
|     for (const char* c = buf; *c ; c++)
 | ||
|     {
 | ||
|       if (*c == '"')
 | ||
|       {
 | ||
|         apici = !apici;
 | ||
|       }
 | ||
|       else
 | ||
|       {
 | ||
|         if (*c == ',')
 | ||
|         {
 | ||
|           if (!apici)
 | ||
|             str << str.separator();
 | ||
|           else
 | ||
|             str << *c;
 | ||
|         }
 | ||
|         else
 | ||
|           str << *c;
 | ||
| 
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| 
 | ||
|   const TRecnotype n = TText_recordset::new_rec(str);
 | ||
| 
 | ||
|   if (n >= 0)
 | ||
|     row(n).separator(str.separator());
 | ||
|   
 | ||
|   return n;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| TImporta_spese_recordset::TImporta_spese_recordset(const char * fileName)
 | ||
|                         : TCSV_recordset("CSV(,)")
 | ||
| {
 | ||
| 	load_file(fileName);
 | ||
| }
 | ||
| 
 | ||
| ///////////////////////////////////////
 | ||
| // TSkeleton_application
 | ||
| ///////////////////////////////////////
 | ||
| class TSpeseCSV : public TSkeleton_application
 | ||
| {
 | ||
| 	virtual bool check_autorization() const {return false;}
 | ||
|   virtual const char * extra_modules() const {return "ve";}
 | ||
| 
 | ||
| protected:
 | ||
|   void chiudi_movimento(TConfig& configfile, TImporto& tot_doc, TDate& data);
 | ||
| 
 | ||
| public:           
 | ||
|   virtual void main_loop();
 | ||
| 	bool transfer(const TMask& msk);
 | ||
|  
 | ||
|   TSpeseCSV() {};
 | ||
| };
 | ||
| 
 | ||
| const char* const nomeini = "ps0713500ats.ini";  //non si conosce il perch<63>
 | ||
| 
 | ||
| void TSpeseCSV::chiudi_movimento(TConfig& configfile, TImporto& tot_doc, TDate& data)
 | ||
| {
 | ||
|   //aggiungo i campi che mancano in testata
 | ||
|   configfile.set_paragraph("23");
 | ||
|   configfile.set(MOV_DATAREG, data);
 | ||
|   configfile.set(MOV_DATADOC, data);
 | ||
|   configfile.set(MOV_DATACOMP, data);
 | ||
| 
 | ||
| 	tot_doc.normalize();
 | ||
| 
 | ||
|   //aggiungo la prima riga che bilancia le righe successive
 | ||
| 	TString8 paragraph;
 | ||
|   paragraph.format("%d,%d",LF_RMOV,1);
 | ||
| 	configfile.set_paragraph(paragraph);  
 | ||
| 	configfile.set(RMV_IMPORTO,tot_doc.valore().string());
 | ||
|   configfile.set(RMV_SEZIONE,tot_doc.sezione());
 | ||
| 
 | ||
|   configfile.set_paragraph("Transaction");
 | ||
|   
 | ||
|   TString app;
 | ||
|   app << "cg2 -0 -i" << nomeini; 
 | ||
|   TExternal_app primanota(app);
 | ||
|   primanota.run();
 | ||
| }
 | ||
| 
 | ||
| bool TSpeseCSV::transfer(const TMask& msk)
 | ||
| {
 | ||
|   //genero il nome del file da caricare
 | ||
|   TFilename name = msk.get(F_PATH);
 | ||
|   name.add(msk.get(F_NAME));
 | ||
|   TImporta_spese_recordset s(name);
 | ||
| 
 | ||
|   TProgind pi(s.items(),"Importazione spese in corso ...",true,true);
 | ||
| 
 | ||
|   xvt_fsys_removefile(nomeini);
 | ||
|   TConfig configfile (nomeini, "Transaction");  //setto il paragrafo [Transaction] del file ini 
 | ||
| 
 | ||
|   TDate dataold, data;
 | ||
| 
 | ||
|   int nriga = 2;
 | ||
|   TImporto tot_doc;
 | ||
| 
 | ||
|   const TRectype& causale = cache().get(LF_RCAUSALI, msk.get(F_CODCAU));
 | ||
| 
 | ||
| 
 | ||
|   for (bool ok=s.move_first();ok;ok=s.move_next())
 | ||
|   {
 | ||
|     if (!pi.addstatus(1)) 
 | ||
|       break;
 | ||
|     
 | ||
|     
 | ||
| 	  TString80 tmp;
 | ||
| 
 | ||
|     //importo
 | ||
| 	  tmp = s.get(2).as_string();
 | ||
| 
 | ||
|     //evito di analizzare eventuali righe vuote
 | ||
|     if (tmp.blank())
 | ||
|       continue;
 | ||
| 
 | ||
|     tmp.replace(',','.');
 | ||
|     tmp.strip("\"");
 | ||
|     const real imp = tmp;
 | ||
| 
 | ||
|     if (!imp.is_zero())
 | ||
|     {
 | ||
|       
 | ||
|       //codice commessa
 | ||
| 	    tmp = s.get(0).as_string();
 | ||
|       tmp.strip("\"");
 | ||
| 
 | ||
|       const TRectype& commessa = cache().get("CMS", tmp);
 | ||
| 
 | ||
| 	    //data
 | ||
| 	    tmp = s.get(1).as_string();    
 | ||
|       tmp.strip("\"");
 | ||
| 	    
 | ||
| 	    data.set_day(atoi(tmp.mid(0,2)));
 | ||
| 	    data.set_month(atoi(tmp.mid(3,2)));
 | ||
| 	    data.set_year(atoi(tmp.mid(6,4)));
 | ||
|       
 | ||
|       //descrizione
 | ||
| 	    tmp = s.get(3).as_string();    
 | ||
|       tmp.strip("\"");
 | ||
| 
 | ||
| 	    if(data != dataold)
 | ||
| 		  {
 | ||
|         if (dataold.ok())
 | ||
|           chiudi_movimento(configfile, tot_doc, data);
 | ||
| 
 | ||
| 				TFilename filename(nomeini);
 | ||
| 				filename.fremove();
 | ||
| 
 | ||
|         configfile.set_paragraph("Transaction");
 | ||
|         configfile.set("Action","INSERT");
 | ||
|         configfile.set("Mode","AUTO");
 | ||
|         
 | ||
|         configfile.set_paragraph("23"); //setto il paragrafo [23] del file ini (testata)
 | ||
|         configfile.set(MOV_CODCAUS, causale.get(RCA_CODCAUS));
 | ||
|   
 | ||
|         configfile.set_paragraph("24,1");
 | ||
|         configfile.set(RMV_NUMRIG,1);
 | ||
|         configfile.set(RMV_GRUPPO, causale.get(RCA_GRUPPO));
 | ||
|         configfile.set(RMV_CONTO, causale.get(RCA_CONTO));
 | ||
|         configfile.set(RMV_SOTTOCONTO, causale.get(RCA_SOTTOCONTO));
 | ||
| 
 | ||
| 			  tot_doc.reset();
 | ||
|         nriga = 2;
 | ||
|         dataold = data;
 | ||
|       }
 | ||
| 
 | ||
| 	    TImporto importo('D', imp);
 | ||
| 	    importo.normalize();
 | ||
|       tot_doc -= importo;
 | ||
| 		  
 | ||
| 	    TString8 paragraph;
 | ||
|       paragraph.format("%d,%d",LF_RMOV,nriga++);
 | ||
|       configfile.set_paragraph(paragraph);
 | ||
| 
 | ||
|       configfile.set(RMV_IMPORTO,importo.valore().string());
 | ||
|       configfile.set(RMV_SEZIONE,importo.sezione());
 | ||
|       configfile.set(RMV_CODCMS,commessa.get("CODTAB"));
 | ||
|       configfile.set(RMV_DATAREG,data);
 | ||
|       configfile.set(RMV_GRUPPO,commessa.get("I1"));
 | ||
|       configfile.set(RMV_CONTO,commessa.get("I2"));
 | ||
|       configfile.set(RMV_SOTTOCONTO,commessa.get("I3"));
 | ||
|     }
 | ||
| 
 | ||
|   }
 | ||
| 
 | ||
|   chiudi_movimento(configfile, tot_doc, data);
 | ||
|     
 | ||
|   return true;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void TSpeseCSV::main_loop()
 | ||
| {
 | ||
|   TImportaSpese_mask msk;
 | ||
| 	
 | ||
|   if (msk.run() == K_ENTER)
 | ||
|   {		
 | ||
| 		if (transfer(msk))
 | ||
| 		{
 | ||
|       message_box(TR("Importazione spese completata"));
 | ||
|       xvt_fsys_removefile(nomeini);
 | ||
| 		}
 | ||
|   }   
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| TSpeseCSV& app() { return (TSpeseCSV&) main_app(); }
 | ||
| 
 | ||
| 
 | ||
| int ps0713500 (int argc, char* argv[])
 | ||
| {
 | ||
|   TSpeseCSV main_app;
 | ||
|   main_app.run(argc, argv, TR("Importazione Spese"));
 | ||
|   return true;
 | ||
| } |