From d88199150e26bfc3882154d57bcb849e0d95d821 Mon Sep 17 00:00:00 2001 From: yamin Date: Wed, 23 Aug 2017 18:14:31 +0630 Subject: [PATCH] CRUDIn_Juties --- .../origami/in_juties_controller.rb | 8 +-- app/models/commissioner.rb | 1 + app/models/dining_facility.rb | 1 + app/models/in_juty.rb | 2 + app/views/origami/commissions/_form.html.erb | 1 + app/views/origami/in_juties/_form.html.erb | 31 ++++++++-- app/views/origami/in_juties/edit.html.erb | 16 ++++-- app/views/origami/in_juties/index.html.erb | 57 ++++++++++++------- app/views/origami/in_juties/new.html.erb | 15 +++-- app/views/origami/in_juties/show.html.erb | 45 ++++++++++++++- 10 files changed, 133 insertions(+), 44 deletions(-) diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index d424186b..2f7ff21f 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -28,7 +28,7 @@ class Origami::InJutiesController < BaseOrigamiController respond_to do |format| if @in_juty.save - format.html { redirect_to @in_juty, notice: 'In juty was successfully created.' } + format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully created.' } format.json { render :show, status: :created, location: @in_juty } else format.html { render :new } @@ -42,7 +42,7 @@ class Origami::InJutiesController < BaseOrigamiController def update respond_to do |format| if @in_juty.update(in_juty_params) - format.html { redirect_to @in_juty, notice: 'In juty was successfully updated.' } + format.html { redirect_to origami_in_juty_path(@in_juty), notice: 'In juty was successfully updated.' } format.json { render :show, status: :ok, location: @in_juty } else format.html { render :edit } @@ -56,7 +56,7 @@ class Origami::InJutiesController < BaseOrigamiController def destroy @in_juty.destroy respond_to do |format| - format.html { redirect_to in_juties_url, notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' } format.json { head :no_content } end end @@ -69,6 +69,6 @@ class Origami::InJutiesController < BaseOrigamiController # Never trust parameters from the scary internet, only allow the white list through. def in_juty_params - params.fetch(:in_juty, {}) + params.require(:in_juty).permit(:dinning_id,:commissioner_ids,:in_time,:out_time) end end diff --git a/app/models/commissioner.rb b/app/models/commissioner.rb index ac199468..dd22278a 100644 --- a/app/models/commissioner.rb +++ b/app/models/commissioner.rb @@ -1,5 +1,6 @@ class Commissioner < ApplicationRecord belongs_to :employee, foreign_key: 'emp_id' belongs_to :commission, foreign_key: 'commission_type' + has_many :in_juties scope :active, -> { where(is_active: true) } end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index f441612a..ba01afb6 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -1,6 +1,7 @@ class DiningFacility < ApplicationRecord belongs_to :zone has_many :dining_charges + has_many :in_juties TABLE_TYPE = "Table" ROOM_TYPE = "Room" diff --git a/app/models/in_juty.rb b/app/models/in_juty.rb index d5ca9685..2f023ff0 100644 --- a/app/models/in_juty.rb +++ b/app/models/in_juty.rb @@ -1,2 +1,4 @@ class InJuty < ApplicationRecord + belongs_to :dining_facility, foreign_key: 'dinning_id' + belongs_to :commissioner, foreign_key: 'commissioner_ids' end diff --git a/app/views/origami/commissions/_form.html.erb b/app/views/origami/commissions/_form.html.erb index 1f7fee4a..5077f946 100644 --- a/app/views/origami/commissions/_form.html.erb +++ b/app/views/origami/commissions/_form.html.erb @@ -8,6 +8,7 @@ <%= f.input :amount %> <%= f.input :commission_type, :collection => ['Percentage','Net Amount'], prompt: 'Select Commission Type', class: 'form-control' %> +
<%= link_to 'Back', origami_commissions_path, class: 'btn btn-success' %> diff --git a/app/views/origami/in_juties/_form.html.erb b/app/views/origami/in_juties/_form.html.erb index 5259b903..d67df51b 100644 --- a/app/views/origami/in_juties/_form.html.erb +++ b/app/views/origami/in_juties/_form.html.erb @@ -1,10 +1,33 @@ -<%= simple_form_for(@in_juty) do |f| %> +
+<%= simple_form_for([:origami,@in_juty]) do |f| %> <%= f.error_notification %>
-
- + <%= f.label :dinning_id %> + <%= f.collection_select :dinning_id, DiningFacility.all, :id, :name, {prompt: 'Select Dining Facilities'}, {class: 'form-control'} %>
+ <%= f.label :commissioner_ids %> + <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
+ + <%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>
+ + <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%> +

