sync data record
This commit is contained in:
10
app/controllers/api/sync_controller.rb
Normal file
10
app/controllers/api/sync_controller.rb
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
class Api::SyncController < Api::ApiController
|
||||||
|
|
||||||
|
def sync_data
|
||||||
|
# Here comes to save the sync records.
|
||||||
|
Order.sync_order_records(params[:orders])
|
||||||
|
OrderItem.sync_order_item_records(params[:order_items])
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -70,4 +70,47 @@ authorize_resource :class => false
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sync_data
|
||||||
|
@orders, @order_items = Booking.get_sync_data(params[:sale_id])
|
||||||
|
|
||||||
|
# Here comes to call the sync api
|
||||||
|
url = "http://192.168.1.187:3000/api/sync_records"
|
||||||
|
|
||||||
|
begin
|
||||||
|
@result = HTTParty.post(url.to_str,
|
||||||
|
:body => { :orders => @orders,
|
||||||
|
:order_items => @order_items
|
||||||
|
}.to_json,
|
||||||
|
:headers => {
|
||||||
|
'Content-Type' => 'application/json',
|
||||||
|
'Authorization' => 'bearer 88fa8a47ba8b52a43cbc'
|
||||||
|
}, :timeout => 10,
|
||||||
|
:verify_ssl => OpenSSL::SSL::VERIFY_NONE,
|
||||||
|
:verify => false )
|
||||||
|
|
||||||
|
rescue HTTParty::Error
|
||||||
|
response = { status: false, message: "Can't open membership server "}
|
||||||
|
rescue Net::OpenTimeout
|
||||||
|
response = { status: false, message: "Can't open membership server "}
|
||||||
|
rescue OpenURI::HTTPError
|
||||||
|
puts "Fire in here"
|
||||||
|
response = { status: false, message: "Can't open membership server "}
|
||||||
|
rescue SocketError
|
||||||
|
response = { status: false, message: "Can't open server "}
|
||||||
|
rescue Errno::EHOSTDOWN
|
||||||
|
response = { status: false, message: "Can't open server "}
|
||||||
|
rescue Errno::ECONNREFUSED, Timeout::Error, Errno::EINVAL, Errno::ECONNRESET, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError
|
||||||
|
response = { status: false, message: "Can't open membership server"}
|
||||||
|
end
|
||||||
|
|
||||||
|
puts url
|
||||||
|
puts response
|
||||||
|
puts '########################'
|
||||||
|
puts @result
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to '/en/reports/receipt_no/', notice: 'Sync Record Completed.'}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -60,6 +60,20 @@ class Booking < ApplicationRecord
|
|||||||
.order("sale_id DESC")
|
.order("sale_id DESC")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.get_sync_data(sale_id)
|
||||||
|
@orders = Order.select('orders.*')
|
||||||
|
.joins('left join booking_orders on booking_orders.order_id = orders.order_id')
|
||||||
|
.joins('left join bookings on bookings.booking_id = booking_orders.booking_id')
|
||||||
|
.where('bookings.sale_id=?', sale_id)
|
||||||
|
|
||||||
|
@order_items = OrderItem.select('order_items.*')
|
||||||
|
.joins('left join booking_orders on booking_orders.order_id = order_items.order_id')
|
||||||
|
.joins('left join bookings on bookings.booking_id = booking_orders.booking_id')
|
||||||
|
.where('bookings.sale_id=?', sale_id)
|
||||||
|
|
||||||
|
return @orders, @order_items
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def generate_custom_id
|
def generate_custom_id
|
||||||
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
|
self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI")
|
||||||
|
|||||||
@@ -560,4 +560,25 @@ class Order < ApplicationRecord
|
|||||||
self.date = Time.now.utc
|
self.date = Time.now.utc
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.sync_order_records(orders)
|
||||||
|
if !orders.nil?
|
||||||
|
orders.each do |o|
|
||||||
|
unless Order.exists?(o.order_id)
|
||||||
|
order = Order.new()
|
||||||
|
order.order_id = o.order_id
|
||||||
|
order.date = o.date
|
||||||
|
order.source = o.source
|
||||||
|
order.order_type = o.order_type
|
||||||
|
order.customer_id = o.customer_id
|
||||||
|
order.item_count = o.item_count
|
||||||
|
order.quantity_count = o.quantity_count
|
||||||
|
order.status = o.status
|
||||||
|
order.waiters = o.waiters
|
||||||
|
order.guest_info = o.guest_info
|
||||||
|
order.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -65,6 +65,33 @@ class OrderItem < ApplicationRecord
|
|||||||
return order_details
|
return order_details
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.sync_order_item_records(order_items)
|
||||||
|
if !order_items.nil?
|
||||||
|
order_items.each do |item|
|
||||||
|
unless OrderItem.exists?(item.order_items_id)
|
||||||
|
order_item = OrderItem.new()
|
||||||
|
order_item.order_items_id = item.order_items_id
|
||||||
|
order_item.order_id = item.order_id
|
||||||
|
order_item.order_item_status = item.order_item_status
|
||||||
|
order_item.item_order_by = item.item_order_by
|
||||||
|
order_item.item_code = item.item_code
|
||||||
|
order_item.item_instance_code = item.item_instance_code
|
||||||
|
order_item.item_name = item.item_name
|
||||||
|
order_item.alt_name = item.alt_name
|
||||||
|
order_item.account_id = item.account_id
|
||||||
|
order_item.qty = item.qty
|
||||||
|
order_item.price = item.price
|
||||||
|
order_item.remark = item.remark
|
||||||
|
order_item.options = item.options
|
||||||
|
order_item.set_menu_items = item.set_menu_items
|
||||||
|
order_item.taxable = item.taxable
|
||||||
|
order_item.completed_by = item.completed_by
|
||||||
|
order_item.save
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def generate_custom_id
|
def generate_custom_id
|
||||||
self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI")
|
self.order_items_id = SeedGenerator.generate_id(self.class.name, "ODI")
|
||||||
|
|||||||
2
app/views/api/sync/sync_data.json.jbuilder
Normal file
2
app/views/api/sync/sync_data.json.jbuilder
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
json.status = true
|
||||||
|
json.message = 'Data successfully Sync'
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
<th><%= t("views.right_panel.detail.grand_total") %> +<br/>
|
<th><%= t("views.right_panel.detail.grand_total") %> +<br/>
|
||||||
<%= t("views.right_panel.detail.rnd_adj_sh") %>
|
<%= t("views.right_panel.detail.rnd_adj_sh") %>
|
||||||
</th>
|
</th>
|
||||||
|
<th><%= "actions" %></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -158,6 +159,7 @@
|
|||||||
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%end%>
|
<%end%>
|
||||||
|
|
||||||
<% if result.old_grand_total.nil? %>
|
<% if result.old_grand_total.nil? %>
|
||||||
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></td>
|
||||||
<%else%>
|
<%else%>
|
||||||
@@ -166,6 +168,11 @@
|
|||||||
|
|
||||||
<td><%= result.rounding_adjustment.to_f rescue '-' %></td>
|
<td><%= result.rounding_adjustment.to_f rescue '-' %></td>
|
||||||
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %></td>
|
<td><%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %></td>
|
||||||
|
<td>
|
||||||
|
<!-- ############### Need to Check SyncStatus ############# -->
|
||||||
|
<%= link_to "Sync", reports_sync_data_path(:sale_id => result.sale_id), class:"btn btn-info wave-effects" %>
|
||||||
|
<!-- ###################################################### -->
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
<tr style="border-top:4px double #666;">
|
<tr style="border-top:4px double #666;">
|
||||||
@@ -218,6 +225,7 @@
|
|||||||
|
|
||||||
<td><b><%= rounding_adj.to_f rescue '-' %></b></td>
|
<td><b><%= rounding_adj.to_f rescue '-' %></b></td>
|
||||||
<td><b><%= number_with_precision(grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
<td><b><%= number_with_precision(grand_total.to_f, precision: precision.to_i ,delimiter: delimiter) rescue '-' %></b></td>
|
||||||
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td colspan="3"> </td>
|
<td colspan="3"> </td>
|
||||||
@@ -232,6 +240,8 @@
|
|||||||
<td><%= t("views.right_panel.detail.grand_total") %> +<br/>
|
<td><%= t("views.right_panel.detail.grand_total") %> +<br/>
|
||||||
<%= t("views.right_panel.detail.rnd_adj_sh") %>
|
<%= t("views.right_panel.detail.rnd_adj_sh") %>
|
||||||
</td>
|
</td>
|
||||||
|
<td>
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<%end%>
|
<%end%>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ class ActionController::Base
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
# check for license file
|
# check for license file
|
||||||
# if check_license
|
if check_license
|
||||||
# current_license(ENV["SX_PROVISION_URL"])
|
current_license(ENV["SX_PROVISION_URL"])
|
||||||
# else
|
else
|
||||||
# redirect_to activate_path
|
redirect_to activate_path
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
|
|
||||||
# application_path="#{File.expand_path("../..", __FILE__)}"
|
application_path="#{File.expand_path("../..", __FILE__)}"
|
||||||
# directory application_path
|
directory application_path
|
||||||
# #environment ENV.fetch("RAILS_ENV") { "production" }
|
#environment ENV.fetch("RAILS_ENV") { "production" }
|
||||||
# environment "production"
|
environment "production"
|
||||||
# pidfile "#{application_path}/tmp/puma/pid"
|
pidfile "#{application_path}/tmp/puma/pid"
|
||||||
# state_path "#{application_path}/tmp/puma/state"
|
state_path "#{application_path}/tmp/puma/state"
|
||||||
# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
|
stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log"
|
||||||
# port ENV.fetch("PORT") { 62158 }
|
port ENV.fetch("PORT") { 62158 }
|
||||||
# workers 2
|
workers 2
|
||||||
# preload_app!
|
preload_app!
|
||||||
|
|||||||
@@ -102,6 +102,9 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
post "request_bill" => "bill#request_bill"
|
post "request_bill" => "bill#request_bill"
|
||||||
post "paymal_payment" => "payments#paymal_payment"
|
post "paymal_payment" => "payments#paymal_payment"
|
||||||
get ":sale_id/void" => "void#overall_void"
|
get ":sale_id/void" => "void#overall_void"
|
||||||
|
|
||||||
|
#API for sync cloud
|
||||||
|
post 'sync_data' => 'sync#sync_data'
|
||||||
end
|
end
|
||||||
|
|
||||||
#--------- Cashier ------------#
|
#--------- Cashier ------------#
|
||||||
@@ -526,7 +529,7 @@ scope "(:locale)", locale: /en|mm/ do
|
|||||||
get "induty/get_shift_by_date", to: "induty#show", as: "get_shift_by_induty"
|
get "induty/get_shift_by_date", to: "induty#show", as: "get_shift_by_induty"
|
||||||
get "shiftsale_print/:id" , to: "shiftsale#print_close_receipt", as: "get_shift_id"
|
get "shiftsale_print/:id" , to: "shiftsale#print_close_receipt", as: "get_shift_id"
|
||||||
post "print_sale_items", to: "saleitem#print_sale_items", as: "print_sale_items"
|
post "print_sale_items", to: "saleitem#print_sale_items", as: "print_sale_items"
|
||||||
|
get "sync_data", to:'receipt_no#sync_data', as:'sync_data'
|
||||||
end
|
end
|
||||||
|
|
||||||
# ----------- Inventory ---------------------------
|
# ----------- Inventory ---------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user