Skip to content

Commit

Permalink
updated ui
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegPhenomenon committed Nov 30, 2023
1 parent 1ca5444 commit b3bfdc6
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ class CallbackHandlerController < ApplicationController
param :event_name, String, desc: event_descr

def callback

puts '============ CALLBACK'
puts params
puts '============ CALLBACK'
Rails.logger.info '============ CALLBACK'
Rails.logger.info params
Rails.logger.info '============ CALLBACK'

payment_reference = params[:payment_reference]
response = EverypayResponse.call(payment_reference)
Expand Down
15 changes: 12 additions & 3 deletions app/controllers/invoice_creators_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
class InvoiceCreatorsController < ParentController
def index
@invoices = Invoice.where(initiator: 'billing_system').order(created_at: :desc)
@pagy, @invoices = pagy(Invoice.search(params).where(initiator: 'billing_system').order(created_at: :desc),
items: params[:per_page] ||= 25,
link_extra: 'data-turbo-action="advance"')
@min_amount = 0
@max_amount = 200_000
end

def new
Expand All @@ -25,12 +29,17 @@ def create

linkpay_params_mutation = params[:linkpay].merge(
invoice_number: @invoice.invoice_number,
transaction_amount: @invoice.transaction_amount,
transaction_amount: @invoice.transaction_amount
)

