mirror of
https://github.com/gwenhael-le-moine/ledgerrb.git
synced 2025-01-27 07:58:31 +01:00
periods between salaries
This commit is contained in:
parent
b876b66fdc
commit
3e5b129b7e
4 changed files with 48 additions and 20 deletions
4
app.rb
4
app.rb
|
@ -29,6 +29,10 @@ class LedgerRbApp < Sinatra::Base
|
||||||
Ledger.accounts( params[ :depth ] ).to_json
|
Ledger.accounts( params[ :depth ] ).to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
get '/api/ledger/dates_salaries/?' do
|
||||||
|
Ledger.dates_salaries.to_json
|
||||||
|
end
|
||||||
|
|
||||||
get '/api/ledger/register/?' do
|
get '/api/ledger/register/?' do
|
||||||
param :period, String, default: nil
|
param :period, String, default: nil
|
||||||
param :category, String, required: true
|
param :category, String, required: true
|
||||||
|
|
|
@ -27,6 +27,15 @@ module Ledger
|
||||||
end.uniq
|
end.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def dates_salaries( category = 'salaire' )
|
||||||
|
CSV.parse( run( '', 'csv', category ) )
|
||||||
|
.map do
|
||||||
|
|row|
|
||||||
|
Date.parse row[ 0 ]
|
||||||
|
end
|
||||||
|
.uniq
|
||||||
|
end
|
||||||
|
|
||||||
def register( period = nil, categories = '' )
|
def register( period = nil, categories = '' )
|
||||||
period = period.nil? ? '' : "-p '#{period}'"
|
period = period.nil? ? '' : "-p '#{period}'"
|
||||||
|
|
||||||
|
|
|
@ -74,23 +74,18 @@ app.controller( 'BalanceCtrl',
|
||||||
// }
|
// }
|
||||||
} );
|
} );
|
||||||
|
|
||||||
$scope.month_offset = 0;
|
|
||||||
|
|
||||||
// retrieve_data() when the value of week_offset changes
|
|
||||||
// n.b.: triggered when week_offset is initialized above
|
|
||||||
$scope.$watch( 'month_offset', function() { retrieve_data(); } );
|
|
||||||
|
|
||||||
$scope.incr_offset = function() { $scope.month_offset++; };
|
|
||||||
$scope.decr_offset = function() { $scope.month_offset--; };
|
|
||||||
$scope.reset_offset = function() { $scope.month_offset = 0; };
|
|
||||||
|
|
||||||
var retrieve_data = function() {
|
var retrieve_data = function() {
|
||||||
$scope.from_date = moment().subtract( $scope.month_offset, 'months' ).startOf( 'month' ).toDate();
|
// $scope.from_date = moment().subtract( $scope.period_offset, 'months' ).startOf( 'month' ).toDate();
|
||||||
$scope.to_date = moment().subtract( $scope.month_offset, 'months' ).endOf( 'month' ).toDate();
|
// $scope.to_date = moment().subtract( $scope.period_offset, 'months' ).endOf( 'month' ).toDate();
|
||||||
|
$scope.from_date = new Date( $scope.dates_salaries[ $scope.period_offset ] );
|
||||||
|
$scope.to_date = ( $scope.period_offset < $scope.dates_salaries.length - 1 ) ? new Date( $scope.dates_salaries[ $scope.period_offset + 1 ] ) : null;
|
||||||
var from = moment( $scope.from_date );
|
var from = moment( $scope.from_date );
|
||||||
var to = moment( $scope.to_date );
|
var period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.date();
|
||||||
var period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.date() + ' to ' + to.year() + '-' + ( to.month() + 1 ) + '-' + to.date();
|
if ( !_($scope.to_date).isNull() ) {
|
||||||
|
var to = moment( $scope.to_date );
|
||||||
|
period = period + ' to ' + to.year() + '-' + ( to.month() + 1 ) + '-' + to.date();
|
||||||
|
}
|
||||||
|
console.log(period)
|
||||||
$scope.balance = { expenses: [],
|
$scope.balance = { expenses: [],
|
||||||
income: [],
|
income: [],
|
||||||
details: {} };
|
details: {} };
|
||||||
|
@ -141,5 +136,21 @@ app.controller( 'BalanceCtrl',
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
|
||||||
//retrieve_data();
|
$scope.dates_salaries = [];
|
||||||
}]);
|
$scope.period_offset = 0;
|
||||||
|
$scope.after = function() { if ( $scope.period_offset < $scope.dates_salaries.length - 1 ) { $scope.period_offset++; } };
|
||||||
|
$scope.before = function() { if ( $scope.period_offset > 0 ) { $scope.period_offset--; } };
|
||||||
|
$scope.reset_offset = function() { $scope.period_offset = $scope.dates_salaries.length - 1; };
|
||||||
|
|
||||||
|
$http.get( '/api/ledger/dates_salaries' )
|
||||||
|
.then( function( response ) {
|
||||||
|
$scope.dates_salaries = response.data;
|
||||||
|
|
||||||
|
$scope.reset_offset();
|
||||||
|
|
||||||
|
// retrieve_data() when the value of week_offset changes
|
||||||
|
// n.b.: triggered when week_offset is initialized above
|
||||||
|
$scope.$watch( 'period_offset', function() { retrieve_data(); } );
|
||||||
|
|
||||||
|
} );
|
||||||
|
} ] );
|
||||||
|
|
|
@ -2,13 +2,17 @@
|
||||||
|
|
||||||
<div class="col-md-12 date">
|
<div class="col-md-12 date">
|
||||||
<h2>
|
<h2>
|
||||||
From {{from_date | date:'longDate'}} to {{to_date | date:'longDate'}}
|
From {{from_date | date:'longDate'}} <span data-ng-if="to_date">to {{to_date | date:'longDate'}}</span>
|
||||||
|
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<button class="btn btn-default" data-ng-click="reset_offset()">Aujourd'hui</button>
|
<button class="btn btn-default" data-ng-click="reset_offset()">Aujourd'hui</button>
|
||||||
<div class="btn-group">
|
<div class="btn-group">
|
||||||
<button class="btn btn-default" data-ng-click="incr_offset()"><span class="glyphicon glyphicon-chevron-left"></span></button>
|
<button class="btn btn-default"
|
||||||
<button class="btn btn-default" data-ng-click="decr_offset()"><span class="glyphicon glyphicon-chevron-right"></span></button>
|
data-ng-click="before()"
|
||||||
|
data-ng-class="{'disabled': period_offset == 0}"><span class="glyphicon glyphicon-chevron-left"></span></button>
|
||||||
|
<button class="btn btn-default"
|
||||||
|
data-ng-click="after()"
|
||||||
|
data-ng-class="{'disabled': period_offset == dates_salaries.length - 1}"><span class="glyphicon glyphicon-chevron-right"></span></button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
Loading…
Add table
Reference in a new issue