<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;

use yii\db\Query;

$this->title = 'Log Sync';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="sync-to-jurnal-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php Pjax::begin(); ?>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <!-- <p>
        <?= Html::a('Create Log Sync', ['create'], ['class' => 'btn btn-success']) ?>
    </p> -->

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            // 'id',
            'last_update',
            // 'tipe_tabel',
            [
                'attribute' => 'jenis_tabel',
                'value' => function($model) {
                    switch ($model->tipe_tabel) {
                        case 'rst_menu':
                            $result = 'Menu';
                            break;
                        
                        case 'bp_customer':
                            $result = 'Customer';
                            break;
                        
                        case 'rst_fc_trans_header':
                            $result = 'Sales';
                            break;
                        
                        case 'rst_fc_payment':
                            $result = 'Payment';
                            break;
                        
                        case 'sales_return':
                            $result = 'Sales Return';
                            break;
                        
                        default:
                            $result = '-';
                            break;
                    }
                    return $result;
                }
            ],
            // 'id_record',
            [
                'attribute' => 'nama_record',
                'value' => function($model) {
                    $db = Yii::$app->dbMyResto;
                    if ($model->tipe_tabel == 'rst_menu' || $model->tipe_tabel == 'bp_customer') {
                        $result = $db->createCommand('SELECT fname AS name FROM '.$model->tipe_tabel.' WHERE fpkey = '.$model->id_record)->queryOne();
                    } elseif ($model->tipe_tabel == 'rst_fc_trans_header' || $model->tipe_tabel == 'sales_return') {
                        $result = $db->createCommand('SELECT fcode AS name FROM rst_fc_trans_header WHERE fpkey = '.$model->id_record)->queryOne();
                    } else {
                        $result['name'] = '-';
                    }
                    return $result['name'];
                }
            ],
            'status_sinkron',
            'keterangan:ntext',
            // 'id_jurnal',
            // 'tipe_proses',

            // ['class' => 'yii\grid\ActionColumn'],
            [
                'class' => 'yii\grid\ActionColumn',
                'template' => '{view}',
            ],
        ],
    ]); ?>
    <?php Pjax::end(); ?>
</div>
