Dynamics GP 2018 Reporte: Listado de ventas por Ítem
Reporte donde podremos encontrar información de ventas en el sistema, agrupado por ítems, saber cuanto se vendió de un ítem, cuanto nos quede en inventario, saber cuanto se vendió en ($$), cual fue mi costo total de lo que se vendió (-$$), precio de lista, ganancia y margen.
Le enviamos los siguientes parámetros:
- Nombre del ítem
- Lugar de la venta
- Fecha de inicio, y fecha de fin (Rango de venta)
SELECT a1.*
FROM (
SELECT a1.*, a1.valorVentaTotal - a1.valorCostoTotal as Ganancia,
CASE WHEN a1.valorVentaTotal = 0 THEN 0
ELSE ROUND( (100 * ( (a1.valorVentaTotal - a1.valorCostoTotal) / a1.valorVentaTotal) ) ,2) end as Margen
FROM (
SELECT a1.*
FROM (
SELECT a2.ITEMNMBR, a2.ITEMDESC, SUM(CASE WHEN a1.SOPTYPE = 4 THEN (a2.QUANTITY*-1) ELSE a2.QUANTITY END) as QUANTITY,
a3.QTYONHND,
SUM(CASE WHEN a1.SOPTYPE = 4 THEN (a2.XTNDPRCE*-1) ELSE a2.XTNDPRCE END) as valorVentaTotal,
SUM(CASE WHEN a1.SOPTYPE = 4 THEN (a2.EXTDCOST*-1) ELSE a2.EXTDCOST END) as valorCostoTotal,
a3.UOMPRICE, a3.ITMSHNAM
FROM SOP30200 as a1
INNER JOIN SOP30300 as a2 ON (a1.SOPNUMBE = a2.SOPNUMBE)
INNER JOIN (
SELECT a1.ITEMNMBR, a1.ITMSHNAM, a3.UOMPRICE, SUM(a2.QTYONHND) as QTYONHND
FROM IV00101 as a1 /* Maestro de item */
INNER JOIN IV00102 as a2 ON (a1.ITEMNMBR=a2.ITEMNMBR) /* Saldos de Items */
INNER JOIN IV00108 as a3 ON (a2.ITEMNMBR=a3.ITEMNMBR) /* Lista de precios */
WHERE a1.ITEMNMBR LIKE (CASE WHEN @NombreItem IS NULL THEN '%%%' ELSE
CASE WHEN @NombreItem = '' THEN '%%%' ELSE CONCAT(CAST(@NombreItem AS varchar) , '') END END)
GROUP BY a1.ITEMNMBR, a1.ITMSHNAM, a3.UOMPRICE
) as a3 ON (a2.ITEMNMBR = a3.ITEMNMBR)
WHERE a1.SOPTYPE IN (3,4) AND a1.LOCNCODE IN (@LugarVenta) AND a1.DOCDATE between @FechaDesde AND @FechaHasta
GROUP BY a2.ITEMNMBR, a3.ITMSHNAM, a2.ITEMDESC , a3.QTYONHND, a3.UOMPRICE
) as a1
) as a1
) as a1
WHERE a1.QUANTITY <> 0 OR (a1.QUANTITY = 0 AND a1.Ganancia <> 0 )
ORDER BY a1.ITEMNMBR
FROM (
SELECT a1.*, a1.valorVentaTotal - a1.valorCostoTotal as Ganancia,
CASE WHEN a1.valorVentaTotal = 0 THEN 0
ELSE ROUND( (100 * ( (a1.valorVentaTotal - a1.valorCostoTotal) / a1.valorVentaTotal) ) ,2) end as Margen
FROM (
SELECT a1.*
FROM (
SELECT a2.ITEMNMBR, a2.ITEMDESC, SUM(CASE WHEN a1.SOPTYPE = 4 THEN (a2.QUANTITY*-1) ELSE a2.QUANTITY END) as QUANTITY,
a3.QTYONHND,
SUM(CASE WHEN a1.SOPTYPE = 4 THEN (a2.XTNDPRCE*-1) ELSE a2.XTNDPRCE END) as valorVentaTotal,
SUM(CASE WHEN a1.SOPTYPE = 4 THEN (a2.EXTDCOST*-1) ELSE a2.EXTDCOST END) as valorCostoTotal,
a3.UOMPRICE, a3.ITMSHNAM
FROM SOP30200 as a1
INNER JOIN SOP30300 as a2 ON (a1.SOPNUMBE = a2.SOPNUMBE)
INNER JOIN (
SELECT a1.ITEMNMBR, a1.ITMSHNAM, a3.UOMPRICE, SUM(a2.QTYONHND) as QTYONHND
FROM IV00101 as a1 /* Maestro de item */
INNER JOIN IV00102 as a2 ON (a1.ITEMNMBR=a2.ITEMNMBR) /* Saldos de Items */
INNER JOIN IV00108 as a3 ON (a2.ITEMNMBR=a3.ITEMNMBR) /* Lista de precios */
WHERE a1.ITEMNMBR LIKE (CASE WHEN @NombreItem IS NULL THEN '%%%' ELSE
CASE WHEN @NombreItem = '' THEN '%%%' ELSE CONCAT(CAST(@NombreItem AS varchar) , '') END END)
GROUP BY a1.ITEMNMBR, a1.ITMSHNAM, a3.UOMPRICE
) as a3 ON (a2.ITEMNMBR = a3.ITEMNMBR)
WHERE a1.SOPTYPE IN (3,4) AND a1.LOCNCODE IN (@LugarVenta) AND a1.DOCDATE between @FechaDesde AND @FechaHasta
GROUP BY a2.ITEMNMBR, a3.ITMSHNAM, a2.ITEMDESC , a3.QTYONHND, a3.UOMPRICE
) as a1
) as a1
) as a1
WHERE a1.QUANTITY <> 0 OR (a1.QUANTITY = 0 AND a1.Ganancia <> 0 )
ORDER BY a1.ITEMNMBR
Comentarios
Publicar un comentario