@mj-biz-apps/orders-ng 5.52.0 → 5.53.0

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 (64) hide show
  1. package/dist/lib/pages/payments/account-credit.page.d.ts +21 -0
  2. package/dist/lib/pages/payments/account-credit.page.d.ts.map +1 -1
  3. package/dist/lib/pages/payments/account-credit.page.js +145 -82
  4. package/dist/lib/pages/payments/account-credit.page.js.map +1 -1
  5. package/dist/lib/pages/receivables/billing-issue.d.ts +14 -0
  6. package/dist/lib/pages/receivables/billing-issue.d.ts.map +1 -0
  7. package/dist/lib/pages/receivables/billing-issue.js +17 -0
  8. package/dist/lib/pages/receivables/billing-issue.js.map +1 -0
  9. package/dist/lib/pages/receivables/billing.page.d.ts +135 -19
  10. package/dist/lib/pages/receivables/billing.page.d.ts.map +1 -1
  11. package/dist/lib/pages/receivables/billing.page.js +748 -163
  12. package/dist/lib/pages/receivables/billing.page.js.map +1 -1
  13. package/dist/lib/pages/receivables/customer-ar.page.d.ts +12 -0
  14. package/dist/lib/pages/receivables/customer-ar.page.d.ts.map +1 -1
  15. package/dist/lib/pages/receivables/customer-ar.page.js +40 -14
  16. package/dist/lib/pages/receivables/customer-ar.page.js.map +1 -1
  17. package/dist/lib/pages/receivables/external-invoicing-queue.page.d.ts +157 -26
  18. package/dist/lib/pages/receivables/external-invoicing-queue.page.d.ts.map +1 -1
  19. package/dist/lib/pages/receivables/external-invoicing-queue.page.js +1278 -316
  20. package/dist/lib/pages/receivables/external-invoicing-queue.page.js.map +1 -1
  21. package/dist/lib/pages/receivables/overdue-page.model.d.ts +55 -0
  22. package/dist/lib/pages/receivables/overdue-page.model.d.ts.map +1 -0
  23. package/dist/lib/pages/receivables/overdue-page.model.js +112 -0
  24. package/dist/lib/pages/receivables/overdue-page.model.js.map +1 -0
  25. package/dist/lib/pages/receivables/overdue.page.d.ts +104 -16
  26. package/dist/lib/pages/receivables/overdue.page.d.ts.map +1 -1
  27. package/dist/lib/pages/receivables/overdue.page.js +476 -125
  28. package/dist/lib/pages/receivables/overdue.page.js.map +1 -1
  29. package/dist/lib/pages/receivables/progress.page.d.ts +69 -8
  30. package/dist/lib/pages/receivables/progress.page.d.ts.map +1 -1
  31. package/dist/lib/pages/receivables/progress.page.js +574 -248
  32. package/dist/lib/pages/receivables/progress.page.js.map +1 -1
  33. package/dist/lib/pages/receivables/worklist-view.model.d.ts +229 -0
  34. package/dist/lib/pages/receivables/worklist-view.model.d.ts.map +1 -0
  35. package/dist/lib/pages/receivables/worklist-view.model.js +402 -0
  36. package/dist/lib/pages/receivables/worklist-view.model.js.map +1 -0
  37. package/dist/lib/panels/aging-bar.component.d.ts +7 -1
  38. package/dist/lib/panels/aging-bar.component.d.ts.map +1 -1
  39. package/dist/lib/panels/aging-bar.component.js +89 -33
  40. package/dist/lib/panels/aging-bar.component.js.map +1 -1
  41. package/dist/lib/panels/side-panel.component.d.ts +41 -0
  42. package/dist/lib/panels/side-panel.component.d.ts.map +1 -0
  43. package/dist/lib/panels/side-panel.component.js +126 -0
  44. package/dist/lib/panels/side-panel.component.js.map +1 -0
  45. package/dist/lib/panels/worklist-bar.component.d.ts +81 -0
  46. package/dist/lib/panels/worklist-bar.component.d.ts.map +1 -0
  47. package/dist/lib/panels/worklist-bar.component.js +291 -0
  48. package/dist/lib/panels/worklist-bar.component.js.map +1 -0
  49. package/dist/lib/panels/worklist-table.component.d.ts +47 -5
  50. package/dist/lib/panels/worklist-table.component.d.ts.map +1 -1
  51. package/dist/lib/panels/worklist-table.component.js +283 -79
  52. package/dist/lib/panels/worklist-table.component.js.map +1 -1
  53. package/dist/lib/sections/orders-sections.component.d.ts.map +1 -1
  54. package/dist/lib/sections/orders-sections.component.js +13 -5
  55. package/dist/lib/sections/orders-sections.component.js.map +1 -1
  56. package/dist/lib/sections/section-nav.model.js +1 -1
  57. package/dist/lib/sections/section-nav.model.js.map +1 -1
  58. package/dist/lib/sections/section-shell.component.js +2 -2
  59. package/dist/lib/styles/orders-kit.css +10 -0
  60. package/dist/public-api.d.ts +2 -0
  61. package/dist/public-api.d.ts.map +1 -1
  62. package/dist/public-api.js +2 -0
  63. package/dist/public-api.js.map +1 -1
  64. package/package.json +2 -2
@@ -2,71 +2,225 @@ import { ChangeDetectorRef, Component, EventEmitter, Output, inject } from '@ang
2
2
  import { CommonModule } from '@angular/common';
3
3
  import { RunView } from '@memberjunction/core';
4
4
  import { MJAlertComponent, MJButtonDirective, MJConfirmService } from '@memberjunction/ng-ui-components';
5
- import { OrdersGetBillingWorklistOperation, OrdersIssueInstalmentInvoiceOperation, } from '@mj-biz-apps/orders-entities';
5
+ import { OrdersGetBillingWorklistOperation, OrdersIssueInstalmentInvoiceOperation, RequireUUID, Today, } from '@mj-biz-apps/orders-entities';
6
+ import { MJOSidePanelComponent } from '../../panels/side-panel.component.js';
6
7
  import { MJOStatTileComponent } from '../../panels/stat-tile.component.js';
8
+ import { MJOWorklistBarComponent } from '../../panels/worklist-bar.component.js';
7
9
  import { MJOWorklistTableComponent } from '../../panels/worklist-table.component.js';
8
10
  import { FormatDate, FormatMoney } from '../../panels/money-format.js';
11
+ import { IssueInvoiceBlockedReason } from './billing-issue.js';
12
+ import { BuildWorklistExport, AddressKey, AdoptCompanyChoice, AdoptWindow, COMPANY_ADDRESS_KEY, CUSTOM_WINDOW, CompaniesToAddress, DaysBetween, ExportFileName, FilterByCompanies, InDayRange, MatchesText, NextSort, ReadWorklistState, ReconcileCompanies, ResolveWindow, RestoreSort, RestoreWindow, SameChoice, SameWindow, ShownSummary, SortRows, WindowToAddress, WriteSharedCompanies, WriteWorklistState, } from './worklist-view.model.js';
9
13
  import * as i0 from "@angular/core";
10
- function MJOBillingPageComponent_Conditional_4_Template(rf, ctx) { if (rf & 1) {
11
- i0.ɵɵelementStart(0, "mj-alert", 4)(1, "strong");
14
+ const _forTrack0 = ($index, $item) => $item.Key;
15
+ function MJOBillingPageComponent_For_6_Template(rf, ctx) { if (rf & 1) {
16
+ i0.ɵɵelementStart(0, "option", 4);
17
+ i0.ɵɵtext(1);
18
+ i0.ɵɵelementEnd();
19
+ } if (rf & 2) {
20
+ const option_r1 = ctx.$implicit;
21
+ const ctx_r1 = i0.ɵɵnextContext();
22
+ i0.ɵɵproperty("value", option_r1.Key)("selected", option_r1.Key === ctx_r1.Window.Key);
23
+ i0.ɵɵadvance();
24
+ i0.ɵɵtextInterpolate(option_r1.Label);
25
+ } }
26
+ function MJOBillingPageComponent_Conditional_7_Template(rf, ctx) { if (rf & 1) {
27
+ const _r3 = i0.ɵɵgetCurrentView();
28
+ i0.ɵɵelementStart(0, "label", 1)(1, "span", 2);
29
+ i0.ɵɵtext(2, "From");
30
+ i0.ɵɵelementEnd();
31
+ i0.ɵɵelementStart(3, "input", 19);
32
+ i0.ɵɵlistener("change", function MJOBillingPageComponent_Conditional_7_Template_input_change_3_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnCustomDay("From", $event.target.value)); });
33
+ i0.ɵɵelementEnd()();
34
+ i0.ɵɵelementStart(4, "label", 1)(5, "span", 2);
35
+ i0.ɵɵtext(6, "To");
36
+ i0.ɵɵelementEnd();
37
+ i0.ɵɵelementStart(7, "input", 20);
38
+ i0.ɵɵlistener("change", function MJOBillingPageComponent_Conditional_7_Template_input_change_7_listener($event) { i0.ɵɵrestoreView(_r3); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnCustomDay("To", $event.target.value)); });
39
+ i0.ɵɵelementEnd()();
40
+ } if (rf & 2) {
41
+ const ctx_r1 = i0.ɵɵnextContext();
42
+ i0.ɵɵadvance(3);
43
+ i0.ɵɵproperty("value", ctx_r1.Window.From ?? "");
44
+ i0.ɵɵadvance(4);
45
+ i0.ɵɵproperty("value", ctx_r1.Window.To ?? "");
46
+ } }
47
+ function MJOBillingPageComponent_Conditional_12_Template(rf, ctx) { if (rf & 1) {
48
+ i0.ɵɵelementStart(0, "mj-alert", 9)(1, "strong");
12
49
  i0.ɵɵtext(2, "The billing worklist did not load.");
13
50
  i0.ɵɵelementEnd();
14
51
  i0.ɵɵtext(3);
15
52
  i0.ɵɵelementEnd();
16
53
  } if (rf & 2) {
17
- const ctx_r0 = i0.ɵɵnextContext();
54
+ const ctx_r1 = i0.ɵɵnextContext();
18
55
  i0.ɵɵadvance(3);
19
- i0.ɵɵtextInterpolate1(" ", ctx_r0.LoadError, " ");
56
+ i0.ɵɵtextInterpolate1(" ", ctx_r1.LoadError, " ");
20
57
  } }
