using NewPdaSqlServer.DB;
|
using NewPdaSqlServer.Dto.service;
|
using NewPdaSqlServer.entity;
|
using NewPdaSqlServer.service.@base;
|
using NewPdaSqlServer.util;
|
using SqlSugar;
|
|
namespace NewPdaSqlServer.service.Warehouse;
|
|
// 期初条码入库
|
public class InventoryManager : RepositoryNoEntity
|
{
|
// 这个方法用于扫描库位条码
|
public string ScanDepotNo(WarehouseQuery query)
|
{
|
var p_section_code = query.DepotCode;
|
|
// 检查库位代码是否为空
|
if (string.IsNullOrEmpty(p_section_code))
|
throw new Exception("002[请扫库位条码!");
|
|
// 查询库区库位信息
|
var depotSection = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
|
new JoinQueryInfos(
|
JoinType.Inner, a.DepotGuid == b.Guid
|
))
|
.Where((a, b) => a.DepotSectionCode == p_section_code)
|
.Select((a, b) => new
|
{ a.DepotSectionName, b.DepotCode, b.DepotName })
|
.Single();
|
|
// 如果库位代码不存在,则返回错误信息
|
if (depotSection == null)
|
throw new Exception("库位编码 " + p_section_code + " 不存在,请确认!");
|
|
// 返回成功信息
|
return "仓库:" + depotSection.DepotName + " 库位:" +
|
depotSection.DepotSectionName;
|
}
|
|
// 这个方法用于扫描条码
|
public WarehouseQuery ScanBarcode(WarehouseQuery query)
|
{
|
var p_item_barcode = query.barcode;
|
var p_section_code = query.DepotCode;
|
var c_user = query.userName;
|
var p_bill_type_id = 100;
|
var p_transction_no = 601;
|
|
// 检查库位代码是否为空
|
// if (string.IsNullOrEmpty(p_section_code))
|
// throw new Exception("002[请扫库位条码!");
|
|
// 查询库区库位信息
|
var depotSection = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
|
new JoinQueryInfos(
|
JoinType.Inner, a.DepotGuid == b.Guid
|
))
|
.Where((a, b) => a.DepotSectionCode == p_section_code)
|
.Select((a, b) => new
|
{ a.DepotSectionName, b.DepotCode, b.DepotName, b.DepotId,b.FSubsidiary })
|
.Single();
|
|
// 如果库位代码不存在,则返回错误信息
|
// if (depotSection == null)
|
// throw new Exception("库位编码 " + p_section_code + " 不存在,请确认!");
|
|
// 检查是否已经收货
|
// var c_num = Db.Queryable<MesInvItemIns, MesInvItemInCDetails>((a, b) =>
|
// new JoinQueryInfos(
|
// JoinType.Inner, a.Guid == b.ItemInId
|
// ))
|
// .Where((a, b) => b.ItemBarcode == p_item_barcode)
|
// .Count();
|
|
// if (c_num > 0) throw new Exception("002[条码重复扫描,请核对!");
|
|
// 查询条码信息
|
// c_num = Db.Queryable<MesInvItemStocks>()
|
// .Where(t => t.ItemBarcode == p_item_barcode)
|
// .Count();
|
|
// if (c_num > 0) throw new Exception("002[条码已在库存中,请核对!");
|
|
// 查询条码详细信息
|
var c_mes_inv_item_barcodes = Db.Queryable<MesInvItemBarcodes>()
|
.Where(t => t.ItemBarcode == p_item_barcode)
|
.Single();
|
|
// if (c_mes_inv_item_barcodes == null)
|
// throw new Exception("002[条码不存在,请核对!");
|
|
if (c_mes_inv_item_barcodes.Memo != "初期物料")
|
throw new Exception("002[条码不是期初条码,无法用期初入库!");
|
|
var wmsManager = new WmsBaseMangeer();
|
// 新增入库校验(调用存储过程)
|
var checkResult = wmsManager.pdaInvJY(
|
db: Db,
|
edtUserNo: query.userName,
|
barcode: p_item_barcode,
|
sectionCode: p_section_code,
|
stockId: depotSection.DepotId.ToString(),
|
stockOrgId: depotSection.FSubsidiary,
|
billNo: "", // 根据实际单据号传值
|
transactionNo: "601" // 事务类型与存储过程匹配
|
);
|
|
if ( Convert.ToInt32(checkResult.result) < 1)
|
throw new Exception($"入库校验失败:{checkResult.strMsg}");
|
|
UseTransaction(db =>
|
{
|
// 自动生成入库单
|
var c_id = db.Queryable<MesInvItemIns>()
|
.Where(d =>
|
d.Sapstatus == 0 &&
|
d.InsDate.Value.ToString("yyyy-MM-dd") ==
|
DateTime.Now.ToString("yyyy-MM-dd") &&
|
d.Status == 0 &&
|
d.TransctionNo == p_transction_no.ToString() &&
|
d.CbillNo == c_mes_inv_item_barcodes.BillNo &&
|
(d.SuppId ?? "0") ==
|
(c_mes_inv_item_barcodes.SuppId ?? "0") &&
|
d.DepotsCode == depotSection.DepotCode)
|
.Single();
|
|
if (c_id == null)
|
{
|
var billNo = BillNo.GetBillNo("IN(入库单)");
|
// 生成入库单号
|
var newMesInvItemIns = new MesInvItemIns
|
{
|
Guid = Guid.NewGuid(),
|
TransctionNo = p_transction_no.ToString(),
|
DepotsCode = depotSection.DepotCode,
|
DepotsId = depotSection.DepotId,
|
BillTypeId = p_bill_type_id,
|
CreateBy = c_user,
|
CreateDate = DateTime.Now,
|
LastupdateBy = c_user,
|
LastupdateDate = DateTime.Now,
|
BillNo = billNo,
|
SuppId = c_mes_inv_item_barcodes.SuppId,
|
SuppNo = c_mes_inv_item_barcodes.SuppNo,
|
UrgentFlag = c_mes_inv_item_barcodes.UrgentFlag == null
|
?
|
null
|
: c_mes_inv_item_barcodes.UrgentFlag.Value
|
? "1"
|
: "0",
|
CbillNo = c_mes_inv_item_barcodes.BillNo,
|
Fstatus = 0,
|
ReceiveOrgId = depotSection.FSubsidiary,
|
InType = "期初入库",
|
};
|
db.Insertable(newMesInvItemIns)
|
.IgnoreColumns(true)
|
.ExecuteCommand();
|
c_id = newMesInvItemIns;
|
}
|
|
// 插入入库单明细
|
db.Insertable(new MesInvItemInCDetails
|
{
|
Guid = Guid.NewGuid(),
|
ItemInId = c_id.Guid,
|
BillNo = c_id.BillNo,
|
ItemBarcode = p_item_barcode,
|
Quantity = c_mes_inv_item_barcodes.Quantity,
|
BarcodeFlag = true,
|
EpFlag = true,
|
WorkType = 1,
|
ItemNo = c_mes_inv_item_barcodes.ItemNo,
|
LotNo = c_mes_inv_item_barcodes.LotNo,
|
SuppNo = c_mes_inv_item_barcodes.SuppNo,
|
DepotId = depotSection.DepotId,
|
DepotCode = depotSection.DepotCode,
|
DepotSectionCode = p_section_code,
|
ItemSname = c_mes_inv_item_barcodes.ItemSname,
|
Unit = c_mes_inv_item_barcodes.Unit,
|
CreateBy = c_user,
|
CreateDate = DateTime.Now,
|
LastupdateBy = c_user,
|
LastupdateDate = DateTime.Now,
|
Remark = c_mes_inv_item_barcodes.Memo,
|
Ebeln = c_mes_inv_item_barcodes.Mblnr,
|
EbelnLineNo = c_mes_inv_item_barcodes.Zeile,
|
WorkNo = c_mes_inv_item_barcodes.WorkNo,
|
WorkLine = c_mes_inv_item_barcodes.WorkLine,
|
CbillNo = c_mes_inv_item_barcodes.BillNo,
|
UrgentFlag = c_mes_inv_item_barcodes.UrgentFlag,
|
BoardStyle = c_mes_inv_item_barcodes.BoardStyle,
|
TaskNo = c_mes_inv_item_barcodes.TaskNo,
|
ItemId = c_mes_inv_item_barcodes.ItemId,
|
ReceiveOrgId = depotSection.FSubsidiary,
|
}).IgnoreColumns(true).ExecuteCommand();
|
|
|
db.Insertable(new MesInvBusiness2
|
{
|
Guid = Guid.NewGuid(),
|
Status = 1,
|
BillTypeId = p_bill_type_id,
|
TransactionCode = p_transction_no.ToString(),
|
BusinessType = 1,
|
ItemBarcode = p_item_barcode,
|
ItemNo = c_mes_inv_item_barcodes.ItemNo,
|
LotNo = c_mes_inv_item_barcodes.LotNo,
|
EpFlag = true,
|
Quantity = c_mes_inv_item_barcodes.Quantity,
|
InvDepotId = depotSection.DepotId,
|
ToInvDepotsCode = depotSection.DepotCode,
|
ToInvDepotSectionsCode = p_section_code,
|
CreateBy = c_user,
|
CreateDate = DateTime.Now,
|
LastupdateBy = c_user,
|
LastupdateDate = DateTime.Now,
|
TaskNo = c_mes_inv_item_barcodes.TaskNo,
|
BillNo = c_id.BillNo,
|
WorkNo = c_mes_inv_item_barcodes.WorkNo,
|
WorkLine = c_mes_inv_item_barcodes.WorkLine,
|
SuppNo = c_mes_inv_item_barcodes.SuppNo,
|
ItemId = c_mes_inv_item_barcodes.ItemId
|
}).IgnoreColumns(true).ExecuteCommand();
|
|
// 插入库存信息
|
db.Insertable(new MesInvItemStocks
|
{
|
Guid = Guid.NewGuid(),
|
TaskNo = c_mes_inv_item_barcodes.TaskNo,
|
ItemBarcode = p_item_barcode,
|
ItemNo = c_mes_inv_item_barcodes.ItemNo,
|
LotNo = c_mes_inv_item_barcodes.LotNo,
|
Quantity = c_mes_inv_item_barcodes.Quantity,
|
EpFlag = c_mes_inv_item_barcodes.EpFlag == null
|
? null
|
: (byte)(c_mes_inv_item_barcodes.EpFlag.Value ? 1 : 0),
|
DepotsCode = depotSection.DepotCode,
|
DepotId = depotSection.DepotId,
|
DepotsId = depotSection.DepotId,
|
DepotSectionsCode = p_section_code,
|
CheckDate = c_mes_inv_item_barcodes.CreateDate,
|
IndepDate = c_mes_inv_item_barcodes.CreateDate,
|
BoardStyle = c_mes_inv_item_barcodes.BoardStyle,
|
WorkNo = c_mes_inv_item_barcodes.WorkNo,
|
WorkLine = c_mes_inv_item_barcodes.WorkLine,
|
// ItemUnit = c_mes_inv_item_barcodes.Unit,
|
SuppNo = c_mes_inv_item_barcodes.SuppNo,
|
ItemId = c_mes_inv_item_barcodes.ItemId,
|
IndepUserCode = c_user,
|
StockOrgId = depotSection.FSubsidiary,
|
// Fsubsidiary = c_organize
|
}).IgnoreColumns(true).ExecuteCommand();
|
|
return 1;
|
});
|
|
var mesItems = Db.Queryable<MesItems>()
|
.Where(s => s.Id == c_mes_inv_item_barcodes.ItemId)
|
.First();
|
|
query.itemNo = mesItems.ItemNo;
|
query.Num = c_mes_inv_item_barcodes.Quantity;
|
query.message = "物料 " +
|
c_mes_inv_item_barcodes.ItemNo + " 本次收货总数: " +
|
c_mes_inv_item_barcodes.Quantity;
|
// 返回成功信息
|
return query;
|
}
|
}
|