Catalogo alp_cat_cdm_clientes
1. Modulo
Cuentas por Cobrar (AR)
2. Descripción
Customer Data Management: unificación de identidades de clientes y agrupaciones comerciales de Alpura.
3. Columnas
| # | Columna | Descripción |
|---|---|---|
| 1 | appl_source | Sistema origen del registro. |
| 2 | client_cdm_id | Identificador funcional único del registro de cliente. |
| 3 | party_id | Identificador interno de la entidad principal del cliente. |
| 4 | identificador_registro | Número o identificador de la entidad cliente. |
| 5 | nombre | Nombre o razón social del cliente. |
| 6 | tipo_cliente | Tipo de entidad del cliente. |
| 7 | numero_identificacion_contribuyente | RFC o identificador fiscal del cliente. |
| 8 | regimen_fiscal | Código del régimen fiscal asignado al cliente. |
| 9 | desc_regimen_fiscal | Descripción del régimen fiscal. |
| 10 | tipo_persona_fisica | Código del tipo de persona fiscal. |
| 11 | desc_tipo_persona_fisica | Descripción del tipo de persona fiscal. |
| 12 | party_osr_id | Identificador de la referencia de la entidad en el sistema origen. |
| 13 | party_osr | Referencia de la entidad en el sistema origen. |
| 14 | cust_account_id | Identificador interno de la cuenta del cliente. |
| 15 | numero_cuenta_cliente | Número de cuenta asociado al cliente. |
| 16 | nombre_cuenta_cliente | Nombre asociado a la cuenta del cliente. |
| 17 | clase_cuenta | Código de la clase o tipo de crédito de la cuenta. |
| 18 | desc_clase_cuenta | Descripción de la clase de cuenta. |
| 19 | canal_tipo_cuenta | Código del canal comercial asociado a la cuenta. |
| 20 | desc_canal_tipo_cuenta | Descripción del canal comercial. |
| 21 | canal_400_tipo_cuenta | Equivalencia del canal comercial para AS400. |
| 22 | grupo_comercial | Código del grupo comercial del cliente. |
| 23 | desc_grupo_comercial | Descripción del grupo comercial. |
| 24 | grupo_comercial_400 | Equivalencia del grupo comercial para AS400. |
| 25 | unidad_facturacion | Código de la unidad responsable de facturación. |
| 26 | desc_unidad_facturacion | Descripción de la unidad de facturación. |
| 27 | forma_pago | Código de la forma de pago. |
| 28 | desc_forma_pago | Descripción de la forma de pago. |
| 29 | tipo_factura | Código del tipo de factura aplicable al cliente. |
| 30 | desc_tipo_factura | Descripción del tipo de factura. |
| 31 | metodo_pago | Código del método de pago configurado. |
| 32 | desc_metodo_pago | Descripción del método de pago. |
| 33 | dias_gracia | Número de días de gracia otorgados al cliente. |
| 34 | codigo_bancario | Código bancario asociado al cliente. |
| 35 | subcanal | Código del subcanal comercial. |
| 36 | desc_subcanal | Descripción del subcanal comercial. |
| 37 | zona_cobranza | Código de la zona de cobranza. |
| 38 | desc_zona_cobranza | Descripción de la zona de cobranza. |
| 39 | dias_pago | Días pactados para pago. |
| 40 | dias_recepcion | Días o condición de recepción configurada para el cliente. |
| 41 | grupo_concentrador | Código del grupo concentrador de facturación o cobranza. |
| 42 | desc_grupo_concentrador | Descripción del grupo concentrador. |
| 43 | no_cliente_factura_concentrada | Número de cliente para facturación concentrada. |
| 44 | agrupacion_ibp | Código de agrupación IBP. |
| 45 | desc_agrupacion_ibp | Descripción de la agrupación IBP. |
| 46 | agrupacion_ibp_400 | Equivalencia de la agrupación IBP para AS400. |
| 47 | timbrado_individual | Indicador de timbrado individual. |
| 48 | uso_cfdi | Código de uso de CFDI asignado al cliente. |
| 49 | desc_uso_cfdi | Descripción del uso de CFDI. |
| 50 | numero_proveedor | Número de proveedor asociado al cliente, cuando aplica. |
| 51 | incoterm | Término comercial internacional asociado a la cuenta. |
| 52 | tipo_addenda | Código del tipo de addenda requerido. |
| 53 | desc_tipo_addenda | Descripción del tipo de addenda. |
| 54 | macro_canal | Código del macrocanal comercial. |
| 55 | desc_macro_canal | Descripción del macrocanal comercial. |
| 56 | giro_cliente | Código del giro o actividad comercial del cliente. |
| 57 | desc_giro_cliente | Descripción del giro del cliente. |
| 58 | genera_addenda | Indicador de generación de addenda. |
| 59 | referencia_cie | Referencia CIE asociada a la cuenta. |
| 60 | referencia_cuenta | Referencia de la cuenta en el sistema origen. |
| 61 | account_osr_id | Identificador de referencia de origen de la cuenta. |
| 62 | account_osr | Referencia de origen de la cuenta. |
| 63 | party_site_id | Identificador interno del sitio de la entidad. |
| 64 | numero_sitio | Número interno del sitio. |
| 65 | nombre_sitio | Nombre del sitio o sucursal del cliente. |
| 66 | direccion_primaria | Indicador de dirección primaria. |
| 67 | party_site_osr_id | Identificador de referencia de origen del sitio. |
| 68 | party_site_osr | Referencia de origen del sitio. |
| 69 | location_id | Identificador interno de la ubicación o dirección. |
| 70 | pais | País de la dirección. |
| 71 | codigo_postal | Código postal de la dirección. |
| 72 | calle | Calle de la dirección. |
| 73 | numero_exterior | Número exterior del domicilio. |
| 74 | numero_interior | Número interior del domicilio. |
| 75 | colonia | Colonia o localidad de la dirección. |
| 76 | alcaldia_municipio | Alcaldía o municipio de la dirección. |
| 77 | estado | Estado o entidad federativa de la dirección. |
| 78 | entre_calle_1 | Primera calle de referencia. |
| 79 | entre_calle_2 | Segunda calle de referencia. |
| 80 | latitud | Coordenada de latitud de la ubicación. |
| 81 | longitud | Coordenada de longitud de la ubicación. |
| 82 | codigo_gln | Código GLN asociado a la ubicación. |
| 83 | location_osr_id | Identificador de referencia de origen de la ubicación. |
| 84 | location_osr | Referencia de origen de la ubicación. |
| 85 | cust_acct_site_id | Identificador interno de la relación cuenta-sitio. |
| 86 | bill_to_flag | Indica si el sitio se utiliza para facturación. |
| 87 | ship_to_flag | Indica si el sitio se utiliza para envío. |
| 88 | plaza_distribucion | Código de la plaza de distribución. |
| 89 | desc_plaza_distribucion | Descripción de la plaza de distribución. |
| 90 | plaza_distribucion_400 | Equivalencia de la plaza de distribución para AS400. |
| 91 | factura_anticipada | Indicador de facturación anticipada. |
| 92 | cedis_asignado | Código del CEDIS asignado al sitio. |
| 93 | desc_cedis_asignado | Descripción del CEDIS asignado. |
| 94 | cedis_asignado_400 | Equivalencia del CEDIS asignado para AS400. |
| 95 | no_sucursal_factura_concentrada | Número de sucursal para facturación concentrada. |
| 96 | codigo_exportacion | Código de exportación asociado al sitio. |
| 97 | zona_nielsen | Código de zona Nielsen. |
| 98 | desc_zona_nielsen | Descripción de la zona Nielsen. |
| 99 | regional_responsable | Código de la regional responsable. |
| 100 | desc_regional_responsable | Descripción de la regional responsable. |
| 101 | tipo_entrega | Código del tipo de entrega. |
| 102 | desc_tipo_entrega | Descripción del tipo de entrega. |
| 103 | segmentacion_categoria_externa | Código de segmentación de categoría externa. |
| 104 | desc_segmentacion_categoria_externa | Descripción de la segmentación externa. |
| 105 | categoria_interna | Código de categoría interna. |
| 106 | desc_categoria_interna | Descripción de la categoría interna. |
| 107 | cuenta_bancaria | Número o identificador de cuenta bancaria. |
| 108 | metodo_comercializacion | Código del método de comercialización. |
| 109 | desc_metodo_comercializacion | Descripción del método de comercialización. |
| 110 | codigo_sucursal | Código de sucursal. |
| 111 | identificador_edi | Identificador EDI del cliente o sitio. |
| 112 | zona_precios | Código de la zona de precios. |
| 113 | desc_zona_precios | Descripción de la zona de precios. |
| 114 | guid_chep | Identificador GUID para integración con CHEP. |
| 115 | inspeccion_calidad | Indicador o configuración de inspección de calidad. |
| 116 | numero_tienda_retek | Número de tienda en Retek. |
| 117 | perfil_cliente | Perfil comercial asignado al cliente. |
| 118 | tipo_pedido_cliente | Tipo de pedido configurado para el cliente. |
| 119 | referencia_sucursal | Referencia de la sucursal en el sistema origen. |
| 120 | account_site_osr_id | Identificador de referencia de origen de la relación cuenta-sitio. |
| 121 | account_site_osr | Referencia de origen de la relación cuenta-sitio. |
| 122 | party_site_use_id | Identificador del uso del sitio de la entidad. |
| 123 | primario_por_tipo | Indica si el sitio es primario para un tipo de uso. |
| 124 | party_site_use_osr_id | Identificador de referencia de origen del uso del sitio. |
| 125 | party_site_use_osr | Referencia de origen del uso del sitio. |
| 126 | site_use_id | Identificador del uso de sitio de la cuenta. |
| 127 | sitio_cuenta_primario | Indica si el sitio es primario para la cuenta. |
| 128 | uso_sitio_cuenta | Tipo de uso del sitio de cuenta, por ejemplo facturación o envío. |
| 129 | sitio | Número o identificador del sitio o sucursal dentro de CDM. |
| 130 | account_site_use_osr_id | Identificador de referencia de origen del uso de sitio de cuenta. |
| 131 | account_site_use_osr | Referencia de origen del uso de sitio de cuenta. |
| 132 | terminos_pago | Nombre de los términos de pago configurados para el cliente. |
| 133 | desc_terminos_pago | Descripción de los términos de pago. |
| 134 | cedis_asignado_as400 | Código equivalente del CEDIS asignado para AS400. |
4. Querys
- Databricks DEV
- Databricks UAT
- Databricks PROD
- Oracle
with 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')
, alp_cdm_clientes as
( select hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, hopc.extn_attribute_char054 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, hopc.extn_attribute_char038 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
, nvl(hopc.party_number,' ') numero_cuenta_cliente
, hopc.organization_name nombre_cuenta_cliente
, hopc.extn_attribute_char025 clase_cuenta
, flv3.meaning desc_clase_cuenta
, hopc.extn_attribute_char024 canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hopc.extn_attribute_char039 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hopc.extn_attribute_char046 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hopc.extn_attribute_char060 forma_pago
, flv7.meaning desc_forma_pago
, hopc.extn_attribute_char029 tipo_factura
, flv8.meaning desc_tipo_factura
, hopc.extn_attribute_char047 metodo_pago
, flv9.meaning desc_metodo_pago
, hopc.extn_attribute_number006 dias_gracia
, cast(hopc.extn_attribute_char072 as double) codigo_bancario
, hopc.extn_attribute_char049 subcanal
, flv10.meaning desc_subcanal
, hopc.extn_attribute_char050 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hopc.extn_attribute_char032 dias_pago
, hopc.extn_attribute_char033 dias_recepcion
, hopc.extn_attribute_char051 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hopc.extn_attribute_number009 no_cliente_factura_concentrada
, hopc.extn_attribute_char052 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hopc.extn_attribute_char020 timbrado_individual
, hopc.extn_attribute_char053 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hopc.extn_attribute_char011 numero_proveedor
, hopc.extn_attribute_char055 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hopc.extn_attribute_char048 macro_canal
, flv15.meaning desc_macro_canal
, hopc.extn_attribute_char056 giro_cliente
, flv16.meaning desc_giro_cliente
, hopc.extn_attribute_char015 referencia_cie
, hosr2.origsystemreference referencia_cuenta
, 'CA'
|| hosr2.origsystemreference account_osr
, hops.organization_name nombre_sitio
, 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
, hops.extn_attribute_char063 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hops.extn_attribute_char062 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hopc.extn_attribute_number010 no_sucursal_factura_concentrada
, hops.extn_attribute_char031 codigo_exportacion
, hops.extn_attribute_char064 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hops.extn_attribute_char065 regional_responsable
, flv20.meaning desc_regional_responsable
, hops.extn_attribute_char061 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hops.extn_attribute_char066 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hops.extn_attribute_char030 categoria_interna
, flv23.meaning desc_categoria_interna
, hopc.extn_attribute_number004 cuenta_bancaria
, hops.extn_attribute_char036 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hops.extn_attribute_char007 identificador_edi
, hops.extn_attribute_char067 zona_precios
, flv25.meaning desc_zona_precios
, hops.extn_attribute_number007 guid_chep
, hops.extn_attribute_char023 inspeccion_calidad
, hops.extn_attribute_char012 numero_tienda_retek
, hops.extn_attribute_char068 perfil_cliente
, hops.extn_attribute_char069 tipo_pedido_cliente
, REPLACE(hosr3.origsystemreference,hosr2.origsystemreference) referencia_sucursal
, hops.party_number sitio
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
, row_number()
over ( partition by hopo.party_id
, hopc.party_id
, hops.party_id
order by hops.party_id desc) reg
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo hp
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles hopo
on hp.partyid = hopo.party_id
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles hopc
on hopo.party_id = hopc.extn_attribute_char003
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles hops
on hopc.party_id = hops.extn_attribute_number001
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo hl
on hp.idenaddrlocationid = hl.locationid
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 hopc.party_id = hosr2.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo hosr3
on hops.party_id = hosr3.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo rtt
on CAST(CAST(hopc.extn_attribute_number011 AS BIGINT) AS STRING) = rtt.ratermtlname
and rtt.ratermtllanguage = 'E'
left join alp_cat_fnd_lookups flv1
on hopc.extn_attribute_char054 = flv1.code
and flv1.type = 'ALP_REGIMENFISCAL'
and flv1.view_appl_id = 0
left join alp_cat_fnd_lookups flv2
on hopc.extn_attribute_char038 = flv2.code
and flv2.type = 'ALP_TIPOFISCAL'
and flv2.view_appl_id = 0
left join alp_cat_fnd_lookups flv3
on hopc.extn_attribute_char025 = flv3.code
and flv3.type = 'ALP_TIPOCREDITO'
and flv3.view_appl_id = 0
left join alp_cat_fnd_lookups flv4
on hopc.extn_attribute_char024 = flv4.code
and flv4.type = 'ALP_CANAL'
and flv4.view_appl_id = 0
left join alp_cat_fnd_lookups flv5
on hopc.extn_attribute_char039 = flv5.code
and flv5.type = 'ALP_GRUPOCOMERCIAL'
and flv5.view_appl_id = 0
left join alp_cat_fnd_lookups flv6
on hopc.extn_attribute_char046 = flv6.code
and flv6.type = 'ALP_UNIDADFACTURACION'
and flv6.view_appl_id = 0
left join alp_cat_fnd_lookups flv7
on hopc.extn_attribute_char060 = flv7.code
and flv7.type = 'ALP_FORMAPAGO'
and flv7.view_appl_id = 0
left join alp_cat_fnd_lookups flv8
on hopc.extn_attribute_char029 = flv8.code
and flv8.type = 'ALP_TIPOFACTURA'
and flv8.view_appl_id = 0
left join alp_cat_fnd_lookups flv9
on hopc.extn_attribute_char047 = flv9.code
and flv9.type = 'ALP_METODOPAGO'
and flv9.view_appl_id = 0
left join alp_cat_fnd_lookups flv10
on hopc.extn_attribute_char049 = flv10.code
and flv10.type = 'ALP_SUBCANAL'
and flv10.view_appl_id = 0
left join alp_cat_fnd_lookups flv11
on hopc.extn_attribute_char050 = flv11.code
and flv11.type = 'ALP_ZCOBRANZA'
and flv11.view_appl_id = 0
left join alp_cat_fnd_lookups flv12
on hopc.extn_attribute_char051 = flv12.code
and flv12.type = 'ALP_CONCENTRADOR'
and flv12.view_appl_id = 0
left join alp_cat_fnd_lookups flv13
on hopc.extn_attribute_char052 = flv13.code
and flv13.type = 'ALP_IBP'
and flv13.view_appl_id = 0
left join alp_cat_fnd_lookups flv14
on hopc.extn_attribute_char053 = flv14.code
and flv14.type = 'ALP_USOCFDI'
and flv14.view_appl_id = 0
left join alp_cat_fnd_lookups flv15
on hopc.extn_attribute_char048 = flv15.code
and flv15.type = 'ALP_MACROCANAL'
and flv15.view_appl_id = 0
left join alp_cat_fnd_lookups flv16
on hopc.extn_attribute_char056 = flv16.code
and flv16.type = 'ALP_GIRO'
and flv16.view_appl_id = 0
left join alp_cat_fnd_lookups flv17
on hops.extn_attribute_char063 = flv17.code
and flv17.type = 'ALP_PLAZADISTRIBUCION'
and flv17.view_appl_id = 0
left join alp_cat_fnd_lookups flv18
on hops.extn_attribute_char062 = flv18.code
and flv18.type = 'ALP_CEDIS'
and flv18.view_appl_id = 0
left join alp_cat_fnd_lookups flv19
on hops.extn_attribute_char064 = flv19.code
and flv19.type = 'ALP_ZNIELSEN'
and flv19.view_appl_id = 0
left join alp_cat_fnd_lookups flv20
on hops.extn_attribute_char065 = flv20.code
and flv20.type = 'ALP_REGIONALRESP'
and flv20.view_appl_id = 0
left join alp_cat_fnd_lookups flv21
on hops.extn_attribute_char061 = flv21.code
and flv21.type = 'ALP_TIPOENTREGA'
and flv21.view_appl_id = 0
left join alp_cat_fnd_lookups flv22
on hops.extn_attribute_char066 = flv22.code
and flv22.type = 'ALP_SEGMENTACION'
and flv22.view_appl_id = 0
left join alp_cat_fnd_lookups flv23
on hops.extn_attribute_char030 = flv23.code
and flv23.type = 'ALP_CLASINTERNA'
and flv23.view_appl_id = 0
left join alp_cat_fnd_lookups flv24
on hops.extn_attribute_char036 = flv24.code
and flv24.type = 'ALP_METODOCOMER'
and flv24.view_appl_id = 0
left join alp_cat_fnd_lookups flv25
on hops.extn_attribute_char067 = flv25.code
and flv25.type = 'ALP_ZONAPRECIOS'
and flv25.view_appl_id = 0
left join alp_cat_fnd_lookups flv26
on hopc.extn_attribute_char055 = flv26.code
and flv26.type = 'ALP_TIPOADENDA'
and flv26.view_appl_id = 0
left join alp_cat_fnd_lookups flv27
on hops.extn_attribute_char062 = flv27.code
and flv27.type = 'ALP_CEDIS_CDM_AS400'
and flv27.view_appl_id = 0
where 1 = 1
and hopo.extn_attribute_char008 = 'ORGANIZACION')
select 'CDM' appl_source
, CONCAT_WS('|', identificador_registro, numero_cuenta_cliente, sitio) client_cdm_id
-- parties
, party_id
, identificador_registro
, nombre
, tipo_cliente
, numero_identificacion_contribuyente
, regimen_fiscal
, desc_regimen_fiscal
, tipo_persona_fisica
, desc_tipo_persona_fisica
-- parties_references
, party_osr_id
, party_osr
-- accounts
, ' ' cust_account_id
, numero_cuenta_cliente
, nombre_cuenta_cliente
, clase_cuenta
, desc_clase_cuenta
, canal_tipo_cuenta
, desc_canal_tipo_cuenta
, canal_400_tipo_cuenta
, grupo_comercial
, desc_grupo_comercial
, grupo_comercial_400
, unidad_facturacion
, desc_unidad_facturacion
, forma_pago
, desc_forma_pago
, tipo_factura
, desc_tipo_factura
, metodo_pago
, desc_metodo_pago
, dias_gracia
, codigo_bancario
, subcanal
, desc_subcanal
, zona_cobranza
, desc_zona_cobranza
, dias_pago
, dias_recepcion
, grupo_concentrador
, desc_grupo_concentrador
, no_cliente_factura_concentrada
, agrupacion_ibp
, desc_agrupacion_ibp
, agrupacion_ibp_400
, timbrado_individual
, uso_cfdi
, desc_uso_cfdi
, numero_proveedor
, ' ' incoterm
, tipo_addenda
, desc_tipo_addenda
, macro_canal
, desc_macro_canal
, giro_cliente
, desc_giro_cliente
, ' ' genera_addenda
, referencia_cie
, referencia_cuenta
-- account_references
, ' ' account_osr_id
, account_osr
-- party_sites
, ' ' party_site_id
, ' ' numero_sitio
, nombre_sitio
, ' ' direccion_primaria
-- party_sites_refernces
, ' ' party_site_osr_id
, ' ' party_site_osr
-- hz_locations
, location_id
, pais
, codigo_postal
, calle
, numero_exterior
, numero_interior
, colonia
, alcaldia_municipio
, estado
, entre_calle_1
, entre_calle_2
, latitud
, longitud
, codigo_gln
-- locations_refrences
, ' ' location_osr_id
, ' ' location_osr
-- account_sites
, ' ' cust_acct_site_id
, ' ' bill_to_flag
, ' ' ship_to_flag
, plaza_distribucion
, desc_plaza_distribucion
, plaza_distribucion_400
, ' ' factura_anticipada
, cedis_asignado
, desc_cedis_asignado
, cedis_asignado_400
, no_sucursal_factura_concentrada
, codigo_exportacion
, zona_nielsen
, desc_zona_nielsen
, regional_responsable
, desc_regional_responsable
, tipo_entrega
, desc_tipo_entrega
, segmentacion_categoria_externa
, desc_segmentacion_categoria_externa
, categoria_interna
, desc_categoria_interna
, cuenta_bancaria
, metodo_comercializacion
, desc_metodo_comercializacion
, ' ' codigo_sucursal
, identificador_edi
, zona_precios
, desc_zona_precios
, guid_chep
, inspeccion_calidad
, numero_tienda_retek
, perfil_cliente
, tipo_pedido_cliente
, referencia_sucursal
-- account_site_references
, ' ' account_site_osr_id
, ' ' account_site_osr
-- party_site_uses
, ' ' party_site_use_id
, ' ' primario_por_tipo
-- party_site_uses_references
, ' ' party_site_use_osr_id
, ' ' party_site_use_osr
-- account_site_uses
, ' ' site_use_id
, ' ' sitio_cuenta_primario
, ' ' uso_sitio_cuenta
, sitio
-- account_site_uses_references
, ' ' account_site_use_osr_id
, ' ' account_site_use_osr
-- terminos de pago
, terminos_pago
, desc_terminos_pago
, cedis_asignado_as400
from alp_cdm_clientes
where reg = 1
with 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')
, alp_cdm_clientes as
( select hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, hopc.extn_attribute_char054 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, hopc.extn_attribute_char038 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
, nvl(hopc.party_number,' ') numero_cuenta_cliente
, hopc.organization_name nombre_cuenta_cliente
, hopc.extn_attribute_char025 clase_cuenta
, flv3.meaning desc_clase_cuenta
, hopc.extn_attribute_char024 canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hopc.extn_attribute_char039 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hopc.extn_attribute_char046 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hopc.extn_attribute_char060 forma_pago
, flv7.meaning desc_forma_pago
, hopc.extn_attribute_char029 tipo_factura
, flv8.meaning desc_tipo_factura
, hopc.extn_attribute_char047 metodo_pago
, flv9.meaning desc_metodo_pago
, hopc.extn_attribute_number006 dias_gracia
, cast(hopc.extn_attribute_char072 as double) codigo_bancario
, hopc.extn_attribute_char049 subcanal
, flv10.meaning desc_subcanal
, hopc.extn_attribute_char050 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hopc.extn_attribute_char032 dias_pago
, hopc.extn_attribute_char033 dias_recepcion
, hopc.extn_attribute_char051 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hopc.extn_attribute_number009 no_cliente_factura_concentrada
, hopc.extn_attribute_char052 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hopc.extn_attribute_char020 timbrado_individual
, hopc.extn_attribute_char053 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hopc.extn_attribute_char011 numero_proveedor
, hopc.extn_attribute_char055 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hopc.extn_attribute_char048 macro_canal
, flv15.meaning desc_macro_canal
, hopc.extn_attribute_char056 giro_cliente
, flv16.meaning desc_giro_cliente
, hopc.extn_attribute_char015 referencia_cie
, hosr2.origsystemreference referencia_cuenta
, 'CA'
|| hosr2.origsystemreference account_osr
, hops.organization_name nombre_sitio
, 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
, hops.extn_attribute_char063 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hops.extn_attribute_char062 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hopc.extn_attribute_number010 no_sucursal_factura_concentrada
, hops.extn_attribute_char031 codigo_exportacion
, hops.extn_attribute_char064 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hops.extn_attribute_char065 regional_responsable
, flv20.meaning desc_regional_responsable
, hops.extn_attribute_char061 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hops.extn_attribute_char066 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hops.extn_attribute_char030 categoria_interna
, flv23.meaning desc_categoria_interna
, hopc.extn_attribute_number004 cuenta_bancaria
, hops.extn_attribute_char036 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hops.extn_attribute_char007 identificador_edi
, hops.extn_attribute_char067 zona_precios
, flv25.meaning desc_zona_precios
, hops.extn_attribute_number007 guid_chep
, hops.extn_attribute_char023 inspeccion_calidad
, hops.extn_attribute_char012 numero_tienda_retek
, hops.extn_attribute_char068 perfil_cliente
, hops.extn_attribute_char069 tipo_pedido_cliente
, REPLACE(hosr3.origsystemreference,hosr2.origsystemreference) referencia_sucursal
, hops.party_number sitio
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
, row_number()
over ( partition by hopo.party_id
, hopc.party_id
, hops.party_id
order by hops.party_id desc) reg
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo_stg hp
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg hopo
on hp.partyid = hopo.party_id
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg hopc
on hopo.party_id = hopc.extn_attribute_char003
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg hops
on hopc.party_id = hops.extn_attribute_number001
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo_stg hl
on hp.idenaddrlocationid = hl.locationid
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 hopc.party_id = hosr2.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr3
on hops.party_id = hosr3.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo_stg rtt
on CAST(CAST(hopc.extn_attribute_number011 AS BIGINT) AS STRING) = rtt.ratermtlname
and rtt.ratermtllanguage = 'E'
left join alp_cat_fnd_lookups flv1
on hopc.extn_attribute_char054 = flv1.code
and flv1.type = 'ALP_REGIMENFISCAL'
and flv1.view_appl_id = 0
left join alp_cat_fnd_lookups flv2
on hopc.extn_attribute_char038 = flv2.code
and flv2.type = 'ALP_TIPOFISCAL'
and flv2.view_appl_id = 0
left join alp_cat_fnd_lookups flv3
on hopc.extn_attribute_char025 = flv3.code
and flv3.type = 'ALP_TIPOCREDITO'
and flv3.view_appl_id = 0
left join alp_cat_fnd_lookups flv4
on hopc.extn_attribute_char024 = flv4.code
and flv4.type = 'ALP_CANAL'
and flv4.view_appl_id = 0
left join alp_cat_fnd_lookups flv5
on hopc.extn_attribute_char039 = flv5.code
and flv5.type = 'ALP_GRUPOCOMERCIAL'
and flv5.view_appl_id = 0
left join alp_cat_fnd_lookups flv6
on hopc.extn_attribute_char046 = flv6.code
and flv6.type = 'ALP_UNIDADFACTURACION'
and flv6.view_appl_id = 0
left join alp_cat_fnd_lookups flv7
on hopc.extn_attribute_char060 = flv7.code
and flv7.type = 'ALP_FORMAPAGO'
and flv7.view_appl_id = 0
left join alp_cat_fnd_lookups flv8
on hopc.extn_attribute_char029 = flv8.code
and flv8.type = 'ALP_TIPOFACTURA'
and flv8.view_appl_id = 0
left join alp_cat_fnd_lookups flv9
on hopc.extn_attribute_char047 = flv9.code
and flv9.type = 'ALP_METODOPAGO'
and flv9.view_appl_id = 0
left join alp_cat_fnd_lookups flv10
on hopc.extn_attribute_char049 = flv10.code
and flv10.type = 'ALP_SUBCANAL'
and flv10.view_appl_id = 0
left join alp_cat_fnd_lookups flv11
on hopc.extn_attribute_char050 = flv11.code
and flv11.type = 'ALP_ZCOBRANZA'
and flv11.view_appl_id = 0
left join alp_cat_fnd_lookups flv12
on hopc.extn_attribute_char051 = flv12.code
and flv12.type = 'ALP_CONCENTRADOR'
and flv12.view_appl_id = 0
left join alp_cat_fnd_lookups flv13
on hopc.extn_attribute_char052 = flv13.code
and flv13.type = 'ALP_IBP'
and flv13.view_appl_id = 0
left join alp_cat_fnd_lookups flv14
on hopc.extn_attribute_char053 = flv14.code
and flv14.type = 'ALP_USOCFDI'
and flv14.view_appl_id = 0
left join alp_cat_fnd_lookups flv15
on hopc.extn_attribute_char048 = flv15.code
and flv15.type = 'ALP_MACROCANAL'
and flv15.view_appl_id = 0
left join alp_cat_fnd_lookups flv16
on hopc.extn_attribute_char056 = flv16.code
and flv16.type = 'ALP_GIRO'
and flv16.view_appl_id = 0
left join alp_cat_fnd_lookups flv17
on hops.extn_attribute_char063 = flv17.code
and flv17.type = 'ALP_PLAZADISTRIBUCION'
and flv17.view_appl_id = 0
left join alp_cat_fnd_lookups flv18
on hops.extn_attribute_char062 = flv18.code
and flv18.type = 'ALP_CEDIS'
and flv18.view_appl_id = 0
left join alp_cat_fnd_lookups flv19
on hops.extn_attribute_char064 = flv19.code
and flv19.type = 'ALP_ZNIELSEN'
and flv19.view_appl_id = 0
left join alp_cat_fnd_lookups flv20
on hops.extn_attribute_char065 = flv20.code
and flv20.type = 'ALP_REGIONALRESP'
and flv20.view_appl_id = 0
left join alp_cat_fnd_lookups flv21
on hops.extn_attribute_char061 = flv21.code
and flv21.type = 'ALP_TIPOENTREGA'
and flv21.view_appl_id = 0
left join alp_cat_fnd_lookups flv22
on hops.extn_attribute_char066 = flv22.code
and flv22.type = 'ALP_SEGMENTACION'
and flv22.view_appl_id = 0
left join alp_cat_fnd_lookups flv23
on hops.extn_attribute_char030 = flv23.code
and flv23.type = 'ALP_CLASINTERNA'
and flv23.view_appl_id = 0
left join alp_cat_fnd_lookups flv24
on hops.extn_attribute_char036 = flv24.code
and flv24.type = 'ALP_METODOCOMER'
and flv24.view_appl_id = 0
left join alp_cat_fnd_lookups flv25
on hops.extn_attribute_char067 = flv25.code
and flv25.type = 'ALP_ZONAPRECIOS'
and flv25.view_appl_id = 0
left join alp_cat_fnd_lookups flv26
on hopc.extn_attribute_char055 = flv26.code
and flv26.type = 'ALP_TIPOADENDA'
and flv26.view_appl_id = 0
left join alp_cat_fnd_lookups flv27
on hops.extn_attribute_char062 = flv27.code
and flv27.type = 'ALP_CEDIS_CDM_AS400'
and flv27.view_appl_id = 0
where 1 = 1
and hopo.extn_attribute_char008 = 'ORGANIZACION')
select 'CDM' appl_source
, CONCAT_WS('|', identificador_registro, numero_cuenta_cliente, sitio) client_cdm_id
-- parties
, party_id
, identificador_registro
, nombre
, tipo_cliente
, numero_identificacion_contribuyente
, regimen_fiscal
, desc_regimen_fiscal
, tipo_persona_fisica
, desc_tipo_persona_fisica
-- parties_references
, party_osr_id
, party_osr
-- accounts
, ' ' cust_account_id
, numero_cuenta_cliente
, nombre_cuenta_cliente
, clase_cuenta
, desc_clase_cuenta
, canal_tipo_cuenta
, desc_canal_tipo_cuenta
, canal_400_tipo_cuenta
, grupo_comercial
, desc_grupo_comercial
, grupo_comercial_400
, unidad_facturacion
, desc_unidad_facturacion
, forma_pago
, desc_forma_pago
, tipo_factura
, desc_tipo_factura
, metodo_pago
, desc_metodo_pago
, dias_gracia
, codigo_bancario
, subcanal
, desc_subcanal
, zona_cobranza
, desc_zona_cobranza
, dias_pago
, dias_recepcion
, grupo_concentrador
, desc_grupo_concentrador
, no_cliente_factura_concentrada
, agrupacion_ibp
, desc_agrupacion_ibp
, agrupacion_ibp_400
, timbrado_individual
, uso_cfdi
, desc_uso_cfdi
, numero_proveedor
, ' ' incoterm
, tipo_addenda
, desc_tipo_addenda
, macro_canal
, desc_macro_canal
, giro_cliente
, desc_giro_cliente
, ' ' genera_addenda
, referencia_cie
, referencia_cuenta
-- account_references
, ' ' account_osr_id
, account_osr
-- party_sites
, ' ' party_site_id
, ' ' numero_sitio
, nombre_sitio
, ' ' direccion_primaria
-- party_sites_refernces
, ' ' party_site_osr_id
, ' ' party_site_osr
-- hz_locations
, location_id
, pais
, codigo_postal
, calle
, numero_exterior
, numero_interior
, colonia
, alcaldia_municipio
, estado
, entre_calle_1
, entre_calle_2
, latitud
, longitud
, codigo_gln
-- locations_refrences
, ' ' location_osr_id
, ' ' location_osr
-- account_sites
, ' ' cust_acct_site_id
, ' ' bill_to_flag
, ' ' ship_to_flag
, plaza_distribucion
, desc_plaza_distribucion
, plaza_distribucion_400
, ' ' factura_anticipada
, cedis_asignado
, desc_cedis_asignado
, cedis_asignado_400
, no_sucursal_factura_concentrada
, codigo_exportacion
, zona_nielsen
, desc_zona_nielsen
, regional_responsable
, desc_regional_responsable
, tipo_entrega
, desc_tipo_entrega
, segmentacion_categoria_externa
, desc_segmentacion_categoria_externa
, categoria_interna
, desc_categoria_interna
, cuenta_bancaria
, metodo_comercializacion
, desc_metodo_comercializacion
, ' ' codigo_sucursal
, identificador_edi
, zona_precios
, desc_zona_precios
, guid_chep
, inspeccion_calidad
, numero_tienda_retek
, perfil_cliente
, tipo_pedido_cliente
, referencia_sucursal
-- account_site_references
, ' ' account_site_osr_id
, ' ' account_site_osr
-- party_site_uses
, ' ' party_site_use_id
, ' ' primario_por_tipo
-- party_site_uses_references
, ' ' party_site_use_osr_id
, ' ' party_site_use_osr
-- account_site_uses
, ' ' site_use_id
, ' ' sitio_cuenta_primario
, ' ' uso_sitio_cuenta
, sitio
-- account_site_uses_references
, ' ' account_site_use_osr_id
, ' ' account_site_use_osr
-- terminos de pago
, terminos_pago
, desc_terminos_pago
, cedis_asignado_as400
from alp_cdm_clientes
where reg = 1
with 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')
, alp_cdm_clientes as
( select hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, hopc.extn_attribute_char054 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, hopc.extn_attribute_char038 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
, nvl(hopc.party_number,' ') numero_cuenta_cliente
, hopc.organization_name nombre_cuenta_cliente
, hopc.extn_attribute_char025 clase_cuenta
, flv3.meaning desc_clase_cuenta
, hopc.extn_attribute_char024 canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hopc.extn_attribute_char039 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hopc.extn_attribute_char046 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hopc.extn_attribute_char060 forma_pago
, flv7.meaning desc_forma_pago
, hopc.extn_attribute_char029 tipo_factura
, flv8.meaning desc_tipo_factura
, hopc.extn_attribute_char047 metodo_pago
, flv9.meaning desc_metodo_pago
, hopc.extn_attribute_number006 dias_gracia
, cast(hopc.extn_attribute_char072 as double) codigo_bancario
, hopc.extn_attribute_char049 subcanal
, flv10.meaning desc_subcanal
, hopc.extn_attribute_char050 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hopc.extn_attribute_char032 dias_pago
, hopc.extn_attribute_char033 dias_recepcion
, hopc.extn_attribute_char051 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hopc.extn_attribute_number009 no_cliente_factura_concentrada
, hopc.extn_attribute_char052 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hopc.extn_attribute_char020 timbrado_individual
, hopc.extn_attribute_char053 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hopc.extn_attribute_char011 numero_proveedor
, hopc.extn_attribute_char055 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hopc.extn_attribute_char048 macro_canal
, flv15.meaning desc_macro_canal
, hopc.extn_attribute_char056 giro_cliente
, flv16.meaning desc_giro_cliente
, hopc.extn_attribute_char015 referencia_cie
, hosr2.origsystemreference referencia_cuenta
, 'CA'
|| hosr2.origsystemreference account_osr
, hops.organization_name nombre_sitio
, 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
, hops.extn_attribute_char063 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, hops.extn_attribute_char062 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hopc.extn_attribute_number010 no_sucursal_factura_concentrada
, hops.extn_attribute_char031 codigo_exportacion
, hops.extn_attribute_char064 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hops.extn_attribute_char065 regional_responsable
, flv20.meaning desc_regional_responsable
, hops.extn_attribute_char061 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hops.extn_attribute_char066 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hops.extn_attribute_char030 categoria_interna
, flv23.meaning desc_categoria_interna
, hopc.extn_attribute_number004 cuenta_bancaria
, hops.extn_attribute_char036 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, hops.extn_attribute_char007 identificador_edi
, hops.extn_attribute_char067 zona_precios
, flv25.meaning desc_zona_precios
, hops.extn_attribute_number007 guid_chep
, hops.extn_attribute_char023 inspeccion_calidad
, hops.extn_attribute_char012 numero_tienda_retek
, hops.extn_attribute_char068 perfil_cliente
, hops.extn_attribute_char069 tipo_pedido_cliente
, REPLACE(hosr3.origsystemreference,hosr2.origsystemreference) referencia_sucursal
, hops.party_number sitio
, rtt.ratermtlname terminos_pago
, rtt.ratermtldescription desc_terminos_pago
, flv27.tag cedis_asignado_as400
, row_number()
over ( partition by hopo.party_id
, hopc.party_id
, hops.party_id
order by hops.party_id desc) reg
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo_prd hp
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_prd hopo
on hp.partyid = hopo.party_id
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_prd hopc
on hopo.party_id = hopc.extn_attribute_char003
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_prd hops
on hopc.party_id = hops.extn_attribute_number001
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo_prd hl
on hp.idenaddrlocationid = hl.locationid
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 hopc.party_id = hosr2.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_prd hosr3
on hops.party_id = hosr3.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.fscm_fin_ar_paymenttermtlextractpvo_prd rtt
on CAST(CAST(hopc.extn_attribute_number011 AS BIGINT) AS STRING) = rtt.ratermtlname
and rtt.ratermtllanguage = 'E'
left join alp_cat_fnd_lookups flv1
on hopc.extn_attribute_char054 = flv1.code
and flv1.type = 'ALP_REGIMENFISCAL'
and flv1.view_appl_id = 0
left join alp_cat_fnd_lookups flv2
on hopc.extn_attribute_char038 = flv2.code
and flv2.type = 'ALP_TIPOFISCAL'
and flv2.view_appl_id = 0
left join alp_cat_fnd_lookups flv3
on hopc.extn_attribute_char025 = flv3.code
and flv3.type = 'ALP_TIPOCREDITO'
and flv3.view_appl_id = 0
left join alp_cat_fnd_lookups flv4
on hopc.extn_attribute_char024 = flv4.code
and flv4.type = 'ALP_CANAL'
and flv4.view_appl_id = 0
left join alp_cat_fnd_lookups flv5
on hopc.extn_attribute_char039 = flv5.code
and flv5.type = 'ALP_GRUPOCOMERCIAL'
and flv5.view_appl_id = 0
left join alp_cat_fnd_lookups flv6
on hopc.extn_attribute_char046 = flv6.code
and flv6.type = 'ALP_UNIDADFACTURACION'
and flv6.view_appl_id = 0
left join alp_cat_fnd_lookups flv7
on hopc.extn_attribute_char060 = flv7.code
and flv7.type = 'ALP_FORMAPAGO'
and flv7.view_appl_id = 0
left join alp_cat_fnd_lookups flv8
on hopc.extn_attribute_char029 = flv8.code
and flv8.type = 'ALP_TIPOFACTURA'
and flv8.view_appl_id = 0
left join alp_cat_fnd_lookups flv9
on hopc.extn_attribute_char047 = flv9.code
and flv9.type = 'ALP_METODOPAGO'
and flv9.view_appl_id = 0
left join alp_cat_fnd_lookups flv10
on hopc.extn_attribute_char049 = flv10.code
and flv10.type = 'ALP_SUBCANAL'
and flv10.view_appl_id = 0
left join alp_cat_fnd_lookups flv11
on hopc.extn_attribute_char050 = flv11.code
and flv11.type = 'ALP_ZCOBRANZA'
and flv11.view_appl_id = 0
left join alp_cat_fnd_lookups flv12
on hopc.extn_attribute_char051 = flv12.code
and flv12.type = 'ALP_CONCENTRADOR'
and flv12.view_appl_id = 0
left join alp_cat_fnd_lookups flv13
on hopc.extn_attribute_char052 = flv13.code
and flv13.type = 'ALP_IBP'
and flv13.view_appl_id = 0
left join alp_cat_fnd_lookups flv14
on hopc.extn_attribute_char053 = flv14.code
and flv14.type = 'ALP_USOCFDI'
and flv14.view_appl_id = 0
left join alp_cat_fnd_lookups flv15
on hopc.extn_attribute_char048 = flv15.code
and flv15.type = 'ALP_MACROCANAL'
and flv15.view_appl_id = 0
left join alp_cat_fnd_lookups flv16
on hopc.extn_attribute_char056 = flv16.code
and flv16.type = 'ALP_GIRO'
and flv16.view_appl_id = 0
left join alp_cat_fnd_lookups flv17
on hops.extn_attribute_char063 = flv17.code
and flv17.type = 'ALP_PLAZADISTRIBUCION'
and flv17.view_appl_id = 0
left join alp_cat_fnd_lookups flv18
on hops.extn_attribute_char062 = flv18.code
and flv18.type = 'ALP_CEDIS'
and flv18.view_appl_id = 0
left join alp_cat_fnd_lookups flv19
on hops.extn_attribute_char064 = flv19.code
and flv19.type = 'ALP_ZNIELSEN'
and flv19.view_appl_id = 0
left join alp_cat_fnd_lookups flv20
on hops.extn_attribute_char065 = flv20.code
and flv20.type = 'ALP_REGIONALRESP'
and flv20.view_appl_id = 0
left join alp_cat_fnd_lookups flv21
on hops.extn_attribute_char061 = flv21.code
and flv21.type = 'ALP_TIPOENTREGA'
and flv21.view_appl_id = 0
left join alp_cat_fnd_lookups flv22
on hops.extn_attribute_char066 = flv22.code
and flv22.type = 'ALP_SEGMENTACION'
and flv22.view_appl_id = 0
left join alp_cat_fnd_lookups flv23
on hops.extn_attribute_char030 = flv23.code
and flv23.type = 'ALP_CLASINTERNA'
and flv23.view_appl_id = 0
left join alp_cat_fnd_lookups flv24
on hops.extn_attribute_char036 = flv24.code
and flv24.type = 'ALP_METODOCOMER'
and flv24.view_appl_id = 0
left join alp_cat_fnd_lookups flv25
on hops.extn_attribute_char067 = flv25.code
and flv25.type = 'ALP_ZONAPRECIOS'
and flv25.view_appl_id = 0
left join alp_cat_fnd_lookups flv26
on hopc.extn_attribute_char055 = flv26.code
and flv26.type = 'ALP_TIPOADENDA'
and flv26.view_appl_id = 0
left join alp_cat_fnd_lookups flv27
on hops.extn_attribute_char062 = flv27.code
and flv27.type = 'ALP_CEDIS_CDM_AS400'
and flv27.view_appl_id = 0
where 1 = 1
and hopo.extn_attribute_char008 = 'ORGANIZACION')
select 'CDM' appl_source
, CONCAT_WS('|', identificador_registro, numero_cuenta_cliente, sitio) client_cdm_id
-- parties
, party_id
, identificador_registro
, nombre
, tipo_cliente
, numero_identificacion_contribuyente
, regimen_fiscal
, desc_regimen_fiscal
, tipo_persona_fisica
, desc_tipo_persona_fisica
-- parties_references
, party_osr_id
, party_osr
-- accounts
, ' ' cust_account_id
, numero_cuenta_cliente
, nombre_cuenta_cliente
, clase_cuenta
, desc_clase_cuenta
, canal_tipo_cuenta
, desc_canal_tipo_cuenta
, canal_400_tipo_cuenta
, grupo_comercial
, desc_grupo_comercial
, grupo_comercial_400
, unidad_facturacion
, desc_unidad_facturacion
, forma_pago
, desc_forma_pago
, tipo_factura
, desc_tipo_factura
, metodo_pago
, desc_metodo_pago
, dias_gracia
, codigo_bancario
, subcanal
, desc_subcanal
, zona_cobranza
, desc_zona_cobranza
, dias_pago
, dias_recepcion
, grupo_concentrador
, desc_grupo_concentrador
, no_cliente_factura_concentrada
, agrupacion_ibp
, desc_agrupacion_ibp
, agrupacion_ibp_400
, timbrado_individual
, uso_cfdi
, desc_uso_cfdi
, numero_proveedor
, ' ' incoterm
, tipo_addenda
, desc_tipo_addenda
, macro_canal
, desc_macro_canal
, giro_cliente
, desc_giro_cliente
, ' ' genera_addenda
, referencia_cie
, referencia_cuenta
-- account_references
, ' ' account_osr_id
, account_osr
-- party_sites
, ' ' party_site_id
, ' ' numero_sitio
, nombre_sitio
, ' ' direccion_primaria
-- party_sites_refernces
, ' ' party_site_osr_id
, ' ' party_site_osr
-- hz_locations
, location_id
, pais
, codigo_postal
, calle
, numero_exterior
, numero_interior
, colonia
, alcaldia_municipio
, estado
, entre_calle_1
, entre_calle_2
, latitud
, longitud
, codigo_gln
-- locations_refrences
, ' ' location_osr_id
, ' ' location_osr
-- account_sites
, ' ' cust_acct_site_id
, ' ' bill_to_flag
, ' ' ship_to_flag
, plaza_distribucion
, desc_plaza_distribucion
, plaza_distribucion_400
, ' ' factura_anticipada
, cedis_asignado
, desc_cedis_asignado
, cedis_asignado_400
, no_sucursal_factura_concentrada
, codigo_exportacion
, zona_nielsen
, desc_zona_nielsen
, regional_responsable
, desc_regional_responsable
, tipo_entrega
, desc_tipo_entrega
, segmentacion_categoria_externa
, desc_segmentacion_categoria_externa
, categoria_interna
, desc_categoria_interna
, cuenta_bancaria
, metodo_comercializacion
, desc_metodo_comercializacion
, ' ' codigo_sucursal
, identificador_edi
, zona_precios
, desc_zona_precios
, guid_chep
, inspeccion_calidad
, numero_tienda_retek
, perfil_cliente
, tipo_pedido_cliente
, referencia_sucursal
-- account_site_references
, ' ' account_site_osr_id
, ' ' account_site_osr
-- party_site_uses
, ' ' party_site_use_id
, ' ' primario_por_tipo
-- party_site_uses_references
, ' ' party_site_use_osr_id
, ' ' party_site_use_osr
-- account_site_uses
, ' ' site_use_id
, ' ' sitio_cuenta_primario
, ' ' uso_sitio_cuenta
, sitio
-- account_site_uses_references
, ' ' account_site_use_osr_id
, ' ' account_site_use_osr
-- terminos de pago
, terminos_pago
, desc_terminos_pago
, cedis_asignado_as400
from alp_cdm_clientes
where reg = 1
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)
select 'CDM' appl_source
-- parties
, hp.partyid party_id
, hp.partynumber identificador_registro
, hp.partyname nombre
, hp.partytype tipo_cliente
, hp.jgzzfiscalcode numero_identificacion_contribuyente
, hopc.extn_attribute_char054 regimen_fiscal
, flv1.meaning desc_regimen_fiscal
, hopc.extn_attribute_char038 tipo_persona_fisica
, flv2.meaning desc_tipo_persona_fisica
-- parties_references
, hosr1.origsystemrefid party_osr_id
, hosr1.origsystemreference party_osr
-- accounts
, ' ' cust_account_id
, hopc.party_number numero_cuenta_cliente
, hopc.organization_name nombre_cuenta_cliente
, hopc.extn_attribute_char025 clase_cuenta
, flv3.meaning desc_clase_cuenta
, hopc.extn_attribute_char024 canal_tipo_cuenta
, flv4.meaning desc_canal_tipo_cuenta
, flv4.tag canal_400_tipo_cuenta
, hopc.extn_attribute_char039 grupo_comercial
, flv5.meaning desc_grupo_comercial
, flv5.tag grupo_comercial_400
, hopc.extn_attribute_char046 unidad_facturacion
, flv6.meaning desc_unidad_facturacion
, hopc.extn_attribute_char060 forma_pago
, flv7.meaning desc_forma_pago
, hopc.extn_attribute_char029 tipo_factura
, flv8.meaning desc_tipo_factura
, hopc.extn_attribute_char047 metodo_pago
, flv9.meaning desc_metodo_pago
, hopc.extn_attribute_number006 dias_gracia
, cast(hopc.extn_attribute_char072 as double) codigo_bancario
, hopc.extn_attribute_char049 subcanal
, flv10.meaning desc_subcanal
, hopc.extn_attribute_char050 zona_cobranza
, flv11.meaning desc_zona_cobranza
, hopc.extn_attribute_char032 dias_pago
, hopc.extn_attribute_char033 dias_recepcion
, hopc.extn_attribute_char051 grupo_concentrador
, flv12.meaning desc_grupo_concentrador
, hopc.extn_attribute_number009 no_cliente_factura_concentrada
, hopc.extn_attribute_char052 agrupacion_ibp
, flv13.meaning desc_agrupacion_ibp
, flv13.tag agrupacion_ibp_400
, hopc.extn_attribute_char020 timbrado_individual
, hopc.extn_attribute_char053 uso_cfdi
, flv14.meaning desc_uso_cfdi
, hopc.extn_attribute_char011 numero_proveedor
, ' ' incoterm
, hopc.extn_attribute_char055 tipo_addenda
, flv26.meaning desc_tipo_addenda
, hopc.extn_attribute_char048 macro_canal
, flv15.meaning desc_macro_canal
, hopc.extn_attribute_char056 giro_cliente
, flv16.meaning desc_giro_cliente
, ' ' genera_addenda
, hopc.extn_attribute_char015 referencia_cie
, hosr2.origsystemreference referencia_cuenta
-- account_references
, ' ' account_osr_id
, 'CA'
|| hosr2.origsystemreference account_osr
-- party_sites
, ' ' party_site_id
, ' ' numero_sitio
, hops.organization_name nombre_sitio
, ' ' direccion_primaria
-- party_sites_refernces
, ' ' party_site_osr_id
, ' ' 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
, ' ' location_osr_id
, ' ' location_osr
-- account_sites
, ' ' cust_acct_site_id
, ' ' bill_to_flag
, ' ' ship_to_flag
, hops.extn_attribute_char063 plaza_distribucion
, flv17.meaning desc_plaza_distribucion
, flv17.tag plaza_distribucion_400
, ' ' factura_anticipada
, hops.extn_attribute_char062 cedis_asignado
, flv18.meaning desc_cedis_asignado
, flv18.tag cedis_asignado_400
, hopc.extn_attribute_number010 no_sucursal_factura_concentrada
, hops.extn_attribute_char031 codigo_exportacion
, hops.extn_attribute_char064 zona_nielsen
, flv19.meaning desc_zona_nielsen
, hops.extn_attribute_char065 regional_responsable
, flv20.meaning desc_regional_responsable
, hops.extn_attribute_char061 tipo_entrega
, flv21.meaning desc_tipo_entrega
, hops.extn_attribute_char066 segmentacion_categoria_externa
, flv22.meaning desc_segmentacion_categoria_externa
, hops.extn_attribute_char030 categoria_interna
, flv23.meaning desc_categoria_interna
, hopc.extn_attribute_number004 cuenta_bancaria
, hops.extn_attribute_char036 metodo_comercializacion
, flv24.meaning desc_metodo_comercializacion
, ' ' codigo_sucursal
, hops.extn_attribute_char007 identificador_edi
, hops.extn_attribute_char067 zona_precios
, flv25.meaning desc_zona_precios
, hops.extn_attribute_number007 guid_chep
, hops.extn_attribute_char023 inspeccion_calidad
, hops.extn_attribute_char012 numero_tienda_retek
, hops.extn_attribute_char068 perfil_cliente
, hops.extn_attribute_char069 tipo_pedido_cliente
, REPLACE(hosr3.origsystemreference,hosr2.origsystemreference) referencia_sucursal
-- account_site_references
, ' ' account_site_osr_id
, ' ' account_site_osr
-- party_site_uses
, ' ' party_site_use_id
, ' ' primario_por_tipo
-- party_site_uses_references
, ' ' party_site_use_osr_id
, ' ' party_site_use_osr
-- account_site_uses
, ' ' site_use_id
, ' ' sitio_cuenta_primario
, ' ' uso_sitio_cuenta
, hops.party_number sitio
-- account_site_uses_references
, ' ' account_site_use_osr_id
, ' ' account_site_use_osr
-- terminos de pago
, ' ' terminos_pago
, ' ' desc_terminos_pago
, flv27.tag cedis_asignado_as400
from cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_partyextractpvo_stg hp
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg hopo
on hp.partyid = hopo.party_id
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg hopc
on hopo.party_id = hopc.extn_attribute_char003
left join cat_master_oracle_fusion.sch_gold_layer.hz_organization_profiles_stg hops
on hopc.party_id = hops.extn_attribute_number001
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_locationextractpvo_stg hl
on hp.idenaddrlocationid = hl.locationid
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 hopc.party_id = hosr2.ownertableid
left join cat_master_oracle_fusion.sch_gold_layer.crm_crm_hz_originalsystemreferenceextractpvo_stg hosr3
on hops.party_id = hosr3.ownertableid
left join alp_fnd_lookup_values flv1
on hopc.extn_attribute_char054 = flv1.lookup_code
and flv1.lookup_type = 'ALP_REGIMENFISCAL'
left join alp_fnd_lookup_values flv2
on hopc.extn_attribute_char038 = flv2.lookup_code
and flv2.lookup_type = 'ALP_TIPOFISCAL'
left join alp_fnd_lookup_values flv3
on hopc.extn_attribute_char025 = flv3.lookup_code
and flv3.lookup_type = 'ALP_TIPOCREDITO'
left join alp_fnd_lookup_values flv4
on hopc.extn_attribute_char024 = flv4.lookup_code
and flv4.lookup_type = 'ALP_CANAL'
left join alp_fnd_lookup_values flv5
on hopc.extn_attribute_char039 = flv5.lookup_code
and flv5.lookup_type = 'ALP_GRUPOCOMERCIAL'
left join alp_fnd_lookup_values flv6
on hopc.extn_attribute_char046 = flv6.lookup_code
and flv6.lookup_type = 'ALP_UNIDADFACTURACION'
left join alp_fnd_lookup_values flv7
on hopc.extn_attribute_char060 = flv7.lookup_code
and flv7.lookup_type = 'ALP_FORMAPAGO'
left join alp_fnd_lookup_values flv8
on hopc.extn_attribute_char029 = flv8.lookup_code
and flv8.lookup_type = 'ALP_TIPOFACTURA'
left join alp_fnd_lookup_values flv9
on hopc.extn_attribute_char047 = flv9.lookup_code
and flv9.lookup_type = 'ALP_METODOPAGO'
left join alp_fnd_lookup_values flv10
on hopc.extn_attribute_char049 = flv10.lookup_code
and flv10.lookup_type = 'ALP_SUBCANAL'
left join alp_fnd_lookup_values flv11
on hopc.extn_attribute_char050 = flv11.lookup_code
and flv11.lookup_type = 'ALP_ZCOBRANZA'
left join alp_fnd_lookup_values flv12
on hopc.extn_attribute_char051 = flv12.lookup_code
and flv12.lookup_type = 'ALP_CONCENTRADOR'
left join alp_fnd_lookup_values flv13
on hopc.extn_attribute_char052 = flv13.lookup_code
and flv13.lookup_type = 'ALP_IBP'
left join alp_fnd_lookup_values flv14
on hopc.extn_attribute_char053 = flv14.lookup_code
and flv14.lookup_type = 'ALP_USOCFDI'
left join alp_fnd_lookup_values flv15
on hopc.extn_attribute_char048 = flv15.lookup_code
and flv15.lookup_type = 'ALP_MACROCANAL'
left join alp_fnd_lookup_values flv16
on hopc.extn_attribute_char056 = flv16.lookup_code
and flv16.lookup_type = 'ALP_GIRO'
left join alp_fnd_lookup_values flv17
on hops.extn_attribute_char063 = flv17.lookup_code
and flv17.lookup_type = 'ALP_PLAZADISTRIBUCION'
left join alp_fnd_lookup_values flv18
on hops.extn_attribute_char062 = flv18.lookup_code
and flv18.lookup_type = 'ALP_CEDIS'
left join alp_fnd_lookup_values flv19
on hops.extn_attribute_char064 = flv19.lookup_code
and flv19.lookup_type = 'ALP_ZNIELSEN'
left join alp_fnd_lookup_values flv20
on hops.extn_attribute_char065 = flv20.lookup_code
and flv20.lookup_type = 'ALP_REGIONALRESP'
left join alp_fnd_lookup_values flv21
on hops.extn_attribute_char061 = flv21.lookup_code
and flv21.lookup_type = 'ALP_TIPOENTREGA'
left join alp_fnd_lookup_values flv22
on hops.extn_attribute_char066 = flv22.lookup_code
and flv22.lookup_type = 'ALP_SEGMENTACION'
left join alp_fnd_lookup_values flv23
on hops.extn_attribute_char030 = flv23.lookup_code
and flv23.lookup_type = 'ALP_CLASINTERNA'
left join alp_fnd_lookup_values flv24
on hops.extn_attribute_char036 = flv24.lookup_code
and flv24.lookup_type = 'ALP_METODOCOMER'
left join alp_fnd_lookup_values flv25
on hops.extn_attribute_char067 = flv25.lookup_code
and flv25.lookup_type = 'ALP_ZONAPRECIOS'
left join alp_fnd_lookup_values flv26
on hopc.extn_attribute_char055 = flv26.lookup_code
and flv26.lookup_type = 'ALP_TIPOADENDA'
left join alp_fnd_lookup_values flv27
on hops.extn_attribute_char062 = flv27.lookup_code
and flv27.lookup_type = 'ALP_CEDIS_CDM_AS400'
where 1 = 1
and hopo.extn_attribute_char008 = 'ORGANIZACION'