Skip to content

Commit

Permalink
add a calendar of productions
Browse files Browse the repository at this point in the history
  • Loading branch information
puppe1990 committed Oct 15, 2024
1 parent 7c608a1 commit d36e84b
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ gem 'net-smtp', require: false

gem 'csv-importer'

gem "simple_calendar"

group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'bullet'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,8 @@ GEM
sexp_processor (4.17.1)
shoulda-matchers (5.3.0)
activesupport (>= 5.2.0)
simple_calendar (3.0.4)
rails (>= 6.1)
simplecov (0.21.2)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -694,6 +696,7 @@ DEPENDENCIES
sentry-ruby
serviceworker-rails
shoulda-matchers (~> 5.3, >= 5.3.0)
simple_calendar
simplecov (~> 0.21.2)
solargraph
spreadsheet_architect
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*= require components/zebra-table
*= require components/thumb-image
*= require components/thumb-image-mobile
*= require simple_calendar
*/

.turbolinks-progress-bar {
Expand Down
20 changes: 20 additions & 0 deletions app/assets/stylesheets/productions.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.simple-calendar {
.day {
height: 80px;
}

.production-event {
padding: 2px 4px;
margin-bottom: 2px;
border-radius: 4px;
font-size: 12px;
}

.confirmed {
background-color: #a8e6cf;
}

.unconfirmed {
background-color: #ffd3b6;
}
}
9 changes: 8 additions & 1 deletion app/controllers/productions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ def price_per_piece_report
end
end

def calendar
start_date = params.fetch(:start_date, Date.today).to_date
@productions = Production.where(paid: false)
.where("confirmed = ? OR expected_delivery_date >= ?", true, start_date)
.order(confirmed: :desc, expected_delivery_date: :asc, payment_date: :asc)
end

private

def set_production
Expand Down Expand Up @@ -345,4 +352,4 @@ def next_service_order_number
"1000" # Starting number if no records exist
end
end
end
end
8 changes: 8 additions & 0 deletions app/models/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,12 @@ def total_paid
def remaining_balance
total_price - total_paid
end

def calendar_date
if confirmed?
payment_date
else
expected_delivery_date
end
end
end
97 changes: 97 additions & 0 deletions app/views/productions/calendar.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<br><br>
<h1 class="mb-4">Productions Calendar</h1>

<div class="card">
<div class="card-body">
<%= month_calendar(events: @productions, attribute: :calendar_date) do |date, productions| %>
<div class="calendar-date"><%= date.day %></div>

<% productions.each do |production| %>
<div class="production-item <%= production.confirmed ? 'confirmed' : 'unconfirmed' %>">
<%= link_to production_path(production), class: "production-link", title: "View details" do %>
<strong><%= production.service_order_number %></strong>
<div class="production-details">
<small><%= production.tailor.name %></small>
<small><%= production.production_products.sum(:quantity) %> pcs</small>
<% if production.confirmed %>
<span class="badge badge-success">Entregue</span>
<% if production.payment_date %>
<% if production.payment_date < Date.today %>
<span class="badge badge-danger">Pagamento Atrasado</span>
<% else %>
<span class="badge badge-info">Pagamento em Espera</span>
<% end %>
<% end %>
<% else %>
<span class="badge badge-warning">Não Entregue</span>
<% end %>
</div>
<% end %>
</div>
<% end %>
<% end %>
</div>
</div>

<style>
.simple-calendar {
.day { height: 100px; }
.wday-0 { background-color: #f8d7da; }
.wday-6 { background-color: #f8d7da; }
.today { background-color: #e8f4f8; }
.past { opacity: 0.6; }
.future { }
.start-date { }
.prev-month { background-color: #f0f0f0; }
.next-month { background-color: #f0f0f0; }
.current-month { }
.has-events { }
}

.calendar-date {
font-weight: bold;
margin-bottom: 5px;
}

.production-item {
margin-bottom: 5px;
padding: 3px;
border-radius: 3px;
font-size: 0.8em;
}

.production-link {
color: inherit;
text-decoration: none;
}

.production-details {
display: flex;
flex-direction: column;
font-size: 0.9em;
}

.confirmed {
background-color: #d4edda;
}

.unconfirmed {
background-color: #fff3cd;
}

.badge {
font-size: 0.7em;
padding: 2px 5px;
margin-top: 2px;
}

.badge-danger {
background-color: #dc3545;
color: white;
}

.badge-info {
background-color: #17a2b8;
color: white;
}
</style>
3 changes: 3 additions & 0 deletions app/views/shared/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
<li class="<%= active_nav_menu_item([top_selling_products_path]) %>">
<%= link_to t("audits.top_selling_products"), top_selling_products_path, class: 'nav-link' %>
</li>
<li class="<%= active_nav_item('productions', 'calendar') %>">
<%= link_to t("productions.calendar"), calendar_productions_path, class: 'nav-link' %>
</li>
<% end %>
<% end %>

Expand Down
3 changes: 2 additions & 1 deletion config/locales/sidebar.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pt-BR:
create: Criar Produção
products_in_production_report: "Produtos em Produção"
price_per_piece_report: "Preço por Peça"
calendar: "Calendário de Produções"
tailors:
one: Costureiro
two: Costureiros
Expand Down Expand Up @@ -87,4 +88,4 @@ pt-BR:
revenue_estimations:
other: Estimativas de Receita
bling_order_items:
list: Lista de Itens de Pedido Bling
list: Lista de Itens de Pedido Bling
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
get 'products_in_production_report'
get 'unpaid_confirmed' # Add this line
get 'price_per_piece_report'
get 'calendar'
end
member do
patch :verify
Expand Down

0 comments on commit d36e84b

Please sign in to comment.