@ -43,51 +43,65 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
condition + = string . Format ( " and c.WMSActualGoodsDate<='{0}' " , endtime ) ;
condition + = string . Format ( " and c.WMSActualGoodsDate<='{0}' " , endtime ) ;
}
}
var datestr = version . Substring ( 0 , 4 ) + "-" + version . Substring ( 4 , 2 ) + "-01" ;
var date = DateTime . Parse ( datestr ) . AddMonths ( 1 ) . AddDays ( - 1 ) ;
var datetime = date . ToShortDateString ( ) + " 23:59:59 " ;
string sqlString = "SELECT\n" +
string sqlString = "SELECT\n" +
" * ,\n" +
" * ,\n" +
" ISNULL( temp1.InvoicePrice * Qty, 0 ) AS InvoiceMoney,--开票金额\n" +
" ISNULL ( temp1.InvoicePrice * 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" +
" ISNULL( Price * Qty - InvoicePrice * Qty, 0 ) AS SumDiffMoney,--总金额差异\n" +
" ISNULL ( Price * Qty - InvoicePrice * Qty, 0 ) AS SumDiffMoney,--总金额差异\n" +
" '' DeliveryOrderNo --出库单号\n" +
" '' DeliveryOrderNo --出库单号\n" +
" \n" +
" \n" +
"FROM\n" +
"FROM\n" +
" (\n" +
" (\n" +
" SELECT\n" +
" SELECT ROW_NUMBER\n" +
" row_number ( ) OVER ( ORDER BY b.EstimateTypeDesc ) AS RowId,\n" +
" ( ) OVER ( ORDER BY b.EstimateTypeDesc ) AS RowId,\n" +
" c.WMSDeliveryNote,--交货单号\n" +
"--c.WMSDeliveryNote,--交货单号\n" +
" CONVERT ( VARCHAR ( 100 ), c.WMSActualGoodsDate, 23 ) AS WMSActualGoodsDate,--实际发货日期年-月-日\n" +
"--CONVERT ( VARCHAR ( 100 ), c.WMSActualGoodsDate, 23 ) AS WMSActualGoodsDate,--实际发货日期年-月-日\n" +
" a.Kanban,--条码号\n" +
" A.Kanban,--条码号\n" +
" b.MaterialCode SapMaterialCode,--厂内物料号\n" +
" b.MaterialCode SapMaterialCode,--厂内物料号\n" +
" b.MaterialDesc,--物料描述\n" +
" b.MaterialDesc,--物料描述\n" +
" b.CustomerPartCode,--客户物料\n" +
" b.CustomerPartCode,--客户物料\n" +
" b.EstimateTypeDesc,--物料组(车型)\n" +
" b.EstimateTypeDesc,--物料组(车型)\n" +
" c.WMSDeliveryQty,--交货数量\n" +
" C.WMSDeliveryQty,--交货数量\n" +
" ISNULL( a.Qty, 0 ) AS SettleNumber,--结算数量\n" +
" ISNULL ( A.Qty, 0 ) AS SettleNumber,--结算数量\n" +
" CONVERT ( VARCHAR ( 100 ), a.SettleDate, 23 ) SettleDate,--结算日期\n" +
" CONVERT ( VARCHAR ( 100 ), A.SettleDate, 23 ) SettleDate,--结算日期\n" +
" ISNULL( a.Qty, 0 ) AS Qty,--用于计算\n" +
" ISNULL ( A.Qty, 0 ) AS Qty,--用于计算\n" +
" ( ISNULL( a.Qty, 0 ) - ISNULL( c.WMSDeliveryQty, 0 ) ) AS SettleWMSDiffQty,--结算与发货差异\n" +
" ( ISNULL ( A.Qty, 0 ) - ISNULL ( C.WMSDeliveryQty, 0 ) ) AS SettleWMSDiffQty,--结算与发货差异\n" +
" 0 AS SettleInvoiceDiffQty,--结算与开票差异\n" +
" 0 AS SettleInvoiceDiffQty,--结算与开票差异\n" +
" ISNULL( a.Qty, 0 ) AS InvoiceDiffQty,--开票数量,默认0,后续拿算法动态算\n" +
" ISNULL ( A.Qty, 0 ) AS InvoiceDiffQty,--开票数量,默认0,后续拿算法动态算\n" +
" ISNULL( d.InvoicePrice, 0 ) InvoicePrice --开票单价\n" +
" ISNULL ( d.InvoicePrice, 0 ) InvoicePrice --开票单价\n" +
" \n" +
" \n" +
" FROM\n" +
" FROM\n" +
" Set_KanBanSettle AS a\n" +
" Set_KanBanSettle\n" +
" LEFT JOIN Set_material AS b ON a.MaterialCode= b.CustomerPartCode\n" +
" AS A 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 (\n" +
" AND a.MaterialCode= c.MaterialCode\n" +
" SELECT\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" +
" ( temp1.Qty - ISNULL ( temp2.Qty, 0 ) ) WMSDeliveryQty,\n" +
" WHERE\n" +
" temp1.MaterialCode,\n" +
" a.VERSION= '{0}' {1} \n" +
" temp1.Kanban \n" +
" ) TEMP1\n" +
" FROM\n" +
" LEFT JOIN ( SELECT Price, --定价\n" +
" ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle WHERE VERSION < '{0}' GROUP BY kanban, MaterialCode ) temp1\n" +
" MaterialCode --厂内物料号\n" +
" INNER JOIN ( SELECT SUM ( WMSDeliveryQty ) Qty, KanBan, MaterialCode FROM Set_WMSKanBanSettle WHERE WMSActualGoodsDate < '{2}' GROUP BY KanBan, MaterialCode ) temp2 ON temp1.Kanban = temp2.KanBan \n" +
" FROM Set_PriceList WHERE version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) TEMP2 ON TEMP1.SapMaterialCode= TEMP2.MaterialCode \n" +
" AND temp1.MaterialCode = temp2.KanBan \n" +
"WHERE\n" +
" ) C ON A.Kanban = C.Kanban \n" +
" 1 =1" ;
" 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" +
" WHERE\n" +
" A.VERSION = '{0}' {1}\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\n" +
" 1 = 1;" ;
string addwhere = string . Empty ;
string addwhere = string . Empty ;
string addSqlStr = string . Format ( sqlString , version , condition ) ;
string addSqlStr = string . Format ( sqlString , version , condition , datetime ) ;
//if (!string.IsNullOrEmpty(kanBan))
//if (!string.IsNullOrEmpty(kanBan))
//{
//{
@ -106,9 +120,86 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
// addwhere += string.Format(" AND EstimateTypeDesc LIKE '{0}%' ", estimateTypeDesc);
// addwhere += string.Format(" AND EstimateTypeDesc LIKE '{0}%' ", estimateTypeDesc);
//}
//}
string _ sql = string . Format ( addSqlStr , addwhere ) ;
string _ sql = string . Format ( addSqlStr , addwhere ) ;
var _ query = DbConnection . Query < SettleKBWithCode > ( _ sql , null , null , true , 1 2 0 0 , null ) ;
var _ query = DbConnection . Query < SettleKBWithCode > ( _ sql , null , null , true , 1 2 0 0 , null ) ;
return _ query . ToList ( ) ;
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 < CompareExtend > ( sql2 ) ;
var _l st = _ query . ToList ( ) ;
List < CompareExtend > _l s = new List < CompareExtend > ( ) ;
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 ) ;
}
}
foreach ( var itm1 in _l st )
{
var itm = _l s . FirstOrDefault ( p = > p . Kanban = = itm1 . Kanban & & p . MaterialCode = = itm1 . MaterialCode ) ;
if ( itm ! = null )
{
itm1 . WMSDeliveryNote = itm . WmsBillNum ;
itm1 . WMSActualGoodsDate = itm . WmsDate ;
}
}
return _l st ;
}
}