Skip to content

Commit

Permalink
Merge pull request #15 from Purple-Stock/feat/filter-pending-products
Browse files Browse the repository at this point in the history
create a filter for pending products
  • Loading branch information
puppe1990 authored Dec 15, 2023
2 parents 210e20f + e9c7daf commit 93d0bc2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
16 changes: 15 additions & 1 deletion app/controllers/orders_control_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@ def show_orders_products_stock
.order(custom_id: :desc)
end


def show_pending_orders
@pending_order_items = BlingOrderItem.where(situation_id: BlingOrderItem::Status::PENDING)
situation_id = params[:situation_id]
store_id = params[:store_id]

if situation_id.present?
cleaned_situation_ids = situation_id.split(',').map(&:to_i)
else
cleaned_situation_ids = BlingOrderItem::Status::PENDING
end

if store_id.present?
@pending_order_items = BlingOrderItem.where(situation_id: cleaned_situation_ids, store_id: store_id)
else
@pending_order_items = BlingOrderItem.where(situation_id: cleaned_situation_ids)
end
end

def show_orders_business_day
Expand Down
8 changes: 8 additions & 0 deletions app/jobs/update_items_bling_order_items_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class UpdateItemsBlingOrderItemsJob < ApplicationJob
queue_as :default

def perform(store_id, situation_id, current_tenant_id)
bling_order_ids = BlingOrderItem.where(store_id: store_id, situation_id: situation_id, items: nil).pluck(:bling_order_id)
Services::Bling::FindOrders.call(order_command: 'find_orders', tenant: current_tenant_id, ids: bling_order_ids)
end
end
9 changes: 8 additions & 1 deletion app/models/bling_order_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ class BlingOrderItem < ApplicationRecord
"24" => 'Verificado',
"94871" => 'Pendente',
"95745" => 'Impresso',
"12" => 'Cancelado'
"12" => 'Cancelado',
}.freeze

STATUS_PENDING_NAME_KEY_VALUE = {
"15, 94871, 95745" => 'Pedidos Pagos Pendentes',
"94871" => 'Pendente',
"15" => 'Em andamento',
"95745" => 'Impresso',
}.freeze

class Status
Expand Down
15 changes: 15 additions & 0 deletions app/views/orders_control/show_pending_orders.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
</div>

<div class="container">
<%= form_with(url: show_pending_orders_path, method: :get, local: true) do |form| %>
<div class="form-group">
<%= form.label :situation_id, 'Filtro por Status' %>
<%= form.select :situation_id, BlingOrderItem::STATUS_PENDING_NAME_KEY_VALUE.invert,
{ include_blank: 'Select Status', selected: params[:situation_id] },
{ class: 'form-control' } %>
</div>
<div class="form-group">
<%= form.label :store_id, 'Filtro por Loja' %>
<%= form.select :store_id, BlingOrderItem::STORE_ID_NAME_KEY_VALUE.invert,
{ include_blank: 'Todas', selected: params[:store_id] },
{ class: 'form-control' } %>
</div>
<%= form.submit 'Filtro', class: 'btn btn-primary' %>
<% end %>
<div class="row justify-content-center">

<% if @pending_order_items.present? %>
Expand Down

0 comments on commit 93d0bc2

Please sign in to comment.