Ricompilazione Demo : [ ] Commento : Riportata la versione 3.1 patch 848 git-svn-id: svn://10.65.10.50/trunk@14993 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			998 lines
		
	
	
		
			24 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			998 lines
		
	
	
		
			24 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "vdlib.h"
 | 
						|
 | 
						|
#include "../ve/velib.h"
 | 
						|
#include "../ve/sconti.h"
 | 
						|
#include "../mg/mglib.h"
 | 
						|
 | 
						|
#include <automask.h>
 | 
						|
#include <defmask.h>
 | 
						|
#include <execp.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
#include "../mg/anamag.h"
 | 
						|
#include "../ve/ve0100.h"
 | 
						|
#include "../ve/veini.h"
 | 
						|
#include "../ve/veuml.h"
 | 
						|
#include "../ve/veuml1.h"
 | 
						|
#include "../ve/verig.h"
 | 
						|
 | 
						|
#include <user.h>
 | 
						|
#include "vd0700a.h"
 | 
						|
#include "vd0700b.h"
 | 
						|
#include "vdconf.h"
 | 
						|
#include "turni.h"
 | 
						|
 | 
						|
class TScontrino_mask;
 | 
						|
 | 
						|
class TPerms_mask : public TAutomask
 | 
						|
{ 
 | 
						|
public:
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
 | 
						|
  TPerms_mask() : TAutomask("vd0700b") {}
 | 
						|
  virtual ~TPerms_mask() { }
 | 
						|
};
 | 
						|
 | 
						|
bool TPerms_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
  switch (o.dlg())
 | 
						|
  {
 | 
						|
		case F_PASSWORD:
 | 
						|
			if (e == fe_modify)
 | 
						|
			{
 | 
						|
				const TString & user = get(F_USERNAME);
 | 
						|
				const TRectype & rec = cache().get(LF_USER, user);
 | 
						|
				const TString & pwd = rec.get(USR_PASSWORD);
 | 
						|
				const TString pass = get(F_PASSWORD);
 | 
						|
				const bool ok = !rec.empty() && pass == decode(pwd);
 | 
						|
 | 
						|
				enable(DLG_OK, ok);
 | 
						|
			}
 | 
						|
		break;
 | 
						|
		default:
 | 
						|
		break;  
 | 
						|
 }
 | 
						|
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
class TChiusura_scontrino_mask : public TAutomask
 | 
						|
{ 
 | 
						|
	int _items;
 | 
						|
	TString_array _codpag;
 | 
						|
	TString_array _labpag;
 | 
						|
	TBit_array _contanti;
 | 
						|
	TBit_array _resto;
 | 
						|
 | 
						|
public:
 | 
						|
	const TString & codpag(int i);
 | 
						|
	const TString & labpag(int i);
 | 
						|
 | 
						|
	bool is_contanti(int i) { return _contanti[i - 1];}
 | 
						|
	bool has_resto(int i) { return _resto[i - 1];}
 | 
						|
	real calcola_saldo();
 | 
						|
	real calcola_resto();
 | 
						|
	void init(TConfig & d);
 | 
						|
	void update_doc(TScontrino_mask & m, const TTurno_vendita & t, bool chiuso = true);
 | 
						|
  virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | 
						|
	void reset_mask(int ncassa, const TDate & data, const real & cassa_attuale, const TDocumento & doc);
 | 
						|
 | 
						|
  TChiusura_scontrino_mask() : TAutomask("vd0700a"), _items(0) {}
 | 
						|
  virtual ~TChiusura_scontrino_mask() {}
 | 
						|
};
 | 
						|
 | 
						|
const TString & TChiusura_scontrino_mask::codpag(int i)
 | 
						|
{
 | 
						|
	i--;
 | 
						|
	if (i < _items)
 | 
						|
		return _codpag.row(i);
 | 
						|
	else
 | 
						|
		return EMPTY_STRING;
 | 
						|
}
 | 
						|
 | 
						|
const TString & TChiusura_scontrino_mask::labpag(int i)
 | 
						|
{
 | 
						|
	i--;
 | 
						|
	if (i < _items)
 | 
						|
		return _labpag.row(i);
 | 
						|
	else
 | 
						|
		return EMPTY_STRING;
 | 
						|
}
 | 
						|
 | 
						|
// Definizione della classe dell'applicazione motore
 | 
						|
