Example #1
0
        //
        // GET: /FiscalYear/Edit/5

        public ActionResult Edit(int id)
        {
            FiscalYearModel model = new FiscalYearModel();

            model = pro.GetObject(id);
            return(View(model));
        }
Example #2
0
        public ActionResult Create(FiscalYearModel model)
        {
            int flag;

            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {
                    flag = pro.Insert(model);
                    if (flag == 1)
                    {
                        TempData["success"] = "Record Created Successfully !";
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        TempData["message"] = "Fiscal year name (in BS or AD) already exists in database.";
                        return(View(model));
                    }
                }
                else
                {
                    return(View(model));
                }
            }
            catch
            {
                return(View());
            }
        }
Example #3
0
        public ActionResult Edit(FiscalYearModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    model.UpdatedDate = DateTime.Now;

                    model.StartDateNp = "";

                    model.EndDateNp = "";

                    fiscalService.Update(model);

                    TempData["Success"] = $"{model.FiscalYearName} is updated !";

                    return(RedirectToAction("Index"));
                }

                return(View(@"~\Views\Configuration\FiscalYear\Edit.cshtml", model));
            }
            catch (Exception e)
            {
                TempData["Danger"] = $"Oppps something went wrong {e.Message}";

                throw;
            }
        }
Example #4
0
        public ActionResult Index()
        {
            FiscalYearModel model = new FiscalYearModel();

            model.FiscalYearList = pro.GetList();

            return(View(model));
        }
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            FiscalYearModel fiscalYearModel = await db.FiscalYearModel.FindAsync(id);

            db.FiscalYearModel.Remove(fiscalYearModel);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #6
0
 public FiscalYearModel GetObject(int id)
 {
     using (EHMSEntities ent = new EHMSEntities())
     {
         var             obj   = ent.SetupFiscalYears.Where(x => x.FiscalYearId == id).FirstOrDefault();
         FiscalYearModel model = AutoMapper.Mapper.Map <SetupFiscalYear, FiscalYearModel>(obj);
         return(model);
     }
 }
        public async Task <ActionResult> Edit([Bind(Include = "FicalYearId,FiscalYear")] FiscalYearModel fiscalYearModel)
        {
            if (ModelState.IsValid)
            {
                db.Entry(fiscalYearModel).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(fiscalYearModel));
        }
        public async Task <ActionResult> Create([Bind(Include = "FicalYearId,FiscalYear")] FiscalYearModel fiscalYearModel)
        {
            if (ModelState.IsValid)
            {
                db.FiscalYearModel.Add(fiscalYearModel);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(fiscalYearModel));
        }
Example #9
0
 public void Update(FiscalYearModel model)
 {
     using (EHMSEntities ent = new EHMSEntities())
     {
         var  objtoedit = ent.SetupFiscalYears.Where(x => x.FiscalYearId == model.FiscalYearId).FirstOrDefault();
         char c         = Convert.ToChar(objtoedit.IsCurrent);
         AutoMapper.Mapper.Map(model, objtoedit);
         objtoedit.IsCurrent        = c.ToString();
         ent.Entry(objtoedit).State = System.Data.EntityState.Modified;
         ent.SaveChanges();
     }
 }
