<?php
class monedaActions extends wtActions
{
    public function executeIndex()
    {
        
    }
    
    public function executeList()
    {
    	$this->block = $this->getRequestParameter( 'block' );
    	
    }
    
    public function executeGrid()
    {
       
        $block = $this->getRequestParameter( 'block' );
        $page  = $this->getRequestParameter( 'page' );
        
         set_header_utf8();
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        $o_GridAction = new GridAction();
        $o_GridAction->setClassFind( new GSS_MonedaMastFN() );
        
        $o_GridAction->addConditionFilter( "Descripcion", GSS_MonedaMastFN::Descripcion, "LIKE", "%%s%" );
        
        $o_GridAction->addOrder( "Descripcion", GSS_MonedaMastFN::Descripcion);
        
        $o_GridAction->addOrder( "Sigla", GSS_MonedaMastFN::Sigla);
        
        $o_GridAction->addOrder( "Estado", GSS_MonedaMastFN::Estado );
        
        $o_GridAction->addOrderDefault( GSS_MonedaMastFN::IdMoneda , true );
        
        $o_GridAction->addRowsToShow( "IdMoneda", "Descripcion","Sigla", "Estado" );
        
        $o_GridAction->setNumberRecordsShow( 15 );
        
        $o_GridAction->initialize();
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        $a_ResultJson['page']    = $o_GridAction->getPage();
        $a_ResultJson['total']   = $o_GridAction->getTotalPage();
        $a_ResultJson['records'] = $o_GridAction->getTotalRecords();
        $a_ResultJson['rows']    = $o_GridAction->getResultArray();
        //pr( $a_ResultJson );
        echo json_encode( $a_ResultJson );

        return ViewResponse::NONE;   
    }
    
    
   
    public function executeAddedit()
    {
        $this->block      = $this->getRequestParameter( 'block' );
        $this->i_Id       = $this->getRequestParameter( 'i_Id' );
        $this->s_TipoProc = $this->getRequestParameter( 's_TipoProc' );
        
                
        $this->s_Titulo = "Nueva Moneda";
        
         /************/
        
        $o_GSS_MonedaMastBN = new GSS_MonedaMastBN();
        $o_GSS_MonedaMastBN->setEstado('A');
        $this->o_GSS_MonedaMastBN = $o_GSS_MonedaMastBN;
        
        /*************/
        //$this->o_ALM_MarcaBN = new ALM_MarcaBN();
        if( $this->s_TipoProc == "upd" )
        {
            $this->s_Titulo = "Editar Moneda";
            $o_GSS_MonedaMastFN = new GSS_MonedaMastFN();
            $this->o_GSS_MonedaMastBN = $o_GSS_MonedaMastFN->selectByPK( $this->i_Id );
        }
    }
   
    public function executeSaveAddEdit()
    {
        $block      = $this->getRequestParameter( 'block' );
        $i_Id       = $this->getRequestParameter( 'i_Id' );
        $s_TipoProc = $this->getRequestParameter( 's_TipoProc' );
        $TypeSub    = $this->getRequestParameter( 'TypeSub' );
        
        
        $IdMoneda        = $this->getRequestParameter( 'IdMoneda' );
        $Descripcion    = $this->getRequestParameter( 'Descripcion' );
        $Sigla          = $this->getRequestParameter( 'Sigla' );
        $Estado         = $this->getRequestParameter( 'Estado' );
        try         
        
        {            
        	$o_GSS_MonedaMastDP = new GSS_MonedaMastDP();            
            $o_GSS_MonedaMastDP->setDescripcion($Descripcion);
            $o_GSS_MonedaMastDP->setSigla( $Sigla);
            $o_GSS_MonedaMastDP->setEstado( $Estado );
            
            if( $s_TipoProc == "nvo" )
            {
                //NUEVO
                //$IdMarca = ALM_MarcaFN::recuperarId();
                $o_GSS_MonedaMastDP->setIdMoneda( $IdMoneda );
                $o_GSS_MonedaMastDP->setFechaCreacion( date( "Y-m-d H:i:s" ) );
                $o_GSS_MonedaMastDP->setUsuarioCreacion( myUser::getUser()->getUserId() );
                $o_GSS_MonedaMastDP->setFechaModificacion( date( "Y-m-d H:i:s" ) );
                $o_GSS_MonedaMastDP->setUsuarioModificacion( myUser::getUser()->getUserId() );
                $b_Result = $o_GSS_MonedaMastDP->save();
                $i_Id = $IdMoneda;
            }
            else 
            {
                //UPDATE
                
                
                //$i_Id = ( int ) $this->getRequestParameter( 'i_Id' );
                $o_GSS_MonedaMastDP->setIdMoneda($i_Id );
                $o_GSS_MonedaMastDP->setFechaModificacion( date( "Y-m-d H:i:s" ) );
                $o_GSS_MonedaMastDP->setUsuarioModificacion( myUser::getUser()->getUserId() );
                $b_Result = $o_GSS_MonedaMastDP->update();
            }
            
            $a_Rs['type_sub'] = $TypeSub;
            $a_Rs['error']    = false;
            $a_Rs['id']       = $i_Id;
        }
        catch ( Exception $o_Exception )
        {
            $a_Rs['error']         = true;
            $a_Rs['mensaje_error'] = $o_Exception->getMessage();
        }
        echo json_encode( $a_Rs );
        return ViewResponse::NONE;
    }
    
