Ejemplo n.º 1
0
        /// <summary>
        /// Returns the file name of the newly creasted invoice
        /// </summary>
        /// <param name="invoiceEntity"></param>
        /// <param name="wid"></param>
        /// <param name="client"></param>
        /// <param name="companyInformationEntity"></param>
        /// <param name="now"></param>
        /// <returns></returns>
        public string CreateWeeklyInvoice(InvoiceEntity invoiceEntity, WeeklyInvoiceDetails wid, ClientEntity client, CompanyInformationEntity companyInformationEntity, DateTime now,string invoiceFolder)
        {
            DirectoryCreator.EnsureExistance(invoiceFolder);

            var pdfDoc = new Document(PageSize.A4, 50, 50, 25, 25);

            var pdfFileName = FileNameProvider.GetAvailableFileName(invoiceFolder + "\\Invoice-", InvoiceNameGenerator.GetName(wid.Number, now), ".pdf");

            var output = new FileStream(pdfFileName, FileMode.OpenOrCreate);

            PdfWriter.GetInstance(pdfDoc, output);

            pdfDoc.Open();

            HeaderFactory.Create(pdfDoc, wid.Number, invoiceEntity, companyInformationEntity, now);

            ClientInfoFactory.Create(pdfDoc, CompositeAddressCreator.CreateAddress(client.CompanyInformationEntity), wid.CommentsOrSpecialInstructions);

            CostSummaryFactory.CreateWeekly(pdfDoc, wid, invoiceEntity,now);

            FooterFactory.Create(pdfDoc, invoiceEntity);

            pdfDoc.Close();

            return pdfFileName;
        }
        public static string Create(InvoiceEntity invoiceEntity, WeeklyInvoiceDetails weeklyInvoiceDetails, CompanyInformationEntity companyInformationEntity, DateTime now, string invoiceFolder)
        {
            var generator = new Generator();
            var filename = generator.CreateWeeklyInvoice(invoiceEntity, weeklyInvoiceDetails, weeklyInvoiceDetails.Client, companyInformationEntity, now,invoiceFolder);

            return filename;
        }
        public static void CreateWeekly(Document document, WeeklyInvoiceDetails wid, InvoiceEntity invoiceEntity, DateTime now)
        {
            var table = new PdfPTable(4) { WidthPercentage = 100 };
            var colWidthPercentages = new[] { 1f, 3f, 1f, 1f };
            table.SetWidths(colWidthPercentages);

            var subTotal = wid.ChargeableHours * wid.HourlyRate;

            AddHeader(table);
            AddWeekWorkCost(table, wid, invoiceEntity,now);
            AddSummary(table, subTotal, subTotal * 0.2);

            document.Add(table);
        }
        public void TestInvoiceSender()
        {
            var clientTo = new DefaultClientsWrappers().Data.First();
            var emailConfig = new DefaultEmailWrapper().Data;
            var ic = new DefaultInvoiceWrapper().Data;
            var icd = new WeeklyInvoiceDetails
                {
                    ChargeableHours = 37.5,
                    Number = 21,
                    HourlyRate = 44,
                    CommentsOrSpecialInstructions = "This is a test invoice - there is no need to take action.",
                };

            var client = new TestClientsWrappers();

            var generator = new Generator();
            var filename = generator.CreateWeeklyInvoice(new TestInvoiceWrapper().Data, icd, client.Data.First(), new DefaultCompanyInformationWrapper().Data, DateTime.Now, "C:\\Hardcore Software\\iSec\\Invoices\\");
            Assert.DoesNotThrow(() => InvoiceEmailer.SendEmailWithAttachement(clientTo, emailConfig, icd, filename, DateTime.Now));
        }
        public void CreatePdf()
        {
            var wid = new WeeklyInvoiceDetails
            {
                Number = 1,
                HourlyRate = 8,
                ChargeableHours = 37.5,
                CommentsOrSpecialInstructions = "All good :)"
            };

            var client = new TestClientsWrappers();

            var pdfFielName = new Generator().CreateWeeklyInvoice(new TestInvoiceWrapper().Data, wid, client.Data.First(), new DefaultCompanyInformationWrapper().Data, DateTime.Now, "C:\\Hardcore Software\\ISec\\Invoices\\");

            if (true)
            {
                var startInfo = new ProcessStartInfo(pdfFielName)
                    {
                        WindowStyle = ProcessWindowStyle.Normal
                    };
                Process.Start(startInfo);
            }
        }
        private static void AddWeekWorkCost(PdfPTable table, WeeklyInvoiceDetails wid, InvoiceEntity invoiceEntity, DateTime now)
        {
            table.AddCell(ElementFactory.CreateCell(wid.ChargeableHours.ToString(CultureInfo.InvariantCulture)));

            table.AddCell(ElementFactory.CreateCell(
                string.Format("{0} ({1} - {2})",
                invoiceEntity.ChargeableJob.Description,
                now.ToStartOfBusinessWeek().ToString("dd MMM yyyy"),
                now.ToEndOfBusinessWeek().ToString("dd MMM yyyy")), Element.ALIGN_LEFT, 200));

            table.AddCell(ElementFactory.CreateCell(string.Format("{0}", wid.HourlyRate)));

            table.AddCell(ElementFactory.CreateCell((wid.HourlyRate * wid.ChargeableHours).ToString(CurrencyString), Element.ALIGN_RIGHT));
        }
