import CheckConstraint from "@entity-access/entity-access/dist/decorators/CheckConstraint.js"; import Column from "@entity-access/entity-access/dist/decorators/Column.js"; import { RelateTo } from "@entity-access/entity-access/dist/decorators/Relate.js"; import Table from "@entity-access/entity-access/dist/decorators/Table.js"; import { StoreJournalEntry } from "./StoreJournalEntry.js"; import { StoreJournal } from "./StoreJournal.js"; import { itemTypeArray, itemTypeArrayType, StoreItem } from "./StoreItem.js"; import { StoreItemPrice } from "./StoreItemPrice.js"; import { StoreAccount } from "./StoreAccount.js"; import type StoreJournalCoupon from "./StoreJournalCoupon.js"; @Table("StoreJournalLineItems") @CheckConstraint({ name: "CC_StoreJournalLineItem_Amount_And_Quantity", filter: (x) => x.quantity > 0 && x.amount > 0 }) export class StoreJournalLineItem { @Column({ dataType: "BigInt", key: true, generated: "identity" }) public lineItemID: number; @Column({ dataType: "BigInt" }) @RelateTo(StoreJournal, { property: (x) => x.journal, inverseProperty: (x) => x.lineItems, foreignKeyConstraint: { name: "FC_Journal_Items_OrderID", onDelete: "cascade" } }) public journalID: number; @Column({ dataType: "BigInt" }) @RelateTo(StoreItem, { property: (x) => x.item, inverseProperty: (x) => x.lineItems, foreignKeyConstraint: { name: "FC_Journal_Items_ItemID", onDelete: "restrict" } }) public itemID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreItemPrice, { property: (x) => x.itemPrice, inverseProperty: (x) => x.lineItems, foreignKeyConstraint: { name: "FC_Journal_Item_Price_ID", onDelete: "restrict" } }) public itemPriceID: number; /** * Price of the item, copied from itemPrice */ @Column({ dataType: "Decimal", default: () => 0 }) public price: number; @Column({ dataType: "Decimal", default: () => 0}) public discountPercentage: number; @Column({ dataType: "Decimal", default: () => 0}) public discount: number; /** This should be the price before coupons are applied */ @Column({ dataType: "Decimal", default: () => 0}) public priceAfterDiscount: number; /** This discount calculated by applicable coupons */ @Column({ dataType: "Decimal", default: () => 0}) public couponDiscount: number; @Column({ dataType: "Decimal", default: () => 1 }) public quantity: number; /** Final amount before tax */ @Column({ dataType: "Decimal", default: () => 0 }) public amount: number; /** * Price of the item, copied from itemPrice */ @Column({ dataType: "Decimal", default: () => 0 }) public taxes: number; @Column({ dataType: "Decimal", default: () => 0 }) public total: number; @Column({ dataType: "Boolean", default: () => false }) public inclusive: boolean; @Column({ dataType: "Char", length: 50, nullable: true, enum: itemTypeArray }) public itemType: itemTypeArrayType; @Column({ dataType: "Boolean", default: () => false }) public hide: boolean; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreAccount, { property: (x) => x.vendor, inverseProperty: (x) => x.soldItems }) public vendorID: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreJournalLineItem, { property: (x) => x.source, inverseProperty: (x) => x.relatedItems }) public sourceID: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(StoreJournalLineItem, { property: (x) => x.taxFor, inverseProperty: (x) => x.taxLineItems }) public taxForID: number; journal: StoreJournal; vendor: StoreAccount; item: StoreItem; itemPrice: StoreItemPrice; taxFor: StoreJournalLineItem; source: StoreJournalLineItem; relatedItems: StoreJournalLineItem[]; entries: StoreJournalEntry[]; coupons: StoreJournalCoupon[]; taxLineItems: StoreJournalLineItem[]; }