com.etcc.csc.datatype.PaymentDetailUtil.java Source code

Java tutorial

Introduction

Here is the source code for com.etcc.csc.datatype.PaymentDetailUtil.java

Source

package com.etcc.csc.datatype;

import com.etcc.csc.plsql.OLC_ST_ADJUSTMENT_ARR;
import com.etcc.csc.plsql.OLC_ST_ADJUSTMENT_REC;
import com.etcc.csc.plsql.OLC_ST_INVOICES_ARR;
import com.etcc.csc.plsql.OLC_ST_INVOICES_REC;
import com.etcc.csc.plsql.OLC_ST_PAYMENT_ARR;
import com.etcc.csc.plsql.OLC_ST_PAYMENT_REC;
import com.etcc.csc.plsql.OLC_ST_PMT_ADJ_REC;
import com.etcc.csc.plsql.OLC_ST_STATEMENT_REC;
import com.etcc.csc.plsql.OLC_ST_UNINVOICED_VIOLS_ARR;
import com.etcc.csc.plsql.OLC_ST_VIOLATION_ARR;
import com.etcc.csc.plsql.OLC_ST_VIOLATION_REC;
import com.etcc.csc.plsql.OLC_UNINVOICED_VIOLS_ARR;
import com.etcc.csc.plsql.OLC_UNINVOICED_VIOLS_REC;
import com.etcc.csc.plsql.OLC_VB_INVOICES_ARR;
import com.etcc.csc.plsql.OLC_VB_INVOICES_REC;
import com.etcc.csc.plsql.OLC_VIOLATION_REC;
import com.etcc.csc.plsql.OLC_VPS_INVOICES_REC;

import com.etcc.csc.plsql.OLC_VPS_INV_FEE_PMT_REC;
import com.etcc.csc.plsql.OLC_VPS_INV_PMT_REC;

import com.etcc.csc.plsql.OLC_VPS_UNINV_FEE_PMT_REC;
import com.etcc.csc.plsql.OLC_VPS_UNINV_PMT_REC;

import java.math.BigDecimal;

import java.sql.SQLException;
import java.sql.Timestamp;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;

import java.util.List;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;

public class PaymentDetailUtil {
    public PaymentDetailUtil() {
    }

    public static Invoice convertToInvoice(OLC_VPS_INVOICES_REC vpsInvoicesRec) throws Exception {
        Invoice invoice = new Invoice();
        invoice.setId(vpsInvoicesRec.getINVOICE_ID().toPlainString());
        invoice.setDueDate(timestampToCalendar(vpsInvoicesRec.getCURR_DUE_DATE()));
        invoice.setInvoiceDate(timestampToCalendar(vpsInvoicesRec.getINVOICE_DATE()));
        invoice.setFirstName(vpsInvoicesRec.getFIRST_NAME());
        invoice.setLastName(vpsInvoicesRec.getLAST_NAME());
        invoice.setAmount(vpsInvoicesRec.getINVOICE_AMOUNT());
        invoice.setVeaAmount(vpsInvoicesRec.getVEA_AMOUNT());
        invoice.setTollAmount(vpsInvoicesRec.getTOLL_AMOUNT());
        invoice.setFeeAmount(vpsInvoicesRec.getFEE_AMOUNT());
        invoice.setOnlineFee(vpsInvoicesRec.getONLINE_FEE());
        invoice.setLicPlateNumber(vpsInvoicesRec.getLIC_PLATE_NBR());
        invoice.setLicPlateState(vpsInvoicesRec.getLIC_STATE());
        invoice.setViolatorId(vpsInvoicesRec.getVIOLATOR_ID().toPlainString());

        //RITE 1947C - Added 5 fields
        if (vpsInvoicesRec.getVIOL_INV_STATUS().equals("M")) {
            invoice.setCaInvStatus("");
            invoice.setViolInvStatus(vpsInvoicesRec.getVIOL_INV_STATUS());
            invoice.setCaAcctId(
                    (vpsInvoicesRec.getCA_ACCT_ID() != null) ? vpsInvoicesRec.getCA_ACCT_ID().toPlainString() : "");
            invoice.setCaAgencyName(
                    (vpsInvoicesRec.getCA_AGENCY_NAME() != null) ? vpsInvoicesRec.getCA_AGENCY_NAME() : "");
            invoice.setCaPhoneNumber(
                    (vpsInvoicesRec.getCA_PHONE_NUMBER() != null) ? vpsInvoicesRec.getCA_PHONE_NUMBER() : "");
        } else {
            invoice.setCaInvStatus("");
            invoice.setViolInvStatus("");
            invoice.setCaAcctId("");
            invoice.setCaAgencyName("");
            invoice.setCaPhoneNumber("");
        }

        //Rite 2041 Adding one more filed
        invoice.setInvoiceAdminFee(vpsInvoicesRec.getINV_ADMIN_FEE());
        //Rite 2128 one more field
        invoice.setInvSecondNoticeAdminFee(vpsInvoicesRec.getINV_SECOND_NOTICE_ADMIN_FEE());
        invoice.setViolations(convertToViolations(vpsInvoicesRec.getVIOLATIONS().getArray()));
        return invoice;
    }

