Files correlati : Ricompilazione Demo : [ ] Commento : git-svn-id: svn://10.65.10.50/trunk@19968 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 <utility.h>
 | 
						||
 | 
						||
#include "../cg/cglib01.h"
 | 
						||
 | 
						||
#include "lv4.h"
 | 
						||
#include "lv4100.h"
 | 
						||
#include "lv4100a.h"
 | 
						||
 | 
						||
#include <pconti.h>
 | 
						||
#include <mov.h>
 | 
						||
#include <rmov.h>
 | 
						||
#include <rmoviva.h>
 | 
						||
 | 
						||
	#define CGC_DITTA_PK						 0		 
 | 
						||
	#define CGC_TIPO								 1
 | 
						||
	#define CGC_GRUPPO							 2
 | 
						||
	#define CGC_CONTO								 3
 | 
						||
	#define CGC_SOTTOCONTO					 4
 | 
						||
	#define CGC_ANNO								 5
 | 
						||
	#define CGC_VALUTA							 6
 | 
						||
	#define CGC_CREAZIONE						 7
 | 
						||
	#define CGC_PROGR_DARE					 8
 | 
						||
	#define CGC_PROGR_AVERE					 9
 | 
						||
	#define CGC_SALDO_APERTURA			10
 | 
						||
	#define CGC_SALDO_CHIUSURA			11
 | 
						||
	#define CGC_ULT_PAG_PART				12
 | 
						||
	#define CGC_DARE_PARTITARIO			13
 | 
						||
	#define CGC_AVERE_PARTITARIO		14
 | 
						||
	#define CGC_DATAAGG_PARTITARIO	15
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TImporta_cogeco_recset
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
real TImporta_cogeco_recset::get_real(int idx) const
 | 
						||
{
 | 
						||
	TString80 imp = get(idx).as_string();
 | 
						||
	imp.strip(".");
 | 
						||
	imp.replace(',', '.');
 | 
						||
	return real(imp);
 | 
						||
}
 | 
						||
 | 
						||
bool TImporta_cogeco_recset::get_bill(TBill& bill, int idx_gruppo) const
 | 
						||
{
 | 
						||
	const int g = get(idx_gruppo).as_int();
 | 
						||
	const int c = get(idx_gruppo+1).as_int();
 | 
						||
	const long s = get(idx_gruppo+2).as_int();
 | 
						||
	bill.set(g, c, s);
 | 
						||
	return bill.ok();
 | 
						||
}
 | 
						||
 | 
						||
