<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jeeplus.modules.workreimbursementcount.dao.WorkReimbursementOfficeDao">
	<select id="findOfficeList" resultType="WorkReimbursementOffice" >
		select
		  a.id AS "id",
		  a.top_company AS "officeName",
		  ifnull(sum(t6.money),0) AS "money"
		from sys_office a
		left join (select i.* from work_reimbursement i where i.del_flag = '0' and i.status=5
		<if test="date != '' and date != null">
		      AND YEAR(i.submitter_date) = #{date}
	    </if>
		<if test="ext != '' and ext != null">
			AND i.ext = #{ext}
		</if>
	     ) t6 on t6.office_id = a.id
		where a.del_flag = '0' and a.type ='2'
		and a.parent_id=#{companyId}
		<!--<choose>
		<when test="type != null and type != ''">
			and a.parent_ids like concat('%', #{companyId},'%') and a.branch_office is null
		</when>
		<otherwise>
			and a.branch_office = #{companyId}
		</otherwise>
	</choose>-->
		<if test="officeId != null and officeId != ''">
			AND a.id = #{officeId}
		</if>
		group by a.id
	</select>
	<select id="findOfficeListSum" resultType="WorkReimbursementOffice" >
		select
		a.id AS "id",
		a.name AS "officeName",
		ifnull(sum(t6.money),0) AS "money"
		from sys_office a
		left join (select i.* from work_reimbursement i where i.del_flag = '0' and i.status=5
		<if test="date != '' and date != null">
			AND YEAR(i.submitter_date) = #{date}
		</if>
		<if test="ext != '' and ext != null">
			AND i.ext = #{ext}
		</if>
		) t6 on t6.office_id = a.id
		where a.del_flag = '0' and a.type ='2'
		and a.parent_ids like concat('%', #{companyId},'%')
	</select>
	<select id="getConpanyType" resultType="java.lang.String" >
		select t.type from sys_office t where t.id=#{companyId}
	</select>
</mapper>