KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Pivot table show more than single information in a given column #526

Open shanaka perera opened this topic on on Nov 22, 2018 - 7 comments

shanaka perera commented on Nov 22, 2018

current_view

Above image represent the current output of the Pivot table I have designed so far. As mentioned in the title, I need to add extra information to the ItmName column like below :

update_1

EachPrice & Qty Columns should be inside the ItmName Column in horizontal orientation.

EX:

Cement- Tokyo Super
Each Price : 960
Qty : 20 

Here is my code so far :

protected function setup()
    {
        $query = "SELECT
    poh.id AS POId,
    poh.code AS POCode,
    poh.po_date AS PODate,
    poh.total AS POTotal,
    pod.qty AS Qty,
    pod.each_price AS EachPrice,
    itm.code AS ItmCode,
    itm.name AS ItmName,
    unt.name AS UnitName
FROM ... ";

        $this->src('konst_pro')
            ->query($query)
            ->pipe(new CalculatedColumn(array(
                "SubTot" => array(
                    "exp" => "{EachPrice}*{Qty}",
                    "type" => "number",
                    "decimals" => 2,
                   // "prefix" => "Rs"
                )
            )))
            ->pipe(new Pivot(array(
                'dimensions' => array(
                    //  'column' => 'Qty',
                    'row' => 'POCode, ItmName, EachPrice, Qty'
                ),

                "aggregates" => array(
                    "sum" => "SubTot"
                )
            )))
            ->pipe($this->dataStore('posum_report'));

    }

Report.view.php

    <h1>PO Summary Report</h1>
    <div>
        <?php
        $dataStore = $this->dataStore('posum_report');
        PivotTable::create(array(
            'dataStore' => $dataStore,
            'hideSubtotalRow' => true,
            'showDataHeaders' => true,
            'rowDimension' => 'row',
            'headerMap' => array(
                'SubTot - sum' => 'Purchase Order'
            ),
        ));
        ?>
    </div>

Any help or suggestion would be appreciable. Thanks.

shanaka perera commented on Nov 22, 2018

Correction

Not horizontal orientation, actually it should be vertical orientation.

_________________________________________________________

Cement- Tokyo Super
Each Price : 960
Qty : 20 
_________________________________________________________

And no use of EachPrice and Qty columns after that.

KoolReport commented on Nov 22, 2018

I think you before going to the Pivot process, you should create a new column which is the combination of ItemName, Each Price and Qty. You may use the CalculatedColumn process for this. After that, using this column for Pivot instead of Itemname, eachprice and qty column.

shanaka perera commented on Nov 22, 2018

So you are suggesting me to create a new column alias with sql query like below ??

...
 CONCAT(itm.name,'<br/> Qty : ',pod.qty,'<br/> EachPrice : ',pod.each_price) AS ColumnAliasHere
...
KoolReport commented on Nov 22, 2018

Yes, you can do it with sql query or using CalculatedColumn process to complete it.

shanaka perera commented on Nov 22, 2018

Can you please show me how to do it with CalculatedColumn ?? And also like to know that the same CalculatedColumn approach can be applied to Total column ??

EX:

______________________________
        Total
______________________________

SubTotal : 2000
Tax : 1000
GrandTotal : 3000
______________________________
KoolReport commented on Nov 22, 2018

It is like this:

->pipe(new CalculatedColumn(array(
    "new_column"=>function($row){
        return $row["itemname"]."<br/>".$row["eachprice"]."<br/>".$row["qty"];
    }
)))

Reference: Use CalculatedColumn function

shanaka perera commented on Nov 22, 2018

Oky .. Thanks a lot .

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed
solved

Pivot