From fa554067a3724659d881c6174f416bc981374869 Mon Sep 17 00:00:00 2001 From: Yan Date: Tue, 24 Oct 2017 17:57:03 +0630 Subject: [PATCH 1/2] fix seed --- app/models/seed_generator.rb | 74 ++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index b05398aa..1451b11e 100755 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,42 +1,15 @@ class SeedGenerator < ApplicationRecord # Generate ID for Tables def self.generate_id(model, prefix) - seed = SeedGenerator.find_by_model(model) - new_receipt_no = 0 + cur_val, next_val = self.update_seed(model) - if (seed.nil?) - seed = SeedGenerator.new() - seed.model = model - new_receipt_no = seed.next - seed.save - else - next_no = seed.next - current_no = seed.next - seed.next = seed.next + seed.increase_by - seed.current = current_no - seed.save - # cur_val, next_val = self.update_seed(model, seed.next, seed.increase_by) - - # if next_no == cur_val - # puts "SSS" - # puts next_val - # cur_val2, next_val2 = self.update_seed(model, next_val, seed.increase_by) - # puts next_val2 - # padding_len = 15 - prefix.length - # saleOrderId = prefix +"-"+ cur_val2.to_s.to_s.rjust((14-prefix.length)+1,'0') - # puts saleOrderId - # return saleOrderId - # end - - # padding_len = 15 - prefix.length - # saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0') - # return saleOrderId - - end + if (cur_val == 0) + cur_val, next_val = self.execute_query(model) + end padding_len = 15 - prefix.length - saleOrderId = prefix +"-"+ seed.current.to_s.to_s.rjust((14-prefix.length)+1,'0') - return saleOrderId + saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust((14-prefix.length)+1,'0') + return saleOrderId end # Generate Receipt No @@ -88,22 +61,41 @@ class SeedGenerator < ApplicationRecord return next_code end - def self.update_seed(model, current, inc) - cur_val = 0 - next_val = 0 - nex = current + inc + def self.execute_query(model) + current = 0 + nex = 0 + + sql = "INSERT INTO seed_generators (model, created_at, updated_at) + VALUES('#{ model }', NOW(), NOW()) + ON DUPLICATE KEY UPDATE current = current + 1, next = next + 1;" - update_sql = "update seed_generators set current= #{current}, next= #{nex} where model='#{model}';"; + select_sql = "select * from seed_generators where model='#{model}';" + ActiveRecord::Base.connection.execute(sql); + select_result = ActiveRecord::Base.connection.execute(select_sql); + + select_result.each do |row| + current = row [3] + nex = row[4] + end + + return current, nex + end + + def self.update_seed(model) + current = 0 + nex = 0 + + update_sql = "UPDATE seed_generators set current = current + 1, next = next + 1 WHERE model='#{model}';" select_sql = "select * from seed_generators where model='#{model}';" update_result = ActiveRecord::Base.connection.execute(update_sql); select_result = ActiveRecord::Base.connection.execute(select_sql); select_result.each do |row| - cur_val = row [3] - next_val = row[4] + current = row [3] + nex = row[4] end - return cur_val, next_val + return current, nex end end From bbae5cd5cc7dc47687eec26c26657aae4a0c3228 Mon Sep 17 00:00:00 2001 From: Yan Date: Wed, 25 Oct 2017 13:03:12 +0630 Subject: [PATCH 2/2] update promotion form --- app/assets/stylesheets/reset.css | 6 + app/views/settings/promotions/_form.html.erb | 129 ++++++++++++++----- 2 files changed, 102 insertions(+), 33 deletions(-) diff --git a/app/assets/stylesheets/reset.css b/app/assets/stylesheets/reset.css index e79eb0b2..db9581fa 100644 --- a/app/assets/stylesheets/reset.css +++ b/app/assets/stylesheets/reset.css @@ -198,5 +198,11 @@ section.content { background-color: #007d72 !important; } +/* FORM */ +.input-group-addon { + padding: 0rem 0rem; +} +/* END FORM */ + /* End Reset Theme */ /* *************************************************** */ \ No newline at end of file diff --git a/app/views/settings/promotions/_form.html.erb b/app/views/settings/promotions/_form.html.erb index 5ee3924f..e68cb665 100755 --- a/app/views/settings/promotions/_form.html.erb +++ b/app/views/settings/promotions/_form.html.erb @@ -5,41 +5,81 @@
-
-
<%= f.input :promo_code %>
-
-
- * Promo Start Date - <%= f.date_field :promo_start_date, :placeholder => "From Date" , :class => "form-control datepicker"%> -
-
-
- * Promo End Date - <%= f.date_field :promo_end_date ,:placeholder => "To Date" , :class => "form-control datepicker"%> + +
+ + vpn_key + + +
+
- - <% 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 %> - + +
+ + date_range + + <% if !@promotion.promo_start_date.nil?%> + + <% else %> + + <% end %> +
- - <% if !@promotion.promo_end_hour.nil?%> + +
+ + date_range + + <% if !@promotion.promo_end_date.nil?%> + + <% else %> + + <% end %> +
+
+
+ +
+
+ +
+ + access_time + + <% if !@promotion.promo_start_hour.nil?%> + + <% else %> + + <% end %> +
+
+
+ +
+ + access_time + + <% if !@promotion.promo_end_hour.nil?%> + + <% else %> + + <% end %> +
+
+
@@ -53,12 +93,19 @@

