From 4e29cd7cdd17ddacbcb078971246fccea9721692 Mon Sep 17 00:00:00 2001 From: yamin Date: Mon, 21 Aug 2017 18:14:36 +0630 Subject: [PATCH] CRUDcommission --- .../origami/commissions_controller.rb | 6 +-- app/views/layouts/_header.html.erb | 1 + app/views/origami/commissions/_form.html.erb | 5 ++ app/views/origami/commissions/edit.html.erb | 16 +++--- app/views/origami/commissions/index.html.erb | 49 +++++++++++++------ app/views/origami/commissions/new.html.erb | 15 ++++-- app/views/origami/commissions/show.html.erb | 40 +++++++++++++++ 7 files changed, 103 insertions(+), 29 deletions(-) diff --git a/app/controllers/origami/commissions_controller.rb b/app/controllers/origami/commissions_controller.rb index 19c6332e..f0f07d2a 100644 --- a/app/controllers/origami/commissions_controller.rb +++ b/app/controllers/origami/commissions_controller.rb @@ -28,7 +28,7 @@ class Origami::CommissionsController < BaseOrigamiController respond_to do |format| if @commission.save - format.html { redirect_to @commission, notice: 'Commission was successfully created.' } + format.html { redirect_to origami_commissions_path , notice: 'Commission was successfully created.' } format.json { render :show, status: :created, location: @commission } else format.html { render :new } @@ -42,7 +42,7 @@ class Origami::CommissionsController < BaseOrigamiController def update respond_to do |format| if @commission.update(commission_params) - format.html { redirect_to @commission, notice: 'Commission was successfully updated.' } + format.html { redirect_to origami_commission_path(@commission), notice: 'Commission was successfully updated.' } format.json { render :show, status: :ok, location: @commission } else format.html { render :edit } @@ -69,6 +69,6 @@ class Origami::CommissionsController < BaseOrigamiController # Never trust parameters from the scary internet, only allow the white list through. def commission_params - params.fetch(:commission, {}) + params.require(:commission).permit(:product_id,:amount,:commission_type, :is_active) end end diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index d4062d26..813d46b2 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -28,6 +28,7 @@
  • <%= link_to "Print Setting", print_settings_path, :tabindex =>"-1" %>

  • <%= link_to "Employees", settings_employees_path, :tabindex =>"-1" %>
  • +
  • <%= link_to "Commissions", origami_commissions_path , :tabindex =>"-1" %>
  • <%= link_to "Commissioners", origami_commissioners_path , :tabindex =>"-1" %>

  • <%= link_to "Accounts", settings_accounts_path, :tabindex =>"-1" %>
  • diff --git a/app/views/origami/commissions/_form.html.erb b/app/views/origami/commissions/_form.html.erb index 70ce85f2..826dbf78 100644 --- a/app/views/origami/commissions/_form.html.erb +++ b/app/views/origami/commissions/_form.html.erb @@ -2,9 +2,14 @@ <%= f.error_notification %>
    + <%= f.collection_select :product_id, Product.all.order('name asc'), :id, :name, {prompt: "Select a Product"}, {class: "form-control"} %> + <%= f.input :amount %> + <%= f.input :commission_type, :collection => [:percentage,:net_amount] %> +
    <%= f.button :submit %>
    <% end %> + \ No newline at end of file diff --git a/app/views/origami/commissions/edit.html.erb b/app/views/origami/commissions/edit.html.erb index 078c85c2..da73332f 100644 --- a/app/views/origami/commissions/edit.html.erb +++ b/app/views/origami/commissions/edit.html.erb @@ -1,6 +1,10 @@ -

    Editing Commission

    - -<%= render 'form', commission: @commission %> - -<%= link_to 'Show', @commission %> | -<%= link_to 'Back', commissions_path %> +
    + + <%= render 'form', commission: @commission %> +
    \ No newline at end of file diff --git a/app/views/origami/commissions/index.html.erb b/app/views/origami/commissions/index.html.erb index 1c6e5eff..420920b9 100644 --- a/app/views/origami/commissions/index.html.erb +++ b/app/views/origami/commissions/index.html.erb @@ -1,25 +1,44 @@ -

    <%= notice %>

    + -

    Commissions

    - - - +
    +
    +
    + + + + + - + - + <% @commissions.each do |commission| %> - - - + + + + + + + <% end %> -
    Product NameAmountCommission typeActive
    <%= link_to 'Show', commission %><%= link_to 'Edit', edit_origami_commission_path(commission) %><%= link_to 'Destroy', commission, method: :delete, data: { confirm: 'Are you sure?' } %> + <% if Product.exists? %> + <% product = Product.find(commission.product_id) %> + <%= product.name %> + <% end %> + + <%= commission.amount %><%= commission.commission_type %><%= commission.is_active %><%= link_to 'Show', origami_commission_path(commission) %><%= link_to 'Edit', edit_origami_commission_path(commission) %><%= link_to 'Destroy', origami_commission_path(commission), method: :delete, data: { confirm: 'Are you sure?' } %>
    - -
    - -<%= link_to 'New Commission', new_origami_commission_path %> + + diff --git a/app/views/origami/commissions/new.html.erb b/app/views/origami/commissions/new.html.erb index 522a45ea..8b6e32ca 100644 --- a/app/views/origami/commissions/new.html.erb +++ b/app/views/origami/commissions/new.html.erb @@ -1,5 +1,10 @@ -

    New Commission

    - -<%= render 'form', commission: @commission %> - -<%= link_to 'Back', origami_commissions_path %> +
    + + <%= render 'form', commission: @commission %> +
    \ No newline at end of file diff --git a/app/views/origami/commissions/show.html.erb b/app/views/origami/commissions/show.html.erb index 77ce0831..6eb399af 100644 --- a/app/views/origami/commissions/show.html.erb +++ b/app/views/origami/commissions/show.html.erb @@ -2,3 +2,43 @@ <%= link_to 'Edit', edit_commission_path(@commission) %> | <%= link_to 'Back', commissions_path %> + + + +
    +
    +

    Commission

    + + + + + + + + + + + + + + + +
    Product Name + <% if Product.exists? %> + <% product = Product.find(@commission.product_id) %> + <%= product.name %> + <% end %> + +
    Amount<%= @commission.amount %>
    Commission Type<%= @commission.commission_type %>
    Active<%= @commission.is_active %>
    <%= link_to 'Edit', edit_origami_commission_path(@commission) %><%= link_to 'Destroy', origami_commission_path(@commission), method: :delete, data: { confirm: 'Are you sure?' } %>
    +
    +
    + +