New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Collections.ObjectModel; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using Demo.Model.Model; |
| | | using Kingdee.BOS; |
| | | using Kingdee.BOS.Core.Attachment; |
| | | using Kingdee.BOS.Core.Bill; |
| | | using Kingdee.BOS.Core.Bill.PlugIn; |
| | | using Kingdee.BOS.Core.Bill.PlugIn.Args; |
| | | using Kingdee.BOS.Core.CommonFilter; |
| | | using Kingdee.BOS.Core.DynamicForm; |
| | | using Kingdee.BOS.Core.DynamicForm.DiffCompare; |
| | | 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.BarElement; |
| | | using Kingdee.BOS.Core.Metadata.ConvertElement; |
| | | using Kingdee.BOS.Core.Metadata.ConvertElement.ServiceArgs; |
| | | using Kingdee.BOS.Core.Metadata.FormElement; |
| | | using Kingdee.BOS.Core.Metadata.QueryElement; |
| | | using Kingdee.BOS.Core.Msg; |
| | | using Kingdee.BOS.Core.Permission; |
| | | using Kingdee.BOS.Log; |
| | | using Kingdee.BOS.Msg; |
| | | using Kingdee.BOS.Orm; |
| | | using Kingdee.BOS.Orm.DataEntity; |
| | | using Kingdee.BOS.Orm.Metadata.DataEntity; |
| | | using Kingdee.BOS.Resource; |
| | | using Kingdee.BOS.ServiceHelper; |
| | | using Kingdee.BOS.Util; |
| | | using Kingdee.K3.SCM.Business; |
| | | using Kingdee.K3.SCM.Core.SCP; |
| | | using Kingdee.K3.SCM.ServiceHelper; |
| | | |
| | | namespace Demo.BillView.PRD |
| | | { |
| | | |
| | | [Description("提料下推送货通知单")] |
| | | [Kingdee.BOS.Util.HotUpdate] |
| | | public class Pro_TlPush : AbstractBillPlugIn |
| | | { |
| | | private string InstockEntryTableNameAs; |
| | | private string ReturnEntryTableNameAs; |
| | | private string PoChangeEntryTableNameAs; |
| | | public override void BarItemClick(BarItemClickEventArgs e) |
| | | { |
| | | string a; |
| | | if ((a = e.BarItemKey.ToUpperInvariant()) != null) |
| | | { |
| | | if (a == "TBPUSH") |
| | | { |
| | | try |
| | | { |
| | | PermissionAuthResult permissionAuthResult = PermissionServiceHelper.FuncPermissionAuth(base.Context, new BusinessObject |
| | | { |
| | | Id = "SCP_ReceiveBill" |
| | | }, "fce8b1aca2144beeb3c6655eaf78bc34"); |
| | | if (!permissionAuthResult.Passed) |
| | | { |
| | | string msg = ResManager.LoadKDString("没有送货通知单的新增权限", "00444293030010485", SubSystemType.SCM, new object[0]); |
| | | base.View.ShowErrMessage(msg, "", MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | DynamicObjectCollection source = this.Model.DataObject["FEntity"] as DynamicObjectCollection; |
| | | string[] selEntryIds = (from p in source |
| | | select Convert.ToString(p["id"])).ToArray<string>(); |
| | | InvokePushToRec(base.View, selEntryIds); |
| | | return; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | if (ex.InnerException != null) |
| | | { |
| | | base.View.ShowErrMessage(ex.InnerException.Message, "", MessageBoxType.Notice); |
| | | } |
| | | else |
| | | { |
| | | base.View.ShowErrMessage(ex.Message, "", MessageBoxType.Notice); |
| | | } |
| | | return; |
| | | } |
| | | } |
| | | long num = Convert.ToInt64(this.Model.DataObject["id"]); |
| | | string arg = Convert.ToString(this.Model.GetValue("fbillno")); |
| | | ScpBillTrackInfo scpBillTrackInfo = new ScpBillTrackInfo(); |
| | | scpBillTrackInfo.IsUpTrack = false; |
| | | scpBillTrackInfo.BillName = ResManager.LoadKDString("供应商协同采购订单", "00444293030009441", SubSystemType.SCM, new object[0]); |
| | | TrackItem trackItem = new TrackItem(); |
| | | trackItem.FormId = "SCP_ReceiveBill"; |
| | | trackItem.FormName = ResManager.LoadKDString("送货通知单", "00444293030009436", SubSystemType.SCM, new object[0]); |
| | | trackItem.Filter = string.Format(" FSRCFORMID='PUR_PurchaseOrder' AND FSRCID={0} ", num); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem); |
| | | TrackItem trackItem2 = new TrackItem(); |
| | | trackItem2.FormId = "SCP_MRAPP"; |
| | | trackItem2.FormName = ResManager.LoadKDString("退料通知单", "00444293030010278", SubSystemType.SCM, new object[0]); |
| | | trackItem2.Filter = string.Format(" FSRCBILLTYPEID='PUR_PurchaseOrder' and FSRCBILLNO = '{0}' ", arg); |
| | | if (string.IsNullOrWhiteSpace(this.InstockEntryTableNameAs)) |
| | | { |
| | | FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(base.Context, "SCP_InStock", true); |
| | | SelectField selectField = formMetadata.BusinessInfo.GetQueryInfo().GetSelectField("FMATERIALID"); |
| | | this.InstockEntryTableNameAs = selectField.FullFieldName.Substring(0, selectField.FullFieldName.IndexOf('.')); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(this.ReturnEntryTableNameAs)) |
| | | { |
| | | FormMetadata formMetadata2 = (FormMetadata)MetaDataServiceHelper.Load(base.Context, "SCP_MRB", true); |
| | | SelectField selectField2 = formMetadata2.BusinessInfo.GetQueryInfo().GetSelectField("FMATERIALID"); |
| | | this.ReturnEntryTableNameAs = selectField2.FullFieldName.Substring(0, selectField2.FullFieldName.IndexOf('.')); |
| | | } |
| | | if (string.IsNullOrWhiteSpace(this.PoChangeEntryTableNameAs)) |
| | | { |
| | | FormMetadata formMetadata3 = (FormMetadata)MetaDataServiceHelper.Load(base.Context, "SCP_POChange", true); |
| | | SelectField selectField3 = formMetadata3.BusinessInfo.GetQueryInfo().GetSelectField("FMATERIALID"); |
| | | this.PoChangeEntryTableNameAs = selectField3.FullFieldName.Substring(0, selectField3.FullFieldName.IndexOf('.')); |
| | | } |
| | | TrackItem trackItem3 = new TrackItem(); |
| | | trackItem3.FormId = "SCP_InStock"; |
| | | trackItem3.FormName = ResManager.LoadKDString("采购入库单", "00444293030010276", SubSystemType.SCM, new object[0]); |
| | | TrackItem trackItem4 = new TrackItem(); |
| | | trackItem4.FormId = "SCP_MRB"; |
| | | trackItem4.FormName = ResManager.LoadKDString("采购退料单", "00444293030010277", SubSystemType.SCM, new object[0]); |
| | | TrackItem trackItem5 = new TrackItem(); |
| | | trackItem5.FormId = "SCP_POChange"; |
| | | trackItem5.FormName = ResManager.LoadKDString("采购订单变更单", "00444293030010132", SubSystemType.SCM, new object[0]); |
| | | List<long> list = new List<long>(); |
| | | list.Add(-1L); |
| | | List<long> list2 = new List<long>(); |
| | | list2.Add(-1L); |
| | | List<long> list3 = new List<long>(); |
| | | list3.Add(-1L); |
| | | string item = Convert.ToString(base.View.Model.DataObject["id"]); |
| | | List<string> list4 = new List<string> |
| | | { |
| | | item |
| | | }; |
| | | string[] trackIds = list4.ToArray(); |
| | | List<long> linkBillEntryIds = PurchaseNewServiceHelper.GetLinkBillEntryIds(base.Context, "T_STK_INSTOCKENTRY_lk", "t_PUR_POOrderEntry", trackIds, null, true); |
| | | List<long> linkBillEntryIds2 = PurchaseNewServiceHelper.GetLinkBillEntryIds(base.Context, "T_PUR_MRBENTRY_lk", "t_PUR_POOrderEntry", trackIds, null, true); |
| | | List<long> linkBillEntryIds3 = PurchaseNewServiceHelper.GetLinkBillEntryIds(base.Context, "T_PUR_POChangeEntry_LK", "t_PUR_POOrderEntry", trackIds, null, true); |
| | | trackItem3.Filter = string.Format(" {1}.fentryid in ({0}) ", string.Join<long>(",", linkBillEntryIds), this.InstockEntryTableNameAs); |
| | | trackItem4.Filter = string.Format(" {1}.fentryid in ({0}) ", string.Join<long>(",", linkBillEntryIds2), this.ReturnEntryTableNameAs); |
| | | trackItem5.Filter = string.Format(" {1}.fentryid in ({0}) ", string.Join<long>(",", linkBillEntryIds3), this.PoChangeEntryTableNameAs); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem2); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem3); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem4); |
| | | scpBillTrackInfo.TrackItems.Add(trackItem5); |
| | | //base.View.ShowForm(scpBillTrackInfo); |
| | | |
| | | View.ShowForm(new DynamicFormShowParameter |
| | | { |
| | | Height = 500, |
| | | Width = 1000, |
| | | FormId = "SCP_ScpBillTracker", |
| | | SyncCallBackAction = true, |
| | | ParentPageId = View.PageId, |
| | | PageId = SequentialGuid.NewGuid().ToString(), |
| | | CustomComplexParams = |
| | | { |
| | | { |
| | | "ScpBillTrackInfo", |
| | | scpBillTrackInfo |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | |
| | | public static void InvokePushToRec(IDynamicFormView formView, string[] selEntryIds) |
| | | { |
| | | if (CheckPoHasPushRec(formView.Context, selEntryIds)) |
| | | { |
| | | formView.ShowWarnningMessage(ResManager.LoadKDString("采购订单有暂存的关联送货单据,再次生成会造成单据重复下推,是否继续生成送货通知单?", "00444293030037168", SubSystemType.SCM, new object[0]), "", MessageBoxOptions.YesNoCancel, delegate (MessageBoxResult selRst) |
| | | { |
| | | if (MessageBoxResult.Yes == selRst) |
| | | { |
| | | InnerInvokePushToRec(formView, selEntryIds); |
| | | } |
| | | }, MessageBoxType.Advise); |
| | | return; |
| | | } |
| | | InnerInvokePushToRec(formView, selEntryIds); |
| | | } |
| | | |
| | | public static bool CheckPoHasPushRec(Context ctx, string[] billEntryIds) |
| | | { |
| | | string strSql = string.Format("select 1 from T_PUR_RECEIVE TH\r\nINNER JOIN T_PUR_RECEIVEENTRY TE ON TE.FID=TH.FID\r\nINNER JOIN T_PUR_RECEIVEENTRY_LK TELK ON TE.FENTRYID=TELK.FENTRYID\r\ninner join (select /*+ cardinality(b1 {0})*/FID from TABLE(fn_StrSplit(@FID,',',1)) b1) b on TELK.FSID=b.fid \r\nwhere TH.FDOCUMENTSTATUS='Z' ", billEntryIds.Length); |
| | | int num = DBServiceHelper.ExecuteScalar<int>(ctx, strSql, 0, new List<SqlParam> |
| | | { |
| | | new SqlParam("@FID", KDDbType.udt_inttable, billEntryIds) |
| | | }.ToArray()); |
| | | return num == 1; |
| | | } |
| | | |
| | | public static void InnerInvokePushToRec(IDynamicFormView formView, string[] selEntryIds) |
| | | { |
| | | DynamicFormShowParameter dynamicFormShowParameter = new DynamicFormShowParameter(); |
| | | dynamicFormShowParameter.FormId = "SCP_PushParamFrom"; |
| | | dynamicFormShowParameter.ParentPageId = formView.PageId; |
| | | dynamicFormShowParameter.OpenStyle.ShowType = ShowType.Modal; |
| | | dynamicFormShowParameter.CustomComplexParams.Add("SrcFormId", "paez_PODemandPlan"); |
| | | dynamicFormShowParameter.CustomComplexParams.Add("TargetFormId", "PUR_ReceiveBill"); |
| | | formView.ShowForm(dynamicFormShowParameter, delegate (FormResult results) |
| | | { |
| | | if (results != null && results.ReturnData != null) |
| | | { |
| | | DynamicObject dynamicObject = results.ReturnData as DynamicObject; |
| | | string CbConvertRule = Convert.ToString(dynamicObject["CbConvertRule"]); |
| | | List<ConvertRuleElement> convertRules = ConvertServiceHelper.GetConvertRules(formView.Context, "paez_PODemandPlan", "PUR_ReceiveBill"); |
| | | ConvertRuleElement rule = convertRules.FirstOrDefault((ConvertRuleElement t) => t.Id == CbConvertRule); |
| | | PushPurOrderToRec(formView, selEntryIds, rule); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | public static void PushPurOrderToRec(IDynamicFormView formView, string[] billEntryIds, ConvertRuleElement rule) |
| | | { |
| | | ConvertPolicyElement convertPolicyElement = rule.Policies[6]; |
| | | Collection<BillTypeMapElement> billTypeMaps = ((BillTypeMapPolicyElement)convertPolicyElement).BillTypeMaps; |
| | | Dictionary<string, string> dictionary = new Dictionary<string, string>(); |
| | | foreach (BillTypeMapElement billTypeMapElement in billTypeMaps) |
| | | { |
| | | if (!dictionary.ContainsKey(billTypeMapElement.SourceBillTypeId)) |
| | | { |
| | | dictionary.Add(billTypeMapElement.SourceBillTypeId, billTypeMapElement.TargetBillTypeId); |
| | | } |
| | | } |
| | | List<ScpOrderPushInfo> list = new List<ScpOrderPushInfo>(); |
| | | string strSQL = string.Format(" select tr.FentryID, t.fbilltypeid,ts.FMASTERID as fsupmasterid,t.fbillNO,TR.FID AS FBILLID \r\n from Cg_PODemandPlanBillMain t\r\n inner join T_BD_SUPPLIER ts on ts.FSUPPLIERID=t.FSUPPLIERID\r\n inner join Cg_PODemandPlanBillSub TR ON TR.FID=T.FID \r\n inner join (select /*+ cardinality(b {0})*/ fid from table(fn_StrSplit(@FID, ',',1)) b) tb on TR.fentryid=tb.fid \r\n ", billEntryIds.Length); |
| | | List<SqlParam> list2 = new List<SqlParam> |
| | | { |
| | | new SqlParam("@FID", KDDbType.udt_inttable, billEntryIds) |
| | | }; |
| | | DynamicObjectCollection dynamicObjectCollection = DBServiceHelper.ExecuteDynamicObject(formView.Context, strSQL, null, null, CommandType.Text, list2.ToArray()); |
| | | if (dynamicObjectCollection == null || dynamicObjectCollection.Count == 0) |
| | | { |
| | | throw new KDException("", ResManager.LoadKDString("受源单所选单据类型限制,不允许下推目标单!", "00444293030009439", SubSystemType.SCM, new object[0])); |
| | | } |
| | | long supplierMasterIdByUserId = SupplierServiceHelper.GetSupplierMasterIdByUserId(formView.Context, formView.Context.UserId); |
| | | string format = ResManager.LoadKDString("您没有权限操作单据{0}", "00444293030009639", SubSystemType.SCM, new object[0]); |
| | | foreach (DynamicObject dynamicObject in dynamicObjectCollection) |
| | | { |
| | | if (supplierMasterIdByUserId != Convert.ToInt64(dynamicObject["fsupmasterid"])) |
| | | { |
| | | throw new KDException("", string.Format(format, Convert.ToString(dynamicObject["fbillNO"]))); |
| | | } |
| | | list.Add(new ScpOrderPushInfo |
| | | { |
| | | EntryId = Convert.ToString(dynamicObject["FentryID"]), |
| | | BillId = Convert.ToString(dynamicObject["FBILLID"]), |
| | | BilltypeId = Convert.ToString(dynamicObject["fbilltypeid"]) |
| | | }); |
| | | } |
| | | IEnumerable<IGrouping<string, ScpOrderPushInfo>> enumerable = from g in list |
| | | group g by g.BilltypeId; |
| | | List<DynamicObject> list3 = new List<DynamicObject>(); |
| | | StringBuilder stringBuilder = new StringBuilder(); |
| | | foreach (IGrouping<string, ScpOrderPushInfo> grouping in enumerable) |
| | | { |
| | | string key = grouping.Key; |
| | | List<ListSelectedRow> list4 = new List<ListSelectedRow>(); |
| | | int num = 0; |
| | | foreach (ScpOrderPushInfo scpOrderPushInfo in grouping) |
| | | { |
| | | list4.Add(new ListSelectedRow(scpOrderPushInfo.BillId, scpOrderPushInfo.EntryId, num++, "paez_PODemandPlan") |
| | | { |
| | | EntryEntityKey = "FEntity" |
| | | }); |
| | | } |
| | | ListSelectedRow[] selectedRows = list4.ToArray(); |
| | | PushArgs pushArgs = new PushArgs(rule, selectedRows); |
| | | if (dictionary.ContainsKey(key)) |
| | | { |
| | | pushArgs.TargetBillTypeId = dictionary[key]; |
| | | } |
| | | try |
| | | { |
| | | ConvertOperationResult convertOperationResult = ConvertServiceHelper.Push(formView.Context, pushArgs, false); |
| | | list3.AddRange(from p in convertOperationResult.TargetDataEntities |
| | | select p.DataEntity); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | stringBuilder.AppendLine(ex.Message); |
| | | } |
| | | } |
| | | if (list3.Count == 0) |
| | | { |
| | | if (stringBuilder.Length > 0) |
| | | { |
| | | formView.ShowErrMessage(stringBuilder.ToString(), "", MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | formView.ShowErrMessage(ResManager.LoadKDString("没有可下推数据!", "00444293030009360", SubSystemType.SCM, new object[0]), "", MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | DynamicObject[] array = list3.ToArray(); |
| | | Dictionary<string, object> dictionary2 = new Dictionary<string, object>(); |
| | | dictionary2["CodeTime"] = 0; |
| | | dictionary2["UpdateMaxNum"] = 1; |
| | | FormMetadata formMetadata = (FormMetadata)MetaDataServiceHelper.Load(formView.Context, "PUR_ReceiveBill", true); |
| | | List<BillNoInfo> billNo = BusinessDataServiceHelper.GetBillNo(formView.Context, formMetadata.BusinessInfo, array, dictionary2, ""); |
| | | for (int i = 0; i < array.Count<DynamicObject>(); i++) |
| | | { |
| | | array[i]["BillNo"] = billNo[i].BillNo; |
| | | array[i]["IsInsideBill"] = true; |
| | | } |
| | | OperateOption option = OperateOption.Create(); |
| | | IOperationResult operationResult = BusinessDataServiceHelper.Draft(formView.Context, formMetadata.BusinessInfo, array, option, ""); |
| | | if (!operationResult.IsSuccess) |
| | | { |
| | | formView.ShowMessage(ResManager.LoadKDString("下推失败!", "00444293030009440", SubSystemType.SCM, new object[0]), MessageBoxType.Notice); |
| | | return; |
| | | } |
| | | if (operationResult.SuccessDataEnity.Count<DynamicObject>() == 1) |
| | | { |
| | | DynamicObject dynamicObject2 = operationResult.SuccessDataEnity.FirstOrDefault<DynamicObject>(); |
| | | formView.ShowForm(new BillShowParameter |
| | | { |
| | | FormId = "SCP_ReceiveBill", |
| | | PKey = Convert.ToString(dynamicObject2["id"]), |
| | | Status = OperationStatus.EDIT, |
| | | OpenStyle = |
| | | { |
| | | ShowType = ShowType.MainNewTabPage |
| | | }, |
| | | CustomComplexParams = |
| | | { |
| | | { |
| | | "FromScpOrderPushRecs", |
| | | true |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | DynamicObjectType dynamicObjectType = new DynamicObjectType("ScpRecBillDatas", null, null, DataEntityTypeFlag.Class, new object[0]); |
| | | dynamicObjectType.RegisterSimpleProperty("BillNo", typeof(string), null, false, new object[0]); |
| | | dynamicObjectType.RegisterSimpleProperty("DocumentStatus", typeof(string), null, false, new object[0]); |
| | | dynamicObjectType.RegisterSimpleProperty("BillId", typeof(long), null, false, new object[0]); |
| | | DynamicObjectCollection dynamicObjectCollection2 = new DynamicObjectCollection(dynamicObjectType, null); |
| | | foreach (DynamicObject dynamicObject3 in operationResult.SuccessDataEnity) |
| | | { |
| | | DynamicObject dynamicObject4 = new DynamicObject(dynamicObjectType); |
| | | dynamicObject4["BillNo"] = dynamicObject3["BillNo"]; |
| | | dynamicObject4["DocumentStatus"] = dynamicObject3["DocumentStatus"]; |
| | | dynamicObject4["BillId"] = dynamicObject3["id"]; |
| | | dynamicObjectCollection2.Add(dynamicObject4); |
| | | } |
| | | formView.ShowForm(new DynamicFormShowParameter |
| | | { |
| | | FormId = "SCP_GENRECRSTFORM", |
| | | PageId = SequentialGuid.NewGuid().ToString(), |
| | | OpenStyle = |
| | | { |
| | | ShowType = ShowType.MainNewTabPage |
| | | }, |
| | | CustomComplexParams = |
| | | { |
| | | { |
| | | "ScpRecBillDatas", |
| | | dynamicObjectCollection2 |
| | | } |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | } |
| | | } |
| | | } |