Exemplo n.º 1
0
        protected string generateInvoicePDF(int invoiceID)
        {
            string reportPath = null;

            string appPath = ConfigurationManager.AppSettings["appPath"].ToString();

            invoiceReport = LeadInvoiceManager.GetInvoiceForReport(invoiceID);

            if (invoiceReport != null)
            {
                reportViewer.Reset();

                reportViewer.LocalReport.DataSources.Clear();

                reportViewer.LocalReport.EnableExternalImages = true;

                ReportDataSource reportDataSource = new ReportDataSource();

                reportDataSource.Name = "DataSet1";

                reportDataSource.Value = invoiceReport;

                reportViewer.LocalReport.DataSources.Add(reportDataSource);

                reportViewer.LocalReport.ReportPath = appPath + "/Content/Invoice.rdlc";

                reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(subReportsEventHandler);

                reportPath = string.Format("{0}/Temp/Invoice_{1}.pdf", appPath, invoiceID);

                Core.ReportHelper.savePDFFromLocalReport(reportViewer.LocalReport, reportPath);
            }

            return(reportPath);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int invoiceID = Request.Params["id"] == null ? 0 : Convert.ToInt32(Request.Params["id"]);

            invoice = LeadInvoiceManager.GetInvoiceForReport(invoiceID);

            if (invoice != null)
            {
                reportViewer.Reset();
                reportViewer.LocalReport.DataSources.Clear();

                reportViewer.LocalReport.EnableExternalImages = true;

                ReportDataSource reportDataSource = new ReportDataSource();
                reportDataSource.Name  = "DataSet1";
                reportDataSource.Value = invoice;

                reportViewer.LocalReport.DataSources.Add(reportDataSource);

                reportViewer.LocalReport.ReportPath = appPath + "/Content/Invoice.rdlc";

                this.reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(subReportsEventHandler);

                string pdfPath = string.Format("{0}/Temp/{1}.pdf", appPath, Guid.NewGuid());

                Core.ReportHelper.savePDFFromLocalReport(reportViewer.LocalReport, pdfPath);

                Core.ReportHelper.renderToBrowser(pdfPath);
            }
        }
        public void bindData()
        {
            int leadID = Core.SessionHelper.getLeadId();

            List <CRM.Data.Entities.LeadInvoice> invoices = LeadInvoiceManager.GetInvoices(leadID).ToList();

            gvInvoices.DataSource = invoices;
            gvInvoices.DataBind();
        }
Exemplo n.º 4
0
        protected void btnEmailInvoice_Click(object sender, EventArgs e)
        {
            string reportPath = null;
            int    invoiceID  = 0;

            Data.Entities.LeadInvoice invoice = null;
            int    port     = 0;
            string password = null;

            CRM.Data.Entities.SecUser user = null;
            string subject  = "Invoice";
            int    userID   = Core.SessionHelper.getUserId();
            string bodyText = "Invoiced is attached.";

            Page.Validate("emailInvoice");
            if (!Page.IsValid)
            {
                return;
            }

            try {
                invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString());

                reportPath = generateInvoicePDF(invoiceID);

                user = SecUserManager.GetByUserId(userID);

                if (user != null && !string.IsNullOrEmpty(reportPath))
                {
                    invoice = LeadInvoiceManager.Get(invoiceID);

                    string[] recipient = new string[] { txtEmailTo.Text };

                    string[] attachments = new string[] { reportPath };

                    port = Convert.ToInt32(user.emailHostPort);

                    password = Core.SecurityManager.Decrypt(user.emailPassword);

                    Core.EmailHelper.sendEmail(user.Email, recipient, null, subject, bodyText, attachments, user.emailHost, port, user.Email, password);

                    updateDocumentLog(reportPath, (int)invoice.PolicyTypeID);

                    lblMessage.Text     = "Invoice mailed successfully.";
                    lblMessage.CssClass = "ok";
                }
            }
            catch (Exception ex) {
                lblMessage.Text     = "Unable to email invoice.";
                lblMessage.CssClass = "error";
            }
        }
        protected void gvInvoices_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int invoiceID = 0;

            CRM.Data.Entities.LeadInvoice invoice = null;

            if (e.CommandName == "DoDelete")
            {
                invoiceID = Convert.ToInt32(e.CommandArgument);

                invoice = LeadInvoiceManager.Get(invoiceID);

                if (invoice != null)
                {
                    invoice.isVoid = true;

                    LeadInvoiceManager.Save(invoice);

                    // refresh list
                    bindData();
                }
            }
        }
