Documents Library report
Report code: documents. Opens the documents module with cmd=print_costume, the customise form, whose Preview submits print=print_all to the same module. There is no separate handler: the report is the library grid query printed as a table, rendered by documents_print_all.htm, with one grouping header per root folder. The grid and the report always agree, because they run the same SQL.
How this page was verified
Traced in master on 2026-09-06; the print path is the same in the big five and KTP apart from the columns each fork adds to the grid. Screenshots from inact-ktp.eris.place, project SNS.
The customise form

| Control | Field | Effect |
|---|---|---|
| Project | project | |
| Filter By | field[], operator[], what[] | grid columns by their SQL alias (d.doc_number, d.issued_code, d.doc_res_id, d.library_code2, ...); operators contains, start with, not contain, equals, not equal, greater than, less than |
| All / By Date | print_type | all prints "As Of today"; perday prints "As of <from> to <to>" and takes the range from the date filter |
| Show All Revisions | print_all_revision | one row per library row instead of one per document |
| Without comment sheet | print_without_commentsheet | adds doc_rev NOT LIKE '%_C' |
| Only vendor / subcontractor | print_only_vendor_subcontractor, print_vendor_subc_opt | restricts to folders whose library_code starts with 13 (vendor), 14 (subcontractor) or either |
| Sort | sortby[], sorttype[] | the Preview sends doc_send_received desc by default |
The note under the form is the rule that matters: by default the report shows the latest revision and the latest commented revision of each document.
The query
The grid query in documents.php: ts_map_documents_library map joined to ts_doc_library and ts_documents, for the project, with map.stat_id = 0 (not removed from the folder), the folder access list of the user's group (admins skip it), the filter rows, and:
- default: one row per
doc_number, the first indoc_send_received DESC, doc_rev DESCorder. MySQL does that withGROUP BY d.doc_no, doc_numberover an ordered subquery; SQL Server and PostgreSQL withROW_NUMBER() OVER (PARTITION BY d.doc_number ORDER BY d.doc_due_date DESC, d.doc_send_received DESC ...). As in the MDR Report Summary, the two orderings are not the same. - Show All Revisions:
GROUP BY d.doc_no, every row.
The rows are then walked in document order. The print loop applies one more rule when Show All Revisions is off: after the first row of a document, a further row of the same document is printed only if its revision starts with the same character as the previous printed one. That is how B and B_C (the comment sheet) print together while A is dropped. Rows are grouped under a header per root folder (getRootParent(library_code), "None" when the document has no folder).
The columns


From documents_print_all.htm in master: ID (doc_no), Library (library_desc), Document Number, Rev, Title, Result Code (doc_res_id), Issued Status (issued_code), Submission Date (doc_send_received), Issued Date (doc_issued_date), Due Date, Originator (doc_originator_person_id), Lead Reviewer, Notes, and Expiration Date when enable_doclib_retention is on. KTP's template labels the date "Received Date" and has no Lead Reviewer column, as the screenshot shows. The header carries the company from inact_report_title_company and "Documents: All, As Of <date>" or the By Date range.
The Print button on the grid itself (grid=1, documents_print_grid.inc.php) is a different thing: it prints the grid's current XML with the columns the user has ticked, no grouping, no revision rule.
Known issues
- The revision rule is by first character. Revisions
1and10print together;BandB1too. A document with revisionsA,BprintsBonly, which is intended, butB,A_CprintsBonly and drops the comment sheet of the older revision. - Vendor and subcontractor folders are recognised by code prefix
13and14, a convention from the first projects that not every instance follows. - By Date reads its range from the date filter row; with no date row the header prints an empty range.
Instance differences
Checked on 2026-09-06.
| Instance | Difference |
|---|---|
| All big five, plus Timas and KTP | The print path is the same (Prima Energy's documents_print_grid.inc.php is byte-identical to master's); the difference is in get_doc_column(), the grid column list each fork extends (system_code, well_site_code, function_code, doc_classification, ...). The report's columns are fixed by the template and do not follow the grid. |
Related
- Document Library: the module.
- DMS reports.