Skip to content

Commit

Permalink
Add Outerpacking to change status to packed
Browse files Browse the repository at this point in the history
  • Loading branch information
logicisaliar committed Dec 3, 2018
1 parent 3389afe commit a9915e5
Show file tree
Hide file tree
Showing 19 changed files with 160 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/controllers/client/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def create
end

def index
@orders = Order.all
@orders = Order.all.sort_by &:order_num
@orders.each do |o|
o = set_status(o)
end
Expand Down
29 changes: 29 additions & 0 deletions app/controllers/client/outerpackings_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
class Client::OuterpackingsController < ApplicationController
skip_before_action :authenticate_user!

def new
@outerpacking = Outerpacking.new
end

def create
@outerpacking = Outerpacking.new(outerpacking_params)
@outerpacking.order = Order.find(params[:order_id])
if @outerpacking.save!
redirect_to client_order_path(@outerpacking.order.id)
else
render :new
end
end

def index
@outeperackings = Outerpacking.all
end


private

def outerpacking_params
params.require(:outerpacking).permit(:outer_id, :quantity)
end

end
33 changes: 30 additions & 3 deletions app/controllers/outerpackings_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
class OuterpackingsController < ApplicationController
def index
end

def new
before_action :set_outerpacking, only: [:show, :edit, :update, :destroy]
skip_before_action :authenticate_user!

def show
end

def edit
end

def update
if @outerpacking.update(outerpacking_params)
redirect_to client_order_path(@outerpacking.order.id)
else
render :edit
end
end

def destroy
o = Order.find(params[:order])
@outerpacking.destroy
redirect_to client_order_path(o)
end


private

def set_outerpacking
@outerpacking = Outerpacking.find(params[:id])
end

def outerpacking_params
params.require(:outerpacking).permit(:outer_id, :quantity)
end

end
2 changes: 0 additions & 2 deletions app/controllers/products_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'csv'

class ProductsController < ApplicationController
skip_before_action :authenticate_user!
before_action :set_product, only: [:show, :edit, :update, :destroy]
Expand Down
2 changes: 0 additions & 2 deletions app/models/company.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
class Company < ApplicationRecord
has_many :lines
has_many :orders, through: :lines
belongs_to :parent, class_name: "Company", optional: true
has_one :child, class_name: "Company", foreign_key: :parent_id
has_many :addresses
Expand Down
1 change: 1 addition & 0 deletions app/models/order.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
class Order < ApplicationRecord
belongs_to :company
has_many :items
has_many :outerpackings
has_one :brokerage
belongs_to :transport
belongs_to :user, optional: true
Expand Down
1 change: 1 addition & 0 deletions app/models/outer.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
class Outer < ApplicationRecord
has_many :outerpackings
end
2 changes: 1 addition & 1 deletion app/views/client/items/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% order_id = params[:format] %>
<% end %>
<h1>Please add new Item</h1>
<%= simple_form_for item, url: lines_path do |f| %>
<%= simple_form_for item do |f| %>
<%= f.error_notification %>
<%= f.input :product_id, collection: @products, label_method: :second, value_method: :first %>
<%= f.input :packing_id, collection: @packings, label_method: :second, value_method: :first %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/client/orders/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<% if @order.company.addresses.length > 1 %>
<%= render "address", order: @order %>
<% elsif @order.lines.length == 0 %>
<% elsif @order.items.length == 0 %>
<%= render "client/items/form", item: Item.new %>
<% else %>
YOOOOOOOO
Expand Down
17 changes: 10 additions & 7 deletions app/views/client/orders/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<% raise %>
<div class="yellow">
<br>
<br>
Expand All @@ -8,29 +9,31 @@
<%= render '/shared/company_card', company: @order.company, class: "top-margin" %>
</div>
<!-- Change Order Status -->
<% if @order.status == "completed" || @order.status == "confirmed" %>
<div class="row horizontal col-xs-4 col-xs-offset-4 top-margin btn-status">
<% if @order.status == "completed" %>
<div class="col-xs-10 col-xs-offset-1 col-md-4 col-md-offset-4 form-default">
<%= link_to "Status Up", client_order_path(@order, status_up: @order.status), class: "btn btn-success" %>
<% end %>
<% if @order.released_date.nil? %>
<% rd = 0 %>
<% else %>
<% rd = @order.released_date %>
<% end %>
<% unless @order.status == "pending" || Date.today > rd + 3 %>
<% unless @order.status == "pending" && Date.today > rd + 3 %>
<%= link_to "Status Down", client_order_path(@order, status_down: @order.status), class: "btn btn-danger" %>
<% end %>
</div>
<!-- Order Details for Status Up -->
<div class="container">
<% if @order.status == "pending" %>
<%= render "/shared/pending", lines: @lines, order: @order %>
<%= render "/shared/pending", order: @order %>
<% elsif @order.status == "confirmed" %>
<%= render "/shared/confirmed", order: @order %>
<% elsif @order.status == "packed" %>
<%= render "/shared/packed", lines: @lines, order: @order %>
<%= render "/shared/packed", order: @order %>
<% elsif @order.status == "invoiced" %>
<%= render "/shared/invoiced", lines: @lines, order: @order %>
<%= render "/shared/invoiced", order: @order %>
<% elsif @order.status == "dispatched" %>
<%= render "/shared/dispatched", lines: @lines, order: @order %>
<%= render "/shared/dispatched", order: @order %>
<% end %>
</div>
<!-- List of Items in the Order -->
Expand Down
3 changes: 3 additions & 0 deletions app/views/client/outerpackings/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% @outerpackings.each do |o| %>
<%= o.quantity %>
<% end %>
8 changes: 8 additions & 0 deletions app/views/client/outerpackings/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<%= simple_form_for @outerpacking, client_order_outerpackings_path do |f| %>
<%= f.error_notification %>
<%= f.input :outer_id, collection: Outer.all %>
<%= f.input :quantity %>
<%= f.button :submit %>
<% end %>

