@company-six/qbosync 0.3.0 → 0.5.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/README.md +140 -5
- package/dist/client.d.ts +18 -0
- package/dist/client.js +36 -1
- package/dist/contract/answers.d.ts +5 -2
- package/dist/contract/bill.d.ts +271 -0
- package/dist/contract/bill.js +130 -0
- package/dist/contract/codes.d.ts +56 -0
- package/dist/contract/codes.js +65 -0
- package/dist/contract/index.d.ts +182 -2
- package/dist/contract/index.js +5 -2
- package/dist/contract/protocol.d.ts +2 -2
- package/dist/contract/protocol.js +2 -2
- package/dist/contract/statusReport.d.ts +2 -0
- package/package.json +2 -2
- package/sql/002_daily_report.sql +260 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @company-six/qbosync
|
|
2
2
|
|
|
3
|
-
Connect your app to QBO Sync, which posts your sales to each company's QuickBooks. Your app sends invoices and credit memos; QBO Sync checks them, posts them and tells your app what happened to each one.
|
|
3
|
+
Connect your app to QBO Sync, which posts your sales and costs to each company's QuickBooks. Your app sends invoices and credit memos, and bills and vendor credits if it records what the company owes its vendors; QBO Sync checks them, posts them and tells your app what happened to each one.
|
|
4
4
|
|
|
5
5
|
Server-side only (Node 20 or later): it holds your app's tokens. TypeScript types are included (TypeScript 5 or later).
|
|
6
6
|
|
|
@@ -105,7 +105,54 @@ Each document is checked against the contract first; one that fails is not sent
|
|
|
105
105
|
|
|
106
106
|
**A document is sent once.** QBO Sync keeps it exactly as first received, so `version` is 1 and a later version is refused. To correct an invoice, send a credit memo, or have a person roll it back in QBO Sync. Sending again after a failure is always safe: QBO Sync answers `unchanged`.
|
|
107
107
|
|
|
108
|
-
|
|
108
|
+
**Item codes and products.** QuickBooks puts every invoice and credit memo line on a product, and QBO Sync picks it by the line's `item_code`: the product the company chose for your code in QBO Sync's Setup → Products, else the QuickBooks product with that SKU, else (by default) a new product named after the line. Send real SKUs if you have a catalogue, or a few fixed category codes (`SALES`, `SHIPPING`) if you don't, the same code for the same thing every time. A company can set your app to never create products; then a line whose code has no product waits in QBO Sync until the company chooses one, and its status report says so. Nothing changes in what you send.
|
|
109
|
+
|
|
110
|
+
**Listing your codes (0.5.0).** If you send a few fixed codes, list them once, each with a label, so every company sees them by name in Setup → Products (item codes) and Setup → Cost codes (bill cost codes) before your first document arrives:
|
|
111
|
+
|
|
112
|
+
```ts
|
|
113
|
+
const listed = await qbosync.declareCodes({
|
|
114
|
+
item_codes: [
|
|
115
|
+
{ code: "SALES", label: "Products, decoration and other charges" },
|
|
116
|
+
{ code: "SHIPPING", label: "Shipping and freight", description: "Every shipping line" },
|
|
117
|
+
],
|
|
118
|
+
cost_codes: [{ code: "freight", label: "Inbound freight" }],
|
|
119
|
+
});
|
|
120
|
+
if (!listed.ok) console.error(listed.error);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Each list you send replaces your whole list of that kind (a code left out is removed); a kind you leave out is kept. It is checked against the contract before anything is sent, changes nothing about posting, and is safe to call again with the same lists, for example each time your app starts. `declaredCodes()` reads back what QBO Sync holds. An app with real catalogue SKUs lists nothing.
|
|
124
|
+
|
|
125
|
+
Apps send invoices, credit memos, bills and vendor credits. Payments, refunds and payouts reach QBO Sync through its own connectors, matched to your invoices by `order_ref`, so give every invoice the `order_ref` of its order. Paying a bill is a money movement too: apps never send one.
|
|
126
|
+
|
|
127
|
+
### Bills and vendor credits (0.5.0)
|
|
128
|
+
|
|
129
|
+
A bill is what the company owes a vendor; a vendor credit is what a vendor gave back. QBO Sync posts them as QuickBooks Bills and Vendor Credits.
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
import type { BillDTO } from "@company-six/qbosync/contract";
|
|
133
|
+
|
|
134
|
+
const bill: BillDTO = {
|
|
135
|
+
schema_version: "1", source_ref: "po-2207-bill", company_key: "Acme", version: 1, status: "active",
|
|
136
|
+
type: "bill",
|
|
137
|
+
number: "BT-55120", // the vendor's bill number
|
|
138
|
+
issue_date: "2026-10-18",
|
|
139
|
+
terms_code: "net_30", // or due_date; QuickBooks works the date out from terms
|
|
140
|
+
currency: "USD",
|
|
141
|
+
vendor: { ref: "vendor-77", name: "Blank Tee Supply" }, // one QuickBooks vendor per ref
|
|
142
|
+
customer: { ref: "customer-3141", name: "Corner Market" }, // optional: whose sale this cost belongs to
|
|
143
|
+
lines: [
|
|
144
|
+
{ description: "Freight", amount_cents: 1500, cost_code: "freight" }, // an account line
|
|
145
|
+
{ description: "Black tee, M", amount_cents: 19800, item_code: "TEE-BLK-M", quantity: 48, unit_cost_cents: 412.5 }, // an item line
|
|
146
|
+
],
|
|
147
|
+
total_cents: 21300,
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
- A line is an **account line** (`cost_code`: your word for what was paid for) or an **item line** (`item_code`, `quantity`, `unit_cost_cents`: a product bought, by SKU). Each company maps your cost codes to its accounts once, in QBO Sync's Setup; a bill whose code is not mapped waits, and its status report says so. An item line posts on the product the company chose for its `item_code` in Setup → Products (the same choice your invoices use), else the QuickBooks product with that SKU; a bill never creates a product, so with neither it fails, or waits until the company chooses one if it has set your app to never create products.
|
|
152
|
+
- `customer` (on the bill, or on one line) puts the cost on that customer for job costing; it is not billed to them again.
|
|
153
|
+
- A vendor credit has the same fields, no terms, and may name its bill with `applies_to_bill_ref`. QuickBooks offers the credit when the company next pays that vendor.
|
|
154
|
+
- `number` is unique per vendor among your bills. When QuickBooks already holds a bill from that vendor with that number, the bill waits for a person in QBO Sync to link it or post it anyway.
|
|
155
|
+
- Like an invoice, a bill is kept as first received: correct it with a vendor credit.
|
|
109
156
|
|
|
110
157
|
## 6. Receive status reports
|
|
111
158
|
|
|
@@ -158,15 +205,103 @@ const checked = await client.checkStatusReports(body, headers[SIGNATURE_HEADER])
|
|
|
158
205
|
|
|
159
206
|
Never use these outside tests: anyone can make such a key.
|
|
160
207
|
|
|
161
|
-
## 7.
|
|
208
|
+
## 7. A daily report (optional)
|
|
162
209
|
|
|
163
|
-
|
|
210
|
+
Each morning, set the invoices and credit memos your app created the day before beside what QBO Sync did with them: posted with the same amounts, posted but different, waiting, failed, or never received. QBO Sync answers for each document; your app picks the documents, compares, keeps the report and shows it. Fixing anything (a resync, a rollback) is done in QBO Sync.
|
|
211
|
+
|
|
212
|
+
To ask about any number of your documents (in batches of 100, answered in the order asked):
|
|
164
213
|
|
|
165
214
|
```ts
|
|
166
|
-
const
|
|
215
|
+
const asked = await qbosync.documentReport(refs);
|
|
167
216
|
// each entry: its status, QuickBooks number, what was posted and the nightly check, or sync_status "unknown" if never received
|
|
168
217
|
```
|
|
169
218
|
|
|
219
|
+
The rest of this section builds the report around that call. Your app does all of it; only the tables come with the SDK.
|
|
220
|
+
|
|
221
|
+
### Add the report tables
|
|
222
|
+
|
|
223
|
+
Run [`sql/002_daily_report.sql`](sql/002_daily_report.sql) once, as you ran the first file (it is in `node_modules/@company-six/qbosync/sql/`). It adds:
|
|
224
|
+
|
|
225
|
+
- **`qbosync_report_runs`**: one row per run. It holds the day, its window in UTC, whether it is running, done or failed, and a finished day's totals.
|
|
226
|
+
- **`qbosync_report_rows`**: one row per document per run. It holds what was true that morning, so a past report shows what it showed then.
|
|
227
|
+
- **`qbosync_report_start(day, time_zone)`**, **`qbosync_report_finish(run_id, counts)`** and **`qbosync_report_fail(run_id, error)`**.
|
|
228
|
+
|
|
229
|
+
The database keeps the rules for you. Only one run runs at a time, and a day has one finished report: finishing a rerun replaces the earlier report. A failed run keeps no rows and leaves the earlier report in place. A run left running for 30 minutes (its server died) is marked failed by the next start.
|
|
230
|
+
|
|
231
|
+
### Run it each morning
|
|
232
|
+
|
|
233
|
+
Run a scheduled job after QBO Sync's nightly QuickBooks check, which starts at 08:00 UTC (11:00 UTC leaves room). Report **yesterday in your own time zone**. Then make up any earlier day that has no finished report, counting from the first day that has one, oldest first and a few days at most per run. That way a morning that failed fills itself in.
|
|
234
|
+
|
|
235
|
+
```ts
|
|
236
|
+
import type { ReportEntry } from "@company-six/qbosync/contract";
|
|
237
|
+
|
|
238
|
+
const TIME_ZONE = "America/Chicago"; // your app's day
|
|
239
|
+
|
|
240
|
+
async function reportDay(day: string) { // "2026-11-08"
|
|
241
|
+
const { data: run, error } = await supabase.rpc("qbosync_report_start", { p_report_date: day, p_time_zone: TIME_ZONE });
|
|
242
|
+
if (error) throw new Error(error.message); // another run is running: stop, the next one makes the day up
|
|
243
|
+
|
|
244
|
+
try {
|
|
245
|
+
// From YOUR records: the documents you created in [window_start, window_end), each with the ref you sent it under.
|
|
246
|
+
const docs = await documentsCreated(run.window_start, run.window_end);
|
|
247
|
+
const asked = await qbosync.documentReport(docs.map((d) => d.source_ref));
|
|
248
|
+
if (!asked.ok) throw new Error(asked.error);
|
|
249
|
+
|
|
250
|
+
const rows = docs.map((doc, i) => ({
|
|
251
|
+
run_id: run.id,
|
|
252
|
+
document_type: doc.document_type, // "invoice" | "credit_memo" | "bill" | "vendor_credit"
|
|
253
|
+
source_ref: doc.source_ref,
|
|
254
|
+
company_key: doc.company_key,
|
|
255
|
+
document_id: doc.id,
|
|
256
|
+
label: doc.order_number,
|
|
257
|
+
...compare(doc, asked.documents[i]),
|
|
258
|
+
}));
|
|
259
|
+
if (rows.length) {
|
|
260
|
+
const inserted = await supabase.from("qbosync_report_rows").insert(rows);
|
|
261
|
+
if (inserted.error) throw new Error(inserted.error.message);
|
|
262
|
+
}
|
|
263
|
+
const finished = await supabase.rpc("qbosync_report_finish", { p_run_id: run.id, p_counts: countByResult(rows) });
|
|
264
|
+
if (finished.error) throw new Error(finished.error.message);
|
|
265
|
+
} catch (err) {
|
|
266
|
+
await supabase.rpc("qbosync_report_fail", { p_run_id: run.id, p_error: err instanceof Error ? err.message : String(err) });
|
|
267
|
+
throw err; // stop: the next morning makes this day up
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
Pick the documents **by when your app created them**, not by their issue date or by when QBO Sync received them. QBO Sync may receive a document hours later (a retry, a company with syncing off), and only your app knows when it made it. Leave out what your app never meant to send, such as a company that has not connected. Otherwise every one of its documents reads as never received.
|
|
273
|
+
|
|
274
|
+
Insert in pages of a few hundred rows on a busy day.
|
|
275
|
+
|
|
276
|
+
### Compare
|
|
277
|
+
|
|
278
|
+
Give each document **one** result, checked in this order:
|
|
279
|
+
|
|
280
|
+
| Result | When |
|
|
281
|
+
|---|---|
|
|
282
|
+
| `not_received` | `sync_status` is `"unknown"`: QBO Sync never received it. Keep your own record of the send beside it (`send_status`, `error`). |
|
|
283
|
+
| `failed` | `sync_status` is `"failed"`. Keep QBO Sync's `error`. |
|
|
284
|
+
| `not_posted` | `posted` is null, or `sync_status` is `"deleted"` or `"excluded"`. It is waiting, syncing is off, or it was excluded or rolled back. |
|
|
285
|
+
| `changed_since_posted` | `posted_version` is not `latest_version`, or your document changed after QBO Sync accepted it. A newer version has not been posted. |
|
|
286
|
+
| `differs` | Something below does not match. Say what in `differences` (a JSON array, never empty, in whatever shape your page shows). |
|
|
287
|
+
| `matches` | Everything below matches. |
|
|
288
|
+
|
|
289
|
+
What to check for `differs`:
|
|
290
|
+
|
|
291
|
+
- **Amounts**: your totals against `posted`. `total_cents`, `shipping_cents`, `tax_cents` and, on an invoice, `discount_cents`. Then each line by its `line_ref` (on a credit memo, `applies_to_line_ref`): its `quantity` and `amount_cents`, and any line only one side has. `posted` is in your own terms, in cents, and a credit memo's amounts are positive.
|
|
292
|
+
- **Voided**: a document you voided should read `sync_status: "voided"`, and the other way round. When both are voided, there are no amounts to compare.
|
|
293
|
+
- **QuickBooks**: `check.result` is QBO Sync's nightly read-back. `differs` means someone changed the document in QuickBooks; `check.differences` says how, in sentences you can show. `missing` means it was deleted there. Either one makes the result `differs`. `not_checked` (the check has not reached it yet) does not keep a document from matching.
|
|
294
|
+
|
|
295
|
+
Copy `qbo_number`, `sync_status`, `synced_at` and `check.result` (as `qbo_check`) into every row QBO Sync knows, so the row stands on its own later. For totals, count rows by result and add `documents`: `{ "documents": 12, "matches": 11, "failed": 1 }`.
|
|
296
|
+
|
|
297
|
+
### Show it
|
|
298
|
+
|
|
299
|
+
- **The list of days**: one line per `report_date`, newest first. Show the day's `done` run with its `counts`. A day with no finished run shows its latest failed run with its `error`, so a gap is visible until a later run makes it up.
|
|
300
|
+
- **One day**: its rows, by `company_key`.
|
|
301
|
+
- **Who sees what**: the tables are for your server only. Show each person only the rows of the companies they belong to, through your own route.
|
|
302
|
+
|
|
303
|
+
Keep the report read-only, and send people to QBO Sync to fix a document.
|
|
304
|
+
|
|
170
305
|
## When a call fails
|
|
171
306
|
|
|
172
307
|
Nothing here throws for something QBO Sync or the network did. Every call answers `{ ok: true, ... }` or a failure with an `error` you can show a person, and a `reason`:
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type CollectResult, type ConnectRequestStore, type OpenResult } from "./connectRequest.ts";
|
|
2
2
|
import { type ConnectionStore, type Log } from "./connection.ts";
|
|
3
|
+
import { type CodesDeclaration, type DeclaredCodes } from "./contract/index.ts";
|
|
3
4
|
import { type SignInRole } from "./contract/protocol.ts";
|
|
4
5
|
import { type AppCompanyStatus, type ReceiveResult, type ReportEntry, type SendOutcome } from "./contract/answers.ts";
|
|
5
6
|
import { type CheckedStatusReports } from "./statusReports.ts";
|
|
@@ -136,6 +137,23 @@ export declare class QbosyncClient {
|
|
|
136
137
|
ok: true;
|
|
137
138
|
documents: ReportEntry[];
|
|
138
139
|
} | Failure>;
|
|
140
|
+
/**
|
|
141
|
+
* Lists the codes the app uses, each with a label, so a company sees them in QBO Sync's Setup before any
|
|
142
|
+
* document carries them: item codes under Setup -> Products, cost codes under Setup -> Cost codes. Each kind
|
|
143
|
+
* sent is the app's whole list of that kind (a code left out is removed); a kind not sent is left as it is.
|
|
144
|
+
* Changes nothing about posting. Checked here first: a list that fails is not sent (`rejected`, `status` absent).
|
|
145
|
+
* Safe to call again with the same list, for example each time the app starts.
|
|
146
|
+
*/
|
|
147
|
+
declareCodes(input: CodesDeclaration): Promise<{
|
|
148
|
+
ok: true;
|
|
149
|
+
codes: DeclaredCodes;
|
|
150
|
+
} | Failure>;
|
|
151
|
+
/** The codes QBO Sync holds for the app, as last listed with `declareCodes`. */
|
|
152
|
+
declaredCodes(): Promise<{
|
|
153
|
+
ok: true;
|
|
154
|
+
codes: DeclaredCodes;
|
|
155
|
+
} | Failure>;
|
|
156
|
+
private codesAnswer;
|
|
139
157
|
/** Which of the app's companies are connected to QBO Sync, with their QuickBooks and syncing. */
|
|
140
158
|
listCompanies(): Promise<{
|
|
141
159
|
ok: true;
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { collectConnectRequest, openConnectRequest } from "./connectRequest.js";
|
|
2
2
|
import { currentCredential, sendRenewingOn401 } from "./connection.js";
|
|
3
|
-
import { checkDocument } from "./contract/index.js";
|
|
3
|
+
import { checkDocument, codesDeclarationSchema, formatIssue } from "./contract/index.js";
|
|
4
4
|
import { MAX_DOCUMENTS_PER_REQUEST, MAX_REPORT_REFS } from "./contract/protocol.js";
|
|
5
5
|
import { endedReasonInWords, outcomeOf } from "./contract/answers.js";
|
|
6
6
|
import { checkStatusReports, SigningKeys } from "./statusReports.js";
|
|
@@ -219,6 +219,41 @@ export class QbosyncClient {
|
|
|
219
219
|
}
|
|
220
220
|
return { ok: true, documents };
|
|
221
221
|
}
|
|
222
|
+
// ---- codes
|
|
223
|
+
/**
|
|
224
|
+
* Lists the codes the app uses, each with a label, so a company sees them in QBO Sync's Setup before any
|
|
225
|
+
* document carries them: item codes under Setup -> Products, cost codes under Setup -> Cost codes. Each kind
|
|
226
|
+
* sent is the app's whole list of that kind (a code left out is removed); a kind not sent is left as it is.
|
|
227
|
+
* Changes nothing about posting. Checked here first: a list that fails is not sent (`rejected`, `status` absent).
|
|
228
|
+
* Safe to call again with the same list, for example each time the app starts.
|
|
229
|
+
*/
|
|
230
|
+
async declareCodes(input) {
|
|
231
|
+
const checked = codesDeclarationSchema.safeParse(input);
|
|
232
|
+
if (!checked.success) {
|
|
233
|
+
const reasons = checked.error.issues.map(formatIssue).join("; ");
|
|
234
|
+
return { ok: false, reason: "rejected", error: `The codes were not sent: ${reasons}`, detail: reasons };
|
|
235
|
+
}
|
|
236
|
+
const called = await this.call("/api/v1/codes", {
|
|
237
|
+
method: "PUT",
|
|
238
|
+
headers: { "Content-Type": "application/json" },
|
|
239
|
+
body: JSON.stringify(checked.data),
|
|
240
|
+
});
|
|
241
|
+
return this.codesAnswer(called);
|
|
242
|
+
}
|
|
243
|
+
/** The codes QBO Sync holds for the app, as last listed with `declareCodes`. */
|
|
244
|
+
async declaredCodes() {
|
|
245
|
+
return this.codesAnswer(await this.call("/api/v1/codes"));
|
|
246
|
+
}
|
|
247
|
+
async codesAnswer(called) {
|
|
248
|
+
if (!called.ok)
|
|
249
|
+
return called;
|
|
250
|
+
const body = (await called.res.json().catch(() => null));
|
|
251
|
+
if (!called.res.ok)
|
|
252
|
+
return failureOf(called.res, body);
|
|
253
|
+
if (!Array.isArray(body?.item_codes) || !Array.isArray(body?.cost_codes))
|
|
254
|
+
return unexpected(called.res.status, "QBO Sync's answer has no codes lists");
|
|
255
|
+
return { ok: true, codes: { item_codes: body.item_codes, cost_codes: body.cost_codes } };
|
|
256
|
+
}
|
|
222
257
|
// ---- companies and people
|
|
223
258
|
/** Which of the app's companies are connected to QBO Sync, with their QuickBooks and syncing. */
|
|
224
259
|
async listCompanies() {
|
|
@@ -47,7 +47,10 @@ export interface PostedLine {
|
|
|
47
47
|
quantity: number;
|
|
48
48
|
amount_cents: number;
|
|
49
49
|
}
|
|
50
|
-
/**
|
|
50
|
+
/**
|
|
51
|
+
* What was posted, in the app's own terms. A credit memo has no discount. A bill or vendor credit has no shipping or
|
|
52
|
+
* tax (0), and an account line reports quantity 1.
|
|
53
|
+
*/
|
|
51
54
|
export interface PostedAmounts {
|
|
52
55
|
total_cents: number;
|
|
53
56
|
shipping_cents: number;
|
|
@@ -68,7 +71,7 @@ export interface UnknownEntry {
|
|
|
68
71
|
}
|
|
69
72
|
export interface KnownEntry {
|
|
70
73
|
source_ref: string;
|
|
71
|
-
document_type: "invoice" | "credit_memo";
|
|
74
|
+
document_type: "invoice" | "credit_memo" | "bill" | "vendor_credit";
|
|
72
75
|
company_key: string | null;
|
|
73
76
|
company: string;
|
|
74
77
|
latest_version: number | null;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* What a company owes its vendors: bills, and the vendor credits that reduce them. QBO Sync posts them as
|
|
4
|
+
* QuickBooks Bills and Vendor Credits. Paying a bill is a money movement, and apps send none.
|
|
5
|
+
*
|
|
6
|
+
* Built on QuickBooks' own bill, not on any one app's: a line is an ACCOUNT line (a cost on the account its
|
|
7
|
+
* `cost_code` maps to) or an ITEM line (a product bought, by `item_code`, with quantity and unit cost).
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A cost code: the app's own word for what a line paid for (`freight`, `decoration`). Each company maps each
|
|
11
|
+
* app's codes once, in QBO Sync's Setup, to one of its QuickBooks accounts; a document with a code that is not
|
|
12
|
+
* mapped WAITS in QBO Sync until it is.
|
|
13
|
+
*/
|
|
14
|
+
export declare const costCode: z.ZodString;
|
|
15
|
+
/** One QuickBooks vendor per `ref` per company. Its name in QuickBooks is `company`, else `name`. */
|
|
16
|
+
export declare const vendor: z.ZodObject<{
|
|
17
|
+
ref: z.ZodString;
|
|
18
|
+
name: z.ZodString;
|
|
19
|
+
company: z.ZodOptional<z.ZodString>;
|
|
20
|
+
email: z.ZodOptional<z.ZodString>;
|
|
21
|
+
address: z.ZodOptional<z.ZodObject<{
|
|
22
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
23
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
24
|
+
city: z.ZodOptional<z.ZodString>;
|
|
25
|
+
region: z.ZodOptional<z.ZodString>;
|
|
26
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
27
|
+
country: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
/**
|
|
31
|
+
* One line of a bill or vendor credit: EITHER an account line (`cost_code`) OR an item line (`item_code`,
|
|
32
|
+
* `quantity`, `unit_cost_cents`). An item line's amount is quantity × unit cost rounded to whole cents; the unit
|
|
33
|
+
* cost may carry fractions of a cent (bought at $0.125 each). `customer` and `class_key` on a line take the place
|
|
34
|
+
* of the document's own for that line.
|
|
35
|
+
*/
|
|
36
|
+
export declare const billLine: z.ZodObject<{
|
|
37
|
+
description: z.ZodString;
|
|
38
|
+
amount_cents: z.ZodInt;
|
|
39
|
+
cost_code: z.ZodOptional<z.ZodString>;
|
|
40
|
+
item_code: z.ZodOptional<z.ZodString>;
|
|
41
|
+
quantity: z.ZodOptional<z.ZodNumber>;
|
|
42
|
+
unit_cost_cents: z.ZodOptional<z.ZodNumber>;
|
|
43
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
44
|
+
ref: z.ZodString;
|
|
45
|
+
name: z.ZodString;
|
|
46
|
+
company: z.ZodOptional<z.ZodString>;
|
|
47
|
+
email: z.ZodOptional<z.ZodString>;
|
|
48
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
49
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
50
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
51
|
+
city: z.ZodOptional<z.ZodString>;
|
|
52
|
+
region: z.ZodOptional<z.ZodString>;
|
|
53
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
54
|
+
country: z.ZodOptional<z.ZodString>;
|
|
55
|
+
}, z.core.$strict>>;
|
|
56
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
57
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
58
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
59
|
+
city: z.ZodOptional<z.ZodString>;
|
|
60
|
+
region: z.ZodOptional<z.ZodString>;
|
|
61
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
62
|
+
country: z.ZodOptional<z.ZodString>;
|
|
63
|
+
}, z.core.$strict>>;
|
|
64
|
+
}, z.core.$strict>>;
|
|
65
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
66
|
+
}, z.core.$strict>;
|
|
67
|
+
/** Quantity × unit cost, rounded to whole cents, as the line's amount must be. */
|
|
68
|
+
export declare function itemLineAmount(line: {
|
|
69
|
+
quantity: number;
|
|
70
|
+
unit_cost_cents: number;
|
|
71
|
+
}): number;
|
|
72
|
+
/**
|
|
73
|
+
* What the company owes a vendor: posted as a Bill on Accounts Payable. `number` is the vendor's own bill
|
|
74
|
+
* number. `due_date` or `terms_code` (the same `net_<days>` as invoices) say when it is due; with terms,
|
|
75
|
+
* QuickBooks works the date out. `customer` (or a line's own) says whose sale the cost belongs to.
|
|
76
|
+
*
|
|
77
|
+
* A total of $0 is allowed: QuickBooks takes a $0 bill.
|
|
78
|
+
*
|
|
79
|
+
* Refused on its own: a line with both or neither of `cost_code` and `item_code`; an item line without its
|
|
80
|
+
* quantity or unit cost, or whose amount is not quantity × unit cost; a total that is not the sum of the lines.
|
|
81
|
+
* Whether the number is already used is checked when the document arrives.
|
|
82
|
+
*/
|
|
83
|
+
export declare const billSchema: z.ZodObject<{
|
|
84
|
+
type: z.ZodLiteral<"bill">;
|
|
85
|
+
due_date: z.ZodOptional<z.ZodString>;
|
|
86
|
+
terms_code: z.ZodOptional<z.ZodString>;
|
|
87
|
+
number: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodString>>;
|
|
88
|
+
issue_date: z.ZodString;
|
|
89
|
+
currency: z.ZodString;
|
|
90
|
+
vendor: z.ZodObject<{
|
|
91
|
+
ref: z.ZodString;
|
|
92
|
+
name: z.ZodString;
|
|
93
|
+
company: z.ZodOptional<z.ZodString>;
|
|
94
|
+
email: z.ZodOptional<z.ZodString>;
|
|
95
|
+
address: z.ZodOptional<z.ZodObject<{
|
|
96
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
97
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
98
|
+
city: z.ZodOptional<z.ZodString>;
|
|
99
|
+
region: z.ZodOptional<z.ZodString>;
|
|
100
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
101
|
+
country: z.ZodOptional<z.ZodString>;
|
|
102
|
+
}, z.core.$strict>>;
|
|
103
|
+
}, z.core.$strict>;
|
|
104
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
105
|
+
ref: z.ZodString;
|
|
106
|
+
name: z.ZodString;
|
|
107
|
+
company: z.ZodOptional<z.ZodString>;
|
|
108
|
+
email: z.ZodOptional<z.ZodString>;
|
|
109
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
110
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
111
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
112
|
+
city: z.ZodOptional<z.ZodString>;
|
|
113
|
+
region: z.ZodOptional<z.ZodString>;
|
|
114
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
115
|
+
country: z.ZodOptional<z.ZodString>;
|
|
116
|
+
}, z.core.$strict>>;
|
|
117
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
118
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
119
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
120
|
+
city: z.ZodOptional<z.ZodString>;
|
|
121
|
+
region: z.ZodOptional<z.ZodString>;
|
|
122
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
123
|
+
country: z.ZodOptional<z.ZodString>;
|
|
124
|
+
}, z.core.$strict>>;
|
|
125
|
+
}, z.core.$strict>>;
|
|
126
|
+
order_ref: z.ZodOptional<z.ZodString>;
|
|
127
|
+
references: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
128
|
+
label: z.ZodString;
|
|
129
|
+
value: z.ZodString;
|
|
130
|
+
}, z.core.$strict>>>;
|
|
131
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
132
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
133
|
+
description: z.ZodString;
|
|
134
|
+
amount_cents: z.ZodInt;
|
|
135
|
+
cost_code: z.ZodOptional<z.ZodString>;
|
|
136
|
+
item_code: z.ZodOptional<z.ZodString>;
|
|
137
|
+
quantity: z.ZodOptional<z.ZodNumber>;
|
|
138
|
+
unit_cost_cents: z.ZodOptional<z.ZodNumber>;
|
|
139
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
140
|
+
ref: z.ZodString;
|
|
141
|
+
name: z.ZodString;
|
|
142
|
+
company: z.ZodOptional<z.ZodString>;
|
|
143
|
+
email: z.ZodOptional<z.ZodString>;
|
|
144
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
145
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
146
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
147
|
+
city: z.ZodOptional<z.ZodString>;
|
|
148
|
+
region: z.ZodOptional<z.ZodString>;
|
|
149
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
150
|
+
country: z.ZodOptional<z.ZodString>;
|
|
151
|
+
}, z.core.$strict>>;
|
|
152
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
153
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
154
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
155
|
+
city: z.ZodOptional<z.ZodString>;
|
|
156
|
+
region: z.ZodOptional<z.ZodString>;
|
|
157
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
158
|
+
country: z.ZodOptional<z.ZodString>;
|
|
159
|
+
}, z.core.$strict>>;
|
|
160
|
+
}, z.core.$strict>>;
|
|
161
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
162
|
+
}, z.core.$strict>>;
|
|
163
|
+
total_cents: z.ZodInt;
|
|
164
|
+
schema_version: z.ZodLiteral<"1">;
|
|
165
|
+
source_ref: z.ZodString;
|
|
166
|
+
company_key: z.ZodString;
|
|
167
|
+
version: z.ZodInt;
|
|
168
|
+
status: z.ZodEnum<{
|
|
169
|
+
active: "active";
|
|
170
|
+
voided: "voided";
|
|
171
|
+
}>;
|
|
172
|
+
}, z.core.$strict>;
|
|
173
|
+
/**
|
|
174
|
+
* What a vendor gave back: posted as a Vendor Credit, which lowers what the company owes that vendor.
|
|
175
|
+
* `applies_to_bill_ref` names the bill it is against, when it is against one; the bill must be one this app sent,
|
|
176
|
+
* from the same vendor `ref`, and the credit posts after it. QuickBooks offers the credit when the company next
|
|
177
|
+
* pays that vendor; QBO Sync does not apply it.
|
|
178
|
+
*/
|
|
179
|
+
export declare const vendorCreditSchema: z.ZodObject<{
|
|
180
|
+
type: z.ZodLiteral<"vendor_credit">;
|
|
181
|
+
applies_to_bill_ref: z.ZodOptional<z.ZodString>;
|
|
182
|
+
number: z.ZodOptional<z.ZodPipe<z.ZodString, z.ZodString>>;
|
|
183
|
+
issue_date: z.ZodString;
|
|
184
|
+
currency: z.ZodString;
|
|
185
|
+
vendor: z.ZodObject<{
|
|
186
|
+
ref: z.ZodString;
|
|
187
|
+
name: z.ZodString;
|
|
188
|
+
company: z.ZodOptional<z.ZodString>;
|
|
189
|
+
email: z.ZodOptional<z.ZodString>;
|
|
190
|
+
address: z.ZodOptional<z.ZodObject<{
|
|
191
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
192
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
193
|
+
city: z.ZodOptional<z.ZodString>;
|
|
194
|
+
region: z.ZodOptional<z.ZodString>;
|
|
195
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
196
|
+
country: z.ZodOptional<z.ZodString>;
|
|
197
|
+
}, z.core.$strict>>;
|
|
198
|
+
}, z.core.$strict>;
|
|
199
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
200
|
+
ref: z.ZodString;
|
|
201
|
+
name: z.ZodString;
|
|
202
|
+
company: z.ZodOptional<z.ZodString>;
|
|
203
|
+
email: z.ZodOptional<z.ZodString>;
|
|
204
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
205
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
206
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
207
|
+
city: z.ZodOptional<z.ZodString>;
|
|
208
|
+
region: z.ZodOptional<z.ZodString>;
|
|
209
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
210
|
+
country: z.ZodOptional<z.ZodString>;
|
|
211
|
+
}, z.core.$strict>>;
|
|
212
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
213
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
214
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
215
|
+
city: z.ZodOptional<z.ZodString>;
|
|
216
|
+
region: z.ZodOptional<z.ZodString>;
|
|
217
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
218
|
+
country: z.ZodOptional<z.ZodString>;
|
|
219
|
+
}, z.core.$strict>>;
|
|
220
|
+
}, z.core.$strict>>;
|
|
221
|
+
order_ref: z.ZodOptional<z.ZodString>;
|
|
222
|
+
references: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
223
|
+
label: z.ZodString;
|
|
224
|
+
value: z.ZodString;
|
|
225
|
+
}, z.core.$strict>>>;
|
|
226
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
227
|
+
lines: z.ZodArray<z.ZodObject<{
|
|
228
|
+
description: z.ZodString;
|
|
229
|
+
amount_cents: z.ZodInt;
|
|
230
|
+
cost_code: z.ZodOptional<z.ZodString>;
|
|
231
|
+
item_code: z.ZodOptional<z.ZodString>;
|
|
232
|
+
quantity: z.ZodOptional<z.ZodNumber>;
|
|
233
|
+
unit_cost_cents: z.ZodOptional<z.ZodNumber>;
|
|
234
|
+
customer: z.ZodOptional<z.ZodObject<{
|
|
235
|
+
ref: z.ZodString;
|
|
236
|
+
name: z.ZodString;
|
|
237
|
+
company: z.ZodOptional<z.ZodString>;
|
|
238
|
+
email: z.ZodOptional<z.ZodString>;
|
|
239
|
+
bill_to: z.ZodOptional<z.ZodObject<{
|
|
240
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
241
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
242
|
+
city: z.ZodOptional<z.ZodString>;
|
|
243
|
+
region: z.ZodOptional<z.ZodString>;
|
|
244
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
245
|
+
country: z.ZodOptional<z.ZodString>;
|
|
246
|
+
}, z.core.$strict>>;
|
|
247
|
+
ship_to: z.ZodOptional<z.ZodObject<{
|
|
248
|
+
line1: z.ZodOptional<z.ZodString>;
|
|
249
|
+
line2: z.ZodOptional<z.ZodString>;
|
|
250
|
+
city: z.ZodOptional<z.ZodString>;
|
|
251
|
+
region: z.ZodOptional<z.ZodString>;
|
|
252
|
+
postal_code: z.ZodOptional<z.ZodString>;
|
|
253
|
+
country: z.ZodOptional<z.ZodString>;
|
|
254
|
+
}, z.core.$strict>>;
|
|
255
|
+
}, z.core.$strict>>;
|
|
256
|
+
class_key: z.ZodOptional<z.ZodString>;
|
|
257
|
+
}, z.core.$strict>>;
|
|
258
|
+
total_cents: z.ZodInt;
|
|
259
|
+
schema_version: z.ZodLiteral<"1">;
|
|
260
|
+
source_ref: z.ZodString;
|
|
261
|
+
company_key: z.ZodString;
|
|
262
|
+
version: z.ZodInt;
|
|
263
|
+
status: z.ZodEnum<{
|
|
264
|
+
active: "active";
|
|
265
|
+
voided: "voided";
|
|
266
|
+
}>;
|
|
267
|
+
}, z.core.$strict>;
|
|
268
|
+
export type BillLine = z.infer<typeof billLine>;
|
|
269
|
+
export type Vendor = z.infer<typeof vendor>;
|
|
270
|
+
export type BillDTO = z.infer<typeof billSchema>;
|
|
271
|
+
export type VendorCreditDTO = z.infer<typeof vendorCreditSchema>;
|