in oracle, we handle null input parameter for query like this:
select empno, ename from emp where ename = nvl(:name, ename);
means if parameter name is null then return all rows regardless of specific ename.
how i can handle it here? see my code below:
( also please guide, is it correct way to have parametarized report )
CustomerSummary.php
<?php
namespace App\Reports;
// require_once "../../../load.koolreport.php";
use \koolreport\KoolReport;
use \koolreport\processes\Sort;
class CustomerSummary extends \koolreport\KoolReport
{
use \koolreport\codeigniter\Friendship;
use \koolreport\inputs\Bindable;
use \koolreport\inputs\POSTBinding;
protected function defaultParamValues()
{
return array(
"dateRange"=>array(
"2022-12-01",
"2022-12-10",
),
"customers"=>null,
);
}
protected function bindParamsToInputs()
{
return array(
"dateRange"=>"dateRange",
"customers"=>"customers",
);
}
function setup()
{
$this->src("default")
->query("SELECT DATE(order_date) AS order_date, user_id, customer_name, rides,rider_charges, order_total FROM customer_summary WHERE
user_id = nvl(:customers, user_id)
AND
order_date >= :start
AND
order_date <= :end")
->params(array(
":start"=>$this->params["dateRange"][0],
":end"=>$this->params["dateRange"][1],
":customers"=>$this->params["customers"]
))
->pipe(Sort::process([
"order_date"=>"desc"
]))
->pipe($this->dataStore("result"));
$this->src("default")->query("
SELECT DISTINCT
user_id,
customer_name
FROM
customer_summary
ORDER BY customer_name
")
->pipe($this->dataStore("customers"));
}
}
please help.
regards