Files correlati : Ricompilazione Demo : [ ] Commento : Allineato uso process_link git-svn-id: svn://10.65.10.50/trunk@11569 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			1216 lines
		
	
	
		
			35 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1216 lines
		
	
	
		
			35 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <execp.h>
 | 
						|
#include <mailbox.h>
 | 
						|
#include <real.h>
 | 
						|
#include <relation.h>
 | 
						|
 | 
						|
#include "../cg/cglib01.h"
 | 
						|
#include "../cg/cgpagame.h"
 | 
						|
#include "../cg/cg21sld.h"
 | 
						|
 | 
						|
#include "sc0100.h"
 | 
						|
#include "sc0100a.h"
 | 
						|
 | 
						|
#define __EXTRA__
 | 
						|
#include "../cg/cg2105.cpp"
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Maschera gestione rate
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TFattura_mask : public TMask
 | 
						|
{
 | 
						|
  TRiga_partite& _fattura;
 | 
						|
  TPagamento* _pag;
 | 
						|
  TString_array _pag_rows;
 | 
						|
  
 | 
						|
protected:        
 | 
						|
  static bool clifo_handler(TMask_field& f, KEY key);
 | 
						|
  static bool datadoc_handler(TMask_field& f, KEY key);
 | 
						|
  static bool codpag_handler(TMask_field& f, KEY key);
 | 
						|
  static bool nrate_handler(TMask_field& f, KEY key);
 | 
						|
  static bool recalc_handler(TMask_field& f, KEY key);
 | 
						|
  static bool codcab_handler(TMask_field& f, KEY key);
 | 
						|
  static bool pag_notify(TSheet_field& ps, int r, KEY k);
 | 
						|
  static bool pag_handler(TMask_field& f, KEY key);
 | 
						|
  static bool reset_handler(TMask_field& f, KEY key);
 | 
						|
  static bool tipopag_handler(TMask_field& f, KEY key);
 | 
						|
 | 
						|
  TPagamento& pagamento() const { return *_pag; }
 | 
						|
  TPagamento& set_pagamento(const char* cod, const char* dat);
 | 
						|
 | 
						|
  TSheet_field& pag_sheet() const { return (TSheet_field&)field(FS_RATESHEET); }
 | 
						|
  void pag2sheet();
 | 
						|
  
 | 
						|
  bool read_scadenze();
 | 
						|
  
 | 
						|
public:
 | 
						|
  void set_totale_pagamento(bool update);
 | 
						|
  void set_scadenze();
 | 
						|
  void write_scadenze() const;
 | 
						|
  real totale_rate(bool val) const;
 | 
						|
 | 
						|
  TFattura_mask(TRiga_partite& fattura);
 | 
						|
  virtual ~TFattura_mask();
 | 
						|
};
 | 
						|
 | 
						|
