From 127cfa99089ba93438a1da80eaaa83fff1bcc3f2 Mon Sep 17 00:00:00 2001 From: Prasanth Chaduvula Date: Tue, 17 Oct 2023 15:10:41 +0530 Subject: [PATCH 1/2] Eager load companies on client invoices (#1551) eager load companies on client invoices --- app/controllers/internal_api/v1/clients_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/internal_api/v1/clients_controller.rb b/app/controllers/internal_api/v1/clients_controller.rb index 676b50cf8b..4d869308f3 100644 --- a/app/controllers/internal_api/v1/clients_controller.rb +++ b/app/controllers/internal_api/v1/clients_controller.rb @@ -34,7 +34,7 @@ def show project_details: client.project_details(params[:time_frame]), total_minutes: client.total_hours_logged(params[:time_frame]), overdue_outstanding_amount: client.client_overdue_and_outstanding_calculation, - invoices: client.invoices, + invoices: client.invoices.includes([:company]), invitations: client.invitations, client_members_emails: client.client_members.joins(:user).pluck("users.email") }, From 3f3ce8c0e5d9b71093ba083f5a5c88ae5e9f6a9d Mon Sep 17 00:00:00 2001 From: Trishanu Nayak Date: Tue, 17 Oct 2023 15:10:59 +0530 Subject: [PATCH 2/2] Updated the date format in the downloaded invoice pdf (#1550) * updated the date format in the downloaded invoice pdf * created formatted_date method in invoice_line_item.rb * fixed robocop checks * fixed rubocop checks * fixed check fail * fixed check fail --------- Co-authored-by: Apoorv Tiwari --- app/models/invoice_line_item.rb | 4 ++++ app/presenters/invoice_line_item_presenter.rb | 2 +- app/views/pdfs/invoices.html.erb | 6 +++--- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/invoice_line_item.rb b/app/models/invoice_line_item.rb index b4cb324904..b060e001b4 100644 --- a/app/models/invoice_line_item.rb +++ b/app/models/invoice_line_item.rb @@ -63,4 +63,8 @@ def time_spent def total_cost @_total_cost ||= (hours_spent * rate).round(3) end + + def formatted_date + CompanyDateFormattingService.new(date, company: invoice.company).process + end end diff --git a/app/presenters/invoice_line_item_presenter.rb b/app/presenters/invoice_line_item_presenter.rb index b4ed22ab7e..b59994475f 100644 --- a/app/presenters/invoice_line_item_presenter.rb +++ b/app/presenters/invoice_line_item_presenter.rb @@ -10,7 +10,7 @@ def initialize(invoice_line_item) def pdf_row(base_currency) { name: invoice_line_item.name, - date: invoice_line_item.date, + date: invoice_line_item.formatted_date, description: invoice_line_item.description, quantity: invoice_line_item.time_spent, rate: FormatAmountService.new(base_currency, invoice_line_item.rate).process, diff --git a/app/views/pdfs/invoices.html.erb b/app/views/pdfs/invoices.html.erb index a297651766..0a4a7266ae 100644 --- a/app/views/pdfs/invoices.html.erb +++ b/app/views/pdfs/invoices.html.erb @@ -43,11 +43,11 @@ html {

Date of Issue

- <%=invoice["issue_date"].strftime('%d-%m-%Y')%> + <%= invoice.formatted_issue_date %>

Due Date

- <%=invoice["due_date"].strftime('%d-%m-%Y')%> + <%= invoice.formatted_due_date %>

@@ -83,7 +83,7 @@ html { <%invoice_line_items.each do |item| %> <%=item[:name]%> - <%=item[:date].strftime('%d-%m-%Y')%> + <%=item[:date]%> <%=item[:description]%>