wip multi orders
This commit is contained in:
parent
fd769509af
commit
f676497e43
29 changed files with 939 additions and 107 deletions
|
|
@ -1,6 +1,7 @@
|
|||
class Finance::BalancingController < Finance::BaseController
|
||||
def index
|
||||
@orders = Order.finished.page(params[:page]).per(@per_page).order('ends DESC')
|
||||
@multi_orders = MultiOrder.includes(:orders, :group_orders).page(params[:page]).per(@per_page).order('ends DESC')
|
||||
@orders = Order.finished.non_multi_order.page(params[:page]).per(@per_page).order('ends DESC')
|
||||
end
|
||||
|
||||
def new
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class GroupOrderInvoicesController < ApplicationController
|
|||
gos.each do |go|
|
||||
goi = GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
|
||||
goi.invoice_date = invoice_date
|
||||
goi.invoice_number = goi.generate_invoice_number(1)
|
||||
goi.invoice_number = goi.generate_invoice_number(GroupOrderInvoice, 1)
|
||||
goi.save!
|
||||
end
|
||||
respond_to do |format|
|
||||
|
|
|
|||
77
app/controllers/multi_orders_controller.rb
Normal file
77
app/controllers/multi_orders_controller.rb
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
class MultiOrdersController < ApplicationController
|
||||
before_action :set_multi_order, only: [:generate_ordergroup_invoices]
|
||||
def create
|
||||
orders = Order.where(id: multi_order_params[:order_ids_for_multi_order])
|
||||
|
||||
unclosed_orders = orders.select { |order| order.closed? == false }
|
||||
multi_orders = orders.select { |order| order.multi_order_id.present? }
|
||||
|
||||
if multi_order_params[:multi_order_ids_for_multi_multi_order].present?
|
||||
#TODO: do the i18n and add a test
|
||||
flash[:alert] = "Du kannst keine Multi-Bestellungen in eine Multi-Multi-Bestellung umwandeln."
|
||||
redirect_to finance_order_index_path
|
||||
return
|
||||
end
|
||||
if multi_orders.any? || unclosed_orders.any?
|
||||
#TODO: do the i18n and add a test
|
||||
flash[:alert] = "Die Bestellung ist noch nicht abgeschlossen oder ist bereits Teil einer Multi-Bestellung."
|
||||
redirect_to finance_order_index_path
|
||||
return
|
||||
end
|
||||
|
||||
begin
|
||||
@multi_order = MultiOrder.new
|
||||
@multi_order.orders = orders
|
||||
@multi_order.ends = orders.map(&:ends).max
|
||||
@multi_order.save!
|
||||
puts "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "#{@multi_order.errors.inspect}" + "
|
||||
" + "______________"+ "
|
||||
" + "______________"+ "
|
||||
" + "______________"
|
||||
|
||||
#create multi group orders
|
||||
all_group_orders = orders.flat_map(&:group_orders)
|
||||
|
||||
grouped_by_ordergroup = all_group_orders.group_by(&:ordergroup_id)
|
||||
|
||||
grouped_by_ordergroup.each do |ordergroup_id, group_orders|
|
||||
multi_group_order = MultiGroupOrder.create!(
|
||||
multi_order: @multi_order, group_orders: group_orders
|
||||
)
|
||||
|
||||
# Now, associate each group_order with the new multi_group_order
|
||||
group_orders.each do |group_order|
|
||||
group_order.update!(multi_group_order: multi_group_order)
|
||||
end
|
||||
end
|
||||
redirect_to finance_order_index_path
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
flash[:alert] = t('errors.general_msg', msg: e.message)
|
||||
redirect_to finance_order_index_path
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def generate_ordergroup_invoices
|
||||
@multi_order.group_orders.group_by(&:ordergroup_id).each do |_, group_orders|
|
||||
OrdergroupInvoice.create!(group_orders: group_orders)
|
||||
end
|
||||
redirect_to finance_order_index_path, notice: t('finance.balancing.close.notice')
|
||||
rescue StandardError => e
|
||||
redirect_to finance_order_index_path, alert: t('errors.general_msg', msg: e.message)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_multi_order
|
||||
@multi_order = MultiOrder.find(params[:id])
|
||||
end
|
||||
|
||||
def multi_order_params
|
||||
params.permit(:id, order_ids_for_multi_order: [], multi_order_ids_for_multi_multi_order: [])
|
||||
end
|
||||
end
|
||||
56
app/controllers/ordergroup_invoices_controller.rb
Normal file
56
app/controllers/ordergroup_invoices_controller.rb
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
class OrdergroupInvoicesController < ApplicationController
|
||||
include Concerns::SendGroupOrderInvoicePdf
|
||||
before_action :authenticate_finance
|
||||
# download create and new ordergroupinvoice
|
||||
# has multiple group orders and one ordergroup
|
||||
|
||||
def new
|
||||
@ordergroup_invoice = OrdergroupInvoice.new
|
||||
@ordergroup_invoice.payment_method = FoodsoftConfig[:ordergroup_invoices][:payment_method] || I18n.t('activerecord.attributes.ordergroup_invoice.payment_method')
|
||||
@ordergroup_invoice.sepa_sequence_type = params[:sepa_sequence_type]
|
||||
end
|
||||
|
||||
def show
|
||||
@ordergroup_invoice = OrdergroupInvoice.find(params[:id])
|
||||
raise RecordInvalid unless FoodsoftConfig[:contact][:tax_number]
|
||||
|
||||
respond_to do |format|
|
||||
format.html do
|
||||
send_group_order_invoice_pdf @ordergroup_invoice if FoodsoftConfig[:contact][:tax_number]
|
||||
end
|
||||
format.pdf do
|
||||
send_group_order_invoice_pdf @ordergroup_invoice if FoodsoftConfig[:contact][:tax_number]
|
||||
end
|
||||
end
|
||||
rescue ActiveRecord::RecordInvalid => e
|
||||
redirect_back fallback_location: root_path, notice: 'Something went wrong', alert: I18n.t('errors.general_msg', msg: "#{e} " + I18n.t('errors.check_tax_number'))
|
||||
end
|
||||
|
||||
def create
|
||||
gos = GroupOrder.where(id: params[:group_order_ids])
|
||||
begin
|
||||
OrdergroupInvoice.create!(group_order_ids: gos)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
rescue StandardError => e
|
||||
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => e)
|
||||
end
|
||||
end
|
||||
|
||||
def create_multiple
|
||||
invoice_date = params[:ordergroup_invoce][:invoice_date]
|
||||
multi_order_id = params[:ordergroup_invoce][:multi_order_id]
|
||||
@multi_order = MultiOrder.find(multi_order_id)
|
||||
multi_group_orders = MultiGroupOrder.where("multi_order_id = ?", multi_order_id)
|
||||
mutli_group_orders.each do |multi_group_order|
|
||||
ordergroup_invoice = OrdergroupInvoice.find_or_create_by!(multi_group_order: multi_group_order)
|
||||
ordergroup_invoice.invoice_date = invoice_date
|
||||
ordergroup_invoice.invoice_number = ordergroup_invoice.generate_invoice_number(OrdergroupInvoice, 1)
|
||||
ordergroup_invoice.save!
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
10
app/helpers/invoice_helper.rb
Normal file
10
app/helpers/invoice_helper.rb
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
module InvoiceHelper
|
||||
def generate_invoice_number(instance, count)
|
||||
trailing_number = count.to_s.rjust(4, '0')
|
||||
if GroupOrderInvoice.find_by(invoice_number: instance.invoice_date.strftime("%Y%m%d") + trailing_number) || OrdergroupInvoice.find_by(invoice_number: instance.invoice_date.strftime("%Y%m%d") + trailing_number)
|
||||
generate_invoice_number(instance, count.to_i + 1)
|
||||
else
|
||||
instance.invoice_date.strftime("%Y%m%d") + trailing_number
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -10,6 +10,9 @@ class GroupOrder < ApplicationRecord
|
|||
has_many :order_articles, through: :group_order_articles
|
||||
has_one :financial_transaction
|
||||
has_one :group_order_invoice
|
||||
belongs_to :ordergroup_invoice, optional: true
|
||||
belongs_to :multi_group_order, optional: true
|
||||
belongs_to :multi_order, optional: true
|
||||
belongs_to :updated_by, optional: true, class_name: 'User', foreign_key: 'updated_by_user_id'
|
||||
|
||||
validates :order_id, presence: true
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
class GroupOrderInvoice < ApplicationRecord
|
||||
include InvoiceHelper
|
||||
|
||||
belongs_to :group_order
|
||||
validates_presence_of :group_order
|
||||
|
|
@ -13,19 +14,10 @@ class GroupOrderInvoice < ApplicationRecord
|
|||
FNAL: "Letztmalige Lastschrift"
|
||||
}
|
||||
|
||||
def generate_invoice_number(count)
|
||||
trailing_number = count.to_s.rjust(4, '0')
|
||||
if GroupOrderInvoice.find_by(invoice_number: self.invoice_date.strftime("%Y%m%d") + trailing_number)
|
||||
generate_invoice_number(count.to_i + 1)
|
||||
else
|
||||
self.invoice_date.strftime("%Y%m%d") + trailing_number
|
||||
end
|
||||
end
|
||||
|
||||
def tax_number_set
|
||||
if FoodsoftConfig[:contact][:tax_number].blank?
|
||||
errors.add(:group_order_invoice, "Keine Steuernummer in FoodsoftConfig :contact gesetzt")
|
||||
end
|
||||
return unless FoodsoftConfig[:contact][:tax_number].blank?
|
||||
|
||||
errors.add(:group_order_invoice, "Keine Steuernummer in FoodsoftConfig :contact gesetzt")
|
||||
end
|
||||
|
||||
def mark_sepa_downloaded
|
||||
|
|
@ -40,7 +32,7 @@ class GroupOrderInvoice < ApplicationRecord
|
|||
|
||||
def init
|
||||
self.invoice_date = Time.now unless invoice_date
|
||||
self.invoice_number = generate_invoice_number(1) unless self.invoice_number
|
||||
self.invoice_number = generate_invoice_number(self, 1) unless self.invoice_number
|
||||
self.payment_method = group_order&.financial_transaction&.financial_transaction_type&.name || FoodsoftConfig[:group_order_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.group_order_invoice.payment_method') unless self.payment_method
|
||||
end
|
||||
|
||||
|
|
@ -54,7 +46,7 @@ class GroupOrderInvoice < ApplicationRecord
|
|||
invoice_data[:pickup] = order.pickup
|
||||
invoice_data[:supplier] = order.supplier&.name
|
||||
invoice_data[:ordergroup] = group_order.ordergroup
|
||||
invoice_data[:group_order] = group_order
|
||||
invoice_data[:group_order_ids] = [group_order.id]
|
||||
invoice_data[:invoice_number] = invoice_number
|
||||
invoice_data[:invoice_date] = invoice_date
|
||||
invoice_data[:tax_number] = FoodsoftConfig[:contact][:tax_number]
|
||||
|
|
|
|||
21
app/models/multi_group_order.rb
Normal file
21
app/models/multi_group_order.rb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
class MultiGroupOrder < ApplicationRecord
|
||||
belongs_to :multi_order
|
||||
has_many :group_orders, dependent: :nullify
|
||||
|
||||
after_destroy :delete_ordergroup_invoices
|
||||
|
||||
def ordergroup_invoice
|
||||
#TODO: delete if deleted
|
||||
group_orders.joins(:ordergroup_invoice).first&.ordergroup_invoice
|
||||
end
|
||||
|
||||
def ordergroup
|
||||
ordergroup_invoice&.ordergroup
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delete_ordergroup_invoices
|
||||
ordergroup_invoice&.destroy
|
||||
end
|
||||
end
|
||||
48
app/models/multi_order.rb
Normal file
48
app/models/multi_order.rb
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
class MultiOrder < ApplicationRecord
|
||||
has_many :orders, dependent: :nullify
|
||||
has_many :order_articles, through: :orders
|
||||
has_many :multi_group_orders, dependent: :destroy
|
||||
has_many :group_orders, through: :multi_group_orders
|
||||
has_many :ordergroups, through: :group_orders
|
||||
#TODO: wenn groupOrderInvoice existiert, dann fehler schmeißen..
|
||||
has_many :ordergroup_invoices, through: :group_orders
|
||||
|
||||
#make sure order has no multi_order_id
|
||||
#make sure orders are not in a multi_order
|
||||
before_create :check_orders
|
||||
|
||||
def name
|
||||
orders.map(&:name).join(', ')
|
||||
end
|
||||
|
||||
def closed?
|
||||
orders.all?(&:closed?)
|
||||
end
|
||||
|
||||
def stockit?
|
||||
orders.all?(&:stockit?)
|
||||
end
|
||||
|
||||
def updated_by
|
||||
orders.map(&:updated_by).compact.first
|
||||
end
|
||||
def updated_at
|
||||
orders.map(&:updated_at).compact.first
|
||||
end
|
||||
def foodcoop_result
|
||||
orders.map(&:foodcoop_result).compact_blank.sum
|
||||
end
|
||||
|
||||
private
|
||||
def check_orders
|
||||
orders.each do |order|
|
||||
errors.add(:base, "Order #{order.name} is already in a multi order") unless order.multi_order_id.nil?
|
||||
#closed==abgerechnet
|
||||
errors.add(:base, "Order #{order.name} not closed") unless order.closed?
|
||||
end
|
||||
if errors.any?
|
||||
errors.add(:base, "Cannot create multi order with unfinished orders")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -10,6 +10,7 @@ class Order < ApplicationRecord
|
|||
has_many :comments, -> { order('created_at') }, class_name: 'OrderComment'
|
||||
has_many :stock_changes
|
||||
belongs_to :invoice, optional: true
|
||||
belongs_to :multi_order, optional: true, inverse_of: :orders
|
||||
belongs_to :supplier, optional: true
|
||||
belongs_to :updated_by, class_name: 'User', foreign_key: 'updated_by_user_id'
|
||||
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'
|
||||
|
|
@ -44,6 +45,8 @@ class Order < ApplicationRecord
|
|||
scope :finished, -> { where(state: %w[finished received closed]).order(ends: :desc) }
|
||||
scope :finished_not_closed, -> { where(state: %w[finished received]).order(ends: :desc) }
|
||||
|
||||
scope :non_multi_order, -> { where(multi_order_id: nil) }
|
||||
|
||||
# Allow separate inputs for date and time
|
||||
# with workaround for https://github.com/einzige/date_time_attribute/issues/14
|
||||
include DateTimeAttributeValidate
|
||||
|
|
|
|||
60
app/models/ordergroup_invoice.rb
Normal file
60
app/models/ordergroup_invoice.rb
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
class OrdergroupInvoice < ApplicationRecord
|
||||
include InvoiceHelper
|
||||
|
||||
belongs_to :multi_group_order, optional: true
|
||||
|
||||
has_many :group_orders, dependent: :nullify
|
||||
validates_presence_of :invoice_number
|
||||
validates_uniqueness_of :invoice_number
|
||||
validate :tax_number_set
|
||||
after_initialize :init, unless: :persisted?
|
||||
|
||||
def init
|
||||
self.invoice_date = Time.now unless invoice_date
|
||||
self.invoice_number = generate_invoice_number(self, 1) unless self.invoice_number
|
||||
self.payment_method = group_orders.first&.financial_transaction&.financial_transaction_type&.name || FoodsoftConfig[:group_order_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.group_order_invoice.payment_method') unless self.payment_method
|
||||
end
|
||||
|
||||
def ordergroup
|
||||
return if group_orders.empty?
|
||||
|
||||
group_orders.first.ordergroup
|
||||
end
|
||||
|
||||
def tax_number_set
|
||||
return if FoodsoftConfig[:contact][:tax_number].present?
|
||||
|
||||
errors.add(:cumulative_invoice, "Keine Steuernummer in FoodsoftConfig :contact gesetzt")
|
||||
end
|
||||
|
||||
def name
|
||||
I18n.t('activerecord.attributes.group_order_invoice.name') + "_#{invoice_number}"
|
||||
end
|
||||
|
||||
def load_data_for_invoice
|
||||
invoice_data = {}
|
||||
order = group_orders.map(&:order).first
|
||||
invoice_data[:pickup] = order.pickup
|
||||
invoice_data[:supplier] = order.supplier&.name
|
||||
invoice_data[:ordergroup] = group_orders.first.ordergroup
|
||||
invoice_data[:group_order_ids] = group_orders.pluck(:id)
|
||||
invoice_data[:invoice_number] = invoice_number
|
||||
invoice_data[:invoice_date] = invoice_date
|
||||
invoice_data[:tax_number] = FoodsoftConfig[:contact][:tax_number]
|
||||
invoice_data[:payment_method] = payment_method
|
||||
invoice_data[:order_articles] = {}
|
||||
group_orders.map(&:order_articles).flatten.each do |order_article|
|
||||
# Get the result of last time ordering, if possible
|
||||
# goa = group_orders.group_order_articles.detect { |tmp_goa| tmp_goa.order_article_id == order_article.id }
|
||||
goa = group_orders.map(&:group_order_articles).flatten.detect { |tmp_goa| tmp_goa.order_article_id == order_article.id }
|
||||
# Build hash with relevant data
|
||||
invoice_data[:order_articles][order_article.id] = {
|
||||
:price => order_article.article.fc_price,
|
||||
:quantity => (goa ? goa.quantity : 0),
|
||||
:total_price => (goa ? goa.total_price : 0),
|
||||
:tax => order_article.article.tax
|
||||
}
|
||||
end
|
||||
invoice_data
|
||||
end
|
||||
end
|
||||
22
app/views/finance/balancing/_multi_order_row.html.haml
Normal file
22
app/views/finance/balancing/_multi_order_row.html.haml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
%tr{:class => cycle("even","odd", :name => "multi_order"), 'data-multi_order_id' => multi_order.id}
|
||||
%td
|
||||
= check_box_tag "multi_order_ids_for_multi_multi_order[]", multi_order.id, false, class: "multi_order-checkbox", id: "multi_order_#{multi_order.id}_combine", data: { multi_order_id: multi_order.id }
|
||||
%td
|
||||
= "*Multi*"
|
||||
-multi_order.orders.each do |order|
|
||||
= link_to truncate(order.name), new_finance_order_path(order_id: order.id)
|
||||
=", " if order != multi_order.orders.last
|
||||
%td=h format_time(multi_order.ends) unless multi_order.ends.nil?
|
||||
%td= multi_order.closed? ? t('finance.balancing.orders.cleared', amount: number_to_currency(multi_order.foodcoop_result)) : t('finance.balancing.orders.ended')
|
||||
%td= show_user(multi_order.updated_by)
|
||||
%td{id: "group-multi_order-invoices-for-multi-order-#{multi_order.id}", class: 'expand-trigger'}
|
||||
- if multi_order.closed?
|
||||
-if FoodsoftConfig[:contact][:tax_number] && multi_order.group_orders.present?
|
||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.open_details_modal'), "#", remote: true, class: 'btn btn-small'
|
||||
-else
|
||||
= I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set')
|
||||
- else
|
||||
= t('orders.index.not_closed')
|
||||
%tr{:class => 'expanded-row', :id => "expanded-row-#{multi_order.id}", :style => 'display: none;'}
|
||||
%td{:colspan => '6'}
|
||||
= render partial: 'ordergroup_invoices/modal', locals: { multi_order: multi_order }
|
||||
26
app/views/finance/balancing/_order_row.html.haml
Normal file
26
app/views/finance/balancing/_order_row.html.haml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
%tr{:class => cycle("even","odd", :name => "order"), 'data-order_id' => order.id}
|
||||
%td
|
||||
= check_box_tag "order_ids_for_multi_order[]", order.id, false, class: "order-checkbox", id: "order_#{order.id}_combine", data: { order_id: order.id }
|
||||
%td= link_to truncate(order.name), new_finance_order_path(order_id: order.id)
|
||||
%td=h format_time(order.ends) unless order.ends.nil?
|
||||
%td= order.closed? ? t('finance.balancing.orders.cleared', amount: number_to_currency(order.foodcoop_result)) : t('finance.balancing.orders.ended')
|
||||
%td= show_user(order.updated_by)
|
||||
%td{id: "group-order-invoices-for-order-#{order.id}", class: 'expand-trigger'}
|
||||
- if order.closed?
|
||||
-if FoodsoftConfig[:contact][:tax_number] && order.ordergroups.present?
|
||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.open_details_modal'), "#", remote: true, class: 'btn btn-small'
|
||||
-else
|
||||
= I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set')
|
||||
- else
|
||||
= t('orders.index.not_closed')
|
||||
%td
|
||||
- unless order.closed?
|
||||
- if current_user.role_orders?
|
||||
- unless order.stockit?
|
||||
= link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-small'
|
||||
- else
|
||||
= link_to t('orders.index.action_receive'), '#', class: 'btn btn-small disabled'
|
||||
= link_to t('finance.balancing.orders.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-small btn-primary'
|
||||
%tr{:class => 'expanded-row', :id => "expanded-row-#{order.id}", :style => 'display: none;'}
|
||||
%td{:colspan => '7'}
|
||||
= render partial: 'group_order_invoices/modal', locals: { order: order }
|
||||
|
|
@ -1,42 +1,27 @@
|
|||
- unless @orders.empty?
|
||||
- unless @orders.empty? && @multi_orders.empty?
|
||||
- if Order.finished.count > 20
|
||||
= items_per_page
|
||||
= pagination_links_remote @orders
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
%th= t('.name')
|
||||
%th= t('.end')
|
||||
%th= t('.state')
|
||||
%th= heading_helper Order, :updated_by
|
||||
%th= heading_helper GroupOrderInvoice, :name
|
||||
%th
|
||||
%th
|
||||
%tbody
|
||||
- @orders.each do |order|
|
||||
%tr{:class => cycle("even","odd", :name => "order"), 'data-order_id' => order.id}
|
||||
%td= link_to truncate(order.name), new_finance_order_path(order_id: order.id)
|
||||
%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= show_user(order.updated_by)
|
||||
%td{id: "group-order-invoices-for-order-#{order.id}", class: 'expand-trigger'}
|
||||
- if order.closed?
|
||||
-if FoodsoftConfig[:contact][:tax_number] && order.ordergroups.present?
|
||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.open_details_modal'), "#", remote: true, class: 'btn btn-small'
|
||||
-else
|
||||
= I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set')
|
||||
- else
|
||||
= t('orders.index.not_closed')
|
||||
%td
|
||||
- unless order.closed?
|
||||
- if current_user.role_orders?
|
||||
- unless order.stockit?
|
||||
= link_to t('orders.index.action_receive'), receive_order_path(order), class: 'btn btn-small'
|
||||
- else
|
||||
= link_to t('orders.index.action_receive'), '#', class: 'btn btn-small disabled'
|
||||
= link_to t('.clear'), new_finance_order_path(order_id: order.id), class: 'btn btn-small btn-primary'
|
||||
%tr{:class => 'expanded-row', :id => "expanded-row-#{order.id}", :style => 'display: none;'}
|
||||
%td{:colspan => '6'}
|
||||
= render partial: 'group_order_invoices/modal', locals: { order: order }
|
||||
-# following posed a real problem, multiple submit buttons are within the same form, so only one of them will be submitted
|
||||
-# convert to javascript
|
||||
= form_with url: multi_orders_path, method: :post, local: true do |form|
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.combine')
|
||||
%th= t('.name')
|
||||
%th= t('.end')
|
||||
%th= t('.state')
|
||||
%th= heading_helper Order, :updated_by
|
||||
%th= heading_helper GroupOrderInvoice, :name
|
||||
%th
|
||||
%th
|
||||
%tbody
|
||||
- @multi_orders.each do |multi_order|
|
||||
= render partial: 'multi_order_row', locals: { multi_order: multi_order }
|
||||
- @orders.each do |order|
|
||||
= render partial: 'order_row', locals: { order: order }
|
||||
= form.submit "Zusammenführen", class: 'btn btn-primary'
|
||||
|
||||
- else
|
||||
%i= t('.no_closed_orders')
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@
|
|||
= f.label :invoice_date, I18n.t('activerecord.attributes.group_order_invoice.links.invoice_date')
|
||||
= f.date_field :invoice_date, {value: Date.today, max: Date.today, required: true}
|
||||
= f.hidden_field :order_id, value: order.id
|
||||
|
||||
= f.submit I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date'), class: 'btn btn'
|
||||
|
||||
%table.table.group-order-invoices-table
|
||||
|
|
|
|||
71
app/views/ordergroup_invoices/_links.html.haml
Normal file
71
app/views/ordergroup_invoices/_links.html.haml
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
|
||||
- show_generate_with_date = true
|
||||
- multi_order.multi_group_orders.each do |mgo|
|
||||
- if mgo.ordergroup_invoice.present?
|
||||
- show_generate_with_date = false
|
||||
- if show_generate_with_date
|
||||
= form_for :ordergroup_invoice, url: url_for('ordergroup_invoice#create_multiple'), remote: true do |f|
|
||||
= f.label :invoice_date, I18n.t('activerecord.attributes.group_order_invoice.links.invoice_date')
|
||||
= f.date_field :invoice_date, {value: Date.today, max: Date.today, required: true}
|
||||
= f.hidden_field :multi_order_id, value: multi_order.id
|
||||
|
||||
= f.submit I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date'), class: 'btn btn'
|
||||
|
||||
%table.table.group-order-invoices-table
|
||||
%thead
|
||||
%tr
|
||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.ordergroup')
|
||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.paid')
|
||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_downloaded')
|
||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_sequence_type')
|
||||
%th=I18n.t('activerecord.attributes.group_order_invoice.links.sepa_select')
|
||||
%th
|
||||
%tbody
|
||||
- multi_order.multi_group_orders.each do |mgo|
|
||||
-if mgo.ordergroup_invoice.present?
|
||||
- if mgo.ordergroup_invoice
|
||||
= mgo.ordergroup_invoice.invoice_number
|
||||
%tr.order-row{id: "multi_group_order_#{mgo.id}"}
|
||||
%td= link_to mgo.ordergroup&.name, edit_admin_ordergroup_path(mgo.ordergroup)
|
||||
%td
|
||||
= link_to I18n.t('activerecord.attributes.group_order_invoice.links.download'), ordergroup_invoice_path(mgo.ordergroup_invoice, :format => 'pdf'), class: 'btn btn-block'
|
||||
-# .div{id: "paid_#{mgo.ordergroup_invoice.id}"}
|
||||
-# = render :partial => "group_order_invoices/toggle_paid", locals: { group_order_invoice: go.group_order_invoice }
|
||||
-# %td
|
||||
-# .div{id: "sepa_downloaded_#{go.group_order_invoice.id}"}
|
||||
-# = render :partial => "group_order_invoices/toggle_sepa_downloaded", locals: { group_order_invoice: go.group_order_invoice }
|
||||
-# %td
|
||||
-# .div{id: "select_sepa_sequence_type_#{go.group_order_invoice.id}"}
|
||||
-# =render :partial => 'group_order_invoices/select_sepa_sequence_type', locals:{ group_order_invoice: go.group_order_invoice, group_order: go }
|
||||
-# %td
|
||||
-# = check_box_tag "group_order_ids_for_order_#{multi_order.id}", go.id, false, class: "group-order-checkbox", id: "group_order_#{go.id}_included_in_sepa", data: { order_id: go.id }
|
||||
-# = link_to I18n.t('activerecord.attributes.group_order_invoice.links.delete'), go.group_order_invoice, method: :delete, class: 'btn btn-block btn-danger', remote: true, data: { confirm: I18n.t('ui.confirm_delete', name: "Bestellgruppenrechnung für #{go.ordergroup.name}" ) }
|
||||
-# - else
|
||||
-# %tr
|
||||
-# %td
|
||||
-# = go.ordergroup&.name
|
||||
-# = 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: multi_order.id}, remote: true
|
||||
-# %td
|
||||
-# %td
|
||||
-# %td
|
||||
-# %td
|
||||
-# %td
|
||||
|
||||
-# - if multi_order.group_orders.map(&:group_order_invoice).compact.present?
|
||||
-# %tr.order-row
|
||||
-# %td= I18n.t('activerecord.attributes.group_order_invoice.links.actions_for_all')
|
||||
-# %td
|
||||
-# .div{id: "toggle_all_paid_#{multi_order.id}"}
|
||||
-# = render :partial => 'group_order_invoices/toggle_all_paid', locals: { order: order }
|
||||
-# %td
|
||||
-# .div{id: "toggle_all_sepa_downloaded_#{multi_order.id}"}
|
||||
-# = render :partial => 'group_order_invoices/toggle_all_sepa_downloaded', locals: { order: order }
|
||||
-# %td
|
||||
-# .div{id: "select_all_sepa_sequence_type_#{multi_order.id}"}
|
||||
-# = render :partial => 'group_order_invoices/select_all_sepa_sequence_type', locals: { order: multi_order }
|
||||
-# %td
|
||||
-# .div{id: "select_all_sepa_#{multi_order.id}"}
|
||||
-# = render :partial => 'group_order_invoices/collective_direct_debit', locals: { order: multi_order }
|
||||
-# %td
|
||||
-# = link_to I18n.t('activerecord.attributes.group_order_invoice.links.download_all_zip'), download_all_group_order_invoices_path(multi_order), class: 'btn btn-block'
|
||||
2
app/views/ordergroup_invoices/_modal.html.haml
Normal file
2
app/views/ordergroup_invoices/_modal.html.haml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
.div{id: "multi_order_#{multi_order.id}_modal", class: 'multi-order-modal', data: { multi_order_id: multi_order.id, supplier: multi_order&.name } }
|
||||
= render :partial => 'ordergroup_invoices/links', locals: { multi_order: multi_order }
|
||||
Loading…
Add table
Add a link
Reference in a new issue