mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
export labels: user name + reference + summary, only on client line. Also: handling new export parameters (decimal separator, label length, export zeros)
This commit is contained in:
parent
f06bdaaf21
commit
3348539fdf
@ -967,7 +967,7 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
|
||||
$scope.firstInvoice = null;
|
||||
|
||||
/**
|
||||
* Validate the close period creation
|
||||
* Validate the export
|
||||
*/
|
||||
$scope.ok = function () {
|
||||
const statusQry = mkQuery();
|
||||
@ -1033,9 +1033,9 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
|
||||
date_format: $scope.exportTarget.settings.dateFormat,
|
||||
start_date: $scope.exportTarget.startDate,
|
||||
end_date: $scope.exportTarget.endDate,
|
||||
label_max_length: $scope.exportTarget.labelMaxLength,
|
||||
decimal_separator: $scope.exportTarget.decimalSeparator,
|
||||
export_invoices_at_zero: $scope.exportTarget.exportInvoicesAtZero
|
||||
label_max_length: $scope.exportTarget.settings.labelMaxLength,
|
||||
decimal_separator: $scope.exportTarget.settings.decimalSeparator,
|
||||
export_invoices_at_zero: $scope.exportTarget.settings.exportInvoicesAtZero
|
||||
})
|
||||
};
|
||||
}
|
||||
|
@ -42,8 +42,10 @@ class Setting < ActiveRecord::Base
|
||||
display_name_enable
|
||||
machines_sort_by
|
||||
accounting_journal_code
|
||||
accounting_client_code
|
||||
accounting_client_label
|
||||
accounting_card_client_code
|
||||
accounting_card_client_label
|
||||
accounting_site_client_code
|
||||
accounting_site_client_label
|
||||
accounting_wallet_code
|
||||
accounting_wallet_label
|
||||
accounting_VAT_code
|
||||
@ -57,9 +59,7 @@ class Setting < ActiveRecord::Base
|
||||
accounting_Event_code
|
||||
accounting_Event_label
|
||||
accounting_Space_code
|
||||
accounting_Space_label
|
||||
accounting_coupon_code
|
||||
accounting_coupon_label] }
|
||||
accounting_Space_label] }
|
||||
|
||||
after_update :update_stylesheet, :notify_privacy_policy_changed if :value_changed?
|
||||
|
||||
|
@ -2,22 +2,37 @@
|
||||
|
||||
# Provides the routine to export the accounting data to an external accounting software
|
||||
class AccountingExportService
|
||||
attr_reader :encoding, :format, :separator, :journal_code, :date_format, :columns, :vat_service
|
||||
include ActionView::Helpers::NumberHelper
|
||||
|
||||
def initialize(columns, encoding: 'UTF-8', format: 'CSV', separator: ';', date_format: '%d/%m/%Y')
|
||||
attr_reader :encoding, :format, :separator, :journal_code, :date_format, :columns, :vat_service, :decimal_separator, :label_max_length,
|
||||
:export_zeros
|
||||
|
||||
def initialize(columns, encoding: 'UTF-8', format: 'CSV', separator: ';')
|
||||
@encoding = encoding
|
||||
@format = format
|
||||
@separator = separator
|
||||
@decimal_separator = ','
|
||||
@date_format = '%d/%m/%Y'
|
||||
@label_max_length = 50
|
||||
@export_zeros = false
|
||||
@journal_code = Setting.find_by(name: 'accounting_journal_code')&.value || ''
|
||||
@date_format = date_format
|
||||
@columns = columns
|
||||
@vat_service = VatHistoryService.new
|
||||
end
|
||||
|
||||
def set_options(decimal_separator: ',', date_format: '%d/%m/%Y', label_max_length: 50, export_zeros: false)
|
||||
@decimal_separator = decimal_separator
|
||||
@date_format = date_format
|
||||
@label_max_length = label_max_length
|
||||
@export_zeros = export_zeros
|
||||
end
|
||||
|
||||
def export(start_date, end_date, file)
|
||||
# build CVS content
|
||||
content = header_row
|
||||
invoices = Invoice.where('created_at >= ? AND created_at <= ?', start_date, end_date).order('created_at ASC')
|
||||
invoices = invoices.where('total > 0') unless export_zeros
|
||||
invoices.each do |i|
|
||||
content << generate_rows(i)
|
||||
end
|
||||
@ -70,7 +85,7 @@ class AccountingExportService
|
||||
when 'piece'
|
||||
row << invoice.reference
|
||||
when 'line_label'
|
||||
row << label(invoice.invoicing_profile&.full_name)
|
||||
row << label(invoice)
|
||||
when 'debit_origin'
|
||||
row << debit_client(invoice, total)
|
||||
when 'credit_origin'
|
||||
@ -106,7 +121,7 @@ class AccountingExportService
|
||||
when 'piece'
|
||||
row << invoice.reference
|
||||
when 'line_label'
|
||||
row << label(item.description)
|
||||
row << ''
|
||||
when 'debit_origin'
|
||||
row << debit(invoice, wo_taxes)
|
||||
when 'credit_origin'
|
||||
@ -143,7 +158,7 @@ class AccountingExportService
|
||||
when 'piece'
|
||||
row << invoice.reference
|
||||
when 'line_label'
|
||||
row << label(subscription_item.description)
|
||||
row << ''
|
||||
when 'debit_origin'
|
||||
row << debit(invoice, wo_taxes)
|
||||
when 'credit_origin'
|
||||
@ -179,7 +194,7 @@ class AccountingExportService
|
||||
when 'piece'
|
||||
row << invoice.reference
|
||||
when 'line_label'
|
||||
row << I18n.t('accounting_export.VAT')
|
||||
row << ''
|
||||
when 'debit_origin'
|
||||
row << debit(invoice, vat)
|
||||
when 'credit_origin'
|
||||
@ -202,7 +217,8 @@ class AccountingExportService
|
||||
def account(invoice, account, type = :code)
|
||||
res = case account
|
||||
when :client
|
||||
Setting.find_by(name: "accounting_client_#{type}")&.value
|
||||
means = invoice.paid_with_stripe? ? 'card' : 'site'
|
||||
Setting.find_by(name: "accounting_#{means}_client_#{type}")&.value
|
||||
when :vat
|
||||
Setting.find_by(name: "accounting_VAT_#{type}")&.value
|
||||
when :subscription
|
||||
@ -226,13 +242,13 @@ class AccountingExportService
|
||||
# Fill the value of the "debit" column: if the invoice is a refund, returns the given amount, returns 0 otherwise
|
||||
def debit(invoice, amount)
|
||||
avoir = invoice.is_a? Avoir
|
||||
avoir ? amount.to_s : '0'
|
||||
avoir ? format_number(amount) : '0'
|
||||
end
|
||||
|
||||
# Fill the value of the "credit" column: if the invoice is a refund, returns 0, otherwise, returns the given amount
|
||||
def credit(invoice, amount)
|
||||
avoir = invoice.is_a? Avoir
|
||||
avoir ? '0' : amount.to_s
|
||||
avoir ? '0' : format_number(amount)
|
||||
end
|
||||
|
||||
# Fill the value of the "debit" column for the client row: if the invoice is a refund, returns 0, otherwise, returns the given amount
|
||||
@ -245,9 +261,19 @@ class AccountingExportService
|
||||
debit(invoice, amount)
|
||||
end
|
||||
|
||||
# Format the given text to match the accounting software rules for the labels
|
||||
def label(text)
|
||||
res = text.tr separator, ''
|
||||
res.truncate(50)
|
||||
# Format the given number as a string, using the configured separator
|
||||
def format_number(num)
|
||||
number_to_currency(num, unit: '', separator: decimal_separator, delimiter: '', precision: 2)
|
||||
end
|
||||
|
||||
# Create a text from the given invoice, matching the accounting software rules for the labels
|
||||
def label(invoice)
|
||||
name = "#{invoice.invoicing_profile.last_name} #{invoice.invoicing_profile.first_name}".tr separator, ''
|
||||
reference = invoice.reference
|
||||
items = invoice.subscription_invoice? ? [I18n.t('accounting_export.subscription')] : []
|
||||
items.push I18n.t("accounting_export.#{invoice.reservation.reservable_type}_reservation") if invoice.invoiced_type == 'Reservation'
|
||||
summary = items.join(' + ')
|
||||
res = "#{reference}, #{summary}"
|
||||
"#{name.truncate(label_max_length - res.length)}, #{res}"
|
||||
end
|
||||
end
|
||||
|
@ -12,8 +12,10 @@ class AccountingExportWorker
|
||||
data = JSON.parse(export.query)
|
||||
service = AccountingExportService.new(
|
||||
data['columns'],
|
||||
encoding: data['encoding'], format: export.extension, separator: export.key, date_format: data['date_format']
|
||||
encoding: data['encoding'], format: export.extension, separator: export.key
|
||||
)
|
||||
service.set_options(date_format: data['date_format'], decimal_separator: data['decimal_separator'],
|
||||
label_max_length: data['label_max_length'], export_zeros: data['export_invoices_at_zero'])
|
||||
|
||||
service.export(data['start_date'], data['end_date'], export.file)
|
||||
|
||||
|
@ -139,6 +139,11 @@ en:
|
||||
credit_euro: "Euro credit"
|
||||
lettering: "Lettering"
|
||||
VAT: 'VAT'
|
||||
subscription: "subscr."
|
||||
Machine_reservation: "machine reserv."
|
||||
Training_reservation: "training reserv."
|
||||
Event_reservation: "event reserv."
|
||||
Space_reservation: "space reserv."
|
||||
|
||||
trainings:
|
||||
# training availabilities
|
||||
@ -321,7 +326,7 @@ en:
|
||||
users_subscriptions: "of the subscriptions' list"
|
||||
users_reservations: "of the reservations' list"
|
||||
availabilities_index: "of the reservations availabilities"
|
||||
accounting_accounting-software: "of the accounting data"
|
||||
accounting_acd: "of the accounting data to ACD"
|
||||
is_over: "is over."
|
||||
download_here: "Download here"
|
||||
notify_member_about_coupon:
|
||||
|
@ -139,6 +139,11 @@ es:
|
||||
credit_euro: "Euro credit" # translation_missing
|
||||
lettering: "Lettering" # translation_missing
|
||||
VAT: 'IVA'
|
||||
subscription: "subscr." # translation_missing
|
||||
Machine_reservation: "machine reserv." # translation_missing
|
||||
Training_reservation: "training reserv." # translation_missing
|
||||
Event_reservation: "event reserv." # translation_missing
|
||||
Space_reservation: "space reserv." # translation_missing
|
||||
|
||||
trainings:
|
||||
# training availabilities
|
||||
@ -321,7 +326,7 @@ es:
|
||||
users_subscriptions: "de la lista de suscripciones"
|
||||
users_reservations: "de la lista de reservas"
|
||||
availabilities_index: "de las reservas disponibles"
|
||||
accounting_accounting-software: "de los datos contables"
|
||||
accounting_acd: "de los datos contables para ACD"
|
||||
is_over: "se ha acabado."
|
||||
download_here: "Descargar aquí"
|
||||
notify_member_about_coupon:
|
||||
|
@ -139,6 +139,11 @@ fr:
|
||||
credit_euro: "Crédit euro"
|
||||
lettering: "Lettrage"
|
||||
VAT: 'TVA'
|
||||
subscription: "abo."
|
||||
Machine_reservation: "réserv. machine"
|
||||
Training_reservation: "réserv. formation"
|
||||
Event_reservation: "réserv. évènement"
|
||||
Space_reservation: "réserv. espace"
|
||||
|
||||
trainings:
|
||||
# disponibilités formations
|
||||
@ -321,7 +326,7 @@ fr:
|
||||
users_subscriptions: "de la liste des abonnements"
|
||||
users_reservations: "de la liste des réservations"
|
||||
availabilities_index: "des disponibilités de réservations"
|
||||
accounting_accounting-software: "des données comptables"
|
||||
accounting_acd: "des données comptables pour ACD"
|
||||
is_over: "est terminé."
|
||||
download_here: "Téléchargez ici"
|
||||
notify_member_about_coupon:
|
||||
|
@ -139,6 +139,11 @@ pt:
|
||||
credit_euro: "Euro credit" # translation_missing
|
||||
lettering: "Lettering" # translation_missing
|
||||
VAT: 'IVA'
|
||||
subscription: "subscr." # translation_missing
|
||||
Machine_reservation: "machine reserv." # translation_missing
|
||||
Training_reservation: "training reserv." # translation_missing
|
||||
Event_reservation: "event reserv." # translation_missing
|
||||
Space_reservation: "space reserv." # translation_missing
|
||||
|
||||
trainings:
|
||||
# training availabilities
|
||||
@ -321,7 +326,7 @@ pt:
|
||||
users_subscriptions: "da lista de assinaturas"
|
||||
users_reservations: "da lista de reservas"
|
||||
availabilities_index: "de reservas disponíveis"
|
||||
accounting_accounting-software: "de dados contábeis"
|
||||
accounting_acd: "de dados contábeis para ACD"
|
||||
is_over: "está finalizado."
|
||||
download_here: "Baixe aqui"
|
||||
notify_member_about_coupon:
|
||||
|
Loading…
x
Reference in New Issue
Block a user