package sikd.sikd5.sikd5ejb.mapper.transaksi;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.type.JdbcType;

import sikd.sikd5.sikd5bean.tabel.transaksi.Headerjurnal;
import sikd.sikd5.sikd5bean.ws.transaksi.Headerjurnal_WS;

/**
 * @oleh : agus
 * @tanggal : May 13, 2019
 */
@SuppressWarnings("el-syntax")
public interface HeaderjurnalMapper {

	@Delete({
			"delete from transaksi.headerjurnal",
			"where headerjurnalid = #{headerjurnalid,jdbcType=BIGINT}"
	})
	int deleteHeaderJurnalByPrimaryKey(Long headerjurnalid);

	@Delete({
			"delete from transaksi.headerjurnal",
			"where tahunanggaran = #{record.tahunanggaran} and kodesatker=#{record.kodesatker} and ",
			"nomorbukti=#{record.nomorbukti} and tanggalbukti=#{record.tanggalbukti}"
	})

	int deleteHeaderJurnalByBukti(@Param("record") Headerjurnal_WS record);

	@Select({
			"insert into transaksi.headerjurnal (headerlogidinsert, ",
			"tahunanggaran, kodesatker, kodepemda, namapemda, jeniscoa,",
			"nomorbukti, ",
			"tanggalbukti, sha256)",
			"values (#{headerlogidinsert,jdbcType=BIGINT}, ",
			"#{record.tahunanggaran,jdbcType=INTEGER}, #{record.kodesatker,jdbcType=VARCHAR},#{record.kodepemda,jdbcType=VARCHAR},",
			"#{record.namapemda,jdbcType=VARCHAR},#{record.jeniscoa,jdbcType=INTEGER}, ",
			"#{record.nomorbukti,jdbcType=VARCHAR}, ",
			"#{record.tanggalbukti,jdbcType=TIMESTAMP}, #{record.sha256,jdbcType=CHAR})",
			"returning headerjurnalid"
	})
	long insertHeaderJurnal(@Param("record") Headerjurnal_WS record, @Param("headerlogidinsert") long headerlogidinsert);

	@Update({
			"update transaksi.headerjurnal",
			"set ",
			"headerlogidiupdate = #{headerlogidiupdate,jdbcType=BIGINT},",
			"where headerjurnalid = #{headerjurnalid,jdbcType=BIGINT}"
	})
	int updateLogUpdateHeaderJurnal(@Param("headerjurnalid") long headerjurnalid, @Param("headerlogidiupdate") long headerlogidiupdate);

