<?php


/* @var $this yii\web\View */
/* @var $model app\models\RefierensSearch */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="refieren-search">
    <?php
    if (!\Yii::$app->user->can('isAdmin')) {
        echo $form->field($model, 'created_by')->dropDownList([Yii::$app->user->identity->id => Yii::$app->user->identity->agente], ['prompt' => '-Todos-']);
    } else {
        echo $form->field($model, 'created_by')->dropDownList(
                \yii\helpers\ArrayHelper::map(common\models\User::find()->all(), 'id', 'agente'), ['prompt' => '-Todos-']
        );
        echo $form->field($model, 'pdv_id')->dropDownList(
                \yii\helpers\ArrayHelper::map(app\models\Pdv::find()->all(), 'id', 'nombre'), ['prompt' => '-Todos-']
        );
    }
    echo $form->field($model, 'nombre')->label('Nombre de quien refiere o referido');
    echo $form->field($model, 'bono_id')->dropDownList(
            \yii\helpers\ArrayHelper::map(app\models\Bono::find()->all(), 'id', 'bono'), ['prompt' => '-Todos-']
    );
    echo $form->field($model, 'telefono')->textInput(['maxlength' => true])->widget(\yii\widgets\MaskedInput::className(), [
        'mask' => '999-999-9999',
    ]);
    ?>
</div>
<div class="salidas-search">
    <div class="info-box">
        <span class="info-box-icon bg-aqua"><i class="fa fa-calendar"></i></span>
        <div class="info-box-content">
            <span class="info-box-text">Meses</span>
            <button type="button" name="btnMonth" class="btn btn-info" value="0">Hoy</button>
            <button type="button" name="btnMonth" class="btn btn-info" value="1">1</button>
            <button type="button" name="btnMonth" class="btn btn-info" value="2">2</button>
            <button type="button" name="btnMonth" class="btn btn-info" value="3">3</button>
            <button type="button" name="btnMonth" class="btn btn-info" value="4">4</button>
            <button type="button" name="btnMonth" class="btn btn-info" value="5">5</button>
            <button type="button" name="btnMonth" class="btn btn-info" value="6">6</button>
        </div><!-- /.info-box-content -->
    </div>
    <label>Meses: </label>
    <?php
//echo date('Y-m-d', strtotime('-1 Month'));
    echo $form->field($model, 'from')->widget(\kartik\widgets\DatePicker::classname(), [
        'options' => ['placeholder' => 'Desde', 'value' => date('Y-m-d', strtotime('-1 Month')), 'id' => 'from'],
        'pluginOptions' => [
            'format' => 'yyyy-mm-dd',
            'autoclose' => true,
        ]
    ]);
//echo date('Y-m-d', strtotime('-1 Day'));
    echo $form->field($model, 'to')->widget(\kartik\widgets\DatePicker::classname(), [
        'options' => ['placeholder' => 'Hasta', 'value' => date('Y-m-d', strtotime('-1 Day')), 'id' => 'to'],
        'pluginOptions' => [
            'format' => 'yyyy-mm-dd',
            'autoclose' => true,
        ]
    ]);
    ?>
</div>
<?php
$this->registerJs('$(".btn.btn-info").click(function () {
        switch (this.value) {
            case "0":
                $("#from").val("' . date("Y-m-d") . '");
                break
            case "1":
                $("#from").val("' . date("Y-m-d", strtotime("-1 Month, +1 Day")) . '");
                break
            case "2":
                $("#from").val("' . date("Y-m-d", strtotime("-2 Month, +1 Day")) . '");
                break
            case "3":
                $("#from").val("' . date("Y-m-d", strtotime("-3 Month, +1 Day")) . '");
                break
            case "4":
                $("#from").val("' . date("Y-m-d", strtotime("-4 Month, +1 Day")) . '");
                break
            case "5":
                $("#from").val("' . date("Y-m-d", strtotime("-5 Month, +1 Day")) . '");
                break
            case "6":
                $("#from").val("' . date("Y-m-d", strtotime("-6 Month, +1 Day")) . '");
                break
        }
        $("#to").val("' . date("Y-m-d") . '");
    });', \yii\web\View::POS_READY);
?>