private async Task <string> CreateInvoice(Account item, string outputHtmlPath)
        {
            var existedInvoicePath = CheckInvoice(item.CompanyId);

            if (existedInvoicePath != null)
            {
                return(existedInvoicePath);
            }

            var id = Guid.NewGuid();

            var invoice = new Invoice
            {
                CompanyId  = item.CompanyId,
                ExpireDate = item.PayDate,
                Path       = _env.WebRootPath + $"/docs/{id}-invoice.pdf",
            };

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var invoiceRepository = scope.ServiceProvider.GetRequiredService <IInvoiceRepository>();
                invoiceRepository.Add(invoice);
            }


            var invoicePath   = _env.WebRootPath + $"/templates/{item.Company.InvoiceTemplate}.html";
            var outputPdfPath = _env.WebRootPath + $"/docs/{id}-invoice.pdf";

            HtmlStringGenerator invoiceHtml = new HtmlStringGenerator(invoicePath);

            invoiceHtml.AddParameters("{date}", item.PayDate.ToString("dd-MM-yyyy"));
            invoiceHtml.AddParameters("{domain}", item.DomainName);
            invoiceHtml.AddParameters("{price}", GetPrice(item.PackageId, item.TermId).ToString());
            invoiceHtml.AddParameters("{name}", item.Company.Name);
            invoiceHtml.AddParameters("{code}", item.Company.Code);
            invoiceHtml.AddParameters("{address}", item.Company.Address);
            invoiceHtml.AddParameters("{invoiceId}", invoice.Id.ToString());
            invoiceHtml.AddParameters("{expireDate}", invoice.ExpireDate.ToString("dd/MM/yyyy"));
            invoiceHtml.AddParameters("{createDate}", DateTime.Now.ToString("dd/MM/yyyy"));

            var invoiceContent = await invoiceHtml.GenerateBody();

            await invoiceHtml.WriteAsync(outputHtmlPath, invoiceContent);

            return(outputPdfPath);
        }
        public async Task CheckExpiration()
        {
            var isMonday = DateTime.Now.DayOfWeek == DayOfWeek.Monday;

            if (!isMonday)
            {
                return;
            }

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var account  = scope.ServiceProvider.GetRequiredService <IRepository <Account> >();
                var accounts = account.GetAll().ToList();
                accounts = accounts
                           .Where(a => a.PayDate.Subtract(DateTime.Now).TotalDays <= 8)
                           .ToList();

                if (accounts.Count >= 0)
                {
                    var body           = CreateBody(accounts);
                    var mailPath       = _env.WebRootPath + "/templates/mail.html";
                    var outputHtmlPath = _env.WebRootPath + "/output/invoice.html";



                    HtmlStringGenerator mail = new HtmlStringGenerator(mailPath);


                    mail.AddParameters("{body}", body);
                    var mailContent = await mail.GenerateBody();

                    Console.WriteLine("Sending Email...");
                    await _email.SendMailAsync("goga33333.gmail.com", "დომენები", mailContent, null);

                    foreach (var item in accounts)
                    {
                        var outputPdfPath = await CreateInvoice(item, outputHtmlPath);

                        DocumentBuilder.CreatePdf(outputHtmlPath, outputPdfPath);

                        await _email.SendMailAsync("goga33333.gmail.com", "არტმედია", "დომენის საფასურის გადახდის ინვოისი", outputPdfPath);
                    }
                }
            }
        }