<commit_before>import {Component} from '@angular/core';
import {NavController, NavParams, Alert} from 'ionic-angular';
import {Area} from '../../classes/area';
import {Item} from '../../classes/item';
import {Order} from '../../classes/order';
import {OrderService} from '../../services/order.service';
import {TranslationService} from '../../services/translation.service';

@Component({
  templateUrl: 'build/pages/accounting-overview/accounting-overview.html'
})
export class AccountingOverviewPage {
  
  area: Area;
  accountingItems: AccountingItem[] = [];

  constructor(private nav: NavController, private navParams: NavParams,
              private orderService: OrderService,
              private translationService: TranslationService) {
    this.area = navParams.get('area');
    this.loadOpenAccountingItems();
  }

  loadOpenAccountingItems() {
    this.accountingItems = [];
    let orders = this.orderService.getOpenOrdersByArea(this.area);
    for (let order of orders) {
      let accountingItem = new AccountingItem();
      accountingItem.order = order;
      accountingItem.selected = false;
      this.accountingItems.push(accountingItem);
    }
  }

  getSelectableItemCount() {
    return this.accountingItems.length;
  }

  getSelectedItemCount() {
    let count: number = 0;
    for (let accountingItem of this.accountingItems) {
      if (accountingItem.selected) {
        count = count + 1;
      }
    }
    return count;
  }

  getSelectedItemAmount() {
    let amount: number = 0;
    for (let accountingItem of this.accountingItems) {
      if (accountingItem.selected) {
        amount = amount + accountingItem.order.item.price;
      }
    }
    return amount;
  }

  closeSelectedOrders() {
    for (let accountingItem of this.accountingItems) {
      if (accountingItem.selected) {
        this.orderService.closeOrder(accountingItem.order)
      }
    }
    this.loadOpenAccountingItems();
  }

  closeAllOrders() {
    for (let accountingItem of this.accountingItems) {
      this.orderService.closeOrder(accountingItem.order)
    }
    this.loadOpenAccountingItems();
  }

  onBill(event) {
    let confirm = Alert.create({
      title: this.getSelectedItemAmount().toString() + '€',
      message: 'Soll der Betrag abgebucht werden?',
      buttons: [
        { text: this.translationService.getTranslation('YES'),
          handler: () => { this.closeSelectedOrders(); }
        },
        { text: this.translationService.getTranslation('NO') }
      ]
    });
    this.nav.present(confirm);
  }

  onBillAll(event) {
    let confirm = Alert.create({
      title: this.getSelectedItemAmount().toString() + '€',
      message: 'Soll der Gesamtbetrag abgebucht werden?',
      buttons: [
        { text: this.translationService.getTranslation('YES'),
          handler: () => { this.closeAllOrders(); }
        },
        { text: this.translationService.getTranslation('NO') }
      ]
    });<commit_msg>bug fixed in page accounting-overview: the overall amount is calculatet correctly<commit_after>import {Component} from '@angular/core';
import {NavController, NavParams, Alert} from 'ionic-angular';
import {Area} from '../../classes/area';
import {Item} from '../../classes/item';
import {Order} from '../../classes/order';
import {OrderService} from '../../services/order.service';
import {TranslationService} from '../../services/translation.service';

@Component({
  templateUrl: 'build/pages/accounting-overview/accounting-overview.html'
})
export class AccountingOverviewPage {
  
  area: Area;
  accountingItems: AccountingItem[] = [];

  constructor(private nav: NavController, private navParams: NavParams,
              private orderService: OrderService,
              private translationService: TranslationService) {
    this.area = navParams.get('area');
    this.loadOpenAccountingItems();
  }

  loadOpenAccountingItems() {
    this.accountingItems = [];
    let orders = this.orderService.getOpenOrdersByArea(this.area);
    for (let order of orders) {
      let accountingItem = new AccountingItem();
      accountingItem.order = order;
      accountingItem.selected = false;
      this.accountingItems.push(accountingItem);
    }
  }

  getSelectableItemCount() {
    return this.accountingItems.length;
  }

  getSelectedItemCount() {
    let count: number = 0;
    for (let accountingItem of this.accountingItems) {
      if (accountingItem.selected) {
        count = count + 1;
      }
    }
    return count;
  }

  getSelectedItemAmount() {
    let amount: number = 0;
    for (let accountingItem of this.accountingItems) {
      if (accountingItem.selected) {
        amount = amount + accountingItem.order.item.price;
      }
    }
    return amount;
  }

  getOverallItemAmount() {
    let amount: number = 0;
    for (let accountingItem of this.accountingItems) {
      amount = amount + accountingItem.order.item.price;
    }
    return amount;
  }

  closeSelectedOrders() {
    for (let accountingItem of this.accountingItems) {
      if (accountingItem.selected) {
        this.orderService.closeOrder(accountingItem.order)
      }
    }
    this.loadOpenAccountingItems();
  }

  closeAllOrders() {
    for (let accountingItem of this.accountingItems) {
      this.orderService.closeOrder(accountingItem.order)
    }
    this.loadOpenAccountingItems();
  }

  onBill(event) {
    let confirm = Alert.create({
      title: this.getSelectedItemAmount().toString() + '€',
      message: 'Soll der Betrag abgebucht werden?',
      buttons: [
        { text: this.translationService.getTranslation('YES'),
          handler: () => { this.closeSelectedOrders(); }
        },
        { text: this.translationService.getTranslation('NO') }
      ]
    });
    this.nav.present(confirm);
  }

  onBillAll(event) {
    let confirm = Alert.create({
      title: this.getOverallItemAmount().toString() + '€',
      message: 'Soll der Gesamtbetrag abgebucht werden?',
      buttons: [
        { text: this.translationService.getTranslation('YES'),
          handler: () => { this.closeAllOrders(); }
        },
        { text: this.translationService.getTranslation('NO') }
      ]
    });
{'fraction_non_alphanumeric': 0.1278843028924277, 'fraction_numerical': 0.0011374715632109197, 'mean_word_length': 3.036065573770492, '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': '5042824', 'n_tokens_mistral': 1787, 'n_tokens_neox': 1755, 'n_words': 365}