Class: Inventory::PastPromisedDateReminder

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/inventory/past_promised_date_reminder.rb

Instance Method Summary collapse

Instance Method Details

#processObject



3
4
5
6
7
8
9
10
11
12
13
# File 'app/services/inventory/past_promised_date_reminder.rb', line 3

def process
  items = PurchaseOrderItem.joins(:purchase_order_shipments).where(state: ['not_receipted','partially_receipted']).where.not(purchase_order_shipments: { promised_delivery_date: nil }).where('promised_delivery_date < ?', 3.days.ago).includes(purchase_order: [:supplier, :store])
  if items.any?
    items.group_by {|i| i.purchase_order.store}.each do |store, items|
      InternalMailer.past_promised_date_reminder(store, items).deliver_later
    end
    return "Reminder sent"
  else
    return "No items found"
  end
end