add to existing order

This commit is contained in:
Myat Zin Wai Maw
2019-12-18 10:15:24 +06:30
parent 8af99742a3
commit 16485875c1
10 changed files with 119 additions and 111 deletions

View File

@@ -311,6 +311,9 @@ settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, val
For Using Staff Meal
settings/lookups => { type:customer_type, name: Staff, value:Staff }
For FoodCourt Cashier role
settings/lookups => { type:employee_roles, name: FoodCourt Cashier, value:foodcourt_cashier }
* ToDo list
1. Migration

View File

@@ -1655,4 +1655,32 @@ $(function() {
//end is_sub_item false
}
}
$("#add_to_existing_order").on('click', function(e){
$(this).attr('disabled', 'disabled');
e.preventDefault();
type = $("#link_type").val();
$("#oqs_loading_wrapper").show();
var ajax_url = 'addorders/add_to_existing_order';
var table_type = $('#table_type').text();
var table_id = $('#table_id').text();
var customer_id = $('#customer_id').text();
var booking_id = $('#booking_id').text();
var sale_id = $('#sale_id').text();
var order_items = JSON.stringify(get_order_item_rows());
var params = {'order_source': type, 'order_type': "dine_in",
'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id,
'table_id': table_id,
'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" };
$.ajax({
type: "POST",
url: ajax_url,
data: params,
dataType: "json",
success:function(result){
if (result.status) {
window.location.href = "/foodcourt/table/sale/" + sale_id + "/food_court/edit";
}
}
});
});
});

View File

@@ -122,6 +122,9 @@ class Api::OrdersController < Api::ApiController
end
@status, @booking = @order.generate
if params[:order_source] != "app"
@order.process_order_queue(@order.order_id,@order.table_id,@order.source)
end
if @order.table_id.to_i > 0
table = DiningFacility.find(@booking.dining_facility_id)
type = 'order'

View File

@@ -305,5 +305,56 @@ class Foodcourt::AddordersController < BaseFoodcourtController
return from
end
def add_to_existing_order
if params[:booking_id].present? && params[:sale_id].present?
booking = Booking.find(params[:booking_id])
saleobj =Sale.find(params[:sale_id])
order =saleobj.orders[0]
items_arr = []
JSON.parse(params[:order_items]).each { |i|
i["item_instance_code"] = i["item_instance_code"].downcase.to_s
if i["item_instance_code"].include? "ext"
is_extra_time = true
arr_exts = i["item_instance_code"].split("_")
if arr_exts[1].match(/^(\d)+$/)
time = arr_exts[1].to_i*60*i["quantity"].to_i
extra_time = Time.at(time)
end
end
if i["parent_order_item_id"];
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])}
else
items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])}
end
items_arr.push(items)
}
order.items = items_arr
order.new_booking = false
order.booking_id = booking.booking_id
@status, booking = order.generate
order_array = []
items_arr.each do |item|
order_item =order.order_items.where("item_instance_code=?",item[:item_instance_code]).last
saleobj.add_item (order_item)
if !order_item.set_menu_items.nil?
saleobj.add_sub_item(order_item.set_menu_items)
end
end
# Re-compute for add
saleobj.compute(order.source)
saleobj.save
order.save
booking.save
order_array.push(order.order_id)
receipt_no = saleobj.receipt_no
action_by = current_user.name
type = "ADD_TO_EXISTING"
remark = "#{action_by} add to existing order #{order_array} to Receipt No=>#{receipt_no}"
sale_audit = SaleAudit.record_audit_sale(saleobj.sale_id,remark,action_by,type )
end
result = {:status=> @status}
render :json => result.to_json
end
end

View File

@@ -8,6 +8,15 @@ class Foodcourt::FoodCourtController < ApplicationController
end
def index
if params[:sale_id].present?
sale =Sale.find(params[:sale_id])
if sale
@sale_id =sale.sale_id
@booking_id =sale.bookings[0].booking_id
end
end
today = DateTime.now
day = Date.today.wday
@menus = []

View File

