<?xml version="1.0" encoding="UTF-8"?>
<!-- Es un archivo de mapeo -->
<!DOCTYPE mapper
  PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.mx.dla.dda.reporte.pagosTransaccion.daos.TransaccionSAPDAO">
	
	<resultMap id="transaccion" type="com.mx.dla.dda.reporte.pagosTransaccion.dtos.TransaccionSAP">
		<result property="mes" column="MES" />
		<result property="idContrato" column="ID_CONTRATO" />
		<result property="idSAP" column="ID_SAP" />
		<result property="docMaterial" column="DOC_MATERIAL" />
		<result property="annio" column="ANNIO" />
	</resultMap>


	<select id="buscarTransaccionSAPPorID" resultMap="transaccion">
		select * from DDA_T_TRANSACCION_SAP where id_contrato = #{idContrato}
	</select>
	<select id="buscarTransaccionSAPPorMes" resultMap="transaccion">
		select * from DDA_T_TRANSACCION_SAP where to_char(mes,'mm-yyyy') = #{mes} 
	</select>
	<select id="buscarTransaccionSAPPorIDMes" resultMap="transaccion">
		select * from DDA_T_TRANSACCION_SAP where id_contrato = #{idContrato} and to_char(mes,'mm-yyyy') = #{mes}
	</select>
	
	<select id="buscarTransaccionSAPPorEstudioMes" resultMap="transaccion">
		select 
			count (*) from DDA_T_TRANSACCION_SAP ts 
		inner join DDA_T_CONTRATO c on c.ID_CONTRATO = ts.ID_CONTRATO
		where 
			c.ID_ESTUDIO = #{idEstudio} 
			and to_char(ts.mes,'mm-yyyy') = #{mes} 
	</select>
	
	<insert id="insertarTransaccionSAP"  parameterType="com.mx.dla.dda.reporte.pagosTransaccion.dtos.TransaccionSAP" >
		insert into DDA_T_TRANSACCION_SAP (MES,ID_CONTRATO,ID_SAP,DOC_MATERIAL,ANNIO) values (#{mes},#{idContrato},#{idSAP},#{docMaterial},#{annio})
	</insert>
	
</mapper>
