Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1353 git-svn-id: svn://10.65.10.50/trunk@18581 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			416 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			416 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "co1.h"
 | |
| #include "co1500a.h"
 | |
| 
 | |
| #include <automask.h>
 | |
| #include <progind.h>
 | |
| #include <reprint.h>
 | |
| #include <viswin.h>
 | |
| 
 | |
| #include <clifo.h>
 | |
| #include <doc.h>
 | |
| #include <rdoc.h>
 | |
| #include <mov.h>
 | |
| #include <rmov.h>
 | |
| #include <rmoviva.h>
 | |
| 
 | |
| #include "..\tc\tc0700.h"
 | |
| #include "..\ve\velib.h"
 | |
| #include "..\ve\velib04.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TIVACoop_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TIVACoop_recset : public TRecordset
 | |
| {
 | |
| 	TArray & _righeIVA;
 | |
| 	long _pos;
 | |
| 	TArray _column;
 | |
| 	long _numreg;
 | |
| 
 | |
| 	void set_column_info();
 | |
| 
 | |
| protected:
 | |
|   virtual TRecnotype items() const {	return _righeIVA.items(); }
 | |
|   virtual TRecnotype current_row() const { return _pos; }
 | |
|   virtual void requery() {}
 | |
|   virtual const TRecordset_column_info& column_info(unsigned int c) const { return (const TRecordset_column_info&)_column[c];}
 | |
| 	unsigned int columns() const { return _column.items(); }
 | |
|   virtual const TVariant& get(unsigned int column) const;
 | |
| 	virtual const TString& query_text() const { return EMPTY_STRING;} 
 | |
|   
 | |
| 	bool move_to(TRecnotype pos);
 | |
| 
 | |
| public:
 | |
| 
 | |
|   TIVACoop_recset(TArray & righeIVA) : TRecordset(), _righeIVA(righeIVA), _pos(0L) { set_column_info(); }
 | |
| };
 | |
| 
 | |
| void TIVACoop_recset::set_column_info()
 | |
| {
 | |
| 	TRectype  rec(LF_RMOVIVA);
 | |
| 
 | |
|   for (int i = 0; i < rec.items(); i++)
 | |
|   {
 | |
|     TRecordset_column_info* info = new TRecordset_column_info;
 | |
|     const char* name = rec.fieldname(i);
 | |
| 
 | |
|     info->_name = name;
 | |
|     info->_type = rec.type(name);
 | |
|     switch (info->_type)
 | |
|     {
 | |
| 			case _datefld: info->_width = 10; break;
 | |
| 			case _memofld: info->_width = 50; break;
 | |
| 			default      : info->_width = rec.length(name); break;
 | |
| 		}							
 | |
| 		_column.add(info);
 | |
|   }
 | |
| }
 | |
| 
 | |
| const TVariant& TIVACoop_recset::get(unsigned int column) const
 | |
| {
 | |
|   const TRecordset_column_info* info = (const TRecordset_column_info*)_column.objptr(column);
 | |
| 
 | |
|   if (info != NULL)
 | |
|   {
 | |
|     const char* field = info->_name;
 | |
| 		const long row = current_row();
 | |
| 		const TRectype * rec = (const TRectype *) _righeIVA.objptr(row);
 | |
| 		
 | |
| 		if (rec != NULL)
 | |
| 		{
 | |
| 			TVariant & var = get_tmp_var();
 | |
| 			
 | |
| 			var = rec->get(field);
 | |
| 			return var;
 | |
| 		}
 | |
|   }
 | |
|   return NULL_VARIANT;
 | |
| }
 | |
| 
 | |
| bool TIVACoop_recset::move_to(TRecnotype pos)
 | |
