Skip to content

Instantly share code, notes, and snippets.

@guipdutra
Created May 15, 2013 18:11
Show Gist options
  • Save guipdutra/5586043 to your computer and use it in GitHub Desktop.
Save guipdutra/5586043 to your computer and use it in GitHub Desktop.
# encoding: utf-8
class TaxRevenueGroupedBuilder
attr_accessor :retentions
attr_writer :tax_revenue, :tax_revenue_issued_status, :tax_revenue_receipt,
:tax_revenue_receipt_issued_status
def initialize(retentions)
self.retentions = retentions
end
def self.build!(retentions)
self.new(retentions).build!
end
def build!
retentions.each do |retention|
create_tax_revenue!(retention)
end
end
private
def create_tax_revenue!(retention)
tax_revenue.create!({
:description => description(retention.pledge_liquidation_parcel_payment),
:document => document(retention.pledge_liquidation_parcel_payment),
:status => tax_revenue_issued_status,
:amount => retention.value,
:pledge_liquidation_parcel_retention_id => retention.id,
:descriptor_id => retention.descriptor_id,
:date => retention.date,
:tax_revenue_receipts => [build_tax_revenue_receipt(retention)]
})
end
def build_tax_revenue_receipt(retention)
tax_revenue_receipt.new({
:budget_revenue_id => retention.budget_revenue_id,
:value => retention.value,
:status => tax_revenue_receipt_issued_status,
:agreement_id => retention.agreement_id
})
end
def description(payment)
"Pelo desconto orçamentário da ordem de pagamento #{payment.code}, empenho #{payment.pledge_code}"
end
def document(payment)
"Ordem de Pagamento #{payment.code}"
end
def tax_revenue
@tax_revenue ||= TaxRevenue
end
def tax_revenue_receipt
@tax_revenue_receipt ||= TaxRevenueReceipt
end
def tax_revenue_issued_status
@tax_revenue_issued_status ||= TaxRevenueStatus::ISSUED
end
def tax_revenue_receipt_issued_status
@tax_revenue_receipt_issued_status ||= TaxRevenueReceiptStatus::ISSUED
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment