Files correlati : Ricompilazione Demo : [ ] Commento : aggiunto metodo ai clifor per raccattare il listino valido di un cliente in una certa data git-svn-id: svn://10.65.10.50/branches/R_10_00@21386 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			328 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			328 lines
		
	
	
		
			7.9 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include <applicat.h>
 | 
						||
#include <modaut.h>
 | 
						||
#include <relation.h>
 | 
						||
 | 
						||
#include "clifor.h"
 | 
						||
#include "condv.h"
 | 
						||
#include "velib.h"
 | 
						||
#include "../li/letint.h"
 | 
						||
#include "../cg/cfban.h" 
 | 
						||
 | 
						||
TOccasionale::TOccasionale() : TRectype(LF_OCCAS)
 | 
						||
{ }
 | 
						||
TOccasionale::TOccasionale(const TRectype& r) : TRectype(r)
 | 
						||
{ }
 | 
						||
 | 
						||
TOccasionale::TOccasionale(const TOccasionale& r) : TRectype(r)
 | 
						||
{
 | 
						||
}
 | 
						||
 | 
						||
TRectype& TOccasionale::operator=(const TRectype& r)
 | 
						||
{
 | 
						||
  return TRectype::operator=(r);
 | 
						||
}
 | 
						||
 | 
						||
TOccasionale& TOccasionale::operator=(const TOccasionale& r)
 | 
						||
{        
 | 
						||
  TRectype::operator=(r);
 | 
						||
  return *this;
 | 
						||
}
 | 
						||
 | 
						||
TOccasionale::~TOccasionale()
 | 
						||
{ }
 | 
						||
 | 
						||
int TCli_for::write_rewrite(TBaseisamfile& f, bool re) const
 | 
						||
{  
 | 
						||
  int err = TMultiple_rectype::write_rewrite(f, re);
 | 
						||
 | 
						||
  if (err == NOERR)
 | 
						||
  {     
 | 
						||
    TLocalisamfile v(LF_CFVEN);
 | 
						||
    TRectype & v_rec = vendite();
 | 
						||
    err = v.write(v_rec);
 | 
						||
    if (err == _isreinsert)
 | 
						||
      err = v.write(v_rec);
 | 
						||
  }
 | 
						||
  return err;
 | 
						||
}
 | 
						||
 | 
						||
TRectype& TCli_for::vendite() const
 | 
						||
{                             
 | 
						||
  const char t = tipo();
 | 
						||
  const long c = codice();
 | 
						||
  
 | 
						||
  if (_ven_rec.empty() || t != *(const char *) (*_ven_tipo) || c != (long) *_ven_codice)
 | 
						||
  {
 | 
						||
    TLocalisamfile v(LF_CFVEN);
 | 
						||
    TRectype& vr = ((TCli_for *)this)->_ven_rec;  // fool const
 | 
						||
  
 | 
						||
    vr.zero();
 | 
						||
    vr.put(CFV_TIPOCF,t);
 | 
						||
    vr.put(CFV_CODCF, c);
 | 
						||
    const TRectype v_rec(vr);
 | 
						||
    if (vr.read(v) != NOERR)
 | 
						||
      vr = v_rec;
 | 
						||
  }
 | 
						||
  return (TRectype &) _ven_rec;
 | 
						||
}
 | 
						||
 | 
						||
