wip on generating invoices with date
This commit is contained in:
parent
76be8fdf1a
commit
368375818e
5 changed files with 37 additions and 24 deletions
|
@ -29,21 +29,13 @@ class GroupOrderInvoicesController < ApplicationController
|
|||
def create_multiple
|
||||
invoice_date = params[:group_order_invoice][:invoice_date]
|
||||
order_id = params[:group_order_invoice][:order_id]
|
||||
puts "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "#{invoice_date}" + "
|
||||
" + "______________"+ "
|
||||
" + "______________"+ "
|
||||
" + "______________"
|
||||
raise "#{invoice_date}"
|
||||
gos = GroupOrder.find_by(order_id: params[:order_id])
|
||||
for go in gos
|
||||
GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
@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!
|
||||
end
|
||||
redirect_back fallback_location: root_path
|
||||
rescue => error
|
||||
|
@ -52,6 +44,7 @@ class GroupOrderInvoicesController < ApplicationController
|
|||
|
||||
def create
|
||||
go = GroupOrder.find(params[:group_order])
|
||||
@order = go.order
|
||||
GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
|
|
|
@ -7,10 +7,18 @@ class GroupOrderInvoice < ApplicationRecord
|
|||
|
||||
def generate_invoice_number(count)
|
||||
trailing_number = count.to_s.rjust(4, '0')
|
||||
if GroupOrderInvoice.find_by(invoice_number: Time.now.strftime("%Y%m%d") + trailing_number)
|
||||
puts "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "#{self.invoice_date}" + "
|
||||
" + "______________"+ "
|
||||
" + "______________"+ "
|
||||
" + "______________"
|
||||
if GroupOrderInvoice.find_by(invoice_number: self.invoice_date.strftime("%Y%m%d") + trailing_number)
|
||||
generate_invoice_number(count.to_i + 1)
|
||||
else
|
||||
Time.now.strftime("%Y%m%d") + trailing_number
|
||||
self.invoice_date.strftime("%Y%m%d") + trailing_number
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -21,8 +29,8 @@ class GroupOrderInvoice < ApplicationRecord
|
|||
end
|
||||
|
||||
def init
|
||||
self.invoice_date = Time.now unless invoice_date
|
||||
self.invoice_number = generate_invoice_number(1) unless self.invoice_number
|
||||
self.invoice_date = Time.now unless self.invoice_date
|
||||
self.payment_method = FoodsoftConfig[:group_order_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.group_order_invoice.payment_method') unless self.payment_method
|
||||
end
|
||||
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
.row
|
||||
= form_for :group_order_invoice, url: url_for('group_order_invoice#create_multiple') do |f|
|
||||
= f.date_field :invoice_date, {}
|
||||
= f.hidden_field :order_id, value: order.id
|
||||
= f.submit 'Alle Rechnungen mit Datum erzeugen', class: 'btn btn small'
|
||||
.column.small-12
|
||||
- show_generate_with_date = true
|
||||
- order.group_orders.each do |go|
|
||||
- if go.group_order_invoice.present?
|
||||
- show_generate_with_date = false
|
||||
- if show_generate_with_date
|
||||
= form_for :group_order_invoice, url: url_for('group_order_invoice#create_multiple') do |f|
|
||||
= f.label :invoice_date, I18n.t('activerecord.attributes.group_order_invoice.links.invoice_date')
|
||||
= f.date_field :invoice_date, {}
|
||||
= f.hidden_field :order_id, value: order.id
|
||||
= f.submit I18n.t('activerecord.attributes.group_order_invoice.links.generate_with_date'), class: 'btn btn small'
|
||||
|
||||
- order.group_orders.includes([:group_order_invoice, :ordergroup]).each do |go|
|
||||
.row
|
||||
|
|
|
@ -94,8 +94,11 @@ de:
|
|||
name: Bestellgruppenrechnung
|
||||
links:
|
||||
delete: Rechnung löschen
|
||||
generate: Rechnung erzeugen
|
||||
download: Rechnung herunterladen
|
||||
generate: Rechnung erzeugen
|
||||
invoice_date: Datum der Bestellgruppenrechnung
|
||||
generate_with_date: setzen & erzeugen
|
||||
|
||||
payment_method: Guthaben
|
||||
tax_number_not_set: Steuernummer in den Einstellungen nicht gesetzt
|
||||
invoice:
|
||||
|
|
|
@ -94,8 +94,10 @@ en:
|
|||
name: Group order invoice
|
||||
links:
|
||||
delete: delete invoice
|
||||
generate: generate invoice
|
||||
download: download invoice
|
||||
invoice_date: date of group order invoice
|
||||
generate: generate invoice
|
||||
generate_with_date: set & generate
|
||||
payment_method: Credit
|
||||
tax_number_not_set: Tax number not set in configs
|
||||
invoice:
|
||||
|
|
Loading…
Reference in a new issue