1
This commit is contained in:
parent
5ad8d87250
commit
14affa9131
@ -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<decimal>();
|
||||
|
||||
if (materialId_Id > 0)
|
||||
var actualDiscountRate = 0M;
|
||||
var actualDiscountRateList = new List<decimal>();
|
||||
foreach (var entry in entrys)
|
||||
{
|
||||
var tempRate = entry["ActualDiscountRate"].Convert<decimal>();
|
||||
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<decimal>();
|
||||
|
||||
if (materialId_Id > 0)
|
||||
{
|
||||
var tempRate = entry["ActualDiscountRate"].Convert<decimal>();
|
||||
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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算实际折扣率
|
||||
/// </summary>
|
||||
/// <param name="price"></param>
|
||||
/// <param name="settlementPrice"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
318
Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill2.cs
Normal file
318
Gatedge.K3.Pilot.PlugIn/BOSPlugIn/Sal_Order/Bill2.cs
Normal file
@ -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<decimal>();
|
||||
//表头普通客户折扣率
|
||||
var F_CustSaleDiscountRate = this.View.Model.GetValue("F_CustSaleDiscountRate").Convert<decimal>();
|
||||
|
||||
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<DateTime>().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<decimal>();
|
||||
//结算价格
|
||||
var settlementPrice = data["F_JSJ"].Convert<decimal>();
|
||||
|
||||
if (isBigCustFlag)
|
||||
{
|
||||
// 大客户结算价
|
||||
var bigCustSettlementPrice = data["F_BIGCUSTSETTLEPRICE"].Convert<decimal>();
|
||||
|
||||
if (bigCustSettlementPrice != 0)
|
||||
settlementPrice = bigCustSettlementPrice;
|
||||
|
||||
this.Model.SetValue("F_BIGCUSTSETTLEPRICE", bigCustSettlementPrice, e.Row);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 协议价
|
||||
var F_AGREEPRICE = data["F_AGREEPRICE"].Convert<decimal>();
|
||||
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<decimal>();
|
||||
//表头普通客户折扣率
|
||||
var F_CustSaleDiscountRate = this.View.Model.GetValue("F_CustSaleDiscountRate").Convert<decimal>();
|
||||
|
||||
var price = e.NewValue.Convert<decimal>();
|
||||
|
||||
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<DateTime>().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<decimal>();
|
||||
|
||||
if (isBigCustFlag)
|
||||
{
|
||||
// 大客户结算价
|
||||
var bigCustSettlementPrice = data["F_BIGCUSTSETTLEPRICE"].Convert<decimal>();
|
||||
|
||||
if (bigCustSettlementPrice != 0)
|
||||
settlementPrice = bigCustSettlementPrice;
|
||||
|
||||
this.Model.SetValue("F_BIGCUSTSETTLEPRICE", bigCustSettlementPrice, e.Row);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 协议价
|
||||
var F_AGREEPRICE = data["F_AGREEPRICE"].Convert<decimal>();
|
||||
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<DateTime>().ToString("yyyy-MM-dd");
|
||||
var details = this.View.BusinessInfo.GetEntity("FSaleOrderEntry");
|
||||
if (details != null)
|
||||
{
|
||||
//表头大客户折扣率
|
||||
var F_BigCustSaleDiscountRate = this.View.Model.GetValue("F_BigCustSaleDiscountRate").Convert<decimal>();
|
||||
//表头普通客户折扣率
|
||||
var F_CustSaleDiscountRate = this.View.Model.GetValue("F_CustSaleDiscountRate").Convert<decimal>();
|
||||
|
||||
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<decimal>();
|
||||
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<decimal>();
|
||||
|
||||
if (isBigCustFlag)
|
||||
{
|
||||
// 大客户结算价
|
||||
var bigCustSettlementPrice = data["F_BIGCUSTSETTLEPRICE"].Convert<decimal>();
|
||||
|
||||
if (bigCustSettlementPrice != 0)
|
||||
settlementPrice = bigCustSettlementPrice;
|
||||
|
||||
this.Model.SetValue("F_BIGCUSTSETTLEPRICE", bigCustSettlementPrice, e.Row);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 协议价
|
||||
var F_AGREEPRICE = data["F_AGREEPRICE"].Convert<decimal>();
|
||||
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<decimal>();
|
||||
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<decimal>();
|
||||
|
||||
if (materialId_Id > 0)
|
||||
{
|
||||
var tempRate = entry["ActualDiscountRate"].Convert<decimal>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算实际折扣率
|
||||
/// </summary>
|
||||
/// <param name="price"></param>
|
||||
/// <param name="settlementPrice"></param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<ListSelectedRow> selectedRows = new List<ListSelectedRow>();
|
||||
if (datas != null)
|
||||
{
|
||||
foreach (var data in datas)
|
||||
{
|
||||
var outStockQty = item["合计出库数量"].Convert<decimal>();
|
||||
var poInStockQty = item["采购入库数量"].Convert<decimal>();
|
||||
var poDeviQty = item["收料数量"].Convert<decimal>();
|
||||
|
||||
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<ListSelectedRow> 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<ListSelectedRow> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 销售订单下推发货通知单
|
||||
/// </summary>
|
||||
/// <param name="selectedRows"></param>
|
||||
/// <returns></returns>
|
||||
private IOperationResult PushSO2De(List<ListSelectedRow> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发货通知单下推销售出库单
|
||||
/// </summary>
|
||||
/// <param name="selectedRows"></param>
|
||||
/// <returns></returns>
|
||||
private IOperationResult PushDe2OS(List<ListSelectedRow> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下推单据
|
||||
/// </summary>
|
||||
/// <param name="selectedRows"></param>
|
||||
/// <param name="sourceFormId"></param>
|
||||
/// <param name="targetFormId"></param>
|
||||
/// <param name="convertRuleId"></param>
|
||||
/// <returns></returns>
|
||||
private IOperationResult DoPustBill(List<ListSelectedRow> selectedRows, string sourceFormId, string targetFormId, string convertRuleId)
|
||||
{
|
||||
IOperationResult result = null;
|
||||
|
||||
try
|
||||
{
|
||||
IConvertService service = ServiceHelper.GetService<IConvertService>();
|
||||
|
||||
//获取元数据服务
|
||||
IMetaDataService metadataService = ServiceHelper.GetService<IMetaDataService>();
|
||||
|
||||
//获取ViewService
|
||||
IViewService viewService = ServiceHelper.GetService<IViewService>();
|
||||
//获取源单元数据
|
||||
|
||||
//获取转换规则
|
||||
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<ISaveService>().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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
45
Gatedge.K3.Pilot.PlugIn/Common/FormIdConstants.cs
Normal file
45
Gatedge.K3.Pilot.PlugIn/Common/FormIdConstants.cs
Normal file
@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 常用formId
|
||||
/// </summary>
|
||||
public static class FormIdConstants
|
||||
{
|
||||
/// <summary>
|
||||
/// 采购订单
|
||||
/// </summary>
|
||||
public const string PUR_PurchaseOrder = "PUR_PurchaseOrder";
|
||||
|
||||
/// <summary>
|
||||
/// 收料通知单
|
||||
/// </summary>
|
||||
public const string PUR_ReceiveBill = "PUR_ReceiveBill";
|
||||
|
||||
/// <summary>
|
||||
/// 采购入库单
|
||||
/// </summary>
|
||||
public const string STK_InStock = "STK_InStock";
|
||||
|
||||
/// <summary>
|
||||
/// 销售出库单
|
||||
/// </summary>
|
||||
public const string SAL_OUTSTOCK = "SAL_OUTSTOCK";
|
||||
|
||||
/// <summary>
|
||||
/// 销售订单
|
||||
/// </summary>
|
||||
public const string SAL_SaleOrder = "SAL_SaleOrder";
|
||||
|
||||
/// <summary>
|
||||
/// 发货通知单
|
||||
/// </summary>
|
||||
public const string SAL_DELIVERYNOTICE = "SAL_DELIVERYNOTICE";
|
||||
|
||||
}
|
||||
}
|
||||
@ -89,16 +89,21 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="BOSPlugIn\AR_SalesVATInvoice\ServicePlugIn\AfterSave.cs" />
|
||||
<Compile Include="BOSPlugIn\BD_CustPrice\Bill.cs" />
|
||||
<Compile Include="BOSPlugIn\BD_CustPrice\ServicePlugIn\Save.cs" />
|
||||
<Compile Include="BOSPlugIn\BD_CustPrice\ServicePlugIn\SaveValidator.cs" />
|
||||
<Compile Include="BOSPlugIn\CUST_PAYMENT_PERIOD\List.cs" />
|
||||
<Compile Include="BOSPlugIn\Sal_Order\Bill.cs" />
|
||||
<Compile Include="BOSPlugIn\Sal_Order\Bill2.cs" />
|
||||
<Compile Include="BOSPlugIn\Sal_OutStock\Bill.cs" />
|
||||
<Compile Include="Common\FormIdConstants.cs" />
|
||||
<Compile Include="Models\POPush.cs" />
|
||||
<Compile Include="Models\Validate\PeriodValidity.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Services\DBService\BaseDAL.cs" />
|
||||
<Compile Include="Services\DBService\BDCustPriceDAL.cs" />
|
||||
<Compile Include="Services\DBService\SalOutStockDAL.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="BOSPlugIn\Sal_Order\ServicePlugIn\" />
|
||||
|
||||
16
Gatedge.K3.Pilot.PlugIn/Models/POPush.cs
Normal file
16
Gatedge.K3.Pilot.PlugIn/Models/POPush.cs
Normal file
@ -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; }
|
||||
}
|
||||
}
|
||||
97
Gatedge.K3.Pilot.PlugIn/Services/DBService/SalOutStockDAL.cs
Normal file
97
Gatedge.K3.Pilot.PlugIn/Services/DBService/SalOutStockDAL.cs
Normal file
@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取销售出库单的订单数据
|
||||
/// </summary>
|
||||
/// <param name="entryId"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
131
查询.sql
131
查询.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
|
||||
--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.收料数量
|
||||
Loading…
x
Reference in New Issue
Block a user