Files correlati : Ricompilazione Demo : [ ] Commento : Riportata la versione 1.7 patch 054 aga sul main trunk git-svn-id: svn://10.65.10.50/trunk@9659 c028cbd2-c16b-5b4b-a496-9718f37d4682
		
			
				
	
	
		
			2288 lines
		
	
	
		
			68 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			2288 lines
		
	
	
		
			68 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "dbcv.h"
 | |
| #include "dbcv09.h"
 | |
| #include "dbcv00a.h"
 | |
| #include "dbcv01.h"
 | |
| 
 | |
| #include <automask.h>
 | |
| #include <applicat.h>
 | |
| #include <execp.h>
 | |
| #include "..\mg\anamag.h"
 | |
| #include "..\mg\mag.h"
 | |
| #include "..\mg\mglib.h"
 | |
| #include "..\include\doc.h"
 | |
| #include "..\include\rdoc.h"
 | |
| #include "..\ve\velib.h"
 | |
| 
 | |
| typedef void (*SET_DOC_FUN)(TImport_file & import,TConfig &trans);
 | |
| typedef int (*SET_BODYDOC_FUN)(TImport_file & import,TConfig &trans, const bool dotrans);
 | |
| typedef const char *(*TIPOCF_FUN)(TImport_file & import);
 | |
| typedef bool (*FILTER_FUN)(TImport_file & import);
 | |
| typedef bool (*GROUPBRK_FUN)(TImport_file & import);
 | |
| 
 | |
| static TExternisamfile *_ithcheck=NULL;
 | |
| static bool _check=TRUE;
 | |
| 
 | |
| #include "dbcvlib.h"
 | |
| 
 | |
| class TImporta_mask : public TAutomask
 | |
| {
 | |
| protected:
 | |
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | |
| public:
 | |
|   TImporta_mask() :TAutomask("dbcv00a.msk"){}
 | |
| };
 | |
| bool TImporta_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | |
| {
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| class TImporta_BPCS : public TSkeleton_application
 | |
| {
 | |
|   TLocalisamfile * _dist, *_rdist, * _anamag, *_umart, *_codcorr,*_mag;
 | |
| private:
 | |
|   void delete_ghosts();
 | |
|   void delete_arts();
 | |
|   bool delete_boms();
 | |
|   int read_last_rdist(const char *item_code);
 | |
|   bool read_is_dist(const char *item_code);
 | |
|   bool 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 *FieldGroup1,  const char *FieldGroup2,  const char *FieldGroup3,  
 | |
|           SET_DOC_FUN set_header,  SET_BODYDOC_FUN set_body,  FILTER_FUN filter ,GROUPBRK_FUN grp,
 | |
|           TIPOCF_FUN tipocf, bool do_ve0=TRUE);
 | |
| 
 | |
|   void clear_docs(long firm, const char * num, const TDate *fromdate=NULL, const TDate *todate=NULL, const long fromnum= 0,const long tonum=-1 );
 | |
|   void change_docs_status(const char * num, const TDate *fromdate, const TDate *todate, int fromstatus, int tostatus);
 | |
|   void newums();
 | |
| 
 | |
| 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);
 | |
| protected:
 | |
|   virtual bool create();
 | |
|   virtual bool destroy();
 | |
|   bool importa_boms(TMask &m);
 | |
|   bool cambia_gmc(TMask & m);
 | |
|   bool importa_arts(TMask &m, const bool erase, 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 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);
 | |
| protected:
 | |
|   virtual void main_loop() ;
 | |
| };
 | |
| 
 | |
| class TImporta_automag_BPCS : public TImporta_BPCS 
 | |
| {
 | |
| protected:
 | |
|   virtual void main_loop() ;
 | |
| };
 | |
| bool TImporta_BPCS::create()
 | |
| {
 | |
|   open_files(LF_TAB, LF_TABCOM, LF_CLIFO, LF_CFVEN, LF_RIGHEDOC, LF_MOVMAG, LF_RMOVMAG, 0);
 | |
|   _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;
 | |
| }
 | |
| bool TImporta_BPCS::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 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();
 | |
|   }
 | |
| }
 | |
| 
 | |
| // cancella le distinte che non sono lavorazioni
 | |
| bool TImporta_BPCS ::delete_boms()
 | |
