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