<?php

use yii\helpers\Html;
use yii\grid\GridView;
use kartik\export\ExportMenu;
use kartik\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $searchModel app\models\ClienteLineasSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Ventas PDV';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="clientes-index">   
    <div class="box box-default collapsed-box">
    <!--<div class="box box-default">-->
        <div class="box-header with-border">
            <h3 class="box-title">Filtrar</h3>
            <div class="box-tools pull-right">
                <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-plus"></i></button>
            </div><!-- /.box-tools -->
        </div><!-- /.box-header -->
        <div class="box-body" style="display: none;">
        <!--<div class="box-body" >-->
            <?php
            $form = ActiveForm::begin([
                        'action' => ['index'],
                        'method' => 'GET',
            ]);
            echo $this->render('_search', ['model' => $searchModel, 'form' => $form]);
            echo '<div class="box-footer">
                    <button type="submit" class="btn btn-primary">Submit</button>
                  </div>';
            ActiveForm::end();
            ?>
        </div><!-- /.box-body -->
    </div>
</div>
<div class="PDV-index">
    <div class="box box-default">
        <div class="box-header with-border">
            <h3 class="box-title"><?= $this->title ?></h3>
            <div class="box-tools pull-right">
<?= Html::a('Registrar venta PDV', ['create'], ['class' => 'btn btn-success']) ?>
            </div>
        </div>
        <div class="box-body">
            <?php
            $gridColumns = [
                'id',
                [
                    'label' => 'Cliente',
                    //'attribute' => 'clientes.nombre',
                    'value' => function($model) {
                        $cliente = $model->getClientes()->one();
                        return ($cliente->nombre . " " . $cliente->apellidop . " " . $cliente->apellidom);
                    }
                ],
                'clientes.telefono',
                'clientes.dnref',
                //'clientes.email:email',
                'linea.icc',
                [
                    'attribute' => 'linea.producto_id',
                    'value' => function($model) {
                        $producto = $model->getLinea()->one()->getProducto()->one();
                        return $producto->producto;
                    }
                ],
                [
                    'attribute' => 'linea.monto_id',
                    'value' => function($model) {
                        $monto = $model->getLinea()->one()->getMonto()->one();
                        return $monto->monto;
                    }
                ],
                // 'modified',
                [
                    'attribute' => 'created_by',
                    'value' => function($model) {
                        $user = $model->getCreatedBy()->one();
                        return $user->username;
                    }
                ],
                [
                    'attribute' => 'created',
                    'value' => function($model) {
                        return date_create($model->created)->format('d-m-Y H:i:s');
                    }
                ],
                'pdv.idpdv',
                // 'created_by',
                // 'modified_by',  
                ['class' => 'yii\grid\ActionColumn'],
            ];

            $gridColumnsExport = [
                'id',
                'clientes.nombre',
                'clientes.apellidop',
                'clientes.apellidom',
                'clientes.telefono',
                'clientes.dnref',
                'clientes.email:email',
                [
                    'attribute' => 'linea.producto_id',
                    'value' => function($model) {
                        $producto = $model->getLinea()->one()->getProducto()->one();
                        return $producto->producto;
                    }
                ],
                'linea.icc',
                'linea.folio',
                [
                    'attribute' => 'linea.monto_id',
                    'value' => function($model) {
                        $monto = $model->getLinea()->one()->getMonto()->one();
                        return $monto->monto;
                    }
                ],
                'linea.folior',
                [
                    'attribute' => 'created_by',
                    'value' => function($model) {
                        $user = $model->getCreatedBy()->one();
                        return $user->username;
                    }
                ],
                [
                    'attribute' => 'created',
                    'value' => function($model) {
                        return date_create($model->created)->format('d-m-Y H:i:s');
                    }
                ],
                'pdv.idpdv',
                    // 'created_by',
                    // 'modified_by', 
            ];
            // Renders a export dropdown menu
            echo ExportMenu::widget([
                'dataProvider' => $dataProvider,
                'columns' => $gridColumnsExport,
                'target' => '_self',
                'filename' => 'registroPDV_' . date('d-m-Y His'),
                'exportConfig' => [
                    'HTML' => false,
                    'CSV' => false,
                    'TXT' => false,
                    'PDF' => false,
                    'Excel5' => false,
                ],
                'dropdownOptions' => [
                    'label' => 'Exportar',
                    'class' => 'btn btn-default',
                ],
                'columnSelectorOptions' => [
                    'label' => 'Columnas',
                    'class' => 'btn btn-default',
                ],
                    //'asDropdown'=> false
            ]);
            ?>
            <div class="box-body table-responsive no-padding">
                <?php
                echo GridView::widget([
                    'dataProvider' => $dataProvider,
                    'columns' => $gridColumns,
                ]);
                ?>
            </div>
        </div>
    </div>
</div>