Skip to content

Commit

Permalink
Merge branch 'staging' into snyk-fix-76bceeb9f3e5d0278a99f655e0f8095a
Browse files Browse the repository at this point in the history
  • Loading branch information
puppe1990 authored Sep 5, 2024
2 parents f8871a9 + fc0f8a7 commit e853ac4
Show file tree
Hide file tree
Showing 54 changed files with 1,599 additions and 557 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20.9.0'
node-version: '22.2.0'
cache: 'yarn'
- run: |
npm install -g yarn@1.22.19
npm install -g yarn@1.22.22
yarn install --check-files
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.2.2
ruby-version: 3.3.4
# runs 'bundle install' and cache installed gems automatically
bundler-cache: true

Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2
3.3.4
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.2.2'
ruby '3.3.4'

# dotenv-rails must be on the top
gem 'dotenv-rails', '>= 3.0.0', groups: %i[development test]
Expand Down Expand Up @@ -142,9 +142,9 @@ 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-rspec', '>= 2.31.0', require: false
gem 'rubocop-performance', '>= 1.21.1', require: false
gem 'rubocop-rails', '>= 2.26.0', require: false
gem 'bling_api', git: 'https://github.com/Purple-Stock/bling_api'

gem "good_job", github: 'bensheldon/good_job', branch: 'main'
Expand Down
20 changes: 11 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.4.0)
parallel (1.26.3)
parser (3.3.4.2)
ast (~> 2.4.1)
racc
path_expander (1.1.2)
Expand Down Expand Up @@ -416,7 +416,7 @@ GEM
railties (>= 5.2)
reverse_markdown (2.1.1)
nokogiri
rexml (3.3.2)
rexml (3.3.6)
strscan
rodf (1.2.0)
builder (>= 3.0)
Expand Down Expand Up @@ -448,7 +448,7 @@ GEM
rspec-mocks (~> 3.13)
rspec-support (~> 3.13)
rspec-support (3.13.1)
rubocop (1.65.0)
rubocop (1.65.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
Expand All @@ -459,15 +459,15 @@ GEM
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-performance (1.21.1)
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 (3.0.3)
rubocop (~> 1.61)
Expand Down Expand Up @@ -602,6 +602,7 @@ GEM

PLATFORMS
arm64-darwin-22
arm64-darwin-23
x86_64-linux

DEPENDENCIES
Expand Down Expand Up @@ -654,9 +655,10 @@ DEPENDENCIES
rqrcode_png!
rspec-rails (>= 6.1.4)
rubocop-performance (>= 1.21.1)
rubocop-rails (>= 2.25.1)
rubocop-rspec (>= 2.31.0)
rubycritic (>= 4.8.1)
rubocop-rails (>= 2.26.0)
rubycritic
rubyzip
sassc-rails
selenium-webdriver (>= 4.22.0)
Expand All @@ -678,7 +680,7 @@ DEPENDENCIES
webmock (>= 3.20.0)

RUBY VERSION
ruby 3.2.2p53
ruby 3.3.4p94

BUNDLED WITH
2.4.10
12 changes: 12 additions & 0 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class ItemsController < ApplicationController
def update_status
@item = Item.find(params[:id])
case params[:status]
when 'resolved'
@item.resolve!
when 'unresolved'
@item.unresolve!
end
redirect_back(fallback_location: show_pending_orders_path, notice: 'Status atualizado com sucesso.')
end
end
35 changes: 22 additions & 13 deletions app/controllers/orders_control_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,41 @@ def show_orders_products_stock
.order(custom_id: :desc)
end


def show_pending_orders
situation_id = params[:situation_id]
store_id = params[:store_id]

@resolution_status = params[:resolution_status] || 'unresolved'

if situation_id.present?
cleaned_situation_ids = situation_id.split(',').map(&:to_i)
else
cleaned_situation_ids = BlingOrderItem::Status::PENDING
end

pending_items = Item.includes(:bling_order_item).where(bling_order_items: { situation_id: cleaned_situation_ids })

if store_id.present?
@pending_order_items = pending_items.where(bling_order_items: { store_id: store_id })
else
@pending_order_items = pending_items
end


items = Item.includes(:bling_order_item).where(bling_order_items: { situation_id: cleaned_situation_ids })

items = items.where(bling_order_items: { store_id: store_id }) if store_id.present?

@all_items = case @resolution_status
when 'unresolved'
items.unresolved
when 'resolved'
items.resolved
else
items
end

# Group items by store and sort by total quantity
@sorted_stores = @all_items.group_by { |item| item.bling_order_item.store_name }
.sort_by { |_, items| -items.sum(&:quantity) }
.to_h

respond_to do |format|
format.html # show.html.erb
format.csv { send_data generate_csv(@pending_order_items), filename: "pending-orders-#{Date.today}.csv" }
format.csv { send_data generate_csv(@all_items), filename: "orders-#{Date.today}.csv" }
end
end


def show_orders_business_day
@simplo_orders = SimploOrder.where(order_status: %w[2 30 31]).order(order_id: :asc)
@calendar = SimploOrder.calendar
Expand Down
84 changes: 53 additions & 31 deletions app/controllers/productions_controller.rb
Original file line number Diff line number Diff line change
@@ -1,64 +1,86 @@
# app/controllers/productions_controller.rb

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

def index
@productions = Production.all
@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
@production = Production.new
@production.production_products.build
end

def edit
@tailors = Tailor.all
end

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
render :new
@tailors = Tailor.all
flash.now[:alert] = t('.creation_failed')
logger.error("Failed to create production: #{@production.errors.full_messages}")
end
end

def edit
@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
begin
ProductionProduct.where(production_id: @production.id).destroy_all
@production.destroy
respond_to do |format|
format.html { redirect_to productions_path, notice: 'Produção deletado.' }
format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@production)) }
end
rescue ActiveRecord::InvalidForeignKey
# Handle invalid foreign key by raising a custom error message
raise "Can't delete production because it has associated records"
if @production.destroy
redirect_to productions_url, notice: t('.production_destroyed')
else
redirect_to productions_url, alert: t('.destruction_failed')
end
end

