move automatic invoices to plugin

changes on deposit calculation

tiny changes on group order invoice pdf
This commit is contained in:
viehlieb 2023-10-10 23:11:34 +02:00
parent 42a1773a87
commit e78d1ad072
67 changed files with 5579 additions and 69 deletions

View file

@ -0,0 +1,3 @@
/ insert_after 'erb:contains("phone")'
- if FoodsoftAutomaticInvoices.enabled?
= config_input c, :tax_number, input_html: {class: 'input-medium'}

View file

@ -0,0 +1,8 @@
/ insert_after 'erb:contains(":use_self_service")'
- if FoodsoftAutomaticInvoices.enabled?
%h4= t '.group_order_invoices'
= form.fields_for :group_order_invoices do |field|
= config_input field, :use_automatic_invoices, as: :boolean
= config_input field, :separate_deposits, as: :boolean
= config_input field, :vat_exempt, as: :boolean
= config_input field, :payment_method, as: :string, input_html: {class: 'input-medium'}

View file

@ -0,0 +1,3 @@
/ insert_after 'erb:contains(":contact_person")'
- if FoodsoftAutomaticInvoices.enabled?
= f.input :customer_number

View file

@ -0,0 +1,27 @@
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

View file

@ -0,0 +1,4 @@
/ insert_after 'erb:contains(":updated_by")'
- if FoodsoftAutomaticInvoices.enabled?
%th= heading_helper GroupOrderInvoice, :name
%th

View file

@ -0,0 +1,10 @@
/ insert_after 'erb:contains("show_user(order.updated_by)")'
- if FoodsoftAutomaticInvoices.enabled?
%td
- if order.closed?
-if FoodsoftConfig[:contact][:tax_number] && order.ordergroups.present?
= render :partial => 'group_order_invoices/links', locals:{order: order}
-else
= I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set')
- else
= t('orders.index.not_closed')

View file

@ -0,0 +1,3 @@
/ replace 'erb:contains("edit_results_by_articles")'
- if FoodsoftAutomaticInvoices.enabled?
= render :partial => 'finance/balancing/edit_results_by_articles_override'

View file

@ -0,0 +1,21 @@
/ replace_contents "tr.gross-amount"
- if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
%tr
%td= t('.gross_amount')
%td.numeric= number_to_currency(order.sum(:gross_without_deposit))
%tr
%td= t('.fc_amount_without_deposit')
%td.numeric= number_to_currency(order.sum(:fc_without_deposit))
%tr
%td= t('.deposit')
%td.numeric= number_to_currency(order.sum(:deposit))
%tr
%td= t('.net_deposit')
%td.numeric= number_to_currency(order.sum(:net_deposit))
%tr
%td= t('.fc_deposit')
%td.numeric= number_to_currency(order.sum(:fc_deposit))
- else
%tr
%td= t('.gross_amount')
%td.numeric= number_to_currency(order.sum(:gross))

View file

@ -0,0 +1,15 @@
if FoodsoftAutomaticInvoices.enabled?
Finance::BalancingHelper.class_eval do
def balancing_view_partial
view = params[:view] || 'edit_results'
case view
when 'edit_results'
'edit_results_by_articles_override'
when 'groups_overview'
'shared/articles_by/groups'
when 'articles_overview'
'shared/articles_by/articles'
end
end
end
end

View file

@ -0,0 +1,20 @@
if FoodsoftAutomaticInvoices.enabled?
Mailer.class_eval do
# Sends automatically generated invoicesfor group orders to ordergroup members
def add_group_order_invoice_attachments(group_order_invoice)
attachment_name = group_order_invoice.name + '.pdf'
attachments[attachment_name] = GroupOrderInvoicePdf.new(group_order_invoice.load_data_for_invoice).to_pdf
end
def group_order_invoice(group_order_invoice, user)
@user = user
@group_order_invoice = group_order_invoice
@group_order = group_order_invoice.group_order
@supplier = @group_order.order.supplier.name
@group = @group_order.ordergroup
add_group_order_invoice_attachments(group_order_invoice)
mail to: user,
subject: I18n.t('mailer.group_order_invoice.subject', group: @group.name, supplier: @supplier)
end
end
end

View file

