mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
download accounting period archive through interface
This commit is contained in:
parent
333eb3658b
commit
279a958e46
@ -655,8 +655,8 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal
|
||||
/**
|
||||
* Controller used in the modal window allowing an admin to close an accounting period
|
||||
*/
|
||||
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'periods', 'lastClosingEnd','dialogs', 'growl', '_t',
|
||||
function ($scope, $uibModalInstance, Invoice, AccountingPeriod, periods, lastClosingEnd, dialogs, growl, _t) {
|
||||
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', '$window', 'Invoice', 'AccountingPeriod', 'periods', 'lastClosingEnd','dialogs', 'growl', '_t',
|
||||
function ($scope, $uibModalInstance, $window, Invoice, AccountingPeriod, periods, lastClosingEnd, dialogs, growl, _t) {
|
||||
const YESTERDAY = moment.utc({ h: 0, m: 0, s: 0, ms: 0 }).subtract(1, 'day').toDate();
|
||||
const LAST_CLOSING = moment.utc(lastClosingEnd.last_end_date).toDate();
|
||||
|
||||
@ -738,5 +738,12 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui
|
||||
* Cancel the refund, dismiss the modal window
|
||||
*/
|
||||
$scope.cancel = function () { $uibModalInstance.dismiss('cancel'); };
|
||||
|
||||
/**
|
||||
* Trigger the API call to download the JSON archive of the closed accounting period
|
||||
*/
|
||||
$scope.downloadArchive = function(period) {
|
||||
$window.location.href = `/api/accounting_periods/${period.id}/archive`;
|
||||
}
|
||||
}
|
||||
]);
|
||||
|
@ -213,6 +213,10 @@ table.closings-table {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
thead th.download-archive {
|
||||
display: none;
|
||||
}
|
||||
|
||||
tr:after { /* clearing float */
|
||||
content: ' ';
|
||||
display: block;
|
||||
@ -230,4 +234,21 @@ table.closings-table {
|
||||
width: 24%; /* 24% is less than (100% / 4 cols) = 25% */
|
||||
float: left;
|
||||
}
|
||||
|
||||
tbody td.download-archive {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
width: 41px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
tbody td.download-archive:hover {
|
||||
i {
|
||||
display: none;
|
||||
}
|
||||
&:after {
|
||||
content: '\f019';
|
||||
font-family: 'fontawesome';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
<th translate>{{ 'invoices.start_date' }}</th>
|
||||
<th translate>{{ 'invoices.end_date' }}</th>
|
||||
<th translate>{{ 'invoices.closed_at' }}</th>
|
||||
<th translate>{{ 'invoices.closed_by' }}</th>
|
||||
<th class="download-archive" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -66,6 +66,7 @@
|
||||
<td>{{period.end_at | amDateFormat:'L'}}</td>
|
||||
<td>{{period.closed_at | amDateFormat:'L'}}</td>
|
||||
<td>{{period.user_name}}</td>
|
||||
<td class="download-archive" ng-click="downloadArchive(period)"><i class="fa fa-archive"></i></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
@ -4,7 +4,7 @@
|
||||
class API::AccountingPeriodsController < API::ApiController
|
||||
|
||||
before_action :authenticate_user!
|
||||
before_action :set_period, only: %i[show]
|
||||
before_action :set_period, only: %i[show download_archive]
|
||||
|
||||
def index
|
||||
@accounting_periods = AccountingPeriodService.all_periods_with_users
|
||||
@ -33,10 +33,15 @@ class API::AccountingPeriodsController < API::ApiController
|
||||
end
|
||||
end
|
||||
|
||||
def download_archive
|
||||
authorize AccountingPeriod
|
||||
send_file File.join(Rails.root, @accounting_period.archive_file), type: 'application/json', disposition: 'attachment'
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_period
|
||||
@tag = AccountingPeriod.find(params[:id])
|
||||
@accounting_period = AccountingPeriod.find(params[:id])
|
||||
end
|
||||
|
||||
def period_params
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
# Check the access policies for API::AccountingPeriodsController
|
||||
class AccountingPeriodPolicy < ApplicationPolicy
|
||||
%w[index show create last_closing_end].each do |action|
|
||||
%w[index show create last_closing_end download_archive].each do |action|
|
||||
define_method "#{action}?" do
|
||||
user.admin?
|
||||
end
|
||||
|
@ -131,6 +131,7 @@ Rails.application.routes.draw do
|
||||
resources :spaces
|
||||
resources :accounting_periods do
|
||||
get 'last_closing_end', on: :collection
|
||||
get 'archive', action: 'download_archive', on: :member
|
||||
end
|
||||
|
||||
# i18n
|
||||
|
Loading…
x
Reference in New Issue
Block a user