group FixedPriceInvoiceItemSqlDao;

fields(prefix) ::= <<
  <prefix>id,
  <prefix>invoice_id,
  <prefix>account_id,
  <prefix>bundle_id,
  <prefix>subscription_id,
  <prefix>plan_name,
  <prefix>phase_name,
  <prefix>start_date,
  <prefix>end_date,
  <prefix>amount,
  <prefix>currency,
  <prefix>created_by,
  <prefix>created_date
>>

getById() ::= <<
  SELECT <fields()>
  FROM fixed_invoice_items
  WHERE id = :id;
>>

getInvoiceItemsByInvoice() ::= <<
  SELECT <fields()>
  FROM fixed_invoice_items
  WHERE invoice_id = :invoiceId;
>>

getInvoiceItemsByAccount() ::= <<
  SELECT <fields("rii.")>
  FROM fixed_invoice_items rii
  INNER JOIN invoices i ON i.id = rii.invoice_id
  WHERE i.account_id = :accountId;
>>

getInvoiceItemsBySubscription() ::= <<
  SELECT <fields()>
  FROM fixed_invoice_items
  WHERE subscription_id = :subscriptionId;
>>

create() ::= <<
  INSERT INTO fixed_invoice_items(<fields()>)
  VALUES(:id, :invoiceId, :accountId, :bundleId, :subscriptionId, :planName, :phaseName,
         :startDate, :endDate, :amount, :currency, :userName, :createdDate);
>>

batchCreateFromTransaction() ::= <<
  INSERT INTO fixed_invoice_items(<fields()>)
  VALUES(:id, :invoiceId, :accountId, :bundleId, :subscriptionId, :planName, :phaseName,
         :startDate, :endDate, :amount, :currency, :userName, :createdDate);
>>

test() ::= <<
  SELECT 1
  FROM fixed_invoice_items;
>>
;