Esempio n. 1
0
        private bool ValidateChartOfAccountAnalysisSetting(int id, AddChartOfAccountSettingModel addmodel)
        {
            var sameAnalysisSettings = _context.ChartOfAccountAnalysisSetting
                                       .Where(x => x.AnalysisNumber == addmodel.SelectedAnalysisNumber && x.ChartOfAccountId == id);

            //validate overlapping
            if (addmodel.MapFull == true)
            {
                if (sameAnalysisSettings.Count() > 0)
                {
                    return(false);
                }
            }
            else
            {
                var analysisCodeFrom = addmodel.AnalysisCodeFrom;
                var analysisCodeTo   = addmodel.AnalysisCodeTo;

                if (sameAnalysisSettings.Where(x => x.AnalysisCodeSelectionModeId == 1).Count() > 0)
                {
                    return(false);
                }

                foreach (var sas in sameAnalysisSettings)
                {
                    if (analysisCodeFrom >= sas.AnalysisCodeIdFrom && analysisCodeFrom <= sas.AnalysisCodeIdTo)
                    {
                        return(false);
                    }

                    if (analysisCodeTo >= sas.AnalysisCodeIdFrom && analysisCodeTo <= sas.AnalysisCodeIdTo)
                    {
                        return(false);
                    }

                    ////1000 >= from <= 2000
                    //if (string.Compare(sas.AnalysisCodeIdFrom, analysisCodeFrom, StringComparison.OrdinalIgnoreCase) <= 0
                    //    && string.Compare(sas.AnalysisCodeTo.Code, analysisCodeFrom, StringComparison.OrdinalIgnoreCase) >= 0)
                    //    return false;

                    ////1000 >= to <= 2000
                    //if (string.Compare(sas.AnalysisCodeFrom.Code, analysisCodeTo.Code, StringComparison.OrdinalIgnoreCase) <= 0
                    //    && string.Compare(sas.AnalysisCodeTo.Code, analysisCodeTo.Code, StringComparison.OrdinalIgnoreCase) >= 0)
                    //    return false;

                    ////from >= 1000 <= to
                    //if (string.Compare(analysisCodeFrom.Code, sas.AnalysisCodeFrom.Code, StringComparison.OrdinalIgnoreCase) <= 0
                    //    && string.Compare(analysisCodeTo.Code, sas.AnalysisCodeFrom.Code, StringComparison.OrdinalIgnoreCase) >= 0)
                    //    return false;

                    ////from >= 2000 <= to
                    //if (string.Compare(analysisCodeFrom.Code, sas.AnalysisCodeTo.Code, StringComparison.OrdinalIgnoreCase) <= 0
                    //    && string.Compare(analysisCodeTo.Code, sas.AnalysisCodeTo.Code, StringComparison.OrdinalIgnoreCase) >= 0)
                    //    return false;
                }
            }

            return(true);
        }
Esempio n. 2
0
        public ActionResult EditSetting(int id, [Bind("SelectedAnalysisNumber,MapFull,AnalysisCodeFrom,AnalysisCodeTo")] AddChartOfAccountSettingModel AddRulemodel)
        {
            try
            {
                ChartOfAccountAnalysisSetting db_AnalysisSetting = _context.ChartOfAccountAnalysisSetting.FirstOrDefault(m => m.Id.Equals(id));
                int             coaID = db_AnalysisSetting.ChartOfAccountId;
                ChartOfAccounts dbCOA = _context.ChartOfAccounts.Where(x => x.Id == coaID).FirstOrDefault();

                if (AddRulemodel == null)
                {
                    return(NotFound());
                }

                OldDataAnalysisSetting oldData = new OldDataAnalysisSetting();
                oldData.AnalysisNumber   = db_AnalysisSetting.AnalysisNumber.ToString();
                oldData.FromAnalysisCode = db_AnalysisSetting.AnalysisCodeIdFrom.ToString();
                oldData.ToAnalysisCode   = db_AnalysisSetting.AnalysisCodeIdTo.ToString();
                oldData.Enabled          = db_AnalysisSetting.Enabled;

                string oldJson = JsonConvert.SerializeObject(oldData);
                string newJson = JsonConvert.SerializeObject(AddRulemodel);

                //var analysisSettings = new ChartOfAccountAnalysisSetting()
                //{
                db_AnalysisSetting.AnalysisNumber = AddRulemodel.SelectedAnalysisNumber.Value;
                db_AnalysisSetting.AnalysisCodeSelectionModeId = AddRulemodel.MapFull ? Convert.ToInt32(AnalysisCodeSelectionMode.Full) : Convert.ToInt32(AnalysisCodeSelectionMode.Range);
                db_AnalysisSetting.AnalysisCodeIdFrom          = AddRulemodel.MapFull ? null : AddRulemodel.AnalysisCodeFrom;
                db_AnalysisSetting.AnalysisCodeIdTo            = AddRulemodel.MapFull ? null : AddRulemodel.AnalysisCodeTo;
                db_AnalysisSetting.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                db_AnalysisSetting.ModifiedDatetime = DateTime.UtcNow;
                //};
                _context.Update(db_AnalysisSetting);
                _context.SaveChanges();

                var  AnalysisData = _context.AnalysisCode.ToList();
                bool delResult    = DeleteRuleSettingMapping(db_AnalysisSetting.Id);

                if (delResult == true)
                {
                    if (AddRulemodel.MapFull)
                    {
                        AnalysisData = AnalysisData.Where(x => x.AnalysisNumber == AddRulemodel.SelectedAnalysisNumber).ToList();
                    }
                    else
                    {
                        AnalysisData = AnalysisData.Where(x => x.AnalysisNumber == AddRulemodel.SelectedAnalysisNumber &&
                                                          (x.Id >= AddRulemodel.AnalysisCodeFrom && x.Id <= AddRulemodel.AnalysisCodeTo)).ToList();
                    }

                    foreach (var data in AnalysisData)
                    {
                        var analysisMap = new ChartOfAccountAnalysisSetting_Mapping()
                        {
                            ChartOfAccountAnalysisSetting_Id = _context.ChartOfAccountAnalysisSetting.OrderByDescending(m => m.Id)
                                                               .Where(x => x.ChartOfAccountId == coaID)
                                                               .Select(m => m.Id).FirstOrDefault(),

                            AnalysisCode_Id = data.Id
                        };

                        _context.ChartOfAccountAnalysisSetting_Mapping.Add(analysisMap);
                        _context.SaveChanges();
                    }
                }


                AuditService.InsertActionLog(dbCOA.CompanyId, db_AnalysisSetting.CreatedBy, "Edit Setting", "Add Rule Setting", oldJson, newJson);

                return(RedirectToAction("Edit", "ChartOfAccounts", new { Id = coaID }));
            }
            catch
            {
                return(NotFound());
            }
        }
