mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
include payment schedules in accounting archives
This commit is contained in:
parent
a416f8c7ae
commit
71775378e8
@ -27,6 +27,10 @@ class AccountingPeriod < ApplicationRecord
|
||||
Invoice.where('created_at >= :start_date AND CAST(created_at AS DATE) <= :end_date', start_date: start_at, end_date: end_at)
|
||||
end
|
||||
|
||||
def payment_schedules
|
||||
PaymentSchedule.where('created_at >= :start_date AND CAST(created_at AS DATE) <= :end_date', start_date: start_at, end_date: end_at)
|
||||
end
|
||||
|
||||
def invoices_with_vat(invoices)
|
||||
vat_service = VatHistoryService.new
|
||||
invoices.map do |i|
|
||||
|
@ -32,12 +32,44 @@ json.invoices do
|
||||
json.object do
|
||||
json.type item.object_type
|
||||
json.id item.object_id
|
||||
json.main item.main
|
||||
end
|
||||
json.partial! 'archive/vat', price: item.amount, vat_rate: invoice[:vat_rate]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.payment_schedules do
|
||||
json.array!(schedules) do |schedule|
|
||||
json.extract! schedule, :id, :payment_method, :created_at, :reference, :footprint
|
||||
json.payment_gateway_objects schedule.payment_gateway_objects do |object|
|
||||
json.id object.gateway_object_id
|
||||
json.type object.gateway_object_type
|
||||
end
|
||||
json.total number_to_currency(schedule.total / 100.0)
|
||||
json.user do
|
||||
json.extract! schedule.invoicing_profile, :user_id, :email, :first_name, :last_name
|
||||
json.address schedule.invoicing_profile&.address&.address
|
||||
json.invoicing_profile_id schedule.invoicing_profile.id
|
||||
if schedule.invoicing_profile.organization
|
||||
json.organization do
|
||||
json.extract! schedule.invoicing_profile.organization, :name, :id
|
||||
json.address schedule.invoicing_profile.organization&.address&.address
|
||||
end
|
||||
end
|
||||
end
|
||||
json.deadlines schedule.payment_schedule_items do |item|
|
||||
json.extract! item, :id, :due_date, :state, :details, :invoice_id, :footprint, :created_at
|
||||
json.amount number_to_currency(item.amount / 100.0)
|
||||
end
|
||||
json.objects schedule.payment_schedule_objects do |object|
|
||||
json.type object.object_type
|
||||
json.id object.object_id
|
||||
json.main object.main
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
json.totals do
|
||||
json.period_total number_to_currency(period_total / 100.0)
|
||||
json.perpetual_total number_to_currency(perpetual_total / 100.0)
|
||||
|
@ -9,11 +9,11 @@ class ArchiveWorker
|
||||
|
||||
def perform(accounting_period_id)
|
||||
period = AccountingPeriod.find(accounting_period_id)
|
||||
|
||||
data = period.invoices.includes(:invoice_items).order(id: :asc)
|
||||
invoices = period.invoices.includes(:invoice_items).order(created_at: :asc)
|
||||
schedules = period.payment_schedules.includes(:payment_schedule_items, :payment_schedule_objects).order(created_at: :asc)
|
||||
previous_file = period.previous_period&.archive_file
|
||||
last_archive_checksum = previous_file ? Integrity::Checksum.file(previous_file) : nil
|
||||
json_data = to_json_archive(period, data, previous_file, last_archive_checksum)
|
||||
json_data = to_json_archive(period, invoices, schedules, previous_file, last_archive_checksum)
|
||||
current_archive_checksum = Integrity::Checksum.text(json_data)
|
||||
date = DateTime.iso8601
|
||||
chained = Integrity::Checksum.text("#{current_archive_checksum}#{last_archive_checksum}#{date}")
|
||||
@ -34,12 +34,13 @@ class ArchiveWorker
|
||||
|
||||
private
|
||||
|
||||
def to_json_archive(period, invoices, previous_file, last_checksum)
|
||||
def to_json_archive(period, invoices, schedules, previous_file, last_checksum)
|
||||
code_checksum = Integrity::Checksum.code
|
||||
ApplicationController.new.view_context.render(
|
||||
partial: 'archive/accounting',
|
||||
locals: {
|
||||
invoices: period.invoices_with_vat(invoices),
|
||||
schedules: schedules,
|
||||
period_total: period.period_total,
|
||||
perpetual_total: period.perpetual_total,
|
||||
period_footprint: period.footprint,
|
||||
|
Loading…
x
Reference in New Issue
Block a user