" 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"+
" WHERE\n"+
" WHERE\n"+
" a.Version= '{0}' \n"+
" a.HQHKanBan <>'BJ' AND a.Version= '{0}' \n"+
" ) AS temp1\n"+
" ) AS temp1\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 WHERE temp1.[交货单号] is null ";
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode WHERE temp1.[交货单号] is null ";
" LEFT OUTER JOIN ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' AND Version = '{0}' ) AS b ON a.Kanban = b.HQHKanBan \n"+
" LEFT OUTER JOIN ( SELECT * FROM Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ' ) AS b ON a.Kanban = b.HQHKanBan \n"+
" AND a.MaterialCode = b.MaterialCode\n"+
" AND a.MaterialCode = b.MaterialCode\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"+
" WHERE\n"+
" WHERE\n"+
" b.HQHKanBan IS NULL \n"+
" b.HQHKanBan IS NULL \n"+
" AND b.MaterialCode IS NULL \n"+
" AND b.MaterialCode IS NULL {0} \n"+
" ) AS temp1\n"+
" ) AS temp1\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";
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode";
// " SELECT SUM ( Qty ) AS Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY Kanban, MaterialCode\n" +
// " ) AS a\n" +
// " LEFT JOIN \n" +
// " ( \n" +
// " SELECT SUM\n" +
// " ( Qty ) AS Qty,\n" +
// " HQHKanBan,\n" +
// " MaterialCode,\n" +
// " Version,\n" +
// " StorageLocation,\n" +
// " StorageLocationDesc,\n" +
// " Factory \n" +
// " FROM\n" +
// " Set_HQ_H_Platform WHERE HQHKanBan <> 'BJ'\n" +
// " GROUP BY\n" +
// " HQHKanBan,\n" +
// " MaterialCode,\n" +
// " Version,\n" +
// " StorageLocation,\n" +
// " StorageLocationDesc,\n" +
// " Factory\n" +
// " \n" +
// " ) AS b \n" +
// " ON a.Kanban = b.HQHKanBan \n" +
// " AND a.MaterialCode = b.MaterialCode\n" +
// " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" +
// " WHERE\n" +
// " b.HQHKanBan is NULL \n" +
// " AND b.MaterialCode is NULL \n" +
// " ) AS temp1\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" +
// " LEFT JOIN (\n" +
// " SELECT SUM\n" +
// " ( Amt ) / SUM ( Qty ) AS Price,\n" +
// " HQHKanBan,\n" +
// " MaterialCode,\n" +
// " Version \n" +
// " FROM\n" +
// " Set_HQ_H_Platform \n" +
// " WHERE\n" +
// " HQHKanBan <> 'BJ' \n" +
// " GROUP BY\n" +
// " HQHKanBan,\n" +
// " MaterialCode,\n" +
// " Version \n" +
// " ) AS TEMP3 ON temp1.[结算物料代码] = TEMP3.MaterialCode \n" +
// " AND temp1.订货看板编号 = TEMP3.HQHKanBan";
// var _sql = string.Format(str, version, condition);
// var _query = DbConnection.Query<HQHSettledDetailDiff>(_sql, null, null, true, 1200, null);
" LEFT JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" LEFT JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ) temp1\n"+
" ) temp1\n"+
" LEFT OUTER JOIN (\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS temp2 ON temp1.Sap编码 = temp2.MaterialCode";
// var _sql = string.Format(str, version, condition);
" LEFT JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n"+
" ) temp1\n"+
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS temp2 ON temp1.Sap编码 = temp2.MaterialCode\n"+
" LEFT JOIN (\n"+
" SELECT SUM\n"+
" ( Amt ) / SUM ( Qty ) AS Price,\n"+
" HQHKanBan,\n"+
" MaterialCode,\n"+
" Version \n"+
" FROM\n"+
" FROM\n"+
" Set_PriceList \n"+
" Set_HQ_H_Platform \n"+
" WHERE\n"+
" WHERE\n"+
" (\n"+
" HQHKanBan = 'BJ' \n"+
" Version = ( SELECT MAX( Version ) AS Expr1 FROM Set_PriceList ))) AS temp2 ON temp1.Sap编码 = temp2.MaterialCode";
" AND Version = '{0}' \n"+
;
" GROUP BY\n"+
var_sql=string.Format(str,version,condition);
" HQHKanBan,\n"+
" MaterialCode,\n"+
" Version \n"+
" ) AS TEMP3 ON temp1.[结算物料号] = temp3.MaterialCode";
// var _sql = string.Format(str, version, condition);
" a.WMSDeliveryQty - ISNULL( b.Qty, 0 )) AS DiffQty \n"+
" FROM\n"+
" FROM\n"+
" Set_WMSKanBanSettle A\n"+
" Set_WMSKanBanSettle A \n"+
" LEFT JOIN ( SELECT * FROM Set_KanBanSettle ) B ON A.Kanban = B.Kanban \n"+
" LEFT JOIN ( SELECT * FROM Set_KanBanSettle ) B ON A.Kanban = B.Kanban \n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" AND A.MaterialCode = B.MaterialCode\n"+
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode \n"+
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode {0}\n"+
" WHERE\n"+
" ) TEMP1\n"+
" B.Kanban IS NULL \n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode";
" AND B.MaterialCode IS NULL {0}\n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapCode = TEMP2.MaterialCode";
stringstr=string.Empty;
stringstr=string.Empty;
str+=" where 1=1 ";
//str += " where 1=1 ";
if(!string.IsNullOrEmpty(begintime))
if(!string.IsNullOrEmpty(begintime))
{
{
str+=string.Format(" and WMSActualGoodsDate >='{0}' ",begintime);
str+=string.Format(" and a.WMSActualGoodsDate >='{0}' ",begintime);
}
}
if(string.IsNullOrEmpty(endtime))
if(string.IsNullOrEmpty(endtime))
{
{
str+=string.Format(" and WMSActualGoodsDate<='{0}' ",endtime);
str+=string.Format(" and a.WMSActualGoodsDate<='{0}' ",endtime);
//" ( a.Qty- c.WMSDeliveryQty ) AS SettleWMSDiffQty,--结算与发货差异\n" +
//" 0 AS SettleInvoiceDiffQty,--结算与发货差异\n" +
//" a.Qty AS InvoiceDiffQty,--开票数量,默认0,后续拿算法动态算\n" +
//" d.InvoicePrice,--开票单价\n" +
//" 0 AS InvoiceMoney,--开票金额\n" +
//" '' DeliveryOrderNo --出库单号\n" +
//" \n" +
//" FROM\n" +
//" Set_KanBanSettle AS a\n" +
//" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n" +
//" LEFT JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n" +
//" AND a.MaterialCode= c.MaterialCode\n" +
//" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) d ON a.MaterialCode= d.MaterialCode where a.VERSION='{0}'\n" +
//" ) TEMP1\n" +
//" LEFT JOIN ( SELECT Price, --定价\n" +
//" MaterialCode --厂内物料号\n" +
//" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n" +
//"WHERE 1=1 ";
stringsqlString="SELECT\n"+
stringsqlString="SELECT\n"+
" * ,\n"+
" * ,\n"+
" ISNULL( Price * Qty, 0 ) AS InvoiceMoney,--开票金额\n"+
" ISNULL( Price * Qty, 0 ) AS InvoiceMoney,--开票金额\n"+
" ISNULL( Price * WMSDeliveryQty, 0 ) AS Amount,--金额\n"+
" ISNULL( Price * WMSDeliveryQty, 0 ) AS Amount,--金额\n"+
" ISNULL( Price * Qty, 0 ) AS SettlePrice,--结算金额\n"+
" ISNULL( Price * Qty, 0 ) AS SettlePrice,--结算金额\n"+
" ( Price - InvoicePrice ) AS InvoiceDiffPrice,--单价差异\n"+
" ( Price - InvoicePrice ) AS InvoiceDiffPrice,--单价差异\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n"+
" LEFT JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n"+
" LEFT JOIN Set_WMSKanBanSettle c ON a.Kanban= c.Kanban \n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" AND a.MaterialCode= c.MaterialCode\n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) d ON a.MaterialCode= d.MaterialCode \n"+
" LEFT JOIN ( SELECT SUM ( amt ) / SUM ( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '{0}' GROUP BY materialcode ) d ON a.MaterialCode= d.MaterialCode \n"+
" WHERE\n"+
" WHERE\n"+
" a.VERSION= '{0}' \n"+
" a.VERSION= '{0}' {1} \n"+
" ) TEMP1\n"+
" ) TEMP1\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" LEFT JOIN ( SELECT Price, --定价\n"+
" MaterialCode --厂内物料号\n"+
" MaterialCode --厂内物料号\n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n"+
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n"+