public static int Save(LeadInvoiceDetail invoiceDetail)
        {
            if (invoiceDetail.InvoiceLineID == 0)
                DbContextHelper.DbContext.Add(invoiceDetail);

            DbContextHelper.DbContext.SaveChanges();

            return invoiceDetail.InvoiceLineID;
        }
예제 #2
0
        public static List<InvoiceView> GetInvoiceForReport(int invoiceID)
        {
            InvoiceView invoice = null;
            List<InvoiceView> invoices = new List<InvoiceView>();
            ZipCodeMaster zipCodeMaster = null;

            LeadInvoice leadInvoice = (from x in DbContextHelper.DbContext
                                   .LeadInvoice
                                   .Include("LeadInvoiceDetail")
                                   .Include("LeadInvoiceDetail.InvoiceServiceType")
                                   .Include("LeadInvoiceDetail.InvoiceServiceType.InvoiceServiceUnit")
                                   .Include("Leads")
                                   .Include("Leads.Client")
                                   .Include("Leads.Client.StateMaster")
                                   .Include("Leads.Client.CityMaster")
                                   .Include("Leads.LeadPolicy")
                                   .Include("Leads.LeadPolicy.LeadPolicyType")
                                  where x.InvoiceID == invoiceID
                                  select x
                            ).FirstOrDefault<LeadInvoice>();

            if (leadInvoice != null) {
                invoice = new InvoiceView();
                invoice.invoiceID = leadInvoice.InvoiceID;
                invoice.invoiceDate = (DateTime)leadInvoice.InvoiceDate;
                invoice.dueDate = leadInvoice.DueDate == null ? DateTime.Now : (DateTime)leadInvoice.DueDate;
                invoice.invoiceNumber = (int)(leadInvoice.InvoiceNumber ?? 0);

                invoice.billTo = leadInvoice.BillToName;
                invoice.billToAddress1 = leadInvoice.BillToAddress1;
                invoice.billToAddress2 = leadInvoice.BillToAddress2;
                invoice.billToAddress3 = leadInvoice.BillToAddress3;
                invoice.totalAmount = leadInvoice.TotalAmount ?? 0;

                invoice.adjusterInvoiceNumber = leadInvoice.AdjusterInvoiceNumber;

                // get policy type associated with invoice
                leadInvoice.Leads.LeadPolicy.FirstOrDefault(x => x.PolicyType == leadInvoice.PolicyTypeID);

                //if (leadInvoice.Leads.LeadPolicy != null && leadInvoice.Leads.LeadPolicy.LeadPolicyType != null)
                //    invoice.policyType = leadInvoice.Leads.LeadPolicy.Description;

                //invoice.policyNumber = leadInvoice.Leads.LeadPolicy;
                //invoice.claimNumber = leadInvoice.Leads.LeadPolicy.ClaimNumber;
                //invoice.insurerFileNo = leadInvoice.Leads.LeadPolicy.InsurerFileNo;

                if (leadInvoice.Leads.LeadPolicy != null && leadInvoice.Leads.LeadPolicy.FirstOrDefault().LeadPolicyType != null)
                    invoice.policyType = leadInvoice.Leads.LeadPolicy.FirstOrDefault().LeadPolicyType.Description;

                invoice.policyNumber = leadInvoice.Leads.LeadPolicy.FirstOrDefault().PolicyNumber;
                invoice.claimNumber = leadInvoice.Leads.LeadPolicy.FirstOrDefault().ClaimNumber;
                invoice.insurerFileNo = leadInvoice.Leads.LeadPolicy.FirstOrDefault().InsurerFileNo;

                invoice.claimantName = leadInvoice.Leads.ClaimantFirstName + " " + leadInvoice.Leads.ClaimantLastName;
                invoice.claimantAddress1 = leadInvoice.Leads.LossAddress;
                invoice.claimantAddress2 = leadInvoice.Leads.LossAddress2;
                invoice.claimantAddress3 = string.Format("{0}, {1} {2}",
                        leadInvoice.Leads.CityName ?? "",
                        leadInvoice.Leads.StateName ?? "",
                        leadInvoice.Leads.Zip ?? "");

                invoice.taxRate = leadInvoice.TaxRate ?? 0;

                if (leadInvoice.Leads.DateSubmitted != null)
                    invoice.claimDate = (DateTime)leadInvoice.Leads.DateSubmitted;

                invoice.legacyInvoiceLines = leadInvoice.LeadInvoiceDetail.ToList();

                // add sales tax
                if (invoice.taxRate > 0) {
                    LeadInvoiceDetail invoiceTaxLine = new LeadInvoiceDetail();
                    invoiceTaxLine.InvoiceID = invoice.invoiceID;
                    invoiceTaxLine.LineDescription = "Sales Tax";
                    invoiceTaxLine.isBillable = true;
                    invoiceTaxLine.LineAmount = invoice.totalAmount * (invoice.taxRate / 100);
                    invoice.legacyInvoiceLines.Add(invoiceTaxLine);
                }

                if (leadInvoice.Leads.Client != null) {
                    invoice.adjusterInvoiceNumber = leadInvoice.AdjusterInvoiceNumber;

                    invoice.clientName = leadInvoice.Leads.Client.BusinessName;
                    invoice.clientAddress1 = leadInvoice.Leads.Client.StreetAddress1;
                    invoice.clientAddress2 = leadInvoice.Leads.Client.StreetAddress2;

                    string stateName = leadInvoice.Leads.Client.StateMaster != null ? leadInvoice.Leads.Client.StateMaster.StateCode : "";
                    string cityName = leadInvoice.Leads.Client.CityMaster != null ? leadInvoice.Leads.Client.CityMaster.CityName : "";
                    string zipCode = leadInvoice.Leads.Client.ZipCode ?? "";

                    // this is badly designed.
                    if (!string.IsNullOrEmpty(zipCode)) {
                        zipCodeMaster = ZipCode.Get(zipCode);
                        if (zipCodeMaster != null)
                            zipCode = zipCodeMaster.ZipCode;
                    }

                    invoice.clientAddress3 = cityName + ", " + stateName + " " + zipCode;

                    invoice.clientPhone = leadInvoice.Leads.Client.PrimaryPhoneNo;
                    invoice.clientFax = leadInvoice.Leads.Client.SecondaryPhoneNo;
                    invoice.clientEmail = leadInvoice.Leads.Client.PrimaryEmailId;

                    invoice.logoPath = string.Format("{0}/ClientLogo/{1}.jpg", ConfigurationManager.AppSettings["appURL"].ToString(), leadInvoice.Leads.ClientID);
                }
                else {
                    invoice.logoPath = ConfigurationManager.AppSettings["appURL"].ToString() + "/images/claim_ruler_logo.jpg";
                    invoice.clientName = "Claim Ruler Demo";
                    invoice.clientAddress1 = "400 East Las Olas Blvd";
                    invoice.clientAddress2 = "Suite 404";
                    invoice.clientAddress3 = "Ft. Lauderdale, FL 33301";
                    invoice.clientPhone = "999-999-9999";
                    invoice.clientFax = "999-999-9999";
                    invoice.clientEmail = "*****@*****.**";
                    invoice.federalIDNo = "99999999";
                }

                invoices.Add(invoice);
            }

            return invoices;
        }
