HACER MAS RAPIDO UN PROCESO
HACER MAS RAPIDO UN PROCESO
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
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
- joseluisysturiz
- Posts: 2064
- Joined: Fri Jan 06, 2006 9:28 pm
- Location: Guatire - Caracas - Venezuela
- Contact:
Re: HACER MAS RAPIDO UN PROCESO
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... 

Dios no está muerto...
Gracias a mi Dios ante todo!
Gracias a mi Dios ante todo!
Re: HACER MAS RAPIDO UN PROCESO
Hombre, lo primero-primero que tendria que hacer es mostrarnos el codigo formateado....
Para ello se trataria de utilizar el boton "Code" que está encima del cuerpo del mensaje.

Para ello se trataria de utilizar el boton "Code" que está encima del cuerpo del mensaje.
- cnavarro
- Posts: 6572
- Joined: Wed Feb 15, 2012 8:25 pm
- Location: España
- Has thanked: 4 times
- Been thanked: 6 times
Re: HACER MAS RAPIDO UN PROCESO
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
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
- joseluisysturiz
- Posts: 2064
- Joined: Fri Jan 06, 2006 9:28 pm
- Location: Guatire - Caracas - Venezuela
- Contact:
Re: HACER MAS RAPIDO UN PROCESO
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...

Dios no está muerto...
Gracias a mi Dios ante todo!
Gracias a mi Dios ante todo!
- nageswaragunupudi
- Posts: 10733
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 11 times
- Contact:
Re: HACER MAS RAPIDO UN PROCESO
Mr jbrita
All this can be done by executing one single SQL statement.
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
All this can be done by executing one single SQL statement.
Code: Select all | Expand
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
G. N. Rao.
Hyderabad, India
-
- Posts: 989
- Joined: Thu Nov 24, 2005 3:01 pm
- Location: Madrid, España
Re: HACER MAS RAPIDO UN PROCESO
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,
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
http://harbouradvisor.blogspot.com/
StackOverflow http://stackoverflow.com/users/549761/carlos-mora
“If you think education is expensive, try ignorance"
- joseluisysturiz
- Posts: 2064
- Joined: Fri Jan 06, 2006 9:28 pm
- Location: Guatire - Caracas - Venezuela
- Contact:
Re: HACER MAS RAPIDO UN PROCESO
nageswaragunupudi wrote:Mr jbrita
All this can be done by executing one single SQL statement.Code: Select all | Expand
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...

Dios no está muerto...
Gracias a mi Dios ante todo!
Gracias a mi Dios ante todo!
- FranciscoA
- Posts: 2164
- Joined: Fri Jul 18, 2008 1:24 am
- Location: Chinandega, Nicaragua, C.A.
Re: HACER MAS RAPIDO UN PROCESO
Creo que me viene "como anillo al dedo" en un sistema de Contabilidad. Voy a probarlo por la noche.
Gracias Sr. Rao.
Gracias Sr. Rao.
Francisco J. Alegría P.
Chinandega, Nicaragua.
Fwxh-MySql-TMySql
Chinandega, Nicaragua.
Fwxh-MySql-TMySql
- nageswaragunupudi
- Posts: 10733
- Joined: Sun Nov 19, 2006 5:22 am
- Location: India
- Been thanked: 11 times
- Contact:
Re: HACER MAS RAPIDO UN PROCESO
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.
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
G. N. Rao.
Hyderabad, India
- joseluisysturiz
- Posts: 2064
- Joined: Fri Jan 06, 2006 9:28 pm
- Location: Guatire - Caracas - Venezuela
- Contact:
Re: HACER MAS RAPIDO UN PROCESO
Para conocimientos generales, incluyendome, saludos...
http://es.kioskea.net/faq/8897-mysql-qu ... ion-elegir

http://es.kioskea.net/faq/8897-mysql-qu ... ion-elegir
Dios no está muerto...
Gracias a mi Dios ante todo!
Gracias a mi Dios ante todo!
- FranciscoA
- Posts: 2164
- Joined: Fri Jul 18, 2008 1:24 am
- Location: Chinandega, Nicaragua, C.A.
Re: HACER MAS RAPIDO UN PROCESO
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
Chinandega, Nicaragua.
Fwxh-MySql-TMySql