Browse Source

销售订单统计报表 多账套

liuchaohui 2 years ago
parent
commit
6b50f12586

+ 311 - 32
jeecg-boot-module-system/src/main/java/org/jeecg/modules/report/mapper/xml/SoSoDetailsMapper.xml

@@ -2,6 +2,14 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="org.jeecg.modules.report.mapper.SoSoDetailsMapper">
     <select id="getSO_SOMainReport" parameterType="java.util.HashMap" resultType="org.jeecg.modules.report.entity.SoSoDetails">
+        select
+        cDepName,
+        cVenAbbName,
+        yearMonth,
+        iNatUnitPrice,
+        sum(iQuantity) as iQuantity,
+        sum(iNatMoney) as iNatMoney
+        from (
         SELECT
         de.cDepName,
         cc.cCusAbbName as cVenAbbName,
@@ -10,7 +18,7 @@
         sum(ssd.iQuantity) as iQuantity,
         sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
         FROM
-        SO_SOMain ss
+        UFDATA_901_2021.dbo.SO_SOMain ss
         LEFT JOIN (
         SELECT
         case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
@@ -19,10 +27,10 @@
         dPreDate,
         ID
         FROM
-        SO_SODetails
+        UFDATA_901_2021.dbo.SO_SODetails
         ) ssd ON ss.ID= ssd.ID
-        left join Department de on ss.cDepCode=de.cDepCode
-        left join Customer cc on ss.cCusCode = cc.cCusCode
+        left join UFDATA_901_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+        left join UFDATA_901_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
         <where>
             (ss.iStatus = 1 or ss.iStatus = 0 )
         <if test="map.startYearMonth!=null and map.startYearMonth!='' and map.endYearMonth!=null and map.endYearMonth!=''">
@@ -43,17 +51,247 @@
         </if>
         </where>
         GROUP BY de.cDepName,ss.cCusCode,convert(char(7),ssd.dPreDate,120),ssd.iTaxUnitPrice,cc.cCusAbbName,ss.iExchRate
+
+        union all
+
+        SELECT
+        de.cDepName,
+        cc.cCusAbbName as cVenAbbName,
+        convert(char(7),ssd.dPreDate,120) yearMonth,
+        ssd.iTaxUnitPrice*ss.iExchRate as iNatUnitPrice,
+        sum(ssd.iQuantity) as iQuantity,
+        sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
+        FROM
+        UFDATA_902_2021.dbo.SO_SOMain ss
+        LEFT JOIN (
+        SELECT
+        case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
+        iNatMoney,
+        iTaxUnitPrice,
+        dPreDate,
+        ID
+        FROM
+        UFDATA_902_2021.dbo.SO_SODetails
+        ) ssd ON ss.ID= ssd.ID
+        left join UFDATA_902_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+        left join UFDATA_902_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+        <where>
+            (ss.iStatus = 1 or ss.iStatus = 0 )
+            <if test="map.startYearMonth!=null and map.startYearMonth!='' and map.endYearMonth!=null and map.endYearMonth!=''">
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{map.startYearMonth}
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{map.endYearMonth}
+            </if>
+            <if test="map.vendorType!=null and map.vendorType!='' and map.vendorType=='内部'">
+                and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+            </if>
+            <if test="map.vendorType!=null and map.vendorType!='' and map.vendorType=='外部'">
+                and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+            </if>
+            <if test="map.department!=null and map.department!='' ">
+                and de.cDepName = #{map.department}
+            </if>
+            <if test="map.customer!=null and map.customer!='' ">
+                and cc.cCusAbbName = #{map.customer}
+            </if>
+        </where>
+        GROUP BY de.cDepName,ss.cCusCode,convert(char(7),ssd.dPreDate,120),ssd.iTaxUnitPrice,cc.cCusAbbName,ss.iExchRate
+
+        union all
+
+        SELECT
+        de.cDepName,
+        cc.cCusAbbName as cVenAbbName,
+        convert(char(7),ssd.dPreDate,120) yearMonth,
+        ssd.iTaxUnitPrice*ss.iExchRate as iNatUnitPrice,
+        sum(ssd.iQuantity) as iQuantity,
+        sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
+        FROM
+        UFDATA_903_2021.dbo.SO_SOMain ss
+        LEFT JOIN (
+        SELECT
+        case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
+        iNatMoney,
+        iTaxUnitPrice,
+        dPreDate,
+        ID
+        FROM
+        UFDATA_903_2021.dbo.SO_SODetails
+        ) ssd ON ss.ID= ssd.ID
+        left join UFDATA_903_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+        left join UFDATA_903_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+        <where>
+            (ss.iStatus = 1 or ss.iStatus = 0 )
+            <if test="map.startYearMonth!=null and map.startYearMonth!='' and map.endYearMonth!=null and map.endYearMonth!=''">
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{map.startYearMonth}
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{map.endYearMonth}
+            </if>
+            <if test="map.vendorType!=null and map.vendorType!='' and map.vendorType=='内部'">
+                and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+            </if>
+            <if test="map.vendorType!=null and map.vendorType!='' and map.vendorType=='外部'">
+                and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+            </if>
+            <if test="map.department!=null and map.department!='' ">
+                and de.cDepName = #{map.department}
+            </if>
+            <if test="map.customer!=null and map.customer!='' ">
+                and cc.cCusAbbName = #{map.customer}
+            </if>
+        </where>
+        GROUP BY de.cDepName,ss.cCusCode,convert(char(7),ssd.dPreDate,120),ssd.iTaxUnitPrice,cc.cCusAbbName,ss.iExchRate
+        ) t
+        GROUP BY cDepName,
+        cVenAbbName,
+        yearMonth,
+        iNatUnitPrice
+        --GROUP BY de.cDepName,ss.cCusCode,convert(char(7),ssd.dPreDate,120),ssd.iTaxUnitPrice,cc.cCusAbbName,ss.iExchRate
         --ORDER BY
         --de.cDepName,ss.cCusCode,CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ),ssd.iTaxUnitPrice
     </select>
 
     <select id="QuerySO_SOMainReportBydepartment" resultType="org.jeecg.modules.report.entity.SoSoDetails">
         SELECT