| {
 | |
|   bool retv=FALSE;
 | |
|   TWait_cursor hourglass;  
 | |
|   TIndwin info(60,"Cancellazione distinte...",FALSE,FALSE);
 | |
|   // distinte
 | |
|   for (long i=_dist->items(); i>0; i--)
 | |
|   {
 | |
|     _dist->readat(i);
 | |
|     if (cache().get("LAV",_dist->get("CODDIST")).empty())
 | |
|     {
 | |
|       // non e' una lavorazione
 | |
|       _dist->remove();
 | |
|     }
 | |
|     if ((i%TICK)==0)
 | |
|       do_events();
 | |
|   }
 | |
|   // righe distinte
 | |
|   for (i=_rdist->items(); i>0; i--)
 | |
|   {
 | |
|     _rdist->readat(i);
 | |
|     if (_rdist->get("TIPO")!="L" || 
 | |
|       _rdist->get("CODCOMP").left(5)=="ACQUA")
 | |
|     {
 | |
|       // non e' una lavorazione interessante
 | |
|       _rdist->remove();
 | |
|     } 
 | |
|     else
 | |
|     {
 | |
|       _rdist->put("NRIG",_rdist->get("NRIG")+200);
 | |
|       _rdist->rewrite();
 | |
|       retv=TRUE;
 | |
|     }
 | |
|     if ((i%TICK)==0)
 | |
|       do_events();
 | |
|   }
 | |
|   return retv;
 | |
| }
 | |
| 
 | |
| // 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=0;
 | |
| 
 | |
|   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==9999999)||(ddis==999999)||(ddis==99999));
 | |
|     if (skipped_lcode==current_lcode || dead_lcode==current_lcode)
 | |
|       skip = TRUE;
 | |
|     if (!skip && m.get_bool(F_CHECKDEADARTS))
 | |
