FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour HACER MAS RAPIDO UN PROCESO
Posts: 537
Joined: Mon Jan 16, 2006 03:42 PM
HACER MAS RAPIDO UN PROCESO
Posted: Tue Apr 28, 2015 03: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

Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Tue Apr 28, 2015 07: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!
Posts: 1515
Joined: Thu Oct 30, 2008 02:37 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Tue Apr 28, 2015 08: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.

Posts: 537
Joined: Mon Jan 16, 2006 03:42 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Tue Apr 28, 2015 11:10 PM

Jose Luis, me puedes mostrar como lo haces por favor
saludos

Posts: 6755
Joined: Wed Feb 15, 2012 08:25 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: 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
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 01: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... :-)
Dios no está muerto...



Gracias a mi Dios ante todo!
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 02:01 AM
Mr jbrita

All this can be done by executing one single SQL statement.
Code (fw): Select all Collapse
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
Posts: 989
Joined: Thu Nov 24, 2005 03:01 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 08: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"
Posts: 537
Joined: Mon Jan 16, 2006 03:42 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 12:40 PM

Excelente muchas gracias
saludos

Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 04:05 PM
nageswaragunupudi wrote:Mr jbrita

All this can be done by executing one single SQL statement.
Code (fw): Select all Collapse
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!
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 07: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
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 07: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
Posts: 2064
Joined: Fri Jan 06, 2006 09:28 PM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Wed Apr 29, 2015 07: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!
Posts: 2170
Joined: Fri Jul 18, 2008 01:24 AM
Re: HACER MAS RAPIDO UN PROCESO
Posted: Thu Apr 30, 2015 01: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

Continue the discussion