HACER MAS RAPIDO UN PROCESO

HACER MAS RAPIDO UN PROCESO

Postby jbrita » Tue Apr 28, 2015 3:46 pm

Hola Amigos, consulta y ayuda. bueno tengo 2 tablas una general y otra detallada. hay en algunas ocaciones el saldo en la tabla general no es la misma que en la tabla detalle, por lo mismo hago este ajusteBodega .

STATIC FUNCTION AjusteBodega(oDlg,oProgress1)
*----------------------------
Local nReg:=TablaRecout("exi_suc")
Local oma_arti,cSql,cExi_Det
Local totini,totent,totsal
Local oCmd,oRsCmd
Local nCount:=0
nActual := 0
nTotal := 0


oCmd:=TOleAuto():New("ADODB.Command")
oCmd:CommandText :="select count(*) from exi_suc WHERE sto_ok='"+"1'"
oCmd:CommandType :=adCmdText
oCmd:ActiveConnection:=oConexion
oRsCmd:=oCmd:Execute()
nCount:=oRsCmd:Fields( 0 ):value

cExi_Suc:= tOleAuto():New("ADODB.Recordset")
cExi_Suc:CursorLocation(3)
cExi_Suc:Open("SELECT ma_arti FROM exi_suc ORDER BY ma_des1", oConexion, 1, 3)

oProgress1:SetRange( 0, nCount )
Do While !cExi_Suc:Eof()
If ADOField(cExi_Suc,"sto_ok")=1
oma_arti:=ADOField(cExi_Suc,"ma_arti")
totini:=0
totent:=0
totsal:=0
cExi_Det:= tOleAuto():New("ADODB.Recordset")
cExi_Det:CursorLocation(3)
cExi_Det:Open("SELECT SUM(exi_ent) As entrada,SUM(exi_sal) AS salida FROM exi_det WHERE exi_art='"+ AllTrim(oma_arti)+ "'", oConexion, 1, 3)
If (cExi_Det:RecordCount) # 0
totini:=0
totent:=ADOField(cExi_Det,"entrada")
totsal:=ADOField(cExi_Det,"salida")
Else
totini:=0
totent:=0
totsal:=0
Endif
ADO Close cExi_Det
cSql:= "UPDATE exi_suc SET bod_ini1='" + Str(totini,11,3) + "'," + ;
"bod_ent1='" + Str(totent,11,3) + "'," + ;
"bod_sal1='" + Str(totsal,11,3) + "'" + ;
" WHERE ma_arti='"+ oma_arti + "'"

oConexion:Execute( cSql )

Endif

nActual++
oProgress1:SetPos( nActual )
SYSREFRESH()
cExi_Suc:Move(+1) //Skip
EndDo
ADO CLOSE cExi_Suc
oDlg:End()
RETURN NIL

"COMO HAGO PARA QUE SE MAS RAPIDO..

Saludos
jbrita
 
Posts: 486
Joined: Mon Jan 16, 2006 3:42 pm

Re: HACER MAS RAPIDO UN PROCESO

Postby joseluisysturiz » Tue Apr 28, 2015 7:11 pm

Creo lo primero deberia ser de sacar el SYSREFRESH del do while, por lo que veo tienes una tabla de totales de movimientos(saldo existencia) y otra de movimientos de productos(entradas/salidas), y quieres hacer una actualizacion de saldos en X momento...que tanto acerte para darte idea de que hacer.? aunque hago lo mismo pero con tdolphin y mysql. saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: HACER MAS RAPIDO UN PROCESO

Postby hmpaquito » Tue Apr 28, 2015 8:06 pm

Hombre, lo primero-primero que tendria que hacer es mostrarnos el codigo formateado.... :wink:
Para ello se trataria de utilizar el boton "Code" que está encima del cuerpo del mensaje.
hmpaquito
 
Posts: 1482
Joined: Thu Oct 30, 2008 2:37 pm

Re: HACER MAS RAPIDO UN PROCESO

Postby jbrita » Tue Apr 28, 2015 11:10 pm

Jose Luis, me puedes mostrar como lo haces por favor
saludos
jbrita
 
Posts: 486
Joined: Mon Jan 16, 2006 3:42 pm

Re: HACER MAS RAPIDO UN PROCESO

Postby cnavarro » Tue Apr 28, 2015 11:23 pm

Al escribir un mensaje, pulsa sobre el boton CODE y pega el "fuente" entre los dos code y /code que te aparece
Cristobal Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
El secreto de la felicidad no está en hacer lo que te gusta, sino en que te guste lo que haces
User avatar
cnavarro
 
Posts: 6500
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: HACER MAS RAPIDO UN PROCESO

Postby joseluisysturiz » Wed Apr 29, 2015 1:09 am

cnavarro wrote:Al escribir un mensaje, pulsa sobre el boton CODE y pega el "fuente" entre los dos code y /code que te aparece

Aclarando, no al escribir un mensaje..sino cuando el mensaje incluya codigo y mas si es tan largo, creo asi esta mas claro, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: HACER MAS RAPIDO UN PROCESO

Postby nageswaragunupudi » Wed Apr 29, 2015 2:01 am

