/**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Departamento'])) {
         $model->attributes = $_POST['Departamento'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $propiedades = Propiedad::model()->findAll(array('select' => 'id,nombre'));
     $this->render('update', array('model' => $model, 'propiedades' => $propiedades));
 }
示例#2
0
    <div class="span12" id="deptos">
        <span><big>¿En qué departamentos va a ejecutar la Prestación?</big></span>
            <?php 
$this->widget('ext.selgridview.SelGridView', array('id' => 'departamentos-grid', 'filter' => $departamentos, 'dataProvider' => $departamentos->searchChb(), 'selectableRows' => 2, 'columns' => array(array('class' => 'CCheckBoxColumn', 'checked' => '$data["id"]', 'checkBoxHtmlOptions' => array('name' => 'chbDepartamentoId[]'), 'value' => '$data->id'), array('name' => 'propiedad_nombre', 'value' => '$data->propiedad->nombre'), 'numero', 'mt2', 'dormitorios', 'estacionamientos', 'renta')));
?>
        <span class="note">Solo los departamentos que estén seleccionados quedarán asociados a la prestación.</span>
        
    </div>
    <div class="span12" id="propiedad">
        <div class="span10">
        <span><big>¿En qué propiedad va a ejecutar la Prestación?</big></span><br/><br/>
        </div>
        <div class="clearfix"></div>
        <div class="span4">
            <?php 
echo $form->dropDownList($model, 'propiedad_id', CHtml::listData(Propiedad::model()->getDeUsuario(Yii::app()->user->id), 'id', 'nombre'), array('prompt' => 'Seleccione Propiedad'));
?>
            <?php 
echo $form->error($model, 'propiedad_id');
?>
        </div>
    </div>
    <div class="clearfix"></div>
    <br/>
    <div class="span2">
            <?php 
echo CHtml::submitButton('Guardar', array('class' => 'btn'));
?>
    </div>
<br/>
<?php 
示例#3
0
 public function estaAsociadoPropietario($user_id, $propiedad_id)
 {
     $propietario_id = Propietario::model()->getId($user_id);
     $response = Propiedad::model()->exists(array('condition' => 'propietario_id=:propietarioID AND t.id=:propiedadID', 'params' => array(':propietarioID' => $propietario_id, ':propiedadID' => $propiedad_id)));
     return $response;
 }
示例#4
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id the ID of the model to be updated
  */
 public function actionUpdate($id)
 {
     $model = $this->loadModel($id);
     $model->fecha = Tools::backFecha($model->fecha);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Egreso'])) {
         $model->attributes = $_POST['Egreso'];
         $model->fecha = Tools::fixFecha($model->fecha);
         $propiedad = null;
         if ($model->centroCosto != null) {
             $ok = $model->validate();
             if ($model->centroCosto->carga_a == '1') {
                 $propiedad = Propiedad::model()->findByPk($model->propiedad_id);
                 if ($propiedad == null) {
                     $model->addError("propiedad_id", "Propiedad no puede ser nulo.");
                     $ok = false;
                 }
             }
             if ($ok) {
                 if ($model->save()) {
                     EgresoPropiedad::model()->deleteAllByAttributes(array('egreso_id' => $model->id));
                     if ($model->centroCosto->carga_a == '1') {
                         $egPro = new EgresoPropiedad();
                         $egPro->egreso_id = $model->id;
                         $egPro->propiedad_id = $model->propiedad_id;
                         $egPro->save();
                     }
                     if ($model->centroCosto->carga_a == '2') {
                         if (isset($_POST['chbDepartamentoId'])) {
                             $cant_deptos = count($_POST['chbDepartamentoId']);
                             if ($cant_deptos > 0) {
                                 EgresoDepartamento::model()->deleteAllByAttributes(array('egreso_id' => $model->id));
                                 foreach ($_POST['chbDepartamentoId'] as $i => $departamento) {
                                     $egDpto = new EgresoDepartamento();
                                     $egDpto->departamento_id = $departamento;
                                     $egDpto->egreso_id = $model->id;
                                     if ($egDpto->validate()) {
                                         $egDpto->save();
                                     }
                                 }
                             }
                         }
                     }
                     $this->redirect(array('admin'));
                 } else {
                     Yii::app()->user->setFlash('error', CHtml::errorSummary($model));
                 }
             } else {
                 Yii::app()->user->setFlash('error', CHtml::errorSummary($model));
             }
         } else {
             Yii::app()->user->setFlash('error', 'ERROR: Centro de costo no puede ser nulo.');
         }
         $model->fecha = Tools::backFecha($model->fecha);
     }
     $conceptos = ConceptoPredefinido::model()->findAll();
     $cptos = array();
     foreach ($conceptos as $concepto) {
         $cptos[] = $concepto->nombre;
     }
     $deptos = new Departamento('search');
     $deptos->unsetAttributes();
     if (isset($_GET['Departamento'])) {
         $deptos->attributes = $_GET['Departamento'];
     }
     $this->render('update', array('model' => $model, 'conceptos' => $cptos, 'departamentos' => $deptos));
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $this->layout = "column1";
     $ultimoContrato = Contrato::model()->findAll(array('order' => 'folio DESC'));
     $ultimoFolio = 0;
     if ($ultimoContrato != null) {
         $ultimoFolio = (int) $ultimoContrato[0]->folio;
     }
     $folio = $ultimoFolio + 1;
     // @todo: cambiar el modelo y el formulario para contratos de 1,2,3,4,5,6 meses o indefinido
     // @todo: Impedir la creación de contratos para deptos que ya tienen
     $model = new Contrato();
     $model->folio = $folio;
     $model->dia_pago = 1;
     $model->fecha_inicio = date('d/m/Y');
     $cuentaModel = new CuentaCorriente();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $valid = false;
     if (isset($_POST['Contrato'])) {
         // generando cuenta corriente asociada al contrato
         $model->attributes = $_POST['Contrato'];
         $model->monto_gastovariable = $_POST['Contrato']['monto_gastovariable'];
         $model->monto_mueble = $_POST['Contrato']['monto_mueble'];
         $model->monto_primer_mes = $_POST['Contrato']['monto_primer_mes'];
         $model->dias_primer_mes = $_POST['Contrato']['dias_primer_mes'];
         $model->monto_cheque = $_POST['Contrato']['monto_cheque'];
         $model->monto_castigado = $_POST['Contrato']['monto_castigado'];
         $model->reajusta_meses = $_POST['Contrato']['reajusta_meses'];
         $model->dia_pago = $_POST['Contrato']['dia_pago'];
         $model->fecha_inicio = Tools::fixFecha($model->fecha_inicio);
         $model->vigente = 1;
         $model->reajusta = 1;
         $valid = $model->validate();
         if ($valid) {
             $cuentaModel->attributes = $_POST['CuentaCorriente'];
             $cliente = $model->cliente;
             $departamento = $model->departamento;
             $cuentaModel->nombre = str_replace("-", "", $cliente->rut) . "-" . $departamento->propiedad->nombre . " (Depto." . $departamento->numero . ")";
             $model->save(FALSE);
             $cuentaModel->contrato_id = $model->id;
             $valid = $valid && $cuentaModel->validate();
             if ($valid) {
                 $cuentaModel->save(FALSE);
                 if ($valid) {
                     $model->crearDeudaMes(date('Y-m-d'));
                     $usuario = $cliente->usuario;
                     $propiedad = $departamento->propiedad;
                     //una vez que está creado el contrato, guardar la copia del docx
                     $this->doccy->newFile($model->tipo_contrato_id . '.docx');
                     $this->doccy->phpdocx->assignToHeader("", "");
                     $this->doccy->phpdocx->assignToFooter("", "");
                     $this->doccy->phpdocx->assign("#CONTRATO_FOLIO#", $model->folio);
                     $this->doccy->phpdocx->assign("#CONTRATO_FECHA_INICIO#", Tools::backFecha($model->fecha_inicio));
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_RENTA#", Tools::formateaPlata($model->monto_renta));
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_GASTO_COMUN#", Tools::formateaPlata($model->monto_gastocomun));
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_PRIMER_MES#", Tools::formateaPlata($model->monto_primer_mes));
                     $this->doccy->phpdocx->assign("#CONTRATO_DIAS_PRIMER_MES#", $model->dias_primer_mes);
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_CHEQUE#", Tools::formateaPlata($model->monto_cheque));
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_CASTIGADO#", Tools::formateaPlata($model->monto_castigado));
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_MUEBLE#", Tools::formateaPlata($model->monto_mueble));
                     $this->doccy->phpdocx->assign("#CONTRATO_MONTO_GASTO_VARIABLE#", Tools::formateaPlata($model->monto_gastovariable));
                     $this->doccy->phpdocx->assign("#CONTRATO_REAJUSTA_MESES#", $model->reajusta_meses);
                     $this->doccy->phpdocx->assign("#CONTRATO_DIA_PAGO#", $model->dia_pago);
                     $this->doccy->phpdocx->assign("#CONTRATO_PLAZO#", $model->plazo);
                     $this->doccy->phpdocx->assign("#CLIENTE_RUT#", $cliente->rut);
                     $this->doccy->phpdocx->assign("#CLIENTE_NOMBRE#", $usuario->nombre);
                     $this->doccy->phpdocx->assign("#CLIENTE_APELLIDO#", $usuario->apellido);
                     $this->doccy->phpdocx->assign("#CLIENTE_EMAIL#", $usuario->email);
                     $this->doccy->phpdocx->assign("#CLIENTE_DIRECCION#", $cliente->direccion_alternativa);
                     $this->doccy->phpdocx->assign("#CLIENTE_TELEFONO#", $cliente->telefono);
                     $this->doccy->phpdocx->assign("#CLIENTE_OCUPACION#", $cliente->ocupacion);
                     $this->doccy->phpdocx->assign("#CLIENTE_RENTA#", Tools::formateaPlata($cliente->renta));
                     $this->doccy->phpdocx->assign("#PROPIEDAD_NOMBRE#", $propiedad->nombre);
                     $this->doccy->phpdocx->assign("#PROPIEDAD_DIRECCION#", $propiedad->direccion);
                     $this->doccy->phpdocx->assign("#DEPARTAMENTO_NUMERO#", $departamento->numero);
                     $this->doccy->phpdocx->assign("#DEPARTAMENTO_MT2#", $departamento->mt2);
                     $this->doccy->phpdocx->assign("#DEPARTAMENTO_DORMITORIOS#", $departamento->dormitorios);
                     $this->doccy->phpdocx->assign("#DEPARTAMENTO_ESTACIONAMIENTOS#", $departamento->estacionamientos);
                     $this->doccy->phpdocx->assign("#DEPARTAMENTO_RENTA#", Tools::formateaPlata($departamento->renta));
                     $this->renderDocx("Contrato_" . $model->folio . ".docx", false);
                     $this->redirect(array('admin'));
                 } else {
                     $model->delete();
                     $cuentaModel->delete();
                     $model->addError('id', 'No fue posible crear la cuenta asociada al contrato. Intente nuevamente');
                 }
             } else {
                 $model->delete();
             }
         }
         if (!$valid) {
             $model->fecha_inicio = Tools::backFecha($model->fecha_inicio);
         }
     }
     //$departamentos = Departamento::model()->getListWithoutContract();
     $propiedades = Propiedad::model()->findAll();
     $clientes = Cliente::model()->getList();
     $tiposContrato = TipoContrato::model()->getList();
     $this->render('create', array('model' => $model, 'ctaModel' => $cuentaModel, 'propiedades' => $propiedades, 'clientes' => $clientes, 'tiposContrato' => $tiposContrato));
 }
