Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 3.2 patch 1262 git-svn-id: svn://10.65.10.50/trunk@17628 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			519 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			519 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include <automask.h>
 | |
| #include <diction.h>
 | |
| #include <recset.h>
 | |
| #include <relation.h>
 | |
| #include <recarray.h>
 | |
| #include <reprint.h>
 | |
| #include <utility.h>
 | |
| 
 | |
| #include "turni.h"
 | |
| #include "../include/user.h"
 | |
| #include "vdlib.h"
 | |
| #include "vdmask.h"
 | |
| #include "../cg/cgpagame.h"
 | |
| #include "../ve/velib.h"
 | |
| 
 | |
| 
 | |
| class TApri_mask : public TAutomask
 | |
| { 
 | |
| 	const TTurno_vendita & _turno;
 | |
| public:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
|   TApri_mask(const TTurno_vendita & t) : TAutomask("vdlib01"), _turno(t) {}
 | |
|   virtual ~TApri_mask() { }
 | |
| };
 | |
| 
 | |
| bool TApri_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   switch (o.dlg())
 | |
|   {
 | |
| 		case F_USERNAME:
 | |
| 			if (e == fe_modify)
 | |
| 				set(F_TURNO, "", 0x3);
 | |
| 			break;
 | |
| 		case F_TURNO:
 | |
| 		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);
 | |
| 				const bool old_turno = get(F_TURNO).full();
 | |
| 				enable(-1, ok && !old_turno);
 | |
| 				enable(DLG_OK, ok);
 | |
| 				if (old_turno)
 | |
| 					clear(-1);
 | |
| 			}
 | |
| 		break;
 | |
| 		case F_SINIZIO:
 | |
| 			if (e == fe_close)
 | |
| 			{
 | |
| 				const TDate & ultima_data = _turno.ultima_data();
 | |
| 
 | |
| 				if (ultima_data == get_date(F_DATA))
 | |
| 				{
 | |
| 					const long ora_fine = _turno.ora_fine();
 | |
| 					const long ora_inizio = get_int(F_HINIZIO) * 10000 + get_int(F_MINIZIO) * 100 + get_int(F_SINIZIO);
 | |
| 
 | |
| 					if (ora_inizio < ora_fine)
 | |
| 						return error_box("Ora inizio %02d:%02d:%02d antecedente alla fine del turno precedente (%02d:%02d:%02d)",
 | |
| 															get_int(F_HINIZIO), get_int(F_MINIZIO), get_int(F_SINIZIO),
 | |
| 															ora_fine / 10000, (ora_fine / 100) % 100, ora_fine % 100);
 | |
| 				}
 | |
| 			}
 | |
| 		break;
 | |
| 		default:
 | |
| 		break;  
 | |
|  }
 | |
| 
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| class TChiudi_mask : public TAutomask
 | |
| { 
 | |
| 	TBit_array _rim;
 | |
| 	TTurno_vendita & _turno;
 | |
| 
 | |
| public:
 | |
| 	real calcola_differenza();
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| 
 | |
|   TChiudi_mask(TTurno_vendita & t);
 | |
|   virtual ~TChiudi_mask() {}
 | |
| };
 | |
| 
 | |
| TChiudi_mask::TChiudi_mask(TTurno_vendita & t)
 | |
| 						: TAutomask("vdlib02"), _turno(t)
 | |
