public InvoiceDocumentViewModel Create(InvoiceDocumentViewModel documentViewModel)
        {
            InvoiceDocumentMapping invoiceDocument = ViewModelToEntityMapper.Map(documentViewModel);

            if (invoiceDocument != null)
            {
                invoiceDocument = this.InvoiceDocumentRepository.Add(invoiceDocument);
                if (invoiceDocument.DocumentId > 0)
                {
                    documentViewModel.DocumentId = invoiceDocument.DocumentId;
                }
                else
                {
                    documentViewModel.HasError = true;
                }
            }

            return(documentViewModel);
        }
        public InvoiceDocumentViewModel Update(InvoiceDocumentViewModel documentViewModel)
        {
            var invoiceDocument = this.InvoiceDocumentRepository.Find(documentViewModel.DocumentId);

            if (invoiceDocument != null)
            {
                var lastModifiedDate = invoiceDocument.LastModifiedOn;
                invoiceDocument = this.InvoiceDocumentRepository.Update(ViewModelToEntityMapper.Map(documentViewModel, invoiceDocument));

                if (lastModifiedDate < invoiceDocument.LastModifiedOn)
                {
                    return(documentViewModel);
                }
                else
                {
                    documentViewModel.HasError = true;
                }
            }

            return(documentViewModel);
        }
Exemplo n.º 3
0
        public static InvoiceDocumentMapping Map(InvoiceDocumentViewModel viewModel, InvoiceDocumentMapping entity)
        {
            if (viewModel == null || entity == null)
            {
                return(null);
            }

            entity.DocumentId     = viewModel.DocumentId;
            entity.UserId         = viewModel.UserId;
            entity.FileType       = viewModel.FileType;
            entity.FileName       = viewModel.FileName;
            entity.FileLocation   = viewModel.FileLocation;
            entity.CreatedBy      = viewModel.CreatedBy;
            entity.CreatedOn      = Convert.ToDateTime(viewModel.CreatedOn);
            entity.LastModifiedBy = viewModel.LastModifiedBy;
            entity.LastModifiedOn = Convert.ToDateTime(viewModel.LastModifiedOn);
            entity.IsActive       = viewModel.IsActive;
            entity.ClaimId        = viewModel.ClaimId;

            return(entity);
        }
Exemplo n.º 4
0
        public static InvoiceDocumentMapping Map(InvoiceDocumentViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(null);
            }

            return(new InvoiceDocumentMapping
            {
                DocumentId = viewModel.DocumentId,
                UserId = viewModel.UserId,
                FileType = viewModel.FileType,
                FileName = viewModel.FileName,
                FileLocation = viewModel.FileLocation,
                CreatedBy = viewModel.CreatedBy,
                CreatedOn = Convert.ToDateTime(viewModel.CreatedOn),
                LastModifiedBy = viewModel.LastModifiedBy,
                LastModifiedOn = Convert.ToDateTime(viewModel.LastModifiedOn),
                IsActive = viewModel.IsActive,
                ClaimId = viewModel.ClaimId
            });
        }