示例#6
0
echo $form->labelEx($model, 'fecha_compra');
?>
		<?php 
$this->widget('zii.widgets.jui.CJuiDatePicker', array('model' => $model, 'attribute' => 'fecha_compra', 'language' => 'es', 'htmlOptions' => array('id' => 'datepicker_for_fecha', 'size' => '10', 'maxlength' => '10', 'value' => $fecha, 'readonly' => 'readonly'), 'defaultOptions' => array('showOn' => 'focus', 'dateFormat' => 'dd/mm/yy', 'showOtherMonths' => true, 'selectOtherMonths' => true, 'changeMonth' => true, 'changeYear' => true, 'showButtonPanel' => true)));
?>
		<?php 
echo $form->error($model, 'fecha_compra');
?>
	</div>
    
        <div class="row">
            <?php 
echo $form->labelEx($model, 'propiedad_id');
?>
            <?php 
echo $form->dropDownList($model, 'propiedad_id', CHtml::listData(Propiedad::model()->getDeUsuario(Yii::app()->user->id), 'id', 'nombre'), array('ajax' => array('type' => 'POST', 'url' => CController::createUrl('//propiedad/getDepartamentosAll'), 'update' => '#departamento_id'), 'prompt' => 'Seleccione una Propiedad'));
?>
            <?php 