Esempio n. 3
0
        public ActionResult AddSetting(int id, [Bind("SelectedAnalysisNumber,MapFull,AnalysisCodeFrom,AnalysisCodeTo")] AddChartOfAccountSettingModel model)
        {
            //var jsonResult = new JsonResultModel();
            //if (!ModelState.IsValid)
            //{
            //    jsonResult.MessageBody = ModelState.GetErrorMessages("<br/>");
            //    jsonResult.MessageTitle = "Error";
            //    return Json(jsonResult, JsonRequestBehavior.AllowGet);
            //}

            if (ModelState.IsValid)
            {
                //var chartOfAccount = _context.ChartOfAccounts.Where(x => x.Id == id).ToList();

                if (ValidateChartOfAccountAnalysisSetting(id, model) == true)
                {
                    var analysisSettings = new ChartOfAccountAnalysisSetting()
                    {
                        ChartOfAccountId            = id,
                        AnalysisNumber              = model.SelectedAnalysisNumber.Value,
                        Enabled                     = true,
                        AnalysisCodeSelectionModeId = model.MapFull ? Convert.ToInt32(AnalysisCodeSelectionMode.Full) : Convert.ToInt32(AnalysisCodeSelectionMode.Range),
                        AnalysisCodeIdFrom          = model.MapFull ? null : model.AnalysisCodeFrom,
                        AnalysisCodeIdTo            = model.MapFull ? null : model.AnalysisCodeTo,
                        CreatedBy                   = _configuration.GetValue <string>("HardcodeValue:Createdby"),
                        CreatedDatetime             = DateTime.UtcNow,
                    };
                    _context.ChartOfAccountAnalysisSetting.Add(analysisSettings);
                    _context.SaveChanges();


                    var AnalysisData = _context.AnalysisCode.ToList();

                    if (model.MapFull)
                    {
                        AnalysisData = AnalysisData.Where(x => x.AnalysisNumber == model.SelectedAnalysisNumber).ToList();
                    }
                    else
                    {
                        AnalysisData = AnalysisData.Where(x => x.AnalysisNumber == model.SelectedAnalysisNumber &&
                                                          (x.Id >= model.AnalysisCodeFrom && x.Id <= model.AnalysisCodeTo)).ToList();
                    }

                    foreach (var data in AnalysisData)
                    {
                        var analysisMap = new ChartOfAccountAnalysisSetting_Mapping()
                        {
                            //ChartOfAccountAnalysisSetting_Id = Convert.ToInt32(_context.ChartOfAccountAnalysisSetting
                            //.Where(x => x.ChartOfAccountId == id)
                            //.Select(m => new AnalysisCode()
                            //{
                            //    Id = m.Id
                            //}).OrderByDescending(m => m.Id).FirstOrDefault()),
                            ChartOfAccountAnalysisSetting_Id = _context.ChartOfAccountAnalysisSetting.OrderByDescending(m => m.Id)
                                                               .Where(x => x.ChartOfAccountId == id)
                                                               .Select(m => m.Id).FirstOrDefault(),

                            AnalysisCode_Id = data.Id
                        };

                        _context.ChartOfAccountAnalysisSetting_Mapping.Add(analysisMap);
                        _context.SaveChanges();
                    }
                }
                else
                {
                    TempData["error"] = "duplicate";
                }
            }

            //var insertResult = _chartOfAccountService.InsertChartOfAccountAnalysisSetting(analysisSettings);

            //if (insertResult != AddOrUpdateChartOfAccountAnalysisSettingResultEnum.Successful)
            //{
            //    switch (insertResult)
            //    {
            //        case AddOrUpdateChartOfAccountAnalysisSettingResultEnum.OverlappedAnalysisSetting:

            //            jsonResult.MessageBody = "Overlapped Rule";
            //            jsonResult.MessageTitle = "Error";
            //            return Json(jsonResult, JsonRequestBehavior.AllowGet);
            //    }
            //}

            ////TO DO : move to service layer
            //_actionLogService.InsertActionLog(_companyContext.Company.Id, _workContext.User.Id, ActionType.Create, ActionModule.ChartOfAccountSetting,
            //    newData: analysisSettings.ToLog(), objectId: chartOfAccount.Id);

            //jsonResult.IsSuccess = true;
            //jsonResult.MessageBody = "Added Setting";
            //jsonResult.MessageTitle = "Success";
            //return Json(jsonResult, JsonRequestBehavior.AllowGet);
            return(RedirectToAction("Edit", "ChartOfAccounts", new { Id = id }));
        }