Credit Line Cron
Monitor and operate the automated credit-line cut process that periodically restores company balances, records outstanding debt, and closes a historical period even when the line was not used.
What You Can Do
- Trigger the credit-line cut manually for all active lines, or for one
company_id - Inspect per-step audit logs in the
logstable (model = 'companies',log_type = 'credit_line.cut') to verify or debug a cut - Identify which companies were restored, recorded as period-only, skipped, or failed on any given cut date
- Open the resulting statements on the company page — Credit Line Cuts
Getting There
Observe a cut in the logs table, filtered by model = 'companies', log_type = 'credit_line.cut', and model_id = <company_id>. The resulting statements are on the company page — Credit Line Cuts.
The cut process is triggered via POST /crons/credit-line/charges, scheduled to run daily at 00:00 America/Monterrey (UTC-6 / 06:00 UTC) via external scheduler (or invoked manually for testing).
Common Tasks
Triggering the cut manually
POST /crons/credit-line/charges
Authorization: Bearer <cron_token>
Content-Type: application/json
{ "company_id": 3360 }Omit company_id to enqueue every active line. A company whose balance is already at the limit still gets a job; it records a period-only statement instead of restoring.
The API responds immediately with { "success": true }. Work continues in the background. Check the logs table for that company and cut date.
Verifying a company was correctly processed
Query the logs table for the company and date:
SELECT id, model_id AS company_id, method, log_type, description, new_value, created_at
FROM logs
WHERE model = 'companies'
AND model_id = <company_id>
AND log_type = 'credit_line.cut'
AND JSON_UNQUOTE(JSON_EXTRACT(new_value, '$.cut_date')) = '<YYYY-MM-DD>'
ORDER BY id ASC;A complete, successful run produces rows in order: start → credit → debt → balance → invoice → notify → complete. The core steps (start, credit, debt, balance, notify, complete) will have status = 'success', while the non-blocking invoice step will show status = 'success' (when issued) or status = 'skipped' (when the company has no active billing profile or is outside the EU).
Checking why a cut stopped at a specific step
- Query the
logstable for the company andcutDate - Find the entry with
status: 'failed'innew_value(or in the description) - Read the
errorattribute for the full message - The last successful step in the sequence shows how far the cut got (for example, a
creditsuccess and adebtfailure means the credit was inserted but the debt was not)
Frequently Asked Questions
The cron ran twice today — will companies be charged twice?
No. Each company is processed once per cutDate. The guard query in createManualCredit prevents inserting a second credit for the same company on the same cut date. The invoice step writes a reclaimable in-progress claim (invoiced_at only) and sends Idempotency-Key: credit-line-invoice-{creditId}. The stamp UPDATE only matches unstamped rows. invoice_receipt is set only after the invoice id is stamped, so a crash mid-invoice does not mark the credit invoiced or skip the retry forever.
A company's balance was manually lowered after the cut ran — will it trigger again?
Not for the same cutDate. The createManualCredit guard detects the existing credit for that date and skips all remaining steps (including the TMS call). The cut period is sealed by the cutDate. A new cut will fire on the next scheduled day.
A job shows "completed" but the company's balance wasn't updated in TMS — what happened?
Check the logs table for the balance step:
- If
status = 'success'→ TMS did apply the balance. The display may be a cache issue. - If
status = 'failed'→ TMS call failed on all 3 retries. Thelogsrow holds the TMS error. - If there is no
balancerow → the job failed before reaching that step. Look for thecreditordebtstep withstatus = 'failed'.
The cut is scheduled for Mondays but today is Monday and no jobs appeared — why?
Check credit_line_type for the affected companies. Only companies with credit_line_type = 1 (or null) run on Mondays. Other types have different schedules (biweekly on 1st/15th, monthly on 1st, 6th, or last day). The schedule runs daily at 00:00 America/Monterrey (UTC-6 / 06:00 UTC) and evaluates day/date rules in UTC, matching the UTC cutDate. Also verify that NODE_ENV = production is set — in non-production environments all companies are eligible every day regardless of type.
Why does an EU invoice show a 1.9% late-payment penalty?
Credit invoices are only generated for companies with active billing information whose billing country (company_billing_information.country_code) is an EU member state. They include payment_penalty_rate: 1.9 so Verifacti can print the statutory late-payment interest on the PDF (Directive 2011/7/EU). Companies without active billing information or whose billing country is outside the EU skip invoice generation.
How do I check which companies are eligible for the next cut?
SELECT id, name, balance, credit_line_limit, credit_line_type,
(credit_line_limit - balance) AS amount
FROM companies
WHERE credit_line_limit > 0
ORDER BY id;Rows with balance >= credit_line_limit are period-only. Rows with balance < credit_line_limit restore. Production still applies credit_line_type to decide whether today is a cut day.
Related
- Technical Documentation: Credit Line Cron — Overview — Architecture, data flow, and key decisions
- API Reference: Credit Line Cron — API — Endpoint details
- Cut statements: Credit Line Cuts — How to read restoration and period-only statements
