Files correlati : ve6.exe Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 979 git-svn-id: svn://10.65.10.50/trunk@15623 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			767 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			767 lines
		
	
	
		
			21 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <colmask.h>
 | 
						|
#include <execp.h>
 | 
						|
#include <tabutil.h>
 | 
						|
#include <utility.h>
 | 
						|
#include <urldefid.h>
 | 
						|
 | 
						|
#include "ve0100.h"
 | 
						|
#include "veini.h"
 | 
						|
 | 
						|
#include "vepriv.h"
 | 
						|
#include "veuml.h"
 | 
						|
#include "veuml1.h"
 | 
						|
#include "verig.h"
 | 
						|
 | 
						|
#include "sconti.h"
 | 
						|
#include "../mg/anamag.h"
 | 
						|
#include "../mg/mglib.h"
 | 
						|
 | 
						|
TCursor& TMotore_application::get_filtered_cursor() const
 | 
						|
{
 | 
						|
  const TEdit_field& f = _msk->efield(F_NDOC);
 | 
						|
  return *f.browse()->cursor();
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::save_and_new() const
 | 
						|
{
 | 
						|
	TDocumento_mask & m = *_docmsk;
 | 
						|
  bool new_doc = false;
 | 
						|
	
 | 
						|
	if (m.insert_mode())
 | 
						|
	{
 | 
						|
		TDocumento & doc = m.doc();
 | 
						|
		new_doc = doc.codice_numerazione().save_and_new();
 | 
						|
		
 | 
						|
		if (new_doc && doc.tipo().printable() && yesno_box("Devo stampare il documento"))
 | 
						|
		{
 | 
						|
			const char s[2] = { doc.tipo().stato_finale_stampa(), '\0' };
 | 
						|
 | 
						|
			app()._print_directly = true;
 | 
						|
			app().print();
 | 
						|
			app()._print_directly= false;
 | 
						|
			m.set(F_STATO, s, TRUE);
 | 
						|
			doc.read();
 | 
						|
			doc.put(DOC_STATO, s);
 | 
						|
			doc.rewrite();
 | 
						|
		}
 | 
						|
	}
 | 
						|
  
 | 
						|
  return new_doc;
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::init_query_mode( TMask& m )
 | 
						|
{
 | 
						|
  disable_menu_item(M_FILE_PRINT);
 | 
						|
 | 
						|
  TEdit_field& cn = _msk->efield(F_CODNUM);
 | 
						|
  if (cn.empty())
 | 
						|
  {
 | 
						|
    cn.set(_codnum);
 | 
						|
    if (_msk->field(F_TIPODOC).empty())
 | 
						|
    {
 | 
						|
      cn.set_focusdirty(TRUE);
 | 
						|
      cn.on_key(K_TAB);
 | 
						|
      cn.set_dirty(FALSE);
 | 
						|
      _msk->set(F_TIPODOC, _tipodoc, TRUE);
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::init_insert_mode( TMask& m )
 | 
						|
{
 | 
						|
  TString4 codnum(m.get(F_CODNUM));
 | 
						|
	
 | 
						|
	if (codnum.empty())
 | 
						|
	{
 | 
						|
		TMask * query_mask = get_mask(MODE_QUERY);
 | 
						|
 | 
						|
	  codnum = query_mask->get(F_CODNUM);
 | 
						|
	  m.set(F_CODNUM, codnum);
 | 
						|
	  m.set(F_TIPODOC, query_mask->get(F_TIPODOC));
 | 
						|
	  m.set(F_ANNO, query_mask->get_int(F_ANNO));
 | 
						|
	  m.set(F_PROVV, query_mask->get(F_PROVV));
 | 
						|
	}
 | 
						|
 | 
						|
	const int anno = m.get_int(F_ANNO);
 | 
						|
  const char provv = m.get(F_PROVV)[0];
 | 
						|
  const long numdoc = m.get_long(F_NDOC);
 | 
						|
  TDocumento_mask& dm = (TDocumento_mask&)m;
 | 
						|
  TDocumento& curdo = dm.doc();
 | 
						|
 | 
						|
  curdo.read(provv, anno, codnum, numdoc);
 | 
						|
  curdo.set_tipo(m.get(F_TIPODOC));
 | 
						|
 | 
						|
  const TTipo_documento& tp = (const TTipo_documento&)curdo.tipo();
 | 
						|
 | 
						|
  const char stato = tp.stato_finale_inserimento();
 | 
						|
  curdo.stato(stato);
 | 
						|
 | 
						|
  _codnum = codnum;
 | 
						|
  _tipodoc = m.get(F_TIPODOC);
 | 
						|
 | 
						|
  m.field(F_CODNUM).set_focusdirty(TRUE);
 | 
						|
  m.field(F_CODNUM).on_key(K_TAB);
 | 
						|
  m.field(F_TIPODOC).set_focusdirty(TRUE);
 | 
						|
  m.field(F_TIPODOC).on_key(K_TAB);
 | 
						|
 | 
						|
  // Giro per supplire alla mancanza di una TMask::set(short id, char c);
 | 
						|
  char str_stato[2] = { stato, '\0' }; 
 | 
						|
  m.set(F_STATO, str_stato);
 | 
						|
  
 | 
						|
  TLocalisamfile doc(LF_DOC);
 | 
						|
  TDate data_doc(TODAY);
 | 
						|
  
 | 
						|
  doc.curr() = curdo.head();
 | 
						|
 | 
						|
	if (!m.field(F_DATADOC).automagic())
 | 
						|
	{
 | 
						|
		doc.read(_isgteq);
 | 
						|
		if (doc.eof() || doc.prev() == NOERR)
 | 
						|
		{                       
 | 
						|
			if (doc.curr().same_key(curdo.head(), 1, 1))
 | 
						|
				data_doc = doc.get_date(DOC_DATADOC);
 | 
						|
		}  
 | 
						|
	}
 | 
						|
  m.set(F_DATADOC, data_doc);
 | 
						|
  
 | 
						|
  int pos = m.id2pos( F_DATACAMBIO1);
 | 
						|
  if (pos >= 0 && m.fld(pos).active() && !m.get(F_CODVAL).empty())
 | 
						|
  {
 | 
						|
    m.fld(pos).set(data_doc);
 | 
						|
    m.fld(pos).dirty();
 | 
						|
  }
 | 
						|
  m.disable(DLG_PRINT);
 | 
						|
 | 
						|
  pos = m.id2pos(F_CAUSMAG);         
 | 
						|
  if (pos >= 0)
 | 
						|
  {
 | 
						|
    m.fld(pos).set(tp.caus_mov());
 | 
						|
    m.fld(pos).dirty();
 | 
						|
  }
 | 
						|
 | 
						|
  tp.set_defaults(m);
 | 
						|
  
 | 
						|
  m.disable(DLG_ELABORA);
 | 
						|
 | 
						|
  if (curdo.tipo().auto_add())
 | 
						|
	{
 | 
						|
    TSheet_field& ss = dm.sfield(F_SHEET);
 | 
						|
		for (int i = 0; i < 10; i++)
 | 
						|
      ss.insert(-1, false, true);
 | 
						|
	}
 | 
						|
 | 
						|
  dm.mask2doc();
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::init_modify_mode( TMask& m )
 | 
						|
{             
 | 
						|
	const bool enable_print = edit_mask().doc().tipo().printable();
 | 
						|
  enable_menu_item(M_FILE_PRINT, enable_print);
 | 
						|
  m.enable(DLG_PRINT, enable_print);
 | 
						|
  m.enable(DLG_ELABORA); 
 | 
						|
  m.disable(F_STATO);
 | 
						|
  TString80 key;
 | 
						|
  key << m.get(F_CODNUM);
 | 
						|
  key << m.get(F_ANNO);
 | 
						|
  key << m.get(F_PROVV);
 | 
						|
  key << m.get(F_NDOC);
 | 
						|
 | 
						|
  // Non dare messaggi inutili durante la cancellazione automatica
 | 
						|
  if (autodeleting() != 0x3) 
 | 
						|
  {     
 | 
						|
    const bool transaction = is_transaction();
 | 
						|
    const bool no_mod = !transaction && !doc().modificabile();
 | 
						|
    const bool no_del = !doc().cancellabile();
 | 
						|
    if (no_del || no_mod)
 | 
						|
    {
 | 
						|
      if (key != __last_key)
 | 
						|
      { 
 | 
						|
        TString msg;
 | 
						|
        msg.format("Documento non %s%s%s.", (no_mod ? "modificabile":""), 
 | 
						|
                   (no_mod && no_del ? " ne' ":""), (no_del ? "cancellabile":""));
 | 
						|
        if (transaction)
 | 
						|
        {
 | 
						|
          TTimed_box box("Attenzione", msg, 5, DLG_OK, 32, 5); 
 | 
						|
 | 
						|
          box.add_button(DLG_OK, 0, "", -11, -1, 10, 2);
 | 
						|
          box.run();
 | 
						|
        }
 | 
						|
        else
 | 
						|
          warning_box(msg);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    if (no_mod)
 | 
						|
      m.disable(DLG_SAVEREC);
 | 
						|
    if (no_del)
 | 
						|
      m.disable(DLG_DELREC);
 | 
						|
 | 
						|
    if (m.id2pos(F_IBAN_STATO) > 0)
 | 
						|
      m.efield(F_IBAN_STATO).validate(K_TAB); // Decodifica IBAN
 | 
						|
  }   
 | 
						|
  __last_key = key;
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::user_function(int index)
 | 
						|
{
 | 
						|
  switch(index)
 | 
						|
  {
 | 
						|
    case 1:
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      yesnofatal_box("Chiamata ad una procedura utente non definita: %d", index);
 | 
						|
      return NOERR;
 | 
						|
      break;
 | 
						|
  }
 | 
						|
  return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::changing_mask( int mode )
 | 
						|
{
 | 
						|
  static int lastmode = NO_MODE;
 | 
						|
 | 
						|
  const bool change = ( mode != lastmode );
 | 
						|
  lastmode = mode;
 | 
						|
  return change;
 | 
						|
}
 | 
						|
 | 
						|
TMask* TMotore_application::get_mask( int mode )
 | 
						|
{
 | 
						|
  if (mode != MODE_INS && mode != MODE_MOD)
 | 
						|
    return _msk;
 | 
						|
 | 
						|
  TString4 tipodoc = _msk->get(F_TIPODOC); // Prendo il tipo documento dalla maschera di query;
 | 
						|
  if (mode == MODE_MOD)
 | 
						|
    tipodoc = get_relation()->curr().get(DOC_TIPODOC); // Lo prendo dalla relazione (Gelai)
 | 
						|
 | 
						|
  _docmsk = (TDocumento_mask*)_doc_masks.objptr(tipodoc);
 | 
						|
  if (_docmsk == NULL)
 | 
						|
  {
 | 
						|
    _docmsk = new TDocumento_mask(tipodoc); 
 | 
						|
    _doc_masks.add(tipodoc, _docmsk);
 | 
						|
  }
 | 
						|
 | 
						|
  return _docmsk;
 | 
						|
}
 | 
						|
 | 
						|
const char* TMotore_application::get_next_key( )
 | 
						|
{
 | 
						|
  TMask& m = curr_mask( );
 | 
						|
  TCodice_numerazione cod_num(m.get(F_CODNUM));
 | 
						|
  
 | 
						|
  // Se per questa numerazione h abilitata le numerazione automatica
 | 
						|
  if( cod_num.auto_num())
 | 
						|
  {
 | 
						|
    TLocalisamfile doc(LF_DOC);
 | 
						|
    doc.zero();
 | 
						|
    doc.put("CODNUM", cod_num.codice());
 | 
						|
    doc.put("ANNO", m.get(F_ANNO));
 | 
						|
    doc.put("PROVV", m.get(F_PROVV));
 | 
						|
 | 
						|
    TRectype cmp_rec(doc.curr());   // record campione
 | 
						|
 | 
						|
    doc.put( "NDOC", 9999999L );
 | 
						|
    if (doc.read(_isgreat) == NOERR)
 | 
						|
      doc.prev();
 | 
						|
    else
 | 
						|
      doc.last();
 | 
						|
 | 
						|
    const long num = ((doc.curr() == cmp_rec) ? doc.get_long( "NDOC" ) : 0) + 1;
 | 
						|
 | 
						|
    return (format( "%d|%ld", F_NDOC, num));
 | 
						|
  }
 | 
						|
  return "";
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::read( TMask& m )
 | 
						|
{
 | 
						|
  TRelation_application::read(m);
 | 
						|
 | 
						|
  doc() = (TDocumento &)_rel->curr();
 | 
						|
  _codnum = m.get(F_CODNUM);
 | 
						|
  _tipodoc = m.get(F_TIPODOC);
 | 
						|
 | 
						|
  ((TDocumento_mask &)m).doc2mask();
 | 
						|
  COLOR high_back_color = _sel_color->get_back_color(_link_pos);
 | 
						|
  COLOR high_color = _sel_color->get_fore_color(_link_pos);
 | 
						|
  
 | 
						|
  ((TDocumento_mask &)m).highlight(high_back_color, high_color);
 | 
						|
 | 
						|
  return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::menu(MENU_TAG mt)
 | 
						|
{             
 | 
						|
  bool ok = TRUE;
 | 
						|
  if (mt == MENU_ITEM(1))
 | 
						|
  {
 | 
						|
    _sel_color->run();
 | 
						|
    COLOR high_back_color = _sel_color->get_back_color(_link_pos);
 | 
						|
    COLOR high_color = _sel_color->get_fore_color(_link_pos);
 | 
						|
  
 | 
						|
    if (!query_mask().is_running())
 | 
						|
    {
 | 
						|
      TDocumento_mask * m = (TDocumento_mask * ) &edit_mask();
 | 
						|
    
 | 
						|
      if (m != NULL)
 | 
						|
        m->highlight(high_back_color, high_color);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  else
 | 
						|
    ok = TRelation_application::menu(mt);
 | 
						|
  return ok;  
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::write( const TMask& m )  // C 90
 | 
						|
{          
 | 
						|
  TDocumento& d = (TDocumento&)_rel->curr();
 | 
						|
  d = ((TDocumento_mask&)m).doc(); // Trasferisce il documento da maschera a record
 | 
						|
 | 
						|
  // Se ho attivato la creazione automatica delle righe allora cancello quelle vuote finali
 | 
						|
  if (d.tipo().auto_add())
 | 
						|
  {
 | 
						|
    for (int r = d.rows(); r > 0; r--) 
 | 
						|
    {
 | 
						|
      const TRiga_documento& dr = d[r];
 | 
						|
      if (dr.get(RDOC_CODART).empty() && dr.get(RDOC_DESCR).empty())
 | 
						|
        d.destroy_row(r);
 | 
						|
      else
 | 
						|
        break;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
  return TRelation_application::write(m);
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::rewrite( const TMask& m ) // C 90
 | 
						|
{
 | 
						|
  TDocumento& d = (TDocumento &) _rel->curr();
 | 
						|
  if (d.bloccato())
 | 
						|
    return NOERR;
 | 
						|
  d = ((TDocumento_mask&)m).doc(); // Trasferisce il documento da maschera a record
 | 
						|
  return TRelation_application::rewrite(m);
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::on_firm_change()
 | 
						|
{
 | 
						|
  if (_config_ditta != NULL)
 | 
						|
    delete _config_ditta;
 | 
						|
  _config_ditta = new TConfig(CONFIG_DITTA);
 | 
						|
  _doc_masks.destroy();
 | 
						|
  TRelation_application::on_firm_change();
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::user_create( )
 | 
						|
{
 | 
						|
   open_files(LF_DOC, LF_RIGHEDOC, LF_CONDV, LF_RCONDV, LF_ANAMAG, LF_SCONTI, LF_UMART, LF_DESLIN, LF_CODCORR,
 | 
						|
             LF_TAB, LF_TABCOM, LF_CLIFO, LF_CFVEN, LF_INDSP, LF_OCCAS, LF_PCON, LF_MOV, LF_STOMAG, 
 | 
						|
             LF_MOVMAG, LF_RMOVMAG, LF_MAG, LF_SVRIEP, LF_AGENTI, LF_PERCPROV, LF_ATTIV, LF_CAUSALI, 0);
 | 
						|
  
 | 
						|
 | 
						|
  _config_ditta = new TConfig(CONFIG_DITTA);
 | 
						|
                                                          
 | 
						|
  // Metto in relazione testata e righe
 | 
						|
  _rel = new TRelation( LF_DOC );
 | 
						|
  _rel->lfile().set_curr(new TDocumento);
 | 
						|
 | 
						|
  _msk = new TMask("ve0100a");
 | 
						|
  _sel_color = new TSelect_color_mask("ve0100a", "0");
 | 
						|
  set_search_field(F_NDOC);
 | 
						|
  _link_pos =_sel_color->add_color_def("LINKED", "Righe collegate a documento", COLOR_YELLOW, COLOR_BLACK);
 | 
						|
 | 
						|
  _msk->set_handler( F_ANNO, TDocumento_mask::anno_handler );
 | 
						|
  _msk->set_handler( F_CODNUM, TDocumento_mask::num_handler );
 | 
						|
  _msk->set_handler( F_TIPODOC, TDocumento_mask::tip_handler );
 | 
						|
  _msk->set_handler( F_NUMDOCRIF, TDocumento_mask::numdocrif_search_handler );
 | 
						|
  _msk->set_handler( F_RAGSOCSEARCH, TDocumento_mask::ragsoc_search_handler );
 | 
						|
  
 | 
						|
  TConfig utente( CONFIG_USER );
 | 
						|
  _codnum = utente.get("CODNUM");
 | 
						|
  _tipodoc = utente.get("TIPODOC");
 | 
						|
  
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::user_destroy( )
 | 
						|
{
 | 
						|
  // Registro l'ultimo tipo documento e l'ultima numerazione
 | 
						|
  TConfig utente( CONFIG_USER );
 | 
						|
  utente.set( "CODNUM", _codnum, "ve" );
 | 
						|
  utente.set( "TIPODOC", _tipodoc, "ve" );
 | 
						|
 | 
						|
  if (_config_ditta != NULL)
 | 
						|
    delete _config_ditta;
 | 
						|
  // Distruggo la maschera di modifica
 | 
						|
  if ( _msk != NULL )
 | 
						|
    delete _msk;
 | 
						|
 | 
						|
  if ( _sel_color != NULL )
 | 
						|
    delete _sel_color;
 | 
						|
 | 
						|
  // Distruggo la relazione
 | 
						|
  delete _rel;
 | 
						|
//  delete _condv;
 | 
						|
 | 
						|
  return TRUE;
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::stato_corrente( )
 | 
						|
{
 | 
						|
  return edit_mask().get_int(F_STATO);
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::sheet2ini(TSheet_field &sheet,TConfig& ini)
 | 
						|
{
 | 
						|
  // scrive le righe degli sheet associati
 | 
						|
  TString16 defpar;
 | 
						|
  TString str(80);
 | 
						|
  TDocumento_mask &m = (TDocumento_mask &)sheet.mask();
 | 
						|
  int r;
 | 
						|
  
 | 
						|
  for (r = 1; r <= sheet.items(); r++)
 | 
						|
  {
 | 
						|
    defpar.format("%d,%d",LF_RIGHEDOC,r);
 | 
						|
    const TMask * sm = m.riga_mask(r-1);
 | 
						|
    const TToken_string rigar = sheet.row(r-1);
 | 
						|
    for (int sf = 0; sf < sm->fields(); sf++)
 | 
						|
    {
 | 
						|
      TMask_field& campo = sm->fld(sf);
 | 
						|
      if (campo.shown() && campo.field())
 | 
						|
      {
 | 
						|
        // str = sheet.row(r-1).get(sheet.cid2index(campo.dlg()));
 | 
						|
        const short id = campo.dlg();
 | 
						|
        rigar.get(sheet.cid2index(id), str);
 | 
						|
        if (str.empty()) 
 | 
						|
          str = " ";
 | 
						|
        const word field_class = campo.class_id();
 | 
						|
        if (field_class == CLASS_MEMO_FIELD || 
 | 
						|
            field_class == CLASS_ZOOM_FIELD)
 | 
						|
        {             
 | 
						|
          int p;
 | 
						|
          while ((p = str.find('\n', 0)) >= 0)
 | 
						|
          {
 | 
						|
            str.overwrite("\\", p);
 | 
						|
            str.insert("n", p+1);
 | 
						|
          }  
 | 
						|
        }  
 | 
						|
				if (campo.field()->name() == RDOC_PREZZO)
 | 
						|
				{
 | 
						|
					TCodiceIVA c(sm->get(FR_CODIVA));
 | 
						|
					TFieldref l;
 | 
						|
					real prezzo(str);
 | 
						|
					real prezzol;
 | 
						|
 | 
						|
					l = RDOC_PREZZOL;
 | 
						|
					if (m.doc().tipo().calcolo_lordo())
 | 
						|
					{
 | 
						|
						prezzol = prezzo;
 | 
						|
						c.scorpora(prezzo);
 | 
						|
					}
 | 
						|
					else
 | 
						|
						prezzol = c.lordo(prezzo);
 | 
						|
					l.write(ini, defpar, prezzol.string());
 | 
						|
					str = prezzo.string();
 | 
						|
				}
 | 
						|
				campo.field()->write(ini, defpar, str);
 | 
						|
      } 
 | 
						|
			const TRiga_documento &rdoc = m.doc()[r];
 | 
						|
			TFieldref f;
 | 
						|
 | 
						|
			f = RDOC_DACODNUM;
 | 
						|
			f.write(ini, defpar, rdoc.get(RDOC_DACODNUM));
 | 
						|
			f = RDOC_DAANNO;
 | 
						|
			f.write(ini, defpar, rdoc.get(RDOC_DAANNO));
 | 
						|
			f = RDOC_DAPROVV;
 | 
						|
			f.write(ini, defpar, rdoc.get(RDOC_DAPROVV));
 | 
						|
			f = RDOC_DANDOC;
 | 
						|
			f.write(ini, defpar, rdoc.get(RDOC_DANDOC));
 | 
						|
			f = RDOC_DAIDRIGA;
 | 
						|
			f.write(ini, defpar, rdoc.get(RDOC_DAIDRIGA));
 | 
						|
    } 
 | 
						|
  } 
 | 
						|
  for ( ; ; r++)
 | 
						|
  {
 | 
						|
    defpar.format("%d,%d",LF_RIGHEDOC,r);
 | 
						|
    if (ini.set_paragraph(defpar))
 | 
						|
      ini.remove_all();
 | 
						|
    else
 | 
						|
      break;  
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::ini2mask(TConfig& ini, TMask& msk, bool query)
 | 
						|
{
 | 
						|
  TRelation_application::ini2mask(ini, msk, query); // Default processing
 | 
						|
 | 
						|
  if (query)
 | 
						|
  {     
 | 
						|
    // Dobbiamo riempire il tipo documento per determinare il profilo corretto!     
 | 
						|
    TMask_field& campo = msk.field(F_TIPODOC);
 | 
						|
    TString16 str = campo.field()->read(ini, format("%d", LF_DOC));
 | 
						|
    if (str.empty())
 | 
						|
    {
 | 
						|
      TToken_string key;
 | 
						|
      key.add(msk.get(F_PROVV));
 | 
						|
      key.add(msk.get(F_ANNO));
 | 
						|
      key.add(msk.get(F_CODNUM));
 | 
						|
      key.add(msk.get(F_NDOC));
 | 
						|
      str = cache().get(LF_DOC, key, DOC_TIPODOC);
 | 
						|
    }
 | 
						|
    campo.set(str);
 | 
						|
      
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
		TDocumento & d = doc();
 | 
						|
 | 
						|
		d.put(DOC_TIPOCF, msk.get(F_TIPOCF));
 | 
						|
		d.put(DOC_CODCF, msk.get(F_CODCF));
 | 
						|
 | 
						|
		const TCli_for & c = d.clifor(); 
 | 
						|
	  const TRectype & ven_rec = c.vendite();
 | 
						|
 | 
						|
		ini.set_paragraph("33");
 | 
						|
 | 
						|
    if (!ini.exist(DOC_CODVAL))
 | 
						|
		{
 | 
						|
		  const TString4 codval = c.get(CLI_CODVAL);  // Attenzione: Non usare TString& qui!
 | 
						|
      msk.set(F_CODVAL, codval, true);
 | 
						|
      msk.set(F_CODVAL1, codval, true);
 | 
						|
			if (codval.blank())
 | 
						|
				msk.reset(F_CAMBIO);  
 | 
						|
		}
 | 
						|
    if (!ini.exist(DOC_CODLIN))
 | 
						|
      msk.set(F_CODLIN, c.get(CLI_CODLIN), true);
 | 
						|
    if (!ini.exist(DOC_CODPAG))
 | 
						|
			msk.set(F_CODPAG, c.get(CLI_CODPAG), true);
 | 
						|
    if (!ini.exist(DOC_CODABIA))
 | 
						|
	    msk.set(F_CODABIA, c.get(CLI_CODABI), true);
 | 
						|
    if (!ini.exist(DOC_CODCABA))
 | 
						|
		  msk.set(F_CODCABA, c.get(CLI_CODCAB), true);
 | 
						|
    if (!ini.exist(DOC_IBAN))
 | 
						|
    {
 | 
						|
      const TString & iban = c.get(CLI_IBAN);
 | 
						|
 | 
						|
      msk.set(F_IBAN, iban, true);
 | 
						|
      if (iban.not_empty())
 | 
						|
      {
 | 
						|
        msk.set(F_IBAN_STATO, iban.left(2));
 | 
						|
        msk.set(F_IBAN_CHECK, iban.mid(2,2));
 | 
						|
        msk.set(F_BBAN      , iban.mid(4));
 | 
						|
        msk.set(F_BBAN_CIN  , iban.mid(4,1));
 | 
						|
        msk.set(F_BBAN_ABI  , iban.mid(5,5));
 | 
						|
        msk.set(F_BBAN_CAB  , iban.mid(10,5));
 | 
						|
        msk.set(F_BBAN_CONTO, iban.mid(15,12));
 | 
						|
      }
 | 
						|
    }
 | 
						|
    // Setta i campi che appartengono al file LF_CFVEN
 | 
						|
    if (!ini.exist(DOC_CODABIP))
 | 
						|
			msk.set(F_CODABIP, ven_rec.get(CFV_CODABIPR), true);
 | 
						|
    if (!ini.exist(DOC_CODCABP))
 | 
						|
	    msk.set(F_CODCABP, ven_rec.get(CFV_CODCABPR), true);
 | 
						|
    if (!ini.exist(DOC_RAGGR))
 | 
						|
	    msk.set(F_RAGGR, ven_rec.get(CFV_RAGGDOC));
 | 
						|
    if (!ini.exist(DOC_RAGGREFF))
 | 
						|
	    msk.set(F_RAGGREFF, ven_rec.get(CFV_RAGGEFF));
 | 
						|
    if (!ini.exist(DOC_CODINDSP))
 | 
						|
	    msk.set(F_CODINDSP, ven_rec.get(CFV_CODINDSP), true);
 | 
						|
    if (!ini.exist(DOC_CODAG))
 | 
						|
			msk.set(F_CODAG, ven_rec.get(CFV_CODAG));
 | 
						|
    if (!ini.exist(DOC_CODSPMEZZO))
 | 
						|
			msk.set(F_CODSPMEZZO, ven_rec.get(CFV_CODSPMEZZO), true);
 | 
						|
    if (!ini.exist(DOC_CODPORTO))
 | 
						|
	    msk.set(F_CODPORTO, ven_rec.get(CFV_CODPORTO), true);
 | 
						|
    if (!ini.exist(DOC_CODNOTESP1))
 | 
						|
			msk.set(F_CODNOTESP1, ven_rec.get(CFV_CODNOTESP1), true);
 | 
						|
    if (!ini.exist(DOC_CODNOTESP2))
 | 
						|
			msk.set(F_CODNOTESP2, ven_rec.get(CFV_CODNOTESP2), true);
 | 
						|
    if (!ini.exist(DOC_CODNOTE))
 | 
						|
			msk.set(F_CODNOTE, ven_rec.get(CFV_CODNOTE), true);
 | 
						|
    if (!ini.exist(DOC_CODVETT1))
 | 
						|
			msk.set(F_CODVETT1, ven_rec.get(CFV_CODVETT1), true);
 | 
						|
    if (!ini.exist(DOC_CODVETT2))
 | 
						|
			msk.set(F_CODVETT2, ven_rec.get(CFV_CODVETT2), true);
 | 
						|
    if (!ini.exist(DOC_CODVETT3))
 | 
						|
			msk.set(F_CODVETT3, ven_rec.get(CFV_CODVETT3), true);
 | 
						|
    if (!ini.exist(DOC_PERCSPINC))
 | 
						|
			msk.set(F_SPESEINC, ven_rec.get(CFV_PERCSPINC));  
 | 
						|
    if (!ini.exist(DOC_ADDBOLLI))
 | 
						|
			msk.set(F_ADDBOLLI, ven_rec.get(CFV_ADDBOLLI));
 | 
						|
    if (!ini.exist(DOC_CATVEN))
 | 
						|
			msk.set(F_CATVEN, ven_rec.get(CFV_CATVEN), false);
 | 
						|
    if (!ini.exist(DOC_ZONA))
 | 
						|
			msk.set(F_CODZON, ven_rec.get(CFV_CODZONA), true);
 | 
						|
    if (!ini.exist(DOC_CODLIST))
 | 
						|
		{
 | 
						|
	    const TString16 codlist = ven_rec.get(CFV_CODLIST);
 | 
						|
	    
 | 
						|
			msk.set(F_CODLIST, codlist, true);              
 | 
						|
			msk.set(F_CODLIST1, codlist, true);              
 | 
						|
		}
 | 
						|
  
 | 
						|
    TSheet_field& f = msk.sfield(F_SHEET);
 | 
						|
    
 | 
						|
    TTipo_riga_documento tr;
 | 
						|
 | 
						|
    // Scorre tutti i paragrafi delle righe documento
 | 
						|
    const TMaskmode oldmode= (TMaskmode)msk.mode();  
 | 
						|
 | 
						|
    msk.set_mode(MODE_MOD);  
 | 
						|
    for (int i = 1; ini.set_paragraph(format("%d,%d", LF_RIGHEDOC, i)); i++)
 | 
						|
    {                    
 | 
						|
      if (i == 1) // Se trovo almeno una riga allora cancello tutto, poi aggiungo le righe
 | 
						|
      {
 | 
						|
        f.destroy();
 | 
						|
        doc().destroy_rows(); 
 | 
						|
      }
 | 
						|
    
 | 
						|
      // Considera solo i tipi riga validi
 | 
						|
      const TString16 tipo(ini.get(RDOC_TIPORIGA));
 | 
						|
      if (tr.read(tipo) == NOERR)
 | 
						|
      {
 | 
						|
        // Crea una nuova riga documento
 | 
						|
        TRiga_documento& rec = doc().new_row(tipo);
 | 
						|
        // Riempie i campi della nuova riga
 | 
						|
        TAssoc_array& var = ini.list_variables();
 | 
						|
        FOR_EACH_ASSOC_STRING(var, obj, key, val)
 | 
						|
        {
 | 
						|
          if (*val == '"' || *val == '\'')
 | 
						|
          {
 | 
						|
            const int len = strlen(val);
 | 
						|
            *(char*)(val+len-1) = '\0';
 | 
						|
            val++;
 | 
						|
          }
 | 
						|
          
 | 
						|
          if (xvt_str_compare_ignoring_case(key, RDOC_DESCR) == 0)   // Trattamento speciale per la descrizione qui verificare
 | 
						|
          {
 | 
						|
            TString s = esc(val); s.rtrim();
 | 
						|
            int split_pos = s.find('\n');
 | 
						|
            const int descr_len = rec.length(RDOC_DESCR);
 | 
						|
            if (split_pos < 0 && s.len() > descr_len)
 | 
						|
              split_pos = descr_len;
 | 
						|
            if (split_pos > descr_len)
 | 
						|
              split_pos = descr_len;
 | 
						|
            if (split_pos > 0)
 | 
						|
            {
 | 
						|
              rec.put(RDOC_DESCR, s.left(split_pos));
 | 
						|
              rec.put(RDOC_DESCLUNGA, "X");
 | 
						|
              rec.put(RDOC_DESCEST, s.mid(split_pos));
 | 
						|
            }
 | 
						|
            else
 | 
						|
            {
 | 
						|
              rec.put(RDOC_DESCR, s);
 | 
						|
              rec.zero(RDOC_DESCLUNGA);
 | 
						|
              rec.zero(RDOC_DESCEST);
 | 
						|
            }
 | 
						|
    
 | 
						|
          }
 | 
						|
          else
 | 
						|
            if (xvt_str_compare_ignoring_case(key, RDOC_NRIGA) != 0)   // Ignora il numero riga ..
 | 
						|
              if (xvt_str_compare_ignoring_case(key, RDOC_TIPORIGA) != 0)   // ... ed il tipo riga
 | 
						|
                rec.put(key, val);        
 | 
						|
        }
 | 
						|
 | 
						|
        // solo la insert chiama la post_insert necessaria alla disabilitazione verifichiamo
 | 
						|
        // l'autoload ??
 | 
						|
        f.insert(-1, FALSE);
 | 
						|
        // Aggiunge la riga allo sheet
 | 
						|
        
 | 
						|
        const bool checked = rec.get_bool(RDOC_CHECKED);
 | 
						|
 | 
						|
        if (checked) 
 | 
						|
        {
 | 
						|
          const TString& codart = rec.get(RDOC_CODARTMAG);
 | 
						|
 | 
						|
          if (codart.full())
 | 
						|
          {
 | 
						|
            const TRectype& art = cache().get(LF_ANAMAG, codart);
 | 
						|
            if (art.empty())
 | 
						|
            {
 | 
						|
              error_box(FR("Articolo non valido sulla riga %d: %s"), i, (const char*)codart);
 | 
						|
              rec.zero(RDOC_CODARTMAG);
 | 
						|
            }
 | 
						|
          }
 | 
						|
        }
 | 
						|
				else
 | 
						|
				{
 | 
						|
					if (!ini.exist(RDOC_DESCR))
 | 
						|
					{
 | 
						|
						const TString& codart = rec.get(RDOC_CODARTMAG);
 | 
						|
						if (codart.full())
 | 
						|
						{
 | 
						|
							const TRectype& art = cache().get(LF_ANAMAG, codart);
 | 
						|
 | 
						|
              rec.put(RDOC_DESCR, art.get(ANAMAG_DESCR));
 | 
						|
							rec.put(RDOC_CODIVA, art.get(ANAMAG_CODIVA));
 | 
						|
						}
 | 
						|
						rec.put(RDOC_CHECKED, "X");
 | 
						|
					}
 | 
						|
				}
 | 
						|
 | 
						|
		    if (!ini.exist(RDOC_CODIVA) && !(rec.is_descrizione() || rec.is_sconto() || rec.is_sconto_perc()))
 | 
						|
				{
 | 
						|
					const TString4 codiva = ((TDocumento_mask &) msk).condv().clifo().vendite().get(CFV_ASSFIS);
 | 
						|
 | 
						|
					if (codiva.full())
 | 
						|
						rec.put(RDOC_CODIVA, codiva);
 | 
						|
				}
 | 
						|
        rec.autoload(f);
 | 
						|
        f.check_row(f.items() - 1, 0x2);
 | 
						|
 | 
						|
        if (!checked)     //se non e' checked, il record viene autosalvato (in modo che sia salvato completamente)
 | 
						|
          rec.autosave(f);
 | 
						|
      }
 | 
						|
    }
 | 
						|
    msk.set_mode(oldmode);  
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::print()
 | 
						|
{
 | 
						|
  if (_print_directly || save(false))   // Registra il record corrente
 | 
						|
  {
 | 
						|
    TDocumento& doc = (TDocumento&)get_relation()->curr();
 | 
						|
   
 | 
						|
    const TTipo_documento& tipo = doc.tipo();
 | 
						|
    TFilename rep; 
 | 
						|
    if (tipo.main_print_profile(rep))
 | 
						|
    {
 | 
						|
      const bool da_stampare = doc.stampabile();
 | 
						|
 | 
						|
      TString commandline;
 | 
						|
      if (rep.ends_with(".rep"))     
 | 
						|
        commandline = "ve1 -2";      // Esiste il nuovo report :-)
 | 
						|
      else                           
 | 
						|
        commandline = "ve1 -0";      // Esiste il vecchio form :-(
 | 
						|
    
 | 
						|
      commandline << ' ' << doc.get(DOC_CODNUM) << ' ' << doc.get(DOC_ANNO) << ' ';
 | 
						|
      commandline << doc.get(DOC_PROVV) << ' ' << doc.get(DOC_NDOC) << ' ' << doc.get(DOC_NDOC);
 | 
						|
      commandline << ' ' << (da_stampare ? 'D' : 'P');
 | 
						|
 | 
						|
      const int ncopie = tipo.ncopie();
 | 
						|
      if (ncopie > 0)
 | 
						|
        commandline << ' ' << ncopie;
 | 
						|
 
 | 
						|
      TExternal_app interattivo( commandline );
 | 
						|
      if (interattivo.run() == NOERR)
 | 
						|
      {
 | 
						|
        TDocumento_mask& m = edit_mask();
 | 
						|
        TDocumento& maindoc = m.doc();
 | 
						|
        maindoc.read(); // Aggiorna STATO e MOVMAG generati da ve1
 | 
						|
 | 
						|
        // Lo stato del documento vive di vita propria
 | 
						|
        const char sfs = maindoc.tipo().stato_finale_stampa();
 | 
						|
        maindoc.stato(sfs);
 | 
						|
        const char str_sfs[2] = { sfs, '\0' };
 | 
						|
        m.set(F_STATO, str_sfs, true);
 | 
						|
      }
 | 
						|
    }
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int ve0100( int argc, char* argv[])
 | 
						|
{
 | 
						|
  TMotore_application a;
 | 
						|
 | 
						|
  a.run( argc, argv, TR("Gestione documenti"));
 | 
						|
  return 0;
 | 
						|
} |