@linkpay = EverypayLinkGenerator.create(params: linkpay_params_mutation)
@invoice.everypay_response = {
@invoice.linkpay_info = {
linkpay: @linkpay,
customer_name: params[:linkpay][:customer_name],
customer_email: params[:linkpay][:customer_email],
description: params[:linkpay][:custom_field1],
custom_field2: params[:linkpay][:custom_field2],
invoice_number: @invoice.invoice_number
}

@invoice.save!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class InvoiceDetails::LinkpayInformationsController < ParentController
def show
@info = Invoice.find(params[:id])&.linkpay_info
end
end
9 changes: 9 additions & 0 deletions app/services/notify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ def self.call(response:)

parsed_response = notifier.parse_response(response)

puts '============ parsed_response'
puts parsed_response
puts '============ parsed_response'

Rails.logger.info '============ parsed_response'
Rails.logger.info parsed_response
Rails.logger.info '============ parsed_response'

order_number = if parsed_response[:order_reference].split(', ').size > 1
parsed_response[:order_reference].split(', ')[0].split(':')[1]
else
Expand All @@ -32,6 +40,7 @@ def self.call(response:)

notifier.update_invoice_state(parsed_response:, invoice:)
return unless invoice.paid?
return if invoice.billing_system?

url = notifier.get_update_payment_url[invoice.initiator.to_sym]
return notifier.define_for_deposit(invoice, url) if invoice.auction_deposit_prepayment?
Expand Down
123 changes: 101 additions & 22 deletions app/views/invoice_creators/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,108 @@
<div class="container mx-auto">
<div class='flex flex-row'>
<div>

<%= form_with url: invoice_creators_path,
method: :get,
data: { controller: 'debounce',
debounce_target: 'form',
turbo_action: "advance",
turbo_frame: "results",
action: 'input->debounce#search'
} do |form| %>
<%= form.search_field :invoice_number, value: params[:invoice_number],
class: 'w-full pl-3 pr-10 py-2 border-2 border-gray-200 rounded-xl hover:border-gray-300 focus:outline-none focus:border-blue-500 transition-colors mb-7 bg-white',
placeholder: 'Type by invoice' %>

<div class="flex flex-row items-center justify-evenly bg-gray-200 p-4 m-4">

<div>
<%= form.select :status, Invoice.statuses, {include_blank: 'Invoice status' }, { class: 'border-0 px-3 py-3 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150'} %>
</div>

<%= form.hidden_field :sort, value: params[:sort], data: { sort_link_target: "sort"} %>
<%= form.hidden_field :direction, value: params[:direction], data: { sort_link_target: "direction"} %>

<div class="w-full sm:w-1/2 pt-6 sm:pl-4 text-center mx-10"
data-controller="range-slider"
data-range-slider-min-value="<%= @min_amount %>"
data-range-slider-max-value="<%= @max_amount %>"
style="width: 250px;">

<div data-range-slider-target="slider"></div>

<%= form.hidden_field :min_amount,
value: params[:min_amount] || @min_amount,
data: { range_slider_target: "currentMin" } %>

<%= form.hidden_field :max_amount,
value: params[:max_amount] || @max_amount,
data: { range_slider_target: "currentMax" } %>

<div class="bottom-0 text-sm font-medium text-gray-500">
Invoice amount
</div>
</div>

<div>
<%= form.select :per_page, options_for_select([5, 10, 25, 50, 100],
selected: params[:per_page]), { }, { class: 'border-0 px-3 py-3 placeholder-gray-300 text-gray-600 bg-white rounded text-sm shadow focus:outline-none focus:ring w-full ease-linear transition-all duration-150'} %>
</div>

<div class='flex items-baseline justify-start'>
<p class="text-sm text-gray-700">
Total pages:
<span class="font-medium"><%= @pagy.pages %></span>
</p>
<%= form.number_field :page,
class: 'w-full px-2 py-2 border-2 border-gray-200 rounded-xl hover:border-gray-300 focus:outline-none focus:border-blue-500 transition-colors bg-white w-64' %>
</div>

</div>
<% end %>

<div class='flex flex-row justify-end'>
<%= link_to 'New Invoice', new_invoice_creator_path,
class: 'h-10 py-2 my-1 px-4 border border-transparent text-sm font-semibold rounded-md text-white bg-violet-700 hover:bg-violet-800 transition duration-150 ease-in-out shadow-md cursor-pointer' %>
</div>

<div>
<table class="min-w-full mt-6">
<thead>
<tr>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Invoice number</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Status</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">transaction_amount</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Linkpay URL</th>
</tr>
</thead>
<tbody id="invoices">
<% @invoices.each do |invoice| %>
<tr>
<td class="px-6 py-1 border-b border-gray-200"><%= invoice.invoice_number %></td>
<td class="px-6 py-1 border-b border-gray-200"><%= invoice.status %></td>
<td class="px-6 py-1 border-b border-gray-200"><%= invoice.transaction_amount %></td>
<td class="px-6 py-1 border-b border-gray-200 break-all"><%= invoice.everypay_response["linkpay"] if invoice.everypay_response.present? %></td>
</tr>
<% end %>
</tbody>
</table>
<%= turbo_frame_tag "results" do %>
<table class="min-w-full mt-6">
<thead>
<tr>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Invoice number</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Status</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">transaction_amount</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Linkpay Info</th>
<th class="px-6 py-1 border-b border-gray-200 bg-gray-50 text-left text-xs text-gray-500 uppercase">Everypay Response Info</th>
</tr>
</thead>
<tbody id="invoices">
<%= turbo_frame_tag "modal" %>
<% @invoices.each do |invoice| %>
<tr>
<td class="px-6 py-1 border-b border-gray-200"><%= invoice.invoice_number %></td>
<td class="px-6 py-1 border-b border-gray-200"><%= invoice.status %></td>
<td class="px-6 py-1 border-b border-gray-200"><%= invoice.transaction_amount %></td>
<td class="px-6 py-1 break-all border-b border-gray-200">
<%= link_to invoice_details_linkpay_information_path(invoice), class: 'w-6 h-6 p-2 rounded-full bg-blue-300 hover:bg-blue-500 text-black border-gray-300 flex items-center justify-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black text-center', data: { turbo_frame: 'modal' } do %>
<i class="fa-solid fa-info"></i>
<% end %>
</td>
<td class="px-6 py-1 break-all border-b border-gray-200">
<%= link_to invoice_details_everypay_response_path(invoice), class: 'w-6 h-6 p-2 rounded-full bg-blue-300 hover:bg-blue-500 text-black border-gray-300 flex items-center justify-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black text-center', data: { turbo_frame: 'modal' } do %>
<i class="fa-solid fa-info"></i>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>

<% if @pagy.pages > 1 %>
<div class="footer text-center mt-2">
<%== pagy_nav(@pagy) %>
</div>
<% end %>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions app/views/invoice_details/linkpay_informations/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= render 'shared/modal', title: 'Linkpay Informations' do %>
<%= JSON.pretty_generate(@info) %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/invoices/_invoice.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<% end %>

</td>
<td class="px-6 py-1 break-all border-b border-gray-200">
<td class="px-6 py-1 break-all border-b border-gray-200">
<%= link_to invoice_details_description_path(invoice), class: 'w-6 h-6 p-2 rounded-full bg-blue-300 hover:bg-blue-500 text-black border-gray-300 flex items-center justify-center focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-black text-center', data: { turbo_frame: 'modal' } do %>
<i class="fa-solid fa-info"></i>
<% end %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/shared/_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<%= tag.div data: { controller: "turbo-modal",
turbo_modal_target: "modal",
action: "turbo:submit-end->turbo-modal#submitEnd keyup@window->turbo-modal#closeWithKeyboard click@window->turbo-modal#closeBackground" },
class: "p-5 bg-yellow-100 absolute z-10 top-20 right-12 rounded-md break-words" do %>
class: "p-5 bg-yellow-100 absolute z-10 top-20 right-12 rounded-md break-words w-96 max-w-full overflow-x-auto" do %>
<h1 class="font-bold text-4xl"><%= title %></h1>

<pre class='break-words'>
<pre class='break-words whitespace-pre-wrap'>
<%= yield %>
</pre>

<%= button_tag "Close", data: { action: "turbo-modal#hideModal" }, type: "button", class: "rounded-lg py-3 px-5 bg-red-600 text-white" %>
<% end %>
<% end %>
<% end %>
2 changes: 1 addition & 1 deletion app/views/shared/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<% end %>

<%= link_to invoice_creators_path, class: 'px-6 py-1 flex flex-col md:flex-row md:items-center' do %>
<i class="fa-solid fa-money-bill-transfer"></i> <span class="ml-2">Invoice creator</span>
<i class="fa-solid fa-square-plus"></i> <span class="ml-2">Invoice creator</span>
<% end %>

<%= link_to white_codes_path, class: 'px-6 py-1 flex flex-col md:flex-row md:items-center' do %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
namespace :invoice_details do
resources :payment_references, only: [:show]
resources :everypay_response, only: [:show]
resources :linkpay_informations, only: [:show]
resources :directo, only: [:show]
resources :descriptions, only: [:show]
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231130114315_add_linkpay_info_to_invoices.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddLinkpayInfoToInvoices < ActiveRecord::Migration[7.0]
def change
add_column :invoices, :linkpay_info, :jsonb, default: {}, null: true
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b3bfdc6

Please sign in to comment.