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 f5f22be1..64bf6cd0 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
@@ -85,7 +85,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" +
@@ -194,7 +194,7 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
}
///
- /// 有发货无结算的报表统计
+ /// 有结算无发货的报表统计
///
///
///
@@ -203,53 +203,114 @@ namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report
///
///
///
- public virtual List GetUnSettleSparePart90ReportList(string purchaseOrderNo, string version, string sapCode, string matialCode,
+ public virtual List GetForwardSettleSparePartReportList(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.PurchaseOrderNo AS 采购订单号,\n" +
- " a.WMSDeliveryNote AS 交货单号,\n" +
- " a.SpareDate AS 交货日期,\n" +
- " a.MaterialCode AS 物料代码,\n" +
- " ISNULL( a.ReceiptQty, 0 ) AS 发货数量,\n" +
- " c.MaterialCode AS SAP编码,\n" +
- " c.MaterialDesc AS 物料描述,\n" +
- " c.EstimateTypeDesc AS 物料组,\n" +
- " b.Version AS 期间,\n" +
- " b.PurchaseOrderNoText AS 采购订单文本,\n" +
- " b.PurchasePriceNoTax AS 开票单价,\n" +
- " 0 AS 数量差异,\n" +
- " ISNULL( b.InvoicedQty, 0 ) AS 开票数量 ,\n" +
- " 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 OUTER JOIN Set_material AS c ON a.MaterialCode = c.CustomerPartCode \n" +
- " WHERE\n" +
- " b.PurchaseOrderNo IS NULL \n" +
- " ) AS temp1\n" +
- " LEFT OUTER JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE ( Version = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode \n" +
- "ORDER BY\n" +
- " temp1.采购订单号";
+ " 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 = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) 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 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, 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" +
+ " 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 = ( SELECT MAX ( Version ) AS Expr1 FROM Set_PriceList ) ) ) AS TEMP2 ON temp1.SAP编码 = TEMP2.MaterialCode";
string addwhere = string.Empty;
string addSqlStr = string.Format(sqlString, version);
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 40d12e55..71e1ab99 100644
--- a/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePartExportService.cs
+++ b/src/Modules/SettleAccount/src/SettleAccount.Job/Services/Report/SettleSparePartExportService.cs
@@ -1,11 +1,15 @@
-using System;
+using Magicodes.ExporterAndImporter.Excel;
+using Shouldly;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TaskJob.EventArgs;
using TaskJob.Interfaces;
+using Volo.Abp.BlobStoring;
using Volo.Abp.DependencyInjection;
+using Win.Sfs.BaseData.ImportExcelCommon;
using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report;
namespace SettleAccount.Job.Services.Report
@@ -15,12 +19,16 @@ namespace SettleAccount.Job.Services.Report
private readonly SettleSparePartDapperReportRepository _dapper;
private readonly OutputService _outputService;
private readonly ErpPartDapperRepository _erpdapperRepository;
+ private readonly IBlobContainer _fileContainer;
- public SettleSparePartExportService(SettleSparePartDapperReportRepository dapper, ErpPartDapperRepository erpdapperRepository, OutputService outputService)
+
+ public SettleSparePartExportService(SettleSparePartDapperReportRepository dapper, ErpPartDapperRepository erpdapperRepository, OutputService outputService
+ , IBlobContainer fileContainer)
{
_dapper = dapper;
_outputService = outputService;
_erpdapperRepository = erpdapperRepository;
+ _fileContainer = fileContainer;
}
@@ -33,8 +41,16 @@ 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 _ls = _dapper.GetSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime);
+ //正向对比,有结算无发货
+ var _forwardls = _dapper.GetForwardSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime);
+
+ //反向对比,有发货无结算
+ var _reversels = _dapper.GetReverseSettleSparePartReportList(purchaseOrderNo, version, sapCode, matialCode, beginTime, endTime);
+
//var diffList = _dapper.GetSettleSparePartSumQtyDiff(version);
//if (diffList != null)
@@ -46,7 +62,7 @@ namespace SettleAccount.Job.Services.Report
// {
// _first.开票数量 = _first.发货数量 + itm.数量差异;//开票数量(结算数量+差异)
// _first.数量差异 = itm.数量差异;
-
+
// }
// }
//}
@@ -68,14 +84,14 @@ namespace SettleAccount.Job.Services.Report
_ls = _ls.Where(p => _groupList.Contains(p.SAP编码)).ToList();
}
}
- if (!string.IsNullOrEmpty(matialCode))
- {
- var _groupList = matialCode.Split(new char[] { '\n' }).Distinct().ToList();
- if (_groupList.Count() > 0)
- {
- _ls = _ls.Where(p => _groupList.Contains(p.物料代码)).ToList();
- }
- }
+ //if (!string.IsNullOrEmpty(matialCode))
+ //{
+ // var _groupList = matialCode.Split(new char[] { '\n' }).Distinct().ToList();
+ // if (_groupList.Count() > 0)
+ // {
+ // _ls = _ls.Where(p => _groupList.Contains(p.物料代码)).ToList();
+ // }
+ //}
if (!string.IsNullOrEmpty(purchaseOrderNo))
{
var _groupList = purchaseOrderNo.Split(new char[] { '\n' }).Distinct().ToList();
@@ -89,11 +105,19 @@ namespace SettleAccount.Job.Services.Report
+ // _outputService.Export(id, fileName, _ls);
+ ExcelExporter _exporter = new ExcelExporter();//导出Excel
+ var result = _exporter.Append(_ls.ToList(), "大众备件数据输出")
+ .SeparateBySheet()
+ .Append(_forwardls.ToList(), "有结算无发货对比")
+ .SeparateBySheet()
+ .Append(_reversels.ToList(),"有发货无结算对比")
+ .ExportAppendDataAsByteArray();
+ result.ShouldNotBeNull();
+ _fileContainer.SaveAsync(fileName, result.Result, true);
- _outputService.Export(id, fileName, _ls);
-
return id.ToString();
}