change promotion with menu item and menu item instance
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -106,39 +106,39 @@
|
||||
</div>
|
||||
-->
|
||||
<div class="row">
|
||||
<% 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 %>
|
||||
<div class="col-md-3 form-group">
|
||||
<label class="control-label"><abbr title="required">*</abbr> Item</label>
|
||||
<select class="form-control item_code_place">
|
||||
<% if !@promotion.original_product.nil? %>
|
||||
<% menuiteminstance = MenuItemInstance.find_by_item_instance_code(@promotion.original_product) %>
|
||||
<% if menuiteminstance.nil?%>
|
||||
<% code = @promotion.original_product %>
|
||||
<% else %>
|
||||
<% code = menuiteminstance.menu_item.item_code %>
|
||||
<% end %>
|
||||
<% menuiteminstance = MenuItemInstance.find_by_item_instance_code(@promotion.original_product) %>
|
||||
<% if menuiteminstance.nil?%>
|
||||
<% code = @promotion.original_product %>
|
||||
<% else %>
|
||||
<% code = menuiteminstance.menu_item.item_code %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<option value="" selected>Choose Something</option>
|
||||
<% arr.each do |a| %>
|
||||
<% if a[1] == code %>
|
||||
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
||||
<% else %>
|
||||
<option value="<%= a[1]%>"><%= a[0] %></option>
|
||||
<% end %>
|
||||
<% if a[1] == code %>
|
||||
<option value="<%= a[1]%>" selected><%= a[0] %></option>
|
||||
<% else %>
|
||||
<option value="<%= a[1]%>"><%= a[0] %></option>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<% 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 %>
|
||||
<div class="col-md-3 form-group"><%= f.input :original_product,collection: sample %></div>
|
||||
<!-- <div class="col-md-6"><%= f.input :original_product,collection: MenuItemInstance.order("item_instance_name desc").pluck(:item_instance_name,:item_instance_code),input_html: { selected: 2 } %></div> -->
|
||||
@@ -160,7 +160,7 @@
|
||||
<%= f.fields_for :promotion_products do |pro| %>
|
||||
<div class="row">
|
||||
<%= 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 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
$(document).ready(function(){
|
||||
if(($('.item_code_place').val()!=undefined) && ($('.item_code_place').val()!="")){
|
||||
getItemInstance($('.item_code_place').val());
|
||||
}
|
||||
|
||||
$('#promotion_promo_start_hour').on('change', function(event) {
|
||||
$('#promotion_promo_start_hour').val($('#promotion_promo_start_hour').val().split(":")[0]+":00");
|
||||
@@ -273,7 +274,7 @@
|
||||
});
|
||||
|
||||
var dayy = $("#promotion_promo_day").val().replace("[","").replace("]","");
|
||||
jQuery.each( dayy.split(","), function( i, d ) {
|
||||
$.each( dayy.split(","), function( i, d ) {
|
||||
$("input.selectDay[value='"+d+"']").prop( "checked", true );
|
||||
});
|
||||
|
||||
@@ -324,8 +325,13 @@
|
||||
// $(".item_code_place").select2();
|
||||
|
||||
$(".item_code_place").on('change', function(event) {
|
||||
var ajax_url = "<%= settings_find_item_instance_path %>";
|
||||
var item_code = this.value;
|
||||
getItemInstance(item_code);
|
||||
});
|
||||
|
||||
function getItemInstance(item_code) {
|
||||
var ajax_url = "<%= settings_find_item_instance_path %>";
|
||||
var original_product = "<%= @promotion.original_product %>";
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: ajax_url,
|
||||
@@ -334,13 +340,15 @@
|
||||
$("#promotion_original_product").empty();
|
||||
var itemlist;
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
itemlist += "<option value ="+result[i][1]+">"+result[i][0]+"</option>"
|
||||
var selected = "";
|
||||
if(original_product == result[i][1]) selected = "selected";
|
||||
itemlist += "<option value ="+result[i][1]+" "+selected+">"+result[i][0]+"</option>"
|
||||
}
|
||||
$("#promotion_original_product").append(itemlist);
|
||||
//$("#promotion_original_product").select2();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//$(".promotion_promotion_products_item_code select").select2();
|
||||
//$(".item_code_place1").select2();
|
||||
@@ -356,7 +364,7 @@
|
||||
|
||||
// for promotion products data showing
|
||||
var promopdt = $(".promo_product");
|
||||
jQuery.each( promopdt, function( i, ppdt ) {
|
||||
$.each( promopdt, function( i, ppdt ) {
|
||||
var ajax_url = "<%= settings_find_parent_item_path %>";
|
||||
var item_code = ppdt.value;
|
||||
var select_id = ppdt.id;
|
||||
@@ -365,14 +373,33 @@
|
||||
url: ajax_url,
|
||||
data: 'item_instance_code=' + item_code,
|
||||
success: function (result) {
|
||||
// console.log(result);
|
||||
var par_item_code = "";
|
||||
var arr_item_inst = "";
|
||||
if((result[0]!=undefined) && (result[0]!="")){
|
||||
$.each(result[0],function(k,val){
|
||||
par_item_code = k;
|
||||
arr_item_inst = val;
|
||||
});
|
||||
}
|
||||
|
||||
if(result.length > 0){
|
||||
$("select#"+select_id).empty();
|
||||
$("select#"+select_id).append("<option value='"+item_code+"'>"+result[0]+"</option>");
|
||||
$("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").find("option[value='"+result[1]+"']").attr("selected","true")
|
||||
var iteminstlists;
|
||||
$.each(arr_item_inst,function(k2,v2al){
|
||||
$("select#"+select_id).empty();
|
||||
var selected = "";
|
||||
$.each(v2al,function(k3,v3al){
|
||||
if(k3 == item_code) selected = "selected";
|
||||
iteminstlists += "<option value='"+k3+"' "+selected+">"+v3al+"</option>";
|
||||
});
|
||||
});
|
||||
$("select#"+select_id).append(iteminstlists);
|
||||
|
||||
$("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").find("option[value='"+par_item_code+"']").attr("selected","true")
|
||||
// $("select#"+select_id).parent().parent().siblings("div.menu_item_choose").find("select").select2();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// promotion_promotion_products_attributes_0_item_code
|
||||
@@ -394,8 +421,8 @@
|
||||
}
|
||||
$("select#"+id).append(itemlist);
|
||||
//$("select#"+id).select2();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
24
db/seeds.rb
24
db/seeds.rb
@@ -182,19 +182,19 @@ cashier_terminal = CashierTerminal.create({name:"Terminal 1", printer_name: "Cas
|
||||
|
||||
zone = Zone.create({id:1, name: "H1", is_active:true, created_by: "SYSTEM DEFAULT"})
|
||||
|
||||
member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "http://staging.membership.paypar.ws",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv"})
|
||||
member_setting = MembershipSetting.create({membership_type:"paypar_url",gateway_url: "https://staging.membership.paypar.ws",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv"})
|
||||
|
||||
member_actions= MembershipAction.create([{membership_type:"get_account_balance",gateway_url:"/api/membership_campaigns/get_correspond_account_data",additional_parameter:{campaign_type_id:1},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"redeem",gateway_url:"/api/membership_campaigns/redeem",additional_parameter:{campaign_type_id:1},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"create_membership_customer",gateway_url:"/api/generic_customer/create_membership_customer",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"update_membership_customer",gateway_url:"/api/generic_customer/update_membership_customer",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_all_member_group",gateway_url:"/api/member_group/get_all_member_group",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"rebate",gateway_url:"/api/membership_campaigns/rebate",additional_parameter:{campaign_type_id:1},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_all_member_account",gateway_url:"/api/generic_customer/get_member_data",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_member_transactions",gateway_url:"/api/generic_customer/get_membership_transactions",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"member_discount",gateway_url:"/api/membership_campaigns/discount",additional_parameter:{campaign_type_id:5},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_member_campaign",gateway_url:"/api/membership_campaigns/get_member_campaign",additional_parameter:{campaign_type_id:5},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"search_paypar_account_no",gateway_url:"/api/generic_customer/get_membership_customer_data",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"}
|
||||
member_actions= MembershipAction.create([{membership_type:"get_account_balance",is_active:1,gateway_url:"/api/membership_campaigns/get_correspond_account_data",additional_parameter:{campaign_type_id:1},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"redeem",is_active:1,gateway_url:"/api/membership_campaigns/redeem",additional_parameter:{campaign_type_id:1},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"create_membership_customer",is_active:1,gateway_url:"/api/generic_customer/create_membership_customer",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"update_membership_customer",is_active:1,gateway_url:"/api/generic_customer/update_membership_customer",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_all_member_group",is_active:1,gateway_url:"/api/member_group/get_all_member_group",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"rebate",is_active:1,gateway_url:"/api/membership_campaigns/rebate",additional_parameter:{campaign_type_id:1},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_all_member_account",is_active:1,gateway_url:"/api/generic_customer/get_member_data",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_member_transactions",is_active:1,gateway_url:"/api/generic_customer/get_membership_transactions",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"member_discount",is_active:1,gateway_url:"/api/membership_campaigns/discount",additional_parameter:{campaign_type_id:5},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"get_member_campaign",is_active:1,gateway_url:"/api/membership_campaigns/get_member_campaign",additional_parameter:{campaign_type_id:5},merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"},
|
||||
{membership_type:"search_paypar_account_no",is_active:1,gateway_url:"/api/generic_customer/get_membership_customer_data",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv",auth_token:"code2lab"}
|
||||
])
|
||||
|
||||
payment_methods = PaymentMethodSetting.create({payment_method:"MPU",gateway_url: "http://membership.paypar.ws"})
|
||||
|
||||
Reference in New Issue
Block a user