Пример #1
0
        private CRM.Data.Entities.LeadPolicy createPolicy(int leadID, DataRow dataRow)
        {
            CRM.Data.Entities.LeadPolicy policy = null;
            string userFieldName = null;

            policy = new CRM.Data.Entities.LeadPolicy();

            policy.LeadId   = leadID;
            policy.IsActive = true;

            // Policy Number
            userFieldName = Core.CSVHelper.getUserFieldName(this.mappedFields, "Policy Number");
            if (!string.IsNullOrEmpty(userFieldName) && dataRow[userFieldName] != null)
            {
                policy.PolicyNumber = dataRow[userFieldName].ToString().Trim();
            }

            // Policy Form
            userFieldName = Core.CSVHelper.getUserFieldName(this.mappedFields, "Policy Form");
            if (!string.IsNullOrEmpty(userFieldName) && dataRow[userFieldName] != null)
            {
                policy.PolicyFormType = dataRow[userFieldName].ToString().Trim();
            }

            LeadPolicyManager.Save(policy);

            return(policy);
        }
Пример #2
0
        protected CRM.Data.Entities.LeadPolicy collectPolicyDataFromUI()
        {
            CRM.Data.Entities.LeadPolicy policy = new CRM.Data.Entities.LeadPolicy();

            policy.PolicyType   = Convert.ToInt32(ucPolicyType1.SelectedValue);
            policy.PolicyNumber = txtPolicyNumber.Text.Trim();
            policy.ClaimNumber  = txtClaimNumber.Text.Trim();
            policy.IsActive     = true;

            policy.LossDate = txtLossDate.Date;



            return(policy);
        }
Пример #3
0
        private void notifyAdjuster(CRM.Data.Entities.LeadPolicy policy)
        {
            AdjusterMaster adjuster      = null;
            string         clientName    = null;
            string         claimantName  = null;
            string         emailText     = null;
            string         emailPassword = null;
            Leads          lead          = null;
            int            leadID        = 0;

            string[] recipients = null;
            string   userEmail  = null;
            string   subject    = null;

            // get adjuster info
            adjuster = AdjusterManager.Get(policy.AdjusterID ?? 0);

            // retreive lead information
            leadID = SessionHelper.getLeadId();

            lead = LeadsManager.GetByLeadId(leadID);

            if (lead != null && adjuster != null && !string.IsNullOrEmpty(adjuster.email) && (adjuster.isEmailNotification ?? true))
            {
                recipients = new string[] { adjuster.email };

                userEmail     = ConfigurationManager.AppSettings["userID"].ToString();
                emailPassword = ConfigurationManager.AppSettings["Password"].ToString();

                // name of CRM client
                clientName = adjuster.Client == null ? "" : adjuster.Client.BusinessName;

                claimantName = string.Format("{0} {1}", lead.ClaimantFirstName ?? "", lead.ClaimantLastName ?? "");

                subject = string.Format("{0} has assigned {1} to you.", clientName, claimantName);

                emailText = string.Format("<br>Claim # {0} was assigned to you.<br>Please review {1} right away to begin the file.<br><br>Thank you.<br><br>http://app.claimruler.com",
                                          policy.ClaimNumber,
                                          claimantName);

                Core.EmailHelper.sendEmail(adjuster.email, recipients, null, subject, emailText, null, userEmail, emailPassword);
            }
        }
Пример #4
0
        protected void gvCarrierPolicy_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            CRM.Data.Entities.LeadPolicy policy = null;
            decimal invoiceAmount = 0;

            int profileID = Convert.ToInt32(ddlInvoiceProfile.SelectedValue);

            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                policy = e.Row.DataItem as CRM.Data.Entities.LeadPolicy;

                Label lblPolicyHolder = e.Row.FindControl("lblPolicyHolder") as Label;
                lblPolicyHolder.Text = LeadsManager.GetLeadName((int)policy.LeadId);

                invoiceAmount = calculateInvoiceAmount(policy);
                Label lblInvoiceAmount = e.Row.FindControl("lblInvoiceAmount") as Label;

                lblInvoiceAmount.Text = string.Format("{0:N2}", invoiceAmount);
            }
        }
Пример #5
0
        public void fillForm()
        {
            Contact primaryContact = null;
            string  zipCode        = null;

            if (policyID > 0)
            {
                CRM.Data.Entities.LeadPolicy policy = LeadPolicyManager.Get(policyID);

                if (policy == null)
                {
                    return;
                }

                ViewState["policyType"] = policy.PolicyType.ToString();

                hf_policyID.Value     = policy.Id.ToString();
                hf_lastStatusID.Value = (policy.LeadStatus ?? 0).ToString();

                //cbxAllDocumentUploaded.Checked = policy.isAllDocumentUploaded ?? false;

                if (policy.PolicyType != null)
                {
                    ucPolicyType1.SelectedValue = policy.PolicyType.ToString();
                }

                txtPolicyFormType.Text = policy.PolicyFormType;

                txtInsuranceCompanyName.Text  = policy.Carrier == null ? policy.InsuranceCompanyName : policy.Carrier.CarrierName;
                txtInsuranceAddress.Text      = policy.Carrier == null ? policy.InsuranceAddress : policy.Carrier.AddressLine1;
                txtInsuranceAddress2.Text     = policy.Carrier == null ? "" : policy.Carrier.AddressLine2;
                txtInsurancePolicyNumber.Text = policy.PolicyNumber;

                if (policy.Carrier != null)
                {
                    txtInsuranceState.Text   = policy.Carrier.StateName;
                    txtInsuranceCity.Text    = policy.Carrier.CityMaster != null ? policy.Carrier.CityMaster.CityName : string.Empty;
                    txtInsuranceZipCode.Text = policy.Carrier.ZipCode;

                    ddlCarrier.SelectedValue = policy.CarrierID.ToString();

                    // get primary carrier contact
                    primaryContact = CarrierContactManager.GetPrimaryContact((int)policy.CarrierID);
                    if (primaryContact != null)
                    {
                        txtPrimaryContactName.Text  = primaryContact.fullName;
                        txtPrimaryContactEmail.Text = primaryContact.Email;
                        txtPrimaryContactPhone.Text = primaryContact.Phone;
                    }
                }
                else
                {
                    zipCode = policy.InsuranceZipCode ?? "";
                }

                txtInsuranceFaxNumber.Text = policy.FaxNumber;

                txtInsurancePhoneNumber.Text = policy.PhoneNumber;

                txtEffectiveDate.Value = policy.EffectiveDate;

                txtExpirationDate.Value = policy.ExpirationDate;

                txtInitialCoverageDate.Value = policy.InitialCoverageDate;

                if (policy.AgentID != null)
                {
                    fillAgentDetails((int)policy.AgentID);
                }
            }
        }
Пример #6
0
        public void saveForm()
        {
            Page.Validate("Policy");
            //if (!Page.IsValid)
            //    return;

            CRM.Data.Entities.LeadPolicy policy = null;

            lblMessage.Text = string.Empty;
            lblMessage.CssClass = string.Empty;

            //if (int.TryParse(hf_policyID.Value, out id) && id > 0) {
            if (policyID > 0) {
                policy = LeadPolicyManager.Get(policyID);
            }
            else {
                // new
                policy = new CRM.Data.Entities.LeadPolicy();
                policy.LeadId = Core.SessionHelper.getLeadId();
                policy.Id = 0;
                policy.IsActive = true;
                policy.isAllDocumentUploaded = false;
            }
            if (ucPolicyType1.SelectedValue == "0" || ucPolicyType1.SelectedValue == "")
            {
                policy.PolicyType = null;
            }
            else
            {
                policy.PolicyType = Convert.ToInt32(ucPolicyType1.SelectedValue);
            }

            // carrier information
            if (ddlCarrier.SelectedIndex > 0)
                policy.CarrierID = Convert.ToInt32(ddlCarrier.SelectedValue);
            else
                policy.CarrierID = null;

            policy.PolicyNumber = txtInsurancePolicyNumber.Text.Trim();
            policy.PolicyFormType = txtPolicyFormType.Text.Trim();

            policy.InsuranceCompanyName = txtInsuranceCompanyName.Text;

            if (!string.IsNullOrEmpty(txtExpirationDate.Text))
                policy.ExpirationDate = txtExpirationDate.Date;
            else
                policy.ExpirationDate = null;

            if (!string.IsNullOrEmpty(txtExpirationDate.Text))
                policy.EffectiveDate = txtEffectiveDate.Date;
            else
                policy.EffectiveDate = null;

            if (!string.IsNullOrEmpty(txtInitialCoverageDate.Text))
                policy.InitialCoverageDate = txtInitialCoverageDate.Date;

            if (ddlAgent.SelectedIndex > 0)
                policy.AgentID = Convert.ToInt32(ddlAgent.SelectedValue);

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    // save policy id
                    this.policyID = LeadPolicyManager.Save(policy);

                    if (HttpContext.Current.Session["Limit"] != null && HttpContext.Current.Session["PolicyLimit"] != null && HttpContext.Current.Session["tblCasulityPolicylimit"] != null && HttpContext.Current.Session["tblAllPolicylimit"] != null)
                    {
                        AddLimitPolicy(this.policyID);
                        CacheBlank();
                        ShowAddCoverage();
                        SetAddCoverage(this.policyID);
                        HideAddCoverageAdd();
                    }
                    else
                    {

                        propertyLimits.saveLimits(policyID);

                        //casualtyLimits.saveLimits(policyID);

                    }

                    propertySubLimits.saveLimits(policyID);

                    scope.Complete();
                }

                // save policy type in viewstate
                policyType = ucPolicyType1.SelectedValue;

                // save policy id
                hf_policyID.Value = policyID.ToString();

                // activate other tabs
                tabContainerPolicy.Visible = true;

                activateLinks();

                bindLimits();

                bindClaims();

                //bindData();

                lblMessage.Text = "Policy Information saved successfully.";
                lblMessage.CssClass = "ok";

            }
            catch (Exception ex) {
                lblMessage.Text = "Policy Information was not saved.";
                lblMessage.CssClass = "error";

                Core.EmailHelper.emailError(ex);
            }
        }
Пример #7
0
        protected void copyPolicy(int sourceLeadID, int targetLeadID)
        {
            List<CRM.Data.Entities.LeadPolicy> policies = LeadPolicyManager.GetPolicies(sourceLeadID);
            if (policies != null && policies.Count > 0)
            {
                foreach (CRM.Data.Entities.LeadPolicy policy in policies)
                {
                    CRM.Data.Entities.LeadPolicy newPolicy = new CRM.Data.Entities.LeadPolicy();
                    newPolicy.LeadId = targetLeadID;

                    newPolicy.AdjusterID = policy.AdjusterID;
                    newPolicy.CarrierID = policy.CarrierID;
                    newPolicy.ClaimNumber = policy.ClaimNumber;
                    newPolicy.FaxNumber = policy.FaxNumber;
                    newPolicy.InsuranceAddress = policy.InsuranceAddress;
                    newPolicy.InsuranceCity = policy.InsuranceCity;
                    newPolicy.InsuranceCompanyName = policy.InsuranceCompanyName;
                    newPolicy.InsuranceState = policy.InsuranceState;
                    newPolicy.InsuranceZipCode = policy.InsuranceZipCode;
                    newPolicy.InsurerFileNo = policy.InsurerFileNo;
                    newPolicy.IsActive = policy.IsActive;
                    newPolicy.isAllDocumentUploaded = policy.isAllDocumentUploaded;
                    newPolicy.LastStatusUpdate = policy.LastStatusUpdate;
                    newPolicy.LeadStatus = policy.LeadStatus;
                    newPolicy.LoanNumber = policy.LoanNumber;
                    newPolicy.LossDate = policy.LossDate;
                    newPolicy.LossLocation = policy.LossLocation;
                    newPolicy.MortgageeID = policy.MortgageeID;
                    newPolicy.PhoneNumber = policy.PhoneNumber;
                    newPolicy.PolicyNumber = policy.PolicyNumber;
                    newPolicy.PolicyPeriod = policy.PolicyPeriod;
                    newPolicy.PolicyType = policy.PolicyType;
                    newPolicy.SiteInspectionCompleted = policy.SiteInspectionCompleted;
                    newPolicy.SiteSurveyDate = policy.SiteSurveyDate;
                    newPolicy.SubStatus = policy.SubStatus;

                    int newPolicyID = LeadPolicyManager.Save(newPolicy);

                    //copyCoverages(newPolicyID, policy);
                }

            }
        }
