created Salary entity

This commit is contained in:
AdisakKanthawilang 2024-02-15 14:47:06 +07:00
parent a429021f6d
commit 570ca11c84
5 changed files with 353 additions and 0 deletions

67
src/entities/PosLevel.ts Normal file
View file

@ -0,0 +1,67 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { PosType } from "./PosType";
import { profile } from "console";
import { Salarys } from "./Salarys";
enum PosLevelAuthority {
HEAD = "HEAD",
DEPUTY = "DEPUTY",
GOVERNOR = "GOVERNOR",
}
@Entity("posLevel")
export class PosLevel extends EntityBase {
@Column({
nullable: true,
comment: "ชื่อระดับตำแหน่ง",
length: 255,
default: null,
})
posLevelName: string;
@Column({
nullable: true,
comment: "ระดับของระดับตำแหน่ง",
default: null,
})
posLevelRank: number;
@Column({
nullable: true,
comment:
"ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ",
type: "enum",
enum: PosLevelAuthority,
default: null,
})
posLevelAuthority: PosLevelAuthority;
@Column({
length: 40,
comment: "เป็นระดับของประเภทตำแหน่งใด",
})
posTypeId: string;
@OneToMany(() => Salarys, (salary) => salary.posLevel_)
salarys_: Salarys[];
@ManyToOne(() => PosType, (posType) => posType.posLevels)
@JoinColumn({ name: "posTypeId" })
posType: PosType;
}
export class CreatePosLevel {
@Column()
posLevelName: string;
@Column()
posLevelRank: number;
@Column()
posLevelAuthority: string;
@Column("uuid")
posTypeId: string;
}
export type UpdatePosLevel = Partial<CreatePosLevel> & { posLevelAuthority?: PosLevelAuthority };

40
src/entities/PosType.ts Normal file
View file

@ -0,0 +1,40 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { PosLevel } from "./PosLevel";
import { Salarys } from "./Salarys";
@Entity("posType")
export class PosType extends EntityBase {
@Column({
nullable: true,
comment: "ชื่อประเภทตำแหน่ง (ทั่วไป วิชาการ อำนวยการ บริหาร)",
length: 255,
default: null,
})
posTypeName: string;
@Column({
nullable: true,
comment:
"ระดับของประเภทตำแหน่ง ไว้ใช้ระบุว่าประเภทตำแหน่งนี้อยู่ระดับสูงหรือต่ำกว่ากัน โดย 1 = ต่ำกว่า , มากกว่า 1 = สูงกว่า ทั่วไป = 1 วิชาการ = 2 อำนวยการ = 3 บริหาร = 4",
default: null,
})
posTypeRank: number;
@OneToMany(() => PosLevel, (posLevel) => posLevel.posType)
posLevels: PosLevel[];
@OneToMany(() => Salarys, (salary) => salary.posType_)
salarys_: Salarys[];
}
export class CreatePosType {
@Column()
posTypeName: string;
@Column()
posTypeRank: number;
}
export type UpdatePosType = Partial<CreatePosType>;

114
src/entities/SalaryRanks.ts Normal file
View file

@ -0,0 +1,114 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { Salarys } from "./Salarys";
@Entity("salaryRanks")
export class SalaryRanks extends EntityBase {
@Column({
length: 40,
comment: "Id ผังเงินเดือน",
})
salaryId: string;
@Column({
type: "double",
comment: "เงินเดือนฐาน",
})
salary: number;
@Column({
nullable: true,
type: "double",
comment: "0.5 ขั้น",
default: null,
})
salaryHalf: number | null;
@Column({
nullable: true,
type: "double",
comment: "0.5 ขั้น(เงินพิเศษ)",
default: null,
})
salaryHalfSpecial: number | null;
@Column({
nullable: true,
type: "double",
comment: "1 ขั้น",
default: null,
})
salaryFull: number | null;
@Column({
nullable: true,
type: "double",
comment: "1 ขั้น(เงินพิเศษ)",
default: null,
})
salaryFullSpecial: number | null;
@Column({
nullable: true,
type: "double",
comment: "1.5 ขั้น",
default: null,
})
salaryFullHalf: number | null;
@Column({
nullable: true,
type: "double",
comment: "1.5 ขั้น(เงินพิเศษ)",
default: null,
})
salaryFullHalfSpecial: number | null;
@Column({
comment: "ทะลุขั้น",
})
isNext: boolean;
@Column({
comment: "ลำดับ",
})
rank: number;
@ManyToOne(() => Salarys, (salarys) => salarys.salaryRanks_)
@JoinColumn({ name: "salaryId" })
salarys_: Salarys;
}
export class CreateSalaryRank {
@Column("uuid")
salaryId: string;
@Column()
salary: number;
@Column()
salaryHalf?: number;
@Column()
salaryHalfSpecial?: number;
@Column()
salaryFull?: number;
@Column()
salaryFullSpecial?: number;
@Column()
salaryFullHalf?: number;
@Column()
salaryFullHalfSpecial?: number;
@Column()
isNext: boolean;
@Column()
rank: number;
}
export type UpdateSalaryRank = Partial<CreateSalaryRank>;

104
src/entities/Salarys.ts Normal file
View file

