@social-mail/social-mail-web-server 1.8.320 → 1.8.322

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/server/model/entities/StoreItem.d.ts +1 -0
  2. package/dist/server/model/entities/StoreItem.d.ts.map +1 -1
  3. package/dist/server/model/entities/StoreItem.js +4 -0
  4. package/dist/server/model/entities/StoreItem.js.map +1 -1
  5. package/dist/server/model/entities/StoreJournal.d.ts +1 -0
  6. package/dist/server/model/entities/StoreJournal.d.ts.map +1 -1
  7. package/dist/server/model/entities/StoreJournal.js +4 -0
  8. package/dist/server/model/entities/StoreJournal.js.map +1 -1
  9. package/dist/server/model/entities/WebSite.d.ts +2 -0
  10. package/dist/server/model/entities/WebSite.d.ts.map +1 -1
  11. package/dist/server/model/entities/WebSite.js +8 -0
  12. package/dist/server/model/entities/WebSite.js.map +1 -1
  13. package/dist/server/model/events/StoreJournalEvents.d.ts +3 -3
  14. package/dist/server/model/events/StoreJournalEvents.d.ts.map +1 -1
  15. package/dist/server/model/events/StoreJournalEvents.js +14 -1
  16. package/dist/server/model/events/StoreJournalEvents.js.map +1 -1
  17. package/dist/server/seed/ui/seed-ui.js +1 -1
  18. package/dist/server/services/accounts/JournalService.d.ts.map +1 -1
  19. package/dist/server/services/accounts/JournalService.js +12 -2
  20. package/dist/server/services/accounts/JournalService.js.map +1 -1
  21. package/dist/server/services/accounts/chart-of-accounts/ChartOfAccounts.d.ts +5 -2
  22. package/dist/server/services/accounts/chart-of-accounts/ChartOfAccounts.d.ts.map +1 -1
  23. package/dist/server/services/accounts/chart-of-accounts/ChartOfAccounts.js +44 -2
  24. package/dist/server/services/accounts/chart-of-accounts/ChartOfAccounts.js.map +1 -1
  25. package/dist/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/src/server/model/entities/StoreItem.ts +3 -0
  28. package/src/server/model/entities/StoreJournal.ts +3 -0
  29. package/src/server/model/entities/WebSite.ts +6 -0
  30. package/src/server/model/events/StoreJournalEvents.ts +17 -1
  31. package/src/server/seed/ui/seed-ui.ts +1 -1
  32. package/src/server/services/accounts/JournalService.ts +13 -2
  33. package/src/server/services/accounts/chart-of-accounts/ChartOfAccounts.ts +52 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@social-mail/social-mail-web-server",
