Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the missing pieces view #300

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/controllers/productions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ def destroy
end
end

def missing_pieces
@productions_with_missing_pieces = Production.includes(:tailor, production_products: :product)
.where(id: ProductionProduct.select(:production_id)
.where('quantity > COALESCE(pieces_delivered, 0)'))
.distinct
end

private

def set_production
Expand Down
4 changes: 3 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def display_status(status)
end

def localize(object, options = {})
super(object, options) if object
return nil if object.nil?
format = options[:format] || :default
I18n.localize(object, format: format)
end

alias l localize
Expand Down
2 changes: 2 additions & 0 deletions app/models/bling_order_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# id :bigint not null, primary key
# aliquotaIPI :decimal(, )
# alteration_date :datetime
# city :string(10485760)
# codigo :string
# collected_alteration_date :date
# date :datetime
Expand All @@ -13,6 +14,7 @@
# descricaoDetalhada :text
# items :jsonb
# quantidade :integer
# state :string(10485760)
# unidade :string
# valor :decimal(, )
# value :decimal(, )
Expand Down
21 changes: 20 additions & 1 deletion app/models/localization.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# == Schema Information
#
# Table name: localizations
#
# id :bigint not null, primary key
# address :string
# city :string
# complement :string
# country_name :string
# name :string
# neighborhood :string
# number :string
# state :string
# zip_code :string
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer
# bling_order_item_id :bigint
#
class Localization < ApplicationRecord
belongs_to :account
belongs_to :bling_order_item, optional: false
end
end
3 changes: 3 additions & 0 deletions app/models/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# consider :boolean default(FALSE)
# cut_date :datetime
# deliver_date :datetime
# delivery_date :date
# expected_delivery_date :date
# observation :text
# paid :boolean
Expand All @@ -21,6 +22,7 @@
#
# index_productions_on_account_id (account_id)
# index_productions_on_cut_date (cut_date)
# index_productions_on_delivery_date (delivery_date)
# index_productions_on_expected_delivery_date (expected_delivery_date)
# index_productions_on_tailor_id (tailor_id)
#
Expand All @@ -41,6 +43,7 @@ class Production < ApplicationRecord
validates :cut_date, presence: true
validates :tailor, presence: true
validates :account, presence: true
validates :service_order_number, presence: true, uniqueness: { scope: :account_id }

# Add a method to calculate total pieces delivered
def total_pieces_delivered
Expand Down
16 changes: 8 additions & 8 deletions app/models/production_product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
#
# Table name: production_products
#
# id :bigint not null, primary key
# pieces_delivered :integer
# pieces_missing :integer
# quantity :integer
# created_at :datetime not null
# updated_at :datetime not null
# product_id :bigint not null
# production_id :bigint not null
# id :bigint not null, primary key
# pieces_delivered :integer
# pieces_missing :integer
# quantity :integer
# created_at :datetime not null
# updated_at :datetime not null
# product_id :bigint not null
# production_id :bigint not null
#
# Indexes
#
Expand Down
1 change: 1 addition & 0 deletions app/views/productions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

<div class="section-body">
<%= link_to t('helpers.links.new'), new_production_path, class: 'btn btn-primary mb-3' %>
<%= link_to t('productions.missing_pieces.title'), missing_pieces_productions_path, class: 'btn btn btn-info mb-3 ml-2' %>

<div class="card">
<div class="card-body">
Expand Down
36 changes: 36 additions & 0 deletions app/views/productions/missing_pieces.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<br><br>
<div class="container">
<h1 class="mb-4">Peças Faltantes</h1>

