app/services/distribution_itemized_breakdown_service.rb
#
# Initializes the DistributionItemizedBreakdownService whoms
# purpose to construct a itemized breakdown of items distributed
# and what is left on-hand currently (at the time of running)
#
# @param organization [Organization]
# @param distribution_ids [Array<Integer>]
# @return [DistributionItemizedBreakdownService]
Initializes the DistributionItemizedBreakdownService whoms
purpose to construct a itemized breakdown of items distributed
and what is left on-hand currently (at the time of running)
Initializes the DistributionItemizedBreakdownService whoms purpose to construct a itemized breakdown of items distributed and what is left on - hand currently ( at the time of running )
def fetch_items_distributed
    item_distribution_hash = distributions.each_with_object({}) do |d, acc|
      d.line_items.each do |i|
        key = i.item.name
        acc[key] ||= {distributed: 0}
        acc[key][:distributed] += i.quantity
      end
    end
    item_distribution_hash.map { |k, v| v.merge(name: k) }
  end
def fetch_items_distributed item_distribution_hash = distributions . each_with_object ( { } ) do | d , acc | d . line_items . each do | i | key = i . item . name acc [ key ] ||= { distributed : 0 } acc [ key ] [ :distributed ] += i . quantity end end item_distribution_hash . map { | k , v | v . merge ( name : k ) } end
Initializes the DistributionItemizedBreakdownService whoms
purpose to construct a itemized breakdown of items distributed
and what is left on-hand currently (at the time of running)
Initializes the DistributionItemizedBreakdownService whoms purpose to construct a itemized breakdown of items distributed and what is left on - hand currently ( at the time of running )
None
DistributionItemizedBreakdownService
<not_specific>
None