From c1709742241196a56f3a3b514c427510051f7bec Mon Sep 17 00:00:00 2001 From: phyusin Date: Mon, 27 Nov 2017 09:23:10 +0630 Subject: [PATCH] change promotion with menu item and menu item instance --- app/controllers/origami/shifts_controller.rb | 14 +++ .../settings/promotions_controller.rb | 25 +++-- app/views/settings/promotions/_form.html.erb | 99 ++++++++++++------- db/seeds.rb | 24 ++--- 4 files changed, 107 insertions(+), 55 deletions(-) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 851be7e5..41bbc846 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -48,16 +48,30 @@ class Origami::ShiftsController < BaseOrigamiController unique_code = "CloseCashierPdf" shop_details = Shop.find(1) + puts "shop details" + p shop_details #get tax shift_obj = ShiftSale.where('id =?',@shift.id) + puts "shift obj" + p shift_obj @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') + puts "sale taxes" + p @sale_taxes #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) + puts "other payment" + p @other_payment # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') + puts "total amount by account" + p @total_amount_by_account @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + puts "total_discount_by_account" + p @total_discount_by_account @total_member_discount = ShiftSale.get_total_member_discount(@shift) + puts "total_member_discount" + p @total_member_discount # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index ec09aaab..ec00c5f6 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -29,8 +29,12 @@ class Settings::PromotionsController < ApplicationController def create @promotion = Promotion.new(promotion_params) @promotion.created_by = current_login_employee.id - @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) - @promotion.promo_end_hour = @promotion.promo_end_hour.to_datetime.advance(hours: +6, minutes: +30) + if !@promotion.promo_start_hour.nil? + @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) + end + if !@promotion.promo_end_hour.nil? + @promotion.promo_end_hour = @promotion.promo_end_hour.to_datetime.advance(hours: +6, minutes: +30) + end respond_to do |format| if @promotion.save promo_pros = @promotion.promotion_products @@ -95,16 +99,23 @@ class Settings::PromotionsController < ApplicationController def find_parent_item res = [] - item = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code]) - if item.nil? + arr_inst = [] + item_inst = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code]) + if item_inst.nil? product = Product.where("item_code = ?",params[:item_instance_code]).pluck(:name,:item_code) res.push(product.name) res.push(product.item_code) else - # menu_item = item.menu_item.pluck(:name,:item_code) - res.push(item.item_instance_name) - res.push(item.menu_item.item_code) + # menu_item = item_inst.menu_item.pluck(:name,:item_code) + # res.push(item_inst.item_instance_name) + # res.push(item_inst.menu_item.item_code) + item_inst.menu_item.menu_item_instances.each do |inst| + arr_inst.push({inst.item_instance_code => inst.item_instance_name}) + end + res.push({item_inst.menu_item.item_code => arr_inst}) end + puts "res" + p res render json: res end diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 6150eff8..e90c8ef5 100755 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -106,39 +106,39 @@ -->
- <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> + <% arr = MenuItem.active.joins("JOIN menu_item_instances as b ON b.menu_item_id=menu_items.id").group("menu_items.id").order("name desc").pluck(:name,:item_code) %> <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> - <% arr.push(p) %> + <% arr.push(p) %> <% end %>
<% sample = [] %> <% if !@promotion.original_product.nil? %> - <% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %> - <% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%> - <% else %> - <% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%> - <% end %> + <% if !MenuItemInstance.find_by_item_instance_code(@promotion.original_product).nil? %> + <% sample = MenuItemInstance.where("item_instance_code=?",@promotion.original_product).pluck(:item_instance_name,:item_instance_code)%> + <% else %> + <% sample = Product.where("item_code=?",@promotion.original_product).pluck(:name,:item_code)%> + <% end %> <% end %>
<%= f.input :original_product,collection: sample %>
@@ -160,7 +160,7 @@ <%= f.fields_for :promotion_products do |pro| %>
<%= pro.hidden_field :item_code,:class => "promo_product" %> - <% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> + <% arr = MenuItem.joins("JOIN menu_item_instances as b ON b.menu_item_id=menu_items.id").group("menu_items.id").order("name desc").pluck(:name,:item_code) %> <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> <% arr.push(p) %> <% end %> @@ -247,9 +247,10 @@