897 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			897 lines
		
	
	
		
			30 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <relapp.h>  
 | 
						||
#include <msksheet.h>
 | 
						||
#include <sheet.h>
 | 
						||
#include <utility.h>
 | 
						||
#include <lffiles.h>
 | 
						||
#include <clifo.h>
 | 
						||
#include "ef0.h"
 | 
						||
#include "ef0300.h"
 | 
						||
#include "ef0301.h"
 | 
						||
 | 
						||
//////////////////////////////////////////////////////////////////////////////
 | 
						||
//Classe per la gestione di distinte (inserimento, modifica, cancellazione) // 
 | 
						||
//  e per la creazione automatica di distinte per importi.                  //
 | 
						||
//////////////////////////////////////////////////////////////////////////////
 | 
						||
class TVariazione_distinte: public TRelation_application
 | 
						||
{
 | 
						||
  TMask *_msk, *_m2;
 | 
						||
  TDistinta *_distinta;
 | 
						||
  TRelation *_rel;                          
 | 
						||
  TLocalisamfile *_reff, *_cession, *_clifo;
 | 
						||
protected:                            
 | 
						||
  virtual void init_query_mode(TMask&); 
 | 
						||
  virtual void init_insert_mode(TMask&); 
 | 
						||
  virtual void init_modify_mode(TMask&);
 | 
						||
  virtual const char* get_next_key();  
 | 
						||
  virtual int read(TMask& m);
 | 
						||
  virtual int rewrite(const TMask& m);
 | 
						||
  virtual int write(const TMask& m);
 | 
						||
  virtual bool remove();    
 | 
						||
  virtual TMask* get_mask(int mode) {return _msk;}
 | 
						||
  virtual bool changing_mask(int mode) {return FALSE;} 
 | 
						||
  static bool tipodist_handler(TMask_field& f, KEY k);
 | 
						||
  static bool importo_handler(TMask_field& f, KEY k);
 | 
						||
  static bool imp_aut_handler(TMask_field& f, KEY k);
 | 
						||
  static bool impdist_notify(TSheet_field& s, int r, KEY key); 
 | 
						||
  static bool imp_notify(TSheet_field& s, int r, KEY key);       
 | 
						||
  static bool conferma_handler(TMask_field& f, KEY k);
 | 
						||
  static bool annulla_handler(TMask_field& f, KEY k); 
 | 
						||
  static bool from_data_handler(TMask_field& f, KEY k);
 | 
						||
  static bool to_data_handler(TMask_field& f, KEY k);
 | 
						||
  static bool ordina_handler(TMask_field& f, KEY k);
 | 
						||
  static void calcola_totale(); 
 | 
						||
  static void calcola();                    
 | 
						||
  static void aggiungi();      
 | 
						||
  static void carica_riba(int tipopag);
 | 
						||
  static void ord_data();
 | 
						||
  static void ord_fatt();
 | 
						||
// ritorna un riferimento allo sheet degli effetti (righe) nella 
 | 
						||
// distinta 
 | 
						||
  TSheet_field& righe_sheet() const { return (TSheet_field&)_msk->field(F_SHEET_RIBA); }
 | 
						||
// ritorna un riferimento allo sheet delle righe 
 | 
						||
  TSheet_field& righe_sel_sheet() const { return (TSheet_field&)_m2->field(F_SHEET); }
 | 
						||
  bool cerca(long num);
 | 
						||
  bool user_create();
 | 
						||
  bool user_destroy();
 | 
						||
  void aggiorna();
 | 
						||
  TToken_string* common_f(const TMask& m);
 | 
						||
public:
 | 
						||
  virtual TRelation* get_relation() const {return _rel;}
 | 
						||
  TVariazione_distinte() {};
 | 
						||
  virtual ~TVariazione_distinte() {};
 | 
						||
};
 | 
						||
 | 
						||
// restituisce un riferimento all' applicazione
 | 
						||
inline TVariazione_distinte& app(){ return (TVariazione_distinte&)main_app(); }
 | 
						||
 | 
						||
// quando si va in query mode abilita i campi relativi alla chiave 
 | 
						||
// di ricerca e resetta i campi relativi ai totali
 | 
						||
void TVariazione_distinte::init_query_mode(TMask&) 
 | 
						||
{ 
 | 
						||
  _msk->enable(F_NUMBER);
 | 
						||
  _msk->enable(F_TIPODIST);
 | 
						||
  _msk->reset(F_TOTIMP);
 | 
						||
  _msk->enable(F_TIPOPAG);
 | 
						||
}   
 | 
						||
 | 
						||
// quando si va in insert mode resetta i campi della maschera relativi
 | 
						||
// ai totali, abilita i campi relativi alla valuta e disabilta i campi 
 | 
						||
// relativi alla chiave di ricerca
 | 
						||
void TVariazione_distinte::init_insert_mode(TMask&)
 | 
						||
{ 
 | 
						||
  _msk->reset(F_TOTIMP);
 | 
						||
  _msk->enable(F_CODVAL);
 | 
						||
  _msk->disable(F_NUMBER);
 | 
						||
  _msk->disable(F_TIPODIST);    
 | 
						||
} 
 | 
						||
 | 
						||
// quando si va in modify mode disabilta i campi relativi alla chiave
 | 
						||
// di ricerca
 | 
						||
void TVariazione_distinte::init_modify_mode(TMask&)
 | 
						||
{ 
 | 
						||
  _msk->disable(F_NUMBER);
 | 
						||
  _msk->disable(F_TIPODIST);
 | 
						||
  _msk->disable(F_TIPOPAG);
 | 
						||
} 
 | 
						||
 | 
						||
// ritorna il prossimo numero di distinta valido   
 | 
						||
