/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new HojaGastos();
     $superTotal = 0;
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['HojaGastos'])) {
         $datosCita = Citas::model()->findByPk($_GET['idCita']);
         $model->attributes = $_POST['HojaGastos'];
         $model->cita_id = $datosCita->id;
         $model->paciente_id = $datosCita->paciente_id;
         $model->observaciones = $_POST['HojaGastos']['observaciones'];
         $model->fecha = date("Y-m-d H:i:s");
         $model->personal_id = Yii::app()->user->usuarioId;
         if ($model->save()) {
             //Los detalles de la Hoja de Gastos
             for ($i = 0; $i <= $_POST['variable']; $i++) {
                 if (isset($_POST['producto_' . $i])) {
                     $detalleC = new HojaGastosDetalle();
                     $detalleC->hoja_gastos_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($_POST['producto_' . $i]);
                     //Reducir inventario e inventario detalle
                     $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_id = $model->id;
         $relacion->paciente_id = $model->paciente_id;
         $relacion->n_identificacion = $datosCita->n_identificacion;
         $relacion->hoja = "Hoja de Gastos";
         $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));
 }
Example #2
0
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Hoja de Gastos</h3>
  </div>
  <div class="modal-body">
 	
 	<table class="table" width="100%">
			<tr>
				<th><small>Codigo</small></th>
				<th><small>Producto</small></th>
				<th><small>Lote</small></th>
				<th><small>Presentación</small></th>
				<th><small>Unidad de Medida</small></th>
				<th><small>Cant.</small></th>
			</tr>
			<?php 
    $losGastos = HojaGastosDetalle::model()->findAll("hoja_gastos_id = {$idHojaGastos->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->lote;
        ?>
</td>
Example #3
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, ''))));