NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;

public class YourClassName
{
// Define a data structure to store last invoice numbers for each combination
private Dictionary<string, int> lastInvoiceNumbers = new Dictionary<string, int>();

/// <summary>
/// Get Salaried Employee List For Invoice
/// </summary>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <param name="companyId"></param>
/// <returns></returns>
public async Task<InvoiceMasterModelForSalariedEmployee> GetSalariedEmployeeListForInvoice(string startDate, string endDate, string companyId)
{
try
{
InvoiceMasterModelForSalariedEmployee invoiceMasterModelForSalariedEmployee = new();
List<InvoiceModelForSalariedEmployee> invoiceModelListForSalariedEmployee = new();
DateTime.TryParseExact(startDate, AppConstants.DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedStartDate);
DateTime.TryParseExact(endDate, AppConstants.DateFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedEndDate);
var currentDate = DateTime.Now;
var empForms = await helperRepository.GetDivisionCodesAsync();
var invoiceSalaryHelper = await helperRepository.GetInvoiceSalaryHelperAsync();
var getExternalConsultingSalaryList = await helperRepository.GetCandidatesRecordModelForInvoice();

foreach (var item in getExternalConsultingSalaryList.DistinctBy(x => new { x.CandidateId, x.BillingStartId, x.BillingRecId }))
{
if (string.IsNullOrEmpty(item.SalaryEndDate) || item.SalaryEndDate.CompareTo(currentDate.ToString("MM-dd-yyyy")) >= 0)
{
if (item.SalaryApproved == AppConstants.One)
{
if (!IsExcludedCompany(item.CompanyId))
{
if (IsValidDivision(item.Division))
{
if (companyId != "0")
{
if (item.CompanyId == companyId)
{
if (item.Division == AppConstants.USA1099DivisionCode && item.SalaryPer != "H")
{
InvoiceModelForSalariedEmployee invoiceModelForSalariedEmployee = CreateInvoiceForSalariedEmployee(item, startDate, endDate, parsedStartDate, parsedEndDate, empForms, invoiceSalaryHelper);
invoiceModelListForSalariedEmployee.Add(invoiceModelForSalariedEmployee);
}
else if (item.Division != AppConstants.USA1099DivisionCode)
{
InvoiceModelForSalariedEmployee invoiceModelForSalariedEmployee = CreateInvoiceForSalariedEmployee(item, startDate, endDate, parsedStartDate, parsedEndDate, empForms, invoiceSalaryHelper);
invoiceModelListForSalariedEmployee.Add(invoiceModelForSalariedEmployee);
}
}
}
}
}
}
}
}

invoiceMasterModelForSalariedEmployee.InvoiceModelListForSalariedEmployee = invoiceModelListForSalariedEmployee;
return invoiceMasterModelForSalariedEmployee;
}
catch (Exception exception)
{
Log.Error($"Error in GetSalariedEmployeeListForInvoice: {exception.Message}");
throw;
}
}

// Method to check if the company is excluded
private bool IsExcludedCompany(string companyId)
{
List<string> excludedCompanies = new List<string> { "5509748", "10175435", "5508844", "9511343" };
return excludedCompanies.Contains(companyId);
}

// Method to check if the division is valid
private bool IsValidDivision(string division)
{
List<string> validDivisions = new List<string> { AppConstants.ECSalaryDivisionCode, AppConstants.W2SalaryDivisionCode, AppConstants.USA1099DivisionCode };
return validDivisions.Contains(division);
}

/// <summary>
/// Create External Consulting Salary For Invoice
/// </summary>
/// <param name="item"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <param name="parsedStartDate"></param>
/// <param name="parsedEndDate"></param>
/// <returns></returns>
private InvoiceModelForSalariedEmployee CreateInvoiceForSalariedEmployee(CandidatesRecordModel item, string startDate, string endDate,
DateTime parsedStartDate, DateTime parsedEndDate, List<DivisionCode> empForms, List<InvoiceSalaryHelper> invoiceSalaryHelper)
{
try
{
InvoiceModelForSalariedEmployee invoiceModelForSalariedEmployee = new();

// Generate invoice number
string invoiceNumber = GenerateInvoiceNumber(item.CompanyId, item.PONumber, item.ClientContact);
invoiceModelForSalariedEmployee.InvoiceNumber = invoiceNumber;

// Other parts of the method remain unchanged...
// (Implementation of creating the invoice model continues here)

return invoiceModelForSalariedEmployee;
}
catch (Exception exception)
{
Log.Error($"Error in CreateInvoiceForSalariedEmployee: {exception.Message}");
throw;
}
}

// Method to generate invoice number
private string GenerateInvoiceNumber(string companyId, string poNumber, string clientContact)
{
string key = $"{companyId}-{poNumber}-{clientContact}";

if (lastInvoiceNumbers.ContainsKey(key))
{
// Increment last invoice number by 1
lastInvoiceNumbers[key]++;
}
else
{
// Start invoice number from 1000 for new combination
lastInvoiceNumbers[key] = 1000;
}

return lastInvoiceNumbers[key].ToString();
}
}
     
 
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.