public DataModel.Contract SetNumberAndDate(Guid contractId) { var contract = AppContext.Contracts.FirstOrDefault(e => e.Id == contractId); if (contract.ContractDate != null && !string.IsNullOrEmpty(contract.Number)) { return(contract); } contract.ContractDate = DateTime.Now; contract.Number = Registrator.GetNumber("ContractNumbers").ToString(); AppContext.SaveChanges(); return(contract); }
public void CreateMaterialDirection(Guid drugDeclarationId) { var statusId = AppContext.Dictionaries.Where(d => d.Type == Dictionary.MaterialDirectionStatusDic.DicCode && d.Code == Dictionary.MaterialDirectionStatusDic.Created) .Select(d => d.Id).FirstOrDefault(); EXP_MaterialDirections mdirection = new EXP_MaterialDirections() { DrugDeclarationId = drugDeclarationId, CreateDate = DateTime.Now, Number = $"{DateTime.Now.Year}/{Registrator.GetNumber(MaterialDirectionCode)}", StatusId = statusId }; AppContext.EXP_MaterialDirections.Add(mdirection); AppContext.SaveChanges(); }
public void CreateMaterialDirectionAsync(Guid drugDeclarationId, Employee getExecutorByDicStageId) { var statusId = AppContext.Dictionaries.Where( d => d.Type == Dictionary.MaterialDirectionStatusDic.DicCode && d.Code == Dictionary.MaterialDirectionStatusDic.Created) .Select(d => d.Id).FirstOrDefault(); var number = $"{GetPrefixFromType(drugDeclarationId)}-{Registrator.GetNumber(MaterialDirectionCode)}/{DateTime.Now.Year}"; EXP_MaterialDirections mdirection = new EXP_MaterialDirections() { Id = Guid.NewGuid(), DrugDeclarationId = drugDeclarationId, CreateDate = DateTime.Now, ExecutorEmployeeId = getExecutorByDicStageId.Id, Number = number, StatusId = statusId }; AppContext.EXP_MaterialDirections.Add(mdirection); AppContext.SaveChanges(); }
public JsonResult CreateDirection(EXP_DirectionToPaysView model) { DirectionToPayRepository repository = new DirectionToPayRepository(); if (ModelState.IsValid) { EXP_DirectionToPays m = new EXP_DirectionToPays() { Id = Guid.NewGuid(), Number = Registrator.GetNumber("DirectionToPay").ToString(), DirectionDate = model.DirectionDate, Type = model.Type, TypeValue = string.Empty, //PayerId = , //PayerValue = , CreateEmployeeId = UserHelper.GetCurrentEmployee().Id, CreateEmployeeValue = UserHelper.GetCurrentEmployee().DisplayName, CreateDate = DateTime.Now }; var status = repository.GetStatusByCode(Dictionary.ExpDirectionToPayStatus.Created); m.StatusId = status.Id; m.StatusValue = status.Name; repository.Insert(m); //repository.Save(); if (model.Type == 1) { if (model.DrugDeclarations != null) { foreach (var modelDrugDeclaration in model.DrugDeclarations) { var drugDeclaration = repository.GetDrugDeclarationById(modelDrugDeclaration.Id); if (drugDeclaration != null) { m.EXP_DrugDeclaration.Add(drugDeclaration); if (drugDeclaration.ContractId != null) { var payer = repository.GetPayerByContractId(drugDeclaration.ContractId.Value); if (payer != null) { m.PayerId = payer.Id; m.PayerValue = payer.Name; } } m.EXP_DirectionToPays_PriceList = CreateDefaultPriceLists(drugDeclaration); } } } m.TotalPrice = 0; foreach (var expDirectionToPaysPriceList in m.EXP_DirectionToPays_PriceList) { m.TotalPrice += expDirectionToPaysPriceList.Total; } } else { if (model.DrugDeclarations != null) { foreach (var modelDrugDeclaration in model.DrugDeclarations) { var drugDeclaration = repository.GetDrugDeclarationById(modelDrugDeclaration.Id); if (drugDeclaration != null) { m.EXP_DrugDeclaration.Add(drugDeclaration); if (drugDeclaration.ContractId != null) { var payer = repository.GetPayerByContractId(drugDeclaration.ContractId.Value); if (payer != null) { m.PayerId = payer.Id; m.PayerValue = payer.Name; } } } } } m.TotalPrice = model.TotalPrice; m.PageCount = model.PageCount; m.PriceForPage = 2277; } repository.Save(); model.Id = m.Id; model.Number = m.Number; } return(Json(model, JsonRequestBehavior.AllowGet)); }
public ActionResult CreateCertificateOfCompletion(int stageId, Guid drugDeclarationId) { CertificateOfCompletionRepository repository = new CertificateOfCompletionRepository(); DictionaryRepository dictionary = new DictionaryRepository(false); var newStatusId = dictionary.GetDictionaryElementIdByTypeAndCode(Dictionary.CertificateOfCompletionStatusDic.DicCode, Dictionary.CertificateOfCompletionStatusDic.New); DirectionToPayRepository directionRepository = new DirectionToPayRepository(false); var directionToPay = directionRepository.GetAsQuarable( d => d.EXP_DrugDeclaration.Any(dd => dd.Id == drugDeclarationId) && d.Type == EXP_DirectionToPaysView.ExpertWorkType && d.DeleteDate == null).FirstOrDefault(); if (directionToPay != null) { var cert = repository.GetAsQuarable(coc => coc.DicStageId == stageId && coc.DrugDeclarationId == drugDeclarationId && coc.DeleteDate == null).FirstOrDefault(); bool isExist = cert != null; if (!isExist) { cert = new EXP_CertificateOfCompletion() { Id = Guid.NewGuid(), Number = Registrator.GetNumber("CertificateOfCompletion").ToString(), CreateEmployeeId = UserHelper.GetCurrentEmployee().Id, CreateDate = DateTime.Now, DeleteDate = null, ModifyDate = null, SendDate = null, StatusId = newStatusId, DicStageId = stageId, DrugDeclarationId = drugDeclarationId } } ; switch (stageId) { case CodeConstManager.STAGE_PRIMARY: cert.TotalPrice = directionToPay.TotalPrice * (decimal)0.7; break; case CodeConstManager.STAGE_SAFETYREPORT: cert.TotalPrice = directionToPay.TotalPrice * (decimal)0.3; break; default: break; } if (isExist) { repository.Update(cert); } else { repository.Insert(cert); } repository.Save(); } else { return(Json(new { IsSuccess = false, Message = "Отсутствует направление на оплату" }, JsonRequestBehavior.AllowGet)); } return(Json(new { IsSuccess = true, Message = "" }, JsonRequestBehavior.AllowGet)); }