Files correlati : ps0713 e tutte le maschere Ricompilazione Demo : [ ] Commento : Portato sulla 10.0 il ps dell'ATS con prevista l'analitica git-svn-id: svn://10.65.10.50/trunk@20447 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			313 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			313 lines
		
	
	
		
			8.4 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <execp.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <textset.h>
 | 
						|
 | 
						|
#include <causali.h>
 | 
						|
#include <clifo.h>
 | 
						|
#include <mov.h>
 | 
						|
#include <rmoviva.h>
 | 
						|
 | 
						|
#include "../ca/calib01.h"
 | 
						|
#include "../ca/calib02.h"
 | 
						|
#include "../ca/movana.h"
 | 
						|
#include "../ca/rmovana.h"
 | 
						|
 | 
						|
#include "ps0713300a.h"
 | 
						|
 | 
						|
                                 //////////////////////////////////////
 | 
						|
                                 ////    TIMPORTA_FATACQ_ANROW    ////
 | 
						|
                                 //////////////////////////////////////
 | 
						|
 | 
						|
//classe TImporta_fatacq_anrow
 | 
						|
class TImporta_fatacq_anrow: public TToken_string
 | 
						|
{
 | 
						|
public:
 | 
						|
  const long idlavoro();
 | 
						|
  const int  gruppo();
 | 
						|
  const int  conto();
 | 
						|
  const int  sotco();
 | 
						|
  
 | 
						|
  TImporta_fatacq_anrow& operator= (const char* key){ set(key); return *this; }
 | 
						|
 | 
						|
  TImporta_fatacq_anrow(const long idlavoro, const int gruppo, const int conto, const int sotco);
 | 
						|
  TImporta_fatacq_anrow(const char* key):TToken_string(key){}
 | 
						|
  TImporta_fatacq_anrow(const TToken_string& key):TToken_string(key){}
 | 
						|
  TImporta_fatacq_anrow(const TImporta_fatacq_anrow& key):TToken_string(key){}
 | 
						|
  TImporta_fatacq_anrow():TToken_string(){}
 | 
						|
};
 | 
						|
 | 
						|
//IDLAVORO: metodo che restituisce l'Idlavoro
 | 
						|
const long TImporta_fatacq_anrow::idlavoro()
 | 
						|
{
 | 
						|
  return get_long(0);
 | 
						|
}
 | 
						|
 | 
						|
//GRUPPO: metodo che restituisce il gruppo
 | 
						|
const int TImporta_fatacq_anrow::gruppo()
 | 
						|
{
 | 
						|
  return get_int(1);
 | 
						|
}
 | 
						|
 | 
						|
//CONTO: metodo che restituisce il conto
 | 
						|
const int TImporta_fatacq_anrow::conto()
 | 
						|
{
 | 
						|
  return get_int(2);
 | 
						|
}
 | 
						|
 | 
						|
//SOTCO: metodo che restituisce il sottoconto
 | 
						|
const int TImporta_fatacq_anrow::sotco()
 | 
						|
{
 | 
						|
  return get_int(3);
 | 
						|
}
 | 
						|
 | 
						|
//metodo costruttore
 | 
						|
TImporta_fatacq_anrow::TImporta_fatacq_anrow(const long idlavoro, const int gruppo, const int conto, const int sotco)
 | 
						|
{
 | 
						|
  add(idlavoro);
 | 
						|
  add(gruppo);
 | 
						|
  add(conto);
 | 
						|
  add(sotco);
 | 
						|
}
 | 
						|
 | 
						|
                                 ///////////////////////////////////
 | 
						|
                                 ////    TIMPORTA_FATACQ_MSK    ////
 | 
						|
                                 ///////////////////////////////////
 | 
						|
 | 
						|
//Classe TImporta_fatacq_msk
 | 
						|
class TImporta_fatacq_msk : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
public:
 | 
						|
  TImporta_fatacq_msk();
 | 
						|
};
 | 
						|
  
 | 
						|
TImporta_fatacq_msk::TImporta_fatacq_msk() :TAutomask ("ps0713300a")
 | 
						|
{
 | 
						|
}  
 | 
						|
 | 
						|
//ON_FIELD_EVENT: metodo che gestisce i comportamenti dei vari campi della maschera
 | 
						|
//(per adesso segnaposto)
 | 
						|
bool TImporta_fatacq_msk::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
                                 ///////////////////////////////////
 | 
						|
                                 ////    TIMPORTA_FATACQ_REC    ////
 | 
						|
                                 ///////////////////////////////////  
 | 
						|
 | 
						|
//Classe TImporta_fatacq_rec
 | 
						|
class TImporta_fatacq_rec : public TCSV_recordset
 | 
						|
{
 | 
						|
  public:
 | 
						|
    TImporta_fatacq_rec(const char * fileName);
 | 
						|
};
 | 
						|
 | 
						|
