// Implementación del módulo de tickets. Ver ticket.h.
#include "ticket.h"

#include <stdio.h>

#include "money.h"

static void print_line(const struct item *item) {
    printf("%-8s %3d  ", item->name, item->quantity);
    money_print(item_total(item));
    printf("\n");
}

void ticket_print(const struct item items[], int n, int percent) {
    for (int i = 0; i < n; i++) {
        print_line(&items[i]);
    }

    int total = items_total(items, n);
    printf("Total:         ");
    money_print(total);
    printf("\nCon %d%%:       ", percent);
    money_print(money_discount(total, percent));
    printf("\n");
}
