mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2024-12-01 12:24:28 +01:00
list existing closings in close period modal
This commit is contained in:
parent
381dc0aec1
commit
5b13c59496
@ -17,8 +17,8 @@
|
|||||||
/**
|
/**
|
||||||
* Controller used in the admin invoices listing page
|
* Controller used in the admin invoices listing page
|
||||||
*/
|
*/
|
||||||
Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'Invoice', 'invoices', '$uibModal', 'growl', '$filter', 'Setting', 'settings', '_t',
|
Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'Invoice', 'AccountingPeriod', 'invoices', '$uibModal', 'growl', '$filter', 'Setting', 'settings', '_t',
|
||||||
function ($scope, $state, Invoice, invoices, $uibModal, growl, $filter, Setting, settings, _t) {
|
function ($scope, $state, Invoice, AccountingPeriod, invoices, $uibModal, growl, $filter, Setting, settings, _t) {
|
||||||
/* PRIVATE STATIC CONSTANTS */
|
/* PRIVATE STATIC CONSTANTS */
|
||||||
|
|
||||||
// number of invoices loaded each time we click on 'load more...'
|
// number of invoices loaded each time we click on 'load more...'
|
||||||
@ -394,7 +394,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
|
|||||||
controller: 'ClosePeriodModalController',
|
controller: 'ClosePeriodModalController',
|
||||||
size: 'lg',
|
size: 'lg',
|
||||||
resolve: {
|
resolve: {
|
||||||
|
periods() { return AccountingPeriod.query().$promise; }
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -617,14 +617,16 @@ Application.Controllers.controller('AvoirModalController', ['$scope', '$uibModal
|
|||||||
/**
|
/**
|
||||||
* Controller used in the modal window allowing an admin to close an accounting period
|
* Controller used in the modal window allowing an admin to close an accounting period
|
||||||
*/
|
*/
|
||||||
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'dialogs', 'growl', '_t',
|
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'periods' ,'dialogs', 'growl', '_t',
|
||||||
function ($scope, $uibModalInstance, Invoice, AccountingPeriod, dialogs, growl, _t) {
|
function ($scope, $uibModalInstance, Invoice, AccountingPeriod, periods, dialogs, growl, _t) {
|
||||||
/* PUBLIC SCOPE */
|
/* PUBLIC SCOPE */
|
||||||
$scope.period = {
|
$scope.period = {
|
||||||
start_at: null,
|
start_at: null,
|
||||||
end_at: null
|
end_at: null
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$scope.accountingPeriods = periods;
|
||||||
|
|
||||||
// AngularUI-Bootstrap datepickers parameters to define the period to close
|
// AngularUI-Bootstrap datepickers parameters to define the period to close
|
||||||
$scope.datePicker = {
|
$scope.datePicker = {
|
||||||
format: Fablab.uibDateFormat,
|
format: Fablab.uibDateFormat,
|
||||||
|
@ -50,71 +50,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr ng-repeat="period in accountingPeriods">
|
||||||
<td>01/01/1970</td>
|
<td>{{period.start_at | amDateFormat:'L'}}</td>
|
||||||
<td>01/01/1971</td>
|
<td>{{period.end_at | amDateFormat:'L'}}</td>
|
||||||
<td>04/01/2019 18:12</td>
|
<td>{{period.closed_at | amDateFormat:'L'}}</td>
|
||||||
<td>Roger Rabbit</td>
|
<td>{{period.user_name}}</td>
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1971</td>
|
|
||||||
<td>01/01/1972</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1972</td>
|
|
||||||
<td>01/01/1973</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1973</td>
|
|
||||||
<td>01/01/1974</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1974</td>
|
|
||||||
<td>01/01/1975</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1975</td>
|
|
||||||
<td>01/01/1976</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1976</td>
|
|
||||||
<td>01/01/1977</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1977</td>
|
|
||||||
<td>01/01/1978</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1978</td>
|
|
||||||
<td>01/01/1979</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1979</td>
|
|
||||||
<td>01/01/1980</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>01/01/1980</td>
|
|
||||||
<td>01/01/2019</td>
|
|
||||||
<td>04/01/2019 18:12</td>
|
|
||||||
<td>Roger Rabbit</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
@ -7,14 +7,14 @@ class API::AccountingPeriodsController < API::ApiController
|
|||||||
before_action :set_period, only: %i[show]
|
before_action :set_period, only: %i[show]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@accounting_periods = AccountingPeriod.all
|
@accounting_periods = AccountingPeriodService.all_periods_with_users
|
||||||
end
|
end
|
||||||
|
|
||||||
def show; end
|
def show; end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
authorize AccountingPeriod
|
authorize AccountingPeriod
|
||||||
@accounting_period = AccountingPeriod.new(period_params)
|
@accounting_period = AccountingPeriod.new(period_params.merge(closed_at: DateTime.now, closed_by: current_user.id))
|
||||||
if @accounting_period.save
|
if @accounting_period.save
|
||||||
render :show, status: :created, location: @accounting_period
|
render :show, status: :created, location: @accounting_period
|
||||||
else
|
else
|
||||||
|
@ -3,7 +3,16 @@
|
|||||||
# Provides methods for accessing AccountingPeriods properties
|
# Provides methods for accessing AccountingPeriods properties
|
||||||
class AccountingPeriodService
|
class AccountingPeriodService
|
||||||
|
|
||||||
def find_last_period
|
def self.find_last_period
|
||||||
AccountingPeriod.where(end_at: AccountingPeriod.select('max(end_at)')).first
|
AccountingPeriod.where(end_at: AccountingPeriod.select('max(end_at)')).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.all_periods_with_users
|
||||||
|
AccountingPeriod.joins("INNER JOIN #{User.arel_table.name} ON users.id = accounting_periods.closed_by
|
||||||
|
INNER JOIN #{Profile.arel_table.name} ON profiles.user_id = users.id")
|
||||||
|
.select("#{AccountingPeriod.arel_table.name}.*,
|
||||||
|
#{Profile.arel_table.name}.first_name,
|
||||||
|
#{Profile.arel_table.name}.last_name")
|
||||||
|
.order('start_at DESC')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
6
app/views/api/accounting_periods/index.json.jbuilder
Normal file
6
app/views/api/accounting_periods/index.json.jbuilder
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
json.array!(@accounting_periods) do |ap|
|
||||||
|
json.extract! ap, :id, :start_at, :end_at, :closed_at, :closed_by, :created_at
|
||||||
|
json.user_name "#{ap.first_name} #{ap.last_name}"
|
||||||
|
end
|
@ -413,6 +413,9 @@ en:
|
|||||||
closed_at: "Closed at"
|
closed_at: "Closed at"
|
||||||
closed_by: "By"
|
closed_by: "By"
|
||||||
confirmation_required: "Confirmation required"
|
confirmation_required: "Confirmation required"
|
||||||
|
confirm_close: "Do you really want to close this accounting period ? Any subsequent changes will be impossible."
|
||||||
|
period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed"
|
||||||
|
failed_to_close_period: "An error occurred, unable to close the accounting period"
|
||||||
|
|
||||||
members:
|
members:
|
||||||
# management of users, labels, groups, and so on
|
# management of users, labels, groups, and so on
|
||||||
|
@ -412,6 +412,10 @@ es:
|
|||||||
end_date: "To" # translation_missing
|
end_date: "To" # translation_missing
|
||||||
closed_at: "Closed at" # translation_missing
|
closed_at: "Closed at" # translation_missing
|
||||||
closed_by: "By" # translation_missing
|
closed_by: "By" # translation_missing
|
||||||
|
confirmation_required: "Confirmation required" # translation_missing
|
||||||
|
confirm_close: "Do you really want to close this accounting period ? Any subsequent changes will be impossible." # translation_missing
|
||||||
|
period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" # translation_missing
|
||||||
|
failed_to_close_period: "An error occurred, unable to close the accounting period" # translation_missing
|
||||||
|
|
||||||
members:
|
members:
|
||||||
# management of users, labels, groups, and so on
|
# management of users, labels, groups, and so on
|
||||||
|
@ -412,6 +412,10 @@ pt:
|
|||||||
end_date: "To" # translation_missing
|
end_date: "To" # translation_missing
|
||||||
closed_at: "Closed at" # translation_missing
|
closed_at: "Closed at" # translation_missing
|
||||||
closed_by: "By" # translation_missing
|
closed_by: "By" # translation_missing
|
||||||
|
confirmation_required: "Confirmation required" # translation_missing
|
||||||
|
confirm_close: "Do you really want to close this accounting period ? Any subsequent changes will be impossible." # translation_missing
|
||||||
|
period_START_END_closed_success: "The accounting period from {{START}} to {{END}} has been successfully closed" # translation_missing
|
||||||
|
failed_to_close_period: "An error occurred, unable to close the accounting period" # translation_missing
|
||||||
|
|
||||||
members:
|
members:
|
||||||
# management of users, labels, groups, and so on
|
# management of users, labels, groups, and so on
|
||||||
|
@ -2,12 +2,12 @@ class ProtectAccountingPeriods < ActiveRecord::Migration
|
|||||||
|
|
||||||
# PostgreSQL only
|
# PostgreSQL only
|
||||||
def up
|
def up
|
||||||
execute('CREATE RULE accounting_periods_del_protect AS ON DELETE TO accounting_periods DO INSTEAD NOTHING;')
|
execute("CREATE RULE accounting_periods_del_protect AS ON DELETE TO #{AccountingPeriod.arel_table.name} DO INSTEAD NOTHING;")
|
||||||
execute('CREATE RULE accounting_periods_upd_protect AS ON UPDATE TO accounting_periods DO INSTEAD NOTHING;')
|
execute("CREATE RULE accounting_periods_upd_protect AS ON UPDATE TO #{AccountingPeriod.arel_table.name} DO INSTEAD NOTHING;")
|
||||||
end
|
end
|
||||||
|
|
||||||
def down
|
def down
|
||||||
execute('DROP RULE IF EXISTS accounting_periods_del_protect ON accounting_periods;')
|
execute("DROP RULE IF EXISTS accounting_periods_del_protect ON #{AccountingPeriod.arel_table.name};")
|
||||||
execute('DROP RULE IF EXISTS accounting_periods_upd_protect ON accounting_periods;')
|
execute("DROP RULE IF EXISTS accounting_periods_upd_protect ON #{AccountingPeriod.arel_table.name};")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user