Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions classes/headers/DynamicHeader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
class DynamicHeader extends HeaderBase {

static $validation = array(
'file'=>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
);
}
}

?>
39 changes: 39 additions & 0 deletions sample_reports/mysql/sales.sql
Original file line number Diff line number Diff line change
@@ -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)
31 changes: 31 additions & 0 deletions sample_reports/mysql/sales_rep_header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
// Dynamic Sales Rep Header
// OPTIONS: {"ignore": true}

if (isset($sales_rep_id) && $sales_rep_id > 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;
}



?>