    public static Invoice convertToInvoice(OLC_VB_INVOICES_REC vpsInvoicesRec) throws Exception {
        Invoice invoice = new Invoice();
        invoice.setId(vpsInvoicesRec.getVBI_INVOICE_ID().toPlainString());
        invoice.setDueDate(timestampToCalendar(vpsInvoicesRec.getDUE_DATE()));
        invoice.setInvoiceDate(timestampToCalendar(vpsInvoicesRec.getINVOICE_DATE()));
        invoice.setFirstName(vpsInvoicesRec.getFIRST_NAME());
        invoice.setLastName(vpsInvoicesRec.getLAST_NAME());
        invoice.setAmount(vpsInvoicesRec.getINVOICE_AMOUNT());
        invoice.setVeaAmount(vpsInvoicesRec.getVEA_AMOUNT());
        invoice.setOnlineFee(vpsInvoicesRec.getONLINE_FEE());
        invoice.setLicPlateNumber(vpsInvoicesRec.getLIC_PLATE_NBR());
        invoice.setLicPlateState(vpsInvoicesRec.getLIC_STATE());
        invoice.setViolatorId(vpsInvoicesRec.getVIOLATOR_ID().toPlainString());
        invoice.setViolations(convertToViolations(vpsInvoicesRec.getVIOLATIONS().getArray()));
        invoice.setNewTrans(vpsInvoicesRec.getTOLL_AMOUNT());
        invoice.setPastDueAmount(vpsInvoicesRec.getPAST_DUE_AMOUNT());
        invoice.setLateFee(vpsInvoicesRec.getLATE_FEE_AMOUNT());
        invoice.setMailHandlingFee(vpsInvoicesRec.getMAIL_FEE_AMOUNT());
        invoice.setPastDueLateFeeAmount(vpsInvoicesRec.getPAST_DUE_LATE_FEE_AMOUNT());
        invoice.setPastDueMailFeeAmount(vpsInvoicesRec.getPAST_DUE_MAIL_FEE_AMOUNT());
        return invoice;
    }

    public static Violation[] convertToViolations(OLC_VIOLATION_REC[] violationRecs) throws Exception {
        if (ArrayUtils.isEmpty(violationRecs)) {
            return null;
        }
        Violation[] violations = new Violation[violationRecs.length];
        for (int i = 0; i < violationRecs.length; i++) {
            violations[i] = convertToViolation(violationRecs[i]);
        }
        return violations;
    }

    public static Violation convertToViolation(OLC_VIOLATION_REC violationRec) throws Exception {
        Violation violation = new Violation();
        violation.setId(violationRec.getVIOLATION_ID().toPlainString());
        violation.setLocation(violationRec.getLANE_NAME());
        violation.setLocationDesc(violationRec.getFULL_LANE_NAME());
        violation.setCitationNumber(violationRec.getCITATION_NBR());
        violation.setTimestamp(timestampToCalendar(violationRec.getVIOLATION_TIME()));
        return violation;
    }

    public static Violation convertToViolation(OLC_UNINVOICED_VIOLS_REC uninvoicedViolsRec) throws Exception {
        Violation violation = new Violation();
        violation.setId(uninvoicedViolsRec.getVIOLATION_ID().toPlainString());
        violation.setLocation(uninvoicedViolsRec.getVIOLATION_LOCATION());
        violation.setLocationDesc(uninvoicedViolsRec.getFULL_LOCATION_NAME());
        violation.setTimestamp(timestampToCalendar(uninvoicedViolsRec.getVIOLATION_DATE_TIME()));
        violation.setStatus(uninvoicedViolsRec.getSTATUS());
        violation.setCashAmount(uninvoicedViolsRec.getCASH_AMT());
        violation.setAviAmount(uninvoicedViolsRec.getAVI_AMT());
        violation.setLicPlate(uninvoicedViolsRec.getLIC_PLATE());
        violation.setLicState(uninvoicedViolsRec.getLIC_STATE());
        violation.setViolatorId(uninvoicedViolsRec.getVIOLATOR_ID());
        // violation.setOnlineFee(uninvoicedViolsRec.getONLINE_FEE());
        violation.setOnlineFee(new BigDecimal(0.0));
        return violation;
    }

    public static OLC_UNINVOICED_VIOLS_REC[] convertToOLC_UNINVOICED_VIOLS_RECs(Violation[] violations)
            throws Exception {
        if (ArrayUtils.isEmpty(violations)) {
            return null;
        }
        OLC_UNINVOICED_VIOLS_REC[] recs = new OLC_UNINVOICED_VIOLS_REC[violations.length];
        for (int i = 0; i < violations.length; i++) {
            recs[i] = convertToOLC_UNINVOICED_VIOLS_REC(violations[i]);
        }
        return recs;
    }

