Example #1
0
        private string InsertPrepareSMS(SLMDBEntities slmdb, kkslm_tr_renewinsurance renew, List <InsuranceCompanyData> companyList, List <kkslm_ms_coveragetype> coverageList)
        {
            try
            {
                if (string.IsNullOrEmpty(AppConstant.SMSTemplatePathReceiveNo))
                {
                    throw new Exception($"ไม่พบ Config {nameof(AppConstant.SMSTemplatePathReceiveNo)} ใน Configuration File");
                }

                InsuranceCompanyData insuranceCompany = companyList.FirstOrDefault(p => p.InsComId == renew.slm_InsuranceComId);
                if (insuranceCompany == null)
                {
                    throw new Exception("ไม่พบข้อมูลบริษัทประกัน Id " + renew.slm_InsuranceComId + " ในระบบ");
                }

                kkslm_ms_coveragetype coverage = coverageList.FirstOrDefault(p => p.slm_CoverageTypeId == renew.slm_CoverageTypeId);
                if (coverage == null)
                {
                    throw new Exception("ไม่พบข้อมูลประเภทประกัน Id " + renew.slm_CoverageTypeId + " ในระบบ");
                }

                kkslm_tr_lead lead = slmdb.kkslm_tr_lead.FirstOrDefault(p => p.slm_ticketId == renew.slm_TicketId);
                if (lead == null)
                {
                    throw new Exception("ไม่พบข้อมูล Lead ในระบบ, TicketId " + renew.slm_TicketId);
                }

                string telNoSms = slmdb.kkslm_tr_cusinfo.Where(p => p.slm_TicketId == lead.slm_ticketId).Select(p => p.slm_TelNoSms).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(telNoSms))
                {
                    telNoSms = lead.slm_TelNo_1;
                }

                string template   = File.ReadAllText(AppConstant.SMSTemplatePathReceiveNo, Encoding.UTF8);
                string smsMessage = template
                                    .Replace("%CoverageType%", coverage.slm_ConverageTypeName?.Trim() ?? "")
                                    .Replace("%CarLicenseNo%", renew.slm_LicenseNo?.Trim() ?? "")
                                    .Replace("%InsuranceCompany%", insuranceCompany.InsNameTH?.Trim() ?? "")
                                    .Replace("%ReceiveNo%", renew.slm_ReceiveNo?.Trim() ?? "")
                                    .Replace("%InsuranceTelNo%", insuranceCompany.TelContact?.Trim() ?? "");

                //kkslm_tr_prelead_prepare_sms sms = InitSMS(smsMessage, telNoSms, renew.slm_TicketId, _dbNow);
                var sms = new kkslm_tr_prelead_prepare_sms
                {
                    slm_ticketId          = renew.slm_TicketId,
                    slm_Prelead_Id        = null,
                    slm_Message           = smsMessage,
                    slm_Message_CreatedBy = "SYSTEM",
                    slm_MessageStatusId   = "1",
                    slm_PhoneNumber       = telNoSms,
                    slm_QueueId           = "6",
                    slm_RequestDate       = DateTime.Now,
                    slm_RuleActivityId    = 0,
                    slm_ExportStatus      = "0",
                    slm_RefId             = null,
                    slm_SendingStatusCode = null,
                    slm_SendingStatus     = null,
                    slm_ErrorCode         = null,
                    slm_ErrorReason       = null,
                    slm_CAS_Flag          = null,
                    slm_CAS_Date          = null,
                    slm_FlagType          = "1",
                    slm_CreatedBy         = "SYSTEM",
                    slm_CreatedDate       = DateTime.Now,
                    slm_UpdatedBy         = "SYSTEM",
                    slm_UpdatedDate       = DateTime.Now,
                    is_Deleted            = 0
                };
                slmdb.kkslm_tr_prelead_prepare_sms.AddObject(sms);
                return(smsMessage);
            }
            catch
            {
                throw;
            }
        }
