| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using Kingdee.BOS.Core.Bill; |
| | | using Kingdee.BOS.Core.Bill.PlugIn; |
| | | using Kingdee.BOS.Core.DbSchema; |
| | | using Kingdee.BOS.Core.DynamicForm; |
| | | using Kingdee.BOS.Core.DynamicForm.PlugIn.Args; |
| | | using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel; |
| | | using Kingdee.BOS.Core.List; |
| | | using Kingdee.BOS.Core.Metadata; |
| | | using Kingdee.BOS.Core.Metadata.EntityElement; |
| | | using Kingdee.BOS.Orm.DataEntity; |
| | | using Kingdee.BOS.ServiceHelper; |
| | | using Newtonsoft.Json.Linq; |
| | | using ZD.Cloud.Logger; |
| | | using ZD.Cloud.WebApi; |
| | | using ZD.Share.Common; |
| | | using Demo.Model; |
| | | using Demo.Model.Model.PODemandPlan; |
| | | |
| | | |
| | | namespace Demo.BillView.PRD |
| | | { |
| | | [Description("提料下推送货通知单")] |
| | | [Description("提料计划单-表单插件")] |
| | | [Kingdee.BOS.Util.HotUpdate] |
| | | public class Pro_TlPush : AbstractBillPlugIn |
| | | { |
| | |
| | | { |
| | | Entity entity = this.View.BillBusinessInfo.GetEntity("FEntity");//标识 |
| | | DynamicObjectCollection entityRows = this.Model.GetEntityDataObject(entity);//获取父单据体行集合 |
| | | int ret = entityRows.Where(x => Convert.ToDecimal(x["FHQty"]) - Convert.ToDecimal(x["FReciveCount"]) > 0).Count(); |
| | | int ret = entityRows.Where(x => Convert.ToDecimal(x["FHQty"]) - Convert.ToDecimal(x["FReciveCount"]) > 0 && !Convert.ToBoolean(x["FCloseStatus"])).Count(); |
| | | if (ret == 0) |
| | | { |
| | | this.View.ShowErrMessage("已全部生成送货单"); |
| | |
| | | JArray Fentity = new JArray(); |
| | | foreach (var item in entityRows) |
| | | { |
| | | if (Convert.ToBoolean(item["FCloseStatus"])) |
| | | continue; |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FMaterialId", new JObject() { ["Fnumber"] = (item["FHMaterID"] as DynamicObject)?["Number"].ToString() ?? "" }); // 物料编码 |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = (item["FUnitID"] as DynamicObject)?["Number"].ToString() ?? "" }); // 单位 |
| | |
| | | FentityModel.Add("FTLId", this.View.Model.DataObject["Id"].ToString());//提料源单内码 |
| | | FentityModel.Add("FTLentryId", item["Id"].ToString());//提料源单分录内码 |
| | | FentityModel.Add("FTLOrderNo", this.Model.GetValue("FBillNo").ToString());//提料源单分录内码 |
| | | |
| | | |
| | | JArray Fentity2 = new JArray(); |
| | | JObject FentityModel2 = new JObject(); |
| | | FentityModel2.Add("FDetailEntity_Link_FRULEID", "a8c6b6e5-a8c0-4fc1-8592-6b76c2136cf9"); |
| | |
| | | this.View.ShowErrMessage(jsonRoot.ToString()); |
| | | } |
| | | } |
| | | else if (a == "TBDEMANDPLAN") |
| | | { |
| | | DemandPlan(); |
| | | } |
| | | else if (a == "TBPURCHASE") |
| | | { |
| | | //选单选择采购订单 |
| | | PurChasePlan(); |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | //选择提料计划 |
| | | public void DemandPlan() |
| | | { |
| | | try |
| | | { |
| | | //选单选择提料计划单 |
| | | int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FEntity").GetSelectedRows();//单据体数据 |
| | | if (selectedIndexsR.Count() == 0) |
| | | { |
| | | this.View.ShowErrMessage("请选择需要变更的单据行"); |
| | | return; |
| | | } |
| | | DynamicObjectCollection selectedRowsDy = this.Model.DataObject["FEntity"] as DynamicObjectCollection;//选中行数据 |
| | | DynamicObject selectedRow; |
| | | List<int> FentryIdList = new List<int>(); |
| | | foreach (var item in selectedIndexsR) |
| | | { |
| | | selectedRow = selectedRowsDy[item]; |
| | | FentryIdList.Add(Convert.ToInt32(selectedRow["Id"])); |
| | | } |
| | | string FentryId = string.Join(",", FentryIdList); |
| | | string isCancleSql = string.Format(@"/*dialect*/ |
| | | select FSEQ from Cg_PODemandPlanBillSub |
| | | FCLOSESTATUS = 1 |
| | | where fentryid in ({0})", FentryId); |
| | | DataTable isCancleTable = DBServiceHelper.ExecuteDataSet(Context, isCancleSql).Tables[0]; |
| | | if (isCancleTable.Rows.Count > 0) |
| | | { |
| | | string errdt = "错误,"; |
| | | foreach (DataRow dr in isCancleTable.Rows) |
| | | { |
| | | errdt += "序号 : " + dr["FSEQ"].ToString() + "已关闭"; |
| | | } |
| | | this.View.ShowErrMessage(errdt); |
| | | return; |
| | | } |
| | | |
| | | //跳转选单界面 |
| | | List<string> FSelectIdList = new List<string>(); //记录选单的明细ID |
| | | string pageId = Guid.NewGuid().ToString(); |
| | | ListShowParameter showParameter = new ListShowParameter(); |
| | | showParameter.FormId = "paez_PODemandPlan"; |
| | | showParameter.PageId = pageId; |
| | | showParameter.UseOrgId = this.Context.CurrentOrganizationInfo.ID; |
| | | showParameter.IsLookUp = true; |
| | | this.View.ShowForm(showParameter, delegate (FormResult result) |
| | | { |
| | | object returnData = result.ReturnData; |
| | | if (returnData is ListSelectedRowCollection) |
| | | { |
| | | ListSelectedRowCollection listSelectedRowCollection = returnData as ListSelectedRowCollection; |
| | | if (listSelectedRowCollection != null) |
| | | { |
| | | foreach (var listSelectedRow in listSelectedRowCollection) |
| | | { |
| | | FSelectIdList.Add(listSelectedRow.DataRow["t1_FENTRYID"].ToString()); |
| | | } |
| | | } |
| | | } |
| | | //if (FentryIdList.Count != FSelectIdList.Count) |
| | | //{ |
| | | // this.View.ShowErrMessage("选择行数量不一致"); |
| | | // return; |
| | | //} |
| | | string FSelectId = string.Join(",", FSelectIdList); |
| | | //需要选择变更的数据 以及 选单选中的数据 判断数据合理性 |
| | | //选单界面B选中行数据物料 需要一致 且B占用采购单数量需要满足A的需求量 |
| | | string sql = string.Format(@"/*dialect*/ |
| | | SELECT count(*) errcount FROM |
| | | ( |
| | | select FHMATERID,SUM(FHQTY)FHQTY from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({0}) |
| | | GROUP BY FHMATERID |
| | | )A |
| | | JOIN |
| | | (select FHMATERID,FHQTY from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({1}) |
| | | ) |
| | | B |
| | | ON A.FHMATERID=B.FHMATERID |
| | | WHERE B.FHQTY < A.FHQTY", FentryId, FSelectId); |
| | | int ErrCount = DBServiceHelper.ExecuteScalar<int>(Context, sql, 0); |
| | | if (ErrCount > 0) |
| | | { |
| | | this.View.ShowErrMessage("选单数据占用的采购订单数量不满足需要变更数量"); |
| | | return; |
| | | } |
| | | //验证通过 |
| | | //关闭A单据选择行 取消采购订单的占用提料数量 |
| | | //生成一张新的提料计划单 提料日期,提料数量,生产工单信息 取A单据 ,采购信息 取B单据 |
| | | string tlSql = string.Format(@"/*dialect*/ |
| | | SELECT A.FID,C.FHDate,D.FSupplierID,E.FNUMBER AS FSupplierName,C.FSettleCurrId,A.FHMATERID,F.FNUMBER AS FMATERIALNAME,A.FHQty,A.FHSourceInterID,A.FHSourceEntryID,A.FHSourceBillNo,A.FDayPlanDate,A.FDayPlanDate,A.FHRelationQty,B.FHPOOrderInterID,B.FHPOOrderEntryID,B.FHPOOrderBillNo,B.FHPOOrderFseq,B.FErpClsID FROM |
| | | ( |
| | | select * from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({0}) |
| | | ) |
| | | A |
| | | JOIN |
| | | (select * from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({1}) |
| | | ) |
| | | B |
| | | ON A.FHMATERID = B.FHMATERID |
| | | JOIN Cg_PODemandPlanBillMain C ON A.FID = C.FID |
| | | JOIN Cg_PODemandPlanBillMain D ON B.FID = D.FID |
| | | JOIN T_BD_SUPPLIER E ON D.FSupplierID = E.FSUPPLIERID |
| | | JOIN T_BD_MATERIAL F ON A.FHMATERID = F.FMATERIALID |
| | | |
| | | ", FentryId, FSelectId); |
| | | DynamicObjectCollection tlCollection = DBServiceHelper.ExecuteDynamicObject(Context, tlSql); |
| | | JObject model = new JObject(); |
| | | JArray Fentity = new JArray(); |
| | | foreach (var item in tlCollection) |
| | | { |
| | | if (!model.ToString().Contains("FHDate")) |
| | | { |
| | | model.Add("FHDate", item["FHDate"].ToString()); |
| | | model.Add("FSettleCurrId", new JObject() { ["Fnumber"] = "PRE001" }); |
| | | model.Add("FSupplierID", new JObject() { ["Fnumber"] = item["FSupplierName"].ToString() }); |
| | | } |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = item["FMATERIALNAME"].ToString() });//物料 |
| | | FentityModel.Add("FHQty", item["FHQty"].ToString());//数量 |
| | | FentityModel.Add("FHSourceInterID", item["FHSourceInterID"].ToString());//日计划工单FID |
| | | FentityModel.Add("FHSourceEntryID", item["FHSourceEntryID"].ToString());//日计划工单FENTRYID |
| | | FentityModel.Add("FHSourceBillNo", item["FHSourceBillNo"].ToString());//日计划工单单号 |
| | | FentityModel.Add("FDayPlanDate", item["FDayPlanDate"].ToString());//日计划日期 |
| | | FentityModel.Add("FHRelationQty", item["FHRelationQty"].ToString());//关联数量 |
| | | FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHPOOrderInterID", item["FHPOOrderInterID"].ToString());// 采购订单内码:FHPOOrderInterID |
| | | FentityModel.Add("FHPOOrderEntryID", item["FHPOOrderEntryID"].ToString()); //采购订单子内码:FHPOOrderEntryID |
| | | FentityModel.Add("FHPOOrderBillNo", item["FHPOOrderBillNo"].ToString()); //采购订单号:FHPOOrderBillNo |
| | | FentityModel.Add("FERPCLSID", item["FErpClsID"].ToString()); // |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位 |
| | | Fentity.Add(FentityModel); |
| | | } |
| | | model.Add("FEntity", Fentity); |
| | | JObject jsonRoot = new JObject() |
| | | { |
| | | ["Creator"] = "", |
| | | ["NeedUpDateFields"] = new JArray(), |
| | | ["NeedReturnFields"] = new JArray(), |
| | | ["IsDeleteEntry"] = "false", |
| | | ["SubSystemId"] = "", |
| | | ["IsVerifyBaseDataField"] = "false", |
| | | ["Model"] = model |
| | | }; |
| | | CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/"); |
| | | var _result = cloudClient.Save("paez_PODemandPlan", jsonRoot.ToString()); |
| | | JObject saveObj = JObject.Parse(_result); |
| | | string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper(); |
| | | if (saveIsSuc != "TRUE") |
| | | { |
| | | LogHelper.Error("提料计划单选单新增异常:" + saveObj.ToString()); |
| | | this.View.ShowMessage(saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString()); |
| | | } |
| | | else |
| | | { |
| | | //关闭A单据体行 更新对应采购订单 提料计划数量 |
| | | List<string> sqlList = new List<string>(); |
| | | string updateSql = string.Format(@"/*dialect*/ |
| | | update Cg_PODemandPlanBillSub set |
| | | FCLOSESTATUS = 1 |
| | | where FEntryID in ({0})", FentryId); |
| | | sqlList.Add(updateSql); |
| | | updateSql = string.Format(@"/*dialect*/ |
| | | UPDATE A SET |
| | | A.FPODemandPlanCount -= B.FHQTY |
| | | FROM t_PUR_POOrderEntry A |
| | | JOIN Cg_PODemandPlanBillSub B ON A.FENTRYID = B.FHPOOrderEntryID |
| | | where B.FEntryID in ({0})", FentryId); |
| | | sqlList.Add(updateSql); |
| | | //已经占用了B的采购订单数量 故不用更新B对应采购订单的提料计划数量 |
| | | //查询出B订单被占用的数量 更新B订单的转移数量 |
| | | updateSql = string.Format(@"/*dialect*/ |
| | | update Cg_PODemandPlanBillSub set |
| | | FRemoveCount += T2.FHQTY |
| | | from Cg_PODemandPlanBillSub T1 |
| | | join |
| | | ( |
| | | SELECT A.FHQTY,FEntryID FROM |
| | | ( |
| | | select FHMATERID,SUM(FHQTY)FHQTY from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({0}) |
| | | GROUP BY FHMATERID |
| | | )A |
| | | JOIN |
| | | (select FHMATERID,FHQTY,FEntryID from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({1}) |
| | | ) |
| | | B |
| | | ON A.FHMATERID=B.FHMATERID |
| | | )T2 ON T1.FEntryID =T2.FEntryID", FentryId, FSelectId); |
| | | sqlList.Add(updateSql); |
| | | //执行sql |
| | | int resCount = DBServiceHelper.ExecuteBatch(Context, sqlList); |
| | | //重新为B订单分配采购订单 |
| | | //优先分配相同供应商 |
| | | |
| | | string cgddSql = @"/*dialect*/ |
| | | select t1.FID,t1.FBillNo,t2.FENTRYID,t1.FSUPPLIERID,t3.fnumber,t2.FMATERIALID,(t2.FQTY-t2.FPODemandPlanCount)FQTY,FPurchaseOrgId FStockOrgId,t5.FNUMBER FORGNumber,FSTOCKINQTY,FReceiveQty,FCloseStatus,FMRPCLOSESTATUS from t_PUR_POOrder t1 |
| | | join t_PUR_POOrderEntry t2 on t1.FID = t2.FID |
| | | join t_BD_Supplier t3 on t1.FSUPPLIERID = t3.FSUPPLIERID |
| | | join T_PUR_POORDERENTRY_R t4 on t2.FENTRYID = t4.FENTRYID |
| | | join T_ORG_Organizations t5 on t1.FPurchaseOrgId = t5.FORGID |
| | | where t2.FQTY-t2.FPODemandPlanCount>0 |
| | | and FCloseStatus in('A') and FMRPCLOSESTATUS in('A') |
| | | and t1.FBillTypeID in('83d822ca3e374b4ab01e5dd46a0062bd','6d01d059713d42a28bb976c90a121142') |
| | | "; |
| | | List<PurchaseInventory> PurchaseInventory = DBServiceHelper.ExecuteDataSet(Context, cgddSql).ToModelList<PurchaseInventory>(); |
| | | string cxfpSql = string.Format(@"/*dialect*/ |
| | | select A.FID,B.FHDate,FRemoveCount,A.FHMATERID,F.FNUMBER AS FMATERIALNAME,B.FSUPPLIERID,E.FNUMBER AS FSupplierName,FHSourceInterID,FHSourceEntryID,FHSourceBillNo,FDayPlanDate,FERPCLSID from Cg_PODemandPlanBillSub A |
| | | JOIN Cg_PODemandPlanBillMain B ON A.FID =B.FID |
| | | JOIN T_BD_MATERIAL F ON A.FHMATERID = F.FMATERIALID |
| | | JOIN T_BD_SUPPLIER E ON B.FSUPPLIERID=E.FSUPPLIERID |
| | | WHERE A.FEntryID IN ({0})", FSelectId); |
| | | DataTable DT = DBServiceHelper.ExecuteDataSet(Context, cxfpSql).Tables[0]; |
| | | //批量执行 |
| | | JArray FinalyResult = new JArray(); |
| | | foreach (DataRow dr in DT.Rows) |
| | | { |
| | | decimal FRemoveCount = Convert.ToDecimal(dr["FRemoveCount"]);//需要拆分的数量 |
| | | var _PurchaseInventory = PurchaseInventory.Where(x => x.FSUPPLIERID == Convert.ToInt32(dr["FSUPPLIERID"]) && x.FMATERIALID == dr["FHMATERID"].ToString() && x.FQTY > 0).OrderBy(x => x.FENTRYID).ToList();//优先该供应商 |
| | | model = new JObject(); |
| | | Fentity = new JArray(); |
| | | if (_PurchaseInventory.Count > 0) |
| | | { |
| | | if (!model.ToString().Contains("FHDate")) |
| | | { |
| | | model.Add("FID", dr["FID"].ToString()); |
| | | model.Add("FHDate", dr["FHDate"].ToString()); |
| | | model.Add("FSettleCurrId", new JObject() { ["Fnumber"] = "PRE001" }); |
| | | model.Add("FSupplierID", new JObject() { ["Fnumber"] = dr["FSupplierName"].ToString() }); |
| | | } |
| | | foreach (var cgitem in _PurchaseInventory) |
| | | { |
| | | if (FRemoveCount == 0) |
| | | break; |
| | | if (cgitem.FQTY >= FRemoveCount) |
| | | { |
| | | //明细行信息Json |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = dr["FMATERIALNAME"].ToString() });//物料 |
| | | FentityModel.Add("FHQty", FRemoveCount);//数量 |
| | | FentityModel.Add("FHSourceInterID", dr["FHSourceInterID"].ToString());//日计划工单FID |
| | | FentityModel.Add("FHSourceEntryID", dr["FHSourceEntryID"].ToString());//日计划工单FENTRYID |
| | | FentityModel.Add("FHSourceBillNo", dr["FHSourceBillNo"].ToString());//日计划工单单号 |
| | | FentityModel.Add("FDayPlanDate", dr["FDayPlanDate"].ToString());//日计划日期 |
| | | FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHPOOrderInterID", cgitem.FID.ToString());// 采购订单内码:FHPOOrderInterID |
| | | FentityModel.Add("FHPOOrderEntryID", cgitem.FENTRYID.ToString()); //采购订单子内码:FHPOOrderEntryID |
| | | FentityModel.Add("FHPOOrderBillNo", cgitem.FBillNo.ToString()); //采购订单号:FHPOOrderBillNo |
| | | FentityModel.Add("FERPCLSID", dr["FErpClsID"].ToString()); // |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位 |
| | | Fentity.Add(FentityModel); |
| | | FRemoveCount = 0; |
| | | PurchaseInventory.Where(c => c.FENTRYID == cgitem.FENTRYID).FirstOrDefault().FQTY -= FRemoveCount; |
| | | } |
| | | else |
| | | { |
| | | //明细行信息Json |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = dr["FMATERIALNAME"].ToString() });//物料 |
| | | FentityModel.Add("FHQty", cgitem.FQTY);//数量 |
| | | FentityModel.Add("FHSourceInterID", dr["FHSourceInterID"].ToString());//日计划工单FID |
| | | FentityModel.Add("FHSourceEntryID", dr["FHSourceEntryID"].ToString());//日计划工单FENTRYID |
| | | FentityModel.Add("FHSourceBillNo", dr["FHSourceBillNo"].ToString());//日计划工单单号 |
| | | FentityModel.Add("FDayPlanDate", dr["FDayPlanDate"].ToString());//日计划日期 |
| | | FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHPOOrderInterID", cgitem.FID.ToString());// 采购订单内码:FHPOOrderInterID |
| | | FentityModel.Add("FHPOOrderEntryID", cgitem.FENTRYID.ToString()); //采购订单子内码:FHPOOrderEntryID |
| | | FentityModel.Add("FHPOOrderBillNo", cgitem.FBillNo.ToString()); //采购订单号:FHPOOrderBillNo |
| | | FentityModel.Add("FERPCLSID", dr["FErpClsID"].ToString()); // |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位 |
| | | Fentity.Add(FentityModel); |
| | | FRemoveCount -= cgitem.FQTY; |
| | | PurchaseInventory.Where(c => c.FENTRYID == cgitem.FENTRYID).FirstOrDefault().FQTY = 0; |
| | | } |
| | | } |
| | | model.Add("FEntity", Fentity); |
| | | } |
| | | FinalyResult.Add(model); |
| | | if (FRemoveCount == 0) |
| | | continue; |
| | | _PurchaseInventory = PurchaseInventory.Where(x => x.FMATERIALID == dr["FHMATERID"].ToString() && x.FQTY > 0).OrderBy(x => x.FENTRYID).ToList();//优先该供应商 |
| | | if (_PurchaseInventory.Count > 0) |
| | | { |
| | | if (!model.ToString().Contains("FHDate")) |
| | | { |
| | | model.Add("FHDate", dr["FHDate"].ToString()); |
| | | model.Add("FSettleCurrId", new JObject() { ["Fnumber"] = "PRE001" }); |
| | | model.Add("FSupplierID", new JObject() { ["Fnumber"] = dr["FSupplierName"].ToString() }); |
| | | } |
| | | foreach (var cgitem in _PurchaseInventory) |
| | | { |
| | | if (FRemoveCount == 0) |
| | | break; |
| | | if (cgitem.FQTY >= FRemoveCount) |
| | | { |
| | | //明细行信息Json |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = dr["FMATERIALNAME"].ToString() });//物料 |
| | | FentityModel.Add("FHQty", FRemoveCount);//数量 |
| | | FentityModel.Add("FHSourceInterID", dr["FHSourceInterID"].ToString());//日计划工单FID |
| | | FentityModel.Add("FHSourceEntryID", dr["FHSourceEntryID"].ToString());//日计划工单FENTRYID |
| | | FentityModel.Add("FHSourceBillNo", dr["FHSourceBillNo"].ToString());//日计划工单单号 |
| | | FentityModel.Add("FDayPlanDate", dr["FDayPlanDate"].ToString());//日计划日期 |
| | | FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHPOOrderInterID", cgitem.FID.ToString());// 采购订单内码:FHPOOrderInterID |
| | | FentityModel.Add("FHPOOrderEntryID", cgitem.FENTRYID.ToString()); //采购订单子内码:FHPOOrderEntryID |
| | | FentityModel.Add("FHPOOrderBillNo", cgitem.FBillNo.ToString()); //采购订单号:FHPOOrderBillNo |
| | | FentityModel.Add("FERPCLSID", dr["FErpClsID"].ToString()); // |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位 |
| | | Fentity.Add(FentityModel); |
| | | FRemoveCount = 0; |
| | | PurchaseInventory.Where(c => c.FENTRYID == cgitem.FENTRYID).FirstOrDefault().FQTY -= FRemoveCount; |
| | | } |
| | | else |
| | | { |
| | | |
| | | //明细行信息Json |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = dr["FMATERIALNAME"].ToString() });//物料 |
| | | FentityModel.Add("FHQty", cgitem.FQTY);//数量 |
| | | FentityModel.Add("FHSourceInterID", dr["FHSourceInterID"].ToString());//日计划工单FID |
| | | FentityModel.Add("FHSourceEntryID", dr["FHSourceEntryID"].ToString());//日计划工单FENTRYID |
| | | FentityModel.Add("FHSourceBillNo", dr["FHSourceBillNo"].ToString());//日计划工单单号 |
| | | FentityModel.Add("FDayPlanDate", dr["FDayPlanDate"].ToString());//日计划日期 |
| | | FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHPOOrderInterID", cgitem.FID.ToString());// 采购订单内码:FHPOOrderInterID |
| | | FentityModel.Add("FHPOOrderEntryID", cgitem.FENTRYID.ToString()); //采购订单子内码:FHPOOrderEntryID |
| | | FentityModel.Add("FHPOOrderBillNo", cgitem.FBillNo.ToString()); //采购订单号:FHPOOrderBillNo |
| | | FentityModel.Add("FERPCLSID", dr["FErpClsID"].ToString()); // |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位 |
| | | Fentity.Add(FentityModel); |
| | | FRemoveCount -= cgitem.FQTY; |
| | | PurchaseInventory.Where(c => c.FENTRYID == cgitem.FENTRYID).FirstOrDefault().FQTY = 0; |
| | | } |
| | | } |
| | | model.Add("FEntity", Fentity); |
| | | } |
| | | FinalyResult.Add(model); |
| | | } |
| | | jsonRoot = new JObject() |
| | | { |
| | | ["Creator"] = "", |
| | | ["NeedUpDateFields"] = new JArray(), |
| | | ["NeedReturnFields"] = new JArray(), |
| | | ["IsDeleteEntry"] = "false", |
| | | ["SubSystemId"] = "", |
| | | ["IsVerifyBaseDataField"] = "false", |
| | | ["Model"] = FinalyResult |
| | | }; |
| | | |
| | | _result = cloudClient.BatchSave("paez_PODemandPlan", jsonRoot.ToString()); |
| | | var _saveObj = JObject.Parse(_result); |
| | | saveIsSuc = _saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper(); |
| | | if (saveIsSuc != "TRUE") |
| | | { |
| | | LogHelper.Error(saveObj.ToString()); |
| | | } |
| | | |
| | | |
| | | string _pageId = Guid.NewGuid().ToString(); |
| | | BillShowParameter _showParameter = new BillShowParameter(); |
| | | _showParameter.FormId = "paez_PODemandPlan"; |
| | | _showParameter.OpenStyle.ShowType = ShowType.MainNewTabPage; |
| | | _showParameter.PageId = _pageId; |
| | | _showParameter.Status = OperationStatus.EDIT; |
| | | // 传入需要修改的销售订单内码,演示代码直接固定写死为100001 |
| | | _showParameter.PKey = saveObj["Result"]["Id"].ToString(); |
| | | this.View.ShowForm(_showParameter); |
| | | } |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | |
| | | //选择采购订单 |
| | | public void PurChasePlan() |
| | | { |
| | | try |
| | | { |
| | | //选单选择提料计划单 |
| | | int[] selectedIndexsR = this.View.GetControl<EntryGrid>("FEntity").GetSelectedRows();//单据体数据 |
| | | if (selectedIndexsR.Count() == 0) |
| | | { |
| | | this.View.ShowErrMessage("请选择需要变更的单据行"); |
| | | return; |
| | | } |
| | | DynamicObjectCollection selectedRowsDy = this.Model.DataObject["FEntity"] as DynamicObjectCollection;//选中行数据 |
| | | DynamicObject selectedRow; |
| | | List<int> FentryIdList = new List<int>(); |
| | | foreach (var item in selectedIndexsR) |
| | | { |
| | | selectedRow = selectedRowsDy[item]; |
| | | FentryIdList.Add(Convert.ToInt32(selectedRow["Id"])); |
| | | } |
| | | string FentryId = string.Join(",", FentryIdList); |
| | | string isCancleSql = string.Format(@"/*dialect*/ |
| | | select FSEQ from Cg_PODemandPlanBillSub |
| | | FCLOSESTATUS = 1 |
| | | where fentryid in ({0})", FentryId); |
| | | DataTable isCancleTable = DBServiceHelper.ExecuteDataSet(Context, isCancleSql).Tables[0]; |
| | | if (isCancleTable.Rows.Count > 0) |
| | | { |
| | | string errdt = "错误,"; |
| | | foreach (DataRow dr in isCancleTable.Rows) |
| | | { |
| | | errdt += "序号 : " + dr["FSEQ"].ToString() + "已关闭"; |
| | | } |
| | | this.View.ShowErrMessage(errdt); |
| | | return; |
| | | } |
| | | //跳转选单界面 |
| | | List<string> FSelectIdList = new List<string>(); //记录选单的明细ID |
| | | string pageId = Guid.NewGuid().ToString(); |
| | | ListShowParameter showParameter = new ListShowParameter(); |
| | | showParameter.FormId = "PUR_PurchaseOrder"; |
| | | showParameter.PageId = pageId; |
| | | showParameter.UseOrgId = this.Context.CurrentOrganizationInfo.ID; |
| | | showParameter.IsLookUp = true; |
| | | this.View.ShowForm(showParameter, delegate (FormResult result) |
| | | { |
| | | object returnData = result.ReturnData; |
| | | if (returnData is ListSelectedRowCollection) |
| | | { |
| | | ListSelectedRowCollection listSelectedRowCollection = returnData as ListSelectedRowCollection; |
| | | if (listSelectedRowCollection != null) |
| | | { |
| | | foreach (var listSelectedRow in listSelectedRowCollection) |
| | | { |
| | | FSelectIdList.Add(listSelectedRow.DataRow["t1_FENTRYID"].ToString()); |
| | | } |
| | | } |
| | | } |
| | | string FSelectId = string.Join(",", FSelectIdList); |
| | | //验证所选采购订单物料数量 是否小于 提料计划物料数量 不满足给出提示 return |
| | | string sql = string.Format(@"/*dialect*/ |
| | | SELECT count(*) errcount FROM |
| | | ( |
| | | select FHMATERID,SUM(FHQTY)FHQTY from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({0}) |
| | | GROUP BY FHMATERID |
| | | )A |
| | | JOIN |
| | | (select FMaterialId,FQty from t_PUR_POOrderEntry |
| | | where FEntryID IN({1}) |
| | | ) |
| | | B |
| | | ON A.FHMATERID=B.FMaterialId |
| | | WHERE B.FQTY < A.FHQTY", FentryId, FSelectId); |
| | | int ErrCount = DBServiceHelper.ExecuteScalar<int>(Context, sql, 0); |
| | | if (ErrCount > 0) |
| | | { |
| | | this.View.ShowErrMessage("选单数据占用的采购订单数量不满足需要变更数量"); |
| | | return; |
| | | } |
| | | //验证通过 |
| | | //关闭A单据选择行 取消采购订单的占用提料数量 |
| | | //生成一张新的提料计划单 提料日期,提料数量,生产工单信息 取A单据 ,采购信息 取B单据 |
| | | string tlSql = string.Format(@"/*dialect*/ |
| | | SELECT A.FID,C.FHDate,D.FSupplierID,E.FNUMBER AS FSupplierName,C.FSettleCurrId,A.FHMATERID,F.FNUMBER AS FMATERIALNAME,A.FHQty,A.FHSourceInterID,A.FHSourceEntryID,A.FHSourceBillNo,A.FDayPlanDate,A.FDayPlanDate,A.FHRelationQty,B.FID AS FHPOOrderInterID,B.FENTRYID AS FHPOOrderEntryID,C.FBILLNO AS FHPOOrderBillNo,B.FSEQ AS FHPOOrderFseq,A.FErpClsID FROM |
| | | ( |
| | | select * from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({0}) |
| | | ) |
| | | A |
| | | JOIN |
| | | (select * from t_PUR_POOrderEntry |
| | | where FEntryID IN({1}) |
| | | ) |
| | | B |
| | | ON A.FHMATERID = B.FMaterialId |
| | | JOIN t_PUR_POOrder PO ON B.FID = PO.FID |
| | | JOIN Cg_PODemandPlanBillMain C ON A.FID = C.FID |
| | | JOIN Cg_PODemandPlanBillMain D ON B.FID = D.FID |
| | | JOIN T_BD_SUPPLIER E ON D.FSupplierID = E.FSUPPLIERID |
| | | JOIN T_BD_MATERIAL F ON A.FHMATERID = F.FMATERIALID |
| | | ", FentryId, FSelectId); |
| | | DynamicObjectCollection tlCollection = DBServiceHelper.ExecuteDynamicObject(Context, tlSql); |
| | | JObject model = new JObject(); |
| | | JArray Fentity = new JArray(); |
| | | foreach (var item in tlCollection) |
| | | { |
| | | if (!model.ToString().Contains("FHDate")) |
| | | { |
| | | model.Add("FHDate", item["FHDate"].ToString()); |
| | | model.Add("FSettleCurrId", new JObject() { ["Fnumber"] = "PRE001" }); |
| | | model.Add("FSupplierID", new JObject() { ["Fnumber"] = item["FSupplierName"].ToString() }); |
| | | } |
| | | JObject FentityModel = new JObject(); |
| | | FentityModel.Add("FHPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHMaterID", new JObject() { ["Fnumber"] = item["FMATERIALNAME"].ToString() });//物料 |
| | | FentityModel.Add("FHQty", item["FHQty"].ToString());//数量 |
| | | FentityModel.Add("FHSourceInterID", item["FHSourceInterID"].ToString());//日计划工单FID |
| | | FentityModel.Add("FHSourceEntryID", item["FHSourceEntryID"].ToString());//日计划工单FENTRYID |
| | | FentityModel.Add("FHSourceBillNo", item["FHSourceBillNo"].ToString());//日计划工单单号 |
| | | FentityModel.Add("FDayPlanDate", item["FDayPlanDate"].ToString());//日计划日期 |
| | | FentityModel.Add("FHRelationQty", item["FHRelationQty"].ToString());//关联数量 |
| | | FentityModel.Add("FPURCHASEORGID", new JObject() { ["Fnumber"] = "100" });//采购组织 |
| | | FentityModel.Add("FHPOOrderInterID", item["FHPOOrderInterID"].ToString());// 采购订单内码:FHPOOrderInterID |
| | | FentityModel.Add("FHPOOrderEntryID", item["FHPOOrderEntryID"].ToString()); //采购订单子内码:FHPOOrderEntryID |
| | | FentityModel.Add("FHPOOrderBillNo", item["FHPOOrderBillNo"].ToString()); //采购订单号:FHPOOrderBillNo |
| | | FentityModel.Add("FERPCLSID", item["FErpClsID"].ToString()); // |
| | | FentityModel.Add("FUnitID", new JObject() { ["Fnumber"] = "Pcs" }); //单位 |
| | | Fentity.Add(FentityModel); |
| | | } |
| | | model.Add("FEntity", Fentity); |
| | | JObject jsonRoot = new JObject() |
| | | { |
| | | ["Creator"] = "", |
| | | ["NeedUpDateFields"] = new JArray(), |
| | | ["NeedReturnFields"] = new JArray(), |
| | | ["IsDeleteEntry"] = "false", |
| | | ["SubSystemId"] = "", |
| | | ["IsVerifyBaseDataField"] = "false", |
| | | ["Model"] = model |
| | | }; |
| | | CloudClient cloudClient = new CloudClient("http://localhost//k3cloud/"); |
| | | var _result = cloudClient.Save("paez_PODemandPlan", jsonRoot.ToString()); |
| | | JObject saveObj = JObject.Parse(_result); |
| | | string saveIsSuc = saveObj["Result"]["ResponseStatus"]["IsSuccess"].ToString().ToUpper(); |
| | | if (saveIsSuc != "TRUE") |
| | | { |
| | | LogHelper.Error("提料计划单选单新增异常:" + saveObj.ToString()); |
| | | this.View.ShowMessage(saveObj["Result"]["ResponseStatus"]["Errors"][0]["Message"].ToString()); |
| | | } |
| | | else |
| | | { |
| | | //关闭A单据体行 更新对应采购订单 提料计划数量 |
| | | List<string> sqlList = new List<string>(); |
| | | string updateSql = string.Format(@"/*dialect*/ |
| | | update Cg_PODemandPlanBillSub set |
| | | FCLOSESTATUS = 1 |
| | | where FEntryID in ({0})", FentryId); |
| | | sqlList.Add(updateSql); |
| | | updateSql = string.Format(@"/*dialect*/ |
| | | UPDATE A SET |
| | | A.FPODemandPlanCount -= B.FHQTY |
| | | FROM t_PUR_POOrderEntry A |
| | | JOIN Cg_PODemandPlanBillSub B ON A.FENTRYID = B.FHPOOrderEntryID |
| | | where B.FEntryID in ({0})", FentryId); |
| | | sqlList.Add(updateSql); |
| | | //更新采购订单 提料计划数量 |
| | | updateSql = string.Format(@"/*dialect*/ |
| | | update t_PUR_POOrderEntry set |
| | | FPODEMANDPLANCOUNT += T2.FHQTY |
| | | from Cg_PODemandPlanBillSub T1 |
| | | join |
| | | ( |
| | | SELECT A.FHQTY,FEntryID FROM |
| | | ( |
| | | select FHMATERID,SUM(FHQTY)FHQTY from Cg_PODemandPlanBillSub |
| | | where FEntryID IN({0}) |
| | | GROUP BY FHMATERID |
| | | )A |
| | | JOIN |
| | | (select FMaterialId,FQTY,FEntryID from t_PUR_POOrderEntry |
| | | where FEntryID IN({1}) |
| | | ) |
| | | B |
| | | ON A.FHMATERID=B.FMaterialId |
| | | )T2 ON T1.FEntryID =T2.FEntryID", FentryId, FSelectId); |
| | | sqlList.Add(updateSql); |
| | | //执行sql |
| | | int resCount = DBServiceHelper.ExecuteBatch(Context, sqlList); |
| | | } |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw ex; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |