Está en la página 1de 33

TO.BTL-2019-00000.

00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

Nombre Objeto : SAPFI_LOADCUADRVENTAS_F (MODIFICADO)

Descripción : Carga data para cuadratura ventas ERI 411.

Tipo : PROCEDURE

1. Functional Overview:
Carga data para cuadratura ventas ERI 411

2. Technical Specifications:

2.1. Input / Output Parameters:

Input / Output In / Out Type Mandator Default Description


Parameters y Value
in_local IN VTAHDRE
F.ORG_LV
L_CHILD
%TYPE
in_chain_id IN NUMBER

2.2. Procedure Outline:

CREATE OR REPLACE PROCEDURE SAPFI_LOADCUADRVENTAS_F (


in_local IN VTAHDREF.ORG_LVL_CHILD%TYPE,
in_chain_id IN number
)
AS

--
****************************************************************************
***********************************
-- Fecha: 20/07/2020
-- Autor: Cesar Lopez Saavedra.
-- SRF: 167736
-- Proyecto: Integracion PMM con SAP
-- Descripción: Carga los datos previos a la generacion del Inf.Cuadratura
SAP
--
BEGIN
DECLARE

----------------------------------------------------------------------------
--------------------------------
-- Declaracion Contantes

Página 1/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

----------------------------------------------------------------------------
--------------------------------
co_My_Proc_Name CONSTANT invstpee.proc_name%TYPE :=
'SAPFI_LOADCUADRVENTAS_F'; -- name SP
co_Interfaz CONSTANT varchar2(10) := 'OTC-N-
411'; -- Interfaz

----------------------------------------------------------------------------
--------------------------------
-- Declaracion Variables en General

----------------------------------------------------------------------------
--------------------------------
xSQL LONG;
l_Nro_Error NUMBER := 0; -- Numero Error
l_Msg_Error VARCHAR2(4000); -- Mensaje Error
var_dproceso CHAR(10);
flag_loop NUMBER:= 0;
var_fila VARCHAR2(5) := '';
var_mntIgvxIsc NUMBER:= 0;
l_tipo_info NUMBER:= 0;

----------------------------------------------------------------------------
--------------------------------
-- Declaracion Cursores

----------------------------------------------------------------------------
--------------------------------
CURSOR c2 IS --jerarquia /cod reporte
SELECT ORG_LVL_CHILD,
DPROCESO,

CTRANSAC,
DCOMPRA,
ORG_LVL_NUMBER,

CDOCUMENTO,

AREA_FUNCIONAL,
DECODE(min(prd_sku_type),'099',
DECODE((SELECT count(pep.NRUT) FROM VTAEMPEP pep WHERE
pep.NRUT = trim(CDOC_IDENTIDAD)),

0,DECODE(CDOCUMENTO,90,3,CODIGO_REPORTE),DECODE(CDOCUMENTO,90,5,4)),CODIGO_R
EPORTE)CODIGO_REPORTE,

DECODE(min(prd_sku_type),'013',
DECODE((SELECT count(pep.NRUT) FROM VTAEMPEP pep WHERE
pep.NRUT = trim(CDOC_IDENTIDAD)),

0,DECODE(CDOCUMENTO,90,3,CODIGO_REPORTE),DECODE(CDOCUMENTO,90,5,4)),CODIGO_R
EPORTE)CODIGO_REPORTE2,

SUM(MVENTA + MDESCTOPRD + MDESCTOPRO -MIVA -MIVA2 )MVENTA,

Página 2/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

INDICADOR_IVA,
SUM(MIVA2) MIVA2,
SUM(MIVA) MIVA

