@fabriktor/fx 0.0.94 → 0.0.96
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/src/billable/billable.d.ts +11 -18
- package/dist/src/billable/billable.js +36 -16
- package/package.json +4 -3
|
@@ -4,8 +4,6 @@ import type { ContactsFXOperator, EmploymentOwnerScope } from "../contacts/conta
|
|
|
4
4
|
import { type OwnerSearchOptions, type SearchOptions, type SearchPage, type SearchQuery } from "../core/search.js";
|
|
5
5
|
type GenerateBillPayload = Parameters<BillableOperator["generateBill"]>[0];
|
|
6
6
|
export type SalaryEstimateInput = GenerateBillPayload["salary_estimate"];
|
|
7
|
-
type BillInsertOptions = Parameters<BillableOperator["insertOneBill"]>[0];
|
|
8
|
-
type BillReplaceOptions = Parameters<BillableOperator["replaceOneBill"]>[0];
|
|
9
7
|
type BillableFolderInsertOptions = Parameters<BillableOperator["insertOneBillableFolder"]>[0];
|
|
10
8
|
type BillableFolderReplaceOptions = Parameters<BillableOperator["replaceOneBillableFolder"]>[0];
|
|
11
9
|
type ChargeInsertOptions = Parameters<BillableOperator["insertOneCharge"]>[0];
|
|
@@ -28,9 +26,7 @@ type VendorInvoiceInsertOptions = Parameters<BillableOperator["insertOneVendorIn
|
|
|
28
26
|
type VendorInvoiceReplaceOptions = Parameters<BillableOperator["replaceOneVendorInvoice"]>[0];
|
|
29
27
|
type WarehouseInsertOptions = Parameters<BillableOperator["insertOneWarehouse"]>[0];
|
|
30
28
|
type WarehouseReplaceOptions = Parameters<BillableOperator["replaceOneWarehouse"]>[0];
|
|
31
|
-
export type
|
|
32
|
-
export type ReplaceBillOptions = BillReplaceOptions;
|
|
33
|
-
export type SearchBillsOptions = OwnerSearchOptions;
|
|
29
|
+
export type SearchBillsOptions = OwnerSearchOptions & Partial<Pick<Bill, "is_estimate">>;
|
|
34
30
|
export type SearchBillsPage = SearchPage<Bill>;
|
|
35
31
|
export type CreateBillableFolderOptions = BillableFolderInsertOptions;
|
|
36
32
|
export type ReplaceBillableFolderOptions = BillableFolderReplaceOptions;
|
|
@@ -137,11 +133,8 @@ export type GenerateDynamicBillOptions = {
|
|
|
137
133
|
exclude_billed?: boolean;
|
|
138
134
|
};
|
|
139
135
|
export declare function zeroSalaryEstimate(): SalaryEstimateInput;
|
|
140
|
-
export type
|
|
141
|
-
|
|
142
|
-
};
|
|
143
|
-
export type CancelBillOptions = {
|
|
144
|
-
in: GenerateBillPayload;
|
|
136
|
+
export type BillActionOptions = {
|
|
137
|
+
bill: Bill;
|
|
145
138
|
};
|
|
146
139
|
export type VendorInvoiceFromBillOptions = Parameters<BillableOperator["vendorInvoiceFromBill"]>[0];
|
|
147
140
|
export declare const BillablePreActionReason: {
|
|
@@ -150,8 +143,6 @@ export declare const BillablePreActionReason: {
|
|
|
150
143
|
export type BillablePreActionReason = (typeof BillablePreActionReason)[keyof typeof BillablePreActionReason];
|
|
151
144
|
export interface BillableFXOperator {
|
|
152
145
|
loadReadContext(opts: LoadBillableReadContextOptions): Promise<BillableReadContext>;
|
|
153
|
-
createBill(opts: CreateBillOptions): Promise<Bill>;
|
|
154
|
-
replaceBill(opts: ReplaceBillOptions): Promise<Bill>;
|
|
155
146
|
searchBills(opts: SearchBillsOptions): Promise<SearchBillsPage>;
|
|
156
147
|
createBillableFolder(opts: CreateBillableFolderOptions): Promise<BillableFolder>;
|
|
157
148
|
replaceBillableFolder(opts: ReplaceBillableFolderOptions): Promise<BillableFolder>;
|
|
@@ -197,8 +188,9 @@ export interface BillableFXOperator {
|
|
|
197
188
|
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<Bill>;
|
|
198
189
|
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<Bill>;
|
|
199
190
|
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<Bill>;
|
|
200
|
-
|
|
201
|
-
cancelBill(opts:
|
|
191
|
+
completeBill(opts: BillActionOptions): Promise<Bill>;
|
|
192
|
+
cancelBill(opts: BillActionOptions): Promise<Bill>;
|
|
193
|
+
retryBillReport(opts: BillActionOptions): Promise<Bill>;
|
|
202
194
|
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<VendorInvoice>;
|
|
203
195
|
}
|
|
204
196
|
export declare class BillableFX implements BillableFXOperator {
|
|
@@ -206,8 +198,6 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
206
198
|
private contacts_fx;
|
|
207
199
|
constructor(opts: BillableFXOptions);
|
|
208
200
|
loadReadContext(opts: LoadBillableReadContextOptions): Promise<BillableReadContext>;
|
|
209
|
-
createBill(opts: CreateBillOptions): Promise<Bill>;
|
|
210
|
-
replaceBill(opts: ReplaceBillOptions): Promise<Bill>;
|
|
211
201
|
searchBills(opts: SearchBillsOptions): Promise<SearchBillsPage>;
|
|
212
202
|
createBillableFolder(opts: CreateBillableFolderOptions): Promise<BillableFolder>;
|
|
213
203
|
replaceBillableFolder(opts: ReplaceBillableFolderOptions): Promise<BillableFolder>;
|
|
@@ -253,8 +243,9 @@ export declare class BillableFX implements BillableFXOperator {
|
|
|
253
243
|
acceptFixedEstimate(opts: AcceptFixedEstimateOptions): Promise<Bill>;
|
|
254
244
|
generateDynamicEstimate(opts: GenerateDynamicEstimateOptions): Promise<Bill>;
|
|
255
245
|
generateDynamicBill(opts: GenerateDynamicBillOptions): Promise<Bill>;
|
|
256
|
-
|
|
257
|
-
cancelBill(opts:
|
|
246
|
+
completeBill(opts: BillActionOptions): Promise<Bill>;
|
|
247
|
+
cancelBill(opts: BillActionOptions): Promise<Bill>;
|
|
248
|
+
retryBillReport(opts: BillActionOptions): Promise<Bill>;
|
|
258
249
|
vendorInvoiceFromBill(opts: VendorInvoiceFromBillOptions): Promise<VendorInvoice>;
|
|
259
250
|
private generateBill;
|
|
260
251
|
private checkVendorInvoiceNumber;
|
|
@@ -287,4 +278,6 @@ export declare function billableOwnsRecord(context: BillableReadContext, record:
|
|
|
287
278
|
} | null | undefined): boolean;
|
|
288
279
|
export declare function billableCatalogOwnerIDs(context: BillableReadContext): string[];
|
|
289
280
|
export declare function newBillableFX(opts: BillableFXOptions): BillableFX;
|
|
281
|
+
export declare function billableCanCompleteBill(bill: Bill): boolean;
|
|
282
|
+
export declare function billableCanCancelBill(bill: Bill): boolean;
|
|
290
283
|
export {};
|
|
@@ -51,6 +51,10 @@ const msgFixedEstimateRequired = "Only a fixed estimate can be accepted.";
|
|
|
51
51
|
const msgInternalFixedEstimateRequired = "Only an internal fixed estimate can be accepted in Fabriktor.";
|
|
52
52
|
const msgCanceledEstimate = "A canceled fixed estimate cannot be accepted.";
|
|
53
53
|
const msgEstimateAlreadyAccepted = "This fixed estimate is already accepted.";
|
|
54
|
+
const msgBillIDRequired = "Bill ID is required.";
|
|
55
|
+
const msgBillIDMissing = "Bill response did not contain an ID.";
|
|
56
|
+
const msgCompletableBillRequired = "Only an uncanceled invoice can be completed.";
|
|
57
|
+
const msgAcceptedEstimateCancellation = "Cancel the accepted invoice instead of its estimate.";
|
|
54
58
|
export const BillableReadResource = {
|
|
55
59
|
Bill: "bill",
|
|
56
60
|
BillableFolder: "billable_folder",
|
|
@@ -102,18 +106,10 @@ export class BillableFX {
|
|
|
102
106
|
employment,
|
|
103
107
|
};
|
|
104
108
|
}
|
|
105
|
-
async createBill(opts) {
|
|
106
|
-
const out = await this.billable.insertOneBill(opts);
|
|
107
|
-
const id = requiredOperationID(out, msgCreatedBillIDMissing);
|
|
108
|
-
return await this.findBill(id);
|
|
109
|
-
}
|
|
110
|
-
async replaceBill(opts) {
|
|
111
|
-
await this.billable.replaceOneBill(opts);
|
|
112
|
-
return await this.findBill(opts.id);
|
|
113
|
-
}
|
|
114
109
|
async searchBills(opts) {
|
|
115
110
|
return await runOwnerSearch({
|
|
116
111
|
...opts,
|
|
112
|
+
query: opts.is_estimate === undefined ? undefined : { is_estimate: opts.is_estimate },
|
|
117
113
|
search: (searchOpts) => this.billable.searchManyBills(searchOpts),
|
|
118
114
|
});
|
|
119
115
|
}
|
|
@@ -381,15 +377,26 @@ export class BillableFX {
|
|
|
381
377
|
salary_estimate: zeroSalaryEstimate(),
|
|
382
378
|
}));
|
|
383
379
|
}
|
|
384
|
-
async
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
380
|
+
async completeBill(opts) {
|
|
381
|
+
const bill_id = billActionID(opts);
|
|
382
|
+
if (opts.bill.is_estimate || opts.bill.is_canceled) {
|
|
383
|
+
throw errValidation({ field: "bill", msg: msgCompletableBillRequired });
|
|
384
|
+
}
|
|
385
|
+
const out = await this.billable.completeBill({ bill_id });
|
|
386
|
+
return await this.findBill(requiredOperationID(out, msgBillIDMissing));
|
|
388
387
|
}
|
|
389
388
|
async cancelBill(opts) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
389
|
+
const bill_id = billActionID(opts);
|
|
390
|
+
if (opts.bill.is_estimate && resolvedID(opts.bill.accepted_bill_id) !== undefined) {
|
|
391
|
+
throw errValidation({ field: "bill", msg: msgAcceptedEstimateCancellation });
|
|
392
|
+
}
|
|
393
|
+
const out = await this.billable.cancelBill({ bill_id });
|
|
394
|
+
return await this.findBill(requiredOperationID(out, msgBillIDMissing));
|
|
395
|
+
}
|
|
396
|
+
async retryBillReport(opts) {
|
|
397
|
+
const bill_id = billActionID(opts);
|
|
398
|
+
const out = await this.billable.retryBillReport({ bill_id });
|
|
399
|
+
return await this.findBill(requiredOperationID(out, msgBillIDMissing));
|
|
393
400
|
}
|
|
394
401
|
async vendorInvoiceFromBill(opts) {
|
|
395
402
|
const out = await this.billable.vendorInvoiceFromBill(opts);
|
|
@@ -737,6 +744,19 @@ function timestamp(value) {
|
|
|
737
744
|
export function newBillableFX(opts) {
|
|
738
745
|
return new BillableFX(opts);
|
|
739
746
|
}
|
|
747
|
+
function billActionID(opts) {
|
|
748
|
+
const id = resolvedID(opts.bill.id);
|
|
749
|
+
if (id === undefined) {
|
|
750
|
+
throw errRequired({ field: "bill", msg: msgBillIDRequired });
|
|
751
|
+
}
|
|
752
|
+
return id;
|
|
753
|
+
}
|
|
754
|
+
export function billableCanCompleteBill(bill) {
|
|
755
|
+
return !bill.is_estimate && !bill.is_canceled && !bill.is_location_achieved;
|
|
756
|
+
}
|
|
757
|
+
export function billableCanCancelBill(bill) {
|
|
758
|
+
return !bill.is_canceled && (!bill.is_estimate || resolvedID(bill.accepted_bill_id) === undefined);
|
|
759
|
+
}
|
|
740
760
|
function fixedEstimateID(opts) {
|
|
741
761
|
const estimate = opts.estimate;
|
|
742
762
|
const id = resolvedID(estimate.id);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabriktor/fx",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.96",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
"typescript": "^6.0.3"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@fabriktor/client": "0.0.
|
|
21
|
-
"@fabriktor/
|
|
20
|
+
"@fabriktor/client": "0.0.77",
|
|
21
|
+
"@fabriktor/fx": "0.0.94",
|
|
22
|
+
"@fabriktor/schema": "0.0.60"
|
|
22
23
|
}
|
|
23
24
|
}
|