From 29a5062b85802f3b7895f8b77f73140a955d08e3 Mon Sep 17 00:00:00 2001 From: yamin Date: Fri, 25 Aug 2017 13:06:25 +0630 Subject: [PATCH 1/4] InJutiesUpdate --- app/controllers/origami/in_juties_controller.rb | 12 ++++++++---- .../origami/in_juties/_assign_in_juty.html.erb | 12 ++++++------ ..._edit_form.html.erb => _edit_in_juty.html.erb} | 14 +++++++------- .../origami/in_juties/assign_in_juty.html.erb | 3 +++ app/views/origami/in_juties/edit_in_juty.html.erb | 8 ++------ .../origami/in_juties/index_in_juty.html.erb | 15 +++++++++++++-- config/routes.rb | 6 +++--- 7 files changed, 42 insertions(+), 28 deletions(-) rename app/views/origami/in_juties/{_edit_form.html.erb => _edit_in_juty.html.erb} (82%) diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index f13c6fb6..4106b77a 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -1,5 +1,5 @@ class Origami::InJutiesController < BaseOrigamiController - before_action :set_in_juty, only: [:show, :edit, :update,:edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty] + before_action :set_in_juty, only: [:show, :edit, :update, :edit_in_juty, :update_for_in_juty , :destroy ,:destroy_in_juty] # GET /in_juties # GET /in_juties.json @@ -9,6 +9,8 @@ class Origami::InJutiesController < BaseOrigamiController def index_in_juty @juties_in= InJuty.where("dinning_id=?",params[:table_id]) + @table = params[:table_id] + end # GET /in_juties/1 # GET /in_juties/1.json @@ -49,7 +51,7 @@ class Origami::InJutiesController < BaseOrigamiController end def create_for_in_juty - + @in_juty = InJuty.new @in_juty.dinning_id = params[:dining_id] @in_juty.commissioner_ids = params[:commissioner_ids] @in_juty.in_time = params[:in_time] @@ -77,7 +79,7 @@ class Origami::InJutiesController < BaseOrigamiController @in_juty.commissioner_ids = params[:commissioner_ids] @in_juty.in_time = params[:in_time] @in_juty.out_time = params[:out_time] - @in_juty.update + @in_juty.save end # DELETE /in_juties/1 @@ -91,9 +93,11 @@ class Origami::InJutiesController < BaseOrigamiController end def destroy_in_juty + @table_id = params[:table_id] @in_juty.destroy + respond_to do |format| - format.html { redirect_to origami_in_juties_path, notice: 'In juty was successfully destroyed.' } + format.html { redirect_to origami_index_in_juty_path(@table_id), notice: 'In juty was successfully destroyed.' } format.json { head :no_content } end end diff --git a/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index 14469fde..8463c191 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -3,13 +3,13 @@ <%= f.error_notification %>
- <%= f.label :dinning_id %> -
+ <%= @table.name %>
+
- <%= f.label :commissioner_ids %> - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} %>
+ + <%= 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"%>
@@ -18,7 +18,7 @@
- <%= link_to 'Back', origami_path(@table.id), class: 'btn btn-success' %> + <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %>
@@ -50,7 +50,7 @@ $(function() { url: ajax_url, data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time, success: function (result) { - window.location.href = '/origami/table/' + dining_id; + window.location.href = '/origami/assign_in_juty/'+ dining_id; } }); }) diff --git a/app/views/origami/in_juties/_edit_form.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb similarity index 82% rename from app/views/origami/in_juties/_edit_form.html.erb rename to app/views/origami/in_juties/_edit_in_juty.html.erb index 61f6512f..86622c66 100644 --- a/app/views/origami/in_juties/_edit_form.html.erb +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -3,13 +3,13 @@ <%= f.error_notification %>
- <%= f.label :dinning_id %> -
+ <%= @table.name %>
+
- <%= f.label :commissioner_ids %> - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {prompt: 'Select Commissioner'}, {class: 'form-control'} ,:value => @in_juty.commissioner.name %>
+ + <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {class: 'form-control'} ,:value => @in_juty.commissioner.name %>

