<commit_before>//
//  ViewController.swift
//  invoicer
//
//  Created by <NAME> on 23/01/15.
//  Copyright (c) 2015 paulosilva. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
  var clientRepository = ClientRepository()
  var itemRepository = ItemRepository()
  var interactor = CreateInvoice()
  
  @IBOutlet var date: UITextField!
  @IBOutlet var client: UITextField!
  @IBOutlet var item: UITextField!
  @IBOutlet var clientPicker: UIPickerView!
  @IBOutlet var itemPicker: UIPickerView!
  
  @IBOutlet weak var itemSumLabel: UILabel!
  @IBOutlet weak var itemVatLabel: UILabel!
  @IBOutlet weak var itemTotalLabel: UILabel!
  
  @IBOutlet weak var createInvoiceButton: UIButton!
  
  @IBAction func createInvoice(sender: UIButton) {
    guard var _date = date.text,
        var _client = client.text,
        var _item = item.text else {
            return
    }
    var _unitPrice = itemRepository.getItemPrice(name: item.text!)
    
    var result = interactor.run(date: _date, client: _client, item: _item, unitPrice: _unitPrice)
    
    if (result) {
      print("Invoice created successfully")
    } else {
      print("Error creating invoice")
    }
  }
  
  override func viewDidLoad() {
    super.viewDidLoad()
    setDefaultDate()
    setClientPicker()
    setItemPicker()
  }
  
  func setDefaultDate() {
    let dateObject = Date()
    var dateFormatter = DateFormatter()
    dateFormatter.dateFormat = "dd-MM-yyyy"
    date.text = dateFormatter.string(from: dateObject)
  }
  
  func setClientPicker() {
    clientPicker = UIPickerView()
    clientPicker.dataSource = self
    clientPicker.delegate = self
    client.inputView = clientPicker
  }
  
  func setItemPicker() {
    itemPicker = UIPickerView()
    itemPicker.dataSource = self
    itemPicker.delegate = self
    item.inputView = itemPicker
  }

  override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
  }
  
  func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    self.view.endEditing(true)
  }
  
  /*
  ** UIPickerViewDataSource
  */
  
  // Returns the number of 'columns' to display.
  func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
    return 1
  }
  
  // Returns the # of rows in each component..
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    if pickerView.isEqual(clientPicker) {
      return clientRepository.clients.count
    }
    else {
      return itemRepository.items.count
    }
  }
  
  /*
  ** UIPickerViewDelegate
  */

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    if pickerView.isEqual(clientPicker) {
      return clientRepository.clients[row].name
    }
    else {
      return itemRepository.items[row].name
    }
  }
  
  func formatCurrencyValue(value:Double) -> String {
    return String(format:"€%.2f", value)
  }

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    if pickerView.isEqual(clientPicker) {
      client.text = clientRepository.clients[row].name
    }
    else {
      var selectedItem = itemRepository.items[row]
      
      item.text = selectedItem.name
        itemSumLabel.text = formatCurrencyValue(value: selectedItem.unitPrice)
        itemVatLabel.text = formatCurrencyValue(value: selectedItem.rrp - selectedItem.unitPrice)
        itemTotalLabel.text = formatCurrencyValue(value: selectedItem.rrp)
      
    }
  }
}<commit_msg>re-indent<commit_after>//
//  ViewController.swift
//  invoicer
//
//  Created by <NAME> on 23/01/15.
//  Copyright (c) 2015 paulosilva. All rights reserved.
//

import UIKit

class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
    var clientRepository = ClientRepository()
    var itemRepository = ItemRepository()
    var interactor = CreateInvoice()

    @IBOutlet var date: UITextField!
    @IBOutlet var client: UITextField!
    @IBOutlet var item: UITextField!
    @IBOutlet var clientPicker: UIPickerView!
    @IBOutlet var itemPicker: UIPickerView!

    @IBOutlet weak var itemSumLabel: UILabel!
    @IBOutlet weak var itemVatLabel: UILabel!
    @IBOutlet weak var itemTotalLabel: UILabel!

    @IBOutlet weak var createInvoiceButton: UIButton!

    @IBAction func createInvoice(sender: UIButton) {
        guard var _date = date.text,
            var _client = client.text,
            var _item = item.text else {
                return
        }
        var _unitPrice = itemRepository.getItemPrice(name: item.text!)

        var result = interactor.run(date: _date, client: _client, item: _item, unitPrice: _unitPrice)

        if (result) {
            print("Invoice created successfully")
        } else {
            print("Error creating invoice")
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        setDefaultDate()
        setClientPicker()
        setItemPicker()
    }

    func setDefaultDate() {
        let dateObject = Date()
        var dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "dd-MM-yyyy"
        date.text = dateFormatter.string(from: dateObject)
    }

    func setClientPicker() {
        clientPicker = UIPickerView()
        clientPicker.dataSource = self
        clientPicker.delegate = self
        client.inputView = clientPicker
    }

    func setItemPicker() {
        itemPicker = UIPickerView()
        itemPicker.dataSource = self
        itemPicker.delegate = self
        item.inputView = itemPicker
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        self.view.endEditing(true)
    }

    /*
     ** UIPickerViewDataSource
     */

    // Returns the number of 'columns' to display.
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
        return 1
    }

    // Returns the # of rows in each component..
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        if pickerView.isEqual(clientPicker) {
            return clientRepository.clients.count
        }
        else {
            return itemRepository.items.count
        }
    }

    /*
     ** UIPickerViewDelegate
     */

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        if pickerView.isEqual(clientPicker) {
            return clientRepository.clients[row].name
        }
        else {
            return itemRepository.items[row].name
        }
    }

    func formatCurrencyValue(value:Double) -> String {
        return String(format:"€%.2f", value)
    }

    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        if pickerView.isEqual(clientPicker) {
            client.text = clientRepository.clients[row].name
        }
        else {
            var selectedItem = itemRepository.items[row]

            item.text = selectedItem.name
            itemSumLabel.text = formatCurrencyValue(value: selectedItem.unitPrice)
            itemVatLabel.text = formatCurrencyValue(value: selectedItem.rrp - selectedItem.unitPrice)
            itemTotalLabel.text = formatCurrencyValue(value: selectedItem.rrp)

        }
    }
}

{'fraction_non_alphanumeric': 0.0898250162022035, 'fraction_numerical': 0.003370058327932599, 'mean_word_length': 2.7257363592467407, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '5975649', 'n_tokens_mistral': 2330, 'n_tokens_neox': 2267, 'n_words': 534}