Example #10
0
 //update fiscal year will update only isActive
 public static void UpdateFiscalYear(FiscalYearModel fiscal, AccountingDbContext accDbContext)
 {
     try
     {
         accDbContext.FiscalYears.Attach(fiscal);
         accDbContext.Entry(fiscal).Property(x => x.IsActive).IsModified = true;
         accDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #11
0
 public static void AddFiscalYear(FiscalYearModel fiscal, AccountingDbContext accDbContext)
 {
     try
     {
         fiscal.CreatedOn = System.DateTime.Now;
         accDbContext.FiscalYears.Add(fiscal);
         accDbContext.SaveChanges();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        // GET: FiscalYearModels/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            FiscalYearModel fiscalYearModel = await db.FiscalYearModel.FindAsync(id);

            if (fiscalYearModel == null)
            {
                return(HttpNotFound());
            }
            return(View(fiscalYearModel));
        }
Example #13
0
        public static FiscalYearModel FiscalYearToFiscalYearModel(FiscalYear model)
        {
            var fiscalYearModel = new FiscalYearModel
            {
                Id                = model.Id,
                CreatedDate       = model.CreatedDate,
                CurrentFiscalYear = model.CurrentFiscalYear,
                EndDate           = model.EndDate,
                EndDateNp         = model.EndDateNp,
                FiscalYearName    = model.FiscalYearName,
                StartDate         = model.StartDate,
                StartDateNp       = model.StartDateNp,
                UpdatedDate       = model.UpdatedDate
            };

            return(fiscalYearModel);
        }
Example #14
0
 public ActionResult Edit(int id, FiscalYearModel model)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             pro.Update(model);
             TempData["success"] = "Record Updated Successfully !";
             return(RedirectToAction("Index"));
         }
         else
         {
             return(View(model));
         }
     }
     catch
     {
         return(View());
     }
 }
Example #15
0
        public int Insert(FiscalYearModel model)
        {
            using (EHMSEntities ent = new EHMSEntities())
            {
                if (ent.SetupFiscalYears.Any(s => s.FiscalYearBS == model.FiscalYearBS || s.FiscalYearAD == model.FiscalYearAD))
                {
                    return(0);
                }
                var objList = ent.SetupFiscalYears.ToList();
                foreach (var item in objList)
                {
                    item.IsCurrent        = "N";
                    ent.Entry(item).State = System.Data.EntityState.Modified;
                    ent.SaveChanges();
                }

                var objToSave = AutoMapper.Mapper.Map <FiscalYearModel, SetupFiscalYear>(model);

                objToSave.IsCurrent = "N";
                ent.SetupFiscalYears.Add(objToSave);
                ent.SaveChanges();
                return(1);
            }
        }
Example #16
0
        public void UpdateFiscalYearRecord(FiscalYearModel model)
        {
            using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
            {
                var fiscalYear = Db.FiscalYears.FirstOrDefault(x => x.Id == model.Id);

                if (fiscalYear != null)
                {
                    fiscalYear.FiscalYearName    = model.FiscalYearName ?? fiscalYear.FiscalYearName;
                    fiscalYear.CreatedDate       = model.CreatedDate ?? fiscalYear.CreatedDate;
                    fiscalYear.UpdatedDate       = model.UpdatedDate ?? fiscalYear.UpdatedDate;
                    fiscalYear.StartDate         = model.StartDate;
                    fiscalYear.EndDate           = model.EndDate;
                    fiscalYear.StartDateNp       = model.StartDateNp ?? fiscalYear.StartDateNp;
                    fiscalYear.EndDateNp         = model.EndDateNp ?? fiscalYear.EndDateNp;
                    fiscalYear.CurrentFiscalYear = model.CurrentFiscalYear;
                }

                Db.Entry(fiscalYear).CurrentValues.SetValues(fiscalYear);
                Db.SaveChanges();

                ts.Complete();
            }
        }
Example #17
0
        //
        // GET: /FiscalYear/Create

        public ActionResult Create()
        {
            FiscalYearModel model = new FiscalYearModel();

            return(View(model));
        }
Example #18
0
        public void Update(FiscalYearModel model)
        {
            var fiscalYear = Mapper.FiscalYearMapper.FiscalYearModelToFiscalYear(model);

            unitOfWork.FiscalYearRepository.Update(fiscalYear);
        }
