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 1559a11a..0c3076d6 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/Reports/ReportServices/ReportMakeService.cs @@ -55,10 +55,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices ISettleAccountBranchEfCoreRepository settlementPartVersionrepository, ISettleAccountBranchEfCoreRepository fisVersionrepository, ISettleAccountBranchEfCoreRepository itemInvoicePriceVersionrepository, - //ISettleAccountBranchEfCoreRepository materialRepository, - //ISettleAccountBranchEfCoreRepository repository, - //ISettleAccountBranchEfCoreRepository versionRepository, - //IDistributedCache cache, + IExcelImportAppService excelImportService, //ISnowflakeIdGenerator snowflakeIdGenerator, //ICommonManager commonManager, @@ -197,7 +194,7 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices /// - /// 导入功能 + /// 1.大众发票与结算核对汇总表 /// /// 上传的文件(前端已经限制只能上传一个附件) /// @@ -225,14 +222,14 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices customConditionList.Add(new CustomCondition() { Name = "ProjectName", Value = "结算与开票数据对比" }); customConditionList.Add(new CustomCondition() { Name = "Year", Value = year ?? DateTime.Now.Year.ToString() }); - var _taskid = await _service.ExportEnqueueAsync("结算与开票数据对比", ExportExtentsion.Excel, CurrentUser, typeof(InvoiceSettledDiffExportService), customConditionList, (rs) => + var _taskid = await _service.ExportEnqueueAsync("大众发票与结算核对汇总表", ExportExtentsion.Excel, CurrentUser, typeof(InvoiceSettledDiffExportService), customConditionList, (rs) => { }); return _taskid; } /// - /// 导入功能 + /// 3.大众准时化结算数量差异比对表 /// /// 上传的文件(前端已经限制只能上传一个附件) /// @@ -254,9 +251,34 @@ namespace Win.Sfs.SettleAccount.Reports.ReportServices } + /// + ///6.大众准时化未结差异比对表 + /// + /// 上传的文件(前端已经限制只能上传一个附件) + /// + [HttpGet] + [Route("UnSettleDiffExport-Make")] + [DisableRequestSizeLimit] + + public async Task UnSettleDiffExportServiceMake(string version, string materialCode, string begin, string end) + { + List customConditionList = new List(); + customConditionList.Add(new CustomCondition() { Name = "Version", Value = version }); + customConditionList.Add(new CustomCondition() { Name = "MaterialCode", Value = materialCode }); + customConditionList.Add(new CustomCondition() { Name = "BeginTime", Value = begin }); + customConditionList.Add(new CustomCondition() { Name = "EndTime", Value = end }); + var _taskid = await _service.ExportEnqueueAsync("大众准时化未结差异比对表", ExportExtentsion.Excel, CurrentUser, typeof(UnSettleDiffExportService), customConditionList, (rs) => + { + }); + return _taskid; + } + + + + diff --git a/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml b/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml index c5652139..808ef9d6 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml +++ b/src/Modules/SettleAccount/src/SettleAccount.Application/SettleAccount.Application.xml @@ -2289,18 +2289,25 @@ - 导入功能 + 1.大众发票与结算核对汇总表 上传的文件(前端已经限制只能上传一个附件) - 导入功能 + 3.大众准时化结算数量差异比对表 上传的文件(前端已经限制只能上传一个附件) + + + 6.大众准时化未结差异比对表 + + 上传的文件(前端已经限制只能上传一个附件) + + 结算总成和ERP总成价格对比 diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs index d5868c57..e3e108ad 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/SettleAccountEntityBase.cs @@ -3,9 +3,18 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Win.Sfs.SettleAccount.Entities.Materials; +using Win.Sfs.SettleAccount.Entities.Prices; namespace Win.Sfs.SettleAccount.Entities { + + public class CacheManager + { + public static List CacheMaterials { set; get; } + public static List CachePriceList { set; get; } + } + public interface ISettleAccountEntityBase { public string Version { set; get; } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs index 915baa30..f9913a45 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/UnSettle/UnSettleDetailReport.cs @@ -12,14 +12,11 @@ namespace Win.Sfs.SettleAccount.Entities.UnSettle { [ExporterHeader(DisplayName = "结算平台未结数量 ")] public decimal Qty { set; get; } - [ExporterHeader(DisplayName = "定价 ")] - public decimal Price { set; get; } - [ExporterHeader(DisplayName = "金额 ")] - public decimal Amt { set; get; } + [ExporterHeader(DisplayName = "漏结标识 ")] public string Flag { set; get; } [ExporterHeader(DisplayName = "漏结期间 ")] - public string UNSettleVersion { set; get; } + public string UnSettleVersion { set; get; } [ExporterHeader(DisplayName = "说明 ")] public string Remark { set; get; } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs b/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs index 286b9e81..038609bd 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Domain/Reports/ReportDetailBase.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; namespace Win.Sfs.SettleAccount.Reports { + public class ReportDetailBase { [ExporterHeader(DisplayName = "交货单号 ")] @@ -17,7 +18,7 @@ namespace Win.Sfs.SettleAccount.Reports public string KENNCode { set; get; } [ExporterHeader(DisplayName = "底盘号")] public string ChassisNumber { set; get; } - [ExporterHeader(DisplayName = "M100交货状态 ")] + [ExporterHeader(DisplayName = "交货状态 ")] public string WmsState { set; get; } [ExporterHeader(DisplayName = "物料号")] public string SapMaterialCode { set; get; } @@ -26,13 +27,15 @@ namespace Win.Sfs.SettleAccount.Reports [ExporterHeader(DisplayName = "客户物料 ")] public string MaterialCode { set; get; } [ExporterHeader(DisplayName = "组件组物料 ")] - public string ParentMaterialCode { set; get; } + public string ParentSapMaterialCode { set; get; } [ExporterHeader(DisplayName = "组件组物料描述 ")] public string ParentMaterialDesc { set; get; } [ExporterHeader(DisplayName = "物料组(车型) ")] public string MaterialGroup { set; get; } - - + [ExporterHeader(DisplayName = "定价 ")] + public decimal Price { set; get; } + [ExporterHeader(DisplayName = "金额 ")] + public decimal Amt { set; get; } } diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpPartDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpPartDapperRepository.cs new file mode 100644 index 00000000..2c73e30a --- /dev/null +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/ErpPartDapperRepository.cs @@ -0,0 +1,85 @@ +using Dapper; +using Magicodes.ExporterAndImporter.Core; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; +using Volo.Abp.Domain.Repositories.Dapper; +using Volo.Abp.EntityFrameworkCore; +using Win.Sfs.SettleAccount.Entities; +using Win.Sfs.SettleAccount.Entities.Materials; +using Win.Sfs.SettleAccount.Entities.Prices; +using Win.Sfs.SettleAccount.Reports; + +namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report +{ + + + /// + /// 主数据Dapper表 + /// + public class ErpPartDapperRepository : DapperRepository, ITransientDependency + { + public ErpPartDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + { + + } + + public virtual List GetDiffReport(List childList) where T : ReportDetailBase, new() + { + List _materialList = new List(); + List _priceList = new List(); + if (CacheManager.CacheMaterials != null) + { + _materialList = CacheManager.CacheMaterials; + } + else + { + _materialList = DbConnection.Query("select * from set_material").ToList(); + } + if (CacheManager.CachePriceList != null) + { + _priceList = CacheManager.CachePriceList; + } + else + { + _priceList = DbConnection.Query("select MaterialCode,Price from Set_PriceList where version=(select max(version) from set_Set_PriceListVersion)").ToList(); + } + + List _list = new List(); + foreach (var itm in childList) + { + var parentMaterial = new T(); + parentMaterial.WmsBillNum = itm.WmsBillNum; + parentMaterial.CP5Time = itm.CP5Time; + parentMaterial.KENNCode = itm.KENNCode; + parentMaterial.ChassisNumber = itm.ChassisNumber; + parentMaterial.WmsState = itm.WmsState; + parentMaterial.SapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.MaterialDesc = itm.ParentMaterialDesc; + parentMaterial.MaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentSapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentMaterialDesc = itm.ParentMaterialDesc; + + var _price = _priceList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_price != null) + { + parentMaterial.Price = _price.Price; + parentMaterial.Amt = _price.Price; + } + var _material = _materialList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_material != null) + { + parentMaterial.MaterialGroup = _material.EstimateTypeDesc; + + } + _list.Add(parentMaterial); + } + + return _list; + + } + } +} diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs index 4cb3f017..b46e903d 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/InvoiceSettledDiffDapperRepository.cs @@ -20,74 +20,117 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob public virtual List GetInvoiceSettledDiffReportList(string version,string year, string tablename ,string materialcode) { - //string str = string.Empty; - //str += " where 1=1 "; - ////if (!string.IsNullOrEmpty(year)) - ////{ - //// str += string.Format(" and year='{0}' ", year); - ////} - //if (!string.IsNullOrEmpty(version)) - //{ - // str += string.Format(" and version='{0}' ", version); - //} - - - //// string sqlString = "select "+ string.Format(" {0} as Version ,",version) + "a.MaterialCode,isnull(b.qty,0) InvoiceQty,isnull(c.qty,0) SettleQty, (isnull(b.qty,0)-isnull(c.qty,0)) as DiffQty from (\n" + - //// " select distinct MaterialCode from( \n"+ - ////"select distinct MaterialCode from Set_Invoice {0}\n" + - //// "union all\n" + - //// "select distinct MaterialCode from {1} {0}\n" + - //// ") temp \n"+ - //// ") as a\n" + - //// "left join\n" + - //// "\n" + - //// "(select SUM(QTY) qty,MaterialCode from Set_Invoice {0} GROUP BY MaterialCode) b on a.MaterialCode=b.MaterialCode\n" + - //// "\n" + - //// "left join\n" + - //// "(select SUM(QTY) qty,MaterialCode from {1} {0} GROUP BY MaterialCode) c on a.MaterialCode=c.MaterialCode"; + + + // string sqlString = + //"SELECT \n" + string.Format(" '{0}' as Version ,", version) + "\n" + + //" b.*,\n" + + //" ISnull(\n" + + //" c.Qty,\n" + + //" IsNull( d.qty, 0 )) SettleQty,\n" + + //"CASE\n" + + //" \n" + + //" WHEN e.Type = 'CP7报废' THEN\n" + + //" isnull( e.Qty, 0 ) ELSE 0 \n" + + //" END AS CP7ScrapQty,\n" + + //"CASE\n" + + //" \n" + + //" WHEN e.Type = '索赔' THEN\n" + + //" isnull( e.Qty, 0 ) ELSE 0 \n" + + //" END AS ClaimQty,\n" + + //" (\n" + + //" b.InvoiceQty - ISnull(\n" + + //" c.Qty,\n" + + //" IsNull( d.qty, 0 ))) DiffQty,\n" + + //" Isnull( f.Price, 0 ) SalePrice,\n" + + //" b.InvoicePrice - Isnull( f.Price, 0 ) DiffPrice,\n" + + //" '' AS SapMaterialCode \n" + + //"FROM\n" + + //" (\n" + + //" SELECT\n" + + //" Factory, MaterialCode,\n" + + //" SUM( QTY ) InvoiceQty,\n" + + //" sum( amt ) InvoiceAmt,\n" + + //" sum( amt )/ sum( Qty ) InvoicePrice \n" + + //" FROM\n" + + //" Set_Invoice \n" + + //" WHERE\n" + + //" version = '{0}' \n" + + //" GROUP BY\n" + + //" MaterialCode,Factory \n" + + //" ) b\n" + + //" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n" + + //" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n" + + //" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n" + + //" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode"; + string sqlString = -"SELECT \n" + string.Format(" '{0}' as Version ,", version) + "\n" + -" b.*,\n" + -" ISnull(\n" + -" c.Qty,\n" + -" IsNull( d.qty, 0 )) SettleQty,\n" + -"CASE\n" + -" \n" + -" WHEN e.Type = 'CP7报废' THEN\n" + -" isnull( e.Qty, 0 ) ELSE 0 \n" + -" END AS CP7ScrapQty,\n" + -"CASE\n" + -" \n" + -" WHEN e.Type = '索赔' THEN\n" + -" isnull( e.Qty, 0 ) ELSE 0 \n" + -" END AS ClaimQty,\n" + -" (\n" + -" b.InvoiceQty - ISnull(\n" + -" c.Qty,\n" + -" IsNull( d.qty, 0 ))) DiffQty,\n" + -" Isnull( f.Price, 0 ) SalePrice,\n" + -" b.InvoicePrice - Isnull( f.Price, 0 ) DiffPrice,\n" + -" '' AS SapMaterialCode \n" + + "SELECT\n" + +" temp1.*, temp1.InvoicePrice - Isnull( temp2.Price, 0 ) DiffPrice , \n" + +" temp2.Price SalePrice\n" + "FROM\n" + " (\n" + " SELECT\n" + -" Factory, MaterialCode,\n" + -" SUM( QTY ) InvoiceQty,\n" + -" sum( amt ) InvoiceAmt,\n" + -" sum( amt )/ sum( Qty ) InvoicePrice \n" + +string.Format(" '{0}' as Version ,", version)+"\n" + +" b.*,\n" + +" ISnull(\n" + +" c.Qty,\n" + +" IsNull( d.qty, 0 )) SettleQty,\n" + +" CASE\n" + +" \n" + +" WHEN e.Type = 'CP7报废' THEN\n" + +" isnull( e.Qty, 0 ) ELSE 0 \n" + +" END AS CP7ScrapQty,\n" + +" CASE\n" + +" \n" + +" WHEN e.Type = '索赔' THEN\n" + +" isnull( e.Qty, 0 ) ELSE 0 \n" + +" END AS ClaimQty,\n" + +" (\n" + +" b.InvoiceQty - ISnull(\n" + +" c.Qty,\n" + +" IsNull( d.qty, 0 ))) DiffQty,\n" + +//" Isnull( f.Price, 0 ) SalePrice,\n" + +//" b.InvoicePrice - Isnull( f.Price, 0 ) DiffPrice,\n" + +" g.MaterialCode AS SapMaterialCode,\n" + +" g.MaterialDesc AS MaterialDesc \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" Factory,\n" + +" MaterialCode,\n" + +" SUM( QTY ) InvoiceQty,\n" + +" sum( amt ) InvoiceAmt,\n" + +" sum( amt )/ sum( Qty ) InvoicePrice \n" + +" FROM\n" + +" Set_Invoice \n" + +" WHERE\n" + +" version = '{0}' \n" + +" GROUP BY\n" + +" MaterialCode,\n" + +" Factory \n" + +" ) b\n" + +" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n" + +" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n" + +" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n" + +//" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode\n" + +" LEFT JOIN Set_material g ON b.MaterialCode = g.CustomerPartCode \n" + +" ) temp1\n" + +" LEFT JOIN (\n" + +" SELECT\n" + +" Price,\n" + +" MaterialCode \n" + " FROM\n" + -" Set_Invoice \n" + +" Set_PriceList \n" + " WHERE\n" + -" version = '{0}' \n" + -" GROUP BY\n" + -" MaterialCode,Factory \n" + -" ) b\n" + -" LEFT JOIN ( SELECT SUM( QTY ) Qty, MaterialCode FROM Set_settle WHERE version = '{0}' GROUP BY MaterialCode ) c ON b.MaterialCode = c.MaterialCode\n" + -" LEFT JOIN ( SELECT SUM( QTY ) qty, MaterialCode FROM Set_KanbanSettle WHERE version = '{0}' GROUP BY MaterialCode ) d ON b.MaterialCode = d.MaterialCode\n" + -" LEFT JOIN ( SELECT * FROM Set_ScrapClaims WHERE version = '{0}' ) e ON b.MaterialCode = e.MaterialCode\n" + -" LEFT JOIN ( SELECT * FROM Set_PriceList WHERE version = '{0}' ) f ON b.MaterialCode = f.MaterialCode"; +" version =(\n" + +" SELECT\n" + +" max( version ) \n" + +" FROM\n" + +" Set_PriceListVersion \n" + +" )) temp2 ON temp1.SapMaterialCode = temp2.MaterialCode"; diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs index 1c611486..1153f1c3 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/SettleFisDiffDetailDapperRepository.cs @@ -46,6 +46,8 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report public string SapCode { set; get; } } + + [ExcelExporter(Name = "未结汇总", AutoFitAllColumn = true, MaxRowNumberOnASheet = 500000)] public class SettleFisDiffSum { diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs index 3a581541..26521d6f 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettleDiffDapperRepository.cs @@ -32,6 +32,9 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } + /// + /// 6.大众准时化未结差异比对表 + /// public class UnSettleDiffDapperRepository : DapperRepository, ITransientDependency { public UnSettleDiffDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) @@ -44,71 +47,125 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report string str1 = "where 1=1 "; - -string sql1 = "SELECT\n" + -" a.MaterialCode,\n" + -" a.KENNCode,\n" + -" a.ChassisNumber,\n" + -" a.qty unsettleQty,\n" + -" b.qty \n" + -" a.Cp5Time \n"+ - -"FROM\n" + -" Set_unsettle a\n" + -" LEFT JOIN (\n" + -" SELECT\n" + -" ItemCode,\n" + -" KENNCode,\n" + -" ChassisNumber2,\n" + -" sum( qty ) qty \n" + -" FROM\n" + -" Set_fis \n" + -" WHERE\n" + -" state = 0 \n" + -" OR state = 4 \n" + -" GROUP BY\n" + -" ItemCode,\n" + -" KENNCode,\n" + -" ChassisNumber2 \n" + -" ) b ON a.ChassisNumber = b.ChassisNumber2 \n" + -" AND a.MaterialCode = b.ItemCode \n" + -" AND a.KENNCode = b.KENNCode {0}"; - - - - string sql2 = - "SELECT\n" + - " a.*,\n" + - " b.Qty unsettleQty \n" + + string sql1 = "SELECT\n" + + " a.MaterialCode,\n" + + " a.KENNCode,\n" + + " a.ChassisNumber,\n" + + " a.qty UNSettleQty,\n" + + " b.qty,\n" + + " a.CP5A CP5Time,\n" + + " c.MaterialCode SapMaterialCode,\n" + + " c.MaterialDesc MaterialDesc,\n" + + " a.model Factory \n" + "FROM\n" + - " (\n" + + " Set_unsettle a\n" + + " LEFT JOIN (\n" + " SELECT\n" + - " WMSState,\n" + - " WMSBillNum,\n" + " ItemCode,\n" + " KENNCode,\n" + " ChassisNumber2,\n" + - " sum( qty ) qty,\n" + - " ErpMaterialCode,\n" + - " ChassisNumber \n" + + " sum( qty ) qty \n" + " FROM\n" + " Set_fis \n" + " WHERE\n" + " state = 0 \n" + + " OR state = 4 \n" + " GROUP BY\n" + " ItemCode,\n" + " KENNCode,\n" + " ChassisNumber2,\n" + - " WMSState,\n" + - " WMSBillNum,\n" + - " ErpMaterialCode,\n" + - " ChassisNumber \n" + - " Cp5Time \n" + - " ) a\n" + - " LEFT JOIN Set_unsettle b ON a.ChassisNumber2 = b.ChassisNumber \n" + - " AND b.MaterialCode = a.ItemCode \n" + - " AND a.KENNCode = b.KENNCode {0}"; + " Model \n" + + " ) b ON a.ChassisNumber = b.ChassisNumber2 \n" + + " AND a.MaterialCode = b.ItemCode \n" + + " AND a.KENNCode = b.KENNCode\n" + + " LEFT JOIN Set_material c ON a.MaterialCode = c.CustomerPartCode {0}"; + + + + string sql2 = + "SELECT\n" + +" t1.*,\n" + +" t1.Qty * T2.Price AMT,\n" + +" T2.Price,\n" + +" Qty -(\n" + +" ISNULL( UnSettleQty, 0 )) DiffQty,\n" + +" Qty -(\n" + +" ISNULL( UnSettleQty, 0 ))* isnull( t2.Price, 0 ) DiffPrice \n" + +"FROM\n" + +" (\n" + +" SELECT\n" + +" temp1.WMSState,\n" + +" temp1.WMSBillNum,\n" + +" temp1.MaterialCode,\n" + +" temp1.KENNCode,\n" + +" temp1.ChassisNumber2,\n" + +" temp1.Qty,\n" + +" temp1.ChassisNumber,\n" + +" temp1.CP5Time,\n" + +" temp1.UnSettleQty,\n" + +" temp1.SapMaterialCode,\n" + +" temp1.MaterialDesc,\n" + +" temp1.MaterialGroup,\n" + +" temp2.MaterialCode AS ParentSapMaterialCode,\n" + +" temp2.MaterialDesc AS ParentMaterialDesc \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" a.WMSState,\n" + +" a.WMSBillNum,\n" + +" a.MaterialCode,\n" + +" a.KENNCode,\n" + +" a.ChassisNumber2,\n" + +" a.Qty,\n" + +" a.ParentCode,\n" + +" a.ChassisNumber,\n" + +" a.CP5Time,\n" + +" b.Qty AS UnSettleQty,\n" + +" C.MaterialCode AS SapMaterialCode,\n" + +" C.MaterialDesc,\n" + +" C.EstimateTypeDesc AS MaterialGroup \n" + +" FROM\n" + +" (\n" + +" SELECT\n" + +" WMSState,\n" + +" WMSBillNum,\n" + +" ItemCode AS MaterialCode,\n" + +" KENNCode,\n" + +" ChassisNumber2,\n" + +" SUM( Qty ) AS Qty,\n" + +" ErpMaterialCode AS ParentCode,\n" + +" ChassisNumber,\n" + +" CP5Time \n" + +" FROM\n" + +" Set_fis \n" + +" WHERE\n" + +" ( State = 0 ) \n" + +" GROUP BY\n" + +" ItemCode,\n" + +" KENNCode,\n" + +" ChassisNumber2,\n" + +" WMSState,\n" + +" WMSBillNum,\n" + +" ErpMaterialCode,\n" + +" ChassisNumber,\n" + +" CP5Time \n" + +" ) AS a\n" + +" LEFT OUTER JOIN Set_Unsettle AS b ON a.ChassisNumber2 = b.ChassisNumber \n" + +" AND b.MaterialCode = a.MaterialCode \n" + +" AND a.KENNCode = b.KENNCode\n" + +" LEFT OUTER JOIN Set_material AS C ON a.MaterialCode = C.CustomerPartCode \n" + +" ) AS temp1\n" + +" LEFT OUTER JOIN Set_material AS temp2 ON temp1.ParentCode = temp2.CustomerPartCode \n" + +" ) t1\n" + +" LEFT JOIN (\n" + +" SELECT\n" + +" MaterialCode,\n" + +" Price \n" + +" FROM\n" + +" Set_PriceList \n" + +"WHERE\n" + +" version = ( SELECT max( version ) FROM Set_PriceListVersion )) t2 ON t1.MaterialCode = t2.MaterialCode"; string _sql = string.Empty; diff --git a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs index ff33ff8f..f80f2d31 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.EntityFrameworkCore/Repository/SettleAccountJob/Report/UnSettledDetailDapperRepository.cs @@ -11,18 +11,23 @@ using Dapper; using Win.Sfs.SettleAccount.FISes; using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report.ExportDto; using Win.Sfs.SettleAccount.Entities.UnSettle; +using Win.Sfs.SettleAccount.Entities.Materials; +using Win.Sfs.SettleAccount.Entities.Prices; namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report { + /// + /// 7.大众准时化未结明细表(包含漏结,漏结要有标识) + /// public class UnSettledDetailDapperRepository : DapperRepository, ITransientDependency { - //ERP总成开票报表 + public UnSettledDetailDapperRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } - public virtual List GetDiffReport(string year, string begin, string end, string customcode, string version,string materialCode,string materialGroup,string sapCode) + public virtual List GetDiffReport(string year, string begin, string end, string customcode, string version, string materialCode, string materialGroup, string sapCode) { string str = string.Empty; @@ -30,7 +35,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report if (!string.IsNullOrEmpty(begin)) { - str += string.Format(" and beginTime>'{0}' ",begin); + str += string.Format(" and beginTime>'{0}' ", begin); } if (!string.IsNullOrEmpty(end)) { @@ -38,81 +43,113 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report } if (!string.IsNullOrEmpty(materialCode)) { - str += string.Format(" and MaterialCode='{0}' ", materialCode); + str += string.Format(" and ItemCode='{0}' ", materialCode); } if (!string.IsNullOrEmpty(materialGroup)) { str += string.Format(" and MaterialGroup='{0}' ", materialGroup); } - if (!string.IsNullOrEmpty(sapCode)) - { - str += string.Format(" and MaterialGroup='{0}' ", materialGroup); - } + //if (!string.IsNullOrEmpty(sapCode)) + //{ + // str += string.Format(" and SapCode='{0}' ", materialGroup); + //} var sqlString = - " SELECT\n" + - " A.*,\n" + - " C.Price,\n" + - " ISNULL( A.QTY, 0 )* ISNULL( C.Price, 0 ) AMT \n" + - "FROM\n" + - " (\n" + - " SELECT DISTINCT\n" + - " '' WMSState,\n" + - " '' UnSettleVersion,\n" + - " '' WMSBillNum,\n" + - " BeginTime CP5Time,\n" + - " ErpMaterialCode MaterialCode,\n" + - " ChassisNumber,\n" + - " KENNCode,\n" + - " 1 QTY,\n" + - " ErpMaterialCode ParentMaterialCode,\n" + - " '' FLAG \n" + - " FROM\n" + - " Set_fis \n" + - " WHERE\n" + - " 1 = 1 \n" + - " AND STATE = 0 {0} UNION ALL\n" + - " SELECT\n" + - " WMSState,\n" + - " UnSettleVersion,\n" + - " WMSBillNum,\n" + - " BeginTime CP5Time,\n" + - " ItemCode MaterialCode,\n" + - " ChassisNumber,\n" + - " KENNCode,\n" + - " QTY,\n" + - " ErpMaterialCode,\n" + - " '' FLAG \n" + - " FROM\n" + - " [Set_fis] \n" + - " WHERE\n" + - " 1 = 1 \n" + - " AND STATE = 0 {0} UNION ALL\n" + - " SELECT\n" + - " WMSState,\n" + - " UnSettleVersion,\n" + - " WMSBillNum,\n" + - " BeginTime CP5Time,\n" + - " ItemCode MaterialCode,\n" + - " ChassisNumber,\n" + - " KENNCode,\n" + - " QTY,\n" + - " ErpMaterialCode,\n" + - " 'L' FLAG \n" + - " FROM\n" + - " [Set_fis] \n" + - " WHERE\n" + - " 1 = 1 \n" + - " AND STATE = 4 {0}\n" + - " ) A\n" + - " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) ) C ON a.MaterialCode = c.MaterialCode"; - - - - string _sql = string.Format(sqlString, version); + "SELECT\n" + + " A.*,\n" + + " C.Price,\n" + + " ISNULL( A.QTY, 0 )* ISNULL( C.Price, 0 ) AMT,\n" + + " B.EstimateTypeDesc MaterialGroup,\n" + + " B.MaterialDesc MaterialDesc,\n" + + " d.MaterialDesc ParentMaterialDesc \n" + + "FROM\n" + + " (\n" + + " SELECT\n" + + " WMSState,\n" + + " WMSBillNum,\n" + + " UnSettleVersion,\n" + + " BeginTime CP5Time,\n" + + " ItemCode MaterialCode,\n" + + " ChassisNumber,\n" + + " KENNCode,\n" + + " QTY,\n" + + " ErpMaterialCode ParentSapMaterialCode,\n" + + " '' FLAG \n" + + " FROM\n" + + " Set_fis {0} \n" + + " WHERE\n" + + " 1 = 1 \n" + + " AND STATE = 0 UNION ALL\n" + + " SELECT\n" + + " WMSState,\n" + + " UnSettleVersion,\n" + + " WMSBillNum,\n" + + " BeginTime CP5Time,\n" + + " ItemCode MaterialCode,\n" + + " ChassisNumber,\n" + + " KENNCode,\n" + + " QTY,\n" + + " ErpMaterialCode ParentSapMaterialCode,\n" + + " 'L' FLAG \n" + + " FROM\n" + + " Set_fis {0} \n" + + " WHERE\n" + + " 1 = 1 \n" + + " AND STATE = 4 \n" + + " ) A\n" + + " LEFT JOIN Set_material B ON a.MaterialCode = b.CustomerPartCode\n" + + " LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) ) C ON a.MaterialCode = c.MaterialCode\n" + + " LEFT JOIN Set_material d ON a.ParentSapMaterialCode = d.MaterialCode"; + + + + + + + + var _materialList = DbConnection.Query("select * from set_material").ToList(); + var _priceList = DbConnection.Query("select MaterialCode,Price from Set_PriceList where version=(select max(version) from set_Set_PriceListVersion)").ToList(); + + + + string _sql = string.Format(sqlString, str); ; var _query = DbConnection.Query(_sql); - return _query.ToList(); + + var _list = _query.ToList(); + var _ls = _list.Where(p=>p.Flag!="L").GroupBy(p => new { p.KENNCode, p.ChassisNumber, p.ParentSapMaterialCode }).Select(p => p.FirstOrDefault()).ToList(); + + foreach (var itm in _ls) + { + + var parentMaterial = new UnSettleDetailReport(); + parentMaterial.WmsBillNum = itm.WmsBillNum; + parentMaterial.CP5Time = itm.CP5Time; + parentMaterial.KENNCode = itm.KENNCode; + parentMaterial.ChassisNumber = itm.ChassisNumber; + parentMaterial.WmsState = itm.WmsState; + parentMaterial.SapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.MaterialDesc = itm.ParentMaterialDesc; + parentMaterial.MaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentSapMaterialCode = itm.ParentSapMaterialCode; + parentMaterial.ParentMaterialDesc = itm.ParentMaterialDesc; + + var _price=_priceList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_price != null) + { + parentMaterial.Price = _price.Price; + parentMaterial.Amt = _price.Price; + } + var _material=_materialList.Where(p => p.MaterialCode == itm.ParentSapMaterialCode).FirstOrDefault(); + if (_material != null) + { + parentMaterial.MaterialGroup = _material.EstimateTypeDesc; + + } + _list.Add(parentMaterial); + } + + return _list; } } } diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs index 3881f5ed..e5d6f65f 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/OutputService.cs @@ -57,8 +57,26 @@ namespace SettleAccount.Job.Services _taskjobRepository.UpdateTaskJob(Id, _task); //保存导出文件到服务器存成二进制 } + public void Export(Guid Id, string fileName, List p_list, List p_list1) where T1 : class, new() + where T2: class, new() + { + ExcelExporter _exporter = new ExcelExporter();//导出Excel + + var result = _exporter + .Append(p_list, "sheet1") + .SeparateBySheet() + .Append(p_list1) + .ExportAppendDataAsByteArray(); + + + + result.ShouldNotBeNull(); + _fileContainer.SaveAsync(fileName, result.Result, true); + var _task = new Win.Sfs.SettleAccount.Entities.TaskJob() { DownFileName = fileName }; + _taskjobRepository.UpdateTaskJob(Id, _task); + //保存导出文件到服务器存成二进制 + } - diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs index 76951a32..099b2b5f 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/InvoiceSettledDiffExportService.cs @@ -70,8 +70,12 @@ namespace SettleAccount.Job.Services SalePrice =itm. SalePrice , DiffPrice =itm. DiffPrice , SapMaterialCode =itm.SapMaterialCode , - Factory = itm.Factory - + MaterialDesc=itm.MaterialDesc, + + + Factory = itm.Factory, + + diff --git a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs index c2fd9c20..d223b3ce 100644 --- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs +++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleFisDiffExportService.cs @@ -1,5 +1,8 @@ -using System; +using NPOI.SS.UserModel; +using NPOI.XSSF.UserModel; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,12 +15,18 @@ using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; namespace SettleAccount.Job.Services.Report { + /// + /// 3.大众准时化结算数量差异比对表 + /// public class SettleFisDiffExportService : ITransientDependency, IExportJob { private readonly SettleFisDiffDetailDapperRepository _dapper; private readonly OutputService _outputService; + + + public SettleFisDiffExportService(SettleFisDiffDetailDapperRepository dapper, OutputService outputService) { _dapper = dapper; @@ -33,7 +42,7 @@ namespace SettleAccount.Job.Services.Report var end = p_list.Where(p => p.Name == "EndTime").FirstOrDefault().Value; var _list= _dapper.GetReportList(version, materialCode, begin,end); - _list.GroupBy(p => new { p.MaterialCode,p.SapCode }).Select(p =>new SettleFisDiffSum + var _ls= _list.GroupBy(p => new { p.MaterialCode,p.SapCode }).Select(p =>new SettleFisDiffSum { MaterialCode= p.Key.MaterialCode, @@ -46,18 +55,132 @@ namespace SettleAccount.Job.Services.Report }); + //_outputService.Export(id, string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()),_list.ToList(),_ls.ToList()); + _outputService.Export(id, string.Format("大众准时化结算数量合计_{0}.xlsx", Guid.NewGuid().ToString()), _ls.ToList()); - - - + _outputService.Export(id,string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()), _list); + return id.ToString(); + } + /// + /// 将数个Excel文件中的第一个工作表合并至一个Excel文件中 + /// + /// 需要合并的数个Excel文件路径 + /// 合并成的一个Excel文件路径 + private void MergeExcels(string[] excelFilePaths, string desFilePath) + { + XSSFWorkbook mergeWorkBook = new XSSFWorkbook(); + for (int i = 0; i < excelFilePaths.Length; i++) + { + if (File.Exists(excelFilePaths[i])) + { + using (FileStream fs = new FileStream(excelFilePaths[i], FileMode.Open, FileAccess.Read, FileShare.Write)) + { + XSSFWorkbook tmpWorkBook = new XSSFWorkbook(fs); + XSSFSheet tmpSheet = tmpWorkBook.GetSheetAt(0) as XSSFSheet; + if (excelFilePaths[i].Contains("当月结算表")) + { + IRow row = null; + for (int j = 2; j < tmpSheet.PhysicalNumberOfRows && tmpSheet.GetRow(j) != null; j++)/*j=1 从索引的第一行开始过滤掉表头*/ + { + row = tmpSheet.GetRow(j); + try + { + if (!string.IsNullOrWhiteSpace(row.GetCell(1).ToString()))/*验证数值非空*/ + { + //cell.CSS("color:red;font-weight:bold;font-size:11;font-name:宋体;border-type:thin;") + /*修改样式关键代码*/ + ICellStyle style = tmpWorkBook.CreateCellStyle(); + style.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Orange.Index; + style.FillPattern = FillPattern.SolidForeground; + style.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Orange.Index; + + style.BorderTop = BorderStyle.Thin;//上 + style.BorderBottom = BorderStyle.Thin;//下 + style.BorderLeft = BorderStyle.Thin;//左 + style.BorderRight = BorderStyle.Thin;//右 + style.VerticalAlignment = VerticalAlignment.Center; + style.Alignment = HorizontalAlignment.Center; + + IFont font = tmpWorkBook.CreateFont(); + font.FontHeightInPoints = 10; // 字体大小 直接对应Excel中的字体大小 + font.FontName = "宋体"; //跟Excel中的字体值一样,直接写对应的名称即可 + font.IsBold = true;//加粗 + style.SetFont(font); + /*修改指定单元格样式 如果要修改行样式则需要将row.Cells.Count循环出来,挨个设置!*/ + for (int g = 0; g < row.Cells.Count; g++) + { + row.Cells[g].CellStyle = style; + } + row.RowStyle = style; + + if (row.GetCell(1).ToString() == "核算表不存在") + { + ICellStyle style1 = tmpWorkBook.CreateCellStyle(); + style1.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index; + style1.FillPattern = FillPattern.SolidForeground; + style1.FillBackgroundColor = NPOI.HSSF.Util.HSSFColor.Yellow.Index; + + style1.BorderTop = BorderStyle.Thin;//上 + style1.BorderBottom = BorderStyle.Thin;//下 + style1.BorderLeft = BorderStyle.Thin;//左 + style1.BorderRight = BorderStyle.Thin;//右 + style1.VerticalAlignment = VerticalAlignment.Center; + style1.Alignment = HorizontalAlignment.Center; + IFont font1 = tmpWorkBook.CreateFont(); + font1.FontHeightInPoints = 10; // 字体大小 直接对应Excel中的字体大小 + font1.FontName = "宋体"; //跟Excel中的字体值一样,直接写对应的名称即可 + font1.IsBold = true;//加粗 + font1.Color = NPOI.HSSF.Util.HSSFColor.White.Index; + style1.SetFont(font); + //style.fon + //HSSFFont font = workbookAll.CreateFont(); + //font.FontHeightInPoints = 9; // 字体大小 直接对应Excel中的字体大小 + //font.FontName = "宋体"; //跟Excel中的字体值一样,直接写对应的名称即可 + //font.Boldweight = HSSFFont.BOLDWEIGHT_BOLD;//加粗 + //style.SetFont(font); + + + /*修改指定单元格样式 如果要修改行样式则需要将row.Cells.Count循环出来,挨个设置!*/ + for (int g = 0; g < row.Cells.Count; g++) + { + row.Cells[g].CellStyle = style1; + } + row.RowStyle = style1; + + } + /*重新修改文件指定单元格样式*/ + } + } + catch + { } + } + } + tmpSheet.CopyTo(mergeWorkBook, Path.GetFileNameWithoutExtension(excelFilePaths[i]), true, true); + } + } + /* 考虑数据量,此处可以限制最多可以合并工作表的数量 */ + //if (mergeWorkBook.NumberOfSheets >= 200) + //{ + // break; + //} + } + if (mergeWorkBook.NumberOfSheets != 0) + { + FileStream fsDesFile = new FileStream(desFilePath, FileMode.OpenOrCreate, FileAccess.Write); + mergeWorkBook.Write(fsDesFile); + fsDesFile.Close(); + mergeWorkBook.Close(); + } + else + { + mergeWorkBook.Close(); + } + } - _outputService.Export(id,string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()), _list); - return id.ToString(); - } } }