0% found this document useful (0 votes)
27 views3 pages

Proc Api Balance Account

This stored procedure retrieves the points balance for a given account and card issuer. It checks the account type, retrieves the associated program details, and then queries the credit_cards or debit_cards table to return the points name, balance in points and currency, and other details. If any errors are encountered, such as an invalid account type or inactive program, appropriate error messages are returned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views3 pages

Proc Api Balance Account

This stored procedure retrieves the points balance for a given account and card issuer. It checks the account type, retrieves the associated program details, and then queries the credit_cards or debit_cards table to return the points name, balance in points and currency, and other details. If any errors are encountered, such as an invalid account type or inactive program, appropriate error messages are returned.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

USE [bc_clop]

GO
/****** Object: StoredProcedure [dbo].[proc_api_balance_account] Script Date:
10/11/2023 8:38:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description:SP QUE RETORNA SALDO DE PUNTOS POR TARJETA DE UNA CUENTA----
-- =============================================
ALTER PROCEDURE [dbo].[proc_api_balance_account]

@account_id BIGINT
,@account_type VARCHAR(1)
,@card_issuer_id BIGINT

AS
BEGIN
SET NOCOUNT ON;

DECLARE @program_id AS BIGINT


DECLARE @currency_code INT
DECLARE @points_name VARCHAR(50)
DECLARE @point_exchange_ratio AS DECIMAL(10,3)
DECLARE @currency_exchange_ratio INT
DECLARE @amount BIGINT

SET @currency_code = 600

-- IDENTIFICAR TIPO DE TARJETA SI ES DE CREDITO O DEBITO Y SI ES TITULAR O


ADICIONAL
IF @account_type ='C'
BEGIN
-- OBTENER DATOS DEL PROGRAMA
SELECT @program_id = program_id FROM accounts WHERE id = @account_id
and card_issuer_id = @card_issuer_id
IF @program_id IS NULL
BEGIN
SELECT '403' AS ERROR,'Program not found' as MESSAGE
END
ELSE
BEGIN
IF EXISTS (SELECT TOP 1 1 FROM programs WHERE id = @program_id
and program_state_id = 3)
BEGIN
SELECT
@points_name = point_name
,@point_exchange_ratio = point_exchange_ratio
,@currency_exchange_ratio = currency_exchange_ratio
FROM programs
WHERE
id = @program_id
and program_state_id = 3
SELECT
200 AS ERROR
,'OK' AS MESSAGE
,is_primary
,masked_pan
,@points_name AS points_name
,ISNULL(new_balance,0) AS points_balance
,CEILING(cast((new_balance /
@point_exchange_ratio) as decimal(20,2)) * @currency_exchange_ratio)AS amount
,@currency_code AS currency_code
FROM
credit_cards
WHERE
account_id = @account_id AND active= 1
END
ELSE
BEGIN
SELECT '403' AS ERROR,'Program not current' as MESSAGE
END

END

END
ELSE IF @account_type ='D'
BEGIN
SELECT @program_id = program_id FROM debit_accounts WHERE id =
@account_id and card_issuer_id = @card_issuer_id
IF @program_id IS NULL
BEGIN
SELECT '403' AS ERROR,'Program not found' as MESSAGE
END
ELSE
BEGIN
IF EXISTS (SELECT TOP 1 1 FROM programs WHERE id = @program_id
and program_state_id = 3)
BEGIN
SELECT
@points_name = point_name
,@point_exchange_ratio = point_exchange_ratio
,@currency_exchange_ratio = currency_exchange_ratio
FROM programs
WHERE
id = @program_id and program_state_id = 3

SELECT
200 AS ERROR
,'OK' AS MESSAGE
,master AS is_primary
,masked_pan
,@points_name AS points_name
,ISNULL(new_balance,0) AS points_balance
,iSNULL(CEILING(cast((new_balance /
@point_exchange_ratio) as decimal(20,2)) * @currency_exchange_ratio),0)AS amount
,@currency_code AS currency_code
FROM
debit_cards
WHERE
debit_account_id = @account_id AND
active= 1
END
ELSE
BEGIN
SELECT '403' AS ERROR,'Program not current' as MESSAGE
END
END

END
ELSE
BEGIN
SELECT '403' AS ERROR,'Invalid Card Type' as MESSAGE
END
END

You might also like