Files correlati : cg2.exe Ricompilazione Demo : [ ] Commento Aggiornato conto cliente sulle scadenze git-svn-id: svn://10.65.10.50/trunk@19082 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1434 lines
		
	
	
		
			45 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1434 lines
		
	
	
		
			45 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| // --------------------------------------------------------------------------
 | |
| // Scadenzario
 | |
| // fv 24/8/94
 | |
| // --------------------------------------------------------------------------
 | |
| 
 | |
| #include <msksheet.h>
 | |
| #include "cgpagame.h"
 | |
| #include "cgsaldac.h"
 | |
| 
 | |
| #include "cg2102.h"
 | |
| #include "cg2100.h"
 | |
| #include "cg21sld.h"
 | |
| 
 | |
| #include <clifo.h>
 | |
| #include <defmask.h>
 | |
| 
 | |
| TPagamento& TPrimanota_application::pagamento() const
 | |
| { 
 | |
|   CHECK(_pag, "Pagamento nullo");
 | |
|   return *_pag; 
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::pag_notify(TSheet_field& ps, int r, KEY k)
 | |
| {                            
 | |
|   TMask* msk = &(ps.mask());      
 | |
| 
 | |
| //  if (!msk->is_running()) return TRUE;  // Necessario per evitare il CHECK sul pagamento nullo 
 | |
|   if (!app().is_fattura() || app()._pag == NULL) return TRUE;  // Necessario per evitare il CHECK sul pagamento nullo
 | |
|   
 | |
|   TPagamento&    pag = app().pagamento();
 | |
|   TString_array& rws = app().pag_rows();                                
 | |
|                                                
 | |
|   const int rdiff      = msk->get_int(FS_RDIFFER);
 | |
|   const bool in_valuta = pag.in_valuta(); 
 | |
| //  const int impos      = in_valuta ? 2 : 1;
 | |
|   
 | |
|   // ts contiene la vecchia riga, ns la nuova                                       
 | |
|   TToken_string ts(128), ns(128);
 | |
|   TString16 banca;
 | |
| 
 | |
|   bool doit = TRUE, m_impl = FALSE, m_impv = FALSE, m_perc = FALSE;
 | |
|   bool m_scad = FALSE, m_tipo = FALSE, m_ulc = FALSE, mod = FALSE;
 | |
|   word ahiahi = P_OK;                                
 | |
|   
 | |
|   TString news(10), newl(15), newv(15), newp(15), newt(1), newu(1);                                  
 | |
| 
 | |
|   bool recalc = msk->get_bool(FS_RECALC); 
 | |
|   bool mcomm  = msk->get_bool(FS_MCOMM);
 | |
|   
 | |
|   switch (k)
 | |
|   { 
 | |
|   case K_SPACE:       
 | |
|     {                                         
 | |
|       const bool can = !recalc && pag.n_rate() > 1 && ps.row(r).get_char(13) != 'X';   
 | |
|       ps.sheet_mask().enable(DLG_DELREC, can);
 | |
|     }  
 | |
|     break;
 | |
|   case K_ENTER:
 | |
|     ns  = ps.row(r);     
 | |
|     ts  = rws.row(r);    
 | |
|     
 | |
|     news = ns.get(0);           // Data scadenza
 | |
|     newl = ns.get(1);           // Imponibile (lire)
 | |
|     newv = ns.get(2);           // Imponibile (valuta)
 | |
|     newp = ns.get(3);           // Percentuale
 | |
|     newt = ns.get(4);           // Tipo pagamento                                 
 | |
|     newu = ns.get(5);           // Ulteriore classificazione 
 | |
|     
 | |
|     // qui viene il bello, si fa per dire 
 | |
|     if (news != ts.get(0))  // modificata data scadenza
 | |
|       mod = m_scad = TRUE;        
 | |
|     if (real(newp) != real(ts.get(3)))  // modificata percentuale
 | |
|       mod = m_perc = TRUE;        
 | |
|     if (real(newl) != real(ts.get(1)))  // modificato importo lire
 | |
|     {          
 | |
|        // se si modifica la percentuale nessun importo viene cagato
 | |
|       if ((recalc && !m_perc) || (!recalc)) 
 | |
|         mod = m_impl = TRUE;   
 | |
|     }
 | |
|     if (in_valuta && real(newv) != real(ts.get(2)))      
 | |
|     {
 | |
|        // se si modifica la percentuale nessun importo viene cagato
 | |
|       if ((recalc && !m_perc) || (!recalc)) 
 | |
|         mod = m_impv = TRUE;   
 | |
|     }
 | |
|     if (newt != ts.get(4))  // modificato tipo pagamento
 | |
|       mod = m_tipo = m_ulc = TRUE;      
 | |
|     
 | |
|     if (newu != ts.get(5))  // modificata ulteriore classificazione
 | |
|       mod = m_ulc  = TRUE;
 | |
|     else if (m_tipo) 
 | |
|     {
 | |
|       // forza reset di ulc se si e' modificato il tipo rata
 | |
|       m_ulc = TRUE;
 | |
|       newu = "";                                             
 | |
|     }                                                        
 | |
|           
 | |
|     break;
 | |
|   case K_DEL: 
 | |
|     doit = !recalc && pag.n_rate() > 1 && ps.row(r).get_char(13) != 'X';   
 | |
|     if (doit)
 | |
|     {
 | |
|       pag.remove_rata(r);
 | |
|       msk->set(FS_NRATE, pag.n_rate());
 | |
|     }  
 | |
|     break;
 | |
|   case K_INS:   
 | |
|     // permette aggiunta e cancellazione solo se non c'e' ricalcolo automatico
 | |
|     doit = !recalc;
 | |
|     break;
 | |
|   case K_CTRL+K_INS:                 // Post inserimento
 | |
|     {                   
 | |
|       const int prev = r - 1;
 | |
|       const int gio_scad = pag.scad_rata(prev); 
 | |
|       TDate data_scad(pag.data_rata(prev));
 | |
| 
 | |
|       pag.add_rata(ZERO, gio_scad, pag.tipo_rata(prev), pag.ulc_rata(prev));
 | |
|       pag.next_scad(data_scad, gio_scad, pag.mese_commerciale(), r);
 | |
|       pag.set_datarata(r, data_scad);
 | |
| //      pag.adjust_fixed_scad();
 | |
|       pag.set_sheet(ps);
 | |
|       rws = ps.rows_array();  
 | |
|     }
 | |
|     break;
 | |
|   default:
 | |
|     break;
 | |
|   }          
 | |
| 
 | |
|   // settato da recalc_rate se occorre ridefinire lo sheet
 | |
|   // aggiungendo o togliendo righe
 | |
|   bool need_recalc = FALSE;      
 | |
| 
 | |
|   if (k == K_ENTER) 
 | |
|   {
 | |
|     if (mod && recalc)
 | |
|     {
 | |
|       // ricalcola sheet come sai fare tu
 | |
|       ahiahi = pag.recalc_rate(r, m_perc, 
 | |
|                                ((m_perc || m_impv) ? 
 | |
|                                 (m_perc ? (const char*)newp : (const char*)newv) : NULL), 
 | |
|                                (m_impl ? (const char*)newl : NULL), 
 | |
|                                (m_scad ? (const char*)news : NULL),
 | |
|                                (m_tipo ? (const char*)newt : NULL),
 | |
|                                (m_ulc  ? (const char*)newu : NULL), 
 | |
|                                rdiff, mcomm, need_recalc);   
 | |
|                                
 | |
|       // see if rdiff changed                          
 | |
|       msk->set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
 | |
|       msk->set(FS_NRATE, pag.n_rate());
 | |
|     } 
 | |
|     if (!recalc)
 | |
|     {                              
 | |
|       ahiahi = P_OK;
 | |
|       // put data as they are
 | |
|       TToken_string& trw = pag.rata(r);
 | |
|       TToken_string& trs = ps.row(r);
 | |
|       if (m_tipo) 
 | |
|         trw.add(newt,2); 
 | |
|       if (m_ulc)
 | |
|         trw.add(newu, 5);
 | |
|       if (m_scad)
 | |
|       {
 | |
|         trw.add(news,3);
 | |
|         if (r > 0)
 | |
|         {             
 | |
|           TDate d(news);   
 | |
|           int scd = (int)(d - pag.data_rata(r-1));
 | |
|           if (pag.mese_commerciale() && (scd % 30) != 0) 
 | |
|             scd = 30 * ((scd/30)+1);
 | |
|           trw.add(scd, 0);
 | |
|         }  
 | |
|         trs.add(news, 0);                                  
 | |
|       }
 | |
|       if (m_impl)  
 | |
|       {
 | |
|         trw.add(newl,7);
 | |
|         if (!in_valuta)
 | |
|         {
 | |
|          // si ricalcola la percentuale a modifica importo in lire solo
 | |
|          // se non c'e' l'importo in valuta
 | |
|           const real p = pag.recalc_percrata(r, FALSE);
 | |
|           trs.add(p.string(), 3);                                  
 | |
|         }
 | |
|       }
 | |
|       if (m_impv)  
 | |
|       {
 | |
|         trw.add(newv,4);
 | |
|         const real p = pag.recalc_percrata(r, TRUE);
 | |
|         trs.add(p.string(), 3);
 | |
|       }
 | |
|       if (mod) 
 | |
|       {
 | |
|         rws.row(r) = trs;
 | |
|         ps.force_update(r);  
 | |
|       }
 | |
|     }    
 | |
|       
 | |
|     if (ahiahi)  // any error? Rimetti le righe com'erano prima
 | |
|     {         
 | |
|       if (recalc)
 | |
|       {            
 | |
|         TString err(80); pag.strerr(ahiahi,err);
 | |
|         warning_box(err);
 | |
|         ps.row(r) = rws.row(r); 
 | |
|         ps.force_update(r); 
 | |
|       }  
 | |
|     } 
 | |
|     else if (recalc && mod && need_recalc) 
 | |
|     {                                   
 | |
|       // ridefinisci lo sheet sulla base delle nuove rate
 | |
|       pag.set_sheet(ps);
 | |
|       rws = ps.rows_array();      
 | |
|     } 
 | |
|   }
 | |
|   
 | |
|   return doit;
 | |
| }                            
 | |
| 
 | |
| bool TPrimanota_application::pag_sheet_handler(TMask_field& f, KEY key)
 | |
| {           
 | |
|   bool ok = TRUE;
 | |
|   if (key == K_TAB || key == K_ENTER)
 | |
|   {              
 | |
|     TMask& m = f.mask();
 | |
| 
 | |
|     TPagamento& pag = app().pagamento();
 | |
|     const TDate dt(m.get(F_DATADOC));
 | |
|     
 | |
|     pag.set_datadoc(dt);
 | |
|     word err = pag.validate();
 | |
|     if (m.edit_mode())
 | |
|       err &= ~(P_RSUM | P_TOTNCLIT | P_TOTNCVAL );    // Ignora totale importi e rate
 | |
|     if (err != P_OK)
 | |
|     {
 | |
|       TString s(256);
 | |
|       pag.strerr(err, s);
 | |
|       return f.error_box(s);   
 | |
|     }  
 | |
|     
 | |
|     const TString& codval = m.get(SK_VALUTA);
 | |
|     const bool in_valuta = pag.in_valuta();
 | |
|     real imp;
 | |
|     
 | |
|     if (key == K_ENTER)
 | |
|     {      
 | |
|       real tot = m.get_real(in_valuta ? SK_TOTDOCVAL : F_TOTALE);
 | |
|       for (int r = pag.n_rate()-1; r >= 0; r--)
 | |
|         imp += in_valuta ? pag.tval_rata(r) : pag.tlit_rata(r); 
 | |
|       
 | |
|       imp.round(pag.round(in_valuta));                               
 | |
|       tot.round(pag.round(in_valuta));                               
 | |
| 
 | |
|       if (imp != tot)  
 | |
|       {                     
 | |
|         TCurrency curr(imp, in_valuta ? (const char*)codval : "");
 | |
|         const TString is = curr.string(TRUE);
 | |
|         curr.set_num(tot);
 | |
|         const TString ts = curr.string(TRUE);
 | |
|         ok = yesno_box(FR("Il totale delle rate e' %s mentre\n"
 | |
|                        "il totale del documento e' %s.\n"
 | |
|                        "Si desidera registrare ugualmente?"),
 | |
|                        (const char*)is, (const char*)ts);
 | |
|       }
 | |
|     }
 | |
|       
 | |
|     if (key == K_ENTER && in_valuta)
 | |
|     {   
 | |
|       const real totlit = m.get_real(F_TOTALE);             
 | |
|       imp = ZERO;
 | |
|       for (int r = pag.n_rate()-1; r >= 0; r--)
 | |
|         imp += pag.tlit_rata(r);
 | |
|                                          
 | |
|       imp.round(pag.round(FALSE));
 | |
| 
 | |
|       if (imp != totlit)
 | |
|       {                             
 | |
|         TCurrency curr(imp);
 | |
|         const TString is = curr.string(TRUE);
 | |
|         curr.set_num(totlit);
 | |
|         const TString ts = curr.string(TRUE);
 | |
|         const TRectype & rec = cache().get("%VAL", TCurrency::get_firm_val());
 | |
|         const char * name = (const char *) rec.get("S0");
 | |
| 
 | |
|         ok = yesno_box(FR("Il totale in %s delle rate e' %s mentre\n"
 | |
|                        "il totale del documento e' %s.\n"
 | |
|                        "Si desidera registrare ugualmente?"), 
 | |
|                        name, (const char*)is, (const char*)ts);
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::tipopag_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if ((key == K_TAB || key == K_ENTER) && f.dirty())
 | |
|   {                
 | |
|     TMask& m = f.mask();
 | |
|     int t = m.get_int(105); 
 | |
|     if (t <= 0)
 | |
|     {
 | |
|       t = 1;  
 | |
|       f.set("1");
 | |
|     }
 | |
|     const char u = m.get(106)[0];
 | |
|     const TPagamento& pag = app().pagamento();  
 | |
|     bool ok;
 | |
|     const char* s = pag.desc_tipo(t, u, &ok);  
 | |
|     if (!ok) m.reset(106);
 | |
|     m.set(107, s);
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::codpag_handler(TMask_field& f, KEY key)
 | |
| {                 
 | |
|   bool ok = true;
 | |
|   
 | |
|   TMask& m = f.mask();
 | |
|   TPrimanota_application& a = app();
 | |
|   const bool set_scad = a.is_fattura() && m.page_enabled(2);   // E' attiva pagina 3
 | |
|   if (key == K_ENTER)
 | |
|   {  
 | |
|     if (set_scad && f.empty())
 | |
|     {
 | |
|       ok = f.error_box(TR("Il codice di pagamento e' obbligatorio!"));
 | |
| 
 | |
|       // Nella maschera iva cerco di reperirlo dal cliente
 | |
|       if (m.id2pos(F_CLIENTE) > 0)
 | |
|       {
 | |
|         const char typ = a.clifo();
 | |
|         const long cod = m.get_long(typ == 'C' ? F_CLIENTE : F_FORNITORE);  
 | |
|         TLocalisamfile clifo(LF_CLIFO);
 | |
|         clifo.put(CLI_TIPOCF, typ);
 | |
|         clifo.put(CLI_CODCF, cod);
 | |
|         if (clifo.read() == NOERR)
 | |
|         {
 | |
|           const TString& cp = clifo.get(CLI_CODPAG);
 | |
|           if (cp.not_empty())
 | |
|           {
 | |
|             f.set(cp);
 | |
|             key = K_TAB;
 | |
|           }  
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|   }   
 | |
|   
 | |
|   if (key == K_TAB && f.focusdirty() && m.insert_mode() && set_scad)
 | |
|     a.set_scadenze(m);
 | |
| 
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::annorif_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   bool ok = TRUE;
 | |
|   if (f.to_check(key)) 
 | |
|   {   
 | |
|     const TMask& m = f.mask();
 | |
|     if (f.empty() && !m.get(F_NUMRIF).blank())
 | |
|     {
 | |
|       const TString& anno = m.get(F_DATADOC).right(4);
 | |
|       f.set(anno);
 | |
|       ok = error_box(TR("L'anno di riferimento partita e' obbligatorio!"));
 | |
|     }                 
 | |
|   } 
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::numrif_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   bool ok = TRUE;
 | |
|   
 | |
|   if (f.to_check(key, TRUE))
 | |
|   {              
 | |
|     TPrimanota_application& a = app();
 | |
|     TMask& m = f.mask();
 | |
|     const bool moviva = a.iva() != nessuna_iva;  // Maschera IVA?
 | |
|     
 | |
|     bool required = m.insert_mode() && a.is_fattura();
 | |
|     required     &= key == K_ENTER || f.focusdirty();
 | |
|     if (moviva)
 | |
|       required     &= !(m.get_bool(F_SOLAIVA) || m.field(F_OCCASEDIT).active());
 | |
| 
 | |
|     if (required && f.get().blank())
 | |
|     {                                                                
 | |
|       if (moviva && m.field(F_CODPAG).empty())
 | |
|       {
 | |
|         TMask_field& clifo = m.field(a.iva() == iva_vendite ? F_CLIENTE : F_FORNITORE);
 | |
|         clifo.set_dirty();
 | |
|         clifo.on_hit();
 | |
|       }
 | |
| 
 | |
| //      TMask_field& anno = m.field(F_ANNORIF);
 | |
|       if (m.get(F_ANNORIF).empty())
 | |
|         m.set(F_ANNORIF, m.get(F_DATADOC).right(4));
 | |
| 
 | |
|       f.set(m.get(a._npart_is_prot ? F_PROTIVA : F_NUMDOC));
 | |
|       key = K_TAB; // Forza la successiva activate_numrif
 | |
|       
 | |
|       ok = f.error_box(TR("Il numero di riferimento partita e' obbligatorio!"));
 | |
|     }
 | |
|     
 | |
|     if (key == K_TAB && a.is_fattura())
 | |
|       a.activate_numrif(m, TRUE);
 | |
| 
 | |
|     if (ok && key == K_ENTER && m.edit_mode())
 | |
|     {
 | |
|       const TPartita* old = a.partite().first();
 | |
|       if (old && old->ok() && f.get().blank())   // Se esisteva una partita ma ora non piu'
 | |
|       { 
 | |
|         const KEY k = yesnocancel_box(FR("Attenzione la fattura della partita %d %s verra' eliminata.\n"
 | |
|                                       "Premere SI per cancellarla, NO per ripristinarla, ANNULLA per modificarla"),
 | |
|                                       old->anno(), (const char*)old->numero());
 | |
|         switch (k)
 | |
|         {
 | |
|         case K_NO:
 | |
|           f.set(old->numero());
 | |
|           if (m.get(F_ANNORIF).empty())
 | |
|             m.set(F_ANNORIF, old->anno());
 | |
|           break;
 | |
|         case K_ESC:
 | |
|           ok = FALSE;
 | |
|           break;
 | |
|         default:
 | |
|           break;
 | |
|         }
 | |
|       }
 | |
|     }  
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::valuta_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (key == K_TAB && f.to_check(key, TRUE))
 | |
|   {           
 | |
|     TMask& m = f.mask();
 | |
|     const TString& val = f.get();
 | |
|     const bool full = val.not_empty() && val != TCurrency::get_firm_val();
 | |
|     
 | |
|     if (full)
 | |
|     {   
 | |
|       TEdit_field& dc = m.efield(SK_DATACAMBIO);
 | |
|       if (dc.get().empty())      // Inizializza data cambio se assente
 | |
|         dc.set(m.get(F_DATADOC));
 | |
| 
 | |
|       if (f.focusdirty())
 | |
|       {
 | |
|         dc.set_dirty(); 
 | |
|         dc.check(RUNNING_CHECK); // Forza ricerca cambio
 | |
|         dc.on_hit();             // Forza messaggi (eventuale copia a pag. 3)
 | |
|         if (m.get(SK_CAMBIO).empty())
 | |
|         {      
 | |
|           TCursor& cur = *dc.browse()->cursor();
 | |
|           if (cur.items() == 0)  // Uso cambio standard
 | |
|           {
 | |
|             const TRectype& recval = cache().get("%VAL", val);
 | |
|             dc.set(recval.get("D0"));     
 | |
|             m.enable(SK_CAMBIO); // Abilito per far funzionare la prossima riga
 | |
|             m.set(SK_CAMBIO, recval.get("S4"), TRUE);
 | |
|           }
 | |
|         }   
 | |
|         
 | |
|         if (m.id2pos(F_VALUTAINTRA) >= 0)
 | |
|         {
 | |
|           TEdit_field& vi = m.efield(F_VALUTAINTRA);
 | |
|           if (vi.active() && vi.empty())
 | |
|           {            
 | |
|             m.set(F_VALUTAINTRA, val);
 | |
|             m.set(F_CAMBIOINTRA, m.get(SK_CAMBIO), TRUE);
 | |
|           }
 | |
|         }
 | |
|       }  
 | |
|     }
 | |
|     else
 | |
|     {
 | |
|       m.set(SK_CAMBIO, "", TRUE); 
 | |
|       m.set(SK_TOTDOCVAL, "", TRUE);
 | |
|       if (m.id2pos(SK_CONTROEURO) >= 0)
 | |
|         m.set(SK_CONTROEURO, "", TRUE);
 | |
|     }  
 | |
|     m.enable(SK_CAMBIO, full); 
 | |
|     m.enable(SK_TOTDOCVAL, full);
 | |
|     
 | |
|     if (app().is_fattura())  
 | |
|       m.set(FS_VALUTA, val);                 // Copia a pagina 3
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::datacambio_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (key == K_TAB && f.to_check(key, TRUE))
 | |
|   {                                         
 | |
|     if (app().is_fattura())
 | |
|       f.mask().set(FS_DATACAMBIO, f.get());               // Copia a pagina 3
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::cambio_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (key == K_TAB && f.to_check(key, TRUE))
 | |
|   {                   
 | |
|     TMask& m = f.mask();
 | |
|     TPrimanota_application& a = app();
 | |
|  
 | |
|     bool update = a.is_fattura();         // Devo ricopiarmi a pagina 3?
 | |
|     if (f.focusdirty())
 | |
|     {                                                       
 | |
|       // Forza il ricalcolo del totale in lire se necessario
 | |
|       a.gioca_cambi(m.insert_mode() ? 0x1 : 0x0);  
 | |
|     }  
 | |
|     else
 | |
|       update &= !m.is_running();
 | |
|     
 | |
|     if (update)
 | |
|       m.set(FS_CAMBIO, f.get());            // Copia a pagina 3
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::reset_handler(TMask_field& f, KEY key)
 | |
| {                                 
 | |
|   if (key == K_SPACE)
 | |
|   {                  
 | |
|     TMask& m = f.mask();
 | |
|     app().reset_pagamento();     
 | |
|     app().set_scadenze(m);
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::recalc_handler(TMask_field& f, KEY key)
 | |
| {                       
 | |
|   TPrimanota_application& a = app();
 | |
|   if (key == K_SPACE && a.is_fattura())
 | |
|   {
 | |
|     TMask& m = f.mask();
 | |
|     TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|     TPagamento& pag = a.pagamento();
 | |
| 
 | |
|     const bool recalc_aut = f.get().not_empty();
 | |
|     
 | |
|     if (!recalc_aut && pag.tipo_prima_rata() > 3)
 | |
|     {
 | |
|       // SE CAMBIANO I SIGNIFICATI DEL TIPO PRIMA RATA BISOGNA RIFARE TUTTO
 | |
|       pag.set_tipo_prima_rata(pag.tipo_prima_rata() - 3);  
 | |
|       m.set(FS_TIPOPR, pag.desc_tpr());
 | |
|       pag.set_tpr4(TRUE);      
 | |
|     }
 | |
|     else if (recalc_aut && pag.was_tpr4())
 | |
|     {
 | |
|       // SE CAMBIANO I SIGNIFICATI DEL TIPO PRIMA RATA BISOGNA RIFARE TUTTO
 | |
|       pag.set_tpr4(FALSE);  
 | |
|       bool yak = pag.tlit_rata(0) != pag.importo_da_non_dividere(FALSE);
 | |
|       if (pag.in_valuta()) yak |= (pag.tval_rata(0) != pag.importo_da_non_dividere(TRUE));    
 | |
|       if (yak)
 | |
|       {
 | |
|         if (yesno_box(TR("L'importo della prima rata e' stato modificato. "
 | |
|                       "Con il ricalcolo automatico esso non sara' piu'"
 | |
|                       " modificabile. Si desidera "
 | |
|                       "riportare le rate alle condizioni iniziali?")))
 | |
|          {
 | |
|            pag.set_tipo_prima_rata(pag.tipo_prima_rata() + 3); 
 | |
|            m.set(FS_TIPOPR, pag.desc_tpr());
 | |
|            a.reset_pagamento();
 | |
|            a.set_scadenze(m);
 | |
|          }
 | |
|          else warning_box(FR("Il tipo prima rata e' stato modificato in \"%s\" per "
 | |
|                           "poter mantenere la rateazione scelta e la possibilita' di "
 | |
|                           "ricalcolo automatico"),
 | |
|                           pag.desc_tpr());
 | |
|           }
 | |
|       else
 | |
|       {
 | |
|         pag.set_tipo_prima_rata(pag.tipo_prima_rata() + 3); 
 | |
|         m.set(FS_TIPOPR, pag.desc_tpr());
 | |
|       }      
 | |
|     }
 | |
|     
 | |
|     const bool on = pag.tipo_prima_rata() < 4 || !recalc_aut;
 | |
|     ps.enable_cell(0, 1, on);
 | |
|     ps.enable_cell(0, 2, on); 
 | |
|     ps.enable_cell(0, 3, on);
 | |
| 
 | |
|     ps.enable_column(3, recalc_aut);
 | |
|     ps.sheet_mask().enable(DLG_DELREC, !recalc_aut); 
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::nrate_handler(TMask_field& f, KEY key)
 | |
| {                                 
 | |
|   if (key == K_TAB && f.focusdirty())
 | |
|   {
 | |
|     TPagamento& pag = app().pagamento();
 | |
|     pag.set_numero_rate(atoi(f.get()));
 | |
|     if (pag.dirty())
 | |
|     {
 | |
|       TMask& m = f.mask();
 | |
|       TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|       pag.set_sheet(ps);      
 | |
|       app().set_banche(m);
 | |
|       app().pag_rows() = ps.rows_array();        
 | |
|     }
 | |
|     TString8 r; r.format("%d", pag.n_rate());
 | |
|     f.set(r);  
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::codcab_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (key == K_TAB && f.focusdirty())
 | |
|   {
 | |
|     const TMask& m = f.mask();
 | |
|     const short id = f.dlg() == FS_NSCAB ? FS_NSABI : FS_VSABI;
 | |
|     const int pos = id == FS_NSABI ? 7 : 9; // Posizione codici ABI sullo sheet
 | |
|     const TString16 abi = m.get(id);
 | |
|     const TString16 cab = m.get(id+1);
 | |
|     TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|     for (int i = ps.items()-1; i >= 0; i--) // Setta la banca in tutte le righe
 | |
|     {
 | |
|       TToken_string& row = ps.row(i);
 | |
|       row.add(abi, pos);
 | |
|       row.add(cab, pos+1);
 | |
|     }
 | |
|     ps.force_update();
 | |
|   }
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::ratalit_handler(TMask_field& f, KEY key)
 | |
| { 
 | |
|   TMask& m = app().curr_mask();
 | |
|   if (key == K_F8 || (key == K_TAB && f.get().empty() && m.is_running()))   
 | |
|   {
 | |
|     const TPagamento& pag = app().pagamento();
 | |
|     if (pag.in_valuta())
 | |
|     {
 | |
|       const TValuta v(m, FS_VALUTA, FS_DATACAMBIO, FS_CAMBIO, SK_CONTROEURO); 
 | |
|       const real other(f.mask().get(103));
 | |
|       const char* s = v.val2lit(other).string();
 | |
|       f.set(s);    
 | |
|     }                        
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::rataval_handler(TMask_field& f, KEY key)
 | |
| {
 | |
|   if (key == K_F8 || (key == K_TAB  && f.get().empty()))   
 | |
|   {
 | |
|     TPagamento& pag = app().pagamento();
 | |
|     if (pag.in_valuta())
 | |
|     {           
 | |
|       const TValuta v(app().curr_mask(), FS_VALUTA, FS_DATACAMBIO, FS_CAMBIO, SK_CONTROEURO); 
 | |
|       const real other(f.mask().get(102));
 | |
|       TString80 s(v.lit2val(other).string());
 | |
|       f.set(s);
 | |
|     }
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::reset_pagamento()
 | |
| {    
 | |
|   TPagamento& pag = pagamento();
 | |
|   pag.read(); 
 | |
|   pag.set_rate_auto(); 
 | |
| }
 | |
|                          
 | |
| void TPrimanota_application::recalc_scadenze(const TDate& d)
 | |
| {
 | |
|   TPagamento& pag = pagamento();
 | |
|   pag.set_inizio(d); 
 | |
|   // ridefinisci lo sheet sulla base delle nuove rate
 | |
|   TSheet_field& ps = pags(); 
 | |
|   TString_array& rws = pag_rows();                                
 | |
|  
 | |
|   pag.set_sheet(ps);
 | |
|   rws = ps.rows_array();  
 | |
| }
 | |
|                            
 | |
| void TPrimanota_application::set_pagamento(const char* c, const char* d)
 | |
| { 
 | |
|   if (_pag != NULL) 
 | |
|   {
 | |
|     delete _pag;
 | |
|     _pag = NULL;  
 | |
|   }  
 | |
|   if (c != NULL || d != NULL)
 | |
|   {
 | |
|     if (!TDate::isdate(d))
 | |
|       d = "";
 | |
|     _pag = new TPagamento(c, d);
 | |
|   }  
 | |
| } 
 | |
| 
 | |
| void TPrimanota_application::set_totale_pagamento(bool update)
 | |
| {
 | |
|   const TMask& m = curr_mask();
 | |
|   TPagamento& pag = pagamento();        
 | |
|   
 | |
|   const real imposta    = m.id2pos(F_IMPOSTE) >= 0 ?  m.get_real(F_IMPOSTE) : ZERO; 
 | |
|   const real imponibile = m.get_real(F_TOTALE) - imposta;
 | |
|   const real spese      = ZERO;        
 | |
|   
 | |
|   const TValuta cambio(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO, SK_CONTROEURO); 
 | |
|   if (cambio.in_valuta())
 | |
|   { 
 | |
|     const real imposval = cambio.lit2val(imposta);
 | |
|     const real imponval = m.get_real(SK_TOTDOCVAL) - imposval;   
 | |
|     pag.set_total_valuta(imponval, imposval, spese, cambio.cambio(), 
 | |
|                          imponibile, imposta, spese, cambio.codice());
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     pag.set_total(imponibile, imposta, spese);
 | |
|   }  
 | |
|   
 | |
|   if (update)
 | |
|   {        
 | |
|     TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|     pagamento().set_sheet(ps);        // Aggiorna lo sheet
 | |
|     pag_rows() = ps.rows_array();     // copia sheet       
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::set_banche(TMask& m)
 | |
| {
 | |
|   // Aggiunge banche: CM000033
 | |
|   TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|   bool update = FALSE;
 | |
|   for (int i = ps.items()-1; i >= 0; i--)
 | |
|   {
 | |
|     TToken_string& row = ps.row(i);
 | |
|     if (row.get_char(7) <= ' ')
 | |
|     {
 | |
|       row.add(m.get(FS_NSABI), 7);
 | |
|       row.add(m.get(FS_NSCAB), 8);
 | |
|       update = TRUE;
 | |
|     }
 | |
|     if (row.get_char(9) <= ' ')
 | |
|     {                              
 | |
|       row.add(m.get(FS_VSABI), 9);
 | |
|       row.add(m.get(FS_VSCAB), 10);
 | |
|       update = TRUE;
 | |
|     }
 | |
|   }
 | |
|   if (update)
 | |
|     ps.force_update();
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::set_scadenze(TMask& m)
 | |
| {                                                                  
 | |
|   const TString& cp = m.get(F_CODPAG);
 | |
|   const TString& dt = m.get(F_DATADOC);
 | |
|   set_pagamento(cp, dt);   
 | |
|   set_totale_pagamento(FALSE);
 | |
|   
 | |
|   TPagamento& pag = pagamento();
 | |
|   if (m.field(FS_RECALC).enabled())
 | |
|   {
 | |
|     m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
 | |
|     m.set(FS_NAMEPAG, pag.name());
 | |
|     m.set(FS_TIPOPR,  pag.desc_tpr());
 | |
|     m.set(FS_MCOMM,   pag.mese_commerciale() ? "X" : "");
 | |
|     m.set(FS_RECALC,  m.insert_mode() ? "X" : "", TRUE);
 | |
|     m.set(FS_NRATE,   pag.n_rate());
 | |
|   }
 | |
| 
 | |
|   pag.set_rate_auto();          
 | |
|   TSheet_field& ps = m.sfield(FS_RATESHEET);
 | |
|   pag.set_sheet(ps);               // prepara lo sheet
 | |
|   set_banche(m);
 | |
|   _pag_rows = ps.rows_array();     // copia sheet       
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::read_scadenze(TMask& m)
 | |
| {                                                                  
 | |
|   const int anno = m.get_int(F_ANNORIF);
 | |
|   const TString& numpart = m.get(F_NUMRIF);
 | |
| 
 | |
|   if (anno <= 0 || numpart.blank())         // Partita vuota
 | |
|     return false;                           
 | |
|   
 | |
|   TBill clifo; cerca_conto_cf(clifo);          
 | |
|   const TPartita& part = partite().partita(clifo, anno, numpart);
 | |
| 
 | |
|   const TRectype& testa = _rel->curr();    
 | |
|   const long nreg       = testa.get_long(MOV_NUMREG);
 | |
|   const TDate datadoc   = testa.get_date(MOV_DATADOC);
 | |
|   
 | |
|   const int npart = part.prima_fattura(nreg);
 | |
|   if (npart <= 0)                           // Non esiste una riga per questo movimento
 | |
|   {
 | |
|     partite().destroy();
 | |
|     return FALSE;         // Non dovrebbe succedere mai, in quanto gia' beccato sopra!
 | |
|   }  
 | |
|   
 | |
|   // Determino il codice pagamento dalla riga di fattura  
 | |
|   TString4 codpag;                           
 | |
|   const TRiga_partite& partita = part.riga(npart);                   
 | |
|   if (partita.rate() > 0)
 | |
|   {
 | |
|     const TRiga_scadenze& primarata = partita.rata(1);
 | |
|     codpag = primarata.get(SCAD_CODPAG);
 | |
|   }  
 | |
|   set_pagamento(codpag, datadoc.string());
 | |
|   TPagamento& pag = pagamento();        
 | |
| 
 | |
|   const bool in_valuta = ::is_true_value(m.get(SK_VALUTA));
 | |
|   
 | |
|   const real totale = m.get_real(in_valuta ? SK_TOTDOCVAL : F_TOTALE);
 | |
|   if (totale != partita.importo(in_valuta).valore())
 | |
|   {
 | |
|     const TCurrency totdoc_c(totale, m.get(SK_VALUTA));
 | |
|     const TCurrency totdoc_s(partita.importo(in_valuta).valore(), m.get(SK_VALUTA));
 | |
|     const TString i1 = totdoc_c.string(TRUE);
 | |
|     const TString i2 = totdoc_s.string(TRUE);
 | |
|     warning_box(FR("Il totale documento (%s) non corrisponde a quello del saldaconto (%s)."), 
 | |
|                 (const char*)i1, (const char*)i2);
 | |
|   }
 | |
|   if (iva() != nessuna_iva)
 | |
|   {
 | |
|     if (m.get_real(F_IMPOSTE) != partita.get_real(PART_IMPOSTA))
 | |
|     {
 | |
|       const TCurrency imposte_c(m.get_real(F_IMPOSTE));
 | |
|       const TCurrency imposte_s(partita.get_real(PART_IMPOSTA));
 | |
|       const TString i1 = imposte_c.string(TRUE);
 | |
|       const TString i2 = imposte_s.string(TRUE);
 | |
|       warning_box(FR("Il totale delle imposte (%s) non corrisponde a quello del saldaconto (%s)."), 
 | |
|                   (const char*)i1, (const char*)i2);
 | |
|     }
 | |
|   }
 | |
|  
 | |
|   set_totale_pagamento(FALSE);
 | |
| 
 | |
|   TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|   
 | |
|   const int protette = partita.ultima_rata_con_abbuoni_diffcam();
 | |
|       
 | |
|   pag.zap_rate();                              // Azzera pagamento
 | |
|   for (int i = 1; i <= partita.rate(); i++)    // E' necessario andare in avanti!!!
 | |
|   { 
 | |
|     const TRiga_scadenze& scadenza = partita.rata(i);
 | |
|     real  importo       = scadenza.get_real(SCAD_IMPORTO); 
 | |
|     const TDate scad    = scadenza.get_date(SCAD_DATASCAD);
 | |
|     const int tipop     = scadenza.get_int(SCAD_TIPOPAG);     
 | |
|     const bool prot     = i <= protette;       // Non cancellabile
 | |
|     const TString16 ulc = scadenza.get(SCAD_ULTCLASS);                       
 | |
|     if (in_valuta)
 | |
|     {                                                        
 | |
|       const real impval(scadenza.get(SCAD_IMPORTOVAL));
 | |
|       pag.set_rata(i-1, impval, importo, scad, tipop, ulc, prot);
 | |
|     }
 | |
|     else
 | |
|       pag.set_rata(i-1, ZERO, importo, scad, tipop, ulc, prot);
 | |
|         
 | |
|     TToken_string& str = ps.row(i-1);
 | |
|     str.add(scadenza.get(SCAD_CODABIPR), 7);
 | |
|     str.add(scadenza.get(SCAD_CODCABPR), 8);
 | |
|     str.add(scadenza.get(SCAD_CODABI),   9);
 | |
|     str.add(scadenza.get(SCAD_CODCAB),   10);    
 | |
|     if (i == 1)
 | |
|     {
 | |
|       m.set(FS_NSABI, str.get(7));
 | |
|       m.set(FS_NSCAB, str.get(8));
 | |
|       m.set(FS_VSABI, str.get(9));
 | |
|       m.set(FS_VSCAB, str.get(10));
 | |
|       m.set(FS_AGENTE, scadenza.get(SCAD_CODAG));
 | |
|     }    
 | |
|     str.add(scadenza.get(SCAD_DESCR),    11);    
 | |
|     str.add(scadenza.get(SCAD_BLOCCATA), 12);    
 | |
|     str.add(prot ? "X" : " ",            13);    
 | |
|   } 
 | |
|   m.set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
 | |
|   m.set(FS_NAMEPAG, pag.name());
 | |
|   m.set(FS_TIPOPR,  pag.desc_tpr());
 | |
|   m.set(FS_MCOMM,   pag.mese_commerciale() ? "X" : "", TRUE);
 | |
|   m.set(FS_RECALC,  m.insert_mode() ? "X" : "", TRUE);
 | |
|   m.set(FS_NRATE,   pag.n_rate());
 | |
| 
 | |
|   pag.set_sheet(ps);
 | |
|   _pag_rows = ps.rows_array();
 | |
|   
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| int TPrimanota_application::cerca_conto_cf(TBill& bill) const
 | |
| {
 | |
|   TString_array& a = cgs().rows_array();
 | |
|   if (iva() != nessuna_iva)
 | |
|   {
 | |
|     const char tipocf = clifo();
 | |
|     const long codcf  = curr_mask().get_long(tipocf == 'C' ? F_CLIENTE : F_FORNITORE);
 | |
|     for (int r = 0; r < a.items(); r++)
 | |
|     {             
 | |
|       TToken_string& row = a.row(r);
 | |
|       bill.get(row, 2, 0x1);
 | |
|       if (bill.tipo() == tipocf && bill.codclifo() == codcf)
 | |
|         return r;
 | |
|     }
 | |
|     bill.set(0, 0, codcf, tipocf);
 | |
|   }
 | |
|   else
 | |
|   {
 | |
|     for (int r = 0; r < a.items(); r++)
 | |
|     {             
 | |
|       TToken_string& row = a.row(r);
 | |
|       bill.get(row, 2, 0x1);
 | |
|       if (bill.tipo() > ' ')
 | |
|         return r;
 | |
|     }
 | |
|     if (a.items() > 0)
 | |
|     {
 | |
|       TToken_string& row = a.row(0);
 | |
|       bill.get(row, 2, 0x1);
 | |
|       return 0;
 | |
|     }
 | |
|     else
 | |
|       bill.set(0, 0, 0, ' ');
 | |
|   }
 | |
|   return -1;
 | |
| }
 | |
| 
 | |
| void TPrimanota_application::write_scadenze(const TMask& m)
 | |
| {                    
 | |
|   const long nreg = m.get_long(F_NUMREG);
 | |
|   const int anno  = m.get_int(F_ANNORIF);
 | |
|   const TString numpart(m.get(F_NUMRIF));
 | |
|   
 | |
|   TPartita* oldgame = partite().first();
 | |
|   TPartita* newgame = NULL;
 | |
|   
 | |
|   int nuova_riga = 0;
 | |
| 
 | |
|   if (anno > 0 && !numpart.blank() && m.page_enabled(2))
 | |
|   {
 | |
|     const int tmov = causale().tipomov();
 | |
|     const TString& desc = m.get(F_DESCR);
 | |
|     const TString& codpag = m.get(F_CODPAG);
 | |
|     const TString8 codcaus = causale().codice(); 
 | |
|     const TValuta cambio(m, SK_VALUTA, SK_DATACAMBIO, SK_CAMBIO, SK_CONTROEURO); 
 | |
|     const TString& agente = m.get(FS_AGENTE); 
 | |
|     const char sezione = causale().sezione(1); //get_cgs_imp(0).sezione();        // Dare/Avere
 | |
|  
 | |
|     TBill clifo; 
 | |
|     const int riga_clifo = cerca_conto_cf(clifo);
 | |
|     CHECK(riga_clifo >= 0, "Impossibile generare la fattura senza gruppo/conto cliente");
 | |
|     newgame = new TPartita(clifo, anno, numpart);
 | |
|   
 | |
|     const int row = newgame->prima_fattura(nreg);         // Riga fattura di questo movimento
 | |
|     TRiga_partite& partita = row <= 0 ? newgame->new_row() : newgame->riga(row);
 | |
|     nuova_riga = partita.get_int(PART_NRIGA);
 | |
|     
 | |
|     TPagamento& pag = pagamento();                      
 | |
|                           
 | |
|     // put data on partita
 | |
|     partita.put(PART_TIPOMOV,   tmov);
 | |
|     partita.put(PART_NREG,      nreg);
 | |
|     partita.put(PART_NUMRIG,    riga_clifo+1);
 | |
|     partita.put(PART_DATAREG,   m.get(F_DATAREG)); 
 | |
|     partita.put(PART_DATADOC,   m.get(F_DATADOC));
 | |
|     partita.put(PART_NUMDOC,    m.get(F_NUMDOC));
 | |
|     partita.put(PART_DESCR,     desc);
 | |
|     partita.put(PART_CODCAUS,   codcaus);
 | |
|     partita.put(PART_REG,       causale().reg().name());
 | |
|     partita.put(PART_SEZ,       sezione);
 | |
| 
 | |
| 		if (clifo.gruppo() != partita.get_int(PART_GRUPPOCL) ||
 | |
| 		  clifo.conto() != partita.get_int(PART_CONTOCL))
 | |
| 		{
 | |
| 			partita.put(PART_GRUPPOCL, clifo.gruppo());
 | |
| 			partita.put(PART_CONTOCL, clifo.conto());
 | |
| 		}
 | |
| 
 | |
|     if (iva() != nessuna_iva)
 | |
|       partita.put(PART_PROTIVA, m.get_long(F_PROTIVA));
 | |
|     
 | |
|     TImporto totdoc = get_cgs_imp(riga_clifo);
 | |
| 		totdoc.normalize(sezione);
 | |
|     partita.put(PART_IMPTOTDOC, totdoc.valore());
 | |
| 
 | |
|     cambio.put(partita);
 | |
|     const bool in_valuta = cambio.in_valuta();
 | |
|     
 | |
|     if (in_valuta)
 | |
|       partita.put(PART_IMPTOTVAL, m.get(SK_TOTDOCVAL));
 | |
|     
 | |
|     real imponibile, imponibile_val;
 | |
|     int i;
 | |
|        
 | |
|     for (i = pag.n_rate()-1; i >= 0; i--)
 | |
|     {            
 | |
|       if (in_valuta)
 | |
|         imponibile_val += pag.tval_rata(i);
 | |
|       imponibile += pag.tlit_rata(i);
 | |
|     }
 | |
| 		
 | |
|     partita.put(PART_IMPORTO, imponibile);
 | |
|     partita.put(PART_IMPORTOVAL, imponibile_val);
 | |
|     partita.put(PART_SPESE, pag.spese());
 | |
|     if (iva() != nessuna_iva)
 | |
|       partita.put(PART_IMPOSTA, m.get(F_IMPOSTE));
 | |
|   
 | |
|     TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | |
|     
 | |
|     partita.elimina_rata(-1);                    // Elimina tutte le rate eventuali
 | |
|     for (i = 0; i < ps.items(); i++)
 | |
|     {    
 | |
|       TToken_string& row = ps.row(i);
 | |
|       
 | |
|       TRiga_scadenze& scadenza = partita.new_row(); 
 | |
| 
 | |
|       scadenza.put(SCAD_CODPAG,     codpag);     // Codice pagamento
 | |
|       scadenza.put(SCAD_CODAG,      agente);     // Codice agente
 | |
| 
 | |
|       scadenza.put(SCAD_DATASCAD,   row.get(0)); // 0 = Data scadenza
 | |
|       scadenza.put(SCAD_IMPORTO,    row.get());  // 1 = Importo
 | |
|       scadenza.put(SCAD_IMPORTOVAL, row.get());  // 2 = Importo in valuta
 | |
|       row.get();                                 // 3 = Percentuale
 | |
|       scadenza.put(SCAD_TIPOPAG,    row.get());  // 4 = Tipo pagamento
 | |
|       scadenza.put(SCAD_ULTCLASS,   row.get());  // 5 = Ulteriore classificazione
 | |
|       row.get();                                 // 6 = Descrizione pagamento
 | |
|       scadenza.put(SCAD_CODABIPR,   row.get());  // 7 = Ns ABI  
 | |
|       scadenza.put(SCAD_CODCABPR,   row.get());  // 8 = Ns CAB  
 | |
|       scadenza.put(SCAD_CODABI,     row.get());  // 9 = Vs ABI  
 | |
|       scadenza.put(SCAD_CODCAB,     row.get());  //10 = Vs CAB 
 | |
|       scadenza.put(SCAD_DESCR,      row.get());  //11 = Note  
 | |
|       scadenza.put(SCAD_BLOCCATA,   row.get());  //12 = Non pagabile  
 | |
|     }
 | |
|   }
 | |
| 
 | |
|   if (oldgame != NULL)
 | |
|   {
 | |
|     const int rigafatt = oldgame->prima_fattura(nreg);
 | |
|     if (rigafatt > 0)
 | |
|     {
 | |
|       if (newgame == NULL || *oldgame != *newgame)
 | |
|       {        
 | |
|         bool sposta = newgame != NULL;
 | |
|         if (sposta)
 | |
|         {                   
 | |
|           sposta = (oldgame->conto().sottoconto() == newgame->conto().sottoconto());
 | |
|           if (sposta)
 | |
|             sposta = yesno_box(FR("Si desidera spostare la fattura e gli eventuali\n"
 | |
|                                "pagamenti relativi nella partita %d %s?"), anno, (const char*)numpart);
 | |
|         }  
 | |
|         if (sposta)                        
 | |
|         {
 | |
|           oldgame->sposta_riga(rigafatt, *newgame, nuova_riga);
 | |
|         }  
 | |
|         else  
 | |
|         {
 | |
|           oldgame->scollega_pagamenti(rigafatt);
 | |
|           oldgame->rimuovi_riga(rigafatt);
 | |
|         }  
 | |
|         oldgame->rewrite();
 | |
|       }
 | |
|       else
 | |
|       {     
 | |
|         oldgame->sposta_riga(rigafatt, *newgame, nuova_riga);
 | |
|       }
 | |
|     }  
 | |
|   } 
 | |
|   
 | |
|   if (newgame != NULL)           // Se non ho cancellato il numero partita ...
 | |
|   {                    
 | |
|     newgame->write();            // Salva nuova partita
 | |
|     delete newgame;
 | |
|   }  
 | |
| }
 | |
| 
 | |
| 
 | |
| ///////////////////////////////////////////////////////////
 | |
| // Gestione pagamenti
 | |
| ///////////////////////////////////////////////////////////
 | |
| 
 | |
| bool TPrimanota_application::showpartite_handler(TMask_field& f, KEY k)
 | |
| {          
 | |
|   bool ok = TRUE;
 | |
|   TMask& m = f.mask();
 | |
|   TPrimanota_application& a = app();
 | |
|   TMask& cm = a.curr_mask();
 | |
|   
 | |
|   const char tipo = m.get(CG_ROWTYPE)[0];                      
 | |
|   const bool is_nota = tipo == 'T' && a.causale().tipomov() == 2 && cm.field(F_NUMRIF).active();
 | |
|   const bool tras = a._as400 && a.causale().tipomov() > 1 && m.get(CG_TIPO).not_empty();
 | |
|   
 | |
|   if (tipo == 'K' || is_nota || tras)
 | |
|   {
 | |
|     TSheet_field& s = *m.get_sheet();   
 | |
|     const int riga = s.selected();
 | |
| 
 | |
|     if (k == K_SPACE)
 | |
|     {
 | |
|       const bool ok = a.edit_partite(m, riga);
 | |
|       if (ok && riga < s.items())
 | |
|         k = K_ENTER;
 | |
|     } 
 | |
|     
 | |
|     if (k == K_ENTER)
 | |
|     {                                
 | |
|       const long curreg = cm.insert_mode() ? NUMREG_PROVVISORIO : cm.get_long(F_NUMREG);
 | |
|       const TImporto importo(a.get_cgs_imp(riga));
 | |
|       const TImporto speso(a.partite().importo_speso(curreg, riga+1));
 | |
| 
 | |
|       if (tipo == 'K' && !speso.is_zero())
 | |
|       {
 | |
|         a.disable_cgs_cells(riga, 'K');
 | |
|         a.cgs().force_update(riga);
 | |
|       }  
 | |
| 
 | |
|       if (importo != speso)
 | |
|       { 
 | |
|         TString msg(128);              
 | |
|         const TCurrency curr(speso.valore());
 | |
|         msg.format(FR("L'importo sul saldaconto della riga %d e' %s"), (riga+1), (const char*)curr.string(TRUE)); 
 | |
|         if (!speso.is_zero())    
 | |
|           msg << (speso.sezione() == 'A' ? TR(" Avere") : TR(" Dare"));
 | |
|         return f.error_box(msg);
 | |
|       }
 | |
|       f.set_focus();
 | |
|     }  
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| 
 | |
| // deleting significato
 | |
| //  -1      sto cancellando tutto
 | |
| //   0      non sto cancellando nulla
 | |
| //   1      sto cancellando la prima riga contabile
 | |
| //   n      sto cancellando la ennesima riga contabile
 | |
| 
 | |
| bool TPrimanota_application::notify_edit_pagamento(TPartita& p, TRectype& new_pag, 
 | |
|                                                    const TValuta& valuta, int deleting)
 | |
| {   
 | |
|   const int nriga = new_pag.get_int(PAGSCA_NRIGA);       // Riga fattura
 | |
|   const int nrata = new_pag.get_int(PAGSCA_NRATA);       // Numero rata
 | |
|   const int nrigp = new_pag.get_int(PAGSCA_NRIGP);       // Riga pagamento
 | |
|   const TRectype& old_pag = p.pagamento(nriga, nrata, nrigp);
 | |
|   const TRiga_partite& somma = p.riga(nrigp);
 | |
|   const int riga_contabile = somma.get_int(PART_NUMRIG); // Riga movimento
 | |
|   TSheet_field& sheet = cgs();
 | |
|   TBill new_conto; new_conto.get(new_pag, TRUE);
 | |
|   
 | |
|   if (_as400 || !new_conto.ok()) 
 | |
|     deleting = -1;                                       // Ignora contropartite
 | |
| 
 | |
|   if (deleting >= 0)
 | |
|   {
 | |
|     const char sez = somma.sezione();                    // Sezione importo e ritenute
 | |
|     const char controsez = sez == 'A' ? 'D' : 'A';       // Sezione contropartita
 | |
| 
 | |
|     // Aggiornamento contopartita
 | |
|     const TImporto old_importo(controsez, old_pag.get_real(PAGSCA_IMPORTO));
 | |
|     TBill old_conto; old_conto.get(old_pag, TRUE);
 | |
| 
 | |
|     const TImporto new_importo(controsez, new_pag.get_real(PAGSCA_IMPORTO));   
 | |
|     
 | |
|     if (old_importo != new_importo || old_conto != new_conto)
 | |
|     {
 | |
|       int old_riga = bill2pos(old_conto, 'I');
 | |
|       if (old_riga >= 0)
 | |
|       {
 | |
|         const bool empty = sub_cgs_imp(old_riga, old_importo);
 | |
|         if (empty && (new_importo.is_zero() || new_conto != old_conto))
 | |
|           sheet.destroy(old_riga);
 | |
|       }  
 | |
|       else                               
 | |
|         if (!old_importo.is_zero())
 | |
|         {        
 | |
|           TImporto imp = old_importo; imp.swap_section();
 | |
|           set_cgs_row(old_riga, imp, old_conto, "", 'I');
 | |
|         }
 | |
| 
 | |
|       // Importo della contropartita
 | |
|       if (!new_importo.is_zero() && new_conto.ok())
 | |
|       {
 | |
|         int new_riga = bill2pos(new_conto, 'I');
 | |
|         if (new_riga < 0)
 | |
|         {                                 
 | |
|           const int tp = somma.get_int(PART_TIPOPAG);
 | |
|           const int da = p.tipopag2causale(tp);
 | |
|           const TString descagg(causale().desc_agg(da));
 | |
|           new_riga = set_cgs_row(new_riga, new_importo, new_conto, descagg, 'I');
 | |
|                                 
 | |
|           TToken_string& cli_row = sheet.row(riga_contabile-1);
 | |
|           TBill contro; contro.get(cli_row, 9, 0x3);
 | |
|           if (!contro.ok())  // Completa controparita della riga cliente se necessario
 | |
|             new_conto.add_to(cli_row, 9, 0x3);
 | |
|           TString80 descr = cli_row.get(CG_DESCR-FIRST_FIELD);
 | |
|           if (descr.blank()) // Compila descrizione della riga cliente se necessario
 | |
|           {
 | |
|             descr = somma.get(PART_DESCR);
 | |
|             cli_row.add(descr, CG_DESCR-FIRST_FIELD);
 | |
|           }
 | |
|           
 | |
|           // Compila contropartita della nuova riga
 | |
|           TBill clifo; clifo.get(cli_row, 2, 0x3);
 | |
|           TToken_string& new_row = sheet.row(new_riga);
 | |
|           clifo.add_to(new_row, 9, 0x3);
 | |
|         }  
 | |
|         else
 | |
|           add_cgs_imp(new_riga, new_importo);  
 | |
|       }    
 | |
|     }
 | |
|     
 | |
|     // Aggiornamento ritenute fiscali
 | |
|     const real old_ritenute(old_pag.get(PAGSCA_RITENUTE));
 | |
|     const real new_ritenute(new_pag.get(PAGSCA_RITENUTE));    
 | |
|     if (old_ritenute != new_ritenute)
 | |
|     { 
 | |
|       const TImporto grow_ritenute(controsez, new_ritenute-old_ritenute); 
 | |
|       const int riga = type2pos('F');
 | |
|       if (riga < 0)
 | |
|       {
 | |
|         TBill conto_rit; causale().bill(RIGA_PAG_RITFIS, conto_rit);
 | |
|         const TString desc(causale().desc_agg(RIGA_PAG_RITFIS));
 | |
|         set_cgs_row(riga, grow_ritenute, conto_rit, desc, 'F');
 | |
|       }
 | |
|       else 
 | |
|       {
 | |
|         const bool empty = add_cgs_imp(riga, grow_ritenute);
 | |
|         if (empty) sheet.destroy(riga);
 | |
|       }  
 | |
|     }
 | |
| 
 | |
|     // Aggiornamento ritenute sociali
 | |
|     const real old_ritsoc(old_pag.get(PAGSCA_RITSOC));
 | |
|     const real new_ritsoc(new_pag.get(PAGSCA_RITSOC));    
 | |
|     if (old_ritsoc != new_ritsoc)
 | |
|     { 
 | |
|       const TImporto grow_ritenute(causale().sezione_ritsoc(), new_ritsoc-old_ritsoc); 
 | |
|       const int riga = type2pos('S');
 | |
|       if (riga < 0)
 | |
|       {
 | |
|         TBill conto_rit; causale().bill(RIGA_PAG_RITSOC, conto_rit);
 | |
|         const TString desc(causale().desc_agg(RIGA_PAG_RITSOC));
 | |
|         set_cgs_row(riga, grow_ritenute, conto_rit, desc, 'S');
 | |
|       }
 | |
|       else 
 | |
|       {
 | |
|         const bool empty = add_cgs_imp(riga, grow_ritenute);
 | |
|         if (empty) sheet.destroy(riga);
 | |
|       }  
 | |
|     }
 | |
|   }      // if (deleting >= 0)
 | |
| 
 | |
|   char old_ap, new_ap;
 | |
|   TImporto old_abbuono, new_abbuono, old_diffcam, new_diffcam;
 | |
|   const bool empty = p.modifica_pagamento(new_pag, valuta,
 | |
|                                           old_ap, old_abbuono, old_diffcam, 
 | |
|                                           new_ap, new_abbuono, new_diffcam, TRUE);
 | |
|   
 | |
|   if (deleting >= 0)
 | |
|   {
 | |
|     // Se c'e' differenza negli abbuoni
 | |
|     if (old_abbuono != new_abbuono || old_ap != new_ap) 
 | |
|     {
 | |
|       if (old_ap != ' ')   // Se c'era un abbuono ...
 | |
|       { 
 | |
|         const int riga_abb = type2pos(old_ap);
 | |
|         CHECK(riga_abb >= 0, "Chiss'e' fregato gli abbuoni?");
 | |
|         const bool empty = add_cgs_imp(riga_abb, old_abbuono);       
 | |
|         if (empty && new_ap != old_ap)
 | |
|           sheet.destroy(riga_abb);
 | |
|         
 | |
|         if (deleting != riga_contabile)
 | |
|         {
 | |
|           // Sottrae l'abbuono con la sezione invertita dalla riga contabile
 | |
|           sub_cgs_imp(riga_contabile-1, old_abbuono); 
 | |
|         }  
 | |
|       }                     
 | |
|       if (new_ap != ' ')                            // Se ci sono abbuoni
 | |
|       {                                       
 | |
|         const int riga_abb = type2pos(new_ap);
 | |
| 
 | |
|         new_abbuono.swap_section();
 | |
|         new_abbuono.normalize();
 | |
| 
 | |
|         if (riga_abb < 0)
 | |
|         {                           
 | |
|           const int rc = new_ap == 'A' ? RIGA_ABBUONI_ATTIVI : RIGA_ABBUONI_PASSIVI;
 | |
|           TBill conto_abb; causale().bill(rc, conto_abb);
 | |
|           const TString desc(causale().desc_agg(rc));
 | |
|           app().set_cgs_row(riga_abb, new_abbuono, conto_abb, desc, new_ap);
 | |
|         }
 | |
|         else
 | |
|           add_cgs_imp(riga_abb, new_abbuono);
 | |
|         
 | |
|         if (deleting != riga_contabile)
 | |
|         {
 | |
|           // Aggiunge l'abbuono con la sezione invertita
 | |
|            sub_cgs_imp(riga_contabile-1, new_abbuono);     
 | |
|         }  
 | |
|       }  
 | |
|     }
 | |
|     
 | |
|     // Se c'e' variazione nella differenza cambi
 | |
|     if (old_diffcam != new_diffcam)                 
 | |
|     {
 | |
|       const int riga_diffcam = type2pos('C');
 | |
|       TImporto grow_diffcam(old_diffcam); 
 | |
|       grow_diffcam -= new_diffcam;
 | |
|       grow_diffcam.normalize();
 | |
|       
 | |
|       if (riga_diffcam < 0)
 | |
|       {
 | |
|         TBill conto_diffcam; causale().bill(RIGA_DIFFCAM, conto_diffcam);
 | |
|         const TString desc(causale().desc_agg(RIGA_DIFFCAM));
 | |
|         set_cgs_row(riga_diffcam, grow_diffcam, conto_diffcam, desc, 'C');
 | |
|       }
 | |
|       else
 | |
|       {
 | |
|         const bool empty = add_cgs_imp(riga_diffcam, grow_diffcam);
 | |
|         if (empty) 
 | |
|           sheet.destroy(riga_diffcam);
 | |
|       }  
 | |
|       
 | |
|       if (deleting != riga_contabile)
 | |
|       {
 | |
|         // Aggiunge la differenza con la sezione invertita
 | |
|         sub_cgs_imp(riga_contabile-1, grow_diffcam);  
 | |
|       }  
 | |
|     }
 | |
|   }     // if (deleting >= 0)
 | |
|   
 | |
|   return empty;
 | |
| }
 | |
| 
 | |
| // Scorre tutte le righe della partita ed azzera i pagamenti relativi a alla riga contabile
 | |
| // cancellata e decrementa i numeri riga superiori a numrig
 | |
| bool TPrimanota_application::notify_cgline_deletion(TPartita& partita, long nreg, int numrig)
 | |
| {                    
 | |
|   bool found = FALSE;
 | |
|   int p;
 | |
|   
 | |
|   // Al primo "giro" elimino i pagamenti dalla rate
 | |
|   for (p = partita.last(); p > 0; p = partita.pred(p))
 | |
|   {
 | |
|     TRiga_partite& part = partita.riga(p);
 | |
|     if (part.is_fattura())
 | |
|     {
 | |
|       for (int r = part.rate(); r > 0; r--)
 | |
|       {
 | |
|         const TRiga_scadenze& scad = part.rata(r);
 | |
|         for (int s = scad.last(); s > 0; s = scad.pred(s))
 | |
|         {
 | |
|           const TRiga_partite& sum = partita.riga(s);
 | |
|           if (sum.get_long(PART_NREG) == nreg && 
 | |
|               (numrig <= 0 || sum.get_int(PART_NUMRIG) == numrig))
 | |
|           {
 | |
|             TRectype nul_pag(scad.row(s));
 | |
|             nul_pag.zero(PAGSCA_IMPORTO);
 | |
|             nul_pag.zero(PAGSCA_IMPORTOVAL);
 | |
|             nul_pag.zero(PAGSCA_RITENUTE);
 | |
|             nul_pag.zero(PAGSCA_RITSOC);
 | |
|             nul_pag.put(PAGSCA_ACCSAL, 'A');
 | |
|             const TValuta val;           // Non cambiare valuta
 | |
|             notify_edit_pagamento(partita, nul_pag, val, numrig);
 | |
|             found = TRUE;
 | |
|           }
 | |
|         }
 | |
|       }
 | |
|     } 
 | |
|   }
 | |
|     
 | |
|   // Alla fine del "giro" elimino i pagamenti non assegnati
 | |
|   TRecord_array& unas = partita.unassigned();
 | |
|   for (int u = unas.last_row(); u > 0; u = unas.pred_row(u))
 | |
|   {
 | |
|     const TRiga_partite& sum = partita.riga(u);
 | |
|     if (sum.get_long(PART_NREG) == nreg && 
 | |
|         (numrig <= 0 || sum.get_int(PART_NUMRIG) == numrig))
 | |
|     {
 | |
|       TRectype nul_pag(unas.row(u, FALSE));
 | |
|       nul_pag.zero(PAGSCA_IMPORTO);
 | |
|       nul_pag.zero(PAGSCA_IMPORTOVAL);
 | |
|       nul_pag.zero(PAGSCA_RITENUTE);
 | |
|       nul_pag.zero(PAGSCA_RITSOC);
 | |
|       nul_pag.put(PAGSCA_ACCSAL, 'A');   // Inutile, ma l'ho copiato da sopra
 | |
|       const TValuta val;                 // Non cambiare valuta
 | |
|       notify_edit_pagamento(partita, nul_pag, val, numrig);
 | |
|       found = TRUE;
 | |
|     }
 | |
|   }
 | |
|   
 | |
|   // Al secondo "giro" decremento NRIGP dalle righe di pagamento
 | |
|   if (numrig > 0)
 | |
|   {
 | |
|     for (p = partita.last(); p > 0; p = partita.pred(p))
 | |
|     {
 | |
|       TRiga_partite& part = partita.riga(p);
 | |
|       if (!part.is_fattura())
 | |
|       {
 | |
|         if (part.get_long(PART_NREG) == nreg)
 | |
|         {
 | |
|           const int nr = part.get_int(PART_NUMRIG);
 | |
|           if (nr > numrig)
 | |
|             part.put(PART_NUMRIG, nr-1);
 | |
|         }   
 | |
|       }    
 | |
|     }
 | |
|   }
 | |
|   
 | |
|   return found;
 | |
| }
 | |
| 
 | |
| bool TPrimanota_application::notify_cgline_deletion(int numrig)
 | |
| {                           
 | |
|   bool found = FALSE;
 | |
| 
 | |
|   const TMask& m = curr_mask();
 | |
|   const long nreg = m.insert_mode() ? NUMREG_PROVVISORIO : m.get_long(F_NUMREG);
 | |
| 
 | |
| //  if (curr_mask().edit_mode())
 | |
| //    partite().add_numreg(nreg);  // Gia' fatto dalla read
 | |
| 
 | |
|   for (TPartita* game = partite().first(); game; game = partite().next())
 | |
|     found |= notify_cgline_deletion(*game, nreg, numrig);
 | |
|   
 | |
|   return found;
 | |
| }
 |