| {
 | |
| 	TConfig d(CONFIG_DITTA);
 | |
| 
 | |
| 	for (int i = 1; i <= 8; i++)
 | |
| 	{
 | |
| 		const TString & codpag = d.get("CODPAG", NULL, i);
 | |
| 		TReport_field * label = _turno.report().section('B', 1).find_field(100 + i);
 | |
| 		TReport_field * value = _turno.report().section('B', 1).find_field(200 + i);
 | |
| 
 | |
| 		if (codpag.full())
 | |
| 		{
 | |
| 			TPagamento p(codpag);
 | |
| 			TTipo_pag t = p.tipo_rata(0);
 | |
| 
 | |
| 			_rim.set(i, t == _rim_dir);
 | |
| 			
 | |
| 			const TString & desc = d.get("LABPAG", NULL, i);
 | |
| 			
 | |
| 			field(F_INC01 +i -1).set_prompt(desc);
 | |
| 			if (label != NULL)
 | |
| 				label->set(desc);
 | |
| 			if (value != NULL)
 | |
| 				value->show(true);
 | |
| 		}
 | |
| 		else
 | |
| 		{
 | |
| 			field(F_INC01 + i - 1).hide();
 | |
| 			if (label != NULL)
 | |
| 				label->hide();
 | |
| 			if (value != NULL)
 | |
| 				value->hide();
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 | |
| real TChiudi_mask::calcola_differenza()
 | |
| {
 | |
| 	real diff =  get_real(F_CASSAFIN) - get_real(F_CASSAINI) + get_real(F_RESTI);
 | |
| 
 | |
| 	for (short id = F_INC01; id <= F_INC08; id++)
 | |
| 	{
 | |
| 		const int i = id - F_INC01 + 1;
 | |
| 
 | |
| 		if (_rim[i])
 | |
| 			diff -= get_real(id);
 | |
| 	}
 | |
| 	return diff;
 | |
| }
 | |
| 
 | |
| bool TChiudi_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 on = !rec.empty() && pass == decode(pwd);
 | |
| 			enable(-1, on && !_turno.riaperto());
 | |
| 			enable(DLG_OK, on);
 | |
| 		}
 | |
| 		break;
 | |
| 	case F_SFINE:
 | |
| 		if (e == fe_close)
 | |
| 		{
 | |
| 			const long ora_inizio = _turno.ora_inizio();
 | |
| 			const long ora_fine = get_int(F_HFINE) * 10000 + get_int(F_MFINE) * 100 + get_int(F_SFINE);
 | |
| 
 | |
| 			if (ora_fine <= ora_inizio)
 | |
| 				return error_box("Ora fine %02d:%02d:%02d antecedente alla inizio del turno (%02d:%02d:%02d)",
 | |
| 													get_int(F_HFINE), get_int(F_MFINE), get_int(F_SFINE),
 | |
| 													ora_inizio / 10000, (ora_inizio / 100) % 100, ora_inizio % 100);
 | |
| 		}
 | |
| 		break;
 | |
| 	case F_INC01:
 | |
| 	case F_INC02:
 | |
| 	case F_INC03:
 | |
| 	case F_INC04:
 | |
| 	case F_INC05:
 | |
| 	case F_INC06:
 | |
| 	case F_INC07:
 | |
| 	case F_INC08:
 | |
| 	case F_CASSAFIN:
 | |
| 		{
 | |
| 			const real diff = calcola_differenza();
 | |
| 			set(F_DIFF, diff);
 | |
| 		}
 | |
| 		break;
 | |
| 	default:
 | |
| 		break;  
 | |
|  }
 | |
| 
 | |
|   return true;
 | |
| }
 | |
| 
 | |
| void TTurno_vendita::leggi(long progr)
 | |
