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); }
void timerBillClosed_Elapsed(object sender, ElapsedEventArgs e) { using (var _dbTeleBillingContext = new telebilling_v01Context()) { try { int billAllocatedStatusId = Convert.ToInt16(EnumList.BillStatus.BillAllocated); List <Billmaster> billMasters = _dbTeleBillingContext.Billmaster.Where(x => !x.IsDelete && (x.BillStatusId == billAllocatedStatusId)).ToList(); if (billMasters.Any()) { foreach (var item in billMasters) { if (item.BillDueDate != null) { if (Convert.ToDateTime(item.BillDueDate).Date < DateTime.Now.Date) { int billCloseStatusId = Convert.ToInt16(EnumList.EmployeeBillStatus.CloseBill); int billAutoCloseBillStatusId = Convert.ToInt16(EnumList.EmployeeBillStatus.AutoCloseBill); List <Employeebillmaster> employeeBillMasters = _dbTeleBillingContext.Employeebillmaster.Where(x => x.BillMasterId == item.Id && !x.IsDelete && (x.EmployeeBillStatus != billCloseStatusId && x.EmployeeBillStatus != billAutoCloseBillStatusId)).Include(x => x.Employee).Include(x => x.Provider).ToList(); List <Notificationlog> notificationlogs = new List <Notificationlog>(); if (employeeBillMasters.Any()) { foreach (var subItem in employeeBillMasters) { #region Transaction Log Entry if (subItem.TransactionId == null) { subItem.TransactionId = GenerateTeleBillingTransctionID(); } //var jsonSerailzeObj = JsonConvert.SerializeObject(subItem); //SaveRequestTraseLog(Convert.ToInt64(subItem.TransactionId), 0, Convert.ToInt64(EnumList.TransactionTraseLog.BillClosed), jsonSerailzeObj); #endregion List <Employeebillservicepackage> employeeBillServicePackages = _dbTeleBillingContext.Employeebillservicepackage.Where(x => x.EmployeeBillId == subItem.Id && !x.IsDelete).Include(x => x.Package).ToList(); foreach (var employeeBillServicePackage in employeeBillServicePackages) { if (!subItem.Employee.IsPresidentOffice) { if (string.IsNullOrEmpty(subItem.TelephoneNumber)) //For Skyp { //for service landline or voip if (employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.VOIP) || employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.MOC)) { if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForIdentification) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.BillReject)) { List <Billdetails> billdetails = _dbTeleBillingContext.Billdetails.Where(x => x.EmployeeBillId == subItem.Id && x.ServiceTypeId == employeeBillServicePackage.ServiceTypeId).ToList(); decimal personalDeduction = 0; decimal businessCharge = 0; foreach (var subBillDetail in billdetails) { if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Business)) { businessCharge += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0; } else if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Employee)) { personalDeduction += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0; } } employeeBillServicePackage.PersonalIdentificationAmount = personalDeduction; employeeBillServicePackage.BusinessIdentificationAmount = businessCharge; employeeBillServicePackage.DeductionAmount = personalDeduction; } else if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.LineManagerApproved)) { employeeBillServicePackage.DeductionAmount = employeeBillServicePackage.PersonalIdentificationAmount; } SendEmailNotificationToEmployee(employeeBillServicePackage, subItem); } } else { var telephoneNumberAllocation = _dbTeleBillingContext.Telephonenumberallocation.FirstOrDefault(x => x.TelephoneNumber == subItem.TelephoneNumber && x.EmployeeId == subItem.EmployeeId && !x.IsDelete); if (telephoneNumberAllocation.AssignTypeId != Convert.ToInt16(EnumList.AssignType.Business)) { employeeBillServicePackage.DeductionAmount = 0; List <Billdetails> billDetails = _dbTeleBillingContext.Billdetails.Where(x => x.EmployeeBillId == subItem.Id && x.ServiceTypeId == employeeBillServicePackage.ServiceTypeId).ToList(); decimal totalAmount = billDetails.Sum(x => x.CallAmount).Value; //for service landline if (employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.LandLine) || employeeBillServicePackage.ServiceTypeId == Convert.ToInt64(EnumList.ServiceType.StaticIP)) { //remaning employeeBillServicePackage.DeductionAmount = employeeBillServicePackage.PersonalIdentificationAmount; SendEmailNotificationToEmployee(employeeBillServicePackage, subItem); } else { if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForIdentification) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.BillReject)) { if (employeeBillServicePackage.Package.PackageAmount < totalAmount) { decimal amount = 0; decimal businessIdentificationAmount = employeeBillServicePackage.BusinessIdentificationAmount != null?Convert.ToDecimal(employeeBillServicePackage.BusinessIdentificationAmount) : 0; if (employeeBillServicePackage.Package.PackageAmount < businessIdentificationAmount) { amount = businessIdentificationAmount; } else { amount = employeeBillServicePackage.Package.PackageAmount != null?Convert.ToDecimal(employeeBillServicePackage.Package.PackageAmount) : 0; } //BusinessIdentificationAmount alway less than or equal Package Amount employeeBillServicePackage.DeductionAmount = totalAmount - amount; SendEmailNotificationToEmployee(employeeBillServicePackage, subItem); } else { employeeBillServicePackage.DeductionAmount = 0; } } else if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval) || subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.LineManagerApproved)) { if (subItem.EmployeeBillStatus == Convert.ToInt16(EnumList.EmployeeBillStatus.WaitingForLineManagerApproval)) { List <Billdetails> billdetails = _dbTeleBillingContext.Billdetails.Where(x => x.EmployeeBillId == subItem.Id).ToList(); var serviceBillDetials = billdetails.GroupBy(x => x.ServiceTypeId); var finalServiceDetails = serviceBillDetials.Where(x => x.Key == employeeBillServicePackage.ServiceTypeId); foreach (var billDetailsData in finalServiceDetails) { decimal personalDeduction = 0; decimal businessCharge = 0; foreach (var subBillDetail in billDetailsData) { if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Business)) { businessCharge += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0; } else if (subBillDetail.CallIdentificationType == Convert.ToInt16(EnumList.AssignType.Employee)) { personalDeduction += subBillDetail.CallAmount != null?Convert.ToDecimal(subBillDetail.CallAmount) : 0; } } employeeBillServicePackage.PersonalIdentificationAmount = personalDeduction; employeeBillServicePackage.BusinessIdentificationAmount = businessCharge; } } if (employeeBillServicePackage.Package.PackageAmount < totalAmount) { decimal businessIdentificationAmount = employeeBillServicePackage.BusinessIdentificationAmount != null?Convert.ToDecimal(employeeBillServicePackage.BusinessIdentificationAmount) : 0; decimal amount = 0; if (employeeBillServicePackage.Package.PackageAmount < businessIdentificationAmount) { amount = businessIdentificationAmount; } else { amount = employeeBillServicePackage.Package.PackageAmount != null?Convert.ToDecimal(employeeBillServicePackage.Package.PackageAmount) : 0; } employeeBillServicePackage.DeductionAmount = totalAmount - amount; SendEmailNotificationToEmployee(employeeBillServicePackage, subItem); } } } } else { employeeBillServicePackage.DeductionAmount = 0; } } } else { employeeBillServicePackage.DeductionAmount = 0; } employeeBillServicePackage.UpdateDate = DateTime.Now; } _dbTeleBillingContext.UpdateRange(employeeBillServicePackages); _dbTeleBillingContext.SaveChanges(); subItem.EmployeeBillStatus = Convert.ToInt16(EnumList.EmployeeBillStatus.AutoCloseBill); subItem.UpdatedDate = DateTime.Now; subItem.BillClosedDate = DateTime.Now; #region Notification FOR Bill Close notificationlogs.Add(GenerateNotificationObject(Convert.ToInt16(subItem.EmployeeId), 1, Convert.ToInt16(EnumList.NotificationType.BillClosed), subItem.Id)); #endregion } if (notificationlogs.Any()) { _dbTeleBillingContext.AddRange(notificationlogs); _dbTeleBillingContext.SaveChanges(); } _dbTeleBillingContext.UpdateRange(employeeBillMasters); _dbTeleBillingContext.SaveChanges(); Billmaster billMaster = _dbTeleBillingContext.Billmaster.FirstOrDefault(x => x.Id == employeeBillMasters[0].BillMasterId && !x.IsDelete); if (billMaster != null) { billMaster.BillStatusId = Convert.ToInt16(EnumList.BillStatus.BillClosed); billMaster.UpdatedDate = DateTime.Now; _dbTeleBillingContext.Update(billMaster); _dbTeleBillingContext.SaveChanges(); } } } } } } } catch (global::System.Exception ex) { throw ex; } } }
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); }