A Rails gem providing FIFO (First In, First Out) and LIFO (Last In, First Out) inventory calculation methods for ActiveRecord models.
Add this line to your application's Gemfile:
gem "acts_as_fifo_lifo"And then execute:
$ bundleOr install it yourself as:
$ gem install acts_as_fifo_lifoInclude the module in your ActiveRecord model and configure the field mappings:
class StockTransaction < ApplicationRecord
acts_as_fifo_lifo item_field: :item_id,
qty_field: :quantity,
cost_field: :unit_cost,
time_field: :created_at,
batch_field: :batch_number,
storage_field: :storage_id,
operation_field: :operation_id,
operation_type_field: :operation_type
endFIFO LIFO Warehouse Application
Returns an ordered list of batches needed to satisfy a quantity request.
StockTransaction.get_batches_for(1, 1, 100, Time.current, method: "fifo")
# => [{ batch_number: "B001", qty: 50, cost: 10.5, batch_time: 2024-01-01 10:00:00 }, ...]Returns stock balance grouped by storage, item, and batch in a nested structure.
Returns stock balance grouped by storage and item with mean cost calculation.
stock_movement_calculation(storage_id: nil, item_id: nil, start_time: nil, end_time: nil, fields_info: {})
Returns stock movement with running balance, grouped by storage, item, and transaction.
Returns an ActiveRecord::Relation with aggregate stock data per item (total_qty and mean_cost).
Transforms item stock balance records into a structured array format.
Contribution directions go here.
The gem is available as open source under the terms of the MIT License.