Skip to content

Reminder before the due date

The cost center’s responsible person first reviews an incoming invoice, then accounting approves the payment. Three days before the due date, the script reminds accounting of the payment approval still open and says whether the review objected to the invoice. An invoice objected to also gets the tag “Prüfen” and a hint on the payment approval.

The workflow starts for every document of the type incoming-invoice. Its file workflow.yaml:

$schema: 'https://docs.acriva.de/schemas/workflow.schema.json'
format: 1
schemaVersion: 4
sdk: '1.0.0'
key: due-date-reminder
name: Erinnerung vor Fälligkeit
template: custom
trigger:
documentType: incoming-invoice
fields: []
start: review
steps:
- kind: humanTask
name: review
label: Sachliche Prüfung
taskKind: review
assignees:
- when: null
assignee:
kind: costCenterResponsible
fallback:
kind: role
role: Buchhaltung
options:
excludeRequester: true
excludeActorsOfSteps: []
pickFile: false
next: beforeDue
onRejected: beforeDue
- kind: timer
name: beforeDue
label: Drei Tage vor Fälligkeit
dateField: dueDate
daysBefore: 3
next: remind
- kind: script
name: remind
label: An die Zahlungsfreigabe erinnern
script: remind.ts
hook: onTimer
inputs:
- kind: field
key: vendorName
type: text
- kind: field
key: invoiceNumber
type: text
- kind: field
key: dueDate
type: date
- kind: field
key: totalGross
type: money
returns: []
exits: []
next: approve
- kind: humanTask
name: approve
label: Zahlungsfreigabe
taskKind: approve
assignees:
- when: null
assignee:
kind: role
role: Buchhaltung
fallback:
kind: role
role: Buchhaltung
options:
excludeRequester: true
excludeActorsOfSteps:
- review
pickFile: false
next: approved
onRejected: rejected
- kind: end
name: approved
label: Freigegeben
outcome: approved
- kind: end
name: rejected
label: Zurückgewiesen
outcome: rejected

Hook: onTimer · Inputs: vendorName, invoiceNumber, dueDate, totalGross · Return values: none

import { date, defineScript, money } from '@acriva/workflow-sdk';
export default defineScript({
hook: 'onTimer',
run(ctx) {
const { vendorName, invoiceNumber, dueDate, totalGross } = ctx.document.fields;
if (dueDate == null) return;
// The timer fires 3 days before the due date, or at once when the review ended later than that.
const days = date.daysBetween(ctx.today(), dueDate);
const due =
days > 1
? `ist in ${days} Tagen fällig (am ${date.format(dueDate)})`
: days === 1
? `ist morgen fällig (am ${date.format(dueDate)})`
: days === 0
? 'ist heute fällig'
: `ist seit dem ${date.format(dueDate)} überfällig`;
const invoice = [
`Die Rechnung ${invoiceNumber ?? 'ohne Nummer'}`,
vendorName == null ? '' : ` von ${vendorName}`,
totalGross == null ? '' : ` über ${money.format(totalGross)}`,
].join('');
// The last task is the review: approved, the payment approval is all that is left; objected to, it needs a clarification.
const objected = ctx.instance.lastTaskOutcome === 'Rejected';
const next = objected
? 'Die sachliche Prüfung hat sie beanstandet: Bitte klären Sie sie vor der Zahlung mit dem Lieferanten.'
: 'Die sachliche Prüfung ist erledigt, die Zahlungsfreigabe fehlt noch.';
ctx.notify({ to: [{ role: 'Buchhaltung' }], text: `${invoice} ${due}. ${next}` });
if (objected) {
ctx.hint(
'Die sachliche Prüfung hat diese Rechnung beanstandet. Den Grund finden Sie im Verlauf.',
);
ctx.addTag('Prüfen');
}
},
});

A test runs each of these cases in the sandbox and compares the result.

  • Input: vendorName Deutsche Bahn AG, invoiceNumber DB-88213, dueDate 2026-10-25, totalGross 1287.4, last task outcome Rejected, today 2026-10-22
  • Exit: the default next step
  • Changes: notification to the role Buchhaltung: “Die Rechnung DB-88213 von Deutsche Bahn AG über 1.287,40 € ist in 3 Tagen fällig (am 25.10.2026). Die sachliche Prüfung hat sie beanstandet: Bitte klären Sie sie vor der Zahlung mit dem Lieferanten.”; hint on the next task: “Die sachliche Prüfung hat diese Rechnung beanstandet. Den Grund finden Sie im Verlauf.”; tag “Prüfen”
  • Input: vendorName null, invoiceNumber RE-55120, dueDate 2026-10-20, totalGross null, last task outcome Approved, today 2026-10-22
  • Exit: the default next step
  • Changes: notification to the role Buchhaltung: “Die Rechnung RE-55120 ist seit dem 20.10.2026 überfällig. Die sachliche Prüfung ist erledigt, die Zahlungsfreigabe fehlt noch.”

Reviewed, the payment approval is still open

Section titled “Reviewed, the payment approval is still open”
  • Input: vendorName Bürobedarf Schmidt GmbH, invoiceNumber 2026-4711, dueDate 2026-10-25, totalGross 342.72, last task outcome Approved, today 2026-10-22
  • Exit: the default next step
  • Changes: notification to the role Buchhaltung: “Die Rechnung 2026-4711 von Bürobedarf Schmidt GmbH über 342,72 € ist in 3 Tagen fällig (am 25.10.2026). Die sachliche Prüfung ist erledigt, die Zahlungsfreigabe fehlt noch.”