Пример #8
0
        private void saveInvoice()
        {
            string[] billToValues  = null;
            int      clientID      = 0;
            int      invoiceID     = 0;
            int      InvoiceLineID = 0;
            Invoice  invoice       = null;

            CRM.Data.Entities.LeadPolicy policy = null;
            InvoiceDetail invoiceDetailLine     = null;
            InvoiceDetail 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 Invoice();

                // get id for current lead
                invoice.ClaimID = Core.SessionHelper.getClaimID();

                invoice.IsVoid = false;

                // assign client
                //invoice.ClientID = clientID;

                // hide print button
                //btnPrint.Visible = false;
            }
            else
            {
                invoice = InvoiceManager.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 = InvoiceManager.GetNextInvoiceNumber(clientID);

                        invoice.InvoiceNumber = nextInvoiceNumber;
                    }

                    invoiceID = InvoiceManager.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 = InvoiceDetailManager.Get(InvoiceLineID);
                    }
                    else
                    {
                        invoiceDetail = new InvoiceDetail();
                    }


                    // 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
                            InvoiceDetailManager.Save(invoiceDetail);

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

                    // update invoice total after adding new detail line
                    invoice = InvoiceManager.Get(invoiceID);

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

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

                    InvoiceManager.Save(invoice);

                    // update claim diarycomment
                    updateClaimDiary(invoice, invoiceDetail);

                    // complete transaction
                    scope.Complete();
                }

                // refresh invoice detail lines
                bindInvoiceDetails(invoiceID);

                // refresh invoice number on UI
                txtInvoiceNumber.Text = (invoice.InvoiceNumber ?? 0).ToString();

                clearFields();

                showToolbarButtons();

                refreshParentWindow();
            }
            catch (Exception ex) {
                lblMessage.Text     = "Error while saving invoice.";
                lblMessage.CssClass = "error";
                Core.EmailHelper.emailError(ex);
            }
        }
Пример #9
0
        private void processClaimData()
        {
            Claim claim = null;

            CRM.Data.Entities.LeadPolicy policy = null;
            Leads lead = null;

            DataTable importTable = null;

            lblMessage.Text     = string.Empty;
            lblMessage.CssClass = string.Empty;

            // intial phase
            try {
                // load file for processing
                string filepath = Server.MapPath("~//Temp//" + ViewState["fileName"].ToString());

                // load csv file into a table
                importTable = CSVHelper.ReadCSVFile(filepath);

                // get collection of mapped fields
                mappedFields = getMappedFields();
            }
            catch (Exception ex) {
                lblMessage.Text     = "Initial phase of failed.";
                lblMessage.CssClass = "error";

                Core.EmailHelper.emailError(ex);
                return;
            }

            // second phase - process each record
            using (TransactionScope scope = new TransactionScope()) {
                try {
                    foreach (DataRow dataRow in importTable.Rows)
                    {
                        lead = createLead(dataRow);

                        if (lead == null)
                        {
                            continue;
                        }

                        policy = createPolicy(lead.LeadId, dataRow);

                        claim = createClaim(policy.Id, dataRow);
                    }

                    scope.Complete();

                    lblMessage.Text     = "Import completed successfully.";
                    lblMessage.CssClass = "ok";
                }
                catch (Exception ex) {
                    lblMessage.Text     = "Import not completed successfully.";
                    lblMessage.CssClass = "error";

                    Core.EmailHelper.emailError(ex);
                }
            }
        }
Пример #10
0
        private CRM.Data.Entities.LeadPolicy createPolicy(int leadID, DataRow dataRow)
        {
            CRM.Data.Entities.LeadPolicy policy = null;
            string userFieldName = null;

            policy = new CRM.Data.Entities.LeadPolicy();

            policy.LeadId = leadID;
            policy.IsActive = true;

            // Policy Number
            userFieldName = Core.CSVHelper.getUserFieldName(this.mappedFields, "Policy Number");
            if (!string.IsNullOrEmpty(userFieldName) && dataRow[userFieldName] != null)
                policy.PolicyNumber = dataRow[userFieldName].ToString().Trim();

            // Policy Form
            userFieldName = Core.CSVHelper.getUserFieldName(this.mappedFields, "Policy Form");
            if (!string.IsNullOrEmpty(userFieldName) && dataRow[userFieldName] != null)
                policy.PolicyFormType = dataRow[userFieldName].ToString().Trim();

            LeadPolicyManager.Save(policy);

            return policy;
        }
Пример #11
0
        private void setReminder(int leadID, CRM.Data.Entities.LeadPolicy policy, int masterStatusID)
        {
            int      lastStatusID = 0;
            double   duration     = 0;
            LeadTask task         = null;
            DateTime reminderDate = DateTime.MaxValue;
            string   sdate        = null;

            // return if no change in status
            int.TryParse(hf_lastStatusID.Value, out lastStatusID);

            if (lastStatusID == masterStatusID)
            {
                return;
            }

            // get status with reminder duration
            StatusMaster statusMaster = StatusManager.GetStatusId(masterStatusID);

            // return if master status not loaded properly
            if (statusMaster == null)
            {
                return;
            }



            // get task associated with policy
            task = TasksManager.GetPolicyReminderTask(leadID, policy.Id);

            // master status has no reminder
            if (statusMaster.ReminderMaster == null)
            {
                // delete existing reminder
                if (task != null)
                {
                    TasksManager.Delete(task.id);
                }
            }
            else
            {
                if (task == null)
                {
                    // create new reminder as task
                    task                = new LeadTask();
                    task.lead_id        = leadID;
                    task.lead_policy_id = policy.Id;
                    task.policy_type    = policy.PolicyType;
                }

                if (SessionHelper.getClientId() > 0)
                {
                    task.creator_id = SessionHelper.getClientId();
                }

                // update existing reminder
                task.master_status_id = masterStatusID;

                sdate = DateTime.Now.ToShortDateString() + " 5:00:00 AM";

                DateTime.TryParse(sdate, out reminderDate);

                // get duration from status reminder
                if (statusMaster.ReminderMaster != null)
                {
                    duration = (double)(statusMaster.ReminderMaster.Duration ?? 0);
                }

                if ((int)statusMaster.ReminderMaster.DurationType == 1)
                {
                    task.start_date = reminderDate.AddHours(duration);
                }
                else
                {
                    task.start_date = reminderDate.AddDays(duration);
                }

                task.end_date  = task.start_date;
                task.status_id = 1;
                task.text      = "Alert";
                task.isAllDay  = true;
                task.details   = statusMaster.StatusName;              // +"&lt;div&gt;Ins. Co: " + policy.InsuranceCompanyName + "&lt;/div&gt;&lt;div&gt;Pol: " + policy.PolicyNumber + "&lt;/div&gt;";
                task.owner_id  = SessionHelper.getUserId();

                TasksManager.Save(task);
            }

            // refresh tasks on parent page
            if (statusChanged != null)
            {
                statusChanged(this, null);
            }
        }
Пример #12
0
        private decimal calculateInvoiceAmount(CRM.Data.Entities.LeadPolicy policy)
        {
            string[] applicableStates = null;
            string   claimState       = null;

            CRM.Data.Entities.CarrierInvoiceProfile profile = null;
            decimal invoiceAmount   = 0;
            decimal netClaimPayable = 0;

            int profileID = Convert.ToInt32(ddlInvoiceProfile.SelectedValue);

            profile = CarrierInvoiceProfileManager.GetProfileForInvoicing(profileID, policy.ClaimDesignationID);

            if (profile != null)
            {
                // check applicable state
                if (!string.IsNullOrEmpty(profile.CoverageArea))
                {
                    applicableStates = profile.CoverageArea.Split(new char[] { ',' });

                    if (policy.Leads != null && policy.Leads.StateId != null && !applicableStates.Contains("all"))
                    {
                        claimState = policy.Leads.StateId.ToString();

                        if (!applicableStates.Contains(claimState))
                        {
                            return(0);
                        }
                    }
                }

                // determine which amount to use as base to calculate invoice amount
                if (profile.InvoiceType != null && profile.InvoiceType == 1)
                {
                    netClaimPayable = (decimal)policy.NetClaimPayable;
                }
                else if (profile.InvoiceType != null && profile.InvoiceType == 2)
                {
                    netClaimPayable = (decimal)policy.GrossLossPayable;
                }

                // apply schedule fee
                if (profile != null && profile.CarrierInvoiceProfileFeeSchedule != null && profile.CarrierInvoiceProfileFeeSchedule.Count() > 0)
                {
                    foreach (CarrierInvoiceProfileFeeSchedule schedule in profile.CarrierInvoiceProfileFeeSchedule)
                    {
                        if (netClaimPayable >= schedule.RangeAmountFrom && netClaimPayable <= schedule.RangeAmountTo)
                        {
                            if (schedule.FlatFee > 0)
                            {
                                invoiceAmount = schedule.FlatFee;
                            }
                            else if (schedule.MinimumFee > 0)
                            {
                                invoiceAmount = schedule.MinimumFee;
                            }
                            else if (schedule.PercentFee > 0)
                            {
                                invoiceAmount = netClaimPayable * schedule.PercentFee;
                            }
                        }
                    }
                }

                // apply pricing provisions
                if (profile != null && profile.CarrierInvoiceProfileFeeProvision != null && profile.CarrierInvoiceProfileFeeProvision.Count() > 0)
                {
                    foreach (CarrierInvoiceProfileFeeProvision feeProvision in profile.CarrierInvoiceProfileFeeProvision)
                    {
                        if (feeProvision.ProvisionAmount > 0)
                        {
                            invoiceAmount += feeProvision.ProvisionAmount;
                        }
                    }
                }
            }

            return(invoiceAmount);
        }
Пример #13
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string  assignmentInstructions = null;
            Carrier carrier              = null;
            bool    isSuccess            = true;
            Leads   lead                 = null;
            string  lossPerilDescription = null;

            CRM.Data.Entities.LeadPolicy policy = collectPolicyDataFromUI();
            int policyID = 0;

            lblMessage.Text = string.Empty;

            using (TransactionScope scope = new TransactionScope()) {
                try {
                    // save lead/claim
                    lead = saveLead();

                    // save carrier
                    carrier = saveCarrier();

                    // save carrier contact
                    saveContact(carrier.CarrierID);

                    // save policy
                    policy.LeadId = lead.LeadId;

                    if (carrier != null)
                    {
                        policy.CarrierID = carrier.CarrierID;
                    }

                    policyID = LeadPolicyManager.Save(policy);

                    //saveCoverages(policyID);

                    // save assingment instructions in comments
                    if (!string.IsNullOrEmpty(txtAssignmentInstructions.Text))
                    {
                        assignmentInstructions = "<div><b>Assignment Instructions</b></div><div>" + this.txtAssignmentInstructions.Text.Trim() + "</div>";
                        saveComments(assignmentInstructions, (int)policy.PolicyType, lead.LeadId);
                    }

                    // save loss Peril Description in comments
                    if (!string.IsNullOrEmpty(this.txtLossPerilDescription.Text))
                    {
                        lossPerilDescription = "<div><b>Loss/Peril Description</b></div><div>" + this.txtLossPerilDescription.Text.Trim() + "</div>";
                        saveComments(lossPerilDescription, (int)policy.PolicyType, lead.LeadId);
                    }

                    // save final comments
                    saveComments(txtComments.Text.Trim(), (int)policy.PolicyType, lead.LeadId);

                    uploadFile(fileUpload1, lead.LeadId, txtfileUpload1.Text);
                    uploadFile(fileUpload2, lead.LeadId, txtfileUpload2.Text);
                    uploadFile(fileUpload3, lead.LeadId, txtfileUpload3.Text);
                    uploadFile(fileUpload4, lead.LeadId, txtfileUpload4.Text);
                    uploadFile(fileUpload5, lead.LeadId, txtfileUpload5.Text);

                    // complete transaction and alert user
                    scope.Complete();

                    //lblMessage.Text = "Data has been submitted successfully.";
                    //lblMessage.CssClass = "ok";
                    isSuccess = true;
                }
                catch (Exception ex) {
                    lblMessage.Text     = "Unable to submit data due to error.";
                    lblMessage.CssClass = "error";

                    isSuccess = false;
                }

                // reload page
                if (isSuccess)
                {
                    Response.Redirect("~/Protected/Intake/form.aspx");
                }
            }
        }
