Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/branches/R_10_00@21342 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			385 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			385 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "halib.h"
 | 
						|
#include "hacnvlib.h"
 | 
						|
#include "hacnv200a.h"
 | 
						|
 | 
						|
#include <applicat.h>
 | 
						|
#include <automask.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <execp.h>
 | 
						|
#include <progind.h>
 | 
						|
#include <reprint.h>
 | 
						|
#include <reputils.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include <mov.h>
 | 
						|
#include <rmov.h>
 | 
						|
#include <rmoviva.h>
 | 
						|
 | 
						|
const char* const APPNAME = TR("Conversione movimenti"); 
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Movimenti
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class THardy_movimenti : public THardy_transfer
 | 
						|
{
 | 
						|
  int _anno;
 | 
						|
  TDate _dadata, _adata;
 | 
						|
  TConfig* _conf;
 | 
						|
  long _kmovcont;
 | 
						|
protected:
 | 
						|
  bool trasferisci_righe();
 | 
						|
  bool trasferisci_righeiva();
 | 
						|
public:
 | 
						|
  virtual bool trasferisci();
 | 
						|
  THardy_movimenti(const int anno, const TDate dadata, const TDate adata);
 | 
						|
};
 | 
						|
 | 
						|
bool THardy_movimenti::trasferisci_righeiva()
 | 
						|
{
 | 
						|
  TString_array lista_campi_righeiva;
 | 
						|
  TConfig& ini = config();
 | 
						|
	ini.list_variables(lista_campi_righeiva, true, "RMOVIVA", true);
 | 
						|
  TString query;
 | 
						|
  query << query_header();
 | 
						|
  query << "SELECT * "
 | 
						|
	         "FROM dbo.MovIvaT "
 | 
						|
           "WHERE KMovconT=";
 | 
						|
  query << _kmovcont;
 | 
						|
  TODBC_recordset recset(query);
 | 
						|
  bool is_iva = (recset.items() > 0);
 | 
						|
  if (is_iva)
 | 
						|
  {
 | 
						|
    bool ok=recset.move_first();
 | 
						|
    if (ok)
 | 
						|
    {
 | 
						|
      // aggiorna_testata movimento già scritta su ini con i nuovi dati di testata
 | 
						|
    }
 | 
						|
    // aggiungo le righe iva
 | 
						|
    long kregivat = recset.get("KRegivaT").as_int();
 | 
						|
    TString query_righe;
 | 
						|
    query_righe << query_header();
 | 
						|
    query_righe << "SELECT * "
 | 
						|
	           "FROM dbo.MovIva "
 | 
						|
             "WHERE KRegivaT=";
 | 
						|
    query_righe << kregivat;
 | 
						|
    TODBC_recordset recset_righe(query_righe);
 | 
						|
 	  TString paragraph;
 | 
						|
	  int nrigac = 1;
 | 
						|
    for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next())
 | 
						|
    {
 | 
						|
	    paragraph.format("%d,%d",LF_RMOVIVA,nrigac++);
 | 
						|
		  _conf->set_paragraph(paragraph);
 | 
						|
      aggiorna_ini(*_conf, lista_campi_righeiva);
 | 
						|
 | 
						|
      // calcolo dei campi non importabili direttamente
 | 
						|
      TString4 sezione = "D";
 | 
						|
		  TImporto imponibile(sezione[0], recset_righe.get("Imponibile").as_real());
 | 
						|
		  TImporto imposta(sezione[0], recset_righe.get("Imposta").as_real());
 | 
						|
      _conf->set(RMI_IMPONIBILE, imponibile.valore().string(0,2)) ;
 | 
						|
      _conf->set(RMI_IMPOSTA, imposta.valore().string(0,2));
 | 
						|
      const TString& key = recset_righe.get("IdConto").as_string(); 
 | 
						|
      TString4 tipoc = recset_righe.get("IdContoTp").as_string();
 | 
						|
      const char tipocc = tipoc[0];
 | 
						|
      int gr, co;
 | 
						|
      long so;
 | 
						|
      switch (tipocc)
 | 
						|
      {      
 | 
						|
      case 'S':
 | 
						|
        {
 | 
						|
          tipoc = " ";
 | 
						|
          gr = atoi(key.mid(1,2));
 | 
						|
          co = atoi(key.mid(3,2));
 | 
						|
          so = atoi(key.mid(5,3));
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      case 'C':
 | 
						|
        {       
 | 
						|
          tipoc = "C";
 | 
						|
          gr = ini.get_int("CLI_GRUPPO", "Mastri");
 | 
						|
          co = ini.get_int("CLI_CONTO", "Mastri");
 | 
						|
          so = hd_key2cli(key);
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      case 'F':
 | 
						|
        {
 | 
						|
          tipoc = "F";
 | 
						|
          gr = ini.get_int("FOR_GRUPPO", "Mastri");
 | 
						|
          co = ini.get_int("FOR_CONTO", "Mastri");
 | 
						|
          so = hd_key2forn(key);
 | 
						|
        }
 | 
						|
        break;
 | 
						|
      default:
 | 
						|
        break;
 | 
						|
      }
 | 
						|
      _conf->set(RMI_TIPOC, tipoc);
 | 
						|
      _conf->set(RMI_GRUPPO, gr);
 | 
						|
      _conf->set(RMI_CONTO, co);
 | 
						|
      _conf->set(RMI_SOTTOCONTO, so);
 | 
						|
    } 
 | 
						|
  }
 | 
						|
  return is_iva;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool THardy_movimenti::trasferisci_righe()
 | 
						|
{
 | 
						|
  TString_array lista_campi_righe;
 | 
						|
  TConfig& ini = config();
 | 
						|
	ini.list_variables(lista_campi_righe, true, "RMOV", true);
 | 
						|
  TString query_righe;
 | 
						|
  query_righe << query_header();
 | 
						|
  query_righe << "SELECT * "
 | 
						|
	         "FROM dbo.MovContabili "
 | 
						|
           "WHERE KMovconT=";
 | 
						|
  query_righe << _kmovcont;
 | 
						|
  TODBC_recordset recset_righe(query_righe);
 | 
						|
 	TString paragraph;
 | 
						|
	int nrigac = 1;
 | 
						|
  for (bool ok=recset_righe.move_first();ok;ok=recset_righe.move_next())
 | 
						|
  {
 | 
						|
	  paragraph.format("%d,%d",LF_RMOV,nrigac++);
 | 
						|
		_conf->set_paragraph(paragraph);
 | 
						|
    aggiorna_ini(*_conf, lista_campi_righe);
 | 
						|
 | 
						|
    // calcolo dei campi non importabili direttamente
 | 
						|
    TString4 sezione = "D";
 | 
						|
		TImporto imp_dare(sezione[0], recset_righe.get("Dare").as_real());
 | 
						|
		TImporto imp_avere(sezione[0], recset_righe.get("Avere").as_real());
 | 
						|
    if (imp_dare.is_zero())
 | 
						|
      sezione = "A";
 | 
						|
    _conf->set(RMV_SEZIONE, sezione);
 | 
						|
    _conf->set(RMV_IMPORTO, (imp_avere.is_zero() ? imp_dare.valore().string(0,2) : imp_avere.valore().string(0,2)));
 | 
						|
    const TString& key = recset_righe.get("IdConto").as_string(); 
 | 
						|
    TString4 tipoc = recset_righe.get("IdContoTp").as_string();
 | 
						|
    const char tipocc = tipoc[0];
 | 
						|
    int gr, co;
 | 
						|
    long so;
 | 
						|
    switch (tipocc)
 | 
						|
    {      
 | 
						|
    case 'S':
 | 
						|
      {
 | 
						|
        tipoc = " ";
 | 
						|
        gr = atoi(key.mid(1,2));
 | 
						|
        co = atoi(key.mid(3,2));
 | 
						|
        so = atoi(key.mid(5,3));
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case 'C':
 | 
						|
      {       
 | 
						|
        tipoc = "C";
 | 
						|
        gr = ini.get_int("CLI_GRUPPO", "Mastri");
 | 
						|
        co = ini.get_int("CLI_CONTO", "Mastri");
 | 
						|
        so = hd_key2cli(key);
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    case 'F':
 | 
						|
      {
 | 
						|
        tipoc = "F";
 | 
						|
        gr = ini.get_int("FOR_GRUPPO", "Mastri");
 | 
						|
        co = ini.get_int("FOR_CONTO", "Mastri");
 | 
						|
        so = hd_key2forn(key);
 | 
						|
      }
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      break;
 | 
						|
    }
 | 
						|
    _conf->set(RMV_TIPOC, tipoc);
 | 
						|
    _conf->set(RMV_GRUPPO, gr);
 | 
						|
    _conf->set(RMV_CONTO, co);
 | 
						|
    _conf->set(RMV_SOTTOCONTO, so);
 | 
						|
  } 
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool THardy_movimenti::trasferisci()
 | 
						|
{
 | 
						|
  TString16 dastr, astr;
 | 
						|
  dastr.format("%4d-%2d-%2d", _dadata.year(), _dadata.month(), _dadata.day());
 | 
						|
  astr.format("%4d-%2d-%2d", _adata.year(), _adata.month(), _adata.day());
 | 
						|
 | 
						|
  TString query = 
 | 
						|
    "SELECT * "
 | 
						|
		"FROM dbo.MovContabiliT "
 | 
						|
    "WHERE Esercizio=";
 | 
						|
  query << _anno;
 | 
						|
  query << " AND DataMovimento>= '";
 | 
						|
  query << dastr;
 | 
						|
  query << "' AND DataMovimento<= '";
 | 
						|
  query << astr;
 | 
						|
  query << "' ORDER BY DataMovimento ";
 | 
						|
 | 
						|
  TRecordset& recset = create_recordset(query);
 | 
						|
  TConfig& ini = config();
 | 
						|
	
 | 
						|
  TString_array lista_campi;
 | 
						|
	ini.list_variables(lista_campi, true, "MOV", true);
 | 
						|
 | 
						|
  TFilename outdir;
 | 
						|
  outdir = ini.get("PATH", "Main");
 | 
						|
	TString80 listfiles = outdir;
 | 
						|
	listfiles << "\\ha*.ini";
 | 
						|
	TString_array transactions;
 | 
						|
  list_files(listfiles, transactions);
 | 
						|
  FOR_EACH_ARRAY_ROW(transactions, row, name)
 | 
						|
    remove(*name);
 | 
						|
 | 
						|
  _conf = NULL;
 | 
						|
	long ntran = 1L;
 | 
						|
 	TString paragraph;
 | 
						|
 | 
						|
  THardy_iterator hi(this);
 | 
						|
  while (++hi)
 | 
						|
  {
 | 
						|
    _kmovcont = recset.get("KMovconT").as_int();
 | 
						|
	  if (_conf != NULL)
 | 
						|
			  delete _conf;
 | 
						|
	  _conf = NULL;
 | 
						|
	  TFilename temp(outdir);
 | 
						|
	  temp.add(format("ha%06ld", ntran++));
 | 
						|
	  temp.ext("ini");
 | 
						|
	  if (temp.exist())
 | 
						|
      temp.fremove();
 | 
						|
	  _conf = new TConfig(temp);
 | 
						|
	  _conf->set_paragraph("Transaction");
 | 
						|
	  _conf->set("Action","INSERT");
 | 
						|
	  _conf->set("Mode", "AUTO");
 | 
						|
    paragraph.format("%d",LF_MOV);
 | 
						|
	  _conf->set_paragraph(paragraph); // testata movimento
 | 
						|
    aggiorna_ini(*_conf, lista_campi);
 | 
						|
    // righe movimento
 | 
						|
    trasferisci_righe();
 | 
						|
    bool iva = trasferisci_righeiva();
 | 
						|
		TString msg;
 | 
						|
    msg << (iva ? TR("Movimento contabile "): TR("Movimento iva ")) << _kmovcont << " generato nel file " << temp;
 | 
						|
  	log(msg);
 | 
						|
  }
 | 
						|
	if (_conf != NULL)
 | 
						|
		delete _conf;
 | 
						|
	if (yesno_box(FR("Si desidera confermare l'importazione di %ld movimenti"), ntran-1))
 | 
						|
	{
 | 
						|
		TString app;
 | 
						|
		app << "cg2 -0 -i" << outdir << "/ha*.ini"; 
 | 
						|
		TExternal_app primanota(app);
 | 
						|
		primanota.run(true);
 | 
						|
	}
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
THardy_movimenti::THardy_movimenti(const int anno, const TDate dadata, const TDate adata) : _anno(anno), _dadata(dadata), _adata(adata)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TConvMovimentiHardy_mask
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TConvMovimentiHardy_mask : public TAutomask
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
  void serialize(bool bSave);
 | 
						|
 | 
						|
public:
 | 
						|
  void trasferisci();
 | 
						|
 | 
						|
  TConvMovimentiHardy_mask();
 | 
						|
  virtual ~TConvMovimentiHardy_mask();
 | 
						|
};
 | 
						|
 | 
						|
// Funzione di trasferimento dati da/verso file .ini con lo stesso nome della maschera
 | 
						|
// Andrebbe messo in libreria
 | 
						|
void TConvMovimentiHardy_mask::serialize(bool bSave)
 | 
						|
{
 | 
						|
  TFilename n = source_file(); n.ext("ini");  // Construisce il nome del .ini in base al .msk
 | 
						|
  TConfig cfg(n, "Main");                     // Crea il file di configurazione
 | 
						|
  TString4 id; 
 | 
						|
  for (int i = fields()-1; i >= 0; i--)       // Scandisce tutti i campi della maschera ...   
 | 
						|
  {
 | 
						|
    TMask_field& f = fld(i);
 | 
						|
    if (f.active() && f.is_loadable())        // ... selezionando solo quelli editabili
 | 
						|
    {
 | 
						|
      id.format("%d", f.dlg());
 | 
						|
      if (bSave)                              // A seconda del flag di scrittura ... 
 | 
						|
        cfg.set(id, f.get());                 // ... o scrive sul .ini 
 | 
						|
      else 
 | 
						|
        f.set(cfg.get(id));                   // ... o legge dal .ini
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TConvMovimentiHardy_mask::trasferisci()
 | 
						|
{
 | 
						|
  TString query_header;
 | 
						|
  query_header << "ODBC(" << get(F_DSN) << ',' << get(F_USR) << ',' << get(F_PWD) << ")\n";
 | 
						|
 | 
						|
  TReport_book book;
 | 
						|
  THardy_log log;
 | 
						|
 | 
						|
  bool rep_to_print = false;
 | 
						|
  bool go_on = true;
 | 
						|
 | 
						|
  const int anno = get_int(F_ANNO);
 | 
						|
  const TDate dadata = get_date(F_DADATA);
 | 
						|
  const TDate adata = get_date(F_ADATA);
 | 
						|
  if (go_on && (anno!=0))
 | 
						|
  {
 | 
						|
    THardy_movimenti pc(anno, dadata, adata);
 | 
						|
    pc.init(TR("Movimenti contabili"), query_header, log);
 | 
						|
    go_on = pc.trasferisci();
 | 
						|
    book.add(log);
 | 
						|
		rep_to_print = true;
 | 
						|
  }
 | 
						|
  if (rep_to_print && book.pages() > 0)
 | 
						|
		book.preview();
 | 
						|
}
 | 
						|
 | 
						|
bool TConvMovimentiHardy_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
  case DLG_OK:
 | 
						|
    if (e == fe_button)
 | 
						|
      serialize(true);
 | 
						|
    break;
 | 
						|
  default:
 | 
						|
    break;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
TConvMovimentiHardy_mask::TConvMovimentiHardy_mask() : TAutomask("hacnv200a")
 | 
						|
{
 | 
						|
  serialize(false);
 | 
						|
}
 | 
						|
 | 
						|
TConvMovimentiHardy_mask::~TConvMovimentiHardy_mask()
 | 
						|
{ 
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TConvMovimentiHardy
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TConvMovimentiHardy : public TSkeleton_application
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual void main_loop();
 | 
						|
};
 | 
						|
 | 
						|
void TConvMovimentiHardy::main_loop()
 | 
						|
{
 | 
						|
  TConvMovimentiHardy_mask mask;
 | 
						|
  while (mask.run() == K_ENTER)
 | 
						|
    mask.trasferisci();
 | 
						|
}
 | 
						|
 | 
						|
int hacnv200(int argc, char* argv[])
 | 
						|
{
 | 
						|
  TConvMovimentiHardy ih;
 | 
						|
  ih.run(argc, argv, APPNAME);
 | 
						|
  return 0;
 | 
						|
}
 | 
						|
 |