Skip to content

Commit

Permalink
Further beautifying of the print stuff...
Browse files Browse the repository at this point in the history
Note that the code probably only works with the default printer,
will adjust in the future.
  • Loading branch information
iamtrex committed Aug 28, 2018
1 parent 346939f commit 4465510
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/com/rweqx/controller/PrintSummaryTemplateController.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,25 @@ public void setEvents(long stuID, LocalDate start, LocalDate end, List<Event> ev

eventHours.setText(String.valueOf(duration));
eventRates.setText(String.valueOf(rate));
eventAmount.setText("$" + String.valueOf(amount));
eventAmount.setText("$" + MathUtil.dollarValueFrom(amount));
total += amount;
} else {
Payment p = (Payment) e;
eventDesc.setText("Paid - " + p.getPaymentType());
double amount = p.getPaymentAmount();
eventAmount.setText("$-" + String.valueOf(amount));
eventAmount.setText("- $" + MathUtil.dollarValueFrom(amount));
total -= amount;
}
eventsGrid.addRow(eventsGrid.getRowCount(), eventDate, eventDesc, eventHours, eventRates, eventAmount);
}
lName.setText(student.getName());
lInvoiceDate.setText(LocalDate.now().toString());
lInvoicePeriod.setText(start.toString() + " - " + end.toString());
lTotal.setText("$" + String.valueOf(total));
if(total >= 0) {
lTotal.setText("$" + MathUtil.dollarValueFrom(total));
}else{
lTotal.setText("- $" + MathUtil.dollarValueFrom(total*-1));
}

}

Expand Down
2 changes: 1 addition & 1 deletion src/com/rweqx/ui/print-summary-table.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<ColumnConstraints halignment="RIGHT" hgrow="SOMETIMES" minWidth="10.0" percentWidth="15" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="10.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="16.0" prefHeight="18.0" vgrow="SOMETIMES" />
</rowConstraints>
<children>
<Label styleClass="title-label" text="Amount" GridPane.columnIndex="4" GridPane.halignment="RIGHT" />
Expand Down
12 changes: 12 additions & 0 deletions src/com/rweqx/util/MathUtil.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
package com.rweqx.util;

import java.text.DecimalFormat;

public class MathUtil {

public static double round(double value, int digits){
return (Math.round(value * Math.pow(10, digits)))/Math.pow(10, digits);
}

public static String dollarValueFrom(double amount) {
DecimalFormat format;
if(Math.floor(amount) == amount){
format = new DecimalFormat("#");
}else {
format = new DecimalFormat("#.00");
}
return format.format(amount);
}
}

0 comments on commit 4465510

Please sign in to comment.