TImporta_fatacq_rec::TImporta_fatacq_rec(const char * fileName)
 | 
						|
                    : TCSV_recordset("CSV(\",\")")
 | 
						|
{
 | 
						|
	load_file(fileName);
 | 
						|
}
 | 
						|
 | 
						|
                                 ///////////////////////////////////
 | 
						|
                                 ////    TIMPORTA_FATACQ_APP    ////
 | 
						|
                                 ///////////////////////////////////
 | 
						|
 | 
						|
//Classe TImporta_fatacq_app
 | 
						|
class TImporta_fatacq_app : public TSkeleton_application
 | 
						|
{
 | 
						|
  TImporta_fatacq_msk*  _msk;
 | 
						|
	TConfig*							_configfile;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool check_autorization() const {return false;}
 | 
						|
  virtual const char * extra_modules() const {return "ve";}
 | 
						|
 | 
						|
public:           
 | 
						|
  virtual bool create();
 | 
						|
  virtual bool destroy();
 | 
						|
  virtual void main_loop();
 | 
						|
  long genera_movcg();
 | 
						|
  void genera_analitica(const long numreg, TAssoc_array& righean);
 | 
						|
	bool transfer(const TFilename& file,  const long numreg, TAssoc_array& righean);
 | 
						|
 
 | 
						|
  TImporta_fatacq_app() {};
 | 
						|
};
 | 
						|
 | 
						|
long TImporta_fatacq_app::genera_movcg()
 | 
						|
{
 | 
						|
  TISAM_recordset movrec("USE MOV");
 | 
						|
  movrec.move_last();
 | 
						|
  long numreg = movrec.get(MOV_NUMREG).as_int(); numreg++;
 | 
						|
 | 
						|
  TLocalisamfile mov(LF_MOV);
 | 
						|
  mov.put(MOV_NUMREG, numreg);  
 | 
						|
  mov.rewrite();
 | 
						|
 | 
						|
  return numreg;
 | 
						|
}
 | 
						|
 | 
						|
