" ( SELECT SUM ( WMSDeliveryQty ) Qty, KanBan, MaterialCode FROM Set_WMSKanBanSettle GROUP BY KanBan, MaterialCode ) temp1\n"+
" ( SELECT SUM ( WMSDeliveryQty ) Qty, KanBan, MaterialCode FROM Set_WMSKanBanSettle GROUP BY KanBan, MaterialCode ) temp1\n"+
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle WHERE VERSION < '{0}' GROUP BY kanban, MaterialCode ) temp2 ON temp1.Kanban = temp2.KanBan \n"+
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle WHERE VERSION < '{0}' GROUP BY kanban, MaterialCode ) temp2 ON temp1.Kanban = temp2.KanBan \n"+
" AND temp1.MaterialCode = temp2.KanBan \n"+
" AND temp1.MaterialCode = temp2.MaterialCode \n"+
" LEFT JOIN ( SELECT PurchaseOrderNo, Version, PurchaseOrderNoText, PurchasePriceNoTax, InvoicedQty, AmountNoTax FROM Set_SparePart WHERE Version = '{0}' ) b ON a.PurchaseOrderNo = b.PurchaseOrderNo\n"+
" LEFT JOIN ( SELECT PurchaseOrderNo, Version, PurchaseOrderNoText, PurchasePriceNoTax, InvoicedQty, AmountNoTax FROM Set_SparePart WHERE Version = '{0}' and Extend='is90' ) b ON a.PurchaseOrderNo = b.PurchaseOrderNo\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
// " ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Version = '{0}' GROUP BY PurchaseOrderNo, MaterialCode ) A\n" +
// " ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Version = '{0}' and Extend='is90' GROUP BY PurchaseOrderNo, MaterialCode ) A\n" +
// " LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) B ON A.MaterialCode = B.MaterialCode \n" +
// " LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) B ON A.MaterialCode = B.MaterialCode \n" +
// " AND A.PurchaseOrderNo = B.PurchaseOrderNo \n" +
// " AND A.PurchaseOrderNo = B.PurchaseOrderNo \n" +
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n"+
" Version,\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' GROUP BY PurchaseOrderNo, MaterialCode ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n"+
" PurchasePriceNoTax,\n"+
" AND temp1.MaterialCode = temp2.MaterialCode \n"+
" InvoicedQty,\n"+
" ) \n"+
" PurchaseOrderNoText,\n"+
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n"+
" AmountNoTax \n"+
" AND A.MaterialCode = C.MaterialCode \n"+
" ) AS a\n"+
" WHERE\n"+
" INNER JOIN (\n"+
" ( a.Version = '{0}' ) \n"+
" SELECT SUM\n"+
" ) AS temp1\n"+
" ( ReceiptQty ) AS ReceiptQty,\n"+
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) temp3 ON temp1.采购订单号 = temp3.Code \n"+
" PurchaseOrderNo,\n"+
" AND temp1.SAP编码= temp3.MaterialCode\n"+
" SapCode,\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n"+
" MaterialCode,\n"+
" ) union1 UNION ALL\n"+
" WMSDeliveryNote,\n"+
"SELECT\n"+
" SpareDate \n"+
" union2.* \n"+
" FROM\n"+
"FROM\n"+
" Set_WMSSparePart \n"+
" (\n"+
" GROUP BY\n"+
" SELECT\n"+
" PurchaseOrderNo,\n"+
" temp1.交货日期,\n"+
" SapCode,\n"+
" '' 交货单号,\n"+
" MaterialCode,\n"+
" '' 订单日期,\n"+
" WMSDeliveryNote,\n"+
" '' 采购订单号,\n"+
" SpareDate \n"+
" temp1.SAP编码,\n"+
" ) AS b ON a.PurchaseOrderNo = b.PurchaseOrderNo \n"+
" temp1.物料代码,\n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" temp1.物料描述,\n"+
" LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ) AS temp1\n"+
" WHERE\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = ( SELECT MAX ( VERSION ) FROM Set_PriceList ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n"+
" ( a.Version = '{0}' ) \n"+
" ) union2";
" ) AS temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n"+
" ) union2";
string_sql=string.Format(sqlString,version);
//" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp.Sap编码 = TEMP2.MaterialCode\n" +
" INNER JOIN ( SELECT MaterialCode, PurchaseOrderNo FROM Set_WMSSparePart GROUP BY MaterialCode, PurchaseOrderNo HAVING COUNT ( 1 ) = 1 ) B ON A.PurchaseOrderNo = B.PurchaseOrderNo \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material t1 ON A.MaterialCode = t1.CustomerPartCode \n"+
" INNER JOIN ( SELECT MaterialCode, PurchaseOrderNo FROM Set_WMSSparePart GROUP BY MaterialCode, PurchaseOrderNo HAVING COUNT ( * ) > 1 ) B ON A.PurchaseOrderNo = B.PurchaseOrderNo \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material t1 ON A.MaterialCode = t1.CustomerPartCode";
// " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' and PurchaseOrderNo is null GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n" +
// " LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n" +
// " LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n" +
// " WHERE\n" +
// " ( a.Version = '{0}' ) \n" +
// " ) AS temp1\n" +
// " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" +
// " ) union2";
// //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp.Sap编码 = TEMP2.MaterialCode\n" +
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, PurchasePriceNoTax ) AS a\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS a\n"+
" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS a\n"+
" LEFT JOIN ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT JOIN ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' ) AS b ON a.MaterialCode = b.MaterialCode\n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT OUTER JOIN ( SELECT MAX ( Id ) Id, MaterialCode, CustomerPartCode, MaterialDesc, EstimateTypeDesc FROM Set_material GROUP BY MaterialCode, MaterialDesc, EstimateTypeDesc, CustomerPartCode ) AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" WHERE\n"+
" WHERE\n"+
@ -395,10 +654,11 @@ public class SparePartSumQtyDiff
[ExporterHeader(DisplayName = "采购订单文本")]
[ExporterHeader(DisplayName = "采购订单文本")]
publicstring采购订单文本{set;get;}
publicstring采购订单文本{set;get;}
[ExporterHeader(DisplayName = "发货数量")]
[ExporterHeader(DisplayName = "收货数量")]
publicdecimal发货数量{set;get;}
publicdecimal收货数量{set;get;}
[ExporterHeader(DisplayName = "开票数量")]
[ExporterHeader(DisplayName = "开票数量")]
publicdecimal开票数量{set;get;}
publicdecimal开票数量{set;get;}
[ExporterHeader(DisplayName = "发货与开票差异")]
[ExporterHeader(DisplayName = "发货与开票差异")]
publicdecimal发货与开票差异{set;get;}
publicdecimal发货与开票差异{set;get;}
[ExporterHeader(DisplayName = "开票单价")]
[ExporterHeader(DisplayName = "开票单价")]
@ -417,5 +677,16 @@ public class SparePartSumQtyDiff