

DECLARE
@idplandasar Varchar(4) ='0159', 
@idplan Varchar(4) = '1103', 
@idvalas Varchar(3) = 'IDR', 
@sexttg Varchar(1) = '', 
@sexppm Varchar(1) = '', 
@pi_thn_ke INT = 2, --1
@usiattg INT = 22,  --21
@usiappm INT = 22, 
--@updasar FLOAT = 1000, 
--@premidasar Float, 
--@mp int, 
@up FLOAT = 1000, 
--@tglprod datetime, 
@tglmulai DATETIME = '1988-01-01',

@idprbayar Varchar(1) = '1', 
@premiberkala FLOAT = 500, 
@topupberkala FLOAT = 500,
@mk INT = 12  --13

SET @usiattg = @usiattg + @pi_thn_ke
SET @usiappm = @usiappm + @pi_thn_ke

--SET @up = IndInsurance.dbo.func_get_uang_pertanggungan(@idplan, @idprbayar, @mk, @premiberkala, @topupberkala, @up, @pi_thn_ke)

   DECLARE @vhasilpremi Float
   DECLARE @vnilaifaktor Float
   DECLARE @vnilaipremi VARCHAR(7)
   DECLARE @umurppm int
   DECLARE @premi Float

   IF @tglmulai < '1997-01-01'
   BEGIN
      IF @usiappm < 20 SET @umurppm = 20
      ELSE SET @umurppm = @usiappm
   END
   ELSE IF @tglmulai BETWEEN '1997-01-01' AND '2009-05-14'
   BEGIN
      IF @sexppm = 'P' 
      BEGIN
         IF @usiappm < 24 SET @umurppm = 20
         ELSE SET @umurppm = @usiappm - 3
      END 
      ELSE SET @umurppm = @usiappm
   END 
   ELSE IF @tglmulai >= '2009-05-15' 
   BEGIN IF @usiappm < 20 SET @umurppm = 20
   ELSE SET @umurppm = @usiappm
   END
    
   IF @idvalas = 'IDR' SET @vnilaifaktor = 0.1
   ELSE SET @vnilaifaktor = 0.092

   IF @idplan = '1103'
   BEGIN
      IF @idplandasar in ('0159','0208')
      BEGIN
         IF @idvalas = 'IDR'
            SELECT @vnilaipremi = nilai FROM gfpbr0159r40 WHERE umur = @umurppm 
         ELSE
            SELECT @vnilaipremi = nilai FROM gfpbr0159d40 WHERE umur = @umurppm 
         
         SET @vhasilpremi = CAST(@vnilaipremi AS Float)
         SET @premi = @vhasilpremi*@up/100000*@vnilaifaktor
      END 
   END 

SELECT 
  @vhasilpremi,
  @up,
  @vnilaifaktor,
  @premi,
  @premi * @mk



SELECT * 
FROM gfpbr0159r40
WHERE umur = @umurppm











