diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js
index 49ef043e..8f4155ba 100644
--- a/app/assets/javascripts/order_reservation.js
+++ b/app/assets/javascripts/order_reservation.js
@@ -47,7 +47,13 @@ $(function() {
item_list.empty();
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 = '
'
+''+items[i].item_name
+' '+items[i].qty+ ' X'+items[i].unit_price+''
@@ -78,56 +84,66 @@ $(function() {
}
$("#accepted").on("click", function(){
- var status = $(this).attr("data-value");
+ var status = $(this).attr("data-value");
var order_id = $('#order_id').text();
- var url = 'order_reservation/update';
+ var ref_no = $('#ref_no').text();
var callback = $('#callback_url').text();
- $.ajax({
- 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';
- }
- }
- });
+ callback_url(callback,ref_no,order_id,status);
});
$("#cancel").on("click", function(){
- var status = $(this).attr("data-value");
+ var status = $(this).attr("data-value");
var order_id = $('#order_id').text();
- var url = 'order_reservation/update';
var callback = $('#callback_url').text();
- $.ajax({
- type: "POST",
- url: url,
- data: {'order_id': order_id, 'status': status},
- dataType: "json",
- success: function(data) {
- console.log(data)
- if (data.status) {
- console.log(data)
- // callback_url(callback,data.message)
- swal("Information","Order has been +'data.status'+","warning");
- window.location.href = '/origami/order_reservation';
- }
- }
- });
+ var ref_no = $('#ref_no').text();
+ callback_url(callback,ref_no,order_id,status);
});
- function callback_url(url,message){
+ 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: url,
- data: {},
+ url: post_url,
+ data: {url: callback, ref_no: ref_no, status: status},
dataType: "json",
success: function(data) {
-
+ if(data.status){
+ $.ajax({
+ type: "POST",
+ url: url,
+ data: {'order_id': order_id, 'status': status},
+ dataType: "json",
+ success: function(data) {
+ console.log(data);
+ if (data.status) {
+ swal({
+ title: 'Information',
+ text: "Order has been "+data.status,
+ type: 'success',
+ html: true,
+ closeOnConfirm: false,
+ closeOnCancel: false,
+ allowOutsideClick: false
+ }, function () {
+ 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';
+ });
+ }
}
});
}
diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb
index a90e755b..3c3bfd0b 100644
--- a/app/controllers/origami/order_reservation_controller.rb
+++ b/app/controllers/origami/order_reservation_controller.rb
@@ -36,5 +36,37 @@ class Origami::OrderReservationController < BaseOrigamiController
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
diff --git a/app/models/customer.rb b/app/models/customer.rb
index 3eb51a24..c380f24b 100755
--- a/app/models/customer.rb
+++ b/app/models/customer.rb
@@ -354,6 +354,11 @@ class Customer < ApplicationRecord
#new customer for doemal
def self.addCustomer(params)
+ if params[:gender] == "female"
+ gender = "Female"
+ else
+ gender = "Male"
+ end
customer = Customer.new
customer.name = params[:name]
customer.email = params[:email]
diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb
index e23f852e..2d0e53bb 100644
--- a/app/models/order_reservation.rb
+++ b/app/models/order_reservation.rb
@@ -49,43 +49,39 @@ class OrderReservation < ApplicationRecord
end
def self.create_doemal_order(order)
-
- is_extra_time = false
- extra_time = ''
+ is_extra_time = false
+ extra_time = ''
- items_arr = []
- count = 1
- order.order_reservation_items.each { |i|
- 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": []}
- count += 1
- items_arr.push(items)
- }
+ items_arr = []
+ count = 1
+ order.order_reservation_items.each { |i|
+ 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": []}
+ count += 1
+ items_arr.push(items)
+ }
- puts items_arr.to_json
- puts "sssssssssssssssssssssss"
- customer_id = order.customer_id
+ puts items_arr.to_json
+ puts "sssssssssssssssssssssss"
+ customer_id = order.customer_id
- @order = Order.new
- @order.source = "doemal_order"
- @order.order_type = "delivery"
- @order.customer_id = customer_id
- @order.items = items_arr
- @order.guest = ''
- @order.table_id = nil # this is dining facilities's id
- @order.new_booking = true
- @order.waiters = current_login_employee.name
- @order.employee_name = current_login_employee.name
+ @order = Order.new
+ @order.source = "doemal_order"
+ @order.order_type = "delivery"
+ @order.customer_id = customer_id
+ @order.items = items_arr
+ @order.guest = ''
+ @order.table_id = nil # this is dining facilities's id
+ @order.new_booking = true
+ @order.waiters = current_login_employee.name
+ @order.employee_name = current_login_employee.name
- @order.is_extra_time = is_extra_time
- @order.extra_time = extra_time
+ @order.is_extra_time = is_extra_time
+ @order.extra_time = extra_time
- @status, @booking = @order.generate
+ @status, @booking = @order.generate
# Order.send_customer_view(@booking)
-
-
if @status && @booking
@status, @sale = Sale.request_bill(@order,current_user,current_login_employee)
diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb
index 15af828f..5bec897f 100644
--- a/app/views/origami/order_reservation/index.html.erb
+++ b/app/views/origami/order_reservation/index.html.erb
@@ -285,10 +285,10 @@
-
-
-
-
+
+
+
+
|