|     {
 | |
|       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 '%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 gli impianti SEgrate e TrieSte
 | |
|     if (!skip && (impianto=="SE" || impianto=="TS" ) /* && metodo == 99 */)
 | |
|     {
 | |
|       main_imp=impianto;
 | |
|       do {
 | |
|         if (impianto == "PD")
 | |
|           impianto = "PR";
 | |
|         if (metodo==7)
 | |
|         {
 | |
|           impianto = "PD";
 | |
|           metodo = 0;
 | |
|         }
 | |
|         const TString8 father_grmerc= cache().get(LF_ANAMAG,old_code).get("GRMERC");
 | |
|         if (metodo!=0)
 | |
|         {
 | |
|           if (metodo==99)
 | |
|           {
 | |
|             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);
 | |
|   
 | |
|             _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");
 | |
|     } 
 | |
|     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 erase, const bool sologhost)
 | |
| {
 | |
|   TWait_cursor hourglass;  
 | |
|   cache().flush(LF_ANAMAG);
 | |
|   cache().flush(LF_DIST);
 | |
|   cache().flush(LF_UMART);
 | |
|   if (erase)
 | |
|     delete_arts();
 | |
| 
 | |
|   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 ((!m.get_bool(F_CHECKDEADARTS) || 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_long("IVEND"));
 | |
|           _anamag->put( ANAMAG_UMP, "KG");
 | |
|           _anamag->put( ANAMAG_PESO, items.get_real("IWGHT"));
 | |
|           // riordino
 | |
|           _anamag->put( ANAMAG_RIORDINO , "F"); //_anamag->put( ANAMAG_RIORDINO , items.get("IMRP")=="M" ? "F" : "P" );
 | |
|           _anamag->put( ANAMAG_GIORNIRIOR, items.get_long("ILEAD"));
 | |
|           _anamag->put( ANAMAG_LOTTORIOR,  items.get_real("ILOTS"));
 | |
|           _anamag->put( ANAMAG_LOTTOIRIOR, items.get_real("IIOQ"));
 | |
|           //
 | |
|           _anamag->put( ANAMAG_PPCONF   , items.get_long("IFII"));
 | |
|           _anamag->put( ANAMAG_PPCOLLO  , items.get_long("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_real("ISCST"));
 | |
|           _anamag->put( ANAMAG_ULTCOS1, items.get_real("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_real("MSIDR"));// idrati
 | |
|             _anamag->put( ANAMAG_USER2 , items_ext.get_real("MSANI"));//anidri
 | |
|             _anamag->put( ANAMAG_USER3 , items_ext.get("MSTAL"));//alcool
 | |
|             // dimensioni
 | |
|             _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"));
 | |
|             // composizione pallets
 | |
|             _anamag->put( ANAMAG_USER7, items_ext.get_long("MSCST")); // casse per strato
 | |
|             _anamag->put( ANAMAG_USER8, items_ext.get_long("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())
 | |
|         {
 | |
|            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);
 | |
|           }
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|     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")
 | |
|     {
 | |
|       for (int falsi_terzisti=0;falsi_terzisti<3; falsi_terzisti++) 
 | |
|       {
 | |
|         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); 
 | |
|         }
 | |
|       }
 | |
|     }
 | |
|     divisori.next();
 | |
|   }
 | |
| 
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| 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;
 | |
|   TIndwin info(80,"Cambio stato documenti                       ",TRUE,FALSE);
 | |
| 
 | |
|   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)
 | |
|       {
 | |
|         info.set_text(format("Cambio stato %s n. %ld", num, doc.get_long(DOC_NDOC)));
 | |
|         doc_record = doc.curr();
 | |
|         doc_record.read(_isequal, _lock);
 | |
|         doc_record.put(DOC_STATO, tostatus);
 | |
|         doc_record.rewrite();
 | |
|       }
 | |
|       err = doc.next();
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| void TImporta_BPCS::clear_docs(long firm, const char * num, const TDate *fromdate, const TDate *todate, const long fromnum,const long tonum )
 | |
| {
 | |
|   TConfig *trans=NULL;
 | |
|   long ntransac=0;
 | |
|   int nblock = 1;
 | |
|   // rimuove le transazioni
 | |
|   delete_files("ND_*.ini");
 | |
| 
 | |
|   TString codnum(num);
 | |
|   TLocalisamfile doc(LF_DOC);
 | |
|   TLocalisamfile rdoc(LF_RIGHEDOC);
 | |
|   for (int anno=1998; anno<=2002; anno++)
 | |
|   {
 | |
|     TDate docdate(doc.get_date("DATADOC"));
 | |
|     doc.put(DOC_PROVV,"D");
 | |
|     doc.put(DOC_ANNO,anno);
 | |
|     doc.put(DOC_CODNUM,codnum);
 | |
|     doc.read(_isgteq);
 | |
|     while (!doc.eof() && doc.get("CODNUM")==codnum)
 | |
|     {
 | |
|       while (!doc.eof() && doc.get("CODNUM")==codnum)
 | |
|       {
 | |
|         if (!fromdate || fromdate->empty() || doc.get_date("DATADOC")>=*fromdate)
 | |
|         if (!todate || todate->empty() || doc.get_date("DATADOC")<=*todate)
 | |
|         if (fromnum<=0 || doc.get_long(DOC_NDOC)>=fromnum )
 | |
|         if (tonum<=0 || doc.get_long(DOC_NDOC)<=tonum )
 | |
|         {
 | |
|           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++;
 | |
|       }
 | |
|     }
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| 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 *FieldGroup1,  const char *FieldGroup2,  const char *FieldGroup3,  
 | |
|   SET_DOC_FUN set_header,  SET_BODYDOC_FUN set_body,  FILTER_FUN filter , 
 | |
|   GROUPBRK_FUN grpfun, TIPOCF_FUN tipocf, 
 | |
|   bool do_ve0)
 | |
| {
 | |
| 
 | |
|   TProgind info(imp_file.items(),msg,TRUE,TRUE);
 | |
|   TConfig *trans=NULL;
 | |
|   int nblock=1;
 | |
|   long ntransac=0;
 | |
|   int  nrigadoc=0;
 | |
|   long starting_ndoc=0;
 | |
|   // autonumerazione a partire da ...
 | |
|   if (FieldNumDoc && *FieldNumDoc== '*' && *(FieldNumDoc+1)== '*' )
 | |
|   {
 | |
|     starting_ndoc = atol(FieldNumDoc+2);
 | |
|     FieldNumDoc = NULL;
 | |
|   }
 | |
|   // rimuove le transazioni
 | |
|   delete_files("ND_*.ini");
 | |
| 
 | |
|   imp_file.first();
 | |
|   while (!imp_file.eof() )
 | |
|   {
 | |
|     long  last_ndoc=-1L;
 | |
|     TDate last_date("");
 | |
|     long  last_clifor=-1L;
 | |
|     TString last_group1="";
 | |
|     TString last_group2="";
 | |
|     TString last_group3="";
 | |
| 
 | |
|     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;
 | |
|         if (new_ndoc <= 0 && starting_ndoc)
 | |
|           new_ndoc = starting_ndoc++ ;
 | |
|         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;
 | |
|         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 ))
 | |
|         {
 | |
|           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);
 | |
|           trans->set(DOC_TIPOCF, tipocf(imp_file));
 | |
|           if (new_clifor>0L)
 | |
|           {
 | |
|             if (tipocf(imp_file) == "F")
 | |
|               new_clifor = trascode_for(new_clifor);
 | |
|             trans->set(DOC_CODCF,new_clifor);
 | |
|             // 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);
 | |
|           }
 | |
|           trans->set(DOC_PROVV,"D");
 | |
|           set_header(imp_file, *trans);
 | |
|           nrigadoc=0;
 | |
|           last_ndoc=-1L;
 | |
|           ntransac++;
 | |
|         }
 | |
|         // righe
 | |
|         trans->set_paragraph(format("%d,%d",LF_RIGHEDOC, nrigadoc+1));
 | |
|         nrigadoc += set_body(imp_file, *trans,do_ve0);
 | |
|       }
 | |
|       imp_file.next();
 | |
|     }
 | |
|     if (trans) 
 | |
|     {
 | |
|       delete trans;
 | |
|       trans=NULL;
 | |
|       // genera i documenti
 | |
|       if (do_ve0)
 | |
|       {
 | |
| 
 | |
|         TExternal_app *_gestart=NULL;
 | |
|         TString cmd("ve0.exe -1 -i");
 | |
|         cmd << format("ND_%03d*.INI",nblock-1) ;
 | |
|         if (_gestart==NULL)
 | |
|           _gestart = new TExternal_app((const char *)cmd);
 | |
|         while (_gestart->run()!=0 && yesno_box("Ritento l'esecuzione di ve0.exe ?"))
 | |
|           ;
 | |
|       }
 | |
|       nblock++;
 | |
|     }
 | |
|   }
 | |
|   return TRUE;
 | |
| }
 | |
| 
 | |
| 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 " "; }
 | |
| 
 | |
| 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"));
 | |
|   round_date(dc,28,TRUE);
 | |
|   trans.set(DOC_DATACONS, dc);// stessa data del doc
 | |
| }
 | |
