Example #1
0
        public async Task <IActionResult> AltAppDetails(Guid id, string sort)
        {
            var application = (await _commonDataService.GetDtoAsync <ImlAppDetailDTO>(x => x.Id == id)).FirstOrDefault();

            if (application == null)
            {
                return(await Task.Run(() => NotFound()));
            }

            // ATU
            if (application.AddressId != Guid.Empty)
            {
                var subAddress = _commonDataService.GetDto <AtuSubjectAddressDTO>(p => p.Id == application.AddressId).SingleOrDefault();
                if (subAddress != null)
                {
                    application.PostIndex = subAddress.PostIndex;
                    ViewBag.Address       = subAddress.Address;
                }
            }
            ViewBag.IsEditable    = _entityStateHelper.GetAppStates(id)[nameof(BaseApplication.BackOfficeAppState)] == "Project";
            ViewBag.PerformerName = _commonDataService.GetDto <UserDetailsDTO>(p => p.Id == application.PerformerId).Select(p => p.FIO).SingleOrDefault();
            switch (sort)
            {
            case "CancelLicenseApplication":
            case "DecreaseIMLApplication":
                if (sort == "CancelLicenseApplication")
                {
                    HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про анулювання ліцензії(імпорт)"));
                }
                else
                {
                    HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про звуження провадження виду господарської діяльності - Звуження виробництва лікарських засобів"));
                }
                return(View("Details_CancelLicenseApplication", application));

            case "ChangeAutPersonApplication":
                HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про зміну інформації у додатку до ліцензії щодо особливих умов провадження діяльності - Зміна уповноважених осіб"));
                return(View("Details_ChangeAutPersonApplication", application));

            case "AddBranchApplication":
                HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про внесення до ЄДР відомостей про місце провадження господарської діяльності - Додавання МПД(імпорт)"));
                return(View("Details_AddBranchApplication", application));

            case "RemBranchApplication":
                HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про внесення змін до ЄДР у зв’язку з припиненням діяльності за певним місцем провадження - Видалення МПД(імпорт)"));
                return(View("Details_RemBranchApplication", application));

            case "ChangeDrugList":
                HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про зміну (доповнення) переліку лікарських засобів, що імпортує ліцензіат"));
                return(View("Details_ChangeDrugList", application));

            case "ReplacementDrugList":
                HttpContext.ModifyCurrentBreadCrumb((crumb => crumb.Name = "Заява про заміну переліку лікарських засобів, що імпортує ліцензіат"));
                return(View("Details_ReplacementDrugList", application));

            default:
                return(await Task.Run(() => NotFound()));
            }
        }
        public bool RegisterApplication(AppShortDTO model)
        {
            _entityStateHelper.CheckChangeAppStatus(model.Id, "Registered");
            var prlApplication = _dataService.GetEntity <PrlApplication>(app => app.Id == model.Id).Single();

            //if (prlApplication.RegNumber == model.RegNumber)
            //{
            //    return false;
            //}
            _objectMapper.Map(model, prlApplication);
            _dataService.SaveChanges();
            var appDetailDto = _dataService.GetDto <PrlAppDetailDTO>(application => application.Id == prlApplication.Id).Single();

            var DublicateRegNum = _dataService.GetDto <PrlAppDetailDTO>(x =>
                                                                        x.RegNumber == appDetailDto.RegNumber && x.RegDate == appDetailDto.RegDate).ToList();

            if (DublicateRegNum.Count <= 1)
            {
                var backOfficeState = prlApplication.BackOfficeAppState;
                var appState        = prlApplication.AppState;

                prlApplication.BackOfficeAppState = "Registered";
                prlApplication.AppState           = "InReview";
                _dataService.SaveChanges();

                try
                {
                    if (prlApplication.AppSort != "AdditionalInfoToLicense")
                    {
                        _limsExchangeService.InsertApplication(prlApplication);
                    }
                }
                catch (Exception e)
                {
                    prlApplication.BackOfficeAppState = backOfficeState;
                    prlApplication.AppState           = appState;
                    prlApplication.RegDate            = null;
                    prlApplication.RegNumber          = null;
                    _dataService.SaveChanges();
                    throw new Exception("Виникла помилка при регестрації заяви. Зверніться до адміністратора", e);
                }

                return(true);
            }
            else
            {
                //_dataService.Remove(prlApplication);
                return(false);
            }
        }