    public static OLC_UNINVOICED_VIOLS_REC convertToOLC_UNINVOICED_VIOLS_REC(Violation violation) throws Exception {
        OLC_UNINVOICED_VIOLS_REC rec = new OLC_UNINVOICED_VIOLS_REC();
        rec.setVIOLATION_ID(new BigDecimal(violation.getId()));
        rec.setVIOLATION_LOCATION(violation.getLocation());
        rec.setVIOLATION_DATE_TIME(new Timestamp(violation.getTimestamp().getTimeInMillis()));
        rec.setSTATUS(violation.getStatus());
        rec.setCASH_AMT(violation.getCashAmount());
        rec.setAVI_AMT(violation.getAviAmount());
        rec.setLIC_PLATE(violation.getLicPlate());
        rec.setLIC_STATE(violation.getLicState());
        rec.setVIOLATOR_ID(violation.getViolatorId());
        rec.setONLINE_FEE(violation.getOnlineFee());
        return rec;
    }

    public static Calendar timestampToCalendar(Timestamp timestamp) {
        if (timestamp == null) {
            return null;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date(timestamp.getTime()));
        return calendar;
    }

    public static OLC_VPS_INV_PMT_REC[] invoicesToOLC_VPS_INV_PMT_RECs(Invoice[] invoices, boolean veaAccepted)
            throws Exception {
        if (ArrayUtils.isEmpty(invoices)) {
            return null;
        }
        OLC_VPS_INV_PMT_REC[] OLC_VPS_INV_PMT_RECs = new OLC_VPS_INV_PMT_REC[invoices.length];
        for (int i = 0; i < invoices.length; i++) {
            OLC_VPS_INV_PMT_REC rec = invoiceToOLC_VPS_INV_PMT_REC(invoices[i], veaAccepted);
            rec.setARR_INDEX(new BigDecimal(i + 1));
            OLC_VPS_INV_PMT_RECs[i] = rec;
        }
        return OLC_VPS_INV_PMT_RECs;
    }

    public static OLC_VPS_INV_PMT_REC invoiceToOLC_VPS_INV_PMT_REC(Invoice invoice, boolean veaAccepted)
            throws Exception {
        if (invoice == null) {
            return null;
        }
        OLC_VPS_INV_PMT_REC rec = new OLC_VPS_INV_PMT_REC();
        rec.setINVOICE_ID(new BigDecimal(invoice.getId()));
        rec.setAMT_PAID((invoice.isVeaEligible() && veaAccepted) ? invoice.getVeaAmount() : invoice.getAmount());
        rec.setVEA_FLAG((invoice.isVeaEligible() && veaAccepted) ? "Y" : "N");
        rec.setVIOLATOR_ID(new BigDecimal(invoice.getViolatorId()));
        rec.setLIC_PLATE_NBR(invoice.getLicPlateNumber());
        rec.setLIC_PLATE_STATE(invoice.getLicPlateState());
        rec.setCITATIONS(concatenateCitations(invoice));

        return rec;
    }

    public static OLC_VB_INVOICES_REC[] invoicesToOLC_VB_INVOICES_RECs(Invoice[] invoices) throws Exception {
        if (ArrayUtils.isEmpty(invoices)) {
            return null;
        }
        OLC_VB_INVOICES_REC[] OLC_VB_INVOICES_RECs = new OLC_VB_INVOICES_REC[invoices.length];
        for (int i = 0; i < invoices.length; i++) {
            OLC_VB_INVOICES_REC rec = invoiceToOLC_VB_INVOICES_REC(invoices[i]);
            //            rec.setARR_INDEX(new BigDecimal(i + 1));
            OLC_VB_INVOICES_RECs[i] = rec;
        }
        return OLC_VB_INVOICES_RECs;
    }

    public static OLC_VB_INVOICES_REC invoiceToOLC_VB_INVOICES_REC(Invoice invoice) throws Exception {
        if (invoice == null) {
            return null;
        }
        OLC_VB_INVOICES_REC rec = new OLC_VB_INVOICES_REC();
        if (invoice.getDueDate() != null) {
            rec.setDUE_DATE(new Timestamp(invoice.getDueDate().getTimeInMillis()));
        }
        rec.setFIRST_NAME(invoice.getFirstName());
        rec.setINVOICE_AMOUNT(invoice.getAmount());
        if (invoice.getInvoiceDate() != null) {
            rec.setINVOICE_DATE(new Timestamp(invoice.getInvoiceDate().getTimeInMillis()));
        }
        rec.setLAST_NAME(invoice.getLastName());
        rec.setLATE_FEE_AMOUNT(invoice.getLateFee());
        rec.setLIC_PLATE_NBR(invoice.getLicPlateNumber());
        rec.setLIC_STATE(invoice.getLicPlateState());
        rec.setMAIL_FEE_AMOUNT(invoice.getMailHandlingFee());
        rec.setONLINE_FEE(invoice.getOnlineFee());
        rec.setPAST_DUE_AMOUNT(invoice.getPastDueAmount());
        rec.setTOLL_AMOUNT(invoice.getNewTrans());
        rec.setPAST_DUE_LATE_FEE_AMOUNT(invoice.getPastDueLateFeeAmount());
        rec.setPAST_DUE_MAIL_FEE_AMOUNT(invoice.getPastDueMailFeeAmount());
        try {
            rec.setVBI_INVOICE_ID(new BigDecimal(invoice.getId()));
        } catch (Exception ex) {
        }
        try {
            rec.setVIOLATOR_ID(new BigDecimal(invoice.getViolatorId()));
        } catch (Exception ex) {
        }
        return rec;
    }