TDate TImporta_cogeco_recset::get_date(int idx) const
 | 
						||
{
 | 
						||
  int gg, mm, aaaa;
 | 
						||
  const TString& str = get(idx).as_string();
 | 
						||
  if (sscanf(str, "%2d/%2d/%4d", &gg, &mm, &aaaa) == 3 && gg > 0 && mm > 0 && aaaa > 2000)
 | 
						||
    return TDate(gg, mm, aaaa);
 | 
						||
  return TDate();
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TAutomask
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TImporta_saldi_mask : public TAutomask
 | 
						||
{
 | 
						||
protected:
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
 | 
						||
public:
 | 
						||
  TImporta_saldi_mask();
 | 
						||
};
 | 
						||
  
 | 
						||
TImporta_saldi_mask::TImporta_saldi_mask() :TAutomask ("lv4100a")
 | 
						||
{
 | 
						||
}  
 | 
						||
 | 
						||
bool TImporta_saldi_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("*.txt");	//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;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////
 | 
						||
// TSkeleton_application
 | 
						||
///////////////////////////////////////
 | 
						||
class TImporta_saldi : public TSkeleton_application
 | 
						||
{
 | 
						||
	TImporta_saldi_mask* _msk;
 | 
						||
 | 
						||
protected:
 | 
						||
	void set_rmov(TConfig& conf, const int nrow, const TImporto& imp, 
 | 
						||
								const TBill& bill) const;
 | 
						||
	void delete_ini(const TFilename& outdir) const;
 | 
						||
 | 
						||
public:           
 | 
						||
  virtual bool create();
 | 
						||
  virtual bool destroy();
 | 
						||
  virtual void main_loop();
 | 
						||
	void transfer(const TFilename& file);
 | 
						||
};
 | 
						||
 | 
						||
void TImporta_saldi::set_rmov(TConfig& conf, const int nrow, const TImporto& imp, 
 | 
						||
															const TBill& bill) const
 | 
						||
{
 | 
						||
	TString8 paragraph;
 | 
						||
	paragraph.format("%d,%d", LF_RMOV, nrow);
 | 
						||
	conf.set_paragraph(paragraph);
 | 
						||
 | 
						||
	const char strsez[2] = {imp.sezione(), '\0'};
 | 
						||
	conf.set(RMV_SEZIONE, strsez);
 | 
						||
	conf.set(RMV_IMPORTO, imp.valore().string());
 | 
						||
	conf.set(RMV_GRUPPO, bill.gruppo());
 | 
						||
	conf.set(RMV_CONTO, bill.conto());
 | 
						||
	conf.set(RMV_SOTTOCONTO, bill.sottoconto());
 | 
						||
}
 | 
						||
 | 
						||
void TImporta_saldi::delete_ini(const TFilename& outdir) const
 | 
						||
{
 | 
						||
	if (outdir.exist())
 | 
						||
	{
 | 
						||
		for (int ntran=1;;ntran++)	
 | 
						||
		{
 | 
						||
			TFilename temp(outdir);
 | 
						||
			temp.add(format("lv41%05ld.ini", ntran++));
 | 
						||
			if (!temp.fremove())
 | 
						||
				break;
 | 
						||
		}
 | 
						||
	}
 | 
						||
	else
 | 
						||
		make_dir(outdir);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
void TImporta_saldi::transfer(const TFilename& file)
 | 
						||
{
 | 
						||
	const TFilename outdir(_msk->get(F_PATHOUT));
 | 
						||
  TImporta_cogeco_recset s(file);
 | 
						||
  TProgind pi(s.items(),"Importazione saldi in corso ...",true,true);
 | 
						||
	TConfig * conf = NULL;
 | 
						||
	TFilename filename;
 | 
						||
	long ntran = 1L;
 | 
						||
	int nrow = 1;
 | 
						||
	int anno = 0;
 | 
						||
	TString8 reg;
 | 
						||
	TDate dataop = _msk->get_date(F_DATAMOV);
 | 
						||
	TImporto totmov;
 | 
						||
	TConfig cditta(CONFIG_DITTA, "cg");
 | 
						||
	const TString4 ctypes("GCF");
 | 
						||
	const TString8 causale = cditta.get("CoCaAp");
 | 
						||
	const TBill conto_ap(cditta.get_int("CsBiApG"), 
 | 
						||
		                   cditta.get_int("CsBiApC"), 
 | 
						||
											 cditta.get_long("CsBiApS"));
 | 
						||
 | 
						||
	int lastgruppo = 0;
 | 
						||
	const int codes = _msk->get_int(F_ANNOES);
 | 
						||
	const long ditta = _msk->get_long(F_CODITTA);
 | 
						||
	const TEsercizi_contabili esc;
 | 
						||
 | 
						||
	delete_ini(outdir);
 | 
						||
 | 
						||
  for (bool ok=s.move_to(1);ok;ok=s.move_next())
 | 
						||
  {
 | 
						||
    if (!pi.addstatus(1)) 
 | 
						||
      break;
 | 
						||
		
 | 
						||
		const long dt = s.get(CGC_DITTA_PK).as_int();
 | 
						||
		if (ditta != dt)
 | 
						||
			continue;
 | 
						||
 | 
						||
		const int es = s.get(CGC_ANNO).as_int();
 | 
						||
		if (codes != es)
 | 
						||
			continue;
 | 
						||
 | 
						||
		if (ctypes.find(s.get(CGC_TIPO).as_string()[0]) < 0)
 | 
						||
			continue;
 | 
						||
 | 
						||
		TBill bill; 
 | 
						||
		if (!s.get_bill(bill, CGC_GRUPPO))
 | 
						||
			continue;
 | 
						||
 | 
						||
		if (lastgruppo != bill.gruppo() || nrow >= 99)
 | 
						||
		{
 | 
						||
			if (conf != NULL)
 | 
						||
			{
 | 
						||
				const bool null_mov = (nrow==1);
 | 
						||
				if (!null_mov)
 | 
						||
					set_rmov(*conf, nrow++, totmov, conto_ap);
 | 
						||
				delete conf;
 | 
						||
  			conf = NULL;
 | 
						||
				totmov.reset();
 | 
						||
				if (null_mov)
 | 
						||
				{
 | 
						||
					remove_file(filename);
 | 
						||
					ntran--;
 | 
						||
				}
 | 
						||
			}
 | 
						||
 | 
						||
			filename = outdir;
 | 
						||
			filename.add(format("lv41%05ld.ini", ntran++));
 | 
						||
			conf = new TConfig(filename);
 | 
						||
			conf->set_paragraph("Transaction"); //setto il paragrafo [Transaction] del file ini
 | 
						||
			conf->set("Action","INSERT");
 | 
						||
			conf->set("Mode","AUTO");
 | 
						||
 | 
						||
			conf->set_paragraph("23"); //setto il paragrafo [23] del file ini (testata)
 | 
						||
			conf->set(MOV_CODCAUS, causale);
 | 
						||
			conf->set(MOV_DATAREG, dataop.stringa());
 | 
						||
			conf->set(MOV_DESCR, TR("Ripresa Saldi"));
 | 
						||
			nrow = 1;
 | 
						||
			lastgruppo = bill.gruppo();
 | 
						||
		}
 | 
						||
 | 
						||
		const real val = s.get_real(CGC_SALDO_APERTURA);
 | 
						||
		TImporto impmov(val > ZERO ? 'D' : 'A', abs(val));
 | 
						||
		const TImporto pdare('D', s.get_real(CGC_PROGR_DARE));
 | 
						||
		const TImporto pavere('A',  s.get_real(CGC_PROGR_AVERE));
 | 
						||
 | 
						||
		impmov += pdare;
 | 
						||
		impmov += pavere;
 | 
						||
 | 
						||
		if (!impmov.is_zero())
 | 
						||
		{
 | 
						||
			set_rmov(*conf, nrow++, impmov, bill);
 | 
						||
			totmov -= impmov;
 | 
						||
		}
 | 
						||
	}
 | 
						||
	if (conf != NULL)
 | 
						||
	{
 | 
						||
		const bool null_mov = (nrow==1);
 | 
						||
		if (!null_mov)
 | 
						||
			set_rmov(*conf, nrow++, totmov, conto_ap);
 | 
						||
		delete conf;
 | 
						||
		conf = NULL;
 | 
						||
		totmov.reset();
 | 
						||
		if (null_mov)
 | 
						||
		{
 | 
						||
			remove_file(filename);
 | 
						||
			ntran--;
 | 
						||
		}
 | 
						||
	}
 | 
						||
 | 
						||
	if (yesno_box(FR("Si desidera confermare l'importazione di %ld movimenti"), ntran -1))
 | 
						||
	{
 | 
						||
		TFilename app = outdir;
 | 
						||
		app.add("lv41*.ini"); 
 | 
						||
		app.insert("cg2 -0 -i");
 | 
						||
		TExternal_app primanota(app);
 | 
						||
		primanota.run(true);
 | 
						||
	}
 | 
						||
}
 | 
						||
 | 
						||
bool TImporta_saldi::create()
 | 
						||
{
 | 
						||
  _msk = new TImporta_saldi_mask();       
 | 
						||
  return TSkeleton_application::create();
 | 
						||
}
 | 
						||
 | 
						||
bool TImporta_saldi::destroy()
 | 
						||
{
 | 
						||
	delete _msk;
 | 
						||
  return TApplication::destroy();
 | 
						||
}
 | 
						||
 | 
						||
void TImporta_saldi::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));
 | 
						||
		transfer(name);
 | 
						||
  }   
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
 | 
						||
int lv4100 (int argc, char* argv[])
 | 
						||
{
 | 
						||
  TImporta_saldi main_app;
 | 
						||
  main_app.run(argc, argv, TR("Importazione contabilit<69> COGECO"));
 | 
						||
  return true;
 | 
						||
} |