Browse Source

更新发票

master
赵新宇 9 months ago
parent
commit
e5341a4c16
  1. 3
      code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccountHttpApiHostModule.cs
  2. 261
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs
  3. 20
      code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs
  4. 4
      code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/INVOICE_GRP.cs

3
code/src/Modules/SettleAccount/host/SettleAccount.HttpApi.Host/SettleAccountHttpApiHostModule.cs

@ -71,6 +71,9 @@ namespace Win.Sfs.SettleAccount
public override void ConfigureServices(ServiceConfigurationContext context)
{
//IServiceCollection Services = new ServiceCollection();
//Services.GetConfiguration();
// System.AbpStringExtensions.ToCamelCase(System.String, Boolean)'
var configuration = context.Services.GetConfiguration();

261
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/Syncs/GenerateJisInvoiceService.cs

@ -5,6 +5,8 @@ using System.Text;
using System.Threading.Tasks;
using AutoMapper;
using CodeArts.Db.Lts;
using DocumentFormat.OpenXml.Bibliography;
using DocumentFormat.OpenXml.Drawing.Diagrams;
using DocumentFormat.OpenXml.Presentation;
using EFCore.BulkExtensions;
using Microsoft.AspNetCore.Mvc;
@ -18,6 +20,7 @@ using TaskJob.EventArgs;
using TaskJob.Interfaces;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Guids;
using Volo.Abp.Uow;
using Win.Sfs.SettleAccount.Bases;
using Win.Sfs.SettleAccount.Bases.DomainServices;
@ -540,19 +543,19 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
{
_dbcontext.BulkUpdate(salist);
//带库位发票
var detailext=salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode,p.LU,p.Price, p.ErpLoc,p.BusinessType })
var detailext = salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode, p.LU, p.Price, p.ErpLoc, p.BusinessType })
.Select(p => new INVOICE_DETAIL_EXT
{
Version=p_version,
InvbillNum= p.Key.InvbillNum,
InvGroupNum= p.Key.InvGroupNum,
PartCode=p.Key.PartCode,
PRICE= p.Key.Price,
ErpLoc=p.Key.ErpLoc,
Version = p_version,
InvbillNum = p.Key.InvbillNum,
InvGroupNum = p.Key.InvGroupNum,
PartCode = p.Key.PartCode,
PRICE = p.Key.Price,
ErpLoc = p.Key.ErpLoc,
Qty = p.Sum(k => k.Qty),
BussiessType=p.Key.BusinessType,
BussiessType = p.Key.BusinessType,
Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
LU=p.Key.LU
LU = p.Key.LU
}
).ToList();
@ -613,6 +616,33 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
EndDate = itm.Key.EndDate
}).ToList();
if (groupDtos.Sum(p => p.Amt) < 10000000)
{
var ls = new List<GroupPartCode>();
var orderbyList = groupDtos.OrderBy(p => p.Qty).ToList();
int i = 0;
int j = orderbyList.Count - 1;
while (i <= j)
{
if (i == j)
{
ls.Add(orderbyList[i]);
}
else
{
ls.Add(orderbyList[i]);
ls.Add(orderbyList[j]);
}
i++;
j--;
}
_invls = GenSecInvoice(orderbyList, p_list, p_adjlist, dtos, p_notlist, p_version, p_InvGroupNum, p_parentInvBillNum, businessType);
}
else
{
List<GroupPartCode> biglist = new List<GroupPartCode>();
List<GroupPartCode> smalllist = new List<GroupPartCode>();
foreach (var itm in groupDtos)//分类1000W以上或1000W以下
@ -781,9 +811,208 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
}
}
}
smalllist = smalllist.OrderBy(p => p.Amt).ToList();
_invls= GenSecInvoice(smalllist, p_list, p_adjlist, dtos, p_notlist, p_version, p_InvGroupNum, p_parentInvBillNum, businessType);
//smalllist = smalllist.OrderBy(p => p.Amt).ToList();
//var gener1 = new InvoiceGeneratorDiff();
//gener1.GenerateInvoices(smalllist);
//var invList1 = gener1.Invoices;
//foreach (var inv in invList1)//小于1000W的开票
//{
// var partlist = inv.Parts;
// var query = from part in p_list
// join part1 in partlist on
// new { part.InvGroupNum, part.PartCode, part.LU, part.Price } equals new { part1.InvGroupNum, part1.PartCode, part1.LU, part1.Price }
// select part;
// var entityList = query.ToList();
// foreach (var entity in entityList)
// {
// entity.InvbillNum = inv.InvBillNum;
// }
// salist.AddRange(entityList);
// if (partlist.Count > 0)
// {
// decimal amt = partlist.Sum(k => k.Amt);//金额
// decimal txtAmt = partlist.Sum(k => k.TaxAmt);//税后金额
// decimal realAmt = partlist.Sum(k => k.Tax);//税额
// var invoicegroupls = entityList.Select(p => p.GroupNum);
// var mapList = new List<INVOICE_MAP_GROUP>();
// foreach (var groupnum in invoicegroupls)
// {
// mapList.Add(new INVOICE_MAP_GROUP(
// guid: GuidGenerator.Create(),
// version: p_version,
// invbillNum: inv.InvBillNum,
// invGroupNum: p_InvGroupNum,
// settleGroupNum: groupnum,
// amt: 0,
// extend1: string.Empty,
// extend2: string.Empty
// )
// );
// }
// if (mapList.Count > 0)
// {
// groupList.AddRange(mapList);
// }
// var innotls = new List<INVOICE_NOT_SETTLE>();
// var sq = entityList.GroupBy(p => new { p.LU, p.GroupNum, p.InvbillNum })
// .Select(p => new { version = p_version, LU = p.Key.LU, Qty = p.Sum(itm => itm.Qty), InvBillNum = p.Key.InvbillNum, GroupNum = p.Key.GroupNum });
// foreach (var sitm in sq)
// {
// innotls.Add(new INVOICE_NOT_SETTLE(
// guid: GuidGenerator.Create(),
// version: p_version,
// invGroupNum: p_InvGroupNum,
// settleGroupNum: sitm.GroupNum,
// lU: sitm.LU,
// lU1: sitm.LU,
// extend1: "可结算",
// extend2: string.Empty,
// qty: sitm.Qty,
// p_invbillnum: sitm.InvBillNum
// ));
// }
// if (innotls.Count > 0)
// {
// notDetialList.AddRange(innotls);
// }
// List<INVOICE_WAIT_DETAIL> _entityDetailList = new List<INVOICE_WAIT_DETAIL>();
// foreach (var detail in partlist)
// {
// _entityDetailList.Add(
// new INVOICE_WAIT_DETAIL(
// guid: GuidGenerator.Create(),
// version: p_version,
// invbillNum: inv.InvBillNum,
// invGroupNum: p_InvGroupNum,
// lU: detail.LU,
// qty: detail.Qty,
// bussiessType: businessType,
// amt: detail.Amt,
// pRICE: detail.Price,
// extend1: detail.ContactDocID,
// extend2: string.Empty,
// beginDate: detail.BeginDate.Value,
// endDate: detail.EndDate.Value,
// partcode: detail.PartCode
// ));
// }
// if (_entityDetailList.Count > 0)
// {
// detailList.AddRange(_entityDetailList);
// }
// var invbill = new INVOICE_GRP
// (
// guid: GuidGenerator.Create(),
// realnvBillNum: string.Empty,
// invbillNum: inv.InvBillNum,
// amt: amt,
// taxAmt: txtAmt,
// fileName: string.Empty,
// businessType: businessType,
// invGroupNum: p_InvGroupNum,
// state: SettleBillState.已开票,
// invoiceBillState: InvoiceBillState.正常,
// tax: 0.13m,
// parent: !string.IsNullOrEmpty(p_parentInvBillNum) ? p_parentInvBillNum : string.Empty,
// preTaxDiff: 0,
// taxDiff: 0,
// clientCode: string.Empty,
// realAmt: realAmt
// );
// string site = dtos.Where(p => !string.IsNullOrEmpty(p.Site)).FirstOrDefault().Site;
// string clientCode = string.Empty;
// switch (site)
// {
// case "1040":
// clientCode = "C001";
// break;
// case "1046":
// clientCode = "C171";
// break;
// default:
// clientCode = "C004";
// break;
// }
// invbill.ClientCode = clientCode;
// invbill.Site = dtos.FirstOrDefault().Site;
// invbill.CreationTime = DateTime.MinValue;
// invbill.LastModificationTime = DateTime.Now;
// invlist.Add(invbill);
// }
//}
//if (salist.Count > 0)
//{
// _dbcontext.BulkUpdate(salist);
// var detailext = salist.GroupBy(p => new { p.InvbillNum, p.InvGroupNum, p.PartCode, p.LU, p.Price, p.ErpLoc, p.BusinessType })
// .Select(p => new INVOICE_DETAIL_EXT
// {
// Version = p_version,
// InvbillNum = p.Key.InvbillNum,
// InvGroupNum = p.Key.InvGroupNum,
// PartCode = p.Key.PartCode,
// PRICE = p.Key.Price,
// ErpLoc = p.Key.ErpLoc,
// Qty = p.Sum(k => k.Qty),
// BussiessType = p.Key.BusinessType,
// Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
// LU = p.Key.LU
// }
// ).ToList();
// foreach (var itm in detailext)
// {
// itm.SetId(GuidGenerator.Create());
// itm.CreationTime = DateTime.Now;
// }
// _dbcontext.BulkInsert(detailext);
//}
//_dbcontext.BulkInsert(invlist);
//_dbcontext.BulkInsert(groupList);
//_dbcontext.BulkInsert(detailList);
//if (adjlist.Count > 0)
//{
// _dbcontext.BulkInsert(adjlist);
//}
//if (notDetialList.Count > 0)
//{
// _dbcontext.BulkInsert(notDetialList);
//}
//_invls = invlist.Select(p => p.InvbillNum).ToList();
}
return _invls;
}
public List<string> GenSecInvoice<TDetail>(List<GroupPartCode> p_grouplist, List<TDetail> p_list, List<PUB_ADJ_DETAIL> p_adjlist, List<TEMP_CAN_SA_DETAIL> dtos, List<TEMP_NOT_SA_DETAIL> p_notlist, int p_version, string p_InvGroupNum, string p_parentInvBillNum, EnumBusinessType businessType)
where TDetail : SA_CAN_BASE, new()
{
var groupList = new List<INVOICE_MAP_GROUP>();
var notDetialList = new List<INVOICE_NOT_SETTLE>();
var detailList = new List<INVOICE_WAIT_DETAIL>();
var invlist = new List<INVOICE_GRP>();
var salist = new List<TDetail>();
var adjlist = new List<PUB_ADJ_DETAIL>();
List<string> _invls = new List<string>();
var gener1 = new InvoiceGeneratorDiff();
gener1.GenerateInvoices(smalllist);
gener1.GenerateInvoices(p_grouplist);
var invList1 = gener1.Invoices;
foreach (var inv in invList1)//小于1000W的开票
{
@ -800,8 +1029,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
entity.InvbillNum = inv.InvBillNum;
}
salist.AddRange(entityList);
if (partlist.Count > 0)
@ -937,7 +1164,6 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
BussiessType = p.Key.BusinessType,
Amt = Math.Round(p.Sum(k => k.Qty) * p.Key.Price, 2),//税前
LU = p.Key.LU
}
).ToList();
foreach (var itm in detailext)
@ -964,6 +1190,8 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
_invls = invlist.Select(p => p.InvbillNum).ToList();
return _invls;
}
}
@ -975,4 +1203,11 @@ namespace Win.Sfs.SettleAccount.Entities.BQ.Syncs
}