private
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

def set_production
@production = Production.find(params[:id])
if params[:tailor_id].present?
@productions_with_missing_pieces = @productions_with_missing_pieces.where(tailor_id: params[:tailor_id])
end
end

def production_params
params.require(:production).permit(:cut_date, :deliver_date, :quantity, :tailor_id, :consider, production_products_attributes: [:id, :product_id, :quantity, :_destroy])
end
private

def set_tailor_options
@tailors = Tailor.all
end
end
def set_production
@production = Production.find(params[:id])
end

def set_tailors
@tailors = Tailor.all
end

def production_params
params.require(:production).permit(
:cut_date, :tailor_id, :service_order_number, :expected_delivery_date,
:confirmed, :paid, :consider, :observation,
production_products_attributes: [:id, :product_id, :quantity, :pieces_delivered, :delivery_date,
:_destroy]
)
end
end
38 changes: 36 additions & 2 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ def top_selling_products
.where(bling_order_items: { situation_id: [BlingOrderItem::Status::PAID] })
.where(account_id: current_tenant.id)
.group('items.sku')
.select('items.sku, SUM(items.quantity) AS total_quantity')
.order('total_quantity DESC')
.select('items.sku, SUM(items.value) AS total_value, COUNT(*) AS total_quantity')
.order('total_value DESC')

@total_value = @items.sum(&:total_value)

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

private
Expand All @@ -48,4 +55,31 @@ def date_range
end
@date_range = initial_date..final_date
end

def generate_csv
CSV.generate(headers: true) do |csv|
csv << ['SKU', 'Total Quantity', 'Total Value', 'Proportional Percentage', 'Cumulative Percentage', 'ABC Classification']

cumulative_value = 0
@items.each do |item|
proportional_percentage = (item.total_value.to_f / @total_value * 100).round(2)
cumulative_value += item.total_value
cumulative_percentage = (cumulative_value.to_f / @total_value * 100).round(2)
classification = case cumulative_percentage
when 0..80 then 'Curva A'
when 80..95 then 'Curva B'
else 'Curva C'
end

csv << [
item.sku,
item.total_quantity,
item.total_value,
proportional_percentage,
cumulative_percentage,
classification
]
end
end
end
end
Loading

0 comments on commit e853ac4

Please sign in to comment.