// function form_presupuesto
        
            private function form_presupuesto(CDBEntidad $oEntidadPedido)
            {   
                $oEntidadProducto = $this->modulo->getEntidad('producto');
                $oEntidadProductoExt = $this->modulo->getEntidad('producto_ext');
                $oEntidadConcepto = $this->modulo->getEntidad('concepto');
                $this->modulo->load->modelo('pedido');
                $this->modulo->load->helper('currency');
                
            // formulario presupuesto
                
                $oForm = new CForm('FormPresupuesto');
                
                $oForm->setTitle($this->modulo->lang->PRESUPUESTO);
 
                if( ($cesta_info = $this->modulo->modelo['pedido']->getCestaInfo($oEntidadPedido->getId())) == false )
                {
                    $this->log->addMessageError($this->root_modulo->lang->ERROR_CARGAR.'('.$this->modulo->lang->PEDIDO.')');
                }
                else
                {
                    $conceptos_editables = in_array($oEntidadPedido->getEstado(), $this->modulo->modelo['pedido']->getEstadosConceptosEditables() );                     
                // estado
 
                    if( !$conceptos_editables )
                    {
                        $oForm->select('estado', $this->modulo->lang->PEDIDO_ESTADO, $this->modulo->modelo['pedido']->getEstadoArray(), $oEntidadPedido->getEstado(), true);
                    }
                    //$pedido_estados = $this->modulo->modelo['pedido']->getEstadoArray();
                    //$oForm->static_text('estado', $this->modulo->lang->PEDIDO_ESTADO, $pedido_estados[$oEntidadPedido->getEstado()]);
 
                    
                // cargamos la plantilla asociada
                
                    $oTemplate = new NokTemplate( $this->modulo->getDirTemplates() );
                    
                    $oTemplate->cargar( 'tpMain', 'common.presupuesto.tpl' );
                    
                    $oTemplate->definirBloque( 'tpForm', 'tpMain');
                    $oTemplate->definirBloque( 'tpFormProducto', 'tpMain');
                    $oTemplate->definirBloque( 'tpFormExtra', 'tpMain');
                    
                    $oTemplate->asignar('NOMBRE_LABEL', $this->modulo->lang->PRODUCTO_NOMBRE);
                    $oTemplate->asignar('PRECIO_LABEL', $this->modulo->lang->PRODUCTO_PRECIO);
                    $oTemplate->asignar('DESCUENTO_LABEL', $this->modulo->lang->PRODUCTO_DESCUENTO.' %');
                    $oTemplate->asignar('CANTIDAD_LABEL', $this->modulo->lang->CONCEPTO_CANTIDAD);
                    $oTemplate->asignar('SUBTOTAL_LABEL', $this->modulo->lang->CESTA_SUBTOTAL);
 
                    foreach( $cesta_info['productos'] as $producto_id => $producto_info )
                    {       
                        if( $conceptos_editables )
                        {
                            $oFormFieldDescuento = new CFormFieldText
($oForm, 'descuento['.$producto_id.']', null, false, array('size'=>'6'), $producto_info['descuento'] );                             $html_descuento = $oFormFieldDescuento->getHtmlField();
                            
                            $oFormFieldCantidad = new CFormFieldText
($oForm, 'cantidad['.$producto_id.']', null, false, array('size'=>'6'), $producto_info['cantidad'] );                             $html_cantidad = $oFormFieldCantidad->getHtmlField();
                        }
                        else 
                        {
                            $html_descuento = $producto_info['descuento'] == null ? '-' : $producto_info['descuento'];
                            $html_cantidad = $producto_info['cantidad'];
                        }
                        
                        $oTemplate->asignar('NOMBRE_VALUE', $producto_info['nombre']);
                        $oTemplate->asignar('PRECIO_VALUE', format_currency($producto_info['precio']));
                        $oTemplate->asignar('DESCUENTO_VALUE', $html_descuento);
                        $oTemplate->asignar('CANTIDAD_VALUE', $html_cantidad);
                        $oTemplate->asignar('SUBTOTAL_VALUE', format_currency($producto_info['subtotal']));
                        
                        $oTemplate->expandir('PRODUCTOS', '+tpFormProducto');
                    }
 
                // encuadernacion
                
                    if( $conceptos_editables )
                    {
                        $oFormFieldEncuadernacion = new CFormFieldText
($oForm, 'encuadernacion', null, false, array('size'=>'6'), $cesta_info['encuadernacion'] );                         $html_encuadernacion = $oFormFieldEncuadernacion->getHtmlField();
                    }
                    else 
                    {
                        $html_encuadernacion = $cesta_info['encuadernacion'];
                    }
                    
                    $oTemplate->asignar('EXTRA_LABEL', $this->modulo->lang->CESTA_ENCUADERNACION);
                    $oTemplate->asignar('EXTRA_VALUE', $html_encuadernacion.' '.CLocale::getInstance()->getCurrencySign());
                    $oTemplate->expandir('EXTRAS', '+tpFormExtra');
                    
                    $subtotal += $oEntidadPedido->getAux1();
                        
                // gastos de envio
                
                    if( $conceptos_editables )
                    {
                        $oFormFieldGastosEnvio = new CFormFieldText
($oForm, 'ship_tax', null, false, array('size'=>'6'), $cesta_info['ship_tax'] );                         $html_gastos_envio = $oFormFieldGastosEnvio->getHtmlField();
                    }
                    else
                    {
                        $html_gastos_envio = $cesta_info['ship_tax'];
                    }
                    
                    $oTemplate->asignar('EXTRA_LABEL', $this->modulo->lang->PEDIDO_SHIP_TAX);
                    $oTemplate->asignar('EXTRA_VALUE', $html_gastos_envio.' '.CLocale::getInstance()->getCurrencySign());
                    $oTemplate->expandir('EXTRAS', '+tpFormExtra');
                    
                // subtotal
                
                    $oTemplate->asignar('EXTRA_LABEL', $this->modulo->lang->CESTA_SUBTOTAL);
                    $oTemplate->asignar('EXTRA_VALUE', format_currency($cesta_info['subtotal']));
                    $oTemplate->expandir('EXTRAS', '+tpFormExtra');
                    
                // iva
                
                    $oTemplate->asignar('EXTRA_LABEL', sprintf($this->modulo->lang->PEDIDO_TAX, $this->modulo->config->pedido->tax));                     $oTemplate->asignar('EXTRA_VALUE', format_currency($cesta_info['tax']));
                    $oTemplate->expandir('EXTRAS', '+tpFormExtra');
                    
                    $subtotal += $tax;
                    
                // total
                
                    $oTemplate->asignar('EXTRA_LABEL', $this->modulo->lang->CESTA_TOTAL);
                    $oTemplate->asignar('EXTRA_VALUE', '<b>'.format_currency($cesta_info['total']).'</b>');
                    $oTemplate->expandir('EXTRAS', '+tpFormExtra');
                    
                    $oTemplate->expandir('FORM_PRESUPUESTO', 'tpForm');
                
                // tabla
                
                    $oForm->insert_html($oTemplate->exportar('FORM_PRESUPUESTO'));
                        
                // botones
                
                    $oForm->input_submit('submit', $this->root_modulo->lang->GUARDAR);
                    $oForm->input_reset('reset', $this->root_modulo->lang->RESTAURAR);
                    
                    
                // validaciones
                
                    //$oForm->addValidation(new CValidatorCurrency($oFormFieldGastosEnvio));
                    //$oForm->addValidation(new CValidatorCurrency($oFormFieldEncuadernacion));
                }
                
            // borramos las variables de sesion asociadas
            
                $oForm->deleteAll();
                
                return $oForm;
            }