echo $form->error($model, 'propiedad_id');
?>
        </div>
        <div class="row">
            <?php 
echo $form->labelEx($model, 'departamento_id');
?>
            <?php 
if ($model->isNewRecord) {
    ?>
            <?php 
    echo $form->dropDownList($model, 'departamento_id', array(), array('prompt' => 'Seleccione un departamento', 'id' => 'departamento_id'));
    ?>
示例#7
0
 public function relacionadosConPropietario($propietario_id)
 {
     $clientes = array();
     $propiedades = Propiedad::model()->findAllByAttributes(array('propietario_id' => $propietario_id));
     foreach ($propiedades as $propiedad) {
         $departamentos = $propiedad->departamentos;
         foreach ($departamentos as $departamento) {
             $contrato = $departamento->contrato;
             if (isset($contrato->cliente_id)) {
                 $cliente_id = $contrato->cliente_id;
                 $clientes[] = $cliente_id;
             }
         }
     }
     return $clientes;
 }
示例#8
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Propiedad the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Propiedad::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
示例#9
0
文件: intra.php 项目: aetexd/sun
?>
</h3>
                  <p>Clientes</p>
                </div>
                <div class="icon">
                  <i class="fa fa-users"></i>
                </div>
                <a href="?r=cliente/create" class="small-box-footer">Nuevos Clientes<i class="fa fa-arrow-circle-right"></i></a>
              </div>
            </div><!-- ./col -->
            <div class="col-lg-3 col-xs-6">
              <!-- small box -->
              <div class="small-box bg-green">
                <div class="inner">
                    <h3><?php 
echo Propiedad::model()->count();
?>
</h3>
                  <p>Propiedades</p>
                </div>
                <div class="icon">
                  <i class="fa fa-home"></i>
                </div>
                <a href="?r=propiedad/index" class="small-box-footer">Nuevas Propiedades <i class="fa fa-arrow-circle-right"></i></a>
              </div>
            </div><!-- ./col -->
            <div class="col-lg-3 col-xs-6">
              <!-- small box -->
              <div class="small-box bg-yellow">
                <div class="inner">
                  <h3>5</h3>
示例#10
0
 public function actionExportarXLS()
 {
     // generate a resultset
     $data = Propiedad::model()->with('propietario')->findAll();
     $this->toExcel($data, array('propietario.rut', 'nombre', 'direccion', 'mt_construidos', 'mt_terreno', 'cant_estacionamientos', 'inscripcion'), 'Propiedades', array());
 }
 public function actionIngresosCliente()
 {
     $model = new IngresosClienteForm();
     $propiedades = Propiedad::model()->getDeUsuario(Yii::app()->user->id);
     $meses = array();
     for ($i = 1; $i <= 12; $i++) {
         $meses[] = array('id' => str_pad($i, 2, "0", STR_PAD_LEFT), 'nombre' => Tools::fixMes($i));
     }
     $agnos = array();
     $agnoInicio = 2000;
     $agnoFin = (int) date('Y') + 10;
     for ($i = $agnoInicio; $i < $agnoFin; $i++) {
         $agnos[] = array('id' => $i, 'nombre' => $i);
     }
     $model->agnoH = date('Y');
     $model->mesH = date('m');
     if ($model->mesH == '01') {
         $model->mesD = '12';
         $model->agnoD = (int) $model->agnoH - 1;
     } else {
         $mes = (int) $model->mesH;
         $model->mesD = str_pad($mes - 1, 2, "0", STR_PAD_LEFT);
         $model->agnoD = $model->agnoH;
     }
     if (isset($_POST['IngresosClienteForm'])) {
         $model->attributes = $_POST['IngresosClienteForm'];
         Yii::import('ext.phpexcel.XPHPExcel');
         $objPHPExcel = XPHPExcel::createPHPExcel();
         $sheet = $objPHPExcel->getActiveSheet();
         $sheet->setCellValue('A1', 'Planilla de Ingresos de Cliente');
         $sheet->mergeCells("A1:K1");
         $sheet->getStyle("A1")->getFont()->setSize(20);
         $sheet->setCellValue('A2', 'Rango de Fechas: Desde ' . Tools::fixMes($model->mesD) . " de " . $model->agnoD . " hasta " . Tools::fixMes($model->mesH) . " de " . $model->agnoH);
         $sheet->mergeCells("A2:K2");
         $sheet->getStyle("A2")->getFont()->setSize(15);
         $i = 4;
         $sheet->setCellValue('A' . $i, 'Fecha');
         $sheet->setCellValue('B' . $i, 'Propiedad');
         $sheet->setCellValue('C' . $i, 'Departamento');
         $sheet->setCellValue('D' . $i, 'Nombre');
         $sheet->setCellValue('E' . $i, 'Monto');
         $sheet->getStyleByColumnAndRow(0, $i, 4, $i)->getFont()->setBold(true);
         $fDesde = $model->agnoD . "-" . str_pad($model->mesD, 2, "0", STR_PAD_LEFT) . "-01";
         $fHasta = $model->agnoH . "-" . str_pad($model->mesH, 2, "0", STR_PAD_LEFT) . "-01";
         $i++;
         $movimientos = Movimiento::model()->getIngresosDePropietarioEntreFechas(Yii::app()->user->id, $fDesde, $fHasta);
         foreach ($movimientos as $movimiento) {
             $sheet->setCellValue('A' . $i, Tools::backFecha($movimiento->fecha));
             $sheet->setCellValue('B' . $i, $movimiento->cuentaCorriente->contrato->departamento->propiedad->nombre);
             $sheet->setCellValue('C' . $i, $movimiento->cuentaCorriente->contrato->departamento->numero);
             $sheet->setCellValue('D' . $i, $movimiento->cuentaCorriente->contrato->cliente->usuario->nombre . " " . $movimiento->cuentaCorriente->contrato->cliente->usuario->apellido . " (" . $movimiento->cuentaCorriente->contrato->cliente->rut . ")");
             $sheet->setCellValue('E' . $i, $movimiento->monto);
             $i++;
         }
         /*                $meses = Tools::arregloMeses($model->mesD, $model->agnoD, $model->mesH, $model->agnoH);
         
                     $sheet->getStyleByColumnAndRow(0,$i)->getFont()->setBold(true);
                     $j = 2;
                     if($model->abonosYCargos){
                         $j = 1;
                     }
                     foreach($meses as $mesArr){
                         $sheet->setCellValueByColumnAndRow($j, $i, $mesArr['mesNombre']." de ".$mesArr['agno']);
                         $sheet->getStyleByColumnAndRow($j,$i)->getFont()->setBold(true);
                         $j++;
                     }
                     $i++;
         
                     $departamentos = Departamento::model()->findAllByAttributes(array('propiedad_id'=>$propiedad->id));
                     foreach($departamentos as $departamento){
                         $j=0;
                         $sheet->setCellValueByColumnAndRow($j,$i, $departamento->numero);
                         $sheet->getStyleByColumnAndRow($j,$i)->getFont()->setBold(true);
                         if($model->abonosYCargos){
                             $j++;
                             $sheet->setCellValueByColumnAndRow($j, $i, "Cargos");
                             $sheet->setCellValueByColumnAndRow($j, $i+1, "Abonos");
                             $sheet->getStyleByColumnAndRow($j,$i,$j,$i+1)->getFont()->setBold(true);
                             $j++;
                         }
                         else{
                             $j = 1;
                         }
                         if($departamento->contrato != null){
                             if($departamento->contrato->cuentaCorriente != null){
                                 foreach($meses as $mesArr){
                                     $saldoMes = $departamento->contrato->cuentaCorriente->saldoMes($mesArr['mes'],$mesArr['agno']);
                                     if($model->abonosYCargos){
                                         $sheet->setCellValueByColumnAndRow($j, $i, $saldoMes['cargos']);
                                         $sheet->setCellValueByColumnAndRow($j, $i+1, $saldoMes['abonos']);
                                     }
                                     else{
                                         $sheet->setCellValueByColumnAndRow($j, $i, $saldoMes['abonos']);
                                     }
                                     $j++;
                                 }
                             }
                         }
                         if($model->abonosYCargos){
                             $i+=2;
                         }
                         else{
                             $i++;
                         }
                     }
         * 
         * 
         */
         $objPHPExcel->setActiveSheetIndex(0);
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment;filename="Movimientos Cliente.xls"');
         header('Cache-Control: max-age=0');
         // If you're serving to IE 9, then the following may be needed
         header('Cache-Control: max-age=1');
         // If you're serving to IE over SSL, then the following may be needed
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         // Date in the past
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         // always modified
         header('Cache-Control: cache, must-revalidate');
         // HTTP/1.1
         header('Pragma: public');
         // HTTP/1.0
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         $objWriter->save('php://output');
         Yii::app()->end();
     }
     $this->render('ingresosCliente', array('model' => $model, 'meses' => $meses, 'agnos' => $agnos, 'propiedades' => $propiedades));
 }
 public function actionInforme()
 {
     $form = new InformeForm();
     if (isset($_POST['InformeForm'])) {
         $form->attributes = $_POST['InformeForm'];
         Yii::import('ext.phpexcel.XPHPExcel');
         $objPHPExcel = XPHPExcel::createPHPExcel();
         $sheet = $objPHPExcel->getActiveSheet();
         $styleCenter = array('alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));
         $sheet->setCellValue('A1', 'Informe de Movimientos de Propietario');
         $sheet->getStyle("A1")->getFont()->setSize(20);
         $sheet->setCellValue('A2', 'Desde: ' . $form->fechaDesde . ' Hasta: ' . $form->fechaHasta);
         $sheet->getStyle("A2")->getFont()->setSize(16);
         $fechaDesdeArr = explode('-', $form->fechaDesde);
         if (count($fechaDesdeArr) == 3) {
             $mesInicio = $fechaDesdeArr[1];
             $agnoInicio = $fechaDesdeArr[0];
         } else {
             $mesInicio = date('m');
             $agnoInicio = date('Y');
             $form->fechaDesde = date('Y-m-d');
         }
         $fechaHastaArr = explode('-', $form->fechaHasta);
         if (count($fechaHastaArr) == 3) {
             $mesFin = $fechaHastaArr[1];
             $agnoFin = $fechaHastaArr[0];
         } else {
             $mesFin = date('m');
             $agnoFin = date('Y');
             $form->fechaHasta = date('Y-m-d');
         }
         $meses = Tools::arregloMeses($mesInicio, $agnoInicio, $mesFin, $agnoFin);
         $propietario_id = Propietario::model()->getId(Yii::app()->user->id);
         $propietario = Propietario::model()->findByPk($propietario_id);
         $propiedades = Propiedad::model()->findAllByAttributes(array('propietario_id' => $propietario_id));
         $row = 4;
         foreach ($propiedades as $propiedad) {
             $sheet->setCellValueByColumnAndRow(0, $row, "PROPIEDAD: " . $propiedad->nombre);
             $row++;
             foreach ($propiedad->departamentos as $departamento) {
                 if ($departamento->contrato != null) {
                     $rmax = 0;
                     $sheet->setCellValueByColumnAndRow(0, $row, "Departamento: " . $departamento->numero . ", Contrato: " . $departamento->contrato->folio . ", Arrendatario: " . $departamento->contrato->cliente->rut . " " . $departamento->contrato->cliente->usuario->nombre . " " . $departamento->contrato->cliente->usuario->apellido);
                     $row++;
                     $sheet->setCellValueByColumnAndRow(0, $row, "Movimientos de la cuenta");
                     $col = 0;
                     $cuentaCorriente = $departamento->contrato->cuentaCorriente;
                     $saldo = 0;
                     foreach ($meses as $mesArreglo) {
                         $nDias = cal_days_in_month(CAL_GREGORIAN, $mesArreglo['mes'], $mesArreglo['agno']);
                         $sheet->mergeCellsByColumnAndRow($col, $row, $col + 1, $row);
                         $sheet->getStyleByColumnAndRow($col, $row)->applyFromArray($styleCenter);
                         $sheet->setCellValueByColumnAndRow($col, $row, $mesArreglo['mesNombre'] . " " . $mesArreglo['agno']);
                         $sheet->setCellValueByColumnAndRow($col, $row + 1, Tools::MOVIMIENTO_TIPO_ABONO);
                         $sheet->setCellValueByColumnAndRow($col + 1, $row + 1, Tools::MOVIMIENTO_TIPO_CARGO);
                         $movimientos = Movimiento::model()->findAll(array('condition' => 'fecha >= :fIni and fecha <= :fFin and cuenta_corriente_id = :cta', 'params' => array(':fIni' => $mesArreglo['agno'] . "-" . $mesArreglo['mes'] . "-01", ':fFin' => $mesArreglo['agno'] . "-" . $mesArreglo['mes'] . "-" . $nDias, ':cta' => $cuentaCorriente->id)));
                         if (count($movimientos) > $rmax) {
                             $rmax = count($movimientos);
                         }
                         $iMov = 0;
                         while ($iMov < count($movimientos)) {
                             $movimiento = $movimientos[$iMov];
                             if ($movimiento->tipo == Tools::MOVIMIENTO_TIPO_ABONO) {
                                 if ($movimiento->validado == 1) {
                                     $sheet->setCellValueByColumnAndRow($col, $row + 2 + $iMov, $movimiento->monto);
                                     $saldo += $movimiento->monto;
                                 }
                             }
                             if ($movimiento->tipo == Tools::MOVIMIENTO_TIPO_CARGO) {
                                 $sheet->setCellValueByColumnAndRow($col + 1, $row + 2 + $iMov, $movimiento->monto);
                                 $saldo -= $movimiento->monto;
                             }
                             $iMov++;
                         }
                         $sheet->mergeCellsByColumnAndRow($col, $row + 2 + $iMov, $col + 1, $row + 2 + $iMov);
                         $sheet->setCellValueByColumnAndRow($col, $row + 2 + $iMov, $saldo);
                         $sheet->getStyleByColumnAndRow($col, $row + 2 + $iMov)->applyFromArray($styleCenter);
                         if ($saldo < 0) {
                             $sheet->getStyleByColumnAndRow($col, $row + 2 + $iMov)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'FF0000'))));
                         } else {
                             $sheet->getStyleByColumnAndRow($col, $row + 2 + $iMov)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => '0000FF'))));
                         }
                         $col += 2;
                     }
                     $row += $rmax + 1;
                 }
             }
             $row += 3;
         }
         // Set active sheet index to the first sheet, so Excel opens this as the first sheet
         $objPHPExcel->setActiveSheetIndex(0);
         header('Content-Type: application/vnd.ms-excel');
         header('Content-Disposition: attachment;filename="Movimientos Propietario ' . $propietario->usuario->nombre . ' ' . $propietario->usuario->apellido . '.xls"');
         header('Cache-Control: max-age=0');
         // If you're serving to IE 9, then the following may be needed
         header('Cache-Control: max-age=1');
         // If you're serving to IE over SSL, then the following may be needed
         header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
         // Date in the past
         header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
         // always modified
         header('Cache-Control: cache, must-revalidate');
         // HTTP/1.1
         header('Pragma: public');
         // HTTP/1.0
         $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
         $objWriter->save('php://output');
         Yii::app()->end();
     } else {
         $form->fechaHasta = date('Y-m-d');
     }
     $this->render('informe', array('model' => $form));
 }