Example #3
0
        public IActionResult ModalUser()
        {
            var userInfo = _userInfoService.GetCurrentUserInfo();
            var userAreaEmployeeDetailDTO = new UserAreaEmployeeDetailDTO();
            var userAreaPersonDetailDTO   = new UserAreaPersonDetailDTO();
            var userAreaOrgDetailDTO      = new UserAreaOrgDetailDTO();

            try
            {
                // TODO переделать в один запрос
                Guid personGuid = userInfo.PersonId;
                userAreaEmployeeDetailDTO = _commonDataService.GetDto <UserAreaEmployeeDetailDTO>(org_employee => (org_employee.PersonId == userInfo.PersonId)).FirstOrDefault();
                userAreaPersonDetailDTO   = _commonDataService.GetDto <UserAreaPersonDetailDTO>(person => (person.Id == userInfo.PersonId)).FirstOrDefault();
                userAreaOrgDetailDTO      = _commonDataService.GetDto <UserAreaOrgDetailDTO>(org_organization => (org_organization.Id == userAreaEmployeeDetailDTO.OrgId)).FirstOrDefault();
            }
            catch
            {
                return(NotFound());
            }

            var model = new UserAreaDetailDTO
            {
                PIB       = userAreaPersonDetailDTO.LastName + " " + userAreaPersonDetailDTO.Name + " " + userAreaPersonDetailDTO.MiddleName,
                Position  = userAreaEmployeeDetailDTO.Position,
                UserEmail = userAreaEmployeeDetailDTO.UserEmail,
                OrgEmail  = userAreaOrgDetailDTO.Email,
                Phone     = userAreaPersonDetailDTO.Phone,

                INN = userAreaPersonDetailDTO.IPN,

                ReceiveOnChangeAllApplication = userAreaEmployeeDetailDTO.ReceiveOnChangeAllApplication,
                ReceiveOnChangeAllMessage     = userAreaEmployeeDetailDTO.ReceiveOnChangeAllMessage,
                ReceiveOnChangeOwnApplication = userAreaEmployeeDetailDTO.ReceiveOnChangeOwnApplication,
                ReceiveOnChangeOwnMessage     = userAreaEmployeeDetailDTO.ReceiveOnChangeOwnMessage,
                PersonalCabinetStatus         = userAreaEmployeeDetailDTO.PersonalCabinetStatus,
                ReceiveOnChangeOrgInfo        = userAreaEmployeeDetailDTO.ReceiveOnChangeOrgInfo,
                ReceiveOnOverduePayment       = userAreaEmployeeDetailDTO.ReceiveOnOverduePayment
            };

            if (userAreaOrgDetailDTO.Edrpou != null)
            {
                model.EDRPOU = userAreaOrgDetailDTO.Edrpou;
            }
            else
            {
                model.EDRPOU = "Фізична особа-підприємець (РНОКПП (Індивідуальний податковий номер): " + userAreaPersonDetailDTO.IPN + ")";
            }

            return(PartialView("_ModalUserArea", model));
        }
Example #4
0
        public IActionResult CancelPayment(Guid appId)
        {
            var edoc = _dataService.GetDto <EDocumentDetailsDTO>(p => p.EntityId == appId && p.EDocumentType == "PaymentDocument" && p.EDocumentStatus == "WaitingForConfirmation",
                                                                 extraParameters: new object[] { $"\'{appId}\'" }).SingleOrDefault();

            return(PartialView("_ModalPaymentCommentEdit", edoc));
        }
Example #5
0
        public SelectList List <T>(
            string idPropertyName   = "Id",
            string textPropertyName = "Caption",
            Expression <Func <T, bool> > predicate = null,
            Func <IQueryable <T>, IOrderedQueryable <T> > orderBy = null,
            string initialSelectedValue = null,
            int skip = 0,
            int take = 0,
            int expirationTimeSeconds = 0) where T : CoreDTO
        {
            var data = _dataService.GetDto <T>(predicate, orderBy, cacheResultDuration: expirationTimeSeconds)
                       .Skip(skip);

            if (take > 0)
            {
                data = data.Take(take);
            }

            var selList = new SelectList(data, idPropertyName, textPropertyName);

            InitSelectList(ref selList, initialSelectedValue);
            return(selList);
        }
