Beispiel #1
0
        public IActionResult Index()
        {
            //签约公司
            var companyInfoDtos = _commonDataService.CompanyInfos();
            var selectListItems = companyInfoDtos.Select(s => new SelectListItem(s.CompanyName, s.CompanyCode)).ToList();

            selectListItems.Insert(0, new SelectListItem("缺省", "-99"));
            selectListItems.Insert(0, new SelectListItem("请选择", ""));
            ViewBag.Company = selectListItems;

            //订单来源(采购大类)
            var types         = _commonDataService.GetRelevanceInfos(5).ToList();
            var typesListItem = types.Select(s => new SelectListItem(s.Value, s.Key)).ToList();

            typesListItem.Insert(0, new SelectListItem("请选择", "0"));
            ViewBag.Types = typesListItem;


            //物料分类
            var productCategoryDtos = _commonDataService.GetProductCategorys(level: 1, type: "MaterialClass");
            var productListItem     = productCategoryDtos.Select(s => new SelectListItem(s.Name, s.ProductCatID)).ToList();

            productListItem.Insert(0, new SelectListItem("请选择", ""));
            ViewBag.productCategories = productListItem;

            //支出类型一级
            var payOutTypes        = _commonDataService.GetDicInfos(723).ToList();
            var payOutTypeListItem = payOutTypes.Select(s => new SelectListItem(s.DictName, s.DictId.ToString())).ToList();

            payOutTypeListItem.Insert(0, new SelectListItem("请选择", "0"));
            ViewBag.payOutTypes = payOutTypeListItem;


            return(View());
        }
        public IActionResult Index()
        {
            //支出类型一级
            var payOutTypes        = _commonDataService.GetDicInfos(723).ToList();
            var payOutTypeListItem = payOutTypes.Select(s => new SelectListItem(s.DictName, s.DictId.ToString())).ToList();

            payOutTypeListItem.Insert(0, new SelectListItem("请选择", "-1"));
            ViewBag.payOutTypes = payOutTypeListItem;

            //阶段:
            var dic   = EnumHelper.GetValueAndDesc <CommonEnum.EnumCostAccountSplitStep>();
            var steps = new List <SelectListItem>();

            foreach (var i in dic)
            {
                steps.Add(new SelectListItem(i.Value, i.Key.ToString()));
            }
            steps.Insert(0, new SelectListItem("请选择", "0"));
            ViewBag.steps = steps;

            return(View());
        }
