Beispiel #1
0
        public async Task <(bool IsSuccess, string ErrorMessage)> CreateInvoiceFile(InvoiceFile invoiceFile)
        {
            try
            {
                using (ZubairEntities dbContext = new ZubairEntities())
                {
                    if (invoiceFile != null)
                    {
                        var tempInvoiceFile = new invoicefile();
                        tempInvoiceFile.invoice_item_id = invoiceFile.InvoiceItemId;
                        tempInvoiceFile.name            = invoiceFile.Name;
                        tempInvoiceFile.filelocation    = invoiceFile.FileLocation;
                        dbContext.invoicefiles.Add(tempInvoiceFile);
                        await dbContext.SaveChangesAsync();

                        return(true, null);
                    }
                }
                return(false, "Not Found");
            }
            catch (Exception ex)
            {
                //logger?.LogError(ex.ToString());
                return(false, ex.Message);
            }
        }
        /* new action to be deleted if not working VV */
        protected async Task <InvoiceFile> GetGeneratedPDF(int id)
        {
            try
            {
                var invoiceWithAll = await _repositoryWrapper.Invoice.GetInvoiceWihtAllDetailsForInvoiceGeneration(id);

                // Add Application user to get access for email data
                ApplicationUser landlordAspUser = invoiceWithAll.Rent.Landlord.ApplicationUser;
                ApplicationUser tenantAspUser   = invoiceWithAll.Rent.Tenant.ApplicationUser;
                Invoice         invoice         = _mapper.Map <Invoice>(invoiceWithAll);
                Rent            rent            = _mapper.Map <Rent>(invoiceWithAll.Rent);
                Tenant          tenant          = _mapper.Map <Tenant>(invoiceWithAll.Rent.Tenant);
                Property        property        = _mapper.Map <Property>(invoiceWithAll.Rent.Property);
                Landlord        landlord        = _mapper.Map <Landlord>(invoiceWithAll.Rent.Landlord);
                Photo           photo           = _mapper.Map <Photo>(invoiceWithAll.State.Photo);
                Rate            rate            = _mapper.Map <Rate>(invoiceWithAll.Rent.Property.Rate);

                var globalSettings = new GlobalSettings
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize   = PaperKind.A4,
                    Margins     = new MarginSettings {
                        Top = 10
                    },
                    DocumentTitle = "Invoice title",
                };

                InvoiceFile invoiceGenerated = TemplateGenerator.GetInvoiceHTMLString(landlordAspUser, tenantAspUser, invoice, tenant, property, landlord, rent);

                var objectSettings = new ObjectSettings
                {
                    PagesCount     = true,
                    HtmlContent    = invoiceGenerated.getInvoiceString(),
                    WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = SystemRecognizer.GetCssFileLocation() },
                    HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                    FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
                };

                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };

                byte[] file = _converter.Convert(pdf);

                invoiceGenerated.setInvoiceBytes(file);

                return(invoiceGenerated);
            }
            catch (Exception e)
            {
                _logger.LogError($"Something went wrong inside ViewOnWebPDF(id) action: {e.ToString()}");
                return(null);
            }
        }
Beispiel #3
0
 public IActionResult ProcesInvoice([FromBody]  InvoiceFile input)
 {
     try {
         _invoiceService.ProcessInvoice(input.InvoiceFiles);
         return(Ok("Successfully Processed the Invoice"));
     }
     catch (Exception e) {
         return(BadRequest(e.Message));
     }
 }
Beispiel #4
0
        public async Task <ActionResult> Files()
        {
            string folderPath            = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "UploadedInvoices");
            UploadedFilesViewModel model = new UploadedFilesViewModel();

            model.InvoiceFiles = new List <InvoiceFile>();
            var invoicesInSystem = Directory.GetFiles(folderPath);

            foreach (string invoiceFile in invoicesInSystem)
            {
                InvoiceFile newInvoiceFile = new InvoiceFile();
                string      textInvoice    = ReadOrderPDFInvoice(invoiceFile);
                var         invoiceLines   = textInvoice.Split("\n");
                newInvoiceFile.FileName      = invoiceFile;
                newInvoiceFile.InvoiceNumber = invoiceLines.Where(l => l.Contains("Invoice Numbers")).FirstOrDefault();
                newInvoiceFile.OrderIds      = invoiceLines.Where(l => l.Contains("Order:")).FirstOrDefault();
                model.InvoiceFiles.Add(newInvoiceFile);
            }

            return(View(model));
        }