Пример #14
0
        protected void btnAgentNewSave_Click(object sender, EventArgs e)
        {
            CRM.Data.Entities.LeadPolicy policy = null;

            Contact contact = null;

            contact          = new Contact();
            contact.ClientID = SessionHelper.getClientId();
            contact.IsActive = true;
            contact.Address1 = txtAgentAddress1.Text;
            contact.Address2 = txtAgentAddress2.Text;

            contact.CategoryID  = (int)Globals.ContactType.Agent;
            contact.CompanyName = txtAgentEntityName.Text;
            contact.ContactName = txtAgentFirstName.Text + " " + txtAgentLastName.Text;

            contact.Email     = txtAgentEmail.Text;
            contact.Fax       = txtAgentFax.Text;
            contact.FirstName = txtAgentFirstName.Text;
            contact.LastName  = txtAgentLastName.Text;

            contact.Phone = txtAgentPhoneNumber.Text;

            if (ddlState.SelectedIndex > 0)
            {
                contact.StateID = Convert.ToInt32(ddlState.SelectedValue);
            }

            if (ddlCity.SelectedIndex > 0)
            {
                contact.CityID = Convert.ToInt32(ddlCity.SelectedValue);
            }

            if (ddlAgentZip.SelectedIndex > 0)
            {
                contact.ZipCodeID = Convert.ToInt32(ddlAgentZip.SelectedValue);
            }


            try {
                using (TransactionScope scope = new TransactionScope()) {
                    contact = ContactManager.Save(contact);

                    policy = LeadPolicyManager.Get(this.policyID);

                    policy.AgentID = contact.ContactID;

                    LeadPolicyManager.Save(policy);

                    scope.Complete();
                }

                showInputFields(false);

                showLabelField(true);

                bindAgents();

                ddlAgent.SelectedValue = contact.ContactID.ToString();

                fillAgentDetails(contact.ContactID);
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);
            }
        }
