<commit_before>'use strict';

angular.module('confRegistrationWebApp')
  .service('RegistrationsViewService', function RegistrationsViewService(ConferenceHelper, U, $filter) {

    this.getTable = function (conference, registrations, onlyCompleted, visibleBlockIds) {

      var table = [];
      var header = getHeader(conference, visibleBlockIds);
      table.push(header);
      var rows = getRows(conference, registrations, onlyCompleted, visibleBlockIds);

      // sort rows by last name
      U.sortArrayByIndex(rows, _.findIndex(header, function (string) {
        return angular.equals(string, 'Last');
      }));

      table.push.apply(table, rows);

      return table;
    };

    var getHeader = function (conference, visibleBlockIds) {
      var blocks = ConferenceHelper.getPageBlocks(conference.registrationPages);

      // header row of block titles
      var header = getBlockTitles(blocks, visibleBlockIds);
      header.push('Completed');

      return header;
    };

    var getRows = function (conference, registrations, onlyCompleted, visibleBlockIds) {
      var rows = [];

      var blocks = ConferenceHelper.getPageBlocks(conference.registrationPages);

      // rows of answers
      ConferenceHelper.getRegistrations(registrations, onlyCompleted).forEach(function (registration) {
        angular.forEach(registration.registrants, function (r) {
          var row = [];

          angular.forEach(blocks, function (block) {
            if (angular.isUndefined(visibleBlockIds) || _.indexOf(visibleBlockIds, block.id) > -1) {
              var answer = ConferenceHelper.findAnswerByBlockId(r.answers, block.id);
              var answerContent = ConferenceHelper.getContentByBlockType(U.isEmpty(answer) ? answer : answer.value, block.type);
              row.push.apply(row, answerContent);
            }
          });

          if(registration.completed){
            row.push.apply(row, ['"' + $filter('evtDateFormat')(registration.completedTimestamp, conference.eventTimezone) + '"']);
          }

          rows.push(row);
        });
      });

      return rows;
    };

    var getBlockTitles = function (blocks, visibleBlockIds) {
      var titles = [];

      angular.forEach(blocks, function (block) {
        if (angular.isUndefined(visibleBlockIds) || _.indexOf(visibleBlockIds, block.id) > -1) {
          if (block.type === 'nameQuestion') {
            titles.push('First');
            titles.push('Last');
          }
          else if (block.type === 'addressQuestion') {
            titles.push('Address1');
            titles.push('Address2');
            titles.push('City');
            titles.push('State');
            titles.push('Zip');
          }
          else {
            titles.push(block.title.replace(/,/g, ''));
          }
        }
      });
      return titles;
    };
  });
<commit_msg>Add total due, total paid and remaining balance to the registrations export<commit_after>'use strict';

angular.module('confRegistrationWebApp')
  .service('RegistrationsViewService', function RegistrationsViewService(ConferenceHelper, U, $filter) {

    this.getTable = function (conference, registrations, onlyCompleted, visibleBlockIds) {

      var table = [];
      var header = getHeader(conference, visibleBlockIds);
      table.push(header);
      var rows = getRows(conference, registrations, onlyCompleted, visibleBlockIds);

      // sort rows by last name
      U.sortArrayByIndex(rows, _.findIndex(header, function (string) {
        return angular.equals(string, 'Last');
      }));

      table.push.apply(table, rows);

      return table;
    };

    var getHeader = function (conference, visibleBlockIds) {
      var blocks = ConferenceHelper.getPageBlocks(conference.registrationPages);

      // header row of block titles
      var header = getBlockTitles(blocks, visibleBlockIds);
      header.push('Completed');
      if(ConferenceHelper.hasCost(conference)) {
        header.push('Total Due');
        header.push('Total Paid');
        header.push('Remaining Balance');
      }

      return header;
    };

    var getRows = function (conference, registrations, onlyCompleted, visibleBlockIds) {
      var rows = [];

      var blocks = ConferenceHelper.getPageBlocks(conference.registrationPages);

      // rows of answers
      ConferenceHelper.getRegistrations(registrations, onlyCompleted).forEach(function (registration) {
        angular.forEach(registration.registrants, function (r) {
          var row = [];

          angular.forEach(blocks, function (block) {
            if (angular.isUndefined(visibleBlockIds) || _.indexOf(visibleBlockIds, block.id) > -1) {
              var answer = ConferenceHelper.findAnswerByBlockId(r.answers, block.id);
              var answerContent = ConferenceHelper.getContentByBlockType(U.isEmpty(answer) ? answer : answer.value, block.type);
              row.push.apply(row, answerContent);
            }
          });

          if(registration.completed){
            row.push.apply(row, ['"' + $filter('evtDateFormat')(registration.completedTimestamp, conference.eventTimezone) + '"']);

            if(ConferenceHelper.hasCost(conference)){
              row.push.apply(row, ['"' + $filter('moneyFormat')(registration.calculatedTotalDue) + '"']);
              row.push.apply(row, ['"' + $filter('moneyFormat')(registration.totalPaid) + '"']);
              row.push.apply(row, ['"' + $filter('moneyFormat')(registration.remainingBalance) + '"']);
            }
          }

          rows.push(row);
        });
      });

      return rows;
    };

    var getBlockTitles = function (blocks, visibleBlockIds) {
      var titles = [];

      angular.forEach(blocks, function (block) {
        if (angular.isUndefined(visibleBlockIds) || _.indexOf(visibleBlockIds, block.id) > -1) {
          if (block.type === 'nameQuestion') {
            titles.push('First');
            titles.push('Last');
          }
          else if (block.type === 'addressQuestion') {
            titles.push('Address1');
            titles.push('Address2');
            titles.push('City');
            titles.push('State');
            titles.push('Zip');
          }
          else {
            titles.push(block.title.replace(/,/g, ''));
          }
        }
      });
      return titles;
    };
  });

{'fraction_non_alphanumeric': 0.13077166350411132, 'fraction_numerical': 0.001265022137887413, 'mean_word_length': 2.56941309255079, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5621400', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1688, 'n_words': 317}