Esempio n. 1
0
 /// <summary>
 /// 构造方法。
 /// </summary>
 /// <param name="rule">单据转换规则。</param>
 /// <param name="dataEntities">数据包。</param>
 /// <param name="argument">生成目标单据参数。</param>
 /// <param name="option">操作额外参数。</param>
 public BeforeUploadTargetDataEventArgs(ConvertRuleElement rule, DynamicObject[] dataEntities, GenTargetArgs argument, OperateOption option)
 {
     this.Rule         = rule;
     this.DataEntities = dataEntities;
     this.Argument     = argument;
     this.Option       = option;
 }
Esempio n. 2
0
 public static void ThrowWhenNull(this ConvertRuleElement element)
 {
     if (element == null)
     {
         throw new KDBusinessException(string.Empty, "未配置有效的单据转换规则!");
     }
 }
Esempio n. 3
0
 /// <summary>
 /// 构造方法。
 /// </summary>
 /// <param name="rule">单据转换规则。</param>
 /// <param name="op">操作结果。</param>
 /// <param name="rows">关联数据源。</param>
 public AfterCreateTargetDataEventArgs(ConvertRuleElement rule, IOperationResult op, IEnumerable <DataLinkSource> rows)
 {
     this.Rule            = rule;
     this.OperationResult = op;
     this.Rows            = rows;
 }
 /// <summary>
 /// 构造方法。
 /// </summary>
 /// <param name="rule">单据转换规则。</param>
 /// <param name="op">操作结果。</param>
 /// <param name="rows">关联数据源。</param>
 public AfterCreatePushArgsEventArgs(ConvertRuleElement rule, PushArgs pushArgs)
 {
     this.Rule     = rule;
     this.PushArgs = pushArgs;
 }
Esempio n. 5
0
        /// <summary>
        /// 后台调用单据转换生成目标单
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public static IOperationResult ConvertBills(Context ctx, BillConvertOption option)
        {
            IOperationResult     result = new OperationResult();
            List <DynamicObject> list   = new List <DynamicObject>();
            ConvertRuleElement   rule   = AppServiceContext.ConvertService.GetConvertRules(ctx, option.sourceFormId, option.targetFormId)
                                          .FirstOrDefault(w => w.Id == option.ConvertRuleKey);
            FormMetadata metaData = (FormMetadata)AppServiceContext.MetadataService.Load(ctx, option.targetFormId, true);

            if ((rule != null) && option.BizSelectRows != null && option.BizSelectRows.Count() > 0)
            {
                PushArgs serviceArgs = new PushArgs(rule, option.BizSelectRows);
                serviceArgs.CustomParams.Add("CustomConvertOption", option);
                serviceArgs.CustomParams.Add("CustomerTransParams", option.customParams);
                OperateOption operateOption = OperateOption.Create();
                operateOption.SetVariableValue("ValidatePermission", true);
                ConvertOperationResult convertOperationResult = AppServiceContext.ConvertService.Push(ctx, serviceArgs, operateOption);
                if (!convertOperationResult.IsSuccess)
                {
                    result = convertOperationResult as IOperationResult;
                    return(result);
                }
                DynamicObject[] collection = convertOperationResult.TargetDataEntities
                                             .Select(s => s.DataEntity).ToArray();
                list.AddRange(collection);
            }
            if (list.Count > 0)
            {
                AppServiceContext.DBService.LoadReferenceObject(ctx, list.ToArray(), metaData.BusinessInfo.GetDynamicObjectType(), false);
            }
            if (option.IsDraft && list.Count > 0)
            {
                result = AppServiceContext.DraftService.Draft(ctx, metaData.BusinessInfo, list.ToArray());
            }
            if (!result.IsSuccess)
            {
                return(result);
            }
            if (option.IsSave && !option.IsDraft && list.Count > 0)
            {
                OperateOption operateOption = OperateOption.Create();
                operateOption.SetVariableValue("ValidatePermission", true);
                operateOption.SetIgnoreWarning(true);
                result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray(), operateOption);

                //result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray());
            }
            if (!result.IsSuccess)
            {
                return(result);
            }
            if (option.IsSubmit && list.Count > 0)
            {
                result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo,
                                                                list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit");
            }
            if (!result.IsSuccess)
            {
                return(result);
            }
            if (option.IsAudit && list.Count > 0)
            {
                result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo,
                                                                list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit");
                if (!result.IsSuccess)
                {
                    return(result);
                }
                List <KeyValuePair <object, object> > keyValuePairs = new List <KeyValuePair <object, object> >();
                list.ForEach(item =>
                {
                    keyValuePairs.Add(new KeyValuePair <object, object>(item.GetPrimaryKeyValue(), item));
                }
                             );
                List <object> auditObjs = new List <object>();
                auditObjs.Add("1");
                auditObjs.Add("");
                //Kingdee.BOS.Util.OperateOptionUtils oou = null;
                OperateOption ooption = OperateOption.Create();
                ooption.SetIgnoreWarning(false);
                ooption.SetIgnoreInteractionFlag(true);
                ooption.SetIsThrowValidationInfo(false);
                result = AppServiceContext.SetStatusService.SetBillStatus(ctx, metaData.BusinessInfo,
                                                                          keyValuePairs, auditObjs, "Audit", ooption);

                option.BillStatusOptionResult = ooption;
                if (!result.IsSuccess)
                {
                    return(result);
                }
            }

            return(result);
        }
