up
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
import { Entity, Enum, Index, ManyToOne, OptionalProps, Property } from '@mikro-orm/core';
|
||||
import { Product } from 'src/modules/product/entities/product.entity';
|
||||
import { IField } from 'src/modules/order/interface/order.interface';
|
||||
import { BaseEntity } from 'src/common/entities/base.entity';
|
||||
import { Invoice } from './invoice.entity';
|
||||
|
||||
|
||||
@Entity({ tableName: 'invoice_items' })
|
||||
export class InvoiceItem extends BaseEntity {
|
||||
[OptionalProps]?: 'createdAt' | 'deletedAt' | 'subTotal' | 'total';
|
||||
|
||||
@ManyToOne(() => Invoice)
|
||||
invoice!: Invoice;
|
||||
|
||||
@ManyToOne(() => Product)
|
||||
product!: Product;
|
||||
|
||||
@Property({ type: 'json', nullable: true })
|
||||
attributes?: IField[]
|
||||
|
||||
@Property({ type: 'int' })
|
||||
quantity!: number;
|
||||
|
||||
@Property({ type: 'int', nullable: true, })
|
||||
unitPrice?: number;
|
||||
|
||||
@Property({
|
||||
type: 'int',
|
||||
columnType: 'int GENERATED ALWAYS AS (COALESCE(unit_price, 0) * quantity) STORED',
|
||||
persist: false,
|
||||
nullable: true
|
||||
})
|
||||
subTotal!: number;
|
||||
|
||||
@Property({
|
||||
type: 'int',
|
||||
nullable: true
|
||||
})
|
||||
discount?: number;
|
||||
|
||||
@Property({
|
||||
type: 'int',
|
||||
nullable: true,
|
||||
columnType: 'int GENERATED ALWAYS AS ((COALESCE(unit_price, 0) * quantity) - COALESCE(discount, 0)) STORED',
|
||||
persist: false
|
||||
})
|
||||
total!: number;
|
||||
|
||||
@Property({ type: 'text', nullable: true })
|
||||
description?: string;
|
||||
|
||||
|
||||
@Property({ nullable: true, columnType: 'timestamptz' })
|
||||
confirmedAt?: Date;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user