Administrator 3 years ago
parent
commit
e8f4a43f85
  1. 300
      src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs
  2. 16
      src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs

300
src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs

@ -94,16 +94,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
public class KanbanUnSettledExtend public class KanbanUnSettledExtend
{ {
[ExporterHeader(DisplayName = "客户物料号")]
[ExporterHeader(DisplayName = "客户物料号")]
public string MaterialCode { set; get; } public string MaterialCode { set; get; }
[ExporterHeader(DisplayName = "物料号")] [ExporterHeader(DisplayName = "物料号")]
public string SapCode { set; get; } public string SapCode { set; get; }
@ -130,6 +121,18 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
public class CompareKanban
{
public string WmsBillNum { set; get; }
public string MaterialCode { set; get; }
public string Kanban { set; get; }
public string WmsDate { set; get; }
}
public class KanbanUnSettledDapperRepository : DapperRepository<SettleAccountDbContext>, ITransientDependency public class KanbanUnSettledDapperRepository : DapperRepository<SettleAccountDbContext>, ITransientDependency
@ -139,6 +142,200 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
} }
public virtual List<KanbanUnSettled> GetKanbanReportList(string version, string begintime, string endtime, string iscontionversion) public virtual List<KanbanUnSettled> GetKanbanReportList(string version, string begintime, string endtime, string iscontionversion)
{
string contion = string.Empty;
//选中,是否过滤掉当期结算数据
if (iscontionversion == "0")
{
contion += string.Format(" WHERE Version <'{0}' ", version);
}
else
{
contion += " WHERE 1=1 ";
}
string str = string.Empty;
//str += " where 1=1 ";
if (!string.IsNullOrEmpty(begintime) && Convert.ToDateTime(begintime) != DateTime.MinValue)
{
str += string.Format(" and a.WMSActualGoodsDate >='{0}' ", begintime);
}
if (!string.IsNullOrEmpty(endtime) && Convert.ToDateTime(endtime) != DateTime.MinValue)
{
str += string.Format(" and a.WMSActualGoodsDate<='{0}' ", endtime);
}
string sql = "SELECT\n" +
" * \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" TEMP1.*,\n" +
" TEMP2.Price,\n" +
" ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" +
" FROM\n" +
" (\n" +
" SELECT\n" +
" '' WmsBillNum,\n" +
" CONVERT ( VARCHAR ( 100 ), a.WMSActualGoodsDate, 23 ) BeginDate,\n" +
" a.Kanban,\n" +
" C.MaterialCode SapCode,\n" +
" C.MaterialDesc,\n" +
" C.CustomerPartCode,\n" +
" C.EstimateTypeDesc MaterialGroup,\n" +
" ISNULL( B.Qty, 0 ) SettleQty,\n" +
" ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" +
" isnull( tt.qty, 0 ) BackQty,\n" +
" ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" +
" FROM\n" +
" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban, WMSActualGoodsDate ) A\n" +
" LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban \n" +
" AND A.MaterialCode = B.MaterialCode\n" +
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n" +
" AND a.MaterialCode = b.MaterialCode \n" +
" WHERE\n" +
" B.Kanban IS NULL \n" +
" 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 \n" +
" ) UNION1 UNION ALL\n" +
"SELECT\n" +
" * \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" TEMP1.*,\n" +
" TEMP2.Price,\n" +
" ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" +
" FROM\n" +
" (\n" +
" SELECT\n" +
" '' WmsBillNum,\n" +
" CONVERT ( VARCHAR ( 100 ), a.WMSActualGoodsDate, 23 ) BeginDate,\n" +
" a.Kanban,\n" +
" C.MaterialCode SapCode,\n" +
" C.MaterialDesc,\n" +
" C.CustomerPartCode,\n" +
" C.EstimateTypeDesc MaterialGroup,\n" +
" ISNULL( B.Qty, 0 ) SettleQty,\n" +
" ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" +
" isnull( tt.qty, 0 ) BackQty,\n" +
" ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" +
" FROM\n" +
" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban, WMSActualGoodsDate ) A\n" +
" INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban \n" +
" AND A.MaterialCode = B.MaterialCode\n" +
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n" +
" AND a.MaterialCode = b.MaterialCode \n" +
" WHERE\n" +
" a.WMSDeliveryQty> B.Qty {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 \n" +
" ) UNION2";
sql = string.Format(sql, str, contion,version);
//发运数据中,查出看板号+物料号相同的重复数据
var sql2 = "SELECT\n" +
" a.WMSDeliveryNote WmsBillNum,\n" +
" t1.MaterialCode MaterialCode,\n" +
" a.Kanban ,\n" +
" A.LastModificationTime WmsDate \n" +
"FROM\n" +
" Set_WMSKanBanSettle A\n" +
" INNER JOIN ( SELECT MaterialCode, Kanban FROM Set_WMSKanBanSettle 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";
var listCompare = DbConnection.Query<CompareKanban>(sql2);
//查询发运表中,看权号+物料号没有重复的数据
var sql3 = "SELECT\n" +
" a.WMSDeliveryNote WmsBillNum,\n" +
" t1.MaterialCode MaterialCode,\n" +
" a.Kanban,\n" +
" A.LastModificationTime WmsDate \n" +
"FROM\n" +
" Set_WMSKanBanSettle A\n" +
" LEFT JOIN ( SELECT MaterialCode, Kanban FROM Set_WMSKanBanSettle 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<CompareKanban>(sql3);
//发运数据比较
List<CompareKanban> _ls = new List<CompareKanban>();
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();
}
_ls.Add(itm);
}
var _query = DbConnection.Query<KanbanUnSettled>(sql, null, null, true, 1200, null);
var _list = _query.ToList();
//数据整合,相同看板号+物料号的交货单号合并成一行中以逗号分隔
foreach (var itm1 in _list)
{
var itm = _ls.FirstOrDefault(p => p.Kanban == itm1.WmsBillNum && p.MaterialCode == itm1.SapCode);
if (itm != null)
{
itm1.WmsBillNum = itm.WmsBillNum;
itm1.BeginDate = itm.WmsDate;
}
}
return _list;
}
/// <summary>
/// 原始看板未结数据
/// </summary>
/// <param name="version"></param>
/// <param name="begintime"></param>
/// <param name="endtime"></param>
/// <param name="iscontionversion"></param>
/// <returns></returns>
public virtual List<KanbanUnSettled> GetOriginalKanbanReportList(string version, string begintime, string endtime, string iscontionversion)
{ {
string contion = string.Empty; string contion = string.Empty;
//选中,是否过滤掉当期结算数据 //选中,是否过滤掉当期结算数据
@ -186,7 +383,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
" 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 \n" +
" left join set_backQty as tt on a.Kanban = tt.Code and a.MaterialCode = b.MaterialCode and a.version='"+version+"'\n"+ " left join set_backQty as tt on a.Kanban = tt.Code and a.MaterialCode = b.MaterialCode and a.version='" + version + "'\n" +
" WHERE\n" + " WHERE\n" +
" B.Kanban IS NULL \n" + " B.Kanban IS NULL \n" +
" AND B.MaterialCode IS NULL {0}\n" + " AND B.MaterialCode IS NULL {0}\n" +
@ -200,6 +397,87 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
var _list = _query.ToList(); var _list = _query.ToList();
return _list; return _list;
} }
/// <summary>
/// 有发货有结算,且发货数量大于结算数量的数据,将要整合到未结数据中
/// </summary>
/// <param name="version"></param>
/// <param name="begintime"></param>
/// <param name="endtime"></param>
/// <param name="iscontionversion"></param>
/// <returns></returns>
public virtual List<KanbanUnSettled> GetWMSKanbanReportList(string version, string begintime, string endtime, string iscontionversion)
{
string contion = string.Empty;
//选中,是否过滤掉当期结算数据
if (iscontionversion == "0")
{
contion += string.Format(" WHERE Version <'{0}' ", version);
}
else
{
contion += " WHERE 1=1 ";
}
string str = string.Empty;
//str += " where 1=1 ";
if (!string.IsNullOrEmpty(begintime) && Convert.ToDateTime(begintime) != DateTime.MinValue)
{
str += string.Format(" and a.WMSActualGoodsDate >='{0}' ", begintime);
}
if (!string.IsNullOrEmpty(endtime) && Convert.ToDateTime(endtime) != DateTime.MinValue)
{
str += string.Format(" and a.WMSActualGoodsDate<='{0}' ", endtime);
}
string sql = "SELECT\n" +
" TEMP1.*,\n" +
" TEMP2.Price,\n" +
" ROUND( TEMP2.Price * TEMP1.DiffQty, 2 ) AS DiffAMT \n" +
"FROM\n" +
" (\n" +
" SELECT\n" +
" a.WMSDeliveryNote WmsBillNum,\n" +
" CONVERT ( VARCHAR ( 100 ), a.WMSActualGoodsDate, 23 ) BeginDate,\n" +
" a.Kanban,\n" +
" C.MaterialCode SapCode,\n" +
" C.MaterialDesc,\n" +
" C.CustomerPartCode,\n" +
" C.EstimateTypeDesc MaterialGroup,\n" +
" ISNULL( B.Qty, 0 ) SettleQty,\n" +
" ISNULL( a.WMSDeliveryQty, 0 ) WMSDeliveryQty,\n" +
" isnull( tt.qty, 0 ) BackQty,\n" +
" ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" +
" FROM\n" +
" ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, WMSDeliveryNote, Kanban, WMSActualGoodsDate FROM Set_WMSKanBanSettle GROUP BY MaterialCode, WMSDeliveryNote, Kanban, WMSActualGoodsDate ) A\n" +
" INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {1} GROUP BY Kanban, MaterialCode ) B ON A.Kanban = B.Kanban\n" +
" AND A.MaterialCode = B.MaterialCode\n" +
" LEFT JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode\n" +
" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{2}' ) AS tt ON a.Kanban = tt.Code \n" +
" AND a.MaterialCode = b.MaterialCode \n" +
" WHERE\n" +
" a.WMSDeliveryQty> B.Qty {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";
sql = string.Format(sql, str, contion,version);
var _query = DbConnection.Query<KanbanUnSettled>(sql, null, null, true, 1200, null);
var _list = _query.ToList();
return _list;
}
public virtual List<KanbanUnSettledExtend> GetNoKanbanReportList(string version, string begintime, string endtime) public virtual List<KanbanUnSettledExtend> GetNoKanbanReportList(string version, string begintime, string endtime)
{ {
var sql = "SELECT\n" + var sql = "SELECT\n" +

16
src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/KanBanUnSettledExport.cs

@ -45,7 +45,14 @@ namespace SettleAccount.Job.Services.Report
var iscontionversion = p_list.Where(p => p.Name == "IsContainVersion").FirstOrDefault().Value; var iscontionversion = p_list.Where(p => p.Name == "IsContainVersion").FirstOrDefault().Value;
var _ls = _dapper.GetKanbanReportList(version, begin,end, iscontionversion); var _ls = _dapper.GetKanbanReportList(version, begin, end, iscontionversion);
//有发货有结算,且发货数量大于结算
var _ls_wmskanban = _dapper.GetWMSKanbanReportList(version, begin, end, iscontionversion);
//原始看板未对比数据
var _ls_orgiinal_kanban = _dapper.GetOriginalKanbanReportList(version, begin, end, iscontionversion);
// var _lst = _dapper.GetNoKanbanReportList(version, begin, end); // var _lst = _dapper.GetNoKanbanReportList(version, begin, end);
//if (!string.IsNullOrEmpty(materialGroup)) //if (!string.IsNullOrEmpty(materialGroup))
//{ //{
@ -96,8 +103,11 @@ namespace SettleAccount.Job.Services.Report
//} //}
ExcelExporter _exporter = new ExcelExporter();//导出Excel ExcelExporter _exporter = new ExcelExporter();//导出Excel
var result = _exporter.Append(_ls.ToList(), "有发货无结算差异对比") var result = _exporter.Append(_ls.ToList(), "有发货无结算差异原始对比")
.SeparateBySheet()
.Append(_ls_orgiinal_kanban.ToList(), "原始看板未结对比数据")
.SeparateBySheet()
.Append(_ls_wmskanban.ToList(), "有发货有结算(发货数量大于结算)")
.ExportAppendDataAsByteArray(); .ExportAppendDataAsByteArray();
result.ShouldNotBeNull(); result.ShouldNotBeNull();
_fileContainer.SaveAsync(_filename, result.Result, true); _fileContainer.SaveAsync(_filename, result.Result, true);

Loading…
Cancel
Save