1999-04-06 15:34:39 +00:00
# include "dbcv.h"
# include "dbcv09.h"
1999-07-16 14:59:11 +00:00
# include "dbcv00a.h"
2000-05-05 15:25:49 +00:00
# include "dbcv01.h"
1999-07-16 14:59:11 +00:00
# include <automask.h>
1999-04-06 15:34:39 +00:00
# include <applicat.h>
# include <execp.h>
# include "..\mg\anamag.h"
# include "..\mg\mag.h"
2001-05-02 13:40:49 +00:00
# include "..\mg\mglib.h"
1999-04-06 15:34:39 +00:00
# include "..\include\doc.h"
# include "..\include\rdoc.h"
2000-05-05 15:25:49 +00:00
# include "..\ve\velib.h"
1999-04-06 15:34:39 +00:00
1999-07-16 14:59:11 +00:00
typedef void ( * SET_DOC_FUN ) ( TImport_file & import , TConfig & trans ) ;
2001-05-02 13:40:49 +00:00
typedef int ( * SET_BODYDOC_FUN ) ( TImport_file & import , TConfig & trans , const bool dotrans ) ;
2000-05-05 15:25:49 +00:00
typedef const char * ( * TIPOCF_FUN ) ( TImport_file & import ) ;
1999-07-16 14:59:11 +00:00
typedef bool ( * FILTER_FUN ) ( TImport_file & import ) ;
2001-05-02 13:40:49 +00:00
typedef bool ( * GROUPBRK_FUN ) ( TImport_file & import ) ;
1999-04-06 15:34:39 +00:00
2000-05-05 15:25:49 +00:00
static TExternisamfile * _ithcheck = NULL ;
static bool _check = TRUE ;
2001-05-02 13:40:49 +00:00
# include "dbcvlib.h"
2000-05-05 15:25:49 +00:00
1999-07-16 14:59:11 +00:00
class TImporta_mask : public TAutomask
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
protected :
virtual bool on_field_event ( TOperable_field & o , TField_event e , long jolly ) ;
1999-04-06 15:34:39 +00:00
public :
1999-07-16 14:59:11 +00:00
TImporta_mask ( ) : TAutomask ( " dbcv00a.msk " ) { }
1999-04-06 15:34:39 +00:00
} ;
1999-07-16 14:59:11 +00:00
bool TImporta_mask : : on_field_event ( TOperable_field & o , TField_event e , long jolly )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
return TRUE ;
1999-04-06 15:34:39 +00:00
}
class TImporta_BPCS : public TSkeleton_application
{
TLocalisamfile * _dist , * _rdist , * _anamag , * _umart , * _codcorr , * _mag ;
private :
void delete_ghosts ( ) ;
1999-07-16 14:59:11 +00:00
void delete_arts ( ) ;
bool delete_boms ( ) ;
1999-04-06 15:34:39 +00:00
int read_last_rdist ( const char * item_code ) ;
bool read_is_dist ( const char * item_code ) ;
1999-07-16 14:59:11 +00:00
bool is_ghost ( const char * item_code ) ;
1999-04-06 15:34:39 +00:00
const char * read_first_um ( const char * item_code ) ;
2001-05-02 13:40:49 +00:00
1999-04-06 15:34:39 +00:00
bool creadocs ( const char * msg ,
long firm , TImport_file & imp_file ,
1999-07-16 14:59:11 +00:00
const char * FieldNumDoc , const char * FieldClifor , const char * FieldDataDoc , const char * FieldGroup1 , const char * FieldGroup2 , const char * FieldGroup3 ,
2001-05-02 13:40:49 +00:00
SET_DOC_FUN set_header , SET_BODYDOC_FUN set_body , FILTER_FUN filter , GROUPBRK_FUN grp ,
2000-05-05 15:25:49 +00:00
TIPOCF_FUN tipocf , bool do_ve0 = TRUE ) ;
1999-04-06 15:34:39 +00:00
2001-05-02 13:40:49 +00:00
void clear_docs ( long firm , const char * num , const TDate * fromdate = NULL , const TDate * todate = NULL , const long fromnum = 0 , const long tonum = - 1 ) ;
2000-05-05 15:25:49 +00:00
void change_docs_status ( const char * num , const TDate * fromdate , const TDate * todate , int fromstatus , int tostatus ) ;
1999-04-06 15:34:39 +00:00
void newums ( ) ;
2000-05-05 15:25:49 +00:00
protected :
void confirm_docs ( const char * num , const TDate * fromdate , const TDate * todate ) ;
void unconfirm_docs ( const char * num , const TDate * fromdate , const TDate * todate ) ;
1999-04-06 15:34:39 +00:00
protected :
1999-07-16 14:59:11 +00:00
virtual bool create ( ) ;
virtual bool destroy ( ) ;
1999-04-06 15:34:39 +00:00
bool importa_boms ( TMask & m ) ;
bool cambia_gmc ( TMask & m ) ;
1999-07-16 14:59:11 +00:00
bool importa_arts ( TMask & m , const bool erase , const bool sologhost = FALSE ) ;
1999-04-06 15:34:39 +00:00
bool importa_ums_BP ( TMask & m ) ;
bool importa_ordacq ( TMask & m ) ;
bool importa_ordcli ( TMask & m ) ;
bool importa_ordprod ( TMask & m ) ;
2000-05-05 15:25:49 +00:00
bool importa_movmag ( TMask & m ) ;
bool importa_movmag ( TImport_file & impfile , bool segrate , bool trieste , const TDate & fromdate , const TDate & todate , bool testonly , bool noclear ) ;
bool importa_bolacq ( TMask & m ) ;
bool importa_bolacq ( TImport_file & impfile , bool segrate , bool trieste , const TDate & fromdate , const TDate & todate , bool testonly , bool noclear ) ;
1999-04-06 15:34:39 +00:00
protected :
virtual void main_loop ( ) ;
} ;
2000-05-05 15:25:49 +00:00
class TImporta_automag_BPCS : public TImporta_BPCS
{
protected :
virtual void main_loop ( ) ;
} ;
1999-04-06 15:34:39 +00:00
bool TImporta_BPCS : : create ( )
{
2000-05-05 15:25:49 +00:00
open_files ( LF_TAB , LF_TABCOM , LF_CLIFO , LF_CFVEN , LF_RIGHEDOC , LF_MOVMAG , LF_RMOVMAG , 0 ) ;
1999-04-06 15:34:39 +00:00
_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 ( ) ;
}
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 ;
}
1999-07-16 14:59:11 +00:00
bool TImporta_BPCS : : is_ghost ( const char * item_code )
1999-04-06 15:34:39 +00:00
{
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 " ) ;
}
1999-07-16 14:59:11 +00:00
// cancella gli articoli
void TImporta_BPCS : : delete_arts ( )
{
TIndwin info ( 60 , " Cancellazione articoli... " , FALSE , FALSE ) ;
int err ;
_anamag - > first ( ) ;
for ( long i = _anamag - > items ( ) ; i > 0 ; i - - )
{
_anamag - > readat ( i ) ;
err = _anamag - > remove ( ) ;
if ( ( i % TICK ) = = 0 )
do_events ( ) ;
}
}
1999-04-06 15:34:39 +00:00
// cancella le distinte che non sono lavorazioni
1999-07-16 14:59:11 +00:00
bool TImporta_BPCS : : delete_boms ( )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
bool retv = FALSE ;
1999-04-06 15:34:39 +00:00
TWait_cursor hourglass ;
TIndwin info ( 60 , " Cancellazione distinte... " , FALSE , FALSE ) ;
// distinte
1999-07-16 14:59:11 +00:00
for ( long i = _dist - > items ( ) ; i > 0 ; i - - )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
_dist - > readat ( i ) ;
if ( cache ( ) . get ( " LAV " , _dist - > get ( " CODDIST " ) ) . empty ( ) )
1999-04-06 15:34:39 +00:00
{
// non e' una lavorazione
_dist - > remove ( ) ;
}
1999-07-16 14:59:11 +00:00
if ( ( i % TICK ) = = 0 )
do_events ( ) ;
1999-04-06 15:34:39 +00:00
}
// righe distinte
1999-07-16 14:59:11 +00:00
for ( i = _rdist - > items ( ) ; i > 0 ; i - - )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
_rdist - > readat ( i ) ;
if ( _rdist - > get ( " TIPO " ) ! = " L " | |
_rdist - > get ( " CODCOMP " ) . left ( 5 ) = = " ACQUA " )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
// non e' una lavorazione interessante
1999-04-06 15:34:39 +00:00
_rdist - > remove ( ) ;
1999-07-16 14:59:11 +00:00
}
else
{
_rdist - > put ( " NRIG " , _rdist - > get ( " NRIG " ) + 200 ) ;
_rdist - > rewrite ( ) ;
retv = TRUE ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
if ( ( i % TICK ) = = 0 )
do_events ( ) ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
return retv ;
1999-04-06 15:34:39 +00:00
}
// 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 ;
1999-07-16 14:59:11 +00:00
int bseq = 0 ;
1999-04-06 15:34:39 +00:00
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 " ) ;
1999-07-16 14:59:11 +00:00
bool skip = ! ( ( ddis = = 99999999 ) | | ( ddis = = 9999999 ) | | ( ddis = = 999999 ) | | ( ddis = = 99999 ) ) ;
if ( skipped_lcode = = current_lcode | | dead_lcode = = current_lcode )
1999-04-06 15:34:39 +00:00
skip = TRUE ;
1999-07-16 14:59:11 +00:00
if ( ! skip & & m . get_bool ( F_CHECKDEADARTS ) )
1999-04-06 15:34:39 +00:00
{
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
{
TTimed_skipbox bbox ( format ( " La distinta %s (%s) , di % s metodo ' % 02 d ' , 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 ;
}
}
}
1999-07-16 14:59:11 +00:00
// importa solo gli impianti SEgrate e TrieSte
2001-05-02 13:40:49 +00:00
if ( ! skip & & ( impianto = = " SE " | | impianto = = " TS " ) /* && metodo == 99 */ )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
main_imp = impianto ;
do {
if ( impianto = = " PD " )
impianto = " PR " ;
if ( metodo = = 7 )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
impianto = " PD " ;
metodo = 0 ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
const TString8 father_grmerc = cache ( ) . get ( LF_ANAMAG , old_code ) . get ( " GRMERC " ) ;
if ( metodo ! = 0 )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
if ( metodo = = 99 )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
if ( cache ( ) . get ( LF_ANAMAG , old_code ) . get ( ANAMAG_GRMERC ) [ 0 ] ! = ' F ' )
message_box ( " Il codice %s con metodo 99 non e' un finito " , ( const char * ) old_code ) ;
// sconfezionamento
impianto = format ( " %s9%02d " , ( const char * ) main_imp , metodo ) ;
if ( cache ( ) . get ( " LNP " , impianto ) . empty ( ) )
{
cache ( ) . discard ( " LNP " , impianto ) ;
// inserisce la linea di sconfezionamento
TTable imp ( " LNP " ) ;
imp . put ( " CODTAB " , impianto ) ;
imp . put ( " S0 " , " Riconfezionamento/sconfezionamento " ) ;
imp . put ( " S6 " , main_imp ) ;
imp . put ( " S7 " , format ( " %s1 " , ( const char * ) impianto ) ) ;
imp . put ( " B9 " , " X " ) ;
imp . write ( ) ;
}
}
else
{
// terzisti
impianto = format ( " X%02d%s " , metodo , ( const char * ) main_imp ) ;
if ( cache ( ) . get ( " LNP " , impianto ) . empty ( ) )
{
cache ( ) . discard ( " LNP " , impianto ) ;
// inserisce il terzista come linea produttiva sull'impianto esterno
TTable imp ( " LNP " ) ;
imp . put ( " CODTAB " , impianto ) ;
imp . put ( " S0 " , format ( " %s (%s) " , descr_method ( metodo ) , ( const char * ) impianto ) ) ;
imp . put ( " S6 " , " XT " ) ;
imp . put ( " S7 " , format ( " %s3%02d " , ( const char * ) impianto , metodo ) ) ;
imp . put ( " B9 " , " X " ) ;
imp . write ( ) ;
}
}
}
// padre
TString descr , um_f ( read_first_um ( old_code ) ) ;
TString item_code = old_code ;
item_code < < " __ " < < impianto ;
const bool father_ghost = is_ghost ( old_code ) ;
if ( father_ghost )
descr = cache ( ) . get ( LF_DIST , old_code ) . get ( " DESCR " ) ;
else
descr = cache ( ) . get ( LF_ANAMAG , old_code ) . get ( " DESCR " ) ;
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 ) ;
1999-04-06 15:34:39 +00:00
1999-07-16 14:59:11 +00:00
_dist - > zero ( ) ;
_dist - > put ( " CODDIST " , old_code ) ;
_dist - > put ( " DESCR " , descr ) ;
_dist - > put ( " VIRTUALE " , " " ) ;
_dist - > put ( " MASTER " , " X " ) ;
_dist - > put ( " ARTPROD " , " X " ) ;
_dist - > put ( " UM " , um_f ) ;
TString varvar ( " VARIANTE= " ) ;
varvar < < " _DISTINTA+ \" __ \" +IF(_IMPIANTO!= \" XT \" ,_IMPIANTO,_LINEA) " ;
_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 ) ;
_rdist - > write ( ) ;
}
}
}
// figlio
TString son_code = boms . get_codice ( " BCHLD " ) ;
TString um_s = read_first_um ( son_code ) ;
const bool son_ghost = is_ghost ( son_code ) ;
if ( son_ghost )
son_code < < " __ " < < impianto ;
// scrivi la bom
if ( last_code ! = item_code )
{
if ( cache ( ) . get ( LF_DIST , item_code ) . empty ( ) )
{
cache ( ) . discard ( LF_DIST , item_code ) ;
descr < < " (impianto " < < main_imp < < " ) " ;
_dist - > zero ( ' ' ) ;
_dist - > put ( " CODDIST " , item_code ) ;
_dist - > put ( " DESCR " , descr ) ;
_dist - > put ( " VIRTUALE " , " X " ) ;
_dist - > put ( " ARTPROD " , " " ) ;
_dist - > put ( " UM " , " BP " ) ;
if ( impianto . left ( 2 ) ! = " XT " )
{
// l'albero della distinte di un impianto e' su qyell'impianto
// i terzisti seguono l'impianto di pianificazione
TString varimp ( " _IMPIANTO= " ) ;
varimp < < ' " ' < < main_imp < < ' " ' ;
_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 ;
if ( bseq > 0 | | ( impianto ! = " PD " & & impianto ! = " PR " ) )
bseq = 0 ;
}
if ( impianto = = " PD " )
bseq - - ;
else if ( impianto ! = " PR " )
bseq + + ;
if ( bseq = = 0 ) error_box ( " Numero riga 0 per %s / %s " , ( const char * ) item_code , ( const char * ) son_code ) ;
_rdist - > zero ( ' ' ) ;
_rdist - > put ( " CODDIST " , item_code ) ;
_rdist - > put ( " NRIG " , bseq > 0 ? bseq : - bseq ) ;
if ( son_ghost )
_rdist - > put ( " TIPO " , " D " ) ;
else if ( son_code = = " ACQUA " | | son_code = = " ACQUADEION " )
_rdist - > put ( " TIPO " , " L " ) ;
else
_rdist - > put ( " TIPO " , " A " ) ;
_rdist - > put ( " CODCOMP " , son_code ) ;
_rdist - > put ( " UM " , um_s ) ;
_rdist - > put ( " EXPR " , boms . get_real ( " BQREQ " ) ) ;
_rdist - > write ( ) ;
imported_lcode = current_lcode ;
} while ( impianto = = " PD " ) ;
1999-04-06 15:34:39 +00:00
}
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
1999-07-16 14:59:11 +00:00
bool TImporta_BPCS : : importa_arts ( TMask & m , const bool erase , const bool sologhost )
1999-04-06 15:34:39 +00:00
{
TWait_cursor hourglass ;
cache ( ) . flush ( LF_ANAMAG ) ;
cache ( ) . flush ( LF_DIST ) ;
cache ( ) . flush ( LF_UMART ) ;
1999-07-16 14:59:11 +00:00
if ( erase )
delete_arts ( ) ;
1999-04-06 15:34:39 +00:00
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 ) ;
1999-07-16 14:59:11 +00:00
if ( ( ! m . get_bool ( F_CHECKDEADARTS ) | | morti . read ( ) ! = NOERR ) & &
1999-04-06 15:34:39 +00:00
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 " ) ) ;
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_CODFORN , items . get_long ( " IVEND " ) ) ;
1999-04-06 15:34:39 +00:00
_anamag - > put ( ANAMAG_UMP , " KG " ) ;
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_PESO , items . get_real ( " IWGHT " ) ) ;
1999-04-06 15:34:39 +00:00
// riordino
_anamag - > put ( ANAMAG_RIORDINO , " F " ) ; //_anamag->put( ANAMAG_RIORDINO , items.get("IMRP")=="M" ? "F" : "P" );
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_GIORNIRIOR , items . get_long ( " ILEAD " ) ) ;
_anamag - > put ( ANAMAG_LOTTORIOR , items . get_real ( " ILOTS " ) ) ;
_anamag - > put ( ANAMAG_LOTTOIRIOR , items . get_real ( " IIOQ " ) ) ;
1999-04-06 15:34:39 +00:00
//
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_PPCONF , items . get_long ( " IFII " ) ) ;
_anamag - > put ( ANAMAG_PPCOLLO , items . get_long ( " IFII " ) ) ;
1999-04-06 15:34:39 +00:00
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 ) ;
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_COSTSTD , items . get_real ( " ISCST " ) ) ;
_anamag - > put ( ANAMAG_ULTCOS1 , items . get_real ( " IACST " ) ) ;
1999-04-06 15:34:39 +00:00
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 " ) ) ) ;
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_USER1 , items_ext . get_real ( " MSIDR " ) ) ; // idrati
_anamag - > put ( ANAMAG_USER2 , items_ext . get_real ( " MSANI " ) ) ; //anidri
1999-04-06 15:34:39 +00:00
_anamag - > put ( ANAMAG_USER3 , items_ext . get ( " MSTAL " ) ) ; //alcool
// dimensioni
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_USER4 , items_ext . get_long ( " MSSLU " ) ) ;
_anamag - > put ( ANAMAG_USER5 , items_ext . get_long ( " MSSAL " ) ) ;
_anamag - > put ( ANAMAG_USER6 , items_ext . get_long ( " MSCPR " ) ) ;
1999-04-06 15:34:39 +00:00
// composizione pallets
2001-05-02 13:40:49 +00:00
_anamag - > put ( ANAMAG_USER7 , items_ext . get_long ( " MSCST " ) ) ; // casse per strato
_anamag - > put ( ANAMAG_USER8 , items_ext . get_long ( " MSSTP " ) ) ; // strati per pallet
1999-04-06 15:34:39 +00:00
}
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 " ) ;
1999-07-16 14:59:11 +00:00
if ( ! m . get ( F_EAN ) . blank ( ) )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
TString16 eancode = items . get ( " IDRAW " ) ;
if ( ean ! = 0L | | ( eancode [ 0 ] > = ' A ' & & eancode [ 0 ] < = ' Z ' & & atol ( eancode . sub ( 1 ) ) ! = 0L ) )
{
_codcorr - > zero ( ) ;
_codcorr - > put ( " CODARTALT " , eancode ) ;
_codcorr - > put ( " NRIGA " , 1 ) ;
_codcorr - > put ( " TIPO " , m . get ( F_EAN ) ) ;
_codcorr - > put ( " CODART " , item_code ) ;
force_write ( * _codcorr ) ;
}
1999-04-06 15:34:39 +00:00
}
}
}
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 ;
impianto = divisori . get ( " ICFAC " ) ;
if ( impianto = = " SE " | | impianto = = " TS " )
{
1999-07-16 14:59:11 +00:00
for ( int falsi_terzisti = 0 ; falsi_terzisti < 3 ; falsi_terzisti + + )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
item_code = ( divisori . get_codice ( " ICPROD " ) ) ;
item_code < < " __ " ;
switch ( falsi_terzisti )
{
case 1 :
item_code < < " PD " ; break ;
case 2 :
item_code < < " PR " ; break ;
default :
item_code < < impianto ; break ;
}
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 ) ;
}
1999-04-06 15:34:39 +00:00
}
}
divisori . next ( ) ;
}
return TRUE ;
}
2000-05-05 15:25:49 +00:00
void TImporta_BPCS : : confirm_docs ( const char * num , const TDate * fromdate , const TDate * todate )
{
change_docs_status ( num , fromdate , todate , 0 , 3 ) ;
change_docs_status ( num , fromdate , todate , 1 , 3 ) ;
change_docs_status ( num , fromdate , todate , 2 , 3 ) ;
}
void TImporta_BPCS : : unconfirm_docs ( const char * num , const TDate * fromdate , const TDate * todate )
{
change_docs_status ( num , fromdate , todate , 3 , 1 ) ;
}
void TImporta_BPCS : : change_docs_status ( const char * num , const TDate * fromdate , const TDate * todate , int fromstatus , int tostatus )
{
TString codnum ( num ) ;
TLocalisamfile doc ( LF_DOC ) ;
TDocumento doc_record ;
2001-05-02 13:40:49 +00:00
TIndwin info ( 80 , " Cambio stato documenti " , TRUE , FALSE ) ;
2000-05-05 15:25:49 +00:00
for ( int anno = 1998 ; anno < = 2000 ; anno + + )
{
doc . zero ( ) ;
doc . put ( DOC_PROVV , " D " ) ;
doc . put ( DOC_ANNO , anno ) ;
doc . put ( DOC_CODNUM , codnum ) ;
int err = doc . read ( _isgteq ) ;
while ( err = = NOERR & &
doc . get_int ( DOC_ANNO ) = = anno & &
( doc . get ( " CODNUM " ) = = codnum | | codnum . blank ( ) ) )
{
if ( info . iscancelled ( ) )
return ;
TDate docdate ( doc . get_date ( DOC_DATADOC ) ) ;
int docstatus ( doc . get_int ( DOC_STATO ) ) ;
if ( ! fromdate | | fromdate - > empty ( ) | | doc . get_date ( " DATADOC " ) > = * fromdate )
if ( ! todate | | todate - > empty ( ) | | doc . get_date ( " DATADOC " ) < = * todate )
if ( docstatus = = fromstatus )
{
2001-05-02 13:40:49 +00:00
info . set_text ( format ( " Cambio stato %s n. %ld " , num , doc . get_long ( DOC_NDOC ) ) ) ;
2000-05-05 15:25:49 +00:00
doc_record = doc . curr ( ) ;
doc_record . read ( _isequal , _lock ) ;
doc_record . put ( DOC_STATO , tostatus ) ;
doc_record . rewrite ( ) ;
}
err = doc . next ( ) ;
}
}
}
2001-05-02 13:40:49 +00:00
void TImporta_BPCS : : clear_docs ( long firm , const char * num , const TDate * fromdate , const TDate * todate , const long fromnum , const long tonum )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
TConfig * trans = NULL ;
long ntransac = 0 ;
2000-05-05 15:25:49 +00:00
int nblock = 1 ;
1999-07-16 14:59:11 +00:00
// rimuove le transazioni
delete_files ( " ND_*.ini " ) ;
1999-04-06 15:34:39 +00:00
TString codnum ( num ) ;
TLocalisamfile doc ( LF_DOC ) ;
TLocalisamfile rdoc ( LF_RIGHEDOC ) ;
2001-05-02 13:40:49 +00:00
for ( int anno = 1998 ; anno < = 2002 ; anno + + )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
TDate docdate ( doc . get_date ( " DATADOC " ) ) ;
doc . put ( DOC_PROVV , " D " ) ;
doc . put ( DOC_ANNO , anno ) ;
doc . put ( DOC_CODNUM , codnum ) ;
1999-04-06 15:34:39 +00:00
doc . read ( _isgteq ) ;
while ( ! doc . eof ( ) & & doc . get ( " CODNUM " ) = = codnum )
{
2000-05-05 15:25:49 +00:00
while ( ! doc . eof ( ) & & doc . get ( " CODNUM " ) = = codnum )
1999-07-16 14:59:11 +00:00
{
2000-05-05 15:25:49 +00:00
if ( ! fromdate | | fromdate - > empty ( ) | | doc . get_date ( " DATADOC " ) > = * fromdate )
if ( ! todate | | todate - > empty ( ) | | doc . get_date ( " DATADOC " ) < = * todate )
2001-05-02 13:40:49 +00:00
if ( fromnum < = 0 | | doc . get_long ( DOC_NDOC ) > = fromnum )
if ( tonum < = 0 | | doc . get_long ( DOC_NDOC ) < = tonum )
2000-05-05 15:25:49 +00:00
{
ntransac + + ;
if ( ntransac = = nblock * 100 )
{
break ;
}
if ( trans ) delete trans ;
trans = new TConfig ( format ( " ND_%05d.ini " , ntransac ) ) ;
trans - > set_paragraph ( " Transaction " ) ;
trans - > set ( " Action " , " DELETE " ) ;
trans - > set ( " Mode " , " AUTO " ) ;
trans - > set ( " Firm " , firm ) ;
trans - > set_paragraph ( format ( " %d " , LF_DOC ) ) ;
trans - > set ( DOC_PROVV , doc . get ( DOC_PROVV ) ) ;
trans - > set ( DOC_ANNO , doc . get ( DOC_ANNO ) ) ;
trans - > set ( DOC_CODNUM , doc . get ( DOC_CODNUM ) ) ;
trans - > set ( DOC_NDOC , doc . get ( DOC_NDOC ) ) ;
}
doc . read ( _isnext ) ;
}
if ( trans )
{
delete trans ;
trans = NULL ;
// genera i documenti
TString cmd ( " ve0.exe -1 -i " ) ;
cmd < < format ( " ND_%03d*.INI " , nblock - 1 ) ;
TExternal_app gestdoc ( ( const char * ) cmd ) ;
gestdoc . run ( ) ;
nblock + + ;
1999-07-16 14:59:11 +00:00
}
1999-04-06 15:34:39 +00:00
}
}
}
2001-05-02 13:40:49 +00:00
2000-05-05 15:25:49 +00:00
bool TImporta_BPCS : : creadocs ( const char * msg ,
1999-04-06 15:34:39 +00:00
long firm , // ditta
TImport_file & imp_file ,
1999-07-16 14:59:11 +00:00
const char * FieldNumDoc , const char * FieldClifor , const char * FieldDataDoc ,
const char * FieldGroup1 , const char * FieldGroup2 , const char * FieldGroup3 ,
2001-05-02 13:40:49 +00:00
SET_DOC_FUN set_header , SET_BODYDOC_FUN set_body , FILTER_FUN filter ,
GROUPBRK_FUN grpfun , TIPOCF_FUN tipocf ,
2000-05-05 15:25:49 +00:00
bool do_ve0 )
1999-04-06 15:34:39 +00:00
{
TProgind info ( imp_file . items ( ) , msg , TRUE , TRUE ) ;
TConfig * trans = NULL ;
1999-07-16 14:59:11 +00:00
int nblock = 1 ;
1999-04-06 15:34:39 +00:00
long ntransac = 0 ;
int nrigadoc = 0 ;
2001-05-02 13:40:49 +00:00
long starting_ndoc = 0 ;
// autonumerazione a partire da ...
if ( FieldNumDoc & & * FieldNumDoc = = ' * ' & & * ( FieldNumDoc + 1 ) = = ' * ' )
{
starting_ndoc = atol ( FieldNumDoc + 2 ) ;
FieldNumDoc = NULL ;
}
1999-04-06 15:34:39 +00:00
// rimuove le transazioni
1999-07-16 14:59:11 +00:00
delete_files ( " ND_*.ini " ) ;
1999-04-06 15:34:39 +00:00
imp_file . first ( ) ;
1999-07-16 14:59:11 +00:00
while ( ! imp_file . eof ( ) )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
long last_ndoc = - 1L ;
TDate last_date ( " " ) ;
long last_clifor = - 1L ;
TString last_group1 = " " ;
TString last_group2 = " " ;
TString last_group3 = " " ;
while ( ! imp_file . eof ( ) )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
info . addstatus ( 1 ) ;
if ( info . iscancelled ( ) )
return FALSE ;
if ( filter ( imp_file ) )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
long new_ndoc = FieldNumDoc ? imp_file . get_long ( FieldNumDoc ) : last_ndoc ;
2001-05-02 13:40:49 +00:00
if ( new_ndoc < = 0 & & starting_ndoc )
new_ndoc = starting_ndoc + + ;
1999-07-16 14:59:11 +00:00
long new_clifor = FieldClifor ? imp_file . get_long ( FieldClifor ) : last_clifor ;
if ( new_clifor = = 0L & & FieldClifor )
new_clifor = 9999 ; // cliente generico
TDate new_date ( FieldDataDoc ? imp_file . get_long ( FieldDataDoc ) : 0L ) ;
TString new_group1 = FieldGroup1 ? imp_file . get ( FieldGroup1 ) : last_group1 ;
TString new_group2 = FieldGroup2 ? imp_file . get ( FieldGroup2 ) : last_group2 ;
TString new_group3 = FieldGroup3 ? imp_file . get ( FieldGroup3 ) : last_group3 ;
2001-05-02 13:40:49 +00:00
if ( nrigadoc > 99 | | ( grpfun & & grpfun ( imp_file ) ) | | ( last_ndoc ! = new_ndoc ) | | ( last_date ! = new_date ) | | ( last_clifor ! = new_clifor ) | |
( last_group1 ! = new_group1 ) | | ( last_group2 ! = new_group2 ) | | ( last_group3 ! = new_group3 ) )
1999-07-16 14:59:11 +00:00
{
if ( ntransac = = nblock * 100 )
{
break ;
}
// emetti il doc
// reset
if ( new_ndoc > 0L ) last_ndoc = new_ndoc ;
if ( new_clifor > 0L ) last_clifor = new_clifor ;
if ( ! new_group1 . blank ( ) ) last_group1 = new_group1 ;
if ( ! new_group2 . blank ( ) ) last_group2 = new_group2 ;
if ( ! new_group3 . blank ( ) ) last_group3 = new_group3 ;
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 ) ;
2000-05-05 15:25:49 +00:00
trans - > set ( DOC_TIPOCF , tipocf ( imp_file ) ) ;
1999-07-16 14:59:11 +00:00
if ( new_clifor > 0L )
2000-05-05 15:25:49 +00:00
{
2001-05-02 13:40:49 +00:00
if ( tipocf ( imp_file ) = = " F " )
new_clifor = trascode_for ( new_clifor ) ;
1999-07-16 14:59:11 +00:00
trans - > set ( DOC_CODCF , new_clifor ) ;
2000-05-05 15:25:49 +00:00
// gestione condizione di pagamento
TToken_string tmp ( tipocf ( imp_file ) ) ;
tmp . add ( new_clifor ) ;
tmp = cache ( ) . get ( LF_CLIFO , tmp ) . get ( " CODPAG " ) ;
trans - > set ( DOC_CODPAG , tmp ) ;
}
1999-07-16 14:59:11 +00:00
trans - > set ( DOC_PROVV , " D " ) ;
set_header ( imp_file , * trans ) ;
nrigadoc = 0 ;
2001-05-02 13:40:49 +00:00
last_ndoc = - 1L ;
ntransac + + ;
1999-07-16 14:59:11 +00:00
}
// righe
2000-05-05 15:25:49 +00:00
trans - > set_paragraph ( format ( " %d,%d " , LF_RIGHEDOC , nrigadoc + 1 ) ) ;
2001-05-02 13:40:49 +00:00
nrigadoc + = set_body ( imp_file , * trans , do_ve0 ) ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
imp_file . next ( ) ;
}
if ( trans )
{
delete trans ;
trans = NULL ;
// genera i documenti
2000-05-05 15:25:49 +00:00
if ( do_ve0 )
{
2001-05-02 13:40:49 +00:00
TExternal_app * _gestart = NULL ;
2000-05-05 15:25:49 +00:00
TString cmd ( " ve0.exe -1 -i " ) ;
cmd < < format ( " ND_%03d*.INI " , nblock - 1 ) ;
2001-05-02 13:40:49 +00:00
if ( _gestart = = NULL )
_gestart = new TExternal_app ( ( const char * ) cmd ) ;
while ( _gestart - > run ( ) ! = 0 & & yesno_box ( " Ritento l'esecuzione di ve0.exe ? " ) )
;
2000-05-05 15:25:49 +00:00
}
1999-07-16 14:59:11 +00:00
nblock + + ;
1999-04-06 15:34:39 +00:00
}
}
return TRUE ;
}
2000-05-05 15:25:49 +00:00
const char * tipocf_for ( TImport_file & import )
{ return " F " ; }
const char * tipocf_cli ( TImport_file & import )
{ return " C " ; }
const char * tipocf_null ( TImport_file & import )
{ return " " ; }
1999-04-06 15:34:39 +00:00
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 " ) ) ;
1999-07-16 14:59:11 +00:00
round_date ( dc , 28 , TRUE ) ;
1999-04-06 15:34:39 +00:00
trans . set ( DOC_DATACONS , dc ) ; // stessa data del doc
}
2001-05-02 13:40:49 +00:00
int set_body_F_ordcli ( TImport_file & import , TConfig & trans , const bool dotrans )
1999-04-06 15:34:39 +00:00
{
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 " ) ) ;
2001-05-02 13:40:49 +00:00
trans . set ( RDOC_QTA , import . get ( " FQTY " ) ) ;
1999-04-06 15:34:39 +00:00
// gia' suddivisa su doc : trans.set(RDOC_DATACONS, import.get_date("FDATE"));
tmp = import . get ( " FPFAC " ) ;
tmp < < 1 ;
trans . set ( RDOC_CODMAG , tmp ) ;
2000-05-05 15:25:49 +00:00
return 1 ;
1999-04-06 15:34:39 +00:00
}
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 " ) ) ;
1999-07-16 14:59:11 +00:00
round_date ( dc , 28 , TRUE ) ;
1999-04-06 15:34:39 +00:00
trans . set ( DOC_DATACONS , dc ) ; // stessa data del doc
}
2001-05-02 13:40:49 +00:00
int set_body_R_ordcli ( TImport_file & import , TConfig & trans , const bool dotrans )
1999-04-06 15:34:39 +00:00
{
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 " ) ) ;
2001-05-02 13:40:49 +00:00
trans . set ( RDOC_QTA , import . get ( " SQREQ " ) ) ;
trans . set ( RDOC_QTAEVASA , import . get ( " SQFIN " ) ) ;
1999-04-06 15:34:39 +00:00
tmp = import . get ( " SOFAC " ) ;
tmp < < 1 ;
trans . set ( RDOC_CODMAG , tmp ) ;
2000-05-05 15:25:49 +00:00
return 1 ;
1999-04-06 15:34:39 +00:00
}
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 ;
}
2001-05-02 13:40:49 +00:00
// ordini di produzione firm planned
1999-04-06 15:34:39 +00:00
void set_head_F_ordprod ( TImport_file & import , TConfig & trans )
{
trans . set ( DOC_ANNO , import . get_date ( " FRDTE " ) . year ( ) ) ;
1999-07-16 14:59:11 +00:00
trans . set ( DOC_CODNUM , ( import . get ( " FPFAC " ) = = " SE " ) ? " MSP " : " TSMP " ) ;
1999-04-06 15:34:39 +00:00
trans . set ( " TIPODOC " , " ORP " ) ;
1999-07-16 14:59:11 +00:00
TDate today ( TODAY ) , dc ( import . get_date ( " FRDTE " ) ) ;
TDate rdt ( import . get_date ( " FRSDT " ) ) ;
if ( rdt . ok ( ) & & rdt ! = 99999999L & & rdt > dc )
dc = rdt ;
if ( dc < today )
2001-05-02 13:40:49 +00:00
if ( 0 | | yesno_box ( " Data ordine di produzione per l'articolo %s inferiore a quella attuale: posticipo a oggi? " , ( const char * ) import . get ( " FPROD " ) ) )
1999-07-16 14:59:11 +00:00
dc = today ;
2001-05-02 13:40:49 +00:00
//round_date(dc,28,TRUE);
1999-04-06 15:34:39 +00:00
TDate dd ( trans . get ( DOC_DATADOC ) ) ;
if ( dc < dd )
trans . set ( DOC_DATADOC , dc ) ;
trans . set ( DOC_DATACONS , dc ) ;
}
2001-05-02 13:40:49 +00:00
int set_body_F_ordprod ( TImport_file & import , TConfig & trans , const bool dotrans )
1999-04-06 15:34:39 +00:00
{
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 ) ;
2001-05-02 13:40:49 +00:00
trans . set ( RDOC_QTA , import . get ( " FQTY " ) ) ;
1999-04-06 15:34:39 +00:00
trans . set ( RDOC_QTAEVASA , " 0 " ) ;
2000-05-05 15:25:49 +00:00
return 1 ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
bool filterFordprodSE ( TImport_file & import )
1999-04-06 15:34:39 +00:00
{
bool ok = import . get ( " FID " ) = = " FP " & & import . get ( " FPFAC " ) = = " SE " & & import . get ( " FTYPE " ) = = " F " ;
if ( ok )
{
1999-07-16 14:59:11 +00:00
const TRectype & art = cache ( ) . get ( LF_ANAMAG , import . get_codice ( " FPROD " ) ) ;
char type = art . get ( ANAMAG_GRMERC ) [ 0 ] ;
if ( art . empty ( ) )
{
if ( yesno_box ( " Articolo non trovato:%s. Lo considero ugualmente come prodotto finito? " , ( const char * ) import . get_codice ( " FPROD " ) ) )
type = ' F ' ;
}
1999-04-06 15:34:39 +00:00
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 ( ) ) ;
1999-07-16 14:59:11 +00:00
trans . set ( " CODNUM " , ( import . get ( " SOFAC " ) = = " SE " ) ? " MSP " : " TSMP " ) ;
1999-04-06 15:34:39 +00:00
trans . set ( " TIPODOC " , " ORP " ) ;
2001-05-02 13:40:49 +00:00
TDate today ( TODAY ) ,
dc ( import . get_date ( " SDDTE " ) ) ; // due date : data di consegna
TDate rdt ( import . get_date ( " SRSDT " ) ) ; // reschedule date
1999-07-16 14:59:11 +00:00
if ( rdt . ok ( ) & & rdt ! = 99999999L & & rdt > dc )
dc = rdt ;
if ( dc < today )
2001-05-02 13:40:49 +00:00
if ( 0 | | yesno_box ( " Data ordine di produzione %ld per l'articolo %s inferiore a quella attuale: posticipo a oggi? " , import . get_long ( " SORD " ) , ( const char * ) import . get ( " SPROD " ) ) )
1999-07-16 14:59:11 +00:00
dc = today ;
2001-05-02 13:40:49 +00:00
//round_date(dc,28,TRUE);
TDate dd ( trans . get ( DOC_DATADOC ) ) ; // data documento
1999-04-06 15:34:39 +00:00
if ( dc < dd )
trans . set ( DOC_DATADOC , dc ) ;
trans . set ( DOC_DATACONS , dc ) ;
}
2001-05-02 13:40:49 +00:00
int set_body_R_ordprod ( TImport_file & import , TConfig & trans , const bool dotrans )
1999-04-06 15:34:39 +00:00
{
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 ) ;
1999-07-16 14:59:11 +00:00
tmp = import . get ( " SOFAC " ) ;
set_workcenter_code ( tmp2 , tmp , import . get_long ( " SWRKC " ) , int ( import . get_long ( " SOBOMM " ) ) ) ;
trans . set ( RDOC_LINEA , tmp2 ) ;
if ( tmp2 . left ( 3 ) = = " X07 " ) // ex terzista cover
{
if ( tmp2 . right ( 2 ) = = " SE " )
tmp = " PR " ;
else
tmp = " PD " ;
trans . set ( RDOC_IMPIANTO , tmp ) ;
tmp < < " 01M " ;
trans . set ( RDOC_LINEA , tmp ) ;
}
real totale = import . get_real ( " SQREQ " ) ;
real evasa = import . get_real ( " SQFIN " ) ;
2001-05-02 13:40:49 +00:00
trans . set ( RDOC_QTA , totale . string ( ) ) ;
trans . set ( RDOC_QTAEVASA , evasa . string ( ) ) ;
1999-04-06 15:34:39 +00:00
add_stdlabors ( import . get_codice ( " SPROD " ) , import . get_long ( " SWRKC " ) , int ( import . get_long ( " SOBOMM " ) ) ) ;
2000-05-05 15:25:49 +00:00
return 1 ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
bool filterRordprodSE ( TImport_file & import )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
bool ok = ( import . get ( " SID " ) = = " SO "
& & import . get ( " SOFAC " ) = = " SE " ) ;
1999-04-06 15:34:39 +00:00
if ( ok )
{
1999-07-16 14:59:11 +00:00
real totale = import . get_real ( " SQREQ " ) ;
totale - = import . get_real ( " SQFIN " ) ;
ok = ( totale > ZERO ) ;
if ( ok )
{
char type = cache ( ) . get ( LF_ANAMAG , import . get_codice ( " SPROD " ) ) . get ( ANAMAG_GRMERC ) [ 0 ] ;
ok = ( type = = ' F ' | | type = = ' S ' ) ;
}
1999-04-06 15:34:39 +00:00
}
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 " ) ;
2000-05-05 15:25:49 +00:00
// gestione doc. in valuta
TString codval = converti_codval ( import . get ( " POCUR " ) ) ;
if ( ! codval . empty ( ) )
{
real cambio = import . get_real ( " PEXRT " ) ;
cambio_fisso ( codval , cambio ) ;
2001-05-02 13:40:49 +00:00
trans . set ( DOC_CAMBIO , cambio . string ( ) ) ;
2000-05-05 15:25:49 +00:00
trans . set ( DOC_CODVAL , codval ) ;
}
1999-04-06 15:34:39 +00:00
}
2001-05-02 13:40:49 +00:00
int set_body_ordacq ( TImport_file & import , TConfig & trans , const bool dotrans )
1999-04-06 15:34:39 +00:00
{
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 ) ;
2000-05-05 15:25:49 +00:00
1999-04-06 15:34:39 +00:00
tmp < < " 1 " ;
trans . set ( RDOC_CODMAG , tmp ) ;
trans . set ( RDOC_QTA , import . get ( " PQORD " ) ) ;
trans . set ( RDOC_QTAEVASA , import . get ( " PQREC " ) ) ;
2000-05-05 15:25:49 +00:00
// gestione codice IVA
tmp = " F " ;
2001-05-02 13:40:49 +00:00
tmp . add ( import . get ( " PVEND " ) ) ;
2000-05-05 15:25:49 +00:00
TString8 codiva ( cache ( ) . get ( LF_CFVEN , tmp ) . get ( " ASSFIS " ) ) ;
if ( codiva . blank ( ) )
codiva = cache ( ) . get ( LF_ANAMAG , tmp ) . get ( ANAMAG_CODIVA ) ;
if ( codiva . blank ( ) )
codiva = " 20 " ;
trans . set ( RDOC_CODIVA , codiva ) ;
return 1 ;
1999-04-06 15:34:39 +00:00
}
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 ;
}
2000-05-05 15:25:49 +00:00
void set_head_bolacq ( TImport_file & import , TConfig & trans )
{
long codcli = atol ( import . get ( " TVEND " ) ) ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
char cod0 = * ( ( const char * ) import . get ( " TTYPE " ) ) ;
char cod1 = * ( ( const char * ) import . get ( " TTYPE " ) + 1 ) ;
TString codimp ;
num_mag2main_imp ( magno , codimp ) ;
TString codnum , tipodoc , causmag , descrmov ;
codnum = codimp ;
long numdoc = 0L ;
switch ( cod0 )
{
case ' 0 ' : // completed;
if ( codcli = = 1700 )
{
if ( import . get ( " TCOM " ) . find ( " PD " ) > = 0 )
codcli = 10002 ;
else
codcli = 10003 ;
if ( magno = = 25 | | magno = = 27 )
{
if ( codcli = = 10002 )
codnum = " PDBV " ;
else
codnum = " PRBV " ;
tipodoc = " BVEN " ;
descrmov = " Vendita con consegna da parte di stabilimenti Cover " ;
}
else
{
codnum < < " BE " ;
causmag = " ENT " ;
tipodoc = " BENT " ;
descrmov = " Carico prodotti finiti da stabilimenti Cover (Ex terzista 1700) " ;
}
} else {
descrmov = " Carico prodotti finiti da terzi " ;
numdoc = import . get_long ( " THRNO " ) ; // riassegno qui il numdoc , per usare il nummag al suo posto come ragguppatore nel ciclo di crea_docs
if ( magno = = 25 | | magno = = 27 )
{
numdoc = 0L ;
codnum < < " P3 " ;
causmag = " CFAL " ;
tipodoc = " BPV3 " ;
} else {
codnum < < " BA " ;
causmag = " CFAL " ;
tipodoc = " BPR3 " ;
}
}
break ;
case ' C ' : // completed;
CHECKS ( cod1 = = ' 3 ' , " Causale sconosciuta :%s " , cod0 ) ;
descrmov = " Scarico componenti per produzione terzista " ;
codnum < < " MM " ;
tipodoc = " __C3 " ;
trans . set ( DOC_TIPOCF , " F " ) ;
if ( codcli = = 1700 )
{
if ( import . get ( " TCOM " ) . find ( " PD " ) > = 0 )
codcli = 10002 ;
else
codcli = 10003 ;
descrmov = " Scarico componenti per produzione stabilimenti Cover PD/PR " ;
}
break ;
case ' U ' :
switch ( cod1 )
{
case ' \0 ' : // completed;
{
numdoc = import . get_long ( " THRNO " ) ; // riassegno qui il numdoc , per usare il nummag al suo posto come ragguppatore nel ciclo di crea_docs
codnum < < " BA " ;
if ( numdoc & & import . get_real ( " TQTY " ) < ZERO )
{
TLocalisamfile doc ( LF_DOC ) ;
doc . put ( DOC_PROVV , " D " ) ;
doc . put ( DOC_ANNO , import . get_date ( " TTDTE " ) . year ( ) ) ;
doc . put ( DOC_CODNUM , codnum ) ;
doc . put ( DOC_NDOC , numdoc ) ;
if ( doc . read ( ) = = NOERR )
numdoc = 0L ;
}
if ( numdoc = = 0L & & import . get_real ( " TQTY " ) < ZERO )
{
descrmov = " Storno Acquisto merce per errata registrazione " ;
causmag = " ACQL " ; // acquisto ordine
codnum . overwrite ( " MM " , 2 ) ;
tipodoc = " BACQ " ;
} else {
descrmov = " Acquisto merce " ;
causmag = " ACQL " ; // acquisto ordine
tipodoc = " BACQ " ;
if ( numdoc = = 0L )
error_box ( " Bolla di entrata senza numero " ) ;
trans . set ( " Mode " , " " ) ;
}
break ;
}
case ' 1 ' : // completed;
case ' 3 ' : // completed;
{
descrmov = " Reso su acquisto in attesa rimpiazzo merce " ;
causmag = " REAL " ; // reso su acquisto ordine
codnum < < " RF " ;
tipodoc = " BRF1 " ;
break ;
}
case ' 2 ' : // completed;
case ' 4 ' : // completed;
{
descrmov = " Reso su acquisto in attesa Nota Accredito " ;
causmag = " REAL " ; // reso su acquisto ordine
codnum < < " RF " ;
tipodoc = " BRF2 " ;
break ;
}
default :
error_box ( " Cazzo di reso e' R%c ? " , cod1 ) ;
}
break ;
}
descrmov < < ' ( ' < < import . get ( " TCOM " ) < < ' ) ' ;
trans . set ( DOC_CODNUM , codnum ) ;
if ( ! tipodoc . blank ( ) )
trans . set ( DOC_TIPODOC , tipodoc ) ;
if ( ! causmag . blank ( ) )
trans . set ( DOC_CAUSMAG , causmag ) ;
trans . set ( DOC_NOTE , descrmov ) ;
trans . set ( DOC_NDOC , numdoc ) ;
2001-05-02 13:40:49 +00:00
codcli = trascode_for ( codcli ) ;
2000-05-05 15:25:49 +00:00
trans . set ( DOC_CODCF , codcli = = 0L ? " " : format ( " %ld " , codcli ) ) ;
trans . set ( DOC_ANNO , import . get_date ( " TTDTE " ) . year ( ) ) ;
// riferimenti
2001-05-02 13:40:49 +00:00
trans . set ( DOC_DOC1 , import . get ( " TREF " ) ) ;
trans . set ( DOC_NUMDOCRIF , external_refnum ( import ) ) ;
trans . set ( DOC_DATADOCRIF , external_refdate ( import ) ) ;
2000-05-05 15:25:49 +00:00
TString codval = converti_codval ( import . get ( " THCURR " ) ) ;
if ( ! codval . empty ( ) )
{
real cambio = import . get_real ( " THTEXR " ) ;
cambio_fisso ( codval , cambio ) ;
2001-05-02 13:40:49 +00:00
trans . set ( DOC_CAMBIO , cambio . string ( ) ) ;
2000-05-05 15:25:49 +00:00
trans . set ( DOC_CODVAL , codval ) ;
}
}
2001-05-02 13:40:49 +00:00
bool set_group_movmag ( TImport_file & import )
{
static TString _prev ;
TString newstr = external_refnum ( import ) ;
if ( _prev ! = newstr )
{
_prev = newstr ;
return TRUE ;
}
return FALSE ;
}
int set_body_bolacq ( TImport_file & import , TConfig & trans , const bool dotrans )
2000-05-05 15:25:49 +00:00
{
int extrarow = 0 ;
static long _last_ord = - 1 ;
int nrigadoc = atoi ( trans . get_paragraph ( ) . sub ( 3 ) ) ;
if ( _last_ord ! = import . get_long ( " TREF " ) | | nrigadoc = = 1 )
{
_last_ord = import . get_long ( " TREF " ) ;
if ( _last_ord )
{
if ( nrigadoc ! = 1 )
{
trans . set ( RDOC_TIPORIGA , " 05 " ) ; // descrizione
trans . set ( RDOC_DESCR , format ( " Ordine n.%ld " , _last_ord ) ) ;
trans . set_paragraph ( format ( " %d,%d " , LF_RIGHEDOC , + + extrarow + nrigadoc ) ) ;
}
}
}
TString codimp , codmag , causmag , desc ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
num_mag2main_imp ( magno , codimp ) ;
imploc2codmagdep ( codimp , import . get ( " TLOCT " ) , codmag ) ;
int terzista = location2method ( import . get_long ( " TLOCT " ) ) ;
if ( terzista = = 7 )
{
if ( import . get ( " TCOM " ) . find ( " PD " ) > = 0 )
codmag = " PD1PF " ;
else if ( import . get ( " TCOM " ) . find ( " PR " ) > = 0 )
codmag = " PR1PF " ;
}
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 ( desc . blank ( ) )
{
cache ( ) . discard ( LF_ANAMAG , tmp ) ;
inserisci_articolo ( tmp , import . get ( " THTUM " ) ) ;
desc = cache ( ) . get ( LF_ANAMAG , tmp ) . get ( " DESCR " ) ;
}
if ( terzista = = 99 )
{
message_box ( " Terzista sconosciuto : %ld " , import . get_long ( " TLOCT " ) ) ;
desc < < " (terzista " < < atol ( import . get ( " TLOCT " ) ) < < " ) " ;
}
trans . set ( RDOC_DESCR , desc ) ;
// gestione codice IVA
TToken_string keyfor = " F " ;
keyfor . add ( import . get ( " TVEND " ) ) ;
TString8 codiva ( cache ( ) . get ( LF_CFVEN , keyfor ) . get ( " ASSFIS " ) ) ;
if ( codiva . blank ( ) )
codiva = cache ( ) . get ( LF_ANAMAG , tmp ) . get ( ANAMAG_CODIVA ) ;
if ( codiva . blank ( ) )
codiva = " 20 " ;
trans . set ( RDOC_CODIVA , codiva ) ;
// gestione UM
TString4 umqta ( import . get ( " THTUM " ) ) ;
if ( umqta . blank ( ) )
{
tmp . add ( " 1 " ) ;
umqta = cache ( ) . get ( LF_UMART , tmp ) . get ( " UM " ) ;
}
trans . set ( RDOC_UMQTA , umqta ) ;
if ( codmag . find ( " PF " ) = = 0 )
codmag = format ( " %s%s " , ( const char * ) codimp , ( const char * ) codmag ) ;
trans . set ( RDOC_CODMAG , codmag ) ;
real qta ( import . get_real ( " TQTY " ) ) ;
const char cod0 = * ( const char * ) import . get ( " TTYPE " ) ;
const char cod1 = * ( ( const char * ) import . get ( " TTYPE " ) + 1 ) ;
switch ( cod0 )
{
case ' C ' :
qta = - qta ;
break ;
case ' U ' :
if ( cod1 = = ' \0 ' )
{
// causale di acquisto o storno da acq; lascio il segno cosi' com'e'
}
else
{
// causale di reso: il segno va invertito
qta = - qta ;
}
break ;
case ' 0 ' :
break ;
}
trans . set ( RDOC_CAUSMAG , causmag ) ;
trans . set ( RDOC_QTA , qta . string ( ) ) ;
2001-05-02 13:40:49 +00:00
trans . set ( RDOC_QTAEVASA , " 0 " ) ;
2000-05-05 15:25:49 +00:00
real price = import . get_real ( " TPRIC " ) ;
if ( price . is_zero ( ) )
{
if ( ! qta . is_zero ( ) & & converti_codval ( import . get ( " THCURR " ) ) . blank ( ) )
{
price = import . get_real ( " TVAL " ) ;
price = price / import . get_real ( " TQTY " ) ;
if ( price . is_zero ( ) )
price = import . get_real ( " THACST " ) ;
if ( price . is_zero ( ) )
price = import . get_real ( " TSCST " ) ;
}
}
trans . set ( RDOC_PREZZO , price . string ( ) ) ;
2001-05-02 13:40:49 +00:00
if ( _ithcheck & & dotrans )
2000-05-05 15:25:49 +00:00
{
_ithcheck - > put ( " TPROD " , import . get ( " TPROD " ) ) ;
_ithcheck - > put ( " TSEQ " , import . get ( " TSEQ " ) ) ;
_ithcheck - > write ( ) ;
}
return extrarow + 1 ;
}
const char * tipocf_movmag ( TImport_file & import )
{
char cod0 = * ( ( const char * ) import . get ( " TTYPE " ) ) ;
char cod1 = * ( ( const char * ) import . get ( " TTYPE " ) + 1 ) ;
switch ( cod0 )
{
case ' 0 ' : // completed;
case ' C ' : // completed;
case ' U ' :
return " F " ;
}
return " " ;
}
1999-04-06 15:34:39 +00:00
void set_head_movmag ( TImport_file & import , TConfig & trans )
{
long codcli = atol ( import . get ( " TVEND " ) ) ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
1999-07-16 14:59:11 +00:00
char cod0 = * ( ( const char * ) import . get ( " TTYPE " ) ) ;
char cod1 = * ( ( const char * ) import . get ( " TTYPE " ) + 1 ) ;
if ( magno = = 25 | | magno = = 27 )
{
cod1 = cod0 ;
cod0 = ' V ' ; // codice fittizio per simulare la vendita
import . put ( " TTYPE " , " V " ) ;
if ( magno = = 25 )
magno = 26 ;
else
magno = 28 ;
}
2001-05-02 13:40:49 +00:00
if ( ( import . get ( " TLOCT " ) = = " CICCA " )
| | ( import . get ( " TLOCT " ) = = " CMINT " ) )
2000-05-05 15:25:49 +00:00
{
import . put ( " TTYPE " , " _L " ) ; //conto lavoro
cod0 = ' _ ' ; // codice fittizio per simulare IL CONTO LAVORO
cod1 = ' L ' ;
}
1999-04-06 15:34:39 +00:00
TString codimp ;
num_mag2main_imp ( magno , codimp ) ;
TString codnum , tipodoc , causmag , descrmov ;
codnum = codimp ;
long numdoc = 0L ; // riassegno qui il numdoc , per usare il nummag al suo posto come ragguppatore nel ciclo di crea_docs
1999-07-16 14:59:11 +00:00
switch ( cod0 )
1999-04-06 15:34:39 +00:00
{
case ' O ' : // completed;
descrmov = " Movimento di apertura di inizio esercizio " ;
codnum < < " DI " ;
causmag = " RIMI " ;
1999-07-16 14:59:11 +00:00
tipodoc = " __O " ;
1999-04-06 15:34:39 +00:00
codcli = 0L ;
break ;
case ' A ' : // completed
descrmov = " Differenza inventariale " ;
codnum < < " DI " ;
1999-07-16 14:59:11 +00:00
tipodoc = " __A " ;
2000-05-05 15:25:49 +00:00
causmag = " CAR " ;
1999-04-06 15:34:39 +00:00
codcli = 0L ;
break ;
case ' M ' :
if ( cod1 = = ' \0 ' ) // completed;
{
1999-07-16 14:59:11 +00:00
descrmov = " Consuntivazione produzione " ;
codnum < < " BP " ;
tipodoc = " BPR " ;
2000-05-05 15:25:49 +00:00
causmag = " CFPRP " ;
1999-04-06 15:34:39 +00:00
} else {
1999-07-16 14:59:11 +00:00
descrmov = " Produzione semilavorati per sconfezionamento " ;
codnum < < " BP " ;
tipodoc = " BPR1 " ;
2000-05-05 15:25:49 +00:00
causmag = " SFSC " ;
1999-04-06 15:34:39 +00:00
}
codcli = 0L ;
break ;
case ' I ' : // confirmed
descrmov = " Scarico componenti " ;
codnum < < " MM " ;
1999-07-16 14:59:11 +00:00
tipodoc = " __I " ;
1999-04-06 15:34:39 +00:00
break ;
case ' T ' : // to be confirmed
codnum < < " MM " ;
1999-07-16 14:59:11 +00:00
descrmov = " Trasferimento merce " ;
1999-04-06 15:34:39 +00:00
codcli = 0L ;
1999-07-16 14:59:11 +00:00
tipodoc = " __T " ;
1999-04-06 15:34:39 +00:00
break ;
case ' X ' : // completed;
codnum < < " MM " ;
if ( cod1 = = ' 7 ' )
{
descrmov = " Scarico manuale " ;
} else if ( cod1 = = ' 8 ' )
{
descrmov = " Carico manuale " ;
} else {
descrmov = " Scarico per campionatura " ;
}
codcli = 0L ;
break ;
1999-07-16 14:59:11 +00:00
case ' V ' : // completed;
descrmov = " Vendita da BPCS (simulata con scarico magazzini 25-27) " ;
codnum < < " MM " ;
if ( cod1 = = ' T ' )
causmag = " VNUSC " ; // vendo stornando una uscita
else
causmag = " VNENT " ; // vendo contemporaneamente ad una entrata
break ;
case ' R ' : // completed;
if ( cod1 = = ' D ' )
{
codnum < < " MM " ;
descrmov = " Cambio codice " ;
codcli = 0L ;
tipodoc = " __RD " ;
}
break ;
2000-05-05 15:25:49 +00:00
case ' _ ' : // completed;
if ( cod1 = = ' L ' )
{
descrmov = " Carico componenti in conto lavoro " ;
codnum < < " BE " ;
tipodoc = " BECL " ;
trans . set ( DOC_TIPOCF , " C " ) ;
causmag = " CCIL " ;
}
break ;
1999-04-06 15:34:39 +00:00
}
1999-07-16 14:59:11 +00:00
descrmov < < ' ( ' < < import . get ( " TCOM " ) < < ' ) ' ;
trans . set ( DOC_CODNUM , codnum ) ;
1999-04-06 15:34:39 +00:00
if ( ! tipodoc . blank ( ) )
1999-07-16 14:59:11 +00:00
trans . set ( DOC_TIPODOC , tipodoc ) ;
1999-04-06 15:34:39 +00:00
if ( ! causmag . blank ( ) )
1999-07-16 14:59:11 +00:00
trans . set ( DOC_CAUSMAG , causmag ) ;
trans . set ( DOC_NOTE , descrmov ) ;
1999-04-06 15:34:39 +00:00
trans . set ( DOC_NDOC , 0L ) ;
2001-05-02 13:40:49 +00:00
if ( trans . get ( DOC_TIPOCF ) = = " F " )
codcli = trascode_for ( codcli ) ;
1999-07-16 14:59:11 +00:00
trans . set ( DOC_CODCF , codcli = = 0L ? " " : format ( " %ld " , codcli ) ) ;
1999-04-06 15:34:39 +00:00
trans . set ( DOC_ANNO , import . get_date ( " TTDTE " ) . year ( ) ) ;
2000-05-05 15:25:49 +00:00
// riferimenti
2001-05-02 13:40:49 +00:00
trans . set ( DOC_DOC1 , import . get ( " TREF " ) ) ;
// trans.set(DOC_NUMDOCRIF,external_refnum(import));
// trans.set(DOC_DATADOCRIF,external_refdate(import));
2000-05-05 15:25:49 +00:00
TString codval = converti_codval ( import . get ( " THCURR " ) ) ;
if ( ! codval . empty ( ) )
{
real cambio = import . get_real ( " THTEXR " ) ;
cambio_fisso ( codval , cambio ) ;
2001-05-02 13:40:49 +00:00
trans . set ( DOC_CAMBIO , cambio . string ( ) ) ;
2000-05-05 15:25:49 +00:00
trans . set ( DOC_CODVAL , codval ) ;
}
1999-04-06 15:34:39 +00:00
}
2001-05-02 13:40:49 +00:00
int set_body_movmag ( TImport_file & import , TConfig & trans , const bool dotrans )
1999-04-06 15:34:39 +00:00
{
2000-05-05 15:25:49 +00:00
int extrarow = 0 ;
static long _last_ord = - 1 ;
int nrigadoc = atoi ( trans . get_paragraph ( ) . sub ( 3 ) ) ;
if ( _last_ord ! = import . get_long ( " TREF " ) | | nrigadoc = = 1 )
{
_last_ord = import . get_long ( " TREF " ) ;
if ( _last_ord )
{
if ( nrigadoc = = 1 )
{
trans . set ( RDOC_TIPORIGA , " 01 " ) ; // descrizione
trans . set_paragraph ( format ( " %d,%d " , LF_RIGHEDOC , + + extrarow + nrigadoc ) ) ;
}
trans . set ( RDOC_TIPORIGA , " 05 " ) ; // descrizione
trans . set ( RDOC_DESCR , format ( " Ordine n.%ld " , _last_ord ) ) ;
trans . set_paragraph ( format ( " %d,%d " , LF_RIGHEDOC , + + extrarow + nrigadoc ) ) ;
}
}
1999-04-06 15:34:39 +00:00
TString codimp , codmag , causmag , desc ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
num_mag2main_imp ( magno , codimp ) ;
2000-05-05 15:25:49 +00:00
imploc2codmagdep ( codimp , import . get ( " TLOCT " ) , codmag ) ;
int terzista = location2method ( import . get_long ( " TLOCT " ) ) ;
if ( terzista = = 7 )
{
2001-05-02 13:40:49 +00:00
if ( codimp = = " PD " | | ( import . get ( " TCOM " ) . find ( " PD " ) > = 0 ) )
2000-05-05 15:25:49 +00:00
codmag = " PD1PF " ;
2001-05-02 13:40:49 +00:00
else if ( codimp = = " PR " | | ( import . get ( " TCOM " ) . find ( " PR " ) > = 0 ) )
2000-05-05 15:25:49 +00:00
codmag = " PR1PF " ;
}
1999-04-06 15:34:39 +00:00
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 " ) ;
2000-05-05 15:25:49 +00:00
if ( desc . blank ( ) )
{
cache ( ) . discard ( LF_ANAMAG , tmp ) ;
inserisci_articolo ( tmp , import . get ( " THTUM " ) ) ;
desc = cache ( ) . get ( LF_ANAMAG , tmp ) . get ( " DESCR " ) ;
}
1999-04-06 15:34:39 +00:00
if ( terzista = = 99 )
1999-07-16 14:59:11 +00:00
{
message_box ( " Terzista sconosciuto : %ld " , import . get_long ( " TLOCT " ) ) ;
1999-04-06 15:34:39 +00:00
desc < < " (terzista " < < atol ( import . get ( " TLOCT " ) ) < < " ) " ;
1999-07-16 14:59:11 +00:00
}
1999-04-06 15:34:39 +00:00
trans . set ( RDOC_DESCR , desc ) ;
1999-07-16 14:59:11 +00:00
TString4 umqta ( import . get ( " THTUM " ) ) ;
if ( umqta . blank ( ) )
{
tmp . add ( " 1 " ) ;
umqta = cache ( ) . get ( LF_UMART , tmp ) . get ( " UM " ) ;
}
trans . set ( RDOC_UMQTA , umqta ) ;
1999-04-06 15:34:39 +00:00
trans . set ( RDOC_CODMAG , codmag ) ;
1999-07-16 14:59:11 +00:00
real qta ( import . get_real ( " TQTY " ) ) ;
const char cod0 = * ( const char * ) import . get ( " TTYPE " ) ;
switch ( cod0 )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
case ' T ' :
1999-04-06 15:34:39 +00:00
case ' M ' :
case ' A ' :
1999-07-16 14:59:11 +00:00
case ' I ' :
case ' X ' :
case ' R ' :
1999-04-06 15:34:39 +00:00
if ( qta > = ZERO )
causmag = " CAR " ;
2000-05-05 15:25:49 +00:00
else
1999-04-06 15:34:39 +00:00
causmag = " SCAR " ;
case ' O ' :
1999-07-16 14:59:11 +00:00
case ' V ' :
2000-05-05 15:25:49 +00:00
case ' _ ' :
1999-04-06 15:34:39 +00:00
break ;
}
1999-07-16 14:59:11 +00:00
trans . set ( RDOC_CAUSMAG , causmag ) ;
1999-04-06 15:34:39 +00:00
trans . set ( RDOC_QTA , qta . string ( ) ) ;
2000-05-05 15:25:49 +00:00
real price = import . get_real ( " TPRIC " ) ;
if ( price . is_zero ( ) )
{
if ( ! qta . is_zero ( ) & & converti_codval ( import . get ( " THCURR " ) ) . blank ( ) )
{
price = import . get_real ( " TVAL " ) ;
price = price / import . get_real ( " TQTY " ) ;
if ( price . is_zero ( ) )
price = import . get_real ( " THACST " ) ;
if ( price . is_zero ( ) )
price = import . get_real ( " TSCST " ) ;
}
}
trans . set ( RDOC_PREZZO , price . string ( ) ) ;
// gestione codice IVA
tmp = tipocf_movmag ( import ) ;
tmp . add ( import . get ( " TVEND " ) ) ;
TString8 codiva ( cache ( ) . get ( LF_CFVEN , tmp ) . get ( " ASSFIS " ) ) ;
if ( codiva . blank ( ) )
codiva = cache ( ) . get ( LF_ANAMAG , tmp ) . get ( ANAMAG_CODIVA ) ;
if ( codiva . blank ( ) )
codiva = " 20 " ;
trans . set ( RDOC_CODIVA , codiva ) ;
2001-05-02 13:40:49 +00:00
if ( _ithcheck & & dotrans )
2000-05-05 15:25:49 +00:00
{
_ithcheck - > put ( " TPROD " , import . get ( " TPROD " ) ) ;
_ithcheck - > put ( " TSEQ " , import . get ( " TSEQ " ) ) ;
_ithcheck - > write ( ) ;
}
return extrarow + 1 ;
}
bool filter_bolacq ( TImport_file & import )
{
if ( ! _ithcheck & & _check )
{
TFilename chkname ( import . name ( ) ) ;
chkname = chkname . path ( ) ;
chkname . add ( " ithchk " ) ;
2001-05-02 13:40:49 +00:00
chkname . ext ( " dbf " ) ;
if ( ! chkname . exist ( ) )
2000-05-05 15:25:49 +00:00
_check = FALSE ;
else
{
_ithcheck = new TExternisamfile ( chkname , TRUE , TRUE ) ;
_ithcheck - > setkey ( 1 ) ;
2001-05-02 13:40:49 +00:00
_ithcheck - > first ( ) ;
/*TString tprod;
int tseq ;
while ( _ithcheck - > eof ( ) )
{
tprod = _ithcheck - > get ( " TPROD " ) ;
tseq = _ithcheck - > get_int ( " TSEQ " ) ;
} */
2000-05-05 15:25:49 +00:00
}
}
if ( _ithcheck )
{
_ithcheck - > put ( " TPROD " , import . get ( " TPROD " ) ) ;
_ithcheck - > put ( " TSEQ " , import . get ( " TSEQ " ) ) ;
if ( _ithcheck - > read ( ) = = NOERR )
return FALSE ;
}
TString tmp ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
num_mag2main_imp ( magno , tmp ) ;
if ( import . get_real ( " TQTY " ) . is_zero ( ) )
return FALSE ;
tmp = import . get ( " TTYPE " ) ;
if ( tmp [ 0 ] = = ' 0 ' | |
tmp = = " C3 " | |
( tmp = = " U " ) )
return TRUE ;
return FALSE ;
}
bool filter_bolacqSE ( TImport_file & import )
{
TString tmp ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
num_mag2main_imp ( magno , tmp ) ;
if ( tmp ! = " SE " ) return FALSE ;
return filter_bolacq ( import ) ;
}
bool filter_bolacqTS ( TImport_file & import )
{
TString tmp ;
int magno = atoi ( import . get ( " TWHS " ) ) ;
num_mag2main_imp ( magno , tmp ) ;
if ( tmp ! = " TS " ) return FALSE ;
return filter_bolacq ( import ) ;
1999-04-06 15:34:39 +00:00
}
2000-05-05 15:25:49 +00:00
1999-04-06 15:34:39 +00:00
bool filter_movmag ( TImport_file & import )
{
2000-05-05 15:25:49 +00:00
if ( ! _ithcheck & & _check )
{
TFilename chkname ( import . name ( ) ) ;
chkname = chkname . path ( ) ;
chkname . add ( " ithchk " ) ;
if ( chkname . exist ( ) )
_check = FALSE ;
else
{
_ithcheck = new TExternisamfile ( chkname , TRUE , TRUE ) ;
_ithcheck - > setkey ( 1 ) ;
}
}
if ( _ithcheck )
{
_ithcheck - > put ( " TPROD " , import . get ( " TPROD " ) ) ;
_ithcheck - > put ( " TSEQ " , import . get ( " TSEQ " ) ) ;
if ( _ithcheck - > read ( ) = = NOERR )
return FALSE ;
}
1999-07-16 14:59:11 +00:00
const long codmag = import . get_long ( " TWHS " ) ;
if ( ! import . get ( " TWHS " ) . blank ( ) )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
if ( import . get_real ( " TQTY " ) ! = ZERO )
{
const char cod0 = * ( const char * ) import . get ( " TTYPE " ) ;
2000-05-05 15:25:49 +00:00
const char cod1 = * ( ( const char * ) import . get ( " TTYPE " ) + 1 ) ;
1999-07-16 14:59:11 +00:00
if ( ( codmag = = 25 | | codmag = = 27 ) & & cod0 = = ' X ' )
return FALSE ; // importa solo i magazzini non fittizi
switch ( cod0 )
{
2000-05-05 15:25:49 +00:00
case ' T ' :
return import . get ( " TRES " ) = = " 02 " | | import . get ( " TRES " ) = = " 05 " ;
case ' R ' : // ricodifiche
return TRUE ;
case ' X ' :
return cod1 = = ' 7 ' | | cod1 = = ' 8 ' ;
1999-07-16 14:59:11 +00:00
case ' 0 ' :
case ' C ' :
case ' U ' :
2000-05-05 15:25:49 +00:00
break ; // acquisti e altre entrate da fornitori (vedi altro prog)
case ' O ' : // opening
case ' A ' : // diff. inventariali
case ' M ' : // consuntivazioni (carichi)
case ' I ' : // consuntivazioni (scarichi)
break ;
1999-07-16 14:59:11 +00:00
default :
fatal_box ( " Causale sconosciuta :%s " , ( const char * ) import . get ( " TTYPE " ) ) ;
}
}
1999-04-06 15:34:39 +00:00
}
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 )
{
1999-07-16 14:59:11 +00:00
long firm = get_firm ( ) ;
clear_docs ( firm , " SEOF " ) ;
2001-05-02 13:40:49 +00:00
// clear_docs(firm,"TSOF");
1999-04-06 15:34:39 +00:00
TImport_file ordacq ( m . get ( F_PATH ) , BPCS_ORDACQ ) ;
1999-07-16 14:59:11 +00:00
return creadocs ( " Importazione ordini di acquisto.. " , firm , ordacq ,
" PORD " , " PVEND " , NULL , NULL , NULL , NULL ,
2001-05-02 13:40:49 +00:00
set_head_ordacq , set_body_ordacq , filter_ordacq , NULL , tipocf_for ) ;
1999-04-06 15:34:39 +00:00
}
bool TImporta_BPCS : : importa_ordcli ( TMask & m )
{
1999-07-16 14:59:11 +00:00
long firm = get_firm ( ) ;
clear_docs ( firm , " SEOC " ) ;
clear_docs ( firm , " TSOC " ) ;
1999-04-06 15:34:39 +00:00
TImport_file released_orders ( m . get ( F_PATH ) , BPCS_SHOPORDS ) ;
1999-07-16 14:59:11 +00:00
bool ok = creadocs ( " Importazione ordini cliente (1).. " , firm , released_orders ,
NULL , " SCUST " , " SRDTE " , " SOFAC " , NULL , NULL ,
2001-05-02 13:40:49 +00:00
set_head_R_ordcli , set_body_R_ordcli , filter_R_ordcli , NULL , tipocf_cli ) ;
1999-04-06 15:34:39 +00:00
TImport_file firm_orders ( m . get ( F_PATH ) , BPCS_FIRMORD ) ;
1999-07-16 14:59:11 +00:00
ok = ok & & creadocs ( " Importazione ordini cliente (2).. " , firm , firm_orders ,
NULL , " FPPVND " , " FRDTE " , " FPFAC " , NULL , NULL ,
2001-05-02 13:40:49 +00:00
set_head_F_ordcli , set_body_F_ordcli , filter_F_ordcli , NULL , tipocf_cli ) ;
1999-04-06 15:34:39 +00:00
return ok ;
}
bool TImporta_BPCS : : importa_ordprod ( TMask & m )
{
1999-07-16 14:59:11 +00:00
long firm = get_firm ( ) ;
if ( yesno_box ( " Cancello gli ordini MSP? " ) )
2001-05-02 13:40:49 +00:00
if ( noyes_box ( " Cancello solo gli MSP non confermati (n. >= 900000)? " ) )
clear_docs ( firm , " MSP " , NULL , NULL , 900000L ) ;
else
clear_docs ( firm , " MSP " ) ;
if ( yesno_box ( " Cancello gli ordini SEFA? " ) )
clear_docs ( firm , " SEFA " ) ;
bool ok = TRUE ;
1999-04-06 15:34:39 +00:00
TImport_file released_orders ( m . get ( F_PATH ) , BPCS_SHOPORDS ) ;
2001-05-02 13:40:49 +00:00
ok = ok & & creadocs ( " Importazione ordini di produzione Segrate (Released).. " , firm , released_orders ,
1999-07-16 14:59:11 +00:00
" SORD " , NULL , " SRDTE " , " SOFAC " , NULL , NULL ,
2001-05-02 13:40:49 +00:00
set_head_R_ordprod , set_body_R_ordprod , filterRordprodSE , NULL , tipocf_null ) ;
1999-04-06 15:34:39 +00:00
TImport_file firm_orders ( m . get ( F_PATH ) , BPCS_FIRMORD ) ;
1999-07-16 14:59:11 +00:00
ok = ok & & creadocs ( " Importazione ordini di produzione Segrate (Firm Planned).. " , firm , firm_orders ,
2001-05-02 13:40:49 +00:00
" **900000 " , NULL , " FRDTE " , " FPFAC " , NULL , NULL ,
set_head_F_ordprod , set_body_F_ordprod , filterFordprodSE , NULL , tipocf_null ) ;
1999-04-06 15:34:39 +00:00
return ok ;
}
2000-05-05 15:25:49 +00:00
bool TImporta_BPCS : : importa_bolacq ( TMask & m )
{
TFilename source ( m . get ( F_MOVMAG_FILE ) ) ;
if ( source . blank ( ) )
source = BPCS_MOVMAG ;
TImport_file movmag ( m . get ( F_PATH ) , source ) ;
const TDate & fromdate = ( m . get_date ( F_MOVMAG_FROMD ) ) ;
const TDate & todate = ( m . get_date ( F_MOVMAG_TOD ) ) ;
if ( yesno_box ( " Controllo la presenza di locazioni sconosciute? " ) )
{
if ( ! check_mag_locations ( m . get ( F_PATH ) , source ) )
return FALSE ;
}
return importa_bolacq ( movmag , m . get_bool ( F_MOVMAG_SE ) , m . get_bool ( F_MOVMAG_TS ) , fromdate , todate , m . get_bool ( F_TESTONLY ) , m . get_bool ( F_NOCLEAR ) ) ;
}
1999-04-06 15:34:39 +00:00
2000-05-05 15:25:49 +00:00
bool TImporta_BPCS : : importa_bolacq ( TImport_file & movmag , bool segrate , bool trieste , const TDate & fromdate , const TDate & todate , bool testonly , bool noclear )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
long firm = get_firm ( ) ;
2000-05-05 15:25:49 +00:00
bool ok = TRUE ;
if ( segrate )
{
if ( ! testonly & & ! noclear )
{
clear_docs ( firm , " SEBA " , & fromdate , & todate ) ;
//clear_docs(firm, "SERF",&fromdate,&todate);
}
ok & = creadocs ( " Importazione bolle di acquisto di Segrate.. " , firm , movmag ,
NULL , " TVEND " , " TTDTE " , " THRNO " , " TTYPE " , " TREF " ,
2001-05-02 13:40:49 +00:00
set_head_bolacq , set_body_bolacq , filter_bolacqSE , set_group_movmag , tipocf_for , ! testonly ) ;
2000-05-05 15:25:49 +00:00
if ( ! testonly )
{
confirm_docs ( " SEBA " , & fromdate , & todate ) ;
//confirm_docs("SERF",&fromdate,&todate);
}
}
if ( trieste )
{
if ( ! testonly & & ! noclear )
{
clear_docs ( firm , " TSBA " , & fromdate , & todate ) ;
clear_docs ( firm , " TSRF " , & fromdate , & todate ) ;
}
ok & = creadocs ( " Importazione bolle di acquisto di Trieste.. " , firm , movmag ,
NULL , " TVEND " , " TTDTE " , " THRNO " , " TTYPE " , " TREF " ,
2001-05-02 13:40:49 +00:00
set_head_bolacq , set_body_bolacq , filter_bolacqTS , set_group_movmag , tipocf_for , ! testonly ) ;
2000-05-05 15:25:49 +00:00
if ( ! testonly )
{
confirm_docs ( " TSBA " , & fromdate , & todate ) ;
confirm_docs ( " TSRF " , & fromdate , & todate ) ;
}
}
return ok ;
}
bool TImporta_BPCS : : importa_movmag ( TMask & m )
{
1999-07-16 14:59:11 +00:00
TFilename source ( m . get ( F_MOVMAG_FILE ) ) ;
if ( source . blank ( ) )
source = BPCS_MOVMAG ;
TImport_file movmag ( m . get ( F_PATH ) , source ) ;
2000-05-05 15:25:49 +00:00
const TDate & fromdate = ( m . get_date ( F_MOVMAG_FROMD ) ) ;
const TDate & todate = ( m . get_date ( F_MOVMAG_TOD ) ) ;
1999-07-16 14:59:11 +00:00
if ( yesno_box ( " Controllo la presenza di locazioni sconosciute? " ) )
{
if ( ! check_mag_locations ( m . get ( F_PATH ) , source ) )
return FALSE ;
}
2000-05-05 15:25:49 +00:00
return importa_movmag ( movmag , m . get_bool ( F_MOVMAG_SE ) , m . get_bool ( F_MOVMAG_TS ) , fromdate , todate , m . get_bool ( F_TESTONLY ) , m . get_bool ( F_NOCLEAR ) ) ;
}
bool TImporta_BPCS : : importa_movmag ( TImport_file & movmag , bool segrate , bool trieste , const TDate & fromdate , const TDate & todate , bool testonly , bool noclear )
{
long firm = get_firm ( ) ;
1999-04-06 15:34:39 +00:00
bool ok = TRUE ;
if ( segrate )
1999-07-16 14:59:11 +00:00
{
2000-05-05 15:25:49 +00:00
if ( ! testonly & & ! noclear )
{
clear_docs ( firm , " SEBE " , & fromdate , & todate ) ;
clear_docs ( firm , " SEBT " , & fromdate , & todate ) ;
clear_docs ( firm , " SEBU " , & fromdate , & todate ) ;
clear_docs ( firm , " SEBV " , & fromdate , & todate ) ;
clear_docs ( firm , " SEDI " , & fromdate , & todate ) ;
clear_docs ( firm , " SEMM " , & fromdate , & todate ) ;
}
1999-07-16 14:59:11 +00:00
ok & = creadocs ( " Importazione movimenti magazzino di Segrate.. " , firm , movmag ,
2001-05-02 13:40:49 +00:00
NULL , " TVEND " , " TTDTE " , " TTYPE " , NULL , NULL ,
set_head_movmag , set_body_movmag , filter_movmagSE , set_group_movmag , tipocf_movmag , ! testonly ) ;
2000-05-05 15:25:49 +00:00
if ( ! testonly )
{
confirm_docs ( " SEBE " , & fromdate , & todate ) ;
confirm_docs ( " SEBT " , & fromdate , & todate ) ;
confirm_docs ( " SEBU " , & fromdate , & todate ) ;
confirm_docs ( " SEBV " , & fromdate , & todate ) ;
confirm_docs ( " SEDI " , & fromdate , & todate ) ;
confirm_docs ( " SEMM " , & fromdate , & todate ) ;
}
1999-07-16 14:59:11 +00:00
}
1999-04-06 15:34:39 +00:00
if ( trieste )
1999-07-16 14:59:11 +00:00
{
2000-05-05 15:25:49 +00:00
if ( ! testonly & & ! noclear )
{
clear_docs ( firm , " TSBE " , & fromdate , & todate ) ;
clear_docs ( firm , " TSBT " , & fromdate , & todate ) ;
clear_docs ( firm , " TSBU " , & fromdate , & todate ) ;
clear_docs ( firm , " TSBV " , & fromdate , & todate ) ;
clear_docs ( firm , " TSDI " , & fromdate , & todate ) ;
clear_docs ( firm , " TSMM " , & fromdate , & todate ) ;
}
1999-07-16 14:59:11 +00:00
ok & = creadocs ( " Importazione movimenti magazzino di Trieste.. " , firm , movmag ,
NULL , " TVEND " , " TTDTE " , " TTYPE " , " TREF " , NULL ,
2001-05-02 13:40:49 +00:00
set_head_movmag , set_body_movmag , filter_movmagTS , set_group_movmag , tipocf_movmag , ! testonly ) ;
2000-05-05 15:25:49 +00:00
if ( ! testonly )
{
confirm_docs ( " TSBE " , & fromdate , & todate ) ;
confirm_docs ( " TSBT " , & fromdate , & todate ) ;
confirm_docs ( " TSBU " , & fromdate , & todate ) ;
confirm_docs ( " TSBV " , & fromdate , & todate ) ;
confirm_docs ( " TSDI " , & fromdate , & todate ) ;
confirm_docs ( " TSMM " , & fromdate , & todate ) ;
}
1999-07-16 14:59:11 +00:00
}
1999-04-06 15:34:39 +00:00
return ok ;
/*bool creadocs( ........
char * FieldNumDoc , char * FieldClifor , char * FieldDataDoc , char * Group
. . . . . . . . . . . ) */
}
void TImporta_BPCS : : main_loop ( )
{
1999-07-16 14:59:11 +00:00
TImporta_mask m ;
1999-04-06 15:34:39 +00:00
m . field ( F_PATH ) . set ( " E: \\ bpcs \\ " ) ;
while ( m . run ( ) ! = K_QUIT )
{
bool ok = TRUE ;
1999-07-16 14:59:11 +00:00
bool lavs_rinumerate = FALSE ;
1999-04-06 15:34:39 +00:00
if ( m . get_bool ( F_ARTS ) )
{
if ( m . get_bool ( F_CHANGEGMC ) )
ok | = cambia_gmc ( m ) ;
else
{
if ( m . get_bool ( F_BOMS ) )
1999-07-16 14:59:11 +00:00
lavs_rinumerate = delete_boms ( ) ;
ok | = importa_arts ( m , m . get_bool ( F_ERASE_ARTS ) , FALSE ) ; // articoli e distinte virtuali fantasma
1999-04-06 15:34:39 +00:00
}
}
if ( m . get_bool ( F_BOMS ) )
{
1999-07-16 14:59:11 +00:00
if ( ! m . get_bool ( F_ARTS ) )
1999-04-06 15:34:39 +00:00
{
1999-07-16 14:59:11 +00:00
if ( yesno_box ( " Azzero le distinte e importo i ghost dall'anagrafica? " ) )
{
lavs_rinumerate = delete_boms ( ) ;
ok | = importa_arts ( m , m . get_bool ( F_ERASE_ARTS ) , TRUE ) ; // importa distinte virtuali fantasma
}
1999-04-06 15:34:39 +00:00
}
ok | = importa_boms ( m ) ;
1999-07-16 14:59:11 +00:00
if ( lavs_rinumerate | | yesno_box ( " Rinumero le distinte ? " ) )
rinumera_dist ( ) ;
if ( yesno_box ( " Setto gli articolo MASTER per il MSP a 2 livelli ? " ) )
build2levmsp ( ) ;
1999-04-06 15:34:39 +00:00
}
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 ) )
1999-07-16 14:59:11 +00:00
if ( noyes_box ( " Gli ordini cliente dovrebbero essere inseriti a mano; confermi l'importazione? " ) )
ok | = importa_ordcli ( m ) ;
1999-04-06 15:34:39 +00:00
if ( m . get_bool ( F_MOVMAG ) )
2000-05-05 15:25:49 +00:00
{
if ( m . get_bool ( F_BOLACQ ) )
ok | = importa_bolacq ( m ) ;
else
ok | = importa_movmag ( m ) ;
}
1999-04-06 15:34:39 +00:00
if ( ok )
message_box ( " Operazione conclusa " ) ;
else
message_box ( " Operazione interrotta " ) ;
}
}
2000-05-05 15:25:49 +00:00
void TImporta_automag_BPCS : : main_loop ( )
{
TMask m ( " dbcv00b.msk " ) ;
if ( m . run ( ) ! = K_QUIT )
{
TFilename source ( m . get ( F_MOVMAG_FILE ) ) ;
if ( source . blank ( ) )
source = BPCS_MOVMAG ;
/*if (yesno_box("Ricostruisco i files di importazione dai TXT di BPCS?"))
{
TCrea_dbf creadbf ;
TFilename txtsource ( source ) ;
creadbf . set_path ( m . get ( F_PATH ) ) ;
creadbf . txt2dbf ( source , txtsource , " ith_aga " ) ;
} */
TImport_file movmag ( m . get ( F_PATH ) , source ) ;
const TDate & fromdate = ( m . get_date ( F_MOVMAG_FROMD ) ) ;
const TDate & todate = ( m . get_date ( F_MOVMAG_TOD ) ) ;
2001-05-02 13:40:49 +00:00
if ( importa_movmag ( movmag , m . get_bool ( F_MOVMAG_SE ) , m . get_bool ( F_MOVMAG_TS ) , fromdate , todate , m . get_bool ( F_TESTONLY ) , m . get_bool ( F_NOCLEAR ) ) )
importa_bolacq ( movmag , m . get_bool ( F_MOVMAG_SE ) , m . get_bool ( F_MOVMAG_TS ) , fromdate , todate , m . get_bool ( F_TESTONLY ) , m . get_bool ( F_NOCLEAR ) ) ;
2000-05-05 15:25:49 +00:00
message_box ( " Fine importazione " ) ;
}
}
1999-04-06 15:34:39 +00:00
int dbcv00 ( int argc , char * argv [ ] )
{
2000-05-05 15:25:49 +00:00
int n = argc > 1 ? ( argv [ 1 ] [ 1 ] - ' 0 ' ) : 0 ;
1999-04-06 15:34:39 +00:00
TString name ;
2000-05-05 15:25:49 +00:00
if ( argc > 2 & & argv [ 2 ] [ 0 ] = = ' a ' )
{
TImporta_automag_BPCS dt ;
dt . run ( argc , argv , " Importa magazzino BPCS " ) ;
}
else
{
TImporta_BPCS dt ;
dt . run ( argc , argv , " Importazione archivi da BPCS " ) ;
}
1999-04-06 15:34:39 +00:00
return 0 ;
}