-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
prebuilt-invoice.ts
559 lines (547 loc) · 16.2 KB
/
prebuilt-invoice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* @azsdk-util
* @azsdk-skip-javascript
*/
// Model: prebuilt-invoice
// Description: Extract key information from invoices.
// API Version: 2023-07-31
// Created: Wed Aug 02 2023
import * as fr from "@azure/ai-form-recognizer";
/**
* Extract key information from invoices.
*/
export const PrebuiltInvoiceModel = fr.createModelFromSchema(
modelInfo()
) as fr.DocumentModel<PrebuiltInvoiceResult>;
export interface PrebuiltInvoiceResult extends fr.AnalyzeResultCommon {
/**
* Extracted pages.
*/
pages?: fr.DocumentPage[];
/**
* Extracted document paragraphs.
*/
paragraphs?: fr.DocumentParagraph[];
/**
* Extracted font styles.
*/
styles?: fr.DocumentStyle[];
/**
* Extracted tables.
*/
tables?: fr.DocumentTable[];
/**
* Extracted key-value pairs.
*/
keyValuePairs?: fr.DocumentKeyValuePair[];
/**
* Extracted documents.
*/
documents: PrebuiltInvoiceDocument[];
}
export type PrebuiltInvoiceDocument = Invoice;
export interface Invoice {
/**
* Document type: "invoice".
*/
docType: "invoice";
/**
* Document fields.
*/
fields: InvoiceFields;
/**
* Bounding regions covering the document.
*/
boundingRegions?: fr.BoundingRegion[];
/**
* Locations of the document's elements in the `content` text (reading-order-concatenated content).
*/
spans: fr.DocumentSpan[];
/**
* The service's confidence that it has correctly extracted the document.
*/
confidence: number;
}
/**
* Describes the fields of `InvoiceFields`.
*/
export interface InvoiceFields {
/**
* Customer being invoiced
*/
customerName?: fr.DocumentStringField;
/**
* Reference ID for the customer
*/
customerId?: fr.DocumentStringField;
/**
* A purchase order reference number
*/
purchaseOrder?: fr.DocumentStringField;
/**
* ID for this specific invoice (often 'Invoice Number')
*/
invoiceId?: fr.DocumentStringField;
/**
* Date the invoice was issued
*/
invoiceDate?: fr.DocumentDateField;
/**
* Date payment for this invoice is due
*/
dueDate?: fr.DocumentDateField;
/**
* Vendor who has created this invoice
*/
vendorName?: fr.DocumentStringField;
/**
* Mailing address for the Vendor
*/
vendorAddress?: fr.DocumentAddressField;
/**
* Name associated with the VendorAddress
*/
vendorAddressRecipient?: fr.DocumentStringField;
/**
* Mailing address for the Customer
*/
customerAddress?: fr.DocumentAddressField;
/**
* Name associated with the CustomerAddress
*/
customerAddressRecipient?: fr.DocumentStringField;
/**
* Explicit billing address for the customer
*/
billingAddress?: fr.DocumentAddressField;
/**
* Name associated with the BillingAddress
*/
billingAddressRecipient?: fr.DocumentStringField;
/**
* Explicit shipping address for the customer
*/
shippingAddress?: fr.DocumentAddressField;
/**
* Name associated with the ShippingAddress
*/
shippingAddressRecipient?: fr.DocumentStringField;
/**
* Subtotal field identified on this invoice
*/
subTotal?: fr.DocumentCurrencyField;
/**
* Total discount field identified on this invoice
*/
totalDiscount?: fr.DocumentCurrencyField;
/**
* Total tax field identified on this invoice
*/
totalTax?: fr.DocumentCurrencyField;
/**
* Total new charges associated with this invoice
*/
invoiceTotal?: fr.DocumentCurrencyField;
/**
* Total Amount Due to the vendor
*/
amountDue?: fr.DocumentCurrencyField;
/**
* Explicit previously unpaid balance
*/
previousUnpaidBalance?: fr.DocumentCurrencyField;
/**
* Explicit remittance or payment address for the customer
*/
remittanceAddress?: fr.DocumentAddressField;
/**
* Name associated with the RemittanceAddress
*/
remittanceAddressRecipient?: fr.DocumentStringField;
/**
* Explicit service address or property address for the customer
*/
serviceAddress?: fr.DocumentAddressField;
/**
* Name associated with the ServiceAddress
*/
serviceAddressRecipient?: fr.DocumentStringField;
/**
* First date for the service period (for example, a utility bill service period)
*/
serviceStartDate?: fr.DocumentDateField;
/**
* End date for the service period (for example, a utility bill service period)
*/
serviceEndDate?: fr.DocumentDateField;
/**
* The government ID number associated with the vendor
*/
vendorTaxId?: fr.DocumentStringField;
/**
* The government ID number associated with the customer
*/
customerTaxId?: fr.DocumentStringField;
/**
* The terms under which the payment is meant to be paid
*/
paymentTerm?: fr.DocumentStringField;
/**
* List of payment details
*/
paymentDetails?: fr.DocumentArrayField<fr.DocumentObjectField<InvoicePaymentDetailsElement>>;
/**
* List of tax details
*/
taxDetails?: fr.DocumentArrayField<fr.DocumentObjectField<InvoiceTaxDetailsElement>>;
/**
* List of line items
*/
items?: fr.DocumentArrayField<fr.DocumentObjectField<InvoiceItemsElement>>;
}
/**
* Describes the fields of `InvoicePaymentDetailsElement`.
*
* List of payment details
*/
export interface InvoicePaymentDetailsElement {
/**
* International bank account number
*/
iBAN?: fr.DocumentStringField;
/**
* ISO9362, an international standard for Business Identifier Codes (BIC)
*/
sWIFT?: fr.DocumentStringField;
}
/**
* Describes the fields of `InvoiceTaxDetailsElement`.
*
* List of tax details
*/
export interface InvoiceTaxDetailsElement {
/**
* The amount of the tax detail
*/
amount?: fr.DocumentCurrencyField;
/**
* The rate of the tax detail
*/
rate?: fr.DocumentStringField;
}
/**
* Describes the fields of `InvoiceItemsElement`.
*
* List of line items
*/
export interface InvoiceItemsElement {
/**
* The amount of the line item
*/
amount?: fr.DocumentCurrencyField;
/**
* Date corresponding to each line item. Often it is a date the line item was shipped
*/
date?: fr.DocumentDateField;
/**
* The text description for the invoice line item
*/
description?: fr.DocumentStringField;
/**
* The quantity for this invoice line item
*/
quantity?: fr.DocumentNumberField;
/**
* Product code, product number, or SKU associated with the specific line item
*/
productCode?: fr.DocumentStringField;
/**
* Tax associated with each line item. Possible values include tax amount, tax %, and tax Y/N
*/
tax?: fr.DocumentCurrencyField;
/**
* Tax rate associated with each line item
*/
taxRate?: fr.DocumentStringField;
/**
* The unit of the line item, e.g, kg, lb etc.
*/
unit?: fr.DocumentStringField;
/**
* The net or gross price (depending on the gross invoice setting of the invoice) of one unit of this item
*/
unitPrice?: fr.DocumentCurrencyField;
}
/**
* The raw model schema.
*/
function modelInfo() {
return {
modelId: "prebuilt-invoice",
description: "Extract key information from invoices.",
createdOn: "2023-07-31T00:00:00.000Z",
apiVersion: "2023-07-31",
docTypes: {
invoice: {
buildMode: "template",
fieldSchema: {
CustomerName: {
type: "string",
description: "Customer being invoiced",
example: "Microsoft Corp",
},
CustomerId: {
type: "string",
description: "Reference ID for the customer",
example: "CID-12345",
},
PurchaseOrder: {
type: "string",
description: "A purchase order reference number",
example: "PO-3333",
},
InvoiceId: {
type: "string",
description: "ID for this specific invoice (often 'Invoice Number')",
example: "INV-100",
},
InvoiceDate: {
type: "date",
description: "Date the invoice was issued",
example: "11/15/2019",
},
DueDate: {
type: "date",
description: "Date payment for this invoice is due",
example: "12/15/2019",
},
VendorName: {
type: "string",
description: "Vendor who has created this invoice",
example: "CONTOSO LTD.",
},
VendorAddress: {
type: "address",
description: "Mailing address for the Vendor",
example: "123 456th St New York, NY, 10001",
},
VendorAddressRecipient: {
type: "string",
description: "Name associated with the VendorAddress",
example: "Contoso Headquarters",
},
CustomerAddress: {
type: "address",
description: "Mailing address for the Customer",
example: "123 Other St, Redmond WA, 98052",
},
CustomerAddressRecipient: {
type: "string",
description: "Name associated with the CustomerAddress",
example: "Microsoft Corp",
},
BillingAddress: {
type: "address",
description: "Explicit billing address for the customer",
example: "123 Bill St, Redmond WA, 98052",
},
BillingAddressRecipient: {
type: "string",
description: "Name associated with the BillingAddress",
example: "Microsoft Services",
},
ShippingAddress: {
type: "address",
description: "Explicit shipping address for the customer",
example: "123 Ship St, Redmond WA, 98052",
},
ShippingAddressRecipient: {
type: "string",
description: "Name associated with the ShippingAddress",
example: "Microsoft Delivery",
},
SubTotal: {
type: "currency",
description: "Subtotal field identified on this invoice",
example: "$100.00",
},
TotalDiscount: {
type: "currency",
description: "Total discount field identified on this invoice",
example: "$5.00",
},
TotalTax: {
type: "currency",
description: "Total tax field identified on this invoice",
example: "$10.00",
},
InvoiceTotal: {
type: "currency",
description: "Total new charges associated with this invoice",
example: "$110.00",
},
AmountDue: {
type: "currency",
description: "Total Amount Due to the vendor",
example: "$610.00",
},
PreviousUnpaidBalance: {
type: "currency",
description: "Explicit previously unpaid balance",
example: "$500.00",
},
RemittanceAddress: {
type: "address",
description: "Explicit remittance or payment address for the customer",
example: "123 Remit St New York, NY, 10001",
},
RemittanceAddressRecipient: {
type: "string",
description: "Name associated with the RemittanceAddress",
example: "Contoso Billing",
},
ServiceAddress: {
type: "address",
description: "Explicit service address or property address for the customer",
example: "123 Service St, Redmond WA, 98052",
},
ServiceAddressRecipient: {
type: "string",
description: "Name associated with the ServiceAddress",
example: "Microsoft Services",
},
ServiceStartDate: {
type: "date",
description:
"First date for the service period (for example, a utility bill service period)",
example: "10/14/2019",
},
ServiceEndDate: {
type: "date",
description:
"End date for the service period (for example, a utility bill service period)",
example: "11/14/2019",
},
VendorTaxId: {
type: "string",
description: "The government ID number associated with the vendor",
example: "123456-7",
},
CustomerTaxId: {
type: "string",
description: "The government ID number associated with the customer",
example: "765432-1",
},
PaymentTerm: {
type: "string",
description: "The terms under which the payment is meant to be paid",
example: "Net90",
},
PaymentDetails: {
type: "array",
description: "List of payment details",
items: {
type: "object",
description: "A single payment detail",
properties: {
IBAN: {
type: "string",
description: "International bank account number",
example: "DE 94 700 700 100 029 49 00 00",
},
SWIFT: {
type: "string",
description:
"ISO9362, an international standard for Business Identifier Codes (BIC)",
example: "DEUTDEMMXXX",
},
},
},
},
TaxDetails: {
type: "array",
description: "List of tax details",
items: {
type: "object",
description: "A single tax detail",
properties: {
Amount: {
type: "currency",
description: "The amount of the tax detail",
example: "29,520.00",
},
Rate: {
type: "string",
description: "The rate of the tax detail",
example: "18 %",
},
},
},
},
Items: {
type: "array",
description: "List of line items",
items: {
type: "object",
description: "A single line item",
example: "3/4/2021\nA123\nConsulting Services\n2 hours\n$30.00\n10%\n$60.00",
properties: {
Amount: {
type: "currency",
description: "The amount of the line item",
example: "$60.00",
},
Date: {
type: "date",
description:
"Date corresponding to each line item. Often it is a date the line item was shipped",
example: "3/4/2021",
},
Description: {
type: "string",
description: "The text description for the invoice line item",
example: "Consulting service",
},
Quantity: {
type: "number",
description: "The quantity for this invoice line item",
example: "2",
},
ProductCode: {
type: "string",
description:
"Product code, product number, or SKU associated with the specific line item",
example: "A123",
},
Tax: {
type: "currency",
description:
"Tax associated with each line item. Possible values include tax amount, tax %, and tax Y/N",
example: "$6.00",
},
TaxRate: {
type: "string",
description: "Tax rate associated with each line item",
example: "18 %",
},
Unit: {
type: "string",
description: "The unit of the line item, e.g, kg, lb etc.",
example: "hours",
},
UnitPrice: {
type: "currency",
description:
"The net or gross price (depending on the gross invoice setting of the invoice) of one unit of this item",
example: "$30.00",
},
},
},
},
},
},
},
} as const;
}