com.sfs.whichdoctor.formatter.RevenueAnalysisFormatter.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.whichdoctor.formatter.RevenueAnalysisFormatter.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.whichdoctor.formatter;

import com.sfs.Formatter;
import com.sfs.whichdoctor.beans.OrganisationBean;
import com.sfs.whichdoctor.beans.PaymentBean;
import com.sfs.whichdoctor.beans.PersonBean;
import com.sfs.whichdoctor.beans.ReceiptBean;
import com.sfs.whichdoctor.beans.RevenueBean;

import java.util.ArrayList;
import java.util.Collection;

import org.apache.commons.lang.StringUtils;

/**
 * The Class RevenueAnalysisFormatter.
 */
public class RevenueAnalysisFormatter {

    /**
     * Gets the field.
     *
     * @param revenue the revenue
     * @param field the field
     * @param format the format
     * @return the field
     */
    public static String getField(final RevenueBean revenue, final String field, final String format) {

        String value = "";

        if (revenue == null || field == null) {
            return value;
        }
        if (field.compareTo("Revenue Stream") == 0) {
            value = revenue.getRevenueType();
        }
        if (field.compareTo("Batch Number") == 0) {
            value = revenue.getBatchNo();
        }
        if (field.compareTo("Total Revenue Value") == 0) {
            value = Formatter.toCurrency(revenue.getNetValue(), "$");
            if (format.compareTo("html") == 0) {
                value = "<div style=\"text-align: right\">" + value + "</div>";
            }
        }

        if (field.compareTo("Total GST Value") == 0) {
            value = Formatter.toCurrency(revenue.getGSTValue(), "$");
            if (format.compareTo("html") == 0) {
                value = "<div style=\"text-align: right\">" + value + "</div>";
            }
        }

        if (field.compareTo("Total Revenue") == 0) {
            value = Formatter.toCurrency(revenue.getValue(), "$");
            if (format.compareTo("html") == 0) {
                value = "<div style=\"text-align: right\">" + value + "</div>";
            }
        }

        if (value == null) {
            value = "";
        }
        return value;
    }

    /**
     * Gets the field.
     *
     * @param receipt the receipt
     * @param object the object
     * @param section the section
     * @param field the field
     * @param format the format
     * @return the field
     */
    public static String getField(final ReceiptBean receipt, final Object object, final String section,
            final String field, final String format) {

        String value = "";

        if (section == null) {
            return value;
        }
        if (field == null) {
            return value;
        }
        if (field.compareTo("GUID") == 0) {
            value = String.valueOf(receipt.getGUID());
        }
        if (field.compareTo("Prefix") == 0) {
            value = String.valueOf(receipt.getAbbreviation());
        }
        if (field.compareTo("Receipt Number") == 0) {
            value = String.valueOf(receipt.getNumber());
        }
        if (field.compareTo("Type") == 0) {
            value = receipt.getTypeName();
        }
        if (field.compareTo("Description") == 0) {
            value = receipt.getDescription();
        }
        if (field.compareTo("Batch Number") == 0) {
            value = receipt.getProcessAbbreviation() + ":" + receipt.getBatchReference();
        }
        if (field.compareTo("Bank") == 0) {
            value = receipt.getBank();
        }
        if (field.compareTo("Branch") == 0) {
            value = receipt.getBranch();
        }
        if (field.compareTo("MIN") == 0) {
            if (receipt.getPerson() != null) {
                value = String.valueOf(receipt.getPerson().getPersonIdentifier());
            }
        }

        if (field.compareTo("Person Issued To") == 0) {
            if (receipt.getPerson() != null) {
                PersonBean person = receipt.getPerson();
                value = OutputFormatter.toCasualName(person);
            }
        }

        if (field.compareTo("Organisation Issued To") == 0) {
            if (receipt.getOrganisation() != null) {
                OrganisationBean organisation = receipt.getOrganisation();
                value = organisation.getName();
            }
        }

        if (field.compareTo("Issued Date") == 0) {
            if (receipt.getIssued() != null) {
                value = Formatter.conventionalDate(receipt.getIssued());
            }
        }
        if (field.compareTo("Cancelled") == 0) {
            value = Formatter.convertBoolean(receipt.getCancelled());
        }
        if (section.compareTo("Payments") == 0) {
            PaymentBean payment = (PaymentBean) object;

            if (payment.getDebit() != null) {
                if (field.compareTo("Debit Prefix") == 0) {
                    value = payment.getDebit().getAbbreviation();
                }
                if (field.compareTo("Debit Number") == 0) {
                    value = payment.getDebit().getNumber();
                }
                if (field.compareTo("Debit Description") == 0) {
                    value = payment.getDebit().getDescription();
                }
                if (field.compareTo("Debit Issued") == 0) {
                    value = Formatter.conventionalDate(payment.getDebit().getIssued());
                }
                if (field.compareTo("Debit Value") == 0) {
                    value = Formatter.toCurrency(payment.getDebit().getValue(), "$");
                    if (format.compareTo("html") == 0) {
                        value = "<div style=\"text-align: right\">" + value + "</div>";
                    }
                }
                if (field.compareTo("Debit GST Value") == 0) {
                    value = Formatter.toCurrency(payment.getDebit().getGSTValue(), "$");
                    if (format.compareTo("html") == 0) {
                        value = "<div style=\"text-align: right\">" + value + "</div>";
                    }
                }
                if (field.compareTo("Debit Total Value") == 0) {
                    value = Formatter.toCurrency(payment.getDebit().getTotalValue(), "$");
                    if (format.compareTo("html") == 0) {
                        value = "<div style=\"text-align: right\">" + value + "</div>";
                    }
                }
                if (field.compareTo("Debit GST Rate") == 0) {
                    value = Formatter.toPercentage(payment.getDebit().getGSTRate(), "%");
                }
                if (field.compareTo("Debit Cancelled") == 0) {
                    value = Formatter.convertBoolean(payment.getDebit().getCancelled());
                }
            }

            if (field.compareTo("Payment Value") == 0) {
                value = Formatter.toCurrency(payment.getNetValue(), "$");
                if (format.compareTo("html") == 0) {
                    value = "<div style=\"text-align: right\">" + value + "</div>";
                }
            }

            if (field.compareTo("Negative Payment") == 0) {
                value = Formatter.convertBoolean(payment.getNegativePayment());
            }
        }

        if (value == null) {
            value = "";
        }
        return value;
    }

    /**
     * Gets the collection.
     *
     * @param revenue the revenue
     * @param section the section
     * @return the collection
     */
    public static Collection<Object> getCollection(final RevenueBean revenue, final String section) {

        Collection<Object> collection = new ArrayList<Object>();

        if (StringUtils.equalsIgnoreCase(section, "Payments")) {
            if (revenue.getReceipts() != null) {
                for (Integer key : revenue.getReceipts().keySet()) {
                    ReceiptBean receipt = revenue.getReceipts().get(key);
                    if (receipt != null) {
                        collection.add(receipt);
                    }
                }
            }
        }
        return collection;
    }

    /**
     * Gets the collection.
     *
     * @param receipt the receipt
     * @return the collection
     */
    public static Collection<Object> getCollection(final ReceiptBean receipt) {

        Collection<Object> collection = new ArrayList<Object>();

        if (receipt.getPayments() != null) {
            for (PaymentBean payment : receipt.getPayments()) {
                collection.add(payment);
            }
        }
        return collection;
    }
}