From 20dda69cad210c3b40d643e52ba1cbccec24b392 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期一, 14 七月 2025 15:23:32 +0800
Subject: [PATCH] 1.携客云获取送货单默认组织写死 2.采购入库优化
---
service/Warehouse/MesInvItemInCDetailsManager.cs | 494 ++++++++++++++++++++++++++++++++++--------------------
1 files changed, 309 insertions(+), 185 deletions(-)
diff --git a/service/Warehouse/MesInvItemInCDetailsManager.cs b/service/Warehouse/MesInvItemInCDetailsManager.cs
index 108ba74..3ecf875 100644
--- a/service/Warehouse/MesInvItemInCDetailsManager.cs
+++ b/service/Warehouse/MesInvItemInCDetailsManager.cs
@@ -1,9 +1,13 @@
-锘縰sing NewPdaSqlServer.DB;
+锘縰sing Masuit.Tools.Models;
+using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity.Base;
+using NewPdaSqlServer.service.@base;
using NewPdaSqlServer.util;
using Newtonsoft.Json;
using SqlSugar;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace NewPdaSqlServer.service.Warehouse;
@@ -11,15 +15,15 @@
{
//褰撳墠绫诲凡缁忕户鎵夸簡 Repository 澧炪�佸垹銆佹煡銆佹敼鐨勬柟娉�
- public PurchaseInventory SaveBarCodes(WarehouseQuery entity)
+ public ItemInBaseModel SaveBarCodes(WarehouseQuery entity)
{
string functionName = "閲囪喘鍏ュ簱", fieldName = null, inFieldVal = null;
string user = entity.userName,
sectionCode = entity.sectionCode,
itemBarcode = entity.barcode;
- string transactionNo = "101";
+ var transactionNo = "101";
int? billTypeId = 100, num = 0, num2 = 0;
- int freeze = 0;
+ var freeze = 0;
decimal cSyQty = 0;
if (string.IsNullOrEmpty(sectionCode))
@@ -32,25 +36,43 @@
if (itemBarcodeDetails == null)
throw new Exception("鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒");
- if (!itemBarcodeDetails.ComeFlg.Value)
+ if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "閲囪喘鍏ュ簱")
throw new Exception("姝ゆ潯鐮佷笉灞炰簬鍒拌揣鏉$爜锛屾棤娉曠敤閲囪喘鍏ュ簱锛�");
var inventory = Db.Queryable<MesInvItemArn>()
- .Where(it => it.BillNo == itemBarcodeDetails.BillNo)
+ .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true )
.First();
if (inventory == null)
- throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曪紒");
+ throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟垨鏈鏍革紒");
+
+ // var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
+ // .Where(it => it.ParentGuid == inventory.Guid
+ // && it.ItemId == itemBarcodeDetails.ItemId
+ // && it.EbelnLine == itemBarcodeDetails.WorkLine
+ // && it.Ebeln == itemBarcodeDetails.WorkNo)
+ // .First();
var inventoryDetails = Db.Queryable<MesInvItemArnDetail>()
- .Where(it => it.ParentGuid == inventory.Guid
- && it.ItemId == itemBarcodeDetails.ItemId
- && it.EbelnLine == itemBarcodeDetails.WorkLine
- && it.Ebeln == itemBarcodeDetails.WorkNo)
+ .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
+ .First();
+
+ var cgddDetails = Db.Queryable<MesRohInData>()
+ .Where(it => it.EbelnK3id == inventoryDetails.LineK3id)
.First();
if (inventoryDetails == null)
throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟槑缁嗭紒");
+
+ //鑾峰彇鍒拌揣妫�楠屾槑缁�
+ var sqlParams = new List<SugarParameter> { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) };
+ var sql1 = @"SELECT *FROM v_dhmx WHERE dhmxGuid = @dhmxGuid ";
+ var dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First();
+ //鍒ゅ畾妫�楠岃兘鍚﹀叆搴�
+ if (dhjymx.CanStore!= 1)
+ {
+ throw new Exception($"璇ユ潯鐮佸搴旂殑鏀舵枡鍗曟楠岀粨鏋�:銆恵dhjymx.InspectionResult}銆�,鍒ゅ畾缁撴灉锛氥�恵dhjymx.JudgmentResult}銆戯紝澶勭悊鎰忚锛氥�恵dhjymx.HandlingSuggestion}銆�,鏃犳硶鍏ュ簱");
+ }
var depotCode = Db.Queryable<MesDepotSections>()
.Where(it => it.DepotSectionCode == sectionCode)
@@ -65,13 +87,13 @@
MesDepots mesDepost = null;
var checkGuid = UtilityHelper.CheckGuid(depotCode);
- if (checkGuid && depotCode2 != null)
+ if (checkGuid && depotCode != null)
{
mesDepost = Db.Queryable<MesDepots>()
- .Where(s => s.DepotId.ToString() == depotCode2).First();
+ .Where(s => s.DepotId.ToString() == depotCode).First();
- if (depotCode != mesDepost.Guid)
- throw new Exception("鎵弿搴撲綅涓庨噰璐叆搴撳簱浣嶄笉涓�鑷达紒");
+ // if (depotCode != mesDepost.Guid)
+ // throw new Exception("鎵弿搴撲綅涓庨噰璐叆搴撳簱浣嶄笉涓�鑷达紒");
}
else
{
@@ -79,54 +101,111 @@
}
- num = Db.Queryable<MesInvItemInCDetails>()
- .Where(it => it.ItemBarcode == itemBarcode)
- .Count();
+ //num = Db.Queryable<MesInvItemInCDetails>()
+ // .Where(it => it.ItemBarcode == itemBarcode)
+ // .Count();
- if (num > 0)
- throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚锛岃鏍稿锛�");
+ //if (num > 0)
+ // throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱瀹屾垚锛岃鏍稿锛�");
- num = Db.Queryable<MesInvItemStocks>()
- .Where(it => it.ItemBarcode == itemBarcode)
- .Count();
+ //num = Db.Queryable<MesInvItemStocks>()
+ // .Where(it => it.ItemBarcode == itemBarcode)
+ // .Count();
- if (num > 0)
- throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱锛岃鏍稿锛�");
+ //if (num > 0)
+ // throw new Exception("姝ゆ潯鐮佸凡鎵爜鍏ュ簱锛岃鏍稿锛�");
- num = Db.Queryable<MesInvItemArn>()
- .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
- .InnerJoin<MesInvItemArnDetail>((a, b) =>
- b.ParentGuid == a.Guid &&
- b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1)
- .Count();
+ var wmsManager = new WmsBaseMangeer();
+ // 鏂板鍏ュ簱鏍¢獙锛堣皟鐢ㄥ瓨鍌ㄨ繃绋嬶級
+ var checkResult = wmsManager.pdaInvJY(
+ db: Db,
+ edtUserNo: entity.userName,
+ barcode: entity.barcode,
+ sectionCode: sectionCode,
+ stockId: mesDepost.DepotId.ToString(),
+ stockOrgId: mesDepost.FSubsidiary,
+ billNo: "", // 鏍规嵁瀹為檯鍗曟嵁鍙蜂紶鍊�
+ transactionNo: "101" // 浜嬪姟绫诲瀷涓庡瓨鍌ㄨ繃绋嬪尮閰�
+ );
- num2 = Db.Queryable<MesInvItemArn>()
- .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
- .InnerJoin<MesInvItemArnDetail>((a, b) => b.ParentGuid == a.Guid
- && b.ItemId == itemBarcodeDetails.ItemId
- && (b.CheckRes == "鍚堟牸" || b.CheckStates == "鐗归噰鐩存帴浣跨敤"))
- .Count();
+ if (Convert.ToInt32(checkResult.result) < 1)
+ throw new Exception($"鍏ュ簱鏍¢獙澶辫触锛歿checkResult.strMsg}");
- switch (num)
- {
- case 0 when num2 == 0:
- case > 0 when num2 == 0:
- freeze = 1;
- break;
- case 0 when num2 > 0:
- throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁鏈夐棶棰橈紒");
- }
- PurchaseInventory result = new PurchaseInventory();
+
+ //num = Db.Queryable<MesInvItemArn>()
+ // .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
+ // .InnerJoin<MesInvItemArnDetail>((a, b) =>
+ // b.ParentGuid == a.Guid &&
+ // b.ItemId == itemBarcodeDetails.ItemId && b.Ischeck == 1)
+ // .Count();
+
+ //num2 = Db.Queryable<MesInvItemArn>()
+ // .Where(a => a.BillNo == itemBarcodeDetails.BillNo)
+ // .InnerJoin<MesInvItemArnDetail>((a, b) => b.ParentGuid == a.Guid
+ // && b.ItemId == itemBarcodeDetails.ItemId
+ // && (b.CheckRes == "鍚堟牸" || b.CheckStates == "鐗归噰鐩存帴浣跨敤"))
+ // .Count();
+
+ //switch (num)
+ //{
+ // case 0 when num2 == 0:
+ // case > 0 when num2 == 0:
+ // freeze = 1;
+ // break;
+ // case 0 when num2 > 0:
+ // throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁鏈夐棶棰橈紒");
+ //}
+
+
+ // 鍒ゆ柇璐т富绫诲瀷
+ var owner_type = wmsManager.GetOwnerType(cgddDetails.DemandOrg);
+ // if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.DemandOrg))
+ // {
+ // owner_type = "BD_OwnerOrg";
+ // }
+ // else
+ // {
+ // // 绗簩灞傚垽鏂細妫�鏌� MES_CUSTOMER
+ // if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
+ // {
+ // owner_type = "BD_Customer";
+ // }
+ // else
+ // {
+ // // 绗笁灞傚垽鏂細妫�鏌� MES_SUPPLIER
+ // if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(cgddDetails.DemandOrg)))
+ // {
+ // owner_type = "BD_Supplier";
+ // }
+ // else
+ // {
+
+ // // 绗洓灞傚垽鏂細鍐嶆妫�鏌� SYS_ORGANIZATION
+ // if (Db.Queryable<SysOrganization>().Any(x => x.Fid == cgddDetails.ReceivingOrg))
+ // {
+ // owner_type = "BD_OwnerOrg";
+ // }
+ // else
+ // {
+ // throw new Exception("鍏ュ簱澶辫触,鍒拌揣鍗曟嵁瀵瑰簲鐨勯渶姹傜粍缁囨湁闂锛�");
+ // }
+ // }
+ // }
+ //}
+
+ var result = new ItemInBaseModel();
UseTransaction(db =>
{
var existingRecord = db.Queryable<MesInvItemIns>()
- .Where(it => it.InsDate.Value.Date == DateTime.Now.Date
+ .Where(it => it.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")
+ && it.TaskNo == itemBarcodeDetails.BillNo
&& it.Status == 0
&& it.TransctionNo == transactionNo
- && it.BillNo == itemBarcodeDetails.BillNo
- && it.DepotsCode == mesDepost.DepotCode)
+ && it.CreateBy == entity.userName
+ && it.BillTypeId == billTypeId
+ && it.DepotsId == mesDepost.DepotId)
.Select(it => new
{
it.Guid,
@@ -134,7 +213,7 @@
})
.First();
- Guid cId = Guid.Empty;
+ var cId = Guid.Empty;
string cBillNo = null;
if (existingRecord != null)
@@ -146,7 +225,7 @@
else
{
cId = Guid.NewGuid();
- cBillNo = BillNo.GetBillNo("IN(鍏ュ簱鍗�)");
+ cBillNo = BillNo.GetBillNo("CGRK(閲囪喘鍏ュ簱)");
var suppNo = db.Queryable<MesSupplier>()
.Where(s => s.Id.ToString() == inventory.SuppId).First();
@@ -166,12 +245,14 @@
CreateDate = DateTime.Now,
LastupdateBy = user,
LastupdateDate = DateTime.Now,
- UrgentFlag = itemBarcodeDetails.UrgentFlag.Value
- ? (byte)1
- : (byte)0,
+ UrgentFlag = itemBarcodeDetails.UrgentFlag.GetValueOrDefault() ? "1" : "0",
CbillNo = itemBarcodeDetails.BillNo,
Fstatus = 0,
- Status = 0
+ Status = 0,
+ ReceiveOrgId = inventory.ReceiveOrgId,
+ InType = "閲囪喘鍏ュ簱",
+ TaskNo = itemBarcodeDetails.BillNo
+ //WorkNo = itemBarcodeDetails.WorkNo
}).IgnoreColumns(true).ExecuteCommand();
}
@@ -207,22 +288,22 @@
IsdepsIn = true
})
.Where(d => d.Guid == detail.Guid)
- .IgnoreColumns(ignoreAllNullColumns: true)
+ .IgnoreColumns(true)
.ExecuteCommand();
// Check if already inserted
var count = db.Queryable<MesInvItemInCItems>()
- .Where(t =>
- t.ItemInId == cId &&
- t.ItemId == detail.ItemId &&
- t.WorkNo == detail.WorkNo &&
- t.WorkLine == detail.WorkLine)
+ .Where(it =>
+ it.ItemInId == cId &&
+ it.ItemId == detail.ItemId &&
+ it.DepotId == mesDepost.DepotId.ToString() &&
+ it.EbelnK3id == detail.EbelnK3id &&
+ it.LineK3id == detail.LineK3id)
.Count();
cSyQty -= remainingQty.Value;
if (count == 0)
- {
// Insert new item into MES_INV_ITEM_IN_C_ITEMS
db.Insertable(new MesInvItemInCItems
{
@@ -234,7 +315,7 @@
DepotCode = mesDepost.DepotCode,
ItemSname = itemBarcodeDetails.ItemSname,
Unit = itemBarcodeDetails.Unit,
- Ebeln = detail.WorkNo,
+ Ebeln = detail.Ebeln,
BillNo = cBillNo,
WorkNo = detail.WorkNo,
CbillNo = detail.CbillNo,
@@ -243,22 +324,22 @@
SuppNo = itemBarcodeDetails.SuppNo,
Remark = itemBarcodeDetails.Memo,
EbelnK3id = detail.EbelnK3id,
- LineK3id = detail.LineK3id
+ LineK3id = detail.LineK3id,
+ DepotId = mesDepost.DepotId.ToString(),
+ itemDabid = itemBarcodeDetails.AboutGuid.ToString()
}).IgnoreColumns(true).ExecuteCommand();
- }
else
- {
db.Updateable<MesInvItemInCItems>()
.SetColumns(it =>
it.Quantity == it.Quantity + remainingQty)
.Where(it =>
it.ItemInId == cId &&
it.ItemId == detail.ItemId &&
- it.WorkNo == detail.WorkNo &&
- it.WorkLine == detail.WorkLine)
- .IgnoreColumns(ignoreAllNullColumns: true)
+ it.DepotId == mesDepost.DepotId.ToString() &&
+ it.EbelnK3id == detail.EbelnK3id &&
+ it.LineK3id == detail.LineK3id)
+ .IgnoreColumns(true)
.ExecuteCommand();
- }
// Insert new detail into MES_INV_ITEM_IN_C_DETAILS
db.Insertable(new MesInvItemInCDetails
@@ -291,7 +372,9 @@
TaskNo = detail.WorkNo,
EbelnK3id = detail.EbelnK3id,
LineK3id = detail.LineK3id,
- ItemId = detail.ItemId
+ ItemId = detail.ItemId,
+ ReceiveOrgId = inventory.ReceiveOrgId,
+ LotNo = cgddDetails.BatchNumber
}).IgnoreColumns(true).ExecuteCommand();
}
else
@@ -303,19 +386,19 @@
OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty)
})
.Where(d => d.Guid == detail.Guid)
- .IgnoreColumns(ignoreAllNullColumns: true)
+ .IgnoreColumns(true)
.ExecuteCommand();
var count = db.Queryable<MesInvItemInCItems>()
- .Where(t =>
- t.ItemInId == cId &&
- t.ItemId == detail.ItemId &&
- t.WorkNo == detail.WorkNo &&
- t.WorkLine == detail.WorkLine)
+ .Where(it =>
+ it.ItemInId == cId &&
+ it.ItemId == detail.ItemId &&
+ it.DepotId == mesDepost.DepotId.ToString() &&
+ it.EbelnK3id == detail.EbelnK3id &&
+ it.LineK3id == detail.LineK3id)
.Count();
if (count == 0)
- {
db.Insertable(new MesInvItemInCItems
{
ItemInId = cId,
@@ -337,22 +420,21 @@
Remark = itemBarcodeDetails.Memo,
EbelnK3id = detail.EbelnK3id,
LineK3id = detail.LineK3id,
- ItemId = detail.ItemId
+ ItemId = detail.ItemId,
+ DepotId = mesDepost.DepotId.ToString()
}).IgnoreColumns(true).ExecuteCommand();
- }
else
- {
db.Updateable<MesInvItemInCItems>()
.SetColumns(it =>
it.Quantity == it.Quantity + cSyQty)
.Where(it =>
it.ItemInId == cId &&
it.ItemId == detail.ItemId &&
- it.WorkNo == detail.WorkNo &&
- it.WorkLine == detail.WorkLine)
- .IgnoreColumns(ignoreAllNullColumns: true)
+ it.DepotId == mesDepost.DepotId.ToString() &&
+ it.EbelnK3id == detail.EbelnK3id &&
+ it.LineK3id == detail.LineK3id)
+ .IgnoreColumns(true)
.ExecuteCommand();
- }
db.Insertable(new MesInvItemInCDetails
{
@@ -385,7 +467,9 @@
TaskNo = detail.WorkNo,
EbelnK3id = detail.EbelnK3id,
LineK3id = detail.LineK3id,
- ItemId = detail.ItemId
+ ItemId = detail.ItemId,
+ ReceiveOrgId = inventory.ReceiveOrgId,
+ LotNo = cgddDetails.BatchNumber
}).IgnoreColumns(true).ExecuteCommand();
cSyQty = 0; // Remaining quantity fulfilled
@@ -400,7 +484,7 @@
BusinessType = 1,
ItemBarcode = itemBarcode,
ItemNo = itemBarcodeDetails.ItemNo,
- LotNo = itemBarcodeDetails.LotNo,
+ LotNo = cgddDetails.BatchNumber,
EpFlag = true,
Quantity = itemBarcodeDetails.Quantity,
ToInvDepotsCode = mesDepost.DepotCode,
@@ -425,16 +509,21 @@
}
else
{
+ var detailone = db.Queryable<MesInvItemArnDetail>()
+ .Where(d =>
+ d.Guid == itemBarcodeDetails.AboutGuid)
+ .First();
+
// 妫�鏌ユ槸鍚﹀瓨鍦ㄤ簬 MES_INV_ITEM_IN_C_ITEMS 琛�
var existingCount = db.Queryable<MesInvItemInCItems>()
- .Where(t => t.ItemInId == cId &&
- t.ItemId == itemBarcodeDetails.ItemId &&
- t.WorkNo == itemBarcodeDetails.WorkNo &&
- t.WorkLine == itemBarcodeDetails.WorkLine)
+ .Where(it =>
+ it.ItemInId == cId &&
+ it.ItemId == detailone.ItemId &&
+ it.DepotId == mesDepost.DepotId.ToString() &&
+ it.itemDabid == itemBarcodeDetails.AboutGuid.ToString())
.Count();
if (existingCount == 0)
- {
// 涓嶅瓨鍦ㄦ椂鎻掑叆鏂拌褰�
db.Insertable(new MesInvItemInCItems
{
@@ -457,23 +546,24 @@
Remark = itemBarcodeDetails.Memo,
EbelnK3id = itemBarcodeDetails.EbelnK3id,
LineK3id = itemBarcodeDetails.LineK3id,
- ItemId = itemBarcodeDetails.ItemId
+ ItemId = itemBarcodeDetails.ItemId,
+ DepotId = mesDepost.DepotId.ToString(),
+ itemDabid = itemBarcodeDetails.AboutGuid.ToString()
}).IgnoreColumns(true).ExecuteCommand();
- }
else
- {
// 瀛樺湪鏃舵洿鏂版暟閲�
db.Updateable<MesInvItemInCItems>()
- .SetColumns(it =>
- it.Quantity ==
- it.Quantity + itemBarcodeDetails.Quantity)
- .Where(it => it.ItemInId == cId &&
- it.ItemId == itemBarcodeDetails.ItemId &&
- it.WorkNo == itemBarcodeDetails.WorkNo &&
- it.WorkLine == itemBarcodeDetails.WorkLine)
- .IgnoreColumns(ignoreAllNullColumns: true)
+ .SetColumns(it => new MesInvItemInCItems
+ {
+ Quantity = SqlFunc.IsNull(it.Quantity, 0) + itemBarcodeDetails.Quantity // 纭繚 Quantity 涓嶄负 null
+ })
+ .Where(it =>
+ it.ItemInId == cId &&
+ it.ItemId == detailone.ItemId &&
+ it.DepotId == mesDepost.DepotId.ToString() &&
+ it.itemDabid == itemBarcodeDetails.AboutGuid.ToString())
+ //.IgnoreColumns(true) // 淇濈暀 IgnoreColumns
.ExecuteCommand();
- }
// 鎻掑叆 mes_inv_item_in_c_details 琛�
db.Insertable(new MesInvItemInCDetails
@@ -486,7 +576,7 @@
EpFlag = true,
WorkType = 1,
ItemNo = itemBarcodeDetails.ItemNo,
- LotNo = itemBarcodeDetails.LotNo,
+ LotNo = cgddDetails.BatchNumber,
SuppId = itemBarcodeDetails.SuppId,
SuppNo = itemBarcodeDetails.SuppNo,
DepotCode = mesDepost.DepotCode,
@@ -512,7 +602,9 @@
Ischeck = true,
CheckDate = inventoryDetails.CheckDate,
CheckRes = inventoryDetails.CheckRes,
- CheckStates = inventoryDetails.CheckStates
+ CheckStates = inventoryDetails.CheckStates,
+ ReceiveOrgId = inventory.ReceiveOrgId,
+ DepotId = Convert.ToInt64(mesDepost.DepotId.ToString())
}).IgnoreColumns(true).ExecuteCommand();
// 鎻掑叆 mes_inv_business2 琛�
@@ -550,11 +642,13 @@
// 鎻掑叆 mes_inv_item_stocks 琛�
}
+
+
db.Insertable(new MesInvItemStocks
{
TaskNo = itemBarcodeDetails.TaskNo,
ItemBarcode = itemBarcode,
- ItemNo = itemBarcodeDetails.ItemNo,
+ ItemNo = cgddDetails.BatchNumber,
LotNo = itemBarcodeDetails.LotNo,
Quantity = itemBarcodeDetails.Quantity,
DepotsCode = mesDepost.DepotCode,
@@ -570,25 +664,31 @@
EbelnK3id = itemBarcodeDetails.EbelnK3id,
LineK3id = itemBarcodeDetails.LineK3id,
ItemId = itemBarcodeDetails.ItemId,
- BillNo = itemBarcodeDetails.BillNo
+ BillNo = itemBarcodeDetails.BillNo,
+ DepotId = Convert.ToInt32(mesDepost.DepotId),
+ OwnerId = cgddDetails.DemandOrg,
+ OwnerType = owner_type,
+ StockOrgId = mesDepost.FSubsidiary,
+ IndepUserCode = user
}).IgnoreColumns(true).ExecuteCommand();
itemBarcodeDetails.Hbdy ??= 0;
if (itemBarcodeDetails.Hbdy != 1)
{
+ //鏇存柊鏀舵枡鍗曟槑缁�
db.Updateable<MesInvItemArnDetail>()
.SetColumns(d => new MesInvItemArnDetail
{
OkRkqty = (int)((d.OkRkqty ?? 0) + cSyQty)
})
- .Where(d => d.Guid == inventoryDetails.Guid)
+ .Where(d => d.Guid == itemBarcodeDetails.AboutGuid)
.ExecuteCommand();
var first = db
.Queryable<MesInvItemArnDetail>()
.Where(b =>
- b.Guid == inventoryDetails.Guid)
+ b.Guid == itemBarcodeDetails.AboutGuid)
.Select(b => new
{
TotalQuantity =
@@ -601,12 +701,10 @@
var TotalOkRkQty = first.TotalOkRkQty ?? 0;
if (TotalQuantity == TotalOkRkQty)
- {
db.Updateable<MesInvItemArnDetail>()
.SetColumns(s => s.IsdepsIn == true)
- .Where(s => s.Guid == inventoryDetails.Guid)
+ .Where(s => s.Guid == itemBarcodeDetails.AboutGuid)
.ExecuteCommand();
- }
var totalSummary = db.Queryable<MesInvItemArnDetail>()
@@ -622,17 +720,15 @@
if ((totalSummary.TotalQuantity ?? 0) ==
(totalSummary.TotalOkRkQty ?? 0))
- {
db.Updateable<MesInvItemArn>()
.SetColumns(it => it.Status == 1)
.Where(it => it.BillNo == itemBarcodeDetails.BillNo)
.ExecuteCommand();
- }
var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>()
- .Where(it => it.WorkLine == itemBarcodeDetails.WorkLine &&
+ .Where(it => it.ItemId == itemBarcodeDetails.ItemId &&
it.WorkNo == itemBarcodeDetails.WorkNo &&
- it.CbillNo == itemBarcodeDetails.BillNo)
+ it.ItemInId == cId)
.Sum(it => it.Quantity);
var detailSummary = db.Queryable<MesInvItemArnDetail>()
@@ -649,19 +745,56 @@
var diffQty = comeQty - invQty;
if (detailSummary == null)
- {
throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟槑缁嗭紒");
- }
var mesItems = db.Queryable<MesItems>()
.Where(s => s.Id == itemBarcodeDetails.ItemId).First();
- result.Message =
- $"鏉$爜鏁伴噺 {itemBarcodeDetails.Quantity},閲囪喘璁㈠崟 {itemBarcodeDetails.WorkNo} 椤规 {itemBarcodeDetails.WorkLine} 鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}";
+ //result.Message =
+ // $"鏉$爜鏁伴噺 {itemBarcodeDetails.Quantity},閲囪喘璁㈠崟 {itemBarcodeDetails.WorkNo} 椤规 {itemBarcodeDetails.WorkLine} 鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}";
+ result.Message = $"鐗╂枡{mesItems.ItemNo}鍏ュ簱鎴愬姛鏁伴噺{itemBarcodeDetails.Quantity.ToString()}";
+
+ result.itemDetail = mesItems;
+
+ result.ItemInDetails = db.Queryable<MesInvItemInCItems,MesItems>(
+ (a, b) => new JoinQueryInfos(
+ JoinType.Left,
+ a.ItemId == b.ItemId)
+ )
+ .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId)
+ .Select<dynamic>((a, b) => new
+ {
+ ItemNo = b.ItemNo,
+ ItemName = b.ItemName,
+ ItemModel = b.ItemModel,
+ FQty = a.Quantity, // 鐢宠鏁伴噺
+ FMaterialId = b.ItemId,
+ Id = b.Guid.ToString()
+ })
+ .ToList();
+
+ result.ItemBarCDetails = db.Queryable<MesInvItemInCDetails, MesItems>(
+ (a, b) => new JoinQueryInfos(
+ JoinType.Left,
+ a.ItemId == b.ItemId)
+ )
+ .Where(a => a.ItemInId == cId && a.ItemId == itemBarcodeDetails.ItemId)
+ .Select<dynamic>((a, b) => new
+ {
+ ItemNo = b.ItemNo,
+ ItemName = b.ItemName,
+ ItemModel = b.ItemModel,
+ FQty = a.Quantity, // 鐢宠鏁伴噺
+ FMaterialId = b.ItemId,
+ Id = a.Guid.ToString(),
+ kw = a.DepotSectionCode,
+ barcode = a.ItemBarcode
+ })
+ .ToList();
- result.ItemNo = mesItems.ItemNo;
- result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
+ //result.ItemNo = mesItems.ItemNo;
+ result.SumQuantity = Convert.ToDecimal(invQty);
return 1;
}
@@ -681,23 +814,19 @@
if ((totalSummary.TotalQuantity ?? 0) ==
(totalSummary.TotalOkRkQty ?? 0))
- {
db.Updateable<MesInvItemArn>()
.SetColumns(it => it.Status == 1)
.Where(it => it.BillNo == itemBarcodeDetails.BillNo)
.ExecuteCommand();
- }
// Step 2: Calculate total sum from `mes_inv_item_in_c_details`
var totalCDetailsQuantity = db.Queryable<MesInvItemInCDetails>()
- .Where(it => it.CbillNo == itemBarcodeDetails.BillNo &&
- it.ItemId == itemBarcodeDetails.ItemId)
+ .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
.Sum(it => it.Quantity);
// Step 3: Calculate comeQty and invQty from `mes_inv_item_arn_detail`
var detailSummary = db.Queryable<MesInvItemArnDetail>()
- .Where(it => it.CbillNo == itemBarcodeDetails.BillNo &&
- it.ItemId == itemBarcodeDetails.ItemId)
+ .Where(it => it.Guid == itemBarcodeDetails.AboutGuid)
.Select(it => new
{
TotalComeQty = SqlFunc.AggregateSum(it.Quantity),
@@ -706,9 +835,7 @@
.First();
if (detailSummary == null)
- {
throw new Exception("姝ゆ潯鐮佹壘涓嶅埌瀵瑰簲鏀惰揣鍗曟槑缁嗭紒");
- }
var comeQty = detailSummary.TotalComeQty ?? 0;
var invQty = detailSummary.TotalInvQty ?? 0;
@@ -722,7 +849,7 @@
$" 鏉$爜鏁伴噺:{itemBarcodeDetails.Quantity},鐗╂枡 {mesItems.ItemNo} 鏈鍏ュ簱鎬绘暟锛歿totalCDetailsQuantity} 鎬诲埌 {comeQty} 宸插叆 {invQty} 娆� {diffQty}";
- result.ItemNo = mesItems.ItemNo;
+ //result.ItemNo = mesItems.ItemNo;
result.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity);
}
@@ -732,25 +859,30 @@
if (mesInvItemInCDetails == null)
throw new Exception("鐗╂枡鍏ュ簱鏉$爜鏄庣粏涓嶅瓨鍦�"); // 鎶涘嚭寮傚父浠ヤ緵鍓嶅彴澶勭悊
+ // 鍒涘缓 鎻掑叆鏃ュ織
+ var logService = new LogService();
+ var LogMsg = "銆怭DA銆戦噰璐叆搴撱�傛潯鐮併��" + entity.barcode + "銆� 鍏ュ簱鍗曞彿銆�" + cBillNo + "銆�";
+ logService.CreateLog(db, entity.userName, inventory.Guid.ToString(), "MES_INV_ITEM_ARN", LogMsg, inventory.BillNo);
+
return 1;
});
var purchaseInventory = getPurchaseInventory(entity);
- result.ItemIns = purchaseInventory.ItemIns;
- result.ItemInDetails = purchaseInventory.ItemInDetails;
- result.InvItemInCDetails = purchaseInventory.InvItemInCDetails;
+
+ //result.ItemInDetails = purchaseInventory.ItemInDetails;
+ //result.InvItemInCDetails = purchaseInventory.InvItemInCDetails;
return result;
}
- public PurchaseInventory getPurchaseInventory(WarehouseQuery query)
+ public ItemInBaseModel getPurchaseInventory(WarehouseQuery query)
{
- return new PurchaseInventory
+ return new ItemInBaseModel
{
- ItemIns = GetInvItemInsList(query).Items[0],
- ItemInDetails = GetItemInDetails(query.id),
- InvItemInCDetails = GetInvItemInCDetails(query.id)
+ //ItemIns = GetInvItemInsList(query).Items[0],
+ //ItemInDetails = GetItemInDetails(query.id),
+ //InvItemInCDetails = GetInvItemInCDetails(query.id)
};
}
@@ -758,21 +890,19 @@
WarehouseQuery query)
{
var parsedGuid = Guid.Empty;
- if (string.IsNullOrEmpty(query.id))
+ if (!string.IsNullOrEmpty(query.id))
{
- return ([], 0);
+ var isValid = Guid.TryParse(query.id, out parsedGuid);
+ if (!isValid)
+ throw new ApplicationException("GUID杞崲閿欒");
}
-
- bool isValid = Guid.TryParse(query.id, out parsedGuid);
- if (!isValid)
- throw new ApplicationException("GUID杞崲閿欒");
var totalCount = 0;
var result = Db.Queryable<MesInvItemIns, MesDepots, MesSupplier>(
(a, b, c) =>
new JoinQueryInfos(JoinType.Left,
- a.DepotsCode == b.DepotCode,
- JoinType.Left, a.SuppNo == c.SuppNo))
+ a.DepotsId == b.DepotId,
+ JoinType.Left, a.SuppId == c.Id.ToString()))
.WhereIF(UtilityHelper.CheckGuid(parsedGuid),
(a, b, c) => a.Guid == parsedGuid)
.Select((a, b, c) => new MesInvItemIns
@@ -798,12 +928,9 @@
{
//string杞琯uid
var parsedGuid = Guid.Empty;
- if (string.IsNullOrEmpty(pid))
- {
- return ( []);
- }
+ if (string.IsNullOrEmpty(pid)) return [];
- bool isValid = Guid.TryParse(pid, out parsedGuid);
+ var isValid = Guid.TryParse(pid, out parsedGuid);
if (!isValid)
throw new ApplicationException("GUID杞崲閿欒");
@@ -821,7 +948,7 @@
ItemNo = c.ItemNo,
ItemSname = g.ItemSname,
Quantity = g.Quantity,
- Unit = d.Fname,
+ Unit = d.Fname
})
.ToList();
@@ -832,12 +959,9 @@
{
//string杞琯uid
var parsedGuid = Guid.Empty;
- if (string.IsNullOrEmpty(pid))
- {
- return ( []);
- }
+ if (string.IsNullOrEmpty(pid)) return [];
- bool isValid = Guid.TryParse(pid, out parsedGuid);
+ var isValid = Guid.TryParse(pid, out parsedGuid);
if (!isValid)
throw new ApplicationException("GUID杞崲閿欒");
@@ -845,7 +969,7 @@
(g, c, d) => new JoinQueryInfos(
JoinType.Left,
g.ItemId == c.Id, JoinType.Inner,
- d.Id == Convert.ToDecimal(c.ItemUnit)
+ d.Id.ToString() == c.Fpurchaseunitid
)
).WhereIF(UtilityHelper.CheckGuid(parsedGuid),
(g, c, d) => g.ItemInId == parsedGuid)
@@ -886,8 +1010,12 @@
}
var ErpUrl = AppsettingsUtility.Settings.ProductionErpUrl;
+
+ var newGuid = Guid.NewGuid();
var message = new MessageCenter
{
+ Guid = newGuid,
+ //Pid = newGuid,
TableName = tableName,
Url = ErpUrl,
Status = 1,
@@ -911,11 +1039,10 @@
var message = MesToErpParam(query);
var executeReturnIdentity =
- Db.Insertable(message).ExecuteReturnIdentity();
+ Db.Insertable(message).ExecuteCommand();
if (executeReturnIdentity > 0)
{
- // message.Guid = executeReturnIdentity;
- message.Pid = executeReturnIdentity;
+ message.Pid = message.Guid;
return message;
}
@@ -943,7 +1070,7 @@
.SetColumns(x => x.Status == entity.status)
.SetColumns(x => x.InsDate == entity.date)
.Where(x => x.BillNo == entity.billNo)
- .IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommand() > 0;
+ .IgnoreColumns(true).ExecuteCommand() > 0;
}
private string GetErpParameters(string? billNo)
@@ -959,24 +1086,20 @@
MesInvItemArnDetail>(
(g, c, d, a) => new JoinQueryInfos(
JoinType.Left,
- g.ItemNo == c.ItemNo && g.Company == c.Company &&
- g.Factory == c.Factory, JoinType.Inner,
- d.Id == Convert.ToDecimal(c.ItemUnit),
- JoinType.Inner,
- a.Ebeln == g.WorkNo && a.WorkLine == g.EbelnLineNo
- && g.CbillNo == a.CbillNo
+ g.ItemId == c.Id, JoinType.Inner,
+ d.Id.ToString() == c.Fpurchaseunitid,
+ JoinType.Inner, a.Ebeln == g.WorkNo && g.CbillNo == a.CbillNo
)
).Where((g, c, d, a) => g.BillNo == billNo).Select<Material>(
(g, c, d, a) => new Material
{
- // FstockId = g.DepotCode,
- // FuintId = d.Fnumber,
- // FsrcEntryId = a.Id,
- // FmesEntryId = g.Id,
- // FmaterialId = a.ItemNo,
- // DepotSectionCode = g.DepotSectionCode,
- // WorkNo = g.WorkNo,
- // Frealqty = g.Quantity
+ FMaterialId = c.ItemNo,
+ FRealQty = g.Quantity.ToString(),
+ FStockId = g.DepotCode,
+ FLot = a.CbillNo,
+ FUnitID = d.Fnumber,
+ FsrcEntryId = a.Guid.ToString(),
+ FMesEntryid = g.Guid.ToString()
}).ToList();
@@ -986,12 +1109,13 @@
var jsonEntries = materials.Select(d => new
{
- // FMaterialId = d.FmaterialId,
- // FUintId = d.FuintId,
- // FRealQty = d.Frealqty,
- // FStockId = d.FstockId,
- // FSRCENTRYID = d.FsrcEntryId.ToString(),
- // F_MES_ENTRYID = d.FmesEntryId.ToString()
+ d.FMaterialId,
+ d.FRealQty,
+ d.FStockId,
+ d.FLot,
+ FUintId = d.FUnitID,
+ FSRCENTRYID = d.FsrcEntryId,
+ F_MES_ENTRYID = d.FMesEntryid
}).ToList();
var fdate = DateTime.Now.ToString("yyyy-MM-dd");
--
Gitblit v1.9.3