This commit is contained in:
Nweni
2017-08-30 14:21:05 +06:30
81 changed files with 4943 additions and 1327 deletions

View File

@@ -1,5 +1,15 @@
class Commission < ApplicationRecord
belongs_to :menu_item, foreign_key: 'product_id'
self.primary_key = 'commission_id'
# primary key - need to be unique
before_create :generate_custom_id
belongs_to :menu_item, foreign_key: 'product_code'
has_many :commissioners
has_many :product_commissions
private
def generate_custom_id
self.commission_id = SeedGenerator.generate_id(self.class.name, 'COM')
end
end

View File

@@ -1,6 +1,6 @@
class Commissioner < ApplicationRecord
belongs_to :employee, foreign_key: 'emp_id'
belongs_to :commission, foreign_key: 'commission_type'
belongs_to :commission, foreign_key: 'commission_id'
has_many :in_juties
has_many :product_commissions
scope :active, -> { where(is_active: true) }

View File

@@ -91,46 +91,54 @@ class Customer < ApplicationRecord
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 = 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, message: "Server Time out" }
rescue OpenURI::HTTPError
response = { status: false, message: "Can't connect server"}
member_params = { 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
rescue SocketError
response = { status: false, message: "Can't connect server"}
end
# Check for paypar account exists
# if paypar_account_no != nil || paypar_account_no != ''
if paypar_account_no.present?
member_params = { name: customer.name,phone: customer.contact_no,
email: customer.email,dob: customer.date_of_birth,
address: customer.address,nrc:customer.nrc_no,
paypar_account_no: customer.paypar_account_no,
card_no:customer.card_no,member_group_id: customer.membership_type,
merchant_uid:merchant_uid,auth_token:auth_token}.to_json
end
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
end
begin
response = HTTParty.post(url,
:body => member_params,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
})
rescue Net::OpenTimeout
response = { status: false, message: "Server Time out" }
rescue OpenURI::HTTPError
response = { status: false, message: "Can't connect server"}
rescue SocketError
response = { status: false, message: "Can't connect server"}
end
if response["status"] == true
status = customer.update_attributes(membership_id: response["customer_datas"]["id"])
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
response = self.rebat(Sale.find(sale.sale_id))
if response["status"] == true
status = sale.update_attributes(rebate_status: "true")
end
@@ -188,12 +196,44 @@ class Customer < ApplicationRecord
response = { "status": false, "message": "Can't connect server"}
end
return response
puts response.to_json
return response
end
end
end
def self.search_paypar_account_no(account_no)
membership = MembershipSetting.find_by_membership_type("paypar_url")
memberaction = MembershipAction.find_by_membership_type("search_paypar_account_no")
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
begin
response = HTTParty.get(url,
:body => { paypar_account_no:account_no,
merchant_uid:merchant_uid,
auth_token:auth_token
}.to_json,
:headers => {
'Content-Type' => 'application/json',
'Accept' => 'application/json'
},
:timeout => 10
)
rescue HTTParty::Error
response = {status: false, message: "Server Error"}
rescue Net::OpenTimeout
response = { status: false , message: "Server Time out"}
rescue OpenURI::HTTPError
response = { status: false, message: "Can't connect server"}
rescue SocketError
response = { status: false, message: "Can't connect server"}
end
return response
end
def self.search(search)
if search
# find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"])

View File

@@ -1,6 +1,6 @@
class MenuItemAttribute < ApplicationRecord
validates_presence_of :attribute_type, :name, :value
def self.collection
MenuItemAttribute.select("name, value").map { |e| [e.name, e.value] }
MenuItemAttribute.select("name").map { |e| [e.name, e.name] }
end
end

View File

@@ -90,7 +90,7 @@ class Order < ApplicationRecord
# self.employee_name)
# end
OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id],
OrderItem.processs_item(menu_item[:item_code], item[:item_instance_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id],
item[:quantity],menu_item[:price], item[:options], set_order_items, self.id,
self.employee_name)

View File

@@ -20,11 +20,12 @@ class OrderItem < ApplicationRecord
# option_values : [],
# sub_order_items : [],
# }
def self.processs_item (item_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by)
def self.processs_item (item_code, instance_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by)
orderitem = OrderItem.create do |oitem|
oitem.order_id = order_id
oitem.item_code = item_code
oitem.item_instance_code = instance_code
oitem.item_name = menu_name
oitem.alt_name = alt_name
oitem.account_id = account_id

View File

@@ -5,7 +5,14 @@ class ProductCommission < ApplicationRecord
belongs_to :sale_item, foreign_key: 'sale_item_id'
belongs_to :sale, foreign_key: 'sale_id'
def self.check_product_commission(sale_item_id)
def self.get_transaction(from, to, commissioner)
transaction = self.all
if !from.nil? && !to.nil?
transaction = transaction.where('updated_at between ? and ?', from, to)
end
if commissioner != 0
transaction = transaction.where(commissioner_id: commissioner)
end
return transaction
end
end

View File