    private static String concatenateCitations(Invoice invoice) {
        String citations = null;
        if (invoice != null) {
            Violation[] violations = invoice.getViolations();
            if (violations != null && violations.length > 0) {
                for (int i = 0; i < violations.length; i++) {
                    if (violations[i] != null && StringUtils.isNotBlank(violations[i].getCitationNumber())) {
                        if (StringUtils.isEmpty(citations)) {
                            citations = violations[i].getCitationNumber();
                        } else {
                            citations = citations + ", " + violations[i].getCitationNumber();
                        }
                    }
                }
            }
        }
        System.out.println(citations);
        return citations;
    }

    public static OLC_VPS_INV_FEE_PMT_REC[] invoicesToOLC_VPS_INV_FEE_PMT_RECs(Invoice[] invoices,
            boolean veaAccepted) throws Exception {
        if (ArrayUtils.isEmpty(invoices)) {
            return null;
        }
        OLC_VPS_INV_FEE_PMT_REC[] OLC_VPS_INV_FEE_PMT_RECs = new OLC_VPS_INV_FEE_PMT_REC[invoices.length];
        for (int i = 0; i < invoices.length; i++) {
            OLC_VPS_INV_FEE_PMT_REC rec = invoiceToOLC_VPS_INV_FEE_PMT_REC(invoices[i], veaAccepted);
            rec.setARR_INDEX(new BigDecimal(i + 1));
            OLC_VPS_INV_FEE_PMT_RECs[i] = rec;
        }
        return OLC_VPS_INV_FEE_PMT_RECs;
    }

    /*
     setARR_INDEX(ARR_INDEX);
     setOL_PMT_DET_ID(OL_PMT_DET_ID);
     setPAYMENT_TXN_ID(PAYMENT_TXN_ID);
     setPAYMENT_LINE_ITEM_ID(PAYMENT_LINE_ITEM_ID);
     setPAYMENT_XREF_ID(PAYMENT_XREF_ID);
     setPAYMENT_FORM(PAYMENT_FORM);
     setINVOICE_ID(INVOICE_ID);
     setAMT_PAID(AMT_PAID);
     setCOLLECTION_ID(COLLECTION_ID);
     setCITATIONS(CITATIONS);
     setVIOLATOR_ID(VIOLATOR_ID);
     setLIC_PLATE_NBR(LIC_PLATE_NBR);
     setLIC_PLATE_STATE(LIC_PLATE_STATE);
     */

    public static OLC_VPS_INV_FEE_PMT_REC invoiceToOLC_VPS_INV_FEE_PMT_REC(Invoice invoice, boolean veaAccepted)
            throws Exception {
        if (invoice == null) {
            return null;
        }
        OLC_VPS_INV_FEE_PMT_REC rec = new OLC_VPS_INV_FEE_PMT_REC();
        rec.setINVOICE_ID(new BigDecimal(invoice.getId()));
        rec.setAMT_PAID((invoice.isVeaEligible() && veaAccepted) ? invoice.getOnlineFee() : new BigDecimal(0.0));
        rec.setVIOLATOR_ID(new BigDecimal(invoice.getViolatorId()));
        rec.setLIC_PLATE_NBR(invoice.getLicPlateNumber());
        rec.setLIC_PLATE_STATE(invoice.getLicPlateState());

        return rec;
    }

    public static OLC_VPS_UNINV_PMT_REC[] violationsToOLC_VPS_UNINV_PMT_RECs(Violation[] violations)
            throws Exception {
        if (ArrayUtils.isEmpty(violations)) {
            return null;
        }
        OLC_VPS_UNINV_PMT_REC[] OLC_VPS_UNINV_PMT_RECs = new OLC_VPS_UNINV_PMT_REC[violations.length];
        for (int i = 0; i < violations.length; i++) {
            OLC_VPS_UNINV_PMT_REC rec = violationToOLC_VPS_UNINV_PMT_REC(violations[i]);
            rec.setARR_INDEX(new BigDecimal(i + 1));
            OLC_VPS_UNINV_PMT_RECs[i] = rec;
        }
        return OLC_VPS_UNINV_PMT_RECs;
    }

    /*
     *     setOL_PMT_DET_ID(OL_PMT_DET_ID);
    setPAYMENT_FORM(PAYMENT_FORM);
    setPAYMENT_TXN_ID(PAYMENT_TXN_ID);
    setPAYMENT_LINE_ITEM_ID(PAYMENT_LINE_ITEM_ID);
    setPAYMENT_XREF_ID(PAYMENT_XREF_ID);
    setVIOLATION_ID(VIOLATION_ID);
    setAMT_PAID(AMT_PAID);
    setVIOLATOR_ID(VIOLATOR_ID);
    setLIC_PLATE_NBR(LIC_PLATE_NBR);
    setLIC_PLATE_STATE(LIC_PLATE_STATE);
    setSTATUS(STATUS);
    setERROR_CODE(ERROR_CODE);
    setARR_INDEX(ARR_INDEX);
     */

