Este es el procedimiento cuando hago el listado o el reporte, es un poco largo, la parte donde dice // Preparar el Reporte empieza a armar el listado.
Código: Seleccionar todo
METHOD btListarClick( oSender ) CLASS TListCtrlBienes
local oReport, oGrupo, oFnt1, oFnt2, oFnt3, oFnt4, aTitulos, aTitulos2, oGrupo1
local aPtos1:={}, aPtos2:={}, cClientes , cOrden, idPtoVta, nCantidad, cSectores, cTipoBienes
local aAux, i, cSql, cOld
::btListar:lEnabled:=.F.
if ::oDatos:lOpen
::oDatos:Close()
endif
if ::oSql:lOpen
::oSql:Close()
endif
// Validar Datos
if empty(::edFechaIni:Value) .or. empty(::edFechaFin:Value) .or. ::edFechaFin:Value<::edFechaIni:Value
::btListar:lEnabled:=.T.
::edFechaIni:SetFocus()
MsgStop('Ingrese el periodo correctamente ...','Error de Datos')
return NIL
endif
cSectores:=""
aAux:=::comSectores:GetSelItems()
for i:=1 to len(aAux)
aadd(aPtos1,::comSectores:Cargo[aAux[i]])
if i==1
cSectores+=" and ( "
else
cSectores+=" or "
endif
cSectores+="sec.id="+CampoAStr(::comSectores:Cargo[aAux[i]])
next
if len(aPtos1)==0
MsgStop('No selecionó ningún Sector ...','Error de Datos')
::btCancelar:lEnabled:= .T.
::btListar:lEnabled := .T.
RETURN Nil
else
cSectores+=") "
endif
cTipoBienes:=""
aAux:=::comTipoBienes:GetSelItems()
for i:=1 to len(aAux)
aadd(aPtos2,::comTipoBienes:Cargo[aAux[i]])
if i==1
cTipoBienes+="and ( "
else
cTipoBienes+=" or "
endif
cTipoBienes+="tp.id="+CampoAStr(::comTipoBienes:Cargo[aAux[i]])
next
if len(aPtos2)==0
MsgStop('No selecionó ningún Tipo de Bien ...','Error de Datos')
::btCancelar:lEnabled:= .T.
::btListar:lEnabled := .T.
RETURN Nil
else
cTipoBienes+=") "
endif
cOrden:=''
do case
case ::oOrden:nIndex == 1
cOrden:='DescSector, DescTipoBien, inm.nroinventario, IdInmueble, ctl.fechaultctrl, ctl.hrultctrl'
case ::oOrden:nIndex == 2
cOrden:='DescTipoBien, DescSector, inm.nroinventario, IdInmueble, ctl.fechaultctrl, ctl.hrultctrl'
case ::oOrden:nIndex == 3
cOrden:='inm.nroinventario, ctl.fechaultctrl, ctl.hrultctrl'
otherwise
cOrden:='IdInmueble, ctl.fechaultctrl, ctl.hrultctrl'
endcase
// Armar Consulta
cSql:='Select inm.id as IdInmueble, ctl.fechaultctrl, ctl.hrultctrl, '
cSql+='inm.nroinventario, inm.nroserie, inm.descripcion, inm.ubicacion, inm.fechaadq, '
cSql+='sec.descripcion as DescSector, tp.descripcion as DescTipoBien '
cSql+='From CtrlBienes ctl Left Join Inmuebles inm on inm.id=ctl.idinmueble '
cSql+= 'Left Join Sectores sec on sec.id=inm.idsector '
cSql+= 'Left Join tipobienes tp on tp.id=inm.idtipobien '
cSql+="Where (inm.fechabaja = ' / / ') and ( inm.fechaadq>="+CampoAStr(::edFechaIni:Value)+" and inm.fechaadq<="+CampoAStr(::edFechaFin:Value)+" ) "
cSql+=cSectores+cTipoBienes
cSql+='Order by '+cOrden
::oSql:cSelect:=cSql
// Llenar el DataSet
if ::oSql:Open()
::oProg:lVisible:=.T.
::oProg:nValue :=1
::oProg:nMin :=1
::oProg:nMax :=::oSql:RecCount()
while !::oSql:eof()
::oProg:StepIt()
if ::oProg:nValue % 5==0
ProcessMessages()
endif
if !::oDatos:lOpen
::oDatos:Open({{::oSql:IdInmueble, ::oSql:fechaultctrl, ::oSql:hrultctrl, ::oSql:nroinventario, ::oSql:nroserie, ;
::oSql:descripcion, ::oSql:ubicacion,::oSql:fechaadq, ::oSql:DescSector, ::oSql:DescTipoBien, nCantidad ;
}}, ;
{'IdInmueble','FechaUltCtrl', 'HrUltCtrl', 'NroInventario','NroSerie', 'Descripcion',;
'Ubicacion', 'FechaAdq', 'DescSector', 'DescTipoBien', 'Cantidad';
})
else
::oDatos:Append()
::oDatos:IdInmueble :=::oSql:IdInmueble
::oDatos:FechaUltCtrl :=::oSql:fechaultctrl
::oDatos:HrUltCtrl :=::oSql:hrultctrl
::oDatos:NroInventario:=::oSql:nroinventario
::oDatos:NroSerie :=::oSql:nroserie
::oDatos:Descripcion :=::oSql:descripcion
::oDatos:Ubicacion :=::oSql:ubicacion
::oDatos:FechaAdq :=::oSql:fechaadq
::oDatos:DescSector :=::oSql:DescSector
::oDatos:DescTipoBien :=::oSql:DescTipoBien
::oDatos:Cantidad :=1
::oDatos:Update()
endif
::oSql:skip(1)
enddo
::oProg:nValue :=1
::oProg:nMin :=1
::oProg:lVisible:=.F.
endif
// Preparar el Reporte
if ::oDatos:lOpen
oFnt1:=TFont():New()
oFnt1:cName:="Times New Roman"
oFnt1:nSize:=8
oFnt2:=TFont():New()
oFnt2:cName:="Times New Roman"
oFnt2:nSize:=10
oFnt2:lBold:=.T.
oFnt4:=TFont():New()
oFnt4:cName:="Arial"
oFnt4:nSize:=9
oFnt4:lBold:=.T.
::oDatos:GoTop()
aTitulos2:={'Listado de Control de Bienes '+dtoc(::edFechaIni:Value)+' hasta el '+dtoc(::edFechaFin:Value) }
REPORT oReport;
PREVIEW MODAL FONT oFnt1, oFnt2
oReport:lAutoLand:=.F.
oReport:bSkip := {|| ::oDatos:skip(1) }
oReport:bWhile := {|| !::oDatos:eof() }
COLUMN OF oReport TITLE 'Nro. de Inventario' ;
DATA ::oDatos:nroinventario;
ALIGN taLeft FONT 1 CHARSIZE 15
COLUMN OF oReport TITLE 'Nro. de Serie' ;
DATA ::oDatos:NroSerie;
ALIGN taLeft FONT 1 CHARSIZE 15
COLUMN OF oReport TITLE 'Sector' ;
DATA ::oDatos:DescSector;
ALIGN taLeft FONT 1 CHARSIZE 15
COLUMN OF oReport TITLE 'Tipo de Bien' ;
DATA ::oDatos:DescTipoBien;
ALIGN taLeft FONT 1 CHARSIZE 15
COLUMN OF oReport TITLE 'Fecha Adq.' ;
DATA DToC(cctod(::oDatos:FechaAdq)) ;
ALIGN taLeft FONT 1 CHARSIZE 8
COLUMN OF oReport TITLE 'Ult. Fecha y Hr. Ctrl.' ;
DATA DToC(cctod(::oDatos:FechaAdq))+', '+::oDatos:HrUltCtrl ;
ALIGN taLeft FONT 1 CHARSIZE 15
cOld:=''
GROUP oGrupo1 OF oReport ON ::oDatos:descripcion;
HEADER ( cOld:=::oDatos:descripcion ) ;
FOOTER if( valtype(cOld)=='C', 'Total '+cOld, '' ) ;
FONT 2
if ::chkExcel:lChecked
oReport:oTitle:=TRptLine():Create(oReport,{ {|| aTitulos2[1] } } , taCENTER , 't' )
oReport:ToExcel()
else
oReport:nTopMargin:=300
RUN REPORT oReport ON STARTPAGE Titulos(oReport,aTitulos)
endif
// Cerrar todo
oReport:End()
oFnt1:End()
oFnt2:End()
oFnt4:End()
endif
if ::oDatos:lOpen
::oDatos:Close()
endif
::btListar:lEnabled:=.T.
RETURN Nil