order reservation

This commit is contained in:
phyusin
2018-04-12 11:01:13 +06:30
parent c1a6ff7230
commit 49ebc6c0dc
6 changed files with 122 additions and 73 deletions

View File

@@ -47,7 +47,13 @@ $(function() {
item_list.empty(); item_list.empty();
for(var i in items) { for(var i in items) {
var total = items[i].qty*items[i].unit_price; var item_price = 0;
if(items[i].price > 0){
item_price = items[i].price;
}else{
item_price = items[i].unit_price;
}
var total = items[i].qty * item_price;
row = '<tr>' row = '<tr>'
+'<td width ="70%" class="body-td align-left">'+items[i].item_name +'<td width ="70%" class="body-td align-left">'+items[i].item_name
+' <br><span class="font-13">'+items[i].qty+ '<span class="col-blue"> <b>X</b>'+items[i].unit_price+'</span></span>' +' <br><span class="font-13">'+items[i].qty+ '<span class="col-blue"> <b>X</b>'+items[i].unit_price+'</span></span>'
@@ -80,54 +86,64 @@ $(function() {
$("#accepted").on("click", function(){ $("#accepted").on("click", function(){
var status = $(this).attr("data-value"); var status = $(this).attr("data-value");
var order_id = $('#order_id').text(); var order_id = $('#order_id').text();
var url = 'order_reservation/update'; var ref_no = $('#ref_no').text();
var callback = $('#callback_url').text(); var callback = $('#callback_url').text();
$.ajax({ callback_url(callback,ref_no,order_id,status);
type: "POST",
url: url,
data: {'order_id': order_id, 'status': status},
dataType: "json",
success: function(data) {
console.log(data)
if (data.status) {
// callback_url(callback,data.message)
swal("Information","Order has been +'data.status'+","success");
window.location.href = '/origami/order_reservation';
}
}
});
}); });
$("#cancel").on("click", function(){ $("#cancel").on("click", function(){
var status = $(this).attr("data-value"); var status = $(this).attr("data-value");
var order_id = $('#order_id').text(); var order_id = $('#order_id').text();
var url = 'order_reservation/update';
var callback = $('#callback_url').text(); var callback = $('#callback_url').text();
var ref_no = $('#ref_no').text();
callback_url(callback,ref_no,order_id,status);
});
function callback_url(callback,ref_no,order_id,status){
var url = 'order_reservation/update';
var post_url = "order_reservation/send_status";
$.ajax({
type: "POST",
url: post_url,
data: {url: callback, ref_no: ref_no, status: status},
dataType: "json",
success: function(data) {
if(data.status){
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: url, url: url,
data: {'order_id': order_id, 'status': status}, data: {'order_id': order_id, 'status': status},
dataType: "json", dataType: "json",
success: function(data) { success: function(data) {
console.log(data) console.log(data);
if (data.status) { if (data.status) {
console.log(data) swal({
// callback_url(callback,data.message) title: 'Information',
swal("Information","Order has been +'data.status'+","warning"); text: "Order has been "+data.status,
type: 'success',
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
window.location.href = '/origami/order_reservation'; window.location.href = '/origami/order_reservation';
});
} }
} }
}); });
}else{
swal({
title: 'Oops',
text: data.message.toString(),
type: 'error',
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
window.location.href = '/origami/order_reservation';
}); });
}
function callback_url(url,message){
$.ajax({
type: "POST",
url: url,
data: {},
dataType: "json",
success: function(data) {
} }
}); });
} }

View File

@@ -36,5 +36,37 @@ class Origami::OrderReservationController < BaseOrigamiController
end end
end end
def send_status
base_url = "http://192.168.1.186:3002"
post_url = base_url + params[:url]
# status = params[:status]
if params[:status] == "cancel"
status = "rejected"
else
status = params[:status]
end
begin
response = HTTParty.post(post_url,
:body => { id: params[:ref_no], status: status}.to_json,
:headers => {
'Authorization' => 'Token token=3T-tnlYtFJ-5Z1vY6XQqxQ',
'Content-Type' => 'application/json',
'Accept' => 'application/json; version=3'
}, :timeout => 10
)
rescue Net::OpenTimeout
response = { status: false }
rescue OpenURI::HTTPError
response = { status: false}
rescue SocketError
response = { status: false}
end
Rails.logger.debug "Get Doemal Status "
Rails.logger.debug response.to_json
render :json => response
end
end end

View File

@@ -354,6 +354,11 @@ class Customer < ApplicationRecord
#new customer for doemal #new customer for doemal
def self.addCustomer(params) def self.addCustomer(params)
if params[:gender] == "female"
gender = "Female"
else
gender = "Male"
end
customer = Customer.new customer = Customer.new
customer.name = params[:name] customer.name = params[:name]
customer.email = params[:email] customer.email = params[:email]

View File

@@ -49,7 +49,6 @@ class OrderReservation < ApplicationRecord
end end
def self.create_doemal_order(order) def self.create_doemal_order(order)
is_extra_time = false is_extra_time = false
extra_time = '' extra_time = ''
@@ -57,7 +56,6 @@ class OrderReservation < ApplicationRecord
count = 1 count = 1
order.order_reservation_items.each { |i| order.order_reservation_items.each { |i|
i.item_instance_code = i.item_instance_code.downcase.to_s i.item_instance_code = i.item_instance_code.downcase.to_s
items = {"order_item_id": count,"item_instance_code": i.item_instance_code,"quantity": i.qty,"options": []} items = {"order_item_id": count,"item_instance_code": i.item_instance_code,"quantity": i.qty,"options": []}
count += 1 count += 1
items_arr.push(items) items_arr.push(items)
@@ -84,8 +82,6 @@ class OrderReservation < ApplicationRecord
@status, @booking = @order.generate @status, @booking = @order.generate
# Order.send_customer_view(@booking) # Order.send_customer_view(@booking)
if @status && @booking if @status && @booking
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee) @status, @sale = Sale.request_bill(@order,current_user,current_login_employee)

View File

@@ -285,10 +285,10 @@
</div> </div>
</div> </div>
</div> </div>
<p id="ref_no"></p> <p id="ref_no" class="hidden"></p>
<p id="callback_url"></p> <p id="callback_url" class="hidden"></p>
<p id="order_id"></p> <p id="order_id" class="hidden"></p>
<p id="status"></p> <p id="status" class="hidden"></p>
<script type="text/javascript"> <script type="text/javascript">
jQuery(function(){ jQuery(function(){
jQuery('.first-1').click(); jQuery('.first-1').click();

View File

@@ -268,7 +268,7 @@ scope "(:locale)", locale: /en|mm/ do
resources :order_reservation resources :order_reservation
get 'order_reservation/get_order/:id' => "order_reservation#get_order",:as => "get_order", :defaults => { :format => 'json' } get 'order_reservation/get_order/:id' => "order_reservation#get_order",:as => "get_order", :defaults => { :format => 'json' }
post 'order_reservation/update', to: "order_reservation#update" , :defaults => { :format => 'json' } post 'order_reservation/update', to: "order_reservation#update" , :defaults => { :format => 'json' }
post 'order_reservation/send_status', to: "order_reservation#send_status"
end end
#--------- Waiter/Ordering Station ------------# #--------- Waiter/Ordering Station ------------#