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..5eaab1be 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,11 +2,122 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + @@ -20,26 +131,16 @@ - - + - - - - - - - - - - - - + + - + + @@ -48,28 +149,169 @@ - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -92,6 +334,8 @@ sale_edit#edit @saleobj edit + sale_item + commissioner @@ -100,12 +344,6 @@ @@ -211,6 +455,12 @@ + + + + + + @@ -605,24 +855,26 @@ - + - + - + + - + @@ -631,7 +883,6 @@ - @@ -646,50 +897,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -747,14 +954,6 @@ - - - - - - - - @@ -801,6 +1000,7 @@ + @@ -822,13 +1022,6 @@ - - - - - - - @@ -840,14 +1033,6 @@ - - - - - - - - @@ -873,6 +1058,7 @@ + @@ -887,13 +1073,7 @@ - - - - - - - + @@ -901,13 +1081,6 @@ - - - - - - - @@ -936,14 +1109,6 @@ - - - - - - - - @@ -976,23 +1141,39 @@ - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1002,26 +1183,188 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/in_juties_controller.rb b/app/controllers/origami/in_juties_controller.rb index f13c6fb6..821aa409 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,9 @@ class Origami::InJutiesController < BaseOrigamiController def index_in_juty @juties_in= InJuty.where("dinning_id=?",params[:table_id]) + @table = DiningFacility.find(params[:table_id]) + @in_juty = InJuty.new + end # GET /in_juties/1 # GET /in_juties/1.json @@ -22,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 @@ -49,12 +54,24 @@ class Origami::InJutiesController < BaseOrigamiController end def create_for_in_juty + @in_juty = InJuty.new + + @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 - @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 end # PATCH/PUT /in_juties/1 @@ -77,7 +94,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 +108,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/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/controllers/settings/dining_charges_controller.rb b/app/controllers/settings/dining_charges_controller.rb index 854354c2..1d34f9c9 100644 --- a/app/controllers/settings/dining_charges_controller.rb +++ b/app/controllers/settings/dining_charges_controller.rb @@ -51,6 +51,10 @@ class Settings::DiningChargesController < ApplicationController respond_to do |format| @dining_charge.dining_facility_id = @settings_dining_facility.id if @dining_charge.update(dining_charge_params) + # @dining_charge.minimum_free_time = @dining_charge.minimum_free_time.to_datetime.advance(hours: +6, minutes: +30) + # @dining_charge.charge_block = @dining_charge.charge_block.to_datetime.advance(hours: +6, minutes: +30) + # @dining_charge.time_rounding_block = @dining_charge.time_rounding_block.to_datetime.advance(hours: +6, minutes: +30) + # @dining_charge.save if @table format.html { redirect_to edit_settings_zone_table_path(@zone,@settings_dining_facility), notice: 'Dining charge was successfully updated.' } else 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/promotion.rb b/app/models/promotion.rb index 282d6798..025abd4b 100644 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -146,7 +146,7 @@ class Promotion < ApplicationRecord sale_item.sale_id = sale_id sale_item.save - sale = Sale.find(sale_id). + sale = Sale.find(sale_id) sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount) end @@ -207,6 +207,7 @@ class Promotion < ApplicationRecord return item[1] end end + return 0 end def self.calculate_discount(total, discount) diff --git a/app/models/sale.rb b/app/models/sale.rb index c8ceb696..8c89195e 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/app/views/origami/in_juties/_assign_in_juty.html.erb b/app/views/origami/in_juties/_assign_in_juty.html.erb index 14469fde..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,32 +1,30 @@ -

-<%= 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.label :dinning_id %> -
+ <%= f.hidden_field :dinning_id,:value => @table.id, :class => "form-control col-md-6 " %> + <%= @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"%>
<%= f.text_field :out_time, :value=>DateTime.now.strftime("%Y-%m-%d / %I:%M %p"),:class=>"form-control datepicker"%>

-
-
-
- <%= link_to 'Back', origami_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_form.html.erb b/app/views/origami/in_juties/_edit_form.html.erb deleted file mode 100644 index 61f6512f..00000000 --- a/app/views/origami/in_juties/_edit_form.html.erb +++ /dev/null @@ -1,59 +0,0 @@ -
-<%= simple_form_for([:origami,@in_juty]) do |f| %> - <%= 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.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 %> -

-
-
-
- <%= link_to 'Back', origami_index_in_juty_path, class: 'btn btn-success' %> -
-
- -
-
-
-<% 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 new file mode 100644 index 00000000..a2405f58 --- /dev/null +++ b/app/views/origami/in_juties/_edit_in_juty.html.erb @@ -0,0 +1,14 @@ +<%= simple_form_for([:origami,@in_juty]) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :dinning_id %> + <%= f.input :commissioner_ids %> + <%= f.input :in_time %> + <%= f.input :out_time %> +
+ +
+ <%= f.button :submit %> +
+<% 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 09dd646a..7176dea6 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,64 @@
- <%= 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/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..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,37 +1,79 @@ -