Handle delete requests for invoices

This commit is contained in:
Paul van Tilburg 2014-10-31 21:59:17 +01:00
parent 3e412ef16e
commit 371ec2c81a
1 changed files with 15 additions and 0 deletions

View File

@ -1187,6 +1187,21 @@ module StopTime::Controllers
redirect R(CustomersNInvoicesX, customer_id, invoice_number)
end
# Find the invoice with the given _invoice_number_ for the customer
# with the given _customer_id_ and deletes existing invoice files.
def delete(customer_id, invoice_number)
@invoice = Invoice.find_by_number(@number)
@customer = Customer.find(customer_id)
tex_file = PUBLIC_DIR + "invoices/#{invoice_number}.tex"
File.unlink(tex_file) if tex_file.exist?
pdf_file = PUBLIC_DIR + "invoices/#{invoice_number}.pdf"
File.unlink(pdf_file) if pdf_file.exist?
redirect R(CustomersNInvoicesX, customer_id, invoice_number)
end
##############
# Private helper methods
#