Corretta gestione dell causali contabili,
git-svn-id: svn://10.65.10.50/trunk@24 c028cbd2-c16b-5b4b-a496-9718f37d4682
This commit is contained in:
		
							parent
							
								
									33be7ac1be
								
							
						
					
					
						commit
						10852c6b02
					
				| @ -70,7 +70,8 @@ const real& TPrimanota_application::cod2IVA(const char* codiva) | |||||||
| 
 | 
 | ||||||
| real TPrimanota_application::scorpora(real& imponibile, const real& percent) | real TPrimanota_application::scorpora(real& imponibile, const real& percent) | ||||||
| { | { | ||||||
|  real imposta = imponibile * percent / (percent + 100.0); imposta.ceil(); |   real imposta = abs(imponibile) * percent / (percent + 100.0); imposta.ceil(); | ||||||
|  |   if (imponibile.sign() < 0) imposta = -imposta;  | ||||||
|   imponibile -= imposta; |   imponibile -= imposta; | ||||||
|   return imposta; |   return imposta; | ||||||
| }   | }   | ||||||
| @ -111,19 +112,7 @@ bool TPrimanota_application::detraibile(int tipodet) | |||||||
| 
 | 
 | ||||||
|   const TSheet_field& iva = app().ivas(); |   const TSheet_field& iva = app().ivas(); | ||||||
| 
 | 
 | ||||||
|  TString16 chiave; |   TString16 chiave(iva.mask().get(F_ANNOIVA)); chiave << app().causale().reg().attivita(); | ||||||
|  chiave = iva.mask().get(F_ANNOIVA); |  | ||||||
|  chiave << iva.mask().get(F_CODREG); |  | ||||||
|  TTable reg("REG"); |  | ||||||
|  reg.put("CODTAB", chiave); |  | ||||||
|  reg.read(); |  | ||||||
| #ifdef DBG |  | ||||||
|  if(reg.status() != NOERR) |  | ||||||
|   error_box("La minchia che trovo il registro '%s'", (const char*)chiave); |  | ||||||
| #endif |  | ||||||
| 
 |  | ||||||
|  const char* att = reg.get("S8"); |  | ||||||
|  chiave.cut(4); chiave << att; |  | ||||||
| 
 | 
 | ||||||
|   TTable pla("PLA"); |   TTable pla("PLA"); | ||||||
|   pla.put("CODTAB", chiave); |   pla.put("CODTAB", chiave); | ||||||
| @ -186,6 +175,7 @@ int TPrimanota_application::bill2contr(const TConto& conto, char sezione) const | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | // Controlla se un conto e' usato nelle righe IVA                              
 | ||||||