Example #2
0
        private void InsertPrepareSMS(SLMDBEntities slmdb, kkslm_tr_lead lead, kkslm_tr_renewinsurance renew, List <InsuranceCompanyData> insurComList, List <CoverageTypeData> coverageList, DateTime createdDate)
        {
            try
            {
                string filePath = AppConstant.SMSTemplatePathPolicyNo;

                if (string.IsNullOrWhiteSpace(filePath))
                {
                    throw new Exception("ไม่พบ Config SMSTemplatePathPolicyNo ใน Configuration File");
                }

                var    paidAmount           = CalculateTotalPaidAmount(slmdb, renew.slm_TicketId, AppConstant.PaymentCode.Policy);
                var    coverageTypeName     = coverageList.Where(p => p.CoverageTypeId == renew.slm_CoverageTypeId).Select(p => p.CoverageTypeName).FirstOrDefault();
                var    insurTelNo           = insurComList.Where(p => p.InsComId == renew.slm_InsuranceComId).Select(p => p.TelContact).FirstOrDefault();
                var    insNameAbb           = insurComList.Where(p => p.InsComId == renew.slm_InsuranceComId).Select(p => p.InsNameAbb).FirstOrDefault();
                string policyStartCoverDate = "";
                if (renew.slm_PolicyStartCoverDate != null)
                {
                    policyStartCoverDate = renew.slm_PolicyStartCoverDate.Value.ToString("dd/MM/") + (renew.slm_PolicyStartCoverDate.Value.Year + 543).ToString().Substring(2, 2);
                }

                string template = File.ReadAllText(filePath, Encoding.UTF8);
                template = template.Replace("%InsNameAbb%", string.IsNullOrWhiteSpace(insNameAbb) ? "" : insNameAbb)
                           .Replace("%CoverageType%", string.IsNullOrWhiteSpace(coverageTypeName) ? "" : coverageTypeName)
                           .Replace("%PolicyPremiumPaid%", paidAmount.ToString("#,##0.00"))
                           .Replace("%PolicyNo%", renew.slm_PolicyNo)
                           .Replace("%PolicyStartCoverDate%", policyStartCoverDate)
                           //.Replace("%CarLicenseNo%", renew.slm_LicenseNo)
                           .Replace("%InsuranceTelNo%", string.IsNullOrWhiteSpace(insurTelNo) ? "" : insurTelNo);

                kkslm_tr_prelead_prepare_sms sms = new kkslm_tr_prelead_prepare_sms()
                {
                    slm_ticketId          = renew.slm_TicketId,
                    slm_Message           = template,
                    slm_Message_CreatedBy = "SYSTEM",
                    slm_MessageStatusId   = "1",
                    slm_PhoneNumber       = GetTelNoSMS(lead),
                    slm_QueueId           = "6",
                    slm_RequestDate       = createdDate,
                    slm_RuleActivityId    = 0,
                    slm_ExportStatus      = "0",
                    slm_RefId             = null,
                    slm_SendingStatusCode = null,
                    slm_SendingStatus     = null,
                    slm_ErrorCode         = null,
                    slm_ErrorReason       = null,
                    slm_CAS_Flag          = null,
                    slm_CAS_Date          = null,
                    slm_FlagType          = "2",
                    slm_CreatedBy         = "SYSTEM",
                    slm_CreatedDate       = createdDate,
                    slm_UpdatedBy         = "SYSTEM",
                    slm_UpdatedDate       = createdDate,
                    is_Deleted            = 0
                };
                slmdb.kkslm_tr_prelead_prepare_sms.AddObject(sms);
                slmdb.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
Example #3
0
        private void CreateCASActivityLog(kkslm_tr_renewinsurance reins, SLMDBEntities slmdb, string batchCode, Int64 batchMonitorId, int phonecall_id, LeadDataForCARLogService data)
        {
            try
            {
                string policyStartCoverDate = "";
                string policyEndCoverDate   = "";
                string actStartCoverDate    = "";
                string actEndCoverDate      = "";
                string preleadId            = "";

                if (data != null)
                {
                    preleadId = data.PreleadId != null?data.PreleadId.Value.ToString() : "";

                    if (data.PolicyStartCoverDate != null)
                    {
                        policyStartCoverDate = data.PolicyStartCoverDate.Value.ToString("dd-MM-") + data.PolicyStartCoverDate.Value.Year.ToString();
                    }
                    if (data.PolicyEndCoverDate != null)
                    {
                        policyEndCoverDate = data.PolicyEndCoverDate.Value.ToString("dd-MM-") + data.PolicyEndCoverDate.Value.Year.ToString();
                    }
                    if (data.ActStartCoverDate != null)
                    {
                        actStartCoverDate = data.ActStartCoverDate.Value.ToString("dd-MM-") + data.ActStartCoverDate.Value.Year.ToString();
                    }
                    if (data.ActEndCoverDate != null)
                    {
                        actEndCoverDate = data.ActEndCoverDate.Value.ToString("dd-MM-") + data.ActEndCoverDate.Value.Year.ToString();
                    }
                }

                //Activity Info
                List <CARService.DataItem> actInfoList = new List <CARService.DataItem>();
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 1, DataLabel = "เลขที่สัญญา", DataValue = data != null ? data.ContractNo : ""
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 2, DataLabel = "บริษัทประกันภัยรถยนต์", DataValue = data != null ? data.InsuranceCompany : ""
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 3, DataLabel = "เลขเล่มกรมธรรม์", DataValue = data != null ? data.PolicyNo : ""
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 4, DataLabel = "เลขลงทะเบียน", DataValue = ""
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 5, DataLabel = "วันที่คุ้มครอง", DataValue = policyStartCoverDate
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 6, DataLabel = "วันที่สิ้นสุดกรมธรรม์", DataValue = policyEndCoverDate
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 7, DataLabel = "เลขที่พรบ.", DataValue = data != null ? data.ActNo : ""
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 8, DataLabel = "วันที่เริ่มต้นพรบ.", DataValue = actStartCoverDate
                });
                actInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 9, DataLabel = "วันที่สิ้นสุดพรบ.", DataValue = actEndCoverDate
                });

                //Customer Info
                List <CARService.DataItem> cusInfoList = new List <CARService.DataItem>();
                cusInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 1, DataLabel = "Subscription ID", DataValue = data != null ? data.CitizenId : ""
                });
                cusInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 2, DataLabel = "Subscription Type", DataValue = data != null ? data.CardTypeName : ""
                });
                cusInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 3, DataLabel = "ชื่อ-นามสกุลของลูกค้า", DataValue = data != null ? data.CustomerName : ""
                });

                //Product Info
                List <CARService.DataItem> prodInfoList = new List <CARService.DataItem>();
                prodInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 1, DataLabel = "Product Group", DataValue = data != null ? data.ProductGroupName : ""
                });
                prodInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 2, DataLabel = "Product", DataValue = data != null ? data.ProductName : ""
                });
                prodInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 3, DataLabel = "Campaign", DataValue = data != null ? data.CampaignName : ""
                });

                //Contract Info
                List <CARService.DataItem> contInfoList = new List <CARService.DataItem>();
                contInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 1, DataLabel = "เลขที่สัญญา", DataValue = data != null ? data.ContractNo : ""
                });
                contInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 2, DataLabel = "ระบบที่บันทึกสัญญา", DataValue = preleadId != "" ? "HP" : ""
                });
                contInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 3, DataLabel = "ทะเบียนรถ", DataValue = data != null ? data.LicenseNo : ""
                });

                //Officer Info
                List <CARService.DataItem> offInfoList = new List <CARService.DataItem>();
                offInfoList.Add(new CARService.DataItem()
                {
                    SeqNo = 1, DataLabel = "Officer", DataValue = "SYSTEM"
                });

                CARService.CARServiceData logdata = new CARService.CARServiceData()
                {
                    ReferenceNo         = reins.slm_RenewInsureId.ToString(),
                    SecurityKey         = preleadId != "" ? AppConstant.CARLogService.OBTSecurityKey : AppConstant.CARLogService.SLMSecurityKey,
                    ServiceName         = "CreateActivityLog",
                    SystemCode          = preleadId != "" ? AppConstant.CARLogService.CARLoginOBT : AppConstant.CARLogService.CARLoginSLM,  //ถ้ามี preleadid ให้ถือว่าเป็น OBT ทั้งหมด ถึงจะมี TicketId ก็ตาม
                    TransactionDateTime = DateTime.Now,
                    ActivityInfoList    = actInfoList,
                    CustomerInfoList    = cusInfoList,
                    ProductInfoList     = prodInfoList,
                    ContractInfoList    = contInfoList,
                    OfficerInfoList     = offInfoList,
                    ActivityDateTime    = DateTime.Now,
                    CampaignId          = data != null ? data.CampaignId : "",
                    ChannelId           = data != null ? data.ChannelId : "",
                    PreleadId           = preleadId,
                    ProductGroupId      = data != null ? data.ProductGroupId : "",
                    ProductId           = data != null ? data.ProductId : "",
                    Status         = data != null ? data.StatusName : "",
                    SubStatus      = data != null ? data.SubStatusName : "",
                    TicketId       = data != null ? data.TicketId : "",
                    SubscriptionId = data != null ? data.CitizenId : "",
                    TypeId         = AppConstant.CARLogService.Data.TypeId,
                    AreaId         = AppConstant.CARLogService.Data.AreaId,
                    SubAreaId      = AppConstant.CARLogService.Data.SubAreaId,
                    ActivityTypeId = AppConstant.CARLogService.Data.ActivityType.TodoId,
                    ContractNo     = data != null ? data.ContractNo : ""
                };

                if (data != null && !string.IsNullOrEmpty(data.SubScriptionTypeId))
                {
                    logdata.SubscriptionTypeId = data.SubScriptionTypeId;
                }

                bool ret = CARService.CreateActivityLog(logdata, batchMonitorId, batchCode, reins.slm_TicketId, logfilename);
                AppUtil.UpdatePhonecallCASFlag(slmdb, phonecall_id, ret ? "1" : "2");
            }
            catch (Exception ex)
            {
                AppUtil.UpdatePhonecallCASFlag(slmdb, phonecall_id, "2");

                //Error ให้ลง Log ไว้ ไม่ต้อง Throw
                string message = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                BizUtil.InsertLog(batchMonitorId, reins.slm_TicketId, "", message);
                Util.WriteLogFile(logfilename, batchCode, message);
            }
        }