bool TCli_for::read_lettera(const TDate & data, bool extended)
 | 
						||
{
 | 
						||
 | 
						||
	if (_use_lettere)
 | 
						||
	{
 | 
						||
		if (data != _last_data)
 | 
						||
		{
 | 
						||
			_letint.zero();
 | 
						||
			TRelation * r = new TRelation(LF_LETINT);
 | 
						||
			TRectype to(r->curr());
 | 
						||
 | 
						||
			to.put(LETINT_ANNO, data.year());
 | 
						||
			to.put(LETINT_CODCLI, codice());
 | 
						||
 | 
						||
			TRectype from(to);
 | 
						||
			
 | 
						||
			from.put(LETINT_ANNO, data.year() - 1);
 | 
						||
			
 | 
						||
			TCursor c(r, "", 2 ,&from, &to);
 | 
						||
			const int items = c.items();
 | 
						||
 | 
						||
			if (items > 0)
 | 
						||
			{
 | 
						||
				TDate dal;
 | 
						||
				TDate al(31, 12, data.year());
 | 
						||
			
 | 
						||
				for (long pos = items - 1; pos >= 0L; pos--)
 | 
						||
				{
 | 
						||
					c = pos;
 | 
						||
 | 
						||
					const int tipo = c.curr().get_int(LETINT_TIPOOP);
 | 
						||
 | 
						||
					if (tipo == 3)
 | 
						||
					{
 | 
						||
						dal = c.curr().get_date(LETINT_DAL);
 | 
						||
						al = c.curr().get_date(LETINT_AL);
 | 
						||
					}
 | 
						||
					else
 | 
						||
					{
 | 
						||
						dal = c.curr().get_date(LETINT_VSDATA);
 | 
						||
						if (c.pos() < items - 1)
 | 
						||
						{
 | 
						||
							++c;
 | 
						||
							const int tipo_next = c.curr().get_int(LETINT_TIPOOP);
 | 
						||
							if (tipo_next == 3)
 | 
						||
								al = c.curr().get_date(LETINT_DAL);
 | 
						||
							else
 | 
						||
								al = c.curr().get_date(LETINT_VSDATA);
 | 
						||
							--c;
 | 
						||
						}
 | 
						||
					}
 | 
						||
					if (dal <= data)
 | 
						||
					{
 | 
						||
						_letint = c.curr();
 | 
						||
						break;
 | 
						||
					}
 | 
						||
				}
 | 
						||
				_lettera_found = !_letint.empty();
 | 
						||
				if (_lettera_found && !extended)
 | 
						||
					_lettera_found = data <= al;
 | 
						||
			}
 | 
						||
			_last_data = data;
 | 
						||
		}
 | 
						||
	}
 | 
						||
	return _lettera_found;
 | 
						||
}
 | 
						||
 | 
						||
int TCli_for::read(const TRectype & rec, word op, word lockop)
 | 
						||
{   
 | 
						||
  _ven_rec.zero();
 | 
						||
  int err = TMultiple_rectype::read(rec, op, lockop);
 | 
						||
	_last_data = botime;
 | 
						||
  return err;
 | 
						||
}
 | 
						||
 | 
						||
int TCli_for::read(char tipo, long codice, word op, word lockop)
 | 
						||
{                      
 | 
						||
  int err = NOERR;
 | 
						||
  _ven_rec.zero();
 | 
						||
  zero();
 | 
						||
  if (tipo > ' ' && codice > 0L)
 | 
						||
  {
 | 
						||
    put(CLI_TIPOCF, tipo);
 | 
						||
    put(CLI_CODCF, codice);
 | 
						||
    err = TMultiple_rectype::read(op, lockop);
 | 
						||
  }
 | 
						||
	_last_data = botime;
 | 
						||
  return err;
 | 
						||
}      
 | 
						||
 | 
						||
int TCli_for::remove(TBaseisamfile& f) const
 | 
						||
{
 | 
						||
  TLocalisamfile v(LF_CFVEN);
 | 
						||
  
 | 
						||
  const int err = vendite().remove(v);
 | 
						||
  if (err != NOERR && err != _iskeynotfound)
 | 
						||
    return err;
 | 
						||
  return TMultiple_rectype:: remove(f);
 | 
						||
}
 | 
						||
 | 
						||
void TCli_for::init()
 | 
						||
{
 | 
						||
  _tipo = new TRecfield(*this, CLI_TIPOCF);
 | 
						||
  _codice = new TRecfield(*this, CLI_CODCF);
 | 
						||
  _ven_tipo = new TRecfield(_ven_rec, CFV_TIPOCF);
 | 
						||
  _ven_codice = new TRecfield(_ven_rec, CFV_CODCF);
 | 
						||
	_use_lettere = main_app().has_module(LIAUT, CHK_DONGLE);
 | 
						||
	if (_use_lettere)
 | 
						||
		_use_lettere = ini_get_bool(CONFIG_DITTA, "ve", "USELETTERE");
 | 
						||
}
 | 
						||
 | 
						||
