<commit_before>package tomas_vycital.eet.android_app.receipt;

import android.os.Handler;
import android.util.SparseIntArray;

import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import tomas_vycital.eet.android_app.Messages;
import tomas_vycital.eet.android_app.VAT;
import tomas_vycital.eet.android_app.items.Item;
import tomas_vycital.eet.android_app.items.ItemList;
import tomas_vycital.eet.android_app.printer.Printer;
import tomas_vycital.eet.android_app.printer.PrinterUtils;
import tomas_vycital.eet.android_app.settings.Settings;
import tomas_vycital.eet.lib.EETReceipt;

/**
 * Holds bought items
 */

public class Receipt implements ItemList {
    private final Handler handler;
    EETReceipt eetReceipt;
    private List<Item> items;
    private int multiplier;

    public Receipt(Handler handler) {
        this.items = new ArrayList<>();
        this.handler = handler;
        this.clear();
    }

    public void add(Item item) {
        this.changed();
        this.items.add(item);
    }

    public void remove(int i) {
        this.changed();
        this.items.remove(i);
    }

    public void setNegative(boolean negative) {
        this.changed();
        this.multiplier = negative ? -1 : 1;
    }

    public boolean isEmpty() {
        return this.items.isEmpty();
    }

    public String getReceiptStr() {
        String negative = this.multiplier == 1 ? "" : "-";
        String str = Settings.getHeading() + "\n"
                + PrinterUtils.getSeparatorNl()
                + "DIČ: " + Settings.getDIC() + "\n"
                + PrinterUtils.getSeparatorNl();
        HashMap<String, Integer> amounts = new HashMap<>();
        List<Item> items = new ArrayList<>();

        int sumWithVAT = 0;
        int sumWithoutVAT = 0;

        for (int i = 0; i < this.items.size(); ++i) {
            Item item = this.items.get(i);
            Integer current = amounts.get(item.getName());
            if (current == null) {
                current = 0;
                items.add(item);
            }

            amounts.put(item.getName(), current + 1);
            sumWithVAT += item.getPrice();
            sumWithoutVAT += item.getPrice() * (1 - (float) item.getVATPercentage() / 100);
        }

        Collections.sort(items);
        for (int i = 0; i < items.size(); ++i) {
            Item item = items.get(i);
            int amount = amounts.get(item.getName());
            str += PrinterUtils.align(amount + " ks: " + item.getName(), negative + item.getPriceStr()) + "\n";
        }

        str += PrinterUtils.getSeparatorNl();
        str += "Součet bez DPH: " + negative + Item.priceFormat.format(sumWithoutVAT / 100.0) + "\n";
        str += "           DPH: " + negative + Item.priceFormat.format((sumWithVAT - sumWithoutVAT) / 100.0) + "\n";
        str += "        Součet: " + negative + Item.priceFormat.format(sumWithVAT / 100.0) + "\n";

        if (this.eetReceipt != null) {
            str += "\n";
            str += "BKP: " + this.eetReceipt.getBKP() + "\n";
            if (this.eetReceipt.getFIK() == null) {
                str += "PKP: " + this.eetReceipt.getPKP() + "\n";
            } else {
                str += "FIK: " + this.eetReceipt.getFIK() + "\n";
            }
            str += "Režim tržby: " + Settings.getModeStr() + "\n";
        }
        str += PrinterUtils.getSeparatorNl();

        str += Settings.getFooting() + "\n";

        // Limit the receipt to the actual width of the physical receipt<commit_msg>Zarovnej součty na účtence<commit_after>package tomas_vycital.eet.android_app.receipt;

import android.os.Handler;
import android.util.SparseIntArray;

import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import tomas_vycital.eet.android_app.Messages;
import tomas_vycital.eet.android_app.VAT;
import tomas_vycital.eet.android_app.items.Item;
import tomas_vycital.eet.android_app.items.ItemList;
import tomas_vycital.eet.android_app.printer.Printer;
import tomas_vycital.eet.android_app.printer.PrinterUtils;
import tomas_vycital.eet.android_app.settings.Settings;
import tomas_vycital.eet.lib.EETReceipt;

/**
 * Holds bought items
 */

public class Receipt implements ItemList {
    private final Handler handler;
    EETReceipt eetReceipt;
    private List<Item> items;
    private int multiplier;

    public Receipt(Handler handler) {
        this.items = new ArrayList<>();
        this.handler = handler;
        this.clear();
    }

    public void add(Item item) {
        this.changed();
        this.items.add(item);
    }

    public void remove(int i) {
        this.changed();
        this.items.remove(i);
    }

    public void setNegative(boolean negative) {
        this.changed();
        this.multiplier = negative ? -1 : 1;
    }

    public boolean isEmpty() {
        return this.items.isEmpty();
    }

    public String getReceiptStr() {
        String negative = this.multiplier == 1 ? "" : "-";
        String str = Settings.getHeading() + "\n"
                + PrinterUtils.getSeparatorNl()
                + "DIČ: " + Settings.getDIC() + "\n"
                + PrinterUtils.getSeparatorNl();
        HashMap<String, Integer> amounts = new HashMap<>();
        List<Item> items = new ArrayList<>();

        int sumWithVAT = 0;
        int sumWithoutVAT = 0;

        for (int i = 0; i < this.items.size(); ++i) {
            Item item = this.items.get(i);
            Integer current = amounts.get(item.getName());
            if (current == null) {
                current = 0;
                items.add(item);
            }

            amounts.put(item.getName(), current + 1);
            sumWithVAT += item.getPrice();
            sumWithoutVAT += item.getPrice() * (1 - (float) item.getVATPercentage() / 100);
        }

        Collections.sort(items);
        for (int i = 0; i < items.size(); ++i) {
            Item item = items.get(i);
            int amount = amounts.get(item.getName());
            str += PrinterUtils.align(amount + " ks: " + item.getName(), negative + item.getPriceStr()) + "\n";
        }

        str += PrinterUtils.getSeparatorNl();
        str += PrinterUtils.align("Součet bez DPH:", negative + Item.priceFormat.format(sumWithoutVAT / 100.0) + " kč\n");
        str += PrinterUtils.align("           DPH:", negative + Item.priceFormat.format((sumWithVAT - sumWithoutVAT) / 100.0) + " kč\n");
        str += PrinterUtils.align("        Součet:", negative + Item.priceFormat.format(sumWithVAT / 100.0) + " kč\n");

        if (this.eetReceipt != null) {
            str += "\n";
            str += "BKP: " + this.eetReceipt.getBKP() + "\n";
            if (this.eetReceipt.getFIK() == null) {
                str += "PKP: " + this.eetReceipt.getPKP() + "\n";
            } else {
                str += "FIK: " + this.eetReceipt.getFIK() + "\n";
            }
            str += "Režim tržby: " + Settings.getModeStr() + "\n";
        }
        str += PrinterUtils.getSeparatorNl();

        str += Settings.getFooting() + "\n";

        // Limit the receipt to the actual width of the physical receipt
{'fraction_non_alphanumeric': 0.13599476439790575, 'fraction_numerical': 0.006544502617801047, 'mean_word_length': 2.3337696335078535, 'pattern_counts': {'":': 0, '<': 19, '<?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': '2277116', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2385, 'n_words': 492}