fix deposit is agnostic to percentage on pdf

This commit is contained in:
viehlieb 2023-10-19 01:05:02 +02:00
parent 3dc806317e
commit 91df920119
6 changed files with 260 additions and 69 deletions

View file

@ -53,16 +53,18 @@ class GroupOrderInvoicePdf < RenderPdf
# invoice Date and nnvoice number # invoice Date and nnvoice number
bounding_box [margin_box.right - 200, margin_box.top - 150], width: 200 do bounding_box [margin_box.right - 200, margin_box.top - 150], width: 200 do
text I18n.t('documents.group_order_invoice_pdf.invoice_date', invoice_date: @options[:invoice_date].strftime(I18n.t('date.formats.default'))), align: :left
move_down 5
text I18n.t('documents.group_order_invoice_pdf.invoice_number', invoice_number: @options[:invoice_number]), align: :left text I18n.t('documents.group_order_invoice_pdf.invoice_number', invoice_number: @options[:invoice_number]), align: :left
move_down 5
text I18n.t('documents.group_order_invoice_pdf.invoice_date', invoice_date: @options[:invoice_date].strftime(I18n.t('date.formats.default'))), align: :left
if @options[:pickup]
move_down 5
text I18n.t('documents.group_order_invoice_pdf.pickup_date', invoice_date: @options[:pickup].strftime(I18n.t('date.formats.default')))
end
end end
move_down 15 move_down 20
# kind of the "body" of the invoice
text I18n.t('documents.group_order_invoice_pdf.payment_method', payment_method: @options[:payment_method]) text I18n.t('documents.group_order_invoice_pdf.payment_method', payment_method: @options[:payment_method])
move_down 15
text I18n.t('documents.group_order_invoice_pdf.table_headline') text I18n.t('documents.group_order_invoice_pdf.table_headline')
move_down 5 move_down 5
@ -151,6 +153,7 @@ class GroupOrderInvoicePdf < RenderPdf
tax_hash_net = Hash.new(0) # for summing up article net prices grouped into vat percentage tax_hash_net = Hash.new(0) # for summing up article net prices grouped into vat percentage
tax_hash_gross = Hash.new(0) # same here with gross prices tax_hash_gross = Hash.new(0) # same here with gross prices
tax_hash_fc = Hash.new(0) # same here with fc prices
if separate_deposits if separate_deposits
total_deposit = 0 total_deposit = 0
@ -158,6 +161,7 @@ class GroupOrderInvoicePdf < RenderPdf
tax_hash_deposit_gross = Hash.new(0) # for summing up deposit gross prices grouped into vat percentage tax_hash_deposit_gross = Hash.new(0) # for summing up deposit gross prices grouped into vat percentage
tax_hash_deposit_net = Hash.new(0) # same here with gross prices tax_hash_deposit_net = Hash.new(0) # same here with gross prices
tax_hash_deposit_fc = Hash.new(0) # same here with fc prices
end end
marge = FoodsoftConfig[:price_markup] marge = FoodsoftConfig[:price_markup]
@ -177,38 +181,42 @@ class GroupOrderInvoicePdf < RenderPdf
order_article = goa.order_article order_article = goa.order_article
goa_total_net = goa.result * order_article.price.price goa_total_net = goa.result * order_article.price.price
goa_total_gross = separate_deposits ? goa.total_price_without_deposit : goa.total_price goa_total_fc = separate_deposits ? goa.total_price_without_deposit : goa.total_price
goa_total_gross = separate_deposits ? goa.result * order_article.price.gross_price_without_deposit : goa.result * order_article.price.gross_price
data << [order_article.article.name, data << [order_article.article.name,
goa.result.to_i, goa.result.to_i,
number_to_currency(order_article.price.price), number_to_currency(order_article.price.price),
number_to_currency(goa_total_net), number_to_currency(goa_total_net),
tax.to_s + '%', tax.to_s + '%',
number_to_currency(goa_total_gross)] number_to_currency(goa_total_fc)]
if separate_deposits && order_article.price.deposit > 0.0 if separate_deposits && order_article.price.deposit > 0.0
goa_deposit = goa.result * order_article.price.net_deposit_price goa_net_deposit = goa.result * order_article.price.net_deposit_price
goa_deposit = goa.result * order_article.price.deposit
goa_total_deposit = goa.result * order_article.price.fc_deposit_price goa_total_deposit = goa.result * order_article.price.fc_deposit_price
data << ["zzgl. Pfand", data << ["zzgl. Pfand",
goa.result.to_i, goa.result.to_i,
number_to_currency(order_article.price.net_deposit_price), number_to_currency(order_article.price.net_deposit_price),
number_to_currency(goa_deposit), number_to_currency(goa_net_deposit),
tax.to_s + '%', tax.to_s + '%',
number_to_currency(goa_total_deposit)] number_to_currency(goa_total_deposit)]
total_deposit += goa_deposit total_deposit += goa_deposit
total_deposit_gross += goa_total_deposit total_deposit_gross += goa_total_deposit
tax_hash_deposit_net[tax.to_i] += goa_deposit tax_hash_deposit_net[tax.to_i] += goa_net_deposit
tax_hash_deposit_gross[tax.to_i] += goa_total_deposit tax_hash_deposit_gross[tax.to_i] += goa_deposit
tax_hash_deposit_fc[tax.to_i] += goa_total_deposit
end end
tax_hash_net[tax.to_i] += goa_total_net tax_hash_net[tax.to_i] += goa_total_net
tax_hash_gross[tax.to_i] += goa_total_gross tax_hash_gross[tax.to_i] += goa_total_gross
tax_hash_fc[tax.to_i] += goa_total_fc
total_net += goa_total_net total_net += goa_total_net
total_gross += goa_total_gross total_gross += goa_total_fc
end end
end end
@ -226,10 +234,34 @@ class GroupOrderInvoicePdf < RenderPdf
table.columns(1..6).align = :right table.columns(1..6).align = :right
end end
if marge > 0
sum = [[nil, nil, "Netto", "MwSt", "FC-Marge", "Brutto"]]
else
sum = [[nil, nil, nil, "Netto", "MwSt", "Brutto"]] sum = [[nil, nil, nil, "Netto", "MwSt", "Brutto"]]
[7, 19].each do |key| end
sum << [nil, nil, "Produkte mit #{key}%", number_to_currency(tax_hash_net[key]), number_to_currency(tax_hash_gross[key] - tax_hash_net[key]), number_to_currency(tax_hash_gross[key])]
sum << [nil, nil, "Pfand mit #{key}%", number_to_currency(tax_hash_deposit_net[key]), number_to_currency(tax_hash_deposit_gross[key] - tax_hash_deposit_net[key]), number_to_currency(tax_hash_deposit_gross[key])] if separate_deposits tax_hash_gross.keys.each do |key|
tmp_sum = [nil, "Produkte mit #{key}%", number_to_currency(tax_hash_net[key])]
if marge <= 0
tmp_sum.unshift(nil)
end
tmp_sum << number_to_currency(tax_hash_gross[key] - tax_hash_net[key])
if marge > 0
tmp_sum << number_to_currency(tax_hash_fc[key] - tax_hash_gross[key])
end
tmp_sum << number_to_currency(tax_hash_fc[key])
sum << tmp_sum
tmp_sum = [nil, "Pfand mit #{key}%", number_to_currency(tax_hash_deposit_net[key])]
if marge <= 0
tmp_sum.unshift(nil)
end
tmp_sum << number_to_currency(tax_hash_deposit_gross[key] - tax_hash_deposit_net[key])
if marge > 0
tmp_sum << number_to_currency(tax_hash_deposit_fc[key] - tax_hash_deposit_gross[key])
end
tmp_sum << number_to_currency(tax_hash_deposit_fc[key])
sum << tmp_sum
end end
total_deposit_gross ||= 0 total_deposit_gross ||= 0

