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.
 
 
 
 
 
 

237 lines
8.0 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.Linq;
using Win_in.Sfs.Label.Application.Contracts;
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;
public PurchaseReceiptController(IBalanceAppService balanceApp, IInventoryLabelAppService labelService, ISupplierAppService supplierApp, ISupplierAsnAppService supplierAsnApp)
{
this._balanceApp = balanceApp;
this._labelService = labelService;
this._supplierApp = supplierApp;
this._supplierAsnApp = supplierAsnApp;
}
[HttpGet("receipt-sum-qty")]
public virtual async Task<PurchaseReceiptSumQtyDashboardDto> GetReceiptSumQtyAsync()
{
var dto = new PurchaseReceiptSumQtyDashboardDto();
var items = await GetPurchaseReceiptItemDashboardAsync().ConfigureAwait(false);
dto = new PurchaseReceiptSumQtyDashboardDto() { Qty = items.Sum(t => t.Qty) };
return dto;
}
[HttpGet("receipt-count-by-supplier")]
public virtual async Task<List<PurchaseReceiptCountBySupplierDashboardDto>> GetReceiptCountBySupplierQtyAsync()
{
var items = await GetPurchaseReceiptItemDashboardAsync().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("receipt-item-list")]
public virtual async Task<List<PurchaseReceiptItemDashboardDto>> GetReceiptItemListAsync()
{
return await GetPurchaseReceiptItemDashboardAsync().ConfigureAwait(false);
}
[HttpGet("un-receipt-sum-qty")]
public virtual async Task<PurchaseReceiptSumQtyDashboardDto> GetUnReceiptSumQtyAsync()
{
var dto = new PurchaseReceiptSumQtyDashboardDto();
var items = await 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 GetUnPurchaseReceiptItemDashboardAsync().ConfigureAwait(false);
}
private async Task<List<PurchaseReceiptItemDashboardDto>> GetPurchaseReceiptItemDashboardAsync()
{
var balances = await GetBalancesAsync("INSPECT", EnumInventoryStatus.OK).ConfigureAwait(false);
var packingcodes = balances.Select(t => t.PackingCode).Distinct();
var labels = await GetLabelsAsync(packingcodes).ConfigureAwait(false);
var supplierCodes = labels.Select(t => t.SupplierCode).Distinct();
var suppliers = await GetSuppliersAsync(supplierCodes).ConfigureAwait(false);
return ConvertToPurchaseReceiptItemDashboard(balances, labels, suppliers);
}
private static 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 _balanceApp.GetListByLocationCodeAndStatusAsync(locationCode, status).ConfigureAwait(false);
}
private async Task<List<InventoryLabelDto>> GetLabelsAsync(IEnumerable<string> codes)
{
return await _labelService.GetByCodesAsync(codes).ConfigureAwait(false);
}
private async Task<List<SupplierDTO>> GetSuppliersAsync(IEnumerable<string> codes)
{
return await _supplierApp.GetByCodesAsync(codes).ConfigureAwait(false);
}
private async Task<List<SupplierAsnDTO>> GetSupplierAsnsAsync()
{
return await _supplierAsnApp.GetForTodayUnReceivedListAsync().ConfigureAwait(false);
}
private static 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 GetSupplierAsnsAsync().ConfigureAwait(false);
var supplierCodes = supplierAsns.Select(t => t.SupplierCode).Distinct();
var suppliers = await GetSuppliersAsync(supplierCodes).ConfigureAwait(false);
return ConvertToUnPurchaseReceiptItemDashboard(supplierAsns, suppliers);
}
}