Exemplo n.º 6
0
        private void saveInvoice()
        {
            string[] billToValues  = null;
            int      clientID      = 0;
            int      invoiceID     = 0;
            int      InvoiceLineID = 0;

            Data.Entities.LeadInvoice    invoice           = null;
            CRM.Data.Entities.LeadPolicy policy            = null;
            LeadInvoiceDetail            invoiceDetailLine = null;
            LeadInvoiceDetail            invoiceDetail     = null;

            int     nextInvoiceNumber = 0;
            int     policyID          = 0;
            decimal taxAmount         = 0;

            billToValues = ddlBillTo.SelectedValue.Split(new char[] { '|' });

            // get invoice id
            invoiceID = Convert.ToInt32(ViewState["InvoiceID"].ToString());

            clientID = Core.SessionHelper.getClientId();

            // current policy being edited
            policyID = Session["policyID"] == null ? 0 : Convert.ToInt32(Session["policyID"]);
            policy   = LeadPolicyManager.GetByID(policyID);



            if (invoiceID == 0)
            {
                invoice = new Data.Entities.LeadInvoice();

                // get id for current lead
                invoice.LeadId = Core.SessionHelper.getLeadId();

                invoice.isVoid = false;

                // assign client
                invoice.ClientID = clientID;

                // hide print button
                //btnPrint.Visible = false;
            }
            else
            {
                invoice = LeadInvoiceManager.Get(invoiceID);

                // show print button
                //btnPrint.Visible = true;
            }


            invoice.PolicyID = policy.PolicyType;

            invoice.InvoiceDate    = Convert.ToDateTime(txtInvoiceDate.Text);
            invoice.DueDate        = Convert.ToDateTime(txtDueDate.Text);
            invoice.BillToName     = txtBillTo.Text.Trim();
            invoice.BillToAddress1 = txtBillToAddress1.Text.Trim();
            invoice.BillToAddress2 = txtBillToAddress2.Text.Trim();
            invoice.BillToAddress3 = txtBillToAddress3.Text.Trim();

            invoice.AdjusterID = policy.AdjusterID;

            invoice.AdjusterInvoiceNumber = txtReferenceNumber.Text.Trim();

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    if (invoiceID == 0)
                    {
                        // assign next invoice number to new invoice
                        nextInvoiceNumber = LeadInvoiceManager.GetNextInvoiceNumber(clientID);

                        invoice.InvoiceNumber = nextInvoiceNumber;
                    }

                    invoiceID = LeadInvoiceManager.Save(invoice);

                    // save newly generated invoice id
                    ViewState["InvoiceID"] = invoiceID.ToString();

                    // check for add/edit invoice detail line
                    InvoiceLineID = ViewState["InvoiceLineID"] == null ? 0 : Convert.ToInt32(ViewState["InvoiceLineID"]);

                    if (InvoiceLineID > 0)
                    {
                        invoiceDetail = LeadInvoiceDetailManager.Get(InvoiceLineID);
                    }
                    else
                    {
                        invoiceDetail = new LeadInvoiceDetail();
                    }


                    // get detail line from gridview footer
                    if (invoiceDetail != null)
                    {
                        invoiceDetailLine = getInvoiceDetailLine();

                        if (invoiceDetailLine.LineDate != null && !string.IsNullOrEmpty(invoiceDetailLine.LineDescription) && invoiceDetailLine.Qty > 0 &&
                            invoiceDetailLine.Rate > 0)
                        {
                            // update fields
                            invoiceDetail.InvoiceID       = invoiceID;
                            invoiceDetail.InvoiceLineID   = InvoiceLineID;
                            invoiceDetail.ServiceTypeID   = invoiceDetailLine.ServiceTypeID;
                            invoiceDetail.Comments        = invoiceDetailLine.Comments;
                            invoiceDetail.isBillable      = invoiceDetailLine.isBillable;
                            invoiceDetail.LineAmount      = invoiceDetailLine.LineAmount;
                            invoiceDetail.LineDate        = invoiceDetailLine.LineDate;
                            invoiceDetail.LineDescription = invoiceDetailLine.LineDescription;
                            invoiceDetail.Qty             = invoiceDetailLine.Qty;
                            invoiceDetail.Rate            = invoiceDetailLine.Rate;
                            invoiceDetail.UnitDescription = invoiceDetailLine.UnitDescription;
                            invoiceDetail.Total           = invoiceDetailLine.Total;

                            // save invoice detail
                            LeadInvoiceDetailManager.Save(invoiceDetail);

                            // clear
                            ViewState["InvoiceLineID"] = "0";

                            // update invoice total after adding
                            invoice = LeadInvoiceManager.Get(invoiceID);

                            invoice.TotalAmount = invoice.LeadInvoiceDetail.Where(x => x.isBillable == true).Sum(x => x.LineAmount);

                            taxAmount = (invoice.TotalAmount ?? 0) * ((invoice.TaxRate ?? 0) / 100);

                            //invoice.TotalAmount = invoice.TotalAmount + taxAmount;

                            LeadInvoiceManager.Save(invoice);

                            // update comment
                            updateInvoiceComment(invoice, invoiceDetail);
                        }
                    }
                    // complete transaction
                    scope.Complete();
                }

                // refresh invoice detail lines
                bindInvoiceDetails(invoiceID);

                clearFields();

                showToolbarButtons();
            }
            catch (Exception ex) {
                lblMessage.Text     = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }
Exemplo n.º 7
0
        protected void bindData()
        {
            int invoiceID = 0;
            int policyID  = 0;

            CRM.Data.Entities.LeadInvoice invoice        = null;
            List <LeadInvoiceDetail>      invoiceDetails = null;

            // get id for current lead
            int leadID = Core.SessionHelper.getLeadId();

            // get client id
            int clientID = Core.SessionHelper.getClientId();

            // get current policy
            policyID = Core.SessionHelper.getPolicyID();

            // check for new invoice or edit invoice
            ViewState["InvoiceID"] = Request.Params["id"] == null ? "0" : Request.Params["id"].ToString();

            int.TryParse(ViewState["InvoiceID"].ToString(), out invoiceID);

            // get lead/claim
            Leads lead = LeadsManager.Get(leadID);

            if (lead != null)
            {
                bindBillTo(lead);

                lblClient.Text = string.Format("<b>{0} {1}<br/>{2}<br/>{3}<br/>{4}, {5} {6}</b>",
                                               lead.ClaimantFirstName ?? "", //0
                                               lead.ClaimantLastName ?? "",  //1
                                               lead.LossAddress ?? "",       //2
                                               lead.LossAddress2 ?? "",      //3
                                               lead.CityName ?? "",          //4
                                               lead.StateName ?? "",         // 5
                                               lead.Zip ?? ""                //6
                                               );
            }


            if (invoiceID == 0)
            {
                // new invoice
                txtInvoiceDate.Text = DateTime.Now.ToShortDateString();

                invoiceDetails = new List <LeadInvoiceDetail>();
                invoiceDetails.Add(new LeadInvoiceDetail());

                gvInvoiceLines.DataSource = invoiceDetails;

                gvInvoiceLines.DataBind();


                // hide empty row
                gvInvoiceLines.Rows[0].Visible = false;

                // hide print button
                //btnPrint.Visible = false;

                // hiden invoice number
                pnlInvoiceNumber.Visible = false;
            }
            else
            {
                // edit invoice
                invoice = LeadInvoiceManager.Get(invoiceID);

                // show print button
                //btnPrint.Visible = true;

                if (invoice != null && invoice.LeadInvoiceDetail != null)
                {
                    txtInvoiceDate.Text = string.Format("{0:MM/dd/yyyy}", invoice.InvoiceDate);
                    txtDueDate.Text     = string.Format("{0:MM/dd/yyyy}", invoice.DueDate);

                    txtBillTo.Text         = invoice.BillToName;
                    txtBillToAddress1.Text = invoice.BillToAddress1;
                    txtBillToAddress2.Text = invoice.BillToAddress2;
                    txtBillToAddress3.Text = invoice.BillToAddress3;

                    // reference
                    txtReferenceNumber.Text = invoice.AdjusterInvoiceNumber;

                    // show total
                    txtTotalAmount.Text = string.Format("{0:N2}", invoice.TotalAmount);


                    // sort line items by date
                    gvInvoiceLines.DataSource = invoice.LeadInvoiceDetail.OrderBy(x => x.LineDate);

                    gvInvoiceLines.DataBind();

                    // show invoice numebr
                    pnlInvoiceNumber.Visible = true;


                    txtInvoiceNumber.Text = string.Format("{0:N0}", invoice.InvoiceNumber ?? 0);
                }
            }


            bindInvoiceServices();
        }