add functionality in views and controllers for generation of group order invoices
This commit is contained in:
parent
817c680c28
commit
50017fefa8
8 changed files with 41 additions and 4 deletions
|
@ -81,9 +81,21 @@ class Finance::BalancingController < Finance::BaseController
|
||||||
@order = Order.find(params[:id])
|
@order = Order.find(params[:id])
|
||||||
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
|
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
|
||||||
@order.close!(@current_user, @type)
|
@order.close!(@current_user, @type)
|
||||||
redirect_to finance_order_index_url, notice: t('finance.balancing.close.notice')
|
note = t('finance.balancing.close.notice')
|
||||||
|
if @order.closed?
|
||||||
|
if FoodsoftConfig[:group_order_invoices]&.[](:use) && FoodsoftConfig[:contact]&.[](:tax_number)
|
||||||
|
@order.group_orders.each do |go|
|
||||||
|
goi = GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
|
||||||
|
if goi.save!
|
||||||
|
NotifyGroupOrderInvoiceJob.perform_later(goi)
|
||||||
|
note = t('finance.balancing.close.notice_mail')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
redirect_to finance_order_index_url, notice: note
|
||||||
rescue => error
|
rescue => error
|
||||||
redirect_to new_finance_order_url(order_id: @order.id), alert: t('finance.balancing.close.alert', message: error.message)
|
redirect_to new_finance_order_url(order_id: @order.id), notice: note, alert: t('finance.balancing.close.alert', message: error.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Close the order directly, without automaticly updating ordergroups account balances
|
# Close the order directly, without automaticly updating ordergroups account balances
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
%th= t('.end')
|
%th= t('.end')
|
||||||
%th= t('.state')
|
%th= t('.state')
|
||||||
%th= heading_helper Order, :updated_by
|
%th= heading_helper Order, :updated_by
|
||||||
|
%th= heading_helper GroupOrderInvoice, :name
|
||||||
|
%th
|
||||||
%th
|
%th
|
||||||
%tbody
|
%tbody
|
||||||
- @orders.each do |order|
|
- @orders.each do |order|
|
||||||
|
@ -17,6 +19,14 @@
|
||||||
%td=h format_time(order.ends) unless order.ends.nil?
|
%td=h format_time(order.ends) unless order.ends.nil?
|
||||||
%td= order.closed? ? t('.cleared', amount: number_to_currency(order.foodcoop_result)) : t('.ended')
|
%td= order.closed? ? t('.cleared', amount: number_to_currency(order.foodcoop_result)) : t('.ended')
|
||||||
%td= show_user(order.updated_by)
|
%td= show_user(order.updated_by)
|
||||||
|
%td{id: "generate-invoice#{order.id}"}
|
||||||
|
- if order.closed?
|
||||||
|
-if FoodsoftConfig[:contact][:tax_number]
|
||||||
|
= render :partial => 'group_order_invoices/links', locals:{order: order}
|
||||||
|
-else
|
||||||
|
= I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set')
|
||||||
|
- else
|
||||||
|
= t('orders.index.not_closed')
|
||||||
%td
|
%td
|
||||||
- unless order.closed?
|
- unless order.closed?
|
||||||
- if current_user.role_orders?
|
- if current_user.role_orders?
|
||||||
|
|
11
app/views/group_order_invoices/_links.html.haml
Normal file
11
app/views/group_order_invoices/_links.html.haml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
.row
|
||||||
|
- order.group_orders.includes([:group_order_invoice, :ordergroup]).each do |go|
|
||||||
|
.row
|
||||||
|
= label_tag go.ordergroup.name
|
||||||
|
- if go.group_order_invoice
|
||||||
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download'), group_order_invoice_path(go.group_order_invoice, :format => 'pdf'), class: 'btn btn-small'
|
||||||
|
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.delete'), go.group_order_invoice, method: :delete, class: 'btn btn-danger btn-small', remote: true
|
||||||
|
- else
|
||||||
|
= button_to I18n.t('activerecord.attributes.group_order_invoice.links.generate'), group_order_invoices_path(:method => :post, group_order: go) ,class: 'btn btn-small', params: {id: order.id}, remote: true
|
||||||
|
%br
|
||||||
|
|
1
app/views/group_order_invoices/create.js.erb
Normal file
1
app/views/group_order_invoices/create.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$("#generate-invoice<%= params[:id] %>").html("<%= escape_javascript(render partial: 'links', locals: {order: @order}) %>");
|
1
app/views/group_order_invoices/destroy.js.erb
Normal file
1
app/views/group_order_invoices/destroy.js.erb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
$("#generate-invoice<%= @order.id %>").html("<%= escape_javascript(render partial: 'links', locals: {order: @order}) %>");
|
0
app/views/group_order_invoices/show.html.haml
Normal file
0
app/views/group_order_invoices/show.html.haml
Normal file
1
app/views/group_order_invoices/show.pdf.prawn
Normal file
1
app/views/group_order_invoices/show.pdf.prawn
Normal file
|
@ -0,0 +1 @@
|
||||||
|
pdf.text "Hello World"
|
|
@ -139,7 +139,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :group_order_invoices
|
||||||
resources :article_categories
|
resources :article_categories
|
||||||
|
|
||||||
########### Finance
|
########### Finance
|
||||||
|
@ -172,6 +172,7 @@ Rails.application.routes.draw do
|
||||||
get :unpaid, on: :collection
|
get :unpaid, on: :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
resources :links, controller: 'financial_links', only: [:create, :show] do
|
resources :links, controller: 'financial_links', only: [:create, :show] do
|
||||||
collection do
|
collection do
|
||||||
get :incomplete
|
get :incomplete
|
||||||
|
|
Loading…
Reference in a new issue