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
		
			
				
	
	
		
			1699 lines
		
	
	
		
			47 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			1699 lines
		
	
	
		
			47 KiB
		
	
	
	
		
			C++
		
	
	
		
			Executable File
		
	
	
	
	
| #include "dbcv.h"
 | ||
| #include "dbcv09.h"
 | ||
| #include "dbcv02a.h"
 | ||
| 
 | ||
| #include <automask.h>
 | ||
| #include <applicat.h>
 | ||
| #include <relation.h>
 | ||
| #include <execp.h>
 | ||
| #include "..\mg\anamag.h"
 | ||
| #include "..\mg\mag.h"
 | ||
| #include "..\include\doc.h"
 | ||
| #include "..\include\rdoc.h"
 | ||
| #include "..\db\dblib.h"
 | ||
| 
 | ||
| typedef void (*SET_DOC_FUN)(TImport_file & import,TConfig &trans);
 | ||
| typedef bool (*FILTER_FUN)(TImport_file & import);
 | ||
| 
 | ||
| bool unevadi_orc(TMask &m, const TString & codimp)
 | ||
| {
 | ||
|   TString8 codnum=codimp;
 | ||
|   codnum<< "OC";
 | ||
|   TRelation *r= new TRelation(LF_DOC);
 | ||
|   r->add(LF_RIGHEDOC,"CODNUM==CODNUM|ANNO==ANNO|PROVV==PROVV|NDOC==NDOC");
 | ||
|   TCursor c(r);
 | ||
|   TRectype frec(LF_DOC);
 | ||
|   frec.put("CODNUM",codnum);
 | ||
|   frec.put("PROVV","D");
 | ||
|   frec.put("ANNO" ,"1999");
 | ||
|   c.setregion(frec,frec);
 | ||
|   c.freeze();
 | ||
| 
 | ||
|   const long items=c.items();
 | ||
|   TProgind info(items,"Reset evasione commesse cliente...",FALSE,TRUE);
 | ||
|   for (long i= 0; i< items ; i++)
 | ||
|   {
 | ||
|     c=i;
 | ||
|     info.addstatus(1);
 | ||
|     TRelation *r =c.relation();
 | ||
|     TLocalisamfile & righe = c.relation()->lfile(LF_RIGHEDOC);
 | ||
|     bool ok = r->is_first_match(LF_RIGHEDOC);
 | ||
|     while (ok)
 | ||
|     {
 | ||
|       if (righe.get_bool("RIGAEVASA") ||righe.get_real("QTAEVASA")!=ZERO )
 | ||
|       {
 | ||
|         righe.put("RIGAEVASA"," ");
 | ||
|         righe.put("QTAEVASA","0.0");
 | ||
|         righe .rewrite();
 | ||
|       }
 | ||
|       ok = r->next_match(LF_RIGHEDOC);
 | ||
|     }
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| bool evadi_orc(TCursor  & c, TAssoc_array & evasioni)
 | ||
| {
 | ||
|   const long items=c.items();
 | ||
|   TProgind info(items,"Evasione commesse cliente...",FALSE,TRUE);
 | ||
|   for (long i= 0; i< items ; i++)
 | ||
|   {
 | ||
|     c=i;
 | ||
|     info.addstatus(1);
 | ||
|     TRelation *r =c.relation();
 | ||
|     TLocalisamfile & righe = c.relation()->lfile(LF_RIGHEDOC);
 | ||
|     bool ok = r->is_first_match(LF_RIGHEDOC);
 | ||
|     while (ok)
 | ||
|     {
 | ||
|       const TString codprod = righe.get("CODARTMAG");
 | ||
|       real *qta=NULL;
 | ||
|       if (evasioni.is_key(codprod))
 | ||
|         qta=(real*)evasioni.objptr(codprod);
 | ||
|       if (!righe.get_bool("RIGAEVASA") && qta!=NULL)
 | ||
|       {
 | ||
|         real q(righe.get_real("QTA"));
 | ||
|         real qevasa(righe.get_real("QTAEVASA"));
 | ||
|         if (*qta>ZERO && q>qevasa)
 | ||
|         {
 | ||
|           if (q-qevasa>*qta)
 | ||
|           {
 | ||
|             qevasa+=*qta;
 | ||
|             *qta = 0;
 | ||
|           } else {
 | ||
|             *qta -= q;
 | ||
|             qevasa=q;
 | ||
|             righe.put("RIGAEVASA","X");
 | ||
|           }
 | ||
|           righe.put("QTAEVASA",qevasa);
 | ||
|           righe .rewrite();
 | ||
|         }
 | ||
|       }
 | ||
|       ok = r->next_match(LF_RIGHEDOC);
 | ||
|     }
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| bool evadi_orc(TMask & m, const TString & codimp)
 | ||
| {
 | ||
|   if (!yesno_box("I movimenti 00 e T-04 sul mag. 25 verranno usati per evadere le commesse. Procedo?"))
 | ||
|     return FALSE;
 | ||
|   TFilename source(m.get(S_MOVMAG_FILE));
 | ||
|   if (source.blank()) 
 | ||
|     source=BPCS_MOVMAG;
 | ||
|   TDate fromdate(m.get(S_MOVMAG_FROMD));
 | ||
|   TDate todate(m.get(S_MOVMAG_TOD));
 | ||
|   TImport_file movmag(m.get(F_PATH),source);
 | ||
|   bool ok = TRUE;
 | ||
|   if (noyes_box("Attenzione: l'operazione non e' ripetibile;assicurarsi che la situazione del pending delle commesse sia relativa alla bolla indicata. Procedo?"))
 | ||
|   {
 | ||
|     const int expmag= codimp == "SE" ? 25 : 27;
 | ||
| 
 | ||
|     TString8 codnum=codimp;
 | ||
|     codnum<< "OC";
 | ||
|     TRelation *r= new TRelation(LF_DOC);
 | ||
|     r->add(LF_RIGHEDOC,"CODNUM==CODNUM|ANNO==ANNO|PROVV==PROVV|NDOC==NDOC");
 | ||
|     TCursor c(r,"!DOCEVASO");
 | ||
|     TRectype frec(LF_DOC);
 | ||
|     frec.put("CODNUM",codnum);
 | ||
|     frec.put("PROVV","D");
 | ||
|     frec.put("ANNO" ,"1999");
 | ||
|     c.setregion(frec,frec);
 | ||
|     c.freeze();
 | ||
| 
 | ||
|     long lastbolla(m.get_int(S_LASTBOLLA)),nobolla;
 | ||
|     TProgind info(movmag.items(),"Estrazione ultime consegne...",FALSE,TRUE);
 | ||
| 
 | ||
|     TAssoc_array evasioni;
 | ||
|     movmag.first();
 | ||
|     while(!movmag.eof())
 | ||
|     {
 | ||
|       info.addstatus(1);
 | ||
|       const TDate dmov = movmag.get_date("TTDTE");
 | ||
|       if (movmag.get_int("TWHS")==expmag &&
 | ||
|           (!fromdate.ok() || dmov >= fromdate) &&
 | ||
|             (!todate.ok() || dmov <= todate) )
 | ||
|       {
 | ||
|         TString codprod(movmag.get("TPROD"));
 | ||
|         real qta(movmag.get_real("TQTY"));
 | ||
|         TString com(movmag.get("TCOM"));
 | ||
|         nobolla = -1;
 | ||
|         if (movmag.get("TTYPE")=="T")
 | ||
|         {
 | ||
|           if (movmag.get("TRES")=="04" && com.len()==15)
 | ||
|             nobolla=atol(com.mid(7));
 | ||
|           else
 | ||
|             if (yesno_box("Includo il trasferimento del %s, %s per %s,\n '%s'",
 | ||
|                (const char *)dmov,(const char *)codprod,(const char *)qta.string(),(const char *)com))
 | ||
|               nobolla=lastbolla+1; // non so come filtrarla !!!
 | ||
|         }
 | ||
|         else if (movmag.get("TTYPE")=="00")
 | ||
|         {
 | ||
|           if (yesno_box("Includo il carico da terzi del %s, %s per %s,\n '%s'",
 | ||
|             (const char *)dmov,(const char *)codprod,(const char *)qta.string(),(const char *)com))
 | ||
|             nobolla=lastbolla+1; // non so come filtrarla !!!
 | ||
|         } 
 | ||
|         if (nobolla>lastbolla)
 | ||
|         {
 | ||
|           // evadi
 | ||
|           if (evasioni.is_key(codprod))
 | ||
|             qta+=(real&)evasioni.find(codprod);
 | ||
|           evasioni.add(codprod, qta, TRUE);
 | ||
|         }
 | ||
|       }
 | ||
|       movmag.next();
 | ||
|     }
 | ||
|     ok = evadi_orc(c, evasioni);
 | ||
|   }
 | ||
|     return FALSE;
 | ||
|   return ok;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void crea_mag3()
 | ||
| {
 | ||
|   TString codmag;TString desc;
 | ||
|   TTable mag("MAG");
 | ||
|   mag.put("CODTAB","SE1");
 | ||
|   mag.put("B0","X");
 | ||
|   mag.put("S0","Magazzino di Segrate (ex mag. 26,91 e 93)");
 | ||
|   force_write(mag);
 | ||
| 
 | ||
|   mag.put("CODTAB","TS1");
 | ||
|   mag.put("B0","X");
 | ||
|   mag.put("S0","Magazzino di Trieste (ex mag. 28 e 92)");
 | ||
|   force_write(mag);
 | ||
| 
 | ||
|   mag.put("CODTAB","PR1");
 | ||
|   mag.put("B0","X");
 | ||
|   mag.put("S0","Magazzino di Parma");
 | ||
|   force_write(mag);
 | ||
| 
 | ||
|   mag.put("CODTAB","PD1");
 | ||
|   mag.put("B0","X");
 | ||
|   mag.put("S0","Magazzino di Padova");
 | ||
|   force_write(mag);
 | ||
|   const char *codimp[] = {"SE","TS","PR","PD"};
 | ||
|   const char *descimp[] = {"Segrate","Trieste","Parma","Padova"};
 | ||
|   for (int t=0 ; t<99;t++)
 | ||
|     for (int i=0 ; i<4;i++)
 | ||
|     {
 | ||
|       mag.zero();
 | ||
|       long l=-1;
 | ||
|       if (t==0)
 | ||
|       {
 | ||
|         codmag.format("%s1PF", codimp[i]);
 | ||
|         desc = "Deposito prodotti finiti ";
 | ||
|         desc << descimp[i]; 
 | ||
|         l=0;
 | ||
|       }
 | ||
|       else
 | ||
|       if (i<2)
 | ||
|       {
 | ||
|         l = method2location(t);
 | ||
|         desc=descr_method(t);
 | ||
|         desc << " (ex locazione " << l << ")"; 
 | ||
|         codmag.format("%s1%02d", codimp[i], t);
 | ||
|       }
 | ||
|       if (l >= 0)
 | ||
|       {
 | ||
|         mag.put("CODTAB",codmag);
 | ||
|         mag.put("S0",desc);
 | ||
|         force_write(mag);
 | ||
|       }
 | ||
|     }
 | ||
| }
 | ||
| 
 | ||
| void crea_linee3()
 | ||
| {
 | ||
|   TTable lnp("LNP");
 | ||
|   TString8 code;
 | ||
|   TString8 codimp;
 | ||
|   for (int imp=0; imp<4; imp++)
 | ||
|   {
 | ||
|     switch (imp)
 | ||
|     {
 | ||
|       case 0: codimp ="SE"; break;
 | ||
|       case 1: codimp ="TS"; break;
 | ||
|       case 2: codimp ="PD"; break;
 | ||
|       case 3: codimp ="PR"; break;
 | ||
|     }
 | ||
|     for (int terz=1; terz<99; terz++)
 | ||
|     {
 | ||
|       code =format("X%02d",terz);
 | ||
|       code << codimp;
 | ||
|       lnp.put("CODTAB",code);
 | ||
|       if (lnp.read()==NOERR)
 | ||
|       {
 | ||
|         lnp.put("S0",format("%s (%s)",descr_method(terz), (const char *)codimp)) ;
 | ||
|         lnp.rewrite();
 | ||
|       }
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| bool find_wrongcycle()
 | ||
| {
 | ||
|   TIndwin iw(80, "Ricerca errori sui cicli di lavoro ...",FALSE,FALSE);
 | ||
|   bool some_done=FALSE;
 | ||
|   int err;
 | ||
|   long distno=1L;
 | ||
|   TString cod="";
 | ||
|   TLocalisamfile umart(LF_UMART);
 | ||
|   TRelation r(new TLocalisamfile(LF_RDIST));
 | ||
|   r.add(LF_DIST,"CODDIST==CODDIST");  
 | ||
|   r.add(LF_UMART,"CODART==CODDIST|UM=UM",2,LF_DIST);  
 | ||
|   r.add(LF_UMART,"CODART==CODDIST",1,LF_DIST,LF_UMART);  
 | ||
|   err = r.first();
 | ||
|   while (err == NOERR)  
 | ||
|   {
 | ||
|     if ((distno%TICK)==1)
 | ||
|     {
 | ||
|       iw.set_text(format("Ricerca errori riga n. %ld", distno));
 | ||
|       do_events();
 | ||
|     }
 | ||
|     distno++;
 | ||
|     if (r.lfile().get("TIPO")=="L" )
 | ||
|     {
 | ||
|       long expr=atol(r.lfile().get("EXPR")), newexpr;
 | ||
|       bool    ask=FALSE;
 | ||
|       if (r.update()==NOERR) 
 | ||
|       {
 | ||
|         long divisore=r.lfile(LF_UMART).get_long("FC");
 | ||
|         TString lav(r.lfile().get("CODCOMP"));
 | ||
|         if (expr < divisore && lav.left(5)!="ACQUA")
 | ||
|         {
 | ||
|           TString codice(r.lfile().get("CODDIST"));
 | ||
|           // caso sospetto
 | ||
|           TString4 main_um(r.lfile(-LF_UMART).get("UM"));
 | ||
|           int formato=lav.find(format("_X"));
 | ||
|           if (formato<0)
 | ||
|             formato=lav.find(format(".X"));
 | ||
|           if (formato<0)
 | ||
|             formato=lav.find(format(" X12"));
 | ||
|           newexpr=divisore;
 | ||
|           if (formato>0)
 | ||
|           {
 | ||
|             // lav in casse
 | ||
|             int pzxca=atoi(lav.sub(formato+2));
 | ||
|             if (pzxca>0)
 | ||
|             {
 | ||
|               if (main_um=="PZ")
 | ||
|                 newexpr/=atoi(lav.sub(formato+2));
 | ||
|               ask=TRUE;
 | ||
|             }
 | ||
|           }
 | ||
|           else
 | ||
|           {
 | ||
|             if (main_um=="PZ")
 | ||
|               ask=TRUE;
 | ||
|           }                                                           
 | ||
|           if (ask)
 | ||
|           {
 | ||
|             if (yesno_box("Il codice %s espresso in '%s'(=%ld %s) \ncontiene la lavorazione %s in quantita' %ld; \nsostituisco con %ld?", (const char *)codice, 
 | ||
|                 (const char *)r.lfile(LF_DIST).get("UM"),
 | ||
|                   divisore, 
 | ||
|                     (const char *)main_um,
 | ||
|                       (const char *)lav, expr,newexpr))
 | ||
|             {
 | ||
|               r.lfile().put("EXPR",newexpr);
 | ||
|               r.lfile().rewrite();
 | ||
|             }
 | ||
|           } else {
 | ||
|             message_box("Il codice %s espresso in '%s'(=%ld %s) \ncontiene la lavorazione %s in quantita' %ld", (const char *)codice, 
 | ||
|                 (const char *)r.lfile(LF_DIST).get("UM"),
 | ||
|                   divisore, 
 | ||
|                     (const char *)main_um,
 | ||
|                       (const char *)lav, expr,newexpr);
 | ||
|           }
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     err = r.next();
 | ||
|   }
 | ||
|   return TRUE;
 | ||
| }
 | ||
| class TMov_diff_inv : public TConfig 
 | ||
| {
 | ||
|   int   _nriga;
 | ||
|   TDate _al;
 | ||
|   bool  _use_giac_al;
 | ||
|   TArticolo_giacenza_data _art;
 | ||
| public:
 | ||
|   void set_header(const char *imp_filter);
 | ||
|   int righe () {return _nriga;}
 | ||
|   bool max_righe () {return _nriga > 99 ;}
 | ||
|   void locate_bpcs_stock(const TString &codice , int mag , const TString &location, TImport_file  &mag_bpcs, real &giac) ;
 | ||
|   int compare_stocks(TLocalisamfile &mag, const real & bpcs_stock, bool giac);
 | ||
|   TMov_diff_inv (int num, const char * al, bool giac_al);
 | ||
|   ~TMov_diff_inv() {}
 | ||
|   
 | ||
| } ;
 | ||
| 
 | ||
| TMov_diff_inv::TMov_diff_inv (int num, const char * al, bool giac_al) :
 | ||
|   TConfig (format("ND_%05d.ini",num)) , _nriga(0), _al(al),
 | ||
|        _use_giac_al(giac_al), _art()
 | ||
| {}
 | ||
| 
 | ||
| void TMov_diff_inv::locate_bpcs_stock(const TString &codice , int mag , const TString &location, TImport_file  &mag_bpcs, real & giac) 
 | ||
| {
 | ||
|   long diff = 0;
 | ||
| 
 | ||
| /*
 | ||
|   int direction = 0;
 | ||
|   do {
 | ||
|     diff = codice.compare(mag_bpcs.get("CODICE"));
 | ||
|     if (diff == 0)
 | ||
|       diff = mag - mag_bpcs.get_int("MAG");
 | ||
|     if (diff  == 0)
 | ||
|       diff = location.compare(mag_bpcs.get("LOC"));
 | ||
|     if (diff > 0 && direction != -1)
 | ||
|     {
 | ||
|       direction = +1;
 | ||
|       if (mag_bpcs.next()!=NOERR)
 | ||
|         direction = 0;
 | ||
|     }
 | ||
|     if (diff < 0 && direction != 1)
 | ||
|     {
 | ||
|       direction = -1;
 | ||
|       if (mag_bpcs.prev()!=NOERR)
 | ||
|         direction = 0;
 | ||
|     }
 | ||
|   } while (diff*direction>0 && direction != 0 );
 | ||
| */
 | ||
|   mag_bpcs.zero();
 | ||
|   mag_bpcs.put("MAG", format("%d",mag));
 | ||
|   mag_bpcs.put("LOC", location);
 | ||
|   mag_bpcs.put("CODICE", codice);
 | ||
|   diff = mag_bpcs.read(_isequal);
 | ||
|   
 | ||
|   if (diff != 0)
 | ||
|     giac = ZERO;
 | ||
|   else
 | ||
|     giac = mag_bpcs.get_real("QTY");
 | ||
| }
 | ||
| 
 | ||
| int TMov_diff_inv::compare_stocks(TLocalisamfile &mag, const real & val_bpcs, bool giac)
 | ||
| {
 | ||
|   if (!giac)
 | ||
|     return _nriga;
 | ||
| /*
 | ||
|   TRectype newmag = mag.curr();
 | ||
|   if (mag.read() != NOERR)
 | ||
|     mag.curr() = newmag;
 | ||
|   real val(mag.get_real("GIAC"));
 | ||
|   if (!giac)
 | ||
|     val = (mag.get_real("VEN"));
 | ||
|   real diff = (val_bpcs - val);
 | ||
|   diff.round(3); 
 | ||
| */
 | ||
|   real val;
 | ||
|   if (_use_giac_al)
 | ||
|   {
 | ||
|     _art.read(mag.get("CODART"));
 | ||
|     TString16 codmag(mag.get("CODMAG"));
 | ||
|     TString16 annoes(mag.get("ANNOES"));
 | ||
|     _art.al(_al, codmag);
 | ||
|     const int i = _art.find_mag(annoes, codmag);
 | ||
|     TRectype & mag1 = _art.mag(annoes)[i];
 | ||
|     val = mag1.get_real("GIAC");
 | ||
|     if (!giac)
 | ||
|       val = (mag1.get_real("VEN"));
 | ||
|   }
 | ||
|   else
 | ||
|   {
 | ||
|     TRectype newmag = mag.curr();
 | ||
|     if (mag.read() != NOERR)
 | ||
|     mag.curr() = newmag;
 | ||
|     val = mag.get_real("GIAC");
 | ||
|     if (!giac)
 | ||
|       val = (mag.get_real("VEN"));
 | ||
|   }
 | ||
|   real diff = (val_bpcs - val);
 | ||
|   diff.round(3);
 | ||
| 
 | ||
| 
 | ||
|   const real piotta = "900000.0";
 | ||
|   while (diff >= 0.001 || diff <= -0.001)
 | ||
|   {
 | ||
|     real newqtadoc = diff;
 | ||
|     if (diff>piotta)
 | ||
|       newqtadoc = piotta;
 | ||
|     if (diff<-piotta)
 | ||
|       newqtadoc = -piotta;
 | ||
|     set_paragraph(format("34,%d", ++_nriga));
 | ||
|     set("TIPORIGA", "01"); 
 | ||
|     set("CODART", mag.get("CODART")); 
 | ||
|     set("CODARTMAG", mag.get("CODART")); 
 | ||
|     set("DESCR", cache().get(LF_ANAMAG,mag.get("CODART")).get("DESCR")); 
 | ||
|     set("CODMAG", mag.get("CODMAG"));
 | ||
|     TToken_string um_key(mag.get("CODART"));
 | ||
|     um_key.add("1");
 | ||
|     set("UMQTA", cache().get(LF_UMART,um_key).get("UM")); 
 | ||
|     set("QTA", newqtadoc.string()); 
 | ||
|     set("CODCAUS", giac ? "CAR" : ""); 
 | ||
|     diff = diff - newqtadoc;
 | ||
|   }
 | ||
|   return _nriga;
 | ||
| }
 | ||
| 
 | ||
| void  TMov_diff_inv::set_header(const char * imp_filter)
 | ||
| {
 | ||
| //  TDate today(TODAY);
 | ||
|   set_paragraph("Transaction");
 | ||
|   set("Action","INSERT");
 | ||
|   set("Mode","AUTO");
 | ||
|   set_paragraph("33");
 | ||
|   TString8 codimp = imp_filter ;
 | ||
|   codimp << "DI";
 | ||
|   set("CODNUM",codimp);
 | ||
|   set("CAUSMAG","");
 | ||
|   set("NOTE","\"Differenze inventariali rilevate per confronto con gli archivi di BPCS\"");
 | ||
|   //set("DATADOC",today.string());
 | ||
|   set("DATADOC",_al.string());
 | ||
| }
 | ||
| 
 | ||
| void sinchro_stock(const TMask & m, const char * imp_filter)
 | ||
| {
 | ||
|   if (!yesno_box(format("Confermi l'allineamento giacenze per %s dal file %s?", imp_filter, BPCS_STOCK)))
 | ||
|     return ;
 | ||
|   const bool launch_ve0 = yesno_box("Devo registrare immediatamente i documenti?");
 | ||
|   TDate day(TODAY);
 | ||
|   TString16 data(m.get(S_GIAC_AL));
 | ||
|   if (data.not_empty())
 | ||
|       day = data;
 | ||
|   const bool use_al = m.get_bool(S_USE_AL);
 | ||
|   TIndwin info(60,format("Allineamento giacenze per %s...",imp_filter),FALSE,FALSE);
 | ||
|   TImport_file mag_bpcs(m.get(F_PATH),BPCS_STOCK);
 | ||
|   TLocalisamfile mag(LF_MAG);
 | ||
|   TLocalisamfile anamag(LF_ANAMAG);
 | ||
|   TString codart,codmag, coddep, codimp;
 | ||
|   TString codlocation;
 | ||
|   int nummag, movimenti = 0;
 | ||
|   bool ok;
 | ||
| 
 | ||
|   delete_files("ND_*.ini");
 | ||
|   TMov_diff_inv *action;
 | ||
|   action = new TMov_diff_inv(movimenti++,day, use_al);
 | ||
|   action->set_header(imp_filter);
 | ||
| 
 | ||
|   // Crea i mag di eurocampo eventualemnte mancanti
 | ||
|   mag.setkey(2);
 | ||
|   ok = mag_bpcs.first()==NOERR;
 | ||
|   while (ok)
 | ||
|   {
 | ||
|     codart = mag_bpcs.get("CODICE");
 | ||
|     nummag = mag_bpcs.get_int("MAG");
 | ||
|     num_mag2main_imp(nummag, codimp);
 | ||
|     if (codimp == imp_filter)
 | ||
|     { 
 | ||
|       TString16 loc = mag_bpcs.get("LOC");
 | ||
|       imploc2codmagdep(codimp, loc, codmag);
 | ||
|       //num_mag2cod_imp(nummag, codmag);
 | ||
|       mag.put("ANNOES", day.year());
 | ||
|       mag.put("CODART", codart);
 | ||
|       mag.put("CODMAG", codmag);
 | ||
|       if (mag.read()!=NOERR)
 | ||
|       {
 | ||
|         anamag.put("CODART", codart);
 | ||
|         int err=NOERR;
 | ||
|         bool skip = FALSE;
 | ||
|         while (TRUE) 
 | ||
|         {
 | ||
|           err = anamag.read(_isequal, _testandlock);
 | ||
|           if (err == NOERR)
 | ||
|             break;
 | ||
|           if (err == _islocked)
 | ||
|           {
 | ||
|             if (yesno_box("Articolo %s bloccato: termina allineamento ?", (const char * )codart))
 | ||
|               return ;
 | ||
|             if (yesno_box("Tralascio l'articolo %s?", (const char * )codart))
 | ||
|               skip = TRUE ;
 | ||
|           }
 | ||
|           if (err != _islocked)
 | ||
|           {
 | ||
|             if (yesno_box("Articolo %s sconosciuto: termina allineamento ?", (const char * )codart))
 | ||
|               return ;
 | ||
|             skip = TRUE ;
 | ||
|             inserisci_articolo(codart,mag_bpcs.get("UM"));
 | ||
|           }
 | ||
|         }
 | ||
|         if (!skip)
 | ||
|         {
 | ||
|           int nriga = 0;
 | ||
|           mag.put("ANNOES", day.year());
 | ||
|           mag.put("CODART", codart);
 | ||
|           mag.put("NRIGA", ++nriga);
 | ||
|           mag.setkey(1);
 | ||
|           while (mag.read()==NOERR)
 | ||
|             mag.put("NRIGA", ++nriga);
 | ||
|           mag.zero(' ');
 | ||
|           mag.put("ANNOES", day.year());
 | ||
|           mag.put("CODART", codart);
 | ||
|           mag.put("NRIGA", nriga);
 | ||
|           mag.put("CODMAG", codmag);
 | ||
|           mag.write();
 | ||
|           mag.setkey(2);
 | ||
|   
 | ||
|           anamag.read(_isequal, _unlock);
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     ok = mag_bpcs.next()==NOERR;
 | ||
|   }
 | ||
| 
 | ||
|   real bpcsstock;
 | ||
|   mag_bpcs.first();
 | ||
|   mag.setkey(1);
 | ||
|   mag.zero();
 | ||
|   mag.put("ANNOES", day.year());
 | ||
|   ok = mag.read(_isgteq)==NOERR;
 | ||
|   // magazzino Eurocampo vs mag BPCS
 | ||
|   while (ok)
 | ||
|   {
 | ||
|     codart = mag.get("CODART");
 | ||
|     codmag = mag.get("CODMAG");
 | ||
|     codimp = codmag.left(2);
 | ||
|     nummag = cod_mag2num_mag(codmag);
 | ||
|     coddep = codmag.sub(3);
 | ||
|     codmag.cut(3);
 | ||
| 
 | ||
|     anamag.put("CODART", codart);
 | ||
|     int err = NOERR;
 | ||
|     bool skip = FALSE;    
 | ||
|     while (TRUE)
 | ||
|     {
 | ||
|       err = anamag.read(_isequal, _testandlock);
 | ||
|       if (err == NOERR)
 | ||
|         break;
 | ||
|       if (err == _islocked)
 | ||
|       {
 | ||
|         if (yesno_box("Articolo %s bloccato: termina allineamento ?", (const char * )codart))
 | ||
|           break ;
 | ||
|         if (yesno_box("Tralascio l'articolo %s?", (const char * )codart))
 | ||
|           skip = TRUE ;
 | ||
|       }
 | ||
|       if (err != _islocked)
 | ||
|       {
 | ||
|         if (!noyes_box("Articolo %s sconosciuto: termina allineamento ?", (const char * )codart))
 | ||
|           skip = TRUE ;
 | ||
|         inserisci_articolo(codart,mag_bpcs.get("UM"));
 | ||
|         break ;
 | ||
|       }
 | ||
|     }
 | ||
|     if (!skip)
 | ||
|     {
 | ||
|       if (err != NOERR)
 | ||
|         break;
 | ||
|       if ((((codimp == "SE1" || codimp == "TS1") && coddep == "07") || codimp == imp_filter ) &&  nummag>0)
 | ||
|       {
 | ||
|         coddep2location(codmag, coddep, codlocation, nummag);
 | ||
|         if (codmag == "SE1" && coddep == "07")
 | ||
|           nummag = 91;
 | ||
|         if (codmag == "TS1" && coddep == "07")
 | ||
|           nummag = 92;
 | ||
|         action->locate_bpcs_stock(codart, nummag, codlocation, mag_bpcs, bpcsstock);
 | ||
|         action->compare_stocks(mag, bpcsstock, TRUE);
 | ||
|         /*if (FALSE && nummag < 30) // elimina 
 | ||
|         {
 | ||
|           action->locate_bpcs_stock( codart, nummag-1 ,0 , mag_bpcs, bpcsstock);
 | ||
|           action->compare_stocks(mag, bpcsstock, FALSE);
 | ||
|         }*/
 | ||
|       }
 | ||
|       if (codmag == "SE3" || codmag == "TS3" /*|| coddep == "07"*/)
 | ||
|       {
 | ||
|         // elimina vecchimagazzini SE3/TS3 e la vecchia codifica del magazzino di padova/parma
 | ||
|         bpcsstock = ZERO;
 | ||
|         action->compare_stocks(mag, bpcsstock, TRUE);
 | ||
|       }
 | ||
|       if (action->max_righe())
 | ||
|       {
 | ||
|         TString80 filename(action->name());
 | ||
|         delete action;
 | ||
|         if (launch_ve0)
 | ||
|         {
 | ||
|           TExternal_app gestdoc(format("ve0.exe -1 -i%s",(const char *)filename));
 | ||
|           gestdoc.run();
 | ||
|         }
 | ||
|         action = new TMov_diff_inv(movimenti++, day, use_al);
 | ||
|         action->set_header(imp_filter);
 | ||
|       }
 | ||
|     }
 | ||
|     
 | ||
|     ok = mag.next()==NOERR;
 | ||
| 
 | ||
|     anamag.read(_isequal, _unlock);
 | ||
|   }
 | ||
| 
 | ||
|   if (action->righe())
 | ||
|   {
 | ||
|     TString80 filename(action->name());
 | ||
|     delete action;
 | ||
|     if (launch_ve0)
 | ||
|     {
 | ||
|       TExternal_app gestdoc(format("ve0.exe -1 -i%s",(const char *)filename));
 | ||
|       gestdoc.run();
 | ||
|     }
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void unlink_numdoc(const char *codnum, int anno)
 | ||
| {
 | ||
|   TRelation *r = new TRelation(LF_DOC);
 | ||
|   r->add(LF_RIGHEDOC,"PROVV==PROVV|ANNO==ANNO|CODNUM==CODNUM|NDOC==NDOC");
 | ||
|   TCursor c(r);
 | ||
|   TRectype from(LF_DOC),to(LF_DOC);
 | ||
|   from.put("PROVV","D");
 | ||
|   from.put("ANNO",anno);
 | ||
|   from.put("CODNUM",codnum);
 | ||
|   to = from;
 | ||
|   c.setregion(from,to);
 | ||
|   const long items=c.items();
 | ||
|   TProgind info(items,format("Scollegamento documenti %s anno %d...",codnum,anno),FALSE,TRUE);
 | ||
|   for (long i=items-1; i>=0 ; i--)
 | ||
|   {
 | ||
|     c = i;
 | ||
|     info.addstatus(1);
 | ||
|     TLocalisamfile &doc=r->lfile();
 | ||
|     TLocalisamfile &rdoc=r->lfile(LF_RIGHEDOC);
 | ||
|     if (doc.get_long("MOVMAG")!=0L)
 | ||
|     {
 | ||
|       doc.put("MOVMAG",0);
 | ||
|       doc.rewrite();
 | ||
|     }
 | ||
|     if (r->is_first_match(LF_RIGHEDOC))
 | ||
|       do {
 | ||
|         if (rdoc.get_long("MOVMAG")!=0L)
 | ||
|         {
 | ||
|           rdoc.put("MOVMAG",0);
 | ||
|           rdoc.rewrite();
 | ||
|         }
 | ||
|       } while (r->next_match(LF_RIGHEDOC));
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void unlink_docs()
 | ||
| {
 | ||
|   unlink_numdoc("SEBA",1998);
 | ||
|   unlink_numdoc("SEBA",1999);
 | ||
|   unlink_numdoc("SEBE",1998);
 | ||
|   unlink_numdoc("SEBE",1999);
 | ||
|   unlink_numdoc("SEBP",1998);
 | ||
|   unlink_numdoc("SEBP",1999);
 | ||
|   unlink_numdoc("SEBT",1998);
 | ||
|   unlink_numdoc("SEBT",1999);
 | ||
|   unlink_numdoc("SEBU",1998);
 | ||
|   unlink_numdoc("SEBU",1999);
 | ||
|   unlink_numdoc("SEBV",1998);
 | ||
|   unlink_numdoc("SEBV",1999);
 | ||
|   unlink_numdoc("SEDI",1998);
 | ||
|   unlink_numdoc("SEDI",1999);
 | ||
|   unlink_numdoc("SEFA",1998);
 | ||
|   unlink_numdoc("SEFA",1999);
 | ||
|   unlink_numdoc("SEMM",1998);
 | ||
|   unlink_numdoc("SEMM",1999);
 | ||
|   unlink_numdoc("SEMP",1998);
 | ||
|   unlink_numdoc("SEMP",1999);
 | ||
|   unlink_numdoc("SEOC",1998);
 | ||
|   unlink_numdoc("SEOC",1999);
 | ||
|   unlink_numdoc("SEOF",1998);
 | ||
|   unlink_numdoc("SEOF",1999);
 | ||
|   unlink_numdoc("SEOP",1998);
 | ||
|   unlink_numdoc("SEOP",1999);
 | ||
|   unlink_numdoc("SERF",1998);
 | ||
|   unlink_numdoc("SERF",1999);
 | ||
| }
 | ||
| 
 | ||
| void kill_blank_mag(const TMask & m, const char * codmag)
 | ||
| {
 | ||
|   TLocalisamfile mag(LF_MAG),mag2(LF_MAG);
 | ||
|   mag2.setkey(2);
 | ||
|   TString codart;
 | ||
|   int anno;
 | ||
|   int err = mag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     anno = mag.get_int("ANNOES");
 | ||
|     codart = mag.get("CODART");
 | ||
|     mag2.put("ANNOES",anno);
 | ||
|     mag2.put("CODMAG",codmag);
 | ||
|     mag2.put("CODART",codart);
 | ||
|     if (mag2.read()==NOERR)
 | ||
|     {
 | ||
|     }
 | ||
|     else
 | ||
|     {
 | ||
|     }
 | ||
|     err= mag.next();
 | ||
|   }
 | ||
|   
 | ||
| }
 | ||
| 
 | ||
| bool unify_magcode(const char * field, TLocalisamfile & file, bool only3=FALSE)
 | ||
| {
 | ||
|   TString codmag = file.get(field);
 | ||
|   if (codmag.blank())
 | ||
|     return FALSE;
 | ||
|   int coddep = atoi(codmag.sub(3));
 | ||
|   if (coddep == 7)
 | ||
|   {
 | ||
|     TString codmagazz = codmag.left(3);
 | ||
|     if (codmagazz == "SE1")
 | ||
|       codmag = "PR1";
 | ||
|     if (codmagazz == "TS1")
 | ||
|       codmag = "PD1";
 | ||
|     codmag.overwrite("PF",3); // deposito produzione finiti
 | ||
|   }
 | ||
|   else 
 | ||
|   if (!only3 && codmag[2]=='1' && codmag[3]=='\0')
 | ||
|   {
 | ||
|     codmag.overwrite("PF",3); // deposito produzione finiti
 | ||
|   }
 | ||
|   else if (codmag[2]=='3'&& codmag[3]!='\0')
 | ||
|   {
 | ||
|     codmag[2]='1';
 | ||
|   } else if (codmag=="   PF")
 | ||
|   {
 | ||
|     codmag="";
 | ||
|   } else
 | ||
|     return FALSE;
 | ||
|   if (codmag==file.get(field))
 | ||
|     return FALSE;
 | ||
| 
 | ||
|   file.put(field,codmag);
 | ||
|   int err;
 | ||
|   if ((err=file.rewrite())!=NOERR)
 | ||
|     err = file.write();
 | ||
|   if (err!= NOERR)
 | ||
|     message_box("Impossibile scrivere il record %d del file %d",file.recno(), file.num());
 | ||
|   do_events();
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| void unify_mags_reset_bar(TProgind & pi, const char * msg2, long max)
 | ||
| {
 | ||
|   const char * msg = "Unificazione magazzini interni e terzisti: ";
 | ||
|   pi.set_text(format("%s%s",msg,msg2));
 | ||
|   pi.setstatus(0);
 | ||
|   pi.setmax(max ? max : 1);
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| 
 | ||
| void check_movmags(const TMask & m)
 | ||
| {
 | ||
|   TString codmag;
 | ||
|   int err;
 | ||
|   TLocalisamfile mag(LF_MAG), 
 | ||
|     rmovmag(LF_RMOVMAG), movmag(LF_MOVMAG);
 | ||
|   TProgind info(80,"",FALSE,TRUE);
 | ||
|   TLocalisamfile doc(LF_DOC),rdoc(LF_RIGHEDOC);
 | ||
|   TString8 caumag;
 | ||
|   TString16 codnum;
 | ||
|   long ndoc;
 | ||
|   int anno;
 | ||
|   bool remove;
 | ||
|   bool rewrite;
 | ||
| 
 | ||
|   unify_mags_reset_bar(info, "Correzione stringa di rif.doc. sui mov mag", movmag.items());
 | ||
|   err=movmag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     TString descr=movmag.get("DESCR");
 | ||
|     rewrite = FALSE;
 | ||
|     if (descr.left(5)==" n.ro")
 | ||
|     {
 | ||
|       codnum = movmag.get("CODNUM");
 | ||
|       anno = movmag.get_int("ANNODOC");
 | ||
|       ndoc = movmag.get_long("NUMDOC");
 | ||
|       if (ndoc)
 | ||
|       {
 | ||
|         doc.put(DOC_PROVV,"D") ;
 | ||
|         doc.put(DOC_CODNUM,codnum);
 | ||
|         doc.put(DOC_ANNO,anno);
 | ||
|         doc.put(DOC_NDOC,ndoc);
 | ||
|         err = doc.read();
 | ||
|         if (err == NOERR)
 | ||
|         {
 | ||
|           descr = codnum;
 | ||
|           descr << " n. " << ndoc <<  " del " << doc.get("DATADOC");
 | ||
|           rewrite = TRUE;
 | ||
|         }
 | ||
|       } 
 | ||
|     } 
 | ||
|     if (rewrite)
 | ||
|     {
 | ||
|       movmag.put("DESCR",descr);
 | ||
|       while ((err=movmag.rewrite())!=NOERR)
 | ||
|         yesno_box("Errore %d nella scrittura del movimento %ld.\nRiprovo ?",err, rdoc.get_long("NUMREG") );
 | ||
|     }
 | ||
|     info.addstatus(1);
 | ||
|     err = movmag.next();
 | ||
|   } 
 | ||
| 
 | ||
|   unify_mags_reset_bar(info, "Correzione date reg e comp errate", movmag.items());
 | ||
|   err=movmag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     TDate datareg=movmag.get_date("DATAREG");
 | ||
|     TDate datacomp=movmag.get_date("DATACOMP");
 | ||
|     rewrite = FALSE;
 | ||
|     if (!datacomp.ok())
 | ||
|     {
 | ||
|       datacomp=datareg;
 | ||
|       rewrite = datacomp.ok();
 | ||
|     }
 | ||
|     if (!datacomp.ok())
 | ||
|     {
 | ||
|       codnum = movmag.get("CODNUM");
 | ||
|       anno = movmag.get_int("ANNODOC");
 | ||
|       ndoc = movmag.get_long("NUMDOC");
 | ||
|       if (ndoc)
 | ||
|       {
 | ||
|         doc.put(DOC_PROVV,"D") ;
 | ||
|         doc.put(DOC_CODNUM,codnum);
 | ||
|         doc.put(DOC_ANNO,anno);
 | ||
|         doc.put(DOC_NDOC,ndoc);
 | ||
|         err = doc.read();
 | ||
|         if (err == NOERR)
 | ||
|         {
 | ||
|           datacomp = doc.get("DATADOC");
 | ||
|           rewrite = TRUE;
 | ||
|         }
 | ||
|       } 
 | ||
|     } 
 | ||
|     if (!datacomp.ok())
 | ||
|       warning_box("Data di competenza non valida sul movimento di magazzino %ld", movmag.get_long("NUMREG"));
 | ||
|     else
 | ||
|       if (rewrite)
 | ||
|       {
 | ||
|         movmag.put("DATACOMP",datacomp);
 | ||
|         movmag.put("DATAREG",datacomp);
 | ||
|         while ((err=movmag.rewrite())!=NOERR)
 | ||
|           yesno_box("Errore %d nella scrittura del movimento %ld.\nRiprovo ?",err, rdoc.get_long("NUMREG") );
 | ||
|       }
 | ||
|     info.addstatus(1);
 | ||
|     err = movmag.next();
 | ||
|   } 
 | ||
| 
 | ||
|   unify_mags_reset_bar(info, "Distruzione righe mov.mag. non da documento", movmag.items());
 | ||
|   err=movmag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     codnum = movmag.get("CODNUM");
 | ||
|     anno = movmag.get_int("ANNODOC");
 | ||
|     ndoc = movmag.get_long("NUMDOC");
 | ||
|     doc.put(DOC_PROVV,"D") ;
 | ||
|     doc.put(DOC_CODNUM,codnum);
 | ||
|     doc.put(DOC_ANNO,anno);
 | ||
|     doc.put(DOC_NDOC,ndoc);
 | ||
|     remove = FALSE;
 | ||
|     err = doc.read();
 | ||
|     if (err == _iskeynotfound || err ==_iseof)
 | ||
|       remove = TRUE;
 | ||
|     else
 | ||
|       remove = doc.get(DOC_CAUSMAG).blank();
 | ||
|     if (!remove)
 | ||
|     {
 | ||
|       remove = movmag.get("NUMREG")!=doc.get("MOVMAG");
 | ||
|       if (remove)
 | ||
|       {
 | ||
|         doc.put("MOVMAG",0);
 | ||
|         while ((err=doc.rewrite())!=NOERR)
 | ||
|           yesno_box("Errore %d nella scrittura del documento %s %d %ld.\nRiprovo ?",err, (const char *)rdoc.get(RDOC_CODNUM),rdoc.get_int(RDOC_ANNO),rdoc.get_long(RDOC_NDOC) );
 | ||
|       }
 | ||
|     }
 | ||
|     caumag=doc.get(DOC_CAUSMAG);
 | ||
|     if (remove)
 | ||
|       movmag.remove();
 | ||
|     info.addstatus(1);
 | ||
|     err = movmag.next();
 | ||
|   } 
 | ||
| 
 | ||
|   unify_mags_reset_bar(info, "Distruzione righe mov.mag. orfane", rmovmag.items());
 | ||
|   err=rmovmag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     movmag.put("NUMREG",rmovmag.get("NUMREG"));
 | ||
|     err = movmag.read();
 | ||
|     if (err == _iskeynotfound || err ==_iseof)
 | ||
|       rmovmag.remove();
 | ||
|     info.addstatus(1);
 | ||
|     err = rmovmag.next();
 | ||
|   } 
 | ||
| 
 | ||
|   return;
 | ||
| }
 | ||
| 
 | ||
| void unify_mags(const TMask & m)
 | ||
| {
 | ||
|   TTable impianti("IMP"), linee("LNP"),tabmag("MAG"),caumag("%CAU");
 | ||
|   TString codmag;
 | ||
|   int err;
 | ||
|   TLocalisamfile mag(LF_MAG), 
 | ||
|     rmovmag(LF_RMOVMAG), movmag(LF_MOVMAG);
 | ||
|   TProgind info(80,"",TRUE,TRUE);
 | ||
| 
 | ||
|   unify_mags_reset_bar(info, "tabella causali mag", caumag.items());
 | ||
|   err = caumag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     unify_magcode("S10", caumag);
 | ||
|     err = caumag.next();
 | ||
|     info.addstatus(1);
 | ||
|     if (info.iscancelled())
 | ||
|       return;
 | ||
|   }
 | ||
|   message_box("Modificare a mano la tabella magazzini");
 | ||
|   unify_mags_reset_bar(info, "tabella impianti", impianti.items());
 | ||
|   impianti.setkey(2);
 | ||
|   err = impianti.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     unify_magcode("S7", impianti);
 | ||
|     unify_magcode("S8", impianti);
 | ||
|     err = impianti.next();
 | ||
|     info.addstatus(1);
 | ||
|     if (info.iscancelled())
 | ||
|       return;
 | ||
|   }
 | ||
|   unify_mags_reset_bar(info, "tabella linee di produzione", linee.items());
 | ||
|   linee.setkey(2);
 | ||
|   err = linee.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     unify_magcode("S7", linee);
 | ||
|     unify_magcode("S8", linee);
 | ||
|     err = linee.next();
 | ||
|     info.addstatus(1);
 | ||
|     if (info.iscancelled())
 | ||
|       return;
 | ||
|   }
 | ||
|   unify_mags_reset_bar(info, "giacenze", mag.items());
 | ||
|   err = mag.first();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     unify_magcode("CODMAG", mag);
 | ||
|     err = mag.next();
 | ||
|     info.addstatus(1);
 | ||
|     if (info.iscancelled())
 | ||
|       return;
 | ||
|   } 
 | ||
|   
 | ||
|   unify_mags_reset_bar(info, "movimenti di magazzino", rmovmag.items());
 | ||
|   err = rmovmag.first();
 | ||
|   movmag.zero();
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     unify_magcode("CODMAG", rmovmag);
 | ||
|     err = rmovmag.next();
 | ||
|     info.addstatus(1);
 | ||
|     if (info.iscancelled())
 | ||
|       return;
 | ||
|   }
 | ||
|   TLocalisamfile doc(LF_DOC),rdoc(LF_RIGHEDOC);
 | ||
|   unify_mags_reset_bar(info, "righe documenti", rdoc.items());
 | ||
|   err = rdoc.first();
 | ||
|   doc.zero();
 | ||
|   TString16 codnum;
 | ||
|   long ndoc;
 | ||
|   int anno;
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     codnum = rdoc.get(RDOC_CODNUM);
 | ||
|     anno = rdoc.get_int(RDOC_ANNO);
 | ||
|     ndoc = rdoc.get_long(RDOC_NDOC);
 | ||
|     do {
 | ||
|       if (err != NOERR
 | ||
|         || doc.get(DOC_CODNUM)!=codnum 
 | ||
|         || doc.get_int(DOC_ANNO)!=anno 
 | ||
|         || doc.get_long(DOC_NDOC)!=ndoc)
 | ||
|       {
 | ||
|         doc.put(DOC_PROVV,"D") ;
 | ||
|         doc.put(DOC_CODNUM,codnum);
 | ||
|         doc.put(DOC_ANNO,anno);
 | ||
|         doc.put(DOC_NDOC,ndoc);
 | ||
|         err = doc.read();
 | ||
|       }
 | ||
|     } while (err != NOERR && yesno_box("Errore nella lettura del documento %s %d %ld.\nRiprovo ?",(const char *)rdoc.get(RDOC_CODNUM),rdoc.get_int(RDOC_ANNO),rdoc.get_long(RDOC_NDOC) ));
 | ||
|     if (err == NOERR)
 | ||
|     {
 | ||
|       unify_magcode("CODMAG", rdoc);
 | ||
|       unify_magcode("CODMAGC", rdoc);
 | ||
|     }
 | ||
|     err = rdoc.next();
 | ||
|     info.addstatus(1);
 | ||
|     if (info.iscancelled())
 | ||
|       return;
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| void checkexplosions(const TMask & m)
 | ||
| {
 | ||
|   TLocalisamfile movmag(LF_MOVMAG), 
 | ||
|     rmovmag(LF_RMOVMAG);
 | ||
|   TArray boom;
 | ||
|   TAssoc_array  movs, arts;
 | ||
|   TDistinta_tree search;
 | ||
|   TString desc,codcaus,key, grmerc;
 | ||
|   TLocalisamfile anamag(LF_ANAMAG);
 | ||
|   int err = rmovmag.last();
 | ||
|   TProgind info(rmovmag.items(),"Controllo scarichi errati da esplosioni distinte",FALSE,TRUE);
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     movmag.put("ANNOES","1999");
 | ||
|     movmag.put("NUMREG",rmovmag.get("NUMREG"));
 | ||
|     movmag.read();
 | ||
|     desc = movmag.get("DESCR");
 | ||
|     codcaus = rmovmag.get("CAUS");
 | ||
|     if (codcaus.blank())
 | ||
|       codcaus = movmag.get("CODCAUS");
 | ||
| 
 | ||
|     key = rmovmag.get("CODART");
 | ||
|     anamag.put("CODART",key);
 | ||
|     if (!arts.is_key(key))
 | ||
|     {
 | ||
|       if (anamag.read()!=NOERR)
 | ||
|       {
 | ||
|           message_box("Articolo '%s' mancante ",
 | ||
|             (const char *)rmovmag.get("CODART"));
 | ||
|           arts.add(key, grmerc);
 | ||
|           grmerc = "~";
 | ||
|       }
 | ||
|       else
 | ||
|         grmerc = anamag.get("GRMERC");
 | ||
|     }
 | ||
|       else
 | ||
|         grmerc = (TString &)arts[key];
 | ||
|     if (grmerc[0] == '~' || codcaus.left(3)=="SCC")
 | ||
|     {
 | ||
|       if (grmerc[0] == '~' || grmerc[0]=='F')
 | ||
|       {
 | ||
|         if (!arts.is_key(key))
 | ||
|         {
 | ||
|           if (search.set_root(key))
 | ||
|           {
 | ||
|             search.explode(boom,FALSE, RAGGR_EXP_NONE, 1, "A");
 | ||
|             if (boom.items() <= 0)
 | ||
|               message_box("Distinta di %s priva di componenti", (const char *)key);
 | ||
|           } else
 | ||
|             message_box("Distinta di %s mancante ", (const char *)key);
 | ||
|           arts.add(key, grmerc);
 | ||
|         }
 | ||
|         key = format("%ld",rmovmag.get_long("NUMREG"));
 | ||
|         if (!movs.is_key(key))
 | ||
|         {
 | ||
|           message_box("Errore nel movimento %ld (%s)",
 | ||
|             rmovmag.get_long("NUMREG"),
 | ||
|             (const char *)desc  );
 | ||
|           movs.add(key,key);
 | ||
|         }
 | ||
|       }
 | ||
|     }    
 | ||
|     err = rmovmag.prev();
 | ||
|     info.addstatus(1);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| // rimuove le unit<69> di misura errate
 | ||
| void remove_wrong_um(const TMask & m)
 | ||
| {
 | ||
|   const bool vars = noyes_box("Vuoi eliminare tutte le unit<69> di misura delle varianti di produzione?");
 | ||
|   const bool var3 = vars ? 1 : yesno_box("Vuoi eliminare le unit<69> di misura degli articoli tipo 'xxxxx__SE3xx' o 'xxxx__TS3xx'?");
 | ||
|   TLocalisamfile umart(LF_UMART);
 | ||
|   int err = umart.last();
 | ||
|   TProgind info(umart.items(),"Eliminazione unit<69> di misura",FALSE,TRUE);
 | ||
|   TString code;
 | ||
| 
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     code = umart.get("CODART");
 | ||
|     if ( (var3 && (code.find("__SE3")>=0 ||code.find("__TS3")>=0)) 
 | ||
|       || (vars && code.find("__")>=3))
 | ||
|       umart.remove();
 | ||
|     err = umart.prev();
 | ||
|     info.addstatus(1);
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| bool sum_giacfield(TRectype & dest, const TRectype & source, const char * filedname)
 | ||
| {
 | ||
|   dest.put(filedname, dest.get_real(filedname)+source.get_real(filedname));
 | ||
|   return !source.get_real(filedname).is_zero();
 | ||
| }
 | ||
| 
 | ||
| bool sum_giacrecord(TRectype & dest, const TRectype & source)
 | ||
| {
 | ||
|   bool some=FALSE;
 | ||
|   some|=sum_giacfield(dest, source, "RIM");
 | ||
|   some|=sum_giacfield(dest, source, "VALRIM");
 | ||
|   some|=sum_giacfield(dest, source, "ACQ");
 | ||
|   some|=sum_giacfield(dest, source, "VALACQ");
 | ||
|   some|=sum_giacfield(dest, source, "ENT");
 | ||
|   some|=sum_giacfield(dest, source, "VALENT");
 | ||
|   some|=sum_giacfield(dest, source, "VEN");
 | ||
|   some|=sum_giacfield(dest, source, "VALVEN");
 | ||
|   some|=sum_giacfield(dest, source, "USC");
 | ||
|   some|=sum_giacfield(dest, source, "VALUSC");
 | ||
|   some|=sum_giacfield(dest, source, "GIAC");
 | ||
|   some|=sum_giacfield(dest, source, "ORDF");
 | ||
|   some|=sum_giacfield(dest, source, "VALORDF");
 | ||
|   some|=sum_giacfield(dest, source, "ORDC");
 | ||
|   some|=sum_giacfield(dest, source, "VALORDC");
 | ||
|   some|=sum_giacfield(dest, source, "INCL");
 | ||
|   some|=sum_giacfield(dest, source, "ACL");
 | ||
|   some|=sum_giacfield(dest, source, "PRODCOMP");
 | ||
|   some|=sum_giacfield(dest, source, "PRODFIN");
 | ||
|   some|=sum_giacfield(dest, source, "NLABEL");
 | ||
|   some|=sum_giacfield(dest, source, "NDIST");
 | ||
|   some|=sum_giacfield(dest, source, "SCARTI");
 | ||
|   return some;
 | ||
| }
 | ||
|   
 | ||
| // rimuove le unit<69> di misura errate
 | ||
| void unify_giacrecords(const TMask & m)
 | ||
| {
 | ||
|   TLocalisamfile anamag(LF_ANAMAG);
 | ||
|   TLocalisamfile mag(LF_MAG);
 | ||
|   
 | ||
|   TString last_art;
 | ||
|   TToken_string key;
 | ||
|   TAssoc_array giacrows;
 | ||
|   int err = mag.first  ();
 | ||
|   TProgind info(mag.items(),"Rimozione righe di giacenza doppie",FALSE,TRUE);
 | ||
|   while (err == NOERR)
 | ||
|   {
 | ||
|     if (last_art.blank() || last_art != mag.get("CODART"))
 | ||
|     {
 | ||
|       last_art = mag.get("CODART");
 | ||
|       anamag.put("CODART",last_art);
 | ||
|       while (anamag.read(_excllock) != NOERR)
 | ||
|       {
 | ||
|         error_box("Record di anagrafica %s bloccato",(const char *)last_art);
 | ||
|       }
 | ||
|       giacrows.destroy();
 | ||
|     }
 | ||
|     int curr_riga = mag.get_int("NRIGA");
 | ||
|     if (mag.get("ANNOES") == "0")
 | ||
|        mag.remove();
 | ||
|     else
 | ||
|     {
 | ||
|       key.add(mag.get("ANNOES"),0);
 | ||
|       key.add(mag.get("CODART"),1);
 | ||
|       key.add(mag.get("CODMAG"),2);
 | ||
|       key.add(mag.get("LIVELLO"),3);
 | ||
|       if (giacrows.is_key(key))
 | ||
|       {
 | ||
|         // giacenza duplicata!
 | ||
|         int last_riga = atoi((TString &)giacrows[key]);
 | ||
|         TRectype dup(mag.curr()); 
 | ||
|         mag.put("NRIGA",last_riga);
 | ||
|         mag.read();
 | ||
|         if (sum_giacrecord(mag.curr(), dup))
 | ||
|           mag.rewrite();
 | ||
|         mag.put("NRIGA",curr_riga);
 | ||
|         mag.remove();
 | ||
|       } else {
 | ||
|         //
 | ||
|         giacrows.add(key, new TString(mag.get("NRIGA")));
 | ||
|       }
 | ||
|     }
 | ||
|     mag.put("NRIGA",++curr_riga);
 | ||
|     err = mag.read(_isgteq);
 | ||
|     info.addstatus(1);
 | ||
|   }
 | ||
|   anamag.read();
 | ||
|   rinumera_mags();
 | ||
| }
 | ||
| // rimuove le unit<69> di misura errate
 | ||
| void find_wrong_um(const TMask & m)
 | ||
| {
 | ||
|   TLocalisamfile dist(LF_DIST);
 | ||
|   TLocalisamfile rdist(LF_RDIST);
 | ||
|   TLocalisamfile umart(LF_UMART);
 | ||
|   int err = dist.last();
 | ||
|   TProgind info(dist.items(),"Ricerca unit<69> di misura di distinta errate",FALSE,TRUE);
 | ||
|   TString coddist, codeum, code;
 | ||
| 
 | ||
|   while (err==NOERR)
 | ||
|   {
 | ||
|     coddist = dist.get("CODDIST");
 | ||
|     codeum = dist.get("UM");
 | ||
|     umart.setkey(2);
 | ||
|     umart.put("CODART",coddist);
 | ||
|     umart.put("UM",codeum);
 | ||
|     if (umart.read()!=NOERR)
 | ||
|       codeum = "";
 | ||
|     umart.setkey(1);
 | ||
|     if (codeum.blank())
 | ||
|     {
 | ||
|       umart.put("CODART",coddist);
 | ||
|       umart.put("NRIGA",1);
 | ||
|       if (umart.read()==NOERR)
 | ||
|       {
 | ||
|         dist.put("UM", umart.get("UM"));
 | ||
|         err = dist.rewrite();
 | ||
|       } else {
 | ||
|         int pos = coddist.find("__"); 
 | ||
|         if (pos >= 0)
 | ||
|         {
 | ||
|           umart.put("CODART",coddist.left(pos));
 | ||
|           umart.put("NRIGA","1");
 | ||
|           if (umart.read()==NOERR)
 | ||
|           {
 | ||
|             codeum = umart.get("UM");
 | ||
|             umart.put("CODART",coddist);
 | ||
|             umart.put("NRIGA","1");
 | ||
|             err = umart.write();
 | ||
|           }
 | ||
|         }
 | ||
|         if (codeum.blank())
 | ||
|           if (yesno_box("Unit<EFBFBD> di misura nulla per %s. Aggiungo", (const char *)coddist))
 | ||
|           {
 | ||
|             umart.put("CODART",coddist);
 | ||
|             umart.put("NRIGA","2");
 | ||
|             umart.put("UM",dist.get("UM"));
 | ||
|             umart.put("FC",1);
 | ||
|             err = umart.write();
 | ||
|             if (err != NOERR)
 | ||
|               warning_box("Errore in scrittura UM");
 | ||
|           }
 | ||
|           
 | ||
|       }
 | ||
|     }
 | ||
|     else if (coddist.find("__")>=0)
 | ||
|     {
 | ||
|       // variante di prod, probabilmente da esprimere in batch di prod
 | ||
|       bool chk_ricetta = FALSE;
 | ||
|       bool chk_distinta = FALSE;
 | ||
|       real bp=ZERO;
 | ||
|       if (codeum != "BP") // oh, guarda, la UM non <20> uguale a batch, caso sospetto!
 | ||
|       {
 | ||
|         umart.setkey(2);
 | ||
|         umart.put("CODART",coddist);
 | ||
|         umart.put("UM","BP");
 | ||
|         if ((err = umart.read())==NOERR)
 | ||
|           bp = umart.get_real("FC");
 | ||
|         umart.setkey(1);
 | ||
|         if (bp.is_zero() || bp == 1.0)
 | ||
|           chk_distinta = TRUE;
 | ||
|       }
 | ||
|       else
 | ||
|       {
 | ||
|         umart.setkey(2);
 | ||
|         umart.put("CODART",coddist);
 | ||
|         umart.put("UM","BP");
 | ||
|         if ((err = umart.read())==NOERR)
 | ||
|           bp = umart.get_real("FC");
 | ||
|         umart.setkey(1);
 | ||
|         umart.put("CODART",coddist);
 | ||
|         umart.put("NRIGA","1");
 | ||
|         err = umart.read();
 | ||
|         if (err==NOERR)
 | ||
|         if (umart.get("UM")=="KG")
 | ||
|           chk_ricetta = TRUE;
 | ||
|         else
 | ||
|           if (bp == 1.0)
 | ||
|             chk_distinta = TRUE;
 | ||
|       }
 | ||
|       if (chk_distinta)
 | ||
|       {
 | ||
|         real total= ZERO;
 | ||
|         rdist.zero();
 | ||
|         rdist.put("CODDIST", coddist);
 | ||
|         if (rdist.read())
 | ||
|         {
 | ||
|           int newbp=0;
 | ||
|           while (bp <= 1.0 && coddist == rdist.get("CODDIST") // 
 | ||
|             && (rdist.get("TIPO")!="V"))
 | ||
|           {
 | ||
|             code = rdist.get("CODCOMP");
 | ||
|             real expr = rdist.get_real("EXPR");
 | ||
|             if (!expr.is_zero()) 
 | ||
|             {
 | ||
|               if (rdist.get("UM") != "KG" && rdist.get("UM") != "GR")
 | ||
|               {
 | ||
|                 total = ZERO;
 | ||
|                 if (expr == 1.0 || (expr < 10.0 && expr == (int)expr.integer()))
 | ||
|                   bp = 1.0;
 | ||
|                 else
 | ||
|                 {
 | ||
|                   expr /= 1000.0;
 | ||
|                   newbp = (int)expr.integer();
 | ||
|                   if (expr == newbp)
 | ||
|                     newbp = 1000;
 | ||
|                   else 
 | ||
|                   {
 | ||
|                     expr *= 10.0;
 | ||
|                     newbp = (int)expr.integer();
 | ||
|                     if (expr == newbp)
 | ||
|                       newbp = 100;
 | ||
|                     else
 | ||
|                     {
 | ||
|                       expr *= 100.0;
 | ||
|                       newbp = (int)expr.integer();
 | ||
|                       if (expr == newbp)
 | ||
|                         newbp = 1;
 | ||
|                       else
 | ||
|                         newbp = 0;
 | ||
|                     }
 | ||
|                   }
 | ||
|                 }
 | ||
|                 if (bp>1.0 && code.find("__")<0)
 | ||
|                 {
 | ||
|                   if (bp != newbp)
 | ||
|                     bp = -1.0;
 | ||
|                 }
 | ||
|                 else
 | ||
|                   bp = newbp ? newbp : bp;
 | ||
|               }
 | ||
|               else
 | ||
|                 total += expr;
 | ||
|             }
 | ||
|             rdist.next();
 | ||
|           }
 | ||
|         }
 | ||
|         if (bp==0 && !total.is_zero())
 | ||
|           if (total > 1000)
 | ||
|             bp = 10000.0;
 | ||
|           else if (total > 100)
 | ||
|             bp = 1000.0;
 | ||
|           else if (total > 10)
 | ||
|               bp = 100.0;
 | ||
|         if (bp>1.0 && !yesno_box("Imposto la UM di distinta per %s a %s %s ?", (const char *)coddist, bp.string(), (const char *)codeum))
 | ||
|          bp = ZERO;
 | ||
|         if (bp<1.0)
 | ||
|           if (!number_box(format("Batch di distinta per %s ", (const char *)coddist),bp))
 | ||
|             bp = 1.0;
 | ||
|         if (bp>1.0)
 | ||
|         {
 | ||
|           umart.zero();
 | ||
|           umart.put("CODART",coddist);
 | ||
|           umart.put("NRIGA","2");
 | ||
|           umart.put("UM","BP");
 | ||
|           umart.put("FC",bp);
 | ||
|           if ((err = umart.write())!=NOERR)
 | ||
|           {
 | ||
|             umart.rewrite();
 | ||
|           }
 | ||
|           dist.put("UM","BP");
 | ||
|           err = dist.rewrite();
 | ||
|         } else {
 | ||
|           if (bp != 1)
 | ||
|             warning_box("UM di distinta per %s %s", (const char *)coddist, (const char *)codeum);
 | ||
|         }
 | ||
|       }
 | ||
|       if (chk_ricetta)
 | ||
|       {
 | ||
|         real totale_ricetta = ZERO;
 | ||
|         rdist.zero();
 | ||
|         rdist.put("CODDIST", coddist);
 | ||
|         rdist.read(_isgteq+_nolock);
 | ||
|         while (coddist == rdist.get("CODDIST"))
 | ||
|         {
 | ||
|           code = rdist.get("CODCOMP");
 | ||
|           real expr = rdist.get_real("EXPR");
 | ||
|           if (rdist.get("UM") == "KG")
 | ||
|             totale_ricetta = totale_ricetta + expr;
 | ||
|           if (rdist.get("UM") == "GR")
 | ||
|             totale_ricetta = totale_ricetta + (expr/1000.0);
 | ||
|           rdist.next();
 | ||
|         }
 | ||
|         if (bp != totale_ricetta && (((bp-totale_ricetta) >0.001 ) || 
 | ||
|           ((totale_ricetta-bp) >0.001 )) )
 | ||
|         {
 | ||
|           TString ts(totale_ricetta.string());
 | ||
|           if ((totale_ricetta == 10000.0 || totale_ricetta == 1000.0 ))
 | ||
|           {
 | ||
|             if (yesno_box("Batch di produzione per %s a %s; lo porto a %s",
 | ||
|              (const char *)coddist, (const char *)bp.string(), (const char *)ts))
 | ||
|             {
 | ||
|               umart.put("CODART",coddist);
 | ||
|               umart.put("UM","BP");
 | ||
|               umart.put("FC", totale_ricetta);
 | ||
|               umart.rewrite();
 | ||
|             }
 | ||
|           }// else 
 | ||
|            // warning_box("Batch di produzione per %s a %s, totale componenti %s",
 | ||
|            //  (const char *)coddist, (const char *)bp.string(), (const char *)ts);
 | ||
|         }
 | ||
|       }
 | ||
|     }
 | ||
|     info.addstatus(1);
 | ||
|     err = dist.prev();
 | ||
|   }
 | ||
| }
 | ||
| 
 | ||
| class TCover_services : public TSkeleton_application
 | ||
| {
 | ||
| protected:
 | ||
|   virtual void main_loop() ;
 | ||
| };
 | ||
| 
 | ||
| class TService_mask : public TAutomask
 | ||
| {
 | ||
| protected:
 | ||
|   virtual bool on_field_event(TOperable_field& o, TField_event e, long jolly);
 | ||
| public:
 | ||
|   TService_mask() :TAutomask("dbcv02a.msk"){}
 | ||
| };
 | ||
| bool TService_mask::on_field_event(TOperable_field& o, TField_event e, long jolly)
 | ||
| {
 | ||
|   switch (o.dlg())
 | ||
|   {
 | ||
|     case DLG_OK:
 | ||
|       if (e == fe_button)
 | ||
|       {
 | ||
|         switch (get_int(F_SERVICE))
 | ||
|         {
 | ||
|           case 1:
 | ||
|             if (noyes_box("Confermi la cancellazione del file degli articoli da escludere ?"))
 | ||
|             {
 | ||
|               TSupport_file morti(LF_DIST, ANAGRAFICA_MORTI);
 | ||
|               morti.zap();
 | ||
|             }
 | ||
|             break;
 | ||
|           case 2:
 | ||
|             crea_mag3();
 | ||
|             break;
 | ||
|           case 3:
 | ||
|             crea_linee3();
 | ||
|             break;
 | ||
|           case 4:
 | ||
|             if (noyes_box("Rinumero le righe delle distinte?"))
 | ||
|               rinumera_dist();
 | ||
|             break;
 | ||
|           case 5:
 | ||
|             if (noyes_box("Rinumero le unita' di misura?"))
 | ||
|               rinumera_ums();
 | ||
|             break;
 | ||
|           case 6:
 | ||
|             if (noyes_box("Le lavorazioni presenti sui finiti verrano spostate sulle varianti di impianto. Confermi?"))
 | ||
|               if (sposta_lavs() && yesno_box("Rinumero le righe di lavorazione?"))
 | ||
|                 rinumera_dist();
 | ||
|             break;
 | ||
|           case 7:
 | ||
|             build2levmsp();
 | ||
|             break;
 | ||
|           case 8:
 | ||
|             setformulavar();
 | ||
|             break;
 | ||
|           case 9:
 | ||
|             //check_mag_locations(get(F_PATH),source);
 | ||
|             break;
 | ||
|           case 10:
 | ||
|             evadi_orc(*this, get(S_CODIMP));
 | ||
|             break;
 | ||
|           case 11:
 | ||
|             unevadi_orc(*this, get(S_CODIMP));
 | ||
|             break;
 | ||
|           case 12:
 | ||
|             find_wrongcycle();
 | ||
|             break;
 | ||
|           case 13:
 | ||
|             sinchro_stock(*this, "SE");
 | ||
|             sinchro_stock(*this, "TS");
 | ||
|             break;
 | ||
|           case 14:
 | ||
|             unlink_docs();
 | ||
|             break;
 | ||
|           case 15:
 | ||
|             kill_blank_mag(*this,"SE1");
 | ||
|             break;
 | ||
|           case 16:
 | ||
|             unify_mags(*this);
 | ||
|             break;
 | ||
|           case 17:
 | ||
|             checkexplosions(*this);
 | ||
|           case 18:
 | ||
|             remove_wrong_um(*this);
 | ||
|             break;
 | ||
|           case 19:
 | ||
|             find_wrong_um(*this);
 | ||
|             break;
 | ||
|           case 20:
 | ||
|             check_movmags(*this);
 | ||
|             break;
 | ||
|           case 21:
 | ||
|             unify_giacrecords(*this);
 | ||
|             break;
 | ||
|           case 22:
 | ||
|             if (noyes_box("Rinumero le righe di giacenza?"))
 | ||
|               rinumera_mags();
 | ||
|             break;
 | ||
|           case 100:
 | ||
|             if (noyes_box("Esporto le lavorazioni?"))
 | ||
|               //exportlavs();
 | ||
|             break;
 | ||
|         }
 | ||
|       }
 | ||
|   }  
 | ||
|   return TRUE;
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| void converti_magazzino(TLocalisamfile & file, const char *campo, const char *campovecchio , const char *camponuovo)
 | ||
| {
 | ||
|   file.first();
 | ||
|   while (!file.eof())
 | ||
|   {
 | ||
|     if (file.get(campo) == campovecchio)
 | ||
|     {
 | ||
|       file.put(campo,camponuovo);
 | ||
|       file.rewrite();
 | ||
|     }
 | ||
|     file.next();
 | ||
|     do_events();
 | ||
|   }
 | ||
| }
 | ||
| void uniscimag(const char *campovecchio , const char *camponuovo)
 | ||
| {
 | ||
|   TLocalisamfile file(LF_MAG), nfile(LF_MAG);;
 | ||
|   TString codart= "";
 | ||
|   real qentr, qusc, qacq, qven , qrimin, qgiac;
 | ||
|   real vqentr, vqusc, vqacq, vqven , vqrimin;
 | ||
|   int nriga = 1;
 | ||
|   int annoes;
 | ||
|   bool done=TRUE;
 | ||
| 
 | ||
|   file.first();
 | ||
|   while (!file.eof())
 | ||
|   {
 | ||
|     if (codart == "")
 | ||
|     {
 | ||
|       codart = file.get("CODART");
 | ||
|       annoes= file.get_int("ANNOES");
 | ||
|       done = TRUE;
 | ||
|     }
 | ||
|     if (file.get("CODMAG") == campovecchio)
 | ||
|     {
 | ||
|       qentr = file.get_real("ENT");
 | ||
|       qusc = file.get_real("USC"); 
 | ||
|       qacq = file.get_real("ACQ");  
 | ||
|       qven  = file.get_real("VEN"); 
 | ||
|       qrimin  = file.get_real("RIM"); 
 | ||
|       vqentr = file.get_real("VALENT");
 | ||
|       vqusc = file.get_real("VALUSC"); 
 | ||
|       vqacq = file.get_real("VALACQ");  
 | ||
|       vqven  = file.get_real("VALVEN"); 
 | ||
|       vqrimin  = file.get_real("VALRIM"); 
 | ||
|       qgiac  = file.get_real("GIAC"); 
 | ||
|         file.put("ENT", ZERO);
 | ||
|         file.put("USC", ZERO); 
 | ||
|         file.put("ACQ",ZERO);  
 | ||
|         file.put("VEN",ZERO); 
 | ||
|         file.put("RIM",ZERO); 
 | ||
|         file.put("VALENT",ZERO);
 | ||
|         file.put("VALUSC",ZERO); 
 | ||
|         file.put("VALACQ",ZERO);  
 | ||
|         file.put("VALVEN",ZERO); 
 | ||
|         file.put("VALRIM",ZERO); 
 | ||
|         file.put("GIAC",ZERO); 
 | ||
|       //   file.remove(); can' remove without renumbering 
 | ||
|       //file.rewrite(); 
 | ||
|       done = FALSE;
 | ||
|     }
 | ||
|     else if (file.get("CODMAG") == camponuovo && !done)
 | ||
|     {
 | ||
|       qentr += file.get_real("ENT");
 | ||
|       qusc += file.get_real("USC"); 
 | ||
|       qacq += file.get_real("ACQ");  
 | ||
|       qven  += file.get_real("VEN"); 
 | ||
|       qrimin  += file.get_real("RIM"); 
 | ||
|       vqentr += file.get_real("VALENT");
 | ||
|       vqusc += file.get_real("VALUSC"); 
 | ||
|       vqacq += file.get_real("VALACQ");  
 | ||
|       vqven  += file.get_real("VALVEN"); 
 | ||
|       vqrimin  += file.get_real("VALRIM"); 
 | ||
|       qgiac  += file.get_real("GIAC"); 
 | ||
|         file.put("ENT", qentr);
 | ||
|         file.put("USC", qusc); 
 | ||
|         file.put("ACQ",qacq);  
 | ||
|         file.put("VEN",qven); 
 | ||
|         file.put("RIM",qrimin); 
 | ||
|         file.put("VALENT",vqentr);
 | ||
|         file.put("VALUSC",vqusc); 
 | ||
|         file.put("VALACQ",vqacq);  
 | ||
|         file.put("VALVEN",vqven); 
 | ||
|         file.put("VALRIM",vqrimin); 
 | ||
|         file.put("GIAC",qgiac); 
 | ||
|       file.put("CODMAG",camponuovo);
 | ||
|       //file.rewrite();
 | ||
|       done = TRUE;
 | ||
|     }
 | ||
|     nriga = file. get_int("NRIGA");
 | ||
|     file.next();
 | ||
|     if (file.eof() || codart != file.get("CODART"))
 | ||
|     {
 | ||
|       if (!done) 
 | ||
|       {
 | ||
|         nfile.zero();
 | ||
|         nfile.put("ENT", qentr);
 | ||
|         nfile.put("USC", qusc); 
 | ||
|         nfile.put("ACQ",qacq);  
 | ||
|         nfile.put("VEN",qven); 
 | ||
|         nfile.put("RIM",qrimin); 
 | ||
|         nfile.put("VALENT",vqentr);
 | ||
|         nfile.put("VALUSC",vqusc); 
 | ||
|         nfile.put("VALACQ",vqacq);  
 | ||
|         nfile.put("VALVEN",vqven); 
 | ||
|         nfile.put("VALRIM",vqrimin); 
 | ||
|         nfile.put("GIAC",qgiac); 
 | ||
|         nfile.put("CODMAG",camponuovo);
 | ||
|         nfile.put("CODART", codart);
 | ||
|         nfile.put("ANNOES", codart);
 | ||
|         nfile.put("NRIGA", nriga+1);
 | ||
|         //nfile.write();
 | ||
|       }
 | ||
|       codart = file.get("CODART");
 | ||
|       annoes= file.get_int("ANNOES");
 | ||
|       done = TRUE;
 | ||
|       qentr = qusc = qacq = qven  = qrimin  = vqentr = vqusc = vqacq = vqven  = vqrimin  = qgiac  = ZERO;
 | ||
|     }
 | ||
|     do_events();
 | ||
|   }
 | ||
| }
 | ||
| void TCover_services::main_loop() 
 | ||
| {
 | ||
|   TLocalisamfile rdoc(LF_RIGHEDOC), rmovmag(LF_RMOVMAG), mag(LF_MAG);
 | ||
|   //converti_magazzino(rdoc, "CODMAG", "COMSE", "SE1X0");
 | ||
|   //converti_magazzino(rdoc, "CODMAGC", "COMSE", "SE1X0");
 | ||
|   //converti_magazzino(rmovmag, "CODMAG", "COMSE", "SE1X0");
 | ||
|   //uniscimag("COM", "SE1X0");
 | ||
|   TService_mask m;
 | ||
|   
 | ||
|   while (m.run()!=K_QUIT);
 | ||
| }
 | ||
| 
 | ||
| 
 | ||
| int dbcv02(int argc, char* argv[])
 | ||
| {
 | ||
|   TString name;
 | ||
|   TCover_services dt;
 | ||
|   dt.run(argc, argv, "Utilita' di conversione BPCS");
 | ||
|   return 0;
 | ||
| }
 |