@ -0,0 +1,104 @@
import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base";
import { SalaryRanks } from "./SalaryRanks";
import { PosType } from "./PosType";
import { PosLevel } from "./PosLevel";
@Entity("salarys")
export class Salarys extends EntityBase {
@Column({
comment: "ประเภทผัง",
length: 255,
})
salaryType: string;
@Column({
length: 40,
comment: "Id ระดับของตำแหน่ง",
})
posTypeId: string;
@Column({
length: 40,
comment: "Id ประเภทของตำแหน่ง",
})
posLevelId: string;
@Column({
comment: "สถานะการใช้งาน",
})
isActive: boolean;
@Column({
nullable: true,
type: "datetime",
comment: "ให้ไว้ ณ วันที่",
default: null,
})
date: Date;
@Column({
nullable: true,
type: "datetime",
comment: "วันที่มีผลบังคับใช้",
default: null,
})
startDate: Date;
@Column({
nullable: true,
type: "datetime",
comment: "วันที่สิ้นสุดบังคับใช้",
default: null,
})
endDate: Date;
@Column({
nullable: true,
comment: "คำอธิบาย",
length: 255,
default: null,
})
details: string;
@OneToMany(() => SalaryRanks, (salaryRanks) => salaryRanks.salarys_)
salaryRanks_: SalaryRanks[];
@ManyToOne(() => PosType, (posType) => posType.salarys_)
@JoinColumn({ name: "posTypeId" })
posType_: PosType;
@ManyToOne(() => PosLevel, (posLevel) => posLevel.salarys_)
@JoinColumn({ name: "posLevelId" })
posLevel_: PosLevel;
}
export class CreateSalaryRank {
@Column()
salaryType: string;
@Column("uuid")
posTypeId: string;
@Column("uuid")
posLevelId: string;
@Column()
isActive: boolean;
@Column()
date?: Date;
@Column()
startDate?: Date;
@Column()
endDate?: Date;
@Column()
detail?: string;
}
export type UpdateSalaryRank = Partial<CreateSalaryRank> ;

View file

@ -0,0 +1,28 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class CreatedTableSalary1707983156369 implements MigrationInterface {
name = 'CreatedTableSalary1707983156369'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE TABLE \`salaryRanks\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`salaryId\` varchar(40) NOT NULL COMMENT 'Id ผังเงินเดือน', \`salary\` double NOT NULL COMMENT 'เงินเดือนฐาน', \`salaryHalf\` double NULL COMMENT '0.5 ขั้น', \`salaryHalfSpecial\` double NULL COMMENT '0.5 ขั้น(เงินพิเศษ)', \`salaryFull\` double NULL COMMENT '1 ขั้น', \`salaryFullSpecial\` double NULL COMMENT '1 ขั้น(เงินพิเศษ)', \`salaryFullHalf\` double NULL COMMENT '1.5 ขั้น', \`salaryFullHalfSpecial\` double NULL COMMENT '1.5 ขั้น(เงินพิเศษ)', \`isNext\` tinyint NOT NULL COMMENT 'ทะลุขั้น', \`rank\` int NOT NULL COMMENT 'ลำดับ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`posLevel\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`posLevelName\` varchar(255) NULL COMMENT 'ชื่อระดับตำแหน่ง', \`posLevelRank\` int NULL COMMENT 'ระดับของระดับตำแหน่ง', \`posLevelAuthority\` enum ('HEAD', 'DEPUTY', 'GOVERNOR') NULL COMMENT 'ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ', \`posTypeId\` varchar(40) NOT NULL COMMENT 'เป็นระดับของประเภทตำแหน่งใด', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`posType\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อประเภทตำแหน่ง (ทั่วไป วิชาการ อำนวยการ บริหาร)', \`posTypeRank\` int NULL COMMENT 'ระดับของประเภทตำแหน่ง ไว้ใช้ระบุว่าประเภทตำแหน่งนี้อยู่ระดับสูงหรือต่ำกว่ากัน โดย 1 = ต่ำกว่า , มากกว่า 1 = สูงกว่า ทั่วไป = 1 วิชาการ = 2 อำนวยการ = 3 บริหาร = 4', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`CREATE TABLE \`salarys\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`salaryType\` varchar(255) NOT NULL COMMENT 'ประเภทผัง', \`posTypeId\` varchar(40) NOT NULL COMMENT 'Id ระดับของตำแหน่ง', \`posLevelId\` varchar(40) NOT NULL COMMENT 'Id ประเภทของตำแหน่ง', \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน', \`date\` datetime NULL COMMENT 'ให้ไว้ ณ วันที่', \`startDate\` datetime NULL COMMENT 'วันที่มีผลบังคับใช้', \`endDate\` datetime NULL COMMENT 'วันที่สิ้นสุดบังคับใช้', \`details\` varchar(255) NULL COMMENT 'คำอธิบาย', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
await queryRunner.query(`ALTER TABLE \`salaryRanks\` ADD CONSTRAINT \`FK_b6c5dca80c76486ebcadf6a4dd9\` FOREIGN KEY (\`salaryId\`) REFERENCES \`salarys\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`posLevel\` ADD CONSTRAINT \`FK_66caa3d974b67a8a8b343d029b2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_fa211557e2cbee0bb3bbef363f2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_683719e5363cc977da591556731\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_683719e5363cc977da591556731\``);
await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_fa211557e2cbee0bb3bbef363f2\``);
await queryRunner.query(`ALTER TABLE \`posLevel\` DROP FOREIGN KEY \`FK_66caa3d974b67a8a8b343d029b2\``);
await queryRunner.query(`ALTER TABLE \`salaryRanks\` DROP FOREIGN KEY \`FK_b6c5dca80c76486ebcadf6a4dd9\``);
await queryRunner.query(`DROP TABLE \`salarys\``);
await queryRunner.query(`DROP TABLE \`posType\``);
await queryRunner.query(`DROP TABLE \`posLevel\``);
await queryRunner.query(`DROP TABLE \`salaryRanks\``);
}
}