<?php
/* Autor...: William L. Taype Perez */
/* Esquema.: ALM_ReservaItemStock.xml */
/* Generado: 2020-08-18 04:21:24 */

/* Mantenimiento de los registros de la tabla ALM_ReservaItemStock */
abstract class BaseALM_ReservaItemStockDP extends ALM_ReservaItemStockBV
{
    /* Constructor ( Establece los valores desde un objeto ALM_ReservaItemStockBN ) */
    public function __construct( ALM_ReservaItemStockBN $o_ALM_ReservaItemStockBN = null )
    {
        parent::__construct();
        if ( !is_null( $o_ALM_ReservaItemStockBN ) )
        {
            $this->setByBN( $o_ALM_ReservaItemStockBN );
        }
    }

    public $b_Debug = false;

    public function getDebug()
    {
        if( SF_DEBUG )
        {
            $this->b_Debug = true;
        }
        return $this->b_Debug;
    }

    public function setDebug( $v )
    {
        $this->b_Debug = $v;
    }

    /* Establece los valores desde un objeto ALM_ReservaItemStockBN */
    public function setByBN( ALM_ReservaItemStockBN $o_ALM_ReservaItemStockBN )
    {
        if ( !is_null( $o_ALM_ReservaItemStockBN->getReservaId() ) )
        {
            $this->setReservaId( $o_ALM_ReservaItemStockBN->getReservaId() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getIdCompania() ) )
        {
            $this->setIdCompania( $o_ALM_ReservaItemStockBN->getIdCompania() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getIdSucursal() ) )
        {
            $this->setIdSucursal( $o_ALM_ReservaItemStockBN->getIdSucursal() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getIdAlmacen() ) )
        {
            $this->setIdAlmacen( $o_ALM_ReservaItemStockBN->getIdAlmacen() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getIdItem() ) )
        {
            $this->setIdItem( $o_ALM_ReservaItemStockBN->getIdItem() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getIdLote() ) )
        {
            $this->setIdLote( $o_ALM_ReservaItemStockBN->getIdLote() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getTipoOperacion() ) )
        {
            $this->setTipoOperacion( $o_ALM_ReservaItemStockBN->getTipoOperacion() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getReservaDocTipo() ) )
        {
            $this->setReservaDocTipo( $o_ALM_ReservaItemStockBN->getReservaDocTipo() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getReservaDocNumero() ) )
        {
            $this->setReservaDocNumero( $o_ALM_ReservaItemStockBN->getReservaDocNumero() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getReservaRefNumero() ) )
        {
            $this->setReservaRefNumero( $o_ALM_ReservaItemStockBN->getReservaRefNumero() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getReservaSecuencia() ) )
        {
            $this->setReservaSecuencia( $o_ALM_ReservaItemStockBN->getReservaSecuencia() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getReservaCantidad() ) )
        {
            $this->setReservaCantidad( $o_ALM_ReservaItemStockBN->getReservaCantidad() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getUsuarioCreacion() ) )
        {
            $this->setUsuarioCreacion( $o_ALM_ReservaItemStockBN->getUsuarioCreacion() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getFechaCreacion() ) )
        {
            $this->setFechaCreacion( $o_ALM_ReservaItemStockBN->getFechaCreacion() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getUsuarioActualizacion() ) )
        {
            $this->setUsuarioActualizacion( $o_ALM_ReservaItemStockBN->getUsuarioActualizacion() );
        }
        if ( !is_null( $o_ALM_ReservaItemStockBN->getFechaActualizacion() ) )
        {
            $this->setFechaActualizacion( $o_ALM_ReservaItemStockBN->getFechaActualizacion() );
        }
    }

