Skip to content

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

Documents Library report, the customise form
Documents Library report, the customise form · click to enlarge
ControlFieldEffect
Projectproject
Filter Byfield[], 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 Dateprint_typeall prints "As Of today"; perday prints "As of <from> to <to>" and takes the range from the date filter
Show All Revisionsprint_all_revisionone row per library row instead of one per document
Without comment sheetprint_without_commentsheetadds doc_rev NOT LIKE '%_C'
Only vendor / subcontractorprint_only_vendor_subcontractor, print_vendor_subc_optrestricts to folders whose library_code starts with 13 (vendor), 14 (subcontractor) or either
Sortsortby[], 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 in doc_send_received DESC, doc_rev DESC order. MySQL does that with GROUP BY d.doc_no, doc_number over an ordered subquery; SQL Server and PostgreSQL with ROW_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

Documents Library report, HTML preview on the KTP snapshot
Documents Library report, HTML preview on the KTP snapshot · click to enlarge
The header, the ‘None’ folder group and the first rows, one document per row
The header, the ‘None’ folder group and the first rows, one document per row · click to enlarge

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 1 and 10 print together; B and B1 too. A document with revisions A, B prints B only, which is intended, but B, A_C prints B only and drops the comment sheet of the older revision.
  • Vendor and subcontractor folders are recognised by code prefix 13 and 14, 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.

InstanceDifference
All big five, plus Timas and KTPThe 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.