s.cutoff /* INNER, not LEFT: the ruling. A sold product with no vitals row is a DELETED product, not an out-of-stock one. */ JOIN {prefix}aieo_core_product_vitals pv ON pv.product_id = o.product_id GROUP BY s.period_rank, s.period, o.product_id ) x GROUP BY x.period_rank, x.period "; return array( 'id' => 'insights_stockout_rate', 'label' => 'Stockout rate by period', 'description' => 'Of the products that actually sold in each window, how many are out of stock right now — and how much of that window\'s turnover they were carrying.', 'footnote' => 'Each row contains the rows above it (the past year includes the past month), so the columns are deliberately never totalled: a sum down this table counts the same orders up to five times. Products that no longer exist in the catalogue are excluded throughout.', 'group' => 'eshop_insights', 'section' => 'stock_management', 'icon' => 'chart-column', 'tier' => 'pro', 'scope' => 'both', 'source' => 'sql', 'sql' => $aieo_sr_sql, 'registry_id' => 'insights_t27.stockout_rate', 'version' => '1', 'per_page' => 10, 'row_key' => 'period_rank', 'default_sort' => array( 'period_rank', 'asc' ), 'requires_hpos' => true, 'empty_state' => 'No sales in the last two years, so there is nothing to rate. Rows appear once the order analytics hold sold products.', 'columns' => array( array( 'key' => 'period_rank', 'label' => 'Rank', 'type' => 'id', 'sortable' => true, 'hidden' => true, ), array( 'key' => 'period', 'label' => 'Period', 'type' => 'text', 'sortable' => true, 'sort_key' => 'period_rank', ), array( 'key' => 'total_products', 'label' => 'Products sold', 'type' => 'integer', 'sortable' => false, ), array( 'key' => 'out_of_stock', 'label' => 'Now out of stock', 'type' => 'integer', 'sortable' => false, ), array( 'key' => 'percentage_out_of_stock', 'label' => 'Out of stock %', 'type' => 'percent', 'format' => array( 'precision' => 2 ), 'sortable' => false, 'bands' => array( array( 'min' => 30, 'tone' => 'danger' ), array( 'min' => 20, 'tone' => 'warning' ), ), ), array( 'key' => 'turnover_total', 'label' => 'Turnover', 'type' => 'money', 'sortable' => false, ), array( 'key' => 'turnover_out_of_stock', 'label' => 'Turnover now unavailable', 'type' => 'money', 'sortable' => false, ), ), );