Пример #15
0
        protected void UploadTemplate2()
        {
            // original format designed by Vivek
            lblSave.Text = string.Empty;
            lblSave.Visible = false;
            lblError.Text = string.Empty;
            lblError.Visible = false;
            lblMessage.Text = string.Empty;
            lblMessage.Visible = false;
            // 2013-02-09 tortega -- Added data validation prior to import. File is not aborted in the event of incorrect data.
            string str = null;
            int fileLineNumber = 0;
            int clientID = Core.SessionHelper.getClientId();

            // assume homeowner
            int policyType = 1;
            DateTime DateSubmitted = DateTime.Now;
            DateTime ContractDate = DateTime.Now;

            string columnValue = null;
            Mortgagee mortgagee = null;

            StatusMaster statusMaster = null;
            string statusName = null;

            try {
                if (FileUpload1.HasFile) {

                    string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);
                    string ActualFileName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(@"\") + 1);
                    string FileNameWithoutExt = ActualFileName.Replace(ext, "");
                    if (ext == ".csv") {

                        if (!Directory.Exists(Server.MapPath("~//CSVLoad//"))) {
                            Directory.CreateDirectory(Server.MapPath("~//CSVLoad//"));
                        }
                        FileUpload1.SaveAs(Server.MapPath("~//CSVLoad//" + FileUpload1.FileName));
                        DataTable table = CSVReader.ReadCSVFile(Server.MapPath("~//CSVLoad//" + FileUpload1.FileName), true);
                        using (TransactionScope scope = new TransactionScope()) {
                            Leads objLead = null;

                            for (int i = 0; i < table.Rows.Count; i++) {
                                fileLineNumber = i;

                                objLead = new Leads();

                                //objLead.LeadStatus = 1;	// active
                                objLead.OriginalLeadDate = DateTime.Now;
                                objLead.TypeOfProperty = 18;	//residential
                                objLead.UserId = Convert.ToInt32(Session["UserId"]);

                                try {

                                    if (columnExists(table, "Create Date") && table.Rows[i]["Create Date"] != string.Empty) {

                                        DateTime.TryParse(table.Rows[i]["Create Date"].ToString(), out DateSubmitted);

                                        objLead.DateSubmitted = DateSubmitted;

                                        objLead.OriginalLeadDate = DateSubmitted;
                                    }

                                    if (columnExists(table, "Last Name") && table.Rows[i]["Last Name"] != string.Empty) {
                                        str = table.Rows[i]["Last Name"].ToString();
                                        if (str.Length > 50) {
                                            objLead.ClaimantLastName = str.Substring(0, 50);
                                            objLead.OwnerLastName = objLead.ClaimantLastName;
                                        }
                                        else {
                                            objLead.ClaimantLastName = str;
                                            objLead.OwnerLastName = str;
                                        }
                                    }

                                    if (columnExists(table, "First Name") && table.Rows[i]["First Name"] != string.Empty) {
                                        str = table.Rows[i]["First Name"].ToString();
                                        if (str.Length > 50) {
                                            objLead.ClaimantFirstName = str.Substring(0, 50);
                                            objLead.OwnerFirstName = objLead.ClaimantFirstName;
                                        }
                                        else {
                                            objLead.ClaimantFirstName = str;
                                            objLead.OwnerFirstName = str;
                                        }
                                    }

                                    if (columnExists(table, "Middle Name") && table.Rows[i]["Middle Name"] != string.Empty) {
                                        str = table.Rows[i]["Middle Name"].ToString();
                                        if (str.Length > 50) {
                                            objLead.ClaimantMiddleName = str.Substring(0, 50);
                                        }
                                        else {
                                            objLead.ClaimantMiddleName = str;
                                        }
                                    }

                                    if (columnExists(table, "E-mail") && table.Rows[i]["E-mail"] != string.Empty) {
                                        str = table.Rows[i]["E-mail"].ToString();
                                        if (str.Length > 100)
                                            objLead.EmailAddress = str.Substring(0, 100);
                                        else
                                            objLead.EmailAddress = str;
                                    }
                                    if (columnExists(table, "Personal E-mail") && table.Rows[i]["Personal E-mail"] != string.Empty) {
                                        str = table.Rows[i]["Personal E-mail"].ToString();
                                        if (str.Length > 100)
                                            objLead.SecondaryEmail = str.Substring(0, 100);
                                        else
                                            objLead.SecondaryEmail = str;
                                    }

                                    if (columnExists(table, "Mobile Phone") && table.Rows[i]["Mobile Phone"] != string.Empty) {
                                        str = table.Rows[i]["Mobile Phone"].ToString();
                                        if (str.Length > 20)
                                            objLead.SecondaryPhone = str.Substring(0, 20);
                                        else
                                            objLead.SecondaryPhone = str;
                                    }

                                    if (columnExists(table, "Salutation") && table.Rows[i]["Salutation"] != string.Empty) {
                                        str = table.Rows[i]["Salutation"].ToString();
                                        if (str.Length > 50)
                                            objLead.Salutation = str.Substring(0, 20);
                                        else
                                            objLead.Salutation = str;
                                    }
                                }
                                catch (Exception ex) {
                                    lblError.Text = "There Is a problem in  data save  !!!";
                                    lblError.Visible = true;

                                    Core.EmailHelper.emailError(ex);

                                    throw new Exception(ex.Message);
                                }

                                string adjusterName = null;
                                int? adjusterID = null;
                                AdjusterMaster adjuster = null;

                                if (columnExists(table, "Adjuster Name") && table.Rows[i]["Adjuster Name"] != string.Empty)
                                    adjusterName = table.Rows[i]["Adjuster Name"].ToString();

                                string adjusterEmail = null;
                                string adjusterFax = null;
                                string AdjusterPhone = null;
                                string AdjusterCo = null;
                                string AdjusterAddress = null;

                                if (columnExists(table, "Adjuster Email") && table.Rows[i]["Adjuster Email"] != string.Empty)
                                    adjusterEmail = table.Rows[i]["Adjuster Email"].ToString();

                                if (columnExists(table, "Adjuster Fax") && table.Rows[i]["Adjuster Fax"] != string.Empty)
                                    adjusterFax = table.Rows[i]["Adjuster Fax"].ToString();

                                if (columnExists(table, "Adjuster Phone") && table.Rows[i]["Adjuster Phone"] != string.Empty)
                                    AdjusterPhone = table.Rows[i]["Adjuster Phone"].ToString();

                                if (columnExists(table, "Adjuster Co") && table.Rows[i]["Adjuster Co"] != string.Empty)
                                    AdjusterCo = table.Rows[i]["Adjuster Co"].ToString();

                                if (columnExists(table, "Adj Address") && table.Rows[i]["Adj Address"] != string.Empty)
                                    AdjusterAddress = table.Rows[i]["Adj Address"].ToString();

                                if (!string.IsNullOrEmpty(adjusterName)) {
                                    adjuster = AdjusterManager.GetByAdjusterName(adjusterName.Trim());
                                    if (adjuster.AdjusterId == 0) {
                                        // add adjuster
                                        adjuster = new AdjusterMaster();
                                        adjuster.Status = true;
                                        adjuster.AdjusterName = adjusterName.Trim();
                                        adjuster.ClientId = clientID;
                                        adjuster.InsertBy = objLead.UserId;
                                        adjuster.InsertDate = DateTime.Now;
                                        adjuster.isEmailNotification = true;
                                        adjuster.email = adjusterEmail;
                                        adjuster.Address1 = AdjusterAddress;
                                        adjuster.PhoneNumber = AdjusterPhone;
                                        adjuster.FaxNumber = adjusterFax;
                                        adjuster.CompanyName = AdjusterCo;
                                        adjuster = AdjusterManager.Save(adjuster);
                                    }

                                    adjusterID = adjuster.AdjusterId;
                                }

                                if (columnExists(table, "ExaminerName") && table.Rows[i]["ExaminerName"] != string.Empty) {
                                    InspectorMaster inspector = InspectorManager.GetByName(table.Rows[i]["ExaminerName"].ToString());
                                    if (inspector.InspectorId > 0) {
                                        objLead.InspectorName = inspector.InspectorId;
                                    }

                                }

                                //if (columnExists(table, "Loss Location") && table.Rows[i]["Loss Location"] != string.Empty)
                                //     objLead.LossLocation = table.Rows[i]["Loss Location"].ToString();

                                //if (columnExists(table, "Date of Loss") && table.Rows[i]["Date of Loss"] != string.Empty) {
                                //     DateTime lossDate = DateTime.MinValue;
                                //     if (DateTime.TryParse(table.Rows[i]["Date of Loss"].ToString(), out lossDate))
                                //          objLead.LossDate = lossDate;
                                //}

                                if (columnExists(table, "Contract Signed Date") && table.Rows[i]["Contract Signed Date"] != string.Empty)
                                    objLead.ContractDate = Convert.ToDateTime(table.Rows[i]["Contract Signed Date"].ToString());

                                if (columnExists(table, "Address 1") && table.Rows[i]["Address 1"] != string.Empty) {
                                    str = table.Rows[i]["Address 1"].ToString();

                                    if (str.Length > 100)
                                        objLead.MailingAddress = str.Substring(0, 99);
                                    else
                                        objLead.LossAddress = str.ToString();
                                }

                                try {

                                    if (columnExists(table, "City") && table.Rows[i]["City"] != string.Empty)
                                        objLead.MailingCity = table.Rows[i]["City"].ToString();

                                    if (columnExists(table, "State") && table.Rows[i]["State"] != string.Empty)
                                        objLead.MailingState = table.Rows[i]["State"].ToString();

                                    if (columnExists(table, "ZIP Code") && table.Rows[i]["ZIP Code"] != string.Empty)
                                        objLead.MailingZip = table.Rows[i]["ZIP Code"].ToString();

                                    if (columnExists(table, "Business Name") && table.Rows[i]["Business Name"] != string.Empty)
                                        objLead.BusinessName = table.Rows[i]["Business Name"].ToString();

                                    if (columnExists(table, "Adjuster Name") && table.Rows[i]["Adjuster Name"] != string.Empty)
                                        adjusterName = table.Rows[i]["Adjuster Name"].ToString();

                                    if (columnExists(table, "Phone") && table.Rows[i]["Phone"] != string.Empty) {
                                        str = table.Rows[i]["Phone"].ToString();
                                        if (str.Length > 20)
                                            objLead.PhoneNumber = str.Substring(0, 20);
                                        else
                                            objLead.PhoneNumber = str.ToString();
                                    }

                                    if (columnExists(table, "Loss Address") && table.Rows[i]["Loss Address"] != string.Empty) {
                                        str = table.Rows[i]["Loss Address"].ToString();

                                        if (str.Length > 100)
                                            objLead.LossAddress = str.Substring(0, 99);
                                        else
                                            objLead.LossAddress = str.ToString();
                                    }
                                    if (columnExists(table, "Loss City") && table.Rows[i]["Loss City"] != string.Empty)
                                        objLead.CityName = table.Rows[i]["Loss City"].ToString();

                                    if (columnExists(table, "Loss State") && table.Rows[i]["Loss State"] != string.Empty)
                                        objLead.StateName = table.Rows[i]["Loss State"].ToString();

                                    if (columnExists(table, "Loss Zip Code") && table.Rows[i]["Loss Zip Code"] != string.Empty) {
                                        str = table.Rows[i]["Loss Zip Code"].ToString();
                                        if (str.Length < 5)
                                            str = "0" + str;

                                        objLead.Zip = str;
                                    }

                                    if (columnExists(table, "Fax") && table.Rows[i]["Fax"] != string.Empty) {
                                        str = table.Rows[i]["Fax"].ToString();
                                        if (str.Length > 20)
                                            objLead.SecondaryPhone = str.Substring(0, 20);
                                        else
                                            objLead.SecondaryPhone = str.ToString();
                                    }

                                    if (columnExists(table, "File Status") && table.Rows[i]["File Status"] != string.Empty) {
                                        statusName = table.Rows[i]["File Status"].ToString();
                                        statusMaster = StatusManager.GetByStatusName(statusName);

                                        if (statusMaster.StatusId == 0) {
                                            statusMaster = new StatusMaster();
                                            statusMaster.clientID = clientID;
                                            statusMaster.InsertBy = objLead.UserId;
                                            statusMaster.InsertDate = DateTime.Now;
                                            statusMaster.isCountable = true;
                                            statusMaster.Status = true;
                                            statusMaster.StatusName = statusName;

                                            statusMaster = StatusManager.Save(statusMaster);
                                        }
                                    }
                                }
                                catch (Exception ex) {
                                    lblError.Text = "There Is a problem in  data save  !!!";
                                    lblError.Visible = true;

                                    Core.EmailHelper.emailError(ex);

                                    throw new Exception(ex.Message);
                                }

                                if (columnExists(table, "Peril") && !string.IsNullOrEmpty(table.Rows[i]["Peril"].ToString())) {
                                    var id = TypeofDamageManager.getbyTypeOfDamage(table.Rows[i]["Peril"].ToString());
                                    if (id.TypeOfDamageId > 0)
                                        objLead.TypeOfDamage = id.TypeOfDamageId.ToString() + ",";

                                    //string dmgid = string.Empty;
                                    //string[] dmg = table.Rows[i]["Type of Damage"].ToString().Split(',');
                                    //for (int d = 0; d < dmg.Length; d++) {
                                    //     string dmgtext = dmg[d];
                                    //     var dmgdata = TypeofDamageManager.getbyTypeOfDamage(dmgtext);
                                    //     if (dmgdata != null && dmgdata.TypeOfDamage != null && dmgdata.TypeOfDamage.ToString() != string.Empty) {
                                    //          dmgid += dmgdata.TypeOfDamageId + ",";
                                    //     }
                                    //     else {
                                    //          TypeOfDamageMaster objdmg = new TypeOfDamageMaster();
                                    //          objdmg.TypeOfDamage = dmgtext.Length > 100 ? dmgtext.Substring(0, 100) : dmgtext;
                                    //          objdmg.Status = true;
                                    //          TypeOfDamageMaster sv = TypeofDamageManager.Save(objdmg);
                                    //          dmgid += sv.TypeOfDamageId + ",";
                                    //     }
                                    //}

                                    //objLead.TypeOfDamage = dmgid;

                                    str = table.Rows[i]["Peril"].ToString();
                                    if (str.Length > 250)
                                        objLead.TypeofDamageText = str.Substring(0, 250).Replace("/", ",");
                                    else
                                        objLead.TypeofDamageText = str.Replace("/", ",");
                                }

                                objLead.Status = 1;

                                // 2013-08-29 tortega
                                if (clientID > 0)
                                    objLead.ClientID = clientID;

                                Leads newLead = LeadsManager.Save(objLead);
                                int policyTypeID = 1;

                                if (newLead != null) {
                                    // add policy
                                    CRM.Data.Entities.LeadPolicy policy = new CRM.Data.Entities.LeadPolicy();

                                    if (columnExists(table, "PolicyType") && table.Rows[i]["PolicyType"] != string.Empty) {
                                        policyTypeID = getPolicyType(table.Rows[i]["PolicyType"].ToString());

                                    }

                                    policy.PolicyType = policyTypeID;

                                    policy.LeadId = newLead.LeadId;
                                    policy.IsActive = true;
                                    policy.isAllDocumentUploaded = false;

                                    if (adjusterID != null)
                                        policy.AdjusterID = adjusterID;

                                    if (columnExists(table, "LoanID") && table.Rows[i]["LoanID"] != string.Empty) {
                                        str = table.Rows[i]["LoanID"].ToString();

                                        if (str.Length > 50)
                                            policy.LoanNumber = str.Substring(0, 50);
                                        else
                                            policy.LoanNumber = str;
                                    }

                                    if (columnExists(table, "DateOfEvaluation") && table.Rows[i]["DateOfEvaluation"] != string.Empty) {
                                        DateTime SiteSurveyDate = DateTime.MinValue;
                                        if (DateTime.TryParse(table.Rows[i]["DateOfEvaluation"].ToString(), out SiteSurveyDate))
                                            policy.SiteSurveyDate = SiteSurveyDate;
                                    }

                                    if (columnExists(table, "Mortgagee") && table.Rows[i]["Mortgagee"] != string.Empty) {
                                        int id = getMortgageeID(table.Rows[i]["Mortgagee"].ToString(), clientID);
                                        if (id > 0)
                                            policy.MortgageeID = id;
                                        else {
                                            mortgagee = new Mortgagee();
                                            mortgagee.ClientID = clientID;
                                            mortgagee.Status = true;
                                            mortgagee.MortageeName = table.Rows[i]["Mortgagee"].ToString();

                                            mortgagee = MortgageeManager.Save(mortgagee);
                                            if (mortgagee.MortgageeID > 0)
                                                policy.MortgageeID = mortgagee.MortgageeID;
                                        }
                                    }

                                    if (columnExists(table, "Loss Location") && table.Rows[i]["Loss Location"] != string.Empty)
                                        policy.LossLocation = table.Rows[i]["Loss Location"].ToString();

                                    if (columnExists(table, "Date of Loss") && table.Rows[i]["Date of Loss"] != string.Empty) {
                                        DateTime lossDate = DateTime.MinValue;
                                        if (DateTime.TryParse(table.Rows[i]["Date of Loss"].ToString(), out lossDate))
                                            policy.LossDate = lossDate;
                                    }

                                    if (columnExists(table, "Policy Period") && table.Rows[i]["Policy Period"] != string.Empty)
                                        policy.PolicyPeriod = table.Rows[i]["Policy Period"].ToString();

                                    string PolicyExpirationDate = null;
                                    if (columnExists(table, "PolicyExpirationDate") && table.Rows[i]["PolicyExpirationDate"] != string.Empty)
                                        PolicyExpirationDate = table.Rows[i]["PolicyExpirationDate"].ToString();

                                    string effectiveDate = null;
                                    if (columnExists(table, "PolicyEffectiveDate") && table.Rows[i]["PolicyEffectiveDate"] != string.Empty)
                                        effectiveDate = table.Rows[i]["PolicyEffectiveDate"].ToString();

                                    str = string.Format("{0} - {1}", effectiveDate ?? "N/A", PolicyExpirationDate ?? "N/A");
                                    if (str.Length > 50)
                                        policy.PolicyPeriod = str.Substring(0, 50);
                                    else
                                        policy.PolicyPeriod = str;

                                    if (columnExists(table, "Claim Number") && table.Rows[i]["Claim Number"] != string.Empty) {
                                        str = table.Rows[i]["Claim Number"].ToString();
                                        if (str.Length > 50)
                                            policy.ClaimNumber = str.Substring(0, 50);
                                        else
                                            policy.ClaimNumber = str;
                                    }

                                    if (columnExists(table, "Policy Number") && table.Rows[i]["Policy Number"] != string.Empty) {
                                        str = table.Rows[i]["Policy Number"].ToString();
                                        if (str.Length > 100)
                                            policy.PolicyNumber = str.Substring(0, 100);
                                        else
                                            policy.PolicyNumber = str;
                                    }

                                    if (columnExists(table, "File Number") && table.Rows[i]["File Number"] != string.Empty) {
                                        str = table.Rows[i]["File Number"].ToString();
                                        if (str.Length > 20)
                                            policy.InsurerFileNo = str.Substring(0, 20);
                                        else
                                            policy.InsurerFileNo = str;
                                    }

                                    if (statusMaster != null)
                                        policy.LeadStatus = statusMaster.StatusId;

                                    if (columnExists(table, "Ins Carrier") && table.Rows[i]["Ins Carrier"] != string.Empty) {
                                        str = table.Rows[i]["Ins Carrier"].ToString();
                                        if (str.Length > 50)
                                            policy.InsuranceCompanyName = str.Substring(0, 50);
                                        else
                                            policy.InsuranceCompanyName = str;
                                    }

                                    if (columnExists(table, "Ins Co Address") && table.Rows[i]["Ins Co Address"] != string.Empty) {
                                        str = table.Rows[i]["Ins Co Address"].ToString();
                                        if (str.Length > 50)
                                            policy.InsuranceAddress = str.Substring(0, 50);
                                        else
                                            policy.InsuranceAddress = str;

                                    }

                                    if (columnExists(table, "Ins Co City") && table.Rows[i]["Ins Co City"] != string.Empty) {
                                        string cityName = table.Rows[i]["Ins Co City"].ToString();
                                        CityMaster cityMaster = City.GetByCityName(cityName);
                                        if (cityMaster != null && cityMaster.CityId > 0)
                                            policy.InsuranceCity = cityMaster.CityId;
                                    }

                                    if (columnExists(table, "Ins Co State") && table.Rows[i]["Ins Co State"] != string.Empty) {
                                        string stateName = table.Rows[i]["Ins Co State"].ToString();
                                        StateMaster stateMaster = State.Getstateid(stateName);
                                        if (stateMaster != null && stateMaster.StateId > 0)
                                            policy.InsuranceState = stateMaster.StateId;
                                    }

                                    if (columnExists(table, "Ins Co Zip") && table.Rows[i]["Ins Co Zip"] != string.Empty) {
                                        string zipCode = table.Rows[i]["Ins Co Zip"].ToString();
                                        ZipCodeMaster zipMaster = ZipCode.GetByZipCode(zipCode);
                                        if (zipMaster != null && zipMaster.ZipCodeID > 0)
                                            policy.InsuranceZipCode = zipMaster.ZipCodeID.ToString();
                                    }

                                    LeadPolicyManager.Save(policy);

                                    // add policy comments
                                    if (columnExists(table, "Notes") && table.Rows[i]["Notes"] != string.Empty) {
                                        char[] splitTokens = { '\n' };

                                        string[] lines = table.Rows[i]["Notes"].ToString().Split(splitTokens, StringSplitOptions.RemoveEmptyEntries);
                                        if (lines != null && lines.Length > 0)
                                            foreach (string line in lines) {

                                                string[] datetimeValues = line.Split(new char[] { ' ' });
                                                if (datetimeValues.Length > 3) {
                                                    string datetime = string.Format("{0} {1} {2}", datetimeValues[0] ?? "", datetimeValues[1] ?? "", datetimeValues[2] ?? "");
                                                    DateTime commentInsertDate = DateTime.Now;
                                                    if (DateTime.TryParse(datetime, out commentInsertDate))
                                                        AddComments(newLead.LeadId, policyTypeID, line, commentInsertDate);
                                                    else
                                                        AddComments(newLead.LeadId, policyTypeID, line);

                                                }
                                                else
                                                    AddComments(newLead.LeadId, policyTypeID, line);
                                            }
                                        //AddComments(newLead.LeadId, policyTypeID, table.Rows[i]["Notes"].ToString().Replace("\n","<br/>");
                                    }

                                    if (columnExists(table, "Certified Mail Number") && table.Rows[i]["Certified Mail Number"] != string.Empty)
                                        AddComments(newLead.LeadId, policyTypeID, "Certified Mail Number: " + table.Rows[i]["Certified Mail Number"].ToString());

                                    //if (columnExists(table, "Contract Signed Date") && table.Rows[i]["Contract Signed Date"] != string.Empty)
                                    //     AddComments(newLead.LeadId, policyTypeID, "Contract Signed Date: " + table.Rows[i]["Contract Signed Date"].ToString());

                                    if (columnExists(table, "Last E-mail") && table.Rows[i]["Last E-mail"] != string.Empty)
                                        AddComments(newLead.LeadId, policyTypeID, "Last E-mail Date: " + table.Rows[i]["Last E-mail"].ToString());

                                    if (columnExists(table, "Last Meeting") && table.Rows[i]["Last Meeting"] != string.Empty)
                                        AddComments(newLead.LeadId, policyTypeID, "Last Meeting Date: " + table.Rows[i]["Last Meeting"].ToString());

                                    if (columnExists(table, "Letter Date") && table.Rows[i]["Letter Date"] != string.Empty)
                                        AddComments(newLead.LeadId, policyTypeID, "Letter Date: " + table.Rows[i]["Letter Date"].ToString());
                                }

                            }	//for (int i = 0; i < table.Rows.Count; i++) {

                            scope.Complete();

                        }
                        string rootFolderPath = Server.MapPath("~//CSVLoad//");
                        string filesToDelete = FileUpload1.FileName;
                        string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
                        foreach (string file in fileList) {
                            System.IO.File.Delete(file);
                        }
                        lblSave.Text = "Data Saved Successfully !!!";
                        lblSave.Visible = true;
                    }
                }
            }
            catch (Exception ex) {
                lblError.Text = "There Is a problem in  data save  !!!";
                lblError.Visible = true;
            }
        }
