@ -27,22 +27,22 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
/// <param name="end"></param>
/// <param name="materialGroup"></param>
/// <returns></returns>
public virtual List < HQFactoryUn SettledDetailDiff > GetHQFactoryDetailDiffReportList ( string version , string materialCode ,
public virtual List < HQSettledUnFactory DetailDiff > GetHQFactoryDetailDiffReportList ( string version , string materialCode ,
string begin , string end , string materialGroup , string iscontionversion )
{
List < HQFactoryUn SettledDetailDiff > _l ist = new List < HQFactoryUn SettledDetailDiff > ( ) ;
List < HQSettledUnFactory DetailDiff > _l ist = new List < HQSettledUnFactory DetailDiff > ( ) ;
string condition = " " ;
//if (!string.IsNullOrEmpty(begin))
//{
// condition += string.Format( " and a.LastModificationTime>='{0}' ", begin);
//}
//if (!string.IsNullOrEmpty(end))
//{
// condition += string.Format( " and a.LastModificationTime<='{0}' ", end);
//}
if ( ! string . IsNullOrEmpty ( begin ) )
{
condition + = string . Format ( " and a.LastModificationTime>='{0}' " , begin ) ;
}
if ( ! string . IsNullOrEmpty ( end ) )
{
condition + = string . Format ( " and a.LastModificationTime<='{0}' " , end ) ;
}
string contion = string . Empty ;
//选中,是否过滤掉当期结算数据
@ -55,16 +55,157 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
contion + = " WHERE 1=1 " ;
}
string conditionDate = "" ;
if ( ! string . IsNullOrEmpty ( begin ) )
{
conditionDate + = string . Format ( " and LastModificationTime>='{0}' " , begin ) ;
}
if ( ! string . IsNullOrEmpty ( end ) )
{
conditionDate + = string . Format ( " and LastModificationTime<='{0}' " , end ) ;
}
#region
//string str = "SELECT\n" +
// " temp3.HQHKanBan 订货看板编号, temp3.ExternalKanbanNumber 外部单号,\n" +
// " temp3.MaterialCode Sap编码,\n" +
// " temp3.hqMaterialCode 客户物料号,\n" +
// " temp3.EstimateTypeDesc 物料组,\n" +
// " temp3.MaterialDesc 零件中文名称,\n" +
// " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" +
// " temp3.发货数量,\n" +
// " temp3.结算数量,\n" +
// " temp3.退货数量,\n" +
// " temp3.系统未结数量,\n" +
// " temp3.UnHQQty 红旗未结数量,\n" +
// " ( ISNULL( temp3.系统未结数量, 0 ) - ISNULL( temp3.UnHQQty, 0 ) ) 差异 \n" +
// "FROM\n" +
// " (\n" +
// " SELECT\n" +
// " * \n" +
// " FROM\n" +
// " (\n" +
// " SELECT\n" +
// " h.HQHKanBan, h.ExternalKanbanNumber, \n" +
// " m.MaterialCode,\n" +
// " h.MaterialCode hqMaterialCode,\n" +
// " m.CustomerPartCode,\n" +
// " m.MaterialDesc,\n" +
// " m.EstimateTypeDesc,\n" +
// " ISNULL( h.Qty, 0 ) AS UnHQQty \n" +
// " FROM\n" +
// " ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode,ExternalKanbanNumber FROM Set_UnHQSettleAccount WHERE Version ='{0}' GROUP BY HQHKanBan, MaterialCode,ExternalKanbanNumber ) AS h\n" +
// " LEFT JOIN Set_material AS m ON h.MaterialCode = m.CustomerPartCode \n" +
// " ) AS unhq\n" +
// " LEFT JOIN (\n" +
// " SELECT\n" +
// " * \n" +
// " FROM\n" +
// " (\n" +
// " SELECT\n" +
// " isnull( temp1.交货单号, '' ) 交货单号,\n" +
// " NULL 交货时间,\n" +
// " temp1.订货看板编号,\n" +
// " temp1.订货零件号,\n" +
// " temp1.Sap编码,\n" +
// " temp1.[客户物料号],\n" +
// " temp1.物料组,\n" +
// " temp1.零件中文名称,\n" +
// " temp1.发货数量,\n" +
// " temp1.外部单号,\n" +
// " temp1.结算数量,\n" +
// " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" +
// " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" +
// " isnull( tt.Qty, 0 ) 退货数量,\n" +
// " isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 系统未结数量 \n" +
// " FROM\n" +
// " (\n" +
// " SELECT\n" +
// " '' AS 交货单号,\n" +
// " a.Kanban AS 订货看板编号,\n" +
// " b.MaterialCode AS 订货零件号,\n" +
// " c.MaterialCode Sap编码,\n" +
// " c.CustomerPartCode 客户物料号,\n" +
// " c.MaterialDesc AS 零件中文名称,\n" +
// " isnull( a.Qty, 0 ) AS 发货数量,\n" +
// " '' AS 外部单号,\n" +
// " isnull( b.Qty, 0 ) AS 结算数量,\n" +
// " C.EstimateTypeDesc AS 物料组 \n" +
// " FROM\n" +
// " ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1=1 {2} GROUP BY kanban, MaterialCode ) AS a\n" +
// " LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b 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 = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
// " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" +
// " AND temp1.订货看板编号 = tt.Code \n" +
// " ) UNION1 UNION ALL\n" +
// " SELECT\n" +
// " * \n" +
// " FROM\n" +
// " (\n" +
// " SELECT\n" +
// " isnull( temp1.交货单号, '' ) 交货单号,\n" +
// " NULL 交货时间,\n" +
// " temp1.订货看板编号,\n" +
// " temp1.订货零件号,\n" +
// " temp1.Sap编码,\n" +
// " temp1.[客户物料号],\n" +
// " temp1.物料组,\n" +
// " temp1.零件中文名称,\n" +
// " temp1.发货数量,\n" +
// " temp1.外部单号,\n" +
// " temp1.结算数量,\n" +
// " isnull( TEMP2.Price, 0 ) AS 发货定价,\n" +
// " isnull( temp1.发货数量, 0 ) * isnull( TEMP2.Price, 0 ) AS 发货总金额,\n" +
// " isnull( tt.Qty, 0 ) 退货数量,\n" +
// " isnull( temp1.发货数量, 0 ) - isnull( temp1.结算数量, 0 ) - isnull( tt.Qty, 0 ) AS 系统未结数量 \n" +
// " FROM\n" +
// " (\n" +
// " SELECT\n" +
// " '' AS 交货单号,\n" +
// " a.Kanban AS 订货看板编号,\n" +
// " b.MaterialCode AS 订货零件号,\n" +
// " c.MaterialCode Sap编码,\n" +
// " c.CustomerPartCode 客户物料号,\n" +
// " c.MaterialDesc AS 零件中文名称,\n" +
// " isnull( a.Qty, 0 ) AS 发货数量,\n" +
// " '' AS 外部单号,\n" +
// " isnull( b.Qty, 0 ) AS 结算数量,\n" +
// " C.EstimateTypeDesc AS 物料组 \n" +
// " FROM\n" +
// " ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1=1 {2} GROUP BY kanban, MaterialCode ) AS a\n" +
// " INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b 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" +
// " a.Qty> b.Qty \n" +
// " ) AS temp1\n" +
// " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
// " LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" +
// " AND temp1.订货看板编号 = tt.Code \n" +
// " ) UNION2 \n" +
// " ) AS temp1 ON unhq.HQHKanBan = temp1.[订货看板编号] \n" +
// " AND unhq.CustomerPartCode= temp1.客户物料号 WHERE temp1.[订货看板编号] is null and temp1.客户物料号 is null \n" +
// " ) temp3\n" +
// " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp3.MaterialCode = TEMP2.MaterialCode";
#endregion
string str = "SELECT\n" +
" temp3.HQHKanBan 订货看板编号,\n" +
" temp3.ExternalKanbanNumber 外部单号,\n" +
" temp3.MaterialCode Sap编码,\n" +
" temp3.hqMaterialCode 客户物料号,\n" +
" temp3.EstimateTypeDesc 物料组,\n" +
" temp3.MaterialDesc 零件中文名称,\n" +
" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" +
" temp3.发货数量,\n" +
" temp3.结算数量,\n" +
" temp3.退货数量,\n" +
" isnull( temp3.Qty, 0 ) 结算数量 ,\n" +
" isnull( temp3.Qty, 0 ) 结算单价,\n" +
" isnull( temp3.Qty, 0 ) * isnull( temp3.Qty, 0 ) 结算金额,\n" +
" temp3.系统未结数量,\n" +
" temp3.UnHQQty 红旗未结数量,\n" +
" ( ISNULL( temp3.系统未结数量, 0 ) - ISNULL( temp3.UnHQQty, 0 ) ) 差异 \n" +
@ -76,6 +217,9 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" (\n" +
" SELECT\n" +
" h.HQHKanBan,\n" +
" h.Qty,\n" +
" h.Price,\n" +
" h.ExternalKanbanNumber,\n" +
" m.MaterialCode,\n" +
" h.MaterialCode hqMaterialCode,\n" +
" m.CustomerPartCode,\n" +
@ -83,7 +227,23 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" m.EstimateTypeDesc,\n" +
" ISNULL( h.Qty, 0 ) AS UnHQQty \n" +
" FROM\n" +
" ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_UnHQSettleAccount GROUP BY HQHKanBan, MaterialCode ) AS h\n" +
" (\n" +
" SELECT SUM\n" +
" ( Qty ) Qty,\n" +
" HQHKanBan,\n" +
" MaterialCode,\n" +
" ExternalKanbanNumber,\n" +
" Price \n" +
" FROM\n" +
" Set_UnHQSettleAccount \n" +
" WHERE\n" +
" Version = '{0}' \n" +
" GROUP BY\n" +
" HQHKanBan,\n" +
" MaterialCode,\n" +
" ExternalKanbanNumber,\n" +
" Price \n" +
" ) AS h\n" +
" LEFT JOIN Set_material AS m ON h.MaterialCode = m.CustomerPartCode \n" +
" ) AS unhq\n" +
" LEFT JOIN (\n" +
@ -121,7 +281,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" isnull( b.Qty, 0 ) AS 结算数量,\n" +
" C.EstimateTypeDesc AS 物料组 \n" +
" FROM\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1 = 1 {2} GROUP BY kanban, MaterialCode ) AS a\n" +
" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b 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" +
@ -130,7 +290,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" AND b.MaterialCode IS NULL \n" +
" ) AS temp1\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" AND temp1.订货看板编号 = tt.Code \n" +
" ) UNION1 UNION ALL\n" +
" SELECT\n" +
@ -167,7 +327,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" isnull( b.Qty, 0 ) AS 结算数量,\n" +
" C.EstimateTypeDesc AS 物料组 \n" +
" FROM\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1 = 1 {2} GROUP BY kanban, MaterialCode ) AS a\n" +
" INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b 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" +
@ -175,228 +335,241 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" a.Qty> b.Qty \n" +
" ) AS temp1\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" AND temp1.订货看板编号 = tt.Code \n" +
" ) UNION2 \n" +
" ) AS temp1 ON unhq.HQHKanBan = temp1.[订货看板编号] \n" +
" AND unhq.CustomerPartCode= temp1.客户物料号 WHERE temp1.[订货看板编号] is null and temp1.客户物料号 is null \n" +
" AND unhq.CustomerPartCode= temp1.客户物料号 \n" +
" WHERE\n" +
" temp1.[订货看板编号] IS NULL \n" +
" AND temp1.客户物料号 IS NULL \n" +
" ) temp3\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp3.MaterialCode = TEMP2.MaterialCode" ;
var _ sql = string . Format ( str , version , contion ) ;
var sql2 = "SELECT\n" +
" a.WmsBillNum,\n" +
" t1.MaterialCode MaterialCode,\n" +
" a.Kanban ,\n" +
" A.LastModificationTime WmsDate \n" +
"FROM\n" +
" Set_HQ_H_Kanban A\n" +
" INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" +
" AND A.MaterialCode = B.MaterialCode " +
" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode " ;
var listCompare = DbConnection . Query < CompareFactoryExtend > ( sql2 ) ;
var sql3 = "SELECT\n" +
" a.WmsBillNum,\n" +
" t1.MaterialCode MaterialCode,\n" +
" a.Kanban,\n" +
" A.LastModificationTime WmsDate \n" +
"FROM\n" +
" Set_HQ_H_Kanban A\n" +
" LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" +
" AND A.MaterialCode = B.MaterialCode \n" +
" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode \n" +
"WHERE\n" +
" B.Kanban IS NULL" ;
var listCompare1 = DbConnection . Query < CompareFactoryExtend > ( sql3 ) ;
var sql10 = "SELECT DISTINCT\n" +
" t1.* \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n" +
" a.KanbanNumber AS KanbanNumber,\n" +
" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS AcceptanceDate,\n" +
" HQHKanBan,\n" +
" b2.MaterialCode \n" +
" FROM\n" +
" Set_UnHQSettleAccount a\n" +
" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n" +
" WHERE\n" +
" Version = '{0}' \n" +
" AND HQHKanBan <> 'BJ' \n" +
" ) t1\n" +
" LEFT JOIN (\n" +
" SELECT\n" +
" HQHKanBan,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_UnHQSettleAccount a \n" +
" WHERE\n" +
" Version = '{0}' \n" +
" AND HQHKanBan <> 'BJ' \n" +
" GROUP BY\n" +
" HQHKanBan,\n" +
" MaterialCode \n" +
" HAVING\n" +
" COUNT ( * ) > 1 \n" +
" ) t2 ON t1.HQHKanBan = t2.HQHKanBan \n" +
" AND t1.MaterialCode = t2.MaterialCode \n" +
"WHERE\n" +
" t2.HQHKanBan IS NULL" ;
var list11 = DbConnection . Query < CompareFactoryExtend1 > ( string . Format ( sql10 , version ) ) ;
var sql11 = "SELECT DISTINCT\n" +
" t1.* \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n" +
" a.KanbanNumber AS KanbanNumber,\n" +
" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS AcceptanceDate,\n" +
" HQHKanBan,\n" +
" b2.MaterialCode \n" +
" FROM\n" +
" Set_UnHQSettleAccount a\n" +
" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n" +
" WHERE\n" +
" Version = '{0}' \n" +
" AND HQHKanBan <> 'BJ' \n" +
" ) t1\n" +
" INNER JOIN (\n" +
" SELECT\n" +
" HQHKanBan,\n" +
" MaterialCode \n" +
" FROM\n" +
" Set_UnHQSettleAccount a \n" +
" WHERE\n" +
" Version = '{0}' \n" +
" AND HQHKanBan <> 'BJ' \n" +
" GROUP BY\n" +
" HQHKanBan,\n" +
" MaterialCode \n" +
" HAVING\n" +
" COUNT ( * ) > 1 \n" +
" ) t2 ON t1.HQHKanBan = t2.HQHKanBan \n" +
" AND t1.MaterialCode = t2.MaterialCode \n" +
"ORDER BY\n" +
" t1.HQHKanBan,\n" +
" t1.MaterialCode" ;
var list12 = DbConnection . Query < CompareFactoryExtend1 > ( string . Format ( sql11 , version ) ) ;
var sql12 = "SELECT\n" +
" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n" +
" a.KanbanNumber AS KanbanNumber,\n" +
" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS AcceptanceDate,\n" +
" HQHKanBan,\n" +
" b2.MaterialCode \n" +
"FROM\n" +
" Set_UnHQSettleAccount a\n" +
" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n" +
"WHERE\n" +
" Version = '{0}' \n" +
" AND HQHKanBan = 'BJ'" ;
var list13 = DbConnection . Query < CompareFactoryExtend1 > ( string . Format ( sql12 , version ) ) ;
List < CompareFactoryExtend1 > _l scopy = new List < CompareFactoryExtend1 > ( ) ;
foreach ( var itm in list11 )
{
var first = _l scopy . FirstOrDefault ( p = > p . HQHKanBan = = itm . HQHKanBan & & p . MaterialCode = = itm . MaterialCode ) ;
if ( first ! = null )
{
//first.KanbanNumber += "," + itm.KanbanNumber;
//first.AcceptanceDate += "," + itm.AcceptanceDate;
first . ExternalKanbanNumber + = "," + itm . ExternalKanbanNumber ;
}
else
{
_l scopy . Add ( itm ) ;
}
}
foreach ( var itm in list12 )
{
_l scopy . Add ( itm ) ;
}
foreach ( var itm in list13 )
{
_l scopy . Add ( itm ) ;
}
var _ sql = string . Format ( str , version , contion , conditionDate ) ;
////发运数据中,查出看板号+物料号相同的重复数据
//var sql2 = "SELECT\n" +
// " a.WmsBillNum,\n" +
// " t1.MaterialCode MaterialCode,\n" +
// " a.Kanban ,\n" +
// " A.LastModificationTime WmsDate \n" +
// "FROM\n" +
// " Set_HQ_H_Kanban A\n" +
// " INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT ( * ) > 1 ) B ON A.Kanban = B.Kanban \n" +
// " AND A.MaterialCode = B.MaterialCode\n" +
// " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n" +
// "WHERE\n" +
// " 1 = 1 {0}";
//var _sql2 = string.Format(sql2, condition);
//var listCompare = DbConnection.Query<CompareFactoryExtend>(_sql2);
////查询发运表中,看板号+物料号没有重复的数据
//var sql3 = "SELECT\n" +
//" a.WmsBillNum,\n" +
//" t1.MaterialCode MaterialCode,\n" +
//" a.Kanban,\n" +
//" A.LastModificationTime WmsDate \n" +
//"FROM\n" +
//" Set_HQ_H_Kanban A\n" +
//" LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_HQ_H_Kanban GROUP BY MaterialCode, Kanban HAVING COUNT(*)> 1 ) B ON A.Kanban = B.Kanban \n" +
//" AND A.MaterialCode = B.MaterialCode \n" +
//" left join Set_material t1 on a.MaterialCode=t1.CustomerPartCode \n" +
//"WHERE\n" +
//" B.Kanban IS NULL {0} ";
//var _sql3 = string.Format(sql3, condition);
//var listCompare1 = DbConnection.Query<CompareFactoryExtend>(_sql3);
//var sql10 = "SELECT DISTINCT\n" +
//" t1.* \n" +
//"FROM\n" +
//" (\n" +
//" SELECT\n" +
//" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n" +
//" a.KanbanNumber AS KanbanNumber,\n" +
//" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS AcceptanceDate,\n" +
//" HQHKanBan,\n" +
//" b2.MaterialCode \n" +
//" FROM\n" +
//" Set_UnHQSettleAccount a\n" +
//" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n" +
//" WHERE\n" +
//" Version = '{0}' \n" +
//" AND HQHKanBan <> 'BJ' \n" +
//" ) t1\n" +
//" LEFT JOIN (\n" +
//" SELECT\n" +
//" HQHKanBan,\n" +
//" MaterialCode \n" +
//" FROM\n" +
//" Set_UnHQSettleAccount a \n" +
//" WHERE\n" +
//" Version = '{0}' \n" +
//" AND HQHKanBan <> 'BJ' \n" +
//" GROUP BY\n" +
//" HQHKanBan,\n" +
//" MaterialCode \n" +
//" HAVING\n" +
//" COUNT ( * ) > 1 \n" +
//" ) t2 ON t1.HQHKanBan = t2.HQHKanBan \n" +
//" AND t1.MaterialCode = t2.MaterialCode \n" +
//"WHERE\n" +
//" t2.HQHKanBan IS NULL";
//var list11 = DbConnection.Query<CompareFactoryExtend1>(string.Format(sql10, version));
//var sql11 = "SELECT DISTINCT\n" +
//" t1.* \n" +
//"FROM\n" +
//" (\n" +
//" SELECT\n" +
//" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n" +
//" a.KanbanNumber AS KanbanNumber,\n" +
//" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS AcceptanceDate,\n" +
//" HQHKanBan,\n" +
//" b2.MaterialCode \n" +
//" FROM\n" +
//" Set_UnHQSettleAccount a\n" +
//" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n" +
//" WHERE\n" +
//" Version = '{0}' \n" +
//" AND HQHKanBan <> 'BJ' \n" +
//" ) t1\n" +
//" INNER JOIN (\n" +
//" SELECT\n" +
//" HQHKanBan,\n" +
//" MaterialCode \n" +
//" FROM\n" +
//" Set_UnHQSettleAccount a \n" +
//" WHERE\n" +
//" Version = '{0}' \n" +
//" AND HQHKanBan <> 'BJ' \n" +
//" GROUP BY\n" +
//" HQHKanBan,\n" +
//" MaterialCode \n" +
//" HAVING\n" +
//" COUNT ( * ) > 1 \n" +
//" ) t2 ON t1.HQHKanBan = t2.HQHKanBan \n" +
//" AND t1.MaterialCode = t2.MaterialCode \n" +
//"ORDER BY\n" +
//" t1.HQHKanBan,\n" +
//" t1.MaterialCode";
//var list12 = DbConnection.Query<CompareFactoryExtend1>(string.Format(sql11, version));
//var sql12 = "SELECT\n" +
//" a.ExternalKanbanNumber AS ExternalKanbanNumber,\n" +
//" a.KanbanNumber AS KanbanNumber,\n" +
//" CONVERT ( VARCHAR ( 100 ), a.AcceptanceDate, 23 ) AS AcceptanceDate,\n" +
//" HQHKanBan,\n" +
//" b2.MaterialCode \n" +
//"FROM\n" +
//" Set_UnHQSettleAccount a\n" +
//" LEFT JOIN Set_material b2 ON a.MaterialCode = b2.CustomerPartCode \n" +
//"WHERE\n" +
//" Version = '{0}' \n" +
//" AND HQHKanBan = 'BJ'";
//var list13 = DbConnection.Query<CompareFactoryExtend1>(string.Format(sql12, version));
//List<CompareFactoryExtend1> _lscopy = new List<CompareFactoryExtend1>();
//foreach (var itm in list11)
//{
// var first = _lscopy.FirstOrDefault(p => p.HQHKanBan == itm.HQHKanBan && p.MaterialCode == itm.MaterialCode);
// if (first != null)
// {
// //first.KanbanNumber += "," + itm.KanbanNumber;
// //first.AcceptanceDate += "," + itm.AcceptanceDate;
// first.ExternalKanbanNumber += "," + itm.ExternalKanbanNumber;
// }
// else
// {
// _lscopy.Add(itm);
// }
//}
//foreach (var itm in list12)
//{
// _lscopy.Add(itm);
//}
//foreach (var itm in list13)
//{
// _lscopy.Add(itm);
//}
List < CompareFactoryExtend > _l s = new List < CompareFactoryExtend > ( ) ;
foreach ( var itm in listCompare . ToList ( ) )
{
var first = _l s . FirstOrDefault ( p = > p . Kanban = = itm . Kanban & & p . MaterialCode = = itm . MaterialCode ) ;
if ( first ! = null )
{
if ( ! string . IsNullOrEmpty ( itm . WmsDate ) )
{
itm . WmsDate = DateTime . Parse ( itm . WmsDate ) . ToShortDateString ( ) ;
}
first . WmsBillNum + = "," + itm . WmsBillNum ;
first . WmsDate + = "," + itm . WmsDate ;
}
else
{
if ( ! string . IsNullOrEmpty ( itm . WmsDate ) )
{
itm . WmsDate = DateTime . Parse ( itm . WmsDate ) . ToShortDateString ( ) ;
}
_l s . Add ( itm ) ;
}
//List<CompareFactoryExtend> _ls = new List<CompareFactoryExtend>();
//foreach (var itm in listCompare.ToList())
//{
// var first = _ls.FirstOrDefault(p => p.Kanban == itm.Kanban && p.MaterialCode == itm.MaterialCode);
// if (first != null)
// {
// if (!string.IsNullOrEmpty(itm.WmsDate))
// {
// itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString();
// }
// first.WmsBillNum += "," + itm.WmsBillNum;
// first.WmsDate += "," + itm.WmsDate;
// }
// else
// {
// if (!string.IsNullOrEmpty(itm.WmsDate))
// {
// itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString();
// }
// _ls.Add(itm);
// }
}
//}
foreach ( var itm in listCompare1 . ToList ( ) )
{
if ( ! string . IsNullOrEmpty ( itm . WmsDate ) )
{
itm . WmsDate = DateTime . Parse ( itm . WmsDate ) . ToShortDateString ( ) ;
}
_l s . Add ( itm ) ;
}
//foreach (var itm in listCompare1.ToList())
//{
// if (!string.IsNullOrEmpty(itm.WmsDate))
// {
// itm.WmsDate = DateTime.Parse(itm.WmsDate).ToShortDateString();
// }
// _ls.Add(itm);
//}
var _ query = DbConnection . Query < HQFactoryUn SettledDetailDiff > ( _ sql , null , null , true , 1 2 0 0 , null ) ;
var _ query = DbConnection . Query < HQSettledUnFactory DetailDiff > ( _ sql , null , null , true , 1 2 0 0 , null ) ;
_l ist = _ query . ToList ( ) ;
foreach ( var itm1 in _l ist )
{
var itm = _l s . FirstOrDefault ( p = > p . Kanban = = itm1 . 订 货 看 板 编 号 & & p . MaterialCode = = itm1 . Sap编码 ) ;
if ( itm ! = null )
{
itm1 . 交 货 单 号 = itm . WmsBillNum ;
itm1 . 交 货 时 间 = itm . WmsDate ;
}
var itmcopy = _l scopy . FirstOrDefault ( p = > p . HQHKanBan = = itm1 . 订 货 看 板 编 号 & & p . MaterialCode = = itm1 . Sap编码 ) ;
if ( itmcopy ! = null )
{
//itm1.看板编号 = itmcopy.KanbanNumber;
//itm1.验收单日期 = itmcopy.AcceptanceDate;
itm1 . 外 部 单 号 = itmcopy . ExternalKanbanNumber ;
}
}
//foreach (var itm1 in _list)
//{
// //var itm = _ls.FirstOrDefault(p => p.Kanban == itm1.订货看板编号 && p.MaterialCode == itm1.Sap编码);
// //if (itm != null)
// //{
// // itm1.交货单号 = itm.WmsBillNum;
// // itm1.交货时间 = itm.WmsDate;
// //}
// var itmcopy = _lscopy.FirstOrDefault(p => p.HQHKanBan == itm1.订货看板编号 && p.MaterialCode == itm1.Sap编码);
// if (itmcopy != null)
// {
// //itm1.看板编号 = itmcopy.KanbanNumber;
// //itm1.验收单日期 = itmcopy.AcceptanceDate;
// itm1.外部单号 = itmcopy.ExternalKanbanNumber;
// }
//}
return _l ist ;
@ -442,6 +615,17 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
contion + = " WHERE 1=1 " ;
}
string conditionDate = "" ;
if ( ! string . IsNullOrEmpty ( begin ) )
{
conditionDate + = string . Format ( " and LastModificationTime>='{0}' " , begin ) ;
}
if ( ! string . IsNullOrEmpty ( end ) )
{
conditionDate + = string . Format ( " and LastModificationTime<='{0}' " , end ) ;
}
string str = "SELECT\n" +
@ -455,6 +639,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" temp.零件中文名称,\n" +
" isnull( TEMP2.Price, 0 ) AS 发货定价,\n" +
" temp.发货数量,\n" +
" isnull( TEMP2.Price, 0 )*isnull(temp.发货数量, 0 ) 发货总金额,\n" +
" temp.结算数量,\n" +
" temp.退货数量,\n" +
" ISNULL( temp.系统未结数量, 0 ) 系统未结数量,\n" +
@ -492,12 +677,12 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" c.CustomerPartCode 客户物料号,\n" +
" c.MaterialDesc AS 零件中文名称,\n" +
" isnull( a.Qty, 0 ) AS 发货数量,\n" +
" '' AS 外部单号,\n" +
" b.ExternalKanbanNumber AS 外部单号,\n" +
" isnull( b.Qty, 0 ) AS 结算数量,\n" +
" C.EstimateTypeDesc AS 物料组 \n" +
" FROM\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n" +
" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b ON a.Kanban = b.HQHKanBan \n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1=1 {0} GROUP BY kanban, MaterialCode ) AS a\n" +
" LEFT OUTER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode,ExternalKanbanNumber FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode,ExternalKanbanNumber ) AS b 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" +
@ -505,7 +690,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" AND b.MaterialCode IS NULL \n" +
" ) AS temp1\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" AND temp1.订货看板编号 = tt.Code \n" +
" ) UNION1 UNION ALL\n" +
" SELECT\n" +
@ -542,7 +727,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" isnull( b.Qty, 0 ) AS 结算数量,\n" +
" C.EstimateTypeDesc AS 物料组 \n" +
" FROM\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban GROUP BY kanban, MaterialCode ) AS a\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_HQ_H_Kanban WHERE 1=1 {0} GROUP BY kanban, MaterialCode ) AS a\n" +
" INNER JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_HQ_H_Platform {1} GROUP BY HQHKanBan, MaterialCode ) AS b 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" +
@ -550,17 +735,17 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" a.Qty> b.Qty \n" +
" ) AS temp1\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.Sap编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" LEFT JOIN set_backQty tt ON temp1.Sap编码 = tt.MaterialCode \n" +
" AND temp1.订货看板编号 = tt.Code \n" +
" ) UNION2 \n" +
" ) AS temp\n" +
" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp.Sap编码 = TEMP2.MaterialCode\n" +
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_UnHQSettleAccount GROUP BY HQHKanBan, MaterialCode ) temp3 ON temp.[订货看板编号] = temp3.HQHKanBan \n" +
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, HQHKanBan, MaterialCode FROM Set_UnHQSettleAccount WHERE Version ='{2}' GROUP BY HQHKanBan, MaterialCode ) temp3 ON temp.[订货看板编号] = temp3.HQHKanBan \n" +
" AND temp.[客户物料号] = temp3.MaterialCode" ;
var _ sql = string . Format ( str , version , cont ion) ;
var _ sql = string . Format ( str , conditionDate , contion , vers ion) ;
@ -716,10 +901,12 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
[ExporterHeader(DisplayName = "发货定价")]
public decimal 发 货 定 价 { set ; get ; }
[ExporterHeader(DisplayName = "金额")]
public decimal 金 额 { set ; get ; }
[ExporterHeader(DisplayName = "发货数量")]
public decimal 发 货 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "发货总金额")]
public decimal 发 货 总 金 额 { set ; get ; }
[ExporterHeader(DisplayName = "结算数量")]
public decimal 结 算 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "退货数量")]
@ -736,6 +923,67 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
}
/// <summary>
/// 红旗主机厂比对红旗未结
/// </summary>
public class HQSettledUnFactoryDetailDiff
{
[ExporterHeader(DisplayName = "收货仓库", IsIgnore = true)]
public string 收 货 仓 库 { set ; get ; }
[ExporterHeader(DisplayName = "收货仓库描述", IsIgnore = true)]
public string 收 货 仓 库 描 述 { set ; get ; }
[ExporterHeader(DisplayName = "订货看板编号")]
public string 订 货 看 板 编 号 { set ; get ; }
[ExporterHeader(DisplayName = "外部单号")]
public string 外 部 单 号 { set ; get ; }
[ExporterHeader(DisplayName = "Sap编码")]
public string Sap编码 { set ; get ; }
[ExporterHeader(DisplayName = "客户物料号")]
public string 客 户 物 料 号 { set ; get ; }
[ExporterHeader(DisplayName = "零件中文名称")]
public string 零 件 中 文 名 称 { set ; get ; }
[ExporterHeader(DisplayName = "物料组")]
public string 物 料 组 { set ; get ; }
[ExporterHeader(DisplayName = "验收单日期", IsIgnore = true)]
public string 验 收 单 日 期 { set ; get ; }
[ExporterHeader(DisplayName = "发货定价", IsIgnore = true)]
public decimal 发 货 定 价 { set ; get ; }
[ExporterHeader(DisplayName = "结算单价")]
public decimal 结 算 单 价 { set ; get ; }
[ExporterHeader(DisplayName = "发货数量",IsIgnore =true)]
public decimal 发 货 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "结算数量")]
public decimal 结 算 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "结算金额")]
public decimal 结 算 金 额 { set ; get ; }
[ExporterHeader(DisplayName = "退货数量",IsIgnore = true)]
public decimal 退 货 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "系统未结数量")]
public decimal 系 统 未 结 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "红旗未结数量")]
public decimal 红 旗 未 结 数 量 { set ; get ; }
[ExporterHeader(DisplayName = "差异")]
public decimal 差 异 { set ; get ; }
}