Patch level : nopatch
Files correlati : Commento : Implementazione FP
This commit is contained in:
		
							parent
							
								
									cce5377cc4
								
							
						
					
					
						commit
						60a52ab73d
					
				| @ -10,6 +10,8 @@ | |||||||
| #include "../cg/cfban.h" | #include "../cg/cfban.h" | ||||||
| #include <alleg.h> | #include <alleg.h> | ||||||
| #include <anagr.h> | #include <anagr.h> | ||||||
|  | #include <clifo.h> | ||||||
|  | #include <cfven.h> | ||||||
| #include <doc.h> | #include <doc.h> | ||||||
| #include <effetti.h> | #include <effetti.h> | ||||||
| #include <anafis.h> | #include <anafis.h> | ||||||
| @ -385,150 +387,158 @@ bool TAnagrafica::init(const TRectype& rec) | |||||||
| 		} | 		} | ||||||
| 		_pec = ""; | 		_pec = ""; | ||||||
| 		_cod_EORI = rec.get(NDT_CODEORI); | 		_cod_EORI = rec.get(NDT_CODEORI); | ||||||
| 		_coddest = rec.get(NDT_CODDEST); | 		_coddest = rec.get(NDT_PADESTIN); | ||||||
| 		_pec = rec.get(NDT_PEC); | 		_pec = rec.get(NDT_PEC); | ||||||
| 		return good; | 		return good; | ||||||
| 	} | 	} | ||||||
| 	break; | 	break; | ||||||
| 	case LF_CLIFO: | 	case LF_CLIFO: | ||||||
| 		_cod_EORI = rec.get(ANA_CODEORI); |  | ||||||
| 		_allegato = rec.get_int(CLI_ALLEG); |  | ||||||
| 		if (_allegato == 4) |  | ||||||
| 		{ | 		{ | ||||||
| 			const long ca = rec.get_long(CLI_CODALLEG); | 			_cod_EORI = rec.get(ANA_CODEORI); | ||||||
| 			if (ca > 0) | 			_allegato = rec.get_int(CLI_ALLEG); | ||||||
| 				return init(rec.get_char(CLI_TIPOCF), ca, EMPTY_STRING); | 			if (_allegato == 4) | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		_tipo = ' '; // Non faccio assunzioni sulla persona fisica
 |  | ||||||
| 
 |  | ||||||
| 		is_firm = (rec.get_char(CLI_TIPOPERS) == 'G' || rec.get_char(CLI_TIPOAPER) == 'G' || _allegato == 7) && (_allegato != 6); |  | ||||||
| 		if (!is_firm && rec.get(CLI_PAIV).full()) |  | ||||||
| 		{ |  | ||||||
| 			TString80 rs = rec.get(CLI_RAGSOC); rs.lower(); |  | ||||||
| 			const char* soc[] = { "&", "azienda ", " sas ", " s.a.s.", " snc", " s.n.c.", " srl", " s.r.l.", |  | ||||||
| 														"coop.", "cooperativa", " s.n.c.", " srl", " s.r.l.", " s.p.a", " s.a.", NULL }; |  | ||||||
| 			for (int s = 0; soc[s] && !is_firm; s++) |  | ||||||
| 				is_firm = rs.find(soc[s]) > 0; |  | ||||||
| 			if (!is_firm) |  | ||||||
| 				is_firm = rs.ends_with(" spa") || (rs.find(" di ") > 15);  // Shopping Point di Karoline Reiner
 |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		if (!is_firm) |  | ||||||
| 		{ |  | ||||||
| 			bool has_cofi = false;  // Codice fiscale alfanumerico?
 |  | ||||||
| 			const TString& cli_cofi = rec.get(CLI_COFI); |  | ||||||
| 			if (cli_cofi.full() && isalpha(cli_cofi[0])) |  | ||||||
| 				has_cofi = cf_check(rec.get(CLI_STATOPAIV), cli_cofi); |  | ||||||
| 
 |  | ||||||
| 			// Persona Fisica?
 |  | ||||||
| 			if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get_date(CLI_DATANASC).ok() || has_cofi || _allegato == 6) |  | ||||||
| 			{ | 			{ | ||||||
| 				const long cod = rec.get_long(CLI_CODANAGPER); // Percipiente?
 | 				const long ca = rec.get_long(CLI_CODALLEG); | ||||||
| 				if (cod > 0) | 				if (ca > 0) | ||||||
| 					init(LF_ANAG, 'F', cod); | 					return init(rec.get_char(CLI_TIPOCF), ca, EMPTY_STRING); | ||||||
|  | 			} | ||||||
| 
 | 
 | ||||||
| 				_tipo = 'F'; | 			_tipo = ' '; // Non faccio assunzioni sulla persona fisica
 | ||||||
| 				_data_nasc = rec.get_date(CLI_DATANASC); |  | ||||||
| 				if (!_data_nasc.ok() && has_cofi) |  | ||||||
| 				{ |  | ||||||
| 					char sex = 'X'; |  | ||||||
| 					decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc); |  | ||||||
| 				} |  | ||||||
| 
 | 
 | ||||||
| 				if (_com_nasc.blank()) | 			is_firm = (rec.get_char(CLI_TIPOPERS) == 'G' || rec.get_char(CLI_TIPOAPER) == 'G' || _allegato == 7) && (_allegato != 6); | ||||||
|  | 			if (!is_firm && rec.get(CLI_PAIV).full()) | ||||||
|  | 			{ | ||||||
|  | 				TString80 rs = rec.get(CLI_RAGSOC); rs.lower(); | ||||||
|  | 				const char* soc[] = { "&", "azienda ", " sas ", " s.a.s.", " snc", " s.n.c.", " srl", " s.r.l.", | ||||||
|  | 															"coop.", "cooperativa", " s.n.c.", " srl", " s.r.l.", " s.p.a", " s.a.", NULL }; | ||||||
|  | 				for (int s = 0; soc[s] && !is_firm; s++) | ||||||
|  | 					is_firm = rs.find(soc[s]) > 0; | ||||||
|  | 				if (!is_firm) | ||||||
|  | 					is_firm = rs.ends_with(" spa") || (rs.find(" di ") > 15);  // Shopping Point di Karoline Reiner
 | ||||||
|  | 			} | ||||||
|  | 
 | ||||||
|  | 			if (!is_firm) | ||||||
|  | 			{ | ||||||
|  | 				bool has_cofi = false;  // Codice fiscale alfanumerico?
 | ||||||
|  | 				const TString& cli_cofi = rec.get(CLI_COFI); | ||||||
|  | 				if (cli_cofi.full() && isalpha(cli_cofi[0])) | ||||||
|  | 					has_cofi = cf_check(rec.get(CLI_STATOPAIV), cli_cofi); | ||||||
|  | 
 | ||||||
|  | 				// Persona Fisica?
 | ||||||
|  | 				if (rec.get_char(CLI_TIPOAPER) == 'F' || rec.get_date(CLI_DATANASC).ok() || has_cofi || _allegato == 6) | ||||||
| 				{ | 				{ | ||||||
| 					_com_nasc = rec.get(CLI_COMNASC); | 					const long cod = rec.get_long(CLI_CODANAGPER); // Percipiente?
 | ||||||
| 					if (_com_nasc.blank() && has_cofi) | 					if (cod > 0) | ||||||
|  | 						init(LF_ANAG, 'F', cod); | ||||||
|  | 
 | ||||||
|  | 					_tipo = 'F'; | ||||||
|  | 					_data_nasc = rec.get_date(CLI_DATANASC); | ||||||
|  | 					if (!_data_nasc.ok() && has_cofi) | ||||||
| 					{ | 					{ | ||||||
| 						char sex = 'X'; | 						char sex = 'X'; | ||||||
| 						decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc); | 						decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc); | ||||||
| 					} | 					} | ||||||
| 				} | 
 | ||||||
| 				if (_stato_nasc <= 0) | 					if (_com_nasc.blank()) | ||||||
| 					_stato_nasc = rec.get_int(CLI_STATONASC); |  | ||||||
| 				if (_com_nasc.blank() && _stato_nasc > 0) |  | ||||||
| 				{ |  | ||||||
| 					TString4 sn; sn.format("%03d", _stato_nasc); |  | ||||||
| 					const TString80 stato = cache().get("%STA", sn, "S0"); |  | ||||||
| 					TISAM_recordset comuni("USE COMUNI\nFROM COM=Z\nTO STATO=\"0~\""); |  | ||||||
| 					double best = 0.8; |  | ||||||
| 					for (bool ok = comuni.move_first(); ok; ok = comuni.move_next()) |  | ||||||
| 					{ | 					{ | ||||||
| 						const TString& desc = comuni.get(COM_DENCOM).as_string(); | 						_com_nasc = rec.get(CLI_COMNASC); | ||||||
| 						const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato); | 						if (_com_nasc.blank() && has_cofi) | ||||||
| 						if (score > best) |  | ||||||
| 						{ | 						{ | ||||||
| 							best = score; | 							char sex = 'X'; | ||||||
| 							_stato_nasc = 0; | 							decode_cofi(cli_cofi, sex, _data_nasc, _com_nasc); | ||||||
| 							_com_nasc = comuni.get(COM_COM).as_string(); | 						} | ||||||
| 							if (best >= 1.0) | 					} | ||||||
| 								break; | 					if (_stato_nasc <= 0) | ||||||
|  | 						_stato_nasc = rec.get_int(CLI_STATONASC); | ||||||
|  | 					if (_com_nasc.blank() && _stato_nasc > 0) | ||||||
|  | 					{ | ||||||
|  | 						TString4 sn; sn.format("%03d", _stato_nasc); | ||||||
|  | 						const TString80 stato = cache().get("%STA", sn, "S0"); | ||||||
|  | 						TISAM_recordset comuni("USE COMUNI\nFROM COM=Z\nTO STATO=\"0~\""); | ||||||
|  | 						double best = 0.8; | ||||||
|  | 						for (bool ok = comuni.move_first(); ok; ok = comuni.move_next()) | ||||||
|  | 						{ | ||||||
|  | 							const TString& desc = comuni.get(COM_DENCOM).as_string(); | ||||||
|  | 							const double score = xvt_str_fuzzy_compare_ignoring_case(desc, stato); | ||||||
|  | 							if (score > best) | ||||||
|  | 							{ | ||||||
|  | 								best = score; | ||||||
|  | 								_stato_nasc = 0; | ||||||
|  | 								_com_nasc = comuni.get(COM_COM).as_string(); | ||||||
|  | 								if (best >= 1.0) | ||||||
|  | 									break; | ||||||
|  | 							} | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		// Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
 | 			// Assegno codice fiscale e partita IVA se validi, altrimenti mantengo quelli dell'anagrafica
 | ||||||
| 
 | 
 | ||||||
| 		_cofi = rec.get(CLI_COFI); | 			_cofi = rec.get(CLI_COFI); | ||||||
| 		_paiv = rec.get(CLI_PAIV); | 			_paiv = rec.get(CLI_PAIV); | ||||||
| 		_stato_paiv = rec.get(CLI_STATOPAIV); | 			_stato_paiv = rec.get(CLI_STATOPAIV); | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 		if (_allegato != 5 && _allegato != 9) | 			if (_allegato != 5 && _allegato != 9) | ||||||
| 		{ |  | ||||||
| 			if (_stato_paiv.blank() || _stato_paiv == "IT") |  | ||||||
| 			{ | 			{ | ||||||
| 				// Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota!
 | 				if (_stato_paiv.blank() || _stato_paiv == "IT") | ||||||
| 				// I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente.
 |  | ||||||
| 				if (_paiv.blank() && pi_check(_stato_paiv, _cofi) && _cofi[0] < '8') |  | ||||||
| 					_paiv = _cofi; |  | ||||||
| 				if (_paiv.len() == 11 && pi_check(_stato_paiv, _paiv) && (_paiv[0] == '8' || _paiv[0] == '9')) |  | ||||||
| 				{ | 				{ | ||||||
| 					if (_cofi.blank()) | 					// Ci sono anagrafiche con codice fiscale numerico e partita IVA vuota!
 | ||||||
| 						_cofi = _paiv; | 					// I codici fiscali che cominciano per 8 e 9 sono le associazioni riconosciute e non, rispettivamente.
 | ||||||
| 					_paiv.cut(0); | 					if (_paiv.blank() && pi_check(_stato_paiv, _cofi) && _cofi[0] < '8') | ||||||
|  | 						_paiv = _cofi; | ||||||
|  | 					if (_paiv.len() == 11 && pi_check(_stato_paiv, _paiv) && (_paiv[0] == '8' || _paiv[0] == '9')) | ||||||
|  | 					{ | ||||||
|  | 						if (_cofi.blank()) | ||||||
|  | 							_cofi = _paiv; | ||||||
|  | 						_paiv.cut(0); | ||||||
|  | 					} | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
| 		} |  | ||||||
| 
 | 
 | ||||||
| 		// Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
 | 			// Prevale sempre la ragione sociale del cliente: "Il cliente ha sempre ragione".
 | ||||||
| 		_ragsoc = rec.get(CLI_RAGSOC); | 			_ragsoc = rec.get(CLI_RAGSOC); | ||||||
| 
 | 
 | ||||||
| 		_loc_res = rec.get(CLI_LOCCF); | 			_loc_res = rec.get(CLI_LOCCF); | ||||||
| 		_cap_res = rec.get(CLI_CAPCF); | 			_cap_res = rec.get(CLI_CAPCF); | ||||||
| 		_stato_estero = rec.get_int(CLI_STATOCF); | 			_stato_estero = rec.get_int(CLI_STATOCF); | ||||||
| 		if (_stato_estero <= 0 && (_allegato == 5 || _allegato == 9)) // Estero CEE o extra-CEE
 | 			if (_stato_estero <= 0 && (_allegato == 5 || _allegato == 9)) // Estero CEE o extra-CEE
 | ||||||
| 			_stato_estero = -1; // Stato estero ignoto
 | 				_stato_estero = -1; // Stato estero ignoto
 | ||||||
| 		_com_res = rec.get(CLI_COMCF); | 			_com_res = rec.get(CLI_COMCF); | ||||||
| 		build_ind_res(rec, CLI_INDCF, CLI_CIVCF); | 			build_ind_res(rec, CLI_INDCF, CLI_CIVCF); | ||||||
| 
 | 
 | ||||||
| 		if (_tipo != 'F' && _tipo != 'G') | 			if (_tipo != 'F' && _tipo != 'G') | ||||||
| 		{ |  | ||||||
| 			switch (_allegato) |  | ||||||
| 			{ | 			{ | ||||||
| 			case  6: _tipo = 'F'; break; // Privato
 | 				switch (_allegato) | ||||||
| 			case  7: _tipo = 'G'; break; // Ente pubblico
 |  | ||||||
| 			case  8: _tipo = 'G'; break; // Fallimento
 |  | ||||||
| 			default: |  | ||||||
| 				if (_com_nasc.full()) |  | ||||||
| 					_tipo = 'F'; |  | ||||||
| 				else |  | ||||||
| 				{ | 				{ | ||||||
| 					_tipo = rec.get_char(CLI_TIPOPERS); | 				case  6: _tipo = 'F'; break; // Privato
 | ||||||
| 					if (_tipo != 'F' || is_firm) | 				case  7: _tipo = 'G'; break; // Ente pubblico
 | ||||||
| 						_tipo = 'G'; | 				case  8: _tipo = 'G'; break; // Fallimento
 | ||||||
|  | 				default: | ||||||
|  | 					if (_com_nasc.full()) | ||||||
|  | 						_tipo = 'F'; | ||||||
|  | 					else | ||||||
|  | 					{ | ||||||
|  | 						_tipo = rec.get_char(CLI_TIPOPERS); | ||||||
|  | 						if (_tipo != 'F' || is_firm) | ||||||
|  | 							_tipo = 'G'; | ||||||
|  | 					} | ||||||
|  | 					break; | ||||||
| 				} | 				} | ||||||
| 				break; |  | ||||||
| 			} | 			} | ||||||
|  | 			if (_tipo == 'G' || _ragsoc.len() <= 30) | ||||||
|  | 				split_ragsoc(); | ||||||
|  | 			_cod_EORI = rec.get(CLI_CODEORI); | ||||||
|  | 			TToken_string key = rec.get(CLI_TIPOCF); | ||||||
|  | 
 | ||||||
|  | 			key.add(rec.get(CLI_CODCF)); | ||||||
|  | 
 | ||||||
|  | 			const TRectype & cfven = cache().get(LF_CFVEN, key); | ||||||
|  | 
 | ||||||
|  | 			_coddest = cfven.get(CFV_PADESTIN); | ||||||
|  | 			_pec = rec.get(CLI_PEC); | ||||||
| 		} | 		} | ||||||
| 		if (_tipo == 'G' || _ragsoc.len() <= 30) |  | ||||||
| 			split_ragsoc(); |  | ||||||
| 		_cod_EORI = rec.get(CLI_CODEORI); |  | ||||||
| 		_coddest = rec.get(CFV_PADESTIN); |  | ||||||
| 		_pec = rec.get(CLI_PEC); |  | ||||||
| 		break; | 		break; | ||||||
| 	case LF_MOV: | 	case LF_MOV: | ||||||
| 		return init(rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF), rec.get(MOV_OCFPI)); | 		return init(rec.get_char(MOV_TIPO), rec.get_long(MOV_CODCF), rec.get(MOV_OCFPI)); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user