Files correlati : pd6342 pd6342200a.msk Ricompilazione Demo : [ ] Commento : Agguinto importatore movimenti di analitica git-svn-id: svn://10.65.10.50/branches/R_10_00@20849 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			221 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			221 lines
		
	
	
		
			5.6 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <progind.h>
 | 
						|
#include <recset.h>
 | 
						|
#include <textset.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "pd6342.h"
 | 
						|
#include "pd6342200a.h"
 | 
						|
 | 
						|
#include "../ca/movana.h"
 | 
						|
#include "../ca/rmovana.h"
 | 
						|
#include "../ca/calib01.h"
 | 
						|
#include "../ca/calib02.h"
 | 
						|
 | 
						|
class TImporta_da_BCS_rec : public TAS400_recordset
 | 
						|
{
 | 
						|
public:
 | 
						|
	TImporta_da_BCS_rec(const char* filename);
 | 
						|
};
 | 
						|
 | 
						|
TImporta_da_BCS_rec::TImporta_da_BCS_rec(const char* filename)
 | 
						|
                   : TAS400_recordset(TString("AS400(121,0,0)\n") << filename)
 | 
						|
{
 | 
						|
	create_field("ANNO",     -1, 4,  _intfld);                //anno di competenza
 | 
						|
  create_field("MESE",     -1, 2,  _intfld);                //mese di competenza
 | 
						|
  create_field("GIORNO",   -1, 2,  _intfld);                //giorno di competenza
 | 
						|
	create_field("CODCOSTO", -1, 15, _alfafld);               //centro di costo
 | 
						|
  create_field("PCONTI",   -1, 15, _alfafld);               //centro di ricavo (o piano dei conti)
 | 
						|
	create_field("IMPORTO",  -1, 12, _realfld);               //importo lordo della prestazione moltiplicato per quantità
 | 
						|
	create_field("SEGNO",    -1, 1,  _alfafld);               //segno importo (+ o -)
 | 
						|
	create_field("PROV",     -1, 3,  _alfafld, true, "FAT");  //provenienza (valore fisso FAT)
 | 
						|
	create_field("IDPROC",   -1, 15, _alfafld);               //ID della procedura inviante
 | 
						|
	create_field("CODPRES",  -1, 8,  _alfafld);               //codice della prestazione
 | 
						|
  create_field("DESPRES",  -1, 40, _alfafld);               //descrizione della prestazione
 | 
						|
}
 | 
						|
 | 
						|
static int sort_by_date(const TObject** o1, const TObject** o2)
 | 
						|
{
 | 
						|
  const TString& r1 = *(TString*)*o1;
 | 
						|
  const TString& r2 = *(TString*)*o2;
 | 
						|
 | 
						|
  const long d1 = atol(r1.left(8));
 | 
						|
  const long d2 = atol(r2.left(8));
 | 
						|
 | 
						|
  return d1 - d2;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
//  MASCHERA
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
class TImporta_da_BCS_msk : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
 | 
						|
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly); 
 | 
						|
	
 | 
						|
public:
 | 
						|
  TImporta_da_BCS_msk();
 | 
						|
  virtual ~TImporta_da_BCS_msk() {}
 | 
						|
};
 | 
						|
 | 
						|
bool TImporta_da_BCS_msk::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  /*switch(o.dlg())
 | 
						|
  {
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }*/
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
TImporta_da_BCS_msk::TImporta_da_BCS_msk() : TAutomask("pd6342200a")
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// APPLICAZIONE
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TImporta_da_BCS_app : public TSkeleton_application
 | 
						|
{
 | 
						|
  TImporta_da_BCS_msk* _mask;
 | 
						|
  bool _has_ca;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool check_autorization() const {return false;}
 | 
						|
  virtual const char * extra_modules() const {return "ca";}
 | 
						|
 | 
						|
  void sposta_file(const TString& file);
 | 
						|
  void genera_movana(TImporta_da_BCS_rec& recset);
 | 
						|
  bool elabora();
 | 
						|
 | 
						|
public:
 | 
						|
  virtual void main_loop();
 | 
						|
 | 
						|
};
 | 
						|
 | 
						|
