Skip to content

Commit aef3f47

Browse files
committed
fix (splitBill): Add option to export with details
1 parent c388ddf commit aef3f47

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

SplitBill/splitBill.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,18 @@ <h3>Persons:</h3>
506506

507507
function share() {
508508
const title = document.title;
509+
510+
const detailed = confirm("Include details? (product per person)");
509511
const totalDiff = (itemsPrice - personsPrice).formatPrice();
510-
const text = data.persons.map(person => `${person.name}: ${calculatePersonTotal(person).formatPrice()}`).join("\n") + (
512+
const text = data.persons.flatMap(person => [
513+
`${person.name}: ${calculatePersonTotal(person).formatPrice()}${person.paid ? ' (paid)' : ''}`,
514+
...(!detailed ? [] :
515+
// keep order from data.items array
516+
data.items.map(item => [item, getAmount(person, item)])
517+
.filter(e => e[1] != 0)
518+
.map(([item, amount]) => ` - ${item.name}${amount == 1 ? '' : ` (${amount})`}: ${(item.price*amount).formatPrice()}`)
519+
)
520+
]).join("\n") + (
511521
totalDiff > 0 ? `\nUnknown: ${totalDiff}` :
512522
totalDiff < 0 ? `\nExtra: ${-totalDiff}` :
513523
""

0 commit comments

Comments
 (0)