2021-12-23 01:48:06 +01:00
class GroupOrderInvoicesController < ApplicationController
include Concerns :: SendGroupOrderInvoicePdf
def show
@group_order_invoice = GroupOrderInvoice . find ( params [ :id ] )
if FoodsoftConfig [ :contact ] [ :tax_number ]
respond_to do | format |
format . pdf do
send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig [ :contact ] [ :tax_number ]
end
end
2021-12-24 13:35:26 +01:00
else
raise RecordInvalid
2021-12-23 01:48:06 +01:00
end
2021-12-24 13:35:26 +01:00
rescue = > error
redirect_back fallback_location : root_path , notice : 'Something went wrong' , alert : I18n . t ( 'errors.general_msg' , msg : " #{ error } " + I18n . t ( 'errors.check_tax_number' ) )
2021-12-23 01:48:06 +01:00
end
def destroy
goi = GroupOrderInvoice . find ( params [ :id ] )
@order = goi . group_order . order
goi . destroy
respond_to do | format |
format . js
format . json { head :no_content }
end
end
2022-03-29 13:17:36 +02:00
def create_multiple
invoice_date = params [ :group_order_invoice ] [ :invoice_date ]
order_id = params [ :group_order_invoice ] [ :order_id ]
2022-03-30 11:45:40 +02:00
@order = Order . find ( order_id )
gos = GroupOrder . where ( " order_id = ? " , order_id )
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 . save!
2022-03-29 13:17:36 +02:00
end
redirect_back fallback_location : root_path
rescue = > error
redirect_back fallback_location : root_path , notice : 'Something went wrong' , :alert = > I18n . t ( 'errors.general_msg' , :msg = > error )
end
2021-12-23 01:48:06 +01:00
def create
go = GroupOrder . find ( params [ :group_order ] )
2022-03-30 11:45:40 +02:00
@order = go . order
2021-12-24 13:35:26 +01:00
GroupOrderInvoice . find_or_create_by! ( group_order_id : go . id )
2021-12-23 01:48:06 +01:00
respond_to do | format |
format . js
end
redirect_back fallback_location : root_path
rescue = > error
redirect_back fallback_location : root_path , notice : 'Something went wrong' , :alert = > I18n . t ( 'errors.general_msg' , :msg = > error )
end
2021-12-24 13:35:26 +01:00
end