Esempio n. 6
0
        /// <summary>
        /// 审核结束自动下推(应付单下推付款申请单)
        /// </summary>
        /// <param name="e"></param>
        public override void AfterExecuteOperationTransaction(AfterExecuteOperationTransaction e)
        {
            base.AfterExecuteOperationTransaction(e);
            try
            {
                string sql = string.Empty;
                if (e.DataEntitys != null && e.DataEntitys.Count <DynamicObject>() > 0)
                {
                    foreach (DynamicObject item in e.DataEntitys)
                    {
                        //收款单id
                        string Fid  = item["Id"].ToString();
                        string sql2 = "";
                        //收款单源单明细
                        DynamicObjectCollection RECEIVEBILLSRCENTRYList = item["RECEIVEBILLSRCENTRY"] as DynamicObjectCollection;
                        foreach (var entry in RECEIVEBILLSRCENTRYList)
                        {
                            //销售订单明细内码
                            string FORDERENTRYID = entry["FSRCORDERENTRYID"].ToString();
                            //本次收款金额
                            decimal FREALRECAMOUNT = Convert.ToDecimal(entry["REALRECAMOUNT"].ToString());
                            if (!string.IsNullOrEmpty(FORDERENTRYID))
                            {
                                //查询采购订单
                                sql = string.Format(@"select a.FBILLNO,b.FENTRYID as 采购订单明细内码 ,f.F_YBG_BUSINESSMODEL as 业务模式  from  t_PUR_POOrder a  
                                                       inner join   t_PUR_POOrderEntry b on a.fID=b.FID 
                                                       inner join T_PUR_POORDERENTRY_LK c on c.FENTRYID=b.FENTRYID 
                                                       left join T_SAL_ORDERENTRY d on d.FENTRYID=c.FSID
                                                       left  join T_SAL_ORDER f on f.FID=d.FID 
                                                       where  FSID='{0}'", FORDERENTRYID);
                                DataSet   ds = DBServiceHelper.ExecuteDataSet(this.Context, sql);
                                DataTable dt = ds.Tables[0];
                                if (dt.Rows.Count > 0)
                                {
                                    for (int i = 0; i < dt.Rows.Count; i++)
                                    {
                                        string F_YBG_BUSINESSMODEL = dt.Rows[i]["采购订单明细内码"].ToString();
                                        if (F_YBG_BUSINESSMODEL == "01" || F_YBG_BUSINESSMODEL == "04") //挂靠的采用自动生成付款申请单
                                        {
                                            string POFENTRYID = dt.Rows[i]["采购订单明细内码"].ToString();
                                            if (string.IsNullOrEmpty(sql2))
                                            {
                                                sql2 += "  FPAYABLEENTRYID='" + POFENTRYID + "' ";
                                            }
                                            else
                                            {
                                                sql2 += "  or  FPAYABLEENTRYID='" + POFENTRYID + "' ";
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        if (!string.IsNullOrEmpty(sql2))
                        {
                            #region  应付单下推付款申请单
                            string           srcFormId  = "AP_Payable";  //应付单
                            string           destFormId = "CN_PAYAPPLY"; //付款申请单
                            IMetaDataService mService   = Kingdee.BOS.App.ServiceHelper.GetService <IMetaDataService>();
                            IViewService     vService   = Kingdee.BOS.App.ServiceHelper.GetService <IViewService>();
                            FormMetadata     destmeta   = mService.Load(this.Context, destFormId) as FormMetadata;
                            //转换规则的唯一标识
                            string ruleKey = "AP_PayableToPayApply";
                            //var rules = ConvertServiceHelper.GetConvertRules(Context, srcFormId, destFormId);
                            //var rule = rules.FirstOrDefault(t => t.IsDefault);
                            ConvertRuleElement     rule    = GetDefaultConvertRule(Context, srcFormId, destFormId, ruleKey);
                            List <ListSelectedRow> lstRows = new List <ListSelectedRow>();
                            string  strsql = "select a.FID , a.FENTRYID  from T_AP_PAYABLEPLAN  a left join T_AP_PAYABLE b on a.FID=b.FID   where b.FDOCUMENTSTATUS='C' and  (" + sql2 + ") ";
                            DataSet ds2    = DBServiceHelper.ExecuteDataSet(Context, strsql);
                            if (ds2.Tables[0].Rows.Count > 0)
                            {
                                HashSet <string> hasset = new HashSet <string>();
                                for (int j = 0; j < ds2.Tables[0].Rows.Count; j++)
                                {
                                    hasset.Add(ds2.Tables[0].Rows[j]["FID"].ToString());
                                    long entryId = Convert.ToInt64(ds2.Tables[0].Rows[j]["FENTRYID"]);
                                    //源单单据标识
                                    ListSelectedRow row = new ListSelectedRow(ds2.Tables[0].Rows[j]["FID"].ToString(), entryId.ToString(), 0, "AP_Payable");
                                    //源单单据体标识
                                    row.EntryEntityKey = "FEntityPlan";
                                    lstRows.Add(row);
                                }

                                PushArgs        pargs      = new PushArgs(rule, lstRows.ToArray());
                                IConvertService cvtService = Kingdee.BOS.App.ServiceHelper.GetService <IConvertService>();
                                OperateOption   option     = OperateOption.Create();
                                option.SetIgnoreWarning(true);
                                option.SetVariableValue("ignoreTransaction", false);
                                option.SetIgnoreInteractionFlag(true);
                                #region 提交审核
                                //OperateOption option2 = OperateOption.Create();
                                //option2.SetIgnoreWarning(true);
                                //option2.SetVariableValue("ignoreTransaction", true);
                                //foreach (var hid in hasset)
                                //{
                                //    //如果应付单没有提交先提交审核
                                //    IMetaDataService BomService = Kingdee.BOS.App.ServiceHelper.GetService<IMetaDataService>();
                                //    //应付单元素包
                                //    FormMetadata APMeta = BomService.Load(Context, "AP_Payable") as FormMetadata;
                                //    IViewService APVService = Kingdee.BOS.App.ServiceHelper.GetService<IViewService>();
                                //    //应付单数据包
                                //    DynamicObject APmd = APVService.LoadSingle(Context, hid, APMeta.BusinessInfo.GetDynamicObjectType());

                                //    DynamicObject[] dy = new DynamicObject[] { APmd };

                                //    object[] items = dy.Select(p => p["Id"]).ToArray();

                                //    ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService<ISubmitService>();
                                //    IOperationResult submitresult = submitService.Submit(Context, APMeta.BusinessInfo, items, "Submit", option2);

                                //    IAuditService auditService = Kingdee.BOS.App.ServiceHelper.GetService<IAuditService>();
                                //    IOperationResult auditresult = auditService.Audit(Context, APMeta.BusinessInfo, items, option2);
                                //}
                                #endregion

                                ConvertOperationResult cvtResult = cvtService.Push(Context, pargs, option, false);
                                if (cvtResult.IsSuccess)
                                {
                                    DynamicObject[] dylist = (from p in cvtResult.TargetDataEntities select p.DataEntity).ToArray();
                                    //修改应收单里面数据
                                    for (int K = 0; K < dylist.Length; K++)
                                    {
                                        //付款原因
                                        dylist[K]["F_YBG_Remarks"] = "供应商付款";
                                        //明细信息
                                        DynamicObjectCollection RECEIVEBILLENTRYList = dylist[K]["FPAYAPPLYENTRY"] as DynamicObjectCollection;
                                        foreach (var Entry in RECEIVEBILLENTRYList)
                                        {
                                            //结算方式
                                            BaseDataField FSETTLETYPEID = destmeta.BusinessInfo.GetField("FSETTLETYPEID") as BaseDataField;
                                            Entry["FSETTLETYPEID_Id"] = 4;
                                            Entry["FSETTLETYPEID"]    = vService.LoadSingle(Context, 4, FSETTLETYPEID.RefFormDynamicObjectType);
                                        }
                                    }
                                    //保存
                                    ISaveService     saveService = Kingdee.BOS.App.ServiceHelper.GetService <ISaveService>();
                                    IOperationResult saveresult  = saveService.Save(Context, destmeta.BusinessInfo, dylist, option);
                                    bool             reult       = CheckResult(saveresult, out string mssg);
                                    if (!reult)
                                    {
                                        throw new Exception("收款款单审核成功,生成付款申请单失败:");
                                    }
                                    else
                                    {
                                        //纪录核销的纪录
                                        OperateResultCollection operateResults = saveresult.OperateResult;
                                        string fnmber = operateResults[0].Number;
                                        string fid    = operateResults[0].PKValue.ToString();
                                    }
                                }
                            }
                            else
                            {
                                throw new KDException("", "应付单不存在或者未审核,下推付款申请单失败");
                            }
                            #endregion
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new KDException("", "应付单下推付款申请单失败:" + ex.ToString());
            }
        }
Esempio n. 7
0
 public static DefaultConvertPolicyElement GetDefaultConvertPolicyElement(this ConvertRuleElement element)
 {
     return(GetConvertPolicyElement <DefaultConvertPolicyElement>(element));
 }
Esempio n. 8
0
 public static T GetConvertPolicyElement <T>(this ConvertRuleElement element) where T : ConvertPolicyElement
 {
     return(element.Policies.Where(police => police is T)
            .Cast <T>()
            .FirstOrDefault());
 }
Esempio n. 9
0
        /// <summary>
        /// 后台调用单据转换生成目标单
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public static IOperationResult ConvertBills(Context ctx, BillConvertOption option,string billtype)
        {
            //return AppServiceContext.ConvertBills(ctx, option);
            //判断单据类型资产接收单转化为资产应付;费用物料转为办公应付
            string billtypeid = "";
            if (billtype == "SLD04_SYS")
            {
                 billtypeid = "56e224fd183867";
                }
            if (billtype == "SLD05_SYS")
            {
                 billtypeid = "777f5fd25084498a9e77e1ef2a72e645";
            }
            IOperationResult result = new OperationResult();
            List<DynamicObject> list = new List<DynamicObject>();
            ConvertRuleElement rule = AppServiceContext.ConvertService.GetConvertRules(ctx, option.sourceFormId, option.targetFormId)
               .FirstOrDefault(w => w.Id == option.ConvertRuleKey);
            FormMetadata metaData = (FormMetadata)AppServiceContext.MetadataService.Load(ctx, option.targetFormId, true);
            if ((rule != null) && option.BizSelectRows != null && option.BizSelectRows.Count() > 0)
            {
                
                    PushArgs serviceArgs = new PushArgs(rule, option.BizSelectRows)
                    {

                        TargetBillTypeId = billtypeid,
                    };
                
                serviceArgs.CustomParams.Add("CustomConvertOption", option);
                serviceArgs.CustomParams.Add("CustomerTransParams", option.customParams);
                OperateOption operateOption = OperateOption.Create();
                operateOption.SetVariableValue("ValidatePermission", true);
                ConvertOperationResult convertOperationResult = AppServiceContext.ConvertService.Push(ctx, serviceArgs, operateOption);
                if (!convertOperationResult.IsSuccess)
                {
                    result = convertOperationResult as IOperationResult;
                    return result;
                }
                DynamicObject[] collection = convertOperationResult.TargetDataEntities
                    .Select(s => s.DataEntity).ToArray();
                list.AddRange(collection);
            }
            if (list.Count > 0)
            {
                AppServiceContext.DBService.LoadReferenceObject(ctx, list.ToArray(), metaData.BusinessInfo.GetDynamicObjectType(), false);
            }
            if (option.IsDraft && list.Count > 0)
            {
                result = AppServiceContext.DraftService.Draft(ctx, metaData.BusinessInfo, list.ToArray());
            }
            if (!result.IsSuccess)
            {
                return result;
            }
            if (option.IsSave && !option.IsDraft && list.Count > 0)
            {
                OperateOption operateOption = OperateOption.Create();
                operateOption.SetVariableValue("ValidatePermission", true);
                operateOption.SetIgnoreWarning(true);
                result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray(), operateOption);

                //result = AppServiceContext.SaveService.Save(ctx, metaData.BusinessInfo, list.ToArray());
            }
            if (!result.IsSuccess)
            {
                return result;
            }
            if (option.IsSubmit && list.Count > 0)
            {
                result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo,
                    list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit");
            }
            if (!result.IsSuccess)
            {
                return result;
            }

            bool systemParamter = Convert.ToBoolean(Kingdee.BOS.ServiceHelper.SystemParameterServiceHelper.GetParamter(ctx, OrgId, 0, "AP_SystemParameter", "F_VTRAutoReceiveBillPayable"));//获取系统参数生成应付单是否创建状态

            if (option.IsAudit && list.Count > 0 && systemParamter==false)
            {
                result = AppServiceContext.SubmitService.Submit(ctx, metaData.BusinessInfo,
                    list.Select(item => ((Object)(Convert.ToInt64(item["Id"])))).ToArray(), "Submit");
                if (!result.IsSuccess)
                {
                    return result;
                }
                List<KeyValuePair<object, object>> keyValuePairs = new List<KeyValuePair<object, object>>();
                list.ForEach(item =>
                {
                    keyValuePairs.Add(new KeyValuePair<object, object>(item.GetPrimaryKeyValue(), item));
                }
                );
                List<object> auditObjs = new List<object>();
                auditObjs.Add("1");
                auditObjs.Add("");
                //Kingdee.BOS.Util.OperateOptionUtils oou = null;
                OperateOption ooption = OperateOption.Create();
                ooption.SetIgnoreWarning(false);
                ooption.SetIgnoreInteractionFlag(true);
                ooption.SetIsThrowValidationInfo(false);
                result = AppServiceContext.SetStatusService.SetBillStatus(ctx, metaData.BusinessInfo,
                  keyValuePairs, auditObjs, "Audit", ooption);

                option.BillStatusOptionResult = ooption;
                if (!result.IsSuccess)
                {
                    return result;
                }
            }

            return result;
        }