21
- function MJOBillingPageComponent_Conditional_5_Template(rf, ctx) { if (rf & 1) {
22
- i0.ɵɵelementStart(0, "mj-alert", 5);
58
+ function MJOBillingPageComponent_Conditional_13_Template(rf, ctx) { if (rf & 1) {
59
+ i0.ɵɵelementStart(0, "mj-alert", 10);
23
60
  i0.ɵɵtext(1);
24
61
  i0.ɵɵelementEnd();
25
62
  } if (rf & 2) {
26
- const ctx_r0 = i0.ɵɵnextContext();
27
- i0.ɵɵproperty("Variant", ctx_r0.Notice.Tone);
63
+ const ctx_r1 = i0.ɵɵnextContext();
64
+ i0.ɵɵproperty("Variant", ctx_r1.Notice.Tone);
28
65
  i0.ɵɵadvance();
29
- i0.ɵɵtextInterpolate1(" ", ctx_r0.Notice.Text, " ");
66
+ i0.ɵɵtextInterpolate1(" ", ctx_r1.Notice.Text, " ");
30
67
  } }
31
- function MJOBillingPageComponent_Conditional_6_Template(rf, ctx) { if (rf & 1) {
32
- i0.ɵɵelementStart(0, "mj-alert", 6)(1, "strong");
68
+ function MJOBillingPageComponent_Conditional_14_Template(rf, ctx) { if (rf & 1) {
69
+ i0.ɵɵelementStart(0, "mj-alert", 11)(1, "strong");
33
70
  i0.ɵɵtext(2, "List truncated.");
34
71
  i0.ɵɵelementEnd();
35
- i0.ɵɵtext(3, " Not every due installment is shown. ");
72
+ i0.ɵɵtext(3, " Not every installment in these dates is shown, and the figures above cover only those that are. ");
36
73
  i0.ɵɵelementEnd();
37
74
  } }
38
- function MJOBillingPageComponent_Conditional_14_Template(rf, ctx) { if (rf & 1) {
39
- i0.ɵɵelementStart(0, "span", 12);
75
+ function MJOBillingPageComponent_Conditional_24_Conditional_22_Template(rf, ctx) { if (rf & 1) {
76
+ i0.ɵɵelementStart(0, "dt");
77
+ i0.ɵɵtext(1, "For");
78
+ i0.ɵɵelementEnd();
79
+ i0.ɵɵelementStart(2, "dd");
80
+ i0.ɵɵtext(3);
81
+ i0.ɵɵelementEnd();
82
+ } if (rf & 2) {
83
+ const row_r5 = i0.ɵɵnextContext();
84
+ i0.ɵɵadvance(3);
85
+ i0.ɵɵtextInterpolate(row_r5.Description);
86
+ } }
87
+ function MJOBillingPageComponent_Conditional_24_Conditional_34_Template(rf, ctx) { if (rf & 1) {
88
+ i0.ɵɵelementStart(0, "p", 29);
40
89
  i0.ɵɵtext(1);
41
90
  i0.ɵɵelementEnd();
42
91
  } if (rf & 2) {
43
- const row_r2 = ctx;
44
- const ctx_r0 = i0.ɵɵnextContext();
45
92
  i0.ɵɵadvance();
46
- i0.ɵɵtextInterpolate4("", row_r2.OrderNumber, " \u00B7 installment ", row_r2.InstallmentNumber, " of ", row_r2.InstallmentCount, " \u00B7 ", ctx_r0.money(row_r2.Amount));
93
+ i0.ɵɵtextInterpolate(ctx);
47
94
  } }
48
- /** How far ahead the worklist looks. Finance's renewal lead is 90 days; a month is the working view. */
49
- const WINDOW_DAYS = 30;
95
+ function MJOBillingPageComponent_Conditional_24_Template(rf, ctx) { if (rf & 1) {
96
+ const _r4 = i0.ɵɵgetCurrentView();
97
+ i0.ɵɵelementStart(0, "div", 18)(1, "mjo-side-panel", 21);
98
+ i0.ɵɵlistener("Closed", function MJOBillingPageComponent_Conditional_24_Template_mjo_side_panel_Closed_1_listener() { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.Selected = null); });
99
+ i0.ɵɵelementStart(2, "div", 22);
100
+ i0.ɵɵtext(3);
101
+ i0.ɵɵelementEnd();
102
+ i0.ɵɵelementStart(4, "dl", 23)(5, "dt");
103
+ i0.ɵɵtext(6, "Customer");
104
+ i0.ɵɵelementEnd();
105
+ i0.ɵɵelementStart(7, "dd");
106
+ i0.ɵɵtext(8);
107
+ i0.ɵɵelementEnd();
108
+ i0.ɵɵelementStart(9, "dt");
109
+ i0.ɵɵtext(10, "Order");
110
+ i0.ɵɵelementEnd();
111
+ i0.ɵɵelementStart(11, "dd")(12, "button", 24);
112
+ i0.ɵɵlistener("click", function MJOBillingPageComponent_Conditional_24_Template_button_click_12_listener() { const row_r5 = i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OpenOrder(row_r5)); });
113
+ i0.ɵɵtext(13);
114
+ i0.ɵɵelementEnd()();
115
+ i0.ɵɵelementStart(14, "dt");
116
+ i0.ɵɵtext(15, "Due");
117
+ i0.ɵɵelementEnd();
118
+ i0.ɵɵelementStart(16, "dd");
119
+ i0.ɵɵtext(17);
120
+ i0.ɵɵelementEnd();
121
+ i0.ɵɵelementStart(18, "dt");
122
+ i0.ɵɵtext(19, "Billed by");
123
+ i0.ɵɵelementEnd();
124
+ i0.ɵɵelementStart(20, "dd");
125
+ i0.ɵɵtext(21);
126
+ i0.ɵɵelementEnd();
127
+ i0.ɵɵconditionalCreate(22, MJOBillingPageComponent_Conditional_24_Conditional_22_Template, 4, 1);
128
+ i0.ɵɵelementStart(23, "dt");
129
+ i0.ɵɵtext(24, "After issuing");
130
+ i0.ɵɵelementEnd();
131
+ i0.ɵɵelementStart(25, "dd");
132
+ i0.ɵɵtext(26);
133
+ i0.ɵɵelementEnd()();
134
+ i0.ɵɵelementStart(27, "div", 25)(28, "button", 26);
135
+ i0.ɵɵlistener("click", function MJOBillingPageComponent_Conditional_24_Template_button_click_28_listener() { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.IssueSelected()); });
136
+ i0.ɵɵelement(29, "i", 16);
137
+ i0.ɵɵtext(30);
138
+ i0.ɵɵelementEnd();
139
+ i0.ɵɵelementStart(31, "button", 27);
140
+ i0.ɵɵlistener("click", function MJOBillingPageComponent_Conditional_24_Template_button_click_31_listener() { const row_r5 = i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OpenOrder(row_r5)); });
141
+ i0.ɵɵelement(32, "i", 28);
142
+ i0.ɵɵtext(33, " Open order ");
143
+ i0.ɵɵelementEnd()();
144
+ i0.ɵɵconditionalCreate(34, MJOBillingPageComponent_Conditional_24_Conditional_34_Template, 2, 1, "p", 29);
145
+ i0.ɵɵelementEnd()();
146
+ } if (rf & 2) {
147
+ let tmp_14_0;
148
+ const row_r5 = ctx;
149
+ const ctx_r1 = i0.ɵɵnextContext();
150
+ i0.ɵɵadvance();
151
+ i0.ɵɵproperty("Title", row_r5.OrderNumber + " \u00B7 installment " + row_r5.InstallmentNumber + " of " + row_r5.InstallmentCount)("Chip", row_r5.OrderStatus)("ChipClass", row_r5.OrderStatus === "Confirmed" ? "mjo-chip--success" : "mjo-chip--outline");
152
+ i0.ɵɵadvance(2);
153
+ i0.ɵɵtextInterpolate(ctx_r1.money(row_r5.Amount));
154
+ i0.ɵɵadvance(5);
155
+ i0.ɵɵtextInterpolate(row_r5.CustomerName);
156
+ i0.ɵɵadvance(5);
157
+ i0.ɵɵtextInterpolate(row_r5.OrderNumber);
158
+ i0.ɵɵadvance(4);
159
+ i0.ɵɵtextInterpolate2("", ctx_r1.date(row_r5.DueDate), " \u00B7 ", ctx_r1.dueNote(row_r5));
160
+ i0.ɵɵadvance(4);
161
+ i0.ɵɵtextInterpolate(row_r5.CompanyName || "\u2014");
162
+ i0.ɵɵadvance();
163
+ i0.ɵɵconditional(row_r5.Description ? 22 : -1);
164
+ i0.ɵɵadvance(4);
165
+ i0.ɵɵtextInterpolate(ctx_r1.RailFor(row_r5.CompanyID) ? "Sent automatically through " + ctx_r1.RailFor(row_r5.CompanyID) : "Not sent automatically");
166
+ i0.ɵɵadvance(2);
167
+ i0.ɵɵproperty("disabled", ctx_r1.Issuing || !!ctx_r1.IssueBlockedReason);
168
+ i0.ɵɵadvance(2);
169
+ i0.ɵɵtextInterpolate1(" ", ctx_r1.Issuing ? "Issuing\u2026" : "Issue invoice", " ");
170
+ i0.ɵɵadvance(4);
171
+ i0.ɵɵconditional((tmp_14_0 = ctx_r1.IssueBlockedReason) ? 34 : -1, tmp_14_0);
172
+ } }
173
+ /**
174
+ * How far ahead the worklist can look. Every choice but the custom one also lists what is already
175
+ * past due: an installment nobody invoiced does not stop needing an invoice because its date passed.
176
+ */
177
+ export const BILLING_WINDOWS = [
178
+ { Key: '7', Label: 'Next 7 days', FromOffset: null, ToOffset: 7 },
179
+ { Key: '30', Label: 'Next 30 days', FromOffset: null, ToOffset: 30 },
180
+ { Key: '60', Label: 'Next 60 days', FromOffset: null, ToOffset: 60 },
181
+ { Key: '90', Label: 'Next 90 days', FromOffset: null, ToOffset: 90 },
182
+ { Key: '365', Label: 'Next 12 months', FromOffset: null, ToOffset: 365 },
183
+ { Key: 'all', Label: 'All dates', FromOffset: null, ToOffset: null },
184
+ { Key: CUSTOM_WINDOW, Label: 'Custom dates…', FromOffset: null, ToOffset: null },
185
+ ];
186
+ /** The page opens on a month: the working view for invoicing. Longer windows are a choice. */
187
+ const DEFAULT_WINDOW = { Key: '30', From: null, To: null };
188
+ /** What the operation is asked for when the window has no end: far enough ahead to reach every schedule. */
189
+ const ALL_DAYS = 36_500;
190
+ /** The operation lists 500 rows unless told otherwise; a window past a quarter, or one with a first day, asks for room. */
191
+ const WIDE_WINDOW_MAX_ROWS = 5_000;
192
+ const BILLING_STATE_KEY = 'mjOrders.billingWorklist.view';
193
+ /** The tab-address key for this page's window. */
194
+ const DUE_ADDRESS_KEY = 'billingDue';
50
195
  const PAYMENT_PROVIDER_ENTITY = 'MJ_BizApps_Orders: Payment Providers';
51
196
  const PAYMENT_PROVIDER_TYPE_ENTITY = 'MJ_BizApps_Orders: Payment Provider Types';
52
197
  /** Provider type codes that invoice through an external rail. Mirrors `INVOICE_RAIL_TYPE_CODES`. */
53
198
  const RAIL_TYPE_CODES = ['BillCom'];
199
+ const PRESET_LABELS = { all: 'All', pastdue: 'Past due', week: 'Next 7 days' };
54
200
  /**
55
201
  * `mjo-billing-page` — instalments due with no invoice behind them (AIDP-24, plan §6.3).
56
202
  *
57
203
  * THE CONTROL FINANCE RUNS BY HAND TODAY. A multi-year contract billed in instalments has rows due
58
204
  * in 2027 and 2029 that nobody will remember. This screen is where they surface on their own: every
59
- * `Scheduled` instalment whose due date is inside the window, earliest first, with the act that
205
+ * `Scheduled` instalment of a confirmed order whose due date is inside the window, earliest first, with the act that
60
206
  * turns it into a receivable document one confirmation away.
61
207
  *
208
+ * ONE ROW OPENS BESIDE THE LIST; SEVERAL ARE TICKED. Clicking an installment shows its facts and its
209
+ * Issue button in a panel next to the table. Ticking rows issues them together, one confirmation
210
+ * for the batch, each installment issued on its own so one refusal does not stop the rest.
211
+ *
62
212
  * ISSUING IS THE IRREVERSIBLE STEP, so it asks first — through `MJConfirmService`, never
63
213
  * `window.confirm`, which throws under the Electron host. Once issued the number is frozen on the
64
214
  * row and the row leaves this list.
65
215
  *
216
+ * THE COMPANY CHOICE IS SHARED with the other Receivables pages, and it and the window are kept in
217
+ * the tab's address through the section (`AddressChanged` / `ApplyAddress`) and follow Back and
218
+ * Forward. A link carries them too, but opens on the Receivables page its reader last used.
219
+ *
66
220
  * ## Example
67
221
  *
68
222
  * ```html
69
- * <mjo-billing-page (OrderOpened)="open($event)" />
223
+ * <mjo-billing-page (OrderOpened)="open($event)" (AddressChanged)="write($event)" />
70
224
  * ```
71
225
  */
72
226
  export class MJOBillingPageComponent {
@@ -74,83 +228,256 @@ export class MJOBillingPageComponent {
74
228
  cdr = inject(ChangeDetectorRef);
75
229
  confirm = inject(MJConfirmService);
76
230
  OrderOpened = new EventEmitter();
77
- WindowDays = WINDOW_DAYS;
231
+ /** The company choice or the window changed: the section writes it to the tab's address. A null value removes the key. */
232
+ AddressChanged = new EventEmitter();
78
233
  String = String;
234
+ Windows = BILLING_WINDOWS;
79
235
  LoadError = null;
80
236
  Notice = null;
81
237
  Truncated = false;
82
238
  Issuing = false;
239
+ /** "Issuing 3 of 12…" while a batch runs. */
240
+ IssueProgress = null;
241
+ Loading = false;
242
+ /** Every installment the operation returned that is due in the window. */
83
243
  AllRows = [];
244
+ /** `AllRows` under the company filter and the search. The tiles count these. */
245
+ Scoped = [];
246
+ /** `Scoped` under the quick filter, in the sorted order. What the table lists and the export writes. */
84
247
  Rows = [];
248
+ /** The installment open in the side panel. */
85
249
  Selected = null;
250
+ /** The ticked installments' schedule IDs; always rows that are listed. */
251
+ CheckedIDs = [];
252
+ Companies = [];
253
+ /** The chosen companies that are offered: what the filter shows. */
254
+ CompanyPicks = [];
255
+ /** The company choice as chosen, shared across Receivables. `CompanyPicks` is this, less any company never seen with rows. */
256
+ companyChoice = [];
257
+ Search = '';
86
258
  Preset = 'all';
87
- /** Company ID (lower-cased) -> the name of its active invoice rail, for the "Then sends via" column. */
259
+ Window = DEFAULT_WINDOW;
260
+ /** The column the list is sorted on; a null key is the list's own order, earliest due first. */
261
+ Sort = { Key: null, Descending: false };
262
+ /** Company ID (lower-cased) -> the name of its active invoice rail. */
88
263
  Rails = new Map();
89
264
  AsOf = '';
90
- WindowEnd = '';
265
+ /** The days the loaded rows cover. Kept from the load so the tiles describe what is on screen, not a choice still loading. */
266
+ loadedRange = { From: null, To: null };
267
+ loadedWindowKey = DEFAULT_WINDOW.Key;
268
+ /** Counts loads, so a slow answer to an earlier window cannot overwrite a later one. */
269
+ loadSeq = 0;
270
+ /** The tab's address as the section last gave it. */
271
+ address = {};
272
+ companyKey = new AddressKey(COMPANY_ADDRESS_KEY);
273
+ dueKey = new AddressKey(DUE_ADDRESS_KEY);
274
+ /** The first load has finished, so an address that arrives now is a change to follow. */
275
+ ready = false;
276
+ /** Past-due and next-7-days figures for the tiles. Fields, rebuilt with the rows. */
277
+ PastDue = { Count: 0, Amount: 0 };
278
+ Week = { Count: 0, Amount: 0 };
279
+ /** The totals row. A field: a getter would hand the table a new object on every pass. */
280
+ Totals = null;
91
281
  Columns = [
92
- { Key: 'DueDate', Label: 'Due', Kind: 'date', Width: '110px', Format: (r) => FormatDate(r.DueDate, { Short: true }), Secondary: (r) => this.dueNote(r) },
93
- { Key: 'OrderNumber', Label: 'Order', Kind: 'mono', Width: '120px', Secondary: (r) => `${r.InstallmentNumber} of ${r.InstallmentCount}` },
94
- { Key: 'CustomerName', Label: 'Customer' },
95
- { Key: 'CompanyName', Label: 'Billed by', HideBelow: 1000 },
96
- { Key: 'Description', Label: 'For', HideBelow: 760 },
97
- { Key: 'Amount', Label: 'Amount', Kind: 'money', Width: '120px', Format: (r) => FormatMoney(r.Amount) },
98
- { Key: 'OrderStatus', Label: 'Order', Kind: 'chip', Width: '110px', HideBelow: 560, ChipClass: (r) => (r.OrderStatus === 'Confirmed' ? 'mjo-chip--success' : 'mjo-chip--outline') },
282
+ { Key: 'DueDate', Label: 'Due', Kind: 'date', Width: '120px', Sortable: true, Format: (r) => this.date(r.DueDate), Secondary: (r) => this.dueNote(r) },
283
+ { Key: 'OrderNumber', Label: 'Order', Kind: 'link', LinkHint: 'Open the order', Width: '130px', Sortable: true, Secondary: (r) => `${r.InstallmentNumber} of ${r.InstallmentCount}` },
284
+ { Key: 'CustomerName', Label: 'Customer', Sortable: true },
285
+ { Key: 'CompanyName', Label: 'Billed by', HideBelow: 1000, Sortable: true },
286
+ { Key: 'Description', Label: 'For', HideBelow: 760, Sortable: true },
287
+ { Key: 'Amount', Label: 'Amount', Kind: 'money', Width: '120px', Sortable: true, Format: (r) => FormatMoney(r.Amount) },
288
+ { Key: 'OrderStatus', Label: 'Order status', Kind: 'chip', Width: '130px', HideBelow: 560, Sortable: true, ChipClass: (r) => (r.OrderStatus === 'Confirmed' ? 'mjo-chip--success' : 'mjo-chip--outline') },
99
289
  {
100
290
  // Issuing an instalment freezes its number; for a company on a rail it ALSO queues an
101
291
  // external invoice, which is the part nobody could see from this screen.
102
292
  Key: 'CompanyID',
103
- Label: 'Then sends via',
293
+ Label: 'Sent through',
104
294
  Width: '150px',
105
295
  HideBelow: 1000,
296
+ Sortable: true,
297
+ SortValue: (r) => this.RailFor(r.CompanyID),
106
298
  Format: (r) => this.RailFor(r.CompanyID) ?? '—',
107
299
  Secondary: (r) => (this.RailFor(r.CompanyID) ? 'automatically, after issuing' : null),
108
300
  },
109
301
  ];
302
+ /** Only an installment that can be issued can be ticked. A field, so the table gets the same function every pass. */
303
+ CanTick = (row) => IssueInvoiceBlockedReason(row) === null;
304
+ TickLabel = (row) => `Select ${row.OrderNumber} installment ${row.InstallmentNumber} for ${row.CustomerName}`;
305
+ /** The export's columns: one value a cell, so nothing a spreadsheet filters on is folded into another. */
306
+ exportFields = [
307
+ { Name: 'DueDate', Label: 'Due date', Type: 'date', Value: (r) => r.DueDate },
308
+ { Name: 'DaysUntilDue', Label: 'Days until due', Type: 'number', Value: (r) => r.DaysUntilDue },
309
+ { Name: 'OrderNumber', Label: 'Order', Value: (r) => r.OrderNumber },
310
+ { Name: 'InstallmentNumber', Label: 'Installment', Type: 'number', Value: (r) => r.InstallmentNumber },
311
+ { Name: 'InstallmentCount', Label: 'Installments on order', Type: 'number', Value: (r) => r.InstallmentCount },
312
+ { Name: 'CustomerName', Label: 'Customer', Value: (r) => r.CustomerName },
313
+ { Name: 'CompanyName', Label: 'Billed by', Value: (r) => r.CompanyName },
314
+ { Name: 'Description', Label: 'For', Value: (r) => r.Description },
315
+ { Name: 'Amount', Label: 'Amount', Type: 'money', Value: (r) => r.Amount },
316
+ { Name: 'OrderStatus', Label: 'Order status', Value: (r) => r.OrderStatus },
317
+ { Name: 'SentThrough', Label: 'Sent through', Value: (r) => this.RailFor(r.CompanyID) },
318
+ ];
319
+ /** The rows listed, as an export file. A field, so the bar is handed the same function every pass. */
320
+ BuildExport = (format) => ({
321
+ FileName: ExportFileName('billing-worklist', this.CompanyPicks, this.Companies, this.AsOf || null),
322
+ ...BuildWorklistExport(this.exportFields, this.Rows, format),
323
+ });
324
+ async ngOnInit() {
325
+ const saved = ReadWorklistState(globalThis.localStorage, BILLING_STATE_KEY);
326
+ if (saved) {
327
+ this.Window = RestoreWindow(saved.Window, BILLING_WINDOWS, DEFAULT_WINDOW);
328
+ this.Sort = RestoreSort(saved.Sort, this.Columns);
329
+ }
330
+ this.adoptAddress();
331
+ await this.load();
332
+ // An address that arrived while that first load was out was kept, not followed. Follow it now.
333
+ if (this.adoptAddress())
334
+ await this.load();
335
+ else
336
+ this.applyView();
337
+ this.ready = true;
338
+ this.cdr.detectChanges();
339
+ }
110
340
  /**
111
- * A FIELD, rebuilt when the rows change — not a getter. A getter returning a fresh array is a
112
- * new input reference on every change-detection pass, which dev mode reports as NG0100 and
113
- * which re-renders the chip row for nothing.
341
+ * The tab's address, from the section: when the page is shown, and on Back, Forward or a link.
342
+ * `company` is the company choice every Receivables page shares; `billingDue` is this page's window.
114
343
  */
115
- Presets = [];
116
- async ngOnInit() {
344
+ ApplyAddress(params) {
345
+ this.address = params;
346
+ if (!this.ready)
347
+ return;
348
+ const windowChanged = this.adoptAddress();
349
+ if (windowChanged)
350
+ void this.reload();
351
+ else
352
+ this.applyView();
353
+ // Back, Forward and links arrive outside any event of this page's own, so nothing else repaints it.
354
+ this.cdr.detectChanges();
355
+ }
356
+ /** Shown again after another page: an installment issued or an order confirmed there changes this list. */
357
+ async OnShown() {
358
+ if (!this.ready)
359
+ return;
117
360
  await this.load();
118
361
  this.cdr.detectChanges();
119
362
  }
120
363
  /* ── Tiles ──────────────────────────────────────────────────────────── */
121
364
  get TotalDisplay() {
122
- return FormatMoney(this.AllRows.reduce((s, r) => s + r.Amount, 0), { Round: true });
365
+ return FormatMoney(this.Scoped.reduce((s, r) => s + r.Amount, 0), { Round: true });
123
366
  }
124
367
  get TotalDetail() {
125
- const orders = new Set(this.AllRows.map((r) => r.OrderHeaderID)).size;
126
- return `${this.AllRows.length} installment${this.AllRows.length === 1 ? '' : 's'} across ${orders} order${orders === 1 ? '' : 's'}`;
368
+ const orders = new Set(this.Scoped.map((r) => r.OrderHeaderID)).size;
369
+ return `${this.Scoped.length} installment${this.Scoped.length === 1 ? '' : 's'} across ${orders} order${orders === 1 ? '' : 's'}`;
370
+ }
371
+ /** The first tile's heading, which names the window the total is for. */
372
+ get TotalLabel() {
373
+ const option = BILLING_WINDOWS.find((o) => o.Key === this.loadedWindowKey);
374
+ if (this.loadedWindowKey === CUSTOM_WINDOW)
375
+ return `To invoice, ${this.rangeText}`;
376
+ if (!option || option.ToOffset == null)
377
+ return 'To invoice, all dates';
378
+ return `To invoice in the ${option.Label.toLowerCase()}`;
379
+ }
380
+ get rangeText() {
381
+ const { From, To } = this.loadedRange;
382
+ if (!From && !To)
383
+ return 'all dates';
384
+ if (!From)
385
+ return `through ${this.date(To)}`;
386
+ if (!To)
387
+ return `from ${this.date(From)}`;
388
+ return `${this.date(From)} to ${this.date(To)}`;
389
+ }
390
+ get PresetLabel() {
391
+ return PRESET_LABELS[this.Preset];
392
+ }
393
+ get IsCustomWindow() {
394
+ return this.Window.Key === CUSTOM_WINDOW;
395
+ }
396
+ /** "12 of 40 installments shown", beside the filters. */
397
+ get Summary() {
398
+ return this.LoadError || (this.Loading && !this.AllRows.length) ? '' : ShownSummary(this.Rows.length, this.AllRows.length, 'installment');
127
399
  }
128
- get PastDueCount() {
129
- return this.AllRows.filter((r) => r.DaysUntilDue < 0).length;
400
+ /** What is ticked, in words, beside the Issue invoices button. */
401
+ get CheckedSummary() {
402
+ const ticked = this.checkedRows();
403
+ return `${ticked.length} ticked · ${FormatMoney(ticked.reduce((s, r) => s + r.Amount, 0))}`;
130
404
  }
131
- get WindowDisplay() {
132
- return this.AsOf ? `${FormatDate(this.AsOf, { Short: true })} – ${FormatDate(this.WindowEnd, { Short: true })}` : '—';
405
+ get filtered() {
406
+ return this.Rows.length < this.AllRows.length;
407
+ }
408
+ get EmptyTitle() {
409
+ return this.AllRows.length && this.filtered ? 'Nothing matches' : 'Nothing to invoice';
410
+ }
411
+ get EmptyHint() {
412
+ return this.AllRows.length && this.filtered ? 'No installment matches these filters. Clear one to see more.' : 'No scheduled installment is due in these dates.';
133
413
  }
134
414
  /** The rail a company invoices through, or null. Read from seeded metadata once per load. */
135
415
  RailFor(companyID) {
136
416
  return this.Rails.get((companyID ?? '').toLowerCase()) ?? null;
137
417
  }
138
- /* ── Actions ────────────────────────────────────────────────────────── */
418
+ /* ── Filters ────────────────────────────────────────────────────────── */
419
+ /** A tile turns its quick filter on; the same tile again, the first tile, or the chip's ✕ turns it off. */
139
420
  OnPreset(preset) {
140
- this.Preset = preset;
141
- this.applyPreset();
421
+ this.Preset = this.Preset === preset ? 'all' : preset;
422
+ this.applyView();
423
+ }
424
+ OnCompanies(picks) {
425
+ this.companyChoice = picks;
426
+ WriteSharedCompanies(globalThis.localStorage, picks);
427
+ this.AddressChanged.emit(this.companyKey.Write(CompaniesToAddress(picks)));
428
+ this.applyView();
429
+ }
430
+ OnSearch(text) {
431
+ this.Search = text;
432
+ this.applyView();
433
+ }
434
+ OnSort(key) {
435
+ this.Sort = NextSort(this.Sort, key, this.Columns);
436
+ WriteWorklistState(globalThis.localStorage, BILLING_STATE_KEY, { Window: this.Window, Sort: this.Sort });
437
+ this.applyView();
438
+ }
439
+ /** A new window is a new question for the server, so it reloads. Custom waits for a day to be entered. */
440
+ async OnWindow(key) {
441
+ if (!BILLING_WINDOWS.some((o) => o.Key === key) || key === this.Window.Key)
442
+ return;
443
+ this.Window = { Key: key, From: null, To: null };
444
+ if (key === CUSTOM_WINDOW)
445
+ return;
446
+ this.saveView();
447
+ await this.load();
448
+ this.cdr.detectChanges();
449
+ }
450
+ async OnCustomDay(side, day) {
451
+ this.Window = { ...this.Window, Key: CUSTOM_WINDOW, [side]: day || null };
452
+ this.saveView();
453
+ await this.load();
454
+ this.cdr.detectChanges();
455
+ }
456
+ async Refresh() {
457
+ this.Notice = null;
458
+ await this.load();
459
+ this.cdr.detectChanges();
142
460
  }
143
- OpenSelected() {
144
- if (this.Selected)
145
- this.OrderOpened.emit({ ID: this.Selected.OrderHeaderID });
461
+ /* ── Rows ───────────────────────────────────────────────────────────── */
462
+ /** Clicking a row opens it beside the list; clicking the open row closes it. */
463
+ OnRow(row) {
464
+ this.Selected = this.Selected?.OrderHeaderPaymentScheduleID === row.OrderHeaderPaymentScheduleID ? null : row;
146
465
  }
466
+ OpenOrder(row) {
467
+ this.OrderOpened.emit({ ID: row.OrderHeaderID });
468
+ }
469
+ /** Why the open instalment cannot be issued, or null when it can. */
470
+ get IssueBlockedReason() {
471
+ return IssueInvoiceBlockedReason(this.Selected);
472
+ }
473
+ /* ── Issuing ────────────────────────────────────────────────────────── */
147
474
  async IssueSelected() {
148
475
  const row = this.Selected;
149
- if (!row || this.Issuing)
476
+ if (!row || this.Issuing || this.IssueBlockedReason)
150
477
  return;
151
478
  const proceed = await this.confirm.Confirm({
152
479
  title: `Issue installment ${row.InstallmentNumber} of ${row.InstallmentCount}?`,
153
- message: `${row.OrderNumber} · ${row.CustomerName} · ${FormatMoney(row.Amount)} due ${FormatDate(row.DueDate, { Short: true })}.`,
480
+ message: `${row.OrderNumber} · ${row.CustomerName} · ${FormatMoney(row.Amount)} due ${this.date(row.DueDate)}.`,
154
481
  detail: 'The invoice number is frozen on the installment and cannot be changed afterwards. Corrections go through a credit memo.',
155
482
  type: 'warning',
156
483
  confirmText: 'Issue invoice',
@@ -162,13 +489,10 @@ export class MJOBillingPageComponent {
162
489
  this.Notice = null;
163
490
  this.cdr.detectChanges();
164
491
  try {
165
- const result = await new OrdersIssueInstalmentInvoiceOperation().Execute({ OrderHeaderPaymentScheduleID: row.OrderHeaderPaymentScheduleID });
166
- const output = result.Output;
167
- if (!result.Success || !output?.Success) {
168
- this.Notice = { Tone: 'error', Text: output?.Message?.trim() || result.ErrorMessage?.trim() || 'The installment could not be issued.' };
492
+ const outcome = await this.issue(row);
493
+ this.Notice = outcome.Ok ? { Tone: 'success', Text: outcome.Text } : { Tone: 'error', Text: outcome.Text };
494
+ if (!outcome.Ok)
169
495
  return;
170
- }
171
- this.Notice = { Tone: 'success', Text: output.Message ?? `Issued as ${output.DocumentNumber}.` };
172
496
  this.Selected = null;
173
497
  await this.load();
174
498
  }
@@ -177,28 +501,128 @@ export class MJOBillingPageComponent {
177
501
  this.cdr.detectChanges();
178
502
  }
179
503
  }
504
+ /**
505
+ * Issue every ticked installment, after one confirmation for the batch. Each is issued on its
506
+ * own, in the order listed, so one the server refuses does not stop the rest; the notice says how
507
+ * many were issued and names each that was not, with the server's reason.
508
+ */
509
+ async IssueChecked() {
510
+ const rows = this.checkedRows();
511
+ if (!rows.length || this.Issuing)
512
+ return;
513
+ const total = rows.reduce((s, r) => s + r.Amount, 0);
514
+ const orders = new Set(rows.map((r) => r.OrderHeaderID)).size;
515
+ const onRail = rows.filter((r) => this.RailFor(r.CompanyID)).length;
516
+ const proceed = await this.confirm.Confirm({
517
+ title: `Issue ${rows.length} invoice${rows.length === 1 ? '' : 's'}?`,
518
+ message: `${FormatMoney(total)} across ${orders} order${orders === 1 ? '' : 's'}.`,
519
+ detail: 'Each invoice number is frozen on its installment and cannot be changed afterwards. Corrections go through a credit memo.' +
520
+ (onRail ? ` ${onRail} of them ${onRail === 1 ? 'is' : 'are'} then sent to the customer automatically.` : ''),
521
+ type: 'warning',
522
+ confirmText: rows.length === 1 ? 'Issue invoice' : `Issue ${rows.length} invoices`,
523
+ cancelText: 'Not yet',
524
+ });
525
+ if (!proceed)
526
+ return;
527
+ this.Issuing = true;
528
+ this.Notice = null;
529
+ const failures = [];
530
+ let issued = 0;
531
+ try {
532
+ for (const [index, row] of rows.entries()) {
533
+ this.IssueProgress = `Issuing ${index + 1} of ${rows.length}…`;
534
+ this.cdr.detectChanges();
535
+ const outcome = await this.issue(row);
536
+ if (outcome.Ok)
537
+ issued += 1;
538
+ else
539
+ failures.push(`${row.OrderNumber} installment ${row.InstallmentNumber}: ${outcome.Text}`);
540
+ }
541
+ this.CheckedIDs = [];
542
+ this.Notice = failures.length
543
+ ? { Tone: issued ? 'warning' : 'error', Text: `${issued} of ${rows.length} issued. Not issued: ${failures.join(' ')}` }
544
+ : { Tone: 'success', Text: `${issued} invoice${issued === 1 ? '' : 's'} issued.` };
545
+ await this.load();
546
+ }
547
+ finally {
548
+ this.Issuing = false;
549
+ this.IssueProgress = null;
550
+ this.cdr.detectChanges();
551
+ }
552
+ }
553
+ /** Issue one installment. Never throws: a failure comes back as text to show. */
554
+ async issue(row) {
555
+ try {
556
+ const result = await new OrdersIssueInstalmentInvoiceOperation().Execute({ OrderHeaderPaymentScheduleID: row.OrderHeaderPaymentScheduleID });
557
+ const output = result.Output;
558
+ if (!result.Success || !output?.Success) {
559
+ return { Ok: false, Text: output?.Message?.trim() || result.ErrorMessage?.trim() || 'The installment could not be issued.' };
560
+ }
561
+ return { Ok: true, Text: output.Message ?? `Issued as ${output.DocumentNumber}.` };
562
+ }
563
+ catch (err) {
564
+ return { Ok: false, Text: err instanceof Error ? err.message : String(err) };
565
+ }
566
+ }
567
+ checkedRows() {
568
+ const ticked = new Set(this.CheckedIDs);
569
+ return this.Rows.filter((r) => ticked.has(r.OrderHeaderPaymentScheduleID) && this.CanTick(r));
570
+ }
180
571
  /* ── Loading ────────────────────────────────────────────────────────── */
572
+ async reload() {
573
+ await this.load();
574
+ this.cdr.detectChanges();
575
+ }
181
576
  async load() {
182
- const result = await new OrdersGetBillingWorklistOperation().Execute({ WindowDays: WINDOW_DAYS });
183
- const output = result.Output;
184
- if (!result.Success || !output?.Success) {
185
- // SAY SO. An empty worklist and a failed one look identical, and "nothing to bill" is
186
- // the most reassuring sentence on the screen.
187
- this.LoadError = output?.Message?.trim() || result.ErrorMessage?.trim() || 'The billing worklist could not be loaded.';
188
- this.AllRows = [];
189
- this.Rows = [];
190
- this.Presets = [];
577
+ const seq = ++this.loadSeq;
578
+ const windowKey = this.Window.Key;
579
+ // The operation lists everything due on or before the window's last day, as of the business
580
+ // day. A custom window's first day is applied here, to the rows it returns.
581
+ const today = Today();
582
+ const range = ResolveWindow(this.Window, BILLING_WINDOWS, today);
583
+ const windowDays = range.To ? Math.max(0, DaysBetween(today, range.To)) : ALL_DAYS;
584
+ this.Loading = true;
585
+ this.cdr.detectChanges();
586
+ try {
587
+ const result = await new OrdersGetBillingWorklistOperation().Execute({
588
+ WindowDays: windowDays,
589
+ // The operation fills its cap from the earliest due date. A long window needs room, and so
590
+ // does a range with a first day: without it the cap can fill with rows before that day.
591
+ ...(windowDays > 90 || range.From ? { MaxCount: WIDE_WINDOW_MAX_ROWS } : {}),
592
+ });
593
+ if (seq !== this.loadSeq)
594
+ return;
595
+ const output = result.Output;
596
+ if (!result.Success || !output?.Success) {
597
+ // SAY SO. An empty worklist and a failed one look identical, and "nothing to invoice" is
598
+ // the most reassuring sentence on the screen.
599
+ this.LoadError = output?.Message?.trim() || result.ErrorMessage?.trim() || 'The billing worklist could not be loaded.';
600
+ this.AllRows = [];
601
+ this.applyView();
602
+ this.cdr.detectChanges();
603
+ return;
604
+ }
605
+ this.LoadError = null;
606
+ // The operation lists everything due on or before the last day asked for, and never fewer
607
+ // than today's: a custom range that ends in the past, or starts after the earliest row, is
608
+ // cut to its two days here, so the list, the tiles, the count and the export all cover the
609
+ // dates the first tile names and nothing outside them can be ticked.
610
+ this.AllRows = output.Rows.filter((r) => InDayRange(r.DueDate, range));
611
+ this.Truncated = output.Truncated;
612
+ this.AsOf = output.AsOfDate;
613
+ this.loadedRange = range;
614
+ this.loadedWindowKey = windowKey;
615
+ await this.loadRails();
616
+ if (seq !== this.loadSeq)
617
+ return;
618
+ this.applyView();
619
+ this.cdr.detectChanges();
620
+ }
621
+ finally {
622
+ if (seq === this.loadSeq)
623
+ this.Loading = false;
191
624
  this.cdr.detectChanges();
192
- return;
193
625
  }
194
- this.LoadError = null;
195
- this.AllRows = output.Rows;
196
- this.Truncated = output.Truncated;
197
- this.AsOf = output.AsOfDate;
198
- this.WindowEnd = output.WindowEnd;
199
- await this.loadRails();
200
- this.applyPreset();
201
- this.cdr.detectChanges();
202
626
  }
203
627
  /**
204
628
  * Active invoice rails by company. Two small reads of seeded metadata rather than a per-row call,
@@ -210,7 +634,7 @@ export class MJOBillingPageComponent {
210
634
  const rv = new RunView();
211
635
  const codes = RAIL_TYPE_CODES.map((c) => `'${c}'`).join(',');
212
636
  const types = await rv.RunView({ EntityName: PAYMENT_PROVIDER_TYPE_ENTITY, ExtraFilter: `Code IN (${codes})`, Fields: ['ID'], ResultType: 'simple' });
213
- const typeIDs = (types.Results ?? []).map((t) => `'${t.ID}'`);
637
+ const typeIDs = (types.Results ?? []).map((t) => `'${RequireUUID(t.ID, 'PaymentProviderTypeID')}'`);
214
638
  if (!typeIDs.length)
215
639
  return;
216
640
  const providers = await rv.RunView({
@@ -226,104 +650,212 @@ export class MJOBillingPageComponent {
226
650
  // Context only. An order still bills the same way whether or not this column renders.
227
651
  }
228
652
  }
229
- applyPreset() {
230
- this.Presets = [
231
- { Key: 'all', Label: 'All in window', Count: this.AllRows.length },
232
- { Key: 'pastdue', Label: 'Past due', Count: this.PastDueCount, Icon: 'fa-solid fa-hourglass-half' },
233
- { Key: 'week', Label: 'Next 7 days', Count: this.AllRows.filter((r) => r.DaysUntilDue >= 0 && r.DaysUntilDue <= 7).length },
234
- ];
235
- this.Rows = this.AllRows.filter((row) => {
236
- switch (this.Preset) {
237
- case 'pastdue':
238
- return row.DaysUntilDue < 0;
239
- case 'week':
240
- return row.DaysUntilDue >= 0 && row.DaysUntilDue <= 7;
241
- default:
242
- return true;
243
- }
244
- });
653
+ /**
654
+ * Take the company choice and the window from the tab's address (`AdoptCompanyChoice`,
655
+ * `AdoptWindow`): what the address states wins, a key that was there and is gone means "none"
656
+ * or the default, and what was saved applies only where the address has never said anything.
657
+ *
658
+ * @returns Whether the window changed, which needs a reload.
659
+ */
660
+ adoptAddress() {
661
+ const picks = AdoptCompanyChoice(this.companyKey, this.address, globalThis.localStorage);
662
+ if (!SameChoice(picks, this.companyChoice))
663
+ this.companyChoice = picks;
664
+ const window = AdoptWindow(this.dueKey, this.address, BILLING_WINDOWS, this.Window, DEFAULT_WINDOW);
665
+ if (SameWindow(window, this.Window))
666
+ return false;
667
+ this.Window = window;
668
+ // Saved as well, so the next visit opens on what the address last said, as it does for the company.
669
+ WriteWorklistState(globalThis.localStorage, BILLING_STATE_KEY, { Window: this.Window, Sort: this.Sort });
670
+ return true;
245
671
  }
672
+ /**
673
+ * Rebuild what is listed from what was loaded: company and search narrow the rows the tiles
674
+ * count; the quick filter and the sort then decide what the table shows. An open
675
+ * or ticked installment the filters hide is let go, so nothing is issued that is not on screen.
676
+ */
677
+ applyView() {
678
+ const companies = ReconcileCompanies(this.AllRows, { ID: (r) => r.CompanyID, Name: (r) => r.CompanyName }, this.companyChoice);
679
+ this.Companies = companies.Options;
680
+ this.CompanyPicks = companies.Picks;
681
+ this.Scoped = FilterByCompanies(this.AllRows, this.CompanyPicks, (r) => r.CompanyID).filter((r) => MatchesText([r.CustomerName, r.OrderNumber, r.Description], this.Search));
682
+ const pastDue = this.Scoped.filter((r) => r.DaysUntilDue < 0);
683
+ const week = this.Scoped.filter((r) => r.DaysUntilDue >= 0 && r.DaysUntilDue <= 7);
684
+ const sum = (rows) => rows.reduce((s, r) => s + r.Amount, 0);
685
+ this.PastDue = { Count: pastDue.length, Amount: sum(pastDue) };
686
+ this.Week = { Count: week.length, Amount: sum(week) };
687
+ const shown = this.Preset === 'pastdue' ? pastDue : this.Preset === 'week' ? week : this.Scoped;
688
+ this.Rows = SortRows(shown, this.Columns, this.Sort);
689
+ this.Totals = { DueDate: 'Total', CustomerName: `${this.Rows.length} installment${this.Rows.length === 1 ? '' : 's'}`, Amount: FormatMoney(sum(this.Rows)) };
690
+ const listed = new Set(this.Rows.map((r) => r.OrderHeaderPaymentScheduleID));
691
+ this.CheckedIDs = this.CheckedIDs.filter((id) => listed.has(id));
692
+ if (this.Selected) {
693
+ const key = this.Selected.OrderHeaderPaymentScheduleID;
694
+ this.Selected = this.Rows.find((r) => r.OrderHeaderPaymentScheduleID === key) ?? null;
695
+ }
696
+ }
697
+ saveView() {
698
+ WriteWorklistState(globalThis.localStorage, BILLING_STATE_KEY, { Window: this.Window, Sort: this.Sort });
699
+ this.AddressChanged.emit(this.dueKey.Write(SameWindow(this.Window, DEFAULT_WINDOW) ? null : WindowToAddress(this.Window)));
700
+ }
701
+ /* ── Display helpers ────────────────────────────────────────────────── */
246
702
  dueNote(row) {
247
703
  if (row.DaysUntilDue < 0)
248
- return `${-row.DaysUntilDue}d past due`;
704
+ return `${-row.DaysUntilDue} day${row.DaysUntilDue === -1 ? '' : 's'} past due`;
249
705
  if (row.DaysUntilDue === 0)
250
706
  return 'due today';
251
- return `in ${row.DaysUntilDue}d`;
707
+ return `in ${row.DaysUntilDue} day${row.DaysUntilDue === 1 ? '' : 's'}`;
708
+ }
709
+ /** Every date on the page reads MM/DD/YYYY, as on Customer A/R. */
710
+ date(value) {
711
+ return value ? FormatDate(value, { Numeric: true }) : '—';
252
712
  }
253
713
  money(value) {
254
714
  return FormatMoney(value);
255
715
  }
256
716
  static ɵfac = function MJOBillingPageComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || MJOBillingPageComponent)(); };
257
- static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: MJOBillingPageComponent, selectors: [["mjo-billing-page"]], outputs: { OrderOpened: "OrderOpened" }, decls: 16, vars: 19, consts: [[1, "mj-stat-grid", "mjo-bl__tiles"], ["Icon", "fa-solid fa-file-invoice-dollar", "Tone", "alert", 3, "Label", "Value", "Detail"], ["Label", "Past due, never invoiced", "Icon", "fa-solid fa-hourglass-half", "Detail", "Issue these first", 3, "Value"], ["Label", "Window", "Icon", "fa-regular fa-calendar", "Detail", "Scheduled installments only", 3, "Value"], ["Variant", "error", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-bl__note"], ["Icon", "fa-solid fa-circle-info", 1, "mjo-bl__note", 3, "Variant"], ["Variant", "warning", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-bl__note"], [1, "row", "mjo-bl__actions"], ["type", "button", "mjButton", "", "variant", "outline", 3, "click", "disabled"], ["aria-hidden", "true", 1, "fa-solid", "fa-arrow-up-right-from-square"], ["type", "button", "mjButton", "", "variant", "primary", 3, "click", "disabled"], ["aria-hidden", "true", 1, "fa-solid", "fa-file-invoice"], [1, "small", "muted"], ["RowKey", "OrderHeaderPaymentScheduleID", "EmptyTitle", "Nothing to bill", "EmptyHint", "No scheduled installment falls inside the window.", "EmptyIcon", "fa-solid fa-file-invoice-dollar", 3, "PresetChanged", "RowClicked", "Columns", "Rows", "Presets", "ActivePreset", "Searchable", "SelectedKey"]], template: function MJOBillingPageComponent_Template(rf, ctx) { if (rf & 1) {
258
- i0.ɵɵelementStart(0, "div", 0);
259
- i0.ɵɵelement(1, "mjo-stat-tile", 1)(2, "mjo-stat-tile", 2)(3, "mjo-stat-tile", 3);
717
+ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: MJOBillingPageComponent, selectors: [["mjo-billing-page"]], outputs: { OrderOpened: "OrderOpened", AddressChanged: "AddressChanged" }, decls: 25, vars: 45, consts: [["SearchPlaceholder", "Search customer, order number or description", 3, "CompanyPicksChange", "SearchChange", "ActiveFilterCleared", "RefreshRequested", "Companies", "CompanyPicks", "Search", "ActiveFilter", "Summary", "Loading", "BuildExport", "CanExport"], [1, "mjo-bl__window"], [1, "small", "muted"], ["aria-label", "Which due dates to list", 1, "mjo-bl__select", 3, "change", "value"], [3, "value", "selected"], [1, "mj-stat-grid", "mjo-bl__tiles"], ["Hint", "Show every installment listed", "Icon", "fa-solid fa-file-invoice-dollar", 1, "mjo-bl__tile", 3, "Clicked", "Label", "Value", "Detail"], ["Hint", "Show installments past their due date", "Label", "Past due, not yet invoiced", "Icon", "fa-solid fa-hourglass-half", 1, "mjo-bl__tile", 3, "Clicked", "Pressed", "Tone", "Value", "Detail"], ["Hint", "Show installments due today or in the next 7 days", "Label", "Due in the next 7 days", "Icon", "fa-regular fa-calendar", 1, "mjo-bl__tile", 3, "Clicked", "Pressed", "Value", "Detail"], ["Variant", "error", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-bl__note"], ["Icon", "fa-solid fa-circle-info", 1, "mjo-bl__note", 3, "Variant"], ["Variant", "warning", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-bl__note"], [1, "mjo-split"], [1, "mjo-split__main"], [1, "row", "mjo-bl__actions"], ["type", "button", "mjButton", "", "variant", "primary", "title", "Issue an invoice for each ticked installment", 3, "click", "disabled"], ["aria-hidden", "true", 1, "fa-solid", "fa-file-invoice"], ["MaxHeight", "calc(100vh - 330px)", "RowKey", "OrderHeaderPaymentScheduleID", "EmptyIcon", "fa-solid fa-file-invoice-dollar", 3, "SelectionChanged", "SortChanged", "LinkClicked", "RowClicked", "Columns", "Rows", "Searchable", "Loading", "Totals", "SortKey", "SortDescending", "SelectedKey", "Selectable", "SelectedKeys", "SelectableRow", "RowLabel", "EmptyTitle", "EmptyHint"], [1, "mjo-split__side"], ["type", "date", "aria-label", "Earliest due date", 1, "mjo-bl__select", 3, "change", "value"], ["type", "date", "aria-label", "Latest due date", 1, "mjo-bl__select", 3, "change", "value"], ["Icon", "fa-solid fa-file-invoice-dollar", 3, "Closed", "Title", "Chip", "ChipClass"], [1, "mjo-side-panel__amount"], [1, "mjo-side-panel__facts"], ["type", "button", "title", "Open the order", 1, "mjo-side-panel__link", 3, "click"], [1, "mjo-side-panel__actions"], ["type", "button", "mjButton", "", "variant", "primary", 3, "click", "disabled"], ["type", "button", "mjButton", "", "variant", "outline", 3, "click"], ["aria-hidden", "true", 1, "fa-solid", "fa-arrow-up-right-from-square"], [1, "small", "mjo-bl__blocked", "mjo-side-panel__note"]], template: function MJOBillingPageComponent_Template(rf, ctx) { if (rf & 1) {
718
+ i0.ɵɵelementStart(0, "mjo-worklist-bar", 0);
719
+ i0.ɵɵlistener("CompanyPicksChange", function MJOBillingPageComponent_Template_mjo_worklist_bar_CompanyPicksChange_0_listener($event) { return ctx.OnCompanies($event); })("SearchChange", function MJOBillingPageComponent_Template_mjo_worklist_bar_SearchChange_0_listener($event) { return ctx.OnSearch($event); })("ActiveFilterCleared", function MJOBillingPageComponent_Template_mjo_worklist_bar_ActiveFilterCleared_0_listener() { return ctx.OnPreset("all"); })("RefreshRequested", function MJOBillingPageComponent_Template_mjo_worklist_bar_RefreshRequested_0_listener() { return ctx.Refresh(); });
720
+ i0.ɵɵelementStart(1, "label", 1)(2, "span", 2);
721
+ i0.ɵɵtext(3, "Due");
722
+ i0.ɵɵelementEnd();
723
+ i0.ɵɵelementStart(4, "select", 3);
724
+ i0.ɵɵlistener("change", function MJOBillingPageComponent_Template_select_change_4_listener($event) { return ctx.OnWindow($event.target.value); });
725
+ i0.ɵɵrepeaterCreate(5, MJOBillingPageComponent_For_6_Template, 2, 3, "option", 4, _forTrack0);
726
+ i0.ɵɵelementEnd()();
727
+ i0.ɵɵconditionalCreate(7, MJOBillingPageComponent_Conditional_7_Template, 8, 2);
260
728
  i0.ɵɵelementEnd();
261
- i0.ɵɵconditionalCreate(4, MJOBillingPageComponent_Conditional_4_Template, 4, 1, "mj-alert", 4);
262
- i0.ɵɵconditionalCreate(5, MJOBillingPageComponent_Conditional_5_Template, 2, 2, "mj-alert", 5);
263
- i0.ɵɵconditionalCreate(6, MJOBillingPageComponent_Conditional_6_Template, 4, 0, "mj-alert", 6);
264
- i0.ɵɵelementStart(7, "div", 7)(8, "button", 8);
265
- i0.ɵɵlistener("click", function MJOBillingPageComponent_Template_button_click_8_listener() { return ctx.OpenSelected(); });
266
- i0.ɵɵelement(9, "i", 9);
267
- i0.ɵɵtext(10, " Open order ");
729
+ i0.ɵɵelementStart(8, "div", 5)(9, "mjo-stat-tile", 6);
730
+ i0.ɵɵlistener("Clicked", function MJOBillingPageComponent_Template_mjo_stat_tile_Clicked_9_listener() { return ctx.OnPreset("all"); });
268
731
  i0.ɵɵelementEnd();
269
- i0.ɵɵelementStart(11, "button", 10);
270
- i0.ɵɵlistener("click", function MJOBillingPageComponent_Template_button_click_11_listener() { return ctx.IssueSelected(); });
271
- i0.ɵɵelement(12, "i", 11);
272
- i0.ɵɵtext(13);
732
+ i0.ɵɵelementStart(10, "mjo-stat-tile", 7);
733
+ i0.ɵɵlistener("Clicked", function MJOBillingPageComponent_Template_mjo_stat_tile_Clicked_10_listener() { return ctx.OnPreset("pastdue"); });
273
734
  i0.ɵɵelementEnd();
274
- i0.ɵɵconditionalCreate(14, MJOBillingPageComponent_Conditional_14_Template, 2, 4, "span", 12);
735
+ i0.ɵɵelementStart(11, "mjo-stat-tile", 8);
736
+ i0.ɵɵlistener("Clicked", function MJOBillingPageComponent_Template_mjo_stat_tile_Clicked_11_listener() { return ctx.OnPreset("week"); });
737
+ i0.ɵɵelementEnd()();
738
+ i0.ɵɵconditionalCreate(12, MJOBillingPageComponent_Conditional_12_Template, 4, 1, "mj-alert", 9);
739
+ i0.ɵɵconditionalCreate(13, MJOBillingPageComponent_Conditional_13_Template, 2, 2, "mj-alert", 10);
740
+ i0.ɵɵconditionalCreate(14, MJOBillingPageComponent_Conditional_14_Template, 4, 0, "mj-alert", 11);
741
+ i0.ɵɵelementStart(15, "div", 12)(16, "div", 13)(17, "div", 14)(18, "button", 15);
742
+ i0.ɵɵlistener("click", function MJOBillingPageComponent_Template_button_click_18_listener() { return ctx.IssueChecked(); });
743
+ i0.ɵɵelement(19, "i", 16);
744
+ i0.ɵɵtext(20);
275
745
  i0.ɵɵelementEnd();
276
- i0.ɵɵelementStart(15, "mjo-worklist-table", 13);
277
- i0.ɵɵlistener("PresetChanged", function MJOBillingPageComponent_Template_mjo_worklist_table_PresetChanged_15_listener($event) { return ctx.OnPreset($event); })("RowClicked", function MJOBillingPageComponent_Template_mjo_worklist_table_RowClicked_15_listener($event) { return ctx.Selected = $event; });
746
+ i0.ɵɵelementStart(21, "span", 2);
747
+ i0.ɵɵtext(22);
748
+ i0.ɵɵelementEnd()();
749
+ i0.ɵɵelementStart(23, "mjo-worklist-table", 17);
750
+ i0.ɵɵlistener("SelectionChanged", function MJOBillingPageComponent_Template_mjo_worklist_table_SelectionChanged_23_listener($event) { return ctx.CheckedIDs = $event; })("SortChanged", function MJOBillingPageComponent_Template_mjo_worklist_table_SortChanged_23_listener($event) { return ctx.OnSort($event); })("LinkClicked", function MJOBillingPageComponent_Template_mjo_worklist_table_LinkClicked_23_listener($event) { return ctx.OpenOrder($event.Row); })("RowClicked", function MJOBillingPageComponent_Template_mjo_worklist_table_RowClicked_23_listener($event) { return ctx.OnRow($event); });
751
+ i0.ɵɵelementEnd()();
752
+ i0.ɵɵconditionalCreate(24, MJOBillingPageComponent_Conditional_24_Template, 35, 14, "div", 18);
278
753
  i0.ɵɵelementEnd();
279
754
  } if (rf & 2) {
280
- let tmp_11_0;
755
+ let tmp_43_0;
756
+ i0.ɵɵproperty("Companies", ctx.Companies)("CompanyPicks", ctx.CompanyPicks)("Search", ctx.Search)("ActiveFilter", ctx.Preset === "all" ? null : ctx.PresetLabel)("Summary", ctx.Summary)("Loading", ctx.Loading)("BuildExport", ctx.BuildExport)("CanExport", ctx.Rows.length > 0);
757
+ i0.ɵɵadvance(4);
758
+ i0.ɵɵproperty("value", ctx.Window.Key);
281
759
  i0.ɵɵadvance();
282
- i0.ɵɵproperty("Label", i0.ɵɵinterpolate1("Due in the next ", ctx.WindowDays, " days"))("Value", ctx.TotalDisplay)("Detail", ctx.TotalDetail);
760
+ i0.ɵɵrepeater(ctx.Windows);
761
+ i0.ɵɵadvance(2);
762
+ i0.ɵɵconditional(ctx.IsCustomWindow ? 7 : -1);
763
+ i0.ɵɵadvance(2);
764
+ i0.ɵɵproperty("Label", ctx.TotalLabel)("Value", ctx.TotalDisplay)("Detail", ctx.TotalDetail);
283
765
  i0.ɵɵadvance();
284
- i0.ɵɵproperty("Value", ctx.String(ctx.PastDueCount));
766
+ i0.ɵɵclassProp("is-on", ctx.Preset === "pastdue");
767
+ i0.ɵɵproperty("Pressed", ctx.Preset === "pastdue")("Tone", ctx.PastDue.Count ? "alert" : "default")("Value", ctx.String(ctx.PastDue.Count))("Detail", ctx.PastDue.Count ? ctx.money(ctx.PastDue.Amount) + " \u00B7 issue these first" : ctx.IsCustomWindow ? "None in these dates" : "Nothing is late");
285
768
  i0.ɵɵadvance();
286
- i0.ɵɵproperty("Value", ctx.WindowDisplay);
769
+ i0.ɵɵclassProp("is-on", ctx.Preset === "week");
770
+ i0.ɵɵproperty("Pressed", ctx.Preset === "week")("Value", ctx.String(ctx.Week.Count))("Detail", ctx.Week.Count ? ctx.money(ctx.Week.Amount) : "Nothing due this week");
287
771
  i0.ɵɵadvance();
288
- i0.ɵɵconditional(ctx.LoadError ? 4 : -1);
772
+ i0.ɵɵconditional(ctx.LoadError ? 12 : -1);
289
773
  i0.ɵɵadvance();
290
- i0.ɵɵconditional(ctx.Notice ? 5 : -1);
774
+ i0.ɵɵconditional(ctx.Notice ? 13 : -1);
291
775
  i0.ɵɵadvance();
292
- i0.ɵɵconditional(ctx.Truncated ? 6 : -1);
776
+ i0.ɵɵconditional(ctx.Truncated ? 14 : -1);
777
+ i0.ɵɵadvance(4);
778
+ i0.ɵɵproperty("disabled", !ctx.CheckedIDs.length || ctx.Issuing);
293
779
  i0.ɵɵadvance(2);
294
- i0.ɵɵproperty("disabled", !ctx.Selected);
295
- i0.ɵɵadvance(3);
296
- i0.ɵɵproperty("disabled", !ctx.Selected || ctx.Issuing);
780
+ i0.ɵɵtextInterpolate1(" ", ctx.Issuing && ctx.IssueProgress ? ctx.IssueProgress : "Issue invoices" + (ctx.CheckedIDs.length ? " (" + ctx.CheckedIDs.length + ")" : ""), " ");
297
781
  i0.ɵɵadvance(2);
298
- i0.ɵɵtextInterpolate1(" ", ctx.Issuing ? "Issuing\u2026" : "Issue invoice", " ");
782
+ i0.ɵɵtextInterpolate1(" ", ctx.CheckedIDs.length ? ctx.CheckedSummary : "Select an installment to see its detail. Tick several to issue them together.", " ");
299
783
  i0.ɵɵadvance();
300
- i0.ɵɵconditional((tmp_11_0 = ctx.Selected) ? 14 : -1, tmp_11_0);
784
+ i0.ɵɵproperty("Columns", ctx.Columns)("Rows", ctx.Rows)("Searchable", false)("Loading", ctx.Loading)("Totals", ctx.Totals)("SortKey", ctx.Sort.Key)("SortDescending", ctx.Sort.Descending)("SelectedKey", (ctx.Selected == null ? null : ctx.Selected.OrderHeaderPaymentScheduleID) ?? null)("Selectable", true)("SelectedKeys", ctx.CheckedIDs)("SelectableRow", ctx.CanTick)("RowLabel", ctx.TickLabel)("EmptyTitle", ctx.EmptyTitle)("EmptyHint", ctx.EmptyHint);
301
785
  i0.ɵɵadvance();
302
- i0.ɵɵproperty("Columns", ctx.Columns)("Rows", ctx.Rows)("Presets", ctx.Presets)("ActivePreset", ctx.Preset)("Searchable", false)("SelectedKey", (ctx.Selected == null ? null : ctx.Selected.OrderHeaderPaymentScheduleID) ?? null);
303
- } }, dependencies: [CommonModule, MJButtonDirective, MJAlertComponent, MJOStatTileComponent, MJOWorklistTableComponent], styles: ["[_nghost-%COMP%] {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-bl__tiles[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-bl__note[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-bl__actions[_ngcontent-%COMP%] {\n align-items: center;\n gap: var(--mj-space-3);\n margin-bottom: var(--mj-space-4);\n }\n @media (max-width: 760px) {\n [_nghost-%COMP%] { padding: var(--mj-space-4); }\n }"] });
786
+ i0.ɵɵconditional((tmp_43_0 = ctx.Selected) ? 24 : -1, tmp_43_0);
787
+ } }, dependencies: [CommonModule, MJButtonDirective, MJAlertComponent, MJOSidePanelComponent, MJOStatTileComponent, MJOWorklistBarComponent, MJOWorklistTableComponent], styles: ["[_nghost-%COMP%] {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-bl__tiles[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-bl__tile[_ngcontent-%COMP%] {\n display: block;\n border-radius: var(--mj-radius-md);\n transition: box-shadow 140ms ease;\n }\n \n\n .mjo-bl__tile.is-on[_ngcontent-%COMP%] { box-shadow: 0 0 0 2px color-mix(in srgb, var(--mj-brand-primary) 55%, transparent); }\n .mjo-bl__note[_ngcontent-%COMP%] { display: block; margin-bottom: var(--mj-space-4); }\n .mjo-bl__blocked[_ngcontent-%COMP%] { color: var(--mj-status-warning-text); }\n .mjo-bl__window[_ngcontent-%COMP%] {\n display: inline-flex;\n align-items: center;\n gap: var(--mj-space-2);\n }\n .mjo-bl__select[_ngcontent-%COMP%] {\n font: inherit;\n font-size: 13px;\n padding: 4px 8px;\n border: 1px solid var(--mj-border-default);\n border-radius: var(--mj-radius-md);\n background: var(--mj-bg-surface);\n color: inherit;\n }\n .mjo-bl__actions[_ngcontent-%COMP%] {\n align-items: center;\n gap: var(--mj-space-3);\n margin-bottom: var(--mj-space-3);\n }\n @media (max-width: 760px) {\n [_nghost-%COMP%] { padding: var(--mj-space-4); }\n }\n @media (prefers-reduced-motion: reduce) {\n .mjo-bl__tile[_ngcontent-%COMP%] { transition: none; }\n }"] });
304
788
  }
305
789
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MJOBillingPageComponent, [{
306
790
  type: Component,
307
- args: [{ selector: 'mjo-billing-page', standalone: true, imports: [CommonModule, MJButtonDirective, MJAlertComponent, MJOStatTileComponent, MJOWorklistTableComponent], template: `
791
+ args: [{ selector: 'mjo-billing-page', standalone: true, imports: [CommonModule, MJButtonDirective, MJAlertComponent, MJOSidePanelComponent, MJOStatTileComponent, MJOWorklistBarComponent, MJOWorklistTableComponent], template: `
792
+ <mjo-worklist-bar
793
+ [Companies]="Companies"
794
+ [CompanyPicks]="CompanyPicks"
795
+ [Search]="Search"
796
+ SearchPlaceholder="Search customer, order number or description"
797
+ [ActiveFilter]="Preset === 'all' ? null : PresetLabel"
798
+ [Summary]="Summary"
799
+ [Loading]="Loading"
800
+ [BuildExport]="BuildExport"
801
+ [CanExport]="Rows.length > 0"
802
+ (CompanyPicksChange)="OnCompanies($event)"
803
+ (SearchChange)="OnSearch($event)"
804
+ (ActiveFilterCleared)="OnPreset('all')"
805
+ (RefreshRequested)="Refresh()">
806
+ <label class="mjo-bl__window">
807
+ <span class="small muted">Due</span>
808
+ <select class="mjo-bl__select" [value]="Window.Key" (change)="OnWindow($any($event.target).value)" aria-label="Which due dates to list">
809
+ @for (option of Windows; track option.Key) {
810
+ <option [value]="option.Key" [selected]="option.Key === Window.Key">{{ option.Label }}</option>
811
+ }
812
+ </select>
813
+ </label>
814
+ @if (IsCustomWindow) {
815
+ <label class="mjo-bl__window">
816
+ <span class="small muted">From</span>
817
+ <input class="mjo-bl__select" type="date" [value]="Window.From ?? ''" (change)="OnCustomDay('From', $any($event.target).value)" aria-label="Earliest due date">
818
+ </label>
819
+ <label class="mjo-bl__window">
820
+ <span class="small muted">To</span>
821
+ <input class="mjo-bl__select" type="date" [value]="Window.To ?? ''" (change)="OnCustomDay('To', $any($event.target).value)" aria-label="Latest due date">
822
+ </label>
823
+ }
824
+ </mjo-worklist-bar>
825
+
826
+ <!-- The tiles total what the company filter, the dates and the search leave. Past due and Next 7 days are also quick filters; the figures do not change when one is on. -->
308
827
  <div class="mj-stat-grid mjo-bl__tiles">
309
828
  <mjo-stat-tile
310
- Label="Due in the next {{ WindowDays }} days"
829
+ class="mjo-bl__tile"
830
+ Hint="Show every installment listed"
831
+ [Label]="TotalLabel"
311
832
  Icon="fa-solid fa-file-invoice-dollar"
312
- Tone="alert"
313
833
  [Value]="TotalDisplay"
314
- [Detail]="TotalDetail" />
834
+ [Detail]="TotalDetail"
835
+ (Clicked)="OnPreset('all')" />
315
836
 
316
837
  <mjo-stat-tile
317
- Label="Past due, never invoiced"
838
+ class="mjo-bl__tile"
839
+ [class.is-on]="Preset === 'pastdue'"
840
+ [Pressed]="Preset === 'pastdue'"
841
+ Hint="Show installments past their due date"
842
+ Label="Past due, not yet invoiced"
318
843
  Icon="fa-solid fa-hourglass-half"
319
- [Value]="String(PastDueCount)"
320
- Detail="Issue these first" />
844
+ [Tone]="PastDue.Count ? 'alert' : 'default'"
845
+ [Value]="String(PastDue.Count)"
846
+ [Detail]="PastDue.Count ? money(PastDue.Amount) + ' · issue these first' : IsCustomWindow ? 'None in these dates' : 'Nothing is late'"
847
+ (Clicked)="OnPreset('pastdue')" />
321
848
 
322
849
  <mjo-stat-tile
323
- Label="Window"
850
+ class="mjo-bl__tile"
851
+ [class.is-on]="Preset === 'week'"
852
+ [Pressed]="Preset === 'week'"
853
+ Hint="Show installments due today or in the next 7 days"
854
+ Label="Due in the next 7 days"
324
855
  Icon="fa-regular fa-calendar"
325
- [Value]="WindowDisplay"
326
- Detail="Scheduled installments only" />
856
+ [Value]="String(Week.Count)"
857
+ [Detail]="Week.Count ? money(Week.Amount) : 'Nothing due this week'"
858
+ (Clicked)="OnPreset('week')" />
327
859
  </div>
328
860
 
329
861
  @if (LoadError) {
@@ -340,39 +872,92 @@ export class MJOBillingPageComponent {
340
872
  @if (Truncated) {
341
873
  <mj-alert Variant="warning" Icon="fa-solid fa-triangle-exclamation" class="mjo-bl__note">
342
874
  <strong>List truncated.</strong>
343
- Not every due installment is shown.
875
+ Not every installment in these dates is shown, and the figures above cover only those that are.
344
876
  </mj-alert>
345
877
  }
346
878
 
347
- <div class="row mjo-bl__actions">
348
- <button type="button" mjButton variant="outline" [disabled]="!Selected" (click)="OpenSelected()">
349
- <i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i> Open order
350
- </button>
351
- <button type="button" mjButton variant="primary" [disabled]="!Selected || Issuing" (click)="IssueSelected()">
352
- <i class="fa-solid fa-file-invoice" aria-hidden="true"></i>
353
- {{ Issuing ? 'Issuing…' : 'Issue invoice' }}
354
- </button>
879
+ <div class="mjo-split">
880
+ <div class="mjo-split__main">
881
+ <div class="row mjo-bl__actions">
882
+ <button type="button" mjButton variant="primary" [disabled]="!CheckedIDs.length || Issuing" (click)="IssueChecked()" title="Issue an invoice for each ticked installment">
883
+ <i class="fa-solid fa-file-invoice" aria-hidden="true"></i>
884
+ {{ Issuing && IssueProgress ? IssueProgress : 'Issue invoices' + (CheckedIDs.length ? ' (' + CheckedIDs.length + ')' : '') }}
885
+ </button>
886
+ <span class="small muted">
887
+ {{ CheckedIDs.length ? CheckedSummary : 'Select an installment to see its detail. Tick several to issue them together.' }}
888
+ </span>
889
+ </div>
890
+
891
+ <mjo-worklist-table
892
+ [Columns]="Columns"
893
+ [Rows]="Rows"
894
+ [Searchable]="false"
895
+ [Loading]="Loading"
896
+ [Totals]="Totals"
897
+ MaxHeight="calc(100vh - 330px)"
898
+ [SortKey]="Sort.Key"
899
+ [SortDescending]="Sort.Descending"
900
+ RowKey="OrderHeaderPaymentScheduleID"
901
+ [SelectedKey]="Selected?.OrderHeaderPaymentScheduleID ?? null"
902
+ [Selectable]="true"
903
+ [SelectedKeys]="CheckedIDs"
904
+ [SelectableRow]="CanTick"
905
+ [RowLabel]="TickLabel"
906
+ [EmptyTitle]="EmptyTitle"
907
+ [EmptyHint]="EmptyHint"
908
+ EmptyIcon="fa-solid fa-file-invoice-dollar"
909
+ (SelectionChanged)="CheckedIDs = $event"
910
+ (SortChanged)="OnSort($event)"
911
+ (LinkClicked)="OpenOrder($event.Row)"
912
+ (RowClicked)="OnRow($event)" />
913
+ </div>
914
+
355
915
  @if (Selected; as row) {
356
- <span class="small muted">{{ row.OrderNumber }} · installment {{ row.InstallmentNumber }} of {{ row.InstallmentCount }} · {{ money(row.Amount) }}</span>
916
+ <div class="mjo-split__side">
917
+ <mjo-side-panel
918
+ Icon="fa-solid fa-file-invoice-dollar"
919
+ [Title]="row.OrderNumber + ' · installment ' + row.InstallmentNumber + ' of ' + row.InstallmentCount"
920
+ [Chip]="row.OrderStatus"
921
+ [ChipClass]="row.OrderStatus === 'Confirmed' ? 'mjo-chip--success' : 'mjo-chip--outline'"
922
+ (Closed)="Selected = null">
923
+ <div class="mjo-side-panel__amount">{{ money(row.Amount) }}</div>
924
+ <dl class="mjo-side-panel__facts">
925
+ <dt>Customer</dt>
926
+ <dd>{{ row.CustomerName }}</dd>
927
+ <dt>Order</dt>
928
+ <dd><button type="button" class="mjo-side-panel__link" (click)="OpenOrder(row)" title="Open the order">{{ row.OrderNumber }}</button></dd>
929
+ <dt>Due</dt>
930
+ <dd>{{ date(row.DueDate) }} · {{ dueNote(row) }}</dd>
931
+ <dt>Billed by</dt>
932
+ <dd>{{ row.CompanyName || '—' }}</dd>
933
+ @if (row.Description) {
934
+ <dt>For</dt>
935
+ <dd>{{ row.Description }}</dd>
936
+ }
937
+ <dt>After issuing</dt>
938
+ <dd>{{ RailFor(row.CompanyID) ? 'Sent automatically through ' + RailFor(row.CompanyID) : 'Not sent automatically' }}</dd>
939
+ </dl>
940
+ <div class="mjo-side-panel__actions">
941
+ <button type="button" mjButton variant="primary" [disabled]="Issuing || !!IssueBlockedReason" (click)="IssueSelected()">
942
+ <i class="fa-solid fa-file-invoice" aria-hidden="true"></i>
943
+ {{ Issuing ? 'Issuing…' : 'Issue invoice' }}
944
+ </button>
945
+ <button type="button" mjButton variant="outline" (click)="OpenOrder(row)">
946
+ <i class="fa-solid fa-arrow-up-right-from-square" aria-hidden="true"></i> Open order
947
+ </button>
948
+ </div>
949
+ @if (IssueBlockedReason; as why) {
950
+ <p class="small mjo-bl__blocked mjo-side-panel__note">{{ why }}</p>
951
+ }
952
+ </mjo-side-panel>
953
+ </div>
357
954
  }
358
955
  </div>
359
-
360
- <mjo-worklist-table
361
- [Columns]="Columns"
362
- [Rows]="Rows"
363
- [Presets]="Presets"
364
- [ActivePreset]="Preset"
365
- [Searchable]="false"
366
- RowKey="OrderHeaderPaymentScheduleID"
367
- [SelectedKey]="Selected?.OrderHeaderPaymentScheduleID ?? null"
368
- EmptyTitle="Nothing to bill"
369
- EmptyHint="No scheduled installment falls inside the window."
370
- EmptyIcon="fa-solid fa-file-invoice-dollar"
371
- (PresetChanged)="OnPreset($event)"
372
- (RowClicked)="Selected = $event" />
373
- `, styles: ["\n :host {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-bl__tiles { margin-bottom: var(--mj-space-4); }\n .mjo-bl__note { margin-bottom: var(--mj-space-4); }\n .mjo-bl__actions {\n align-items: center;\n gap: var(--mj-space-3);\n margin-bottom: var(--mj-space-4);\n }\n @media (max-width: 760px) {\n :host { padding: var(--mj-space-4); }\n }\n "] }]
956
+ `, styles: ["\n :host {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-bl__tiles { margin-bottom: var(--mj-space-4); }\n .mjo-bl__tile {\n display: block;\n border-radius: var(--mj-radius-md);\n transition: box-shadow 140ms ease;\n }\n /* Ringed only while its quick filter is on. The first tile, which clears the filter, never is. */\n .mjo-bl__tile.is-on { box-shadow: 0 0 0 2px color-mix(in srgb, var(--mj-brand-primary) 55%, transparent); }\n .mjo-bl__note { display: block; margin-bottom: var(--mj-space-4); }\n .mjo-bl__blocked { color: var(--mj-status-warning-text); }\n .mjo-bl__window {\n display: inline-flex;\n align-items: center;\n gap: var(--mj-space-2);\n }\n .mjo-bl__select {\n font: inherit;\n font-size: 13px;\n padding: 4px 8px;\n border: 1px solid var(--mj-border-default);\n border-radius: var(--mj-radius-md);\n background: var(--mj-bg-surface);\n color: inherit;\n }\n .mjo-bl__actions {\n align-items: center;\n gap: var(--mj-space-3);\n margin-bottom: var(--mj-space-3);\n }\n @media (max-width: 760px) {\n :host { padding: var(--mj-space-4); }\n }\n @media (prefers-reduced-motion: reduce) {\n .mjo-bl__tile { transition: none; }\n }\n "] }]
374
957
  }], null, { OrderOpened: [{
375
958
  type: Output
959
+ }], AddressChanged: [{
960
+ type: Output
376
961
  }] }); })();
377
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(MJOBillingPageComponent, { className: "MJOBillingPageComponent", filePath: "lib/pages/receivables/billing.page.ts", lineNumber: 132 }); })();
962
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(MJOBillingPageComponent, { className: "MJOBillingPageComponent", filePath: "lib/pages/receivables/billing.page.ts", lineNumber: 329 }); })();
378
963
  //# sourceMappingURL=billing.page.js.map