예제 #1
0
        public string NotPaid(int weeks)
        {
            var document = new Document();
            var pdfPath  = ReportHelper.CreateDoc(ref document);

            document.Open();

            //Define Fonts
            var fontReportHeader = FontFactory.GetFont(FontFactory.HELVETICA, 18, Font.BOLD);
            var fontColumnHeader = FontFactory.GetFont(FontFactory.HELVETICA, 8, Font.BOLD);
            var fontNormal       = FontFactory.GetFont(FontFactory.HELVETICA, 6, Font.NORMAL);

            //Adds content to the document:
            ReportHelper.AddLine(document, fontReportHeader, "Not Paid - " + weeks.ToString(CultureInfo.InvariantCulture) + " Weeks");

            //Define Table
            var tbl = new PdfPTable(6);

            //tbl.BorderWidth = 0;
            //tbl.Cellpadding = 2;
            //tbl.Border = Rectangle.NO_BORDER;
            //tbl.AutoFillEmptyCells = true;

            //Column Widths
            //tbl.Widths = headerwidths;

            //Table Headers
            ReportHelper.AddCell(tbl, "Account Code", 1, Element.ALIGN_CENTER, fontColumnHeader, Rectangle.BOTTOM_BORDER, 10);
            ReportHelper.AddCell(tbl, "Loan Value", 1, Element.ALIGN_CENTER, fontColumnHeader, Rectangle.BOTTOM_BORDER, 10);
            ReportHelper.AddCell(tbl, "Outstanding", 1, Element.ALIGN_CENTER, fontColumnHeader, Rectangle.BOTTOM_BORDER, 10);
            ReportHelper.AddCell(tbl, "Customer", 1, Element.ALIGN_CENTER, fontColumnHeader, Rectangle.BOTTOM_BORDER, 10);
            ReportHelper.AddCell(tbl, "Last Payment Paid", 1, Element.ALIGN_CENTER, fontColumnHeader, Rectangle.BOTTOM_BORDER, 10);
            ReportHelper.AddCell(tbl, "Next Payment Due", 1, Element.ALIGN_CENTER, fontColumnHeader, Rectangle.BOTTOM_BORDER, 10);

            //Data
            var accountIds = Functions.AccountsNotPaidForWeeks(weeks);

            foreach (var accountId in accountIds)
            {
                if (accountId == null)
                {
                    continue;
                }
                //if (notpaid.NextPaymentWasDue == null) continue;

                //var account = (from a in _db.Accounts where a.Id == notpaid.Account_Id select a).FirstOrDefault();
                var account = _db.Accounts.Find(accountId);
                if (account == null)
                {
                    throw new Exception("Can't find Account");
                }
                if (account.CurrentStatus.Status != "Created")
                {
                    continue;
                }

                if (account.Payments?.Count == 0)
                {
                    continue;
                }

                ReportHelper.AddCell(tbl, account.InvoiceCode, 1, Element.ALIGN_LEFT, fontNormal, Rectangle.RIGHT_BORDER, 10);
                ReportHelper.AddCell(tbl, account.NetValue.ToString("£0.00"), 1, Element.ALIGN_RIGHT, fontNormal, Rectangle.RIGHT_BORDER, 10);
                ReportHelper.AddCell(tbl, account.Outstanding.ToString("£0.00"), 1, Element.ALIGN_RIGHT, fontNormal, Rectangle.RIGHT_BORDER, 10);
                ReportHelper.AddCell(tbl, account.Customer.FullName, 1, Element.ALIGN_LEFT, fontNormal, Rectangle.RIGHT_BORDER, 10);
                ReportHelper.AddCell(tbl, account.LastPayment.Timestamp.ToString("dd/MMM/yyyy"), 1, Element.ALIGN_CENTER, fontNormal, Rectangle.NO_BORDER, 10);
                ReportHelper.AddCell(tbl, account.NextPaymentDate.ToString("dd/MMM/yyyy"), 1, Element.ALIGN_CENTER, fontNormal, Rectangle.NO_BORDER, 10);
            }

            document.Add(tbl);
            document.Close();

            return(pdfPath);
        }