diff --git a/app/views/origami/addorders/show.html.erb b/app/assets/javascripts/addorder.js
similarity index 51%
rename from app/views/origami/addorders/show.html.erb
rename to app/assets/javascripts/addorder.js
index 1cc58af9..b9219c52 100644
--- a/app/views/origami/addorders/show.html.erb
+++ b/app/assets/javascripts/addorder.js
@@ -1,146 +1,3 @@
-
-
-
- <% @menu.each do |menu| %>
-
- <% end %>
-
-
-
-
-
-
-
-
-
-
-
- | # |
- Items |
- QTY |
- Price |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- <%= image_tag "logo.png" ,width: '', height: '', :style => '' %>
-
-
-
Quantity
-
-
-
-
-
-
- Oh !Have not attribute for this item Please select another attribute .
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+});
\ No newline at end of file
diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss
new file mode 100644
index 00000000..01e01e15
--- /dev/null
+++ b/app/assets/stylesheets/addorder.scss
@@ -0,0 +1,102 @@
+@import "bootstrap";
+@import "font-awesome";
+@import "theme";
+@import "jquery-ui";
+@import "bootstrap-datepicker3";
+
+.card-head{
+ height: 40px;
+ background-color: #54A5AF;
+ padding:5px;
+ color :#fff;
+ }
+ .card-block {
+ padding: 0.3rem !important;
+ }
+ @media (min-width: 34em) {
+ .card-columns {
+ -webkit-column-count: 2;
+ -moz-column-count: 2;
+ column-count: 2;
+ }
+ }
+
+ @media (min-width: 48em) {
+ .card-columns {
+ -webkit-column-count: 3;
+ -moz-column-count: 3;
+ column-count: 3;
+ }
+ }
+
+ @media (min-width: 62em) {
+ .card-columns {
+ -webkit-column-count: 4;
+ -moz-column-count: 4;
+ column-count: 4;
+ }
+ }
+
+ @media (min-width: 75em) {
+ .card-columns {
+ -webkit-column-count: 4;
+ -moz-column-count: 4;
+ column-count: 4;
+ }
+ }
+
+.nav-tabs .nav-item {
+ border-bottom: 1px solid #fff;
+ border-left: 1px solid #54A5AF;
+ border-right: 1px solid #54A5AF;
+}
+.nav > li > a{
+ color:#54A5AF;
+}
+.nav-tabs {
+ background-color: #eeeeee;
+}
+.nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link {
+ background-color: #fff;
+ border-left: 6px solid #111;
+ color:#54A5AF;
+ font-weight: bold;
+ border-color: #fff #fff #fff #54A5AF;
+}
+
+.modal-dialog {
+ left:auto;
+ right: auto;
+ width: 100%;
+ padding-top: 200px;
+
+}
+.selected-attribute {
+ color: #fff !important;
+ background-color: green !important;
+}
+.selected-option {
+ color: #fff !important;
+ background-color: green !important;
+}
+.attribute_btn {
+ white-space: normal !important;
+ height: 40px;
+ /*width: 80px;*/
+ margin-bottom: 5px;
+ margin-right: 5px;
+}
+
+.option_btn {
+ white-space: normal !important;
+ height: 40px;
+ /*width: 80px;*/
+ margin-bottom: 5px;
+ margin-right: 5px;
+}
+#logo{
+ margin: auto;
+ width: 50%;
+ border: 1px solid #54A5AF;
+ padding: 10px;
+}
\ No newline at end of file
diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb
index 3a95dc6c..23a7bc26 100644
--- a/app/controllers/origami/addorders_controller.rb
+++ b/app/controllers/origami/addorders_controller.rb
@@ -1,5 +1,5 @@
class Origami::AddordersController < BaseOrigamiController
- before_action :set_dining, only: [:show]
+ # before_action :set_dining, only: [:detail]
def index
@tables = Table.all.active.order('zone_id asc').group("zone_id")
@@ -8,16 +8,134 @@ class Origami::AddordersController < BaseOrigamiController
@all_room = Room.all.active.order('status desc')
end
- def show
+ def detail
@menu = MenuCategory.all
@table_id = params[:id]
- @table_type = DiningFacility.find(@table_id).type
+ @table = DiningFacility.find(@table_id)
+ @booking = @table.get_booking
+ if @booking
+ @booking_id = @booking.booking_id
+ @order_items = Array.new
+ @booking.booking_orders.each do |booking_order|
+ order = Order.find(booking_order.order_id)
+ if (order.status == "new")
+ @obj_order = order
+ @customer = order.customer
+ @date = order.created_at
+ order.order_items.each do |item|
+ @order_items.push(item)
+ end
+ end
+ end
+ else
+ @booking = nil
+ end
+
+
+ end
+
+ def create
+ Rails.logger.debug "Order Source - " + params[:order_source].to_s
+ Rails.logger.debug "Table ID - " + params[:table_id].to_s
+ items_arr = []
+ JSON.parse(params[:order_items]).each { |i|
+ 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]
+ @order.order_type = params[:order_type]
+ @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
+ @order.items = items_arr
+ @order.guest = params[:guest_info]
+ @order.table_id = params[:table_id] # this is dining facilities's id
+ @order.new_booking = true
+ @order.employee_name = current_login_employee.name
+ #Create Table Booking or Room Booking
+ if !params["booking_id"].nil?
+ # check booking id is already completed.
+ booking = Booking.find(params[:booking_id])
+ if booking
+ if booking.dining_facility_id.to_i == params[:table_id].to_i && booking.booking_status != 'moved'
+ if !booking.sale_id.nil?
+ sale_status = check_order_with_booking(booking)
+ # puts "WWwwWWWWWWww"
+ # puts sale_status
+ if sale_status
+ return return_json_status_with_code(400, "bill requested")
+ end
+ else
+ @order.new_booking = false
+ @order.booking_id = params[:booking_id]
+ end
+ else
+ sale_status = check_order_with_table(params[:table_id])
+ # puts "OOOOOOOOO"
+ # puts sale_status
+ if sale_status
+ return return_json_status_with_code(400, "bill requested")
+ end
+ end
+ end #booking exists
+ else
+ sale_status = check_order_with_table(params[:table_id])
+ # puts "MMMMMMMM"
+ # puts sale_status
+ if sale_status
+ # return false , @message = "bill requested"
+ return return_json_status_with_code(400, "bill requested")
+ end
+ end
+
+ @status, @booking = @order.generate
+
+ end
+
+ # render json for http status code
+ def return_json_status_with_code(code, msg)
+ render status: code, json: {
+ message: msg,
+ booking_id: booking_id
+ }.to_json
+ end
+
+ def check_order_with_table(table_id)
+ table = DiningFacility.find(table_id)
+ if table
+ booking = table.get_current_booking
+ # puts booking
+ if booking
+ if !booking.sale_id.nil?
+ if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
+ @order.new_booking = true
+ return false
+ end
+ else
+ @order.new_booking = false
+ @order.booking_id = booking.booking_id
+ return false
+ end
+ end
+ end
+ end
+
+ # this can always true
+ def check_order_with_booking(booking)
+ if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new"
+ @order.new_booking = true
+ return false
+ else
+ @order.new_booking = false
+ @order.booking_id = params[:booking_id]
+ return false
+ end
end
private
- def set_dining
- @dining = DiningFacility.find(params[:id])
- end
+ # def set_dining
+ # @dining = DiningFacility.find(params[:id])
+ # end
end
diff --git a/app/models/order.rb b/app/models/order.rb
index 0ef19729..fc9b1cf9 100644
--- a/app/models/order.rb
+++ b/app/models/order.rb
@@ -134,6 +134,8 @@ class Order < ApplicationRecord
def re_order_items(form_items) #reorder inputs items as parents and child
parent_id = Array.new
parents = Array.new
+ puts form_items
+ puts "hhhhh"
parents_and_children_items = Array.new
new_items_list = Array.new
diff --git a/app/views/origami/addorders/create.json.jbuilder b/app/views/origami/addorders/create.json.jbuilder
new file mode 100644
index 00000000..175e6e94
--- /dev/null
+++ b/app/views/origami/addorders/create.json.jbuilder
@@ -0,0 +1,15 @@
+if @status == true
+ json.status :success
+ json.id @order.id
+ json.booking_id @booking.id
+ json.order_items do
+ json.array! @order.order_items, :item_code, :item_name, :qty, :options, :remark
+ end
+else
+ json.status :error
+ if @error_messages
+ json.error_messages @error_messages
+ else
+ json.error_messages @order.errors
+ end
+end
diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb
new file mode 100644
index 00000000..a8534f94
--- /dev/null
+++ b/app/views/origami/addorders/detail.html.erb
@@ -0,0 +1,147 @@
+<%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %>
+<%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %>
+
+
+
+ <% @menu.each do |menu| %>
+
+ <% end %>
+
+
+
+
+
+
+
+
+
+
+
+ | # |
+ Items |
+ QTY |
+ Price |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
<%= image_tag "logo.png" ,width: '', height: '', :id => 'logo' %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Attributes
+
+
+
+
Options
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb
index adb297d1..bcb83367 100644
--- a/config/initializers/assets.rb
+++ b/config/initializers/assets.rb
@@ -32,3 +32,7 @@ Rails.application.config.assets.precompile += %w( jquery-confirm.js )
# --- Image Uploader ----
Rails.application.config.assets.precompile += %w( fileinput.min.js )
+
+# --- Customer/ Customer - Crm ----
+Rails.application.config.assets.precompile += %w( addorder.css )
+Rails.application.config.assets.precompile += %w( addorder.js )
diff --git a/config/routes.rb b/config/routes.rb
index b5af4fe2..64341edf 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -171,7 +171,9 @@ Rails.application.routes.draw do
post '/:sale_id/get_customer' => "customers#get_customer"
- resources :addorders
+ get '/:addorders/:id' => "addorders#detail"
+ post '/:addorders/create' => "addorders#create", :defaults => { :format => 'json' }
+
resources :commissions
resources :commissioners
resources :in_juties