0 ? home_url( '/?p=' . $id ) : ''; } } $aieo_rs_sql = " SELECT sp.id, sp.created_at, br.label AS branch, sp.product_id, pv.image_url, pp.image_url AS parent_image_url, COALESCE( NULLIF( pv.product_name, '' ), NULLIF( pv.name, '' ), CONCAT( '#', sp.product_id ) ) AS product, COALESCE( pv.parent_id, sp.product_id ) AS link_id, ( pv.product_id IS NOT NULL ) AS resolvable, pv.sku, pv.gtin AS barcode, st.name AS supplier, ( SELECT tm.meta_value FROM {prefix}termmeta tm WHERE tm.term_id = sp.supplier_term_id AND tm.meta_key = 'aieo_supplier_erp_id' LIMIT 1 ) AS supplier_erp_id, sp.requested_qty, sp.prior_existing, sp.status, sp.scanned_user_id FROM {prefix}aieo_dmm_supplier_preorders sp LEFT JOIN {prefix}aieo_core_product_vitals pv ON pv.product_id = sp.product_id LEFT JOIN {prefix}aieo_core_product_vitals pp ON pp.product_id = pv.parent_id LEFT JOIN {prefix}aieo_dmm_branches br ON br.id = sp.branch_id LEFT JOIN {prefix}terms st ON st.term_id = sp.supplier_term_id "; return array( 'id' => 'insights_reorder_summary', 'label' => 'Reorder summary', 'description' => 'Every branch pre-order request ever recorded — the full history behind the Supplier Orders approval queue, with the product, supplier and branch on every line.', 'footnote' => 'The supplier ERP id is blank when the supplier has no ERP mapping. Requests naming a product that has since been deleted stay listed as #id — the request happened even if the product is gone. "Stock at request" was recorded only when the scan captured it.', 'group' => 'eshop_insights', 'section' => 'stock_reordering', 'icon' => 'repeat', 'tier' => 'pro', 'scope' => 'local', 'source' => 'sql', 'sql' => $aieo_rs_sql, 'registry_id' => 'insights_t35.reorder_summary', 'version' => '1', 'per_page' => 50, 'row_key' => 'id', 'default_sort' => array( 'created_at', 'desc' ), 'empty_state' => 'No pre-order requests recorded yet. Requests arrive from the branch worksheets and from staff scans on the Branch Stock Scanner.', 'columns' => array( array( 'key' => 'id', 'label' => 'ID', 'type' => 'id', 'hidden' => true, ), array( 'key' => 'created_at', 'label' => 'Requested', 'type' => 'datetime', 'width' => '150px', 'nowrap' => true, 'sortable' => true, 'filter' => 'date_range', 'format' => array( 'tz' => 'utc' ), ), array( 'key' => 'branch', 'label' => 'Branch', 'type' => 'text', 'sortable' => true, 'filter' => 'select', 'empty' => '—', ), array( 'key' => 'image_url', 'label' => '', 'sr_label' => 'Product image', 'type' => 'image', 'format' => array( 'size' => 44, 'rehost' => true ), 'width' => '58px', 'sortable' => false, 'empty' => '', ), array( 'key' => 'parent_image_url', 'label' => '', 'sr_label' => 'Parent product image', 'type' => 'image', 'format' => array( 'size' => 44, 'rehost' => true ), 'width' => '58px', 'sortable' => false, 'empty' => '', ), array( 'key' => 'product', 'label' => 'Product', 'type' => 'link', 'format' => array( 'href' => 'aieo_reorder_summary_permalink' ), 'subline' => 'sku', 'sortable' => true, 'searchable' => true, 'filter' => 'text', 'truncate' => 48, 'tooltip' => true, ), array( 'key' => 'sku', 'label' => 'SKU', 'type' => 'code', 'searchable' => true, 'hidden' => true, ), array( 'key' => 'barcode', 'label' => 'Barcode', 'type' => 'code', 'searchable' => true, 'hidden' => true, ), array( 'key' => 'supplier', 'label' => 'Supplier', 'type' => 'text', 'sortable' => true, 'filter' => 'select', 'empty' => '— unresolved —', ), array( 'key' => 'supplier_erp_id', 'label' => 'Supplier ERP id', 'type' => 'code', 'empty' => '—', ), array( 'key' => 'requested_qty', 'label' => 'Requested qty', 'type' => 'integer', 'width' => '90px', 'sortable' => true, 'aggregate' => 'SUM', ), array( 'key' => 'prior_existing', 'label' => 'Stock at request', 'type' => 'integer', 'width' => '90px', 'empty' => '—', ), array( 'key' => 'status', 'label' => 'Status', 'type' => 'badge', 'width' => '100px', 'sortable' => true, 'filter' => 'select', 'format' => array( 'labels' => array( 'requested' => 'pending' ), 'map' => array( 'requested' => 'warning', 'approved' => 'info', 'ordered' => 'info', 'received' => 'success', 'rejected' => 'danger', ), ), ), array( 'key' => 'scanned_user_id', 'label' => 'Recorded by', 'type' => 'user', 'empty' => '—', 'empty_zero' => true, ), array( 'key' => 'product_id', 'label' => 'Product ID', 'type' => 'id', 'sortable' => true, 'searchable' => true, 'hidden' => true, ), array( 'key' => 'link_id', 'label' => 'Link ID', 'type' => 'id', 'hidden' => true ), array( 'key' => 'resolvable', 'label' => 'Resolvable', 'type' => 'boolean', 'hidden' => true ), ), );