This commit is contained in:
Nweni
2017-07-11 10:24:26 +06:30
72 changed files with 1976 additions and 857 deletions

View File

@@ -27,7 +27,7 @@ class Customer < ApplicationRecord
'Content-Type' => 'application/json',
'Accept' => 'application/json'
},
:timeout => 100
:timeout => 10
)
rescue HTTParty::Error
response = {status: false, message: "Server Error"}
@@ -46,7 +46,7 @@ class Customer < ApplicationRecord
end
def self.get_membership_transactions(customer)
def self.get_membership_transactions(customer,receipt_no = nil)
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("get_member_transactions")
merchant_uid = memberaction.merchant_account_id.to_s
@@ -55,13 +55,17 @@ class Customer < ApplicationRecord
# urltest =self.url_exist?(url)
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
)
response = HTTParty.get(url,
:body => { membership_id: customer.membership_id,
receipt_no:receipt_no,
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 , message: "Server Time out"}
@@ -100,22 +104,90 @@ class Customer < ApplicationRecord
'Accept' => 'application/json'
})
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
puts response.to_json
if response["status"] == true
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
end
end
end
end
def self.update_rebate
sales = Sale.where("rebate_status = 'false'")
sales.each do |sale|
if sale.customer.membership_id
response = self.rebat(Sale.find(sale.sale_id))
puts response.to_json
if response["status"] == true
status = sale.update_attributes(rebate_status: "true")
end
end
end
end
def self.rebat(sObj)
rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items)
generic_customer_id = sObj.customer.membership_id
if generic_customer_id.present?
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 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")
merchant_uid = memberaction.merchant_account_id.to_s
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
# Control for Paypar Cloud
begin
response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_sale_transaction_amount: sObj.grand_total,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 , "message": "Connect To" }
rescue OpenURI::HTTPError
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { "status": false, "message": "Can't connect server"}
end
return response
puts response.to_json
end
end
end
def self.search(search)

View File

@@ -9,7 +9,7 @@ class OrderItem < ApplicationRecord
#Validation
validates_presence_of :item_code, :item_name, :qty
validates :qty, numericality: { :greater_than => 0 }
# validates :qty, numericality: { :greater_than => 0 }
validates_associated :order
#This Method - handle how items is added into order

View File

@@ -13,7 +13,7 @@ class OrderQueueStation < ApplicationRecord
def process_order (order, table_id)
oqs_stations = OrderQueueStation.active
dining=DiningFacility.find(table_id)
oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
# oqpbz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id)
order_items = order.order_items
@@ -47,12 +47,16 @@ class OrderQueueStation < ApplicationRecord
end
# Auto Printing
# ToDo per item per printer
if oqs.auto_print && is_auto_printed == false
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
end
end
OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}").find_each do |oqpbz|
if oqs.id == oqpbz.order_queue_station_id
if oqs.auto_print
if oqs_order_items.length > 0
print_slip(oqs, order, oqs_order_items)
is_auto_printed = true
end
end
end
end
end
end

View File

@@ -427,7 +427,7 @@ class Sale < ApplicationRecord
SUM(case when (sale_payments.payment_method='jcb') then sale_payments.payment_amount else 0 end) as jcb_amount,
SUM(case when (sale_payments.payment_method='paypar') then sale_payments.payment_amount else 0 end) as paypar_amount,
SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='credit') then sale_payments.payment_amount else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='creditnote') then sale_payments.payment_amount else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount")
.joins("join (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sale_payments on sale_payments.sale_id = sales.sale_id")
.where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to)
@@ -445,6 +445,7 @@ class Sale < ApplicationRecord
total_sale = Sale.select("IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total,
IFNULL(SUM(case when (sale_status='completed') then old_grand_total else 0 end),0) as old_grand_total,
IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0) as total_discount,
IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount,
IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount,
IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj")
.where("(sale_status = ? OR sale_status = ?) AND receipt_date between ? and ? AND total_amount != 0", 'completed', 'void', from_date, to_date)
@@ -454,6 +455,7 @@ class Sale < ApplicationRecord
old_grand_total = sale.old_grand_total
total_discount = sale.total_discount
void_amount = sale.void_amount
total_change_amount = sale.total_change_amount
total = {:sale_date => pay.sale_date,
:mpu_amount => pay.mpu_amount,
:master_amount => pay.master_amount,
@@ -464,6 +466,7 @@ class Sale < ApplicationRecord
:credit_amount => pay.credit_amount,
:foc_amount => pay.foc_amount,
:total_discount => total_discount,
:total_change_amount => total_change_amount,
:grand_total => grand_total,
:old_grand_total => old_grand_total,
:void_amount => void_amount,
@@ -493,7 +496,7 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
JOIN employees ea ON ea.id = sales.cashier_id")
query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status)
query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status)
@@ -514,7 +517,7 @@ def self.get_by_shiftsales(from,to)
return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
end
# def self.get_by_shiftsales(employee,from,to)
# def self.get_by_shiftsales(from,to)
# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date')
# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id")
# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to)
@@ -529,23 +532,23 @@ end
# void = Sale.select("SUM(sales.grand_total) AS grand_total")
# .joins("join shift_sales sh on sh.id = sales.shift_sale_id")
# .where('sales.sales_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id)
# .where('sales.sale_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id)
# .sum(:grand_total)
# cash = all_total.select('sr.payment_type')
# .where('sr.payment_type = "cash"')
# .sum(:amount)
# credit = all_total.where('sr.payment_type = "credit"')
# credit = all_total.where('sr.payment_type = "creditnote"')
# .sum(:amount)
# accept_credit = all_total.select('ci.amout')
# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id")
# .where('sr.payment_type = "credit"')
# .where('sr.payment_type = "creditnote"')
# .sum(:amout)
# foc = all_total.where('sales.payment_type = "foc" and sales.sales_status = "completed"')
# foc = all_total.where('sales.payment_type = "foc" and sales.sale_status = "completed"')
# .sum(:grand_total)
# card = all_total.select('payment_type')
@@ -571,6 +574,31 @@ end
# return sale_arr
# end
# def self.get_receipt_no_list(from,to)
# sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
# end
def self.get_by_shift_sale(from,to,status)
query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date,shift_closed_at As closing_date," +
" grand_total AS grand_total, cash_sales AS cash," +
"total_taxes AS total_tax,total_discounts As total_discount")
.order("shift_sales.id DESC")
return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to)
end
def self.get_separate_tax(from,to,payment_type=nil)
query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
.joins("INNER JOIN sales ON sales.id = sale_taxes.sale_id")
.group("sale_taxes.tax_name")
return query = query.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
end
def grand_total_after_rounding
return self.old_grand_total.to_f + self.rounding_adjustment.to_f
end
def get_cash_amount
cash = 0.0
self.sale_payments.each do |pay|
@@ -604,7 +632,7 @@ end
def get_commerical_tax
tax = 0.0
self.sale_taxes.each do |taxobj|
if taxobj.tax_name == "Commerical Tax"
if taxobj.tax_name == "Commercial Tax"
tax += taxobj.tax_payable_amount
end
end
@@ -616,8 +644,4 @@ end
def generate_custom_id
self.sale_id = SeedGenerator.generate_id(self.class.name, "SAL")
end
def self.get_receipt_no_list(from,to)
sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
end
end

