class SaleTax < ApplicationRecord
  self.primary_key = "sale_tax_id"

  #primary key - need to be unique generated for multiple shops
  before_create :generate_custom_id
  belongs_to :sale

  def self.get_tax(from,to)
    query = SaleTax.select("sale_taxes.tax_name,SUM(sale_taxes.tax_payable_amount) as tax_amount").joins("join sales on sales.sale_id = sale_taxes.sale_id").where("sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0", 'completed', from, to).group("sale_taxes.tax_name")
  end

  private
  def generate_custom_id
    self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI")
  end
end
