Skip to content

Commit

Permalink
feat: Adds saveInvoice
Browse files Browse the repository at this point in the history
jondewoo committed Dec 11, 2024
1 parent 5a981d5 commit 7d9b8a9
Showing 3 changed files with 123 additions and 0 deletions.
103 changes: 103 additions & 0 deletions src/client.test.ts
Original file line number Diff line number Diff line change
@@ -47,6 +47,109 @@ test("Get next invoice number", async () => {
assert.type(nextInvoiceNumber, "string");
});

test("Create a new invoice", async () => {
const { objects: invoiceNumber } = await sevDeskClient.getNextInvoiceNumber({
invoiceType: "RE",
useNextNumber: true,
});
const { objects: contacts } = await sevDeskClient.getContacts();

const {
objects: { invoice },
} = await sevDeskClient.saveInvoice({
invoice: {
// id: null,
objectName: "Invoice",
invoiceNumber,
contact: {
id: contacts[0].id,
objectName: "Contact",
},
contactPerson: {
id: env.CONTACT_PERSON_ID,
objectName: "SevUser",
},
invoiceDate: "01.01.2022",
header: `Invoice ${invoiceNumber}`,
headText: "header information",
footText: "footer information",
timeToPay: 20,
discount: 0,
address: "name\nstreet\npostCode city",
addressCountry: {
id: 1,
objectName: "StaticCountry",
},
payDate: "2019-08-24T14:15:22Z",
deliveryDate: "01.01.2022",
deliveryDateUntil: null,
status: "100",
smallSettlement: 0,
taxRate: 0,
taxRule: {
id: "1",
objectName: "TaxRule",
},
taxText: "Umsatzsteuer 19%",
taxType: "default",
taxSet: null,
paymentMethod: {
id: 21919,
objectName: "PaymentMethod",
},
sendDate: "01.01.2020",
invoiceType: "RE",
currency: "EUR",
showNet: "1",
sendType: "VPR",
origin: null,
customerInternalNote: null,
propertyIsEInvoice: false,
mapAll: true,
},
invoicePosSave: [
{
id: null,
objectName: "InvoicePos",
mapAll: true,
// part: {
// id: 0,
// objectName: 'Part',
// },
quantity: 1,
price: 100,
name: "Dragonglass",
unity: {
id: 1,
objectName: "Unity",
},
positionNumber: 0,
text: "string",
discount: 0.1,
taxRate: 19,
priceGross: 100,
priceTax: 0.1,
},
],
invoicePosDelete: null,
filename: "string",
discountSave: [
{
discount: "true",
text: "string",
percentage: true,
value: 0,
objectName: "Discounts",
mapAll: "true",
},
],
discountDelete: null,
});

console.log(invoice);
assertIsInvoice(invoice);
});

test("Get document folders", async () => {
const { objects: documentFolders } = await sevDeskClient.getDocumentFolders();

15 changes: 15 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -113,6 +113,21 @@ export class SevDeskClient {
}>(url, { method: "GET" });
}

/**
* Create a new invoice
*/
async saveInvoice(body: unknown) {
const url = this.urls.apiSaveInvoiceUrl();

return this.request<{
objects: { invoice: Required<ModelInvoice> };
}>(url, {
method: "POST",
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" },
});
}

// -------------------------------------------------------
// DocumentFolder
// -------------------------------------------------------
5 changes: 5 additions & 0 deletions src/tests/env.ts
Original file line number Diff line number Diff line change
@@ -4,3 +4,8 @@ export const TEST_SEVDESK_API_TOKEN = env
.get("TEST_SEVDESK_API_TOKEN")
.required()
.asString();

export const CONTACT_PERSON_ID = env
.get("CONTACT_PERSON_ID")
.required()
.asString();

0 comments on commit 7d9b8a9

Please sign in to comment.