	@Select({
			"select",
			"headerjurnalid, headerlogidinsert, headerlogidiupdate, tahunanggaran, kodesatker, ",
			"kodepemda, namapemda, jeniscoa, nomorbukti, tanggalbukti, sha256",
			"from transaksi.headerjurnal",
			"where ",
			"tahunanggaran=#{tahunanggaran,jdbcType=INTEGER}",
			"and kodesatker=#{kodesatker,jdbcType=VARCHAR}",
			"and extract(month from tanggalbukti)=#{bulan,jdbcType=INTEGER}"
	})
	@Results({
			@Result(column = "headerjurnalid", property = "headerjurnalid", jdbcType = JdbcType.BIGINT, id = true),
			@Result(column = "headerlogidinsert", property = "headerlogidinsert", jdbcType = JdbcType.BIGINT),
			@Result(column = "headerlogidiupdate", property = "headerlogidiupdate", jdbcType = JdbcType.BIGINT),
			@Result(column = "tahunanggaran", property = "tahunanggaran", jdbcType = JdbcType.SMALLINT),
			@Result(column = "kodesatker", property = "kodesatker"),
			@Result(column = "kodepemda", property = "kodepemda"),
			@Result(column = "namapemda", property = "namapemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "jeniscoa", property = "jeniscoa", jdbcType = JdbcType.SMALLINT),
			@Result(column = "nomorbukti", property = "nomorbukti", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tanggalbukti", property = "tanggalbukti", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "sha256", property = "sha256")
	})
	List<Headerjurnal> selectHeaderjurnalByMonth(@Param("tahunanggaran") int tahunanggaran,
			@Param("kodesatker") String kodesatker, @Param("bulan") int bulan);

	@Update({
			"update transaksi.headerjurnal",
			"set ",
			"headerlogidiupdate = #{headerlogidiupdate,jdbcType=BIGINT},",
			"tahunanggaran = #{record.tahunanggaran,jdbcType=SMALLINT},",
			"kodesatker = #{record.kodesatker,jdbcType=CHAR},",
			"kodepemda = #{record.kodepemda,jdbcType=CHAR},",
			"namapemda = #{record.namapemda,jdbcType=VARCHAR},",
			"jeniscoa = #{record.jeniscoa,jdbcType=SMALLINT},",
			"nomorbukti = #{record.nomorbukti,jdbcType=VARCHAR},",
			"tanggalbukti = #{record.tanggalbukti,jdbcType=TIMESTAMP},",
			"sha256 = #{record.sha256,jdbcType=CHAR}",
			"where headerjurnalid = #{headerjurnalid,jdbcType=BIGINT}"
	})
	int updateHeaderjurnalByPrimaryKey(@Param("record") Headerjurnal_WS record, @Param("headerjurnalid") long headerjurnalid,
			@Param("headerlogidiupdate") long headerlogidiupdate);

	@Select({
			"select",
			"headerjurnalid, headerlogidinsert, headerlogidiupdate, tahunanggaran, kodesatker, ",
			"kodepemda, namapemda, jeniscoa, nomorbukti, tanggalbukti, sha256",
			"from transaksi.headerjurnal",
			"where ",
			"tahunanggaran=#{tahunanggaran,jdbcType=INTEGER}",
			"and kodesatker=#{kodesatker,jdbcType=VARCHAR}",
			"and nomorbukti=ANY(#{inBuktis})"
	})
	@Results({
			@Result(column = "tahunanggaran", property = "tahunanggaran", jdbcType = JdbcType.SMALLINT),
			@Result(column = "kodesatker", property = "kodesatker"),
			@Result(column = "kodepemda", property = "kodepemda"),
			@Result(column = "namapemda", property = "namapemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "jeniscoa", property = "jeniscoa", jdbcType = JdbcType.SMALLINT),
			@Result(column = "nomorbukti", property = "nomorbukti", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tanggalbukti", property = "tanggalbukti", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "sha256", property = "sha256")
	})
	List<Headerjurnal_WS> selectHeaderjurnalByNomorbuktis(@Param("tahunanggaran") int tahunanggaran,
			@Param("kodesatker") String kodesatker, @Param("inBuktis") String[] inBuktis);

	@Select({
			"select",
			"headerjurnalid, headerlogidinsert, headerlogidiupdate, tahunanggaran, kodesatker, ",
			"kodepemda, namapemda, jeniscoa, nomorbukti, tanggalbukti, sha256",
			"from transaksi.headerjurnal",
			"where ",
			"tahunanggaran=#{tahunanggaran}",
			"and kodesatker=#{kodesatker}",
			"and nomorbukti=#{nomorbukti}",
			"and tanggalbukti=#{tanggalbukti}"
	})
	@Results({
			@Result(column = "headerjurnalid", property = "headerjurnalid", jdbcType = JdbcType.BIGINT, id = true),
			@Result(column = "headerlogidinsert", property = "headerlogidinsert", jdbcType = JdbcType.BIGINT),
			@Result(column = "headerlogidiupdate", property = "headerlogidiupdate", jdbcType = JdbcType.BIGINT),
			@Result(column = "tahunanggaran", property = "tahunanggaran", jdbcType = JdbcType.SMALLINT),
			@Result(column = "kodesatker", property = "kodesatker"),
			@Result(column = "kodepemda", property = "kodepemda"),
			@Result(column = "namapemda", property = "namapemda", jdbcType = JdbcType.VARCHAR),
			@Result(column = "jeniscoa", property = "jeniscoa", jdbcType = JdbcType.SMALLINT),
			@Result(column = "nomorbukti", property = "nomorbukti", jdbcType = JdbcType.VARCHAR),
			@Result(column = "tanggalbukti", property = "tanggalbukti", jdbcType = JdbcType.TIMESTAMP),
			@Result(column = "sha256", property = "sha256")
	})
	Headerjurnal selectHeaderjurnalByNomorbukti(@Param("tahunanggaran") int tahunanggaran,
			@Param("kodesatker") String kodesatker, @Param("nomorbukti") String nomorbukti,
			@Param("tanggalbukti") Date tanggalbukti);
}