    public static OLC_VPS_UNINV_PMT_REC violationToOLC_VPS_UNINV_PMT_REC(Violation violation) throws Exception {
        if (violation == null) {
            return null;
        }

        OLC_VPS_UNINV_PMT_REC rec = new OLC_VPS_UNINV_PMT_REC();
        rec.setVIOLATION_ID(new BigDecimal(violation.getId()));
        rec.setAMT_PAID(violation.getCashAmount());
        rec.setVIOLATOR_ID(violation.getViolatorId());
        rec.setLIC_PLATE_NBR(violation.getLicPlate());
        rec.setLIC_PLATE_STATE(violation.getLicState());
        return rec;
    }

    public static OLC_UNINVOICED_VIOLS_REC[] violationsToOLC_UNINVOICED_VIOLS_RECs(Violation[] violations)
            throws Exception {
        if (ArrayUtils.isEmpty(violations)) {
            return null;
        }
        OLC_UNINVOICED_VIOLS_REC[] OLC_UNINVOICED_VIOLS_RECs = new OLC_UNINVOICED_VIOLS_REC[violations.length];
        for (int i = 0; i < violations.length; i++) {
            OLC_UNINVOICED_VIOLS_REC rec = violationToOLC_UNINVOICED_VIOLS_REC(violations[i]);
            //rec.setARR_INDEX(new BigDecimal(i + 1));
            OLC_UNINVOICED_VIOLS_RECs[i] = rec;
        }
        return OLC_UNINVOICED_VIOLS_RECs;
    }

    public static OLC_UNINVOICED_VIOLS_REC violationToOLC_UNINVOICED_VIOLS_REC(Violation violation)
            throws Exception {
        if (violation == null) {
            return null;
        }

        OLC_UNINVOICED_VIOLS_REC rec = new OLC_UNINVOICED_VIOLS_REC();
        rec.setAVI_AMT(violation.getAviAmount());
        rec.setCASH_AMT(violation.getCashAmount());
        rec.setFULL_LOCATION_NAME(violation.getLocationDesc());
        rec.setLIC_PLATE(violation.getLicPlate());
        rec.setLIC_STATE(violation.getLicState());
        rec.setONLINE_FEE(violation.getOnlineFee());
        rec.setSTATUS(violation.getStatus());
        if (violation.getTimestamp() != null) {
            rec.setVIOLATION_DATE_TIME(new Timestamp(violation.getTimestamp().getTimeInMillis()));
        }
        rec.setVIOLATION_ID(new BigDecimal(violation.getId()));
        rec.setVIOLATOR_ID(violation.getViolatorId());
        return rec;
    }

    public static OLC_VPS_UNINV_FEE_PMT_REC[] violationsToOLC_VPS_UNINV_FEE_PMT_RECs(Violation[] violations)
            throws Exception {
        if (ArrayUtils.isEmpty(violations)) {
            return null;
        }

        OLC_VPS_UNINV_FEE_PMT_REC[] OLC_VPS_UNINV_FEE_PMT_RECs = new OLC_VPS_UNINV_FEE_PMT_REC[violations.length];
        for (int i = 0; i < violations.length; i++) {
            OLC_VPS_UNINV_FEE_PMT_REC rec = violationToOLC_VPS_UNINV_FEE_PMT_REC(violations[i]);
            rec.setARR_INDEX(new BigDecimal(i + 1));
            OLC_VPS_UNINV_FEE_PMT_RECs[i] = rec;
        }
        return OLC_VPS_UNINV_FEE_PMT_RECs;
    }

    /*
     *     setARR_INDEX(ARR_INDEX);
    setOL_PMT_DET_ID(OL_PMT_DET_ID);
    setPAYMENT_TXN_ID(PAYMENT_TXN_ID);
    setPAYMENT_LINE_ITEM_ID(PAYMENT_LINE_ITEM_ID);
    setPAYMENT_XREF_ID(PAYMENT_XREF_ID);
    setPAYMENT_FORM(PAYMENT_FORM);
    setVIOLATION_ID(VIOLATION_ID);
    setAMT_PAID(AMT_PAID);
    setVIOLATOR_ID(VIOLATOR_ID);
    setLIC_PLATE_NBR(LIC_PLATE_NBR);
    setLIC_PLATE_STATE(LIC_PLATE_STATE);
    setSTATUS(STATUS);
    setERROR_CODE(ERROR_CODE);
        
     */

    public static OLC_VPS_UNINV_FEE_PMT_REC violationToOLC_VPS_UNINV_FEE_PMT_REC(Violation violation)
            throws Exception {
        if (violation == null) {
            return null;
        }

        OLC_VPS_UNINV_FEE_PMT_REC rec = new OLC_VPS_UNINV_FEE_PMT_REC();
        rec.setVIOLATION_ID(new BigDecimal(violation.getId()));
        rec.setAMT_PAID(violation.getOnlineFee());
        rec.setVIOLATOR_ID(violation.getViolatorId());
        rec.setLIC_PLATE_NBR(violation.getLicPlate());
        rec.setLIC_PLATE_STATE(violation.getLicState());
        return rec;
    }