| {
 | |
| 	bool aperto = false;
 | |
| 	
 | |
| 	const TString use  = format("USE %d\nFROM CODCASSA=%d ANNO=%d\nTO CODCASSA=%d ANNO=%d\n", LF_TURNI, _cassa, _anno, _cassa, _anno);
 | |
| 	TISAM_recordset r(use);
 | |
| 
 | |
| 	if (progr > 0L)
 | |
| 	{
 | |
| 		TRectype & rec = r.cursor()->curr();
 | |
| 
 | |
| 		rec.zero();
 | |
| 		rec.put(TRN_CODCASSA, _cassa);
 | |
| 		rec.put(TRN_ANNO, _anno);
 | |
| 		rec.put(TRN_PROGR, progr);
 | |
| 		r.cursor()->read();
 | |
| 		_rec = rec;
 | |
| 		return;
 | |
| 	}
 | |
| 	if (r.items() > 0L)
 | |
| 	{
 | |
| 		const TString & real_user = ::user();
 | |
| 		r.move_last();
 | |
| 		if (progr < 0L)
 | |
| 		{
 | |
| 			bool found = false;
 | |
| 			while (!found)
 | |
| 			{
 | |
| 				_rec = r.cursor()->curr();
 | |
| 				const TString & u = _rec.get(TRN_USERNAME);
 | |
| 
 | |
| 				found = real_user == u;
 | |
| 				if (!r.move_prev())
 | |
| 					break;
 | |
| 			}
 | |
| 			if (!found)
 | |
| 				r.move_last();
 | |
| 		}
 | |
| 		_rec = r.cursor()->curr();
 | |
| 		const long fine = _rec.get_long(TRN_FINE);
 | |
| 
 | |
| 		progr = _rec.get_long(TRN_PROGR);
 | |
| 		const TString & u = _rec.get(TRN_USERNAME);
 | |
| 		if (u == real_user)
 | |
| 			aperto = fine == 0L;
 | |
| 
 | |
| 	}
 | |
| 	if (!aperto)
 | |
| 	{
 | |
| 		_datafine = _rec.get(TRN_DATA);
 | |
| 		_orafine = _rec.get_long(TRN_FINE);
 | |
| 		progr++;
 | |
| 		_rec.zero();
 | |
| 		_rec.put(TRN_CODCASSA, _cassa);
 | |
| 		_rec.put(TRN_ANNO, _anno);
 | |
| 		_rec.put(TRN_PROGR, progr);
 | |
| 	}
 | |
| }
 | |
| 
 | |
| const long TTurno_vendita::ora_inizio() const
 | |
| {
 | |
| 	return _rec.get_long(TRN_INIZIO);
 | |
| }
 | |
| 
 | |
| bool TTurno_vendita::apri(const bool select_prev)
 | |
| {
 | |
| 	leggi();
 | |
| 	if (!aperto())
 | |
| 	{
 | |
| 		TApri_mask m(*this);
 | |
| 		TDocumento d('D', _anno, _codnum, 0L);
 | |
| 		const long fndoc = d.renum_ndoc();
 | |
| 		const long ora = daytime();
 | |
| 		
 | |
| 		m.show(F_TURNO, select_prev);
 | |
| 		m.set(F_CASSA, _cassa);
 | |
| 		m.set(F_USERNAME, ::user());
 | |
| 		m.set(F_HINIZIO, ora / 10000);
 | |
| 		m.set(F_MINIZIO, (ora / 100) % 100);
 | |
| 		m.set(F_SINIZIO, ora % 100);
 | |
| 		if (m.run() == K_ENTER)
 | |
| 		{
 | |
| 			const long idturno = m.get_long(F_TURNO);
 | |
| 			
 | |
| 			if (idturno > 0L)
 | |
| 			{
 | |
| 				leggi(idturno);
 | |
| 				riapri();
 | |
| 				return true;
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				const real cassa_ini = m.get_real(F_CASSAINI);
 | |
| 				const long ora_inizio = m.get_int(F_HINIZIO) * 10000 + m.get_int(F_MINIZIO) * 100 + m.get_int(F_SINIZIO);
 | |
| 				TLocalisamfile f(LF_TURNI);
 | |
| 
 | |
| 				_rec.put(TRN_USERNAME, m.get(F_USERNAME));
 | |
| 				_rec.put(TRN_CASSAINI, cassa_ini);
 | |
| 				_rec.put(TRN_CASSAFIN, cassa_ini);
 | |
| 				_rec.put(TRN_DATA, m.get_date(F_DATA));
 | |
| 				_rec.put(TRN_INIZIO, ora_inizio);
 | |
| 				_rec.put(TRN_FNDOC, fndoc);
 | |
| 				_err = _rec.write(f);
 | |
| 			}
 | |
| 			return _err == NOERR;
 | |
| 		}
 | |
| 	}
 | |
| 	return false;
 | |
| }
 | |
