Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 01.05 patch 282 git-svn-id: svn://10.65.10.50/trunk@8019 c028cbd2-c16b-5b4b-a496-9718f37d4682
1490 lines
41 KiB
C++
Executable File
1490 lines
41 KiB
C++
Executable File
#include "dbcv.h"
|
|
#include "dbcv09.h"
|
|
#include <applicat.h>
|
|
#include <execp.h>
|
|
#include <utility.h>
|
|
#include <tabutil.h>
|
|
#include <mask.h>
|
|
#include <progind.h>
|
|
#include <recarray.h>
|
|
#include "..\mg\anamag.h"
|
|
#include "..\mg\mag.h"
|
|
#include "..\include\doc.h"
|
|
#include "..\include\rdoc.h"
|
|
|
|
#define BPCS_ANAGRAFICA "iiml01"
|
|
#define BPCS_IMPORTEX "iimsl01"
|
|
#define BPCS_DISTINTE "mbml01"
|
|
#define BPCS_DIVISORI "cicl01"
|
|
#define BPCS_MOVMAG "ithl01"
|
|
#define BPCS_ORDACQ "acq_ord"
|
|
#define BPCS_FIRMORD "ord_cli"
|
|
#define BPCS_SHOPORDS "ord_prod"
|
|
|
|
|
|
class TTimed_skipbox: public TTimed_breakbox
|
|
{
|
|
public:
|
|
TTimed_skipbox(const char * message,int seconds,int x=40,int y=10);
|
|
~TTimed_skipbox();
|
|
};
|
|
|
|
TTimed_skipbox:: TTimed_skipbox(const char * message,int seconds,int x,int y)
|
|
: TTimed_breakbox(message,seconds,x,y)
|
|
{
|
|
hide(DLG_OK);
|
|
hide(DLG_CANCEL);
|
|
add_button(DLG_CANCEL, 0, "~Ignora", -22, -1, 12, 2,"",0);
|
|
add_button(DLG_OK, 0, "Im~porta", -12, -1, 12, 2,"",0);
|
|
}
|
|
|
|
TTimed_skipbox::~TTimed_skipbox()
|
|
{}
|
|
|
|
|
|
class TImport_file : public TObject
|
|
{
|
|
TExternisamfile *_f;
|
|
real _rbuffer;
|
|
TString _sbuffer;
|
|
TDate _dbuffer;
|
|
public:
|
|
void put(const char *field, const char * val);
|
|
TString & get(const char *field);
|
|
inline const long get_long(const char *field);
|
|
inline const real & get_real(const char *field);
|
|
inline const TDate & get_date(const char *field);
|
|
TString & get_codice(const char *field);
|
|
bool first();
|
|
bool next();
|
|
bool eof();
|
|
long items();
|
|
TImport_file(const char *path, const char * name);
|
|
};
|
|
|
|
TImport_file::TImport_file(const char *path, const char * name)
|
|
{
|
|
TFilename fname(path);
|
|
fname.add(name);
|
|
_f = new TExternisamfile(fname, FALSE, TRUE);
|
|
}
|
|
void TImport_file::put(const char *field, const char * val)
|
|
{
|
|
_f->put(field,val);
|
|
}
|
|
TString & TImport_file::get(const char *field)
|
|
{
|
|
_sbuffer = _f->get(field);
|
|
return _sbuffer.trim();
|
|
}
|
|
TString & TImport_file::get_codice(const char *field)
|
|
{
|
|
_sbuffer = _f->get(field);
|
|
_sbuffer.trim();
|
|
|
|
return _sbuffer;
|
|
}
|
|
const real & TImport_file::get_real(const char *field)
|
|
{
|
|
get(field).replace(',','.');
|
|
_rbuffer=real(_sbuffer);
|
|
return _rbuffer;
|
|
}
|
|
const long TImport_file::get_long(const char *field)
|
|
{
|
|
const long l= _f->get_long(field);
|
|
return l;
|
|
}
|
|
const TDate & TImport_file::get_date(const char *field)
|
|
{
|
|
_dbuffer=_f->get_long(field);
|
|
return _dbuffer;
|
|
}
|
|
|
|
bool TImport_file::first()
|
|
{
|
|
return _f->first();
|
|
}
|
|
bool TImport_file::next()
|
|
{
|
|
return _f->next();
|
|
}
|
|
bool TImport_file::eof()
|
|
{
|
|
return _f->eof();
|
|
}
|
|
|
|
long TImport_file::items()
|
|
{
|
|
return _f->items();
|
|
}
|
|
|
|
|
|
class TSupport_file : public TObject
|
|
{
|
|
TIsamtempfile * _f;
|
|
TRecord_cache *_cache;
|
|
public:
|
|
void zap();
|
|
void put(const char * field, const char * value);
|
|
int read(TRectype & r);
|
|
int read()
|
|
{return read(_f->curr());}
|
|
int write();
|
|
TSupport_file (int logicnum,const char * radix);
|
|
virtual ~TSupport_file ();
|
|
};
|
|
|
|
void TSupport_file::zap()
|
|
{
|
|
int err;
|
|
for (long i=_f->items(); i>0; i--)
|
|
{
|
|
_f->readat(i);
|
|
err=_f->remove();
|
|
}
|
|
}
|
|
int TSupport_file::read(TRectype & r)
|
|
{
|
|
CHECK(r.num() == _f->num(),"TIpo record inconsistente");
|
|
TString k(r.build_key(1));
|
|
r = _cache->get(k);
|
|
if (r.empty())
|
|
return _iskeynotfound;
|
|
return NOERR;
|
|
}
|
|
int TSupport_file::write()
|
|
{
|
|
TString k(_f->curr().build_key(1));
|
|
_cache->discard(k);
|
|
return _f->write();
|
|
}
|
|
|
|
void TSupport_file::put(const char * field, const char * value)
|
|
{
|
|
_f->put(field,value);
|
|
}
|
|
|
|
TSupport_file::TSupport_file (int logicnum,const char * radix)
|
|
{
|
|
_f = new TIsamtempfile(logicnum,radix,FALSE,FALSE);
|
|
_cache= new TRecord_cache(_f);
|
|
}
|
|
TSupport_file::~TSupport_file()
|
|
{
|
|
delete _f;
|
|
delete _cache;
|
|
}
|
|
|
|
typedef void (*SET_DOC_FUN)(TImport_file & import,TConfig &trans);
|
|
typedef bool (*FILTER_FUN)(TImport_file & import);
|
|
|
|
class TImporta_BPCS : public TSkeleton_application
|
|
{
|
|
TLocalisamfile * _dist, *_rdist, * _anamag, *_umart, *_codcorr,*_mag;
|
|
private:
|
|
void delete_ghosts();
|
|
void delete_boms();
|
|
int read_last_rdist(const char *item_code);
|
|
bool read_is_dist(const char *item_code);
|
|
bool read_is_ghost(const char *item_code);
|
|
const char * read_first_um(const char *item_code);
|
|
bool creadocs(const char * msg,
|
|
long firm, TImport_file & imp_file,
|
|
const char *FieldNumDoc, const char *FieldClifor, const char *FieldDataDoc,const char *FieldGroup,
|
|
SET_DOC_FUN set_header, SET_DOC_FUN set_body, FILTER_FUN filter );
|
|
|
|
void clear_docs(const char * num);
|
|
void newums();
|
|
bool force_write(TLocalisamfile & f);
|
|
|
|
protected:
|
|
bool create();
|
|
bool destroy();
|
|
bool importa_boms(TMask &m);
|
|
bool cambia_gmc(TMask & m);
|
|
bool importa_arts(TMask &m, const bool sologhost=FALSE);
|
|
bool importa_ums_BP(TMask &m);
|
|
bool importa_ordacq(TMask & m);
|
|
bool importa_ordcli(TMask & m);
|
|
bool importa_ordprod(TMask & m);
|
|
bool importa_movmag(TMask & m, bool segrate=FALSE, bool trieste=FALSE);
|
|
protected:
|
|
virtual void main_loop() ;
|
|
};
|
|
|
|
bool TImporta_BPCS::create()
|
|
{
|
|
_dist = new TLocalisamfile(LF_DIST);
|
|
_rdist = new TLocalisamfile(LF_RDIST);
|
|
_anamag = new TLocalisamfile(LF_ANAMAG);
|
|
_umart = new TLocalisamfile(LF_UMART);
|
|
_codcorr = new TLocalisamfile(LF_CODCORR);
|
|
_mag = new TLocalisamfile(LF_MAG);
|
|
return TSkeleton_application::create();
|
|
}
|
|
bool TImporta_BPCS::destroy()
|
|
{
|
|
delete _dist;
|
|
delete _rdist;
|
|
delete _anamag;
|
|
delete _umart;
|
|
delete _codcorr;
|
|
delete _mag;
|
|
return TSkeleton_application::destroy();
|
|
}
|
|
|
|
bool TImporta_BPCS::force_write(TLocalisamfile & f)
|
|
{
|
|
int err=f.write();
|
|
if (err != NOERR) // fallisce se c'e' gia'
|
|
err=f.rewrite();
|
|
return err;
|
|
}
|
|
|
|
int TImporta_BPCS::read_last_rdist(const char *item_code)
|
|
{
|
|
static TString prevcode="";
|
|
static int nrig=0;
|
|
if (prevcode!=item_code)
|
|
{
|
|
prevcode=item_code;
|
|
nrig=0;
|
|
_rdist->put("CODDIST",item_code);
|
|
int err=_rdist->read(_isgteq);
|
|
while (err==NOERR && _rdist->get("CODDIST")==item_code)
|
|
{
|
|
nrig++;
|
|
err=_rdist->next();
|
|
}
|
|
}
|
|
return ++nrig;
|
|
}
|
|
|
|
bool TImporta_BPCS::read_is_dist(const char *item_code)
|
|
{
|
|
const TRectype & rec=cache().get(LF_DIST,item_code);
|
|
if (!rec.empty())
|
|
return TRUE;
|
|
return FALSE;
|
|
}
|
|
bool TImporta_BPCS::read_is_ghost(const char *item_code)
|
|
{
|
|
const TRectype & rec=cache().get(LF_DIST,item_code);
|
|
if (!rec.empty())
|
|
return rec.get_bool("VIRTUALE") && !rec.get_bool("ARTPROD")&& !rec.get_bool("ARTACQ") ;
|
|
return FALSE;
|
|
}
|
|
const char * TImporta_BPCS::read_first_um(const char *item_code)
|
|
{
|
|
TToken_string key(item_code);
|
|
key.add(1);
|
|
const TRectype & rec=cache().get(LF_UMART,key);
|
|
if (rec.empty())
|
|
error_box("Impossibile trovare l'item %s",item_code);
|
|
return rec.get("UM");
|
|
}
|
|
// cancella le distinte che non sono lavorazioni
|
|
void TImporta_BPCS ::delete_boms()
|
|
{
|
|
TWait_cursor hourglass;
|
|
TIndwin info(60,"Cancellazione distinte...",FALSE,FALSE);
|
|
TTable lav("LAV");
|
|
_dist->first();
|
|
// distinte
|
|
while (!_dist->eof())
|
|
{
|
|
do_events();
|
|
lav.put("CODTAB",_dist->get("CODDIST"));
|
|
if (lav.read()!=NOERR)
|
|
{
|
|
// non e' una lavorazione
|
|
_dist->remove();
|
|
}
|
|
_dist->next();
|
|
}
|
|
// righe distinte
|
|
_rdist->first();
|
|
while (!_rdist->eof())
|
|
{
|
|
do_events();
|
|
lav.put("CODTAB",_dist->get("CODDIST"));
|
|
if (1
|
|
|| _rdist->get("TIPO")!="L")
|
|
{
|
|
// non e' una lavorazione
|
|
_rdist->remove();
|
|
}
|
|
_rdist->next();
|
|
}
|
|
}
|
|
|
|
// elimina i ghost "di servizio"
|
|
void TImporta_BPCS ::delete_ghosts()
|
|
{
|
|
TWait_cursor hourglass;
|
|
TIndwin info(60,"Cancellazione distinte fantasma inutili...",FALSE,FALSE);
|
|
TLocalisamfile dist(LF_DIST);
|
|
_dist->first();
|
|
while (!_dist->eof())
|
|
{
|
|
do_events();
|
|
if (_dist->get_bool("VIRTUALE") && !_dist->get_bool("ARTPROD")&& !_dist->get_bool("ARTACQ") )// fantasma
|
|
{
|
|
TString codice=_dist->get("CODDIST");
|
|
if (codice.find("__") < 0) // non appartiene ad uno stabilimento particolare
|
|
_dist->remove();
|
|
}
|
|
_dist->next();
|
|
}
|
|
}
|
|
|
|
bool TImporta_BPCS ::importa_boms(TMask &m)
|
|
{
|
|
TWait_cursor hourglass;
|
|
cache().flush(LF_DIST);
|
|
cache().flush(LF_ANAMAG);
|
|
cache().flush(LF_UMART);
|
|
|
|
TSupport_file morti(LF_DIST,ANAGRAFICA_MORTI);
|
|
TImport_file boms(m.get(F_PATH), BPCS_DISTINTE);
|
|
TProgind info(boms.items(),"Importazione distinte...",TRUE,TRUE);
|
|
TToken_string imported_lcode,dead_lcode,skipped_lcode,current_lcode;
|
|
TString old_code,item_code,last_code;
|
|
TString8 impianto,main_imp;
|
|
int bseq;
|
|
|
|
boms.first();
|
|
while (!boms.eof())
|
|
{
|
|
info.addstatus(1);
|
|
if (info.iscancelled())
|
|
return FALSE;
|
|
// converte ogni distinta ancora valida
|
|
old_code=(boms.get_codice("BPROD"));
|
|
impianto=(boms.get("BMWHS"));
|
|
int metodo(int(boms.get_long("BMBOMM")));
|
|
current_lcode.add(old_code,0);
|
|
current_lcode.add(impianto,1);
|
|
current_lcode.add(metodo,2);
|
|
|
|
const long ddis=boms.get_long("BDDIS");
|
|
bool skip=!((ddis==99999999)||(ddis==999999)||(ddis==99999)||(ddis==9999999));
|
|
if (imported_lcode==current_lcode)
|
|
skip = FALSE;
|
|
else if (skipped_lcode==current_lcode || dead_lcode==current_lcode)
|
|
skip = TRUE;
|
|
if (!skip)
|
|
{
|
|
morti.put("CODDIST",old_code);
|
|
if (morti.read()==NOERR)
|
|
{
|
|
skip=TRUE;
|
|
skipped_lcode=current_lcode;
|
|
}
|
|
}
|
|
if (!skip && atol(boms.get("BDEFF"))<m.get_int(F_ANNO)*10000L)
|
|
{
|
|
if (skipped_lcode==current_lcode || dead_lcode==current_lcode)
|
|
skip = TRUE;
|
|
else if (imported_lcode==current_lcode)
|
|
skip = FALSE;
|
|
else
|
|
{
|
|
TTimed_skipbox bbox(format("La distinta %s (%s), di %s metodo '%02d', risale al %s; ignoro l'importazione ?",
|
|
(const char *)old_code,
|
|
(const char *)cache().get(LF_ANAMAG,old_code).get("DESCR"),
|
|
(const char *)impianto,
|
|
metodo,
|
|
(const char *)boms.get("BDEFF")),60);
|
|
if (skip=(bbox.run()==K_ESC))
|
|
{
|
|
if (noyes_box("Ignoro l'importazione di tutti i metodi del codice %s?",(const char *) old_code))
|
|
{
|
|
morti.put("CODDIST",old_code);
|
|
morti.write();
|
|
dead_lcode=current_lcode;
|
|
}
|
|
skipped_lcode=current_lcode;
|
|
}
|
|
}
|
|
}
|
|
// importa solo i metodi !=99 degli impianti SEgrate e TrieSte
|
|
if (!skip && metodo != 99 && (impianto=="SE" || impianto=="TS" ))
|
|
{
|
|
const TString8 father_grmerc= cache().get(LF_ANAMAG,old_code).get("GRMERC");
|
|
if (metodo!=0)
|
|
{
|
|
main_imp=impianto;
|
|
impianto=format("%s3%02d",(const char *)impianto,metodo);
|
|
if (cache().get("IMP",impianto).empty())
|
|
{
|
|
cache().discard("IMP",impianto);
|
|
// inserisce il terzista
|
|
TTable imp("IMP");
|
|
imp.put("CODTAB",impianto);
|
|
imp.put("S0",format("Terzista %d (%s)",metodo,descr_method(metodo)));
|
|
imp.write();
|
|
}
|
|
}
|
|
// padre
|
|
TString descr=cache().get(LF_ANAMAG,old_code).get("DESCR");
|
|
TString um_f=read_first_um(old_code) ;
|
|
TString item_code=old_code;
|
|
item_code << "__" << impianto;
|
|
const bool father_ghost= read_is_ghost(old_code);
|
|
if (!father_ghost && item_code!=last_code)
|
|
{
|
|
// se non e' un fantasma lo definisce come variante (distinta contenente una riga di tipo variabile)
|
|
if (cache().get(LF_DIST,old_code).empty())
|
|
{
|
|
cache().discard(LF_DIST,old_code);
|
|
|
|
_dist->zero();
|
|
_dist->put("CODDIST", old_code);
|
|
_dist->put("DESCR", descr);
|
|
_dist->put("VIRTUALE", " ");
|
|
_dist->put("ARTPROD", "X");
|
|
_dist->put("UM", um_f);
|
|
TString varvar("VARIANTE=");
|
|
varvar << "\"" << old_code << "__\"+IF(_IMPIANTO!=\"\",IF(_IMPIANTO==\"XT\",_IMPIANTO,_LINEA),\"SE\")" ;
|
|
_dist->put("PARAMETRI",varvar);
|
|
int err=_dist->write();
|
|
if (err!=_isreinsert)
|
|
{
|
|
_rdist->zero();
|
|
_rdist->put("CODDIST", old_code);
|
|
_rdist->put("NRIG", 1 );
|
|
_rdist->put("TIPO", "V" );
|
|
_rdist->put("CODCOMP", "VARIANTE" );
|
|
_rdist->put("UM", "");
|
|
_rdist->put("EXPR", 1 );
|
|
force_write(*_rdist);
|
|
}
|
|
}
|
|
}
|
|
// figlio
|
|
TString son_code=boms.get_codice("BCHLD");
|
|
TString um_s=read_first_um(son_code) ;
|
|
const bool son_ghost=read_is_ghost(son_code);
|
|
if (son_ghost)
|
|
son_code << "__" << impianto ;
|
|
// scrivi la bom
|
|
if (last_code!=item_code && cache().get(LF_DIST,item_code).empty())
|
|
{
|
|
descr << " (impianto " << impianto << ")";
|
|
cache().discard(LF_DIST,item_code);
|
|
_dist->zero();
|
|
_dist->put("CODDIST", item_code);
|
|
_dist->put("DESCR", descr);
|
|
_dist->put("VIRTUALE", "X" );
|
|
_dist->put("ARTPROD", "");
|
|
_dist->put("UM", "BP");
|
|
TString varimp("_IMPIANTO=");
|
|
varimp << '"' << impianto << '"';
|
|
_dist->put("PARAMETRI",varimp);
|
|
_dist->write(); // fallisce se esiste gia'
|
|
|
|
_umart->zero();
|
|
_umart->put("CODART",item_code);
|
|
_umart->put("NRIGA",1);
|
|
_umart->put("UM",um_f);
|
|
_umart->put("FC","1");
|
|
force_write(*_umart);
|
|
|
|
last_code=item_code;
|
|
bseq=0;
|
|
}
|
|
bseq++;
|
|
_rdist->zero(' ');
|
|
_rdist->put("CODDIST", item_code);
|
|
_rdist->put("NRIG", bseq);
|
|
_rdist->put("TIPO", son_ghost ? "D" : "A");
|
|
_rdist->put("CODCOMP", son_code );
|
|
_rdist->put("UM", um_s);
|
|
_rdist->put("EXPR", boms.get_real("BQREQ") );
|
|
force_write(*_rdist);
|
|
|
|
imported_lcode=current_lcode;
|
|
}
|
|
boms.next();
|
|
}
|
|
delete_ghosts();
|
|
return TRUE;
|
|
}
|
|
|
|
void TImporta_BPCS ::newums()
|
|
{
|
|
_dist->first();
|
|
TString item_code,ghostcode;
|
|
while (!_dist->eof())
|
|
{
|
|
if (_dist->get_bool("VIRTUALE") && !_dist->get_bool("ARTPROD")&& !_dist->get_bool("ARTACQ") )// fantasma
|
|
{
|
|
item_code=_dist->get("CODDIST");
|
|
int pos=item_code.find("__");
|
|
if (pos>=0)
|
|
{
|
|
ghostcode=item_code;
|
|
ghostcode.cut(pos);
|
|
_umart->zero();
|
|
_umart->put("CODART",ghostcode);
|
|
_umart->put("NRIGA",1);
|
|
if (_umart->read()==NOERR)
|
|
{
|
|
_umart->put("CODART",item_code);
|
|
force_write(*_umart);
|
|
}
|
|
}
|
|
}
|
|
_dist->next();
|
|
}
|
|
}
|
|
|
|
// importa le ums dal file di anagrafica
|
|
bool TImporta_BPCS ::importa_arts(TMask & m, const bool sologhost)
|
|
{
|
|
TWait_cursor hourglass;
|
|
cache().flush(LF_ANAMAG);
|
|
cache().flush(LF_DIST);
|
|
cache().flush(LF_UMART);
|
|
|
|
TSupport_file morti(LF_DIST,ANAGRAFICA_MORTI);
|
|
TImport_file items_ext(m.get(F_PATH),BPCS_IMPORTEX);
|
|
TImport_file items(m.get(F_PATH),BPCS_ANAGRAFICA);
|
|
TString item_code,item_type,tmp;
|
|
bool skip;
|
|
TProgind info(items.items(),sologhost ? "Importazione distinte fantasma...":"Importazione articoli e distinte fantasma...",TRUE,TRUE);
|
|
items_ext.first();
|
|
items.first();
|
|
while (!items.eof())
|
|
{
|
|
info.addstatus(1);
|
|
if (info.iscancelled())
|
|
return FALSE;
|
|
item_type=items.get("IITYP");
|
|
if (items.get("IID")=="IM" && atoi(item_type)!=6)
|
|
{
|
|
item_code=items.get_codice("IPROD");
|
|
skip=FALSE;
|
|
// sincronizza il file dell'anagrafica Importex
|
|
while (!sologhost && items_ext.get_codice("MSITE")<item_code && !items_ext.eof())
|
|
items_ext.next();
|
|
morti.put("CODDIST",item_code);
|
|
if ((morti.read()!=NOERR) &&
|
|
item_type=="0" || !sologhost)
|
|
{
|
|
if (item_type=="0") // fantasma
|
|
{
|
|
_dist->zero();
|
|
_dist->put("CODDIST",item_code);
|
|
_dist->put("DESCR",items.get("IDESC"));
|
|
_dist->put("VIRTUALE", "X" );
|
|
_dist->put("ARTPROD", " ");
|
|
force_write(*_dist);
|
|
} else {
|
|
_anamag->zero();
|
|
_anamag->put( ANAMAG_CODART,item_code);
|
|
_anamag->put( ANAMAG_DESCR,items.get("IDESC"));
|
|
_anamag->put( ANAMAG_DESCRAGG,items.get("IDSCE"));
|
|
_anamag->put( ANAMAG_CODFORN, items.get("IVEND"));
|
|
_anamag->put( ANAMAG_UMP, "KG");
|
|
_anamag->put( ANAMAG_PESO, items.get("IWGHT"));
|
|
// riordino
|
|
_anamag->put( ANAMAG_RIORDINO , "F"); //_anamag->put( ANAMAG_RIORDINO , items.get("IMRP")=="M" ? "F" : "P" );
|
|
_anamag->put( ANAMAG_GIORNIRIOR, items.get("ILEAD"));
|
|
_anamag->put( ANAMAG_LOTTORIOR, items.get("ILOTS"));
|
|
_anamag->put( ANAMAG_LOTTOIRIOR, items.get("IIOQ"));
|
|
//
|
|
_anamag->put( ANAMAG_PPCONF , items.get("IFII"));
|
|
_anamag->put( ANAMAG_PPCOLLO , items.get("IFII"));
|
|
TString16 gmc=items.get("IITYP");
|
|
switch (gmc[0])
|
|
{
|
|
case 'F':
|
|
case 'E':
|
|
case 'Z':
|
|
case 'G':
|
|
gmc[0]= 'F'; break;
|
|
case 'M':
|
|
gmc[0]= 'S'; break;
|
|
case 'P':
|
|
gmc[0]= 'C'; break;
|
|
}
|
|
TString16 iclas(items.get("ICLAS"));
|
|
if (!iclas.blank())
|
|
{
|
|
switch (m.get(F_ICLAS)[0])
|
|
{
|
|
case 'S':
|
|
complete_gmc(gmc, iclas);
|
|
break;
|
|
case 'C':
|
|
gmc << iclas;
|
|
break;
|
|
case ' ':
|
|
break;
|
|
}
|
|
}
|
|
_anamag->put( ANAMAG_GRMERC,gmc);
|
|
_anamag->put( ANAMAG_COSTSTD, items.get("ISCST"));
|
|
_anamag->put( ANAMAG_ULTCOS1, items.get("IACST"));
|
|
tmp=items.get("TAXC1");
|
|
if (tmp.left(3)=="IVA")
|
|
tmp=tmp.sub(3);
|
|
_anamag->put( ANAMAG_CODIVA , tmp);
|
|
if (items_ext.get_codice("MSITE")==items.get_codice("IPROD"))
|
|
{
|
|
_anamag->put( ANAMAG_CLASSDOG , check_clasdog(items_ext.get_long("MSTDO")));
|
|
_anamag->put( ANAMAG_USER1 , items_ext.get("MSIDR"));// idrati
|
|
_anamag->put( ANAMAG_USER2 , items_ext.get("MSANI"));//anidri
|
|
_anamag->put( ANAMAG_USER3 , items_ext.get("MSTAL"));//alcool
|
|
// dimensioni
|
|
_anamag->put( ANAMAG_USER4, items_ext.get("MSPLU"));
|
|
_anamag->put( ANAMAG_USER5, items_ext.get("MSPAL"));
|
|
_anamag->put( ANAMAG_USER6, items_ext.get("MSPPR"));
|
|
// composizione pallets
|
|
_anamag->put( ANAMAG_USER7, items_ext.get("MSCST")); // casse per strato
|
|
_anamag->put( ANAMAG_USER8, items_ext.get("MSSTP")); // strati per pallet
|
|
}
|
|
force_write(*_anamag);
|
|
real smin(items.get("IMIN"));
|
|
if (smin!=ZERO)
|
|
{
|
|
_mag->zero();
|
|
_mag->put(MAG_SCORTAMIN,smin);
|
|
_mag->put(MAG_ANNOES,"1999");
|
|
_mag->put(MAG_CODART,item_code);
|
|
_mag->put(MAG_NRIGA,1);
|
|
_mag->put(MAG_CODMAG,"SE1");
|
|
force_write(*_mag);
|
|
_mag->put(MAG_NRIGA,2);
|
|
_mag->put(MAG_CODMAG,"TS1");
|
|
force_write(*_mag);
|
|
}
|
|
}
|
|
TString16 um,ums(items.get("IUMS"));
|
|
real fc;
|
|
int nriga=1;
|
|
for (int u=0; u<3; u++)
|
|
{
|
|
switch (u)
|
|
{
|
|
case 1:
|
|
um=items.get("IUMP");
|
|
fc=items.get_real("IUMCN");
|
|
break;
|
|
case 2:
|
|
um=items.get("IUMR");
|
|
fc=items.get_real("IUMRC");
|
|
break;
|
|
default:
|
|
um=ums;
|
|
fc=1.0;
|
|
}
|
|
if (!um.blank() && (u==0 || um!=ums))
|
|
{
|
|
_umart->zero();
|
|
_umart->put("CODART",item_code);
|
|
_umart->put("NRIGA",nriga);
|
|
_umart->put("UM",um);
|
|
if (nriga==1)
|
|
_umart->put("PREZZO",items.get("ILIST"));
|
|
_umart->put("FC",fc);
|
|
force_write(*_umart);
|
|
nriga++;
|
|
}
|
|
} // fine ciclo unita' di misura
|
|
long ean=items.get_long("IDRAW");
|
|
if (!m.get(F_EAN).blank() && ean!=0L)
|
|
{
|
|
_codcorr->zero();
|
|
_codcorr->put("CODARTALT",ean);
|
|
_codcorr->put("NRIGA",1);
|
|
_codcorr->put("TIPO",m.get(F_EAN));
|
|
_codcorr->put("CODART",item_code);
|
|
force_write(*_codcorr);
|
|
}
|
|
}
|
|
}
|
|
items.next();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
bool TImporta_BPCS ::cambia_gmc(TMask & m)
|
|
{
|
|
TWait_cursor hourglass;
|
|
cache().flush(LF_ANAMAG);
|
|
cache().flush(LF_DIST);
|
|
cache().flush(LF_UMART);
|
|
|
|
TImport_file items_ext(m.get(F_PATH),BPCS_IMPORTEX);
|
|
TImport_file items(m.get(F_PATH),BPCS_ANAGRAFICA);
|
|
TString item_code,item_type,tmp;
|
|
TProgind info(items.items(),"Importazione gruppi merceologici e classi doganali",TRUE,TRUE);
|
|
items_ext.first();
|
|
items.first();
|
|
while (!items.eof())
|
|
{
|
|
info.addstatus(1);
|
|
if (info.iscancelled())
|
|
return FALSE;
|
|
item_type=items.get("IITYP");
|
|
if (items.get("IID")=="IM" && atoi(item_type)!=6)
|
|
{
|
|
item_code=items.get_codice("IPROD");
|
|
if (item_type!="0") // fantasma
|
|
{
|
|
_anamag->zero();
|
|
_anamag->put( ANAMAG_CODART,item_code);
|
|
if (_anamag->read()==NOERR)
|
|
{
|
|
// sincronizza il file dell'anagrafica Importex
|
|
while (items_ext.get_codice("MSITE")<item_code && !items_ext.eof())
|
|
items_ext.next();
|
|
if (items_ext.get_codice("MSITE")==items.get_codice("IPROD"))
|
|
{
|
|
TString cld=check_clasdog(items_ext.get_long("MSTDO"));
|
|
if (!cld.blank())
|
|
_anamag->put( ANAMAG_CLASSDOG , cld);
|
|
}
|
|
TString16 gmc=items.get("IITYP");
|
|
switch (gmc[0])
|
|
{
|
|
case 'F':
|
|
case 'E':
|
|
case 'Z':
|
|
case 'G':
|
|
gmc[0]= 'F'; break; // finiti
|
|
case 'M':
|
|
gmc[0]= 'S'; break; // semilavorati ()
|
|
case 'P':
|
|
gmc[0]= 'C'; break; // componenti (parts)
|
|
}
|
|
TString16 iclas(items.get("ICLAS"));
|
|
if (!iclas.blank())
|
|
{
|
|
switch (m.get(F_ICLAS)[0])
|
|
{
|
|
case 'S':
|
|
complete_gmc(gmc, iclas);
|
|
break;
|
|
case 'C':
|
|
gmc << iclas;
|
|
break;
|
|
case ' ':
|
|
break;
|
|
}
|
|
}
|
|
_anamag->put( ANAMAG_GRMERC,gmc);
|
|
_anamag->rewrite();
|
|
}
|
|
}
|
|
}
|
|
items.next();
|
|
}
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
// importa le ums dal file dei divisori
|
|
bool TImporta_BPCS ::importa_ums_BP(TMask & m)
|
|
{
|
|
TWait_cursor hourglass;
|
|
cache().flush(LF_UMART);
|
|
|
|
TImport_file divisori(m.get(F_PATH),BPCS_DIVISORI);
|
|
TProgind info(divisori.items(),"Importazione divisori (batch di produzione)...",TRUE,TRUE);
|
|
divisori.first();
|
|
TString item_code,impianto;
|
|
while (!divisori.eof())
|
|
{
|
|
info.addstatus(1);
|
|
if (info.iscancelled())
|
|
return FALSE;
|
|
item_code=(divisori.get_codice("ICPROD"));
|
|
impianto=divisori.get("ICFAC");
|
|
if (impianto=="SE" || impianto == "TS")
|
|
{
|
|
item_code << "__" << impianto;
|
|
if (read_is_dist(item_code))
|
|
{
|
|
_umart->zero();
|
|
_umart->put("CODART",item_code);
|
|
_umart->put("NRIGA",2);
|
|
_umart->put("UM","BP");
|
|
_umart->put("FC",divisori.get("ICBTCH"));
|
|
force_write(*_umart);
|
|
}
|
|
}
|
|
divisori.next();
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
void TImporta_BPCS ::clear_docs(const char * num)
|
|
{
|
|
TString codnum(num);
|
|
TLocalisamfile doc(LF_DOC);
|
|
TLocalisamfile rdoc(LF_RIGHEDOC);
|
|
for (int anno=1998; anno<=1999; anno++)
|
|
{
|
|
doc.put("PROVV","D");
|
|
doc.put("ANNO",anno);
|
|
doc.put("CODNUM",codnum);
|
|
doc.read(_isgteq);
|
|
while (!doc.eof() && doc.get("CODNUM")==codnum)
|
|
{
|
|
doc.remove();
|
|
doc.next();
|
|
}
|
|
}
|
|
rdoc.put("CODNUM",codnum);
|
|
rdoc.read(_isgteq);
|
|
while (!rdoc.eof() && rdoc.get("CODNUM")==codnum)
|
|
{
|
|
rdoc.remove();
|
|
rdoc.next();
|
|
}
|
|
}
|
|
|
|
bool TImporta_BPCS ::creadocs(const char * msg,
|
|
long firm, // ditta
|
|
TImport_file & imp_file,
|
|
const char *FieldNumDoc, const char *FieldClifor, const char *FieldDataDoc,const char *FieldGroup,
|
|
SET_DOC_FUN set_header, SET_DOC_FUN set_body, FILTER_FUN filter )
|
|
{
|
|
|
|
TProgind info(imp_file.items(),msg,TRUE,TRUE);
|
|
TConfig *trans=NULL;
|
|
long ntransac=0;
|
|
int nrigadoc=0;
|
|
long last_ndoc=-1L;
|
|
TDate last_date("");
|
|
long last_clifor=-1L;
|
|
TString last_group="";
|
|
|
|
// rimuove le transazioni
|
|
TString_array transactions;
|
|
list_files("ND_*.ini", transactions);
|
|
FOR_EACH_ARRAY_ROW(transactions, row, name)
|
|
remove(*name);
|
|
|
|
imp_file.first();
|
|
while (!imp_file.eof())
|
|
{
|
|
info.addstatus(1);
|
|
if (info.iscancelled())
|
|
return FALSE;
|
|
if (filter(imp_file))
|
|
{
|
|
long new_ndoc =FieldNumDoc ? imp_file.get_long(FieldNumDoc) : last_ndoc;
|
|
long new_clifor=FieldClifor ? imp_file.get_long(FieldClifor) : last_clifor;
|
|
if (new_clifor==0L && FieldClifor)
|
|
new_clifor=9999; // cliente generico
|
|
TString new_group=FieldGroup ? imp_file.get(FieldGroup) : last_group;
|
|
TDate new_date(FieldDataDoc ? imp_file.get_long(FieldDataDoc) : 0L);
|
|
if (nrigadoc>100 || (last_ndoc != new_ndoc) || (last_date != new_date ) || (last_clifor != new_clifor )|| (last_group != new_group ))
|
|
{
|
|
// emetti il doc
|
|
// reset
|
|
ntransac++;
|
|
if (new_ndoc>0L)
|
|
last_ndoc=new_ndoc;
|
|
if (new_clifor>0L)
|
|
last_clifor=new_clifor;
|
|
if (!new_group.blank())
|
|
last_group=new_group;
|
|
if (!new_date.empty())
|
|
last_date=new_date;
|
|
if (trans) delete trans;
|
|
trans = new TConfig(format("ND_%05d.ini",ntransac));
|
|
trans->set_paragraph("Transaction");
|
|
trans->set("Action","INSERT");
|
|
trans->set("Mode","AUTO");
|
|
trans->set("Firm",firm);
|
|
|
|
trans->set_paragraph(format("%d",LF_DOC));
|
|
if (new_ndoc>0)
|
|
trans->set(DOC_NDOC,new_ndoc);
|
|
if (new_date.empty())
|
|
new_date=TODAY;
|
|
trans->set(DOC_DATADOC, new_date);
|
|
trans->set(DOC_TIPOCF,"F");
|
|
if (new_clifor>0L)
|
|
trans->set(DOC_CODCF,new_clifor);
|
|
trans->set(DOC_PROVV,"D");
|
|
set_header(imp_file, *trans);
|
|
nrigadoc=0;
|
|
}
|
|
// righe
|
|
nrigadoc++;
|
|
trans->set_paragraph(format("%d,%d",LF_RIGHEDOC, nrigadoc));
|
|
set_body(imp_file, *trans);
|
|
}
|
|
imp_file.next();
|
|
}
|
|
if (trans) delete trans;
|
|
// genera i documenti
|
|
TExternal_app gestdoc("ve0.exe -1 -ind_*.ini ");
|
|
gestdoc.run();
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_head_F_ordcli(TImport_file & import, TConfig &trans)
|
|
{
|
|
trans.set(DOC_ANNO,import.get_date("FRDTE").year());
|
|
trans.set(DOC_CODNUM,(import.get("FPFAC")=="SE") ? "SEOC": "TSOC");
|
|
trans.set(DOC_TIPODOC,"ORC");
|
|
TDate dc(import.get_date("FRDTE"));
|
|
dc+=28;
|
|
round_date(dc,TRUE);
|
|
trans.set(DOC_DATACONS, dc);// stessa data del doc
|
|
}
|
|
void set_body_F_ordcli(TImport_file &import, TConfig &trans)
|
|
{
|
|
TToken_string tmp;
|
|
trans.set(RDOC_TIPORIGA,"01");
|
|
tmp =import.get_codice("FPROD");
|
|
trans.set(RDOC_CODART,tmp);
|
|
trans.set(RDOC_DESCR,cache().get(LF_ANAMAG,tmp).get("DESCR"));
|
|
tmp.add("1");
|
|
trans.set(RDOC_PREZZO,cache().get(LF_UMART,tmp).get("PREZZO"));
|
|
trans.set(RDOC_UMQTA,cache().get(LF_UMART,tmp).get("UM"));
|
|
trans.set(RDOC_QTA,import.get("FQTY"));
|
|
// gia' suddivisa su doc : trans.set(RDOC_DATACONS, import.get_date("FDATE"));
|
|
tmp=import.get("FPFAC");
|
|
tmp << 1;
|
|
trans.set(RDOC_CODMAG,tmp);
|
|
}
|
|
bool filter_F_ordcli(TImport_file & import)
|
|
{
|
|
bool ok= import.get("FID")=="FP" && import.get("FTYPE")=="F";
|
|
if (ok)
|
|
{
|
|
char type = cache().get(LF_ANAMAG,import.get_codice("FPROD")).get(ANAMAG_GRMERC)[0];
|
|
ok = (type== 'F');
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
void set_head_R_ordcli(TImport_file & import, TConfig &trans)
|
|
{
|
|
trans.set(DOC_ANNO,import.get_date("SRDTE").year());
|
|
trans.set(DOC_CODNUM,(import.get("SOFAC")=="SE") ? "SEOC": "TSOC");
|
|
trans.set(DOC_TIPODOC,"ORC");
|
|
TDate dc(import.get_date("SRDTE"));
|
|
dc+=28;
|
|
round_date(dc,TRUE);
|
|
trans.set(DOC_DATACONS, dc);// stessa data del doc
|
|
}
|
|
void set_body_R_ordcli(TImport_file &import, TConfig &trans)
|
|
{
|
|
TToken_string tmp;
|
|
trans.set(RDOC_TIPORIGA,"01");
|
|
tmp =import.get_codice("SPROD");
|
|
trans.set(RDOC_CODART,tmp);
|
|
trans.set(RDOC_DESCR,cache().get(LF_ANAMAG,tmp).get("DESCR"));
|
|
tmp.add("1");
|
|
trans.set(RDOC_PREZZO,cache().get(LF_UMART,tmp).get("PREZZO"));
|
|
trans.set(RDOC_UMQTA,cache().get(LF_UMART,tmp).get("UM"));
|
|
trans.set(RDOC_QTA,import.get("SQREQ"));
|
|
trans.set(RDOC_QTAEVASA,import.get("SQFIN"));
|
|
|
|
tmp=import.get("SOFAC");
|
|
tmp << 1;
|
|
trans.set(RDOC_CODMAG,tmp);
|
|
}
|
|
bool filter_R_ordcli(TImport_file & import)
|
|
{
|
|
bool ok=import.get("SID")=="SO";
|
|
if (ok)
|
|
{
|
|
char type = cache().get(LF_ANAMAG,import.get_codice("SPROD")).get(ANAMAG_GRMERC)[0];
|
|
ok = (type== 'F');
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
// ordini di produzione
|
|
void set_head_F_ordprod(TImport_file & import, TConfig &trans)
|
|
{
|
|
trans.set(DOC_ANNO,import.get_date("FRDTE").year());
|
|
trans.set(DOC_CODNUM,(import.get("FPFAC")=="SE") ? "SEOC": "TSOC");
|
|
trans.set("TIPODOC","ORP");
|
|
TDate dc(import.get_date("FRDTE"));
|
|
dc+=28;
|
|
round_date(dc);
|
|
TDate dd(trans.get(DOC_DATADOC));
|
|
if (dc < dd )
|
|
trans.set(DOC_DATADOC, dc);
|
|
trans.set(DOC_DATACONS, dc);
|
|
}
|
|
void set_body_F_ordprod(TImport_file &import, TConfig &trans)
|
|
{
|
|
TToken_string tmp,tmp2;
|
|
trans.set(RDOC_TIPORIGA,"01");
|
|
tmp =import.get_codice("FPROD");
|
|
trans.set(RDOC_CODART,tmp);
|
|
trans.set(RDOC_DESCR,cache().get(LF_ANAMAG,tmp).get("DESCR"));
|
|
tmp.add("1");
|
|
trans.set(RDOC_PREZZO,cache().get(LF_UMART,tmp).get("PREZZO"));
|
|
trans.set(RDOC_UMQTA,cache().get(LF_UMART,tmp).get("UM"));
|
|
|
|
tmp=import.get("FPFAC");
|
|
codimp2codmagdep(tmp, atoi(import.get("FPBOMM")), tmp2);
|
|
trans.set(RDOC_IMPIANTO,tmp);
|
|
trans.set(RDOC_CODMAG,tmp2);
|
|
trans.set(RDOC_QTA,import.get("FQTY"));
|
|
trans.set(RDOC_QTAEVASA,"0");
|
|
}
|
|
bool filter_F_ordprod(TImport_file & import)
|
|
{
|
|
bool ok= import.get("FID")=="FP" && import.get("FPFAC")=="SE" && import.get("FTYPE")=="F";
|
|
if (ok)
|
|
{
|
|
char type = cache().get(LF_ANAMAG,import.get_codice("FPROD")).get(ANAMAG_GRMERC)[0];
|
|
ok = (type== 'F' || type== 'S' );
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
void set_head_R_ordprod(TImport_file & import, TConfig &trans)
|
|
{
|
|
trans.set(DOC_ANNO,import.get_date("SRDTE").year());
|
|
trans.set("CODNUM",(import.get("SOFAC")=="SE") ? "SEMP": "TSMP");
|
|
trans.set("TIPODOC","ORP");
|
|
TDate dc(import.get_date("SRDTE"));
|
|
dc+=28;
|
|
round_date(dc);
|
|
TDate dd(trans.get(DOC_DATADOC));
|
|
if (dc < dd )
|
|
trans.set(DOC_DATADOC, dc);
|
|
trans.set(DOC_DATACONS, dc);
|
|
}
|
|
void set_body_R_ordprod(TImport_file &import, TConfig &trans)
|
|
{
|
|
TToken_string tmp,tmp2;
|
|
trans.set(RDOC_TIPORIGA,"01");
|
|
tmp =import.get_codice("SPROD");
|
|
trans.set(RDOC_CODART,tmp);
|
|
trans.set(RDOC_DESCR,cache().get(LF_ANAMAG,tmp).get("DESCR"));
|
|
tmp.add("1");
|
|
trans.set(RDOC_PREZZO,cache().get(LF_UMART,tmp).get("PREZZO"));
|
|
trans.set(RDOC_UMQTA,cache().get(LF_UMART,tmp).get("UM"));
|
|
|
|
tmp=import.get("SOFAC");
|
|
codimp2codmagdep(tmp, atoi(import.get("SOBOMM")), tmp2);
|
|
trans.set(RDOC_IMPIANTO,tmp);
|
|
trans.set(RDOC_CODMAG,tmp2);
|
|
trans.set(RDOC_QTA,import.get("SQREQ"));
|
|
trans.set(RDOC_QTAEVASA,import.get("SQFIN"));
|
|
add_stdlabors(import.get_codice("SPROD"), import.get_long("SWRKC"), int(import.get_long("SOBOMM")));
|
|
}
|
|
bool filter_R_ordprod(TImport_file & import)
|
|
{
|
|
bool ok=(import.get("SID")=="SO" && import.get("SOFAC")=="SE");
|
|
if (ok)
|
|
{
|
|
char type = cache().get(LF_ANAMAG,import.get_codice("SPROD")).get(ANAMAG_GRMERC)[0];
|
|
ok = (type== 'F'||type== 'S');
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
|
|
|
|
void set_head_ordacq(TImport_file & import, TConfig &trans)
|
|
{
|
|
TString codimp;
|
|
int nummag=(atoi(import.get_date("PWHSE"))) ;
|
|
num_mag2main_imp(nummag, codimp);
|
|
|
|
TDate dc(import.get_date("PDDTE"));
|
|
TDate dd(import.get_date("PEDTE"));//data doc
|
|
if (dc < dd )
|
|
dd=dc;
|
|
trans.set(DOC_DATADOC, dd);
|
|
trans.set(DOC_DATACONS, dc);
|
|
trans.set(DOC_ANNO,dd.year());
|
|
trans.set("CODNUM",(codimp=="SE") ? "SEOF": "TSOF");
|
|
trans.set("TIPODOC","ORF");
|
|
}
|
|
|
|
void set_body_ordacq(TImport_file &import, TConfig &trans)
|
|
{
|
|
TToken_string tmp,tmp2;
|
|
trans.set(RDOC_TIPORIGA,"01");
|
|
tmp=import.get_codice("PPROD");
|
|
trans.set(RDOC_CODART,tmp);
|
|
trans.set(RDOC_DESCR,cache().get(LF_ANAMAG,tmp).get("DESCR"));
|
|
//trans.set(RDOC_PREZZO,import.get("POLIST"));
|
|
trans.set(RDOC_UMQTA,import.get("PUM"));
|
|
|
|
int nummag=(atoi(import.get_date("PWHSE"))) ;
|
|
num_mag2main_imp(nummag, tmp);
|
|
tmp << "1";
|
|
trans.set(RDOC_CODMAG,tmp);
|
|
trans.set(RDOC_QTA,import.get("PQORD"));
|
|
trans.set(RDOC_QTAEVASA,import.get("PQREC"));
|
|
}
|
|
|
|
bool filter_ordacq(TImport_file & import)
|
|
{
|
|
TString codimp;
|
|
int nummag=(atoi(import.get_date("PWHSE"))) ;
|
|
num_mag2main_imp(nummag, codimp);
|
|
bool ok =(codimp == "SE" ||codimp == "TS" );
|
|
if (!ok)
|
|
error_box("Ordine di acquisto sull'impianto %s",(const char *)codimp);
|
|
return ok;
|
|
}
|
|
|
|
void set_head_movmag(TImport_file & import, TConfig &trans)
|
|
{
|
|
bool alertnegative=TRUE;
|
|
long codcli=atol(import.get("TVEND"));
|
|
int magno=atoi(import.get("TWHS"));
|
|
TString codimp;
|
|
num_mag2main_imp(magno, codimp);
|
|
|
|
TString codnum,tipodoc, causmag, descrmov;
|
|
codnum=codimp;
|
|
const char * cod0=(const char * )import.get("TTYPE");
|
|
char cod1=*(cod0+1);
|
|
long numdoc=0L;// riassegno qui il numdoc , per usare il nummag al suo posto come ragguppatore nel ciclo di crea_docs
|
|
switch (*cod0)
|
|
{
|
|
case 'O': // completed;
|
|
descrmov="Movimento di apertura di inizio esercizio";
|
|
codnum << "DI";
|
|
causmag="RIMI";
|
|
codcli=0L;
|
|
break;
|
|
|
|
case 'A': // completed
|
|
descrmov="Differenza inventariale";
|
|
codnum << "DI";
|
|
alertnegative=FALSE;
|
|
codcli=0L;
|
|
break;
|
|
|
|
case '0': // completed;
|
|
descrmov="Carico prodotti finiti da terzi";
|
|
codnum << "BE";
|
|
causmag="CFAL";
|
|
break;
|
|
|
|
case 'C': // completed;
|
|
CHECKS(cod1=='3',"Causale sconosciuta :%s",cod0);
|
|
descrmov="Scarico componenti verso terzisti";
|
|
codnum << "MM";
|
|
causmag="SCAR";
|
|
trans.set(DOC_TIPOCF,"F");
|
|
break;
|
|
|
|
case 'M':
|
|
if (cod1=='\0') // completed;
|
|
{
|
|
descrmov="Confezionamento prodotti finiti";
|
|
codnum << "MM";
|
|
} else {
|
|
descrmov="Sconfezionamento";
|
|
codnum << "MM";
|
|
}
|
|
codcli=0L;
|
|
alertnegative=FALSE;
|
|
break;
|
|
|
|
case 'U':
|
|
if (cod1=='\0') // completed;
|
|
{
|
|
descrmov="acquisto";
|
|
codnum << "BA";
|
|
} else {
|
|
descrmov="reso";
|
|
codnum << "RF";
|
|
}
|
|
break;
|
|
|
|
case 'I': // confirmed
|
|
descrmov="Scarico componenti ";
|
|
codnum << "MM";
|
|
causmag="SCAR";
|
|
break;
|
|
|
|
case 'T': // to be confirmed
|
|
codnum << "MM";
|
|
descrmov="Trasferimento";
|
|
codcli=0L;
|
|
alertnegative=FALSE;
|
|
break;
|
|
case 'X': // completed;
|
|
codnum << "MM";
|
|
if (cod1=='7')
|
|
{
|
|
descrmov="Scarico manuale";
|
|
causmag="SCAR";
|
|
} else if (cod1=='8')
|
|
{
|
|
descrmov="Carico manuale";
|
|
causmag="CAR";
|
|
} else {
|
|
descrmov="Scarico per campionatura";
|
|
causmag="SCAR";
|
|
}
|
|
codcli=0L;
|
|
break;
|
|
default:
|
|
CHECKS(TRUE,"Causale sconosciuta :%s",cod0);
|
|
}
|
|
trans.set("CODNUM",codnum);
|
|
if (!tipodoc.blank())
|
|
trans.set("TIPODOC",tipodoc);
|
|
if (!causmag.blank())
|
|
trans.set("CAUSMAG",causmag);
|
|
trans.set("DESCR",descrmov);
|
|
trans.set(DOC_NDOC,0L);
|
|
trans.set(DOC_CODCF,codcli);
|
|
trans.set(DOC_ANNO,import.get_date("TTDTE").year());
|
|
trans.set(DOC_NUMDOCRIF,import.get("TREF"));
|
|
trans.set(DOC_DATADOCRIF,import.get_date("TSDTE"));
|
|
|
|
}
|
|
|
|
void set_body_movmag(TImport_file &import, TConfig &trans)
|
|
{
|
|
TString codimp, codmag, causmag, desc;
|
|
int magno=atoi(import.get("TWHS"));
|
|
num_mag2main_imp(magno, codimp);
|
|
int terzista=location2metod(import.get_long("TLOCT"));
|
|
codimp2codmagdep(codimp, terzista,codmag);
|
|
|
|
TToken_string tmp(import.get_codice("TPROD"));
|
|
trans.set(RDOC_TIPORIGA,"01");
|
|
trans.set(RDOC_CODART,tmp);
|
|
desc =cache().get(LF_ANAMAG,tmp).get("DESCR");
|
|
if (terzista==99)
|
|
desc << "(terzista " << atol(import.get("TLOCT")) << ")";
|
|
trans.set(RDOC_DESCR,desc);
|
|
trans.set(RDOC_UMQTA,import.get("THTUM"));
|
|
|
|
trans.set(RDOC_CODMAG,codmag);
|
|
const char * cod0=(const char * )import.get("TTYPE");
|
|
real qta(import.get("TQTY"));
|
|
switch (*cod0)
|
|
{
|
|
case 'M':
|
|
if (*(cod0+1)=='1')
|
|
qta = -qta;
|
|
case 'A':
|
|
case 'T':
|
|
if (qta >= ZERO)
|
|
{
|
|
causmag="CAR";
|
|
} else {
|
|
qta = -qta;
|
|
causmag="SCAR";
|
|
}
|
|
trans.set(RDOC_CAUSMAG,causmag);
|
|
break;
|
|
|
|
case 'O':
|
|
case '0':
|
|
case 'C':
|
|
case 'U':
|
|
case 'I':
|
|
case 'X':
|
|
break;
|
|
}
|
|
trans.set(RDOC_QTA, qta.string());
|
|
}
|
|
|
|
bool filter_movmag(TImport_file & import)
|
|
{
|
|
const char * cod0=(const char * )import.get("TTYPE");
|
|
switch (*cod0)
|
|
{
|
|
case 'O': // completed;
|
|
case 'A': // completed
|
|
case '0': // completed;
|
|
case 'C': // completed;
|
|
case 'M':
|
|
case 'U':
|
|
case 'I': // confirmed
|
|
case 'T': // to be confirmed
|
|
case 'X': // completed;
|
|
return TRUE;
|
|
break;
|
|
}
|
|
return FALSE;
|
|
}
|
|
|
|
|
|
bool filter_movmagSE(TImport_file & import)
|
|
{
|
|
TString codimp;
|
|
int magno=atoi(import.get("TWHS"));
|
|
num_mag2main_imp(magno, codimp);
|
|
return codimp=="SE" && filter_movmag(import);
|
|
}
|
|
|
|
bool filter_movmagTS(TImport_file & import)
|
|
{
|
|
TString codimp;
|
|
int magno=atoi(import.get("TWHS"));
|
|
num_mag2main_imp(magno, codimp);
|
|
return codimp=="TS";
|
|
}
|
|
|
|
|
|
bool TImporta_BPCS ::importa_ordacq(TMask & m)
|
|
{
|
|
clear_docs("SEOF");
|
|
clear_docs("TSOF");
|
|
TImport_file ordacq(m.get(F_PATH),BPCS_ORDACQ);
|
|
return creadocs("Importazione ordini di acquisto..",get_firm(),ordacq,
|
|
"PORD","PVEND",NULL,NULL,
|
|
set_head_ordacq,set_body_ordacq,filter_ordacq);
|
|
}
|
|
|
|
bool TImporta_BPCS ::importa_ordcli(TMask & m)
|
|
{
|
|
clear_docs("SEOC");
|
|
clear_docs("TSOC");
|
|
TImport_file released_orders(m.get(F_PATH),BPCS_SHOPORDS);
|
|
bool ok = creadocs("Importazione ordini cliente (1)..",get_firm(),released_orders,
|
|
NULL,"SCUST","SRDTE","SOFAC",
|
|
set_head_R_ordcli,set_body_R_ordcli,filter_R_ordcli);
|
|
|
|
TImport_file firm_orders(m.get(F_PATH),BPCS_FIRMORD);
|
|
ok = ok && creadocs("Importazione ordini cliente (2)..",get_firm(),firm_orders,
|
|
NULL,"FPPVND","FRDTE","FPFAC",
|
|
set_head_F_ordcli,set_body_F_ordcli,filter_F_ordcli);
|
|
return ok;
|
|
}
|
|
|
|
bool TImporta_BPCS ::importa_ordprod(TMask & m)
|
|
{
|
|
clear_docs("SEMP");
|
|
clear_docs("SEOP");
|
|
clear_docs("SEFA");
|
|
clear_docs("TSMP");
|
|
clear_docs("TSOP");
|
|
clear_docs("TSFA");
|
|
TImport_file released_orders(m.get(F_PATH),BPCS_SHOPORDS);
|
|
bool ok = creadocs("Importazione ordini di produzione (1)..",get_firm(),released_orders,
|
|
"SORD",NULL,"SRDTE","SOFAC",
|
|
set_head_R_ordprod,set_body_R_ordprod,filter_R_ordprod);
|
|
|
|
TImport_file firm_orders(m.get(F_PATH),BPCS_FIRMORD);
|
|
ok = ok && creadocs("Importazione ordini di produzione (2)..",get_firm(),firm_orders,
|
|
NULL,"FPPVND","FRDTE","FPFAC",
|
|
set_head_F_ordprod,set_body_F_ordprod,filter_F_ordprod);
|
|
return ok;
|
|
}
|
|
|
|
|
|
bool TImporta_BPCS ::importa_movmag(TMask & m, bool segrate, bool trieste)
|
|
{
|
|
clear_docs("TSBA");
|
|
clear_docs("TSBE");
|
|
clear_docs("TSBT");
|
|
clear_docs("TSBU");
|
|
clear_docs("TSBV");
|
|
clear_docs("TSDI");
|
|
clear_docs("TSMM");
|
|
clear_docs("TSRF");
|
|
clear_docs("SEBA");
|
|
clear_docs("SEBE");
|
|
clear_docs("SEBT");
|
|
clear_docs("SEBU");
|
|
clear_docs("SEBV");
|
|
clear_docs("SEDI");
|
|
clear_docs("SEMM");
|
|
clear_docs("SERF");
|
|
TImport_file movmag(m.get(F_PATH),BPCS_MOVMAG);
|
|
bool ok = TRUE;
|
|
if (segrate)
|
|
ok &= creadocs("Importazione movimenti magazzino di Segrate..",get_firm(),movmag,
|
|
NULL,"TREFM","TTDTE","TTYPE",
|
|
set_head_movmag,set_body_movmag,filter_movmagSE);
|
|
if (trieste)
|
|
ok &= creadocs("Importazione movimenti magazzino di Trieste..",get_firm(),movmag,
|
|
NULL,"TREFM","TTDTE","TTYPE",
|
|
set_head_movmag,set_body_movmag,filter_movmagTS);
|
|
return ok;
|
|
/*bool creadocs( ........
|
|
char *FieldNumDoc,char *FieldClifor,char *FieldDataDoc, char *Group
|
|
...........)*/
|
|
}
|
|
|
|
|
|
void TImporta_BPCS ::main_loop()
|
|
{
|
|
TMask m("dbcv00a.msk");
|
|
m.field(F_PATH).set("E:\\bpcs\\");
|
|
while (m.run()!=K_QUIT)
|
|
{
|
|
if (m.get_bool(F_RESETMORTI) && noyes_box("Confermi la cancellazione del file degli articoli da escludere ?"))
|
|
{
|
|
TSupport_file morti(LF_DIST, ANAGRAFICA_MORTI);
|
|
morti.zap();
|
|
}
|
|
if (m.get_bool(F_CREAMAG3))
|
|
crea_mag3();
|
|
|
|
bool ok=TRUE;
|
|
if (m.get_bool(F_ARTS))
|
|
{
|
|
if (m.get_bool(F_CHANGEGMC))
|
|
ok|=cambia_gmc(m);
|
|
else
|
|
{
|
|
if (m.get_bool(F_BOMS))
|
|
delete_boms();
|
|
ok|=importa_arts(m); // articoli e distinte virtuali fantasma
|
|
}
|
|
}
|
|
if (m.get_bool(F_BOMS))
|
|
{
|
|
if (0 && !m.get_bool(F_ARTS))
|
|
{
|
|
delete_boms();
|
|
ok|=importa_arts(m, TRUE); // importa distinte virtuali fantasma
|
|
}
|
|
ok|=importa_boms(m);
|
|
}
|
|
if (m.get_bool(F_DIVS))
|
|
ok|=importa_ums_BP(m);
|
|
if (m.get_bool(F_ORDACQ))
|
|
ok|=importa_ordacq(m);
|
|
if (m.get_bool(F_ORDPROD))
|
|
ok|=importa_ordprod(m);
|
|
if (m.get_bool(F_ORDCLI))
|
|
ok|=importa_ordcli(m);
|
|
if (m.get_bool(F_MOVMAG))
|
|
ok|=importa_movmag(m,TRUE,FALSE);
|
|
|
|
if (ok)
|
|
message_box("Operazione conclusa");
|
|
else
|
|
message_box("Operazione interrotta");
|
|
}
|
|
}
|
|
|
|
|
|
int dbcv00(int argc, char* argv[])
|
|
{
|
|
TString name;
|
|
TImporta_BPCS dt;
|
|
dt.run(argc, argv, "Conversione distinte da BPCS");
|
|
return 0;
|
|
}
|