Files correlati : ve1.exe Ricompilazione Demo : [ ] Commento : Corretta stampa in duplice copia dei documenti, anche se non richiesta git-svn-id: svn://10.65.10.50/trunk@17808 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			986 lines
		
	
	
		
			25 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			986 lines
		
	
	
		
			25 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 "velib04.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 = edit_mask();
 | 
						|
  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(TR("Si desidera 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);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  TEdit_field& n = m.efield(F_NDOC);
 | 
						|
 | 
						|
	if (!n.empty())
 | 
						|
	{
 | 
						|
		if (find(0))
 | 
						|
			modify_mode();
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::init_insert_mode( TMask& m )
 | 
						|
{
 | 
						|
  TDocumento_mask& dm = (TDocumento_mask&)m;
 | 
						|
  TString4 codnum(m.get(F_CODNUM));
 | 
						|
	
 | 
						|
	dm.reset_father_rows();
 | 
						|
	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& curdo = dm.doc();
 | 
						|
 | 
						|
  curdo.read(provv, anno, codnum, numdoc);
 | 
						|
  curdo.set_tipo(m.get(F_TIPODOC));
 | 
						|
 | 
						|
  const TTipo_documento& tp = 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);
 | 
						|
  
 | 
						|
  TDate data_doc(TODAY);
 | 
						|
  const bool magic_datadoc = m.field(F_DATADOC).automagic();
 | 
						|
	if (!magic_datadoc)
 | 
						|
	{
 | 
						|
    long ndoc = 0; // unused
 | 
						|
    last_doc(provv, anno, codnum, ndoc, data_doc);
 | 
						|
	}
 | 
						|
  m.set(F_DATADOC, data_doc, 0x1);
 | 
						|
  
 | 
						|
  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();
 | 
						|
  }
 | 
						|
  
 | 
						|
 | 
						|
  pos = m.id2pos(F_CAUSMAG);         
 | 
						|
  if (pos >= 0)
 | 
						|
  {
 | 
						|
    m.fld(pos).set(tp.caus_mov());
 | 
						|
    m.fld(pos).dirty();
 | 
						|
  }
 | 
						|
 | 
						|
  tp.set_defaults(m);
 | 
						|
  
 | 
						|
  if (provv == 'P')
 | 
						|
		m.enable(DLG_CONFERMA);
 | 
						|
	else
 | 
						|
		m.disable(DLG_CONFERMA);
 | 
						|
		m.disable(DLG_PRINT);
 | 
						|
  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 )
 | 
						|
{             
 | 
						|
  TEdit_field& n = query_mask().efield(F_NDOC);
 | 
						|
 | 
						|
	n.set("");
 | 
						|
	n.update_flags("R");
 | 
						|
	const bool enable_print = edit_mask().doc().tipo().printable();
 | 
						|
	const TString4 provv = m.get(F_PROVV);
 | 
						|
  enable_menu_item(M_FILE_PRINT, provv == "D" && enable_print);
 | 
						|
  if (provv[0] == 'P')
 | 
						|
	{
 | 
						|
		m.disable(DLG_PRINT);
 | 
						|
		m.enable(DLG_CONFERMA);
 | 
						|
	}
 | 
						|
	else
 | 
						|
	{
 | 
						|
		m.disable(DLG_CONFERMA);
 | 
						|
	  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 << 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;
 | 
						|
}
 | 
						|
 | 
						|
// Cerca numero e data dell'ultimo documento di una numerazione di un anno
 | 
						|
bool TMotore_application::last_doc(char provv, int anno, const char* codnum,
 | 
						|
                                   long& ndoc, TDate& ddoc) const
 | 
						|
{
 | 
						|
  TRelation rel(LF_DOC);
 | 
						|
  TRectype& curr = rel.curr();
 | 
						|
  curr.put(DOC_PROVV, provv);
 | 
						|
  curr.put(DOC_ANNO, anno);
 | 
						|
	TString cod(codnum); cod.left_just(4, '~');
 | 
						|
  curr.put(DOC_CODNUM, cod);
 | 
						|
  TCursor cur(&rel, "", 1, &curr, &curr);
 | 
						|
  
 | 
						|
  TRecnotype docs = cur.items();
 | 
						|
  bool found = docs > 0;
 | 
						|
 | 
						|
	if (found)
 | 
						|
  {
 | 
						|
    cur = docs-1;
 | 
						|
    ndoc = curr.get_long(DOC_NDOC);
 | 
						|
  	ddoc = curr.get_date(DOC_DATADOC);
 | 
						|
  }
 | 
						|
  else
 | 
						|
  {
 | 
						|
    ndoc = 0;
 | 
						|
    const TDate oggi(TODAY);
 | 
						|
    if (anno < oggi.year())
 | 
						|
      ddoc = TDate(31, 12, anno);
 | 
						|
    else 
 | 
						|
      ddoc = oggi;
 | 
						|
  }
 | 
						|
  return found;
 | 
						|
}
 | 
						|
 | 
						|
const char* TMotore_application::get_next_key( )
 | 
						|
{
 | 
						|
  const TMask& m = curr_mask( );
 | 
						|
  const TCodice_numerazione cod_num(m.get(F_CODNUM));
 | 
						|
  
 | 
						|
  // Se per questa numerazione e' abilitata le numerazione automatica
 | 
						|
  if (cod_num.auto_num())
 | 
						|
  {
 | 
						|
    TDate ddoc; // unused
 | 
						|
    long ndoc = 1;
 | 
						|
    if (last_doc(m.get(F_PROVV)[0], m.get_int(F_ANNO), cod_num.codice(), ndoc, ddoc))
 | 
						|
      ndoc++;
 | 
						|
    else
 | 
						|
      ndoc = 1;
 | 
						|
    return format("%d|%ld", F_NDOC, ndoc);
 | 
						|
  }
 | 
						|
 | 
						|
  return "";
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::read( TMask& m )
 | 
						|
{
 | 
						|
	TDocumento_mask& mask = (TDocumento_mask&) m;
 | 
						|
  TRelation_application::read(m);
 | 
						|
 | 
						|
	mask.reset_father_rows();
 | 
						|
 | 
						|
 | 
						|
  doc() = (TDocumento &)_rel->curr();
 | 
						|
	mask.update_father_rows(false);
 | 
						|
 | 
						|
  _codnum = m.get(F_CODNUM);
 | 
						|
  _tipodoc = m.get(F_TIPODOC);
 | 
						|
 | 
						|
  mask.doc2mask();
 | 
						|
  COLOR high_back_color = _sel_color->get_back_color(_link_pos);
 | 
						|
  COLOR high_color = _sel_color->get_fore_color(_link_pos);
 | 
						|
  
 | 
						|
  mask.highlight(high_back_color, high_color);
 | 
						|
 | 
						|
  return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::menu(MENU_TAG mt)
 | 
						|
{             
 | 
						|
  bool ok = true;
 | 
						|
  if (mt == MENU_ITEM(1))
 | 
						|
  {
 | 
						|
    if (_sel_color->run() != K_ESC && _docmsk != NULL)
 | 
						|
		{
 | 
						|
			COLOR high_back_color = _sel_color->get_back_color(_link_pos);
 | 
						|
			COLOR high_color = _sel_color->get_fore_color(_link_pos);
 | 
						|
 			_docmsk->highlight(high_back_color, high_color);
 | 
						|
 | 
						|
		}
 | 
						|
  }
 | 
						|
  else
 | 
						|
    ok = TRelation_application::menu(mt);
 | 
						|
  return ok;  
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::write( const TMask& m )  // C 90
 | 
						|
{          
 | 
						|
	TDocumento_mask& mask = (TDocumento_mask&) m;
 | 
						|
  TDocumento& d = (TDocumento&)_rel->curr();
 | 
						|
  d = mask.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;
 | 
						|
    }
 | 
						|
  }
 | 
						|
 | 
						|
	const int err = TRelation_application::write(m);
 | 
						|
	
 | 
						|
	if (err == NOERR)
 | 
						|
	{
 | 
						|
		mask.update_father_rows();
 | 
						|
		mask.save_father_rows();
 | 
						|
	}
 | 
						|
	return err;
 | 
						|
}
 | 
						|
 | 
						|
int TMotore_application::rewrite( const TMask& m ) // C 90
 | 
						|
{
 | 
						|
  TDocumento& d = (TDocumento &) _rel->curr();
 | 
						|
	TDocumento_mask& mask = (TDocumento_mask&) m;
 | 
						|
 | 
						|
  if (d.bloccato())
 | 
						|
    return NOERR;
 | 
						|
  d = ((TDocumento_mask&)m).doc(); // Trasferisce il documento da maschera a record
 | 
						|
  const int err = TRelation_application::rewrite(m);
 | 
						|
	if (err == NOERR)
 | 
						|
	{
 | 
						|
		mask.update_father_rows();
 | 
						|
		mask.save_father_rows();
 | 
						|
	}
 | 
						|
	return err;
 | 
						|
}
 | 
						|
 | 
						|
bool TMotore_application::remove() // C 90
 | 
						|
{
 | 
						|
  const bool ok = TRelation_application::remove();
 | 
						|
	if (ok)
 | 
						|
		edit_mask().save_father_rows();
 | 
						|
	return ok;
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::on_firm_change()
 | 
						|
{
 | 
						|
  if (_config_ditta != NULL)
 | 
						|
    delete _config_ditta;
 | 
						|
  _config_ditta = new TConfig(CONFIG_DITTA);
 | 
						|
  _doc_masks.destroy();
 | 
						|
	load_auto_reopen_data();
 | 
						|
  TRelation_application::on_firm_change();
 | 
						|
}
 | 
						|
 | 
						|
void TMotore_application::load_auto_reopen_data()
 | 
						|
{
 | 
						|
	TAssoc_array & auto_reopen_nums = TDocumento_mask::auto_reopen_nums();
 | 
						|
	TAssoc_array & tipidoc_rels = TDocumento_mask::tipidoc_rels();
 | 
						|
	TTable num("%NUM");
 | 
						|
	TTable eld("%ELD");
 | 
						|
 | 
						|
	auto_reopen_nums.destroy();
 | 
						|
	tipidoc_rels.destroy();
 | 
						|
	for (int err = num.first(); err == NOERR; err = num.next())
 | 
						|
	{
 | 
						|
		if (num.get_bool("B7"))
 | 
						|
		{
 | 
						|
			const TString4 codnum = num.get("CODTAB");
 | 
						|
			TCodice_numerazione numeraz(codnum);
 | 
						|
			const int ntipidoc = numeraz.ntipi_doc();
 | 
						|
			TString_array tipi;
 | 
						|
 | 
						|
			for (int k = 0 ; k < ntipidoc; k++)
 | 
						|
				tipi.add(numeraz.tipo_doc(k));
 | 
						|
			auto_reopen_nums.add(codnum, codnum);
 | 
						|
			for (int err1 = eld.first(); err1 == NOERR; err1 = eld.next())
 | 
						|
			{
 | 
						|
				TCopia_documento e(eld.get("CODTAB"));
 | 
						|
				const TTipo_elaborazione tipo = e.tipo();
 | 
						|
 | 
						|
				if (tipo == _consegna_ordini ||
 | 
						|
            tipo == _consuntivazione_produzione)
 | 
						|
				{
 | 
						|
					const TString4 dest_tipo_doc = e.tipo_finale();
 | 
						|
					const char stato_finale = e.stato_finale_doc_iniziale()[0];
 | 
						|
  			
 | 
						|
 | 
						|
					for (int i = 0; i < 10; i++)
 | 
						|
					{
 | 
						|
						TToken_string key(e.tipo_iniziale(i));
 | 
						|
						if (key.blank())
 | 
						|
							break;
 | 
						|
						if (tipi.find(key) >= 0)
 | 
						|
						{
 | 
						|
							key.add(dest_tipo_doc);
 | 
						|
							tipidoc_rels.add(key, new TStati(e.stato_iniziale(i), stato_finale));
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
bool num_filter(const TRelation* r)
 | 
						|
{
 | 
						|
	const TCodice_numerazione & cod_num = cached_numerazione(r->curr().get("CODTAB"));
 | 
						|
 | 
						|
	int last = cod_num.ntipi_doc();
 | 
						|
	for (int i = 0; i < last; i++ )
 | 
						|
		if (tipodoc_ok(cod_num.tipo_doc(i)))
 | 
						|
			return true;
 | 
						|
	return false;
 | 
						|
}
 | 
						|
 | 
						|
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_NUMDOCRIF, TDocumento_mask::numdocrif_search_handler );
 | 
						|
  _msk->set_handler( F_RAGSOCSEARCH, TDocumento_mask::ragsoc_search_handler );
 | 
						|
 | 
						|
	const int args = argc() ;
 | 
						|
 | 
						|
	TEdit_field & e = _msk->efield(F_CODNUM);
 | 
						|
	TBrowse * b = e.browse();
 | 
						|
	TEdit_field & edes = _msk->efield(F_DESNUM);
 | 
						|
	TBrowse * bdes = edes.browse();	
 | 
						|
	TCursor * cur = b->cursor();
 | 
						|
	TCursor * descur = bdes->cursor();
 | 
						|
	
 | 
						|
	cur->set_filterfunction(num_filter);
 | 
						|
	descur->set_filterfunction(num_filter);
 | 
						|
 | 
						|
	for (int i = 2; i < args; i++)
 | 
						|
	{
 | 
						|
		const TString  arg(argv(i));
 | 
						|
 | 
						|
		if (arg.starts_with("-def"))
 | 
						|
		{
 | 
						|
			TToken_string str(arg.mid(4), ',');
 | 
						|
			const TString16 codnum(str.get());
 | 
						|
			const TString16 tipodoc(str.get());
 | 
						|
			const TString16 paragraph(str.get());
 | 
						|
 | 
						|
			if (paragraph.blank())
 | 
						|
			{
 | 
						|
				_codnum = codnum;
 | 
						|
				_tipodoc = tipodoc;
 | 
						|
			}
 | 
						|
			else
 | 
						|
			{
 | 
						|
				TConfig c(CONFIG_DITTA, paragraph);
 | 
						|
 | 
						|
				_codnum = c.get(codnum);
 | 
						|
				_tipodoc = c.get(tipodoc);
 | 
						|
			}
 | 
						|
		}
 | 
						|
		else
 | 
						|
			if (arg.starts_with("-filt"))
 | 
						|
			{
 | 
						|
				if (b != NULL || bdes != NULL)
 | 
						|
				{
 | 
						|
					TString filter = b->get_filter();
 | 
						|
 | 
						|
					if (filter.full())
 | 
						|
					{
 | 
						|
						filter.insert("(");
 | 
						|
						filter << ")&&(" << arg.mid(5) << ")";
 | 
						|
						if (b != NULL)
 | 
						|
							b->set_filter(filter);
 | 
						|
						if (bdes != NULL)
 | 
						|
							bdes->set_filter(filter);
 | 
						|
					}
 | 
						|
					else
 | 
						|
					{
 | 
						|
						const TString newfilter(arg.mid(5));
 | 
						|
 | 
						|
						if (b != NULL)
 | 
						|
							b->set_filter(newfilter);
 | 
						|
						if (bdes != NULL)
 | 
						|
							bdes->set_filter(newfilter);
 | 
						|
					}
 | 
						|
				}
 | 
						|
			}
 | 
						|
	}
 | 
						|
 
 | 
						|
	TConfig utente( CONFIG_USER );
 | 
						|
 | 
						|
	if (_codnum.blank())
 | 
						|
		_codnum = utente.get("CODNUM");
 | 
						|
	if (_tipodoc.blank())
 | 
						|
		_tipodoc = utente.get("TIPODOC");
 | 
						|
	_docmsk = NULL;
 | 
						|
 | 
						|
	load_auto_reopen_data();
 | 
						|
 | 
						|
  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).doc().codesiva();
 | 
						|
 | 
						|
					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()
 | 
						|
{
 | 
						|
	bool ok = _print_directly;
 | 
						|
	if (!ok)
 | 
						|
	{
 | 
						|
		ok = save(false);
 | 
						|
		edit_mask().update_father_rows(false);
 | 
						|
	}
 | 
						|
  if (ok)   // Registra il record corrente
 | 
						|
  {
 | 
						|
    TDocumento& doc = (TDocumento&)get_relation()->curr();
 | 
						|
   
 | 
						|
    const TTipo_documento& tipo = doc.tipo();
 | 
						|
    TFilename rep; 
 | 
						|
    if (tipo.main_print_profile(rep, 0))
 | 
						|
    {
 | 
						|
      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)
 | 
						|
      {
 | 
						|
        if (da_stampare) // Aggiorna stato documento se necessario
 | 
						|
        {	
 | 
						|
          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);
 | 
						|
        }
 | 
						|
      }
 | 
						|
    }
 | 
						|
		else
 | 
						|
		{
 | 
						|
			rep.ext("");
 | 
						|
			message_box("Il profilo %s non esiste", (const char *) rep);
 | 
						|
		}
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
int ve0100( int argc, char* argv[])
 | 
						|
{
 | 
						|
  TMotore_application a;
 | 
						|
 | 
						|
  a.run( argc, argv, TR("Gestione documenti"));
 | 
						|
  return 0;
 | 
						|
}
 |