const char* TVariazione_distinte::get_next_key()
 | 
						||
{                                                           
 | 
						||
  long ndist = 99999L;                        
 | 
						||
  const TString16 tipodist = get_mask(MODE_INS)->get(F_TIPODIST);
 | 
						||
  TLocalisamfile& effetti = _rel->lfile(); 
 | 
						||
  effetti.put(EFF_TIPODIST,tipodist); 
 | 
						||
  effetti.put(EFF_NDIST,ndist); 
 | 
						||
  effetti.setkey(4);
 | 
						||
  effetti.read(_isgteq); 
 | 
						||
  if (!effetti.empty() && tipodist == effetti.get(EFF_TIPODIST))
 | 
						||
    ndist = effetti.get_long(EFF_NDIST) + 1;   
 | 
						||
  else 
 | 
						||
    ndist = 1;
 | 
						||
  return format("%d|%ld",F_NUMBER,ndist);  
 | 
						||
}  
 | 
						||
 | 
						||
// ritorna TRUE se trovo nell'array delle righe distinta l'effetto 
 | 
						||
// passato
 | 
						||
bool TVariazione_distinte::cerca(long num)
 | 
						||
{
 | 
						||
  TArray& righedist = _distinta->righe(); 
 | 
						||
 | 
						||
  for (int i = _distinta->items() - 1; i >= 0; i--)// ciclo sugli elementi dell'array
 | 
						||
  {                                                       
 | 
						||
     TEffetto& eff = (TEffetto&)righedist[i];
 | 
						||
 | 
						||
     if (num == eff.get_long(EFF_NPROGTR))
 | 
						||
       return TRUE;
 | 
						||
  }
 | 
						||
  return FALSE;   
 | 
						||
}         
 | 
						||
 | 
						||
// metodo che permette di scivere sull'array (in memoria) gli 
 | 
						||
// effetti presenti nello sheet
 | 
						||
void TVariazione_distinte::aggiorna()
 | 
						||
{       
 | 
						||
  TSheet_field& shrighe = righe_sheet();
 | 
						||
  int items = shrighe.items();                   
 | 
						||
  for (int i = 0; i < items; i++)// prendo tutte le righe dello sheet
 | 
						||
  {                   
 | 
						||
    TToken_string& row = shrighe.row(i);                
 | 
						||
    row.restart();               
 | 
						||
    long num = row.get_long(shrighe.cid2index(F_NRIBA));              
 | 
						||
    if (!cerca(num))// se non <20> gi<67> presente in memoria
 | 
						||
    {               // carico l'effetto nell'array
 | 
						||
      TLocalisamfile eff(LF_EFFETTI);
 | 
						||
      TRectype & rec = eff.curr();
 | 
						||
      eff.setkey(1);
 | 
						||
      rec.zero();
 | 
						||
      rec.put(EFF_NPROGTR, num);
 | 
						||
      eff.read();      
 | 
						||
 | 
						||
      TEffetto* effetto = new TEffetto(rec);
 | 
						||
      TArray& righedist = _distinta->righe();
 | 
						||
 | 
						||
      righedist.add(effetto);
 | 
						||
    }
 | 
						||
  }  
 | 
						||
}
 | 
						||
 | 
						||
// Metodo che permette di prendere i dati dalla maschera e metterli in 
 | 
						||
// una TToken_string che servir<69> per passarli alla write della distinta
 | 
						||
TToken_string* TVariazione_distinte::common_f(const TMask& m)
 | 
						||
{ 
 | 
						||
  char tipodist = m.get(F_TIPODIST)[0];// prendo i dati
 | 
						||
  long ndist = m.get_long(F_NUMBER);  // identificatvi della
 | 
						||
  TDate datadist = (TDate)m.get(F_DATA);// distinta
 | 
						||
  long codabi = m.get_long(F_CODABIP);  // dalla maschera
 | 
						||
  long codcab = m.get_long(F_CODCABP);  
 | 
						||
  m.autosave(*_rel); 
 | 
						||
  TToken_string * datidist= new TToken_string; // creo la token string   
 | 
						||
  datidist->add(tipodist); // inserisco i dati nella
 | 
						||
  datidist->add(ndist);    // token string
 | 
						||
  datidist->add(datadist);
 | 
						||
  datidist->add(codabi);
 | 
						||
  datidist->add(codcab);
 | 
						||
  return datidist;
 | 
						||
}
 | 
						||
 | 
						||
// carica nella maschera i dati dai files 
 | 
						||
