Lista de Precios Calculados (alp_lista_precios)
1. Descripción
La función alp_lista_sppd_precios calcula el precio neto vigente de un artículo para uno o varios clientes dentro de un canal de ventas específico en PostgreSQL. Integra de forma nativa las listas maestras de precios y estrategias comerciales de Oracle Fusion Pricing con los folios de acuerdos de Precios Especiales SPPD (alp_sppd_folio_rework).
A diferencia de versiones anteriores basadas en cursor imperativo (FOR ... LOOP), la arquitectura actual procesa el cálculo en un único pase relacional basado en CTEs (Common Table Expressions). Esto optimiza drásticamente el tiempo de ejecución y la escalabilidad cuando se consulta el universo completo de clientes del canal.
La lógica evalúa cuatro niveles para determinar el precio final:
- Precio por Perfil de Cliente (
alp_perfil): Se busca coincidencia directa entre la cuenta del cliente y elcustomer_ratingasociado a su estrategia de precios. - Precio Comercial por Canal y Subcanal (
alp_canal_subcanal): Si el cliente no tiene un perfil específico, se asigna la lista comercial ligada a su combinación exacta de canal y subcanal. - Precio Comercial por Subcanal (
alp_subcanal): Si no hay regla de canal + subcanal, se busca la regla residual asignada únicamente al subcanal de venta.
Sobre el precio base obtenido de Oracle Pricing, se sobreponen los folios aprobados de SPPD:
El resultado clasifica además el tipo de precio aplicado en Precio Especial o Precio Normal, filtrando por defecto sobre la unidad de medida pieza (PZ).
2. Parámetros
| Parámetro | Tipo | Obligatorio | Valor por Defecto | Descripción |
|---|---|---|---|---|
p_canal | TEXT | Sí | N/A | Canal de ventas a consultar (ej. 'AUTOSERVICIO', 'DETALLE'). Filtra clientes y acuerdos SPPD. |
p_clientes | TEXT[] | No | '{TODOS}' | Arreglo de números de cuenta de clientes. Soporta además banderas especiales:
|
p_producto | TEXT | No | NULL | Código Oracle del artículo (item_code). Filtra la lista de precios y los folios SPPD. |
p_fecha | TEXT | No | NULL | Fecha de referencia para validar la vigencia de listas, perfiles y folios SPPD (formato 'YYYY-MM-DD'). |
3. Retorno
La función retorna una tabla con las siguientes columnas:
| Campo | Tipo | Descripción |
|---|---|---|
no_cliente | INTEGER | Número de cuenta o identificador del cliente evaluado. |
item_code | TEXT | Código identificador Oracle del artículo. |
item_code_as400 | TEXT | Código homologado del artículo en AS400. |
description | TEXT | Descripción comercial del artículo. |
price_type | TEXT | Origen del precio aplicado: 'Precio Especial' o 'Precio Normal'. |
udm | TEXT | Unidad de medida del precio (evaluado en 'PZ'). |
precio | NUMERIC | Precio final resultante tras la evaluación de precedencia. |
4. Flujo funcional
La función ejecuta el siguiente proceso:
5. Lógica de negocio
5.1. Extracción Unificada de Precios Oracle (alp_qp_precios)
Se filtran y preparan todos los artículos correspondientes a p_producto en unidad de medida 'PZ', asegurando que:
- La lista tenga tipo
'Price List'y estatus'Aprobada'. - La fecha de evaluación
p_fechacaiga dentro del rango de vigencia de la lista (detail_start_date/detail_end_date) y de la estrategia (strategy_start_date/strategy_end_date). - Se enlaza la asignación de estrategia (
alp_cat_qp_pricing_assignments_strategy) y opcionalmente el perfil del cliente (alp_cat_qp_pricing_profiles) medianteLEFT JOIN.
5.2. Filtrado de Universo de Clientes (alp_clientes)
Filtra sobre alp_cat_ar_clientes con base en el canal p_canal:
- Si
p_clientescontiene'TODOS'o'LIST_PRICE', se incluyen todos los clientes del canal agrupados por cuenta, canal y subcanal. - Si se proporcionan cuentas específicas, se evalúa
numero_cuenta_cliente::text = ANY(p_clientes::text[]).
5.3. Cascada de Precios Base (Perfil -> Canal/Subcanal -> Subcanal)
Para evitar duplicidades y garantizar la prioridad de listas:
alp_perfil: Clientes con precio derivado de su cuenta y perfil individual.alp_canal_subcanal: Clientes que no tuvieron precio enalp_perfil, asignándoles la lista por canal + subcanal.alp_subcanal: Clientes residuales que no existieron ni enalp_perfilni enalp_canal_subcanal, asignándoles la lista por subcanal.
5.4. Acuerdos Especiales SPPD (alp_sppd)
Se desanidan mediante CROSS JOIN LATERAL los clientes de la estructura JSON de alp_sppd_folio_rework:
- Filtra folios aprobados (
id_estatus_folio IN (1, 6)), no cancelados (is_cancelation = false), vigentes ap_fechay correspondientes al productop_producto. - Mediante
ROW_NUMBER() OVER (PARTITION BY product_code ORDER BY id DESC)se asegura el folio más reciente (reg = 1).
5.5. Prioridad y Regla de Bandera 'LIST_PRICE'
- Si en
p_clientesse especifica'LIST_PRICE', el sistema omite intencionalmente cualquier precio promocional de SPPD y reporta el precio estándar de lista como'Precio Normal'. - Si no está presente dicha bandera, se prioriza el acuerdo de SPPD general (
TODOS), luego el de cliente particular, y finalmente el precio base de lista.
6. Catálogos y Tablas Utilizadas
| Catálogo / Tabla | Esquema | Propósito Operativo |
|---|---|---|
alp_cat_ar_clientes | general_catalogs | Catálogo maestro de clientes, identificando número de cuenta, canal y subcanal de venta. |
alp_cat_qp_price_lists | general_catalogs | Detalle de precios vigentes por lista, artículo y unidad de medida. |
alp_cat_qp_pricing_oracle | general_catalogs | Cabecera y estatus de listas de precios y descuentos de Oracle Pricing. |
alp_cat_qp_pricing_assignments_strategy | general_catalogs | Matriz de asignación de estrategias de precios por segmento, canal y subcanal. |
alp_cat_qp_pricing_profiles | general_catalogs | Perfiles y ratings individuales asignados a las cuentas de clientes. |
alp_sppd_folio_rework | sppd | Folios y acuerdos comerciales de Precios Especiales SPPD. |
7. Consideraciones Técnicas
- Eliminación de Bucles: La función ejecuta un único plan de ejecución declarativo en PostgreSQL (
RETURN QUERY WITH ...), eliminando variables escalares intermedias, bloques condicionalesFOR ... LOOPy sentenciasRAISE NOTICE. - Filtro Estricto de Producto y UDM: Para optimizar los índices de las tablas de listas de precios, la función requiere
p_productoy restringe la evaluación a piezas (udm = 'PZ'). - Manejo de Nulos en Fechas: Las fechas de fin de vigencia en las listas de precios y estrategias que sean nulas se interpretan como abiertas mediante
COALESCE(fecha_fin, p_fecha::timestamp).
8. SQL
- Código Función V.1.0.0.0
- Código Actual
- Ejecución en BD
- Info a Mostrar
CREATE OR REPLACE FUNCTION general_catalogs.alp_lista_sppd_precios(
p_canal text,
p_clientes text[] DEFAULT '{TODOS}'::text[],
p_producto text DEFAULT NULL::text,
p_fecha text DEFAULT NULL::text
)
RETURNS TABLE(
no_cliente integer,
item_code text,
item_code_as400 text,
description text,
price_type text,
udm text,
precio numeric
)
LANGUAGE plpgsql
AS \$function\$
declare
v_cliente int;
v_perfil text;
v_perfil_segment text;
v_perfil_strategy text;
v_pricing_segment text;
v_pricing_strategy text;
v_perfil_lista_precio text;
v_perfil_lista_descuento text;
v_pricing_lista_precio text;
v_pricing_lista_descuento text;
v_clientes jsonb[];
c RECORD;
begin
if exists ( select 1
from unnest(p_clientes) x(cliente)
where UPPER(x.cliente) = 'TODOS') then
select array_agg(distinct jsonb_build_object('cliente', numero_cuenta_cliente::int,'subcanal', desc_subcanal))
into v_clientes
from alp_cat_ar_clientes
where desc_canal_tipo_cuenta = p_canal;
else
select array_agg(distinct jsonb_build_object('cliente', numero_cuenta_cliente::int,'subcanal', desc_subcanal))
into v_clientes
from alp_cat_ar_clientes
where desc_canal_tipo_cuenta = p_canal
and (identificador_registro::int = any(array( select cliente::int
from unnest(p_clientes) as x(cliente)))
or numero_cuenta_cliente::int = any(array( select cliente::int
from unnest(p_clientes) as x(cliente))));
end if;
RAISE NOTICE 'Clientes %', v_clientes;
for c in
select *
from jsonb_to_recordset(to_jsonb(v_clientes)) as x(cliente int,subcanal text)
loop
v_perfil := null;
v_perfil_segment := null;
v_perfil_strategy := null;
v_perfil_lista_precio := null;
v_perfil_lista_descuento := null;
v_pricing_segment := null;
v_pricing_strategy := null;
v_pricing_lista_precio := null;
v_pricing_lista_descuento := null;
begin
select p.customer_rating
into v_perfil
from alp_cat_qp_pricing_profiles p
where p_fecha::timestamp between coalesce(p.start_date::timestamp,p_fecha::timestamp)
and coalesce(p.end_date::timestamp,p_fecha::timestamp)
and p.account_number::int = c.cliente;
exception
when others then
v_perfil := null;
end;
if v_perfil is not null then
begin
select ps.pricing_segment
into v_perfil_segment
from omnicanal.general_catalogs.alp_cat_qp_pricing_segments ps
where ps.customer_rating = v_perfil
and p_fecha::timestamp between coalesce(ps.start_date::timestamp,p_fecha::timestamp)
and coalesce(ps.end_date::timestamp,p_fecha::timestamp);
exception
when others then
v_perfil_segment := null;
end;
if v_perfil_segment is not null then
begin
select pst.pricing_strategy
into v_perfil_strategy
from omnicanal.general_catalogs.alp_cat_qp_pricing_assignments_strategy pst
where pst.pricing_segment = v_perfil_segment;
exception
when others then
v_perfil_strategy := null;
end;
if v_perfil_strategy is not null then
begin
select pl.detail_entity
into v_perfil_lista_precio
from general_catalogs.alp_cat_qp_pricing_oracle pl
where pl.detail_entity_type = 'Price List'
and pl.status = 'Aprobada'
and pl.detail_status = 'Aprobada'
and pl.pricing_strategy = v_perfil_strategy
and p_fecha::timestamp between coalesce(pl.detail_start_date::timestamp,p_fecha::timestamp)
and coalesce(pl.detail_end_date::timestamp,p_fecha::timestamp)
and p_fecha::timestamp between coalesce(pl.strategy_start_date::timestamp,p_fecha::timestamp)
and coalesce(pl.strategy_end_date::timestamp,p_fecha::timestamp);
exception
when others then
v_perfil_lista_precio := null;
end;
begin
select detail_entity
into v_perfil_lista_descuento
from ( select prd.detail_entity
, row_number()
over ( partition by prd.pricing_strategy
order by prd.detail_start_date) reg
from general_catalogs.alp_cat_qp_pricing_oracle prd
where prd.detail_entity_type = 'Discount List'
and prd.status = 'Aprobada'
and prd.detail_status = 'Aprobada'
and prd.pricing_strategy = v_perfil_strategy
and p_fecha::timestamp between coalesce(prd.detail_start_date::timestamp,p_fecha::timestamp)
and coalesce(prd.detail_end_date::timestamp,p_fecha::timestamp)
and p_fecha::timestamp between coalesce(prd.strategy_start_date::timestamp,p_fecha::timestamp)
and coalesce(prd.strategy_end_date::timestamp,p_fecha::timestamp))
where reg = 1;
exception
when others then
v_perfil_lista_descuento := null;
end;
end if;
end if;
end if;
begin
select pas1.pricing_segment
, pas1.pricing_strategy
into v_pricing_segment
, v_pricing_strategy
from omnicanal.general_catalogs.alp_cat_qp_pricing_assignments_strategy pas1
where pas1.canal_ventas = p_canal
and pas1.subcanal_ventas = c.subcanal;
exception
when others then
begin
select pas2.pricing_segment
, pas2.pricing_strategy
into v_pricing_segment
, v_pricing_strategy
from omnicanal.general_catalogs.alp_cat_qp_pricing_assignments_strategy pas2
where pas2.canal_ventas = p_canal;
exception
when others then
begin
select pas3.pricing_segment
, pas3.pricing_strategy
into v_pricing_segment
, v_pricing_strategy
from omnicanal.general_catalogs.alp_cat_qp_pricing_assignments_strategy pas3
where pas3.subcanal_ventas = c.subcanal;
exception
when others then
v_pricing_segment := null;
v_pricing_strategy := null;
end;
end;
end;
if v_pricing_strategy is not null then
begin
select pl.detail_entity
into v_pricing_lista_precio
from general_catalogs.alp_cat_qp_pricing_oracle pl
where pl.detail_entity_type = 'Price List'
and pl.status = 'Aprobada'
and pl.detail_status = 'Aprobada'
and pl.pricing_strategy = v_pricing_strategy
and p_fecha::timestamp between coalesce(pl.detail_start_date::timestamp,p_fecha::timestamp)
and coalesce(pl.detail_end_date::timestamp,p_fecha::timestamp)
and p_fecha::timestamp between coalesce(pl.strategy_start_date::timestamp,p_fecha::timestamp)
and coalesce(pl.strategy_end_date::timestamp,p_fecha::timestamp);
exception
when others then
v_pricing_lista_precio := null;
end;
begin
select detail_entity
into v_pricing_lista_descuento
from ( select prd.detail_entity
, row_number()
over ( partition by prd.pricing_strategy
order by prd.detail_start_date) reg
from general_catalogs.alp_cat_qp_pricing_oracle prd
where prd.detail_entity_type = 'Discount List'
and prd.status = 'Aprobada'
and prd.detail_status = 'Aprobada'
and prd.pricing_strategy = v_pricing_strategy
and p_fecha::timestamp between coalesce(prd.detail_start_date::timestamp,p_fecha::timestamp)
and coalesce(prd.detail_end_date::timestamp,p_fecha::timestamp)
and p_fecha::timestamp between coalesce(prd.strategy_start_date::timestamp,p_fecha::timestamp)
and coalesce(prd.strategy_end_date::timestamp,p_fecha::timestamp))
where reg = 1;
exception
when others then
v_pricing_lista_descuento := null;
end;
end if;
raise notice 'Cliente: %', c.cliente;
raise notice 'Subcanal: %', c.subcanal;
raise notice 'Perfil: %', v_perfil;
raise notice 'Perfil Segmento: %', v_perfil_segment;
raise notice 'Perfil Estrategia: %', v_perfil_strategy;
raise notice 'Perfil Lista de Precio: %', v_perfil_lista_precio;
raise notice 'Perfil Lista Descuento: %', v_perfil_lista_descuento;
raise notice 'Pricing Segment %', v_pricing_segment;
raise notice 'Pricing Strategy %', v_pricing_strategy;
raise notice 'Pricing Lista Precio %', v_pricing_lista_precio;
raise notice 'Pricing Lista Descuentos %', v_pricing_lista_descuento;
return query
with alp_lista1 as
( select l1.item_code
, l1.item_code_as400
, l1.description
, l1.udm
, l1.precio::numeric precio
from general_catalogs.alp_cat_qp_price_lists l1
where l1.lista_precios = v_pricing_lista_precio
and p_fecha::timestamp between l1.fecha_inicio::timestamp
and COALESCE(l1.fecha_fin::date,p_fecha::timestamp))
, alp_lista2 as
( select l2.item_code
, l2.item_code_as400
, l2.description
, l2.udm
, l2.precio::numeric precio
from general_catalogs.alp_cat_qp_price_lists l2
where l2.lista_precios = v_perfil_lista_precio
and p_fecha::timestamp between l2.fecha_inicio::timestamp
and COALESCE(l2.fecha_fin::date,p_fecha::timestamp))
, alp_sppd as
( select r.id
, client.customer ->> 'clientNumber' client_number
, split_part(client.customer ->> 'channel',' - ',1) channel_code
, split_part(client.customer ->> 'channel', ' - ',2) channel
, client.customer #>> '{products,0,keyProducts}' product_code
, (client.customer #>> '{products,0,specialPrice}')::numeric special_price
from sppd.alp_sppd_folio_rework r
cross join lateral jsonb_array_elements(r.customers) client(customer)
where r.id_estatus_folio in (1,6)
and coalesce(is_cancelation,false) = false
and p_fecha::timestamp between to_date(r.inicio_vigencia,'DD-MM-YYYY')
and to_date(r.fin_vigencia,'DD-MM-YYYY'))
, alp_sppd_sp_todos as
( select row_number()
over ( partition by product_code
order by id desc) reg
, product_code
, special_price
from alp_sppd
where client_number = 'TODOS'
and channel = p_canal
and product_code = p_producto)
, alp_sppd_sp_client as
( select row_number()
over ( partition by product_code
order by id desc) reg
, product_code
, special_price
from alp_sppd
where channel = p_canal
and client_number = c.cliente::varchar
and product_code = p_producto)
select c.cliente no_cliente
, al1.item_code
, al1.item_code_as400
, al1.description
, case
when assc.special_price is not null then 'Precio Especial'
when asst.special_price is not null then 'Precio Especial'
else 'Precio Normal'
end price_type
, al1.udm
, coalesce(al2.precio,assc.special_price,asst.special_price,al1.precio) precio
from alp_lista1 al1
left join alp_lista2 al2
on al1.item_code = al2.item_code
and al1.udm = al2.udm
left join alp_sppd_sp_client assc
on al1.item_code = assc.product_code
and assc.reg = 1
left join alp_sppd_sp_todos asst
on al1.item_code = asst.product_code
and asst.reg = 1
where al1.item_code = p_producto
and al1.udm = 'PZ'
order by al1.item_code
, al1.udm;
end loop;
end;
\$function\$;
CREATE OR REPLACE FUNCTION general_catalogs.alp_lista_sppd_precios(p_canal text, p_clientes text[] DEFAULT '{TODOS}'::text[], p_producto text DEFAULT NULL::text, p_fecha text DEFAULT NULL::text)
RETURNS TABLE(no_cliente integer, item_code text, item_code_as400 text, description text, price_type text, udm text, precio numeric)
LANGUAGE plpgsql
AS $function$
begin
return query
WITH alp_qp_precios AS
(
SELECT
acqpl.lista_precios
, acqpl.item_code
, acqpl.item_code_as400
, acqpl.description
, acqpl.precio::numeric AS precio
, acqpl.udm
, acqpl.fecha_inicio
, acqpl.fecha_fin
, acqpo.pricing_strategy
, acqpas.canal_ventas
, acqpas.subcanal_ventas
, acqpas.pricing_segment
, acqpp.account_number
FROM general_catalogs.alp_cat_qp_price_lists acqpl
JOIN general_catalogs.alp_cat_qp_pricing_oracle acqpo
ON acqpl.lista_precios = acqpo.detail_entity
AND acqpo.detail_entity_type = 'Price List'
AND acqpo.status = 'Aprobada'
AND acqpo.detail_status = 'Aprobada'
AND p_fecha::timestamp BETWEEN
COALESCE(
acqpo.detail_start_date::timestamp,
p_fecha::timestamp
)
AND
COALESCE(
acqpo.detail_end_date::timestamp,
p_fecha::timestamp
)
AND p_fecha::timestamp BETWEEN
COALESCE(
acqpo.strategy_start_date::timestamp,
p_fecha::timestamp
)
AND
COALESCE(
acqpo.strategy_end_date::timestamp,
p_fecha::timestamp
)
JOIN general_catalogs.alp_cat_qp_pricing_assignments_strategy acqpas
ON acqpo.pricing_strategy = acqpas.pricing_strategy
LEFT JOIN general_catalogs.alp_cat_qp_pricing_profiles acqpp
ON acqpas.pricing_segment = acqpp.customer_rating
WHERE acqpl.item_code = p_producto
AND acqpl.udm = 'PZ'
AND p_fecha::timestamp BETWEEN
acqpl.fecha_inicio::timestamp
AND COALESCE(
acqpl.fecha_fin::date,
p_fecha::timestamp
)
ORDER BY
acqpl.lista_precios
, acqpl.item_code
),
alp_clientes AS
(
SELECT
numero_cuenta_cliente AS no_cliente
, desc_canal_tipo_cuenta AS canal
, desc_subcanal AS subcanal
FROM general_catalogs.mv_cat_oracle_clientes
WHERE desc_canal_tipo_cuenta = p_canal
AND (
'TODOS' = ANY(p_clientes::text[])
OR 'LIST_PRICE' = ANY(p_clientes::text[])
OR numero_cuenta_cliente::text = ANY(p_clientes::text[])
)
GROUP BY
numero_cuenta_cliente
, desc_canal_tipo_cuenta
, desc_subcanal
),
alp_perfil AS
(
SELECT
ac.no_cliente
, aqp.item_code
, aqp.item_code_as400
, aqp.description
, aqp.udm
, aqp.precio
FROM alp_qp_precios aqp
JOIN alp_clientes ac
ON aqp.account_number = ac.no_cliente
),
alp_canal_subcanal AS
(
SELECT
ac.no_cliente
, aqp.item_code
, aqp.item_code_as400
, aqp.description
, aqp.udm
, aqp.precio
FROM alp_qp_precios aqp
JOIN alp_clientes ac
ON aqp.canal_ventas = ac.canal
AND aqp.subcanal_ventas = ac.subcanal
WHERE ac.no_cliente NOT IN
(
SELECT p.no_cliente
FROM alp_perfil p
)
),
alp_subcanal AS
(
SELECT
ac.no_cliente
, aqp.item_code
, aqp.item_code_as400
, aqp.description
, aqp.udm
, aqp.precio
FROM alp_qp_precios aqp
JOIN alp_clientes ac
ON aqp.subcanal_ventas = ac.subcanal
WHERE ac.no_cliente NOT IN
(
SELECT p.no_cliente
FROM alp_perfil p
)
AND ac.no_cliente NOT IN
(
SELECT cs.no_cliente
FROM alp_canal_subcanal cs
)
),
alp_sppd AS
(
SELECT
row_number() OVER
(
PARTITION BY
client.customer #>> '{products,0,keyProducts}'
ORDER BY r.id DESC
) AS reg
, r.id
, client.customer ->> 'clientNumber'
AS client_number
, split_part(
client.customer ->> 'channel',
' - ',
1
) AS channel_code
, split_part(
client.customer ->> 'channel',
' - ',
2
) AS channel
, client.customer #>> '{products,0,keyProducts}'
AS product_code
, (
client.customer #>> '{products,0,specialPrice}'
)::numeric AS special_price
FROM sppd.alp_sppd_folio_rework r
CROSS JOIN LATERAL
jsonb_array_elements(r.customers) client(customer)
WHERE r.id_estatus_folio IN (1,6)
AND COALESCE(
is_cancelation,
false
) = false
AND client.customer #>> '{products,0,keyProducts}' = p_producto
AND p_fecha::timestamp BETWEEN
to_date(
r.inicio_vigencia,
'DD-MM-YYYY'
)
AND
to_date(
r.fin_vigencia,
'DD-MM-YYYY'
)
)
SELECT
p.no_cliente::integer AS no_cliente
, p.item_code
, p.item_code_as400
, p.description
, CASE
WHEN 'LIST_PRICE' = ANY(p_clientes::text[])
THEN 'Precio Normal'
WHEN todos.special_price IS NOT NULL
THEN 'Precio Especial'
WHEN sppd.special_price IS NOT NULL
THEN 'Precio Especial'
ELSE 'Precio Normal'
END AS price_type
, p.udm
, CASE
WHEN 'LIST_PRICE' = ANY(p_clientes::text[])
THEN p.precio::numeric
ELSE COALESCE(
todos.special_price::numeric,
sppd.special_price::numeric,
p.precio::numeric
)
END::numeric AS precio
FROM
(
SELECT
p.no_cliente
, p.item_code
, p.item_code_as400
, p.description
, p.udm
, p.precio
FROM alp_perfil p
UNION ALL
SELECT
cs.no_cliente
, cs.item_code
, cs.item_code_as400
, cs.description
, cs.udm
, cs.precio
FROM alp_canal_subcanal cs
UNION ALL
SELECT
asu.no_cliente
, asu.item_code
, asu.item_code_as400
, asu.description
, asu.udm
, asu.precio
FROM alp_subcanal asu
) p
LEFT JOIN alp_sppd sppd
ON p.no_cliente = sppd.client_number
AND sppd.reg = 1
LEFT JOIN alp_sppd todos
ON todos.client_number = 'TODOS'
AND todos.reg = 1
ORDER BY p.no_cliente;
end;
$function$
;
Ejemplo 1: Consulta para clientes específicos
SELECT *
FROM alp_lista_sppd_precios(
'AUTOSERVICIO',
ARRAY['100245', '100246'],
'10000001',
'2026-07-21'
);
Ejemplo 2: Consulta para TODOS los clientes del canal considerando el Precio Special de SPPD
SELECT *
FROM alp_lista_sppd_precios(
'AUTOSERVICIO',
'{TODOS}',
'10000001',
'2026-07-21'
);
Ejemplo 3: Consulta para TODOS los clientes del canal con Precio Normal
SELECT *
FROM alp_lista_sppd_precios(
'AUTOSERVICIO',
'{LIST_PRICE}',
'10000001',
'2026-07-21'
);
| no_cliente | item_code | item_code_as400 | description | price_type | udm | precio |
|---|---|---|---|---|---|---|
| 100245 | 10000001 | 000123 | Leche Entera 1L | Precio Especial | PZ | 24.50 |
| 100246 | 10000001 | 000123 | Leche Entera 1L | Precio Normal | PZ | 28.50 |