Catalogo alp_cat_ar_clientes
1. Modulo
Cuentas por Cobrar (AR)
2. Descripción
Maestro general de clientes, cuentas, direcciones y estados de cuenta comerciales.
3. Columnas
| # | Columna | Tipo / Origen | Descripción |
|---|---|---|---|
| 1 | appl_source | String | Sistema fuente (Default: 'AR'). |
| 2 | party_id | Long | ID único de la entidad (HZ_PARTIES). |
| 3 | identificador_registro | String | Número de registro de la entidad (party_number). |
| 4 | nombre | String | Razón social o nombre comercial. |
| 5 | tipo_cliente | String | Clasificación del tipo de cliente. |
| 6 | numero_identificacion_contribuyente | String | RFC / ID Fiscal. |
| 7 | regimen_fiscal | String | Código de régimen fiscal. |
| 8 | desc_regimen_fiscal | String | Descripción del régimen fiscal. |
| 9 | tipo_persona_fisica | String | Código de tipo de persona física. |
| 10 | desc_tipo_persona_fisica | String | Descripción del tipo de persona física. |
| 11 | party_osr_id | Long | ID referencia del sistema origen (Party). |
| 12 | party_osr | String | Código de referencia del sistema origen (Party). |
| 13 | cust_account_id | Long | ID interno de la cuenta (CUST_ACCOUNTS). |
| 14 | numero_cuenta_cliente | String | Número de cuenta contable. |
| 15 | nombre_cuenta_cliente | String | Nombre de la cuenta de cliente. |
| 16 | clase_cuenta | String | Código de clase de crédito. |
| 17 | desc_clase_cuenta | String | Descripción de la clase de crédito. |
| 18 | canal_tipo_cuenta | String | Clasificación del canal de venta. |
| 19 | desc_canal_tipo_cuenta | String | Descripción del canal. |
| 20 | canal_400_tipo_cuenta | String | Tag para integración con AS400. |
| 21 | grupo_comercial | String | Código del grupo comercial. |
| 22 | desc_grupo_comercial | String | Descripción del grupo comercial. |
| 23 | grupo_comercial_400 | String | Tag para integración con AS400. |
| 24 | unidad_facturacion | String | Código de unidad de facturación. |
| 25 | desc_unidad_facturacion | String | Descripción de unidad de facturación. |
| 26 | forma_pago | String | Código de forma de pago. |
| 27 | desc_forma_pago | String | Descripción de forma de pago. |
| 28 | tipo_factura | String | Código de tipo de factura. |
| 29 | desc_tipo_factura | String | Descripción de tipo de factura. |
| 30 | metodo_pago | String | Código de método de pago. |
| 31 | desc_metodo_pago | String | Descripción de método de pago. |
| 32 | dias_gracia | String | Días de gracia otorgados. |
| 33 | codigo_bancario | String | Código bancario de la cuenta. |
| 34 | subcanal | String | Código de subcanal. |
| 35 | desc_subcanal | String | Descripción del subcanal. |
| 36 | zona_cobranza | String | Código de zona de cobranza. |
| 37 | desc_zona_cobranza | String | Descripción de la zona de cobranza. |
| 38 | dias_pago | String | Días para el pago. |
| 39 | dias_recepcion | String | Días para la recepción. |
| 40 | grupo_concentrador | String | Código del grupo concentrador. |
| 41 | desc_grupo_concentrador | String | Descripción del grupo concentrador. |
| 42 | no_cliente_factura_concentrada | String | ID de cliente para facturación concentrada. |
| 43 | agrupacion_ibp | String | Código de agrupación IBP. |
| 44 | desc_agrupacion_ibp | String | Descripción de la agrupación IBP. |
| 45 | agrupacion_ibp_400 | String | Tag para integración con AS400. |
| 46 | timbrado_individual | String | Flag para timbrado individual. |
| 47 | uso_cfdi | String | Código de uso CFDI. |
| 48 | desc_uso_cfdi | String | Descripción del uso CFDI. |
| 49 | numero_proveedor | String | Número de proveedor asociado. |
| 50 | incoterm | String | Incoterm comercial. |
| 51 | tipo_addenda | String | Código de tipo de addenda. |
| 52 | desc_tipo_addenda | String | Descripción de tipo de addenda. |
| 53 | macro_canal | String | Código de macro canal. |
| 54 | desc_macro_canal | String | Descripción de macro canal. |
| 55 | giro_cliente | String | Código de giro del cliente. |
| 56 | desc_giro_cliente | String | Descripción de giro del cliente. |
| 57 | genera_addenda | String | Flag para generación de addenda. |
| 58 | referencia_cie | String | Referencia CIE bancaria. |
| 59 | referencia_cuenta | String | Referencia de cuenta general. |
| 60 | account_osr_id | Long | ID referencia origen (Cuenta). |
| 61 | account_osr | String | Código referencia origen (Cuenta). |
| 62 | party_site_id | Long | ID del sitio del cliente. |
| 63 | numero_sitio | String | Número de identificación del sitio. |
| 64 | nombre_sitio | String | Nombre asignado al sitio. |
| 65 | direccion_primaria | String | Flag de dirección principal. |
| 66 | party_site_osr_id | Long | ID referencia origen (Sitio). |
| 67 | party_site_osr | String | Código referencia origen (Sitio). |
| 68 | location_id | Long | ID interno de localización. |
| 69 | pais | String | Código de país. |
| 70 | codigo_postal | String | Código postal. |
| 71 | calle | String | Dirección (calle). |
| 72 | numero_exterior | String | Número exterior. |
| 73 | numero_interior | String | Número interior. |
| 74 | colonia | String | Colonia. |
| 75 | alcaldia_municipio | String | Alcaldía o municipio. |
| 76 | estado | String | Estado o provincia. |
| 77 | entre_calle_1 | String | Referencia vial 1. |
| 78 | entre_calle_2 | String | Referencia vial 2. |
| 79 | latitud | String | Latitud geográfica. |
| 80 | longitud | String | Longitud geográfica. |
| 81 | codigo_gln | String | Código GLN. |
| 82 | location_osr_id | Long | ID referencia origen (Localización). |
| 83 | location_osr | String | Código referencia origen (Localización). |
| 84 | cust_acct_site_id | Long | ID de relación cuenta-sitio. |
| 85 | bill_to_flag | String | Flag de facturación. |
| 86 | ship_to_flag | String | Flag de envío. |
| 87 | plaza_distribucion | String | Código de plaza. |
| 88 | desc_plaza_distribucion | String | Descripción de plaza. |
| 89 | plaza_distribucion_400 | String | Tag AS400. |
| 90 | factura_anticipada | String | Flag para factura anticipada. |
| 91 | cedis_asignado | String | ID del CEDIS asignado. |
| 92 | desc_cedis_asignado | String | Descripción del CEDIS. |
| 93 | cedis_asignado_400 | String | Tag AS400. |
| 94 | no_sucursal_factura_concentrada | String | Sucursal de facturación. |
| 95 | codigo_exportacion | String | Código de exportación. |
| 96 | zona_nielsen | String | Zona Nielsen. |
| 97 | desc_zona_nielsen | String | Descripción de zona Nielsen. |
| 98 | regional_responsable | String | Regional responsable. |
| 99 | desc_regional_responsable | String | Descripción de regional. |
| 100 | tipo_entrega | String | Tipo de entrega. |
| 101 | desc_tipo_entrega | String | Descripción de entrega. |
| 102 | segmentacion_categoria_externa | String | Categoría externa. |
| 103 | desc_segmentacion_categoria_externa | String | Descripción de categoría externa. |
| 104 | categoria_interna | String | Categoría interna. |
| 105 | desc_categoria_interna | String | Descripción de categoría interna. |
| 106 | cuenta_bancaria | String | Cuenta bancaria asociada. |
| 107 | metodo_comercializacion | String | Método de comercialización. |
| 108 | desc_metodo_comercializacion | String | Descripción método comercial. |
| 109 | codigo_sucursal | String | Código de sucursal. |
| 110 | identificador_edi | String | ID para EDI. |
| 111 | zona_precios | String | Zona de precios. |
| 112 | desc_zona_precios | String | Descripción zona de precios. |
| 113 | guid_chep | String | GUID de CHEP. |
| 114 | inspeccion_calidad | String | Flag inspección calidad. |
| 115 | numero_tienda_retek | String | ID tienda Retek. |
| 116 | perfil_cliente | String | Perfil del cliente. |
| 117 | tipo_pedido_cliente | String | Tipo de pedido. |
| 118 | referencia_sucursal | String | Referencia de sucursal. |
| 119 | account_site_osr_id | Long | ID referencia origen (Sitio-Cuenta). |
| 120 | account_site_osr | String | Código referencia origen (Sitio-Cuenta). |
| 121 | party_site_use_id | Long | ID de uso de sitio. |
| 122 | primario_por_tipo | String | Flag uso primario. |
| 123 | party_site_use_osr_id | Long | ID referencia origen (Uso Sitio). |
| 124 | party_site_use_osr | String | Código referencia origen (Uso Sitio). |
| 125 | site_use_id | Long | ID uso de sitio cuenta. |
| 126 | sitio_cuenta_primario | String | Flag sitio cuenta primario. |
| 127 | uso_sitio_cuenta | String | Tipo de uso. |
| 128 | sitio | String | Código sitio. |
| 129 | account_site_use_osr_id | Long | ID referencia origen (Uso Sitio-Cuenta). |
| 130 | account_site_use_osr | String | Código referencia origen (Uso Sitio-Cuenta). |
| 131 | terminos_pago | String | Términos de pago. |
| 132 | desc_terminos_pago | String | Descripción términos de pago. |
| 133 | cedis_asignado_as400 | String | Tag CEDIS AS400. |
| 134 | meaning | String | Significado adicional. |
| 135 | setname | String | Nombre del set de referencia. |
4. Querys
- Databricks DEV
- Databricks UAT
- Databricks PROD
- Oracle
with alp_party_site_use as
( select row_number()
over ( partition by hpsu.partysiteid
, hpsu.siteusetype
order by hosr5.creationdate) reg
, hpsu.partysiteid party_site_id
, hpsu.siteusetype site_use_type
, hpsu.partysiteuseid party_site_use_id
, hpsu.primarypertype primario_por_tipo
, hosr5.origsystemrefid party_site_use_osr_id
, hosr5.origsystemreference party_site_use_osr
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteuseextractpvo hpsu
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr5
on hpsu.partysiteuseid = hosr5.ownertableid
and hosr5.origsystemreference like 'PSU%')
, alp_cat_fnd_lookups as
( select flv.lookuptype type
, flv.lookupcode code
, flvt.meaning
, flv.setid set_id
, flv.tag
, flv.viewapplicationid view_appl_id
, flv.enabledflag enabled
, flv.startdateactive start_date
, flv.enddateactive end_date
from cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluesextractpvo flv
join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluestlextractpvo flvt
on flv.lookuptype = flvt.lookuptype
and flv.lookupcode = flvt.lookupcode
and flv.viewapplicationid = flvt.viewapplicationid
and flvt.language = 'E')
select 'AR' appl_source
-- parties
, hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, op.attribute1 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, op.attribute2 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
-- parties_references
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
-- accounts
, hca.custaccountid cust_account_id
, hca.accountnumber numero_cuenta_cliente
, hca.accountname nombre_cuenta_cliente
, hca.customerclasscode clase_cuenta
, flv3.meaning desc_clase_cuenta
, hca.customertype canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hca.attribute1 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hca.attribute2 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hca.attribute3 forma_pago
, flv7.meaning desc_forma_pago
, hca.attribute4 tipo_factura
, flv8.meaning desc_tipo_factura
, hca.attribute5 metodo_pago
, flv9.meaning desc_metodo_pago
, hca.attribute6 dias_gracia
, hca.attribute7 codigo_bancario
, hca.attribute8 subcanal
, flv10.meaning desc_subcanal
, hca.attribute9 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hca.attribute10 dias_pago
, hca.attribute11 dias_recepcion
, hca.attribute12 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hca.attribute13 no_cliente_factura_concentrada
, hca.attribute14 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hca.attribute15 timbrado_individual
, hca.attribute16 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hca.attribute17 numero_proveedor
, hca.attribute18 incoterm
, hca.attribute19 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hca.attribute20 macro_canal
, flv15.meaning desc_macro_canal
, hca.attribute21 giro_cliente
, flv16.meaning desc_giro_cliente
, hca.attribute22 genera_addenda
, hca.attribute23 referencia_cie
, hca.attribute24 referencia_cuenta
-- account_references
, hosr2.origsystemrefid account_osr_id
, hosr2.origsystemreference account_osr
-- party_sites
, hps.partysiteid party_site_id
, hps.partysitenumber numero_sitio
, hps.partysitename nombre_sitio
, hps.identifyingaddressflag direccion_primaria
-- party_sites_refernces
, hosr3.origsystemrefid party_site_osr_id
, hosr3.origsystemreference party_site_osr
-- hz_locations
, hl.locationid location_id
, hl.country pais
, hl.postalcode codigo_postal
, hl.address1 calle
, hl.address2 numero_exterior
, hl.address3 numero_interior
, hl.city colonia
, hl.county alcaldia_municipio
, hl.state estado
, hl.addrelementattribute1 entre_calle_1
, hl.addrelementattribute2 entre_calle_2
, hl.addrelementattribute3 latitud
, hl.addrelementattribute4 longitud
, hl.addrelementattribute5 codigo_gln
-- locations_refrences
, hosr7.origsystemrefid location_osr_id
, hosr7.origsystemreference location_osr
-- account_sites
, hcasa.custacctsiteid cust_acct_site_id
, hcasa.billtoflag bill_to_flag
, hcasa.shiptoflag ship_to_flag
, hcasa.attribute1 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hcasa.attribute2 factura_anticipada
, hcasa.attribute3 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hcasa.attribute4 no_sucursal_factura_concentrada
, hcasa.attribute5 codigo_exportacion
, hcasa.attribute6 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hcasa.attribute7 regional_responsable
, flv20.meaning desc_regional_responsable
, hcasa.attribute8 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hcasa.attribute9 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hcasa.attribute10 categoria_interna
, flv23.meaning desc_categoria_interna
, hcasa.attribute11 cuenta_bancaria
, hcasa.attribute12 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hcasa.attribute13 codigo_sucursal
, hcasa.attribute14 identificador_edi
, hcasa.attribute15 zona_precios
, flv25.meaning desc_zona_precios
, hcasa.attribute16 guid_chep
, hcasa.attribute17 inspeccion_calidad
, hcasa.attribute18 numero_tienda_retek
, hcasa.attribute19 perfil_cliente
, hcasa.attribute20 tipo_pedido_cliente
, hcasa.attribute21 referencia_sucursal
-- account_site_references
, hosr4.origsystemrefid account_site_osr_id
, hosr4.origsystemreference account_site_osr
-- party_site_uses
, hpsu.party_site_use_id
, hpsu.primario_por_tipo
-- party_site_uses_references
, hpsu.party_site_use_osr_id
, hpsu.party_site_use_osr
-- account_site_uses
, hcsu.siteuseid site_use_id
, hcsu.primaryflag sitio_cuenta_primario
, hcsu.siteusecode uso_sitio_cuenta
, hcsu.location sitio
-- account_site_uses_references
, hosr6.origsystemrefid account_site_use_osr_id
, hosr6.origsystemreference account_site_use_osr
-- terminos de pago
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
, flv18.meaning
, fasis.setname
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo hp
join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles op
on hp.partyid = op.party_id
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountextractpvo hca
on hp.partyid = hca.partyid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountsiteextractpvo hcasa
on hca.custaccountid = hcasa.custaccountid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteextractpvo hps
on hcasa.partysiteid = hps.partysiteid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo hl
on hps.locationid = hl.locationid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeracctsiteuseextractpvo hcsu
on hcasa.custacctsiteid = hcsu.custacctsiteid
join alp_party_site_use hpsu
on hps.partysiteid = hpsu.party_site_id
and hcsu.siteusecode = hpsu.site_use_type
and hpsu.reg = 1
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo rtt
on hcsu.paymenttermid = rtt.ratermtltermid
and rtt.ratermtllanguage = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_setidsetspvo fasis
on hcasa.setid = fasis.setid
and fasis.language = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr1
on hp.partyid = hosr1.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr2
on hca.custaccountid = hosr2.ownertableid
and hca.origsystemreference = hosr2.origsystemreference
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr3
on hps.partysiteid = hosr3.ownertableid
and hosr3.origsystemreference like 'PS%'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr4
on hcasa.custacctsiteid = hosr4.ownertableid
and hosr4.origsystemreference = 'FUSION'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr6
on hcsu.siteuseid = hosr6.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr7
on hl.locationid = hosr7.ownertableid
left join alp_cat_fnd_lookups flv1
on op.attribute1 = flv1.code
and flv1.type = 'ALP_REGIMENFISCAL'
and flv1.view_appl_id = 0
left join alp_cat_fnd_lookups flv2
on op.attribute2 = flv2.code
and flv2.type = 'ALP_TIPOFISCAL'
and flv2.view_appl_id = 0
left join alp_cat_fnd_lookups flv3
on hca.customerclasscode = flv3.code
and flv3.type = 'ALP_TIPOCREDITO'
and flv3.view_appl_id = 0
left join alp_cat_fnd_lookups flv4
on hca.customertype = flv4.code
and flv4.type = 'ALP_CANAL'
and flv4.view_appl_id = 0
left join alp_cat_fnd_lookups flv5
on hca.attribute1 = flv5.code
and flv5.type = 'ALP_GRUPOCOMERCIAL'
and flv5.view_appl_id = 0
left join alp_cat_fnd_lookups flv6
on hca.attribute2 = flv6.code
and flv6.type = 'ALP_UNIDADFACTURACION'
and flv6.view_appl_id = 0
left join alp_cat_fnd_lookups flv7
on hca.attribute3 = flv7.code
and flv7.type = 'ALP_FORMAPAGO'
and flv7.view_appl_id = 0
left join alp_cat_fnd_lookups flv8
on hca.attribute4 = flv8.code
and flv8.type = 'ALP_TIPOFACTURA'
and flv8.view_appl_id = 0
left join alp_cat_fnd_lookups flv9
on hca.attribute5 = flv9.code
and flv9.type = 'ALP_METODOPAGO'
and flv9.view_appl_id = 0
left join alp_cat_fnd_lookups flv10
on hca.attribute8 = flv10.code
and flv10.type = 'ALP_SUBCANAL'
and flv10.view_appl_id = 0
left join alp_cat_fnd_lookups flv11
on hca.attribute9 = flv11.code
and flv11.type = 'ALP_ZCOBRANZA'
and flv11.view_appl_id = 0
left join alp_cat_fnd_lookups flv12
on hca.attribute12 = flv12.code
and flv12.type = 'ALP_CONCENTRADOR'
and flv12.view_appl_id = 0
left join alp_cat_fnd_lookups flv13
on hca.attribute14 = flv13.code
and flv13.type = 'ALP_IBP'
and flv13.view_appl_id = 0
left join alp_cat_fnd_lookups flv14
on hca.attribute16 = flv14.code
and flv14.type = 'ALP_USOCFDI'
and flv14.view_appl_id = 0
left join alp_cat_fnd_lookups flv15
on hca.attribute20 = flv15.code
and flv15.type = 'ALP_MACROCANAL'
and flv15.view_appl_id = 0
left join alp_cat_fnd_lookups flv16
on hca.attribute21 = flv16.code
and flv16.type = 'ALP_GIRO'
and flv16.view_appl_id = 0
left join alp_cat_fnd_lookups flv17
on hcasa.attribute1 = flv17.code
and flv17.type = 'ALP_PLAZADISTRIBUCION'
and flv17.view_appl_id = 0
left join alp_cat_fnd_lookups flv18
on hcasa.attribute3 = flv18.code
and flv18.type = 'ALP_CEDIS'
and flv18.view_appl_id = 0
left join alp_cat_fnd_lookups flv19
on hcasa.attribute6 = flv19.code
and flv19.type = 'ALP_ZNIELSEN'
and flv19.view_appl_id = 0
left join alp_cat_fnd_lookups flv20
on hcasa.attribute7 = flv20.code
and flv20.type = 'ALP_REGIONALRESP'
and flv20.view_appl_id = 0
left join alp_cat_fnd_lookups flv21
on hcasa.attribute8 = flv21.code
and flv21.type = 'ALP_TIPOENTREGA'
and flv21.view_appl_id = 0
left join alp_cat_fnd_lookups flv22
on hcasa.attribute9 = flv22.code
and flv22.type = 'ALP_SEGMENTACION'
and flv22.view_appl_id = 0
left join alp_cat_fnd_lookups flv23
on hcasa.attribute10 = flv23.code
and flv23.type = 'ALP_CLASINTERNA'
and flv23.view_appl_id = 0
left join alp_cat_fnd_lookups flv24
on hcasa.attribute12 = flv24.code
and flv24.type = 'ALP_METODOCOMER'
and flv24.view_appl_id = 0
left join alp_cat_fnd_lookups flv25
on hcasa.attribute15 = flv25.code
and flv25.type = 'ALP_ZONAPRECIOS'
and flv25.view_appl_id = 0
left join alp_cat_fnd_lookups flv26
on hca.attribute19 = flv26.code
and flv26.type = 'ALP_TIPOADENDA'
and flv26.view_appl_id = 0
left join alp_cat_fnd_lookups flv27
on hcasa.attribute3 = flv27.code
and flv27.type = 'ALP_CEDIS_CDM_AS400'
and flv27.view_appl_id = 0
where 1 = 1
and hp.partytype = 'ORGANIZATION'
and ((fasis.setname = 'GPLP_SET'
and hca.customerclasscode = 'R')
or (flv18.meaning is null
and hca.customerclasscode <> 'R')
or flv18.meaning like concat('%',replace(fasis.setname,'_SET',''),'%'))
with alp_party_site_use as
( select row_number()
over ( partition by hpsu.partysiteid
, hpsu.siteusetype
order by hosr5.creationdate) reg
, hpsu.partysiteid party_site_id
, hpsu.siteusetype site_use_type
, hpsu.partysiteuseid party_site_use_id
, hpsu.primarypertype primario_por_tipo
, hosr5.origsystemrefid party_site_use_osr_id
, hosr5.origsystemreference party_site_use_osr
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteuseextractpvo_stg hpsu
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr5
on hpsu.partysiteuseid = hosr5.ownertableid
and hosr5.origsystemreference like 'PSU%')
, alp_cat_fnd_lookups as
( select flv.lookuptype type
, flv.lookupcode code
, flvt.meaning
, flv.setid set_id
, flv.tag
, flv.viewapplicationid view_appl_id
, flv.enabledflag enabled
, flv.startdateactive start_date
, flv.enddateactive end_date
from cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluesextractpvo_stg flv
join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluestlextractpvo_stg flvt
on flv.lookuptype = flvt.lookuptype
and flv.lookupcode = flvt.lookupcode
and flv.viewapplicationid = flvt.viewapplicationid
and flvt.language = 'E')
select 'AR' appl_source
-- parties
, hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, op.attribute1 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, op.attribute2 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
-- parties_references
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
-- accounts
, hca.custaccountid cust_account_id
, hca.accountnumber numero_cuenta_cliente
, hca.accountname nombre_cuenta_cliente
, hca.customerclasscode clase_cuenta
, flv3.meaning desc_clase_cuenta
, hca.customertype canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hca.attribute1 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hca.attribute2 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hca.attribute3 forma_pago
, flv7.meaning desc_forma_pago
, hca.attribute4 tipo_factura
, flv8.meaning desc_tipo_factura
, hca.attribute5 metodo_pago
, flv9.meaning desc_metodo_pago
, hca.attribute6 dias_gracia
, hca.attribute7 codigo_bancario
, hca.attribute8 subcanal
, flv10.meaning desc_subcanal
, hca.attribute9 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hca.attribute10 dias_pago
, hca.attribute11 dias_recepcion
, hca.attribute12 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hca.attribute13 no_cliente_factura_concentrada
, hca.attribute14 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hca.attribute15 timbrado_individual
, hca.attribute16 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hca.attribute17 numero_proveedor
, hca.attribute18 incoterm
, hca.attribute19 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hca.attribute20 macro_canal
, flv15.meaning desc_macro_canal
, hca.attribute21 giro_cliente
, flv16.meaning desc_giro_cliente
, hca.attribute22 genera_addenda
, hca.attribute23 referencia_cie
, hca.attribute24 referencia_cuenta
-- account_references
, hosr2.origsystemrefid account_osr_id
, hosr2.origsystemreference account_osr
-- party_sites
, hps.partysiteid party_site_id
, hps.partysitenumber numero_sitio
, hps.partysitename nombre_sitio
, hps.identifyingaddressflag direccion_primaria
-- party_sites_refernces
, hosr3.origsystemrefid party_site_osr_id
, hosr3.origsystemreference party_site_osr
-- hz_locations
, hl.locationid location_id
, hl.country pais
, hl.postalcode codigo_postal
, hl.address1 calle
, hl.address2 numero_exterior
, hl.address3 numero_interior
, hl.city colonia
, hl.county alcaldia_municipio
, hl.state estado
, hl.addrelementattribute1 entre_calle_1
, hl.addrelementattribute2 entre_calle_2
, hl.addrelementattribute3 latitud
, hl.addrelementattribute4 longitud
, hl.addrelementattribute5 codigo_gln
-- locations_refrences
, hosr7.origsystemrefid location_osr_id
, hosr7.origsystemreference location_osr
-- account_sites
, hcasa.custacctsiteid cust_acct_site_id
, hcasa.billtoflag bill_to_flag
, hcasa.shiptoflag ship_to_flag
, hcasa.attribute1 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hcasa.attribute2 factura_anticipada
, hcasa.attribute3 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hcasa.attribute4 no_sucursal_factura_concentrada
, hcasa.attribute5 codigo_exportacion
, hcasa.attribute6 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hcasa.attribute7 regional_responsable
, flv20.meaning desc_regional_responsable
, hcasa.attribute8 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hcasa.attribute9 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hcasa.attribute10 categoria_interna
, flv23.meaning desc_categoria_interna
, hcasa.attribute11 cuenta_bancaria
, hcasa.attribute12 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hcasa.attribute13 codigo_sucursal
, hcasa.attribute14 identificador_edi
, hcasa.attribute15 zona_precios
, flv25.meaning desc_zona_precios
, hcasa.attribute16 guid_chep
, hcasa.attribute17 inspeccion_calidad
, hcasa.attribute18 numero_tienda_retek
, hcasa.attribute19 perfil_cliente
, hcasa.attribute20 tipo_pedido_cliente
, hcasa.attribute21 referencia_sucursal
-- account_site_references
, hosr4.origsystemrefid account_site_osr_id
, hosr4.origsystemreference account_site_osr
-- party_site_uses
, hpsu.party_site_use_id
, hpsu.primario_por_tipo
-- party_site_uses_references
, hpsu.party_site_use_osr_id
, hpsu.party_site_use_osr
-- account_site_uses
, hcsu.siteuseid site_use_id
, hcsu.primaryflag sitio_cuenta_primario
, hcsu.siteusecode uso_sitio_cuenta
, hcsu.location sitio
-- account_site_uses_references
, hosr6.origsystemrefid account_site_use_osr_id
, hosr6.origsystemreference account_site_use_osr
-- terminos de pago
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
, flv18.meaning
, fasis.setname
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo_stg hp
join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg op
on hp.partyid = op.party_id
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountextractpvo_stg hca
on hp.partyid = hca.partyid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountsiteextractpvo_stg hcasa
on hca.custaccountid = hcasa.custaccountid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteextractpvo_stg hps
on hcasa.partysiteid = hps.partysiteid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo_stg hl
on hps.locationid = hl.locationid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeracctsiteuseextractpvo_stg hcsu
on hcasa.custacctsiteid = hcsu.custacctsiteid
join alp_party_site_use hpsu
on hps.partysiteid = hpsu.party_site_id
and hcsu.siteusecode = hpsu.site_use_type
and hpsu.reg = 1
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo_stg rtt
on hcsu.paymenttermid = rtt.ratermtltermid
and rtt.ratermtllanguage = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_setidsetspvo_stg fasis
on hcasa.setid = fasis.setid
and fasis.language = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr1
on hp.partyid = hosr1.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr2
on hca.custaccountid = hosr2.ownertableid
and hca.origsystemreference = hosr2.origsystemreference
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr3
on hps.partysiteid = hosr3.ownertableid
and hosr3.origsystemreference like 'PS%'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr4
on hcasa.custacctsiteid = hosr4.ownertableid
and hosr4.origsystemreference = 'FUSION'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr6
on hcsu.siteuseid = hosr6.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr7
on hl.locationid = hosr7.ownertableid
left join alp_cat_fnd_lookups flv1
on op.attribute1 = flv1.code
and flv1.type = 'ALP_REGIMENFISCAL'
and flv1.view_appl_id = 0
left join alp_cat_fnd_lookups flv2
on op.attribute2 = flv2.code
and flv2.type = 'ALP_TIPOFISCAL'
and flv2.view_appl_id = 0
left join alp_cat_fnd_lookups flv3
on hca.customerclasscode = flv3.code
and flv3.type = 'ALP_TIPOCREDITO'
and flv3.view_appl_id = 0
left join alp_cat_fnd_lookups flv4
on hca.customertype = flv4.code
and flv4.type = 'ALP_CANAL'
and flv4.view_appl_id = 0
left join alp_cat_fnd_lookups flv5
on hca.attribute1 = flv5.code
and flv5.type = 'ALP_GRUPOCOMERCIAL'
and flv5.view_appl_id = 0
left join alp_cat_fnd_lookups flv6
on hca.attribute2 = flv6.code
and flv6.type = 'ALP_UNIDADFACTURACION'
and flv6.view_appl_id = 0
left join alp_cat_fnd_lookups flv7
on hca.attribute3 = flv7.code
and flv7.type = 'ALP_FORMAPAGO'
and flv7.view_appl_id = 0
left join alp_cat_fnd_lookups flv8
on hca.attribute4 = flv8.code
and flv8.type = 'ALP_TIPOFACTURA'
and flv8.view_appl_id = 0
left join alp_cat_fnd_lookups flv9
on hca.attribute5 = flv9.code
and flv9.type = 'ALP_METODOPAGO'
and flv9.view_appl_id = 0
left join alp_cat_fnd_lookups flv10
on hca.attribute8 = flv10.code
and flv10.type = 'ALP_SUBCANAL'
and flv10.view_appl_id = 0
left join alp_cat_fnd_lookups flv11
on hca.attribute9 = flv11.code
and flv11.type = 'ALP_ZCOBRANZA'
and flv11.view_appl_id = 0
left join alp_cat_fnd_lookups flv12
on hca.attribute12 = flv12.code
and flv12.type = 'ALP_CONCENTRADOR'
and flv12.view_appl_id = 0
left join alp_cat_fnd_lookups flv13
on hca.attribute14 = flv13.code
and flv13.type = 'ALP_IBP'
and flv13.view_appl_id = 0
left join alp_cat_fnd_lookups flv14
on hca.attribute16 = flv14.code
and flv14.type = 'ALP_USOCFDI'
and flv14.view_appl_id = 0
left join alp_cat_fnd_lookups flv15
on hca.attribute20 = flv15.code
and flv15.type = 'ALP_MACROCANAL'
and flv15.view_appl_id = 0
left join alp_cat_fnd_lookups flv16
on hca.attribute21 = flv16.code
and flv16.type = 'ALP_GIRO'
and flv16.view_appl_id = 0
left join alp_cat_fnd_lookups flv17
on hcasa.attribute1 = flv17.code
and flv17.type = 'ALP_PLAZADISTRIBUCION'
and flv17.view_appl_id = 0
left join alp_cat_fnd_lookups flv18
on hcasa.attribute3 = flv18.code
and flv18.type = 'ALP_CEDIS'
and flv18.view_appl_id = 0
left join alp_cat_fnd_lookups flv19
on hcasa.attribute6 = flv19.code
and flv19.type = 'ALP_ZNIELSEN'
and flv19.view_appl_id = 0
left join alp_cat_fnd_lookups flv20
on hcasa.attribute7 = flv20.code
and flv20.type = 'ALP_REGIONALRESP'
and flv20.view_appl_id = 0
left join alp_cat_fnd_lookups flv21
on hcasa.attribute8 = flv21.code
and flv21.type = 'ALP_TIPOENTREGA'
and flv21.view_appl_id = 0
left join alp_cat_fnd_lookups flv22
on hcasa.attribute9 = flv22.code
and flv22.type = 'ALP_SEGMENTACION'
and flv22.view_appl_id = 0
left join alp_cat_fnd_lookups flv23
on hcasa.attribute10 = flv23.code
and flv23.type = 'ALP_CLASINTERNA'
and flv23.view_appl_id = 0
left join alp_cat_fnd_lookups flv24
on hcasa.attribute12 = flv24.code
and flv24.type = 'ALP_METODOCOMER'
and flv24.view_appl_id = 0
left join alp_cat_fnd_lookups flv25
on hcasa.attribute15 = flv25.code
and flv25.type = 'ALP_ZONAPRECIOS'
and flv25.view_appl_id = 0
left join alp_cat_fnd_lookups flv26
on hca.attribute19 = flv26.code
and flv26.type = 'ALP_TIPOADENDA'
and flv26.view_appl_id = 0
left join alp_cat_fnd_lookups flv27
on hcasa.attribute3 = flv27.code
and flv27.type = 'ALP_CEDIS_CDM_AS400'
and flv27.view_appl_id = 0
where 1 = 1
and hp.partytype = 'ORGANIZATION'
and ((fasis.setname = 'GPLP_SET'
and hca.customerclasscode = 'R')
or (flv18.meaning is null
and hca.customerclasscode <> 'R')
or flv18.meaning like concat('%',replace(fasis.setname,'_SET',''),'%'))
with alp_party_site_use as
( select row_number()
over ( partition by hpsu.partysiteid
, hpsu.siteusetype
order by hosr5.creationdate) reg
, hpsu.partysiteid party_site_id
, hpsu.siteusetype site_use_type
, hpsu.partysiteuseid party_site_use_id
, hpsu.primarypertype primario_por_tipo
, hosr5.origsystemrefid party_site_use_osr_id
, hosr5.origsystemreference party_site_use_osr
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteuseextractpvo_prd hpsu
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr5
on hpsu.partysiteuseid = hosr5.ownertableid
and hosr5.origsystemreference like 'PSU%')
, alp_cat_fnd_lookups as
( select flv.lookuptype type
, flv.lookupcode code
, flvt.meaning
, flv.setid set_id
, flv.tag
, flv.viewapplicationid view_appl_id
, flv.enabledflag enabled
, flv.startdateactive start_date
, flv.enddateactive end_date
from cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluesextractpvo_prd flv
join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluestlextractpvo_prd flvt
on flv.lookuptype = flvt.lookuptype
and flv.lookupcode = flvt.lookupcode
and flv.viewapplicationid = flvt.viewapplicationid
and flvt.language = 'E')
select 'AR' appl_source
-- parties
, hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, op.attribute1 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, op.attribute2 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
-- parties_references
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
-- accounts
, hca.custaccountid cust_account_id
, hca.accountnumber numero_cuenta_cliente
, hca.accountname nombre_cuenta_cliente
, hca.customerclasscode clase_cuenta
, flv3.meaning desc_clase_cuenta
, hca.customertype canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hca.attribute1 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hca.attribute2 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hca.attribute3 forma_pago
, flv7.meaning desc_forma_pago
, hca.attribute4 tipo_factura
, flv8.meaning desc_tipo_factura
, hca.attribute5 metodo_pago
, flv9.meaning desc_metodo_pago
, hca.attribute6 dias_gracia
, hca.attribute7 codigo_bancario
, hca.attribute8 subcanal
, flv10.meaning desc_subcanal
, hca.attribute9 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hca.attribute10 dias_pago
, hca.attribute11 dias_recepcion
, hca.attribute12 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hca.attribute13 no_cliente_factura_concentrada
, hca.attribute14 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hca.attribute15 timbrado_individual
, hca.attribute16 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hca.attribute17 numero_proveedor
, hca.attribute18 incoterm
, hca.attribute19 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hca.attribute20 macro_canal
, flv15.meaning desc_macro_canal
, hca.attribute21 giro_cliente
, flv16.meaning desc_giro_cliente
, hca.attribute22 genera_addenda
, hca.attribute23 referencia_cie
, hca.attribute24 referencia_cuenta
-- account_references
, hosr2.origsystemrefid account_osr_id
, hosr2.origsystemreference account_osr
-- party_sites
, hps.partysiteid party_site_id
, hps.partysitenumber numero_sitio
, hps.partysitename nombre_sitio
, hps.identifyingaddressflag direccion_primaria
-- party_sites_refernces
, hosr3.origsystemrefid party_site_osr_id
, hosr3.origsystemreference party_site_osr
-- hz_locations
, hl.locationid location_id
, hl.country pais
, hl.postalcode codigo_postal
, hl.address1 calle
, hl.address2 numero_exterior
, hl.address3 numero_interior
, hl.city colonia
, hl.county alcaldia_municipio
, hl.state estado
, hl.addrelementattribute1 entre_calle_1
, hl.addrelementattribute2 entre_calle_2
, hl.addrelementattribute3 latitud
, hl.addrelementattribute4 longitud
, hl.addrelementattribute5 codigo_gln
-- locations_refrences
, hosr7.origsystemrefid location_osr_id
, hosr7.origsystemreference location_osr
-- account_sites
, hcasa.custacctsiteid cust_acct_site_id
, hcasa.billtoflag bill_to_flag
, hcasa.shiptoflag ship_to_flag
, hcasa.attribute1 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hcasa.attribute2 factura_anticipada
, hcasa.attribute3 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hcasa.attribute4 no_sucursal_factura_concentrada
, hcasa.attribute5 codigo_exportacion
, hcasa.attribute6 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hcasa.attribute7 regional_responsable
, flv20.meaning desc_regional_responsable
, hcasa.attribute8 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hcasa.attribute9 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hcasa.attribute10 categoria_interna
, flv23.meaning desc_categoria_interna
, hcasa.attribute11 cuenta_bancaria
, hcasa.attribute12 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hcasa.attribute13 codigo_sucursal
, hcasa.attribute14 identificador_edi
, hcasa.attribute15 zona_precios
, flv25.meaning desc_zona_precios
, hcasa.attribute16 guid_chep
, hcasa.attribute17 inspeccion_calidad
, hcasa.attribute18 numero_tienda_retek
, hcasa.attribute19 perfil_cliente
, hcasa.attribute20 tipo_pedido_cliente
, hcasa.attribute21 referencia_sucursal
-- account_site_references
, hosr4.origsystemrefid account_site_osr_id
, hosr4.origsystemreference account_site_osr
-- party_site_uses
, hpsu.party_site_use_id
, hpsu.primario_por_tipo
-- party_site_uses_references
, hpsu.party_site_use_osr_id
, hpsu.party_site_use_osr
-- account_site_uses
, hcsu.siteuseid site_use_id
, hcsu.primaryflag sitio_cuenta_primario
, hcsu.siteusecode uso_sitio_cuenta
, hcsu.location sitio
-- account_site_uses_references
, hosr6.origsystemrefid account_site_use_osr_id
, hosr6.origsystemreference account_site_use_osr
-- terminos de pago
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
, flv18.meaning
, fasis.setname
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo_prd hp
join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_prd op
on hp.partyid = op.party_id
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountextractpvo_prd hca
on hp.partyid = hca.partyid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountsiteextractpvo_prd hcasa
on hca.custaccountid = hcasa.custaccountid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteextractpvo_prd hps
on hcasa.partysiteid = hps.partysiteid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo_prd hl
on hps.locationid = hl.locationid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeracctsiteuseextractpvo_prd hcsu
on hcasa.custacctsiteid = hcsu.custacctsiteid
join alp_party_site_use hpsu
on hps.partysiteid = hpsu.party_site_id
and hcsu.siteusecode = hpsu.site_use_type
and hpsu.reg = 1
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo_prd rtt
on hcsu.paymenttermid = rtt.ratermtltermid
and rtt.ratermtllanguage = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_setidsetspvo_prd fasis
on hcasa.setid = fasis.setid
and fasis.language = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr1
on hp.partyid = hosr1.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr2
on hca.custaccountid = hosr2.ownertableid
and hca.origsystemreference = hosr2.origsystemreference
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr3
on hps.partysiteid = hosr3.ownertableid
and hosr3.origsystemreference like 'PS%'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr4
on hcasa.custacctsiteid = hosr4.ownertableid
and hosr4.origsystemreference = 'FUSION'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr6
on hcsu.siteuseid = hosr6.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr7
on hl.locationid = hosr7.ownertableid
left join alp_cat_fnd_lookups flv1
on op.attribute1 = flv1.code
and flv1.type = 'ALP_REGIMENFISCAL'
and flv1.view_appl_id = 0
left join alp_cat_fnd_lookups flv2
on op.attribute2 = flv2.code
and flv2.type = 'ALP_TIPOFISCAL'
and flv2.view_appl_id = 0
left join alp_cat_fnd_lookups flv3
on hca.customerclasscode = flv3.code
and flv3.type = 'ALP_TIPOCREDITO'
and flv3.view_appl_id = 0
left join alp_cat_fnd_lookups flv4
on hca.customertype = flv4.code
and flv4.type = 'ALP_CANAL'
and flv4.view_appl_id = 0
left join alp_cat_fnd_lookups flv5
on hca.attribute1 = flv5.code
and flv5.type = 'ALP_GRUPOCOMERCIAL'
and flv5.view_appl_id = 0
left join alp_cat_fnd_lookups flv6
on hca.attribute2 = flv6.code
and flv6.type = 'ALP_UNIDADFACTURACION'
and flv6.view_appl_id = 0
left join alp_cat_fnd_lookups flv7
on hca.attribute3 = flv7.code
and flv7.type = 'ALP_FORMAPAGO'
and flv7.view_appl_id = 0
left join alp_cat_fnd_lookups flv8
on hca.attribute4 = flv8.code
and flv8.type = 'ALP_TIPOFACTURA'
and flv8.view_appl_id = 0
left join alp_cat_fnd_lookups flv9
on hca.attribute5 = flv9.code
and flv9.type = 'ALP_METODOPAGO'
and flv9.view_appl_id = 0
left join alp_cat_fnd_lookups flv10
on hca.attribute8 = flv10.code
and flv10.type = 'ALP_SUBCANAL'
and flv10.view_appl_id = 0
left join alp_cat_fnd_lookups flv11
on hca.attribute9 = flv11.code
and flv11.type = 'ALP_ZCOBRANZA'
and flv11.view_appl_id = 0
left join alp_cat_fnd_lookups flv12
on hca.attribute12 = flv12.code
and flv12.type = 'ALP_CONCENTRADOR'
and flv12.view_appl_id = 0
left join alp_cat_fnd_lookups flv13
on hca.attribute14 = flv13.code
and flv13.type = 'ALP_IBP'
and flv13.view_appl_id = 0
left join alp_cat_fnd_lookups flv14
on hca.attribute16 = flv14.code
and flv14.type = 'ALP_USOCFDI'
and flv14.view_appl_id = 0
left join alp_cat_fnd_lookups flv15
on hca.attribute20 = flv15.code
and flv15.type = 'ALP_MACROCANAL'
and flv15.view_appl_id = 0
left join alp_cat_fnd_lookups flv16
on hca.attribute21 = flv16.code
and flv16.type = 'ALP_GIRO'
and flv16.view_appl_id = 0
left join alp_cat_fnd_lookups flv17
on hcasa.attribute1 = flv17.code
and flv17.type = 'ALP_PLAZADISTRIBUCION'
and flv17.view_appl_id = 0
left join alp_cat_fnd_lookups flv18
on hcasa.attribute3 = flv18.code
and flv18.type = 'ALP_CEDIS'
and flv18.view_appl_id = 0
left join alp_cat_fnd_lookups flv19
on hcasa.attribute6 = flv19.code
and flv19.type = 'ALP_ZNIELSEN'
and flv19.view_appl_id = 0
left join alp_cat_fnd_lookups flv20
on hcasa.attribute7 = flv20.code
and flv20.type = 'ALP_REGIONALRESP'
and flv20.view_appl_id = 0
left join alp_cat_fnd_lookups flv21
on hcasa.attribute8 = flv21.code
and flv21.type = 'ALP_TIPOENTREGA'
and flv21.view_appl_id = 0
left join alp_cat_fnd_lookups flv22
on hcasa.attribute9 = flv22.code
and flv22.type = 'ALP_SEGMENTACION'
and flv22.view_appl_id = 0
left join alp_cat_fnd_lookups flv23
on hcasa.attribute10 = flv23.code
and flv23.type = 'ALP_CLASINTERNA'
and flv23.view_appl_id = 0
left join alp_cat_fnd_lookups flv24
on hcasa.attribute12 = flv24.code
and flv24.type = 'ALP_METODOCOMER'
and flv24.view_appl_id = 0
left join alp_cat_fnd_lookups flv25
on hcasa.attribute15 = flv25.code
and flv25.type = 'ALP_ZONAPRECIOS'
and flv25.view_appl_id = 0
left join alp_cat_fnd_lookups flv26
on hca.attribute19 = flv26.code
and flv26.type = 'ALP_TIPOADENDA'
and flv26.view_appl_id = 0
left join alp_cat_fnd_lookups flv27
on hcasa.attribute3 = flv27.code
and flv27.type = 'ALP_CEDIS_CDM_AS400'
and flv27.view_appl_id = 0
where 1 = 1
and hp.partytype = 'ORGANIZATION'
and ((fasis.setname = 'GPLP_SET'
and hca.customerclasscode = 'R')
or (flv18.meaning is null
and hca.customerclasscode <> 'R')
or flv18.meaning like concat('%',replace(fasis.setname,'_SET',''),'%'))
with alp_fnd_lookup_values as
( select flv.lookuptype lookup_type
, flv.lookupcode lookup_code
, flvt.meaning
, flv.tag
from cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluesextractpvo_stg flv
join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_lookupvaluestlextractpvo_stg flvt
on flv.lookuptype = flvt.lookuptype
and flv.lookupcode = flvt.lookupcode
and flv.viewapplicationid = flvt.viewapplicationid
where flv.lookuptype in ( 'ALP_REGIMENFISCAL'
, 'ALP_TIPOFISCAL'
, 'ALP_TIPOCREDITO'
, 'ALP_CANAL'
, 'ALP_GRUPOCOMERCIAL'
, 'ALP_UNIDADFACTURACION'
, 'ALP_FORMAPAGO'
, 'ALP_TIPOFACTURA'
, 'ALP_METODOPAGO'
, 'ALP_SUBCANAL'
, 'ALP_ZCOBRANZA'
, 'ALP_CONCENTRADOR'
, 'ALP_IBP'
, 'ALP_USOCFDI'
, 'ALP_MACROCANAL'
, 'ALP_GIRO'
, 'ALP_PLAZADISTRIBUCION'
, 'ALP_CEDIS'
, 'ALP_ZNIELSEN'
, 'ALP_REGIONALRESP'
, 'ALP_TIPOENTREGA'
, 'ALP_SEGMENTACION'
, 'ALP_CLASINTERNA'
, 'ALP_METODOCOMER'
, 'ALP_ZONAPRECIOS'
, 'ALP_TIPOADENDA'
, 'ALP_CEDIS_CDM_AS400')
and flvt.language = 'E'
and flv.viewapplicationid = 0)
, alp_party_site_use as
( select row_number()
over ( partition by hpsu.partysiteid
, hpsu.siteusetype
order by hosr5.creationdate) reg
, hpsu.partysiteid party_site_id
, hpsu.siteusetype site_use_type
, hpsu.partysiteuseid party_site_use_id
, hpsu.primarypertype primario_por_tipo
, hosr5.origsystemrefid party_site_use_osr_id
, hosr5.origsystemreference party_site_use_osr
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteuseextractpvo_stg hpsu
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr5
on hpsu.partysiteuseid = hosr5.ownertableid
and hosr5.origsystemreference like 'PSU%')
select 'AR' appl_source
-- parties
, hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, op.attribute1 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, op.attribute2 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
-- parties_references
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
-- accounts
, hca.custaccountid cust_account_id
, hca.accountnumber numero_cuenta_cliente
, hca.accountname nombre_cuenta_cliente
, hca.customerclasscode clase_cuenta
, flv3.meaning desc_clase_cuenta
, hca.customertype canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hca.attribute1 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hca.attribute2 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hca.attribute3 forma_pago
, flv7.meaning desc_forma_pago
, hca.attribute4 tipo_factura
, flv8.meaning desc_tipo_factura
, hca.attribute5 metodo_pago
, flv9.meaning desc_metodo_pago
, hca.attribute6 dias_gracia
, hca.attribute7 codigo_bancario
, hca.attribute8 subcanal
, flv10.meaning desc_subcanal
, hca.attribute9 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hca.attribute10 dias_pago
, hca.attribute11 dias_recepcion
, hca.attribute12 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hca.attribute13 no_cliente_factura_concentrada
, hca.attribute14 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hca.attribute15 timbrado_individual
, hca.attribute16 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hca.attribute17 numero_proveedor
, hca.attribute18 incoterm
, hca.attribute19 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hca.attribute20 macro_canal
, flv15.meaning desc_macro_canal
, hca.attribute21 giro_cliente
, flv16.meaning desc_giro_cliente
, hca.attribute22 genera_addenda
, hca.attribute23 referencia_cie
, hca.attribute24 referencia_cuenta
-- account_references
, hosr2.origsystemrefid account_osr_id
, hosr2.origsystemreference account_osr
-- party_sites
, hps.partysiteid party_site_id
, hps.partysitenumber numero_sitio
, hps.partysitename nombre_sitio
, hps.identifyingaddressflag direccion_primaria
-- party_sites_refernces
, hosr3.origsystemrefid party_site_osr_id
, hosr3.origsystemreference party_site_osr
-- hz_locations
, hl.locationid location_id
, hl.country pais
, hl.postalcode codigo_postal
, hl.address1 calle
, hl.address2 numero_exterior
, hl.address3 numero_interior
, hl.city colonia
, hl.county alcaldia_municipio
, hl.state estado
, hl.addrelementattribute1 entre_calle_1
, hl.addrelementattribute2 entre_calle_2
, hl.addrelementattribute3 latitud
, hl.addrelementattribute4 longitud
, hl.addrelementattribute5 codigo_gln
-- locations_refrences
, hosr7.origsystemrefid location_osr_id
, hosr7.origsystemreference location_osr
-- account_sites
, hcasa.custacctsiteid cust_acct_site_id
, hcasa.billtoflag bill_to_flag
, hcasa.shiptoflag ship_to_flag
, hcasa.attribute1 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hcasa.attribute2 factura_anticipada
, hcasa.attribute3 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hcasa.attribute4 no_sucursal_factura_concentrada
, hcasa.attribute5 codigo_exportacion
, hcasa.attribute6 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hcasa.attribute7 regional_responsable
, flv20.meaning desc_regional_responsable
, hcasa.attribute8 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hcasa.attribute9 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hcasa.attribute10 categoria_interna
, flv23.meaning desc_categoria_interna
, hcasa.attribute11 cuenta_bancaria
, hcasa.attribute12 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hcasa.attribute13 codigo_sucursal
, hcasa.attribute14 identificador_edi
, hcasa.attribute15 zona_precios
, flv25.meaning desc_zona_precios
, hcasa.attribute16 guid_chep
, hcasa.attribute17 inspeccion_calidad
, hcasa.attribute18 numero_tienda_retek
, hcasa.attribute19 perfil_cliente
, hcasa.attribute20 tipo_pedido_cliente
, hcasa.attribute21 referencia_sucursal
-- account_site_references
, hosr4.origsystemrefid account_site_osr_id
, hosr4.origsystemreference account_site_osr
-- party_site_uses
, hpsu.party_site_use_id
, hpsu.primario_por_tipo
-- party_site_uses_references
, hpsu.party_site_use_osr_id
, hpsu.party_site_use_osr
-- account_site_uses
, hcsu.siteuseid site_use_id
, hcsu.primaryflag sitio_cuenta_primario
, hcsu.siteusecode uso_sitio_cuenta
, hcsu.location sitio
-- account_site_uses_references
, hosr6.origsystemrefid account_site_use_osr_id
, hosr6.origsystemreference account_site_use_osr
-- terminos de pago
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo_stg hp
join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg op
on hp.partyid = op.party_id
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountextractpvo_stg hca
on hp.partyid = hca.partyid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeraccountsiteextractpvo_stg hcasa
on hca.custaccountid = hcasa.custaccountid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partysiteextractpvo_stg hps
on hcasa.partysiteid = hps.partysiteid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo_stg hl
on hps.locationid = hl.locationid
join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_customeracctsiteuseextractpvo_stg hcsu
on hcasa.custacctsiteid = hcsu.custacctsiteid
join alp_party_site_use hpsu
on hps.partysiteid = hpsu.party_site_id
and hcsu.siteusecode = hpsu.site_use_type
and hpsu.reg = 1
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo_stg rtt
on hcsu.paymenttermid = rtt.ratermtltermid
and rtt.ratermtllanguage = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_aes_setidsetspvo_stg fasis
on hcasa.setid = fasis.setid
and fasis.language = 'E'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr1
on hp.partyid = hosr1.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr2
on hca.custaccountid = hosr2.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr3
on hps.partysiteid = hosr3.ownertableid
and hosr3.origsystemreference like 'PS%'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr4
on hcasa.custacctsiteid = hosr4.ownertableid
and hosr4.origsystemreference = 'FUSION'
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr6
on hcsu.siteuseid = hosr6.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr7
on hl.locationid = hosr7.ownertableid
left join alp_fnd_lookup_values flv1
on op.attribute1 = flv1.lookup_code
and flv1.lookup_type = 'ALP_REGIMENFISCAL'
left join alp_fnd_lookup_values flv2
on op.attribute2 = flv2.lookup_code
and flv2.lookup_type = 'ALP_TIPOFISCAL'
left join alp_fnd_lookup_values flv3
on hca.customerclasscode = flv3.lookup_code
and flv3.lookup_type = 'ALP_TIPOCREDITO'
left join alp_fnd_lookup_values flv4
on hca.customertype = flv4.lookup_code
and flv4.lookup_type = 'ALP_CANAL'
left join alp_fnd_lookup_values flv5
on hca.attribute1 = flv5.lookup_code
and flv5.lookup_type = 'ALP_GRUPOCOMERCIAL'
left join alp_fnd_lookup_values flv6
on hca.attribute2 = flv6.lookup_code
and flv6.lookup_type = 'ALP_UNIDADFACTURACION'
left join alp_fnd_lookup_values flv7
on hca.attribute3 = flv7.lookup_code
and flv7.lookup_type = 'ALP_FORMAPAGO'
left join alp_fnd_lookup_values flv8
on hca.attribute4 = flv8.lookup_code
and flv8.lookup_type = 'ALP_TIPOFACTURA'
left join alp_fnd_lookup_values flv9
on hca.attribute5 = flv9.lookup_code
and flv9.lookup_type = 'ALP_METODOPAGO'
left join alp_fnd_lookup_values flv10
on hca.attribute8 = flv10.lookup_code
and flv10.lookup_type = 'ALP_SUBCANAL'
left join alp_fnd_lookup_values flv11
on hca.attribute9 = flv11.lookup_code
and flv11.lookup_type = 'ALP_ZCOBRANZA'
left join alp_fnd_lookup_values flv12
on hca.attribute12 = flv12.lookup_code
and flv12.lookup_type = 'ALP_CONCENTRADOR'
left join alp_fnd_lookup_values flv13
on hca.attribute14 = flv13.lookup_code
and flv13.lookup_type = 'ALP_IBP'
left join alp_fnd_lookup_values flv14
on hca.attribute16 = flv14.lookup_code
and flv14.lookup_type = 'ALP_USOCFDI'
left join alp_fnd_lookup_values flv15
on hca.attribute20 = flv15.lookup_code
and flv15.lookup_type = 'ALP_MACROCANAL'
left join alp_fnd_lookup_values flv16
on hca.attribute21 = flv16.lookup_code
and flv16.lookup_type = 'ALP_GIRO'
left join alp_fnd_lookup_values flv17
on hcasa.attribute1 = flv17.lookup_code
and flv17.lookup_type = 'ALP_PLAZADISTRIBUCION'
left join alp_fnd_lookup_values flv18
on hcasa.attribute3 = flv18.lookup_code
and flv18.lookup_type = 'ALP_CEDIS'
left join alp_fnd_lookup_values flv19
on hcasa.attribute6 = flv19.lookup_code
and flv19.lookup_type = 'ALP_ZNIELSEN'
left join alp_fnd_lookup_values flv20
on hcasa.attribute7 = flv20.lookup_code
and flv20.lookup_type = 'ALP_REGIONALRESP'
left join alp_fnd_lookup_values flv21
on hcasa.attribute8 = flv21.lookup_code
and flv21.lookup_type = 'ALP_TIPOENTREGA'
left join alp_fnd_lookup_values flv22
on hcasa.attribute9 = flv22.lookup_code
and flv22.lookup_type = 'ALP_SEGMENTACION'
left join alp_fnd_lookup_values flv23
on hcasa.attribute10 = flv23.lookup_code
and flv23.lookup_type = 'ALP_CLASINTERNA'
left join alp_fnd_lookup_values flv24
on hcasa.attribute12 = flv24.lookup_code
and flv24.lookup_type = 'ALP_METODOCOMER'
left join alp_fnd_lookup_values flv25
on hcasa.attribute15 = flv25.lookup_code
and flv25.lookup_type = 'ALP_ZONAPRECIOS'
left join alp_fnd_lookup_values flv26
on hca.attribute19 = flv26.lookup_code
and flv26.lookup_type = 'ALP_TIPOADENDA'
left join alp_fnd_lookup_values flv27
on hcasa.attribute3 = flv27.lookup_code
and flv27.lookup_type = 'ALP_CEDIS_CDM_AS400'
where 1 = 1
and hp.partytype = 'ORGANIZATION'
and ((fasis.setname = 'GPLP_SET'
and hca.customerclasscode = 'R')
or (flv18.meaning is null
and hca.customerclasscode <> 'R')
or flv18.meaning like concat('%',replace(fasis.setname,'_SET',''),'%'))