Correzioni per Aerea
git-svn-id: svn://10.65.10.50/branches/R_10_00@22883 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									1b64d55829
								
							
						
					
					
						commit
						f6f643fa96
					
				| @ -752,7 +752,7 @@ END | ||||
| 
 | ||||
| STRING F_E_PIVA_HARDY 12 | ||||
| BEGIN | ||||
|   PROMPT 2 4 "Partita IVA Hardy         " | ||||
|   PROMPT 2 4 "Partita IVA Hardy/Aerea   " | ||||
|   HELP "Partita IVA Hardy" | ||||
|   FIELD Esselunga_PIvaHardy | ||||
| END | ||||
| @ -766,9 +766,10 @@ END | ||||
| 
 | ||||
| NUMBER F_E_COD_HARDY 6 | ||||
| BEGIN | ||||
|   PROMPT 2 6 "Cod. fornitore Hardy      " | ||||
|   PROMPT 2 6 "Cod. fornitore Hardy/Aerea" | ||||
|   HELP "Codice fornitore Hardy presso Esselunga" | ||||
|   FIELD Esselunga_CodHardy | ||||
|   FLAGS "Z" | ||||
| END	 | ||||
| 
 | ||||
| NUMBER F_E_COD_ESSELUNGA 6 | ||||
|  | ||||
							
								
								
									
										185
									
								
								ha/ha0500.cpp
									
									
									
									
									
								
							
							
						
						
									
										185
									
								
								ha/ha0500.cpp
									
									
									
									
									
								
							| @ -4,6 +4,7 @@ | ||||
| #include <recarray.h> | ||||
| #include <recset.h> | ||||
| #include <reputils.h> | ||||
| #include <utility.h> | ||||
| 
 | ||||