Beispiel #5
0
        public async Task <List <InvoiceFile> > GetInvoicesFromAzureStorageByCustomerId(int customerId, int jobId)
        {
            List <InvoiceFile> InvoiceFiles     = new List <InvoiceFile>();
            var               containerName     = $"invoices";
            string            connectionString  = Configuration["AzureStorage:FifeShutters:ConnectionString"];
            BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);

            try
            {
                await blobServiceClient.GetBlobContainerClient(containerName).ExistsAsync();

                BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
                var blobPages = blobContainerClient.GetBlobsByHierarchy(prefix: $"{customerId}/{jobId}/", delimiter: "/").AsPages();

                foreach (Page <BlobHierarchyItem> blobPage in blobPages)
                {
                    foreach (BlobHierarchyItem blobItem in blobPage.Values)
                    {
                        var         uri         = $"{blobContainerClient.Uri.AbsoluteUri}/{blobItem.Blob.Name}";
                        var         createdOn   = blobItem.Blob.Properties.CreatedOn.Value;
                        var         filename    = blobItem.Blob.Name;
                        InvoiceFile invoiceFile = new InvoiceFile()
                        {
                            CreatedOn = createdOn, Filename = filename, Url = uri
                        };
                        InvoiceFiles.Add(invoiceFile);
                    }
                }

                return(InvoiceFiles);
            }
            catch (RequestFailedException ex)
            {
                throw;
            }
        }
        public async Task <ActionResult> Invoice(string name, string last_name, string country, string address, string zipcode, string city, string province, string phone, string email, string invoice)
        {
            string url = HttpContext.Request.Url.AbsoluteUri;
            string respond;
            string path = ControllerContext.HttpContext.Server.MapPath("");

            if (!url.Contains("?"))
            {
                return(View("Error"));
            }

            if (invoice == "true")
            {
                respond = await InvoiceFile.MakeInvoice(name, last_name, country, address, zipcode, city, province, phone, email, path);
            }
            else
            {
                respond = "Thank you for your purchase!";
            }

            ViewBag.respond = respond;

            return(View());
        }
        /// <summary>
        /// Carga de una factura recibida.
        /// Se coloca en la entidad fiscal  que realiza la llamada
        /// </summary>
        /// <param name="cfdiXMLBase64">Archivo XML en string de base64</param>
        public bool Upload(string cfdiXMLBase64)
        {
            var invFile = new InvoiceFile()
            {
                Content         = cfdiXMLBase64,
                ContentEncoding = "base64",
                ContentType     = "xml",
                ContentLength   = cfdiXMLBase64.Length
            };


            var request = new RestRequest(Method.POST)
            {
                Resource = $"{UriResource}/upload/cfdi"
            };

            request.AddHeader("Content-Type", "application/json");
            var json = JsonConvert.SerializeObject(invFile, Formatting.None, new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Converters        = new List <JsonConverter> {
                    new Newtonsoft.Json.Converters.StringEnumConverter()
                }
            });

            request.AddParameter("application/json", json, ParameterType.RequestBody);
            var response = Execute(request);

            var result = JsonConvert.DeserializeObject <IDictionary <string, object> >(response.Content);

            if (result != null && result.ContainsKey("success"))
            {
                return((bool)result["success"]);
            }
            return(false);
        }
        public async Task <IActionResult> SendMailToTenantWithPDF(int id)
        {
            try
            {
                var invoiceWithAll = await _repositoryWrapper.Invoice.GetInvoiceWihtAllDetailsForInvoiceGeneration(id);

                // Add Application user to get access for email data
                ApplicationUser landlordAspUser = invoiceWithAll.Rent.Landlord.ApplicationUser;
                ApplicationUser tenantAspUser   = invoiceWithAll.Rent.Tenant.ApplicationUser;
                Invoice         invoice         = _mapper.Map <Invoice>(invoiceWithAll);
                Rent            rent            = _mapper.Map <Rent>(invoiceWithAll.Rent);
                Tenant          tenant          = _mapper.Map <Tenant>(invoiceWithAll.Rent.Tenant);
                Property        property        = _mapper.Map <Property>(invoiceWithAll.Rent.Property);
                Landlord        landlord        = _mapper.Map <Landlord>(invoiceWithAll.Rent.Landlord);
                Photo           photo           = _mapper.Map <Photo>(invoiceWithAll.State.Photo);
                Rate            rate            = _mapper.Map <Rate>(invoiceWithAll.Rent.Property.Rate);

                var globalSettings = new GlobalSettings
                {
                    ColorMode   = ColorMode.Color,
                    Orientation = Orientation.Portrait,
                    PaperSize   = PaperKind.A4,
                    Margins     = new MarginSettings {
                        Top = 10
                    },
                    DocumentTitle = "Invoice title",
                    //Out = SystemRecognizer.GetGeneratedInvoiceFileLocation() // this line will generate an invoice file on in InvoiceGeneratior/invoices folder but wont let generate proper attachment!!
                };

                InvoiceFile invoiceGenerated = TemplateGenerator.GetInvoiceHTMLString(landlordAspUser, tenantAspUser, invoice, tenant, property, landlord, rent);

                var objectSettings = new ObjectSettings
                {
                    PagesCount     = true,
                    HtmlContent    = invoiceGenerated.getInvoiceString(),
                    WebSettings    = { DefaultEncoding = "utf-8", UserStyleSheet = SystemRecognizer.GetCssFileLocation() },
                    HeaderSettings = { FontName = "Arial", FontSize = 9, Right = "Page [page] of [toPage]", Line = true },
                    FooterSettings = { FontName = "Arial", FontSize = 9, Line = true, Center = "Report Footer" }
                };

                var pdf = new HtmlToPdfDocument()
                {
                    GlobalSettings = globalSettings,
                    Objects        = { objectSettings }
                };

                var invoiceFile = _converter.Convert(pdf);

                var message = new Email(
                    new string[] { /*tenant.Email,*/ "*****@*****.**" /*, "*****@*****.**",*/ },
                    $"Nowa Faktura od: {landlord.CompanyName}",
                    $"Nowa faktura do zaplaty za mieszkanie {property.FlatLabel} " +
                    $"{property.Address.City} " +
                    $"{property.Address.Street} " +
                    $"{property.Address.BuildingNumber}/{property.Address.FlatNumber}. Prosimy o terminową wpłatę na konto: {landlord.BankAccount}. ",
                    new List <byte[]> {
                    invoiceFile
                },
                    new List <string> {
                    invoiceGenerated.getInvoiceFileName().Replace('/', '-')
                }
                    );
                await _emailEmmiter.SendMailAsync(message);

                return(Ok());
            }
            catch (Exception e)
            {
                _logger.LogError($"Something went wrong inside SendMailToTenantWithPDF(id) action: {e.ToString()}");
                return(StatusCode(500, e.Message));
            }
        }