add posexcutive date

This commit is contained in:
kittapath 2025-02-28 11:45:04 +07:00
parent 180cdd225e
commit f781af3151
7 changed files with 984 additions and 155 deletions

View file

@ -0,0 +1,155 @@
import { ViewColumn, ViewEntity } from "typeorm";
@ViewEntity({
expression: `
SELECT
DATE(MIN(commandDateAffect)) AS commandDateAffect,
TIMESTAMPDIFF(
DAY,
LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) AS days_diff,
TIMESTAMPDIFF(
DAY,
LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) / 365.2524 AS 'Years',
TIMESTAMPDIFF(
DAY,
LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) / 30.4375 % 12 AS 'Months',
TIMESTAMPDIFF(
DAY,
LAG(MIN(commandDateAffect)) OVER (PARTITION BY profileId ORDER BY commandDateAffect, \`order\` ASC), MIN(commandDateAffect)) % 30.4375 AS 'Days',
positionName,
positionCee,
posNo,
positionExecutive,
positionType,
positionLevel,
OrgRoot,
orgChild1,
orgChild2,
orgChild3,
orgChild4,
commandCode,
commandName,
commandNo,
commandYear,
remark,
profileId,
ROW_NUMBER() OVER (PARTITION BY profileId ORDER BY commandDateAffect ASC) AS orderNumber
FROM
profileSalary
WHERE
commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND
positionExecutive <> '' AND
positionExecutive is not null
GROUP BY
profileId, positionExecutive
UNION ALL
SELECT
CURDATE() AS commandDateAffect,
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) AS days_diff,
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 365.2524 AS 'Years',
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) / 30.4375 % 12 AS 'Months',
TIMESTAMPDIFF(DAY, MAX(commandDateAffect), CURDATE()) % 30.4375 AS 'Days',
NULL AS positionName,
NULL AS positionCee,
NULL AS posNo,
NULL AS positionExecutive,
NULL AS positionType,
NULL AS positionLevel,
NULL AS OrgRoot,
NULL AS orgChild1,
NULL AS orgChild2,
NULL AS orgChild3,
NULL AS orgChild4,
NULL AS commandCode,
NULL AS commandName,
NULL AS commandNo,
NULL AS commandYear,
'Comparison with current date' AS remark,
profileId,
NULL AS orderNumber
FROM
profileSalary
WHERE
commandCode IN (1, 2, 3, 4, 8, 10, 11, 12, 15, 16) AND
positionExecutive <> '' AND
positionExecutive is not null
GROUP BY
profileId
ORDER BY
profileId,
commandDateAffect ASC
`,
})
export class viewCurrentTenureExcOfficer {
@ViewColumn()
commandDateAffect: Date;
@ViewColumn()
days_diff: number;
@ViewColumn()
Years: number;
@ViewColumn()
Months: number;
@ViewColumn()
Days: number;
@ViewColumn()
positionName: string;
@ViewColumn()
positionCee: string;
@ViewColumn()
posNo: string;
@ViewColumn()
positionExecutive: string;
@ViewColumn()
positionType: string;
@ViewColumn()
positionLevel: string;
@ViewColumn()
OrgRoot: string;
@ViewColumn()
orgChild1: string;
@ViewColumn()
orgChild2: string;
@ViewColumn()
orgChild3: string;
@ViewColumn()
orgChild4: string;
@ViewColumn()
commandCode: number;
@ViewColumn()
commandName: string;
@ViewColumn()
commandNo: string;
@ViewColumn()
commandYear: number;
@ViewColumn()
remark: string;
@ViewColumn()
profileId: string;
@ViewColumn()
orderNumber: number;
}

View file

@ -55,6 +55,26 @@ import { ViewColumn, ViewEntity } from "typeorm";
FROM profileEducation ed
WHERE ed.isUse IS TRUE
ORDER BY ed.level ASC
),
PositionDate AS (
SELECT
vcto.Years,
vcto.Months,
vcto.Days,
vcto.profileId,
ROW_NUMBER() OVER (PARTITION BY vcto.profileId) AS vcto_number
FROM view_current_tenure_officer vcto
WHERE vcto.orderNumber Is Null
),
PositionExcDate AS (
SELECT
vctoExc.Years,
vctoExc.Months,
vctoExc.Days,
vctoExc.profileId,
ROW_NUMBER() OVER (PARTITION BY vctoExc.profileId) AS vctoExc_number
FROM view_current_tenure_exc_officer vctoExc
WHERE vctoExc.orderNumber Is Null
)
SELECT
p.id as profileId,
@ -100,14 +120,17 @@ import { ViewColumn, ViewEntity } from "typeorm";
TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,
vcto.Years,
vcto.Months,
vcto.Days
vcto.Days,
vctoExc.Years AS posExecutiveYears,
vctoExc.Months AS posExecutiveMonths,
vctoExc.Days AS posExecutiveDays
FROM profile p
LEFT JOIN posLevel ON p.posLevelId = posLevel.id
LEFT JOIN posType ON p.posTypeId = posType.id
LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1
LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1
Inner Join view_current_tenure_officer vcto On p.id = vcto.profileId
Where vcto.orderNumber Is Null
LEFT JOIN PositionDate vcto ON p.id = vcto.profileId AND vcto.vcto_number = 1
LEFT JOIN PositionExcDate vctoExc ON p.id = vctoExc.profileId AND vctoExc.vctoExc_number = 1
`,
})
export class viewRegistryOfficer {
@ -222,13 +245,12 @@ export class viewRegistryOfficer {
@ViewColumn()
Days: number;
// @ViewColumn()
// posExecutiveYears: number;
@ViewColumn()
posExecutiveYears: number;
// @ViewColumn()
// posExecutiveMonths: number;
// @ViewColumn()
// posExecutiveDays: number;
@ViewColumn()
posExecutiveMonths: number;
@ViewColumn()
posExecutiveDays: number;
}