+
- <%= f.input :promo_type,input_html: { class: "" }, - collection: %w{Quantity Net_off Net_price Percentage},:class => 'form-control' ,:label => "Promotion Type" %> + +
+
<% arr = MenuItem.active.order("name desc").pluck(:name,:item_code) %> <% Product.order("name desc").pluck(:name,:item_code).each do |p| %> @@ -182,18 +229,31 @@ $(document).ready(function(){ // format:'H:m' // }); - $('#promotion_promo_start_hour').on('change', function(event) { - $('#promotion_promo_start_hour').val($('#promotion_promo_start_hour').val().split(":")[0]+":00"); + // $('#promotion_promo_start_hour').on('change', function(event) { + // $('#promotion_promo_start_hour').val($('#promotion_promo_start_hour').val().split(":")[0]+":00"); + // }); + + // $('#promotion_promo_end_hour').on('change', function(event) { + // $('#promotion_promo_end_hour').val($('#promotion_promo_end_hour').val().split(":")[0]+":00"); + // }); + + $('.datepicker').bootstrapMaterialDatePicker({ + format: 'dddd DD MM YYYY', + clearButton: true, + weekStart: 1, + time: false }); - $('#promotion_promo_end_hour').on('change', function(event) { - $('#promotion_promo_end_hour').val($('#promotion_promo_end_hour').val().split(":")[0]+":00"); + $('.timepicker').bootstrapMaterialDatePicker({ + format: 'HH:mm', + clearButton: true, + date: false }); - var dayy = $("#promotion_promo_day").val().replace("[","").replace("]",""); - jQuery.each( dayy.split(","), function( i, d ) { - $("input.selectDay[value='"+d+"']").prop( "checked", true ); - }); + // var dayy = $("#promotion_promo_day").val().replace("[","").replace("]",""); + // jQuery.each( dayy.split(","), function( i, d ) { + // $("input.selectDay[value='"+d+"']").prop( "checked", true ); + // }); var form = document.getElementById("new_promotion"); var inputs = $("input"); @@ -202,7 +262,6 @@ $(document).ready(function(){ var day = "["; $(".selectDay").click(function() { - // debugger; day = "["; for (var j = 8; j <=15; j += 1){ @@ -226,6 +285,7 @@ $(".selectDay").click(function() { $("#promotion_original_product").select2(); $(".item_code_place").select2(); + $(".item_code_place").on('change', function(event) { var ajax_url = "<%= settings_find_item_instance_path %>"; var item_code = this.value; @@ -244,9 +304,12 @@ $(".selectDay").click(function() { } }); }); + $(".promotion_promotion_products_item_code select").select2(); $(".item_code_place1").select2(); + callforpromoproduct(); + $(".addProduct").on('click', function(event) { setTimeout(function(){ $(".promotion_promotion_products_item_code select").select2();