<?php
class DetailV3Action extends wtActions
{
    public function execute()
    {
        LayoutTemplate::getInstance()->setUseBootstrap();
        
        $this->block      = $this->getRequestParameter( 'block' );
        $this->i_Id       = $this->getRequestParameter( 'i_Id' );
        $this->s_TipoProc = $this->getRequestParameter( 's_TipoProc' );
        $this->s_IdRango  = $this->getRequestParameter( 'IdRango' );
        
        $this->s_Titulo = "Editar Lista de Precios";
        
        $this->IdCompania = myUser::getUser()->getIdCompania();
        $this->IdSucursal = myUser::getUser()->getIdSucursal();
        
        $this->IdItem       = $this->getRequestParameter( 'IdItem' );
        $this->IdLinea      = $this->getRequestParameter( 'IdLinea' );
        $this->IdFamilia    = $this->getRequestParameter( 'IdFamilia' );
        
        $o_DefaultFN = new MST_ListaPrecioCabeceraFN();
        $o_DefaultFN->setIdListaPreciCab( $this->i_Id );
        $this->o_DefaultBN = $o_DefaultFN->selectByPK( $this->IdCompania, $this->IdSucursal );
        
        $this->a_ALM_ItemMast = array();
        
        $o_ALM_ItemMastFN = new ALM_ItemMastFN();
        $o_ALM_ItemMastFN->setEstado( "A" );
        $o_ALM_ItemMastFN->addCondition( ALM_ItemMastFN::IdItemTipo, "NOT IN", "('02')", false );
        $o_ALM_ItemMastFN->addCondition( ALM_ItemMastFN::IdItem, "NOT IN", "('ZZDSCTO')", false );
        $o_ALM_ItemMastFN->addOrderBy( ALM_ItemMastFN::DescripcionCompleta );
        
        if( $this->IdItem )
        {
            $o_ALM_ItemMastFN->setIdItem( $this->IdItem );
            
            $o_TMP_ALM_ItemMastFN = new ALM_ItemMastFN();
            $o_TMP_ALM_ItemMastBN = $o_TMP_ALM_ItemMastFN->selectByPK( $this->IdItem );
            if( $o_TMP_ALM_ItemMastBN )
            {
                if( $this->o_DefaultBN->getIdTipoLista() == 1 )
                {
                    if( $o_TMP_ALM_ItemMastBN->getEsParaVenta() == "SI" )
                    {
                        $this->s_IdRango = $o_TMP_ALM_ItemMastBN->getIdRangoVenta();
                    }
                }
                if( $this->o_DefaultBN->getIdTipoLista() == 2 )
                {
                    if( $o_TMP_ALM_ItemMastBN->getEsParaAlquiler() == "SI" )
                    {
                        $this->s_IdRango = $o_TMP_ALM_ItemMastBN->getIdRangoAlquiler();
                    }
                }
            }
        }
        
        $o_MST_ClaseLineaFN = new MST_ClaseLineaFN();
        $o_MST_ClaseLineaFN->setEstado( "A" );
        $o_MST_ClaseLineaFN->addOrderBy( MST_ClaseLineaFN::Descripcion );
        $this->a_MST_ClaseLinea = $o_MST_ClaseLineaFN->select();
        
        $this->a_MST_ClaseFamilia = array();
        if( $this->IdLinea )
        {
            $o_MST_ClaseFamiliaFN = new MST_ClaseFamiliaFN();
            $o_MST_ClaseFamiliaFN->setIdLinea( $this->IdLinea );
            $o_MST_ClaseFamiliaFN->setEstado( "A" );
            $this->a_MST_ClaseFamilia = $o_MST_ClaseFamiliaFN->select();
            
            $o_ALM_ItemMastFN->setIdLinea( $this->IdLinea );
        }
        
        if( $this->IdFamilia )
        {
            $o_ALM_ItemMastFN->setIdFamilia( $this->IdFamilia );
        }
        
        $this->a_MST_Rango = array();
        $o_MST_RangoFN = new MST_RangoFN();
        $o_MST_RangoFN->setFlagEncofrado( "0" );
        if( $this->o_DefaultBN->getIdTipoLista() == 1 )
        {
            $o_MST_RangoFN->setFlagVenta( 1 );
            $o_ALM_ItemMastFN->setEsParaVenta( "SI" );
            if( $this->s_IdRango )
            {
                $o_ALM_ItemMastFN->setIdRangoVenta( $this->s_IdRango );
            }
        }
        if( $this->o_DefaultBN->getIdTipoLista() == 2 )
        {
            $o_MST_RangoFN->setFlagAlquiler( 1 );
            $o_ALM_ItemMastFN->setEsParaAlquiler( 'SI' );
            if( $this->s_IdRango )
            {
                $o_ALM_ItemMastFN->setIdRangoAlquiler( $this->s_IdRango );
            }
        }
        if( $this->o_DefaultBN->getIdTipoLista() == 1 || $this->o_DefaultBN->getIdTipoLista() == 2 )
        {
            $this->a_MST_Rango = $o_MST_RangoFN->select();
        }
        else
        {
            $o_ALM_ItemMastFN->setEsParaAlquiler( "NO" );
            $o_ALM_ItemMastFN->setEsParaVenta( "NO" );
        }
        
        $this->a_MST_RangoDetalle = array();
        if( $this->s_IdRango )
        {
            $o_MST_RangoDetalleFN = new MST_RangoDetalleFN();
            $o_MST_RangoDetalleFN->setIdRango( $this->s_IdRango );
            $o_MST_RangoDetalleFN->addOrderBy( MST_RangoDetalleFN::Minimo );
            $this->a_MST_RangoDetalle = $o_MST_RangoDetalleFN->select();
        }

        if( $this->getRequestParameter( 'Control' ) )
        {
            $this->a_ALM_ItemMast = $o_ALM_ItemMastFN->select();
        }
        else
        {
            $this->a_ALM_ItemMast = array();
        }
    }
}