-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' for release 5.9.1
- Loading branch information
Showing
35 changed files
with
502 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
# frozen_string_literal: true | ||
|
||
# Allows splinting a StatisticIndex into multiple types. | ||
# e.g. The StatisticIndex "subscriptions" may have types like "1 month", "1 year", etc. | ||
class StatisticType < ApplicationRecord | ||
has_one :statistic_index | ||
has_many :statistic_type_sub_types | ||
belongs_to :statistic_index | ||
has_many :statistic_type_sub_types, dependent: :destroy | ||
has_many :statistic_sub_types, through: :statistic_type_sub_types | ||
has_many :statistic_custom_aggregations | ||
has_many :statistic_custom_aggregations, dependent: :destroy | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
# Provides methods around Excel files specification | ||
class ExcelService | ||
class << self | ||
# remove all unauthorized characters from the given Excel's worksheet name | ||
# @param name [String] | ||
# @param replace [String] | ||
# @return [String] | ||
def name_safe(name, replace = '-') | ||
name.gsub(%r{[*|\\:"<>?/]}, replace).truncate(31) | ||
end | ||
|
||
# Generate a name for the current type, compatible with Excel worksheet names | ||
# @param type [StatisticType] | ||
# @param workbook [Axlsx::Workbook] | ||
# @return [String] | ||
def statistic_type_sheet_name(type, workbook) | ||
# see https://msdn.microsoft.com/fr-fr/library/c6bdca6y(v=vs.90).aspx for unauthorized character list | ||
name = "#{type.statistic_index.label} - #{type.label}".gsub(%r{[*|\\:"<>?/]}, '') | ||
# sheet name is limited to 31 characters | ||
if name.length > 31 | ||
name = "#{type.statistic_index.label.truncate(4, omission: '.')} - #{type.label}".gsub(%r{[*|\\:"<>?/]}, '').truncate(31) | ||
end | ||
# we cannot have two sheets with the same name | ||
name = name[0..30] + String((rand * 10).to_i) until workbook.sheet_by_name(name).nil? | ||
name | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# frozen_string_literal: true | ||
|
||
# module definition | ||
module Invoices; end | ||
|
||
# The invoice number is based on the previous invoice | ||
class Invoices::NumberService | ||
class << self | ||
# Get the order number or reference number for the given invoice (not the whole identifier). | ||
# The date part, online payment part, etc. will be excluded and only the number part will be returned. | ||
# @param document [PaymentDocument,NilClass] | ||
# @param setting [String] 'invoice_reference' | 'invoice_order-nb' | ||
# @return [Integer,NilClass] | ||
def number(document, setting = 'invoice_reference') | ||
raise TypeError, "invalid setting #{setting}" unless %w[invoice_order-nb invoice_reference].include?(setting) | ||
return nil if document.nil? | ||
|
||
saved_number = setting == 'invoice_reference' ? document.reference : document.order_number | ||
return nil if saved_number.nil? | ||
|
||
pattern = pattern(document, setting) | ||
pattern = PaymentDocumentService.send(:replace_document_type_pattern, document, pattern) | ||
start_idx = pattern.index(/n+|y+|m+|d+/) | ||
end_idx = pattern.rindex(/n+|y+|m+|d+/) | ||
|
||
saved_number[start_idx..end_idx]&.to_i | ||
end | ||
|
||
# @param document [PaymentDocument,NilClass] | ||
# @param setting [String] 'invoice_reference' | 'invoice_order-nb' | ||
# @return [String,NilClass] 'global' | 'year' | 'month' | 'day' | ||
def number_periodicity(document, setting = 'invoice_reference') | ||
raise TypeError, "invalid setting #{setting}" unless %w[invoice_order-nb invoice_reference].include?(setting) | ||
return nil if document.nil? | ||
|
||
pattern = pattern(document, setting) | ||
pattern = PaymentDocumentService.send(:replace_document_type_pattern, document, pattern) | ||
|
||
return 'global' if pattern.match?(/n+/) | ||
return 'year' if pattern.match?(/y+/) | ||
return 'month' if pattern.match?(/m+/) | ||
return 'day' if pattern.match?(/d+/) | ||
|
||
nil | ||
end | ||
|
||
# Get the pattern applicable to generate the number of the given invoice. | ||
# @param document [PaymentDocument] | ||
# @param setting [String] 'invoice_reference' | 'invoice_order-nb' | ||
# @return [String] | ||
def pattern(document, setting = 'invoice_reference') | ||
raise TypeError, "invalid setting #{setting}" unless %w[invoice_order-nb invoice_reference].include?(setting) | ||
|
||
value = Setting.find_by(name: setting).value_at(document.created_at) | ||
value || if document.created_at < Setting.find_by(name: setting).first_update | ||
Setting.find_by(name: setting).first_value | ||
else | ||
Setting.get(setting) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.