<?php
$botoes = (User::canUpdate()) ? '{view} {update}' : '{view}';

    if (User::isAdmin()) {
        $botoes .= ' {delete}';
    }
    ?>
    <div id="div-endereco-cobranca">
        <h1>Endereço de Cobrança &raquo; <?php echo $nomeCliente; ?></h1>
        <div class="portlet" id="yw4">
            <div class="portlet-content">
                <ul id="yw5">
                    <li><a href="<?php echo Yii::app()->request->baseUrl ?>/index.php?r=enderecos/create&CLI_IDCLIENTE=<?php echo $model->CLI_IDCLIENTE; ?>"><?php echo FaHtml::iconNovo(); ?></a></li>
                </ul></div>
            </div>
            <br /><br />
            <?php
            $criteria = new CDbCriteria();
            $criteria->compare('END_IDCLIENTE', $model->CLI_IDCLIENTE);
            $dataProvider = new CActiveDataProvider('Enderecos', array(
                'criteria' => $criteria,
                'sort' => array(
                    'defaultOrder' => 'END_DESCRICAO ASC',
                    ),
                ));

            $this->widget('ext.Utils.widgets.CrmGridView', array(
                'id' => 'enderecos-grid',
                'dataProvider' => $dataProvider,
                'selectableRows' => 1,
                'afterAjaxUpdate'=>'updated',
                'selectionChanged' => 'function(id){ location.href = "' . Yii::app()->createUrl('enderecos/view') . '&id="+$.fn.yiiGridView.getSelection(id);}',
                'columns' => array(
                    'END_DESCRICAO',
                    'END_COMPLEMENTO',
                    'END_BAIRRO',
                    'END_CEP',
                    array(
                        'name' => 'END_IDCIDADE',
                        'value' => 'Util::getCidadeEstado($data->END_IDCIDADE)',
                        ),
                    array(
                        'name' => 'END_TIPO',
                        'value' => '$data->END_TIPO == "E" ? "Entrega" : "Cobrança"',
                        ),
                    'END_PONTOREFERENCIA',
                    array(
                        'class' => 'CButtonColumn',
                        'template' => $botoes,
                        'buttons' => array(
                            'view' => array(
                                'label' => 'Exibir',
                                'url' => 'Yii::app()->createUrl("enderecos/view", array("id"=>$data->END_IDENDERECO))',
                                ),
                            'update' => array(
                                'label' => 'Editar',
                                'url' => 'Yii::app()->createUrl("enderecos/update", array("id"=>$data->END_IDENDERECO))',
                                ),
                            'delete' => array(
                                'label' => 'Editar',
                                'url' => 'Yii::app()->createUrl("enderecos/delete", array("id"=>$data->END_IDENDERECO))',
                                ),
                            ),
                        ),
                    ),
)
            );
?>
</div>