Page 1 of 1

HACER MAS RAPIDO UN PROCESO

PostPosted: Tue Apr 28, 2015 3:46 pm
by jbrita
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

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Tue Apr 28, 2015 7:11 pm
by joseluisysturiz
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:

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Tue Apr 28, 2015 8:06 pm
by hmpaquito
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.

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Tue Apr 28, 2015 11:10 pm
by jbrita
Jose Luis, me puedes mostrar como lo haces por favor
saludos

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Tue Apr 28, 2015 11:23 pm
by cnavarro
Al escribir un mensaje, pulsa sobre el boton CODE y pega el "fuente" entre los dos code y /code que te aparece

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 1:09 am
by joseluisysturiz
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:

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 2:01 am
by nageswaragunupudi
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

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 8:15 am
by Carlos Mora
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,

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 12:40 pm
by jbrita
Excelente muchas gracias
saludos

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 4:05 pm
by joseluisysturiz
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:

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 7:16 pm
by FranciscoA
Creo que me viene "como anillo al dedo" en un sistema de Contabilidad. Voy a probarlo por la noche.
Gracias Sr. Rao.

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 7:32 pm
by nageswaragunupudi
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.

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Wed Apr 29, 2015 7:40 pm
by joseluisysturiz
Para conocimientos generales, incluyendome, saludos... :shock:

http://es.kioskea.net/faq/8897-mysql-qu ... ion-elegir

Re: HACER MAS RAPIDO UN PROCESO

PostPosted: Thu Apr 30, 2015 1:50 am
by FranciscoA
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