@ -0,0 +1,31 @@
if FoodsoftAutomaticInvoices.enabled?
PriceCalculation.class_eval do
# deposit is always gross
def gross_price
add_percent(price, tax) + deposit
end
def gross_price_without_deposit
add_percent(price, tax)
end
def net_deposit_price
remove_percent(deposit, tax)
end
def fc_price_without_deposit
add_percent(gross_price_without_deposit, FoodsoftConfig[:price_markup].to_i)
end
def fc_deposit_price
add_percent(deposit, FoodsoftConfig[:price_markup].to_i)
end
private
def remove_percent(value, percent)
(value / ((percent * 0.01) + 1)).round(2)
end
end
end

View file

@ -0,0 +1,15 @@
if FoodsoftAutomaticInvoices.enabled?
GroupOrderArticle.class_eval do
def total_price_without_deposit(order_article = self.order_article)
if order_article.order.open?
if FoodsoftConfig[:tolerance_is_costly]
order_article.price.fc_price_without_deposit * (quantity + tolerance)
else
order_article.price.fc_price_without_deposit * quantity
end
else
order_article.price.fc_price_without_deposit * result
end
end
end
end

View file

@ -0,0 +1,5 @@
if FoodsoftAutomaticInvoices.enabled?
GroupOrder.class_eval do
has_one :group_order_invoice
end
end

View file

@ -0,0 +1,15 @@
if FoodsoftAutomaticInvoices.enabled?
OrderArticle.class_eval do
def total_gross_price_without_deposit
units * price.unit_quantity * price.gross_price_without_deposit
end
def total_deposit_price
units * price.unit_quantity * price.deposit
end
def total_price_without_deposit
units * price.unit_quantity * price.fc_price_without_deposit
end
end
end

View file

@ -0,0 +1,50 @@
if FoodsoftAutomaticInvoices.enabled?
class Order < ApplicationRecord
# Returns the all round price of a finished order
# :groups returns the sum of all GroupOrders
# :clear returns the price without tax, deposit and markup
# :gross includes tax and deposit(gross). this amount should be equal to suppliers bill
# :gross_without_deposit excludes the depost from the gross price
# :net_deposit returns the deposit without tax (deposit entered by user is default gross)
# :fc_deposit_price returns the deposit with markup
# :fc, guess what...
def sum(type = :gross)
total = 0
if %i[net gross net_deposit gross_without_deposit fc_without_deposit fc_deposit deposit fc].include?(type)
for oa in order_articles.ordered.includes(:article, :article_price)
quantity = oa.units * oa.price.unit_quantity
case type
when :net
total += quantity * oa.price.price
when :gross
total += quantity * oa.price.gross_price
when :gross_without_deposit
total += quantity * oa.price.gross_price_without_deposit
when :fc
total += quantity * oa.price.fc_price
when :fc_without_deposit
total += quantity * oa.price.fc_price_without_deposit
when :net_deposit
total += quantity * oa.price.net_deposit_price
when :fc_deposit
total += quantity * oa.price.fc_deposit_price
when :deposit
total += quantity * oa.price.deposit
end
end
elsif %i[groups groups_without_markup].include?(type)
for go in group_orders.includes(group_order_articles: { order_article: %i[article article_price] })
for goa in go.group_order_articles
case type
when :groups
total += goa.result * goa.order_article.price.fc_price
when :groups_without_markup
total += goa.result * goa.order_article.price.gross_price
end
end
end
end
total
end
end
end

View file

@ -0,0 +1,6 @@
/ insert_after 'erb:contains(":contact_person")'
- if FoodsoftAutomaticInvoices.enabled?
%p
= f.label :customer_number
%br/
= f.text_field :customer_number

View file

@ -0,0 +1,5 @@
/ insert_before 'erb:contains("t \'.prices\'")'
- if FoodsoftAutomaticInvoices.enabled?
- if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
%th= t '.deposit'

View file

@ -0,0 +1,5 @@
/ insert_after 'erb:contains("number_to_currency(gross_price)")'
- if FoodsoftAutomaticInvoices.enabled?
- if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
%td= number_to_currency(order_article.price.deposit)

View file

@ -0,0 +1,5 @@
/ insert_after 'erb:contains(".description2")'
- if FoodsoftAutomaticInvoices.enabled?
- if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits)
= t '.description3', net_deposit: number_to_currency(@order.sum(:net_deposit)), deposit: number_to_currency(@order.sum(:deposit))

View file

@ -0,0 +1,4 @@
/ insert_after 'erb:contains(" group.contact_address")'
- if FoodsoftAutomaticInvoices.enabled?
%dt= heading_helper(Ordergroup, :customer_number) + ':'
%dd=h group.customer_number