Wiki/GL coding/
GL coding for invoices: where agents find each line's code

GL coding for invoices: where agents find each line's code

GL coding
·
6 min read
·
Updated July 2026
Joshua Kurian
Joshua Kurian
On this page

GL coding for invoices is the assignment of a general ledger account, a cost center or other cost object, and any further accounting dimensions to each line of a supplier invoice before it posts. Every line gets its codes through one of two doors: a PO-backed invoice inherits them from the purchase order it references, while a non-PO invoice arrives with no coding at all and someone supplies it at posting time. Which door the invoice came through determines who codes it, when the decision was really made, and how much can go wrong.

The wiki you are reading covers source-to-pay for companies where AI agents carry the operational load – extracting lines, applying policy, proposing codes – and people keep the decisions that need judgment. The concept itself lives at GL coding; this page follows the document, tracing where each line's code comes from between arrival and posting.

Most GL coding for invoices is decided at order time

A PO-backed invoice rarely gets coded by anyone in accounts payable. When the purchase order was created, either the buyer chose an account assignment on the requisition or the material master supplied one – the master record that describes a purchased item, including the valuation class that maps it to a GL account automatically in systems like SAP. When the invoice arrives and passes matching, it inherits that coding line for line and posts without a coding decision being made at all.

The practical consequence is that invoice-time coding work on PO-backed spend is order-time coding surfacing later. If a buyer coded a requisition to a general "outside services" account to get it through approval quickly, every invoice against that order books to the dumping ground, and AP can do nothing about it without amending the order. The invoice is the last place the error becomes visible and the worst place to fix it.

A non-PO invoice is coded by whoever posts it

The second door is emptier. Non-PO invoices – utilities, legal fees, subscriptions, facilities work that never had an order – arrive carrying a supplier, an amount, and a description, with no accounting attached. Someone has to answer whose budget, which account, and which project before the invoice can post: an AP coder working from memory of similar bills, or the requester, reached by email and answering on their own schedule. This is the population where the mechanics below do most of their damage.

One line on the paper can be three lines in the ledger

In practice, take a $42,000 invoice from a facilities contractor covering a quarter's work on one building. Read against the statements of work, it contains three purchases: $9,500 to repair a failed rooftop HVAC compressor, $26,000 to install a second unit where none existed, and $6,500 for the quarterly preventive-maintenance contract. Those are three lines with three treatments. The repair is a period expense to repairs and maintenance under the building's cost center. The new unit sits above the capitalization threshold – the dollar floor, commonly $5,000, above which a purchase with a multi-year useful life must be recorded as a fixed asset and depreciated rather than expensed – so it books to a fixed-asset account and hits the income statement over years instead of at once. The contract portion is a contracted-service expense tied to the service period.

Code the whole $42,000 to repairs and maintenance and the quarter's expense is overstated by $26,000 while the asset register is understated by the same amount. The split is the coding decision, and nothing on the invoice header hints that one is required.

Freight and tax lines have their own destinations

A supplier can bundle freight into the unit price or bill it as a separate line, and the two choices book differently. Bundled freight follows the material – on inventory purchases it becomes part of landed cost, the item's value including delivery. A separate $1,200 freight line needs its own decision: into inventory value, or to a freight expense account under whichever cost object bears it. Tax behaves the same way. A correctly applied tax code posts the tax to dedicated accounts, where recoverable amounts can be reclaimed; tax bundled into a line price gets expensed with the goods, and the recoverable portion is quietly lost. Neither charge is large on any single invoice, which is exactly why their coding drifts unnoticed.

A credit memo must mirror the invoice it reverses

Credits and rebills multiply the original decision. Suppose the contractor later credits $8,000 of repair work that was originally split 70/30 across two buildings' cost centers. The credit memo has to carry the same 70/30 distribution – $5,600 and $2,400 – or the net spend of both cost centers is distorted while the company-level total stays correct, which means nobody notices until a budget owner disputes a variance. A rebill coded fresh, to a different account than the credit it follows, shifts category totals with no change in what was actually bought.

GL coding for invoices has a deadline

The coding decision is also a period decision. An invoice for December service that gets coded in the second week of January posts to January, and December's expense is understated until someone catches it. When AP knows the invoice exists but cannot code it yet, the close does not wait: an accountant books an accrual – a journal entry recognizing the expense in the period it was incurred, ahead of the invoice posting – using an estimate, reverses it next period, and lets the actual land. Every held, uncoded invoice at month-end becomes one of those estimates, and every gap between estimate and actual becomes noise in two periods' numbers.

An agent codes the mixed invoice from the records

Take the $42,000 facilities invoice again, this time with an AI agent working it. The agent reads the lines and the attached statements of work and separates the three components. The $6,500 maintenance charge matches the signed preventive-maintenance contract in the repository, and nine prior invoices under that contract booked to the same service account and cost center, so the agent codes it with confidence. The $9,500 compressor repair matches a dozen precedents from the same supplier with near-identical descriptions, all expensed to repairs and maintenance. The $26,000 unit is genuinely ambiguous: policy capitalizes added capacity but expenses replacement in kind, and the documents support either reading. So the agent proposes the three-line split, attaches the evidence, and asks the facilities budget owner one question: does the second unit add capacity or replace the failed one? The answer capitalizes or expenses the line, and the invoice posts. How coding systems reached this point is the subject of automated GL coding; when a proposed code is disputed rather than confirmed, the case becomes a coding and approval exception.

The contrast with the manual path is the size of the question. Emailed a whole invoice, a budget owner answers in days; asked one precise question with evidence attached, they answer from their phone.

Line-level codes are the raw material of every report above them

Category spend reports, budget variance, cost-center P&Ls, and the spend cube procurement negotiates from are all aggregations of invoice line codes. There is no later step where the data gets cleaned; a quarter of miscoded splits and mismatched credits becomes a quarter of reclass journals at close and a spend analysis nobody fully trusts. Coding quality is set at posting time, one line at a time.

Fragment builds AI agents that do this coding on the live invoice queue – reading each line against the PO, the contract, and years of coding precedent, proposing splits and period treatment with the evidence attached, and asking a budget owner only the question the records cannot answer. See how the workflows run or request a demo.

From Fragment
See exception resolution on your own data
Fragment resolves invoice exceptions autonomously across your existing ERP and documents.
Request demo