- <%= f.button :submit %> + <%= link_to 'Back', origami_in_juties_path, class: 'btn btn-success' %> + <%= f.button :submit, class: 'btn btn-info' %>
<% end %> +
+ + \ No newline at end of file diff --git a/app/views/origami/in_juties/edit.html.erb b/app/views/origami/in_juties/edit.html.erb index 45addcc2..3a6fc774 100644 --- a/app/views/origami/in_juties/edit.html.erb +++ b/app/views/origami/in_juties/edit.html.erb @@ -1,6 +1,10 @@ -

Editing In Juty

- -<%= render 'form', in_juty: @in_juty %> - -<%= link_to 'Show', @in_juty %> | -<%= link_to 'Back', in_juties_path %> +
+ + <%= render 'form', in_juty: @in_juty %> +
\ No newline at end of file diff --git a/app/views/origami/in_juties/index.html.erb b/app/views/origami/in_juties/index.html.erb index d407bb94..6efeb999 100644 --- a/app/views/origami/in_juties/index.html.erb +++ b/app/views/origami/in_juties/index.html.erb @@ -1,25 +1,38 @@ -

<%= notice %>

- -

In Juties

- - - - - - - - - - <% @in_juties.each do |in_juty| %> - - - - - - <% end %> - -
<%= link_to 'Show', in_juty %><%= link_to 'Edit', edit_in_juty_path(in_juty) %><%= link_to 'Destroy', in_juty, method: :delete, data: { confirm: 'Are you sure?' } %>
+
+
+ + + + + + + + + + -<%= link_to 'New In Juty', new_in_juty_path %> + + <% @in_juties.each do |in_juty| %> + + + + + + + + + + <% end %> + +
Dining Facility NameCommissioner IdsIn timeOut time
<%= in_juty.dining_facility.name rescue '-' %><%= in_juty.commissioner.name rescue '-' %><%= in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %><%= link_to 'Show', origami_in_juty_path(in_juty) %><%= link_to 'Edit', edit_origami_in_juty_path(in_juty) %><%= link_to 'Destroy', origami_in_juty_path(in_juty), method: :delete, data: {confirm: 'Are you sure?'} %>
+
diff --git a/app/views/origami/in_juties/new.html.erb b/app/views/origami/in_juties/new.html.erb index cf54d27f..eb34f01c 100644 --- a/app/views/origami/in_juties/new.html.erb +++ b/app/views/origami/in_juties/new.html.erb @@ -1,5 +1,10 @@ -

New In Juty

- -<%= render 'form', in_juty: @in_juty %> - -<%= link_to 'Back', in_juties_path %> +
+ + <%= render 'form', in_juty: @in_juty %> +
diff --git a/app/views/origami/in_juties/show.html.erb b/app/views/origami/in_juties/show.html.erb index c5d6379a..34d72071 100644 --- a/app/views/origami/in_juties/show.html.erb +++ b/app/views/origami/in_juties/show.html.erb @@ -1,4 +1,43 @@ -

<%= notice %>

+ +
+
+

In Juty

+ + + + + + + + + + + + + + + + + + + + + +
Dining Facility Name<%= @in_juty.dining_facility.name%>
Commissioner Name + <%= @in_juty.commissioner.name rescue '-' %> +
In Time<%= @in_juty.in_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %>
Out Time<%= @in_juty.out_time.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") rescue '-' %>
+ <%= link_to 'Back', origami_in_juties_path, class: 'btn btn-success' %> + <%= link_to 'Edit', edit_origami_in_juty_path(@in_juty), class: 'btn btn-info' %> + <%= link_to 'Destroy', origami_in_juty_path(@in_juty), method: :delete, data: {confirm: 'Are you sure?'}, class: 'btn btn-danger' %> +
+
+ +