<commit_before>'use strict';

angular.module('ddsApp').controller('FoyerPensionsAlimentairesCtrl', function($scope, ressourceTypes, SituationService, IndividuService, RessourceService) {

    var momentDebutAnnee = moment($scope.situation.dateDeValeur).subtract('years', 1);
    $scope.debutAnneeGlissante = momentDebutAnnee.format('MMMM YYYY');
    $scope.currentMonth = moment($scope.situation.dateDeValeur).format('MMMM YYYY');
    var months = SituationService.getMonths($scope.situation.dateDeValeur);

    var initMontantsMensuels = function(individu, pensionType) {
        var result = _.map(months, function(month) {
            var ressource = _.find(individu.ressources, { periode: month.id, type: pensionType });
            return ressource ? RessourceService.roundToCents(ressource.montant) : 0;
        });

        return result;
    };

    var initMontantAnnuel = function(individu, pensionType) {
        var result = _.chain(individu.ressources)
            .where({ type: pensionType })
            .pluck('montant')
            .reduce(function(sum, num) {
                return sum + num;
            })
            .value();

        return RessourceService.roundToCents(result) || 0;
    };

    $scope.pensionsVersees = _.find(ressourceTypes, { id: 'pensionsAlimentairesVersees' });

    function createIndividuVM (individu) {
        return {
            individu: individu,
            label: IndividuService.label(individu),
            pensionsVersees: {
                type: $scope.pensionsVersees,
                montantsMensuels: initMontantsMensuels(individu, 'pensionsAlimentairesVersees'),
                montantAnnuel: initMontantAnnuel(individu, 'pensionsAlimentairesVersees'),
                onGoing: true
            }
        };
    };

    var demandeur = _.find($scope.situation.individus, { role: 'demandeur' });
    var conjoint = _.find($scope.situation.individus, { role: 'conjoint' });
    $scope.individusVM = [createIndividuVM(demandeur)];
    if (conjoint) {
        $scope.individusVM.push(createIndividuVM(conjoint));
    }

    $scope.situation.parentsPayPensionsAlimentaires = false;
    $scope.individusVM.forEach(function(individuVM) {
        if (_.any([
            _.find(individuVM.individu.ressources, { type: 'pensionsAlimentairesVersees' })
        ])) {
            $scope.situation.parentsPayPensionsAlimentaires = true;
        }
    });

    function applyPensionToIndividu (individuVM) {
        var individu = individuVM.individu;
        var ressource = individuVM.pensionsVersees;
        RessourceService.spreadIndividuRessources(individu, months, ressource, $scope.situation.dateDeValeur);
    };

    $scope.submit = function(form) {
        form.submitted = true;
        if (form.$valid) {
            $scope.individusVM.forEach(function (individuVM) {
                // Remove old pensions alimentaires versees
                individuVM.individu.ressources = _.filter(individuVM.individu.ressources, function(ressource) {
                    return ! _.contains(['pensionsAlimentairesVersees'], ressource.type);
                });
                if ($scope.situation.parentsPayPensionsAlimentaires) {
                    applyPensionToIndividu(individuVM);
                }
            });
            $scope.$emit('pensionsAlimentaires');
        }
    };
});<commit_msg>Remove unnecessary semicolons<commit_after>'use strict';

angular.module('ddsApp').controller('FoyerPensionsAlimentairesCtrl', function($scope, ressourceTypes, SituationService, IndividuService, RessourceService) {

    var momentDebutAnnee = moment($scope.situation.dateDeValeur).subtract('years', 1);
    $scope.debutAnneeGlissante = momentDebutAnnee.format('MMMM YYYY');
    $scope.currentMonth = moment($scope.situation.dateDeValeur).format('MMMM YYYY');
    var months = SituationService.getMonths($scope.situation.dateDeValeur);

    var initMontantsMensuels = function(individu, pensionType) {
        var result = _.map(months, function(month) {
            var ressource = _.find(individu.ressources, { periode: month.id, type: pensionType });
            return ressource ? RessourceService.roundToCents(ressource.montant) : 0;
        });

        return result;
    };

    var initMontantAnnuel = function(individu, pensionType) {
        var result = _.chain(individu.ressources)
            .where({ type: pensionType })
            .pluck('montant')
            .reduce(function(sum, num) {
                return sum + num;
            })
            .value();

        return RessourceService.roundToCents(result) || 0;
    };

    $scope.pensionsVersees = _.find(ressourceTypes, { id: 'pensionsAlimentairesVersees' });

    function createIndividuVM (individu) {
        return {
            individu: individu,
            label: IndividuService.label(individu),
            pensionsVersees: {
                type: $scope.pensionsVersees,
                montantsMensuels: initMontantsMensuels(individu, 'pensionsAlimentairesVersees'),
                montantAnnuel: initMontantAnnuel(individu, 'pensionsAlimentairesVersees'),
                onGoing: true
            }
        };
    }

    var demandeur = _.find($scope.situation.individus, { role: 'demandeur' });
    var conjoint = _.find($scope.situation.individus, { role: 'conjoint' });
    $scope.individusVM = [createIndividuVM(demandeur)];
    if (conjoint) {
        $scope.individusVM.push(createIndividuVM(conjoint));
    }

    $scope.situation.parentsPayPensionsAlimentaires = false;
    $scope.individusVM.forEach(function(individuVM) {
        if (_.any([
            _.find(individuVM.individu.ressources, { type: 'pensionsAlimentairesVersees' })
        ])) {
            $scope.situation.parentsPayPensionsAlimentaires = true;
        }
    });

    function applyPensionToIndividu (individuVM) {
        var individu = individuVM.individu;
        var ressource = individuVM.pensionsVersees;
        RessourceService.spreadIndividuRessources(individu, months, ressource, $scope.situation.dateDeValeur);
    }

    $scope.submit = function(form) {
        form.submitted = true;
        if (form.$valid) {
            $scope.individusVM.forEach(function (individuVM) {
                // Remove old pensions alimentaires versees
                individuVM.individu.ressources = _.filter(individuVM.individu.ressources, function(ressource) {
                    return ! _.contains(['pensionsAlimentairesVersees'], ressource.type);
                });
                if ($scope.situation.parentsPayPensionsAlimentaires) {
                    applyPensionToIndividu(individuVM);
                }
            });
            $scope.$emit('pensionsAlimentaires');
        }
    };
});
{'fraction_non_alphanumeric': 0.11345411345411345, 'fraction_numerical': 0.000891000891000891, 'mean_word_length': 2.6504065040650406, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7051882', 'n_tokens_mistral': 2113, 'n_tokens_neox': 2030, 'n_words': 294}