rescue member call and update oqs and js route bug

This commit is contained in:
Yan
2017-06-18 03:20:19 +06:30
parent 80320b6d3e
commit f33f11df64
12 changed files with 102 additions and 51 deletions

View File

@@ -121,7 +121,7 @@ $(document).ready(function(){
// Bill Request
$('#request_bills').click(function() {
var order_id=$(".selected-item").find(".orders-id").text();
var order_id=$(".selected-item").find(".orders-id").text().substr(0,16);
if(order_id!=""){
window.location.href = '/origami/' + order_id + '/request_bills'
}
@@ -133,7 +133,8 @@ $(document).ready(function(){
// Discount for Payment
$('#discount').click(function() {
var order_id=$(".selected-item").find(".orders-id").text();
var order_id=$(".selected-item").find(".orders-id").text().substr(0,16);
if(order_id!=""){
window.location.href = '/origami/' + order_id + '/discount'
}
@@ -148,7 +149,7 @@ $(document).ready(function(){
$("#pay-discount").on('click', function(e){
e.preventDefault();
var sale_id = $('#sale-id').text();
var sale_item_id = $('.selected-item').attr('id');
var sale_item_id = $('.selected-item').attr('id').substr(0,16);
var sub_total = $('#order-sub-total').text();
var grand_total = $('#order-grand-total').text();
var discount_type = $('#discount-type').val();
@@ -178,7 +179,7 @@ $(document).ready(function(){
// Payment for Bill
$('#pay-bill').click(function() {
var sale_id=$(".selected-item").find(".orders-id").text();
var sale_id=$(".selected-item").find(".orders-id").text().substr(0,16);
if(sale_id!=""){
window.location.href = '/origami/sale/'+ sale_id + "/payment"
}
@@ -190,7 +191,7 @@ $(document).ready(function(){
});
$('#customer').click(function() {
var sale = $(".selected-item").find(".orders-id").text();
var sale = $(".selected-item").find(".orders-id").text().substr(0,16);
if (sale.substring(0, 3)=="SAL") {
var sale_id = sale
}else{
@@ -202,7 +203,7 @@ $(document).ready(function(){
});
$('#re-print').click(function() {
var sale_id = $(".selected-item").find(".orders-id").text();
var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16);
window.location.href = '/origami/'+ sale_id + "/reprint"

View File

@@ -15,13 +15,32 @@ class Api::BillController < Api::ApiController
@status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee)
else
@status = true
@sale_id = booking.sale_id
end
end
elsif (params[:order_id])
@sale = Sale.new
@status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee)
end
@sale_data = Sale.find_by_sale_id(@sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_id)
unique_code = "ReceiptBillPdf"
customer= Customer.where('customer_id=' + @sale_data.customer_id)
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
# find order id by sale id
# sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id)
# Calculate Food and Beverage Total
food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total)
redirect_to origami_path(@sale_data.sale_id)
end

View File

@@ -28,16 +28,24 @@ class Oqs::HomeController < BaseOqsController
table_name = params[:table_id]
status = params[:status]
dining = DiningFacility.find_by_name(table_name);
oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
if status == ""
AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi|
oi = OrderItem.find_by_item_code(aoi.item_code)
items.push(oi)
end
else
AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi|
oi = OrderItem.find_by_item_code(aoi.item_code)
items.push(oi)
# oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
# if status == ""
# AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi|
# oi = OrderItem.find_by_item_code(aoi.item_code)
# items.push(oi)
# end
# else
# AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi|
# oi = OrderItem.find_by_item_code(aoi.item_code)
# items.push(oi)
# end
# end
booking = Booking.find_by_dining_facility_id(dining.id)
BookingOrder.where("booking_id='#{ booking.booking_id }'").find_each do |bo|
order=Order.find(bo.order_id)
order.order_items.each do |oi|
items.push(oi)
end
end
@@ -73,16 +81,26 @@ class Oqs::HomeController < BaseOqsController
# Query for OQS with status
def queue_items_query(status)
# AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at")
# .joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id
# left join dining_facilities as df on df.zone_id = oqpz.zone_id
# left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id
# left join orders as od ON od.order_id = assigned_order_items.order_id
# left join order_items as odt ON odt.item_code = assigned_order_items.item_code
# left join customers as cus ON cus.customer_id = od.customer_id")
# .where("assigned_order_items.delivery_status = #{status}")
# .group("assigned_order_items.assigned_order_item_id")
# .order("odt.item_name DESC")
AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at")
.joins(" left join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id
left join dining_facilities as df on df.zone_id = oqpz.zone_id
left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id
.joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id
left join orders as od ON od.order_id = assigned_order_items.order_id
left join order_items as odt ON odt.item_code = assigned_order_items.item_code
left join customers as cus ON cus.customer_id = od.customer_id")
left join customers as cus ON cus.customer_id = od.customer_id
left join booking_orders as bo on bo.order_id = assigned_order_items.order_id
left join bookings as bk on bk.booking_id = bo.booking_id
left join dining_facilities as df on df.id = bk.dining_facility_id")
.where("assigned_order_items.delivery_status = #{status}")
.group("assigned_order_items.assigned_order_item_id")
.order("odt.item_name DESC")
end
end

View File

@@ -39,6 +39,7 @@ class Origami::HomeController < BaseOrigamiController
str.push(ord_detail)
end
end
if is_ajax == 1
render :json => str.to_json
else

View File

@@ -48,7 +48,7 @@ class Origami::PaymentsController < BaseOrigamiController
@balance = 0.00
@accountable_type = ''
if response["data"]==true
if response["status"]==true
response["data"].each do |res|
if res["accountable_type"] == "RebateAccount"
@balance = res["balance"]

View File

@@ -39,12 +39,17 @@ class Customer < ApplicationRecord
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
begin
response = HTTParty.get(url, :body => { membership_id: customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}
},
:timeout => 10
)
rescue Net::OpenTimeout
response = { status: false }
end
return response;

View File

@@ -246,7 +246,7 @@ class Order < ApplicationRecord
.joins("left join orders on orders.order_id = booking_orders.order_id")
.joins("left join sales on sales.sale_id = bookings.sale_id")
.where("sales.sale_status='completed'")
.group("sales.sale_id,bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id")
.group("sales.sale_id")
# For PG
#bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id
end

View File

@@ -195,28 +195,28 @@ class Sale < ApplicationRecord
existing_tax.delete
end
total_tax_amount = 0
#tax_profile - list by order_by
tax_profiles = TaxProfile.all.order("order_by asc")
# total_tax_amount = 0
# #tax_profile - list by order_by
# tax_profiles = TaxProfile.all.order("order_by asc")
#Creat new tax records
tax_profiles.each do |tax|
sale_tax = SaleTax.new(:sale => self)
sale_tax.tax_name = tax.name
sale_tax.tax_rate = tax.rate
#include or execulive
# sale_tax.tax_payable_amount = total_taxable * tax.rate
sale_tax.tax_payable_amount = total_taxable * tax.rate / 100
#new taxable amount
total_taxable = total_taxable + sale_tax.tax_payable_amount
# #Creat new tax records
# tax_profiles.each do |tax|
# sale_tax = SaleTax.new(:sale => self)
# sale_tax.tax_name = tax.name
# sale_tax.tax_rate = tax.rate
# #include or execulive
# # sale_tax.tax_payable_amount = total_taxable * tax.rate
# sale_tax.tax_payable_amount = total_taxable * tax.rate / 100
# #new taxable amount
# total_taxable = total_taxable + sale_tax.tax_payable_amount
sale_tax.inclusive = tax.inclusive
sale_tax.save
# sale_tax.inclusive = tax.inclusive
# sale_tax.save
total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
end
# total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount
# end
self.total_tax = total_tax_amount
# self.total_tax = total_tax_amount
end

View File

@@ -30,6 +30,7 @@ class SaleItem < ApplicationRecord
# end
end
# Calculate food total and beverage total
def self.calculate_food_beverage(sale_items)
food_prices=0
beverage_prices=0
@@ -43,6 +44,7 @@ class SaleItem < ApplicationRecord
return food_prices, beverage_prices
end
# get food price or beverage price for item
def self.get_price(sale_item_id)
food_price=0
beverage_price=0

View File

@@ -260,12 +260,17 @@ class SalePayment < ApplicationRecord
campaign_type_id = memberaction.additional_parameter["campaign_type_id"]
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
begin
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,merchant_uid:merchant_uid,total_amount: total_amount,campaign_type_id: campaign_type_id,
receipt_no: receipt_no,auth_token:auth_token}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
})
}, :timeout => 10)
rescue Net::OpenTimeout
response = { status: false }
end
puts response.to_json
end

View File

@@ -121,9 +121,9 @@ class ReceiptBillPdf < Prawn::Document
pad_top(15) {
text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :overflow => :shrink_to_fix, :size => self.item_font_size, :overflow => :shrink_to_fix
text_box "#{price.to_i}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "#{qty.to_i}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "#{total_price.to_i}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "#{price}", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
text_box "#{qty}", :at =>[item_name_width,y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix
text_box "#{total_price}", :at =>[(item_name_width),y_position], :width =>self.total_width+5, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix
}
move_down 3
end
@@ -174,7 +174,7 @@ class ReceiptBillPdf < Prawn::Document
text "#{ st.tax_name }", :size => self.item_font_size,:align => :left
end
bounding_box([self.item_description_width,y_position], :width =>self.label_width) do
text "( " +"#{ st.tax_payable_amount }" +" )" , :size => self.item_font_size,:align => :right
text "#{ st.tax_payable_amount }" , :size => self.item_font_size,:align => :right
end
end
else

View File

@@ -354,14 +354,14 @@
<td class="charges-name"><strong>Discount:</strong></td>
<td class="item-attr"><strong id="order-discount">(<%=@selected_item.total_discount rescue 0%>)</strong></td>
</tr>
<tr>
<!-- <tr>
<td class="charges-name"><strong>Tax:</strong></td>
<td class="item-attr"><strong id="order-Tax"><%=@selected_item.total_tax rescue 0%></strong></td>
</tr>
<tr>
<td class="charges-name"><strong>Grand Total:</strong></td>
<td class="item-attr"><strong id="order-grand-total"><%=@selected_item.grand_total rescue 0%></strong></td>
</tr>
</tr> -->
<tr class="rebate_amount">
</tr>