Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added balance inbound to e-invoices to support deposits #1156

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def oneoff

def send_e_invoice
invoice = Invoice.accessible_by(current_ability).find_by!(uuid: params[:uuid])
response = EisBilling::SendEInvoice.call(invoice: invoice, payable: false)
response = EisBilling::SendEInvoice.call(invoice: invoice, payable: !invoice.paid?)

if response.result?
redirect_to invoice_path(invoice.uuid), notice: t('.sent_to_omniva')
Expand Down
5 changes: 3 additions & 2 deletions app/models/concerns/invoice/book_keeping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ def e_invoice_data
invoice['buyer_zip'] = postal_code
invoice['buyer_city'] = city
invoice['buyer_country_code'] = billing_alpha_two_country_code
invoice['total'] = total.to_f + (enable_deposit? ? deposit : 0.0)
invoice['vat_rate'] = vat_rate * 100
invoice['total'] = price.to_f * (1 + vat_rate)
invoice['total_to_pay'] = total.to_f
invoice['vat_rate'] = vat_rate.to_f * 100
invoice['currency'] = Setting.find_by(code: 'auction_currency').retrieve

invoice
Expand Down
37 changes: 24 additions & 13 deletions app/services/eis_billing/send_e_invoice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,47 @@ def initialize(invoice:, payable:)
end

def call
prepared_data = {
prepared_data = build_prepared_data
struct_response(post(e_invoice_url, prepared_data))
end

private

def build_prepared_data
{
invoice: invoice.e_invoice_data,
vat_amount: invoice.vat.amount,
invoice_subtotal: invoice.price.amount,
vat_amount: invoice.vat.to_f,
invoice_subtotal: invoice.price.to_f,
buyer_billing_email: invoice.user&.email,
payable: payable,
inbound: prepare_inbound_data(invoice),
initiator: INITIATOR,
items: prepare_items(invoice)
items: prepare_items(invoice),
}

struct_response(post(e_invoice_url, prepared_data))
end

private

def prepare_items(invoice)
invoice.items.map do |invoice_item|
{
description: item_description(invoice.result),
price: invoice_item.price.amount,
description: invoice_item.name,
price: invoice_item.price.to_f,
quantity: 1,
unit: 'piece',
subtotal: invoice_item.price.amount,
subtotal: invoice_item.price.to_f,
vat_rate: invoice.vat_rate.to_f * 100,
vat_amount: invoice.vat.amount,
total: invoice.total.to_f,
vat_amount: invoice_item.price.to_f * invoice.vat_rate,
total: invoice_item.price.to_f * (1 + invoice.vat_rate),
}
end
end

def prepare_inbound_data(invoice)
total = invoice.price.to_f * (1 + invoice.vat_rate)
return total if payable == false

invoice.enable_deposit? ? invoice.deposit.to_f : 0
end

def e_invoice_url
'/api/v1/e_invoice/e_invoice'
end
Expand Down
18 changes: 10 additions & 8 deletions app/views/invoices/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,18 @@
</tfoot>
</table>
</div>
<% if @invoice.payable? %>
<div class="column">
<div class="column">
<% if @invoice.payable? %>
<%= button_to t('invoices.show.pay'), oneoff_invoice_path(uuid: @invoice.uuid), class: 'ui button primary' %>
</div>
<% end %>
<% end %>
</div>
<div class="column right aligned">
<% if @invoice.do_not_send_e_invoice? %>
<a href="https://eservice.omniva.eu" target="_blank"><img src="/images/finbite.png" alt="EInvoice" style="height:40px;"/></a>
<% else %>
<%= button_to t('invoices.show.send_e_invoice'), send_e_invoice_path(uuid: @invoice.uuid), class: 'ui button default', data: { turbo: false } %>
<% unless @invoice.cancelled? %>
<% if @invoice.e_invoice_sent? %>
<a href="https://eservice.omniva.eu" target="_blank"><img src="/images/finbite.png" alt="EInvoice" style="height:40px;"/></a>
<% else %>
<%= button_to t('invoices.show.send_e_invoice'), send_e_invoice_path(uuid: @invoice.uuid), class: 'ui button default', data: { turbo: false } %>
<% end %>
<% end %>
</div>
</div>
Expand Down
Loading