1. Function SY_ALP_IN_PK_DETALLE_DOCUMENTO(p_tipo in varchar2,p_transaction_id in
number,
p_codigo_articulo in varchar2,p_organizacion in varchar2, p_data in
varchar2 )
return VARCHAR2 is
TIPO_GUIA VARCHAR2(150):='';
p_source_header_id APPS.wsh_delivery_details.source_header_id
%TYPE;
P_deliver_to_location_id
APPS.wsh_delivery_details.deliver_to_location_id%TYPE;
P_group_number APPS.wsh_delivery_details.attribute1%TYPE;
P_organization_id APPS.wsh_delivery_details.organization_id
%TYPE;
P_org_id APPS.wsh_delivery_details.org_id%TYPE;
ln_customer_id APPS.wsh_delivery_details.customer_id%TYPE := 0;
lv_customer_id varchar2(150) := NULL;
ln_delivery_detail_id
APPS.wsh_inv_delivery_details_v.delivery_detail_id%TYPE := 0;
P_FECHA1 DATE;
P_FECHA2 DATE;
CP_NRO_GUIA varchar2(15) ;
CP_NRO_FACTURA varchar(15);
CP_FECHA_FACTURA date ;
CP_NRO_PEDIDO varchar2(150) ;
CP_CUSTOMER_NAME varchar2(50);
BEGIN
--CP_NRO_GUIA:= NULL;
IF p_tipo='OM' THEN
/* SI mmt.source_line_id = mmt.trx_source_line_id
ENTONCES mmt.picking_line_id, mmt.trx_source_delivery_id,
mmt.source_code IS NOT NULL */
BEGIN
SELECT mmt.picking_line_id
delivery_detail_id
INTO ln_delivery_detail_id
FROM mtl_material_transactions mmt
WHERE mmt.source_line_id =
mmt.trx_source_line_id
AND mmt.transaction_id =
p_transaction_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
/* SI mmt.source_line_id <>
mmt.trx_source_line_id
ENTONCES mmt.picking_line_id,
mmt.trx_source_delivery_id, mmt.source_code IS NULL */
BEGIN
SELECT
min(nvl(delivery_detail_id,0)) ln_delivery_detail_id
INTO ln_delivery_detail_id
FROM mtl_material_transactions
mmt
,apps.wsh_inv_delivery_details_v widd
WHERE mmt.source_line_id
<> mmt.trx_source_line_id
AND mmt.trx_source_line_id
= widd.oe_line_id
AND mmt.source_line_id =
widd.move_order_line_id
AND mmt.transaction_id
3. END;
/* INFORAMCION DE FECHA FACTURA*/
begin
select DISTINCT nvl(TRUNC(rctpv.TRX_DATE),
TRUNC(sysdate))
INTO P_FECHA1
from WSH_DELIVERABLES_V wdv,
WSH_NEW_DELIVERIES_V wndv,
RA_CUSTOMER_TRX_PARTIAL_V rctpv
where wdv.RELEASED_STATUS = 'C'
and wdv.oe_interfaced_flag = 'Y'
and wdv.source_code = 'OE'
and WDV.delivery_id = WNDV.delivery_id
and wndv.name = rctpv.trx_number (+)
and wndv.customer_id = rctpv.bill_to_customer_id
(+)
AND WDV.delivery_detail_id =
ln_delivery_detail_id;
EXCEPTION
WHEN OTHERS THEN
P_FECHA1 := NULL;
END;
BEGIN
SELECT 'GUIA ' || SUBSTR(MT_DESCRIPCION_MOTIVO,1,20) TIPO_DOC
,NRO_GUIA
,nro_factura
,fecha_factura
INTO TIPO_guia
,CP_NRO_GUIA
,CP_NRO_FACTURA
,P_FECHA2
FROM al_guias_datos_adicionales
WHERE source_header_id = p_source_header_id
AND deliver_to_location_id = p_deliver_to_location_id
AND group_number = p_group_number
AND organization_id = p_organization_id
AND org_id = p_org_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN
/* SRW.MESSAGE('13','GUIA OM NO_DATA_FOUND
'||'p_source_header_id: '||p_source_header_id
||',p_deliver_to_location_id: '||p_deliver_to_location_id
||',p_group_number: '||
p_group_number
||',p_organization_id: '||
p_organization_id
||',p_org_id: '||p_org_id
);*/
raise_application_error(-20002,'GUIA OM NO_DATA_FOUND
'||'p_source_header_id: '||p_source_header_id
||',p_deliver_to_location_id: '||p_deliver_to_location_id
||',p_group_number: '||
p_group_number
||',p_organization_id: '||
p_organization_id
||',p_org_id: '||p_org_id ||
sqlerrm);
WHEN TOO_MANY_ROWS THEN
4. /* SRW.MESSAGE('14','GUIA OM TOO_MANY_ROWS
'||'p_source_header_id: '||p_source_header_id
||',p_deliver_to_location_id: '||p_deliver_to_location_id
||',p_group_number: '||
p_group_number
||',p_organization_id: '||
p_organization_id
||',p_org_id: '||p_org_id
);*/
raise_application_error(-20002,'GUIA OM NO_DATA_FOUND
'||'p_source_header_id: '||p_source_header_id
||',p_deliver_to_location_id: '||p_deliver_to_location_id
||',p_group_number: '||
p_group_number
||',p_organization_id: '||
p_organization_id
||',p_org_id: '||p_org_id ||
sqlerrm);
WHEN OTHERS THEN
/* SRW.MESSAGE('15','GUIA OM OTHERS '||'p_source_header_id: '||
p_source_header_id
||',p_deliver_to_location_id: '||p_deliver_to_location_id
||',p_group_number: '||
p_group_number
||',p_organization_id: '||
p_organization_id
||',p_org_id: '||p_org_id
);*/
raise_application_error(-20002,'GUIA OM NO_DATA_FOUND
'||'p_source_header_id: '||p_source_header_id
||',p_deliver_to_location_id: '||p_deliver_to_location_id
||',p_group_number: '||
p_group_number
||',p_organization_id: '||
p_organization_id
||',p_org_id: '||p_org_id ||
sqlerrm);
END;
IF P_FECHA1 IS NOT NULL
THEN CP_FECHA_FACTURA := P_FECHA1;
ELSE CP_FECHA_FACTURA := P_FECHA2;
END IF;
END IF;
IF p_tipo='INV' THEN
IF p_transaction_id IS NOT NULL THEN
BEGIN
SELECT SUBSTR(ATTRIBUTE_CATEGORY,1,25) ATTRIBUTE_CATEGORY --
tipo documento (guia)
, ATTRIBUTE10 -- nro de documento (guia)
, ATTRIBUTE4 -- customer_id
INTO TIPO_GUIA
,CP_NRO_GUIA
,lv_customer_id
from mtl_material_transactions
where transaction_id=p_transaction_id;
5. EXCEPTION
WHEN OTHERS THEN
/* SRW.MESSAGE('20','DELIVERY OTHERS '
|| ' TRANSACTION_ID: ' || p_transaction_id
|| ' CODIGO_ARTICULO: ' || p_codigo_articulo
|| ' ORGANIZACION: ' || p_organizacion
);*/
raise_application_error(-20002,'DELIVERY OTHERS '
|| ' TRANSACTION_ID: ' || p_transaction_id
|| ' CODIGO_ARTICULO: ' || p_codigo_articulo
|| ' ORGANIZACION: ' || p_organizacion ||sqlerrm);
END;
END IF;
END IF;
/* INFORMACION DEL CLIENTE*/
BEGIN
if lv_customer_id is not null then
ln_customer_id := to_number(lv_customer_id);
end if;
SELECT SUBSTR(C.CUSTOMER_NAME,1,30) CUSTOMER_NAME
INTO CP_CUSTOMER_NAME
FROM AR_CUSTOMERS_V C
WHERE C.CUSTOMER_ID = ln_customer_id;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
IF p_data='NRO_GUIA' THEN
return CP_NRO_GUIA;
ELSIF p_data='NRO_FACTURA' THEN
RETURN CP_NRO_FACTURA;
ELSIF p_data='FECHA_FACTURA' THEN
return to_char(CP_FECHA_FACTURA,'DD/MM/RRRR');
ELSIF p_data='NRO_PEDIDO' THEN
RETURN CP_NRO_PEDIDO ;
ELSIF p_data='CUSTOMER_NAME' THEN
RETURN CP_CUSTOMER_NAME;
END IF;
EXCEPTION
WHEN OTHERS THEN
return(NULL);
--RETURN CP_NRO_GUIA;
end SY_ALP_IN_PK_DETALLE_DOCUMENTO;
function SY_CF_ValorizadoInicialFormula(p_cuenta in varchar2
,p_unegocio in varchar2 ,p_codigo_articulo in varchar2,p_almacen in
number
,p_fecdesde in date , p_fechasta IN DATE)
return Number is
Ntotal number;
BEGIN
6. SELECT SUM(saldo_cantidad) valorizado_inic
INTO ntotal
FROM (
SELECT sum(mta_SI.base_transaction_value) saldo_cantidad
FROM
sy_altr_in_txns_kardex_val mmt_si --MCO 05/11/04
,mtl_transaction_accounts mta_SI
,mtl_system_items_b msib
,mtl_secondary_inventories msi1 --MCO 04/11/04
,gl_code_combinations gcc1 --MCO 04/11/04
WHERE mmt_SI.transaction_id = mta_SI.transaction_id(+)
AND (mta_SI.accounting_line_type = 1 or mta_SI.accounting_line_type is
null)
AND mmt_si.inventory_item_id = msib.inventory_item_id
AND mmt_si.organization_id = msib.organization_id
and mmt_si.subinventory_code = msi1.secondary_inventory_name
--OJO
AND mmt_si.organization_id = msi1.organization_id
--MCO 04/11/04
AND gcc1.code_combination_id = msi1.attribute2
--MCO 04/11/04
AND (gcc1.segment2 = P_CUENTA OR P_CUENTA IS NULL )
--MCO 04/11/04
AND (gcc1.segment4 = P_UNEGOCIO OR P_UNEGOCIO IS NULL )
--MCO 04/11/04
AND msib.segment1 ||'-'||msib.segment2 = p_codigo_articulo--CODIGO_ARTICULO
AND mmt_si.organization_id = P_ALMACEN
AND mmt_si.transaction_id < (
SELECT
MIN(transaction_id)
FROM
mtl_material_transactions mmt,
mtl_secondary_inventories msi,
gl_code_combinations gcc
-- mtl_transaction_accounts mta -- rb 12/10/04 --MCO 05/11/04
WHERE
--mmt.transaction_id = mta.transaction_id(+) --MCO
--and (mta.accounting_line_type = 1 or mta.accounting_line_type is null)
mmt.inventory_item_id = msib.inventory_item_id
and mmt.organization_id = msib.organization_id
and mmt.subinventory_code = msi.secondary_inventory_name
and mmt.organization_id = msi.organization_id
--MCO 03/11/04
and gcc.code_combination_id = msi.attribute2
-- Condiciones del Kardex
--AND mmt.organization_id = 382--P_ALMACEN
--MCO 03/11/04
AND (gcc.segment2 = P_CUENTA OR P_CUENTA IS NULL )
AND (gcc.segment4 = P_UNEGOCIO OR P_UNEGOCIO IS NULL ) -- Tiene
valores sólo para Alprosa
AND (TO_CHAR(trunc(mmt.transaction_date ),'YYYY/MM/DD') between
TO_CHAR(P_FECDESDE ,'YYYY/MM/DD') and TO_CHAR(P_FECHASTA,'YYYY/MM/DD') )
)
/*Transferencia entre almacenes*/
UNION
SELECT sum(nvl(mta_SI.base_transaction_value,0)) saldo_cantidad
FROM
sy_altr_in_txns_kardex_val mmt_si --MCO 05/11/04
,mtl_transaction_accounts mta_SI
,mtl_system_items_b msib
,mtl_secondary_inventories msi1 --MCO 04/11/04
,gl_code_combinations gcc1 --MCO 04/11/04
7. WHERE mmt_SI.transaction_id = mta_SI.transaction_id(+)
AND (mta_SI.accounting_line_type <> 1)
AND mmt_si.inventory_item_id = msib.inventory_item_id
AND mmt_si.organization_id = msib.organization_id
and mmt_si.subinventory_code = msi1.secondary_inventory_name
--OJO
AND mmt_si.organization_id = msi1.organization_id
--MCO 04/11/04
AND gcc1.code_combination_id = msi1.attribute2
--MCO 04/11/04
AND (gcc1.segment2 = P_CUENTA OR P_CUENTA IS NULL )
--MCO 04/11/04
AND (gcc1.segment4 = P_UNEGOCIO OR P_UNEGOCIO IS NULL )
--MCO 04/11/04
AND mmt_si.transaction_source_type_id IN (13) --MCO 05/11/04
AND mmt_si.transaction_action_id IN (2,3,12,21) --MCO 05/11/04
AND msib.segment1 ||'-'||msib.segment2 = P_CODIGO_ARTICULO
AND mmt_si.organization_id = P_ALMACEN
AND mmt_si.transaction_id < (
SELECT
MIN(transaction_id)
FROM
mtl_material_transactions mmt,
mtl_secondary_inventories msi,
gl_code_combinations gcc
--mtl_transaction_accounts mta -- rb 12/10/04 --MCO 05/11/04
WHERE
--mmt.transaction_id = mta.transaction_id(+) --MCO
--and (mta.accounting_line_type = 1 or mta.accounting_line_type is null)
--MCO 05/11/04
mmt.inventory_item_id = msib.inventory_item_id
and mmt.organization_id = msib.organization_id
and mmt.subinventory_code = msi.secondary_inventory_name
and mmt.organization_id = msi.organization_id
--MCO 03/11/04
and gcc.code_combination_id = msi.attribute2
-- Condiciones del Kardex
--AND mmt.organization_id = 382--P_ALMACEN
--MCO 03/11/04
AND (gcc.segment2 = P_CUENTA OR P_CUENTA IS NULL )
AND (gcc.segment4 = P_UNEGOCIO OR P_UNEGOCIO IS NULL ) -- Tiene
valores sólo para Alprosa
AND (TO_CHAR(trunc(mmt.transaction_date ),'YYYY/MM/DD') between
TO_CHAR(P_FECDESDE ,'YYYY/MM/DD') and TO_CHAR(P_FECHASTA,'YYYY/MM/DD') )
))
;
IF ntotal is null THEN
Begin
SELECT SUM(saldo_cantidad) valorizado_inic
INTO ntotal
FROM (
SELECT sum(mta_SI.base_transaction_value)
saldo_cantidad
FROM
sy_altr_in_txns_kardex_val mmt_si --MCO
05/11/04
,mtl_transaction_accounts mta_SI
,mtl_system_items_b msib
,mtl_secondary_inventories msi1 --MCO 04/11/04
,gl_code_combinations gcc1 --MCO 04/11/04
WHERE mmt_SI.transaction_id = mta_SI.transaction_id(+)
8. AND (mta_SI.accounting_line_type = 1 or
mta_SI.accounting_line_type is null)
AND mmt_si.inventory_item_id =
msib.inventory_item_id
AND mmt_si.organization_id =
msib.organization_id
and mmt_si.subinventory_code =
msi1.secondary_inventory_name --OJO
AND mmt_si.organization_id =
msi1.organization_id --MCO 04/11/04
AND gcc1.code_combination_id =
msi1.attribute2 --MCO 04/11/04
AND (gcc1.segment2 =
P_CUENTA OR P_CUENTA IS NULL ) --MCO 04/11/04
AND (gcc1.segment4 =
P_UNEGOCIO OR P_UNEGOCIO IS NULL ) --MCO 04/11/04
AND msib.segment1 ||'-'||msib.segment2 =
P_CODIGO_ARTICULO
AND mmt_si.organization_id =
P_ALMACEN
AND mmt_si.transaction_id <= (
SELECT
MAX(transaction_id)
FROM
mtl_material_transactions mmt,
mtl_secondary_inventories msi,
gl_code_combinations gcc
WHERE
mmt.inventory_item_id =
msib.inventory_item_id
and mmt.organization_id = msib.organization_id
and mmt.subinventory_code = msi.secondary_inventory_name
and mmt.organization_id = msi.organization_id --MCO
03/11/04
and gcc.code_combination_id = msi.attribute2
-- Condiciones del Kardex
AND (gcc.segment2 = P_CUENTA OR P_CUENTA IS NULL )
AND (gcc.segment4 = P_UNEGOCIO OR P_UNEGOCIO IS NULL ) -- Tiene valores
sólo para Alprosa
AND (TO_CHAR(trunc(mmt.transaction_date ),'YYYY/MM/DD') <=
TO_CHAR(P_FECDESDE,'YYYY/MM/DD') )
)
/*Transferencia entre almacenes*/
UNION
SELECT sum(nvl(mta_SI.base_transaction_value,0)) saldo_cantidad
FROM
sy_altr_in_txns_kardex_val mmt_si --MCO 05/11/04
,mtl_transaction_accounts mta_SI
9. ,mtl_system_items_b msib
,mtl_secondary_inventories msi1 --MCO 04/11/04
,gl_code_combinations gcc1 --MCO 04/11/04
WHERE mmt_SI.transaction_id = mta_SI.transaction_id(+)
AND (mta_SI.accounting_line_type <> 1)
AND mmt_si.inventory_item_id =
msib.inventory_item_id
AND mmt_si.organization_id =
msib.organization_id
and mmt_si.subinventory_code =
msi1.secondary_inventory_name --OJO
AND mmt_si.organization_id =
msi1.organization_id --MCO 04/11/04
AND gcc1.code_combination_id =
msi1.attribute2 --MCO 04/11/04
AND (gcc1.segment2 = P_CUENTA
OR P_CUENTA IS NULL ) --MCO 04/11/04
AND (gcc1.segment4 =
P_UNEGOCIO OR P_UNEGOCIO IS NULL ) --MCO 04/11/04
AND mmt_si.transaction_source_type_id IN (13)
--MCO 05/11/04
AND mmt_si.transaction_action_id IN (2,3,12,21)
--MCO 05/11/04
AND msib.segment1 ||'-'||msib.segment2 =
P_CODIGO_ARTICULO
AND mmt_si.organization_id =
P_ALMACEN
AND mmt_si.transaction_id <= (
SELECT
MAX(transaction_id)
FROM
mtl_material_transactions mmt,
mtl_secondary_inventories msi,
gl_code_combinations gcc
WHERE
mmt.inventory_item_id = msib.inventory_item_id
and mmt.organization_id =
msib.organization_id
and mmt.subinventory_code = msi.secondary_inventory_name
and mmt.organization_id = msi.organization_id --MCO
03/11/04
and gcc.code_combination_id = msi.attribute2
-- Condiciones del Kardex
AND (gcc.segment2 = P_CUENTA OR P_CUENTA IS NULL )
AND (gcc.segment4 = P_UNEGOCIO OR P_UNEGOCIO IS NULL ) -- Tiene valores
sólo para Alprosa
AND (TO_CHAR(trunc(mmt.transaction_date ),'YYYY/MM/DD') <=
TO_CHAR(P_FECDESDE,'YYYY/MM/DD') )
11. BEGIN
SELECT MEANING
INTO l_translated_string
FROM FND_LOOKUP_VALUES
WHERE LOOKUP_CODE = P_LOOKUP_CODE
AND LOOKUP_TYPE = P_LOOKUP_TYPE
AND LANGUAGE = P_LANGUAGE
AND ROWNUM = 1;
RETURN l_translated_string;
END iec_get_translated_fnd_lookup;
FUNCTION Iec_GetPredictedExhaustion
( p_rec_remain IN NUMBER
, p_rec_called_removed IN NUMBER
, p_start_time IN DATE
, p_sysdate IN DATE)
RETURN DATE
IS
l_pred_exhaust DATE;
BEGIN
BEGIN
IF p_start_time IS NOT NULL AND ((p_sysdate - p_start_time)
> (8/24)) THEN
l_pred_exhaust := p_sysdate + (p_rec_remain * (1 /
(p_rec_called_removed / Iec_CleanDivisor(p_sysdate - p_start_time))));
ELSE
-- not enough data to compute predicted exhaustion
l_pred_exhaust := NULL;
END IF;
EXCEPTION
WHEN OTHERS THEN
l_pred_exhaust := NULL;
END;
RETURN l_pred_exhaust;
END;
FUNCTION Iec_GetPhoneCountryCodeDisplay(p_phone_country_code IN NUMBER)
RETURN VARCHAR2
IS
l_display_str VARCHAR2(4000);
l_country_col SYSTEM.varchar_tbl_type;
BEGIN
IF p_phone_country_code = 1 THEN
SELECT TERRITORY_SHORT_NAME
BULK COLLECT INTO l_country_col
FROM FND_TERRITORIES_VL
WHERE TERRITORY_CODE IN ('US', 'CA')
ORDER BY TERRITORY_SHORT_NAME;
l_display_str := '1 - (North American Numbering Plan - '
|| l_country_col(1)
|| ', ' || l_country_col(2) || ')';
RETURN l_display_str;
END IF;
SELECT TERRITORY_SHORT_NAME
BULK COLLECT INTO l_country_col
FROM FND_TERRITORIES_VL A, HZ_PHONE_COUNTRY_CODES B
12. WHERE A.TERRITORY_CODE = B.TERRITORY_CODE
AND B.PHONE_COUNTRY_CODE = p_phone_country_code
ORDER BY TERRITORY_SHORT_NAME;
l_display_str := p_phone_country_code;
IF l_country_col IS NOT NULL AND l_country_col.COUNT > 0 THEN
l_display_str := l_display_str || ' - (' ||
l_country_col(1);
FOR i IN 2..l_country_col.LAST LOOP
l_display_str := l_display_str || ', ' ||
l_country_col(i);
END LOOP;
l_display_str := l_display_str || ')';
END IF;
RETURN l_display_str;
END;
FUNCTION Iec_GetLocationHeirarchy(p_loc_id IN NUMBER)
RETURN VARCHAR2
IS
l_loc_name VARCHAR2(500);
l_loc_type VARCHAR2(500);
l_loc_id NUMBER(15);
l_parent_loc_id NUMBER(15);
l_heirarchy_str VARCHAR2(4000);
BEGIN
-- Get name for location of leaf node
SELECT LOCATION_AREA_NAME, PARENT_LOCATION_AREA_ID
INTO l_loc_name, l_parent_loc_id
FROM JTF_LOC_AREAS_VL
WHERE LOCATION_AREA_ID = p_loc_id;
l_heirarchy_str := l_loc_name;
l_loc_id := l_parent_loc_id;
WHILE l_loc_id IS NOT NULL LOOP
SELECT LOCATION_AREA_NAME, LOCATION_TYPE_CODE,
PARENT_LOCATION_AREA_ID
INTO l_loc_name, l_loc_type, l_parent_loc_id
FROM JTF_LOC_AREAS_VL
WHERE LOCATION_AREA_ID = l_loc_id;
l_heirarchy_str := l_loc_name || '/' || l_heirarchy_str;
l_loc_id := l_parent_loc_id;
EXIT WHEN L_loc_type = 'AREA1';
END LOOP;
RETURN l_heirarchy_str;
END;
FUNCTION Iec_CleanDivisor(p_divisor IN NUMBER)
RETURN NUMBER
IS
l_clean_divisor NUMBER;
BEGIN
-- If divisor is 0, then return null
IF p_divisor <> 0 THEN
l_clean_divisor := p_divisor;
END IF;
RETURN l_clean_divisor;
13. END;
FUNCTION Get_Translated_DNU_Reason(P_DNU_REASON_CODE IN VARCHAR2)
RETURN VARCHAR2
IS
l_dnu_reason VARCHAR2(500);
BEGIN
SELECT DESCRIPTION
INTO l_dnu_reason
FROM FND_LOOKUPS
WHERE LOOKUP_TYPE = 'IEC_DNU_REASON'
AND LOOKUP_CODE = P_DNU_REASON_CODE;
RETURN l_dnu_reason;
END Get_Translated_DNU_Reason;
FUNCTION "EUL_GET_OBJECT_NAME" (USEKEY in VARCHAR2, TYPEKEY in varchar2)
return VARCHAR2 is oname varchar2(2000);
startpt NUMBER :=1;
endpt NUMBER :=length(USEKEY);
pos NUMBER :=1;
ctr NUMBER :=0;
chklgth NUMBER;
objid NUMBER;
aggtype NUMBER;
objname VARCHAR2(100);
cursor folder is select obj_name from eul_objs where obj_id = objid;
cursor item is select exp_name from eul_expressions where exp_id = objid;
begin while pos <> 0 loop aggtype:=0;
ctr:=ctr+1; pos:=instr(USEKEY, '.', 1, ctr);
if pos=0 then if upper(TYPEKEY)='F' then objid:= to_number(substr(USEKEY,
startpt, (endpt-startpt+1)));
else objid:= to_number(substr(USEKEY, startpt, (endpt-startpt-1)));
aggtype:= to_number(substr(USEKEY, endpt, 1));
end if;
else if upper(TYPEKEY)='F' then objid:= to_number(substr(USEKEY, startpt, (pos-startpt)));
else objid:= to_number(substr(USEKEY, startpt, (pos-startpt-2)));
aggtype:= to_number(substr(USEKEY, pos-1, 1));
end if; startpt:=pos+1;
end if;
if upper(TYPEKEY) ='F' then open folder; fetch folder into objname;
close folder; end if;
if upper(TYPEKEY)='I' then open item; fetch item into objname;
close item; end if;
if ctr=1 then if aggtype=0 then oname:=objname;
elsif aggtype=1 then oname:=objname||' SUM';
elsif aggtype=2 then oname:=objname||' AVG';
elsif aggtype=3 then oname:=objname||' COUNT';
elsif aggtype=4 then oname:=objname||' MAX';
elsif aggtype=5 then oname:=objname||' MIN';
else oname:=objname; end if; else if aggtype=0 then chklgth:= length(oname)
+length(objname)+2;
elsif aggtype=1 then chklgth:= length(oname)+length(objname)+6;
elsif aggtype=2 then chklgth:= length(oname)+length(objname)+6;
elsif aggtype=3 then chklgth:= length(oname)+length(objname)+8;
elsif aggtype=4 then chklgth:= length(oname)+length(objname)+6;
elsif aggtype=5 then chklgth:= length(oname)+length(objname)+6;
else chklgth:= length(oname)+length(objname)+2; end if; if chklgth > 1999 then
oname:=oname||'*';
exit;
else if aggtype = 0 then oname:=oname||', '||objname; elsif aggtype=1 then
oname:=oname||', '||objname||' SUM'; elsif aggtype=2 then oname:=oname||', '||
14. objname||' AVG'; elsif aggtype=3 then oname:=oname||', '||objname||' COUNT';
elsif aggtype=4 then oname:=oname||', '||objname||' MAX'; elsif aggtype=5 then
oname:=oname||', '||objname||' MIN'; else oname:=oname||', '||objname;
end if; end if; end if; end loop; return oname;
end EUL_GET_OBJECT_NAME;
function CF_saldo_ini4Formula (
p_set_of_books_id number,
cta4 varchar2,
p_currency_code varchar2,
p_chart_acc_id number,
p_company varchar2,
p_end_acc varchar2,
p_start_acc varchar2,
p_start_plt varchar2,
p_end_plt varchar2,
p_start_c_c varchar2,
p_end_c_c varchar2,
p_start_proy varchar2,
p_end_proy varchar2,
p_start_period varchar2
)
return Number is
lv_cadena3 varchar2(2000);
ln_saldo4 number;
ln_debe4 number;
ln_haber4 number;
ln_MONTO4 number;
lv_cadena1 varchar2(2000);
lv_seg_cta varchar2(30);
lv_seg_cia varchar2(30);
lv_nro_segmento_cc varchar2(35); --- jgc 11-01-04
lv_seg_plta varchar2(30); --- jgc 30-01-04
lv_seg_proy varchar2(30); --- jgc 30-01-04
ln_debe_usd4 number;
ln_haber_usd4 number;
lv_currency_code4 varchar2(5);
cp_debe_usd4 number;
cp_haber_usd4 number;
cp_debe4 number;
cp_haber4 number;
------
begin
Begin
SELECT
DISTINCT(fifs.application_column_name)
INTO
lv_seg_cia
FROM
apps.fnd_segment_attribute_values fsav
,apps.fnd_id_flex_segments_vl fifs
,apps.fnd_id_flex_structures fifst
,apps.gl_sets_of_books gsob
,apps.fnd_flex_value_sets ffvs
,apps.fnd_flex_values_vl ffv
WHERE
15. ffv.flex_value_set_id =
ffvs.flex_value_set_id
AND ffvs.flex_value_set_id =
fifs.flex_value_set_id
AND fsav.application_id =
fifs.application_id
AND fsav.id_flex_code = fifs.id_flex_code
AND fsav.id_flex_num = fifs.id_flex_num
AND fsav.application_column_name =
fifs.application_column_name
AND fifs.application_id =
fifst.application_id
AND fifs.id_flex_code =
fifst.id_flex_code
AND fifs.id_flex_num = fifst.id_flex_num
AND fifs.id_flex_num =
gsob.chart_of_accounts_id
AND gsob.set_of_books_id = p_set_of_books_id
AND fifst.id_flex_code = 'GL#'
AND fsav.segment_attribute_type = 'GL_BALANCING'
AND fsav.attribute_value = 'Y'
AND rownum = 1;
EXCEPTION
WHEN OTHERS THEN
return null;
End;
/*Obtiene segmento de la cuenta*/
Begin
SELECT
DISTINCT(fifs.application_column_name)
INTO
lv_seg_cta
FROM
apps.fnd_segment_attribute_values fsav
,apps.fnd_id_flex_segments fifs
,apps.fnd_id_flex_structures fifst
,apps.gl_sets_of_books gsob
,apps.fnd_flex_value_sets ffvs
,apps.fnd_flex_values_vl ffv
WHERE
ffv.flex_value_set_id =
ffvs.flex_value_set_id
AND ffvs.flex_value_set_id =
fifs.flex_value_set_id
AND fsav.application_id =
fifs.application_id
AND fsav.id_flex_code =
fifs.id_flex_code
AND fsav.id_flex_num = fifs.id_flex_num
AND fsav.application_column_name =
fifs.application_column_name
AND fifs.application_id =
fifst.application_id
AND fifs.id_flex_code =
fifst.id_flex_code
AND fifs.id_flex_num =
fifst.id_flex_num
AND fifs.id_flex_num =
gsob.chart_of_accounts_id
AND gsob.set_of_books_id =
16. p_set_of_books_id
AND fifst.id_flex_code = 'GL#'
AND fsav.segment_attribute_type = 'GL_ACCOUNT'
AND fsav.attribute_value = 'Y'
AND rownum = 1;
EXCEPTION
WHEN OTHERS THEN
return null;
End;
/*Obtiene segmento de la planta*/ --- SEGMENT3 --- JGC 30-01-04
Begin
SELECT
DISTINCT(fifs.application_column_name)
INTO
lv_seg_plta
FROM
apps.fnd_segment_attribute_values fsav
,apps.fnd_id_flex_segments fifs
,apps.fnd_id_flex_structures fifst
,apps.gl_sets_of_books gsob
,apps.fnd_flex_value_sets ffvs
,apps.fnd_flex_values_vl ffv
WHERE
ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_id = fifs.flex_value_set_id
AND fsav.application_id = fifs.application_id
AND fsav.id_flex_code = fifs.id_flex_code
AND fsav.id_flex_num = fifs.id_flex_num
AND fsav.application_column_name = fifs.application_column_name
AND fifs.application_id = fifst.application_id
AND fifs.id_flex_code = fifst.id_flex_code
AND fifs.id_flex_num = fifst.id_flex_num
AND fifs.id_flex_num = gsob.chart_of_accounts_id
AND gsob.set_of_books_id = p_set_of_books_id
AND fifst.id_flex_code = 'GL#'
AND fsav.segment_attribute_type = 'GL_GLOBAL'
AND fsav.attribute_value = 'Y'
AND rownum = 1
AND fifs.application_column_name='SEGMENT3';
EXCEPTION
WHEN OTHERS THEN
return null;
End;
/*MAAN 010803*/ /*Obtiene segmento del centro de costo*/ --- SEGMENT4
BEGIN
SELECT
DISTINCT(fifs.application_column_name)
INTO
lv_nro_segmento_cc
FROM
apps.fnd_segment_attribute_values fsav
,apps.fnd_id_flex_segments fifs
,apps.fnd_id_flex_structures fifst
,apps.gl_sets_of_books gsob
,apps.fnd_flex_value_sets ffvs
,apps.fnd_flex_values_vl ffv
WHERE
ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_id = fifs.flex_value_set_id
AND fsav.application_id = fifs.application_id
17. AND fsav.id_flex_code = fifs.id_flex_code
AND fsav.id_flex_num = fifs.id_flex_num
AND fsav.application_column_name = fifs.application_column_name
AND fifs.application_id = fifst.application_id
AND fifs.id_flex_code = fifst.id_flex_code
AND fifs.id_flex_num = fifst.id_flex_num
AND fifs.id_flex_num = gsob.chart_of_accounts_id
AND gsob.set_of_books_id = p_set_of_books_id
AND fifst.id_flex_code = 'GL#'
AND fsav.segment_attribute_type = 'FA_COST_CTR'
AND fsav.attribute_value = 'Y'
AND rownum = 1;
EXCEPTION
WHEN OTHERS THEN
return null;
End;
/*Obtiene segmento del proyecto*/ --- SEGMENT5 --- JGC 30-01-04
BEGIN
SELECT
DISTINCT(fifs.application_column_name)
INTO
lv_seg_proy
FROM
apps.fnd_segment_attribute_values fsav
,apps.fnd_id_flex_segments fifs
,apps.fnd_id_flex_structures fifst
,apps.gl_sets_of_books gsob
,apps.fnd_flex_value_sets ffvs
,apps.fnd_flex_values_vl ffv
WHERE
ffv.flex_value_set_id = ffvs.flex_value_set_id
AND ffvs.flex_value_set_id = fifs.flex_value_set_id
AND fsav.application_id = fifs.application_id
AND fsav.id_flex_code = fifs.id_flex_code
AND fsav.id_flex_num = fifs.id_flex_num
AND fsav.application_column_name = fifs.application_column_name
AND fifs.application_id = fifst.application_id
AND fifs.id_flex_code = fifst.id_flex_code
AND fifs.id_flex_num = fifst.id_flex_num
AND fifs.id_flex_num = gsob.chart_of_accounts_id
AND gsob.set_of_books_id = p_set_of_books_id --RBS 18.03.08
AND fifst.id_flex_code = 'GL#'
AND fsav.segment_attribute_type = 'GL_GLOBAL'
AND fsav.attribute_value = 'Y'
AND rownum = 1
AND fifs.application_column_name='SEGMENT5';
EXCEPTION
WHEN OTHERS THEN
return null;
End;
/*Elimina cualquier registro de tabla temporal*/
--srw.do_sql('DELETE sy_lo_pe_gl_ta_tempo1');
DELETE sy_lo_pe_gl_ta_lm4;
COMMIT;
/*Crea registro con saldo inicial en tabla temporal*/
lv_cadena1 := 'INSERT into sy_lo_pe_gl_ta_lm4
(SELECT 0, ' ||
--' SUM(DECODE(SUBSTR(GCC.'||
lv_seg_cta ||' ,1,4),'''|| SUBSTR(:cta4,1,4)||'''
,DECODE(gb.currency_code,''PEN'',nvl(gb.begin_balance_dr,0),0),0)) ,' || --DTR
13/09/04
--' SUM(DECODE(gb.currency_code,'''
18. || :p_currency_code || ''',nvl(gb.begin_balance_dr,0),0)) ,' ||
--' SUM(DECODE(gb.currency_code,'''
|| :p_currency_code || ''',nvl(gb.begin_balance_cr,0),0)) ,' ||
--' SUM(DECODE(SUBSTR(GCC.'||lv_seg_cta ||' ,
1,4),'''|| SUBSTR(:cta4,1,4)||''' ,DECODE(gb.currency_code,''' ||
:p_currency_code || ''',nvl(gb.begin_balance_cr,0),0),0)) ,' || --DTR 13/09/04
' SUM(DECODE(SUBSTR(GCC.'||lv_seg_cta ||' ,
1,5),'''|| SUBSTR(cta4,1,5)||'''
,DECODE(gb.currency_code,''PEN'',nvl(gb.period_net_dr,0),0),0)) ,' || --DTR
13/09/04
' SUM(DECODE(SUBSTR(GCC.'||lv_seg_cta ||' ,
1,5),'''|| SUBSTR(cta4,1,5)||''' ,DECODE(gb.currency_code,''' || p_currency_code
|| ''',nvl(gb.period_net_cr,0),0),0)) ,' || --DTR 13/09/04
'
SUM(DECODE(substr(gcc.segment3,3,1),''2'',DECODE(gb.currency_code,''USD'',nvl(gb
.begin_balance_dr,0)-nvl(gb.begin_balance_cr,0),0),0)),' ||
'
SUM(DECODE(gb.currency_code,''' || p_currency_code ||
''',nvl(gb.begin_balance_dr,0)-nvl(gb.begin_balance_cr,0),0)), ' ||
' MAX(gb.currency_code) ,'||
' SUM(DECODE(SUBSTR(GCC.'||
lv_seg_cta ||' ,1,5),'''|| SUBSTR(cta4,1,5)||'''
,DECODE(gb.currency_code,''USD'',nvl(gb.begin_balance_dr,0),0),0)) ,' ||
' SUM(DECODE(SUBSTR(GCC.'||
lv_seg_cta ||' ,1,5),'''|| SUBSTR(cta4,1,5)||'''
,DECODE(gb.currency_code,''USD'',nvl(gb.begin_balance_cr,0),0),0)) ' ||
' FROM gl_code_combinations gcc
,gl_period_statuses gps
,gl_balances gb
WHERE gps.application_id = 101
AND gcc.code_combination_id = gb.code_combination_id
AND gb.period_name = gps.period_name
AND gps.set_of_books_id = '|| p_set_of_books_id ||
' AND gps.effective_period_num = ' ||
cf_per_num_ini_effFormula(p_set_of_books_id,p_start_period) ||
' AND gcc.chart_of_accounts_id = '||
p_chart_acc_id ||
' AND gcc.code_combination_id =
gb.code_combination_id
AND gcc.'||lv_seg_cia || '=
nvl('''||p_company||''',gcc.segment1)
AND gcc.'||lv_seg_cta||' BETWEEN '''||
p_start_acc||''' AND '''||p_end_acc||'''
AND gcc.'||lv_seg_plta||' BETWEEN '''||
p_start_plt||''' AND '''||p_end_plt||'''
AND gcc.'||lv_nro_segmento_cc||' BETWEEN '''||
p_start_c_c||''' AND '''||p_end_c_c||'''
AND gcc.'||lv_seg_proy||' BETWEEN '''||
p_start_proy||''' AND '''||p_end_proy||'''
AND gb.set_of_books_id = ' ||p_set_of_books_id||'
AND gcc.template_id IS NULL
AND gb.actual_flag = '''||'A'||'''
AND gcc.summary_flag ='''||'N'||''' )';
--DTR 13/09/04
--AND SUBSTR( gcc.'||lv_seg_cta || ',1,4) = '''||
19. SUBSTR(:cta4,1,4)||''' )'; --DTR 13/09/04
-- srw.do_sql(lv_cadena1);
/*Captura saldo inicial de tabla temporal*/
bEGIN
SELECT saldo, montodebe, montohaber, montooriginal,
moneda, montodebe_usd, montohaber_usd
INTO ln_saldo4, ln_debe4, ln_haber4 , ln_monto4 ,
lv_currency_code4, ln_debe_usd4, ln_haber_usd4
FROM sy_lo_pe_gl_ta_lm4;
EXCEPTION
WHEN OTHERS THEN
return null;
END;
cp_debe_usd4:=nvl(ln_debe_usd4, 0);
cp_haber_usd4:=nvl(ln_haber_usd4, 0);
cp_debe4:=nvl(ln_debe4, 0);
cp_haber4:=nvl(ln_haber4, 0);
RETURN(ln_saldo4);
--EXCEPTION
-- WHEN OTHERS THEN
return 0;
end;