Merge branch 'master' of bitbucket.org:code2lab/sxrestaurant

This commit is contained in:
Yan
2017-07-02 20:50:18 +06:30
31 changed files with 439 additions and 299 deletions

View File

@@ -27,16 +27,19 @@ class Customer < ApplicationRecord
'Content-Type' => 'application/json',
'Accept' => 'application/json'
},
:timeout => 10
:timeout => 100
)
rescue HTTParty::Error
response = {status: false, message: "Server Error"}
rescue Net::OpenTimeout
response = { status: false }
response = { status: false , message: "Server Time out"}
rescue OpenURI::HTTPError
response = { status: false}
response = { status: false, message: "Can't connect server"}
rescue SocketError
response = { status: false}
response = { status: false, message: "Can't connect server"}
end
return response;
@@ -60,19 +63,61 @@ class Customer < ApplicationRecord
:timeout => 10
)
rescue Net::OpenTimeout
response = { status: false }
response = { status: false , message: "Server Time out"}
rescue OpenURI::HTTPError
response = { status: false}
response = { status: false, message: "Can't connect server"}
rescue SocketError
response = { status: false}
response = { status: false, message: "Can't connect server"}
end
return response;
end
def self.update_membership
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("create_membership_customer")
merchant_uid = memberaction.merchant_account_id.to_s
auth_token = memberaction.auth_token.to_s
url = membership.gateway_url.to_s + memberaction.gateway_url.to_s
@customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL")
@customers.each do |customer|
begin
response = HTTParty.post(url,
:body =>
{ name: customer.name,phone: customer.contact_no,
email: customer.email,dob: customer.date_of_birth,
address: customer.address,nrc:customer.nrc_no,
card_no:customer.card_no,member_group_id: customer.membership_type,
merchant_uid:merchant_uid,auth_token:auth_token
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
})
rescue Net::OpenTimeout
response = { status: false }
rescue OpenURI::HTTPError
response = { status: false}
rescue SocketError
response = { status: false}
end
puts response.to_json
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
end
end
end
def self.search(search)
if search
# find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"])

View File

@@ -55,7 +55,7 @@ class SalePayment < ApplicationRecord
sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by)
# update complete order items in oqs
SaleOrder.where("sale_id = '#{ invoice.sale_id }'").find_each do |sodr|
SaleOrder.where("sale_id = '#{ invoice.sale_id }'").find_each do |sodr|
AssignedOrderItem.where("order_id = '#{ sodr.order_id }'").find_each do |aoi|
aoi.delivery_status = 1
aoi.save
@@ -287,7 +287,7 @@ class SalePayment < ApplicationRecord
bookings = table.bookings
bookings.each do |tablebooking|
if tablebooking.booking_status != 'moved'
if tablebooking.sale.sale_status != 'completed'
if tablebooking.sale.sale_status != 'completed' && tablebooking.sale.sale_status != 'void'
status = false
end
end
@@ -306,16 +306,22 @@ class SalePayment < ApplicationRecord
if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0
paypar = sObj.sale_payments
payparcost = 0
credit = 0
paypar.each do |pp|
if pp.payment_method == "paypar"
payparcost = payparcost + pp.payment_amount
elsif pp.payment_method == "creditnote"
credit = 1
end
end
# overall_dis = SaleItem.get_overall_discount(sObj.id)
overall_dis = sObj.total_discount
total_amount = rebate_prices - payparcost + overall_dis
if total_amount > 0
total_amount = rebate_prices - payparcost - overall_dis
if credit == 1
total_amount = 0
end
if total_amount >= 0
receipt_no = sObj.receipt_no
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("rebate")
@@ -331,15 +337,15 @@ class SalePayment < ApplicationRecord
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}, :timeout => 10)
}, :timeout => 100)
rescue Net::OpenTimeout
response = { status: false }
response = { status: false , message: "Server Time out"}
rescue OpenURI::HTTPError
response = { status: false}
response = { status: false, message: "Can't connect server"}
rescue SocketError
response = { status: false}
response = { status: false, message: "Can't connect server"}
end
return response
# puts response.to_json

View File

@@ -16,11 +16,17 @@ class ShiftSale < ApplicationRecord
belongs_to :cashier_terminal
belongs_to :employee, :foreign_key => 'employee_id'
def self.current_shift
today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("DATE(shift_started_at)=? and shift_started_at is not null and shift_closed_at is null",today_date).take
return shift
end
def self.current_open_shift(current_user)
#if current_user
#find open shift where is open today and is not closed and login by current cashier
today_date = DateTime.now.strftime("%Y-%m-%d")
shift = ShiftSale.where("DATE(shift_started_at)= #{ today_date } and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take
shift = ShiftSale.where("DATE(shift_started_at)=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}",today_date).take
return shift
#end
end