| int set_body_F_ordcli(TImport_file &import, TConfig &trans, const bool dotrans)
 | |
| {
 | |
|   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);
 | |
|   return 1;
 | |
| }
 | |
| 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"));
 | |
|   round_date(dc,28,TRUE);
 | |
|   trans.set(DOC_DATACONS, dc);// stessa data del doc
 | |
| }
 | |
| int set_body_R_ordcli(TImport_file &import, TConfig &trans, const bool dotrans)
 | |
| {
 | |
|   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);
 | |
|   return 1;
 | |
| }
 | |
| 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 firm planned
 | |
| 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") ? "MSP": "TSMP");
 | |
|   trans.set("TIPODOC","ORP");
 | |
|   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)
 | |
|     if (0 || yesno_box("Data ordine di produzione per l'articolo %s inferiore a quella attuale: posticipo a oggi?",(const char *) import.get("FPROD")))
 | |
|       dc = today;
 | |
|   //round_date(dc,28,TRUE);
 | |
|   TDate dd(trans.get(DOC_DATADOC));
 | |
|   if (dc < dd )
 | |
|     trans.set(DOC_DATADOC, dc);
 | |
|   trans.set(DOC_DATACONS, dc);
 | |
| }
 | |
| int set_body_F_ordprod(TImport_file &import, TConfig &trans, const bool dotrans)
 | |
| {
 | |
|   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");
 | |
|   return 1;
 | |
| }
 | |
| bool filterFordprodSE(TImport_file & import)
 | |
| {
 | |
|   bool ok= import.get("FID")=="FP" && import.get("FPFAC")=="SE" && import.get("FTYPE")=="F";
 | |
|   if (ok)
 | |
|   {
 | |
|     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';
 | |
|     }
 | |
|     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") ? "MSP": "TSMP");
 | |
|   trans.set("TIPODOC","ORP");
 | |
|   TDate today(TODAY),
 | |
|     dc(import.get_date("SDDTE")); // due date : data di consegna
 | |
|   TDate rdt(import.get_date("SRSDT")); // reschedule date
 | |
|   if (rdt.ok() && rdt != 99999999L && rdt > dc)
 | |
|     dc = rdt;
 | |
|   if (dc < today)
 | |
|     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")))
 | |
|       dc = today;
 | |
|   //round_date(dc,28,TRUE);
 | |
|   TDate dd(trans.get(DOC_DATADOC)); // data documento
 | |
|   if (dc < dd )
 | |
|     trans.set(DOC_DATADOC, dc);
 | |
|   trans.set(DOC_DATACONS, dc);
 | |
| }
 | |
| int set_body_R_ordprod(TImport_file &import, TConfig &trans, const bool dotrans)
 | |
| {
 | |
|   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);
 | |
| 
 | |
|   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");
 | |
|   trans.set(RDOC_QTA,totale.string());
 | |
