Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app/javascript/src/components/Projects/Details/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ const getTableData = (project) => {
return project.members.map((member) => {
const hours = member.minutes / 60;
const hour = hours.toFixed(2);
const cost = (hours * parseInt(member.hourlyRate)).toFixed(2);
return {
col1: (
<div className="text-base text-miru-dark-purple-1000">
Expand All @@ -40,7 +39,7 @@ const getTableData = (project) => {
),
col2: (
<div className="text-base text-miru-dark-purple-1000 text-right">
${member.hourlyRate}
{member.formattedHourlyRate}
</div>
),
col3: (
Expand All @@ -50,7 +49,7 @@ const getTableData = (project) => {
),
col4: (
<div className="text-lg font-bold text-miru-dark-purple-1000 text-right">
${cost}
{member.formattedCost}
</div>
)
};
Expand Down
5 changes: 3 additions & 2 deletions app/javascript/src/mapper/project.mapper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

const getMember = (input:any) => input.map((elem) => ({
hourlyRate: elem.hourly_rate,
formattedHourlyRate: elem.formatted_hourly_rate,
id: elem.id,
minutes: elem.minutes_logged,
name: elem.name
name: elem.name,
formattedCost: elem.formatted_cost
}));

export const unmapper = (data:any = {}) => ({
Expand Down
16 changes: 12 additions & 4 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,21 @@ def project_team_member_details(time_frame)
{
id: member.user_id,
name: member.full_name,
hourly_rate: member.hourly_rate,
minutes_logged: 0
formatted_hourly_rate: format_amount(member.hourly_rate),
minutes_logged: 0,
formatted_cost: format_amount(0)
}
end
else
entries.map do |entry|
hourly_rate = members[entry.user_id]
cost = (entry.duration / 60) * hourly_rate
{
id: entry.user_id,
name: entry.user.full_name,
hourly_rate: members[entry.user_id],
minutes_logged: entry.duration
formatted_hourly_rate: format_amount(hourly_rate),
minutes_logged: entry.duration,
formatted_cost: format_amount(cost)
}
end
end
Expand Down Expand Up @@ -103,6 +107,10 @@ def overdue_and_outstanding_amounts
}
end

def format_amount(amount)
FormatAmountService.new(client.company.base_currency, amount).process
end

private

def discard_project_members
Expand Down
34 changes: 27 additions & 7 deletions spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,39 @@
let(:client) { create(:client, company:) }
let(:project) { create(:project, client:) }
let!(:member) { create(:project_member, project:, user:, hourly_rate: 5000) }
let(:formatted_hourly_rate) { FormatAmountService.new(company.base_currency, member.hourly_rate).process }
let(:result) do
[{
id: user.id,
name: user.full_name,
hourly_rate: 5000,
minutes_logged: 480.0
minutes_logged: 480.0,
formatted_hourly_rate:
}]
end

context "when entries are missing" do
let(:time_frame) { "last_week" }

it "returns data with 0 values" do
expect(subject).to eq([{ id: member.user_id, name: user.full_name, hourly_rate: 5000, minutes_logged: 0 }])
expect(subject).to eq(
[{
id: member.user_id,
name: user.full_name,
formatted_hourly_rate:,
minutes_logged: 0,
formatted_cost: project.format_amount(0)
}])
end
end

context "when time_frame is last_week" do
let(:time_frame) { "last_week" }

it "returns the project_team_member_details for a project in the last week" do
create(:timesheet_entry, user:, project:, work_date: Date.today.last_week)
timesheet_entry = create(:timesheet_entry, user:, project:, work_date: Date.today.last_week)
result.first[:formatted_hourly_rate] = formatted_hourly_rate
cost = (timesheet_entry.duration / 60) * member.hourly_rate
result.first[:formatted_cost] = project.format_amount(cost)
expect(subject).to eq(result)
end
end
Expand All @@ -57,7 +68,10 @@
let(:time_frame) { "week" }

it "returns the project_team_member_details for a project in a week" do
create(:timesheet_entry, user:, project:, work_date: Date.today.at_beginning_of_week)
timesheet_entry = create(:timesheet_entry, user:, project:, work_date: Date.today.at_beginning_of_week)
result.first[:formatted_hourly_rate] = formatted_hourly_rate
cost = (timesheet_entry.duration / 60) * member.hourly_rate
result.first[:formatted_cost] = project.format_amount(cost)
expect(subject).to eq(result)
end
end
Expand All @@ -66,7 +80,10 @@
let(:time_frame) { "month" }

it "returns the project_team_member_details for a project in a month" do
create(:timesheet_entry, user:, project:, work_date: Date.today.at_beginning_of_month)
timesheet_entry = create(:timesheet_entry, user:, project:, work_date: Date.today.at_beginning_of_month)
result.first[:formatted_hourly_rate] = formatted_hourly_rate
cost = (timesheet_entry.duration / 60) * member.hourly_rate
result.first[:formatted_cost] = project.format_amount(cost)
expect(subject).to eq(result)
end
end
Expand All @@ -75,7 +92,10 @@
let(:time_frame) { "year" }

it "returns the project_team_member_details for a project in a year" do
create(:timesheet_entry, user:, project:, work_date: Date.today.beginning_of_year)
timesheet_entry = create(:timesheet_entry, user:, project:, work_date: Date.today.beginning_of_year)
result.first[:formatted_hourly_rate] = formatted_hourly_rate
cost = (timesheet_entry.duration / 60) * member.hourly_rate
result.first[:formatted_cost] = project.format_amount(cost)
expect(subject).to eq(result)
end
end
Expand Down