| bool TPrimanota_application::bill_used(const TConto& conto) const | bool TPrimanota_application::bill_used(const TConto& conto) const | ||||||
| { | { | ||||||
|   const TArray& rows = ivas().rows_array(); |   const TArray& rows = ivas().rows_array(); | ||||||
| @ -355,10 +345,10 @@ void TPrimanota_application::cgs_pack() | |||||||
|       if (imp == 0.0) |       if (imp == 0.0) | ||||||
|       { |       { | ||||||
|         del = TRUE; |         del = TRUE; | ||||||
| /*   
 |         /*   
 | ||||||
|            const TConto c(r, 6, 0x0);   // Remove if import=0 and Bill not used
 |            const TConto c(r, 6, 0x0);   // Remove if import=0 and Bill not used
 | ||||||
|            del = !bill_used(c); |            del = !bill_used(c); | ||||||
| */     |            */     | ||||||
|       } |       } | ||||||
|        |        | ||||||
|     } |     } | ||||||
| @ -457,7 +447,7 @@ void TPrimanota_application::set_ivas_row(int nriga, const char* codiva, TConto& | |||||||
|   TToken_string& riga = ivas().row(nriga); |   TToken_string& riga = ivas().row(nriga); | ||||||
|   riga = " ";                  // Importo
 |   riga = " ";                  // Importo
 | ||||||
|   riga.add (codiva);           // codiva
 |   riga.add (codiva);           // codiva
 | ||||||
|  riga.add (" | | ");          // Imposta - C/R - Det
 |   riga.add (" | | ");          // Det - Imposta - C/R
 | ||||||
|   riga.add(tc.string(0x3));    // Conto
 |   riga.add(tc.string(0x3));    // Conto
 | ||||||
|   riga.add(desc);              // Descrizione
 |   riga.add(desc);              // Descrizione
 | ||||||
| } | } | ||||||
| @ -467,13 +457,19 @@ bool TPrimanota_application::imponibile_handler(TMask_field& f, KEY key) | |||||||
| { | { | ||||||
|   if (key == K_TAB && f.dirty()) |   if (key == K_TAB && f.dirty()) | ||||||
|   { |   { | ||||||
|   const TString& iva = f.mask().get(102);         |     TString16 iva(f.mask().get(102));         | ||||||
|  |     if (iva.empty()) | ||||||
|  |     { | ||||||
|  |       iva = app().mask().get(F_CODIVA); | ||||||
|  |       f.mask().set(102, iva); | ||||||
|  |     }   | ||||||
|     if (iva.not_empty())                           // Se c'e' il codice IVA
 |     if (iva.not_empty())                           // Se c'e' il codice IVA
 | ||||||
|     { |     { | ||||||
|       const real& percent = cod2IVA(iva); |       const real& percent = cod2IVA(iva); | ||||||
|       const real imponibile(f.get()); |       const real imponibile(f.get()); | ||||||
|    real imposta = imponibile * percent / 100.0; imposta.ceil(); |       real imposta = abs(imponibile) * percent / 100.0; imposta.ceil(); | ||||||
|    f.mask().set(103, imposta.string()); |       if (imponibile.sign() < 0) imposta = -imposta; | ||||||
|  |       f.mask().set(104, imposta.string()); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -499,15 +495,17 @@ bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key) | |||||||
|   { |   { | ||||||
|     const real imponibile(f.mask().get(101)); |     const real imponibile(f.mask().get(101)); | ||||||
|     const real& percent = cod2IVA(f.mask().get(102)); |     const real& percent = cod2IVA(f.mask().get(102)); | ||||||
|   real imposta = imponibile * percent / 100.0; imposta.ceil(); |     real imposta = abs(imponibile) * percent / 100.0;  | ||||||
|  |     imposta.ceil(); | ||||||
|  |     if (imponibile.sign() < 0) imposta = -imposta; | ||||||
|  |      | ||||||
|     const real val(f.get()); |     const real val(f.get()); | ||||||
|     if (val != imposta) |     if (val != imposta) | ||||||
|     { |     { | ||||||
|       const TString16 wrong(val.string(".")); |       const TString16 wrong(val.string(".")); | ||||||
|       const TString16 right(imposta.string(".")); |       const TString16 right(imposta.string(".")); | ||||||
|     if (f.yesno_box("Imposta di '%s' errata: modificare in '%s'?",  |       if (f.warning_box("Imposta di '%s' errata: dovrebbe essere '%s'",  | ||||||
|         (const char*)wrong, (const char*)right)) |                         (const char*)wrong, (const char*)right)); | ||||||
|      f.set(imposta.string()); |  | ||||||
|     }    |     }    | ||||||
|   } else |   } else | ||||||
|     if (key == K_F8 && f.get().empty()) |     if (key == K_F8 && f.get().empty()) | ||||||
| @ -515,8 +513,8 @@ bool TPrimanota_application::imposta_handler(TMask_field& f, KEY key) | |||||||
|       real imponibile(f.mask().get(101)); |       real imponibile(f.mask().get(101)); | ||||||
|       const real& percent = cod2IVA(f.mask().get(102)); |       const real& percent = cod2IVA(f.mask().get(102)); | ||||||
|       const real imposta = scorpora(imponibile, percent); |       const real imposta = scorpora(imponibile, percent); | ||||||
|   f.set(imposta.string()); |  | ||||||
|       f.mask().set(101, imponibile.string()); |       f.mask().set(101, imponibile.string()); | ||||||
|  |       f.set(imposta.string()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|   return TRUE; |   return TRUE; | ||||||
| @ -541,12 +539,12 @@ bool TPrimanota_application::iva_notify(int r, KEY k) | |||||||
|     oldpos = bill2pos(oldconto, 'I'); |     oldpos = bill2pos(oldconto, 'I'); | ||||||
|     oldimp = imp2sez(real(row.get(0))); |     oldimp = imp2sez(real(row.get(0))); | ||||||
|     oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N'); |     oldposiva = type2pos(detraibile(row.get_int(4)) ? 'D' : 'N'); | ||||||
|   oldiva = imp2sez(real(row.get(2))); |     oldiva = imp2sez(real(row.get(3))); | ||||||
|   } |   } | ||||||
|   if (k == K_DEL) |   if (k == K_DEL) | ||||||
|   { |   { | ||||||
|     row.add("0", 0); // Azzera imponibile
 |     row.add("0", 0); // Azzera imponibile
 | ||||||
|   row.add("0", 2);  // Azzera imposta
 |     row.add("0", 3);  // Azzera imposta
 | ||||||
|     k = K_ENTER;      // Elegante o Sporco trucco
 |     k = K_ENTER;      // Elegante o Sporco trucco
 | ||||||
|   } |   } | ||||||
|   if (k == K_ENTER) |   if (k == K_ENTER) | ||||||
| @ -562,7 +560,7 @@ bool TPrimanota_application::iva_notify(int r, KEY k) | |||||||
|       oldiva = 0.0; |       oldiva = 0.0; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| // Aggiorna conto sulla riga contabile
 |     // Aggiorna conto sulla riga contabile
 | ||||||
|     real imp = imp2sez(real(row.get(0)));               // Imponibile
 |     real imp = imp2sez(real(row.get(0)));               // Imponibile
 | ||||||
|     TConto conto(row, 5, 0x3); |     TConto conto(row, 5, 0x3); | ||||||
|     oldpos = bill2pos(conto, 'I'); |     oldpos = bill2pos(conto, 'I'); | ||||||
| @ -573,9 +571,9 @@ bool TPrimanota_application::iva_notify(int r, KEY k) | |||||||
|       app().add_cgs_imp(oldpos, imp-oldimp); |       app().add_cgs_imp(oldpos, imp-oldimp); | ||||||
|     oldimp = imp;  |     oldimp = imp;  | ||||||
|      |      | ||||||
| // Aggiorna conto IVA sulla riga contabile
 |     // Aggiorna conto IVA sulla riga contabile
 | ||||||
| 
 | 
 | ||||||
|   imp = imp2sez(real(row.get(2)));                    // Imposta
 |     imp = imp2sez(real(row.get(3)));                    // Imposta
 | ||||||
|     const bool detrarre = detraibile(row.get_int(4));   // Determina se IVA detraibile
 |     const bool detrarre = detraibile(row.get_int(4));   // Determina se IVA detraibile
 | ||||||
|     app().causale().bill(detrarre ? 3 : 4, conto); |     app().causale().bill(detrarre ? 3 : 4, conto); | ||||||
|     const char tipod = detrarre ? 'D' : 'N'; |     const char tipod = detrarre ? 'D' : 'N'; | ||||||
| @ -605,8 +603,7 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) | |||||||
|   { |   { | ||||||
|     TToken_string& row = app().ivas().row(r); |     TToken_string& row = app().ivas().row(r); | ||||||
|     imp += real(row.get(0));       // imponibile
 |     imp += real(row.get(0));       // imponibile
 | ||||||
|     row.get();                     // IVA
 |     imp += real(row.get(3));       // imposta
 | ||||||
|     imp += real(row.get());        // imposta
 |  | ||||||
|   } |   } | ||||||
|    |    | ||||||
|   const TMask& m = f.mask();          |   const TMask& m = f.mask();          | ||||||
| @ -619,7 +616,7 @@ bool TPrimanota_application::iva_handler(TMask_field& f, KEY k) | |||||||
|     TString16 t(tot.string(".")); |     TString16 t(tot.string(".")); | ||||||
|     TString16 i(imp.string(".")); |     TString16 i(imp.string(".")); | ||||||
|     return error_box("La somma del totale documento e delle ritenute (%s) e' diverso dalla "  |     return error_box("La somma del totale documento e delle ritenute (%s) e' diverso dalla "  | ||||||
|                      "somma degli imponibili e delle imposte (%s)", t, i); |                      "somma degli imponibili e delle imposte (%s)", (const char*)t, (const char*)i); | ||||||
|   }   |   }   | ||||||
|    |    | ||||||
|   return TRUE; |   return TRUE; | ||||||
| @ -647,7 +644,7 @@ bool TPrimanota_application::num_handler(TMask_field& f, KEY key) | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // Handler of the F_CODCAUS field on the query mask
 | // Handler of the F_CODCAUS field on the query mask
 | ||||||
| // Certified 90%
 | // Certified 99%
 | ||||||
| bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) | bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) | ||||||
| { | { | ||||||
|   if (!f.mask().is_running()) return TRUE; |   if (!f.mask().is_running()) return TRUE; | ||||||
| @ -657,12 +654,12 @@ bool TPrimanota_application::caus_query_handler(TMask_field& f, KEY key) | |||||||
|     const int ann = f.mask().get_int(F_ANNOIVA); |     const int ann = f.mask().get_int(F_ANNOIVA); | ||||||
|     const char* cau = f.get(); |     const char* cau = f.get(); | ||||||
|      |      | ||||||
|   const TipoIVA i = cau2IVA(cau, ann); |     const TipoIVA i = cau2IVA(cau, ann);          // Cerca causale e suo tipo
 | ||||||
|     if (i != iva_errata) |     if (i != iva_errata) | ||||||
|     { |     { | ||||||
|     const bool ok = suspended_handler(f, key); |       const bool ok = suspended_handler(f, key);  // Controlla sospensione
 | ||||||
|       if (ok) |       if (ok) | ||||||
|      dispatch_e_char(f.parent(), K_INS); |         dispatch_e_char(f.parent(), K_INS);        // Entra in modo inserimento
 | ||||||
|     }  |     }  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
| @ -711,9 +708,11 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) | |||||||
|      |      | ||||||
|     if (m.query_mode()) |     if (m.query_mode()) | ||||||
|     { |     { | ||||||
|       if (ae == 0) return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); |       if (ae == 0)  | ||||||
|  |         return f.error_box("La data dell'operazione non appartiene a nessun esercizio"); | ||||||
|       ok = app().giornale().read(ae); |       ok = app().giornale().read(ae); | ||||||
|       if (!ok) return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); |       if (!ok)  | ||||||
|  |         return f.error_box("Non esiste il libro giornale dell'esercizio %d", ae); | ||||||
|     }   |     }   | ||||||
|     if (dr < app().giornale().last_print()) |     if (dr < app().giornale().last_print()) | ||||||
|       return f.error_box("La data dell'operazione e' antecedente alla " |       return f.error_box("La data dell'operazione e' antecedente alla " | ||||||
| @ -738,7 +737,7 @@ bool TPrimanota_application::datareg_handler(TMask_field& f, KEY key) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Handler of the F_DATACOMP field on the modify mask
 | // Handler of the F_DATACOMP field on the modify mask
 | ||||||
| // Certified 70%
 | // Certified 90%
 | ||||||
| bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) | bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) | ||||||
| {                           | {                           | ||||||
|   if (!f.to_check(key, TRUE))  |   if (!f.to_check(key, TRUE))  | ||||||
| @ -771,7 +770,7 @@ bool TPrimanota_application::datacomp_handler(TMask_field& f, KEY key) | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Handler of the F_DATA74TER field on the modify mask
 | // Handler of the F_DATA74TER field on the modify mask
 | ||||||
| // Certified 70%
 | // Certified 90%
 | ||||||
| bool TPrimanota_application::data74ter_handler(TMask_field& f, KEY key) | bool TPrimanota_application::data74ter_handler(TMask_field& f, KEY key) | ||||||
| {                           | {                           | ||||||
|   if (!f.to_check(key)) return TRUE; |   if (!f.to_check(key)) return TRUE; | ||||||
| @ -795,7 +794,7 @@ bool TPrimanota_application::reg_handler(TMask_field& f, KEY key) | |||||||
| {    | {    | ||||||
|   if (f.to_check(key, TRUE)) |   if (f.to_check(key, TRUE)) | ||||||
|   { |   { | ||||||
| //   if (!suspended_handler(f, key)) return FALSE;
 |     //   if (!suspended_handler(f, key)) return FALSE;
 | ||||||
|      |      | ||||||
|     const int ai = f.mask().get_int(F_ANNOIVA); |     const int ai = f.mask().get_int(F_ANNOIVA); | ||||||
|     const char* r = f.get(); |     const char* r = f.get(); | ||||||
| @ -885,10 +884,10 @@ void TPrimanota_application::add_cgs_tot(TMask& m) | |||||||
|   { |   { | ||||||
|     iva_notify(0, K_SPACE); |     iva_notify(0, K_SPACE); | ||||||
|     const real imposta = scorpora(tot, iva.percentuale()); |     const real imposta = scorpora(tot, iva.percentuale()); | ||||||
|     row.add(tot.string(), 0); |      | ||||||
|     row.add(iva.codice(), 1); |     row.add(tot.string(), 0);                   // imponibile
 | ||||||
|     row.add(imposta.string(), 2); |     row.add(iva.codice(), 1);                   // imposta
 | ||||||
|     row.add(" | "); |     row.add(imposta.string(), 3);               // imposta
 | ||||||
|      |      | ||||||
|     TConto bill;                                // Conto della prima riga IVA
 |     TConto bill;                                // Conto della prima riga IVA
 | ||||||
|     const TString& tipo = iva.tipo(); |     const TString& tipo = iva.tipo(); | ||||||
| @ -903,7 +902,12 @@ void TPrimanota_application::add_cgs_tot(TMask& m) | |||||||
|     if (!bill.ok())  |     if (!bill.ok())  | ||||||
|       _causale.bill(2, bill); |       _causale.bill(2, bill); | ||||||
| 
 | 
 | ||||||
|     row.add(bill.string(0x3)); |     row.add(bill.tipo(), 5); | ||||||
|  |     row.add(bill.gruppo(), 6); | ||||||
|  |     row.add(bill.conto(), 7); | ||||||
|  |     row.add(bill.sottoconto(), 8); | ||||||
|  |     row.add(bill.descrizione(), 9); | ||||||
|  |      | ||||||
|     app().ivas().force_update(0); |     app().ivas().force_update(0); | ||||||
|     iva_notify(0, K_ENTER); |     iva_notify(0, K_ENTER); | ||||||
|   }   |   }   | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user