public ActionResult Index()
        {
            var userId              = User.Identity.GetUserId();
            var UserInfo            = _unitOfWork.User.GetMyInfo(userId);
            var Company             = _unitOfWork.Company.GetMyCompany(UserInfo.fCompanyId);
            ResettingAccountsVM Obj = new ResettingAccountsVM
            {
                FromYear = UserInfo.CurrYear - 1,
                ToYear   = UserInfo.CurrYear,
                TheDecimalPointForTheForeignCurrency = Company.TheDecimalPointForTheForeignCurrency,
                TheDecimalPointForTheLocalCurrency   = Company.TheDecimalPointForTheLocalCurrency
            };

            return(View(Obj));
        }
        public JsonResult GetAccount(ResettingAccountsVM ObjToSave)
        {
            MsgUnit Msg = new MsgUnit();

            try
            {
                var    userId      = User.Identity.GetUserId();
                var    UserInfo    = _unitOfWork.User.GetMyInfo(userId);
                double SumSelected = 0;
                if (ObjToSave == null)
                {
                    return(Json(new List <ResttingAccountVM>(), JsonRequestBehavior.AllowGet));
                }

                if (!ModelState.IsValid)
                {
                    string Err    = " ";
                    var    errors = ModelState.Values.SelectMany(v => v.Errors);
                    foreach (ModelError error in errors)
                    {
                        Err = Err + error.ErrorMessage + " * ";
                    }

                    Msg.Msg  = Resources.Resource.SomthingWentWrong + " : " + Err;
                    Msg.Code = 0;
                    return(Json(Msg, JsonRequestBehavior.AllowGet));
                }

                string AccountType = "";
                if (ObjToSave.AccountType != null)
                {
                    foreach (var a in ObjToSave.AccountType)
                    {
                        AccountType = AccountType + a.AccountTypeID + ",";
                    }
                    AccountType = AccountType.Remove(AccountType.Length - 1, 1);

                    var d = _unitOfWork.NativeSql.GetAllAcountToResstting(AccountType, 0, UserInfo.CurrYear - 1);
                    if (d != null)
                    {
                        d           = d.Where(m => m.Total != 0).ToList();
                        SumSelected = d.Sum(m => m.Total);
                    }
                    else
                    {
                        SumSelected = 0;
                    }
                }



                var d2 = _unitOfWork.NativeSql.GetAllAcountToResstting(AccountType, 1, UserInfo.CurrYear - 1);
                d2 = d2.Where(m => m.Total != 0).ToList();
                foreach (var t in d2)
                {
                    if (t.Total < 0)
                    {
                        t.Credit = Math.Abs(t.Total);
                    }
                    else
                    {
                        t.Debit = Math.Abs(t.Total);
                    }
                }



                ResttingAccountVM SelectedAccountData = _unitOfWork.NativeSql.GetAllAcountToRessttingByAccount(ObjToSave.AccountNumber, UserInfo.CurrYear);
                if (SelectedAccountData == null)
                {
                    SelectedAccountData = new ResttingAccountVM
                    {
                        AccountNumber = ObjToSave.AccountNumber,
                        ArabicName    = ObjToSave.AccountName,

                        Total = 0
                    };
                }



                SelectedAccountData.Total = SelectedAccountData.Total + SumSelected;
                if (SelectedAccountData.Total < 0)
                {
                    SelectedAccountData.Credit = Math.Abs(SelectedAccountData.Total);
                }
                else
                {
                    SelectedAccountData.Debit = Math.Abs(SelectedAccountData.Total);
                }

                var dataList = d2.ToList();
                dataList.Add(SelectedAccountData);

                return(Json(dataList, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                Msg.Msg  = Resources.Resource.SomthingWentWrong + " : " + ex.Message.ToString();
                Msg.Code = 0;
                return(Json(new List <ResttingAccountVM>(), JsonRequestBehavior.AllowGet));
            }
        }