Example #6
0
        public async Task <AppAssigneeDetailDTO> Edit(Guid?id, IDictionary <string, string> paramList)
        {
            paramList.TryGetValue("appId", out var strAppId);
            paramList.TryGetValue("AppSort", out var sort);
            paramList.TryGetValue("AppType", out var type);

            var appId = new Guid(strAppId);
            AppAssigneeDetailDTO model;

            if (id == null)
            {
                model = new AppAssigneeDetailDTO();
                if (type == "PRL" || type == "IML")
                {
                    model.OrgPositionType = "Authorized";
                }
                else if (type == "TRL")
                {
                    model.AppType = type;
                }
            }
            else
            {
                var entityId = Guid.Parse(id.ToString());
                model = DataService.GetDto <AppAssigneeDetailDTO>(dto => dto.Id == entityId).Single();
                if (type == "TRL")
                {
                    model.AppType = type;
                }
            }

            if (!string.IsNullOrEmpty(sort))
            {
                model.AppSort = sort;
            }


            if (model.OrgPositionType == "Manager")
            {
                model.BranchId = GetSelectedBranches(model.Id).FirstOrDefault();
            }
            else
            {
                model.ListOfBranches = GetSelectedBranches(model.Id).ToList();
            }

            model.appId = appId;
            return(model);
        }
Example #7
0
        public async Task UpdateBranch(Guid appId)
        {
            var branchIdList = _dataService.GetDto <BranchListDTO>(x => x.ApplicationId == appId).Select(x => x.Id);
            var branchList   = _dataService.GetEntity <Branch>(x => branchIdList.Contains(x.Id) && x.CreateDls == false && x.RecordState != RecordState.D).ToList();

            if (branchList.Any())
            {
                branchList.ForEach(x => x.CreateTds = true);
                try
                {
                    await _limsExchangeService.CreateTdsAsync(appId);
                }
                catch (Exception e)
                {
                    branchList.ForEach(x => x.CreateTds = false);
                }

                await _dataService.SaveChangesAsync();
            }
        }
Example #8
0
        public bool ChangePaymentStatus(Guid appId, string status, string comment = null)
        {
            var edoc = _commonDataService.GetEntity <EDocument>(p => p.EDocumentType == "PaymentDocument" && p.EntityId == appId);

            EDocument activeEdoc;

            switch (status)
            {
            case "WaitingForConfirmation":
                activeEdoc = edoc.SingleOrDefault(p => p.EDocumentStatus == "RequiresPayment");

                var files = _commonDataService.GetDto <FileStoreDTO>(p => p.EntityId == activeEdoc.Id).ToList();
                if (files.Count <= 0)
                {
                    return(false);
                }
                break;

            case "PaymentNotVerified":
            case "PaymentConfirmed":
                activeEdoc = edoc.SingleOrDefault(p => p.EDocumentStatus == "WaitingForConfirmation");
                break;

            default:
                return(false);
            }

            if (activeEdoc == null)
            {
                return(false);
            }

            activeEdoc.EDocumentStatus = status;
            activeEdoc.Comment         = comment;
            _commonDataService.SaveChanges();

            return(true);
        }
        public IActionResult ExpertiseDetails(Guid appId)
        {
            var expertise = _commonDataService.GetDto <TrlAppExpertiseDTO>(p => p.Id == appId).SingleOrDefault() ??
                            new TrlAppExpertiseDTO {
                Id = appId
            };

            expertise.PerformerName = _commonDataService.GetDto <UserDetailsDTO>(p => p.Id == expertise.PerformerOfExpertiseId).Select(p => p.FIO).SingleOrDefault();
            ViewBag.IsEditable      = _entityStateHelper.GetAppStates(appId)[nameof(BaseApplication.BackOfficeAppState)] != "Reviewed";
            return(PartialView("_trlExpertiseDetails", expertise));
        }
