Class: Inventory::EmptyPromisedDateReminder

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

Instance Method Summary collapse

Instance Method Details

#processObject



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

def process
  items = PurchaseOrderItem.left_joins(:purchase_order_shipments)
                           .where(purchase_order_shipments: { promised_delivery_date: nil })
                           .where.not(state: %w[cancelled fully_receipted])
                           .where(purchase_order_items: { created_at: ...3.days.ago })
                           .joins(:purchase_order)
                           .where.not(purchase_orders: { state: %w[cancelled landed_costs fully_receipted] })
                           .includes(purchase_order: %i[supplier store])

  return 'No items found' unless items.any?

  InternalMailer.empty_promised_date_reminder(items).deliver
  'Reminder sent'
end