Skip to content

Commit 741e9bc

Browse files
authored
Merge pull request #304 from Purple-Stock/staging
Staging
2 parents fced950 + 3b2751a commit 741e9bc

File tree

2 files changed

+55
-28
lines changed

2 files changed

+55
-28
lines changed

app/controllers/orders_control_controller.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,29 @@ def show_orders_products_stock
2424
def show_pending_orders
2525
situation_id = params[:situation_id]
2626
store_id = params[:store_id]
27-
27+
2828
if situation_id.present?
2929
cleaned_situation_ids = situation_id.split(',').map(&:to_i)
3030
else
3131
cleaned_situation_ids = BlingOrderItem::Status::PENDING
3232
end
33-
33+
3434
pending_items = Item.includes(:bling_order_item).where(bling_order_items: { situation_id: cleaned_situation_ids })
35-
35+
3636
if store_id.present?
37-
@pending_order_items = pending_items.where(bling_order_items: { store_id: store_id })
37+
@all_items = pending_items.where(bling_order_items: { store_id: store_id })
3838
else
39-
@pending_order_items = pending_items
39+
@all_items = pending_items
4040
end
41-
41+
42+
# Group items by store and sort by total quantity
43+
@sorted_stores = @all_items.group_by { |item| item.bling_order_item.store_name }
44+
.sort_by { |_, items| -items.sum(&:quantity) }
45+
.to_h
46+
4247
respond_to do |format|
4348
format.html # show.html.erb
44-
format.csv { send_data generate_csv(@pending_order_items), filename: "pending-orders-#{Date.today}.csv" }
49+
format.csv { send_data generate_csv(@all_items), filename: "pending-orders-#{Date.today}.csv" }
4550
end
4651
end
4752

app/views/orders_control/show_pending_orders.html.erb

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,53 @@
2020
<% end %>
2121

2222
<div class="row justify-content-center">
23-
<% if @all_items.present? %>
24-
<% @all_items.group_by { |item| item.bling_order_item.store_name }.each do |loja_name, items| %>
23+
<% if @sorted_stores.present? %>
24+
<% @sorted_stores.each do |loja_name, items| %>
2525
<div class="col-md-12">
2626
<div class="card mb-4">
27+
<div class="card-header bg-primary text-white">
28+
<h5 class="mb-0"><%= loja_name %> - Total: <%= items.sum(&:quantity) %> unidades</h5>
29+
</div>
2730
<div class="card-body">
28-
<h5 class="card-title"><%= loja_name %></h5>
29-
<% items.group_by(&:sku).each do |codigo, sku_items| %>
30-
<% sorted_sku_items = sku_items.sort_by { |item| -item.quantity.to_i } %>
31-
<div>
32-
<a href="#" class="btn btn-info" data-toggle="collapse" data-target=".collapse<%= codigo %>">
33-
Código <%= codigo %> - <%= sorted_sku_items.sum { |item| item.quantity.to_i } %> unidades
34-
</a>
35-
<% sorted_sku_items.each do |item| %>
36-
<div class="collapse collapse<%= codigo %> mt-2">
37-
<div class="card card-body">
38-
Pedido: <%= item.bling_order_item.bling_order_id %>, Quantidade: <%= item.quantity %> unidades<br>
39-
<a href='https://www.bling.com.br/vendas.php#edit/<%= item.bling_order_item.bling_order_id %>'>Ver Pedido no Bling</a>
40-
<p>Status: <%= item.pending? ? 'Pendente' : 'Não Pendente' %></p>
41-
<% if item.bling_order_item.situation_id == BlingOrderItem::Status::PENDING %>
42-
<%= link_to 'Marcar como Pendente', update_status_item_path(item, status: 'pendente'), method: :patch, class: 'btn btn-success' %>
43-
<%= link_to 'Marcar como Não Pendente', update_status_item_path(item, status: 'nao_pendente'), method: :patch, class: 'btn btn-danger' %>
44-
<% end %>
45-
</div>
31+
<% items.group_by(&:sku).sort_by { |_, sku_items| -sku_items.sum(&:quantity) }.each do |codigo, sku_items| %>
32+
<div class="mb-3">
33+
<button class="btn btn-info btn-block text-left" type="button" data-toggle="collapse" data-target=".collapse<%= codigo %>">
34+
<strong>Código <%= codigo %></strong> - <%= sku_items.sum(&:quantity) %> unidades
35+
</button>
36+
<div class="collapse collapse<%= codigo %> mt-2">
37+
<div class="table-responsive">
38+
<table class="table table-bordered table-striped">
39+
<thead class="thead-light">
40+
<tr>
41+
<th>Pedido</th>
42+
<th>Quantidade</th>
43+
<th>Status</th>
44+
<th>Ações</th>
45+
</tr>
46+
</thead>
47+
<tbody>
48+
<% sku_items.sort_by(&:quantity).reverse.each do |item| %>
49+
<tr>
50+
<td>
51+
<%= item.bling_order_item.bling_order_id %>
52+
<a href='https://www.bling.com.br/vendas.php#edit/<%= item.bling_order_item.bling_order_id %>' target="_blank" class="btn btn-sm btn-outline-secondary ml-2">
53+
Ver no Bling
54+
</a>
55+
</td>
56+
<td><%= item.quantity %> unidades</td>
57+
<td><%= item.pending? ? 'Pendente' : 'Não Pendente' %></td>
58+
<td>
59+
<% if item.bling_order_item.situation_id == BlingOrderItem::Status::PENDING %>
60+
<%= link_to 'Marcar Pendente', update_status_item_path(item, status: 'pendente'), method: :patch, class: 'btn btn-sm btn-success' %>
61+
<%= link_to 'Marcar Não Pendente', update_status_item_path(item, status: 'nao_pendente'), method: :patch, class: 'btn btn-sm btn-danger' %>
62+
<% end %>
63+
</td>
64+
</tr>
65+
<% end %>
66+
</tbody>
67+
</table>
4668
</div>
47-
<% end %>
69+
</div>
4870
</div>
4971
<% end %>
5072
</div>

0 commit comments

Comments
 (0)