Java · Track 5 · Tutorial 1 of 4
Send journal lines
Send the postings behind the month's figures - every journal, line by line - so any figure can be traced to the entries that made it.
1What journal lines add
The trial balance gives each account's total for the month. Journal lines are the postings behind those totals - every debit and credit, with its date and description - so any figure can be traced to the entries that made it. Like invoices, they never change a figure.
2Write September's journals
Create Journals.java. It describes six journals compactly and turns each posting into a line:
Journals.java
// Journals.java - sends September's journal lines.
import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class Journals {
record Posting(String account, String side, double amount, String document) {}
record Journal(String id, String date, String description, List<Posting> postings) {}
public static void main(String[] args) throws Exception {
List<Journal> journals = List.of(
new Journal("J-0901", "2026-09-05", "Cash sales", List.of(
new Posting("1000", "debit", 20000.00, null), new Posting("4000", "credit", 20000.00, null))),
new Journal("J-0902", "2026-09-08", "Invoice INV-1001", List.of(
new Posting("1200", "debit", 10000.00, "INV-1001"), new Posting("4000", "credit", 10000.00, "INV-1001"))),
new Journal("J-0903", "2026-09-20", "Payment from Harbour Trading", List.of(
new Posting("1000", "debit", 5000.00, null), new Posting("1200", "credit", 5000.00, null))),
new Journal("J-0904", "2026-09-03", "Bill BILL-501", List.of(
new Posting("5000", "debit", 8000.00, "BILL-501"), new Posting("2000", "credit", 8000.00, "BILL-501"))),
new Journal("J-0905", "2026-09-01", "September rent", List.of(
new Posting("6000", "debit", 2000.00, null), new Posting("1000", "credit", 2000.00, null))),
new Journal("J-0906", "2026-09-25", "Payment to Northwind", List.of(
new Posting("2000", "debit", 3000.00, null), new Posting("1000", "credit", 3000.00, null))));
List<Map<String, Object>> lines = new ArrayList<>();
for (Journal journal : journals) {
for (int n = 0; n < journal.postings().size(); n++) {
Posting posting = journal.postings().get(n);
Map<String, Object> line = new LinkedHashMap<>();
line.put("journal_external_id", journal.id());
line.put("line_external_id", String.valueOf(n + 1));
line.put("date", journal.date());
line.put("account_code", posting.account());
line.put("side", posting.side());
line.put("amount_base", posting.amount());
line.put("description", journal.description());
if (posting.document() != null) {
line.put("document_external_id", posting.document());
}
lines.add(line);
}
}
var request = Brizo.written(Brizo.call("POST", "/organisations/" + Brizo.COMPANY_ID + "/transactions", Map.of(
"declarations", Map.of(
"source_reference", "my-ledger",
"period", "2026-09",
"value_basis", "company_base",
"rate_direction", "document_to_base",
"base_currency", "SGD"),
"records", lines)));
Brizo.show("Journal lines", request);
System.out.println("Lines an invoice or bill explains: " + request.path("suppressed").asText());
JsonNode control = request.path("result").path("control_total");
if (!control.path("compared").asBoolean()) {
System.out.println("No trial balance from the API for this month to compare with.");
} else if (control.path("accounts").isEmpty()) {
System.out.println("The lines add up to the trial balance, account by account.");
} else {
for (JsonNode account : control.path("accounts")) {
System.out.println(" " + account.path("account_code").asText() + ": lines " + account.path("ledger").asText()
+ ", trial balance " + account.path("trial_balance").asText());
}
}
}
}Each line has the journal's ID, its own ID within the journal, a date, an account, a side - debit or credit - and amount_base, a positive amount in the company's currency.
3Send them
gradle -q run -Pmain=JournalsCheck
Journal lines: request 99 - 12 created, 0 updated, 0 unchanged, 0 refused
Lines an invoice or bill explains: 4
The lines add up to the trial balance, account by account.The last two lines are explained in the next two tutorials.
4Every journal must balance
BrizoConsol adds up each journal's debits and credits. If they differ, every line of that journal is refused with journal_does_not_balance, and the other journals are still stored. Send all of a journal's lines in the same request.
5One source per month
A company's ledger for a month comes from one source. If another source_reference already sent journal lines for September, your request is refused whole with month_held_by_another_source. Use one source name for one company's ledger.
6Sending more, or again
- Lines can be sent in parts - a journal at a time, or a few days at a time. With the default mode, lines are added and updated, never removed.
"mode": "replace_all"removes every line this source holds from journals not in the request - in every month. Use it only to send the whole ledger in one go.- A company holds up to 1,000 journal lines a month.
Want more detail? See the documentation