Пример #16
0
        protected void UploadTemplate1()
        {
            // original format designed by Vivek
            int adjusterID = 0;
            lblSave.Text = string.Empty;
            lblSave.Visible = false;
            lblError.Text = string.Empty;
            lblError.Visible = false;
            lblMessage.Text = string.Empty;
            lblMessage.Visible = false;
            // 2013-02-09 tortega -- Added data validation prior to import. File is not aborted in the event of incorrect data.
            string str = null;

            int clientID = Core.SessionHelper.getClientId();

            // assume homeowner
            int policyType = 1;
            DateTime DateSubmitted = DateTime.Now;

            try {
                if (FileUpload1.HasFile) {

                    string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);
                    string ActualFileName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(@"\") + 1);
                    string FileNameWithoutExt = ActualFileName.Replace(ext, "");
                    if (ext == ".csv") {

                        if (!Directory.Exists(Server.MapPath("~//CSVLoad//"))) {
                            Directory.CreateDirectory(Server.MapPath("~//CSVLoad//"));
                        }
                        FileUpload1.SaveAs(Server.MapPath("~//CSVLoad//" + FileUpload1.FileName));
                        DataTable table = CSVReader.ReadCSVFile(Server.MapPath("~//CSVLoad//" + FileUpload1.FileName), true);
                        using (TransactionScope scope = new TransactionScope()) {
                            Leads objLead = null;
                            for (int i = 0; i < table.Rows.Count; i++) {

                                objLead = new Leads();

                                objLead.OriginalLeadDate = DateTime.Now;
                                objLead.UserId = Convert.ToInt32(Session["UserId"]);

                                if (table.Rows[i]["DateSubmitted"] != string.Empty) {

                                    DateTime.TryParse(table.Rows[i]["DateSubmitted"].ToString(), out DateSubmitted);

                                    objLead.DateSubmitted = DateSubmitted;
                                }

                                str = table.Rows[i]["LFUUID"].ToString();
                                if (str.Length > 50)
                                    objLead.LFUUID = table.Rows[i]["LFUUID"].ToString().Substring(0, 50);
                                else
                                    objLead.LFUUID = table.Rows[i]["LFUUID"].ToString();

                                if (table.Rows[i]["Original Lead Date"] != string.Empty) {
                                    objLead.OriginalLeadDate = Convert.ToDateTime(table.Rows[i]["Original Lead Date"]);
                                }

                                if (table.Rows[i]["Last Name"] != string.Empty) {
                                    str = table.Rows[i]["Last Name"].ToString();
                                    if (str.Length > 50)
                                        objLead.ClaimantLastName = table.Rows[i]["Last Name"].ToString().Substring(0, 50);
                                    else
                                        objLead.ClaimantLastName = table.Rows[i]["Last Name"].ToString();
                                }

                                if (table.Rows[i]["First Name"] != string.Empty) {
                                    str = table.Rows[i]["First Name"].ToString();
                                    if (str.Length > 50)
                                        objLead.ClaimantFirstName = table.Rows[i]["First Name"].ToString().Substring(0, 50);
                                    else
                                        objLead.ClaimantFirstName = table.Rows[i]["First Name"].ToString();
                                }

                                if (table.Rows[i]["Email Address"] != string.Empty) {
                                    str = table.Rows[i]["Email Address"].ToString();
                                    if (str.Length > 100)
                                        objLead.EmailAddress = str.Substring(0, 100);
                                    else
                                        objLead.EmailAddress = str;
                                }
                                if (table.Rows[i]["Secondary Email"] != string.Empty) {
                                    str = table.Rows[i]["Secondary Email"].ToString();
                                    if (str.Length > 100)
                                        objLead.SecondaryEmail = str.Substring(0, 100);
                                    else
                                        objLead.SecondaryEmail = str;
                                }

                                if (table.Rows[i]["Adjuster"] != string.Empty) {
                                    string adjusterName = table.Rows[i]["Adjuster"].ToString();
                                    AdjusterMaster adjuster = null;

                                    if (!string.IsNullOrEmpty(adjusterName)) {
                                        adjuster = AdjusterManager.GetByAdjusterName(adjusterName.Trim());
                                        if (adjuster.AdjusterId == 0) {
                                            // add adjuster
                                            adjuster = new AdjusterMaster();
                                            adjuster.Status = true;
                                            adjuster.AdjusterName = adjusterName.Trim();
                                            adjuster.ClientId = clientID;
                                            adjuster.InsertBy = objLead.UserId;
                                            adjuster.InsertDate = DateTime.Now;
                                            adjuster.isEmailNotification = true;

                                            adjuster = AdjusterManager.Save(adjuster);
                                        }

                                        adjusterID = adjuster.AdjusterId;
                                    }

                                }
                                if (table.Rows[i]["Lead Source"] != string.Empty) {

                                    string sourceName = table.Rows[i]["Lead Source"].ToString();

                                    var id = LeadSourceManager.GetByLeadSourceName(sourceName);
                                    if (id.LeadSourceId > 0)
                                        objLead.LeadSource = id.LeadSourceId;
                                    else {
                                        // add source
                                        LeadSourceMaster leadSource = new LeadSourceMaster();
                                        if (clientID > 0)
                                            leadSource.ClientId = clientID;

                                        leadSource.InsertBy = Core.SessionHelper.getUserId();
                                        leadSource.InsertDate = DateTime.Now;
                                        leadSource.LeadSourceName = sourceName.Length > 100 ? sourceName.Substring(0, 100) : sourceName;
                                        leadSource.Status = true;

                                        LeadSourceMaster newLeadSource = LeadSourceManager.Save(leadSource);

                                        objLead.LeadSource = newLeadSource.LeadSourceId;
                                    }
                                }
                                if (table.Rows[i]["Primary Producer"] != string.Empty) {
                                    var id = ProducerManager.GetByProducerName(table.Rows[i]["Primary Producer"].ToString());
                                    if (id != null && id.ProducerId > 0)
                                        objLead.PrimaryProducerId = id.ProducerId;
                                    else {
                                        ProducerMaster producer = AddProducer(objLead, table.Rows[i]["Primary Producer"].ToString());
                                        objLead.PrimaryProducerId = producer.ProducerId;
                                    }
                                }
                                if (table.Rows[i]["Secondary Producer"] != string.Empty) {
                                    var id = SecondaryProducerManager.GetBySecondaryProducerName(table.Rows[i]["Secondary Producer"].ToString());
                                    if (id != null && id.SecondaryProduceId > 0)
                                        objLead.SecondaryProducerId = id.SecondaryProduceId;
                                    else {
                                        ProducerMaster producer = AddProducer(objLead, table.Rows[i]["Secondary Producer"].ToString());
                                        objLead.SecondaryProducerId = producer.ProducerId;
                                    }
                                }
                                if (table.Rows[i]["Inspector Name"] != string.Empty) {
                                    var id = InspectorManager.GetByName(table.Rows[i]["Inspector Name"].ToString());
                                    if (id != null && id.InspectorId > 0)
                                        objLead.InspectorName = id.InspectorId;
                                    else {
                                        InspectorMaster inspector = AddInspector(objLead, table.Rows[i]["Inspector Name"].ToString());
                                        objLead.InspectorName = inspector.InspectorId;
                                    }
                                }
                                if (table.Rows[i]["Inspector Cell"] != string.Empty) {
                                    str = table.Rows[i]["Inspector Cell"].ToString();
                                    if (str.Length > 20)
                                        str = objLead.InspectorCell = table.Rows[i]["Inspector Cell"].ToString().Substring(0, 20);
                                    else
                                        objLead.InspectorCell = table.Rows[i]["Inspector Cell"].ToString();
                                }
                                if (table.Rows[i]["Inspector Email"] != string.Empty) {
                                    str = table.Rows[i]["Inspector Email"].ToString(); ;
                                    if (str.Length > 100)
                                        objLead.InspectorEmail = table.Rows[i]["Inspector Email"].ToString().Substring(0, 100);
                                    else
                                        objLead.InspectorEmail = table.Rows[i]["Inspector Email"].ToString();
                                }

                                if (table.Rows[i]["Phone Number"] != string.Empty) {
                                    str = table.Rows[i]["Phone Number"].ToString();
                                    if (str.Length > 20)
                                        objLead.PhoneNumber = table.Rows[i]["Phone Number"].ToString().Substring(0, 20);
                                    else
                                        objLead.PhoneNumber = table.Rows[i]["Phone Number"].ToString();
                                }
                                if (table.Rows[i]["Secondary Phone"] != string.Empty) {
                                    str = table.Rows[i]["Secondary Phone"].ToString();
                                    if (str.Length > 20)
                                        objLead.SecondaryPhone = str.Substring(0, 20);
                                    else
                                        objLead.SecondaryPhone = str;
                                }
                                //if (table.Rows[i]["Webform Source"] != string.Empty) {
                                //	//objLead.WebformSource = table.Rows[i]["Webform Source"].ToString();
                                //	var id = WebFormSourceManager.GetByName(table.Rows[i]["Webform Source"].ToString());

                                //	if (id != null && id.WebformSourceId > 0)
                                //		objLead.WebformSource = id.WebformSourceId;
                                //}

                                if (!string.IsNullOrEmpty(table.Rows[i]["Type of Damage"].ToString())) {
                                    //objLead.TypeOfDamage = table.Rows[i]["Type of Damage"].ToString();
                                    var id = TypeofDamageManager.getbyTypeOfDamage(table.Rows[i]["Type of Damage"].ToString());
                                    objLead.TypeOfDamage = id.TypeOfDamage;

                                    //string dmgid = string.Empty;
                                    //string[] dmg = table.Rows[i]["Type of Damage"].ToString().Split(',');
                                    //for (int d = 0; d < dmg.Length; d++) {
                                    //     string dmgtext = dmg[d];
                                    //     var dmgdata = TypeofDamageManager.getbyTypeOfDamage(dmgtext);
                                    //     if (dmgdata != null && dmgdata.TypeOfDamage != null && dmgdata.TypeOfDamage.ToString() != string.Empty) {
                                    //          dmgid += dmgdata.TypeOfDamageId + ",";
                                    //     }
                                    //     else {
                                    //          TypeOfDamageMaster objdmg = new TypeOfDamageMaster();
                                    //          objdmg.TypeOfDamage = dmgtext.Length > 100 ? dmgtext.Substring(0, 100) : dmgtext;
                                    //          objdmg.Status = true;
                                    //          TypeOfDamageMaster sv = TypeofDamageManager.Save(objdmg);
                                    //          dmgid += sv.TypeOfDamageId + ",";
                                    //     }
                                    //}

                                    //objLead.TypeOfDamage = dmgid;

                                    str = table.Rows[i]["Type of Damage"].ToString();
                                    if (str.Length > 250)
                                        objLead.TypeofDamageText = table.Rows[i]["Type of Damage"].ToString().Substring(0, 250);
                                    else
                                        objLead.TypeofDamageText = table.Rows[i]["Type of Damage"].ToString();

                                    //string Damagetxt = string.Empty;
                                    //string DamageId = string.Empty;
                                    //for (int j = 0; j < chkTypeOfDamage.Items.Count; j++)
                                    //{
                                    //    if (chkTypeOfDamage.Items[j].Selected == true)
                                    //    {
                                    //        Damagetxt += chkTypeOfDamage.Items[j].Text + ',';
                                    //        DamageId += chkTypeOfDamage.Items[j].Value + ',';
                                    //    }
                                    //}
                                }
                                if (!string.IsNullOrEmpty(table.Rows[i]["Type of Property"].ToString())) {
                                    var id = PropertyTypeManager.GetByPropertyName(table.Rows[i]["Type of Property"].ToString());

                                    if (id != null && id.TypeOfPropertyId > 0) {
                                        objLead.TypeOfProperty = id.TypeOfPropertyId;

                                        if (id.TypeOfProperty.Contains("Home"))
                                            policyType = 1;

                                        if (id.TypeOfProperty.Contains("Commercial"))
                                            policyType = 2;

                                        if (id.TypeOfProperty.Contains("Flood"))
                                            policyType = 3;

                                        if (id.TypeOfProperty.Contains("Earthquake"))
                                            policyType = 4;
                                    }
                                }
                                if (table.Rows[i]["Market Value"] != string.Empty) {
                                    decimal MarketValue = 0;
                                    decimal.TryParse(table.Rows[i]["Market Value"].ToString(), out MarketValue);

                                    objLead.MarketValue = MarketValue;	//Convert.ToDecimal(table.Rows[i]["Market Value"]);
                                }
                                if (table.Rows[i]["Loss Address"] != string.Empty) {
                                    str = table.Rows[i]["Loss Address"].ToString();
                                    if (str.Length > 100)
                                        objLead.LossAddress = str.Substring(0, 100);
                                    else
                                        objLead.LossAddress = str;
                                }

                                if (table.Rows[i]["City"] != string.Empty)
                                    objLead.CityName = table.Rows[i]["City"].ToString();

                                if (table.Rows[i]["State"] != string.Empty)
                                    objLead.StateName = table.Rows[i]["State"].ToString();

                                if (table.Rows[i]["Zip"] != string.Empty)
                                    objLead.Zip = table.Rows[i]["Zip"].ToString();

                                if (table.Rows[i]["Property Damage Estimate"] != string.Empty) {
                                    decimal PropertyDamageEstimate = 0;
                                    decimal.TryParse(table.Rows[i]["Property Damage Estimate"].ToString(), out PropertyDamageEstimate);

                                    objLead.PropertyDamageEstimate = PropertyDamageEstimate;// Convert.ToDecimal(table.Rows[i]["Property Damage Estimate"]);
                                }
                                //if (table.Rows[i]["Habitable"] != string.Empty) {
                                //	//objLead.Habitable = table.Rows[i]["Habitable"].ToString();
                                //	var id = HabitableManager.GetbyHabitable(table.Rows[i]["Habitable"].ToString());
                                //	if (id != null && id.HabitableId > 0)
                                //		objLead.Habitable = id.HabitableId;
                                //}
                                //if (table.Rows[i]["Wind Policy"] != string.Empty) {
                                //	//objLead.WindPolicy = table.Rows[i]["Wind Policy"].ToString();
                                //	//var id = WindPolicyManager.getbyWindPolicy(table.Rows[i]["Habitable"].ToString());
                                //	var id = WindPolicyManager.getbyWindPolicy(table.Rows[i]["Wind Policy"].ToString());
                                //	if (id != null && id.WindPolicyId > 0)
                                //		objLead.WindPolicy = id.WindPolicyId;
                                //}
                                //if (table.Rows[i]["Flood Policy"] != string.Empty) {
                                //	//objLead.FloodPolicy = table.Rows[i]["Flood Policy"].ToString();
                                //	var id = FloodPolicyManager.GetByFloodPolicy(table.Rows[i]["Flood Policy"].ToString());
                                //	if (id != null && id.FloodPolicyId > 0)
                                //		objLead.FloodPolicy = id.FloodPolicyId;
                                //}

                                if (table.Rows[i]["Owner First Name"] != string.Empty)
                                    if (table.Rows[i]["Owner First Name"].ToString().Length > 50)
                                        objLead.OwnerFirstName = table.Rows[i]["Owner First Name"].ToString().Substring(0, 50);
                                    else
                                        objLead.OwnerFirstName = table.Rows[i]["Owner First Name"].ToString();

                                if (table.Rows[i]["Owner Last Name"] != string.Empty) {
                                    str = table.Rows[i]["Owner Last Name"].ToString();
                                    objLead.OwnerLastName = str.Length > 50 ? str.Substring(0, 50) : str;
                                }

                                if (table.Rows[i]["Owner Phone Number"] != string.Empty) {
                                    str = table.Rows[i]["Owner Phone Number"].ToString();
                                    objLead.OwnerPhone = str.Length > 15 ? str.Substring(0, 15) : str;
                                }

                                if (table.Rows[i]["Last Contact Date"] != string.Empty)
                                    objLead.LastContactDate = Convert.ToDateTime(table.Rows[i]["Last Contact Date"].ToString());

                                if (table.Rows[i]["Personal Referral"] != string.Empty) {
                                    str = table.Rows[i]["Personal Referral"].ToString();
                                    objLead.HearAboutUsDetail = str.Length > 250 ? str.Substring(0, 250) : str;
                                }

                                StatusMaster statusMaster = null;

                                if (table.Rows[i]["Status"] != string.Empty) {
                                    string statusName = table.Rows[i]["Status"].ToString();
                                    statusName = statusName.Length > 100 ? statusName.Substring(0, 100) : statusName;
                                    statusMaster = StatusManager.GetByStatusName(statusName);

                                    if (statusMaster.StatusId == 0) {
                                        statusMaster = new StatusMaster();
                                        statusMaster.clientID = clientID;
                                        statusMaster.InsertBy = objLead.UserId;
                                        statusMaster.InsertDate = DateTime.Now;
                                        statusMaster.isCountable = true;
                                        statusMaster.isCountAsOpen = true;
                                        statusMaster.Status = true;
                                        statusMaster.StatusName = statusName;

                                        statusMaster = StatusManager.Save(statusMaster);
                                    }
                                }

                                objLead.Status = 1;
                                objLead.InsertBy = objLead.UserId;

                                // 2013-08-29 tortega
                                if (clientID > 0)
                                    objLead.ClientID = clientID;

                                Leads newLead = LeadsManager.Save(objLead);

                                if (newLead != null) {
                                    LeadComment objLeadComment = null;

                                    // add policy
                                    CRM.Data.Entities.LeadPolicy policy = new CRM.Data.Entities.LeadPolicy();
                                    policy.PolicyType = 1;
                                    policy.LeadId = newLead.LeadId;
                                    policy.IsActive = true;
                                    policy.isAllDocumentUploaded = false;

                                    if (statusMaster != null)
                                        policy.LeadStatus = statusMaster.StatusId;

                                    if (adjusterID > 0)
                                        policy.AdjusterID = adjusterID;

                                    if (table.Rows[i]["Claims Number"] != string.Empty)
                                        policy.ClaimNumber = table.Rows[i]["Claims Number"].ToString();

                                    if (table.Rows[i]["Site Survey Date"] != string.Empty)
                                        policy.SiteSurveyDate = Convert.ToDateTime(table.Rows[i]["Site Survey Date"].ToString());

                                    LeadPolicyManager.Save(policy);

                                    if (!string.IsNullOrEmpty(table.Rows[i]["Reported to Insurer"].ToString())) {
                                        objLeadComment = new LeadComment();
                                        int LeadID = objLead.LeadId;

                                        objLeadComment.LeadId = LeadID;

                                        objLeadComment.UserId = objLead.UserId;

                                        objLeadComment.Status = 1;

                                        // 2013-08-29 tortega
                                        objLeadComment.PolicyType = policyType;

                                        str = table.Rows[i]["Reported to Insurer"].ToString();
                                        if (str.Length > 8000)
                                            objLeadComment.CommentText = "Reported to Insurer " + str.Substring(0, 8000);
                                        else
                                            objLeadComment.CommentText = "Reported to Insurer " + str;

                                        LeadComment objld = LeadCommentManager.Save(objLeadComment);
                                    }

                                    if (!string.IsNullOrEmpty(table.Rows[i]["Claimant Comments"].ToString())) {
                                        objLeadComment = new LeadComment();
                                        int LeadID = objLead.LeadId;

                                        objLeadComment.LeadId = LeadID;

                                        objLeadComment.UserId = objLead.UserId;

                                        objLeadComment.Status = 1;

                                        // 2013-08-29 tortega
                                        objLeadComment.PolicyType = policyType;

                                        str = table.Rows[i]["Claimant Comments"].ToString();
                                        if (str.Length > 8000)
                                            objLeadComment.CommentText = str.Substring(0, 8000);
                                        else
                                            objLeadComment.CommentText = str;

                                        LeadComment objld = LeadCommentManager.Save(objLeadComment);
                                    }
                                }

                            }	//for (int i = 0; i < table.Rows.Count; i++) {

                            scope.Complete();

                        }
                        string rootFolderPath = Server.MapPath("~//CSVLoad//");
                        string filesToDelete = FileUpload1.FileName;
                        string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
                        foreach (string file in fileList) {
                            System.IO.File.Delete(file);
                        }
                        lblSave.Text = "Data Saved Successfully !!!";
                        lblSave.Visible = true;
                    }
                }
            }
            catch (Exception ex) {
                lblError.Text = "There Is a problem in  data save  !!!";
                lblError.Visible = true;

                Core.EmailHelper.emailError(ex);
            }
        }