Example #4
0
        private void DoProcess(SLMDBEntities slmdb, kkslm_tr_renewinsurance reins, List <ContractInsuranceData> contractInsureList, List <InsuranceCompanyData> insurComList, List <CoverageTypeData> coverageList)
        {
            try
            {
                string   errMessage     = "";
                bool     doUpdatePolicy = false;
                bool     doUpdateAct    = false;
                DateTime createdDate    = DateTime.Now;
                var      lead           = slmdb.kkslm_tr_lead.Where(p => p.slm_ticketId == reins.slm_TicketId).FirstOrDefault();
                if (lead == null)
                {
                    throw new Exception("ไม่พบข้อมูล Lead TicketId " + reins.slm_TicketId + " ในระบบ");
                }

                int countPolicy            = slmdb.kkslm_tr_renewinsurance_compare.Count(p => p.slm_RenewInsureId == reins.slm_RenewInsureId && p.slm_Selected == true);
                int countAct               = slmdb.kkslm_tr_renewinsurance_compare_act.Count(p => p.slm_RenewInsureId == reins.slm_RenewInsureId && p.slm_ActPurchaseFlag == true);
                ContractInsuranceData data = null;

                if (countPolicy > 0)
                {
                    if (string.IsNullOrWhiteSpace(reins.slm_ReceiveNo))
                    {
                        InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.ReceiveNoNotFound, "");

                        errMessage = string.Format("ContractNo : {0}, TicketId : {1}, GoToPending, Error : ไม่พบข้อมูลเลขที่รับแจ้ง", reins.slm_ContractNo, reins.slm_TicketId);
                        Util.WriteLogFile(logfilename, BatchCode, errMessage);
                        BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", errMessage);
                        //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING");
                        return;
                    }

                    data = contractInsureList.Where(p => p.PolicyType == "V").FirstOrDefault();
                    if (data != null)
                    {
                        if (string.IsNullOrWhiteSpace(reins.slm_PolicyNo))
                        {
                            doUpdatePolicy = true;
                        }
                        else
                        {
                            if (reins.slm_PolicyNo.Trim().ToLower() != data.PolicyNo.ToLower())
                            {
                                doUpdatePolicy = true;
                            }
                        }

                        if (doUpdatePolicy)
                        {
                            reins.slm_PolicyNo = data.PolicyNo;
                            UpdateStatusAndOwnerLogging(slmdb, lead, createdDate, "10", "30", AppConstant.LoggingType.EODUpdateCurrent);
                            UpdatePending(slmdb, reins.slm_ContractNo, "V", createdDate);
                        }
                    }

                    data = contractInsureList.Where(p => p.PolicyType == "C").FirstOrDefault();
                    if (data != null)
                    {
                        if (countAct > 0)
                        {
                            if (string.IsNullOrWhiteSpace(reins.slm_ActNo))
                            {
                                doUpdateAct = true;
                            }
                            else
                            {
                                if (reins.slm_ActNo.Trim().ToLower() != data.PolicyNo.ToLower())
                                {
                                    doUpdateAct = true;
                                }
                            }

                            if (doUpdateAct)
                            {
                                reins.slm_ActNo = data.PolicyNo;
                                UpdatePending(slmdb, reins.slm_ContractNo, "C", createdDate);
                            }
                        }
                        else
                        {
                            InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.PurchaseDetailNotFound, "C");

                            errMessage = string.Format("ContractNo : {0}, TicketId : {1}, GoToPending, Error : ไม่พบข้อมูลการซื้อพรบ. แต่มีเลขพรบ.เข้าระบบ", reins.slm_ContractNo, reins.slm_TicketId);
                            Util.WriteLogFile(logfilename, BatchCode, errMessage);
                            BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", errMessage);
                            //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING");
                        }
                    }
                }
                else if (countPolicy == 0 && countAct > 0)
                {
                    data = contractInsureList.Where(p => p.PolicyType == "C").FirstOrDefault();
                    if (data != null)
                    {
                        if (string.IsNullOrWhiteSpace(reins.slm_ActNo))
                        {
                            doUpdateAct = true;
                        }
                        else
                        {
                            if (reins.slm_ActNo.Trim().ToLower() != data.PolicyNo.ToLower())
                            {
                                doUpdateAct = true;
                            }
                        }

                        if (doUpdateAct)
                        {
                            reins.slm_ActNo = data.PolicyNo;
                            UpdateStatusAndOwnerLogging(slmdb, lead, createdDate, "10", "31", AppConstant.LoggingType.EODUpdateCurrent);
                            UpdatePending(slmdb, reins.slm_ContractNo, "C", createdDate);
                        }
                    }

                    data = contractInsureList.Where(p => p.PolicyType == "V").FirstOrDefault();
                    if (data != null)
                    {
                        InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.PurchaseDetailNotFound, "V");

                        errMessage = string.Format("ContractNo : {0}, TicketId : {1}, GoToPending, Error : ไม่พบข้อมูลการซื้อประกัน แต่มีเลขกรมธรรม์เข้าระบบ", reins.slm_ContractNo, reins.slm_TicketId);
                        Util.WriteLogFile(logfilename, BatchCode, errMessage);
                        BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", errMessage);
                        //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING");
                    }
                }
                else
                {
                    InsertPolicyActPending(contractInsureList, reins.slm_ContractNo, slmdb, AppConstant.PendingType.PurchaseDetailNotFound, "");
                    Util.WriteLogFile(logfilename, BatchCode, string.Format("ContractNo : {0}, Error : ไม่พบข้อมูลการซื้อขายประกันและพรบ.", reins.slm_ContractNo));
                    BizUtil.InsertLog(BatchMonitorId, lead.slm_ticketId, "", string.Format("ContractNo : {0}, Error : ไม่พบข้อมูลการซื้อขายประกันและพรบ.", reins.slm_ContractNo));
                    //Console.WriteLine("ContractNo " + reins.slm_ContractNo + ": PENDING");
                    return;     //ถ้าตก Pending ไม่มีการซื้อประกันและพรบ. ไม่ต้องลงบันทึกผลการติดต่อและไม่ส่ง CAR
                }

                if (doUpdatePolicy || doUpdateAct)
                {
                    reins.slm_UpdatedBy   = "SYSTEM";
                    reins.slm_UpdatedDate = createdDate;
                    slmdb.SaveChanges();

                    var carData   = AppUtil.GetDataForCARLogService(reins.slm_TicketId, slmdb);
                    var phonecall = InsertPhonecallHistory(slmdb, reins.slm_TicketId, createdDate, carData);

                    if (doUpdatePolicy && AppConstant.SendSMSPolicyNo)
                    {
                        InsertPrepareSMS(slmdb, lead, reins, insurComList, coverageList, createdDate);
                    }

                    CreateCASActivityLog(reins, slmdb, BatchCode, BatchMonitorId, phonecall.slm_PhoneCallId, carData);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }