public static function arregloMeses($mesInicio, $agnoInicio, $mesFin, $agnoFin) { $meses = array(); $mesTope = 12; for ($i = $agnoInicio; $i <= $agnoFin; $i++) { if ($i == $agnoFin) { $mesTope = $mesFin; } for ($j = $mesInicio; $j <= $mesTope; $j++) { $meses[] = array('mes' => str_pad($j, 2, "0", STR_PAD_LEFT), 'agno' => $i, 'mesNombre' => Tools::fixMes($j)); } $mesInicio = 1; } return $meses; }
/** * 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['Ipc'])) { $model->attributes = $_POST['Ipc']; $anterior = Ipc::model()->findByAttributes(array('mes' => $model->mes, 'agno' => $model->agno)); if ($anterior != null) { if ($anterior->id != $id) { $model->addError('mes', Tools::fixMes($model->mes) . " de " . $model->agno . " ya existe."); } else { if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } } } $this->render('update', array('model' => $model)); }
public function actionListado() { $model = new ListadoPrestacionesForm(); $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['ListadoPrestacionesForm'])) { $model->attributes = $_POST['ListadoPrestacionesForm']; $propiedad = Propiedad::model()->findByPk($model->propiedad_id); $departamento = Departamento::model()->findByPk($model->departamento_id); Yii::import('ext.phpexcel.XPHPExcel'); $objPHPExcel = XPHPExcel::createPHPExcel(); $sheet = $objPHPExcel->getActiveSheet(); $sheet->setCellValue('A1', 'Listado de Prestaciones por Propiedad'); $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 = 3; if ($propiedad != null) { $sheet->setCellValueByColumnAndRow(0, $i, 'Propiedad: ' . $propiedad->nombre); $sheet->mergeCellsByColumnAndRow(0, $i, 5, $i); $sheet->getStyleByColumnAndRow(0, $i)->getFont()->setSize(15); $i++; } if ($departamento != null && $propiedad != null) { $sheet->setCellValueByColumnAndRow(0, $i, 'Departamento: ' . $departamento->numero); $sheet->mergeCellsByColumnAndRow(0, $i, 5, $i); $sheet->getStyleByColumnAndRow(0, $i)->getFont()->setSize(15); $i++; } $i++; $sheet->setCellValueByColumnAndRow(0, $i, 'Fecha'); $sheet->setCellValueByColumnAndRow(1, $i, 'Propiedad'); $sheet->setCellValueByColumnAndRow(2, $i, 'Departamento'); $sheet->setCellValueByColumnAndRow(3, $i, 'General Prop'); $sheet->setCellValueByColumnAndRow(4, $i, 'Nro Cheque'); $sheet->setCellValueByColumnAndRow(5, $i, 'Monto'); $sheet->setCellValueByColumnAndRow(6, $i, 'C/S Cargo'); $sheet->setCellValueByColumnAndRow(7, $i, 'Concepto'); $sheet->setCellValueByColumnAndRow(8, $i, 'Maestro'); $sheet->setCellValueByColumnAndRow(9, $i, 'Tipo Prestación'); $sheet->getStyleByColumnAndRow(0, $i, 10, $i)->getFont()->setSize(15); $sheet->getStyleByColumnAndRow(0, $i, 10, $i)->getFont()->setBold(true); $i++; $prestaciones = Prestacionesadepartamentos::model()->getDePropiedadYDepartamento($propiedad, $departamento); foreach ($prestaciones as $prestacion) { $sheet->setCellValueByColumnAndRow(0, $i, Tools::backFecha($prestacion->fecha)); $propiedad = Propiedad::model()->findByPk($prestacion->propiedad_id); $departamento = Departamento::model()->findByPk($prestacion->departamento_id); if ($propiedad == null) { $propiedad = $departamento->propiedad; } $sheet->setCellValueByColumnAndRow(1, $i, $propiedad->nombre); $sheet->setCellValueByColumnAndRow(2, $i, $departamento != null ? $departamento->numero : "SIN DEPARTAMENTO"); $sheet->setCellValueByColumnAndRow(3, $i, $prestacion->general_prop == 1 ? "SÍ" : "NO"); $sheet->setCellValueByColumnAndRow(4, $i, $prestacion->documento); $sheet->setCellValueByColumnAndRow(5, $i, $prestacion->monto); $sheet->setCellValueByColumnAndRow(6, $i, $prestacion->genera_cargos == 1 ? "SÍ" : "NO"); $sheet->setCellValueByColumnAndRow(7, $i, $prestacion->descripcion); $sheet->setCellValueByColumnAndRow(8, $i, $prestacion->maestro); $sheet->setCellValueByColumnAndRow(9, $i, $prestacion->tipo); $i++; } $objPHPExcel->setActiveSheetIndex(0); header('Content-Type: application/vnd.ms-excel'); header('Content-Disposition: attachment;filename="Prestaciones a Propiedades.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('listado', array('model' => $model, 'meses' => $meses, 'agnos' => $agnos, 'propiedades' => $propiedades)); }
public function actionAdminAbonos() { $model = new Contrato('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Contrato'])) { $model->attributes = $_GET['Contrato']; } $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); } $filtroModel = new EstadoCuentaForm(); $filtroModel->agnoH = date('Y'); $filtroModel->mesH = date('m'); if ($filtroModel->mesH == '01') { $filtroModel->mesD = '12'; $filtroModel->agnoD = (int) $filtroModel->agnoH - 1; } else { $mes = (int) $filtroModel->mesH; $filtroModel->mesD = str_pad($mes - 1, 2, "0", STR_PAD_LEFT); $filtroModel->agnoD = $filtroModel->agnoH; } if (isset($_POST['EstadoCuentaForm'])) { $filtroModel->attributes = $_POST['EstadoCuentaForm']; Yii::import('ext.phpexcel.XPHPExcel'); $objPHPExcel = XPHPExcel::createPHPExcel(); $sheet = $objPHPExcel->getActiveSheet(); $contrato = Contrato::model()->findByPk($filtroModel->contratoId); if ($contrato == null) { die; } if (!$contrato->estaAsociadoAPropietario(Yii::app()->user->id)) { die; } $sheet->setCellValue('A1', 'Movimientos de Cliente'); $sheet->mergeCells("A1:L1"); $sheet->getStyle("A1")->getFont()->setSize(15); $sheet->setCellValue('A3', 'Nombre: '); $sheet->setCellValue('B3', $contrato->cliente->usuario->nombre . " " . $contrato->cliente->usuario->apellido); $sheet->setCellValue('F3', 'Fecha Consulta: ' . date('d/m/Y')); $sheet->setCellValue('A4', 'Propiedad: '); $sheet->setCellValue('B4', $contrato->departamento->propiedad->nombre); $sheet->setCellValue('C4', "Departamento: "); $sheet->setCellValue('D4', $contrato->departamento->numero); $sheet->getStyle("A3")->getFont()->setSize(13); $sheet->getStyle("B3")->getFont()->setSize(13); $sheet->getStyle("F3")->getFont()->setSize(13); $sheet->getStyle("A4")->getFont()->setSize(13); $sheet->getStyle("B4")->getFont()->setSize(13); $sheet->getStyle("C4")->getFont()->setSize(13); $sheet->getStyle("D4")->getFont()->setSize(13); $sheet->setCellValue('A5', "Rango de fechas consultado"); $sheet->getStyle("A5")->getFont()->setSize(13); $sheet->setCellValue('A6', "Desde:"); $sheet->getStyle("A6")->getFont()->setSize(13); $sheet->setCellValue('B6', Tools::fixMes($filtroModel->mesD) . " " . $filtroModel->agnoD); $sheet->getStyle("B6")->getFont()->setSize(13); $fechaDesde = $filtroModel->agnoD . "-" . $filtroModel->mesD . "-" . "01"; if ($filtroModel->desdeInicio == '1') { $sheet->setCellValue('A6', "Desde inicio del Contrato:"); $sheet->setCellValue('B6', Tools::backFecha($contrato->fecha_inicio)); $fechaDesde = $contrato->fecha_inicio; } if ($filtroModel->desdeSaldo0 == '1') { $movimiento = Movimiento::model()->findByPk($contrato->cuentaCorriente->idMovUltimoSaldo0()); if ($movimiento != null) { $sheet->setCellValue('A6', "Desde último saldo 0:"); $sheet->setCellValue('B6', Tools::backFecha($movimiento->fecha)); $fechaDesde = $movimiento->fecha; } else { $sheet->setCellValue('A6', "Desde último saldo 0:"); $sheet->setCellValue('B6', "No hay saldo 0 "); $fechaDesde = $contrato->fecha_inicio; } } $fechaArr = explode("-", $fechaDesde); $filtroModel->mesD = $fechaArr[1]; $filtroModel->agnoD = $fechaArr[0]; $sheet->setCellValue('A7', "Hasta:"); $sheet->getStyle("A7")->getFont()->setSize(13); $sheet->setCellValue('B7', Tools::fixMes($filtroModel->mesH) . " " . $filtroModel->agnoH); $sheet->getStyle("B7")->getFont()->setSize(13); $sheet->setCellValue('A9', "Saldo Anterior:"); $sheet->getStyle("A9")->getFont()->setSize(13); $sheet->setCellValue('B9', $contrato->cuentaCorriente->saldoAFecha($fechaDesde)); $sheet->getStyle("B9")->getFont()->setSize(13); if ($filtroModel->conDetalle == "1") { $sheet->setCellValue('A11', "Mes/Año"); $sheet->setCellValue('B11', "Concepto"); $sheet->setCellValue('C11', "Cargos"); $sheet->mergeCells('C11:D11'); $sheet->setCellValue('E1', "Abonos"); $sheet->mergeCells('E11:F11'); $sheet->setCellValue('C12', "Fecha"); $sheet->setCellValue('D12', "Monto"); $sheet->setCellValue('E12', "Fecha"); $sheet->setCellValue('F12', "Monto"); $sheet->getStyle("A11:F12")->getFont()->setBold(true); $j = 13; } else { $sheet->setCellValue('A11', "Mes/Año"); $sheet->setCellValue('B11', "Cargos"); $sheet->setCellValue('C11', "Abonos"); $sheet->getStyle("A11:C11")->getFont()->setBold(true); $j = 12; } $meses = Tools::arregloMeses($filtroModel->mesD, $filtroModel->agnoD, $filtroModel->mesH, $filtroModel->agnoH); $abonos = 0; $cargos = 0; foreach ($meses as $mesArr) { $mes = $mesArr['mes']; $agno = $mesArr['agno']; $mesNombre = $mesArr['mesNombre']; if ($filtroModel->conDetalle == "1") { $sheet->setCellValue('A' . $j, $mesNombre . " " . $agno); $j++; $movimientosMes = $contrato->cuentaCorriente->movimientosDeMes($mes, $agno); foreach ($movimientosMes as $movimiento) { $sheet->setCellValue('B' . $j, $movimiento->detalle); if ($movimiento->tipo == Tools::MOVIMIENTO_TIPO_CARGO) { $sheet->setCellValue('C' . $j, Tools::backFecha($movimiento->fecha)); $sheet->setCellValue('D' . $j, $movimiento->monto); $cargos += $movimiento->monto; } else { $sheet->setCellValue('E' . $j, Tools::backFecha($movimiento->fecha)); $sheet->setCellValue('F' . $j, $movimiento->monto); $abonos += $movimiento->monto; } $j++; } } else { $saldoMes = $contrato->cuentaCorriente->saldoMes($mes, $agno); $sheet->setCellValue('A' . $j, $mesNombre . " " . $agno); $sheet->setCellValue('B' . $j, $saldoMes['cargos']); $sheet->setCellValue('C' . $j, $saldoMes['abonos']); $j++; } } if ($filtroModel->conDetalle == "1") { $sheet->setCellValue('A' . $j, "SUB TOTAL"); $sheet->setCellValue('D' . $j, $cargos); $sheet->setCellValue('F' . $j, $abonos); $j++; } $saldo = $contrato->cuentaCorriente->saldoAFecha(date('Y-m-d')); $sheet->setCellValue('A' . ($j + 1), "Saldo fecha consulta: "); $sheet->getStyle('A' . ($j + 1))->getFont()->setSize(13); $sheet->setCellValue('B' . ($j + 1), $saldo); $sheet->getStyle('B' . ($j + 1))->getFont()->setSize(13); $color = '00FF00'; if ($saldo < 0) { $color = 'FF0000'; } $sheet->getStyle("B" . ($j + 1))->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => $color)))); // 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 Cliente ' . $contrato->cliente->usuario->nombre . ' ' . $contrato->cliente->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(); } Yii::app()->user->returnUrl = array('//contrato/adminAbonos'); $this->render('adminAbonos', array('model' => $model, 'filtroModel' => $filtroModel, 'meses' => $meses, 'agnos' => $agnos)); }
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)); }
<?php /* @var $this IpcController */ /* @var $model Ipc */ $this->breadcrumbs = array('IPC' => array('admin'), $model->id); $this->menu = array(array('label' => 'Crear IPC', 'url' => array('create')), array('label' => 'Editar IPC', 'url' => array('update', 'id' => $model->id)), array('label' => 'Eliminar IPC', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => 'Are you sure you want to delete this item?')), array('label' => 'Administrar IPC', 'url' => array('admin'))); ?> <?php $this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array('porcentaje', array('name' => 'mes', 'value' => Tools::fixMes($model->mes)), 'agno')));