From 2f17d90054f6fee9592b5f03a7b11bc95e444e2e Mon Sep 17 00:00:00 2001 From: Sylvain Date: Wed, 9 Jan 2019 17:07:15 +0100 Subject: [PATCH] remove button 'generate refund' for invoices within closed periods --- .../javascripts/controllers/admin/invoices.js.erb | 14 ++++++++++++++ app/assets/templates/admin/invoices/index.html.erb | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/controllers/admin/invoices.js.erb b/app/assets/javascripts/controllers/admin/invoices.js.erb index d1c5751ac..640a84177 100644 --- a/app/assets/javascripts/controllers/admin/invoices.js.erb +++ b/app/assets/javascripts/controllers/admin/invoices.js.erb @@ -405,6 +405,20 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I }); } + /** + * Test if the given date is within a closed accounting period + * @param date {Date} date to test + * @returns {boolean} true if closed, false otherwise + */ + $scope.isDateClosed = function(date) { + for (const period of closedPeriods) { + if (moment(date).isBetween(moment.utc(period.start_at).startOf('day'), moment.utc(period.end_at).endOf('day'), null, '[]')) { + return true; + } + } + return false; + } + /* PRIVATE SCOPE */ /** diff --git a/app/assets/templates/admin/invoices/index.html.erb b/app/assets/templates/admin/invoices/index.html.erb index 8449e7acb..c668b5cd8 100644 --- a/app/assets/templates/admin/invoices/index.html.erb +++ b/app/assets/templates/admin/invoices/index.html.erb @@ -87,7 +87,7 @@ {{ 'invoices.download_the_credit_note' | translate }} - + {{ 'invoices.credit_note' | translate }}