<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of actions
 * Pretende editar la liquidación de aportes de un funcionario
  * @package    nomina
 * @subpackage edit_liquida_aporte
 * @author Manuel Enrique Paredes Lopez
 */
class edit_liquida_aporteActions extends sfActions{
    //put your code here
    /**
     * Executes list action
     *
     * @param sfRequest $request A request object
     */
    public function executeAdd(sfWebRequest $request) {
        
       
        $this->logMessage("---BEGIN Logging request");
        foreach ($request->getPostParameters() as $key => $value) {
            $this->logMessage("request[$key] = $value");
        }
        $this->logMessage("--------------------------------------------------*  Ip: " . $_SERVER['REMOTE_ADDR']);
        foreach ($request->getGetParameters() as $key => $value) {
            $this->logMessage("request[$key] = $value");
        }
        $this->logMessage("---END Logging request");

         /**
             * Abrir nueva conexion con la Base de Datos
             */
            $this->conn = Doctrine_Manager::getInstance()->getCurrentConnection();
            $this->conn->beginTransaction();
        
        /**
             * Aporte funcionario
             */
            if (isset($request['aporte_func'])) {
                $aporte_func = $request['aporte_func'];
            } else {
                $aporte_func = 0;
            }
            
                 /**
             * Aporte patronal
             */
            if (isset($request['aporte_patrono'])) {
                $aporte_patrono = $request['aporte_patrono'];
            } else {
                $aporte_patrono =0;
            }
            
            
                /**
             * tarifa
             */
            
             if (isset($request['tarifa'])) {
                $tarifa = $request['tarifa'];
            } else {
                $tarifa =0;
            }
            
                /**
             * valor base
             */
             if (isset($request['valor_base'])) {
                $valor_base = $request['valor_base'];
            } else {
                $valor_base =0;
            }
            
            
               /**
             * id_liquida_aporte
             */
             if (isset($request['num_dias'])) {
                $num_dias = $request['num_dias'];
            } else {
                $num_dias =0;
            }
            
            
               /**
             * id_liquida_aporte
             */
             if (isset($request['id_liquida_aporte'])) {
                $id_liquida_aporte = $request['id_liquida_aporte'];
            } else {
                $id_liquida_aporte = 0;
            }
            
            
        
        
        try{
            
                //sentencia sql
            $sql = <<<EOD
ALTER SESSION SET NLS_DATE_FORMAT = "YYYY-MM-DD"
EOD;
            //ejecuta y obtiene el resultado del sql
            CN_TABLE::executeSQL($sql);

            
            
            $sql = <<<EOD
                    
                    UPDATE NO_LIQUIDA_APORTE
        SET 
       VALOR_BASE = $valor_base,
       APORTE_FUNC = $aporte_func,
       APORTE_PATRONO = $aporte_patrono,
       NUM_DIAS = $num_dias
WHERE ID_LIQUIDA_APORTE = $id_liquida_aporte
EOD;
            
            CN_TABLE::executeSQL($sql);
            
            
            
            $records = array(
                'update'=>1
            );

            $this->totalRows = 0;
            $this->startRow = 0;
            $this->endRow = 0;
            $this->list_data = $records;
            $this->logMessage("[edit_liquida_aporte] Actualización exitosa.");
            $this->conn->commit();
        } catch (Exception $ex) {
            
            
              $mensaje = "[edit_liquida_aporte] ERROR!!!";

            $this->status = 1;
            $this->mensajeError = $mensaje;
            $this->list_data = array();
            $this->logMessage($mensaje);
            $this->logMessage($e->getMessage());

            $this->conn->rollback();

        }
        
    }
    
}