<%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker" ,:value => @in_juty.in_time %>
@@ -18,7 +18,7 @@
- <%= link_to 'Back', origami_index_in_juty_path, class: 'btn btn-success' %> + <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %>
@@ -49,9 +49,9 @@ $(function() { $.ajax({ type: "PUT", url: ajax_url, - data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time, + data: 'dining_id=' + dining_id + "&commissioner_ids=" + commissioner_ids +'&in_time=' + in_time + "&out_time=" + out_time + "&table_id=" + dining_id, success: function (result) { - window.location.href = '/origami/assign_in_juty'; + window.location.href = '/origami/assign_in_juty/'+ dining_id; } }); }) diff --git a/app/views/origami/in_juties/assign_in_juty.html.erb b/app/views/origami/in_juties/assign_in_juty.html.erb index 09dd646a..93dd4745 100644 --- a/app/views/origami/in_juties/assign_in_juty.html.erb +++ b/app/views/origami/in_juties/assign_in_juty.html.erb @@ -1,3 +1,6 @@
+ <%= render 'assign_in_juty', in_juty: @in_juty %>
\ No newline at end of file diff --git a/app/views/origami/in_juties/edit_in_juty.html.erb b/app/views/origami/in_juties/edit_in_juty.html.erb index 3a6fc774..473071d0 100644 --- a/app/views/origami/in_juties/edit_in_juty.html.erb +++ b/app/views/origami/in_juties/edit_in_juty.html.erb @@ -1,10 +1,6 @@
- <%= render 'form', in_juty: @in_juty %> + <%= render 'edit_in_juty', in_juty: @in_juty %>
\ No newline at end of file diff --git a/app/views/origami/in_juties/index_in_juty.html.erb b/app/views/origami/in_juties/index_in_juty.html.erb index 29e4ebab..fc5128bb 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -28,10 +28,21 @@ <%= 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 'Edit', origami_edit_in_juty_path(in_juty) %> - <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty), method: :delete, data: {confirm: 'Are you sure?'} %> + <%= link_to 'Back', origami_path(in_juty.dining_facility.id) %> + <%= link_to 'Edit', origami_edit_in_juty_path(in_juty.dining_facility.id,in_juty) %> + <%= link_to 'Destroy', origami_destroy_in_juty_path(in_juty.dining_facility.id,in_juty),method: :delete, data: {confirm: 'Are you sure?'} %> <% end %>
+ + \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 3e8caa28..3552d8f3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -94,9 +94,9 @@ Rails.application.routes.draw do get '/table/:table_id/assign_in_juty' => 'in_juties#assign_in_juty', as: 'assign_in_juty' post 'assign_in_juty' => 'in_juties#create_for_in_juty', as: 'create_for_in_juty' get 'assign_in_juty/:table_id' => 'in_juties#index_in_juty', as: 'index_in_juty' - get '/in_juty/:in_juty_id/edit' => 'in_juties#edit_in_juty' ,as: 'edit_in_juty' - put '/edit_in_juty/:in_juty_id' => 'in_juties#update_for_in_juty', as: 'update_for_in_juty' - delete '/destroy_in_juty/:in_juty_id' => 'in_juties#destroy_in_juty', as: 'destroy_in_juty' + get 'table/:table_id/in_juty/:id/edit' => 'in_juties#edit_in_juty' ,as: 'edit_in_juty' + put '/edit_in_juty/:id' => 'in_juties#update_for_in_juty', as: 'update_for_in_juty' + delete 'table/:table_id/destroy_in_juty/:id' => 'in_juties#destroy_in_juty', as: 'destroy_in_juty' From b4eb27b8a932735b74b7d4f828173c66a0933f47 Mon Sep 17 00:00:00 2001 From: Zin Lin Phyo Date: Fri, 25 Aug 2017 13:44:22 +0630 Subject: [PATCH 2/4] commission in sale edit --- .idea/sxrestaurant.iml | 101 +---- .idea/workspace.xml | 387 +++++++++++------- .../origami/commissions_controller.rb | 15 +- .../origami/product_commissions_controller.rb | 79 +++- app/models/commission.rb | 1 + app/models/commissioner.rb | 1 + app/models/menu_item.rb | 1 + app/models/product_commission.rb | 9 + app/models/sale.rb | 1 + app/models/sale_item.rb | 3 +- .../commissions/_commissioners.html.erb | 16 - .../commissions/load_commissioners.html.erb | 193 ++++----- app/views/origami/home/index_bk.html.erb | 2 +- config/routes.rb | 2 + ...170822034139_create_product_commissions.rb | 12 - ...170823034141_create_product_commissions.rb | 16 + 16 files changed, 417 insertions(+), 422 deletions(-) delete mode 100644 app/views/origami/commissions/_commissioners.html.erb delete mode 100644 db/migrate/20170822034139_create_product_commissions.rb create mode 100644 db/migrate/20170823034141_create_product_commissions.rb diff --git a/.idea/sxrestaurant.iml b/.idea/sxrestaurant.iml index e1c0cfaa..2a0f8404 100644 --- a/.idea/sxrestaurant.iml +++ b/.idea/sxrestaurant.iml @@ -11,106 +11,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -164,6 +64,7 @@ + diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 2cb0533a..0b106937 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,22 @@ - + + + + + + + + + + + - + + @@ -20,26 +31,16 @@ - - + - - - - - - - - - - - - + + - + + @@ -48,28 +49,88 @@ - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -92,6 +153,8 @@ sale_edit#edit @saleobj edit + sale_item + commissioner @@ -100,12 +163,6 @@ @@ -211,6 +274,12 @@ + + + + + + @@ -605,24 +674,26 @@ - + - + - + + - + @@ -631,7 +702,6 @@ - @@ -646,50 +716,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -747,14 +773,6 @@ - - - - - - - - @@ -801,6 +819,7 @@ + @@ -822,13 +841,6 @@ - - - - - - - @@ -840,14 +852,6 @@ - - - - - - - - @@ -873,6 +877,7 @@ + @@ -887,13 +892,7 @@ - - - - - - - + @@ -901,13 +900,6 @@ - - - - - - - @@ -936,14 +928,6 @@ - - - - - - - - @@ -976,23 +960,39 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1002,26 +1002,107 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + diff --git a/app/controllers/origami/commissions_controller.rb b/app/controllers/origami/commissions_controller.rb index f5a91ad9..db49a188 100644 --- a/app/controllers/origami/commissions_controller.rb +++ b/app/controllers/origami/commissions_controller.rb @@ -74,13 +74,18 @@ class Origami::CommissionsController < BaseOrigamiController def select_sale_item # byebug sale_item_id = params[:sale_item_id] - @sale_item = SaleItem.find_by_sale_item_id(sale_item_id) + @selected_sale_item = SaleItem.find_by_sale_item_id(sale_item_id) + @product_commission = ProductCommission.find_by_sale_item_id(@selected_sale_item.id) + unless @product_commission.nil? + selected_commissioner = @product_commission.commissioner + end @commissioners = Commissioner.active.all - respond_to do |format| - format.json {render json: @commissioners} - # format.html {render @commissioners} - end + # respond_to do |format| + # format.json {render json: {[@commissioners],[@selected_sale_item]}} + # # format.html {render @commissioners} + # end + render json: {commissioner: @commissioners, selected_commissioner: selected_commissioner} end private diff --git a/app/controllers/origami/product_commissions_controller.rb b/app/controllers/origami/product_commissions_controller.rb index f3f05ab9..e2cba46c 100644 --- a/app/controllers/origami/product_commissions_controller.rb +++ b/app/controllers/origami/product_commissions_controller.rb @@ -28,11 +28,11 @@ class Origami::ProductCommissionsController < ApplicationController respond_to do |format| if @product_commission.save - format.html { redirect_to @product_commission, notice: 'Product commission was successfully created.' } - format.json { render :show, status: :created, location: @product_commission } + format.html {redirect_to @product_commission, notice: 'Product commission was successfully created.'} + format.json {render :show, status: :created, location: @product_commission} else - format.html { render :new } - format.json { render json: @product_commission.errors, status: :unprocessable_entity } + format.html {render :new} + format.json {render json: @product_commission.errors, status: :unprocessable_entity} end end end @@ -42,11 +42,11 @@ class Origami::ProductCommissionsController < ApplicationController def update respond_to do |format| if @product_commission.update(product_commission_params) - format.html { redirect_to @product_commission, notice: 'Product commission was successfully updated.' } - format.json { render :show, status: :ok, location: @product_commission } + format.html {redirect_to @product_commission, notice: 'Product commission was successfully updated.'} + format.json {render :show, status: :ok, location: @product_commission} else - format.html { render :edit } - format.json { render json: @product_commission.errors, status: :unprocessable_entity } + format.html {render :edit} + format.json {render json: @product_commission.errors, status: :unprocessable_entity} end end end @@ -56,19 +56,62 @@ class Origami::ProductCommissionsController < ApplicationController def destroy @product_commission.destroy respond_to do |format| - format.html { redirect_to product_commissions_url, notice: 'Product commission was successfully destroyed.' } - format.json { head :no_content } + format.html {redirect_to product_commissions_url, notice: 'Product commission was successfully destroyed.'} + format.json {head :no_content} + end + end + + def set_commissioner_to_sale_item + deselect = false + sale_item_id = params[:sale_item_id] + commissioner_id = params[:commissioner_id] + @sale_item = SaleItem.find(sale_item_id) + @menu_item = MenuItem.find_by_item_code(@sale_item.product_code) + @commission = Commission.where('product_id = ? AND is_active = ?', @menu_item.id, true).take + @commissioner = Commissioner.where('id = ? AND is_active = ?', commissioner_id, true).take + @product_commission = ProductCommission.where('sale_item_id = ?', @sale_item.id).take + # byebug + if !@product_commission.nil? + if @product_commission.commissioner_id == @commissioner.id + @product_commission.destroy + deselect = true + else + @product_commission.commissioner_id = @commissioner.id + deselect = false + end + else + @product_commission = ProductCommission.new + @product_commission.product_id = @menu_item.id + unless @commission.nil? + @product_commission.commission_id = @commission.id + if @commission.commission_type == 'Percentage' + @product_commission.price = @sale_item.unit_price * (@commission.amount / 100.0) + @product_commission.amount = @product_commission.price * @sale_item.qty + elsif @commission.commission_type == 'Net Amount' + @product_commission.price = @commission.amount + @product_commission.amount = @product_commission.price * @sale_item.qty + end + end + @product_commission.commissioner_id = @commissioner.id + @product_commission.qty = @sale_item.qty + @product_commission.sale_id = @sale_item.sale_id + @product_commission.sale_item_id = @sale_item.sale_item_id + end + if @product_commission.save + render json: {status: true, deselect: deselect} + else + render json: {status: false, deselect: deselect} end end private - # Use callbacks to share common setup or constraints between actions. - def set_product_commission - @product_commission = ProductCommission.find(params[:id]) - end + # Use callbacks to share common setup or constraints between actions. + def set_product_commission + @product_commission = ProductCommission.find(params[:id]) + end - # Never trust parameters from the scary internet, only allow the white list through. - def product_commission_params - params.fetch(:product_commission, {}) - end + # Never trust parameters from the scary internet, only allow the white list through. + def product_commission_params + params.fetch(:product_commission, {}) + end end diff --git a/app/models/commission.rb b/app/models/commission.rb index df11eb24..943bb5c1 100644 --- a/app/models/commission.rb +++ b/app/models/commission.rb @@ -1,4 +1,5 @@ class Commission < ApplicationRecord belongs_to :menu_item, foreign_key: 'product_id' has_many :commissioners + has_many :product_commissions end diff --git a/app/models/commissioner.rb b/app/models/commissioner.rb index dd22278a..8bec411d 100644 --- a/app/models/commissioner.rb +++ b/app/models/commissioner.rb @@ -2,5 +2,6 @@ class Commissioner < ApplicationRecord belongs_to :employee, foreign_key: 'emp_id' belongs_to :commission, foreign_key: 'commission_type' has_many :in_juties + has_many :product_commissions scope :active, -> { where(is_active: true) } end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index c581a7b0..e7f53dcd 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -4,6 +4,7 @@ class MenuItem < ApplicationRecord belongs_to :menu_category, :optional => true has_many :menu_item_instances has_many :commissions + has_many :product_commissions # belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true # has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id" diff --git a/app/models/product_commission.rb b/app/models/product_commission.rb index 70de81f8..59e64b79 100644 --- a/app/models/product_commission.rb +++ b/app/models/product_commission.rb @@ -1,2 +1,11 @@ class ProductCommission < ApplicationRecord + belongs_to :commission, foreign_key: 'commission_id' + belongs_to :commissioner, foreign_key: 'commissioner_id' + belongs_to :menu_item, foreign_key: 'product_id' + belongs_to :sale_item, foreign_key: 'sale_item_id' + belongs_to :sale, foreign_key: 'sale_id' + + def self.check_product_commission(sale_item_id) + + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9927251d..5544d1b8 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -13,6 +13,7 @@ class Sale < ApplicationRecord has_many :sale_payments has_many :sale_orders has_many :bookings + has_many :product_commissions scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") } diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index af2230de..b8ae456d 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -5,6 +5,7 @@ class SaleItem < ApplicationRecord before_create :generate_custom_id belongs_to :sale + has_many :product_commissions #compute items - discount, tax, price_change def compute_item @@ -80,7 +81,7 @@ class SaleItem < ApplicationRecord account_price[:amount] = account_price[:amount] + si.price price = price + si.price end - + end rebate_arr.push(account_price) end diff --git a/app/views/origami/commissions/_commissioners.html.erb b/app/views/origami/commissions/_commissioners.html.erb deleted file mode 100644 index ed9da369..00000000 --- a/app/views/origami/commissions/_commissioners.html.erb +++ /dev/null @@ -1,16 +0,0 @@ -
-
-
COMMISSIONERS
-
-
-
- <% @commissioners.each do |commissioner| %> -
-
- <%= commissioner.name %> -
-
- <% end %> -
-
-
diff --git a/app/views/origami/commissions/load_commissioners.html.erb b/app/views/origami/commissions/load_commissioners.html.erb index 748fb4ef..b0bb5e63 100644 --- a/app/views/origami/commissions/load_commissioners.html.erb +++ b/app/views/origami/commissions/load_commissioners.html.erb @@ -1,11 +1,26 @@
- <%= render 'origami/commissions/commissioners', commissioners: @commissioners %> +
+
+
COMMISSIONERS
+
+
+
+ <% @commissioners.each do |commissioner| %> +
+
+ <%= commissioner.name %> +
+
+ <% end %> +
+
+
-
+
INVOICE DETAILS
@@ -34,11 +49,10 @@ # - Items - QTY - - Price - + Items + QTY + Price + Commissioner @@ -49,22 +63,26 @@ count += 1 sub_total = sub_total + sale_item.price %> - + <% # Can't check for discount unless sale_item.price == 0 %> - + <%= count %> - + <%= sale_item.product_name %> - + <%= sale_item.qty %> - + <%= sale_item.unit_price %> + + <% product_commission = ProductCommission.find_by_sale_item_id(sale_item.id) %> + <%= product_commission.commissioner.name rescue '-' %> + <% end @@ -87,135 +105,78 @@
-
+
- +
diff --git a/app/views/origami/home/index_bk.html.erb b/app/views/origami/home/index_bk.html.erb index ce2b3a94..281478b6 100644 --- a/app/views/origami/home/index_bk.html.erb +++ b/app/views/origami/home/index_bk.html.erb @@ -243,7 +243,7 @@ -

