diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index d2faf9da..fd37fb2d 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -183,7 +183,27 @@ $(document).ready(function() { ' {caption}\n' + '\n', } - }); + }); + + $(".order").fileinput({ + previewFileType: "mp3", + allowedFileExtensions: ["mp3"], + browseClass: "btn btn-success", + browseLabel: "Pick Audio", + browseIcon: " ", + removeClass: "btn btn-danger", + removeLabel: "Delete", + removeIcon: " ", + showUpload: false, + // uploadClass: "btn btn-info", + // uploadLabel: "Upload", + // uploadIcon: " ", + previewTemplates: { + image: '
\n' + + ' {caption}\n' + + '
\n', + } + }); // first input focus for all form $('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus(); diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 8d2255d4..3553c7e0 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -5,14 +5,10 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController ORDER_RESERVATION = "order_and_reservation" def check_customer - customer_id = 0 + customer_id = nil status = false - if !params[:name] - render :json => { :status => false, :message => "name is required!" } - elsif !params[:email] - render :json => { :status => false, :message => "email is required!" } - elsif !params[:membership_id] - render :json => { :status => false, :message => "membership_id is required!" } + if !params[:name] || !params[:email] || !params[:contact_no] || !params[:membership_id] + render :json => { :status => false, :message => "name, email, contact_no and membership_id are required!" } else status = true end @@ -25,7 +21,11 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController customer = OrderReservation.addCustomer(params) customer_id = customer.id end - render :json => { :status => true, :data => { :customer_id => customer_id} } + if !customer_id.nil? + render :json => { :status => false, :message => "email and customer are already existed!" } + else + render :json => { :status => true, :data => { :customer_id => customer_id} } + end end end diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb index 06c9f643..c3d7bb4a 100644 --- a/app/controllers/api/survey_controller.rb +++ b/app/controllers/api/survey_controller.rb @@ -17,8 +17,8 @@ class Api::SurveyController < Api::ApiController dining_facility = DiningFacility.find(params[:id]) cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) - - if params[:survey][:id] + puts params.to_json + if params[:survey][:id]>0 survey = Survey.find(params[:survey][:id]) else survey = Survey.new diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb index 975d9e25..7d9ccd25 100644 --- a/app/controllers/settings/shops_controller.rb +++ b/app/controllers/settings/shops_controller.rb @@ -47,13 +47,26 @@ class Settings::ShopsController < ApplicationController # PATCH/PUT /settings/shops/1 # PATCH/PUT /settings/shops/1.json def update - respond_to do |format| if @settings_shop.update(shop_params) if params[:display_images].present? params[:display_images][:image].each do |a| - @aa = Base64.encode64(a.read) - @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => "data:image/jpeg;base64,"+@aa) + if File.extname(a.original_filename) == ".mp3" + delete_path = Rails.root.join("public/#{@settings_shop.display_images.find_by_name("order_audio").image}") + if File.exists?(delete_path) + File.delete(delete_path) + end + save_path = Rails.root.join("public/#{Shop.find(1).shop_code}_#{a.original_filename}") + File.open(save_path, 'wb') do |f| + f.write a.read + end + audio_name = "#{Shop.find(1).shop_code}_#{a.original_filename}" + @settings_shop.display_images.where(:name => "order_audio").destroy_all + @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :name => "order_audio", :image => audio_name) + else + @aa = Base64.encode64(a.read) + @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => "data:image/jpeg;base64,"+@aa) + end end end format.html { redirect_to settings_shops_url, notice: 'Shop was successfully updated.' } @@ -85,6 +98,6 @@ class Settings::ShopsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def shop_params - params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info, display_images_attributes: [:id, :shop_id, :image]) + params.require(:shop).permit(:logo, :name,:address,:city,:township,:state,:country,:phone_no,:reservation_no,:license,:activated_at,:license_data,:base_currency,:cloud_token,:cloud_url,:owner_token,:id_prefix,:is_rounding_adj,:quick_sale_summary,:calc_tax_order,:show_account_info, display_images_attributes: [:id, :shop_id, :name, :image]) end end diff --git a/app/models/promotion.rb b/app/models/promotion.rb index 0fd43d30..5bc6a686 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -154,7 +154,8 @@ class Promotion < ApplicationRecord promotion_qty = foc_qty end # item = OrderItem.find_by_item_instance_code(promo_product) - item = OrderItem.where("item_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first + item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first + source = Order.find(item.order_id).source update_existing_item(promotion_qty, item, sale_id, "promotion", item.price,source) end @@ -211,8 +212,12 @@ class Promotion < ApplicationRecord source = Order.find(item.order_id).source update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) else - # foc_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty + order_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty foc_qty = orderitem[1].to_i / foc_min_qty + + if foc_qty > order_qty + foc_qty = order_qty + end # item = OrderItem.find_by_item_instance_code(promo_product.item_code) item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first price = item.price - promo_product.net_price @@ -233,11 +238,13 @@ class Promotion < ApplicationRecord source = Order.find(item.order_id).source update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) else - # foc_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check + order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check foc_qty = orderitem[1].to_i / foc_min_qty # give total qty is 1 #foc_qty = (foc_qty - foc_qty) + 1 - + if foc_qty > order_qty + foc_qty = order_qty + end # item = OrderItem.find_by_item_instance_code(promo_product.item_code) item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first # total = item.price * foc_qty diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index e8062d46..9262e05c 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -468,7 +468,7 @@
-
- +
+
+
+
+ <%= f.file_field :image, :multiple => true, name: "display_images[image][]" %> +
+ +
+
+ +
+
+
-
- <%= f.file_field :image, :multiple => true, name: "display_images[image][]" %> +
+
+ <%= f.file_field :image, :multiple => false, name: "display_images[image][]", accept: 'audio/mp3', :class => "order" %>
diff --git a/app/views/settings/shops/show.html.erb b/app/views/settings/shops/show.html.erb index 40082d72..eb8632e2 100755 --- a/app/views/settings/shops/show.html.erb +++ b/app/views/settings/shops/show.html.erb @@ -103,7 +103,19 @@ Shop Images <% @display_images.each do |p| %> - <%= image_tag "#{p.image}", :class => "img-thumbnail second-display", :size => "155x185"%> + <% if p.name.nil? %> + <%= image_tag "#{p.image}", :class => "img-thumbnail second-display", :size => "155x185"%> + <% end %> + <% end %> + + + + Order Audio + + <% @display_images.each do |p| %> + <% if !p.name.nil? %> + <%= image_tag "#{p.image}", :class => "img-thumbnail second-display", :size => "155x185"%> + <% end %> <% end %>