|   trans.set(RDOC_QTAEVASA,evasa.string());
 | |
|   add_stdlabors(import.get_codice("SPROD"), import.get_long("SWRKC"), int(import.get_long("SOBOMM")));
 | |
|   return 1;
 | |
| }
 | |
| bool filterRordprodSE(TImport_file & import)
 | |
| {
 | |
|   bool ok=(import.get("SID")=="SO" 
 | |
|             && import.get("SOFAC")=="SE");
 | |
|   if (ok)
 | |
|   {
 | |
|     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');
 | |
|     }
 | |
|   }
 | |
|   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");
 | |
|   // gestione doc. in valuta
 | |
|   TString codval = converti_codval(import.get("POCUR"));
 | |
|   if (!codval.empty())  
 | |
|   {
 | |
|     real cambio=import.get_real("PEXRT");
 | |
|     cambio_fisso(codval,cambio);
 | |
|     trans.set(DOC_CAMBIO,cambio.string());
 | |
|     trans.set(DOC_CODVAL,codval);
 | |
|   }
 | |
| }
 | |
| 
 | |
| int set_body_ordacq(TImport_file &import, TConfig &trans, const bool dotrans)
 | |
| {
 | |
|   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"));
 | |
|   // gestione codice IVA
 | |
|   tmp = "F";
 | |
|   tmp.add(import.get("PVEND"));
 | |
|   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;
 | |
| }
 | |
| 
 | |
| 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_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);
 | |
|   
 | |
|   codcli = trascode_for(codcli);
 | |
|   
 | |
|   trans.set(DOC_CODCF,codcli == 0L ? "" : format("%ld",codcli));
 | |
|   trans.set(DOC_ANNO,import.get_date("TTDTE").year());
 | |
|   // riferimenti
 | |
|   trans.set(DOC_DOC1,import.get("TREF"));
 | |
|   trans.set(DOC_NUMDOCRIF,external_refnum(import));
 | |
|   trans.set(DOC_DATADOCRIF,external_refdate(import));
 | |
|   TString codval = converti_codval(import.get("THCURR"));
 | |
|   if (!codval.empty())  
 | |
|   {
 | |
|     real cambio=import.get_real("THTEXR");
 | |
|     cambio_fisso(codval,cambio);
 | |
|     trans.set(DOC_CAMBIO,cambio.string());
 | |
|     trans.set(DOC_CODVAL,codval);
 | |
|   }
 | |
| }
 | |
| 
 | |
| 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)
 | |
| {
 | |
|   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());
 | |
|   trans.set(RDOC_QTAEVASA, "0");
 | |
|   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());
 | |
| 
 | |
|   if (_ithcheck && dotrans)
 | |
|   {
 | |
|     _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 " ";
 | |
| }
 | |
| 
 | |
| void set_head_movmag(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);
 | |
| 
 | |
|   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;
 | |
|   }
 | |
|   if ((import.get("TLOCT")=="CICCA")
 | |
|     || (import.get("TLOCT")=="CMINT"))
 | |
|   {
 | |
|     import.put("TTYPE", "_L");//conto lavoro
 | |
|     cod0 = '_'; // codice fittizio per simulare IL CONTO LAVORO
 | |
|     cod1 = 'L';
 | |
|   }
 | |
|   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
 | |
|   switch (cod0)
 | |
|   {
 | |
|     case 'O': // completed; 
 | |
|       descrmov="Movimento di apertura di inizio esercizio";
 | |
|       codnum << "DI";
 | |
|       causmag="RIMI";
 | |
|       tipodoc = "__O";
 | |
|       codcli=0L;
 | |
|       break;    
 | |
| 
 | |
|     case 'A': // completed
 | |
|       descrmov="Differenza inventariale";
 | |
|       codnum << "DI";
 | |
|       tipodoc = "__A";
 | |
|       causmag="CAR";
 | |
|       codcli=0L;
 | |
|       break;    
 | |
| 
 | |
|     case 'M': 
 | |
|       if (cod1=='\0')  // completed;
 | |
|       {
 | |
|         descrmov="Consuntivazione produzione";
 | |
|         codnum << "BP"; 
 | |
|         tipodoc = "BPR";
 | |
|         causmag="CFPRP";
 | |
|       } else {
 | |
|         descrmov="Produzione semilavorati per sconfezionamento ";
 | |
|         codnum << "BP"; 
 | |
|         tipodoc = "BPR1";
 | |
|         causmag="SFSC";
 | |
|       }
 | |
|       codcli=0L;
 | |
|       break;    
 | |
| 
 | |
|     case 'I':   // confirmed
 | |
|       descrmov="Scarico componenti ";
 | |
|       codnum << "MM";
 | |
|       tipodoc = "__I";
 | |
|       break;    
 | |
| 
 | |
|     case 'T':   // to be confirmed
 | |
|       codnum << "MM";
 | |
|       descrmov="Trasferimento merce";
 | |
|       codcli=0L;
 | |
|       tipodoc = "__T";
 | |
|       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;    
 | |
|     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;    
 | |
|     case '_':    // completed; 
 | |
|       if (cod1=='L')
 | |
|       {
 | |
|         descrmov="Carico componenti in conto lavoro";
 | |
|         codnum << "BE";
 | |
|         tipodoc = "BECL";
 | |
|         trans.set(DOC_TIPOCF,"C");
 | |
|         causmag="CCIL";
 | |
|       }
 | |
|       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,0L);
 | |
