diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/TaskListDto.cs b/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/TaskListDto.cs index 0f8b954b..8410800e 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/TaskListDto.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application.Contracts/Entities/TaskListDto.cs @@ -1,6 +1,7 @@ using Magicodes.ExporterAndImporter.Core; using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -22,9 +23,9 @@ namespace Win.Sfs.SettleAccount.Entities [ExporterHeader(DisplayName = "入库库位")] //入库库位 public string InPut { set; get; } - [ImporterHeader(Name = "状态")] - [ExporterHeader(DisplayName = "状态")] - public int State { get; set; } + //[ImporterHeader(Name = "状态")] + //[ExporterHeader(DisplayName = "状态")] + //public int State { get; set; } [ImporterHeader(Name = "开票单价")] [ExporterHeader(DisplayName = "开票单价")] @@ -79,6 +80,15 @@ namespace Win.Sfs.SettleAccount.Entities [ImporterHeader(Name = "结算数量")] public decimal Qty { set; get; } + [ExporterHeader(DisplayName = "状态")] + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } + } @@ -120,9 +130,16 @@ namespace Win.Sfs.SettleAccount.Entities [ImporterHeader(Name = "入库库位", IsIgnore = true)] //入库库位 public string InPut { set; get; } + [ExporterHeader(DisplayName = "状态")] - [ImporterHeader(Name = "状态", IsIgnore = true)] - public int State { get; set; } + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } + [ExporterHeader(DisplayName = "客户物料")] [ImporterHeader(Name = "客户物料")] /// @@ -201,9 +218,15 @@ namespace Win.Sfs.SettleAccount.Entities [ImporterHeader(Name = "BillNum", IsIgnore = true)] [ExporterHeader(DisplayName = "BillNum", IsIgnore = true)] public string BillNum { set; get; } - [ImporterHeader(Name = "状态", IsIgnore = true)] + [ExporterHeader(DisplayName = "状态")] - public int State { set; get; } + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } [ImporterHeader(Name = "开票单价")] [ExporterHeader(DisplayName = "开票单价")] @@ -243,8 +266,16 @@ namespace Win.Sfs.SettleAccount.Entities [ExporterHeader(DisplayName = "入库库位", IsIgnore = true)] //入库库位 public string InPut { set; get; } - [ExporterHeader(DisplayName = "状态", IsIgnore = true)] - public int State { get; set; } + + [ExporterHeader(DisplayName = "状态")] + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } + [ExporterHeader(DisplayName = "物料代码")] /// /// 扩展字段1 @@ -329,9 +360,16 @@ namespace Win.Sfs.SettleAccount.Entities [ExporterHeader(DisplayName = "入库库位", IsIgnore = true)] //入库库位 public string InPut { set; get; } - [ImporterHeader(Name = "状态", IsIgnore = true)] - [ExporterHeader(DisplayName = "状态", IsIgnore = true)] - public int State { get; set; } + + [ExporterHeader(DisplayName = "状态")] + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } + [ImporterHeader(Name = "物料代码")] [ExporterHeader(DisplayName = "物料代码")] /// @@ -414,9 +452,16 @@ namespace Win.Sfs.SettleAccount.Entities [ImporterHeader(Name = "BillNum", IsIgnore = true)] [ExporterHeader(DisplayName = "BillNum", IsIgnore = true)] public string BillNum { set; get; } - [ImporterHeader(Name = "状态", IsIgnore = true)] - [ExporterHeader(DisplayName = "状态", IsIgnore = true)] - public int State { set; get; } + + [ExporterHeader(DisplayName = "状态")] + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } + [ImporterHeader(Name = "开票单价")] [ExporterHeader(DisplayName = "开票单价")] @@ -424,7 +469,6 @@ namespace Win.Sfs.SettleAccount.Entities [ImporterHeader(Name = "开票金额")] [ExporterHeader(DisplayName = "开票金额")] public decimal Amt { set; get; } - } @@ -468,9 +512,16 @@ namespace Win.Sfs.SettleAccount.Entities [ImporterHeader(Name = "BillNum", IsIgnore = true)] [ExporterHeader(DisplayName = "BillNum", IsIgnore = true)] public string BillNum { set; get; } - [ImporterHeader(Name = "状态", IsIgnore = true)] - [ExporterHeader(DisplayName = "状态", IsIgnore = true)] - public int State { set; get; } + + + [ExporterHeader(DisplayName = "状态")] + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } [ImporterHeader(Name = "开票单价")] [ExporterHeader(DisplayName = "开票单价")] @@ -529,9 +580,16 @@ namespace Win.Sfs.SettleAccount.Entities [ExporterHeader(DisplayName = "入库库位", IsIgnore = true)] //入库库位 public string InPut { set; get; } - [ImporterHeader(Name = "状态", IsIgnore = true)] - [ExporterHeader(DisplayName = "状态", IsIgnore = true)] - public int State { get; set; } + + [ExporterHeader(DisplayName = "状态")] + [ValueMapping("未处理", 0)] + [ValueMapping("申请出库", 1)] + [ValueMapping("确认出库", 2)] + [ValueMapping("不能出库", 3)] + [ValueMapping("取消出库", 4)] + + public ExporterStatus State { set; get; } + [ImporterHeader(Name = "结算物料号")] [ExporterHeader(DisplayName = "结算物料号")] /// @@ -573,6 +631,43 @@ namespace Win.Sfs.SettleAccount.Entities } + /// + /// 学生状态 正常、流失、休学、勤工俭学、顶岗实习、毕业、参军 + /// + public enum ExporterStatus + { + /// + /// 未处理 + /// + [Display(Name = "未处理")] + Normal = 0, + + /// + /// 申请出库 + /// + [Display(Name = "申请出库")] + PupilsAway = 1, + + /// + /// 确认出库 + /// + [Display(Name = "确认出库")] + Suspension = 2, + + /// + /// 不能出库 + /// + [Display(Name = "不能出库")] + WorkStudy = 3, + + /// + /// 取消出库 + /// + [Display(Name = "取消出库")] + PostPractice = 4, + + } + } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/VWSparePart/SparePartAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/VWSparePart/SparePartAppService.cs index 866e580b..aa3dc008 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/VWSparePart/SparePartAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/VWSparePart/SparePartAppService.cs @@ -63,7 +63,7 @@ namespace Win.Sfs.SettleAccount.Entities.VWSparePart /// - /// 导入功能 + /// 大众备件明细数据导入功能(以后正常使用的功能),包含导入有空的订单号 /// /// 上传的文件(前端已经限制只能上传一个附件) /// @@ -101,7 +101,17 @@ namespace Win.Sfs.SettleAccount.Entities.VWSparePart _bomList.Add(new SparePartVersion(_id, branchId, year, period, version, customerCode)); foreach (var itm in entityList) { - itm.SetValue(GuidGenerator.Create(), branchId, year, period, version, "not90"); + if (string.IsNullOrEmpty(itm.PurchaseOrderNo)) + { + //订单号不空 + itm.SetValue(GuidGenerator.Create(), branchId, year, period, version, "not90", "NoOrder"); + } + else + { + //赋值上主键ID + itm.SetValue(GuidGenerator.Create(), branchId, year, period, version, "not90"); + } + } if (checkList.Count > 0) { @@ -112,6 +122,16 @@ namespace Win.Sfs.SettleAccount.Entities.VWSparePart return ApplicationConsts.SuccessStr; } + /// + /// 大众备件调整导入(财务期初时用的功能),订单号+物料号能一对一匹配 + /// + /// + /// + /// + /// + /// + /// + /// [HttpPost] [Route("ExcelImport90")] [DisableRequestSizeLimit] diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePartAppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePartAppService.cs index 16e455b6..d85b82da 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePartAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePartAppService.cs @@ -245,8 +245,8 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts if (_joblist.Count() > 0) { var fileList = _joblist.Select(p => p.RealDownFileName).ToList(); - List _lst = new List(); - List _lstBill = new List(); + List _lst = new List();//无订单 + List _lstBill = new List();//有订单 foreach (var filename in fileList) { string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename; @@ -256,9 +256,9 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts var _list90Summary = _excelHelper.ExcelToListOne();//有单号 - var _list = _listSummary.Where(p => p.OrderBillNum == "").ToList();//过滤 没有采购订单号为空的集合 - var _listBill = _list90Summary.Where(p => p.OrderBillNum != "").ToList();//过滤 有采购订单号的集合 - + //NoOrder用来标识采购订单号为空的数据 + var _list = _listSummary.Where(p => p.OrderBillNum == "NoOrder").ToList();//没有采购订单号的集合 + var _listBill = _list90Summary.Where(p => !string.IsNullOrEmpty(p.OrderBillNum) && p.OrderBillNum != "NoOrder").ToList();//有采购订单号的集合 //var _list = _excelHelper.ExcelToList(); @@ -328,7 +328,7 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts if (_lst != null && _lst.Count>0) { //没有采购订单号 - var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version && p.OrderBillNum == "").ToListAsync(); + var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version && string.IsNullOrEmpty(p.OrderBillNum)).ToListAsync(); var error = from itm1 in outPutDetail join itm2 in _lst on @@ -412,7 +412,7 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts if (_lstBill != null && _lstBill.Count>0) { //有采购订单号 - var outPutDetailBill = await _wmsRepository90.Where(p => p.Version == input.Version && p.OrderBillNum != "").ToListAsync(); + var outPutDetailBill = await _wmsRepository90.Where(p => p.Version == input.Version && !string.IsNullOrEmpty(p.OrderBillNum)).ToListAsync(); var error = from itm1 in outPutDetailBill join itm2 in _lstBill on @@ -631,7 +631,12 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts return true; } - + /// + /// 出库单导入功能 + /// + /// + /// + /// [HttpPost] [Route("ExcelImport")] [DisableRequestSizeLimit] @@ -666,8 +671,8 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts var result90 = await _exportImporter.ExtendExcelOfSheetOneImport(files, _excelImportService); - var result_nobill = result.Where(p => p.OrderBillNum == "").ToList(); - var result_withbill = result90.Where(p => p.OrderBillNum != "").ToList(); + var result_nobill = result.Where(p =>string.IsNullOrEmpty(p.OrderBillNum)).ToList();//没有采购单号集合 + var result_withbill = result90.Where(p =>!string.IsNullOrEmpty(p.OrderBillNum)).ToList();//有采购单号集合 //没有采购单号 @@ -677,7 +682,8 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts List _lst = new List(); var _lsCopy = new List(); - foreach (var itm in result_nobill) + var result_nobill_filter = result_nobill.Where(p => string.IsNullOrEmpty(p.OrderBillNum) && !string.IsNullOrEmpty(p.MaterialCode)); + foreach (var itm in result_nobill_filter) { WmsSharePartOutPutDetial _detail = new WmsSharePartOutPutDetial( GuidGenerator.Create(), @@ -772,7 +778,7 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts List _lst = new List(); var _lsCopy = new List(); - var filte_result_withbill = result_withbill.Where(p => p.OrderBillNum != "");//采购单号为空的过滤掉 + var filte_result_withbill = result_withbill.Where(p =>!string.IsNullOrEmpty(p.OrderBillNum));//采购单号为空的过滤掉 foreach (var itm in filte_result_withbill) { WmsSharePart90OutPutDetial _detail = new WmsSharePart90OutPutDetial( diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs index 5698ca71..cbe620ce 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs @@ -176,7 +176,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices #region 大众备件0-90天和90天以上输出 /// - /// 大众备件0-90天报表输出 + /// 大众备件数据调整结算输出 /// /// /// @@ -215,7 +215,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices } /// - /// 大众备件结算核对明细表 + /// 大众备件输出(包括带订货单号和无订单号) /// /// 采购订单号 /// 厂内物料号 diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/VWSparePart/SparePart.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/VWSparePart/SparePart.cs index 1a9aa5a2..cae54b14 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/VWSparePart/SparePart.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/VWSparePart/SparePart.cs @@ -25,6 +25,17 @@ namespace Win.Sfs.SettleAccount.Entities.VWSparePart BranchId = branchId; Extend = extend; } + + public void SetValue(Guid guid, Guid branchId, string year, string peroid, string version, string extend,string purchaseOrderNo) + { + Period = peroid; + Year = year; + Id = guid; + Version = version; + BranchId = branchId; + Extend = extend; + PurchaseOrderNo = purchaseOrderNo; + } public SparePart(Guid Id, string year, string period, string version, string lineNumber, string purchaseType,string purchaseOrderNo, string purchaseOrderNoItem, string purchaseOrderNoText, decimal receiptQty, decimal invoicedQty, decimal amountNoTax, decimal purchasePriceNoTax, diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQFactorySettledDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQFactorySettledDetailDapperRepository.cs index f2d90bd9..48ba2225 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQFactorySettledDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQFactorySettledDetailDapperRepository.cs @@ -179,7 +179,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " AND temp1.订货看板编号 = tt.Code \n" + " ) UNION2 \n" + " ) AS temp1 ON unhq.HQHKanBan = temp1.[订货看板编号] \n" + - " AND unhq.CustomerPartCode= 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"; @@ -492,7 +492,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// - /// 红旗系统未对比对红旗主机厂未结 + /// 红旗系统未对比对红旗主机厂未结,其中红旗系统未结数据中还包括有发货有结算中发货数量大于结算的也要整合到未结当中 /// /// /// diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs index 15b0c1fe..a6ebf6dc 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/HQHSettledDetailDapperRepository.cs @@ -57,8 +57,6 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report List _list = new List(); - - //string condition = " "; //if (!string.IsNullOrEmpty(begin)) @@ -70,7 +68,6 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report // condition += string.Format(" and b.LastModificationTime<='{0}' ", end); //} - string str = "SELECT\n" + " isnull( temp1.交货单号, '' ) 交货单号,\n" + diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs index d222bf10..4d051815 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/KanbanUnSettledDapperRepository.cs @@ -189,10 +189,10 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + " FROM\n" + " ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban ) 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" + + " LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {0} 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 = '{0}' ) AS tt ON a.Kanban = tt.Code \n" + + " LEFT JOIN ( SELECT * FROM set_backQty ) AS tt ON a.Kanban = tt.Code \n" + " AND a.MaterialCode = tt.MaterialCode \n" + " WHERE\n" + " B.Kanban IS NULL \n" + @@ -224,10 +224,10 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " ( ISNULL( a.WMSDeliveryQty, 0 ) - ISNULL( b.Qty, 0 ) - isnull( tt.qty, 0 ) ) AS DiffQty \n" + " FROM\n" + " ( SELECT SUM ( WMSDeliveryQty ) WMSDeliveryQty, MaterialCode, Kanban FROM Set_WMSKanBanSettle GROUP BY MaterialCode, Kanban ) 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" + + " INNER JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle {0} 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 = '{0}' ) AS tt ON a.Kanban = tt.Code \n" + + " LEFT JOIN ( SELECT * FROM set_backQty ) AS tt ON a.Kanban = tt.Code \n" + " AND a.MaterialCode = tt.MaterialCode \n" + " WHERE\n" + " a.WMSDeliveryQty> B.Qty \n" + @@ -237,7 +237,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report - sql = string.Format(sql, version, contion); + sql = string.Format(sql,contion); //发运数据中,查出看板号+物料号相同的重复数据 @@ -385,7 +385,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " AND A.MaterialCode = B.MaterialCode\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 \n" + " WHERE\n" + " B.Kanban IS NULL \n" + " AND B.MaterialCode IS NULL {0}\n" + @@ -456,7 +456,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " 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" + + " LEFT JOIN ( SELECT * FROM set_backQty ) AS tt ON a.Kanban = tt.Code \n" + " AND a.MaterialCode = b.MaterialCode \n" + " WHERE\n" + " a.WMSDeliveryQty> B.Qty {0}\n" + @@ -465,7 +465,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report - sql = string.Format(sql, str, contion,version); + sql = string.Format(sql, str, contion); var _query = DbConnection.Query(sql, null, null, true, 1200, null); var _list = _query.ToList(); return _list; diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleKBWithCodeDapperReportRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleKBWithCodeDapperReportRepository.cs index 389963bc..d93fcf81 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleKBWithCodeDapperReportRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleKBWithCodeDapperReportRepository.cs @@ -87,7 +87,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " (\n" + " ( SELECT SUM ( WMSDeliveryQty ) Qty, KanBan, MaterialCode FROM Set_WMSKanBanSettle GROUP BY KanBan, MaterialCode ) temp1\n" + " LEFT JOIN ( SELECT SUM ( Qty ) Qty, Kanban, MaterialCode FROM Set_KanBanSettle WHERE VERSION < '{0}' GROUP BY kanban, MaterialCode ) temp2 ON temp1.Kanban = temp2.KanBan \n" + - " AND temp1.MaterialCode = temp2.KanBan \n" + + " AND temp1.MaterialCode = temp2.MaterialCode \n" + " ) \n" + " ) C ON A.Kanban = C.Kanban \n" + " AND A.MaterialCode = C.MaterialCode\n" + diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePart90DapperReportRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePart90DapperReportRepository.cs index 91a844ef..d204ec62 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePart90DapperReportRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePart90DapperReportRepository.cs @@ -12,7 +12,7 @@ using Volo.Abp.EntityFrameworkCore; namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { /// - /// 根据虚拟单号0-90天的是按照SAP物料号进行先进先出操作 + /// 大众备件明细输出, /// public class SettleSparePart90DapperReportRepository : DapperRepository, ITransientDependency { @@ -21,7 +21,113 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { } + /// + /// 大众备件数据调整:期初没有WMS发运数据,调整的数据就是给WMS一份,给结算一份 + /// + /// + /// + /// + /// + /// + /// + /// public virtual List GetSettleSparePart90ReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + string begintime, string endtime) + { + string sqlString = "SELECT\n" + + " temp1.交货日期,\n" + + " temp1.交货单号,\n" + + " '' 订单日期,\n" + + " temp1.采购订单号,\n" + + " temp1.SAP编码,\n" + + " temp1.物料代码,\n" + + " temp1.物料描述,\n" + + " temp1.采购订单文本,\n" + + " temp1.发货数量,\n" + + " temp1.开票数量,\n" + + " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + " temp1.开票单价,\n" + + " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " a.Version AS 期间,\n" + + " a.PurchaseOrderNoText AS 采购订单文本,\n" + + " b.WMSDeliveryNote AS 交货单号,\n" + + " b.SpareDate AS 交货日期,\n" + + " a.PurchaseOrderNo AS 采购订单号,\n" + + " c.MaterialCode AS SAP编码,\n" + + " b.MaterialCode AS 物料代码,\n" + + " c.MaterialDesc AS 物料描述,\n" + + " c.EstimateTypeDesc AS 物料组,\n" + + " a.PurchasePriceNoTax AS 开票单价,\n" + + " 0 AS 数量差异,\n" + + " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + + " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + " ISNULL( a.AmountNoTax, 0 ) AS 开票金额 \n" + + " FROM\n" + + " (\n" + + " SELECT SUM\n" + + " ( ReceiptQty ) AS ReceiptQty,\n" + + " PurchaseOrderNo,\n" + + " MaterialCode,\n" + + " Version,\n" + + " PurchasePriceNoTax,\n" + + " InvoicedQty,\n" + + " PurchaseOrderNoText,\n" + + " AmountNoTax \n" + + " FROM\n" + + " Set_SparePart where Extend='is90' \n" + + " GROUP BY\n" + + " PurchaseOrderNo,\n" + + " MaterialCode,\n" + + " Version,\n" + + " PurchasePriceNoTax,\n" + + " InvoicedQty,\n" + + " PurchaseOrderNoText,\n" + + " AmountNoTax \n" + + " ) AS a\n" + + " INNER JOIN (\n" + + " SELECT SUM\n" + + " ( ReceiptQty ) AS ReceiptQty,\n" + + " PurchaseOrderNo,\n" + + " SapCode,\n" + + " MaterialCode,\n" + + " WMSDeliveryNote,\n" + + " SpareDate \n" + + " FROM\n" + + " Set_WMSSparePart \n" + + " GROUP BY\n" + + " PurchaseOrderNo,\n" + + " SapCode,\n" + + " MaterialCode,\n" + + " WMSDeliveryNote,\n" + + " SpareDate \n" + + " ) AS b ON a.PurchaseOrderNo = b.PurchaseOrderNo \n" + + " AND a.MaterialCode = b.MaterialCode\n" + + " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + " WHERE\n" + + " ( a.Version = '{0}' ) \n" + + " ) AS temp1\n" + + " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + + "ORDER BY\n" + + " temp1.采购订单号"; + + string addwhere = string.Empty; + string addSqlStr = string.Format(sqlString, version); + + string _sql = string.Format(addSqlStr, addwhere); + //string _sql = string.Format(sqlString, version); + var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + return _query.ToList(); + + } + + + public virtual List GetSettleSparePart90ReportList_old(string purchaseOrderNo, string version, string sapCode, string matialCode, string begintime, string endtime) { string sqlString = "SELECT\n" + @@ -70,7 +176,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " PurchaseOrderNoText,\n" + " AmountNoTax \n" + " FROM\n" + - " Set_SparePart \n" + + " Set_SparePart where Extend='is90' \n" + " GROUP BY\n" + " PurchaseOrderNo,\n" + " MaterialCode,\n" + @@ -116,7 +222,16 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } - + /// + /// 大众备件未结明细 + /// + /// + /// + /// + /// + /// + /// + /// public virtual List GetUnSettleSparePart90ReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, string begintime, string endtime) { @@ -156,7 +271,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " ISNULL( b.AmountNoTax, 0 ) AS 开票金额 \n" + " FROM\n" + " Set_WMSSparePart a\n" + - " LEFT JOIN ( SELECT PurchaseOrderNo, Version, PurchaseOrderNoText, PurchasePriceNoTax, InvoicedQty, AmountNoTax FROM Set_SparePart WHERE Version = '{0}' ) b ON a.PurchaseOrderNo = b.PurchaseOrderNo\n" + + " LEFT JOIN ( SELECT PurchaseOrderNo, Version, PurchaseOrderNoText, PurchasePriceNoTax, InvoicedQty, AmountNoTax FROM Set_SparePart WHERE Version = '{0}' and Extend='is90' ) b ON a.PurchaseOrderNo = b.PurchaseOrderNo\n" + " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + " WHERE\n" + " b.PurchaseOrderNo IS NULL \n" + @@ -183,7 +298,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report // " a.PurchaseOrderNo 订单号,\n" + // " a.MaterialCode 物料号 \n" + // "FROM\n" + - // " ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Version = '{0}' GROUP BY PurchaseOrderNo, MaterialCode ) A\n" + + // " ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Version = '{0}' and Extend='is90' GROUP BY PurchaseOrderNo, MaterialCode ) A\n" + // " LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) B ON A.MaterialCode = B.MaterialCode \n" + // " AND A.PurchaseOrderNo = B.PurchaseOrderNo \n" + // "WHERE\n" + diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs index 5ff95b24..925afacc 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleSparePartDapperReportRepository.cs @@ -18,12 +18,10 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report : base(dbContextProvider) { } - //public async Task SettledSparePart(string purchaseOrderNo, string sapCode, string version, string customerCode, string factory, string matialCode, - //string state, DateTime begin, DateTime end) - + /// - /// 带采购订单号和无订单号一起统计报表 WHERE Extend != 'is90' + /// 带采购订单号和无订单号一起统计报表 WHERE Extend != 'is90' 去掉 备件调整数据 /// /// /// @@ -35,166 +33,325 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report public virtual List GetSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, string begintime, string endtime) { + + //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" + + //" temp1.开票数量,\n" + + //" ISNULL( temp1.收货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 收货与开票差异,\n" + + //" temp1.开票单价,\n" + + //" ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + //" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + //" temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + //" ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额,\n" + + //" temp1.交货数量,\n" + + //" temp1.收货与交货差异,\n" + + //" ISNULL( temp1.交货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + //" ISNULL( temp3.Qty, 0 ) 退货数量 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" a.Version AS 期间,\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.PurchasePriceNoTax, 0 ) AS 开票单价,\n" + + //" ISNULL( a.ReceiptQty, 0 ) AS 收货数量,\n" + + //" ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + //" ISNULL( a.InvoicedQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额,\n" + + //" ISNULL( C.WMSDeliveryQty, 0 ) AS 交货数量,\n" + + //" ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( C.WMSDeliveryQty, 0 ) ) AS 收货与交货差异 \n" + + //" FROM\n" + + //" ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND PurchaseOrderNo!='NoOrder' ) 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 ) - 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 ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' AND PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) 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" + + //" WHERE\n" + + //" ( a.Version = '{0}' ) \n" + + //" ) AS temp1\n" + + //" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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" + + //" ) union1 UNION ALL\n" + + //"SELECT\n" + + //" union2.* \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" temp1.交货日期,\n" + + //" '' 交货单号,\n" + + //" '' 订单日期,\n" + + //" '' 采购订单号,\n" + + //" temp1.SAP编码,\n" + + //" temp1.物料代码,\n" + + //" temp1.物料描述,\n" + + //" '' 采购订单文本,\n" + + //" temp1.收货数量,\n" + + //" temp1.开票数量,\n" + + //" ISNULL( temp1.收货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + //" temp1.开票单价,\n" + + //" ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + //" ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + //" temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + //" ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额,\n" + + //" 0 交货数量,\n" + + //" 0 收货与交货差异,\n" + + //" 0 实际交货数量,\n" + + //" 0 退货数量 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" NULL AS 交货日期,\n" + + //" c.MaterialCode AS SAP编码,\n" + + //" a.MaterialCode AS 物料代码,\n" + + //" c.MaterialDesc AS 物料描述,\n" + + //" c.EstimateTypeDesc AS 物料组,\n" + + //" ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票单价,\n" + + //" ISNULL( a.ReceiptQty, 0 ) AS 收货数量,\n" + + //" ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + //" ISNULL( a.ReceiptQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT SUM\n" + + //" ( ReceiptQty ) AS ReceiptQty,\n" + + //" SUM ( InvoicedQty ) InvoicedQty,\n" + + //" MaterialCode,\n" + + //" PurchasePriceNoTax \n" + + //" FROM\n" + + //" Set_SparePart \n" + + //" WHERE\n" + + //" Extend != 'is90' \n" + + //" AND Version = '{0}' \n" + + //" AND PurchaseOrderNo='NoOrder' \n" + + //" GROUP BY\n" + + //" MaterialCode,\n" + + //" PurchasePriceNoTax \n" + + //" ) AS a\n" + + //" LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\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" + + //" ) 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" + + //" ) union2"; + + string sqlString = "SELECT\n" + - " union1.* \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " temp1.交货日期,\n" + - " temp1.交货单号,\n" + - " '' 订单日期,\n" + - " temp1.采购订单号,\n" + - " temp1.SAP编码,\n" + - " temp1.物料代码,\n" + - " temp1.物料描述,\n" + - " temp1.采购订单文本,\n" + - " temp1.发货数量,\n" + - " temp1.开票数量,\n" + - " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + - " temp1.开票单价,\n" + - " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + - " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + - " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + - " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " a.Version AS 期间,\n" + - " a.PurchaseOrderNoText AS 采购订单文本,\n" + - " b.WMSDeliveryNote AS 交货单号,\n" + - " b.SpareDate AS 交货日期,\n" + - " a.PurchaseOrderNo AS 采购订单号,\n" + - " c.MaterialCode AS SAP编码,\n" + - " b.MaterialCode AS 物料代码,\n" + - " c.MaterialDesc AS 物料描述,\n" + - " c.EstimateTypeDesc AS 物料组,\n" + - " a.PurchasePriceNoTax AS 开票单价,\n" + - " 0 AS 数量差异,\n" + - " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + - " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + - " ISNULL( a.AmountNoTax, 0 ) AS 开票金额 \n" + - " FROM\n" + - " (\n" + - " SELECT SUM\n" + - " ( ReceiptQty ) AS ReceiptQty,\n" + - " PurchaseOrderNo,\n" + - " MaterialCode,\n" + - " Version,\n" + - " PurchasePriceNoTax,\n" + - " InvoicedQty,\n" + - " PurchaseOrderNoText,\n" + - " AmountNoTax \n" + - " FROM\n" + - " Set_SparePart WHERE Extend != 'is90' \n" + - " GROUP BY\n" + - " PurchaseOrderNo,\n" + - " MaterialCode,\n" + - " Version,\n" + - " PurchasePriceNoTax,\n" + - " InvoicedQty,\n" + - " PurchaseOrderNoText,\n" + - " AmountNoTax \n" + - " ) AS a\n" + - " INNER JOIN (\n" + - " SELECT SUM\n" + - " ( ReceiptQty ) AS ReceiptQty,\n" + - " PurchaseOrderNo,\n" + - " SapCode,\n" + - " MaterialCode,\n" + - " WMSDeliveryNote,\n" + - " SpareDate \n" + - " FROM\n" + - " Set_WMSSparePart \n" + - " GROUP BY\n" + - " PurchaseOrderNo,\n" + - " SapCode,\n" + - " MaterialCode,\n" + - " WMSDeliveryNote,\n" + - " SpareDate \n" + - " ) AS b ON a.PurchaseOrderNo = b.PurchaseOrderNo \n" + - " AND a.MaterialCode = b.MaterialCode\n" + - " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + - " WHERE\n" + - " ( a.Version = '{0}' ) \n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + - " ) union1 UNION ALL\n" + - "SELECT\n" + - " union2.* \n" + - "FROM\n" + - " (\n" + - " SELECT\n" + - " temp1.交货日期,\n" + - " '' 交货单号,\n" + - " '' 订单日期,\n" + - " '' 采购订单号,\n" + - " temp1.SAP编码,\n" + - " temp1.物料代码,\n" + - " temp1.物料描述,\n" + - " temp1.采购订单文本,\n" + - " temp1.发货数量,\n" + - " temp1.开票数量,\n" + - " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + - " temp1.开票单价,\n" + - " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + - " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + - " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + - " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + - " FROM\n" + - " (\n" + - " SELECT\n" + - " a.Version AS 期间,\n" + - " '' AS 采购订单文本,\n" + - " NULL AS 交货日期,\n" + - " c.MaterialCode AS SAP编码,\n" + - " a.MaterialCode AS 物料代码,\n" + - " c.MaterialDesc AS 物料描述,\n" + - " c.EstimateTypeDesc AS 物料组,\n" + - " a.PurchasePriceNoTax AS 开票单价,\n" + - " 0 AS 数量差异,\n" + - " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + - " ISNULL( a.ReceiptQty, 0 ) AS 开票数量 ,\n" + - " ISNULL( a.ReceiptQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + - " FROM\n" + - " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n" + - " LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\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" + - " ( a.Version = '{0}' ) \n" + - " ) AS temp1\n" + - " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + - " ) union2"; - - //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp.Sap编码 = TEMP2.MaterialCode\n" + - string addwhere = string.Empty; - string addSqlStr = string.Format(sqlString, version); + " 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" + + " temp1.开票数量,\n" + + " ISNULL( temp1.收货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 收货与开票差异,\n" + + " temp1.开票单价,\n" + + " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额,\n" + + " temp1.交货数量,\n" + + " temp1.收货与交货差异,\n" + + " ISNULL( temp1.交货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + " ISNULL( temp3.Qty, 0 ) 退货数量 \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " a.Version AS 期间,\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.PurchasePriceNoTax, 0 ) AS 开票单价,\n" + + " ISNULL( a.ReceiptQty, 0 ) AS 收货数量,\n" + + " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + " ISNULL( a.InvoicedQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额,\n" + + " ISNULL( C.WMSDeliveryQty, 0 ) AS 交货数量,\n" + + " ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( C.WMSDeliveryQty, 0 ) ) AS 收货与交货差异 \n" + + " FROM\n" + + " ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND PurchaseOrderNo!='NoOrder' ) 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 ) - 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 ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' AND PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) 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" + + " WHERE\n" + + " ( a.Version = '{0}' ) \n" + + " ) AS temp1\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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" + + " ) union1 \n" ; - //if (!string.IsNullOrEmpty(purchaseOrderNo)) - //{ - // addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo); - //} - //else if (!string.IsNullOrEmpty(sapCode)) - //{ - // addwhere += string.Format(" AND SAPCode LIKE '{0}%' ", sapCode); - //} - //else if (!string.IsNullOrEmpty(matialCode)) - //{ - // addwhere += string.Format(" AND MaterialCode LIKE '{0}%' ", matialCode); - //} - //else if (!string.IsNullOrEmpty(begintime)&& !string.IsNullOrEmpty(endtime)) - //{ - // addwhere += string.Format(" AND OrderDate BETWEEN '{0}' AND '{1}' ", begintime, endtime); - //} - string _sql = string.Format(addSqlStr, addwhere); - //string _sql = string.Format(sqlString, version); + + string _sql = string.Format(sqlString, version); + var _query = DbConnection.Query(_sql, null, null, true, 1200, null); - return _query.ToList(); + + var _lst = _query.ToList(); + + var sql1 = "SELECT\n" + + " A.WMSDeliveryNote WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " A.PurchaseOrderNo,\n" + + " A.SpareDate WmsDate \n" + + "FROM\n" + + " Set_WMSSparePart A\n" + + " INNER JOIN ( SELECT MaterialCode, PurchaseOrderNo FROM Set_WMSSparePart GROUP BY MaterialCode, PurchaseOrderNo HAVING COUNT ( 1 ) = 1 ) B ON A.PurchaseOrderNo = B.PurchaseOrderNo \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON A.MaterialCode = t1.CustomerPartCode \n" + + "WHERE\n" + + " A.WMSDeliveryNote IS NOT NULL "; + + + var listCompare1 = DbConnection.Query(sql1); + + + List _ls1 = new List(); + foreach (var itm in listCompare1.ToList()) + { + var first = _ls1.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(); + } + _ls1.Add(itm); + } + + } + + + + + var sql2 = "SELECT\n" + + " A.WMSDeliveryNote WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " A.PurchaseOrderNo,\n" + + " A.SpareDate WmsDate \n" + + "FROM\n" + + " Set_WMSSparePart A\n" + + " INNER JOIN ( SELECT MaterialCode, PurchaseOrderNo FROM Set_WMSSparePart GROUP BY MaterialCode, PurchaseOrderNo HAVING COUNT ( * ) > 1 ) B ON A.PurchaseOrderNo = B.PurchaseOrderNo \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON A.MaterialCode = t1.CustomerPartCode"; + + var listCompare = DbConnection.Query(sql2); + + + + List _ls = new List(); + 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 itm1 in _lst) + { + //itm1.收货与交货差异 = itm1.收货数量 - ((!string.IsNullOrEmpty(itm1.实际交货数量)) ? decimal.Parse(itm1.实际交货数量) : 0); + var item = _ls1.FirstOrDefault(p => p.Kanban == itm1.采购订单号 && p.MaterialCode == itm1.SAP编码); + if (item != null) + { + itm1.交货单号 = item.WmsBillNum; + itm1.交货日期 = item.WmsDate; + } + + + + var itm = _ls.FirstOrDefault(p => p.Kanban == itm1.采购订单号 && p.MaterialCode == itm1.SAP编码); + if (itm != null) + { + itm1.交货单号 = itm.WmsBillNum; + itm1.交货日期 = itm.WmsDate; + } + + + } + + return _lst; } + /// - /// 有结算无发货的报表统计 + /// 带采购订单号和无订单号一起统计报表 WHERE Extend != 'is90' /// /// /// @@ -203,48 +360,241 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// /// /// - public virtual List GetForwardSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + //public virtual List GetSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + // string begintime, string endtime) + //{ + // string sqlString = "SELECT\n" + + // " union1.* \n" + + // "FROM\n" + + // " (\n" + + // " SELECT\n" + + // " temp1.交货日期,\n" + + // " temp1.交货单号,\n" + + // " '' 订单日期,\n" + + // " temp1.采购订单号,\n" + + // " temp1.SAP编码,\n" + + // " temp1.物料代码,\n" + + // " temp1.物料描述,\n" + + // " temp1.采购订单文本,\n" + + // " temp1.发货数量,\n" + + // " temp1.开票数量,\n" + + // " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + // " temp1.开票单价,\n" + + // " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + // " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + // " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + // " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + + // " FROM\n" + + // " (\n" + + // " SELECT\n" + + // " a.Version AS 期间,\n" + + // " a.PurchaseOrderNoText AS 采购订单文本,\n" + + // " b.WMSDeliveryNote AS 交货单号,\n" + + // " b.SpareDate AS 交货日期,\n" + + // " a.PurchaseOrderNo AS 采购订单号,\n" + + // " c.MaterialCode AS SAP编码,\n" + + // " b.MaterialCode AS 物料代码,\n" + + // " c.MaterialDesc AS 物料描述,\n" + + // " c.EstimateTypeDesc AS 物料组,\n" + + // " a.PurchasePriceNoTax AS 开票单价,\n" + + // " 0 AS 数量差异,\n" + + // " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + + // " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + // " ISNULL( a.AmountNoTax, 0 ) AS 开票金额 \n" + + // " FROM\n" + + // " (\n" + + // " SELECT SUM\n" + + // " ( ReceiptQty ) AS ReceiptQty,\n" + + // " PurchaseOrderNo,\n" + + // " MaterialCode,\n" + + // " Version,\n" + + // " PurchasePriceNoTax,\n" + + // " InvoicedQty,\n" + + // " PurchaseOrderNoText,\n" + + // " AmountNoTax \n" + + // " FROM\n" + + // " Set_SparePart WHERE Extend != 'is90' \n" + + // " GROUP BY\n" + + // " PurchaseOrderNo,\n" + + // " MaterialCode,\n" + + // " Version,\n" + + // " PurchasePriceNoTax,\n" + + // " InvoicedQty,\n" + + // " PurchaseOrderNoText,\n" + + // " AmountNoTax \n" + + // " ) AS a\n" + + // " INNER JOIN (\n" + + // " SELECT SUM\n" + + // " ( ReceiptQty ) AS ReceiptQty,\n" + + // " PurchaseOrderNo,\n" + + // " SapCode,\n" + + // " MaterialCode,\n" + + // " WMSDeliveryNote,\n" + + // " SpareDate \n" + + // " FROM\n" + + // " Set_WMSSparePart \n" + + // " GROUP BY\n" + + // " PurchaseOrderNo,\n" + + // " SapCode,\n" + + // " MaterialCode,\n" + + // " WMSDeliveryNote,\n" + + // " SpareDate \n" + + // " ) AS b ON a.PurchaseOrderNo = b.PurchaseOrderNo \n" + + // " AND a.MaterialCode = b.MaterialCode\n" + + // " LEFT OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" + + // " WHERE\n" + + // " ( a.Version = '{0}' ) \n" + + // " ) AS temp1\n" + + // " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + + // " ) union1 UNION ALL\n" + + // "SELECT\n" + + // " union2.* \n" + + // "FROM\n" + + // " (\n" + + // " SELECT\n" + + // " temp1.交货日期,\n" + + // " '' 交货单号,\n" + + // " '' 订单日期,\n" + + // " '' 采购订单号,\n" + + // " temp1.SAP编码,\n" + + // " temp1.物料代码,\n" + + // " temp1.物料描述,\n" + + // " temp1.采购订单文本,\n" + + // " temp1.发货数量,\n" + + // " temp1.开票数量,\n" + + // " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + // " temp1.开票单价,\n" + + // " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + // " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + // " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + // " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + + // " FROM\n" + + // " (\n" + + // " SELECT\n" + + // " a.Version AS 期间,\n" + + // " '' AS 采购订单文本,\n" + + // " NULL AS 交货日期,\n" + + // " c.MaterialCode AS SAP编码,\n" + + // " a.MaterialCode AS 物料代码,\n" + + // " c.MaterialDesc AS 物料描述,\n" + + // " c.EstimateTypeDesc AS 物料组,\n" + + // " a.PurchasePriceNoTax AS 开票单价,\n" + + // " 0 AS 数量差异,\n" + + // " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + + // " ISNULL( a.ReceiptQty, 0 ) AS 开票数量 ,\n" + + // " ISNULL( a.ReceiptQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + + // " FROM\n" + + // " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' and PurchaseOrderNo is null GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n" + + // " LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\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" + + // " ( a.Version = '{0}' ) \n" + + // " ) AS temp1\n" + + // " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" + + // " ) union2"; + + // //" LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) FROM Set_PriceList ) ) ) AS TEMP2 ON temp.Sap编码 = TEMP2.MaterialCode\n" + + // string addwhere = string.Empty; + // string addSqlStr = string.Format(sqlString, version); + + // //if (!string.IsNullOrEmpty(purchaseOrderNo)) + // //{ + // // addwhere += string.Format(" AND PurchaseOrderNo LIKE '{0}%' ", purchaseOrderNo); + // //} + // //else if (!string.IsNullOrEmpty(sapCode)) + // //{ + // // addwhere += string.Format(" AND SAPCode LIKE '{0}%' ", sapCode); + // //} + // //else if (!string.IsNullOrEmpty(matialCode)) + // //{ + // // addwhere += string.Format(" AND MaterialCode LIKE '{0}%' ", matialCode); + // //} + // //else if (!string.IsNullOrEmpty(begintime)&& !string.IsNullOrEmpty(endtime)) + // //{ + // // addwhere += string.Format(" AND OrderDate BETWEEN '{0}' AND '{1}' ", begintime, endtime); + // //} + + // string _sql = string.Format(addSqlStr, addwhere); + // //string _sql = string.Format(sqlString, version); + // var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + // return _query.ToList(); + + //} + + + /// + /// 大众备件有单号,统计有结算无发货 + /// + /// + /// + /// + /// + /// + /// + /// + public virtual List GetWithCodeSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, string begintime, string endtime) { string sqlString = "SELECT\n" + " temp1.交货日期,\n" + - " '' 交货单号,\n" + - " '' 订单日期,\n" + - " '' 采购订单号,\n" + + " temp1.交货单号,\n" + + " NULL 订单日期,\n" + + " temp1.采购订单号,\n" + " temp1.SAP编码,\n" + " temp1.物料代码,\n" + " temp1.物料描述,\n" + " temp1.采购订单文本,\n" + - " temp1.发货数量,\n" + + " temp1.收货数量,\n" + " temp1.开票数量,\n" + - " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + " ISNULL( temp1.收货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 收货与开票差异,\n" + " temp1.开票单价,\n" + " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + - " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + + " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额,\n" + + " temp1.交货数量,\n" + + " temp1.收货与交货差异,\n" + + " ISNULL( temp1.交货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + " ISNULL( temp3.Qty, 0 ) 退货数量 \n" + "FROM\n" + " (\n" + " SELECT\n" + " a.Version AS 期间,\n" + - " '' AS 采购订单文本,\n" + + " a.PurchaseOrderNoText AS 采购订单文本,\n" + + " '' AS 交货单号,\n" + " NULL AS 交货日期,\n" + - " c.MaterialCode AS SAP编码,\n" + - " a.MaterialCode AS 物料代码,\n" + - " c.MaterialDesc AS 物料描述,\n" + - " c.EstimateTypeDesc AS 物料组,\n" + - " a.PurchasePriceNoTax AS 开票单价,\n" + - " 0 AS 数量差异,\n" + - " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + - " ISNULL( a.ReceiptQty, 0 ) AS 开票数量 ,\n" + - " ISNULL( a.ReceiptQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) 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.PurchasePriceNoTax, 0 ) AS 开票单价,\n" + + " ISNULL( a.ReceiptQty, 0 ) AS 收货数量,\n" + + " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + " ISNULL( a.InvoicedQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额,\n" + + " ISNULL( C.WMSDeliveryQty, 0 ) AS 交货数量,\n" + + " ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( C.WMSDeliveryQty, 0 ) ) AS 收货与交货差异 \n" + " FROM\n" + - " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode, Version, PurchasePriceNoTax FROM Set_SparePart WHERE Extend != 'is90' GROUP BY MaterialCode, Version, PurchasePriceNoTax ) AS a\n" + - " LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\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" + + " ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' and PurchaseOrderNo!='NoOrder' ) 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 ) - 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 ( SELECT SUM ( ReceiptQty ) Qty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE VERSION < '{0}' AND Extend != 'is90' and PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) 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" + " WHERE\n" + - " ( a.Version = '{0}' ) \n" + + " C.PurchaseOrderNo is null and C.MaterialCode is NULL\n" + " ) AS temp1\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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"; string addwhere = string.Empty; @@ -258,8 +608,9 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } + /// - /// 有发货无结算的报表统计 + /// 大众备件无单号,求和汇总显示 /// /// /// @@ -268,8 +619,8 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// /// /// - public virtual List GetReverseSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, - string begintime, string endtime) + public virtual List GetNoCodeSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + string begintime, string endtime) { string sqlString = "SELECT\n" + " temp1.交货日期,\n" + @@ -279,10 +630,11 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " temp1.SAP编码,\n" + " temp1.物料代码,\n" + " temp1.物料描述,\n" + - " temp1.采购订单文本,\n" + - " temp1.发货数量,\n" + + " '' 采购订单文本,\n" + + " 0 发货数量,\n" + + " temp1.收货数量,\n" + " temp1.开票数量,\n" + - " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + " ISNULL( temp1.收货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 收货与开票差异,\n" + " temp1.开票单价,\n" + " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + @@ -291,26 +643,36 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report "FROM\n" + " (\n" + " SELECT\n" + - " b.Version AS 期间,\n" + - " '' AS 采购订单文本,\n" + + " '' AS 交货单号,\n" + " NULL AS 交货日期,\n" + " c.MaterialCode AS SAP编码,\n" + " a.MaterialCode AS 物料代码,\n" + " c.MaterialDesc AS 物料描述,\n" + " c.EstimateTypeDesc AS 物料组,\n" + - " b.PurchasePriceNoTax AS 开票单价,\n" + - " 0 AS 数量差异,\n" + - " ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + - " ISNULL( b.ReceiptQty, 0 ) AS 开票数量 ,\n" + - " ISNULL( b.ReceiptQty, 0 ) * ISNULL( b.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + + " ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票单价,\n" + + " ISNULL( a.ReceiptQty, 0 ) AS 收货数量,\n" + + " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + " ISNULL( a.ReceiptQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + " FROM\n" + - " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, SapCode, MaterialCode FROM Set_WMSSparePart GROUP BY SapCode, MaterialCode ) AS a\n" + - " LEFT JOIN ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' ) AS b ON a.MaterialCode = b.MaterialCode\n" + + " (\n" + + " SELECT SUM\n" + + " ( ReceiptQty ) AS ReceiptQty,\n" + + " SUM ( InvoicedQty ) InvoicedQty,\n" + + " MaterialCode,\n" + + " PurchasePriceNoTax \n" + + " FROM\n" + + " Set_SparePart \n" + + " WHERE\n" + + " Extend != 'is90' \n" + + " AND Version = '{0}' \n" + + " AND PurchaseOrderNo = 'NoOrder' \n" + + " GROUP BY\n" + + " MaterialCode,\n" + + " PurchasePriceNoTax \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" + - " WHERE\n" + - " ( 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"; + " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = ( SELECT MAX ( VERSION ) FROM Set_PriceList ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode"; string addwhere = string.Empty; string addSqlStr = string.Format(sqlString, version); @@ -324,6 +686,445 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report + /// + /// 不管备件有无单号,财务要求都做一个汇总,然后和寄售库进行比对 + /// + /// + /// + /// + /// + /// + /// + /// + public virtual List GetForwardSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + string begintime, string endtime) + { + string sqlString = "SELECT\n" + + " temp1.交货日期,\n" + + " '' 交货单号,\n" + + " '' 订单日期,\n" + + " '' 采购订单号,\n" + + " temp1.SAP编码,\n" + + " temp1.物料代码,\n" + + " temp1.物料描述,\n" + + " temp1.采购订单文本,\n" + + " temp1.发货数量,\n" + + " temp1.收货数量,\n" + + " temp1.开票数量,\n" + + " ISNULL( temp1.收货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 收货与开票差异,\n" + + " temp1.开票单价,\n" + + " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " '' AS 采购订单文本,\n" + + " NULL AS 交货日期,\n" + + " c.MaterialCode AS SAP编码,\n" + + " a.MaterialCode AS 物料代码,\n" + + " c.MaterialDesc AS 物料描述,\n" + + " c.EstimateTypeDesc AS 物料组,\n" + + " a.PurchasePriceNoTax AS 开票单价,\n" + + " 0 AS 数量差异,\n" + + " ISNULL( b.ReceiptQty, 0 ) AS 发货数量,\n" + + " ISNULL( a.ReceiptQty, 0 ) AS 收货数量 ,\n" + + " ISNULL( a.InvoicedQty, 0 ) AS 开票数量 ,\n" + + " ISNULL( a.ReceiptQty, 0 ) * ISNULL( a.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + + " FROM\n" + + " (\n" + + " SELECT SUM\n" + + " ( ReceiptQty ) AS ReceiptQty,\n" + + " SUM ( InvoicedQty ) InvoicedQty,\n" + + " MaterialCode,\n" + + " PurchasePriceNoTax \n" + + " FROM\n" + + " Set_SparePart \n" + + " WHERE\n" + + " Extend != 'is90' \n" + + " AND Version = '{0}' \n" + + " GROUP BY\n" + + " MaterialCode,\n" + + " PurchasePriceNoTax \n" + + " ) AS a\n" + + " LEFT JOIN ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS b ON a.MaterialCode = b.MaterialCode\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" + + " ) AS temp1\n" + + " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE Version = '202110' ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode"; + + + string _sql = string.Format(sqlString, version); + var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + return _query.ToList(); + + } + + + /// + /// 有发货无结算的报表统计,不用了 + /// + /// + /// + /// + /// + /// + /// + /// + //public virtual List GetReverseSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + // string begintime, string endtime) + //{ + // string sqlString = "SELECT\n" + + // " temp1.交货日期,\n" + + // " '' 交货单号,\n" + + // " '' 订单日期,\n" + + // " '' 采购订单号,\n" + + // " temp1.SAP编码,\n" + + // " temp1.物料代码,\n" + + // " temp1.物料描述,\n" + + // " temp1.采购订单文本,\n" + + // " temp1.发货数量,\n" + + // " temp1.开票数量,\n" + + // " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.开票数量, 0 ) AS 发货与开票差异,\n" + + // " temp1.开票单价,\n" + + // " ISNULL( temp1.开票金额, 0 ) AS 开票金额,\n" + + // " ISNULL( TEMP2.Price, 0 ) AS 定价,\n" + + // " temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) AS 单价差异 ,\n" + + // " ( temp1.开票单价 - ISNULL( TEMP2.Price, 0 ) ) * temp1.开票数量 AS 差异总金额 \n" + + // "FROM\n" + + // " (\n" + + // " SELECT\n" + + // " b.Version AS 期间,\n" + + // " '' AS 采购订单文本,\n" + + // " NULL AS 交货日期,\n" + + // " c.MaterialCode AS SAP编码,\n" + + // " a.MaterialCode AS 物料代码,\n" + + // " c.MaterialDesc AS 物料描述,\n" + + // " c.EstimateTypeDesc AS 物料组,\n" + + // " b.PurchasePriceNoTax AS 开票单价,\n" + + // " 0 AS 数量差异,\n" + + // " ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + + // " ISNULL( b.ReceiptQty, 0 ) AS 开票数量 ,\n" + + // " ISNULL( b.ReceiptQty, 0 ) * ISNULL( b.PurchasePriceNoTax, 0 ) AS 开票金额 \n" + + // " FROM\n" + + // " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, MaterialCode FROM Set_WMSSparePart GROUP BY MaterialCode ) AS a\n" + + // " LEFT JOIN ( SELECT * FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' ) AS b ON a.MaterialCode = b.MaterialCode\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" + + // " ( 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"; + + // string addwhere = string.Empty; + // string addSqlStr = string.Format(sqlString, version); + + // string _sql = string.Format(addSqlStr, addwhere); + // //string _sql = string.Format(sqlString, version); + // var _query = DbConnection.Query(_sql, null, null, true, 1200, null); + // return _query.ToList(); + + //} + + + /// + /// 大众备件未结(带单号),包含有发货有结算(条件:发货数量大于结算数据)也整合到大众备件未结中 + /// + /// + /// + /// + /// + /// + /// + /// + public virtual List GetReverseWithCodeSettleSparePartReportList(string purchaseOrderNo, string version, string sapCode, string matialCode, + string begintime, string endtime) + { + List _list = new List(); + + string condition = ""; + + if (!string.IsNullOrEmpty(begintime) && Convert.ToDateTime(begintime) != DateTime.MinValue) + { + condition += string.Format(" and a.SpareDate>='{0}' ", begintime); + } + if (!string.IsNullOrEmpty(endtime) && Convert.ToDateTime(begintime) != DateTime.MinValue) + { + condition += string.Format(" and a.SpareDate<='{0}' ", endtime); + } + + string sqlString = "SELECT\n" + + " * \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " temp1.交货单号,\n" + + " temp1.交货日期,\n" + + " temp1.采购订单号,\n" + + " temp1.SAP编码,\n" + + " temp1.物料代码,\n" + + " temp1.物料描述,\n" + + " temp1.发货数量,\n" + + " temp1.收货数量,\n" + + " temp1.收货与交货差异,\n" + + " ISNULL( temp3.Qty, 0 ) 退货数量,\n" + + " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.收货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + " ISNULL( TEMP2.Price, 0 ) AS 定价 \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " '' AS 交货单号,\n" + + " NULL AS 交货日期,\n" + + " a.PurchaseOrderNo AS 采购订单号,\n" + + " c.MaterialCode AS SAP编码,\n" + + " c.CustomerPartCode AS 物料代码,\n" + + " c.MaterialDesc AS 物料描述,\n" + + " c.EstimateTypeDesc AS 物料组,\n" + + " ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + + " ISNULL( b.ReceiptQty, 0 ) AS 收货数量,\n" + + " ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( b.ReceiptQty, 0 ) ) AS 收货与交货差异 \n" + + " FROM\n" + + " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart WHERE PurchaseOrderNo is not null and PurchaseOrderNo!='' GROUP BY PurchaseOrderNo, MaterialCode ) AS a\n" + + " LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' and PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n" + + " AND a.MaterialCode = b.MaterialCode\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" + + " b.PurchaseOrderNo IS NULL \n" + + " AND b.MaterialCode IS NULL \n" + + " ) AS temp1\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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" + + " ) unint1 UNION ALL\n" + + "SELECT\n" + + " * \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " temp1.交货单号,\n" + + " temp1.交货日期,\n" + + " temp1.采购订单号,\n" + + " temp1.SAP编码,\n" + + " temp1.物料代码,\n" + + " temp1.物料描述,\n" + + " temp1.发货数量,\n" + + " temp1.收货数量,\n" + + " temp1.收货与交货差异,\n" + + " ISNULL( temp3.Qty, 0 ) 退货数量,\n" + + " ISNULL( temp1.发货数量, 0 ) - ISNULL( temp1.收货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + " ISNULL( TEMP2.Price, 0 ) AS 定价 \n" + + " FROM\n" + + " (\n" + + " SELECT\n" + + " '' AS 交货单号,\n" + + " NULL AS 交货日期,\n" + + " a.PurchaseOrderNo AS 采购订单号,\n" + + " c.MaterialCode AS SAP编码,\n" + + " c.CustomerPartCode AS 物料代码,\n" + + " c.MaterialDesc AS 物料描述,\n" + + " c.EstimateTypeDesc AS 物料组,\n" + + " ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" + + " ISNULL( b.ReceiptQty, 0 ) AS 收货数量,\n" + + " ( ISNULL( b.ReceiptQty, 0 ) - ISNULL( a.ReceiptQty, 0 ) ) AS 收货与交货差异 \n" + + " FROM\n" + + " ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart WHERE PurchaseOrderNo is not null and PurchaseOrderNo!='' GROUP BY PurchaseOrderNo, MaterialCode ) a\n" + + " INNER JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' and PurchaseOrderNo!='NoOrder' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n" + + " AND a.MaterialCode = b.MaterialCode\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" + + " a.ReceiptQty> b.ReceiptQty \n" + + " ) AS temp1\n" + + " LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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" + + " ) unint2"; + + //string sqlString = "SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" temp1.交货单号,\n" + + //" temp1.交货日期,\n" + + //" temp1.采购订单号,\n" + + //" temp1.SAP编码,\n" + + //" temp1.物料代码,\n" + + //" temp1.物料描述,\n" + + //" temp1.交货数量,\n" + + //" temp1.收货数量,\n" + + //" temp1.收货与交货差异,\n" + + //" ISNULL( temp3.Qty, 0 ) 退货数量,\n" + + //" ISNULL( temp1.交货数量, 0 ) - ISNULL( temp1.收货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + //" ISNULL( TEMP2.Price, 0 ) AS 定价 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" NULL AS 交货日期,\n" + + //" a.PurchaseOrderNo AS 采购订单号,\n" + + //" c.MaterialCode AS SAP编码,\n" + + //" c.CustomerPartCode AS 物料代码,\n" + + //" c.MaterialDesc AS 物料描述,\n" + + //" c.EstimateTypeDesc AS 物料组,\n" + + //" ISNULL( a.ReceiptQty, 0 ) AS 交货数量,\n" + + //" ISNULL( b.ReceiptQty, 0 ) AS 收货数量,\n" + + //" ( ISNULL( a.ReceiptQty, 0 ) - ISNULL( b.ReceiptQty, 0 ) ) AS 收货与交货差异 \n" + + //" FROM\n" + + //" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) AS a\n" + + //" LEFT JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' AND Version = '{0}' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n" + + //" AND a.MaterialCode = b.MaterialCode\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" + + //" b.PurchaseOrderNo IS NULL \n" + + //" AND b.MaterialCode IS NULL \n" + + //" ) AS temp1\n" + + //" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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" + + //" ) unint1 UNION ALL\n" + + //"SELECT\n" + + //" * \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" temp1.交货单号,\n" + + //" temp1.交货日期,\n" + + //" temp1.采购订单号,\n" + + //" temp1.SAP编码,\n" + + //" temp1.物料代码,\n" + + //" temp1.物料描述,\n" + + //" temp1.交货数量,\n" + + //" temp1.收货数量,\n" + + //" temp1.收货与交货差异,\n" + + //" ISNULL( temp3.Qty, 0 ) 退货数量,\n" + + //" ISNULL( temp1.交货数量, 0 ) - ISNULL( temp1.收货数量, 0 ) - ISNULL( temp3.Qty, 0 ) 实际交货数量,\n" + + //" ISNULL( TEMP2.Price, 0 ) AS 定价 \n" + + //" FROM\n" + + //" (\n" + + //" SELECT\n" + + //" '' AS 交货单号,\n" + + //" NULL AS 交货日期,\n" + + //" a.PurchaseOrderNo AS 采购订单号,\n" + + //" c.MaterialCode AS SAP编码,\n" + + //" c.CustomerPartCode AS 物料代码,\n" + + //" c.MaterialDesc AS 物料描述,\n" + + //" c.EstimateTypeDesc AS 物料组,\n" + + //" ISNULL( a.ReceiptQty, 0 ) AS 交货数量,\n" + + //" ISNULL( b.ReceiptQty, 0 ) AS 收货数量,\n" + + //" ( ISNULL( b.ReceiptQty, 0 ) - ISNULL( a.ReceiptQty, 0 ) ) AS 收货与交货差异 \n" + + //" FROM\n" + + //" ( SELECT SUM ( ReceiptQty ) AS ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_WMSSparePart GROUP BY PurchaseOrderNo, MaterialCode ) a\n" + + //" INNER JOIN ( SELECT SUM ( ReceiptQty ) ReceiptQty, PurchaseOrderNo, MaterialCode FROM Set_SparePart WHERE Extend != 'is90' AND Version < '{0}' GROUP BY PurchaseOrderNo, MaterialCode ) AS b ON a.PurchaseOrderNo= b.PurchaseOrderNo \n" + + //" AND a.MaterialCode = b.MaterialCode\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" + + //" a.ReceiptQty> b.ReceiptQty \n" + + //" ) AS temp1\n" + + //" LEFT JOIN ( SELECT * FROM set_backQty WHERE Version = '{0}' ) 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" + + //" ) unint2"; + + + string _sql = string.Format(sqlString, version); + + + + //发运数据中,查出看板号+物料号相同的重复数据 + var sql2 = "SELECT\n" + + " a.WMSDeliveryNote WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " a.PurchaseOrderNo Kanban ,\n" + + " A.SpareDate WmsDate \n" + + "FROM\n" + + " Set_WMSSparePart A\n" + + " INNER JOIN ( SELECT MaterialCode, PurchaseOrderNo FROM Set_WMSSparePart GROUP BY MaterialCode, PurchaseOrderNo HAVING COUNT ( * ) > 1 ) B ON A.PurchaseOrderNo = B.PurchaseOrderNo \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(_sql2); + + + + + //查询发运表中,看板号+物料号没有重复的数据 + var sql3 = "SELECT\n" + + " a.WMSDeliveryNote WmsBillNum,\n" + + " t1.MaterialCode MaterialCode,\n" + + " a.PurchaseOrderNo Kanban,\n" + + " A.SpareDate WmsDate \n" + + "FROM\n" + + " Set_WMSSparePart A\n" + + " LEFT JOIN ( SELECT MaterialCode, PurchaseOrderNo FROM Set_WMSSparePart GROUP BY MaterialCode, PurchaseOrderNo HAVING COUNT ( * ) > 1 ) B ON A.PurchaseOrderNo = B.PurchaseOrderNo \n" + + " AND A.MaterialCode = B.MaterialCode\n" + + " LEFT JOIN Set_material t1 ON a.MaterialCode= t1.CustomerPartCode \n" + + "WHERE\n" + + " B.PurchaseOrderNo IS NULL {0}"; + var _sql3 = string.Format(sql3, condition); + var listCompare1 = DbConnection.Query(_sql3); + + + + + + //发运数据比较 + List _ls = new List(); + 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(_sql, null, null, true, 1200, null); + _list = _query.ToList(); + + 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; + } + } + + + return _list; + + } + + + } @@ -337,7 +1138,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report -public class SparePartSumQtyDiff + public class SparePartSumQtyDiff { public decimal 数量差异 { set; get; } public string 订单号 { set; get; } @@ -364,21 +1165,30 @@ public class SparePartSumQtyDiff public SettleSparePartExport( string sapMaterialCode, string materialCode, string materialDesc, - decimal qty, decimal sockQty) + decimal shouqty,decimal reqty, decimal qty, decimal diff,decimal price,decimal invocprice, + decimal dingprice,decimal diffprice,decimal diffsumprice, decimal sockQty) { SAP编码 = sapMaterialCode; - 物料描述 = materialDesc; 物料代码 = materialCode; + 物料描述 = materialDesc; + 发货数量 = shouqty; + 收货数量 = reqty; 开票数量 = qty; + 收货与开票差异 = diff; + 开票单价 = price; + 开票金额 = invocprice; + 定价 = dingprice; + 单价差异 = diffprice; + 差异总金额 = diffsumprice; 寄售库存数量 = sockQty; } - - [ExporterHeader(DisplayName = "交货日期 ")] - public string 交货日期 { set; get; } [ExporterHeader(DisplayName = "交货单号")] public string 交货单号 { set; get; } + [ExporterHeader(DisplayName = "交货日期 ")] + public string 交货日期 { set; get; } + [ExporterHeader(DisplayName = "订单日期")] public string 订单日期 { set; get; } @@ -392,15 +1202,19 @@ public class SparePartSumQtyDiff [ExporterHeader(DisplayName = "物料描述")] public string 物料描述 { set; get; } - [ExporterHeader(DisplayName = "采购订单文本")] + [ExporterHeader(DisplayName = "采购订单文本",IsIgnore =true)] public string 采购订单文本 { 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 = "收货与开票差异")] + public decimal 收货与开票差异 { set; get; } [ExporterHeader(DisplayName = "开票单价")] public decimal 开票单价 { set; get; } @@ -417,5 +1231,67 @@ public class SparePartSumQtyDiff [ExporterHeader(DisplayName = "寄售库存数量")] public decimal 寄售库存数量 { set; get; } + [ExporterHeader(DisplayName = "交货数量",IsIgnore =true)] + public decimal 交货数量 { set; get; } + + [ExporterHeader(DisplayName = "退货数量",IsIgnore =true)] + public string 退货数量 { set; get; } + + [ExporterHeader(DisplayName = "实际交货数量", IsIgnore = true)] + public string 实际交货数量 { set; get; } + [ExporterHeader(DisplayName = "收货与交货差异", IsIgnore = true)] + public decimal 收货与交货差异 { set; get; } + + } + + /// + /// 大众备件未结 + /// + public class UnSettleSparePartExport + { + + public UnSettleSparePartExport() + { + } + + [ExporterHeader(DisplayName = "交货单号")] + 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 = "采购订单文本", IsIgnore = true)] + public string 采购订单文本 { set; get; } + + [ExporterHeader(DisplayName = "发货数量")] + public decimal 发货数量 { set; get; } + + [ExporterHeader(DisplayName = "收货数量")] + public decimal 收货数量 { set; get; } + + + [ExporterHeader(DisplayName = "收货与交货差异")] + public decimal 收货与交货差异 { set; get; } + [ExporterHeader(DisplayName = "退货数量")] + public string 退货数量 { set; get; } + [ExporterHeader(DisplayName = "实际交货数量")] + public string 实际交货数量 { set; get; } + + [ExporterHeader(DisplayName = "定价")] + public decimal 定价 { set; get; } + + + [ExporterHeader(DisplayName = "寄售库存数量", IsIgnore = true)] + public decimal 寄售库存数量 { set; get; } + + } } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSharePartSettledDetailDiffExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSharePartSettledDetailDiffExportService.cs index 30bdb6dc..7cc4697a 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSharePartSettledDetailDiffExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/HQHSharePartSettledDetailDiffExportService.cs @@ -59,6 +59,7 @@ namespace SettleAccount.Job.Services.Report var sapCode = p_list.Where(p => p.Name == "SapCode").FirstOrDefault().Value; var warehouseDesc = p_list.Where(p => p.Name == "WarehouseDesc").FirstOrDefault().Value; + //备件明细数据 var _ls = _dapperRepository.GetSharePartSettledDetailDiffReportList(version, materialCode, begin, end, materialGroup); //求和汇总 diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePart90ExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePart90ExportService.cs index 9cfbc6bf..75efd346 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePart90ExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePart90ExportService.cs @@ -97,7 +97,7 @@ namespace SettleAccount.Job.Services.Report ExcelExporter _exporter = new ExcelExporter();//导出Excel - var result = _exporter.Append(_ls.ToList(), "大众备件数据调整") + var result = _exporter.Append(_ls.ToList(), "大众备件数据调整输出") .SeparateBySheet() .Append(_unls.ToList(), "有发货无结算") .ExportAppendDataAsByteArray(); diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePartExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePartExportService.cs index 1b25aa14..e29f9803 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePartExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePartExportService.cs @@ -44,18 +44,45 @@ namespace SettleAccount.Job.Services.Report var matialCode = p_list.Where(p => p.Name == "MatialCode").FirstOrDefault().Value; var beginTime = p_list.Where(p => p.Name == "BegingTime").FirstOrDefault().Value; var endTime = p_list.Where(p => p.Name == "EndTime").FirstOrDefault().Value; + //var iscontionversion = p_list.Where(p => p.Name == "IsContainVersion").FirstOrDefault().Value; - //汇总 + //大众备件明细输出 var _ls = _dapper.GetSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); - //正向对比,有结算无发货 - var _forwardls = _dapper.GetForwardSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); + //正向对比,即有结算无发货,针对有单号备件,订单号+物料号明细 + var _forwardls_withcode = _dapper.GetWithCodeSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); + + //反向对比,即大众备件未结(有单号),包含有发货有结算并且发货数量大于结算数量的数据也整合到未结中 + var _reversels_withcode = _dapper.GetReverseWithCodeSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); - //反向对比,有发货无结算 - var _reversels = _dapper.GetReverseSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); - //按照零件号汇总数量,有一列显示寄售库数量 var stockList = _wmsDapper.GetSalesStock(); + + //针对无单号备件,求和汇总显示 + var _forwardls_nocode = _dapper.GetNoCodeSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); + var queryStockList_nocode = from itm in _forwardls_nocode + join itm1 in stockList on itm.SAP编码 equals itm1.SapCode into temp1 + from tm1 in temp1.DefaultIfEmpty() + select new SettleSparePartExport( + itm.SAP编码, + itm.物料代码, + itm.物料描述, + itm.发货数量, + itm.收货数量, + itm.开票数量, + itm.收货与开票差异, + itm.开票单价, + itm.开票金额, + itm.定价, + itm.单价差异, + itm.差异总金额, + tm1 == null ? 0 : tm1.Qty + ); + + //不管有单号备件还是无单号备件,财务要求全部按照零件汇总求和显示,并和寄售库存比对 + var _forwardls = _dapper.GetForwardSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime); + //按照零件号汇总数量,有一列显示寄售库数量 + var queryStockList = from itm in _forwardls join itm1 in stockList on itm.SAP编码 equals itm1.SapCode into temp1 from tm1 in temp1.DefaultIfEmpty() @@ -63,9 +90,17 @@ namespace SettleAccount.Job.Services.Report itm.SAP编码, itm.物料代码, itm.物料描述, + itm.发货数量, + itm.收货数量, itm.开票数量, + itm.收货与开票差异, + itm.开票单价, + itm.开票金额, + itm.定价, + itm.单价差异, + itm.差异总金额, tm1 == null ? 0 : tm1.Qty - ); + ); @@ -126,11 +161,13 @@ namespace SettleAccount.Job.Services.Report ExcelExporter _exporter = new ExcelExporter();//导出Excel - var result = _exporter.Append(_ls.ToList(), "大众备件数据输出") - .SeparateBySheet() - .Append(_forwardls.ToList(), "有结算无发货对比") + var result = _exporter.Append(_ls.ToList(), "大众备件明细数据") .SeparateBySheet() - .Append(_reversels.ToList(), "有发货无结算对比") + .Append(_forwardls_withcode.ToList(), "有结算无发货对比") + .SeparateBySheet() + .Append(_reversels_withcode.ToList(), "大众备件未结(包含发货数量大于结算数据)") + .SeparateBySheet() + .Append(queryStockList_nocode.ToList(), "大众备件无单号汇总") .SeparateBySheet() .Append(queryStockList.ToList(), "零件汇总比对寄售库存") .ExportAppendDataAsByteArray();