periods between salaries

This commit is contained in:
Gwenhael Le Moine 2014-09-30 12:15:37 +02:00
parent b876b66fdc
commit 3e5b129b7e
4 changed files with 48 additions and 20 deletions

4
app.rb
View file

@ -29,6 +29,10 @@ class LedgerRbApp < Sinatra::Base
Ledger.accounts( params[ :depth ] ).to_json
end
get '/api/ledger/dates_salaries/?' do
Ledger.dates_salaries.to_json
end
get '/api/ledger/register/?' do
param :period, String, default: nil
param :category, String, required: true

View file

@ -27,6 +27,15 @@ module Ledger
end.uniq
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 = '' )
period = period.nil? ? '' : "-p '#{period}'"

View file

@ -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() {
$scope.from_date = moment().subtract( $scope.month_offset, 'months' ).startOf( 'month' ).toDate();
$scope.to_date = moment().subtract( $scope.month_offset, 'months' ).endOf( 'month' ).toDate();
// $scope.from_date = moment().subtract( $scope.period_offset, 'months' ).startOf( '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 to = moment( $scope.to_date );
var period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.date() + ' to ' + to.year() + '-' + ( to.month() + 1 ) + '-' + to.date();
var period = 'from ' + from.year() + '-' + ( from.month() + 1 ) + '-' + from.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: [],
income: [],
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(); } );
} );
} ] );

View file

@ -2,13 +2,17 @@
<div class="col-md-12 date">
<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">
<button class="btn btn-default" data-ng-click="reset_offset()">Aujourd'hui</button>
<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" data-ng-click="decr_offset()"><span class="glyphicon glyphicon-chevron-right"></span></button>
<button class="btn btn-default"
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>
</h2>