Files correlati : lv2 - lv0 - lvlib - tracciati record Ricompilazione Demo : [ ] Commento : 0001104: Le date di stagionalità nei passaggi per contratto non devono contenere l'anno Descrizione Spiegazione: La stagionalità si intende già all'interno dell'anno ed è un dato che normalmente si protrae di anno in anno Se lasciato l'anno in queste date, la stagionalità non si potrà riporporre pergli anni successivi. è questo non è corretto. git-svn-id: svn://10.65.10.50/trunk@18003 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			560 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			560 lines
		
	
	
		
			14 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
#include "lvlib.h"
 | 
						|
#include "lvrcondv.h"
 | 
						|
#include "lvcondv.h"
 | 
						|
 | 
						|
#include "../cg/cglib01.h"
 | 
						|
#include "../mg/clifogiac.h"
 | 
						|
 | 
						|
#include <config.h>
 | 
						|
#include <recset.h>
 | 
						|
#include <utility.h>
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// Utilities
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
void lv_set_creation_info(TRectype& rec)
 | 
						|
{
 | 
						|
  rec.set_creation_info();
 | 
						|
}
 | 
						|
 | 
						|
void lv_set_update_info(TRectype& rec)
 | 
						|
{
 | 
						|
  rec.set_modify_info();
 | 
						|
}
 | 
						|
 | 
						|
//funzione che restituisce true se la data che gli passo è una festività
 | 
						|
bool lv_is_holiday(const TDate& data)
 | 
						|
{
 | 
						|
  static TAssoc_array calendari;
 | 
						|
 | 
						|
  const int anno = data.year();
 | 
						|
  
 | 
						|
  TString16 key;
 | 
						|
  key.format("%05ld%4d",prefix().get_codditta(),anno);
 | 
						|
 | 
						|
  TString* cal = (TString*)calendari.objptr(key);
 | 
						|
 | 
						|
  if (cal == NULL)
 | 
						|
  {
 | 
						|
    TConfig ini(CONFIG_DITTA);
 | 
						|
    cal = new TString(366);
 | 
						|
    calendari.add(key,cal);
 | 
						|
    *cal = ini.get("CAL", "lv", anno);
 | 
						|
    cal->left_just(366,'-');
 | 
						|
  }
 | 
						|
 | 
						|
  const TDate primo(1,1,anno);
 | 
						|
  const long index = data - primo;
 | 
						|
  
 | 
						|
  return (*cal)[index] == 'X';
 | 
						|
}
 | 
						|
 | 
						|
//funzione che restituisce un codice contratto valido dato cliente, indirizzo di spedizione e data
 | 
						|