@@ -38,19 +38,6 @@ class Foodcourt::SaleEditController < BaseFoodcourtController
# re-calc tax
saleObj = Sale.find(saleitemObj.sale_id)
# booking = Booking.find_by_sale_id(saleitemObj.sale_id)
# booking.booking_orders.each do |bo|
# order = Order.find(bo.order_id)
# order.order_items.each do |o|
# if saleitemObj.product_code == o.item_code
# o.qty = saleitemObj.qty * -1
# o.price = saleitemObj.price * -1
# o.save
# end
# end
# end
# FOr Sale Audit
action_by = current_user.name
if access_code != "null" && current_user.role == "cashier"
@@ -99,26 +86,6 @@ class Foodcourt::SaleEditController < BaseFoodcourtController
ProductCommission.create_product_commission(@newsaleitem, saleitemObj)
end
# def item_edit
# saleitemId = params[:sale_item_id]
# update_qty = params[:update_qty]
# update_price = params[:update_price]
# saleitemObj = SaleItem.find(saleitemId)
# saleitemObj.status = 'void'
# saleitemObj.save
# @newsaleitem = SaleItem.new
# @newsaleitem = saleitemObj.dup
# @newsaleitem.save
# @newsaleitem.qty = update_qty
# @newsaleitem.price = update_price
# @newsaleitem.unit_price = update_price
# @newsaleitem.taxable_price = update_price
# @newsaleitem.is_taxable = 0
# @newsaleitem.remark = 'edit'
# @newsaleitem.product_name = saleitemObj.product_name + " - updated"
# @newsaleitem.save
# end
def item_edit
saleitemId = params[:sale_item_id]
update_qty = params[:update_qty]
@@ -149,20 +116,6 @@ class Foodcourt::SaleEditController < BaseFoodcourtController
saleitemObj.save
# re-calc tax
# saleObj = Sale.find(saleitemObj.sale_id)
# order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id
# order = Order.find(order_id)
# order.order_items.each do |o|
# if saleitemObj.product_code == o.item_code
# o.qty = update_qty
# o.price = update_price
# o.save
# end
# end
sale.compute_by_sale_items(sale.total_discount, nil, order_source)
ProductCommission.edit_product_commission(saleitemObj,sale.shop_code)

View File

@@ -151,63 +151,17 @@
</button>
<br>
<div class="card-header" style="padding: 0.12rem 0.25rem">
<% if type %>
<div class="row clearfix">
<div class="col-md-6 col-lg-6 col-sm-12">
<strong id="order-title" class="font-13">ORDER DETAILS </strong>
</div>
<% if modify_order %>
<% if @table.nil? %>
<div class="col-md-3 col-lg-3 col-sm-3">Table : </div>
<p class="hidden" id="table_id"><%=@table_id%></p>
<p class="hidden" id="table_type"></p>
<p class="hidden" id="table_get_current"></p>
<% else%>
<div class="col-md-3 col-lg-3 col-sm-3">Table : <%=@table.name%></div>
<p class="hidden" id="table_id"><%=@table_id%></p>
<p class="hidden" id="table_type"><%=@table.type%></p>
<p class="hidden" id="table_get_current"><%=@table.get_current_checkout_booking%></p>
<% end%>
<p class="hidden" id="booking_id"><%=@booking_id%></p>
<p class="hidden" id="customer_id"><%=@customer ? @customer.customer_id : '---'%></p>
<p class="hidden" id="sale_id"><%=@sale_id%></p>
<div class="col-md-1 col-lg-1 col-sm-1">
<button type="button" class="btn btn-xs btn-danger waves-effect float-left" id='clear_all'> Clear
</button>
</div>
<% else%>
<p class="hidden" id="table_type"></p>
<div class="col-md-2 col-lg-2 col-sm-2">
</div>
<div class="col-md-3 col-lg-3 col-sm-3">
<button type="button" class="btn btn-xs btn-danger waves-effect float-left" id='clear_all'> Clear
</button>
</div>
<% end%>
</div>
<% else %>
<div class="row ">
<div class="col-md-9 col-lg-9 col-sm-9 ">
<strong id="order-title" class="font-14 p-l-10">ORDER DETAILS </strong>| <span class="font-14">Table-<%=@table.name%></span>
<p class="hidden" id="table_id"><%=@table_id%></p>
<p class="hidden" id="table_type"><%=@table.type%></p>
<strong id="order-title" class="font-14 p-l-10">ORDER DETAILS </strong>
<p class="hidden" id="booking_id"><%=@booking_id%></p>
<p class="hidden" id="customer_id"><%=@customer ? @customer.customer_id : ''%></p>
<p class="hidden" id="table_get_current"><%=@table.get_current_checkout_booking%></p>
<p class="hidden" id="sale_id"><%=@sale_id%></p>
</div>
<div class="col-md-3 col-lg-3 col-sm-3">
<button type="button" class="btn btn-xs btn-danger waves-effect" id='clear_all'>Clear
</button>
</div>
<% end%>
</div>
<div class="card-block">
@@ -237,7 +191,11 @@
</tr>
</table>
<input type="hidden" name="customer_id" id="customer_id" value="CUS-000000000001">
<button type="button" class="btn btn-primary action-btn create col-md-11" id="create_pay_order" disabled="disabled" style="padding-top:4px !important;padding-bottom:4px !important;"><i class="material-icons" style="font-size:34px;width:34px">attach_money</i></button>
<% if @sale_id.nil?%>
<button type="button" class="btn btn-primary action-btn create col-md-11" id="create_pay_order" disabled="disabled" style="padding-top:4px !important;padding-bottom:4px !important;"><i class="material-icons" style="font-size:34px;width:34px">attach_money</i></button>
<% else %>
<button type="button" class="btn btn-primary action-btn create col-md-11" id="add_to_existing_order" disabled="disabled" style="padding-top:4px !important;padding-bottom:4px !important;"><i class="material-icons" style="font-size:34px;width:34px">attach_money</i></button>
<% end %>
</div>
</div>
</div>
@@ -360,7 +318,7 @@
<button type="button" class="btn btn-default " data-dismiss="modal" id="close">Close</button>
</div>
<div class="col-md-6">
<button type="button" class="btn btn-primary add_to_order " data-dismiss="modal" id="add_to_order">Add to Order</button>
<button type="button" class="btn btn-primary add_to_order " data-dismiss="modal" id="add_to_order">Add to Order</button>
</div>
</div>
</div>
@@ -727,4 +685,5 @@ var webview = <%= @webview %>;
showHideNavbar(webview);
<% end %>
});
</script>

