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 Sql from "@entity-access/entity-access/dist/sql/Sql.js"; import DateTime from "@entity-access/entity-access/dist/types/DateTime.js"; import AppFile from "./AppFile.js"; import { StoreJournalEntry } from "./StoreJournalEntry.js"; import { StoreJournalLineItem } from "./StoreJournalLineItem.js"; import type StorePaymentAttempt from "./StorePaymentAttempt.js"; import WebSite from "./WebSite.js"; import { StoreAccount } from "./StoreAccount.js"; import { StoreAccountAddress } from "./StoreAddress.js"; import type StoreJournalCoupon from "./StoreJournalCoupon.js"; import StoreSubscription from "./StoreSubscription.js"; const journalTypeArray = [ "order", "purchase-order", "sales-invoice", "journal", "purchase-bill", "payment"] as const; export type journalTypeArrayType = typeof journalTypeArray[number]; const statusTypeArray = [ "new", "paid", "draft"] as const; export type statusType = typeof statusTypeArray[number]; @Table("StoreJournals") export class StoreJournal { @Column({ dataType: "BigInt", key: true, generated: "identity"}) public journalID: number; @Column({ dataType: "BigInt"}) @RelateTo(WebSite, { property: (x) => x.store, inverseProperty: (x) => x.journals }) public storeID: number; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) dateCreated: DateTime; @Column({ dataType: "DateTime", default: () => Sql.date.now()}) dateUpdated: DateTime; @Column({ dataType: "AsciiChar", length: 50, enum: journalTypeArray }) journalType: journalTypeArrayType; @Column({ dataType: "Char", nullable: true }) description: string; @Column({ dataType: "Boolean", default: () => false }) posted: boolean; @Column({ dataType: "Char", length: 50, default: () => "draft", enum: statusTypeArray }) status: statusType; @Column({ dataType: "BigInt" ,nullable: true }) @RelateTo(StoreAccount, { property: (x) => x.seller, inverseProperty: (x) => x.soldInvoices, foreignKeyConstraint: { name: "FC_Journal_SellerID", onDelete: "restrict" } }) sellerID: number; @Column({ dataType: "BigInt" ,nullable: true }) @RelateTo(StoreAccount, { property: (x) => x.buyer, inverseProperty: (x) => x.boughtInvoices, foreignKeyConstraint: { name: "FC_Journal_BuyerID", onDelete: "restrict" } }) buyerID: number; @Column({ dataType: "BigInt" ,nullable: true }) @RelateTo(StoreAccountAddress, { property: (x) => x.buyerBillingAddress, inverseProperty: (x) => x.billedOrders }) buyerBillingAddressID: number; @Column({ dataType: "BigInt" ,nullable: true }) @RelateTo(StoreAccountAddress, { property: (x) => x.buyerShippingAddress, inverseProperty: (x) => x.shippedOrders }) buyerShippingAddressID: number; @Column({ dataType: "Decimal", default: () => 0}) total: number; @Column({ dataType: "Decimal", default: () => 0}) balance: number; @Column({ dataType: "BigInt", nullable: true }) @RelateTo(StoreJournal, { property: (x) => x.reference, inverseProperty: (x) => x.references }) referenceID: number; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(AppFile, { property: (x) => x.folder, inverseProperty: (x) => x.storeJournals, foreignKeyConstraint: { name: "FK_StoreJournal_FolderID", onDelete: "restrict" } }) folderID: number; @Column({ dataType: "Boolean", default: () => false }) taxExempt: boolean; @Column({ dataType: "Char", nullable: true}) taxExemptNotes: string; @Column({ dataType: "Char", nullable: true}) taxExemptTaxID: string; @Column({ dataType: "Char", length: 200, nullable: true}) invoiceID: string; @Column({ dataType: "BigInt", nullable: true}) @RelateTo(StoreSubscription, { property: (x) => x.subscription, inverseProperty: (x) => x.invoices, foreignKeyConstraint: { name: "FC_StoreJournal_SubscriptionID", onDelete: "restrict" } }) subscriptionID: number; buyer: StoreAccount; seller: StoreAccount; store: WebSite; entries: StoreJournalEntry[]; lineItems: StoreJournalLineItem[]; reference: StoreJournal; references: StoreJournal[]; buyerBillingAddress: StoreAccountAddress; buyerShippingAddress: StoreAccountAddress; folder: AppFile; paymentAttempts: StorePaymentAttempt[]; orderCoupons: StoreJournalCoupon[]; subscription: StoreSubscription; }