View File

@@ -57,7 +57,7 @@ class SaleItem < ApplicationRecord
# Check for actual sale items
sale_items.where("is_taxable = false AND remark = 'Discount'").find_each do |si|
if si.account_id == a.id
discount_account[:price] = (discount_account[:price] + si.price) * -1
discount_account[:price] = (discount_account[:price].abs + si.price.abs) * -1
end
end
discount_accounts.push(discount_account)

View File

@@ -260,9 +260,27 @@ class SalePayment < ApplicationRecord
self.sale.payment_status = "outstanding"
end
self.sale.sale_status = "completed"
response = rebat(sObj)
if response["status"] == true
self.sale.rebate_status = 'true'
end
if response["status"] == false
self.sale.rebate_status = 'false'
end
if response[:status] == false
self.sale.rebate_status = 'false'
end
if response[:status] == "no_member"
self.sale.rebate_status = nil
end
self.sale.save!
table_update_status(sObj)
rebat(sObj)
if paid_amount != "0.0"
update_shift
end
@@ -270,6 +288,7 @@ class SalePayment < ApplicationRecord
end
# update for cashier shift
def update_shift
shift = ShiftSale.current_open_shift(self.sale.cashier_id)
if !shift.nil?
@@ -303,7 +322,7 @@ class SalePayment < ApplicationRecord
rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items)
generic_customer_id = sObj.customer.membership_id
if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0
if generic_customer_id.present?
paypar = sObj.sale_payments
payparcost = 0
credit = 0
@@ -337,20 +356,25 @@ class SalePayment < ApplicationRecord
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
}, :timeout => 100)
}, :timeout => 10)
rescue Net::OpenTimeout
response = { status: false , message: "Server Time out"}
response = { "status": false , "message": "Connect To" }
rescue OpenURI::HTTPError
response = { status: false, message: "Can't connect server"}
response = { "status": false, "message": "Can't connect server"}
rescue SocketError
response = { status: false, message: "Can't connect server"}
response = { "status": false, "message": "Can't connect server"}
end
return response
# puts response.to_json
return response
puts response.to_json
end
end
else
response = { "status": "no_member", "message": "Not membership"}
end
end

View File

@@ -52,10 +52,34 @@ class ShiftSale < ApplicationRecord
self.cash_sales = self.cash_sales.to_f + cash.to_f
self.credit_sales = self.credit_sales.to_i + credit.to_f
self.other_sales = self.other_sales.to_i + other_sales.to_f
self.nett_sales = self.grand_total.to_i - self.commercial_taxes
self.nett_sales = self.nett_sales + saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes
self.commercial_taxes = self.commercial_taxes.to_i + tax.to_f
self.total_rounding = self.total_rounding + saleobj.rounding_adjustment
self.total_receipt = self.total_receipt + 1
self.save
end
# Calculate by type and update
def calculate(sale, type)
saleobj = Sale.find_by_sale_id(sale)
cash = saleobj.get_cash_amount
credit = saleobj.get_credit_amount
other_sales = saleobj.get_other_amount
tax = saleobj.get_commerical_tax
if type == "void"
self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f
self.total_discounts = self.total_discounts - saleobj.total_discount
self.total_taxes = self.total_taxes - saleobj.total_tax
self.grand_total = self.grand_total - saleobj.grand_total
self.cash_sales = self.cash_sales.to_f - cash.to_f
self.credit_sales = self.credit_sales.to_i - credit.to_f
self.other_sales = self.other_sales.to_i - other_sales.to_f
self.nett_sales = self.nett_sales - saleobj.total_amount.to_f #self.grand_total.to_i - self.commercial_taxes
self.commercial_taxes = self.commercial_taxes.to_i - tax.to_f
self.total_rounding = self.total_rounding - saleobj.rounding_adjustment
self.total_void = self.total_void + saleobj.grand_total
self.save
end
end
def get_closing_balance(shift)