| 
 | |
| // @ cmember riapri il turno
 | |
| bool TTurno_vendita::riapri()
 | |
| {
 | |
| 	_rec.zero(TRN_CHIUSO);
 | |
| 	return true;
 | |
| }
 | |
| 
 | |
| // @ cmember chiudi il turno
 | |
| bool TTurno_vendita::chiudi()
 | |
| {
 | |
| 	if (!riaperto())
 | |
| 		leggi(-1);
 | |
| 	if (chiuso())
 | |
| 		return error_box(FR("Turno chiuso"));
 | |
| 
 | |
| 	TChiudi_mask m(*this);
 | |
| 	TArray inc;
 | |
| 	real resti, sospesi;
 | |
| 	const TString user = _rec.get(TRN_USERNAME);
 | |
| 	const long fndoc = _rec.get_long(TRN_FNDOC);
 | |
| 	const long lndoc = _rec.get_long(TRN_LNDOC);
 | |
| 	const long ora = daytime();
 | |
| 	int numscontr = 0;
 | |
| 	
 | |
| 	m.set(F_CASSA, _cassa);
 | |
| 	m.set(F_DATA, _rec.get(TRN_DATA));
 | |
| 	m.set(F_USERNAME, user);
 | |
|   m.set(F_CASSAINI, _rec.get(TRN_CASSAINI));
 | |
| 	m.set(F_HFINE, ora / 10000);
 | |
| 	m.set(F_MFINE, (ora / 100) % 100);
 | |
| 	m.set(F_SFINE, ora % 100);
 | |
| 	m.set(F_CASSAFIN, _rec.get(TRN_CASSAFIN));
 | |
| 	m.set(F_DIFF, _rec.get(TRN_DIFF));
 | |
| 
 | |
| 	for (int i = 0; i <= 8; i++)
 | |
| 	  inc.add(ZERO);
 | |
| 
 | |
|   long ndoc;
 | |
| 	for (ndoc = fndoc; ndoc <= lndoc; ndoc++)
 | |
| 	{
 | |
| 		TDocumento d('D', _anno, _codnum, ndoc);
 | |
| 
 | |
| 		if (user == d.get(TRN_USERNAME))
 | |
| 		{
 | |
| 			if (d.chiuso())
 | |
| 			{
 | |
| 				(real &) inc[1] += d.get_real(TRN_INC01);
 | |
| 				(real &) inc[2] += d.get_real(TRN_INC02);
 | |
| 				(real &) inc[3] += d.get_real(TRN_INC03);
 | |
| 				(real &) inc[4] += d.get_real(TRN_INC04);
 | |
| 				(real &) inc[5] += d.get_real(TRN_INC05);
 | |
| 				(real &) inc[6] += d.get_real(TRN_INC06);
 | |
| 				(real &) inc[7] += d.get_real(TRN_INC07);
 | |
| 				(real &) inc[8] += d.get_real(TRN_INC08);
 | |
| 			}
 | |
| 			else
 | |
| 				sospesi = d.totale_doc();
 | |
| 			resti += d.get_real(TRN_RESTI);
 | |
| 			numscontr++;
 | |
| 		}
 | |
| 	}
 | |
| 	m.set(F_INC01, (real &) inc[1]);
 | |
| 	m.set(F_INC02, (real &) inc[2]);
 | |
| 	m.set(F_INC03, (real &) inc[3]);
 | |
| 	m.set(F_INC04, (real &) inc[4]);
 | |
| 	m.set(F_INC05, (real &) inc[5]);
 | |
| 	m.set(F_INC06, (real &) inc[6]);
 | |
| 	m.set(F_INC07, (real &) inc[7]);
 | |
| 	m.set(F_INC08, (real &) inc[8]);
 | |
| 	m.set(F_SOSPESI, sospesi);
 | |
| 	m.set(F_RESTI, resti);
 | |
| 
 | |
| 	const real diff = m.calcola_differenza();
 | |
| 
 | |
| 	m.set(F_DIFF, diff);
 | |
| 
 | |
| 	if (m.run() == K_ENTER)
 | |
| 	{
 | |
| 		TLocalisamfile f(LF_TURNI);
 | |
| 
 | |
| 		if (_rec.get(TRN_FINE).blank())
 | |
| 		{
 | |
| 			const long ora_fine = m.get_int(F_HFINE) * 10000 + m.get_int(F_MFINE) * 100 + m.get_int(F_SFINE);
 | |
| 			_rec.put(TRN_FINE, ora_fine);
 | |
| 		}
 | |
| 		_rec.put(TRN_CHIUSO, (bool) true);
 | |
| 		_rec.put(TRN_INC01, m.get_real(F_INC01));
 | |
| 		_rec.put(TRN_INC02, m.get_real(F_INC02));
 | |
| 		_rec.put(TRN_INC03, m.get_real(F_INC03));
 | |
| 		_rec.put(TRN_INC04, m.get_real(F_INC04));
 | |
| 		_rec.put(TRN_INC05, m.get_real(F_INC05));
 | |
| 		_rec.put(TRN_INC06, m.get_real(F_INC06));
 | |
| 		_rec.put(TRN_INC07, m.get_real(F_INC07));
 | |
| 		_rec.put(TRN_INC08, m.get_real(F_INC08));
 | |
| 		_rec.put(TRN_SOSPESI, m.get_real(F_SOSPESI));
 | |
| 		_rec.put(TRN_CASSAFIN, m.get_real(F_CASSAFIN));
 | |
| 		_rec.put(TRN_DIFF, m.get_real(F_DIFF));
 | |
| 		_rec.put(TRN_LNDOC, ndoc);
 | |
| 		_rec.put(TRN_NUMSCONTR, numscontr);
 | |
| 		_err = _rec.rewrite(f);
 | |
| 		if (_err == NOERR)
 | |
| 		{
 | |
| 			TReport & rep = report();
 | |
| 			TReport_book book;
 | |
| 			TVariant var;
 | |
| 
 | |
| 			var = _rec.get(TRN_CODCASSA);
 | |
| 			rep.recordset()->set_var("#CODCASSA", var);
 | |
| 			var =  _rec.get(TRN_ANNO);
 | |
| 			rep.recordset()->set_var("#ANNO", var);
 | |
| 			var =  _rec.get(TRN_PROGR);
 | |
| 			rep.recordset()->set_var("#PROGR", var);
 | |
| 		
 | |
| 			book.add(rep);
 | |
| 			book.print_or_preview();
 | |
| 			return true;
 | |
| 		}
 | |
| 		else
 | |
| 			return error_box(FR("Errore di scrittura turno %d"), _err);
 | |
| 	}
 | |
| 	return false;
 | |
| }
 | |
