diff --git a/classes/headers/DynamicHeader.php b/classes/headers/DynamicHeader.php new file mode 100644 index 00000000..23d3c419 --- /dev/null +++ b/classes/headers/DynamicHeader.php @@ -0,0 +1,64 @@ +array( + 'required'=>true, + 'type'=>'string' + ) + ); + + public static function init($params, &$report) { + + if($params['file'][0] === '/') { + + $file_path = substr($params['file'],1); + + } + else { + + $file_path = dirname($report->report).'/'.$params['file']; + + } + + if(file_exists(PhpReports::$config['reportDir'].'/'.$file_path)) { + + include(PhpReports::$config['reportDir'].'/'.$file_path); + + /** + * This allows you to specify headers in php, + * which allows you to build the properties dynamically. + */ + if (isset($headers) and count($headers)) { + + foreach ($headers as $header) { + + $report->parseHeader($header['name'], $header['params']); + + } + } + + /** + * Similarly this allows you to specify macros + * in php so you can disallow various headers, + * substituting them with macros. + */ + if (isset($macros) and count($macros)) { + + foreach ($macros as $key => $value) { + $report->addMacro($key, $value); + } + + } + + } + } + + public static function parseShortcut($value) { + return array( + 'file'=>$value + ); + } +} + +?> diff --git a/sample_reports/mysql/sales.sql b/sample_reports/mysql/sales.sql new file mode 100644 index 00000000..fa262a0c --- /dev/null +++ b/sample_reports/mysql/sales.sql @@ -0,0 +1,39 @@ +-- Sales +-- This report lets a non sales rep, look at a specific sales reps orders within a specified time period, +-- however a sales rep will only be able to see their own orders. +-- You can click on a customer name to drill down into all orders for that customer. +-- VARIABLE: { +-- name: "range", +-- display: "Report Range", +-- type: "daterange", +-- default: { start: "yesterday", end: "yesterday" } +-- } +-- DYNAMIC: { +-- file: "sales_rep_header.php" +-- } +-- FILTER: { +-- column: "Customer Name", +-- filter: "drilldown", +-- params: { +-- macros: { "id": { column: "Customer Id" } }, +-- report: "drilldown/customer-orders.sql" +-- } +-- } + +SELECT + order_id as `Order Id`, + created_at as `Order Date`, + CONCAT(customer_fname, " ", customer_lname) as `Customer Name`, + customer_id as `Customer Id`, + grand_total as `Grand Total`, + status as `Order Status` +FROM + orders +WHERE + created_at BETWEEN "{{ range.start }}" AND "{{ range.end }}" + AND + (CASE + WHEN 'ALL' = '{{ sales_rep_id }}' + THEN 1 = 1 + ELSE sales_rep_id = '{{ sales_rep_id }}' + END) diff --git a/sample_reports/mysql/sales_rep_header.php b/sample_reports/mysql/sales_rep_header.php new file mode 100644 index 00000000..c6749014 --- /dev/null +++ b/sample_reports/mysql/sales_rep_header.php @@ -0,0 +1,31 @@ + 0) { + + $macros['sales_rep_id'] = $sales_rep_id; + +} else { + + $header['name'] = 'VARIABLE'; + $header['params'] = array( + 'name' => 'sales_rep_id', + 'display' => 'Sales Rep', + 'type' => 'select', + 'empty' => true, + 'database_options' => array( + 'table' => 'sales_reps', + 'column' => 'id', + 'display' => 'name', + 'where' => 'active = "y"', + 'all' => true + ) + ); + + $headers[] = $header; +} + + + +?>