In order for this site to work correctly we need to store a small file (called a cookie) on your computer. Most every site in the world does this, however since the 25th of May 2011, by law we have to get your permission first. Please abandon the forum if you disagree.

Para que este foro funcione correctamente es necesario guardar un pequeño fichero (llamado cookie) en su ordenador. La mayoría de los sitios de Internet lo hacen, no obstante desde el 25 de Marzo de 2011 y por ley, necesitamos de su permiso con antelación. Abandone este foro si no está conforme.

Agrupar y Contar Productos (Solucionado)

FastReport for Xailer & [x]Harbour (English/Spanish)
Responder
ryder1912
Mensajes: 29
Registrado: Jue Jul 09, 2015 8:17 pm

Agrupar y Contar Productos (Solucionado)

Mensaje por ryder1912 »

Buenas, estoy haciendo un listado de inmuebles de una clinica, un sistema inventario. El tema es que cuando hago el listado me gustaria poner al final la Cantidad de cada inmueble o bien, pero no me sale y nosé como encaralo. En el adjunto puse una imagen del informe y el total lo puse en color rojo con el paint para que se entienda lo que quiero hacer, tambien adjunto la clase x las dudas.
foto del reporte
foto del reporte
stock_deposito.jpg (145.8 KiB) Visto 4286 veces
Listado.rar
Clase
(3.58 KiB) Descargado 236 veces
La pregunta es: Es posible contarlos y poner el total de cada uno al final como está en la imagen? o hay otra manera mas sencilla de poder hacerlo?

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
Última edición por ryder1912 el Sab Dic 17, 2016 8:57 pm, editado 1 vez en total.
Avatar de Usuario
ignacio
Site Admin
Mensajes: 9246
Registrado: Lun Abr 06, 2015 8:00 pm
Ubicación: Madrid, Spain
Contactar:

Re: Agrupar y Contar Productos

Mensaje por ignacio »

Buenos días,

Su pregunta no es sobre Fast Report, sino sobre el generador de informes que incluye Xailer. Simplemente una pista. Échele un vistazo a la propiedad TRptGroup:nCounter.

Saludos
Ignacio Ortiz de Zúñiga
[Equipo de Xailer / Xailer team]
https://www.xailer.com
ryder1912
Mensajes: 29
Registrado: Jue Jul 09, 2015 8:17 pm

Re: Agrupar y Contar Productos

Mensaje por ryder1912 »

Perfecto, muchas gracias.
Solucion:

Código: Seleccionar todo

      GROUP oGrupo1 OF oReport ON ::oDatos:nroinventario;
      HEADER ::oDatos:descripcion ;
      FOOTER 'Total: '+CampoAStr(oGrupo1:nCounter) ;
      FONT 2
Responder