USE [SAIB_Remttance] GO /****** Object: StoredProcedure [dbo].[Promotion_Details_Add] Script Date: 1/14/2025 12:30:44 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo].[Promotion_Details_Add] @PromoTypeID int=0, --@PromoName nvarchar(50)=null, @PromoTypeDesp nvarchar(50)=null, @PromotionValue nvarchar(250)=null, @MinAmt nvarchar(50)=null, @MaxAmt nvarchar(50)=null, @CustType nvarchar(50)=null, @StartDate nvarchar(50)=null, @EndDate nvarchar(50)=null, @ProSegment nvarchar(50)=null, @ProCountryID nvarchar(50)=null, @ProCurrency nvarchar(50)=null, @ProReceiveAgent nvarchar(50)=null, @ProCIF nvarchar(50)=null, @PromoCode nvarchar(20)=null, @ProPaymentMode nvarchar(20)=null, @ProPartnerCode nvarchar(50)=null, @IsActive bit=false, @CreatedBy nvarchar(20)=null, @CreatedOn datetime =null, @UpdatedBy nvarchar(20)=null, @UpdatedOn datetime=null, @Filter nvarchar(max) = null, @ProcedureType int =0, -- 0 for Select, 1 for update, 2 for Insert and 3 for Delete @ViewType int = 0 -- 0 for View, 1 for Process AS BEGIN DECLARE @msg nvarchar(MAX) DECLARE @PromotionID int DECLARE @CountryID nvarchar(50) DECLARE @RECEAGENT NVARCHAR(50) BEGIN TRY Declare @Script nvarchar(MAX) --VIEW IF @ProcedureType=0 BEGIN Select * from tbl_PromotionMasterDetails where PromotionID=30 END --UPDATE IF @ProcedureType=1 BEGIN Select * from tbl_PromotionMasterDetails END --INSERT IF @ProcedureType=2 BEGIN if @ProCountryID <>'NO' Begin if @ProCountryID<>'None' Begin -- set @ProCountryID='0' --End SET @CountryID=@ProCountryID set @ProCountryID=(select CountryShortName from tbl_04_08_Country_Details where CountryID=@CountryID) End END if @ProReceiveAgent <>'NO' Begin SET @RECEAGENT=@ProReceiveAgent if @ProReceiveAgent<>'None' begin if @ProReceiveAgent='All Receive Agent' begin set @ProReceiveAgent='-1' end Else Begin set @ProReceiveAgent=(select Agent_ID from tbl_agent_details where Agent_Name=@RECEAGENT) End End End if @ProPaymentMode <>'NO' Begin if @ProPaymentMode<>'None' Begin --set @ProPaymentMode='0' --End --set @ProCurrency=(select CurrencyShortName from tbl_04_13_Currency where currencyname=@ProCurrency) set @ProPaymentMode=(SELECT ModeOfPayment_Name FROM tbl_Mode_Of_Payment_Master where ModeOfPayment_ID=@ProPaymentMode) end End INSERT INTO tbl_PromotionMasterMain(Promotiondesp,PromotionType,PromotionValue,CREATEDDATE,EnteredBy) VALUES(@PromoTypeDesp,@PromoTypeID,@PromotionValue,Getdate(),@CreatedBy) set @PromotionID=(select MAX(PromotionID) from tbl_PromotionMasterMain) -- INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Value2,Value3,Value4,Value5,Active,EnteredBy,CREATEDDATE) --VALUES(@PromotionID,@PromoTypeID,@PromoName,@MinAmt,@MaxAmt,@CustType,@StartDate,@EndDate,@IsActive,@CreatedBy,Getdate(),@ProSegment,@ProCountryID,@ProCurrency,@ProReceiveAgent,@ProCIF,@PromoCode,@ProPaymentMode,@ProPartnerCode) if @MinAmt='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'16','Min Amount',NUll,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'16','Min Amount',@MinAmt,@IsActive,@CreatedBy,Getdate()) End if @MaxAmt='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'5','Max Amount',NUll,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'5','Max Amount',@MaxAmt,@IsActive,@CreatedBy,Getdate()) End -- if @CustType='NO' -- Begin --INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) --VALUES(@PromotionID,'7','CustType',NULL,0,@CreatedBy,Getdate()) -- End -- exec [Promotion_Details_Add]@PromoTypeID='0',@PromoTypeDesp='test',@PromotionValue='50',@MinAmt='10',@MaxAmt='20',@CustType='NO',@ProcedureType=2 IF @CustType = 'NO' BEGIN INSERT INTO tbl_PromotionMasterDetails( PromotionID, PromoTypeID, PromoTypeDesp, Value1, Active, EnteredBy, CREATEDDATE ) VALUES ( @PromotionID, '7', 'CustType', NULL, 0, @CreatedBy, GETDATE() ) END Else Begin --INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) --VALUES(@PromotionID,'7','CustType',@CustType,@IsActive,@CreatedBy,Getdate()) IF @CustType <> 'NO' BEGIN INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'7','CustType', case @CustType when 'EasyPay' then '1' when 'SAIB' then '2' when 'SAIB Staff' then '3' when 'Virgin Mobile' then '4' End ,@IsActive,@CreatedBy,Getdate()) End End INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Value2,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'6','Promotion Date',@StartDate,@EndDate,@IsActive,@CreatedBy,Getdate()) if @ProSegment='0' or @ProSegment='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'8','Segment',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'8','Segment',@ProSegment,@IsActive,@CreatedBy,Getdate()) End if @ProCountryID='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'9','Country',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'9','Country',@ProCountryID,@IsActive,@CreatedBy,Getdate()) End if @ProCurrency='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'10','Currency',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'10','Currency',@ProCurrency,@IsActive,@CreatedBy,Getdate()) End if @ProReceiveAgent='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'11','ReceiveAgent',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'11','ReceiveAgent',@ProReceiveAgent,@IsActive,@CreatedBy,Getdate()) End if @ProCIF='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'12','CIF',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'12','CIF',@ProCIF,@IsActive,@CreatedBy,Getdate()) End if @PromoCode='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'13','PromoCode',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'13','PromoCode',@PromoCode,@IsActive,@CreatedBy,Getdate()) End if @ProPaymentMode='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'14','PaymentMode',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'14','PaymentMode',@ProPaymentMode,@IsActive,@CreatedBy,Getdate()) End if @ProPartnerCode='NO' Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'15','PartnerCode',NULL,0,@CreatedBy,Getdate()) End Else Begin INSERT INTO tbl_PromotionMasterDetails(PromotionID,PromoTypeID,PromoTypeDesp,Value1,Active,EnteredBy,CREATEDDATE) VALUES(@PromotionID,'15','PartnerCode',@ProPartnerCode,@IsActive,@CreatedBy,Getdate()) End END --DELETE --IF @ProcedureType=3 --BEGIN -- Select * from tbl_PromotionMasterDetails --END END TRY BEGIN CATCH SET @msg = error_message() RAISERROR(@msg,16,1) END CATCH END