Compare commits

..

3 Commits

Author SHA1 Message Date
5649ba05cd Added Checkbox Controller javascript 2026-01-19 19:34:59 -05:00
bcdd515cf1 Remove view_layouts_base_body_bottom 2026-01-19 19:34:10 -05:00
704dff2a72 Multiple Invoices to PDF 2026-01-19 19:33:29 -05:00
6 changed files with 68 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ gem 'will_paginate'
gem 'rails-jquery-autocomplete' gem 'rails-jquery-autocomplete'
gem 'jquery-ui-rails' gem 'jquery-ui-rails'
gem 'rexml' gem 'rexml'
gem 'combine_pdf'
group :assets do group :assets do
gem 'coffee-rails' gem 'coffee-rails'

View File

@@ -1,6 +1,6 @@
#The MIT License (MIT) #The MIT License (MIT)
# #
#Copyright (c) 2024 rick barrette #Copyright (c) 2026 rick barrette
# #
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: #Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
# #
@@ -10,6 +10,7 @@
class InvoiceController < ApplicationController class InvoiceController < ApplicationController
include AuthHelper include AuthHelper
require 'combine_pdf'
before_action :require_user, :unless => proc {|c| session[:token].nil? } before_action :require_user, :unless => proc {|c| session[:token].nil? }
skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? } skip_before_action :verify_authenticity_token, :check_if_login_required, :unless => proc {|c| session[:token].nil? }
@@ -18,13 +19,33 @@ class InvoiceController < ApplicationController
# Downloads and forwards the invoice pdf # Downloads and forwards the invoice pdf
# #
def show def show
logger.info("Processing request for URL: #{request.original_url}")
begin begin
qbo = Qbo.first qbo = Qbo.first
qbo.perform_authenticated_request do |access_token| qbo.perform_authenticated_request do |access_token|
service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token)
# If multiple id's then pull each pdf & combine them
if params[:item_ids]
logger.info("Grabbing pdfs for " + params[:item_ids].join(', '))
ref = ""
params[:item_ids].each do |i|
logger.info("processing " + i)
invoice = service.fetch_by_id(i)
ref += " #{invoice.doc_number}"
@pdf << CombinePDF.parse(service.pdf(invoice)) unless @pdf.nil?
if @pdf.nil?
@pdf = CombinePDF.parse(service.pdf(invoice))
end
end
@pdf = @pdf.to_pdf
else
invoice = service.fetch_by_id(params[:id]) invoice = service.fetch_by_id(params[:id])
@pdf = service.pdf(invoice) @pdf = service.pdf(invoice)
send_data @pdf, filename: "invoice #{invoice.doc_number}.pdf", :disposition => 'inline', :type => "application/pdf" ref = invoice.doc_number
end
send_data @pdf, filename: "invoice #{ref}.pdf", :disposition => 'inline', :type => "application/pdf"
end end
rescue rescue
redirect_to :back, :flash => { :error => "Invoice not found" } redirect_to :back, :flash => { :error => "Invoice not found" }

View File

@@ -1,11 +1,22 @@
<% if @customer.present? %> <% if @customer.present? %>
<%= form_with(url: invoice_path, method: :get) do |form| %>
<div class="form-check">
<%= check_box_tag "select_all", "1", false, id: "select-all-batches" %>
<%= label_tag "select-all-batches", "Select All Items" %>
</div>
<% @customer.invoices.order(id: :desc).each do |invoice| %> <% @customer.invoices.order(id: :desc).each do |invoice| %>
<div class="row"> <div class="row">
<%= check_box_tag "item_ids[]", invoice.id, false,data: { checkbox_select_all_target: "checkbox", class: "item-checkbox" } %>
<b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %> <b><%= link_to "##{invoice.doc_number}", invoice_path(invoice), target: :_blank %></b> <%= invoice.txn_date %>
</div> </div>
<% end %> <% end %>
<%= form.submit "Bulk PDF" %>
<% end %>
<% else %> <% else %>
<p><%=t(:label_no_invoices)%>.</p> <p><%=t(:label_no_invoices)%>.</p>
<% end %> <% end %>

View File

@@ -0,0 +1,23 @@
document.addEventListener("turbo:load", () => {
const selectAllBox = document.getElementById("select-all-batches");
const checkboxes = document.querySelectorAll(".item-checkbox");
if (selectAllBox) {
selectAllBox.addEventListener("change", function() {
checkboxes.forEach((checkbox) => {
checkbox.checked = this.checked;
});
});
// Optional: Uncheck "Select All" if an individual box is unchecked
checkboxes.forEach((checkbox) => {
checkbox.addEventListener("change", () => {
if (!checkbox.checked) {
selectAllBox.checked = false;
} else if (Array.from(checkboxes).every(c => c.checked)) {
selectAllBox.checked = true;
}
});
});
}
});

View File

@@ -8,11 +8,6 @@
# #
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class HeaderFooterHookListener < Redmine::Hook::ViewListener class HeaderFooterHookListener < Redmine::Hook::ViewListener
def view_layouts_base_html_head(context = {})
#nothing
end
def view_layouts_base_body_bottom(context = {}) def view_layouts_base_body_bottom(context = {})
return "<div id='footer' align='center'><b>#{I18n.translate(:label_last_sync)}: </b> #{Qbo.last_sync if Qbo.exists?}</div>" return "<div id='footer' align='center'><b>#{I18n.translate(:label_last_sync)}: </b> #{Qbo.last_sync if Qbo.exists?}</div>"
end end

View File

@@ -12,8 +12,10 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener
# Load the javascript to support the autocomplete forms # Load the javascript to support the autocomplete forms
def view_layouts_base_html_head(context = {}) def view_layouts_base_html_head(context = {})
js = javascript_include_tag 'application', :plugin => 'redmine_qbo' logger.info("IssuesFormHookListener.view_layouts_base_html_head")
js += javascript_include_tag 'autocomplete-rails', :plugin => 'redmine_qbo' js = javascript_include_tag 'application.js', :plugin => 'redmine_qbo'
js += javascript_include_tag 'autocomplete-rails.js', :plugin => 'redmine_qbo'
js += javascript_include_tag 'checkbox_controller.js', :plugin => 'redmine_qbo'
return js return js
end end