Beispiel #1
0
        public ReturnValue ReSentInvoiceEmail()
        {
            ReturnValue _result = new ReturnValue();

            TInvoice _tInvoice = new TInvoice();

            _result = _tInvoice.getReInvoiceEmailList();
            if (_result.Success == false)
            {
                return(_result);
            }

            EntityList list = _result.ObjectList;


            foreach (TInvoice item in list)
            {
                _result = SentInvoiceEmail(item.InvoiceId);

                if (_result.Success == false)
                {
                    Common.Log("Invoice : " + item.InvoiceId + "---ER \r\n" + _result.ErrMessage);
                }
                else
                {
                    Common.Log("Invoice : " + item.InvoiceId + "---OK");
                }
            }

            return(_result);
        }
Beispiel #2
0
        private IEnumerable <TInvoiceViewModel> ConvertToTInvoices(TInvoice invoice)
        {
            TInvoiceViewModel inv = new TInvoiceViewModel
            {
                //ProjectId = entity.ProjectId != null ? entity.ProjectId.Id : string.Empty,
                ProjectName       = invoice.ProjectId != null ? invoice.ProjectId.ProjectName : string.Empty,
                ProjectSpkNo      = invoice.ProjectId != null ? invoice.ProjectId.ProjectSpkNo : string.Empty,
                CustomerName      = invoice.ProjectId != null ? invoice.ProjectId.CustomerId.CustomerName : string.Empty,
                CustomerAddress   = invoice.ProjectId != null ? invoice.ProjectId.CustomerId.CustomerAddress : string.Empty,
                InvoicePeriod     = invoice.InvoicePeriod,
                InvoiceStartDate  = invoice.InvoiceStartDate,
                InvoiceEndDate    = invoice.InvoiceEndDate,
                InvoiceNo         = invoice.InvoiceNo,
                InvoiceDate       = invoice.InvoiceDate,
                InvoiceLastStatus = invoice.InvoiceLastStatus,
                InvoicePaidDate   = invoice.InvoicePaidDate,
                //InvoiceValue = invoice.InvoiceValue,
                //InvoiceRetention = invoice.InvoiceRetention,
                //InvoicePpn = invoice.InvoicePpn,
                //InvoiceTotal = invoice.InvoiceTotal,
                InvoiceId = invoice.Id
            };
            IList <TInvoiceViewModel> list = new List <TInvoiceViewModel>();

            list.Add(inv);
            return(list);
        }
        private void ConvertToTInvoice(TInvoiceViewModel vm, TInvoice entity, string ParentProjectId)
        {
            entity.ProjectId = string.IsNullOrEmpty(ParentProjectId) ? null : _TProjectTasks.One(ParentProjectId);

            entity.InvoicePeriod     = new DateTime(vm.InvoicePeriod.Value.Year, vm.InvoicePeriod.Value.Month, 1);
            entity.InvoiceStartDate  = vm.InvoiceStartDate;
            entity.InvoiceEndDate    = vm.InvoiceEndDate;
            entity.InvoiceNo         = vm.InvoiceNo;
            entity.InvoiceDate       = vm.InvoiceDate;
            entity.InvoiceLastStatus = vm.InvoiceLastStatus;
            entity.InvoicePaidDate   = vm.InvoicePaidDate;
            //entity.InvoiceValue = vm.InvoiceValue;
            //entity.InvoiceRetention = vm.InvoiceRetention;
            //entity.InvoicePpn = vm.InvoicePpn;
            //entity.InvoiceTotal = vm.InvoiceTotal;
        }
        public ActionResult TInvoices_Create([DataSourceRequest] DataSourceRequest request, TInvoiceViewModel vm, string ParentProjectId)
        {
            if (vm != null && ModelState.IsValid)
            {
                TInvoice entity = new TInvoice();
                entity.SetAssignedIdTo(Guid.NewGuid().ToString());

                ConvertToTInvoice(vm, entity, ParentProjectId);

                entity.CreatedDate = DateTime.Now;
                entity.CreatedBy   = User.Identity.Name;
                entity.DataStatus  = EnumDataStatus.New.ToString();

                _tasks.Insert(entity);
            }

            return(Json(new[] { vm }.ToDataSourceResult(request, ModelState)));
        }
