NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

private CommissionModelForHourlyEmployee CreateCommissionForHourlyEmployee(CandidatesRecordModel item, string startDate, string endDate,
DateTime parsedStartDate, DateTime parsedEndDate, List<DivisionCode> empForms, List<ECHoursHelper> externalConsultingHoursHelper, List<W2HoursHelper> w2HoursHelperAsync,
List<USA1099HoursHelper> usa1099HoursHelperAsync, List<PR480PayrollHelper> pr480PayrollHelperAsync, List<EmployeeTimesheet> employeeTimesheets,
List<InvoiceHoursHelper> invoiceHoursHelper, List<HRTable> getHRDetailsAsync, List<AccountManager> getAccountManagersAsync, List<ManagerAssociatedEmployee> managerAssociatedEmployeeAsync)
{
try
{
CommissionModelForHourlyEmployee commissionModelForHourlyEmployee = new();
if (item.Division != null)
{
var empForm = empForms.Where(d => d.DivisionCodes == item.Division).Select(s => s.DivisionName).FirstOrDefault();
if (empForm != null)
{
commissionModelForHourlyEmployee.Form = empForm;
}
}

var hrDetails = getHRDetailsAsync.FirstOrDefault(x => x.EmployeeId == item.CandidateId);
if (!String.IsNullOrEmpty(hrDetails?.FirstName) && !String.IsNullOrEmpty(hrDetails?.LastName) && hrDetails.FirstName != hrDetails.LastName)
{
commissionModelForHourlyEmployee.LastName = hrDetails.LastName;
commissionModelForHourlyEmployee.FirstName = hrDetails.FirstName;
commissionModelForHourlyEmployee.ITEM = $"{hrDetails.FirstName} {hrDetails.LastName}";
}
else
{
commissionModelForHourlyEmployee.LastName = item.LastName;
commissionModelForHourlyEmployee.FirstName = item.FirstName;
commissionModelForHourlyEmployee.ITEM = $"{item.FirstName} {item.LastName}";
}
commissionModelForHourlyEmployee.Customer = item.CompanyName;

if (item.BillRatePer != null && item.BillRate != null)
{
decimal billRate = Convert.ToDecimal(objectCalculation.GetCostosBillRate(item.BillRatePer, item.BillRate));
if (billRate != 0)
{
commissionModelForHourlyEmployee.PriceBillRate = $"${billRate.ToString(AppConstants.DefaultFiveDigits)}";
commissionModelForHourlyEmployee.BillRate = billRate.ToString();
}
}
var invoiceHrsHelper = invoiceHoursHelper.Where(x => x.StartId == item.BillingStartId).FirstOrDefault();

commissionModelForHourlyEmployee.EmployeeId = item.CandidateId;
commissionModelForHourlyEmployee.StartId = item.BillingStartId;
commissionModelForHourlyEmployee.RecId = item.BillingRecId;

if (startDate != AppConstants.RepositoryDefaultDate && endDate != AppConstants.RepositoryDefaultDate)
{
if (parsedStartDate != DateTime.MinValue && parsedEndDate != DateTime.MinValue)
{
commissionModelForHourlyEmployee.ServiceDate = parsedEndDate.ToString(InvoiceConstants.DateFormat);

var ecHoursHelper = externalConsultingHoursHelper.Where(x => x.StartId == item.SalaryStartId).FirstOrDefault();
decimal ecVariableHours = Convert.ToDecimal(ecHoursHelper?.VariableHours);

var w2HoursHelper = w2HoursHelperAsync.Where(x => x.StartId == item.SalaryStartId).FirstOrDefault();
decimal w2VariableHours = Convert.ToDecimal(w2HoursHelper?.VariableHours);

var usa1099HoursHelper = usa1099HoursHelperAsync.Where(x => x.StartId == item.SalaryStartId).FirstOrDefault();
decimal usa1099VariableHours = Convert.ToDecimal(usa1099HoursHelper?.VariableHours);

var pr480HoursHelper = pr480PayrollHelperAsync.Where(x => x.StartId == item.SalaryStartId).FirstOrDefault();
decimal pr480VariableHours = Convert.ToDecimal(pr480HoursHelper?.VariableHours);

switch (item.Division)
{
case AppConstants.ECHoursDivisionCode:
if (invoiceHrsHelper?.VariableHours != null)
{
decimal variableHours = Convert.ToDecimal(invoiceHrsHelper?.VariableHours);
commissionModelForHourlyEmployee.VariableHours = variableHours.ToString(AppConstants.DefaultTwoDigits);
}
else if (ecVariableHours != 0)
{
commissionModelForHourlyEmployee.VariableHours = ecVariableHours.ToString(AppConstants.DefaultTwoDigits);
}
break;
case AppConstants.W2HoursDivisionCode:
if (invoiceHrsHelper?.VariableHours != null)
{
decimal variableHours = Convert.ToDecimal(invoiceHrsHelper?.VariableHours);
commissionModelForHourlyEmployee.VariableHours = variableHours.ToString(AppConstants.DefaultTwoDigits);
}
else if (w2VariableHours != 0)
{
commissionModelForHourlyEmployee.VariableHours = w2VariableHours.ToString(AppConstants.DefaultTwoDigits);
}
break;
case AppConstants.USA1099DivisionCode:
if (invoiceHrsHelper?.VariableHours != null)
{
commissionModelForHourlyEmployee.VariableHours = invoiceHrsHelper.VariableHours;
}
else if (usa1099VariableHours != 0)
{
decimal variableHours = Convert.ToDecimal(invoiceHrsHelper?.VariableHours);
commissionModelForHourlyEmployee.VariableHours = variableHours.ToString(AppConstants.DefaultTwoDigits);
}
break;
case AppConstants.PR480DivisionCode:
if (invoiceHrsHelper?.VariableHours != null)
{
decimal variableHours = Convert.ToDecimal(invoiceHrsHelper?.VariableHours);
commissionModelForHourlyEmployee.VariableHours = variableHours.ToString(AppConstants.DefaultTwoDigits);
}
else if (pr480VariableHours != 0)
{
commissionModelForHourlyEmployee.VariableHours = pr480VariableHours.ToString(AppConstants.DefaultTwoDigits);
}
break;
default:
break;
}

var employeeTimesheet = employeeTimesheets.Where(x => x.StartId == item.SalaryStartId && x.BillRate == commissionModelForHourlyEmployee.BillRate && x.BillingRecdId == item.BillingRecId).ToList();
decimal totalRegHours = employeeTimesheet.Sum(x => Convert.ToDecimal(x.RegHours) + Convert.ToDecimal(x.OtHours));

decimal subTotalHours = totalRegHours + Convert.ToDecimal(commissionModelForHourlyEmployee.VariableHours);

if (item.BillRatePer == "H")
{
commissionModelForHourlyEmployee.QuantityTotalHours = (subTotalHours).ToString(AppConstants.DefaultOneDigits).Replace(".0", string.Empty);
}
else
{
commissionModelForHourlyEmployee.QuantityTotalHours = AppConstants.OneSixZero;
}

DateTime strDate = Convert.ToDateTime(item.BillingStartDate); //new added
var strYear = strDate.Year;
var strMonth = strDate.Month;

var parsedStrYear = parsedStartDate.Year;
var parsedStrMonth = parsedStartDate.Month;

DateTime endsDate = string.IsNullOrEmpty(item.BillingEndDate) ? DateTime.MinValue : Convert.ToDateTime(item.BillingEndDate);
int endYear = endsDate.Year;
int endMonth = endsDate.Month;

var parsedEndYear = parsedEndDate.Year;
var parsedEndMonth = parsedEndDate.Month;

decimal amount = 0;
decimal billRate = Convert.ToDecimal(commissionModelForHourlyEmployee.PriceBillRate?.Replace(@"$", string.Empty));

if (item.BillRatePer != null && item.BillRate != null)
{
if (item.BillRatePer == "H")
{
//amount = subTotalHours * billRate;
amount = 160 * billRate;
commissionModelForHourlyEmployee.Amount = $"${amount.ToString(AppConstants.DefaultFiveDigits)}";
}
else
{
decimal salaryEmp = Convert.ToDecimal(objectCalculation.GetExternalConsultingSalaryForInvoice(item.BillRatePer, item.BillRate));
decimal priceBillRate = salaryEmp / 160;
commissionModelForHourlyEmployee.PriceBillRate = $"${priceBillRate.ToString(AppConstants.DefaultTwoDigits)}";
// Case 1: Candidate joined before parsedStartDate, and SalaryEndDate is null or empty
if (strDate < parsedStartDate && string.IsNullOrEmpty(item.BillingEndDate) || endsDate >= parsedEndDate)
{
amount = salaryEmp;
commissionModelForHourlyEmployee.Amount = $"${salaryEmp}";
}
// Case 2: Candidate joined after parsedStartDate, and SalaryEndDate is null or empty
else if (strDate >= parsedStartDate && string.IsNullOrEmpty(item.BillingEndDate))
{
var numberOfDays = (parsedEndDate - strDate).TotalDays;
decimal amountOneDay = (Convert.ToDecimal(salaryEmp)) / 30;
amount = (amountOneDay * Convert.ToDecimal(numberOfDays));
commissionModelForHourlyEmployee.Amount = $"${amount.ToString(AppConstants.DefaultFiveDigits)}";
}
// Case 3: Candidate joined before parsedStartDate and left on SalaryEndDate
else if (strDate < parsedStartDate && endsDate <= parsedEndDate)
{
var numberOfDays = (endsDate - parsedStartDate).TotalDays;
decimal amountOneDay = (Convert.ToDecimal(salaryEmp)) / 30;
amount = (amountOneDay * Convert.ToDecimal(numberOfDays));
commissionModelForHourlyEmployee.Amount = $"${amount.ToString(AppConstants.DefaultFiveDigits)}";
}
// Case 4: Candidate joined after parsedStartDate and left on SalaryEndDate
else if (strDate >= parsedStartDate && endsDate <= parsedEndDate)
{
var numberOfDays = (endsDate - strDate).TotalDays;
decimal amountOneDay = (Convert.ToDecimal(salaryEmp)) / 30;
amount = (amountOneDay * Convert.ToDecimal(numberOfDays));
commissionModelForHourlyEmployee.Amount = $"${amount.ToString(AppConstants.DefaultFiveDigits)}";
}
}
}


decimal tax = (amount) * 4 / 100;

var costosCode = item.CostosCode;
var costosAmount = item.CostosAmount;

decimal payRates = 0;
decimal payRateAmount = 0;
if (item.SalaryPer != null && item.EmpSalary != null)
{
decimal payRate = Convert.ToDecimal(objectCalculation.GetCostosPayRate(item.SalaryPer, item.EmpSalary));
if (payRate != 0)
{
payRates = payRate;
payRateAmount = payRates * 160;
}
}

string impuestos8 = string.Empty;
string impuestos175 = string.Empty;
string impuestos25 = string.Empty;
string costTotal = string.Empty;

if (!String.IsNullOrEmpty(item?.Division) && !String.IsNullOrEmpty(item.SalaryPer) && !String.IsNullOrEmpty(item.EmpSalary) && !String.IsNullOrEmpty(item.BillRatePer))
{
//impuestos175 = objectCalculation.GetImpuestos17PercentForCosts(item.Division, amount.ToString());
//impuestos25 = objectCalculation.GetImpuestos2PercentForCosts(item.Division, amount.ToString());
//impuestos8 = objectCalculation.GetImpuestos8PercentForCosts(item.Division, amount.ToString());

impuestos175 = objectCalculation.GetImpuestos17PercentForCosts(item.Division, payRateAmount.ToString());
impuestos25 = objectCalculation.GetImpuestos2PercentForCosts(item.Division, payRateAmount.ToString());
impuestos8 = objectCalculation.GetImpuestos8PercentForCosts(item.Division, payRateAmount.ToString());

costTotal = CostHours(costosCode, costosAmount, payRates, impuestos8, impuestos175, impuestos25, item.Division, item.BillRatePer);
}

commissionModelForHourlyEmployee.CostTotal = $"${costTotal}";

decimal margen = billRate - Convert.ToDecimal(costTotal);
commissionModelForHourlyEmployee.Margen = $"${margen.ToString(AppConstants.DefaultTwoDigits)}";

decimal coeff5Percent = (billRate - Convert.ToDecimal(costTotal)) * 5 / 100;
commissionModelForHourlyEmployee.Coeff5Percent = $"${coeff5Percent.ToString(AppConstants.DefaultTwoDigits)}";

var employeesManager = managerAssociatedEmployeeAsync.Where(x => x.EmployeeId == item?.CandidateId && x.StartId == item?.SalaryStartId && x.RecdId == item?.BillingRecId).FirstOrDefault();
if (employeesManager?.Eber == "true")
{
var eberAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "5303747171857").FirstOrDefault();
if (eberAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(eberAccount?.CommissionPercent);
if (eberAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Eber = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Eber = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Eber = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.Mirlan == "true")
{
var mirlanAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "7585500168886").FirstOrDefault();
if (mirlanAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(mirlanAccount?.CommissionPercent);
if (mirlanAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Mirlan = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Mirlan = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Mirlan = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.Anna == "true")
{
var annaAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "9865926385929").FirstOrDefault();
if (annaAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(annaAccount?.CommissionPercent);
if (annaAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Anna = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Anna = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Anna = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.Vicky == "true")
{
var vickyAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "12438203168299").FirstOrDefault();
if (vickyAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(vickyAccount?.CommissionPercent);
if (vickyAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Vicky = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Vicky = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Vicky = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.LuisZambrano == "true")
{
var luisAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "12757921517488").FirstOrDefault();
if (luisAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(luisAccount?.CommissionPercent);
if (luisAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.LuisZambrano = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.LuisZambrano = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.LuisZambrano = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.Amneris == "true")
{
var amnerisAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "8029243113602").FirstOrDefault();
if (amnerisAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(amnerisAccount?.CommissionPercent);
if (amnerisAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Amneris = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Amneris = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Amneris = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.Valeria == "true")
{
var valeriaAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "12601583645467").FirstOrDefault();
if (valeriaAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(valeriaAccount?.CommissionPercent);
if (valeriaAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Valeria = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Valeria = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Valeria = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
if (employeesManager?.Paula == "true")
{
var paulaAccount = getAccountManagersAsync.Where(x => x.AccountManagerCode == "14171006780277").FirstOrDefault();
if (paulaAccount != null)
{
decimal commissionPercent = Convert.ToDecimal(paulaAccount?.CommissionPercent);
if (paulaAccount?.TypeOfCommission == "1")
{
decimal profit1Percent = amount * commissionPercent / 100;
commissionModelForHourlyEmployee.Paula = $"${profit1Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal coeff5Percents = (billRate - Convert.ToDecimal(costTotal)) * commissionPercent / 100;
if (item?.BillRatePer == "H")
{

decimal billing5Percent = coeff5Percents * subTotalHours;
commissionModelForHourlyEmployee.Paula = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
else
{
decimal billing5Percent = coeff5Percents * 160;
commissionModelForHourlyEmployee.Paula = $"${billing5Percent.ToString(AppConstants.DefaultTwoDigits)}";
}
}
}
}
}
}
return commissionModelForHourlyEmployee;
}
catch (Exception exception)
{
Log.Error($"Error in CreateInvoiceForHourlyEmployee: {exception.Message}");
throw;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.