Beispiel #3
0
        public bool AddCostAccountBeforeSplit(string poCode = "", string period = null)
        {
            //计入日期
            if (string.IsNullOrEmpty(period) || period.Length != 7)
            {
                period = DateTime.Now.AddMonths(-1).ToString("yyyy-MM");
            }


            #region 获取范围数据

            Expression <Func <PurchaseOrderLineConfirmHistory, bool> >          histExp = s => s.Status == 0 && s.Period == period;
            Expression <Func <PurchaseRequirementDeptShareRatioVersion, bool> > verExp  = s =>
                                                                                          s.Status == 0 && s.Period == period;
            if (!string.IsNullOrEmpty(poCode))
            {
                histExp = histExp.And(s => s.POCode == poCode);
                verExp  = verExp.And(s => s.POCode == poCode);
            }

            var historys = _polchRepository.Where(histExp);
            var versions = _purchaseRequirementDeptShareRatioVersionRepository.Where(verExp);
            #endregion

            var configs  = _costAccountConfigRepository.Where(s => s.Status == 0);
            var dicInfos = _commonDataService.GetDicInfos();

            //1.历史记录表
            var models = new List <PurchaseOrderLineConfirmHistory>();
            foreach (var confirmHistory in historys)
            {
                var count = versions.Count(s => s.POCode == confirmHistory.POCode && s.POLineNum == confirmHistory.POLineNum);
                if (count > 0)
                {
                    int     i         = 1;
                    decimal sum       = 0;
                    decimal allAmount = confirmHistory.Amount;
                    foreach (var ver in versions.Where(s => s.POCode == confirmHistory.POCode && s.POLineNum == confirmHistory.POLineNum))
                    {
                        var toDepartId = ver.DepartID;
                        var toRate     = ver.ShareProportion * (decimal)0.01;

                        var tem = Newtonsoft.Json.JsonConvert.DeserializeObject <PurchaseOrderLineConfirmHistory>(Newtonsoft.Json.JsonConvert.SerializeObject(confirmHistory));// JsonConvert (confirmHistory);
                        tem.DepartID       = toDepartId;
                        tem.DepartNamePath = ver.DepartNamePath;
                        tem.Amount         = i == count ? allAmount - sum : decimal.Round(confirmHistory.Amount * toRate, 2);//满足总和一致

                        tem.Ratio    = toRate;
                        tem.Formula += i == count ? $"拆分前:({allAmount}-{sum})---->" : $"拆分前:({confirmHistory.Amount}*{toRate})---->";

                        models.Add(tem);
                        i++;
                        sum += tem.Amount;
                    }
                }
                else
                {
                    models.Add(confirmHistory);
                }
            }

            var costAccounts = new List <CostAccount>();
            foreach (var item in models)
            {
                var tem = configs.Where(s => (s.CompanyCode == item.CompanyCode || s.CompanyCode == "-99") &&
                                        s.ContentType == item.ContentType &&
                                        s.ProductCat1 == item.MaterialClassCode &&
                                        (s.ProductCat2 == item.MaterialCode || s.ProductCat2 == "-99")).ToList();
                var costAccountConfig = tem.OrderByDescending(s => s.CompanyCode).ThenByDescending(s => s.ProductCat2).FirstOrDefault() ?? new CostAccountConfig();
                var ca = new CostAccount
                {
                    POCode              = item.POCode,
                    POLineNum           = item.POLineNum,
                    DepartID            = item.DepartID,
                    DepathNamePath      = item.DepartNamePath,
                    Period              = item.Period,
                    Amount              = item.Amount,
                    MaterialClassCode   = item.MaterialClassCode,
                    MaterialClassName   = item.MaterialClassName,
                    MaterialCode        = item.MaterialCode,
                    MaterialName        = item.MaterialName,
                    ExpenseItem         = item.ExpenseItem,
                    ExpenseItemName     = item.ExpenseItemName,
                    ProjectCode         = item.ProjectCode,
                    ProjectName         = item.ProjectName,
                    CompanyCode         = item.CompanyCode,
                    CompanyName         = item.CompanyName,
                    SupplierID          = item.SupplierID,
                    SupplierName        = item.SupplierName,
                    ContentType         = item.ContentType,
                    ContentTypeName     = item.ContentTypeName,
                    CostAccountConfigID = costAccountConfig.Id,
                    SubjectCode         = costAccountConfig.PayOutType1,
                    SubjectName         = costAccountConfig.PayOutType1 == 0?null:dicInfos.FirstOrDefault(s => s.DictId == costAccountConfig.PayOutType1)?.DictName,
                    SecondSubjectCode   = costAccountConfig.PayOutType2,
                    SecondSubjetName    = costAccountConfig.PayOutType2 == 0 ? null : costAccountConfig.PayOutType2 == -99?"缺省" :dicInfos.FirstOrDefault(s => s.DictId == costAccountConfig.PayOutType2)?.DictName,
                    Status              = 0,
                    CreateTime          = DateTime.Now,

                    Ratio   = item.Ratio,
                    Step    = (int)CommonEnum.EnumCostAccountSplitStep.BeforeSplit,
                    Formula = string.IsNullOrEmpty(item.Formula) ? "拆分前:计入---->" : item.Formula,


                    PRCode           = item.PRCode,
                    PRDepartID       = item.PRDepartID,
                    PRDepartNamePath = item.PRDepartNamePath,
                    POCreateTime     = item.POCreateTime,
                    POLineAmount     = item.POLineAmount,
                    POLineBeginTime  = item.POLineBeginTime,
                    POLineEndTime    = item.POLineEndTime,
                    CustID           = item.CustID,
                    CustName         = item.CustName,
                    OrderEnum        = item.OrderEnum,
                    OrderEnumName    = item.OrderEnumName,
                    TaxCode          = item.TaxCode
                };
                costAccounts.Add(ca);
            }



            using (var uow = _uowCrm.Create())
            {
                //更新状态
                Expression <Func <CostAccount, bool> > delExpression = s => s.Status == 0 && s.Period == period;
                if (!string.IsNullOrEmpty(poCode))
                {
                    delExpression = delExpression.And(s => s.POCode == poCode);
                }
                var cc = _costAccountRepository.UpdateWhere(delExpression, new CostAccount()
                {
                    Status = -1, LastUpdateTime = DateTime.Now
                }, t => t.Status, t => t.LastUpdateTime);
                var num = _costAccountRepository.Add(costAccounts);
                uow.SaveChanges();
                return(true);
            }
        }
