Exemplo n.º 1
0
        public async Task <List <ProviderBillChartDetailAC> > GetChartDetailByProvider(long providerid)
        {
            int billClosed  = Convert.ToInt16(EnumList.BillStatus.BillClosed);
            int memoCreated = Convert.ToInt16(EnumList.BillStatus.MemoCreated);

            List <ProviderBillChartDetailAC> providerBillChartDetailACs = new List <ProviderBillChartDetailAC>();
            List <Billmaster> billmasters = await _dbTeleBilling_V01Context.Billmaster.Where(x => !x.IsDelete && x.ProviderId == providerid && (x.BillStatusId == billClosed || x.BillStatusId == memoCreated)).OrderByDescending(x => x.Id).Take(3).Include(x => x.Billdetails).Include(x => x.Currency).ToListAsync();

            List <Billdetails> billdetails = new List <Billdetails>();

            if (billmasters.Count > 0)
            {
                foreach (var item in billmasters)
                {
                    billdetails.AddRange(item.Billdetails);
                }
            }

            List <TransTypeDetailsAC> transTypeDetailsACs = new List <TransTypeDetailsAC>();
            List <string>             trasnTypes          = billdetails.GroupBy(x => x.TransType).Select(x => x.Key).ToList();

            foreach (var item in billmasters)
            {
                ProviderBillChartDetailAC providerBillChartDetailAC = new ProviderBillChartDetailAC();
                EnumList.Month            month = (EnumList.Month)item.BillMonth;
                providerBillChartDetailAC.MonthYears          = (month.ToString() + " " + item.BillYear);
                providerBillChartDetailAC.Currency            = item.Currency.Code;
                providerBillChartDetailAC.transTypeDetailsACs = GetTransTypeDetailsAC(trasnTypes);

                decimal?totalAmount = 0;
                foreach (var subItem in item.Billdetails.GroupBy(x => x.TransType))
                {
                    var transTypeDetails = providerBillChartDetailAC.transTypeDetailsACs.FirstOrDefault(x => x.TransType == subItem.Key);
                    transTypeDetails.BillAmount = 0;
                    if (transTypeDetails != null)
                    {
                        transTypeDetails.BillAmount = subItem.Sum(x => x.CallAmount);
                    }
                    else
                    {
                        transTypeDetails.BillAmount = 0;
                    }

                    totalAmount += transTypeDetails.BillAmount;
                }

                providerBillChartDetailAC.TotalAmount = Convert.ToDecimal(totalAmount);
                providerBillChartDetailACs.Add(providerBillChartDetailAC);
            }

            return(providerBillChartDetailACs);
        }
Exemplo n.º 2
0
        public async Task <List <ProviderWiseClosedBillAC> > GetProviderWiseLastClosedBillDetails()
        {
            var providerdata = (from provider in _dbTeleBilling_V01Context.Provider
                                join
                                providerservice in _dbTeleBilling_V01Context.Providerservice on provider.Id equals providerservice.ProviderId
                                where provider.IsDelete == false && providerservice.IsDelete == false && (providerservice.ServiceTypeId == 1 || providerservice.ServiceTypeId == 2 || providerservice.ServiceTypeId == 6 || providerservice.ServiceTypeId == 12)
                                select new TeleBillingUtility.Models.Provider
            {
                Id = provider.Id,
                Name = provider.Name
            }).ToList();


            List <ProviderWiseClosedBillAC> providerWiseClosedBillACs = new List <ProviderWiseClosedBillAC>();

            foreach (var item in providerdata)
            {
                if (!providerWiseClosedBillACs.Any(x => x.ProviderId == item.Id))
                {
                    ProviderWiseClosedBillAC providerWiseClosedBillAC = new ProviderWiseClosedBillAC();
                    int billClosed  = Convert.ToInt16(EnumList.BillStatus.BillClosed);
                    int memoCreated = Convert.ToInt16(EnumList.BillStatus.MemoCreated);

                    Billmaster billmasters = await _dbTeleBilling_V01Context.Billmaster.Where(x => x.ProviderId == item.Id && !x.IsDelete && (x.BillStatusId == billClosed || x.BillStatusId == memoCreated)).Include(x => x.Currency).OrderByDescending(x => x.Id).FirstOrDefaultAsync();

                    if (billmasters != null)
                    {
                        decimal?totalDeductableAmount = 0;
                        List <Employeebillmaster> employeebillmasters = await _dbTeleBilling_V01Context.Employeebillmaster.Where(x => !x.IsDelete && x.BillMasterId == billmasters.Id).Include(x => x.Employeebillservicepackage).ToListAsync();

                        foreach (var subItem in employeebillmasters)
                        {
                            totalDeductableAmount += subItem.Employeebillservicepackage.Sum(x => x.DeductionAmount);
                        }
                        providerWiseClosedBillAC.BillNumber = billmasters.BillNumber;
                        EnumList.Month month = (EnumList.Month)billmasters.BillMonth;
                        providerWiseClosedBillAC.MonthYear           = month.ToString() + " " + billmasters.BillYear;
                        providerWiseClosedBillAC.ProviderId          = item.Id;
                        providerWiseClosedBillAC.ProviderName        = item.Name;
                        providerWiseClosedBillAC.TotalBillAmount     = billmasters.BillAmount;
                        providerWiseClosedBillAC.EmployeeDeducatable = Convert.ToDecimal(totalDeductableAmount);
                        providerWiseClosedBillAC.CompanyPayable      = providerWiseClosedBillAC.TotalBillAmount - providerWiseClosedBillAC.EmployeeDeducatable;
                        providerWiseClosedBillAC.Currency            = billmasters.Currency.Code;
                        providerWiseClosedBillACs.Add(providerWiseClosedBillAC);
                    }
                }
            }
            return(providerWiseClosedBillACs);
        }
