The function get_invoice_range() in the invoice report reporting/rep107.php uses the sql:
SELECT trans.trans_no, trans.reference
FROM 1_debtor_trans trans
LEFT JOIN 1_voided voided ON trans.type=voided.type AND trans.trans_no=voided.id
WHERE trans.type=10 AND ISNULL(voided.id);
which extracts the invoices to be printed and example of it is:
trans_no reference
1 001/2017
2 002/2017
3 003/2017
4 004/2017
The function get_customer_trans in sales/includes/db/cust_trans_db.inc uses the sql:
SELECT trans.*, ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,
cust.name AS DebtorName, cust.address,
cust.curr_code,
cust.tax_id,
trans.prep_amount>0 AS prepaid,
com.memo_,
1_shippers.shipper_name,
1_sales_types.sales_type,
1_sales_types.tax_included,
branch.*,
cust.discount,
1_tax_groups.name AS tax_group_name,
1_tax_groups.id AS tax_group_id
FROM 1_debtor_trans trans
LEFT JOIN 1_comments com ON trans.type=com.type AND trans.trans_no=com.id
LEFT JOIN 1_shippers ON 1_shippers.shipper_id=trans.ship_via,
1_debtors_master cust,
1_sales_types,
1_cust_branch branch,
1_tax_groups
WHERE trans.debtor_no=cust.debtor_no
AND 1_sales_types.id = trans.tpe
AND branch.branch_code = trans.branch_code
AND branch.tax_group_id = 1_tax_groups.id;
The delivery date is in another record (type=13) and not in the invoice record (type=10).