show and update changes in commission and report
This commit is contained in:
@@ -5,14 +5,42 @@ class ProductCommission < ApplicationRecord
|
||||
belongs_to :sale_item, foreign_key: 'sale_item_id'
|
||||
belongs_to :sale, foreign_key: 'sale_id'
|
||||
|
||||
def self.create_product_commission(saleItemObj)
|
||||
end
|
||||
|
||||
def self.edit_product_commission(saleItemObj)
|
||||
menu_item = MenuItem.find_by_item_code(saleItemObj.product_code)
|
||||
commission = Commission.where('product_code = ? AND is_active = ?', menu_item.id, true).take
|
||||
product_commission = ProductCommission.where('sale_item_id = ?', saleItemObj.id).take
|
||||
|
||||
return if commission.nil?
|
||||
product_commission.qty = saleItemObj.qty
|
||||
if commission.commission_type == 'Percentage'
|
||||
product_commission.price = saleItemObj.unit_price * (commission.amount / 100.0)
|
||||
product_commission.amount = product_commission.price * saleItemObj.qty
|
||||
elsif commission.commission_type == 'Net Amount'
|
||||
product_commission.price = commission.amount
|
||||
product_commission.amount = product_commission.price * saleItemObj.qty
|
||||
end
|
||||
product_commission.save
|
||||
puts 'Edit Product Commission Success'
|
||||
end
|
||||
|
||||
def self.remove_product_commission(sale_item_id)
|
||||
transaction = ProductCommission.find_by_sale_item_id(sale_item_id)
|
||||
return if transaction.nil?
|
||||
transaction.destroy
|
||||
puts 'Remove Product Commission Success'
|
||||
end
|
||||
|
||||
def self.get_transaction(from, to, commissioner)
|
||||
transaction = self.all
|
||||
transaction = 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
|
||||
transaction
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user