Ejemplo n.º 7
0
        public static InvoiceEntity LoadInvoiceConfig(string fullFileName)
        {
            var xDoc = XDocument.Load(fullFileName);
            var a1 = xDoc.Root.Elements(typeof(AccountDetails).Name).Elements(Nameof<AccountDetails>.Property(e => e.Name)).First().Value;
            var a2 = xDoc.Root.Elements(typeof(AccountDetails).Name).Elements(Nameof<AccountDetails>.Property(e => e.Number)).First().Value;
            var a3 = xDoc.Root.Elements(typeof(AccountDetails).Name).Elements(Nameof<AccountDetails>.Property(e => e.SortCode)).First().Value;

            var e1 = xDoc.Root.Elements(typeof(ChargeableJob).Name).Elements(Nameof<ChargeableJob>.Property(e => e.Description)).First().Value;
            var e2 = Convert.ToDouble(xDoc.Root.Elements(typeof(ChargeableJob).Name).Elements(Nameof<ChargeableJob>.Property(e => e.Quantity)).First().Value);
            var e3 = Convert.ToDouble(xDoc.Root.Elements(typeof(ChargeableJob).Name).Elements(Nameof<ChargeableJob>.Property(e => e.UnitPrice)).First().Value);

            var f = xDoc.Root.Elements(Nameof<InvoiceEntity>.Property(e => e.FooterText)).First().Value;

            var g = xDoc.Root.Elements(Nameof<InvoiceEntity>.Property(e => e.Notes)).First().Value;

            WeeklyInvoiceDetails h = null;
            var wid = xDoc.Root.Elements(Nameof<InvoiceEntity>.Property(e => e.WeeklyInvoiceDetails)).FirstOrDefault();
            if (wid != null)
            {
                h = new WeeklyInvoiceDetails();
                h.HourlyRate = Convert.ToDouble(wid.Elements(Nameof<WeeklyInvoiceDetails>.Property(x => x.HourlyRate)).First().Value);
                h.Number = int.Parse(wid.Elements(Nameof<WeeklyInvoiceDetails>.Property(x => x.Number)).First().Value);
                h.ChargeableHours = Convert.ToDouble(wid.Elements(Nameof<WeeklyInvoiceDetails>.Property(x => x.ChargeableHours)).First().Value);
                h.CommentsOrSpecialInstructions = wid.Elements(Nameof<WeeklyInvoiceDetails>.Property(x => x.CommentsOrSpecialInstructions)).First().Value;
            }

            var i = Convert.ToInt32(xDoc.Root.Elements(Nameof<InvoiceEntity>.Property(e => e.ClientId)).First().Value);

            return new InvoiceEntity
            {
                AccountDetails = new AccountDetails
                {
                    Name = a1,
                    Number = a2,
                    SortCode = a3
                },
                ChargeableJob = new ChargeableJob
                {
                    Description = e1,
                    Quantity = e2,
                    UnitPrice = e3
                },
                FooterText = f,
                Notes = g,
                WeeklyInvoiceDetails = h,
                ClientId = i
            };
        }