Пример #17
0
        protected void UploadTemplate2_bak()
        {
            // original format designed by Vivek
            lblSave.Text = string.Empty;
            lblSave.Visible = false;
            lblError.Text = string.Empty;
            lblError.Visible = false;
            lblMessage.Text = string.Empty;
            lblMessage.Visible = false;
            // 2013-02-09 tortega -- Added data validation prior to import. File is not aborted in the event of incorrect data.
            string str = null;

            int clientID = Core.SessionHelper.getClientId();

            // assume homeowner
            int policyType = 1;
            DateTime DateSubmitted = DateTime.Now;

            try {
                if (FileUpload1.HasFile) {

                    string ext = System.IO.Path.GetExtension(FileUpload1.PostedFile.FileName);
                    string ActualFileName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(@"\") + 1);
                    string FileNameWithoutExt = ActualFileName.Replace(ext, "");
                    if (ext == ".csv") {

                        if (!Directory.Exists(Server.MapPath("~//CSVLoad//"))) {
                            Directory.CreateDirectory(Server.MapPath("~//CSVLoad//"));
                        }
                        FileUpload1.SaveAs(Server.MapPath("~//CSVLoad//" + FileUpload1.FileName));
                        DataTable table = CSVReader.ReadCSVFile(Server.MapPath("~//CSVLoad//" + FileUpload1.FileName), true);
                        using (TransactionScope scope = new TransactionScope()) {
                            Leads objLead = null;
                            for (int i = 0; i < table.Rows.Count; i++) {

                                objLead = new Leads();

                                //objLead.LeadStatus = 1;	// active
                                objLead.OriginalLeadDate = DateTime.Now;
                                objLead.TypeOfProperty = 18;	//residential
                                objLead.UserId = Convert.ToInt32(Session["UserId"]);

                                if (table.Rows[i]["Create Date"] != string.Empty) {

                                    DateTime.TryParse(table.Rows[i]["Create Date"].ToString(), out DateSubmitted);

                                    objLead.DateSubmitted = DateSubmitted;

                                    objLead.OriginalLeadDate = DateSubmitted;
                                }

                                if (table.Rows[i]["Last Name"] != string.Empty) {
                                    str = table.Rows[i]["Last Name"].ToString();
                                    if (str.Length > 50) {
                                        objLead.ClaimantLastName = str.Substring(0, 50);
                                        objLead.OwnerLastName = objLead.ClaimantLastName;
                                    }
                                    else {
                                        objLead.ClaimantLastName = str;
                                        objLead.OwnerLastName = str;
                                    }
                                }

                                if (table.Rows[i]["First Name"] != string.Empty) {
                                    str = table.Rows[i]["First Name"].ToString();
                                    if (str.Length > 50) {
                                        objLead.ClaimantFirstName = str.Substring(0, 50);
                                        objLead.OwnerFirstName = objLead.ClaimantFirstName;
                                    }
                                    else {
                                        objLead.ClaimantFirstName = str;
                                        objLead.OwnerFirstName = str;
                                    }
                                }

                                if (table.Rows[i]["Middle Name"] != string.Empty) {
                                    str = table.Rows[i]["Middle Name"].ToString();
                                    if (str.Length > 50) {
                                        objLead.ClaimantMiddleName = str.Substring(0, 50);
                                    }
                                    else {
                                        objLead.ClaimantMiddleName = str;
                                    }
                                }

                                if (table.Rows[i]["E-mail"] != string.Empty) {
                                    str = table.Rows[i]["E-mail"].ToString();
                                    if (str.Length > 100)
                                        objLead.EmailAddress = str.Substring(0, 100);
                                    else
                                        objLead.EmailAddress = str;
                                }
                                if (table.Rows[i]["Personal E-mail"] != string.Empty) {
                                    str = table.Rows[i]["Personal E-mail"].ToString();
                                    if (str.Length > 100)
                                        objLead.SecondaryEmail = str.Substring(0, 100);
                                    else
                                        objLead.SecondaryEmail = str;
                                }

                                if (table.Rows[i]["Mobile Phone"] != string.Empty) {
                                    str = table.Rows[i]["Mobile Phone"].ToString();
                                    if (str.Length > 20)
                                        objLead.SecondaryPhone = str.Substring(0, 20);
                                    else
                                        objLead.SecondaryPhone = str;
                                }

                                if (table.Rows[i]["Salutation"] != string.Empty) {
                                    str = table.Rows[i]["Salutation"].ToString();
                                    if (str.Length > 50)
                                        objLead.Salutation = str.Substring(0, 20);
                                    else
                                        objLead.Salutation = str;
                                }

                                string adjusterName = null;
                                int? adjusterID = null;
                                AdjusterMaster adjuster = null;

                                if (table.Rows[i]["Adjuster Name"] != string.Empty)
                                    adjusterName = table.Rows[i]["Adjuster Name"].ToString();

                                string adjusterEmail = null;
                                string adjusterFax = null;
                                string AdjusterPhone = null;
                                string AdjusterCo = null;
                                string AdjusterAddress = null;

                                if (table.Rows[i]["Adjuster Email"] != string.Empty)
                                    adjusterEmail = table.Rows[i]["Adjuster Email"].ToString();

                                if (table.Rows[i]["Adjuster Fax"] != string.Empty)
                                    adjusterFax = table.Rows[i]["Adjuster Fax"].ToString();

                                if (table.Rows[i]["Adjuster Phone"] != string.Empty)
                                    AdjusterPhone = table.Rows[i]["Adjuster Phone"].ToString();

                                if (table.Rows[i]["Adjuster Co"] != string.Empty)
                                    AdjusterCo = table.Rows[i]["Adjuster Co"].ToString();

                                if (table.Rows[i]["Adj Address"] != string.Empty)
                                    AdjusterAddress = table.Rows[i]["Adj Address"].ToString();

                                if (!string.IsNullOrEmpty(adjusterName)) {
                                    adjuster = AdjusterManager.GetByAdjusterName(adjusterName.Trim());
                                    if (adjuster.AdjusterId == 0) {
                                        // add adjuster
                                        adjuster = new AdjusterMaster();
                                        adjuster.Status = true;
                                        adjuster.AdjusterName = adjusterName.Trim();
                                        adjuster.ClientId = clientID;
                                        adjuster.InsertBy = objLead.UserId;
                                        adjuster.InsertDate = DateTime.Now;
                                        adjuster.isEmailNotification = true;
                                        adjuster.email = adjusterEmail;
                                        adjuster.Address1 = AdjusterAddress;
                                        adjuster.PhoneNumber = AdjusterPhone;
                                        adjuster.FaxNumber = adjusterFax;
                                        adjuster.CompanyName = AdjusterCo;
                                        adjuster = AdjusterManager.Save(adjuster);
                                    }

                                    adjusterID = adjuster.AdjusterId;
                                }

                                if (table.Rows[i]["Date of Loss"] != string.Empty) {
                                    DateTime lossDate = DateTime.MinValue;
                                    if (DateTime.TryParse(table.Rows[i]["Date of Loss"].ToString(), out lossDate))
                                        objLead.LossDate = lossDate;
                                }

                                if (table.Rows[i]["Loss Location"] != string.Empty)
                                    objLead.LossLocation = table.Rows[i]["Loss Location"].ToString();

                                if (table.Rows[i]["Address 1"] != string.Empty)
                                    objLead.LossAddress = table.Rows[i]["Address 1"].ToString();

                                if (table.Rows[i]["Address 2"] != string.Empty)
                                    objLead.LossAddress2 = table.Rows[i]["Address 2"].ToString();

                                if (table.Rows[i]["City"] != string.Empty)
                                    objLead.CityName = table.Rows[i]["City"].ToString();

                                if (table.Rows[i]["State"] != string.Empty)
                                    objLead.StateName = table.Rows[i]["State"].ToString();

                                if (table.Rows[i]["ZIP Code"] != string.Empty)
                                    objLead.Zip = table.Rows[i]["ZIP Code"].ToString();

                                if (table.Rows[i]["Company"] != string.Empty)
                                    objLead.BusinessName = table.Rows[i]["Company"].ToString();

                                if (table.Rows[i]["Adjuster Name"] != string.Empty)
                                    adjusterName = table.Rows[i]["Adjuster Name"].ToString();

                                if (table.Rows[i]["Phone"] != string.Empty) {
                                    str = table.Rows[i]["Phone"].ToString();
                                    if (str.Length > 20)
                                        objLead.PhoneNumber = str.Substring(0, 20);
                                    else
                                        objLead.PhoneNumber = str.ToString();
                                }

                                StatusMaster statusMaster = null;
                                string statusName = null;

                                if (table.Rows[i]["File Status"] != string.Empty) {
                                    statusName = table.Rows[i]["File Status"].ToString();
                                    statusMaster = StatusManager.GetByStatusName(statusName);

                                    if (statusMaster.StatusId == 0) {
                                        statusMaster = new StatusMaster();
                                        statusMaster.clientID = clientID;
                                        statusMaster.InsertBy = objLead.UserId;
                                        statusMaster.InsertDate = DateTime.Now;
                                        statusMaster.isCountable = true;
                                        statusMaster.Status = true;
                                        statusMaster.StatusName = statusName;

                                        statusMaster = StatusManager.Save(statusMaster);
                                    }
                                }

                                if (!string.IsNullOrEmpty(table.Rows[i]["Peril"].ToString())) {
                                    var id = TypeofDamageManager.getbyTypeOfDamage(table.Rows[i]["Peril"].ToString());
                                    objLead.TypeOfDamage = id.TypeOfDamage;

                                    //string dmgid = string.Empty;
                                    //string[] dmg = table.Rows[i]["Type of Damage"].ToString().Split(',');
                                    //for (int d = 0; d < dmg.Length; d++) {
                                    //     string dmgtext = dmg[d];
                                    //     var dmgdata = TypeofDamageManager.getbyTypeOfDamage(dmgtext);
                                    //     if (dmgdata != null && dmgdata.TypeOfDamage != null && dmgdata.TypeOfDamage.ToString() != string.Empty) {
                                    //          dmgid += dmgdata.TypeOfDamageId + ",";
                                    //     }
                                    //     else {
                                    //          TypeOfDamageMaster objdmg = new TypeOfDamageMaster();
                                    //          objdmg.TypeOfDamage = dmgtext.Length > 100 ? dmgtext.Substring(0, 100) : dmgtext;
                                    //          objdmg.Status = true;
                                    //          TypeOfDamageMaster sv = TypeofDamageManager.Save(objdmg);
                                    //          dmgid += sv.TypeOfDamageId + ",";
                                    //     }
                                    //}

                                    //objLead.TypeOfDamage = dmgid;

                                    str = table.Rows[i]["Peril"].ToString();
                                    if (str.Length > 250)
                                        objLead.TypeofDamageText = str.Substring(0, 250).Replace("/", ",");
                                    else
                                        objLead.TypeofDamageText = str.Replace("/", ",");
                                }

                                objLead.Status = 1;

                                // 2013-08-29 tortega
                                if (clientID > 0)
                                    objLead.ClientID = clientID;

                                Leads newLead = LeadsManager.Save(objLead);

                                if (newLead != null) {
                                    if (table.Rows[i]["Certified Mail Number"] != string.Empty)
                                        AddComments(newLead.LeadId, "Certified Mail Number: " + table.Rows[i]["Certified Mail Number"].ToString());

                                    //if (table.Rows[i]["Contract Signed Date"] != string.Empty)
                                    //     AddComments(newLead.LeadId, "Contract Signed Date: " + table.Rows[i]["Contract Signed Date"].ToString());

                                    if (table.Rows[i]["Last E-mail"] != string.Empty)
                                        AddComments(newLead.LeadId, "Last E-mail Date: " + table.Rows[i]["Last E-mail"].ToString());

                                    if (table.Rows[i]["Last Meeting"] != string.Empty)
                                        AddComments(newLead.LeadId, "Last Meeting Date: " + table.Rows[i]["Last Meeting"].ToString());

                                    if (table.Rows[i]["Letter Date"] != string.Empty)
                                        AddComments(newLead.LeadId, "Letter Date: " + table.Rows[i]["Letter Date"].ToString());

                                    // add policy
                                    CRM.Data.Entities.LeadPolicy policy = new CRM.Data.Entities.LeadPolicy();
                                    policy.PolicyType = 1;
                                    policy.LeadId = newLead.LeadId;
                                    policy.IsActive = true;
                                    policy.isAllDocumentUploaded = false;

                                    if (adjusterID != null)
                                        policy.AdjusterID = adjusterID;

                                    if (table.Rows[i]["Claim Number"] != string.Empty)
                                        policy.ClaimNumber = table.Rows[i]["Claim Number"].ToString();

                                    if (table.Rows[i]["Policy Number"] != string.Empty)
                                        policy.PolicyNumber = table.Rows[i]["Policy Number"].ToString();

                                    if (table.Rows[i]["Policy Period"] != string.Empty)
                                        policy.PolicyPeriod = table.Rows[i]["Policy Period"].ToString();

                                    if (table.Rows[i]["File Number"] != string.Empty)
                                        policy.InsurerFileNo = table.Rows[i]["File Number"].ToString();

                                    if (statusMaster != null)
                                        policy.LeadStatus = statusMaster.StatusId;

                                    if (table.Rows[i]["Ins Carrier"] != string.Empty)
                                        policy.InsuranceCompanyName = table.Rows[i]["Ins Carrier"].ToString();

                                    if (table.Rows[i]["Ins Co Address"] != string.Empty)
                                        policy.InsuranceAddress = table.Rows[i]["Ins Co Address"].ToString();

                                    if (table.Rows[i]["Ins Co City"] != string.Empty) {
                                        string cityName = table.Rows[i]["Ins Co City"].ToString();
                                        CityMaster cityMaster = City.GetByCityName(cityName);
                                        if (cityMaster != null && cityMaster.CityId > 0)
                                            policy.InsuranceCity = cityMaster.CityId;
                                    }

                                    if (table.Rows[i]["Ins Co State"] != string.Empty) {
                                        string stateName = table.Rows[i]["Ins Co State"].ToString();
                                        StateMaster stateMaster = State.Getstateid(stateName);
                                        if (stateMaster != null && stateMaster.StateId > 0)
                                            policy.InsuranceState = stateMaster.StateId;
                                    }

                                    if (table.Rows[i]["Ins Co Zip"] != string.Empty) {
                                        string zipCode = table.Rows[i]["Ins Co Zip"].ToString();
                                        ZipCodeMaster zipMaster = ZipCode.GetByZipCode(zipCode);
                                        if (zipMaster != null && zipMaster.ZipCodeID > 0)
                                            policy.InsuranceZipCode = zipMaster.ZipCodeID.ToString();
                                    }

                                    LeadPolicyManager.Save(policy);
                                }

                            }	//for (int i = 0; i < table.Rows.Count; i++) {

                            scope.Complete();

                        }
                        string rootFolderPath = Server.MapPath("~//CSVLoad//");
                        string filesToDelete = FileUpload1.FileName;
                        string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
                        foreach (string file in fileList) {
                            System.IO.File.Delete(file);
                        }
                        lblSave.Text = "Data Saved Successfully !!!";
                        lblSave.Visible = true;
                    }
                }
            }
            catch (Exception ex) {
                lblError.Text = "There Is a problem in  data save  !!!";
                lblError.Visible = true;

                Core.EmailHelper.emailError(ex);
            }
        }
Пример #18
0
        protected CRM.Data.Entities.LeadPolicy collectPolicyDataFromUI()
        {
            CRM.Data.Entities.LeadPolicy policy = new CRM.Data.Entities.LeadPolicy();

            policy.PolicyType = Convert.ToInt32(ucPolicyType1.SelectedValue);
            policy.PolicyNumber = txtPolicyNumber.Text.Trim();
            policy.ClaimNumber = txtClaimNumber.Text.Trim();
            policy.IsActive = true;

            policy.LossDate = txtLossDate.Date;

            return policy;
        }
Пример #19
0
        // generate invoices
        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            Carrier carrier = null;
            CarrierInvoiceProfile profile = null;

            Invoice invoice       = null;
            int     carrierID     = Convert.ToInt32(ddlCarrier.SelectedValue);
            decimal invoiceAmount = 0;
            int     policyID      = 0;

            int profileID = Convert.ToInt32(this.ddlInvoiceProfile.SelectedValue);

            if (carrierID == 0 || profileID == 0)
            {
                return;
            }

            try {
                profile = CarrierInvoiceProfileManager.Get(profileID);

                carrier = CarrierManager.Get(carrierID);
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                showErrorMessage();

                return;
            }

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    foreach (GridViewRow row in gvCarrierPolicy.Rows)
                    {
                        if (row.RowType == DataControlRowType.DataRow)
                        {
                            CheckBox cbxSelect = row.FindControl("cbxSelect") as CheckBox;

                            if (cbxSelect.Checked)
                            {
                                invoice = new Invoice();
                                //invoice.ClientID = clientID;
                                //invoice.CarrierID = carrierID;
                                invoice.InvoiceDate = DateTime.Now;

                                invoice.InvoiceTypeID = profile.InvoiceType;

                                invoice.CarrierInvoiceProfileID = profileID;

                                invoice.IsVoid = false;

                                invoice.BillToAddress1 = carrier.AddressLine1;
                                invoice.BillToAddress2 = carrier.AddressLine2;
                                invoice.BillToAddress3 = string.Empty;
                                invoice.BillToName     = carrier.CarrierName;

                                policyID = (int)gvCarrierPolicy.DataKeys[row.RowIndex].Values[0];

                                //invoice.PolicyID = policyID;

                                //invoice.LeadId = (int)gvCarrierPolicy.DataKeys[row.RowIndex].Values[1];

                                //invoice.PolicyTypeID = (int)gvCarrierPolicy.DataKeys[row.RowIndex].Values[2];

                                Label lblInvoiceAmount = row.FindControl("lblInvoiceAmount") as Label;

                                decimal.TryParse(lblInvoiceAmount.Text, out invoiceAmount);

                                invoice.TotalAmount = invoiceAmount;

                                invoice.InvoiceNumber = InvoiceManager.GetNextInvoiceNumber(clientID);

                                int invoiceID = InvoiceManager.Save(invoice);

                                InvoiceDetail invoiceDetail = new InvoiceDetail();
                                invoiceDetail.InvoiceID       = invoiceID;
                                invoiceDetail.isBillable      = true;
                                invoiceDetail.Qty             = 1;
                                invoiceDetail.Rate            = invoiceAmount;
                                invoiceDetail.LineAmount      = invoiceAmount;
                                invoiceDetail.LineDate        = DateTime.Now;
                                invoiceDetail.LineDescription = "As per contract";

                                InvoiceDetailManager.Save(invoiceDetail);

                                // flag policy as invoiced
                                CRM.Data.Entities.LeadPolicy policy = LeadPolicyManager.Get(policyID);

                                if (policy != null)
                                {
                                    policy.IsInvoiced = true;

                                    LeadPolicyManager.Save(policy);
                                }
                            }
                        }
                    }                     // foreach

                    // complete transaction
                    scope.Complete();

                    lblMessage.Text     = "Invoice(s) have been generated.";
                    lblMessage.CssClass = "ok";
                }
            }
            catch (Exception ex) {
                Core.EmailHelper.emailError(ex);

                showErrorMessage();
            }
            finally {
                // refresh those policies to be invoiced
                bindPoliciesReadyForInvoice();
            }
        }