Example #19
0
        public string Update(/*string reqType*/)
        {
            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>();

            AccountingDbContext accountingDBContext = new AccountingDbContext(connString);


            try
            {
                //string str = Request.Form.Keys.First<string>();
                string   str         = this.ReadPostData();
                string   reqType     = this.ReadQueryStringData("reqType");
                RbacUser currentUser = HttpContext.Session.Get <RbacUser>("currentuser");
                if (!String.IsNullOrEmpty(str))
                {
                    if (reqType == "itemISActive")
                    {
                        ItemModel item = DanpheJSONConvert.DeserializeObject <ItemModel>(str);
                        accountingDBContext.Items.Attach(item);
                        accountingDBContext.Entry(item).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Results = item;
                        responseData.Status  = "OK";
                    }
                    else if (reqType == "ledgerISActive")
                    {
                        LedgerModel ledger = DanpheJSONConvert.DeserializeObject <LedgerModel>(str);
                        accountingDBContext.Ledgers.Attach(ledger);
                        accountingDBContext.Entry(ledger).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Results = ledger;
                        responseData.Status  = "OK";
                    }
                    else if (reqType == "updateLedgerGrpIsActive")
                    {
                        LedgerGroupModel ledgerGrp = DanpheJSONConvert.DeserializeObject <LedgerGroupModel>(str);
                        accountingDBContext.LedgerGroups.Attach(ledgerGrp);
                        accountingDBContext.Entry(ledgerGrp).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ledgerGrp;
                    }
                    else if (reqType == "updateLedgerGroup")
                    {
                        LedgerGroupModel ledgerGroup = DanpheJSONConvert.DeserializeObject <LedgerGroupModel>(str);
                        var ledgerGrp = accountingDBContext.LedgerGroups.Where(x => x.LedgerGroupId == ledgerGroup.LedgerGroupId).FirstOrDefault();
                        if (ledgerGrp != null)
                        {
                            ledgerGrp.COA             = ledgerGroup.COA;
                            ledgerGrp.Description     = ledgerGroup.Description;
                            ledgerGrp.IsActive        = ledgerGroup.IsActive;
                            ledgerGrp.LedgerGroupName = ledgerGroup.LedgerGroupName;
                            ledgerGrp.ModifiedBy      = ledgerGroup.ModifiedBy;
                            ledgerGrp.ModifiedOn      = System.DateTime.Now;
                            ledgerGrp.PrimaryGroup    = ledgerGroup.PrimaryGroup;

                            accountingDBContext.LedgerGroups.Attach(ledgerGrp);
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.COA).IsModified             = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.Description).IsModified     = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.IsActive).IsModified        = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.LedgerGroupName).IsModified = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.ModifiedBy).IsModified      = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.ModifiedOn).IsModified      = true;
                            accountingDBContext.Entry(ledgerGrp).Property(x => x.PrimaryGroup).IsModified    = true;
                            accountingDBContext.SaveChanges();
                            responseData.Results = ledgerGrp;
                            responseData.Status  = "OK";
                        }
                        else
                        {
                            responseData.Status = "Failed";
                        }
                    }
                    else if (reqType == "updateFiscalYearStatus")
                    {
                        FiscalYearModel fiscalYearModel = DanpheJSONConvert.DeserializeObject <FiscalYearModel>(str);
                        accountingDBContext.FiscalYears.Attach(fiscalYearModel);
                        accountingDBContext.Entry(fiscalYearModel).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = fiscalYearModel;
                    }
                    else if (reqType == "updateCostCenterItemStatus")
                    {
                        CostCenterItemModel ccImodel = DanpheJSONConvert.DeserializeObject <CostCenterItemModel>(str);
                        accountingDBContext.CostCenterItems.Attach(ccImodel);
                        accountingDBContext.Entry(ccImodel).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ccImodel;
                    }
                    else if (reqType == "updateLedgerGrpCategoryIsActive")
                    {
                        LedgerGroupCategoryModel ledgerGrpCat = DanpheJSONConvert.DeserializeObject <LedgerGroupCategoryModel>(str);
                        accountingDBContext.LedgerGroupsCategory.Attach(ledgerGrpCat);
                        accountingDBContext.Entry(ledgerGrpCat).Property(x => x.IsActive).IsModified = true;
                        accountingDBContext.SaveChanges();
                        responseData.Status  = "OK";
                        responseData.Results = ledgerGrpCat;
                    }
                    else if (reqType == "UpdateLedger")
                    {
                        LedgerModel ledger = DanpheJSONConvert.DeserializeObject <LedgerModel>(str);
                        var         led    = accountingDBContext.Ledgers.Where(s => s.LedgerId == ledger.LedgerId).FirstOrDefault();
                        if (led != null)
                        {
                            led.IsActive               = ledger.IsActive;
                            led.LedgerName             = ledger.LedgerName;
                            led.OpeningBalance         = ledger.OpeningBalance;
                            led.Description            = ledger.Description;
                            led.IsCostCenterApplicable = ledger.IsCostCenterApplicable;
                            led.DrCr = ledger.DrCr;
                            accountingDBContext.Ledgers.Attach(led);
                            accountingDBContext.Entry(led).Property(x => x.IsActive).IsModified               = true;
                            accountingDBContext.Entry(led).Property(x => x.LedgerName).IsModified             = true;
                            accountingDBContext.Entry(led).Property(x => x.Description).IsModified            = true;
                            accountingDBContext.Entry(led).Property(x => x.DrCr).IsModified                   = true;
                            accountingDBContext.Entry(led).Property(x => x.IsCostCenterApplicable).IsModified = true;
                            accountingDBContext.Entry(led).Property(x => x.OpeningBalance).IsModified         = true;
                            accountingDBContext.SaveChanges();
                            responseData.Status  = "OK";
                            responseData.Results = led;
                        }
                        else
                        {
                            responseData.Status = "Failed";
                        }
                    }

                    else if (reqType == "UpdateVoucherHead")
                    {
                        VoucherHeadModel voucher = DanpheJSONConvert.DeserializeObject <VoucherHeadModel>(str);
                        var voucherHead          = accountingDBContext.VoucherHeads.Where(s => s.VoucherHeadId == voucher.VoucherHeadId).FirstOrDefault();
                        if (voucherHead != null)
                        {
                            voucherHead.IsActive        = voucher.IsActive;
                            voucherHead.VoucherHeadName = voucher.VoucherHeadName;
                            voucherHead.Description     = voucher.Description;
                            voucherHead.ModifiedOn      = System.DateTime.Now;
                            voucherHead.ModifiedBy      = voucher.ModifiedBy;
                            accountingDBContext.VoucherHeads.Attach(voucherHead);
                            accountingDBContext.Entry(voucherHead).Property(x => x.IsActive).IsModified        = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.VoucherHeadName).IsModified = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.Description).IsModified     = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.ModifiedOn).IsModified      = true;
                            accountingDBContext.Entry(voucherHead).Property(x => x.ModifiedBy).IsModified      = true;
                            accountingDBContext.SaveChanges();
                            responseData.Status  = "OK";
                            responseData.Results = voucherHead;
                        }
                        else
                        {
                            responseData.Status = "Failed";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }
            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }
