<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\Pjax;
use mdm\admin\components\Helper;
use common\widgets\Alert;
use common\components\widget\MdcWidget;
use common\components\modular\SoKasir;

/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var frontend\models\TorderhdSearch $searchModel
 */
// js with obfuscation
$this->registerJsFile(Url::Base(true) . '/frontend/web/js/salesorder/index_sales_regular.js', ['position' => $this::POS_END, 'appendTimestamp' => true]);

$this->title = 'Sales Order ' . $title;
$this->params['breadcrumbs'][] = $this->title;
$modul = new SoKasir;
?>
<style>
    .btn-orange {
        background: rgb(75,108,187);
        background: linear-gradient(0deg, rgba(75,108,187,1) 0%, rgba(244,89,89,1) 100%);
        border-color: #f45959;
        color: white;
    }
    .btn-pink {
        background-color: #f56e87;
        border-color: #f5647f;
        color: white;
    }

    .btn-pink:hover,
    .btn-pink:active {
        background-color: #eb657e;
        border-color: #ef5e79;
        color: white;
    }

    .btn-purple {
        background-color: #a86ef5;
        border-color: #9c64f5;
        color: white;
    }

    .btn-purple:hover,
    .btn-purple:active {
        background-color: #9e64eb;
        border-color: #945deb;
        color: white;
    }
</style>
<?php Pjax::begin(); ?>
<div class="torderhd-index">
    <?php $create = '';
    $blockr = '';
    $reportcreate = '';
    $reportcreate2 = '';
    $reportcreate3 = ''; ?>
    <?php if (Helper::checkRoute('/salesorder/create-kasir')) {
        $random = rand();
        $create .=  Html::a('<i class="glyphicon glyphicon-plus"></i>', ['create-kasir?uid=' . $random], ['class' => 'btn btn-success']);
    }

    // if (Helper::checkRoute('/salesorder/block')) {
    //     $create .=  Html::a('<i class="glyphicon glyphicon-exclamation-sign"></i>', ['block'], ['class' => 'btn btn-danger', 'title' => Yii::t('kvgrid', 'Pengajuan SO')]);
    // }
    // if ($title == 'Non-Regular') {
    //     if (Helper::checkRoute('/order-report/reportksorder')) {
    //         $create .=  Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::to(['order-report/reportksorder']), ['class' => 'btn btn-primary']);
    //     }
    //     if (Helper::checkRoute('/order-report/reportprincipal')) {
    //         $create .= Html::a('<i class="glyphicon glyphicon-list-alt"></i>', ['order-report/reportprincipal'], ['class' => 'btn btn-danger', 'title' => Yii::t('kvgrid', 'Report Principal')]);
    //     }
    // } else if ($title == 'Regular') {
    //     if (Helper::checkRoute('/order-report/reportregular')) {
    //         $create .=  Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::to(['order-report/reportregular']), ['class' => 'btn btn-info']);
    //     }
    //     if (Helper::checkRoute('/order-report/faktur-reguler')) {
    //         $create .=  Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::to(['/order-report/faktur-reguler']), ['class' => 'btn btn-danger']);
    //     }
    //     if (Helper::checkRoute('/report-list/report-reguler')) {
    //         $create .=  Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::to(['/report-list/report-reguler']), ['class' => 'btn btn-orange']);
    //     }
    // }

    // $create .= Html::a('<i class="glyphicon glyphicon-list-alt"></i> Compare', Url::to(['compare']), ['class' => 'btn btn-purple', 'title' => 'Compare SO']);
    // if (Yii::$app->user->identity->cabang == 1) {
    //     $create .=  Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::to(['list-apm']), ['class' => 'btn btn-pink', 'title' => 'List Transaksi Apotek']);
    //     $create .=  Html::a('<i class="glyphicon glyphicon-list-alt"></i>', Url::to(['list-sebagian']), ['class' => 'btn btn-purple', 'title' => 'List SO Detail Sebagian']);
    // }
    ?>

    <?= MdcWidget::gridList($modul, [
        'dataProvider' => $dataProvider,
        'searchModel'  => $searchModel,
        'button'       => $create
    ]) ?>

</div>

<?=
// modal transfer so
Yii::$app->controller->renderPartial('@common/components/template/salesorder/modalCekSync');
?>
<?=
// modal transfer so
Yii::$app->controller->renderPartial('@common/components/template/salesorder/modalTransferSO');
?>

<?=
// modal update pembayaran
Yii::$app->controller->renderPartial('@common/components/template/salesorder/modalUpdatePembayaran', [
    'model' => $model,
]);
?>
<?=
// modal batal SO
Yii::$app->controller->renderPartial('@common/components/template/salesorder/modalBatalSO');
?>

<script>
    // Url Sections
    var urlVirtualAccount = "<?= Url::to(['generate']) ?>";
    var urlGopay = "<?= Url::to(['request-midtrans']) ?>";
    var urlSync = "<?= Url::to(['log-sync']) ?>";
    var urlTransfer = "<?= Url::to(['transfer']) ?>";
    var urlClose = "<?= Url::to(['close']) ?>";
</script>