diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePart90AppService.cs b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePart90AppService.cs index 4a57875f..46caa532 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePart90AppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePart90AppService.cs @@ -245,6 +245,11 @@ namespace Win.Sfs.SettleAccount.Entities.WMS string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename; ExcelHelper _excelHelper = new ExcelHelper(fileSavePath); var _list = _excelHelper.ExcelToList(); + + //var _list_withbillNo = _list.Select(p => p.BillNum != string.Empty); + //var _list_withNoBillNo= _list.Select(p => p.BillNum == string.Empty); + + if (_list.Count() > 0) { var _lsAry = _list.Select(p => new @@ -462,6 +467,7 @@ namespace Win.Sfs.SettleAccount.Entities.WMS } + [HttpPost] [Route("ExcelImport")] [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 7bc42c29..631c1f0b 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePartAppService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/WMS/WMSSharePartAppService.cs @@ -216,28 +216,45 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts } return false; } - /// - /// 选择任务,生成出库单,只包含已确认的单据 - /// - /// - /// - /// + + + + + + + /// + /// 选择任务,生成出库单,只包含已确认的单据 + /// + /// + /// + /// [HttpPost] [Route("WmsSharePartOutPut")] public async Task WmsSharePartOutPut(WmsJitRequestDto input) { var _billNum = "B" + DateTime.Now.ToString("yyyyMMddhhmmss"); + var _billNoNum = "BNoBill" + DateTime.Now.ToString("yyyyMMddhhmmss"); var _joblist = _job.Where(p => input.Guids.Contains(p.Id) && p.FileName == "已确认").ToList(); if (_joblist.Count() > 0) { var fileList = _joblist.Select(p => p.RealDownFileName).ToList(); List _lst = new List(); + List _lstBill = new List(); foreach (var filename in fileList) { string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename; ExcelHelper _excelHelper = new ExcelHelper(fileSavePath); - var _list = _excelHelper.ExcelToList(); - if (_list.Count() > 0) + var _listSummary = _excelHelper.ExcelToList(); + + var _list = _listSummary.Where(p => p.OrderBillNum == "").ToList();//过滤 采购订单号为空的集合 + var _listBill = _listSummary.Where(p => p.OrderBillNum != "").ToList();//过滤 采购订单号不为空的集合 + + + + + //var _list = _excelHelper.ExcelToList(); + //没有 采购订单号 + if (_list != null && _list.Count > 0) { var _lsAry = _list.Select(p => new WmsSharePartOutPutDetial( @@ -251,11 +268,11 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts string.Empty, 0, !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, - + string.Empty, string.Empty, p.MaterialCode, - _billNum, + _billNoNum, GuidGenerator.Create(), string.Empty, p.Qty, @@ -266,88 +283,219 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts )); _lst.AddRange(_list.ToArray()); } - } - - var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version).ToListAsync(); - var error = from itm1 in outPutDetail - join itm2 in _lst on - new { itm1.MaterialCode, itm1.OrderBillNum,itm1.WmsBillNum } - equals - new { itm2.MaterialCode, itm2.OrderBillNum,itm2.WmsBillNum } - select itm1; + if (_listBill != null && _listBill.Count() > 0) + { + var _lsAry = _listBill.Select(p => new + WmsSharePartOutPutDetial( + GuidGenerator.Create(), + p.WmsBillNum, + p.OrderBillNum, + p.MaterialCode, + p.MaterialDesc, + p.MaterialGroup, + string.Empty, + string.Empty, + 0, + !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, - var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); - if (errList.Count() == 0) - { - var query = from itm1 in _lst - join itm2 in outPutDetail on - new { itm1.MaterialCode, itm1.OrderBillNum, itm1.WmsBillNum } - equals - new { itm2.MaterialCode, itm2.OrderBillNum, itm2.WmsBillNum } into temp1 - from tm1 in temp1.DefaultIfEmpty() - where tm1 == null - select itm1; - var _wmslst = query.ToList(); - _wmslst= _wmslst.Select(p => new - WmsSharePartOutPutDetial( - GuidGenerator.Create(), - string.Empty, - string.Empty, - p.MaterialCode, - p.MaterialDesc, - p.MaterialGroup, - string.Empty, - string.Empty, - 0, - !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, - string.Empty, - input.Version, - p.MaterialCode, - _billNum, - GuidGenerator.Create(), - string.Empty, - p.Qty, + string.Empty, + string.Empty, + p.MaterialCode, + _billNum, + GuidGenerator.Create(), + string.Empty, + p.Qty, p.StockQty, p.Qty, p.Price, p.Amt - )).ToList(); - await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); - int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNum); - if (_wmslst.Count()>0 && _count == 0) + )); + _lstBill.AddRange(_listBill.ToArray()); + } + } + + + if (_lst != null) + { + //没有采购订单号 + var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version && p.OrderBillNum == "").ToListAsync(); + + var error = from itm1 in outPutDetail + join itm2 in _lst on + new { itm1.MaterialCode } + equals + new { itm2.MaterialCode } + select itm1; + + var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + if (errList.Count() == 0) { - var _version = new WmsSharePartOutPut(GuidGenerator.Create(), input.Version, _billNum, CurrentUser.Email); - await _wmsVersionRepository.InsertAsync(_version, true); + var query = from itm1 in _lst + join itm2 in outPutDetail on + new { itm1.MaterialCode } + equals + new { itm2.MaterialCode } into temp1 + from tm1 in temp1.DefaultIfEmpty() + where tm1 == null + select itm1; + var _wmslst = query.ToList(); + _wmslst = _wmslst.Select(p => new + WmsSharePartOutPutDetial( + GuidGenerator.Create(), + string.Empty, + string.Empty, + p.MaterialCode, + p.MaterialDesc, + p.MaterialGroup, + string.Empty, + string.Empty, + 0, + !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, + string.Empty, + input.Version, + p.MaterialCode, + _billNoNum, + GuidGenerator.Create(), + string.Empty, + p.Qty, + p.StockQty, + p.Qty, + p.Price, + p.Amt + )).ToList(); + await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); + int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNoNum); + if (_wmslst.Count() > 0 && _count == 0) + { + var _version = new WmsSharePartOutPut(GuidGenerator.Create(), input.Version, _billNoNum, CurrentUser.Email); + await _wmsVersionRepository.InsertAsync(_version, true); + } + foreach (var job in _joblist) + { + job.FileName = _billNoNum; + await _job.UpdateAsync(job); + } } - foreach (var job in _joblist) + else { - job.FileName = _billNum; - await _job.UpdateAsync(job); + StringBuilder _buffer = new StringBuilder(); + foreach (var itm in errList) + { + _buffer.AppendFormat("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number); + } + var _errinfo = _buffer.ToString(); + + foreach (var job in _joblist) + { + job.FileName = _errinfo; + await _job.UpdateAsync(job); + } } } - else + + + + + if (_lstBill != null) { - StringBuilder _buffer = new StringBuilder(); - foreach (var itm in errList) + //有采购订单号 + var outPutDetailBill = await _wmsRepository.Where(p => p.Version == input.Version && p.OrderBillNum != "").ToListAsync(); + + var error = from itm1 in outPutDetailBill + join itm2 in _lstBill on + new { itm1.MaterialCode, itm1.OrderBillNum } + equals + new { itm2.MaterialCode, itm2.OrderBillNum } + select itm1; + + var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + if (errList.Count() == 0) { - _buffer.AppendFormat("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number); - } - var _errinfo = _buffer.ToString(); + var queryBill = from itm1 in _lstBill + join itm2 in outPutDetailBill on + new { itm1.MaterialCode, itm1.OrderBillNum } + equals + new { itm2.MaterialCode, itm2.OrderBillNum } into temp1 + from tm1 in temp1.DefaultIfEmpty() + where tm1 == null + select itm1; + var _wmslstBill = queryBill.ToList(); + _wmslstBill = _wmslstBill.Select(p => new + WmsSharePartOutPutDetial( + GuidGenerator.Create(), + p.WmsBillNum, + p.OrderBillNum, + p.MaterialCode, + p.MaterialDesc, + p.MaterialGroup, + string.Empty, + string.Empty, + 0, + !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, + string.Empty, + input.Version, + p.MaterialCode, + _billNum, + GuidGenerator.Create(), + string.Empty, + p.Qty, + p.StockQty, + p.Qty, + p.Price, + p.Amt + )).ToList(); - foreach (var job in _joblist) + await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslstBill, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); + int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNum); + if (_wmslstBill.Count() > 0 && _count == 0) + { + var _version = new WmsSharePartOutPut(GuidGenerator.Create(), input.Version, _billNum, CurrentUser.Email); + await _wmsVersionRepository.InsertAsync(_version, true); + } + foreach (var job in _joblist) + { + if (_lst != null) + { + job.FileName = _billNum + "/" + _billNoNum; + } + else + { + job.FileName = _billNum; + } + + await _job.UpdateAsync(job); + } + } + else { - job.FileName = _errinfo; - await _job.UpdateAsync(job); + StringBuilder _buffer = new StringBuilder(); + foreach (var itm in errList) + { + _buffer.AppendFormat("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number); + } + var _errinfo = _buffer.ToString(); + + foreach (var job in _joblist) + { + job.FileName = _errinfo; + await _job.UpdateAsync(job); + } } } + + } else { _billNum = string.Empty; + _billNoNum = string.Empty; } return ApplicationConsts.SuccessStr; } + + + /// /// 出库界面功能,核准出库功能 /// @@ -359,34 +507,246 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts [UnitOfWork(false)] public async Task WmsSharePartOutPutPass(WmsJitRequestDto input) { - if (input.Guids != null) + if (input.BillNum.Contains("NoBill")) { - List _ls = new List(); - if (input.Guids.Count() > 0) - { - _ls = await _wmsRepository.Where(p => input.Guids.Contains(p.Id) && p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); - } - else + //没有采购订单号的出库方式 + if (input.Guids != null) { - _ls = await _wmsRepository.Where(p => p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + List _ls = new List(); + if (input.Guids.Count() > 0) + { + _ls = await _wmsRepository.Where(p => input.Guids.Contains(p.Id) && p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + } + else + { + _ls = await _wmsRepository.Where(p => p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + } + if (_ls.Count() > 0) + { + var sql = "DECLARE @return_value int\n" + + "EXEC @return_value = [dbo].[p_wms_output]\n" + + " @billnum = N'{0}',\n" + + " @type = 2,\n" + + " @date = N'{1}'\n" + + "SELECT 'Return Value' = @return_value"; + await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + string.Format(sql, input.BillNum, input.AccountDate.ToShortDateString())); + + } } - if (_ls.Count() > 0) + } + else + { + //有采购订单号的出库方式 + if (input.Guids != null) { - var sql = "DECLARE @return_value int\n" + - "EXEC @return_value = [dbo].[p_wms_output]\n" + - " @billnum = N'{0}',\n" + - " @type = 2,\n" + - " @date = N'{1}'\n" + - "SELECT 'Return Value' = @return_value"; - await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( - string.Format(sql, input.BillNum,input.AccountDate.ToShortDateString())); - + List _ls = new List(); + if (input.Guids.Count() > 0) + { + _ls = await _wmsRepository.Where(p => input.Guids.Contains(p.Id) && p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + } + else + { + _ls = await _wmsRepository.Where(p => p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + } + if (_ls.Count() > 0) + { + var sql = "DECLARE @return_value int\n" + + "EXEC @return_value = [dbo].[p_wms_output]\n" + + " @billnum = N'{0}',\n" + + " @type = 10,\n" + + " @date = N'{1}'\n" + + "SELECT 'Return Value' = @return_value"; + await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + string.Format(sql, input.BillNum, input.AccountDate.ToShortDateString())); + + } } } return true; } + + + /// + /// 选择任务,生成出库单,只包含已确认的单据 + /// + /// + /// + /// + //[HttpPost] + //[Route("WmsSharePartOutPut")] + //public async Task WmsSharePartOutPut(WmsJitRequestDto input) + //{ + // var _billNum = "B" + DateTime.Now.ToString("yyyyMMddhhmmss"); + // var _joblist = _job.Where(p => input.Guids.Contains(p.Id) && p.FileName == "已确认").ToList(); + // if (_joblist.Count() > 0) + // { + // var fileList = _joblist.Select(p => p.RealDownFileName).ToList(); + // List _lst = new List(); + // foreach (var filename in fileList) + // { + // string fileSavePath = Environment.CurrentDirectory + @"\wwwroot\files\host\my-file-container\" + filename; + // ExcelHelper _excelHelper = new ExcelHelper(fileSavePath); + // var _list = _excelHelper.ExcelToList(); + // if (_list.Count() > 0) + // { + // var _lsAry = _list.Select(p => new + // WmsSharePartOutPutDetial( + // GuidGenerator.Create(), + // string.Empty, + // string.Empty, + // p.MaterialCode, + // p.MaterialDesc, + // p.MaterialGroup, + // string.Empty, + // string.Empty, + // 0, + // !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, + + // string.Empty, + // string.Empty, + // p.MaterialCode, + // _billNum, + // GuidGenerator.Create(), + // string.Empty, + // p.Qty, + // p.StockQty, + // p.Qty, + // p.Price, + // p.Amt + // )); + // _lst.AddRange(_list.ToArray()); + // } + // } + + // var outPutDetail = await _wmsRepository.Where(p => p.Version == input.Version).ToListAsync(); + + // var error = from itm1 in outPutDetail + // join itm2 in _lst on + // new { itm1.MaterialCode, itm1.OrderBillNum, itm1.WmsBillNum } + // equals + // new { itm2.MaterialCode, itm2.OrderBillNum, itm2.WmsBillNum } + // select itm1; + + // var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + // if (errList.Count() == 0) + // { + // var query = from itm1 in _lst + // join itm2 in outPutDetail on + // new { itm1.MaterialCode, itm1.OrderBillNum, itm1.WmsBillNum } + // equals + // new { itm2.MaterialCode, itm2.OrderBillNum, itm2.WmsBillNum } into temp1 + // from tm1 in temp1.DefaultIfEmpty() + // where tm1 == null + // select itm1; + // var _wmslst = query.ToList(); + // _wmslst = _wmslst.Select(p => new + // WmsSharePartOutPutDetial( + // GuidGenerator.Create(), + // string.Empty, + // string.Empty, + // p.MaterialCode, + // p.MaterialDesc, + // p.MaterialGroup, + // string.Empty, + // string.Empty, + // 0, + // !string.IsNullOrEmpty(p.Extend1) ? p.Extend1 : string.Empty, + // string.Empty, + // input.Version, + // p.MaterialCode, + // _billNum, + // GuidGenerator.Create(), + // string.Empty, + // p.Qty, + // p.StockQty, + // p.Qty, + // p.Price, + // p.Amt + // )).ToList(); + // await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); + // int _count = _wmsVersionRepository.Count(p => p.Version == input.Version && p.BillNum == _billNum); + // if (_wmslst.Count() > 0 && _count == 0) + // { + // var _version = new WmsSharePartOutPut(GuidGenerator.Create(), input.Version, _billNum, CurrentUser.Email); + // await _wmsVersionRepository.InsertAsync(_version, true); + // } + // foreach (var job in _joblist) + // { + // job.FileName = _billNum; + // await _job.UpdateAsync(job); + // } + // } + // else + // { + // StringBuilder _buffer = new StringBuilder(); + // foreach (var itm in errList) + // { + // _buffer.AppendFormat("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number); + // } + // var _errinfo = _buffer.ToString(); + + // foreach (var job in _joblist) + // { + // job.FileName = _errinfo; + // await _job.UpdateAsync(job); + // } + // } + // } + // else + // { + // _billNum = string.Empty; + // } + // return ApplicationConsts.SuccessStr; + //} + + + + + + + + ///// + ///// 出库界面功能,核准出库功能 + ///// + ///// + ///// + ///// + //[HttpPost] + //[Route("WmsSharePartOutPut-Pass")] + //[UnitOfWork(false)] + //public async Task WmsSharePartOutPutPass(WmsJitRequestDto input) + //{ + // if (input.Guids != null) + // { + // List _ls = new List(); + // if (input.Guids.Count() > 0) + // { + // _ls = await _wmsRepository.Where(p => input.Guids.Contains(p.Id) && p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + // } + // else + // { + // _ls = await _wmsRepository.Where(p => p.Version == input.Version && p.BillNum == input.BillNum && p.State != 2).ToListAsync(); + // } + // if (_ls.Count() > 0) + // { + // var sql = "DECLARE @return_value int\n" + + // "EXEC @return_value = [dbo].[p_wms_output]\n" + + // " @billnum = N'{0}',\n" + + // " @type = 2,\n" + + // " @date = N'{1}'\n" + + // "SELECT 'Return Value' = @return_value"; + // await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + // string.Format(sql, input.BillNum,input.AccountDate.ToShortDateString())); + + // } + // } + // return true; + //} + + [HttpPost] [Route("WmsSharePartOutPutModify")] [DisableRequestSizeLimit] @@ -414,31 +774,65 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts [Route("WmsSharePartOutPut-Cancel")] public async Task WmsSharePartOutPutCancel(WmsJitRequestDto input) { - if(input.Guids != null && input.Guids.Count() > 0) + if (input.BillNum.Contains("NoBill")) { - List _ls = new List(); - foreach (var itm in input.Guids) + //没有有采购单据号的单子 + if (input.Guids != null && input.Guids.Count() > 0) { - _ls.Add(string.Format("{0}", itm)); + List _ls = new List(); + foreach (var itm in input.Guids) + { + _ls.Add(string.Format("{0}", itm)); + } + + string str = string.Join(",", _ls.ToArray()); + + var sql = "DECLARE @return_value int\n" + + "EXEC @return_value = [dbo].[p_wms_output_cancel]\n" + + " @Guids ='{0}', \n" + + " @billnum = N'{1}',\n" + + " @type = 2,\n" + + " @accountdate = N'{2}'\n" + + "SELECT 'Return Value' = @return_value"; + + sql = string.Format(sql, str, input.BillNum, input.AccountDate.ToShortDateString()); + + await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + sql + ); + } + } + else + { + //有采购单据号的单子 + if (input.Guids != null && input.Guids.Count() > 0) + { + List _ls = new List(); + foreach (var itm in input.Guids) + { + _ls.Add(string.Format("{0}", itm)); + } - string str = string.Join(",", _ls.ToArray()); + string str = string.Join(",", _ls.ToArray()); - var sql = "DECLARE @return_value int\n" + - "EXEC @return_value = [dbo].[p_wms_output_cancel]\n" + - " @Guids ='{0}', \n" + - " @billnum = N'{1}',\n" + - " @type = 2,\n" + - " @accountdate = N'{2}'\n" + - "SELECT 'Return Value' = @return_value"; + var sql = "DECLARE @return_value int\n" + + "EXEC @return_value = [dbo].[p_wms_output_cancel]\n" + + " @Guids ='{0}', \n" + + " @billnum = N'{1}',\n" + + " @type = 10,\n" + + " @accountdate = N'{2}'\n" + + "SELECT 'Return Value' = @return_value"; - sql = string.Format(sql, str, input.BillNum, input.AccountDate.ToShortDateString()); + sql = string.Format(sql, str, input.BillNum, input.AccountDate.ToShortDateString()); - await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( - sql - ); + await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + sql + ); + } } + return true; } @@ -453,20 +847,42 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts [UnitOfWork(false)] public async Task WmsOutPutDelete(WmsJitRequestDto input) { - var count = _wmsRepository.Count(p => p.BillNum == input.BillNum && p.State != 0); + if (input.BillNum.Contains("NoBill")) + { + //没有采购单据号的单子 + var count = _wmsRepository.Count(p => p.BillNum == input.BillNum && p.State != 0); - if (count > 0) + if (count > 0) + { + return false; + } + var sql = "DECLARE @return_value int\n" + + "EXEC @return_value = [dbo].[p_wms_output_cancel_all]\n" + + " @billnum = N'{0}',\n" + + " @type = 2\n" + + "SELECT 'Return Value' = @return_value"; + await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + string.Format(sql, input.BillNum) + ); + } + else { - return false; + //有采购单据号的单子 + var count = _wmsRepository.Count(p => p.BillNum == input.BillNum && p.State != 0); + + if (count > 0) + { + return false; + } + var sql = "DECLARE @return_value int\n" + + "EXEC @return_value = [dbo].[p_wms_output_cancel_all]\n" + + " @billnum = N'{0}',\n" + + " @type = 10\n" + + "SELECT 'Return Value' = @return_value"; + await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( + string.Format(sql, input.BillNum) + ); } - var sql = "DECLARE @return_value int\n" + - "EXEC @return_value = [dbo].[p_wms_output_cancel_all]\n" + - " @billnum = N'{0}',\n" + - " @type = 2\n" + - "SELECT 'Return Value' = @return_value"; - await _wmsRepository.GetDbContext().Database.ExecuteSqlRawAsync( - string.Format(sql, input.BillNum) - ); @@ -480,143 +896,298 @@ namespace Win.Sfs.SettleAccount.Entities.SettleAccounts //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] public async Task ExcelImport([FromForm] IFormFileCollection files, string version) { - var _billNum = "B" + DateTime.Now.ToString("yyyyMMddhhmmss"); + ExportImporter _exportImporter = new ExportImporter(); var result = await _exportImporter.ExtendExcelImport(files, _excelImportService); - List _lst = new List(); - var _lsCopy = new List(); - foreach (var itm in result) + if (result == null) { - WmsSharePartOutPutDetial _detail = new WmsSharePartOutPutDetial( - GuidGenerator.Create(), - //itm.WmsBillNum, - //itm.OrderBillNum, - string.Empty, - string.Empty, - itm.MaterialCode, - itm.MaterialDesc, - itm.MaterialGroup, - string.Empty, - string.Empty, - 0, - !string.IsNullOrEmpty(itm.Extend1) ?itm.Extend1 : string.Empty, - string.Empty, - version, - itm.ParentMaterialCode, - itm.BillNum, - GuidGenerator.Create() - , string.Empty - , itm.Qty - , 0 - , itm.Qty - ,itm.Price - ,itm.Amt - ); - _lsCopy.Add(_detail); + throw new BusinessException("导入的模板中没有数据,不能为空,请检查!"); } - _lst.AddRange(_lsCopy.ToArray()); - //var _ls1 = _lst.Where(p => p.ParentMaterialCode == p.MaterialCode).ToList(); - var outPutDetail = await _wmsRepository.Where(p => p.Version == version).ToListAsync(); + var result_withbill = result.Where(p => p.OrderBillNum != "").ToList(); + var result_nobill = result.Where(p => p.OrderBillNum == "").ToList(); + //没有采购单号 + if (result_nobill != null) + { + var _billNoNum = "BNoBill" + DateTime.Now.ToString("yyyyMMddhhmmss"); + List _lst = new List(); - //var error = from itm1 in outPutDetail - // join itm2 in _ls1 on - // new { itm1.MaterialCode, itm1.OrderBillNum,itm1.WmsBillNum } - // equals - // new { itm2.MaterialCode, itm2.OrderBillNum,itm2.WmsBillNum } - // select itm1; + var _lsCopy = new List(); + foreach (var itm in result_nobill) + { + WmsSharePartOutPutDetial _detail = new WmsSharePartOutPutDetial( + GuidGenerator.Create(), + string.Empty, + string.Empty, + itm.MaterialCode, + itm.MaterialDesc, + itm.MaterialGroup, + string.Empty, + string.Empty, + 0, + !string.IsNullOrEmpty(itm.Extend1) ? itm.Extend1 : string.Empty, + string.Empty, + version, + itm.ParentMaterialCode, + itm.BillNum, + GuidGenerator.Create() + , string.Empty + , itm.Qty + , 0 + , itm.Qty + , itm.Price + , itm.Amt + ); + _lsCopy.Add(_detail); + } + _lst.AddRange(_lsCopy.ToArray()); - var error = from itm1 in outPutDetail - join itm2 in _lst on - new { itm1.MaterialCode } - equals - new { itm2.MaterialCode } - select itm1; + //var _ls1 = _lst.Where(p => p.ParentMaterialCode == p.MaterialCode).ToList(); + var outPutDetail = await _wmsRepository.Where(p => p.Version == version).ToListAsync(); - var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + var error = from itm1 in outPutDetail + join itm2 in _lst on + new { itm1.MaterialCode } + equals + new { itm2.MaterialCode } + select itm1; - var checkList = new List(); - foreach (var itm in errList) - { - checkList.Add(new ErrorExportDto() { Message = string.Format("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number) }); - } - if (checkList.Count > 0) - { + var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); - return await ExportErrorReportAsync(checkList); - } + var checkList = new List(); + foreach (var itm in errList) + { + checkList.Add(new ErrorExportDto() { Message = string.Format("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number) }); + } + if (checkList.Count > 0) + { - //var query = from itm1 in _ls1 - // join itm2 in outPutDetail on - // new { itm1.MaterialCode, itm1.OrderBillNum } - // equals - // new { itm2.MaterialCode, itm2.OrderBillNum } into temp1 - // from tm1 in temp1.DefaultIfEmpty() - // where tm1 == null - // select itm1; - var query = from itm1 in _lst - join itm2 in outPutDetail on - new { itm1.MaterialCode } - equals - new { itm2.MaterialCode } into temp1 - from tm1 in temp1.DefaultIfEmpty() - where tm1 == null - select itm1; - var _wmslst = query.ToList(); - foreach (var itm in _wmslst) - { - itm.BillNum = _billNum; + return await ExportErrorReportAsync(checkList); + } + + var query = from itm1 in _lst + join itm2 in outPutDetail on + new { itm1.MaterialCode } + equals + new { itm2.MaterialCode } into temp1 + from tm1 in temp1.DefaultIfEmpty() + where tm1 == null + select itm1; + var _wmslst = query.ToList(); + foreach (var itm in _wmslst) + { + itm.BillNum = _billNoNum; + } + await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); + int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNoNum); + if (_count == 0 && _wmslst.Count() > 0) + { + var _version = new WmsSharePartOutPut(GuidGenerator.Create(), version, _billNoNum, CurrentUser.Email); + await _wmsVersionRepository.InsertAsync(_version, true); + } } - await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); - int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNum); - if (_count == 0 && _wmslst.Count()>0) + + //有采购单号 + if (result_withbill != null) { - var _version = new WmsSharePartOutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email); - await _wmsVersionRepository.InsertAsync(_version, true); + var _billNum = "B" + DateTime.Now.ToString("yyyyMMddhhmmss"); + List _lst = new List(); + + var _lsCopy = new List(); + foreach (var itm in result_withbill) + { + WmsSharePartOutPutDetial _detail = new WmsSharePartOutPutDetial( + GuidGenerator.Create(), + itm.WmsBillNum, + itm.OrderBillNum, + itm.MaterialCode, + itm.MaterialDesc, + itm.MaterialGroup, + string.Empty, + string.Empty, + 0, + !string.IsNullOrEmpty(itm.Extend1) ? itm.Extend1 : string.Empty, + string.Empty, + version, + itm.ParentMaterialCode, + itm.BillNum, + GuidGenerator.Create() + , string.Empty + , itm.Qty + , 0 + , itm.Qty + , itm.Price + , itm.Amt + ); + _lsCopy.Add(_detail); + } + _lst.AddRange(_lsCopy.ToArray()); + + var outPutDetail = await _wmsRepository.Where(p => p.Version == version).ToListAsync(); + + + var error = from itm1 in outPutDetail + join itm2 in _lst on + new { itm1.MaterialCode, itm1.OrderBillNum, itm1.WmsBillNum } + equals + new { itm2.MaterialCode, itm2.OrderBillNum, itm2.WmsBillNum } + select itm1; + + + var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + + var checkList = new List(); + foreach (var itm in errList) + { + checkList.Add(new ErrorExportDto() { Message = string.Format("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number) }); + } + if (checkList.Count > 0) + { + + return await ExportErrorReportAsync(checkList); + } + + var query = from itm1 in _lst + join itm2 in outPutDetail on + new { itm1.MaterialCode, itm1.OrderBillNum } + equals + new { itm2.MaterialCode, itm2.OrderBillNum } into temp1 + from tm1 in temp1.DefaultIfEmpty() + where tm1 == null + select itm1; + var _wmslst = query.ToList(); + foreach (var itm in _wmslst) + { + itm.BillNum = _billNum; + } + await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); + int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNum); + if (_count == 0 && _wmslst.Count() > 0) + { + var _version = new WmsSharePartOutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email); + await _wmsVersionRepository.InsertAsync(_version, true); + } } + return ApplicationConsts.SuccessStr; } + //[HttpPost] + //[Route("ExcelImport")] + //[DisableRequestSizeLimit] + ////[Authorize(SettleAccountPermissions.SettleAccounts.Default)] + //public async Task ExcelImport([FromForm] IFormFileCollection files, string version) + //{ + // var _billNum = "B" + DateTime.Now.ToString("yyyyMMddhhmmss"); + // ExportImporter _exportImporter = new ExportImporter(); + // var result = await _exportImporter.ExtendExcelImport(files, _excelImportService); - /// - /// 导出 - /// - /// - /// - [HttpPost] - [Route("Export")] - //[Authorize(SettleAccountPermissions.SettleAccounts.Default)] - virtual public async Task ExportAsync(WmsKanbanOutPutDetialRequestDto input) - { - input.Filters.Add(new FilterCondition() { Action = EnumFilterAction.Equal, Column = "BillNum", Logic = EnumFilterLogic.And, Value = input.BillNum }); - var entities = await _wmsRepository.GetListByFilterAsync(GuidGenerator.Create(), input.Filters, input.Sorting, int.MaxValue, - 0, true); + // //if (result == null) + // //{ + // // throw new BusinessException("导入的模板中没有数据,不能为空,请检查!"); + // //} - IExporter _excel = new ExcelExporter(); - byte[] result = null; + // //var result_withbill = result.Select(p => p.BillNum != string.Empty).ToList(); + // //var result_nobill = result.Select(p => p.BillNum == string.Empty).ToList(); - var _fileName = string.Format("出库单_{0}.xlsx", Guid.NewGuid().ToString()); - result = await _excel.ExportAsByteArray(entities); + // List _lst = new List(); + // var _lsCopy = new List(); + // foreach (var itm in result) + // { + // WmsSharePartOutPutDetial _detail = new WmsSharePartOutPutDetial( + // GuidGenerator.Create(), + // //itm.WmsBillNum, + // //itm.OrderBillNum, + // string.Empty, + // string.Empty, + // itm.MaterialCode, + // itm.MaterialDesc, + // itm.MaterialGroup, + // string.Empty, + // string.Empty, + // 0, + // !string.IsNullOrEmpty(itm.Extend1) ? itm.Extend1 : string.Empty, + // string.Empty, + // version, + // itm.ParentMaterialCode, + // itm.BillNum, + // GuidGenerator.Create() + // , string.Empty + // , itm.Qty + // , 0 + // , itm.Qty + // , itm.Price + // , itm.Amt + // ); + // _lsCopy.Add(_detail); + // } + // _lst.AddRange(_lsCopy.ToArray()); - result.ShouldNotBeNull(); + // //var _ls1 = _lst.Where(p => p.ParentMaterialCode == p.MaterialCode).ToList(); + // var outPutDetail = await _wmsRepository.Where(p => p.Version == version).ToListAsync(); - //保存导出文件到服务器存成二进制 - await _excelImportService.SaveBlobAsync( - new SaveExcelImportInputDto - { - Name = _fileName, - Content = result - } - ); - return _fileName; + // //var error = from itm1 in outPutDetail + // // join itm2 in _ls1 on + // // new { itm1.MaterialCode, itm1.OrderBillNum,itm1.WmsBillNum } + // // equals + // // new { itm2.MaterialCode, itm2.OrderBillNum,itm2.WmsBillNum } + // // select itm1; + // var error = from itm1 in outPutDetail + // join itm2 in _lst on + // new { itm1.MaterialCode } + // equals + // new { itm2.MaterialCode } + // select itm1; - } + // var errList = error.GroupBy(p => new { p.BillNum }).Select(p => new { BillNum = p.Key.BillNum, Number = p.Sum(itm => itm.Qty) }); + + // var checkList = new List(); + // foreach (var itm in errList) + // { + // checkList.Add(new ErrorExportDto() { Message = string.Format("出库单号:{0}重复记录数:{1}条", itm.BillNum, itm.Number) }); + // } + // if (checkList.Count > 0) + // { + + // return await ExportErrorReportAsync(checkList); + // } + + // //var query = from itm1 in _ls1 + // // join itm2 in outPutDetail on + // // new { itm1.MaterialCode, itm1.OrderBillNum } + // // equals + // // new { itm2.MaterialCode, itm2.OrderBillNum } into temp1 + // // from tm1 in temp1.DefaultIfEmpty() + // // where tm1 == null + // // select itm1; + // var query = from itm1 in _lst + // join itm2 in outPutDetail on + // new { itm1.MaterialCode } + // equals + // new { itm2.MaterialCode } into temp1 + // from tm1 in temp1.DefaultIfEmpty() + // where tm1 == null + // select itm1; + // var _wmslst = query.ToList(); + // foreach (var itm in _wmslst) + // { + // itm.BillNum = _billNum; + // } + // await _wmsRepository.GetDbContext().BulkInsertAsync(_wmslst, new BulkConfig() { BulkCopyTimeout = 0, BatchSize = 10000 }); + // int _count = _wmsVersionRepository.Count(p => p.Version == version && p.BillNum == _billNum); + // if (_count == 0 && _wmslst.Count() > 0) + // { + // var _version = new WmsSharePartOutPut(GuidGenerator.Create(), version, _billNum, CurrentUser.Email); + // await _wmsVersionRepository.InsertAsync(_version, true); + // } + // return ApplicationConsts.SuccessStr; + //} } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml b/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml index 289b673a..e281402b 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml @@ -2347,6 +2347,14 @@ + + + 选择任务,生成出库单,只包含已确认的单据 + + + + + 出库界面功能, 撤销核准出库 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 64bf6cd0..497f56f0 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 @@ -23,7 +23,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report /// - /// 带采购订单号和无订单号一起统计报表 + /// 带采购订单号和无订单号一起统计报表 WHERE Extend != 'is90' /// /// /// @@ -85,7 +85,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report " PurchaseOrderNoText,\n" + " AmountNoTax \n" + " FROM\n" + - " Set_SparePart WHERE Extend != 'is90' \n" + + " Set_SparePart WHERE Extend != 'is90' \n" + " GROUP BY\n" + " PurchaseOrderNo,\n" + " MaterialCode,\n" +