Merge pull request #421 from foodcoop1040/edit_links
Add page to edit deliveries and orders linked to an invoice
This commit is contained in:
commit
4433a665e4
12 changed files with 72 additions and 34 deletions
|
@ -14,9 +14,21 @@ class Finance::InvoicesController < ApplicationController
|
||||||
@invoice = Invoice.new :supplier_id => params[:supplier_id]
|
@invoice = Invoice.new :supplier_id => params[:supplier_id]
|
||||||
@invoice.deliveries << Delivery.find_by_id(params[:delivery_id]) if params[:delivery_id]
|
@invoice.deliveries << Delivery.find_by_id(params[:delivery_id]) if params[:delivery_id]
|
||||||
@invoice.orders << Order.find_by_id(params[:order_id]) if params[:order_id]
|
@invoice.orders << Order.find_by_id(params[:order_id]) if params[:order_id]
|
||||||
|
fill_deliveries_and_orders_collection @invoice.id, @invoice.supplier_id
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
fill_deliveries_and_orders_collection @invoice.id, @invoice.supplier_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def form_on_supplier_id_change
|
||||||
|
fill_deliveries_and_orders_collection params[:invoice_id], params[:supplier_id]
|
||||||
|
render :layout => false
|
||||||
|
end
|
||||||
|
|
||||||
|
def fill_deliveries_and_orders_collection(invoice_id, supplier_id)
|
||||||
|
@deliveries_collection = Delivery.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ?)', invoice_id, supplier_id).order(:delivered_on)
|
||||||
|
@orders_collection = Order.where('invoice_id = ? OR (invoice_id IS NULL AND supplier_id = ? AND state = ?)', invoice_id, supplier_id, 'finished').order(:ends)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
|
8
app/helpers/finance/invoices_helper.rb
Normal file
8
app/helpers/finance/invoices_helper.rb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
module Finance::InvoicesHelper
|
||||||
|
def format_delivery_item delivery
|
||||||
|
format_date(delivery.delivered_on)
|
||||||
|
end
|
||||||
|
def format_order_item order
|
||||||
|
"#{format_date(order.ends)} (#{number_to_currency(order.sum)})"
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,24 +1,20 @@
|
||||||
= simple_form_for([:finance, @invoice]) do |f|
|
= simple_form_for([:finance, @invoice]) do |f|
|
||||||
= f.association :deliveries, multiple: true, as: :hidden
|
- if @invoice.created_at
|
||||||
= f.association :orders, multiple: true, as: :hidden
|
.fold-line
|
||||||
|
.control-group
|
||||||
- if @invoice.deliveries.first
|
%label.control-label{for: 'created_at'}
|
||||||
%p= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_delivery'), [@invoice.supplier,@invoice.deliveries.first])).html_safe
|
= Invoice.human_attribute_name(:created_at)
|
||||||
- if @invoice.orders.first
|
.controls.control-text#article_fc_price
|
||||||
%p= t('finance.invoices.linked', what_link: link_to(t('finance.invoices.linked_order'), new_finance_order_path(order_id: @invoice.orders.first.id))).html_safe
|
= format_date @invoice.created_at
|
||||||
|
.control-group
|
||||||
.fold-line
|
%label.control-label{for: 'created_by'}
|
||||||
.control-group
|
= Invoice.human_attribute_name(:created_by)
|
||||||
%label.control-label{for: 'created_at'}
|
.controls.control-text#article_fc_price
|
||||||
= Invoice.human_attribute_name(:created_at)
|
= show_user @invoice.created_by
|
||||||
.controls.control-text#article_fc_price
|
|
||||||
= format_date @invoice.created_at
|
|
||||||
.control-group
|
|
||||||
%label.control-label{for: 'created_by'}
|
|
||||||
= Invoice.human_attribute_name(:created_by)
|
|
||||||
.controls.control-text#article_fc_price
|
|
||||||
= show_user @invoice.created_by
|
|
||||||
= f.association :supplier, collection: Supplier.order(:name), hint: false
|
= f.association :supplier, collection: Supplier.order(:name), hint: false
|
||||||
|
- if Delivery.any?
|
||||||
|
= f.association :deliveries, collection: @deliveries_collection, input_html: {size: 10}, multiple: true, label_method: method(:format_delivery_item)
|
||||||
|
= f.association :orders, collection: @orders_collection, multiple: true, label_method: method(:format_order_item)
|
||||||
= f.input :number
|
= f.input :number
|
||||||
= f.input :date, as: :date_picker
|
= f.input :date, as: :date_picker
|
||||||
- if current_user.role_finance?
|
- if current_user.role_finance?
|
||||||
|
@ -30,3 +26,5 @@
|
||||||
.form-actions
|
.form-actions
|
||||||
= f.submit class: 'btn'
|
= f.submit class: 'btn'
|
||||||
= link_to t('ui.or_cancel'), :back
|
= link_to t('ui.or_cancel'), :back
|
||||||
|
|
||||||
|
= render :partial => 'form_js', :locals => {:invoice_id => invoice_id}
|
||||||
|
|
14
app/views/finance/invoices/_form_js.html.haml
Normal file
14
app/views/finance/invoices/_form_js.html.haml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
- content_for :javascript do
|
||||||
|
:javascript
|
||||||
|
$(function() {
|
||||||
|
if ($('#invoice_delivery_ids').length)
|
||||||
|
$('#invoice_delivery_ids').select2();
|
||||||
|
$('#invoice_order_ids').select2();
|
||||||
|
$('#invoice_supplier_id').change(function(e) {
|
||||||
|
$.ajax({
|
||||||
|
url: '#{form_on_supplier_id_change_finance_invoices_path}',
|
||||||
|
type: 'get',
|
||||||
|
data: {invoice_id: #{invoice_id}, supplier_id: $('#invoice_supplier_id').val()}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,2 +1,2 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
= render :partial => 'form'
|
= render :partial => 'form', :locals => {:invoice_id => @invoice.id}
|
||||||
|
|
16
app/views/finance/invoices/form_on_supplier_id_change.js.erb
Normal file
16
app/views/finance/invoices/form_on_supplier_id_change.js.erb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
<%
|
||||||
|
deliveries_data = @deliveries_collection.map {|d| { id: d.id, text: format_delivery_item(d) } }
|
||||||
|
orders_data = @orders_collection.map {|o| { id: o.id, text: format_order_item(o) } }
|
||||||
|
%>
|
||||||
|
(function() {
|
||||||
|
function update_select2(id, data) {
|
||||||
|
var ele = $(id);
|
||||||
|
if (!ele.length)
|
||||||
|
return;
|
||||||
|
ele.select2("destroy");
|
||||||
|
ele.html("");
|
||||||
|
ele.select2({data: data});
|
||||||
|
}
|
||||||
|
update_select2("#invoice_delivery_ids", <%= raw deliveries_data.to_json %>);
|
||||||
|
update_select2("#invoice_order_ids", <%= raw orders_data.to_json %>);
|
||||||
|
})();
|
|
@ -1,3 +1,3 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
= render :partial => 'form'
|
= render :partial => 'form', :locals => {:invoice_id => 0}
|
||||||
= link_to t('ui.or_cancel'), finance_invoices_path
|
= link_to t('ui.or_cancel'), finance_invoices_path
|
||||||
|
|
|
@ -780,9 +780,6 @@ de:
|
||||||
index:
|
index:
|
||||||
action_new: Neue Rechnung anlegen
|
action_new: Neue Rechnung anlegen
|
||||||
title: Rechnungen
|
title: Rechnungen
|
||||||
linked: Diese Rechnung ist mit %{what_link} verknüpft.
|
|
||||||
linked_delivery: einer Lieferung
|
|
||||||
linked_order: einer Bestellung
|
|
||||||
new:
|
new:
|
||||||
title: Neue Rechnung anlegen
|
title: Neue Rechnung anlegen
|
||||||
show:
|
show:
|
||||||
|
|
|
@ -793,9 +793,6 @@ en:
|
||||||
index:
|
index:
|
||||||
action_new: Create new invoice
|
action_new: Create new invoice
|
||||||
title: Invoices
|
title: Invoices
|
||||||
linked: This invoice is linked to %{what_link}.
|
|
||||||
linked_delivery: a delivery
|
|
||||||
linked_order: an order
|
|
||||||
new:
|
new:
|
||||||
title: Create new invoice
|
title: Create new invoice
|
||||||
show:
|
show:
|
||||||
|
|
|
@ -775,9 +775,6 @@ fr:
|
||||||
index:
|
index:
|
||||||
action_new: Ajouter une facture
|
action_new: Ajouter une facture
|
||||||
title: Factures
|
title: Factures
|
||||||
linked: Cette facture est associée à %{what_link}.
|
|
||||||
linked_delivery: un réapprovisionnement
|
|
||||||
linked_order: une commande
|
|
||||||
new:
|
new:
|
||||||
title: Ajouter une facture
|
title: Ajouter une facture
|
||||||
show:
|
show:
|
||||||
|
|
|
@ -773,9 +773,6 @@ nl:
|
||||||
index:
|
index:
|
||||||
action_new: Nieuwe factuur toevoegen
|
action_new: Nieuwe factuur toevoegen
|
||||||
title: Facturen
|
title: Facturen
|
||||||
linked: Deze factuur is aan %{what_link} gekoppeld.
|
|
||||||
linked_delivery: een levering
|
|
||||||
linked_order: een bestelling
|
|
||||||
new:
|
new:
|
||||||
title: Nieuwe factuur toevoegen
|
title: Nieuwe factuur toevoegen
|
||||||
show:
|
show:
|
||||||
|
|
|
@ -156,7 +156,9 @@ Foodsoft::Application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :invoices
|
resources :invoices do
|
||||||
|
get :form_on_supplier_id_change, on: :collection
|
||||||
|
end
|
||||||
|
|
||||||
resources :ordergroups, only: [:index] do
|
resources :ordergroups, only: [:index] do
|
||||||
resources :financial_transactions, as: :transactions
|
resources :financial_transactions, as: :transactions
|
||||||
|
|
Loading…
Reference in a new issue