group BusinessInvoiceField;

CHECK_TENANT() ::= "tenant_record_id = :tenantRecordId"
AND_CHECK_TENANT() ::= "AND <CHECK_TENANT()>"

getFieldsForInvoice(invoice_id) ::=<<
select
  invoice_id
, name
, value
from old_bin_fields
where invoice_id = :invoice_id
<AND_CHECK_TENANT()>
;
>>

addField(invoice_id, name, value) ::=<<
insert into old_bin_fields (
  invoice_id
, name
, value
, account_record_id
, tenant_record_id
) values (
  :invoice_id
, :name
, :value
, :accountRecordId
, :tenantRecordId
);
>>

removeField(invoice_id, name, value) ::= <<
delete from old_bin_fields where invoice_id = :invoice_id and name = :name <AND_CHECK_TENANT()>;
>>

test() ::= <<
select 1 from old_bin_tags where <CHECK_TENANT()> limit 1;
>>