FROM (
SELECT

A.TRN_TECH_KEY, prd.prd_sku_type,
a.org_lvl_child,
A.DPROCESO,
A.NTERMINAL,
A.CTRANSAC,
A.DCOMPRA,
A.ORG_LVL_NUMBER,
A.CDOCUMENTO,

DECODE(NVL(MIN(d.prd_lvl_child),0), 0, 'J01',
NVL(prd_obt_jerarq_f(MIN(d.prd_lvl_child), 6, 1),'J01'))
Area_funcional,

nvl(fn_obtieneCodReporte('P009',A.trn_tech_key,MIN(d.prd_lvl_child),MIN(d.pr
d_lvl_ch2),MIN(d.prd_upc),A.CTRANSAC) ,1) Codigo_reporte,
SUM(d.mventa) mventa,

DECODE(sum(nvl(d.miva2,0)),0, DECODE((select count(1) from


FATXSEXPEE w where w.txs_type_exe = 2 and
w.exp_prd_lvl_child=nvl(d.prd_lvl_child,0)),0,'D3','D0'),

DECODE(SUM(nvl(d.miva1,0)),0,'D1',nvl(MIN(IMP.TXS_CODE_INDIMP),'D1')))
Indicador_iva,

NVL(DECODE(A.CTRANSAC, 30,DECODE (nvl((SELECT FB.NRUT FROM


FANCRHDREF FA, FANCROTREF FB
WHERE A.DCOMPRA = FA.DCOMPRA
AND A.NTERMINAL = FA.NTERMINAL
AND A.NSECUENCIA = FA.NSECUENCIA
AND A.ORG_LVL_CHILD = FA.ORG_LVL_CHILD
AND LENGTH(FB.NRUT) > 7
AND FA.CAUTORIZA = FB.CAUTORIZA AND ROWNUM <
2),0),0,DECODE(nvl(translate(A.cdoc_identidad,'T
0123456789','T'),'0'),'0',A.cdoc_identidad,0),
(SELECT FB.NRUT FROM FANCRHDREF FA, FANCROTREF FB
WHERE A.DCOMPRA = FA.DCOMPRA
AND A.NTERMINAL = FA.NTERMINAL
AND A.NSECUENCIA = FA.NSECUENCIA
AND A.ORG_LVL_CHILD = FA.ORG_LVL_CHILD
AND LENGTH(FB.NRUT) > 7
AND FA.CAUTORIZA = FB.CAUTORIZA AND ROWNUM < 2)),
31,DECODE (nvl((SELECT FB.NRUT FROM FANCRHDREF FA, FANCROTREF FB
WHERE A.DCOMPRA = FA.DCOMPRA
AND A.NTERMINAL = FA.NTERMINAL
AND A.NSECUENCIA = FA.NSECUENCIA
AND A.ORG_LVL_CHILD = FA.ORG_LVL_CHILD
AND LENGTH(FB.NRUT) > 7
AND FA.CAUTORIZA = FB.CAUTORIZA AND ROWNUM <

Página 3/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

2),0),0,DECODE(nvl(translate(A.cdoc_identidad,'T
0123456789','T'),'0'),'0',A.cdoc_identidad,0),
(SELECT FB.NRUT FROM FANCRHDREF FA, FANCROTREF FB
WHERE A.DCOMPRA = FA.DCOMPRA
AND A.NTERMINAL = FA.NTERMINAL
AND A.NSECUENCIA = FA.NSECUENCIA
AND A.ORG_LVL_CHILD = FA.ORG_LVL_CHILD
AND LENGTH(FB.NRUT) > 7
AND FA.CAUTORIZA = FB.CAUTORIZA AND ROWNUM < 2))
,TO_CHAR((SELECT dfc.nrutfactura FROM vtadfcef dfc WHERE
dfc.trn_tech_key=A.TRN_TECH_KEY AND ROWNUM < 2))),'0') cdoc_identidad,

--DECODE(SUM(nvl(d.miva1,0)),0,SUM(nvl(d.miva2,0)),SUM(nvl(d.miva1,0)))
miva,

DECODE(SUM(nvl(d.miva1,0)),0,SUM(nvl(d.miva2,0)),SUM(nvl(d.miva1,0))) miva,
--si hay isc monto isc, si no igv
DECODE(SUM(nvl(d.miva1,0)),0,0,SUM(nvl(d.miva2,0))) miva2, --igv
si hay isc, igv=0 si no hay isc

SUM(D.MDESCTOPRD) MDESCTOPRD,
SUM(D.MDESCTOPRO) MDESCTOPRO

FROM VTAHDREF A, VTATTRCF TTR, VTADPREF D left join PRDMSTEE PRD


ON D.prd_lvl_child=PRD.prd_lvl_child left join TXSPRDEE TPR
ON TPR.prd_lvl_child=PRD.prd_lvl_child left join TXSCODEE TXS
ON TXS.TXS_CODE_TECH_KEY = TPR.TXS_CODE_TECH_KEY left join
SAPFI_INDIMPDET IMP
ON IMP.TXS_CODE_TECH_KEY = TXS.TXS_CODE_TECH_KEY , capstree cap
WHERE A.DPROCESO = var_dproceso
AND ((in_local is null or in_local=0) or A.org_lvl_child=in_local)
AND (in_local = 139 or A.org_lvl_number NOT IN (499,822))
AND cap.cap_chain_id = in_chain_id
and cap.ORG_LVL_NUMBER = a.ORG_LVL_NUMBER
AND A.TRN_TECH_KEY = D.TRN_TECH_KEY
AND A.CESTADO = 'V'
AND A.CTRANSAC = TTR.CTRANSAC
AND TO_CHAR(NVL(a.cdocumento,0)) IN (0,1,2,3,7)
AND TO_CHAR(a.ctransac) IN (1,30,31)
/* AND A.TRN_TECH_KEY not in (select tb2.TRN_TECH_KEY from VTAHDREF
tb2,(SELECT HD.DPROCESO,HD.NTERMINAL, HD.NSECUENCIA,
HD.DCOMPRA,HD.ORG_LVL_NUMBER,HD.TCOMPROBANTE_E,HD.CSERIE_ELECTRONICA,HD.NCOM
PROBANTE
from VTAHDREF HD, capstree cap WHERE cap.cap_chain_id =
in_chain_id and HD.CESTADO = 'V' AND HD.ORG_LVL_NUMBER = cap.ORG_LVL_NUMBER
AND HD.ctransac IN (1,30,31) AND TO_CHAR(NVL(HD.cdocumento,0)) IN (1,2,3,7)
and DPROCESO = var_dproceso GROUP BY HD.DPROCESO,HD.NTERMINAL,
HD.NSECUENCIA,
HD.DCOMPRA,HD.ORG_LVL_NUMBER,HD.TCOMPROBANTE_E,HD.CSERIE_ELECTRONICA,HD.NCOM
PROBANTE
having sum(HD.MMONTO)=0) tb1 where tb2.CESTADO = 'V'
and tb2.ctransac IN (1,30,31) AND TO_CHAR(NVL(tb2.cdocumento,0)) IN
(1,2,3,7)
AND tb1.DPROCESO = tb2.DPROCESO AND tb1.NTERMINAL =
tb2.NTERMINAL AND tb1.NSECUENCIA = tb2.NSECUENCIA

Página 4/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

AND tb1.DCOMPRA = tb2.DCOMPRA AND tb1.ORG_LVL_NUMBER =


tb2.ORG_LVL_NUMBER AND tb1.TCOMPROBANTE_E = tb2.TCOMPROBANTE_E
AND tb1.CSERIE_ELECTRONICA = tb2.CSERIE_ELECTRONICA
AND tb1.NCOMPROBANTE = tb2.NCOMPROBANTE)*/
AND A.TRN_TECH_KEY not in (SELECT TRN_TECH_KEY FROM VTATEMPWW
WHERE DPROCESO = var_dproceso AND TABLA = 'VTA' AND FLAG ='E')--REENTRADA
ONLINE

GROUP BY
A.TRN_TECH_KEY,d.prd_lvl_child,
A.CDOC_IDENTIDAD,
A.DCOMPRA,
a.org_lvl_child,prd.prd_sku_type,
A.DPROCESO,
A.ORG_LVL_NUMBER,
A.CDOCUMENTO,
A.CTRANSAC,

A.NTERMINAL,
A.NSECUENCIA
ORDER BY A.ORG_LVL_NUMBER, A.DPROCESO, A.DCOMPRA, area_funcional )
GROUP BY ORG_LVL_CHILD,DPROCESO, CTRANSAC, DCOMPRA,
ORG_LVL_NUMBER, CDOCUMENTO,
AREA_FUNCIONAL,CODIGO_REPORTE, INDICADOR_IVA ,CDOC_IDENTIDAD;
c2Row c2%RowType;

CURSOR c1 IS --medio de pago


SELECT ORG_LVL_CHILD,
DPROCESO,

CTRANSAC,

DCOMPRA,
ORG_LVL_NUMBER,

DECODE(CTRANSAC,30,90,DECODE(CDOCUMENTO,3,39,2,39,NVL(CDOCUMENTO,0)))
CDOCUMENTO,
SUM(FPAY) FPAY,
SUM(EFECTIVO) EFECTIVO,
SUM(CMR) CMR,
SUM(VISA) VISA,
SUM((MC) + (GIFTCORP)) MC,
SUM(EXPRESSNET) EXPRESSNET,
SUM(DINERS) DINERS,
SUM(GIFT) GIFT,
SUM(CONTADOCHEQUE) CONTADOCHEQUE,
SUM(CCC) CCC,
SUM(VALECREDITO) VALECREDITO,
SUM(VALES_ALIM_MONTO) VALES_ALIM_MONTO,
SUM(CMRPUNTOS) CMRPUNTOS,
SUM(QUICKPAY_CRED) QUICKPAY_CRED,
SUM(QUICKPAY_DEB) QUICKPAY_DEB,
SUM(REDONDEO) REDONDEO,
SUM(VALE_CONSUMO) VALE_CONSUMO,
SUM(LINIO) LINIO,

Página 5/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

SUM(MONTOTTUS) MONTOTTUS,
SUM(GLOVO) GLOVO,
SUM(UBER) UBER,
SUM(DONACION) DONACION,
SUM(VUELTO) VUELTO ,
SUM(EXCESOVALES) EXCESOVALES --med pago
FROM (
SELECT ---Q3

a.org_lvl_child,
A.DPROCESO,

A.CTRANSAC,
A.DCOMPRA,
A.ORG_LVL_NUMBER,
A.CDOCUMENTO,
(SELECT NVL(SUM(PAY.MWALLET), 0)FROM VTAEPAYP PAY WHERE
PAY.TRN_TECH_KEY = A.TRN_TECH_KEY) AS FPAY,
(SELECT NVL(SUM(DEF.MEFECTIVO), 0) FROM VTADEFEF DEF WHERE
DEF.TRN_TECH_KEY = A.TRN_TECH_KEY) AS EFECTIVO,
(SELECT NVL(SUM(DTI.MTARJETA), 0)FROM VTADTIEF DTI WHERE
DTI.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CMR,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE where DTE.CTARJETA
= 'V' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VISA,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE where DTE.CTARJETA
= 'M' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS MC,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'A' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS EXPRESSNET,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'D' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS DINERS,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'G' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS GIFTCORP,
(SELECT NVL(SUM(DGT.MGIFT), 0) FROM VTADGTEF DGT WHERE
DGT.TRN_TECH_KEY = A.TRN_TECH_KEY) AS GIFT,
(SELECT NVL(SUM(DCE.MCCE), 0) FROM VTADCEEF DCE WHERE
DCE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CONTADOCHEQUE,
(SELECT NVL(SUM(CCC.MCCC), 0) FROM VTADCCEF CCC WHERE
CCC.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CCC,--
(SELECT NVL(SUM(DVC.MVALE), 0) FROM VTADVCEF DVC WHERE
DVC.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VALECREDITO,
(SELECT NVL(SUM(DMB.MMONTO), 0) FROM VTADMBEP DMB WHERE
DMB.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VALES_ALIM_MONTO,
(SELECT NVL(SUM(PTS.MTARJETA), 0) FROM VTAPTSEF PTS WHERE
PTS.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CMRPUNTOS,
(SELECT NVL(SUM(PQP.MQUICKPAY), 0) FROM VTAPQPEP PQP WHERE
PQP.TRN_TECH_KEY = A.TRN_TECH_KEY AND (TRIM(PQP.QPTYPEPAYMENT) = 'QPCR' and
PQP.QPTYPEPAYMENT is null )) AS QUICKPAY_CRED,
(SELECT NVL(SUM(PQP.MQUICKPAY), 0) FROM VTAPQPEP PQP WHERE
PQP.TRN_TECH_KEY = A.TRN_TECH_KEY AND TRIM(PQP.QPTYPEPAYMENT) = 'QPDB') AS
QUICKPAY_DEB,
(SELECT NVL(SUM(ADV.MREDONDEO), 0) FROM VTADVUEP ADV WHERE
ADV.TRN_TECH_KEY = A.TRN_TECH_KEY) AS REDONDEO,
(SELECT NVL(SUM(DPP.MVALECONSUMO), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VALE_CONSUMO,
(SELECT NVL(SUM(DPP.MVALELIN), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS LINIO,

Página 6/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA


= 'T' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS MONTOTTUS,
(SELECT NVL(SUM(DPP.MVALEGLV), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS GLOVO,
(SELECT NVL(SUM(DPP.MVALEUBR), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS UBER,
(SELECT NVL(SUM(DON.MDONACION), 0) FROM VTADONEP DON WHERE
DON.TRN_TECH_KEY = A.TRN_TECH_KEY) AS DONACION,
(SELECT NVL(SUM(DTE.MCASH_BACK),0) FROM VTADTEEF DTE WHERE
DTE.TRN_TECH_KEY = A.TRN_TECH_KEY AND DTE.BMATCH = 'D') VUELTO,
(SELECT NVL(SUM(DMB.MEXCESO),0) FROM VTADMBEP DMB WHERE
DMB.TRN_TECH_KEY = A.TRN_TECH_KEY ) EXCESOVALES
--med pago
FROM VTAHDREF A, VTATTRCF TTR, VTADPREF D left join PRDMSTEE PRD
ON D.prd_lvl_child=PRD.prd_lvl_child left join TXSPRDEE TPR
ON TPR.prd_lvl_child=PRD.prd_lvl_child left join TXSCODEE TXS
ON TXS.TXS_CODE_TECH_KEY = TPR.TXS_CODE_TECH_KEY left join
SAPFI_INDIMPDET IMP
ON IMP.TXS_CODE_TECH_KEY = TXS.TXS_CODE_TECH_KEY , capstree cap
WHERE A.DPROCESO = var_dproceso
AND ((in_local is null or in_local=0) or A.org_lvl_child=in_local)
AND (in_local = 139 or A.org_lvl_number NOT IN (499,822))
AND cap.cap_chain_id = in_chain_id
and cap.ORG_LVL_NUMBER = a.ORG_LVL_NUMBER
AND A.TRN_TECH_KEY = D.TRN_TECH_KEY
AND A.CESTADO = 'V'
AND A.CTRANSAC = TTR.CTRANSAC
AND TO_CHAR(NVL(a.cdocumento,0)) IN (0,1,2,3,7)
AND TO_CHAR(a.ctransac) IN (1,30,31)
/* AND A.TRN_TECH_KEY not in (select tb2.TRN_TECH_KEY from VTAHDREF
tb2,(SELECT HD.DPROCESO,HD.NTERMINAL, HD.NSECUENCIA,
HD.DCOMPRA,HD.ORG_LVL_NUMBER,HD.TCOMPROBANTE_E,HD.CSERIE_ELECTRONICA,HD.NCOM
PROBANTE
from VTAHDREF HD, capstree cap WHERE cap.cap_chain_id =
in_chain_id and HD.CESTADO = 'V' AND HD.ORG_LVL_NUMBER = cap.ORG_LVL_NUMBER
AND HD.ctransac IN (1,30,31) AND TO_CHAR(NVL(HD.cdocumento,0)) IN (1,2,3,7)
and DPROCESO = var_dproceso GROUP BY HD.DPROCESO,HD.NTERMINAL,
HD.NSECUENCIA,
HD.DCOMPRA,HD.ORG_LVL_NUMBER,HD.TCOMPROBANTE_E,HD.CSERIE_ELECTRONICA,HD.NCOM
PROBANTE
having sum(HD.MMONTO)=0) tb1 where tb2.CESTADO = 'V'
and tb2.ctransac IN (1,30,31) AND TO_CHAR(NVL(tb2.cdocumento,0)) IN
(1,2,3,7)
AND tb1.DPROCESO = tb2.DPROCESO AND tb1.NTERMINAL =
tb2.NTERMINAL AND tb1.NSECUENCIA = tb2.NSECUENCIA
AND tb1.DCOMPRA = tb2.DCOMPRA AND tb1.ORG_LVL_NUMBER =
tb2.ORG_LVL_NUMBER AND tb1.TCOMPROBANTE_E = tb2.TCOMPROBANTE_E
AND tb1.CSERIE_ELECTRONICA = tb2.CSERIE_ELECTRONICA
AND tb1.NCOMPROBANTE = tb2.NCOMPROBANTE)*/
AND A.TRN_TECH_KEY not in (SELECT TRN_TECH_KEY FROM VTATEMPWW
WHERE DPROCESO = var_dproceso AND TABLA = 'VTA' AND FLAG ='E')--REENTRADA
ONLINE
GROUP BY
A.DCOMPRA,A.TRN_TECH_KEY,
a.org_lvl_child,
A.DPROCESO,

Página 7/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

A.ORG_LVL_NUMBER,
A.CDOCUMENTO,
A.CTRANSAC
ORDER BY A.ORG_LVL_NUMBER, A.DPROCESO, A.DCOMPRA)
GROUP BY ORG_LVL_CHILD,DPROCESO, CTRANSAC, DCOMPRA,
ORG_LVL_NUMBER,CDOCUMENTO;
c1Row c1%RowType;

CURSOR c0 IS
SELECT ORG_LVL_CHILD,
DPROCESO,

CTRANSAC,
DCOMPRA,
ORG_LVL_NUMBER,

DECODE(CTRANSAC,70,DECODE(SUM(CCC),0,DECODE(CDOCUMENTO,6,5,CDOCUMENTO),
DECODE(CDOCUMENTO,5,6,CDOCUMENTO)),CDOCUMENTO) CDOCUMENTO,

AREA_FUNCIONAL,
CODIGO_REPORTE,
SUM(MVENTA+MDESCTOPRD-MIVA-MIVA2)MVENTA,
INDICADOR_IVA,

SUM(MIVA) MIVA,
SUM(MIVA2) MIVA2,
SUM(FPAY) FPAY,
SUM(EFECTIVO) EFECTIVO,
SUM(CMR) CMR,
SUM(VISA) VISA,
SUM(MC + GIFTCORP) MC,
SUM(EXPRESSNET) EXPRESSNET,
SUM(DINERS) DINERS,
SUM(GIFT) GIFT,
SUM(CONTADOCHEQUE) CONTADOCHEQUE,
SUM(CCC) CCC,
SUM(VALECREDITO) VALECREDITO,
SUM(VALES_ALIM_MONTO) VALES_ALIM_MONTO,
SUM(CMRPUNTOS) CMRPUNTOS,
SUM(QUICKPAY_CRED) QUICKPAY_CRED,
SUM(QUICKPAY_DEB) QUICKPAY_DEB,
SUM(REDONDEO) REDONDEO,
SUM(VALE_CONSUMO) VALE_CONSUMO,
SUM(LINIO) LINIO,
SUM(MONTOTTUS) MONTOTTUS,
SUM(GLOVO) GLOVO,
SUM(UBER) UBER,
SUM(DONACION) DONACION,
SUM(VUELTO) VUELTO,
SUM(EXCESOVALES) EXCESOVALES --med pago
FROM (SELECT ---

A.TRN_TECH_KEY,
a.org_lvl_child,
A.DPROCESO,

Página 8/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

A.CTRANSAC,
A.DCOMPRA,
A.ORG_LVL_NUMBER,

nvl((select distinct sfp.PAR_CODE from SAPFI_PARAM sfp


where trim(sfp.PAR_VALUE)=to_char(d.prd_upc)
and TRIM(PAR_TYPE) = 'SAPFI_GENXMLOTC411_F' and
TRIM(PAR_NOMBRE) = 'CODE_TRANSAC'
and substr(par_desc,1,2)=trim(A.CTRANSAC)
and rownum = 1),0) AS CDOCUMENTO,

'J000' Area_funcional,
1 Codigo_reporte,
0 mventa,
'' Indicador_iva,
0 miva,
0 miva2,
0 MDESCTOPRD,
0 MDESCTOPRO,
(SELECT NVL(SUM(PAY.MWALLET), 0)FROM VTAEPAYP PAY WHERE
PAY.TRN_TECH_KEY = A.TRN_TECH_KEY) AS FPAY,
(SELECT NVL(SUM(DEF.MEFECTIVO), 0) FROM VTADEFEF DEF WHERE
DEF.TRN_TECH_KEY = A.TRN_TECH_KEY) AS EFECTIVO,
DECODE(A.CTRANSAC, 51, 0 , 52, 0 , 14 , 0,
(SELECT NVL(SUM(DTI.MTARJETA), 0)FROM VTADTIEF DTI WHERE
DTI.TRN_TECH_KEY = A.TRN_TECH_KEY)) AS CMR,
SUM((SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE where
DTE.CTARJETA = 'V' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY)) AS VISA,
SUM((SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE where
DTE.CTARJETA = 'M' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY)) AS MC,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'A' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS EXPRESSNET,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'D' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS DINERS,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'G' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS GIFTCORP,
(SELECT NVL(SUM(DGT.MGIFT), 0) FROM VTADGTEF DGT WHERE
DGT.TRN_TECH_KEY = A.TRN_TECH_KEY) AS GIFT,
(SELECT NVL(SUM(DCE.MCCE), 0) FROM VTADCEEF DCE WHERE
DCE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CONTADOCHEQUE,
(SELECT NVL(SUM(CCC.MCCC), 0) FROM VTADCCEF CCC WHERE
CCC.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CCC,--
(SELECT NVL(SUM(DVC.MVALE), 0) FROM VTADVCEF DVC WHERE
DVC.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VALECREDITO,
(SELECT NVL(SUM(DMB.MMONTO), 0) FROM VTADMBEP DMB WHERE
DMB.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VALES_ALIM_MONTO,
(SELECT NVL(SUM(PTS.MTARJETA), 0) FROM VTAPTSEF PTS WHERE
PTS.TRN_TECH_KEY = A.TRN_TECH_KEY) AS CMRPUNTOS,
(SELECT NVL(SUM(PQP.MQUICKPAY), 0) FROM VTAPQPEP PQP WHERE
PQP.TRN_TECH_KEY = A.TRN_TECH_KEY AND (TRIM(PQP.QPTYPEPAYMENT) = 'QPCR' and
PQP.QPTYPEPAYMENT is null )) AS QUICKPAY_CRED,
(SELECT NVL(SUM(PQP.MQUICKPAY), 0) FROM VTAPQPEP PQP WHERE
PQP.TRN_TECH_KEY = A.TRN_TECH_KEY AND TRIM(PQP.QPTYPEPAYMENT) = 'QPDB') AS
QUICKPAY_DEB,
(SELECT NVL(SUM(ADV.MREDONDEO), 0) FROM VTADVUEP ADV WHERE

Página 9/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

ADV.TRN_TECH_KEY = A.TRN_TECH_KEY) AS REDONDEO,


(SELECT NVL(SUM(DPP.MVALECONSUMO), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS VALE_CONSUMO,
(SELECT NVL(SUM(DPP.MVALELIN), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS LINIO,
(SELECT NVL(SUM(DTE.MTARJETA), 0)FROM VTADTEEF DTE WHERE DTE.CTARJETA
= 'T' and DTE.TRN_TECH_KEY = A.TRN_TECH_KEY) AS MONTOTTUS,
(SELECT NVL(SUM(DPP.MVALEGLV), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS GLOVO,
(SELECT NVL(SUM(DPP.MVALEUBR), 0) FROM VTADPPEF DPP WHERE
DPP.TRN_TECH_KEY = A.TRN_TECH_KEY) AS UBER,
(SELECT NVL(SUM(DON.MDONACION), 0) FROM VTADONEP DON WHERE
DON.TRN_TECH_KEY = A.TRN_TECH_KEY) AS DONACION,
(SELECT NVL(SUM(DMB.MEXCESO),0) FROM VTADMBEP DMB WHERE
DMB.TRN_TECH_KEY = A.TRN_TECH_KEY ) EXCESOVALES,
(SELECT NVL(SUM(DTE.MCASH_BACK),0) FROM VTADTEEF DTE WHERE
DTE.TRN_TECH_KEY = A.TRN_TECH_KEY AND DTE.BMATCH = 'D') VUELTO
--med pago
FROM VTAHDREF A left join VTADPREF D ON A.TRN_TECH_KEY =
D.TRN_TECH_KEY left join PRDMSTEE PRD
ON D.prd_lvl_child=PRD.prd_lvl_child left join TXSPRDEE TPR
ON TPR.prd_lvl_child=PRD.prd_lvl_child left join TXSCODEE TXS
ON TXS.TXS_CODE_TECH_KEY = TPR.TXS_CODE_TECH_KEY
left join SAPFI_INDIMPDET IMP
ON IMP.TXS_CODE_TECH_KEY = TXS.TXS_CODE_TECH_KEY,VTATTRCF TTR,capstree
cap
WHERE A.DPROCESO = var_dproceso
AND ((in_local is null or in_local=0) or A.org_lvl_child=in_local)
AND (in_local = 139 or A.org_lvl_number NOT IN (499,822))
AND cap.cap_chain_id = in_chain_id
and cap.ORG_LVL_NUMBER = a.ORG_LVL_NUMBER

AND A.CESTADO = 'V'


AND A.CTRANSAC = TTR.CTRANSAC
AND NVL(a.cdocumento,0) IN (0,2)
AND TO_CHAR(a.ctransac) IN (14, 52, 70, 51, 74, 76, 79, 71)

GROUP BY
A.TRN_TECH_KEY,d.prd_lvl_child,d.prd_upc,
a.org_lvl_child,
A.DPROCESO,
A.CTRANSAC,
A.DCOMPRA,
A.ORG_LVL_NUMBER

having sum(nvl(d.mventa,a.mmonto)) <> 0


ORDER BY A.CTRANSAC, A.ORG_LVL_NUMBER, A.DPROCESO, A.DCOMPRA)

GROUP BY
ORG_LVL_CHILD,
DPROCESO,

CTRANSAC,
DCOMPRA,
ORG_LVL_NUMBER,
CDOCUMENTO,

Página 10/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

AREA_FUNCIONAL,
CODIGO_REPORTE,
INDICADOR_IVA

ORDER BY CTRANSAC, ORG_LVL_NUMBER, DPROCESO, DCOMPRA


, area_funcional;
c0Row c0%RowType;

CURSOR documentos IS
select cdr2.cod_cero,cdr2.cod_uno,cdr2.cod_dos,cdr2.cod_tres
from sapfi_cuadrvta2 cdr2 where cod_tres in (4,5) and cod_cuatro = 'F'
and flg_estado = 1;
documentosRow documentos%RowType;

CURSOR conceptos IS
select cdr2.cod_cero,cdr2.cod_uno,cdr2.cod_dos,cdr2.cod_tres
from sapfi_cuadrvta2 cdr2 where cod_tres =3 and cod_cuatro = 'F'
and flg_estado = 1;
conceptosRow conceptos%RowType;

--INSERTA LOS REGISTROS EN TABLA DE CUADRATURA


PROCEDURE INSERTA_FILA(P_DPROCESO DATE
,P_DCOMPRA DATE
,P_ORG_LVL_CHILD NUMBER
,P_NTERMINAL NUMBER
,P_COD_SECCION NUMBER
,P_COD_FILA NUMBER
,P_COD_COLUMN NUMBER
,P_MONTO NUMBER
,P_TIPINFO NUMBER
) IS

BEGIN

begin
INSERT INTO SAPFI_CUADRVTA (FEC_CARGA, FEC_PROCESO, FEC_COMPRA,
ORG_LVL_CHILD,
NTERMINAL, COD_SECCION, COD_FILA,
COD_COLUMN,
MONTO,TIP_INFO)
VALUES(sysdate, P_DPROCESO, P_DCOMPRA,
P_ORG_LVL_CHILD,
P_NTERMINAL, P_COD_SECCION, P_COD_FILA,
P_COD_COLUMN,
P_MONTO,P_TIPINFO);
exception
when others then

xSQL:= 'INSERT INTO SAPFI_CUADRVTA (FEC_CARGA, FEC_PROCESO,


FEC_COMPRA, ORG_LVL_CHILD,NTERMINAL, COD_SECCION, COD_FILA,
COD_COLUMN, MONTO,TIP_INFO) ' ||
'VALUES(' || TO_CHAR(sysdate) || ' , ' ||
TO_CHAR(P_DPROCESO) || ' , ' || TO_CHAR(P_DCOMPRA) || ' , ' ||
TO_CHAR(P_ORG_LVL_CHILD) || ' , ' ||
TO_CHAR(P_NTERMINAL) || ' , ' ||

Página 11/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

TO_CHAR(P_COD_SECCION) || ' , ' || TO_CHAR(P_COD_FILA) || ' , ' ||


TO_CHAR(P_COD_COLUMN) || ' , ' ||
TO_CHAR(P_MONTO) || ' , ' || TO_CHAR(P_TIPINFO) ||
' )';

INSERT INTO SAPFI_CUADRVTA_LOG (FEC_PROCESO, TIP_INFO,


MONTO, xSQL)
VALUES(P_DPROCESO, P_TIPINFO, P_MONTO, xSQL);

COMMIT;

end;
END INSERTA_FILA;

PROCEDURE prc_creaRegistro(P_DPROCESO CHAR


,P_DCOMPRA CHAR
,P_ORG_LVL_CHILD NUMBER
,P_NTERMINAL NUMBER
,P_COD_SECCION NUMBER
,P_COD_FILA NUMBER
,P_COD_COLUMN NUMBER
,P_MONTO NUMBER
,P_TIPINFO NUMBER) IS
BEGIN
IF(P_TIPINFO = 23)THEN
l_tipo_info:= 2;
ELSIF (P_TIPINFO = 1) THEN
l_tipo_info:= 1;
END IF;
IF(P_MONTO <> 0)THEN

INSERTA_FILA(
TO_DATE(P_DPROCESO,'dd/mm/yyyy'),
TO_DATE(P_DCOMPRA,'dd/mm/yyyy'),
P_ORG_LVL_CHILD,
P_NTERMINAL,
P_COD_SECCION,
P_COD_FILA,
P_COD_COLUMN,
TO_NUMBER(round(P_MONTO,2)),
l_tipo_info
);

END IF;
END prc_creaRegistro;

BEGIN

BEGIN
--obtencion de la fecha a procesar
Begin
select to_char(caldat-1,'dd/mm/yyyy')
into var_dproceso
from caldayee;

Página 12/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

Exception
When No_Data_Found Then var_dproceso :=
to_char(trunc(sysdate),'dd/mm/yyyy');
End;

IF(in_chain_id = 23)THEN
l_tipo_info:= 2;
ELSIF (in_chain_id = 1) THEN
l_tipo_info:= 1;
END IF;
--limpiar registros
begin
delete SAPFI_CUADRVTA where FEC_PROCESO = var_dproceso
and ((in_local is null or in_local=0) or
org_lvl_child=in_local)
and tip_info = l_tipo_info ;
COMMIT;
exception
when others then
dbms_output.put_line('Excep. limpiar regitros');
end;

--cursor c0
FOR c0Row IN c0 LOOP

--donaciones / efectivo

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,
5,67,--seccion/fila
600,TO_NUMBER(c0Row.DONACION),in_chain_id);--
columna/monto

--exceso de vales

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,
5,68,--seccion/fila
606,TO_NUMBER(c0Row.EXCESOVALES),in_chain_id);--
columna/monto

flag_loop := 0;
--ctransac cdocumento --por medio de pago

FOR documentosRow IN documentos LOOP

IF (trim(c0Row.CTRANSAC) = documentosRow.cod_uno AND


trim(c0Row.CDOCUMENTO) =documentosRow.cod_dos ) THEN

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,

Página 13/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
600,TO_NUMBER(c0Row.EFECTIVO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
603,TO_NUMBER(c0Row.CMR),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
612,TO_NUMBER(c0Row.VISA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
614,TO_NUMBER(c0Row.MC),in_chain_id);--columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
613,TO_NUMBER(c0Row.EXPRESSNET),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
615,TO_NUMBER(c0Row.DINERS),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),

Página 14/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
604,TO_NUMBER(c0Row.GIFT),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
611,TO_NUMBER(c0Row.CONTADOCHEQUE),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
609,TO_NUMBER(c0Row.CCC),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
605,TO_NUMBER(c0Row.VALECREDITO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
606,TO_NUMBER(c0Row.VALES_ALIM_MONTO +
c0Row.EXCESOVALES),in_chain_id);--columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
650,TO_NUMBER(c0Row.CMRPUNTOS),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),

Página 15/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
619,TO_NUMBER(c0Row.QUICKPAY_CRED),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
649,TO_NUMBER(c0Row.QUICKPAY_DEB),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
601,TO_NUMBER(c0Row.REDONDEO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
607,TO_NUMBER(c0Row.VALE_CONSUMO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
653,TO_NUMBER(c0Row.LINIO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
616,TO_NUMBER(c0Row.MONTOTTUS),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),

Página 16/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
652,TO_NUMBER(c0Row.GLOVO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
651,TO_NUMBER(c0Row.UBER),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c0Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c0Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c0Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
654,TO_NUMBER(c0Row.FPAY),in_chain_id);--
columna/monto
flag_loop := 1;

END IF;

EXIT WHEN flag_loop = 1;

END LOOP;
--
commit;
END LOOP;

--cursor c1
FOR c1Row IN c1 LOOP

--donaciones / efectivo

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,
5,67,--seccion/fila
600,TO_NUMBER(c1Row.DONACION),in_chain_id);--
columna/monto

--exceso de vales

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,
5,68,--seccion/fila
606,TO_NUMBER(c1Row.EXCESOVALES),in_chain_id);--
columna/monto

Página 17/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

flag_loop := 0;
--ctransac cdocumento --por medio de pago

FOR documentosRow IN documentos LOOP

IF (trim(c1Row.CTRANSAC) = documentosRow.cod_uno AND


trim(c1Row.CDOCUMENTO) =documentosRow.cod_dos ) THEN

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
600,TO_NUMBER(c1Row.EFECTIVO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
603,TO_NUMBER(c1Row.CMR),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
612,TO_NUMBER(c1Row.VISA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
614,TO_NUMBER(c1Row.MC),in_chain_id);--columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
613,TO_NUMBER(c1Row.EXPRESSNET),in_chain_id);--
columna/monto

Página 18/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
615,TO_NUMBER(c1Row.DINERS),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
604,TO_NUMBER(c1Row.GIFT),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
611,TO_NUMBER(c1Row.CONTADOCHEQUE),in_chain_id);--
columna/monto

----------------------------------------------------------------------------
----------------------
var_fila := '4';

IF(c1Row.CDOCUMENTO = 1) THEN --Factura


var_fila := '4';

ELSIF(c1Row.CDOCUMENTO = 90) THEN --NC


var_fila := '6';

ELSIF(c1Row.CDOCUMENTO = 39) THEN --Boleta


var_fila := '2';
END IF;

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(var_fila),--seccion/fila
609,TO_NUMBER(c1Row.CCC),in_chain_id);--
columna/monto

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

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),

Página 19/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
605,TO_NUMBER(c1Row.VALECREDITO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila

606,TO_NUMBER(c1Row.VALES_ALIM_MONTO ),in_chain_id);--columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
650,TO_NUMBER(c1Row.CMRPUNTOS),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
619,TO_NUMBER(c1Row.QUICKPAY_CRED),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
649,TO_NUMBER(c1Row.QUICKPAY_DEB),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
601,TO_NUMBER(c1Row.REDONDEO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,

Página 20/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
607,TO_NUMBER(c1Row.VALE_CONSUMO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
653,TO_NUMBER(c1Row.LINIO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
616,TO_NUMBER(c1Row.MONTOTTUS),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
652,TO_NUMBER(c1Row.GLOVO),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
651,TO_NUMBER(c1Row.UBER),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c1Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c1Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c1Row.ORG_LVL_CHILD),0,

TO_NUMBER(documentosRow.cod_tres),TO_NUMBER(documentosRow.cod_cero),--
seccion/fila
654,TO_NUMBER(c1Row.FPAY),in_chain_id);--
columna/monto
flag_loop := 1;

END IF;

Página 21/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

EXIT WHEN flag_loop = 1;

END LOOP;

--
commit;
END LOOP;
--fin cursor c1

--cursor c2
FOR c2Row IN c2 LOOP

--codigo de reporte --por monto e igv


flag_loop := 0;
FOR conceptosRow IN conceptos LOOP

IF (conceptosRow.cod_uno=trim(c2Row.CODIGO_REPORTE) OR
conceptosRow.cod_dos=trim(c2Row.CODIGO_REPORTE)) THEN

IF (trim(c2Row.INDICADOR_IVA) = 'D0') THEN --inafecto


IF (trim(c2Row.CODIGO_REPORTE)='4' or
trim(c2Row.CODIGO_REPORTE)='5') THEN --vinculado

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

514,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;

IF (trim(c2Row.CODIGO_REPORTE)='6' or
trim(c2Row.CODIGO_REPORTE)='7') THEN --consignacion

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

515,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--

Página 22/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

seccion/fila

513,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
END IF;

IF (trim(c2Row.INDICADOR_IVA) = 'D3') THEN --exento


IF (trim(c2Row.CODIGO_REPORTE)='4' or
trim(c2Row.CODIGO_REPORTE)='5') THEN --vinculado

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

511,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;

IF (trim(c2Row.CODIGO_REPORTE)='6' or
trim(c2Row.CODIGO_REPORTE)='7') THEN --consignacion

IF (trim(c2Row.CODIGO_REPORTE2)='4' or
trim(c2Row.CODIGO_REPORTE2)='5') THEN --vinculada

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

517,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

512,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

Página 23/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

510,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
END IF;

IF (trim(c2Row.INDICADOR_IVA) = 'D1') THEN


IF (trim(c2Row.CODIGO_REPORTE)='4' or
trim(c2Row.CODIGO_REPORTE)='5') THEN --vinculado

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

502,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;

IF (trim(c2Row.CODIGO_REPORTE)='6' or
trim(c2Row.CODIGO_REPORTE)='7') THEN --consignacion

IF (trim(c2Row.CODIGO_REPORTE2)='4' or
trim(c2Row.CODIGO_REPORTE2)='5') THEN --vinculada

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

516,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

503,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;

Página 24/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

END IF;
var_mntIgvxIsc := c2Row.MIVA;
IF (trim(c2Row.INDICADOR_IVA) = 'I1') THEN --ISC 12%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
505,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'J1') THEN --ISC 17%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
506,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'K1') THEN --ISC 20%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
507,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

Página 25/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'L1') THEN --ISC 25%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
508,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'N1') THEN --ISC 30%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
509,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;

--IGV

Página 26/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
504,TO_NUMBER(var_mntIgvxIsc),in_chain_id);--
columna/monto

flag_loop := 1;
END IF;
EXIT WHEN flag_loop = 1;
END LOOP;

IF (flag_loop=0) THEN --jerarquia


FOR conceptosRow IN conceptos LOOP
IF (conceptosRow.cod_uno=trim(c2Row.AREA_FUNCIONAL)) THEN
--jerarquia

IF (trim(c2Row.INDICADOR_IVA) = 'D0') THEN --inafecto


IF (trim(c2Row.CODIGO_REPORTE)='4' or
trim(c2Row.CODIGO_REPORTE)='5') THEN --vinculado

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

514,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSIF (trim(c2Row.CODIGO_REPORTE)='6' or
trim(c2Row.CODIGO_REPORTE)='7') THEN --consignacion

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

515,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

513,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
END IF;

Página 27/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

IF (trim(c2Row.INDICADOR_IVA) = 'D3') THEN --exento


IF (trim(c2Row.CODIGO_REPORTE)='4' or
trim(c2Row.CODIGO_REPORTE)='5') THEN --vinculado

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

511,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSIF (trim(c2Row.CODIGO_REPORTE)='6' or
trim(c2Row.CODIGO_REPORTE)='7') THEN --consignacion

IF (trim(c2Row.CODIGO_REPORTE2)='4' or
trim(c2Row.CODIGO_REPORTE2)='5') THEN --vinculada

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

517,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

512,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;

ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

510,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
END IF;

IF (trim(c2Row.INDICADOR_IVA) = 'D1') THEN


IF (trim(c2Row.CODIGO_REPORTE)='4' or
trim(c2Row.CODIGO_REPORTE)='5') THEN --vinculado

Página 28/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

502,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSIF (trim(c2Row.CODIGO_REPORTE)='6' or
trim(c2Row.CODIGO_REPORTE)='7') THEN --consignacion

IF (trim(c2Row.CODIGO_REPORTE2)='4' or
trim(c2Row.CODIGO_REPORTE2)='5') THEN --vinculada

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

516,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

503,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;

ELSE

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila

501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--columna/monto
END IF;
END IF;
var_mntIgvxIsc := c2Row.MIVA;
IF (trim(c2Row.INDICADOR_IVA) = 'I1') THEN --ISC 12%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

Página 29/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
505,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'J1') THEN --ISC 17%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
506,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'K1') THEN --ISC 20%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
507,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto

Página 30/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'L1') THEN --ISC 25%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
508,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
IF (trim(c2Row.INDICADOR_IVA) = 'N1') THEN --ISC 30%

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
509,TO_NUMBER(c2Row.MIVA),in_chain_id);--
columna/monto

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
501,TO_NUMBER(c2Row.MVENTA),in_chain_id);--
columna/monto
var_mntIgvxIsc := c2Row.MIVA2;
END IF;
--IGV

prc_creaRegistro(TO_CHAR(c2Row.DPROCESO,'dd/mm/yyyy'),TO_CHAR(c2Row.DCOMPRA,
'dd/mm/yyyy'),
TO_NUMBER(c2Row.ORG_LVL_CHILD),0,

TO_NUMBER(conceptosRow.cod_tres),TO_NUMBER(conceptosRow.cod_cero),--
seccion/fila
504,TO_NUMBER(var_mntIgvxIsc),in_chain_id);--
columna/monto

Página 31/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

flag_loop := 1;
END IF;

EXIT WHEN flag_loop = 1;


END LOOP;

END IF;
--
commit;
END LOOP;
commit;
EXCEPTION
WHEN OTHERS THEN
l_nro_error := SQLCODE;
l_msg_error := substr('Error: generar data IDC SAP ' || SQLERRM || ' '
||
DBMS_UTILITY.format_error_backtrace,1,4000);
BEGIN
raise_application_error(l_Nro_Error, l_Msg_Error);
EXCEPTION
WHEN OTHERS THEN
sapfi_errhandle(co_My_Proc_Name,co_Interfaz,0);
END;
END;

END;
END SAPFI_LOADCUADRVENTAS_F;

3. Logical Outline:
o Ninguno

4. Called From:
o Ninguno

5. Called To:
o Ninguno

6. Consideraciones de Migración:
o Ambientes:
Desarrollo PMMINTDS
Test PMMINTPETS
Producción PMMINTPEPR

7. Dependencias de Migración:

Página 32/33
TO.BTL-2019-00000.00 – SAPFI_LOADCUADRVENTAS_F PROCEDURE

Firmas

___________________ ______________________
Technical Manager Cliente Jefe proyecto Cliente

Página 33/33