2008-09-10 09:22:52 +00:00
|
|
|
#include <automask.h>
|
|
|
|
#include <execp.h>
|
2008-12-10 11:57:25 +00:00
|
|
|
#include <progind.h>
|
2008-08-21 15:41:07 +00:00
|
|
|
#include <relapp.h>
|
|
|
|
|
|
|
|
#include "lv0400.h"
|
2008-10-28 20:07:09 +00:00
|
|
|
#include "lvlib.h"
|
|
|
|
#include "../cg/cglib01.h"
|
2008-09-04 13:44:10 +00:00
|
|
|
#include "../mg/anamag.h"
|
2008-09-11 10:34:37 +00:00
|
|
|
#include "../mg/mglib.h"
|
2008-08-21 15:41:07 +00:00
|
|
|
|
2008-09-10 09:22:52 +00:00
|
|
|
|
|
|
|
class TContratti_msk: public TAutomask
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
bool on_art_select();
|
|
|
|
virtual bool on_field_event(TOperable_field& o,TField_event e,long jolly);
|
|
|
|
public:
|
|
|
|
TContratti_msk();
|
|
|
|
};
|
|
|
|
|
|
|
|
bool TContratti_msk::on_art_select()
|
|
|
|
{
|
2008-10-28 20:07:09 +00:00
|
|
|
TSheet_field& ss = sfield(F_RIGHE);
|
|
|
|
TMask& rowmask = ss.sheet_mask();
|
2008-09-10 09:22:52 +00:00
|
|
|
TToken_string & row = ss.row(ss.selected());
|
|
|
|
const TString80 codart(row.get(ss.cid2index(S_CODART)));
|
2008-10-28 20:07:09 +00:00
|
|
|
const long codcf = get_long(F_CODCF);
|
|
|
|
const int indsped = get_int(F_INDSPED);
|
|
|
|
TArticolo_lavanderie & artrec = cached_article_laundry(codart, 'C', codcf, indsped);
|
|
|
|
TDate datasc = get_date(F_DATASC);
|
|
|
|
|
|
|
|
if (!datasc.ok())
|
|
|
|
datasc = TDate(TODAY);
|
|
|
|
const int annoes = esercizi().date2esc(datasc);
|
|
|
|
int index = artrec.find_clifomag(annoes);
|
|
|
|
|
|
|
|
if (index > 0)
|
|
|
|
{
|
|
|
|
const TString4 umcont(row.get(ss.cid2index(S_UM)));
|
|
|
|
const real dotin = artrec.convert_to_um(artrec.clifomag(annoes)[index].get_real("DOTIN"),umcont);
|
|
|
|
rowmask.set(S_DOTIN, dotin);
|
|
|
|
row.add(dotin.stringa(), ss.cid2index(S_DOTIN));
|
|
|
|
const real dotod = artrec.convert_to_um(artrec.clifomag(annoes)[index].get_real("DOTOD"),umcont);
|
|
|
|
rowmask.set(S_DOTOD, dotod);
|
|
|
|
row.add(dotod.stringa(), ss.cid2index(S_DOTOD));
|
|
|
|
const real dottmp = artrec.convert_to_um(artrec.clifomag(annoes)[index].get_real("DOTTM"),umcont);
|
|
|
|
rowmask.set(S_DOTTMP, dottmp);
|
|
|
|
row.add(dottmp.stringa(), ss.cid2index(S_DOTTMP));
|
|
|
|
const real consyear = artrec.convert_to_um(artrec.clifomag(annoes)[index].get_real("CONSANNO"),umcont);
|
|
|
|
rowmask.set(S_CONSANNO, consyear);
|
|
|
|
row.add(consyear.stringa(), ss.cid2index(S_CONSANNO));
|
|
|
|
const real consmonth = artrec.convert_to_um(artrec.clifomag(annoes)[index].get_real("CONSMESE"),umcont);
|
|
|
|
rowmask.set(S_CONSMESE, consmonth);
|
|
|
|
row.add(consmonth.stringa(), ss.cid2index(S_CONSMESE));
|
|
|
|
}
|
2008-09-11 10:34:37 +00:00
|
|
|
|
2008-10-20 08:18:31 +00:00
|
|
|
const bool varclcons = rowmask.get_int(S_PPCONF)>0;
|
2008-09-10 09:22:52 +00:00
|
|
|
|
|
|
|
ss.enable_cell(ss.selected(),ss.cid2index(S_CALCCONS));
|
|
|
|
|
2008-10-20 08:18:31 +00:00
|
|
|
rowmask.set(S_CALCCONS,"0");
|
2008-09-10 09:22:52 +00:00
|
|
|
row.add("0",ss.cid2index(S_CALCCONS));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool TContratti_msk:: on_field_event(TOperable_field& o,TField_event e,long jolly)
|
|
|
|
{
|
|
|
|
switch(o.dlg())
|
|
|
|
{
|
2008-12-12 08:29:38 +00:00
|
|
|
case F_CODCF:
|
|
|
|
if (e == fe_close)
|
|
|
|
{
|
|
|
|
if (query_mode() && o.get().blank())
|
|
|
|
return error_box("Codice Cliente Obbligatorio");
|
|
|
|
}
|
2008-09-10 09:22:52 +00:00
|
|
|
case DLG_PLANNING:
|
2008-09-15 14:26:31 +00:00
|
|
|
if (e==fe_button && edit_mode())
|
2008-09-10 09:22:52 +00:00
|
|
|
{
|
|
|
|
TRelation_application& app=(TRelation_application&) main_app();
|
|
|
|
app.get_relation()->read(_isequal,_unlock);
|
|
|
|
TString str;
|
|
|
|
str << "lv0 -4 " << get(F_CODCF) << " " << get(F_CODCONT);
|
|
|
|
TExternal_app planning(str);
|
|
|
|
planning.run();
|
|
|
|
app.get_relation()->read(_isequal,_lock);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case S_CODART:
|
2008-10-21 15:51:13 +00:00
|
|
|
if (!o.empty())
|
2008-09-10 09:22:52 +00:00
|
|
|
{
|
2008-10-21 15:51:13 +00:00
|
|
|
if (e==fe_modify)
|
|
|
|
{
|
|
|
|
TArticolo art(o.get());
|
|
|
|
if (art.um().rows() > 0)
|
|
|
|
{
|
|
|
|
TSheet_field& ss=sfield(F_RIGHE);
|
|
|
|
TMask& m = o.mask(); // maschera di riga!
|
|
|
|
const TString& um = art.um()[1].get(UMART_UM);
|
|
|
|
m.set(S_UM,um);
|
|
|
|
TToken_string& row=ss.row(ss.selected());
|
|
|
|
row.add(o.get(),ss.cid2index(S_CODART));
|
|
|
|
row.add(um,S_UM);
|
|
|
|
on_art_select();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (e==fe_init)
|
|
|
|
on_art_select();
|
2008-09-10 09:22:52 +00:00
|
|
|
}
|
2008-10-21 15:51:13 +00:00
|
|
|
break;
|
2008-09-10 09:22:52 +00:00
|
|
|
default:break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-10 13:47:37 +00:00
|
|
|
TContratti_msk::TContratti_msk():TAutomask("lv0400a")
|
2008-09-10 09:22:52 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-08-21 15:41:07 +00:00
|
|
|
class TContratti_app: public TRelation_application
|
|
|
|
{
|
2008-09-10 09:22:52 +00:00
|
|
|
TContratti_msk* _msk;
|
2008-08-21 15:41:07 +00:00
|
|
|
TRelation* _rel;
|
|
|
|
bool _unicont;
|
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
private:
|
|
|
|
void save_rows(const TMask& m);
|
|
|
|
void build_query(const TMask& m,TString& query) const;
|
|
|
|
int find_art(TSheet_field& s,const TString& art) const;
|
|
|
|
|
2008-08-21 15:41:07 +00:00
|
|
|
protected:
|
2008-09-02 10:38:36 +00:00
|
|
|
virtual TMask* get_mask (int mode) {return _msk; }
|
2008-08-21 15:41:07 +00:00
|
|
|
virtual TRelation* get_relation() const {return _rel;}
|
|
|
|
|
|
|
|
virtual bool user_create();
|
|
|
|
virtual bool user_destroy();
|
|
|
|
virtual void on_config_change();
|
|
|
|
virtual bool get_next_key(TToken_string& key);
|
2008-08-27 15:21:44 +00:00
|
|
|
virtual int read(TMask& m);
|
|
|
|
virtual int write(const TMask& m);
|
|
|
|
virtual int rewrite(const TMask& m);
|
2008-12-10 11:57:25 +00:00
|
|
|
virtual bool protected_record(TRectype & rec);
|
2008-08-27 15:21:44 +00:00
|
|
|
virtual bool remove();
|
2008-12-09 12:43:15 +00:00
|
|
|
virtual void init_query_mode(TMask& m);
|
2008-10-21 15:51:13 +00:00
|
|
|
virtual void init_insert_mode(TMask& m);
|
2008-12-10 12:03:36 +00:00
|
|
|
bool elimina_planning(const long& codcont, const long& codcf) const;
|
2008-12-10 11:57:25 +00:00
|
|
|
bool kill_planning (TISAM_recordset& selrighe) const;
|
2008-08-21 15:41:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
bool TContratti_app:: user_create()
|
|
|
|
{
|
|
|
|
_rel=new TRelation (LF_LVCONDV);
|
2008-09-10 09:22:52 +00:00
|
|
|
_msk= new TContratti_msk;
|
2008-12-09 12:43:15 +00:00
|
|
|
|
|
|
|
TSheet_field& ss=_msk->sfield(F_RIGHE);
|
|
|
|
|
|
|
|
ss.set_auto_append();
|
|
|
|
|
|
|
|
return true;
|
2008-08-21 15:41:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TContratti_app:: user_destroy()
|
|
|
|
{
|
2008-09-02 10:38:36 +00:00
|
|
|
delete _msk;
|
2008-08-21 15:41:07 +00:00
|
|
|
delete _rel;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TContratti_app:: on_config_change()
|
|
|
|
{
|
|
|
|
TConfig ini(CONFIG_DITTA);
|
|
|
|
_unicont=ini.get_bool("UniCont");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TContratti_app:: get_next_key(TToken_string& key)
|
|
|
|
{
|
2008-09-02 10:38:36 +00:00
|
|
|
const long cliente=_msk->get_long(F_CODCF);
|
2008-08-21 15:41:07 +00:00
|
|
|
if (cliente<=0) return false;
|
|
|
|
key.add(F_CODCF);
|
|
|
|
key.add(cliente);
|
|
|
|
key.add(F_CODCONT);
|
|
|
|
|
|
|
|
long codcont=0;
|
|
|
|
if (_unicont)
|
|
|
|
{
|
|
|
|
TISAM_recordset recset ("USE LVCONDV");
|
|
|
|
for (bool ok=recset.move_first(); ok; ok=recset.move_next())
|
|
|
|
{
|
|
|
|
const long codice=recset.get("CODCONT").as_int();
|
|
|
|
if (codice>codcont)
|
|
|
|
codcont=codice;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
TString query;
|
|
|
|
query<<"USE LVCONDV \n"
|
|
|
|
<<"FROM CODCF=#CLIENTE\n"
|
|
|
|
<<"TO CODCF=#CLIENTE\n";
|
|
|
|
TISAM_recordset recset (query);
|
|
|
|
recset.set_var("#CLIENTE",cliente);
|
|
|
|
if (recset.move_last())
|
|
|
|
codcont=recset.get("CODCONT").as_int();
|
|
|
|
|
|
|
|
}
|
|
|
|
codcont++;
|
|
|
|
key.add(codcont);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-02 10:38:36 +00:00
|
|
|
|
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
void TContratti_app:: build_query(const TMask& m,TString& query) const
|
|
|
|
{
|
|
|
|
query="";
|
2008-08-27 15:34:52 +00:00
|
|
|
query << "USE LVRCONDV\n"
|
2008-08-27 15:21:44 +00:00
|
|
|
<< "FROM CODCF="<<m.get(F_CODCF)<<" CODCONT="<<m.get(F_CODCONT)<<"\n"
|
|
|
|
<< "TO CODCF="<<m.get(F_CODCF)<<" CODCONT="<<m.get(F_CODCONT);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int TContratti_app:: read(TMask& m)
|
|
|
|
{
|
|
|
|
int err=TRelation_application::read(m);
|
|
|
|
if(err==NOERR)
|
|
|
|
{
|
|
|
|
TString query;
|
|
|
|
build_query(m,query);
|
|
|
|
TISAM_recordset righeset(query);
|
|
|
|
const TRectype& rec=righeset.cursor()->curr();
|
|
|
|
|
|
|
|
TSheet_field& righe=m.sfield(F_RIGHE);
|
|
|
|
TMask& msk=righe.sheet_mask();
|
|
|
|
righe.destroy();
|
|
|
|
|
|
|
|
for (bool ok=righeset.move_first(); ok; ok=righeset.move_next())
|
|
|
|
{
|
|
|
|
TToken_string& row=righe.row(-1);
|
|
|
|
FOR_EACH_MASK_FIELD(msk,i,f)
|
|
|
|
{
|
|
|
|
const TFieldref*fr=f->field();
|
|
|
|
if (fr!= NULL)
|
|
|
|
row.add(fr->read(rec),righe.cid2index(f->dlg()));
|
|
|
|
}
|
|
|
|
righe.check_row(righe.items()-1,3);
|
|
|
|
}
|
|
|
|
righe.force_update();
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TContratti_app::find_art(TSheet_field& s,const TString& art) const
|
|
|
|
{
|
|
|
|
int r=-1;
|
|
|
|
for (r=s.items()-1;r>=0;r--)
|
|
|
|
{
|
|
|
|
const char* codart= s.row(r).get(0);
|
|
|
|
if (art==codart)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
void TContratti_app::save_rows(const TMask& m)
|
|
|
|
{
|
|
|
|
TString query;
|
|
|
|
TSheet_field& righe=m.sfield(F_RIGHE);
|
|
|
|
build_query(m,query);
|
|
|
|
TISAM_recordset righeset(query);
|
|
|
|
TLocalisamfile& file=righeset.cursor()->file();
|
|
|
|
for (bool ok=righeset.move_first(); ok; ok=righeset.move_next())
|
|
|
|
{
|
|
|
|
const TString& art=righeset.get("CODART").as_string();
|
|
|
|
if (find_art(righe,art)<0)
|
|
|
|
file.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
TMask& msk=righe.sheet_mask();
|
|
|
|
FOR_EACH_SHEET_ROW(righe,r,row)
|
|
|
|
{
|
|
|
|
file.zero();
|
|
|
|
file.put("CODCF",m.get(F_CODCF));
|
|
|
|
file.put("CODCONT",m.get(F_CODCONT));
|
|
|
|
FOR_EACH_MASK_FIELD(msk,i,f)
|
|
|
|
{
|
|
|
|
const TFieldref*fr=f->field();
|
|
|
|
if (fr!= NULL)
|
|
|
|
{
|
|
|
|
const int pos=righe.cid2index(f->dlg());
|
|
|
|
fr->write(row->get(pos),file.curr());
|
|
|
|
}
|
|
|
|
}
|
2008-10-21 15:51:13 +00:00
|
|
|
if (file.get("CODART").full())
|
|
|
|
file.rewrite_write();
|
2008-08-27 15:21:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-12-09 12:43:15 +00:00
|
|
|
void TContratti_app::init_query_mode(TMask& m)
|
|
|
|
{
|
2008-12-12 08:29:38 +00:00
|
|
|
if (m.field(F_CODCF).enabled())
|
|
|
|
m.field(F_RAGSOC).enable();
|
|
|
|
else
|
|
|
|
m.field(F_RAGSOC).disable();
|
2008-12-09 12:43:15 +00:00
|
|
|
}
|
|
|
|
|
2008-10-21 15:51:13 +00:00
|
|
|
void TContratti_app::init_insert_mode(TMask& m)
|
|
|
|
{
|
|
|
|
TSheet_field& ss=m.sfield(F_RIGHE);
|
2008-12-12 08:29:38 +00:00
|
|
|
// ss.insert();
|
|
|
|
|
2008-10-21 15:51:13 +00:00
|
|
|
}
|
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
int TContratti_app::write(const TMask& m)
|
|
|
|
{
|
|
|
|
int err=TRelation_application::write(m);
|
2008-12-12 11:56:19 +00:00
|
|
|
if(err==NOERR)
|
|
|
|
{
|
|
|
|
save_rows(m);
|
|
|
|
warning_box(TR("Ricordarsi di inserire i passaggi per planning"));
|
|
|
|
}
|
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
int TContratti_app::rewrite(const TMask& m)
|
|
|
|
{
|
|
|
|
int err=TRelation_application::rewrite(m);
|
|
|
|
if(err==NOERR) save_rows(m);
|
|
|
|
return err;
|
|
|
|
}
|
2008-12-10 11:57:25 +00:00
|
|
|
|
|
|
|
bool TContratti_app::protected_record(TRectype & rec)
|
|
|
|
{
|
|
|
|
TLaundry_contract cont(rec);
|
|
|
|
return !cont.can_be_deleted();
|
|
|
|
}
|
|
|
|
|
2008-12-10 12:03:36 +00:00
|
|
|
bool TContratti_app::elimina_planning(const long& codcont, const long& codcf) const
|
2008-12-10 11:57:25 +00:00
|
|
|
{
|
|
|
|
//creo il recordset
|
2008-12-10 12:03:36 +00:00
|
|
|
TISAM_recordset selrighe("USE LVRCONSPLAN KEY 3\nFROM CODCF=#CODCF CODCONT=#CODCONT \nTO CODCF=#CODCF CODCONT=#CODCONT");
|
2008-12-10 11:57:25 +00:00
|
|
|
|
|
|
|
//setto le variabili
|
|
|
|
selrighe.set_var("#CODCF",codcf);
|
|
|
|
selrighe.set_var("#CODCONT",codcont);
|
|
|
|
|
|
|
|
//richiamo la funzione che effettivamente fa la cancellazione delle righe interessate
|
|
|
|
kill_planning(selrighe);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TContratti_app::kill_planning (TISAM_recordset& selrighe) const
|
|
|
|
{
|
|
|
|
const TRecnotype righe = selrighe.items();
|
|
|
|
if (righe > 0)
|
|
|
|
{
|
|
|
|
TProgind pi(righe, TR("Eliminazione planning in corso..."), true, true);
|
|
|
|
TLocalisamfile& rplan = selrighe.cursor()->file();
|
|
|
|
for (bool ok = selrighe.move_last(); ok; ok = selrighe.move_prev())
|
|
|
|
{
|
|
|
|
if (!pi.addstatus(1))
|
|
|
|
break;
|
|
|
|
rplan.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
bool TContratti_app::remove()
|
|
|
|
{
|
|
|
|
bool ok=TRelation_application::remove();
|
|
|
|
if(ok)
|
|
|
|
{
|
|
|
|
TString query;
|
2008-09-02 10:38:36 +00:00
|
|
|
build_query(*_msk,query);
|
2008-08-27 15:21:44 +00:00
|
|
|
TISAM_recordset righeset(query);
|
|
|
|
TLocalisamfile& file=righeset.cursor()->file();
|
2008-12-10 11:57:25 +00:00
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
for (bool ok=righeset.move_first(); ok; ok=righeset.move_next())
|
|
|
|
{
|
|
|
|
file.remove();
|
|
|
|
}
|
|
|
|
|
2008-12-10 12:03:36 +00:00
|
|
|
elimina_planning(_msk->get_long(F_CODCONT),_msk->get_long(F_CODCF));
|
2008-08-27 15:21:44 +00:00
|
|
|
}
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2008-08-21 15:41:07 +00:00
|
|
|
int lv0400(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
TContratti_app app;
|
|
|
|
app.run (argc,argv,TR("Gestione contratti"));
|
|
|
|
return 0;
|
|
|
|
}
|