{"skills":[{"name":"Find duplicate supplier invoice records","description":"Group repeated invoice references and distinguish a duplicate candidate from conflicting versions or a genuine credit.","content":"# Find duplicate supplier invoice records\n\nGroup repeated invoice references and distinguish a duplicate candidate from conflicting versions or a genuine credit.\n\n## When to use this skill\n\n- Before a payment run, someone wants to check the payables list for invoices entered twice.\n- A supplier says it was paid twice, or an invoice number appears more than once in the ledger.\n- A group with several companies exports one payables list and needs repeats checked within each company.\n\n## When not to use it\n\n- Reconciling one supplier's statement with the ledger. Use the supplier statement reconciliation skill.\n- A request to change a supplier's bank details, or an invoice that looks fake. Follow the business's fraud checks and confirm with the supplier using contact details you already hold, not those on the invoice.\n- Deleting, reversing or cancelling records. The report flags candidates; a person with payables authority decides and corrects.\n\n## What you need\n\n- Accounts payable export with record ID, buying entity, supplier ID, document type, invoice reference, signed total and currency\n- Supplier-specific reference normalisation rules if available\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- Does the export cover more than one company, and is the buying company on each row? Duplicates only mean something within one buyer.\n- Which column holds the supplier's own invoice number, as opposed to your internal record ID?\n- Have any of these records been paid, cancelled or reversed? That decides whether to hold a payment or ask for a refund.\n- Does any supplier have an agreed reference format, such as prefixes or leading zeros, that you treat as the same number?\n\n## Method\n\n1. Keep distinct purchasing legal entities in separate scopes. A branch, delivery site or cost centre alone does not establish a different legal buyer. If a multi-entity export omits the buyer, flag the uncertain groups for review.\n2. Within each scope, group by supplier ID, document type, currency and the supplier's reference exactly as recorded. Trim outer whitespace only. Keep leading zeros, prefixes and letters unless the supplier has a documented rule, because the number identifies a document within that supplier's own series.\n3. Within each repeated key compare signed gross totals. If every amount agrees, flag the group as a duplicate candidate. If any amount differs, classify the whole group as conflicting versions.\n4. Flag records with no supplier reference separately, even when the amount and date match another invoice. Do not fill a missing reference from the amount or strip prefixes by guesswork.\n5. Note near-matches outside the groups for checking, not as candidates: the same supplier, amount and date with a reference that differs only in format, or two supplier IDs sharing a VAT number or bank account.\n6. For each candidate keep every internal record ID and check the originals, purchase order, goods receipt, posting, cancellation and payment history. Recommend holding the unpaid copy, or asking the supplier for a credit or refund if both were paid. Make no deletions or payment decisions.\n\n## Checks before you deliver\n\n- Two suppliers can issue the same invoice number.\n- A genuine credit or instalment might have the same absolute amount, so grouping on price is unreliable.\n- Stripping leading zeros or prefixes merges different documents: 0012 and 12 are not the same reference without the supplier's confirmation.\n- Treating two amounts under one reference as two valid invoices. A reissued invoice with a corrected price is a conflict, and the supplier must confirm which version stands.\n- Grouping across companies in a group export makes separate obligations of different legal buyers look like duplicates.\n\n## How to present the result\n\nLead with the number of candidate groups and the amount at risk of double payment. List each group with record IDs, supplier, reference, amount and payment status, and the check needed against the original. Then show conflicting versions with the amounts that differ, records missing a reference, and which items to hold from the next payment run.\n\n## Worked example\n\n**Request:** Check these records for possible duplicate bills.\n\n**Supplied material:**\n\n```text\nAll GBP. id | supplier | type | ref | total\nA1 Vale invoice 0012 80\nA2 Vale invoice 0012 80\nB1 Moss invoice 0012 80\nC1 Vale credit 0012 -80\nA3 Vale invoice 12 80\n```\n\n**Answer:** Check A1 and A2 against Vale\u2019s original invoice 0012 and the posting\/payment history before correcting either entry. Both are \u00a380. B1 is from Moss, C1 is a credit, and A3 has reference 12 rather than 0012.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn candidates and conflicts as arrays of groups of record IDs. Sort IDs within groups and groups by their first ID. Return missing_reference as a sorted ID array. Preserve leading zeroes.\n\n## Sources\n\n- [GOV.UK \u00b7 What an invoice must include](https:\/\/www.gov.uk\/invoicing-and-taking-payment-from-customers\/invoices-what-they-must-include): UK guidance says every invoice must carry a unique identification number together with the supplier's and the customer's names and addresses. The skill therefore groups on the supplier and the buyer as well as the reference.\n- [HMRC \u00b7 VAT invoice details (VATREC5010)](https:\/\/www.gov.uk\/hmrc-internal-manuals\/vat-trader-records\/vatrec5010): HMRC's manual says a full VAT invoice must have a sequential number based on one or more series which uniquely identifies the document, and that the number may include letters. This is why the skill keeps each reference exactly as recorded, within each supplier.\n- [Microsoft \u00b7 External document numbers on purchase documents](https:\/\/learn.microsoft.com\/en-us\/dynamics365\/business-central\/purchasing-ext-doc-no): Business Central can make the vendor's own invoice number mandatory before a purchase invoice is posted and lets you search posted entries by it. A record with no supplier reference cannot be checked this way, so the skill reports it separately.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/find-duplicate-invoice-records\n","scope":"contextual","trigger_keywords":["Find duplicate supplier invoice records","find-duplicate-invoice-records","find duplicate invoice records","Have any of these supplier invoices been entered twice before we pay them?","Have any of these supplier invoices been entered twice before we pay them","duplicate invoices","possible duplicate invoice","invoices entered twice"],"is_private":true,"is_active":true,"scripts":[{"name":"find-duplicate-invoice-records-check","description":"Compare a saved JSON answer with a published test. Pass tests\/case-1\/expected.json (or another case) and the path to your answer.","language":"python","filename":"find-duplicate-invoice-records-check.py","content":"from pathlib import Path\nimport runpy\n\nrunpy.run_path(str(Path(__file__).parent \/ 'tests' \/ 'check.py'), run_name='__main__')\n","supporting_files":[{"path":"SKILL.md","content":"---\nname: find-duplicate-invoice-records\ndescription: \"Find supplier invoices entered twice by grouping on buyer, supplier, document type, currency and exact reference, and separate duplicate candidates from conflicting versions and missing references. Use when checking accounts payable for duplicate bills before a payment run.\"\nlicense: CC-BY-4.0\nmetadata:\n  author: Raq.com\n  version: \"2026-11-22\"\n  homepage: https:\/\/skills.raq.com\/skills\/find-duplicate-invoice-records\n---\n\n# Find duplicate supplier invoice records\n\nGroup repeated invoice references and distinguish a duplicate candidate from conflicting versions or a genuine credit.\n\n## When to use this skill\n\n- Before a payment run, someone wants to check the payables list for invoices entered twice.\n- A supplier says it was paid twice, or an invoice number appears more than once in the ledger.\n- A group with several companies exports one payables list and needs repeats checked within each company.\n\n## When not to use it\n\n- Reconciling one supplier's statement with the ledger. Use the supplier statement reconciliation skill.\n- A request to change a supplier's bank details, or an invoice that looks fake. Follow the business's fraud checks and confirm with the supplier using contact details you already hold, not those on the invoice.\n- Deleting, reversing or cancelling records. The report flags candidates; a person with payables authority decides and corrects.\n\n## What you need\n\n- Accounts payable export with record ID, buying entity, supplier ID, document type, invoice reference, signed total and currency\n- Supplier-specific reference normalisation rules if available\n\n## Ask before you start\n\nIf any of these are missing or unclear, ask before doing the work.\n\n- Does the export cover more than one company, and is the buying company on each row? Duplicates only mean something within one buyer.\n- Which column holds the supplier's own invoice number, as opposed to your internal record ID?\n- Have any of these records been paid, cancelled or reversed? That decides whether to hold a payment or ask for a refund.\n- Does any supplier have an agreed reference format, such as prefixes or leading zeros, that you treat as the same number?\n\n## Method\n\n1. Keep distinct purchasing legal entities in separate scopes. A branch, delivery site or cost centre alone does not establish a different legal buyer. If a multi-entity export omits the buyer, flag the uncertain groups for review.\n2. Within each scope, group by supplier ID, document type, currency and the supplier's reference exactly as recorded. Trim outer whitespace only. Keep leading zeros, prefixes and letters unless the supplier has a documented rule, because the number identifies a document within that supplier's own series.\n3. Within each repeated key compare signed gross totals. If every amount agrees, flag the group as a duplicate candidate. If any amount differs, classify the whole group as conflicting versions.\n4. Flag records with no supplier reference separately, even when the amount and date match another invoice. Do not fill a missing reference from the amount or strip prefixes by guesswork.\n5. Note near-matches outside the groups for checking, not as candidates: the same supplier, amount and date with a reference that differs only in format, or two supplier IDs sharing a VAT number or bank account.\n6. For each candidate keep every internal record ID and check the originals, purchase order, goods receipt, posting, cancellation and payment history. Recommend holding the unpaid copy, or asking the supplier for a credit or refund if both were paid. Make no deletions or payment decisions.\n\n## Checks before you deliver\n\n- Two suppliers can issue the same invoice number.\n- A genuine credit or instalment might have the same absolute amount, so grouping on price is unreliable.\n- Stripping leading zeros or prefixes merges different documents: 0012 and 12 are not the same reference without the supplier's confirmation.\n- Treating two amounts under one reference as two valid invoices. A reissued invoice with a corrected price is a conflict, and the supplier must confirm which version stands.\n- Grouping across companies in a group export makes separate obligations of different legal buyers look like duplicates.\n\n## How to present the result\n\nLead with the number of candidate groups and the amount at risk of double payment. List each group with record IDs, supplier, reference, amount and payment status, and the check needed against the original. Then show conflicting versions with the amounts that differ, records missing a reference, and which items to hold from the next payment run.\n\n## Worked example\n\n**Request:** Check these records for possible duplicate bills.\n\n**Supplied material:**\n\n```text\nAll GBP. id | supplier | type | ref | total\nA1 Vale invoice 0012 80\nA2 Vale invoice 0012 80\nB1 Moss invoice 0012 80\nC1 Vale credit 0012 -80\nA3 Vale invoice 12 80\n```\n\n**Answer:** Check A1 and A2 against Vale\u2019s original invoice 0012 and the posting\/payment history before correcting either entry. Both are \u00a380. B1 is from Moss, C1 is a credit, and A3 has reference 12 rather than 0012.\n\n## Structured output for tests\n\nFor an ordinary job, answer in the format above and point back to the supplied evidence. Use this structure only for the test cases published with this skill, or when someone asks for structured JSON.\n\nReturn candidates and conflicts as arrays of groups of record IDs. Sort IDs within groups and groups by their first ID. Return missing_reference as a sorted ID array. Preserve leading zeroes.\n\n## Sources\n\n- [GOV.UK \u00b7 What an invoice must include](https:\/\/www.gov.uk\/invoicing-and-taking-payment-from-customers\/invoices-what-they-must-include): UK guidance says every invoice must carry a unique identification number together with the supplier's and the customer's names and addresses. The skill therefore groups on the supplier and the buyer as well as the reference.\n- [HMRC \u00b7 VAT invoice details (VATREC5010)](https:\/\/www.gov.uk\/hmrc-internal-manuals\/vat-trader-records\/vatrec5010): HMRC's manual says a full VAT invoice must have a sequential number based on one or more series which uniquely identifies the document, and that the number may include letters. This is why the skill keeps each reference exactly as recorded, within each supplier.\n- [Microsoft \u00b7 External document numbers on purchase documents](https:\/\/learn.microsoft.com\/en-us\/dynamics365\/business-central\/purchasing-ext-doc-no): Business Central can make the vendor's own invoice number mandatory before a purchase invoice is posted and lets you search posted entries by it. A record with no supplier reference cannot be checked this way, so the skill reports it separately.\n\nTest cases and an answer checker for this skill: https:\/\/skills.raq.com\/skills\/find-duplicate-invoice-records\n"},{"path":"LICENSE.txt","content":"Original Raq.com instructions and synthetic examples: CC BY 4.0.\nhttps:\/\/creativecommons.org\/licenses\/by\/4.0\/\nAttribution: Raq.com, https:\/\/skills.raq.com\/skills\/find-duplicate-invoice-records\nReferenced third-party materials retain their own terms.\n"},{"path":"examples\/worked-example.md","content":"# Shared numbers across vendors\n\nCheck these records for possible duplicate bills.\n\n## Supplied material\n\nAll GBP. id | supplier | type | ref | total\nA1 Vale invoice 0012 80\nA2 Vale invoice 0012 80\nB1 Moss invoice 0012 80\nC1 Vale credit 0012 -80\nA3 Vale invoice 12 80\n\n## Worked answer\n\nCheck A1 and A2 against Vale\u2019s original invoice 0012 and the posting\/payment history before correcting either entry. Both are \u00a380. B1 is from Moss, C1 is a credit, and A3 has reference 12 rather than 0012.\n\n## Reasoning\n\nThe supplier, document type and exact reference protect three unrelated records.\n"},{"path":"tests\/check.py","content":"\"\"\"Check a saved agent answer locally with Python 3 (standard library only).\"\"\"\nimport json\nimport math\nimport sys\nfrom pathlib import Path\n\n\ndef compare(expected, actual, path=\"$\", accepted=None):\n    if isinstance(expected, bool) or isinstance(actual, bool):\n        if expected is not actual:\n            yield path\n    elif isinstance(expected, (int, float)) and isinstance(actual, (int, float)):\n        if not math.isclose(expected, actual, rel_tol=0, abs_tol=1e-8):\n            yield path\n    elif isinstance(expected, dict) and isinstance(actual, dict):\n        for key in sorted(set(expected) | set(actual)):\n            if key not in expected or key not in actual:\n                yield f\"{path}.{key}\"\n            elif not any(\n                not list(compare(option, actual[key]))\n                for option in (accepted or {}).get(key, [])\n            ):\n                yield from compare(expected[key], actual[key], f\"{path}.{key}\")\n    elif isinstance(expected, list) and isinstance(actual, list):\n        if len(expected) != len(actual):\n            yield f\"{path} (length)\"\n        for i, (left, right) in enumerate(zip(expected, actual)):\n            yield from compare(left, right, f\"{path}[{i}]\")\n    elif type(expected) != type(actual) or expected != actual:\n        yield path\n\n\ndef main():\n    if len(sys.argv) != 3:\n        raise SystemExit(\"Usage: python3 check.py expected.json answer.json\")\n    try:\n        expected, actual = [json.loads(Path(p).read_text(encoding=\"utf-8\")) for p in sys.argv[1:]]\n        alternatives = Path(sys.argv[1]).with_name(\"accepted.json\")\n        accepted = json.loads(alternatives.read_text(encoding=\"utf-8\")) if alternatives.is_file() else {}\n    except (ValueError, OSError) as error:\n        raise SystemExit(str(error))\n    differences = list(compare(expected, actual, accepted=accepted))\n    if differences:\n        raise SystemExit(\"Different fields: \" + \", \".join(differences))\n    print(\"Pass\")\n\n\nif __name__ == \"__main__\":\n    main()\n"},{"path":"tests\/README.md","content":"Give your agent SKILL.md and one request.txt in a fresh session. Keep the expected answer aside. Save the reply as answer.json, then run this from the tests folder:\n\n    python3 check.py case-1\/expected.json answer.json\n\nEach case also has an explanation. Where accepted.json exists, the checker accepts the alternatives listed there.\n"},{"path":"tests\/case-1\/request.txt","content":"Check these records for possible duplicate bills.\nReturn only the JSON specified in SKILL.md for this test.\n\nAll GBP. id | supplier | type | ref | total\nA1 Vale invoice 0012 80\nA2 Vale invoice 0012 80\nB1 Moss invoice 0012 80\nC1 Vale credit 0012 -80\nA3 Vale invoice 12 80\n"},{"path":"tests\/case-1\/expected.json","content":"{\n    \"candidates\": [\n        [\n            \"A1\",\n            \"A2\"\n        ]\n    ],\n    \"conflicts\": [],\n    \"missing_reference\": []\n}\n"},{"path":"tests\/case-1\/explanation.txt","content":"The supplier, document type and exact reference protect three unrelated records.\n"},{"path":"tests\/case-2\/request.txt","content":"What needs manual review before we pay?\nReturn only the JSON specified in SKILL.md for this test.\n\nEUR. M3 Kern invoice X9 92; M2 Kern invoice X9 90; M8 Kern invoice [blank] 90; M9 Kern invoice X8 90.\n"},{"path":"tests\/case-2\/expected.json","content":"{\n    \"candidates\": [],\n    \"conflicts\": [\n        [\n            \"M2\",\n            \"M3\"\n        ]\n    ],\n    \"missing_reference\": [\n        \"M8\"\n    ]\n}\n"},{"path":"tests\/case-2\/explanation.txt","content":"Different totals sharing one key suggest a disputed version. The blank reference remains its own exception.\n"},{"path":"tests\/case-3\/request.txt","content":"Find the repeat payable in this group export.\nReturn only the JSON specified in SKILL.md for this test.\n\nAll supplier Alpine, GBP 80 invoices, reference 112, same date. A1 and A2 buyer East Ltd, same original supplier PDF and receipt. B1 buyer West Ltd, invoice addressed to West Ltd, separate original and separate goods receipt.\n"},{"path":"tests\/case-3\/expected.json","content":"{\n    \"candidates\": [\n        [\n            \"A1\",\n            \"A2\"\n        ]\n    ],\n    \"conflicts\": [],\n    \"missing_reference\": []\n}\n"},{"path":"tests\/case-3\/explanation.txt","content":"The buyer is part of the scope. B1 documents a distinct obligation of another legal entity.\n"}],"is_active":true,"is_approved":false}]}]}