Merge branch 'develop'
This commit is contained in:
commit
7b2587be7d
9 changed files with 1266 additions and 118 deletions
|
|
@ -1269,7 +1269,9 @@ export class ImportDataController extends Controller {
|
|||
|
||||
education.level = educationLevel == null ? 1 : educationLevel.level + 1;
|
||||
education.profileId = _item.id;
|
||||
education.degree = educationCode ? educationCode.EDUCATION_NAME : "";
|
||||
education.degree = educationCode ? educationCode.EDUCATION_ABB_NAME : "";
|
||||
// education.degree = educationCode ? educationCode.MAJOR_NAME: "";
|
||||
// education.degree = educationCode ? educationCode.FUND_COURSE_CODE: "";
|
||||
education.institute = item.INSTITUE;
|
||||
education.level = item.EDUCATION_SEQ ? null_ : Number(item.EDUCATION_SEQ);
|
||||
education.startDate = startDate;
|
||||
|
|
|
|||
|
|
@ -7087,9 +7087,10 @@ export class OrganizationController extends Controller {
|
|||
(x) =>
|
||||
x.orgChild1Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.posMasterOrder <= 3 &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: orgRoot.orgRootShortName + x.posMasterNo,
|
||||
|
|
@ -7134,9 +7135,10 @@ export class OrganizationController extends Controller {
|
|||
(x) =>
|
||||
x.orgChild2Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.posMasterOrder <= 3 &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: orgChild1.orgChild1ShortName + x.posMasterNo,
|
||||
|
|
@ -7189,9 +7191,10 @@ export class OrganizationController extends Controller {
|
|||
(x) =>
|
||||
x.orgChild3Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.posMasterOrder <= 3 &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: orgChild2.orgChild2ShortName + x.posMasterNo,
|
||||
|
|
@ -7251,9 +7254,10 @@ export class OrganizationController extends Controller {
|
|||
(x) =>
|
||||
x.orgChild4Id == null &&
|
||||
// x.current_holderId != null &&
|
||||
x.posMasterOrder <= 3 &&
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: orgChild3.orgChild3ShortName + x.posMasterNo,
|
||||
|
|
@ -7319,8 +7323,10 @@ export class OrganizationController extends Controller {
|
|||
.filter(
|
||||
(x) =>
|
||||
// x.current_holderId != null &&
|
||||
x.posMasterOrder <= 3 && x.isDirector === true,
|
||||
x.isDirector === true,
|
||||
)
|
||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||
// .slice(0, 3) // Select the first 3 rows
|
||||
.map(async (x) => ({
|
||||
posmasterId: x.id,
|
||||
posNo: orgChild4.orgChild4ShortName + x.posMasterNo,
|
||||
|
|
|
|||
|
|
@ -82,53 +82,48 @@ export class ProfileSalaryController extends Controller {
|
|||
|
||||
@Get("tenure/{profileId}")
|
||||
public async getPositionTenure(@Path() profileId: string, @Request() req: RequestWithUser) {
|
||||
const position = await AppDataSource.query(
|
||||
"CALL GetProfileSalaryPosition(?)",
|
||||
[profileId]
|
||||
);
|
||||
const _position = position.length > 0 ? position[0] : []
|
||||
const mapPosition = _position.length > 1
|
||||
? _position
|
||||
.slice(1)
|
||||
.map((curr: any, index: number) => ({
|
||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||
name: _position[index]?.positionName
|
||||
}))
|
||||
: [];
|
||||
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?)", [profileId]);
|
||||
const _position = position.length > 0 ? position[0] : [];
|
||||
const mapPosition =
|
||||
_position.length > 1
|
||||
? _position.slice(1).map((curr: any, index: number) => ({
|
||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||
name: _position[index]?.positionName,
|
||||
}))
|
||||
: [];
|
||||
|
||||
const posLevel = [{
|
||||
year: 1,
|
||||
month: 0,
|
||||
day: 0,
|
||||
name: "ต้น",
|
||||
}];
|
||||
|
||||
const posExecutive = await AppDataSource.query(
|
||||
"CALL GetProfileSalaryExecutive(?)",
|
||||
[profileId]
|
||||
);
|
||||
const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : []
|
||||
const mapPosExecutive = _posExecutive.length > 1
|
||||
? _posExecutive
|
||||
.slice(1)
|
||||
.map((curr: any, index: number) => ({
|
||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||
name: _posExecutive[index]?.positionName
|
||||
}))
|
||||
: [];
|
||||
const posLevel: any = [
|
||||
// {
|
||||
// year: 1,
|
||||
// month: 0,
|
||||
// day: 0,
|
||||
// name: "ต้น",
|
||||
// }
|
||||
];
|
||||
|
||||
const posExecutive = await AppDataSource.query("CALL GetProfileSalaryExecutive(?)", [
|
||||
profileId,
|
||||
]);
|
||||
const _posExecutive = posExecutive.length > 0 ? posExecutive[0] : [];
|
||||
const mapPosExecutive =
|
||||
_posExecutive.length > 1
|
||||
? _posExecutive.slice(1).map((curr: any, index: number) => ({
|
||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||
name: _posExecutive[index]?.positionName,
|
||||
}))
|
||||
: [];
|
||||
|
||||
return new HttpSuccess({
|
||||
position: mapPosition,
|
||||
posLevel: posLevel,
|
||||
posExecutive: mapPosExecutive
|
||||
posLevel: posLevel,
|
||||
posExecutive: mapPosExecutive,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Get("admin/{profileId}")
|
||||
public async getSalaryAdmin(@Path() profileId: string, @Request() req: RequestWithUser) {
|
||||
let _workflow = await new permission().Workflow(req, profileId, "SYS_SALARY_OFFICER");
|
||||
|
|
|
|||
|
|
@ -87,6 +87,36 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Get("tenure/{profileId}")
|
||||
public async getPositionTenure(@Path() profileId: string, @Request() req: RequestWithUser) {
|
||||
const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?)", [
|
||||
profileId,
|
||||
]);
|
||||
const _position = position.length > 0 ? position[0] : [];
|
||||
const mapPosition =
|
||||
_position.length > 1
|
||||
? _position.slice(1).map((curr: any, index: number) => ({
|
||||
year: curr.Years ? Math.floor(Number(curr.Years)) : 0,
|
||||
month: curr.Months ? Math.floor(Number(curr.Months)) : 0,
|
||||
day: curr.Days ? Math.floor(Number(curr.Days)) : 0,
|
||||
name: _position[index]?.positionName,
|
||||
}))
|
||||
: [];
|
||||
|
||||
const posLevel: any = [
|
||||
// {
|
||||
// year: 3,
|
||||
// month: 0,
|
||||
// day: 0,
|
||||
// name: "ส 1",
|
||||
// }
|
||||
];
|
||||
return new HttpSuccess({
|
||||
position: mapPosition,
|
||||
posLevel: posLevel,
|
||||
});
|
||||
}
|
||||
|
||||
@Get("admin/{profileId}")
|
||||
public async getSalaryEmployeeAdmin(@Path() profileId: string, @Request() req: RequestWithUser) {
|
||||
let _workflow = await new permission().Workflow(req, profileId, "SYS_WAGE");
|
||||
|
|
|
|||
|
|
@ -189,15 +189,18 @@ export class ReportController extends Controller {
|
|||
@Query() isRetire?: boolean,
|
||||
@Query() isRetireLaw?: boolean,
|
||||
@Query() retireType?: string,
|
||||
@Query() tenureType?: string,
|
||||
@Query() tenureMin?: number,
|
||||
@Query() tenureMax?: number,
|
||||
@Query() sortBy: string = "posMasterNo",
|
||||
@Query() sort: "ASC" | "DESC" = "ASC",
|
||||
) {
|
||||
const _null: any = null;
|
||||
if(!dateStart) {
|
||||
dateStart = _null
|
||||
if (!dateStart) {
|
||||
dateStart = _null;
|
||||
}
|
||||
if(!dateEnd) {
|
||||
dateEnd = _null
|
||||
if (!dateEnd) {
|
||||
dateEnd = _null;
|
||||
}
|
||||
if (ageMin && (ageMin < 18 || ageMin > 60)) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60");
|
||||
|
|
@ -211,6 +214,9 @@ export class ReportController extends Controller {
|
|||
ageMin = ageMin ?? 18;
|
||||
ageMax = ageMax ?? 60;
|
||||
|
||||
tenureMin = tenureMin ?? 0;
|
||||
tenureMax = tenureMax ?? 20;
|
||||
|
||||
let nodeCondition = "1=1";
|
||||
if (node === 0 && nodeId) {
|
||||
nodeCondition = "registryOfficer.orgRootId = :nodeId";
|
||||
|
|
@ -241,9 +247,16 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
let retireLawCondition = "1=1";
|
||||
if(isRetireLaw) {
|
||||
if (isRetireLaw) {
|
||||
retireLawCondition =
|
||||
"DATE(registryOfficer.dateRetireLaw) >= :startDateRetireLaw AND DATE(registryOfficer.dateRetireLaw) <= :endDateRetireLaw";
|
||||
"DATE(registryOfficer.dateRetireLaw) >= :startDateRetireLaw AND DATE(registryOfficer.dateRetireLaw) <= :endDateRetireLaw";
|
||||
}
|
||||
|
||||
let tenureTypeCondition = "1=1";
|
||||
if (tenureType != "" && tenureType == "position") {
|
||||
tenureTypeCondition = "registryOfficer.Years BETWEEN :tenureMin AND :tenureMax";
|
||||
} else if (tenureType != "" && tenureType == "level") {
|
||||
tenureTypeCondition = "registryOfficer.Years BETWEEN :tenureMin AND :tenureMax"; //xxxxxxxxxxxx
|
||||
}
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(viewRegistryOfficer)
|
||||
|
|
@ -251,6 +264,10 @@ export class ReportController extends Controller {
|
|||
.where(nodeCondition, {
|
||||
nodeId: nodeId,
|
||||
})
|
||||
.andWhere(tenureTypeCondition, {
|
||||
tenureMin: tenureMin,
|
||||
tenureMax: tenureMax,
|
||||
})
|
||||
.andWhere("registryOfficer.age BETWEEN :ageMin AND :ageMax", {
|
||||
ageMin,
|
||||
ageMax,
|
||||
|
|
@ -260,36 +277,36 @@ export class ReportController extends Controller {
|
|||
endDateAppoint: dateEnd?.toISOString().split("T")[0],
|
||||
})
|
||||
.andWhere(retireLawCondition, {
|
||||
startDateRetireLaw: new Date(new Date().getFullYear() - 1, 9, 1, 0, 0, 0, 0)?.toISOString().split("T")[0],
|
||||
endDateRetireLaw: new Date(new Date().getFullYear(), 8, 30, 23, 59, 59, 999).toISOString().split("T")[0],
|
||||
startDateRetireLaw: new Date(new Date().getFullYear() - 1, 9, 1, 0, 0, 0, 0)
|
||||
?.toISOString()
|
||||
.split("T")[0],
|
||||
endDateRetireLaw: new Date(new Date().getFullYear(), 8, 30, 23, 59, 59, 999)
|
||||
.toISOString()
|
||||
.split("T")[0],
|
||||
})
|
||||
.andWhere("registryOfficer.isProbation = :isProbation", {
|
||||
isProbation: isProbation,
|
||||
})
|
||||
.andWhere(IsLeavecondition.join(" AND "), parameters)
|
||||
.andWhere(
|
||||
posType != null && posType != ""
|
||||
? "registryOfficer.posTypeName LIKE :posTypeName"
|
||||
: "1=1",
|
||||
posType != null && posType != "" ? "registryOfficer.posTypeName LIKE :posTypeName" : "1=1",
|
||||
{
|
||||
posTypeName: `%${posType}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
posLevel != null && posLevel != ""
|
||||
? "registryOfficer.posLevelName LIKE :posLevelName"
|
||||
posLevel != null && posLevel != ""
|
||||
? "registryOfficer.posLevelName LIKE :posLevelName"
|
||||
: "1=1",
|
||||
{
|
||||
posLevelName: `%${posLevel}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
position != null && position != ""
|
||||
? "registryOfficer.position LIKE :position"
|
||||
: "1=1",
|
||||
position != null && position != "" ? "registryOfficer.position LIKE :position" : "1=1",
|
||||
{
|
||||
position: `%${position}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
positionExecutive != null && positionExecutive != ""
|
||||
|
|
@ -297,34 +314,26 @@ export class ReportController extends Controller {
|
|||
: "1=1",
|
||||
{
|
||||
posExecutiveName: `%${positionExecutive}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(gender != null && gender != "" ? "registryOfficer.gender LIKE :gender" : "1=1", {
|
||||
gender: `%${gender}%`,
|
||||
})
|
||||
.andWhere(
|
||||
gender != null && gender != ""
|
||||
? "registryOfficer.gender LIKE :gender"
|
||||
: "1=1",
|
||||
{
|
||||
gender: `%${gender}%`,
|
||||
}
|
||||
)
|
||||
.andWhere(
|
||||
status != null && status != ""
|
||||
? "registryOfficer.relationship LIKE :relationship"
|
||||
: "1=1",
|
||||
status != null && status != "" ? "registryOfficer.relationship LIKE :relationship" : "1=1",
|
||||
{
|
||||
relationship: `%${status}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
education != null && education != ""
|
||||
? "registryOfficer.degree LIKE :degree"
|
||||
: "1=1",
|
||||
education != null && education != "" ? "registryOfficer.degree LIKE :degree" : "1=1",
|
||||
{
|
||||
degree: `%${education}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.orderBy(`registryOfficer.${sortBy}`, sort)
|
||||
.getManyAndCount();
|
||||
|
||||
const mapData = lists.map((x) => ({
|
||||
profileId: x.profileId,
|
||||
citizenId: x.citizenId,
|
||||
|
|
@ -362,6 +371,24 @@ export class ReportController extends Controller {
|
|||
age: x.age,
|
||||
currentPosition: null,
|
||||
lengthPosition: null,
|
||||
positionDate: {
|
||||
Years: x.Years,
|
||||
Months: x.Months,
|
||||
Days: x.Days,
|
||||
},
|
||||
posExcutiveDate: {
|
||||
Years: x.posExecutiveYears,
|
||||
Months: x.posExecutiveMonths,
|
||||
Days: x.posExecutiveDays,
|
||||
},
|
||||
posLevelDate: {
|
||||
// Years: x.levelYears,
|
||||
// Months: x.levelMonths,
|
||||
// Days: x.levelDays,
|
||||
Years: 0,
|
||||
Months: 0,
|
||||
Days: 0,
|
||||
},
|
||||
}));
|
||||
return new HttpSuccess({
|
||||
data: mapData,
|
||||
|
|
@ -504,15 +531,18 @@ export class ReportController extends Controller {
|
|||
@Query() retireType?: string,
|
||||
@Query() ageMin?: number,
|
||||
@Query() ageMax?: number,
|
||||
@Query() tenureType?: string,
|
||||
@Query() tenureMin?: number,
|
||||
@Query() tenureMax?: number,
|
||||
@Query() sortBy: string = "posMasterNo",
|
||||
@Query() sort: "ASC" | "DESC" = "ASC",
|
||||
) {
|
||||
const _null: any = null;
|
||||
if(!dateStart) {
|
||||
dateStart = _null
|
||||
if (!dateStart) {
|
||||
dateStart = _null;
|
||||
}
|
||||
if(!dateEnd) {
|
||||
dateEnd = _null
|
||||
if (!dateEnd) {
|
||||
dateEnd = _null;
|
||||
}
|
||||
if (ageMin && (ageMin < 18 || ageMin > 60)) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ageMin must be between 18 and 60");
|
||||
|
|
@ -526,6 +556,9 @@ export class ReportController extends Controller {
|
|||
ageMin = ageMin ?? 18;
|
||||
ageMax = ageMax ?? 60;
|
||||
|
||||
tenureMin = tenureMin ?? 0;
|
||||
tenureMax = tenureMax ?? 20;
|
||||
|
||||
let nodeCondition = "1=1";
|
||||
if (node === 0 && nodeId) {
|
||||
nodeCondition = "registryEmployee.orgRootId = :nodeId";
|
||||
|
|
@ -556,9 +589,9 @@ export class ReportController extends Controller {
|
|||
}
|
||||
|
||||
let retireLawCondition = "1=1";
|
||||
if(isRetireLaw) {
|
||||
if (isRetireLaw) {
|
||||
retireLawCondition =
|
||||
"DATE(registryEmployee.dateRetireLaw) >= :startDateRetireLaw AND DATE(registryEmployee.dateRetireLaw) <= :endDateRetireLaw";
|
||||
"DATE(registryEmployee.dateRetireLaw) >= :startDateRetireLaw AND DATE(registryEmployee.dateRetireLaw) <= :endDateRetireLaw";
|
||||
}
|
||||
|
||||
const [lists, total] = await AppDataSource.getRepository(viewRegistryEmployee)
|
||||
|
|
@ -575,8 +608,12 @@ export class ReportController extends Controller {
|
|||
endDateAppoint: dateEnd?.toISOString().split("T")[0],
|
||||
})
|
||||
.andWhere(retireLawCondition, {
|
||||
startDateRetireLaw: new Date(new Date().getFullYear() - 1, 9, 1, 0, 0, 0, 0)?.toISOString().split("T")[0],
|
||||
endDateRetireLaw: new Date(new Date().getFullYear(), 8, 30, 23, 59, 59, 999).toISOString().split("T")[0],
|
||||
startDateRetireLaw: new Date(new Date().getFullYear() - 1, 9, 1, 0, 0, 0, 0)
|
||||
?.toISOString()
|
||||
.split("T")[0],
|
||||
endDateRetireLaw: new Date(new Date().getFullYear(), 8, 30, 23, 59, 59, 999)
|
||||
.toISOString()
|
||||
.split("T")[0],
|
||||
})
|
||||
.andWhere("registryEmployee.isProbation = :isProbation", {
|
||||
isProbation: isProbation,
|
||||
|
|
@ -584,52 +621,39 @@ export class ReportController extends Controller {
|
|||
.andWhere(IsLeavecondition.join(" AND "), parameters)
|
||||
.andWhere("registryEmployee.employeeClass = 'PERM'")
|
||||
.andWhere(
|
||||
posType != null && posType != ""
|
||||
? "registryEmployee.posTypeName LIKE :posTypeName"
|
||||
: "1=1",
|
||||
posType != null && posType != "" ? "registryEmployee.posTypeName LIKE :posTypeName" : "1=1",
|
||||
{
|
||||
posTypeName: `%${posType}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
posLevel != null && posLevel != ""
|
||||
? "registryEmployee.posLevelName LIKE :posLevelName"
|
||||
posLevel != null && posLevel != ""
|
||||
? "registryEmployee.posLevelName LIKE :posLevelName"
|
||||
: "1=1",
|
||||
{
|
||||
posLevelName: `%${posLevel}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
position != null && position != ""
|
||||
? "registryEmployee.position LIKE :position"
|
||||
: "1=1",
|
||||
position != null && position != "" ? "registryEmployee.position LIKE :position" : "1=1",
|
||||
{
|
||||
position: `%${position}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(gender != null && gender != "" ? "registryEmployee.gender LIKE :gender" : "1=1", {
|
||||
gender: `%${gender}%`,
|
||||
})
|
||||
.andWhere(
|
||||
gender != null && gender != ""
|
||||
? "registryEmployee.gender LIKE :gender"
|
||||
: "1=1",
|
||||
{
|
||||
gender: `%${gender}%`,
|
||||
}
|
||||
)
|
||||
.andWhere(
|
||||
status != null && status != ""
|
||||
? "registryEmployee.relationship LIKE :relationship"
|
||||
: "1=1",
|
||||
status != null && status != "" ? "registryEmployee.relationship LIKE :relationship" : "1=1",
|
||||
{
|
||||
relationship: `%${status}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
education != null && education != ""
|
||||
? "registryEmployee.degree LIKE :degree"
|
||||
: "1=1",
|
||||
education != null && education != "" ? "registryEmployee.degree LIKE :degree" : "1=1",
|
||||
{
|
||||
degree: `%${education}%`,
|
||||
}
|
||||
},
|
||||
)
|
||||
.orderBy(`registryEmployee.${sortBy}`, sort)
|
||||
.getManyAndCount();
|
||||
|
|
|
|||
155
src/entities/view/viewCurrentTenureExcOfficer.ts
Normal file
155
src/entities/view/viewCurrentTenureExcOfficer.ts
Normal 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;
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
@ -97,12 +117,20 @@ import { ViewColumn, ViewEntity } from "typeorm";
|
|||
p.dateRetireLaw,
|
||||
p.birthdate,
|
||||
ed.degree,
|
||||
TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age
|
||||
TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,
|
||||
vcto.Years,
|
||||
vcto.Months,
|
||||
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
|
||||
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 {
|
||||
|
|
@ -207,4 +235,22 @@ export class viewRegistryOfficer {
|
|||
|
||||
@ViewColumn()
|
||||
age: number;
|
||||
|
||||
@ViewColumn()
|
||||
Years: number;
|
||||
|
||||
@ViewColumn()
|
||||
Months: number;
|
||||
|
||||
@ViewColumn()
|
||||
Days: number;
|
||||
|
||||
@ViewColumn()
|
||||
posExecutiveYears: number;
|
||||
|
||||
@ViewColumn()
|
||||
posExecutiveMonths: number;
|
||||
|
||||
@ViewColumn()
|
||||
posExecutiveDays: number;
|
||||
}
|
||||
|
|
|
|||
227
src/migration/1740652136299-updateView.ts
Normal file
227
src/migration/1740652136299-updateView.ts
Normal file
|
|
@ -0,0 +1,227 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateView1740652136299 implements MigrationInterface {
|
||||
name = 'UpdateView1740652136299'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_registry_officer\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_registry_officer\` AS
|
||||
WITH Position AS (
|
||||
SELECT
|
||||
posExecutive.posExecutiveName,
|
||||
pn.posMasterId,
|
||||
ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number
|
||||
FROM position pn
|
||||
LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id
|
||||
WHERE pn.positionIsSelected IS TRUE
|
||||
),
|
||||
PosMaster AS (
|
||||
SELECT
|
||||
pm.current_holderId,
|
||||
pm.posMasterNo,
|
||||
pm.orgRootId,
|
||||
pm.orgChild1Id,
|
||||
pm.orgChild2Id,
|
||||
pm.orgChild3Id,
|
||||
pm.orgChild4Id,
|
||||
orgRoot.orgRootName,
|
||||
orgChild1.orgChild1Name,
|
||||
orgChild2.orgChild2Name,
|
||||
orgChild3.orgChild3Name,
|
||||
orgChild4.orgChild4Name,
|
||||
pn.posExecutiveName,
|
||||
CASE
|
||||
WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)
|
||||
WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)
|
||||
WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)
|
||||
WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)
|
||||
ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)
|
||||
END AS searchShortName,
|
||||
ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number
|
||||
FROM posMaster pm
|
||||
LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId
|
||||
LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId
|
||||
LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id
|
||||
LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id
|
||||
LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id
|
||||
LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id
|
||||
LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1
|
||||
WHERE
|
||||
orgRevision.orgRevisionIsCurrent IS TRUE
|
||||
AND orgRevision.orgRevisionIsDraft IS FALSE
|
||||
),
|
||||
Education AS (
|
||||
SELECT
|
||||
ed.degree,
|
||||
ed.profileId,
|
||||
ed.level,
|
||||
ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number
|
||||
FROM profileEducation ed
|
||||
WHERE ed.isUse IS TRUE
|
||||
ORDER BY ed.level ASC
|
||||
)
|
||||
SELECT
|
||||
p.id as profileId,
|
||||
p.citizenId,
|
||||
p.rank,
|
||||
p.prefix,
|
||||
p.firstName,
|
||||
p.lastName,
|
||||
p.isProbation,
|
||||
p.isLeave,
|
||||
p.isRetirement,
|
||||
p.leaveType,
|
||||
pm.posMasterNo,
|
||||
pm.orgRootId,
|
||||
pm.orgChild1Id,
|
||||
pm.orgChild2Id,
|
||||
pm.orgChild3Id,
|
||||
pm.orgChild4Id,
|
||||
pm.orgRootName,
|
||||
pm.orgChild1Name,
|
||||
pm.orgChild2Name,
|
||||
pm.orgChild3Name,
|
||||
pm.orgChild4Name,
|
||||
CASE
|
||||
WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName
|
||||
WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName)
|
||||
WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName)
|
||||
WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName)
|
||||
ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName)
|
||||
END AS org,
|
||||
pm.searchShortName,
|
||||
pm.posExecutiveName,
|
||||
p.position,
|
||||
posType.posTypeName,
|
||||
posLevel.posLevelName,
|
||||
p.gender,
|
||||
p.relationship,
|
||||
p.dateAppoint,
|
||||
p.dateRetire,
|
||||
p.dateRetireLaw,
|
||||
p.birthdate,
|
||||
ed.degree,
|
||||
TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,
|
||||
vcto.Years,
|
||||
vcto.Months,
|
||||
vcto.Days
|
||||
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
|
||||
`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM position pn\n LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n pn.posExecutiveName,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM posMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE \n orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n pm.posExecutiveName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age,\n vcto.Years,\n vcto.Months,\n vcto.Days\n FROM profile p\n LEFT JOIN posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1\n Inner Join view_current_tenure_officer vcto On p.id = vcto.profileId\n Where vcto.orderNumber Is Null"]);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`DELETE FROM \`bma_ehr_organization_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_registry_officer","bma_ehr_organization_demo"]);
|
||||
await queryRunner.query(`DROP VIEW \`view_registry_officer\``);
|
||||
await queryRunner.query(`CREATE VIEW \`view_registry_officer\` AS WITH Position AS (
|
||||
SELECT
|
||||
posExecutive.posExecutiveName,
|
||||
pn.posMasterId,
|
||||
ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number
|
||||
FROM position pn
|
||||
LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id
|
||||
WHERE pn.positionIsSelected IS TRUE
|
||||
),
|
||||
PosMaster AS (
|
||||
SELECT
|
||||
pm.current_holderId,
|
||||
pm.posMasterNo,
|
||||
pm.orgRootId,
|
||||
pm.orgChild1Id,
|
||||
pm.orgChild2Id,
|
||||
pm.orgChild3Id,
|
||||
pm.orgChild4Id,
|
||||
orgRoot.orgRootName,
|
||||
orgChild1.orgChild1Name,
|
||||
orgChild2.orgChild2Name,
|
||||
orgChild3.orgChild3Name,
|
||||
orgChild4.orgChild4Name,
|
||||
pn.posExecutiveName,
|
||||
CASE
|
||||
WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)
|
||||
WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)
|
||||
WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)
|
||||
WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)
|
||||
ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)
|
||||
END AS searchShortName,
|
||||
ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number
|
||||
FROM posMaster pm
|
||||
LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId
|
||||
LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId
|
||||
LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id
|
||||
LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id
|
||||
LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id
|
||||
LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id
|
||||
LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1
|
||||
WHERE
|
||||
orgRevision.orgRevisionIsCurrent IS TRUE
|
||||
AND orgRevision.orgRevisionIsDraft IS FALSE
|
||||
),
|
||||
Education AS (
|
||||
SELECT
|
||||
ed.degree,
|
||||
ed.profileId,
|
||||
ed.level,
|
||||
ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number
|
||||
FROM profileEducation ed
|
||||
WHERE ed.isUse IS TRUE
|
||||
ORDER BY ed.level ASC
|
||||
)
|
||||
SELECT
|
||||
p.id as profileId,
|
||||
p.citizenId,
|
||||
p.rank,
|
||||
p.prefix,
|
||||
p.firstName,
|
||||
p.lastName,
|
||||
p.isProbation,
|
||||
p.isLeave,
|
||||
p.isRetirement,
|
||||
p.leaveType,
|
||||
pm.posMasterNo,
|
||||
pm.orgRootId,
|
||||
pm.orgChild1Id,
|
||||
pm.orgChild2Id,
|
||||
pm.orgChild3Id,
|
||||
pm.orgChild4Id,
|
||||
pm.orgRootName,
|
||||
pm.orgChild1Name,
|
||||
pm.orgChild2Name,
|
||||
pm.orgChild3Name,
|
||||
pm.orgChild4Name,
|
||||
CASE
|
||||
WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName
|
||||
WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, " ", pm.orgRootName)
|
||||
WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName)
|
||||
WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName)
|
||||
ELSE CONCAT(pm.orgChild4Name, " ", pm.orgChild3Name, " ", pm.orgChild2Name, " ", pm.orgChild1Name, " ", pm.orgRootName)
|
||||
END AS org,
|
||||
pm.searchShortName,
|
||||
pm.posExecutiveName,
|
||||
p.position,
|
||||
posType.posTypeName,
|
||||
posLevel.posLevelName,
|
||||
p.gender,
|
||||
p.relationship,
|
||||
p.dateAppoint,
|
||||
p.dateRetire,
|
||||
p.dateRetireLaw,
|
||||
p.birthdate,
|
||||
ed.degree,
|
||||
TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age
|
||||
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`);
|
||||
await queryRunner.query(`INSERT INTO \`bma_ehr_organization_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_organization_demo","VIEW","view_registry_officer","WITH Position AS (\n SELECT \n posExecutive.posExecutiveName,\n pn.posMasterId,\n ROW_NUMBER() OVER (PARTITION BY pn.posMasterId) AS pn_number\n FROM position pn\n LEFT JOIN posExecutive ON pn.posExecutiveId = posExecutive.id\n WHERE pn.positionIsSelected IS TRUE\n ),\n PosMaster AS (\n SELECT \n pm.current_holderId,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n orgRoot.orgRootName,\n orgChild1.orgChild1Name,\n orgChild2.orgChild2Name,\n orgChild3.orgChild3Name,\n orgChild4.orgChild4Name,\n pn.posExecutiveName,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN CONCAT(orgRoot.orgRootShortName, pm.posMasterNo)\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(orgChild1.orgChild1ShortName, pm.posMasterNo)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(orgChild2.orgChild2ShortName, pm.posMasterNo)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(orgChild3.orgChild3ShortName, pm.posMasterNo)\n ELSE CONCAT(orgChild4.orgChild4ShortName, pm.posMasterNo)\n END AS searchShortName,\n ROW_NUMBER() OVER (PARTITION BY pm.current_holderId ORDER BY pm.posMasterNo DESC) AS pm_number\n FROM posMaster pm\n LEFT JOIN orgRevision ON orgRevision.id = pm.orgRevisionId\n LEFT JOIN orgRoot ON orgRoot.id = pm.orgRootId\n LEFT JOIN orgChild1 ON orgChild1.id = pm.orgChild1Id\n LEFT JOIN orgChild2 ON orgChild2.id = pm.orgChild2Id\n LEFT JOIN orgChild3 ON orgChild3.id = pm.orgChild3Id\n LEFT JOIN orgChild4 ON orgChild4.id = pm.orgChild4Id\n LEFT JOIN Position pn ON pm.id = pn.posMasterId AND pn.pn_number = 1\n WHERE \n orgRevision.orgRevisionIsCurrent IS TRUE \n AND orgRevision.orgRevisionIsDraft IS FALSE\n ),\n Education AS (\n SELECT \n ed.degree,\n ed.profileId,\n ed.level,\n ROW_NUMBER() OVER (PARTITION BY ed.profileId ORDER BY ed.level ASC) AS ed_number\n FROM profileEducation ed\n WHERE ed.isUse IS TRUE\n ORDER BY ed.level ASC\n )\n SELECT \n p.id as profileId,\n p.citizenId,\n p.rank,\n p.prefix,\n p.firstName,\n p.lastName,\n p.isProbation,\n p.isLeave,\n p.isRetirement,\n p.leaveType,\n pm.posMasterNo,\n pm.orgRootId,\n pm.orgChild1Id,\n pm.orgChild2Id,\n pm.orgChild3Id,\n pm.orgChild4Id,\n pm.orgRootName,\n pm.orgChild1Name,\n pm.orgChild2Name,\n pm.orgChild3Name,\n pm.orgChild4Name,\n CASE \n WHEN pm.orgChild1Id IS NULL THEN pm.orgRootName\n WHEN pm.orgChild2Id IS NULL THEN CONCAT(pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild3Id IS NULL THEN CONCAT(pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n WHEN pm.orgChild4Id IS NULL THEN CONCAT(pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n ELSE CONCAT(pm.orgChild4Name, \" \", pm.orgChild3Name, \" \", pm.orgChild2Name, \" \", pm.orgChild1Name, \" \", pm.orgRootName)\n END AS org,\n pm.searchShortName,\n pm.posExecutiveName,\n p.position,\n posType.posTypeName,\n posLevel.posLevelName,\n p.gender,\n p.relationship,\n p.dateAppoint,\n p.dateRetire,\n p.dateRetireLaw,\n p.birthdate,\n ed.degree,\n TIMESTAMPDIFF(YEAR, p.birthdate, CURDATE()) AS age\n FROM profile p\n LEFT JOIN posLevel ON p.posLevelId = posLevel.id\n LEFT JOIN posType ON p.posTypeId = posType.id\n LEFT JOIN PosMaster pm ON p.id = pm.current_holderId AND pm.pm_number = 1\n LEFT JOIN Education ed ON p.id = ed.profileId AND ed.ed_number = 1"]);
|
||||
}
|
||||
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue