mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-20 14:54:15 +01:00
(bug) find_by_number should consider the number period
Also: added progress indicators
This commit is contained in:
parent
a184f3b0be
commit
e9205775ce
@ -35,13 +35,27 @@ class Invoices::NumberService
|
||||
pattern = pattern(date, setting)
|
||||
pattern = pattern.gsub(/([SXR]\[[^\]]+\])+/, '%')
|
||||
if pattern.match?(/n+/)
|
||||
pattern = pattern.gsub(/n+(?![^\[]*\])/) do |match|
|
||||
pattern = pattern.gsub(/n+/) do |match|
|
||||
pad_and_truncate(number, match.to_s.length)
|
||||
end
|
||||
pattern = pattern.gsub(/[YMD]+/) { |match| '_' * match.to_s.length }
|
||||
else
|
||||
start_idx = pattern.index(/y+|m+|d+/)
|
||||
end_idx = pattern.rindex(/y+|m+|d+/)
|
||||
pattern[start_idx..end_idx] = pad_and_truncate(number, end_idx - start_idx + 1)
|
||||
case pattern
|
||||
when /y+/
|
||||
pattern = pattern.gsub(/y+/) do |match|
|
||||
pad_and_truncate(number, match.to_s.length)
|
||||
end
|
||||
pattern = pattern.gsub(/[MD]+/) { |match| '_' * match.to_s.length }
|
||||
when /m+/
|
||||
pattern = pattern.gsub(/m+/) do |match|
|
||||
pad_and_truncate(number, match.to_s.length)
|
||||
end
|
||||
pattern = pattern.gsub(/D+/) { |match| '_' * match.to_s.length }
|
||||
when /d+/
|
||||
pattern = pattern.gsub(/d+/) do |match|
|
||||
pad_and_truncate(number, match.to_s.length)
|
||||
end
|
||||
end
|
||||
end
|
||||
pattern = PaymentDocumentService.send(:replace_date_pattern, pattern, date)
|
||||
|
||||
|
@ -36,7 +36,7 @@ namespace :fablab do
|
||||
total = missing_references.values.filter(&:present?).flatten.count
|
||||
counter = 1
|
||||
missing_references.each_pair do |date, numbers|
|
||||
numbers.reverse_each.with_index do |number, index|
|
||||
numbers.uniq.sort.reverse_each.with_index do |number, index|
|
||||
print "#{counter} / #{total}\r"
|
||||
invoice = Invoice.new(
|
||||
total: 0,
|
||||
|
@ -29,11 +29,14 @@ namespace :fablab do
|
||||
end
|
||||
end
|
||||
end
|
||||
print "\n"
|
||||
print "\nRestoring the store orders numbers...\n"
|
||||
Order.where(reference: nil).order(id: :asc).find_each do |order|
|
||||
order.update(reference: PaymentDocumentService.generate_order_number(order))
|
||||
end
|
||||
Invoice.where(order_number: nil).order(id: :asc).find_each do |invoice|
|
||||
puts 'Filling the gaps for invoices numbers...'
|
||||
max = Invoice.where(order_number: nil).count
|
||||
Invoice.where(order_number: nil).order(id: :asc).find_each.with_index do |invoice, index|
|
||||
print "Processing: #{index} / #{max}\r"
|
||||
next unless invoice.payment_schedule_item.nil?
|
||||
|
||||
unless invoice.order.nil?
|
||||
@ -43,12 +46,14 @@ namespace :fablab do
|
||||
|
||||
invoice.update(order_number: PaymentDocumentService.generate_order_number(invoice))
|
||||
end
|
||||
puts 'Restoring the payment schedules numbers...'
|
||||
PaymentSchedule.order(id: :asc).find_each do |schedule|
|
||||
schedule.update(order_number: PaymentDocumentService.generate_order_number(schedule))
|
||||
schedule.ordered_items.each do |item|
|
||||
item.invoice&.update(order_number: schedule.order_number)
|
||||
end
|
||||
end
|
||||
puts 'Restoring the refund invoices numbers...'
|
||||
Avoir.where(order_number: nil).order(id: :asc).find_each do |refund|
|
||||
next if refund.invoice.nil?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user