Example #10
0
        public async Task <IActionResult> Edit(Guid?id, Guid?appId, string sort)
        {
            BranchDetailsDTO         model;
            IEnumerable <EnumRecord> appActivityTypeList = new List <EnumRecord>();

            if (id == null)
            {
                if (appId == null)
                {
                    return(await Task.Run(() => NotFound()));
                }

                model = new BranchDetailsDTO();
                model.ApplicationId = appId.Value;
                //TODO null reference exception
                var apps = await _dataService.GetDtoAsync <ApplicationListDTO>(x => x.Id == appId);

                if (apps != null)
                {
                    model.AppType = apps.SingleOrDefault()?.AppTypeEnum;
                }
                else
                {
                    throw new NullReferenceException("ApplicationListDTO is null");
                }

                model.OrganizationId = new Guid((await _userInfoService.GetCurrentUserInfoAsync()).OrganizationId());

                if ((sort == "AddBranchApplication" && model.AppType == "TRL") || model.AppType == "TRL")
                {
                    appActivityTypeList = _branchService.GetAppActivityTypeList(sort, appId);
                }
            }
            else
            {
                model = (await _dataService.GetDtoAsync <BranchDetailsDTO>()).SingleOrDefault(x => x.Id == id.Value);
                if (model == null)
                {
                    return(NotFound());
                }

                model.AppType = (await _dataService.GetDtoAsync <ApplicationListDTO>()).SingleOrDefault(x => x.Id == model.ApplicationId)?.AppTypeEnum;

                var branchAppTypeModel = _dataService.GetDto <EntityEnumDTO>(x => x.BranchId == model.Id && x.EntityType == "BranchApplication")?.FirstOrDefault();

                model.TrlActivityType = branchAppTypeModel?.EnumCode;

                if ((sort == "AddBranchApplication" && model.AppType == "TRL") || model.AppType == "TRL")
                {
                    appActivityTypeList = _branchService.GetAppActivityTypeList(model.AppType, appId);
                }
            }

            if (model.AppType == "TRL")
            {
                var pharmacyList = _branchService.GetPharmacyList(id, appId);

                ViewBag.PharmacyList = new SelectList(pharmacyList.Select(p => new { p.Id, p.Name }), nameof(BranchListDTO.Id), nameof(BranchListDTO.Name));

                ViewBag.trlActivityTypeList =
                    new SelectList(appActivityTypeList, nameof(EnumRecord.Code), nameof(EnumRecord.Name));
            }

            model.OperationListDTO    = _formListService.GetOperationListDTO();
            ViewBag.OperationListJson = JsonConvert.SerializeObject(model.OperationListDTO);
            ViewBag.AppId             = appId;

            return(View(model));
        }
Example #11
0
        private void BaseTemplate(string templatePath, Guid id, out StringBuilder htmlFile, out Message pdfMessage)
        {
            var orgExt = new OrganizationExtDetailDTO();

            try
            {
                pdfMessage = _dataService.GetEntity <Message>(x => x.Id == id).FirstOrDefault();
                var orgId = pdfMessage.OrgUnitId;
                orgExt = _dataService.GetDto <OrganizationExtDetailDTO>(x => x.Id == orgId).FirstOrDefault();
            }
            catch
            {
                throw new Exception("Помилка при отриманні інформації про повідомлення та організацію");
            }

            var emailPath = Path.Combine(_path, templatePath);

            htmlFile = new StringBuilder(File.ReadAllText(emailPath));

            htmlFile.Replace("@@RegDate@@", " " + pdfMessage.MessageDate.ToString("« dd » MMMM yyyy", CultureInfo.CreateSpecificCulture("uk")));
            htmlFile.Replace("@@RegNumber@@", " " + pdfMessage.MessageNumber);
            htmlFile.Replace("@@OrgName@@", " '" + orgExt.Name + "' ");

            if (string.IsNullOrEmpty(orgExt.INN))
            {
                htmlFile.Replace("@@OrgCode@@", " (ЄДРПОУ " + orgExt.EDRPOU + ")&emsp;");
            }
            else
            {
                htmlFile.Replace("@@OrgCode@@", " (РНОКПП (Індивідуальний податковий номер) " + orgExt.INN + ")&emsp;");
            }

            if (!string.IsNullOrEmpty(pdfMessage.MessageText))
            {
                var commentPath     = Path.Combine(_path, "Templates/Messages/PDFTemplate_MessageComment.html");
                var htmlCommentFile = new StringBuilder(File.ReadAllText(commentPath));

                htmlCommentFile.Replace("@@MessageComment@@", pdfMessage.MessageText);
                htmlFile.Replace("@@MessageComment@@", htmlCommentFile.ToString());
            }
            else
            {
                htmlFile.Replace("@@MessageComment@@", "");
            }

            htmlFile.Replace("@@UserName@@", _userInfoService.GetCurrentUserInfo().FullName());
            htmlFile.Replace("@@Date@@", DateTime.Now.ToString("« dd » MMMM yyyy", CultureInfo.CreateSpecificCulture("uk")));
        }