int TVariazione_distinte::read(TMask& m)
 | 
						||
{ 
 | 
						||
  m.autoload(*_rel);          
 | 
						||
  int err = _rel->status();
 | 
						||
  if (err == NOERR)
 | 
						||
  {                                                     
 | 
						||
    //resetto l'array che contiene gli effetti nella distinta
 | 
						||
    err = _distinta->reset();
 | 
						||
    // legge la distinta dal record corrente della relazione
 | 
						||
    err = _distinta->read(_rel->curr());   
 | 
						||
    if (err == NOERR)
 | 
						||
    { 
 | 
						||
      TToken_string riga(80);
 | 
						||
      TSheet_field& shrighe = righe_sheet();
 | 
						||
      shrighe.reset();                             
 | 
						||
      // prendo il numero di effetti nella distinta 
 | 
						||
      int items = _distinta->items();
 | 
						||
      TArray& righedist = _distinta->righe();
 | 
						||
      // carico tutti gli effetti della distinta nello sheet
 | 
						||
      if (items > 0)
 | 
						||
      {
 | 
						||
        TEffetto& e = (TEffetto&)righedist[0];
 | 
						||
        m.set(F_DATA, e.get("DATADIST"));// distinta
 | 
						||
        m.set(F_CODABIP, e.get("CODABIP"));  // dalla maschera
 | 
						||
        m.set(F_CODCABP, e.get("CODCABP"));  
 | 
						||
        for (int i = 0; i < items; i++) 
 | 
						||
        { 
 | 
						||
          TEffetto& eff = (TEffetto&)righedist[i];
 | 
						||
          riga.cut(0);    
 | 
						||
          riga.add(' ');
 | 
						||
          const long numero = eff.get_long(EFF_NPROGTR); 
 | 
						||
          riga.add(numero);
 | 
						||
          riga.add(eff.get(EFF_DATASCAD));                                      
 | 
						||
          //prendo la ragione sociale del cliente conoscendone il codice
 | 
						||
          const long codcf = eff.get_long(EFF_CODCF); 
 | 
						||
          _clifo->zero();                                      
 | 
						||
          _clifo->put(CLI_TIPOCF , 'C');
 | 
						||
          _clifo->put(CLI_CODCF, codcf);
 | 
						||
          if (_clifo->read() == NOERR)
 | 
						||
            riga.add(_clifo->get(CLI_RAGSOC));
 | 
						||
          else
 | 
						||
            riga.add("");
 | 
						||
          if (eff.fatt(numero))// se l'effetto contiene solo una fattura 
 | 
						||
          { // metto i riferimenti al documento ed al numero di rata
 | 
						||
            const TRectype& rec_r = eff.row_r(1); 
 | 
						||
            riga.add(rec_r.get(REFF_NFATT));
 | 
						||
            riga.add(rec_r.get(REFF_DATAFATT));
 | 
						||
            if (eff.rows_r() == 1)
 | 
						||
              riga.add(rec_r.get(REFF_NRATA));
 | 
						||
            else
 | 
						||
              riga.add("Varie");
 | 
						||
          }
 | 
						||
          else// se l'effetto contiene pi<70> di una fattura 
 | 
						||
          { // non metto i riferimenti al documento ed al numero di rata
 | 
						||
            riga.add("Varie");
 | 
						||
            riga.add("Varie");
 | 
						||
            riga.add("Varie");   
 | 
						||
          }
 | 
						||
          //gestisco il controllo sulla presenza o meno di una valuta
 | 
						||
          const TString16 codval(eff.get(EFF_CODVAL));
 | 
						||
          if (i == 0)
 | 
						||
          {
 | 
						||
            const bool valuta = (codval.not_empty() && codval != "LIT"); 
 | 
						||
 
 | 
						||
            m.set(F_CODVAL, codval);
 | 
						||
            m.enable(F_CODVAL, valuta);
 | 
						||
          }
 | 
						||
          riga.add(codval);
 | 
						||
          riga.add(eff.get(EFF_IMPORTO));
 | 
						||
          riga.add(eff.get(EFF_IMPORTOVAL));
 | 
						||
          shrighe.row(i) = riga;
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return err;
 | 
						||
}
 | 
						||
 | 
						||
// riscrive distinta
 | 
						||
int TVariazione_distinte::rewrite(const TMask& m)
 | 
						||
{
 | 
						||
  // prima di riscrive controllo se ci sono effetti nello sheet 
 | 
						||
  // selezionati per l'eliminazione
 | 
						||
  TEffetto eff;
 | 
						||
  TLocalisamfile file(LF_EFFETTI); 
 | 
						||
  const char tipodist = _msk->get(F_TIPODIST)[0];
 | 
						||
  const long ndist = _msk->get_long(F_NUMBER);
 | 
						||
  TDistinta * distinta = app()._distinta;
 | 
						||
  TSheet_field& sf = righe_sheet();
 | 
						||
  int items = sf.items();
 | 
						||
  int to_delete = 0;               
 | 
						||
  for (int i = items - 1; i >= 0 ; i--)
 | 
						||
  {
 | 
						||
    TToken_string& row = sf.row(i);   
 | 
						||
    if (*row.get(0) == 'X') // to delete
 | 
						||
      to_delete++;
 | 
						||
  }
 | 
						||
  if (items <= to_delete)
 | 
						||
  { // non posso cancellare tutti gli effetti di una distinta 
 | 
						||
    error_box("Impossibile escludere tutti gli effetti dalla distinta.\n Utilizzare elimina per cancellarla.");
 | 
						||
    return NOERR;
 | 
						||
  }
 | 
						||
  if (to_delete > 0)
 | 
						||
  {
 | 
						||
    TArray& righedist = distinta->righe();
 | 
						||
    //ciclo sugli elementi dello sheet
 | 
						||
  
 | 
						||
    for (int i = items - 1; i >= 0; i--)
 | 
						||
    {  
 | 
						||
       TToken_string& row = sf.row(i);   
 | 
						||
       if (*row.get(0) == 'X') // to delete
 | 
						||
       {                                 
 | 
						||
          const long num = row.get_long(1);
 | 
						||
             //ciclo sugli elementi dell'array
 | 
						||
          for (int j = 0; j < distinta->items(); j++)  
 | 
						||
          {
 | 
						||
            TEffetto& eff = (TEffetto&)righedist[j];
 | 
						||
            if (num == eff.get_long(EFF_NPROGTR))
 | 
						||
             {
 | 
						||
               // tolgo l'effetto dall'array
 | 
						||
               righedist.destroy(j,TRUE);                
 | 
						||
               break;
 | 
						||
             }  
 | 
						||
          }                                                          
 | 
						||
          // tolgo l'effetto dallo sheet       
 | 
						||
          sf.destroy(i);
 | 
						||
          eff.read(file, tipodist, ndist, i + 1);
 | 
						||
          eff.zero(EFF_TIPODIST);
 | 
						||
          eff.zero(EFF_NDIST);
 | 
						||
          eff.zero(EFF_DATADIST);
 | 
						||
          eff.zero(EFF_NRIGADIST);
 | 
						||
          eff.zero(EFF_CODABIP);
 | 
						||
          eff.zero(EFF_CODCABP); 
 | 
						||
          eff.rewrite(file); 
 | 
						||
       }    
 | 
						||
    }
 | 
						||
  }
 | 
						||
  //resetto l'array che contiene gli effetti nella distinta
 | 
						||
  int err = _distinta->reset();
 | 
						||
  aggiorna();                                                             
 | 
						||
  err = _distinta->rewrite(common_f(m));
 | 
						||
  if (err == NOERR)                 
 | 
						||
  { // riposiziono la relazione                             
 | 
						||
    _rel->lfile().setkey(4); 
 | 
						||
    TRectype& curr = _rel->curr();
 | 
						||
    curr.put(EFF_TIPODIST, tipodist);
 | 
						||
    curr. put(EFF_NDIST, ndist);
 | 
						||
    curr. put(EFF_NRIGADIST, 1);
 | 
						||
    _rel->read();
 | 
						||
  } 
 | 
						||
  return err;  
 | 
						||
}
 | 
						||
 | 
						||
// scrive distinta
 | 
						||
int TVariazione_distinte::write(const TMask& m)
 | 
						||
{                                                                        
 | 
						||
  //resetto l'array che contiene gli effetti nella distinta
 | 
						||
  int err = _distinta->reset();
 | 
						||
  char tipodist = m.get(F_TIPODIST)[0];
 | 
						||
  long ndist =  m.get_long(F_NUMBER);              
 | 
						||
  aggiorna();                                                    
 | 
						||
  err = _distinta->write(TRUE, common_f(m));
 | 
						||
  if (err == NOERR)           
 | 
						||
  {  //riposiziono la relazione                         
 | 
						||
    _rel->lfile().setkey(4); 
 | 
						||
    TRectype& curr = _rel->curr();
 | 
						||
    curr.put(EFF_TIPODIST, tipodist);
 | 
						||
    curr. put(EFF_NDIST, ndist);
 | 
						||
    curr. put(EFF_NRIGADIST, 1);
 | 
						||
    _rel->read();
 | 
						||
  } 
 | 
						||
  return err;  
 | 
						||
}
 | 
						||
 | 
						||
// Metodo che permette di eliminare una distinta, l'eliminazione 
 | 
						||
// consiste nell'andare a togliere dagli effetti i dati ad essa 
 | 
						||
// relativi.
 | 
						||
bool TVariazione_distinte::remove() 
 | 
						||
{                                           
 | 
						||
  TMask* m = app()._msk;
 | 
						||
  char tipodist = m->get(F_TIPODIST)[0];
 | 
						||
  long ndist =  m->get_long(F_NUMBER);    
 | 
						||
  int err = _distinta->remove(tipodist, ndist) == NOERR;
 | 
						||
  return err;  
 | 
						||
}
 | 
						||
 | 
						||
// creo la relap
 | 
						||
bool TVariazione_distinte::user_create()
 | 
						||
{
 | 
						||
  _msk = new TMask("ef0300a");  
 | 
						||
  _m2 = new TMask("ef0300c");
 | 
						||
  _rel = new TRelation(LF_EFFETTI);
 | 
						||
  _reff = new TLocalisamfile(LF_REFFETTI);
 | 
						||
  _cession = new TLocalisamfile(LF_CESS);  
 | 
						||
  _clifo = new TLocalisamfile(LF_CLIFO); 
 | 
						||
  _distinta = new TDistinta;  
 | 
						||
  set_search_field(F_NUMBER);//setto il campo di ricerca della distinta
 | 
						||
  _msk->set_handler(F_TIPODIST, tipodist_handler); 
 | 
						||
  _msk->set_handler(F_IMP, importo_handler);
 | 
						||
  _m2->set_handler(F_TOTIMPDIST, imp_aut_handler);
 | 
						||
  _m2->set_handler(DLG_OK, conferma_handler);
 | 
						||
  _m2->set_handler(DLG_CANCEL, annulla_handler);
 | 
						||
  _m2->set_handler(F_DADATA, from_data_handler);
 | 
						||
  _m2->set_handler(F_ADATA, to_data_handler);
 | 
						||
  _m2->set_handler(F_TIPORD, ordina_handler);
 | 
						||
  righe_sheet().set_notify(impdist_notify);  
 | 
						||
  righe_sel_sheet().set_notify(imp_notify); 
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// distruggo la relap
 | 
						||
bool TVariazione_distinte::user_destroy()
 | 
						||
{
 | 
						||
  delete _msk;  
 | 
						||
  delete _m2;
 | 
						||
  delete _rel;                          
 | 
						||
  delete _reff;
 | 
						||
  delete _cession;                    
 | 
						||
  delete _clifo;
 | 
						||
  delete _distinta;
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// Permette di caricare lo sheet per la selezione delle riba da 
 | 
						||
// aggiungere alla distinta: vengono presi tutti gli effetti sul file
 | 
						||
// LF_EFFETTI che non hanno ancora un riferimento ad una distinta;
 | 
						||
// inoltre <20> possibile inserire nella distinta effetti aventi lo stesso
 | 
						||
// tipo di pagamento.
 | 
						||
void TVariazione_distinte::carica_riba(int tipopag)
 | 
						||
{                                     
 | 
						||
// deve caricare solo quegli effetti che non hanno riferimento alla
 | 
						||
// distinta quindi setta i campi ad essa relativi a zero  
 | 
						||
  char tipodist = 0;                       
 | 
						||
  long ndist = 0;
 | 
						||
  int nrigadist = 0;
 | 
						||
  TEffetto eff;     
 | 
						||
  TLocalisamfile f(LF_EFFETTI);             
 | 
						||
  // per prendere la ragione sociale del cliente di cui ho il codice
 | 
						||
  TLocalisamfile * clifo = app()._clifo;
 | 
						||
  TToken_string riga(80);           
 | 
						||
  TMask* m2 = app()._m2;              
 | 
						||
  m2->reset();
 | 
						||
  TSheet_field& sf = (TSheet_field&)m2->field(F_SHEET);
 | 
						||
  sf.reset();                    
 | 
						||
  int err, i = 0;
 | 
						||
  err = eff.read(f, tipodist, ndist, nrigadist);           
 | 
						||
  int tipop =  eff.get_int(EFF_TIPOPAG); 
 | 
						||
  while ( (err == NOERR) && (tipodist == 0)) 
 | 
						||
  {  
 | 
						||
     // se effetti di tipo cambiario (pagher<65>, tratta, tratta accettata)
 | 
						||
     // se non indico un tipo di effetto prendo il tipo del primo che 
 | 
						||
     // seleziono   
 | 
						||
    const bool to_select = (tipopag == 0) || (tipopag == tipop) ||
 | 
						||
                           ((tipopag == 2 || tipopag ==5 || tipopag == 7) &&
 | 
						||
                            (tipop == 2 || tipop ==5 || tipop == 7)); 
 | 
						||
    if (to_select)
 | 
						||
    {
 | 
						||
      riga.cut(0);
 | 
						||
      riga.add(' ');
 | 
						||
      const long numero = eff.get_long(EFF_NPROGTR); 
 | 
						||
      riga.add(numero);
 | 
						||
      riga.add(eff.get(EFF_DATASCAD)); 
 | 
						||
      long codcf = eff.get_long(EFF_CODCF);
 | 
						||
      clifo->zero();
 | 
						||
      clifo->put(CLI_TIPOCF, 'C');
 | 
						||
      clifo->put(CLI_CODCF, codcf);
 | 
						||
      if (clifo->read() == NOERR)
 | 
						||
        riga.add(clifo->get(CLI_RAGSOC));
 | 
						||
      else
 | 
						||
        riga.add("");
 | 
						||
      if (eff.fatt(numero))// se l'effetto contiene solo una fattura 
 | 
						||
      {   // metto i riferimenti al documento ed al numero di rata
 | 
						||
        const TRectype& rec_r = eff.row_r(1); 
 | 
						||
        riga.add(rec_r.get(REFF_NFATT));
 | 
						||
        riga.add(rec_r.get(REFF_DATAFATT));
 | 
						||
        if (eff.rows_r() == 1)
 | 
						||
          riga.add(rec_r.get(REFF_NRATA));
 | 
						||
        else 
 | 
						||
          riga.add(("Varie"));
 | 
						||
      }
 | 
						||
      else// se l'effetto contiene pi<70> di una fattura 
 | 
						||
      {   // non metto i riferimenti al documento ed al numero di rata
 | 
						||
        riga.add(("Varie"));
 | 
						||
        riga.add(("Varie"));
 | 
						||
        riga.add(("Varie"));   
 | 
						||
      }
 | 
						||
      riga.add(eff.get(EFF_CODVAL));
 | 
						||
      riga.add(eff.get(EFF_IMPORTO));
 | 
						||
      riga.add(eff.get(EFF_IMPORTOVAL));
 | 
						||
      sf.row(i) = riga;
 | 
						||
      i++;
 | 
						||
    }      
 | 
						||
    f.setkey(4);
 | 
						||
    err = eff.next(f);//leggo l'effetto successivo 
 | 
						||
    tipodist = eff.get(EFF_TIPODIST)[0];// e ne prendo il tipo distinta 
 | 
						||
    tipop =  eff.get_int(EFF_TIPOPAG);
 | 
						||
  } 
 | 
						||
}
 | 
						||
 | 
						||
// Handler per gestire il fatto che una distinta allo sconto pu<70> 
 | 
						||
// contenere solo effetti cambiari
 | 
						||
bool TVariazione_distinte::tipodist_handler(TMask_field& f, KEY k)
 | 
						||
{ 
 | 
						||
  if (k == K_SPACE)
 | 
						||
  {         
 | 
						||
    TMask &m = f.mask(); 
 | 
						||
    const bool allo_sconto = f.get()[0] == 'S';
 | 
						||
   
 | 
						||
    m.enable(F_TIPOPAG, !allo_sconto);
 | 
						||
    if (allo_sconto)
 | 
						||
      m.set(F_TIPOPAG,2);
 | 
						||
  } 
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// Handler per gestire il caricamento degli effetti nella distinta 
 | 
						||
// in automatico relativamente ad un importo fissato (per la maschera
 | 
						||
// princiapale)
 | 
						||
bool TVariazione_distinte::importo_handler(TMask_field& f, KEY k)
 | 
						||
{ 
 | 
						||
  if (k == K_TAB && f.to_check(k, TRUE))
 | 
						||
  {
 | 
						||
    TMask& m = f.mask();                    
 | 
						||
    const TString16 codval = m.get(F_CODVAL);
 | 
						||
    const bool valuta = codval.not_empty() && codval != "LIT";
 | 
						||
    TSheet_field& sf_riba = (TSheet_field&)m.field(F_SHEET_RIBA);
 | 
						||
    const int mode = m.mode();
 | 
						||
    if( mode == MODE_INS || mode == MODE_MOD) 
 | 
						||
    {     
 | 
						||
      TMask* m2 = app()._m2;
 | 
						||
      real impdist = m.get_real(F_IMP) - m.get_real(F_TOTIMP);   
 | 
						||
      const int tipopag = m.get_int(F_TIPOPAG); 
 | 
						||
// se importo distinta maggiore importo presentato si devono andare a
 | 
						||
// caricare effetti in automatico per un valore minore uguale alla 
 | 
						||
// differenza dei suddetti importi 
 | 
						||
      if (impdist > ZERO)
 | 
						||
      { 
 | 
						||
        app().begin_wait();
 | 
						||
        carica_riba(tipopag);     
 | 
						||
        app().end_wait();
 | 
						||
        m2->reset(F_TOTIMPDIST);
 | 
						||
        m2->reset(F_IMPSEL);
 | 
						||
        m2->set(F_TOTIMPDIST, impdist);
 | 
						||
        m2->run();
 | 
						||
        calcola_totale();
 | 
						||
      }                 
 | 
						||
      else
 | 
						||
        if (impdist < ZERO)
 | 
						||
          error_box("Il valore di presentazione non pu<70> superare l'importo della distinta");        
 | 
						||
    }
 | 
						||
    if (f.focusdirty())
 | 
						||
      sf_riba.force_update();
 | 
						||
  }                                        
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
    
 | 
						||
// Handler per gestire il caricamento degli effetti nella distinta in
 | 
						||
// automatico relativamente ad un importo fissato (per la maschera 
 | 
						||
// secondaria)
 | 
						||
bool TVariazione_distinte::imp_aut_handler(TMask_field& f, KEY k)
 | 
						||
{ 
 | 
						||
  TMask& m2 = f.mask();
 | 
						||
// se quando si entra nell maschera il campo contiene un valore 
 | 
						||
// significa che si deve procedere con il caricamento automatico 
 | 
						||
// di effetti per l'importo iscritto nel campo
 | 
						||
  if (k == K_TAB && f.to_check(k, TRUE))
 | 
						||
  {
 | 
						||
    TMask* m = app()._msk; 
 | 
						||
    TSheet_field& sf = (TSheet_field&)m2.field(F_SHEET);
 | 
						||
    TSheet_field& sf_riba = (TSheet_field&)m->field(F_SHEET_RIBA); 
 | 
						||
    const real impdist = m->get_real(F_IMP) - m->get_real(F_TOTIMP);
 | 
						||
    real res = m2.get_real(F_TOTIMPDIST); 
 | 
						||
    if (res > ZERO && impdist > ZERO)
 | 
						||
    { // se i due importi sono diversi da zero  
 | 
						||
      TString val = m->get(F_CODVAL);
 | 
						||
      if (val == "LIT")
 | 
						||
        val.cut(0);                                
 | 
						||
      int items = sf.items();                       
 | 
						||
      // cerca se esiste un effetto con importo uguale a quello
 | 
						||
      // da caricare    
 | 
						||
      for (int i = 0; i < items; i++)
 | 
						||
      {
 | 
						||
        TToken_string& row = sf.row(i);
 | 
						||
        TString16 codval = row.get(sf.cid2index(F_VALUTA));
 | 
						||
        // se la valuta non appare o <20> lire faccio in modo che vengano
 | 
						||
        // presi gli effetti con valuta inesistente 
 | 
						||
        if (codval == " " || codval == "LIT")
 | 
						||
          codval.cut(0);                                
 | 
						||
        const bool valuta = codval.not_empty();
 | 
						||
        const real imp(row.get(sf.cid2index(valuta ? F_IMPORTOVAL : F_IMPORTO)));        
 | 
						||
        if (imp == res && codval == val) 
 | 
						||
        {  
 | 
						||
          row.add('X', 0);
 | 
						||
          res = ZERO;
 | 
						||
        } 
 | 
						||
      }
 | 
						||
      // se non esiste un effetto con importo uguale a quello
 | 
						||
      // da caricare carico l'importo sommando pi<70> effetti    
 | 
						||
      for (i = 0; res > ZERO && i < items; i++)
 | 
						||
      {
 | 
						||
        TToken_string& row = sf.row(i);
 | 
						||
        TString16 codval = row.get(sf.cid2index(F_VALUTA));
 | 
						||
        if (codval == " " || codval == "LIT")
 | 
						||
          codval.cut(0);                                
 | 
						||
        const bool valuta = codval.not_empty();
 | 
						||
        const real imp = (row.get(sf.cid2index(valuta ? F_IMPORTOVAL : F_IMPORTO)));        
 | 
						||
        // se l'importo, della riga corrente dello sheet, <20> minore 
 | 
						||
        // dell 'importo che si deve caricare e se lo rimane anche 
 | 
						||
        // sommato all'importo gi<67> selezionato, si procede a rendere 
 | 
						||
        // la riga selezionata per il caricamento   
 | 
						||
        if (codval == val && imp <= res)
 | 
						||
        {  
 | 
						||
          row.add('X',0);
 | 
						||
          res -= imp;
 | 
						||
        } 
 | 
						||
      } 
 | 
						||
      sf.force_update();
 | 
						||
      calcola();      
 | 
						||
    }  
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
} 
 | 
						||
 | 
						||
// Handler per gestire la pressione del bottone conferma della maschera
 | 
						||
// per l'aggiunta delle riba (ef0300c)
 | 
						||
bool TVariazione_distinte::conferma_handler(TMask_field& f, KEY k)
 | 
						||
{  
 | 
						||
  if (k == K_ENTER)
 | 
						||
  { 
 | 
						||
    TMask * msk = app()._msk;
 | 
						||
    TSheet_field & sf_riba = (TSheet_field&)msk->field(F_SHEET_RIBA);    
 | 
						||
    TMask& m = f.mask();
 | 
						||
    
 | 
						||
    m.close(); // chiudo la maschera secondaria
 | 
						||
// scarico tutte le righe, selezionate, dello sheet della maschera
 | 
						||
// secondaria nello sheet della maschera primaria della relap (ef0300a)   
 | 
						||
    TSheet_field& sf = (TSheet_field&)m.field(F_SHEET);
 | 
						||
    int items = sf.items();  
 | 
						||
    for (int i = 0; i < items; i++)
 | 
						||
    {
 | 
						||
       TToken_string& row = sf.row(i);   
 | 
						||
       if (*row.get(0) == 'X')  // selected
 | 
						||
       { 
 | 
						||
         row.add(" ", 0);
 | 
						||
         sf_riba.row(-1) = row;
 | 
						||
       }  
 | 
						||
    }                  
 | 
						||
  }   
 | 
						||
  return TRUE;  
 | 
						||
}             
 | 
						||
 | 
						||
// Handler per gestire la pressione del bottone annulla della maschera
 | 
						||
// per l'aggiunta delle riba (ef0300c)
 | 
						||
bool TVariazione_distinte::annulla_handler(TMask_field& f, KEY k)
 | 
						||
{    
 | 
						||
  TMask& m = f.mask();
 | 
						||
  m.close();  
 | 
						||
  return TRUE;  
 | 
						||
}             
 | 
						||
 | 
						||
// Handler per gestire la scelta per data, nella maschera di scelta 
 | 
						||
// delle riba (ef0300c)
 | 
						||
bool TVariazione_distinte::from_data_handler(TMask_field& f, KEY k)
 | 
						||
{
 | 
						||
  if (k == K_TAB)
 | 
						||
  {                   
 | 
						||
   TMask& m = f.mask();
 | 
						||
   if (!f.get().empty())
 | 
						||
   {                                        
 | 
						||
      bool deleted = FALSE;    
 | 
						||
      TDate data = m.get_date(F_DADATA);
 | 
						||
      TSheet_field& sf = (TSheet_field&)m.field(F_SHEET);
 | 
						||
// tolgo dallo sheet gli effetti che hanno una data minore a quella 
 | 
						||
// indicata nel campo della maschera      
 | 
						||
      for(int i = 0; i < sf.items(); i++)
 | 
						||
      {
 | 
						||
          if (deleted) i--;
 | 
						||
          TToken_string& row = sf.row(i);
 | 
						||
          TDate data_sh = (TDate)row.get(2);
 | 
						||
          if (data_sh < data)               
 | 
						||
          {
 | 
						||
             sf.destroy(i); 
 | 
						||
             deleted = TRUE; 
 | 
						||
          }
 | 
						||
          else deleted = FALSE;   
 | 
						||
      }   
 | 
						||
   }
 | 
						||
  }
 | 
						||
  return TRUE;  
 | 
						||
}
 | 
						||
                     
 | 
						||
// Handler per gestire la scelta per data, nella maschera di scelta 
 | 
						||
// delle riba (ef0300c)
 | 
						||
bool TVariazione_distinte::to_data_handler(TMask_field& f, KEY k)
 | 
						||
{              
 | 
						||
  if (k == K_TAB)
 | 
						||
  {        
 | 
						||
   TMask& m = f.mask();                         
 | 
						||
   if (!f.get().empty())
 | 
						||
   {                             
 | 
						||
      bool deleted = FALSE;    
 | 
						||
      TDate data = m.get_date(F_ADATA);
 | 
						||
      TSheet_field& sf = (TSheet_field&)m.field(F_SHEET);
 | 
						||
// tolgo dallo sheet gli effetti che hanno una data maggiore a quella
 | 
						||
// indicata nel campo della maschera            
 | 
						||
      for(int i = 0; i < sf.items(); i++)
 | 
						||
      {
 | 
						||
          if (deleted) i--;
 | 
						||
          TToken_string& row = sf.row(i);
 | 
						||
          TDate data_sh = (TDate)row.get(2);
 | 
						||
          if (data_sh > data)               
 | 
						||
          {
 | 
						||
             sf.destroy(i); 
 | 
						||
             deleted = TRUE; 
 | 
						||
          }
 | 
						||
          else deleted = FALSE;  
 | 
						||
      }   
 | 
						||
   }
 | 
						||
  }  
 | 
						||
  return TRUE; 
 | 
						||
}  
 | 
						||
 | 
						||
// COMPARE FUNCTION per l'ordinamento per data degli effetti presenti
 | 
						||
// nello sheet, nella maschera di scelta delle riba (ef0300c)
 | 
						||
HIDDEN int confronta_data(const TObject** o1, const TObject** o2)
 | 
						||
{
 | 
						||
  int val;
 | 
						||
  TToken_string* s1 = (TToken_string*) *o1; 
 | 
						||
  TToken_string* s2 = (TToken_string*) *o2;   
 | 
						||
  TDate data1 = s1->get(2);
 | 
						||
  TDate data2 = s2->get(2);
 | 
						||
  if (data1 == data2)
 | 
						||
    val = 0;
 | 
						||
  else
 | 
						||
   val = (data1 > data2) ? +1 : -1; 
 | 
						||
  return val;  
 | 
						||
}
 | 
						||
 | 
						||
// Handler per gestire l'ordinamento per data degli effetti presenti 
 | 
						||
// nello sheet, nella maschera di scelta delle riba (ef0300c) 
 | 
						||
void TVariazione_distinte::ord_data()
 | 
						||
{     
 | 
						||
  TMask* m = app()._m2;
 | 
						||
  TSheet_field& sf = (TSheet_field&)m->field(F_SHEET);
 | 
						||
  // scarico tutte le righe dello sheet in un array
 | 
						||
  TArray& effetti = sf.rows_array();
 | 
						||
  app().begin_wait();
 | 
						||
  // faccio l'ordinamento degli elementi dell'array
 | 
						||
  effetti.sort(confronta_data);
 | 
						||
  app().end_wait();
 | 
						||
  sf.force_update();
 | 
						||
}
 | 
						||
 | 
						||
// COMPARE FUNCTION per l'ordinamento per numero e data fattura degli
 | 
						||
// effetti presenti nello sheet, nella maschera di scelta delle riba
 | 
						||
HIDDEN int confronta_fatt(const TObject** o1, const TObject** o2)
 | 
						||
{ 
 | 
						||
  int val;
 | 
						||
  TToken_string* s1 = (TToken_string*) *o1; 
 | 
						||
  TToken_string* s2 = (TToken_string*) *o2;
 | 
						||
  long num1 = s1->get_long(4);
 | 
						||
  long num2 = s2->get_long(4);
 | 
						||
  TDate data1 = s1->get(5);
 | 
						||
  TDate data2 = s2->get(5);
 | 
						||
  // ordinamento sul numero fattura
 | 
						||
  if (num1 != num2)     
 | 
						||
  {
 | 
						||
    val = (num1 > num2) ? +1 : -1;
 | 
						||
    return val;
 | 
						||
  }
 | 
						||
  // ordinamento sulla data fattura  
 | 
						||
  if (data1 == data2)
 | 
						||
  {
 | 
						||
    val = 0; 
 | 
						||
    return val;
 | 
						||
  }  
 | 
						||
  else 
 | 
						||
  {
 | 
						||
    val = (data1 > data2) ? +1 : -1;
 | 
						||
    return val;  
 | 
						||
  }
 | 
						||
}
 | 
						||
                     
 | 
						||
// Handler per gestire l'ordinamento per numero e data fattura degli
 | 
						||
// effetti presenti nello sheet, nella maschera di scelta delle riba
 | 
						||
void TVariazione_distinte::ord_fatt()
 | 
						||
{
 | 
						||
  TMask* m = app()._m2;
 | 
						||
  TSheet_field& sf = (TSheet_field&)m->field(F_SHEET);
 | 
						||
  // scarico le righe dello sheet in un array
 | 
						||
  TArray& effetti = sf.rows_array();
 | 
						||
  app().begin_wait();
 | 
						||
  effetti.sort(confronta_fatt);// ordino gli elementi dell'array
 | 
						||
  app().end_wait();
 | 
						||
  sf.force_update();
 | 
						||
}
 | 
						||
                  
 | 
						||
// Handler per gestire i diversi ordinamenti, nella maschera di scelta
 | 
						||
// delle riba (ef0300c) 
 | 
						||
bool TVariazione_distinte::ordina_handler(TMask_field& f, KEY k)
 | 
						||
{              
 | 
						||
  if (f.to_check(k, TRUE))
 | 
						||
  {
 | 
						||
    char ord = f.get()[0];
 | 
						||
    if (ord == 'S')//ordino gli effetti nello sheet per data
 | 
						||
      ord_data();
 | 
						||
    if (ord == 'F')
 | 
						||
      ord_fatt();//ordino gli effetti nello sheet per fattura   
 | 
						||
  }
 | 
						||
  return TRUE; 
 | 
						||
}
 | 
						||
 | 
						||
// Metodo che calcola i totali relativi alla distinta (totale in 
 | 
						||
// lire e totale in valuta(se presente)) nella maschera principale
 | 
						||
void TVariazione_distinte::calcola_totale()
 | 
						||
{ 
 | 
						||
  TMask* m = app()._msk;
 | 
						||
  TSheet_field& sf = (TSheet_field&)m->field(F_SHEET_RIBA);
 | 
						||
  const int items = sf.items();         
 | 
						||
  real impdist;  
 | 
						||
  const TString16 codval = m->get(F_CODVAL);
 | 
						||
  const bool valuta = codval.not_empty() && codval != "LIT";
 | 
						||
  for (int i = 0; i < items; i++)
 | 
						||
  {
 | 
						||
    TToken_string& row = sf.row(i);     
 | 
						||
// se l'effetto <20> selezionato per l'eliminazione tolgo il suo importo 
 | 
						||
// dal totale presentazione della distinta    
 | 
						||
 | 
						||
    if (*row.get(0) != 'X') // valido (not to delete)
 | 
						||
    {
 | 
						||
      const real imp = row.get(sf.cid2index(valuta ? F_IMPORTOVAL : F_IMPORTO));
 | 
						||
      impdist += imp;                                                           
 | 
						||
    }
 | 
						||
  }
 | 
						||
  m->set(F_TOTIMP, impdist);
 | 
						||
  m->set(F_IMP, impdist);
 | 
						||
}  
 | 
						||
 | 
						||
// Metodo che calcola i totali relativi alla selezione effetti per la
 | 
						||
// distinta nella maschera di scelta delle riba (ef0300c)
 | 
						||
void TVariazione_distinte::calcola()
 | 
						||
{ 
 | 
						||
  TMask* m2 = app()._m2;                   
 | 
						||
  TMask* m = app()._msk;   
 | 
						||
  TSheet_field& sf = (TSheet_field&)m2->field(F_SHEET);
 | 
						||
  const int items = sf.items();         
 | 
						||
  real impsel;                  
 | 
						||
  const real imp_pres = m->get_long(F_TOTIMP);
 | 
						||
  const real importo = m->get_long(F_IMP);
 | 
						||
  const real impdist = importo - imp_pres;
 | 
						||
  const TString16 codval = m->get(F_CODVAL);
 | 
						||
  const bool valuta = codval.not_empty() && codval != "LIT";
 | 
						||
  for (int i = 0; i < items; i++)
 | 
						||
  {
 | 
						||
     TToken_string& row = sf.row(i);     
 | 
						||
// se l'effetto <20> selezionato aggiungo il suo importo al totale importo
 | 
						||
// selezionato     
 | 
						||
     if (*row.get(0) == 'X')
 | 
						||
     {
 | 
						||
       const real imp(row.get(sf.cid2index(valuta ? F_IMPORTOVAL : F_IMPORTO)));
 | 
						||
       impsel += imp;
 | 
						||
     }
 | 
						||
  }
 | 
						||
  m2->set(F_IMPSEL, impsel);
 | 
						||
  if (impdist == ZERO)
 | 
						||
  {
 | 
						||
    if (imp_pres == ZERO)
 | 
						||
      m2->set(F_TOTIMPDIST, impsel);  
 | 
						||
    else
 | 
						||
      m2->set(F_TOTIMPDIST, importo); 
 | 
						||
  }
 | 
						||
}  
 | 
						||
 | 
						||
// Notify per il calcolo dei totali relativi alla selezione effetti 
 | 
						||
// per la distinta nella maschera di scelta delle riba (ef0300c)
 | 
						||
bool TVariazione_distinte::imp_notify(TSheet_field& s, int r, KEY key)
 | 
						||
{            
 | 
						||
  if (s.to_check(key, TRUE)) 
 | 
						||
    calcola();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// Metodo che permette di aggiungere effetti alla distinta caricandoli
 | 
						||
// tra quelli non ancora assegnati, chiamato quando si aggiunge una 
 | 
						||
// riga allo sheet degli effetti della distinta 
 | 
						||
void TVariazione_distinte::aggiungi()
 | 
						||
{
 | 
						||
    TMask* m = app()._msk;  
 | 
						||
    TMask* m2 = app()._m2;   
 | 
						||
    int tipopag = m->get_int(F_TIPOPAG); 
 | 
						||
    app().begin_wait();
 | 
						||
    carica_riba(tipopag);     
 | 
						||
    app().end_wait();
 | 
						||
    m2->reset(F_TOTIMPDIST);
 | 
						||
    m2->reset(F_IMPSEL);
 | 
						||
    m2->run(); 
 | 
						||
    calcola_totale();
 | 
						||
}
 | 
						||
 | 
						||
// Notify per il calcolo dei totali relativi alla distinta  
 | 
						||
// nella maschera della relap (ef0300a)
 | 
						||
bool TVariazione_distinte::impdist_notify(TSheet_field& s, int r, KEY key)
 | 
						||
{            
 | 
						||
  if (s.to_check(key, TRUE)) 
 | 
						||
    calcola_totale();
 | 
						||
  if (key == K_INS) 
 | 
						||
  {
 | 
						||
    aggiungi(); 
 | 
						||
    s.force_update(); 
 | 
						||
    return FALSE;
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
int ef0300(int argc, char* argv[])
 | 
						||
{
 | 
						||
  TVariazione_distinte a ;
 | 
						||
  a.run(argc, argv, "Distinte di presentazione");
 | 
						||
  return 0;
 | 
						||
} |