Files correlati : Ricompilazione Demo : [ ] Commento :sistemato errore di riporto (mancava una } ) git-svn-id: svn://10.65.10.50/trunk@10868 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			2391 lines
		
	
	
		
			64 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			2391 lines
		
	
	
		
			64 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <automask.h>
 | 
						||
#include <dongle.h>
 | 
						||
#include <modaut.h>
 | 
						||
#include <sheet.h>
 | 
						||
#include <tabutil.h>
 | 
						||
#include <tree.h>
 | 
						||
#include <postman.h>
 | 
						||
#include <urldefid.h>
 | 
						||
 | 
						||
#include "velib.h"
 | 
						||
#include "vepriv.h"
 | 
						||
#include "verig.h"
 | 
						||
 | 
						||
#include "ve0100.h"
 | 
						||
#include "ve0100b1.h"
 | 
						||
#include "ve0100o.h"
 | 
						||
#include "veuml.h"
 | 
						||
#include "veuml1.h"
 | 
						||
#include "veini.h"
 | 
						||
 | 
						||
#include "sconti.h"             
 | 
						||
 | 
						||
#include "doc.h"             
 | 
						||
#include "rdoc.h"             
 | 
						||
 | 
						||
TDocumento_mask::TDocumento_mask(const char* td)
 | 
						||
               : TVariable_mask(), _progs_page(-1), _last_prog(-1), 
 | 
						||
                 _condv(NULL)
 | 
						||
{               
 | 
						||
  CHECK(strlen(td) <= 4, "TDocumento_mask(TipoDocumento) not (MaskName)");
 | 
						||
 | 
						||
  {
 | 
						||
    TMagazzini m;
 | 
						||
 | 
						||
    _ges_mag = m.gestmag();
 | 
						||
    _ges_dep = m.gestdep();
 | 
						||
    _std_mag = m.standardmag();
 | 
						||
    _std_dep = m.standarddep();
 | 
						||
  }
 | 
						||
  _doc.set_tipo(td);
 | 
						||
  const TString mname = _doc.tipo().mask_name();
 | 
						||
  read_mask(mname, 0, MAX_PAGES);
 | 
						||
 | 
						||
  int pos = id2pos(BASE_PIEDE + 1);
 | 
						||
  if (pos >= 0)
 | 
						||
  {
 | 
						||
    _progs_page = find_parent_page(fld(pos));
 | 
						||
    _last_prog = 0;
 | 
						||
    while (id2pos(BASE_PIEDE + _last_prog + 1) >= 0)
 | 
						||
      _last_prog++;
 | 
						||
  }
 | 
						||
 | 
						||
  _sheet = &sfield(F_SHEET);      
 | 
						||
  _sheet->set_handler( ss_handler );
 | 
						||
  _sheet->set_notify( ss_notify );
 | 
						||
  _sheet->set_append(FALSE);
 | 
						||
  
 | 
						||
  TList_field& listbox = ( TList_field& )field( F_LBTIPORIGA );
 | 
						||
  
 | 
						||
  TTipo_documento& tdoc = (TTipo_documento&)_doc.tipo();
 | 
						||
  TToken_string& keys   = (TToken_string&) tdoc.keys_descrs()[0];
 | 
						||
  TToken_string& descrs = (TToken_string&) tdoc.keys_descrs()[1];
 | 
						||
  listbox.replace_items(keys, descrs);
 | 
						||
  
 | 
						||
  configura_sheet(*_sheet);
 | 
						||
  
 | 
						||
  ((TVariable_sheet_field*)_sheet)->set_getmask( ss_getmask );
 | 
						||
  if (_doc.tipo().clifo_optional()) 
 | 
						||
  {
 | 
						||
    field(F_CODCF).check_type(CHECK_NORMAL);
 | 
						||
    field(F_RAGSOC).check_type(CHECK_NORMAL);
 | 
						||
  }
 | 
						||
    
 | 
						||
  set_handler( F_OCCASEDIT, occas_handler );
 | 
						||
  set_handler( F_CODCF, clifo_handler );
 | 
						||
  set_handler( F_CODPAG, condpag_hndl );
 | 
						||
  set_handler( F_DATAINSC, condpag_hndl );
 | 
						||
  set_handler( F_CODNOTE, note_hndl );
 | 
						||
  set_handler( F_DATADOC, data_hndl );
 | 
						||
  set_handler( F_CODLIST, codlist_handler ); 
 | 
						||
  set_handler( F_CODLIST1, codlist_handler ); 
 | 
						||
  set_handler( F_CODCONT, codcont_handler ); 
 | 
						||
  set_handler( F_CODCONT1, codcont_handler ); 
 | 
						||
  set_handler( F_CODCAMP, codcamp_handler ); 
 | 
						||
  set_handler( F_CODVAL, codval_handler );
 | 
						||
  set_handler( F_CODVAL1, codval_handler );
 | 
						||
  set_handler( F_DATACAMBIO1, datacambio_handler );
 | 
						||
  set_handler( F_NUMDOCRIF, datadocrif_handler);
 | 
						||
  set_handler( F_DATADOCRIF, datadocrif_handler);
 | 
						||
  set_handler( DLG_ELABORA, elabora_handler );      
 | 
						||
  set_handler( DLG_PRINT, print_handler );
 | 
						||
  
 | 
						||
  const TString_array& handlers = tdoc.handlers();
 | 
						||
  int numhandler = handlers.items();
 | 
						||
  
 | 
						||
  for (int i = 0; i < numhandler; i ++ )
 | 
						||
  {
 | 
						||
    TToken_string& riga = (TToken_string&) handlers[i];
 | 
						||
    user_set_handler( riga.get_int( 0 ), riga.get_int( 1 ) );
 | 
						||
  }
 | 
						||
 | 
						||
  _livelli_giac = new TCodgiac_livelli;
 | 
						||
 | 
						||
  for (i = 4; i > 0; i--)
 | 
						||
  {
 | 
						||
    const short pos = _sheet->cid2index(FR_LIV1 + i -1);
 | 
						||
    if (_livelli_giac->enabled(i))
 | 
						||
    {
 | 
						||
      const TString & header = _livelli_giac->name(i);
 | 
						||
      const int len = header.len() + 1;
 | 
						||
      const int f_len = _livelli_giac->code_length(i);
 | 
						||
      _sheet->set_column_header(pos, header);
 | 
						||
      _sheet->set_column_width(pos, (len > f_len ? len : f_len) * 8);
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      _sheet->sheet_mask().hide(FR_LIV1 + i -1);
 | 
						||
      _sheet->delete_column(pos);
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
// configurazione campi
 | 
						||
 | 
						||
  TConfig cfg(CONFIG_DITTA, "ve");
 | 
						||
  const bool gesval   = cfg.get_bool("GESVAL");
 | 
						||
  const bool gescambi = cfg.get_bool("GESVALAC");
 | 
						||
 | 
						||
  if (gesval)
 | 
						||
  {
 | 
						||
    const bool enable_controeuro   =  cfg.get_bool("CONTROEURO");
 | 
						||
 | 
						||
    enable(F_CONTROEURO, enable_controeuro);
 | 
						||
    show(F_CODVAL, !gescambi);
 | 
						||
    show(F_DATACAMBIO, !gescambi);
 | 
						||
    show(F_NOMEVAL, !gescambi);
 | 
						||
    show(F_CODVAL1, gescambi);
 | 
						||
    show(F_DATACAMBIO1, gescambi);
 | 
						||
    show(F_NOMEVAL1, gescambi);
 | 
						||
    show(F_CAMBIO);
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    disable(F_CODVAL);
 | 
						||
    disable(F_DATACAMBIO);
 | 
						||
    disable(F_CONTROEURO);
 | 
						||
    disable(F_NOMEVAL);
 | 
						||
    hide(F_CODVAL1);
 | 
						||
    hide(F_DATACAMBIO1);
 | 
						||
    hide(F_NOMEVAL1);
 | 
						||
    disable(F_CAMBIO);
 | 
						||
  }
 | 
						||
 | 
						||
  const bool geslin   =  cfg.get_bool("GESLIN");
 | 
						||
 | 
						||
  enable(F_CODLIN, geslin);
 | 
						||
  enable(F_DESLIN, geslin);
 | 
						||
 | 
						||
  const bool geslis         =  cfg.get_bool("GES", "ve", 1);
 | 
						||
  const bool gesliscatven   =  cfg.get_bool("GESLISCV");
 | 
						||
 | 
						||
  if (geslis)
 | 
						||
  {
 | 
						||
    show(F_CODLIST, !gesliscatven);
 | 
						||
    show(F_CODLIST1, gesliscatven);
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    disable(F_CODLIST);
 | 
						||
    hide(F_CODLIST1);
 | 
						||
  }
 | 
						||
 | 
						||
  const bool gescontr       =  cfg.get_bool("GES", "ve", 2);
 | 
						||
  const bool gescontrcli    =  cfg.get_bool("GESCONCC");
 | 
						||
 | 
						||
  if (gescontr)
 | 
						||
  {
 | 
						||
    show(F_CODCONT1, gescontrcli);
 | 
						||
    show(F_CODCONT, !gescontrcli);
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    disable(F_CODCONT);
 | 
						||
    hide(F_CODCONT1);
 | 
						||
  }
 | 
						||
 | 
						||
  const bool gesoff        =  cfg.get_bool("GES", "ve", 3);
 | 
						||
  enable(F_CODCAMP, gesoff);
 | 
						||
 | 
						||
  const bool gessco        =  cfg.get_char("GESSCO") != 'N';
 | 
						||
  enable(F_SCONTOPERC, gessco);
 | 
						||
 | 
						||
  const bool gesage        =  cfg.get_bool("GESAGE");
 | 
						||
  enable(F_CODAG, gesage);
 | 
						||
  enable(F_DESAG, gesage);
 | 
						||
  enable(F_CODAGVIS, gesage);
 | 
						||
  enable(F_DESAGVIS, gesage);
 | 
						||
 | 
						||
  const bool has_movmag = dongle().active(MGAUT) && _doc.tipo().mov_mag();
 | 
						||
  pos = id2pos(F_CAUSMAG);
 | 
						||
  if (pos >= 0)
 | 
						||
    fld(pos).show(has_movmag);
 | 
						||
  pos = id2pos(F_DESCRMAG);
 | 
						||
  if (pos >= 0)
 | 
						||
    fld(pos).show(has_movmag);
 | 
						||
  pos = id2pos(F_CAUSMAGC);
 | 
						||
  if (pos >= 0)
 | 
						||
    fld(pos).show(has_movmag);
 | 
						||
  pos = id2pos(F_DESCRMAGC);
 | 
						||
  if (pos >= 0)
 | 
						||
    fld(pos).show(has_movmag);
 | 
						||
  pos = id2pos(F_CURGIAC);
 | 
						||
  if (pos >= 0)
 | 
						||
    fld(pos).show(has_movmag);
 | 
						||
  pos = id2pos(F_CURDISP);
 | 
						||
  if (pos >= 0)
 | 
						||
    fld(pos).show(has_movmag);
 | 
						||
}
 | 
						||
 | 
						||
TDocumento_mask::~TDocumento_mask()
 | 
						||
{
 | 
						||
  if (_condv)
 | 
						||
    delete _condv;
 | 
						||
  if (_livelli_giac)
 | 
						||
    delete _livelli_giac;
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::configura_sheet(TSheet_field& sheet)
 | 
						||
{
 | 
						||
  TBit_array to_delete(MAX_COLUMNS);
 | 
						||
  to_delete.set();
 | 
						||
  TTipo_documento& tdoc = (TTipo_documento&) _doc.tipo();
 | 
						||
  const TString_array& sheet_columns = tdoc.sheet_columns();
 | 
						||
  int ncols = sheet_columns.items();
 | 
						||
 | 
						||
  TToken_string colonne;
 | 
						||
  colonne = "0";
 | 
						||
  
 | 
						||
  for (int i = 0; i < ncols; i ++ )
 | 
						||
  {
 | 
						||
    TToken_string& sheet_col = (TToken_string&) sheet_columns[i];
 | 
						||
    const int field_id = sheet_col.get_int(0);
 | 
						||
    const int coltomove = sheet.cid2index(field_id);
 | 
						||
    to_delete.reset(coltomove);
 | 
						||
 | 
						||
    const TString80 descr(sheet_col.get(1));
 | 
						||
    if (descr.not_empty() )
 | 
						||
      sheet.set_column_header( field_id, descr);
 | 
						||
 | 
						||
    const int size = sheet_col.get_int(2) * 8; // XI_FU_MULTIPLE
 | 
						||
    if (size != 0)
 | 
						||
      sheet.set_column_width( field_id, size);
 | 
						||
     
 | 
						||
    if (field_id != FR_LORDO || tdoc.calcolo_lordo())
 | 
						||
      colonne.add(field_id);
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (tdoc.calcolo_lordo())
 | 
						||
    to_delete.reset(0L);        
 | 
						||
  else
 | 
						||
    to_delete.set(0L);
 | 
						||
  to_delete.reset(1);
 | 
						||
    
 | 
						||
 | 
						||
  if (!to_delete[sheet.cid2index(FR_CODDEP)])
 | 
						||
    sheet.enable_column(FR_CODDEP, _ges_dep && _ges_mag);
 | 
						||
  if (!to_delete[sheet.cid2index(FR_CODMAG)])
 | 
						||
    sheet.enable_column(FR_CODMAG, _ges_mag);
 | 
						||
  if (!to_delete[sheet.cid2index(FR_CODDEPC)])
 | 
						||
    sheet.enable_column(FR_CODDEPC, _ges_dep && _ges_mag);
 | 
						||
  if (!to_delete[sheet.cid2index(FR_CODMAGC)])
 | 
						||
    sheet.enable_column(FR_CODMAGC, _ges_mag);
 | 
						||
  to_delete.set(sheet.cid2index(FR_CODARTMAG));
 | 
						||
  to_delete.set(sheet.cid2index(FR_CHECKED));
 | 
						||
 | 
						||
/*
 | 
						||
  const int sconto_col = sheet.cid2index(FR_SCONTO);
 | 
						||
  if (to_delete[sconto_col] == FALSE)
 | 
						||
  {
 | 
						||
    const bool del = tdoc.sconto_riga() == "N";
 | 
						||
    to_delete.set(sconto_col, del);
 | 
						||
  }
 | 
						||
*/
 | 
						||
 | 
						||
  for ( i = MAX_COLUMNS - 1; i >= 0; i-- )
 | 
						||
    if( to_delete[i] )
 | 
						||
    {
 | 
						||
      sheet.enable_column( i + FIRST_FIELD, FALSE);
 | 
						||
      sheet.delete_column( i + FIRST_FIELD);
 | 
						||
    }
 | 
						||
 | 
						||
  if (!sheet.user_saved_columns_order())
 | 
						||
    sheet.set_columns_order(&colonne);
 | 
						||
}
 | 
						||
 | 
						||
 | 
						||
TCond_vendita& TDocumento_mask::condv() const
 | 
						||
{
 | 
						||
  if (_condv == NULL)
 | 
						||
  {
 | 
						||
    TDocumento_mask* myself = (TDocumento_mask*)this;
 | 
						||
    myself->_condv = new TCond_vendita(myself, NULL);
 | 
						||
  }
 | 
						||
  return *_condv;
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::update_progs()
 | 
						||
{
 | 
						||
  TWait_cursor hourglass;
 | 
						||
 | 
						||
  for (int f = id2pos(BASE_PIEDE + 1)-1; f >= 0; f--)
 | 
						||
  {
 | 
						||
    const TMask_field& mf = fld(f);
 | 
						||
    const TFieldref* fr = mf.field();
 | 
						||
    if (fr)
 | 
						||
      _doc.put(fr->name(), mf.get());
 | 
						||
  }
 | 
						||
    
 | 
						||
  _doc.set_riga_esenzione();
 | 
						||
    
 | 
						||
  for (int i = _last_prog; i > 0; i--)
 | 
						||
  {
 | 
						||
    const short id = BASE_PIEDE + i;
 | 
						||
    const TString& name = field(id).field()->name();
 | 
						||
    const TString& val = _doc.get(name);
 | 
						||
    set(id, val, TRUE); 
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::next_page(int p)
 | 
						||
{     
 | 
						||
  const bool was_normal_page = curr_page() < _progs_page;
 | 
						||
  TMask::next_page(p);
 | 
						||
  const bool is_calculated_page = curr_page() >= _progs_page;
 | 
						||
 | 
						||
  if (was_normal_page && is_calculated_page)
 | 
						||
    update_progs();
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::stop_run(KEY key)
 | 
						||
{                             
 | 
						||
  if (key != K_ESC && key != K_QUIT)
 | 
						||
    update_progs();
 | 
						||
  return TVariable_mask::stop_run(key);
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::on_key(KEY key)
 | 
						||
{ 
 | 
						||
  if (key == K_SHIFT + K_F12)
 | 
						||
  {
 | 
						||
    TRelation r(LF_DOC);
 | 
						||
    r.curr()=doc();
 | 
						||
    if (!doc().bloccato() && ::user_can_write(&r))
 | 
						||
    {
 | 
						||
      TMask_field& stato = field(F_STATO);
 | 
						||
      stato.enable();
 | 
						||
      enable(DLG_SAVEREC);
 | 
						||
      enable(DLG_DELREC);
 | 
						||
    }
 | 
						||
    else
 | 
						||
      warning_box("L'utente %s non puo' modificare questo documento", 
 | 
						||
                            (const char*)user());
 | 
						||
    return TRUE;
 | 
						||
  }
 | 
						||
  return TVariable_mask::on_key(key); 
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::occ2mask()
 | 
						||
{  
 | 
						||
  const TOccasionale& o = doc().occas();
 | 
						||
 | 
						||
  reset(F_COFI);
 | 
						||
  reset(F_PAIVA);
 | 
						||
  set(F_OCFPI, o.get(OCC_CFPI));   
 | 
						||
  const TString & ragsoc = o.get(OCC_RAGSOC);
 | 
						||
  set(F_RAGSOC, ragsoc);
 | 
						||
  set(F_RAGSOCSP, ragsoc);
 | 
						||
  const TString & indir = o.get(OCC_INDIR);
 | 
						||
  set(F_INDCF, indir);
 | 
						||
  set(F_INDSP, indir);
 | 
						||
  const TString & civ = o.get(OCC_CIV);
 | 
						||
  set(F_CIVCF, civ);
 | 
						||
  set(F_CIVSP, civ);
 | 
						||
  const TString & cap = o.get(OCC_CAP);
 | 
						||
  set(F_CAPCF, cap);
 | 
						||
  set(F_CAPSP, cap);
 | 
						||
  const TString & com = o.get(OCC_COM);
 | 
						||
  set(F_COMCF, com);    
 | 
						||
  set( F_COMSP, com);
 | 
						||
  const TString & stato = o.get(OCC_STATO);
 | 
						||
  set(F_STATOCF, stato);  
 | 
						||
  set( F_STATOSP, stato);
 | 
						||
  if (id2pos(F_CODINDSP) >= 0)
 | 
						||
    reset(F_CODINDSP);
 | 
						||
  // Sugli occasionali non c'<27> la localit<69>
 | 
						||
  const TString & localita = o.get(OCC_LOCALITA);
 | 
						||
  set(F_LOCALITACF, localita);
 | 
						||
  set(F_LOCALITASP, localita);
 | 
						||
  check_field(F_COMSP);
 | 
						||
  check_field(F_STATOSP);
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::cli2mask()
 | 
						||
{  
 | 
						||
 TCli_for & c = doc().clifor(); 
 | 
						||
 TOccasionale & o = doc().occas();
 | 
						||
 | 
						||
  const bool onload = !is_running();
 | 
						||
  const TString16 codval(get(F_CODVAL));
 | 
						||
  const TString16 datacambio(get(F_DATACAMBIO1));
 | 
						||
  
 | 
						||
  // Setta i campi che appartengono al file LF_CLIFO  
 | 
						||
  const bool occas = c.occasionale();
 | 
						||
 | 
						||
  show(F_OCCASEDIT, occas);
 | 
						||
  if (!occas)
 | 
						||
    reset(F_OCFPI);
 | 
						||
  show(F_OCFPI, occas);
 | 
						||
  // In forse per l'Occasionale, sicuri per il Normale
 | 
						||
  show(F_COFI, !occas);
 | 
						||
  show(F_STATOPAIVA, !occas);
 | 
						||
  show(F_PAIVA, !occas);    
 | 
						||
  set(F_RAGSOC, c.get(CLI_RAGSOC));
 | 
						||
  enable(F_RAGSOC, !occas);
 | 
						||
  
 | 
						||
  const TRectype & ven_rec = c.vendite();
 | 
						||
 | 
						||
  if(!onload)    
 | 
						||
  {                       
 | 
						||
    short pos = id2pos(F_CODVAL);                
 | 
						||
    const TString & codval = c.get(CLI_CODVAL);
 | 
						||
    
 | 
						||
    if (pos >= 0)
 | 
						||
      fld(pos).set(codval);
 | 
						||
    pos = id2pos(F_CODVAL1);              
 | 
						||
    if (pos >= 0)
 | 
						||
      fld(pos).set(codval);
 | 
						||
    pos = id2pos(F_CODLIN);              
 | 
						||
    if (pos >= 0 && fld(pos).active())
 | 
						||
      fld(pos).set(c.get(CLI_CODLIN));
 | 
						||
    set(F_CODPAG, c.get(CLI_CODPAG));
 | 
						||
    set(F_CODABIA, c.get(CLI_CODABI));
 | 
						||
    set(F_CODCABA, c.get(CLI_CODCAB));
 | 
						||
    // Setta i campi che appartengono al file LF_CFVEN
 | 
						||
    set(F_CODABIP, ven_rec.get(CFV_CODABIPR));
 | 
						||
    set(F_CODCABP, ven_rec.get(CFV_CODCABPR));
 | 
						||
    set(F_RAGGR, ven_rec.get(CFV_RAGGDOC));
 | 
						||
    set(F_RAGGREFF, ven_rec.get(CFV_RAGGEFF));
 | 
						||
    set(F_CODINDSP, ven_rec.get(CFV_CODINDSP));
 | 
						||
    set(F_CODAG, ven_rec.get(CFV_CODAG));
 | 
						||
    set(F_CODSPMEZZO, ven_rec.get(CFV_CODSPMEZZO));
 | 
						||
    set(F_CODPORTO, ven_rec.get(CFV_CODPORTO));
 | 
						||
    set(F_CODNOTESP1, ven_rec.get(CFV_CODNOTESP1));
 | 
						||
    set(F_CODNOTESP2, ven_rec.get(CFV_CODNOTESP2));
 | 
						||
    set(F_CODNOTE, ven_rec.get(CFV_CODNOTE));
 | 
						||
    set(F_CODVETT1, ven_rec.get(CFV_CODVETT1));
 | 
						||
    set(F_CODVETT2, ven_rec.get(CFV_CODVETT2));
 | 
						||
    set(F_CODVETT3, ven_rec.get(CFV_CODVETT3));
 | 
						||
    set(F_SPESEINC, ven_rec.get(CFV_PERCSPINC));  
 | 
						||
    set(F_ADDBOLLI, ven_rec.get(CFV_ADDBOLLI));
 | 
						||
    set(F_CATVEN, ven_rec.get(CFV_CATVEN));
 | 
						||
    pos = id2pos(F_CODLIST);              
 | 
						||
    const TString & codlist = ven_rec.get(CFV_CODLIST);
 | 
						||
    if (pos >= 0 && fld(pos).active())
 | 
						||
    {   
 | 
						||
      TEdit_field & f = (TEdit_field&) fld(pos);
 | 
						||
      
 | 
						||
      f.set(codlist);
 | 
						||
      f.check();
 | 
						||
      f.on_hit();
 | 
						||
    }
 | 
						||
    pos = id2pos(F_CODLIST1);              
 | 
						||
    if (pos >= 0 && fld(pos).active())
 | 
						||
    {   
 | 
						||
      TEdit_field & f = (TEdit_field&) fld(pos);
 | 
						||
      
 | 
						||
      f.set(codlist);
 | 
						||
      f.check();
 | 
						||
      f.on_hit();
 | 
						||
    }
 | 
						||
    pos = id2pos(F_CODAG);              
 | 
						||
    if (pos >= 0 && fld(pos).active())
 | 
						||
      fld(pos).set(ven_rec.get(CFV_CODAG));
 | 
						||
    set(F_CODZON, ven_rec.get(CFV_CODZONA));
 | 
						||
    set(F_RAGGR, ven_rec.get(CFV_RAGGDOC));
 | 
						||
    sconto_testa2mask();
 | 
						||
    spese2mask();
 | 
						||
  }
 | 
						||
  enable( F_CODINDSP , !occas);      
 | 
						||
  if (occas) 
 | 
						||
    occ2mask();
 | 
						||
  else           
 | 
						||
  {        
 | 
						||
    set(F_COFI, c.get(CLI_COFI));
 | 
						||
    set(F_INDCF, c.get(CLI_INDCF));
 | 
						||
    set(F_CIVCF, c.get(CLI_CIVCF));
 | 
						||
    set(F_STATOPAIVA, c.get(CLI_STATOPAIV));
 | 
						||
    set(F_PAIVA, c.get(CLI_PAIV));
 | 
						||
    set(F_LOCALITACF, c.get(CLI_LOCCF));
 | 
						||
    set(F_CAPCF, c.get(CLI_CAPCF));
 | 
						||
    set(F_COMCF, c.get(CLI_COMCF));
 | 
						||
    set(F_STATOCF, c.get(CLI_STATOCF));
 | 
						||
    check_field( F_CODINDSP );
 | 
						||
  }
 | 
						||
  const TString16 newcodval(get(F_CODVAL));
 | 
						||
  const TString16 newdatacambio(get(F_DATACAMBIO1));
 | 
						||
 | 
						||
  short pos = id2pos(F_CAMBIO);                           
 | 
						||
  if ((pos >= 0) && newcodval.empty())
 | 
						||
    fld(pos).reset();  
 | 
						||
  pos = id2pos(F_CODVAL);                           
 | 
						||
  if (pos >= 0 && fld(pos).active())
 | 
						||
    fld(pos).check(STARTING_CHECK);
 | 
						||
  pos = id2pos(F_CODVAL1);                           
 | 
						||
  if (pos >= 0 && fld(pos).active())
 | 
						||
    fld(pos).check(STARTING_CHECK);
 | 
						||
  pos = id2pos(F_DATACAMBIO1);                           
 | 
						||
  if (pos >= 0 && fld(pos).active() &&
 | 
						||
     (codval != newcodval || datacambio != newdatacambio))
 | 
						||
    fld(pos).check();
 | 
						||
  check_field(F_COMCF);
 | 
						||
  check_field(F_STATOCF);
 | 
						||
  check_field( F_CODPAG );
 | 
						||
  pos = id2pos(F_CODLIN);                           
 | 
						||
  if (pos >= 0 && fld(pos).active())
 | 
						||
    fld(pos).check();
 | 
						||
  check_field( F_CODCABA );
 | 
						||
  pos = id2pos(F_CODLIST);                           
 | 
						||
  if (pos >= 0 && fld(pos).active())
 | 
						||
    fld(pos).check();
 | 
						||
  pos = id2pos(F_CODLIST1);                           
 | 
						||
  if (pos >= 0 && fld(pos).active())
 | 
						||
    fld(pos).check();
 | 
						||
  check_field( F_CODCABP );
 | 
						||
  pos = id2pos(F_CODAG);                           
 | 
						||
  if (pos >= 0 && fld(pos).active())
 | 
						||
    fld(pos).check();
 | 
						||
  check_field( F_CODSPMEZZO );
 | 
						||
  check_field( F_CODPORTO );
 | 
						||
  check_field( F_CODNOTESP1 );
 | 
						||
  check_field( F_CODNOTESP2 );
 | 
						||
  check_field( F_CODNOTE );
 | 
						||
  check_field( F_CODVETT1 );
 | 
						||
  check_field( F_CODVETT2 );
 | 
						||
  check_field( F_CODVETT3 );    
 | 
						||
  check_field( F_CATVEN );    
 | 
						||
  check_field( F_CODZON );
 | 
						||
  
 | 
						||
  const bool contr_enabled = ven_rec.get_bool(CFV_GESTCONTR);
 | 
						||
  bool gescontr = FALSE;
 | 
						||
  if (contr_enabled)
 | 
						||
  {
 | 
						||
    TConfig ditta(CONFIG_DITTA, "ve");
 | 
						||
    gescontr = ditta.get_bool("GES", "ve", 2);          
 | 
						||
  }
 | 
						||
  
 | 
						||
  enable(F_CODCONT1, contr_enabled && gescontr);
 | 
						||
  enable(F_CODCONT, contr_enabled && gescontr);
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::sconto_testa2mask()
 | 
						||
{
 | 
						||
  TCli_for & c = doc().clifor(); 
 | 
						||
  TConfig ditta(CONFIG_DITTA, "ve");
 | 
						||
  const char tipogestione = ditta.get("GESSCO", "ve")[ 0 ];
 | 
						||
  switch( tipogestione )
 | 
						||
  {
 | 
						||
    case 'N':  // Sconti non gestiti: pussa via!
 | 
						||
      break;
 | 
						||
    case 'P':  // Percentuale su anagrafica cliente
 | 
						||
      set( F_SCONTOPERC, c.vendite().get(CFV_SCONTO));
 | 
						||
      break;
 | 
						||
    case 'T':  // Gestione tabella sconti
 | 
						||
      {
 | 
						||
        const TString16 codsconto(c.vendite().get(CFV_CODSCC));
 | 
						||
        
 | 
						||
        if (codsconto.not_empty())
 | 
						||
        {
 | 
						||
          TTable sconti("%SCC");
 | 
						||
          sconti.setkey(1);
 | 
						||
          sconti.zero();
 | 
						||
          sconti.put("CODTAB", codsconto);
 | 
						||
          if (sconti.read( ) == NOERR)
 | 
						||
            set(F_SCONTOPERC, sconti.get("S1"));
 | 
						||
        }
 | 
						||
      }
 | 
						||
      break;
 | 
						||
    case 'A':  // Gestione archivio sconti
 | 
						||
      {
 | 
						||
        TString16 cod;               
 | 
						||
        const TRectype & ven_rec = c.vendite();
 | 
						||
        TLocalisamfile sconti(LF_SCONTI );
 | 
						||
                                     
 | 
						||
        sconti.setkey(1);
 | 
						||
        sconti.zero();
 | 
						||
        sconti.put("TIPO", "I");
 | 
						||
        if(ditta.get_bool("SCOKEY", "ve", 1))
 | 
						||
          sconti.put("CODCAT", ven_rec.get(CFV_CATVEN));
 | 
						||
        if(ditta.get_bool("SCOKEY", "ve", 2))
 | 
						||
          cod.format("%-2s", (const char *)ven_rec.get(CFV_CODSCC));
 | 
						||
        else
 | 
						||
          cod = "  ";
 | 
						||
        if( ditta.get_bool("SCOKEY", "ve", 3))
 | 
						||
        {
 | 
						||
          TString8 cz; cz.format("%-2s", (const char*)ven_rec.get(CFV_CODZONA));
 | 
						||
          cod << cz;
 | 
						||
        }
 | 
						||
        else
 | 
						||
          cod << "  ";
 | 
						||
        if( ditta.get_bool("SCOKEY", "ve", 4))
 | 
						||
          cod << c.get(CLI_CODPAG);
 | 
						||
        sconti.put("CODART", cod);
 | 
						||
        if(sconti.read() == NOERR)
 | 
						||
          set(F_SCONTOPERC, sconti.get( "SCONTO"));
 | 
						||
      }
 | 
						||
      break;    
 | 
						||
    default:
 | 
						||
      break;  
 | 
						||
  }  
 | 
						||
  return;
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::spese2mask()
 | 
						||
{
 | 
						||
  TSheet_field & sh = (TSheet_field &) field(F_SHEET);
 | 
						||
  TCli_for & c = doc().clifor(); 
 | 
						||
  
 | 
						||
  TString16 name("CODSP0");
 | 
						||
  TString_array spese;        
 | 
						||
  TRectype & ven_rec = c.vendite();
 | 
						||
  for (int i = 1; i <= 4; i++)
 | 
						||
  {                     
 | 
						||
    name.rtrim(1); name << i;
 | 
						||
    const TString16 s(ven_rec.get(name));
 | 
						||
    
 | 
						||
    if (s.not_empty()) 
 | 
						||
      spese.add(s);
 | 
						||
  }               
 | 
						||
//  autosave(*_rel);            
 | 
						||
 | 
						||
  doc().put("SPESEUPD", FALSE);
 | 
						||
  doc().put(DOC_CODVAL, get(F_CODVAL));
 | 
						||
  doc().put(DOC_CAMBIO, get(F_CAMBIO));
 | 
						||
  doc().put(DOC_CONTROEURO, get(F_CONTROEURO));
 | 
						||
  
 | 
						||
  doc().update_spese_aut(spese, FALSE, &sh);
 | 
						||
  sh.force_update();
 | 
						||
} 
 | 
						||
 | 
						||
void TDocumento_mask::reset_masks(const TString& tipo_doc)
 | 
						||
{
 | 
						||
  static TString16 last_tipo_doc;
 | 
						||
 | 
						||
  if (tipo_doc != last_tipo_doc)
 | 
						||
  {
 | 
						||
    FOR_EACH_ASSOC_OBJECT(_maskriga, h, k, o)
 | 
						||
    {
 | 
						||
      TMask* m = (TMask*)o;
 | 
						||
      m->enable_default(); 
 | 
						||
      if (!_sheet->exist_column(FR_PREZZO))
 | 
						||
        m->hide(FR_PREZZO);
 | 
						||
    }
 | 
						||
    last_tipo_doc = tipo_doc;
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::doc2mask(bool reload_clifo)
 | 
						||
{ 
 | 
						||
  for (int p = id2pos(BASE_PIEDE + 1)-1; p >= 0; p--)
 | 
						||
  {
 | 
						||
    TMask_field& f = fld(p);
 | 
						||
    const TFieldref* fr = f.field();
 | 
						||
    if (fr)
 | 
						||
      f.set(fr->read(doc()));
 | 
						||
  }
 | 
						||
 | 
						||
  if (reload_clifo)
 | 
						||
    cli2mask();      
 | 
						||
 | 
						||
  TSheet_field& s = sfield(F_SHEET);
 | 
						||
  s.destroy( );
 | 
						||
  
 | 
						||
  const int righe = doc().physical_rows();
 | 
						||
  for (int i = 0; i < righe; i++)
 | 
						||
  {
 | 
						||
    s.insert(-1, FALSE);
 | 
						||
    TToken_string& r = s.row(i);
 | 
						||
    doc()[i+1].autoload(s);
 | 
						||
    s.check_row(i, 0x2);
 | 
						||
  }
 | 
						||
 | 
						||
  reset_masks(get(F_TIPODOC));
 | 
						||
  
 | 
						||
  s.force_update();
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::mask2doc()
 | 
						||
{
 | 
						||
  for (int p = fields()-1; p >= 0; p--)
 | 
						||
  {
 | 
						||
    TMask_field& f = fld(p);
 | 
						||
    const TFieldref* fr = f.field();
 | 
						||
    if (fr)
 | 
						||
      fr->write(f.get(), doc());
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
TVariable_mask* TDocumento_mask::riga_mask(int numriga)
 | 
						||
{ 
 | 
						||
  const TRiga_documento& riga = doc()[numriga + 1];
 | 
						||
  const TTipo_riga_documento& tiporiga = riga.tipo();
 | 
						||
  const char* name = tiporiga.mask_name();
 | 
						||
 | 
						||
  TVariable_mask* m = (TVariable_mask*)_maskriga.objptr(name);
 | 
						||
  if (m == NULL)
 | 
						||
  {
 | 
						||
    m = new TVariable_mask(name); 
 | 
						||
 | 
						||
    _maskriga.add(name, m);
 | 
						||
  
 | 
						||
    TFilename proname(tiporiga.profile_name());
 | 
						||
    proname.ext("ini");  
 | 
						||
     
 | 
						||
    TConfig pro( proname, "HANDLERS" );
 | 
						||
    int numhandler = pro.get_int( "NHANDLER", "HANDLERS" );
 | 
						||
  
 | 
						||
    for( int i = 1; i <= numhandler; i ++ )
 | 
						||
    {
 | 
						||
      TString8 chiave;  chiave.format("%d", i );
 | 
						||
      TToken_string riga = pro.get( chiave, "HANDLERS" );
 | 
						||
      row_set_handler( *m, riga.get_int( 0 ), riga.get_int( 1 ) );
 | 
						||
    }
 | 
						||
                  
 | 
						||
    m->set_handler( FR_QTA, qta_handler );
 | 
						||
    m->set_handler( FR_UMQTA, um_handler );
 | 
						||
    
 | 
						||
    const int pos = m->id2pos(FR_CODART);
 | 
						||
    if (pos >= 0)
 | 
						||
    {
 | 
						||
      const TMask_field & f = m->field(FR_CODART);
 | 
						||
      if (f.is_edit())
 | 
						||
      {
 | 
						||
        TBrowse * browse = ((TEdit_field &) f).browse();
 | 
						||
        const char tipo_r = tiporiga.tipo();
 | 
						||
        
 | 
						||
        if (browse )
 | 
						||
        {                 
 | 
						||
          const TCursor * cur = browse->cursor();
 | 
						||
          if (cur)
 | 
						||
          {
 | 
						||
            const int num = cur->file().num();
 | 
						||
            if (num == LF_ANAMAG || num == LF_CODCORR)
 | 
						||
            {
 | 
						||
              m->set_handler( FR_CODMAG, codmag_handler ); 
 | 
						||
              m->set_handler( FR_CODMAGC, codmag_coll_handler ); 
 | 
						||
              m->set_handler( FR_CODART, codart_handler );
 | 
						||
              m->set_handler( FR_LIV1, liv_handler );
 | 
						||
              m->set_handler( FR_LIV2, liv_handler );
 | 
						||
              m->set_handler( FR_LIV3, liv_handler );
 | 
						||
              m->set_handler( FR_LIV4, liv_handler );
 | 
						||
              m->set_handler( FR_UMQTA, umart_handler );
 | 
						||
              m->set_handler( FR_CODARTMAG, codartmag_handler );
 | 
						||
              m->set_handler( FR_DESCR, descr_handler ); 
 | 
						||
              m->set_handler( FR_QTA, qtaart_handler ); 
 | 
						||
              if (livelli().autoinsert(1))
 | 
						||
                m->field(FR_LIV1).check_type(CHECK_NONE);
 | 
						||
              if (livelli().autoinsert(2))
 | 
						||
                m->field(FR_LIV2).check_type(CHECK_NONE);
 | 
						||
              if (livelli().autoinsert(3))
 | 
						||
                m->field(FR_LIV3).check_type(CHECK_NONE);
 | 
						||
              if (livelli().autoinsert(4))
 | 
						||
                m->field(FR_LIV4).check_type(CHECK_NONE);
 | 
						||
             }
 | 
						||
            else
 | 
						||
              if (tipo_r == RIGA_SPESEDOC || tipo_r == RIGA_PRESTAZIONI)
 | 
						||
                m->set_handler( FR_CODART, sppr_handler ); 
 | 
						||
          }
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
    m->set_handler(FR_QTAEVASA, qta_evasa_handler);
 | 
						||
    m->set_handler(FR_CAUS, causmag_handler);
 | 
						||
    
 | 
						||
    if (m->id2pos(FR_CODIVA) >= 0)
 | 
						||
    {
 | 
						||
      m->set_handler(FR_CODIVA, iva_handler);
 | 
						||
      const TString& tipiva = doc().tipo().tipi_iva_validi();
 | 
						||
      if (tipiva.not_empty())
 | 
						||
      {
 | 
						||
        TBrowse& browse = *(m->efield(FR_CODIVA)).browse();
 | 
						||
        TString filter = browse.get_filter();
 | 
						||
 | 
						||
        bool close_filter = FALSE;
 | 
						||
        if (filter.not_empty()) 
 | 
						||
        { 
 | 
						||
          filter.insert("("); 
 | 
						||
          filter << ")&&("; 
 | 
						||
          close_filter = TRUE;
 | 
						||
        }  
 | 
						||
        bool firstor = TRUE;
 | 
						||
        for (int i = tipiva.len()-1; i >= 0; i--) if (tipiva[i] != ' ')
 | 
						||
        {
 | 
						||
          if (firstor) 
 | 
						||
            firstor = FALSE; 
 | 
						||
          else 
 | 
						||
            filter << "||"; 
 | 
						||
          filter << "(S1==\"";
 | 
						||
          switch(i)
 | 
						||
          {
 | 
						||
          case  1: filter << "VE"; break;
 | 
						||
          case  2: filter << "ES"; break;
 | 
						||
          case  3: filter << "NI"; break;
 | 
						||
          case  4: filter << "NS"; break;
 | 
						||
          default: break;
 | 
						||
          }
 | 
						||
          filter << "\")";  
 | 
						||
        }
 | 
						||
        if (close_filter) filter << ')';
 | 
						||
        browse.set_filter(filter);
 | 
						||
      }
 | 
						||
      m->set_handler(DLG_USER, link_handler);
 | 
						||
    }  
 | 
						||
  }    
 | 
						||
 | 
						||
  m->set_sheet((TSheet_field *)&(field(F_SHEET))); 
 | 
						||
 | 
						||
  int pos = m->id2pos(FR_PREZZO);
 | 
						||
  if (pos >= 0)
 | 
						||
  {
 | 
						||
    TEditable_field & f =((TEditable_field &) m->fld(pos));
 | 
						||
    f.reset_driver(F_CODVAL);
 | 
						||
    f.add_driver(-F_CODVAL);
 | 
						||
  }
 | 
						||
      
 | 
						||
  pos = m->id2pos(FR_IMPFISSO);
 | 
						||
  if (pos >= 0)
 | 
						||
  {
 | 
						||
    TEditable_field & f =((TEditable_field &) m->fld(pos));
 | 
						||
    f.reset_driver();
 | 
						||
    f.add_driver(-F_CODVAL);
 | 
						||
  }
 | 
						||
  
 | 
						||
  return m;
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::update_giacenza()
 | 
						||
{                                  
 | 
						||
  if (id2pos(F_CURGIAC)<0)
 | 
						||
    return;
 | 
						||
 | 
						||
  TSheet_field& sf = sfield(F_SHEET);
 | 
						||
  TToken_string& row = sf.row(sf.selected());       
 | 
						||
  const TString codart = row.get(sf.cid2index(FR_CODARTMAG));
 | 
						||
  
 | 
						||
  real giac, disp;
 | 
						||
  if (codart.not_empty())
 | 
						||
  {
 | 
						||
    const TString& annoes = get(F_ANNO);
 | 
						||
    TString16 codmag = row.get(sf.cid2index(FR_CODMAG));
 | 
						||
    const TString16 coddep = row.get(sf.cid2index(FR_CODDEP));    
 | 
						||
    if (!coddep.blank())
 | 
						||
      codmag << coddep;
 | 
						||
    
 | 
						||
    TString16 livello;
 | 
						||
    for (int i = 0; i < 4; i++)
 | 
						||
    {
 | 
						||
      const char* liv = row.get(sf.cid2index(FR_LIV1+i));
 | 
						||
      if (*liv > ' ')
 | 
						||
        livello << liv;
 | 
						||
      else
 | 
						||
        break;  
 | 
						||
    }
 | 
						||
    
 | 
						||
    TArticolo_giacenza art(codart);
 | 
						||
    giac = art.disponibilita(annoes, codmag, livello, TRUE);
 | 
						||
    disp = art.disponibilita(annoes, codmag, livello, FALSE);
 | 
						||
        
 | 
						||
    TLocalisamfile umart(LF_UMART);
 | 
						||
    umart.setkey(2);
 | 
						||
    umart.put(UMART_CODART, codart);
 | 
						||
    umart.put(UMART_UM, row.get(sf.cid2index(FR_UMQTA)));
 | 
						||
    if (umart.read() == NOERR)
 | 
						||
    {
 | 
						||
      real curr_fc = umart.get_real(UMART_FC);
 | 
						||
      if (curr_fc > ZERO)
 | 
						||
      {
 | 
						||
        giac /= curr_fc;
 | 
						||
        disp /= curr_fc;
 | 
						||
      }  
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  set(F_CURGIAC, giac.string());
 | 
						||
  set(F_CURDISP, disp.string());                            
 | 
						||
  
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// Handlers and notifiers
 | 
						||
///////////////////////////////////////////////////////////        
 | 
						||
                                 
 | 
						||
bool TDocumento_mask::ss_handler(TMask_field& f, KEY key)
 | 
						||
{          
 | 
						||
  bool ok = TRUE;
 | 
						||
  if (key == K_ENTER && f.mask().insert_mode())
 | 
						||
  {
 | 
						||
    TSheet_field& ss = (TSheet_field&)f;
 | 
						||
    if (!app().is_transaction() && ss.items() == 0)
 | 
						||
      ok = yesno_box("Il documento e' privo di righe:\n"
 | 
						||
                     "Si desidera continuare ugualmente?");
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::ss_notify( TSheet_field& ss, int r, KEY key )
 | 
						||
{
 | 
						||
  TDocumento_mask& m = (TDocumento_mask&)ss.mask();
 | 
						||
  TDocumento& doc = m.doc();
 | 
						||
 | 
						||
  if ( key == K_ENTER ) // modifica
 | 
						||
  {
 | 
						||
    TRiga_documento & riga = doc[r + 1];
 | 
						||
    riga.autosave(ss);
 | 
						||
  }
 | 
						||
  else
 | 
						||
    if ( key == K_DEL ) // Cancellazione
 | 
						||
    {
 | 
						||
      doc.destroy_row(r + 1, TRUE);
 | 
						||
      if (r < doc.rows())
 | 
						||
      {
 | 
						||
        TRiga_documento & riga = doc[r + 1];
 | 
						||
        if (riga.is_omaggio() && riga.is_generata())
 | 
						||
        {
 | 
						||
          ss.destroy(r + 1);
 | 
						||
          doc.destroy_row(r + 1, TRUE);
 | 
						||
        }
 | 
						||
      }
 | 
						||
    }
 | 
						||
    else
 | 
						||
      if (key == K_INS) // Inserimento
 | 
						||
      {
 | 
						||
        if (r < doc.rows())
 | 
						||
        {
 | 
						||
          TRiga_documento & riga = doc[r + 1];
 | 
						||
          if (riga.is_omaggio() && riga.is_generata())
 | 
						||
            return FALSE;
 | 
						||
        }
 | 
						||
        doc.insert_row(r + 1, m.get( F_LBTIPORIGA ));
 | 
						||
      }
 | 
						||
      else
 | 
						||
        if (key == K_CTRL + K_INS)
 | 
						||
        {
 | 
						||
          TRiga_documento & riga = doc[r + 1];
 | 
						||
          TRectype & ven_rec = doc.clifor().vendite();
 | 
						||
          TString16 s(ven_rec.get(CFV_CODMAG));
 | 
						||
          if (s.not_empty())
 | 
						||
          {
 | 
						||
            s.left_just(3);
 | 
						||
            s << ven_rec.get(CFV_CODDEP);
 | 
						||
          }
 | 
						||
          else 
 | 
						||
          {
 | 
						||
            s = m.get(F_CAUSMAG);
 | 
						||
            if (!s.blank())
 | 
						||
            {
 | 
						||
              const TRectype & c=cache().get("%CAU", s);
 | 
						||
              if (!c.empty() && !c.get("S10").blank())
 | 
						||
                s = c.get("S10");
 | 
						||
              else
 | 
						||
              {
 | 
						||
                s = m._std_mag;
 | 
						||
                s.left_just(3);
 | 
						||
                s << m._std_dep;
 | 
						||
              }
 | 
						||
            }
 | 
						||
          }
 | 
						||
          riga.put("CODMAG", s);
 | 
						||
          riga.autoload(ss);
 | 
						||
          ss.check_row(r);
 | 
						||
          // ss.select(r, 1);  // Ma serve a qualcosa?  
 | 
						||
        }
 | 
						||
        else
 | 
						||
          if ( key == K_TAB ) // ingresso nella riga
 | 
						||
          {
 | 
						||
            TMask & sm = ss.sheet_mask();
 | 
						||
            set_curr_um(sm);
 | 
						||
            m.update_giacenza();
 | 
						||
            const bool on = doc[r + 1].get(RDOC_DACODNUM).not_empty();
 | 
						||
            sm.enable(DLG_USER, on);
 | 
						||
          }
 | 
						||
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
// Funzione che dato il profilo di riga ottiene la maschera
 | 
						||
// Serve per ottenere una maschera diversa per ogni riga
 | 
						||
TMask* TDocumento_mask::ss_getmask(int numriga, TMask& fullmask)
 | 
						||
{
 | 
						||
  TSheet_field* sf = fullmask.get_sheet();
 | 
						||
  TDocumento_mask& m = (TDocumento_mask&)sf->mask();
 | 
						||
  const TDocumento& doc = m.doc();
 | 
						||
 | 
						||
  if (numriga < doc.physical_rows())
 | 
						||
    return m.riga_mask(numriga);
 | 
						||
  else
 | 
						||
    return &fullmask;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::occas_code_handler(TMask_field& f, KEY key)
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    const char* code = f.get();
 | 
						||
    if (*code)
 | 
						||
    {
 | 
						||
      TRelation occas(LF_OCCAS);
 | 
						||
      occas.lfile().put("CFPI", code);
 | 
						||
      if (occas.read(_isequal) == NOERR)
 | 
						||
      {
 | 
						||
        TMask& m = f.mask();
 | 
						||
        m.autoload(occas);
 | 
						||
        m.send_key(K_TAB, O_COMUNE);         // Forza decodifica comuni
 | 
						||
        m.send_key(K_TAB, O_COMUNENAS);
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::occas_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  TDocumento_mask & m = (TDocumento_mask &)f.mask();
 | 
						||
  if ( key == K_SPACE && m.is_running( ) )
 | 
						||
  {
 | 
						||
    TDocumento& doc = m.doc();
 | 
						||
    TOccasionale& occ = doc.occas();
 | 
						||
 | 
						||
    TMask occas_mask("ve0100o");
 | 
						||
    occas_mask.set_handler( O_CODICE, occas_code_handler );
 | 
						||
 | 
						||
    for (int i = occas_mask.fields() - 1; i >= 0; i--)
 | 
						||
    {
 | 
						||
      TMask_field & f = occas_mask.fld(i);
 | 
						||
      const TFieldref * c = f.field();
 | 
						||
      if (c)
 | 
						||
        f.set(c->read(occ));
 | 
						||
    }
 | 
						||
    if (occas_mask.run() != K_ESC)
 | 
						||
    {
 | 
						||
      const TString ocfpi(occas_mask.get(O_CODICE));
 | 
						||
      doc.put("OCFPI", ocfpi);
 | 
						||
      m.set(F_OCFPI, ocfpi);
 | 
						||
  
 | 
						||
      for (int i = occas_mask.fields() - 1; i >= 0; i--)
 | 
						||
      {
 | 
						||
        const TMask_field& f = occas_mask.fld(i);
 | 
						||
        const TFieldref* c = f.field();
 | 
						||
        if (c)
 | 
						||
        {
 | 
						||
          const char* val = f.get();
 | 
						||
          c->write(val, occ);
 | 
						||
        }  
 | 
						||
      }
 | 
						||
      m.occ2mask();
 | 
						||
    }
 | 
						||
    f.set_focus( );
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::clifo_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key != K_ENTER && f.to_check(key, TRUE))
 | 
						||
  {
 | 
						||
    TDocumento_mask & m = (TDocumento_mask &) f.mask();
 | 
						||
    TDocumento & d = m.doc();
 | 
						||
    const TString & val = f.get();
 | 
						||
 | 
						||
    TTipo_documento& tdoc = (TTipo_documento&) d.tipo();
 | 
						||
    d.put("TIPOCF", tdoc.tipocf());
 | 
						||
    d.put("CODCF", atol(val));
 | 
						||
 | 
						||
    TCli_for & cli_for = d.clifor();
 | 
						||
    cli_for.put(CLI_CODCF, ""); // force reload
 | 
						||
 | 
						||
    if ( cli_for.get_bool("SOSPESO") )
 | 
						||
      return f.error_box( "Il codice '%ld' e' sospeso e non puo' essere utilizzato", atol(val) );
 | 
						||
    m.cli2mask();
 | 
						||
    if (cli_for.occasionale())
 | 
						||
    {
 | 
						||
      TOccasionale & occas = d.occas();
 | 
						||
      if(m.id2pos(F_OCCASEDIT) > 0 && f.to_check(key) && *(occas.codice()) == '\0')
 | 
						||
        m.send_key( K_SPACE, F_OCCASEDIT );   // Lancia maschera occasionali
 | 
						||
    }
 | 
						||
    else
 | 
						||
      d.zero("OCFPI");
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::highlight(COLOR high_back_color, COLOR high_color)
 | 
						||
{       
 | 
						||
  TSheet_field & sf = sfield(F_SHEET);
 | 
						||
  const int items = sf.items();
 | 
						||
  
 | 
						||
  for (int i = 0 ; i < items; i++)
 | 
						||
  {
 | 
						||
    const bool on = doc()[i + 1].linked();                                     
 | 
						||
  
 | 
						||
    COLOR back = on ? high_back_color : NORMAL_BACK_COLOR;
 | 
						||
    COLOR fore = on ? high_color : NORMAL_COLOR;
 | 
						||
  
 | 
						||
    sf.set_back_and_fore_color(back, fore, i);
 | 
						||
    sf.force_update(i);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TLista_elaborazioni
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
void TLista_elaborazioni::read()
 | 
						||
{                        
 | 
						||
  if (_elab == NULL)
 | 
						||
  { 
 | 
						||
    _elab = new TAssoc_array();
 | 
						||
    
 | 
						||
    TTable eld("%ELD");
 | 
						||
  
 | 
						||
    for (int err = eld.first(); err == NOERR; err = eld.next()) 
 | 
						||
    { 
 | 
						||
      TElaborazione * el = NULL;  
 | 
						||
      switch (eld.curr().get_int("I0"))
 | 
						||
      {
 | 
						||
        case _esterna :
 | 
						||
          el = new TElaborazione_esterna(eld.curr());
 | 
						||
          break;
 | 
						||
        case _consegna_ordini:
 | 
						||
          el = new TConsegna_ordini(eld.curr());
 | 
						||
          break;  
 | 
						||
        case _fatturazione_bolle :
 | 
						||
          el = new TFatturazione_bolle(eld.curr());
 | 
						||
          break;
 | 
						||
        case _contabilizzazione :
 | 
						||
          el = new TContabilizzazione(eld.curr());
 | 
						||
          break;
 | 
						||
        case _copia_documento :
 | 
						||
          el = new TCopia_documento(eld.curr());
 | 
						||
          break;
 | 
						||
        case _generazione_effetti :
 | 
						||
          el = new TGenerazione_effetti(eld.curr());
 | 
						||
          break;
 | 
						||
        default :
 | 
						||
          break;         
 | 
						||
      }
 | 
						||
      _elab->add(el->codice(), el);  
 | 
						||
    }
 | 
						||
  }
 | 
						||
}  
 | 
						||
 | 
						||
int TLista_elaborazioni::select(TString_array & result, const char * tipo_iniziale, const char * stato_iniziale, const char * tipo_finale, const char * stato_finale)
 | 
						||
{ 
 | 
						||
  read();                     
 | 
						||
  _elab->restart();
 | 
						||
  result.destroy();
 | 
						||
  for (TElaborazione * el = (TElaborazione *)_elab->get(); el ; el = (TElaborazione *) _elab->get())
 | 
						||
  {             
 | 
						||
    bool ok = FALSE;
 | 
						||
    TString ti;
 | 
						||
    if ((tipo_iniziale && *tipo_iniziale) && (stato_iniziale && *stato_iniziale))
 | 
						||
      for (int i = 0; !ok && i < TElaborazione::_max_tipi_doc_elab; i++)          
 | 
						||
      {
 | 
						||
        ti = el->tipo_iniziale(i);
 | 
						||
        const char si = el->stato_iniziale(i);
 | 
						||
        ok |= ti == tipo_iniziale &&
 | 
						||
              si == *stato_iniziale;
 | 
						||
      }
 | 
						||
    else 
 | 
						||
      ok = TRUE;      
 | 
						||
    if ((tipo_finale && *tipo_finale) && (stato_finale && *stato_finale))                                                 
 | 
						||
      ok &= el->tipo_finale() == tipo_finale &&
 | 
						||
            el->stato_finale() == stato_finale;
 | 
						||
    if (ok)
 | 
						||
      result.add(el->codice());
 | 
						||
  }
 | 
						||
  return result.items();
 | 
						||
} 
 | 
						||
  
 | 
						||
TElaborazione & TLista_elaborazioni::operator [](const char * key) const
 | 
						||
{
 | 
						||
  ((TLista_elaborazioni *)this)->read();
 | 
						||
  return (TElaborazione &) (*_elab)[key];
 | 
						||
}
 | 
						||
 | 
						||
void TLista_elaborazioni::update()
 | 
						||
{
 | 
						||
  delete _elab; _elab = NULL;
 | 
						||
  read();
 | 
						||
}  
 | 
						||
 | 
						||
TLista_elaborazioni::~TLista_elaborazioni()
 | 
						||
{              
 | 
						||
  if (_elab)
 | 
						||
    delete _elab;
 | 
						||
}  
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TDocument_tree
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TDocument_tree : public TBidirectional_tree
 | 
						||
{
 | 
						||
  TRelation* _relation;
 | 
						||
  TCursor* _cursor;
 | 
						||
  TToken_string _curnode;
 | 
						||
  
 | 
						||
protected:         
 | 
						||
  virtual void node2id(const TObject* node, TString& id) const;
 | 
						||
  bool on_head() const;
 | 
						||
  bool on_row() const;
 | 
						||
  
 | 
						||
  void format_field(const TRectype& rec, const TString& field, TString& str) const;
 | 
						||
  void append_custom_fields(const TTipo_documento& tipo, const TRectype& rec, TString& str) const;
 | 
						||
 | 
						||
public:  
 | 
						||
  virtual bool goto_root();
 | 
						||
  virtual bool goto_firstson();
 | 
						||
  virtual bool goto_rbrother(); 
 | 
						||
  virtual bool goto_node(const TString &id);
 | 
						||
  virtual bool has_son() const;
 | 
						||
  virtual bool has_rbrother() const;
 | 
						||
  virtual bool has_father() const;
 | 
						||
  virtual bool has_lbrother() const;
 | 
						||
  virtual bool goto_father();
 | 
						||
  virtual bool goto_lbrother();
 | 
						||
  virtual TObject* curr_node() const { return &(TToken_string&)_curnode; }
 | 
						||
  virtual bool get_description(TString& str) const;
 | 
						||
  virtual TImage* image(bool selected) const;
 | 
						||
  
 | 
						||
  const TRectype& testata() const;
 | 
						||
  const TRectype& riga() const;
 | 
						||
  const TRectype& record() const;
 | 
						||
 | 
						||
  void set_cursor(char tipocf, long codcf, int anno, const char* filter, FILTERFUNCTION ff = NULL);
 | 
						||
  TCursor* get_cursor() { return _cursor; }
 | 
						||
 | 
						||
  TDocument_tree();  
 | 
						||
  ~TDocument_tree();  
 | 
						||
};
 | 
						||
 | 
						||
const TRectype& TDocument_tree::testata() const
 | 
						||
{                                             
 | 
						||
  TDocument_tree& me = (TDocument_tree&)*this;
 | 
						||
  const TRecnotype pos = me._curnode.get_long(0);
 | 
						||
  if (_cursor->pos() != pos || _relation->curr(LF_RIGHEDOC).empty())
 | 
						||
    *me._cursor = pos;
 | 
						||
  return _relation->curr();
 | 
						||
}
 | 
						||
 | 
						||
const TRectype& TDocument_tree::riga() const
 | 
						||
{
 | 
						||
  TDocument_tree& me = (TDocument_tree&)*this;
 | 
						||
  const TRectype& rec = _relation->curr(LF_RIGHEDOC);
 | 
						||
  const TRecnotype pos = me._curnode.get_long(0);
 | 
						||
  const int nriga = me._curnode.get_int(1);
 | 
						||
  if (_cursor->pos() != pos || rec.get_int(RDOC_NRIGA) > nriga)
 | 
						||
    *me._cursor = pos;
 | 
						||
  for (int i = rec.get_int(RDOC_NRIGA); i < nriga; i++)
 | 
						||
    _relation->next_match(LF_RIGHEDOC);
 | 
						||
  return rec;  
 | 
						||
}
 | 
						||
 | 
						||
const TRectype& TDocument_tree::record() const
 | 
						||
{
 | 
						||
  return on_row() ? riga() : testata();
 | 
						||
}
 | 
						||
 | 
						||
void TDocument_tree::node2id(const TObject* node, TString& id) const
 | 
						||
{
 | 
						||
  id = *(TString*)node;       
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::on_head() const
 | 
						||
{
 | 
						||
  TDocument_tree& me = (TDocument_tree&)*this;
 | 
						||
  return me._curnode.get_int(1) == 0;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::on_row() const
 | 
						||
{
 | 
						||
  TDocument_tree& me = (TDocument_tree&)*this;
 | 
						||
  return me._curnode.get_int(1) > 0;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::goto_root()
 | 
						||
{
 | 
						||
  const bool ok = _cursor != NULL && _cursor->items()>0;
 | 
						||
  _curnode = ok ? "0" : "";
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::goto_firstson()
 | 
						||
{
 | 
						||
  bool ok = has_son();
 | 
						||
  if (ok)
 | 
						||
    _curnode.add(1,1); 
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::goto_rbrother()
 | 
						||
{
 | 
						||
  bool ok = has_rbrother();
 | 
						||
  if (ok)
 | 
						||
  {
 | 
						||
    if (on_head())
 | 
						||
    {             
 | 
						||
       const long pos = _curnode.get_long(0);
 | 
						||
       _curnode.add(pos+1, 0);
 | 
						||
    } 
 | 
						||
    else
 | 
						||
    {
 | 
						||
      const int nriga = _curnode.get_int(1);
 | 
						||
      _curnode.add(nriga+1, 1);
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::goto_node(const TString &id)
 | 
						||
{            
 | 
						||
  _curnode = id;      
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::has_son() const
 | 
						||
{
 | 
						||
  bool ok = on_head();
 | 
						||
  if (ok)
 | 
						||
  {   
 | 
						||
    testata();
 | 
						||
    const TRectype& rec = _relation->curr(LF_RIGHEDOC);
 | 
						||
    ok = rec.get_int(RDOC_NRIGA) > 0;
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::has_rbrother() const
 | 
						||
{
 | 
						||
  bool ok = FALSE;
 | 
						||
  if (on_head())
 | 
						||
  {
 | 
						||
    TDocument_tree& me = (TDocument_tree&)*this;
 | 
						||
    const long pos = me._curnode.get_long(0);
 | 
						||
    ok = pos < _cursor->items()-1;
 | 
						||
  } 
 | 
						||
  else
 | 
						||
  {
 | 
						||
    riga(); // Posizionati sulla riga corrente
 | 
						||
    ok = _relation->next_match(LF_RIGHEDOC);
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
} 
 | 
						||
 | 
						||
bool TDocument_tree::has_father() const
 | 
						||
{
 | 
						||
  return on_row();
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::has_lbrother() const
 | 
						||
{
 | 
						||
  bool ok = FALSE;
 | 
						||
  TDocument_tree& me = (TDocument_tree&)*this;
 | 
						||
  if (on_head())
 | 
						||
  {
 | 
						||
    const long pos = me._curnode.get_long(0);
 | 
						||
    ok = pos > 0L;
 | 
						||
  } 
 | 
						||
  else
 | 
						||
  {
 | 
						||
    const int nriga = me._curnode.get_int(1);
 | 
						||
    ok = nriga > 1;
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::goto_father()
 | 
						||
{
 | 
						||
  bool ok = on_row();
 | 
						||
  if (ok)       
 | 
						||
    _curnode.add(0, 1);
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::goto_lbrother()
 | 
						||
{
 | 
						||
  bool ok = has_lbrother();
 | 
						||
  if (ok)
 | 
						||
  {
 | 
						||
    if (on_head())
 | 
						||
    {             
 | 
						||
       const long pos = _curnode.get_long(0);
 | 
						||
       _curnode.add(pos-1, 0);
 | 
						||
    } 
 | 
						||
    else
 | 
						||
    {
 | 
						||
      const int nriga = _curnode.get_int(1);
 | 
						||
      _curnode.add(nriga-1, 1);
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return ok;
 | 
						||
}
 | 
						||
 | 
						||
void TDocument_tree::format_field(const TRectype& rec, const TString& field, TString& str) const
 | 
						||
{
 | 
						||
  const TFieldref fld(field, rec.num());
 | 
						||
  const TString& value = fld.read(rec);
 | 
						||
  const TFieldtypes ft = rec.type(fld.name());
 | 
						||
  if (ft == _realfld)
 | 
						||
  {                                       
 | 
						||
    const int len = rec.length(fld.name());
 | 
						||
    const int ndec = rec.ndec(fld.name());
 | 
						||
    TString8 pic; pic.format(".%d", ndec);
 | 
						||
    const real r = value;
 | 
						||
    str = r.string(pic);
 | 
						||
    str.right_just(len);
 | 
						||
  }
 | 
						||
  else
 | 
						||
    str = value;
 | 
						||
}
 | 
						||
 | 
						||
void TDocument_tree::append_custom_fields(const TTipo_documento& tipo, const TRectype& rec, TString& str) const
 | 
						||
{ 
 | 
						||
  const TString& format = rec.num() == LF_DOC ? tipo.stringa_descrizione_documento() 
 | 
						||
                                              : tipo.stringa_descrizione_riga();
 | 
						||
  if (format.not_empty())
 | 
						||
  { 
 | 
						||
    str << ' ';
 | 
						||
    int ch = -1;
 | 
						||
    TString tmp;
 | 
						||
    for (int ap = format.find('{'); ap >= 0; ap = format.find('{', ch+1))
 | 
						||
    {     
 | 
						||
      str << format.sub(ch+1, ap);
 | 
						||
      ch = format.find('}', ap);
 | 
						||
      const TString16 field = format.sub(ap+1, ch);
 | 
						||
      format_field(rec, field, tmp);
 | 
						||
      str << tmp;
 | 
						||
    }
 | 
						||
    str << format.mid(ch+1);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
TImage* TDocument_tree::image(bool selected) const
 | 
						||
{                
 | 
						||
  if (on_row()) 
 | 
						||
  {
 | 
						||
    const TRectype& rec = riga();
 | 
						||
    if (rec.get_bool(RDOC_RIGAEVASA))
 | 
						||
      return get_res_image(BMP_STOP);
 | 
						||
  }
 | 
						||
  return TTree::image(selected);
 | 
						||
}
 | 
						||
 | 
						||
bool TDocument_tree::get_description(TString& str) const
 | 
						||
{
 | 
						||
  if (on_head())
 | 
						||
  {
 | 
						||
    const TRectype& rec = testata();
 | 
						||
    str = rec.get(DOC_ANNO);
 | 
						||
    str << ' ' << rec.get(DOC_CODNUM);
 | 
						||
    TString16 tmp;
 | 
						||
    tmp.format("%6ld", rec.get_long(DOC_NDOC));
 | 
						||
    str << ' ' << tmp << ' ' << rec.get(DOC_DATADOC);
 | 
						||
    const char tipocf = rec.get_char(DOC_TIPOCF);
 | 
						||
    const long codcf = rec.get_long(DOC_CODCF);
 | 
						||
    tmp.format(" %c%6ld ", tipocf, codcf);
 | 
						||
    str << tmp;
 | 
						||
    tmp.format("%c|%6ld", tipocf, codcf);
 | 
						||
    str << cache().get(LF_CLIFO, tmp, CLI_RAGSOC);
 | 
						||
    str.left_just(63);
 | 
						||
    
 | 
						||
    const TTipo_documento& tipo = TDocumento::tipo(rec.get(DOC_TIPODOC));
 | 
						||
    append_custom_fields(tipo, rec, str);
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    const TRectype& rec = riga();
 | 
						||
    const TRectype& testata = _relation->curr();
 | 
						||
    
 | 
						||
    const TString80 codart = rec.get(RDOC_CODART);
 | 
						||
    str = codart;
 | 
						||
    str.left_just(21);
 | 
						||
    str << rec.get(RDOC_DESCR).left(30);
 | 
						||
    str.left_just(52);
 | 
						||
    
 | 
						||
    if (codart.not_empty())
 | 
						||
    {
 | 
						||
      const TTipo_documento& tipo = TDocumento::tipo(testata.get(DOC_TIPODOC));
 | 
						||
      const real qta = rec.get(tipo.field_qta());
 | 
						||
      str << qta.string("###.###.##@,@@@");
 | 
						||
      if (tipo.is_ordine())
 | 
						||
      {
 | 
						||
        const real qta_evasa = rec.get(tipo.field_qtaevasa());
 | 
						||
        const real residuo = qta_evasa < qta ? (qta-qta_evasa) : ZERO;
 | 
						||
        str << residuo.string("###.###.##@,@@@");
 | 
						||
      }
 | 
						||
      append_custom_fields(tipo, rec, str);
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TDocument_tree::set_cursor(char tipocf, long codcf, int anno, const char* filter, FILTERFUNCTION ff)
 | 
						||
{ 
 | 
						||
  if (_relation == NULL)
 | 
						||
  {
 | 
						||
    _relation = new TRelation(LF_DOC);
 | 
						||
    _relation->add(LF_RIGHEDOC, "PROVV==PROVV|ANNO==ANNO|CODNUM==CODNUM|NDOC==NDOC");
 | 
						||
  }
 | 
						||
  if (_cursor == NULL)
 | 
						||
  {
 | 
						||
    _cursor = new TCursor(_relation, "", 2); 
 | 
						||
  }
 | 
						||
  TRectype& rec = _relation->curr();
 | 
						||
  rec.zero();
 | 
						||
  rec.put(DOC_TIPOCF, tipocf);
 | 
						||
  rec.put(DOC_CODCF, codcf);
 | 
						||
  rec.put(DOC_PROVV, "D");
 | 
						||
  rec.put(DOC_ANNO, anno);
 | 
						||
  _cursor->freeze(FALSE);
 | 
						||
  _cursor->setfilter(filter);
 | 
						||
  _cursor->setregion(rec, rec);
 | 
						||
  const long items = _cursor->items();
 | 
						||
  _cursor->freeze(TRUE);
 | 
						||
  
 | 
						||
  goto_root();
 | 
						||
  if (items <= 3)
 | 
						||
    expand_all();
 | 
						||
}
 | 
						||
 | 
						||
TDocument_tree::TDocument_tree() 
 | 
						||
              : _relation(NULL), _cursor(NULL)
 | 
						||
{
 | 
						||
}
 | 
						||
 
 | 
						||
TDocument_tree::~TDocument_tree()
 | 
						||
{
 | 
						||
  if (_cursor)
 | 
						||
    delete _cursor;
 | 
						||
  if (_relation)
 | 
						||
    delete _relation;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TElabora_mask
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
class TElabora_mask : public TAutomask
 | 
						||
{         
 | 
						||
  TDocumento_mask* _main;
 | 
						||
  TLista_elaborazioni _elab;
 | 
						||
  TDocument_tree _tree;
 | 
						||
 | 
						||
  TElaborazione* _last_elab;
 | 
						||
  
 | 
						||
// @access Protected Member
 | 
						||
protected:        
 | 
						||
  TString _art_filter, _liv_filter;
 | 
						||
  static TElabora_mask* _myself;
 | 
						||
  static bool article_filter(const TRelation* rel);
 | 
						||
 | 
						||
  void add_valuta_filter(TString& filter) const;
 | 
						||
  
 | 
						||
  void docrif_search();
 | 
						||
  int update_list();
 | 
						||
  void update_ndoc_filter(bool is_tipo_elaborazione = FALSE);
 | 
						||
 | 
						||
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						||
  
 | 
						||
// @access Public Member
 | 
						||
public:        
 | 
						||
  bool elabora();  
 | 
						||
  TElaborazione* curr_elab();
 | 
						||
 | 
						||
  // @cmember Costruttore (crea la maschera leggendo la descrizione dal file .msk)
 | 
						||
  TElabora_mask(TDocumento_mask& main_mask);
 | 
						||
  // @cmember Distruttore
 | 
						||
  virtual ~TElabora_mask() {} 
 | 
						||
};
 | 
						||
 | 
						||
TElabora_mask* TElabora_mask::_myself = NULL;
 | 
						||
 | 
						||
bool TElabora_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						||
{
 | 
						||
  switch (o.dlg())
 | 
						||
  {                
 | 
						||
  case F_CODART:
 | 
						||
  case F_CODNUM_ELAB:
 | 
						||
    if (e == fe_modify)
 | 
						||
      update_ndoc_filter();
 | 
						||
    break;
 | 
						||
  case F_TYPE:
 | 
						||
    if (e == fe_init || e == fe_modify)
 | 
						||
    {
 | 
						||
      int ne = update_list();
 | 
						||
      if (e == fe_init && ne == 0)  // Riprova a cambiare flag e ricostruire la lista
 | 
						||
      {
 | 
						||
        set(F_TYPE, "X");
 | 
						||
        ne = update_list();
 | 
						||
        if (ne == 0)
 | 
						||
          set(F_TYPE, "");
 | 
						||
      }
 | 
						||
      update_ndoc_filter(TRUE);
 | 
						||
      const bool is_search = o.get().empty() || field(F_CODCF_ELAB).empty();
 | 
						||
      o.mask().field(F_NDOC_ELAB).check_type(is_search ? CHECK_SEARCH : CHECK_REQUIRED);
 | 
						||
    }
 | 
						||
    break;    
 | 
						||
  case F_STATODOC_ELAB:
 | 
						||
  case F_TIPODOC_ELAB:
 | 
						||
    if (e == fe_modify)
 | 
						||
    {
 | 
						||
      update_list();
 | 
						||
      update_ndoc_filter();
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case F_ELAB:
 | 
						||
  case F_ANNO_ELAB:
 | 
						||
 | 
						||
    if (e == fe_modify)
 | 
						||
      update_ndoc_filter();
 | 
						||
    break;
 | 
						||
  case F_NUMDOCRIF_ELAB:
 | 
						||
    if (e == fe_button) 
 | 
						||
      docrif_search();
 | 
						||
    break;
 | 
						||
  case F_NDOC_ELAB:
 | 
						||
    if ((e == fe_modify || e == fe_close) && o.check_type() == CHECK_SEARCH && !o.empty()) 
 | 
						||
    {
 | 
						||
/*    Metodo inaffidabile in assenza di codice clifo
 | 
						||
      o.check_type(CHECK_REQUIRED);
 | 
						||
      const bool ok = o.on_key (K_ENTER);
 | 
						||
      o.check_type(CHECK_SEARCH);
 | 
						||
      return ok;      
 | 
						||
*/      
 | 
						||
      TToken_string key; 
 | 
						||
      key.add("D"); key.add(get(F_ANNO_ELAB));
 | 
						||
      key.add(get(F_CODNUM_ELAB)); key.add(o.get());
 | 
						||
      const TRectype& rec = cache().get(LF_DOC, key);
 | 
						||
      bool ok = !rec.empty(); // Verifica esistenza documento
 | 
						||
      if (ok)
 | 
						||
      {
 | 
						||
        TCursor* c = _tree.get_cursor();
 | 
						||
        c->curr() = rec;
 | 
						||
        ok = c->test(_isequal) == NOERR; // Verifica compatibilit<69> documento
 | 
						||
      }
 | 
						||
      if (!ok)
 | 
						||
        return error_box(((TEdit_field&)o).get_warning());
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  case F_ROWS:
 | 
						||
    if (e == fe_modify && is_running()) 
 | 
						||
    {                
 | 
						||
      TCursor* c = _tree.get_cursor();
 | 
						||
      if (c != NULL && c->items() > 0)
 | 
						||
      {
 | 
						||
        const TRectype& head = _tree.testata();
 | 
						||
        set(F_DATADOC_ELAB, head.get(DOC_DATADOC)); // Anch'essa nella chiave 2!
 | 
						||
        set(F_ANNO_ELAB, head.get(DOC_ANNO));
 | 
						||
        set(F_CODNUM_ELAB, head.get(DOC_CODNUM));
 | 
						||
        field(F_CODNUM_ELAB).check();
 | 
						||
        set(F_NDOC_ELAB, head.get(DOC_NDOC));
 | 
						||
      }
 | 
						||
    }
 | 
						||
    break;
 | 
						||
  default:
 | 
						||
    break;
 | 
						||
  }
 | 
						||
  return TRUE;  
 | 
						||
}
 | 
						||
 | 
						||
int TElabora_mask::update_list()
 | 
						||
{
 | 
						||
  TString_array elabs;
 | 
						||
  const TString16 tipo(_main->get(F_TIPODOC));
 | 
						||
  const TString16 stato(_main->get(F_STATO));
 | 
						||
  const TString16 tipo_elab(get(F_TIPODOC_ELAB));
 | 
						||
  const TString16 stato_elab(get(F_STATODOC_ELAB));
 | 
						||
  const bool from_elab = !get_bool(F_TYPE);   
 | 
						||
  int items = 0;
 | 
						||
  
 | 
						||
  bool agg_test = FALSE;  
 | 
						||
  if (from_elab)
 | 
						||
    items = _elab.select(elabs, tipo, stato,"",""/*tipo_elab, stato_elab*/) ;
 | 
						||
  else
 | 
						||
  {
 | 
						||
    items = _elab.select(elabs, tipo_elab, stato_elab, tipo, stato);
 | 
						||
    agg_test = _main->sfield(F_SHEET).items() == 0;
 | 
						||
  }  
 | 
						||
  set(F_UPDATE_HEADER, agg_test ? "X" : "");
 | 
						||
 | 
						||
  const bool ok = items > 0;
 | 
						||
  enable(DLG_OK, ok);
 | 
						||
  enable(F_ELAB, ok);
 | 
						||
 | 
						||
  TList_field & f = (TList_field &) field(F_ELAB);
 | 
						||
  TToken_string codes;
 | 
						||
  TToken_string descrs;
 | 
						||
 | 
						||
  for (int i = 0; i < items; i++)
 | 
						||
  {           
 | 
						||
    const TElaborazione& e = _elab[elabs.row(i)];
 | 
						||
    codes.add(e.codice());
 | 
						||
    descrs.add(e.descrizione());
 | 
						||
  }
 | 
						||
  if (codes != f.get_codes())
 | 
						||
    f.replace_items(codes, descrs);
 | 
						||
  const TElaborazione * e = curr_elab();
 | 
						||
  if (e && e->tipo() == _consegna_ordini)
 | 
						||
    show(-GRP_ART);
 | 
						||
  else
 | 
						||
  {
 | 
						||
    reset(-GRP_ART);
 | 
						||
    hide(-GRP_ART);
 | 
						||
  }
 | 
						||
  
 | 
						||
  return items;
 | 
						||
}
 | 
						||
 | 
						||
bool TElabora_mask::elabora()
 | 
						||
{   
 | 
						||
  bool update_mask = FALSE;
 | 
						||
 | 
						||
  TLista_documenti in;
 | 
						||
  TLista_documenti out;                                 
 | 
						||
  TDocumento& app_doc = ((TDocumento_mask *)_main)->doc();
 | 
						||
  long numdoc = get_long(F_NDOC_ELAB);
 | 
						||
  const bool update_header = get_bool(F_UPDATE_HEADER);
 | 
						||
  
 | 
						||
  TDocumento* newdoc = new TDocumento(*get(F_PROVV_ELAB), get_int(F_ANNO_ELAB), get(F_CODNUM_ELAB), numdoc);
 | 
						||
  TDocumento& d = *newdoc;
 | 
						||
 | 
						||
  if (numdoc <= 0)                   
 | 
						||
  {            
 | 
						||
    TDocumento::copy_data(d.head(), app_doc.head());
 | 
						||
    d.put(DOC_TIPODOC, get(F_TIPODOC_ELAB));     
 | 
						||
    
 | 
						||
    const TDate datadoc = d.get_date(DOC_DATADOC);
 | 
						||
    const TDate datainsc = d.get_date(DOC_DATAINSC);
 | 
						||
    const bool equal = !datainsc.ok() || datadoc == datainsc;
 | 
						||
    
 | 
						||
    d.put(DOC_DATADOC, get(F_DATADOC_ELAB));
 | 
						||
    if (equal)
 | 
						||
      d.zero(DOC_DATAINSC);
 | 
						||
    
 | 
						||
    const TTipo_documento & t = d.tipo();
 | 
						||
    
 | 
						||
    if (t.mov_mag())
 | 
						||
      d.put(DOC_CAUSMAG, t.caus_mov());
 | 
						||
    else
 | 
						||
      d.zero(DOC_CAUSMAG);
 | 
						||
  }
 | 
						||
  
 | 
						||
  if (update_header)                   
 | 
						||
  {                                                      
 | 
						||
    const TString16 tipo_doc(app_doc.get(DOC_TIPODOC));
 | 
						||
    const TString16 caus_mag(app_doc.get(DOC_CAUSMAG));
 | 
						||
    const long movmag = app_doc.get_long(DOC_MOVMAG);
 | 
						||
    const TDate datadoc = app_doc.get_date(DOC_DATADOC);
 | 
						||
    const TDate datainsc = app_doc.get_date(DOC_DATAINSC);
 | 
						||
    const char stato = app_doc.stato();
 | 
						||
    
 | 
						||
    TDocumento::copy_data(app_doc.head(), d.head());
 | 
						||
    
 | 
						||
    app_doc.put(DOC_TIPODOC, tipo_doc);
 | 
						||
    app_doc.put(DOC_CAUSMAG, caus_mag);
 | 
						||
    app_doc.put(DOC_MOVMAG, movmag);
 | 
						||
    app_doc.put(DOC_DATADOC, datadoc);
 | 
						||
    app_doc.put(DOC_DATAINSC, datainsc);
 | 
						||
    app_doc.put(DOC_STATO, stato);
 | 
						||
  }
 | 
						||
  
 | 
						||
  const bool from_elab = !get_bool(F_TYPE);   
 | 
						||
  TElaborazione * e = curr_elab();
 | 
						||
  
 | 
						||
  if (e == NULL)
 | 
						||
    return FALSE;
 | 
						||
  
 | 
						||
  if (e->tipo() == _consegna_ordini)
 | 
						||
  {
 | 
						||
    TParametri_elaborazione& p = e->params();
 | 
						||
    p.set("ARTICOLO", get(F_CODART));
 | 
						||
    p.set("UM", get(F_UMQTA));
 | 
						||
    p.set("QUANTITA", get(F_QTA));
 | 
						||
  }
 | 
						||
  if (from_elab)
 | 
						||
  {
 | 
						||
    in.add(app_doc);
 | 
						||
    out.add(d);
 | 
						||
    if (e->elabora(in, out, TDate(TODAY), TRUE))
 | 
						||
    {                    
 | 
						||
      if (out[0] != d)
 | 
						||
        out.rewrite();
 | 
						||
      if (app_doc != in[0])
 | 
						||
      {
 | 
						||
        in.rewrite();
 | 
						||
        app_doc = in[0];
 | 
						||
        update_mask = TRUE;
 | 
						||
      }  
 | 
						||
    }
 | 
						||
  }
 | 
						||
  else
 | 
						||
  {
 | 
						||
    out.add(app_doc);
 | 
						||
    in.add(d);
 | 
						||
    if (e->elabora(in, out, TDate(TODAY), TRUE))
 | 
						||
    {
 | 
						||
      if (out[0] != app_doc)
 | 
						||
      {
 | 
						||
        out.rewrite();
 | 
						||
        app_doc = out[0];
 | 
						||
        update_mask = TRUE;
 | 
						||
      }            
 | 
						||
      if (d != in[0])
 | 
						||
        in.rewrite();
 | 
						||
    }
 | 
						||
    TString8 num_in(e->codice_numerazione_iniziale());
 | 
						||
  
 | 
						||
    set(F_CODNUM_ELAB, num_in);
 | 
						||
    set(F_NDOC_ELAB, "");
 | 
						||
    set(F_NUMDOCRIF_ELAB, "");
 | 
						||
  }         
 | 
						||
  if (e->tipo() == _consegna_ordini)
 | 
						||
  {
 | 
						||
    TParametri_elaborazione& p = e->params();
 | 
						||
    if (p.get("ARTICOLO").not_empty())
 | 
						||
    {
 | 
						||
      real qta = get_real(F_QTA);
 | 
						||
      if (qta > ZERO)
 | 
						||
      {
 | 
						||
        const real qta_evasa = p.get_real("QUANTITA");
 | 
						||
        qta -= qta_evasa;
 | 
						||
        set(F_QTA, qta);
 | 
						||
      } 
 | 
						||
    }
 | 
						||
  }
 | 
						||
  
 | 
						||
  delete newdoc;
 | 
						||
 | 
						||
  // Azzera l'anno in caso di ordini
 | 
						||
  if (in.items() > 0 && in[0].is_ordine()) 
 | 
						||
  {
 | 
						||
    reset(F_ANNO_ELAB);
 | 
						||
    update_mask = TRUE;
 | 
						||
  }
 | 
						||
 | 
						||
  if (update_mask)
 | 
						||
    update_ndoc_filter();
 | 
						||
      
 | 
						||
  return update_mask;
 | 
						||
}
 | 
						||
 | 
						||
TElaborazione * TElabora_mask::curr_elab()
 | 
						||
{
 | 
						||
  const TString16 cod_elab(get(F_ELAB));
 | 
						||
  return cod_elab.not_empty() ? &_elab[cod_elab] : NULL;
 | 
						||
}     
 | 
						||
 | 
						||
bool TElabora_mask::article_filter(const TRelation* rel)
 | 
						||
{                          
 | 
						||
  bool yes = FALSE;
 | 
						||
  TElabora_mask& m = *_myself;
 | 
						||
  TLocalisamfile rdoc(LF_RIGHEDOC);
 | 
						||
  rdoc.put(RDOC_CODNUM, rel->curr().get(DOC_CODNUM));
 | 
						||
  rdoc.put(RDOC_ANNO,   rel->curr().get(DOC_ANNO));
 | 
						||
  rdoc.put(RDOC_PROVV,  rel->curr().get(DOC_PROVV));
 | 
						||
  rdoc.put(RDOC_NDOC,   rel->curr().get(DOC_NDOC));
 | 
						||
  rdoc.put(RDOC_NRIGA,  1);
 | 
						||
  int next_riga = 1;
 | 
						||
  for (int err = rdoc.read(); err == NOERR; err = rdoc.next())
 | 
						||
  {
 | 
						||
    const int nriga = rdoc.get_int(RDOC_NRIGA);
 | 
						||
    if (nriga != next_riga)
 | 
						||
      break;
 | 
						||
    next_riga++;  
 | 
						||
    const bool evasa= rdoc.get_bool(RDOC_RIGAEVASA);
 | 
						||
    const TString& codart = rdoc.get(RDOC_CODART);
 | 
						||
    if (!evasa && codart == m._art_filter)
 | 
						||
    {   
 | 
						||
      yes = TRUE;
 | 
						||
      break;
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return yes;
 | 
						||
}
 | 
						||
 | 
						||
void TElabora_mask::add_valuta_filter(TString& filter) const
 | 
						||
{                                             
 | 
						||
  TString16 valuta = get(F_CODVAL_ELAB);
 | 
						||
  if (::is_firm_value(valuta))
 | 
						||
  {              
 | 
						||
    filter << "((CODVAL==\"" << valuta <<  "\")";
 | 
						||
    if (valuta.empty())
 | 
						||
      valuta = TCurrency::get_firm_val();
 | 
						||
    else
 | 
						||
      valuta.cut(0);  
 | 
						||
    filter << "||(CODVAL==\"" << valuta <<  "\"))";
 | 
						||
  }
 | 
						||
  else
 | 
						||
    filter << "(CODVAL==\"" << valuta <<  "\")";
 | 
						||
}
 | 
						||
 | 
						||
void TElabora_mask::update_ndoc_filter(bool is_tipo_elaborazione)
 | 
						||
{
 | 
						||
  TString filter(80);
 | 
						||
  // Ora <20> nella maschera
 | 
						||
  // filter.format("(TIPOCF==\"%s\")&&(CODCF==\"%s\")&&", (const char *)get(F_TIPOCF_ELAB), (const char *)get(F_CODCF_ELAB));
 | 
						||
  add_valuta_filter(filter);
 | 
						||
  
 | 
						||
  TElaborazione * e = curr_elab();
 | 
						||
  const bool elab_changed = e != _last_elab;
 | 
						||
  _last_elab = e;
 | 
						||
 | 
						||
  const bool aggiungi_doc_att = get_bool(F_TYPE);   
 | 
						||
  enable(-1, aggiungi_doc_att /*&& e != NULL*/);
 | 
						||
 | 
						||
  if (!aggiungi_doc_att && is_tipo_elaborazione )
 | 
						||
    reset(-1);
 | 
						||
  if (e != NULL)
 | 
						||
  {
 | 
						||
    if (aggiungi_doc_att)
 | 
						||
    {
 | 
						||
      const TString8 num_in = e->codice_numerazione_iniziale(); 
 | 
						||
      if (elab_changed)
 | 
						||
      { 
 | 
						||
        const TString16 tipo_in(e->tipo_iniziale(0));
 | 
						||
        const char stato_in = e->stato_iniziale(0);
 | 
						||
 | 
						||
        set(F_CODNUM_ELAB, num_in);
 | 
						||
        field(F_CODNUM_ELAB).check();
 | 
						||
        set(F_TIPODOC_ELAB , tipo_in);
 | 
						||
        field(F_TIPODOC_ELAB).check();
 | 
						||
        TString8 si; si << stato_in;
 | 
						||
        set(F_STATODOC_ELAB, si);
 | 
						||
        field(F_STATODOC_ELAB).check();
 | 
						||
  
 | 
						||
        // Azzero anno di elaaborazione quando ho a che fare con degli ordini        
 | 
						||
        const TTipo_documento& tipodocin = _main->doc().tipo(tipo_in);
 | 
						||
        if (tipodocin.is_ordine())
 | 
						||
          reset(F_ANNO_ELAB);
 | 
						||
      }
 | 
						||
 | 
						||
      if (!field(F_TIPODOC_ELAB).empty())                                   
 | 
						||
      { 
 | 
						||
        const TString16 tipo(get(F_TIPODOC_ELAB));
 | 
						||
        TString80 td; td.format("&&(TIPODOC==\"%s\")", (const char *)tipo);
 | 
						||
        filter << td;
 | 
						||
        const TString& stato = get(F_STATODOC_ELAB);
 | 
						||
        if (stato.not_empty())
 | 
						||
        {
 | 
						||
          filter << "&&(STATO==\"" << stato << "\")";
 | 
						||
        }
 | 
						||
        else
 | 
						||
        {
 | 
						||
          bool almost_one = FALSE;
 | 
						||
                                           
 | 
						||
          for (int i = 0; i < TElaborazione::_max_tipi_doc_elab; i++)
 | 
						||
          {
 | 
						||
            const TString16 tipo_in(e->tipo_iniziale(i));
 | 
						||
            const char stato_in = e->stato_iniziale(i);
 | 
						||
              
 | 
						||
            if (tipo == tipo_in && stato_in > '0')
 | 
						||
            {                       
 | 
						||
              if (almost_one)
 | 
						||
                filter << "||";
 | 
						||
              else
 | 
						||
                filter << "&&(";
 | 
						||
              almost_one = TRUE;
 | 
						||
              
 | 
						||
             filter << "(STATO==\"" << stato_in << "\")";
 | 
						||
            }
 | 
						||
          }
 | 
						||
          if (almost_one)
 | 
						||
            filter << ')';
 | 
						||
        }
 | 
						||
      }
 | 
						||
      else
 | 
						||
      {  
 | 
						||
        bool almost_one = FALSE;
 | 
						||
                                         
 | 
						||
        for (int i = 0; i < TElaborazione::_max_tipi_doc_elab; i++)
 | 
						||
        {
 | 
						||
          const TString16 tipo_in(e->tipo_iniziale(i));
 | 
						||
          if (tipo_in.not_empty())
 | 
						||
          {                       
 | 
						||
            if (almost_one)
 | 
						||
              filter << "||";
 | 
						||
            else
 | 
						||
              filter << "&&(";
 | 
						||
            almost_one = TRUE;
 | 
						||
            filter << "((TIPODOC==\"" << tipo_in << "\")";
 | 
						||
              
 | 
						||
            const char stato_in[2] = { e->stato_iniziale(i), '\0' };
 | 
						||
            if (stato_in[0] > '0')
 | 
						||
              filter << "&&(STATO==\"" << stato_in << "\")";
 | 
						||
            filter << ')';
 | 
						||
          }
 | 
						||
        }
 | 
						||
        if (almost_one)
 | 
						||
          filter << ')';
 | 
						||
      }   
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      const TString16 tipo_fin(e->tipo_finale());
 | 
						||
      const TString16 stato_fin(e->stato_finale());
 | 
						||
 | 
						||
      filter << "&&";
 | 
						||
      if (stato_fin != "0")
 | 
						||
        filter << '(';
 | 
						||
      filter << "(TIPODOC==\"" << tipo_fin << "\")";
 | 
						||
      if (stato_fin != "0")
 | 
						||
        filter << "&&(STATO==\"" << stato_fin << "\"))";
 | 
						||
 | 
						||
      if (is_tipo_elaborazione)
 | 
						||
      {           
 | 
						||
        const TString16 num_fin(e->codice_numerazione_finale());
 | 
						||
        set(F_CODNUM_ELAB, num_fin);
 | 
						||
        field(F_CODNUM_ELAB).check();
 | 
						||
        set(F_TIPODOC_ELAB, tipo_fin);
 | 
						||
        field(F_TIPODOC_ELAB).check();
 | 
						||
        set(F_STATODOC_ELAB, stato_fin);
 | 
						||
        field(F_STATODOC_ELAB).check();
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
 | 
						||
  if (!field(F_CODNUM_ELAB).empty())
 | 
						||
  {
 | 
						||
    TString80 cn; cn.format("&&(CODNUM==\"%s\")", (const char*)get(F_CODNUM_ELAB));
 | 
						||
    filter << cn;
 | 
						||
  }
 | 
						||
  
 | 
						||
  TBrowse& brew = *efield(F_NDOC_ELAB).browse();
 | 
						||
  brew.set_filter(filter);
 | 
						||
  
 | 
						||
  _art_filter = get(F_CODART);
 | 
						||
 | 
						||
  TCursor* cursor = brew.cursor();
 | 
						||
  if (_art_filter.not_empty() && aggiungi_doc_att)
 | 
						||
    cursor->set_filterfunction(article_filter);
 | 
						||
  else
 | 
						||
    cursor->set_filterfunction(NULL);
 | 
						||
    
 | 
						||
  TTree_field& tf = tfield(F_ROWS); 
 | 
						||
  if (!field(F_TIPODOC_ELAB).empty() && e != NULL)
 | 
						||
  {
 | 
						||
    tf.set_tree(&_tree);
 | 
						||
    TToken_string header(256, '\n');
 | 
						||
    header.add("Anno Num.    N. Data       Cli/For Ragione Sociale");
 | 
						||
    header.add("   Codice Articolo      Descrizione Riga                    ");
 | 
						||
    if (e->tipo() == _consegna_ordini)
 | 
						||
      header << "Da Evadere        Residuo";
 | 
						||
    else
 | 
						||
      header << "  Quantit<69>";
 | 
						||
    tf.set_header(header);
 | 
						||
  
 | 
						||
    if (aggiungi_doc_att && _art_filter.not_empty())
 | 
						||
      _tree.set_cursor(get(F_TIPOCF_ELAB)[0], get_long(F_CODCF_ELAB), get_int(F_ANNO_ELAB), filter, article_filter);
 | 
						||
    else  
 | 
						||
      _tree.set_cursor(get(F_TIPOCF_ELAB)[0], get_long(F_CODCF_ELAB), get_int(F_ANNO_ELAB), filter);
 | 
						||
    
 | 
						||
    TCursor& cur = *_tree.get_cursor();
 | 
						||
    if (cur.items() == 1) // Propone l'unico documento possibile
 | 
						||
    {                                
 | 
						||
      cur = 0L;
 | 
						||
      const TRectype& curr = cur.curr();
 | 
						||
      set(F_NDOC_ELAB, curr.get(DOC_NDOC));
 | 
						||
      set(F_DATADOC_ELAB, curr.get(DOC_DATADOC));
 | 
						||
    }
 | 
						||
  }
 | 
						||
  else
 | 
						||
    tf.set_tree(NULL);
 | 
						||
  tf.win().force_update();
 | 
						||
}
 | 
						||
 | 
						||
void TElabora_mask::docrif_search()
 | 
						||
{
 | 
						||
  TRectype filtrec(LF_DOC);
 | 
						||
  filtrec.put(DOC_TIPOCF, get(F_TIPOCF_ELAB));
 | 
						||
  filtrec.put(DOC_CODCF, get(F_CODCF_ELAB));
 | 
						||
  filtrec.put(DOC_PROVV, get(F_PROVV_ELAB));
 | 
						||
  filtrec.put(DOC_ANNO, get(F_ANNO_ELAB));
 | 
						||
    
 | 
						||
  TRelation rel(LF_DOC);
 | 
						||
  rel.add(LF_CLIFO, "TIPOCF==TIPOCF|CODCF==CODCF");
 | 
						||
  TSorted_cursor cur(&rel, "TIPOCF|CODCF|PROVV|ANNO|CODNUM|NUMDOCRIF", "", 2, &filtrec, &filtrec);
 | 
						||
  TString flt(256); 
 | 
						||
  if (!field(F_CODNUM_ELAB).empty())
 | 
						||
    flt << "(CODNUM==\"" << get(F_CODNUM_ELAB) << "\")&&";
 | 
						||
  if (!field(F_TIPODOC_ELAB).empty())
 | 
						||
    flt << "(TIPODOC==\"" << get(F_TIPODOC_ELAB) << "\")&&";
 | 
						||
  if (!field(F_STATODOC_ELAB).empty())
 | 
						||
    flt << "(STATO==\"" << get(F_STATODOC_ELAB) << "\")&&";
 | 
						||
  add_valuta_filter(flt); flt << "&&";
 | 
						||
  TEdit_field& f = efield(F_NUMDOCRIF_ELAB);
 | 
						||
  if (!f.empty())
 | 
						||
    flt << "(NUMDOCRIF==\"" << f.get() << "\")&&";
 | 
						||
  flt.rtrim(2);  // Togli gli ultimi &&
 | 
						||
  
 | 
						||
  cur.setfilter(flt);
 | 
						||
  
 | 
						||
  TToken_string fields = "ANNO|CODNUM|TIPODOC|NUMDOCRIF|STATO|DATADOCRIF|DOC1|DOC2|DOC3|NDOC|20->RAGSOC";
 | 
						||
  TCursor_sheet sheet(&cur, fields, 
 | 
						||
                      "Documento di riferimento",
 | 
						||
                      "Anno|Num.|Tipo|Docum.Rif.|Stato|Data@10|Docum.Rif.1|Docum.Rif.2|Docum.Rif.3|Documento|Ragione Sociale@50",
 | 
						||
                      0, 1);
 | 
						||
  if (sheet.run() == K_ENTER)
 | 
						||
  {                                     
 | 
						||
    const int nrifpos = fields.get_pos("NUMDOCRIF");
 | 
						||
    const TString16 nrif = sheet.row(-1).get(nrifpos);
 | 
						||
    f.set(nrif);
 | 
						||
    const int ndocpos = fields.get_pos("NDOC");
 | 
						||
    const TString16 ndoc = sheet.row(-1).get(ndocpos);
 | 
						||
    set(F_NDOC_ELAB, ndoc);
 | 
						||
    const int codnumpos = fields.get_pos("CODNUM");
 | 
						||
    const TString16 codnum = sheet.row(-1).get(codnumpos);
 | 
						||
    set(F_CODNUM_ELAB, codnum, TRUE);
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
TElabora_mask::TElabora_mask(TDocumento_mask& main_mask)
 | 
						||
             : TAutomask("ve0100b"), _main(&main_mask), _last_elab(NULL)
 | 
						||
{                                            
 | 
						||
  _myself = this;
 | 
						||
  
 | 
						||
  set(F_ANNO_ELAB, _main->get(F_ANNO));
 | 
						||
  set(F_TIPOCF_ELAB, _main->get(F_TIPOCF));                                                 
 | 
						||
  set(F_CODCF_ELAB, _main->get(F_CODCF));
 | 
						||
  set(F_CODVAL_ELAB, _main->get(F_CODVAL));
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::elabora_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_SPACE)
 | 
						||
  {
 | 
						||
    TDocumento_mask& m = (TDocumento_mask&)f.mask();
 | 
						||
    m.update_progs();
 | 
						||
    if (m.check_fields()) // Check values
 | 
						||
    {
 | 
						||
      TElabora_mask* selection = new TElabora_mask(m); // No woman no stack
 | 
						||
      bool update_mask = FALSE;
 | 
						||
      const char stato_iniziale = m.doc().stato();
 | 
						||
      
 | 
						||
      while (selection->run() != K_ESC)
 | 
						||
      {
 | 
						||
        m.mask2doc();
 | 
						||
        update_mask |= selection->elabora();
 | 
						||
        
 | 
						||
        if (m.doc().stato() != stato_iniziale)
 | 
						||
          break;
 | 
						||
        if (update_mask)
 | 
						||
        {        
 | 
						||
          m.doc2mask(FALSE);
 | 
						||
          TSheet_field& ss = m.sfield(F_SHEET);          
 | 
						||
          for (int i = 0; i < ss.items(); i++)
 | 
						||
          {
 | 
						||
            m.ss_notify(ss,i,K_TAB); 
 | 
						||
            m.ss_notify(ss,i,K_SPACE); 
 | 
						||
            m.ss_notify(ss,i,K_ENTER); 
 | 
						||
          }
 | 
						||
        }  
 | 
						||
      }
 | 
						||
      if (update_mask)
 | 
						||
      {
 | 
						||
        m.doc2mask(FALSE);
 | 
						||
        // Provoca decodifiche necessarie
 | 
						||
        const int last = m.id2pos(BASE_PIEDE + 1);
 | 
						||
        for (int p = 0; p < last; p++)
 | 
						||
        {
 | 
						||
          TMask_field& f = m.fld(p);
 | 
						||
          f.check(STARTING_CHECK);
 | 
						||
        }
 | 
						||
      }
 | 
						||
      delete selection;     
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
// TDocumento_mask
 | 
						||
///////////////////////////////////////////////////////////
 | 
						||
 | 
						||
bool TDocumento_mask::print_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_SPACE)      
 | 
						||
    main_app().print();
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
void TDocumento_mask::user_set_handler(int fieldid, int index)
 | 
						||
{
 | 
						||
  switch( index )
 | 
						||
  {
 | 
						||
  case 1:
 | 
						||
    set_handler( fieldid, ora_hndl );
 | 
						||
    break;
 | 
						||
  case 2:
 | 
						||
    set_handler( fieldid, totdoc_hndl );
 | 
						||
    break;
 | 
						||
  case 3:
 | 
						||
    set_handler( fieldid, numdocrif_hndl );
 | 
						||
    break;
 | 
						||
  case 4:
 | 
						||
    set_handler( fieldid, dummy_hndl );
 | 
						||
    break;
 | 
						||
  default:
 | 
						||
    CHECK( FALSE, "Tentativo di installare un handler non definito" );
 | 
						||
    break;
 | 
						||
  }
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::num_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.to_check(key, TRUE))
 | 
						||
  {
 | 
						||
    // Ottengo la maschera
 | 
						||
    TDocumento_mask& m = (TDocumento_mask&)f.mask( );
 | 
						||
    
 | 
						||
    TTable & tabnum  = ((TTable &) ((TEdit_field &)f).browse()->cursor()->file());
 | 
						||
    if ( tabnum.good())
 | 
						||
    {
 | 
						||
      TCodice_numerazione cod_num(tabnum.curr());
 | 
						||
      m.set( F_DESNUM, cod_num.descrizione());
 | 
						||
      // Propone il primo tipo di documento come default
 | 
						||
      if (m.field(F_TIPODOC).empty() || f.focusdirty())
 | 
						||
      {
 | 
						||
        m.set( F_TIPODOC, cod_num.tipo_doc(0));
 | 
						||
        m.send_key( K_TAB, F_TIPODOC );
 | 
						||
      }
 | 
						||
      // Se per questa numerazione e' abilitata le numerazione provvisoria
 | 
						||
      if (cod_num.num_provv())
 | 
						||
      {
 | 
						||
        // Setta di default la numerazione provvisoria
 | 
						||
        m.set( F_PROVV, "P" );
 | 
						||
        // Abilita il campo per la selezione della numerazione
 | 
						||
        m.enable( F_PROVV );
 | 
						||
      }
 | 
						||
      else // Altrimenti ...
 | 
						||
      {
 | 
						||
        // Setta la numerazione a definitiva
 | 
						||
        m.set( F_PROVV, "D" );
 | 
						||
        // Disabilita il campo per la selezione della numerazione
 | 
						||
        m.disable( F_PROVV );
 | 
						||
      }
 | 
						||
    }
 | 
						||
    else
 | 
						||
    {
 | 
						||
      m.set( F_DESNUM, "" );
 | 
						||
      m.set( F_TIPODOC, "" );
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::tip_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  TDocumento_mask& m = (TDocumento_mask&)f.mask( );
 | 
						||
  if ( key == K_TAB && m.is_running() && m.get(F_TIPODOC).not_empty())
 | 
						||
  {
 | 
						||
    TCodice_numerazione cod_num(m.get(F_CODNUM));
 | 
						||
    const TString& tipo = f.get();
 | 
						||
    int last = cod_num.ntipi_doc();
 | 
						||
    for (int i = 0; i < last; i++ )
 | 
						||
    {
 | 
						||
      const TString16 curtipo(cod_num.tipo_doc(i));
 | 
						||
      if (curtipo == tipo)
 | 
						||
        return TRUE;
 | 
						||
    }
 | 
						||
    return f.error_box( "Tipo non valido per la numerazione selezionata!" );
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::codlist_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    TLocalisamfile & list = ((TEdit_field &) f).browse()->cursor()->file();
 | 
						||
    const TDate datadoc(f.mask().get(F_DATADOC));
 | 
						||
    const TDate datascad(list.get_date("VALFIN"));
 | 
						||
    
 | 
						||
    if (datascad.ok() && datadoc > datascad)
 | 
						||
    {     
 | 
						||
      const TString16 codsucc(list.get("CODLISSUCC"));
 | 
						||
      
 | 
						||
      if (codsucc.empty())
 | 
						||
        return error_box("Listino scaduto il %s", datascad.string());
 | 
						||
      else    
 | 
						||
      {
 | 
						||
        f.set(codsucc);
 | 
						||
        f.set_focusdirty();
 | 
						||
        ((TEdit_field &)f).check();
 | 
						||
      }
 | 
						||
    }
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::codcont_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {            
 | 
						||
    TLocalisamfile & cont = ((TEdit_field &) f).browse()->cursor()->file();
 | 
						||
    const TDate datadoc(f.mask().get(F_DATADOC));
 | 
						||
    const TDate datascad(cont.get_date("VALFIN"));
 | 
						||
    
 | 
						||
    if (datascad.ok() && datadoc > datascad)
 | 
						||
      return error_box("Contratto scaduto il %s", datascad.string());
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::codcamp_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {
 | 
						||
    TLocalisamfile & camp = ((TEdit_field &) f).browse()->cursor()->file();
 | 
						||
    const TDate datadoc(f.mask().get(F_DATADOC));
 | 
						||
    const TDate datascad(camp.get_date("VALFIN"));
 | 
						||
    
 | 
						||
    if (datascad.ok() && datadoc > datascad)
 | 
						||
      return error_box("Offerta scaduta il %s", datascad.string());
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
/*
 | 
						||
bool TDocumento_mask::controeuro_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  TMask & m = f.mask();
 | 
						||
  
 | 
						||
  if (m.is_running() && key == K_SPACE)
 | 
						||
  {         
 | 
						||
    const real cambio_euro = TCurrency::get_euro_change();
 | 
						||
    const real val = cambio_euro / m.get_real(F_CAMBIO);
 | 
						||
    
 | 
						||
    m.set(F_CAMBIO, val);
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
*/
 | 
						||
bool TDocumento_mask::datacambio_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.mask().get(F_CAMBIO).empty())
 | 
						||
  {                                                                  
 | 
						||
    const TRectype & rec = cache().get("%VAL", f.mask().get(F_CODVAL1));
 | 
						||
    real c = rec.get_real("S4");
 | 
						||
    f.mask().set(F_CAMBIO, c);
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
}
 | 
						||
 | 
						||
bool TDocumento_mask::codval_handler( TMask_field& f, KEY key )
 | 
						||
{
 | 
						||
  if (key == K_TAB && f.focusdirty())
 | 
						||
  {                 
 | 
						||
    TMask& m = f.mask();
 | 
						||
    
 | 
						||
    // Cerco un cambio per la data specificata, se non lo trovo lo invento
 | 
						||
    TDate datacam = m.get(F_DATACAMBIO);
 | 
						||
    if (!datacam.ok())
 | 
						||
    {
 | 
						||
      datacam = m.get_date(F_DATADOC);
 | 
						||
      m.set(F_DATACAMBIO, datacam);
 | 
						||
    }
 | 
						||
    TExchange exc(f.get());
 | 
						||
    exchange_type et;
 | 
						||
    real cambio = exc.get_change(et); // Determino il cambio standard ed il "Contro-Euro"
 | 
						||
    TString16 key;
 | 
						||
    key.format("%-3s", (const char*)f.get()); key << datacam.string(ANSI);
 | 
						||
    const real giornaliero = cache().get("CAM", key, "S4");
 | 
						||
    if (!giornaliero.is_zero())
 | 
						||
      cambio = giornaliero; // Ho trovato un cambio per il giorno!
 | 
						||
    m.set(F_CAMBIO, cambio);
 | 
						||
    m.set(F_CONTROEURO, et == _exchange_contro ? "X" : "");
 | 
						||
  
 | 
						||
    TSheet_field& righe = m.sfield(F_SHEET);
 | 
						||
    righe.force_update();
 | 
						||
  }
 | 
						||
  return TRUE;
 | 
						||
} |