long lv_find_contract(const long codcf, const long indsped, const TDate& data)
 | 
						|
{
 | 
						|
  TString query;
 | 
						|
  query << "USE LVCONDV\n"
 | 
						|
        << "SELECT BETWEEN(#DATA,DATAIN,DATASC)&&BETWEEN(CODINDSP,#INDSPED,#INDSPED)&&(PROPOSTA!=\"X\")\n"
 | 
						|
        << "FROM CODCF=#CODCF\nTO CODCF=#CODCF";
 | 
						|
  TISAM_recordset contr(query);
 | 
						|
  contr.set_var("#DATA",data);
 | 
						|
  contr.set_var("#INDSPED",indsped);
 | 
						|
  contr.set_var("#CODCF",codcf);
 | 
						|
 | 
						|
  long cod = 0L;
 | 
						|
  if (contr.move_first())
 | 
						|
    cod = contr.get("CODCONT").as_int();
 | 
						|
  
 | 
						|
  return cod;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TLaundry_contract
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
// Ritorna la riga di contratto corrispondente a codart
 | 
						|
const TRectype& TLaundry_contract::row(const char* codart) const
 | 
						|
{
 | 
						|
  TToken_string key;
 | 
						|
  key.add(get(LVRCONDV_CODCF));
 | 
						|
  key.add(get(LVRCONDV_CODCONT));
 | 
						|
  key.add(codart);
 | 
						|
  return cache().get(LF_LVRCONDV, key);
 | 
						|
}
 | 
						|
 | 
						|
// Controlla se il contratto esiste veramente
 | 
						|
bool TLaundry_contract::ok() const
 | 
						|
{ return !empty(); }
 | 
						|
 | 
						|
bool TLaundry_contract::can_be_deleted() const
 | 
						|
{
 | 
						|
  TConfig ini(CONFIG_DITTA,"lv");
 | 
						|
  const TString & codnum=ini.get("NUM_GEN");
 | 
						|
 | 
						|
  TString query;
 | 
						|
  
 | 
						|
  query << "USE DOC KEY 4 SELECT CODNUM=#CODNUM \n"
 | 
						|
        << "FROM TIPOCF=C CODCF=#CODCF PROVV=D \n"
 | 
						|
        << "TO TIPOCF=C CODCF=#CODCF PROVV=D \n";
 | 
						|
 | 
						|
  TISAM_recordset rset(query);
 | 
						|
 | 
						|
  rset.set_var("#CODNUM",TVariant(codnum));
 | 
						|
  rset.set_var("#CODCF",get_long(LVCONDV_CODCF));
 | 
						|
  
 | 
						|
  return !rset.move_first();
 | 
						|
}
 | 
						|
 | 
						|
// Legge un contratto tramite la chiave primaria cliente+codice
 | 
						|
bool TLaundry_contract::read(const long codcf, const long codcont)
 | 
						|
{
 | 
						|
  if (codcf > 0 && codcont > 0) // Campi obbligatori!
 | 
						|
  {
 | 
						|
    TString16 key; key.format("%ld|%ld", codcf, codcont);
 | 
						|
    *((TRectype*)this) = cache().get(LF_LVCONDV, key);
 | 
						|
  }
 | 
						|
  else
 | 
						|
    zero();
 | 
						|
  return ok();
 | 
						|
}
 | 
						|
 | 
						|
// Cerca il contratto in essere alla data di un certo cliente+indirizzo
 | 
						|
bool TLaundry_contract::read(const long codcf, const long indsped, const TDate& data)
 | 
						|
{
 | 
						|
  const long codcont = lv_find_contract(codcf, indsped, data);
 | 
						|
  return read(codcf, codcont);
 | 
						|
}
 | 
						|
 | 
						|
// Inizializza un contratto vuoto: servira' una read successiva
 | 
						|
TLaundry_contract::TLaundry_contract() : TRectype(LF_LVCONDV)
 | 
						|
{ zero(); }
 | 
						|
 | 
						|
TLaundry_contract::TLaundry_contract(const TRectype & rec): TRectype(rec)
 | 
						|
{
 | 
						|
}
 | 
						|
// Inizializza un contratto in base alla chiave primaria
 | 
						|
TLaundry_contract::TLaundry_contract(const long codcf, const long codcont) 
 | 
						|
                 : TRectype(LF_LVCONDV)
 | 
						|
{ read(codcf, codcont); }
 | 
						|
 | 
						|
// Tenta di inizilizzare il contratto corrente di un cliente
 | 
						|
TLaundry_contract::TLaundry_contract(const long codcf, const long indsped, const TDate& data)
 | 
						|
                 : TRectype(LF_LVCONDV)
 | 
						|
{ read(codcf, indsped, data); }
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TRecmag_lavanderie
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
void TRecmag_lavanderie::update()
 | 
						|
{
 | 
						|
	if (_update_time > 0L)
 | 
						|
		return;
 | 
						|
 | 
						|
	_update_time = 1L;
 | 
						|
 | 
						|
  TString query, filter;
 | 
						|
	const int anno = get_int(CLIFOGIAC_ANNOES);
 | 
						|
	const TString4 tipocf(get(CLIFOGIAC_TIPOCF));
 | 
						|
	const long codcf = get_long(CLIFOGIAC_CODCF);
 | 
						|
  const int indsped = get_int(CLIFOGIAC_INDSPED);
 | 
						|
	const TString80 codart(get(CLIFOGIAC_CODART));
 | 
						|
	const TString80 livello(get(CLIFOGIAC_LIVELLO));
 | 
						|
  const TDate oggi(TODAY);
 | 
						|
  TDate imese;
 | 
						|
	TDate ianno;
 | 
						|
	TEsercizi_contabili & esc = esercizi();
 | 
						|
	const TArticolo & artrec = cached_article(codart);
 | 
						|
 | 
						|
	if (anno >= esc.date2esc(oggi))
 | 
						|
	{
 | 
						|
		imese = oggi;
 | 
						|
		imese.set_day(1);
 | 
						|
	  ianno.set_month(1);
 | 
						|
	}
 | 
						|
	else
 | 
						|
	{
 | 
						|
		imese = esc.esercizio(anno).fine();
 | 
						|
		ianno = imese;
 | 
						|
	}
 | 
						|
  
 | 
						|
  query="USE MOVMAG KEY 2\n";
 | 
						|
  query << "SELECT (TIPOCF='C')&&(STR(CODCF=" << codcf << "))&&(STR(CODINDSP=" << indsped << "))&&(STR(DATAREG==" << oggi << "))\n";
 | 
						|
  query << "FROM ANNOES=" << anno << "\n";
 | 
						|
  query << "TO ANNOES=" << anno << "\n";
 | 
						|
 | 
						|
  TISAM_recordset recmag(query);
 | 
						|
 | 
						|
  for (bool ok=recmag.move_first(); ok; ok=recmag.move_next())
 | 
						|
  {
 | 
						|
		const TDate datareg = recmag.get(MOVMAG_DATAREG).as_date();
 | 
						|
    TString queryrmag="USE RMOVMAG\n";
 | 
						|
		queryrmag << " SELECT (CODART=\"" << codart << "\")&&(LIVGIAC=\"" << livello << "\")\n";
 | 
						|
		queryrmag << "FROM NUMREG=" << recmag.get(MOVMAG_NUMREG) << "\n"
 | 
						|
              << "TO NUMREG=" << recmag.get(MOVMAG_NUMREG) << "\n";
 | 
						|
    
 | 
						|
    TISAM_recordset recrmag(queryrmag);
 | 
						|
 | 
						|
    for (bool ok=recrmag.move_first(); ok; ok=recrmag.move_next())
 | 
						|
    {
 | 
						|
      const TString& codcaus = recrmag.get(RMOVMAG_CODCAUS).as_string();
 | 
						|
			const TCausale_magazzino & tcaus = cached_causale_magazzino(codcaus.full() ? codcaus : recmag.get(MOVMAG_CODCAUS).as_string());
 | 
						|
      int sgn_dotin = tcaus.sgn(s_dotin);
 | 
						|
      int sgn_dotod = tcaus.sgn(s_dotod);
 | 
						|
      int sgn_dottm = tcaus.sgn(s_dottm);
 | 
						|
      int sgn_consanno = tcaus.sgn(s_consanno);
 | 
						|
      int sgn_consmese = tcaus.sgn(s_consmese);
 | 
						|
      if (sgn_dotin != 0 || sgn_dotod != 0 || sgn_dottm != 0 || sgn_consanno != 0 || sgn_consmese != 0)
 | 
						|
      {
 | 
						|
        const TString4 um = recrmag.get(RMOVMAG_UM).as_string();
 | 
						|
        const real qta = ((TArticolo &)artrec).convert_to_um(recrmag.get(RMOVMAG_QUANT).as_real(), NULL,um);
 | 
						|
 | 
						|
				_dotin += real(qta * sgn_dotin);
 | 
						|
				_dotod += real(qta * sgn_dotod);
 | 
						|
				_dottm += real(qta * sgn_dottm);
 | 
						|
				if (datareg >= ianno)
 | 
						|
					_consanno += real(qta * sgn_consanno);
 | 
						|
				if (datareg >= imese)
 | 
						|
					_consmese += real(qta * sgn_consmese);
 | 
						|
      }
 | 
						|
    }
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
int TRecmag_lavanderie::name2index(const char* fieldname) const
 | 
						|
{
 | 
						|
	if (strcmp(fieldname, "CONSANNO") == 0)
 | 
						|
		return 0;
 | 
						|
	if (strcmp(fieldname, "CONSMESE") == 0)
 | 
						|
		return 1;
 | 
						|
	return -1;
 | 
						|
}
 | 
						|
 | 
						|
TFieldtypes TRecmag_lavanderie::type(const char* fieldname) const
 | 
						|
 | 
						|
{
 | 
						|
  if (name2index(fieldname) >= 0)
 | 
						|
    return _realfld; 
 | 
						|
  return TRectype::type(fieldname);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int TRecmag_lavanderie::length(const char* fieldname) const
 | 
						|
 | 
						|
{
 | 
						|
  if (name2index(fieldname) >= 0)
 | 
						|
    return 15;
 | 
						|
  return TRectype::length(fieldname);
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
int TRecmag_lavanderie::ndec(const char* fieldname) const
 | 
						|
{
 | 
						|
  if (name2index(fieldname) >= 0)
 | 
						|
    return 5; 
 | 
						|
  return TRectype::ndec(fieldname);
 | 
						|
}
 | 
						|
 | 
						|
bool TRecmag_lavanderie::exist(const char* fieldname) const
 | 
						|
{                   
 | 
						|
  if (name2index(fieldname) >= 0)
 | 
						|
    return true;
 | 
						|
  return TRectype::exist(fieldname);
 | 
						|
}
 | 
						|
 | 
						|
const TString & TRecmag_lavanderie::get_str(const char* fieldname) const
 | 
						|
{ 
 | 
						|
	const int index = name2index(fieldname);
 | 
						|
 | 
						|
	if (index >= 0)
 | 
						|
		((TRecmag_lavanderie *)this)->update();
 | 
						|
	switch (index)
 | 
						|
	{
 | 
						|
		case  0: return	get_tmp_string() = _consanno.string();
 | 
						|
		case  1: return get_tmp_string() = _consmese.string();
 | 
						|
		default: break;
 | 
						|
	}
 | 
						|
	return TVariable_rectype::get_str(fieldname);
 | 
						|
}
 | 
						|
 | 
						|
TRecmag_lavanderie::TRecmag_lavanderie()
 | 
						|
                  : TVariable_rectype(LF_CLIFOGIAC)
 | 
						|
{
 | 
						|
}
 | 
						|
 | 
						|
TObject* TRecmag_lavanderie::dup() const
 | 
						|
{
 | 
						|
  TRecmag_lavanderie* o = new TRecmag_lavanderie(*this);
 | 
						|
  return o;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TArticolo_lavanderie
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
const TString & TArticolo_lavanderie::get_str(const char* fieldname) const
 | 
						|
{ 
 | 
						|
  if (*fieldname != '#')
 | 
						|
    return TRectype::get_str(fieldname);
 | 
						|
  char * fname = (char *) fieldname + 1;
 | 
						|
  const int logicnum = atoi(fname);
 | 
						|
  if (logicnum != LF_CLIFOGIAC)
 | 
						|
		return TArticolo_giacenza_data::get_str(fieldname);
 | 
						|
 | 
						|
  const char * op1 =  strchr(fname, '_');
 | 
						|
  int index = 0;
 | 
						|
  if (op1)
 | 
						|
  {
 | 
						|
    op1=op1+1;
 | 
						|
    fname = (char *) op1;
 | 
						|
    if (*op1 == '#')
 | 
						|
      index = atoi(fname + 1);             
 | 
						|
  }
 | 
						|
  const char * op2 = strchr(fname, '_');
 | 
						|
  if (op2) 
 | 
						|
  {
 | 
						|
    op2=op2+1;
 | 
						|
    fname = (char *) op2 + 1;
 | 
						|
  }
 | 
						|
  const char * op3 = strchr(fname, '_');
 | 
						|
  if (op3) 
 | 
						|
  {
 | 
						|
    op3=op3+1;
 | 
						|
    fname = (char *) op3 + 1;
 | 
						|
  }
 | 
						|
  const char * op4 = strchr(fname, '_');
 | 
						|
  if (op4) 
 | 
						|
  {
 | 
						|
    op4=op4+1;
 | 
						|
    fname = (char *) op2 + 1;
 | 
						|
  }
 | 
						|
  const char * op5 = strchr(fname, '_');
 | 
						|
  if (op5)
 | 
						|
    op5=op5+1;
 | 
						|
  const char * op6 = strstr(fname, "->"); 
 | 
						|
  CHECKS(op6, "Can't find '->' in string ", fieldname);
 | 
						|
  op6=op6+2;
 | 
						|
       
 | 
						|
  if (logicnum == LF_CLIFOGIAC && op2 && op3 && op4)
 | 
						|
	{
 | 
						|
		((TArticolo_lavanderie *)this)->set_tipocf(*op2);
 | 
						|
		((TArticolo_lavanderie *)this)->set_codcf(atol(op3));
 | 
						|
		((TArticolo_lavanderie *)this)->set_indsped(atol(op4));
 | 
						|
    if (index == 0)
 | 
						|
      index = find_clifomag(op1, op5);
 | 
						|
    if (index > 0)
 | 
						|
      return clifomag(op1).row(index).get(op4);
 | 
						|
	}
 | 
						|
  return EMPTY_STRING;
 | 
						|
}
 | 
						|
 | 
						|
void TArticolo_lavanderie::set_body_key(TRectype & rowrec)
 | 
						|
{
 | 
						|
  const int logicnum = rowrec.num();
 | 
						|
  const char * cod = (const char *) codice();
 | 
						|
  
 | 
						|
  switch (logicnum)
 | 
						|
  { 
 | 
						|
    case LF_CLIFOGIAC:
 | 
						|
      rowrec.put(CLIFOGIAC_ANNOES, _anno_lav);
 | 
						|
      rowrec.put(CLIFOGIAC_CODART, cod);
 | 
						|
      rowrec.put(CLIFOGIAC_TIPOCF, _tipocf);
 | 
						|
      rowrec.put(CLIFOGIAC_CODCF, _codcf);
 | 
						|
      rowrec.put(CLIFOGIAC_INDSPED, _indsped);
 | 
						|
      break;
 | 
						|
    default:
 | 
						|
      TArticolo_giacenza_data::set_body_key(rowrec);
 | 
						|
      break;
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
void TArticolo_lavanderie::set_anno_lav (int anno)
 | 
						|
{
 | 
						|
  if (_anno_lav != anno)
 | 
						|
    remove_body(LF_CLIFOGIAC);
 | 
						|
  _anno_lav = anno;
 | 
						|
}
 | 
						|
 | 
						|
TRectype * TArticolo_lavanderie::new_body_record(int logicnum)
 | 
						|
{
 | 
						|
	if (logicnum == LF_CLIFOGIAC)
 | 
						|
		return new TRecmag_lavanderie();
 | 
						|
	return new TRectype(logicnum ? logicnum : TArticolo_giacenza_data::num());
 | 
						|
}
 | 
						|
 | 
						|
int TArticolo_lavanderie::find_clifomag(TRecord_array& rclifomag, const char * livello, int from) const
 | 
						|
 | 
						|
{
 | 
						|
  const int last = rclifomag.last_row();
 | 
						|
 | 
						|
  if (last > 0 && from < last)
 | 
						|
  {
 | 
						|
    const int livello_len = livello ? strlen(livello) : 0;   
 | 
						|
    
 | 
						|
    if (livello_len == 0)
 | 
						|
      return from + 1;
 | 
						|
 | 
						|
    for (int i = rclifomag.succ_row(from); i <= last; i = rclifomag.succ_row(i))
 | 
						|
    {
 | 
						|
      const TRectype & rec = rclifomag.row(i);
 | 
						|
    
 | 
						|
			if (livello_len == 0 || rec.get(CLIFOGIAC_LIVELLO).compare(livello, livello_len) == 0)
 | 
						|
				return i;
 | 
						|
    }
 | 
						|
  }
 | 
						|
  return -1;
 | 
						|
}
 | 
						|
 | 
						|
int TArticolo_lavanderie::find_clifomag(int annoes, const char * livello, int from) const
 | 
						|
{
 | 
						|
  TRecord_array & rclifomag = clifomag(annoes);
 | 
						|
  return find_clifomag(rclifomag, livello, from);  
 | 
						|
}
 | 
						|
 | 
						|
TRecord_array & TArticolo_lavanderie::clifomag(int annoes) const
 | 
						|
{
 | 
						|
	((TArticolo_lavanderie*)this)->set_anno_lav(annoes > 0 ? annoes : esercizi().last_mag());
 | 
						|
  return body(LF_CLIFOGIAC);
 | 
						|
}
 | 
						|
 | 
						|
TArticolo_lavanderie::TArticolo_lavanderie(const char* codice, const char tipocf, const long codcf, const int indsped)
 | 
						|
										 : TArticolo_giacenza_data(codice), _anno_lav(0),
 | 
						|
										   _tipocf(tipocf), _codcf(codcf), _indsped(indsped)
 | 
						|
 | 
						|
{
 | 
						|
  add_file(LF_CLIFOGIAC ,"NRIGA");
 | 
						|
}
 | 
						|
 | 
						|
TArticolo_lavanderie::TArticolo_lavanderie(const TRectype & rec, const char tipocf, const long codcf, const int indsped)
 | 
						|
										 : TArticolo_giacenza_data(rec), _anno_lav(0),
 | 
						|
										   _tipocf(tipocf), _codcf(codcf), _indsped(indsped)
 | 
						|
 | 
						|
{
 | 
						|
  add_file(LF_CLIFOGIAC ,"NRIGA");
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TCache_articoli_lavanderie
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
class TCache_articoli_lavanderie : public TRecord_cache
 | 
						|
{
 | 
						|
protected:
 | 
						|
  virtual TObject* rec2obj(const TRectype& rec) const { return new TArticolo_lavanderie(rec);}
 | 
						|
 | 
						|
public:
 | 
						|
  TArticolo_lavanderie& lav(const char* key) { return (TArticolo_lavanderie&)query(key); }
 | 
						|
 | 
						|
	TCache_articoli_lavanderie();
 | 
						|
  virtual ~TCache_articoli_lavanderie() { }
 | 
						|
};
 | 
						|
 | 
						|
TCache_articoli_lavanderie::TCache_articoli_lavanderie()
 | 
						|
												   : TRecord_cache(LF_ANAMAG, 1)
 | 
						|
{ 
 | 
						|
  test_file_changes();   // Tieni d'occhio le modifiche sul file
 | 
						|
  set_items_limit(256);  // Standard
 | 
						|
}        
 | 
						|
 | 
						|
TArticolo_lavanderie & cached_article_laundry(const char * codart, const char tipocf, const long codcf, const int indsped)
 | 
						|
{
 | 
						|
	HIDDEN TCache_articoli_lavanderie __cache_articoli_lavanderie;
 | 
						|
 | 
						|
	TArticolo_lavanderie & art = __cache_articoli_lavanderie.lav(codart);
 | 
						|
	
 | 
						|
	art.set_tipocf(tipocf);
 | 
						|
	art.set_codcf(codcf);
 | 
						|
	art.set_indsped(indsped);
 | 
						|
	return art;
 | 
						|
}
 | 
						|
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
// TLavanderie_calendar
 | 
						|
///////////////////////////////////////////////////////////
 | 
						|
 | 
						|
// Serve per aggiungere le feste dei Patroni
 | 
						|
void TLavanderie_calendar::set_holiday(const TDate & date, bool holiday)
 | 
						|
{
 | 
						|
	if (_year == date.year())
 | 
						|
	{
 | 
						|
		const TDate inizio(1, 1, _year);
 | 
						|
		long ndays = date - inizio;
 | 
						|
 | 
						|
		_days.set(ndays, holiday);
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
bool TLavanderie_calendar::is_holiday(const TDate& date) const
 | 
						|
{
 | 
						|
	if (_year == date.year())
 | 
						|
	{
 | 
						|
		const TDate inizio(1, 1, _year);
 | 
						|
		long ndays = date - inizio;
 | 
						|
		
 | 
						|
		return _days[ndays];
 | 
						|
	}
 | 
						|
	return false;
 | 
						|
}
 | 
						|
 | 
						|
int TLavanderie_calendar::read(int year)
 | 
						|
{
 | 
						|
	if (year != 0)
 | 
						|
		_year = year;
 | 
						|
 | 
						|
	TConfig cfg(CONFIG_DITTA);
 | 
						|
	const TString val = cfg.get("CAL", "lv", _year);
 | 
						|
	
 | 
						|
	if (val.full())
 | 
						|
	{
 | 
						|
		const int len = val.len();
 | 
						|
		for (int i = 0; i < len; i++)
 | 
						|
			_days.set(i, val[i] == 'X');
 | 
						|
	}
 | 
						|
	else
 | 
						|
	{
 | 
						|
		const TDate inizio(1, 1, _year);
 | 
						|
		const TDate fine(31, 12, _year);
 | 
						|
		TDate data(inizio);
 | 
						|
 | 
						|
		for (int i = 0;  data <= fine; ++data, i++)
 | 
						|
			_days.set(i, data.is_holiday());
 | 
						|
	}
 | 
						|
  
 | 
						|
  return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
int TLavanderie_calendar::write() const
 | 
						|
{
 | 
						|
	TString val(366);
 | 
						|
	const TDate inizio(1, 1, _year);
 | 
						|
	const TDate fine(31, 12, _year);
 | 
						|
	TDate data(inizio);
 | 
						|
  TConfig cfg(CONFIG_DITTA);
 | 
						|
 | 
						|
	for (int i = 0;  data <= fine; ++data, i++)
 | 
						|
		val << (_days[i] ? 'X' : '-');
 | 
						|
	cfg.set("CAL", val, "lv", true, _year);
 | 
						|
	return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
int TLavanderie_calendar::remove() const
 | 
						|
{
 | 
						|
	TString val(366);
 | 
						|
  TConfig cfg(CONFIG_DITTA);
 | 
						|
	const TDate inizio(1, 1, _year);
 | 
						|
	const TDate fine(31, 12, _year);
 | 
						|
	TDate data(inizio);
 | 
						|
 | 
						|
	for (int i = 0;  data <= fine; ++data, i++)
 | 
						|
		val << data.is_holiday() ? 'X' : '-';
 | 
						|
	cfg.set("CAL", val, "lv", true, _year);
 | 
						|
  return NOERR;
 | 
						|
}
 | 
						|
 | 
						|
TLavanderie_calendar::TLavanderie_calendar(const int year) : _year(year)
 | 
						|
{
 | 
						|
	read();
 | 
						|
}
 | 
						|
 |