Example #12
0
        //public async Task<string> TrlCreateLicenseApp(Guid id)
        //{
        //    // Генерація pdf для TRL

        //    var app = (await _dataService.GetDtoAsync<TrlAppDetailDTO>(x => x.Id == id)).FirstOrDefault();

        //    var branches = await _dataService.GetDtoAsync<BranchDetailsDTO>(x => x.ApplicationId == id);
        //    var assigneeBranches =
        //        _dataService.GetEntity<AppAssigneeBranch>(x => branches.Select(y => y.Id).Contains(x.BranchId)).Select(x => x.AssigneeId);
        //    var assignees = await _dataService.GetDtoAsync<AppAssigneeDetailDTO>(x => assigneeBranches.Contains(x.Id));
        //    if (app == null)
        //    {
        //        throw new Exception("No application");
        //    }

        //    //var trlActivityType = _dataService.GetEntity<EntityEnumRecords>(x => x.EntityId == id).Select(x => x.EnumRecordCode);
        //    //var enumR = _dataService.GetEntity<EnumRecord>(x => x.EnumType == "TrlActivityType" && trlActivityType.Contains(x.Code)).ToList();
        //    var a = _dataService.GetDto<EntityEnumDTO>(x => x.ApplicationId == id).ToList();

        //    var appObject = _objectMapper.Map<RptTrlAppDTO>(app);

        //    var checkbox = ((char)ushort.Parse("2611", NumberStyles.HexNumber)).ToString();

        //    var employeeList = "";
        //    var mpdList = "";

        //    var pathHtml = string.IsNullOrEmpty(app.EDRPOU)
        //        ? "Templates/Htmls/TRL/Htmls/CreateLicenseApp/PDFTemplate_CreateLicenseAppTRL_FOP.html"
        //        : "Templates/Htmls/TRL/Htmls/CreateLicenseApp/PDFTemplate_CreateLicenseAppTRL_ORG.html";
        //    var emailPath = Path.Combine(path, pathHtml);
        //    var htmlFile = new StringBuilder(File.ReadAllText(emailPath));

        //    var mpdPath = Path.Combine(path, "Templates/Htmls/TRL/Htmls/PDFTemplate_TRL_MPD.html");

        //    var empPath = Path.Combine(path, "Templates/Htmls/TRL/Htmls/PDFTemplate_TRL_AutPersonList.html");

        //    foreach (var employee in assignees)
        //    {
        //        var empFile = new StringBuilder(File.ReadAllText(empPath));

        //        empFile.Replace("@@AssigneTypeName@@", employee.AssigneTypeName);
        //        empFile.Replace("@@AutPersonPosition@@", employee.NameOfPosition);
        //        empFile.Replace("@@AutPersonSurname@@", employee.LastName);
        //        empFile.Replace("@@AutPersonName@@", employee.Name);
        //        empFile.Replace("@@AutPersonMiddleName@@", employee.MiddleName);
        //        empFile.Replace("@@AutPersonEducation@@", employee.EducationInstitution);
        //        empFile.Replace("@@AutPersonExperience@@", employee.WorkExperience);

        //        employeeList += empFile.ToString();
        //    }

        //    foreach (var branch in branches)
        //    {
        //        var mpdFile = new StringBuilder(File.ReadAllText(mpdPath));

        //        mpdFile.Replace("@@MPDName@@", branch.Name);

        //        mpdFile.Replace("@@AddressString@@", branch.PostIndex + ", " + branch.Address);
        //        mpdFile.Replace("@@AddressEng@@", branch.AdressEng);
        //        mpdFile.Replace("@@PhoneNumber@@", StandartPhone(branch.PhoneNumber));
        //        mpdFile.Replace("@@FaxNumber@@", StandartPhone(branch.FaxNumber));
        //        mpdFile.Replace("@@E-mail@@", branch.EMail);
        //        mpdFile.Replace("@@ListOfTrlActivityTypeName@@", branch.EMail);
        //        mpdFile.Replace("@@BranchTypeName@@", branch.EMail);
        //        mpdFile.Replace("@@SpecialConditions@@", branch.SpecialConditions);
        //        mpdFile.Replace("@@AsepticConditionsName@@", branch.AsepticConditions);

        //        mpdList += mpdFile.ToString();
        //    }

        //    htmlFile.Replace("@@AutPersonList@@", employeeList);
        //    htmlFile.Replace("@@MPD@@", mpdList);
        //    htmlFile.Replace("@@OrgName@@", appObject.OrgName);
        //    htmlFile.Replace("@@AddressString@@", appObject.PostIndex + ", " + appObject.Address);
        //    htmlFile.Replace("@@OrgDirector@@", appObject.OrgDirector);
        //    htmlFile.Replace("@@LegalFormTypeName@@", appObject.LegalFormName);
        //    htmlFile.Replace("@@EDRPOU@@", string.IsNullOrEmpty(appObject.EDRPOU) ? "</br>" : appObject.EDRPOU);
        //    htmlFile.Replace("@@Phone@@", StandartPhone(appObject.PhoneNumber));
        //    htmlFile.Replace("@@FaxNumber@@", StandartPhone(appObject.FaxNumber));
        //    htmlFile.Replace("@@EMail@@", appObject.EMail);
        //    htmlFile.Replace("@@EconomicClassificationTypeName@@", appObject.EconomicClassificationTypeName);
        //    htmlFile.Replace("@@ActivityTypeName@@", appObject.ActivityTypeName);
        //    htmlFile.Replace("@@NationalAccount@@", appObject.NationalAccount);
        //    htmlFile.Replace("@@NationalBankRequisites@@", appObject.NationalBankRequisites);
        //    htmlFile.Replace("@@InternationalAccount@@", appObject.InternationalAccount);
        //    htmlFile.Replace("@@InternationalBankRequisites@@", appObject.InternationalBankRequisites);
        //    htmlFile.Replace("@@Duns@@", appObject.Duns);
        //    htmlFile.Replace("@@IsConditionsForControl@@", appObject.IsConditionsForControl ? checkbox : "");
        //    htmlFile.Replace("@@IsCheckMPD@@", appObject.IsCheckMpd ? checkbox : "");
        //    htmlFile.Replace("@@IsPaperLicense@@", appObject.IsPaperLicense ? checkbox : "");
        //    htmlFile.Replace("@@IsCourierDelivery@@", appObject.IsCourierDelivery ? checkbox : "");
        //    htmlFile.Replace("@@IsPostDelivery@@", appObject.IsPostDelivery ? checkbox : "");
        //    htmlFile.Replace("@@IsAgreeLicenseTerms@@", appObject.IsAgreeLicenseTerms ? checkbox : "");
        //    htmlFile.Replace("@@IsAgreeProcesingData@@", appObject.IsAgreeProcessingData ? checkbox : "");
        //    htmlFile.Replace("@@IsCourierResults@@", appObject.IsCourierResults ? checkbox : "");
        //    htmlFile.Replace("@@IsPostResults@@", appObject.IsPostResults ? checkbox : "");
        //    htmlFile.Replace("@@IsElectricFormResults@@", appObject.IsElectricFormResults ? checkbox : "");

        //    htmlFile.Replace("@@PassportSerial@@", appObject.PassportSerial);
        //    htmlFile.Replace("@@PassportNumber@@", appObject.PassportNumber);
        //    htmlFile.Replace("@@PassportDate@@",
        //        appObject.PassportDate.HasValue
        //            ? appObject.PassportDate.Value.ToString("«dd» MMMM yyyy", CultureInfo.CreateSpecificCulture("uk"))
        //            : "");
        //    htmlFile.Replace("@@PassportIssueUnit@@", appObject.PassportIssueUnit);
        //    htmlFile.Replace("@@INN@@", string.IsNullOrEmpty(appObject.INN) ? "</br>" : appObject.INN);

        //    htmlFile.Replace("@@OrgEmployeeExt@@", employeeList);

        //    htmlFile.Replace("@@UserName@@", _userInfoService.GetCurrentUserInfo().FullName());
        //    htmlFile.Replace("@@Date@@",
        //        DateTime.Now.ToString("«dd» MMMM yyyy", CultureInfo.CreateSpecificCulture("uk")));

        //    var infoFile = GetAddon();
        //    htmlFile.Append(infoFile);

        //    return htmlFile.ToString();
        //}

        public async Task <string> TrlCreateLicenseApp(Guid id)
        {
            // Генерація pdf для TRL

            var app = (await _dataService.GetDtoAsync <TrlAppDetailDTO>(x => x.Id == id)).FirstOrDefault();

            var branches = await _dataService.GetDtoAsync <BranchDetailsDTO>(x => x.ApplicationId == id);

            if (app == null)
            {
                throw new Exception("No application");
            }

            var activityTypeList = _dataService.GetDto <EntityEnumDTO>(x => x.ApplicationId == id).Select(x => x.EnumCode);

            var appObject = _objectMapper.Map <RptTrlAppDTO>(app);

            var checkbox      = ((char)ushort.Parse("2611", NumberStyles.HexNumber)).ToString();
            var checkboxEmpty = ((char)ushort.Parse("2610", NumberStyles.HexNumber)).ToString();

            var mpdList = "";

            var pathHtml = "Templates/Htmls/TRL/Htmls/CreateLicenseApp/PDFTemplate_CreateLicenseAppTRL.html";

            var emailPath = Path.Combine(path, pathHtml);
            var htmlFile  = new StringBuilder(File.ReadAllText(emailPath));

            var mpdPath = Path.Combine(path, "Templates/Htmls/TRL/Htmls/PDFTemplate_TRL_MPD_License.html");

            foreach (var branch in branches)
            {
                var mpdFile      = new StringBuilder(File.ReadAllText(mpdPath));
                var activityType = _dataService.GetDto <EntityEnumDTO>(x => x.BranchId == branch.Id).FirstOrDefault()?.EnumName;

                if (branch.BranchType == "PharmacyItem")
                {
                    var farmacyItem = _dataService.GetEntity <PharmacyItemPharmacy>(x => x.PharmacyItemId == branch.Id).ToList();

                    foreach (var item in farmacyItem)
                    {
                        var farmacy = _dataService.GetDto <BranchDetailsDTO>(x => x.Id == item.PharmacyId).ToList();
                        if (farmacy.Any())
                        {
                            mpdFile.Replace("@@MPD@@", branch.Name + ", " + "</br>" +
                                            farmacy.FirstOrDefault()?.Name + "</br>" +
                                            (string.IsNullOrEmpty(branch.Lpz) ? "" : ", " + branch.Lpz));
                        }
                        else
                        {
                            mpdFile.Replace("@@MPD@@", branch.Name + ", " + "</br>" +
                                            (string.IsNullOrEmpty(branch.Lpz) ? "" : ", " + branch.Lpz));
                        }
                    }
                    mpdFile.Replace("@@ActivityType@@", activityType ?? "");
                    mpdFile.Replace("@@MpdAddress@@", branch.PostIndex + ", " + branch.Address);
                }
                else
                {
                    mpdFile.Replace("@@MPD@@", branch.Name);
                    mpdFile.Replace("@@MpdAddress@@", branch.PostIndex + ", " + branch.Address);
                    mpdFile.Replace("@@ActivityType@@", activityType ?? "");
                }

                mpdList += mpdFile.ToString();
            }
            htmlFile.Replace("@@MpdList@@", mpdList);

            htmlFile.Replace("@@Name@@", appObject.OrgName + ", " + appObject.Address);

            if (string.IsNullOrEmpty(appObject.EDRPOU))
            {
                htmlFile.Replace("@@OrgName@@", ".");
                htmlFile.Replace("@@FopName@@", appObject.OrgName);
                htmlFile.Replace("@@PassportData@@",
                                 appObject.PassportSerial + ", " + appObject.PassportNumber + ", "
                                 + (appObject.PassportDate.HasValue ?
                                    appObject.PassportDate.Value.ToString("«dd» MMMM yyyy", CultureInfo.CreateSpecificCulture("uk"))
                                                  : ""));
                htmlFile.Replace("@@PassportIssueUnit@@", string.IsNullOrEmpty(appObject.PassportIssueUnit) ? "." : appObject.PassportIssueUnit);
                htmlFile.Replace("@@INN@@", appObject.INN);
                htmlFile.Replace("@@EDRPOU@@", ".");
            }
            else
            {
                htmlFile.Replace("@@FopName@@", ".");
                htmlFile.Replace("@@OrgName@@", appObject.OrgDirector);
                htmlFile.Replace("@@PassportData@@", ".");
                htmlFile.Replace("@@PassportIssueUnit@@", ".");
                htmlFile.Replace("@@INN@@", ".");
                htmlFile.Replace("@@EDRPOU@@", appObject.EDRPOU);
            }

            htmlFile.Replace("@@EMail@@", appObject.EMail);
            htmlFile.Replace("@@Phone@@", StandartPhone(appObject.PhoneNumber));

            var retailOfMedicines    = false;
            var wholesaleOfMedicines = false;
            var prlInPharmacies      = false;

            foreach (var activityType in activityTypeList)
            {
                switch (activityType)
                {
                case "RetailOfMedicines":
                    retailOfMedicines = true;
                    break;

                case "WholesaleOfMedicines":
                    wholesaleOfMedicines = true;
                    break;

                case "PrlInPharmacies":
                    prlInPharmacies = true;
                    break;
                }
            }
            htmlFile.Replace("@@RetailOfMedicines@@", !retailOfMedicines ? checkboxEmpty : checkbox);
            htmlFile.Replace("@@WholesaleOfMedicines@@", !wholesaleOfMedicines ? checkboxEmpty : checkbox);
            htmlFile.Replace("@@PrlInPharmacies@@", !prlInPharmacies ? checkboxEmpty : checkbox);

            htmlFile.Replace("@@LegalFormTypeName@@", appObject.LegalFormName);
            htmlFile.Replace("@@UserName@@", _userInfoService.GetCurrentUserInfo().FullName());
            htmlFile.Replace("@@IsCheckMPD@@", appObject.IsCheckMpd ? checkbox : checkboxEmpty);
            htmlFile.Replace("@@IsCourierDelivery@@", appObject.IsCourierDelivery ? checkbox : checkboxEmpty);
            htmlFile.Replace("@@IsPostDelivery@@", appObject.IsPostDelivery ? checkbox : checkboxEmpty);
            htmlFile.Replace("@@IsCourierResults@@", appObject.IsCourierResults ? checkbox : checkboxEmpty);
            htmlFile.Replace("@@IsPostResults@@", appObject.IsPostResults ? checkbox : checkboxEmpty);
            htmlFile.Replace("@@IsElectricFormResults@@", appObject.IsElectricFormResults ? checkbox : checkboxEmpty);
            htmlFile.Replace("@@Date@@",
                             DateTime.Now.ToString("«dd» MMMM yyyy", CultureInfo.CreateSpecificCulture("uk")));
            htmlFile.Replace("@@RegDate@@",
                             (appObject.RegDate != null ?
                              appObject.RegDate.Value.ToString("«dd» MMMM yyyy", CultureInfo.CreateSpecificCulture("uk")) :
                              " \"___\" ___________ 20___"));
            htmlFile.Replace("@@RegNumber@@",
                             (!string.IsNullOrEmpty(appObject.RegNumber) ? appObject.RegNumber : "__________"));

            var infoFile = GetAddon();

            htmlFile.Append(infoFile);

            return(htmlFile.ToString());
        }