You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

259 lines
9.7 KiB

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Win_in.Sfs.Basedata.Application.Contracts;
using Win_in.Sfs.Wms.Dashboard.Host.Models;
namespace Win_in.Sfs.Wms.Dashboard.Host.Controllers
{
using System;
using System.Linq;
using Volo.Abp;
using Win_in.Sfs.Label.Application.Contracts;
using Win_in.Sfs.Label.Domain;
using Win_in.Sfs.Shared.Domain.Shared;
using Win_in.Sfs.Wms.Inventory.Application.Contracts;
using Win_in.Sfs.Wms.Store.Application.Contracts;
[ApiController]
[Route($"{PdaHostConst.ROOT_ROUTE}purchase-receipt")]
public class PurchaseReceiptController : AbpController
{
private readonly IBalanceAppService _balanceApp;
private readonly IInventoryLabelAppService _labelService;
private readonly ISupplierAppService _supplierApp;
private readonly ISupplierAsnAppService _supplierAsnApp;
private readonly IPurchaseReceiptNoteAppService _purchaseReceiptNoteAppService;
private readonly IInspectNoteAppService _inspectNoteAppService;
public PurchaseReceiptController(IBalanceAppService balanceApp, IInventoryLabelAppService labelService, ISupplierAppService supplierApp, ISupplierAsnAppService supplierAsnApp, IPurchaseReceiptNoteAppService purchaseReceiptNoteAppService, IInspectNoteAppService inspectNoteAppService)
{
this._balanceApp = balanceApp;
this._labelService = labelService;
this._supplierApp = supplierApp;
this._supplierAsnApp = supplierAsnApp;
_purchaseReceiptNoteAppService = purchaseReceiptNoteAppService;
_inspectNoteAppService = inspectNoteAppService;
}
/// <summary>
/// 未上架数量
/// </summary>
/// <returns></returns>
[HttpGet("no-put-away-sum-qty")]
public virtual async Task<PurchaseReceiptSumQtyDashboardDto> GetNoPutAwaySumQtyAsync()
{
var dto = new PurchaseReceiptSumQtyDashboardDto();
var items = await GetPurchaseReceiptItemDashboardAsync();
dto = new PurchaseReceiptSumQtyDashboardDto() { Qty = items.Sum(t => t.Qty) };
return dto;
}
/// <summary>
/// 未上架汇总
/// </summary>
/// <returns></returns>
[HttpGet("no-put-away-by-supplier")]
public virtual async Task<List<PurchaseReceiptCountBySupplierDashboardDto>> GetNoPutAwayBySupplierAsync()
{
var items = await GetPurchaseReceiptItemDashboardAsync();
var dtos = items.GroupBy(t => t.SupplierShortName)
.Select(
t => new PurchaseReceiptCountBySupplierDashboardDto
{
SupplierShortName = t.Key,
Qty = t.Sum(t1 => t1.Qty)
}).OrderBy(t => t.SupplierShortName).ToList();
return dtos;
}
/// <summary>
/// 未上架明细
/// </summary>
/// <returns></returns>
[HttpGet("no-put-away-item-list")]
public virtual async Task<List<PurchaseReceiptItemDashboardDto>> GetReceiptItemListAsync()
{
return await GetPurchaseReceiptItemDashboardAsync();
}
[HttpGet("un-receipt-sum-qty")]
public virtual async Task<PurchaseReceiptSumQtyDashboardDto> GetUnReceiptSumQtyAsync()
{
var dto = new PurchaseReceiptSumQtyDashboardDto();
var items = await this.GetUnPurchaseReceiptItemDashboardAsync().ConfigureAwait(false);
dto = new PurchaseReceiptSumQtyDashboardDto() { Qty = items.Sum(t => t.Qty) };
return dto;
}
[HttpGet("un-receipt-count-by-supplier")]
public virtual async Task<List<PurchaseReceiptCountBySupplierDashboardDto>> GetUnReceiptCountBySupplierQtyAsync()
{
var items = await GetUnPurchaseReceiptItemDashboardAsync().ConfigureAwait(false);
var dtos = items.GroupBy(t => t.SupplierShortName)
.Select(
t => new PurchaseReceiptCountBySupplierDashboardDto
{
SupplierShortName = t.Key,
Qty = t.Sum(t1 => t1.Qty)
}).OrderBy(t => t.SupplierShortName).ToList();
return dtos;
}
[HttpGet("un-receipt-item-list")]
public virtual async Task<List<PurchaseReceiptItemDashboardDto>> GetUnReceiptItemListAsync()
{
return await this.GetUnPurchaseReceiptItemDashboardAsync().ConfigureAwait(false);
}
private async Task<List<PurchaseReceiptItemDashboardDto>> GetPurchaseReceiptItemDashboardAsync()
{
var inspectNoteDetailDto = await _inspectNoteAppService.GetInspectNoteDetailByDayTaskAsync(7).ConfigureAwait(false);//7天数据
var packingCodeList = inspectNoteDetailDto.Where(p => p.Status == EnumInventoryStatus.OK|| p.Status == EnumInventoryStatus.INSP).Select(p => p.PackingCode).ToList();
var balances = await _balanceApp.GetListByPackingCodesAsync(packingCodeList);
balances = balances.Where(p => p.LocationCode == "INSPECT").ToList();
//var balances = await GetBalancesAsync("INSPECT", EnumInventoryStatus.OK);
var packingcodes = balances.Select(t => t.PackingCode).Distinct();
var labels = await GetLabelsAsync(packingcodes);
var supplierCodes = labels.Select(t => t.SupplierCode).Distinct();
var suppliers = await GetSuppliersAsync(supplierCodes);
return ConvertToPurchaseReceiptItemDashboard(balances, labels, suppliers);
}
private List<PurchaseReceiptItemDashboardDto> ConvertToPurchaseReceiptItemDashboard(
List<BalanceDTO> balances,
List<InventoryLabelDto> labels,
List<SupplierDTO> suppliers)
{
var dtos = new List<PurchaseReceiptItemDashboardDto>();
foreach (var balance in balances)
{
var supplierShortName = string.Empty;
var label = labels.FirstOrDefault(t => t.Code == balance.PackingCode);
if (label == null)
continue;
var supplier = suppliers.FirstOrDefault(t => t != null && t.Code == label.SupplierCode);
if (supplier == null)
continue;
supplierShortName = supplier.ShortName;
var dto = dtos.Find(t => t.SupplierShortName == supplierShortName && t.ItemCode == balance.ItemCode);
if (dto == null)
{
dto = new PurchaseReceiptItemDashboardDto();
dto.SupplierShortName = supplierShortName;
dto.ItemCode = balance.ItemCode;
dto.ItemDesc1 = balance.ItemDesc1;
dto.Qty = 0;
dtos.Add(dto);
}
dto.Qty += balance.Qty;
}
return dtos.OrderBy(t => t.SupplierShortName).ToList();
}
private async Task<List<BalanceDTO>> GetBalancesAsync(string locationCode, EnumInventoryStatus status)
{
return await this._balanceApp.GetListByLocationCodeAndStatusAsync(locationCode, status);
}
private async Task<List<InventoryLabelDto>> GetLabelsAsync(IEnumerable<string> codes)
{
return await this._labelService.GetByCodesAsync(codes);
}
private async Task<List<SupplierDTO>> GetSuppliersAsync(IEnumerable<string> codes)
{
return await this._supplierApp.GetByCodesAsync(codes);
}
private async Task<List<SupplierAsnDTO>> GetSupplierAsnsAsync(int day)
{
return await this._supplierAsnApp.GeUnReceivedByDayListAsync(day);
}
private List<PurchaseReceiptItemDashboardDto> ConvertToUnPurchaseReceiptItemDashboard(
List<SupplierAsnDTO> supplierAsns,
List<SupplierDTO> suppliers)
{
var dtos = new List<PurchaseReceiptItemDashboardDto>();
foreach (var supplierAsn in supplierAsns)
{
var supplierShortName = string.Empty;
var supplier = suppliers.FirstOrDefault(t => t.Code == supplierAsn.SupplierCode);
if (supplier == null)
continue;
supplierShortName = supplier.ShortName;
foreach (var detail in supplierAsn.Details)
{
var dto = dtos.Find(t => t.SupplierShortName == supplierShortName && t.ItemCode == detail.ItemCode);
if (dto == null)
{
dto = new PurchaseReceiptItemDashboardDto();
dto.SupplierShortName = supplierShortName;
dto.ItemCode = detail.ItemCode;
dto.ItemDesc1 = detail.ItemDesc1;
dto.Qty = 0;
dtos.Add(dto);
}
dto.Qty += detail.Qty;
}
}
return dtos.OrderBy(t => t.SupplierShortName).ToList();
}
private async Task<List<PurchaseReceiptItemDashboardDto>> GetUnPurchaseReceiptItemDashboardAsync()
{
var dtos = new List<PurchaseReceiptItemDashboardDto>();
var supplierAsns = await this.GetSupplierAsnsAsync(7).ConfigureAwait(false);//七天数据
var supplierCodes = supplierAsns.Select(t => t.SupplierCode).Distinct();
var suppliers = await GetSuppliersAsync(supplierCodes);
return this.ConvertToUnPurchaseReceiptItemDashboard(supplierAsns, suppliers);
}
}
}