public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             $attribs = array();
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha_sola', $laFechaDesde, $laFechaHasta);
             $rows = MedicamentosBiologicos::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = MedicamentosBiologicos::model()->findAll();
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'medicamento'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new MedicamentosBiologicos('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['MedicamentosBiologicos'])) {
             $model->attributes = $_GET['MedicamentosBiologicos'];
         }
         $this->render('admin', array('model' => $model));
     }
 }
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             $attribs = array();
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha', $laFechaDesde, $laFechaHasta);
             $rows = Presupuesto::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = Presupuesto::model()->findAll();
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'paciente.nombreCompleto', 'paciente.n_identificacion::Cedula', 'estado', 'fecha', 'total', 'vendedor.nombreCompleto::Vendido Por'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new Presupuesto('search');
         $model->unsetAttributes();
         // clear any default values
         $this->layout = 'main';
         if (isset($_GET['Presupuesto'])) {
             $model->attributes = $_GET['Presupuesto'];
         }
         $this->render('admin', array('model' => $model));
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             $attribs = array('estado' => 'Activo');
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha_sola', $laFechaDesde, $laFechaHasta);
             $rows = Egresos::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = Egresos::model()->findAll("estado = 'Activo'");
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'proveedor.nombre', 'factura.factura_n', 'forma_pago', 'valor_egreso', 'iva_valor', 'total_egreso', 'centroCosto.nombre', 'personal.nombreCompleto', 'fecha_sola::Fecha'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new Egresos('search');
         $model->unsetAttributes();
         // clear any default values
         $this->layout = 'main';
         if (isset($_GET['Egresos'])) {
             $model->attributes = $_GET['Egresos'];
         }
         $losEgresos = Egresos::model()->count();
         if ($losEgresos == 0) {
             $this->render('vacio', array('model' => $model));
         } else {
             $this->render('admin', array('model' => $model));
         }
     }
 }
 public function actionExportarPrimeraVisitaNo()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['claveNo'] == $clave->super_usuario) {
         if ($_POST['filtroNo'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desdeNo']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hastaNo']);
             $sql = "SELECT citas.id as cita, citas.linea_servicio_id, citas.fecha_cita, CONCAT(personal.nombres, ' ', personal.apellidos) as nombrepersonal, paciente.id as paciente, paciente.nombre, paciente.apellido, paciente.n_identificacion from paciente INNER join citas on citas.paciente_id = paciente.id inner join personal on personal.id = citas.personal_id where citas.linea_servicio_id = 5 and citas.estado = 'Completada' and citas.fecha_cita between '{$laFechaDesde}' and '{$laFechaHasta}' and paciente.id not in (select contratos.paciente_id from contratos) group by paciente order by citas.fecha_cita";
             // //$attribs = array('estado'=>'Activo');
             // $attribs = array();
             // $criteria = new CDbCriteria(array('order'=>'id DESC'));
             // $criteria->addBetweenCondition('fecha_cita', $laFechaDesde, $laFechaHasta);
             // $rows = Citas::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $sql = "SELECT citas.id as cita, citas.linea_servicio_id, citas.fecha_cita, CONCAT(personal.nombres, ' ', personal.apellidos) as nombrepersonal, paciente.id as paciente, paciente.nombre, paciente.apellido, paciente.n_identificacion from paciente INNER join citas on citas.paciente_id = paciente.id inner join personal on personal.id = citas.personal_id where citas.linea_servicio_id = 5 and citas.estado = 'Completada' and paciente.id not in (select contratos.paciente_id from contratos) group by paciente order by citas.fecha_cita";
         }
         $rawData = Yii::app()->db->createCommand($sql);
         $model = new CSqlDataProvider($rawData, array('keyField' => 'cita', 'sort' => array('attributes' => array('cita'), 'defaultOrder' => array('cita' => CSort::SORT_ASC)), 'pagination' => array('pageSize' => 9999999999)));
         // Export it
         $this->toExcel($model, array('cita::num_cita', 'fecha_cita', 'nombrepersonal', 'nombre', 'apellido', 'n_identificacion'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $this->actionPrimeraVisita();
     }
 }
 public function actionAnular($id)
 {
     $lasConfiguraciones = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $lasConfiguraciones->super_usuario) {
         if ($_POST['observacion_anular'] == "") {
             Yii::app()->user->setFlash('error', "Falta observación, no se realizo la anulación.");
             $this->redirect(array('view', 'id' => $id));
         }
         $datosVenta = Ventas::model()->findByPk($id);
         $datosVenta->estado = "Anulada";
         $datosVenta->total_venta = $datosVenta->total_venta;
         $datosVenta->fecha_anulada = date("Y-m-d H:i:s");
         $datosVenta->comentario_anulada = $_POST['observacion_anular'];
         if ($datosVenta->update()) {
             //Verificar tipo de pago
             if ($datosVenta->forma_pago == "Efectivo") {
                 $laCaja = CajaEfectivo::model()->findByPk($datosVenta->personal);
                 //validar
                 if ($datosVenta->total2 > 0) {
                     $laCaja->total = $laCaja->total - $datosVenta->total1;
                 } else {
                     $laCaja->total = $laCaja->total - $datosVenta->total_venta;
                 }
                 $laCaja->update();
                 $datoCajaDetalle = CajaEfectivoDetalle::model()->find("venta_id = {$datosVenta->id}");
                 $datoCajaDetalle->tipo = "Venta Anulada";
                 $datoCajaDetalle->monto = $datoCajaDetalle->monto * -1;
                 $datoCajaDetalle->update();
             }
             //Regresar productos al inventario
             $productosVenta = VentasDetalle::model()->findAll("venta_id = {$datosVenta->id}");
             foreach ($productosVenta as $producto_venta) {
                 $elProducto = ProductoInventario::model()->findByPk($producto_venta->producto_id);
                 $elProducto->cantidad = $elProducto->cantidad + $producto_venta->cantidad;
                 $elProducto->update();
             }
             Yii::app()->user->setFlash('success', "Se completo la anulación.");
             $this->redirect(array('view', 'id' => $datosVenta->id));
         }
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta, no se realizo la anulación.");
         $this->redirect(array('view', 'id' => $id));
     }
 }
 public function actionExportar()
 {
     // $actualizarpago = PagoCosmetologas::model()->findAll();
     // foreach ($actualizarpago as $actualizar_pago)
     // {
     // 	$actualizar_pago->fecha_sola = Yii::app()->dateformatter->format("yyyy-MM-dd",$actualizar_pago->fecha);
     // 	$actualizar_pago->update();
     // }
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             $attribs = array('estado' => 'Activo');
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha_sola', $laFechaDesde, $laFechaHasta);
             $rows = PagoCosmetologas::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = PagoCosmetologas::model()->findAll("estado = 'Activo'");
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'paciente.nombreCompleto', 'n_identificacion::Cedula', 'lineaServicio.nombre', 'personal.nombreCompleto::Asistencial', 'contrato_id::Contrato', 'sesion::Sesion', 'fecha_sola', 'valor_tratamiento::Valor de Tratamiento', 'valor_tratamiento_desc::Tratamiento con Descuento', 'valor_comision::Valor Comisión', 'vendedor.nombreCompleto::Vendedor', 'aprobo.nombreCompleto::Establecio estado', 'total_pago::Total de Pago', 'saldo::Saldo a Favor'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new PagoCosmetologas('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['PagoCosmetologas'])) {
             $model->attributes = $_GET['PagoCosmetologas'];
         }
         $this->layout = 'main';
         $loPagos = PagoCosmetologas::model()->count();
         if ($loPagos == 0) {
             $this->render('vacio', array('model' => $model));
         } else {
             $this->render('admin', array('model' => $model));
         }
     }
 }
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             // $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd",$_POST['fecha_desde']);
             // $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd",$_POST['fecha_hasta']);
             // $attribs = array('estado'=>'Activo');
             // $criteria = new CDbCriteria(array('order'=>'id DESC'));
             // $criteria->addBetweenCondition('fecha_sola', $laFechaDesde, $laFechaHasta);
             // $rows = Egresos::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = CuentasXc::model()->findAll("saldo > 0");
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'paciente.nombreCompleto', 'n_identificacion', 'saldo'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new CuentasXc('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['CuentasXc'])) {
             $model->attributes = $_GET['CuentasXc'];
             $model->saldo > 0;
         }
         $lasCuentas = CuentasXc::model()->count();
         $criteria = new CDbCriteria();
         $criteria->select = 'SUM(saldo) as lasuma';
         //$criteria->condition='id > 0';
         $sumaSaldo = CuentasXc::model()->find($criteria);
         $lasuma = Yii::app()->db->createCommand("SELECT SUM(`saldo`) as `sum` FROM `cuentas_xc` WHERE 1")->queryScalar();
         //$lasumas = $lasuma * -1;
         if ($lasCuentas == 0 or $lasuma == 0) {
             $this->render('vacio', array('model' => $model));
         } else {
             $this->render('admin', array('model' => $model));
         }
     }
 }
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             $attribs = array('estado' => 'Activo');
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha', $laFechaDesde, $laFechaHasta);
             $rows = VentasDetalle::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = VentasDetalle::model()->findAll("id > 0");
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'venta_id', 'paciente.nombreCompleto::Nombre de Paciente', 'producto.nombre_producto', 'cantidad', 'valor', 'iva', 'total', 'fecha::Fecha de Venta'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new VentasDetalle('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['VentasDetalle'])) {
             $model->attributes = $_GET['VentasDetalle'];
         }
         $this->layout = 'main';
         $lasVentas = VentasDetalle::model()->count();
         if ($lasVentas == 0) {
             $this->render('vacio', array('model' => $model));
         } else {
             $this->render('admin', array('model' => $model));
         }
     }
 }
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             //$attribs = array('estado'=>'Activo');
             $attribs = array();
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha_cita', $laFechaDesde, $laFechaHasta);
             $rows = Citas::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = Citas::model()->findAll();
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'paciente.nombre', 'paciente.apellido', 'paciente.celular', 'n_identificacion::Cedula', 'personal.nombreCompleto::Ingresado Por', 'usuario.nombreCompleto::Registrado por', 'lineaServicio.nombre::Linea de Servicio', 'contrato_id::Contrato Asociado', 'estado::Estado', 'fecha_cita::Fecha de Cita', 'horaInicio.hora::Hora de Inicio', 'horaFinMostrar.hora::Hora de Fin', 'comentario::Comentario', 'motivo_cancelacion::Motivo de Cancelación', 'usuarioEstado.nombreCompleto::Establecio Estado', 'fecha_creacion::Fecha Creación'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new Citas('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['Citas'])) {
             $model->attributes = $_GET['Citas'];
         }
         $this->layout = 'main';
         $this->render('admin', array('model' => $model));
     }
 }
 public function actionExportarCxp()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd H:i:s", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd H:i:s", $_POST['fecha_hasta']);
             $attribs = array('estado' => 'Activo');
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha', $laFechaDesde, $laFechaHasta);
             $rows = ProductoCompras::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = ProductoCompras::model()->findAll("estado = 'Activo'");
         }
         // Export it
         $this->toExcel($rows, array('id::Orden N°', 'productoProveedor.nombre::Proveedor', 'factura_n::Factura', 'total_compra', 'forma_pago', 'credito_dias', 'credito_fecha', 'saldo', 'estado'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new ProductoCompras('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['ProductoCompras'])) {
             $model->attributes = $_GET['ProductoCompras'];
             $model->estado = "Activo";
         }
         $this->layout = 'main';
         $lasCompras = ProductoCompras::model()->count();
         if ($lasCompras == 0) {
             $this->render('vacio', array('model' => $model));
         } else {
             $this->render('cxp', array('model' => $model));
         }
     }
 }
 /**
  * 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 Configuraciones the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Configuraciones::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['fecha_hasta']);
             $attribs = array();
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha', $laFechaDesde, $laFechaHasta);
             $rows = RelacionHojaGastos::model()->findAllByAttributes($attribs, $criteria);
         } else {
             $rows = RelacionHojaGastos::model()->findAll();
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'paciente.nombreCompleto::Paciente', 'n_identificacion::Cedula', 'hoja', 'asistencial.nombreCompleto::Asistencial', 'lineaServicio.nombre::Linea de Servicio', 'fecha', 'costo', 'personal.nombreCompleto::Registrado por'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $model = new Paciente('search');
         $model->unsetAttributes();
         // clear any default values
         if (isset($_GET['Paciente'])) {
             $model->attributes = $_GET['Paciente'];
         }
         $this->render('admin', array('model' => $model));
     }
 }
 public function actionExportar()
 {
     $clave = Configuraciones::model()->findByPk(1);
     if ($_POST['clave'] == $clave->super_usuario) {
         if ($_POST['filtro'] == 1) {
             $laFechaDesde = Yii::app()->dateformatter->format("yyyy-MM-dd H:i:s", $_POST['fecha_desde']);
             $laFechaHasta = Yii::app()->dateformatter->format("yyyy-MM-dd H:i:s", $_POST['fecha_hasta']);
             if ($_GET["tipo"] == 0) {
                 $attribs = array('estado' => 'Activo');
             }
             if ($_GET["tipo"] == 1) {
                 $attribs = array('estado' => 'Activo', 'tipo_inventario' => 'Productos');
             }
             if ($_GET["tipo"] == 2) {
                 $attribs = array('estado' => 'Activo', 'tipo_inventario' => 'Insumos');
             }
             if ($_GET["tipo"] == 3) {
                 $attribs = array('estado' => 'Activo', 'tipo_inventario' => 'Consumibles');
             }
             if ($_GET["tipo"] == 4) {
                 $attribs = array('estado' => 'Inactivo');
             }
             $criteria = new CDbCriteria(array('order' => 'id DESC'));
             $criteria->addBetweenCondition('fecha', $laFechaDesde, $laFechaHasta);
             $rows = ProductoInventario::model()->findAllByAttributes($attribs, $criteria);
         } else {
             if ($_GET["tipo"] == 0) {
                 $rows = ProductoInventario::model()->findAll("estado = 'Activo'");
             }
             if ($_GET["tipo"] == 1) {
                 $rows = ProductoInventario::model()->findAll("estado = 'Activo' and tipo_inventario = 'Productos'");
             }
             if ($_GET["tipo"] == 2) {
                 $rows = ProductoInventario::model()->findAll("estado = 'Activo' and tipo_inventario = 'Insumos'");
             }
             if ($_GET["tipo"] == 3) {
                 $rows = ProductoInventario::model()->findAll("estado = 'Activo' and tipo_inventario = 'Consumibles'");
             }
             if ($_GET["tipo"] == 4) {
                 $rows = ProductoInventario::model()->findAll("estado = 'Inactivo'");
             }
         }
         // Export it
         $this->toExcel($rows, array('id::ID', 'producto_referencia::Referencia', 'lote', 'productoProveedor.nombre::Proveedor', 'costo_iva', 'precio_publico', 'iva', 'productoPresentacion.presentacion', 'productoUnidadMedida.medida', 'cantidad::Existencia', 'stock_minimo', 'productoCategoria.categoria', 'tipo_inventario', 'estado'));
     } else {
         Yii::app()->user->setFlash('error', "Clave incorrecta para realizar la exportación.");
         $elfiltro = "";
         if (isset($_GET['tipo'])) {
             $elfiltro = trim($_GET['tipo']);
         }
         //echo $elfiltro;
         $model = new ProductoInventario('search');
         //$model->unsetAttributes();  // clear any default values
         if (isset($_GET['ProductoInventario'])) {
             $model->attributes = $_GET['ProductoInventario'];
         }
         switch ($elfiltro) {
             case 1:
                 $model->tipo_inventario = "Productos";
                 $losProductos = ProductoInventario::model()->count("tipo_inventario = 'Productos'");
                 break;
             case 2:
                 $model->tipo_inventario = "Insumos";
                 $losProductos = ProductoInventario::model()->count("tipo_inventario = 'Insumos'");
                 break;
             case 3:
                 $model->tipo_inventario = "Consumibles";
                 $losProductos = ProductoInventario::model()->count("tipo_inventario = 'Consumibles'");
                 break;
             case 4:
                 $model->estado = "Inactivo";
                 $losProductos = ProductoInventario::model()->count("estado = 'Inactivo'");
                 break;
             default:
                 $losProductos = ProductoInventario::model()->count();
                 break;
         }
         if ($losProductos == 0) {
             $this->render('vacio', array('model' => $model));
         } else {
             $this->render('admin', array('model' => $model));
         }
     }
 }