Hjelp og kundeservice
Integrasjoner

API: Closing invoices


If you want to close a sales invoice, either against a credit note, or a payment you can use the EntryMatch endpoint to do that.

The EntryMatch endpoint accepts posting line ids, so to use it you will have to do the following

  1. Fetch the journal id from the sales invoice(s)
  2. Use the journal id to fetch the relevant posting lines and their ids. You use the customers account for closing, so make sure you select those posting lines.
  3. Provide the posting line ids and the customers account id to the EntryMatch

In the example where you want to match an invoice to a credit note, you will have to find journal and posting line ids for both the invoice and the credit note.

1. Fetch journal id

Query:

query($id: ID!) {
    saleInvoice(id: $id) {
        id
        bookkeepingJournal { id }
    }
}

Example response:

{
    "data": {
        "saleInvoice": {
            "id": "9DhWnW",
            "bookkeepingJournal": { "id": "4LCGvv" }
        }
    }
}

(you will have to do this twice for invoice/credit note matching)

2. Fetch posting line ids

Fetching journal: Query:

query($id: ID!){
    bookkeepingJournal(id: 4LCGvv) {
        id
        postings {
            postingLines {
                id
                amountCents
                debitAccount {
                    id
                    code
                    subCode
                }
                creditAccount {
                    id
                    code
                    subCode
                }
            }
        }
    }
}

(you will have to do this twice for invoice/credit note matching)

Example response:

{
    "data": {
        "bookkeepingJournal": {
            "id": "4LCGvv",
            "postings": [ {
                "postingLines": [ {
                    "id": "JeCRVx",
                    "amountCents": 15000,
                    "debitAccount": {
                        "id": "24HJA4y",
                        "code": "1500",
                        "subCode": "10005"
                    },
                    "creditAccount": {
                        "id": "ggHNwdQ",
                        "code": "3100",
                        "subCode": null
                    }
                } ]
            } ]
        }
    }
}

3. Create an entry match

Mutation:

mutation ($postingLineId1: ID!, $postingLineId2: ID!, $accountId: ID!) {
    bookkeepingEntryMatchCreate(entryMatch: {postingLines: [{id: JeCRVx}, {id: gYCr2n}], accountId: 24HJA4y}) {
        id
        postingEntriesDebit {
            id
        }
        postingEntriesCredit {
            id
        }
    }
}

Example response:

{
    "data": {
        "bookkeepingEntryMatchCreate": {
            "id": "kQBSpD",
            "postingEntriesDebit": [ {
                "id": "JeCRVx"
            }],
            "postingEntriesCredit": [ {
                "id": "JeCRVx"
            }]
        }
    }
}

Optional, to reopen an invoice, you just delete the entry match

Mutation:

mutation ($id: ID!) {
    bookkeepingEntryMatchDestroy(id: kQBSpD) {
        id
    }
}

Response:

{
    "data": {
        "bookkeepingEntryMatchDestroy": {
            "id": "zdKSq6"
        }
    }
}

Luca Regnskap

Enkelt, rimelig og bekymringsfritt regnskap for små bedrifter.

For kun 99,-/måned kan du fakturere dine kunder, holde regnskapet under kontroll, og rapportere det staten skal ha.

Prøv gratis i 30 dager

Relaterte artikler

Vi bruker informasjonskapsler (cookies) for å forbedre brukeropplevelsen. Les mer