I'm not sure if I'm on the right track for this or not. So I've been given an assignment where I have two reports on two different cvs files that hold the information below:
One csv holds payment information under these headers:
Payments.csv:
id,employee_id,payment,code
The other holds employee information using the following headers:
Employee.csv:
id,first_name,last_name,email,city,ip_address
The primary key here is id
in the employee.csv file while the foreign key is employee_id
in the payments.csv file. This means that id
on the employee.csv file should match up with employee_id
on the payment.csv.
With this information I am supposed to create 2 classes. One will be an employee class that creates objects using the information from the employee.csv file. The other will be a payments class that creates objects using the payments.csv.
I will then need to compare both sets of objects where id
on employee.csv equals employee_id
on payments.csv. Then I'd like to use this data to create a new csv that consolidates the data on both csv files into one file where employees on employee.csv are linked to their payments on payments.csv.
Any assistance or guidance is appreciated! This is what I've go so far. I might be way off so please no judgement. Just trying to learn. I've hit a road block on exactly what to do after being able to create employee and payment objects.
#Class that creates employee object
class Employee {
[Int]$id
[String]$first_name
[String]$last_name
[String]$email
[String]$city
[String]$ip_address
Employee ([Int]$id,[String]$first_name,[String]$last_name,[String]$email,[String]$city,[String]$ip_address){
$This.id = $id
$This.first_name = $first_name
$This.last_name = $last_name
$This.email = $email
$This.city = $city
$This.ip_address = $ip_address
}
}
#Class that creates payment object
class Payment{
[Int]$id
[Int]$employee_id
[String]$payment
[String]$code
Payment ([Int]$id,[Int]$employee_id,[String]$payment,[String]$code){
$This.id = $id
$This.employee_id = $employee_id
$This.payment = $payment
$This.code = $code
}
}
#Importing spreadsheets w/ data being used
$ImportedEmployees = Import-Csv ".\Employee.csv"
$ImportedPayments = Import-Csv ".\Payment.csv"
$FinalEmployeeReport = @{}
#Calling [Employee] to create new objects using the employee.csv
Foreach ($Employee in $ImportedEmployees){
$NewEmployeeEntry = [Employee]::new([Int]$Employee.id,[String]$Employee.first_name,[String]$Employee.last_name,[String]$Employee.email,[String]$Employee.city,[String]$Employee.ip_address)
#Adding object to $FinalEmployeeReport
$FinalEmployeeReport.Add([String]$NewEmployeeEntry.last_name,[Int]$NewEmployeeEntry.id)
}
Foreach ($Payment in $ImportedPayments)
{
$NewPayment = [Payment]::new([Int]$Payment.id,[Int]$Payment.employee_id,[String]$Payment.payment,[String]$Payment.code)
$FinalEmployeeReport.Add[Int]$Payment.employee_id,[String]$Payment.payment))
}
Foreach($Payment in $ImportedPayments){
$NewPayment = [Payment]::new([Int]$Payment.id,[Int]$Payment.employee_id,[String]$Payment.payment,[String]$Payment.code)
Foreach($NewEmployeeEntry in $Payment){
if($NewPayment.employee_id -eq $NewEmployeeEntry.id ){
$NewEmployeeEntry.Add($NewPayment)
}
}
}
$FinalEmployeeReport.Add($NewEmployeeEntry)