    public static Invoice convertToStatementInvoice(OLC_ST_INVOICES_REC vpsInvoicesRec,
            OLC_ST_STATEMENT_REC statementRec) throws Exception {
        Invoice invoice = new Invoice();
        invoice.setId(vpsInvoicesRec.getINVOICE_ID().toPlainString());
        invoice.setViolInvoiceId(vpsInvoicesRec.getVIOL_INVOICE_ID().toPlainString());
        invoice.setInvType(vpsInvoicesRec.getINVOICE_TYPE());
        invoice.setIsNTTAToll(vpsInvoicesRec.getNTTA_TOLL_IND());
        invoice.setIsHighwayToll(vpsInvoicesRec.getHIGHWAY_TOLL_IND());
        invoice.setAmount(vpsInvoicesRec.getINVOICE_AMOUNT());
        invoice.setTollAmount(vpsInvoicesRec.getTOLL_AMOUNT());
        invoice.setFeeAmount(vpsInvoicesRec.getONLINE_FEE());
        invoice.setInvoiceAdminFee(vpsInvoicesRec.getINV_ADMIN_FEE());
        invoice.setInvSecondNoticeAdminFee(vpsInvoicesRec.getINV_SECOND_NOTICE_ADMIN_FEE());
        invoice.setInvStatus(vpsInvoicesRec.getVIOL_INV_STATUS_DESC());
        invoice.setViolations(convertToStatementViolations(vpsInvoicesRec.getVIOLATIONS().getArray()));
        invoice.setNoViolations(vpsInvoicesRec.getVIOLATIONS_COUNT().toPlainString());
        invoice.setVbInvStatus(vpsInvoicesRec.getVBI_INVOICE_STATUS_DESC());
        invoice.setTotalTXNFees(vpsInvoicesRec.getTOTAL_TXN_FEES());
        invoice.setDueDate(timestampToCalendar(vpsInvoicesRec.getCURR_DUE_DATE()));
        invoice.setInvoiceDate(timestampToCalendar(vpsInvoicesRec.getINVOICE_DATE()));
        invoice.setLicPlateNumber(statementRec.getLICENSE_PLATE());
        invoice.setPaidIndicator(vpsInvoicesRec.getPAID_IND());
        invoice.setAdjustedTxnFees(vpsInvoicesRec.getADJUSTED_TXN_FEES());
        return invoice;
    }

    public static Violation[] convertToStatementViolations(OLC_ST_VIOLATION_REC[] violationRecs) throws Exception {
        if (ArrayUtils.isEmpty(violationRecs)) {
            return null;
        }
        Violation[] violations = new Violation[violationRecs.length];

        for (int i = 0; i < violationRecs.length; i++) {
            violations[i] = convertToStatementViolation(violationRecs[i]);
        }
        return violations;
    }

    public static Violation convertToStatementViolation(OLC_ST_VIOLATION_REC violationRec) throws Exception {
        Violation violation = new Violation();
        violation.setId(violationRec.getVIOLATION_ID().toPlainString());
        violation.setLocation(violationRec.getLANE_NAME());
        violation.setLocationDesc(violationRec.getFULL_LANE_NAME());
        violation.setTollAmt(violationRec.getTOLL_AMT_DUE());
        //violation.setPostDate(timestampToCalendar(violationRec.getVIOLATION_TIME()));        
        violation.setFineAmt(violationRec.getFINE_AMOUNT());
        violation.setPostDate(timestampToCalendar(violationRec.getTRANSACTION_DATE()));
        violation.setTimestamp(timestampToCalendar(violationRec.getTRANSACTION_TIME()));
        violation.setTollType(violationRec.getNTTA_IND());
        violation.setPaidIndicator(violationRec.getPAID_IND());
        return violation;
    }

