<?php

use yii\helpers\Html;
use kartik\grid\GridView;
use yii\widgets\Pjax;
use mdm\admin\components\Helper;
use common\widgets\Alert;
use common\helper\Support;
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var frontend\models\TorderhdSearch $searchModel
 */

$this->title = 'Report Detail Sales Order';
$this->params['breadcrumbs'][] = ['label' => 'Sales Order', 'url' => ['salesorder/listks']];
$this->params['breadcrumbs'][] = $this->title;

?>
<?php Pjax::begin(); ?>

<div class="torderhd-index">
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?php /* echo Html::a('Create Torderhd', ['create'], ['class' => 'btn btn-success'])*/  ?>
    </p>
    <?php     $create = ''; ?>
    <?php     /* if(Helper::checkRoute('/salesorder/create')){
          $random = rand();
          $create =  Html::a('<i class="glyphicon glyphicon-plus"></i>', ['create?uid='.$random], ['class' => 'btn btn-success']);
    } */?>
   
    <?php echo GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            
            'vNoFaktur',
            [
                'attribute' => 'vNoInvoice',
                'value' => 'header.vNoInvoice',
                'label' => 'No Struk'
            ],
            [
                'attribute' => 'iCabangid',
                'value' => 'header.cabang.vNama',
                'label' => 'Cabang'
            ],
            [
                'attribute' => 'sektor',
                'value' => 'header.eTipesektor',
            ],
            [
                'attribute' => 'nama_barang',
                'value' => 'barang.vNama'
            ],
            [
                'attribute' => 'kemasan',
                'value' => 'kemasan.vNama'
            ],
            [
                'attribute' => 'status',
                'value' => 'header.eStatus'
            ],

            [
                'attribute' =>'tCreated',
                'label' => 'Created',
                'value'     => function($model){
                    $nama = (isset($model->header->iCreated->name) && $model->header->iCreated->name) ? $model->header->iCreated->name : '-';
                    $date = ($model->header->tCreated) ? $model->header->tCreated : '-';
                    return '<b>'.Support::potong($nama, 12).'</b>';
                },
                'format' => 'raw'
            ],

            [
                'attribute' =>'tUpdated',
                'label' => 'PIC',
                'value'     => function($model){
                    $nama = (isset($model->header->ipic->name) && $model->header->ipic->name) ? $model->header->ipic->name : '-';
                    $date = ($model->header->tUpdated) ? $model->header->tUpdated : '-';
                    return '<b>'. Support::potong($nama, 12).'</b>';
                },
                'format' => 'raw'
            ],
            // 'iQty',
            // 'iQtyKirim',
            // 'iBonus',
            // 'eStatus',
            // [
            //     'attribute' => 'eStatusRelease',
            //     'label' => 'Release'
            // ],
            // 'fDiscount',
            // [
            //     'contentOptions' => [ 'style' => 'width: 4%;' ],
            //     'attribute' => 'fHargaJual',
            //     'format'=>['decimal',2]
            // ],
            // [
            //     'contentOptions' => [ 'style' => 'width: 4%;' ],
            //     'attribute' => 'fTotal',
            //     'format'=>['decimal',2]
            // ],
            // [
            //     'contentOptions' => [ 'style' => 'width: 4%;' ],
            //     'attribute' => 'fPPN',
            //     'format'=>['decimal',2]
            // ],
            // [
            //     'contentOptions' => [ 'style' => 'width: 4%;' ],
            //     'attribute' => 'fGrandtotal',
            //     'format'=>['decimal',2]
            // ],
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => Helper::filterActionColumn(''),
                'buttons' => [
                    // 'closefuco' => function ($url, $model) {
                    //     $icon = '<span class="glyphicon glyphicon-ban-circle btn btn-sm btn-danger" title="Close Order"></span>';
                    //     $disabled = ($model->eFlagor == 'Close') ? 'disabled' : '';
                    //     if($model->eFlagor != 'Close'){
                    //         return Html::a($icon,'javascript:void(0)',[
                    //             'class'=>'btn '.$disabled,
                    //             'id'=>'close-order-'.$model->iId,
                    //             'onclick'=>'closed("'.$url.'");'
                    //         ]);
                    //     }               
                    // },
                    //  'createor' => function ($url, $model) {
                     
                    //     $icon = '<span class="glyphicon glyphicon-list-alt btn btn-sm btn-primary" title="Create Order Request"></span>';
                    //     if($model->eFlagor != 'Close'){
                    //         return Html::a($icon,$url);             
                    //     }else{
                    //         return 'Closed';
                    //     }
                     
                    // },
                    
                ],
            ],
        ],
         'containerOptions' => ['style' => 'overflow: auto'],
         'headerRowOptions' => ['class' => 'kartik-sheet-style'],
         'filterRowOptions' => ['class' => 'kartik-sheet-style'],
         'pjax' => true,
         
         'toolbar' =>  [
             
            ['content' => 
            
                $create. ' '.
                Html::a('<i class="glyphicon glyphicon-repeat"></i>', ['/salesorder'], ['class' => 'btn btn-warning', 'title' => Yii::t('kvgrid', 'Reset Grid')
                    ])
              
           ],
              
            '{export}',
            '{toggleData}',
            
        ],
        
        'export' => [
            'fontAwesome' => true
        ],
         
        'bordered' => true,
        'striped' => true,
        'condensed' => true,
        'responsive' => true,
        'hover' => true,
         'pager' => [
                    'options'=>['class'=>'pagination'],   
                    'prevPageLabel' => '<i class="glyphicon glyphicon-step-backward"></i>',  
                    'nextPageLabel' => '<i class="glyphicon glyphicon-step-forward"></i>',   
                    'firstPageLabel'=>'<i class="glyphicon glyphicon-fast-backward"></i>',  
                    'lastPageLabel'=>'<i class="glyphicon glyphicon-fast-forward"></i>',   
                    'maxButtonCount'=>10,    
            ],      

        'panel' => [
            'type' => GridView::TYPE_PRIMARY,
            // 'heading' => 'Order Request Non Regular',
        ],
        'persistResize' => false,
        'toggleDataOptions' => ['minCount' => 10],
        'exportConfig' => 'excel',
        
    ]); ?>

</div>
<script>
    function closed(url){
        if(confirm('Close Order ini?')){
            window.location.href = url;
        }else{
            alert('Anda membatalkan aksi ini');
        }
    }
</script>