Java · Track 8 · Tutorial 1 of 4

Put the steps in order

Put everything together in one run: the chart, the month, the detail, and the consolidation request - in the order BrizoConsol needs them.

You will needThe earlier tracks of this series.
By the endA monthly script you can schedule, with the morning check that follows it.

1Put it together

Every track so far sent one thing. A monthly run sends them all, in the order BrizoConsol needs them.

The order a monthly run sends things in
The order matters: the chart before anything that names an account, and the consolidation request last.

2Write the run

Create Monthly.java. Its two methods, chartFromMySystem() and trialBalanceFromMySystem(), return the same data the earlier tutorials sent: replace them with reads from your own system. The rest is the run itself.

Monthly.java

// Monthly.java - the whole month in one run: chart, trial balance, documents, journal lines, consolidation.
//   gradle -q run -Pmain=Monthly --args="2026-09"
import com.fasterxml.jackson.databind.JsonNode;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.YearMonth;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class Monthly {
    // Replace these with reads from your own system. They return the same shapes the earlier tutorials sent.
    static List<Map<String, Object>> chartFromMySystem() {
        return List.of(
                Map.of("code", "1000", "name", "Operating bank", "type", "Bank"),
                Map.of("code", "1200", "name", "Trade receivables", "type", "Accounts Receivable"),
                Map.of("code", "2000", "name", "Trade payables", "type", "Accounts Payable"),
                Map.of("code", "4000", "name", "Sales revenue", "type", "Revenue"),
                Map.of("code", "5000", "name", "Cost of sales", "type", "Direct Costs"),
                Map.of("code", "6000", "name", "Rent", "type", "Expense"));
    }

    static List<Map<String, Object>> trialBalanceFromMySystem(String period) {
        return List.of(
                Map.of("account_code", "1000", "debit", 20000.00, "credit", 0),
                Map.of("account_code", "1200", "debit", 5000.00, "credit", 0),
                Map.of("account_code", "2000", "debit", 0, "credit", 5000.00),
                Map.of("account_code", "4000", "debit", 0, "credit", 30000.00),
                Map.of("account_code", "5000", "debit", 8000.00, "credit", 0),
                Map.of("account_code", "6000", "debit", 2000.00, "credit", 0));
    }

    static Map<String, Object> declarations(String source, String period, String currency, String webhook) {
        Map<String, Object> declarations = new LinkedHashMap<>();
        declarations.put("source_reference", source);
        declarations.put("period", period);
        declarations.put("value_basis", "company_base");
        declarations.put("rate_direction", "document_to_base");
        declarations.put("base_currency", currency);
        if (webhook != null) {
            declarations.put("webhook_url", webhook);
        }
        return declarations;
    }

    public static void main(String[] args) throws Exception {
        String period = args.length > 0 ? args[0] : YearMonth.now().minusMonths(1).toString();
        String currency = "SGD";
        String version = "v1"; // change it to send a month again after its figures change
        String webhook = System.getenv("BRIZO_WEBHOOK_URL"); // optional: a public URL told when each write finishes
        if (webhook != null && webhook.isEmpty()) {
            webhook = null;
        }

        System.out.println("Sending " + period);

        // 1. The chart first: a trial balance can only name accounts the chart already holds.
        Brizo.show("Chart", Brizo.written(Brizo.call("POST", "/organisations/" + Brizo.COMPANY_ID + "/accounts", Map.of(
                "declarations", Map.of("source_reference", "my-ledger", "mode", "merge"),
                "records", chartFromMySystem()))));

        // 2. The month, whole. The key makes a retry of this run harmless.
        JsonNode month = Brizo.written(Brizo.call("POST", "/organisations/" + Brizo.COMPANY_ID + "/trial-balances", Map.of(
                "declarations", declarations("my-ledger", period, currency, webhook),
                "records", trialBalanceFromMySystem(period)),
                Map.of("Idempotency-Key", Brizo.COMPANY_ID + "-" + period + "-" + version)));
        Brizo.show("Trial balance", month);

        // 3. Invoices, bills and journal lines go here, as in tracks 4 and 5.

        // 4. Ask for tonight's consolidation, once, after the last write.
        JsonNode run = Brizo.written(Brizo.call("POST", "/organisations/" + Brizo.COMPANY_ID + "/consolidation-requests")).path("data");
        System.out.println("Consolidation request " + run.path("id").asText() + ": " + run.path("status").asText());

        // Keep these two numbers: tomorrow, CheckRun reads what became of them.
        Files.writeString(Path.of("run-" + period + ".json"), Brizo.JSON.writeValueAsString(
                Map.of("month", month.path("id"), "consolidation", run.path("id"))));
        System.out.println("Tomorrow: gradle -q run -Pmain=CheckRun --args=\"" + month.path("id").asText() + " " + run.path("id").asText() + "\"");
    }
}

3Run it

gradle -q run -Pmain=Monthly --args="2026-09"

Check

Sending 2026-09
Chart: request 101 - 0 created, 1 updated, 5 unchanged, 0 refused
Trial balance: request 92 - 6 created, 0 updated, 0 unchanged, 0 refused
Consolidation request 12: pending
Tomorrow: gradle -q run -Pmain=CheckRun --args="92 12"

The trial balance answers the request from before, because the key is the same: nothing was written twice.

4Run it every month

Schedule it for after your books close each month - with cron, the Windows Task Scheduler, or your own scheduler - and schedule gradle -q run -Pmain=CheckRun for the next morning. Without a month on the command line, it sends last month.

Where your own system plugs in
Replace the two methods with reads from your system; the rest of the run stays the same.

Want more detail? See the documentation