mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Add bulk invoices printing
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor, Orders, SortOptions) ->
|
||||
angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor, Orders, SortOptions, $http, $window) ->
|
||||
$scope.RequestMonitor = RequestMonitor
|
||||
$scope.pagination = Orders.pagination
|
||||
$scope.orders = Orders.all
|
||||
@@ -53,3 +53,11 @@ angular.module("admin.orders").controller "ordersCtrl", ($scope, RequestMonitor,
|
||||
$scope.changePage = (newPage) ->
|
||||
$scope.page = newPage
|
||||
$scope.fetchResults(newPage)
|
||||
|
||||
$scope.bulkInvoice = ->
|
||||
params = ''
|
||||
angular.forEach $scope.selected, (selected, order_id) ->
|
||||
params += 'order_ids[]='+order_id+'&' if selected
|
||||
|
||||
$window.open('/admin/orders/bulk_invoice?'+params)
|
||||
true
|
||||
|
||||
@@ -103,3 +103,10 @@ table.index td.actions {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
}
|
||||
|
||||
.index-controls {
|
||||
|
||||
button {
|
||||
float: right;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
require 'open_food_network/spree_api_key_loader'
|
||||
require 'combine_pdf'
|
||||
|
||||
Spree::Admin::OrdersController.class_eval do
|
||||
include OpenFoodNetwork::SpreeApiKeyLoader
|
||||
@@ -37,13 +38,33 @@ Spree::Admin::OrdersController.class_eval do
|
||||
end
|
||||
|
||||
def invoice
|
||||
pdf = render_to_string pdf: "invoice-#{@order.number}.pdf", template: invoice_template, formats: [:html], encoding: "UTF-8"
|
||||
pdf = render_to_string pdf: "invoice-#{@order.number}.pdf",
|
||||
template: invoice_template,
|
||||
formats: [:html], encoding: "UTF-8"
|
||||
|
||||
Spree::OrderMailer.invoice_email(@order.id, pdf).deliver
|
||||
flash[:success] = t('admin.orders.invoice_email_sent')
|
||||
|
||||
respond_with(@order) { |format| format.html { redirect_to edit_admin_order_path(@order) } }
|
||||
end
|
||||
|
||||
def bulk_invoice
|
||||
orders = params[:order_ids]
|
||||
|
||||
combined_pdf = CombinePDF.new
|
||||
|
||||
orders.each do |order_id|
|
||||
@order = Spree::Order.find(order_id)
|
||||
pdf_data = render_to_string pdf: "invoice-#{@order.number}.pdf", template: invoice_template,
|
||||
formats: [:html], encoding: "UTF-8"
|
||||
|
||||
combined_pdf << CombinePDF.parse(pdf_data)
|
||||
end
|
||||
|
||||
send_data combined_pdf.to_pdf, filename: "invoices.pdf",
|
||||
type: "application/pdf", disposition: :inline
|
||||
end
|
||||
|
||||
def print
|
||||
render pdf: "invoice-#{@order.number}", template: invoice_template, encoding: "UTF-8"
|
||||
end
|
||||
|
||||
@@ -210,7 +210,9 @@ class AbilityDecorator
|
||||
# during the order creation process from the admin backend
|
||||
order.distributor.nil? || user.enterprises.include?(order.distributor) || order.order_cycle.andand.coordinated_by?(user)
|
||||
end
|
||||
can [:admin, :bulk_management, :managed], Spree::Order if user.admin? || user.enterprises.any?(&:is_distributor)
|
||||
can [:admin, :bulk_management, :managed, :bulk_invoice], Spree::Order do
|
||||
user.admin? || user.enterprises.any?(&:is_distributor)
|
||||
end
|
||||
can [:admin, :visible], Enterprise
|
||||
can [:admin, :index, :create, :update, :destroy], :line_item
|
||||
can [:admin, :index, :create], Spree::LineItem
|
||||
|
||||
@@ -16,9 +16,12 @@
|
||||
- content_for :table_filter do
|
||||
= render partial: 'filters'
|
||||
|
||||
.row
|
||||
.row.index-controls{'ng-show' => '!RequestMonitor.loading && orders.length > 0'}
|
||||
= render partial: 'per_page_controls'
|
||||
|
||||
%button{'ng-click' => 'bulkInvoice()'}
|
||||
= t('.print_invoices')
|
||||
|
||||
%table#listing_orders.index.responsive{width: "100%", 'ng-init' => 'initialise()', 'ng-show' => "!RequestMonitor.loading && orders.length > 0" }
|
||||
%colgroup
|
||||
%col{style: "width: 10%"}
|
||||
|
||||
@@ -2696,6 +2696,7 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
results_found: "%{number} Results found."
|
||||
viewing: "Viewing %{start} to %{end}."
|
||||
select_all: "Select All"
|
||||
print_invoices: "Print Invoices"
|
||||
invoice:
|
||||
issued_on: Issued on
|
||||
tax_invoice: TAX INVOICE
|
||||
|
||||
Reference in New Issue
Block a user