213 lines
11 KiB
C#
213 lines
11 KiB
C#
using JNPF.DependencyInjection;
|
|
using JNPF.DynamicApiController;
|
|
using JNPF.Systems.Interfaces.System;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using SqlSugar;
|
|
using Tnb.BasicData.Entities;
|
|
using Tnb.WarehouseMgr.Entities;
|
|
using Tnb.WarehouseMgr.Entities.Dto.ErpInputs;
|
|
|
|
namespace Tnb.WarehouseMgr
|
|
{
|
|
/// <summary>
|
|
/// erp接口模块
|
|
/// </summary>
|
|
[ApiDescriptionSettings(Tag = ModuleConsts.Tag, Area = ModuleConsts.Area, Order = 800)]
|
|
public class ErpToWmsService : IDynamicApiController, ITransient
|
|
{
|
|
private readonly ISqlSugarRepository<WmsPurchaseH> _repository;
|
|
private readonly IBillRullService _billRuleService;
|
|
public ErpToWmsService(ISqlSugarRepository<WmsPurchaseH> repository, IBillRullService billRuleService)
|
|
{
|
|
_repository = repository;
|
|
_billRuleService = billRuleService;
|
|
}
|
|
/// <summary>
|
|
/// 采购到货单
|
|
/// </summary>
|
|
public async Task PurchaseArrive(PurchaseArriveInput input)
|
|
{
|
|
//主表 create_time 采购收货单号 bill_code 单据类型 bill_type 单据状态 status 业务类型 biz_type 入库仓库ID warehouse_id 供应商ID supplier_id 供应商名称supplier_name 生成类型 generate_type
|
|
//子表 主表id bill_id 执行状态line_status 单位id unit_id 物料id material_id
|
|
var db = _repository.AsSugarClient();
|
|
WmsPurchaseH wmsPurchaseH = new WmsPurchaseH();
|
|
string Code = await _billRuleService.GetBillNumber("WmsPurchase");
|
|
wmsPurchaseH.bill_code = Code;
|
|
wmsPurchaseH.bill_type = "25103333373205";//收料通知单(到货单)
|
|
wmsPurchaseH.biz_type = "26191496816421";//一般入库
|
|
wmsPurchaseH.status = "25065138925589";//新增
|
|
wmsPurchaseH.generate_type = "1";//0人工 1自动
|
|
wmsPurchaseH.create_time = DateTime.Now;
|
|
wmsPurchaseH.source_id = input.source_id;
|
|
wmsPurchaseH.source_code = input.source_code;
|
|
wmsPurchaseH.delivery_date = input.delivery_date;
|
|
wmsPurchaseH.shipping_method = input.shipping_method;
|
|
var warehouse = await db.Queryable<BasWarehouse>().Where(p => p.whcode == input.warehouse).FirstAsync();
|
|
if (warehouse != null)
|
|
wmsPurchaseH.warehouse_id = warehouse.id;
|
|
wmsPurchaseH.supplier_code = input.supplier_code;
|
|
var supplier = await db.Queryable<BasSupplier>().Where(p => p.supplier_code == input.supplier_code).FirstAsync();
|
|
if (supplier != null)
|
|
{
|
|
wmsPurchaseH.supplier_id = supplier.id;
|
|
wmsPurchaseH.supplier_name = supplier.supplier_name;
|
|
}
|
|
List<WmsPurchaseD> WmsPurchaseDs = new List<WmsPurchaseD>();
|
|
foreach (var detail in input.details)
|
|
{
|
|
WmsPurchaseD wmsPurchased = new WmsPurchaseD();
|
|
wmsPurchased.bill_id = wmsPurchaseH.id;
|
|
wmsPurchased.line_status = "25065138925589";//新增
|
|
wmsPurchased.purchase_qty = detail.purchase_qty;
|
|
wmsPurchased.purchase_prqty = detail.purchase_prqty;
|
|
wmsPurchased.code_batch = detail.code_batch;
|
|
wmsPurchased.purchase_arriveqty = detail.purchase_arriveqty;
|
|
wmsPurchased.container_no = detail.container_no;
|
|
wmsPurchased.material_code = detail.material_code;
|
|
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
|
if (material != null)
|
|
{
|
|
wmsPurchased.material_id = material.id;
|
|
// wmsPurchased.material_name = material.name;
|
|
wmsPurchased.unit_id = material.unit_id;
|
|
}
|
|
WmsPurchaseDs.Add(wmsPurchased);
|
|
}
|
|
await db.Insertable(wmsPurchaseH).ExecuteCommandAsync();
|
|
await db.Insertable(WmsPurchaseDs).ExecuteCommandAsync();
|
|
|
|
}
|
|
/// <summary>
|
|
/// 采购退货单
|
|
/// </summary>
|
|
public async Task PurchaseReturn(PurchaseReturnInput input)
|
|
{
|
|
//主表 create_time 采购收货单号 bill_code 单据类型 bill_type 单据状态 status 业务类型 biz_type 入库仓库ID warehouse_id 供应商ID supplier_id 供应商名称supplier_name 生成类型 generate_type
|
|
//子表 主表id bill_id 执行状态line_status 单位id unit_id 物料id material_id
|
|
var db = _repository.AsSugarClient();
|
|
WmsPurchaseH wmsPurchaseH = new WmsPurchaseH();
|
|
string Code = await _billRuleService.GetBillNumber("WmsPurchase");
|
|
wmsPurchaseH.bill_code = Code;
|
|
wmsPurchaseH.bill_type = "25103345478421";//采购退料单
|
|
wmsPurchaseH.biz_type = "26191522660645";//一般出库
|
|
wmsPurchaseH.status = "25065138925589";//新增
|
|
wmsPurchaseH.generate_type = "1";//0人工 1自动
|
|
wmsPurchaseH.create_time = DateTime.Now;
|
|
wmsPurchaseH.source_id = input.source_id;
|
|
wmsPurchaseH.source_code = input.source_code;
|
|
wmsPurchaseH.delivery_date = input.delivery_date;
|
|
wmsPurchaseH.shipping_method = input.shipping_method;
|
|
var warehouse = await db.Queryable<BasWarehouse>().Where(p => p.whcode == input.warehouse).FirstAsync();
|
|
if (warehouse != null)
|
|
wmsPurchaseH.warehouse_id = warehouse.id;
|
|
wmsPurchaseH.supplier_code = input.supplier_code;
|
|
var supplier = await db.Queryable<BasSupplier>().Where(p => p.supplier_code == input.supplier_code).FirstAsync();
|
|
if (supplier != null)
|
|
{
|
|
wmsPurchaseH.supplier_id = supplier.id;
|
|
|
|
wmsPurchaseH.supplier_name = supplier.supplier_name;
|
|
}
|
|
List<WmsPurchaseD> WmsPurchaseDs = new List<WmsPurchaseD>();
|
|
foreach (var detail in input.details)
|
|
{
|
|
WmsPurchaseD wmsPurchased = new WmsPurchaseD();
|
|
wmsPurchased.bill_id = wmsPurchaseH.id;
|
|
wmsPurchased.line_status = "25065138925589";//新增
|
|
wmsPurchased.purchase_qty = detail.purchase_qty;
|
|
wmsPurchased.purchase_prqty = detail.purchase_prqty;
|
|
wmsPurchased.code_batch = detail.code_batch;
|
|
wmsPurchased.purchase_arriveqty = detail.purchase_arriveqty;
|
|
wmsPurchased.container_no = detail.container_no;
|
|
wmsPurchased.material_code = detail.material_code;
|
|
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
|
if (material != null)
|
|
{
|
|
wmsPurchased.material_id = material.id;
|
|
// wmsPurchased.material_name = material.name;
|
|
wmsPurchased.unit_id = material.unit_id;
|
|
}
|
|
WmsPurchaseDs.Add(wmsPurchased);
|
|
}
|
|
await db.Insertable(wmsPurchaseH).ExecuteCommandAsync();
|
|
await db.Insertable(WmsPurchaseDs).ExecuteCommandAsync();
|
|
|
|
}
|
|
/// <summary>
|
|
/// 仓库调拨
|
|
/// </summary>
|
|
public async Task Allot(AllotInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
WmsAllot wmsAllot = new WmsAllot();
|
|
string Code = await _billRuleService.GetBillNumber("WmsTransfer");
|
|
wmsAllot.bill_code = Code;
|
|
wmsAllot.biz_type = "25044010525205";//仓库调拨
|
|
wmsAllot.status = "25065138925589";//新增
|
|
var warehouse = await db.Queryable<BasWarehouse>().Where(p => p.whcode == input.warehouse).FirstAsync();
|
|
if (warehouse != null)
|
|
wmsAllot.warehouse_id = warehouse.id;
|
|
var startloc = await db.Queryable<BasLocation>().Where(p => p.location_code == input.startlocation).FirstAsync();
|
|
if (startloc != null)
|
|
wmsAllot.startlocation_id = startloc.id;
|
|
var endloc = await db.Queryable<BasLocation>().Where(p => p.location_code == input.endlocation).FirstAsync();
|
|
if (endloc != null)
|
|
wmsAllot.endlocation_id = endloc.id;
|
|
wmsAllot.create_time = DateTime.Now;
|
|
await db.Insertable(wmsAllot).ExecuteCommandAsync();
|
|
}
|
|
/// <summary>
|
|
/// 销售出库单
|
|
/// </summary>
|
|
public async Task SaleOut(SaleOutInput input)
|
|
{
|
|
var db = _repository.AsSugarClient();
|
|
WmsSaleH WmsSaleH = new WmsSaleH();
|
|
string Code = await _billRuleService.GetBillNumber("WmsSale");
|
|
WmsSaleH.bill_code = Code;
|
|
WmsSaleH.bill_type = "25103439022357";//销售出库单
|
|
WmsSaleH.biz_type = "26191522660645";//一般出库
|
|
WmsSaleH.status = "25065138925589";//新增
|
|
WmsSaleH.generate_type = "1";//0人工 1自动
|
|
WmsSaleH.create_time = DateTime.Now;
|
|
WmsSaleH.source_id = input.source_id;
|
|
WmsSaleH.source_code = input.source_code;
|
|
WmsSaleH.ship_date = input.ship_date;
|
|
WmsSaleH.shipping_method = input.shipping_method;
|
|
var warehouse = await db.Queryable<BasWarehouse>().Where(p => p.whcode == input.warehouse).FirstAsync();
|
|
if (warehouse != null)
|
|
WmsSaleH.warehouse_id = warehouse.id;
|
|
WmsSaleH.customer_code = input.customer_code;
|
|
var customer = await db.Queryable<BasCustomer>().Where(p => p.customer_code == input.customer_code).FirstAsync();
|
|
if (customer != null)
|
|
{
|
|
WmsSaleH.customer_id = customer.id;
|
|
WmsSaleH.customer_name = customer.customer_name;
|
|
}
|
|
List<WmsSaleD> WmsSaleDs = new List<WmsSaleD>();
|
|
foreach (var detail in input.details)
|
|
{
|
|
WmsSaleD WmsSaleD = new WmsSaleD();
|
|
WmsSaleD.bill_id = WmsSaleH.id;
|
|
WmsSaleD.line_status = "25065138925589";//新增
|
|
WmsSaleD.purchase_qty = detail.purchase_qty;
|
|
WmsSaleD.purchase_prqty = detail.purchase_prqty;
|
|
WmsSaleD.code_batch = detail.code_batch;
|
|
WmsSaleD.purchase_arriveqty = detail.purchase_arriveqty;
|
|
WmsSaleD.container_no = detail.container_no;
|
|
WmsSaleD.material_code = detail.material_code;
|
|
var material = await db.Queryable<BasMaterial>().Where(p => p.code == detail.material_code).FirstAsync();
|
|
if (material != null)
|
|
{
|
|
WmsSaleD.material_id = material.id;
|
|
// WmsSaleD.material_name = material.name;
|
|
WmsSaleD.unit_id = material.unit_id;
|
|
}
|
|
WmsSaleDs.Add(WmsSaleD);
|
|
}
|
|
await db.Insertable(WmsSaleH).ExecuteCommandAsync();
|
|
await db.Insertable(WmsSaleDs).ExecuteCommandAsync();
|
|
}
|
|
}
|
|
}
|