Skip to content

Commit

Permalink
Merge pull request #326 from Purple-Stock/staging
Browse files Browse the repository at this point in the history
create new reports
  • Loading branch information
puppe1990 authored Sep 16, 2024
2 parents 76801ea + d7fb247 commit 93cc05e
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 0 deletions.
54 changes: 54 additions & 0 deletions app/controllers/productions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ def missing_pieces
end

@tailors_summary = calculate_tailors_summary(@productions_with_missing_pieces)

respond_to do |format|
format.html
format.csv { send_data generate_tailors_summary_csv, filename: "tailors_summary_#{Date.today}.csv" }
end
end

def products_in_production_report
@products_summary = ProductionProduct.joins(:production, :product)
.where('quantity > COALESCE(pieces_delivered, 0) + COALESCE(dirty, 0) + COALESCE(error, 0) + COALESCE(discard, 0)')
.group('products.id, products.name')
.select('products.id, products.name, SUM(quantity) as total_quantity, SUM(quantity - COALESCE(pieces_delivered, 0) - COALESCE(dirty, 0) - COALESCE(error, 0) - COALESCE(discard, 0)) as total_missing')
.order('total_quantity DESC') # Change this line to order by total_quantity in descending order

respond_to do |format|
format.html
format.csv { send_data generate_products_in_production_csv, filename: "products_in_production_#{Date.today}.csv" }
end
end

private
Expand Down Expand Up @@ -121,4 +139,40 @@ def calculate_tailors_summary(productions)

summary
end

def generate_tailors_summary_csv
require 'csv'

CSV.generate(headers: true) do |csv|
csv << ['Tailor Name', 'Total Productions', 'Total Missing Pieces', 'Products with Missing Pieces']

@tailors_summary.each do |tailor_id, summary|
tailor = Tailor.find(tailor_id)
products_summary = summary[:products].map { |product_id, count| "#{Product.find(product_id).name}: #{count}" }.join(', ')

csv << [
tailor.name,
summary[:productions_count],
summary[:total_missing_pieces],
products_summary
]
end
end
end

def generate_products_in_production_csv
require 'csv'

CSV.generate(headers: true) do |csv|
csv << ['Product Name', 'Total Quantity', 'Total Missing Pieces']

@products_summary.each do |product|
csv << [
product.name,
product.total_quantity,
product.total_missing
]
end
end
end
end
4 changes: 4 additions & 0 deletions app/views/productions/missing_pieces.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
<%= submit_tag t('productions.missing_pieces.apply_filter'), class: 'btn btn-primary' %>
<% end %>

<!-- Add this line below the form -->
<%= link_to t('.download_csv'), missing_pieces_productions_path(format: :csv, tailor_id: params[:tailor_id], status: params[:status]), class: 'btn btn-secondary mb-3 mr-2' %>
<%= link_to t('.products_in_production_report'), products_in_production_report_productions_path, class: 'btn btn-info mb-3' %>

<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item" role="presentation">
<a class="nav-link active" id="productions-tab" data-toggle="tab" href="#productions" role="tab" aria-controls="productions" aria-selected="true">Productions</a>
Expand Down
24 changes: 24 additions & 0 deletions app/views/productions/products_in_production_report.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<div class="container">
<h1 class="mb-4"><%= t('.title') %></h1>

<%= link_to t('.download_csv'), products_in_production_report_productions_path(format: :csv), class: 'btn btn-secondary mb-3' %>

<table class="table table-striped">
<thead>
<tr>
<th><%= t('.product_name') %></th>
<th><%= t('.total_quantity') %></th>
<th><%= t('.total_missing') %></th>
</tr>
</thead>
<tbody>
<% @products_summary.each do |product| %>
<tr>
<td><%= product.name %></td>
<td><%= product.total_quantity %></td>
<td><%= product.total_missing %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
3 changes: 3 additions & 0 deletions app/views/shared/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li class="<%= active_nav_item('productions', 'missing_pieces') %>">
<%= link_to t("productions.side_missing_pieces"), missing_pieces_productions_path, class: 'nav-link' %>
</li>
<li class="<%= active_nav_item('productions', 'products_in_production_report') %>">
<%= link_to t("productions.products_in_production_report"), products_in_production_report_productions_path, class: 'nav-link' %>
</li>
<li class="<%= active_nav_item('tailors', 'index') %>">
<%= link_to t("tailors.list"), tailors_path, class: 'nav-link' %>
</li>
Expand Down
7 changes: 7 additions & 0 deletions config/locales/pt-BR.models.productions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pt-BR:
products_with_missing_pieces: "Produtos com Peças Faltantes"
productions: "Produções"
tailors_summary: "Resumo dos Costureiros"
products_in_production_report: "Relatório de Produtos em Produção"
show:
title: "Detalhes da Produção"
tailor_details: "Detalhes do Costureiro"
Expand Down Expand Up @@ -76,6 +77,12 @@ pt-BR:
destroy:
production_destroyed: "Produção excluída com sucesso."
destruction_failed: "Falha ao excluir a produção."
products_in_production_report:
title: "Relatório de Produtos em Produção"
download_csv: "Baixar CSV"
product_name: "Nome do Produto"
total_quantity: "Quantidade Total"
total_missing: "Total de Peças Faltantes"
helpers:
submit:
create: "Criar %{model}"
Expand Down
1 change: 1 addition & 0 deletions config/locales/sidebar.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pt-BR:
side_missing_pieces: "Peças Faltantes"
list: Lista de Produções
create: Criar Produção
products_in_production_report: "Relatório de Produtos em Produção"
tailors:
one: Costureiro
two: Costureiros
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
resources :productions do
collection do
get 'missing_pieces'
get :products_in_production_report
end
member do
patch :verify
Expand Down

0 comments on commit 93cc05e

Please sign in to comment.