Example #20
0
        //public static Boolean AccountClosureTransaction(AccountClosureVM closureVM, AccountingDbContext accountingDb)
        //{
        //    using (var dbContextTransaction = accountingDb.Database.BeginTransaction())
        //    {
        //        try
        //        {
        //            FiscalYearModel fy = accountingDb.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault();

        //            if (fy != null)
        //            {
        //                fy.IsActive = false;
        //                UpdateFiscalYear(fy, accountingDb);
        //            }

        //            AddFiscalYear(closureVM.nextFiscalYear, accountingDb);

        //            closureVM.TnxModel.FiscalyearId = closureVM.nextFiscalYear.FiscalYearId;
        //            closureVM.TnxModel.VoucherId = 1;
        //            AddTransaction(closureVM.TnxModel, accountingDb);
        //            dbContextTransaction.Commit();
        //            return true;
        //        }
        //        catch (Exception ex)
        //        {
        //            dbContextTransaction.Rollback();
        //            throw ex;
        //        }
        //    }
        //}

        #region account closure
        //Ajay 24-10-2018
        public static bool AccountClosure(FiscalYearModel fiscalYear, AccountingDbContext accountingDBContext)
        {
            using (var dbContextTransaction = accountingDBContext.Database.BeginTransaction())
            {
                try
                {
                    //get active fiscal year and deactive it
                    FiscalYearModel fy = accountingDBContext.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault();
                    if (fy != null)
                    {
                        fy.IsActive = false;
                        UpdateFiscalYear(fy, accountingDBContext);
                    }
                    //add new fiscal year
                    AddFiscalYear(fiscalYear, accountingDBContext);
                    //get active ledgers with primary group Assets or Liabialities
                    var ledgers = (from led in accountingDBContext.Ledgers
                                   join ledGrp in accountingDBContext.LedgerGroups on led.LedgerGroupId equals ledGrp.LedgerGroupId
                                   where led.IsActive == true   // && (ledGrp.PrimaryGroup == "Assets" || ledGrp.PrimaryGroup == "Liabilities")
                                   select new
                    {
                        led.LedgerId,
                        led.OpeningBalance,
                        led.DrCr,
                        ledGrp.PrimaryGroup
                    }).ToList();

                    ledgers.ForEach(ledger =>
                    {
                        LedgerBalanceHistoryModel ledgerBalanceHistory = new LedgerBalanceHistoryModel();
                        LedgerModel led = accountingDBContext.Ledgers.Where(x => x.LedgerId == ledger.LedgerId).FirstOrDefault();
                        //calculate closing balance
                        if (ledger.PrimaryGroup == "Assets" || ledger.PrimaryGroup == "Liabilities")
                        {
                            double drAmount = accountingDBContext.TransactionItems
                                              .Where(x => x.LedgerId == ledger.LedgerId && x.DrCr == true)
                                              .Select(x => x.Amount).Sum().GetValueOrDefault();
                            double crAmount = accountingDBContext.TransactionItems
                                              .Where(x => x.LedgerId == ledger.LedgerId && x.DrCr == false)
                                              .Select(x => x.Amount).Sum().GetValueOrDefault();

                            if (led.DrCr == true)
                            {
                                drAmount = drAmount + led.OpeningBalance.Value;
                            }
                            if (led.DrCr == false)
                            {
                                crAmount = crAmount + led.OpeningBalance.Value;
                            }
                            if (drAmount > crAmount)
                            {
                                ledgerBalanceHistory.ClosingDrCr    = true;
                                ledgerBalanceHistory.ClosingBalance = drAmount - crAmount;

                                led.OpeningBalance = drAmount - crAmount;
                                led.DrCr           = true;
                            }
                            if (drAmount < crAmount)
                            {
                                ledgerBalanceHistory.ClosingDrCr    = false;
                                ledgerBalanceHistory.ClosingBalance = crAmount - drAmount;

                                led.OpeningBalance = crAmount - drAmount;
                                led.DrCr           = false;
                            }
                        }


                        //adding ledgerBalanceHistory
                        ledgerBalanceHistory.FiscalYearId   = accountingDBContext.FiscalYears.Where(a => a.IsActive == true).FirstOrDefault().FiscalYearId;
                        ledgerBalanceHistory.LedgerId       = ledger.LedgerId;
                        ledgerBalanceHistory.OpeningBalance = ledger.OpeningBalance;
                        ledgerBalanceHistory.OpeningDrCr    = led.DrCr;
                        ledgerBalanceHistory.CreatedOn      = DateTime.Now;
                        ledgerBalanceHistory.CreatedBy      = fiscalYear.CreatedBy;
                        accountingDBContext.LedgerBalanceHistory.Add(ledgerBalanceHistory);
                        accountingDBContext.SaveChanges();


                        //updating ledger opening balance
                        accountingDBContext.Ledgers.Attach(led);
                        accountingDBContext.Entry(led).Property(x => x.OpeningBalance).IsModified = true;
                        accountingDBContext.Entry(led).Property(x => x.DrCr).IsModified           = true;
                        accountingDBContext.SaveChanges();
                    });



                    dbContextTransaction.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    dbContextTransaction.Rollback();
                    throw ex;
                }
            }
        }