示例#13
0
<?php

/* @var $this PrestacionController */
/* @var $model Prestacion */
$this->breadcrumbs = array('Prestaciones' => array('admin'), 'Prestación #' . $model->id);
$this->menu = array(array('label' => 'Crear Prestación', 'url' => array('create')), array('label' => 'Editar Prestación', 'url' => array('update', 'id' => $model->id)), array('label' => 'Eliminar Prestación', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Seguro quiere eliminar esta prestación?')), array('label' => 'Administrar Prestaciones', 'url' => array('admin')));
?>

<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array(array('name' => 'fecha', 'value' => Tools::backFecha($model->fecha)), array('name' => 'propiedad', 'value' => $model->propiedad_id != null ? Propiedad::model()->findByPk($model->propiedad_id)->nombre : '', 'visible' => $model->propiedad_id != null), 'monto', 'documento', 'descripcion', array('name' => 'tipo_prestacion_nombre', 'value' => $model->tipoPrestacion->nombre), array('name' => 'ejecutor', 'value' => $model->ejecutor->nombre), array('name' => 'genera_cargos', 'value' => Tools::backGeneraCargos($model->genera_cargos)), array('name' => 'general_prop', 'value' => Tools::backGeneraCargos($model->general_prop)))));
?>

<fieldset>
    <legend>Departamentos en los que se ejecutó la prestación</legend>
    <?php 