20
code/src/Modules/SettleAccount/src/SettleAccount.Application/Entities/BQ/VmiAppService.cs

@ -1223,6 +1223,13 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
/// <returns></returns>
private async Task<IActionResult> BeginTran<T>(List<T> p_list, List<VmiLog> logList) where T : SE_BASE, new()
{
IServiceCollection Services = new ServiceCollection();
/*
*
*/
Services.GetConfiguration();
Services.GetRequiredService<IConfiguration>();
Services.GetRequiredService<ILoggerFactory>();
//var messageList = logList.Select(log => new VmiMessage { Message = JsonSerializer.Serialize(log) }).ToList();
var connectionString = this._serviceProvider.GetRequiredService<IConfiguration>().GetConnectionString("SettleAccountService");
var options = new DbContextOptionsBuilder<SettleAccountDbContext>().UseSqlServer(connectionString).Options;
@ -1725,6 +1732,19 @@ namespace Win.Sfs.SettleAccount.Entities.BQ
}
reader.Close();
connection.Close();
foreach (var item in ls)
{
if (item.BusinessType == EnumBusinessType.JisBBAC.ToString() || item.BusinessType == EnumBusinessType.JisHBPO.ToString() || item.BusinessType == EnumBusinessType.MaiDanJianHBPO.ToString() || item.BusinessType == EnumBusinessType.MaiDanJianBBAC.ToString())
{
if (!string.IsNullOrEmpty(item.PartCode))
{
item.PartCode = item.LU.Replace(" ", "-");
}
}
}
return ls;
}

4
code/src/Modules/SettleAccount/src/SettleAccount.Domain/Entities/BQ/INVOICE_GRP.cs

@ -158,6 +158,8 @@ namespace SettleAccount.Domain.BQ
public string InvBillNum { set; get; }
public InvoiceByDiff() { }
private List<GroupPartCode> parts = new List<GroupPartCode>();
public IReadOnlyList<GroupPartCode> Parts => parts.AsReadOnly();
public decimal TotalAmount => parts.Sum(p => p.Amt);
public int PartCount => parts.GroupBy(p => new { p.LU, p.PartCode }).Count();
@ -169,7 +171,7 @@ namespace SettleAccount.Domain.BQ
{
if (CanAddPart(part))
{
//partCount.Add(part.PartCode);
parts.Add(part);
}

Loading…
Cancel
Save