diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js new file mode 100644 index 00000000..49ef043e --- /dev/null +++ b/app/assets/javascripts/order_reservation.js @@ -0,0 +1,135 @@ + +$(function() { + + $(".nav-item").on("click", function(){ + type = $(this).attr("data-type"); + if (type == "pending") { + $('#accepted').text("Accepted"); + $('#accepted').attr("data-value","accepted"); + }else if(type == "processing"){ + $('#accepted').text("SEND TO KITCHEN"); + $('#accepted').attr("data-value","processed"); + }else if(type == "delivery"){ + $('#accepted').text("READY TO DELIVERY"); + $('#accepted').attr("data-value","delivery"); + }else if(type == "completed"){ + $('#accepted').text("PICK-UP"); + $('#accepted').attr("data-value","completed"); + } + console.log(type) + }); + + jQuery(function(){ + jQuery('.first-1').click(); + }); + + $(".custom-tr").on("click", function(){ + $(".custom-tr").removeClass("tr-active"); + $(this).addClass("tr-active"); + var order_id = $(this).attr("data-id"); + var url = "order_reservation/get_order/"+order_id; + show_order_detail(url); + }); + + //show order list + function show_order_detail(url){ + //Start Ajax + $.ajax({ + type: "GET", + url: url, + data: {}, + dataType: "json", + success: function(data) { + var delivery = data["delivery"] + var items = data["order_items"] + + var item_list = $('.summary-items'); + item_list.empty(); + + for(var i in items) { + var total = items[i].qty*items[i].unit_price; + row = '' + +''+items[i].item_name + +'
'+items[i].qty+ ' X'+items[i].unit_price+'' + +'' + +''+ total +'' + +''; + $('.summary-items').append(row); + } + + $('#sub_total').text(data.total_amount); + $('#delivery_fee').text(delivery.delivery_fee); + $('#total_charges').text(0); + $('#total_tax').text(data.total_tax); + $('#grand_total').text(data.grand_total); + + var address = delivery.address +', ' +delivery.township+", (" +delivery.direction_address+")" + $('#customer_name').text(data.customer_name); + $('#phone').text(data.phone); + $('#address').text(address); + $('#delivery_to').text(delivery.provider); + + $('#ref_no').text(data.transaction_ref); + $('#callback_url').text(data.callback_url); + $('#order_id').text(data.order_reservation_id); + } + }); + //end Ajax + } + + $("#accepted").on("click", function(){ + 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) { + // callback_url(callback,data.message) + swal("Information","Order has been +'data.status'+","success"); + window.location.href = '/origami/order_reservation'; + } + } + }); + }); + + $("#cancel").on("click", function(){ + 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'; + } + } + }); + }); + + function callback_url(url,message){ + $.ajax({ + type: "POST", + url: url, + data: {}, + dataType: "json", + success: function(data) { + + } + }); + } + +}); \ No newline at end of file diff --git a/app/assets/stylesheets/order_reservation.scss b/app/assets/stylesheets/order_reservation.scss new file mode 100644 index 00000000..c33e1f32 --- /dev/null +++ b/app/assets/stylesheets/order_reservation.scss @@ -0,0 +1,88 @@ + .nav-tabs > li.active > a, + .nav-tabs > li.active > a:hover, + .nav-tabs > li.active > a:focus { + border-bottom: 2px solid #2196F3 ; + bottom: 2px ; +} + +.nav-tabs .nav-link { + padding: 0.5286em .33em; +} +.nav-tabs li a.active { + color: #111 !important; + border-bottom: 0px solid #fff !important; +} +.nav-tabs .nav-link.active { + color: #111; + border-color: #fff; +} +.nav-tabs > li > a { + margin-right: 0px; + color:#fff !important; +} + +.nav-tabs > li > a { + border-bottom: 2px solid #2196F3; + bottom: 2px; +} +.nav-tabs.tab-col-teal > li > a:before { + border-bottom: 0px solid #009688; +} +.nav-tabs .nav-item{ + margin-bottom: 2px ; +} +.num{ + color:#fff; + text-align: center; + margin-bottom: -1px !important; +} +.nav-tabs .nav-link.active > p{ + color: #111; + border-color: #fff; +} + +/*Custosm Class*/ +.table .header-td{ + border-top:0px solid !important; + border-bottom: 0px solid !important; + padding:3px 7px !important; + border-top:0px solid !important; + border-bottom: 0px solid !important; +} +.custom-card-block .table td:first-child, +.custom-card-block .table td:nth-child(2), +.custom-card-footer .table td:first-child, +.custom-card-footer .table td:nth-child(2){ + border-top:0px solid !important; +} + +.custom-card-footer .footer-td , +.grand-card-footer .footer-td { + border-top:0px solid !important; + border-bottom:0px solid !important; + font-weight: bold; + padding:6px 10px; +} +.custom-card-header{ + border-bottom: 1px solid #F8BBD0 !important; + padding:13px 5px !important; +} +.custom-card-footer{ + border-top: 1px solid #F8BBD0 !important; +} +.custom-card-block, +.grand-card-footer, +.custom-card-footer{ + padding :5px !important; +} +.custom-table{ + background-color:#F3E5F5; +} +.custom-table tbody tr td, +.custom-table tbody tr th{ + border-top: 1px solid #FFEBEE; + border-bottom: 1px solid #FFEBEE; +} +.tr-active{ + background-color : #FFCDD2; +} \ No newline at end of file diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 4abab9c8..8e23d2c9 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -111,7 +111,8 @@ class Origami::AddordersController < BaseOrigamiController end items_arr.push(items) } - +puts items_arr.to_json + puts "sssssssssssssssssssssss" # begin # if params[:order_source] == "quick_service" # customer_id = "CUS-000000000002" # for no customer id from mobile diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index db56d882..a90e755b 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -1,12 +1,40 @@ class Origami::OrderReservationController < BaseOrigamiController def index - @webview = check_mobile - @shop = Shop::ShopDetail + @order = OrderReservation.all + end + def update + @id = params[:order_id] + @status = params[:status] + @order = OrderReservation.find(@id) + + status = true + + if status + if @status == "processed" + OrderReservation.create_doemal_order(@order) + else + if @status == "cancel" + result = {:status=> true, :message => "cancelled" } + else + result = {:status=> true, :message => "accepted" } + end + render :json => result.to_json + end + + else + result = {:status=> false, :message => "Order not accepted !" } + render :json => result.to_json + end + end + + def get_order + if (params[:id]) + @order = OrderReservation.find(params[:id]) + return @order + end end - - end diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index 0be5e4c8..d9a60a1f 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -40,6 +40,55 @@ class OrderReservation < ApplicationRecord end end + def self.create_doemal_order(order) + + 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) + } + + 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.is_extra_time = is_extra_time + @order.extra_time = extra_time + + @status, @booking = @order.generate + + # Order.send_customer_view(@booking) + + + if @status && @booking + + @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + # for second display + + result = {:status=> @status, :data => @sale } + render :json => result.to_json + end + + end + private def generate_custom_id self.order_reservation_id = SeedGenerator.generate_id(self.class.name, "ODRS") diff --git a/app/views/origami/order_reservation/_order_item.json.jbuilder b/app/views/origami/order_reservation/_order_item.json.jbuilder new file mode 100644 index 00000000..794da464 --- /dev/null +++ b/app/views/origami/order_reservation/_order_item.json.jbuilder @@ -0,0 +1,15 @@ +json.id item.order_reservation_items_id +json.order_id item.order_reservation_id +json.item_status item.item_status +json.item_code item.item_code +json.item_instance_code item.item_instance_code +json.item_name item.item_name +json.alt_name item.alt_name +json.set_menu_items item.set_menu_items +json.account_id item.account_id +json.qty item.qty +json.unit_price item.unit_price +json.price item.price +json.remark item.remark +json.options item.options +json.taxable item.taxable \ No newline at end of file diff --git a/app/views/origami/order_reservation/get_order.json.jbuilder b/app/views/origami/order_reservation/get_order.json.jbuilder new file mode 100644 index 00000000..5fdd5293 --- /dev/null +++ b/app/views/origami/order_reservation/get_order.json.jbuilder @@ -0,0 +1,25 @@ +if @order + + json.(@order, :order_reservation_id,:order_reservation_type,:customer_id, + :requested_time,:callback_url,:transaction_ref,:item_count,:total_customer,:payment_type, + :payment_status,:payment_ref,:total_amount,:total_tax, + :discount_amount,:grand_total,:status,:order_remark, + :reservation_remark) + @delivery = Delivery.find_by_order_reservation_id(@order.order_reservation_id) + if @delivery + json.delivery do |json| + # json.(@article.author, :id, :name) + json.(@delivery, :provider,:delivery_type,:township, + :address,:direction_address,:delivery_fee,:remark) + end + end + if @order.order_reservation_items + json.order_items @order.order_reservation_items do |item| + json.partial! 'origami/order_reservation/order_item', item: item + end + end + @customer = Customer.find(@order.customer_id) + + json.customer_name @customer.name + json.phone @customer.contact_no +end diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb index 42628dd9..15af828f 100644 --- a/app/views/origami/order_reservation/index.html.erb +++ b/app/views/origami/order_reservation/index.html.erb @@ -1,17 +1,19 @@ +<%= stylesheet_link_tag 'order_reservation', media: 'all', 'data-turbolinks-track': 'reload' %> +<%= javascript_include_tag 'order_reservation', 'data-turbolinks-track': 'reload' %>
@@ -22,62 +24,26 @@ @@ -90,35 +56,26 @@ @@ -130,89 +87,57 @@
-
+
@@ -227,7 +152,8 @@
- @@ -236,50 +162,15 @@
-
No.11 + + No.11 (DELIVERY) 0065 4321
+
- +
@@ -288,28 +179,28 @@ - - + - + - + - +
@@ -321,14 +212,27 @@ GRAND TOTAL - 1400.00 + 0.00 - + - + + @@ -353,119 +257,41 @@ NAME
- DAW AYE AYE + PHONE
- 09 8765 4321 098 + ADDRESS
- No. (12), 3rd floor, zay kyee Street, kyi myin dine - infront of Nya Zay Main Entrance + - DELEVER TO
- HOME + DELEVERY
+ - +
- \ No newline at end of file + \ No newline at end of file diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 7aa7b6ba..bd889f51 100755 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -37,7 +37,7 @@ Rails.application.config.assets.precompile += %w( CRM.js ) # --- Image Uploader ---- Rails.application.config.assets.precompile += %w( fileinput.min.js ) -# --- Customer/ Customer - Crm ---- +# --- Add order/ Add order - Crm ---- Rails.application.config.assets.precompile += %w( addorder.css ) Rails.application.config.assets.precompile += %w( addorder.js ) @@ -53,4 +53,9 @@ Rails.application.config.assets.precompile += %w( sx-sidebar.css ) Rails.application.config.assets.precompile += %w( inventory_definitions.css ) Rails.application.config.assets.precompile += %w( inventory.js ) +# --- Customer/ Customer - Crm ---- +Rails.application.config.assets.precompile += %w( order_reservation.css ) +Rails.application.config.assets.precompile += %w( order_reservation.js ) + + diff --git a/config/routes.rb b/config/routes.rb index e5421453..a4d61642 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -265,6 +265,9 @@ scope "(:locale)", locale: /en|mm/ do #order and reservation resources :order_reservation + 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' } + end #--------- Waiter/Ordering Station ------------#