2008-09-10 09:22:52 +00:00
|
|
|
#include <automask.h>
|
|
|
|
#include <execp.h>
|
2008-08-27 15:21:44 +00:00
|
|
|
#include <msksheet.h>
|
2008-08-21 15:41:07 +00:00
|
|
|
#include <relapp.h>
|
2008-09-02 10:38:36 +00:00
|
|
|
#include <recarray.h>
|
2008-08-21 15:41:07 +00:00
|
|
|
#include <recset.h>
|
|
|
|
|
|
|
|
#include "lv0400.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()
|
|
|
|
{
|
|
|
|
TSheet_field& ss=sfield(F_RIGHE);
|
|
|
|
TToken_string & row = ss.row(ss.selected());
|
|
|
|
const TString80 codart(row.get(ss.cid2index(S_CODART)));
|
2008-09-11 10:34:37 +00:00
|
|
|
const TString4 umcont(row.get(ss.cid2index(S_UM)));
|
|
|
|
TArticolo artrec(codart);
|
2008-10-20 08:18:31 +00:00
|
|
|
TMask& rowmask=ss.sheet_mask();
|
2008-09-10 09:22:52 +00:00
|
|
|
|
|
|
|
const int indsped=get_int(F_INDSPED);
|
|
|
|
const TDate oggi(TODAY);
|
|
|
|
|
|
|
|
TString query, filter;
|
|
|
|
|
|
|
|
filter << "ANNOES=#ANNOES CODART=#CODART TIPOCF=C CODCF=#CLIENTE";
|
2008-09-11 10:34:37 +00:00
|
|
|
filter << " INDSPED=" << indsped;
|
2008-09-10 09:22:52 +00:00
|
|
|
|
|
|
|
query << "USE CLIFOGIAC KEY 3\n"
|
|
|
|
<< "FROM " << filter << '\n'
|
|
|
|
<< "TO " << filter << '\n';
|
|
|
|
|
2008-09-11 10:34:37 +00:00
|
|
|
TISAM_recordset recgiac (query);
|
2008-09-10 09:22:52 +00:00
|
|
|
|
2008-09-11 10:34:37 +00:00
|
|
|
recgiac.set_var("#CLIENTE",get_long(F_CODCF));
|
|
|
|
recgiac.set_var("#ANNOES",TVariant((long)oggi.year()));
|
|
|
|
recgiac.set_var("#CODART",TVariant(codart));
|
2008-09-10 09:22:52 +00:00
|
|
|
|
2008-09-11 10:34:37 +00:00
|
|
|
real dotod,consyear,consmonth;
|
|
|
|
if (recgiac.move_first())
|
2008-09-10 09:22:52 +00:00
|
|
|
{
|
2008-09-11 10:34:37 +00:00
|
|
|
dotod=artrec.convert_to_um(recgiac.get("GIAC").as_real(),umcont);
|
|
|
|
consyear=artrec.convert_to_um(recgiac.get("ACQ").as_real()+recgiac.get("ENT").as_real(),umcont);
|
2008-09-10 09:22:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-20 08:18:31 +00:00
|
|
|
rowmask.set(S_DOTOD,dotod);
|
|
|
|
row.add(dotod.stringa(),ss.cid2index(S_DOTOD));
|
|
|
|
|
|
|
|
rowmask.set(S_CONSANNO,consyear);
|
|
|
|
row.add(consyear.stringa(),ss.cid2index(S_CONSANNO));
|
2008-09-10 09:22:52 +00:00
|
|
|
|
2008-09-11 10:34:37 +00:00
|
|
|
TDate imese(oggi);
|
|
|
|
imese.set_day(1);
|
|
|
|
|
|
|
|
query="USE MOVMAG KEY 3\n";
|
|
|
|
query << "SELECT (TIPOCF='C')&&(STR(CODCF=" << get_long(F_CODCF) << "))&&(STR(CODINDSP=" << indsped << "))\n";
|
|
|
|
query << "FROM DATAREG=" << imese << "\n"
|
|
|
|
<< "TO DATAREG=" << oggi << "\n";
|
|
|
|
|
|
|
|
TISAM_recordset recmag(query);
|
|
|
|
|
|
|
|
for (bool ok=recmag.move_first(); ok; ok=recmag.move_next())
|
|
|
|
{
|
|
|
|
const TCausale_magazzino tcaus(recmag.get(MOVMAG_CODCAUS).as_string());
|
|
|
|
|
|
|
|
TString queryrmag="USE RMOVMAG\n";
|
|
|
|
queryrmag << "SELECT CODART='" << codart << "'\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())
|
|
|
|
{
|
|
|
|
int sgn_acq=tcaus.sgn(s_acq);
|
|
|
|
int sgn_ent=tcaus.sgn(s_ent);
|
|
|
|
const TString& codcaus=recrmag.get(RMOVMAG_CODCAUS).as_string();
|
|
|
|
if (codcaus.full())
|
|
|
|
{
|
|
|
|
const TCausale_magazzino rcaus(codcaus);
|
|
|
|
sgn_acq=rcaus.sgn(s_acq);
|
|
|
|
sgn_ent=rcaus.sgn(s_ent);
|
|
|
|
}
|
|
|
|
if (sgn_acq!=0 || sgn_ent!=0)
|
|
|
|
{
|
|
|
|
const TString4 um=recrmag.get(RMOVMAG_UM).as_string();
|
|
|
|
const real qta=artrec.convert_to_um(recrmag.get(RMOVMAG_QUANT).as_real(),umcont,um);
|
|
|
|
if (sgn_acq!=0)
|
|
|
|
consmonth+=qta*sgn_acq;
|
|
|
|
if (sgn_ent!=0)
|
|
|
|
consmonth+=qta*sgn_ent;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-20 08:18:31 +00:00
|
|
|
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())
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
virtual bool remove();
|
2008-10-21 15:51:13 +00:00
|
|
|
virtual void init_insert_mode(TMask& m);
|
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-08-21 15:41:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10-21 15:51:13 +00:00
|
|
|
void TContratti_app::init_insert_mode(TMask& m)
|
|
|
|
{
|
|
|
|
TSheet_field& ss=m.sfield(F_RIGHE);
|
|
|
|
ss.insert();
|
|
|
|
}
|
|
|
|
|
2008-08-27 15:21:44 +00:00
|
|
|
int TContratti_app::write(const TMask& m)
|
|
|
|
{
|
|
|
|
int err=TRelation_application::write(m);
|
|
|
|
if(err==NOERR) save_rows(m);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
int TContratti_app::rewrite(const TMask& m)
|
|
|
|
{
|
|
|
|
int err=TRelation_application::rewrite(m);
|
|
|
|
if(err==NOERR) save_rows(m);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
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();
|
|
|
|
for (bool ok=righeset.move_first(); ok; ok=righeset.move_next())
|
|
|
|
{
|
|
|
|
file.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|