<%= odr.table_name %>

<%= odr.table_name %>

Receipt No : diff --git a/config/routes.rb b/config/routes.rb index b5af4fe2..fecc8d77 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -89,6 +89,8 @@ Rails.application.routes.draw do # commissions get '/table/:table_id/sale/:sale_id/load_commissioners' => 'commissions#load_commissioners', as: 'load_commissioners' post 'select_sale_item' => 'commissions#select_sale_item' + # product_commission + post 'select_commissioner' => 'product_commissions#set_commissioner_to_sale_item' get 'table/:dining_id/movetable' => "movetable#move_dining" get 'table/:dining_id/moveroom' => "moveroom#move_dining" diff --git a/db/migrate/20170822034139_create_product_commissions.rb b/db/migrate/20170822034139_create_product_commissions.rb deleted file mode 100644 index 95f9442d..00000000 --- a/db/migrate/20170822034139_create_product_commissions.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateProductCommissions < ActiveRecord::Migration[5.1] - def change - create_table :product_commissions do |t| - t.string :product_code - t.integer :commission_id - t.integer :qty - t.string :sale_id - t.string :sale_item_id - t.timestamps - end - end -end diff --git a/db/migrate/20170823034141_create_product_commissions.rb b/db/migrate/20170823034141_create_product_commissions.rb new file mode 100644 index 00000000..cb0e5a3f --- /dev/null +++ b/db/migrate/20170823034141_create_product_commissions.rb @@ -0,0 +1,16 @@ +class CreateProductCommissions < ActiveRecord::Migration[5.1] + # rake db:migrate:down VERSION=20170823034141 + def change + create_table :product_commissions do |t| + t.string :product_id + t.integer :commission_id + t.integer :commissioner_id + t.decimal :qty, :precision => 10, :scale => 2, :default => 0.00 + t.string :sale_id + t.string :sale_item_id + t.decimal :price, :precision => 10, :scale => 2, :default => 0.00 + t.decimal :amount, :precision => 10, :scale => 2, :default => 0.00 + t.timestamps + end + end +end From 57d668d1221139aced16d89eeb752bb5f0d6f95b Mon Sep 17 00:00:00 2001 From: yamin Date: Fri, 25 Aug 2017 18:48:34 +0630 Subject: [PATCH 3/4] InJutyIndexform --- .../origami/in_juties_controller.rb | 27 ++++- .../in_juties/_assign_in_juty.html.erb | 38 ++---- .../origami/in_juties/_edit_in_juty.html.erb | 61 ++-------- .../origami/in_juties/assign_in_juty.html.erb | 62 +++++++++- .../origami/in_juties/index_in_juty.html.erb | 113 +++++++++++------- 5 files changed, 171 insertions(+), 130 deletions(-) diff --git a/app/controllers/origami/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index 4106b77a..821aa409 100644 --- a/app/controllers/origami/in_juties_controller.rb +++ b/app/controllers/origami/in_juties_controller.rb @@ -9,7 +9,8 @@ class Origami::InJutiesController < BaseOrigamiController def index_in_juty @juties_in= InJuty.where("dinning_id=?",params[:table_id]) - @table = params[:table_id] + @table = DiningFacility.find(params[:table_id]) + @in_juty = InJuty.new end # GET /in_juties/1 @@ -24,9 +25,11 @@ class Origami::InJutiesController < BaseOrigamiController # GET /in_juties/1/edit def edit + end def edit_in_juty + @in_juty = InJuty.find(params[:id]) @table = DiningFacility.find(params[:table_id]) end @@ -52,11 +55,23 @@ class Origami::InJutiesController < BaseOrigamiController def create_for_in_juty @in_juty = InJuty.new - @in_juty.dinning_id = params[:dining_id] - @in_juty.commissioner_ids = params[:commissioner_ids] - @in_juty.in_time = params[:in_time] - @in_juty.out_time = params[:out_time] - @in_juty.save + + @in_juty.dinning_id = in_juty_params[:dinning_id] + @in_juty.commissioner_ids = in_juty_params[:commissioner_ids] + @in_juty.in_time = in_juty_params[:in_time] + @in_juty.out_time = in_juty_params[:out_time] + + + respond_to do |format| + if @in_juty.save + format.html { redirect_to origami_index_in_juty_path(in_juty_params[:dinning_id]), notice: 'In juty was successfully created.' } + format.json { render :show, status: :created, location: @in_juty } + else + format.html { render :new } + format.json { render json: @in_juty.errors, status: :unprocessable_entity } + end + end + end # PATCH/PUT /in_juties/1 diff --git a/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index 8463c191..f2f0ed16 100644 --- a/app/views/origami/in_juties/_assign_in_juty.html.erb +++ b/app/views/origami/in_juties/_assign_in_juty.html.erb @@ -1,8 +1,9 @@ -