|   if (trans.get(DOC_TIPOCF) == "F")
 | |
|     codcli = trascode_for(codcli);
 | |
|   trans.set(DOC_CODCF,codcli == 0L ? "" : format("%ld",codcli));
 | |
|   trans.set(DOC_ANNO,import.get_date("TTDTE").year());
 | |
|   // riferimenti
 | |
|   trans.set(DOC_DOC1,import.get("TREF"));
 | |
| //  trans.set(DOC_NUMDOCRIF,external_refnum(import));
 | |
| //  trans.set(DOC_DATADOCRIF,external_refdate(import));
 | |
|   TString codval = converti_codval(import.get("THCURR"));
 | |
|   if (!codval.empty())  
 | |
|   {
 | |
|     real cambio=import.get_real("THTEXR");
 | |
|     cambio_fisso(codval,cambio);
 | |
|     trans.set(DOC_CAMBIO,cambio.string());
 | |
|     trans.set(DOC_CODVAL,codval);
 | |
|   }
 | |
| }
 | |
| int set_body_movmag(TImport_file &import, TConfig &trans, const bool dotrans)
 | |
| {
 | |
|   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));
 | |
|     }
 | |
|   }
 | |
|   
 | |
|   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 (codimp == "PD" || (import.get("TCOM").find("PD")>=0))
 | |
|       codmag = "PD1PF";
 | |
|     else if (codimp == "PR" || (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);
 | |
|   TString4 umqta(import.get("THTUM"));
 | |
|   if (umqta.blank())
 | |
|   {
 | |
|     tmp .add("1");
 | |
|     umqta=cache().get(LF_UMART,tmp).get("UM");
 | |
|   }
 | |
|   trans.set(RDOC_UMQTA,umqta);
 | |
| 
 | |
|   trans.set(RDOC_CODMAG,codmag);
 | |
|   real qta(import.get_real("TQTY"));
 | |
|   const char cod0=*(const char * )import.get("TTYPE");
 | |
|   switch (cod0)
 | |
|   {
 | |
|     case 'T':
 | |
|     case 'M': 
 | |
|     case 'A': 
 | |
|     case 'I':
 | |
|     case 'X':
 | |
|     case 'R': 
 | |
|       if (qta >= ZERO)
 | |
|         causmag="CAR";
 | |
|       else
 | |
|         causmag="SCAR";
 | |
|     case 'O': 
 | |
|     case 'V': 
 | |
|     case '_': 
 | |
|       break;    
 | |
|   }
 | |
|   trans.set(RDOC_CAUSMAG,causmag);
 | |
|   trans.set(RDOC_QTA, qta.string());
 | |
|   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);
 | |
|   if (_ithcheck && dotrans)
 | |
|   {
 | |
|     _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");
 | |
|     chkname.ext("dbf");
 | |
|     if (!chkname.exist())
 | |
|       _check = FALSE;
 | |
|     else
 | |
|     {
 | |
|       _ithcheck = new TExternisamfile(chkname, TRUE, TRUE);
 | |
|       _ithcheck->setkey(1);
 | |
|       _ithcheck->first();
 | |
|       /*TString tprod;
 | |
|       int tseq ;
 | |
|       while (_ithcheck->eof())
 | |
|       {
 | |
|         tprod = _ithcheck->get("TPROD");
 | |
|         tseq = _ithcheck->get_int("TSEQ");
 | |
|         
 | |
|       }*/
 | |
|     }
 | |
|   }
 | |
|   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);
 | |
| }
 | |
| 
 | |
| 
 | |
| 
 | |
| bool filter_movmag(TImport_file & import)
 | |
| {
 | |
|   
 | |
|   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;
 | |
|   }
 | |