const TString& TCli_for::find_listino_al(const TDate& datadoc) const
 | 
						||
{
 | 
						||
  const bool gest_list_catven = ini_get_bool(CONFIG_DITTA, "ve", "GESLISCV", false, 1);
 | 
						||
  const TRectype& v = vendite();
 | 
						||
  TString4 listino = v.get(CFV_CODLIST);
 | 
						||
 | 
						||
  //se il cliente ha un listino specificato -> va usato (previo controllo validit<69>)
 | 
						||
  while (listino.full())
 | 
						||
  {
 | 
						||
    TToken_string key_condv;
 | 
						||
    key_condv.add("L");
 | 
						||
    if (gest_list_catven)
 | 
						||
      key_condv.add(v.get(CFV_CATVEN));
 | 
						||
    else
 | 
						||
      key_condv.add("");
 | 
						||
    key_condv.add("");
 | 
						||
    key_condv.add("");
 | 
						||
    key_condv.add(listino);
 | 
						||
    const TRectype& rec_condv = cache().get(LF_CONDV, key_condv);
 | 
						||
 | 
						||
    const TDate inizio_validita = rec_condv.get_date(CONDV_VALIN);
 | 
						||
    const TDate fine_validita = rec_condv.get_date(CONDV_VALFIN);
 | 
						||
    
 | 
						||
    //usa il listino indicato sul cliente solo se <20> valido per la data del documento
 | 
						||
    if (datadoc >= inizio_validita && (datadoc <= fine_validita || !fine_validita.ok()))
 | 
						||
      break;
 | 
						||
    else
 | 
						||
      listino = rec_condv.get(CONDV_CODLISSUCC);
 | 
						||
  }
 | 
						||
  return get_tmp_string() = listino;
 | 
						||
}
 | 
						||
 | 
						||
void TCli_for::cli2doc(TDocumento & doc)
 | 
						||
{
 | 
						||
	const TRectype & v = vendite();
 | 
						||
 | 
						||
	doc.put(DOC_CODVAL, get(CLI_CODVAL));
 | 
						||
	doc.put(DOC_CODLIN, get(CLI_CODLIN));
 | 
						||
	doc.put(DOC_CODPAG, get(CLI_CODPAG));
 | 
						||
 | 
						||
	TToken_string key;
 | 
						||
 | 
						||
	key.add(get(CLI_TIPOCF));
 | 
						||
	key.add(get(CLI_CODCF));
 | 
						||
	key.add("V");
 | 
						||
	key.add("1");
 | 
						||
 | 
						||
	const TRectype & cfban = cache().get(LF_CFBAN, key);
 | 
						||
 | 
						||
	if (cfban.empty())
 | 
						||
	{
 | 
						||
		doc.put(DOC_CODCABA, get(CLI_CODCAB));
 | 
						||
		doc.put(DOC_CODABIA, get(CLI_CODABI));
 | 
						||
		doc.put(DOC_IBAN, get(CLI_IBAN));
 | 
						||
	}
 | 
						||
	else
 | 
						||
	{
 | 
						||
		doc.put(DOC_CODABIA, cfban.get(CFBAN_ABI));
 | 
						||
		doc.put(DOC_CODCABA, cfban.get(CFBAN_CAB));
 | 
						||
		doc.put(DOC_IBAN, get(CFBAN_IBAN));
 | 
						||
	}
 | 
						||
 | 
						||
 | 
						||
	key.cut(0);
 | 
						||
	key.add(get(CLI_TIPOCF));
 | 
						||
	key.add(get(CLI_CODCF));
 | 
						||
	key.add("N");
 | 
						||
	key.add("1");
 | 
						||
 | 
						||
	const TRectype & cfbanpr = cache().get(LF_CFBAN, key);
 | 
						||
 | 
						||
	// Setta i campi che appartengono al file LF_CFVEN
 | 
						||
	if (cfbanpr.empty())
 | 
						||
	{
 | 
						||
		doc.put(DOC_CODABIP, v.get(CFV_CODABIPR));
 | 
						||
		doc.put(DOC_CODCABP, v.get(CFV_CODCABPR));
 | 
						||
	}
 | 
						||
	else
 | 
						||
	{
 | 
						||
		doc.put(DOC_CODABIP, cfbanpr.get(CFBAN_ABI));
 | 
						||
		doc.put(DOC_CODCABP, cfbanpr.get(CFBAN_CAB));
 | 
						||
		doc.put(DOC_PROGBNP, cfbanpr.get(CFBAN_PROGPR));
 | 
						||
	}
 | 
						||
	doc.put(DOC_RAGGR, v.get(CFV_RAGGDOC));
 | 
						||
	doc.put(DOC_RAGGREFF, v.get(CFV_RAGGEFF));
 | 
						||
	doc.put(DOC_CODINDSP, v.get(CFV_CODINDSP));
 | 
						||
	doc.put(DOC_CODAG, v.get(CFV_CODAG));
 | 
						||
	doc.put(DOC_CODAGVIS, v.get(CFV_CODAG1));
 | 
						||
	doc.put(DOC_CODSPMEZZO, v.get(CFV_CODSPMEZZO));
 | 
						||
	doc.put(DOC_CODPORTO, v.get(CFV_CODPORTO));
 | 
						||
	doc.put(DOC_CODNOTESP1, v.get(CFV_CODNOTESP1));
 | 
						||
	doc.put(DOC_CODNOTESP2, v.get(CFV_CODNOTESP2));
 | 
						||
	doc.put(DOC_CODNOTE, v.get(CFV_CODNOTE));
 | 
						||
	doc.put(DOC_CODVETT1, v.get(CFV_CODVETT1));
 | 
						||
	doc.put(DOC_CODVETT2, v.get(CFV_CODVETT2));
 | 
						||
	doc.put(DOC_CODVETT3, v.get(CFV_CODVETT3));
 | 
						||
	doc.put(DOC_PERCSPINC, v.get(CFV_PERCSPINC));	
 | 
						||
	doc.put(DOC_ADDBOLLI, v.get(CFV_ADDBOLLI));
 | 
						||
	doc.put(DOC_CATVEN, v.get(CFV_CATVEN));
 | 
						||
	doc.put(DOC_LIQDIFF, get_int(CLI_ALLEG) == 7 && v.get_bool(CFV_FATTSOSP) ? "X" : "");
 | 
						||
 | 
						||
  //listino: deve essere attiva la gestione listini nella ditta
 | 
						||
  const bool gest_listini = ini_get_bool(CONFIG_DITTA, "ve", "GES", false, 1);
 | 
						||
  if (gest_listini)
 | 
						||
  {
 | 
						||
    const TDate datadoc = doc.get_date(DOC_DATADOC);
 | 
						||
    const TString& listino = find_listino_al(datadoc);
 | 
						||
    doc.put(DOC_CODLIST, listino);
 | 
						||
  }
 | 
						||
 | 
						||
  doc.put(DOC_ZONA, v.get(CFV_CODZONA));
 | 
						||
  doc.put(DOC_RAGGR, v.get(CFV_RAGGDOC));
 | 
						||
 | 
						||
  //aggiungere gestione spese e bolli???
 | 
						||
}
 | 
						||
 | 
						||
		
 | 
						||