| {
 | |
|   bool ok = pos >= 0 && pos < items();
 | |
|  
 | |
| 	if (ok)
 | |
|     _pos = pos;
 | |
| 	else
 | |
| 		_pos = 0L;
 | |
|   
 | |
| 	return ok;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TRMovCoop_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TRMovCoop_recset : public TRecordset
 | |
| {
 | |
| 	TArray & _righemov;
 | |
| 	long _pos;
 | |
| 	TArray _column;
 | |
| 	
 | |
| 	void set_column_info();
 | |
| 
 | |
| protected:
 | |
|   virtual TRecnotype items() const {	return _righemov.items();}
 | |
|   virtual TRecnotype current_row() const { return _pos; }
 | |
|   virtual void requery() {}
 | |
|   virtual const TRecordset_column_info& column_info(unsigned int c) const { return (const TRecordset_column_info&)_column[c];}
 | |
| 	unsigned int columns() const { return _column.items(); }
 | |
|   virtual const TVariant& get(unsigned int column) const;
 | |
| 	virtual const TString& query_text() const { return EMPTY_STRING;} 
 | |
| 
 | |
|   bool move_to(TRecnotype pos);
 | |
| 
 | |
| public:
 | |
| 
 | |
|   TRMovCoop_recset(TArray & righemov) : TRecordset(), _righemov(righemov), _pos(0L) { set_column_info(); }
 | |
| };
 | |
| 
 | |
| void TRMovCoop_recset::set_column_info()
 | |
| {
 | |
| 	TRectype  rec(LF_RMOV);
 | |
| 
 | |
|   for (int i = 0; i < rec.items(); i++)
 | |
|   {
 | |
|     TRecordset_column_info* info = new TRecordset_column_info;
 | |
|     const char* name = rec.fieldname(i);
 | |
| 
 | |
|     info->_name << name;
 | |
|     info->_type = rec.type(name);
 | |
|     switch (info->_type)
 | |
|     {
 | |
| 			case _datefld: info->_width = 10; break;
 | |
| 			case _memofld: info->_width = 50; break;
 | |
| 			default      : info->_width = rec.length(name); break;
 | |
| 		}							
 | |
| 		_column.add(info);
 | |
|   }
 | |
| }
 | |
| 
 | |
| const TVariant& TRMovCoop_recset::get(unsigned int column) const
 | |
| {
 | |
|   const TRecordset_column_info* info = (const TRecordset_column_info*)_column.objptr(column);
 | |
|   if (info != NULL)
 | |
|   {
 | |
|     const char* field = info->_name;
 | |
| 		const long row = current_row();
 | |
| 		const TRectype * rec = (const TRectype *) _righemov.objptr(row);
 | |
| 		
 | |
| 		if (rec != NULL)
 | |
| 		{
 | |
| 			TVariant & var = get_tmp_var();
 | |
| 			
 | |
| 			var = rec->get(field);
 | |
| 			return var;
 | |
| 		}
 | |
|   }
 | |
|   return NULL_VARIANT;
 | |
| }
 | |
| 
 | |
| bool TRMovCoop_recset::move_to(TRecnotype pos)
 | |
| {
 | |
|   bool ok = pos >= 0 && pos < items();
 | |
|  
 | |
| 	if (ok)
 | |
|     _pos = pos;
 | |
| 	else
 | |
| 		_pos = 0L;
 | |
|   
 | |
| 	return ok;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TMovCoop_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TMovCoop_recset;
 | |
| 
 | |
| class TCoop_contabilizzazione : public TContabilizzazione
 | |
| {
 | |
| 	TMovCoop_recset & _recset;
 | |
| 		
 | |
| 	virtual void export_movimento(TMovimentoPN_VE & mov, TViswin & v);
 | |
| 	virtual bool exporting() { return true; }
 | |
| 
 | |
| public:
 | |
|   TCoop_contabilizzazione(TMovCoop_recset & recset, const char* cod) : TContabilizzazione(cod), _recset(recset) {}
 | |
|   TCoop_contabilizzazione(TMovCoop_recset & recset, const TRectype& rec) : TContabilizzazione(rec), _recset(recset) {}
 | |
|   virtual ~TCoop_contabilizzazione() {}
 | |
| 
 | |
| };
 | |
| 
 | |
| class TMovCoop_recset : public TISAM_recordset
 | |
| {
 | |
| 	TRectype _mov;
 | |
| 	TArray _righeIVA;
 | |
| 	TArray _righemov;
 | |
| 	long _codditta;
 | |
| 	long _codcoop;
 | |
| 	TCoop_contabilizzazione * _el;
 | |
| 
 | |
| public:
 | |
|   virtual const TVariant& get(const char* column_name) const;
 | |
| 	bool move_to(TRecnotype pos);
 | |
| 	TRectype & mov() { return _mov;}
 | |
| 	TArray & righeIVA() { return _righeIVA;}
 | |
| 	TArray & righemov() { return _righemov;}
 | |
| 	const TString & ditta();
 | |
| 
 | |
|   TMovCoop_recset(const char * query, const char * codel, TArray & recsets);
 | |
| };
 | |
| 
 | |
| const TVariant& TMovCoop_recset::get(const char* column_name) const
 | |
| {
 | |
| 	const TFixed_string fname(column_name);
 | |
| 
 | |
| 	if (_mov.exist(fname))
 | |
| 	{
 | |
| 		TVariant & var = get_tmp_var();
 | |
| 
 | |
| 		var = _mov.get(fname);
 | |
| 		return var;
 | |
| 	}
 | |
| 
 | |
| 	return TRecordset::get(fname);
 | |
| }
 | |
| 
 | |
| const TString & TMovCoop_recset::ditta()
 | |
| {
 | |
| 	TString & str = get_tmp_string();
 | |
| 
 | |
| 	str.format("%04ld", _codditta);
 | |
| 	return str;
 | |
| }
 | |
| 
 | |
| TMovCoop_recset::TMovCoop_recset(const char * query, const char * codel, TArray & recsets)
 | |
|            : TISAM_recordset(query), _codditta(0L), _mov(LF_MOV), _el(NULL)
 | |
| {
 | |
| 	TConfig c(CONFIG_DITTA);
 | |
| 
 | |
| 	_codcoop = c.get_long("CodCoop");
 | |
| 
 | |
| 	recsets.add(new TIVACoop_recset(righeIVA()), LF_RMOVIVA);
 | |
| 	recsets.add(new TRMovCoop_recset(righemov()), LF_RMOV);
 | |
| 	_el = new TCoop_contabilizzazione(*this, codel);
 | |
| }
 | |
| 
 | |
| void TCoop_contabilizzazione::export_movimento(TMovimentoPN_VE & mov, TViswin & v)
 | |
| { 
 | |
| 	_recset.mov() = mov.lfile().curr();
 | |
| 
 | |
| 	_recset.mov().zero(MOV_DESCR);
 | |
| 	const TString16 numdoc = _recset.mov().get(MOV_NUMDOC);
 | |
| 	_recset.mov().zero(MOV_NUMDOC);
 | |
| 	_recset.mov().put(MOV_PROTIVA, numdoc);
 | |
| 	
 | |
| 	int cgrows = mov.cg_items();
 | |
| 
 | |
| 	for (int i = 0; i < cgrows; i++)
 | |
| 		_recset.righemov().add(mov.cg(i));
 | |
| 
 | |
| 	int ivarows = mov.iva_items();
 | |
| 
 | |
| 	for (int j = 0; j < ivarows; j++)
 | |
| 		_recset.righeIVA().add(mov.iva(j));
 | |
| 	
 | |
| 	const int lines = v.lines();
 | |
| 	TTextfile & txt = v.text();
 | |
| 
 | |
| 	for (int k = 0; k < lines; k++)
 | |
| 		((TTS_sender &) main_app()).log(lines > 2, txt.line(k));
 | |
| 
 | |
| }
 | |
| 
 | |
| bool TMovCoop_recset::move_to(TRecnotype pos)
 | |
| {
 | |
|   bool ok = TISAM_recordset::move_to(pos);
 | |
| 	
 | |
| 	if (ok)
 | |
|   {
 | |
| 		TToken_string key;
 | |
| 		TDocumento d(cursor()->curr());
 | |
| 		
 | |
| 		_codditta = d.get_long(DOC_CODCF);
 | |
| 		d.put(DOC_TIPOCF, "C");
 | |
| 		d.put(DOC_CODCF, _codcoop);
 | |
| 
 | |
| 		const int rows = d.physical_rows();
 | |
| 		int row = 0;
 | |
| 
 | |
| 		for (int i = 1; row == 0 && i <= rows; i++)
 | |
| 		{
 | |
| 			const TRiga_documento & r = d[i];
 | |
| 
 | |
| 			if (r.is_merce())
 | |
| 				row = i;
 | |
| 		}
 | |
| 
 | |
| 		if (row > 0)
 | |
| 		{
 | |
| 			TRiga_documento & r = d[row];
 | |
| 			const TRectype & anamag = cache().get(LF_ANAMAG, r.get(RDOC_CODARTMAG));
 | |
| 			const TString & tipodoc = anamag.get(ANAMAG_USER3);
 | |
| 
 | |
| 			TCodiceIVA iva(r.get(RDOC_CODIVA));
 | |
| 
 | |
| 			if (iva.get_int("S4") == 0 && _codditta < 1000)
 | |
| 				_codditta += 1000;
 | |
| 
 | |
| 			key = "F";
 | |
| 			key.add(_codditta % 1000);
 | |
| 			const TRectype & socio = cache().get(LF_CFVEN, key);
 | |
| 
 | |
| 			if (socio.get_bool(CFV_IVARID))
 | |
| 			{
 | |
| 				const TString4 ci = anamag.get(ANAMAG_CODIVAR);
 | |
| 
 | |
| 				if (ci.full())
 | |
| 					r.put(RDOC_CODIVA, ci);
 | |
| 			}
 | |
| 
 | |
| 			if (tipodoc.full())
 | |
| 			{
 | |
| 				d.put(DOC_CODNUM, tipodoc);
 | |
| 				d.put(DOC_TIPODOC, tipodoc);
 | |
| 				d.body().renum_key(RDOC_CODNUM, tipodoc);
 | |
| 			}
 | |
| 			_righeIVA.destroy();
 | |
| 			_righemov.destroy();
 | |
| 
 | |
| 			TLista_documenti in;
 | |
| 			TLista_documenti out;
 | |
| 			TDate datadoc(d.get_date(DOC_DATADOC));
 | |
| 			
 | |
| 			in.add(d);
 | |
| 			_el->set_writeable(false);
 | |
| 			_el->elabora(in, out, datadoc, true);
 | |
| 		}
 | |
| 	}
 | |
|   
 | |
| 	return ok;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TCoop_sender
 | |
| ///////////////////////////////////////////////////////////
 | |
| class TCoop_sender : public TTS_campo_sender
 | |
| {
 | |
| protected:
 | |
| //	virtual bool test_swap(const TRecordset& mov) { return ((TMovCoop_recset&)mov).nota_credito();}
 | |
| 
 | |
| protected:
 | |
| //	virtual const char * decode_causale(const TRecordset& mov); ?
 | |
| //	virtual bool test_swap(const TRecordset& mov);
 | |
| //	virtual bool swap_ritsoc(const TRecordset& mov);
 | |
| protected:
 | |
| 	virtual TRecordset & movrecset();
 | |
| 	virtual const char * mask_name() const {return "co1500a"; }
 | |
|   virtual const char * extra_modules() const {return "ba";}
 | |
| 
 | |
| 	virtual bool find_regolarizzazione(TRecordset& mov) { return false; }
 | |
| 	virtual bool mov_regolarizzazione(const TRecordset& mov) { return false; }
 | |
| 	virtual bool mov_intra(const TRecordset& mov) { return false; }
 | |
| 	virtual bool mov_reverse_charge(const TRecordset& mov) { return false; }
 | |
| 	virtual long iva11_reverse(const TRecordset & mov) { return 0L;}
 | |
| 	virtual bool regime_agricolo(const TRecordset& mov) const { return true; }
 | |
| 	const TString & dittamulti(const TRecordset& mov) const { return ((TMovCoop_recset &)mov).ditta(); }
 | |
| 
 | |
| public:
 | |
| 	virtual void update_parameters(const TMask & m, TRecordset & mov) {}
 | |
| 	TCoop_sender() {}
 | |
| };
 | |
| 
 | |
| TCoop_sender& app() { return (TCoop_sender&)main_app(); }
 | |
| 
 | |
| TRecordset & TCoop_sender::movrecset()
 | |
| {
 | |
| 
 | |
| 	TRecordset * mov = get_recset(LF_MOV);
 | |
| 
 | |
| 	if (mov == NULL)
 | |
| 	{
 | |
| 		TString query;
 | |
| 		TMask & m = get_mask();
 | |
| 		TDate from = m.get_date(F_DATA_DA);
 | |
| 		TDate to = m.get_date(F_DATA_AL);
 | |
| 		const TString & codnum  = m.get(F_CODNUM);
 | |
| 
 | |
| 		query << "USE " << SF_DOC << " KEY 3 SELECT " << DOC_CODNUM << "==\"" << codnum <<"\"\n";
 | |
| 		query << "FROM " DOC_DATADOC "=\"" << from.string() << "\" " << DOC_PROVV << "=D " << DOC_ANNO << "=" << from.year() << " " << DOC_CODNUM << "=" << codnum << "\n";
 | |
| 		query << "TO " DOC_DATADOC "=\"" << to.string() << "\" " << DOC_PROVV << "=D " << DOC_ANNO << "=" << to.year() << " " << DOC_CODNUM << "=" << codnum;
 | |
| 		mov = set_recset(LF_MOV, new TMovCoop_recset(query, m.get(F_CODEL), recsets()));
 | |
| 	}
 | |
| 
 | |
| 	return *mov;
 | |
| }
 | |
| 
 | |
| int co1500(int argc, char* argv[])
 | |
| {
 | |
|   TCoop_sender app;
 | |
| 
 | |
|   app.run(argc, argv, "Invio a TeamSystem mov. coop.");
 | |
|   return 0;
 | |
| }
 |