diff --git a/app/controllers/spree/admin/invoices_controller.rb b/app/controllers/spree/admin/invoices_controller.rb index 1f949e1033..f5b14e0000 100644 --- a/app/controllers/spree/admin/invoices_controller.rb +++ b/app/controllers/spree/admin/invoices_controller.rb @@ -7,7 +7,7 @@ module Spree authorize_resource class: false def index - @order = Spree::Order.find_by_number(params[:order_id]) + @order = Spree::Order.find_by(number: params[:order_id]) end def create @@ -17,6 +17,23 @@ module Spree render json: invoice_service.id, status: :ok end + def generate + @order = Order.find_by(number: params[:order_id]) + if @order.can_generate_new_invoice? + @order.invoices.create!( + date: Time.zone.today, + number: @order.next_invoice_number, + data: invoice_data + ) + elsif @order.can_update_latest_invoice? + @order.invoices.last.update!( + date: Time.zone.today, + data: invoice_data + ) + end + redirect_back(fallback_location: spree.admin_dashboard_path) + end + def show invoice_id = params[:id] invoice_pdf = BulkInvoiceService.new.filepath(invoice_id) @@ -33,6 +50,12 @@ module Spree render json: { created: false }, status: :unprocessable_entity end end + + protected + + def invoice_data + @invoice_data ||= InvoiceDataGenerator.new(@order).generate + end end end end diff --git a/app/controllers/spree/admin/orders_controller.rb b/app/controllers/spree/admin/orders_controller.rb index 759f18633f..6033a41f37 100644 --- a/app/controllers/spree/admin/orders_controller.rb +++ b/app/controllers/spree/admin/orders_controller.rb @@ -99,11 +99,10 @@ module Spree end def print - # This is for testing on realtime - # I'll replace it later - data = Invoice::OrderSerializer.new(@order).serializable_hash - @invoice=Invoice.new(order: @order, data: data, date: Time.now.to_date) - @invoice_presenter= @invoice.presenter + if OpenFoodNetwork::FeatureToggle.enabled?(:invoices) + @invoice = @order.invoices.find(params[:invoice_id]) + @invoice_presenter = @invoice.presenter + end render_with_wicked_pdf InvoiceRenderer.new.args(@order) end diff --git a/app/helpers/order_helper.rb b/app/helpers/order_helper.rb index e15b8acdbb..467292907c 100644 --- a/app/helpers/order_helper.rb +++ b/app/helpers/order_helper.rb @@ -8,4 +8,9 @@ module OrderHelper def outstanding_balance_label(order) order.outstanding_balance.label end + + def show_generate_invoice_button?(order) + order.can_generate_new_invoice? || + order.can_update_latest_invoice? + end end diff --git a/app/helpers/spree/admin/orders_helper.rb b/app/helpers/spree/admin/orders_helper.rb index 81f9066f90..e64648238c 100644 --- a/app/helpers/spree/admin/orders_helper.rb +++ b/app/helpers/spree/admin/orders_helper.rb @@ -31,6 +31,7 @@ module Spree end def invoice_links + return [] if OpenFoodNetwork::FeatureToggle.enabled?(:invoices) return [] unless Spree::Config[:enable_invoices?] [send_invoice_link, print_invoice_link] diff --git a/app/models/spree/order.rb b/app/models/spree/order.rb index 37b3c953ee..f08ecad087 100644 --- a/app/models/spree/order.rb +++ b/app/models/spree/order.rb @@ -578,11 +578,21 @@ module Spree def can_generate_new_invoice? return true if invoices.empty? - !invoice_comparator.equal? current_state_invoice, invoices.last + invoice_comparator.can_generate_new_invoice? current_state_invoice, invoices.last + end + + def can_update_latest_invoice? + return false if invoices.empty? + + invoice_comparator.can_update_latest_invoice? current_state_invoice, invoices.last + end + + def next_invoice_number + invoices.count + 1 end def invoice_comparator - @invoice_comparator ||= InvoiceComparator.new + @invoice_comparator ||= OrderInvoiceComparator.new end def current_state_invoice diff --git a/app/services/invoice_data_generator.rb b/app/services/invoice_data_generator.rb index 72f990a90f..dad8bd34d4 100644 --- a/app/services/invoice_data_generator.rb +++ b/app/services/invoice_data_generator.rb @@ -59,6 +59,6 @@ class InvoiceDataGenerator end def old_data - @old_data ||= order.invoices&.last.data + @old_data ||= order.invoices&.last&.data end end diff --git a/app/services/invoice_renderer.rb b/app/services/invoice_renderer.rb index 78dbe3938b..d46ed37a33 100644 --- a/app/services/invoice_renderer.rb +++ b/app/services/invoice_renderer.rb @@ -24,10 +24,20 @@ class InvoiceRenderer attr_reader :renderer def invoice_template - if Spree::Config.invoice_style2? + if OpenFoodNetwork::FeatureToggle.enabled?(:invoices) + invoice_presenter_template + elsif Spree::Config.invoice_style2? "spree/admin/orders/invoice2" else "spree/admin/orders/invoice" end end + + def invoice_presenter_template + if Spree::Config.invoice_style2? + "spree/admin/orders/invoice4" + else + "spree/admin/orders/invoice3" + end + end end diff --git a/app/views/spree/admin/invoices/_invoices_table.html.haml b/app/views/spree/admin/invoices/_invoices_table.html.haml index 7f356965db..553c9eaea6 100644 --- a/app/views/spree/admin/invoices/_invoices_table.html.haml +++ b/app/views/spree/admin/invoices/_invoices_table.html.haml @@ -16,9 +16,9 @@ %td.align-center.label = invoice.number %td.align-center.label - = invoice.data['order']['total'] + = invoice.presenter.total %td.align-center.label = t(invoice.status) %td.align-center.label - =link_to(t(:download),invoice.status) + =link_to(t(:download),print_admin_order_path(@order,invoice_id: invoice.id),target: "_blank") diff --git a/app/views/spree/admin/invoices/index.html.haml b/app/views/spree/admin/invoices/index.html.haml index 3df54147a5..df49cc615b 100644 --- a/app/views/spree/admin/invoices/index.html.haml +++ b/app/views/spree/admin/invoices/index.html.haml @@ -6,8 +6,8 @@ = t(:invoices) - content_for :page_actions do - - if @order.can_generate_new_invoice? - %li= button_link_to t(:new_invoice), new_admin_order_adjustment_url(@order), :icon => 'icon-plus', disabled: true + - if show_generate_invoice_button?(@order) + %li= button_link_to t(:new_invoice), generate_admin_order_invoices_path(@order), :icon => 'icon-plus', data: { method: 'post' } = render partial: 'spree/admin/shared/order_links' %li= button_link_to t(:back_to_orders_list), admin_orders_path, :icon => 'icon-arrow-left' diff --git a/app/views/spree/admin/orders/_invoice_table.html.haml b/app/views/spree/admin/orders/_invoice_table.html.haml index 71b9cc7c30..7ed12adca1 100644 --- a/app/views/spree/admin/orders/_invoice_table.html.haml +++ b/app/views/spree/admin/orders/_invoice_table.html.haml @@ -6,33 +6,33 @@ %th{:align => "right", :width => "15%"} %h4= t(:invoice_column_qty) %th{:align => "right", :width => "15%"} - %h4= @invoice_presenter.total_tax > 0 ? t(:invoice_column_tax) : "" + %h4= @order.total_tax > 0 ? t(:invoice_column_tax) : "" %th{:align => "right", :width => "15%"} %h4= t(:invoice_column_price) %tbody - - @invoice_presenter.sorted_line_items.each do |item| + - @order.sorted_line_items.each do |item| %tr %td - = render 'spree/admin/orders/_invoice/line_item_name', line_item: item + = render 'spree/shared/line_item_name', line_item: item %br %small %em= raw(item.variant.product.supplier.name) %td{:align => "right"} = item.quantity %td{:align => "right"} - = item.display_line_items_taxes + = display_line_items_taxes(item) %td{:align => "right"} = item.display_amount_with_adjustments - - @invoice_presenter.checkout_adjustments(exclude: [:line_item]).reverse_each do |adjustment| - - taxable = adjustment#.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment + - checkout_adjustments_for(@order, exclude: [:line_item]).reverse_each do |adjustment| + - taxable = adjustment.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment %tr %td %strong= "#{raw(adjustment.label)}" %td{:align => "right"} 1 %td{:align => "right"} - = adjustment.display_taxes + = display_taxes(taxable, display_zero: false) %td{:align => "right"} = adjustment.display_amount %tfoot @@ -40,16 +40,16 @@ %td{:align => "right", :colspan => "2"} %strong= t(:invoice_tax_total) %td{:align => "right", :colspan => "2"} - %strong= @invoice_presenter.display_checkout_tax_total + %strong= display_checkout_tax_total(@order) %tr %td{:align => "right", :colspan => "2"} %strong= t(:total_excl_tax) %td{:align => "right", :colspan => "2"} - %strong= @invoice_presenter.display_checkout_total_less_tax + %strong= display_checkout_total_less_tax(@order) %tr %td{:align => "right", :colspan => "2"} %strong= t(:total_incl_tax) %td{:align => "right", :colspan => "2"} - %strong= @invoice_presenter.display_total + %strong= @order.display_total %p   diff --git a/app/views/spree/admin/orders/_invoice_table2.html.haml b/app/views/spree/admin/orders/_invoice_table2.html.haml index 8cb6cdd412..ff24582867 100644 --- a/app/views/spree/admin/orders/_invoice_table2.html.haml +++ b/app/views/spree/admin/orders/_invoice_table2.html.haml @@ -6,10 +6,10 @@ %th{:align => "right", :width => "15%"} %h5= t(:invoice_column_qty) %th{:align => "right", :width => "15%"} - %h5= @invoice_presenter.has_taxes_included ? t(:invoice_column_unit_price_with_taxes) : t(:invoice_column_unit_price_without_taxes) + %h5= @order.has_taxes_included ? t(:invoice_column_unit_price_with_taxes) : t(:invoice_column_unit_price_without_taxes) %th{:align => "right", :width => "15%"} - %h5= @invoice_presenter.has_taxes_included ? t(:invoice_column_price_with_taxes) : t(:invoice_column_price_without_taxes) - - if @invoice_presenter.total_tax > 0 + %h5= @order.has_taxes_included ? t(:invoice_column_price_with_taxes) : t(:invoice_column_price_without_taxes) + - if @order.total_tax > 0 %th{:align => "right", :width => "15%"} %h5= t(:invoice_column_tax_rate) %tbody @@ -44,9 +44,9 @@ %tfoot %tr %td{:align => "right", :colspan => "3"} - %strong= @invoice_presenter.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax) + %strong= @order.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax) %td{:align => "right", :colspan => "2"} - %strong= @invoice_presenter.has_taxes_included ? @invoice_presenter.display_total : @invoice_presenter.display_checkout_total_less_tax + %strong= @order.has_taxes_included ? @order.display_total : display_checkout_total_less_tax(@order) - display_checkout_taxes_hash(@order).each do |tax| %tr %td{:align => "right", :colspan => "3"} @@ -55,8 +55,8 @@ = tax[:amount] %tr %td{:align => "right", :colspan => "3"} - = @invoice_presenter.has_taxes_included ? t(:total_excl_tax) : t(:total_incl_tax) + = @order.has_taxes_included ? t(:total_excl_tax) : t(:total_incl_tax) %td{:align => "right", :colspan => "2"} - = @invoice_presenter.has_taxes_included ? @invoice_presenter.display_checkout_total_less_tax : @invoice_presenter.display_total + = @order.has_taxes_included ? display_checkout_total_less_tax(@order) : @order.display_total %p   diff --git a/app/views/spree/admin/orders/_invoice_table3.html.haml b/app/views/spree/admin/orders/_invoice_table3.html.haml new file mode 100644 index 0000000000..71b9cc7c30 --- /dev/null +++ b/app/views/spree/admin/orders/_invoice_table3.html.haml @@ -0,0 +1,55 @@ +%table.order-summary{:width => "100%"} + %thead + %tr + %th{:align => "left"} + %h4= t(:invoice_column_item) + %th{:align => "right", :width => "15%"} + %h4= t(:invoice_column_qty) + %th{:align => "right", :width => "15%"} + %h4= @invoice_presenter.total_tax > 0 ? t(:invoice_column_tax) : "" + %th{:align => "right", :width => "15%"} + %h4= t(:invoice_column_price) + %tbody + - @invoice_presenter.sorted_line_items.each do |item| + %tr + %td + = render 'spree/admin/orders/_invoice/line_item_name', line_item: item + %br + %small + %em= raw(item.variant.product.supplier.name) + %td{:align => "right"} + = item.quantity + %td{:align => "right"} + = item.display_line_items_taxes + %td{:align => "right"} + = item.display_amount_with_adjustments + + - @invoice_presenter.checkout_adjustments(exclude: [:line_item]).reverse_each do |adjustment| + - taxable = adjustment#.adjustable_type == "Spree::Shipment" ? adjustment.adjustable : adjustment + %tr + %td + %strong= "#{raw(adjustment.label)}" + %td{:align => "right"} + 1 + %td{:align => "right"} + = adjustment.display_taxes + %td{:align => "right"} + = adjustment.display_amount + %tfoot + %tr + %td{:align => "right", :colspan => "2"} + %strong= t(:invoice_tax_total) + %td{:align => "right", :colspan => "2"} + %strong= @invoice_presenter.display_checkout_tax_total + %tr + %td{:align => "right", :colspan => "2"} + %strong= t(:total_excl_tax) + %td{:align => "right", :colspan => "2"} + %strong= @invoice_presenter.display_checkout_total_less_tax + %tr + %td{:align => "right", :colspan => "2"} + %strong= t(:total_incl_tax) + %td{:align => "right", :colspan => "2"} + %strong= @invoice_presenter.display_total +%p +   diff --git a/app/views/spree/admin/orders/_invoice_table4.html.haml b/app/views/spree/admin/orders/_invoice_table4.html.haml new file mode 100644 index 0000000000..8cb6cdd412 --- /dev/null +++ b/app/views/spree/admin/orders/_invoice_table4.html.haml @@ -0,0 +1,62 @@ +%table.order-summary{:width => "100%"} + %thead + %tr + %th{:align => "left"} + %h5= t(:invoice_column_item) + %th{:align => "right", :width => "15%"} + %h5= t(:invoice_column_qty) + %th{:align => "right", :width => "15%"} + %h5= @invoice_presenter.has_taxes_included ? t(:invoice_column_unit_price_with_taxes) : t(:invoice_column_unit_price_without_taxes) + %th{:align => "right", :width => "15%"} + %h5= @invoice_presenter.has_taxes_included ? t(:invoice_column_price_with_taxes) : t(:invoice_column_price_without_taxes) + - if @invoice_presenter.total_tax > 0 + %th{:align => "right", :width => "15%"} + %h5= t(:invoice_column_tax_rate) + %tbody + - @order.sorted_line_items.each do |item| + %tr + %td + = render 'spree/shared/line_item_name', line_item: item + %br + %small + %em= raw(item.variant.product.supplier.name) + %td{:align => "right"} + = item.quantity + %td{:align => "right"} + = item.single_display_amount_with_adjustments + %td{:align => "right"} + = item.display_amount_with_adjustments + - if @order.total_tax > 0 + %td{:align => "right"} + = display_line_item_tax_rates(item) + + - checkout_adjustments_for(@order, exclude: [:line_item]).reverse_each do |adjustment| + %tr + %td + %strong= "#{raw(adjustment.label)}" + %td{:align => "right"} + %td{:align => "right"} + %td{:align => "right"} + = adjustment.display_amount + - if @order.total_tax > 0 + %td{:align => "right"} + = display_adjustment_tax_rates(adjustment) + %tfoot + %tr + %td{:align => "right", :colspan => "3"} + %strong= @invoice_presenter.has_taxes_included ? t(:total_incl_tax) : t(:total_excl_tax) + %td{:align => "right", :colspan => "2"} + %strong= @invoice_presenter.has_taxes_included ? @invoice_presenter.display_total : @invoice_presenter.display_checkout_total_less_tax + - display_checkout_taxes_hash(@order).each do |tax| + %tr + %td{:align => "right", :colspan => "3"} + = t(:tax_total, rate: tax[:percentage]) + %td{:align => "right", :colspan => "2"} + = tax[:amount] + %tr + %td{:align => "right", :colspan => "3"} + = @invoice_presenter.has_taxes_included ? t(:total_excl_tax) : t(:total_incl_tax) + %td{:align => "right", :colspan => "2"} + = @invoice_presenter.has_taxes_included ? @invoice_presenter.display_checkout_total_less_tax : @invoice_presenter.display_total +%p +   diff --git a/app/views/spree/admin/orders/invoice.html.haml b/app/views/spree/admin/orders/invoice.html.haml index b66306606f..d1dbc32264 100644 --- a/app/views/spree/admin/orders/invoice.html.haml +++ b/app/views/spree/admin/orders/invoice.html.haml @@ -6,32 +6,32 @@ %td{ :align => "left", colspan: 3 } %h6 = "#{t('.issued_on')}: " - = l @invoice_presenter.invoice_date + = l Time.zone.now.to_date %tr{ valign: "top" } %td{ :align => "left" } %h4 = "#{t('.tax_invoice')}: " - = "#{@invoice_presenter.order_number}" + = "#{@order.number}" %td{width: "10%" }   %td{ :align => "right" } - %h4= @invoice_presenter.order_cycle.name + %h4= @order.order_cycle&.name %tr{ valign: "top" } %td{ align: "left", colspan: 3 } - - if @invoice_presenter.distributor.business_address.blank? - %strong= "#{t('.from')}: #{@invoice_presenter.distributor.name}" + - if @order.distributor.business_address.blank? + %strong= "#{t('.from')}: #{@order.distributor.name}" - else - %strong= "#{t('.from')}: #{@invoice_presenter.distributor.business_address.company}" - - if @invoice_presenter.distributor.abn.present? + %strong= "#{t('.from')}: #{@order.distributor.business_address.company}" + - if @order.distributor.abn.present? %br - = "#{t(:abn)} #{@invoice_presenter.distributor.abn}" + = "#{t(:abn)} #{@order.distributor.abn}" %br - - if @invoice_presenter.distributor.business_address.blank? - = @invoice_presenter.distributor.address.full_address + - if @order.distributor.business_address.blank? + = @order.distributor.address.full_address - else - = @invoice_presenter.distributor.business_address.full_address + = @order.distributor.business_address.full_address %br - = @invoice_presenter.distributor.contact.email + = @order.distributor.contact.email %tr{ valign: "top" } %td{ colspan: 3 }   @@ -39,44 +39,44 @@ %td{ align: "left" } %strong= "#{t('.to')}:" %br - - if @invoice_presenter.bill_address - = @invoice_presenter.bill_address.full_name - - if @invoice_presenter.customer.code.present? + - if @order.bill_address + = @order.bill_address.full_name + - if @order&.customer&.code.present? %br - = "#{t('.code')}: #{@invoice_presenter.customer.code}" + = "#{t('.code')}: #{@order.customer.code}" %br - - if @invoice_presenter.bill_address - = @invoice_presenter.bill_address.full_address + - if @order.bill_address + = @order.bill_address.full_address %br - - if @invoice_presenter.customer.email.present? - = "#{@invoice_presenter.customer.email}," - - if @invoice_presenter.bill_address - = "#{@invoice_presenter.bill_address.phone}" + - if @order&.customer&.email.present? + = "#{@order.customer.email}," + - if @order.bill_address + = "#{@order.bill_address.phone}" %td   %td{ align: "left", style: "border-left: .1em solid black; padding-left: 1em" } - %strong= "#{t('.shipping')}: #{@invoice_presenter.shipping_method.name}" - - if @invoice_presenter.shipping_method.require_ship_address + %strong= "#{t('.shipping')}: #{@order.shipping_method&.name}" + - if @order.shipping_method&.require_ship_address %br - = @invoice_presenter.ship_address.full_name + = @order.ship_address.full_name %br - = @invoice_presenter.ship_address.full_address + = @order.ship_address.full_address %br - = @invoice_presenter.ship_address.phone - - if @invoice_presenter.order_special_instructions.present? + = @order.ship_address.phone + - if @order.special_instructions.present? %br %br %strong= t :customer_instructions - = @invoice_presenter.order_special_instructions + = @order.special_instructions = render 'spree/admin/orders/invoice_table' -- if @invoice_presenter.distributor.invoice_text.present? +- if @order.distributor.invoice_text.present? %p - = @invoice_presenter.distributor.invoice_text + = @order.distributor.invoice_text -= render 'spree/admin/orders/_invoice/payment' += render 'spree/shared/payment' -- if @invoice_presenter.order_note.present? - = render partial: 'spree/admin/orders/_invoice/order_note' +- if @order.note.present? + = render partial: 'spree/shared/order_note' diff --git a/app/views/spree/admin/orders/invoice2.html.haml b/app/views/spree/admin/orders/invoice2.html.haml index aa29f39e9d..c55a1f6637 100644 --- a/app/views/spree/admin/orders/invoice2.html.haml +++ b/app/views/spree/admin/orders/invoice2.html.haml @@ -6,89 +6,89 @@ %td{ :align => "left" } %h4 = t :tax_invoice - - if @invoice_presenter.distributor.display_invoice_logo? && @invoice_presenter.distributor.logo_url + - if @order.distributor.display_invoice_logo? && @order.distributor.logo.variable? %td{ :align => "right", rowspan: 2 } - = wicked_pdf_image_tag @invoice_presenter.distributor.logo_url + = wicked_pdf_image_tag @order.distributor.logo_url(:small) %tr{ valign: "top" } %td{ :align => "left" } - - if @invoice_presenter.distributor.business_address.blank? - %strong= @invoice_presenter.distributor.name + - if @order.distributor.business_address.blank? + %strong= @order.distributor.name %br - = @invoice_presenter.distributor.address.address_part1 + = @order.distributor.address.address_part1 %br - = @invoice_presenter.distributor.address.address_part2 + = @order.distributor.address.address_part2 %br - = @invoice_presenter.distributor.email_address - - if @invoice_presenter.distributor.phone.present? + = @order.distributor.email_address + - if @order.distributor.phone.present? %br - = @invoice_presenter.distributor.phone + = @order.distributor.phone - else - %strong= @invoice_presenter.distributor.business_address.company + %strong= @order.distributor.business_address.company %br - = @invoice_presenter.distributor.business_address.address_part1 + = @order.distributor.business_address.address_part1 %br - = @invoice_presenter.distributor.business_address.address_part2 + = @order.distributor.business_address.address_part2 %br - = @invoice_presenter.distributor.email_address - - if @invoice_presenter.distributor.business_address.phone.present? + = @order.distributor.email_address + - if @order.distributor.business_address.phone.present? %br - = @invoice_presenter.distributor.business_address.phone - - if @invoice_presenter.distributor.abn.present? + = @order.distributor.business_address.phone + - if @order.distributor.abn.present? %br - = "#{t :abn} #{@invoice_presenter.distributor.abn}" - - if @invoice_presenter.distributor.acn.present? + = "#{t :abn} #{@order.distributor.abn}" + - if @order.distributor.acn.present? %br - = "#{t :acn} #{@invoice_presenter.distributor.acn}" + = "#{t :acn} #{@order.distributor.acn}" %tr{ valign: "top" } %td{ :align => "left", colspan: 2 }   %tr{ valign: "top" } %td{ :align => "left" } %br = t :invoice_issued_on - = l @invoice_presenter.invoice_date + = l Time.zone.now.to_date %br = t :date_of_transaction - = l @invoice_presenter.order_completed_at.to_date + = l @order.completed_at.to_date %br = t :order_number - = @invoice_presenter.order_number + = @order.number %td{ :align => "right" } = t :invoice_billing_address %br - - if @invoice_presenter.bill_address - %strong= @invoice_presenter.bill_address.full_name - - if @invoice_presenter&.customer&.code.present? + - if @order.bill_address + %strong= @order.bill_address.full_name + - if @order&.customer&.code.present? %br - = "Code: #{@invoice_presenter.customer.code}" + = "Code: #{@order.customer.code}" %br - - if @invoice_presenter.bill_address - = @invoice_presenter.bill_address.address_part1 + - if @order.bill_address + = @order.bill_address.address_part1 %br - - if @invoice_presenter.bill_address - = @invoice_presenter.bill_address.address_part2 - - if @invoice_presenter.bill_address.phone.present? + - if @order.bill_address + = @order.bill_address.address_part2 + - if @order.bill_address.phone.present? %br - = @invoice_presenter.bill_address.phone - - if @invoice_presenter&.customer&.email.present? + = @order.bill_address.phone + - if @order&.customer&.email.present? %br - = @invoice_presenter.customer.email + = @order.customer.email = render 'spree/admin/orders/invoice_table2' -- if @invoice_presenter.order_special_instructions.present? +- if @order.special_instructions.present? %p.callout %strong = t :customer_instructions %p - %em= @invoice_presenter.order_special_instructions + %em= @order.special_instructions %p   -- if @invoice_presenter.distributor.invoice_text.present? +- if @order.distributor.invoice_text.present? %p - = @invoice_presenter.distributor.invoice_text + = @order.distributor.invoice_text -= render 'spree/admin/orders/_invoice/payment' += render 'spree/shared/payment' -- if @invoice_presenter.order_note.present? - = render partial: 'spree/admin/orders/_invoice/order_note' +- if @order.note.present? + = render partial: 'spree/shared/order_note' diff --git a/app/views/spree/admin/orders/invoice3.html.haml b/app/views/spree/admin/orders/invoice3.html.haml new file mode 100644 index 0000000000..461cc422ad --- /dev/null +++ b/app/views/spree/admin/orders/invoice3.html.haml @@ -0,0 +1,82 @@ += pdf_stylesheet_pack_tag "mail" + +%table{:width => "100%"} + %tbody + %tr{ valign: "top" } + %td{ :align => "left", colspan: 3 } + %h6 + = "#{t('spree.admin.orders.invoice.issued_on')}: " + = l @invoice_presenter.invoice_date + %tr{ valign: "top" } + %td{ :align => "left" } + %h4 + = "#{t('spree.admin.orders.invoice.tax_invoice')}: " + = "#{@invoice_presenter.order_number}" + %td{width: "10%" } +   + %td{ :align => "right" } + %h4= @invoice_presenter.order_cycle.name + %tr{ valign: "top" } + %td{ align: "left", colspan: 3 } + - if @invoice_presenter.distributor.business_address.blank? + %strong= "#{t('spree.admin.orders.invoice.from')}: #{@invoice_presenter.distributor.name}" + - else + %strong= "#{t('spree.admin.orders.invoice.from')}: #{@invoice_presenter.distributor.business_address.company}" + - if @invoice_presenter.distributor.abn.present? + %br + = "#{t(:abn)} #{@invoice_presenter.distributor.abn}" + %br + - if @invoice_presenter.distributor.business_address.blank? + = @invoice_presenter.distributor.address.full_address + - else + = @invoice_presenter.distributor.business_address.full_address + %br + = @invoice_presenter.distributor.contact.email + %tr{ valign: "top" } + %td{ colspan: 3 } +   + %tr{ valign: "top" } + %td{ align: "left" } + %strong= "#{t('spree.admin.orders.invoice.to')}:" + %br + - if @invoice_presenter.bill_address + = @invoice_presenter.bill_address.full_name + - if @invoice_presenter.customer.code.present? + %br + = "#{t('spree.admin.orders.invoice.code')}: #{@invoice_presenter.customer.code}" + %br + - if @invoice_presenter.bill_address + = @invoice_presenter.bill_address.full_address + %br + - if @invoice_presenter.customer.email.present? + = "#{@invoice_presenter.customer.email}," + - if @invoice_presenter.bill_address + = "#{@invoice_presenter.bill_address.phone}" + %td +   + %td{ align: "left", style: "border-left: .1em solid black; padding-left: 1em" } + %strong= "#{t('spree.admin.orders.invoice.shipping')}: #{@invoice_presenter.shipping_method.name}" + - if @invoice_presenter.shipping_method.require_ship_address + %br + = @invoice_presenter.ship_address.full_name + %br + = @invoice_presenter.ship_address.full_address + %br + = @invoice_presenter.ship_address.phone + - if @invoice_presenter.order_special_instructions.present? + %br + %br + %strong= t :customer_instructions + = @invoice_presenter.order_special_instructions + + += render 'spree/admin/orders/invoice_table3' + +- if @invoice_presenter.distributor.invoice_text.present? + %p + = @invoice_presenter.distributor.invoice_text + += render 'spree/admin/orders/_invoice/payment' + +- if @invoice_presenter.order_note.present? + = render partial: 'spree/admin/orders/_invoice/order_note' diff --git a/app/views/spree/admin/orders/invoice4.html.haml b/app/views/spree/admin/orders/invoice4.html.haml new file mode 100644 index 0000000000..47f689c1c6 --- /dev/null +++ b/app/views/spree/admin/orders/invoice4.html.haml @@ -0,0 +1,94 @@ += pdf_stylesheet_pack_tag "mail" + +%table{:width => "100%"} + %tbody + %tr{ valign: "top" } + %td{ :align => "left" } + %h4 + = t :tax_invoice + - if @invoice_presenter.distributor.display_invoice_logo? && @invoice_presenter.distributor.logo_url + %td{ :align => "right", rowspan: 2 } + = wicked_pdf_image_tag @invoice_presenter.distributor.logo_url + %tr{ valign: "top" } + %td{ :align => "left" } + - if @invoice_presenter.distributor.business_address.blank? + %strong= @invoice_presenter.distributor.name + %br + = @invoice_presenter.distributor.address.address_part1 + %br + = @invoice_presenter.distributor.address.address_part2 + %br + = @invoice_presenter.distributor.email_address + - if @invoice_presenter.distributor.phone.present? + %br + = @invoice_presenter.distributor.phone + - else + %strong= @invoice_presenter.distributor.business_address.company + %br + = @invoice_presenter.distributor.business_address.address_part1 + %br + = @invoice_presenter.distributor.business_address.address_part2 + %br + = @invoice_presenter.distributor.email_address + - if @invoice_presenter.distributor.business_address.phone.present? + %br + = @invoice_presenter.distributor.business_address.phone + - if @invoice_presenter.distributor.abn.present? + %br + = "#{t :abn} #{@invoice_presenter.distributor.abn}" + - if @invoice_presenter.distributor.acn.present? + %br + = "#{t :acn} #{@invoice_presenter.distributor.acn}" + %tr{ valign: "top" } + %td{ :align => "left", colspan: 2 }   + %tr{ valign: "top" } + %td{ :align => "left" } + %br + = t :invoice_issued_on + = l @invoice_presenter.invoice_date + %br + = t :date_of_transaction + = l @invoice_presenter.order_completed_at.to_date + %br + = t :order_number + = @invoice_presenter.order_number + %td{ :align => "right" } + = t :invoice_billing_address + %br + - if @invoice_presenter.bill_address + %strong= @invoice_presenter.bill_address.full_name + - if @invoice_presenter&.customer&.code.present? + %br + = "Code: #{@invoice_presenter.customer.code}" + %br + - if @invoice_presenter.bill_address + = @invoice_presenter.bill_address.address_part1 + %br + - if @invoice_presenter.bill_address + = @invoice_presenter.bill_address.address_part2 + - if @invoice_presenter.bill_address.phone.present? + %br + = @invoice_presenter.bill_address.phone + - if @invoice_presenter&.customer&.email.present? + %br + = @invoice_presenter.customer.email + += render 'spree/admin/orders/invoice_table4' + +- if @invoice_presenter.order_special_instructions.present? + %p.callout + %strong + = t :customer_instructions + %p + %em= @invoice_presenter.order_special_instructions + %p +   + +- if @invoice_presenter.distributor.invoice_text.present? + %p + = @invoice_presenter.distributor.invoice_text + += render 'spree/admin/orders/_invoice/payment' + +- if @invoice_presenter.order_note.present? + = render partial: 'spree/admin/orders/_invoice/order_note' diff --git a/app/views/spree/admin/shared/_order_tabs.html.haml b/app/views/spree/admin/shared/_order_tabs.html.haml index 067da26620..78d6b18c95 100644 --- a/app/views/spree/admin/shared/_order_tabs.html.haml +++ b/app/views/spree/admin/shared/_order_tabs.html.haml @@ -61,9 +61,10 @@ %li{ class: adjustments_classes } = link_to_with_icon 'icon-cogs', t(:adjustments), spree.admin_order_adjustments_url(@order) - - invoices_classes = "active" if current == 'Invoices' - %li{ class: invoices_classes } - = link_to_with_icon 'icon-cogs', t(:invoices), spree.admin_order_invoices_url(@order) + - if feature?(:invoices) + - invoices_classes = "active" if current == 'Invoices' + %li{ class: invoices_classes } + = link_to_with_icon 'icon-cogs', t(:invoices), spree.admin_order_invoices_url(@order) - if @order.completed? - authorizations_classes = "active" if current == "Return Authorizations" diff --git a/config/routes/spree.rb b/config/routes/spree.rb index f2b26246e7..cdc8d7660e 100644 --- a/config/routes/spree.rb +++ b/config/routes/spree.rb @@ -100,7 +100,10 @@ Spree::Core::Engine.routes.draw do end resources :adjustments - resources :invoices + resources :invoices, only: [:index] + resource :invoices, only: [] do + post :generate, to: :generate + end resources :payments do member do diff --git a/lib/open_food_network/feature_toggle.rb b/lib/open_food_network/feature_toggle.rb index 2bd0b25bde..f2a1617018 100644 --- a/lib/open_food_network/feature_toggle.rb +++ b/lib/open_food_network/feature_toggle.rb @@ -38,6 +38,12 @@ module OpenFoodNetwork "vouchers" => <<~DESC, Add voucher functionality. Voucher can be managed via Enterprise settings. DESC + "white_label" => <<~DESC, + Customize shopfront (shop, cart, checkout) and emails without OFN branding. + DESC + "invoices" => <<~DESC, + Enable invoices. + DESC }.freeze def self.setup!