| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- import { Entity, PrimaryGeneratedColumn, Column, Index } from 'typeorm';
- import { z } from '@hono/zod-openapi';
- @Entity('expense')
- export class Expense {
- @PrimaryGeneratedColumn({ unsigned: true })
- id!: number;
- @Column({ name: 'expense_date', type: 'date' })
- expenseDate!: Date;
- @Column({ name: 'user_id', type: 'varchar', length: 50 })
- userId!: string;
- @Column({ name: 'type', type: 'varchar', length: 50 })
- type!: string;
- @Column({ name: 'amount', type: 'decimal', precision: 10, scale: 2 })
- amount!: number;
- @Column({ name: 'client_id', type: 'int', unsigned: true, nullable: true })
- clientId?: number;
- @Column({ name: 'project_id', type: 'varchar', length: 50, nullable: true })
- projectId?: string;
- @Column({ name: 'department', type: 'varchar', length: 100, nullable: true })
- department?: string;
- @Column({ name: 'description', type: 'text', nullable: true })
- description?: string;
- @Column({ name: 'status', type: 'varchar', length: 50 })
- status!: string;
- @Column({ name: 'approver', type: 'varchar', length: 50, nullable: true })
- approver?: string;
- @Column({ name: 'approve_date', type: 'date', nullable: true })
- approveDate?: Date;
- @Column({ name: 'reimbursement_date', type: 'date', nullable: true })
- reimbursementDate?: Date;
- @Column({ name: 'payment_method', type: 'varchar', length: 50, nullable: true })
- paymentMethod?: string;
- @Column({ name: 'invoice_number', type: 'varchar', length: 100, nullable: true })
- invoiceNumber?: string;
- @Column({ name: 'currency', type: 'varchar', length: 20, default: 'CNY' })
- currency!: string;
- @Column({ name: 'exchange_rate', type: 'decimal', precision: 10, scale: 4, default: 1 })
- exchangeRate!: number;
- @Column({ name: 'foreign_amount', type: 'decimal', precision: 10, scale: 2, nullable: true })
- foreignAmount?: number;
- @Column({ name: 'created_at', type: 'timestamp', default: () => 'CURRENT_TIMESTAMP' })
- createdAt!: Date;
- @Column({
- name: 'updated_at',
- type: 'timestamp',
- default: () => 'CURRENT_TIMESTAMP',
- onUpdate: 'CURRENT_TIMESTAMP'
- })
- updatedAt!: Date;
- }
- export const ExpenseSchema = z.object({
- id: z.number().int().positive().openapi({
- description: '费用记录ID',
- example: 1
- }),
- expenseDate: z.date().openapi({
- description: '费用发生日期',
- example: '2023-01-15'
- }),
- userId: z.string().max(50).openapi({
- description: '产生费用的用户ID',
- example: 'U1001'
- }),
- type: z.string().max(50).openapi({
- description: '费用类型',
- example: '差旅费'
- }),
- amount: z.number().multipleOf(0.01).openapi({
- description: '费用金额',
- example: 1500.50
- }),
- clientId: z.number().int().positive().nullable().openapi({
- description: '关联客户ID',
- example: 2001
- }),
- projectId: z.string().max(50).nullable().openapi({
- description: '关联项目ID',
- example: 'P3001'
- }),
- department: z.string().max(100).nullable().openapi({
- description: '产生费用的部门',
- example: '研发部'
- }),
- description: z.string().nullable().openapi({
- description: '费用描述',
- example: '参加技术研讨会差旅费'
- }),
- status: z.string().max(50).openapi({
- description: '费用状态:如审批中、已报销等',
- example: '已报销'
- }),
- approver: z.string().max(50).nullable().openapi({
- description: '费用审批人ID',
- example: 'U1002'
- }),
- approveDate: z.date().nullable().openapi({
- description: '费用审批日期',
- example: '2023-01-20'
- }),
- reimbursementDate: z.date().nullable().openapi({
- description: '费用报销日期',
- example: '2023-01-25'
- }),
- paymentMethod: z.string().max(50).nullable().openapi({
- description: '支付方式',
- example: '银行卡'
- }),
- invoiceNumber: z.string().max(100).nullable().openapi({
- description: '发票号码',
- example: 'INV20230125001'
- }),
- currency: z.string().max(20).openapi({
- description: '货币类型',
- example: 'CNY'
- }),
- exchangeRate: z.number().multipleOf(0.0001).openapi({
- description: '汇率',
- example: 1.0000
- }),
- foreignAmount: z.number().multipleOf(0.01).nullable().openapi({
- description: '外币金额',
- example: null
- }),
- createdAt: z.date().openapi({
- description: '创建时间',
- example: '2023-01-15T00:00:00Z'
- }),
- updatedAt: z.date().openapi({
- description: '更新时间',
- example: '2023-01-25T00:00:00Z'
- })
- });
- export const CreateExpenseDto = z.object({
-
- expenseDate: z.coerce.date().openapi({
- description: '费用发生日期',
- example: '2023-01-15'
- }),
- type: z.string().max(50).openapi({
- description: '费用类型',
- example: '差旅费'
- }),
- amount: z.coerce.number().multipleOf(0.01).openapi({
- description: '费用金额',
- example: 1500.50
- }),
- clientId: z.coerce.number().int().positive().nullable().optional().openapi({
- description: '关联客户ID',
- example: 2001
- }),
- projectId: z.string().max(50).nullable().optional().openapi({
- description: '关联项目ID',
- example: 'P3001'
- }),
- department: z.string().max(100).nullable().optional().openapi({
- description: '产生费用的部门',
- example: '研发部'
- }),
- description: z.string().nullable().optional().openapi({
- description: '费用描述',
- example: '参加技术研讨会差旅费'
- }),
- status: z.string().max(50).openapi({
- description: '费用状态:如审批中、已报销等',
- example: '审批中'
- }),
- approver: z.string().max(50).nullable().optional().openapi({
- description: '费用审批人ID',
- example: 'U1002'
- }),
- approveDate: z.coerce.date().nullable().optional().openapi({
- description: '费用审批日期',
- example: '2023-01-20'
- }),
- reimbursementDate: z.coerce.date().nullable().optional().openapi({
- description: '费用报销日期',
- example: '2023-01-25'
- }),
- paymentMethod: z.string().max(50).nullable().optional().openapi({
- description: '支付方式',
- example: '银行卡'
- }),
- invoiceNumber: z.string().max(100).nullable().optional().openapi({
- description: '发票号码',
- example: 'INV20230125001'
- }),
- currency: z.string().max(20).default('CNY').openapi({
- description: '货币类型',
- example: 'CNY'
- }),
- exchangeRate: z.coerce.number().multipleOf(0.0001).default(1).openapi({
- description: '汇率',
- example: 1.0000
- }),
- foreignAmount: z.coerce.number().multipleOf(0.01).nullable().optional().openapi({
- description: '外币金额',
- example: null
- })
- });
- export const UpdateExpenseDto = z.object({
- expenseDate: z.coerce.date().optional().openapi({
- description: '费用发生日期',
- example: '2023-01-15'
- }),
- type: z.string().max(50).optional().openapi({
- description: '费用类型',
- example: '差旅费'
- }),
- amount: z.coerce.number().multipleOf(0.01).optional().openapi({
- description: '费用金额',
- example: 1500.50
- }),
- clientId: z.coerce.number().int().positive().nullable().optional().openapi({
- description: '关联客户ID',
- example: 2001
- }),
- projectId: z.string().max(50).nullable().optional().openapi({
- description: '关联项目ID',
- example: 'P3001'
- }),
- department: z.string().max(100).nullable().optional().openapi({
- description: '产生费用的部门',
- example: '研发部'
- }),
- description: z.string().nullable().optional().openapi({
- description: '费用描述',
- example: '参加技术研讨会差旅费'
- }),
- status: z.string().max(50).optional().openapi({
- description: '费用状态:如审批中、已报销等',
- example: '已报销'
- }),
- approver: z.string().max(50).nullable().optional().openapi({
- description: '费用审批人ID',
- example: 'U1002'
- }),
- approveDate: z.coerce.date().nullable().optional().openapi({
- description: '费用审批日期',
- example: '2023-01-20'
- }),
- reimbursementDate: z.coerce.date().nullable().optional().openapi({
- description: '费用报销日期',
- example: '2023-01-25'
- }),
- paymentMethod: z.string().max(50).nullable().optional().openapi({
- description: '支付方式',
- example: '银行卡'
- }),
- invoiceNumber: z.string().max(100).nullable().optional().openapi({
- description: '发票号码',
- example: 'INV20230125001'
- }),
- currency: z.string().max(20).optional().openapi({
- description: '货币类型',
- example: 'CNY'
- }),
- exchangeRate: z.coerce.number().multipleOf(0.0001).optional().openapi({
- description: '汇率',
- example: 1.0000
- }),
- foreignAmount: z.coerce.number().multipleOf(0.01).nullable().optional().openapi({
- description: '外币金额',
- example: null
- })
- });
|