3
- "version": "1.8.320",
3
+ "version": "1.8.322",
4
4
  "description": "## Phase 1",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -111,6 +111,9 @@ export class StoreItem {
111
111
  @ReadOnlyJsonProperty
112
112
  public maxPrice: number;
113
113
 
114
+ @Column({ dataType: "Char", length: 20, nullable: true})
115
+ public taxCode: string;
116
+
114
117
  public store: WebSite;
115
118
 
116
119
  public vendor: StoreAccount;
@@ -126,6 +126,9 @@ export class StoreJournal {
126
126
  @Column({ dataType: "Char", nullable: true})
127
127
  taxExemptTaxID: string;
128
128
 
129
+ @Column({ dataType: "Char", length: 200, nullable: true})
130
+ invoiceID: string;
131
+
129
132
  buyer: StoreAccount;
130
133
  seller: StoreAccount;
131
134
 
@@ -151,6 +151,12 @@ export default class WebSite {
151
151
  @Column({ dataType:"Char", length: 10, default: () => "USD"})
152
152
  public currency: string;
153
153
 
154
+ @Column({ dataType: "Char", length: 16, nullable: true})
155
+ public invoicePrefix: string;
156
+
157
+ @Column({ dataType: "BigInt", default: () => 1})
158
+ public nextInvoiceID: number;
159
+
154
160
  public folder: AppFile;
155
161
 
156
162
  currentVersion: AppFile;
@@ -137,10 +137,26 @@ export default class StoreJournalEvents extends AuthenticatedEvents<StoreJournal
137
137
  return this.updateBalances(entity, entry);
138
138
  }
139
139
 
140
- updateBalances(entity: StoreJournal, entry: ChangeEntry<StoreJournal>) {
140
+ async updateBalances(entity: StoreJournal, entry: ChangeEntry<StoreJournal>) {
141
141
  if (!entity.posted) {
142
142
  return;
143
143
  }
144
+
145
+ if (entity.journalType === "sales-invoice") {
146
+ if (entity.invoiceID) {
147
+ const m = /(?<id>\d+)$/.exec(entity.invoiceID);
148
+ const id = m?.groups["id"];
149
+ if (id) {
150
+ const { storeID } = entity;
151
+ const nextInvoiceID = (BigInt(id) + 1n).toString() as any;
152
+ await this.db.websiteFolders.where({ storeID, nextInvoiceID }, (p) => (x) =>
153
+ x.folderID === p.storeID
154
+ && x.nextInvoiceID < p.nextInvoiceID)
155
+ .update({ nextInvoiceID }, (p) => (x) => ({ nextInvoiceID }));
156
+ }
157
+ }
158
+ }
159
+
144
160
  this.db.queuePostSaveTask(async () => {
145
161
  await entry.loadNavigationAsync((x) => x.entries);
146
162
 
@@ -17,7 +17,7 @@ export default async function seedUI(config: DBConfig) {
17
17
  await config.saveVersion(UIPackageConfig, {
18
18
  package: "@social-mail/social-mail-client",
19
19
  view: "dist/web/AppIndex",
20
- version: "1.9.23"
20
+ version: "1.9.24"
21
21
  });
22
22
 
23
23
  await config.saveVersion(WebComponentsPackageConfig, {
@@ -16,7 +16,18 @@ export default class JournalService {
16
16
 
17
17
  async syncEntries(entry: ChangeEntry<StoreJournal>, entity: StoreJournal) {
18
18
 
19
- const { total } = entity;
19
+ const { total, storeID } = entity;
20
+
21
+ // create an anonymous customer
22
+ // if buyerID is null
23
+ if (!entity.buyerID) {
24
+ const account = await this.chartOfAccounts.ensureAccount({
25
+ storeID,
26
+ name: "Customer",
27
+ head: "Customers"
28
+ });
29
+ entity.buyerID = account.accountID;
30
+ }
20
31
 
21
32
  await this.addEntry({
22
33
  entity,
@@ -33,7 +44,7 @@ export default class JournalService {
33
44
  await ce.loadNavigationAsync((x) => x.item);
34
45
  await ce.loadNavigationAsync((x) => x.itemPrice);
35
46
 
36
- if(!lineItem.source) {
47
+ if(!lineItem.source && !lineItem.taxFor) {
37
48
  await this.addEntry({
38
49
  account: AccountNames.Sales,
39
50
  lineItem,
@@ -1,5 +1,9 @@
1
1
  import Inject, { RegisterTransient } from "@entity-access/entity-access/dist/di/di.js";
2
2
  import SocialMailContext from "../../../model/SocialMailContext.js";
3
+ import EntityAccessError from "@entity-access/entity-access/dist/common/EntityAccessError.js";
4
+ import { randomUUID } from "node:crypto";
5
+ import CryptoService from "../../CryptoService.js";
6
+ import DateTime from "@entity-access/entity-access/dist/types/DateTime.js";
3
7
 
4
8
  @RegisterTransient
5
9
  export default class ChartOfAccounts {
@@ -7,19 +11,65 @@ export default class ChartOfAccounts {
7
11
  @Inject
8
12
  db: SocialMailContext;
9
13
 
10
- async ensureAccount({storeID , name , parentID = null, parentName = null, customerID = null, head = null}) {
14
+ @Inject
15
+ cryptoService: CryptoService;
16
+
17
+ async ensureAccount({storeID , name , parentID = null, parentName = null, userID = null, createUser = true, head = null}) {
18
+
19
+ let path = name;
11
20
 
12
21
  if (parentName) {
13
22
  const parent = await this.ensureAccount({ storeID, name: parentName, head });
14
23
  parentID = parent.accountID;
15
24
  head = parent.head;
25
+ path = `${parentName}/${name}`;
26
+ }
27
+
28
+ const existing = await this.db.storeAccounts.statements.select({}, {
29
+ parentID,
30
+ storeID,
31
+ name,
32
+ path,
33
+ head
34
+ });
35
+
36
+ if (existing) {
37
+ return existing;
38
+ }
39
+
40
+ if (!userID) {
41
+ if (!createUser) {
42
+ throw new EntityAccessError(`UserID not specified to create an account`);
43
+ }
44
+
45
+ // let us create a unique user...
46
+ const password = randomUUID();
47
+
48
+ const { cryptoService } = this;
49
+
50
+ const passwordSalt = cryptoService.generateSalt();
51
+ const passwordHash = cryptoService.hash(passwordSalt, password);
52
+
53
+ const dateCreated = DateTime.now;
54
+
55
+ const user = await this.db.users.statements.insert({
56
+ userName: randomUUID(),
57
+ displayName: `${name} (${storeID})`,
58
+ passwordSalt,
59
+ passwordHash,
60
+ multiFactor: false,
61
+ dateUpdated: dateCreated,
62
+ isExternal: true
63
+ });
64
+ userID = user.userID;
16
65
  }
17
66
 
18
67
  return await this.db.storeAccounts.statements.selectOrInsert({
19
68
  parentID,
20
69
  storeID,
21
70
  name,
22
- accountID: customerID,
71
+ path,
72
+ accountID: userID,
23
73
  head,
24
74
  });
25
75
  }