-        cc.cCusAbbName  as cCusName,
+        cCusName,
+        sum(iQuantity) as iQuantity,
+        sum(iNatMoney) as iNatMoney
+        from(
+            SELECT
+            cc.cCusAbbName  as cCusName,
+            sum(ssd.iQuantity) as iQuantity,
+            sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
+            FROM
+            UFDATA_901_2021.dbo.SO_SOMain ss
+            LEFT JOIN (
+            SELECT
+            case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
+            iNatMoney,
+            iTaxUnitPrice,
+            dPreDate,
+            ID
+            FROM
+            UFDATA_901_2021.dbo.SO_SODetails
+            ) ssd ON ss.ID= ssd.ID
+            left join UFDATA_901_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+            left join UFDATA_901_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+            <where>
+                (ss.iStatus = 1 or ss.iStatus = 0 )
+            <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{startYearMonth}
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{endYearMonth}
+            </if>
+            <if test="vendorType!=null and vendorType!='' and vendorType=='内部'">
+                and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+            </if>
+            <if test="vendorType!=null and vendorType!='' and vendorType=='外部'">
+                and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+            </if>
+            <if test="department!=null and department!='' ">
+                and de.cDepName = #{department}
+            </if>
+            <if test="customer!=null and customer!='' ">
+                and cc.cCusAbbName = #{customer}
+            </if>
+            </where>
+            GROUP BY cc.cCusAbbName
+
+            union
+
+            SELECT
+            cc.cCusAbbName  as cCusName,
+            sum(ssd.iQuantity) as iQuantity,
+            sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
+            FROM
+            UFDATA_902_2021.dbo.SO_SOMain ss
+            LEFT JOIN (
+            SELECT
+            case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
+            iNatMoney,
+            iTaxUnitPrice,
+            dPreDate,
+            ID
+            FROM
+            UFDATA_902_2021.dbo.SO_SODetails
+            ) ssd ON ss.ID= ssd.ID
+            left join UFDATA_902_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+            left join UFDATA_902_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+            <where>
+                (ss.iStatus = 1 or ss.iStatus = 0 )
+                <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
+                    AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{startYearMonth}
+                    AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{endYearMonth}
+                </if>
+                <if test="vendorType!=null and vendorType!='' and vendorType=='内部'">
+                    and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+                </if>
+                <if test="vendorType!=null and vendorType!='' and vendorType=='外部'">
+                    and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+                </if>
+                <if test="department!=null and department!='' ">
+                    and de.cDepName = #{department}
+                </if>
+                <if test="customer!=null and customer!='' ">
+                    and cc.cCusAbbName = #{customer}
+                </if>
+            </where>
+            GROUP BY cc.cCusAbbName
+
+            union
+
+            SELECT
+            cc.cCusAbbName  as cCusName,
+            sum(ssd.iQuantity) as iQuantity,
+            sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
+            FROM
+            UFDATA_903_2021.dbo.SO_SOMain ss
+            LEFT JOIN (
+            SELECT
+            case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
+            iNatMoney,
+            iTaxUnitPrice,
+            dPreDate,
+            ID
+            FROM
+            UFDATA_903_2021.dbo.SO_SODetails
+            ) ssd ON ss.ID= ssd.ID
+            left join UFDATA_903_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+            left join UFDATA_903_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+            <where>
+                (ss.iStatus = 1 or ss.iStatus = 0 )
+                <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
+                    AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{startYearMonth}
+                    AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{endYearMonth}
+                </if>
+                <if test="vendorType!=null and vendorType!='' and vendorType=='内部'">
+                    and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+                </if>
+                <if test="vendorType!=null and vendorType!='' and vendorType=='外部'">
+                    and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+                </if>
+                <if test="department!=null and department!='' ">
+                    and de.cDepName = #{department}
+                </if>
+                <if test="customer!=null and customer!='' ">
+                    and cc.cCusAbbName = #{customer}
+                </if>
+            </where>
+            GROUP BY cc.cCusAbbName
+        ) t GROUP BY cCusName
+
+    </select>
+
+
+    <select id="QuerySO_SOMainReportBycustomer" resultType="org.jeecg.modules.report.entity.SoSoDetails">
+        SELECT
+        cDepName,
+        sum(iQuantity) as iQuantity,
+        sum(iNatMoney) as iNatMoney
+        from (
+        SELECT
+        de.cDepName,
         sum(ssd.iQuantity) as iQuantity,
         sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
         FROM
-        SO_SOMain ss
+        UFDATA_901_2021.dbo.SO_SOMain ss
         LEFT JOIN (
         SELECT
         case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
@@ -62,10 +300,10 @@
         dPreDate,
         ID
         FROM
-        SO_SODetails
+        UFDATA_901_2021.dbo.SO_SODetails
         ) ssd ON ss.ID= ssd.ID
-        left join Department de on ss.cDepCode=de.cDepCode
-        left join Customer cc on ss.cCusCode = cc.cCusCode
+        left join UFDATA_901_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+        left join UFDATA_901_2021.dbo.Department de on ss.cDepCode=de.cDepCode
         <where>
             (ss.iStatus = 1 or ss.iStatus = 0 )
         <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
@@ -85,17 +323,16 @@
             and cc.cCusAbbName = #{customer}
         </if>
         </where>
-        GROUP BY cc.cCusAbbName
-    </select>
+        GROUP BY de.cDepName
 
+        union
 
-    <select id="QuerySO_SOMainReportBycustomer" resultType="org.jeecg.modules.report.entity.SoSoDetails">
         SELECT
         de.cDepName,
         sum(ssd.iQuantity) as iQuantity,
         sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
         FROM
-        SO_SOMain ss
+        UFDATA_902_2021.dbo.SO_SOMain ss
         LEFT JOIN (
         SELECT
         case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
@@ -104,29 +341,71 @@
         dPreDate,
         ID
         FROM
-        SO_SODetails
+        UFDATA_902_2021.dbo.SO_SODetails
         ) ssd ON ss.ID= ssd.ID
-        left join Customer cc on ss.cCusCode = cc.cCusCode
-        left join Department de on ss.cDepCode=de.cDepCode
+        left join UFDATA_902_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+        left join UFDATA_902_2021.dbo.Department de on ss.cDepCode=de.cDepCode
         <where>
             (ss.iStatus = 1 or ss.iStatus = 0 )
-        <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
-            AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{startYearMonth}
-            AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{endYearMonth}
-        </if>
-        <if test="vendorType!=null and vendorType!='' and vendorType=='内部'">
-            and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
-        </if>
-        <if test="vendorType!=null and vendorType!='' and vendorType=='外部'">
-            and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
-        </if>
-        <if test="department!=null and department!='' ">
-            and de.cDepName = #{department}
-        </if>
-        <if test="customer!=null and customer!='' ">
-            and cc.cCusAbbName = #{customer}
-        </if>
+            <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{startYearMonth}
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{endYearMonth}
+            </if>
+            <if test="vendorType!=null and vendorType!='' and vendorType=='内部'">
+                and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+            </if>
+            <if test="vendorType!=null and vendorType!='' and vendorType=='外部'">
+                and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+            </if>
+            <if test="department!=null and department!='' ">
+                and de.cDepName = #{department}
+            </if>
+            <if test="customer!=null and customer!='' ">
+                and cc.cCusAbbName = #{customer}
+            </if>
+        </where>
+        GROUP BY de.cDepName
+
+        union
+
+        SELECT
+        de.cDepName,
+        sum(ssd.iQuantity) as iQuantity,
+        sum(ssd.iTaxUnitPrice*ss.iExchRate*ssd.iQuantity) as iNatMoney
+        FROM
+        UFDATA_903_2021.dbo.SO_SOMain ss
+        LEFT JOIN (
+        SELECT
+        case when cSCloser is null then iQuantity else foutquantity end as iQuantity,
+        iNatMoney,
+        iTaxUnitPrice,
+        dPreDate,
+        ID
+        FROM
+        UFDATA_903_2021.dbo.SO_SODetails
+        ) ssd ON ss.ID= ssd.ID
+        left join UFDATA_903_2021.dbo.Customer cc on ss.cCusCode = cc.cCusCode
+        left join UFDATA_903_2021.dbo.Department de on ss.cDepCode=de.cDepCode
+        <where>
+            (ss.iStatus = 1 or ss.iStatus = 0 )
+            <if test="startYearMonth!=null and startYearMonth!='' and endYearMonth!=null and endYearMonth!=''">
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ >= ]]> #{startYearMonth}
+                AND CONVERT ( CHAR ( 7 ), ssd.dPreDate, 120 ) <![CDATA[ <= ]]> #{endYearMonth}
+            </if>
+            <if test="vendorType!=null and vendorType!='' and vendorType=='内部'">
+                and (cc.cCusAbbName='宁波森语' or  cc.cCusAbbName='马菲羊' or  cc.cCusAbbName='森语集团')
+            </if>
+            <if test="vendorType!=null and vendorType!='' and vendorType=='外部'">
+                and (cc.cCusAbbName  <![CDATA[ <> ]]> '宁波森语' and cc.cCusAbbName <![CDATA[ <> ]]> '马菲羊' and  cc.cCusAbbName <![CDATA[ <> ]]> '森语集团')
+            </if>
+            <if test="department!=null and department!='' ">
+                and de.cDepName = #{department}
+            </if>
+            <if test="customer!=null and customer!='' ">
+                and cc.cCusAbbName = #{customer}
+            </if>
         </where>
         GROUP BY de.cDepName
+        ) f GROUP BY cDepName
     </select>
 </mapper>