<commit_before>'use strict';

/**
 */
angular.module('openolitor-admin')
  .controller('AbosOverviewCreateRechnungsPositionenController', ['$scope', '$filter', '$routeParams',
    '$location', '$route', '$uibModal', '$log', '$http', 'gettext',
    'moment', 'EnumUtil', 'DataUtil', 'msgBus', '$q', 'lodash',
    'API_URL', 'alertService', 'AbosOverviewService',

    function($scope, $filter, $routeParams, $location, $route, $uibModal,
      $log, $http, gettext,
      moment, EnumUtil, DataUtil, msgBus, $q, _, API_URL,
      alertService, AbosOverviewService) {

      $scope.rechnungsPositionen = {
        ids: $scope.aboIds,
        waehrung: 'CHF'
      };

      $scope.form = {
        mode: 'AnzahlLieferungen',
        manuellerBetrag: false
      };

      $scope.batchCreated = {
        ids: [],
        openAboIds: $scope.aboIds
      };

      $scope.commandIssued = false;

      $scope.open = {
        start: false
      };

      $scope.batchCreate = function() {
        switch($scope.form.mode) {
          case 'AnzahlLieferungen':
            AbosOverviewService.createAnzahlLieferungenRechnungsPositionen($scope.rechnungsPositionen).then(function() {
              $scope.commandIssued = true;
              $scope.createHasWorked = true;
            }, function (){
              $scope.commandIssued = true;
              $scope.createHasWorked = false;
              console.log('AnzahlLieferungen error');
            });
            break;
          case 'BisGuthaben':
             AbosOverviewService.createBisGuthabenRechnungsPositionen($scope.rechnungsPositionen).then(function() {
              $scope.commandIssued = true;
              $scope.createHasWorked = true;
            }, function (){
              $scope.commandIssued = true;
              console.log('BisGuthaben error');
              $scope.createHasWorked = false;
            });
            break;
        }
      };

      $scope.openCalendar = function(e, date) {
        e.preventDefault();
        e.stopPropagation();

        $scope.open[date] = true;
      };

      $scope.jumpToRechnungspositionen = function() {
        $location.path('/rechnungspositionen').search('q', 'id=' + $scope.batchCreated.ids.join());
      };

      $scope.jumpToAbosWhereCreateHasFailed = function() {
        $scope.filterQuery = 'id=' + $scope.batchCreated.openAboIds.join();
      };
      
      msgBus.onMsg('EntityCreated', $scope, function(event, msg) {
        if (msg.entity === 'RechnungsPosition') {
          if(_.includes($scope.rechnungsPositionen.ids, msg.data.aboId)) {
            $scope.batchCreated.ids.push(msg.data.id);
            _.pull($scope.batchCreated.openAboIds, msg.data.aboId);
            $scope.$apply();
          }
        }
      });
    }
  ]);<commit_msg>OO-805 only fetch ids on Click<commit_after>'use strict';

/**
 */
angular.module('openolitor-admin')
  .controller('AbosOverviewCreateRechnungsPositionenController', ['$scope', '$filter', '$routeParams',
    '$location', '$route', '$uibModal', '$log', '$http', 'gettext',
    'moment', 'EnumUtil', 'DataUtil', 'msgBus', '$q', 'lodash',
    'API_URL', 'alertService', 'AbosOverviewService',

    function($scope, $filter, $routeParams, $location, $route, $uibModal,
      $log, $http, gettext,
      moment, EnumUtil, DataUtil, msgBus, $q, _, API_URL,
      alertService, AbosOverviewService) {

      $scope.rechnungsPositionen = {
        waehrung: 'CHF'
      };

      $scope.form = {
        mode: 'AnzahlLieferungen',
        manuellerBetrag: false
      };

      $scope.batchCreated = {
        ids: [],
        openAboIds: $scope.aboIds
      };

      $scope.commandIssued = false;

      $scope.open = {
        start: false
      };

      $scope.batchCreate = function() {
        $scope.rechnungsPositionen.ids = $scope.aboIds;
        switch($scope.form.mode) {
          case 'AnzahlLieferungen':
            AbosOverviewService.createAnzahlLieferungenRechnungsPositionen($scope.rechnungsPositionen).then(function() {
              $scope.commandIssued = true;
              $scope.createHasWorked = true;
            }, function (){
              $scope.commandIssued = true;
              $scope.createHasWorked = false;
              console.log('AnzahlLieferungen error');
            });
            break;
          case 'BisGuthaben':
             AbosOverviewService.createBisGuthabenRechnungsPositionen($scope.rechnungsPositionen).then(function() {
              $scope.commandIssued = true;
              $scope.createHasWorked = true;
            }, function (){
              $scope.commandIssued = true;
              console.log('BisGuthaben error');
              $scope.createHasWorked = false;
            });
            break;
        }
      };

      $scope.openCalendar = function(e, date) {
        e.preventDefault();
        e.stopPropagation();

        $scope.open[date] = true;
      };

      $scope.jumpToRechnungspositionen = function() {
        $location.path('/rechnungspositionen').search('q', 'id=' + $scope.batchCreated.ids.join());
      };

      $scope.jumpToAbosWhereCreateHasFailed = function() {
        $scope.filterQuery = 'id=' + $scope.batchCreated.openAboIds.join();
      };

      msgBus.onMsg('EntityCreated', $scope, function(event, msg) {
        if (msg.entity === 'RechnungsPosition') {
          if(_.includes($scope.rechnungsPositionen.ids, msg.data.aboId)) {
            $scope.batchCreated.ids.push(msg.data.id);
            _.pull($scope.batchCreated.openAboIds, msg.data.aboId);
            $scope.$apply();
          }
        }
      });
    }
  ]);
{'fraction_non_alphanumeric': 0.14634146341463414, 'fraction_numerical': 0.0005340929321701976, 'mean_word_length': 2.247398843930636, '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': '5713814', 'n_tokens_mistral': 1738, 'n_tokens_neox': 1692, 'n_words': 247}