Files correlati : Ricompilazione Demo : [ ] Commento :riportate modifiche 3.2 git-svn-id: svn://10.65.10.50/trunk@16969 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			291 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			291 lines
		
	
	
		
			7.0 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <execp.h>
 | 
						||
#include <filetext.h>
 | 
						||
#include <progind.h>
 | 
						||
#include <printer.h>
 | 
						||
#include <sort.h>
 | 
						||
#include <utility.h>
 | 
						||
 | 
						||
#include "co0.h"
 | 
						||
#include "co0800a.h"
 | 
						||
#include "colib.h"
 | 
						||
 | 
						||
#include "clifo.h"
 | 
						||
#include "comuni.h"
 | 
						||
#include "doc.h"
 | 
						||
#include "rdoc.h"
 | 
						||
 | 
						||
#include "..\cg\cglib01.h"
 | 
						||
#include "..\ve\velib.h"
 | 
						||
 | 
						||
// TAutomask
 | 
						||
 | 
						||
class TImportazioneConf_mask : public TAutomask
 | 
						||
{
 | 
						||
protected:
 | 
						||
  bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
public:
 | 
						||
  TImportazioneConf_mask();
 | 
						||
  virtual ~TImportazioneConf_mask() {};
 | 
						||
};
 | 
						||
  
 | 
						||
TImportazioneConf_mask::TImportazioneConf_mask() :TAutomask("co0800a")
 | 
						||
{
 | 
						||
}  
 | 
						||
 | 
						||
