Sha256: 9ed517226a8662d7d58c2fbae07df9c6f02a9afee8d007797389b757cba76018

Contents?: true

Size: 911 Bytes

Versions: 28

Compression:

Stored size: 911 Bytes

Contents

module Comee
  module Core
    class Util
      # This method generates document numbers with a certain prefix
      # and a serial suffix
      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
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
comee_core-0.3.62 app/utils/comee/core/util.rb
comee_core-0.3.61 app/utils/comee/core/util.rb
comee_core-0.3.60 app/utils/comee/core/util.rb
comee_core-0.3.59 app/utils/comee/core/util.rb
comee_core-0.3.58 app/utils/comee/core/util.rb
comee_core-0.3.57 app/utils/comee/core/util.rb
comee_core-0.3.56 app/utils/comee/core/util.rb
comee_core-0.3.55 app/utils/comee/core/util.rb
comee_core-0.3.54 app/utils/comee/core/util.rb
comee_core-0.3.53 app/utils/comee/core/util.rb
comee_core-0.3.51 app/utils/comee/core/util.rb
comee_core-0.3.50 app/utils/comee/core/util.rb
comee_core-0.3.49 app/utils/comee/core/util.rb
comee_core-0.3.48 app/utils/comee/core/util.rb
comee_core-0.3.47 app/utils/comee/core/util.rb
comee_core-0.3.46 app/utils/comee/core/util.rb
comee_core-0.3.45 app/utils/comee/core/util.rb
comee_core-0.3.44 app/utils/comee/core/util.rb
comee_core-0.3.43 app/utils/comee/core/util.rb
comee_core-0.3.42 app/utils/comee/core/util.rb