    /* Graba un nuevo registro */
    public function save()
    {
        $this->validateRecord();
        $o_ALM_ReservaItemStockFN = new ALM_ReservaItemStockFN();
        $o_ALM_ReservaItemStockBN = $o_ALM_ReservaItemStockFN->selectByPk( $this->getReservaId() );
        if ( is_null( $o_ALM_ReservaItemStockBN ) )
        {
            $s_SQLQuery1 = "INSERT INTO ALM_ReservaItemStock ( ";
            $s_SQLQuery2 = "VALUES ( ";
            $s_Separator = "";
            if ( !is_null( $this->getReservaId() ) )
            {
                $s_SQLQuery1 .= $s_Separator."ReservaId";
                $s_SQLQuery2 .= $s_Separator."".$this->getReservaId()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdCompania() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdCompania";
                $s_SQLQuery2 .= $s_Separator."".$this->getIdCompania()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdSucursal() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdSucursal";
                $s_SQLQuery2 .= $s_Separator."".$this->getIdSucursal()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdAlmacen() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdAlmacen";
                $s_SQLQuery2 .= $s_Separator."'".$this->getIdAlmacen()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdItem() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdItem";
                $s_SQLQuery2 .= $s_Separator."'".$this->getIdItem()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdLote() ) )
            {
                $s_SQLQuery1 .= $s_Separator."IdLote";
                $s_SQLQuery2 .= $s_Separator."'".$this->getIdLote()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getTipoOperacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."TipoOperacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getTipoOperacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaDocTipo() ) )
            {
                $s_SQLQuery1 .= $s_Separator."ReservaDocTipo";
                $s_SQLQuery2 .= $s_Separator."'".$this->getReservaDocTipo()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaDocNumero() ) )
            {
                $s_SQLQuery1 .= $s_Separator."ReservaDocNumero";
                $s_SQLQuery2 .= $s_Separator."'".$this->getReservaDocNumero()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaRefNumero() ) )
            {
                $s_SQLQuery1 .= $s_Separator."ReservaRefNumero";
                $s_SQLQuery2 .= $s_Separator."'".$this->getReservaRefNumero()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaSecuencia() ) )
            {
                $s_SQLQuery1 .= $s_Separator."ReservaSecuencia";
                $s_SQLQuery2 .= $s_Separator."".$this->getReservaSecuencia()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaCantidad() ) )
            {
                $s_SQLQuery1 .= $s_Separator."ReservaCantidad";
                $s_SQLQuery2 .= $s_Separator."".$this->getReservaCantidad()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioCreacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."UsuarioCreacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getUsuarioCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaCreacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."FechaCreacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getFechaCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioActualizacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."UsuarioActualizacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getUsuarioActualizacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaActualizacion() ) )
            {
                $s_SQLQuery1 .= $s_Separator."FechaActualizacion";
                $s_SQLQuery2 .= $s_Separator."'".$this->getFechaActualizacion()."'";
                $s_Separator = ", ";
            }
            $s_SQLQuery = $s_SQLQuery1." ) ".$s_SQLQuery2." );";
            $o_Resource = Conexion::getConexion();
            $o_Statement = $o_Resource->createStatement();
            $o_Statement->executeQuery( $s_SQLQuery );
            if( $this->getDebug() ){ pr( $s_SQLQuery ); }
        }
        else
        {
            throw new Exception( "El id ya esta registrado." );
        }
        return true;
    }

    /* Actualiza los datos del registro */
    public function update()
    {
        $this->validateRecord();
        if ( true )
        {
            $s_SQLQuery = "UPDATE ALM_ReservaItemStock SET ";
            $s_Separator = "";
            if ( !is_null( $this->getIdCompania() ) )
            {
                $s_SQLQuery .= $s_Separator."IdCompania = ".$this->getIdCompania()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdSucursal() ) )
            {
                $s_SQLQuery .= $s_Separator."IdSucursal = ".$this->getIdSucursal()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdAlmacen() ) )
            {
                $s_SQLQuery .= $s_Separator."IdAlmacen = '".$this->getIdAlmacen()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdItem() ) )
            {
                $s_SQLQuery .= $s_Separator."IdItem = '".$this->getIdItem()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getIdLote() ) )
            {
                $s_SQLQuery .= $s_Separator."IdLote = '".$this->getIdLote()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getTipoOperacion() ) )
            {
                $s_SQLQuery .= $s_Separator."TipoOperacion = '".$this->getTipoOperacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaDocTipo() ) )
            {
                $s_SQLQuery .= $s_Separator."ReservaDocTipo = '".$this->getReservaDocTipo()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaDocNumero() ) )
            {
                $s_SQLQuery .= $s_Separator."ReservaDocNumero = '".$this->getReservaDocNumero()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaRefNumero() ) )
            {
                $s_SQLQuery .= $s_Separator."ReservaRefNumero = '".$this->getReservaRefNumero()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaSecuencia() ) )
            {
                $s_SQLQuery .= $s_Separator."ReservaSecuencia = ".$this->getReservaSecuencia()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getReservaCantidad() ) )
            {
                $s_SQLQuery .= $s_Separator."ReservaCantidad = ".$this->getReservaCantidad()."";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioCreacion() ) )
            {
                $s_SQLQuery .= $s_Separator."UsuarioCreacion = '".$this->getUsuarioCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaCreacion() ) )
            {
                $s_SQLQuery .= $s_Separator."FechaCreacion = '".$this->getFechaCreacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getUsuarioActualizacion() ) )
            {
                $s_SQLQuery .= $s_Separator."UsuarioActualizacion = '".$this->getUsuarioActualizacion()."'";
                $s_Separator = ", ";
            }
            if ( !is_null( $this->getFechaActualizacion() ) )
            {
                $s_SQLQuery .= $s_Separator."FechaActualizacion = '".$this->getFechaActualizacion()."'";
                $s_Separator = ", ";
            }
            $s_SQLQuery .= " WHERE  ReservaId = ".$this->getReservaId().";";
            $o_Resource = Conexion::getConexion();
            $o_Statement = $o_Resource->createStatement();
            $o_Statement->executeQuery( $s_SQLQuery );
            if( $this->getDebug() ){ pr( $s_SQLQuery ); }

        }
        else
        {
            throw new Exception( "El id no esta registrado." );
        }
        return true;
    }

    /* Elimina el registro */
    public function delete()
    {
        $s_SQLQuery = "DELETE FROM ALM_ReservaItemStock WHERE  ReservaId = ".$this->getReservaId().";";
        $o_Resource = Conexion::getConexion();
        $o_Statement = $o_Resource->createStatement();
        $o_Statement->executeQuery( $s_SQLQuery );
        if( $this->getDebug() ){ pr( $s_SQLQuery ); }
        return true;
    }

}
?>