class TScontrino_application : public TMotore_application
 | 
						|
{
 | 
						|
	TTurno_vendita *_turno;
 | 
						|
	TOperatore * _cassiere;
 | 
						|
	TOperatore * _responsabile;
 | 
						|
	TString8 _filiale;
 | 
						|
	TString8 _numdoc;
 | 
						|
	TString8 _tipodoc;
 | 
						|
	TString8 _codlist;
 | 
						|
	TString8 _numdocf;
 | 
						|
	TString8 _tipodocf;
 | 
						|
	TString80 _cassa_app;
 | 
						|
	bool _chk_doc;
 | 
						|
  bool _barcode_peso_var;
 | 
						|
  bool _peso_var;
 | 
						|
  int _npag;
 | 
						|
	int _ncassa;
 | 
						|
	int _cassetto;
 | 
						|
	int _def_qta;
 | 
						|
	TChiusura_scontrino_mask *_chiusura;
 | 
						|
	TScontrino_mask * _sc_mask;
 | 
						|
	TString_array _tv_labels;
 | 
						|
	TString_array _tv_cmds;
 | 
						|
 | 
						|
protected:
 | 
						|
  virtual bool user_create( );
 | 
						|
  virtual bool user_destroy( );
 | 
						|
  virtual bool menu(MENU_TAG mt);
 | 
						|
  virtual TMask* get_mask( int mode );
 | 
						|
  virtual const char* get_next_key( );
 | 
						|
  virtual void init_query_mode(TMask& m);
 | 
						|
  virtual void init_modify_mode( TMask& m );
 | 
						|
  virtual void init_insert_mode( TMask& m );
 | 
						|
  virtual bool save_and_new() const { return true; }
 | 
						|
  virtual bool has_filtered_cursor() const { return false; }
 | 
						|
	int read( TMask& m );
 | 
						|
	void update_doc( const TMask& m );
 | 
						|
	int write( const TMask& m );
 | 
						|
	int rewrite( const TMask& m );
 | 
						|
  virtual TDocumento_mask & edit_mask() const { CHECK( _sc_mask, "Maschera di edit nulla!" ); return (TDocumento_mask &) *_sc_mask; }
 | 
						|
	bool build_print_file(const TFilename &file);
 | 
						|
 | 
						|
  // Operazione
 | 
						|
public:
 | 
						|
	TChiusura_scontrino_mask & chiusura() { return *_chiusura;}
 | 
						|
  virtual void print();
 | 
						|
	int ncassa() const { return _ncassa;}
 | 
						|
	int def_qta() const { return _def_qta;}
 | 
						|
	const TString & numdoc() const { return _numdoc;}
 | 
						|
	const TString & codlist() const { return _codlist;}
 | 
						|
	const TString & numdocf() const { return _numdocf;}
 | 
						|
	const TString & tipodocf() const { return _tipodocf;}
 | 
						|
	const TString_array & tv_cmds() const {return _tv_cmds;}
 | 
						|
	const TString_array & tv_labels() const {return _tv_labels;}
 | 
						|
	const TOperatore & curr_user() const { return _responsabile != NULL ? *_responsabile : *_cassiere;}
 | 
						|
	bool set_responsabile(const char * user);
 | 
						|
	void set_authorizations(TMask & m);
 | 
						|
	
 | 
						|
	TTurno_vendita & turno() { return *_turno;}
 | 
						|
 | 
						|
  TScontrino_application() : _sc_mask(NULL), _turno(NULL), _chiusura(NULL),
 | 
						|
		                         _cassiere(NULL), _responsabile(NULL) {}
 | 
						|
  virtual ~TScontrino_application();
 | 
						|
};
 | 
						|
 | 
						|
inline TScontrino_application& sapp() { return (TScontrino_application &) main_app(); }
 | 
						|
 | 
						|
class TScontrino_mask : public TDocumento_mask
 | 
						|
{
 | 
						|
protected:
 | 
						|
	static bool turno_handler( TMask_field& f, KEY key );
 | 
						|
	static bool chiudi_handler( TMask_field& f, KEY key );
 | 
						|
	static bool sospendi_handler( TMask_field& f, KEY key );
 | 
						|
	static bool search_chiusi_handler(TMask_field& f, KEY key);
 | 
						|
	static bool search_sospesi_handler(TMask_field& f, KEY key);
 | 
						|
	static bool tasti_veloci_handler(TMask_field& f, KEY key);
 | 
						|
	static bool perms_handler( TMask_field& f, KEY key );
 | 
						|
  static bool ss_notify(TSheet_field& ss, int r, KEY key);
 | 
						|
	static bool check_perms(TDocumento & doc, TSheet_field & s, TDocumento_mask & m, int nrow);
 | 
						|
 | 
						|
public:
 | 
						|
	virtual bool is_omaggio_enabled() { return sapp().curr_user().can_change_omaggi();}
 | 
						|
 | 
						|
  TScontrino_mask(const char* tipodoc);
 | 
						|
  virtual ~TScontrino_mask() {}
 | 
						|
};
 | 
						|
 | 
						|
