1
|
USE [MinovaHR_BANK_MEGA_Production]
|
2
|
GO
|
3
|
/****** Object: StoredProcedure [dbo].[AutoGenerateLeaveQuotaAfter1YearHiring] Script Date: 25/03/2022 17:10:03 ******/
|
4
|
SET ANSI_NULLS ON
|
5
|
GO
|
6
|
SET QUOTED_IDENTIFIER ON
|
7
|
GO
|
8
|
-- =============================================
|
9
|
-- Author: <Author,,Name>
|
10
|
-- Create date: <Create Date,,>
|
11
|
-- Description: <Description,,>
|
12
|
-- =============================================
|
13
|
alter PROCEDURE [dbo].[AutoGenerateLeaveQuotaAfter1YearHiring]
|
14
|
-- Add the parameters for the stored procedure here
|
15
|
--@Landscape varchar(3)
|
16
|
AS
|
17
|
BEGIN
|
18
|
INSERT INTO dbo.hr_md_emp_md0017
|
19
|
SELECT DISTINCT CONVERT(VARCHAR(20), '100') AS landscape ,
|
20
|
md02.emp_id ,
|
21
|
CONVERT(VARCHAR,YEAR(GETDATE()))+CONVERT(VARCHAR,SUBSTRING(hiring_date,5,4)) stdate ,
|
22
|
CONVERT(VARCHAR,YEAR(GETDATE()) +1)+CONVERT(VARCHAR,SUBSTRING(hiring_date,5,2))+ SUBSTRING(CONVERT(VARCHAR(MAX), CONVERT(DATE, DATEADD(DAY, -1, hiring_date))),9,2) AS endate ,
|
23
|
CONVERT(VARCHAR,YEAR(GETDATE()))+CONVERT(VARCHAR,SUBSTRING(hiring_date,5,4)) std,
|
24
|
CONVERT(VARCHAR,YEAR(GETDATE()) +1)+CONVERT(VARCHAR,SUBSTRING(hiring_date,5,2))+SUBSTRING(CONVERT(VARCHAR(MAX), CONVERT(DATE, DATEADD(DAY, -1, hiring_date))),9,2) AS etd ,
|
25
|
CONVERT(VARCHAR(20), '12') AS oriquot,
|
26
|
CONVERT(VARCHAR(20), 'System') AS userchange,
|
27
|
format(getdate(),'yyyyMMddHHmmss') AS laschange,
|
28
|
CONVERT(VARCHAR(20), 'System') AS createby,
|
29
|
format(getdate(),'yyyyMMddHHmmss') AS createdate,
|
30
|
CASE WHEN (SELECT TOP(1) CONVERT(VARCHAR(20), CONVERT(INT,seq)+1) AS seq FROM dbo.hr_md_emp_md0017 WHERE emp_id= md02.emp_id ORDER BY seq desc)
|
31
|
IS NOT NULL THEN
|
32
|
(SELECT TOP(1) CONVERT(VARCHAR(20), CONVERT(INT,seq)+1) AS seq FROM dbo.hr_md_emp_md0017 WHERE emp_id= md02.emp_id ORDER BY seq DESC) ELSE '1'
|
33
|
END AS seq,
|
34
|
CONVERT(VARCHAR(20),'1000') AS absentyp,
|
35
|
CONVERT(VARCHAR(20), '12') AS remainquot
|
36
|
FROM dbo.hr_md_emp_md0002 md02
|
37
|
LEFT OUTER JOIN dbo.hr_md_emp_md0015 md15 ON md02.emp_id = md15.emp_id
|
38
|
WHERE md02.employee_status = '01'
|
39
|
AND md15.hiring_date <= REPLACE(CAST(DATEADD(YEAR, -1, GETDATE()) AS DATE),'-', '')
|
40
|
AND md02.end_date = '99991231'
|
41
|
AND md02.emp_id NOT IN (
|
42
|
SELECT DISTINCT md02.emp_id
|
43
|
FROM dbo.hr_md_emp_md0002 md02
|
44
|
LEFT OUTER JOIN dbo.hr_md_emp_md0017 md17 ON md17.emp_id = md02.emp_id
|
45
|
WHERE md02.employee_status = '01'
|
46
|
AND md02.end_date = '99991231'
|
47
|
AND SUBSTRING( md17.[start_date],0,5) >= YEAR(GETDATE())
|
48
|
)
|
49
|
--AND md02.emp_id ='03053749'
|
50
|
END
|
51
|
|