From f70b0852f086309ed565c42a4fdff0bfd4e8748c Mon Sep 17 00:00:00 2001 From: Daniel Nottingham Date: Wed, 28 Jan 2026 16:38:57 -0300 Subject: [PATCH 1/2] refactor: event_procedures and medical_shifts pdf --- app/pdfs/event_procedures_report_pdf.rb | 10 +++++++--- app/pdfs/medical_shifts_report_pdf.rb | 16 ++++++++-------- spec/pdfs/event_procedures_report_pdf_spec.rb | 5 ++--- spec/pdfs/medical_shifts_report_pdf_spec.rb | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/pdfs/event_procedures_report_pdf.rb b/app/pdfs/event_procedures_report_pdf.rb index a84b386..74401a7 100644 --- a/app/pdfs/event_procedures_report_pdf.rb +++ b/app/pdfs/event_procedures_report_pdf.rb @@ -55,10 +55,10 @@ def start_new_page_if_needed def add_item_details(item) add_item_line(truncate_text(item.patient.name), item_paid?(item)) - add_item_line(truncate_text(item.procedure.name), item.total_amount.format) + add_item_line(truncate_text(item.procedure.name), "") add_item_line( - "#{truncate_text(item.hospital.name)} - #{truncate_text(item.health_insurance.name)}", - item_date(item) + "#{truncate_text(item.hospital.name)} - #{truncate_text(item.health_insurance.name)} - #{item_date(item)}", + item_amount(item) ) end @@ -82,4 +82,8 @@ def item_paid?(item) def item_date(item) item.date.strftime("%d/%m/%Y") end + + def item_amount(item) + item.total_amount.format(thousands_separator: ".", decimal_mark: ",") + end end diff --git a/app/pdfs/medical_shifts_report_pdf.rb b/app/pdfs/medical_shifts_report_pdf.rb index c7b75af..550ba68 100644 --- a/app/pdfs/medical_shifts_report_pdf.rb +++ b/app/pdfs/medical_shifts_report_pdf.rb @@ -54,9 +54,9 @@ def start_new_page_if_needed end def add_item_details(item) - add_item_line(truncate_text(item.hospital_name), item_start_date(item)) - add_item_line(item_workload(item), item.amount.format) - add_item_line(item_start_hour(item), item_paid?(item)) + add_item_line(truncate_text(item.hospital_name), item_amount(item)) + add_item_line(item_workload(item), "") + add_item_line(item_start_date(item), item_paid?(item)) end def add_item_line(left_text, right_text) @@ -77,18 +77,18 @@ def item_shift(item) end def item_workload(item) - "#{item_shift(item)} - #{item.workload_humanize}" + "#{item_shift(item)} - #{item.workload_humanize} - #{item.start_hour.strftime('%H:%M')}" end def item_start_date(item) item.start_date.strftime("%d/%m/%Y") end - def item_start_hour(item) - "InĂ­cio: #{item.start_hour.strftime('%H:%M')}" - end - def item_paid?(item) item.paid ? "Pago" : "A Receber" end + + def item_amount(item) + item.amount.format(thousands_separator: ".", decimal_mark: ",") + end end diff --git a/spec/pdfs/event_procedures_report_pdf_spec.rb b/spec/pdfs/event_procedures_report_pdf_spec.rb index b5e2273..2af2a94 100644 --- a/spec/pdfs/event_procedures_report_pdf_spec.rb +++ b/spec/pdfs/event_procedures_report_pdf_spec.rb @@ -19,10 +19,9 @@ event_procedures.each do |event_procedure| expect(text_analysis.strings).to include( event_procedure.procedure.name, - event_procedure.procedure.amount.format, event_procedure.patient.name, - "#{event_procedure.hospital.name} - #{event_procedure.health_insurance.name}", - event_procedure.date.strftime("%d/%m/%Y") + "#{event_procedure.hospital.name} - #{event_procedure.health_insurance.name} - + #{event_procedure.date.strftime('%d/%m/%Y')}".squish ) end end diff --git a/spec/pdfs/medical_shifts_report_pdf_spec.rb b/spec/pdfs/medical_shifts_report_pdf_spec.rb index 217dc04..38e489f 100644 --- a/spec/pdfs/medical_shifts_report_pdf_spec.rb +++ b/spec/pdfs/medical_shifts_report_pdf_spec.rb @@ -16,7 +16,7 @@ medical_shifts.each do |medical_shift| expect(text_analysis.strings).to include( medical_shift.hospital_name, - medical_shift.amount.format, + medical_shift.amount.format(thousands_separator: ".", decimal_mark: ","), medical_shift.start_date.strftime("%d/%m/%Y") ) end From c34326ce3a2b16971c98f8b431dfaf869c6fd0dd Mon Sep 17 00:00:00 2001 From: Daniel Nottingham Date: Wed, 28 Jan 2026 21:46:10 -0300 Subject: [PATCH 2/2] refactor: event_procedures and medical_shifts pdf --- .../event_procedures/total_amount_cents.rb | 2 +- app/operations/medical_shifts/total_amount_cents.rb | 12 +++++++++--- .../event_procedures/total_amount_cents_spec.rb | 6 +++--- .../medical_shifts/total_amount_cents_spec.rb | 6 +++--- .../requests/api/v1/event_procedures_request_spec.rb | 2 +- spec/requests/api/v1/medical_shifts_request_spec.rb | 12 ++++++------ 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/app/operations/event_procedures/total_amount_cents.rb b/app/operations/event_procedures/total_amount_cents.rb index 4457212..6fc194d 100644 --- a/app/operations/event_procedures/total_amount_cents.rb +++ b/app/operations/event_procedures/total_amount_cents.rb @@ -15,7 +15,7 @@ def call end def convert_money(amount_cents) - Money.new(amount_cents, "BRL").format + Money.new(amount_cents, "BRL").format(thousands_separator: ".", decimal_mark: ",") end def calculate_amount(filtered_event_procedures) diff --git a/app/operations/medical_shifts/total_amount_cents.rb b/app/operations/medical_shifts/total_amount_cents.rb index eead48c..0772ce9 100644 --- a/app/operations/medical_shifts/total_amount_cents.rb +++ b/app/operations/medical_shifts/total_amount_cents.rb @@ -9,9 +9,15 @@ class TotalAmountCents < Actor output :unpaid, type: String def call - self.total = Money.new(medical_shifts.sum(&:amount_cents), "BRL").format - self.paid = Money.new(medical_shifts.select(&:paid).sum(&:amount_cents), "BRL").format - self.unpaid = Money.new(medical_shifts.reject(&:paid).sum(&:amount_cents), "BRL").format + self.total = formatted_amount(medical_shifts.sum(&:amount_cents)) + self.paid = formatted_amount(medical_shifts.select(&:paid).sum(&:amount_cents)) + self.unpaid = formatted_amount(medical_shifts.reject(&:paid).sum(&:amount_cents)) + end + + private + + def formatted_amount(value) + Money.new(value, "BRL").format(thousands_separator: ".", decimal_mark: ",") end end end diff --git a/spec/operations/event_procedures/total_amount_cents_spec.rb b/spec/operations/event_procedures/total_amount_cents_spec.rb index d5ba170..11f4c40 100644 --- a/spec/operations/event_procedures/total_amount_cents_spec.rb +++ b/spec/operations/event_procedures/total_amount_cents_spec.rb @@ -33,9 +33,9 @@ event_procedures = paid_event_procedures + unpaid_event_procedures total_amount_cents = described_class.call(event_procedures: event_procedures) - expect(total_amount_cents.total).to eq("R$190.00") - expect(total_amount_cents.paid).to eq("R$150.00") - expect(total_amount_cents.unpaid).to eq("R$40.00") + expect(total_amount_cents.total).to eq("R$190,00") + expect(total_amount_cents.paid).to eq("R$150,00") + expect(total_amount_cents.unpaid).to eq("R$40,00") end end end diff --git a/spec/operations/medical_shifts/total_amount_cents_spec.rb b/spec/operations/medical_shifts/total_amount_cents_spec.rb index 96a7a54..986481f 100644 --- a/spec/operations/medical_shifts/total_amount_cents_spec.rb +++ b/spec/operations/medical_shifts/total_amount_cents_spec.rb @@ -29,9 +29,9 @@ ] ) - expect(result.total).to eq("R$45.00") - expect(result.paid).to eq("R$30.00") - expect(result.unpaid).to eq("R$15.00") + expect(result.total).to eq("R$45,00") + expect(result.paid).to eq("R$30,00") + expect(result.unpaid).to eq("R$15,00") end end end diff --git a/spec/requests/api/v1/event_procedures_request_spec.rb b/spec/requests/api/v1/event_procedures_request_spec.rb index c5d58e5..6571818 100644 --- a/spec/requests/api/v1/event_procedures_request_spec.rb +++ b/spec/requests/api/v1/event_procedures_request_spec.rb @@ -131,7 +131,7 @@ end it "returns total values without consider page and per_page params" do - expect(response.parsed_body["total"]).to eq("R$400.00") + expect(response.parsed_body["total"]).to eq("R$400,00") end end end diff --git a/spec/requests/api/v1/medical_shifts_request_spec.rb b/spec/requests/api/v1/medical_shifts_request_spec.rb index 7aaf04d..4857f94 100644 --- a/spec/requests/api/v1/medical_shifts_request_spec.rb +++ b/spec/requests/api/v1/medical_shifts_request_spec.rb @@ -93,9 +93,9 @@ get path, params: { month: "2" }, headers: headers - expect(response.parsed_body["total"]).to eq("R$30.00") - expect(response.parsed_body["total_paid"]).to eq("R$10.00") - expect(response.parsed_body["total_unpaid"]).to eq("R$20.00") + expect(response.parsed_body["total"]).to eq("R$30,00") + expect(response.parsed_body["total_paid"]).to eq("R$10,00") + expect(response.parsed_body["total_unpaid"]).to eq("R$20,00") end end @@ -207,9 +207,9 @@ expect(response.parsed_body.symbolize_keys).to eq( { - total: "R$0.00", - total_paid: "R$0.00", - total_unpaid: "R$0.00", + total: "R$0,00", + total_paid: "R$0,00", + total_unpaid: "R$0,00", medical_shifts: [] } )