From 14affa91315d19545a992116c52426cd3d7d7c44 Mon Sep 17 00:00:00 2001 From: liangjunyu <13726812+shifang-tianhua_0@user.noreply.gitee.com> Date: Fri, 12 Dec 2025 14:46:03 +0800 Subject: [PATCH] 1 --- .../BOSPlugIn/Sal_Order/Bill.cs | 79 +++-- .../BOSPlugIn/Sal_Order/Bill2.cs | 318 ++++++++++++++++++ .../BOSPlugIn/Sal_OutStock/Bill.cs | 261 +++++++++++++- .../Common/FormIdConstants.cs | 45 +++ .../Gatedge.K3.Pilot.PlugIn.csproj | 5 + Gatedge.K3.Pilot.PlugIn/Models/POPush.cs | 16 + .../Services/DBService/SalOutStockDAL.cs | 97 ++++++ 查询.sql | 131 ++++---- 8 files changed, 853 insertions(+), 99 deletions(-) create mode 100644 Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill2.cs create mode 100644 Gatedge.K3.Pilot.PlugIn/Common/FormIdConstants.cs create mode 100644 Gatedge.K3.Pilot.PlugIn/Models/POPush.cs create mode 100644 Gatedge.K3.Pilot.PlugIn/Services/DBService/SalOutStockDAL.cs diff --git a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill.cs b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill.cs index 9f1ac53..5e69aef 100644 --- a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill.cs +++ b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill.cs @@ -74,16 +74,11 @@ namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_Order } //实际户折扣率 - var F_ActualDiscountRate = settlementPrice == 0 ? 100M : price / settlementPrice * 100; + var F_ActualDiscountRate = CalculateActualDiscountRate(price, settlementPrice); this.Model.SetValue("F_ActualDiscountRate", F_ActualDiscountRate, e.Row); this.View.InvokeFieldUpdateService("F_ActualDiscountRate", e.Row); } - - ////普通客户折扣率 - //this.Model.SetValue("F_CustSaleDiscountRate", F_CustSaleDiscountRate); - ////大客户折扣率 - //this.Model.SetValue("F_BigCustSaleDiscountRate", F_BigCustSaleDiscountRate); } //销售价格 @@ -143,16 +138,12 @@ namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_Order } //实际户折扣率 - var F_ActualDiscountRate = settlementPrice == 0 ? 100M : price / settlementPrice * 100; + var F_ActualDiscountRate = CalculateActualDiscountRate(price, settlementPrice); this.Model.SetValue("F_ActualDiscountRate", F_ActualDiscountRate, e.Row); this.View.InvokeFieldUpdateService("F_ActualDiscountRate", e.Row); } - ////普通客户折扣率 - //this.Model.SetValue("F_CustSaleDiscountRate", F_CustSaleDiscountRate); - ////大客户折扣率 - //this.Model.SetValue("F_BigCustSaleDiscountRate", F_BigCustSaleDiscountRate); } //客户 @@ -222,19 +213,16 @@ namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_Order } //大客户折扣率 - var F_ActualDiscountRate = settlementPrice == 0 ? 100M : price / settlementPrice * 100; + var F_ActualDiscountRate = CalculateActualDiscountRate(price, settlementPrice); this.Model.SetValue("F_ActualDiscountRate", F_ActualDiscountRate, rowIndex); this.View.InvokeFieldUpdateService("F_ActualDiscountRate", rowIndex); } - ////普通客户折扣率 - //this.Model.SetValue("F_CustSaleDiscountRate", F_CustSaleDiscountRate); - ////大客户折扣率 - //this.Model.SetValue("F_BigCustSaleDiscountRate", F_BigCustSaleDiscountRate); } } + //实际折扣率 if (e.Field.Key.EqualsIgnoreCase("F_ActualDiscountRate")) { //普通客户折扣率 @@ -256,31 +244,28 @@ namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_Order { isBigCustFlag = creditClassification["Number"].ToString().EqualsIgnoreCase("KHXYFL013"); } - } - var actualDiscountRate = 0M; - foreach (var entry in entrys) - { - var rowIndex = this.View.Model.GetRowIndex(details, entry); - - var materialId_Id = entry["MaterialId_Id"].Long2Int(); - - var price = entry["TaxPrice"].Convert(); - - if (materialId_Id > 0) + var actualDiscountRate = 0M; + var actualDiscountRateList = new List(); + foreach (var entry in entrys) { - var tempRate = entry["ActualDiscountRate"].Convert(); + var rowIndex = this.View.Model.GetRowIndex(details, entry); - if (actualDiscountRate == 0) - actualDiscountRate = tempRate; - else - actualDiscountRate = tempRate < actualDiscountRate ? tempRate : actualDiscountRate; + var materialId_Id = entry["MaterialId_Id"].Long2Int(); + + var price = entry["TaxPrice"].Convert(); + + if (materialId_Id > 0) + { + var tempRate = entry["ActualDiscountRate"].Convert(); + actualDiscountRateList.Add(tempRate); + //actualDiscountRate = tempRate < actualDiscountRate ? tempRate : actualDiscountRate; + } } - } - if (custId_Id > 0) - { - if (isBigCustFlag) + actualDiscountRate = actualDiscountRateList.Count == 0 ? 0M : actualDiscountRateList.Min(); + + if (!isBigCustFlag) { //普通客户折扣率 this.Model.SetValue("F_CustSaleDiscountRate", actualDiscountRate); @@ -295,5 +280,27 @@ namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_Order } } + + /// + /// 计算实际折扣率 + /// + /// + /// + /// + private decimal CalculateActualDiscountRate(decimal price, decimal settlementPrice) + { + var actualDiscountRate = 0M; + + if (price != 0 && settlementPrice == 0) + actualDiscountRate = 100; + else if (price == 0 && settlementPrice != 0) + actualDiscountRate = 0; + else if (price == 0 && settlementPrice == 0) + actualDiscountRate = 0; + else + actualDiscountRate = price / settlementPrice; + + return actualDiscountRate; + } } } \ No newline at end of file diff --git a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill2.cs b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill2.cs new file mode 100644 index 0000000..f8ca50d --- /dev/null +++ b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill2.cs @@ -0,0 +1,318 @@ +using Gatedge.K3.Pilot.PlugIn.Services.DBService; +using Kingdee.BOS.Core.Bill.PlugIn; +using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; +using Kingdee.BOS.Orm.DataEntity; +using Kingdee.BOS.Util; +using Kingdee.K3.BD.NewCode.Core.Utils; +using Kingdee.K3.Core.SCM.IOS; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_Order +{ + [HotUpdate, Description("销售订单_表单插件")] + public class Bill2 : AbstractBillPlugIn + { + public override void DataChanged(DataChangedEventArgs e) + { + base.DataChanged(e); + //物料 + if (e.Field.Key.EqualsIgnoreCase("FMaterialId")) + { + this.Model.SetValue("F_AGREEPRICE", 0, e.Row); + this.Model.SetValue("F_BIGCUSTSETTLEPRICE", 0, e.Row); + this.Model.SetValue("F_ActualDiscountRate", 0, e.Row); + + //表头大客户折扣率 + var F_BigCustSaleDiscountRate = this.View.Model.GetValue("F_BigCustSaleDiscountRate").Convert(); + //表头普通客户折扣率 + var F_CustSaleDiscountRate = this.View.Model.GetValue("F_CustSaleDiscountRate").Convert(); + + var materialId_Id = e.NewValue.Long2Int(); + if (materialId_Id == 0) + return; + + var custId_Id = this.View.Model.DataObject["CustId_Id"].Long2Int(); + if (custId_Id == 0) + return; + + bool isBigCustFlag = false; + var custId = this.View.Model.DataObject["CustId"] as DynamicObject; + var creditClassification = custId["F_CreditClassification"] as DynamicObject; + if (creditClassification != null && creditClassification["Number"] != null) + { + isBigCustFlag = creditClassification["Number"].ToString().EqualsIgnoreCase("KHXYFL013"); + } + + var dal = new BDCustPriceDAL(this.Context); + var dateTime = this.View.Model.DataObject["Date"].Convert().ToString("yyyy-MM-dd"); + var resData = dal.GetMaterialPrice(materialId_Id, custId_Id, dateTime); + if (resData != null && resData.Count > 0) + { + var data = resData[0]; + + //销售价格 + var price = this.Model.GetValue("FTaxPrice", e.Row).Convert(); + //结算价格 + var settlementPrice = data["F_JSJ"].Convert(); + + if (isBigCustFlag) + { + // 大客户结算价 + var bigCustSettlementPrice = data["F_BIGCUSTSETTLEPRICE"].Convert(); + + if (bigCustSettlementPrice != 0) + settlementPrice = bigCustSettlementPrice; + + this.Model.SetValue("F_BIGCUSTSETTLEPRICE", bigCustSettlementPrice, e.Row); + } + else + { + // 协议价 + var F_AGREEPRICE = data["F_AGREEPRICE"].Convert(); + this.Model.SetValue("F_AGREEPRICE", F_AGREEPRICE, e.Row); + } + + //实际户折扣率 + var F_ActualDiscountRate = CalculateActualDiscountRate(price, settlementPrice); + this.Model.SetValue("F_ActualDiscountRate", F_ActualDiscountRate, e.Row); + this.View.InvokeFieldUpdateService("F_ActualDiscountRate", e.Row); + + } + } + + //销售价格 + if (e.Field.Key.EqualsIgnoreCase("FTaxPrice")) + { + this.Model.SetValue("F_AGREEPRICE", 0, e.Row); + this.Model.SetValue("F_BIGCUSTSETTLEPRICE", 0, e.Row); + this.Model.SetValue("F_ActualDiscountRate", 0, e.Row); + + //表头大客户折扣率 + var F_BigCustSaleDiscountRate = this.View.Model.GetValue("F_BigCustSaleDiscountRate").Convert(); + //表头普通客户折扣率 + var F_CustSaleDiscountRate = this.View.Model.GetValue("F_CustSaleDiscountRate").Convert(); + + var price = e.NewValue.Convert(); + + var custId_Id = this.View.Model.DataObject["CustId_Id"].Long2Int(); + if (custId_Id == 0) + return; + + bool isBigCustFlag = false; + var custId = this.View.Model.DataObject["CustId"] as DynamicObject; + var creditClassification = custId["F_CreditClassification"] as DynamicObject; + if (creditClassification != null && creditClassification["Number"] != null) + { + isBigCustFlag = creditClassification["Number"].ToString().EqualsIgnoreCase("KHXYFL013"); + } + + var materialId = this.View.Model.GetValue("FMaterialId", e.Row) as DynamicObject; + var materialId_Id = 0; + + var dal = new BDCustPriceDAL(this.Context); + var dateTime = this.View.Model.DataObject["Date"].Convert().ToString("yyyy-MM-dd"); + + if (materialId != null) + materialId_Id = materialId["Id"].Long2Int(); + + var resData = dal.GetMaterialPrice(materialId_Id, custId_Id, dateTime); + if (resData != null && resData.Count > 0) + { + var data = resData[0]; + + //结算价格 + var settlementPrice = data["F_JSJ"].Convert(); + + if (isBigCustFlag) + { + // 大客户结算价 + var bigCustSettlementPrice = data["F_BIGCUSTSETTLEPRICE"].Convert(); + + if (bigCustSettlementPrice != 0) + settlementPrice = bigCustSettlementPrice; + + this.Model.SetValue("F_BIGCUSTSETTLEPRICE", bigCustSettlementPrice, e.Row); + } + else + { + // 协议价 + var F_AGREEPRICE = data["F_AGREEPRICE"].Convert(); + this.Model.SetValue("F_AGREEPRICE", F_AGREEPRICE, e.Row); + } + + //实际户折扣率 + var F_ActualDiscountRate = CalculateActualDiscountRate(price, settlementPrice); + this.Model.SetValue("F_ActualDiscountRate", F_ActualDiscountRate, e.Row); + this.View.InvokeFieldUpdateService("F_ActualDiscountRate", e.Row); + + } + + } + + //客户 + if (e.Field.Key.EqualsIgnoreCase("FCustID")) + { + var custId_Id = e.NewValue.Long2Int(); + + var dal = new BDCustPriceDAL(this.Context); + var dateTime = this.View.Model.DataObject["Date"].Convert().ToString("yyyy-MM-dd"); + var details = this.View.BusinessInfo.GetEntity("FSaleOrderEntry"); + if (details != null) + { + //表头大客户折扣率 + var F_BigCustSaleDiscountRate = this.View.Model.GetValue("F_BigCustSaleDiscountRate").Convert(); + //表头普通客户折扣率 + var F_CustSaleDiscountRate = this.View.Model.GetValue("F_CustSaleDiscountRate").Convert(); + + var entrys = this.View.Model.GetEntityDataObject(details); + + bool isBigCustFlag = false; + if (custId_Id > 0) + { + var custId = this.View.Model.DataObject["CustId"] as DynamicObject; + var creditClassification = custId["F_CreditClassification"] as DynamicObject; + if (creditClassification != null && creditClassification["Number"] != null) + { + isBigCustFlag = creditClassification["Number"].ToString().EqualsIgnoreCase("KHXYFL013"); + } + } + + foreach (var entry in entrys) + { + var rowIndex = this.View.Model.GetRowIndex(details, entry); + + var materialId_Id = entry["MaterialId_Id"].Long2Int(); + + var price = entry["TaxPrice"].Convert(); + var settlementPrice = 0M; + this.Model.SetValue("F_AGREEPRICE", 0, rowIndex); + this.Model.SetValue("F_BIGCUSTSETTLEPRICE", 0, rowIndex); + this.Model.SetValue("F_ActualDiscountRate", 0, rowIndex); + + if (materialId_Id > 0 && custId_Id > 0) + { + var resData = dal.GetMaterialPrice(materialId_Id, custId_Id, dateTime); + + if (resData != null && resData.Any()) + { + var data = resData.FirstOrDefault(); + + //结算价格 + settlementPrice = data["F_JSJ"].Convert(); + + if (isBigCustFlag) + { + // 大客户结算价 + var bigCustSettlementPrice = data["F_BIGCUSTSETTLEPRICE"].Convert(); + + if (bigCustSettlementPrice != 0) + settlementPrice = bigCustSettlementPrice; + + this.Model.SetValue("F_BIGCUSTSETTLEPRICE", bigCustSettlementPrice, e.Row); + } + else + { + // 协议价 + var F_AGREEPRICE = data["F_AGREEPRICE"].Convert(); + this.Model.SetValue("F_AGREEPRICE", F_AGREEPRICE, rowIndex); + } + } + } + + //大客户折扣率 + var F_ActualDiscountRate = CalculateActualDiscountRate(price, settlementPrice); + this.Model.SetValue("F_ActualDiscountRate", F_ActualDiscountRate, rowIndex); + this.View.InvokeFieldUpdateService("F_ActualDiscountRate", rowIndex); + + } + + } + } + + //实际折扣率 + if (e.Field.Key.EqualsIgnoreCase("F_ActualDiscountRate")) + { + //普通客户折扣率 + this.Model.SetValue("F_CustSaleDiscountRate", 0); + //大客户折扣率 + this.Model.SetValue("F_BigCustSaleDiscountRate", 0); + + var details = this.View.BusinessInfo.GetEntity("FSaleOrderEntry"); + if (details != null) + { + var entrys = this.View.Model.GetEntityDataObject(details); + bool isBigCustFlag = false; + var custId_Id = this.View.Model.DataObject["CustId_Id"].Long2Int(); + if (custId_Id > 0) + { + var custId = this.View.Model.DataObject["CustId"] as DynamicObject; + var creditClassification = custId["F_CreditClassification"] as DynamicObject; + if (creditClassification != null && creditClassification["Number"] != null) + { + isBigCustFlag = creditClassification["Number"].ToString().EqualsIgnoreCase("KHXYFL013"); + } + + var actualDiscountRate = 0M; + var actualDiscountRateList = new List(); + foreach (var entry in entrys) + { + var rowIndex = this.View.Model.GetRowIndex(details, entry); + + var materialId_Id = entry["MaterialId_Id"].Long2Int(); + + var price = entry["TaxPrice"].Convert(); + + if (materialId_Id > 0) + { + var tempRate = entry["ActualDiscountRate"].Convert(); + actualDiscountRateList.Add(tempRate); + //actualDiscountRate = tempRate < actualDiscountRate ? tempRate : actualDiscountRate; + } + } + + actualDiscountRate = actualDiscountRateList.Count == 0 ? 0M : actualDiscountRateList.Min(); + + if (!isBigCustFlag) + { + //普通客户折扣率 + this.Model.SetValue("F_CustSaleDiscountRate", actualDiscountRate); + } + else + { + //大客户折扣率 + this.Model.SetValue("F_BigCustSaleDiscountRate", actualDiscountRate); + } + } + } + } + + } + + /// + /// 计算实际折扣率 + /// + /// + /// + /// + private decimal CalculateActualDiscountRate(decimal price, decimal settlementPrice) + { + var actualDiscountRate = 0M; + + if (price != 0 && settlementPrice == 0) + actualDiscountRate = 100; + else if (price == 0 && settlementPrice != 0) + actualDiscountRate = 0; + else if (price == 0 && settlementPrice == 0) + actualDiscountRate = 0; + else + actualDiscountRate = price / settlementPrice; + + return actualDiscountRate; + } + } +} \ No newline at end of file diff --git a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_OutStock/Bill.cs b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_OutStock/Bill.cs index df5c687..c6cf809 100644 --- a/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_OutStock/Bill.cs +++ b/Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_OutStock/Bill.cs @@ -1,5 +1,21 @@ -using Kingdee.BOS.Core.Bill.PlugIn; +using Gatedge.K3.Pilot.PlugIn.Common; +using Gatedge.K3.Pilot.PlugIn.Models; +using Gatedge.K3.Pilot.PlugIn.Services.DBService; +using Kingdee.BOS.App; +using Kingdee.BOS.Contracts; +using Kingdee.BOS.Core.Bill.PlugIn; +using Kingdee.BOS.Core.Const; +using Kingdee.BOS.Core.DynamicForm; +using Kingdee.BOS.Core.DynamicForm.Operation; +using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; +using Kingdee.BOS.Core.List; +using Kingdee.BOS.Core.Metadata; +using Kingdee.BOS.Core.Metadata.ConvertElement; +using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs; +using Kingdee.BOS.Orm; +using Kingdee.BOS.Orm.DataEntity; using Kingdee.BOS.Util; +using Kingdee.K3.BD.NewCode.Core.Utils; using System; using System.Collections.Generic; using System.ComponentModel; @@ -9,10 +25,251 @@ using System.Threading.Tasks; namespace Gatedge.K3.Pilot.PlugIn.BOSPlugIn.Sal_OutStock { - + [Description("销售出库单插件"), HotUpdate] public class Bill : AbstractBillPlugIn { + public override void AfterDoOperation(AfterDoOperationEventArgs e) + { + base.AfterDoOperation(e); + if (e.Operation.Operation.EqualsIgnoreCase("DoPushAOrgBill")) + { + var dataObj = this.View.Model.DataObject; + var entry = dataObj["SAL_OUTSTOCKENTRY"] as DynamicObjectCollection; + var dal = new SalOutStockDAL(this.Context); + foreach (var item in entry) + { + var entryId = item["Id"].Long2Int(); + if (entryId != 0) + { + var datas = dal.GetSalOutStockSrcPO(entryId); + List selectedRows = new List(); + if (datas != null) + { + foreach (var data in datas) + { + var outStockQty = item["合计出库数量"].Convert(); + var poInStockQty = item["采购入库数量"].Convert(); + var poDeviQty = item["收料数量"].Convert(); + + if (outStockQty == poInStockQty) + continue; + + selectedRows.Add(new ListSelectedRow("0", item["采购订单分录内码"]?.ToString(), 0, "")); + + var reSaveResult = PushPO2Re(selectedRows); + + var selectRows = reSaveResult.SuccessDataEnity.SelectMany(x => x["PUR_ReceiveEntry"] as DynamicObjectCollection).Select(x => new ListSelectedRow("0", x["Id"].Long2Int().ToString(), 0, "")).ToList(); + if (selectRows.Count > 0) + { + var isResult = PushRe2InStock(selectRows); + } + } + } + } + } + } + } + + private IOperationResult PushPO2Re(List selectedRows) + { + IOperationResult result = null; + + try + { + string sourceFormId = FormIdConstants.PUR_PurchaseOrder; + string targetFormId = FormIdConstants.PUR_ReceiveBill; + string convertRuleId = "PUR_PurchaseOrder-PUR_ReceiveBill"; + //PUR_ReceiveBill-STK_InStock + result = DoPustBill(selectedRows, sourceFormId, targetFormId, convertRuleId); + } + catch (Exception ex) + { + result = new OperationResult(); + result.IsSuccess = false; + var opResFirst = new OperateResult(); + opResFirst.Name = ex.Message; + opResFirst.Message = ex.Message + "\r\n" + ex.StackTrace; + opResFirst.SuccessStatus = false; + result.OperateResult.Add(opResFirst); + } + + return result; + } + + private IOperationResult PushRe2InStock(List selectedRows) + { + IOperationResult result = null; + + try + { + string sourceFormId = FormIdConstants.PUR_ReceiveBill; + string targetFormId = FormIdConstants.STK_InStock; + string convertRuleId = "PUR_ReceiveBill-STK_InStock"; + //PUR_ReceiveBill-STK_InStock + result = DoPustBill(selectedRows, sourceFormId, targetFormId, convertRuleId); + } + catch (Exception ex) + { + result = new OperationResult(); + result.IsSuccess = false; + var opResFirst = new OperateResult(); + opResFirst.Name = ex.Message; + opResFirst.Message = ex.Message + "\r\n" + ex.StackTrace; + opResFirst.SuccessStatus = false; + result.OperateResult.Add(opResFirst); + } + + return result; + } + + /// + /// 销售订单下推发货通知单 + /// + /// + /// + private IOperationResult PushSO2De(List selectedRows) + { + IOperationResult result = null; + + try + { + string sourceFormId = FormIdConstants.SAL_SaleOrder; + string targetFormId = FormIdConstants.SAL_DELIVERYNOTICE; + string convertRuleId = "SaleOrder-DeliveryNotice"; + //PUR_ReceiveBill-STK_InStock + result = DoPustBill(selectedRows, sourceFormId, targetFormId, convertRuleId); + } + catch (Exception ex) + { + result = new OperationResult(); + result.IsSuccess = false; + var opResFirst = new OperateResult(); + opResFirst.Name = ex.Message; + opResFirst.Message = ex.Message + "\r\n" + ex.StackTrace; + opResFirst.SuccessStatus = false; + result.OperateResult.Add(opResFirst); + } + + return result; + } + + /// + /// 发货通知单下推销售出库单 + /// + /// + /// + private IOperationResult PushDe2OS(List selectedRows) + { + IOperationResult result = null; + + try + { + string sourceFormId = FormIdConstants.SAL_DELIVERYNOTICE; + string targetFormId = FormIdConstants.SAL_OUTSTOCK; + string convertRuleId = "DeliveryNotice-OutStock"; + //PUR_ReceiveBill-STK_InStock + result = DoPustBill(selectedRows, sourceFormId, targetFormId, convertRuleId); + } + catch (Exception ex) + { + result = new OperationResult(); + result.IsSuccess = false; + var opResFirst = new OperateResult(); + opResFirst.Name = ex.Message; + opResFirst.Message = ex.Message + "\r\n" + ex.StackTrace; + opResFirst.SuccessStatus = false; + result.OperateResult.Add(opResFirst); + } + + return result; + } + + /// + /// 下推单据 + /// + /// + /// + /// + /// + /// + private IOperationResult DoPustBill(List selectedRows, string sourceFormId, string targetFormId, string convertRuleId) + { + IOperationResult result = null; + + try + { + IConvertService service = ServiceHelper.GetService(); + + //获取元数据服务 + IMetaDataService metadataService = ServiceHelper.GetService(); + + //获取ViewService + IViewService viewService = ServiceHelper.GetService(); + //获取源单元数据 + + //获取转换规则 + var ruleMeta = service.GetConvertRule(this.Context, convertRuleId); + + if (ruleMeta != null) + { + FormMetadata sourceMetada = metadataService.Load(this.Context, sourceFormId) as FormMetadata; + + var policies = ruleMeta.Rule.Policies; + //字段映射关系 + var policie7002 = policies.FirstOrDefault(x => x.ElementType == 7002) as DefaultConvertPolicyElement; + if (policie7002 == null) + throw new Exception("转换单据中,字段映射关系类型值:7002不存在。"); + + //单据类型映射 + var policie7009 = policies.FirstOrDefault(x => x.ElementType == 7009) as BillTypeMapPolicyElement; + if (policie7009 == null) + throw new Exception("转换单据中,单据类型属性类型值:7009不存在。"); + var billTypeMap = policie7009.BillTypeMaps.FirstOrDefault(); + + if (billTypeMap == null) + throw new Exception($"转换规则中,源单单据类型不存在!"); + + var sourceBillTypeId = billTypeMap.SourceBillTypeId; + var targetBillTypeId = billTypeMap.TargetBillTypeId; + //设置来源单据类型 + selectedRows.ForEach(x => + { + x.EntryEntityKey = policie7002.SourceEntryKey; + }); + + var pushArgs = new PushArgs(ruleMeta.Rule, selectedRows.ToArray()); + pushArgs.TargetBillTypeId = targetBillTypeId; + OperateOption option = OperateOption.Create();//选项参数 + + option.SetVariableValue(ConvertConst.SelectByBillId, false);//不按照整单下推 + + //源单数据转换目标数据 + ConvertOperationResult convertResult = service.Push(this.Context, pushArgs, option); + + DynamicObject[] destObjs = convertResult.TargetDataEntities.Select(r => r.DataEntity).ToArray(); + + FormMetadata destFormMetadata = metadataService.Load(this.Context, targetFormId) as FormMetadata; + + IOperationResult saveResult = ServiceHelper.GetService().SaveAndAudit(this.Context, destFormMetadata.BusinessInfo, destObjs, OperateOption.Create()); + + result = saveResult; + } + + } + catch (Exception ex) + { + result = new OperationResult(); + result.IsSuccess = false; + var opResFirst = new OperateResult(); + opResFirst.Name = ex.Message; + opResFirst.Message = ex.Message + "\r\n" + ex.StackTrace; + opResFirst.SuccessStatus = false; + result.OperateResult.Add(opResFirst); + } + + return result; + } } } diff --git a/Gatedge.K3.Pilot.PlugIn/Common/FormIdConstants.cs b/Gatedge.K3.Pilot.PlugIn/Common/FormIdConstants.cs new file mode 100644 index 0000000..2d96f97 --- /dev/null +++ b/Gatedge.K3.Pilot.PlugIn/Common/FormIdConstants.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Gatedge.K3.Pilot.PlugIn.Common +{ + /// + /// 常用formId + /// + public static class FormIdConstants + { + /// + /// 采购订单 + /// + public const string PUR_PurchaseOrder = "PUR_PurchaseOrder"; + + /// + /// 收料通知单 + /// + public const string PUR_ReceiveBill = "PUR_ReceiveBill"; + + /// + /// 采购入库单 + /// + public const string STK_InStock = "STK_InStock"; + + /// + /// 销售出库单 + /// + public const string SAL_OUTSTOCK = "SAL_OUTSTOCK"; + + /// + /// 销售订单 + /// + public const string SAL_SaleOrder = "SAL_SaleOrder"; + + /// + /// 发货通知单 + /// + public const string SAL_DELIVERYNOTICE = "SAL_DELIVERYNOTICE"; + + } +} diff --git a/Gatedge.K3.Pilot.PlugIn/Gatedge.K3.Pilot.PlugIn.csproj b/Gatedge.K3.Pilot.PlugIn/Gatedge.K3.Pilot.PlugIn.csproj index 26cf29c..cc432a0 100644 --- a/Gatedge.K3.Pilot.PlugIn/Gatedge.K3.Pilot.PlugIn.csproj +++ b/Gatedge.K3.Pilot.PlugIn/Gatedge.K3.Pilot.PlugIn.csproj @@ -89,16 +89,21 @@ + + + + + diff --git a/Gatedge.K3.Pilot.PlugIn/Models/POPush.cs b/Gatedge.K3.Pilot.PlugIn/Models/POPush.cs new file mode 100644 index 0000000..8cf0327 --- /dev/null +++ b/Gatedge.K3.Pilot.PlugIn/Models/POPush.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Gatedge.K3.Pilot.PlugIn.Models +{ + public class POPush + { + public int Id { get; set; } + public int entryId { get; set; } + + public decimal qty { get; set; } + } +} diff --git a/Gatedge.K3.Pilot.PlugIn/Services/DBService/SalOutStockDAL.cs b/Gatedge.K3.Pilot.PlugIn/Services/DBService/SalOutStockDAL.cs new file mode 100644 index 0000000..d90d898 --- /dev/null +++ b/Gatedge.K3.Pilot.PlugIn/Services/DBService/SalOutStockDAL.cs @@ -0,0 +1,97 @@ +using Kingdee.BOS; +using Kingdee.BOS.Orm.DataEntity; +using Kingdee.BOS.ServiceHelper; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Gatedge.K3.Pilot.PlugIn.Services.DBService +{ + public class SalOutStockDAL : BaseDAL + { + public SalOutStockDAL(Context context) : base(context) + { + + } + + /// + /// 获取销售出库单的订单数据 + /// + /// + /// + public DynamicObjectCollection GetSalOutStockSrcPO(int entryId) + { + var sql = $@"/*dialect*/ + +WITH #销售出库单采购入库 AS ( + SELECT t0.FBILLNO AS '销售出库单' + ,t0.FDATE AS '销售出库日期' + ,t0e.FENTRYID AS '销售出库单分录ID' + ,t0e.FREALQTY AS '出库数量' + ,SUM(t0e.FREALQTY) OVER (PARTITION BY t3e.FENTRYID) '合计出库数量' + ,t1.FBILLNO AS '发货通知单' + ,t1e.FENTRYID AS '发货通知单分录ID' + ,t1e.FQTY AS '通知数量' + ,t2.FBILLNO AS '销售订单' + ,t2e.FENTRYID AS '销售订单分录ID' + ,t2e.FQTY AS '订单数量' + ,t3.FBILLNO AS '采购订单' + ,t3.FDATE AS '采购日期' + ,t3e.FSEQ AS '采购订单行号' + ,t3e.FID AS '采购订单内码' + ,t3e.FENTRYID AS '采购订单分录内码' + ,t3e.FQTY AS '采购数量' + ,ISNULL(t4.FACTRECEIVEQTY,0) AS '收料数量' + ,ISNULL(t4.FREALQTY,0) '采购入库数量' + --INTO #销售出库单采购入库 + FROM T_SAL_OUTSTOCK t0 + INNER JOIN T_SAL_OUTSTOCKENTRY t0e on t0e.FID = t0.FID + INNER JOIN T_SAL_OUTSTOCKENTRY_LK t0e_lk on t0e.FENTRYID = t0e_lk.FENTRYID + AND t0e_lk.FSTABLENAME = 'T_SAL_DELIVERYNOTICEENTRY' + INNER JOIN T_SAL_DELIVERYNOTICE t1 on t1.FID = t0e_lk.FSBILLID + INNER JOIN T_SAL_DELIVERYNOTICEENTRY t1e on t1.FID = t1e.FID AND t0e_lk.FSBILLID = t1e.FID AND t0e_lk.FSID = t1e.FENTRYID + INNER JOIN T_SAL_DELIVERYNOTICEENTRY_LK t1e_lk on t1e.FENTRYID = t1e_lk.FENTRYID + AND t1e_lk.FSTABLENAME = 'T_SAL_ORDERENTRY' + INNER JOIN T_SAL_ORDER t2 on t2.FID = t1e_lk.FSBILLID + INNER JOIN T_SAL_ORDERENTRY t2e on t1e_lk.FSBILLID = t2e.FID AND t1e_lk.FSID = t2e.FENTRYID + INNER JOIN T_SAL_ORDERENTRY_LK t2e_lk on t2e.FENTRYID = t2e_lk.FENTRYID + AND t2e_lk.FSTABLENAME = 't_PUR_POOrderEntry' + INNER JOIN T_PUR_POORDER t3 on t2e_lk.FSBILLID = t3.FID + INNER JOIN T_PUR_POORDERENTRY t3e on t3.FID = t3e.FID AND t2e_lk.FSBILLID = t3e.FID AND t2e_lk.FSID = t3e.FENTRYID + AND t3e.FMRPCLOSESTATUS = 'A' + INNER JOIN T_PUR_POORDERENTRY_LK t3e_lk on t3e_lk.FENTRYID = t3e.FENTRYID + OUTER APPLY ( + SELECT SUM(t4e.FACTRECEIVEQTY) 'FACTRECEIVEQTY',SUM(ISNULL(t5.FREALQTY,0)) 'FREALQTY' + --,STRING_AGG(t4e.FENTRYID,';') '收料单分录ID' + --,STRING_AGG(ISNULL(t5.FREALQTY,0),';') '收料单分录入库数量' + FROM T_PUR_RECEIVE t4 + INNER JOIN T_PUR_RECEIVEENTRY t4e on t4e.FID = t4.FID + INNER JOIN T_PUR_RECEIVEENTRY_LK t4e_lk on t4e_lk.FENTRYID = t4e.FENTRYID + AND t4e_lk.FSTABLENAME = 'T_PUR_POORDERENTRY' + OUTER APPLY ( + SELECT t5e_lk.FSID,SUM(t5e.FREALQTY) 'FREALQTY' + FROM T_STK_INSTOCK t5 + INNER JOIN T_STK_INSTOCKENTRY t5e on t5.fID = t5e.FID + INNER JOIN T_STK_INSTOCKENTRY_LK t5e_lk on t5e_lk.FENTRYID = t5e.FENTRYID + AND t5e_lk.FSTABLENAME = 'T_PUR_RECEIVEENTRY' + WHERE t5e_lk.FSBILLID = t4e.FID AND t5e_lk.FSID = t4e.FENTRYID + GROUP BY t5e_lk.FSID + ) t5 + WHERE t3e.FENTRYID = t4e_lk.FSID AND t3e.FID = t4e_lk.FSBILLID + GROUP BY t4e_lk.FSID + ) t4 + WHERE t3.FCLOSESTATUS = 'A' +) +SELECT t0.* +FROM #销售出库单采购入库 t0 +WHERE 1 = 1 + AND t0.销售出库单分录ID = {entryId} +ORDER BY t0.采购订单,t0.采购订单行号,t0.销售出库日期,t0.销售出库单分录ID + +"; + return DBServiceHelper.ExecuteDynamicObject(this.Context, sql); + } + } +} diff --git a/查询.sql b/查询.sql index d36ddb7..28375a6 100644 --- a/查询.sql +++ b/查询.sql @@ -1,61 +1,70 @@ -SELECT t0.FBILLNO AS '۳ⵥ' - ,t5_l.FNAME '֯' - ,t6_l.FNAME 'ɹ֯' - ,t0e.FENTRYID AS '۳ⵥ¼ID' - ,t0e.FREALQTY AS '' - ,t0e_m.FNUMBER AS '۳' - ,t1.FBILLNO AS '֪ͨ' - ,t1e.FENTRYID AS '֪ͨ¼ID' - ,t1e.FQTY AS '֪ͨ' - ,t1e_m.FNUMBER AS '֪ͨ' - ,t2.FBILLNO AS '۶' - ,t2e.FENTRYID AS '۶¼ID' - ,t2e.FQTY AS '' - ,t2e_m.FNUMBER AS '' - ,t3.FBILLNO AS 'ɹ' - ,t3e.FSEQ AS 'ɹк' - ,t3e.FENTRYID AS 'ɹ¼ID' - ,t3e.FQTY AS 'ɹ' - ,t3.FPURCHASEORGID - ,ISNULL(t4.FACTRECEIVEQTY,0) AS '' - ,ISNULL(t4.FREALQTY,0) 'ɹ' -FROM T_SAL_OUTSTOCK t0 - INNER JOIN T_SAL_OUTSTOCKENTRY t0e on t0e.FID = t0.FID - INNER JOIN T_BD_MATERIAL t0e_m on t0e_m.FMATERIALID = t0e.FMATERIALID - INNER JOIN T_SAL_OUTSTOCKENTRY_LK t0e_lk on t0e.FENTRYID = t0e_lk.FENTRYID - AND t0e_lk.FSTABLENAME = 'T_SAL_DELIVERYNOTICEENTRY' - INNER JOIN T_SAL_DELIVERYNOTICE t1 on t1.FID = t0e_lk.FSBILLID - INNER JOIN T_SAL_DELIVERYNOTICEENTRY t1e on t1.FID = t1e.FID AND t0e_lk.FSBILLID = t1e.FID AND t0e_lk.FSID = t1e.FENTRYID - INNER JOIN T_BD_MATERIAL t1e_m on t1e_m.FMATERIALID = t0e.FMATERIALID - INNER JOIN T_SAL_DELIVERYNOTICEENTRY_LK t1e_lk on t1e.FENTRYID = t1e_lk.FENTRYID - AND t1e_lk.FSTABLENAME = 'T_SAL_ORDERENTRY' - INNER JOIN T_SAL_ORDER t2 on t2.FID = t1e_lk.FSBILLID - INNER JOIN T_SAL_ORDERENTRY t2e on t1e_lk.FSBILLID = t2e.FID AND t1e_lk.FSID = t2e.FENTRYID - INNER JOIN T_BD_MATERIAL t2e_m on t2e_m.FMATERIALID = t0e.FMATERIALID - INNER JOIN T_SAL_ORDERENTRY_LK t2e_lk on t2e.FENTRYID = t2e_lk.FENTRYID - AND t2e_lk.FSTABLENAME = 't_PUR_POOrderEntry' - INNER JOIN T_PUR_POORDER t3 on t2e_lk.FSBILLID = t3.FID - --AND t3.FBILLNO = 'XN-CGDD2025091000001' - INNER JOIN T_PUR_POORDERENTRY t3e on t3.FID = t3e.FID AND t2e_lk.FSBILLID = t3e.FID AND t2e_lk.FSID = t3e.FENTRYID - INNER JOIN T_PUR_POORDERENTRY_LK t3e_lk on t3e_lk.FENTRYID = t3e.FENTRYID - OUTER APPLY ( - SELECT SUM(t4e.FACTRECEIVEQTY) 'FACTRECEIVEQTY',SUM(t5.FREALQTY) 'FREALQTY' - FROM T_PUR_RECEIVE t4 - INNER JOIN T_PUR_RECEIVEENTRY t4e on t4e.FID = t4.FID - INNER JOIN T_PUR_RECEIVEENTRY_LK t4e_lk on t4e_lk.FENTRYID = t4e.FENTRYID - AND t4e_lk.FSTABLENAME = 'T_PUR_POORDERENTRY' - OUTER APPLY ( - SELECT SUM(t5e.FREALQTY) 'FREALQTY' - FROM T_STK_INSTOCK t5 - INNER JOIN T_STK_INSTOCKENTRY t5e on t5.fID = t5e.FID - INNER JOIN T_STK_INSTOCKENTRY_LK t5e_lk on t5e_lk.FENTRYID = t5e.FENTRYID - AND t5e_lk.FSTABLENAME = 'T_PUR_RECEIVEENTRY' - WHERE t5e_lk.FSBILLID = t4e.FID AND t5e_lk.FSID = t4e.FENTRYID - GROUP BY t5e_lk.FSID - ) t5 - WHERE t3e.FENTRYID = t4e_lk.FSID AND t3e.FID = t4e_lk.FSBILLID - GROUP BY t4e_lk.FSID - ) t4 - INNER JOIN T_ORG_ORGANIZATIONS_L t5_l on t5_l.FORGID = t0.FSALEORGID AND t5_l.FLOCALEID = 2052 - INNER JOIN T_ORG_ORGANIZATIONS_L t6_l on t6_l.FORGID = t3.FPURCHASEORGID AND t6_l.FLOCALEID = 2052 -ORDER BY t3e.FID,t3e.FENTRYID \ No newline at end of file +--DROP TABLE IF EXISTS #۳ⵥɹ +WITH #۳ⵥɹ AS ( + SELECT t0.FBILLNO AS '۳ⵥ' + ,t0e.FENTRYID AS '۳ⵥ¼ID' + ,t0e.FREALQTY AS '' + ,SUM(t0e.FREALQTY) OVER (PARTITION BY t3e.FENTRYID) 'ϼƳ' + ,t1.FBILLNO AS '֪ͨ' + ,t1e.FENTRYID AS '֪ͨ¼ID' + ,t1e.FQTY AS '֪ͨ' + ,t2.FBILLNO AS '۶' + ,t2e.FENTRYID AS '۶¼ID' + ,t2e.FQTY AS '' + ,t3.FBILLNO AS 'ɹ' + ,t3.FDATE AS 'ɹ' + ,t3e.FSEQ AS 'ɹк' + ,t3e.FENTRYID AS 'ɹ¼ID' + ,t3e.FQTY AS 'ɹ' + ,ISNULL(t4.FACTRECEIVEQTY,0) AS '' + ,ISNULL(t4.FREALQTY,0) 'ɹ' + --,ISNULL(t4.ϵ¼ID,'') 'ϵ¼ID' + --,ISNULL(t4.ϵ¼,'') 'ϵ¼' + --INTO #۳ⵥɹ + FROM T_SAL_OUTSTOCK t0 + INNER JOIN T_SAL_OUTSTOCKENTRY t0e on t0e.FID = t0.FID + INNER JOIN T_SAL_OUTSTOCKENTRY_LK t0e_lk on t0e.FENTRYID = t0e_lk.FENTRYID + AND t0e_lk.FSTABLENAME = 'T_SAL_DELIVERYNOTICEENTRY' + INNER JOIN T_SAL_DELIVERYNOTICE t1 on t1.FID = t0e_lk.FSBILLID + INNER JOIN T_SAL_DELIVERYNOTICEENTRY t1e on t1.FID = t1e.FID AND t0e_lk.FSBILLID = t1e.FID AND t0e_lk.FSID = t1e.FENTRYID + INNER JOIN T_SAL_DELIVERYNOTICEENTRY_LK t1e_lk on t1e.FENTRYID = t1e_lk.FENTRYID + AND t1e_lk.FSTABLENAME = 'T_SAL_ORDERENTRY' + INNER JOIN T_SAL_ORDER t2 on t2.FID = t1e_lk.FSBILLID + INNER JOIN T_SAL_ORDERENTRY t2e on t1e_lk.FSBILLID = t2e.FID AND t1e_lk.FSID = t2e.FENTRYID + INNER JOIN T_SAL_ORDERENTRY_LK t2e_lk on t2e.FENTRYID = t2e_lk.FENTRYID + AND t2e_lk.FSTABLENAME = 't_PUR_POOrderEntry' + INNER JOIN T_PUR_POORDER t3 on t2e_lk.FSBILLID = t3.FID + INNER JOIN T_PUR_POORDERENTRY t3e on t3.FID = t3e.FID AND t2e_lk.FSBILLID = t3e.FID AND t2e_lk.FSID = t3e.FENTRYID + AND t3e.FMRPCLOSESTATUS = 'A' + INNER JOIN T_PUR_POORDERENTRY_LK t3e_lk on t3e_lk.FENTRYID = t3e.FENTRYID + OUTER APPLY ( + SELECT SUM(t4e.FACTRECEIVEQTY) 'FACTRECEIVEQTY',SUM(ISNULL(t5.FREALQTY,0)) 'FREALQTY' + --,STRING_AGG(t4e.FENTRYID,';') 'ϵ¼ID' + --,STRING_AGG(ISNULL(t5.FREALQTY,0),';') 'ϵ¼' + FROM T_PUR_RECEIVE t4 + INNER JOIN T_PUR_RECEIVEENTRY t4e on t4e.FID = t4.FID + INNER JOIN T_PUR_RECEIVEENTRY_LK t4e_lk on t4e_lk.FENTRYID = t4e.FENTRYID + AND t4e_lk.FSTABLENAME = 'T_PUR_POORDERENTRY' + OUTER APPLY ( + SELECT t5e_lk.FSID,SUM(t5e.FREALQTY) 'FREALQTY' + FROM T_STK_INSTOCK t5 + INNER JOIN T_STK_INSTOCKENTRY t5e on t5.fID = t5e.FID + INNER JOIN T_STK_INSTOCKENTRY_LK t5e_lk on t5e_lk.FENTRYID = t5e.FENTRYID + AND t5e_lk.FSTABLENAME = 'T_PUR_RECEIVEENTRY' + WHERE t5e_lk.FSBILLID = t4e.FID AND t5e_lk.FSID = t4e.FENTRYID + GROUP BY t5e_lk.FSID + ) t5 + WHERE t3e.FENTRYID = t4e_lk.FSID AND t3e.FID = t4e_lk.FSBILLID + GROUP BY t4e_lk.FSID + ) t4 + WHERE t3.FCLOSESTATUS = 'A' + --AND t0e.FREALQTY != ISNULL(t4.FREALQTY,0) + --ORDER BY t3e.FID,t3e.FENTRYID +) +SELECT t0.* +FROM #۳ⵥɹ t0 +WHERE 1=1 + --AND t0.ɹ != t0.ϼƳ + --AND t0.ɹ < t0.ϼƳ + --AND t0.ɹ > t0.ϼƳ + AND t0.۳ⵥ¼ID = 107059 + --AND t0.ɹ != t0. \ No newline at end of file