<?php
/**
 * Clase DP para RhPensionDevengueDP
 *
 * @package    
 * @subpackage RhPensionDevengueDP
 * @author     Willy
 * @version    SVN:: RhPensionDevengueDP.class.php,v 1.1 2015-01-23 19:01:22 william.taype Exp $
 */
class RhPensionDevengueDP extends BaseRhPensionDevengueDP
{
	
	public function save()
  {
    try
    {
      $con = Conexion::getConexion();
      
      if($this->getIdPeriodo() && $this->getIdPension()){
        $a_Fields = array();

        if($this->getIdPeriodo()) : $a_Fields['IdPeriodo'] = ($this->getIdPeriodo()); endif;
        if($this->getIdPension()) : $a_Fields['IdPension'] = ($this->getIdPension()); endif;
        if($this->getComisionFija()) : $a_Fields['ComisionFija'] = ($this->getComisionFija()); endif;
        if($this->getComisionFlujo()) : $a_Fields['ComisionFlujo'] = ($this->getComisionFlujo()); endif;
        if($this->getComisionMixtaFlujo()) : $a_Fields['ComisionMixtaFlujo'] = ($this->getComisionMixtaFlujo()); endif;
        if($this->getComisionAnualSaldo()) : $a_Fields['ComisionMixtaASaldo'] = ($this->getComisionAnualSaldo()); endif;
        if($this->getSeguro()) : $a_Fields['Seguro'] = ($this->getSeguro()); endif;
        if($this->getPorcentajeAporteObligatorio()) : $a_Fields['PorcentajeAporteObligatorio'] = ($this->getPorcentajeAporteObligatorio()); endif;
        if($this->getRMA()) : $a_Fields['RMA'] = ($this->getRMA()); endif;
        if($this->getFechaRegistro()) : $a_Fields['FechaRegistro'] = ($this->getFechaRegistro()); endif;
        if($this->getUsuarioRegistro()) : $a_Fields['UsuarioRegistro'] = ($this->getUsuarioRegistro()); endif;

        $sStringField = arrayClass::implode_keys(',', $a_Fields);
        $sStringValue = "'".implode("','", $a_Fields)."'";

        $sql = "REPLACE INTO rh_pension_devengue (".$sStringField.") VALUES (".$sStringValue.");";
        
        $oLink = method_exists($con, 'getResource')?$con->getResource():$con;
        $result = mysql_query($sql, $oLink);
        if($result)
        {
          $this->nRowsAffected = (int) mysql_affected_rows($oLink);
        }
        else
        {
          throw new Exception( mysql_error($oLink) );
        }
      }
      else
      {
        throw new Exception( 'El id no esta registrado.');
      }
    }
    catch ( Exception $o_Error )
    {
      throw new Exception($o_Error->getMessage().' en '.$o_Error->getFile().' linea '.$o_Error->getLine());
    }
    return true;
  }
}