    public static MonthlyStatement convertToStatement(OLC_ST_STATEMENT_REC statementRec) throws Exception {
        MonthlyStatement statement = new MonthlyStatement();
        statement.setStatementId(statementRec.getSTATEMENT_ID().toString());
        statement.setZipCashAcctId(statementRec.getACCOUNT_ID().toString());
        statement.setLicPlateNumber(statementRec.getLICENSE_PLATE().toString());
        statement.setLicPlateState(statementRec.getLIC_PLATE_STATE().toString());
        statement.setBillingPeriodStart(timestampToCalendar(statementRec.getBILLING_PERIOD_START()));
        statement.setBillingPeriodEnd(timestampToCalendar(statementRec.getBILLING_PERIOD_END()));
        statement.setPaymentDueDate(timestampToCalendar(statementRec.getPAYMENT_DUE_DATE()));
        statement.setAmountDue(statementRec.getAMOUNT_DUE());
        statement.setPrevBalance(statementRec.getPREVIOUS_BALANCE());
        statement.setUnpaidBalance(statementRec.getUNPAID_BALANCE());
        statement.setTotalPayment(statementRec.getTOTAL_PAYMENTS().negate());
        statement.setTotalAdjustments(statementRec.getTOTAL_ADJUSTMENTS().negate());
        statement.setCurrentTolls(statementRec.getCURRENT_TOLLS());
        statement.setTotalFees(statementRec.getTOTAL_FEES());

        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(statementRec.getBILLING_PERIOD_END());
        cal1.add(Calendar.DATE, 1);
        statement.setStatementDate(cal1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(statement.getStatementDate().getTime());
        cal2.add(Calendar.MONTH, 1);
        statement.setNextStatementDate(cal2);

        return statement;
    }

    public static void convertToStatementPmtAdj(OLC_ST_PMT_ADJ_REC pmtAdjRec, PaymentDetail paymentDetai)
            throws Exception {
        OLC_ST_PAYMENT_ARR pmtArr = pmtAdjRec.getST_PAYMENTS();
        OLC_ST_ADJUSTMENT_ARR adjArr = pmtAdjRec.getST_ADJUSTMENTS();

        OLC_ST_PAYMENT_ARR recentPmtArr = pmtAdjRec.getST_PAYMENTS();
        OLC_ST_ADJUSTMENT_ARR recentAdjArr = pmtAdjRec.getST_ADJUSTMENTS();

        List<MSPaymentAdjust> pmtAdjList = new ArrayList<MSPaymentAdjust>();
        List<MSPaymentAdjust> recentPmtAdjList = new ArrayList<MSPaymentAdjust>();

        MSPaymentAdjust msPaymentAdjust = null;
        for (int i = 0; i < pmtArr.getArray().length; i++) {
            msPaymentAdjust = convertPmtToStatementPmtAdj(pmtArr.getArray()[i]);
            if (pmtArr.getArray()[i].getPAYMENT_ID().intValue() == 1) {
                recentPmtAdjList.add(msPaymentAdjust);
            } else {
                pmtAdjList.add(msPaymentAdjust);
            }
        }

        for (int i = 0; i < adjArr.getArray().length; i++) {
            msPaymentAdjust = convertAdjToStatementPmtAdj(adjArr.getArray()[i]);
            if (adjArr.getArray()[i].getADJUSTMENT_ID().intValue() == 1) {
                recentPmtAdjList.add(msPaymentAdjust);
            } else {
                pmtAdjList.add(msPaymentAdjust);
            }
        }

        paymentDetai.setPmtAdjArr(pmtAdjList.toArray(new MSPaymentAdjust[pmtAdjList.size()]));
        paymentDetai.setRecentPmtAdjArr(recentPmtAdjList.toArray(new MSPaymentAdjust[recentPmtAdjList.size()]));
    }

    public static MSPaymentAdjust convertPmtToStatementPmtAdj(OLC_ST_PAYMENT_REC pmtRec) throws Exception {
        MSPaymentAdjust pmtAdjRec = new MSPaymentAdjust();
        pmtAdjRec.setPmtAdjId(pmtRec.getPAYMENT_ID().toPlainString());
        pmtAdjRec.setPmtAdjAmount(pmtRec.getPAYMENT_AMOUNT().negate());
        pmtAdjRec.setPmtAdjAction(pmtRec.getDESCRIPTION());
        pmtAdjRec.setPmtAdjDate(new SimpleDateFormat("MM/dd/yyyy").format(pmtRec.getPAYMENT_DATE()));
        pmtAdjRec.setPmtAdjType("PMT");

        return pmtAdjRec;
    }

    public static MSPaymentAdjust convertAdjToStatementPmtAdj(OLC_ST_ADJUSTMENT_REC adjRec) throws Exception {
        MSPaymentAdjust pmtAdjRec = new MSPaymentAdjust();
        pmtAdjRec.setPmtAdjId(adjRec.getADJUSTMENT_ID().toPlainString());
        pmtAdjRec.setPmtAdjAmount(adjRec.getADJUSTMENT_AMOUNT().negate());
        pmtAdjRec.setPmtAdjAction(adjRec.getDESCRIPTION());
        pmtAdjRec.setPmtAdjDate(new SimpleDateFormat("MM/dd/yyyy").format(adjRec.getADJUSTMENT_DATE()));
        pmtAdjRec.setPmtAdjType("ADJ");

        return pmtAdjRec;
    }

    public static OLC_ST_INVOICES_REC[] invoicesToOLC_ST_INVOICES_RECs(Invoice[] invoices) throws Exception {
        if (ArrayUtils.isEmpty(invoices)) {
            return null;
        }
        OLC_ST_INVOICES_REC[] P_OLC_ST_INVOICES_RECs = new OLC_ST_INVOICES_REC[invoices.length];
        for (int i = 0; i < invoices.length; i++) {

            OLC_ST_INVOICES_REC rec = new OLC_ST_INVOICES_REC();
            rec.setINVOICE_ID(new BigDecimal(invoices[i].getId()));
            rec.setVIOL_INVOICE_ID(new BigDecimal(invoices[i].getViolInvoiceId()));
            rec.setINVOICE_TYPE(invoices[i].getInvType());

            rec.setNTTA_TOLL_IND(invoices[i].getIsNTTAToll());
            rec.setHIGHWAY_TOLL_IND(invoices[i].getIsHighwayToll());
            rec.setINVOICE_AMOUNT(invoices[i].getAmount());
            rec.setTOLL_AMOUNT(invoices[i].getAdjustedTollAmount());
            rec.setTOTAL_TXN_FEES(invoices[i].getFeeAmount());

            rec.setINV_ADMIN_FEE(invoices[i].getInvoiceAdminFee());
            rec.setINV_SECOND_NOTICE_ADMIN_FEE(invoices[i].getInvSecondNoticeAdminFee());
            rec.setVIOL_INV_STATUS_DESC(invoices[i].getInvStatus());

            OLC_ST_VIOLATION_ARR P_OLC_ST_VIOLATION_ARR = new OLC_ST_VIOLATION_ARR();
            P_OLC_ST_VIOLATION_ARR.setArray(convertToStatementViolations(invoices[i].getViolations()));
            rec.setVIOLATIONS(P_OLC_ST_VIOLATION_ARR);

            rec.setVIOLATIONS_COUNT(new BigDecimal(invoices[i].getNoViolations()));
            rec.setVBI_INVOICE_STATUS_DESC(invoices[i].getVbInvStatus());

            rec.setTOTAL_TXN_FEES(invoices[i].getTotalTXNFees());
            rec.setCURR_DUE_DATE(new Timestamp(invoices[i].getDueDate().getTimeInMillis()));
            rec.setINVOICE_DATE(new Timestamp(invoices[i].getInvoiceDate().getTimeInMillis()));

            P_OLC_ST_INVOICES_RECs[i] = rec;
        }
        return P_OLC_ST_INVOICES_RECs;
    }

    public static OLC_ST_VIOLATION_REC[] convertToStatementViolations(Violation[] violationRecs) throws Exception {
        if (ArrayUtils.isEmpty(violationRecs)) {
            return null;
        }
        OLC_ST_VIOLATION_REC[] violations = new OLC_ST_VIOLATION_REC[violationRecs.length];

        for (int i = 0; i < violationRecs.length; i++) {
            violations[i] = convertToStatementViolation(violationRecs[i]);
        }
        return violations;
    }

    public static OLC_ST_VIOLATION_REC convertToStatementViolation(Violation violationRec) throws Exception {
        OLC_ST_VIOLATION_REC violation = new OLC_ST_VIOLATION_REC();
        violation.setVIOLATION_ID(new BigDecimal(violationRec.getId()));
        violation.setLANE_NAME(violationRec.getLocation());
        violation.setFULL_LANE_NAME(violationRec.getLocationDesc());
        violation.setTOLL_AMT_DUE(violationRec.getTollAmt());
        if (violationRec.getPostDate() != null) {
            violation.setTRANSACTION_DATE(new Timestamp(violationRec.getPostDate().getTimeInMillis()));

        } else {
            violation.setTRANSACTION_DATE(new Timestamp(violationRec.getTimestamp().getTimeInMillis()));
        }
        violation.setTRANSACTION_TIME(new Timestamp(violationRec.getTimestamp().getTimeInMillis()));
        violation.setNTTA_IND(violationRec.getTollType());
        return violation;
    }

    public static Violation[] convertToStatementUnInvoiceViolations(OLC_ST_VIOLATION_REC[] olcUninvRecs)
            throws SQLException {
        if (ArrayUtils.isEmpty(olcUninvRecs)) {
            return null;
        }
        Violation[] violations = new Violation[olcUninvRecs.length];

        for (int i = 0; i < olcUninvRecs.length; i++) {
            violations[i] = convertToStatementUnInvoiceViolation(olcUninvRecs[i]);
        }
        return violations;
    }

    private static Violation convertToStatementUnInvoiceViolation(OLC_ST_VIOLATION_REC violationRec)
            throws SQLException {
        Violation violation = new Violation();
        violation.setId(violationRec.getVIOLATION_ID().toPlainString());
        violation.setLocation(violationRec.getLANE_NAME());
        violation.setLocationDesc(violationRec.getFULL_LANE_NAME());
        violation.setTollAmt(violationRec.getTOLL_AMT_DUE());
        //violation.setPostDate(timestampToCalendar(violationRec.getVIOLATION_TIME()));        
        violation.setFineAmt(violationRec.getFINE_AMOUNT());
        violation.setPostDate(timestampToCalendar(violationRec.getTRANSACTION_DATE()));
        violation.setTimestamp(timestampToCalendar(violationRec.getTRANSACTION_TIME()));
        violation.setTollType(violationRec.getNTTA_IND());
        violation.setLicPlate(violationRec.getLIC_PLATE());
        violation.setLicState(violationRec.getLIC_STATE());
        violation.setStatus(violationRec.getSTATUS());
        violation.setAviAmount(violationRec.getTOLL_AMT_DUE());
        violation.setCashAmount(violationRec.getTOLL_AMT_DUE());
        violation.setOnlineFee(new BigDecimal(0.0));
        return violation;
    }
}