Example #21
0
        public string Post()
        {
            //if reqtype=employee, then use masterdbcontext.employee.add  and so on for others.

            DanpheHTTPResponse <object> responseData = new DanpheHTTPResponse <object>(); //type 'object' since we have variable return types

            responseData.Status = "OK";                                                   //by default status would be OK, hence assigning at the top
            AccountingDbContext accountingDBContext = new AccountingDbContext(connString);
            RbacUser            currentUser         = HttpContext.Session.Get <RbacUser>("currentuser");

            try
            {
                string str         = this.ReadPostData();
                string reqType     = this.ReadQueryStringData("reqType");
                string companyName = this.ReadQueryStringData("companyName");

                if (reqType == "AddLedgers")
                {
                    LedgerModel ledger = DanpheJSONConvert.DeserializeObject <LedgerModel>(str);
                    if (accountingDBContext.Ledgers.Any(r => r.LedgerGroupId == ledger.LedgerGroupId && r.LedgerName == ledger.LedgerName))
                    {
                        responseData.Status = "Failed";
                    }
                    else
                    {
                        ledger.CreatedOn = System.DateTime.Now;
                        accountingDBContext.Ledgers.Add(ledger);
                        accountingDBContext.SaveChanges();
                        if (ledger.LedgerType == "pharmacysupplier")
                        {
                            LedgerMappingModel ledgerMapping = new LedgerMappingModel();
                            ledgerMapping.LedgerId    = ledger.LedgerId;
                            ledgerMapping.LedgerType  = ledger.LedgerType;
                            ledgerMapping.ReferenceId = (int)ledger.LedgerReferenceId;
                            accountingDBContext.LedgerMappings.Add(ledgerMapping);
                        }
                        accountingDBContext.SaveChanges();
                        responseData.Results = ledger;
                        responseData.Status  = "OK";
                    }
                }
                if (reqType == "AddLedgersList")
                {
                    List <LedgerModel> Ledgrs = DanpheJSONConvert.DeserializeObject <List <LedgerModel> >(str);
                    //if (accountingDBContext.Ledgers.Any(r => r.LedgerGroupId == ledger.LedgerGroupId && r.LedgerName == ledger.LedgerName))
                    //{
                    //    responseData.Status = "Failed";
                    //}
                    //else
                    //{
                    Ledgrs.ForEach(ledger =>
                    {
                        ledger.CreatedOn = System.DateTime.Now;
                        accountingDBContext.Ledgers.Add(ledger);
                        accountingDBContext.SaveChanges();
                        if (ledger.LedgerType == "pharmacysupplier")
                        {
                            LedgerMappingModel ledgerMapping = new LedgerMappingModel();
                            ledgerMapping.LedgerId           = ledger.LedgerId;
                            ledgerMapping.LedgerType         = ledger.LedgerType;
                            ledgerMapping.ReferenceId        = (int)ledger.LedgerReferenceId;
                            accountingDBContext.LedgerMappings.Add(ledgerMapping);
                        }
                    });

                    accountingDBContext.SaveChanges();
                    responseData.Results = Ledgrs;
                    responseData.Status  = "OK";
                    //}
                }
                else if (reqType == "AddVouchers")
                {
                    VoucherModel voucher = DanpheJSONConvert.DeserializeObject <VoucherModel>(str);
                    voucher.CreatedOn = System.DateTime.Now;
                    voucher.CreatedBy = currentUser.UserId;
                    accountingDBContext.Vouchers.Add(voucher);
                    accountingDBContext.SaveChanges();
                    responseData.Results = voucher;
                    responseData.Status  = "OK";
                }

                else if (reqType == "AddVoucherHead")
                {
                    VoucherHeadModel voucherHead = DanpheJSONConvert.DeserializeObject <VoucherHeadModel>(str);
                    if (accountingDBContext.VoucherHeads.Any(x => x.VoucherHeadId == voucherHead.VoucherHeadId && x.VoucherHeadName == voucherHead.VoucherHeadName))
                    {
                        responseData.Status = "Failed";
                    }
                    else
                    {
                        voucherHead.CreatedOn = System.DateTime.Now;
                        voucherHead.CreatedBy = currentUser.UserId;
                        accountingDBContext.VoucherHeads.Add(voucherHead);
                        accountingDBContext.SaveChanges();
                        responseData.Results = voucherHead;
                        responseData.Status  = "OK";
                    }
                }
                else if (reqType == "AddItems")
                {
                    ItemModel item = DanpheJSONConvert.DeserializeObject <ItemModel>(str);
                    item.CreatedOn = System.DateTime.Now;
                    accountingDBContext.Items.Add(item);
                    accountingDBContext.SaveChanges();
                    var itemWithLedgerName = (from led in accountingDBContext.Ledgers
                                              where led.LedgerId == item.LedgerId
                                              select new
                    {
                        ItemId = item.ItemId,
                        ItemName = item.ItemName,
                        AvailableQuantity = item.AvailableQuantity,
                        IsActive = item.IsActive,
                        Description = item.Description,
                        LedgerId = item.LedgerId,
                        LedgerName = led.LedgerName
                    }
                                              );
                    responseData.Results = itemWithLedgerName;
                    responseData.Status  = "OK";
                }
                else if (reqType == "AddLedgersGroup")
                {
                    LedgerGroupModel ledgerGrpData = DanpheJSONConvert.DeserializeObject <LedgerGroupModel>(str);
                    if (accountingDBContext.LedgerGroups.Any(r => r.LedgerGroupName == ledgerGrpData.LedgerGroupName && r.COA == ledgerGrpData.COA && r.PrimaryGroup == ledgerGrpData.PrimaryGroup))
                    {
                        responseData.Status = "Failed";
                    }
                    else
                    {
                        ledgerGrpData.CreatedOn = DateTime.Now;
                        ledgerGrpData.CreatedBy = currentUser.UserId;
                        accountingDBContext.LedgerGroups.Add(ledgerGrpData);
                        accountingDBContext.SaveChanges();
                        responseData.Results = ledgerGrpData;
                        responseData.Status  = "OK";
                    }
                }
                else if (reqType == "manageVoucherWithLedgegroup")
                {
                    List <VoucherLedgerGroupMapModel> mappedData = DanpheJSONConvert.DeserializeObject <List <VoucherLedgerGroupMapModel> >(str);
                    var postMappedLedgerGroup = new List <VoucherLedgerGroupMapModel>();
                    var putMappedLedgerGroup  = new List <VoucherLedgerGroupMapModel>();
                    //map and separate two list for add and update
                    mappedData.ForEach(x =>
                    {
                        if (x.actionName == "post")
                        {
                            x.CreatedOn = DateTime.Now;
                            x.CreatedBy = currentUser.UserId;
                            postMappedLedgerGroup.Add(x);
                        }
                        else if (x.actionName == "put")
                        {
                            putMappedLedgerGroup.Add(x);
                        }
                    });
                    //update
                    foreach (var itm in putMappedLedgerGroup)
                    {
                        accountingDBContext.VoucherLedgerGroupMaps.Attach(itm);
                        accountingDBContext.Entry(itm).Property(x => x.IsActive).IsModified = true;
                    }
                    accountingDBContext.SaveChanges();

                    //add
                    foreach (var itm in postMappedLedgerGroup)
                    {
                        accountingDBContext.VoucherLedgerGroupMaps.Add(itm);
                    }
                    accountingDBContext.SaveChanges();
                    responseData.Status = "OK";
                }
                else if (reqType == "AddFiscalYear")
                {
                    FiscalYearModel fsModel = DanpheJSONConvert.DeserializeObject <FiscalYearModel>(str);

                    var checkFiscalYear = (from fs in accountingDBContext.FiscalYears
                                           where ((fs.FiscalYearName == fsModel.FiscalYearName) && (fs.IsActive == true))
                                           select fs).FirstOrDefault();
                    if (checkFiscalYear != null)
                    {
                        fsModel = null;
                        responseData.Results = fsModel;
                    }
                    else
                    {
                        fsModel.CreatedOn = System.DateTime.Now;
                        fsModel.CreatedBy = currentUser.UserId;
                        accountingDBContext.FiscalYears.Add(fsModel);
                        accountingDBContext.SaveChanges();

                        var fiscalCurtData = (from fisCal in accountingDBContext.FiscalYears
                                              where fisCal.FiscalYearId == fsModel.FiscalYearId
                                              select new
                        {
                            FiscalYearId = fisCal.FiscalYearId,
                            FiscalYearName = fisCal.FiscalYearName,
                            StartYear = fisCal.StartDate,
                            EndYear = fisCal.EndDate,
                            Description = fisCal.Description,
                            IsActive = fisCal.IsActive,
                        });
                        responseData.Results = fiscalCurtData;
                    }
                    responseData.Status = "OK";
                }
                else if (reqType == "AddCostCenterItem")
                {
                    CostCenterItemModel costCenterMod = DanpheJSONConvert.DeserializeObject <CostCenterItemModel>(str);
                    costCenterMod.CreatedOn = System.DateTime.Now;
                    costCenterMod.CreatedBy = currentUser.UserId;
                    accountingDBContext.CostCenterItems.Add(costCenterMod);
                    accountingDBContext.SaveChanges();

                    var curtCostCenterItmData = (from costCenterItm in accountingDBContext.CostCenterItems
                                                 where costCenterItm.CostCenterItemId == costCenterMod.CostCenterItemId
                                                 select new
                    {
                        CostCenterItemId = costCenterItm.CostCenterItemId,
                        CostCenterItemName = costCenterItm.CostCenterItemName,
                        Description = costCenterItm.Description,
                        IsActive = costCenterItm.IsActive,
                    });
                    responseData.Status  = "OK";
                    responseData.Results = curtCostCenterItmData;
                }
                else if (reqType == "AddLedgerGroupCategory")
                {
                    LedgerGroupCategoryModel ledGrpCatMod = DanpheJSONConvert.DeserializeObject <LedgerGroupCategoryModel>(str);
                    ledGrpCatMod.CreatedOn = System.DateTime.Now;
                    ledGrpCatMod.CreatedBy = currentUser.UserId;
                    accountingDBContext.LedgerGroupsCategory.Add(ledGrpCatMod);
                    accountingDBContext.SaveChanges();

                    var curtLedGrpCategoryData = (from ledgrpCat in accountingDBContext.LedgerGroupsCategory
                                                  join chartOfAcc in accountingDBContext.ChartOfAccounts on ledgrpCat.ChartOfAccountId equals chartOfAcc.ChartOfAccountId
                                                  where ledgrpCat.LedgerGroupCategoryId == ledGrpCatMod.LedgerGroupCategoryId
                                                  select new
                    {
                        LedgerGroupCategoryId = ledgrpCat.LedgerGroupCategoryId,
                        LedgerGroupCategoryName = ledgrpCat.LedgerGroupCategoryName,
                        ChartOfAccountName = chartOfAcc.ChartOfAccountName,
                        Description = ledgrpCat.Description,
                        IsActive = ledgrpCat.IsActive,
                        IsDebit = ledgrpCat.IsDebit,
                    });
                    responseData.Status  = "OK";
                    responseData.Results = curtLedGrpCategoryData;
                }
            }
            catch (Exception ex)
            {
                responseData.Status       = "Failed";
                responseData.ErrorMessage = ex.Message + " exception details:" + ex.ToString();
            }

            return(DanpheJSONConvert.SerializeObject(responseData, true));
        }