$this->widget('zii.widgets.grid.CGridView', array('id' => 'departamentos-grid', 'dataProvider' => $departamentos, 'columns' => array(array('name' => 'propiedad_nombre', 'value' => '$data->propiedad->nombre'), 'numero', 'mt2', 'dormitorios', 'estacionamientos', 'renta')));
?>
</fieldset>

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $deptos = new Departamento('search');
     $deptos->unsetAttributes();
     if (isset($_GET['Departamento'])) {
         $deptos->attributes = $_GET['Departamento'];
     }
     $model = new Prestacion();
     $model->fecha = date('d/m/Y');
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Prestacion'])) {
         $model->attributes = $_POST['Prestacion'];
         $model->fecha = Tools::fixFecha($model->fecha);
         $ok = true;
         $propiedad = null;
         if ($model->general_prop) {
             $propiedad = Propiedad::model()->findByPk($model->propiedad_id);
             if ($propiedad == null) {
                 $ok = false;
             }
         }
         if ($ok) {
             if ($model->save()) {
                 if ($model->general_prop != "1") {
                     if (isset($_POST['chbDepartamentoId'])) {
                         $cant_deptos = count($_POST['chbDepartamentoId']);
                         if ($cant_deptos > 0) {
                             $monto = (int) $model->monto / $cant_deptos;
                             foreach ($_POST['chbDepartamentoId'] as $i => $departamento) {
                                 $prest_depto = new PrestacionADepartamento();
                                 $prest_depto->departamento_id = $departamento;
                                 $prest_depto->prestacion_id = $model->id;
                                 if ($prest_depto->validate()) {
                                     $prest_depto->save();
                                 }
                                 if ($model->genera_cargos == "1") {
                                     //se crean los cargos para el depto
                                     $cargo = new Movimiento();
                                     $depto = Departamento::model()->findByPk($departamento);
                                     if ($depto->contrato != null) {
                                         if ($depto->contrato->vigente) {
                                             $cargo->cuenta_corriente_id = $depto->contrato->cuentaCorriente->id;
                                         } else {
                                             continue;
                                         }
                                     } else {
                                         continue;
                                     }
                                     $cargo->fecha = $model->fecha;
                                     $cargo->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
                                     $cargo->monto = $monto;
                                     $cargo->detalle = "PRESTACIÓN REALIZADA: " . $model->descripcion;
                                     $cargo->validado = 1;
                                     $cargo->saldo_cuenta = $cargo->ultimoSaldo();
                                     $cargo->save();
                                     $cargo->actualizaSaldosPosteriores(-$monto);
                                     $prestacionMovimiento = new PrestacionGeneraMovimiento();
                                     $prestacionMovimiento->prestacion_id = $model->id;
                                     $prestacionMovimiento->movimiento_id = $cargo->id;
                                     $prestacionMovimiento->save();
                                 }
                             }
                         }
                     }
                 } else {
                     //general_prop == "1"
                     if ($model->genera_cargos == "1") {
                         //se crean los cargos para el depto
                         $departamentos = Departamento::model()->getVigentesDePropiedad($propiedad->id);
                         $cant_deptos = count($departamentos);
                         if ($cant_deptos != 0) {
                             $monto = (int) $model->monto / $cant_deptos;
                             foreach ($departamentos as $depto) {
                                 $cargo = new Movimiento();
                                 if ($depto->contrato != null) {
                                     if ($depto->contrato->vigente) {
                                         $cargo->cuenta_corriente_id = $depto->contrato->cuentaCorriente->id;
                                     } else {
                                         continue;
                                     }
                                 } else {
                                     continue;
                                 }
                                 $cargo->fecha = $model->fecha;
                                 $cargo->tipo = Tools::MOVIMIENTO_TIPO_CARGO;
                                 $cargo->monto = $monto;
                                 $cargo->detalle = "PRESTACIÓN REALIZADA: " . $model->descripcion;
                                 $cargo->validado = 1;
                                 $cargo->saldo_cuenta = $cargo->ultimoSaldo();
                                 $cargo->save();
                                 $cargo->actualizaSaldosPosteriores(-$monto);
                                 $prestacionMovimiento = new PrestacionGeneraMovimiento();
                                 $prestacionMovimiento->prestacion_id = $model->id;
                                 $prestacionMovimiento->movimiento_id = $cargo->id;
                                 $prestacionMovimiento->save();
                             }
                         }
                     }
                 }
                 Yii::app()->user->setFlash('success', 'Prestación creada correctamente.');
                 $model = new Prestacion();
             } else {
                 Yii::app()->user->setFlash('error', 'Error: No se pudo crear la Prestación. Reintente.');
             }
         } else {
             Yii::app()->user->setFlash('error', 'Debe seleccionar una propiedad válida.');
         }
     }
     $this->render('create', array('model' => $model, 'departamentos' => $deptos));
 }
示例#15
0
 public function getPropiedadYNumero()
 {
     $propiedad = Propiedad::model()->find('id=:id', array(':id' => $this->propiedad_id));
     return $propiedad->nombre . ' - (' . $this->numero . ')';
 }