/// <summary> /// Sets New Depreciation /// </summary> /// <param name="sndVm">SetNewDepreciationViewModel object</param> /// <returns>Rollback Flag 1 or 0</returns> public int SetNewDepreciation(SetNewDepreciationViewModel sndVm) { var rollbackFlag = 0; using (SqlConnection con = new SqlConnection(TableConstant.CONNECTION_STRING)) { using (SqlCommand cmd = new SqlCommand("dbo.usp_SetNewDepreciation")) { cmd.CommandType = CommandType.StoredProcedure; cmd.Connection = con; cmd.Parameters.AddWithValue("@AssetPurchaseId", sndVm.AssetPurchaseId); cmd.Parameters.AddWithValue("@DepreciationRate", sndVm.DepreciationRate); cmd.Parameters.AddWithValue("@DepreciationType", sndVm.DepreciationType); cmd.Parameters.AddWithValue("@CurrentAssetValue", sndVm.CurrentAssetValue); cmd.Parameters.AddWithValue("@RateStatus", sndVm.RateStatus); cmd.Parameters.AddWithValue("@DepreciationEntryDate", sndVm.DepreciationEntryDate); var returnParameter = cmd.Parameters.Add("@RollBackFlag", SqlDbType.Int); returnParameter.Direction = ParameterDirection.ReturnValue; con.Open(); cmd.ExecuteNonQuery(); con.Close(); rollbackFlag = (int)returnParameter.Value; } } return(rollbackFlag); }
public PartialViewResult SetNewDepreciation(long id) { var purchaseObj = _repPurchaseAsset.GetAssetPurchaseDetails().Where(x => x.Id == id).SingleOrDefault(); var PurchaseNo = purchaseObj.PurchaseNo; var AssetName = _repAsset.GetAssetInfo().Where(x => x.Id == purchaseObj.AssetId).SingleOrDefault().AssetName; ViewBag.Title = String.Concat(Constant.SET_NEW_DEPRECIATION, " for ", AssetName, " - ", PurchaseNo); var previousDepreciationObj = _repDepreciation.GetPreviousDepreciation(id); var sndVm = new SetNewDepreciationViewModel() { DepreciationRate = (previousDepreciationObj != null) ? previousDepreciationObj.Rate : 0, DepreciationType = (previousDepreciationObj != null) ? previousDepreciationObj.DepreciationType : "fixed", AssetPurchaseId = id }; return(PartialView(sndVm)); }
public ActionResult SetNewDepreciation(FormCollection fc, long id) { var depreciationRate = Decimal.Parse(fc["formValue[DepreciationRate]"]); var depreciationType = fc["formValue[DepreciationType]"]; var depreciationEntryDate = fc["formValue[DepreciationEntryDate]"]; var purchasedDate = _repPurchaseAsset.GetAssetPurchaseDetails().Where(x => x.Id == id).SingleOrDefault().PurchasedDate; var purchasedPrice = _repPurchaseAsset.GetAssetPurchaseDetails().Where(x => x.Id == id).SingleOrDefault().PricePerUnit; var sndVm = new SetNewDepreciationViewModel() { AssetPurchaseId = id, DepreciationRate = depreciationRate, DepreciationType = depreciationType, //CurrentAssetValue = Decimal.Parse(GetCurrentAssetValue(purchasedPrice, // purchasedDate, // depreciationRate, // depreciationType).ToString("#.##")), //Calculate Asset Value, CurrentAssetValue = Decimal.Parse(CurrentItemValue.GetCurrentValue(id).ToString("#.##")), RateStatus = 1, DepreciationEntryDate = DateTime.Now }; var hasNewDepreciation = _repDepreciation.SetNewDepreciation(sndVm); var annualDepnNotificationObj = _repDepreciation.GetAnnualDepreciationNotifications(); sndVm.NewDepreciationCount = annualDepnNotificationObj.Count(); //Update Session Notification SessionHelper.NotificationCount = annualDepnNotificationObj.Count(); SessionHelper.TopNotification = annualDepnNotificationObj.ToList(); var json = "[]"; if (hasNewDepreciation == 1) { json = JsonConvert.SerializeObject(sndVm); } return(Json(json, JsonRequestBehavior.AllowGet)); }