updat e addorder for product add
This commit is contained in:
@@ -1,5 +1,81 @@
|
||||
$(function(){
|
||||
//click menu sidebar menu category
|
||||
$(".product").on("click", function(){
|
||||
var url = $(this).attr('data-ref');
|
||||
show_product_list(url);
|
||||
console.log(url)
|
||||
});
|
||||
//show menu item list when click menu category
|
||||
function show_product_list(url_item){
|
||||
|
||||
var menu_list = $('.menu_items_list');
|
||||
menu_list.empty();
|
||||
//Start Ajax
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: url_item,
|
||||
data: {},
|
||||
dataType: "json",
|
||||
success: function(data) {
|
||||
|
||||
var menu_items_list = $('.menu_items_list');
|
||||
menu_items_list.empty();
|
||||
product = data;
|
||||
|
||||
for(var field in product) {
|
||||
console.log(product[field].name);
|
||||
if (product[field].unit_price > 0) {
|
||||
console.log("hi");
|
||||
qty = 1;
|
||||
options = [];
|
||||
item_attributes = [];
|
||||
|
||||
if (product[field].image_path) {
|
||||
image_path = product[field].image_path.url;
|
||||
}else{
|
||||
image_path = "/image/logo.png";
|
||||
}
|
||||
|
||||
row = '<div class="card custom-card testimonial-card animated fadeInRight" style="">'
|
||||
+'<div class="custom-card-head card-head" style="line-height:14px;">'
|
||||
+'<small class="col-md-9">'+ product[field].name +'</small>'
|
||||
+"<div class='col-md-3 add_icon' data-item-code='"
|
||||
+ product[field].item_code +"' data-name='"
|
||||
+ product[field].name +"' data-qty = '"+ qty +"' data-price = '"
|
||||
+ product[field].unit_price +"' data-instance-code = '"+ product[field].item_code +"' data-instance = '"
|
||||
+ product[field].name +"' data-promotion-price = '"+ 1 +"' data-attributes = '"
|
||||
+ JSON.stringify(item_attributes) +"' data-options = '"
|
||||
+ options +"' data-image='"+image_path+"'>"
|
||||
+"<i class='fa fa-plus '"
|
||||
+ 'style="margin-top:4px;">'
|
||||
+'</i>'
|
||||
+'</div>'
|
||||
+'</div>'
|
||||
|
||||
+"<div class='menu_item_box' data-item-code='"
|
||||
+ product[field].item_code +"' data-instance = '"
|
||||
+JSON.stringify(item_attributes)+"' data-id = '"
|
||||
+JSON.stringify(item_attributes)+"' data-item = '"
|
||||
+JSON.stringify(item_attributes)+"' data-option = '"
|
||||
+JSON.stringify(item_attributes)+"' data-item-sets = '"
|
||||
+JSON.stringify(item_attributes)+"' data-toggle='modal' data-target='.sx_item_detailModal'>"
|
||||
|
||||
+"<div class='card-block custom-card-block'>"
|
||||
+"<img id='logo' src='"+image_path+"'>"
|
||||
+"</div>"
|
||||
|
||||
+'<div class="card-footer custom-card-footer">'
|
||||
+'<small>'+ product[field].unit_price +'</small>'
|
||||
+'</div>'
|
||||
+'</div>';
|
||||
$('.menu_items_list').append(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
//end Ajax
|
||||
}
|
||||
//end show list function
|
||||
//click menu sidebar menu category
|
||||
$(".menu_category").on("click", function(){
|
||||
var menu_id = $(this).find(".menu-id").text();
|
||||
|
||||
@@ -43,6 +43,9 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
end
|
||||
end
|
||||
|
||||
def get_all_product()
|
||||
@product = Product.all
|
||||
end
|
||||
|
||||
def create
|
||||
Rails.logger.debug "Order Source - " + params[:order_source].to_s
|
||||
@@ -53,6 +56,7 @@ class Origami::AddordersController < BaseOrigamiController
|
||||
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]}
|
||||
items_arr.push(items)
|
||||
}
|
||||
|
||||
# begin
|
||||
@order = Order.new
|
||||
@order.source = params[:order_source]
|
||||
|
||||
@@ -38,6 +38,41 @@ class Order < ApplicationRecord
|
||||
booking.save!
|
||||
self.default_values
|
||||
|
||||
# cashier already opened?
|
||||
if self.save!
|
||||
|
||||
self.adding_line_items
|
||||
#Add Order Table and Room relation afrer order creation
|
||||
BookingOrder.create({:booking_id => booking.booking_id, :order => self})
|
||||
|
||||
#Send order to queue one it done!
|
||||
process_order_queue
|
||||
|
||||
#send order to broadcast job
|
||||
send_order_broadcast(booking)
|
||||
|
||||
return true, booking
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
def custom_generate
|
||||
booking = nil
|
||||
|
||||
if self.new_booking
|
||||
booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking",
|
||||
:checkin_at => Time.now.utc, :checkin_by => self.employee_name,
|
||||
:booking_status => "assign" })
|
||||
table = DiningFacility.find(self.table_id)
|
||||
table.status = "occupied"
|
||||
table.save
|
||||
else
|
||||
booking = Booking.find(self.booking_id)
|
||||
end
|
||||
|
||||
booking.save!
|
||||
self.default_values
|
||||
|
||||
# cashier already opened?
|
||||
if self.save!
|
||||
|
||||
@@ -58,7 +93,6 @@ class Order < ApplicationRecord
|
||||
return false
|
||||
|
||||
end
|
||||
|
||||
#Main Method - to update order / add items
|
||||
def modify
|
||||
|
||||
@@ -71,8 +105,13 @@ class Order < ApplicationRecord
|
||||
|
||||
#loop to add all items to order
|
||||
self.items.each do |item|
|
||||
|
||||
menu_item = MenuItem.search_by_item_code(item[:item_instance_code])
|
||||
|
||||
if menu_item.nil?
|
||||
menu_item = Product.search_by_product_code(item[:item_instance_code])
|
||||
end
|
||||
|
||||
#if (!menu_item.nil?)
|
||||
Rails.logger.debug menu_item
|
||||
set_order_items = nil
|
||||
|
||||
@@ -3,4 +3,24 @@ class Product < ApplicationRecord
|
||||
|
||||
# Product Image Uploader
|
||||
mount_uploader :image_path, ProductImageUploader
|
||||
|
||||
def self.search_by_product_code(item_code)
|
||||
menu_item_hash = Hash.new
|
||||
mt_instance = Product.find_by_item_code(item_code)
|
||||
if (!mt_instance.nil?)
|
||||
menu_item_hash[:type] = 'SetMenuItem'
|
||||
menu_item_hash[:account_id] = 1
|
||||
menu_item_hash[:item_code] = mt_instance.item_code
|
||||
menu_item_hash[:item_instance_code] = mt_instance.item_code
|
||||
menu_item_hash[:name] = mt_instance.name.to_s
|
||||
menu_item_hash[:alt_name] = mt_instance.alt_name.to_s
|
||||
menu_item_hash[:price] = mt_instance.unit_price
|
||||
menu_item_hash[:promotion_price] = 0
|
||||
menu_item_hash[:is_on_promotion] = 0
|
||||
menu_item_hash[:is_available] = 0
|
||||
menu_item_hash[:taxable] = mt_instance.taxable
|
||||
|
||||
return menu_item_hash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
<div class="row">
|
||||
<div class="col-lg-2 col-md-2 col-sm-2">
|
||||
<ul class="nav nav-tabs flex-column" role="tablist" >
|
||||
<% @menu.each do |menu| %>
|
||||
<li class="nav-item menu_category" data-ref="<%= origami_get_menu_category_path menu.id%>">
|
||||
<p class="hidden menu-id"><%= menu.id %></p>
|
||||
<a class="nav-link" data-toggle="tab" href="" role="tab"> <%= menu.name%></a>
|
||||
|
||||
</li>
|
||||
<% end %>
|
||||
<% @menu.each do |menu| %>
|
||||
<li class="nav-item menu_category" data-ref="<%= origami_get_menu_category_path menu.id%>">
|
||||
<p class="hidden menu-id"><%= menu.id %></p>
|
||||
<a class="nav-link" data-toggle="tab" href="" role="tab"> <%= menu.name%></a>
|
||||
</li>
|
||||
<% end %>
|
||||
<li class="nav-item product" data-ref="<%= origami_get_all_product_path %>">
|
||||
<a class="nav-link" data-toggle="tab" href="" role="tab">Products</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-md-7 col-lg-7 col-sm-7">
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
json.array! @product, :id, :item_code, :name, :alt_name,:image_path,
|
||||
:description,:information,:taxable,:unit_price, :created_at,
|
||||
:updated_at, :created_by
|
||||
@@ -181,6 +181,7 @@ Rails.application.routes.draw do
|
||||
get '/:addorders/:id' => "addorders#detail"
|
||||
post '/:addorders/create' => "addorders#create", :defaults => { :format => 'json' }
|
||||
get '/addorders/get_menu_category/:id' => "addorders#get_menu_category",:as => "get_menu_category", :defaults => { :format => 'json' }
|
||||
get '/addorders/products/list' => "addorders#get_all_product",:as => "get_all_product", :defaults => { :format => 'json' }
|
||||
|
||||
resources :commissions
|
||||
resources :commissioners
|
||||
|
||||
Reference in New Issue
Block a user