Administrator
3 years ago
17 changed files with 22435 additions and 138 deletions
File diff suppressed because it is too large
File diff suppressed because it is too large
@ -0,0 +1,116 @@ |
|||||
|
using Dapper; |
||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
using Magicodes.ExporterAndImporter.Excel; |
||||
|
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.Reports; |
||||
|
|
||||
|
namespace Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report |
||||
|
{ |
||||
|
|
||||
|
|
||||
|
/// <summary>
|
||||
|
///3.大众准时化结算数量差异比对表
|
||||
|
/// </summary>
|
||||
|
public class UnInvoiceSettledDetailDiffDapperRepository : DapperRepository<SettleAccountDbContext>, ITransientDependency |
||||
|
{ |
||||
|
public UnInvoiceSettledDetailDiffDapperRepository(IDbContextProvider<SettleAccountDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
public virtual List<InvoiceSettledDetailDiff> GetDetailDiffReportList(string version, string materialCode, string begin, string end ,string cp7begin,string cp7end,string kennCode,string chassisNumber) |
||||
|
{ |
||||
|
|
||||
|
List<InvoiceSettledDetailDiff> _list = new List<InvoiceSettledDetailDiff>(); |
||||
|
|
||||
|
string condition = " where 1=1 "; |
||||
|
|
||||
|
|
||||
|
if (!string.IsNullOrEmpty(materialCode)) |
||||
|
{ |
||||
|
condition += string.Format(" d.MaterialCode='{0}' ", materialCode); |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(begin)) |
||||
|
{ |
||||
|
condition += string.Format(" a.BeginTime>='{0}' ", begin); |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(end)) |
||||
|
{ |
||||
|
condition += string.Format(" a.BeginTime<='{0}' ", end); |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(cp7begin)) |
||||
|
{ |
||||
|
condition += string.Format(" B.cp7Time>='{0}' ", cp7begin); |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(cp7end)) |
||||
|
{ |
||||
|
condition += string.Format(" B.cp7Time<='{0}' ", cp7end); |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(kennCode)) |
||||
|
{ |
||||
|
condition += string.Format(" B.kenncode='{0}' ", kennCode); |
||||
|
} |
||||
|
if (!string.IsNullOrEmpty(chassisNumber)) |
||||
|
{ |
||||
|
condition += string.Format(" B.chassisNumber='{0}' ", chassisNumber); |
||||
|
} |
||||
|
|
||||
|
string str = |
||||
|
"SELECT\n" + |
||||
|
" temp1.*,\n" + |
||||
|
" TEMP2.Price,(\n" + |
||||
|
" Isnull( temp2.Price, 0 ) * isnull( temp1.SettledQty, 0 )) Amt \n" + |
||||
|
"FROM\n" + |
||||
|
" (\n" + |
||||
|
" SELECT\n" + |
||||
|
" a.YEAR,\n" + |
||||
|
" a.Kenncode,\n" + |
||||
|
" a.MaterialCode,\n" + |
||||
|
" a.Model,\n" + |
||||
|
" a.ChassisNumber,\n" + |
||||
|
" isnull( b.Qty, 0 ) Qty,\n" + |
||||
|
" a.CP5A CP5Time,\n" + |
||||
|
" a.CP7 CP7Time,\n" + |
||||
|
" a.QTY SettledQty,\n" + |
||||
|
" '' ParentSapMaterialCode,\n" + |
||||
|
" '' WMSState,\n" + |
||||
|
" '' WMSBillNum,\n" + |
||||
|
" d.MaterialCode SapMaterialCode,\n" + |
||||
|
" d.MaterialDesc MaterialDesc,\n" + |
||||
|
" d.EstimateTypeDesc MaterialGroup,\n" + |
||||
|
" '' ParentMaterialDesc,\n" + |
||||
|
" c.InvoicePrice,\n" + |
||||
|
" ( c.InvoicePrice * a.qty ) InvoiceAmt,\n" + |
||||
|
" ( c.InvoicePrice * a.Qty ) SettleAmt,\n" + |
||||
|
" a.Qty - IsNull( B.Qty, 0 ) DiffSettleFisQty,\n" + |
||||
|
" 0 DiffSettleInvQty,\n" + |
||||
|
" a.Qty InvoiceQty \n" + |
||||
|
" FROM\n" + |
||||
|
" ( SELECT * FROM set_settle WHERE version = '202110' ) a\n" + |
||||
|
" LEFT JOIN Set_fis b ON a.ChassisNumber = b.ChassisNumber2 \n" + |
||||
|
" AND a.KENNCode = b.KENNCode \n" + |
||||
|
" AND a.MaterialCode = b.ItemCode\n" + |
||||
|
" LEFT JOIN ( SELECT SUM( amt )/ SUM( Qty ) InvoicePrice, MaterialCode FROM set_invoice WHERE version = '202110' GROUP BY materialcode ) c ON a.MaterialCode = c.MaterialCode\n" + |
||||
|
" LEFT JOIN set_material d ON a.MaterialCode = d.CustomerPartCode \n" + |
||||
|
" WHERE\n" + |
||||
|
" b.Qty IS NULL \n" + |
||||
|
" ) temp1\n" + |
||||
|
" LEFT JOIN ( SELECT Price, MaterialCode FROM Set_PriceList WHERE version = ( SELECT Max( Version ) FROM Set_PriceList ) AND type = 10 ) TEMP2 ON TEMP1.SapMaterialCode = TEMP2.MaterialCode"; |
||||
|
var _sql = string.Format(str, version,condition); |
||||
|
|
||||
|
var _query = DbConnection.Query<InvoiceSettledDetailDiff>(_sql, null, null, true, 1200, null); |
||||
|
_list=_query.ToList(); |
||||
|
|
||||
|
|
||||
|
return _list; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
@ -0,0 +1,139 @@ |
|||||
|
using Magicodes.ExporterAndImporter.Core; |
||||
|
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.Reports.InvoiceSettledDiffs; |
||||
|
using Win.Sfs.SettleAccount.Repository.SettleAccount; |
||||
|
using Win.Sfs.SettleAccount.Repository.SettleAccountJob; |
||||
|
using Win.Sfs.SettleAccount.Repository.SettleAccountJob.Report; |
||||
|
|
||||
|
namespace SettleAccount.Job.Services |
||||
|
{ |
||||
|
//物料组车型 SAP编码 零件号 结算数量 M100数量 差异总数 开票单价 差异金额
|
||||
|
public class UnInvoiceSettledDetailSum |
||||
|
{ |
||||
|
[ExporterHeader(DisplayName = "物料组车型")] |
||||
|
public string MaterialGroup { set; get;} |
||||
|
[ExporterHeader(DisplayName = "SAP编码")] |
||||
|
public string SapMaterailCode { set; get; } |
||||
|
[ExporterHeader(DisplayName = "零件号")] |
||||
|
public string MaterialCode { set; get; } |
||||
|
[ExporterHeader(DisplayName = "结算数量")] |
||||
|
public decimal SettleQty { set; get; } |
||||
|
[ExporterHeader(DisplayName = "M100数量")] |
||||
|
public decimal FisQty { set; get; } |
||||
|
[ExporterHeader(DisplayName = "差异总数")] |
||||
|
public decimal DiffQty { set; get; } |
||||
|
[ExporterHeader(DisplayName = "开票单价")] |
||||
|
public decimal Price { set; get; } |
||||
|
[ExporterHeader(DisplayName = "差异金额")] |
||||
|
public decimal DiffAmt { set; get; } |
||||
|
} |
||||
|
/// <summary>
|
||||
|
///3.大众准时化结算数量差异比对表
|
||||
|
/// </summary>
|
||||
|
public class UnInvoiceSettledDetailDiffExportService : ITransientDependency, IExportJob |
||||
|
{ |
||||
|
|
||||
|
private readonly UnInvoiceSettledDetailDiffDapperRepository _dapperRepository; |
||||
|
private readonly ErpPartDapperRepository _erpdapperRepository; |
||||
|
|
||||
|
private readonly IBlobContainer<MyFileContainer> _fileContainer; |
||||
|
|
||||
|
|
||||
|
private readonly OutputService _outputService; |
||||
|
private readonly InputService _inputService; |
||||
|
public UnInvoiceSettledDetailDiffExportService( |
||||
|
IBlobContainer<MyFileContainer> fileContainer, |
||||
|
ErpPartDapperRepository erpdapperRepository, |
||||
|
UnInvoiceSettledDetailDiffDapperRepository dapperRepository, |
||||
|
OutputService outputService, |
||||
|
InputService inputService |
||||
|
) |
||||
|
{ |
||||
|
_fileContainer = fileContainer; |
||||
|
_inputService = inputService; |
||||
|
_outputService = outputService; |
||||
|
_erpdapperRepository= erpdapperRepository; |
||||
|
//_repository = repository;
|
||||
|
//_versionRepository = versionRepository;
|
||||
|
_dapperRepository =dapperRepository; |
||||
|
} |
||||
|
|
||||
|
public string ExportFile(Guid id, List<string> exportName, List<CustomCondition> p_list) |
||||
|
{ |
||||
|
var version = p_list.Where(p => p.Name == "Version").FirstOrDefault().Value; |
||||
|
var materialCode = p_list.Where(p => p.Name == "MaterialCode").FirstOrDefault().Value; |
||||
|
var begin = p_list.Where(p => p.Name == "BeginTime").FirstOrDefault().Value; |
||||
|
var end = p_list.Where(p => p.Name == "EndTime").FirstOrDefault().Value; |
||||
|
var cp7begin = p_list.Where(p => p.Name == "Cp7BeginTime").FirstOrDefault().Value; |
||||
|
var cp7end = p_list.Where(p => p.Name == "Cp7EndTime").FirstOrDefault().Value; |
||||
|
var kenncode = p_list.Where(p => p.Name == "KennCode").FirstOrDefault().Value; |
||||
|
var chassisNumber = p_list.Where(p => p.Name == "ChassisNumber").FirstOrDefault().Value; |
||||
|
var _ls = _dapperRepository.GetDetailDiffReportList(version, materialCode, begin, end, cp7begin, cp7end, kenncode, chassisNumber); |
||||
|
var diffList = _erpdapperRepository.GetSettleInvoiceDiff(version); |
||||
|
foreach (var itm in _ls) |
||||
|
{ |
||||
|
itm.InvocieAmt = itm.InvoiceQty * itm.InvoicePrice; |
||||
|
itm.DiffPrice = itm.Price - itm.InvoicePrice; |
||||
|
} |
||||
|
_ls=_ls.OrderBy(p => p.ChassisNumber).ThenBy(p=>p.KENNCode).ThenBy(p=>p.SapMaterialCode).ToList(); |
||||
|
|
||||
|
var _lsSum=_ls.GroupBy(p => new { p.MaterialCode, p.SapMaterialCode, p.MaterialGroup }).Select(p => new UnInvoiceSettledDetailSum |
||||
|
{ |
||||
|
MaterialCode = p.Key.MaterialCode, |
||||
|
SapMaterailCode = p.Key.SapMaterialCode, |
||||
|
MaterialGroup = p.Key.MaterialGroup, |
||||
|
SettleQty = p.Sum(itm => itm.SettledQty), |
||||
|
FisQty=0, |
||||
|
DiffQty=- p.Sum(itm => itm.SettledQty), |
||||
|
Price=p.Sum(itm=>itm.InvoicePrice), |
||||
|
DiffAmt= p.Sum(itm => itm.SettledQty)* p.Sum(itm => itm.InvoicePrice) |
||||
|
}).ToList(); |
||||
|
|
||||
|
var _sumTotal= new UnInvoiceSettledDetailSum() { |
||||
|
|
||||
|
SettleQty = _lsSum.Sum(p => p.SettleQty), |
||||
|
DiffQty = _lsSum.Sum(p => p.DiffQty), |
||||
|
Price = _lsSum.Sum(p => p.Price), |
||||
|
DiffAmt=_lsSum.Sum(p=>p.DiffAmt) |
||||
|
|
||||
|
|
||||
|
}; |
||||
|
_lsSum.Add(_sumTotal); |
||||
|
ExcelExporter _exporter = new ExcelExporter();//导出Excel
|
||||
|
//if (_ls.Count > 500000)
|
||||
|
//{
|
||||
|
//}
|
||||
|
//if (_ls.Count > 1000000)
|
||||
|
//{
|
||||
|
//}
|
||||
|
//if (_ls.Count > 1500000)
|
||||
|
//{
|
||||
|
//}
|
||||
|
|
||||
|
|
||||
|
|
||||
|
var result = _exporter.Append(_ls, "差异明细表") |
||||
|
.SeparateBySheet() |
||||
|
.Append(_lsSum, "数量差异汇总表") |
||||
|
.ExportAppendDataAsByteArray(); |
||||
|
result.ShouldNotBeNull(); |
||||
|
_fileContainer.SaveAsync(string.Format("大众准时化结算数量差异比对表_{0}.xlsx", Guid.NewGuid().ToString()), result.Result, true); |
||||
|
|
||||
|
//_outputService.Export<InvoiceSettledDetailDiff>(id, string.Format("大众结算未发运核对明细表_{0}.xlsx", Guid.NewGuid().ToString()), _ls);
|
||||
|
|
||||
|
return id.ToString(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
Loading…
Reference in new issue