2008-08-12 15:11:26 +00:00
|
|
|
#include "lvlib.h"
|
2008-10-28 20:07:09 +00:00
|
|
|
#include "..\mg\clifogiac.h"
|
2008-08-12 15:11:26 +00:00
|
|
|
|
2008-11-01 18:09:05 +00:00
|
|
|
#include <config.h>
|
|
|
|
#include <date.h>
|
2008-10-28 20:07:09 +00:00
|
|
|
#include <recset.h>
|
2008-08-12 15:11:26 +00:00
|
|
|
#include <utility.h>
|
2008-10-28 20:07:09 +00:00
|
|
|
#include "../cg/cglib01.h"
|
2008-08-12 15:11:26 +00:00
|
|
|
|
|
|
|
void lv_set_creation_info(TRectype& rec)
|
|
|
|
{
|
2008-08-27 12:56:29 +00:00
|
|
|
rec.set_creation_info();
|
2008-08-12 15:11:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void lv_set_update_info(TRectype& rec)
|
|
|
|
{
|
2008-08-27 12:56:29 +00:00
|
|
|
rec.set_modify_info();
|
2008-08-12 15:11:26 +00:00
|
|
|
}
|
2008-10-28 20:07:09 +00:00
|
|
|
|
|
|
|
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 3\n";
|
|
|
|
query << "SELECT (TIPOCF='C')&&(STR(CODCF=" << codcf << "))&&(STR(CODINDSP=" << indsped << "))\n";
|
|
|
|
query << "TO DATAREG=" << oggi << "\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);
|
|
|
|
|
2008-11-11 16:23:43 +00:00
|
|
|
_dotin += real(qta * sgn_dotin);
|
|
|
|
_dotod += real(qta * sgn_dotod);
|
|
|
|
_dottm += real(qta * sgn_dottm);
|
2008-10-28 20:07:09 +00:00
|
|
|
if (datareg >= ianno)
|
2008-11-11 16:23:43 +00:00
|
|
|
_consanno += real(qta * sgn_consanno);
|
2008-10-28 20:07:09 +00:00
|
|
|
if (datareg >= imese)
|
2008-11-11 16:23:43 +00:00
|
|
|
_consmese += real(qta * sgn_consmese);
|
2008-10-28 20:07:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TRecmag_lavanderie::name2index(const char* fieldname) const
|
|
|
|
{
|
|
|
|
if (strcmp(fieldname, "DOTIN") == 0)
|
|
|
|
return 0;
|
|
|
|
if (strcmp(fieldname, "DOTOD") == 0)
|
|
|
|
return 1;
|
|
|
|
if (strcmp(fieldname, "DOTTM") == 0)
|
|
|
|
return 2;
|
|
|
|
if (strcmp(fieldname, "CONSANNO") == 0)
|
|
|
|
return 3;
|
|
|
|
if (strcmp(fieldname, "CONSMESE") == 0)
|
|
|
|
return 4;
|
|
|
|
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 18;
|
|
|
|
return TRectype::length(fieldname);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int TRecmag_lavanderie::ndec(const char* fieldname) const
|
|
|
|
{
|
|
|
|
if (name2index(fieldname) >= 0)
|
|
|
|
return 3;
|
|
|
|
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 _dotin.as_string();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
return _dotod.as_string();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
return _dottm.as_string();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
return _consanno.as_string();
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
return _consmese.as_string();
|
|
|
|
break;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// TArticolo_lavanderie_cache
|
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-11-01 18:09:05 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// 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);
|
|
|
|
_dirty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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, "lv");
|
|
|
|
TString8 varname("CAL");
|
|
|
|
|
|
|
|
varname << _year;
|
|
|
|
_days.reset();
|
|
|
|
const TString val = cfg.get(varname);
|
|
|
|
|
|
|
|
if (val.full())
|
|
|
|
{
|
|
|
|
const int len = val.len();
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
_days.set(i, val[i] != ' ');
|
|
|
|
}
|
|
|
|
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() || data.wday() == 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLavanderie_calendar::write() const
|
|
|
|
{
|
|
|
|
if (_dirty)
|
|
|
|
{
|
|
|
|
TConfig cfg(CONFIG_DITTA, "lv");
|
|
|
|
TString8 varname("CAL");
|
|
|
|
|
|
|
|
varname << _year;
|
|
|
|
TString val(255);
|
|
|
|
const TDate inizio(1, 1, _year);
|
|
|
|
const TDate fine(31, 12, _year);
|
|
|
|
TDate data(inizio);
|
|
|
|
|
|
|
|
for (int i = 0; data <= fine; ++data, i++)
|
|
|
|
val << (_days[i] ? 'X' : ' ');
|
|
|
|
cfg.set(varname, val);
|
|
|
|
}
|
|
|
|
((TLavanderie_calendar *)this)->_dirty = false;
|
|
|
|
return NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLavanderie_calendar::remove() const
|
|
|
|
{
|
|
|
|
TConfig cfg(CONFIG_DITTA, "lv");
|
|
|
|
TString8 varname("CAL");
|
|
|
|
|
|
|
|
varname << _year;
|
|
|
|
TString val(255);
|
|
|
|
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(varname, val);
|
|
|
|
return NOERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
TLavanderie_calendar::TLavanderie_calendar(const int year) : _year(year), _dirty(false)
|
|
|
|
{
|
|
|
|
read();
|
|
|
|
}
|
|
|
|
|