]> git.mxchange.org Git - jfinancials-war.git/blob - src/java/org/mxchange/jfinancials/beans/helper/receipt/FinancialsWebViewReceiptHelperBean.java
Updated copyright year
[jfinancials-war.git] / src / java / org / mxchange / jfinancials / beans / helper / receipt / FinancialsWebViewReceiptHelperBean.java
1 /*
2  * Copyright (C) 2016 - 2022 Free Software Foundation
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License as
6  * published by the Free Software Foundation, either version 3 of the
7  * License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU Affero General Public License for more details.
13  *
14  * You should have received a copy of the GNU Affero General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 package org.mxchange.jfinancials.beans.helper.receipt;
18
19 import java.text.DateFormat;
20 import javax.faces.view.ViewScoped;
21 import javax.inject.Named;
22 import org.mxchange.jfinancials.beans.BaseFinancialsBean;
23 import org.mxchange.jfinancials.model.receipt.BillableReceipt;
24
25 /**
26  * A receipt helper for beans
27  * <p>
28  * @author Roland Häder<roland@mxchange.org>
29  */
30 @Named ("receiptBeanHelper")
31 @ViewScoped
32 public class FinancialsWebViewReceiptHelperBean extends BaseFinancialsBean implements FinancialsWebViewReceiptHelperController {
33
34         /**
35          * Serial number
36          */
37         private static final long serialVersionUID = 17_258_793_567_145_811L;
38
39         /**
40          * Default constructor
41          */
42         public FinancialsWebViewReceiptHelperBean () {
43                 // Call super constructor
44                 super();
45         }
46
47         /**
48          * Returns the receipt number and more. If null is provided, an empty string
49          * is returned.
50          * <p>
51          * @param receipt                Receipt instance
52          * @param showReceiptPaymentType Whether the payment type should be shown
53          * <p>
54          * @return Receipt number and more
55          */
56         public String renderReceipt (final BillableReceipt receipt, final Boolean showReceiptPaymentType) {
57                 // Default is empty string, so let's get started
58                 final StringBuilder sb = new StringBuilder(50);
59
60                 // Is receipt set?
61                 if (receipt instanceof BillableReceipt) {
62                         // Add relevant data
63                         sb.append(this.getMessageFromBundle("RECEIPT_ISSUED")).append(" "); //NOI18N
64                         sb.append(DateFormat.getInstance().format(receipt.getReceiptIssued()));
65
66                         // Is payment type to be shown?
67                         if (showReceiptPaymentType) {
68                                 // Add payment type
69                                 sb.append(", ").append(this.getMessageFromBundle("PAYMENT_TYPE")).append(" "); //NOI18N
70                                 sb.append(this.getMessageFromBundle(receipt.getReceiptPaymentType().getMessageKey()));
71                         }
72
73                         // Is receipt number included?
74                         if (receipt.getReceiptNumber() != null) {
75                                 // Append it
76                                 sb.append(", ").append(this.getMessageFromBundle("RECEIPT_NUMBER")).append(" "); //NOI18N
77                                 sb.append(receipt.getReceiptNumber());
78                         }
79
80                         // Add company's short name
81                         sb.append(" ("); //NOI18N
82                         sb.append(receipt.getReceiptBranchOffice().getBranchCompany().getCompanyShortName());
83                         sb.append(")"); //NOI18N
84                 }
85
86                 // Return it
87                 return sb.toString();
88         }
89
90 }