@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
@@ -3,59 +3,143 @@ import { CommonModule } from '@angular/common';
3
3
  import { EntityViewerModule } from '@memberjunction/ng-entity-viewer';
4
4
  import { Metadata } from '@memberjunction/core';
5
5
  import { PresetViewRef } from '../../data/preset-view.js';
6
- import { OrdersGetOverdueWorklistOperation, OverdueFilter, Today, } from '@mj-biz-apps/orders-entities';
7
- import { MJOAgingBarComponent } from '../../panels/aging-bar.component.js';
6
+ import { OrdersGetOverdueWorklistOperation, OverdueFilter, RequireUUID, Today, } from '@mj-biz-apps/orders-entities';
7
+ import { GetOpenInstalmentDetails } from '../../data/orders-queries.js';
8
+ import { GroupInstalmentsByOrder, MJOAgingBarComponent } from '../../panels/aging-bar.component.js';
8
9
  import { MJOStatTileComponent } from '../../panels/stat-tile.component.js';
9
10
  import { FormatDate, FormatMoney } from '../../panels/money-format.js';
10
11
  import { MJAlertComponent } from '@memberjunction/ng-ui-components';
11
12
  import { MJO_ENTITIES } from '../../data/entity-names.js';
12
13
  import { MJO_ORDER_HEADER_GRID_STATE } from '../../data/orders-grid-state.js';
14
+ import { MJOWorklistBarComponent } from '../../panels/worklist-bar.component.js';
15
+ import { CreditHeld, RestateOverdue, SumAged } from './overdue-page.model.js';
16
+ import { BuildWorklistExport, AddressKey, AdoptCompanyChoice, AdoptWindow, COMPANY_ADDRESS_KEY, CUSTOM_WINDOW, CompaniesToAddress, ExportFileName, FilterByCompanies, InDayRange, ReadWorklistState, ReconcileCompanies, ResolveWindow, RestoreWindow, SameChoice, SameWindow, ShownSummary, WindowToAddress, WriteSharedCompanies, WriteWorklistState, } from './worklist-view.model.js';
13
17
  import * as i0 from "@angular/core";
14
18
  import * as i1 from "@memberjunction/ng-entity-viewer";
15
- function MJOOverduePageComponent_Conditional_5_Template(rf, ctx) { if (rf & 1) {
16
- i0.ɵɵelementStart(0, "mj-alert", 5)(1, "strong");
19
+ const _forTrack0 = ($index, $item) => $item.Key;
20
+ function MJOOverduePageComponent_For_6_Template(rf, ctx) { if (rf & 1) {
21
+ i0.ɵɵelementStart(0, "option", 4);
22
+ i0.ɵɵtext(1);
23
+ i0.ɵɵelementEnd();
24
+ } if (rf & 2) {
25
+ const option_r1 = ctx.$implicit;
26
+ const ctx_r1 = i0.ɵɵnextContext();
27
+ i0.ɵɵproperty("value", option_r1.Key)("selected", option_r1.Key === ctx_r1.Window.Key);
28
+ i0.ɵɵadvance();
29
+ i0.ɵɵtextInterpolate(option_r1.Label);
30
+ } }
31
+ function MJOOverduePageComponent_Conditional_7_Template(rf, ctx) { if (rf & 1) {
32
+ const _r3 = i0.ɵɵgetCurrentView();
33
+ i0.ɵɵelementStart(0, "label", 1)(1, "span", 2);
34
+ i0.ɵɵtext(2, "Due from");
35
+ i0.ɵɵelementEnd();
36
+ i0.ɵɵelementStart(3, "input", 25);
37
+ i0.ɵɵlistener("change", function MJOOverduePageComponent_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)); });
38
+ i0.ɵɵelementEnd()();
39
+ i0.ɵɵelementStart(4, "label", 1)(5, "span", 2);
40
+ i0.ɵɵtext(6, "to");
41
+ i0.ɵɵelementEnd();
42
+ i0.ɵɵelementStart(7, "input", 26);
43
+ i0.ɵɵlistener("change", function MJOOverduePageComponent_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)); });
44
+ i0.ɵɵelementEnd()();
45
+ } if (rf & 2) {
46
+ const ctx_r1 = i0.ɵɵnextContext();
47
+ i0.ɵɵadvance(3);
48
+ i0.ɵɵproperty("value", ctx_r1.Window.From ?? "");
49
+ i0.ɵɵadvance(4);
50
+ i0.ɵɵproperty("value", ctx_r1.Window.To ?? "");
51
+ } }
52
+ function MJOOverduePageComponent_Conditional_13_Template(rf, ctx) { if (rf & 1) {
53
+ i0.ɵɵelementStart(0, "mj-alert", 10)(1, "strong");
17
54
  i0.ɵɵtext(2, "The worklist did not load.");
18
55
  i0.ɵɵelementEnd();
19
56
  i0.ɵɵtext(3);
20
57
  i0.ɵɵelementEnd();
21
58
  } if (rf & 2) {
22
- const ctx_r0 = i0.ɵɵnextContext();
59
+ const ctx_r1 = i0.ɵɵnextContext();
60
+ i0.ɵɵadvance(3);
61
+ i0.ɵɵtextInterpolate1(" ", ctx_r1.LoadError, " ");
62
+ } }
63
+ function MJOOverduePageComponent_Conditional_14_Template(rf, ctx) { if (rf & 1) {
64
+ i0.ɵɵelementStart(0, "mj-alert", 11)(1, "strong");
65
+ i0.ɵɵtext(2, "Installments could not be read.");
66
+ i0.ɵɵelementEnd();
67
+ i0.ɵɵtext(3);
68
+ i0.ɵɵelementEnd();
69
+ } if (rf & 2) {
70
+ const ctx_r1 = i0.ɵɵnextContext();
23
71
  i0.ɵɵadvance(3);
24
- i0.ɵɵtextInterpolate1(" ", ctx_r0.LoadError, " ");
72
+ i0.ɵɵtextInterpolate1(" Each order is shown with its whole balance, from its next due date. ", ctx_r1.InstalmentsError, " ");
25
73
  } }
