0
votes

I have 2 tables called 'PO' and 'Agen'. Table PO have reference to Agen (agen_id attribute). When viewing in the gridview from index.php PO, i want to calculate $model->netto ($PO->netto) with $Agen->fee.

[
        'class'=> 'kartik\grid\FormulaColumn', 
        'header' => 'Subtotal Fee Agen',
        'value' => function($model){
            //return var_dump($model);
            return ($model->netto * fee);
        },
        'format'=>['decimal', 0],
        'hAlign' => 'right'
    ],

I have still no luck with this. Unknown property error. Please advice. thanks before.

1

1 Answers

0
votes

With $model being the instance of PO and $agen being the instance of Agen passed from the controller use inside the grid:

'value' => function ($model) use ($agen) {
    return $model->netto * $agen->fee;
},

If I got it correctly and you have relation set getAgen() in PO using agen_id so you can reach Agen like:

$fee = $model->agen->fee;

you can use it like that:

'value' => function ($model) {
    return $model->netto * $model->agen->fee;
},