bool TImportazioneConf_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | 
						||
{ 
 | 
						||
  switch (f.dlg())
 | 
						||
  {                             
 | 
						||
  case F_PERCORSO:
 | 
						||
    if (e == fe_button)
 | 
						||
    {
 | 
						||
			FILE_SPEC fs;
 | 
						||
			
 | 
						||
			memset(&fs, 0, sizeof(FILE_SPEC));
 | 
						||
			strcpy(fs.type, "");
 | 
						||
			strcpy(fs.name, f.get());
 | 
						||
			xvt_fsys_get_default_dir(&fs.dir);
 | 
						||
			xvt_fsys_save_dir();
 | 
						||
			if (xvt_dm_post_file_open(&fs, TR("Selezione file")) == FL_OK)
 | 
						||
			{       
 | 
						||
				TFilename n;
 | 
						||
				xvt_fsys_convert_dir_to_str(&fs.dir, n.get_buffer(n.size()), n.size());
 | 
						||
				n.add(fs.name);
 | 
						||
				f.set(n);
 | 
						||
			}
 | 
						||
			xvt_fsys_restore_dir();
 | 
						||
			f.set_focus();
 | 
						||
    }
 | 
						||
		else
 | 
						||
	    if(e==fe_close)                //se e = alla pressione del bottone 'chiudi' (fe_close) controlla che il campo sia stato
 | 
						||
			{                              //riempito correttamente nella maschera
 | 
						||
				TFilename n=f.get();
 | 
						||
 | 
						||
				return n.exist();
 | 
						||
			}     
 | 
						||
 | 
						||
    break;
 | 
						||
  }  
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
// TSkeleton_application
 | 
						||
 | 
						||
class TImportazioneConf : public TSkeleton_application
 | 
						||
{
 | 
						||
  TRelation*      _rel;
 | 
						||
  TCursor*        _cur;
 | 
						||
  TProgind*       _prog;  
 | 
						||
 | 
						||
public:           
 | 
						||
	virtual bool create();
 | 
						||
  virtual bool destroy();
 | 
						||
  virtual void main_loop();
 | 
						||
  TImportazioneConf() {}
 | 
						||
};
 | 
						||
 | 
						||
TImportazioneConf& app() { return (TImportazioneConf&) main_app(); }
 | 
						||
 | 
						||
bool TImportazioneConf::create()
 | 
						||
{
 | 
						||
  open_files(LF_CLIFO, 0);
 | 
						||
  return TSkeleton_application::create();
 | 
						||
}
 | 
						||
 | 
						||
bool TImportazioneConf::destroy()
 | 
						||
{
 | 
						||
  return TApplication::destroy();
 | 
						||
}
 | 
						||
 | 
						||
void TImportazioneConf::main_loop()
 | 
						||
{  
 | 
						||
	//TConfig configfile("co0800.ini");
 | 
						||
  TImportazioneConf_mask mask;
 | 
						||
	TFilename trecfile;
 | 
						||
 | 
						||
	TConfig confditta(CONFIG_DITTA, "co");
 | 
						||
	const real ritqta = real(confditta.get("RitQta"));
 | 
						||
	const real ritprezzo = real(confditta.get("RitPrezzo"));
 | 
						||
 | 
						||
 | 
						||
  //mask.set(F_PERCORSO,	configfile.get("PERCORSO", "OPZIONI"));
 | 
						||
 | 
						||
  while (mask.run() == K_ENTER)
 | 
						||
  {
 | 
						||
		const TString4 codnum = mask.get(F_CODNUM);
 | 
						||
		const TString4 codtipo = mask.get(F_TIPO);
 | 
						||
		const long codmercato = mask.get_long(F_CODMERCATO);
 | 
						||
		TDocumento_mask m(codtipo);
 | 
						||
		TFilename nomefile = mask.get(F_PERCORSO);
 | 
						||
		TString16 last_cf;
 | 
						||
		TDate last_data;
 | 
						||
		int fcf = -1, fdata = -1;
 | 
						||
		TLocalisamfile clifo(LF_CLIFO);
 | 
						||
 | 
						||
	 	trecfile = "cotr"; trecfile << codmercato;
 | 
						||
		if (!trecfile.custom_path())
 | 
						||
			trecfile = "co0800.ini";
 | 
						||
 | 
						||
		TFile_text input_docs(nomefile, trecfile);     //crea un oggetto articoli di tipo TFile_text
 | 
						||
		TRecord_text trec;                             //crea un record vuoto con nome trec 
 | 
						||
		TTracciato_record& rec = *(input_docs.t_rec(""));
 | 
						||
    const int nfields = rec.tracciati_campo().items();
 | 
						||
		
 | 
						||
    clifo.setkey(4);
 | 
						||
		for (int f = 0; f < nfields; f++)
 | 
						||
		{
 | 
						||
			const TTracciato_campo& c = rec.get(f);
 | 
						||
			const TString name = c.name();
 | 
						||
			if (name == "CF")
 | 
						||
				fcf = f;
 | 
						||
			else
 | 
						||
				if (name == DOC_DATADOC)
 | 
						||
					fdata = f;
 | 
						||
		}
 | 
						||
 | 
						||
		if (fcf < 0)
 | 
						||
		{
 | 
						||
			error_box("Manca il campo codice fiscale nel tracciato");
 | 
						||
			return;
 | 
						||
		}
 | 
						||
		if (fdata < 0)
 | 
						||
		{
 | 
						||
			error_box("Manca il campo data documento nel tracciato");
 | 
						||
			return; 
 | 
						||
		}
 | 
						||
		const long size = fsize(nomefile);
 | 
						||
		input_docs.open();                                      //applico il metodo open che apre il file in lettura (contenuta in TFile_text)
 | 
						||
		ifstream & rf = *input_docs.read_file();
 | 
						||
 | 
						||
		TProgind p(size, TR("Importazione conferimenti"), true, true);
 | 
						||
		TDocumento * d = NULL;
 | 
						||
 		for (int i = 0; input_docs.ok_r(); i++)             //ok_r <20> una funzione che indica la fine del file
 | 
						||
		{ 
 | 
						||
			if (!p.setstatus(rf.tellg()))
 | 
						||
				break;
 | 
						||
			if (input_docs.read(trec) == NOERR)
 | 
						||
			{ 
 | 
						||
 | 
						||
				const TString16 cf = trec.get(fcf);
 | 
						||
				const TDate datadoc(trec.get(fdata));
 | 
						||
 | 
						||
				if ((cf != last_cf) || (datadoc != last_data))
 | 
						||
				{
 | 
						||
					if (d != NULL && d->rows() > 0)
 | 
						||
					{
 | 
						||
						m.doc() = *d;
 | 
						||
						m.doc2mask();
 | 
						||
						m.mask2doc();
 | 
						||
						*d = m.doc();
 | 
						||
						TSheet_field& sh = m.sheet();
 | 
						||
						for (int i = 1; i <= m.doc().physical_rows(); i++)
 | 
						||
						{
 | 
						||
							TRiga_documento& r = (*d)[i];
 | 
						||
							r.autosave(sh);
 | 
						||
							r.put(RDOC_SCONTO, ritprezzo);	
 | 
						||
						}
 | 
						||
						update_spese_doc(codmercato, *d);
 | 
						||
						d->stato(d->tipo().stato_finale_inserimento());
 | 
						||
						d->write();
 | 
						||
						delete d;
 | 
						||
						d = NULL;
 | 
						||
					}
 | 
						||
					d = new TDocumento;
 | 
						||
					d->zero();
 | 
						||
					d->set_key(*d, 'D', datadoc.year(), codnum, 0L);
 | 
						||
					clifo.put(CLI_TIPOCF, "F");
 | 
						||
					clifo.put(CLI_COFI, cf);
 | 
						||
					int err = clifo.read(_isequal);
 | 
						||
					if (err != NOERR)
 | 
						||
						error_box("Fornitore con codice fiscale %s assente errore : %d)", (const char *) cf, err);
 | 
						||
 | 
						||
					const long codcf = clifo.get_long(CLI_CODCF);
 | 
						||
					d->put(DOC_TIPODOC, codtipo);
 | 
						||
					d->put(DOC_TIPOCF, "F");
 | 
						||
					d->put(DOC_CODCF, codcf);
 | 
						||
					d->put(DOC_DATADOC, datadoc);
 | 
						||
					d->put("MERCATO", codmercato);
 | 
						||
					for (int f = 0; f < nfields; f++)
 | 
						||
					{
 | 
						||
						const TTracciato_campo& c = rec.get(f);
 | 
						||
						const TString& name = c.name();
 | 
						||
 | 
						||
						if (name != "CF" && name != "DATADOC")
 | 
						||
							if (name.full() && ((name.find("->") < 0) || (name.starts_with("33->"))))
 | 
						||
								d->put(name, trec.get(f));
 | 
						||
					}
 | 
						||
					last_cf = cf;
 | 
						||
					last_data = datadoc;
 | 
						||
				}
 | 
						||
				TRiga_documento& row = d->new_row("CO");
 | 
						||
 | 
						||
				for (int f = 0; f < nfields; f++)
 | 
						||
				{
 | 
						||
					const TTracciato_campo& c = rec.get(f);
 | 
						||
					TString name = c.name();
 | 
						||
					TString val;
 | 
						||
 | 
						||
					if (name.starts_with("34->"))
 | 
						||
					{
 | 
						||
						name.ltrim(4);
 | 
						||
						val = trec.get(f);
 | 
						||
						if (row.type(name) == _realfld)
 | 
						||
						{
 | 
						||
							val.replace(',', '.');
 | 
						||
							real v(val);
 | 
						||
							row.put(name, v);
 | 
						||
						}
 | 
						||
						else
 | 
						||
							row.put(name, val);
 | 
						||
					}
 | 
						||
				}
 | 
						||
				TString80 codice = row.get(RDOC_CODART);
 | 
						||
				TString80 key;  
 | 
						||
				key.format("%06ld%s", codmercato, (const char*) codice);
 | 
						||
				const TRectype& rec = cache().get("%COA", key);
 | 
						||
 | 
						||
				if (!rec.empty())
 | 
						||
				{
 | 
						||
					codice = rec.get("S1");
 | 
						||
					row.put(RDOC_CODART, codice);			
 | 
						||
				}
 | 
						||
				real qta = row.get(RDOC_QTAGG1);
 | 
						||
				if (ritqta > ZERO)
 | 
						||
					qta -= qta*ritqta/CENTO;
 | 
						||
				row.put(RDOC_QTA, qta);		
 | 
						||
	
 | 
						||
			}                                                       
 | 
						||
		} 
 | 
						||
		if (d !=NULL && d->rows() > 0)
 | 
						||
		{
 | 
						||
			m.doc() = *d;
 | 
						||
			m.doc2mask();
 | 
						||
			m.mask2doc();
 | 
						||
			*d = m.doc();
 | 
						||
			TSheet_field& sh = m.sheet();
 | 
						||
			for (int i = 1; i <= m.doc().physical_rows(); i++)
 | 
						||
			{
 | 
						||
				TRiga_documento& r = (*d)[i];
 | 
						||
				r.autosave(sh);
 | 
						||
				r.put(RDOC_SCONTO, ritprezzo);	
 | 
						||
			}
 | 
						||
			update_spese_doc(codmercato, *d);
 | 
						||
			d->stato(d->tipo().stato_finale_inserimento());
 | 
						||
			d->write();
 | 
						||
		}
 | 
						||
		input_docs.close();
 | 
						||
  }   
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
int co0800(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TImportazioneConf main_app;
 | 
						||
  main_app.run(argc, argv, TR("Importazione conferimenti"));
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 |