<div class="row">
<% @productions_with_missing_pieces.each do |production| %>
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-header">
<h1 class="card-title">
<%= t('.service_order', number: production.service_order_number.presence || 'N/A') %>
</h1>
</div>
<div class="card-body">
<p><strong><%= Production.human_attribute_name(:tailor) %>:</strong> <%= production.tailor.name %></p>
<p><strong><%= Production.human_attribute_name(:cut_date) %>:</strong> <%= l(production.cut_date) if production.cut_date %></p>
<p><strong><%= Production.human_attribute_name(:expected_delivery_date) %>:</strong> <%= l(production.expected_delivery_date) if production.expected_delivery_date %></p>
<h6 class="mt-3"><%= t('.missing_pieces') %>:</h6>
<ul>
<% production.production_products.each do |pp| %>
<% pieces_missing = pp.quantity - (pp.pieces_delivered || 0) %>
<% if pieces_missing > 0 %>
<li><%= "#{pp.product.name}: #{pieces_missing}" %></li>
<% end %>
<% end %>
</ul>
</div>
<div class="card-footer">
<%= link_to t('helpers.links.edit'), edit_production_path(production), class: 'btn btn-primary btn-sm' %>
<%= link_to t('helpers.links.show'), production_path(production), class: 'btn btn-info btn-sm' %>
</div>
</div>
</div>
<% end %>
</div>
</div>
1 change: 1 addition & 0 deletions app/views/productions/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<div class="actions">
<%= link_to t('.back', :default => t("helpers.links.back")), productions_path, :class => 'btn btn-secondary' %>
<%= link_to t('.edit', :default => t("helpers.links.edit")), edit_production_path(@production), :class => 'btn btn-warning' %>
<%= link_to t('productions.missing_pieces.title'), missing_pieces_productions_path, class: 'btn btn-info' %>
<%= link_to t('.destroy', :default => t("helpers.links.destroy")), production_path(@production), :method => 'delete',
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:class => 'btn btn-danger' %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/shared/_sidebar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
<li class="<%= active_nav_item('productions', 'new') %>">
<%= link_to t("productions.create"), new_production_path, class: 'nav-link' %>
</li>
<li class="<%= active_nav_item('productions', 'missing_pieces') %>">
<%= link_to t("productions.missing_pieces"), missing_pieces_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
5 changes: 5 additions & 0 deletions config/locales/pt-BR.models.productions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ pt-BR:
destroy:
production_destroyed: "Produção excluída com sucesso."
destruction_failed: "Falha ao excluir a produção."
missing_pieces:
title: "Produções com Peças Faltantes"
production_number: "Produção #%{number}"
missing_pieces: "Peças Faltantes"
service_order: "Ordem de Serviço #%{number}"
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 @@ -13,6 +13,7 @@ pt-BR:
productions:
one: Produção
two: Produções
missing_pieces: "Peças Faltantes"
list: Lista de Produções
create: Criar Produção
tailors:
Expand Down
6 changes: 4 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
mount GoodJob::Engine => 'good_job'

resources :productions do
collection do
get 'missing_pieces'
end
member do
get :verify
patch :verify, to: 'productions#update'
patch :verify
end
end

Expand Down
62 changes: 52 additions & 10 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.


ActiveRecord::Schema[7.0].define(version: 2024_02_09_142949) do
ActiveRecord::Schema[7.0].define(version: 2024_09_01_200830) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
Expand All @@ -37,7 +36,7 @@
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", precision: nil, null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
Expand All @@ -49,7 +48,7 @@
t.text "metadata"
t.bigint "byte_size", null: false
t.string "checksum"
t.datetime "created_at", precision: nil, null: false
t.datetime "created_at", null: false
t.string "service_name", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
Expand Down Expand Up @@ -92,12 +91,16 @@
t.string "marketplace_code_id"
t.integer "bling_id"
t.bigint "account_id"
t.decimal "value"
t.jsonb "items"
t.decimal "value"
t.date "collected_alteration_date"
t.string "original_situation_id"
t.string "city", limit: 10485760
t.string "state", limit: 10485760
t.index ["account_id"], name: "index_bling_order_items_on_account_id"
t.index ["bling_order_id"], name: "bling_order_id_index_on_bling_order_items"
t.index ["bling_order_id"], name: "index_bling_order_items_on_bling_order_id", unique: true
t.index ["situation_id", "store_id"], name: "situation_id_index_on_bling_order_items"
end

create_table "categories", force: :cascade do |t|
Expand Down Expand Up @@ -163,13 +166,17 @@
t.datetime "finished_at"
t.text "error"
t.integer "error_event", limit: 2
t.text "error_backtrace", array: true
t.uuid "process_id"
t.index ["active_job_id", "created_at"], name: "index_good_job_executions_on_active_job_id_and_created_at"
t.index ["process_id", "created_at"], name: "index_good_job_executions_on_process_id_and_created_at"
end

create_table "good_job_processes", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.jsonb "state"
t.integer "lock_type", limit: 2
end