TScontrino_mask::TScontrino_mask(const char* tipodoc) 
 | 
						|
                :TDocumento_mask(tipodoc)
 | 
						|
{
 | 
						|
	set_handler(DLG_TURNO, turno_handler);      
 | 
						|
	set_handler(DLG_CHIUDI, chiudi_handler);      
 | 
						|
	set_handler(DLG_SAVEREC, sospendi_handler);      
 | 
						|
	set_handler(DLG_RICSOSP, search_sospesi_handler);      
 | 
						|
	set_handler(DLG_RICCHIUSI, search_chiusi_handler);    
 | 
						|
  set_handler(DLG_PERMS, perms_handler);
 | 
						|
	if (id2pos(F_CODLIST) < 0)
 | 
						|
		add_string(F_CODLIST, 0, "Listino", 60, 60, 4, "HP");
 | 
						|
	for (short id = F_FUNC1; id <= F_FUNC8; id++)
 | 
						|
	{
 | 
						|
		const TString & label = sapp().tv_labels().row(id - F_FUNC1);
 | 
						|
 | 
						|
		if (label.full())
 | 
						|
		{
 | 
						|
			TButton_field & b = (TButton_field &) field(id);
 | 
						|
			TFilename img(label);
 | 
						|
 | 
						|
			if (TImage::build_filename(img))
 | 
						|
				b.set_bmp(img);
 | 
						|
			else
 | 
						|
				b.set_prompt(label);
 | 
						|
			b.set_handler(tasti_veloci_handler);
 | 
						|
		}
 | 
						|
		else
 | 
						|
			hide(id);
 | 
						|
	}
 | 
						|
	sfield(F_SHEET).set_notify( ss_notify );
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::check_perms(TDocumento & doc, TSheet_field & s, TDocumento_mask & m, int nrow)
 | 
						|
{
 | 
						|
	bool ok = true;
 | 
						|
	if (nrow > 0 && nrow <= doc.physical_rows())
 | 
						|
		doc[nrow].autosave(s);
 | 
						|
	if (m.is_calculated_page(m.curr_page()))
 | 
						|
		m.update_progs();
 | 
						|
 | 
						|
	const real totale = doc.totale_doc();
 | 
						|
 | 
						|
	if (totale > sapp().curr_user().max_scontrino())
 | 
						|
		ok =  error_box(FR("Scontrino di valore (%s) superiore al massimo (%s) consentito"), totale.string(), sapp().curr_user().max_scontrino().string());
 | 
						|
 | 
						|
	const real abbuono = doc.get_real("SCONTOD");
 | 
						|
	
 | 
						|
	if (ok && abbuono > sapp().curr_user().max_abbuono())
 | 
						|
		ok=  error_box(FR("Abbuono (%s) superiore al massimo (%s) consentito"), abbuono.string(), sapp().curr_user().max_abbuono().string());
 | 
						|
	
 | 
						|
	if (ok && nrow > 0 && nrow <= doc.physical_rows())
 | 
						|
	{
 | 
						|
		TRiga_documento & riga = doc[nrow];
 | 
						|
 | 
						|
		const real qta = riga.get_real(RDOC_QTA);
 | 
						|
 | 
						|
		if (ok && qta < 0 && !sapp().curr_user().can_resi())
 | 
						|
			ok = error_box(TR("Reso non possibile"));
 | 
						|
 | 
						|
		TString ge;
 | 
						|
		real psconto;
 | 
						|
 | 
						|
		scontoexpr2perc(riga.get(RDOC_SCONTO), false, ge, psconto);
 | 
						|
		psconto = CENTO * (1 - psconto);
 | 
						|
		if (ok && psconto > sapp().curr_user().max_sconto())
 | 
						|
			ok = error_box(FR("Percentuale di sconto (%s) superiore al massimo (%s) consentito"), psconto.string(), sapp().curr_user().max_sconto().string());
 | 
						|
 | 
						|
		if (ok && !sapp().curr_user().can_sotto_costo())
 | 
						|
		{
 | 
						|
			const TRectype & anamag = cache().get(LF_ANAMAG, riga.get(RDOC_CODARTMAG));
 | 
						|
			const real prezzo = riga.get_real(RDOC_PREZZOL);
 | 
						|
			real costo = anamag.get_real(ANAMAG_ULTCOS1);
 | 
						|
 | 
						|
			riga.iva().lordo(costo);
 | 
						|
			if (!anamag.empty() && prezzo < costo)
 | 
						|
				ok = error_box(FR("Non e' possibile vendere sottocosto (%s < %s)"), prezzo.string(), costo.string());
 | 
						|
		}
 | 
						|
	}
 | 
						|
	m.enable(DLG_CHIUDI, ok);
 | 
						|
	return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::ss_notify( TSheet_field& ss, int r, KEY key )
 | 
						|
{
 | 
						|
  TDocumento_mask& m = (TDocumento_mask&)ss.mask();
 | 
						|
  CHECK(&m == &app().curr_mask(), "Cast dal cas");
 | 
						|
 | 
						|
  TDocumento& doc = m.doc();
 | 
						|
 | 
						|
	switch (key)
 | 
						|
	{
 | 
						|
	case K_DEL:
 | 
						|
		{
 | 
						|
			const TRiga_documento & riga = doc[r + 1];
 | 
						|
 | 
						|
			if (riga.is_omaggio() && !sapp().curr_user().can_change_omaggi())
 | 
						|
				return false;
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	case K_CTRL + K_DEL:
 | 
						|
		{
 | 
						|
			check_perms(doc, ss, m, 0);
 | 
						|
			return true; 
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	case K_CTRL + K_INS:
 | 
						|
		{
 | 
						|
			const int quant = sapp().def_qta();
 | 
						|
      if (quant > 0)
 | 
						|
      {
 | 
						|
			  TRiga_documento& riga = doc[r + 1];
 | 
						|
			  if (riga.is_merce())
 | 
						|
			  {
 | 
						|
				  riga.put("QUANT", quant);
 | 
						|
				  riga.autoload(ss);
 | 
						|
			  }
 | 
						|
      }			
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	case K_ENTER:
 | 
						|
	case K_INS:
 | 
						|
		{
 | 
						|
			if (!check_perms(doc, ss, m, r + 1))
 | 
						|
				return false;
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	default:
 | 
						|
		break;
 | 
						|
	}
 | 
						|
 | 
						|
	return TDocumento_mask::ss_notify(ss, r, key);
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::turno_handler( TMask_field& f, KEY key )
 | 
						|
{
 | 
						|
  if (key == K_SPACE)
 | 
						|
		return sapp().turno().chiudi();
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::chiudi_handler( TMask_field& f, KEY key )
 | 
						|
{
 | 
						|
  if (key == K_SPACE)
 | 
						|
  {
 | 
						|
		TChiusura_scontrino_mask & mask = sapp().chiusura();
 | 
						|
		TTurno_vendita & turno = sapp().turno();
 | 
						|
		TScontrino_mask & docmask = (TScontrino_mask &) f.mask();
 | 
						|
		TDocumento & doc = docmask.doc();
 | 
						|
 | 
						|
		mask.reset_mask(sapp().ncassa(), docmask.get_date(F_DATADOC), turno.cassa_attuale(), doc);
 | 
						|
		mask.show(-2, sapp().curr_user().can_invoice());
 | 
						|
		mask.show(-3, sapp().curr_user().can_invoice());
 | 
						|
		if (mask.run() == K_ENTER)
 | 
						|
		{
 | 
						|
			do
 | 
						|
			{
 | 
						|
				sapp().print();
 | 
						|
			} while (yesno_box(TR("Vuoi ristampare lo scontrino")));
 | 
						|
 | 
						|
			const real & saldo = mask.get_real(F_SALDO);
 | 
						|
			const long ndoc = doc.get_long(DOC_NDOC);
 | 
						|
 | 
						|
			turno.aggiorna(ndoc, saldo);
 | 
						|
 | 
						|
			const TString & num = sapp().numdocf();
 | 
						|
			const TString & tipo = sapp().tipodocf();
 | 
						|
 | 
						|
			if (mask.get_bool(F_DAFATT) && num.full() && tipo.full())
 | 
						|
			{
 | 
						|
				TDocumento_mask m(tipo);
 | 
						|
				TDocumento & fatt = m.doc();
 | 
						|
				TFilename ini_file; ini_file.temp(NULL, "ini");
 | 
						|
				
 | 
						|
				fatt.put(DOC_CODNUM, num);
 | 
						|
				fatt.put(DOC_ANNO, doc.get(DOC_ANNO));
 | 
						|
				fatt.put(DOC_PROVV, doc.get(DOC_PROVV));
 | 
						|
				fatt.renum_ndoc();
 | 
						|
				fatt.copy_contents(doc); 
 | 
						|
				fatt.stato(fatt.tipo().stato_finale_inserimento());
 | 
						|
				fatt.put(DOC_TIPODOC, tipo);
 | 
						|
				fatt.put(DOC_TIPOCF, mask.get(F_TIPOCFC));
 | 
						|
				fatt.put(DOC_CODCF, mask.get(F_CODCFC));
 | 
						|
 | 
						|
				for (int i = 1; i <= fatt.physical_rows(); i++)
 | 
						|
					fatt[i].set_original_rdoc_key(doc[i]);
 | 
						|
				m.doc2mask();
 | 
						|
				{
 | 
						|
					TConfig ini(ini_file, "Transaction");
 | 
						|
					char mode[2] = { TM_INTERACTIVE, '\0' };
 | 
						|
 | 
						|
					ini.set("Action", TRANSACTION_INSERT);
 | 
						|
					ini.set("Mode", mode);
 | 
						|
		      sapp().mask2ini(m, ini);
 | 
						|
					TString_array p;
 | 
						|
					TString val;
 | 
						|
					
 | 
						|
					ini.list_paragraphs(p);
 | 
						|
					FOR_EACH_ARRAY_ROW(p, rp, par)
 | 
						|
					{
 | 
						|
						TAssoc_array & v =ini.list_variables(*par);
 | 
						|
 | 
						|
						FOR_EACH_ASSOC_STRING(v, obj, key, vr)
 | 
						|
						{
 | 
						|
							const TString16 var(key);
 | 
						|
							if (var == DOC_CODLIST ||
 | 
						|
							    var == DOC_CODVAL  ||
 | 
						|
							    var == DOC_DATACAMBIO  ||
 | 
						|
							    var == DOC_CAMBIO)
 | 
						|
									continue;
 | 
						|
							val = vr;
 | 
						|
							val.strip("\"");
 | 
						|
 | 
						|
							if (val.blank())
 | 
						|
								ini.remove(var);
 | 
						|
						}
 | 
						|
					}
 | 
						|
				}
 | 
						|
 | 
						|
				TString cmd("ve0 -1 -i");	cmd << ini_file;
 | 
						|
				TExternal_app  app(cmd);
 | 
						|
	
 | 
						|
				app.run();
 | 
						|
				
 | 
						|
				{
 | 
						|
					TConfig ini(ini_file, "Transaction");
 | 
						|
 | 
						|
					if (ini.get("Result") != "OK")
 | 
						|
						mask.set(F_CODCFC, "");
 | 
						|
				}
 | 
						|
			}
 | 
						|
			mask.update_doc(docmask, turno);
 | 
						|
			docmask.stop_run(K_SAVE);
 | 
						|
		}
 | 
						|
		else
 | 
						|
			return false;
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
static bool chiusi_filter(const TRelation* r)
 | 
						|
{
 | 
						|
	return r->curr().get("USERNAME") == sapp().turno().user();
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::sospendi_handler( TMask_field& f, KEY key )
 | 
						|
{
 | 
						|
  if (key == K_SPACE)
 | 
						|
  {
 | 
						|
		const TTurno_vendita & turno = sapp().turno();
 | 
						|
		TScontrino_mask & docmask = (TScontrino_mask &) f.mask();
 | 
						|
		TChiusura_scontrino_mask & mask = sapp().chiusura();
 | 
						|
		mask.update_doc(docmask, turno, false);
 | 
						|
  }
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::search_chiusi_handler(TMask_field& f, KEY key)
 | 
						|
{             
 | 
						|
  if (key == K_SPACE)
 | 
						|
  {                     
 | 
						|
    TScontrino_mask &  m = (TScontrino_mask &)  f.mask();
 | 
						|
    TRectype filtrec(LF_DOC);
 | 
						|
 | 
						|
    filtrec.put(DOC_PROVV, m.get(F_PROVV));
 | 
						|
    filtrec.put(DOC_ANNO, m.get(F_ANNO));
 | 
						|
		filtrec.put(DOC_CODNUM, m.get(F_CODNUM));
 | 
						|
 | 
						|
    TRelation rel(LF_DOC);
 | 
						|
 | 
						|
		rel.lfile().set_curr(new TDocumento);
 | 
						|
 | 
						|
		TCursor cur(&rel, "", 1, &filtrec, &filtrec);
 | 
						|
    TString80 filt; filt.format("(STATO>=\"%c\")&&(TIPODOC==\"%s\")&&(CODCF==\"\")", m.doc().tipo().stato_bloccato(), (const char *) m.get(F_TIPODOC));
 | 
						|
    
 | 
						|
    cur.setfilter(filt);
 | 
						|
		cur.set_filterfunction(chiusi_filter);
 | 
						|
    TCursor_sheet sheet(&cur, "ANNO|CODNUM|NDOC|DATADOC|CODVAL|G1:TOTDOC",
 | 
						|
                        "Documento",
 | 
						|
                        "Anno|Numeraz|Doc.numero|Data\nDocumento@10|Valuta|Totale\nDocumento@18V",
 | 
						|
                        0, 1);
 | 
						|
    if (sheet.run() == K_ENTER)
 | 
						|
    {                                     
 | 
						|
      const TString16 ndoc = sheet.row(-1).get(2);
 | 
						|
			TDate oggi(TODAY);
 | 
						|
			
 | 
						|
			m.set(F_PROVV, "D");
 | 
						|
			f.mask().set(F_ANNO, oggi.year());
 | 
						|
			m.set(F_CODNUM, sapp().numdoc());
 | 
						|
      m.set(F_NDOC, ndoc);
 | 
						|
      m.stop_run(K_AUTO_ENTER);
 | 
						|
			m.enable(DLG_CHIUDI);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
static bool sospesi_filter(const TRelation* r)
 | 
						|
{
 | 
						|
	return r->curr().get_long(TRN_PROGR) == sapp().turno().nturno();
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::search_sospesi_handler(TMask_field& f, KEY key)
 | 
						|
{             
 | 
						|
  if (key == K_SPACE)
 | 
						|
  {                     
 | 
						|
    TScontrino_mask &  m = (TScontrino_mask &) f.mask();
 | 
						|
    TRectype filtrec(LF_DOC);
 | 
						|
 | 
						|
    filtrec.put(DOC_PROVV, m.get(F_PROVV));
 | 
						|
    filtrec.put(DOC_ANNO, m.get(F_ANNO));
 | 
						|
		filtrec.put(DOC_CODNUM, m.get(F_CODNUM));
 | 
						|
 | 
						|
    TRelation rel(LF_DOC);
 | 
						|
 | 
						|
		rel.lfile().set_curr(new TDocumento);
 | 
						|
 | 
						|
    TCursor cur(&rel, "", 1, &filtrec, &filtrec);
 | 
						|
    TString80 filt; filt.format("(STATO<\"%c\")&&(TIPODOC==\"%s\")", m.doc().tipo().stato_bloccato(), (const char *) m.get(F_TIPODOC));
 | 
						|
    
 | 
						|
    cur.setfilter(filt);
 | 
						|
		cur.set_filterfunction(sospesi_filter);
 | 
						|
    TCursor_sheet sheet(&cur, "ANNO|CODNUM|NDOC|DATADOC|CODVAL|G1:TOTDOC",
 | 
						|
                        "Documento",
 | 
						|
                        "Anno|Numeraz|Doc.numero|Data\nDocumento@10|Valuta|Totale\nDocumento@18V",
 | 
						|
                        0, 1);
 | 
						|
    if (sheet.run() == K_ENTER)
 | 
						|
    {                                     
 | 
						|
      const TString16 ndoc = sheet.row(-1).get(2);
 | 
						|
			TDate oggi(TODAY);
 | 
						|
			
 | 
						|
			m.set(F_PROVV, "D");
 | 
						|
			f.mask().set(F_ANNO, oggi.year());
 | 
						|
			m.set(F_CODNUM, sapp().numdoc());
 | 
						|
      m.set(F_NDOC, ndoc);
 | 
						|
      m.stop_run(K_AUTO_ENTER);
 | 
						|
			m.enable(DLG_CHIUDI);
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::tasti_veloci_handler(TMask_field& f, KEY key)
 | 
						|
{
 | 
						|
  if (key == K_SPACE)
 | 
						|
  { 
 | 
						|
		const TString & cmd = sapp().tv_cmds().row(f.dlg() - F_FUNC1);
 | 
						|
 | 
						|
		if (cmd.full())
 | 
						|
		{
 | 
						|
	    TScontrino_mask & docmask = (TScontrino_mask &) f.mask();
 | 
						|
			TSheet_field & sf = docmask.sfield(F_SHEET);
 | 
						|
			int r = sf.items() == 0 ?  0 : sf.selected() + 1;
 | 
						|
			
 | 
						|
			r = sf.insert(r, false, true);                      
 | 
						|
			if (r >= 0)
 | 
						|
			{
 | 
						|
				TToken_string & row = sf.row(r);
 | 
						|
				TDocumento & doc = docmask.doc();
 | 
						|
				TRiga_documento & rdoc = doc.insert_row(r + 1, docmask.get(F_LBTIPORIGA));
 | 
						|
		
 | 
						|
				rdoc.put(RDOC_CODART, cmd);
 | 
						|
				rdoc.zero(RDOC_CHECKED);
 | 
						|
				rdoc.put("QTA", sapp().def_qta());
 | 
						|
				rdoc.autoload(sf);
 | 
						|
				sf.check_row(r);
 | 
						|
				rdoc.autosave(sf);
 | 
						|
				sf.force_update();
 | 
						|
				sf.select(r);
 | 
						|
				sf.set_focus();
 | 
						|
				sf.set_dirty();
 | 
						|
				docmask.ss_notify(sf, r, K_ENTER);
 | 
						|
				docmask.update_progs();
 | 
						|
			}
 | 
						|
    }
 | 
						|
  }
 | 
						|
  
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_mask::perms_handler( TMask_field& f, KEY key )
 | 
						|
{
 | 
						|
  if (key == K_SPACE)
 | 
						|
  { 
 | 
						|
		TPerms_mask m;
 | 
						|
 | 
						|
		if (m.run() == K_ENTER)
 | 
						|
		{
 | 
						|
			if (sapp().set_responsabile(m.get(F_USERNAME)))
 | 
						|
			{
 | 
						|
				sapp().set_authorizations(f.mask());
 | 
						|
				f.mask().sfield(F_SHEET).force_update();
 | 
						|
 | 
						|
				TString super(m.get(F_USERNAME)) ;
 | 
						|
 | 
						|
				if (super == sapp().turno().user())
 | 
						|
					super.cut(0);
 | 
						|
				sapp().turno().set_superuser(super);
 | 
						|
			}
 | 
						|
		}
 | 
						|
	}
 | 
						|
  return true;
 | 
						|
}
 | 
						|
 | 
						|
void TChiusura_scontrino_mask::init(TConfig & d)
 | 
						|
{
 | 
						|
	TString8 codpag(d.get("CODPAG", NULL, 1));
 | 
						|
	while (codpag.full() && _items <= 8)
 | 
						|
	{
 | 
						|
		const int last = _items;
 | 
						|
		_items++;
 | 
						|
		_codpag.add(codpag);
 | 
						|
		const TString & desc = d.get("LABPAG", NULL, _items);
 | 
						|
		_labpag.add(desc);
 | 
						|
		field(F_INC01 + _items - 1).set_prompt(desc);
 | 
						|
		field(F_INC01 + _items - 1).enable();
 | 
						|
 | 
						|
		TPagamento p(codpag);
 | 
						|
		TTipo_pag t = p.tipo_rata(0);
 | 
						|
 | 
						|
		_resto.set(last, d.get_bool("RESTO", NULL, _items));
 | 
						|
		_contanti.set(last, _resto[last] || (t == _rim_dir));
 | 
						|
 | 
						|
		codpag = d.get("CODPAG", NULL, _items + 1);
 | 
						|
	}
 | 
						|
	for (int i = _items; i < 8; i++)
 | 
						|
		field(F_INC01 + i).hide();
 | 
						|
}
 | 
						|
 | 
						|
void TChiusura_scontrino_mask::update_doc(TScontrino_mask & m, const TTurno_vendita & t, bool chiuso)
 | 
						|
{
 | 
						|
	TDocumento & doc = m.doc();
 | 
						|
	const char stato = doc.tipo().stato_bloccato();
 | 
						|
 | 
						|
	doc.put(TRN_CODCASSA, t.ncassa());
 | 
						|
	doc.put(TRN_PROGR, t.nturno());
 | 
						|
	doc.put(TRN_USERNAME, t.user());
 | 
						|
	doc.put("TEMPUSERNAME", t.superuser());
 | 
						|
	if (chiuso)
 | 
						|
	{
 | 
						|
		doc.stato(stato);
 | 
						|
		m.set(F_STATO, doc.get(DOC_STATO));
 | 
						|
		doc.put(TRN_INC01, get(F_INC01));
 | 
						|
		doc.put(TRN_INC02, get(F_INC02));
 | 
						|
		doc.put(TRN_INC03, get(F_INC03));
 | 
						|
		doc.put(TRN_INC04, get(F_INC04));
 | 
						|
		doc.put(TRN_INC05, get(F_INC05));
 | 
						|
		doc.put(TRN_INC06, get(F_INC06));
 | 
						|
		doc.put(TRN_INC07, get(F_INC07));
 | 
						|
		doc.put(TRN_INC08, get(F_INC08));
 | 
						|
		doc.put(TRN_RESTI, get(F_RESTO));
 | 
						|
		const long codcf = get_long(F_CODCFC);
 | 
						|
 | 
						|
		if (codcf > 0L)
 | 
						|
		{
 | 
						|
			doc.put(DOC_TIPOCF, get(F_TIPOCFC));
 | 
						|
			doc.put(DOC_CODCF, codcf);
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
real TChiusura_scontrino_mask::calcola_saldo()
 | 
						|
{
 | 
						|
	real saldo = get_real(F_CASSAINI) - get_real(F_RESTO);
 | 
						|
	int i = 1;
 | 
						|
 | 
						|
	for (short id = F_INC01; id <= F_INC08; id++, i++)
 | 
						|
		if (is_contanti(i))
 | 
						|
			saldo += get_real(id);
 | 
						|
	return saldo;
 | 
						|
}
 | 
						|
 | 
						|
real TChiusura_scontrino_mask::calcola_resto()
 | 
						|
{
 | 
						|
	real resto = -get_real(F_TOTDOC);
 | 
						|
	int i = 1;
 | 
						|
 | 
						|
	for (short id = F_INC01; id <= F_INC08; id++, i++)
 | 
						|
		resto += get_real(id);
 | 
						|
	enable(DLG_OK, resto >= ZERO);
 | 
						|
	return resto > ZERO ? resto : ZERO;
 | 
						|
}
 | 
						|
 | 
						|
bool TChiusura_scontrino_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | 
						|
{
 | 
						|
	switch (o.dlg())
 | 
						|
  {
 | 
						|
	case F_INC01:
 | 
						|
	case F_INC02:
 | 
						|
	case F_INC03:
 | 
						|
	case F_INC04:
 | 
						|
	case F_INC05:
 | 
						|
	case F_INC06:
 | 
						|
	case F_INC07:
 | 
						|
	case F_INC08:
 | 
						|
		if (e == fe_modify)
 | 
						|
		{
 | 
						|
			if (!has_resto(o.dlg() - F_INC01 + 1))
 | 
						|
			{
 | 
						|
				real valore = get_real(o.dlg());
 | 
						|
				real residuo = get_real(F_TOTDOC);
 | 
						|
				int i = 1;
 | 
						|
 | 
						|
				for (short id = F_INC01; id <= F_INC08; id++, i++)
 | 
						|
					if (!has_resto(i))
 | 
						|
						residuo -= get_real(id);
 | 
						|
				if (residuo < ZERO)
 | 
						|
				{
 | 
						|
					valore += residuo;
 | 
						|
					if (valore < ZERO)
 | 
						|
						valore = ZERO;
 | 
						|
					message_box("Importo senza resto non permesso");
 | 
						|
					o.set(valore.string());
 | 
						|
				}
 | 
						|
			}
 | 
						|
			const real resto = calcola_resto();
 | 
						|
			set(F_RESTO, resto);
 | 
						|
			const real saldo = calcola_saldo();
 | 
						|
			set(F_SALDO, saldo);
 | 
						|
		}
 | 
						|
		break;
 | 
						|
	case F_CODCFC:
 | 
						|
		enable(DLG_OK, field(DLG_OK).enabled() || o.get().full());
 | 
						|
		break;
 | 
						|
	default:
 | 
						|
		break;  
 | 
						|
 }
 | 
						|
 return true;
 | 
						|
}
 | 
						|
 | 
						|
void TChiusura_scontrino_mask::reset_mask(int ncassa, const TDate & data, const real & cassa_attuale, const TDocumento & doc)
 | 
						|
{
 | 
						|
	const bool aperto = !doc.chiuso();
 | 
						|
 | 
						|
	reset();
 | 
						|
	set(F_CASSA, ncassa);
 | 
						|
	set(F_DATA, data);
 | 
						|
	set(F_TOTDOC, doc.totale_doc());
 | 
						|
	if (aperto)
 | 
						|
		set(F_CASSAINI, cassa_attuale);
 | 
						|
 | 
						|
	enable(F_SALDO, aperto);
 | 
						|
	for (short i = F_INC01 ; i<= F_INC08; i++)
 | 
						|
		if (field(i).shown())
 | 
						|
		{
 | 
						|
			TString f; f.format("INC%02d", i - F_INC01 +1);
 | 
						|
 | 
						|
			set(i, doc.get(f));
 | 
						|
			field(i).enable(aperto);
 | 
						|
		}
 | 
						|
 | 
						|
	set(F_RESTO, doc.get(TRN_RESTI));
 | 
						|
 | 
						|
	const bool da_fatturare = doc.get(DOC_CODCF).blank();
 | 
						|
 | 
						|
	enable(-3, da_fatturare);
 | 
						|
	disable(DLG_OK);
 | 
						|
}
 | 
						|
 | 
						|
TScontrino_application::~TScontrino_application()
 | 
						|
{
 | 
						|
	delete _turno;
 | 
						|
	delete _chiusura;
 | 
						|
	if (_sc_mask != NULL)
 | 
						|
		delete _sc_mask;
 | 
						|
	if (_cassiere != NULL)
 | 
						|
		delete _cassiere;
 | 
						|
	if (_responsabile != NULL)
 | 
						|
		delete _responsabile;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_application::set_responsabile(const char * user)
 | 
						|
{
 | 
						|
	_responsabile = new TOperatore(user);
 | 
						|
	if (!_responsabile->ok())
 | 
						|
	{
 | 
						|
		delete _responsabile;
 | 
						|
		_responsabile = NULL;
 | 
						|
		return false;
 | 
						|
	}
 | 
						|
	return true;
 | 
						|
}
 | 
						|
 | 
						|
TMask* TScontrino_application::get_mask( int mode )
 | 
						|
{
 | 
						|
  return _sc_mask;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_application::user_create( )
 | 
						|
{
 | 
						|
	const bool ok = TMotore_application::user_create();
 | 
						|
 | 
						|
	TConfig d(CONFIG_DITTA);
 | 
						|
 | 
						|
	_turno = new TTurno_vendita;
 | 
						|
	_chiusura = new TChiusura_scontrino_mask;
 | 
						|
 | 
						|
	_filiale = d.get("FILIALE");
 | 
						|
  _numdoc = d.get("CODNUM");
 | 
						|
	_tipodoc = d.get("TIPODOC");
 | 
						|
	_codlist = d.get("CODLIST");
 | 
						|
  _numdocf = d.get("CODNUMF");
 | 
						|
	_tipodocf = d.get("TIPODOCF");
 | 
						|
	_chk_doc =  d.get_bool("CHECKDOC");
 | 
						|
  _barcode_peso_var =  d.get_bool("BARPVAR");
 | 
						|
  _peso_var = d.get_bool("CODPVAR");
 | 
						|
  
 | 
						|
	_chiusura->init(d);
 | 
						|
 | 
						|
 | 
						|
	TConfig w(CONFIG_WST);
 | 
						|
 | 
						|
	_ncassa = w.get_int("NCASSA");
 | 
						|
	_cassetto = w.get_int("NCASSETTO");
 | 
						|
 | 
						|
	TString8 wrk = w.get("CODLIST");
 | 
						|
	
 | 
						|
	if (wrk.full())
 | 
						|
		_codlist = wrk;
 | 
						|
  wrk = w.get("CODNUMF");
 | 
						|
	if (wrk.full())
 | 
						|
		_numdocf = wrk;
 | 
						|
	wrk = w.get("TIPODOCF");
 | 
						|
	if (wrk.full())
 | 
						|
		_tipodocf = wrk;
 | 
						|
	_cassa_app = w.get("CASSAAPP");
 | 
						|
	_def_qta = w.get_int("QTADEF");
 | 
						|
 | 
						|
	for (int i = 1; i <= 8; i++)
 | 
						|
	{
 | 
						|
		_tv_labels.add(w.get("TVLABEL", "", i));
 | 
						|
		_tv_cmds.add(w.get("TVCMD", "", i));
 | 
						|
	}
 | 
						|
 | 
						|
	_sc_mask = new TScontrino_mask(_tipodoc); 
 | 
						|
 | 
						|
	return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_application::user_destroy()
 | 
						|
{
 | 
						|
	const bool ok = TMotore_application::user_destroy();
 | 
						|
  return ok;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_application::build_print_file(const TFilename &file)
 | 
						|
{
 | 
						|
	ofstream f(file);
 | 
						|
 | 
						|
	if (f)
 | 
						|
		f <<"Quando cazzo mi dici come si fa ?";
 | 
						|
	return f != 0;
 | 
						|
}
 | 
						|
 | 
						|
bool TScontrino_application::menu(MENU_TAG mt)
 | 
						|
{            
 | 
						|
  return TMotore_application::menu(mt);
 | 
						|
}
 | 
						|
 | 
						|
void TScontrino_application::print()
 | 
						|
{
 | 
						|
	if (_cassa_app.full())
 | 
						|
	{
 | 
						|
		TFilename sc_file;
 | 
						|
		TFilename app(_cassa_app);
 | 
						|
		TString cmd; cmd;
 | 
						|
 | 
						|
		sc_file.temp(NULL, "txt");
 | 
						|
		build_print_file(sc_file);
 | 
						|
		cmd << app << " " << sc_file;
 | 
						|
 | 
						|
		TExternal_app  stampa(cmd);
 | 
						|
	
 | 
						|
		stampa.run();
 | 
						|
	}
 | 
						|
	else
 | 
						|
		TMotore_application::print();
 | 
						|
}
 | 
						|
 | 
						|
const char* TScontrino_application::get_next_key( )
 | 
						|
{
 | 
						|
  TCodice_numerazione cod_num(_numdoc);
 | 
						|
  
 | 
						|
  // Se per questa numerazione h abilitata le numerazione automatica
 | 
						|
  if( cod_num.auto_num())
 | 
						|
  {
 | 
						|
    TLocalisamfile doc(LF_DOC);
 | 
						|
		TDate oggi(TODAY);
 | 
						|
 | 
						|
    doc.zero();
 | 
						|
    doc.put("CODNUM", cod_num.codice());
 | 
						|
    doc.put("ANNO", oggi.year());
 | 
						|
    doc.put("PROVV", "D");
 | 
						|
 | 
						|
    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 "";
 | 
						|
}
 | 
						|
 | 
						|
void TScontrino_application::set_authorizations(TMask & m)
 | 
						|
{
 | 
						|
	TSheet_field & sf = m.sfield(F_SHEET);
 | 
						|
	const int items = sf.items();
 | 
						|
 | 
						|
	sf.enable_column(FR_PREZZO, curr_user().can_change_price());
 | 
						|
	sf.enable_column(FR_SCONTO, curr_user().can_change_sconti());
 | 
						|
	for (int i = 0; i < items; i++)
 | 
						|
		sf.check_row(i);
 | 
						|
	sf.force_update();
 | 
						|
 | 
						|
	m.enable(DLG_RICCHIUSI, sapp().curr_user().can_invoice());
 | 
						|
}
 | 
						|
 | 
						|
void TScontrino_application::init_query_mode( TMask& m )
 | 
						|
{
 | 
						|
 | 
						|
	if (_turno->chiuso())
 | 
						|
		if (!_turno->apri())
 | 
						|
			exit(0);// verificare
 | 
						|
	if (_cassiere != NULL)
 | 
						|
		delete _cassiere;
 | 
						|
	_cassiere = new TOperatore(_turno->user());		
 | 
						|
	if (_responsabile != NULL)
 | 
						|
	{
 | 
						|
		delete _responsabile;
 | 
						|
		_responsabile = NULL;
 | 
						|
	}
 | 
						|
	_turno->set_superuser();
 | 
						|
	set_mode(MODE_INS);
 | 
						|
	TDate oggi(TODAY);
 | 
						|
 | 
						|
  m.set(F_PROVV, "D");
 | 
						|
  m.set(F_ANNO, oggi.year());
 | 
						|
  m.set(F_CODNUM, _numdoc);
 | 
						|
  m.set(F_TIPODOC, _tipodoc);
 | 
						|
	m.set(F_DATADOC, oggi);
 | 
						|
	m.set(F_CODLIST, _codlist);
 | 
						|
 | 
						|
	
 | 
						|
	TToken_string key(get_next_key());
 | 
						|
	const long numdoc = key.get_long(1);
 | 
						|
	
 | 
						|
	m.set(F_NDOC, numdoc);
 | 
						|
 | 
						|
	TScontrino_mask & dm = (TScontrino_mask &) m;
 | 
						|
	TDocumento & doc = dm.doc();
 | 
						|
 | 
						|
	doc.zero();
 | 
						|
	dm.mask2doc();
 | 
						|
 | 
						|
	doc.stato(doc.tipo().stato_finale_inserimento());
 | 
						|
	m.set(F_STATO, doc.get(DOC_STATO));
 | 
						|
	m.enable(DLG_RICSOSP);
 | 
						|
	m.enable(DLG_CHIUDI, !turno().riaperto());
 | 
						|
	set_authorizations(m);
 | 
						|
}
 | 
						|
 | 
						|
void TScontrino_application::init_insert_mode( TMask& m )
 | 
						|
{             
 | 
						|
	init_query_mode(m);
 | 
						|
}
 | 
						|
 | 
						|
void TScontrino_application::init_modify_mode( TMask& m )
 | 
						|
{             
 | 
						|
	m.disable(DLG_RICCHIUSI);
 | 
						|
	m.disable(DLG_RICSOSP);
 | 
						|
	set_authorizations(m);
 | 
						|
}
 | 
						|
 | 
						|
int TScontrino_application::read( TMask& m )
 | 
						|
{
 | 
						|
  return TMotore_application::read(m);
 | 
						|
}
 | 
						|
 | 
						|
int TScontrino_application::write( const TMask& m )  // C 90
 | 
						|
{          
 | 
						|
	if (((TScontrino_mask & )m).doc().physical_rows() > 0)
 | 
						|
		return TMotore_application::write(m);
 | 
						|
	else
 | 
						|
		return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
int TScontrino_application::rewrite( const TMask& m ) // C 90
 | 
						|
{
 | 
						|
	TDocumento & doc = ((TDocumento_mask &) m).doc();
 | 
						|
	if (doc.chiuso())
 | 
						|
		doc.rewrite();
 | 
						|
  return TMotore_application::rewrite(m);
 | 
						|
}
 | 
						|
 | 
						|
int vd0700( int argc, char* argv[])
 | 
						|
{
 | 
						|
  TScontrino_application a;
 | 
						|
 | 
						|
  a.run( argc, argv, TR("Vendita a banco"));
 | 
						|
  return 0;
 | 
						|
}
 |