<?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.ErpXiaoShouMapper">


    <select id="getWanChengLv" resultType="com.huimv.getdata.entity.xiaoshou.XiaoShouWanChenLvJinE"
            parameterType="java.util.Date">

        SELECT DISTINCT A.FBILLNO , C.FALLAMOUNT_LC ,C.FALLAMOUNT  , A.FCUSTID ,A.FSALEDEPTID , A.FSALERID , A.FSALEORGID ,A.FDATE  ,B.FQTY, B.FMATERIALID ,D.FNAME wuLiaoName ,E.FRETURNQTY,
E.FBASERETURNQTY ,F.FNAME ,F.fdeptname, (C.FALLAMOUNT_LC / B.FQTY )  xiaoShouDanJia ,  G.FNAME  keHuName
 FROM  T_SAL_ORDER A
 INNER JOIN T_SAL_ORDERENTRY B ON A.FID = B.FID
 INNER JOIN T_SAL_ORDERENTRY_F C ON C.FENTRYID = B.FENTRYID
 INNER JOIN T_BD_MATERIAL_L D ON D.FMATERIALID  = B.FMATERIALID
 INNER JOIN T_SAL_ORDERENTRY_R E ON E.FENTRYID = B.FENTRYID
 LEFT JOIN V_BD_SALESMAN_L F ON F.fid = A.FSALERID
        LEFT JOIN  T_BD_CUSTOMER_L G ON G.FCUSTID = A.FCUSTID
        <if test="date !=null">
            where A.FDATE >= #{date}
        </if>
    </select>
    <select id="getBaiFangKeHu" resultType="com.huimv.getdata.entity.xiaoshou.BaiFangKeHu"
            parameterType="java.util.Date">
        select * from  zc_jh_VisitRecord
        <if test="date !=null">
            where F_ZC_DATE >= #{date}
        </if>
    </select>
    <select id="getXiaoShouFaPiaoJinE" resultType="com.huimv.getdata.entity.xiaoshou.XiaoShouFaPiaoJinE"
            parameterType="java.util.Date">

        SELECT A.FDATE, A.FSETTLEORGID , A.FSALEORGID ,A.FSALEERID ,B.FALLAMOUNT ,A.FSETACCOUNTTYPE ,A.FBILLNO FROM 	 T_AR_RECEIVABLE A
	INNER JOIN 	 T_AR_RECEIVABLEENTRY B ON A.FID = B.FID
	WHERE A.FSETACCOUNTTYPE = 3
        <if test="date !=null">
            and A.FDATE >= #{date}
        </if>
    </select>
    <select id="getXiaoShouFaHuoJinEKeHuGongXian"
            resultType="com.huimv.getdata.entity.xiaoshou.XiaoShouFaHuoJinEKeHuGongXian"
            parameterType="java.util.Date">

SELECT  DISTINCT A.FSALEORGID ,A.FDATE ,A.FSTOCKORGID ,A.FCUSTOMERID,A.FSALESMANID , B.FREALQTY , C.FALLAMOUNT_LC ,D.FNAME   ,A.FBILLNO
        F.FNAME xiaoShouName
        FROM  T_SAL_OUTSTOCK A
INNER JOIN  T_SAL_OUTSTOCKENTRY B ON A.FID = B.FID
INNER JOIN  T_SAL_OUTSTOCKENTRY_F C ON C.FENTRYID = B.FENTRYID
INNER JOIN T_BD_CUSTOMER_L D ON D.FCUSTID=A.FCUSTOMERID
        <if test="date !=null">
            where A.FDATE >= #{date}
        </if>

    </select>
    <select id="getXiaoShouFeiYong" resultType="com.huimv.getdata.entity.xiaoshou.XiaoShouFeiYong"
            parameterType="java.util.Date">

        SELECT A.FACCTORGID ,A.FDATE ,B.FCREDIT ,D.FNAME  FROM T_GL_VOUCHER A
INNER JOIN T_GL_VOUCHERENTRY B ON A.FVOUCHERID = B.FVOUCHERID
INNER JOIN T_BD_ACCOUNT C ON  C.FACCTID = B.FACCOUNTID
 INNER JOIN T_BD_ACCOUNT_L  D ON  D.FACCTID = C.FACCTID
 WHERE C.Fnumber in  ('6601.01.01','6601.01.02','6601.02','6601.03','6601.05','6601.06','6601.08','6601.09','6601.10','6601.13','6601.14.02','6601.14.01','6601.15','6601.19','6601.16','6601.17','6601.18','6601.21.02','6601.21.03','6601.21.04','6601.22','6601.21.01')
        <if test="date !=null">
            and A.FDATE >= #{date}
        </if>

    </select>
    <select id="getYvQiHeTongMingXi" resultType="com.huimv.getdata.entity.xiaoshou.YvQiHeTongMingXi"
            parameterType="java.util.Date">
        SELECT DISTINCT A.FBILLNO , A.FDATE ,A.FBILLTYPEID   ,C.FNAME , D.FNAME keHuName ,E.FQTY  ,F.FALLAMOUNT_LC , G.FDATE chuKuDate  FROM T_CRM_CONTRACT A
INNER JOIN T_BAS_BILLTYPE  B ON B.FBILLTYPEID = A.FBILLTYPEID
INNER JOIN T_BAS_BILLTYPE_L C ON A.FBILLTYPEID = C.FBILLTYPEID
INNER JOIN T_BD_CUSTOMER_L D ON D.FCUSTID=A.FCUSTID
INNER JOIN T_CRM_CONTRACTENTRY E  ON E.FID  = A.FID
LEFT JOIN T_CRM_CONTRACTENTRY_F F  ON F.FID  = A.FID
LEFT JOIN T_SAL_OUTSTOCK G  ON G.FBILLTYPEID  = A.FBILLTYPEID
        <if test="date !=null">
            where A.FDATE >= #{date}
        </if>
    </select>
</mapper>