TCli_for::TCli_for(char tipo, long codice) : TMultiple_rectype( LF_CLIFO ), _ven_rec(LF_CFVEN),
 | 
						||
																						 _letint(LF_LETINT), _use_lettere(false), _lettera_found(false)
 | 
						||
{
 | 
						||
	init();
 | 
						||
  add_file(LF_INDSP, IND_CODIND);  
 | 
						||
  if (tipo > ' ' && codice > 0L)
 | 
						||
    read(tipo, codice);
 | 
						||
}  
 | 
						||
 | 
						||
TCli_for::TCli_for(const TRectype & rec) : TMultiple_rectype(rec), _ven_rec(LF_CFVEN),
 | 
						||
																					 _letint(LF_LETINT), _use_lettere(false), _lettera_found(false)
 | 
						||
{
 | 
						||
	init();
 | 
						||
  add_file(LF_INDSP, IND_CODIND);  
 | 
						||
  read(rec);
 | 
						||
}  
 | 
						||
 | 
						||
TCli_for::TCli_for(const TCli_for & c) : TMultiple_rectype(c), _ven_rec(c._ven_rec),
 | 
						||
																				 _letint(LF_LETINT), _use_lettere(false), _lettera_found(false)
 | 
						||
{
 | 
						||
	init();
 | 
						||
}  
 | 
						||
   
 | 
						||
TCli_for::~TCli_for()
 | 
						||
{
 | 
						||
  delete _tipo;
 | 
						||
  delete _codice;
 | 
						||
  delete _ven_tipo;
 | 
						||
  delete _ven_codice;
 | 
						||
}
 | 
						||
        
 |