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