Exemplo n.º 3
0
        public async Task <List <BillAC> > GetAccountBills()
        {
            List <BillAC>             billACs             = new List <BillAC>();
            List <Employeebillmaster> employeeBillMasters = await _dbTeleBilling_V01Context.Employeebillmaster.Where(x => !x.IsDelete).Include(x => x.Currency).Include(x => x.Provider).Include(x => x.Employee).Include(x => x.EmpBusinessUnit).Include(x => x.Employee.CostCenter).Include(x => x.MobileAssignTypeNavigation).ToListAsync();

            if (employeeBillMasters.Any())
            {
                foreach (var item in employeeBillMasters)
                {
                    BillAC billAC = new BillAC();
                    billAC.Amount = item.TotalBillAmount;

                    if (item.MobileAssignTypeNavigation != null)
                    {
                        billAC.AssignedType = item.MobileAssignTypeNavigation.Name;
                    }

                    EnumList.Month monthEnum = (EnumList.Month)item.BillMonth;
                    billAC.BillDate = monthEnum.ToString() + " " + item.BillYear.ToString();
                    if (item.EmpBusinessUnitId != null)
                    {
                        billAC.BusinessUnit   = item.EmpBusinessUnit.Name;
                        billAC.BusinessUnitId = Convert.ToInt64(item.EmpBusinessUnitId);
                    }
                    billAC.Currency    = item.Currency.Code;
                    billAC.Description = item.Description;
                    if (item.EmployeeId != null)
                    {
                        billAC.EmployeeId   = Convert.ToInt64(item.EmployeeId);
                        billAC.EmployeeName = item.Employee.FullName;
                        billAC.CostCenter   = item.Employee.CostCenter.Name;
                        billAC.CostCenterId = item.Employee.CostCenterId;
                    }
                    billAC.MobileNumber = item.TelephoneNumber;
                    billAC.BillNumber   = item.BillNumber;
                    billAC.Month        = item.BillMonth;
                    billAC.Provider     = item.Provider.Name;
                    billAC.ProviderId   = item.ProviderId;
                    billAC.Year         = item.BillYear;
                    billAC.Status       = CommonFunction.GetDescriptionFromEnumValue(((EnumList.EmployeeBillStatus)item.EmployeeBillStatus));
                    billACs.Add(billAC);
                }
            }
            return(billACs);
        }
Exemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="employeeBillServicePackage"></param>
        /// <param name="employeeBillMasters"></param>
        private void SendEmailNotificationToEmployee(Employeebillservicepackage employeeBillServicePackage, Employeebillmaster employeeBillMaster)
        {
            if (!string.IsNullOrEmpty(employeeBillMaster.Employee.EmailId))
            {
                Dictionary <string, string> replacements = new Dictionary <string, string>();
                EnumList.Month month = (EnumList.Month)employeeBillMaster.BillMonth;
                replacements.Add("{BillNumber}", employeeBillMaster.BillNumber);
                replacements.Add("{BillMonth}", month.ToString());
                replacements.Add("{BillYear}", employeeBillMaster.BillYear.ToString());
                replacements.Add("{newEmpName}", employeeBillMaster.Employee.FullName);
                replacements.Add("{Provider}", employeeBillMaster.Provider.Name);
                string telphoneNumber = !string.IsNullOrEmpty(employeeBillMaster.TelephoneNumber) ? employeeBillMaster.TelephoneNumber.Trim() : string.Empty;
                replacements.Add("{TelePhoneNumber}", telphoneNumber);

                string deductionAmount = string.Empty;
                if (employeeBillServicePackage.DeductionAmount != null)
                {
                    deductionAmount = Convert.ToString(employeeBillServicePackage.DeductionAmount);
                }
                replacements.Add("{DeductionAmount}", deductionAmount);

                using (var _dbTeleBillingContext = new telebilling_v01Context())
                {
                    long          emailTemplateTypeId = Convert.ToInt64(EnumList.EmailTemplateType.SendEmailNotificationToEmployeForAmountToBeDeducted);
                    Emailtemplate emailTemplate       = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId);
                    if (emailTemplate != null && !string.IsNullOrEmpty(employeeBillMaster.Employee.EmailId))
                    {
                        string body = emailTemplate.EmailText;
                        replacements.ToList().ForEach(x =>
                        {
                            body = body.Replace(x.Key, Convert.ToString(x.Value));
                        });

                        if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, employeeBillMaster.Employee.EmailId))
                        {
                            AddedReminderNotificationLog(emailTemplate.Id, employeeBillMaster.Id, false, employeeBillMaster.Employee.EmailId);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        void timerReminder_Elapsed(object sender, ElapsedEventArgs e)
        {
            using (var _dbTeleBillingContext = new telebilling_v01Context())
            {
                int waitingForIdentificationStatus            = Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForIdentification);
                int waitingForLineManagerApprovalStatus       = Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval);
                List <Employeebillmaster> employeeBillMasters = _dbTeleBillingContext.Employeebillmaster.Where(x => !x.IsDelete && (x.EmployeeBillStatus == waitingForIdentificationStatus || x.EmployeeBillStatus == waitingForLineManagerApprovalStatus)).Include(x => x.Provider).Include(x => x.Employee).Include(x => x.Linemanager).Include(x => x.BillDelegatedEmp).ToList();
                Configuration             configuration       = _dbTeleBillingContext.Configuration.First();
                DateTime todaydate = DateTime.Now.Date;

                //mail sending only one time for bill identification
                if (configuration.NBillAllocationToEmployee)
                {
                    List <Employeebillmaster> employeeBillMastersForNotiIdentification = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForIdentificationStatus && x.CreatedDate.Date == todaydate).ToList();
                    if (employeeBillMastersForNotiIdentification.Any())
                    {
                        int           emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.EmployeeCallIdentificationNotification);
                        Emailtemplate emailTemplate       = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId);
                        if (emailTemplate != null)
                        {
                            foreach (var item in employeeBillMastersForNotiIdentification)
                            {
                                Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail);
                                if (emailReminderLog == null && !string.IsNullOrEmpty(item.Employee.EmailId))
                                {
                                    Dictionary <string, string> replacements = new Dictionary <string, string>();
                                    EnumList.Month month = (EnumList.Month)item.BillMonth;
                                    replacements.Add("{newEmpName}", item.Employee.FullName);
                                    replacements.Add("{BillNumber}", item.BillNumber);
                                    replacements.Add("{BillMonth}", month.ToString());
                                    replacements.Add("{Provider}", item.Provider.Name);
                                    replacements.Add("{BillYear}", item.BillYear.ToString());
                                    replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                    string body = emailTemplate.EmailText;
                                    replacements.ToList().ForEach(x =>
                                    {
                                        body = body.Replace(x.Key, Convert.ToString(x.Value));
                                    });

                                    if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Employee.EmailId))
                                    {
                                        AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.Employee.EmailId);
                                    }
                                }
                            }
                        }
                    }
                }

                //mail sending only one time for bill delegated identification
                if (configuration.NBillDelegatesForIdentification)
                {
                    List <Employeebillmaster> employeeBillMastersForDelgatedIdentification = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForIdentificationStatus && x.BillDelegatedEmpId != null).ToList();
                    if (employeeBillMastersForDelgatedIdentification.Any())
                    {
                        int           emailTemplateForDelegatedTypeId = Convert.ToInt16(EnumList.EmailTemplateType.BillDelegatesForIdentification);
                        Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateForDelegatedTypeId);
                        if (emailTemplate != null)
                        {
                            foreach (var item in employeeBillMastersForDelgatedIdentification)
                            {
                                Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail);
                                if (emailReminderLog == null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId))
                                {
                                    Dictionary <string, string> replacements = new Dictionary <string, string>();
                                    EnumList.Month month = (EnumList.Month)item.BillMonth;
                                    replacements.Add("{newEmpName}", item.BillDelegatedEmp.FullName);
                                    replacements.Add("{BillNumber}", item.BillNumber);
                                    replacements.Add("{BillMonth}", month.ToString());
                                    replacements.Add("{Provider}", item.Provider.Name);
                                    replacements.Add("{BillYear}", item.BillYear.ToString());

                                    string body = emailTemplate.EmailText;
                                    replacements.ToList().ForEach(x =>
                                    {
                                        body = body.Replace(x.Key, Convert.ToString(x.Value));
                                    });

                                    if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.BillDelegatedEmp.EmailId))
                                    {
                                        AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.BillDelegatedEmp.EmailId);
                                    }
                                }
                            }
                        }
                    }
                }

                //mail sending only one time for bill identification request approval to line manager
                if (configuration.NNewBillReceiveForApproval)
                {
                    List <Employeebillmaster> employeeBillMastersForbillApproval = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForLineManagerApprovalStatus && x.CreatedDate.Date == todaydate).ToList();
                    if (employeeBillMastersForbillApproval.Any())
                    {
                        int           emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.LineManagerApprovalNotification);
                        Emailtemplate emailTemplate       = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId);
                        if (emailTemplate != null)
                        {
                            foreach (var item in employeeBillMastersForbillApproval)
                            {
                                Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail);
                                if (emailReminderLog == null && !string.IsNullOrEmpty(item.Linemanager.EmailId))
                                {
                                    Dictionary <string, string> replacements = new Dictionary <string, string>();
                                    replacements.Add("{newEmpName}", item.Employee.FullName);
                                    EnumList.Month month = (EnumList.Month)item.BillMonth;
                                    replacements.Add("{BillNumber}", item.BillNumber);
                                    replacements.Add("{BillMonth}", month.ToString());
                                    replacements.Add("{BillYear}", item.BillYear.ToString());
                                    replacements.Add("{Provider}", item.Provider.Name);
                                    replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                    string body = emailTemplate.EmailText;
                                    replacements.ToList().ForEach(x =>
                                    {
                                        body = body.Replace(x.Key, Convert.ToString(x.Value));
                                    });

                                    if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Linemanager.EmailId))
                                    {
                                        AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.Linemanager.EmailId);
                                    }
                                }
                            }
                        }
                    }
                }

                //mail sending only one time for delegates bill identification request approval to line manager
                if (configuration.NDelegatesBillForApproval)
                {
                    List <Employeebillmaster> employeeBillMastersForDelegatesBillApproval = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForLineManagerApprovalStatus && x.CreatedDate.Date == todaydate && x.BillDelegatedEmpId != null).ToList();
                    if (employeeBillMastersForDelegatesBillApproval.Any())
                    {
                        int           emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.DelegateBillApproval);
                        Emailtemplate emailTemplate       = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId);
                        if (emailTemplate != null)
                        {
                            foreach (var item in employeeBillMastersForDelegatesBillApproval)
                            {
                                Emailreminderlog emailReminderLog = _dbTeleBillingContext.Emailreminderlog.FirstOrDefault(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && !x.IsReminderMail);
                                if (emailReminderLog == null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId))
                                {
                                    Dictionary <string, string> replacements = new Dictionary <string, string>();
                                    replacements.Add("{newEmpName}", item.Employee.FullName);
                                    EnumList.Month month = (EnumList.Month)item.BillMonth;
                                    replacements.Add("{BillNumber}", item.BillNumber);
                                    replacements.Add("{BillMonth}", month.ToString());
                                    replacements.Add("{BillYear}", item.BillYear.ToString());
                                    replacements.Add("{Provider}", item.Provider.Name);
                                    replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                    string body = emailTemplate.EmailText;
                                    replacements.ToList().ForEach(x =>
                                    {
                                        body = body.Replace(x.Key, Convert.ToString(x.Value));
                                    });

                                    if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.BillDelegatedEmp.EmailId))
                                    {
                                        AddedReminderNotificationLog(emailTemplate.Id, item.Id, false, item.BillDelegatedEmp.EmailId);
                                    }
                                }
                            }
                        }
                    }
                }

                //mail sending reminder in perticular interval for bill identification and also delegated employee
                if (configuration.REmployeeCallIdentificationIsActive)                //Included delgated employee
                {
                    List <Employeebillmaster> employeeBillMastersForREmpCllIdetification = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForIdentificationStatus).ToList();
                    if (employeeBillMastersForREmpCllIdetification.Any())
                    {
                        int emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.EmployeeCallIdentificationRemider);
                        int emailTemplateTypeForDelegateUserId = Convert.ToInt16(EnumList.EmailTemplateType.BillDelegatesForIdentification);

                        foreach (var item in employeeBillMastersForREmpCllIdetification)
                        {
                            DateTime         reminderDate     = new DateTime();
                            Emailreminderlog emailReminderLog = new Emailreminderlog();
                            //check bill delgated or not
                            if (item.BillDelegatedEmpId != null)
                            {
                                Emailtemplate emailTemplateForDelegateUser = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeForDelegateUserId);
                                if (emailTemplateForDelegateUser != null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId))
                                {
                                    emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplateForDelegateUser.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault();

                                    int intervalDay = configuration.REmployeeCallIdentificationInterval != null?Convert.ToInt32(configuration.REmployeeCallIdentificationInterval) : 0;

                                    if (emailReminderLog != null)
                                    {
                                        reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay);
                                    }
                                    else
                                    {
                                        reminderDate = item.CreatedDate.AddDays(intervalDay);
                                    }

                                    if (reminderDate.Date == DateTime.Now.Date)
                                    {
                                        Dictionary <string, string> replacements = new Dictionary <string, string>();
                                        replacements.Add("{newEmpName}", item.Employee.FullName);
                                        EnumList.Month month = (EnumList.Month)item.BillMonth;
                                        replacements.Add("{BillNumber}", item.BillNumber);
                                        replacements.Add("{Provider}", item.Provider.Name);
                                        replacements.Add("{BillMonth}", month.ToString());
                                        replacements.Add("{BillYear}", item.BillYear.ToString());
                                        replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                        string body = emailTemplateForDelegateUser.EmailText;
                                        replacements.ToList().ForEach(x =>
                                        {
                                            body = body.Replace(x.Key, Convert.ToString(x.Value));
                                        });

                                        if (SendEmail(emailTemplateForDelegateUser.EmailFrom, emailTemplateForDelegateUser.EmailBcc, emailTemplateForDelegateUser.Subject, body, item.BillDelegatedEmp.EmailId))
                                        {
                                            AddedReminderNotificationLog(emailTemplateForDelegateUser.Id, item.Id, true, item.BillDelegatedEmp.EmailId);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                Emailtemplate emailTemplate = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId);
                                if (emailTemplate != null && !string.IsNullOrEmpty(item.Employee.EmailId))
                                {
                                    emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault();

                                    int intervalDay = configuration.REmployeeCallIdentificationInterval != null?Convert.ToInt32(configuration.REmployeeCallIdentificationInterval) : 0;

                                    if (emailReminderLog != null)
                                    {
                                        reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay);
                                    }
                                    else
                                    {
                                        reminderDate = item.CreatedDate.AddDays(intervalDay);
                                    }

                                    if (reminderDate.Date == DateTime.Now.Date)
                                    {
                                        Dictionary <string, string> replacements = new Dictionary <string, string>();
                                        replacements.Add("{newEmpName}", item.Employee.FullName);
                                        EnumList.Month month = (EnumList.Month)item.BillMonth;
                                        replacements.Add("{BillNumber}", item.BillNumber);
                                        replacements.Add("{BillMonth}", month.ToString());
                                        replacements.Add("{BillYear}", item.BillYear.ToString());
                                        replacements.Add("{Provider}", item.Provider.Name);
                                        replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                        string body = emailTemplate.EmailText;
                                        replacements.ToList().ForEach(x =>
                                        {
                                            body = body.Replace(x.Key, Convert.ToString(x.Value));
                                        });

                                        if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Employee.EmailId))
                                        {
                                            AddedReminderNotificationLog(emailTemplate.Id, item.Id, true, item.Employee.EmailId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                //mail sending reminder perticular interval for bill identification request approval to line manager
                if (configuration.RLinemanagerApprovalIsActive)
                {
                    List <Employeebillmaster> employeeBillMastersForRLineManager = employeeBillMasters.Where(x => !x.IsDelete && x.EmployeeBillStatus == waitingForLineManagerApprovalStatus).ToList();
                    if (employeeBillMastersForRLineManager.Any())
                    {
                        foreach (var item in employeeBillMastersForRLineManager)
                        {
                            DateTime         reminderDate     = new DateTime();
                            Emailreminderlog emailReminderLog = new Emailreminderlog();
                            //check bill delgated or not
                            if (item.BillDelegatedEmpId != null)
                            {
                                int           emailTemplateDelegateTypeId  = Convert.ToInt16(EnumList.EmailTemplateType.DelegateBillApproval);
                                Emailtemplate emailTemplateForDelegateUser = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateDelegateTypeId);
                                if (emailTemplateForDelegateUser != null && !string.IsNullOrEmpty(item.BillDelegatedEmp.EmailId))
                                {
                                    emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplateForDelegateUser.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault();

                                    int intervalDay = configuration.RLinemanagerApprovalInterval != null?Convert.ToInt32(configuration.RLinemanagerApprovalInterval) : 0;

                                    if (emailReminderLog != null)
                                    {
                                        reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay);
                                    }
                                    else
                                    {
                                        reminderDate = item.CreatedDate.AddDays(intervalDay);
                                    }

                                    if (reminderDate.Date == DateTime.Now.Date)
                                    {
                                        Dictionary <string, string> replacements = new Dictionary <string, string>();
                                        replacements.Add("{newEmpName}", item.Employee.FullName);
                                        EnumList.Month month = (EnumList.Month)item.BillMonth;
                                        replacements.Add("{BillNumber}", item.BillNumber);
                                        replacements.Add("{BillMonth}", month.ToString());
                                        replacements.Add("{BillYear}", item.BillYear.ToString());
                                        replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                        string body = emailTemplateForDelegateUser.EmailText;
                                        replacements.ToList().ForEach(x =>
                                        {
                                            body = body.Replace(x.Key, Convert.ToString(x.Value));
                                        });

                                        if (SendEmail(emailTemplateForDelegateUser.EmailFrom, emailTemplateForDelegateUser.EmailBcc, emailTemplateForDelegateUser.Subject, body, item.BillDelegatedEmp.EmailId))
                                        {
                                            AddedReminderNotificationLog(emailTemplateForDelegateUser.Id, item.Id, true, item.BillDelegatedEmp.EmailId);
                                        }
                                    }
                                }
                            }
                            else
                            {
                                int           emailTemplateTypeId = Convert.ToInt16(EnumList.EmailTemplateType.LineManagerApprovalRemider);
                                Emailtemplate emailTemplate       = _dbTeleBillingContext.Emailtemplate.FirstOrDefault(x => x.EmailTemplateTypeId == emailTemplateTypeId);

                                if (emailTemplate != null && !string.IsNullOrEmpty(item.Linemanager.EmailId))
                                {
                                    emailReminderLog = _dbTeleBillingContext.Emailreminderlog.Where(x => x.EmployeeBillId == item.Id && x.TemplateId == emailTemplate.Id && x.IsReminderMail).OrderByDescending(x => x.CreatedDateInt).FirstOrDefault();

                                    int intervalDay = configuration.RLinemanagerApprovalInterval != null?Convert.ToInt32(configuration.RLinemanagerApprovalInterval) : 0;

                                    if (emailReminderLog != null)
                                    {
                                        reminderDate = emailReminderLog.CreatedDate.AddDays(intervalDay);
                                    }
                                    else
                                    {
                                        reminderDate = item.CreatedDate.AddDays(intervalDay);
                                    }

                                    if (reminderDate.Date == DateTime.Now.Date)
                                    {
                                        Dictionary <string, string> replacements = new Dictionary <string, string>();
                                        replacements.Add("{newEmpName}", item.Employee.FullName);
                                        EnumList.Month month = (EnumList.Month)item.BillMonth;
                                        replacements.Add("{BillNumber}", item.BillNumber);
                                        replacements.Add("{BillMonth}", month.ToString());
                                        replacements.Add("{BillYear}", item.BillYear.ToString());
                                        replacements.Add("{TelePhoneNumber}", item.TelephoneNumber.Trim());

                                        string body = emailTemplate.EmailText;
                                        replacements.ToList().ForEach(x =>
                                        {
                                            body = body.Replace(x.Key, Convert.ToString(x.Value));
                                        });

                                        if (SendEmail(emailTemplate.EmailFrom, emailTemplate.EmailBcc, emailTemplate.Subject, body, item.Linemanager.EmailId))
                                        {
                                            AddedReminderNotificationLog(emailTemplate.Id, item.Id, true, item.Linemanager.EmailId);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public async Task <ResponseAC> AddMemo(MemoAC memoAC, long userId, string loginUserName)
        {
            ResponseAC responseAC = new ResponseAC();
            Memo       memo       = _mapper.Map <Memo>(memoAC);

            memo.Id            = 0;
            memo.CreatedBy     = userId;
            memo.CreatedDate   = DateTime.Now;
            memo.TransactionId = _iLogManagement.GenerateTeleBillingTransctionID();
            memo.RefrenceNo    = memoAC.ProviderName + "/INV/" + memoAC.Month + "/" + memo.Year;
            _dbTeleBilling_V01Context.Add(memo);
            await _dbTeleBilling_V01Context.SaveChangesAsync();

            List <Memobills>  billMemos   = new List <Memobills>();
            List <Billmaster> billMasters = new List <Billmaster>();

            foreach (long item in memoAC.BillIds)
            {
                Memobills memoBill = new Memobills();
                memoBill.BillId        = item;
                memoBill.MemoId        = memo.Id;
                memoBill.TransactionId = memo.TransactionId;
                memoBill.CreatedBy     = userId;
                memoBill.CreatedDate   = DateTime.Now;
                billMemos.Add(memoBill);

                Billmaster billMaster = await _dbTeleBilling_V01Context.Billmaster.FirstOrDefaultAsync(x => x.Id == item);

                billMaster.UpdatedBy    = userId;
                billMaster.BillStatusId = Convert.ToInt16(EnumList.BillStatus.MemoCreated);
                billMaster.UpdatedDate  = DateTime.Now;
                billMasters.Add(billMaster);
            }

            if (billMemos.Any())
            {
                await _dbTeleBilling_V01Context.AddRangeAsync(billMemos);

                await _dbTeleBilling_V01Context.SaveChangesAsync();
            }


            if (billMasters.Any())
            {
                _dbTeleBilling_V01Context.UpdateRange(billMasters);
                await _dbTeleBilling_V01Context.SaveChangesAsync();

                memo = await _dbTeleBilling_V01Context.Memo.Where(x => x.Id == memo.Id && !x.IsDelete).Include(x => x.Provider).FirstOrDefaultAsync();

                #region Send Mail For Create Memo
                TeleBillingUtility.Models.Configuration configuration = await _dbTeleBilling_V01Context.Configuration.FirstOrDefaultAsync();

                List <MstEmployee> mstEmployees = await _dbTeleBilling_V01Context.MstEmployee.Where(x => !x.IsDelete && x.IsActive && x.IsPresidentOffice).ToListAsync();

                if (configuration != null && configuration.NSendMemo)
                {
                    foreach (var item in billMasters)
                    {
                        if (mstEmployees.Any())
                        {
                            foreach (var employee in mstEmployees)
                            {
                                if (!string.IsNullOrEmpty(employee.EmailId))
                                {
                                    Emailtemplate emailTemplate = new Emailtemplate();
                                    Dictionary <string, string> replacements = new Dictionary <string, string>();
                                    EnumList.Month month = (EnumList.Month)item.BillMonth;

                                    replacements.Add("{BillMonth}", month.ToString());
                                    replacements.Add("{BillYear}", item.BillYear.ToString());
                                    replacements.Add("{RefrenceNo}", memo.RefrenceNo);
                                    replacements.Add("{newEmpName}", employee.FullName);
                                    replacements.Add("{MemoSubject}", memo.Subject);
                                    replacements.Add("{BillNumber}", item.BillNumber);
                                    replacements.Add("{BillAmount}", memo.TotalAmount.ToString());
                                    replacements.Add("{Provider}", memo.Provider.Name);

                                    if (await _iEmailSender.SendEmail(Convert.ToInt64(EnumList.EmailTemplateType.SendMemo), replacements, employee.EmailId))
                                    {
                                        await _iEmailSender.AddedReminderNotificationLog(Convert.ToInt64(EnumList.EmailTemplateType.SendMemo), null, false, employee.EmailId);
                                    }
                                }
                            }
                        }
                    }
                }
                #endregion


                #region Notification For Memo
                List <Notificationlog> notificationlogs = new List <Notificationlog>();
                if (mstEmployees.Any())
                {
                    foreach (var item in mstEmployees)
                    {
                        notificationlogs.Add(_iLogManagement.GenerateNotificationObject(item.UserId, userId, Convert.ToInt16(EnumList.NotificationType.SendMemo), memo.Id));
                    }
                    await _iLogManagement.SaveNotificationList(notificationlogs);
                }
                #endregion
            }

            await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.AddMemo, loginUserName, userId, "Memo(" + memo.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Add, memo.Id);

            responseAC.Message    = _iStringConstant.MemoAddedsuccessfully;
            responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);

            return(responseAC);
        }
Exemplo n.º 7
0
        public async Task <ResponseAC> MemoApproval(MemoApprovalAC memoApprovalAC, long userId, string loginUserName)
        {
            ResponseAC        responseAC      = new ResponseAC();
            List <Memo>       lstMemo         = new List <Memo>();
            List <Billmaster> billMasters     = new List <Billmaster>();
            List <string>     stringMemoArray = new List <string>();

            foreach (var item in memoApprovalAC.billMemoACs)
            {
                Memo memoObj = await _dbTeleBilling_V01Context.Memo.Where(x => x.Id == item.Id).Include(x => x.Provider).FirstOrDefaultAsync();

                if (memoObj.IsApproved == null)
                {
                    memoObj.IsApproved   = memoApprovalAC.IsApprvoed;
                    memoObj.ApprovedDate = DateTime.Now;
                    memoObj.ApprovedBy   = userId;
                    memoObj.Comment      = item.Comment;
                    memoObj.UpdatedBy    = userId;
                    memoObj.UpdatedDate  = DateTime.Now;
                    lstMemo.Add(memoObj);

                    string memoApproval = string.Empty;
                    if (!memoApprovalAC.IsApprvoed)
                    {
                        billMasters.AddRange(await _dbTeleBilling_V01Context.Memobills.Where(x => x.MemoId == item.Id && !x.IsDelete).Include(x => x.Bill).Select(x => x.Bill).ToListAsync());
                        memoApproval = "Rejected";
                    }
                    else
                    {
                        memoApproval = "Approved";
                    }

                    #region Send Mail For Memo Approval
                    TeleBillingUtility.Models.Configuration configuration = await _dbTeleBilling_V01Context.Configuration.FirstOrDefaultAsync();

                    MstEmployee mstEmployee = await _dbTeleBilling_V01Context.MstEmployee.FirstOrDefaultAsync(x => !x.IsDelete && x.UserId == memoObj.CreatedBy);

                    if (configuration != null && configuration.NMemoApprovalRejection)
                    {
                        if (mstEmployee != null)
                        {
                            if (!string.IsNullOrEmpty(mstEmployee.EmailId))
                            {
                                Dictionary <string, string> replacements = new Dictionary <string, string>();
                                EnumList.Month month = (EnumList.Month)memoObj.Month;
                                replacements.Add("{MemoApproval}", memoApproval);
                                replacements.Add("{BillMonth}", month.ToString());
                                replacements.Add("{BillYear}", memoObj.Year.ToString());
                                replacements.Add("{RefrenceNo}", memoObj.RefrenceNo);
                                replacements.Add("{newEmpName}", mstEmployee.FullName);
                                replacements.Add("{ApprovalComment}", memoObj.Comment);
                                replacements.Add("{BillAmount}", memoObj.TotalAmount.ToString());
                                replacements.Add("{MemoSubject}", memoObj.Subject);
                                replacements.Add("{Provider}", memoObj.Provider.Name);

                                if (await _iEmailSender.SendEmail(Convert.ToInt64(EnumList.EmailTemplateType.MemoApproval), replacements, mstEmployee.EmailId))
                                {
                                    await _iEmailSender.AddedReminderNotificationLog(Convert.ToInt64(EnumList.EmailTemplateType.MemoApproval), null, false, mstEmployee.EmailId);
                                }
                            }
                        }
                    }
                    #endregion

                    #region Notification For Memo
                    List <Notificationlog> notificationlogs = new List <Notificationlog>();
                    if (mstEmployee != null)
                    {
                        if (memoApprovalAC.IsApprvoed)
                        {
                            notificationlogs.Add(_iLogManagement.GenerateNotificationObject(mstEmployee.UserId, userId, Convert.ToInt16(EnumList.NotificationType.MemoApprove), memoObj.Id));
                            await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.MemoApprove, loginUserName, userId, "Memo(" + memoObj.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Approve, memoObj.Id);
                        }
                        else
                        {
                            notificationlogs.Add(_iLogManagement.GenerateNotificationObject(mstEmployee.UserId, userId, Convert.ToInt16(EnumList.NotificationType.MemoReject), memoObj.Id));
                            await _iLogManagement.SaveAuditActionLog((int)EnumList.AuditLogActionType.MemoReject, loginUserName, userId, "Memo(" + memoObj.RefrenceNo + ")", (int)EnumList.ActionTemplateTypes.Reject, memoObj.Id);
                        }
                        await _iLogManagement.SaveNotificationList(notificationlogs);
                    }
                    #endregion
                }
                else
                {
                    stringMemoArray.Add(memoObj.RefrenceNo);
                }
            }
            #region Update Bill Status
            if (billMasters.Any())
            {
                foreach (var item in billMasters)
                {
                    item.BillStatusId = Convert.ToInt16(EnumList.BillStatus.BillAllocated);
                    item.UpdatedBy    = userId;
                    item.UpdatedDate  = DateTime.Now;
                }

                _dbTeleBilling_V01Context.UpdateRange(billMasters);
                await _dbTeleBilling_V01Context.SaveChangesAsync();
            }
            #endregion

            if (lstMemo.Any())
            {
                _dbTeleBilling_V01Context.UpdateRange(lstMemo);
                await _dbTeleBilling_V01Context.SaveChangesAsync();
            }

            if (lstMemo.Count() == memoApprovalAC.billMemoACs.Count())
            {
                responseAC.Message    = memoApprovalAC.IsApprvoed ? _iStringConstant.MemoApprovedsuccessfully : _iStringConstant.MemoRejectedsuccessfully;
                responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Success);
            }
            else
            {
                string message = String.Join(',', stringMemoArray);
                responseAC.Message    = memoApprovalAC.IsApprvoed ? _iStringConstant.MemoApprovalMessagesuccessfully.Replace("{{@currentapproval}}", "approved").Replace("{{@memo}}", message) : _iStringConstant.MemoApprovalMessagesuccessfully.Replace("{{@currentapproval}}", "rejected").Replace("{{@memo}}", message);
                responseAC.StatusCode = Convert.ToInt16(EnumList.ResponseType.Warning);
            }
            return(responseAC);
        }