    public function executeAudi()
    {
        $block          = $this->getRequestParameter( 'block' );
        $i_Id           = $this->getRequestParameter( 'i_Id' );
        $this->s_Topico = "Moneda";
        $o_GSS_MonedaMastFN = new GSS_MonedaMastFN();
        $this->o_ObjectBN = $o_GSS_MonedaMastFN->selectByPK( $i_Id );
    }
    
    public function executeViewdel()
    {
        $this->block      = $this->getRequestParameter( 'block' );
        $this->i_Id       = $this->getRequestParameter( 'i_Id' );
        $this->s_TipoProc = $this->getRequestParameter( 's_TipoProc' );
       
        
        $o_GSS_MonedaMastFN = new GSS_MonedaMastFN();
        $this->o_GSS_MonedaMastBN = $o_GSS_MonedaMastFN->selectByPK( $this->i_Id );
    }
    
    /* public function executeDeleteRow()
    {
        $block      = $this->getRequestParameter( 'block' );
        $i_Id       = $this->getRequestParameter( 'i_Id' );
        $s_TipoProc = $this->getRequestParameter( 's_TipoProc' );
        try 
        {
            $o_MST_UnidadMastDP = new MST_UnidadMastDP();
            $o_MST_UnidadMastDP->setIdUnidad( $i_Id );
            $o_MST_UnidadMastDP->delete();

            $a_Rs['error']   = false;
            $a_Rs['id']      = $i_Id;
        }
        catch ( Exception $o_Exception )
        {
            $a_Rs['error']   = true;
            $a_Rs['mensaje_error_ex'] = $o_Exception->getMessage();
            $a_Rs['mensaje_error'] = "No se pudo eliminar el registro.";
        }
        echo json_encode( $a_Rs );
        return ViewResponse::NONE;
    }*/
    
    
    public function executeDeleteRow()
    {
        $block      = $this->getRequestParameter( 'block' );
        $i_Id       = $this->getRequestParameter( 'i_Id' );
        $s_TipoProc = $this->getRequestParameter( 's_TipoProc' );
        
        try 
        {
        	
            $o_GSS_MonedaMastDP = new GSS_MonedaMastDP();
           // $o_MST_UnidadMastDP->setIdUnidad( $i_Id );
            $o_GSS_MonedaMastDP->setIdMoneda($i_Id );
            $o_GSS_MonedaMastDP->delete();

            $a_Rs['error']   = false;
            $a_Rs['id']      = $i_Id;
        }
        catch ( Exception $o_Exception )
        {
            $a_Rs['error']   = true;
            $a_Rs['mensaje_error_ex'] = $o_Exception->getMessage();
            $a_Rs['mensaje_error'] = "No se pudo eliminar el registro.";
        }
        echo json_encode( $a_Rs );
        return ViewResponse::NONE;
    }
}