Ejemplo n.º 1
0
        public ReturnValue PrintInvoice(int invoiceId)
        {
            #region Get Order and Customer Info

            ReturnValue _result = new ReturnValue();

            TOrderTF      _TOrder        = new TOrderTF();
            TCustomer     _TCustomer     = new TCustomer();
            TUser         _TUser         = new TUser();
            TInvoice      _TInvoice      = new TInvoice();
            TPaymentTerms _TPaymentTerms = new TPaymentTerms();

            _result = _TInvoice.getInvoiceById(invoiceId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TInvoice = _result.Object as TInvoice;

            if (string.IsNullOrEmpty(_TPaymentTerms.Description) == true)
            {
                _TPaymentTerms.Description = "Credit Card";
            }

            _result = _TOrder.getOrderById(_TInvoice.OrderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TOrder = _result.Object as TOrderTF;

            _result = _TCustomer.getCustomerById(_TOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TCustomer = _result.Object as TCustomer;

            _result = _TUser.getUserById(_TCustomer.SalesRepId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TUser = _result.Object as TUser;

            _result = _TPaymentTerms.getPaymentTermsById(_TCustomer.PaymentTermsId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TPaymentTerms = _result.Object as TPaymentTerms;
            #endregion

            #region Get Address Info

            TAddress _TAddressBillTo = new TAddress();
            _result = _TAddressBillTo.getAddressById(_TCustomer.BillToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TAddressBillTo = _result.Object as TAddress;



            TAddress _TAddressShipTo = new TAddress();
            _result = _TAddressShipTo.getAddressById(_TOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _TAddressShipTo = _result.Object as TAddress;

            #endregion

            #region Get OrderLineItem, Invoice

            _result = _result = new TInvoice_Line_Item().getInvoice_Line_ItemListByInvoiceId(_TInvoice.InvoiceId);
            if (!_result.Success)
            {
                return(_result);
            }

            EntityList oliList = _result.ObjectList;
            oliList.Sort("OrderLineItemId", true);



            #endregion

            MemoryStream m = new MemoryStream();

            string _path = System.Configuration.ConfigurationSettings.AppSettings["InvoiceImagePath"].ToString();

            try
            {
                #region Print Order and Customer Info

                Document  document = new Document(PageSize.A4, -10, 10, 50, 60);
                PdfWriter writer   = PdfWriter.GetInstance(document, m);

                document.Open();
                Font font       = new Font(Font.FontFamily.UNDEFINED, this.PrintInvoiceSize);
                Font font7      = new Font(Font.FontFamily.UNDEFINED, 6);
                Font fontBold   = new Font(Font.FontFamily.UNDEFINED, this.PrintInvoiceSize, Font.BOLD);
                Font fontBold14 = new Font(Font.FontFamily.UNDEFINED, 12, Font.BOLD);



                PdfPTable             _PdfPTable = new PdfPTable(2);
                iTextSharp.text.Image _Image     = iTextSharp.text.Image.GetInstance(new Uri(_path + "\\Images\\tflogo.JPG"));
                _Image.ScalePercent(11.0f);
                PdfPCell _PdfPCell = new PdfPCell(_Image);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell                     = new PdfPCell(new Paragraph("Customer Invoice", fontBold14));
                _PdfPCell.BorderWidth         = 0.0f;
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPTable.AddCell(_PdfPCell);


                Phrase _Phrase = new Phrase();
                _Phrase.Add(new Phrase("                 Waterford at Blue Lagoon\r\n\r\n", font));
                _Phrase.Add(new Phrase("                 5775 Blue Lagoon Drive, Suite 110 \r\n\r\n", font));
                _Phrase.Add(new Phrase("                 Miami, Florida 33126  \r\n\r\n", font));
                _Phrase.Add(new Phrase("                 Please make Checks/Money orders payable to:\r\n\r\n", fontBold));
                _Phrase.Add(new Phrase("                 Tecnifibre USA, INC\r\n", font));
                _PdfPCell             = new PdfPCell(_Phrase);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell             = new PdfPCell(new Paragraph("   ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);



                _PdfPTable = new PdfPTable(new float[] { 47f, 12, 12f, 9f, 11f, 11f });
                _Phrase    = new Phrase();
                _Phrase.Add(new Paragraph("\r\n\r\nBill to Address:\r\n\r\n", fontBold14));
                _Phrase.Add(new Paragraph(
                                _TAddressBillTo.FirstName + " " + _TAddressBillTo.LastName + "\r\n\r\n" +
                                _TAddressBillTo.Address1 + "\r\n\r\n" +
                                _TAddressBillTo.City + ", " + _TAddressBillTo.StateCode + ", " + _TAddressBillTo.PostalCode
                                , font));

                _PdfPCell                   = new PdfPCell(_Phrase);
                _PdfPCell.BorderWidth       = 0.0f;
                _PdfPCell.Rowspan           = 8;
                _PdfPCell.VerticalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_MIDDLE;
                _PdfPTable.AddCell(_PdfPCell);


                fontBold.Size                 = this.PrintInvoiceSize;
                _PdfPCell                     = new PdfPCell(new Paragraph("Customer Acct", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Sales Rep", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Order #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Order Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("PO #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                font.Size = this.PrintInvoiceSize;
                _PdfPCell = new PdfPCell(new Paragraph(_TCustomer.AltCustNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TUser.FirstName + " " + _TUser.LastName, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.AltOrderNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.OrderDate.Year == 1 ? "" : _TOrder.OrderDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.PONumber, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Invoice Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Due Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Terms", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Ship Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceId.ToString(), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceDate.Year == 1 ? "" : _TInvoice.InvoiceDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.DueDate.Year == 1 ? "" : _TInvoice.DueDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TPaymentTerms.Description, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.ShippedDate.Year == 1 ? "" : _TInvoice.ShippedDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidthTop    = 0.5f;
                _PdfPCell.BorderWidthBottom = 0f;
                _PdfPCell.BorderWidthLeft   = 0.5f;
                _PdfPCell.BorderWidthRight  = 0.5f;
                _PdfPCell.Colspan           = 5;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (If Paid within " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                decimal balanceInDays = Convert.ToDecimal(_TInvoice.InvoiceAmount - _TInvoice.PaiedAmount);
                if (_TInvoice.DueDate > DateTime.Now)
                {
                    balanceInDays = balanceInDays - Convert.ToDecimal(_TInvoice.InvoiceAmount * _TPaymentTerms.Discount / 100);
                }

                if (balanceInDays < 0)
                {
                    balanceInDays = 0;
                }
                _PdfPCell = new PdfPCell(new Paragraph(balanceInDays.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 2;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidthTop    = 0.5f;
                _PdfPCell.BorderWidthBottom = 0f;
                _PdfPCell.BorderWidthLeft   = 0.5f;
                _PdfPCell.BorderWidthRight  = 0.5f;
                _PdfPCell.Colspan           = 5;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (IF Paid after " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph((_TInvoice.InvoiceAmount - _TInvoice.PaiedAmount).ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 2;
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);


                _PdfPTable            = new PdfPTable(1);
                _PdfPCell             = new PdfPCell(new Paragraph("    ", new Font(Font.FontFamily.UNDEFINED, 1)));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                fontBold.Size               = 7;
                _PdfPCell                   = new PdfPCell(new Paragraph("                                                                                                                  PLEASE DETACH AND RETURN TOP PORTION WITH YOUR PAYMENT", fontBold));
                _PdfPCell.BorderWidthTop    = 0.5f;
                _PdfPCell.BorderWidthLeft   = 0.0f;
                _PdfPCell.BorderWidthRight  = 0.0f;
                _PdfPCell.BorderWidthBottom = 0.0f;
                _PdfPCell.BorderColorTop    = new BaseColor(System.Drawing.Color.SteelBlue);
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);



                fontBold.Size         = this.PrintInvoiceSize;
                _PdfPTable            = new PdfPTable(1);
                _PdfPCell             = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _Phrase = new Phrase();
                _Phrase.Add(new Paragraph("Ship to Address:\r\n", fontBold));
                _Phrase.Add(new Paragraph(
                                _TAddressShipTo.FirstName + " " + _TAddressShipTo.LastName + "\r\n" +
                                _TAddressShipTo.Address1 + "\r\n" +
                                _TAddressShipTo.City + ", " + _TAddressShipTo.StateCode + ", " + _TAddressShipTo.PostalCode
                                , font));
                _PdfPCell             = new PdfPCell(_Phrase);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell             = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                document.Add(_PdfPTable);


                #endregion

                #region Print Order Line Item and Order Total

                _PdfPTable = new PdfPTable(new float[] { 10f, 25f, 9f, 28f, 20f, 15f, 21f, 18f, 17f, 20f });

                _PdfPCell             = new PdfPCell(new Paragraph("", fontBold));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPCell.Colspan     = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Customer Account", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Sales Rep", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Order #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Invoice #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Invoice Date", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("PO #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Terms", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell             = new PdfPCell(new Paragraph("", fontBold));
                _PdfPCell.Colspan     = 3;
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TCustomer.AltCustNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TUser.FirstName + " " + _TUser.LastName, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.AltOrderNum, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceId.ToString(), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceDate.Year == 1 ? "" : _TInvoice.InvoiceDate.ToString("MM/dd/yy"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TOrder.PONumber, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TPaymentTerms.Description, font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Line #", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Stock Number", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Description", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Qty", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Standard Price", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Discount", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Sale Price", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph("Total Cost", fontBold));
                _PdfPCell.BackgroundColor     = new BaseColor(System.Drawing.Color.LightBlue);
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthTop      = 0.5f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                StringBuilder sb = new StringBuilder();

                int index = 0;
                int count = oliList.Count;

                font.Size = this.PrintInvoiceSize;

                foreach (TInvoice_Line_Item oliItem in oliList)
                {
                    _PdfPCell = new PdfPCell(new Paragraph((++index).ToString(), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                    _PdfPCell.BorderWidthLeft     = 0.5f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.PartNumber, font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.ProductName, font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPCell.Colspan             = 3;
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.Quantity.ToString(), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_CENTER;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.StandardPrice.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.DiscountAmount.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.WholeSalePrice.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);

                    _PdfPCell = new PdfPCell(new Paragraph(oliItem.TotalCost.ToString("c"), font));
                    _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                    _PdfPCell.BorderWidthLeft     = 0f;
                    _PdfPCell.BorderWidthRight    = 0.5f;
                    _PdfPCell.BorderWidthTop      = 0f;
                    _PdfPCell.BorderWidthBottom   = (index == count ? 0.5f : 0.5f);
                    _PdfPTable.AddCell(_PdfPCell);
                }


                //font.Size = 7;
                _Phrase = new Phrase();
                _Phrase.Add(new Phrase("\r\n\r\nA 1.5% interest will be assessed on all unpaid balances 60 days past due.", font7));
                _Phrase.Add(new Phrase("\r\n\r\nFor billing or order inquiries, please call : 888-301-7878", font7));
                _Phrase.Add(new Phrase("\r\n\r\nThank you for your business!\r\n", font7));

                _PdfPCell             = new PdfPCell(_Phrase);
                _PdfPCell.Colspan     = 6;
                _PdfPCell.Rowspan     = 5;
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPTable.AddCell(_PdfPCell);


                font.Size = this.PrintInvoiceSize;
                _PdfPCell = new PdfPCell(new Paragraph("Sub Total", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.Subtotal.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Tax", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPCell.Colspan             = 3;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.Tax.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Shipping", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.Shipping.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);



                //font = new Font(Font.FontFamily.UNDEFINED, 9, Font.BOLD);
                _PdfPCell = new PdfPCell(new Paragraph("Invoice Total", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.InvoiceAmount.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                //font = new Font(Font.FontFamily.UNDEFINED, 9);
                _PdfPCell = new PdfPCell(new Paragraph("Payment Applies/Credit memo", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(_TInvoice.PaiedAmount.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell             = new PdfPCell(_Image);
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPCell.Colspan     = 6;
                _PdfPCell.Rowspan     = 3;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (If Paid within " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph(balanceInDays.ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);


                _PdfPCell = new PdfPCell(new Paragraph("Invoice Balance (IF Paid after " + _TPaymentTerms.DiscountIfPaidInDays.ToString() + " Days)", font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_LEFT;
                _PdfPCell.Colspan             = 3;
                _PdfPCell.BorderWidthLeft     = 0.5f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell = new PdfPCell(new Paragraph((_TInvoice.InvoiceAmount - _TInvoice.PaiedAmount).ToString("C"), font));
                _PdfPCell.HorizontalAlignment = iTextSharp.text.pdf.PdfPCell.ALIGN_RIGHT;
                _PdfPCell.BorderWidthLeft     = 0f;
                _PdfPCell.BorderWidthRight    = 0.5f;
                _PdfPCell.BorderWidthTop      = 0f;
                _PdfPCell.BorderWidthBottom   = 0.5f;
                _PdfPTable.AddCell(_PdfPCell);

                _PdfPCell             = new PdfPCell(new Paragraph("    ", font));
                _PdfPCell.BorderWidth = 0.0f;
                _PdfPCell.Colspan     = 4;
                _PdfPTable.AddCell(_PdfPCell);


                document.Add(_PdfPTable);

                #endregion
                document.Close();
            }
            catch (DocumentException ex)
            {
                _result            = new ReturnValue();
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();


                return(_result);
            }



            try
            {
                byte[] bytes    = m.GetBuffer();
                string filename = "Invoice/TFInvoice_" + invoiceId.ToString() + ".pdf";
                using (FileStream fs = new FileStream(filename, FileMode.Create))
                {
                    fs.Write(bytes, 0, bytes.Length);
                }
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }



            return(_result);
        }
Ejemplo n.º 2
0
        protected override ReturnValue customerEventPostShipmentUpdate(TOrder order, EntityList orderline, Transaction tran)
        {
            ReturnValue _result = new ReturnValue();

            #region Invoice

            #region get order

            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(order.OrderId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            #endregion

            #region search invoice

            TInvoice _tInvoice = new TInvoice();
            _result = _tInvoice.getInvoice(order.OrderId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _tInvoice = _result.Object as TInvoice;

            #endregion

            if (_tInvoice.InvoiceId == 0)
            {
                #region Create new invoice

                TCustomer _tCustomer = new TCustomer();
                _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tCustomer = _result.Object as TCustomer;

                TPaymentTerms _tPaymentTerms = new TPaymentTerms();
                _result = _tPaymentTerms.getPaymentTermsById(_tCustomer.PaymentTermsId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tPaymentTerms = _result.Object as TPaymentTerms;

                TUser _tUser = new TUser();
                _result = _tUser.getUserById(_tCustomer.SalesRepId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tUser = _result.Object as TUser;

                _tInvoice.InvoiceDate = System.DateTime.Now;
                _tInvoice.ShippedDate = order.ShippedDate.Value;
                _tInvoice.CreatedOn   = System.DateTime.Now;
                _tInvoice.OrderId     = order.OrderId;
                //_tInvoice.SessionId = _sessionId;
                _tInvoice.PONum         = _tOrder.PONumber;
                _tInvoice.CustomerId    = _tOrder.PWPCustomerId;
                _tInvoice.AltInvoiceNum = order.OrderId.ToString();

                _tInvoice.SalesRep = _tCustomer.SalesRepId;
                _tInvoice.Terms    = _tCustomer.PaymentTermsId;

                _tInvoice.TermsName    = _tPaymentTerms.Description;
                _tInvoice.SalesRepName = _tUser.SaleRepInitials;

                _tInvoice.DueDate       = System.DateTime.Now.AddDays(_tPaymentTerms.NetDueInDays);
                _tInvoice.PaymentStatus = "PEND";

                _result = _tInvoice.Save(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
                //_tInvoice.AltInvoiceNum = _orderId.ToString();
                _tInvoice.InvoiceId = _result.IdentityId;
                _tInvoice.QBRef     = _tInvoice.InvoiceId.ToString();
                _result             = _tInvoice.Update(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }


                //_invoiceList.Add(_tInvoice);

                #endregion
            }

            #region invoice line

            foreach (TOrder_Line_Item item in orderline)
            {
                _result = item.getOrderLineByOrderPartNumber(order.OrderId, item.PartNumber, item.Quantity, tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
                TOrder_Line_Item _tOrder_Line_Item = _result.Object as TOrder_Line_Item;

                if (_tOrder_Line_Item.ShippedDate == null || _tOrder_Line_Item.Quantity == 0 || item.Quantity == 0)
                {
                    continue;
                }

                TInvoice_Line_Item _tInvoice_Line_Item = new TInvoice_Line_Item();
                _tInvoice_Line_Item.InvoiceId        = _tInvoice.InvoiceId;
                _tInvoice_Line_Item.LineNum          = _tOrder_Line_Item.LineNum;
                _tInvoice_Line_Item.ProgramProductId = _tOrder_Line_Item.ProgramProductId;
                _tInvoice_Line_Item.ProductName      = _tOrder_Line_Item.ProductName;
                _tInvoice_Line_Item.PartNumber       = _tOrder_Line_Item.PartNumber;
                _tInvoice_Line_Item.Quantity         = item.Quantity;
                _tInvoice_Line_Item.ShippedDate      = _tOrder_Line_Item.ShippedDate.Value;
                _tInvoice_Line_Item.TrackingNumber   = _tOrder_Line_Item.TrackingNumber;
                _tInvoice_Line_Item.ReleaseNumber    = _tOrder_Line_Item.ReleaseNumber.Value;

                _tInvoice_Line_Item.OrderLineItemId = _tOrder_Line_Item.OrderLineItemId;
                _tInvoice_Line_Item.Amount          = (_tOrder_Line_Item.ActualPrice - _tOrder_Line_Item.ComAmount) * (item.Quantity / _tOrder_Line_Item.Quantity);
                _tInvoice_Line_Item.Price           = _tInvoice_Line_Item.Amount / item.Quantity;
                _result = _tInvoice_Line_Item.Save(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
            }

            #endregion

            #region update paid amount & invocie status

            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getTFOrderPaymentArrangementList(order.OrderId);
            if (_result.Success == false)
            {
                return(_result);
            }
            EntityList _payList = _result.ObjectList;


            double _paiedAmount = 0.00;

            bool _noPT = true;

            foreach (TPaymentArrangement _pItem in _payList)
            {
                if (_pItem.PayMethodId != 4)
                {
                    _paiedAmount += _pItem.Amount;
                }
                else
                {
                    _noPT = false;
                }
            }


            TInvoice_Line_Item _Invoice_Line_Item = new TInvoice_Line_Item();
            _result = _Invoice_Line_Item.getTotalInvoiceLineItemByInvoiceId(_tInvoice.InvoiceId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _Invoice_Line_Item = _result.Object as TInvoice_Line_Item;

            if ((_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount) != 0)
            {
                Double _productAmountRate = _Invoice_Line_Item.Amount / (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount);

                _tInvoice.Subtotal      = WComm.Utilities.Round(_Invoice_Line_Item.Amount, 2);
                _tInvoice.Shipping      = WComm.Utilities.Round(_productAmountRate * (_tOrder.TotalShipping - _tOrder.CompShipingCost), 2);
                _tInvoice.Tax           = WComm.Utilities.Round(_productAmountRate * (_tOrder.TotalTax - _tOrder.CompTax), 2);
                _tInvoice.InvoiceAmount = WComm.Utilities.Round(_tInvoice.Subtotal + _tInvoice.Shipping + _tInvoice.Tax, 2);
                _tInvoice.PaiedAmount   = WComm.Utilities.Round(_paiedAmount * _productAmountRate, 2);
                _tInvoice.BalanceDue    = WComm.Utilities.Round(_tInvoice.InvoiceAmount - _tInvoice.PaiedAmount, 2);
                if (_noPT == true)
                {
                    _tInvoice.PaymentStatus = "PAID";
                    _tInvoice.BalanceDue    = 0;
                    _tInvoice.PaiedAmount   = _tInvoice.InvoiceAmount;
                }
                _result = _tInvoice.Update(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
            }

            #endregion

            #region sent invoice email

            VCBusiness.TecnifibreEmailFactory EmailFactory = new TecnifibreEmailFactory();

            _result = EmailFactory.SentInvoiceEmail(_tInvoice.InvoiceId);
            if (_result.Success == false)
            {
                return(_result);
            }


            _tInvoice.EmailSentOn = System.DateTime.Now;
            _result = _tInvoice.Update(tran);
            if (_result.Success == false)
            {
                return(_result);
            }

            #endregion


            #endregion

            return(_result);
        }