View file

@ -33,6 +33,7 @@ class GroupOrderInvoice < ApplicationRecord
def load_data_for_invoice def load_data_for_invoice
invoice_data = {} invoice_data = {}
order = group_order.order order = group_order.order
invoice_data[:pickup] = order.pickup
invoice_data[:supplier] = order.supplier.name invoice_data[:supplier] = order.supplier.name
invoice_data[:ordergroup] = group_order.ordergroup invoice_data[:ordergroup] = group_order.ordergroup
invoice_data[:group_order] = group_order invoice_data[:group_order] = group_order

View file

@ -11,14 +11,14 @@
%td= t('.gross_amount') %td= t('.gross_amount')
%td.numeric= number_to_currency(order.sum(:gross_without_deposit)) %td.numeric= number_to_currency(order.sum(:gross_without_deposit))
%tr %tr
%td= t('.fc_amount') %td= t('.fc_amount_without_deposit')
%td.numeric= number_to_currency(order.sum(:fc_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 %tr
%td= t('.net_deposit') %td= t('.net_deposit')
%td.numeric= number_to_currency(order.sum(:net_deposit)) %td.numeric= number_to_currency(order.sum(:net_deposit))
%tr
%td= t('.deposit')
%td.numeric= number_to_currency(order.sum(:deposit))
%tr %tr
%td= t('.fc_deposit') %td= t('.fc_deposit')
%td.numeric= number_to_currency(order.sum(:fc_deposit)) %td.numeric= number_to_currency(order.sum(:fc_deposit))

View file

@ -782,6 +782,7 @@ de:
customer_number: 'Kundennummer: %{customer_number}' customer_number: 'Kundennummer: %{customer_number}'
name: Bestellgruppe %{ordergroup} name: Bestellgruppe %{ordergroup}
payment_method: 'Zahlungsart: %{payment_method}' payment_method: 'Zahlungsart: %{payment_method}'
pickup_date: 'Lieferdatum: %{invoice_date}'
sum_to_pay: Zu zahlen gesamt sum_to_pay: Zu zahlen gesamt
sum_to_pay_net: Zu zahlen gesamt (netto) sum_to_pay_net: Zu zahlen gesamt (netto)
sum_to_pay_gross: Gesamt sum_to_pay_gross: Gesamt

View file

@ -11,7 +11,7 @@
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
create_table "action_text_rich_texts", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "action_text_rich_texts", charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.text "body", size: :long t.text "body", size: :long
t.string "record_type", null: false t.string "record_type", null: false
@ -21,7 +21,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
end end
create_table "active_storage_attachments", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "active_storage_attachments", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "record_type", null: false t.string "record_type", null: false
t.bigint "record_id", null: false t.bigint "record_id", null: false
@ -31,7 +31,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end end
create_table "active_storage_blobs", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "active_storage_blobs", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "key", null: false t.string "key", null: false
t.string "filename", null: false t.string "filename", null: false
t.string "content_type" t.string "content_type"
@ -43,19 +43,19 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end end
create_table "active_storage_variant_records", charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "active_storage_variant_records", charset: "utf8mb4", force: :cascade do |t|
t.integer "blob_id", null: false t.integer "blob_id", null: false
t.string "variation_digest", null: false t.string "variation_digest", null: false
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true
end end
create_table "article_categories", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "article_categories", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", default: "", null: false t.string "name", default: "", null: false
t.string "description" t.string "description"
t.index ["name"], name: "index_article_categories_on_name", unique: true t.index ["name"], name: "index_article_categories_on_name", unique: true
end end
create_table "article_prices", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "article_prices", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "article_id", null: false t.integer "article_id", null: false
t.decimal "price", precision: 8, scale: 2, default: "0.0", null: false t.decimal "price", precision: 8, scale: 2, default: "0.0", null: false
t.decimal "tax", precision: 8, scale: 2, default: "0.0", null: false t.decimal "tax", precision: 8, scale: 2, default: "0.0", null: false
@ -65,7 +65,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["article_id"], name: "index_article_prices_on_article_id" t.index ["article_id"], name: "index_article_prices_on_article_id"
end end
create_table "articles", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "articles", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", default: "", null: false t.string "name", default: "", null: false
t.integer "supplier_id", default: 0, null: false t.integer "supplier_id", default: 0, null: false
t.integer "article_category_id", default: 0, null: false t.integer "article_category_id", default: 0, null: false
@ -91,14 +91,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["type"], name: "index_articles_on_type" t.index ["type"], name: "index_articles_on_type"
end end
create_table "assignments", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "assignments", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "user_id", default: 0, null: false t.integer "user_id", default: 0, null: false
t.integer "task_id", default: 0, null: false t.integer "task_id", default: 0, null: false
t.boolean "accepted", default: false t.boolean "accepted", default: false
t.index ["user_id", "task_id"], name: "index_assignments_on_user_id_and_task_id", unique: true t.index ["user_id", "task_id"], name: "index_assignments_on_user_id_and_task_id", unique: true
end end
create_table "bank_accounts", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "bank_accounts", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "iban" t.string "iban"
t.string "description" t.string "description"
@ -108,14 +108,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.integer "bank_gateway_id" t.integer "bank_gateway_id"
end end
create_table "bank_gateways", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "bank_gateways", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "url", null: false t.string "url", null: false
t.string "authorization" t.string "authorization"
t.integer "unattended_user_id" t.integer "unattended_user_id"
end end
create_table "bank_transactions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "bank_transactions", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "bank_account_id", null: false t.integer "bank_account_id", null: false
t.string "external_id" t.string "external_id"
t.date "date" t.date "date"
@ -129,7 +129,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["financial_link_id"], name: "index_bank_transactions_on_financial_link_id" t.index ["financial_link_id"], name: "index_bank_transactions_on_financial_link_id"
end end
create_table "documents", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "documents", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name" t.string "name"
t.string "mime" t.string "mime"
t.binary "data", size: :long t.binary "data", size: :long
@ -140,16 +140,16 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["parent_id"], name: "index_documents_on_parent_id" t.index ["parent_id"], name: "index_documents_on_parent_id"
end end
create_table "financial_links", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "financial_links", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.text "note" t.text "note"
end end
create_table "financial_transaction_classes", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "financial_transaction_classes", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.boolean "ignore_for_account_balance", default: false, null: false t.boolean "ignore_for_account_balance", default: false, null: false
end end
create_table "financial_transaction_types", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "financial_transaction_types", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.integer "financial_transaction_class_id", null: false t.integer "financial_transaction_class_id", null: false
t.string "name_short" t.string "name_short"
@ -157,7 +157,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["name_short"], name: "index_financial_transaction_types_on_name_short" t.index ["name_short"], name: "index_financial_transaction_types_on_name_short"
end end
create_table "financial_transactions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "financial_transactions", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "ordergroup_id" t.integer "ordergroup_id"
t.decimal "amount", precision: 8, scale: 2, default: "0.0", null: false t.decimal "amount", precision: 8, scale: 2, default: "0.0", null: false
t.text "note", null: false t.text "note", null: false
@ -171,7 +171,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["reverts_id"], name: "index_financial_transactions_on_reverts_id", unique: true t.index ["reverts_id"], name: "index_financial_transactions_on_reverts_id", unique: true
end end
create_table "group_order_article_quantities", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "group_order_article_quantities", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "group_order_article_id", default: 0, null: false t.integer "group_order_article_id", default: 0, null: false
t.integer "quantity", default: 0 t.integer "quantity", default: 0
t.integer "tolerance", default: 0 t.integer "tolerance", default: 0
@ -179,7 +179,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["group_order_article_id"], name: "index_group_order_article_quantities_on_group_order_article_id" t.index ["group_order_article_id"], name: "index_group_order_article_quantities_on_group_order_article_id"
end end
create_table "group_order_articles", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "group_order_articles", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "group_order_id", default: 0, null: false t.integer "group_order_id", default: 0, null: false
t.integer "order_article_id", default: 0, null: false t.integer "order_article_id", default: 0, null: false
t.integer "quantity", default: 0, null: false t.integer "quantity", default: 0, null: false
@ -192,7 +192,17 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["order_article_id"], name: "index_group_order_articles_on_order_article_id" t.index ["order_article_id"], name: "index_group_order_articles_on_order_article_id"
end end
create_table "group_orders", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "group_order_invoices", charset: "utf8mb4", force: :cascade do |t|
t.integer "group_order_id"
t.bigint "invoice_number"
t.date "invoice_date"
t.string "payment_method"
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.index ["group_order_id"], name: "index_group_order_invoices_on_group_order_id", unique: true
end
create_table "group_orders", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "ordergroup_id" t.integer "ordergroup_id"
t.integer "order_id", default: 0, null: false t.integer "order_id", default: 0, null: false
t.decimal "price", precision: 8, scale: 2, default: "0.0", null: false t.decimal "price", precision: 8, scale: 2, default: "0.0", null: false
@ -205,7 +215,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["ordergroup_id"], name: "index_group_orders_on_ordergroup_id" t.index ["ordergroup_id"], name: "index_group_orders_on_ordergroup_id"
end end
create_table "groups", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "groups", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "type", default: "", null: false t.string "type", default: "", null: false
t.string "name", default: "", null: false t.string "name", default: "", null: false
t.string "description" t.string "description"
@ -231,7 +241,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["name"], name: "index_groups_on_name", unique: true t.index ["name"], name: "index_groups_on_name", unique: true
end end
create_table "invites", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "invites", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "token", default: "", null: false t.string "token", default: "", null: false
t.datetime "expires_at", precision: nil, null: false t.datetime "expires_at", precision: nil, null: false
t.integer "group_id", default: 0, null: false t.integer "group_id", default: 0, null: false
@ -240,7 +250,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["token"], name: "index_invites_on_token" t.index ["token"], name: "index_invites_on_token"
end end
create_table "invoices", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "invoices", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "supplier_id" t.integer "supplier_id"
t.string "number" t.string "number"
t.date "date" t.date "date"
@ -258,7 +268,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["supplier_id"], name: "index_invoices_on_supplier_id" t.index ["supplier_id"], name: "index_invoices_on_supplier_id"
end end
create_table "links", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "links", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "url", null: false t.string "url", null: false
t.integer "workgroup_id" t.integer "workgroup_id"
@ -266,7 +276,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.string "authorization" t.string "authorization"
end end
create_table "mail_delivery_status", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "mail_delivery_status", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.datetime "created_at", precision: nil t.datetime "created_at", precision: nil
t.string "email", null: false t.string "email", null: false
t.string "message", null: false t.string "message", null: false
@ -275,13 +285,13 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["email"], name: "index_mail_delivery_status_on_email" t.index ["email"], name: "index_mail_delivery_status_on_email"
end end
create_table "memberships", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "memberships", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "group_id", default: 0, null: false t.integer "group_id", default: 0, null: false
t.integer "user_id", default: 0, null: false t.integer "user_id", default: 0, null: false
t.index ["user_id", "group_id"], name: "index_memberships_on_user_id_and_group_id", unique: true t.index ["user_id", "group_id"], name: "index_memberships_on_user_id_and_group_id", unique: true
end end
create_table "message_recipients", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "message_recipients", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "message_id", null: false t.integer "message_id", null: false
t.integer "user_id", null: false t.integer "user_id", null: false
t.integer "email_state", default: 0, null: false t.integer "email_state", default: 0, null: false
@ -290,7 +300,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["user_id", "read_at"], name: "index_message_recipients_on_user_id_and_read_at" t.index ["user_id", "read_at"], name: "index_message_recipients_on_user_id_and_read_at"
end end
create_table "messages", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "messages", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "sender_id" t.integer "sender_id"
t.string "subject", null: false t.string "subject", null: false
t.boolean "private", default: false t.boolean "private", default: false
@ -301,7 +311,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.binary "received_email", size: :medium t.binary "received_email", size: :medium
end end
create_table "oauth_access_grants", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "oauth_access_grants", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "resource_owner_id", null: false t.integer "resource_owner_id", null: false
t.integer "application_id", null: false t.integer "application_id", null: false
t.string "token", null: false t.string "token", null: false
@ -313,7 +323,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true t.index ["token"], name: "index_oauth_access_grants_on_token", unique: true
end end
create_table "oauth_access_tokens", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "oauth_access_tokens", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "resource_owner_id" t.integer "resource_owner_id"
t.integer "application_id" t.integer "application_id"
t.string "token", null: false t.string "token", null: false
@ -327,7 +337,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true t.index ["token"], name: "index_oauth_access_tokens_on_token", unique: true
end end
create_table "oauth_applications", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "oauth_applications", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "uid", null: false t.string "uid", null: false
t.string "secret", null: false t.string "secret", null: false
@ -339,7 +349,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true t.index ["uid"], name: "index_oauth_applications_on_uid", unique: true
end end
create_table "order_articles", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "order_articles", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "order_id", default: 0, null: false t.integer "order_id", default: 0, null: false
t.integer "article_id", default: 0, null: false t.integer "article_id", default: 0, null: false
t.integer "quantity", default: 0, null: false t.integer "quantity", default: 0, null: false
@ -353,7 +363,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["order_id"], name: "index_order_articles_on_order_id" t.index ["order_id"], name: "index_order_articles_on_order_id"
end end
create_table "order_comments", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "order_comments", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "order_id" t.integer "order_id"
t.integer "user_id" t.integer "user_id"
t.text "text" t.text "text"
@ -361,7 +371,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["order_id"], name: "index_order_comments_on_order_id" t.index ["order_id"], name: "index_order_comments_on_order_id"
end end
create_table "orders", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "orders", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "supplier_id" t.integer "supplier_id"
t.text "note" t.text "note"
t.datetime "starts", precision: nil t.datetime "starts", precision: nil
@ -380,7 +390,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["state"], name: "index_orders_on_state" t.index ["state"], name: "index_orders_on_state"
end end
create_table "page_versions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "page_versions", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "page_id" t.integer "page_id"
t.integer "lock_version" t.integer "lock_version"
t.text "body" t.text "body"
@ -391,7 +401,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["page_id"], name: "index_page_versions_on_page_id" t.index ["page_id"], name: "index_page_versions_on_page_id"
end end
create_table "pages", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "pages", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "title" t.string "title"
t.text "body" t.text "body"
t.string "permalink" t.string "permalink"
@ -405,20 +415,20 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["title"], name: "index_pages_on_title" t.index ["title"], name: "index_pages_on_title"
end end
create_table "periodic_task_groups", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "periodic_task_groups", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.date "next_task_date" t.date "next_task_date"
t.datetime "created_at", precision: nil, null: false t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false t.datetime "updated_at", precision: nil, null: false
end end
create_table "poll_choices", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "poll_choices", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "poll_vote_id", null: false t.integer "poll_vote_id", null: false
t.integer "choice", null: false t.integer "choice", null: false
t.integer "value", null: false t.integer "value", null: false
t.index ["poll_vote_id", "choice"], name: "index_poll_choices_on_poll_vote_id_and_choice", unique: true t.index ["poll_vote_id", "choice"], name: "index_poll_choices_on_poll_vote_id_and_choice", unique: true
end end
create_table "poll_votes", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "poll_votes", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "poll_id", null: false t.integer "poll_id", null: false
t.integer "user_id", null: false t.integer "user_id", null: false
t.integer "ordergroup_id" t.integer "ordergroup_id"
@ -428,7 +438,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["poll_id", "user_id", "ordergroup_id"], name: "index_poll_votes_on_poll_id_and_user_id_and_ordergroup_id", unique: true t.index ["poll_id", "user_id", "ordergroup_id"], name: "index_poll_votes_on_poll_id_and_user_id_and_ordergroup_id", unique: true
end end
create_table "polls", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "polls", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "created_by_user_id", null: false t.integer "created_by_user_id", null: false
t.string "name", null: false t.string "name", null: false
t.text "description" t.text "description"
@ -448,7 +458,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["final_choice"], name: "index_polls_on_final_choice" t.index ["final_choice"], name: "index_polls_on_final_choice"
end end
create_table "printer_job_updates", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "printer_job_updates", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "printer_job_id", null: false t.integer "printer_job_id", null: false
t.datetime "created_at", precision: nil, null: false t.datetime "created_at", precision: nil, null: false
t.string "state", null: false t.string "state", null: false
@ -456,7 +466,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["printer_job_id", "created_at"], name: "index_printer_job_updates_on_printer_job_id_and_created_at" t.index ["printer_job_id", "created_at"], name: "index_printer_job_updates_on_printer_job_id_and_created_at"
end end
create_table "printer_jobs", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "printer_jobs", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "order_id" t.integer "order_id"
t.string "document", null: false t.string "document", null: false
t.integer "created_by_user_id", null: false t.integer "created_by_user_id", null: false
@ -465,7 +475,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["finished_at"], name: "index_printer_jobs_on_finished_at" t.index ["finished_at"], name: "index_printer_jobs_on_finished_at"
end end
create_table "settings", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "settings", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "var", null: false t.string "var", null: false
t.text "value" t.text "value"
t.integer "thing_id" t.integer "thing_id"
@ -475,7 +485,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true t.index ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true
end end
create_table "stock_changes", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "stock_changes", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "stock_event_id" t.integer "stock_event_id"
t.integer "order_id" t.integer "order_id"
t.integer "stock_article_id" t.integer "stock_article_id"
@ -485,7 +495,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["stock_event_id"], name: "index_stock_changes_on_stock_event_id" t.index ["stock_event_id"], name: "index_stock_changes_on_stock_event_id"
end end
create_table "stock_events", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "stock_events", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.integer "supplier_id" t.integer "supplier_id"
t.date "date" t.date "date"
t.datetime "created_at", precision: nil t.datetime "created_at", precision: nil
@ -495,14 +505,14 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["supplier_id"], name: "index_stock_events_on_supplier_id" t.index ["supplier_id"], name: "index_stock_events_on_supplier_id"
end end
create_table "supplier_categories", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "supplier_categories", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", null: false t.string "name", null: false
t.string "description" t.string "description"
t.integer "financial_transaction_class_id" t.integer "financial_transaction_class_id"
t.integer "bank_account_id" t.integer "bank_account_id"
end end
create_table "suppliers", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "suppliers", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", default: "", null: false t.string "name", default: "", null: false
t.string "address", default: "", null: false t.string "address", default: "", null: false
t.string "phone", default: "", null: false t.string "phone", default: "", null: false
@ -524,7 +534,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["name"], name: "index_suppliers_on_name", unique: true t.index ["name"], name: "index_suppliers_on_name", unique: true
end end
create_table "tasks", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "tasks", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "name", default: "", null: false t.string "name", default: "", null: false
t.text "description" t.text "description"
t.date "due_date" t.date "due_date"
@ -541,7 +551,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_22_120005) do
t.index ["workgroup_id"], name: "index_tasks_on_workgroup_id" t.index ["workgroup_id"], name: "index_tasks_on_workgroup_id"
end end
create_table "users", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| create_table "users", id: :integer, charset: "utf8mb4", force: :cascade do |t|
t.string "nick" t.string "nick"
t.string "password_hash", default: "", null: false t.string "password_hash", default: "", null: false
t.string "password_salt", default: "", null: false t.string "password_salt", default: "", null: false

147
db/seeds/demo.seeds.rb Normal file
View file

@ -0,0 +1,147 @@
require_relative 'seed_helper.rb'
FinancialTransactionClass.create!(:id => 1, :name => 'Standard')
FinancialTransactionClass.create!(:id => 2, :name => 'Foodsoft')
FinancialTransactionType.create!(:id => 1, :name => "Foodcoop", :financial_transaction_class_id => 1)
alice = User.create!(:id => 1, :nick => "alice", :password => "secret", :first_name => "Alice", :last_name => "Administrator", :email => "admin@foo.test", :phone => "+4421486548", :created_on => 'Wed, 15 Jan 2014 16:15:33 UTC +00:00')
bob = User.create!(:id => 2, :nick => "bob", :password => "secret", :first_name => "Bob", :last_name => "Doe", :email => "bob@doe.test", :created_on => 'Sun, 19 Jan 2014 17:38:22 UTC +00:00')
Workgroup.create!(:id => 1, :name => "Administrators", :description => "System administrators.", :account_balance => 0.0, :created_on => 'Wed, 15 Jan 2014 16:15:33 UTC +00:00', :role_admin => true, :role_suppliers => true, :role_article_meta => true, :role_finance => true, :role_orders => true, :next_weekly_tasks_number => 8, :ignore_apple_restriction => false)
Workgroup.create!(:id => 2, :name => "Finances", :account_balance => 0.0, :created_on => 'Sun, 19 Jan 2014 17:40:03 UTC +00:00', :role_admin => false, :role_suppliers => false, :role_article_meta => false, :role_finance => true, :role_orders => false, :next_weekly_tasks_number => 8, :ignore_apple_restriction => false)
Ordergroup.create!(:id => 5, :name => "Alice WG", :account_balance => 0.90E2, :created_on => 'Sat, 18 Jan 2014 00:38:48 UTC +00:00', :role_admin => false, :role_suppliers => false, :role_article_meta => false, :role_finance => false, :role_orders => false, :stats => { :jobs_size => 0, :orders_sum => 1021.74 }, :next_weekly_tasks_number => 8, :ignore_apple_restriction => true)
Ordergroup.create!(:id => 8, :name => "Bob's Family", :account_balance => 0.90E2, :created_on => 'Wed, 09 Apr 2014 12:23:29 UTC +00:00', :role_admin => false, :role_suppliers => false, :role_article_meta => false, :role_finance => false, :role_orders => false, :contact_person => "John Doe", :stats => { :jobs_size => 0, :orders_sum => 0 }, :next_weekly_tasks_number => 8, :ignore_apple_restriction => false)
FinancialTransaction.create!(:ordergroup_id => 5, :amount => 0.90E2, :note => "Bank transfer", :user_id => 2, :created_on => 'Mon, 17 Feb 2014 16:19:34 UTC +00:00', :financial_transaction_type_id => 1)
FinancialTransaction.create!(:ordergroup_id => 8, :amount => 0.90E2, :note => "Bank transfer", :user_id => 2, :created_on => 'Mon, 17 Feb 2014 16:19:34 UTC +00:00', :financial_transaction_type_id => 1)
Membership.create!(:group_id => 1, :user_id => 1)
Membership.create!(:group_id => 5, :user_id => 1)
Membership.create!(:group_id => 2, :user_id => 2)
Membership.create!(:group_id => 8, :user_id => 2)
supplier_category = SupplierCategory.create!(:id => 1, :name => "Other", :financial_transaction_class_id => 1)
chocolate_supplier = Supplier.create!(
name: "Kollektiv CHOCK!",
address: "Grabower Straße 1\n12345 Berlin",
phone: "0123456789",
email: "info@bbakery.test",
supplier_category: supplier_category
)
nkn_supplier = Supplier.create!(
name: "Naturgut Süd",
address: "Somewhere in Hamburg, maybe St. Pauli?",
phone: "0123434789",
email: "foodsoft@local-it.org",
supplier_category: supplier_category
)
chocolate_category = ArticleCategory.create!(name: "Schokolade")
obst_category = ArticleCategory.create!(name: "Obst, Gemüse, Sprossen, Pilze")
nudeln_category = ArticleCategory.create!(name: "Nudeln, Trockenfrüchte, Müsli")
reis_category = ArticleCategory.create!(name: "Getreide, Ölsaaten. Nußkerne")
Article.create!(
name: "Vollmilch-Schokolade",
supplier_id: chocolate_supplier.id,
article_category_id: chocolate_category.id,
manufacturer: "Grabower Süßwaren GmbH",
origin: "D", price: 3.0, tax: 7.0,
unit: "200g", unit_quantity: 5,
note: "bio, fairtrade, 40% Kakao, vegan",
availability: true, order_number: "1")
Article.create!(
name: "Weiße Schokolade",
supplier_id: chocolate_supplier.id,
article_category_id: chocolate_category.id,
manufacturer: "Grabower Süßwaren GmbH",
origin: "D", price: 3.49, tax: 7.0,
unit: "200g", unit_quantity: 5,
note: "bio, fairtrade, 40% Kakao, vegan",
availability: true, order_number: "2")
dark_chocolate = Article.create!(
name: "Dunkle Schokolade",
supplier_id: chocolate_supplier.id,
article_category_id: chocolate_category.id,
manufacturer: "Grabower Süßwaren GmbH",
origin: "D", price: 2.89, tax: 7.0,
unit: "200g", unit_quantity: 5,
note: "bio, fairtrade, 40% Kakao, vegan",
availability: true, order_number: "3")
Article.create!(
name: "Himbeer-Schokolade",
supplier_id: chocolate_supplier.id,
article_category_id: chocolate_category.id,
manufacturer: "Grabower Süßwaren GmbH",
origin: "D", price: 2.89, tax: 7.0,
unit: "170g", unit_quantity: 4,
note: "bio, fairtrade, 40% Kakao, vegan",
availability: true, order_number: "4")
previous_order = seed_order(supplier_id: chocolate_supplier.id, starts: 10.days.ago, ends: 7.days.ago)
GroupOrderArticle.create!(
group_order: GroupOrder.create!(order_id: previous_order.id, ordergroup_id: 8),
order_article: previous_order.order_articles.find_by(article_id: dark_chocolate.id),
quantity: 5, tolerance: 0)
previous_order.close!(alice)
seed_order(supplier_id: chocolate_supplier.id, starts: 0.days.ago, ends: 7.days.from_now)
apple = Article.create!(
name: "Äpfel Elstar",
supplier_id: nkn_supplier.id,
article_category_id: obst_category.id,
manufacturer: "Obsthof Bruno Brugger",
origin: "D", price: 3.49, tax: 7.0,
unit: "1kg", unit_quantity: 10,
note: "lecker, fruchtig, demeter",
availability: true, order_number: "5")
brokkoli = Article.create!(
name: "Brokkoli",
supplier_id: nkn_supplier.id,
article_category_id: obst_category.id,
manufacturer: "Fattoria degli Orsi",
origin: "IT", price: 2.89, tax: 7.0,
unit: "400g", unit_quantity: 6,
note: "gesund und lecker",
availability: true, order_number: "6")
tomatoes = Article.create!(
name: "Tomaten",
supplier_id: nkn_supplier.id,
article_category_id: obst_category.id,
manufacturer: "Terra di Puglia",
origin: "IT", price: 2.89, tax: 7.0,
unit: "500g", unit_quantity: 20,
note: "pomodori italiani, demeter",
availability: true, order_number: "7")
rice = Article.create!(
name: "Reis",
supplier_id: nkn_supplier.id,
article_category_id: reis_category.id,
manufacturer: "Finck",
origin: "D", price: 3.29, tax: 7.0,
unit: "3kg", unit_quantity: 10,
note: "Reis im Vorratssack, demeter",
availability: true, order_number: "8")
spaghetti = Article.create!(
name: "Spaghetti",
supplier_id: nkn_supplier.id,
article_category_id: nudeln_category.id,
manufacturer: "Pastificio Zanellini spa",
origin: "D", price: 2.89, tax: 7.0,
unit: "500g", unit_quantity: 4,
note: "100% italienisches Hartweizengrieß",
availability: true, order_number: "9")