1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

list existing closings in close period modal

This commit is contained in:
Sylvain 2019-01-07 16:45:31 +01:00
parent 381dc0aec1
commit 5b13c59496
9 changed files with 45 additions and 77 deletions

View File

@ -17,8 +17,8 @@
/**
* Controller used in the admin invoices listing page
*/
Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'Invoice', 'invoices', '$uibModal', 'growl', '$filter', 'Setting', 'settings', '_t',
function ($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, AccountingPeriod, invoices, $uibModal, growl, $filter, Setting, settings, _t) {
/* PRIVATE STATIC CONSTANTS */
// number of invoices loaded each time we click on 'load more...'
@ -394,7 +394,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
controller: 'ClosePeriodModalController',
size: 'lg',
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
*/
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'dialogs', 'growl', '_t',
function ($scope, $uibModalInstance, Invoice, AccountingPeriod, dialogs, growl, _t) {
Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingPeriod', 'periods' ,'dialogs', 'growl', '_t',
function ($scope, $uibModalInstance, Invoice, AccountingPeriod, periods, dialogs, growl, _t) {
/* PUBLIC SCOPE */
$scope.period = {
start_at: null,
end_at: null
};
$scope.accountingPeriods = periods;
// AngularUI-Bootstrap datepickers parameters to define the period to close
$scope.datePicker = {
format: Fablab.uibDateFormat,

View File

@ -50,71 +50,11 @@
</tr>
</thead>
<tbody>
<tr>
<td>01/01/1970</td>
<td>01/01/1971</td>
<td>04/01/2019 18:12</td>
<td>Roger Rabbit</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 ng-repeat="period in accountingPeriods">
<td>{{period.start_at | amDateFormat:'L'}}</td>
<td>{{period.end_at | amDateFormat:'L'}}</td>
<td>{{period.closed_at | amDateFormat:'L'}}</td>
<td>{{period.user_name}}</td>
</tr>
</tbody>
</table>

View File

@ -7,14 +7,14 @@ class API::AccountingPeriodsController < API::ApiController
before_action :set_period, only: %i[show]
def index
@accounting_periods = AccountingPeriod.all
@accounting_periods = AccountingPeriodService.all_periods_with_users
end
def show; end
def create
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
render :show, status: :created, location: @accounting_period
else

View File

@ -3,7 +3,16 @@
# Provides methods for accessing AccountingPeriods properties
class AccountingPeriodService
def find_last_period
def self.find_last_period
AccountingPeriod.where(end_at: AccountingPeriod.select('max(end_at)')).first
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

View 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

View File

@ -413,6 +413,9 @@ en:
closed_at: "Closed at"
closed_by: "By"
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:
# management of users, labels, groups, and so on

View File

@ -412,6 +412,10 @@ es:
end_date: "To" # translation_missing
closed_at: "Closed at" # 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:
# management of users, labels, groups, and so on

View File

@ -412,6 +412,10 @@ pt:
end_date: "To" # translation_missing
closed_at: "Closed at" # 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:
# management of users, labels, groups, and so on

View File

@ -2,12 +2,12 @@ class ProtectAccountingPeriods < ActiveRecord::Migration
# PostgreSQL only
def up
execute('CREATE RULE accounting_periods_del_protect AS ON DELETE TO accounting_periods DO INSTEAD NOTHING;')
execute('CREATE RULE accounting_periods_upd_protect AS ON UPDATE 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 #{AccountingPeriod.arel_table.name} DO INSTEAD NOTHING;")
end
def down
execute('DROP RULE IF EXISTS accounting_periods_del_protect ON accounting_periods;')
execute('DROP RULE IF EXISTS accounting_periods_upd_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 #{AccountingPeriod.arel_table.name};")
end
end