Beispiel #4
0
        public PagedResultDto <CostAccountConfigOut> GetAccountConfigsByPage(CostAccountConfigInput queryModel)
        {
            #region expression表达式
            var expression = Expression(queryModel);

            #endregion

            //var count = _costAccountConfigRepository.Count(expression);
            var model = _costAccountConfigRepository.PageListSelect(expression, s => new CostAccountConfig()
            {
                Id          = s.Id,
                CompanyCode = s.CompanyCode,
                OrderType   = s.OrderType,
                ContentType = s.ContentType,
                ProductCat1 = s.ProductCat1,
                ProductCat2 = s.ProductCat2,
                PayOutType1 = s.PayOutType1,
                PayOutType2 = s.PayOutType2
            }, queryModel.CurrentPage, queryModel.PageSize, new Tuple <Expression <Func <CostAccountConfig, object> >, SortOrder>(s => s.Id, SortOrder.Descending));

            //签约公司
            var companyInfos = _commonDataService.CompanyInfos();
            //订单类型
            var relevanceInfos = _commonDataService.GetRelevanceInfos(5);
            //采购类型
            var contentTypes = _commonDataService.GetDicInfos(701);
            //物料分类
            var productCat1s = _commonDataService.GetProductCategorys(level: 1, type: "MaterialClass");
            //物料
            var productCat2s = _commonDataService.GetProductCategorys(level: 2, type: "Material");
            //支出类型1
            var payOutType1s = _commonDataService.GetDicInfos(723);
            var payOutType2s = new List <DicInfoDto>();
            payOutType1s.ForEach(s =>
            {
                payOutType2s.AddRange(_commonDataService.GetDicInfos(s.DictId));
            });

            var models = new List <CostAccountConfigOut>();
            foreach (var item in model.Items)
            {
                var tem = new CostAccountConfigOut()
                {
                    Id              = item.Id,
                    CompanyCode     = item.CompanyCode,
                    CompanyName     = item.CompanyCode == "-99" ? "缺省" : companyInfos.Where(s => s.CompanyCode == item.CompanyCode.ToString()).Select(s => s.CompanyName).FirstOrDefault(),
                    OrderType       = item.OrderType,
                    OrderTypeName   = relevanceInfos.Where(s => s.Key == item.OrderType.ToString()).Select(s => s.Value).FirstOrDefault(),
                    ContentType     = item.ContentType,
                    ContentTypeName = item.ContentType == -99 ? "缺省" : contentTypes.Where(s => s.DictId == item.ContentType).Select(s => s.DictName).FirstOrDefault(),
                    ProductCat1     = item.ProductCat1,
                    ProductCat1Name = productCat1s.Where(s => s.ProductCatID == item.ProductCat1.ToString()).Select(s => s.Name).FirstOrDefault(),
                    ProductCat2     = item.ProductCat2,
                    ProductCat2Name = item.ProductCat2 == "-99" ? "缺省" : productCat2s.Where(s => s.ProductCatID == item.ProductCat2.ToString()).Select(s => s.Name).FirstOrDefault(),
                    PayOutType1     = item.PayOutType1,
                    PayOutType1Name = payOutType1s.Where(s => s.DictId == item.PayOutType1).Select(s => s.DictName).FirstOrDefault(),
                    PayOutType2     = item.PayOutType2,
                    PayOutType2Name = item.PayOutType2 == -99 ? "缺省" : payOutType2s.Where(s => s.DictId == item.PayOutType2).Select(s => s.DictName).FirstOrDefault(),
                };
                models.Add(tem);
            }


            return(new PagedResultDto <CostAccountConfigOut>(model.Total, models));
        }