26
- function MJOOverduePageComponent_Conditional_18_Template(rf, ctx) { if (rf & 1) {
27
- i0.ɵɵelementStart(0, "mj-alert", 13)(1, "strong");
74
+ function MJOOverduePageComponent_Conditional_29_Template(rf, ctx) { if (rf & 1) {
75
+ i0.ɵɵelementStart(0, "mj-alert", 20)(1, "strong");
28
76
  i0.ɵɵtext(2, "List truncated.");
29
77
  i0.ɵɵelementEnd();
30
- i0.ɵɵtext(3, " Not all overdue orders are shown. Add a filter to narrow the list. ");
78
+ i0.ɵɵtext(3, " Not all overdue orders are shown, and the figures above cover only those that are. ");
31
79
  i0.ɵɵelementEnd();
32
80
  } }
33
- function MJOOverduePageComponent_Conditional_20_Template(rf, ctx) { if (rf & 1) {
34
- const _r2 = i0.ɵɵgetCurrentView();
35
- i0.ɵɵelementStart(0, "mj-entity-viewer", 17);
36
- i0.ɵɵlistener("RecordOpened", function MJOOverduePageComponent_Conditional_20_Template_mj_entity_viewer_RecordOpened_0_listener($event) { i0.ɵɵrestoreView(_r2); const ctx_r0 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r0.OnRecordOpened($event)); });
81
+ function MJOOverduePageComponent_Conditional_31_Template(rf, ctx) { if (rf & 1) {
82
+ const _r4 = i0.ɵɵgetCurrentView();
83
+ i0.ɵɵelementStart(0, "mj-entity-viewer", 27);
84
+ i0.ɵɵlistener("RecordOpened", function MJOOverduePageComponent_Conditional_31_Template_mj_entity_viewer_RecordOpened_0_listener($event) { i0.ɵɵrestoreView(_r4); const ctx_r1 = i0.ɵɵnextContext(); return i0.ɵɵresetView(ctx_r1.OnRecordOpened($event)); });
37
85
  i0.ɵɵelementEnd();
38
86
  } if (rf & 2) {
39
- const ctx_r0 = i0.ɵɵnextContext();
40
- i0.ɵɵproperty("Entity", ctx_r0.OrderEntityInfo)("ViewEntity", ctx_r0.OverdueView)("GridState", ctx_r0.OrderGridState);
87
+ const ctx_r1 = i0.ɵɵnextContext();
88
+ i0.ɵɵproperty("Entity", ctx_r1.OrderEntityInfo)("ViewEntity", ctx_r1.OverdueView)("GridState", ctx_r1.OrderGridState);
41
89
  } }
42
- function MJOOverduePageComponent_Conditional_21_Template(rf, ctx) { if (rf & 1) {
43
- i0.ɵɵelementStart(0, "div", 16);
90
+ function MJOOverduePageComponent_Conditional_32_Template(rf, ctx) { if (rf & 1) {
91
+ i0.ɵɵelementStart(0, "div", 23);
44
92
  i0.ɵɵtext(1, "Loading overdue orders...");
45
93
  i0.ɵɵelementEnd();
46
94
  } }
95
+ /**
96
+ * How late the orders listed are. The three bands are the aging bar's: choosing one lists the orders
97
+ * that have an amount that late and totals that amount, so the list, the tile and the bar's band are
98
+ * the same money. Custom due dates go by each order's oldest invoiced, past-due installment.
99
+ */
100
+ export const OVERDUE_WINDOWS = [
101
+ { Key: 'all', Label: 'Any age', FromOffset: null, ToOffset: null },
102
+ { Key: '1-30', Label: '1 to 30 days', FromOffset: -30, ToOffset: -1 },
103
+ { Key: '31-60', Label: '31 to 60 days', FromOffset: -60, ToOffset: -31 },
104
+ { Key: '61+', Label: '61 days or more', FromOffset: null, ToOffset: -61 },
105
+ { Key: CUSTOM_WINDOW, Label: 'Custom due dates…', FromOffset: null, ToOffset: null },
106
+ ];
107
+ const DEFAULT_WINDOW = { Key: 'all', From: null, To: null };
108
+ const OVERDUE_STATE_KEY = 'mjOrders.overdueWorklist.view';
109
+ /** The tab-address key for this page's age filter. */
110
+ const AGE_ADDRESS_KEY = 'overdueAge';
111
+ /** The aging bar's bands and the age choices are the same three ranges. */
112
+ const BUCKET_WINDOW = { Days1To30: '1-30', Days31To60: '31-60', Days61Plus: '61+' };
113
+ /**
114
+ * The orders the grid may list, as SQL: exactly the ones the page lists, by ID. The grid reads the
115
+ * orders itself, and the page's rules (invoiced amounts only, company, age, credit) are worked out
116
+ * here from the installments, so the grid is handed the result and not a second statement of them.
117
+ * IDs are checked as UUIDs before they are written.
118
+ */
119
+ export function OverdueGridScope(orderIDs) {
120
+ if (!orderIDs.length)
121
+ return '1 = 0';
122
+ return `ID IN (${orderIDs.map((id) => `'${RequireUUID(id, 'OrderHeaderID')}'`).join(',')})`;
123
+ }
47
124
  /**
48
125
  * `mjo-overdue-page` — chase what is late.
49
126
  *
50
- * A WORKLIST, NOT A REPORT. Rows are ordered by what to do next rather than by
51
- * size — the biggest debt is not always the most at risk, and sorting by amount
52
- * buries the small invoice nobody has touched in four months.
127
+ * OVERDUE MEANS INVOICED AND PAST ITS DATE, as on Customer A/R (bc-aidp-next-golive#481). The
128
+ * operation lists an order once its next unpaid installment's date has passed, invoiced or not, and
129
+ * reports the whole balance. This page reads the installments too and restates each order
130
+ * (`overdue-page.model.ts`): only invoiced amounts past their own due date are counted, each aged
131
+ * from its own date. An order whose only late installments were never invoiced is not chased; it is
132
+ * counted on its own tile, which leads to the Billing worklist where the invoice is issued.
133
+ *
134
+ * THE TILES AND THE AGING BAR ARE THE FILTERS. A band of the bar shows only orders that old; the
135
+ * credit tile shows only customers holding credit. The company filter is the one every Receivables
136
+ * page shares. Whatever is chosen narrows the tiles, the grid and the export together. The bar keeps
137
+ * showing every age under an age band, with the other bands dimmed: it is what the band is chosen from.
53
138
  *
54
- * The suggested next action is computed per row from what is actually known:
55
- * whether the customer is already holding credit, whether anyone has contacted
56
- * them, how late it is. The FIRST rule is the one that matters most — if they
57
- * hold a credit, spend it before chasing cash, because that collects without a
58
- * conversation.
139
+ * The suggested next action is computed per row from what is actually known: whether the customer is
140
+ * already holding credit, whether a grace period is running, how late it is. The FIRST rule is the
141
+ * one that matters most — if they hold a credit, spend it before chasing cash, because that collects
142
+ * without a conversation.
59
143
  *
60
144
  * DUNNING NOTIFIES A PERSON; NOTHING AUTO-CANCELS. A failed card is usually an
61
145
  * expired card rather than a lost customer, and cancelling on the system's
@@ -64,7 +148,7 @@ function MJOOverduePageComponent_Conditional_21_Template(rf, ctx) { if (rf & 1)
64
148
  * ## Example
65
149
  *
66
150
  * ```html
67
- * <mjo-overdue-page (OrderOpened)="open($event)" />
151
+ * <mjo-overdue-page (OrderOpened)="open($event)" (NavigateRequested)="go($event)" (AddressChanged)="write($event)" />
68
152
  * ```
69
153
  */
70
154
  export class MJOOverduePageComponent {
@@ -77,14 +161,50 @@ export class MJOOverduePageComponent {
77
161
  cdr = inject(ChangeDetectorRef);
78
162
  /** Non-null when the worklist could not be read. Rendered instead of the aging bar. */
79
163
  LoadError = null;
164
+ /** Non-null when the installments could not be read, so the orders are shown as the operation returned them. */
165
+ InstalmentsError = null;
80
166
  OrderOpened = new EventEmitter();
167
+ /** Go to another Receivables page, by its id in the rail. */
168
+ NavigateRequested = new EventEmitter();
169
+ /** The company choice or the age filter changed: the section writes it to the tab's address. A null value removes the key. */
170
+ AddressChanged = new EventEmitter();
81
171
  OrderEntityInfo = null;
82
172
  OrderGridState = MJO_ORDER_HEADER_GRID_STATE;
173
+ /** Every order the operation returned. */
83
174
  AllRows = [];
175
+ /** The orders with an invoiced amount past due, restated by installment. */
176
+ Listed = [];
177
+ /** `Listed` under the company filter, the age filter and the credit filter. The tiles, the grid and the export read these. */
84
178
  Rows = [];
179
+ /** Orders, under the company filter, whose only late installments were never invoiced. */
180
+ NeverInvoiced = [];
181
+ neverInvoicedAll = [];
85
182
  Buckets = { Current: 0, Days1To30: 0, Days31To60: 0, Days61Plus: 0 };
86
183
  Truncated = false;
87
- Preset = 'all';
184
+ Loading = false;
185
+ Windows = OVERDUE_WINDOWS;
186
+ Companies = [];
187
+ /** The chosen companies that are offered: what the filter shows. */
188
+ CompanyPicks = [];
189
+ /** The company choice as chosen, shared across Receivables. */
190
+ companyChoice = [];
191
+ Window = DEFAULT_WINDOW;
192
+ /** Show only customers who hold credit. */
193
+ CreditOnly = false;
194
+ /** The grid's extra filter: '' while the page lists everything the operation returned, else the listed orders by ID. */
195
+ gridScope = '';
196
+ /** Bumped by Refresh, so the grid is handed a new view and reads again along with the tiles. */
197
+ refreshCount = 0;
198
+ address = {};
199
+ companyKey = new AddressKey(COMPANY_ADDRESS_KEY);
200
+ ageKey = new AddressKey(AGE_ADDRESS_KEY);
201
+ /** Counts loads, so a slow answer to an earlier read cannot overwrite a later one. */
202
+ loadSeq = 0;
203
+ /**
204
+ * The first load has finished. The grid waits for it: before then the page does not know which
205
+ * orders it lists, and a grid shown early would list the operation's orders and then drop some.
206
+ */
207
+ Ready = false;
88
208
  /** Exposed so the template can stringify without a pipe. */
89
209
  String = String;
90
210
  overdueView = new PresetViewRef();
@@ -92,22 +212,48 @@ export class MJOOverduePageComponent {
92
212
  if (!this.OrderEntityInfo)
93
213
  return null;
94
214
  const today = Today();
215
+ const scope = this.gridScope ?? '';
95
216
  // Keyed on the DAY as well as the entity: the filter moves at midnight and the grid must follow.
96
- return this.overdueView.For(`${this.OrderEntityInfo.ID}|${today}`, () => ({
217
+ // And on what the page lists and the refresh count, so the grid reloads when either changes.
218
+ return this.overdueView.For(`${this.OrderEntityInfo.ID}|${today}|${scope}|${this.refreshCount ?? 0}`, () => ({
97
219
  EntityID: this.OrderEntityInfo.ID,
98
220
  Entity: this.OrderEntityInfo.Name,
99
221
  // ONE definition of overdue (overdue.ts), the same one the worklist operation filters by.
100
- WhereClause: OverdueFilter(today),
222
+ WhereClause: scope ? `${OverdueFilter(today)} AND ${scope}` : OverdueFilter(today),
101
223
  ID: 'preset-overdue-worklist',
102
224
  Name: 'Overdue Collections'
103
225
  }));
104
226
  }
105
227
  async ngOnInit() {
228
+ const saved = ReadWorklistState(globalThis.localStorage, OVERDUE_STATE_KEY);
229
+ if (saved)
230
+ this.Window = RestoreWindow(saved.Window, OVERDUE_WINDOWS, DEFAULT_WINDOW);
231
+ this.adoptAddress();
106
232
  const md = new Metadata();
107
233
  this.OrderEntityInfo = md.Entities.find((e) => e.Name === MJO_ENTITIES.OrderHeader) || null;
108
234
  await this.load();
235
+ // An address that arrived while that first load was out was kept, not followed. Follow it now.
236
+ this.adoptAddress();
237
+ this.applyView();
238
+ this.Ready = true;
109
239
  this.cdr.detectChanges();
110
240
  }
241
+ /** The tab's address, from the section: `company` is shared across Receivables, `overdueAge` is this page's age filter. */
242
+ ApplyAddress(params) {
243
+ this.address = params;
244
+ if (!this.Ready)
245
+ return;
246
+ this.adoptAddress();
247
+ this.applyView();
248
+ // Back, Forward and links arrive outside any event of this page's own, so nothing else repaints it.
249
+ this.cdr.detectChanges();
250
+ }
251
+ /** Shown again after another page: a payment or an invoice issued there changes what is overdue. */
252
+ async OnShown() {
253
+ if (!this.Ready)
254
+ return;
255
+ await this.Refresh();
256
+ }
111
257
  OnRecordOpened(event) {
112
258
  const id = (event.compositeKey?.GetValueByFieldName('ID') ?? event.record?.['ID']);
113
259
  if (id) {
@@ -115,33 +261,110 @@ export class MJOOverduePageComponent {
115
261
  this.OrderOpened.emit(surrogate);
116
262
  }
117
263
  }
118
- OnPreset(preset) {
119
- this.Preset = preset;
120
- this.applyPreset();
264
+ /* ── Filters ────────────────────────────────────────────────────────── */
265
+ OnCompanies(picks) {
266
+ this.companyChoice = picks;
267
+ WriteSharedCompanies(globalThis.localStorage, picks);
268
+ this.AddressChanged.emit(this.companyKey.Write(CompaniesToAddress(picks)));
269
+ this.applyView();
270
+ }
271
+ OnWindow(key) {
272
+ if (!OVERDUE_WINDOWS.some((o) => o.Key === key))
273
+ return;
274
+ this.Window = { Key: key, From: null, To: null };
275
+ // Custom is not a choice until it has a day: nothing is saved or written to the address before then.
276
+ if (key !== CUSTOM_WINDOW)
277
+ this.saveView();
278
+ this.applyView();
279
+ }
280
+ OnCustomDay(side, day) {
281
+ this.Window = { ...this.Window, Key: CUSTOM_WINDOW, [side]: day || null };
282
+ this.saveView();
283
+ this.applyView();
284
+ }
285
+ /** A band of the aging bar lists only orders that old; the same band again lists every age. */
286
+ OnBucket(bucket) {
287
+ const key = BUCKET_WINDOW[bucket];
288
+ if (!key)
289
+ return;
290
+ this.OnWindow(this.Window.Key === key ? 'all' : key);
291
+ }
292
+ OnCreditOnly(on) {
293
+ this.CreditOnly = on;
294
+ this.applyView();
295
+ }
296
+ /** The Past due tile: every age, credit or not. The company filter stays. */
297
+ OnShowAll() {
298
+ this.CreditOnly = false;
299
+ this.OnWindow('all');
300
+ }
301
+ /** Read the worklist again, and hand the grid a new view so it reads again too. */
302
+ async Refresh() {
303
+ this.refreshCount += 1;
304
+ await this.load();
305
+ this.cdr.detectChanges();
306
+ }
307
+ get IsCustomWindow() {
308
+ return this.Window.Key === CUSTOM_WINDOW;
309
+ }
310
+ /** The aging band the age filter is on, for the bar to mark. */
311
+ get ActiveBucket() {
312
+ const match = Object.entries(BUCKET_WINDOW).find(([, key]) => key === this.Window.Key);
313
+ return match ? match[0] : null;
121
314
  }
315
+ /** "12 of 28 orders shown", beside the filters. */
316
+ get Summary() {
317
+ return this.LoadError || (this.Loading && !this.AllRows.length) ? '' : ShownSummary(this.Rows.length, this.Listed.length, 'order');
318
+ }
319
+ /** The export's columns. It carries what the grid does not: the past-due amount, days overdue, credit held and the suggested next step. */
320
+ exportFields = [
321
+ { Name: 'OrderNumber', Label: 'Order', Value: (r) => r.OrderNumber },
322
+ { Name: 'CustomerName', Label: 'Customer', Value: (r) => r.CustomerName },
323
+ { Name: 'CompanyName', Label: 'Company', Value: (r) => r.CompanyName },
324
+ { Name: 'OrderDate', Label: 'Order date', Type: 'date', Value: (r) => r.OrderDate },
325
+ { Name: 'DueDate', Label: 'Oldest due date', Type: 'date', Value: (r) => r.DueDate },
326
+ { Name: 'DaysOverdue', Label: 'Days overdue', Type: 'number', Value: (r) => r.DaysOverdue },
327
+ { Name: 'PastDue', Label: 'Past due', Type: 'money', Value: (r) => r.PastDue },
328
+ // The same three figures the aging bar totals, so the file adds up to the bar and to the tile under an age band.
329
+ { Name: 'Days1To30', Label: 'Past due 1-30 days', Type: 'money', Value: (r) => r.Aged.Days1To30 },
330
+ { Name: 'Days31To60', Label: 'Past due 31-60 days', Type: 'money', Value: (r) => r.Aged.Days31To60 },
331
+ { Name: 'Days61Plus', Label: 'Past due 61+ days', Type: 'money', Value: (r) => r.Aged.Days61Plus },
332
+ { Name: 'Balance', Label: 'Order balance', Type: 'money', Value: (r) => r.Balance },
333
+ { Name: 'TotalGross', Label: 'Order total', Type: 'money', Value: (r) => r.TotalGross },
334
+ { Name: 'AmountPaid', Label: 'Paid', Type: 'money', Value: (r) => r.AmountPaid },
335
+ { Name: 'AvailableCredit', Label: 'Credit available', Type: 'money', Value: (r) => r.AvailableCredit },
336
+ { Name: 'NextStep', Label: 'Suggested next step', Value: (r) => this.nextAction(r).Text },
337
+ { Name: 'GraceThroughDate', Label: 'Grace period ends', Type: 'date', Value: (r) => r.GraceThroughDate },
338
+ { Name: 'SalesRepName', Label: 'Sales rep', Value: (r) => r.SalesRepName },
339
+ { Name: 'Description', Label: 'Description', Value: (r) => r.Description },
340
+ ];
341
+ /** The orders listed, most overdue first, as an export file. A field, so the bar gets the same function every pass. */
342
+ BuildExport = (format) => ({
343
+ FileName: ExportFileName('overdue-worklist', this.CompanyPicks, this.Companies, Today()),
344
+ ...BuildWorklistExport(this.exportFields, this.Rows, format),
345
+ });
122
346
  /* ── Tiles ──────────────────────────────────────────────────────────── */
347
+ /** Past due across the orders listed; under an age band, the amount that is that late, which is the band's own figure. */
123
348
  get TotalDisplay() {
124
- return FormatMoney(this.AllRows.reduce((s, r) => s + r.Balance, 0), { Round: true });
349
+ const band = this.ActiveBucket;
350
+ return FormatMoney(this.Rows.reduce((s, r) => s + (band ? r.Aged[band] : r.PastDue), 0), { Round: true });
125
351
  }
126
352
  get TotalDetail() {
127
- const customers = new Set(this.AllRows.map((r) => r.CustomerName)).size;
128
- return `${this.AllRows.length} order${this.AllRows.length === 1 ? '' : 's'} across ${customers} customer${customers === 1 ? '' : 's'}`;
353
+ const customers = new Set(this.Rows.map((r) => r.CustomerName)).size;
354
+ const counts = `${this.Rows.length} order${this.Rows.length === 1 ? '' : 's'}, ${customers} customer${customers === 1 ? '' : 's'}`;
355
+ const band = OVERDUE_WINDOWS.find((o) => o.Key === this.Window.Key && this.ActiveBucket);
356
+ return band ? `${band.Label} late · ${counts}` : `Invoiced and past its due date · ${counts}`;
129
357
  }
130
358
  get OldestDisplay() {
131
- const oldest = Math.max(0, ...this.AllRows.map((r) => r.DaysOverdue));
132
- return oldest ? `${oldest}d` : '—';
359
+ const oldest = Math.max(0, ...this.Rows.map((r) => r.DaysOverdue));
360
+ return oldest ? `${oldest} day${oldest === 1 ? '' : 's'}` : '—';
133
361
  }
134
362
  get OldestDetail() {
135
- const oldest = this.AllRows.slice().sort((a, b) => b.DaysOverdue - a.DaysOverdue)[0];
363
+ const oldest = this.Rows[0];
136
364
  return oldest ? `${oldest.OrderNumber} · ${oldest.CustomerName}` : 'Nothing overdue';
137
365
  }
138
- /** Overdue rows with no subscription attached: one-time orders rather than renewals. */
139
- get OverdueOneTimeOrders() {
140
- return this.AllRows.filter((r) => !r.SubscriptionID && r.DaysOverdue > 0).length;
141
- }
142
366
  get CreditDisplay() {
143
- const total = this.AllRows.reduce((s, r) => s + r.AvailableCredit, 0);
144
- return FormatMoney(total, { Zero: '—' });
367
+ return FormatMoney(CreditHeld(this.Rows), { Zero: '—' });
145
368
  }
146
369
  /* ── Next action ────────────────────────────────────────────────────── */
147
370
  /**
@@ -159,7 +382,7 @@ export class MJOOverduePageComponent {
159
382
  if (row.GraceThroughDate) {
160
383
  return {
161
384
  Icon: 'fa-solid fa-hourglass-half',
162
- Text: `Call before grace period ends ${FormatDate(row.GraceThroughDate, { Short: true })}`,
385
+ Text: `Call before grace period ends ${FormatDate(row.GraceThroughDate, { Numeric: true })}`,
163
386
  Tone: 'warning',
164
387
  };
165
388
  }
@@ -175,103 +398,211 @@ export class MJOOverduePageComponent {
175
398
  async load() {
176
399
  // The worklist is assembled server-side: overdue is computed from the
177
400
  // clock, so there is no column a client could filter on.
178
- const op = new OrdersGetOverdueWorklistOperation();
179
- const result = await op.Execute({});
180
- if (!result.Success || !result.Output) {
181
- // SAY SO. An empty worklist and a failed one look identical — both
182
- // render "Nothing overdue", which is the single most reassuring
183
- // sentence on the screen. Reporting a clean collections desk because
184
- // a server call failed is worse than reporting nothing at all.
185
- this.LoadError =
186
- result.ErrorMessage?.trim() ||
187
- 'The overdue worklist could not be loaded.';
188
- this.AllRows = [];
189
- this.Rows = [];
401
+ const seq = ++this.loadSeq;
402
+ this.Loading = true;
403
+ this.cdr.detectChanges();
404
+ try {
405
+ // The installments ride along so each order can be restated the way Customer A/R reads it.
406
+ // They are context for the list, not the list: if they cannot be read, the orders still show.
407
+ const [result, instalments] = await Promise.all([
408
+ new OrdersGetOverdueWorklistOperation().Execute({}),
409
+ GetOpenInstalmentDetails().then((rows) => ({ Rows: rows, Error: null }), (err) => ({ Rows: null, Error: err instanceof Error ? err.message : String(err) })),
410
+ ]);
411
+ if (seq !== this.loadSeq)
412
+ return;
413
+ if (!result.Success || !result.Output) {
414
+ // SAY SO. An empty worklist and a failed one look identical — both
415
+ // render "Nothing overdue", which is the single most reassuring
416
+ // sentence on the screen. Reporting a clean collections desk because
417
+ // a server call failed is worse than reporting nothing at all.
418
+ this.LoadError =
419
+ result.ErrorMessage?.trim() ||
420
+ 'The overdue worklist could not be loaded.';
421
+ this.AllRows = [];
422
+ this.Listed = [];
423
+ this.neverInvoicedAll = [];
424
+ this.applyView();
425
+ this.cdr.detectChanges();
426
+ return;
427
+ }
428
+ this.LoadError = null;
429
+ this.InstalmentsError = instalments.Error;
430
+ this.AllRows = result.Output.Rows;
431
+ this.Truncated = result.Output.Truncated;
432
+ const book = RestateOverdue(this.AllRows, instalments.Rows ? GroupInstalmentsByOrder(instalments.Rows) : null, Today());
433
+ this.Listed = book.Rows;
434
+ this.neverInvoicedAll = book.NeverInvoiced;
435
+ this.applyView();
436
+ this.cdr.detectChanges();
437
+ }
438
+ finally {
439
+ if (seq === this.loadSeq)
440
+ this.Loading = false;
190
441
  this.cdr.detectChanges();
191
- return;
192
442
  }
193
- this.LoadError = null;
194
- this.AllRows = result.Output.Rows;
195
- this.Buckets = {
196
- Current: result.Output.Buckets.Current,
197
- Days1To30: result.Output.Buckets.Days1To30,
198
- Days31To60: result.Output.Buckets.Days31To60,
199
- Days61Plus: result.Output.Buckets.Days61Plus,
200
- };
201
- this.Truncated = result.Output.Truncated;
202
- this.applyPreset();
203
- this.cdr.detectChanges();
204
443
  }
205
- applyPreset() {
206
- this.Rows = this.AllRows.filter((row) => {
207
- switch (this.Preset) {
208
- case 't1':
209
- return row.DaysOverdue >= 1 && row.DaysOverdue <= 30;
210
- case 't2':
211
- return row.DaysOverdue > 30 && row.DaysOverdue <= 60;
212
- case 't3':
213
- return row.DaysOverdue > 60;
214
- case 'credit':
215
- return row.AvailableCredit > 0;
216
- default:
217
- return true;
218
- }
219
- });
444
+ /** Take the company choice and the age filter from the tab's address; see the Billing worklist for the rule. */
445
+ adoptAddress() {
446
+ const picks = AdoptCompanyChoice(this.companyKey, this.address, globalThis.localStorage);
447
+ if (!SameChoice(picks, this.companyChoice))
448
+ this.companyChoice = picks;
449
+ const window = AdoptWindow(this.ageKey, this.address, OVERDUE_WINDOWS, this.Window, DEFAULT_WINDOW);
450
+ if (!SameWindow(window, this.Window)) {
451
+ this.Window = window;
452
+ // Saved as well, so the next visit opens on what the address last said, as it does for the company.
453
+ WriteWorklistState(globalThis.localStorage, OVERDUE_STATE_KEY, { Window: this.Window, Sort: { Key: null, Descending: false } });
454
+ }
455
+ }
456
+ /**
457
+ * Narrow the listed orders to the chosen companies, credit and age, total the aging bar (before
458
+ * an age band is applied, so the band stays one part of a whole), and tell the grid which orders are listed. The company filter offers every company the
459
+ * operation returned, so one whose late installments are all uninvoiced can still be chosen.
460
+ */
461
+ applyView() {
462
+ const companies = ReconcileCompanies(this.AllRows, { ID: (r) => r.CompanyID, Name: (r) => r.CompanyName }, this.companyChoice);
463
+ this.Companies = companies.Options;
464
+ this.CompanyPicks = companies.Picks;
465
+ const band = this.ActiveBucket;
466
+ const scoped = FilterByCompanies(this.Listed, this.CompanyPicks, (r) => r.CompanyID).filter((r) => !this.CreditOnly || r.AvailableCredit > 0);
467
+ // Custom due dates go by each order's oldest late installment. A band does not narrow the bar:
468
+ // the bar is what the band is chosen from, so it keeps showing every age, with the others dimmed.
469
+ const range = ResolveWindow(this.Window, OVERDUE_WINDOWS, Today());
470
+ const dated = band ? scoped : scoped.filter((r) => InDayRange(r.DueDate, range));
471
+ this.Buckets = SumAged(dated);
472
+ // An order belongs to a band when it has an amount that late, whatever else it owes.
473
+ this.Rows = band ? dated.filter((r) => r.Aged[band] > 0) : dated;
474
+ this.NeverInvoiced = FilterByCompanies(this.neverInvoicedAll, this.CompanyPicks, (r) => r.CompanyID);
475
+ // The grid lists what the operation lists unless the page lists fewer; then it is told which.
476
+ this.gridScope = this.Rows.length === this.AllRows.length ? '' : OverdueGridScope(this.Rows.map((r) => r.OrderHeaderID));
477
+ }
478
+ saveView() {
479
+ WriteWorklistState(globalThis.localStorage, OVERDUE_STATE_KEY, { Window: this.Window, Sort: { Key: null, Descending: false } });
480
+ this.AddressChanged.emit(this.ageKey.Write(SameWindow(this.Window, DEFAULT_WINDOW) ? null : WindowToAddress(this.Window)));
220
481
  }
221
482
  static ɵfac = function MJOOverduePageComponent_Factory(__ngFactoryType__) { return new (__ngFactoryType__ || MJOOverduePageComponent)(); };
222
- static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: MJOOverduePageComponent, selectors: [["mjo-overdue-page"]], outputs: { OrderOpened: "OrderOpened" }, decls: 22, vars: 10, consts: [[1, "mj-stat-grid", "mjo-ov__tiles"], ["Label", "Total overdue", "Icon", "fa-solid fa-hourglass-half", "Tone", "alert", 3, "Value", "Detail"], ["Label", "Oldest", "Icon", "fa-solid fa-clock", 3, "Value", "Detail"], ["Label", "Overdue one-time orders", "Icon", "fa-regular fa-envelope", "Detail", "No subscription attached", 3, "Value"], ["Label", "Credit available to apply", "Icon", "fa-solid fa-piggy-bank", "Detail", "Apply before following up", 3, "Value"], ["Variant", "error", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-ov__error"], [1, "mjo-note", "mjo-ov__error"], ["aria-hidden", "true", 1, "fa-solid", "fa-circle-info"], [1, "mj-card", "mjo-ov__aging"], [1, "mj-card-head"], ["aria-hidden", "true", 1, "fa-solid", "fa-chart-column"], [1, "mj-card-pad"], [3, "Buckets"], ["Variant", "warning", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-ov__truncated"], [1, "mjo-ov__viewer-host"], [3, "Entity", "ViewEntity", "GridState"], [1, "small", "muted", 2, "padding", "24px"], [3, "RecordOpened", "Entity", "ViewEntity", "GridState"]], template: function MJOOverduePageComponent_Template(rf, ctx) { if (rf & 1) {
223
- i0.ɵɵelementStart(0, "div", 0);
224
- i0.ɵɵelement(1, "mjo-stat-tile", 1)(2, "mjo-stat-tile", 2)(3, "mjo-stat-tile", 3)(4, "mjo-stat-tile", 4);
483
+ static ɵcmp = /*@__PURE__*/ i0.ɵɵdefineComponent({ type: MJOOverduePageComponent, selectors: [["mjo-overdue-page"]], outputs: { OrderOpened: "OrderOpened", NavigateRequested: "NavigateRequested", AddressChanged: "AddressChanged" }, decls: 35, vars: 26, consts: [[3, "CompanyPicksChange", "ActiveFilterCleared", "RefreshRequested", "Companies", "CompanyPicks", "Searchable", "ActiveFilter", "Summary", "Loading", "BuildExport", "CanExport"], [1, "mjo-ov__window"], [1, "small", "muted"], ["aria-label", "How late the orders listed are", 1, "mjo-ov__select", 3, "change", "value"], [3, "value", "selected"], [1, "mj-stat-grid", "mjo-ov__tiles"], ["Hint", "Show every overdue order", "Label", "Past due", "Icon", "fa-solid fa-hourglass-half", "Tone", "alert", 1, "mjo-ov__tile", 3, "Clicked", "Value", "Detail"], ["Label", "Oldest", "Icon", "fa-solid fa-clock", 3, "Value", "Detail"], ["Hint", "Show customers who hold credit", "Label", "Credit available to apply", "Icon", "fa-solid fa-piggy-bank", "Detail", "Apply before following up", 1, "mjo-ov__tile", 3, "Clicked", "Pressed", "Value"], ["Hint", "Open the Billing worklist", "Label", "Late, not yet invoiced", "Icon", "fa-solid fa-file-invoice-dollar", 1, "mjo-ov__tile", 3, "Clicked", "Value", "Detail"], ["Variant", "error", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-ov__error"], ["Variant", "warning", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-ov__error"], [1, "mjo-note", "mjo-ov__error"], ["aria-hidden", "true", 1, "fa-solid", "fa-circle-info"], [1, "mj-card", "mjo-ov__aging"], [1, "mj-card-head"], ["aria-hidden", "true", 1, "fa-solid", "fa-chart-column"], [1, "right", "small", "muted"], [1, "mj-card-pad"], ["EmptyText", "Nothing overdue.", 3, "BucketClicked", "Buckets", "Active"], ["Variant", "warning", "Icon", "fa-solid fa-triangle-exclamation", 1, "mjo-ov__truncated"], [1, "mjo-ov__viewer-host"], [3, "Entity", "ViewEntity", "GridState"], [1, "small", "muted", 2, "padding", "24px"], [1, "small", "muted", "mjo-ov__foot"], ["type", "date", "aria-label", "Earliest due date", 1, "mjo-ov__select", 3, "change", "value"], ["type", "date", "aria-label", "Latest due date", 1, "mjo-ov__select", 3, "change", "value"], [3, "RecordOpened", "Entity", "ViewEntity", "GridState"]], template: function MJOOverduePageComponent_Template(rf, ctx) { if (rf & 1) {
484
+ i0.ɵɵelementStart(0, "mjo-worklist-bar", 0);
485
+ i0.ɵɵlistener("CompanyPicksChange", function MJOOverduePageComponent_Template_mjo_worklist_bar_CompanyPicksChange_0_listener($event) { return ctx.OnCompanies($event); })("ActiveFilterCleared", function MJOOverduePageComponent_Template_mjo_worklist_bar_ActiveFilterCleared_0_listener() { return ctx.OnCreditOnly(false); })("RefreshRequested", function MJOOverduePageComponent_Template_mjo_worklist_bar_RefreshRequested_0_listener() { return ctx.Refresh(); });
486
+ i0.ɵɵelementStart(1, "label", 1)(2, "span", 2);
487
+ i0.ɵɵtext(3, "Overdue by");
488
+ i0.ɵɵelementEnd();
489
+ i0.ɵɵelementStart(4, "select", 3);
490
+ i0.ɵɵlistener("change", function MJOOverduePageComponent_Template_select_change_4_listener($event) { return ctx.OnWindow($event.target.value); });
491
+ i0.ɵɵrepeaterCreate(5, MJOOverduePageComponent_For_6_Template, 2, 3, "option", 4, _forTrack0);
492
+ i0.ɵɵelementEnd()();
493
+ i0.ɵɵconditionalCreate(7, MJOOverduePageComponent_Conditional_7_Template, 8, 2);
225
494
  i0.ɵɵelementEnd();
226
- i0.ɵɵconditionalCreate(5, MJOOverduePageComponent_Conditional_5_Template, 4, 1, "mj-alert", 5);
227
- i0.ɵɵelementStart(6, "p", 6);
228
- i0.ɵɵelement(7, "i", 7);
229
- i0.ɵɵelementStart(8, "strong");
230
- i0.ɵɵtext(9, "Reminders notify the customer.");
495
+ i0.ɵɵelementStart(8, "div", 5)(9, "mjo-stat-tile", 6);
496
+ i0.ɵɵlistener("Clicked", function MJOOverduePageComponent_Template_mjo_stat_tile_Clicked_9_listener() { return ctx.OnShowAll(); });
231
497
  i0.ɵɵelementEnd();
232
- i0.ɵɵtext(10, " Nothing on this screen cancels an order or subscription. ");
498
+ i0.ɵɵelement(10, "mjo-stat-tile", 7);
499
+ i0.ɵɵelementStart(11, "mjo-stat-tile", 8);
500
+ i0.ɵɵlistener("Clicked", function MJOOverduePageComponent_Template_mjo_stat_tile_Clicked_11_listener() { return ctx.OnCreditOnly(!ctx.CreditOnly); });
233
501
  i0.ɵɵelementEnd();
234
- i0.ɵɵelementStart(11, "div", 8)(12, "div", 9);
235
- i0.ɵɵelement(13, "i", 10);
236
- i0.ɵɵelementStart(14, "h3");
237
- i0.ɵɵtext(15, "By age");
502
+ i0.ɵɵelementStart(12, "mjo-stat-tile", 9);
503
+ i0.ɵɵlistener("Clicked", function MJOOverduePageComponent_Template_mjo_stat_tile_Clicked_12_listener() { return ctx.NavigateRequested.emit("billing"); });
238
504
  i0.ɵɵelementEnd()();
239
- i0.ɵɵelementStart(16, "div", 11);
240
- i0.ɵɵelement(17, "mjo-aging-bar", 12);
505
+ i0.ɵɵconditionalCreate(13, MJOOverduePageComponent_Conditional_13_Template, 4, 1, "mj-alert", 10);
506
+ i0.ɵɵconditionalCreate(14, MJOOverduePageComponent_Conditional_14_Template, 4, 1, "mj-alert", 11);
507
+ i0.ɵɵelementStart(15, "p", 12);
508
+ i0.ɵɵelement(16, "i", 13);
509
+ i0.ɵɵelementStart(17, "strong");
510
+ i0.ɵɵtext(18, "Reminders notify the customer.");
511
+ i0.ɵɵelementEnd();
512
+ i0.ɵɵtext(19, " Nothing on this screen cancels an order or subscription. ");
513
+ i0.ɵɵelementEnd();
514
+ i0.ɵɵelementStart(20, "div", 14)(21, "div", 15);
515
+ i0.ɵɵelement(22, "i", 16);
516
+ i0.ɵɵelementStart(23, "h3");
517
+ i0.ɵɵtext(24, "By age");
518
+ i0.ɵɵelementEnd();
519
+ i0.ɵɵelementStart(25, "span", 17);
520
+ i0.ɵɵtext(26, "Select an age to list the orders with an amount that late");
241
521
  i0.ɵɵelementEnd()();
242
- i0.ɵɵconditionalCreate(18, MJOOverduePageComponent_Conditional_18_Template, 4, 0, "mj-alert", 13);
243
- i0.ɵɵelementStart(19, "div", 14);
244
- i0.ɵɵconditionalCreate(20, MJOOverduePageComponent_Conditional_20_Template, 1, 3, "mj-entity-viewer", 15)(21, MJOOverduePageComponent_Conditional_21_Template, 2, 0, "div", 16);
522
+ i0.ɵɵelementStart(27, "div", 18)(28, "mjo-aging-bar", 19);
523
+ i0.ɵɵlistener("BucketClicked", function MJOOverduePageComponent_Template_mjo_aging_bar_BucketClicked_28_listener($event) { return ctx.OnBucket($event); });
524
+ i0.ɵɵelementEnd()()();
525
+ i0.ɵɵconditionalCreate(29, MJOOverduePageComponent_Conditional_29_Template, 4, 0, "mj-alert", 20);
526
+ i0.ɵɵelementStart(30, "div", 21);
527
+ i0.ɵɵconditionalCreate(31, MJOOverduePageComponent_Conditional_31_Template, 1, 3, "mj-entity-viewer", 22)(32, MJOOverduePageComponent_Conditional_32_Template, 2, 0, "div", 23);
528
+ i0.ɵɵelementEnd();
529
+ i0.ɵɵelementStart(33, "div", 24);
530
+ i0.ɵɵtext(34, "Balance is each order's whole open balance. Past due, above and in the export, counts only invoiced amounts past their due date.");
245
531
  i0.ɵɵelementEnd();
246
532
  } if (rf & 2) {
533
+ i0.ɵɵproperty("Companies", ctx.Companies)("CompanyPicks", ctx.CompanyPicks)("Searchable", false)("ActiveFilter", ctx.CreditOnly ? "Credit available" : null)("Summary", ctx.Summary)("Loading", ctx.Loading)("BuildExport", ctx.BuildExport)("CanExport", ctx.Rows.length > 0);
534
+ i0.ɵɵadvance(4);
535
+ i0.ɵɵproperty("value", ctx.Window.Key);
247
536
  i0.ɵɵadvance();
537
+ i0.ɵɵrepeater(ctx.Windows);
538
+ i0.ɵɵadvance(2);
539
+ i0.ɵɵconditional(ctx.IsCustomWindow ? 7 : -1);
540
+ i0.ɵɵadvance(2);
248
541
  i0.ɵɵproperty("Value", ctx.TotalDisplay)("Detail", ctx.TotalDetail);
249
542
  i0.ɵɵadvance();
250
543
  i0.ɵɵproperty("Value", ctx.OldestDisplay)("Detail", ctx.OldestDetail);
251
544
  i0.ɵɵadvance();
252
- i0.ɵɵproperty("Value", ctx.String(ctx.OverdueOneTimeOrders));
545
+ i0.ɵɵclassProp("is-on", ctx.CreditOnly);
546
+ i0.ɵɵproperty("Pressed", ctx.CreditOnly)("Value", ctx.CreditDisplay);
253
547
  i0.ɵɵadvance();
254
- i0.ɵɵproperty("Value", ctx.CreditDisplay);
548
+ i0.ɵɵproperty("Value", ctx.String(ctx.NeverInvoiced.length))("Detail", ctx.NeverInvoiced.length ? "Not counted here \u00B7 issue on the Billing worklist" : "Every late installment has an invoice");
255
549
  i0.ɵɵadvance();
256
- i0.ɵɵconditional(ctx.LoadError ? 5 : -1);
257
- i0.ɵɵadvance(12);
258
- i0.ɵɵproperty("Buckets", ctx.Buckets);
550
+ i0.ɵɵconditional(ctx.LoadError ? 13 : -1);
259
551
  i0.ɵɵadvance();
260
- i0.ɵɵconditional(ctx.Truncated ? 18 : -1);
552
+ i0.ɵɵconditional(ctx.InstalmentsError ? 14 : -1);
553
+ i0.ɵɵadvance(14);
554
+ i0.ɵɵproperty("Buckets", ctx.Buckets)("Active", ctx.ActiveBucket);
555
+ i0.ɵɵadvance();
556
+ i0.ɵɵconditional(ctx.Truncated ? 29 : -1);
261
557
  i0.ɵɵadvance(2);
262
- i0.ɵɵconditional(ctx.OrderEntityInfo ? 20 : 21);
263
- } }, dependencies: [CommonModule, EntityViewerModule, i1.EntityViewerComponent, MJOAgingBarComponent, MJOStatTileComponent, MJAlertComponent], styles: ["[_nghost-%COMP%] {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-ov__tiles[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-ov__error[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-ov__aging[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-ov__truncated[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-ov__viewer-host[_ngcontent-%COMP%] {\n height: 600px;\n min-height: 500px;\n background: var(--mj-bg-surface);\n border: 1px solid var(--mj-border-default);\n border-radius: var(--mj-radius-md);\n overflow: hidden;\n margin-top: var(--mj-space-4);\n display: flex;\n flex-direction: column;\n }\n mj-entity-viewer[_ngcontent-%COMP%] {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n height: 100%;\n width: 100%;\n }\n @media (max-width: 760px) {\n [_nghost-%COMP%] { padding: var(--mj-space-4); }\n }"] });
558
+ i0.ɵɵconditional(ctx.OrderEntityInfo && ctx.Ready ? 31 : 32);
559
+ } }, dependencies: [CommonModule, EntityViewerModule, i1.EntityViewerComponent, MJOAgingBarComponent, MJOStatTileComponent, MJAlertComponent, MJOWorklistBarComponent], styles: ["[_nghost-%COMP%] {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-ov__tiles[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-ov__tile[_ngcontent-%COMP%] {\n display: block;\n border-radius: var(--mj-radius-md);\n transition: box-shadow 140ms ease;\n }\n .mjo-ov__tile.is-on[_ngcontent-%COMP%] { box-shadow: 0 0 0 2px color-mix(in srgb, var(--mj-brand-primary) 55%, transparent); }\n .mjo-ov__error[_ngcontent-%COMP%] { display: block; margin-bottom: var(--mj-space-4); }\n .mjo-ov__aging[_ngcontent-%COMP%] { margin-bottom: var(--mj-space-4); }\n .mjo-ov__truncated[_ngcontent-%COMP%] { display: block; margin-bottom: var(--mj-space-4); }\n .mjo-ov__foot[_ngcontent-%COMP%] { margin-top: var(--mj-space-3); }\n .mjo-ov__window[_ngcontent-%COMP%] {\n display: inline-flex;\n align-items: center;\n gap: var(--mj-space-2);\n }\n .mjo-ov__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-ov__viewer-host[_ngcontent-%COMP%] {\n height: 600px;\n min-height: 500px;\n background: var(--mj-bg-surface);\n border: 1px solid var(--mj-border-default);\n border-radius: var(--mj-radius-md);\n overflow: hidden;\n margin-top: var(--mj-space-4);\n display: flex;\n flex-direction: column;\n }\n mj-entity-viewer[_ngcontent-%COMP%] {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n height: 100%;\n width: 100%;\n }\n @media (max-width: 760px) {\n [_nghost-%COMP%] { padding: var(--mj-space-4); }\n }\n @media (prefers-reduced-motion: reduce) {\n .mjo-ov__tile[_ngcontent-%COMP%] { transition: none; }\n }"] });
264
560
  }
265
561
  (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassMetadata(MJOOverduePageComponent, [{
266
562
  type: Component,
267
- args: [{ selector: 'mjo-overdue-page', standalone: true, imports: [CommonModule, EntityViewerModule, MJOAgingBarComponent, MJOStatTileComponent, MJAlertComponent], template: `
563
+ args: [{ selector: 'mjo-overdue-page', standalone: true, imports: [CommonModule, EntityViewerModule, MJOAgingBarComponent, MJOStatTileComponent, MJAlertComponent, MJOWorklistBarComponent], template: `
564
+ <mjo-worklist-bar
565
+ [Companies]="Companies"
566
+ [CompanyPicks]="CompanyPicks"
567
+ [Searchable]="false"
568
+ [ActiveFilter]="CreditOnly ? 'Credit available' : null"
569
+ [Summary]="Summary"
570
+ [Loading]="Loading"
571
+ [BuildExport]="BuildExport"
572
+ [CanExport]="Rows.length > 0"
573
+ (CompanyPicksChange)="OnCompanies($event)"
574
+ (ActiveFilterCleared)="OnCreditOnly(false)"
575
+ (RefreshRequested)="Refresh()">
576
+ <label class="mjo-ov__window">
577
+ <span class="small muted">Overdue by</span>
578
+ <select class="mjo-ov__select" [value]="Window.Key" (change)="OnWindow($any($event.target).value)" aria-label="How late the orders listed are">
579
+ @for (option of Windows; track option.Key) {
580
+ <option [value]="option.Key" [selected]="option.Key === Window.Key">{{ option.Label }}</option>
581
+ }
582
+ </select>
583
+ </label>
584
+ @if (IsCustomWindow) {
585
+ <label class="mjo-ov__window">
586
+ <span class="small muted">Due from</span>
587
+ <input class="mjo-ov__select" type="date" [value]="Window.From ?? ''" (change)="OnCustomDay('From', $any($event.target).value)" aria-label="Earliest due date">
588
+ </label>
589
+ <label class="mjo-ov__window">
590
+ <span class="small muted">to</span>
591
+ <input class="mjo-ov__select" type="date" [value]="Window.To ?? ''" (change)="OnCustomDay('To', $any($event.target).value)" aria-label="Latest due date">
592
+ </label>
593
+ }
594
+ </mjo-worklist-bar>
595
+
268
596
  <div class="mj-stat-grid mjo-ov__tiles">
269
597
  <mjo-stat-tile
270
- Label="Total overdue"
598
+ class="mjo-ov__tile"
599
+ Hint="Show every overdue order"
600
+ Label="Past due"
271
601
  Icon="fa-solid fa-hourglass-half"
272
602
  Tone="alert"
273
603
  [Value]="TotalDisplay"
274
- [Detail]="TotalDetail" />
604
+ [Detail]="TotalDetail"
605
+ (Clicked)="OnShowAll()" />
275
606
 
276
607
  <mjo-stat-tile
277
608
  Label="Oldest"
@@ -280,16 +611,24 @@ export class MJOOverduePageComponent {
280
611
  [Detail]="OldestDetail" />
281
612
 
282
613
  <mjo-stat-tile
283
- Label="Overdue one-time orders"
284
- Icon="fa-regular fa-envelope"
285
- [Value]="String(OverdueOneTimeOrders)"
286
- Detail="No subscription attached" />
287
-
288
- <mjo-stat-tile
614
+ class="mjo-ov__tile"
615
+ [class.is-on]="CreditOnly"
616
+ [Pressed]="CreditOnly"
617
+ Hint="Show customers who hold credit"
289
618
  Label="Credit available to apply"
290
619
  Icon="fa-solid fa-piggy-bank"
291
620
  [Value]="CreditDisplay"
292
- Detail="Apply before following up" />
621
+ Detail="Apply before following up"
622
+ (Clicked)="OnCreditOnly(!CreditOnly)" />
623
+
624
+ <mjo-stat-tile
625
+ class="mjo-ov__tile"
626
+ Hint="Open the Billing worklist"
627
+ Label="Late, not yet invoiced"
628
+ Icon="fa-solid fa-file-invoice-dollar"
629
+ [Value]="String(NeverInvoiced.length)"
630
+ [Detail]="NeverInvoiced.length ? 'Not counted here · issue on the Billing worklist' : 'Every late installment has an invoice'"
631
+ (Clicked)="NavigateRequested.emit('billing')" />
293
632
  </div>
294
633
 
295
634
  @if (LoadError) {
@@ -298,6 +637,12 @@ export class MJOOverduePageComponent {
298
637
  {{ LoadError }}
299
638
  </mj-alert>
300
639
  }
640
+ @if (InstalmentsError) {
641
+ <mj-alert Variant="warning" Icon="fa-solid fa-triangle-exclamation" class="mjo-ov__error">
642
+ <strong>Installments could not be read.</strong>
643
+ Each order is shown with its whole balance, from its next due date. {{ InstalmentsError }}
644
+ </mj-alert>
645
+ }
301
646
 
302
647
  <p class="mjo-note mjo-ov__error">
303
648
  <i class="fa-solid fa-circle-info" aria-hidden="true"></i>
@@ -309,21 +654,22 @@ export class MJOOverduePageComponent {
309
654
  <div class="mj-card-head">
310
655
  <i class="fa-solid fa-chart-column" aria-hidden="true"></i>
311
656
  <h3>By age</h3>
657
+ <span class="right small muted">Select an age to list the orders with an amount that late</span>
312
658
  </div>
313
659
  <div class="mj-card-pad">
314
- <mjo-aging-bar [Buckets]="Buckets" />
660
+ <mjo-aging-bar [Buckets]="Buckets" [Active]="ActiveBucket" EmptyText="Nothing overdue." (BucketClicked)="OnBucket($event)" />
315
661
  </div>
316
662
  </div>
317
663
 
318
664
  @if (Truncated) {
319
665
  <mj-alert Variant="warning" Icon="fa-solid fa-triangle-exclamation" class="mjo-ov__truncated">
320
666
  <strong>List truncated.</strong>
321
- Not all overdue orders are shown. Add a filter to narrow the list.
667
+ Not all overdue orders are shown, and the figures above cover only those that are.
322
668
  </mj-alert>
323
669
  }
324
670
 
325
671
  <div class="mjo-ov__viewer-host">
326
- @if (OrderEntityInfo) {
672
+ @if (OrderEntityInfo && Ready) {
327
673
  <mj-entity-viewer
328
674
  [Entity]="OrderEntityInfo"
329
675
  [ViewEntity]="OverdueView"
@@ -334,9 +680,14 @@ export class MJOOverduePageComponent {
334
680
  <div class="small muted" style="padding: 24px;">Loading overdue orders...</div>
335
681
  }
336
682
  </div>
337
- `, styles: ["\n :host {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-ov__tiles { margin-bottom: var(--mj-space-4); }\n .mjo-ov__error { margin-bottom: var(--mj-space-4); }\n .mjo-ov__aging { margin-bottom: var(--mj-space-4); }\n .mjo-ov__truncated { margin-bottom: var(--mj-space-4); }\n .mjo-ov__viewer-host {\n height: 600px;\n min-height: 500px;\n background: var(--mj-bg-surface);\n border: 1px solid var(--mj-border-default);\n border-radius: var(--mj-radius-md);\n overflow: hidden;\n margin-top: var(--mj-space-4);\n display: flex;\n flex-direction: column;\n }\n mj-entity-viewer {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n height: 100%;\n width: 100%;\n }\n @media (max-width: 760px) {\n :host { padding: var(--mj-space-4); }\n }\n "] }]
683
+ <div class="small muted mjo-ov__foot">Balance is each order's whole open balance. Past due, above and in the export, counts only invoiced amounts past their due date.</div>
684
+ `, styles: ["\n :host {\n display: block;\n height: 100%;\n overflow: auto;\n padding: var(--mj-space-6);\n }\n .mjo-ov__tiles { margin-bottom: var(--mj-space-4); }\n .mjo-ov__tile {\n display: block;\n border-radius: var(--mj-radius-md);\n transition: box-shadow 140ms ease;\n }\n .mjo-ov__tile.is-on { box-shadow: 0 0 0 2px color-mix(in srgb, var(--mj-brand-primary) 55%, transparent); }\n .mjo-ov__error { display: block; margin-bottom: var(--mj-space-4); }\n .mjo-ov__aging { margin-bottom: var(--mj-space-4); }\n .mjo-ov__truncated { display: block; margin-bottom: var(--mj-space-4); }\n .mjo-ov__foot { margin-top: var(--mj-space-3); }\n .mjo-ov__window {\n display: inline-flex;\n align-items: center;\n gap: var(--mj-space-2);\n }\n .mjo-ov__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-ov__viewer-host {\n height: 600px;\n min-height: 500px;\n background: var(--mj-bg-surface);\n border: 1px solid var(--mj-border-default);\n border-radius: var(--mj-radius-md);\n overflow: hidden;\n margin-top: var(--mj-space-4);\n display: flex;\n flex-direction: column;\n }\n mj-entity-viewer {\n display: flex;\n flex-direction: column;\n flex: 1 1 auto;\n height: 100%;\n width: 100%;\n }\n @media (max-width: 760px) {\n :host { padding: var(--mj-space-4); }\n }\n @media (prefers-reduced-motion: reduce) {\n .mjo-ov__tile { transition: none; }\n }\n "] }]
338
685
  }], null, { OrderOpened: [{
339
686
  type: Output
687
+ }], NavigateRequested: [{
688
+ type: Output
689
+ }], AddressChanged: [{
690
+ type: Output
340
691
  }] }); })();
341
- (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(MJOOverduePageComponent, { className: "MJOOverduePageComponent", filePath: "lib/pages/receivables/overdue.page.ts", lineNumber: 161 }); })();
692
+ (() => { (typeof ngDevMode === "undefined" || ngDevMode) && i0.ɵsetClassDebugInfo(MJOOverduePageComponent, { className: "MJOOverduePageComponent", filePath: "lib/pages/receivables/overdue.page.ts", lineNumber: 305 }); })();
342
693
  //# sourceMappingURL=overdue.page.js.map