예제 #3
0
        // process gridview commands
        protected void gvInvoiceLines_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int invoiceID     = 0;
            int invoiceLineID = 0;

            CRM.Data.Entities.LeadInvoiceDetail invoiceLine = null;
            TextBox txtLineAmount;

            switch (e.CommandName)
            {
            case "DoEdit":
                invoiceLineID = Convert.ToInt32(e.CommandArgument);

                invoiceLine = LeadInvoiceDetailManager.Get(invoiceLineID);

                if (invoiceLine != null)
                {
                    ViewState["InvoiceLineID"] = invoiceLineID.ToString();


                    // date
                    WebDatePicker txtDate = gvInvoiceLines.FooterRow.FindControl("txtDate") as WebDatePicker;
                    if (txtDate != null && invoiceLine.LineDate != null)
                    {
                        txtDate.Text = string.Format("{0:MM/dd/yyyy}", invoiceLine.LineDate);
                    }

                    // service description
                    DropDownList cbx = gvInvoiceLines.FooterRow.FindControl("cbxServiceDescription") as DropDownList;
                    if (cbx != null && invoiceLine.ServiceTypeID != null)
                    {
                        ListItem item = cbx.Items.FindByText(invoiceLine.LineDescription.Trim());
                        if (item != null)
                        {
                            cbx.SelectedIndex = cbx.Items.IndexOf(item);
                        }
                    }
                    else
                    {
                        ListItem item = new ListItem(invoiceLine.LineDescription, invoiceLine.LineDescription);
                        cbx.Items.Add(item);
                        cbx.Text = invoiceLine.LineDescription;
                    }

                    // quantity
                    WebNumericEditor txtQty = gvInvoiceLines.FooterRow.FindControl("txtQty") as WebNumericEditor;
                    if (txtQty != null && invoiceLine.Qty != null)
                    {
                        txtQty.Text = invoiceLine.Qty.ToString();
                    }

                    // rate
                    WebNumericEditor txtRate = gvInvoiceLines.FooterRow.FindControl("txtRate") as WebNumericEditor;
                    if (txtRate != null && invoiceLine.InvoiceServiceType != null && invoiceLine.InvoiceServiceType.ServiceRate != null)
                    {
                        txtRate.Text = invoiceLine.InvoiceServiceType.ServiceRate.ToString();
                    }

                    // service unit
                    Label lblUnitDescription = gvInvoiceLines.FooterRow.FindControl("lblUnitDescription") as Label;
                    if (lblUnitDescription != null && invoiceLine.InvoiceServiceType != null && invoiceLine.InvoiceServiceType.InvoiceServiceUnit != null)
                    {
                        lblUnitDescription.Text = invoiceLine.InvoiceServiceType.InvoiceServiceUnit.UnitDescription;
                    }

                    // total amount
                    txtLineAmount = gvInvoiceLines.FooterRow.FindControl("txtLineAmount") as TextBox;
                    if (txtLineAmount != null)
                    {
                        txtLineAmount.Text = string.Format("{0:N2}", invoiceLine.LineAmount ?? 0);
                    }

                    //billable
                    CheckBox cbxBillable = gvInvoiceLines.FooterRow.FindControl("cbxBillable") as CheckBox;
                    if (cbxBillable != null && invoiceLine.isBillable != null)
                    {
                        cbxBillable.Checked = invoiceLine.isBillable ?? false;
                    }

                    // comments
                    WebTextEditor txtComments = gvInvoiceLines.FooterRow.FindControl("txtComments") as WebTextEditor;
                    if (txtComments != null && invoiceLine.Comments != null)
                    {
                        txtComments.Text = invoiceLine.Comments;
                    }

                    // show cancel icon
                    ImageButton ibtnCancel = gvInvoiceLines.FooterRow.FindControl("ibtnCancel") as ImageButton;
                    ibtnCancel.Visible = true;
                }
                break;

            case "DoDelete":
                invoiceLineID = Convert.ToInt32(e.CommandArgument);
                if (invoiceLineID > 0)
                {
                    using (TransactionScope scope = new TransactionScope()) {
                        try {
                            LeadInvoiceDetailManager.Delete(invoiceLineID);

                            deleteInvoiceComment(invoiceLineID);

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

                            bindInvoiceDetails(invoiceID);

                            // complete transaction
                            scope.Complete();
                        }
                        catch (Exception ex) {
                            lblMessage.Text     = "Error while deleting invoice detail line.";
                            lblMessage.CssClass = "error";
                            Core.EmailHelper.emailError(ex);
                        }
                    }
                }

                break;
            }
        }
