Skip to content

Commit b266fed

Browse files
authored
Merge pull request #15 from Purple-Stock/feat/filter-pending-products
create a filter for pending products
2 parents 98db3e0 + 519a2fb commit b266fed

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

app/controllers/orders_control_controller.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,22 @@ def show_orders_products_stock
2020
.order(custom_id: :desc)
2121
end
2222

23+
2324
def show_pending_orders
24-
@pending_order_items = BlingOrderItem.where(situation_id: BlingOrderItem::Status::PENDING)
25+
situation_id = params[:situation_id]
26+
store_id = params[:store_id]
27+
28+
if situation_id.present?
29+
cleaned_situation_ids = situation_id.split(',').map(&:to_i)
30+
else
31+
cleaned_situation_ids = BlingOrderItem::Status::PENDING
32+
end
33+
34+
if store_id.present?
35+
@pending_order_items = BlingOrderItem.where(situation_id: cleaned_situation_ids, store_id: store_id)
36+
else
37+
@pending_order_items = BlingOrderItem.where(situation_id: cleaned_situation_ids)
38+
end
2539
end
2640

2741
def show_orders_business_day
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class UpdateItemsBlingOrderItemsJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(store_id, situation_id, current_tenant_id)
5+
bling_order_ids = BlingOrderItem.where(store_id: store_id, situation_id: situation_id, items: nil).pluck(:bling_order_id)
6+
Services::Bling::FindOrders.call(order_command: 'find_orders', tenant: current_tenant_id, ids: bling_order_ids)
7+
end
8+
end

app/models/bling_order_item.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ class BlingOrderItem < ApplicationRecord
4848
"24" => 'Verificado',
4949
"94871" => 'Pendente',
5050
"95745" => 'Impresso',
51-
"12" => 'Cancelado'
51+
"12" => 'Cancelado',
52+
}.freeze
53+
54+
STATUS_PENDING_NAME_KEY_VALUE = {
55+
"15, 94871, 95745" => 'Pedidos Pagos Pendentes',
56+
"94871" => 'Pendente',
57+
"15" => 'Em andamento',
58+
"95745" => 'Impresso',
5259
}.freeze
5360

5461
class Status

app/views/orders_control/show_pending_orders.html.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
</div>
66

77
<div class="container">
8+
<%= form_with(url: show_pending_orders_path, method: :get, local: true) do |form| %>
9+
<div class="form-group">
10+
<%= form.label :situation_id, 'Filtro por Status' %>
11+
<%= form.select :situation_id, BlingOrderItem::STATUS_PENDING_NAME_KEY_VALUE.invert,
12+
{ include_blank: 'Select Status', selected: params[:situation_id] },
13+
{ class: 'form-control' } %>
14+
</div>
15+
<div class="form-group">
16+
<%= form.label :store_id, 'Filtro por Loja' %>
17+
<%= form.select :store_id, BlingOrderItem::STORE_ID_NAME_KEY_VALUE.invert,
18+
{ include_blank: 'Todas', selected: params[:store_id] },
19+
{ class: 'form-control' } %>
20+
</div>
21+
<%= form.submit 'Filtro', class: 'btn btn-primary' %>
22+
<% end %>
823
<div class="row justify-content-center">
924

1025
<% if @pending_order_items.present? %>

0 commit comments

Comments
 (0)