Ar ap aging collections

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Ar ap aging collections is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Source: https://developer.xero.com/documentation/api/accounting/reports/#agedreceivablesbycontact

How to use this skill

Skill file

<!--

Source: https://developer.xero.com/documentation/api/accounting/reports/#agedreceivablesbycontact

Source: https://docs.stripe.com/billing/subscriptions/smart-retries

Source: https://docs.mercury.com/reference/payments

Reference role.md: "Dunning email templates"

-->

AR aging + AP aging + collections / dunning

Receivables collection (dunning cadence, days 0/7/14/30) and payables management (vendor pay runs, early-pay discount math). Standard cadence + templates that recover 80%+ of overdue AR without escalation.

When to use

NOT for: legal collections (defer to legal-counsel); cap-table receivables (use carta-pulley-cap-table).

Setup

# AR / AP data — already shipped via:
# - xero-mcp (catalog) + default xero skill
# - cli-anything + Intuit QBO MCP

# Dunning execution:
# - gmail-mcp (catalog) — primary
# - outlook-mcp (catalog) — alt
# - slack-mcp (catalog) — internal notify

# Card retry (for B2C SaaS):
# - stripe-mcp — Smart Retries configuration

AR aging buckets (standard)

| Bucket | Action | Owner |

|---|---|---|

| Current (0 days) | Day-0 reminder when invoice issued | Auto |

| 1-30 days | Day-7 first chase; Day-14 firm | Controller |

| 31-60 days | Day-30 service-hold notice; manager review | Controller + CSM |

| 61-90 days | Escalation; CSM + Founder | Cross-functional |

| 90+ days | Allowance booking; legal review | Founder + legal |

Common recipes

Recipe 1 — Pull AR aging (Xero)

xero.reports.aged_receivables_by_contact({
  date: "2026-06-30",
  fromDate: null,
  toDate: null
})
// Returns rows: contact + current + 1-30 + 31-60 + 61-90 + 90+ + total

Recipe 2 — Pull AR aging (QBO)

curl -H "Authorization: Bearer $QBO_TOKEN" \
  "https://quickbooks.api.intuit.com/v3/company/$QBO_REALM_ID/reports/AgedReceivables?\
report_date=2026-06-30&aging_period=30&num_periods=4"

Recipe 3 — Day 0 reminder (auto on invoice issuance)

# Via gmail-mcp
def send_day_0_reminder(invoice):
    body = f"""
Hi {invoice.contact_first_name},

A quick note that invoice #{invoice.number} for ${invoice.amount:,.2f} is due
{invoice.due_date}. You can pay via the link below:

{invoice.payment_link}

If there are any questions about the invoice, just reply here — happy
to walk through line items.

Thanks,
{sender_name}
"""
    gmail.send(
      to=invoice.contact_email,
      subject=f"Invoice {invoice.number} — ${invoice.amount:,.2f} due {invoice.due_date}",
      body=body
    )

Recipe 4 — Day 7 past due first chase

def send_day_7_chase(invoice):
    body = f"""
Hi {invoice.contact_first_name},

Quick check-in: invoice #{invoice.number} for ${invoice.amount:,.2f} was due
{invoice.due_date} and is now 7 days past due. Could you let me know the
expected payment date so we can update our records?

If you've already sent it, please ignore — bank-feed delay is real.

Thanks,
{sender_name}
"""
    gmail.send(to=invoice.contact_email,
               subject=f"Invoice {invoice.number} past due — ${invoice.amount:,.2f}",
               body=body)

Recipe 5 — Day 14 firm chase

def send_day_14_firm(invoice):
    body = f"""
Hi {invoice.contact_first_name},

Invoice #{invoice.number} for ${invoice.amount:,.2f} is now 14 days past due.
Per our terms, we need to receive payment by {invoice.due_date + timedelta(days=21)}.

If there's a payment issue or dispute, please reply here today and we'll
work through it. If it's been paid, please send us the confirmation.

Thanks,
{sender_name}
"""
    gmail.send(to=invoice.contact_email,
               subject=f"Invoice {invoice.number} — 14 days past due — please pay by {due_plus_21}",
               body=body)

Recipe 6 — Day 30 service hold notice

def send_day_30_service_hold(invoice):
    body = f"""
Hi {invoice.contact_first_name},

Invoice #{invoice.number} for ${invoice.amount:,.2f} is 30 days past due. Per
our terms, we'll pause service on {today + timedelta(days=3)} if payment is not received.

I want to avoid that — please reply today so we can find a resolution.

Thanks,
{sender_name}
"""
    gmail.send(to=invoice.contact_email,
               subject=f"Invoice {invoice.number} — service hold notice",
               body=body)
    # Also: notify CSM via Slack
    slack.send_message(channel="#cs-account-issues",
      text=f"⚠ Day-30 service-hold notice sent to {invoice.contact}. "
           f"Inv #{invoice.number} ${invoice.amount:,.0f}. CSM action: align on resolution.")

Recipe 7 — Dunning orchestrator (weekly loop)

