Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export options for accounts aging #1680

Merged
merged 8 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 7 additions & 8 deletions app/services/reports/accounts_aging/download_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,13 @@ def generate_csv
end

csv_data << [
"Total Amounts",
reports[:total_amount_overdue_by_date_range][:zero_to_thirty_days],
reports[:total_amount_overdue_by_date_range][:thirty_one_to_sixty_days],
reports[:total_amount_overdue_by_date_range][:sixty_one_to_ninety_days],
reports[:total_amount_overdue_by_date_range][:ninety_plus_days],
reports[:total_amount_overdue_by_date_range][:total]

]
"Total Amounts",
reports[:total_amount_overdue_by_date_range][:zero_to_thirty_days],
reports[:total_amount_overdue_by_date_range][:thirty_one_to_sixty_days],
reports[:total_amount_overdue_by_date_range][:sixty_one_to_ninety_days],
reports[:total_amount_overdue_by_date_range][:ninety_plus_days],
reports[:total_amount_overdue_by_date_range][:total]
]

Reports::GenerateCsv.new(csv_data, headers).process
end
Expand Down
11 changes: 5 additions & 6 deletions app/services/reports/generate_csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ def initialize(data, headers)

def process
CSV.generate do |csv|
csv << headers

data.each do |row|
csv << row
end
csv << headers
data.each do |row|
csv << row
end
end
end
end
end
62 changes: 31 additions & 31 deletions app/services/reports/generate_pdf.rb
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
# frozen_string_literal: true
# frozen_string_literal: true

class Reports::GeneratePdf
attr_reader :report_data, :current_company, :report_type
class Reports::GeneratePdf
attr_reader :report_data, :current_company, :report_type

def initialize(report_type, report_data, current_company)
@report_type = report_type
@report_data = report_data
@current_company = current_company
end
def initialize(report_type, report_data, current_company)
@report_type = report_type
@report_data = report_data
@current_company = current_company
end

def process
case report_type
when :time_entries
generate_time_entries_pdf
when :accounts_aging
generate_accounts_aging_pdf
else
raise ArgumentError, "Unsupported report type: #{report_type}"
end
def process
case report_type
when :time_entries
generate_time_entries_pdf
when :accounts_aging
generate_accounts_aging_pdf
else
raise ArgumentError, "Unsupported report type: #{report_type}"
end
end

private
private

def generate_time_entries_pdf
Pdf::HtmlGenerator.new(
:reports,
locals: { report_data:, current_company: }
).make
end
def generate_time_entries_pdf
Pdf::HtmlGenerator.new(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create common method for both the reports def generate_pdf_reports(reports)

:reports,
locals: { report_data:, current_company: }
).make
end

def generate_accounts_aging_pdf
Pdf::HtmlGenerator.new(
:accounts_aging_reports,
locals: { report_data:, current_company: }
).make
end
end
def generate_accounts_aging_pdf
Pdf::HtmlGenerator.new(
:accounts_aging_reports,
locals: { report_data:, current_company: }
).make
end
end
18 changes: 9 additions & 9 deletions app/services/reports/time_entries/download_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def generate_csv
headers = ["Project", "Client", "Note", "Team Member", "Date", "Hours Logged"]
flatten_reports = reports.map { |e| e[:entries] }.flatten
flatten_reports.each do |entry|
data << [
"#{entry.project_name}",
"#{entry.client_name}",
"#{entry.note}",
"#{entry.user_name}",
"#{format_date(entry.work_date)}",
"#{DurationFormatter.new(entry.duration).process}"
]
end
data << [
"#{entry.project_name}",
"#{entry.client_name}",
"#{entry.note}",
"#{entry.user_name}",
"#{format_date(entry.work_date)}",
"#{DurationFormatter.new(entry.duration).process}"
]
end
Reports::GenerateCsv.new(data, headers).process
end

Expand Down
62 changes: 31 additions & 31 deletions app/views/pdfs/accounts_aging_reports.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,37 @@
</th>
</thead>
<tbody>
<% report_data[:clients].each do |client| %>
<tr>
<td style="font-size: 14px; text-align: center; flex-basis: 25%; padding: 2px; border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= client[:name] %>
</p>
</td>
<td style="text-align: left; font-size: 14px; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #6B7280; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:zero_to_thirty_days]).process %>
</p>
</td>
<td style="text-align: left; font-size: 14px; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:thirty_one_to_sixty_days]).process %>
</td>
<td style="font-size: 14px; text-align: left; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:sixty_one_to_ninety_days]).process %>
</p>
</td>
<td style="font-size: 14px; text-align: left; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:ninety_plus_days]).process %>
</p>
</td>
<td style="font-size: 14px; text-align: left; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:total]).process %>
</p>
</td>
</tr>
<% report_data[:clients].each do |client| %>
<tr>
<td style="font-size: 14px; text-align: center; flex-basis: 25%; padding: 2px; border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= client[:name] %>
</p>
</td>
<td style="text-align: left; font-size: 14px; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #6B7280; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:zero_to_thirty_days]).process %>
</p>
</td>
<td style="text-align: left; font-size: 14px; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:thirty_one_to_sixty_days]).process %>
</td>
<td style="font-size: 14px; text-align: left; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:sixty_one_to_ninety_days]).process %>
</p>
</td>
<td style="font-size: 14px; text-align: left; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:ninety_plus_days]).process %>
</p>
</td>
<td style="font-size: 14px; text-align: left; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
<p style="color: #1F2937; margin: 0;">
<%= FormatAmountService.new(report_data[:base_currency],client[:amount_overdue][:total]).process %>
</p>
</td>
</tr>
<% end %>
<tr>
<td style="text-align: left; font-size: 14px; flex-basis: 25%; padding: 2px;border: 1px solid #000;">
Expand Down
Loading