Skip to content

Commit

Permalink
replace to turbo billing update
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Hasjanov authored and Oleg Hasjanov committed Mar 1, 2024
1 parent 1a61c48 commit baa40f1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 50 deletions.
2 changes: 1 addition & 1 deletion app/components/modals/pay_invoice/component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>

<%= turbo_frame_tag "invoice_information" do %>
<%= render partial: 'invoices/invoice_information', locals: { invoice: @invoice } %>
<%= component 'modals/pay_invoice/invoice_information', invoice: @invoice %>
<% end %>


Expand Down
38 changes: 0 additions & 38 deletions app/components/modals/pay_invoice/component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,6 @@ def initialize(invoice:)

@invoice = invoice
end

def current_billing_profile
params[:billing_profile_id].presence || invoice.billing_profile_id
end

def invoice_issuer
Setting.find_by(code: 'invoice_issuer').retrieve
end

def issuer_for
@invoice.address
end

def invoice_issuer_address
Setting.find_by(code: 'invoice_issuer_address').retrieve
end

def invoice_issuer_reg_no
Setting.find_by(code: 'invoice_issuer_reg_no').retrieve
end

def invoice_issuer_vat_number
Setting.find_by(code: 'invoice_issuer_vat_number').retrieve
end

def billing_profile_dropdown_properties
{
attribute: :billing_profile_id,
enum: billing_profiles = BillingProfile.where(user_id: invoice.user_id).collect do |b|
[b.name, b.id, { 'data-vat-rate' => b.vat_rate }]
end,
first_options: {},
second_options: {
class: billing_profiles.size == 1 ? 'disabled' : '',
data: { action: 'change->invoice-autotax-counterr#updateTax', invoice_autotax_counter_target: 'dropdown'}
}
}
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="c-modal__grid u-align-start u-flex-wrap">
<div class="c-modal__col">

<%= form_with model: invoice, url: invoice_path(invoice.uuid), data: { controller: 'form--debounce', action: 'change->form--debounce#search', form__debounce_target: 'form' } do |f| %>
<%= form_with model: @invoice, url: invoice_path(@invoice.uuid), data: { controller: 'form--debounce', action: 'change->form--debounce#search', form__debounce_target: 'form' } do |f| %>
<%= component 'common/form/label', form: f, attribute: :billing_profile_id, title: t('billing_profiles_name') %>

<%= component 'common/form/dropdown_input', form: f, attribute: :billing_profile_id,
enum: options_for_select(BillingProfile.where(user_id: invoice.user_id).pluck(:name, :id), params[:billing_profile_id].presence || invoice.billing_profile_id),
enum: options_for_select(BillingProfile.where(user_id: @invoice.user_id).pluck(:name, :id), params[:billing_profile_id].presence || @invoice.billing_profile_id),
first_options: { include_blank: false } %>
<% end %>
</div>
Expand Down Expand Up @@ -54,7 +54,7 @@
</thead>
<tbody>

<% invoice.items.each_with_index do |item, index| %>
<% @invoice.items.each_with_index do |item, index| %>
<tr>
<td><%= index + 1 %></td>
<td><%= I18n.t('invoice_items.name',
Expand All @@ -67,29 +67,29 @@

<tr>
<td>2</td>
<td><%= t('invoices.vat_amount') %> <%= number_to_percentage(invoice.vat_rate * 100, precision: 0) %></td>
<td><%= t('offers.price_in_currency', price: invoice.vat) %></td>
<td><%= t('invoices.vat_amount') %> <%= number_to_percentage(@invoice.vat_rate * 100, precision: 0) %></td>
<td><%= t('offers.price_in_currency', price: @invoice.vat) %></td>
</tr>

<tr>
<td>3</td>
<td><%= t('invoices.total') %></td>
<td><%= t('offers.price_in_currency', price: invoice.total + (invoice.enable_deposit? ? invoice.deposit : 0.0)) %></td>
<td><%= t('offers.price_in_currency', price: @invoice.total + (@invoice.enable_deposit? ? @invoice.deposit : 0.0)) %></td>
</tr>

<% if invoice.enable_deposit? %>
<% if @invoice.enable_deposit? %>
<tr>
<td>4</td>
<td><%= t('invoices.deposit') %></td>
<td><%= t('offers.price_in_currency', price: invoice.deposit) %></td>
<td><%= t('offers.price_in_currency', price: @invoice.deposit) %></td>
</tr>
<% end %>

</tbody>
<tfoot>
<tr>
<td colspan="2"><%= t('invoices.show.total_amount') %></td>
<td><%= t('offers.price_in_currency', price: invoice.total) %></td>
<td><%= t('offers.price_in_currency', price: @invoice.total) %></td>
</tr>
</tfoot>
</table>
Expand Down
15 changes: 15 additions & 0 deletions app/components/modals/pay_invoice/invoice_information/component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Modals
module PayInvoice
module InvoiceInformation
class Component < ApplicationViewComponent
attr_reader :invoice

def initialize(invoice:)
super

@invoice = invoice
end
end
end
end
end
5 changes: 3 additions & 2 deletions app/controllers/invoices_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ def update
if update_predicate
format.turbo_stream do
render turbo_stream: [
turbo_stream.update('invoice_information', partial: 'invoices/invoice_information', locals: { invoice: @invoice }),
turbo_stream.toast(t(:updated), position: "right", background: 'linear-gradient(to right, #11998e, #38ef7d)')
turbo_stream.update('invoice_information',
Modals::PayInvoice::InvoiceInformation::Component.new(invoice: @invoice)),
turbo_stream.toast(t(:updated), position: "right", background: 'linear-gradient(to right, #11998e, #38ef7d)')
]
end

Expand Down

0 comments on commit baa40f1

Please sign in to comment.