public virtual IActionResult _ContractPaymentAdd(int Id = 0) { var item = new PaymentExpenditure(); var model = new PaymentExpenditureModel() { Id = Id }; if (Id > 0) { item = _contractService.GetPaymentExpenditureById(Id); model = item.ToModel <PaymentExpenditureModel>(); } return(PartialView(model)); }
public virtual IActionResult Create(PaymentExpenditureModel model) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePaymentExpenditureCreate)) { return(AccessDeniedView()); } if (ModelState.IsValid && model.lstContractPayment.Count() > 0) { var noti = "admin.common.Added"; var item = new PaymentExpenditure(); if (model.Id > 0) { item = _contractService.GetPaymentExpenditureById(model.Id); } _contractModelFactory.PreparePaymentExpenditure(model, item); if (model.PaymentAdvanceId > 0) { item.PaymentAdvanceId = model.PaymentAdvanceId; item.AcceptanceId = null; } if (model.AcceptanceId > 0) { item.AcceptanceId = model.AcceptanceId; item.PaymentAdvanceId = null; } if (model.Id > 0) { _contractPaymentService.DeleteContractPaymentsByExpenditureId(item.Id); _contractService.UpdatePaymentExpenditure(item); noti = "admin.common.Updated"; } else { _contractService.InsertPaymentExpenditure(item); } foreach (ContractPaymentModel paymentModel in model.lstContractPayment) { var payment = new ContractPayment { CreatorId = _workContext.CurrentCustomer.Id, ApprovedDate = DateTime.Now, CreatedDate = DateTime.Now, IsReceipts = false, StatusId = (int)ContractPaymentStatus.Approved, }; var task = _workTaskService.GetTaskById(paymentModel.TaskId); payment.ExpenditureId = item.Id; payment.Description = item.Name + " " + task.Name; payment.Code = item.Code + task.Code; payment.TaskId = paymentModel.TaskId; payment.ContractId = task.ContractId; if (task.UnitId > 0) { payment.UnitId = (int)task.UnitId; } else { payment.UnitId = null; } if (task.CurrencyId > 0) { payment.CurrencyId = (int)task.CurrencyId; } else { payment.CurrencyId = (int)item.CurrencyId; } payment.Amount = paymentModel.Amount.ToNumber(); payment.TypeId = item.TypeId; _contractPaymentService.InsertContractPayment(payment); } return(JsonSuccessMessage(_localizationService.GetResource(noti), item.ToModel <PaymentExpenditureModel>())); } var list = ModelState.Values.Where(c => c.Errors.Count > 0).ToList(); return(JsonErrorMessage("Error", list)); }