diff --git a/Gemfile b/Gemfile index 7b2cdca5..44a85e51 100644 --- a/Gemfile +++ b/Gemfile @@ -116,3 +116,4 @@ gem 'httparty', '~> 0.15.5' # # gem 'momentjs-rails', '>= 2.9.0' # gem 'bootstrap3-datetimepicker-rails'z gem 'bootstrap-datepicker-rails' +gem 'jquery-datetimepicker-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 912f79ef..f2d875dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,7 @@ GEM jbuilder (2.7.0) activesupport (>= 4.2.0) multi_json (>= 1.2) + jquery-datetimepicker-rails (2.4.1.0) jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) @@ -265,6 +266,7 @@ DEPENDENCIES font-awesome-rails httparty (~> 0.15.5) jbuilder (~> 2.5) + jquery-datetimepicker-rails jquery-rails jquery-ui-rails kaminari (~> 1.0.1) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index cd056d1c..675bca2e 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -20,6 +20,7 @@ //= require settings/processing_items //= require jquery-ui //= require bootstrap-datepicker +//= require jquery.datetimepicker $(document).on('turbolinks:load', function() { $('.datepicker').datepicker({ diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 2db849ab..6ff7113c 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -4,6 +4,7 @@ @import "theme"; @import "jquery-ui"; @import "bootstrap-datepicker3"; +@import "jquery.datetimepicker"; /* Show it is fixed to the top */ // body { @@ -75,5 +76,3 @@ select.form-control { } /*--- Reset --- */ - - diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index 246bd51b..94f095ec 100644 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -28,8 +28,14 @@ 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) respond_to do |format| if @promotion.save + promo_pros = @promotion.promotion_products + promo_pros.each do |promo_pro| + promo_pro.save + end format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully created.' } format.json { render :show, status: :created, location: @promotion } else @@ -44,6 +50,13 @@ class Settings::PromotionsController < ApplicationController def update respond_to do |format| if @promotion.update(promotion_params) + @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) + @promotion.save + promo_pros = @promotion.promotion_products + promo_pros.each do |promo_pro| + promo_pro.save + end format.html { redirect_to settings_promotions_path, notice: 'Promotion was successfully updated.' } format.json { render :show, status: :ok, location: @promotion } else diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 474dcb3d..c3953f32 100644 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -1,3 +1,4 @@ + <%= simple_nested_form_for([:settings,@promotion]) do |f| %> <%= f.error_notification %> @@ -20,11 +21,23 @@
- <%= f.input :promo_start_hour %> + + <% if !@promotion.promo_start_hour.nil?%> + <%= f.input :promo_start_hour, as: :string, input_html: { :value => @promotion.promo_start_hour.utc.strftime('%H:%M') } %> + <% else %> + <%= f.input :promo_start_hour, as: :string, input_html: { } %> + <% end %>
-
<%= f.input :promo_end_hour %>
+
+ + <% if !@promotion.promo_end_hour.nil?%> + <%= f.input :promo_end_hour, as: :string, input_html: {:value => @promotion.promo_end_hour.utc.strftime('%H:%M') } %> + <% else %> + <%= f.input :promo_end_hour, as: :string, input_html: {} %> + <% end %> +
<%= f.input :promo_day %>
@@ -40,19 +53,52 @@
<%= f.input :min_qty %>

-

<%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %>


- <%= f.fields_for :promotion_products do |p| %> + + + + + + + + + + + -
-
<%= p.input :item_code , :class => "form-control" %>
-
<%= p.input :min_qty , :class => "form-control" %>
-
<%= p.input :net_off , :class => "form-control" %>
-
<%= p.input :net_price , :class => "form-control" %>
-
<%= p.input :percentage , :class => "form-control" %>
-
<%= p.link_to_remove "X"%>
-
+ + +
Item CodeMin QtyNet offNet PricePercentage
+ <%= f.fields_for :promotion_products do |pro| %> + + + + + + + + + + + + + +
<%= pro.input :item_code, label: false%><%= pro.input :min_qty , label: false%><%= pro.input :net_off , label: false %><%= pro.input :net_price , label: false %><%= pro.input :percentage , label: false %><%= pro.link_to_remove "X" %>
<% end %> + <%= f.link_to_add "Add Product", :promotion_products, :class => 'btn btn-primary' %> @@ -61,3 +107,23 @@ <%= f.button :submit %> <% end %> + diff --git a/app/views/settings/promotions/index.html.erb b/app/views/settings/promotions/index.html.erb index 606b138b..7914c6af 100644 --- a/app/views/settings/promotions/index.html.erb +++ b/app/views/settings/promotions/index.html.erb @@ -35,8 +35,8 @@ <%= link_to pro.promo_code, settings_promotion_path(pro) %> <%= pro.promo_start_date %> <%= pro.promo_end_date %> - <%= pro.promo_start_hour.strftime("%I:%M %P") rescue "-" %> - <%= pro.promo_end_hour.strftime("%I:%M %P") rescue "-" %> + <%= pro.promo_start_hour.utc.strftime("%I:%M %P") rescue "-" %> + <%= pro.promo_end_hour.utc.strftime("%I:%M %P") rescue "-" %> <%= pro.promo_day %> <% if MenuItem.exists?(pro.original_product) %> diff --git a/app/views/settings/promotions/show.html.erb b/app/views/settings/promotions/show.html.erb index 170ba4bf..4a994919 100644 --- a/app/views/settings/promotions/show.html.erb +++ b/app/views/settings/promotions/show.html.erb @@ -17,8 +17,8 @@ Promotion code<%= @promotion.promo_code %> Promotion Start Date<%= @promotion.promo_start_date %> Promotion End Date<%= @promotion.promo_end_date %> - Promotion Start Hour<%= @promotion.promo_start_hour %> - Promotion Start Hour<%= @promotion.promo_end_hour %> + Promotion Start Hour<%= @promotion.promo_start_hour.utc.strftime("%I:%M %P") rescue "-" %> + Promotion Start Hour<%= @promotion.promo_end_hour.utc.strftime("%I:%M %P") rescue "-" %> <%= link_to 'Edit', edit_settings_promotion_path(@promotion) %><%= link_to 'Destroy', settings_promotion_path(@promotion), method: :delete, data: { confirm: 'Are you sure?' } %>