/**
  * 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 PresupuestoImportacion the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = PresupuestoImportacion::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 2
0
		        <tr class="principaltr">
		            <th data-field="Producto">Producto Importado</th>
		            <th data-field="Divisa">Divisa</th>
		            <th data-field="tipoimportacion">Tipo Importación</th>
		            <th data-field="fechallegada">Fecha estimada de la importación</th>
		            <th data-field="unidad">Costo unitario en divisa </th>
		            <th data-field="cantidad">Cantidad</th>
		            <th data-field="descripcion">Descripción</th>
		            <th data-field="totalbs">Total Bs.</th>
		            <th data-field="accion">Accion</th>
		        </tr>
		    </thead>
		    <tbody>
		    <?php 

		    	foreach (PresupuestoImportacion::model()->findAllByAttributes(array('producto_id'=>$presuImp->producto_id,'presupuesto_partida_id'=>$presuImp->presupuesto_partida_id)) as $key => $presIm) {
		    		
		    ?>
		    	<tr class="principaltr">

		    		<td><?php echo $this->obtenerCodigoNcmNombre($presIm->codigosNcms);?></td>
		    		<td><?php echo $presIm->divisa->abreviatura; ?></td>
					<td><?php echo $presIm->tipo =='corpovex' ? 'Corpovex' : 'Licitacion Internacional'; ?></td>
					<td><?php echo $presIm->fecha_llegada; ?></td>
					<td><?php echo number_format($presIm->monto_presupuesto,2,',','.'); ?></td>
					<td><?php echo $presIm->cantidad; ?></td>
					<td><?php echo $presIm->descripcion; ?></td>
		    		<td><?php echo number_format($presIm->monto_presupuesto*$presIm->cantidad*$presIm->divisa->tasa->tasa,2,',','.');?></td>
		    		<td><?php echo CHtml::link('Eliminar',Yii::app()->createAbsoluteUrl('/planificacion/eliminarProductoImportado',
		    			array('ppid'=>$presIm->presupuesto_partida_id,'pid'=>$presIm->producto_id,'cn'=>$presIm->codigo_ncm_id)),
		    		array('onClick'=>"eliminar('".$this->obtenerCodigoNcmNombre($presIm->codigosNcms)."');"));?></td>
 public function actionImportado()
 {
     $usuario = Usuarios::model()->findByPk(Yii::app()->user->getId());
     //Selección de Proyecto a Acción
     $proyectoSel = new Proyectos('search');
     $accionSel = new Acciones('search');
     // Selección Partidas
     $partidaSel = new Partidas('search');
     //Selección Producto
     $productoSel = new Productos('search');
     // Lista de productos cargados
     $presuImps = array();
     $presuImp = new PresupuestoImportacion();
     $codigoNcmSel = new CodigosNcm();
     //$partidas = new PresupuestoPartidas();
     $partidas = array();
     $productosPartidas = array();
     $presuPartida = new PresupuestoPartidas();
     //Todos los Presupuesto Partidas de un Proyecto o una accción
     $presupuestoPartidas = array();
     //$partidass = '';
     if (isset($_POST['Proyectos'])) {
         $proyectoSel->attributes = $_POST['Proyectos'];
         // Para el manejo del dropdown de acciones y proyectos
         //print_r($_POST['Proyectos']['proyecto_id']);
         if (!empty($_POST['Proyectos']['proyecto_id'])) {
             // Verificando si el id pasado es de una acción o un proyecto
             if (strstr($proyectoSel->proyecto_id, 'a')) {
                 $accionSel->accion_id = $this->accionId($proyectoSel->proyecto_id);
                 $partidas = $this->partidasAccion($accionSel->accion_id);
                 foreach (PresupuestoPartidaAcciones::model()->findAllByAttributes(array('accion_id' => $accionSel->accion_id, 'ente_organo_id' => $usuario->ente_organo_id, 'anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])) as $key => $value) {
                     //if($value->presupuestoPartida->partida_id == $partidaSel->partida_id)
                     //Todos los presupuestos partidas de la Acción seleccionada
                     $presupuestoPartidas[] = $value->presupuestoPartida;
                 }
             } else {
                 $proyectoActual = Proyectos::model()->findByPk($proyectoSel->proyecto_id);
                 $partidas = $this->partidasProyecto($proyectoSel->proyecto_id);
                 //Todos los Presupuesto Partidas del proyecto seleccionado
                 $presupuestoPartidas = $proyectoActual->presupuestoPartidas;
             }
             //$partidas = Partidas::model()->findByPk($partidas[0]->partida_id);
             //$partidas = $proyectoSel->presupuestoPartidaProyecto->presupuestoPartida;
             //print_r($_POST['Partidas']);
             if (isset($_POST['Partidas']) && !empty($_POST['Partidas']['partida_id'])) {
                 $partidaSel->attributes = $_POST['Partidas'];
                 //$presuPros = Proyectos::model()->findAllByAttributes(array('proyecto_id'=>attributeValue), condition, array('key'=>value))
                 $presuPartida = new PresupuestoPartidas();
                 if (!empty($accionSel->accion_id)) {
                     foreach (PresupuestoPartidaAcciones::model()->findAllByAttributes(array('accion_id' => $accionSel->accion_id, 'ente_organo_id' => $usuario->ente_organo_id, 'anho' => Yii::app()->params['trimestresFechas'][Yii::app()->session['trimestreSeleccionado']]['anho'])) as $key => $value) {
                         if ($value->presupuestoPartida->partida_id == $partidaSel->partida_id) {
                             $presuPartida = $value->presupuestoPartida;
                         }
                     }
                 }
                 if (isset($proyectoActual)) {
                     foreach ($proyectoActual->presupuestoPartidas as $key => $presupuestoPartida) {
                         if ($presupuestoPartida->partida_id == $partidaSel->partida_id) {
                             $presuPartida = $presupuestoPartida;
                         }
                     }
                 }
                 //$productosPartidas = Partidas::model()->findByPk($partidaSel->partida_id)->productos;
                 // Producto Nacional
                 if (isset($_POST['Productos']) && !empty($_POST['Productos']['producto_id'])) {
                     $productoSel->attributes = $_POST['Productos'];
                 }
                 //$this->render('_importado',array('presuImps'=>$presuImps));
                 //Yii::app()->end();
             }
         }
     }
     // Producto Importado
     if (isset($_POST['PresupuestoImportacion'])) {
         $presuImp->attributes = $_POST['PresupuestoImportacion'];
         $presuImp->presupuesto_partida_id = $presuPartida->presupuesto_partida_id;
         $presuImp->monto_ejecutado = 0;
         $presuImp->producto_id = $productoSel->producto_id;
         $par = Partidas::model()->findByPk($partidaSel->partida_id);
         if ($par->p1 == '403') {
             // Servicios
             $presuImp->codigo_ncm_id = CodigosNcm::model()->findByAttributes(array('codigo_ncm_nivel_1' => '0'))->codigo_ncm_id;
         }
         if ($presuImp->validate()) {
             $total = $this->montoCargadoPartida($presuPartida);
             //throw new Exception("Error ".$presuImp->divisa->tasa->tasa." Request", 1);
             if (@($presuPartida->monto_presupuestado >= $total + $presuImp->monto_presupuesto * $presuImp->divisa->tasa->tasa * $presuImp->cantidad)) {
                 $transaction = $presuImp->dbConnection->beginTransaction();
                 // Transaction begin //Yii::app()->db->beginTransaction
                 try {
                     if ($presuImp->save()) {
                         $transaction->commit();
                         // committing
                         $presuImp = new PresupuestoImportacion();
                         Yii::app()->user->setFlash('success', "Producto cargado con  éxito!");
                     } else {
                         Yii::app()->user->setFlash('error', "No se pudo guardar el producto.");
                         $transaction->rollBack();
                     }
                 } catch (Exception $e) {
                     Yii::app()->user->setFlash('error', "No se guardo el producto o servicio.");
                     $transaction->rollBack();
                 }
             } else {
                 Yii::app()->user->setFlash('notice', "No se agrego el producto valorado en " . number_format($presuImp->monto_presupuesto * $presuImp->divisa->tasa->tasa * $presuImp->cantidad, 2, ',', '.') . " Bs. La partida lleva cargada un monto en productos de " . number_format($total, 2, ',', '.') . " Bs.  y el monto presupuestado para esta partida es de " . number_format($presuPartida->monto_presupuestado, 2, ',', '.') . ' Bs.');
             }
         }
         //$this->guardarPresupuestoProductos($presuPro);
     }
     //Recargando listas
     if (!empty($partidaSel->partida_id) && !empty($proyectoSel->proyecto_id)) {
         //Listando todos los productos que ya se han cargado
         foreach ($presupuestoPartidas as $key => $presupuestoPartida) {
             if ($presupuestoPartida->partida_id == $partidaSel->partida_id) {
                 $presuImps = $presupuestoPartida->presupuestoImportacion;
             }
         }
         $productosPartidas = $this->listaProductosPartida($partidaSel->partida_id, $proyectoSel->proyecto_id, 'i');
         //Partidas::model()->findByPk($partidaSel->partida_id)->productos;
         $productosPartidas = CHtml::listData($productosPartidas, 'producto_id', function ($producto) {
             return CHtml::encode($this->numeroProducto($producto) . ' - ' . $producto->nombre);
         });
     }
     $this->render('importado', array('usuario' => $usuario, 'proyectoSel' => $proyectoSel, 'accionSel' => $accionSel, 'partidas' => $partidas, 'partidaSel' => $partidaSel, 'productoSel' => $productoSel, 'presuImps' => $presuImps, 'presuImp' => $presuImp, 'productosPartidas' => $productosPartidas, 'codigoNcmSel' => $codigoNcmSel));
 }