From 4094d62e8ad32d974ac48547e68b2f8c99d0b952 Mon Sep 17 00:00:00 2001 From: fadlydev Date: Tue, 21 Jan 2025 19:35:56 +0700 Subject: [PATCH] update request order field --- src/entity/goods.ts | 32 ++++++++---- src/entity/request_orders.ts | 98 +++++++++++++++++++++++------------- 2 files changed, 84 insertions(+), 46 deletions(-) diff --git a/src/entity/goods.ts b/src/entity/goods.ts index 5f74824..aae092b 100644 --- a/src/entity/goods.ts +++ b/src/entity/goods.ts @@ -11,7 +11,8 @@ import { } from 'typeorm'; import { AssetCategory } from './asset_category'; -import { Supplier } from './supplier'; +import { Supplier } from './supplier'; +import { RequestOrder } from './request_orders'; @Entity('goods') export class Goods { @@ -19,18 +20,21 @@ export class Goods { id: string; @Column({ + type: 'varchar', nullable: false, length: 128, }) name: string; @Column({ + type: 'varchar', nullable: true, length: 255, }) description: string; @Column({ + type: 'varchar', nullable: false, length: 64, unique: true, @@ -46,43 +50,49 @@ export class Goods { price: number; @Column({ - nullable: false, + nullable: false, type: 'int', }) quantity: number; @Index() @Column({ - nullable: false, type: 'varchar', + nullable: false, }) created_by: string; @Index() @Column({ - nullable: false, type: 'varchar', + nullable: false, }) updated_by: string; @ManyToOne(() => AssetCategory, (category) => category.goods, { - nullable: false, - onDelete: 'SET NULL' + nullable: true, + onDelete: 'SET NULL', }) - @Index() - @JoinColumn({ name: 'category_id'}) + @JoinColumn({ name: 'category_id' }) category: AssetCategory; - + @ManyToOne(() => Supplier, (supplier) => supplier.goods, { nullable: true, - onDelete: 'SET NULL' + onDelete: 'SET NULL', }) - @Index() @JoinColumn({ name: 'supplier_id' }) supplier: Supplier; + @ManyToOne(() => RequestOrder, (requestOrder) => requestOrder.goods, { + nullable: true, + onDelete: 'SET NULL', + }) + @Index() + @JoinColumn({ name: 'request_order_id' }) + request_order: RequestOrder; + @Column({ nullable: false, default: true, diff --git a/src/entity/request_orders.ts b/src/entity/request_orders.ts index 486284a..707f2ad 100644 --- a/src/entity/request_orders.ts +++ b/src/entity/request_orders.ts @@ -5,84 +5,112 @@ import { CreateDateColumn, UpdateDateColumn, DeleteDateColumn, - Index, - ManyToOne, - JoinColumn, + OneToMany, } from 'typeorm'; - - -export enum PurchasingMethod { - PO = 'PO', // Purchase Order - DP = 'DP', // Direct Purchase -} +import { Goods } from './goods'; @Entity('request_orders') export class RequestOrder { @PrimaryGeneratedColumn('uuid') - id: string; + id: string; @Column({ nullable: false, length: 128, + unique: true, }) order_number: string; @Column({ - nullable: false, type: 'date', + nullable: false, }) order_date: Date; @Column({ - nullable: false, type: 'decimal', - precision: 12, + precision: 10, scale: 2, + nullable: false, }) total_amount: number; - @Index() @Column({ + type: 'varchar', nullable: false, - type: 'uuid', }) requested_by: string; @Column({ - nullable: false, - type: 'uuid', - array: true, - }) - goods_ids: string[]; - - @Column({ - nullable: true, type: 'text', + nullable: true, }) - remarks: string; + remarks: string | null; @Column({ - nullable: false, length: 64, + nullable: false, }) status: string; @Column({ + length: 2, nullable: false, - type: 'enum', - enum: PurchasingMethod, }) - purchasing_method: PurchasingMethod; + purchasing_method: string; + + // Supervisor Approval + @Column({ + type: 'uuid', + nullable: true, + }) + approved_by_spv: string | null; + + @Column({ + type: 'timestamp', + nullable: true, + }) + spv_approval_date: Date | null; + + @Column({ + type: 'varchar', + length: 16, + nullable: true, + default: 'PENDING', + }) + spv_approval_status: 'PENDING' | 'APPROVED' | 'REJECTED'; + + // General Manager Approval + @Column({ + type: 'uuid', + nullable: true, + }) + approved_by_gm: string | null; + + @Column({ + type: 'timestamp', + nullable: true, + }) + gm_approval_date: Date | null; + + @Column({ + type: 'varchar', + length: 16, + nullable: true, + default: 'PENDING', + }) + gm_approval_status: 'PENDING' | 'APPROVED' | 'REJECTED'; + + // Relation with Goods + @OneToMany(() => Goods, (goods) => goods.request_order) + goods: Goods[]; - @Column() @CreateDateColumn() created_at: Date; - @Column({ nullable: true }) - @UpdateDateColumn() - updated_at: Date; + @UpdateDateColumn({ nullable: true }) + updated_at: Date | null; - @Column({ nullable: true }) - @DeleteDateColumn() - deleted_at: Date; + @DeleteDateColumn({ nullable: true }) + deleted_at: Date | null; }