Mr jbrita

All this can be done by executing one single SQL statement.
Code: Select all  Expand view

STATIC FUNCTION AjusteBodega()

   local cSql

   TEXT INTO cSql
   UPDATE exi_suc A
   LEFT OUTER JOIN (
      SELECT exi_art,
             SUM(exi_ent) AS entrada,
             SUM(exi_sal) AS salia
             FROM exi_det
             GROUP BY exi_art
      ) B
   ON A.ma_arti = B.exi_art
   SET A.bod_ent1 = IFNULL( B.entrada, 0 ),
       A.bod_sal1 = IFNULL( B.salia, 0 ),
       A.bod_ini1 = 0
   WHERE A.sto_ok = 1
   ENDTEXT

   CursorWait()
   oConexion:Execute( cSql )
   CursorArrow()

return nil
 


This SQL syntax is for MySql. For others this may be different.
You can use ADO or TDolphin or any other library, this SQL syntax works.

You do not need progress meter because the execution is extremely fast.
Please check for any spelling mistakes before executing the above code
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: HACER MAS RAPIDO UN PROCESO

Postby Carlos Mora » Wed Apr 29, 2015 8:15 am

Mr Rao,

Excelent answer! Should be saved as a great 'recipe' for future SQL reference.
This kind of solutions are the strongest points in favor of SQL vs. clasic ISAM/dbf.

Thanks for sharing,
Saludos
Carlos Mora
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
Carlos Mora
 
Posts: 988
Joined: Thu Nov 24, 2005 3:01 pm
Location: Madrid, España

Re: HACER MAS RAPIDO UN PROCESO

Postby jbrita » Wed Apr 29, 2015 12:40 pm

Excelente muchas gracias
saludos
jbrita
 
Posts: 486
Joined: Mon Jan 16, 2006 3:42 pm

Re: HACER MAS RAPIDO UN PROCESO

Postby joseluisysturiz » Wed Apr 29, 2015 4:05 pm

nageswaragunupudi wrote:Mr jbrita

All this can be done by executing one single SQL statement.
Code: Select all  Expand view

STATIC FUNCTION AjusteBodega()

   local cSql

   TEXT INTO cSql
   UPDATE exi_suc A
   LEFT OUTER JOIN (
      SELECT exi_art,
             SUM(exi_ent) AS entrada,
             SUM(exi_sal) AS salia
             FROM exi_det
             GROUP BY exi_art
      ) B
   ON A.ma_arti = B.exi_art
   SET A.bod_ent1 = IFNULL( B.entrada, 0 ),
       A.bod_sal1 = IFNULL( B.salia, 0 ),
       A.bod_ini1 = 0
   WHERE A.sto_ok = 1
   ENDTEXT

   CursorWait()
   oConexion:Execute( cSql )
   CursorArrow()

return nil
 


This SQL syntax is for MySql. For others this may be different.
You can use ADO or TDolphin or any other library, this SQL syntax works.

You do not need progress meter because the execution is extremely fast.
Please check for any spelling mistakes before executing the above code


Mejor que como lo hago, lo tratare implementar en mi sistema y luego comento como resulto, saludos... :shock:
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: HACER MAS RAPIDO UN PROCESO

Postby FranciscoA » Wed Apr 29, 2015 7:16 pm

Creo que me viene "como anillo al dedo" en un sistema de Contabilidad. Voy a probarlo por la noche.
Gracias Sr. Rao.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2110
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: HACER MAS RAPIDO UN PROCESO

Postby nageswaragunupudi » Wed Apr 29, 2015 7:32 pm

I just answered mr jbrita's requirement.
If you are talking about accounting systems, there are a lot of better ways to do.
We can straightaway get account summary ( some countries call it trial balance) with group totals and all in one stroke.
Then super-impose closing entries and display balance-sheet and profit and loss account.
I suggest you post a specific requirement in a separate thread and we see how simple the entire process can be.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10248
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: HACER MAS RAPIDO UN PROCESO

Postby joseluisysturiz » Wed Apr 29, 2015 7:40 pm

Para conocimientos generales, incluyendome, saludos... :shock:

http://es.kioskea.net/faq/8897-mysql-qu ... ion-elegir
Dios no está muerto...

Gracias a mi Dios ante todo!
User avatar
joseluisysturiz
 
Posts: 2064
Joined: Fri Jan 06, 2006 9:28 pm
Location: Guatire - Caracas - Venezuela

Re: HACER MAS RAPIDO UN PROCESO

Postby FranciscoA » Thu Apr 30, 2015 1:50 am

nageswaragunupudi wrote:I just answered mr jbrita's requirement.
If you are talking about accounting systems, there are a lot of better ways to do.
We can straightaway get account summary ( some countries call it trial balance) with group totals and all in one stroke.
Then super-impose closing entries and display balance-sheet and profit and loss account.
I suggest you post a specific requirement in a separate thread and we see how simple the entire process can be.


Mr. Rao: viewtopic.php?f=3&t=30616#p175861
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh-MySql-TMySql
User avatar
FranciscoA
 
Posts: 2110
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.


Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 71 guests