Пример #20
0
        public void saveForm()
        {
            Page.Validate("Policy");
            //if (!Page.IsValid)
            //    return;

            CRM.Data.Entities.LeadPolicy policy = null;

            lblMessage.Text     = string.Empty;
            lblMessage.CssClass = string.Empty;

            //if (int.TryParse(hf_policyID.Value, out id) && id > 0) {
            if (policyID > 0)
            {
                policy = LeadPolicyManager.Get(policyID);
            }
            else
            {
                // new
                policy          = new CRM.Data.Entities.LeadPolicy();
                policy.LeadId   = Core.SessionHelper.getLeadId();
                policy.Id       = 0;
                policy.IsActive = true;
                policy.isAllDocumentUploaded = false;
            }
            if (ucPolicyType1.SelectedValue == "0" || ucPolicyType1.SelectedValue == "")
            {
                policy.PolicyType = null;
            }
            else
            {
                policy.PolicyType = Convert.ToInt32(ucPolicyType1.SelectedValue);
            }

            // carrier information
            if (ddlCarrier.SelectedIndex > 0)
            {
                policy.CarrierID = Convert.ToInt32(ddlCarrier.SelectedValue);
            }
            else
            {
                policy.CarrierID = null;
            }

            policy.PolicyNumber   = txtInsurancePolicyNumber.Text.Trim();
            policy.PolicyFormType = txtPolicyFormType.Text.Trim();

            policy.InsuranceCompanyName = txtInsuranceCompanyName.Text;

            if (!string.IsNullOrEmpty(txtExpirationDate.Text))
            {
                policy.ExpirationDate = txtExpirationDate.Date;
            }
            else
            {
                policy.ExpirationDate = null;
            }

            if (!string.IsNullOrEmpty(txtExpirationDate.Text))
            {
                policy.EffectiveDate = txtEffectiveDate.Date;
            }
            else
            {
                policy.EffectiveDate = null;
            }

            if (!string.IsNullOrEmpty(txtInitialCoverageDate.Text))
            {
                policy.InitialCoverageDate = txtInitialCoverageDate.Date;
            }

            if (ddlAgent.SelectedIndex > 0)
            {
                policy.AgentID = Convert.ToInt32(ddlAgent.SelectedValue);
            }

            try {
                using (TransactionScope scope = new TransactionScope()) {
                    // save policy id
                    this.policyID = LeadPolicyManager.Save(policy);



                    if (HttpContext.Current.Session["Limit"] != null && HttpContext.Current.Session["PolicyLimit"] != null && HttpContext.Current.Session["tblCasulityPolicylimit"] != null && HttpContext.Current.Session["tblAllPolicylimit"] != null)
                    {
                        AddLimitPolicy(this.policyID);
                        CacheBlank();
                        ShowAddCoverage();
                        SetAddCoverage(this.policyID);
                        HideAddCoverageAdd();
                    }
                    else
                    {
                        propertyLimits.saveLimits(policyID);

                        //casualtyLimits.saveLimits(policyID);
                    }



                    propertySubLimits.saveLimits(policyID);

                    scope.Complete();
                }

                // save policy type in viewstate
                policyType = ucPolicyType1.SelectedValue;

                // save policy id
                hf_policyID.Value = policyID.ToString();

                // activate other tabs
                tabContainerPolicy.Visible = true;

                activateLinks();

                bindLimits();

                bindClaims();

                //bindData();


                lblMessage.Text     = "Policy Information saved successfully.";
                lblMessage.CssClass = "ok";
            }
            catch (Exception ex) {
                lblMessage.Text     = "Policy Information was not saved.";
                lblMessage.CssClass = "error";

                Core.EmailHelper.emailError(ex);
            }
        }