<?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.huimv.getdata.mapper.ErpCaiGouMapper">


    <select id="getDingDanJinE" resultType="com.huimv.getdata.entity.caigou.DingDanJinE"
            parameterType="java.util.Date">
SELECT    B.FALLAMOUNT ,A.FDATE ,A.FPURCHASEORGID FROM  T_PUR_CONTRACT A
INNER JOIN  T_PUR_CONTRACTENTRY_F B ON A.FID = B.FID
        <if test="date !=null">
            and  A.FDATE >= #{date}
        </if>

    </select>
    <select id="getCaiGouRuku" resultType="com.huimv.getdata.entity.caigou.CaiGouRuKu"
            parameterType="java.util.Date">
SElECT DISTINCT B.FBILLAMOUNT_LC  FBILLAMOUNTLC ,A.FDATE , A.FDEMANDORGID FROM  T_STK_INSTOCK A
        INNER JOIN  T_STK_INSTOCKFIN B ON A.FID = B.FID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>

    </select>

    <select id="getCaiGouFaPiao" resultType="com.huimv.getdata.entity.caigou.FaPiaoJinE"
            parameterType="java.util.Date">
        SELECT    B.FALLAMOUNT ,A.FDATE ,A.FPURCHASEORGID ,C.FQTY  FROM  T_PUR_POORDER A
        INNER JOIN T_PUR_POORDERENTRY C ON A.FID  = C.FID
        INNER JOIN  T_PUR_POORDERENTRY_F B ON B.FENTRYID  = C.FENTRYID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>

    </select>
    <select id="getLeiJiRuKu" resultType="com.huimv.getdata.entity.caigou.LeiJiRuKu"
            parameterType="java.util.Date">
       SELECT B.FREALQTY ,A.FDATE ,A.FDEMANDORGID FROM T_STK_INSTOCK A
        INNER JOIN  T_STK_INSTOCKENTRY B ON A.FID = B.FID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>


    </select>
    <select id="getShouLiaoJinE" resultType="com.huimv.getdata.entity.caigou.ShouLiaoJinE"
            parameterType="java.util.Date">
        SELECT B.FINSTOCKQTY ,A.FDATE  ,A.FSTOCKORGID
 FROM  T_PUR_RECEIVE A
        INNER JOIN T_PUR_RECEIVEENTRY_S B ON A.FID = B.FID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>


    </select>
    <select id="getJiaoHuoShuLiang" resultType="com.huimv.getdata.entity.caigou.JiaoHuoShuliang"
            parameterType="java.util.Date">
        SELECT A.FDATE  ,A.FSTOCKORGID  ,B.FACTRECEIVEQTY FROM  T_PUR_RECEIVE  A
        INNER JOIN   T_PUR_RECEIVEENTRY B  ON  A.FID = B.FID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>

    </select>
    <select id="getCaiGouShuLiang" resultType="com.huimv.getdata.entity.caigou.CaiGouShuLiang"
            parameterType="java.util.Date">

        SELECT DISTINCT A.FDATE  ,A.FPURCHASEORGID  ,B.FQTY FROM  T_PUR_POORDER  A
        INNER JOIN   T_PUR_POORDERENTRY B  ON  A.FID = B.FID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>

    </select>
    <select id="getCaiGouDingDanShuLiangJinE" resultType="com.huimv.getdata.entity.caigou.CaiGouDingDanShuLiangJinE"
            parameterType="java.lang.String">
        SELECT DISTINCT D.FNAME ,A.FDATE ,A.FPURCHASEORGID , B.FQTY ,C.FALLAMOUNT ,( C.FALLAMOUNT /B.FQTY ) danJia  ,E.FNAME gys ,
        F.FNAME dingDanType  , G.FNUMBER  fnumber
         FROM T_PUR_POORDER A
INNER JOIN T_PUR_POORDERENTRY B ON A.FID = B.FID
INNER JOIN T_PUR_POORDERENTRY_F C  ON B.FENTRYID = C.FENTRYID
INNER JOIN T_BD_MATERIAL_L  D ON D.FMATERIALID = B.FMATERIALID
        INNER JOIN T_BD_SUPPLIER_L  E ON A.FSUPPLIERID = E.FSUPPLIERID
        INNER JOIN T_BAS_BILLTYPE_L F ON A.FBILLTYPEID = F.FBILLTYPEID
        INNER JOIN T_BD_MATERIAL G ON G.FMATERIALID = D.FMATERIALID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>
    </select>
    <select id="getDaiJianShuLiang" resultType="com.huimv.getdata.entity.caigou.DaiJianShuLiang"
            parameterType="java.util.Date">
        SELECT   C.FINSTOCKQTY, B.FACTRECEIVEQTY ,A.FDATE ,A.FSTOCKORGID ,( B.FACTRECEIVEQTY -  C.FINSTOCKQTY) DAIJIAN,D.FNAME as test FROM  T_PUR_RECEIVE  A
