wip move automatic invoices to plugin

This commit is contained in:
viehlieb 2023-10-10 23:11:34 +02:00
parent 42a1773a87
commit 78bf494182
33 changed files with 7197 additions and 0 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(":updated_by")'
%th= heading_helper GroupOrderInvoice, :name
%th

View file

@ -0,0 +1,9 @@
/ insert_after 'erb:contains("show_user(order.updated_by)")'
%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,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')
%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?
Mailer.class_eval do
# Sends automatically generated invoicesfor group orders to ordergroup members
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,11 @@
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
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