module Toolhound # Class to parse GitHub repository owner and name from # URLs and to generate URLs class Project < Base attr_accessor :owner, :name, :id self.table_name = "tblLocation" self.primary_key = "intLocationID" def default_selects #{ }"SELECT tblEntity.intEntityID, tblEntity.varEntityID AS job_no, tblLocation.intLocationID, tblLocationText.varLocationName FROM tblEntity INNER JOIN tblLocation ON tblLocation.intEntityID = tblEntity.intEntityID INNER JOIN tblLocationText ON tblLocationText.intLocationID = tblLocation.intLocationID WHERE varEntityID LIKE '%10526.00%'" { location: [:int_location_id, :dte_created_date, :dte_modified_date], location_text: [:var_location_name], entity: [:int_entity_id, var_entity_id: :job_no ], # tax rates tax: [:dec_tax1_rate, :dec_tax2_rate, :dec_tax3_rate, :dec_tax4_rate], tax_text: [:var_tax1_description, :var_tax2_description, :var_tax3_description, :var_tax4_description], # rental periods rental_period: [:dte_min_rental_date, :dte_max_rental_date] } end def default_joins arr = [] arr << "INNER JOIN tblEntity ON (tblEntity.intEntityID = tblLocation.intEntityID)" arr << "INNER JOIN tblLocationText ON (tblLocationText.intLocationID = tblLocation.intLocationID)" # tax rates arr << "LEFT OUTER JOIN ( SELECT intLocationID, MAX(tblTax.dteCreatedDate) AS max_date FROM tblTax GROUP BY intLocationID ) as taxQuery ON taxQuery.intLocationID = tblLocation.intLocationID" arr << "LEFT OUTER JOIN tblTax ON tblTax.intLocationID = taxQuery.intLocationID AND tblTax.dteCreatedDate = taxQuery.max_date" arr << "LEFT OUTER JOIN tblTaxText ON tblTaxText.intTaxID = tblTax.intTaxID AND tblTaxText.varLocaleID = '#{locale}'" # rental periods arr << "LEFT OUTER JOIN ( SELECT intEntityID, MIN(dteStartDate) as dteMinRentalDate, MAX(dteStartDate) AS dteMaxRentalDate FROM tblRentalCharge GROUP BY intEntityID ) AS tblRentalPeriod ON tblRentalPeriod.intEntityID = tblEntity.intEntityID" arr end def find_by_entity_id(id) all(limit: 1, where: [{int_entity_id: id}]).first end def find_by_job_no(job_no) all(limit: 1, where: [{"entity.var_entity_id" => {value: "%#{job_no}%", op: :like} }]).first end # rename_attributes intLocationID: 'location_id' end end