create_table "good_job_settings", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
Expand Down Expand Up @@ -202,6 +209,8 @@
t.text "job_class"
t.integer "error_event", limit: 2
t.text "labels", array: true
t.uuid "locked_by_id"
t.datetime "locked_at"
t.index ["active_job_id", "created_at"], name: "index_good_jobs_on_active_job_id_and_created_at"
t.index ["batch_callback_id"], name: "index_good_jobs_on_batch_callback_id", where: "(batch_callback_id IS NOT NULL)"
t.index ["batch_id"], name: "index_good_jobs_on_batch_id", where: "(batch_id IS NOT NULL)"
Expand All @@ -210,7 +219,10 @@
t.index ["cron_key", "cron_at"], name: "index_good_jobs_on_cron_key_and_cron_at_cond", unique: true, where: "(cron_key IS NOT NULL)"
t.index ["finished_at"], name: "index_good_jobs_jobs_on_finished_at", where: "((retried_good_job_id IS NULL) AND (finished_at IS NOT NULL))"
t.index ["labels"], name: "index_good_jobs_on_labels", where: "(labels IS NOT NULL)", using: :gin
t.index ["locked_by_id"], name: "index_good_jobs_on_locked_by_id", where: "(locked_by_id IS NOT NULL)"
t.index ["priority", "created_at"], name: "index_good_job_jobs_for_candidate_lookup", where: "(finished_at IS NULL)"
t.index ["priority", "created_at"], name: "index_good_jobs_jobs_on_priority_created_at_when_unfinished", order: { priority: "DESC NULLS LAST" }, where: "(finished_at IS NULL)"
t.index ["priority", "scheduled_at"], name: "index_good_jobs_on_priority_scheduled_at_unfinished_unlocked", where: "((finished_at IS NULL) AND (locked_by_id IS NULL))"
t.index ["queue_name", "scheduled_at"], name: "index_good_jobs_on_queue_name_and_scheduled_at", where: "(finished_at IS NULL)"
t.index ["scheduled_at"], name: "index_good_jobs_on_scheduled_at", where: "(finished_at IS NULL)"
end
Expand Down Expand Up @@ -245,6 +257,23 @@
t.bigint "bling_order_item_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "pending", default: false
end

create_table "localizations", force: :cascade do |t|
t.string "name"
t.string "address"
t.string "number"
t.string "complement"
t.string "city"
t.string "state"
t.string "zip_code"
t.string "neighborhood"
t.string "country_name"
t.integer "account_id"
t.bigint "bling_order_item_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "post_data", force: :cascade do |t|
Expand All @@ -254,7 +283,7 @@
t.string "post_code"
t.string "post_type"
t.float "value"
t.datetime "send_date", precision: nil
t.datetime "send_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand All @@ -265,6 +294,8 @@
t.integer "quantity"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "pieces_delivered"
t.integer "pieces_missing"
t.index ["product_id"], name: "index_production_products_on_product_id"
t.index ["production_id"], name: "index_production_products_on_production_id"
end
Expand All @@ -277,7 +308,17 @@
t.integer "account_id"
t.bigint "tailor_id"
t.boolean "consider", default: false
t.date "delivery_date"
t.integer "pieces_delivered"
t.integer "pieces_missing"
t.date "expected_delivery_date"
t.boolean "confirmed"
t.boolean "paid"
t.text "observation"
t.index ["account_id"], name: "index_productions_on_account_id"
t.index ["cut_date"], name: "index_productions_on_cut_date"
t.index ["delivery_date"], name: "index_productions_on_delivery_date"
t.index ["expected_delivery_date"], name: "index_productions_on_expected_delivery_date"
t.index ["tailor_id"], name: "index_productions_on_tailor_id"
end

Expand Down Expand Up @@ -374,7 +415,7 @@
create_table "simplo_clients", force: :cascade do |t|
t.string "name"
t.integer "age"
t.datetime "order_date", precision: nil
t.datetime "order_date"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand All @@ -388,7 +429,7 @@
t.float "valor_total"
t.float "peso"
t.float "desconto"
t.datetime "data_pedido", precision: nil
t.datetime "data_pedido"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "order_id"
Expand Down Expand Up @@ -485,8 +526,8 @@
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at", precision: nil
t.datetime "remember_created_at", precision: nil
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "first_name"
Expand All @@ -505,6 +546,7 @@
add_foreign_key "group_products", "products"
add_foreign_key "production_products", "productions"
add_foreign_key "production_products", "products"
add_foreign_key "productions", "accounts"
add_foreign_key "productions", "tailors"
add_foreign_key "products", "categories"
add_foreign_key "purchase_products", "products"
Expand Down
Loading
Loading