| 
 | |
| const real TTurno_vendita::cassa_attuale()
 | |
| {
 | |
| 	if (!riaperto())
 | |
| 		leggi();
 | |
| 	return _rec.get_real(TRN_CASSAFIN);
 | |
| }
 | |
| 
 | |
| bool TTurno_vendita::aggiorna(const long ndoc, const real & saldo)
 | |
| {
 | |
| 	if (!riaperto())
 | |
| 		leggi();
 | |
| 	if (chiuso())
 | |
| 		return error_box(FR("Turno chiuso"));
 | |
| 
 | |
| 	TLocalisamfile f(LF_TURNI);
 | |
| 	const long fndoc = _rec.get_long(TRN_FNDOC);
 | |
| 	const long lndoc = _rec.get_long(TRN_LNDOC);
 | |
| 
 | |
| 	if (ndoc < fndoc)
 | |
| 		_rec.put(TRN_FNDOC, ndoc);
 | |
| 	if (ndoc > lndoc)
 | |
| 		_rec.put(TRN_LNDOC, ndoc);
 | |
| 	_rec.put(TRN_CASSAFIN, saldo);
 | |
| 
 | |
| 	_err = _rec.rewrite(f);
 | |
| 		if (_err != NOERR)
 | |
| 			return error_box(FR("Errore di scrittura turno %d"), _err);
 | |
| 	return true;
 | |
| }
 | |
