Esempio n. 1
0
        /// <summary>
        /// 获取单据类型Id
        /// </summary>
        /// <param name="info"></param>
        /// <param name="dataEntity"></param>
        /// <returns></returns>
        private string GetBillTypeId(BusinessInfo info, DynamicObject dataEntity)
        {
            DynamicObject rootObj = dataEntity;

            do
            {
                rootObj = dataEntity.Parent as DynamicObject;
            } while (rootObj.Parent != null);
            var billTypeField = info.GetBillTypeField();

            if (billTypeField != null)
            {
                return(billTypeField.RefIDDynamicProperty.GetValue <string>(rootObj));
            }
            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据销售报价明细分录创建产品代码
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="info">销售报价单模型信息</param>
        /// <param name="saleQuoteEntryRows">销售报价单表体分录集合信息</param>
        /// <param name="option"></param>
        /// <returns></returns>
        public IOperationResult CreateProductMaterial(Context ctx, BusinessInfo info, DynamicObject[] saleQuoteEntryRows, OperateOption option, DynamicObject dynamicO = null)
        {
            IOperationResult result = new OperationResult();

            result.IsSuccess = false;


            DynamicObject customer = dynamicO["CustId"] as DynamicObject;//客户信息

            //if (customer == null)
            //{
            //    throw new KDBusinessException("", "产品创建失败:请先录入客户信息!");
            //}
            string custName = (customer == null) ? "" : customer["Name"].ToString();
            long   userId   = (long)dynamicO["SaleOrgId_Id"];       //使用组织
            string billno   = Convert.ToString(dynamicO["BillNo"]); //单据号

            if (saleQuoteEntryRows == null || saleQuoteEntryRows.Any() == false)
            {
                return(result);
            }

            Dictionary <DynamicObject, DynamicObject> dctQuoteMaterialData = new Dictionary <DynamicObject, DynamicObject>();

            var billTypeField = info.GetBillTypeField();

            if (billTypeField == null)
            {
                return(result);
            }

            FormMetadata mtrlMetadata = AppServiceContext.MetadataService.Load(ctx, "BD_MATERIAL") as FormMetadata;

            var saleQuoteEntryGroups = saleQuoteEntryRows.GroupBy(o => billTypeField.RefIDDynamicProperty.GetValue <string>(o.Parent as DynamicObject));

            foreach (var saleQuoteGroup in saleQuoteEntryGroups)
            {
                var billTypeParaObj = AppServiceContext.GetService <ISysProfileService>().LoadBillTypeParameter(ctx, info.GetForm().Id, saleQuoteGroup.Key);
                if (billTypeParaObj == null)
                {
                    continue;
                }

                //产品组别没有配置对应物料模板
                var billTypeParaTplMtrlRows = billTypeParaObj["QuoteMtrlTplEntity"] as DynamicObjectCollection;
                foreach (var quoteEntryRow in saleQuoteGroup)
                {
                    var matchTplMtrlRowObj = billTypeParaTplMtrlRows.FirstOrDefault(o => (long)o["F_JN_MtrlGroupId_Id"] == (long)quoteEntryRow["F_JN_MtrlGroupId_Id"]);
                    if (matchTplMtrlRowObj == null)
                    {
                        var strMtrlGroupName = "";
                        if (quoteEntryRow["F_JN_MtrlGroupId"] is DynamicObject)
                        {
                            strMtrlGroupName = Convert.ToString((quoteEntryRow["F_JN_MtrlGroupId"] as DynamicObject)["name"]);
                        }
                        throw new KDBusinessException("", string.Format("产品创建失败:产品组别{0}未配置对应的模板物料!", strMtrlGroupName));
                    }

                    var           lRefMtrlTplId = (long)matchTplMtrlRowObj["F_JN_TplMtrlId_Id"];
                    DynamicObject refMtrlObject = null;
                    if (lRefMtrlTplId > 0)
                    {
                        refMtrlObject = AppServiceContext.ViewService.LoadWithCache(ctx, new object[] { lRefMtrlTplId }, mtrlMetadata.BusinessInfo.GetDynamicObjectType(), true, null)
                                        .FirstOrDefault();
                    }

                    if (refMtrlObject == null)
                    {
                        var strMtrlGroupName = "";
                        if (quoteEntryRow["F_JN_MtrlGroupId"] is DynamicObject)
                        {
                            strMtrlGroupName = Convert.ToString((quoteEntryRow["F_JN_MtrlGroupId"] as DynamicObject)["name"]);
                        }
                        throw new KDBusinessException("", string.Format("产品创建失败:产品组别{0}关联的模板物料不存在!", strMtrlGroupName));
                    }

                    //通过克隆生成新物料数据包
                    var newMtrlObject = refMtrlObject.Clone(false, true) as DynamicObject;
                    dctQuoteMaterialData[quoteEntryRow] = newMtrlObject;

                    //TODO:新物料数据包需要覆盖及重写的属性
                    newMtrlObject["DocumentStatus"] = "Z";
                    newMtrlObject["ForbidStatus"]   = "A";
                    string name = quoteEntryRow["F_JN_ProductName"] as string;
                    if (name.IsNullOrEmptyOrWhiteSpace())
                    {
                        name = custName + "特配";
                    }
                    newMtrlObject["Name"]             = new LocaleValue(name);
                    newMtrlObject["MaterialGroup_Id"] = quoteEntryRow["F_JN_MtrlGroupId_Id"];
                    newMtrlObject["CreateOrgId_Id"]   = userId;
                    newMtrlObject["UseOrgId_Id"]      = userId;
                    newMtrlObject["F_JNSRCBillNo"]    = billno;
                    //统一根据编码规则生成
                    newMtrlObject["Number"] = AppServiceContext.GetService <IBusinessDataService>().GetListBillNO(ctx, "BD_MATERIAL", 1, "565c204c1f5abf")[0];
                    //计量单位本可以根据报价分录去重写,但目前可以考虑放在模板物料中设置,一个行业的产品代码特性通常相同的。
                }
            }


            if (dctQuoteMaterialData.Any())
            {
                var saveRet = AppServiceContext.SaveService.Save(ctx, mtrlMetadata.BusinessInfo, dctQuoteMaterialData.Values.ToArray(), option, "Save");
                result.MergeResult(saveRet);

                if (saveRet.SuccessDataEnity != null)
                {
                    //更新msterID--解决工序汇报已添加相同键的项
                    DynamicObject mtrl = saveRet.SuccessDataEnity.FirstOrDefault();

                    string sql = string.Format("update T_BD_MATERIAL set FMASTERID=FMATERIALID where FMATERIALID={0}", mtrl["ID"]);
                    DBUtils.Execute(ctx, sql);
                }

                /*
                 * //启动审批流
                 *  // 读取单据的工作流配置模板
                 *  var submitRowObjs = saveRet.SuccessDataEnity.Where(o => Convert.ToString(o["DocumentStatus"]).EqualsIgnoreCase("A")
                 || Convert.ToString(o["DocumentStatus"]).EqualsIgnoreCase("D")).Select(o => o["Id"]).ToArray();
                 || string formId = "BD_MATERIAL";
                 || String[] Billarray = null;
                 || int length = submitRowObjs.GetLength(0);
                 || Billarray = new String[length];
                 || for (int i = 0; i < length; i++)
                 || {
                 ||     Billarray[i] = Convert.ToString(submitRowObjs.GetValue(i));
                 || }
                 || IWorkflowTemplateService wfTemplateService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetWorkflowTemplateService(ctx);
                 || List<FindPrcResult> findProcResultList = wfTemplateService.GetPrcListByFormID(
                 ||                 formId, Billarray, ctx);
                 || if (findProcResultList == null || findProcResultList.Count == 0)
                 || {
                 ||     throw new KDBusinessException("AutoSubmit-002", "查找单据适用的流程模板失败,不允许提交工作流!");
                 || }
                 ||
                 || // 设置提交参数:忽略操作过程中的警告,避免与用户交互
                 || OperateOption submitOption = OperateOption.Create();
                 || submitOption.SetIgnoreWarning(true);
                 || IOperationResult submitResult = null;
                 ||
                 || FindPrcResult findProcResult = findProcResultList[0];
                 || if (findProcResult.Result == TemplateResultType.Error)
                 || {
                 ||     throw new KDBusinessException("AutoSubmit-003", "单据不符合流程启动条件,不允许提交工作流!");
                 || }
                 || else if (findProcResult.Result != TemplateResultType.Normal)
                 || {// 本单无适用的流程图,直接走传统审批
                 ||     ISubmitService submitService = Kingdee.BOS.App.ServiceHelper.GetService<ISubmitService>();
                 ||     submitResult = submitService.Submit(ctx, mtrlMetadata.BusinessInfo,
                 ||         submitRowObjs, "Submit", submitOption);
                 || }
                 || else
                 || {// 走工作流
                 ||     IBOSWorkflowService wfService = Kingdee.BOS.Workflow.Contracts.ServiceFactory.GetBOSWorkflowService(ctx);
                 ||     submitResult = wfService.ListSubmit(ctx, mtrlMetadata.BusinessInfo,
                 ||         0, submitRowObjs, findProcResultList, submitOption);
                 ||     result.MergeResult(submitResult);
                 || }
                 ||
                 ||
                 ||var submitRet = AppServiceContext.SubmitService.Submit(ctx, mtrlMetadata.BusinessInfo, saveRet.SuccessDataEnity.Select(o => o["Id"]).ToArray(), "Submit", option);
                 ||result.MergeResult(submitRet);
                 ||if (submitRet.SuccessDataEnity != null)
                 ||{
                 || var auditResult = AppServiceContext.SetStatusService.SetBillStatus(ctx, mtrlMetadata.BusinessInfo,
                 ||     submitRet.SuccessDataEnity.Select(o => new KeyValuePair<object, object>(o["Id"], 0)).ToList(),
                 ||     new List<object> { "1", "" },
                 ||     "Audit", option);
                 ||
                 || result.MergeResult(auditResult);
                 ||}
                 ||
                 ||}*/
            }
            result.IsSuccess  = true;
            result.FuncResult = dctQuoteMaterialData;
            return(result);
        }