Files correlati : tc0.exe l Ricompilazione Demo : [ ] Commento : Conversione archivi CAMPO 1a versione git-svn-id: svn://10.65.10.50/trunk@19882 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1358 lines
		
	
	
		
			33 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1358 lines
		
	
	
		
			33 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "tc0.h"
 | |
| #include "tc0900a.h"
 | |
| 
 | |
| #include <automask.h>
 | |
| #include <progind.h>
 | |
| #include <reprint.h>
 | |
| 
 | |
| #include <clifo.h>
 | |
| #include <pconti.h>
 | |
| #include <causali.h>
 | |
| #include <mov.h>
 | |
| #include <rmov.h>
 | |
| #include <rmoviva.h>
 | |
| 
 | |
| 
 | |
| #include "tc0701.h"
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TTransfer_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TTransfer_mask : public TAutomask
 | |
| {
 | |
| private:
 | |
|   void serialize(bool bSave);
 | |
| protected:
 | |
|   bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| public:
 | |
|   TTransfer_mask();
 | |
|   virtual ~TTransfer_mask();
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TMov_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TMov_recset : public TAS400_recordset
 | |
| {
 | |
| protected:
 | |
|   void add_field(const char* name = "Filler", int from = -1, char tipo = 'a', 
 | |
| 								 int len = 0, const char* def = NULL);
 | |
| 
 | |
| public:
 | |
| 	bool vendite() const;
 | |
| 	bool acquisti() const;
 | |
| 	bool fattura() const;
 | |
| 	bool nota_credito() const;
 | |
|   virtual const TVariant& get(const char* column_name) const;
 | |
|  
 | |
|   TMov_recset(const char * query);
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TTransfer_sender
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TTransfer_sender : public TTS_sender
 | |
| {
 | |
| 	TTransfer_mask * _mask;
 | |
| 
 | |
| protected:
 | |
| 
 | |
| protected:
 | |
| 	virtual TRecordset & movrecset();
 | |
| 	virtual TRecordset & rmovrecset(const TRecordset & mov);
 | |
| 	virtual const TRecordset & clirecset(const char tipocf, const long codcf);
 | |
| 	virtual TMask & get_mask();
 | |
| 	virtual bool find_regolarizzazione(TRecordset& mov);
 | |
| 	virtual const char * decode_causale(const TRecordset& mov);
 | |
| 	virtual bool test_swap(const TRecordset& mov) { return ((TMov_recset &) mov).nota_credito();}
 | |
| 	virtual bool swap_ritsoc(const TRecordset& mov);
 | |
| 	virtual bool mov_regolarizzazione(const TRecordset& mov);
 | |
| 	virtual bool mov_intra(const TRecordset& mov) {	return causrecset(mov).get(CAU_INTRACOM).as_bool();}
 | |
| 	virtual bool mov_reverse_charge(const TRecordset& mov);
 | |
| 	virtual long iva11_reverse(const TRecordset & mov) { return causrecset(mov).get(CAU_REGSPIVA).as_int();}  // verificare
 | |
| 
 | |
| public:
 | |
| 	virtual TRecordset & rivarecset(const TRecordset & mov);
 | |
| 	const TRecordset & pconrecset(const int gruppo, int conto, long sottoconto);
 | |
| 	const TRecordset & causrecset(const TRecordset & mov);
 | |
| 	virtual void update_parameters(const TMask & m, TRecordset & mov) {}
 | |
| 	TTransfer_sender() : _mask(NULL) {}
 | |
| };
 | |
| 
 | |
| TTransfer_sender& app() { return (TTransfer_sender&)main_app(); }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TClifo_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TClifo_recset : public TAS400_recordset
 | |
| {
 | |
| 	TAssoc_array _index;
 | |
| 
 | |
| protected:
 | |
|   void add_field(const char* name = "Filler", int from = -1, char tipo = 'a', 
 | |
| 								 int len = 0, const char* def = NULL);
 | |
| 
 | |
| public:
 | |
| 	bool find(char tipocf, long codcf);
 | |
|   virtual const TVariant& get(const char* column_name) const;
 | |
|  
 | |
|   TClifo_recset(const char * query);
 | |
| };
 | |
| 
 | |
| void TClifo_recset::add_field(const char* name, int from, char tipo, int len, const char* def)
 | |
| {
 | |
| 	const bool required = false;
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(name, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(name, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| const TVariant& TClifo_recset::get(const char* column_name) const
 | |
| {
 | |
| 	TFixed_string fname(column_name);
 | |
| 
 | |
| 	if (fname == CLI_COFI || fname == CLI_PAIV)
 | |
| 	{
 | |
| 		TVariant& var = get_tmp_var();
 | |
| 		TString80 s(TAS400_recordset::get(fname).as_string());
 | |
| 
 | |
| 		var.set(s.trim());
 | |
| 		return var;
 | |
| 	}
 | |
| 	else
 | |
|   	if (fname == CLI_TIPOCF)
 | |
| 		{
 | |
| 			TVariant& var = get_tmp_var();
 | |
| 			const int tipo = TAS400_recordset::get(fname).as_int();
 | |
| 
 | |
| 			var.set(tipo == 1 ? "C" : "F");
 | |
| 			return var;
 | |
| 		}
 | |
| 
 | |
| 	return TAS400_recordset::get(fname);
 | |
| }
 | |
| 
 | |
| 
 | |
| TClifo_recset::TClifo_recset(const char * query)
 | |
|              : TAS400_recordset(TString("AS400(213)\n") << query)
 | |
| {
 | |
|   const char a = 'a';
 | |
|   const char n = 'n';
 | |
| 
 | |
|   add_field("TIPOR",	     1, a,	2);	
 | |
|   add_field(CLI_TIPOCF,	   3, a,	1);	
 | |
|   add_field(CLI_CODCF,		 4, n,	6);
 | |
|   add_field("L01",	       10 , a,	6);
 | |
|   add_field("L02",	       16 , n,	1);
 | |
|   add_field(CLI_RAGSOC,	   17, a,	50);
 | |
|   add_field(CLI_PAIV,	     67, a,	11);
 | |
|   add_field(CLI_COFI,	     78, a,	16);
 | |
|   add_field(CLI_INDCF,		 94, a,	35);
 | |
|   add_field(CLI_CAPCF,	   129, n,	5);
 | |
|   add_field(CLI_LOCCF,	   134, a,	20);
 | |
|   add_field("PROV",	       154, a,	2);
 | |
|   add_field(CLI_TEL,	     156, a,	12);
 | |
|   add_field(CLI_ALLEG,	   168, a,	1);
 | |
|   add_field(CLI_GRUPPORIC, 169, n,	2);
 | |
|   add_field(CLI_CONTORIC,  171, n,	2);
 | |
|   add_field(CLI_SOTTOCRIC, 173, n,	6);
 | |
|   add_field("L03",         179, n,	1);
 | |
|   add_field(CLI_CODALLEG,	 180, n,	6);
 | |
|   add_field(CLI_CODPAG,	   186, n,	2);
 | |
|   add_field("L03" ,	       188, a,	68);
 | |
|   add_field("L03" ,	       256, a,	1);
 | |
| 
 | |
|   bool ok;
 | |
| 
 | |
| 	for (ok = move_last(); ok;)
 | |
| 	{
 | |
| 		const int p = current_row();
 | |
| 
 | |
| 		if (get("TIPOR").as_string() != "A1")
 | |
| 		{
 | |
| 			destroy(p);
 | |
| 			if (p <= last())
 | |
| 				move_to(p);
 | |
| 			else
 | |
| 				move_last();
 | |
| 		}
 | |
| 		else
 | |
| 			ok = move_prev();
 | |
| 	}
 | |
| 
 | |
| 	TString16 pos, key;
 | |
| 
 | |
|   for (ok = move_first(); ok; ok = move_next())
 | |
| 	{
 | |
| 		pos.format("%ld", current_row());
 | |
| 		key.format("%c|%ld", get(CLI_TIPOCF).as_string()[0], get(CLI_CODCF).as_int());
 | |
| 		
 | |
| 		_index.add(key, pos);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| bool TClifo_recset::find(char tipocf, long codcf)
 | |
| {
 | |
| 	TString16 key;
 | |
| 
 | |
| 	key.format("%c|%ld", tipocf, codcf);
 | |
| 
 | |
| 	TString * s = (TString *) _index.objptr(key);
 | |
| 	long pos = 0L;
 | |
| 	const bool ok =	s && s->full();
 | |
|   
 | |
| 	if (ok)
 | |
| 		pos = atoi(*s);
 | |
| 	move_to(pos);
 | |
| 	return ok;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TPCon_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TPCon_recset : public TAS400_recordset
 | |
| {
 | |
| 	TAssoc_array _index;
 | |
| 
 | |
| protected:
 | |
|   void add_field(const char * tipor, const char* name = "Filler", int from = -1, char tipo = 'a', 
 | |
| 								 int len = 0, const char* def = NULL);
 | |
| 
 | |
| public:
 | |
| 	bool find(int gruppo, int conto, long sottoconto);
 | |
|   virtual const TVariant& get(const char* column_name) const;
 | |
|  
 | |
|   TPCon_recset(const char * query);
 | |
| };
 | |
| 
 | |
| void TPCon_recset::add_field(const char * tipor, const char* name, int from, char tipo, int len, const char* def)
 | |
| {
 | |
| 	const bool required = false;
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   TString80 field(name);
 | |
| 	
 | |
| 	if (tipor && *tipor)
 | |
| 		field.format("%s.%s", tipor, name);
 | |
| 
 | |
|   if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(field, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(field, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| const TVariant& TPCon_recset::get(const char* column_name) const
 | |
| {
 | |
| 	const char * tipor = (const char *) get("TIPOR").as_string();
 | |
| 	const TFixed_string field(column_name);
 | |
| 	TFixed_string name(field);
 | |
| 
 | |
| 	if (tipor && *tipor)
 | |
| 		name.format("%s.%s", tipor, field);
 | |
| 
 | |
| 	return TAS400_recordset::get(name);
 | |
| }
 | |
| 
 | |
| 
 | |
| TPCon_recset::TPCon_recset(const char * query)
 | |
|             : TAS400_recordset(TString("AS400(213)\n") << query)
 | |
| {
 | |
|   const char a = 'a';
 | |
|   const char n = 'n';
 | |
| 
 | |
| 	add_field("","TIPOR",					1, a,	2);	
 | |
|   add_field("P1", PCN_GRUPPO,		3, n,	2);	
 | |
|   add_field("P1", "L01",				5 , n,	11);
 | |
|   add_field("P1", PCN_DESCR,	  16, a,	30);
 | |
|   add_field("P1", "L02" ,	      46, a,	210);
 | |
|   add_field("P1", "L03" ,	      256, a,	1);
 | |
| 
 | |
|   add_field("P2", PCN_GRUPPO,			3, n,	2);	
 | |
|   add_field("P2", PCN_CONTO,			5, n,	2);	
 | |
|   add_field("P2", "L01",					7 , n,	9);
 | |
|   add_field("P2", PCN_DESCR,			16, a,	30);
 | |
|   add_field("P2", PCN_INDBIL,			46, n,	1);
 | |
|   add_field("P2", PCN_TMCF,				47, a,	1);
 | |
|   add_field("P2", PCN_STSOTTBIL,	48, n,	1);
 | |
|   add_field("P2", "L02" ,					49, a,	21);
 | |
|   add_field("P2", PCN_COMPENS,		70, n,	1);
 | |
|   add_field("P2", "L02" ,					71, a,	185);
 | |
|   add_field("P2", "L03" ,	      256, a,	1);
 | |
| 
 | |
|   add_field("P3", PCN_GRUPPO,			3, n,	2);	
 | |
|   add_field("P3", PCN_CONTO,			5, n,	2);	
 | |
|   add_field("P3", PCN_SOTTOCONTO,	7, n,	6);	
 | |
|   add_field("P3", "L01",					13 , n,	3);
 | |
|   add_field("P3", PCN_DESCR,			16, a,	30);
 | |
|   add_field("P3", PCN_TIPOSPRIC,	46, n,	1);
 | |
|   add_field("P3", "L02",					47, a,	1);
 | |
|   add_field("P3", "L03" ,					48, a,	21);
 | |
|   add_field("P3", "L04" ,					69, a,	21);
 | |
|   add_field("P3", "L05",					90, n,	2);
 | |
|   add_field("P3", "L06" ,					92, a,	164);
 | |
|   add_field("P3", "L07" ,					256, a,	1);
 | |
| 
 | |
| 	bool ok;
 | |
| 
 | |
| 	for (ok = move_last(); ok;)
 | |
| 	{
 | |
| 		const int p = current_row();
 | |
| 
 | |
| 		if (get("TIPOR").as_string() != "P1" ||
 | |
| 			  get("TIPOR").as_string() != "P2" ||
 | |
| 				get("TIPOR").as_string() != "P3")
 | |
| 		{
 | |
| 			destroy(p);
 | |
| 			if (p <= last())
 | |
| 				move_to(p);
 | |
| 			else
 | |
| 				move_last();
 | |
| 		}
 | |
| 		else
 | |
| 			ok = move_prev();
 | |
| 	}
 | |
| 
 | |
| 	TString16 pos, key;
 | |
| 
 | |
|   for (ok = move_first(); ok; ok = move_next())
 | |
| 	{
 | |
| 		pos.format("%ld", current_row());
 | |
| 		key.format("%ld|%ld|%ld", get(PCN_GRUPPO).as_int(), get(PCN_CONTO).as_int(), get(PCN_SOTTOCONTO).as_int());
 | |
| 		
 | |
| 		_index.add(key, pos);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| bool TPCon_recset::find(int gruppo, int conto, long sottoconto)
 | |
| {
 | |
| 	TString16 key;
 | |
| 
 | |
| 	key.format("%ld|%ld|%ld", gruppo, conto, sottoconto);
 | |
| 
 | |
| 	TString * s = (TString *) _index.objptr(key);
 | |
| 	long pos = 0L;
 | |
| 	const bool ok =	s && s->full();
 | |
|   
 | |
| 	if (ok)
 | |
| 		pos = atoi(*s);
 | |
| 	move_to(pos);
 | |
| 	return ok;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TCausali_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TCausali_recset : public TAS400_recordset
 | |
| {
 | |
| 	TAssoc_array _index;
 | |
| 
 | |
| protected:
 | |
|   void add_field(const char* name = "Filler", int from = -1, char tipo = 'a', 
 | |
| 								 int len = 0, const char* def = NULL);
 | |
| 
 | |
| public:
 | |
| 	bool find(const char * codcaus);
 | |
|  
 | |
|   TCausali_recset(const char * query);
 | |
| };
 | |
| 
 | |
| void TCausali_recset::add_field(const char* name, int from, char tipo, int len, const char* def)
 | |
| {
 | |
| 	const bool required = false;
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   
 | |
| 	if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(name, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(name, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| 
 | |
| TCausali_recset::TCausali_recset(const char * query)
 | |
|             : TAS400_recordset(TString("AS400(213)\n") << query)
 | |
| {
 | |
|   const char a = 'a';
 | |
|   const char n = 'n';
 | |
| 
 | |
| 	add_field("TIPOR",					1, a,	2);	
 | |
|   add_field(CAU_CODCAUS,	  	3, n,	3);	
 | |
|   add_field("L01",						6, n,	10);
 | |
|   add_field(CAU_DESCR,				16, a,	20);
 | |
|   add_field(CAU_TIPODOC,			36, a,	2);
 | |
|   add_field(CAU_REG,					38, a,	1);
 | |
|   add_field(CAU_ALLEG,				39, a,	1);
 | |
|   add_field(CAU_M770,					40, n,	1);
 | |
|   add_field("L02" ,						41, a,	1);
 | |
|   add_field("GRUPPO[0]" ,	    42, n,	2);
 | |
|   add_field("CONTO[0]" ,	    44, n,	2);
 | |
|   add_field("SOTTOCONTO[0]",  46, n,	6);
 | |
|   add_field("GRUPPO[1]" ,	    52, n,	2);
 | |
|   add_field("CONTO[1]" ,	    54, n,	2);
 | |
|   add_field("SOTTOCONTO[1]",  56, n,	6);
 | |
|   add_field("GRUPPO[2]" ,	    62, n,	2);
 | |
|   add_field("CONTO[2]" ,	    64, n,	2);
 | |
|   add_field("SOTTOCONTO[2]",  66, n,	6);
 | |
|   add_field("GRUPPO[3]" ,	    72, n,	2);
 | |
|   add_field("CONTO[3]" ,	    74, n,	2);
 | |
|   add_field("SOTTOCONTO[3]",  76, n,	6);
 | |
|   add_field("GRUPPO[4]" ,	    82, n,	2);
 | |
|   add_field("CONTO[4]" ,	    84, n,	2);
 | |
|   add_field("SOTTOCONTO[4]",  86, n,	6);
 | |
|   add_field("GRUPPO[5]" ,	    92, n,	2);
 | |
|   add_field("CONTO[5]" ,	    94, n,	2);
 | |
|   add_field("SOTTOCONTO[5]",  96, n,	6);
 | |
|   add_field("GRUPPO[6]" ,	    102, n,	2);
 | |
|   add_field("CONTO[6]" ,	    104, n,	2);
 | |
|   add_field("SOTTOCONTO[6]",  106, n,	6);
 | |
|   add_field("GRUPPO[7]" ,	    112, n,	2);
 | |
|   add_field("CONTO[7]" ,	    114, n,	2);
 | |
|   add_field("SOTTOCONTO[7]",  116, n,	6);
 | |
|   add_field("GRUPPO[8]" ,	    122, n,	2);
 | |
|   add_field("CONTO[8]" ,	    124, n,	2);
 | |
|   add_field("SOTTOCONTO[8]",  126, n,	6);
 | |
|   add_field("GRUPPO[9]" ,	    132, n,	2);
 | |
|   add_field("CONTO[9]" ,	    134, n,	2);
 | |
|   add_field("SOTTOCONTO[9]",  136, n,	6);
 | |
|   add_field("C[10]",					142, n,	10);
 | |
|   add_field("C[11]",					152, n,	10);
 | |
|   add_field("C[12]",					162, n,	10);
 | |
|   add_field("C[13]",					172, n,	10);
 | |
|   add_field("C[14]",					182, n,	10);
 | |
|   add_field("SEZ[0]",					192, n,	1);
 | |
|   add_field("SEZ[1]",					193, n,	1);
 | |
|   add_field("SEZ[2]",					194, n,	1);
 | |
|   add_field("SEZ[3]",					195, n,	1);
 | |
|   add_field("SEZ[4]",					196, n,	1);
 | |
|   add_field("SEZ[5]",					197, n,	1);
 | |
|   add_field("SEZ[6]",					198, n,	1);
 | |
|   add_field("SEZ[7]",					198, n,	1);
 | |
|   add_field("SEZ[8]",					200, n,	1);
 | |
|   add_field("SEZ[9]",					201, n,	1);
 | |
|   add_field("SEZ[10]",				202, n,	1);
 | |
|   add_field("SEZ[11]",				202, n,	1);
 | |
|   add_field("SEZ[12]",				204, n,	1);
 | |
|   add_field("SEZ[13]",				205, n,	1);
 | |
|   add_field("SEZ[14]",				206, n,	1);
 | |
|   add_field(CAU_NUMDOC,				207, n,	1);
 | |
|   add_field(CAU_DATADOC,			208, n,	1);
 | |
|   add_field(CAU_TIPOMOV,			209, n,	1);
 | |
|   add_field("L03" ,						210, n,	3);
 | |
|   add_field(CAU_MOVAP,				213, a,	1);
 | |
|   add_field("L04",						214, a,	1);
 | |
|   add_field(CAU_MOVVAL,				215, a,	1);
 | |
|   add_field("L05" ,						216, a,	31);
 | |
|   add_field(CAU_INTRACOM,			247, a,	1);
 | |
|   add_field(CAU_VALINTRA,			248, a,	1);
 | |
|   add_field(CAU_AUTOFATT,			249, a,	1);
 | |
|   add_field(CAU_RITFATT,			250, a,	1);
 | |
|   add_field("L06" ,						251, a,	5);
 | |
|   add_field("L07" ,				    256, a,	1);
 | |
| 
 | |
| 	bool ok;
 | |
| 
 | |
| 	for (ok = move_last(); ok;)
 | |
| 	{
 | |
| 		const int p = current_row();
 | |
| 
 | |
| 		if (get("TIPOR").as_string() != "P1" ||
 | |
| 			  get("TIPOR").as_string() != "P2" ||
 | |
| 				get("TIPOR").as_string() != "P3")
 | |
| 		{
 | |
| 			destroy(p);
 | |
| 			if (p <= last())
 | |
| 				move_to(p);
 | |
| 			else
 | |
| 				move_last();
 | |
| 		}
 | |
| 		else
 | |
| 			ok = move_prev();
 | |
| 	}
 | |
| 
 | |
| 	TString16 pos, key;
 | |
| 
 | |
|   for (ok = move_first(); ok; ok = move_next())
 | |
| 	{
 | |
| 		pos.format("%ld", current_row());
 | |
| 		key.format("%ld|%ld|%ld", get(PCN_GRUPPO).as_int(), get(PCN_CONTO).as_int(), get(PCN_SOTTOCONTO).as_int());
 | |
| 		
 | |
| 		_index.add(key, pos);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| bool TCausali_recset::find(const char * codcaus)
 | |
| {
 | |
| 	TString * s = (TString *) _index.objptr(codcaus);
 | |
| 	long pos = 0L;
 | |
| 	const bool ok =	s && s->full();
 | |
|   
 | |
| 	if (ok)
 | |
| 		pos = atoi(*s);
 | |
| 	move_to(pos);
 | |
| 	return ok;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TIVA_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TIVA_recset : public TAS400_recordset
 | |
| {
 | |
| 
 | |
| 	TRecnotype _first, _last;
 | |
| 	long _numreg;
 | |
| 	TAssoc_array _index;
 | |
| 
 | |
| private:
 | |
|   void add_field(const char* name = "Filler", int from = -1, char tipo = 'a', 
 | |
| 								 int len = 0, const char* def = NULL);
 | |
| 
 | |
| public:
 | |
| 	bool find(long numreg);
 | |
|   virtual const TVariant& get(const char* column_name) const;
 | |
|   virtual bool move_to(TRecnotype pos);
 | |
| 
 | |
|   TIVA_recset(const char * query);
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TRMov_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| class TRMov_recset : public TAS400_recordset
 | |
| {
 | |
| 	TRecnotype _first, _last;
 | |
| 	long _numreg;
 | |
| 	TAssoc_array _index;
 | |
| 
 | |
| private:
 | |
|   void add_field(const char* name = "Filler", int from = -1, char tipo = 'a', 
 | |
| 								 int len = 0, const char* def = NULL);
 | |
| 
 | |
| 
 | |
| public:
 | |
| 	bool find(long numreg);
 | |
|   virtual const TVariant& get(const char* column_name) const;
 | |
|   virtual bool move_to(TRecnotype pos);
 | |
| 
 | |
|   TRMov_recset(const char * query);
 | |
| };
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TMov_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| bool TMov_recset::vendite() const
 | |
| {
 | |
| 	if (acquisti())
 | |
| 		return false;
 | |
| 	return  nota_credito() || fattura();
 | |
| }
 | |
| 
 | |
| bool TMov_recset::acquisti() const
 | |
| {
 | |
| 	const TString4 tipodoc = app().causrecset(*this).get(CAU_TIPODOC).as_string();
 | |
| 
 | |
| 	return  tipodoc == "FA" || tipodoc == "ND" || tipodoc == "BD";
 | |
| }
 | |
| 
 | |
| bool TMov_recset::nota_credito() const
 | |
| {
 | |
| 	const TString4 tipodoc = app().causrecset(*this).get(CAU_TIPODOC).as_string();
 | |
| 
 | |
| 	return  tipodoc == "NC" || tipodoc == "ND";
 | |
| }
 | |
| 
 | |
| bool TMov_recset::fattura() const
 | |
| {
 | |
| 	if (nota_credito())
 | |
| 		return false;
 | |
| 	
 | |
| 	const TString4 tipodoc = app().causrecset(*this).get(CAU_TIPODOC).as_string();
 | |
| 	
 | |
| 	return  tipodoc != "PG" || tipodoc != "IN";
 | |
| }
 | |
| 
 | |
| void TMov_recset::add_field(const char* name, int from, char tipo, int len, const char* def)
 | |
| {
 | |
| 	const bool required = false;
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   
 | |
| 	if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(name, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(name, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| const TVariant& TMov_recset::get(const char* column_name) const
 | |
| {
 | |
| 	TString16 fname(column_name);
 | |
| 	TVariant& var = get_tmp_var();
 | |
| 
 | |
| 	if (fname == MOV_TIPO)
 | |
| 	{
 | |
| 		var = vendite() ? "C" : "F";
 | |
| 		return var;
 | |
| 	}
 | |
| 	else
 | |
| 		if (fname == MOV_CODCF || fname == MOV_CODVALI)
 | |
| 			return  app().rivarecset(*this).get(fname);
 | |
| 		else
 | |
| 			if (fname == MOV_CORRVALUTA)
 | |
| 			{
 | |
| 				var = app().rivarecset(*this).get(fname);
 | |
| 				const real r = var.as_real() / CENTO;
 | |
| 					
 | |
| 				var.set(r);
 | |
| 				return var;
 | |
| 			}
 | |
| 
 | |
| 	var = TAS400_recordset::get(fname);
 | |
| 
 | |
| 	if (fname == MOV_DATAREG ||	fname == MOV_DATADOC)
 | |
| 	{
 | |
| 		const TDate d(atol(var.as_string()) + 20000000L);
 | |
| 
 | |
| 		var.set(d);
 | |
| 	}
 | |
| 	else
 | |
| 		if (fname == MOV_TOTDOC || fname == RMI_IMPONIBILE ||
 | |
| 				fname == RMI_IMPOSTA)
 | |
| 		{
 | |
| 			const real r = var.as_real() / CENTO;
 | |
| 				
 | |
| 			var.set(r);
 | |
| 		}
 | |
| 	return var;
 | |
| }
 | |
| 
 | |
| 
 | |
| TMov_recset::TMov_recset(const char * query)
 | |
|            : TAS400_recordset(TString("AS400(256)") << query)
 | |
| 					   
 | |
| {
 | |
|   const char a = 'a';
 | |
|   const char n = 'n';
 | |
|   
 | |
|   add_field("TIPOR",	     1, n,	2);	
 | |
|   add_field(MOV_NUMREG,	   3, n,	6);
 | |
|   add_field(RMV_NUMRIG,    9, n,	2);
 | |
|   add_field("L01",				11, a,	5);
 | |
|   add_field(MOV_DATAREG,	16, a,	6);
 | |
|   add_field("L02",				22, a,	1);
 | |
|   add_field(MOV_DATADOC,  23, a,	6);
 | |
|   add_field(MOV_NUMDOC,	  29, a,	7);
 | |
|   add_field(MOV_REG,		  36, a,	1);
 | |
|   add_field(MOV_PROTIVA,	37, n,	5);
 | |
|   add_field(MOV_CODCAUS,	42, a,	3);
 | |
|   add_field(MOV_DESCR,	  45, a,	30);
 | |
|   add_field("L03",	      75, n,	2);	
 | |
|   add_field("L04",	      77, n,	2);	
 | |
|   add_field("L05",	      79, n,	6);	
 | |
|   add_field("L04",	      85, a,	1);
 | |
|   add_field("L05",	      86, n,	2);
 | |
|   add_field("L06",	      88, n,	2);
 | |
|   add_field("L07",	      90, n,	6);
 | |
|   add_field(MOV_CODPAG,   96, a,	2);
 | |
|   add_field(MOV_TOTDOC,   98, n,	11);
 | |
|   add_field(MOV_UPROTIVA, 109, n,	5);
 | |
|   add_field("L08",        114, n,	5);
 | |
|   add_field("L09",     	  119, a,	1);
 | |
|   add_field("L10",     	  120, a,	99);
 | |
|   add_field("L11",     	  219, a,	1);
 | |
|   add_field("L12",     	  220, a,	37);
 | |
| 
 | |
| 	bool ok;
 | |
| 
 | |
| 	for (ok = move_last(); ok;)
 | |
| 	{
 | |
| 		const int p = current_row();
 | |
| 
 | |
| 		if (get("TIPOR").as_string() != "Z1" || get(RMV_NUMRIG).as_int() != 1)
 | |
| 		{
 | |
| 			destroy(p);
 | |
| 			if (p <= last())
 | |
| 				move_to(p);
 | |
| 			else
 | |
| 				move_last();
 | |
| 		}
 | |
| 		else
 | |
| 			ok = move_prev();
 | |
| 	}
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TIVA_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| void TIVA_recset::add_field(const char* name, int from, char tipo, int len, const char* def)
 | |
| {
 | |
| 	const bool required = false;
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   
 | |
| 	if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(name, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(name, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| bool TIVA_recset::find(long numreg)
 | |
| {
 | |
| 	if (numreg != _numreg)
 | |
| 	{
 | |
| 		_first = _last = -1L;
 | |
| 
 | |
| 		TString key;
 | |
| 		
 | |
| 		key.format("%ld", numreg);
 | |
| 	
 | |
| 		TToken_string * val = (TToken_string *) _index.objptr(key);
 | |
| 
 | |
| 		if (val && *val)
 | |
| 		{
 | |
| 			_first = val->get_int();
 | |
| 			_last = val->get_int();
 | |
| 		}
 | |
| 		_numreg = numreg;
 | |
| 	}
 | |
| 	return _first >= 0L;
 | |
| }
 | |
| 
 | |
| const TVariant& TIVA_recset::get(const char* column_name) const
 | |
| {
 | |
| 	const TFixed_string fname(column_name);
 | |
| 
 | |
| 	if (fname == RMI_IMPONIBILE || fname == RMI_IMPOSTA)
 | |
| 	{
 | |
| 		TVariant& var = get_tmp_var();
 | |
| 	
 | |
| 		var.set(TAS400_recordset::get(fname).as_real() / CENTO);
 | |
| 		return var;
 | |
| 	}
 | |
| 	else
 | |
| 		if (fname == RMI_TIPOC)
 | |
| 		{
 | |
| 			TVariant& var = get_tmp_var();
 | |
| 			const TString4 val(app().pconrecset(get(RMI_GRUPPO).as_int(), get(RMI_CONTO).as_int(), 0L).get(PCN_TMCF).as_string());
 | |
| 		
 | |
| 			var.set(val);
 | |
| 			return var;
 | |
| 		}
 | |
| 	return TAS400_recordset::get(fname);
 | |
| }
 | |
| 
 | |
| bool TIVA_recset::move_to(TRecnotype pos)
 | |
| {
 | |
| 	if (_first < 0L)
 | |
| 		return TAS400_recordset::move_to(pos);
 | |
| 	if (pos == 0L)
 | |
| 		pos = _first;
 | |
| 	if (pos <= _last)
 | |
| 		return TAS400_recordset::move_to(pos);
 | |
| 	return false;
 | |
| }
 | |
| 
 | |
| 
 | |
| TIVA_recset::TIVA_recset(const char * query)
 | |
|            : TAS400_recordset(TString("AS400(256)") << query),
 | |
| 						 _first(-1L), _last(-1L), _numreg(-1L)
 | |
| {
 | |
|   const char a = 'a';
 | |
|   const char n = 'n';
 | |
| 
 | |
|   add_field("TIPOR",	      1, n,	2);	
 | |
|   add_field(RMI_NUMREG,	    3, n,	6);
 | |
|   add_field(RMI_NUMRIG,     9, n,	2);
 | |
|   add_field("L01",			  	11, a,	5);
 | |
|   add_field(MOV_CODCF,	  	16, n,	6);
 | |
|   add_field(RMI_IMPONIBILE, 22, n,	11);
 | |
|   add_field(RMI_CODIVA,	    33, n,	2);	
 | |
|   add_field(RMI_IMPOSTA,    35, n,	9);
 | |
|   add_field(RMI_TIPOCR,	    44, n,	1);	
 | |
|   add_field(RMI_TIPODET,    45, n,	1);	
 | |
|   add_field(RMI_GRUPPO,			46, n,	2);
 | |
|   add_field(RMI_CONTO,			48, n,	2);
 | |
|   add_field(RMI_SOTTOCONTO, 50, n,	6);	
 | |
|   add_field("L03",			  	56, a,	6);
 | |
|   add_field("L04",			  	62, a,	25);
 | |
|   add_field("L05",			  	87, a,	22);
 | |
|   add_field("L06",			  	109, a,	18);
 | |
|   add_field("L07",			  	127, n,	5);
 | |
|   add_field("L08",			  	132, a,	2);
 | |
| 	add_field(RMI_TIPOATT,    134, n,	1);	
 | |
|   add_field(RMI_INTRA,	    135, a,	1);	
 | |
|   add_field("L09",			  	136, n,	11);
 | |
|   add_field("L10",			  	147, a,	3);
 | |
|   add_field("L11",			  	150, n,	11);
 | |
|   add_field("L12",			  	161, n,	14);
 | |
|   add_field("L13",			  	175, n,	2);
 | |
|   add_field("L14",			  	177, a,	1);
 | |
|   add_field("L15",			  	177, a,	79);
 | |
| 
 | |
| 	bool ok;
 | |
| 	
 | |
| 	for (ok = move_last(); ok;)
 | |
| 	{
 | |
| 		const int p = current_row();
 | |
| 
 | |
| 		if (get("TIPOR").as_string() != "U1" )
 | |
| 		{
 | |
| 			destroy(p);
 | |
| 			if (p <= last())
 | |
| 				move_to(p);
 | |
| 			else
 | |
| 				move_last();
 | |
| 		}
 | |
| 		else
 | |
| 			ok = move_prev();
 | |
| 	}
 | |
| 	TString16 pos, key;
 | |
| 	
 | |
| 	ok = move_first();
 | |
| 	_numreg = get(RMV_NUMREG).as_int();
 | |
| 	_first = _last = current_row();
 | |
| 
 | |
|   for (ok = move_first(); ok; ok = move_next())
 | |
| 	{
 | |
| 		const long numreg = get(RMV_NUMREG).as_int();
 | |
| 
 | |
| 		if (numreg == _numreg)
 | |
| 			_last = current_row();
 | |
| 		else
 | |
| 		{
 | |
| 			pos.format("%ld|ld", _first, _last);
 | |
| 			key.format("%ld", _numreg);
 | |
| 		
 | |
| 			_index.add(key, pos);
 | |
| 			_numreg = numreg;
 | |
| 			_first = _last = current_row();
 | |
| 		}
 | |
| 	}
 | |
| 	if (_first >= 0)
 | |
| 	{
 | |
| 		pos.format("%ld|ld", _first, _last);
 | |
| 		key.format("%ld", _numreg);
 | |
| 	
 | |
| 		_index.add(key, pos);
 | |
| 	}
 | |
| 	_numreg = 0L;
 | |
| 	_first = _last = -1L;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TRMov_recset
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| void TRMov_recset::add_field(const char* name, int from, char tipo, int len, const char* def)
 | |
| {
 | |
| 	const bool required = false;
 | |
|   const TFieldtypes t = tipo == 'n' ? _longzerofld : _alfafld;
 | |
|   const int pos = from - 1;
 | |
|   
 | |
| 	if (def && *def)
 | |
|   {
 | |
|     CHECKS(def == NULL || (int)strlen(def) <= len, "Invalid default value ", def);
 | |
|     TVariant var(def); var.convert_to(t);
 | |
|     create_field(name, pos, len, t, required, var);
 | |
|   }
 | |
|   else
 | |
|     create_field(name, pos, len, t, required);
 | |
| }
 | |
| 
 | |
| bool TRMov_recset::find(long numreg)
 | |
| {
 | |
| 	if (numreg != _numreg)
 | |
| 	{
 | |
| 		_first = _last = -1L;
 | |
| 
 | |
| 		TString key;
 | |
| 		
 | |
| 		key.format("%ld", numreg);
 | |
| 	
 | |
| 		TToken_string * val = (TToken_string *) _index.objptr(key);
 | |
| 
 | |
| 		if (val && *val)
 | |
| 		{
 | |
| 			_first = val->get_int();
 | |
| 			_last = val->get_int();
 | |
| 		}
 | |
| 		_numreg = numreg;
 | |
| 	}
 | |
| 	return _first >= 0L;
 | |
| }
 | |
| 
 | |
| const TVariant& TRMov_recset::get(const char* column_name) const
 | |
| {
 | |
| 	const TFixed_string fname(column_name);
 | |
| 
 | |
| 	if (fname == RMV_IMPORTO)
 | |
| 	{
 | |
| 		TVariant& var = get_tmp_var();
 | |
| 	
 | |
| 		var.set(TAS400_recordset::get(fname).as_real() / CENTO);
 | |
| 		return var;
 | |
| 	}
 | |
| 	else
 | |
| 		if (fname == RMV_TIPOC)
 | |
| 		{
 | |
| 			TVariant& var = get_tmp_var();
 | |
| 			const TString4 val(app().pconrecset(get(RMV_GRUPPO).as_int(), get(RMV_CONTO).as_int(), 0L).get(PCN_TMCF).as_string());
 | |
| 		
 | |
| 			var.set(val);
 | |
| 			return var;
 | |
| 		}
 | |
| 		else
 | |
| 			if (fname == RMV_TIPOCC)
 | |
| 			{
 | |
| 				TVariant& var = get_tmp_var();
 | |
| 				const TString4 val(app().pconrecset(get(RMV_GRUPPOC).as_int(), get(RMV_CONTOC).as_int(), 0L).get(PCN_TMCF).as_string());
 | |
| 		
 | |
| 				var.set(val);
 | |
| 				return var;
 | |
| 			}
 | |
| 	return TAS400_recordset::get(fname);
 | |
| }
 | |
| 
 | |
| bool TRMov_recset::move_to(TRecnotype pos)
 | |
| {
 | |
| 	if (_first < 0L)
 | |
| 		return TAS400_recordset::move_to(pos);
 | |
| 	if (pos == 0L)
 | |
| 		pos = _first;
 | |
| 	if (pos <= _last)
 | |
| 		return TAS400_recordset::move_to(pos);
 | |
| 	return false;
 | |
| }
 | |
| 
 | |
| TRMov_recset::TRMov_recset(const char * query)
 | |
|            : TAS400_recordset(TString("AS400(256)") << query),
 | |
| 						  _first(-1L), _last(-1L), _numreg(-1L)
 | |
| 
 | |
| {
 | |
|   const char a = 'a';
 | |
|   const char n = 'n';
 | |
| 	TVariant var;
 | |
| 	int row = 1;
 | |
| 	TString4 fgr, fco, fso;
 | |
| 	TVariant sez, tipo;
 | |
| 
 | |
|   add_field("TIPOR",	      1, n,	2);	
 | |
|   add_field(RMV_NUMREG,	    3, n,	6);
 | |
|   add_field(RMV_NUMRIG,      9, n,	2);
 | |
|   add_field("L01",			  	11, a,	5);
 | |
|   add_field(RMV_DATAREG,  	16, a,	6);
 | |
|   add_field("L02",			   	22, a,	1);
 | |
|   add_field("L03",          23, a,	6);
 | |
|   add_field("L04",          29, a,	7);
 | |
|   add_field("L05",          36, a,	1);
 | |
|   add_field("L06",          37, n,	5);
 | |
|   add_field("L07",          42, a,	3);
 | |
|   add_field(RMV_DESCR,			45, a,	30);
 | |
|   add_field(RMV_GRUPPO,     75, n,	2);	
 | |
|   add_field(RMV_CONTO,	    77, n,	2);	
 | |
|   add_field(RMV_SOTTOCONTO, 79, n,	6);	
 | |
|   add_field(RMV_SEZIONE,	  85, a,	1);
 | |
|   add_field(RMV_GRUPPOC,    86, n,	2);
 | |
|   add_field(RMV_CONTOC,     88, n,	2);
 | |
|   add_field(RMV_SOTTOCONTOC,90, n,	6);
 | |
|   add_field("L09",          96, a,	2);
 | |
|   add_field(RMV_IMPORTO,    98, n,	11);
 | |
|   add_field("L10",          109, n,	5);
 | |
|   add_field("L11",          114, n,	5);
 | |
|   add_field("L12",       	  119, a,	1);
 | |
|   add_field("L13",      	  120, a,	99);
 | |
|   add_field("L14",       	  219, a,	1);
 | |
|   add_field("L15",      	  220, a,	37);
 | |
| 
 | |
| 	bool ok;
 | |
| 	
 | |
| 	for (ok = move_last(); ok;)
 | |
| 	{
 | |
| 		const int p = current_row();
 | |
| 
 | |
| 		if (get("TIPOR").as_string() != "Z1" || get(RMV_NUMRIG).as_int() != 1)
 | |
| 		{
 | |
| 			destroy(p);
 | |
| 			if (p <= last())
 | |
| 				move_to(p);
 | |
| 			else
 | |
| 				move_last();
 | |
| 		}
 | |
| 		else
 | |
| 			ok = move_prev();
 | |
| 	}
 | |
| 	TString16 pos, key;
 | |
| 	
 | |
| 	ok = move_first();
 | |
| 	_numreg = get(RMV_NUMREG).as_int();
 | |
| 	_first = _last = current_row();
 | |
| 
 | |
|   for (ok = move_first(); ok; ok = move_next())
 | |
| 	{
 | |
| 		const long numreg = get(RMV_NUMREG).as_int();
 | |
| 
 | |
| 		if (numreg == _numreg)
 | |
| 			_last = current_row();
 | |
| 		else
 | |
| 		{
 | |
| 			pos.format("%ld|ld", _first, _last);
 | |
| 			key.format("%ld", _numreg);
 | |
| 		
 | |
| 			_index.add(key, pos);
 | |
| 			_numreg = numreg;
 | |
| 			_first = _last = current_row();
 | |
| 		}
 | |
| 	}
 | |
| 	if (_first >= 0)
 | |
| 	{
 | |
| 		pos.format("%ld|ld", _first, _last);
 | |
| 		key.format("%ld", _numreg);
 | |
| 	
 | |
| 		_index.add(key, pos);
 | |
| 	}
 | |
| 	_numreg = 0L;
 | |
| 	_first = _last = -1L;
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TTransfer_mask
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| TTransfer_mask::TTransfer_mask() : TAutomask("tc0900a")
 | |
| {
 | |
|   serialize(false);
 | |
| }
 | |
| 
 | |
| TTransfer_mask::~TTransfer_mask()
 | |
| {
 | |
|   serialize(true);
 | |
| }
 | |
| 
 | |
| bool TTransfer_mask::on_field_event(TOperable_field& f, TField_event e, long jolly)
 | |
| { 
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| HIDDEN bool browse_file_handler(TMask_field& f, KEY k)
 | |
| {
 | |
|   if (k == K_F9)
 | |
|   {  
 | |
|     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();
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| void TTransfer_mask::serialize(bool bSave)
 | |
| {
 | |
|   const char* defpar = "tc";
 | |
|   TConfig ini(CONFIG_DITTA, defpar);
 | |
|   for (int i = fields()-1; i >= 0; i--)
 | |
|   {
 | |
|     TMask_field& f = fld(i);
 | |
|     const TFieldref* fr = f.field();
 | |
|     if (fr != NULL)
 | |
|     {
 | |
|       if (bSave)
 | |
|         fr->write(ini, defpar, f.get());
 | |
|       else
 | |
|         f.set(fr->read(ini, defpar));
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // TTransfer_sender
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| TMask & TTransfer_sender::get_mask()
 | |
| {
 | |
| 	if (_mask == NULL)
 | |
| 		_mask = new TTransfer_mask;
 | |
| 
 | |
| 	return * _mask;
 | |
| }
 | |
| 
 | |
| const char * TTransfer_sender::decode_causale(const TRecordset& mov)
 | |
| {
 | |
|   return causrecset(mov).get(CAU_DESCR).as_string();
 | |
| }
 | |
| 
 | |
| TRecordset & TTransfer_sender::movrecset()
 | |
| {
 | |
| 
 | |
| 	TRecordset * mov = get_recset(LF_MOV);
 | |
| 
 | |
| 	if (mov == NULL)
 | |
| 	{
 | |
| 		TString query("SELECT * FROM ");
 | |
| 		TMask & m = get_mask();
 | |
| 		TFilename name = m.get(F_INPATH);
 | |
| 
 | |
| 		if (name.blank())
 | |
| 			name= "TRASFER";
 | |
| 		name.add(m.get(F_INFILET));
 | |
| 		query << name;
 | |
| 
 | |
| 		mov = set_recset(LF_MOV, new TMov_recset(query));
 | |
| 	}
 | |
| 	return *mov;
 | |
| }
 | |
| 
 | |
| TRecordset & TTransfer_sender::rmovrecset(const TRecordset & mov)
 | |
| {
 | |
| 	TRecordset * rmov = get_recset(LF_RMOV);
 | |
| 
 | |
| 	if (rmov == NULL)
 | |
| 	{
 | |
| 		TString query("SELECT * FROM ");
 | |
| 		TMask & m = get_mask();
 | |
| 		TFilename name = m.get(F_INPATH);
 | |
| 
 | |
| 		if (name.blank())
 | |
| 			name= "TRASFER";
 | |
| 		name.add(m.get(F_INFILET));
 | |
| 		query << name;
 | |
| 
 | |
| 		rmov = set_recset(LF_RMOV, new TRMov_recset(query));
 | |
| 	}
 | |
| 	return *rmov;
 | |
| }
 | |
| 
 | |
| TRecordset & TTransfer_sender::rivarecset(const TRecordset & mov)
 | |
| {
 | |
| 	TRecordset * rmoviva = get_recset(LF_RMOVIVA);
 | |
| 
 | |
| 	if (rmoviva == NULL)
 | |
| 	{
 | |
| 		TString query("SELECT * FROM ");
 | |
| 		TMask & m = get_mask();
 | |
| 		TFilename name = m.get(F_INPATH);
 | |
| 
 | |
| 		if (name.blank())
 | |
| 			name= "TRASFER";
 | |
| 		name.add(m.get(F_INFILET));
 | |
| 		query << name;
 | |
| 
 | |
| 		rmoviva = set_recset(LF_RMOVIVA, new TIVA_recset(query));
 | |
| 	}
 | |
| 	return *rmoviva;
 | |
| }
 | |
| 
 | |
| const TRecordset& TTransfer_sender::clirecset(const char tipocf, const long codcf)
 | |
| {
 | |
| 	TClifo_recset * clifo = (TClifo_recset *) get_recset(LF_CLIFO);
 | |
| 
 | |
| 	if (clifo == NULL)
 | |
| 	{
 | |
| 		TString query("SELECT * FROM ");
 | |
| 		TMask & m = get_mask();
 | |
| 		TFilename name = m.get(F_INPATH);
 | |
| 
 | |
| 		name.add(m.get(F_INFILET));
 | |
| 		query << name;
 | |
| 
 | |
| 		clifo = (TClifo_recset *) set_recset(LF_CLIFO, new TClifo_recset(query));
 | |
| 	}
 | |
| 
 | |
| 	if (!clifo->find(tipocf, codcf))
 | |
| 	{
 | |
| 		TString msg(tipocf == 'C' ? "Cliente " : "Fornitore ");
 | |
| 
 | |
| 		msg << codcf << " assente"; 
 | |
| 		app().log(2, msg);
 | |
| 	}
 | |
| 
 | |
| 	return *clifo;
 | |
| }
 | |
| 
 | |
| const TRecordset& TTransfer_sender::pconrecset(const int gruppo, int conto, long sottoconto)
 | |
| {
 | |
| 	TPCon_recset * pcon = (TPCon_recset *) get_recset(LF_PCON);
 | |
| 
 | |
| 	if (pcon == NULL)
 | |
| 	{
 | |
| 		TString query("SELECT * FROM ");
 | |
| 		TMask & m = get_mask();
 | |
| 		TFilename name = m.get(F_INPATH);
 | |
| 
 | |
| 		name.add(m.get(F_INFILET));
 | |
| 		query << name;
 | |
| 
 | |
| 		pcon = (TPCon_recset *) set_recset(LF_PCON, new TPCon_recset(query));
 | |
| 	}
 | |
| 
 | |
| 	if (!pcon->find(gruppo, conto, sottoconto))
 | |
| 	{
 | |
| 		TString msg("Conto ");
 | |
| 
 | |
| 		msg << gruppo << '.' << conto << '.' << sottoconto << " assente"; 
 | |
| 		app().log(2, msg);
 | |
| 	}
 | |
| 
 | |
| 	return *pcon;
 | |
| }
 | |
| 
 | |
| const TRecordset& TTransfer_sender::causrecset(const TRecordset & mov)
 | |
| {
 | |
| 	TCausali_recset * caus = (TCausali_recset *) get_recset(LF_CAUSALI);
 | |
| 
 | |
| 	if (caus == NULL)
 | |
| 	{
 | |
| 		TString query("SELECT * FROM ");
 | |
| 		TMask & m = get_mask();
 | |
| 		TFilename name = m.get(F_INPATH);
 | |
| 
 | |
| 		name.add(m.get(F_INFILET));
 | |
| 		query << name;
 | |
| 
 | |
| 		caus = (TCausali_recset *) set_recset(LF_CLIFO, new TCausali_recset(query));
 | |
| 	}
 | |
| 
 | |
| 	const TString8 codcaus(mov.get(MOV_CODCAUS).as_string());
 | |
| 
 | |
| 	if (!caus->find(codcaus))
 | |
| 	{
 | |
| 		TString msg("Causale ");
 | |
| 
 | |
| 		msg <<  codcaus << " assente"; 
 | |
| 		app().log(2, msg);
 | |
| 	}
 | |
| 
 | |
| 	return *caus;
 | |
| }
 | |
| 
 | |
| bool TTransfer_sender::find_regolarizzazione(TRecordset& mov)
 | |
| {
 | |
| 	bool found = false;
 | |
|   const TRecordset & caus = causrecset(mov);
 | |
| 	const TString16 causreg =	caus.get(CAU_CODCAUREG).as_string();  // verificare
 | |
| 	real totdoc = mov.get(MOV_TOTDOC).as_real();
 | |
| 	const real ritfis = mov.get(MOV_RITFIS).as_real();
 | |
| 	const real ritsoc = mov.get(MOV_RITSOC).as_real();
 | |
| 
 | |
| 	if (ritfis != ZERO)
 | |
| 		totdoc += ritfis;
 | |
|   if (ritsoc != ZERO)
 | |
| 	{
 | |
| 		if (swap_ritsoc(mov))                      // Somma ritenute sociali con segno
 | |
| 			totdoc -= ritsoc;
 | |
| 	  else
 | |
| 		  totdoc += ritsoc;                        
 | |
| 	}
 | |
|   if (test_swap(mov))
 | |
| 		totdoc = -totdoc;
 | |
| 
 | |
| 	const TRecordset & cli = clirecset(mov.get(MOV_TIPO).as_string()[0], mov.get(MOV_CODCF).as_int());
 | |
| 	const TString16 paiv = cli.get(CLI_PAIV).as_string();
 | |
| 	const TString16 cf = cli.get(CLI_COFI).as_string();
 | |
| 
 | |
| 	for (bool ok = mov.move_next(); ok && ! found; ok = mov.move_next())
 | |
| 	{
 | |
| 		const TRecordset & clireg = clirecset(mov.get(MOV_TIPO).as_string()[0], mov.get(MOV_CODCF).as_int());
 | |
| 
 | |
| 		found = ((paiv.full() && paiv == clireg.get(CLI_PAIV).as_string()) || (paiv.blank() && cf == clireg.get(CLI_COFI).as_string()));
 | |
| 
 | |
| 		if (found)
 | |
| 		{
 | |
| 			const TRecordset & caus = causrecset(mov);
 | |
| 			const TString16 cod = caus.get(CAU_CODCAUS).as_string();
 | |
| 		
 | |
| 			found &= (causreg.full() && cod == causreg); // || (causreg.blank() && (_caus_regolarizzazione.objptr(cod) || caus.get_bool(CAU_SOLOIVA)));
 | |
| 			found &= (totdoc == mov.get(MOV_TOTDOC).as_real());
 | |
| 		
 | |
| 			if (found)
 | |
| 				break;
 | |
| 		}
 | |
| 	}
 | |
| 
 | |
| 	return found;
 | |
| }
 | |
| 
 | |
| bool TTransfer_sender::swap_ritsoc(const TRecordset& mov)
 | |
| {
 | |
| 	TRecordset & rmov = rmovrecset(mov);
 | |
|   bool ok = rmov.move_first();
 | |
|   const char sez = rmov.get(RMV_SEZIONE).as_string()[0];
 | |
| 	char sezrit = sez;
 | |
| 
 | |
| 	for (; ok; ok = rmov.move_next())
 | |
| 	{
 | |
| 		const char tiporiga = rmov.get(RMV_ROWTYPE).as_string()[0];
 | |
| 
 | |
| 		if (tiporiga =='S')
 | |
| 		{
 | |
| 		  sezrit = rmov.get(RMV_SEZIONE).as_string()[0];
 | |
| 			break;
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
|   const bool s = sez != sezrit;
 | |
|   return s;
 | |
| }
 | |
| 
 | |
| bool TTransfer_sender::mov_regolarizzazione(const TRecordset& mov)
 | |
| {
 | |
|   const TString& codcaus = mov.get(MOV_CODCAUS).as_string();
 | |
| 
 | |
| 	return false; // verificare _caus_regolarizzazione.objptr(codcaus) != NULL;
 | |
| }
 | |
| 
 | |
| bool TTransfer_sender::mov_reverse_charge(const TRecordset& mov)
 | |
| {
 | |
| 	const int	regsp = iva11_reverse(mov);
 | |
| 
 | |
| 	return regsp == 13 || regsp == 50 || regsp == 51;
 | |
| }
 | |
| 
 | |
| int tc0900(int argc, char* argv[])
 | |
| {
 | |
|   TTransfer_sender app;
 | |
|   app.run(argc, argv, "Invio a TeamSystem da transfer AS400");
 | |
|   return 0;
 | |
| }
 |