@mj-biz-apps/orders-core-entities-server 5.41.0 → 5.43.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.
- package/dist/AccessOverride.d.ts +7 -1
- package/dist/AccessOverride.d.ts.map +1 -1
- package/dist/AccessOverride.js +23 -3
- package/dist/AccessOverride.js.map +1 -1
- package/dist/AccountingBridge.d.ts +4 -4
- package/dist/AccountingBridge.d.ts.map +1 -1
- package/dist/AccountingBridge.js +5 -9
- package/dist/AccountingBridge.js.map +1 -1
- package/dist/BaseInvoiceRail.d.ts +10 -0
- package/dist/BaseInvoiceRail.d.ts.map +1 -1
- package/dist/BaseInvoiceRail.js +12 -0
- package/dist/BaseInvoiceRail.js.map +1 -1
- package/dist/BillComInvoiceRail.d.ts +2 -0
- package/dist/BillComInvoiceRail.d.ts.map +1 -1
- package/dist/BillComInvoiceRail.js +4 -0
- package/dist/BillComInvoiceRail.js.map +1 -1
- package/dist/CheckoutAccountStep.d.ts +13 -0
- package/dist/CheckoutAccountStep.d.ts.map +1 -1
- package/dist/CheckoutAccountStep.js +31 -2
- package/dist/CheckoutAccountStep.js.map +1 -1
- package/dist/CheckoutSessionService.d.ts +35 -0
- package/dist/CheckoutSessionService.d.ts.map +1 -1
- package/dist/CheckoutSessionService.js +168 -39
- package/dist/CheckoutSessionService.js.map +1 -1
- package/dist/ConcessionGate.d.ts +4 -2
- package/dist/ConcessionGate.d.ts.map +1 -1
- package/dist/ConcessionGate.js +9 -6
- package/dist/ConcessionGate.js.map +1 -1
- package/dist/ContractBalance.d.ts +29 -0
- package/dist/ContractBalance.d.ts.map +1 -1
- package/dist/ContractBalance.js +48 -0
- package/dist/ContractBalance.js.map +1 -1
- package/dist/EntitlementGrantClaimDriver.d.ts.map +1 -1
- package/dist/EntitlementGrantClaimDriver.js +7 -1
- package/dist/EntitlementGrantClaimDriver.js.map +1 -1
- package/dist/GetProgressWorklistOperation.d.ts.map +1 -1
- package/dist/GetProgressWorklistOperation.js +9 -2
- package/dist/GetProgressWorklistOperation.js.map +1 -1
- package/dist/GiftCardBehavior.d.ts +15 -0
- package/dist/GiftCardBehavior.d.ts.map +1 -1
- package/dist/GiftCardBehavior.js +26 -0
- package/dist/GiftCardBehavior.js.map +1 -1
- package/dist/GiftCardEngine.d.ts +4 -0
- package/dist/GiftCardEngine.d.ts.map +1 -1
- package/dist/GiftCardEngine.js +16 -3
- package/dist/GiftCardEngine.js.map +1 -1
- package/dist/GuestOrderClaimDriver.d.ts.map +1 -1
- package/dist/GuestOrderClaimDriver.js +7 -1
- package/dist/GuestOrderClaimDriver.js.map +1 -1
- package/dist/InvoiceRailResolver.d.ts.map +1 -1
- package/dist/InvoiceRailResolver.js +6 -0
- package/dist/InvoiceRailResolver.js.map +1 -1
- package/dist/IssueExternalInvoiceOperation.d.ts +14 -1
- package/dist/IssueExternalInvoiceOperation.d.ts.map +1 -1
- package/dist/IssueExternalInvoiceOperation.js +85 -4
- package/dist/IssueExternalInvoiceOperation.js.map +1 -1
- package/dist/IssueInstalmentInvoiceOperation.d.ts +5 -1
- package/dist/IssueInstalmentInvoiceOperation.d.ts.map +1 -1
- package/dist/IssueInstalmentInvoiceOperation.js +6 -2
- package/dist/IssueInstalmentInvoiceOperation.js.map +1 -1
- package/dist/OrderEntityServer.d.ts +49 -1
- package/dist/OrderEntityServer.d.ts.map +1 -1
- package/dist/OrderEntityServer.js +216 -14
- package/dist/OrderEntityServer.js.map +1 -1
- package/dist/OrderJournalEntryFactory.d.ts +13 -1
- package/dist/OrderJournalEntryFactory.d.ts.map +1 -1
- package/dist/OrderJournalEntryFactory.js +38 -5
- package/dist/OrderJournalEntryFactory.js.map +1 -1
- package/dist/PaymentAllocationInputs.d.ts.map +1 -1
- package/dist/PaymentAllocationInputs.js +5 -3
- package/dist/PaymentAllocationInputs.js.map +1 -1
- package/dist/PaymentHeaderEntityServer.d.ts.map +1 -1
- package/dist/PaymentHeaderEntityServer.js +17 -12
- package/dist/PaymentHeaderEntityServer.js.map +1 -1
- package/dist/PaymentLineEntityServer.d.ts.map +1 -1
- package/dist/PaymentLineEntityServer.js +9 -13
- package/dist/PaymentLineEntityServer.js.map +1 -1
- package/dist/PaymentScheduleBehavior.d.ts +24 -0
- package/dist/PaymentScheduleBehavior.d.ts.map +1 -1
- package/dist/PaymentScheduleBehavior.js +88 -1
- package/dist/PaymentScheduleBehavior.js.map +1 -1
- package/dist/PaymentSettlement.d.ts +20 -0
- package/dist/PaymentSettlement.d.ts.map +1 -1
- package/dist/PaymentSettlement.js +41 -14
- package/dist/PaymentSettlement.js.map +1 -1
- package/dist/PaymentWebhookDeliveryLog.d.ts +16 -0
- package/dist/PaymentWebhookDeliveryLog.d.ts.map +1 -1
- package/dist/PaymentWebhookDeliveryLog.js +23 -2
- package/dist/PaymentWebhookDeliveryLog.js.map +1 -1
- package/dist/PaymentWebhookHandler.d.ts.map +1 -1
- package/dist/PaymentWebhookHandler.js +15 -3
- package/dist/PaymentWebhookHandler.js.map +1 -1
- package/dist/PollExternalPaymentsOperation.d.ts +19 -2
- package/dist/PollExternalPaymentsOperation.d.ts.map +1 -1
- package/dist/PollExternalPaymentsOperation.js +55 -0
- package/dist/PollExternalPaymentsOperation.js.map +1 -1
- package/dist/RecordProgressOperation.d.ts.map +1 -1
- package/dist/RecordProgressOperation.js +9 -5
- package/dist/RecordProgressOperation.js.map +1 -1
- package/dist/SpawnRenewalsOperation.d.ts +22 -0
- package/dist/SpawnRenewalsOperation.d.ts.map +1 -1
- package/dist/SpawnRenewalsOperation.js +32 -3
- package/dist/SpawnRenewalsOperation.js.map +1 -1
- package/dist/SubscriptionBehavior.d.ts +5 -0
- package/dist/SubscriptionBehavior.d.ts.map +1 -1
- package/dist/SubscriptionBehavior.js +34 -5
- package/dist/SubscriptionBehavior.js.map +1 -1
- package/dist/claimDriverHelpers.d.ts +6 -2
- package/dist/claimDriverHelpers.d.ts.map +1 -1
- package/dist/claimDriverHelpers.js +11 -13
- package/dist/claimDriverHelpers.js.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
* RESOLVER: GLAccountResolver (./GLAccountResolver.ts)
|
|
27
27
|
* OP: 'Accounting.CreateJournalEntries' (@mj-biz-apps/accounting-core-entities-server)
|
|
28
28
|
*/
|
|
29
|
-
import { EntitySaveOptions, ValidationResult } from '@memberjunction/core';
|
|
29
|
+
import { EntityDeleteOptions, EntitySaveOptions, ValidationResult } from '@memberjunction/core';
|
|
30
30
|
import { OrderHeaderEntity, mjBizAppsOrdersOrderLineEntity } from '@mj-biz-apps/orders-entities';
|
|
31
31
|
import { type ReversalContext } from './ReversalResolver.js';
|
|
32
32
|
import { type ManualDiscountRequest, type RequestedCharge } from '@mj-biz-apps/orders-entities';
|
|
@@ -82,6 +82,12 @@ export declare class OrderEntityServer extends OrderHeaderEntity {
|
|
|
82
82
|
* it now lives. Left null, nothing changes.
|
|
83
83
|
*/
|
|
84
84
|
ExpectedGrossTotal: number | null;
|
|
85
|
+
/**
|
|
86
|
+
* The business day the instalments this confirm issues are invoiced on, `YYYY-MM-DD` (#831).
|
|
87
|
+
* Left null they are invoiced today. `Orders.SpawnRenewals` sets its as-of day, so a catch-up
|
|
88
|
+
* run dates the instalment entry on the day the schedule row's due date was counted from.
|
|
89
|
+
*/
|
|
90
|
+
InstalmentInvoiceDay: string | null;
|
|
85
91
|
/**
|
|
86
92
|
* Promotion and charge decisions made by `prepareLines` and consumed by `savePendingLines`.
|
|
87
93
|
*
|
|
@@ -285,6 +291,17 @@ export declare class OrderEntityServer extends OrderHeaderEntity {
|
|
|
285
291
|
* the move to Confirmed waits, so the work is kept and the concession stays visible as a queue.
|
|
286
292
|
*/
|
|
287
293
|
private passesConcessionGate;
|
|
294
|
+
/**
|
|
295
|
+
* Ask the host's order-line edit veto about every saved line this save would delete (#799).
|
|
296
|
+
*
|
|
297
|
+
* The line's own `Delete()` asks too, but it runs inside the save's transaction, where a refusal
|
|
298
|
+
* could only surface as a thrown "Failed to delete removed order line" with the vetoer's words
|
|
299
|
+
* buried in it. Asking here, before the transaction, fails the save with those words as its
|
|
300
|
+
* message. A bundle's components count: `deleteRemovedLines` deletes them with the bundle.
|
|
301
|
+
*
|
|
302
|
+
* Not while booking: that is Orders confirming its own order, which the line loop exempts too.
|
|
303
|
+
*/
|
|
304
|
+
private passesRemovalVeto;
|
|
288
305
|
/**
|
|
289
306
|
* What the concession gate would refuse this order's confirm for, without confirming (golive #340).
|
|
290
307
|
* Writes nothing. Loads the saved lines first when they are not in memory, so a freshly loaded
|
|
@@ -411,6 +428,27 @@ export declare class OrderEntityServer extends OrderHeaderEntity {
|
|
|
411
428
|
private resolvedExtendedFor;
|
|
412
429
|
/** Persist priced lines and the component/charge rows that need their IDs. */
|
|
413
430
|
private persistPreparedLines;
|
|
431
|
+
/**
|
|
432
|
+
* Delete a Draft or Quoted order with its lines and the rows its draft saves wrote (#843).
|
|
433
|
+
*
|
|
434
|
+
* `spDeleteOrderHeader` deletes only the header, and none of the foreign keys into it cascades,
|
|
435
|
+
* so a draft with lines failed on FK_OrderLine_OrderHeader. The lines go the way a removed draft
|
|
436
|
+
* line goes (`deleteLineDependents`, then the line, components before their bundle), then the
|
|
437
|
+
* order-level rows a draft's save writes, then the header, in one transaction.
|
|
438
|
+
*
|
|
439
|
+
* A Confirmed or Voided order is refused: a booked order is corrected by a reversal order, and a
|
|
440
|
+
* voided one is the record of that decision. Rows only booking or checkout writes (payment
|
|
441
|
+
* intents, a checkout session's draft link, access overrides) are not deleted here; an order that
|
|
442
|
+
* has them still fails on that row's foreign key.
|
|
443
|
+
*/
|
|
444
|
+
Delete(options?: EntityDeleteOptions): Promise<boolean>;
|
|
445
|
+
/** {@link buildFailureResult}, typed as a delete. */
|
|
446
|
+
private buildDeleteFailure;
|
|
447
|
+
/** Every row a draft order's saves wrote that points at it, children before parents. See {@link Delete}. */
|
|
448
|
+
private deleteDraftOrderRows;
|
|
449
|
+
private loadRowsForDelete;
|
|
450
|
+
private deleteRowsForDelete;
|
|
451
|
+
private deleteEach;
|
|
414
452
|
/**
|
|
415
453
|
* Issue the deletes this save's line pass would otherwise never issue (golive #187).
|
|
416
454
|
*
|
|
@@ -722,6 +760,16 @@ export declare class OrderEntityServer extends OrderHeaderEntity {
|
|
|
722
760
|
* then have changed.
|
|
723
761
|
*/
|
|
724
762
|
private savePriceComponents;
|
|
763
|
+
/**
|
|
764
|
+
* Delete the price breakdown a re-priced line carries from an earlier save, so the one written
|
|
765
|
+
* now replaces it (#794).
|
|
766
|
+
*
|
|
767
|
+
* A saved line priced above zero counts as stated and is not re-priced, which kept this rare;
|
|
768
|
+
* a line the engine prices at zero is re-priced on every save, and each save appended another
|
|
769
|
+
* full set of components. One read covers every line priced in this save; a line inserted by
|
|
770
|
+
* this save has no rows yet and matches nothing.
|
|
771
|
+
*/
|
|
772
|
+
private deleteSupersededPriceComponents;
|
|
725
773
|
/**
|
|
726
774
|
* Derive each draft line's GL dimension tags and write them as `OrderLineDimension` rows.
|
|
727
775
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OrderEntityServer.d.ts","sourceRoot":"","sources":["../src/OrderEntityServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"OrderEntityServer.d.ts","sourceRoot":"","sources":["../src/OrderEntityServer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,OAAO,EAKH,mBAAmB,EACnB,iBAAiB,EAUjB,gBAAgB,EACnB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAGH,iBAAiB,EAIjB,8BAA8B,EAmBjC,MAAM,8BAA8B,CAAC;AAStC,OAAO,EAAmE,KAAK,eAAe,EAAE,MAAM,uBAAuB,CAAC;AA+C9H,OA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C;AAgED,0FAA0F;AAC1F,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C"}
|
|
@@ -32,14 +32,14 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
32
32
|
* RESOLVER: GLAccountResolver (./GLAccountResolver.ts)
|
|
33
33
|
* OP: 'Accounting.CreateJournalEntries' (@mj-biz-apps/accounting-core-entities-server)
|
|
34
34
|
*/
|
|
35
|
-
import { BaseEntity, BaseEntityResult,
|
|
35
|
+
import { BaseEntity, BaseEntityResult, CompositeKey, EntitySaveOptions, LogError, LogStatus, Metadata, RunView, ValidationErrorInfo, ValidationErrorType, } from '@memberjunction/core';
|
|
36
36
|
import { MJGlobal, RegisterClass, UUIDsEqual } from '@memberjunction/global';
|
|
37
|
-
import { ADDRESS_SNAPSHOT_FIELDS, BuildAddressSnapshot, OrderHeaderEntity, OrderLineEntity, mjBizAppsOrdersEventOrderLineEntity, ToISODate, IsEditable, REVIEWED_HEADER_FIELDS, REVIEWED_LINE_FIELDS, HostOrderConfirmVeto, ResolveOrderConfirmRefusal, RunAlongsideRefusal, } from '@mj-biz-apps/orders-entities';
|
|
37
|
+
import { ADDRESS_SNAPSHOT_FIELDS, BuildAddressSnapshot, OrderHeaderEntity, OrderLineEntity, mjBizAppsOrdersEventOrderLineEntity, ToISODate, IsEditable, REVIEWED_HEADER_FIELDS, REVIEWED_LINE_FIELDS, HostOrderConfirmVeto, ResolveOrderConfirmRefusal, HostOrderLineEditVeto, ResolveOrderLineEditRefusal, RunAlongsideRefusal, } from '@mj-biz-apps/orders-entities';
|
|
38
38
|
import { CalendarDayOrToday } from './calendar-day.js';
|
|
39
39
|
import { ResolveLineParty } from './LineParty.js';
|
|
40
|
-
import { BuildGLAccountResolver, EntityIDFor, LoadAccountingEngine, ResolverEntities } from './AccountingBridge.js';
|
|
40
|
+
import { BuildGLAccountResolver, EntityIDFor, LoadAccountingEngine, ResolveAccountingOperation, ResolverEntities } from './AccountingBridge.js';
|
|
41
41
|
import { MarkAsOrdersOwnWrite } from './OrderLineEntityServer.js';
|
|
42
|
-
import { InstalmentsToCancel, RefuseEarlierThanPriorReversal, RefuseEarnedNotBilled } from './ContractBalance.js';
|
|
42
|
+
import { InstalmentsToCancel, RefuseCancellingPaidInstalments, RefuseEarlierThanPriorReversal, RefuseEarnedNotBilled } from './ContractBalance.js';
|
|
43
43
|
import { InheritedTerms, MirroredTaxCharges, RefreshedDiscountAmount, ValidateReversal } from './ReversalBehavior.js';
|
|
44
44
|
import { IsWholeOrderReversed, LoadOriginTaxCharges, LoadReversalContext } from './ReversalResolver.js';
|
|
45
45
|
import { BookingErrorLogText, DescribeBookingErrors } from './booking-errors.js';
|
|
@@ -62,6 +62,7 @@ import { RaiseTermLengthExceptions } from './TermLengthExceptions.js';
|
|
|
62
62
|
import { DimensionDefaultResolver } from './DimensionDefaultResolver.js';
|
|
63
63
|
import { DeriveLineDimensions } from './LineDimensionRules.js';
|
|
64
64
|
import { MergeDerivedTags, MergeLineDimensions } from './LineDimensionMerge.js';
|
|
65
|
+
import { ChildLinesFirst, DescendantLines } from '@mj-biz-apps/orders-entities';
|
|
65
66
|
import { DisplacedStartEventData } from './displaced-start-event.js';
|
|
66
67
|
import { ORDER_LINE_DIMENSION_ENTITY } from './entity-names.js';
|
|
67
68
|
import { MergeOrderRollups, ORDER_ROLLUP_FIELDS, } from './OrderRollupBehavior.js';
|
|
@@ -165,6 +166,12 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
165
166
|
* it now lives. Left null, nothing changes.
|
|
166
167
|
*/
|
|
167
168
|
this.ExpectedGrossTotal = null;
|
|
169
|
+
/**
|
|
170
|
+
* The business day the instalments this confirm issues are invoiced on, `YYYY-MM-DD` (#831).
|
|
171
|
+
* Left null they are invoiced today. `Orders.SpawnRenewals` sets its as-of day, so a catch-up
|
|
172
|
+
* run dates the instalment entry on the day the schedule row's due date was counted from.
|
|
173
|
+
*/
|
|
174
|
+
this.InstalmentInvoiceDay = null;
|
|
168
175
|
/**
|
|
169
176
|
* Promotion and charge decisions made by `prepareLines` and consumed by `savePendingLines`.
|
|
170
177
|
*
|
|
@@ -467,6 +474,9 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
467
474
|
// for the same reason as the status move above: a refused confirm must change nothing.
|
|
468
475
|
if (booking && !(await this.passesConcessionGate()))
|
|
469
476
|
return false;
|
|
477
|
+
// A REMOVAL ANOTHER APP REFUSES FAILS THE SAVE, before anything is written (#799).
|
|
478
|
+
if (!booking && !(await this.passesRemovalVeto()))
|
|
479
|
+
return false;
|
|
470
480
|
// NO CONFIRM AHEAD OF AN ORDER REVIEW (golive #320 §5), once concessions are decided, so the
|
|
471
481
|
// reviewer sees the order as it will book. Off until a host switches a trigger on.
|
|
472
482
|
if (booking && !(await this.passesOrderReviewGate()))
|
|
@@ -977,6 +987,43 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
977
987
|
`must be approved before the customer is committed to it.`)));
|
|
978
988
|
return false;
|
|
979
989
|
}
|
|
990
|
+
/**
|
|
991
|
+
* Ask the host's order-line edit veto about every saved line this save would delete (#799).
|
|
992
|
+
*
|
|
993
|
+
* The line's own `Delete()` asks too, but it runs inside the save's transaction, where a refusal
|
|
994
|
+
* could only surface as a thrown "Failed to delete removed order line" with the vetoer's words
|
|
995
|
+
* buried in it. Asking here, before the transaction, fails the save with those words as its
|
|
996
|
+
* message. A bundle's components count: `deleteRemovedLines` deletes them with the bundle.
|
|
997
|
+
*
|
|
998
|
+
* Not while booking: that is Orders confirming its own order, which the line loop exempts too.
|
|
999
|
+
*/
|
|
1000
|
+
async passesRemovalVeto() {
|
|
1001
|
+
const veto = HostOrderLineEditVeto();
|
|
1002
|
+
if (!veto || !this.ID || !this.Lines.Removed.length)
|
|
1003
|
+
return true;
|
|
1004
|
+
const removed = new Set(this.Lines.Removed);
|
|
1005
|
+
for (const parent of this.Lines.Removed) {
|
|
1006
|
+
for (const child of DescendantLines(parent, this.Lines.Items))
|
|
1007
|
+
removed.add(child);
|
|
1008
|
+
}
|
|
1009
|
+
const refusals = [];
|
|
1010
|
+
for (const line of removed) {
|
|
1011
|
+
if (!line.IsSaved || !line.ID)
|
|
1012
|
+
continue;
|
|
1013
|
+
const refusal = await ResolveOrderLineEditRefusal(veto, {
|
|
1014
|
+
OrderHeaderID: this.ID,
|
|
1015
|
+
OrderLineID: line.ID,
|
|
1016
|
+
Kind: 'delete',
|
|
1017
|
+
ContextUser: this.ContextCurrentUser ?? null,
|
|
1018
|
+
}, 'Nothing was deleted.');
|
|
1019
|
+
if (refusal)
|
|
1020
|
+
refusals.push(`Line ${line.LineNumber ?? ''}: ${refusal}`);
|
|
1021
|
+
}
|
|
1022
|
+
if (!refusals.length)
|
|
1023
|
+
return true;
|
|
1024
|
+
this.RegisterResultHistoryEntry(this.buildFailureResult(new Error(refusals.join('; '))));
|
|
1025
|
+
return false;
|
|
1026
|
+
}
|
|
980
1027
|
/**
|
|
981
1028
|
* What the concession gate would refuse this order's confirm for, without confirming (golive #340).
|
|
982
1029
|
* Writes nothing. Loads the saved lines first when they are not in memory, so a freshly loaded
|
|
@@ -1400,9 +1447,117 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
1400
1447
|
}
|
|
1401
1448
|
/** Persist priced lines and the component/charge rows that need their IDs. */
|
|
1402
1449
|
async persistPreparedLines(options, decisions) {
|
|
1450
|
+
// Before the lines save: saving them writes this save's zero-tax reason components, which a
|
|
1451
|
+
// later delete would take with the superseded rows.
|
|
1452
|
+
await this.deleteSupersededPriceComponents();
|
|
1403
1453
|
await this.savePendingLines(options, decisions);
|
|
1404
1454
|
await this.savePriceComponents(options);
|
|
1405
1455
|
}
|
|
1456
|
+
/**
|
|
1457
|
+
* Delete a Draft or Quoted order with its lines and the rows its draft saves wrote (#843).
|
|
1458
|
+
*
|
|
1459
|
+
* `spDeleteOrderHeader` deletes only the header, and none of the foreign keys into it cascades,
|
|
1460
|
+
* so a draft with lines failed on FK_OrderLine_OrderHeader. The lines go the way a removed draft
|
|
1461
|
+
* line goes (`deleteLineDependents`, then the line, components before their bundle), then the
|
|
1462
|
+
* order-level rows a draft's save writes, then the header, in one transaction.
|
|
1463
|
+
*
|
|
1464
|
+
* A Confirmed or Voided order is refused: a booked order is corrected by a reversal order, and a
|
|
1465
|
+
* voided one is the record of that decision. Rows only booking or checkout writes (payment
|
|
1466
|
+
* intents, a checkout session's draft link, access overrides) are not deleted here; an order that
|
|
1467
|
+
* has them still fails on that row's foreign key.
|
|
1468
|
+
*/
|
|
1469
|
+
async Delete(options) {
|
|
1470
|
+
const status = String(this.GetFieldByName('Status')?.OldValue ?? this.Status ?? '');
|
|
1471
|
+
if (this.IsSaved && !IsEditable(status)) {
|
|
1472
|
+
this.RegisterResultHistoryEntry(this.buildDeleteFailure(`Order ${this.OrderNumber ?? ''} is ${status}, so it cannot be deleted. Only a Draft or ` +
|
|
1473
|
+
`Quoted order can be deleted; a confirmed order is corrected with a reversal order.`));
|
|
1474
|
+
return false;
|
|
1475
|
+
}
|
|
1476
|
+
if (!this.IsSaved)
|
|
1477
|
+
return super.Delete(options);
|
|
1478
|
+
const dbProvider = this.ProviderToUse;
|
|
1479
|
+
try {
|
|
1480
|
+
await dbProvider.BeginTransaction();
|
|
1481
|
+
await this.deleteDraftOrderRows();
|
|
1482
|
+
if (!(await super.Delete(options))) {
|
|
1483
|
+
await dbProvider.RollbackTransaction();
|
|
1484
|
+
return false;
|
|
1485
|
+
}
|
|
1486
|
+
await dbProvider.CommitTransaction();
|
|
1487
|
+
return true;
|
|
1488
|
+
}
|
|
1489
|
+
catch (err) {
|
|
1490
|
+
LogError(`OrderEntityServer.Delete failed for order ${this.OrderNumber ?? this.ID}: ${err}`);
|
|
1491
|
+
try {
|
|
1492
|
+
await dbProvider.RollbackTransaction();
|
|
1493
|
+
}
|
|
1494
|
+
catch (rollbackErr) {
|
|
1495
|
+
LogError(`Rollback failed after OrderEntityServer.Delete error: ${rollbackErr}`);
|
|
1496
|
+
}
|
|
1497
|
+
this.RegisterResultHistoryEntry(this.buildDeleteFailure(err instanceof Error ? err.message : String(err)));
|
|
1498
|
+
return false;
|
|
1499
|
+
}
|
|
1500
|
+
}
|
|
1501
|
+
/** {@link buildFailureResult}, typed as a delete. */
|
|
1502
|
+
buildDeleteFailure(message) {
|
|
1503
|
+
const result = this.buildFailureResult(new Error(message));
|
|
1504
|
+
result.Type = 'delete';
|
|
1505
|
+
return result;
|
|
1506
|
+
}
|
|
1507
|
+
/** Every row a draft order's saves wrote that points at it, children before parents. See {@link Delete}. */
|
|
1508
|
+
async deleteDraftOrderRows() {
|
|
1509
|
+
const orderID = RequireUUID(this.ID, 'OrderHeaderID');
|
|
1510
|
+
const byOrder = `OrderHeaderID='${orderID}'`;
|
|
1511
|
+
const lines = await this.loadRowsForDelete('MJ_BizApps_Orders: Order Lines', byOrder);
|
|
1512
|
+
for (const line of ChildLinesFirst(lines)) {
|
|
1513
|
+
await this.deleteLineDependents(line);
|
|
1514
|
+
if (!(await line.Delete())) {
|
|
1515
|
+
throw new Error(`Failed to delete order line ${line.LineNumber}: ${ExtractEntityErrorMessage(line)}`);
|
|
1516
|
+
}
|
|
1517
|
+
}
|
|
1518
|
+
// Order-level rows: concessions (payment terms), adjustments and charges with their
|
|
1519
|
+
// allocations, checkout answers and the payment schedule.
|
|
1520
|
+
await this.deleteRowsForDelete('MJ_BizApps_Orders: Order Concessions', byOrder);
|
|
1521
|
+
const adjustments = await this.loadRowsForDelete('MJ_BizApps_Orders: Order Adjustments', byOrder);
|
|
1522
|
+
if (adjustments.length) {
|
|
1523
|
+
await this.deleteRowsForDelete('MJ_BizApps_Orders: Order Adjustment Allocations', `OrderAdjustmentID IN (${adjustments.map((a) => `'${RequireUUID(String(a.Get('ID')), 'OrderAdjustmentID')}'`).join(',')})`);
|
|
1524
|
+
await this.deleteEach('MJ_BizApps_Orders: Order Adjustments', adjustments);
|
|
1525
|
+
}
|
|
1526
|
+
const charges = await this.loadRowsForDelete('MJ_BizApps_Orders: Order Charges', byOrder);
|
|
1527
|
+
if (charges.length) {
|
|
1528
|
+
await this.deleteRowsForDelete('MJ_BizApps_Orders: Order Charge Allocations', `OrderChargeID IN (${charges.map((c) => `'${RequireUUID(String(c.Get('ID')), 'OrderChargeID')}'`).join(',')})`);
|
|
1529
|
+
await this.deleteEach('MJ_BizApps_Orders: Order Charges', charges);
|
|
1530
|
+
}
|
|
1531
|
+
await this.deleteRowsForDelete('MJ_BizApps_Orders: Order Checkout Answers', byOrder);
|
|
1532
|
+
await this.deleteRowsForDelete('MJ_BizApps_Orders: Order Header Payment Schedules', byOrder);
|
|
1533
|
+
}
|
|
1534
|
+
async loadRowsForDelete(entityName, filter) {
|
|
1535
|
+
const rv = new RunView(this.ProviderToUse);
|
|
1536
|
+
const result = await rv.RunView({ EntityName: entityName, ExtraFilter: filter, ResultType: 'entity_object', MaxRows: DEPENDENT_ROW_CAP }, this.ContextCurrentUser);
|
|
1537
|
+
if (!result?.Success) {
|
|
1538
|
+
throw new Error(`Failed to read ${entityName} for order ${this.OrderNumber ?? ''}: ${result?.ErrorMessage ?? 'unknown error'}`);
|
|
1539
|
+
}
|
|
1540
|
+
const rows = result.Results ?? [];
|
|
1541
|
+
// A guard, not a page size: deleting the first thousand would fail the header's delete later.
|
|
1542
|
+
if (rows.length >= DEPENDENT_ROW_CAP) {
|
|
1543
|
+
throw new Error(`Order ${this.OrderNumber ?? ''} has ${DEPENDENT_ROW_CAP} or more ${entityName} rows; ` +
|
|
1544
|
+
`refusing to delete it rather than clearing only part of them.`);
|
|
1545
|
+
}
|
|
1546
|
+
return rows;
|
|
1547
|
+
}
|
|
1548
|
+
async deleteRowsForDelete(entityName, filter) {
|
|
1549
|
+
await this.deleteEach(entityName, await this.loadRowsForDelete(entityName, filter));
|
|
1550
|
+
}
|
|
1551
|
+
async deleteEach(entityName, rows) {
|
|
1552
|
+
for (const row of rows) {
|
|
1553
|
+
// A concession goes with its draft order, decided or not, as it goes with a draft line.
|
|
1554
|
+
if ('WithdrawWithDraftLine' in row)
|
|
1555
|
+
row.WithdrawWithDraftLine = true;
|
|
1556
|
+
if (!(await row.Delete())) {
|
|
1557
|
+
throw new Error(`Failed to delete ${entityName} for order ${this.OrderNumber ?? ''}: ${ExtractEntityErrorMessage(row)}`);
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1406
1561
|
/**
|
|
1407
1562
|
* Issue the deletes this save's line pass would otherwise never issue (golive #187).
|
|
1408
1563
|
*
|
|
@@ -1418,7 +1573,17 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
1418
1573
|
* because the delete moved them on the row. See the call site.
|
|
1419
1574
|
*/
|
|
1420
1575
|
async deleteRemovedLines() {
|
|
1421
|
-
|
|
1576
|
+
if (!this.Lines.Removed.length)
|
|
1577
|
+
return false;
|
|
1578
|
+
// A REMOVED BUNDLE TAKES ITS COMPONENTS WITH IT (#793). `OrderHeaderEntity.RemoveLine` does
|
|
1579
|
+
// this for the editor; a caller that removed only the bundle through `Lines.Remove` left its
|
|
1580
|
+
// components in the collection, still naming it through the non-cascading
|
|
1581
|
+
// FK_OrderLine_ParentOrderLine. They are removed here too, and every delete runs child first.
|
|
1582
|
+
for (const parent of [...this.Lines.Removed]) {
|
|
1583
|
+
for (const child of DescendantLines(parent, this.Lines.Items))
|
|
1584
|
+
this.Lines.Remove(child);
|
|
1585
|
+
}
|
|
1586
|
+
const removed = ChildLinesFirst(this.Lines.Removed.filter((line) => line.IsSaved));
|
|
1422
1587
|
if (!removed.length)
|
|
1423
1588
|
return false;
|
|
1424
1589
|
for (const line of removed) {
|
|
@@ -1429,9 +1594,9 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
1429
1594
|
* Orders itself — so the veto is asked. While booking it is Orders confirming its own
|
|
1430
1595
|
* order, and a refusal there would block the close that creates the record being protected.
|
|
1431
1596
|
*
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1434
|
-
*
|
|
1597
|
+
* `passesRemovalVeto` has already asked before the transaction opened and failed the save
|
|
1598
|
+
* with the vetoer's words (#799); a refusal here is only a vetoer that changed its answer
|
|
1599
|
+
* in between, and that throws.
|
|
1435
1600
|
*/
|
|
1436
1601
|
const serverLine = line;
|
|
1437
1602
|
serverLine.BypassExternalEditVeto = this.bookingInFlight;
|
|
@@ -1832,6 +1997,8 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
1832
1997
|
ProductID: l.ProductID,
|
|
1833
1998
|
Quantity: Number(l.Quantity ?? 0),
|
|
1834
1999
|
UnitPrice: Number(l.UnitPrice ?? 0),
|
|
2000
|
+
LineTotalNet: Number(l.LineTotalNet ?? 0),
|
|
2001
|
+
LineNumber: l.LineNumber ?? null,
|
|
1835
2002
|
ReversesOrderLineID: l.ReversesOrderLineID ?? null,
|
|
1836
2003
|
ShipToPersonID: l.ShipToPersonID ?? null,
|
|
1837
2004
|
ShipToOrganizationID: l.ShipToOrganizationID ?? null,
|
|
@@ -2036,6 +2203,8 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
2036
2203
|
RecognizedToDate: Number(context.Origin.RecognizedToDate ?? 0),
|
|
2037
2204
|
RemainingQuantity: context.Origin.Quantity - context.AlreadyReversed,
|
|
2038
2205
|
OriginNet: Number(context.Origin.LineTotalNet ?? 0),
|
|
2206
|
+
OriginServicePeriodStart: context.Origin.ServicePeriodStart ?? null,
|
|
2207
|
+
OriginServicePeriodEnd: context.Origin.ServicePeriodEnd ?? null,
|
|
2039
2208
|
PriorReversals: context.PriorReversals,
|
|
2040
2209
|
ScheduleRows: context.ScheduleRows,
|
|
2041
2210
|
OriginOrderNumber: context.Origin.OrderNumber ?? null,
|
|
@@ -2223,11 +2392,20 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
2223
2392
|
seen.add(originOrder);
|
|
2224
2393
|
if (!(await IsWholeOrderReversed(originOrder, provider, user)))
|
|
2225
2394
|
continue;
|
|
2395
|
+
const toCancel = [];
|
|
2226
2396
|
for (const scheduleID of InstalmentsToCancel(context.ScheduleRows)) {
|
|
2227
2397
|
const row = await provider.GetEntityObject(ORDER_HEADER_PAYMENT_SCHEDULE_ENTITY, user);
|
|
2228
2398
|
if (!(await row.Load(scheduleID))) {
|
|
2229
2399
|
throw new Error(`Instalment ${scheduleID} could not be loaded to cancel it for the reversal.`);
|
|
2230
2400
|
}
|
|
2401
|
+
toCancel.push(row);
|
|
2402
|
+
}
|
|
2403
|
+
// A deposit paid ahead of an instalment would be stranded by cancelling it (#840).
|
|
2404
|
+
const depositRefusal = RefuseCancellingPaidInstalments(toCancel.map((r) => ({ InstallmentNumber: Number(r.InstallmentNumber), AmountPaid: Number(r.AmountPaid ?? 0) })), `order ${context.Origin.OrderNumber ?? originOrder}`);
|
|
2405
|
+
if (depositRefusal)
|
|
2406
|
+
throw new Error(depositRefusal);
|
|
2407
|
+
for (const row of toCancel) {
|
|
2408
|
+
const scheduleID = row.ID;
|
|
2231
2409
|
row.Status = 'Canceled';
|
|
2232
2410
|
if (!(await row.Save(options))) {
|
|
2233
2411
|
throw new Error(row.LatestResult?.CompleteMessage ??
|
|
@@ -2567,6 +2745,34 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
2567
2745
|
}
|
|
2568
2746
|
this._priceComponents.clear();
|
|
2569
2747
|
}
|
|
2748
|
+
/**
|
|
2749
|
+
* Delete the price breakdown a re-priced line carries from an earlier save, so the one written
|
|
2750
|
+
* now replaces it (#794).
|
|
2751
|
+
*
|
|
2752
|
+
* A saved line priced above zero counts as stated and is not re-priced, which kept this rare;
|
|
2753
|
+
* a line the engine prices at zero is re-priced on every save, and each save appended another
|
|
2754
|
+
* full set of components. One read covers every line priced in this save; a line inserted by
|
|
2755
|
+
* this save has no rows yet and matches nothing.
|
|
2756
|
+
*/
|
|
2757
|
+
async deleteSupersededPriceComponents() {
|
|
2758
|
+
const ids = RequireUUIDs([...new Set([...this._priceComponents.keys()].map((line) => line.ID).filter(Boolean))], 'OrderLineID');
|
|
2759
|
+
if (!ids.length)
|
|
2760
|
+
return;
|
|
2761
|
+
const rv = new RunView(this.ProviderToUse);
|
|
2762
|
+
const result = await rv.RunView({
|
|
2763
|
+
EntityName: 'MJ_BizApps_Orders: Order Line Price Components',
|
|
2764
|
+
ExtraFilter: `OrderLineID IN (${ids.map((id) => `'${id}'`).join(',')})`,
|
|
2765
|
+
ResultType: 'entity_object',
|
|
2766
|
+
}, this.ContextCurrentUser);
|
|
2767
|
+
if (!result.Success) {
|
|
2768
|
+
throw new Error(`Failed to read the earlier price breakdown: ${result.ErrorMessage}`);
|
|
2769
|
+
}
|
|
2770
|
+
for (const row of result.Results ?? []) {
|
|
2771
|
+
if (!(await row.Delete())) {
|
|
2772
|
+
throw new Error(`Failed to replace the price breakdown for an order line: ${ExtractEntityErrorMessage(row)}`);
|
|
2773
|
+
}
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2570
2776
|
/**
|
|
2571
2777
|
* Derive each draft line's GL dimension tags and write them as `OrderLineDimension` rows.
|
|
2572
2778
|
*
|
|
@@ -2858,11 +3064,7 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
2858
3064
|
* package does not hard-depend on the accounting server package at build time.
|
|
2859
3065
|
*/
|
|
2860
3066
|
async submitDrafts(drafts, provider, user) {
|
|
2861
|
-
const op =
|
|
2862
|
-
if (!op) {
|
|
2863
|
-
throw new Error(`The 'Accounting.CreateJournalEntries' operation is not registered. The BizApps ` +
|
|
2864
|
-
`Accounting server package must be loaded before orders can book journal entries.`);
|
|
2865
|
-
}
|
|
3067
|
+
const op = ResolveAccountingOperation('Accounting.CreateJournalEntries', 'book journal entries');
|
|
2866
3068
|
const result = await op.Execute({ Drafts: drafts.map((d) => d.Draft) }, { provider, user });
|
|
2867
3069
|
// The envelope reports transport/authorization failure; the payload reports the
|
|
2868
3070
|
// accounting-domain outcome. Both must be checked — a successful call can still carry
|
|
@@ -4211,7 +4413,7 @@ let OrderEntityServer = class OrderEntityServer extends OrderHeaderEntity {
|
|
|
4211
4413
|
const provider = this.ProviderToUse;
|
|
4212
4414
|
const user = this.ContextCurrentUser;
|
|
4213
4415
|
for (const row of due) {
|
|
4214
|
-
const outcome = await IssueInstalment(String(row.ID), provider, user);
|
|
4416
|
+
const outcome = await IssueInstalment(String(row.ID), provider, user, this.InstalmentInvoiceDay);
|
|
4215
4417
|
if (!outcome.Success) {
|
|
4216
4418
|
throw new Error(`Order ${this.OrderNumber} could not issue instalment ${row.InstallmentNumber}, which is ` +
|
|
4217
4419
|
`due on or before the order date: ${outcome.Message}`);
|