Beispiel #5
0
        private ReportDataSource GetInvoice(string ProjectId, DateTime?RptPeriod, ref EnumReports rpt)
        {
            var invoices = this._InvoiceTasks.GetListByProjectAndPeriod(ProjectId, RptPeriod);

            if (invoices.Count() > 0)
            {
                TInvoice         inv              = invoices.ToList()[0];
                var              results          = ConvertToTInvoices(inv);
                ReportDataSource reportDataSource = new ReportDataSource("TInvoiceViewModel", results);

                //set rpt to print
                if (inv.ProjectId.ProjectInvoiceFormat == EnumInvoiceFormat.PPH.ToString())
                {
                    rpt = EnumReports.RptPrintInvoice_Pph;
                }
                else if (inv.ProjectId.ProjectInvoiceFormat == EnumInvoiceFormat.PPH_PPN.ToString())
                {
                    rpt = EnumReports.RptPrintInvoice_Pph_Ppn;
                }
                return(reportDataSource);
            }
            return(null);
        }
Beispiel #6
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);
        }
Beispiel #7
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);
        }
Beispiel #8
0
        public ReturnValue CancelHDOrder()
        {
            ReturnValue _result = new ReturnValue();

            #region get orders

            TInvoice _ttInvoice = new TInvoice();
            _result = _ttInvoice.getHDOrderList();
            if (_result.Success == false)
            {
                Common.Log("getHDOrderList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getHDOrderList---OK");
            }

            EntityList _list = _result.ObjectList;

            int    _successfulRecord = 0;
            int    _failedRecord     = 0;
            string _errorNotes       = "";


            foreach (TOrder _item in _list)
            {
                Transaction _transaction = new Transaction();

                _item.StatusCode = "CN";

                _result = _item.Update(_transaction);
                if (_result.Success == false)
                {
                    _transaction.RollbackTransaction();
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Order : " + _item.OrderId.ToString() + "- Cancel ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Order : " + _item.OrderId.ToString() + "- Cancel ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                _transaction.CommitTransaction();
                _successfulRecord++;

                Common.Log("Order : " + _item.OrderId.ToString() + "- Cancel ---OK");
            }

            #endregion

            if (_failedRecord != 0)
            {
                Common.SentAlterEmail(_failedRecord, _errorNotes);
            }


            return(_result);
        }
Beispiel #9
0
        public ReturnValue PastDue()
        {
            ReturnValue _result = new ReturnValue();

            #region get TProgram_Email

            TProgram_EmailTF _tProgram_Email = new TProgram_EmailTF();
            _result = _tProgram_Email.getEmailTemplate("10DaysPastDue");
            if (_result.Success == false)
            {
                Common.Log("getProgram_InfoList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getProgram_InfoList---OK");
            }


            _tProgram_Email = _result.Object as TProgram_EmailTF;

            #endregion


            #region get Invoices

            TInvoice _ttInvoice = new TInvoice();
            _result = _ttInvoice.getPastDueInvoiceList();
            if (_result.Success == false)
            {
                Common.Log("getPastDueInvoiceList---ER \r\n" + _result.ErrMessage);

                Common.SentAlterEmail(1, _result.ErrMessage);

                return(_result);
            }
            else
            {
                Common.Log("getPastDueInvoiceList---OK");
            }


            #endregion

            EntityList _list = _result.ObjectList;

            int    _successfulRecord = 0;
            int    _failedRecord     = 0;
            string _errorNotes       = "";

            #region sent email

            foreach (TInvoice _item in _list)
            {
                string _content = System.Web.HttpUtility.HtmlDecode(_tProgram_Email.FullHtml);

                TProgram_Email _email = _tProgram_Email.Clone() as TProgram_Email;



                DateTime dt1    = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                DateTime dt3    = new DateTime(_item.DueDate.Year, _item.DueDate.Month, _item.DueDate.Day);
                int      _aging = dt1.Subtract(dt3).Days;

                _content = _content.Replace("[customeraccount]", _item.CustomerAccount)
                           .Replace("[OrderDate]", _item.OrderDate.ToString("MM/dd/yyyy"))
                           .Replace("[aging]", _aging.ToString())
                           .Replace("[invoiceNo]", _item.InvoiceId.ToString())
                           .Replace("[duedate]", _item.DueDate.ToString("MM/dd/yyyy"));

                _email.ToAddress  = _item.Email;
                _email.FullHtml   = _content;
                _email.CCAddress  = _email.CCAddress + ";" + _item.InvoiceEmail;
                _email.BccAddress = _email.BccAddress + ";" + _item.SalesRepEmail;


                #region attached pdf

                TecnifibreInvoicePDF TecnifibreInvoicePDF = new TecnifibreInvoicePDF();
                _result = TecnifibreInvoicePDF.PrintInvoice(_item.InvoiceId);
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- TFInvoicePDFGenerator ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- TFInvoicePDFGenerator ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                string pdffilename = "Invoice/TFInvoice_" + _item.InvoiceId.ToString() + ".pdf";

                FileAttachment fileAttachment = new FileAttachment(new FileInfo(pdffilename));

                fileAttachment.ContentType = "application/pdf";



                #endregion



                _result = SentEmail(_email, EmailFormat.Html, _item.InvoiceId, fileAttachment);

                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- PastDue ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- PastDue ---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                _item.PastDueEmailOn = System.DateTime.Now;
                _result = _item.Update();
                if (_result.Success == false)
                {
                    _failedRecord++;
                    _errorNotes = _errorNotes + "Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---ER \r\n" + _result.ErrMessage + "\r\n";

                    Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---ER \r\n" + _result.ErrMessage);

                    continue;
                }


                _successfulRecord++;
                Common.Log("Invoice : " + _item.InvoiceId.ToString() + "- DueInvoices ---OK");
            }

            #endregion


            if (_failedRecord != 0)
            {
                Common.SentAlterEmail(_failedRecord, _errorNotes);
            }


            return(_result);
        }
        private Boolean ImprimirPE()
        {
            String sDocEntry   = "";
            String sFolio      = "";
            String sFolioPref  = "";
            String Tabla       = "";
            String sTipo       = "";
            String sDocSubType = "";
            String sObjType    = "";
            String GLOB_EncryptSQL;
            String TipoDocElect = "";

            SAPbouiCOM.EditText oEditText;
            SAPbouiCOM.ComboBox oComboBox;
            //String[] FE52 = { "52", "52T", "52D" };
            //String[] FEOt = { "01", "01A", "08", "03" };

            try
            {
                oForm.Freeze(true);
                GLOB_EncryptSQL = GlobalSettings.GLOB_EncryptSQL;
                oEditText       = (EditText)(oForm.Items.Item("Folio").Specific);
                sFolio          = oEditText.Value;
                oEditText       = (EditText)(oForm.Items.Item("FolioPref").Specific);
                sFolioPref      = oEditText.Value;
                oComboBox       = (ComboBox)(oForm.Items.Item("TipDoc").Specific);
                sTipo           = oComboBox.Value;
                sDocSubType     = "";
                if (sTipo == "01") //Factura venta
                {
                    Tabla        = "OINV";
                    sDocSubType  = "'--'";
                    TipoDocElect = "01";
                }
                else if (sTipo == "01A") //Factura anticipo
                {
                    Tabla        = "ODPI";
                    sDocSubType  = "'--'";
                    TipoDocElect = "01";
                }
                else if (sTipo == "01X") //Factura Exportacion
                {
                    Tabla        = "OINV";
                    sDocSubType  = "'IX'";
                    TipoDocElect = "01";
                }
                else if (sTipo == "08") //Nota de Debito
                {
                    Tabla        = "OINV";
                    sDocSubType  = "'DN'";
                    TipoDocElect = "08";
                }
                else if (sTipo == "03") //Boleta
                {
                    Tabla        = "OINV";
                    sDocSubType  = "'IB','--'";
                    TipoDocElect = "03";
                }
                else if (sTipo == "07") //nota de credito
                {
                    Tabla        = "ORIN";
                    sDocSubType  = "'--'";
                    TipoDocElect = "07";
                }
                else if (sTipo == "09") //guia remision Entrega
                {
                    Tabla        = "ODLN";
                    sDocSubType  = "'--'";
                    TipoDocElect = "09";
                    sObjType     = "15";
                }
                else if (sTipo == "09T") //guia remision Transferencia
                {
                    Tabla        = "OWTR";
                    sDocSubType  = "'--'";
                    TipoDocElect = "09";
                    sObjType     = "67";
                }
                else if (sTipo == "09D") //guia remision Devolucion
                {
                    Tabla        = "ORPD";
                    sDocSubType  = "'--'";
                    TipoDocElect = "09";
                    sObjType     = "21";
                }
                else if (sTipo == "20") //Comprobante Retencion
                {
                    Tabla        = "OVPM";
                    sDocSubType  = "'--'";
                    TipoDocElect = "20";
                }


                if (TipoDocElect == "20")
                {
                    if (GlobalSettings.RunningUnderSQLServer)
                    {
                        s = @"SELECT CAST(T0.DocEntry AS VARCHAR(20)) 'DocEntry', '--' 'DocSubType'
                            FROM {0} T0 
                            JOIN NNM1 T2 ON T0.Series = T2.Series 
                           WHERE (T0.U_BPP_PTCC = '{1}')
                             AND T0.U_BPP_PTSC = '{2}'
                             --AND SUBSTRING(UPPER(T2.BeginStr), 1, 1) = 'E'
                           ORDER BY T0.DocEntry DESC";
                    }
                    else
                    {
                        s = @"SELECT CAST(T0.""DocEntry"" AS VARCHAR(20)) ""DocEntry"", '--' ""DocSubType""
                            FROM ""{0}"" T0 
                            JOIN ""NNM1"" T2 ON T0.""Series"" = T2.""Series"" 
                           WHERE (T0.""U_BPP_PTCC"" = '{1}')
                             AND T0.""U_BPP_PTSC"" = '{2}'
                             --AND SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) = 'E'
                           ORDER BY T0.""DocEntry"" DESC";
                    }
                    s = String.Format(s, Tabla, sFolio, sFolioPref);
                }
                else
                {
                    if (GlobalSettings.RunningUnderSQLServer)
                    {
                        s = @"SELECT CAST(T0.DocEntry AS VARCHAR(20)) 'DocEntry', T0.DocSubType
                            FROM {0} T0 
                            JOIN NNM1 T2 ON T0.Series = T2.Series 
                           WHERE (T0.U_BPP_MDCD = '{1}')
                             AND T0.U_BPP_MDSD = '{3}'
                             --AND SUBSTRING(UPPER(T2.BeginStr), 1, 1) = 'E'
                             AND T0.DocSubType IN ({2})
                           ORDER BY T0.DocEntry DESC";
                    }
                    else
                    {
                        s = @"SELECT CAST(T0.""DocEntry"" AS VARCHAR(20)) ""DocEntry"", T0.""DocSubType""
                            FROM ""{0}"" T0 
                            JOIN ""NNM1"" T2 ON T0.""Series"" = T2.""Series"" 
                           WHERE (T0.""U_BPP_MDCD"" = '{1}')
                             AND T0.""U_BPP_MDSD"" = '{3}'
                             --AND SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) = 'E'
                             AND T0.""DocSubType"" IN ({2})
                           ORDER BY T0.""DocEntry"" DESC";
                    }
                    s = String.Format(s, Tabla, sFolio, sDocSubType, sFolioPref);
                }

                oRecordSet.DoQuery(s);

                if (oRecordSet.RecordCount > 0)
                {
                    sDocEntry   = (System.String)(oRecordSet.Fields.Item("DocEntry").Value);
                    sDocSubType = ((System.String)oRecordSet.Fields.Item("DocSubType").Value).Trim();

                    //if (sTipo in ['33','34','39','41','56'])
                    if ((sTipo == "01") || (sTipo == "01X"))
                    {
                        var oInvoice_FM = new TInvoice();
                        oInvoice_FM.SBO_f = FSBOf;
                        oInvoice_FM.EnviarFE_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, "13", sDocSubType, RUC, sTipo);
                    }
                    else if (sTipo == "01A")
                    {
                        var oInvoice_FM = new TInvoice();
                        oInvoice_FM.SBO_f = FSBOf;
                        oInvoice_FM.EnviarFE_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, "203", sDocSubType, RUC, sTipo);
                    }
                    else if (sTipo == "03")
                    {
                        var oInvoice_FM = new TInvoice();
                        oInvoice_FM.SBO_f = FSBOf;
                        oInvoice_FM.EnviarFE_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, "13", sDocSubType, RUC, sTipo);
                    }
                    if (sTipo == "08")
                    {
                        var oInvoice_FM = new TInvoice();
                        oInvoice_FM.SBO_f = FSBOf;
                        oInvoice_FM.EnviarFE_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, "13", sDocSubType, RUC, sTipo);
                    }
                    else if (sTipo == "07")
                    {
                        var oCreditNotes_FM = new TCreditNotes();
                        oCreditNotes_FM.SBO_f = FSBOf;
                        oCreditNotes_FM.EnviarCN_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, "14", sDocSubType, RUC, sTipo);
                    }
                    else if (sTipo == "20")
                    {
                        var oPagoEfectuado = new TPagoEfectuado();
                        oPagoEfectuado.SBO_f = FSBOf;
                        oPagoEfectuado.EnviarFE_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, "46", RUC);
                    }
                    else if ((sTipo == "09") || (sTipo == "09T") || (sTipo == "09D"))
                    {
                        var oDelivery = new TDeliveryNote();
                        oDelivery.SBO_f = FSBOf;
                        oDelivery.EnviarFE_PE_ED(sDocEntry, GlobalSettings.RunningUnderSQLServer, sFolioPref, sFolio, TipoDocElect, sObjType, sDocSubType, RUC, sTipo);
                    }
                }
                else
                {
                    FSBOApp.StatusBar.SetText("No se ha encontrado el documento " + sFolioPref + "-" + sFolio, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                }

                oForm.DataSources.UserDataSources.Item("Folio").Value = "";
                oForm.Freeze(false);
                return(true);
            }
            catch (Exception e)
            {
                FSBOApp.StatusBar.SetText(e.Message + " ** Trace: " + e.StackTrace, BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Error);
                OutLog("ImprimirPE: " + e.Message + " ** Trace: " + e.StackTrace);
                return(false);
            }
            oForm.Freeze(false);
        } //fin ImprimirPE
