Skip to content

Commit

Permalink
Merge pull request #293 from Purple-Stock/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
puppe1990 authored Sep 2, 2024
2 parents 869205e + e9b2ad2 commit 9495277
Show file tree
Hide file tree
Showing 19 changed files with 589 additions and 330 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ gem 'rack-cors', require: 'rack/cors'
gem 'rails-i18n', '~> 7.0.9'
gem 'rqrcode_png', git: "https://github.com/DCarper/rqrcode_png.git"
gem 'serviceworker-rails'
gem 'rubocop-rails', '>= 2.25.1', require: false
gem 'rubocop-rails', '>= 2.26.0', require: false
gem 'rubocop-rspec', '>= 2.24.1', require: false
gem 'rubocop-performance', '>= 1.20.0', require: false
gem 'bling_api', git: 'https://github.com/Purple-Stock/bling_api'
Expand Down
18 changes: 9 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ GEM
racc (~> 1.4)
orm_adapter (0.5.0)
pagy (6.0.4)
parallel (1.25.1)
parser (3.3.3.0)
parallel (1.26.3)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
path_expander (1.1.1)
Expand Down Expand Up @@ -416,7 +416,7 @@ GEM
railties (>= 5.2)
reverse_markdown (2.1.1)
nokogiri
rexml (3.3.1)
rexml (3.3.6)
strscan
rodf (1.2.0)
builder (>= 3.0)
Expand Down Expand Up @@ -448,18 +448,18 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.64.1)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
regexp_parser (>= 2.4, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.1)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop (~> 1.41)
Expand All @@ -468,10 +468,10 @@ GEM
rubocop-performance (1.21.0)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rails (2.25.1)
rubocop-rails (2.26.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.30.0)
rubocop (~> 1.40)
Expand Down Expand Up @@ -661,7 +661,7 @@ DEPENDENCIES
rqrcode_png!
rspec-rails (>= 6.1.4)
rubocop-performance (>= 1.20.0)
rubocop-rails (>= 2.25.1)
rubocop-rails (>= 2.26.0)
rubocop-rspec (>= 2.24.1)
rubycritic
rubyzip
Expand Down
37 changes: 26 additions & 11 deletions app/controllers/productions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# app/controllers/productions_controller.rb

class ProductionsController < ApplicationController
before_action :set_production, only: [:show, :edit, :update, :destroy]
before_action :set_production, only: [:show, :edit, :update, :destroy, :verify]
before_action :set_tailors, only: [:new, :edit, :create, :update]

def index
@productions = Production.includes(:tailor, production_products: :product).all
end

def show
def show; end

def verify
@production = @account.productions.find(params[:id])
end

def new
Expand All @@ -19,29 +23,35 @@ def new
def create
@production = Production.new(production_params)
if @production.save
redirect_to @production, notice: 'Production was successfully created.'
redirect_to @production, notice: t('.production_created')
else
@tailors = Tailor.all
render :new
flash.now[:alert] = t('.creation_failed')
logger.error("Failed to create production: #{@production.errors.full_messages}")
end
end

def edit
@tailors = Tailor.all
@production = Production.find(params[:id])
@tailors = Tailor.all # Ensure @tailors is set for the edit view
end

def update
if @production.update(production_params)
redirect_to @production, notice: 'Production was successfully updated.'
@production = Production.find(params[:id])
if @production.update!(production_params)
redirect_to @production, notice: t('.production_updated')
else
@tailors = Tailor.all
render :edit
end
end

def destroy
@production.destroy
redirect_to productions_url, notice: 'Production was successfully destroyed.'
if @production.destroy
redirect_to productions_url, notice: t('.production_destroyed')
else
redirect_to productions_url, alert: t('.destruction_failed')
end
end

private
Expand All @@ -50,10 +60,15 @@ def set_production
@production = Production.find(params[:id])
end

def set_tailors
@tailors = Tailor.all
end

def production_params
params.require(:production).permit(
:tailor_id, :cut_date, :delivery_date, :consider,
production_products_attributes: [:id, :product_id, :quantity, :_destroy]
:tailor_id, :cut_date, :expected_delivery_date,
:confirmed, :paid, :consider, :observation,
production_products_attributes: [:id, :product_id, :quantity, :pieces_delivered, :pieces_missing, :_destroy]
)
end
end
48 changes: 35 additions & 13 deletions app/models/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,53 @@
#
# Table name: productions
#
# id :bigint not null, primary key
# consider :boolean default(FALSE)
# cut_date :datetime
# deliver_date :datetime
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer
# tailor_id :bigint
# id :bigint not null, primary key
# confirmed :boolean
# consider :boolean default(FALSE)
# cut_date :datetime
# deliver_date :datetime
# expected_delivery_date :date
# observation :text
# paid :boolean
# pieces_delivered :integer
# pieces_missing :integer
# created_at :datetime not null
# updated_at :datetime not null
# account_id :integer
# tailor_id :bigint
#
# Indexes
#
# index_productions_on_account_id (account_id)
# index_productions_on_tailor_id (tailor_id)
# index_productions_on_account_id (account_id)
# index_productions_on_cut_date (cut_date)
# index_productions_on_expected_delivery_date (expected_delivery_date)
# index_productions_on_tailor_id (tailor_id)
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (tailor_id => tailors.id)
#
class Production < ApplicationRecord
acts_as_tenant :account
has_many :production_products
acts_as_tenant(:account)

belongs_to :tailor
has_many :production_products, dependent: :destroy
has_many :products, through: :production_products

accepts_nested_attributes_for :production_products, allow_destroy: true

belongs_to :tailor, optional: true
validates :cut_date, presence: true
validates :tailor, presence: true
validates :account, presence: true

# Add a method to calculate total pieces delivered
def total_pieces_delivered
production_products.sum(:pieces_delivered)
end

# Add a method to calculate total pieces missing
def total_pieces_missing
production_products.sum { |pp| pp.quantity - (pp.pieces_delivered || 0) }
end
end
24 changes: 18 additions & 6 deletions app/models/production_product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
#
# Table name: production_products
#
# id :bigint not null, primary key
# 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 All @@ -24,4 +26,14 @@ class ProductionProduct < ApplicationRecord
belongs_to :production

validates :quantity, presence: true, numericality: { greater_than_or_equal_to: 0 }
validates :pieces_delivered, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true
validates :pieces_missing, numericality: { greater_than_or_equal_to: 0 }, allow_nil: true

before_save :set_default_pieces_delivered

private

def set_default_pieces_delivered
self.pieces_delivered ||= 0
end
end
24 changes: 19 additions & 5 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>

Expand All @@ -29,11 +29,11 @@

<body>
<div id="app">
<div class="main-wrapper main-wrapper-1">
<div class="main-wrapper">
<div class="navbar-bg"></div>
<%= render 'shared/navbar' %>
<%= render 'shared/sidebar' %>
<div class="main-content mt-5">
<div class="main-content">
<section class="section">
<%= content_for?(:content) ? yield(:content) : yield %>
</section>
Expand All @@ -44,8 +44,22 @@

<%= render 'shared/toastr' %>

<!-- scripts -->
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>-->
<%= yield(:javascript) if content_for?(:javascript) %>

<%= yield :page_scripts %>

<script>
document.addEventListener('DOMContentLoaded', function() {
const sidebarToggle = document.querySelector('[data-toggle="sidebar"]');
const body = document.body;

if (sidebarToggle) {
sidebarToggle.addEventListener('click', function(e) {
e.preventDefault();
body.classList.toggle('sidebar-mini');
});
}
});
</script>
</body>
</html>
9 changes: 7 additions & 2 deletions app/views/orders_control/show_pending_orders.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<% end %>

<div class="row justify-content-center">
<% if @pending_order_items.present? %>
<% @pending_order_items.group_by { |item| item.bling_order_item.store_name }.each do |loja_name, items| %>
<% if @all_items.present? %>
<% @all_items.group_by { |item| item.bling_order_item.store_name }.each do |loja_name, items| %>
<div class="col-md-12">
<div class="card mb-4">
<div class="card-body">
Expand All @@ -37,6 +37,11 @@
<div class="card card-body">
Pedido: <%= item.bling_order_item.bling_order_id %>, Quantidade: <%= item.quantity %> unidades<br>
<a href='https://www.bling.com.br/vendas.php#edit/<%= item.bling_order_item.bling_order_id %>'>Ver Pedido no Bling</a>
<p>Status: <%= item.pending? ? 'Pendente' : 'Não Pendente' %></p>
<% if item.bling_order_item.situation_id == BlingOrderItem::Status::PENDING %>
<%= link_to 'Marcar como Pendente', update_status_item_path(item, status: 'pendente'), method: :patch, class: 'btn btn-success' %>
<%= link_to 'Marcar como Não Pendente', update_status_item_path(item, status: 'nao_pendente'), method: :patch, class: 'btn btn-danger' %>
<% end %>
</div>
</div>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/productions/_production_product_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div class="nested-fields">
<div class="row">
<div class="col-md-6">
<div class="col-md-5">
<%= f.label :product_id, ProductionProduct.human_attribute_name(:product), class: 'form-label' %>
<%= f.collection_select :product_id, Product.all, :id, :name, { include_blank: true }, { class: 'form-control', required: true } %>
<%= f.collection_select :product_id, Product.all, :id, :sku, { include_blank: true }, { class: 'form-control select2', required: true } %>
</div>
<div class="col-md-4">
<div class="col-md-5">
<%= f.label :quantity, ProductionProduct.human_attribute_name(:quantity), class: 'form-label' %>
<%= f.number_field :quantity, class: 'form-control', min: 1, required: true %>
</div>
Expand Down
Loading

0 comments on commit 9495277

Please sign in to comment.