Example #1
0
<?php

/* @var $this RelacionHojaGastosController */
/* @var $model RelacionHojaGastos */
$this->menu = array(array('label' => 'Buscar Relación Hoja de Gastos', 'url' => array('admin')));
$titulo = $model->hoja;
//Los productos
if ($model->hoja == "Hoja de Gastos") {
    //$lahoja = HojaGastos::model()->find("id = $model->cita_id");
    $detalleHoja = HojaGastosDetalle::model()->findAll("hoja_gastos_id = {$model->hoja_gastos_id}");
}
if ($model->hoja == "Hoja de Gastos Cirugia") {
    //$lahoja = HojaGastosCirugia::model()->find("cita_id = $model->cita_id");
    $detalleHoja = HojaGastosCirugiaDetalle::model()->findAll("hoja_gastos_cirugia_id = {$model->hoja_gastos_cirugia_id}");
}
?>

<h1>Relación Hoja de Gastos #<?php 
echo $model->id;
?>
</h1>

<div class = "row">
	<div class="span6">
		<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array(array('name' => 'paciente_id', 'value' => $model->paciente->nombreCompleto, ''), 'hoja', array('name' => 'asistencial_id', 'value' => $model->asistencial->nombreCompleto, ''), 'cita_id')));
?>
	</div>
	<div class="span6">
		<?php 
$this->widget('zii.widgets.CDetailView', array('data' => $model, 'attributes' => array(array('name' => 'linea_servicio_id', 'value' => $model->lineaServicio->nombre, ''), array('name' => 'fecha', 'value' => Yii::app()->dateformatter->format("dd-MM-yyyy", $model->fecha)), array('name' => 'costo', 'value' => "\$ " . number_format($model->costo, 2)), array('name' => 'personal_id', 'value' => $model->personal->nombreCompleto, ''))));
Example #2
0
    } else {
        $nombreInstrumento = null;
    }
    $this->widget('zii.widgets.CDetailView', array('data' => $idHojaCirugia, 'attributes' => array('hora_ingreso', 'hora_inicio_cirugia', 'hora_final_cirugia', array('name' => 'Cirujano', 'value' => $nombreCirujano, ''), array('name' => 'Ayudante', 'value' => $nombreAyudante, ''), array('name' => 'Anestesiologo', 'value' => $nombreAnestesia, ''), array('name' => 'Rotadora', 'value' => $nombreRotadora, ''), array('name' => 'Instrumentadora', 'value' => $nombreInstrumento, ''), array('name' => 'Fecha de Ingreso', 'value' => Yii::app()->dateformatter->format("dd-MM-yyyy HH:mm:ss", $idHojaCirugia->fecha), ''), array('name' => 'Ingresado por', 'value' => $idHojaCirugia->personal->nombreCompleto, ''))));
    ?>
	</div>
 	<h4>Productos Utilizados</h4>
 	<table class="table" width="100%">
		<tr>
			<th><small>Codigo</small></th>
			<th><small>Producto</small></th>
			<th><small>Unidad de Medida</small></th>				
			<th><small>Cant.</small></th>
		</tr>
		<?php 
    $losGastos = HojaGastosCirugiaDetalle::model()->findAll("hoja_gastos_cirugia_id = {$idHojaCirugia->id}");
    foreach ($losGastos as $los_gastos) {
        ?>
			<tr>
				<td><?php 
        echo $los_gastos->producto->producto_referencia;
        ?>
</td>
				<td><?php 
        echo $los_gastos->producto->nombre_producto;
        ?>
</td>
				<td><?php 
        echo $los_gastos->producto->productoUnidadMedida->medida;
        ?>
</td>
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new HojaGastosCirugia();
     $superTotal = 0;
     if (isset($_GET['idCita'])) {
         $idCita = $_GET['idCita'];
     } else {
         $idCita = null;
     }
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['HojaGastosCirugia'])) {
         $model->attributes = $_POST['HojaGastosCirugia'];
         $model->paciente_id = $_GET['idPaciente'];
         $model->cita_id = $idCita;
         $model->fecha_cirugia = Yii::app()->dateformatter->format("yyyy-MM-dd", $_POST['HojaGastosCirugia']['fecha_cirugia']);
         $model->fecha = date("Y-m-d H:i:s");
         $model->personal_id = Yii::app()->user->usuarioId;
         if ($model->save()) {
             //Los detalles de la Compra
             for ($i = 0; $i <= $_POST['variable']; $i++) {
                 if (isset($_POST['producto_' . $i])) {
                     $datosCita = Citas::model()->findByPk($idCita);
                     $detalleC = new HojaGastosCirugiaDetalle();
                     $detalleC->hoja_gastos_cirugia_id = $model->id;
                     $detalleC->producto_id = $_POST['elid_' . $i];
                     $detalleC->cantidad = $_POST['cantidad_' . $i];
                     $detalleC->save();
                     //Agregar a relación de Hoja de gstos
                     $elCosto = ProductoInventario::model()->findByPk($detalleC->producto_id);
                     //Disminuir inventario
                     //$elProducto = ProductoInventario::model()->findByPk($_POST['producto_'.$i]);
                     $elProducto = InventarioPersonalDetalle::model()->find('id =' . $_POST['producto_' . $i] . " and inventario_personal_id =" . Yii::app()->user->usuarioId);
                     $elProducto->cantidad = $elProducto->cantidad - $_POST['cantidad_' . $i];
                     $elProducto->save();
                     $elProductoDetalle = ProductoInventarioDetalle::model()->find('producto_inventario_id = ' . $elProducto->producto_id . ' and lote = "' . $_POST['lote_' . $i] . '"');
                     $elProductoDetalle->existencia = $elProductoDetalle->existencia - $_POST['cantidad_' . $i];
                     if ($elProductoDetalle->save()) {
                         $elProducto = ProductoInventario::model()->findByPk($elProductoDetalle->producto_inventario_id);
                         $elProducto->cantidad = $elProducto->cantidad - $_POST['cantidad_' . $i];
                         $elProducto->save();
                     }
                     $superTotal = $superTotal + $elProducto->costo_iva;
                 }
             }
             $relacion = new RelacionHojaGastos();
             $relacion->hoja_gastos_cirugia_id = $model->id;
             $relacion->paciente_id = $model->paciente_id;
             $relacion->n_identificacion = $datosCita->n_identificacion;
             $relacion->hoja = "Hoja de Gastos Cirugia";
             $relacion->asistencial_id = $datosCita->personal_id;
             $relacion->cita_id = $datosCita->id;
             $relacion->linea_servicio_id = $datosCita->linea_servicio_id;
             $relacion->fecha = date("Y-m-d");
             $relacion->fecha_hora = date("Y-m-d H:i:s");
             $relacion->costo = $superTotal;
             $relacion->personal_id = Yii::app()->user->usuarioId;
             $relacion->save();
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }