ok i m trying new way of doing the actual calculation in koolreport iteself and it gives me an interesting error.
here is the code:
$cust_payments_source = $this->src("fmd")->query(
\App\CustomerPayment::where('deleted_at', '=', null)
->FilterBetweenMonths(
$start_date,
$end_date
)
)
->pipe(new Sort(array(
"name" => "asc"
)))
->pipe(new DateTimeFormat(array(
"payment_date" => "Y-m",
)))
->pipe(new CalculatedColumn(array(
"customer_payment_amount" => function ($data) {
if ($data["payment_status"] === 'success') {
return $data["payment_amount"] - $data["amount_refunded"];
}
},
)))
->pipe(new \koolreport\processes\ColumnMeta([
"customer_payment_amount" => [
"type" => "number",
"decimals" => 2,
],
]))
->pipe(new Group(array(
"by" => array("customer_id", "payment_date"),
"sum" => array(
"adjusted_amount",
"payment_amount",
"customer_payment_amount"
),
)))
->pipe(new OnlyColumn(array(
"customer_id", "payment_date",
"adjusted_amount",
"payment_amount",
"customer_payment_amount"
)));
//$cust_payments_source->pipe($this->dataStore('temp'));
$join = new Join($customers_source, $cust_payments_source, array("customer_id" => "customer_id"));
$join2 = new Join($salespeople_source, $join, array("salesperson_id" => "salesperson_id"));
$join3 = new Join($contractors_source, $join2, array("contractor_id" => "contractor_id"));
//$join3->pipe($this->dataStore('temp'));
$join3
->pipe(new Group(array(
"by" => array("contractor_id", "contractor_name"),
"sum" => array(
"payment_amount",
"customer_payment_amount"
),
)))
->saveTo($all_data_source);
$all_data_source->pipe($this->dataStore('temp'));