From 371ec2c81ad4a854a9cab18efccb1f81f8c02ad4 Mon Sep 17 00:00:00 2001 From: Paul van Tilburg Date: Fri, 31 Oct 2014 21:59:17 +0100 Subject: [PATCH] Handle delete requests for invoices --- stoptime.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/stoptime.rb b/stoptime.rb index 858fae3..4ae5bae 100644 --- a/stoptime.rb +++ b/stoptime.rb @@ -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 #