Beispiel #11
0
        }//fin FormEvent

        public new void FormDataEvent(ref BusinessObjectInfo BusinessObjectInfo, ref Boolean BubbleEvent)
        {
            String  DocEntry;
            Boolean bMultiSoc;
            String  nMultiSoc;
            String  TipoDocElect;

            String[]             FE52 = { "15", "67", "21" };
            SAPbobsCOM.Documents oDocuments;

            base.FormDataEvent(ref BusinessObjectInfo, ref BubbleEvent);
            try
            {
                if ((BusinessObjectInfo.BeforeAction == false) && (BusinessObjectInfo.EventType == BoEventTypes.et_FORM_DATA_UPDATE) && (BusinessObjectInfo.ActionSuccess))
                {
                    if (GlobalSettings.RunningUnderSQLServer)
                    {
                        s = "select ISNULL(U_Distrib,'N') 'Distribuido', ISNULL(U_MultiSoc,'N') MultiSoc from [@VID_FEPARAM]";
                    }
                    else
                    {
                        s = @"select IFNULL(""U_Distrib"",'N') ""Distribuido"", IFNULL(""U_MultiSoc"",'N') ""MultiSoc"" from ""@VID_FEPARAM"" ";
                    }
                    oRecordSet.DoQuery(s);

                    if (oRecordSet.RecordCount > 0)
                    {
                        if ((System.String)(oRecordSet.Fields.Item("Distribuido").Value) == "N")
                        {
                            if ((System.String)(oRecordSet.Fields.Item("MultiSoc").Value) == "Y")
                            {
                                bMultiSoc = true;
                            }
                            else
                            {
                                bMultiSoc = false;
                            }

                            if (oForm.BusinessObject.Type == "13") //And (Flag = true)) then
                            {
                                //Flag := false;
                                DocEntry = FSBOf.GetDocEntryBusinessObjectInfo(BusinessObjectInfo.ObjectKey);
                                if (GlobalSettings.RunningUnderSQLServer)
                                {
                                    s = @"select T0.DocSubType, 
                                                 SUBSTRING(UPPER(T2.BeginStr), 1, 1) 'Tipo', 
                                                 SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) Inst,
                                                 SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) TipoDocElect 
                                            from oinv T0 
                                            JOIN NNM1 T2 ON T0.Series = T2.Series 
                                           where T0.DocEntry = {0}";
                                }
                                else
                                {
                                    s = @"select T0.""DocSubType"", 
                                                 SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) ""Tipo"", 
                                                 SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""Inst"",
                                                 SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""TipoDocElect"" 
                                            from ""OINV"" T0 
                                            JOIN ""NNM1"" T2 ON T0.""Series"" = T2.""Series"" 
                                           where T0.""DocEntry"" = {0}";
                                }
                                s = String.Format(s, DocEntry);
                                oRecordSet.DoQuery(s);

                                if (((System.String)(oRecordSet.Fields.Item("TipoDocElect").Value) == "111") && ((System.String)(oRecordSet.Fields.Item("DocSubType").Value) == "DN"))
                                {
                                    TipoDocElect = "111";
                                }
                                else if (((System.String)(oRecordSet.Fields.Item("TipoDocElect").Value) != "111") && ((System.String)(oRecordSet.Fields.Item("DocSubType").Value) == "DN"))
                                {
                                    TipoDocElect = "56";
                                }
                                else if ((System.String)(oRecordSet.Fields.Item("DocSubType").Value) == "IE") //Factura Exenta
                                {
                                    TipoDocElect = "34";
                                }
                                else if ((System.String)(oRecordSet.Fields.Item("DocSubType").Value) == "IB") //Boleta
                                {
                                    TipoDocElect = "39";
                                }
                                else if ((System.String)(oRecordSet.Fields.Item("DocSubType").Value) == "EB") //Boleta Exenta
                                {
                                    TipoDocElect = "41";
                                }
                                else if ((System.String)(oRecordSet.Fields.Item("DocSubType").Value) == "IX") //Factura Exportacion
                                {
                                    TipoDocElect = "110";
                                }
                                else
                                {
                                    TipoDocElect = "33";
                                }

                                s = (System.String)(oRecordSet.Fields.Item("DocSubType").Value);
                                if ((System.String)(oRecordSet.Fields.Item("Tipo").Value) == "E")
                                {
                                    nMultiSoc = (System.String)(oRecordSet.Fields.Item("Inst").Value);
                                    if ((bMultiSoc == true) && (nMultiSoc == ""))
                                    {
                                        FSBOApp.StatusBar.SetText("Se encuentra parametrizado para Multiples Sociedades pero no se encuentra parametrizada la serie del documento", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                                    }
                                    else
                                    {
                                        var oInvoice = new TInvoice();
                                        oInvoice.SBO_f = FSBOf;
                                        oDocuments     = null;
                                        oDocuments     = (SAPbobsCOM.Documents)(FCmpny.GetBusinessObject(BoObjectTypes.oInvoices));
                                        if (oDocuments.GetByKey(Convert.ToInt32(DocEntry)))//**se dejo la normal mientras se termina la modificacion en el portal 20170202
                                        {
                                            oInvoice.EnviarFE_WebService(oForm.BusinessObject.Type, oDocuments, TipoDocElect, false, "", GlobalSettings.RunningUnderSQLServer, "--", TipoDocElect, false);
                                        }
                                    }
                                }
                            }
                            else if (oForm.BusinessObject.Type == "14") //And (Flag = true)) then
                            {
                                //Flag := false;
                                DocEntry = FSBOf.GetDocEntryBusinessObjectInfo(BusinessObjectInfo.ObjectKey);
                                if (GlobalSettings.RunningUnderSQLServer)
                                {
                                    s = @"select T0.DocSubType, SUBSTRING(UPPER(T2.BeginStr), 1, 1) 'Tipo', SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) Inst, SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) TipoDocElect, T0.ObjType from ORIN T0 JOIN NNM1 T2 ON T0.Series = T2.Series where T0.DocEntry = {0}";
                                }
                                else
                                {
                                    s = @"select T0.""DocSubType"", SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) ""Tipo"", SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""Inst"", SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""TipoDocElect"", T0.""ObjType"" from ""ORIN"" T0 JOIN ""NNM1"" T2 ON T0.""Series"" = T2.""Series"" where T0.""DocEntry"" = {0}";
                                }
                                s = String.Format(s, DocEntry);
                                oRecordSet.DoQuery(s);

                                if ((System.String)(oRecordSet.Fields.Item("TipoDocElect").Value) == "112")
                                {
                                    TipoDocElect = "112";
                                }
                                else
                                {
                                    TipoDocElect = "61";
                                }

                                var DocSubTypeNC = (System.String)(oRecordSet.Fields.Item("DocSubType").Value);
                                if ((System.String)(oRecordSet.Fields.Item("Tipo").Value) == "E")
                                {
                                    nMultiSoc = (System.String)(oRecordSet.Fields.Item("Inst").Value);
                                    if ((bMultiSoc == true) && (nMultiSoc == ""))
                                    {
                                        FSBOApp.StatusBar.SetText("Se encuentra parametrizado para Multiples Sociedades pero no se encuentra parametrizada la serie del documento", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                                    }
                                    else
                                    {
                                        var oCreditNotes = new TCreditNotes();
                                        oCreditNotes.SBO_f = FSBOf;
                                        oCreditNotes.EnviarFE_WebServiceNotaCredito(DocEntry, DocSubTypeNC, bMultiSoc, nMultiSoc, GlobalSettings.GLOB_EncryptSQL, GlobalSettings.RunningUnderSQLServer, (System.String)(oRecordSet.Fields.Item("ObjType").Value), TipoDocElect, TipoDocElect, false);
                                    }
                                }
                            }
                            //else if (oForm.BusinessObject.Type in ['15','67','21']) //And (Flag = true)) then
                            else if (FE52.Contains(oForm.BusinessObject.Type))
                            {
                                //Flag := false;
                                DocEntry = FSBOf.GetDocEntryBusinessObjectInfo(BusinessObjectInfo.ObjectKey);
                                if (GlobalSettings.RunningUnderSQLServer)
                                {
                                    if (oForm.BusinessObject.Type == "15")
                                    {
                                        s = @"select T0.DocSubType, SUBSTRING(UPPER(T2.BeginStr), 1, 1) 'Tipo', SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) Inst from ODLN T0 JOIN NNM1 T2 ON T0.Series = T2.Series where T0.DocEntry = {0}";
                                    }
                                    else if (oForm.BusinessObject.Type == "21")
                                    {
                                        s = @"select T0.DocSubType, SUBSTRING(UPPER(T2.BeginStr), 1, 1) 'Tipo', SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) Inst from ORPD T0 JOIN NNM1 T2 ON T0.Series = T2.Series where T0.DocEntry = {0}";
                                    }
                                    else if (oForm.BusinessObject.Type == "67")
                                    {
                                        s = @"select T0.DocSubType, SUBSTRING(UPPER(T2.BeginStr), 1, 1) 'Tipo', SUBSTRING(ISNULL(T2.BeginStr,''), 2, LEN(T2.BeginStr)) Inst from OWTR T0 JOIN NNM1 T2 ON T0.Series = T2.Series where T0.DocEntry = {0}";
                                    }
                                }
                                else
                                {
                                    if (oForm.BusinessObject.Type == "15")
                                    {
                                        s = @"select T0.""DocSubType"", SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) ""Tipo"", SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""Inst"" from ""ODLN"" T0 JOIN ""NNM1"" T2 ON T0.""Series"" = T2.""Series"" where T0.""DocEntry"" = {0}";
                                    }
                                    else if (oForm.BusinessObject.Type == "21")
                                    {
                                        s = @"select T0.""DocSubType"", SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) ""Tipo"", SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""Inst"" from ""ORPD"" T0 JOIN ""NNM1"" T2 ON T0.""Series"" = ""T2.Series"" where T0.""DocEntry"" = {0}";
                                    }
                                    else if (oForm.BusinessObject.Type == "67")
                                    {
                                        s = @"select T0.""DocSubType"", SUBSTRING(UPPER(T2.""BeginStr""), 1, 1) ""Tipo"", SUBSTRING(IFNULL(T2.""BeginStr"",''), 2, LENGTH(T2.""BeginStr"")) ""Inst"" from ""OWTR"" T0 JOIN ""NNM1"" T2 ON T0.""Series"" = T2.""Series"" where T0.""DocEntry"" = {0}";
                                    }
                                }
                                s = String.Format(s, DocEntry);
                                oRecordSet.DoQuery(s);
                                s = (System.String)(oRecordSet.Fields.Item("DocSubType").Value);
                                if ((System.String)(oRecordSet.Fields.Item("Tipo").Value) == "E")
                                {
                                    nMultiSoc = (System.String)(oRecordSet.Fields.Item("Inst").Value);
                                    if ((bMultiSoc == true) && (nMultiSoc == ""))
                                    {
                                        FSBOApp.StatusBar.SetText("Se encuentra parametrizado para Multiples Sociedades pero no se encuentra parametrizada la serie del documento", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                                    }
                                    else
                                    {
                                        var oDeliveryNote = new TDeliveryNote();
                                        oDeliveryNote.SBO_f = FSBOf;
                                        if (oForm.BusinessObject.Type == "15")
                                        {
                                            oDeliveryNote.EnviarFE_WebService(DocEntry, s, false, false, false, bMultiSoc, nMultiSoc, GlobalSettings.GLOB_EncryptSQL, GlobalSettings.RunningUnderSQLServer, "52", oForm.BusinessObject.Type, false);
                                        }
                                        else if (oForm.BusinessObject.Type == "21")
                                        {
                                            oDeliveryNote.EnviarFE_WebService(DocEntry, s, false, false, true, bMultiSoc, nMultiSoc, GlobalSettings.GLOB_EncryptSQL, GlobalSettings.RunningUnderSQLServer, "52D", oForm.BusinessObject.Type, false);
                                        }
                                        else if (oForm.BusinessObject.Type == "67")
                                        {
                                            oDeliveryNote.EnviarFE_WebService(DocEntry, s, true, false, false, bMultiSoc, nMultiSoc, GlobalSettings.GLOB_EncryptSQL, GlobalSettings.RunningUnderSQLServer, "52T", oForm.BusinessObject.Type, false);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        FSBOApp.StatusBar.SetText("Debe Parametrizar el Addon", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Warning);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }//fin FormDataEvent