|   const long codmag=import.get_long("TWHS");
 | |
|   if (!import.get("TWHS").blank() )
 | |
|   {
 | |
|     if (import.get_real("TQTY")!=ZERO)
 | |
|     {
 | |
|       const char cod0=*(const char * )import.get("TTYPE");
 | |
|       const char cod1=*((const char * )import.get("TTYPE")+1);
 | |
| 
 | |
|       if ((codmag == 25 || codmag == 27) && cod0 == 'X')
 | |
|         return FALSE; // importa solo i magazzini non fittizi
 | |
|       switch (cod0)
 | |
|       {
 | |
|         case 'T': 
 | |
|           return import.get("TRES")=="02" || import.get("TRES")=="05";
 | |
|         case 'R': // ricodifiche
 | |
|           return TRUE;
 | |
|         case 'X': 
 | |
|           return cod1=='7' || cod1=='8';
 | |
|         case '0': 
 | |
|         case 'C': 
 | |
|         case 'U':
 | |
|           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;
 | |
|         default:
 | |
|           fatal_box("Causale sconosciuta :%s",(const char * )import.get("TTYPE"));
 | |
|       }
 | |
|     }
 | |
|   }
 | |
|   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)
 | |
| {
 | |
|   long firm =get_firm();
 | |
|   clear_docs(firm,"SEOF");
 | |
|   // clear_docs(firm,"TSOF");
 | |
|   TImport_file ordacq(m.get(F_PATH),BPCS_ORDACQ);
 | |
|   return creadocs("Importazione ordini di acquisto..",firm,ordacq,
 | |
|       "PORD","PVEND",NULL,NULL,NULL,NULL,
 | |
|         set_head_ordacq,set_body_ordacq,filter_ordacq, NULL, tipocf_for);
 | |
| }
 | |
| 
 | |
| bool TImporta_BPCS ::importa_ordcli(TMask & m)
 | |
| {
 | |
|   long firm =get_firm();
 | |
|   clear_docs(firm,"SEOC");
 | |
|   clear_docs(firm,"TSOC");
 | |
|   TImport_file released_orders(m.get(F_PATH),BPCS_SHOPORDS);
 | |
|   bool ok = creadocs("Importazione ordini cliente (1)..",firm,released_orders,
 | |
|       NULL,"SCUST","SRDTE","SOFAC",NULL,NULL,
 | |
|         set_head_R_ordcli,set_body_R_ordcli,filter_R_ordcli, NULL, tipocf_cli);
 | |
| 
 | |
|   TImport_file firm_orders(m.get(F_PATH),BPCS_FIRMORD);
 | |
|   ok = ok && creadocs("Importazione ordini cliente (2)..",firm,firm_orders,
 | |
|       NULL,"FPPVND","FRDTE","FPFAC",NULL,NULL,
 | |
|         set_head_F_ordcli,set_body_F_ordcli,filter_F_ordcli, NULL, tipocf_cli);
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| bool TImporta_BPCS ::importa_ordprod(TMask & m)
 | |
| {
 | |
|   long firm =get_firm();
 | |
|   if (yesno_box("Cancello gli ordini MSP?"))
 | |
|     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;
 | |
|   TImport_file released_orders(m.get(F_PATH),BPCS_SHOPORDS);
 | |
|   ok = ok && creadocs("Importazione ordini di produzione Segrate (Released)..",firm,released_orders,
 | |
|       "SORD",NULL,"SRDTE","SOFAC",NULL,NULL,
 | |
|         set_head_R_ordprod,set_body_R_ordprod,filterRordprodSE, NULL, tipocf_null);
 | |
| 
 | |
|   TImport_file firm_orders(m.get(F_PATH),BPCS_FIRMORD);
 | |
|   ok = ok && creadocs("Importazione ordini di produzione Segrate (Firm Planned)..",firm,firm_orders,
 | |
|       "**900000",NULL,"FRDTE","FPFAC",NULL,NULL,
 | |
|         set_head_F_ordprod,set_body_F_ordprod,filterFordprodSE, NULL, tipocf_null);
 | |
| 
 | |
| 
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| 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));
 | |
| } 
 | |
| 
 | |
| bool TImporta_BPCS::importa_bolacq(TImport_file &movmag, bool segrate, bool trieste, const TDate &fromdate,  const TDate &todate , bool testonly, bool noclear)
 | |
| {
 | |
|   long firm =get_firm();
 | |
| 
 | |
|   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",
 | |
|           set_head_bolacq,set_body_bolacq,filter_bolacqSE, set_group_movmag, tipocf_for, !testonly);
 | |
