Class: Comee::Core::Util
- Inherits:
-
Object
- Object
- Comee::Core::Util
- Defined in:
- app/utils/comee/core/util.rb
Class Method Summary collapse
-
.generate_number(clz, field, prefix, sep = nil, start = 1) ⇒ Object
This method generates document numbers with a certain prefix and a serial suffix.
Class Method Details
.generate_number(clz, field, prefix, sep = nil, start = 1) ⇒ Object
This method generates document numbers with a certain prefix and a serial suffix
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/utils/comee/core/util.rb', line 6 def self.generate_number(clz, field, prefix, sep = nil, start = 1) # clz_hash = { # "PurchaseRequisition" => "PR", # "PurchaseOrder" => "PO", # "Invoice" => "IN", # "SalesOrder" => "SO", # "DeliveryNote" => "DN" # } clazz_name = "Comee::Core::#{clz}" clazz = clazz_name.constantize last = clazz.last return "#{prefix}#{sep}#{start}" unless last index = prefix.length val = last.send(field) pref = val.slice(0, index) suff = sep ? val.slice(index + 1, val.length).to_i : val.slice(index, val.length).to_i return "#{prefix}#{sep}#{start}" unless prefix == pref "#{prefix}#{sep}#{suff + 1}" end |