<?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.cf.imes.module.executor.dal.mysql.funds.purchase.PurchaseRecordMapper">


    <select id="selectOrganInvoice"
            resultType="com.cf.imes.module.executor.controller.admin.funds.invoice.vo.InvoiceAmountRespVO">


        select
            sum(case when is_invocing = 1 then account_balance_spent + alipay_spent + wechat_spent end ) as inTheInvoice,
            sum(case when is_invocing = 2 then account_balance_spent + alipay_spent + wechat_spent end ) as invoiced

        from purchase_record

        where organ_id = #{organId}
          and deleted = false



    </select>


    <select id="selectPurchaseRecord"
            resultType="com.cf.imes.module.executor.controller.admin.funds.invoice.vo.InvoicePurchaseRecord">


        select distinct pr.id as purchaseRecordId,
                        pr.create_time as createTime,
                        pr.product_name as productName,
                        ied.cash_amount_change as rechargeAmount,
                        ied.trade_type as tradeType,
                        ied.business_no as businessNo

        from purchase_record pr
                 join income_expense_details ied on pr.organId = ied.organId and ied.purchase_id = pr.id
        where pr.organId = #{organId}
          and pr.deleted = false
          and pr.id in
        <foreach item="purchaseIdList" collection="purchaseIdList" open="(" separator="," close=")">
            #{purchaseIdList}
        </foreach>





    </select>


</mapper>