<?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.zfire.mall.manager.commonmapper.K3Mapper">
    <select id="queryReceiptBill" resultType="com.zfire.mall.manager.bean.k3.K3ReceiptBean">
        select
            a.*,
            d.name AS 'wl_company_name',
            b.name AS 'customer_name',
            c.name AS 'wallet_name'
        from king_dee_receipt a
        join king_dee_customer b on a.customer_id=b.id
        join king_dee_wallet c on a.wallet_id=c.id
        join king_dee_customer d on d.id=b.id
        where a.status='C'

            <if test="billType !=null and billType !=''">
                and a.bill_type like concat('%',#{billType},'%')
            </if>
            <if test="billNo !=null and billNo !=''">
                and a.bill_no like concat('%',#{billNo},'%')
            </if>
            <if test="wlCompanyType !=null and wlCompanyType !=''">
                and d.name like concat('%',#{wlCompanyType},'%')
            </if>
            <if test="customerName !=null and customerName !=''">
                and b.name like concat('%',#{customerName},'%')
            </if>
            <if test="settleType !=null and settleType !=''">
                and a.settle_type like concat('%',#{settleType},'%')
            </if>
            <if test="startTime !=null and startTime !='' and endTime != null and endTime !=''">
                and a.the_time between #{startTime} and #{endTime}
            </if>
            <if test="customerId !=null and customerId !=''">
                and a.customer_id = #{customerId}
            </if>
            <if test="websitNumber != null and websitNumber !=''">
                and b.id in (
                    select a.customer_id from admin_user a
                    join admin_user_websit_rela b on a.admin_user_id=b.admin_user_id
                    join admin_websit c on c.admin_websit_id=b.admin_websit_id
                    where c.websit_number=#{websitNumber}
                )
            </if>

        order by a.create_time desc
    </select>


    <select id="queryMaterialUnit" resultType="com.zfire.mall.manager.plus.entity.KingDeeMaterial">
        select
            DISTINCT
            base_unit_id,base_unit_code,
            store_unit_id,store_unit_code,
            sale_price_unit_id,sale_price_unit_code,
            purchase_price_unit_id,purchase_price_unit_code
        from king_dee_material
    </select>


    <select id="queryReceiptBillCount" resultType="com.zfire.mall.manager.bean.CommonCountBean">
        select
        sum(a.amount) 'orderAmountC'
        from king_dee_receipt a
        join king_dee_customer b on a.customer_id=b.id
        join king_dee_wallet c on a.wallet_id=c.id
        join king_dee_customer d on d.id=b.id
        where a.status='C'

        <if test="billType !=null and billType !=''">
            and a.bill_type like concat('%',#{billType},'%')
        </if>
        <if test="billNo !=null and billNo !=''">
            and a.bill_no like concat('%',#{billNo},'%')
        </if>
        <if test="wlCompanyType !=null and wlCompanyType !=''">
            and d.name like concat('%',#{wlCompanyType},'%')
        </if>
        <if test="customerName !=null and customerName !=''">
            and b.name like concat('%',#{customerName},'%')
        </if>
        <if test="settleType !=null and settleType !=''">
            and a.settle_type like concat('%',#{settleType},'%')
        </if>
        <if test="startTime !=null and startTime !='' and endTime != null and endTime !=''">
            and a.the_time between #{startTime} and #{endTime}
        </if>
        <if test="customerId !=null and customerId !=''">
            and a.customer_id = #{customerId}
        </if>
        <if test="websitNumber != null and websitNumber !=''">
            and b.id in (
            select a.customer_id from admin_user a
            join admin_user_websit_rela b on a.admin_user_id=b.admin_user_id
            join admin_websit c on c.admin_websit_id=b.admin_websit_id
            where c.websit_number=#{websitNumber}
            )
        </if>

    </select>
    <select id="v2ListPage" resultType="com.zfire.mall.manager.bean.k3.v2.KingDeeCategoryVO">
        SELECT
            *
        FROM
            king_dee_category
        ${ex.query}
        <if test="ex.orderBy == null or ex.orderBy ==''">
            ORDER BY create_time DESC
        </if>
        ${ex.orderBy}
    </select>


</mapper>