Friday, June 14, 2019
Tax Calculation and Round To Cent (for active record and tax >= 2.5)
SELECT COUNT(*) AS bil_akaun_dicukaikan,
SUM(E1.cukai_penggal_sebenar) AS anggaran_cukai
FROM
(SELECT D1.no_akaun,
D1.kod_stsakaun,
D1.nilai_thnn,
D1.cukai_sms,
D1.cukai_sms_sen,
D1.len_cukai_sms_sen,
D1.nilai_sen,
to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) AS cukai_b4,
CASE
WHEN D1.nilai_sen = 1
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) - 0.01
WHEN D1.nilai_sen = 2
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) - 0.02
WHEN D1.nilai_sen = 3
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) + 0.02
WHEN D1.nilai_sen = 4
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) + 0.01
WHEN D1.nilai_sen = 5
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen ))
WHEN D1.nilai_sen = 6
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) - 0.01
WHEN D1.nilai_sen = 7
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) - 0.02
WHEN D1.nilai_sen = 8
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) + 0.02
WHEN D1.nilai_sen = 9
THEN to_number(SUBSTR (cukai_sms,1, D1.len_cukai_sms_sen )) + 0.01
ELSE D1.cukai_sms
END AS cukai_penggal_sebenar
FROM
(SELECT C1.no_akaun,
C1.kod_stsakaun,
C1.nilai_thnn,
C1.cukai_sms,
C1.cukai_sms_sen,
LENGTH(trim(C1.cukai_sms_sen)) AS len_cukai_sms_sen,
SUBSTR(C1.cukai_sms, LENGTH(trim(C1.cukai_sms_sen)),1) AS nilai_sen
FROM
(SELECT B1.no_akaun,
B1.kod_stsakaun,
B1.nilai_thnn,
B1.cukai_sms,
TO_CHAR(B1.cukai_sms,'9999999.99') AS cukai_sms_sen
FROM
(SELECT A1.no_akaun,
A1.kod_stsakaun,
A1.nilai_thnn,
A1.kdr_taksiran,
ROUND(A1.cukai_sms,2) AS cukai_sms
FROM
(SELECT no_akaun,
kod_stsakaun,
nilai_thnn,
kdr_taksiran,
CASE
WHEN kod_stsakaun = 'T'
THEN 0
WHEN (nilai_thnn * KDR_TAKSIRAN/100)/2 < 2.5
THEN 0
ELSE (nilai_thnn * KDR_TAKSIRAN/100)/2
END cukai_sms
FROM ntharta
WHERE nilai_thnn >= 0
AND kdr_taksiran >= 0
AND no_akaun NOT IN
( SELECT no_akaun FROM enpenilaian
)
AND kod_stsakaun = 'A'
ORDER BY no_akaun
) A1
WHERE A1.cukai_sms >= 2.5
) B1
) C1
) D1
) E1 ;
Labels:
Oracle (SQL)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment