on 11-04-2014 4:12 PM
Jovenes expertos, solicito su ayuda ya que tengo algo curioso, les explico, tengo una SP en SQL que me muestra ventas por articulo Inventario 1 e Inventario 2, las ventas me las muestra super pero cuando veo el inventario 1 no me muestra el valor que deveria de ser en el Crystal Report, y pense que el SP estaba llamando los datos equivocados, pero resulta que cuando ejecuto el SP en el SQL me muestra el dato correcto, y no se que sea y es en el 1er articulo que me muestra el resto si me muestra el dato el correcto.
Pongo un ejemplo
Item | Ventas | Inventario 1 | Inventario 2 |
---|---|---|---|
Item1 | 100 | 200 (siendo el dato correcto 50) | 100 (siendo el dato correcto 25) |
Item2 | 50 | 100 (este si es dato correcto) | 150(este si es el dato correcto) |
Espero me puedan ayudar o indicarme en donde puedo buscar el error.
De antemano muy agradecido por su ayuda y su tiempo.
Saludos Cordiales
Ayudaria mucho si muestras el SP. y compartas el cr para revisar.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Gracias Ana por tu respuesta y claro aca esta el SP y Crystal Report
Por tu ayuda o su ayuda muy agradecido perdona el Crystal no me deja subirlo en el foro asi que lo subi a un alojador.
Aca lo pueden descargar http://freakshare.com/files/pxcpd8yp/Costo-de-Ventas-CJP.rpt.html por la ayuda muy agradecido.
ALTER PROCEDURE [dbo].[_SBOSP_ANALISIS_DE_VENTAS]
-- Add the parameters for the stored procedure here
@FechaInicial DATETIME,
@FechaFinal DATETIME,
@Planta VARCHAR(8)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT ob.U_Cod_Planta, ob.itemcode, A.ItemName dscription, SUM(ob.unidades) As unidades,
ROUND(SUM(ob.total),2) as 'Total',
--,(SUM(ob.total)/Sum(ob.unidades)) precio
(
--Query para inventario 1
SELECT sum(costo)
from v_inventario_final_prod_ter t10,itm1 t11
where t11.ItemCode=t10.codigo and t10.docdate < @FechaInicial and t10.codigoplanta= @planta
and t10.codigo=A.ItemCode and t11.pricelist='1'
) [Inventario 1],
--'Costo Primo + Gastos de Fabricacion'[Costo de Produccion],
(
SELECT Sum(V_CONSUMO_Y_PRODUCCION.Costo) AS 'costo'
FROM SBO_INVERFFACSA.dbo.V_CONSUMO_Y_PRODUCCION V_CONSUMO_Y_PRODUCCION
WHERE (V_CONSUMO_Y_PRODUCCION.DueDate Between @FechaInicial And @FechaFinal) AND
(V_CONSUMO_Y_PRODUCCION.CodigoPlanta= @Planta) and
(V_CONSUMO_Y_PRODUCCION.Grupo= A.ItemCode)
)[Costo],
(
SELECT sum(T0.CmpltQty) fabricado
FROM OWOR T0 LEFT JOIN OITM T3 ON T3.ItemCode = T0.ItemCode left join OWHS T5 ON T5.WhsCode=T0.Warehouse
WHERE T0.DueDate BETWEEN @FechaInicial AND @FechaFinal and T5.U_Cod_Planta= @Planta
and T0.ItemCode=a.ItemCode
AND T0.ITEMCODE NOT IN ('MPCEMGRANEL','MPCEMGRANELCFB','D1BLO14193935')
)[Produccion_Periodo],
(
--Query para inventario 2
SELECT sum(costo)
from v_inventario_final_prod_ter t10,itm1 t11
where t11.ItemCode=t10.codigo and t10.docdate <= @FechaFinal and t10.codigoplanta= @Planta
and t10.codigo=A.ItemCode and t11.pricelist='1'
) [Inventario 2],
(
--QUERY para consumo
SELECT sum(Costo) *-1
from V_CONSUMO_Y_PRODUCCION
where DueDate between @FechaInicial and @FechaFinal and codigoplanta= @Planta
)TotalComsumos,
(--- Mano de Obra Directa
Select sum(t3.PriceBefDi ) Mano_Obra_Directa
from jdt1 t0, oact t1, opch t2,pch1 t3
where t0.account = t1.acctcode and t2.DocEntry=t0.BaseRef and t3.DocEntry=t2.DocEntry and
t3.OcrCode =t0.ProfitCode and t0.account='_SYS00000000194' AND
t2.DocDate between @FechaInicial and @FechaFinal and t3.AcctCode='_SYS00000000194' and
t0.ProfitCode=@Planta
)ManoObraDiecta,
(---- Gastos de Fabricación
SELECT Sum(V_GASTOS_INDIRECTOS.PriceBefDi) AS 'SumaGastos'
FROM SBO_INVERFFACSA.dbo.V_GASTOS_INDIRECTOS V_GASTOS_INDIRECTOS
WHERE (V_GASTOS_INDIRECTOS.CATEGORY Between '2' And '3') AND
(V_GASTOS_INDIRECTOS.DocDate Between @FechaInicial And @FechaFinal ) AND
(V_GASTOS_INDIRECTOS.profitCode=@Planta)
)[Gastos de Fabricacion],
(----Gastos Indirectos
SELECT /*V_GASTOS_INDIRECTOS.formatcode, V_GASTOS_INDIRECTOS.AcctName, */
Sum(V_GASTOS_INDIRECTOS.PriceBefDi) AS 'SumaGastos'
FROM SBO_INVERFFACSA.dbo.V_GASTOS_INDIRECTOS V_GASTOS_INDIRECTOS
WHERE (V_GASTOS_INDIRECTOS.CATEGORY Between '2' And '3')
AND (V_GASTOS_INDIRECTOS.DocDate Between @FechaInicial And @FechaFinal )
AND (V_GASTOS_INDIRECTOS.profitCode=@Planta)
)[Gastos Indirecto]
----INICIO OB---
FROM (
SELECT C.U_Cod_Planta, c.itemcode, SUM(c.unidades) unidades,
SUM(c.total) total
----INICIO C ---
FROM(
SELECT DISTINCT B.U_Cod_Planta, B.itemcode, SUM(B.unidades) unidades, SUM(total2) total
---INICIO B --
FROM(
SELECT *
---INICIO A---
FROM (
SELECT distinct T2.U_Cod_Planta,
T0.DocEntry,t0.DocNum,T1.LineNum,T1.ItemCode as 'itemcode',
T1.PackQty 'unidades',
--T1.Linetotal 'total',
--((t0.DiscPrcnt / 100)) porcentaje,
(T1.Linetotal-(((T0.DiscPrcnt / 100)) * T1.Linetotal)) total2
FROM OINV T0 INNER JOIN
INV1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
OITM T2 ON T1.ItemCode = T2.ItemCode
WHERE T0.DocDate between @FechaInicial AND @FechaFinal and T2.U_Cod_Planta=@Planta and
T0.CANCELED ='N'
GROUP BY T0.DocEntry,T0.DocNum,T1.LineNum,T1.ItemCode,/*T2.NumInCnt,T1.InvQty,*/ T1.LineTotal,
T0.DiscPrcnt, T1.PackQty, T2.U_Cod_Planta
)A
)B
GROUP BY B.itemcode, B.U_Cod_Planta
UNION ALL
SELECT DISTINCT B.U_Cod_Planta, B.itemcode, SUM(B.unidades) unidades, SUM(total2) total
FROM(
SELECT *
FROM (
SELECT DISTINCT T2.U_Cod_Planta, T0.DocEntry,T0.DocNum,T1.LineNum,T1.ItemCode as 'itemcode',
--T1.PackQty 'unidades',
CASE
WHEN T0.CANCELED IN ('N','Y') THEN -T1.PackQty
ELSE T1.PackQty
END 'unidades',
CASE
WHEN T0.CANCELED IN ('N','Y') THEN -(T1.Linetotal-(((t0.DiscPrcnt / 100)) * T1.Linetotal))
ELSE (T1.Linetotal-(((t0.DiscPrcnt / 100)) * T1.Linetotal))
END total2
FROM ORIN T0 INNER JOIN
RIN1 T1 ON T0.DocEntry = T1.DocEntry INNER JOIN
OITM T2 ON T1.ItemCode = T2.ItemCode
WHERE T0.DocDate BETWEEN @FechaInicial AND @FechaFinal and T2.U_Cod_Planta=@Planta
GROUP BY T0.DocEntry,T0.DocNum,T0.CANCELED,T1.LineNum,T1.ItemCode,/*T2.NumInCnt,T1.InvQty,*/
T1.LineTotal,T0.DiscPrcnt, T1.PackQty, T2.U_Cod_Planta
)A
)B
GROUP BY B.itemcode, B.U_Cod_Planta
)C
GROUP BY c.itemcode, C.U_Cod_Planta
----------------------------------------------------------------------------------------------
) as Ob
INNER JOIN OITM A ON A.ItemCode = ob.itemcode
GROUP BY ob.itemcode, A.ItemName, OB.U_Cod_Planta, A.ItemCode
ORDER BY itemcode
END
User | Count |
---|---|
85 | |
7 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.