<%= link_to "Go back", root_path %>
10 changes: 8 additions & 2 deletions app/views/outerpackings/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
<h1>Outerpackings#edit</h1>
<p>Find me in app/views/outerpackings/edit.html.erb</p>
<div class="col-xs-10 col-xs-offset-1 col-md-4 col-md-offset-4 form-default">
<%= simple_form_for @outerpacking do |f| %>
<%= f.error_notification %>
<%= f.input :outer_id, collection: Outer.all %>
<%= f.input :quantity %>
<%= f.button :submit, class: "btn-submit" %>
<% end %>
</div>
2 changes: 0 additions & 2 deletions app/views/outerpackings/index.html.erb

This file was deleted.

2 changes: 0 additions & 2 deletions app/views/outerpackings/new.html.erb

This file was deleted.

27 changes: 27 additions & 0 deletions app/views/shared/_confirmed.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div class="col-xs-10 col-xs-offset-1 col-md-4 col-md-offset-4 form-default">
<% unless order.outerpackings.length == 0 %>
<%= link_to "Packing Done", client_order_path(@order, status_up: @order.status), class: "btn btn-success" %>
<% end %>
</div>
<div class="col-xs-10 col-xs-offset-1 col-md-4 col-md-offset-4 form-default">
<% Outerpacking.all.each do |o| %>
<h6>
<%= o.outer.name %> - <%= o.quantity %>
<%= link_to '<i class="fas fa-edit"></i>'.html_safe, edit_outerpacking_path(o), order: o.order.id %> ||| <%= link_to '<i class="fas fa-trash-alt"></i>'.html_safe, outerpacking_path(o, order: o.order.id), data: { confirm: "Are you sure?" }, method: :delete %>
</h6>
<% end %>
</div>
<div class="col-xs-10 col-xs-offset-1 col-md-4 col-md-offset-4 form-default">
<%= simple_form_for Outerpacking.new, url: client_order_outerpackings_path(order) do |f| %>
<%= f.error_notification %>
<%= f.input :outer_id, collection: Outer.all %>
<%= f.input :quantity %>
<div class="hidden">
<%= f.input_field "Pass Params", name: "status", value: order.status %>
</div>
<%= f.button :submit, class: "btn-submit" %>
<% end %>
</div>



15 changes: 6 additions & 9 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
Rails.application.routes.draw do
get 'outerpackings/index'
get 'outerpackings/new'
get 'outerpackings/edit'
get 'brokerages/edit'
get 'brokerages/index'
get 'brokerages/show'
get 'brokerage/edit'
get 'brokerage/index'
get 'brokerage/show'
namespace :client do
get 'outerpackings/new'
get 'outerpackings/index'
end
devise_for :users
root to: 'pages#home'
get 'development', to: 'pages#development'
namespace :client do
resources :orders do
resources :items, only: [:index, :new, :create]
resources :outerpackings, only: [:index, :new, :create]
end
end
get '/client/order/get_address', to: 'client/orders#get_address'
resources :items, only: [:show, :edit, :update, :destroy]
resources :outerpackings, only: [:show, :edit, :update, :destroy]
resources :types, only: [:index]
resources :states, only: [:index]
resources :packings, only: [:index]
Expand Down
21 changes: 20 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2018_11_23_094153) do
ActiveRecord::Schema.define(version: 2018_12_01_121741) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -160,6 +160,23 @@
t.index ["user_id"], name: "index_orders_on_user_id"
end

create_table "outerpackings", force: :cascade do |t|
t.bigint "order_id"
t.bigint "outer_id"
t.integer "quantity"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["order_id"], name: "index_outerpackings_on_order_id"
t.index ["outer_id"], name: "index_outerpackings_on_outer_id"
end

create_table "outers", force: :cascade do |t|
t.string "name"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "packings", force: :cascade do |t|
t.float "rebate"
t.float "pack_size"
Expand Down Expand Up @@ -265,6 +282,8 @@
add_foreign_key "orders", "companies"
add_foreign_key "orders", "transports"
add_foreign_key "orders", "users"
add_foreign_key "outerpackings", "orders"
add_foreign_key "outerpackings", "outers"
add_foreign_key "pincodes", "cities"
add_foreign_key "products", "harmonics"
add_foreign_key "products", "types"
Expand Down
14 changes: 14 additions & 0 deletions test/controllers/client/outerpackings_controller_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
require 'test_helper'

class Client::OuterpackingsControllerTest < ActionDispatch::IntegrationTest
test "should get new" do
get client_outerpackings_new_url
assert_response :success
end

test "should get index" do
get client_outerpackings_index_url
assert_response :success
end

end

0 comments on commit a9915e5

Please sign in to comment.