void TImporta_da_BCS_app::sposta_file(const TString& file)
 | 
						|
{
 | 
						|
  TFilename fileori = file;
 | 
						|
  TFilename path = fileori.path();
 | 
						|
  path.add("elaborati");
 | 
						|
  make_dir(path);
 | 
						|
 | 
						|
  TString strname;
 | 
						|
  strname.format("%06d_%06d_%s", TDate(TODAY).date2ansi(), daytime(), (const char*)fileori.name());  
 | 
						|
  TFilename filedest = path;
 | 
						|
  filedest.add(strname);
 | 
						|
  
 | 
						|
  //se la copia è andata a buon fine, creo un file .old vuoto e cancello il file .dat
 | 
						|
  if (fcopy(fileori, filedest))
 | 
						|
  {
 | 
						|
    TFilename fileold;
 | 
						|
    fileold = fileori.path();
 | 
						|
 | 
						|
    TString strn = fileori.name_only();
 | 
						|
    strn << ".old";
 | 
						|
 | 
						|
    fileold.add(strn);
 | 
						|
 | 
						|
    fclose(fopen(fileold, "w"));   
 | 
						|
 | 
						|
    fileori.fremove();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TImporta_da_BCS_app::genera_movana(TImporta_da_BCS_rec& recset)
 | 
						|
{
 | 
						|
  TLocalisamfile fmov(LF_MOVANA);
 | 
						|
  
 | 
						|
  TDate dataold(NULLDATE);
 | 
						|
  
 | 
						|
  const TDate oggi(TODAY);
 | 
						|
  const TString4 codcau = "CAUS";
 | 
						|
 | 
						|
  TAnal_mov ana(0);
 | 
						|
 | 
						|
  //TProgind pi(recset.items(), "Importazione in corso...", true, true);
 | 
						|
 | 
						|
  for(bool ok = recset.move_first(); ok; ok = recset.move_next());
 | 
						|
  {
 | 
						|
    //if (!pi.addstatus(1)) 
 | 
						|
		  //break;
 | 
						|
 | 
						|
    const int anno = recset.get("ANNO").as_int();
 | 
						|
    const TDate data(recset.get("GIORNO").as_int(), recset.get("MESE").as_int(), anno);
 | 
						|
 | 
						|
    if(data != dataold)
 | 
						|
    {
 | 
						|
      ana.rewrite_write(fmov);
 | 
						|
      
 | 
						|
      ana.zero();
 | 
						|
      ana.put(MOVANA_ANNOES,   anno);
 | 
						|
      ana.put(MOVANA_DATAREG,  oggi);
 | 
						|
      ana.put(MOVANA_DATACOMP, data);
 | 
						|
      ana.put(MOVANA_CODCAUS,  codcau);
 | 
						|
 | 
						|
      dataold = data;
 | 
						|
    }
 | 
						|
 | 
						|
    TRectype& riga = ana.new_row();
 | 
						|
 | 
						|
    TString16 impstr;
 | 
						|
    impstr << recset.get("SEGNO").as_string()[0] << recset.get("IMPORTO").as_string();
 | 
						|
    const real imp(impstr);
 | 
						|
 | 
						|
    TImporto importo('A', imp);
 | 
						|
    importo.normalize();
 | 
						|
 | 
						|
    TString80 descrizione;
 | 
						|
    descrizione << recset.get("CODPRES").as_string() << '-' << recset.get("DESPRES").as_string();
 | 
						|
 | 
						|
    riga.put(RMOVANA_ANNOES, anno);
 | 
						|
    riga.put(RMOVANA_SEZIONE, importo.sezione());
 | 
						|
    riga.put(RMOVANA_DATACOMP, data);
 | 
						|
    riga.put(RMOVANA_CODCCOSTO, recset.get("CODCOSTO").as_string());
 | 
						|
    riga.put(RMOVANA_CODCONTO, recset.get("PCONTI").as_string());
 | 
						|
    riga.put(RMOVANA_DESCR, descrizione);
 | 
						|
    riga.put(RMOVANA_IMPORTO, importo.valore());
 | 
						|
  }
 | 
						|
  ana.rewrite_write(fmov);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TImporta_da_BCS_app::elabora()
 | 
						|
{
 | 
						|
  TFilename file = _mask->get(F_FILE);
 | 
						|
 
 | 
						|
  TFilename filename = _mask->get(F_PATH);
 | 
						|
  filename << file.name();
 | 
						|
  
 | 
						|
  TImporta_da_BCS_rec recset(filename);
 | 
						|
  recset.sort(sort_by_date);
 | 
						|
  genera_movana(recset);
 | 
						|
 | 
						|
  sposta_file(filename);
 | 
						|
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
 | 
						|
void TImporta_da_BCS_app::main_loop()
 | 
						|
{
 | 
						|
 | 
						|
  _mask = new TImporta_da_BCS_msk;
 | 
						|
	
 | 
						|
  if (_mask->run() == K_ENTER)
 | 
						|
  {		
 | 
						|
		if (elabora())
 | 
						|
		  message_box(TR("Importazione righe terminata"));
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int pd6342200(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TImporta_da_BCS_app imp_anal;
 | 
						|
  imp_anal.run(argc, argv, TR("Importa Movimenti Analitici"));
 | 
						|
  return 0;
 | 
						|
} |