public ActionResult DeletePurchasePaymentHistoryByID(GetDetailsByID getByid) { try { PurchasePaymentHistory pphd = db.PurchasePaymentHistory.Find(getByid.id); AccountList AccountList = db.AccountList.Find(pphd.AccountListID); pphd.DeleteBy = AppUtils.GetLoginUserID(); pphd.DeleteDate = AppUtils.GetDateTimeNow(); pphd.Status = AppUtils.TableStatusIsDelete; db.SaveChanges(); AccountList.InitialBalance += Convert.ToDecimal(pphd.PaymentAmount); AccountList.UpdateBy = AppUtils.GetLoginUserID(); AccountList.UpdateDate = AppUtils.GetDateTimeNow(); db.SaveChanges(); Purchase purchase = db.Purchase.Find(pphd.PurchaseID); purchase.PurchasePayment -= pphd.PaymentAmount; db.SaveChanges(); AccountingHistory accountingHistory = new AccountingHistory(); //Mode 1 mean Create 2 mean Update SetInformationForAccountHistory(ref accountingHistory, pphd, 1); db.AccountingHistory.Add(accountingHistory); db.SaveChanges(); return(Json(new { DeleteStatus = true, PaymentStatus = GetPaymentStatus(pphd.Status), DeleteBy = db.Employee.Find(pphd.DeleteBy).LoginName, DeleteDate = pphd.DeleteDate }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { DeleteStatus = false, }, JsonRequestBehavior.AllowGet)); } }
public ActionResult SavePurchasePayment(PurchasePaymentHistory pph) { AccountList accountList = db.AccountList.Find(pph.AccountListID); if (Convert.ToDouble(accountList.InitialBalance.Value) < pph.PaymentAmount) { return(Json(new { Success = false, Message = "Sorry This Account Does Not Have Suffiecient Balance ." }, JsonRequestBehavior.AllowGet)); } accountList.InitialBalance -= Convert.ToDecimal(pph.PaymentAmount); db.SaveChanges(); DateTime dt = new DateTime(); pph.PurchasePaymentDate = pph.PurchasePaymentDate.AddHours(dt.Hour).AddMinutes(dt.Minute).AddSeconds(dt.Second); pph.Status = AppUtils.TableStatusIsActive; pph.CreateBy = AppUtils.GetLoginUserID(); pph.CreateDate = AppUtils.GetDateTimeNow(); db.PurchasePaymentHistory.Add(pph); db.SaveChanges(); Purchase purchase = db.Purchase.Where(x => x.PurchaseID == pph.PurchaseID).FirstOrDefault(); purchase.PurchasePayment += pph.PaymentAmount; //db.Entry(purchase).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); AccountingHistory accountingHistory = new AccountingHistory(); //Mode 1 mean Create 2 mean Update SetInformationForAccountHistory(ref accountingHistory, pph, 1); db.AccountingHistory.Add(accountingHistory); db.SaveChanges(); return(Json(new { Success = true, Message = "Purchase Payment Added Successfully.", DueAmount = purchase.SubTotal - purchase.PurchasePayment, PaymentStatus = purchase.SubTotal > purchase.PurchasePayment ? "Pending" : "Paid" }, JsonRequestBehavior.AllowGet)); }
private void SetInformationForAccountHistory(ref AccountingHistory accountingHistory, PurchasePaymentHistory PurchasePaymentHistory, int CreateOrUpdate) { DateTime dt = AppUtils.GetDateTimeNow(); accountingHistory.Amount = Convert.ToDouble(PurchasePaymentHistory.PaymentAmount); if (CreateOrUpdate == 1)//mean create { accountingHistory.PurchaseID = PurchasePaymentHistory.PurchaseID; accountingHistory.ActionTypeID = (int)AppUtils.AccountingHistoryType.Purchase; accountingHistory.Date = AppUtils.GetDateTimeNow(); accountingHistory.DRCRTypeID = (int)AppUtils.AccountTransactionType.DR; accountingHistory.Description = PurchasePaymentHistory.Description; accountingHistory.Year = dt.Year; accountingHistory.Month = dt.Month; accountingHistory.Day = dt.Day; accountingHistory.CreateBy = AppUtils.GetLoginUserID(); accountingHistory.CreateDate = dt; accountingHistory.Status = AppUtils.TableStatusIsActive; } else { accountingHistory.UpdateBy = AppUtils.GetLoginUserID(); accountingHistory.UpdateDate = dt; } }