| 
 | |
| bool TTurno_vendita::aperto() const 
 | |
| {
 | |
| 	return _rec.get_long(TRN_INIZIO) > 0L && !_rec.get_bool(TRN_CHIUSO);
 | |
| }
 | |
| 
 | |
| const TString & TTurno_vendita::user() const
 | |
| {
 | |
| 	return _rec.get(TRN_USERNAME);
 | |
| }
 | |
| 
 | |
| int TTurno_vendita::nturno() const
 | |
| {
 | |
| 	return _rec.get_int(TRN_PROGR);
 | |
| }
 | |
| 
 | |
| TTurno_vendita::TTurno_vendita() : _rec(LF_TURNI)
 | |
| {
 | |
| 	{
 | |
| 		TConfig w(CONFIG_WST);
 | |
| 	
 | |
| 		_cassa = w.get_int("NCASSA");
 | |
| 	}
 | |
| 
 | |
| 	_anno = TDate(TODAY).year();
 | |
| 	TConfig d(CONFIG_DITTA);
 | |
| 	
 | |
| 	_codnum = d.get("CODNUM");
 | |
| 	if (_codnum.empty())
 | |
| 		fatal_box(TR("E' necessario configurare il modulo prima di utilizzare questo programma!"));
 | |
| 	_rep.load("vdlib02r");
 | |
| 	leggi();
 | |
| }
 | |
| 
 | |
| TOperatore::TOperatore(const char * user) : _rec(LF_TAB)
 | |
| {
 | |
| 	_rec = cache().get("OPD", user);
 | |
| 	const TString & gruppo = cache().get(LF_USER, user, USR_GROUPNAME);
 | |
| 
 | |
| 	if (gruppo.full())
 | |
| 	{
 | |
| 		const TRectype & recgr = cache().get("OPD", gruppo);
 | |
| 
 | |
| 		if(!recgr.empty())
 | |
| 		{
 | |
| 			if (max_scontrino() <= ZERO)
 | |
| 				_rec.put("R0", recgr.get_real("R0"));
 | |
| 			if (max_abbuono() <= ZERO)
 | |
| 				_rec.put("R1", recgr.get_real("R1"));
 | |
| 			if (!can_change_price())
 | |
| 				_rec.put("B0", recgr.get_bool("B0"));
 | |
| 			if (!can_sotto_costo())
 | |
| 				_rec.put("B1", recgr.get_bool("B1"));
 | |
| 			if (!can_change_omaggi())
 | |
| 				_rec.put("B2", recgr.get_bool("B2"));
 | |
| 			if (!can_change_sconti())
 | |
| 				_rec.put("B3", recgr.get_bool("B3"));
 | |
| 			if (!can_resi())
 | |
| 				_rec.put("B4", recgr.get_bool("B4"));
 | |
| 			if (!can_invoice())
 | |
| 				_rec.put("B5", recgr.get_bool("B5"));
 | |
| 			if (max_sconto() <= ZERO)
 | |
| 				_rec.put("R2", recgr.get_real("R2"));
 | |
| 			if (provvigione() <= ZERO)
 | |
| 				_rec.put("R3", recgr.get_real("R3"));
 | |
| 		}
 | |
| 	}
 | |
| }
 | |
| 
 |