-<%= simple_form_for([:origami,@in_juty]) do |f| %> +<%= simple_form_for @in_juty,:url => origami_create_for_in_juty_path, :method => :post do |f| %> + <%= f.error_notification %>
+ <%= f.hidden_field :dinning_id,:value => @table.id, :class => "form-control col-md-6 " %> <%= @table.name %>
@@ -15,18 +16,15 @@ <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>

-
-
-
- <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %> -
-
- -
-
+ +
+ <%= f.button :submit, "Create",:class => 'btn btn-primary ', :id => 'create' %> + <%= f.button :submit, "Update",:class => 'btn btn-primary ', :disabled =>'disabled', :id => 'update' %> + <%= f.button :button, "Reset",:class => 'btn btn-danger ', :id => 'reset' %>
+ <% end %> -
+ \ No newline at end of file diff --git a/app/views/origami/in_juties/_edit_in_juty.html.erb b/app/views/origami/in_juties/_edit_in_juty.html.erb index 86622c66..a2405f58 100644 --- a/app/views/origami/in_juties/_edit_in_juty.html.erb +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -1,59 +1,14 @@ -
<%= simple_form_for([:origami,@in_juty]) do |f| %> <%= f.error_notification %>
- - <%= @table.name %> -
-
- - - <%= f.collection_select :commissioner_ids, Commissioner.all, :id, :name, {class: 'form-control'} ,:value => @in_juty.commissioner.name %>