|     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",
 | |
|           set_head_bolacq,set_body_bolacq,filter_bolacqTS, set_group_movmag, tipocf_for, !testonly);
 | |
|     if (!testonly)
 | |
|     {
 | |
|       confirm_docs("TSBA",&fromdate,&todate);
 | |
|       confirm_docs("TSRF",&fromdate,&todate);
 | |
|     }
 | |
|   }
 | |
|   return ok;
 | |
| }
 | |
| 
 | |
| 
 | |
| bool TImporta_BPCS::importa_movmag(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_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();
 | |
| 
 | |
|   bool ok = TRUE;
 | |
|   if (segrate)
 | |
|   {
 | |
|     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);
 | |
|     }
 | |
|     ok &= creadocs("Importazione movimenti magazzino di Segrate..",firm, movmag,
 | |
|         NULL,"TVEND","TTDTE","TTYPE",NULL,NULL,
 | |
|           set_head_movmag,set_body_movmag,filter_movmagSE, set_group_movmag, tipocf_movmag, !testonly);
 | |
|     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);
 | |
|     }
 | |
|   }
 | |
|   if (trieste)
 | |
|   {
 | |
|     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);
 | |
|     }
 | |
|     ok &= creadocs("Importazione movimenti magazzino di Trieste..",firm, movmag,
 | |
|         NULL,"TVEND","TTDTE","TTYPE","TREF",NULL,
 | |
|           set_head_movmag,set_body_movmag,filter_movmagTS, set_group_movmag, tipocf_movmag, !testonly);
 | |
|     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);
 | |
|     }
 | |
|   }
 | |
|   return ok;
 | |
| /*bool creadocs( ........ 
 | |
|   char *FieldNumDoc,char *FieldClifor,char *FieldDataDoc, char *Group
 | |
|     ...........)*/
 | |
| }
 | |
| 
 | |
| 
 | |
| void TImporta_BPCS ::main_loop() 
 | |
| {
 | |
|   TImporta_mask m;
 | |
|   m.field(F_PATH).set("E:\\bpcs\\");
 | |
|   while (m.run()!=K_QUIT)
 | |
|   {
 | |
|     bool ok=TRUE;
 | |
|     bool lavs_rinumerate=FALSE;
 | |
|     if (m.get_bool(F_ARTS))
 | |
|     {
 | |
|       if (m.get_bool(F_CHANGEGMC))
 | |
|         ok|=cambia_gmc(m);
 | |
|       else
 | |
|       {
 | |
|         if (m.get_bool(F_BOMS))
 | |
|           lavs_rinumerate = delete_boms();
 | |
|         ok|=importa_arts(m, m.get_bool(F_ERASE_ARTS), FALSE); // articoli e distinte virtuali fantasma
 | |
|       }
 | |
|     }
 | |
|     if (m.get_bool(F_BOMS))
 | |
|     {
 | |
|       if (!m.get_bool(F_ARTS))
 | |
|       {
 | |
|         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
 | |
|         }
 | |
|       }
 | |
|       ok|=importa_boms(m);
 | |
|       if (lavs_rinumerate || yesno_box("Rinumero le distinte ?" ))
 | |
|         rinumera_dist();
 | |
|       if (yesno_box("Setto gli articolo MASTER per il MSP a 2 livelli ?"))
 | |
|         build2levmsp();
 | |
|     }
 | |
|     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))
 | |
|       if (noyes_box("Gli ordini cliente dovrebbero essere inseriti a mano; confermi l'importazione?"))
 | |
|         ok|=importa_ordcli(m);
 | |
|     if (m.get_bool(F_MOVMAG))
 | |
|     {
 | |
|       if (m.get_bool(F_BOLACQ))
 | |
|         ok|=importa_bolacq(m);
 | |
|       else
 | |
|         ok|=importa_movmag(m);
 | |
|     }
 | |
|     if (ok)
 | |
|       message_box("Operazione conclusa");
 | |
|     else
 | |
|       message_box("Operazione interrotta");
 | |
|   }
 | |
| }
 | |
| 
 | |
| 
 | |
| 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));
 | |
|         
 | |
|     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));
 | |
| 
 | |
|     message_box("Fine importazione");
 | |
|   }
 | |
| }
 | |
| 
 | |
| int dbcv00(int argc, char* argv[])
 | |
| {
 | |
|   int n = argc > 1 ? (argv[1][1] - '0') : 0;
 | |
|   TString name;
 | |
|   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");
 | |
|   }
 | |
| 
 | |
|   return 0;
 | |
| }
 |