| #include <doc.h> | ||||
| #include <rdoc.h> | ||||
| @ -32,22 +33,77 @@ bool THardy_elab_docs_mask::on_field_event(TOperable_field& o, TField_event e, l | ||||
| {  | ||||
| 	switch (o.dlg()) | ||||
| 	{ | ||||
|   case F_ADATA: | ||||
|     if (e == fe_close || e == fe_modify) | ||||
|   case F_DADATA: | ||||
|     if ((e == fe_close || e == fe_modify) && !o.empty()) | ||||
|     { | ||||
|       //se la data iniziale è piena -> l'anno deve essere lo stesso nelle 2 date;
 | ||||
|       //se invece è vuota -> la data iniziale viene presa come la data iniziale dell'esercizio della data finale...
 | ||||
|       //..ma questo qui non serve e viene rinviato alla query principale del recordset
 | ||||
|       const TDate adata = get_date(F_ADATA); | ||||
|       TEsercizi_contabili esc; | ||||
|       const int adata_esc = esc.date2esc(adata); | ||||
| 
 | ||||
|       TDate dadata = o.get(); | ||||
|       if (dadata.ok()) | ||||
|       TDate da_data = o.get(); | ||||
|       const TDate a_data = get_date(F_ADATA); | ||||
|       if (da_data.ok()) | ||||
|       { | ||||
|         const int dadata_esc = esc.date2esc(dadata); | ||||
|         if (adata_esc != dadata_esc) | ||||
|           return error_box(TR("Le date devono appartenere allo stesso esercizio!")); | ||||
|         bool changed = false; | ||||
|         if (da_data.day() != 1) | ||||
|         { | ||||
|           da_data.set_day(1); | ||||
|           changed = true; | ||||
|         } | ||||
|         const int tc = get_int(F_TIPOCONTR); | ||||
|         if (tc != 8)  // non è nolo
 | ||||
|         { | ||||
|           const int m = da_data.month(); | ||||
|           const int r = m % 3; | ||||
|           if (r != 1) | ||||
|           { | ||||
|             da_data.set_month(m - (r == 0 ? 2 : (r-1))); | ||||
|             changed = true; | ||||
|           } | ||||
|         } | ||||
|         if (changed) | ||||
|           o.set(da_data.string()); | ||||
|       } | ||||
|     } | ||||
|     break; | ||||
|   case F_ADATA: | ||||
|     if ((e == fe_close || e == fe_modify) && !o.empty()) | ||||
|     { | ||||
|       TDate d = o.get(); | ||||
|       if (d.ok()) | ||||
|       { | ||||
|         bool changed = false; | ||||
|         const int tc = get_int(F_TIPOCONTR); | ||||
|         if (tc != 8)  // Non è nolo
 | ||||
|         { | ||||
|           const int m = d.month(); | ||||
|           const int r = m % 3; | ||||
|           if (r != 0) | ||||
|           { | ||||
|             d.set_month(m + 3 - r); | ||||
|             changed = true; | ||||
|           } | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|           TDate da_data = d;  | ||||
|           da_data.set_day(1); | ||||
|           set(F_DADATA, da_data); | ||||
|         } | ||||
| 
 | ||||
|         if (!d.is_end_month()) | ||||
|         { | ||||
|           d.set_end_month(); | ||||
|           changed = true; | ||||
|         } | ||||
|         if (changed) | ||||
|           o.set(d.string()); | ||||
| 
 | ||||
|         if (e == fe_close) | ||||
|         { | ||||
|           const TDate dal = get(F_DADATA); | ||||
|           if (dal.ok() && dal.year() != d.year()) | ||||
|             return error_box(TR("Le date devono appartenere allo stesso anno!")); | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|     break; | ||||
| @ -56,15 +112,15 @@ bool THardy_elab_docs_mask::on_field_event(TOperable_field& o, TField_event e, l | ||||
|   case F_DEFINITIVO: | ||||
|     if (e == fe_modify)    | ||||
|     { | ||||
|       if (o.get() == "X") | ||||
|       if (o.get().full()) | ||||
|       { | ||||
|         set(F_KILLPROVV, "X"); | ||||
|         disable(F_KILLPROVV); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         reset(F_KILLPROVV); | ||||
|         enable(F_KILLPROVV); | ||||
|         set(F_KILLPROVV, " "); | ||||
|       } | ||||
|     } | ||||
|     break; | ||||
| @ -74,8 +130,6 @@ bool THardy_elab_docs_mask::on_field_event(TOperable_field& o, TField_event e, l | ||||
|   return true; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| ///////////////////////////////////////
 | ||||
| // TSkeleton_application
 | ||||
| ///////////////////////////////////////
 | ||||
| @ -90,6 +144,7 @@ protected: | ||||
| 
 | ||||
|   //metodi medio livello
 | ||||
|   bool aggiorna_contratto(const TRiga_documento& rdoc, TContratto_premi& contratto, TLog_report& log); | ||||
|   bool deve_generare_nac(const TContratto_premi& contratto, const TDate& data) const; | ||||
|   bool elabora_contratti(TDocumento& curr_doc, TArray& contratti_cliente, const TDate& data_fine, TLog_report& log); | ||||
|   bool genera_nac(const TMask& mask, TArray& contratti_cliente, TAssoc_array& nac_nolo, TLog_report& log); | ||||
|   bool genera_fat(const TMask& mask, TContratto_premi& contratto, TToken_string& nakey, TLog_report& log); | ||||
| @ -184,6 +239,8 @@ int THardy_elab_docs::kill_provv_nac(const TMask& mask) | ||||
| //metodo che filtra tutti i documenti in base ai parametri della maschera
 | ||||
| long THardy_elab_docs::genera_recordset(const TMask& mask, TISAM_recordset& recset) | ||||
| { | ||||
|   const int tc = mask.get_int(F_TIPOCONTR); | ||||
| 
 | ||||
|   //parametri di elaborazione
 | ||||
|   //per prima cosa controlla se il cliente è stato specificato; questo influisce sulla scelta della chiave di ricerca sul file
 | ||||
|   int key = 3; | ||||
| @ -197,7 +254,9 @@ long THardy_elab_docs::genera_recordset(const TMask& mask, TISAM_recordset& recs | ||||
|   query << "USE DOC KEY " << key; | ||||
|   //lo stato dipende da quanto sta scritto sulla elaborazione differita (stato iniziale dei docs da considerare)
 | ||||
|   //viene messo CODNUM nella SELECT perchè, essendoci un range di date nelle chiavi, la numerazione verrebbe ignorata! (provato!)
 | ||||
|   query << "\nSELECT (STATO>=#STATOINI)&&(STATO<'9')"; | ||||
|   query << "\nSELECT (STATO>=#STATOINI)"; | ||||
|   if (tc != 8)                  // Per i contratti NON di nolo ...
 | ||||
|     query << "&&(STATO<'9')";   // ... scarta i documenti definitivi
 | ||||
| 
 | ||||
|   //in base al tipo documento che si deve elaborare (settato in configurazione), ci possono essere più numerazioni da considerare!
 | ||||
|   TConfig config(CONFIG_DITTA, "ha"); | ||||
| @ -207,11 +266,9 @@ long THardy_elab_docs::genera_recordset(const TMask& mask, TISAM_recordset& recs | ||||
|   // Inutile testare tutte le numerazioni, basta il tipo documento
 | ||||
|   query << "&&((" << DOC_TIPODOC << "=='" << tipo_doc_to_elab1 << "')||(" << DOC_TIPODOC << "=='" << tipo_doc_to_elab2 << "'))"; | ||||
| 
 | ||||
|   //se c'è l'agente specificato...
 | ||||
|   const TString& agente = mask.get(F_CODAGE); | ||||
|    | ||||
|   //ordinamento (agente)-codcf-ndoc
 | ||||
|   query << "\nBY " << DOC_CODCF << " " << DOC_NDOC; | ||||
|   if (codcf <= 0) | ||||
|     query << "\nBY " << DOC_CODCF << ' ' << DOC_NDOC;  //ordinamento codcf-ndoc
 | ||||
| 
 | ||||
|   //from-to dipendente da chiave
 | ||||
|   switch (key) | ||||
| @ -242,6 +299,8 @@ long THardy_elab_docs::genera_recordset(const TMask& mask, TISAM_recordset& recs | ||||
|   const TString& stato_ini = config.get("StatoIniFatt"); | ||||
|   recset.set_var("#STATOINI", stato_ini); | ||||
| 
 | ||||
|   //se c'è l'agente specificato...
 | ||||
|   const TString& agente = mask.get(F_CODAGE); | ||||
|   if (agente.full()) | ||||
|     recset.set_var("#CODAG", agente); | ||||
|   if (codcf > 0) | ||||
| @ -454,6 +513,21 @@ bool THardy_elab_docs::aggiorna_contratto(const TRiga_documento& rdoc, TContratt | ||||
|   return elaborato; | ||||
| } | ||||
| 
 | ||||
| bool THardy_elab_docs::deve_generare_nac(const TContratto_premi& contratto, const TDate& data) const | ||||
| { | ||||
|   const int mese = data.month(); | ||||
|   bool yes = false; | ||||
|   switch (contratto.frequenza()) | ||||
|   { | ||||
|   case 'A': yes = mese == 12; break;            // Gli annuali valgono solo a dicembre
 | ||||
|   case 'M': yes = true; break;                  // I mensili (nolo) valgono sempre
 | ||||
|   case 'S': yes = mese == 6 || mese == 12;      // I semestrali valgono solo a giugno e dicembre
 | ||||
|   case 'T': yes = data.month() % 3 == 0; break; // I trimestrali valgono solo a marzo, giugno, settembre e dicembre
 | ||||
|   default:  break; | ||||
|   } | ||||
|   return yes; | ||||
| } | ||||
| 
 | ||||
| //aggiorna, in base al documento in esame curr_doc, le somme restituite nelle righe di tipo verigh02 nei contratti validi..
 | ||||
| //..del cliente
 | ||||
| bool THardy_elab_docs::elabora_contratti(TDocumento& curr_doc, TArray& contratti_cliente, const TDate& data_fine, TLog_report& log) | ||||
| @ -472,11 +546,12 @@ bool THardy_elab_docs::elabora_contratti(TDocumento& curr_doc, TArray& contratti | ||||
|        | ||||
|       // Calcola l'inizio di validità dei documenti in base alla frequenza (14-01-2013)
 | ||||
|       TDate data_inizio(1, 1, data_fine.year()); | ||||
|       const int mese = data_fine.month(); | ||||
|       switch (contratto.frequenza()) | ||||
|       { | ||||
|       case 'M': data_inizio.set_month(data_fine.month()); break; // Solo contratti NOLO
 | ||||
|       case 'S': data_inizio.set_month(data_fine.month() > 6 ? 7 : 1); break; | ||||
|       case 'T': data_inizio.set_month(max(1, data_fine.month()-2));   break; | ||||
|       case 'M': data_inizio.set_month(mese); break; // Solo contratti NOLO
 | ||||
|       case 'S': data_inizio.set_month(mese > 6 ? 7 : 1); break; | ||||
|       case 'T': data_inizio.set_month(max(1, mese-2));   break; | ||||
|       default:  break; | ||||
|       } | ||||
| 
 | ||||
| @ -498,6 +573,7 @@ bool THardy_elab_docs::genera_nac(const TMask& mask, TArray& contratti_cliente, | ||||
| 
 | ||||
|   //si informa se l'elaborazione è definitiva o meno
 | ||||
|   const bool definitivo = mask.get_bool(F_DEFINITIVO); | ||||
|   const TDate data_fine = mask.get(F_ADATA); | ||||
| 
 | ||||
|   //giro su tutti i contratti del cliente che stanno nell'array (ogni contratto genera una NAC)
 | ||||
|   FOR_EACH_ARRAY_ITEM(contratti_cliente, r, riga) | ||||
| @ -507,9 +583,36 @@ bool THardy_elab_docs::genera_nac(const TMask& mask, TArray& contratti_cliente, | ||||
|     const long codcf = contratto.codcf();                    // il codice cliente ci serve nella generazione della NAC...
 | ||||
|     const char tipo_contratto = contratto.tipo_contratto();  // ...e pure il tipo di contratto in esame!
 | ||||
| 
 | ||||
|     TString80 tip = ""; | ||||
|     switch (tipo_contratto) | ||||
|     { | ||||
|     case 'A': tip = TR("Anticipo");  break; | ||||
|     case 'N': tip = TR("Nolo"); break; | ||||
|     case 'P': tip = TR("Posticipo");  break; | ||||
|     case 'R': tip = TR("Rifatturzaione");  break; | ||||
|     default : break; | ||||
|     } | ||||
| 
 | ||||
|     TString80 freq = ""; | ||||
|     switch (contratto.frequenza()) | ||||
|     { | ||||
|     case 'A': freq = TR("annuale");  break; | ||||
|     case 'M': freq << TR("rata ") << (contratto.get_int(DOC_NUMANT)+1); break; | ||||
|     case 'S': freq << (data_fine.month() < 7 ? TR("I sem.") : TR("II sem."));  break; | ||||
|     case 'T': freq << itor((data_fine.month()/3)) << TR(" trim."); break; | ||||
|     default : break; | ||||
|     } | ||||
| 
 | ||||
|     const bool nac_ok = deve_generare_nac(contratto, data_fine); | ||||
|     //segnaliamo l'elaborazione del contratto sul log
 | ||||
|     TString log_msg; | ||||
|     log_msg.format(FR("Contratto:%6ld Cliente:%6ld"), ndoc, codcf); | ||||
|     log_msg.format(FR("Cliente:%ld Contratto:%ld %s %s"), codcf, ndoc, (const char*)tip, (const char*)freq); | ||||
|     log_msg << "(NAC "; | ||||
|     if (nac_ok) | ||||
|       log_msg << "def."; | ||||
|     else | ||||
|       log_msg << "provv."; | ||||
|     log_msg << ')'; | ||||
| 
 | ||||
|     //  generazione del documento NAC dal contratto
 | ||||
|     //  -------------------------------------------
 | ||||
| @ -556,7 +659,7 @@ bool THardy_elab_docs::genera_nac(const TMask& mask, TArray& contratti_cliente, | ||||
|     const int anno = datadoc.year(); | ||||
|     //solo in caso di elaborazione definitiva si scrivono NAC di tipo D; 
 | ||||
|     //sennò di tipo P, che sono uccidibili all'inizio di ogni nuova elaborazione
 | ||||
|     const char provv = definitivo ? 'D' : 'P'; | ||||
|     const char provv = definitivo && nac_ok ? 'D' : 'P'; | ||||
| 
 | ||||
|     TDocumento nac(provv, anno, nac_codnum, 0);   //num_doc = 0 perchè viene aggiornato in fase di registrazione
 | ||||
|     nac.set_tipo(nac_tipo); | ||||
| @ -761,7 +864,11 @@ bool THardy_elab_docs::genera_nac(const TMask& mask, TArray& contratti_cliente, | ||||
|         log_msg << " -- Impossibile aggiornare contratto: errore " << err; | ||||
|     } | ||||
|   | ||||
|     log.log(0, log_msg); | ||||
|     if (err == NOERR) | ||||
|       log.log(nac_ok ? 1 : 0, log_msg); | ||||
|     else | ||||
|       log.log(2, log_msg); | ||||
|    | ||||
|     log.log(0, ""); | ||||
| 
 | ||||
| 
 | ||||
| @ -962,30 +1069,15 @@ void THardy_elab_docs::elabora_documenti(const TMask& mask, TISAM_recordset& fat | ||||
|       old_codcf = codcf; | ||||
| 
 | ||||
|       const int n_contratti = find_contratti_cliente(codcf, mask, tc, contratti_cliente); | ||||
| 
 | ||||
|       TString8 key; key.format("C|%ld", codcf); | ||||
|       TString msg; msg << TR("Cliente") << ' ' << codcf << ' ' << cache().get(LF_CLIFO, key, CLI_RAGSOC); | ||||
| 
 | ||||
|       if (n_contratti > 0) | ||||
|       { | ||||
|         TString8 key; key.format("C|%ld", codcf); | ||||
|         TString msg; msg << TR("Cliente") << ' ' << codcf << ' ' << cache().get(LF_CLIFO, key, CLI_RAGSOC); | ||||
|         log.log(0, msg); | ||||
|       } | ||||
|       else | ||||
|       { | ||||
|         if (tc & 0x8) // Elaborazione nolo?
 | ||||
|         { | ||||
|           // Nulla di grave se non esistono contratti di nolo
 | ||||
|         } | ||||
|         else | ||||
|         { | ||||
|           log.log(0, msg); | ||||
|           msg =  TR("Non ha un contratto valido nel periodo selezionato pur avendo fatture."); | ||||
|           log.log(1, msg);  | ||||
|         } | ||||
|       } | ||||
|     } | ||||
| 
 | ||||
|     if (contratti_cliente.items() > 0) | ||||
|     if (!contratti_cliente.empty()) | ||||
|     { | ||||
|       const TDate data_fine = mask.get(F_ADATA); | ||||
| 
 | ||||
| @ -1003,9 +1095,8 @@ void THardy_elab_docs::elabora_documenti(const TMask& mask, TISAM_recordset& fat | ||||
|   if (!contratti_cliente.empty()) | ||||
|     genera_nac(mask, contratti_cliente, fat_nolo, log); | ||||
| 
 | ||||
|   //se elaborazione definitiva -> cambia lo stato ai documenti di vendita elaborati, mettendolo uguale..
 | ||||
|   //..a quello deciso in configurazione
 | ||||
|   const bool definitivo = mask.get_bool(F_DEFINITIVO); | ||||
|   // se elaborazione definitiva NON di nolo-> cambia lo stato ai documenti di vendita elaborati
 | ||||
|   const bool definitivo = mask.get_bool(F_DEFINITIVO) && ((tc & 0x8) == 0); | ||||
|   if (definitivo && !documenti_cliente.empty()) | ||||
|   { | ||||
|     const TString4 stato_finale = ini_get_string(CONFIG_DITTA, "ha", "StatoFinFatt"); | ||||
|  | ||||
| @ -67,6 +67,7 @@ BEGIN | ||||
|   PROMPT 22 4 "A data " | ||||
|   CHECKTYPE REQUIRED | ||||
|   VALIDATE DATE_CMP_FUNC >= F_DADATA | ||||
|   WARNING "Inserire una data successiva a quella iniziale" | ||||
| END | ||||
| 
 | ||||
| GROUPBOX DLG_NULL 76 4 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user