How To Avoid Fatal Error: Maximum Execution Time Of 30 Seconds Exceeded

I am developing an inventory system. I am getting this error when I want display the requisition list. I admit that the list has a lot of calculation, like verified and draft requisition, and many more. Belows are the code




<?php

$this->widget('bootstrap.widgets.TbGridView', array(

    'id' => 'lot-requisition-grid',

    'type' => 'condensed bordered',

    'emptyText' => 'Data tidak tersedia!',

    'summaryText' => 'Menampilkan baris {start}-{end} dari {count} baris - ' . CHtml::dropDownList('pageSize', $pageSize, array(2 => 2, 5 => 5, 10 => 10, 25 => 25, 50 => 50, 100 => 100, 500 => 500), array('class' => 'change-pageSize', 'style' => 'width: auto;')) . ' baris per halaman.',

    'template' => "{pager}\n{summary}\n{items}\n{pager}",

    'dataProvider' => $model->showReqLot($merge),

    'filter' => $model,

    'template' => "{pager}\n{summary}\n{items}\n{pager}",

    'rowCssClassExpression' => '($data->getRemainingRequisition($data->id) <= 0) ? "warning" : ""',

    'columns' => array(

        array(

            'header' => 'No',

            'value' => '$this->grid->dataProvider->pagination->currentPage * $this->grid->dataProvider->pagination->pageSize + $row + 1', // row is zero based

            'htmlOptions' => array('style' => 'text-align: center; width: 50px;'),

        ),

        array(

            'name' => 'itemFk',

            'type' => 'raw',

            'value' => '$data->item->name'

        ),

        array(

            'header' => 'FPP [V]',

            'type' => 'raw',

            'value' => '$data->getVerRequisition($data->itemFk) == round($data->getVerRequisition($data->itemFk), 0) ? number_format($data->getVerRequisition($data->itemFk), 0, ",", ".") : number_format($data->getVerRequisition($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FPP [D]',

            'type' => 'raw',

            'value' => '$data->getUnverRequisition($data->itemFk) == round($data->getUnverRequisition($data->itemFk), 0) ? number_format($data->getUnverRequisition($data->itemFk), 0, ",", ".") : number_format($data->getUnverRequisition($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FPO [V]',

            'type' => 'raw',

            'value' => '$data->getVerPurchaseOrder($data->itemFk) == round($data->getVerPurchaseOrder($data->itemFk), 0) ? number_format($data->getVerPurchaseOrder($data->itemFk), 0, ",", ".") : number_format($data->getVerPurchaseOrder($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FPO [D]',

            'type' => 'raw',

            'value' => '$data->getUnverPurchaseOrder($data->itemFk) == round($data->getUnverPurchaseOrder($data->itemFk), 0) ? number_format($data->getUnverPurchaseOrder($data->itemFk), 0, ",", ".") : number_format($data->getUnverPurchaseOrder($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FP (PO) [V]',

            'type' => 'raw',

            'value' => '$data->getVerPurchaseOutgoing($data->itemFk) == round($data->getVerPurchaseOutgoing($data->itemFk), 0) ? number_format($data->getVerPurchaseOutgoing($data->itemFk), 0, ",", ".") : number_format($data->getVerPurchaseOutgoing($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FP (PO) [D]',

            'type' => 'raw',

            'value' => '$data->getUnverPurchaseOutgoing($data->itemFk) == round($data->getUnverPurchaseOutgoing($data->itemFk), 0) ? number_format($data->getUnverPurchaseOutgoing($data->itemFk), 0, ",", ".") : number_format($data->getUnverPurchaseOutgoing($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FP (Gd) [V]',

            'type' => 'raw',

            'value' => '$data->getVerOutgoing($data->itemFk) == round($data->getVerOutgoing($data->itemFk), 0) ? number_format($data->getVerOutgoing($data->itemFk), 0, ",", ".") : number_format($data->getVerOutgoing($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'FP (Gd) [D]',

            'type' => 'raw',

            'value' => '$data->getUnverOutgoing($data->itemFk) == round($data->getUnverOutgoing($data->itemFk), 0) ? number_format($data->getUnverOutgoing($data->itemFk), 0, ",", ".") : number_format($data->getUnverOutgoing($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span1', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'Sisa permintaan',

            'type' => 'raw',

            'value' => '$data->getVerRemainingRequisition($data->itemFk) == round($data->getVerRemainingRequisition($data->itemFk), 0) ? number_format($data->getVerRemainingRequisition($data->itemFk), 0, ",", ".") : number_format($data->getVerRemainingRequisition($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span2', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'Pemakaian material',

            'type' => 'raw',

            'value' => '$data->getUsage($data->itemFk) == round($data->getUsage($data->itemFk), 0) ? number_format($data->getUsage($data->itemFk), 0, ",", ".") : number_format($data->getUsage($data->itemFk), 2, ",", ".")',

            'htmlOptions' => array('class' => 'span2', 'style' => 'text-align: right;')

        ),

        array(

            'header' => 'Satuan',

            'name' => 'baseUnit',

            'htmlOptions' => array('class' => 'span1')

        ),

    ),

));

?>






public function showReqLot($merge = null) {

        // Warning: Please modify the following code to remove attributes that

        // should not be searched.


        $criteria = new CDbCriteria;

        $criteria->with = array('item', 'header', 'lot');

        $criteria->compare('header.type', 2); // Only requisitions

        $criteria->addBetweenCondition('header.status', 0, 1);

        $criteria->compare('item.name', $this->itemFk, true);

        $criteria->compare('t.baseUnit', $this->baseUnit, true);

        $criteria->group = 't.itemFk';

        if ($merge != null) {

            $criteria->mergeWith($criteria);

        }


        $sort = new CSort;

        $sort->defaultOrder = 'item.name ASC';

        $sort->attributes = array(

            'itemFk' => array(

                'asc' => 'item.name ASC',

                'desc' => 'item.name DESC',

            ),

            'baseUnit' => 't.baseUnit',

            'memo' => 't.memo',

        );


        $sort->applyOrder($criteria);


        return new CActiveDataProvider($this, array(

            'criteria' => $criteria,

            'sort' => $sort,

            'pagination' => array(

                'pageSize' => Yii::app()->user->getState('FormDetail_pageSize', Yii::app()->params['defaultPageSize']),

            ),

        ));

    }



I am thinking using database view, but still very slow. Any help on this? It would be fine if I need to create the report in yii command, but I need to be able to call the command from the web app.

Thank you in advance.

If you expect that the execution time will take more than the default time such as 30 seconds, see here

where is the link?