Files
negareh-api/src/modules/invoice/entities/invoice-item.entity.ts
T
2026-02-18 23:58:03 +03:30

61 lines
1.4 KiB
TypeScript

import { Entity, ManyToOne, OptionalProps, Property } from '@mikro-orm/core';
import { Product } from 'src/modules/product/entities/product.entity';
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: 'int' })
quantity!: number;
@Property({ type: 'int'})
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({ type: 'string', nullable: true })
paymentMethod?: string;
@Property({ nullable: true, columnType: 'timestamptz' })
confirmedAt?: Date;
@Property({ type: 'json', nullable: true })
attachments?: string[]
}