28 lines
1.1 KiB
Ruby
28 lines
1.1 KiB
Ruby
|
if FoodsoftAutomaticInvoices.enabled?
|
||
|
Finance::BalancingController.class_eval do
|
||
|
def close
|
||
|
@order = Order.find(params[:id])
|
||
|
@type = FinancialTransactionType.find_by_id(params.permit(:type)[:type])
|
||
|
@order.close!(@current_user, @type)
|
||
|
note = t('finance.balancing.close.notice')
|
||
|
if @order.closed?
|
||
|
alert = t('finance.balancing.close.alert')
|
||
|
if FoodsoftConfig[:group_order_invoices]&.[](:use_automatic_invoices)
|
||
|
@order.group_orders.each do |go|
|
||
|
alert = t('finance.balancing.close.settings_not_set')
|
||
|
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
|
||
|
alert ||= t('finance.balancing.close.alert')
|
||
|
redirect_to finance_order_index_url, notice: note
|
||
|
rescue => error
|
||
|
redirect_to new_finance_order_url(order_id: @order.id), notice: note, alert: alert, msg: error.message
|
||
|
end
|
||
|
end
|
||
|
end
|