Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 13

select

--K5."Remark"
K4."U_GG_SUCURSAL" as "Remark"

,K0."DocDate",K0."TaxDate",K0."DocTime"
,K0."DocEntry"
,K0."CardCode",K0."CardName"

,(
case
when K6."DiscPrcnt"= 0 then

sum((K3."LineTotal"/ K3."Quantity")* (K3."Quantity" -


K3."DelivrdQty"))
else
(

(SUM((K3."LineTotal"/K3."Quantity") * (K3."Quantity" -
K3."DelivrdQty"))-SUM((K3."LineTotal"/K3."Quantity") * (K3."Quantity" -
K3."DelivrdQty") *K0."DiscPrcnt"/100))

end
) as "venta"

,0 as "PrecioCosto"
, 1 as "Codigo"
,'ENTREGADOS FACTURADOS' as "Tipo"
,K4."SlpName"

from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."DLN1" K3 ON K3."BaseType" = 17
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = 13
inner JOIN "SBOELECTROLEG"."ODLN" K6 on K6."DocEntry"= K3."DocEntry"
where
K1."LineStatus"='C' and K0."DocStatus" = 'C'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")
and K0."DocEntry" not in (select distinct "DocEntry"
from "_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_ANULADAS_TOTALES"
where "venta"="Total"

)
and K0."DocEntry" not in (28872)
Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime",K0."CardCode"
,K0."CardName",K4."SlpName",K0."SlpCode"
,K6."DiscPrcnt",K4."U_GG_SUCURSAL"
union all

select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime"
,K0."DocEntry"
,K0."CardCode",K0."CardName"

, (

case
when K0."DiscPrcnt" = 0 then

sum(K3."LineTotal")
else
(
sum(K3."LineTotal" - (K3."LineTotal"
*K0."DiscPrcnt"/100) )
-- (SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty"))-
SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty") *K0."DiscPrcnt"/100))

)
end
) as "venta"

,0 as "PrecioCosto"
, 2 as "Codigo"
,'ENTREGADOS PARCIALMENTE FACTURADOS' as "Tipo"
,K4."SlpName"
from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."DLN1" K3 ON K3."BaseType" = 17
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = 13
where
K0."DocStatus" = 'O'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime"
,K0."CardCode",K0."CardName"
,K4."SlpName",K0."SlpCode"
,K0."DiscPrcnt",K4."U_GG_SUCURSAL"

----------------------------------------------------------------------------
union all
select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime"
, K0."DocEntry"
,K0."CardCode",K0."CardName"

, (

case
when K0."DiscPrcnt" = 0 then

sum(K3."LineTotal")
else
(
sum(K3."LineTotal" - (K3."LineTotal"
*K0."DiscPrcnt"/100) )
-- (SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty"))-
SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty") *K0."DiscPrcnt"/100))

)
end
) as "venta"

,0 as "PrecioCosto"
, 3 as "Codigo"
,'ENTREGADOS NO FACTURADOS' as "Tipo"
,K4."SlpName"
from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."DLN1" K3 ON K3."BaseType" = 17
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = -1
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
where
K1."LineStatus"='C' and K0."DocStatus" = 'C'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime"
,K0."CardCode",K0."CardName"
,K4."SlpName",K0."SlpCode",K0."DiscPrcnt",K4."U_GG_SUCURSAL"

UNION ALL

select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime"
, K0."DocEntry"
,K0."CardCode",K0."CardName"

, (

case
when K0."DiscPrcnt" = 0 then
sum((K3."LineTotal"/ K3."Quantity")* (K3."Quantity" -
K3."DelivrdQty"))
else
(

(SUM((K3."LineTotal"/K3."Quantity") * (K3."Quantity" -
K3."DelivrdQty"))-SUM((K3."LineTotal"/K3."Quantity") * (K3."Quantity" -
K3."DelivrdQty") *K0."DiscPrcnt"/100))

-- (sum((K1."LineTotal"/ K1."Quantity")*K1."OpenInvQty")) -
(sum((K1."LineTotal"/ K1."Quantity")*K1."OpenInvQty")*K0."DiscPrcnt"/100)

end
) as "venta"

,0 as "PrecioCosto"
, 7 as "Codigo"
,'ORDENESE ENTREGADOS PARCIALMENTE NO FACTURADOS' as "Tipo"
,K4."SlpName"

from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."DLN1" K3 ON K3."BaseType" = 17
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = -1
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
where
K0."DocStatus" = 'O'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime"
,K0."CardCode",K0."CardName"
,K4."SlpName",K0."SlpCode",K0."DiscPrcnt",K4."U_GG_SUCURSAL"

-------------------------------------------------------------------------
union all

select

K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime",
K0."DocEntry"
,K0."CardCode",K0."CardName"

,(
case
when K6."DiscPrcnt" = 0 then

sum((K3."LineTotal"/ K3."Quantity")* ( K3."DelivrdQty"))


else
(

(SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty"))-
SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty") *K0."DiscPrcnt"/100))

end
) as "venta"

,0 as "PrecioCosto"
, 4 as "Codigo"
,'ORDENES FACTURAS de RESERVA ENTREGADAS' as "Tipo"
,K4."SlpName"

from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."INV1" K3 ON K3."BaseType" = 17
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = 15
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
inner join "SBOELECTROLEG"."OINV" K6 ON K6."DocEntry" = K3."DocEntry"
where
--K0."DocEntry"= 2132 and
K1."LineStatus"='C' and K0."DocStatus" = 'C'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime" ,K0."CardCode"


,K0."CardName",K4."SlpName",K0."SlpCode"
,K6."DiscPrcnt",K4."U_GG_SUCURSAL"

union all

select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime",
K0."DocEntry"
,K0."CardCode",K0."CardName"
, (

case
when K6."DiscPrcnt" = 0 then

sum((K3."LineTotal"/ K3."Quantity")* (K3."OpenCreQty"))


else
(
(SUM((K3."LineTotal"/K3."Quantity") * (K3."OpenCreQty"))-
SUM((K3."LineTotal"/K3."Quantity") * (K3."OpenCreQty") *K0."DiscPrcnt"/100))

-- (SUM((K3."LineTotal"/K3."Quantity") * (K3."Quantity" - K3."DelivrdQty"))-


SUM((K3."LineTotal"/K3."Quantity") * (K3."Quantity" - K3."DelivrdQty")
*K0."DiscPrcnt"/100))

end
) as "venta"

,0 as "PrecioCosto"
, 5 as "Codigo"
,'ORDENES FACTURAS de RESERVA no ENTREGADAS' as "Tipo"
,K4."SlpName"
from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."INV1" K3 ON K3."BaseType" = 17
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
inner join "SBOELECTROLEG"."OINV" K6 ON K6."DocEntry" = K3."DocEntry"
where
K1."LineStatus"='C' and K0."DocStatus" = 'C'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime" ,K0."CardCode"


,K0."CardName",K4."SlpName",K0."SlpCode",K4."U_GG_SUCURSAL"
,K6."DiscPrcnt"

having sum (K3."OpenCreQty")!=0

---------------------------------------------------------------------------
----------------------------------------------------

union all

select

K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime",
K0."DocEntry"
,K0."CardCode",K0."CardName"

,(
case
when K0."DiscPrcnt" = 0 then
sum((K3."LineTotal"/ K3."Quantity")* ( K3."DelivrdQty"))
else
(

(SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty"))-
SUM((K3."LineTotal"/K3."Quantity") * (K3."DelivrdQty") *K0."DiscPrcnt"/100))

end
) as "venta"

,0 as "PrecioCosto"
, 41 as "Codigo"
,'ORDENES FACTURAS de RESERVA ENTREGADAS' as "Tipo"
,K4."SlpName"

from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."INV1" K3 ON K3."BaseType" = 17
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = 14
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
where
--K0."DocEntry"= 10108 and
K3."DelivrdQty">0 and
K1."LineStatus"='C' and K0."DocStatus" = 'C'
and K0."DocEntry" not in (select distinct "DocEntry" from
"_SYS_BIC"."GG_ELECTROLEG_PROD.COMPRAS/VENTAS_ORDENES_NOTAS_CREDITO_COMPLETA")

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime" ,K0."CardCode"


,K0."CardName",K4."SlpName",K0."SlpCode"
,K0."DiscPrcnt",K4."U_GG_SUCURSAL"

--revisado--
union all

select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime",
K0."DocEntry"
,K0."CardCode",K0."CardName"
--,sum((K1."LineTotal"/ K1."Quantity")*K1."OpenInvQty")

, (

case
when K0."DiscPrcnt" = 0 then sum((K1."LineTotal"/
K1."Quantity")*K1."OpenInvQty")
else
(

(sum((K1."LineTotal"/ K1."Quantity")*K1."OpenInvQty")) -
(sum((K1."LineTotal"/ K1."Quantity")*K1."OpenInvQty")*K0."DiscPrcnt"/100)

end
) as "venta"

,0 as "PrecioCosto"

, 6 as "Codigo"
,'ORDENES ABIERTAS' as "Tipo"

,K4."SlpName"
from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
and K1."OpenInvQty">0
---and K1."TargetType" = -1
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
where

K0."DocStatus" = 'O'
AND
K1."DocEntry" not in (

select T1."DocEntry" from "SBOELECTROLEG"."ADOC" T0


inner Join "SBOELECTROLEG"."ORDR" T1 on K0."DocEntry"=T1."DocEntry" where

K0."ObjType"=17 and K0."DocStatus" = 'C' and T1."DocStatus" = 'O'

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime" ,K0."CardCode"


,K0."CardName",K4."SlpName",K0."SlpCode"
,K0."DiscPrcnt",K4."U_GG_SUCURSAL"

-----------------------------------------------------------------------------------
------------
UNION ALL

select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime",
K0."DocEntry"
,K0."CardCode",K0."CardName"
, (

case
when K0."DiscPrcnt" = 0 then SUM(K1."LineTotal")
else
(SUM((K1."LineTotal"/K1."Quantity") *
(K1."Quantity" - K1."DelivrdQty"))-
SUM((K1."LineTotal"/K1."Quantity") * (K1."Quantity" - K1."DelivrdQty")
*K0."DiscPrcnt"/100))

end
) as "venta"

,0 as "PrecioCosto"

, 8 as "Codigo"
,'ORDENES ANULADAS' as "Tipo"

,K4."SlpName"
from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
and K1."OpenInvQty"=0
and K1."TargetType" = -1
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
where
K0."DocStatus" = 'C' and
K1."DocEntry" not in (

select T1."DocEntry" from "SBOELECTROLEG"."ADOC" T0


inner Join "SBOELECTROLEG"."ORDR" T1 on K0."DocEntry"=T1."DocEntry" where
K0."ObjType"=17 and K0."DocStatus" = 'C' and T1."DocStatus" = 'O'

Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime" ,K0."CardCode"


,K0."CardName",K4."SlpName",K0."SlpCode"
,K0."DiscPrcnt",K4."U_GG_SUCURSAL"

-----------------------------------------------------------------------------------
-------------------------------------

union all
select
K4."U_GG_SUCURSAL",
K0."DocDate",K0."TaxDate",K0."DocTime",
K0."DocEntry"
,K0."CardCode",K0."CardName"
,0 as "PrecioCosto"
, 9 as "Codigo"
,'NOTAS DE CREDITO' as "Tipo"
,K4."SlpName"
from "SBOELECTROLEG"."ORDR" K0
INNER JOIN "SBOELECTROLEG"."RDR1" K1 on K1."DocEntry" = K0."DocEntry"
Inner JOIN "SBOELECTROLEG"."OITM" K2 on K2."ItemCode"= K1."ItemCode"
INNER JOIN "SBOELECTROLEG"."INV1" K3 ON K3."BaseType" = 17
inner JOIN "SBOELECTROLEG"."OSLP" K4 on K4."SlpCode"= K0."SlpCode"
inner JOIN "SBOELECTROLEG"."NNM1" K5 on K5."Series"= K0."Series"
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = 14
AND K3."BaseEntry" = K0."DocEntry"
AND K3."BaseLine" =K1."LineNum" AND K3."ItemCode"=K1."ItemCode"
and K3."TargetType" = 14
inner join "SBOELECTROLEG"."RIN1" K6 on K6."BaseType" = 13 and K6."BaseEntry"=
K3."DocEntry" and K6."BaseLine"= K3."LineNum"

where
K1."LineStatus"='C' and K0."DocStatus" = 'C'
Group by K0."DocEntry",K0."DocDate",K0."TaxDate",K0."DocTime"
,K0."CardCode",K0."CardName",K4."SlpName",K0."SlpCode",K4."U_GG_SUCURSAL"

-----------------------------------------------------------------------------------
----------------------

union all

Select
L."U_GG_SUCURSAL",
A."DocDate",A."TaxDate",A."DocTime",

--,A."DocNum",
A."DocEntry"
,A."CardCode",A."CardName"
-- ,B."ItemCode"
-- ,SUM(B."Quantity")
--,J."DocTotal"-J."VatSum" as "venta"

,SUM (I."LineTotal") as "venta"


,0 as "PrecioCosto"

, 14 as "Codigo"
,'NOTAS DE CREDITO 1' as "Tipo"

,L."SlpName"

--,1 as "Ingreso"
--, SUM(B."Quantity" * B."GrossBuyPr") /sum(B."Quantity") as "CostoUnitario"

From "SBOELECTROLEG"."ORDR" A
Inner Join "SBOELECTROLEG"."RDR1" B on A."DocEntry" = B."DocEntry"
INNER Join "SBOELECTROLEG"."DLN1" C on C."BaseType" = 17 and C."BaseEntry" =
B."DocEntry" and C."BaseLine" = B."LineNum"
INNER Join "SBOELECTROLEG"."ODLN" D on C."DocEntry" = D."DocEntry" and
D."CANCELED" = 'N'
INNER Join "SBOELECTROLEG"."INV1" E on E."BaseType" = 15 and E."BaseEntry" =
C."DocEntry" and E."BaseLine" = C."LineNum"
INNER Join "SBOELECTROLEG"."OINV" F on E."DocEntry" = F."DocEntry" and
F."CANCELED" = 'N'
inner join "SBOELECTROLEG"."RIN1" I on E."DocEntry" = I."BaseEntry" and
E."LineNum" = I."BaseLine" and E."ObjType" = I."BaseType"
INNER JOIN "SBOELECTROLEG"."ORIN" J on J."DocEntry" = I."DocEntry"
INNER Join "SBOELECTROLEG"."OITM" G on B."ItemCode" = G."ItemCode"
INNER Join "SBOELECTROLEG"."OITB" H on G."ItmsGrpCod" = H."ItmsGrpCod"
inner JOIN "SBOELECTROLEG"."NNM1" K on K."Series"= A."Series"
inner JOIN "SBOELECTROLEG"."OSLP" L on L."SlpCode"= A."SlpCode"
where
-- (A."DocTotal"-A."VatSum") = (J."DocTotal"-J."VatSum") and

A."DocEntry" not in (232,4907,6853,9431,9436,


9855,9864,9865,10982,11967,28026,27468
) and
A."DocStatus" = 'C'
Group by

L."U_GG_SUCURSAL",
A."DocDate",A."TaxDate",A."DocTime",
A."DocEntry"
,A."CardCode",A."CardName"
,J."DocTotal",J."VatSum",L."SlpName",A."DocNum"

union all

Select
L."U_GG_SUCURSAL"
,
A."DocDate",A."TaxDate",A."DocTime",
--,A."DocNum",
A."DocEntry"
,A."CardCode",A."CardName"
--,B."ItemCode"
--,SUM(B."Quantity")
--,J."DocTotal"-J."VatSum" as "venta"

,sum(B."LineTotal")/2
,0 as "PrecioCosto"

, 13 as "Codigo"
,'NOTAS DE CREDITO 1' as "Tipo"

,L."SlpName"

--,1 as "Ingreso"
--, SUM(B."Quantity" * B."GrossBuyPr") /sum(B."Quantity") as "CostoUnitario"

From "SBOELECTROLEG"."ORDR" A
Inner Join "SBOELECTROLEG"."RDR1" B on A."DocEntry" = B."DocEntry"
INNER Join "SBOELECTROLEG"."DLN1" C on C."BaseType" = 17 and C."BaseEntry" =
B."DocEntry" and C."BaseLine" = B."LineNum"
INNER Join "SBOELECTROLEG"."ODLN" D on C."DocEntry" = D."DocEntry" and
D."CANCELED" = 'N'
INNER Join "SBOELECTROLEG"."INV1" E on E."BaseType" = 15 and E."BaseEntry" =
C."DocEntry" and E."BaseLine" = C."LineNum"
INNER Join "SBOELECTROLEG"."OINV" F on E."DocEntry" = F."DocEntry" and
F."CANCELED" = 'N'
inner join "SBOELECTROLEG"."RIN1" I on E."DocEntry" = I."BaseEntry" and
E."LineNum" = I."BaseLine" and E."ObjType" = I."BaseType"
INNER JOIN "SBOELECTROLEG"."ORIN" J on J."DocEntry" = I."DocEntry"
INNER Join "SBOELECTROLEG"."OITM" G on B."ItemCode" = G."ItemCode"
INNER Join "SBOELECTROLEG"."OITB" H on G."ItmsGrpCod" = H."ItmsGrpCod"
inner JOIN "SBOELECTROLEG"."NNM1" K on K."Series"= A."Series"
inner JOIN "SBOELECTROLEG"."OSLP" L on L."SlpCode"= A."SlpCode"
where
-- (A."DocTotal"-A."VatSum") = (J."DocTotal"-J."VatSum") and

A."DocEntry" in (232,4907,6853)

and
A."DocStatus" = 'C'
Group by

L."U_GG_SUCURSAL",
A."DocDate",A."TaxDate",A."DocTime",
A."DocEntry"
,A."CardCode",A."CardName"
,L."SlpName",A."DocNum"

union all

Select
--K."Remark"
L."U_GG_SUCURSAL"
,
A."DocDate",A."TaxDate",A."DocTime",
--,A."DocNum",
A."DocEntry"
,A."CardCode",A."CardName"
--,I."ItemCode"
--,SUM(I."Quantity")
--,J."DocTotal"-J."VatSum" as "venta"

,sum(I."LineTotal")
,0 as "PrecioCosto"

, 12 as "Codigo"
,'NOTAS DE CREDITO 1' as "Tipo"

,L."SlpName"

--,1 as "Ingreso"
--, SUM(B."Quantity" * B."GrossBuyPr") /sum(B."Quantity") as "CostoUnitario"

From "SBOELECTROLEG"."ORDR" A
Inner Join "SBOELECTROLEG"."RDR1" B on A."DocEntry" = B."DocEntry"
INNER Join "SBOELECTROLEG"."DLN1" C on C."BaseType" = 17 and C."BaseEntry" =
B."DocEntry" and C."BaseLine" = B."LineNum"
INNER Join "SBOELECTROLEG"."ODLN" D on C."DocEntry" = D."DocEntry" and
D."CANCELED" = 'N'
INNER Join "SBOELECTROLEG"."INV1" E on E."BaseType" = 15 and E."BaseEntry" =
C."DocEntry" and E."BaseLine" = C."LineNum"
INNER Join "SBOELECTROLEG"."OINV" F on E."DocEntry" = F."DocEntry" and
F."CANCELED" = 'N'
inner join "SBOELECTROLEG"."RIN1" I on E."DocEntry" = I."BaseEntry" and
E."LineNum" = I."BaseLine" and E."ObjType" = I."BaseType"
INNER JOIN "SBOELECTROLEG"."ORIN" J on J."DocEntry" = I."DocEntry"
INNER Join "SBOELECTROLEG"."OITM" G on B."ItemCode" = G."ItemCode"
INNER Join "SBOELECTROLEG"."OITB" H on G."ItmsGrpCod" = H."ItmsGrpCod"
inner JOIN "SBOELECTROLEG"."NNM1" K on K."Series"= A."Series"
inner JOIN "SBOELECTROLEG"."OSLP" L on L."SlpCode"= A."SlpCode"
where
-- (A."DocTotal"-A."VatSum") = (J."DocTotal"-J."VatSum") and

A."DocEntry" in (9431,9436,9855,9864,9865,10982,11967)

and
A."DocStatus" = 'C'
Group by
L."U_GG_SUCURSAL",
A."DocDate",A."TaxDate",A."DocTime",
A."DocEntry"
,A."CardCode",A."CardName"
,L."SlpName",A."DocNum"
;

You might also like