TFattura_mask::TFattura_mask(TRiga_partite& fattura) 
 | 
						|
             : TMask("sc0100c"), _fattura(fattura), _pag(NULL)
 | 
						|
{              
 | 
						|
  const bool edit = _fattura.rate() > 0;
 | 
						|
  set_mode(edit ? MODE_MOD : MODE_INS);
 | 
						|
  xvt_statbar_set(edit ? TR("Modifica") : TR("Inserimento"), TRUE);
 | 
						|
  
 | 
						|
  enable(DLG_DELREC, edit);
 | 
						|
 | 
						|
  set_handler(E_TOTALE,  TSaldaconto_app::totale_handler);
 | 
						|
  set_handler(E_IMPOSTE, TSaldaconto_app::imposte_handler);
 | 
						|
  set_handler(E_DESCR,   TSaldaconto_app::descr_handler);
 | 
						|
  
 | 
						|
  if (app().gestione_valuta())
 | 
						|
  {
 | 
						|
    set_handler(E_TOTDOCVAL,  TSaldaconto_app::totval_handler);
 | 
						|
    set_handler(E_VALUTA,     TSaldaconto_app::valuta_handler);
 | 
						|
    set_handler(E_DATACAMBIO, TSaldaconto_app::datacambio_handler);
 | 
						|
    set_handler(E_CAMBIO,     TSaldaconto_app::cambio_handler);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    hide(-3);  
 | 
						|
  const char tipo = _fattura.partita().conto().tipo();
 | 
						|
  if (tipo > ' ')  
 | 
						|
  {
 | 
						|
    const short clifo = tipo == 'C' ? E_CLIENTE : E_FORNITORE;  
 | 
						|
    set_handler(clifo, clifo_handler);
 | 
						|
  }
 | 
						|
 | 
						|
  set_handler(E_DATADOC, datadoc_handler);
 | 
						|
  set_handler(E_CODPAG,  codpag_handler);
 | 
						|
  set_handler(FS_NRATE,  nrate_handler);
 | 
						|
  set_handler(FS_RECALC, recalc_handler);
 | 
						|
  set_handler(FS_NSCAB,  codcab_handler);
 | 
						|
  set_handler(FS_VSCAB,  codcab_handler);
 | 
						|
  set_handler(FS_RESET,  reset_handler);
 | 
						|
  
 | 
						|
  TSheet_field& sf = pag_sheet();
 | 
						|
  sf.set_notify(pag_notify);
 | 
						|
  sf.set_handler(pag_handler);
 | 
						|
  
 | 
						|
  TMask& sm = sf.sheet_mask();
 | 
						|
  sm.set_handler(105, tipopag_handler);
 | 
						|
  sm.set_handler(106, tipopag_handler);
 | 
						|
  
 | 
						|
  const bool ad = edit && _fattura.ultima_rata_con_abbuoni_diffcam() > 0;
 | 
						|
  if (ad)  // Esistono abbuoni o differenze cambio sulla fattura
 | 
						|
  {
 | 
						|
    disable(E_SEZIONE);    // Non posso cambiare sezione
 | 
						|
    disable(E_ANNORIF);    // Non posso cambiare partita
 | 
						|
    disable(E_NUMRIF);
 | 
						|
    disable(DLG_DELREC);   // Non posso eliminare
 | 
						|
  }
 | 
						|
  
 | 
						|
  read_scadenze();
 | 
						|
} 
 | 
						|
                            
 | 
						|
TFattura_mask::~TFattura_mask()
 | 
						|
{
 | 
						|
  delete _pag;     
 | 
						|
  xvt_statbar_set(TR("Estratto conto"), TRUE);
 | 
						|
}
 | 
						|
 | 
						|
real TFattura_mask::totale_rate(bool val) const
 | 
						|
{                                                       
 | 
						|
  const TPagamento& pag = pagamento();
 | 
						|
  real tot;
 | 
						|
  for (int r = pag.n_rate()-1; r >= 0; r--)
 | 
						|
    tot += pag.importo_rata(r, val);
 | 
						|
  return tot;
 | 
						|
}
 | 
						|
 | 
						|
void TFattura_mask::pag2sheet()
 | 
						|
{
 | 
						|
  TPagamento& pag = pagamento();
 | 
						|
  TSheet_field& ps = pag_sheet();
 | 
						|
  pag.set_sheet(ps);
 | 
						|
  _pag_rows = ps.rows_array();
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::pag_notify(TSheet_field& ps, int riga, KEY k)
 | 
						|
{                                   
 | 
						|
  TFattura_mask& msk = (TFattura_mask&)ps.mask();      
 | 
						|
  TPagamento&    pag = msk.pagamento();
 | 
						|
  TString_array& rws = msk._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, m_pag = FALSE;
 | 
						|
  bool m_scad = FALSE, m_tipo = FALSE, m_ulc = FALSE, mod = FALSE, m_implit = 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(riga).get_char(13) != 'X';   
 | 
						|
      ps.sheet_mask().enable(DLG_DELREC, can);
 | 
						|
    }  
 | 
						|
    break;
 | 
						|
  case K_ENTER:
 | 
						|
    ns  = ps.row(riga);     
 | 
						|
    ts  = rws.row(riga);    
 | 
						|
    
 | 
						|
    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(riga).get_char(13) != 'X';   
 | 
						|
    if (doit)
 | 
						|
    {
 | 
						|
      pag.remove_rata(riga);
 | 
						|
      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 = riga - 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(), riga);
 | 
						|
      pag.set_datarata(riga, data_scad);
 | 
						|
//      pag.adjust_fixed_scad();
 | 
						|
      msk.pag2sheet();
 | 
						|
    }
 | 
						|
    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(riga, 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(riga);
 | 
						|
      TToken_string  srw = trw;
 | 
						|
      if (m_tipo) trw.add(newt,2); 
 | 
						|
      if (m_ulc)
 | 
						|
        trw.add(newu, 5);
 | 
						|
      if (m_scad)
 | 
						|
      {
 | 
						|
        trw.add(news,3);
 | 
						|
        if (riga > 0)
 | 
						|
        {             
 | 
						|
          TDate d(news);   
 | 
						|
          int scd = (int)(d - pag.data_rata(riga-1));
 | 
						|
          if (pag.mese_commerciale() && (scd % 30) != 0) 
 | 
						|
               scd = 30 * ((scd/30)+1);
 | 
						|
          trw.add(scd, 0);
 | 
						|
        }
 | 
						|
      }
 | 
						|
      if (m_impl)  
 | 
						|
      {
 | 
						|
        trw.add(newl,7); 
 | 
						|
        if (!in_valuta)
 | 
						|
        {
 | 
						|
          const real p = pag.recalc_percrata(riga, FALSE);
 | 
						|
          ps.row(riga).add(p.string(), 3);                                  
 | 
						|
        } 
 | 
						|
        ps.force_update(riga); 
 | 
						|
      }
 | 
						|
      if (m_impv)  
 | 
						|
      {
 | 
						|
        trw.add(newv,4);
 | 
						|
        const real p = pag.recalc_percrata(riga, TRUE);
 | 
						|
        ps.row(riga).add(p.string(), 3);
 | 
						|
        ps.force_update(riga); 
 | 
						|
      }
 | 
						|
      else
 | 
						|
       if (m_tipo)
 | 
						|
         ps.force_update(riga);  
 | 
						|
      if (mod) 
 | 
						|
        rws.row(riga) = ps.row(riga);
 | 
						|
    }    
 | 
						|
      
 | 
						|
    if (ahiahi)  // any error? Rimetti le righe com'erano prima
 | 
						|
    {         
 | 
						|
      if (recalc)
 | 
						|
      {            
 | 
						|
        TString err(80); pag.strerr(ahiahi,err);
 | 
						|
        warning_box(err);
 | 
						|
        ps.row(riga) = rws.row(riga); 
 | 
						|
        ps.force_update(riga); 
 | 
						|
      }  
 | 
						|
    } 
 | 
						|
    else if (recalc && mod && need_recalc) 
 | 
						|
    {                                   
 | 
						|
      msk.pag2sheet();
 | 
						|
    } 
 | 
						|
  }
 | 
						|
  
 | 
						|
  return doit;
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::pag_handler(TMask_field& f, KEY key)
 | 
						|
{           
 | 
						|
  bool ok = TRUE;
 | 
						|
  if (key == K_TAB || key == K_ENTER)
 | 
						|
  {              
 | 
						|
    TFattura_mask& m = (TFattura_mask&)f.mask();
 | 
						|
 | 
						|
    TPagamento& pag = m.pagamento();
 | 
						|
    const TDate dt(m.get(E_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 bool in_valuta = m.get(E_VALUTA).not_empty();
 | 
						|
    real imp;
 | 
						|
    
 | 
						|
    if (key == K_ENTER && m.edit_mode())
 | 
						|
    {      
 | 
						|
      real tot = m.get(in_valuta ? E_TOTDOCVAL : E_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)  
 | 
						|
      {                     
 | 
						|
        const char* const pic = in_valuta ? ".3" : ".";                
 | 
						|
        const TString is(imp.string(pic));
 | 
						|
        const TString ts(tot.string(pic));
 | 
						|
        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(E_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)
 | 
						|
      {
 | 
						|
        const TString is(imp.string("."));
 | 
						|
        const TString ts(totlit.string("."));
 | 
						|
        ok = f.yesno_box(FR("Il totale in lire delle rate e' %s mentre\n"
 | 
						|
                         "il totale del documento e' %s.\n"
 | 
						|
                         "Si desidera registrare ugualmente?"), 
 | 
						|
                         (const char*)is, (const char*)ts);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::datadoc_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (key == K_TAB && f.focusdirty())
 | 
						|
  {
 | 
						|
    TFattura_mask& fm = (TFattura_mask&)f.mask();
 | 
						|
    TPagamento& pag = fm.pagamento();
 | 
						|
    const TDate dd(f.get());
 | 
						|
    if (fm.insert_mode())
 | 
						|
    {
 | 
						|
      pag.set_inizio(dd); 
 | 
						|
      fm.pag2sheet();
 | 
						|
    }   
 | 
						|
    else 
 | 
						|
      pag.set_datadoc(dd);
 | 
						|
  }  
 | 
						|
  
 | 
						|
  if (key == K_ENTER && f.get().empty())
 | 
						|
    return f.error_box(TR("La data del documento e' obbligatoria."));
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
} 
 | 
						|
 | 
						|
bool TFattura_mask::codpag_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  bool ok = TRUE;              
 | 
						|
  
 | 
						|
  TFattura_mask& m = (TFattura_mask&)f.mask();
 | 
						|
 | 
						|
  if (key == K_TAB && f.focusdirty() && m.insert_mode())
 | 
						|
    m.set_scadenze();
 | 
						|
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::clifo_handler(TMask_field& f, KEY key)
 | 
						|
{                  
 | 
						|
  if (key == K_TAB)
 | 
						|
  {                                  
 | 
						|
    TFattura_mask& m = (TFattura_mask&)f.mask();
 | 
						|
    if (m.insert_mode())
 | 
						|
    {              
 | 
						|
      const TEdit_field& clifo = (TEdit_field&)f;
 | 
						|
      const TRectype& cur = clifo.browse()->cursor()->curr();
 | 
						|
      TMask_field& cp = m.field(E_CODPAG);
 | 
						|
      if (cp.get().empty())
 | 
						|
      {
 | 
						|
        cp.set(cur.get(CLI_CODPAG));
 | 
						|
        cp.check(STARTING_CHECK);
 | 
						|
      }  
 | 
						|
      TMask_field& cv = m.field(E_VALUTA);
 | 
						|
      if (cv.get().empty())
 | 
						|
      {
 | 
						|
        cv.set(cur.get(CLI_CODVAL));
 | 
						|
        cv.on_hit();
 | 
						|
      }
 | 
						|
      if (m.get(FS_VSABI).empty())  
 | 
						|
      {
 | 
						|
        m.set(FS_VSABI, cur.get(CLI_CODABI)); 
 | 
						|
        m.set(FS_VSCAB, cur.get(CLI_CODCAB));
 | 
						|
        m.send_key(K_TAB, FS_VSCAB);
 | 
						|
      }
 | 
						|
    }  
 | 
						|
  }  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 
 | 
						|
bool TFattura_mask::reset_handler(TMask_field& f, KEY key)
 | 
						|
{                       
 | 
						|
  TFattura_mask& fm = (TFattura_mask&)f.mask();
 | 
						|
  if (key == K_SPACE && fm.is_running())
 | 
						|
    fm.set_scadenze();
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::recalc_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  TFattura_mask& fm = (TFattura_mask&)f.mask();
 | 
						|
  if (key == K_SPACE)
 | 
						|
  {
 | 
						|
    TSheet_field& ps = (TSheet_field&)fm.field(FS_RATESHEET);
 | 
						|
    TPagamento& pag = fm.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);  
 | 
						|
      fm.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 (f.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); 
 | 
						|
           fm.set(FS_TIPOPR, pag.desc_tpr());
 | 
						|
           fm.set_scadenze();
 | 
						|
         }
 | 
						|
         else 
 | 
						|
           f.warning_box(FR("Il tipo prima rata rimane modificato in %s"), pag.desc_tpr());
 | 
						|
      }
 | 
						|
      else
 | 
						|
      {
 | 
						|
        pag.set_tipo_prima_rata(pag.tipo_prima_rata() + 3); 
 | 
						|
        fm.set(FS_TIPOPR, pag.desc_tpr());
 | 
						|
      }      
 | 
						|
    }
 | 
						|
    
 | 
						|
    ps.enable_column(3, recalc_aut);
 | 
						|
    ps.sheet_mask().enable(DLG_DELREC, !recalc_aut); 
 | 
						|
    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.force_update();
 | 
						|
  }
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::nrate_handler(TMask_field& f, KEY key)
 | 
						|
{                                 
 | 
						|
  if (key == K_TAB && f.focusdirty())
 | 
						|
  {
 | 
						|
    TFattura_mask& fm = (TFattura_mask&)f.mask();
 | 
						|
    TPagamento& pag = fm.pagamento();
 | 
						|
    pag.set_numero_rate(atoi(f.get()));
 | 
						|
    if (pag.dirty())
 | 
						|
      fm.pag2sheet();  
 | 
						|
    
 | 
						|
    TString n; n << pag.n_rate();
 | 
						|
    f.set(n);  
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::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;
 | 
						|
    const TString abi = m.get(id);
 | 
						|
    const TString cab = m.get(id+1);
 | 
						|
    TSheet_field& ps = (TSheet_field&)m.field(FS_RATESHEET);
 | 
						|
    for (int i = ps.items()-1; i >= 0; i--)
 | 
						|
    {
 | 
						|
      TToken_string& row = ps.row(i);
 | 
						|
      row.add(abi, pos);
 | 
						|
      row.add(cab, pos+1);
 | 
						|
    }
 | 
						|
    ps.force_update();
 | 
						|
  }
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
TPagamento& TFattura_mask::set_pagamento(const char* cod, const char* dat)
 | 
						|
{
 | 
						|
  if (_pag != NULL) delete _pag;
 | 
						|
  _pag = new TPagamento(cod, dat);
 | 
						|
  return *_pag;
 | 
						|
}
 | 
						|
 | 
						|
void TFattura_mask::set_totale_pagamento(bool update)
 | 
						|
{
 | 
						|
  TPagamento& pag = pagamento();        
 | 
						|
  
 | 
						|
  const real imposta    = get_real(E_IMPOSTE); 
 | 
						|
  const real imponibile = get_real(E_TOTALE) - imposta;
 | 
						|
  const real spese      = ZERO;        
 | 
						|
  
 | 
						|
  const TValuta cambio(*this, E_VALUTA, E_DATACAMBIO, E_CAMBIO); 
 | 
						|
  if (cambio.in_valuta())
 | 
						|
  { 
 | 
						|
    const real imposval = cambio.lit2val(imposta);
 | 
						|
    const real imponval = get_real(E_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)
 | 
						|
    pag2sheet();
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
bool TFattura_mask::read_scadenze()
 | 
						|
{                                                                  
 | 
						|
  TRelation rel(LF_PARTITE);
 | 
						|
  rel.curr() = _fattura;
 | 
						|
  autoload(rel);
 | 
						|
  
 | 
						|
  // Attenzione: alcune fatture (*) possono non avere il totale del documento!
 | 
						|
  if (get(E_TOTALE).empty())
 | 
						|
    set(E_TOTALE, _fattura.get(PART_IMPORTO));
 | 
						|
 | 
						|
  // Determino il codice pagamento dalla riga di fattura  
 | 
						|
  TString codpag;                           
 | 
						|
  if (_fattura.rate() > 0)
 | 
						|
  {
 | 
						|
    const TRiga_scadenze& primarata = _fattura.rata(1);
 | 
						|
    codpag = primarata.get(SCAD_CODPAG);
 | 
						|
    set(E_CODPAG, codpag);
 | 
						|
  }  
 | 
						|
  
 | 
						|
  TPagamento& pag = set_pagamento(codpag, get(E_DATADOC));
 | 
						|
  
 | 
						|
  const bool in_valuta = _fattura.in_valuta();
 | 
						|
  set_totale_pagamento(FALSE);
 | 
						|
 | 
						|
  TSheet_field& ps = (TSheet_field&)field(FS_RATESHEET);
 | 
						|
  
 | 
						|
  const int protette = _fattura.ultima_rata_con_abbuoni_diffcam();
 | 
						|
      
 | 
						|
  pag.zap_rate();                              // Azzera pagamento
 | 
						|
  for (int i = 1; i <= _fattura.rate(); i++)   // E' necessario andare in avanti!!!
 | 
						|
  { 
 | 
						|
    const TRiga_scadenze& scadenza = _fattura.rata(i);
 | 
						|
    real  importo       = scadenza.get(SCAD_IMPORTO); 
 | 
						|
    const TDate scad    = scadenza.get(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)
 | 
						|
    {
 | 
						|
      set(FS_NSABI, str.get(7));
 | 
						|
      set(FS_NSCAB, str.get(8));
 | 
						|
      set(FS_VSABI, str.get(9));
 | 
						|
      set(FS_VSCAB, str.get(10));
 | 
						|
      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);    
 | 
						|
  } 
 | 
						|
  pag2sheet();
 | 
						|
 | 
						|
  set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
 | 
						|
  set(FS_NAMEPAG, pag.name());
 | 
						|
  set(FS_TIPOPR,  pag.desc_tpr());
 | 
						|
  set(FS_MCOMM,   pag.mese_commerciale() ? "X" : "", TRUE);
 | 
						|
  set(FS_RECALC,  insert_mode() ? "X" : "", TRUE);
 | 
						|
  set(FS_NRATE,   pag.n_rate());
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
void TFattura_mask::set_scadenze()
 | 
						|
{                                                                  
 | 
						|
  const TString cp(get(E_CODPAG));
 | 
						|
  const TString dt(get(E_DATADOC));
 | 
						|
  set_pagamento(cp, dt);   
 | 
						|
  set_totale_pagamento(FALSE);
 | 
						|
  
 | 
						|
  TPagamento& pag = pagamento();
 | 
						|
  if (field(FS_RECALC).enabled())
 | 
						|
  {
 | 
						|
    set(FS_RDIFFER, pag.rate_differenziate() ? "1" : "2");
 | 
						|
    set(FS_NAMEPAG, pag.name());
 | 
						|
    set(FS_TIPOPR,  pag.desc_tpr());
 | 
						|
    set(FS_MCOMM,   pag.mese_commerciale() ? "X" : "");
 | 
						|
    set(FS_RECALC,  insert_mode() ? "X" : "", TRUE);
 | 
						|
    set(FS_NRATE,   pag.n_rate());
 | 
						|
  }
 | 
						|
 | 
						|
  pag.set_rate_auto();          
 | 
						|
  pag2sheet();
 | 
						|
}
 | 
						|
 | 
						|
bool TFattura_mask::tipopag_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if ((key == K_TAB || key == K_ENTER) && f.dirty())
 | 
						|
  {                
 | 
						|
    TFattura_mask& m = (TFattura_mask&)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 = m.pagamento();  
 | 
						|
    bool ok;
 | 
						|
    const char* s = pag.desc_tipo(t, u, &ok);  
 | 
						|
    if (!ok) m.reset(106);
 | 
						|
    m.set(107, s);
 | 
						|
  }
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
void TFattura_mask::write_scadenze() const
 | 
						|
{ 
 | 
						|
  TPartita* oldgame = &_fattura.partita();
 | 
						|
  const TBill conto(oldgame->conto());  // Conto cliente/fornitore della partita                       
 | 
						|
  const int anno = get_int(E_ANNORIF);  // Anno di riferimento
 | 
						|
  const TString numpart(get(E_NUMRIF)); // Numero di riferimento
 | 
						|
  
 | 
						|
  int vecchia_riga = _fattura.get_int(PART_NRIGA);
 | 
						|
  if (insert_mode())
 | 
						|
  {
 | 
						|
    oldgame->rimuovi_riga(vecchia_riga); // Elimina riga creata provvisoriamente 
 | 
						|
    oldgame = NULL;                      // Annulla vecchia partita
 | 
						|
    vecchia_riga = 0;                    // Annulla vecchio numero riga fattura
 | 
						|
  }
 | 
						|
 | 
						|
  TPartita* newgame = NULL;
 | 
						|
  int nuova_riga = 0;  
 | 
						|
 | 
						|
  if (anno > 0 && !numpart.blank())      // In realta' e' sempre cosi' nell'extra-contabile
 | 
						|
  {
 | 
						|
    // Campi invarianti per ogni rata
 | 
						|
    const TString codpag(get(E_CODPAG));
 | 
						|
    const TValuta cambio(*this, E_VALUTA, E_DATACAMBIO, E_CAMBIO); 
 | 
						|
    const TString agente(get(FS_AGENTE)); 
 | 
						|
    
 | 
						|
    newgame = new TPartita(conto, anno, numpart);
 | 
						|
  
 | 
						|
    TRiga_partite& partita = (oldgame != NULL && *newgame == *oldgame) ? 
 | 
						|
                             newgame->riga(vecchia_riga) : newgame->new_row();
 | 
						|
    nuova_riga = partita.get_int(PART_NRIGA);
 | 
						|
    
 | 
						|
    TPagamento& pag = pagamento();                      
 | 
						|
                          
 | 
						|
    // put data on partita
 | 
						|
    partita.put(PART_TIPOMOV,   (int)tm_fattura);
 | 
						|
    partita.put(PART_NUMRIG,    0);
 | 
						|
    partita.put(PART_DATAREG,   get(E_DATAREG)); 
 | 
						|
    partita.put(PART_DATADOC,   get(E_DATADOC));
 | 
						|
    partita.put(PART_NUMDOC,    get(E_NUMDOC));
 | 
						|
    partita.put(PART_DESCR,     get(E_DESCR));
 | 
						|
    partita.put(PART_SEZ,       get(E_SEZIONE));        
 | 
						|
    partita.put(PART_IMPTOTDOC, get(E_TOTALE));
 | 
						|
    partita.put(PART_IMPTOTVAL, get(E_TOTDOCVAL));
 | 
						|
    partita.put(PART_CODCAUS,   get(E_CODCAUS));
 | 
						|
    
 | 
						|
    cambio.put(partita);
 | 
						|
    const bool in_valuta = cambio.in_valuta();
 | 
						|
 | 
						|
    TSheet_field& ps = (TSheet_field&)field(FS_RATESHEET);
 | 
						|
    partita.elimina_rata(-1);                    // Elimina tutte le rate eventuali
 | 
						|
    
 | 
						|
    real imponibile, imponibile_val;   
 | 
						|
    for (int 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
 | 
						|
      
 | 
						|
      const real imp = row.get();     imponibile += imp;
 | 
						|
      const real imp_val = row.get(); imponibile_val += imp_val;
 | 
						|
      
 | 
						|
      scadenza.put(SCAD_IMPORTO,    imp);        // 1 = Importo
 | 
						|
      scadenza.put(SCAD_IMPORTOVAL, imp_val);    // 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  
 | 
						|
    }
 | 
						|
    
 | 
						|
    partita.put(PART_IMPORTO, imponibile);
 | 
						|
    partita.put(PART_IMPORTOVAL, imponibile_val);
 | 
						|
    partita.put(PART_IMPOSTA, get(E_IMPOSTE));
 | 
						|
    partita.put(PART_SPESE, get(FS_SPESE));
 | 
						|
  }
 | 
						|
  
 | 
						|
  if (oldgame != NULL)
 | 
						|
  {
 | 
						|
    if (newgame == NULL || *oldgame != *newgame)
 | 
						|
    {        
 | 
						|
      bool sposta = newgame != NULL;
 | 
						|
      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(vecchia_riga, *newgame, nuova_riga);
 | 
						|
      }  
 | 
						|
      else  
 | 
						|
      {
 | 
						|
        oldgame->scollega_pagamenti(vecchia_riga);
 | 
						|
        oldgame->rimuovi_riga(vecchia_riga);
 | 
						|
      }  
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {     
 | 
						|
      oldgame->sposta_riga(vecchia_riga, *newgame, nuova_riga);
 | 
						|
    }
 | 
						|
    oldgame->rewrite();
 | 
						|
  }    
 | 
						|
 | 
						|
  if (newgame != NULL)               // Se non ho cancellato il numero partita ...
 | 
						|
  {
 | 
						|
    app().partite().insert(newgame); // Aggiungi nuova partita
 | 
						|
    newgame->write(edit_mode());
 | 
						|
  }  
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Addendum alla maschera gestione partite
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
bool TPay_mask::numdoc_handler(TMask_field& f, KEY k)
 | 
						|
{   
 | 
						|
  if (f.to_check(k))   
 | 
						|
  {
 | 
						|
    TPay_mask& m = (TPay_mask&)f.mask();         
 | 
						|
    if (!m._assigned)
 | 
						|
      m.set(S_NUMDOC, f.get());
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}          
 | 
						|
 | 
						|
bool TPay_mask::datareg_handler(TMask_field& f, KEY k)
 | 
						|
{   
 | 
						|
  if (k == K_TAB && (f.focusdirty() || !f.mask().is_running()))   
 | 
						|
  {
 | 
						|
    TMask& m = f.mask();
 | 
						|
    if (m.get(S_DATAPAG).empty())
 | 
						|
      m.set(S_DATAPAG, f.get());
 | 
						|
  } 
 | 
						|
  return TRUE;
 | 
						|
}  
 | 
						|
 | 
						|
bool TPay_mask::datadoc_handler(TMask_field& f, KEY k)
 | 
						|
{   
 | 
						|
  if (f.to_check(k))   
 | 
						|
  {
 | 
						|
    TPay_mask& m = (TPay_mask&)f.mask();         
 | 
						|
    m._datadoc = f.get();
 | 
						|
    if (!m._assigned)
 | 
						|
      m.set(S_DATADOC, m._datadoc);
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}          
 | 
						|
 | 
						|
bool TPay_mask::sezione_handler(TMask_field& f, KEY k)
 | 
						|
{   
 | 
						|
  if (k == K_SPACE)   
 | 
						|
  {
 | 
						|
    TPay_mask& m = (TPay_mask&)f.mask();         
 | 
						|
    if (!m._assigned)
 | 
						|
      m.set(S_SEZIONE_SCAD, f.get());
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}          
 | 
						|
 | 
						|
bool TPay_mask::descr_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  if (k == K_TAB && f.focusdirty())
 | 
						|
  {            
 | 
						|
    TPay_mask& pm = (TPay_mask&)f.mask();
 | 
						|
    const short id = f.dlg() == E_DESCR ? S_DESCAGG : E_DESCR;
 | 
						|
    const char* d = f.get();
 | 
						|
    pm.set(id, d);
 | 
						|
    if (pm.unassigned())
 | 
						|
      pm.set(S_DESCR, d);
 | 
						|
  }                         
 | 
						|
  
 | 
						|
  // Controlla che non sia vuoto insieme alla causale
 | 
						|
  if (f.dlg() == E_DESCR)
 | 
						|
    return TSaldaconto_app::descr_handler(f, k);
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TGame_mask::edit_fattura(TPartita& p, int nriga)
 | 
						|
{                                       
 | 
						|
  const bool nuova = nriga <= 0;          
 | 
						|
  if (nuova)
 | 
						|
    nriga = nuova_riga(p, tm_fattura);
 | 
						|
  
 | 
						|
  TRiga_partite& f = p.riga(nriga);
 | 
						|
  TFattura_mask fm(f);
 | 
						|
  const KEY k = fm.run();
 | 
						|
  bool updated = FALSE;
 | 
						|
  if (k == K_SAVE || k == K_ENTER)  
 | 
						|
  {
 | 
						|
    fm.write_scadenze();
 | 
						|
    updated = TRUE;
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    if (nuova || (k == K_DEL && yesno_box("Confermare l'eliminazione")))
 | 
						|
    {
 | 
						|
      p.rimuovi_riga(nriga);
 | 
						|
      updated = !nuova;
 | 
						|
      if (updated)
 | 
						|
        p.rewrite();
 | 
						|
    }  
 | 
						|
  }  
 | 
						|
  
 | 
						|
  return updated;
 | 
						|
}              
 | 
						|
 | 
						|
bool TGame_mask::prima_nota(const long nreg)
 | 
						|
{   
 | 
						|
  app().partite().destroy();       // Distrugge tutte le partite in memoria
 | 
						|
 | 
						|
  // Nuovo modo elegante
 | 
						|
  TRectype pn(LF_MOV);
 | 
						|
  pn.put(MOV_NUMREG, nreg);
 | 
						|
  bool ok = pn.edit();
 | 
						|
  if (ok)
 | 
						|
    fill_partite();                  // Rilegge partite
 | 
						|
  
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Handlers prima pagina
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
HIDDEN bool is_fattura(TMask& m)
 | 
						|
{
 | 
						|
  const tipo_movimento tm = (tipo_movimento)m.get_int(E_TIPOMOV);
 | 
						|
  return tm == tm_fattura;
 | 
						|
}
 | 
						|
HIDDEN void update_rate(TMask& m)
 | 
						|
{           
 | 
						|
  CHECK(is_fattura(m), "Non e' una maschera di fattura!");
 | 
						|
  if (m.insert_mode())
 | 
						|
  {
 | 
						|
    TFattura_mask& fm = (TFattura_mask&)m;
 | 
						|
    fm.set_scadenze();
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::descr_handler(TMask_field& f, KEY key)
 | 
						|
{             
 | 
						|
  bool ok = TRUE;
 | 
						|
  if ((key == K_TAB && f.focusdirty()) || key == K_ENTER)
 | 
						|
  {
 | 
						|
    if (f.empty() && f.mask().field(E_CODCAUS).empty())
 | 
						|
    {
 | 
						|
      f.error_box(TR("La descrizione e' obbligatoria in assenza della causale"));
 | 
						|
      ok = key == K_TAB;  // Non bloccare sul tab
 | 
						|
    }
 | 
						|
  }                      
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::totale_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  bool ok = TRUE;
 | 
						|
  TMask& m = f.mask();
 | 
						|
  const bool is_fatt = is_fattura(m);
 | 
						|
  
 | 
						|
  if (k == K_F8)
 | 
						|
  {            
 | 
						|
    if (is_fatt)
 | 
						|
    {
 | 
						|
      TFattura_mask& fm = (TFattura_mask&)m;
 | 
						|
      f.set(fm.totale_rate(FALSE).string());
 | 
						|
    }
 | 
						|
    else
 | 
						|
      f.set(m.get(S_IMPORTO));
 | 
						|
    k = K_TAB;
 | 
						|
  }
 | 
						|
 | 
						|
  if (k == K_TAB)
 | 
						|
  {   
 | 
						|
    const bool dirty = f.focusdirty();
 | 
						|
    if (dirty) app().gioca_cambi(m);
 | 
						|
    if (is_fatt)
 | 
						|
    {
 | 
						|
      if (dirty)
 | 
						|
        update_rate(m);
 | 
						|
      const real tot(f.get());
 | 
						|
      const real imp(m.get(E_IMPOSTE));
 | 
						|
      m.set(FS_IMPONIBILI, real(tot-imp));
 | 
						|
      m.set(FS_IMPOSTE, imp);
 | 
						|
    }  
 | 
						|
    else
 | 
						|
    {                    
 | 
						|
      if (dirty || !m.is_running())
 | 
						|
      {
 | 
						|
        TPay_mask& pm = (TPay_mask&)m;
 | 
						|
        if (pm.unassigned())
 | 
						|
          pm.set(S_IMPORTO_SCAD, f.get());
 | 
						|
      }  
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  if (k == K_ENTER)
 | 
						|
  {
 | 
						|
    const real totale(f.get());
 | 
						|
    if (totale.is_zero())
 | 
						|
      ok = yesno_box(TR("Totale documento nullo: continuare ugualmente?"));
 | 
						|
    
 | 
						|
    if (ok)
 | 
						|
    {
 | 
						|
      const TValuta cambio(m, E_VALUTA, E_DATACAMBIO, E_CAMBIO);
 | 
						|
      if (cambio.in_valuta())
 | 
						|
      {
 | 
						|
        const real totval(m.get(E_TOTDOCVAL));
 | 
						|
        const real totlit = cambio.val2lit(totval);
 | 
						|
        if (totale != totlit)
 | 
						|
          ok = yesno_box(FR("Il totale documento in lire dovrebbe essere %s: continuare ugualmente?"),
 | 
						|
                         totlit.string("."));
 | 
						|
      }  
 | 
						|
    }  
 | 
						|
    
 | 
						|
    if (ok && !is_fatt)
 | 
						|
    {
 | 
						|
      const real totdoc(f.get());
 | 
						|
      const real imppag(m.get_real(S_IMPORTO) + m.get_real(S_RITENUTE));
 | 
						|
      if (totdoc != imppag)
 | 
						|
      {
 | 
						|
        TString msg(80);
 | 
						|
        msg << TR("Il totale documento inserito ") << totdoc.string(".");
 | 
						|
        msg << TR("\nnon coincide con l'importo pagato ") << imppag.string(".");
 | 
						|
        msg << TR(".\nSi desidera modificarli?");
 | 
						|
        ok = !f.yesno_box(msg);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }    
 | 
						|
  
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::imposte_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (key == K_TAB && f.focusdirty())
 | 
						|
  {               
 | 
						|
    TMask_field& tot = f.mask().field(E_TOTALE);  
 | 
						|
    tot.set_dirty();
 | 
						|
    tot.on_hit();
 | 
						|
  }  
 | 
						|
  return TRUE;  
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::totval_handler(TMask_field& f, KEY key)
 | 
						|
{   
 | 
						|
  bool ok = TRUE;
 | 
						|
  TMask& m = f.mask(); 
 | 
						|
  const bool is_fatt = is_fattura(m);
 | 
						|
             
 | 
						|
  if (key == K_F8)           
 | 
						|
  {
 | 
						|
    if (is_fatt)
 | 
						|
    {
 | 
						|
      TFattura_mask& fm = (TFattura_mask&)m;
 | 
						|
      f.set(fm.totale_rate(TRUE).string());
 | 
						|
    }
 | 
						|
    else
 | 
						|
      f.set(m.get(S_IMPORTOVAL));
 | 
						|
    key = K_TAB;  
 | 
						|
  }
 | 
						|
  
 | 
						|
  if (key == K_TAB)
 | 
						|
  {        
 | 
						|
    const bool dirty = f.focusdirty();
 | 
						|
    if (dirty)
 | 
						|
      app().gioca_cambi(m);
 | 
						|
                        
 | 
						|
    if (is_fatt)
 | 
						|
    {
 | 
						|
      if (dirty)
 | 
						|
        update_rate(m);
 | 
						|
    }
 | 
						|
    else  
 | 
						|
    {                          
 | 
						|
      if (dirty || !m.is_running())
 | 
						|
      {
 | 
						|
        TPay_mask& pm = (TPay_mask&)m;
 | 
						|
        if (pm.unassigned())
 | 
						|
          pm.set(S_IMPORTOVAL_SCAD, f.get());
 | 
						|
      }    
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  if (key == K_ENTER && !is_fatt)
 | 
						|
  {
 | 
						|
    const real totdoc(f.get());
 | 
						|
    const real imppag(m.get(S_IMPORTOVAL));
 | 
						|
    if (totdoc != imppag)
 | 
						|
    {
 | 
						|
      TString msg(80);
 | 
						|
      msg << TR("Il totale del documento in valuta e' diverso dall'importo pagato ") 
 | 
						|
          << imppag.string(".3") 
 | 
						|
          << TR("\nSi desidera continuare ugualmente?");
 | 
						|
      ok = f.yesno_box(msg);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::valuta_handler(TMask_field& f, KEY k)
 | 
						|
{
 | 
						|
  if (k == K_TAB && f.to_check(k, TRUE))
 | 
						|
  {           
 | 
						|
    TMask& m = f.mask();
 | 
						|
    const TString& val = f.get();
 | 
						|
    const bool full = val.not_empty();
 | 
						|
    
 | 
						|
    if (full)
 | 
						|
    {   
 | 
						|
      TMask_field& dc = m.field(E_DATACAMBIO);
 | 
						|
      if (dc.get().empty())      // Inizializza data cambio se assente
 | 
						|
        dc.set(m.get(E_DATADOC));
 | 
						|
      if (f.focusdirty())
 | 
						|
      {
 | 
						|
        dc.set_dirty(); 
 | 
						|
        dc.check(RUNNING_CHECK); // Forza ricerca cambio
 | 
						|
        dc.on_hit();             // Forza messaggi (eventuale copia a pag. 2)
 | 
						|
      }  
 | 
						|
    }
 | 
						|
    else
 | 
						|
    {
 | 
						|
      m.set(E_CAMBIO, "", TRUE); 
 | 
						|
      m.set(E_TOTDOCVAL, "", TRUE);
 | 
						|
    }  
 | 
						|
    m.enable(E_CAMBIO, full); 
 | 
						|
    m.enable(E_TOTDOCVAL, full);
 | 
						|
    
 | 
						|
    if (is_fattura(m))                
 | 
						|
    {                                                
 | 
						|
      TFattura_mask& fm = (TFattura_mask&)m;
 | 
						|
      fm.set(FS_VALUTA, val);                  // Copia codice valuta a pagina 2
 | 
						|
      fm.set_totale_pagamento(TRUE);           // Aggiorna colonne sheet
 | 
						|
    }  
 | 
						|
    else
 | 
						|
    { 
 | 
						|
      TPay_mask& pm = (TPay_mask&)m;  
 | 
						|
      m.set(S_CODVAL, val);                    // Copia codice valuta a pagina 2
 | 
						|
      pm.attiva_valuta(full);                  // Dis/abilita campi gestione valuta
 | 
						|
    }  
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::datacambio_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (key == K_TAB && f.to_check(key, TRUE))
 | 
						|
  {                          
 | 
						|
    TMask& m = f.mask();             
 | 
						|
    if (is_fattura(m))                
 | 
						|
      m.set(FS_DATACAMBIO, f.get());      // Copia a pagina 2
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TSaldaconto_app::cambio_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (key == K_TAB && f.to_check(key, TRUE))
 | 
						|
  {                   
 | 
						|
    TMask& m = f.mask();
 | 
						|
    bool update = is_fattura(m);         // Devo ricopiarmi a pagina 2?
 | 
						|
    if (f.focusdirty())
 | 
						|
    {                                                       
 | 
						|
      // Forza il ricalcolo del totale in lire se necessario
 | 
						|
      app().gioca_cambi(m, m.insert_mode() ? 0x1 : 0x0);  
 | 
						|
    }  
 | 
						|
    else
 | 
						|
      update &= !m.is_running();
 | 
						|
    
 | 
						|
    if (update)
 | 
						|
      m.set(FS_CAMBIO, f.get());            // Copia a pagina 3
 | 
						|
  }
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Gestione partite extra-contabili
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
void TSaldaconto_app::edit_partite(const TMask& m)
 | 
						|
{                                           
 | 
						|
  const char t = m.get(F_TIPO)[0];
 | 
						|
  const int g  = m.get_int(F_GRUPPO);
 | 
						|
  const int c  = m.get_int(F_CONTO);
 | 
						|
  const long s = m.get_long(F_SOTTOCONTO);
 | 
						|
  const TBill b(g, c, s, t);  // Legge il conto della riga selezionata
 | 
						|
  TGame_mask gm(b, 0, 0);                
 | 
						|
  gm.run();
 | 
						|
  partite().destroy();        // Azzera memoria        
 | 
						|
}
 | 
						|
 |