import "org/killbill/billing/util/entity/dao/EntitySqlDao.sql.stg"

tableName() ::= "invoice_tracking_ids"

tableFields(prefix) ::= <<
  <prefix>tracking_id
, <prefix>invoice_id
, <prefix>subscription_id
, <prefix>unit_type
, <prefix>record_date
, <prefix>created_by
, <prefix>created_date
>>

tableValues() ::= <<
  :trackingId
, :invoiceId
, :subscriptionId
, :unitType
, :recordDate
, :userName
, :createdDate
>>

getTrackingsByDateRange() ::= <<
select
  <allTableFields("")>
from <tableName()>
where
record_date >= :startDate
and record_date \< :endDate
and <accountRecordIdField("")> = :accountRecordId
<AND_CHECK_TENANT("")>
<defaultOrderBy("")>
;
>>

getTrackingsForInvoice() ::= <<
select
  <allTableFields("")>
from <tableName()>
where
invoice_id = :invoiceId
and <accountRecordIdField("")> = :accountRecordId
<AND_CHECK_TENANT("")>
<defaultOrderBy("")>
;
>>