예제 #4
0
        public static LeadInvoice Save_bak(LeadInvoice invoice)
        {
            LeadInvoice updateInvoice = null;
            LeadInvoiceDetail updateinvoiceLine = null;

            if (invoice.InvoiceID == 0) {
                DbContextHelper.DbContext.Add(invoice);

                //DbContextHelper.DbContext.SaveChanges();
            }
            else {
                updateInvoice = Get(invoice.InvoiceID);

                updateInvoice.InvoiceDate = invoice.InvoiceDate;

                updateInvoice.PolicyTypeID = invoice.PolicyTypeID;

                updateInvoice.BillToName = invoice.BillToName;
                updateInvoice.BillToAddress1 = invoice.BillToAddress1;
                updateInvoice.BillToAddress2 = invoice.BillToAddress2;
                updateInvoice.BillToAddress3 = invoice.BillToAddress3;

                updateInvoice.AdjusterInvoiceNumber = invoice.AdjusterInvoiceNumber;

                //DbContextHelper.DbContext.SaveChanges();

                foreach (LeadInvoiceDetail invoiceLine in invoice.LeadInvoiceDetail) {
                    if (invoiceLine.InvoiceLineID == 0) {
                        updateinvoiceLine = new LeadInvoiceDetail();

                        updateinvoiceLine.InvoiceID = invoice.InvoiceID;

                        DbContextHelper.DbContext.Add(updateinvoiceLine);
                    }
                    else
                        updateinvoiceLine = GetInvoiceDetailLine(invoiceLine.InvoiceLineID);

                    updateinvoiceLine.LineItemNo = invoiceLine.LineItemNo;

                    updateinvoiceLine.LineDescription = invoiceLine.LineDescription;

                    updateinvoiceLine.LineAmount = invoiceLine.LineAmount;

                }
            }

            DbContextHelper.DbContext.SaveChanges();

            return invoice;
        }