Class: Inventory::PastPromisedDateReminder

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

Overview

Service object: past promised date reminder.

Instance Method Summary collapse

Instance Method Details

#processObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/services/inventory/past_promised_date_reminder.rb', line 4

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