Exemplo n.º 5
0
        public ActionResult GenerateIncoicePdf(int ClaimId, int InvoiceId, int TimelogId)
        {
            try
            {
                StringBuilder html = new StringBuilder();

                List <InvoiceViewModel>        invoices = this.InvoiceBusinessLayer.GetAllInvoicesforPdf(User.Identity.GetUserId(), ClaimId, InvoiceId).ToList();
                IEnumerable <TimeLogViewModel> timeLogs = this.TimeLogBusinessLayer.GetAllTimeLogsforPdf(User.Identity.GetUserId(), ClaimId, TimelogId).Where(x => x.IsBilled == false);
                var          SeriveBillingItems         = new List <PdfBillingItems>();
                decimal      sTotal        = 0;
                decimal      tax           = 0;
                decimal      fTotal        = 0;
                string       claimNumber   = string.Empty;
                string       invoiceNumber = string.Empty;
                PdfViewModel pdfViewModel  = null;
                if (invoices != null && timeLogs != null)
                {
                    foreach (var invoice in invoices)
                    {
                        foreach (var timeLog in invoice.TimeLogs)
                        {
                            var serviceItem = new PdfBillingItems();
                            serviceItem.Item        = timeLog.ServiceItemName;
                            serviceItem.Description = timeLog.Comment;
                            serviceItem.Quantity    = timeLog.Quantity;
                            //serviceItem.Rate = timeLog.ServiceRate;
                            serviceItem.Price = timeLog.TotalAmount;
                            serviceItem.Rate  = decimal.Round(timeLog.ServiceRate, 2, MidpointRounding.AwayFromZero);
                            sTotal           += timeLog.TotalAmount;
                            SeriveBillingItems.Add(serviceItem);
                        }
                        claimNumber   = invoice.ClaimNumber;
                        invoiceNumber = invoice.InvoiceNumber;
                    }
                    foreach (var timeLog in timeLogs)
                    {
                        var serviceItem = new PdfBillingItems();
                        serviceItem.Item        = timeLog.ServiceItemName;
                        serviceItem.Description = timeLog.Comment;
                        serviceItem.Quantity    = timeLog.Quantity;
                        serviceItem.Rate        = decimal.Round(0, 2, MidpointRounding.AwayFromZero);
                        serviceItem.Price       = decimal.Round(0, 2, MidpointRounding.AwayFromZero);
                        SeriveBillingItems.Add(serviceItem);
                    }
                    fTotal       = tax + sTotal;
                    pdfViewModel = new PdfViewModel
                    {
                        ImagePath      = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + ConfigurationManager.AppSettings.Get("InvoiceImageLocation") + "InvoiceImage.png",
                        BgImagePath    = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + ConfigurationManager.AppSettings.Get("InvoiceImageLocation") + "InvoiceBackground.png",
                        InvoiceNumber  = invoices[0].InvoiceNumber,
                        InvoiceDate    = invoices[0].InvoiceDate,
                        InvoiceDueDate = invoices[0].DueDate,
                        Insured        = invoices[0].ClaimantName,
                        InsuredPolicy  = invoices[0].PolicyNumber,
                        FileNumber     = invoices[0].FileNumber,
                        Adjuster       = invoices[0].AdjusterName,
                        LostUnit       = invoices[0].LossType,
                        LostDate       = invoices[0].LostDate,
                        CompanyName    = invoices[0].CompanyName,
                        Street         = invoices[0].Street,
                        City           = invoices[0].City,
                        ProvinceName   = invoices[0].ProvinceName,
                        CountryName    = invoices[0].CountryName,
                        PostalCode     = invoices[0].PostalCode,
                        ContactName    = invoices[0].ContactName,
                        BillingItems   = SeriveBillingItems,
                        SubTotal       = sTotal,
                        Tax            = tax,
                        Total          = fTotal
                    };
                }
                string invoiceTemlatePath = Server.MapPath("~/Templates/Invoice/InvoicePdf.cshtml");
                //var emailDataModel = new EmailViewModel
                //{
                //    UserName ="******",
                //    CallbackUrl = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath + ConfigurationManager.AppSettings.Get("InvoiceImageLocation")
                //};
                html.Append(RenderEmailTemplateUsingRazor(invoiceTemlatePath, pdfViewModel).ToString());

                string       dirPath    = GetDataDir_Data(User.Identity.GetUserId(), claimNumber, invoiceNumber) + ".pdf";
                FileStream   fs         = new FileStream(dirPath, FileMode.Create, FileAccess.Write, FileShare.None);
                StreamReader sr         = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(html.ToString())));
                Document     doc        = new Document(PageSize.A4, 50f, 50f, 10f, 0f);
                HTMLWorker   htmlParser = new HTMLWorker(doc);
                PdfWriter    writer     = PdfWriter.GetInstance(doc, fs);
                doc.Open();
                htmlParser.Parse(sr);
                //var htmlContext = new HtmlPipelineContext(null);
                //htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
                //ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
                //cssResolver.AddCssFile(HttpContext.Server.MapPath("~/Content/Site/StyleSheets/Bootstrap/bootstrap.css"), true);
                //cssResolver.AddCssFile(HttpContext.Server.MapPath("~/Content/Site/StyleSheets/Site.css"), true);
                //cssResolver.AddCss(".shadow {background-color: #ebdddd; }", true);
                //IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(doc, writer)));

                //var worker = new XMLWorker(pipeline, true);
                //var xmlParse = new XMLParser(true, worker);

                //xmlParse.Parse(sr);
                //xmlParse.Flush();
                doc.Close();
                //Response.ContentType = "application/pdf";
                //Response.AddHeader("content-disposition", "attachment;filename="+dirPath);
                //Response.Cache.SetCacheability(HttpCacheability.NoCache);
                //Response.Write(doc);
                //Response.End();

                InvoiceDocumentViewModel documentViewModel = new InvoiceDocumentViewModel
                {
                    UserId         = User.Identity.GetUserId(),
                    FileType       = "Pdf",
                    FileName       = dirPath,
                    FileLocation   = fileLocation,
                    CreatedBy      = User.Identity.GetUserId(),
                    CreatedOn      = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"),
                    LastModifiedBy = User.Identity.GetUserId(),
                    LastModifiedOn = DateTime.Now.ToString("yyyy/MM/dd hh:mm:ss"),
                    IsActive       = true,
                    ClaimId        = ClaimId
                };
                documentViewModel = InvoiceDocumnetMappingBusinessLayer.Create(documentViewModel);

                if (documentViewModel.DocumentId > 0)
                {
                    return(Content("True"));
                }
            }
            catch (Exception ex)
            {
                this.ExceptionLogger.Log(LogLevel.Error, ex);
                throw ex;
            }
            return(Content("False"));
        }