This commit is contained in:
2026-02-18 22:00:00 +03:30
parent 417461a016
commit 84270ccb46
19 changed files with 387 additions and 2 deletions
@@ -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;
}