<?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.fjhx.purchase.mapper.purchase.PurchaseMapper">
    <select id="getPage" resultType="com.fjhx.purchase.entity.purchase.vo.PurchaseVo">
        select
            p.*
        from purchase p
            ${ew.customSqlSegment}
    </select>
    <select id="paymentBill" resultType="com.fjhx.purchase.entity.purchase.dto.PurchaseDto">
        SELECT
            pu.code,
            pu.supply_id,
            bs.`name` supplyName,
            pu.amount,
            IFNULL(SUM(nd.money),0) invoiceAmount,
            pu.pay_status  payStatus,
            pu.currency,
            pu.id
        FROM
            purchase pu
                LEFT JOIN bytesailing_supply.supplier_info bs ON pu.supply_id = bs.id
                LEFT JOIN  invoice_details nd on pu.id = nd.purchase_id
            ${ew.customSqlSegment}
    </select>
    <select id="arrivalAmount" resultType="com.fjhx.purchase.entity.purchase.dto.PurchaseDto">
        SELECT
            SUM(wd.receipt_quantity) * pd.price  amount,
            pd.purchase_id id
        FROM
            bytesailing_wms.stock_wait sw
                JOIN bytesailing_wms.stock_wait_details wd on sw.id = wd.stock_wait_id
                join arrival_detail ad on wd.business_details_id = ad.id
                join purchase_detail pd on ad.purchase_detail_id = pd.id
            ${ew.customSqlSegment}
    </select>
    <select id="paidAmount" resultType="com.fjhx.purchase.entity.purchase.dto.PurchaseDto">
        SELECT
            sum(pd.money) amount,
            p.currency,
            pd.purchase_id id
        FROM
            pay_detail pd
                LEFT JOIN pay p ON pd.pay_id = p.id
            ${ew.customSqlSegment}
    </select>

</mapper>
