$aieo_us_slug . '_30d', 'label' => sprintf( __( '%s, 30 days', 'ai-eshop-optimizer' ), $aieo_us_bl ), 'type' => 'integer', 'sortable' => true, 'filter' => 'number_range', ); $aieo_us_bcolumns[] = array( 'key' => $aieo_us_slug . '_60d', 'label' => sprintf( __( '%s, 60 days', 'ai-eshop-optimizer' ), $aieo_us_bl ), 'type' => 'integer', 'sortable' => true, 'hidden' => true, ); $aieo_us_bcolumns[] = array( 'key' => 'trend_of_' . $aieo_us_slug, 'label' => sprintf( __( '%s trend', 'ai-eshop-optimizer' ), $aieo_us_bl ), 'type' => 'percent', 'format' => array( 'precision' => 1, 'sign' => true ), 'sortable' => true, 'hidden' => true, ); } $aieo_us_sql = " SELECT s.`id`, COALESCE( NULLIF( s.`name`, '' ), s.`sku` ) AS `name`, s.`product_id`, s.`sku`, s.`gtin`, s.`brand`, s.`image_url`, s.`total_30d`, s.`total_60d`, s.`trend_of_total`, /* THE ERP FIGURE, aliased the way the vendor aliased it. `total_30d` reconciles against this on 10,986 of 10,986 rows and against the Woo columns on 480 fewer. See the docblock. */ s.`eshop_soft1_30d` AS `eshop_30d`, s.`eshop_soft1_60d` AS `eshop_60d`, s.`trend_of_eshop_soft1` AS `trend_of_eshop`, {$aieo_us_bcols} s.`created` FROM {prefix}aieo_dmm_store_sales s {$aieo_us_bjoins}"; return array( 'id' => 'insights_unit_sales', 'label' => 'Unit sales, online and branches', 'description' => 'How many units of each product moved in the last 30 and 60 days, split by the online shop and each branch, with the trend between the two windows.', 'footnote' => 'The five channel columns add up to the total, so only the totals are summed at the foot. A trend is a rate and is never totalled. Products the ERP sells but this shop has never listed appear under their SKU.', 'group' => 'eshop_insights', 'section' => 'stock_management', 'icon' => 'building-2', 'tier' => 'pro', 'scope' => 'both', 'source' => 'sql', 'sql' => $aieo_us_sql, 'registry_id' => 'insights_t32.unit_sales', 'version' => '1', 'per_page' => 50, 'row_key' => 'id', 'default_sort' => array( 'total_30d', 'desc' ), 'empty_state' => 'No unit sales recorded yet. This fills from the nightly store-sales build, which reads the ERP feed and the shop together.', 'actions' => array( array( 'id' => 'edit', 'label' => 'Edit', 'intent' => array( 'name' => 'edit_product', 'key' => 'product_id' ), 'capability' => 'edit_products', 'when' => array( 'key' => 'product_id', 'not' => '' ), ), ), 'columns' => array_merge( array( array( 'key' => 'id', 'label' => 'ID', 'type' => 'id', 'hidden' => true, ), array( 'key' => 'image_url', 'label' => '', 'sr_label' => 'Product image', 'type' => 'image', 'format' => array( 'size' => 44, 'rehost' => true ), 'width' => '58px', 'sortable' => false, 'empty' => '', ), array( 'key' => 'name', 'label' => 'Product', 'type' => 'text', 'sortable' => true, 'searchable' => true, 'filter' => 'text', 'truncate' => 48, 'tooltip' => true, ), array( 'key' => 'sku', 'label' => 'SKU', 'type' => 'code', 'sortable' => true, 'searchable' => true, 'filter' => 'text', ), array( 'key' => 'gtin', 'label' => 'GTIN', 'type' => 'code', 'searchable' => true, 'hidden' => true, ), array( 'key' => 'brand', 'label' => 'Brand', 'type' => 'text', 'sortable' => true, 'searchable' => true, 'filter' => 'select', ), array( 'key' => 'total_30d', 'label' => 'Units, 30 days', 'type' => 'integer', 'sortable' => true, 'filter' => 'number_range', 'aggregate' => 'SUM', ), array( 'key' => 'total_60d', 'label' => 'Units, 60 days', 'type' => 'integer', 'sortable' => true, 'filter' => 'number_range', 'aggregate' => 'SUM', ), array( 'key' => 'trend_of_total', 'label' => 'Trend', 'type' => 'percent', 'format' => array( 'precision' => 1, 'sign' => true ), 'sortable' => true, 'filter' => 'number_range', 'bands' => array( array( 'max' => -25, 'tone' => 'danger' ), array( 'min' => 25, 'tone' => 'success' ), ), ), array( 'key' => 'eshop_30d', 'label' => 'Online, 30 days', 'type' => 'integer', 'sortable' => true, 'filter' => 'number_range', ), array( 'key' => 'eshop_60d', 'label' => 'Online, 60 days', 'type' => 'integer', 'sortable' => true, 'hidden' => true, ), array( 'key' => 'trend_of_eshop', 'label' => 'Online trend', 'type' => 'percent', 'format' => array( 'precision' => 1, 'sign' => true ), 'sortable' => true, 'hidden' => true, ), ), $aieo_us_bcolumns, array( array( 'key' => 'product_id', 'label' => 'Product', 'type' => 'id', 'hidden' => true, ), array( 'key' => 'created', 'label' => 'Built', 'type' => 'datetime', 'format' => array( 'tz' => 'utc' ), 'hidden' => true, ), ) ), );