View File

@@ -155,6 +155,7 @@
<div class="col-lg-1 col-md-1 col-sm-1">
<!-- Waiter Buttons -->
<button type="button" class="btn btn-block btn-lg bg-default waves-effect" id='back'><i class="material-icons">reply</i>Back</button>
<button type="button" id="add_order" class="btn btn-block bg-blue waves-effect"><%= t("views.btn.add") %> <%= t("views.right_panel.detail.order") %></button>
<button type="button" class="btn btn-danger btn- action-btn" id='cancel_all_void'>Cancel All Void</button>
<button type="button" class="btn btn-block btn-lg bg-blue waves-effect" id='apply'>Apply</button>
</div>
@@ -421,7 +422,7 @@ var access_code = localStorage.getItem("access_code");
}
}
function checkPrice(obj_value,sale_item_id) {
}
$('#add_order').on('click', function () {
window.location.href = '/foodcourt/food_court?sale_id=<%=@saleobj.sale_id %>';
});
</script>

View File

@@ -1,11 +1,11 @@
# application_path="#{File.expand_path("../..", __FILE__)}"
# directory application_path
# #environment ENV.fetch("RAILS_ENV") { "production" }
# environment "production"
# pidfile "#{application_path}/tmp/puma/pid"
# state_path "#{application_path}/tmp/puma/state"
# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
# port ENV.fetch("PORT") { 62158 }
# workers 2
# preload_app!
# threads 1,1
application_path="#{File.expand_path("../..", __FILE__)}"
directory application_path
#environment ENV.fetch("RAILS_ENV") { "production" }
environment "production"
pidfile "#{application_path}/tmp/puma/pid"
state_path "#{application_path}/tmp/puma/state"
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
port ENV.fetch("PORT") { 62158 }
workers 2
preload_app!
threads 1,1

View File

@@ -677,6 +677,7 @@ scope "(:locale)", locale: /en|mm/ do
get '/:addorders/:id' => "addorders#detail"
post '/:addorders/create' => "addorders#create",:as => "addorder_create", :defaults => { :format => 'json' }
post '/:addorders/add_to_existing_order' => "addorders#add_to_existing_order",:as => "add_to_existing_order", :defaults => { :format => 'json' }
get '/addorders/get_item_instance/:id' => "addorders#get_item_instance",:as => "get_item_instance", :defaults => { :format => 'json' }