@@ -23,12 +23,13 @@ class Promotion < ApplicationRecord
end
def self.is_between_promo_datetime(current_day,current_time) #database is not local time
promoList = Promotion.where("(TO_CHAR(promo_start_date, 'YYYY-MM-DD') <=? AND TO_CHAR(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
promoList = Promotion.where("(date_format(promo_start_date, 'YYYY-MM-DD') <=? AND date_format(promo_end_date, 'YYYY-MM-DD') >=?) AND (promo_start_hour < ? AND promo_end_hour > ?)", current_day, current_day, current_time, current_time)
return promoList
end
def self.combine_item(saleObj)
itemList = saleObj.sale_items.group(:product_code).sum(:qty)
order_id = saleObj.sale_orders[0].order_id
itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty)
end
def self.is_promo_day(promoList, day, orderitemList, sale_id)
@@ -44,7 +45,8 @@ class Promotion < ApplicationRecord
end
def self.find_promo_item(promo, orderitem, sale_id)
if promo.original_product.to_s == orderitem[0].to_s
item_code = OrderItem.find_by_item_instance_code(orderitem[0]).item_code
if promo.original_product.to_s == item_code
if promo.min_qty.to_i > orderitem[1].to_i
return false
else
@@ -69,13 +71,13 @@ class Promotion < ApplicationRecord
give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id)
elsif promo.promo_type == Promotion::PROMO_TYPE4
give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id)
give_promotion_discount(same,promo_product,promo.min_qty, orderitem, sale_id)
end
end
def self.check_giveaway_product(promo, orderitem)
promo.promotion_products.each do |promo_product|
if promo_product.item_code == orderitem
if promo_product.item_code == OrderItem.find_by_item_instance_code(orderitem).item_code
return true, promo_product
else
return false, promo_product
@@ -110,7 +112,13 @@ class Promotion < ApplicationRecord
else
charge_qty += qty
end
item = OrderItem.find_by_item_code(orderitem[0])
item = OrderItem.find_by_item_instance_code(orderitem[0])
byebug
# if promo_product == OrderItem.find_by_item_instance_code(orderitem[0]).item_code
# item = OrderItem.find_by_item_instance_code(orderitem[0])
# else
# item = OrderItem.find_by_item_code(promo_product)
# end
update_existing_item(foc_qty, item, sale_id, "promotion", item.price)
puts "Charged - " + charge_qty.to_s
@@ -124,7 +132,7 @@ class Promotion < ApplicationRecord
if (foc_qty < promotion_qty)
promotion_qty = foc_qty
end
item = OrderItem.find_by_item_code(promo_product)
item = OrderItem.find_by_item_instance_code(promo_product,orderID)
update_existing_item(promotion_qty, item, sale_id, "promotion", item.price)
end
@@ -138,8 +146,8 @@ class Promotion < ApplicationRecord
sale_item.remark = type
sale_item.qty = foc_qty * (-1)
sale_item.unit_price = item_price * (-1)
sale_item.taxable_price = item_price * (-1)
sale_item.unit_price = item_price # * (-1)
sale_item.taxable_price = item_price # * (-1)
sale_item.price = foc_qty * item_price * (-1)
sale_item.is_taxable = false
@@ -156,11 +164,11 @@ class Promotion < ApplicationRecord
if same
foc_qty = orderitem[1].to_i / foc_min_qty
item = OrderItem.find_by_item_code(orderitem[0])
item = OrderItem.find_by_item_instance_code(orderitem[0])
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
else
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
item = OrderItem.find_by_item_code(promo_product.item_code)
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off)
end
end
@@ -170,12 +178,12 @@ class Promotion < ApplicationRecord
if same
foc_qty = orderitem[1].to_i / foc_min_qty
item = OrderItem.find_by_item_code(orderitem[0])
price = item.price - promo_product.net_price
item = OrderItem.find_by_item_instance_code(orderitem[0]) # need to specify with menu item instance
price = item.price.to_i - promo_product.net_price.to_i
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
else
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
item = OrderItem.find_by_item_code(promo_product.item_code)
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
price = item.price - promo_product.net_price
update_existing_item(foc_qty, item, sale_id, "promotion nett price", price)
end
@@ -186,14 +194,16 @@ class Promotion < ApplicationRecord
if same
foc_qty = orderitem[1].to_i / foc_min_qty
item = OrderItem.find_by_item_code(orderitem[0])
total = orderitem[1].to_i * item.price
item = OrderItem.find_by_item_instance_code(orderitem[0])
# total = orderitem[1].to_i * item.price
total = item.price
price = calculate_discount(total, promo_product.percentage)
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
else
foc_qty = find_second_item_qty(sale_id, promo_product.item_code)
item = OrderItem.find_by_item_code(promo_product.item_code)
total = item.price * foc_qty
item = OrderItem.find_by_item_instance_code(promo_product.item_code)
# total = item.price * foc_qty
total = item.price
price = calculate_discount(total, promo_product.percentage)
update_existing_item(foc_qty, item, sale_id, "promotion discount", price)
end
@@ -203,7 +213,7 @@ class Promotion < ApplicationRecord
saleObj = Sale.find_by_sale_id(sale_id)
itemList = combine_item(saleObj)
itemList.each do |item|
if item[0] == promo_item
if OrderItem.find_by_item_instance_code(item[0]).item_code == promo_item
return item[1]
end
end

View File

@@ -324,7 +324,6 @@ class SalePayment < ApplicationRecord
update_shift
end
end
end
# update for cashier shift