import datetime
def dunning_cycle(today):
    ar = xero.reports.aged_receivables_by_contact(date=today)
    for inv in xero.invoices.list(where='Status=="AUTHORISED" AND AmountDue>0'):
        days_past_due = (today - inv.due_date).days
        if days_past_due < 0:
            continue  # not yet due
        elif days_past_due == 0:
            send_day_0_reminder(inv)
        elif days_past_due == 7:
            send_day_7_chase(inv)
        elif days_past_due == 14:
            send_day_14_firm(inv)
        elif days_past_due == 30:
            send_day_30_service_hold(inv)
        elif days_past_due >= 60:
            escalate_to_founder(inv)

Recipe 8 — Stripe Smart Retries for failed cards

# Configure retry schedule for failed subscription charges
curl -X POST https://api.stripe.com/v1/billing/billing_settings/retry_rules \
  -u $STRIPE_API_KEY: \
  -d "max_retry_attempts=4" \
  -d "retry_intervals=3,7,10,14"  # days between retries

Smart Retries recovers 14-38% of involuntary churn (Stripe benchmark).

Recipe 9 — Pull AP aging + schedule pay run

ap = xero.reports.aged_payables_by_contact(date=today)
# Sort vendors by criticality + due date
pay_run = []
for vendor in ap.contacts:
    for bill in vendor.bills:
        if bill.days_past_due > 0:
            priority = "URGENT"
        elif bill.discount_offered and bill.days_until_discount_window <= 5:
            priority = "EARLY_PAY_DISCOUNT"
        elif bill.days_until_due <= 7:
            priority = "DUE_WEEK"
        else:
            priority = "DEFER"

        pay_run.append({
          "vendor": vendor.name, "bill": bill.number,
          "amount": bill.amount, "priority": priority,
          "discount_available": bill.discount_offered
        })

# Output: pay run sorted by priority
sorted_pay_run = sorted(pay_run, key=lambda x: ["URGENT","EARLY_PAY_DISCOUNT","DUE_WEEK","DEFER"].index(x["priority"]))

Recipe 10 — Early-pay discount evaluator

def early_pay_decision(bill, treasury_apy=0.05):
    """2/10 net 30 = 2% off if paid by day 10; full due day 30"""
    if not bill.discount_offered:
        return ("PAY_ON_TERMS", 0)

    discount = bill.discount_pct       # e.g., 0.02
    discount_window_days = bill.discount_window  # e.g., 10
    full_terms_days = bill.net_terms   # e.g., 30
    days_paid_early = full_terms_days - discount_window_days

    # Annualized return on early payment
    annualized = (discount / days_paid_early) * 365

    if annualized > treasury_apy:
        savings = bill.amount * discount
        return ("PAY_EARLY", savings)
    return ("PAY_ON_TERMS", 0)

# Example: 2/10 net 30 → annualized 36.5% → far better than 5% APY → PAY EARLY

Recipe 11 — DSO calculation

# Days Sales Outstanding = AR balance / daily revenue
# = AR / (Revenue / Days in period)

def dso(ar_balance, revenue, period_days=30):
    return ar_balance / (revenue / period_days)

# Benchmark by industry:
# - SaaS (mostly card): DSO 10-20 days
# - SaaS B2B (invoiced): DSO 30-45 days
# - Enterprise: DSO 45-75 days
# - Anything > 60 days for B2B = collection issue

Recipe 12 — Bad debt allowance estimate

def estimate_allowance(ar_aging):
    """Standard allowance percentages per bucket"""
    return (
      ar_aging.bucket_current * 0.005 +    # 0.5% on current
      ar_aging.bucket_1_30   * 0.02  +    # 2% on 1-30
      ar_aging.bucket_31_60  * 0.10  +    # 10% on 31-60
      ar_aging.bucket_61_90  * 0.30  +    # 30% on 61-90
      ar_aging.bucket_90_plus* 0.75       # 75% on 90+
    )
# Book as journal: Dr Bad Debt Expense / Cr Allowance for Doubtful Accounts

Examples

Example 1: Weekly AR sweep

Goal: Every Tuesday morning, send all due dunning emails.

Steps:

  1. Pull AR aging (Recipe 1).
  2. Run dunning cycle (Recipe 7) for today.
  3. Log each email sent to internal CRM / spreadsheet.
  4. Flag any invoice >60d past due to founder + legal review (Recipe 7 escalate branch).
  5. Summarize to Slack #finance-ar:

```

AR Aging 2026-06-09:

Total AR: $205K | DSO: 31 days (target ≤ 35)

```

Result: Predictable cadence; DSO trends down; founder only involved on 60+.

Example 2: AP pay run with early-pay discounts

Goal: Weekly pay run optimizing cash + discounts.

Steps:

  1. Pull AP aging (Recipe 9).
  2. Evaluate each bill via Recipe 10.
  3. Build pay run priority list:
  1. Surface to founder: "DECISION REQUIRED — pay run $56K this week, saves $620 via early discounts. Approve?"
  2. On approval, batch payment via Mercury (Recipe 3 of mercury-modern-treasury-banking).
  3. Record payments in Xero against each bill.

Result: $56K AP cleared; $620 discount captured; 11 bills deferred.

Edge cases / gotchas

Sources

Related skills

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.