INNER JOIN  T_PUR_RECEIVEENTRY B ON A.FID = B.FID
INNER JOIN    T_PUR_RECEIVEENTRY_S C  ON  B.FENTRYID = C.FENTRYID
INNER JOIN T_BD_MATERIAL_L  D ON D.FMATERIALID = B.FMATERIALID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>
    </select>
    <select id="getCaiGouYueJun" resultType="com.huimv.getdata.entity.caigou.CaiGouYueJun"
            parameterType="java.util.Date">
SELECT B.FQTY ,A.FDATE ,A.FPURCHASEORGID  FROM  T_PUR_POORDER A
INNER JOIN  T_PUR_POORDERENTRY  B ON A.FID = B.FID
        <if test="date !=null">
            where  A.FDATE >= #{date}
        </if>
    </select>
    <select id="getYingFuZhangKuang" resultType="com.huimv.getdata.entity.caigou.YingFuZhangKuan"
            parameterType="java.util.Date">
        SELECT DISTINCT A.FDATE ,A.FBGLSHSJDW ,A.FPURCHASEORGID , A.FPAYORGID, B.FPURPOSEID ,C.FNAME ,B.FNOTVERIFICATEAMOUNT ,B.FQTY  ,D.FNAME wuLiaoName
        ,E.FBOOKINGDATE  FROM  T_AP_PAYBILL 	A
INNER JOIN  T_AP_PAYBILLENTRY B ON A.FID = B.FID
INNER JOIN  T_CN_RECPAYPURPOSE_L C ON C.FID = B.FPURPOSEID
        INNER JOIN  T_BD_MATERIAL_L  D ON B.FMATERIALID =D.FMATERIALID
        LEFT JOIN T_AP_PAYBILL_O  E ON E.FID = A.FID
        WHERE B.FNOTVERIFICATEAMOUNT >0
        <if test="date !=null">
            AND  A.FDATE >= #{date}
        </if>
    </select>
    <select id="getZuiDiKuChun" resultType="com.huimv.getdata.entity.caigou.ZuiDiKuChun"
            parameterType="java.util.Date">
        SELECT  DISTINCT C.FINSTOCKQTY, B.FACTRECEIVEQTY ,A.FDATE ,A.FSTOCKORGID ,( B.FACTRECEIVEQTY -  C.FINSTOCKQTY)   as shengYv,D.FNAME
        ,E.FMINSTOCK ,F.FAVBQTY
        FROM  T_PUR_RECEIVE  A
        INNER JOIN  T_PUR_RECEIVEENTRY B ON A.FID = B.FID
        INNER JOIN    T_PUR_RECEIVEENTRY_S C  ON  B.FENTRYID = C.FENTRYID
        INNER JOIN T_BD_MATERIAL_L  D ON D.FMATERIALID = B.FMATERIALID
        INNER JOIN t_BD_MaterialStock E ON E.FMATERIALID = D.FMATERIALID
        LEFT JOIN T_STK_INVENTORY F ON F.FMATERIALID = E.FMATERIALID
        WHERE  (B.FACTRECEIVEQTY -  C.FINSTOCKQTY)  &lt; E.FMINSTOCK
        <if test="date !=null">
            AND  A.FDATE >= #{date}
        </if>

    </select>
    <select id="getCaiGouHeTongShuLiangJinE" resultType="com.huimv.getdata.entity.caigou.CaiGouDingDanShuLiangJinE"
            parameterType="java.util.Date">
        SELECT DISTINCT D.FNAME ,A.FDATE ,A.FPURCHASEORGID , B.FQTY ,C.FALLAMOUNT  ,( C.FALLAMOUNT /B.FQTY )  danJia , E.FNAME dingDanType  ,
        G.FNUMBER  fnumber   FROM T_PUR_CONTRACT A
INNER JOIN T_PUR_CONTRACTENTRY B ON A.FID = B.FID
INNER JOIN T_PUR_CONTRACTENTRY_F C  ON B.FENTRYID = C.FENTRYID
INNER JOIN T_BD_MATERIAL_L  D ON D.FMATERIALID = B.FMATERIALID
        INNER JOIN T_BAS_BILLTYPE_L E ON A.FBILLTYPEID = E.FBILLTYPEID
        INNER JOIN T_BD_MATERIAL G ON G.FMATERIALID = D.FMATERIALID
        <if test="date !=null">
            WHERE  A.FDATE >= #{date}
        </if>
    </select>
</mapper>