void TImporta_fatacq_app::genera_analitica(const long numreg, TAssoc_array& righean)
 | 
						|
{
 | 
						|
  TProgind pi(righean.items(), "Importazione analitica in corso...", true, true);
 | 
						|
 | 
						|
  const TDate datareg = _msk->get_date(F_DATAREG);
 | 
						|
  const int   anno    = _msk->get_date(F_DATAREG).year();
 | 
						|
 | 
						|
  TToken_string key;
 | 
						|
  key.add(_msk->get(F_CODCAU));
 | 
						|
  key.add(1);
 | 
						|
  key.add(1);
 | 
						|
  const TRectype& causale = cache().get(LF_RCAUSALI, key);
 | 
						|
 | 
						|
  //instanzio il movimento di analitica
 | 
						|
  TAnal_mov anmo(0);
 | 
						|
  anmo.put(MOVANA_NUMREGCG, numreg);
 | 
						|
  anmo.put(MOVANA_DATACOMP, datareg);
 | 
						|
  anmo.put(MOVANA_DATAREG,  datareg);
 | 
						|
  anmo.put(MOVANA_CODCAUS,  _msk->get(F_CODCAU));
 | 
						|
  anmo.put(MOVANA_ANNOES,   anno);
 | 
						|
 | 
						|
  //per ogni oggetto dell'assoc_array, creo una riga di analitica
 | 
						|
  FOR_EACH_ASSOC_OBJECT(righean, obj, keyar, itm)
 | 
						|
  {
 | 
						|
    if (!pi.addstatus(1)) 
 | 
						|
		  break;
 | 
						|
 | 
						|
    TImporta_fatacq_anrow& row = (TImporta_fatacq_anrow)keyar;
 | 
						|
    const long idlav  = row.idlavoro();
 | 
						|
    const int  gruppo = row.gruppo();   TString8  grup; grup.format("%03d",  gruppo);
 | 
						|
    const int  conto  = row.conto();    TString8  cont; cont.format("%03d",  conto);
 | 
						|
    const int  sotco  = row.sotco();    TString16 sotc; sotc.format("%06ld", sotco);
 | 
						|
    TString80 codconto; codconto << grup << cont << sotc;
 | 
						|
 | 
						|
    real& imp = *(real*)itm;  imp.round(2);
 | 
						|
		
 | 
						|
		if (!imp.is_zero())
 | 
						|
		{
 | 
						|
      TRectype& ranmo = anmo.new_row();
 | 
						|
      ranmo.put(RMOVANA_ANNOES,   anno);
 | 
						|
      ranmo.put(RMOVANA_SEZIONE,  causale.get("SEZIONE"));
 | 
						|
      ranmo.put(RMOVANA_CODCONTO, codconto);
 | 
						|
      ranmo.put(RMOVANA_CODCMS,   idlav);
 | 
						|
      ranmo.put(RMOVANA_IMPORTO,  imp);
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
bool TImporta_fatacq_app::transfer(const TFilename& file, const long numreg, TAssoc_array& righean)
 | 
						|
{
 | 
						|
  TImporta_fatacq_rec s(file);
 | 
						|
 | 
						|
  TProgind pi(s.items(),"Importazione fatture in corso ...",true,true);
 | 
						|
 | 
						|
  _configfile->set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini  
 | 
						|
  _configfile->set("Action","MODIFY");
 | 
						|
  _configfile->set("Mode","AUTO");
 | 
						|
  _configfile->set_paragraph("23"); //setto il paragrafo [23] del file ini (testata)
 | 
						|
  _configfile->set(MOV_NUMREG, numreg);
 | 
						|
  _configfile->set(MOV_TIPO,"F");
 | 
						|
  _configfile->set(MOV_CODCF, _msk->get(F_CODCF));
 | 
						|
  _configfile->set(MOV_CODCAUS, _msk->get(F_CODCAU));  
 | 
						|
  _configfile->set(MOV_DATAREG, _msk->get(F_DATAREG));
 | 
						|
 | 
						|
  int nriga = 1;
 | 
						|
 | 
						|
  for (bool ok = s.move_first(); ok; ok = s.move_next())
 | 
						|
  {
 | 
						|
    if (!pi.addstatus(1)) 
 | 
						|
      break;
 | 
						|
 | 
						|
    TString8 paragraph;
 | 
						|
    paragraph.format("%d,%d",LF_RMOVIVA,nriga++);
 | 
						|
    _configfile->set_paragraph(paragraph);
 | 
						|
 | 
						|
    TString16 codcom = s.get(0).as_string();
 | 
						|
    real      imp    = s.get(1).as_real();
 | 
						|
 | 
						|
    TTable cms("CMS");
 | 
						|
    cms.put("CODTAB", codcom);
 | 
						|
    int err = cms.read();
 | 
						|
    const int  gruppo = err == NOERR ? cms.get_int("I1") : 0;
 | 
						|
    const int  conto  = err == NOERR ? cms.get_int("I2") : 0;
 | 
						|
    const long sotco  = err == NOERR ? cms.get_int("I3") : 0;
 | 
						|
 | 
						|
    TImporta_fatacq_anrow ankey(atol(codcom), gruppo, conto, sotco);
 | 
						|
 | 
						|
    if(righean.is_key(ankey))
 | 
						|
    {
 | 
						|
      real& imponibile = *(real*)righean.objptr(ankey);
 | 
						|
      imponibile += imp;
 | 
						|
    }
 | 
						|
    else
 | 
						|
      righean.add(ankey, imp);
 | 
						|
 | 
						|
    _configfile->set(RMI_IMPONIBILE, imp.string());
 | 
						|
    _configfile->set(RMI_CODIVA, _msk->get(F_CODIVA));
 | 
						|
    _configfile->set(RMI_CODCMS, codcom);
 | 
						|
  }
 | 
						|
 | 
						|
  _configfile->set_paragraph("Transaction");
 | 
						|
    
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
const char* nomeini = "ps0713300fatt.ini";
 | 
						|
 | 
						|
bool TImporta_fatacq_app::create()
 | 
						|
{
 | 
						|
  xvt_fsys_removefile(nomeini);
 | 
						|
  _configfile = new TConfig(nomeini);
 | 
						|
 | 
						|
  _msk = new TImporta_fatacq_msk();
 | 
						|
         
 | 
						|
  return TSkeleton_application::create();
 | 
						|
}
 | 
						|
 | 
						|
bool TImporta_fatacq_app::destroy()
 | 
						|
{
 | 
						|
	delete _msk;
 | 
						|
	delete _configfile;
 | 
						|
  return TApplication::destroy();
 | 
						|
}
 | 
						|
 | 
						|
void TImporta_fatacq_app::main_loop()
 | 
						|
{
 | 
						|
  KEY	tasto;
 | 
						|
	tasto = _msk->run();
 | 
						|
  if (tasto == K_ENTER)
 | 
						|
  {
 | 
						|
		
 | 
						|
    //genero il nome del file da caricare
 | 
						|
    TFilename name = _msk->get(F_PATH);
 | 
						|
    name.add(_msk->get(F_NAME));
 | 
						|
    TAssoc_array righean;
 | 
						|
    const long numreg = genera_movcg();
 | 
						|
		if (transfer(name, numreg, righean))
 | 
						|
		{
 | 
						|
			genera_analitica(numreg, righean);
 | 
						|
 | 
						|
      TString app;
 | 
						|
      app << "cg2 -0 -i" << nomeini; 
 | 
						|
      TExternal_app primanota(app);
 | 
						|
      primanota.run();
 | 
						|
 | 
						|
      message_box(TR("Importazione fatture completata"));
 | 
						|
		}
 | 
						|
  }   
 | 
						|
}
 | 
						|
 | 
						|
TImporta_fatacq_app& app() { return (TImporta_fatacq_app&) main_app(); }
 | 
						|
 | 
						|
 | 
						|
int ps0713300 (int argc, char* argv[])
 | 
						|
{
 | 
						|
  TImporta_fatacq_app main_app;
 | 
						|
  main_app.run(argc, argv, TR("Importazione Fatture"));
 | 
						|
  return true;
 | 
						|
} |