- - <%= f.text_field :in_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker" ,:value => @in_juty.in_time %>
- - <%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker" ,:value => @in_juty.out_time %> -

+ <%= f.input :dinning_id %> + <%= f.input :commissioner_ids %> + <%= f.input :in_time %> + <%= f.input :out_time %> +
+
-
-
- <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %> -
-
- -
+ <%= f.button :submit %>
-
-<% end %> -
- - \ No newline at end of file +<% end %> \ No newline at end of file diff --git a/app/views/origami/in_juties/assign_in_juty.html.erb b/app/views/origami/in_juties/assign_in_juty.html.erb index 93dd4745..7176dea6 100644 --- a/app/views/origami/in_juties/assign_in_juty.html.erb +++ b/app/views/origami/in_juties/assign_in_juty.html.erb @@ -2,5 +2,63 @@ - <%= render 'assign_in_juty', in_juty: @in_juty %> -
\ No newline at end of file +
+ <%= simple_form_for([:origami,@in_juty]) do |f| %> + <%= f.error_notification %> + +
+ + <%= @table.name %> +
+
+ + + <%= 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"%> +

+
+
+
+ <%= link_to 'Back', origami_index_in_juty_path(@table.id), class: 'btn btn-success' %> +
+
+ +
+
+
+ <% end %> +
+
+ + + \ No newline at end of file diff --git a/app/views/origami/in_juties/index_in_juty.html.erb b/app/views/origami/in_juties/index_in_juty.html.erb index fc5128bb..0141af05 100644 --- a/app/views/origami/in_juties/index_in_juty.html.erb +++ b/app/views/origami/in_juties/index_in_juty.html.erb @@ -1,48 +1,79 @@ -