@ -35,114 +35,6 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
{
{
string sqlString = "SELECT\n" +
" union1.* \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" temp1.交货日期,\n" +
" temp1.交货单号,\n" +
" NULL 订单日期,\n" +
" temp1.采购订单号,\n" +
" temp1.SAP编码,\n" +
" temp1.物料代码,\n" +
" temp1.物料描述,\n" +
" temp1.采购订单文本,\n" +
" temp1.开票数量,\n" +
" ISNULL( TEMP4.PurchasePriceNoTax, 0 ) AS 开票单价,\n" +
" ISNULL( temp1.开票数量, 0 ) * ISNULL( TEMP4.PurchasePriceNoTax, 0 ) AS 开票金额,\n" +
" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" +
" ISNULL( TEMP4.PurchasePriceNoTax, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" +
" ( ISNULL( TEMP4.PurchasePriceNoTax, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额,\n" +
" temp1.发货数量,\n" +
" temp1.发货与开票差异,\n" +
" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" +
" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) - ISNULL( temp3.Qty, 0 ) AS 实际交货与开票差异,\n" +
" ISNULL( temp3.Qty, 0 ) 退货数量 \n" +
" FROM\n" +
" (\n" +
" SELECT\n" +
" a.PurchaseOrderNoText AS 采购订单文本,\n" +
" '' AS 交货单号,\n" +
" NULL AS 交货日期,\n" +
" a.PurchaseOrderNo AS 采购订单号,\n" +
" b.MaterialCode AS SAP编码,\n" +
" a.MaterialCode AS 物料代码,\n" +
" b.MaterialDesc AS 物料描述,\n" +
" b.EstimateTypeDesc AS 物料组,\n" +
" ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" +
" ISNULL( C.Qty, 0 ) AS 发货数量,\n" +
" ISNULL( C.Qty, 0 ) - ISNULL( a.InvoicedQty, 0 ) AS 发货与开票差异 \n" +
" FROM\n" +
" (\n" +
" SELECT SUM\n" +
" ( InvoicedQty ) InvoicedQty,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode,\n" +
" PurchaseOrderNoText \n" +
" FROM\n" +
" Set_SparePart \n" +
" WHERE\n" +
" Extend != 'is90' \n" +
" AND PurchaseOrderNo != 'NoOrder' \n" +
" AND Version = '{0}' \n" +
" GROUP BY\n" +
" PurchaseOrderNo,\n" +
" MaterialCode,\n" +
" PurchaseOrderNoText \n" +
" ) AS a\n" +
" LEFT OUTER JOIN Set_material AS b ON a.MaterialCode = b.CustomerPartCode\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" ISNULL( temp1.Qty, 0 ) AS Qty,\n" +
" ( ISNULL( temp1.Qty, 0 ) - ISNULL( temp2.Qty, 0 ) ) WMSDeliveryQty,\n" +
" temp1.MaterialCode,\n" +
" temp1.PurchaseOrderNo \n" +
" FROM\n" +
" (\n" +
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n" +
" LEFT JOIN (\n" +
" SELECT SUM\n" +
" ( InvoicedQty ) Qty,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_SparePart \n" +
" WHERE\n" +
" VERSION = '{0}' \n" +
" AND Extend != 'is90' \n" +
" AND PurchaseOrderNo != 'NoOrder' \n" +
" GROUP BY\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n" +
" AND temp1.MaterialCode = temp2.MaterialCode \n" +
" ) \n" +
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n" +
" AND A.MaterialCode = C.MaterialCode \n" +
" ) AS temp1\n" +
" LEFT JOIN ( SELECT * FROM set_backQty ) temp3 ON temp1.采购订单号 = temp3.Code \n" +
" AND temp1.SAP编码= temp3.MaterialCode\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" ROUND( SUM ( AmountNoTax ) / SUM ( InvoicedQty ), 4 ) PurchasePriceNoTax,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_SparePart \n" +
" WHERE\n" +
" Extend != 'is90' \n" +
" AND PurchaseOrderNo != 'NoOrder' \n" +
" AND Version = '{0}' \n" +
" GROUP BY\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" ) AS TEMP4 ON temp1.[物料代码] = TEMP4.MaterialCode \n" +
" AND temp1.采购订单号 = TEMP4.PurchaseOrderNo \n" +
" ) union1" ;
//加上--往期已经字段
//string sqlString = "SELECT\n" +
//string sqlString = "SELECT\n" +
// " union1.* \n" +
// " union1.* \n" +
// "FROM\n" +
// "FROM\n" +
@ -166,8 +58,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
// " temp1.发货与开票差异,\n" +
// " temp1.发货与开票差异,\n" +
// " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" +
// " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" +
// " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) - ISNULL( temp3.Qty, 0 ) AS 实际交货与开票差异,\n" +
// " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) - ISNULL( temp3.Qty, 0 ) AS 实际交货与开票差异,\n" +
//" ISNULL( temp3.Qty, 0 ) 退货数量,\n" +
// " ISNULL( temp3.Qty, 0 ) 退货数量 \n" +
//" ISNULL( TEMP5.Qty, 0 ) 往期已结 \n" +
// " FROM\n" +
// " FROM\n" +
// " (\n" +
// " (\n" +
// " SELECT\n" +
// " SELECT\n" +
@ -176,7 +67,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
// " NULL AS 交货日期,\n" +
// " NULL AS 交货日期,\n" +
// " a.PurchaseOrderNo AS 采购订单号,\n" +
// " a.PurchaseOrderNo AS 采购订单号,\n" +
// " b.MaterialCode AS SAP编码,\n" +
// " b.MaterialCode AS SAP编码,\n" +
//" b.CustomerPart Code AS 物料代码,\n" +
// " a.Material Code AS 物料代码,\n" +
// " b.MaterialDesc AS 物料描述,\n" +
// " b.MaterialDesc AS 物料描述,\n" +
// " b.EstimateTypeDesc AS 物料组,\n" +
// " b.EstimateTypeDesc AS 物料组,\n" +
// " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" +
// " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" +
@ -249,24 +140,133 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
// " MaterialCode \n" +
// " MaterialCode \n" +
// " ) AS TEMP4 ON temp1.[物料代码] = TEMP4.MaterialCode \n" +
// " ) AS TEMP4 ON temp1.[物料代码] = TEMP4.MaterialCode \n" +
// " AND temp1.采购订单号 = TEMP4.PurchaseOrderNo \n" +
// " AND temp1.采购订单号 = TEMP4.PurchaseOrderNo \n" +
//" LEFT JOIN (\n" +
//" SELECT SUM\n" +
//" ( Qty ) Qty,\n" +
//" OrderBillNum,\n" +
//" Extend1 \n" +
//" FROM\n" +
//" Set_WmsSharePart90OutPutDetial \n" +
//" WHERE\n" +
//" Version < '{0}' \n" +
//" AND State = 2 \n" +
//" AND Extend1 != '' \n" +
//" GROUP BY\n" +
//" OrderBillNum,\n" +
//" Extend1 \n" +
//" ) AS TEMP5 ON temp1.采购订单号 = TEMP5.OrderBillNum \n" +
//" AND temp1.[物料代码] = TEMP5.Extend1 \n" +
// " ) union1";
// " ) union1";
//加上--往期已经字段
string sqlString = "SELECT\n" +
" union1.* \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" temp1.交货日期,\n" +
" temp1.交货单号,\n" +
" NULL 订单日期,\n" +
" temp1.采购订单号,\n" +
" temp1.SAP编码,\n" +
" temp1.物料代码,\n" +
" temp1.物料描述,\n" +
" temp1.采购订单文本,\n" +
" temp1.开票数量,\n" +
" ISNULL( TEMP4.PurchasePriceNoTax, 0 ) AS 开票单价,\n" +
" ISNULL( temp1.开票数量, 0 ) * ISNULL( TEMP4.PurchasePriceNoTax, 0 ) AS 开票金额,\n" +
" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" +
" ISNULL( TEMP4.PurchasePriceNoTax, 0 ) - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" +
" ( ISNULL( TEMP4.PurchasePriceNoTax, 0 ) - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额,\n" +
" temp1.发货数量,\n" +
" temp1.发货与开票差异,\n" +
" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" +
" ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) - ISNULL( temp3.Qty, 0 ) AS 实际交货与开票差异,\n" +
" ISNULL( temp3.Qty, 0 ) 退货数量,\n" +
" ISNULL( TEMP5.Qty, 0 ) 往期已结 \n" +
" FROM\n" +
" (\n" +
" SELECT\n" +
" a.PurchaseOrderNoText AS 采购订单文本,\n" +
" '' AS 交货单号,\n" +
" NULL AS 交货日期,\n" +
" a.PurchaseOrderNo AS 采购订单号,\n" +
" b.MaterialCode AS SAP编码,\n" +
" b.CustomerPartCode AS 物料代码,\n" +
" b.MaterialDesc AS 物料描述,\n" +
" b.EstimateTypeDesc AS 物料组,\n" +
" ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" +
" ISNULL( C.Qty, 0 ) AS 发货数量,\n" +
" ISNULL( C.Qty, 0 ) - ISNULL( a.InvoicedQty, 0 ) AS 发货与开票差异 \n" +
" FROM\n" +
" (\n" +
" SELECT SUM\n" +
" ( InvoicedQty ) InvoicedQty,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode,\n" +
" PurchaseOrderNoText \n" +
" FROM\n" +
" Set_SparePart \n" +
" WHERE\n" +
" Extend != 'is90' \n" +
" AND PurchaseOrderNo != 'NoOrder' \n" +
" AND Version = '{0}' \n" +
" GROUP BY\n" +
" PurchaseOrderNo,\n" +
" MaterialCode,\n" +
" PurchaseOrderNoText \n" +
" ) AS a\n" +
" LEFT OUTER JOIN Set_material AS b ON a.MaterialCode = b.CustomerPartCode\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" ISNULL( temp1.Qty, 0 ) AS Qty,\n" +
" ( ISNULL( temp1.Qty, 0 ) - ISNULL( temp2.Qty, 0 ) ) WMSDeliveryQty,\n" +
" temp1.MaterialCode,\n" +
" temp1.PurchaseOrderNo \n" +
" FROM\n" +
" (\n" +
" ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) temp1\n" +
" LEFT JOIN (\n" +
" SELECT SUM\n" +
" ( InvoicedQty ) Qty,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_SparePart \n" +
" WHERE\n" +
" VERSION = '{0}' \n" +
" AND Extend != 'is90' \n" +
" AND PurchaseOrderNo != 'NoOrder' \n" +
" GROUP BY\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" ) temp2 ON temp1.PurchaseOrderNo = temp2.PurchaseOrderNo \n" +
" AND temp1.MaterialCode = temp2.MaterialCode \n" +
" ) \n" +
" ) C ON A.PurchaseOrderNo = C.PurchaseOrderNo \n" +
" AND A.MaterialCode = C.MaterialCode \n" +
" ) AS temp1\n" +
" LEFT JOIN ( SELECT * FROM set_backQty ) temp3 ON temp1.采购订单号 = temp3.Code \n" +
" AND temp1.SAP编码= temp3.MaterialCode\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" ROUND( SUM ( AmountNoTax ) / SUM ( InvoicedQty ), 4 ) PurchasePriceNoTax,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_SparePart \n" +
" WHERE\n" +
" Extend != 'is90' \n" +
" AND PurchaseOrderNo != 'NoOrder' \n" +
" AND Version = '{0}' \n" +
" GROUP BY\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" ) AS TEMP4 ON temp1.[物料代码] = TEMP4.MaterialCode \n" +
" AND temp1.采购订单号 = TEMP4.PurchaseOrderNo\n" +
" LEFT JOIN (\n" +
" SELECT SUM\n" +
" ( Qty ) Qty,\n" +
" OrderBillNum,\n" +
" Extend1 \n" +
" FROM\n" +
" Set_WmsSharePart90OutPutDetial \n" +
" WHERE\n" +
" Version < '{0}' \n" +
" AND State = 2 \n" +
" AND Extend1 != '' \n" +
" GROUP BY\n" +
" OrderBillNum,\n" +
" Extend1 \n" +
" ) AS TEMP5 ON temp1.采购订单号 = TEMP5.OrderBillNum \n" +
" AND temp1.[物料代码] = TEMP5.Extend1 \n" +
" ) union1" ;
string _ sql = string . Format ( sqlString , version ) ;
string _ sql = string . Format ( sqlString , version ) ;
@ -1286,7 +1286,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" MaterialCode\n" +
" MaterialCode\n" +
" ) AS a\n" +
" ) AS a\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" +
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, OrderBillNum, Extend1 FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 GROUP BY OrderBillNum, Extend1 ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" +
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, OrderBillNum, Extend1 FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 and Extend1!='' GROUP BY OrderBillNum, Extend1 ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" +
" AND a.MaterialCode = b.Extend1 \n" +
" AND a.MaterialCode = b.Extend1 \n" +
" WHERE\n" +
" WHERE\n" +
" b.OrderBillNum IS NULL \n" +
" b.OrderBillNum IS NULL \n" +
@ -1343,7 +1343,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" PurchaseOrderNo,\n" +
" PurchaseOrderNo,\n" +
" MaterialCode \n" +
" MaterialCode \n" +
" ) a\n" +
" ) a\n" +
" INNER JOIN ( SELECT SUM ( Qty ) ReceiptQty, OrderBillNum, Extend1 FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 GROUP BY OrderBillNum, Extend1 ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" +
" INNER JOIN ( SELECT SUM ( Qty ) ReceiptQty, OrderBillNum, Extend1 FROM Set_WmsSharePart90OutPutDetial WHERE State = 2 and Extend1!='' GROUP BY OrderBillNum, Extend1 ) AS b ON a.PurchaseOrderNo= b.OrderBillNum \n" +
" AND a.MaterialCode = b.Extend1\n" +
" AND a.MaterialCode = b.Extend1\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" +